-
-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1901 from westnordost/multi-download
Multi download
- Loading branch information
Showing
227 changed files
with
3,458 additions
and
2,987 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
app/src/androidTest/java/de/westnordost/streetcomplete/data/osm/osmquest/TestQuestType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
package de.westnordost.streetcomplete.data.osm.osmquest | ||
|
||
import de.westnordost.osmapi.map.data.BoundingBox | ||
import de.westnordost.osmapi.map.MapDataWithGeometry | ||
import de.westnordost.osmapi.map.data.Element | ||
import de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder | ||
import de.westnordost.streetcomplete.data.osm.elementgeometry.ElementGeometry | ||
import de.westnordost.streetcomplete.quests.AbstractQuestAnswerFragment | ||
|
||
open class TestQuestType : OsmElementQuestType<String> { | ||
|
||
override fun getTitle(tags: Map<String, String>) = 0 | ||
override fun download(bbox: BoundingBox, handler: (element: Element, geometry: ElementGeometry?) -> Unit) = false | ||
override fun isApplicableTo(element: Element):Boolean? = null | ||
override fun applyAnswerTo(answer: String, changes: StringMapChangesBuilder) {} | ||
override val icon = 0 | ||
override fun createForm(): AbstractQuestAnswerFragment<String> = object : AbstractQuestAnswerFragment<String>() {} | ||
override val commitMessage = "" | ||
override fun getApplicableElements(mapData: MapDataWithGeometry) = emptyList<Element>() | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/de/westnordost/osmapi/map/LightweightOsmMapDataFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package de.westnordost.osmapi.map | ||
|
||
import de.westnordost.osmapi.changesets.Changeset | ||
import de.westnordost.osmapi.map.data.* | ||
import java.util.* | ||
|
||
/** Same as OsmMapDataFactory only that it throws away the Changeset data included in the OSM | ||
* response */ | ||
class LightweightOsmMapDataFactory : MapDataFactory { | ||
override fun createNode( | ||
id: Long, version: Int, lat: Double, lon: Double, tags: MutableMap<String, String>?, | ||
changeset: Changeset?, dateEdited: Date? | ||
): Node = OsmNode(id, version, lat, lon, tags, null, dateEdited) | ||
|
||
override fun createWay( | ||
id: Long, version: Int, nodes: MutableList<Long>, tags: MutableMap<String, String>?, | ||
changeset: Changeset?, dateEdited: Date? | ||
): Way = OsmWay(id, version, nodes, tags, null, dateEdited) | ||
|
||
override fun createRelation( | ||
id: Long, version: Int, members: MutableList<RelationMember>, | ||
tags: MutableMap<String, String>?, changeset: Changeset?, dateEdited: Date? | ||
): Relation = OsmRelation(id, version, members, tags, null, dateEdited) | ||
|
||
override fun createRelationMember( | ||
ref: Long, role: String?, type: Element.Type | ||
): RelationMember = OsmRelationMember(ref, role, type) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package de.westnordost.osmapi.map | ||
|
||
import de.westnordost.osmapi.map.data.* | ||
import de.westnordost.osmapi.map.handler.MapDataHandler | ||
import de.westnordost.streetcomplete.data.osm.elementgeometry.ElementGeometry | ||
import de.westnordost.streetcomplete.data.osm.elementgeometry.ElementPointGeometry | ||
import de.westnordost.streetcomplete.util.MultiIterable | ||
|
||
interface MapDataWithGeometry : MapData { | ||
fun getNodeGeometry(id: Long): ElementPointGeometry? | ||
fun getWayGeometry(id: Long): ElementGeometry? | ||
fun getRelationGeometry(id: Long): ElementGeometry? | ||
|
||
fun getGeometry(elementType: Element.Type, id: Long): ElementGeometry? = when(elementType) { | ||
Element.Type.NODE -> getNodeGeometry(id) | ||
Element.Type.WAY -> getWayGeometry(id) | ||
Element.Type.RELATION -> getRelationGeometry(id) | ||
} | ||
} | ||
|
||
interface MapData : Iterable<Element> { | ||
val nodes: Collection<Node> | ||
val ways: Collection<Way> | ||
val relations: Collection<Relation> | ||
val boundingBox: BoundingBox? | ||
|
||
fun getNode(id: Long): Node? | ||
fun getWay(id: Long): Way? | ||
fun getRelation(id: Long): Relation? | ||
} | ||
|
||
open class MutableMapData : MapData, MapDataHandler { | ||
|
||
protected val nodesById: MutableMap<Long, Node> = mutableMapOf() | ||
protected val waysById: MutableMap<Long, Way> = mutableMapOf() | ||
protected val relationsById: MutableMap<Long, Relation> = mutableMapOf() | ||
override var boundingBox: BoundingBox? = null | ||
protected set | ||
|
||
override fun handle(bounds: BoundingBox) { boundingBox = bounds } | ||
override fun handle(node: Node) { nodesById[node.id] = node } | ||
override fun handle(way: Way) { waysById[way.id] = way } | ||
override fun handle(relation: Relation) { relationsById[relation.id] = relation } | ||
|
||
override val nodes get() = nodesById.values | ||
override val ways get() = waysById.values | ||
override val relations get() = relationsById.values | ||
|
||
override fun getNode(id: Long) = nodesById[id] | ||
override fun getWay(id: Long) = waysById[id] | ||
override fun getRelation(id: Long) = relationsById[id] | ||
|
||
fun addAll(elements: Iterable<Element>) { | ||
for (element in elements) { | ||
when(element) { | ||
is Node -> nodesById[element.id] = element | ||
is Way -> waysById[element.id] = element | ||
is Relation -> relationsById[element.id] = element | ||
} | ||
} | ||
} | ||
|
||
override fun iterator(): Iterator<Element> { | ||
val elements = MultiIterable<Element>() | ||
elements.add(nodes) | ||
elements.add(ways) | ||
elements.add(relations) | ||
return elements.iterator() | ||
} | ||
} | ||
|
||
fun MapData.isRelationComplete(id: Long): Boolean = | ||
getRelation(id)?.members?.all { member -> | ||
when (member.type!!) { | ||
Element.Type.NODE -> getNode(member.ref) != null | ||
Element.Type.WAY -> getWay(member.ref) != null && isWayComplete(member.ref) | ||
/* not being recursive here is deliberate. sub-relations are considered not relevant | ||
for the element geometry in StreetComplete (and OSM API call to get a "complete" | ||
relation also does not include sub-relations) */ | ||
Element.Type.RELATION -> getRelation(member.ref) != null | ||
} | ||
} ?: false | ||
|
||
fun MapData.isWayComplete(id: Long): Boolean = | ||
getWay(id)?.nodeIds?.all { getNode(it) != null } ?: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package de.westnordost.osmapi.map | ||
|
||
import de.westnordost.osmapi.map.data.BoundingBox | ||
import de.westnordost.streetcomplete.data.MapDataApi | ||
|
||
fun MapDataApi.getMap(bounds: BoundingBox): MapData { | ||
val result = MutableMapData() | ||
getMap(bounds, result) | ||
return result | ||
} | ||
|
||
fun MapDataApi.getWayComplete(id: Long): MapData { | ||
val result = MutableMapData() | ||
getWayComplete(id, result) | ||
return result | ||
} | ||
|
||
fun MapDataApi.getRelationComplete(id: Long): MapData { | ||
val result = MutableMapData() | ||
getRelationComplete(id, result) | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
761f286
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank You! This is an exceptional upgrade! 🚀