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