Attributes cleanup
This commit is contained in:
parent
ffc77dc611
commit
ad938a614a
@ -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.*
|
||||
|
@ -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<T>
|
||||
|
||||
public object ZAttribute : Attribute<Float>
|
||||
|
||||
public object DraggableAttribute : Attribute<DragHandle<Any>>
|
||||
|
||||
public interface SetAttribute<V> : Attribute<Set<V>>
|
||||
|
||||
public object DragListenerAttribute : SetAttribute<DragListener<Any>>
|
||||
public object NameAttribute : Attribute<String>
|
||||
|
||||
public object ClickListenerAttribute : SetAttribute<MouseListener<Any>>
|
||||
|
||||
public object HoverListenerAttribute : SetAttribute<MouseListener<Any>>
|
||||
|
||||
public object VisibleAttribute : Attribute<Boolean>
|
||||
|
||||
public object ColorAttribute : Attribute<Color>
|
||||
|
||||
public object ZoomRangeAttribute : Attribute<FloatRange>
|
||||
|
||||
public object AlphaAttribute : Attribute<Float>
|
||||
|
@ -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
|
||||
|
@ -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<Float>
|
||||
|
||||
@ -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<T : Any> : Feature<T> {
|
||||
@Composable
|
||||
public fun getPainter(): Painter
|
||||
|
@ -1,7 +1,6 @@
|
||||
package center.sciprog.maps.features
|
||||
|
||||
import center.sciprog.attributes.Attributes
|
||||
import center.sciprog.attributes.ZAttribute
|
||||
|
||||
|
||||
public fun <T : Any> FeatureGroup<T>.draggableLine(
|
||||
|
@ -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<Float>
|
||||
|
||||
public object DraggableAttribute : Attribute<DragHandle<Any>>
|
||||
|
||||
public object DragListenerAttribute : SetAttribute<DragListener<Any>>
|
||||
|
||||
public object ClickListenerAttribute : SetAttribute<MouseListener<Any>>
|
||||
|
||||
public object HoverListenerAttribute : SetAttribute<MouseListener<Any>>
|
||||
|
||||
public object VisibleAttribute : Attribute<Boolean>
|
||||
|
||||
public object ColorAttribute : Attribute<Color>
|
||||
|
||||
public object ZoomRangeAttribute : Attribute<FloatRange>
|
||||
|
||||
public object AlphaAttribute : Attribute<Float>
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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<GeoJsonFeature> {
|
||||
init {
|
||||
|
@ -3,6 +3,4 @@ package center.sciprog.maps.geojson
|
||||
import center.sciprog.attributes.Attribute
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
|
||||
public object GeoJsonPropertiesAttribute : Attribute<JsonObject>
|
||||
|
||||
public object GeoJsonNameAttribute : Attribute<String>
|
||||
public object GeoJsonPropertiesAttribute : Attribute<JsonObject>
|
@ -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<Gmc>.geoJsonFeature(
|
||||
geoJson: GeoJsonFeature,
|
||||
id: String? = null,
|
||||
): FeatureId<Feature<Gmc>> {
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user