From eda0bf4b234098e87af30bd5df6277a637dee886 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sun, 1 Sep 2024 13:34:04 -0400 Subject: [PATCH] LocationChooser: Add a "Locate" button to locate yourself The map centers on London by default, but for the other people living outside it may find it hard to figure out where they are. This adds a button that calls into QtPositioning to center the map over where you are. --- src/qml/LocationChooser.qml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/qml/LocationChooser.qml b/src/qml/LocationChooser.qml index 7138585d8..82c8bb7dd 100644 --- a/src/qml/LocationChooser.qml +++ b/src/qml/LocationChooser.qml @@ -36,9 +36,30 @@ Components.AbstractMaximizeComponent { icon.name: "snap-bounding-box-center-symbolic" onTriggered: mapView.map.fitViewportToMapItems([mapView.locationMapItem]) enabled: root.location !== undefined + }, + Kirigami.Action { + text: i18nc("@action:intoolbar Determine the device's location", "Locate") + icon.name: "mark-location-symbolic" + enabled: positionSource.valid + onTriggered: positionSource.update() } ] + PositionSource { + id: positionSource + + active: false + + onPositionChanged: { + const coord = position.coordinate; + mapView.gpsMapItem.latitude = coord.latitude; + mapView.gpsMapItem.longitude = coord.longitude; + + mapView.map.addMapItem(mapView.gpsMapItem); + mapView.map.fitViewportToMapItems([mapView.gpsMapItem]) + } + } + content: MapView { id: mapView map.plugin: OsmLocationPlugin.plugin @@ -60,6 +81,15 @@ Components.AbstractMaximizeComponent { author: null } + readonly property LocationMapItem gpsMapItem: LocationMapItem { + latitude: 0.0 + longitude: 0.0 + isLive: true + heading: NaN + asset: "" + author: null + } + Connections { target: mapView.map function onCopyrightLinkActivated(link: string) {