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.unit.dp
|
||||||
import androidx.compose.ui.window.Window
|
import androidx.compose.ui.window.Window
|
||||||
import androidx.compose.ui.window.application
|
import androidx.compose.ui.window.application
|
||||||
import center.sciprog.attributes.AlphaAttribute
|
|
||||||
import center.sciprog.attributes.Attributes
|
import center.sciprog.attributes.Attributes
|
||||||
import center.sciprog.attributes.ColorAttribute
|
|
||||||
import center.sciprog.attributes.ZAttribute
|
|
||||||
import center.sciprog.maps.compose.*
|
import center.sciprog.maps.compose.*
|
||||||
import center.sciprog.maps.coordinates.*
|
import center.sciprog.maps.coordinates.*
|
||||||
import center.sciprog.maps.features.*
|
import center.sciprog.maps.features.*
|
||||||
|
@ -1,29 +1,8 @@
|
|||||||
package center.sciprog.attributes
|
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 interface Attribute<T>
|
||||||
|
|
||||||
public object ZAttribute : Attribute<Float>
|
|
||||||
|
|
||||||
public object DraggableAttribute : Attribute<DragHandle<Any>>
|
|
||||||
|
|
||||||
public interface SetAttribute<V> : Attribute<Set<V>>
|
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 androidx.compose.runtime.Stable
|
||||||
import center.sciprog.maps.features.Feature
|
import center.sciprog.maps.features.Feature
|
||||||
|
import center.sciprog.maps.features.ZAttribute
|
||||||
import kotlin.jvm.JvmInline
|
import kotlin.jvm.JvmInline
|
||||||
|
|
||||||
@Stable
|
@Stable
|
||||||
|
@ -15,8 +15,7 @@ import androidx.compose.ui.unit.Dp
|
|||||||
import androidx.compose.ui.unit.DpSize
|
import androidx.compose.ui.unit.DpSize
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import center.sciprog.attributes.Attributes
|
import center.sciprog.attributes.Attributes
|
||||||
import center.sciprog.attributes.ColorAttribute
|
import center.sciprog.attributes.NameAttribute
|
||||||
import center.sciprog.attributes.ZoomRangeAttribute
|
|
||||||
|
|
||||||
public typealias FloatRange = ClosedFloatingPointRange<Float>
|
public typealias FloatRange = ClosedFloatingPointRange<Float>
|
||||||
|
|
||||||
@ -36,6 +35,9 @@ public val Feature<*>.color: Color? get() = attributes[ColorAttribute]
|
|||||||
public val Feature<*>.zoomRange: FloatRange
|
public val Feature<*>.zoomRange: FloatRange
|
||||||
get() = attributes[ZoomRangeAttribute] ?: Float.NEGATIVE_INFINITY..Float.POSITIVE_INFINITY
|
get() = attributes[ZoomRangeAttribute] ?: Float.NEGATIVE_INFINITY..Float.POSITIVE_INFINITY
|
||||||
|
|
||||||
|
public val Feature<*>.name: String?
|
||||||
|
get() = attributes[NameAttribute]
|
||||||
|
|
||||||
public interface PainterFeature<T : Any> : Feature<T> {
|
public interface PainterFeature<T : Any> : Feature<T> {
|
||||||
@Composable
|
@Composable
|
||||||
public fun getPainter(): Painter
|
public fun getPainter(): Painter
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package center.sciprog.maps.features
|
package center.sciprog.maps.features
|
||||||
|
|
||||||
import center.sciprog.attributes.Attributes
|
import center.sciprog.attributes.Attributes
|
||||||
import center.sciprog.attributes.ZAttribute
|
|
||||||
|
|
||||||
|
|
||||||
public fun <T : Any> FeatureGroup<T>.draggableLine(
|
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.DpOffset
|
||||||
import androidx.compose.ui.unit.DpRect
|
import androidx.compose.ui.unit.DpRect
|
||||||
import androidx.compose.ui.unit.dp
|
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 center.sciprog.maps.features.*
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
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.nativeCanvas
|
||||||
import androidx.compose.ui.graphics.painter.Painter
|
import androidx.compose.ui.graphics.painter.Painter
|
||||||
import androidx.compose.ui.graphics.toArgb
|
import androidx.compose.ui.graphics.toArgb
|
||||||
import center.sciprog.attributes.AlphaAttribute
|
|
||||||
import center.sciprog.attributes.plus
|
import center.sciprog.attributes.plus
|
||||||
import org.jetbrains.skia.Font
|
import org.jetbrains.skia.Font
|
||||||
import org.jetbrains.skia.Paint
|
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
|
@JvmInline
|
||||||
public value class GeoJsonFeatureCollection(override val json: JsonObject) : GeoJson, Iterable<GeoJsonFeature> {
|
public value class GeoJsonFeatureCollection(override val json: JsonObject) : GeoJson, Iterable<GeoJsonFeature> {
|
||||||
init {
|
init {
|
||||||
|
@ -4,5 +4,3 @@ import center.sciprog.attributes.Attribute
|
|||||||
import kotlinx.serialization.json.JsonObject
|
import kotlinx.serialization.json.JsonObject
|
||||||
|
|
||||||
public object GeoJsonPropertiesAttribute : Attribute<JsonObject>
|
public object GeoJsonPropertiesAttribute : Attribute<JsonObject>
|
||||||
|
|
||||||
public object GeoJsonNameAttribute : Attribute<String>
|
|
@ -2,6 +2,7 @@ package center.sciprog.maps.geojson
|
|||||||
|
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.PointMode
|
import androidx.compose.ui.graphics.PointMode
|
||||||
|
import center.sciprog.attributes.NameAttribute
|
||||||
import center.sciprog.maps.coordinates.Gmc
|
import center.sciprog.maps.coordinates.Gmc
|
||||||
import center.sciprog.maps.features.*
|
import center.sciprog.maps.features.*
|
||||||
import kotlinx.serialization.json.contentOrNull
|
import kotlinx.serialization.json.contentOrNull
|
||||||
@ -60,13 +61,20 @@ public fun FeatureGroup<Gmc>.geoJsonFeature(
|
|||||||
id: String? = null,
|
id: String? = null,
|
||||||
): FeatureId<Feature<Gmc>> {
|
): FeatureId<Feature<Gmc>> {
|
||||||
val geometry = geoJson.geometry ?: return group {}
|
val geometry = geoJson.geometry ?: return group {}
|
||||||
val idOverride = geoJson.json["id"]?.jsonPrimitive?.contentOrNull ?: geoJson.properties?.get("id")?.jsonPrimitive?.contentOrNull ?: id
|
val idOverride = id ?: geoJson.getProperty("id")?.jsonPrimitive?.contentOrNull
|
||||||
val colorOverride = geoJson.properties?.get("color")?.jsonPrimitive?.intOrNull?.let { Color(it) }
|
|
||||||
val jsonGeometry = geoJsonGeometry(geometry, idOverride)
|
return geoJsonGeometry(geometry, idOverride).modifyAttributes {
|
||||||
return if( colorOverride!= null){
|
geoJson.properties?.let {
|
||||||
jsonGeometry.color(colorOverride)
|
GeoJsonPropertiesAttribute(it)
|
||||||
} else{
|
}
|
||||||
jsonGeometry
|
|
||||||
|
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