diff --git a/build.gradle.kts b/build.gradle.kts index 5c1d24e..994ab4b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,7 +10,7 @@ val ktorVersion by extra("2.0.3") allprojects { group = "center.sciprog" - version = "0.1.0-dev-4" + version = "0.1.0-dev-5" } ksciencePublish{ diff --git a/demo/maps/src/jvmMain/kotlin/Main.kt b/demo/maps/src/jvmMain/kotlin/Main.kt index 989a2c3..e4ca8bc 100644 --- a/demo/maps/src/jvmMain/kotlin/Main.kt +++ b/demo/maps/src/jvmMain/kotlin/Main.kt @@ -35,12 +35,12 @@ private fun GeodeticMapCoordinates.toShortString(): String = fun App() { MaterialTheme { //create a view point - val viewPoint = remember { - MapViewPoint( - GeodeticMapCoordinates.ofDegrees(55.7558, 37.6173), - 8.0 - ) - } +// val viewPoint = remember { +// MapViewPoint( +// GeodeticMapCoordinates.ofDegrees(55.7558, 37.6173), +// 8.0 +// ) +// } val scope = rememberCoroutineScope() val mapTileProvider = remember { diff --git a/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapView.kt b/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapView.kt index 4006f55..7bd6b7e 100644 --- a/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapView.kt +++ b/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapView.kt @@ -101,20 +101,29 @@ private fun prepareConfig(initialConfig: MapViewConfig, featureBuilder: MapFeatu internal fun GmcRectangle.computeViewPoint( mapTileProvider: MapTileProvider, -): (canvasSize: DpSize) -> MapViewPoint = { canvasSize -> + canvasSize: DpSize, +): MapViewPoint { val zoom = log2( min( canvasSize.width.value / longitudeDelta.radians.value, canvasSize.height.value / latitudeDelta.radians.value ) * PI / mapTileProvider.tileSize ) - MapViewPoint(center, zoom) + return MapViewPoint(center, zoom) } +/** + * Draw a map using convenient parameters. If neither [initialViewPoint], noe [initialRectangle] is defined, + * use map features to infer view region. + * @param initialViewPoint The view point of the map using center and zoom. Is used if provided + * @param initialRectangle The rectangle to be used for view point computation. Used if [initialViewPoint] is not defined. + * @param buildFeatures - a builder for features + */ @Composable public fun MapView( mapTileProvider: MapTileProvider, initialViewPoint: MapViewPoint? = null, + initialRectangle: GmcRectangle? = null, config: MapViewConfig = MapViewConfig(), modifier: Modifier = Modifier.fillMaxSize(), buildFeatures: @Composable (MapFeatureBuilder.() -> Unit) = {}, @@ -130,15 +139,10 @@ public fun MapView( MapView( mapTileProvider, { canvasSize -> - initialViewPoint ?: features.values.computeBoundingBox(1.0)?.let { box -> - val zoom = log2( - min( - canvasSize.width.value / box.longitudeDelta.radians.value, - canvasSize.height.value / box.latitudeDelta.radians.value - ) * PI / mapTileProvider.tileSize - ) - MapViewPoint(box.center, zoom) - } ?: MapViewPoint(GeodeticMapCoordinates(0.0.radians, 0.0.radians), 1.0) + initialViewPoint + ?: initialRectangle?.computeViewPoint(mapTileProvider, canvasSize) + ?: features.values.computeBoundingBox(1.0)?.computeViewPoint(mapTileProvider, canvasSize) + ?: MapViewPoint(GeodeticMapCoordinates(0.0.radians, 0.0.radians), 1.0) }, features, newConfig, diff --git a/maps-kt-compose/src/jvmMain/kotlin/center/sciprog/maps/compose/MapViewJvm.kt b/maps-kt-compose/src/jvmMain/kotlin/center/sciprog/maps/compose/MapViewJvm.kt index 330a96d..d014b64 100644 --- a/maps-kt-compose/src/jvmMain/kotlin/center/sciprog/maps/compose/MapViewJvm.kt +++ b/maps-kt-compose/src/jvmMain/kotlin/center/sciprog/maps/compose/MapViewJvm.kt @@ -158,7 +158,7 @@ public actual fun MapView( ) config.onSelect(gmcBox) if (config.zoomOnSelect) { - val newViewPoint = gmcBox.computeViewPoint(mapTileProvider).invoke(canvasSize) + val newViewPoint = gmcBox.computeViewPoint(mapTileProvider, canvasSize) config.onViewChange(newViewPoint) viewPoint = newViewPoint