From b71d1943ec2726eded034223ff3ec3b960e7e374 Mon Sep 17 00:00:00 2001 From: Tobias Zwick Date: Wed, 15 Jan 2025 22:36:33 +0100 Subject: [PATCH] don't show scalebar when the map is not initialized yet (#249) --- .../dev/sargunv/maplibrecompose/material3/controls/ScaleBar.kt | 3 +++ .../kotlin/dev/sargunv/maplibrecompose/compose/CameraState.kt | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/maplibre-compose-material3/src/commonMain/kotlin/dev/sargunv/maplibrecompose/material3/controls/ScaleBar.kt b/lib/maplibre-compose-material3/src/commonMain/kotlin/dev/sargunv/maplibrecompose/material3/controls/ScaleBar.kt index b75fd6fc..573c2a0b 100644 --- a/lib/maplibre-compose-material3/src/commonMain/kotlin/dev/sargunv/maplibrecompose/material3/controls/ScaleBar.kt +++ b/lib/maplibre-compose-material3/src/commonMain/kotlin/dev/sargunv/maplibrecompose/material3/controls/ScaleBar.kt @@ -56,6 +56,9 @@ public fun ScaleBar( textStyle: TextStyle = MaterialTheme.typography.labelSmall, alignment: Alignment.Horizontal = Alignment.Start, ) { + // when map is not fully initialized yet + if (metersPerDp == 0.0) return + val textMeasurer = rememberTextMeasurer() // longest possible text val maxTextSizePx = diff --git a/lib/maplibre-compose/src/commonMain/kotlin/dev/sargunv/maplibrecompose/compose/CameraState.kt b/lib/maplibre-compose/src/commonMain/kotlin/dev/sargunv/maplibrecompose/compose/CameraState.kt index 38175352..db4799bb 100644 --- a/lib/maplibre-compose/src/commonMain/kotlin/dev/sargunv/maplibrecompose/compose/CameraState.kt +++ b/lib/maplibre-compose/src/commonMain/kotlin/dev/sargunv/maplibrecompose/compose/CameraState.kt @@ -57,7 +57,7 @@ public class CameraState internal constructor(firstPosition: CameraPosition) { public val moveReason: CameraMoveReason get() = moveReasonState.value - /** meters per dp at the target position */ + /** meters per dp at the target position. Zero when the map is not initialized yet. */ public val metersPerDpAtTarget: Double get() = metersPerDpAtTargetState.value