Search in sources :

Example 36 with LatLon

use of de.westnordost.osmapi.map.data.LatLon in project StreetComplete by westnordost.

the class QuestDownload method download.

public void download() {
    if (cancelState.get())
        return;
    List<QuestType> questTypes = getQuestTypesToDownload();
    if (questTypes.isEmpty()) {
        finished = true;
        progressListener.onNotStarted();
        return;
    }
    totalQuestTypes = questTypes.size();
    BoundingBox bbox = SlippyMapMath.asBoundingBox(tiles, ApplicationConstants.QUEST_TILE_ZOOM);
    try {
        Log.i(TAG, "(" + bbox.getAsLeftBottomRightTopString() + ") Starting");
        progressListener.onStarted();
        Set<LatLon> notesPositions;
        if (questTypes.contains(getOsmNoteQuestType())) {
            notesPositions = downloadNotes(bbox);
        } else {
            notesPositions = getNotePositionsFromDb(bbox);
        }
        downloadQuestTypes(bbox, questTypes, notesPositions);
        progressListener.onSuccess();
    } finally {
        finished = true;
        progressListener.onFinished();
        Log.i(TAG, "(" + bbox.getAsLeftBottomRightTopString() + ") Finished");
    }
}
Also used : OsmNoteQuestType(de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuestType) OsmElementQuestType(de.westnordost.streetcomplete.data.osm.OsmElementQuestType) QuestType(de.westnordost.streetcomplete.data.QuestType) LatLon(de.westnordost.osmapi.map.data.LatLon) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox)

Example 37 with LatLon

use of de.westnordost.osmapi.map.data.LatLon in project StreetComplete by westnordost.

the class MapFragment method meters2Pixels.

private float meters2Pixels(LngLat at, float meters) {
    LatLon pos0 = TangramConst.toLatLon(at);
    LatLon pos1 = SphericalEarthMath.translate(pos0, meters, 0);
    PointF screenPos0 = controller.lngLatToScreenPosition(at);
    PointF screenPos1 = controller.lngLatToScreenPosition(TangramConst.toLngLat(pos1));
    double tiltFactor = Math.sin(controller.getTilt() / 2.0) * Math.cos(controller.getRotation());
    return (float) ((1 / (1 - Math.abs(tiltFactor))) * Math.sqrt(Math.pow(screenPos1.y - screenPos0.y, 2) + Math.pow(screenPos1.x - screenPos0.x, 2)));
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) PointF(android.graphics.PointF)

Example 38 with LatLon

use of de.westnordost.osmapi.map.data.LatLon in project StreetComplete by westnordost.

the class QuestsMapFragment method addQuests.

/*
	public void addQuest(Quest quest, QuestGroup group)
	{
		// TODO: this method may also be called for quests that are already displayed on this map
		if(questsLayer == null) return;

		LngLat pos = TangramConst.toLngLat(quest.getMarkerLocation());
		Map<String, String> props = new HashMap<>();
		props.put("type", "point");
		props.put("kind", quest.getType().getIconName());
		props.put(MARKER_QUEST_GROUP, group.name());
		props.put(MARKER_QUEST_ID, String.valueOf(quest.getId()));
		questsLayer.addPoint(pos, props);

		controller.applySceneUpdates();
	}
*/
@UiThread
public void addQuests(Iterable quests, QuestGroup group) {
    if (questsLayer == null)
        return;
    StringBuilder geoJson = new StringBuilder();
    geoJson.append("{\"type\":\"FeatureCollection\",\"features\": [");
    boolean first = true;
    for (Object q : quests) {
        Quest quest = (Quest) q;
        // hack away cycleway quests for old Android SDK versions (#713)
        if (quest.getType() instanceof AddCycleway && android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            continue;
        }
        if (first)
            first = false;
        else
            geoJson.append(",");
        LatLon pos = quest.getMarkerLocation();
        String questIconName = getActivity().getResources().getResourceEntryName(quest.getType().getIcon());
        Integer order = questTypeOrder.get(quest.getType());
        if (order == null)
            order = 0;
        geoJson.append("{\"type\":\"Feature\",");
        geoJson.append("\"geometry\":{\"type\":\"Point\",\"coordinates\": [");
        geoJson.append(pos.getLongitude());
        geoJson.append(",");
        geoJson.append(pos.getLatitude());
        geoJson.append("]},\"properties\": {\"type\":\"point\", \"kind\":\"");
        geoJson.append(questIconName);
        geoJson.append("\",\"");
        geoJson.append(MARKER_QUEST_GROUP);
        geoJson.append("\":\"");
        geoJson.append(group.name());
        geoJson.append("\",\"");
        geoJson.append(MARKER_QUEST_ID);
        geoJson.append("\":\"");
        geoJson.append(quest.getId());
        geoJson.append("\",\"");
        geoJson.append("order");
        geoJson.append("\":\"");
        geoJson.append(order);
        geoJson.append("\"}}");
    }
    geoJson.append("]}");
    questsLayer.addGeoJson(geoJson.toString());
    controller.requestRender();
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) AddCycleway(de.westnordost.streetcomplete.quests.bikeway.AddCycleway) Quest(de.westnordost.streetcomplete.data.Quest) UiThread(android.support.annotation.UiThread)

Example 39 with LatLon

use of de.westnordost.osmapi.map.data.LatLon in project StreetComplete by westnordost.

the class TangramConst method toLngLat.

public static List<List<LngLat>> toLngLat(List<List<LatLon>> positionLists) {
    List<List<LngLat>> result = new ArrayList<>(positionLists.size());
    for (List<LatLon> positions : positionLists) {
        List<LngLat> resultPositions = new ArrayList<>(positions.size());
        for (LatLon pos : positions) {
            resultPositions.add(toLngLat(pos));
        }
        result.add(resultPositions);
    }
    return result;
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) LngLat(com.mapzen.tangram.LngLat) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 40 with LatLon

use of de.westnordost.osmapi.map.data.LatLon in project StreetComplete by westnordost.

the class JTSConst method toLinearRing.

public static LinearRing toLinearRing(BoundingBox bbox) {
    List<LatLon> corners = new ArrayList<>(5);
    corners.add(bbox.getMin());
    corners.add(new OsmLatLon(bbox.getMinLatitude(), bbox.getMaxLongitude()));
    corners.add(bbox.getMax());
    corners.add(new OsmLatLon(bbox.getMaxLatitude(), bbox.getMinLongitude()));
    corners.add(bbox.getMin());
    return factory.createLinearRing(toCoordinates(corners));
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) ArrayList(java.util.ArrayList) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Aggregations

LatLon (de.westnordost.osmapi.map.data.LatLon)63 OsmLatLon (de.westnordost.osmapi.map.data.OsmLatLon)45 ArrayList (java.util.ArrayList)29 BoundingBox (de.westnordost.osmapi.map.data.BoundingBox)13 List (java.util.List)12 ElementGeometry (de.westnordost.streetcomplete.data.osm.ElementGeometry)8 OsmNode (de.westnordost.osmapi.map.data.OsmNode)5 HashMap (java.util.HashMap)5 Point (android.graphics.Point)3 PointF (android.graphics.PointF)3 Node (de.westnordost.osmapi.map.data.Node)3 OsmElementQuestType (de.westnordost.streetcomplete.data.osm.OsmElementQuestType)3 LngLat (com.mapzen.tangram.LngLat)2 Point (com.vividsolutions.jts.geom.Point)2 Element (de.westnordost.osmapi.map.data.Element)2 QuestGroup (de.westnordost.streetcomplete.data.QuestGroup)2 VisibleQuestListener (de.westnordost.streetcomplete.data.VisibleQuestListener)2 OsmNoteQuestType (de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuestType)2 Collection (java.util.Collection)2 Map (java.util.Map)2