mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
449c92801b
commit
1d80b08a8f
1 changed files with 16 additions and 6 deletions
|
@ -136,19 +136,28 @@ Item {
|
||||||
return !isNaN(pt.x)
|
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() {
|
function stopZoomAnimations() {
|
||||||
mapAnimationZoomIn.stop()
|
mapAnimationZoomIn.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
function centerOnCoordinate(coord) {
|
function centerOnCoordinate(coord) {
|
||||||
stopZoomAnimations()
|
stopZoomAnimations()
|
||||||
if (coord.latitude === 0.0 && coord.longitude === 0.0) {
|
if (!coordIsValid(coord)) {
|
||||||
// Do nothing
|
console.warn("MapWidget.qml: centerOnCoordinate(): !coordIsValid()")
|
||||||
} else {
|
} else {
|
||||||
var newZoomOutFound = false
|
var newZoomOutFound = false
|
||||||
var zoomStored = zoomLevel
|
var zoomStored = zoomLevel
|
||||||
|
var centerStored = QtPositioning.coordinate(center.latitude, center.longitude)
|
||||||
newZoomOut = zoomLevel
|
newZoomOut = zoomLevel
|
||||||
newCenter = coord
|
newCenter = coord
|
||||||
|
zoomLevel = Math.floor(zoomLevel)
|
||||||
while (zoomLevel > minimumZoomLevel) {
|
while (zoomLevel > minimumZoomLevel) {
|
||||||
var pt = fromCoordinate(coord)
|
var pt = fromCoordinate(coord)
|
||||||
if (pointIsVisible(pt)) {
|
if (pointIsVisible(pt)) {
|
||||||
|
@ -156,11 +165,12 @@ Item {
|
||||||
newZoomOutFound = true
|
newZoomOutFound = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
zoomLevel--
|
zoomLevel -= 1.0
|
||||||
}
|
}
|
||||||
if (!newZoomOutFound)
|
if (!newZoomOutFound)
|
||||||
newZoomOut = defaultZoomOut
|
newZoomOut = defaultZoomOut
|
||||||
zoomLevel = zoomStored
|
zoomLevel = zoomStored
|
||||||
|
center = centerStored
|
||||||
newZoom = zoomStored
|
newZoom = zoomStored
|
||||||
mapAnimationZoomIn.restart()
|
mapAnimationZoomIn.restart()
|
||||||
}
|
}
|
||||||
|
@ -185,13 +195,13 @@ Item {
|
||||||
newZoomOutFound = true
|
newZoomOutFound = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
zoomLevel--
|
zoomLevel -= 1.0
|
||||||
}
|
}
|
||||||
if (!newZoomOutFound)
|
if (!newZoomOutFound)
|
||||||
newZoomOut = defaultZoomOut
|
newZoomOut = defaultZoomOut
|
||||||
// calculate zoom in
|
// calculate zoom in
|
||||||
center = newCenter
|
center = newCenter
|
||||||
zoomLevel = maximumZoomLevel
|
zoomLevel = Math.floor(maximumZoomLevel)
|
||||||
var diagonalRect = topLeft.distanceTo(bottomRight)
|
var diagonalRect = topLeft.distanceTo(bottomRight)
|
||||||
while (zoomLevel > minimumZoomLevel) {
|
while (zoomLevel > minimumZoomLevel) {
|
||||||
var c0 = toCoordinate(Qt.point(0.0, 0.0))
|
var c0 = toCoordinate(Qt.point(0.0, 0.0))
|
||||||
|
@ -200,7 +210,7 @@ Item {
|
||||||
newZoom = zoomLevel - 2.0
|
newZoom = zoomLevel - 2.0
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
zoomLevel--
|
zoomLevel -= 1.0
|
||||||
}
|
}
|
||||||
if (newZoom > defaultZoomIn)
|
if (newZoom > defaultZoomIn)
|
||||||
newZoom = defaultZoomIn
|
newZoom = defaultZoomIn
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue