Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cycleway overlay: don't show contra-flow side of roundabouts etc. as missing when there is no data #5961

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}