diff --git a/demo/maps/src/jvmMain/kotlin/Main.kt b/demo/maps/src/jvmMain/kotlin/Main.kt index 4c2fb7e..2b63878 100644 --- a/demo/maps/src/jvmMain/kotlin/Main.kt +++ b/demo/maps/src/jvmMain/kotlin/Main.kt @@ -12,10 +12,7 @@ import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Window import androidx.compose.ui.window.application -import center.sciprog.attributes.AlphaAttribute import center.sciprog.attributes.Attributes -import center.sciprog.attributes.ColorAttribute -import center.sciprog.attributes.ZAttribute import center.sciprog.maps.compose.* import center.sciprog.maps.coordinates.* import center.sciprog.maps.features.* diff --git a/maps-kt-features/src/commonMain/kotlin/center.sciprog.attributes/Attribute.kt b/maps-kt-features/src/commonMain/kotlin/center.sciprog.attributes/Attribute.kt index 23bdd06..563f1a7 100644 --- a/maps-kt-features/src/commonMain/kotlin/center.sciprog.attributes/Attribute.kt +++ b/maps-kt-features/src/commonMain/kotlin/center.sciprog.attributes/Attribute.kt @@ -1,29 +1,8 @@ package center.sciprog.attributes -import androidx.compose.ui.graphics.Color -import center.sciprog.maps.features.DragHandle -import center.sciprog.maps.features.DragListener -import center.sciprog.maps.features.FloatRange -import center.sciprog.maps.features.MouseListener - public interface Attribute -public object ZAttribute : Attribute - -public object DraggableAttribute : Attribute> - public interface SetAttribute : Attribute> -public object DragListenerAttribute : SetAttribute> +public object NameAttribute : Attribute -public object ClickListenerAttribute : SetAttribute> - -public object HoverListenerAttribute : SetAttribute> - -public object VisibleAttribute : Attribute - -public object ColorAttribute : Attribute - -public object ZoomRangeAttribute : Attribute - -public object AlphaAttribute : Attribute diff --git a/maps-kt-features/src/commonMain/kotlin/center.sciprog.attributes/Attributes.kt b/maps-kt-features/src/commonMain/kotlin/center.sciprog.attributes/Attributes.kt index 20d72e0..5e8ecc3 100644 --- a/maps-kt-features/src/commonMain/kotlin/center.sciprog.attributes/Attributes.kt +++ b/maps-kt-features/src/commonMain/kotlin/center.sciprog.attributes/Attributes.kt @@ -2,6 +2,7 @@ package center.sciprog.attributes import androidx.compose.runtime.Stable import center.sciprog.maps.features.Feature +import center.sciprog.maps.features.ZAttribute import kotlin.jvm.JvmInline @Stable diff --git a/maps-kt-features/src/commonMain/kotlin/center/sciprog/maps/features/Feature.kt b/maps-kt-features/src/commonMain/kotlin/center/sciprog/maps/features/Feature.kt index 7c5c20e..e826d6a 100644 --- a/maps-kt-features/src/commonMain/kotlin/center/sciprog/maps/features/Feature.kt +++ b/maps-kt-features/src/commonMain/kotlin/center/sciprog/maps/features/Feature.kt @@ -15,8 +15,7 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.dp import center.sciprog.attributes.Attributes -import center.sciprog.attributes.ColorAttribute -import center.sciprog.attributes.ZoomRangeAttribute +import center.sciprog.attributes.NameAttribute public typealias FloatRange = ClosedFloatingPointRange @@ -36,6 +35,9 @@ public val Feature<*>.color: Color? get() = attributes[ColorAttribute] public val Feature<*>.zoomRange: FloatRange get() = attributes[ZoomRangeAttribute] ?: Float.NEGATIVE_INFINITY..Float.POSITIVE_INFINITY +public val Feature<*>.name: String? + get() = attributes[NameAttribute] + public interface PainterFeature : Feature { @Composable public fun getPainter(): Painter diff --git a/maps-kt-features/src/commonMain/kotlin/center/sciprog/maps/features/compositeFeatures.kt b/maps-kt-features/src/commonMain/kotlin/center/sciprog/maps/features/compositeFeatures.kt index c016628..f874942 100644 --- a/maps-kt-features/src/commonMain/kotlin/center/sciprog/maps/features/compositeFeatures.kt +++ b/maps-kt-features/src/commonMain/kotlin/center/sciprog/maps/features/compositeFeatures.kt @@ -1,7 +1,6 @@ package center.sciprog.maps.features import center.sciprog.attributes.Attributes -import center.sciprog.attributes.ZAttribute public fun FeatureGroup.draggableLine( diff --git a/maps-kt-features/src/commonMain/kotlin/center/sciprog/maps/features/mapFeatureAttributes.kt b/maps-kt-features/src/commonMain/kotlin/center/sciprog/maps/features/mapFeatureAttributes.kt new file mode 100644 index 0000000..7726a18 --- /dev/null +++ b/maps-kt-features/src/commonMain/kotlin/center/sciprog/maps/features/mapFeatureAttributes.kt @@ -0,0 +1,23 @@ +package center.sciprog.maps.features + +import androidx.compose.ui.graphics.Color +import center.sciprog.attributes.Attribute +import center.sciprog.attributes.SetAttribute + +public object ZAttribute : Attribute + +public object DraggableAttribute : Attribute> + +public object DragListenerAttribute : SetAttribute> + +public object ClickListenerAttribute : SetAttribute> + +public object HoverListenerAttribute : SetAttribute> + +public object VisibleAttribute : Attribute + +public object ColorAttribute : Attribute + +public object ZoomRangeAttribute : Attribute + +public object AlphaAttribute : Attribute \ No newline at end of file diff --git a/maps-kt-features/src/jvmMain/kotlin/center/sciprog/maps/compose/mapControls.kt b/maps-kt-features/src/jvmMain/kotlin/center/sciprog/maps/compose/mapControls.kt index 3622c22..e11054d 100644 --- a/maps-kt-features/src/jvmMain/kotlin/center/sciprog/maps/compose/mapControls.kt +++ b/maps-kt-features/src/jvmMain/kotlin/center/sciprog/maps/compose/mapControls.kt @@ -7,9 +7,6 @@ import androidx.compose.ui.input.pointer.* import androidx.compose.ui.unit.DpOffset import androidx.compose.ui.unit.DpRect import androidx.compose.ui.unit.dp -import center.sciprog.attributes.ClickListenerAttribute -import center.sciprog.attributes.DraggableAttribute -import center.sciprog.attributes.HoverListenerAttribute import center.sciprog.maps.features.* import kotlin.math.max import kotlin.math.min diff --git a/maps-kt-features/src/jvmMain/kotlin/center/sciprog/maps/features/drawFeature.kt b/maps-kt-features/src/jvmMain/kotlin/center/sciprog/maps/features/drawFeature.kt index a1c65ab..c75e2db 100644 --- a/maps-kt-features/src/jvmMain/kotlin/center/sciprog/maps/features/drawFeature.kt +++ b/maps-kt-features/src/jvmMain/kotlin/center/sciprog/maps/features/drawFeature.kt @@ -11,7 +11,6 @@ import androidx.compose.ui.graphics.drawscope.translate import androidx.compose.ui.graphics.nativeCanvas import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.graphics.toArgb -import center.sciprog.attributes.AlphaAttribute import center.sciprog.attributes.plus import org.jetbrains.skia.Font import org.jetbrains.skia.Paint diff --git a/maps-kt-geojson/src/commonMain/kotlin/center/sciprog/maps/geojson/GeoJson.kt b/maps-kt-geojson/src/commonMain/kotlin/center/sciprog/maps/geojson/GeoJson.kt index 471ab40..8e9f149 100644 --- a/maps-kt-geojson/src/commonMain/kotlin/center/sciprog/maps/geojson/GeoJson.kt +++ b/maps-kt-geojson/src/commonMain/kotlin/center/sciprog/maps/geojson/GeoJson.kt @@ -34,6 +34,8 @@ public value class GeoJsonFeature(override val json: JsonObject) : GeoJson { } } +public fun GeoJsonFeature.getProperty(key: String): JsonElement? = json[key] ?: properties?.get(key) + @JvmInline public value class GeoJsonFeatureCollection(override val json: JsonObject) : GeoJson, Iterable { init { diff --git a/maps-kt-geojson/src/commonMain/kotlin/center/sciprog/maps/geojson/GeoJsonProperties.kt b/maps-kt-geojson/src/commonMain/kotlin/center/sciprog/maps/geojson/GeoJsonProperties.kt index fd9c573..d2058dd 100644 --- a/maps-kt-geojson/src/commonMain/kotlin/center/sciprog/maps/geojson/GeoJsonProperties.kt +++ b/maps-kt-geojson/src/commonMain/kotlin/center/sciprog/maps/geojson/GeoJsonProperties.kt @@ -3,6 +3,4 @@ package center.sciprog.maps.geojson import center.sciprog.attributes.Attribute import kotlinx.serialization.json.JsonObject -public object GeoJsonPropertiesAttribute : Attribute - -public object GeoJsonNameAttribute : Attribute \ No newline at end of file +public object GeoJsonPropertiesAttribute : Attribute \ No newline at end of file diff --git a/maps-kt-geojson/src/commonMain/kotlin/center/sciprog/maps/geojson/geoJsonFeature.kt b/maps-kt-geojson/src/commonMain/kotlin/center/sciprog/maps/geojson/geoJsonFeature.kt index ebd98eb..d677a72 100644 --- a/maps-kt-geojson/src/commonMain/kotlin/center/sciprog/maps/geojson/geoJsonFeature.kt +++ b/maps-kt-geojson/src/commonMain/kotlin/center/sciprog/maps/geojson/geoJsonFeature.kt @@ -2,6 +2,7 @@ package center.sciprog.maps.geojson import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.PointMode +import center.sciprog.attributes.NameAttribute import center.sciprog.maps.coordinates.Gmc import center.sciprog.maps.features.* import kotlinx.serialization.json.contentOrNull @@ -59,14 +60,21 @@ public fun FeatureGroup.geoJsonFeature( geoJson: GeoJsonFeature, id: String? = null, ): FeatureId> { - val geometry = geoJson.geometry ?: return group{} - val idOverride = geoJson.json["id"]?.jsonPrimitive?.contentOrNull ?: geoJson.properties?.get("id")?.jsonPrimitive?.contentOrNull ?: id - val colorOverride = geoJson.properties?.get("color")?.jsonPrimitive?.intOrNull?.let { Color(it) } - val jsonGeometry = geoJsonGeometry(geometry, idOverride) - return if( colorOverride!= null){ - jsonGeometry.color(colorOverride) - } else{ - jsonGeometry + val geometry = geoJson.geometry ?: return group {} + val idOverride = id ?: geoJson.getProperty("id")?.jsonPrimitive?.contentOrNull + + return geoJsonGeometry(geometry, idOverride).modifyAttributes { + geoJson.properties?.let { + GeoJsonPropertiesAttribute(it) + } + + geoJson.getProperty("name")?.jsonPrimitive?.contentOrNull?.let { + NameAttribute(it) + } + + geoJson.getProperty("color")?.jsonPrimitive?.intOrNull?.let { + ColorAttribute(Color(it)) + } } }