From a1151ebb62a3bc53ba207ff2509924447bd7ae0c Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 13 Jul 2022 16:01:08 +0300 Subject: [PATCH] Fix zoom --- .../kotlin/centre/sciprog/maps/MapViewPoint.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/commonMain/kotlin/centre/sciprog/maps/MapViewPoint.kt b/src/commonMain/kotlin/centre/sciprog/maps/MapViewPoint.kt index e873048..f6b02c4 100644 --- a/src/commonMain/kotlin/centre/sciprog/maps/MapViewPoint.kt +++ b/src/commonMain/kotlin/centre/sciprog/maps/MapViewPoint.kt @@ -35,13 +35,16 @@ fun MapViewPoint.move(delta: GeodeticMapCoordinates): MapViewPoint { return MapViewPoint(newCoordinates, zoom) } -fun MapViewPoint.zoom(zoomDelta: Double): MapViewPoint = copy(zoom = (zoom + zoomDelta).coerceIn(2.0, 18.0)) - -fun MapViewPoint.zoom(zoomDelta: Double, invariant: GeodeticMapCoordinates): MapViewPoint { - val difScale = 2.0.pow(-zoomDelta) +fun MapViewPoint.zoom( + zoomDelta: Double, + invariant: GeodeticMapCoordinates = focus, +): MapViewPoint = if (invariant == focus) { + copy(zoom = (zoom + zoomDelta).coerceIn(2.0, 18.0)) +} else { + val difScale = (1 - 2.0.pow(-zoomDelta)) val newCenter = GeodeticMapCoordinates.ofRadians( focus.latitude + (invariant.latitude - focus.latitude) * difScale, focus.longitude + (invariant.longitude - focus.longitude) * difScale ) - return MapViewPoint(newCenter, (zoom + zoomDelta).coerceIn(2.0, 18.0)) + MapViewPoint(newCenter, (zoom + zoomDelta).coerceIn(2.0, 18.0)) } \ No newline at end of file