Skip to content

Commit bd548b7

Browse files
feat: allow map API key configuration (#765)
1 parent acb5d6b commit bd548b7

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ cd build
8787
qmake ..
8888
```
8989
90+
### Map API Key
91+
92+
Some map providers such as Mapbox require an API key. The map widget now
93+
includes a **Map API key** field in its settings menu where you can paste
94+
your key so those providers can load correctly.
95+
9096
## Contributing
9197
9298
**Thanks to all the people who have contributed !**

qml/ui/elements/AppSettings.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ Settings {
338338
property bool show_gpio: false
339339
property int selected_map_provider: 0
340340
property int selected_map_variant: 0
341+
property string map_api_key: ""
341342

342343
property bool show_vibration: false
343344

qml/ui/widgets/map/MapWidget.qml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ MapWidgetForm {
2222
property variant map
2323

2424
Component.onCompleted: {
25-
// TODO: Figure out how we can get better (terrain) maps
26-
if(false){
27-
pluginModel.append({
28-
"name": "mapboxgl",
29-
"description": "MapboxGL"
30-
})
31-
}
25+
// Add additional map providers
26+
pluginModel.append({
27+
"name": "mapboxgl",
28+
"description": "MapboxGL"
29+
})
3230
// Consti10: This way we need a restart of QOpenHD when the map is enabled, but we
3331
// save some performance in case the map is not enabled
3432
if(settings.show_map){
@@ -64,13 +62,17 @@ MapWidgetForm {
6462
function createMap(parent, provider) {
6563
console.log("createMap(" + provider + ")");
6664
var plugin
65+
var pluginParameters = ""
66+
if (provider === "mapboxgl") {
67+
pluginParameters = 'PluginParameter { name: "mapbox.access_token"; value: "' + settings.map_api_key + '" }'
68+
} else if (provider === "osm") {
69+
pluginParameters = 'PluginParameter { name: "osm.mapping.custom.host"; value: "https://tile.openstreetmap.org/" }'
70+
}
6771
plugin = Qt.createQmlObject(`
6872
import QtLocation 5.15
6973
Plugin {
7074
name: "` + provider + `"
71-
PluginParameter {
72-
name: "osm.mapping.custom.host";
73-
value: "https://tile.openstreetmap.org/" }
75+
` + pluginParameters + `
7476
}
7577
`, mapWidget);
7678
console.log("Using plugin: " + plugin.name);

qml/ui/widgets/map/MapWidgetForm.ui.qml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ BaseWidget {
3232
property alias widgetInnerMap: widgetInnerMap
3333
property alias sidebar_wrapper: sidebar_wrapper
3434
property alias pluginModel: pluginModel
35+
property alias apiKeyField: apiKeyField
3536

3637
defaultAlignment: 1
3738
defaultXOffset: 12
@@ -535,6 +536,16 @@ BaseWidget {
535536

536537
}
537538

539+
TextField {
540+
id: apiKeyField
541+
height: 48
542+
width: parent.width
543+
placeholderText: qsTr("Map API key")
544+
text: settings.map_api_key
545+
visible: pluginModel.get(providerDropdown.currentIndex).name === "mapboxgl"
546+
onEditingFinished: settings.map_api_key = text
547+
}
548+
538549
ComboBox {
539550
id: variantDropdown
540551
height: 48

0 commit comments

Comments
 (0)