use of de.westnordost.osmapi.map.data.Element in project StreetComplete by westnordost.
the class QuestController method retrieve.
/**
* Retrieve the given quest from local database asynchronously, including the element / note.
*/
public void retrieve(final QuestGroup group, final long questId) {
workerHandler.post(() -> {
if (group == QuestGroup.OSM) {
// race condition: another thread may have removed the element already (#288)
OsmQuest osmQuest = osmQuestDB.get(questId);
if (osmQuest == null)
return;
Element element = osmElementDB.get(osmQuest.getElementType(), osmQuest.getElementId());
if (element == null)
return;
relay.onQuestSelected(osmQuest, group, element);
} else if (group == QuestGroup.OSM_NOTE) {
OsmNoteQuest osmNoteQuest = osmNoteQuestDB.get(questId);
if (osmNoteQuest == null)
return;
relay.onQuestSelected(osmNoteQuest, group, null);
}
});
}
use of de.westnordost.osmapi.map.data.Element in project StreetComplete by westnordost.
the class MergedElementDao method putAll.
public void putAll(Collection<Element> elements) {
Collection<Node> nodes = new ArrayList<>();
Collection<Way> ways = new ArrayList<>();
Collection<Relation> relations = new ArrayList<>();
for (Element element : elements) {
switch(element.getType()) {
case NODE:
nodes.add((Node) element);
break;
case WAY:
ways.add((Way) element);
break;
case RELATION:
relations.add((Relation) element);
break;
}
}
if (!nodes.isEmpty())
nodeDao.putAll(nodes);
if (!ways.isEmpty())
wayDao.putAll(ways);
if (!relations.isEmpty())
relationDao.putAll(relations);
}
use of de.westnordost.osmapi.map.data.Element in project StreetComplete by westnordost.
the class OverpassMapDataParserTest method testNode.
public void testNode() {
LatLon pos = new OsmLatLon(51.7463194, 0.2428181);
String xml = " <node id='5' version='1' lat='" + pos.getLatitude() + "' lon='" + pos.getLongitude() + "'/>";
Element e = parseOne(xml, null);
assertTrue(e instanceof Node);
Node node = (Node) e;
assertEquals(pos, node.getPosition());
assertEquals(5, node.getId());
assertEquals(1, node.getVersion());
assertNull(node.getTags());
}
use of de.westnordost.osmapi.map.data.Element in project StreetComplete by westnordost.
the class OverpassMapDataParserTest method testRelation.
public void testRelation() {
OsmLatLon[] p = new OsmLatLon[5];
p[0] = new OsmLatLon(1, 2);
p[1] = new OsmLatLon(3, 4);
p[2] = new OsmLatLon(5, 6);
p[3] = new OsmLatLon(7, 8);
p[4] = new OsmLatLon(9, 10);
String xml = "<relation id='10' version='1'>\n" + " <member type='relation' ref='4' role=''/>\n" + " <member type='way' ref='1' role='outer'>\n" + " <nd lat='" + p[0].getLatitude() + "' lon='" + p[0].getLongitude() + "'/>\n" + " <nd lat='" + p[1].getLatitude() + "' lon='" + p[1].getLongitude() + "'/>\n" + " </member>\n" + " <member type='way' ref='2' role='inner'>\n" + " <nd lat='" + p[2].getLatitude() + "' lon='" + p[2].getLongitude() + "'/>\n" + " <nd lat='" + p[3].getLatitude() + "' lon='" + p[3].getLongitude() + "'/>\n" + " </member>\n" + " <member type='node' ref='3' role='point'>\n" + " <nd lat='" + p[4].getLatitude() + "' lon='" + p[4].getLongitude() + "'/>\n" + " </member>\n" + "</relation>";
LongSparseArray<List<LatLon>> expectedGeometry = new LongSparseArray<>();
expectedGeometry.put(1, new ArrayList<>(Arrays.asList(p[0], p[1])));
expectedGeometry.put(2, new ArrayList<>(Arrays.asList(p[2], p[3])));
Element e = parseOne(xml, expectedGeometry);
assertTrue(e instanceof Relation);
Relation relation = (Relation) e;
assertEquals(10, relation.getId());
assertEquals(1, relation.getVersion());
assertEquals(4, relation.getMembers().size());
RelationMember[] rm = new RelationMember[relation.getMembers().size()];
relation.getMembers().toArray(rm);
assertEquals(4, rm[0].getRef());
assertEquals(Element.Type.RELATION, rm[0].getType());
assertEquals("", rm[0].getRole());
assertEquals(1, rm[1].getRef());
assertEquals(Element.Type.WAY, rm[1].getType());
assertEquals("outer", rm[1].getRole());
assertEquals(2, rm[2].getRef());
assertEquals(Element.Type.WAY, rm[2].getType());
assertEquals("inner", rm[2].getRole());
assertEquals(3, rm[3].getRef());
assertEquals(Element.Type.NODE, rm[3].getType());
assertEquals("point", rm[3].getRole());
assertNull(relation.getTags());
}
use of de.westnordost.osmapi.map.data.Element in project StreetComplete by westnordost.
the class AOsmElementDaoTest method createElement.
private Element createElement(long id, int version) {
Element element = mock(Element.class);
when(element.getId()).thenReturn(id);
when(element.getVersion()).thenReturn(version);
return element;
}
Aggregations