mapwidget.qml: add a couple of helpers

Add stopZoomAnimations(), which is really just a precaution
function to make sure we have stopped all animation of the
map before doing calculations! Since the animation *should*
be running in a separate thread, this would make sure the Map "center"
and "zoomLevel" properties do not change.

Add pointIsVisible(), which is a helper to determine
if a point created by map.fromCoordinate() method is inside
the viewport. fromCoordinate() has to be called without the
"false" (clip) flag for this to work.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
Lubomir I. Ivanov 2017-08-07 02:13:25 +03:00 committed by Dirk Hohndel
parent d421660f91
commit 0fc9a3bf4a

View file

@ -148,7 +148,17 @@ Item {
mapAnimationZoomOut.restart()
}
function pointIsVisible(pt) {
return !isNaN(pt.x)
}
function stopZoomAnimations() {
mapAnimationZoomIn.stop()
mapAnimationZoomOut.stop()
}
function centerOnCoordinate(coord) {
stopZoomAnimations()
newCenter = coord
if (coord.latitude === 0.0 && coord.longitude === 0.0) {
newZoom = 2.6
@ -157,8 +167,8 @@ Item {
var zoomStored = zoomLevel
newZoomOut = zoomLevel
while (zoomLevel > minimumZoomLevel) {
var pt = fromCoordinate(coord, false)
if (pt.x > 0 && pt.y > 0 && pt.x < width && pt.y < height) {
var pt = fromCoordinate(coord)
if (pointIsVisible(pt)) {
newZoomOut = zoomLevel
break
}