From 0fc9a3bf4ae532f5a9afd6d3fd8731eb16745671 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Mon, 7 Aug 2017 02:13:25 +0300 Subject: 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 --- mobile-widgets/qml/MapWidget.qml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'mobile-widgets/qml') diff --git a/mobile-widgets/qml/MapWidget.qml b/mobile-widgets/qml/MapWidget.qml index 42bc546ce..cdfa25d79 100644 --- a/mobile-widgets/qml/MapWidget.qml +++ b/mobile-widgets/qml/MapWidget.qml @@ -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 } -- cgit v1.2.3-70-g09d2