diff --git a/demo/maps/src/jvmMain/kotlin/Main.kt b/demo/maps/src/jvmMain/kotlin/Main.kt index cf8f6df..bbb2de6 100644 --- a/demo/maps/src/jvmMain/kotlin/Main.kt +++ b/demo/maps/src/jvmMain/kotlin/Main.kt @@ -96,8 +96,8 @@ fun App() { centerCoordinates?.let { group(id = "center") { - circle(center = it, color = Color.Blue, size = 1f) - text(position = it, it.toShortString(), color = Color.Blue) + circle(center = it, color = Color.Blue, id = "circle", size = 1f) + text(position = it, it.toShortString(), id = "text", color = Color.Blue) } } diff --git a/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapFeatureBuilder.kt b/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapFeatureBuilder.kt index 433e4f4..174844c 100644 --- a/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapFeatureBuilder.kt +++ b/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapFeatureBuilder.kt @@ -30,7 +30,7 @@ public interface MapFeatureBuilder { public val features: MutableMap - public fun attributes(): Map + public val attributes: Map //TODO use context receiver for that public fun FeatureId.draggable(enabled: Boolean = true) { @@ -42,7 +42,7 @@ internal class MapFeatureBuilderImpl( override val features: SnapshotStateMap, ) : MapFeatureBuilder { - private val attributes = SnapshotStateMap, in Any?>>() + private val _attributes = SnapshotStateMap, in Any?>>() private fun generateID(feature: MapFeature): FeatureId = "@feature[${feature.hashCode().toUInt()}]" @@ -54,11 +54,11 @@ internal class MapFeatureBuilderImpl( } override fun setAttribute(id: FeatureId, key: MapFeatureAttributeKey, value: T) { - attributes.getOrPut(id) { SnapshotStateMap() }[key] = value + _attributes.getOrPut(id) { SnapshotStateMap() }[key] = value } - override fun attributes(): Map = - attributes.mapValues { MapFeatureAttributeSet(it.value) } + override val attributes: Map + get() = _attributes.mapValues { MapFeatureAttributeSet(it.value) } } diff --git a/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapView.kt b/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapView.kt index 09aedd2..dd29373 100644 --- a/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapView.kt +++ b/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapView.kt @@ -104,15 +104,15 @@ public fun MapView( buildFeatures: @Composable (MapFeatureBuilder.() -> Unit) = {}, ) { - var viewPointOverride by remember { mutableStateOf(initialViewPoint ?: MapViewPoint.globe) } + var viewPointOverride by remember(initialViewPoint, initialRectangle) { mutableStateOf(initialViewPoint ?: MapViewPoint.globe) } val featuresBuilder = MapFeatureBuilderImpl(mutableStateMapOf()).apply { buildFeatures() } - val features: SnapshotStateMap = remember { featuresBuilder.features } + val features: SnapshotStateMap = remember(buildFeatures) { featuresBuilder.features } - val attributes = remember { featuresBuilder.attributes() } + val attributes = remember(buildFeatures) { featuresBuilder.attributes } - val featureDrag = remember { + val featureDrag by derivedStateOf { DragHandle.withPrimaryButton { _, start, end -> val zoom = start.zoom attributes.filterValues {