From 51ba800e5bb11e5c16b0deabcaa6479be2eef6ca Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Wed, 1 Jul 2026 06:39:35 +0000 Subject: fix(layers): TSS string constants + close openRawResource stream --- .../app/src/main/kotlin/org/terst/nav/ui/MapHandler.kt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/android-app/app/src/main/kotlin/org/terst/nav/ui/MapHandler.kt b/android-app/app/src/main/kotlin/org/terst/nav/ui/MapHandler.kt index 02c9fca..f753335 100644 --- a/android-app/app/src/main/kotlin/org/terst/nav/ui/MapHandler.kt +++ b/android-app/app/src/main/kotlin/org/terst/nav/ui/MapHandler.kt @@ -104,6 +104,10 @@ class MapHandler(private val maplibreMap: MapLibreMap) { private val ATON_LABELS_ID = "aton-labels" private var atonSource: GeoJsonSource? = null + private val TSS_SOURCE_ID = "tss-source" + private val TSS_LANES_ID = "tss-lanes-layer" + private val TSS_SEP_ID = "tss-sep-layer" + private val FISHING_LINE_SOURCE_ID = "fishing-line-source" private val FISHING_LINE_LAYER_ID = "fishing-line-layer" private var fishingLineSource: GeoJsonSource? = null @@ -553,11 +557,11 @@ class MapHandler(private val maplibreMap: MapLibreMap) { */ fun setupTssLayer(style: Style, context: Context, visible: Boolean) { val json = context.resources.openRawResource(R.raw.pacific_tss) - .bufferedReader().readText() - val src = GeoJsonSource("tss-source", FeatureCollection.fromJson(json)) + .bufferedReader().use { it.readText() } + val src = GeoJsonSource(TSS_SOURCE_ID, FeatureCollection.fromJson(json)) style.addSource(src) val v = if (visible) "visible" else "none" - style.addLayer(FillLayer("tss-lanes-layer", "tss-source").apply { + style.addLayer(FillLayer(TSS_LANES_ID, TSS_SOURCE_ID).apply { setFilter(Expression.neq( Expression.get("type"), Expression.literal("separation_zone"))) setProperties( @@ -574,7 +578,7 @@ class MapHandler(private val maplibreMap: MapLibreMap) { PropertyFactory.visibility(v) ) }) - style.addLayer(FillLayer("tss-sep-layer", "tss-source").apply { + style.addLayer(FillLayer(TSS_SEP_ID, TSS_SOURCE_ID).apply { setFilter(Expression.eq( Expression.get("type"), Expression.literal("separation_zone"))) setProperties( @@ -588,8 +592,8 @@ class MapHandler(private val maplibreMap: MapLibreMap) { /** Shows or hides the TSS lanes and separation zone layers on a live style. */ fun setTssLayerVisible(style: Style, visible: Boolean) { val v = if (visible) "visible" else "none" - style.getLayer("tss-lanes-layer")?.setProperties(PropertyFactory.visibility(v)) - style.getLayer("tss-sep-layer")?.setProperties(PropertyFactory.visibility(v)) + style.getLayer(TSS_LANES_ID)?.setProperties(PropertyFactory.visibility(v)) + style.getLayer(TSS_SEP_ID)?.setProperties(PropertyFactory.visibility(v)) } /** Clears all tack markers. */ -- cgit v1.2.3