diff --git a/maps-kt-compose/src/jvmMain/kotlin/center/sciprog/maps/compose/MapViewJvm.kt b/maps-kt-compose/src/jvmMain/kotlin/center/sciprog/maps/compose/MapViewJvm.kt index 68527cb..e4c09b8 100644 --- a/maps-kt-compose/src/jvmMain/kotlin/center/sciprog/maps/compose/MapViewJvm.kt +++ b/maps-kt-compose/src/jvmMain/kotlin/center/sciprog/maps/compose/MapViewJvm.kt @@ -15,10 +15,7 @@ import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.dp import center.sciprog.maps.coordinates.Gmc -import center.sciprog.maps.features.FeaturesState -import center.sciprog.maps.features.PainterFeature -import center.sciprog.maps.features.ViewConfig -import center.sciprog.maps.features.drawFeature +import center.sciprog.maps.features.* import kotlinx.coroutines.launch import kotlinx.coroutines.supervisorScope import mu.KotlinLogging @@ -130,7 +127,7 @@ public actual fun MapView( ) } - featuresState.features.values.filter { viewPoint.zoom in it.zoomRange }.forEach { feature -> + featuresState.features.values.filter { viewPoint.zoom in it.zoomRange }.sortedBy { it.depth }.forEach { feature -> drawFeature(state, painterCache, feature) } } diff --git a/maps-kt-features/src/commonMain/kotlin/center/sciprog/maps/features/AttributeMap.kt b/maps-kt-features/src/commonMain/kotlin/center/sciprog/maps/features/AttributeMap.kt index e158f86..f996ff3 100644 --- a/maps-kt-features/src/commonMain/kotlin/center/sciprog/maps/features/AttributeMap.kt +++ b/maps-kt-features/src/commonMain/kotlin/center/sciprog/maps/features/AttributeMap.kt @@ -3,6 +3,8 @@ package center.sciprog.maps.features import androidx.compose.runtime.mutableStateMapOf import androidx.compose.ui.graphics.Color +public object DepthAttribute : Feature.Attribute + public object DraggableAttribute : Feature.Attribute> public object SelectableAttribute : Feature.Attribute<(FeatureId<*>, SelectableFeature<*>) -> Unit> @@ -14,7 +16,7 @@ public object ColorAttribute : Feature.Attribute public class AttributeMap { public val map: MutableMap, Any> = mutableStateMapOf() - public fun > setAttribute( + public operator fun > set( attribute: A, attrValue: T?, ) { @@ -42,4 +44,10 @@ public class AttributeMap { override fun hashCode(): Int = map.hashCode() override fun toString(): String = "AttributeMap(value=${map.entries})" -} \ No newline at end of file +} + +public var Feature<*>.depth: Float + get() = attributes[DepthAttribute] ?: 0f + set(value) { + attributes[DepthAttribute] = value + } \ No newline at end of file diff --git a/maps-kt-features/src/commonMain/kotlin/center/sciprog/maps/features/FeaturesState.kt b/maps-kt-features/src/commonMain/kotlin/center/sciprog/maps/features/FeaturesState.kt index 2013b79..d077032 100644 --- a/maps-kt-features/src/commonMain/kotlin/center/sciprog/maps/features/FeaturesState.kt +++ b/maps-kt-features/src/commonMain/kotlin/center/sciprog/maps/features/FeaturesState.kt @@ -44,7 +44,7 @@ public class FeaturesState(public val coordinateSpace: CoordinateSpace< public fun , V> setAttribute(id: FeatureId, key: Feature.Attribute, value: V?) { - getFeature(id).attributes.setAttribute(key, value) + getFeature(id).attributes.set(key, value) } //TODO use context receiver for that diff --git a/maps-kt-scheme/src/commonMain/kotlin/center/sciprog/maps/scheme/SchemeFeatureState.kt b/maps-kt-scheme/src/commonMain/kotlin/center/sciprog/maps/scheme/schemeFeatures.kt similarity index 94% rename from maps-kt-scheme/src/commonMain/kotlin/center/sciprog/maps/scheme/SchemeFeatureState.kt rename to maps-kt-scheme/src/commonMain/kotlin/center/sciprog/maps/scheme/schemeFeatures.kt index b244dab..89a4be1 100644 --- a/maps-kt-scheme/src/commonMain/kotlin/center/sciprog/maps/scheme/SchemeFeatureState.kt +++ b/maps-kt-scheme/src/commonMain/kotlin/center/sciprog/maps/scheme/schemeFeatures.kt @@ -23,7 +23,12 @@ fun FeaturesState.background( offset, XY(width + offset.x, height + offset.y) ) - return scalableImage(box, id = id, painter = painter) + return feature( + id, + ScalableImageFeature(coordinateSpace, box, painter = painter).apply { + depth = -100f + } + ) } fun FeaturesState.circle( diff --git a/maps-kt-scheme/src/jvmMain/kotlin/center/sciprog/maps/scheme/SchemeView.kt b/maps-kt-scheme/src/jvmMain/kotlin/center/sciprog/maps/scheme/SchemeView.kt index dbc8a20..01a5edf 100644 --- a/maps-kt-scheme/src/jvmMain/kotlin/center/sciprog/maps/scheme/SchemeView.kt +++ b/maps-kt-scheme/src/jvmMain/kotlin/center/sciprog/maps/scheme/SchemeView.kt @@ -48,14 +48,12 @@ public fun SchemeView( } clipRect { - featuresState.features.values.filterIsInstance>().forEach { background -> - drawFeature(state, painterCache, background) - } - featuresState.features.values.filter { - it !is ScalableImageFeature && viewPoint.zoom in it.zoomRange - }.forEach { feature -> - drawFeature(state, painterCache, feature) - } + featuresState.features.values + .filter { viewPoint.zoom in it.zoomRange } + .sortedBy { it.depth } + .forEach { background -> + drawFeature(state, painterCache, background) + } } selectRect?.let { dpRect -> val rect = dpRect.toRect()