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");
}
}
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)));
}
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();
}
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;
}
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));
}
Aggregations