diff --git a/demo/maps/src/jvmMain/kotlin/Main.kt b/demo/maps/src/jvmMain/kotlin/Main.kt index 574dc0e..25721ff 100644 --- a/demo/maps/src/jvmMain/kotlin/Main.kt +++ b/demo/maps/src/jvmMain/kotlin/Main.kt @@ -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(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) diff --git a/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapFeature.kt b/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapFeature.kt index 2180674..c8fce51 100644 --- a/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapFeature.kt +++ b/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapFeature.kt @@ -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( diff --git a/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapFeatureBuilder.kt b/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapFeatureBuilder.kt index 55f18ee..700acee 100644 --- a/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapFeatureBuilder.kt +++ b/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapFeatureBuilder.kt @@ -71,8 +71,9 @@ public fun MapFeatureBuilder.draw( position: Pair, 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, @@ -133,4 +134,14 @@ public fun MapFeatureBuilder.group( val map = MapFeatureBuilderImpl(emptyMap()).apply(builder).build() val feature = MapFeatureGroup(map, zoomRange) return addFeature(id, feature) -} \ No newline at end of file +} + +public fun MapFeatureBuilder.featureSelector( + id: FeatureId? = null, + onSelect: MapFeatureBuilder.(zoom: Int) -> MapFeature +): FeatureId = addFeature( + id = id, + feature = MapFeatureSelector( + selector = { onSelect(this, it) } + ) +) \ No newline at end of file