Skip to content

Commit

Permalink
Cycleway overlay: don't show contra-flow side of roundabouts etc. as …
Browse files Browse the repository at this point in the history
…missing when there is no data (fixes #5959 / #5716)
  • Loading branch information
westnordost committed Oct 14, 2024
1 parent bd7905f commit 748ba05
Showing 1 changed file with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
)
}

Expand All @@ -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<Boolean>,
isNoCyclewayExpected: () -> Boolean,
): StrokeStyle = when (this) {
TRACK ->
StrokeStyle(Color.BLUE)
Expand Down Expand Up @@ -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)
}

0 comments on commit 748ba05

Please sign in to comment.