State encapsulation #14
@ -5,12 +5,14 @@ import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Home
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.geometry.Size
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.window.Window
|
||||
import androidx.compose.ui.window.application
|
||||
import center.sciprog.maps.compose.*
|
||||
import center.sciprog.maps.coordinates.Distance
|
||||
import center.sciprog.maps.coordinates.GeodeticMapCoordinates
|
||||
import center.sciprog.maps.coordinates.GmcBox
|
||||
import center.sciprog.maps.coordinates.MapViewPoint
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.engine.cio.CIO
|
||||
@ -47,6 +49,27 @@ fun App() {
|
||||
|
||||
var centerCoordinates by remember { mutableStateOf<GeodeticMapCoordinates?>(null) }
|
||||
|
||||
val markers = (1..1_000_000).map {
|
||||
val position = GeodeticMapCoordinates.ofDegrees(
|
||||
latitude = Random.nextDouble(-90.0, 90.0),
|
||||
longitude = Random.nextDouble(0.0, 180.0)
|
||||
)
|
||||
MapDrawFeature(
|
||||
position = position,
|
||||
getBoundingBox = {
|
||||
GmcBox.withCenter(
|
||||
center = position,
|
||||
width = Distance(0.001),
|
||||
height = Distance(0.001)
|
||||
)
|
||||
}
|
||||
) {
|
||||
drawRoundRect(
|
||||
color = Color.Yellow,
|
||||
size = Size(10f, 10f)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
MapView(
|
||||
mapTileProvider = mapTileProvider,
|
||||
@ -67,11 +90,27 @@ fun App() {
|
||||
centerCoordinates = pointTwo,
|
||||
)
|
||||
|
||||
draw(position = pointThree) {
|
||||
draw(
|
||||
position = pointThree,
|
||||
getBoundingBox = {
|
||||
GmcBox.withCenter(
|
||||
center = GeodeticMapCoordinates.ofDegrees(
|
||||
pointThree.first,
|
||||
pointThree.second
|
||||
),
|
||||
height = Distance(0.001),
|
||||
width = Distance(0.001)
|
||||
)
|
||||
}
|
||||
) {
|
||||
drawLine(start = Offset(-10f, -10f), end = Offset(10f, 10f), color = Color.Red)
|
||||
drawLine(start = Offset(-10f, 10f), end = Offset(10f, -10f), color = Color.Red)
|
||||
}
|
||||
|
||||
featureSelector { zoom ->
|
||||
markers.groupBy { }
|
||||
}
|
||||
|
||||
arc(pointOne, Distance(10.0), 0f, PI)
|
||||
|
||||
line(pointOne, pointTwo)
|
||||
|
@ -40,12 +40,10 @@ public class MapFeatureSelector(
|
||||
public class MapDrawFeature(
|
||||
public val position: GeodeticMapCoordinates,
|
||||
override val zoomRange: IntRange = defaultZoomRange,
|
||||
private val getBoundingBox: (zoom: Int) -> GmcBox,
|
||||
public val drawFeature: DrawScope.() -> Unit,
|
||||
) : MapFeature {
|
||||
override fun getBoundingBox(zoom: Int): GmcBox {
|
||||
//TODO add box computation
|
||||
return GmcBox(position, position)
|
||||
}
|
||||
override fun getBoundingBox(zoom: Int): GmcBox = getBoundingBox(zoom)
|
||||
}
|
||||
|
||||
public class MapCircleFeature(
|
||||
|
@ -71,8 +71,9 @@ public fun MapFeatureBuilder.draw(
|
||||
position: Pair<Double, Double>,
|
||||
zoomRange: IntRange = defaultZoomRange,
|
||||
id: FeatureId? = null,
|
||||
getBoundingBox: (Int) -> GmcBox,
|
||||
drawFeature: DrawScope.() -> Unit,
|
||||
): FeatureId = addFeature(id, MapDrawFeature(position.toCoordinates(), zoomRange, drawFeature))
|
||||
): FeatureId = addFeature(id, MapDrawFeature(position.toCoordinates(), zoomRange, getBoundingBox, drawFeature))
|
||||
|
||||
public fun MapFeatureBuilder.line(
|
||||
aCoordinates: Pair<Double, Double>,
|
||||
@ -133,4 +134,14 @@ public fun MapFeatureBuilder.group(
|
||||
val map = MapFeatureBuilderImpl(emptyMap()).apply(builder).build()
|
||||
val feature = MapFeatureGroup(map, zoomRange)
|
||||
return addFeature(id, feature)
|
||||
}
|
||||
}
|
||||
|
||||
public fun MapFeatureBuilder.featureSelector(
|
||||
id: FeatureId? = null,
|
||||
onSelect: MapFeatureBuilder.(zoom: Int) -> MapFeature
|
||||
): FeatureId = addFeature(
|
||||
id = id,
|
||||
feature = MapFeatureSelector(
|
||||
selector = { onSelect(this, it) }
|
||||
)
|
||||
)
|
Loading…
Reference in New Issue
Block a user