diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/src/commonMain/kotlin/centre/sciprog/maps/compose/MapView.kt b/src/commonMain/kotlin/centre/sciprog/maps/compose/MapView.kt index decc7b0..ebd8483 100644 --- a/src/commonMain/kotlin/centre/sciprog/maps/compose/MapView.kt +++ b/src/commonMain/kotlin/centre/sciprog/maps/compose/MapView.kt @@ -20,7 +20,7 @@ expect fun MapView( mapTileProvider: MapTileProvider, computeViewPoint: (canvasSize: DpSize) -> MapViewPoint, features: Map, - onClick: (GeodeticMapCoordinates) -> Unit = {}, + onClick: MapViewPoint.() -> Unit = {}, //TODO consider replacing by modifier config: MapViewConfig = MapViewConfig(), modifier: Modifier = Modifier.fillMaxSize(), @@ -31,7 +31,7 @@ fun MapView( mapTileProvider: MapTileProvider, initialViewPoint: MapViewPoint, features: Map = emptyMap(), - onClick: (GeodeticMapCoordinates) -> Unit = {}, + onClick: MapViewPoint.() -> Unit = {}, config: MapViewConfig = MapViewConfig(), modifier: Modifier = Modifier.fillMaxSize(), buildFeatures: @Composable (FeatureBuilder.() -> Unit) = {}, @@ -46,7 +46,7 @@ fun MapView( mapTileProvider: MapTileProvider, box: GmcBox, features: Map = emptyMap(), - onClick: (GeodeticMapCoordinates) -> Unit = {}, + onClick: MapViewPoint.() -> Unit = {}, config: MapViewConfig = MapViewConfig(), modifier: Modifier = Modifier.fillMaxSize(), buildFeatures: @Composable (FeatureBuilder.() -> Unit) = {}, diff --git a/src/jvmMain/kotlin/Main.kt b/src/jvmMain/kotlin/Main.kt index 5c19ea9..7112b15 100644 --- a/src/jvmMain/kotlin/Main.kt +++ b/src/jvmMain/kotlin/Main.kt @@ -43,7 +43,7 @@ fun App() { MapView( mapTileProvider, viewPoint, - onClick = { gmc -> coordinates = gmc }, + onClick = { coordinates = focus }, config = MapViewConfig(inferViewBoxFromFeatures = true) ) { val pointOne = 55.568548 to 37.568604 diff --git a/src/jvmMain/kotlin/centre/sciprog/maps/compose/MapViewJvm.kt b/src/jvmMain/kotlin/centre/sciprog/maps/compose/MapViewJvm.kt index 2bdf8eb..910fd44 100644 --- a/src/jvmMain/kotlin/centre/sciprog/maps/compose/MapViewJvm.kt +++ b/src/jvmMain/kotlin/centre/sciprog/maps/compose/MapViewJvm.kt @@ -40,27 +40,29 @@ actual fun MapView( mapTileProvider: MapTileProvider, computeViewPoint: (canvasSize: DpSize) -> MapViewPoint, features: Map, - onClick: (GeodeticMapCoordinates) -> Unit, + onClick: MapViewPoint.() -> Unit, config: MapViewConfig, modifier: Modifier, ) { var canvasSize by remember { mutableStateOf(DpSize(512.dp, 512.dp)) } - var viewPointOverride by remember { mutableStateOf( - if(config.inferViewBoxFromFeatures){ - features.values.computeBoundingBox(1)?.let { box -> - val zoom = log2( - min( - canvasSize.width.value / box.width, - canvasSize.height.value / box.height - ) * PI / mapTileProvider.tileSize - ) - MapViewPoint(box.center, zoom) + var viewPointOverride: MapViewPoint? by remember { + mutableStateOf( + if (config.inferViewBoxFromFeatures) { + features.values.computeBoundingBox(1)?.let { box -> + val zoom = log2( + min( + canvasSize.width.value / box.width, + canvasSize.height.value / box.height + ) * PI / mapTileProvider.tileSize + ) + MapViewPoint(box.center, zoom) + } + } else { + null } - } else { - null - } - ) } + ) + } val viewPoint by derivedStateOf { viewPointOverride ?: computeViewPoint(canvasSize) } @@ -123,7 +125,7 @@ actual fun MapView( } else { val dragStart = change.position val dpPos = DpOffset(dragStart.x.toDp(), dragStart.y.toDp()) - onClick(dpPos.toGeodetic()) + onClick(MapViewPoint(dpPos.toGeodetic(), viewPoint.zoom)) drag(change.id) { dragChange -> val dragAmount = dragChange.position - dragChange.previousPosition viewPointOverride = viewPoint.move(