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),