mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
mapwidget.qml: return early instead of doing branching
The centerOn*() functions can just return early for invalid input, instead of branching the conditions. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
parent
1d80b08a8f
commit
837ed67d86
1 changed files with 59 additions and 59 deletions
|
@ -151,73 +151,73 @@ Item {
|
||||||
stopZoomAnimations()
|
stopZoomAnimations()
|
||||||
if (!coordIsValid(coord)) {
|
if (!coordIsValid(coord)) {
|
||||||
console.warn("MapWidget.qml: centerOnCoordinate(): !coordIsValid()")
|
console.warn("MapWidget.qml: centerOnCoordinate(): !coordIsValid()")
|
||||||
} else {
|
return
|
||||||
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)) {
|
|
||||||
newZoomOut = zoomLevel
|
|
||||||
newZoomOutFound = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
zoomLevel -= 1.0
|
|
||||||
}
|
|
||||||
if (!newZoomOutFound)
|
|
||||||
newZoomOut = defaultZoomOut
|
|
||||||
zoomLevel = zoomStored
|
|
||||||
center = centerStored
|
|
||||||
newZoom = zoomStored
|
|
||||||
mapAnimationZoomIn.restart()
|
|
||||||
}
|
}
|
||||||
|
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)) {
|
||||||
|
newZoomOut = zoomLevel
|
||||||
|
newZoomOutFound = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
zoomLevel -= 1.0
|
||||||
|
}
|
||||||
|
if (!newZoomOutFound)
|
||||||
|
newZoomOut = defaultZoomOut
|
||||||
|
zoomLevel = zoomStored
|
||||||
|
center = centerStored
|
||||||
|
newZoom = zoomStored
|
||||||
|
mapAnimationZoomIn.restart()
|
||||||
}
|
}
|
||||||
|
|
||||||
function centerOnRectangle(topLeft, bottomRight, centerRect) {
|
function centerOnRectangle(topLeft, bottomRight, centerRect) {
|
||||||
stopZoomAnimations()
|
stopZoomAnimations()
|
||||||
if (newCenter.latitude === 0.0 && newCenter.longitude === 0.0) {
|
if (newCenter.latitude === 0.0 && newCenter.longitude === 0.0) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
} else {
|
return
|
||||||
var centerStored = QtPositioning.coordinate(center.latitude, center.longitude)
|
|
||||||
var zoomStored = zoomLevel
|
|
||||||
var newZoomOutFound = false
|
|
||||||
newCenter = centerRect
|
|
||||||
// calculate zoom out
|
|
||||||
newZoomOut = zoomLevel
|
|
||||||
while (zoomLevel > minimumZoomLevel) {
|
|
||||||
var ptCenter = fromCoordinate(centerStored)
|
|
||||||
var ptCenterRect = fromCoordinate(centerRect)
|
|
||||||
if (pointIsVisible(ptCenter) && pointIsVisible(ptCenterRect)) {
|
|
||||||
newZoomOut = zoomLevel
|
|
||||||
newZoomOutFound = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
zoomLevel -= 1.0
|
|
||||||
}
|
|
||||||
if (!newZoomOutFound)
|
|
||||||
newZoomOut = defaultZoomOut
|
|
||||||
// calculate zoom in
|
|
||||||
center = newCenter
|
|
||||||
zoomLevel = Math.floor(maximumZoomLevel)
|
|
||||||
var diagonalRect = topLeft.distanceTo(bottomRight)
|
|
||||||
while (zoomLevel > minimumZoomLevel) {
|
|
||||||
var c0 = toCoordinate(Qt.point(0.0, 0.0))
|
|
||||||
var c1 = toCoordinate(Qt.point(width, height))
|
|
||||||
if (c0.distanceTo(c1) > diagonalRect) {
|
|
||||||
newZoom = zoomLevel - 2.0
|
|
||||||
break
|
|
||||||
}
|
|
||||||
zoomLevel -= 1.0
|
|
||||||
}
|
|
||||||
if (newZoom > defaultZoomIn)
|
|
||||||
newZoom = defaultZoomIn
|
|
||||||
zoomLevel = zoomStored
|
|
||||||
center = centerStored
|
|
||||||
mapAnimationZoomIn.restart()
|
|
||||||
}
|
}
|
||||||
|
var centerStored = QtPositioning.coordinate(center.latitude, center.longitude)
|
||||||
|
var zoomStored = zoomLevel
|
||||||
|
var newZoomOutFound = false
|
||||||
|
newCenter = centerRect
|
||||||
|
// calculate zoom out
|
||||||
|
newZoomOut = zoomLevel
|
||||||
|
while (zoomLevel > minimumZoomLevel) {
|
||||||
|
var ptCenter = fromCoordinate(centerStored)
|
||||||
|
var ptCenterRect = fromCoordinate(centerRect)
|
||||||
|
if (pointIsVisible(ptCenter) && pointIsVisible(ptCenterRect)) {
|
||||||
|
newZoomOut = zoomLevel
|
||||||
|
newZoomOutFound = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
zoomLevel -= 1.0
|
||||||
|
}
|
||||||
|
if (!newZoomOutFound)
|
||||||
|
newZoomOut = defaultZoomOut
|
||||||
|
// calculate zoom in
|
||||||
|
center = newCenter
|
||||||
|
zoomLevel = Math.floor(maximumZoomLevel)
|
||||||
|
var diagonalRect = topLeft.distanceTo(bottomRight)
|
||||||
|
while (zoomLevel > minimumZoomLevel) {
|
||||||
|
var c0 = toCoordinate(Qt.point(0.0, 0.0))
|
||||||
|
var c1 = toCoordinate(Qt.point(width, height))
|
||||||
|
if (c0.distanceTo(c1) > diagonalRect) {
|
||||||
|
newZoom = zoomLevel - 2.0
|
||||||
|
break
|
||||||
|
}
|
||||||
|
zoomLevel -= 1.0
|
||||||
|
}
|
||||||
|
if (newZoom > defaultZoomIn)
|
||||||
|
newZoom = defaultZoomIn
|
||||||
|
zoomLevel = zoomStored
|
||||||
|
center = centerStored
|
||||||
|
mapAnimationZoomIn.restart()
|
||||||
}
|
}
|
||||||
|
|
||||||
function deselectMapLocation() {
|
function deselectMapLocation() {
|
||||||
|
|
Loading…
Reference in a new issue