Search in sources :

Example 1 with Quest

use of de.westnordost.streetcomplete.data.Quest 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)

Aggregations

UiThread (android.support.annotation.UiThread)1 LatLon (de.westnordost.osmapi.map.data.LatLon)1 Quest (de.westnordost.streetcomplete.data.Quest)1 AddCycleway (de.westnordost.streetcomplete.quests.bikeway.AddCycleway)1