Partial fix for TAVRIDA-T-3
(Zoom in works corretly, zoom out - not)
This commit is contained in:
parent
2ac4bdfd4f
commit
960c64d480
@ -1,6 +1,8 @@
|
||||
package centre.sciprog.maps
|
||||
|
||||
import kotlin.math.pow
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.math.sign
|
||||
|
||||
/**
|
||||
* Observable position on the map. Includes observation coordinate and [zoom] factor
|
||||
@ -35,3 +37,12 @@ fun MapViewPoint.move(delta: GeodeticMapCoordinates): MapViewPoint {
|
||||
}
|
||||
|
||||
fun MapViewPoint.zoom(zoomDelta: Double): MapViewPoint = copy(zoom = (zoom + zoomDelta).coerceIn(2.0, 18.0))
|
||||
|
||||
fun MapViewPoint.zoom(zoomDelta: Double, at: GeodeticMapCoordinates): MapViewPoint {
|
||||
val difScale = 2.0.pow(-zoomDelta)
|
||||
val newCenter = GeodeticMapCoordinates.ofRadians(
|
||||
focus.latitude + (at.latitude - focus.latitude) * difScale,
|
||||
focus.longitude + (at.longitude - focus.longitude) * difScale
|
||||
)
|
||||
return MapViewPoint(newCenter, (zoom + zoomDelta).coerceIn(2.0, 18.0))
|
||||
}
|
@ -70,7 +70,11 @@ actual fun MapView(
|
||||
val (xPos, yPos) = it.changes.first().position
|
||||
onClick(DpOffset(xPos.toDp(), yPos.toDp()).toGeodetic())
|
||||
}.onPointerEvent(PointerEventType.Scroll) {
|
||||
viewPoint = viewPoint.zoom(-it.changes.first().scrollDelta.y.toDouble())
|
||||
val change = it.changes.first()
|
||||
val (xPos, yPos) = change.position
|
||||
//compute invariant point of translation
|
||||
val at = DpOffset(xPos.toDp(), yPos.toDp()).toGeodetic()
|
||||
viewPoint = viewPoint.zoom(-change.scrollDelta.y.toDouble(), at)
|
||||
}.pointerInput(Unit) {
|
||||
detectDragGestures { _: PointerInputChange, dragAmount: Offset ->
|
||||
viewPoint = viewPoint.move(-dragAmount.x, +dragAmount.y)
|
||||
|
Loading…
Reference in New Issue
Block a user