diff options
author | Lubomir I. Ivanov <neolit123@gmail.com> | 2017-11-27 17:05:43 +0200 |
---|---|---|
committer | Lubomir I. Ivanov <neolit123@gmail.com> | 2017-11-27 22:59:22 +0100 |
commit | 1d80b08a8fb1fe06fd5cf60eac43b9ae1dc1197c (patch) | |
tree | 7a0f236abe6ed5f0a8fe5fed6ea7ba53b115f35f /map-widget | |
parent | 449c92801b7fee8537fa23c3f03f927cbb4cba5f (diff) | |
download | subsurface-1d80b08a8fb1fe06fd5cf60eac43b9ae1dc1197c.tar.gz |
mapwidget.qml: more minor improvements
- Add the helper coordIsValid() and use it in centerOnCoordinate().
This checks for NaN coordinates and prevents an infinite while() loop.
- Use '-= 1.0' instead of '--' to be more clear that the decremented
variable is a float
- Store the current center with 'centerStored' in
centerOnCoordinate(). Fixes a possible zoom out glitch.
- use Math.floor() to convert 'zoomLevel' to integer when estimating
zoomOut in centerOn*()
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Diffstat (limited to 'map-widget')
-rw-r--r-- | map-widget/qml/MapWidget.qml | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/map-widget/qml/MapWidget.qml b/map-widget/qml/MapWidget.qml index 7b122babe..12b4554eb 100644 --- a/map-widget/qml/MapWidget.qml +++ b/map-widget/qml/MapWidget.qml @@ -136,19 +136,28 @@ Item { return !isNaN(pt.x) } + function coordIsValid(coord) { + if (coord == null || isNaN(coord.latitude) || isNaN(coord.longitude) || + (coord.latitude === 0.0 && coord.longitude === 0.0)) + return false; + return true; + } + function stopZoomAnimations() { mapAnimationZoomIn.stop() } function centerOnCoordinate(coord) { stopZoomAnimations() - if (coord.latitude === 0.0 && coord.longitude === 0.0) { - // Do nothing + if (!coordIsValid(coord)) { + console.warn("MapWidget.qml: centerOnCoordinate(): !coordIsValid()") } else { var newZoomOutFound = false var zoomStored = zoomLevel + var centerStored = QtPositioning.coordinate(center.latitude, center.longitude) newZoomOut = zoomLevel newCenter = coord + zoomLevel = Math.floor(zoomLevel) while (zoomLevel > minimumZoomLevel) { var pt = fromCoordinate(coord) if (pointIsVisible(pt)) { @@ -156,11 +165,12 @@ Item { newZoomOutFound = true break } - zoomLevel-- + zoomLevel -= 1.0 } if (!newZoomOutFound) newZoomOut = defaultZoomOut zoomLevel = zoomStored + center = centerStored newZoom = zoomStored mapAnimationZoomIn.restart() } @@ -185,13 +195,13 @@ Item { newZoomOutFound = true break } - zoomLevel-- + zoomLevel -= 1.0 } if (!newZoomOutFound) newZoomOut = defaultZoomOut // calculate zoom in center = newCenter - zoomLevel = maximumZoomLevel + zoomLevel = Math.floor(maximumZoomLevel) var diagonalRect = topLeft.distanceTo(bottomRight) while (zoomLevel > minimumZoomLevel) { var c0 = toCoordinate(Qt.point(0.0, 0.0)) @@ -200,7 +210,7 @@ Item { newZoom = zoomLevel - 2.0 break } - zoomLevel-- + zoomLevel -= 1.0 } if (newZoom > defaultZoomIn) newZoom = defaultZoomIn |