From 6f6c4b117b8fd3e1e58515357a8ed7662abe3347 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 13 Jul 2022 21:24:46 +0300 Subject: [PATCH] Pan logic on coroutines --- src/commonMain/kotlin/centre/sciprog/maps/MapViewPoint.kt | 7 +++++-- .../kotlin/centre/sciprog/maps/WebMercatorProjection.kt | 6 +++--- 2 files 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 f6b02c4..1b27e2d 100644 --- a/src/commonMain/kotlin/centre/sciprog/maps/MapViewPoint.kt +++ b/src/commonMain/kotlin/centre/sciprog/maps/MapViewPoint.kt @@ -10,10 +10,13 @@ data class MapViewPoint( val focus: GeodeticMapCoordinates, val zoom: Double, ) { - val scaleFactor by lazy { WebMercatorProjection.scaleFactor(zoom.roundToInt()) } + val scaleFactor by lazy { WebMercatorProjection.scaleFactor(zoom) } } -fun MapViewPoint.move(deltaX: Double, deltaY: Double): MapViewPoint { +/** + * + */ +internal fun MapViewPoint.move(deltaX: Double, deltaY: Double): MapViewPoint { val newCoordinates = GeodeticMapCoordinates.ofRadians( (focus.latitude + deltaY / scaleFactor).coerceIn( -MercatorProjection.MAXIMUM_LATITUDE, diff --git a/src/commonMain/kotlin/centre/sciprog/maps/WebMercatorProjection.kt b/src/commonMain/kotlin/centre/sciprog/maps/WebMercatorProjection.kt index a05816a..db4882b 100644 --- a/src/commonMain/kotlin/centre/sciprog/maps/WebMercatorProjection.kt +++ b/src/commonMain/kotlin/centre/sciprog/maps/WebMercatorProjection.kt @@ -14,10 +14,10 @@ public object WebMercatorProjection { /** * Compute radians to projection coordinates ratio for given [zoom] factor */ - public fun scaleFactor(zoom: Int) = 256.0 / 2 / PI * 2.0.pow(zoom) + public fun scaleFactor(zoom: Double) = 256.0 / 2 / PI * 2.0.pow(zoom) public fun toGeodetic(mercator: WebMercatorCoordinates): GeodeticMapCoordinates { - val scaleFactor = scaleFactor(mercator.zoom) + val scaleFactor = scaleFactor(mercator.zoom.toDouble()) val longitude = mercator.x / scaleFactor - PI val latitude = (atan(exp(PI - mercator.y / scaleFactor)) - PI / 4) * 2 return GeodeticMapCoordinates.ofRadians(latitude, longitude) @@ -29,7 +29,7 @@ public object WebMercatorProjection { public fun toMercator(gmc: GeodeticMapCoordinates, zoom: Int): WebMercatorCoordinates { require(abs(gmc.latitude) <= MercatorProjection.MAXIMUM_LATITUDE) { "Latitude exceeds the maximum latitude for mercator coordinates" } - val scaleFactor = scaleFactor(zoom) + val scaleFactor = scaleFactor(zoom.toDouble()) return WebMercatorCoordinates( zoom = zoom, x = scaleFactor * (gmc.longitude + PI),