Fix zoom
This commit is contained in:
parent
b95885694d
commit
a1151ebb62
@ -35,13 +35,16 @@ fun MapViewPoint.move(delta: GeodeticMapCoordinates): MapViewPoint {
|
|||||||
return MapViewPoint(newCoordinates, zoom)
|
return MapViewPoint(newCoordinates, zoom)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun MapViewPoint.zoom(zoomDelta: Double): MapViewPoint = copy(zoom = (zoom + zoomDelta).coerceIn(2.0, 18.0))
|
fun MapViewPoint.zoom(
|
||||||
|
zoomDelta: Double,
|
||||||
fun MapViewPoint.zoom(zoomDelta: Double, invariant: GeodeticMapCoordinates): MapViewPoint {
|
invariant: GeodeticMapCoordinates = focus,
|
||||||
val difScale = 2.0.pow(-zoomDelta)
|
): 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(
|
val newCenter = GeodeticMapCoordinates.ofRadians(
|
||||||
focus.latitude + (invariant.latitude - focus.latitude) * difScale,
|
focus.latitude + (invariant.latitude - focus.latitude) * difScale,
|
||||||
focus.longitude + (invariant.longitude - focus.longitude) * 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))
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user