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.
This commit is contained in:
Joshua Goins
2024-09-01 13:34:04 -04:00
parent 4f4b10e0b6
commit eda0bf4b23

View File

@@ -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) {