diff options
-rw-r--r-- | map-widget/qmlmapwidgethelper.cpp | 9 | ||||
-rw-r--r-- | map-widget/qmlmapwidgethelper.h | 1 | ||||
-rw-r--r-- | mobile-widgets/qml/MapPage.qml | 18 |
3 files changed, 28 insertions, 0 deletions
diff --git a/map-widget/qmlmapwidgethelper.cpp b/map-widget/qmlmapwidgethelper.cpp index e8187a679..fa0616202 100644 --- a/map-widget/qmlmapwidgethelper.cpp +++ b/map-widget/qmlmapwidgethelper.cpp @@ -23,6 +23,15 @@ MapWidgetHelper::MapWidgetHelper(QObject *parent) : QObject(parent) this, SLOT(selectedLocationChanged(MapLocation *))); } +QGeoCoordinate MapWidgetHelper::getCoordinatesForUUID(QVariant dive_site_uuid) +{ + const uint32_t uuid = qvariant_cast<uint32_t>(dive_site_uuid); + struct dive_site *ds = get_dive_site_by_uuid(uuid); + if (!ds || !dive_site_has_gps_location(ds)) + return QGeoCoordinate(0.0, 0.0); + return QGeoCoordinate(ds->latitude.udeg * 0.000001, ds->longitude.udeg * 0.000001); +} + void MapWidgetHelper::centerOnDiveSiteUUID(QVariant dive_site_uuid) { const uint32_t uuid = qvariant_cast<uint32_t>(dive_site_uuid); diff --git a/map-widget/qmlmapwidgethelper.h b/map-widget/qmlmapwidgethelper.h index d5cdb35bc..eb57dcd88 100644 --- a/map-widget/qmlmapwidgethelper.h +++ b/map-widget/qmlmapwidgethelper.h @@ -22,6 +22,7 @@ public: explicit MapWidgetHelper(QObject *parent = NULL); void centerOnDiveSite(struct dive_site *); + Q_INVOKABLE QGeoCoordinate getCoordinatesForUUID(QVariant dive_site_uuid); Q_INVOKABLE void centerOnDiveSiteUUID(QVariant dive_site_uuid); Q_INVOKABLE void reloadMapLocations(); Q_INVOKABLE void copyToClipboardCoordinates(QGeoCoordinate coord, bool formatTraditional); diff --git a/mobile-widgets/qml/MapPage.qml b/mobile-widgets/qml/MapPage.qml index ee1e99dc2..fdfcfa213 100644 --- a/mobile-widgets/qml/MapPage.qml +++ b/mobile-widgets/qml/MapPage.qml @@ -12,6 +12,7 @@ Kirigami.Page { topPadding: 0 rightPadding: 0 bottomPadding: 0 + property bool firstRun: true MapWidget { id: mapWidget @@ -40,10 +41,27 @@ Kirigami.Page { 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) + } } |