From 87ed5ac3e112f2e365d19664e85033937dc2be3d Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sat, 7 Jan 2023 15:17:38 +0100 Subject: [PATCH] use :left/right/both in custom overlays --- .../overlays/custom/CustomOverlay.kt | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/overlays/custom/CustomOverlay.kt b/app/src/main/java/de/westnordost/streetcomplete/overlays/custom/CustomOverlay.kt index 3a8c0eea72..1eff1bb2e4 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/overlays/custom/CustomOverlay.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/overlays/custom/CustomOverlay.kt @@ -42,15 +42,43 @@ class CustomOverlay(val prefs: SharedPreferences) : Overlay { } private fun getStyle(element: Element, colorKeySelector: Regex?): Style { - val color = if (colorKeySelector == null) Color.LIME + val color by lazy { + if (colorKeySelector == null) Color.LIME else createColorFromString(element.tags.mapNotNull { if (it.key.matches(colorKeySelector)) it.value + it.key else null }.joinToString().takeIf { it.isNotEmpty() }) + } + + // get left/right style if there is some match + var leftColor = "" + var rightColor = "" + if (colorKeySelector != null && element !is Node) // avoid doing needless work + for ((k, v) in element.tags) { + if (!k.matches(colorKeySelector)) continue + // contains or endsWith? contains will also match things like sidewalk:left:surface, which may be wanted or not... + if (v == "both" || k.contains(":both")) { + leftColor = createColorFromString(v + k) + rightColor = leftColor + break + } + if (v == "right" || k.contains(":right")) { + rightColor = createColorFromString(v + k) + continue + } + if (v == "left" || k.contains(":left")) + leftColor = createColorFromString(v + k) + } + return when { - element is Node -> PointStyle("ic_custom_overlay_poi", element.tags["name"]) + element is Node -> PointStyle("ic_custom_overlay_poi", element.tags["name"]) // currently no coloring possible... IS_AREA_EXPRESSION.matches(element) -> PolygonStyle(color, label = element.tags["name"]) + leftColor.isNotEmpty() || rightColor.isNotEmpty() -> PolylineStyle( + stroke = null, + strokeLeft = leftColor.takeIf { it.isNotEmpty() }?.let { StrokeStyle(it) }, + strokeRight = rightColor.takeIf { it.isNotEmpty() }?.let { StrokeStyle(it) } + ) else -> PolylineStyle(StrokeStyle(color)) // no label for lines, because this often leads to duplicate labels e.g. for roads } }