From 576c2751fef695365bc0fd63251627ef84c0993c Mon Sep 17 00:00:00 2001 From: Sargun Vohra Date: Sun, 12 Jan 2025 15:27:13 -0800 Subject: [PATCH] repro issue #244 --- .../files/data/openbeta-crags.json | 8 +++++++ .../demoapp/demos/StyleSwitcherDemo.kt | 24 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 demo-app/src/commonMain/composeResources/files/data/openbeta-crags.json diff --git a/demo-app/src/commonMain/composeResources/files/data/openbeta-crags.json b/demo-app/src/commonMain/composeResources/files/data/openbeta-crags.json new file mode 100644 index 00000000..b827fabc --- /dev/null +++ b/demo-app/src/commonMain/composeResources/files/data/openbeta-crags.json @@ -0,0 +1,8 @@ +{ + "tiles": [ + "https://maptiles.openbeta.io/crags/{z}/{x}/{y}.pbf" + ], + "promoteId": "id", + "maxzoom": 11, + "attribution": "© OpenBeta contributors" +} diff --git a/demo-app/src/commonMain/kotlin/dev/sargunv/maplibrecompose/demoapp/demos/StyleSwitcherDemo.kt b/demo-app/src/commonMain/kotlin/dev/sargunv/maplibrecompose/demoapp/demos/StyleSwitcherDemo.kt index 933d47d9..7ac5c98f 100644 --- a/demo-app/src/commonMain/kotlin/dev/sargunv/maplibrecompose/demoapp/demos/StyleSwitcherDemo.kt +++ b/demo-app/src/commonMain/kotlin/dev/sargunv/maplibrecompose/demoapp/demos/StyleSwitcherDemo.kt @@ -14,16 +14,24 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.text.style.TextOverflow import dev.sargunv.maplibrecompose.compose.MaplibreMap +import dev.sargunv.maplibrecompose.compose.layer.SymbolLayer import dev.sargunv.maplibrecompose.compose.rememberCameraState import dev.sargunv.maplibrecompose.compose.rememberStyleState +import dev.sargunv.maplibrecompose.compose.source.rememberVectorSource import dev.sargunv.maplibrecompose.core.CameraPosition import dev.sargunv.maplibrecompose.demoapp.ALL_STYLES import dev.sargunv.maplibrecompose.demoapp.Demo import dev.sargunv.maplibrecompose.demoapp.DemoMapControls import dev.sargunv.maplibrecompose.demoapp.DemoOrnamentSettings import dev.sargunv.maplibrecompose.demoapp.DemoScaffold +import dev.sargunv.maplibrecompose.demoapp.generated.Res import dev.sargunv.maplibrecompose.demoapp.getDefaultColorScheme +import dev.sargunv.maplibrecompose.expressions.dsl.const +import dev.sargunv.maplibrecompose.expressions.dsl.convertToString +import dev.sargunv.maplibrecompose.expressions.dsl.feature +import dev.sargunv.maplibrecompose.expressions.value.SymbolAnchor import io.github.dellisd.spatialk.geojson.Position +import org.jetbrains.compose.resources.ExperimentalResourceApi private val NEW_YORK = Position(latitude = 40.744, longitude = -73.981) @@ -32,6 +40,7 @@ object StyleSwitcherDemo : Demo { override val description = "Switch between different map styles at runtime." @Composable + @OptIn(ExperimentalResourceApi::class) override fun Component(navigateUp: () -> Unit) { var selectedIndex by remember { mutableStateOf(0) } @@ -48,7 +57,20 @@ object StyleSwitcherDemo : Demo { cameraState = cameraState, styleState = styleState, ornamentSettings = DemoOrnamentSettings(), - ) + ) { + val crags = rememberVectorSource( + id = "openbeta-crags", + uri = Res.getUri("files/data/openbeta-crags.json") + ) + SymbolLayer( + id = "crag-name-label", + source = crags, + sourceLayer = "crags", + iconAnchor = const(SymbolAnchor.Center), + textField = feature.get("name").convertToString(), + textFont = const(listOf("Noto Sans Regular")) + ) + } DemoMapControls(cameraState, styleState) }