-
-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
redo StreetParkingCreator (fixes #4634)
- Loading branch information
1 parent
e345e4b
commit 6742ab0
Showing
6 changed files
with
125 additions
and
65 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 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
80 changes: 38 additions & 42 deletions
80
app/src/main/java/de/westnordost/streetcomplete/osm/street_parking/StreetParkingCreator.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,66 +1,62 @@ | ||
package de.westnordost.streetcomplete.osm.street_parking | ||
|
||
import de.westnordost.streetcomplete.osm.Tags | ||
import de.westnordost.streetcomplete.osm.expandSides | ||
import de.westnordost.streetcomplete.osm.hasCheckDateForKey | ||
import de.westnordost.streetcomplete.osm.mergeSides | ||
import de.westnordost.streetcomplete.osm.updateCheckDateForKey | ||
|
||
fun LeftAndRightStreetParking.applyTo(tags: Tags) { | ||
val currentParking = createStreetParkingSides(tags) | ||
|
||
// first clear previous | ||
val keyToRemove = Regex("parking:lane:(both|left|right)(:(parallel|diagonal|perpendicular))?") | ||
for (key in tags.keys) { | ||
if (key.matches(keyToRemove)) tags.remove(key) | ||
} | ||
|
||
val r = right ?: currentParking?.right | ||
val l = left ?: currentParking?.left | ||
|
||
// parking:lane:<left/right/both> | ||
val laneRight = r?.toOsmLaneValue() | ||
val laneLeft = l?.toOsmLaneValue() | ||
|
||
if (laneLeft == laneRight) { | ||
if (laneLeft != null) tags["parking:lane:both"] = laneLeft | ||
} else { | ||
if (laneLeft != null) tags["parking:lane:left"] = laneLeft | ||
if (laneRight != null) tags["parking:lane:right"] = laneRight | ||
} | ||
|
||
// parking:lane:<left/right/both>:<parallel/diagonal/perpendicular> | ||
val positionRight = (r as? StreetParkingPositionAndOrientation)?.position?.toOsmValue() | ||
val positionLeft = (l as? StreetParkingPositionAndOrientation)?.position?.toOsmValue() | ||
|
||
if (laneLeft == laneRight && positionLeft == positionRight) { | ||
if (positionLeft != null) tags["parking:lane:both:$laneLeft"] = positionLeft | ||
} else { | ||
if (positionLeft != null) tags["parking:lane:left:$laneLeft"] = positionLeft | ||
if (positionRight != null) tags["parking:lane:right:$laneRight"] = positionRight | ||
} | ||
if (left == null && right == null) return | ||
/* for being able to modify only one side (e.g. `left` is null while `right` is not null), | ||
the sides conflated in :both keys need to be separated first. E.g. parking:lane=no | ||
when left is made separate should become | ||
- parking:lane:right=no | ||
- parking:lane:left=separate | ||
First separating the values and then later conflating them again, if possible, solves this. | ||
*/ | ||
tags.expandSides("parking:lane", null, true) | ||
ParkingOrientation.values().forEach { tags.expandSides("parking:lane", it.osmValue, true) } | ||
|
||
// parking:lane:<left/right> | ||
left?.applyTo(tags, "left") | ||
right?.applyTo(tags, "right") | ||
|
||
tags.mergeSides("parking:lane") | ||
ParkingOrientation.values().forEach { tags.mergeSides("parking:lane", it.osmValue) } | ||
|
||
if (!tags.hasChanges || tags.hasCheckDateForKey("parking:lane")) { | ||
tags.updateCheckDateForKey("parking:lane") | ||
} | ||
} | ||
|
||
private fun StreetParking.applyTo(tags: Tags, side: String) { | ||
tags["parking:lane:$side"] = osmLaneValue | ||
// clear previous orientation(s) | ||
ParkingOrientation.values().forEach { tags.remove("parking:lane:$side:${it.osmValue}") } | ||
if (this is StreetParkingPositionAndOrientation) { | ||
tags["parking:lane:$side:$osmLaneValue"] = position.osmValue | ||
} | ||
} | ||
|
||
/** get the OSM value for the parking:lane key */ | ||
private fun StreetParking.toOsmLaneValue(): String = when (this) { | ||
is StreetParkingPositionAndOrientation -> orientation.toOsmValue() | ||
private val StreetParking.osmLaneValue get() = when (this) { | ||
is StreetParkingPositionAndOrientation -> orientation.osmValue | ||
NoStreetParking -> "no" | ||
StreetParkingSeparate -> "separate" | ||
UnknownStreetParking, IncompleteStreetParking -> throw IllegalArgumentException("Attempting to tag invalid parking lane") | ||
} | ||
|
||
private fun ParkingPosition.toOsmValue() = when (this) { | ||
ParkingPosition.ON_STREET -> "on_street" | ||
ParkingPosition.HALF_ON_KERB -> "half_on_kerb" | ||
ParkingPosition.ON_KERB -> "on_kerb" | ||
ParkingPosition.STREET_SIDE -> "street_side" | ||
private val ParkingPosition.osmValue get() = when (this) { | ||
ParkingPosition.ON_STREET -> "on_street" | ||
ParkingPosition.HALF_ON_KERB -> "half_on_kerb" | ||
ParkingPosition.ON_KERB -> "on_kerb" | ||
ParkingPosition.STREET_SIDE -> "street_side" | ||
ParkingPosition.PAINTED_AREA_ONLY -> "painted_area_only" | ||
} | ||
|
||
private fun ParkingOrientation.toOsmValue() = when (this) { | ||
ParkingOrientation.PARALLEL -> "parallel" | ||
ParkingOrientation.DIAGONAL -> "diagonal" | ||
private val ParkingOrientation.osmValue get() = when (this) { | ||
ParkingOrientation.PARALLEL -> "parallel" | ||
ParkingOrientation.DIAGONAL -> "diagonal" | ||
ParkingOrientation.PERPENDICULAR -> "perpendicular" | ||
} |
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