Pan logic on coroutines
This commit is contained in:
parent
a1151ebb62
commit
6f6c4b117b
@ -10,10 +10,13 @@ data class MapViewPoint(
|
|||||||
val focus: GeodeticMapCoordinates,
|
val focus: GeodeticMapCoordinates,
|
||||||
val zoom: Double,
|
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(
|
val newCoordinates = GeodeticMapCoordinates.ofRadians(
|
||||||
(focus.latitude + deltaY / scaleFactor).coerceIn(
|
(focus.latitude + deltaY / scaleFactor).coerceIn(
|
||||||
-MercatorProjection.MAXIMUM_LATITUDE,
|
-MercatorProjection.MAXIMUM_LATITUDE,
|
||||||
|
@ -14,10 +14,10 @@ public object WebMercatorProjection {
|
|||||||
/**
|
/**
|
||||||
* Compute radians to projection coordinates ratio for given [zoom] factor
|
* 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 {
|
public fun toGeodetic(mercator: WebMercatorCoordinates): GeodeticMapCoordinates {
|
||||||
val scaleFactor = scaleFactor(mercator.zoom)
|
val scaleFactor = scaleFactor(mercator.zoom.toDouble())
|
||||||
val longitude = mercator.x / scaleFactor - PI
|
val longitude = mercator.x / scaleFactor - PI
|
||||||
val latitude = (atan(exp(PI - mercator.y / scaleFactor)) - PI / 4) * 2
|
val latitude = (atan(exp(PI - mercator.y / scaleFactor)) - PI / 4) * 2
|
||||||
return GeodeticMapCoordinates.ofRadians(latitude, longitude)
|
return GeodeticMapCoordinates.ofRadians(latitude, longitude)
|
||||||
@ -29,7 +29,7 @@ public object WebMercatorProjection {
|
|||||||
public fun toMercator(gmc: GeodeticMapCoordinates, zoom: Int): WebMercatorCoordinates {
|
public fun toMercator(gmc: GeodeticMapCoordinates, zoom: Int): WebMercatorCoordinates {
|
||||||
require(abs(gmc.latitude) <= MercatorProjection.MAXIMUM_LATITUDE) { "Latitude exceeds the maximum latitude for mercator coordinates" }
|
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(
|
return WebMercatorCoordinates(
|
||||||
zoom = zoom,
|
zoom = zoom,
|
||||||
x = scaleFactor * (gmc.longitude + PI),
|
x = scaleFactor * (gmc.longitude + PI),
|
||||||
|
Loading…
Reference in New Issue
Block a user