refactor custom feature -> draw feature
This commit is contained in:
parent
f218853544
commit
52d0d959de
@ -8,7 +8,6 @@ import androidx.compose.ui.geometry.Size
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.drawscope.DrawScope
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import centre.sciprog.maps.GmcBox
|
||||
|
||||
typealias FeatureId = String
|
||||
|
||||
@ -23,6 +22,7 @@ internal class MapFeatureBuilder(initialFeatures: Map<FeatureId, MapFeature>) :
|
||||
private val content: SnapshotStateMap<FeatureId, MapFeature> = mutableStateMapOf<FeatureId, MapFeature>().apply {
|
||||
putAll(initialFeatures)
|
||||
}
|
||||
|
||||
private fun generateID(feature: MapFeature): FeatureId = "@feature[${feature.hashCode().toUInt()}]"
|
||||
|
||||
override fun addFeature(id: FeatureId?, feature: MapFeature): FeatureId {
|
||||
@ -46,18 +46,10 @@ fun FeatureBuilder.circle(
|
||||
|
||||
fun FeatureBuilder.custom(
|
||||
position: Pair<Double, Double>,
|
||||
zoomRange: IntRange = defaultZoomRange,
|
||||
id: FeatureId? = null,
|
||||
customFeatureBuilder: DrawScope.(Offset) -> Unit,
|
||||
) = addFeature(id, object : MapCustomFeature(position = position.toCoordinates()) {
|
||||
override fun drawFeature(drawScope: DrawScope, offset: Offset) {
|
||||
customFeatureBuilder(drawScope, offset)
|
||||
}
|
||||
|
||||
override fun getBoundingBox(zoom: Int): GmcBox {
|
||||
return GmcBox(position.toCoordinates(), position.toCoordinates())
|
||||
}
|
||||
|
||||
})
|
||||
drawFeature: DrawScope.(Offset) -> Unit,
|
||||
) = addFeature(id, MapDrawFeature(position.toCoordinates(), zoomRange, drawFeature))
|
||||
|
||||
fun FeatureBuilder.line(
|
||||
aCoordinates: Pair<Double, Double>,
|
||||
|
@ -30,14 +30,17 @@ internal val defaultZoomRange = 1..18
|
||||
*/
|
||||
class MapFeatureSelector(val selector: (zoom: Int) -> MapFeature) : MapFeature(defaultZoomRange) {
|
||||
override fun getBoundingBox(zoom: Int): GmcBox = selector(zoom).getBoundingBox(zoom)
|
||||
|
||||
}
|
||||
|
||||
abstract class MapCustomFeature(
|
||||
class MapDrawFeature(
|
||||
val position: GeodeticMapCoordinates,
|
||||
zoomRange: IntRange = defaultZoomRange,
|
||||
val position: GeodeticMapCoordinates
|
||||
val drawFeature: DrawScope.(Offset) -> Unit,
|
||||
) : MapFeature(zoomRange) {
|
||||
abstract fun drawFeature(drawScope: DrawScope, offset: Offset)
|
||||
override fun getBoundingBox(zoom: Int): GmcBox {
|
||||
//TODO add box computation
|
||||
return GmcBox(position, position)
|
||||
}
|
||||
}
|
||||
|
||||
class MapCircleFeature(
|
||||
|
@ -236,7 +236,7 @@ actual fun MapView(
|
||||
feature.color.toPaint()
|
||||
)
|
||||
}
|
||||
is MapCustomFeature -> drawIntoCanvas { canvas ->
|
||||
is MapDrawFeature -> {
|
||||
val offset = feature.position.toOffset()
|
||||
feature.drawFeature(this, offset)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user