From 748ba058a5d46cdb44ff0f5666365e14b8985634 Mon Sep 17 00:00:00 2001 From: Tobias Zwick Date: Mon, 14 Oct 2024 14:29:20 +0200 Subject: [PATCH] Cycleway overlay: don't show contra-flow side of roundabouts etc. as missing when there is no data (fixes #5959 / #5716) --- .../overlays/cycleway/CyclewayOverlay.kt | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/overlays/cycleway/CyclewayOverlay.kt b/app/src/main/java/de/westnordost/streetcomplete/overlays/cycleway/CyclewayOverlay.kt index 343cbdf920..7133c3ab81 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/overlays/cycleway/CyclewayOverlay.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/overlays/cycleway/CyclewayOverlay.kt @@ -9,6 +9,7 @@ import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry import de.westnordost.streetcomplete.data.osm.mapdata.filter import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement import de.westnordost.streetcomplete.osm.ALL_ROADS +import de.westnordost.streetcomplete.osm.Direction import de.westnordost.streetcomplete.osm.MAXSPEED_TYPE_KEYS import de.westnordost.streetcomplete.osm.bicycle_boulevard.BicycleBoulevard import de.westnordost.streetcomplete.osm.bicycle_boulevard.parseBicycleBoulevard @@ -18,6 +19,7 @@ import de.westnordost.streetcomplete.osm.cycleway.isAmbiguous import de.westnordost.streetcomplete.osm.cycleway.parseCyclewaySides import de.westnordost.streetcomplete.osm.cycleway_separate.SeparateCycleway import de.westnordost.streetcomplete.osm.cycleway_separate.parseSeparateCycleway +import de.westnordost.streetcomplete.osm.isInContraflowOfOneway import de.westnordost.streetcomplete.osm.isPrivateOnFoot import de.westnordost.streetcomplete.osm.surface.UNPAVED_SURFACES import de.westnordost.streetcomplete.overlays.Color @@ -90,14 +92,16 @@ private fun SeparateCycleway?.getColor() = when (this) { } private fun getStreetCyclewayStyle(element: Element, countryInfo: CountryInfo): PolylineStyle { - val cycleways = parseCyclewaySides(element.tags, countryInfo.isLeftHandTraffic) + val isLeftHandTraffic = countryInfo.isLeftHandTraffic + val cycleways = parseCyclewaySides(element.tags, isLeftHandTraffic) val isBicycleBoulevard = parseBicycleBoulevard(element.tags) == BicycleBoulevard.YES - val isNoCyclewayExpected = lazy { cyclewayTaggingNotExpected(element) || isPrivateOnFoot(element) } + val isNoCyclewayExpectedLeft = { cyclewayTaggingNotExpected(element, false, isLeftHandTraffic) } + val isNoCyclewayExpectedRight = { cyclewayTaggingNotExpected(element, true, isLeftHandTraffic) } return PolylineStyle( stroke = if (isBicycleBoulevard) StrokeStyle(Color.GOLD, dashed = true) else null, - strokeLeft = cycleways?.left?.cycleway.getStyle(countryInfo, isNoCyclewayExpected), - strokeRight = cycleways?.right?.cycleway.getStyle(countryInfo, isNoCyclewayExpected) + strokeLeft = cycleways?.left?.cycleway.getStyle(countryInfo, isNoCyclewayExpectedLeft), + strokeRight = cycleways?.right?.cycleway.getStyle(countryInfo, isNoCyclewayExpectedRight) ) } @@ -114,12 +118,28 @@ private val cyclewayTaggingNotExpectedFilter by lazy { """ or ~"${(MAXSPEED_TYPE_KEYS + "maxspeed").joinToString("|")}" ~ ".*:(zone)?:?([1-9]|[1-2][0-9]|30)" """.toElementFilterExpression() } -private fun cyclewayTaggingNotExpected(element: Element) = +private val cyclewayTaggingInContraflowNotExpectedFilter by lazy { """ + ways with + dual_carriageway = yes + or highway ~ primary_link|secondary_link|tertiary_link + or junction ~ roundabout|circular +""".toElementFilterExpression() } + +private fun cyclewayTaggingNotExpected( + element: Element, + isRightSide: Boolean, + isLeftHandTraffic: Boolean +): Boolean = cyclewayTaggingNotExpectedFilter.matches(element) + || isPrivateOnFoot(element) + || ( + isInContraflowOfOneway(element.tags, Direction.getDefault(isRightSide, isLeftHandTraffic)) + && cyclewayTaggingInContraflowNotExpectedFilter.matches(element) + ) private fun Cycleway?.getStyle( countryInfo: CountryInfo, - isNoCyclewayExpected: Lazy, + isNoCyclewayExpected: () -> Boolean, ): StrokeStyle = when (this) { TRACK -> StrokeStyle(Color.BLUE) @@ -163,5 +183,5 @@ private fun Cycleway?.getStyle( StrokeStyle(Color.DATA_REQUESTED) null -> - StrokeStyle(if (isNoCyclewayExpected.value) Color.INVISIBLE else Color.DATA_REQUESTED) + StrokeStyle(if (isNoCyclewayExpected()) Color.INVISIBLE else Color.DATA_REQUESTED) }