Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
09307f3a39 |
@ -54,7 +54,7 @@ fun App() {
|
||||
) {
|
||||
val pointOne = 55.568548 to 37.568604
|
||||
val pointTwo = 55.929444 to 37.518434
|
||||
val pointThree = 60.929444 to 37.518434
|
||||
val pointThree = 55.742465 to 37.615812
|
||||
|
||||
image(pointOne, Icons.Filled.Home)
|
||||
|
||||
@ -63,6 +63,17 @@ fun App() {
|
||||
centerCoordinates = pointTwo,
|
||||
)
|
||||
|
||||
route(
|
||||
route = listOf(
|
||||
55.742465 to 37.615812,
|
||||
55.742713 to 37.616370,
|
||||
55.742815 to 37.616659,
|
||||
55.742320 to 37.617132,
|
||||
55.742086 to 37.616566,
|
||||
55.741715 to 37.616716
|
||||
)
|
||||
)
|
||||
|
||||
custom(position = pointThree) {
|
||||
drawRect(
|
||||
color = Color.Red,
|
||||
|
@ -8,6 +8,7 @@ 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.GeodeticMapCoordinates
|
||||
import centre.sciprog.maps.GmcBox
|
||||
|
||||
typealias FeatureId = String
|
||||
@ -23,6 +24,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 {
|
||||
@ -34,6 +36,14 @@ internal class MapFeatureBuilder(initialFeatures: Map<FeatureId, MapFeature>) :
|
||||
override fun build(): SnapshotStateMap<FeatureId, MapFeature> = content
|
||||
}
|
||||
|
||||
fun FeatureBuilder.route(
|
||||
route: List<Pair<Double, Double>>,
|
||||
zoomRange: IntRange = defaultZoomRange,
|
||||
stroke: Float = 2f,
|
||||
color: Color = Color.Red,
|
||||
id: FeatureId? = null
|
||||
) = addFeature(id, MapRouteFeature(route.map { it.toCoordinates() }, zoomRange, stroke, color))
|
||||
|
||||
fun FeatureBuilder.circle(
|
||||
centerCoordinates: Pair<Double, Double>,
|
||||
zoomRange: IntRange = defaultZoomRange,
|
||||
|
@ -40,6 +40,18 @@ abstract class MapCustomFeature(
|
||||
abstract fun drawFeature(drawScope: DrawScope, offset: Offset)
|
||||
}
|
||||
|
||||
class MapRouteFeature(
|
||||
val route: List<GeodeticMapCoordinates>,
|
||||
zoomRange: IntRange = defaultZoomRange,
|
||||
val stroke: Float = 2f,
|
||||
val color: Color = Color.Red
|
||||
) : MapFeature(zoomRange) {
|
||||
override fun getBoundingBox(zoom: Int): GmcBox {
|
||||
return GmcBox(route.first(), route.last())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MapCircleFeature(
|
||||
val center: GeodeticMapCoordinates,
|
||||
zoomRange: IntRange = defaultZoomRange,
|
||||
|
@ -9,11 +9,8 @@ import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.geometry.Rect
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.PathEffect
|
||||
import androidx.compose.ui.graphics.*
|
||||
import androidx.compose.ui.graphics.drawscope.*
|
||||
import androidx.compose.ui.graphics.nativeCanvas
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.input.pointer.*
|
||||
import androidx.compose.ui.unit.*
|
||||
import centre.sciprog.maps.*
|
||||
@ -236,10 +233,19 @@ actual fun MapView(
|
||||
feature.color.toPaint()
|
||||
)
|
||||
}
|
||||
is MapCustomFeature -> drawIntoCanvas { canvas ->
|
||||
is MapCustomFeature -> {
|
||||
val offset = feature.position.toOffset()
|
||||
feature.drawFeature(this, offset)
|
||||
}
|
||||
is MapRouteFeature -> {
|
||||
val points = feature.route.map { it.toOffset() }
|
||||
drawPoints(
|
||||
points = points,
|
||||
color = feature.color,
|
||||
pointMode = PointMode.Polygon,
|
||||
strokeWidth = feature.stroke
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user