mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-18 00:06:15 +00:00
centerOnLocationHard() is added in MapPage.qml so that on `firstRun` the map is hard panned to the desired location without animation. This affects the selection of a new "Dive details" -> "Map it" or when opening a GPS location in the map. The idea behind this change is to avoid starting the map animation from an arbitrary location such as [0,0] or London. Also, to not start the map zoomed out completely and then zoom in on a selected dive. For this change to work, add the helper getCoordinatesForUUID() to qmlmapwidgethelper.cpp/.h and use it to obtain the QGeoCoordinates for a dive site UUID. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
67 lines
1.8 KiB
QML
67 lines
1.8 KiB
QML
// SPDX-License-Identifier: GPL-2.0
|
|
import QtQuick 2.6
|
|
import QtPositioning 5.3
|
|
import org.subsurfacedivelog.mobile 1.0
|
|
import org.kde.kirigami 2.2 as Kirigami
|
|
|
|
Kirigami.Page {
|
|
id: mapPage
|
|
objectName: "MapPage"
|
|
title: qsTr("Map")
|
|
leftPadding: 0
|
|
topPadding: 0
|
|
rightPadding: 0
|
|
bottomPadding: 0
|
|
property bool firstRun: true
|
|
|
|
MapWidget {
|
|
id: mapWidget
|
|
anchors.fill: parent
|
|
onSelectedDivesChanged: {
|
|
if (list.length === 0) {
|
|
console.warn("main.qml: onSelectedDivesChanged(): received empty list!")
|
|
return
|
|
}
|
|
var id = list[0] // only single dive selection is supported
|
|
var idx = diveModel.getIdxForId(id)
|
|
if (idx === -1) {
|
|
console.warn("main.qml: onSelectedDivesChanged(): cannot find list index for dive id:", id)
|
|
return
|
|
}
|
|
diveList.setCurrentDiveListIndex(idx, true)
|
|
}
|
|
}
|
|
|
|
function reloadMap() {
|
|
mapWidget.mapHelper.reloadMapLocations()
|
|
}
|
|
|
|
function centerOnDiveSiteUUID(uuid) {
|
|
if (!uuid) {
|
|
console.warn("main.qml: centerOnDiveSiteUUI(): uuid is undefined!")
|
|
return
|
|
}
|
|
// on firstRun, hard pan/center the map to the desired location so that
|
|
// we don't start at an arbitrary location such as [0,0] or London.
|
|
if (firstRun) {
|
|
var coord = mapWidget.mapHelper.getCoordinatesForUUID(uuid)
|
|
centerOnLocationHard(coord.latitude, coord.longitude)
|
|
firstRun = false
|
|
} // continue here as centerOnDiveSiteUUID() also does marker selection.
|
|
mapWidget.mapHelper.centerOnDiveSiteUUID(uuid)
|
|
}
|
|
|
|
function centerOnLocation(lat, lon) {
|
|
if (firstRun) {
|
|
centerOnLocationHard(lat, lon)
|
|
firstRun = false
|
|
return // no need to animate via centerOnCoordinate().
|
|
}
|
|
mapWidget.map.centerOnCoordinate(QtPositioning.coordinate(lat, lon))
|
|
}
|
|
|
|
function centerOnLocationHard(lat, lon) {
|
|
mapWidget.map.zoomLevel = mapWidget.map.defaultZoomIn
|
|
mapWidget.map.center = QtPositioning.coordinate(lat, lon)
|
|
}
|
|
}
|