mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
mapwidget.qml: implement centerOnRectangle()
First, this function calculates the zoom out effect until both the current Map center and the target rectangle are visible - see the "calculate zoom out" part. Then it calculates a zoom level, so that the target rectangle fits the viewport, but also so that the zoom is not too much (clamped). see the "calculate zoom in" part. NOTE: "centerStored" (the variable used to store the current map center) is created using QtPositioning.coordinate(), because the code needs a new object and not a reference of the map.center QGeoCoordinate object. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
parent
0fc9a3bf4a
commit
5db2460168
1 changed files with 43 additions and 2 deletions
|
@ -181,8 +181,49 @@ Item {
|
||||||
mapAnimationZoomOut.stop()
|
mapAnimationZoomOut.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
function centerOnRectangle(topLeft, bottomRight, center) {
|
function centerOnRectangle(topLeft, bottomRight, centerRect) {
|
||||||
// TODO
|
stopZoomAnimations()
|
||||||
|
newCenter = centerRect
|
||||||
|
if (newCenter.latitude === 0.0 && newCenter.longitude === 0.0) {
|
||||||
|
newZoom = 2.6
|
||||||
|
newZoomOut = newZoom
|
||||||
|
} else {
|
||||||
|
var centerStored = QtPositioning.coordinate(center.latitude, center.longitude)
|
||||||
|
var zoomStored = zoomLevel
|
||||||
|
var ptCenter
|
||||||
|
var ptTopLeft
|
||||||
|
var ptBottomRight
|
||||||
|
// calculate zoom out
|
||||||
|
newZoomOut = zoomLevel
|
||||||
|
while (zoomLevel > minimumZoomLevel) {
|
||||||
|
ptCenter = fromCoordinate(centerStored)
|
||||||
|
ptTopLeft = fromCoordinate(topLeft)
|
||||||
|
ptBottomRight = fromCoordinate(bottomRight)
|
||||||
|
if (pointIsVisible(ptCenter) && pointIsVisible(ptTopLeft) && pointIsVisible(ptBottomRight)) {
|
||||||
|
newZoomOut = zoomLevel
|
||||||
|
break
|
||||||
|
}
|
||||||
|
zoomLevel--
|
||||||
|
}
|
||||||
|
// calculate zoom in
|
||||||
|
center = newCenter
|
||||||
|
zoomLevel = maximumZoomLevel
|
||||||
|
while (zoomLevel > minimumZoomLevel) {
|
||||||
|
ptTopLeft = fromCoordinate(topLeft)
|
||||||
|
ptBottomRight = fromCoordinate(bottomRight)
|
||||||
|
if (pointIsVisible(ptTopLeft) && pointIsVisible(ptBottomRight)) {
|
||||||
|
newZoom = zoomLevel
|
||||||
|
break
|
||||||
|
}
|
||||||
|
zoomLevel--
|
||||||
|
}
|
||||||
|
if (newZoom > defaultZoomIn)
|
||||||
|
newZoom = defaultZoomIn
|
||||||
|
zoomLevel = zoomStored
|
||||||
|
center = centerStored
|
||||||
|
}
|
||||||
|
mapAnimationZoomIn.restart()
|
||||||
|
mapAnimationZoomOut.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
function deselectMapLocation() {
|
function deselectMapLocation() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue