diff --git a/src/QtLocationPlugin/MapboxMapProvider.cpp b/src/QtLocationPlugin/MapboxMapProvider.cpp index 214bd8beca9f8338c5619e1f60a8bcae05d55152..15c2117a1ade00d9483c29dc2c4bdea1328ec30c 100644 --- a/src/QtLocationPlugin/MapboxMapProvider.cpp +++ b/src/QtLocationPlugin/MapboxMapProvider.cpp @@ -4,6 +4,7 @@ #include "SettingsManager.h" static const QString MapBoxUrl = QStringLiteral("https://api.mapbox.com/v4/%1/%2/%3/%4.jpg80?access_token=%5"); +static const QString MapBoxUrlCustom = QStringLiteral("https://api.mapbox.com/styles/v1/%1/%2/tiles/256/%3/%4/%5?access_token=%6"); MapboxMapProvider::MapboxMapProvider(const QString &mapName, const quint32 averageSize, const QGeoMapType::MapStyle mapType, QObject* parent) : MapProvider(QStringLiteral("https://www.mapbox.com/"), QStringLiteral("jpg"), averageSize, mapType, parent) @@ -15,6 +16,11 @@ QString MapboxMapProvider::_getURL(const int x, const int y, const int zoom, QNe Q_UNUSED(networkManager) const QString mapBoxToken = qgcApp()->toolbox()->settingsManager()->appSettings()->mapboxToken()->rawValue().toString(); if (!mapBoxToken.isEmpty()) { + if (_mapboxName == QString("mapbox.custom")) { + const QString mapBoxAccount = qgcApp()->toolbox()->settingsManager()->appSettings()->mapboxAccount()->rawValue().toString(); + const QString mapBoxStyle = qgcApp()->toolbox()->settingsManager()->appSettings()->mapboxStyle()->rawValue().toString(); + return MapBoxUrlCustom.arg(mapBoxAccount).arg(mapBoxStyle).arg(zoom).arg(x).arg(y).arg(mapBoxToken); + } return MapBoxUrl.arg(_mapboxName).arg(zoom).arg(x).arg(y).arg(mapBoxToken); } return QString(); diff --git a/src/QtLocationPlugin/MapboxMapProvider.h b/src/QtLocationPlugin/MapboxMapProvider.h index 239e4f4e4e7c4b9d0dff8e5889035de955760ed0..5d59903ca6dd4427f86a247c811cf386d4a370e3 100644 --- a/src/QtLocationPlugin/MapboxMapProvider.h +++ b/src/QtLocationPlugin/MapboxMapProvider.h @@ -151,3 +151,12 @@ public: : MapboxMapProvider(QStringLiteral("mapbox.high-contrast"), AVERAGE_TILE_SIZE, QGeoMapType::CustomMap, parent) {} }; + +class MapboxCustomMapProvider : public MapboxMapProvider { + Q_OBJECT + +public: + MapboxCustomMapProvider(QObject* parent = nullptr) + : MapboxMapProvider(QStringLiteral("mapbox.custom"), AVERAGE_TILE_SIZE, + QGeoMapType::CustomMap, parent) {} +}; diff --git a/src/QtLocationPlugin/QGCMapUrlEngine.cpp b/src/QtLocationPlugin/QGCMapUrlEngine.cpp index 31513f329d60eb39606c6b822ebc2ba41a75b537..2d26b8ab2d20aeb6dee92e39c49b34e0b5230e42 100644 --- a/src/QtLocationPlugin/QGCMapUrlEngine.cpp +++ b/src/QtLocationPlugin/QGCMapUrlEngine.cpp @@ -67,6 +67,7 @@ UrlFactory::UrlFactory() : _timeout(5 * 1000) { _providersTable["Mapbox Outdoors"] = new MapboxOutdoorsMapProvider(this); _providersTable["Mapbox RunBikeHike"] = new MapboxRunBikeHikeMapProvider(this); _providersTable["Mapbox HighContrast"] = new MapboxHighContrastMapProvider(this); + _providersTable["Mapbox Custom"] = new MapboxCustomMapProvider(this); //_providersTable["MapQuest Map"] = new MapQuestMapMapProvider(this); //_providersTable["MapQuest Sat"] = new MapQuestSatMapProvider(this); diff --git a/src/QtLocationPlugin/QMLControl/OfflineMap.qml b/src/QtLocationPlugin/QMLControl/OfflineMap.qml index dcb276f8aca0fe48cf098cedcb86996658591adf..596b212e2cfe325b05102fb5fc42a1ec0ed96671 100644 --- a/src/QtLocationPlugin/QMLControl/OfflineMap.qml +++ b/src/QtLocationPlugin/QMLControl/OfflineMap.qml @@ -36,6 +36,8 @@ Item { property var _settings: _settingsManager ? _settingsManager.offlineMapsSettings : null property var _fmSettings: _settingsManager ? _settingsManager.flightMapSettings : null property Fact _mapboxFact: _settingsManager ? _settingsManager.appSettings.mapboxToken : null + property Fact _mapboxAccountFact: _settingsManager ? _settingsManager.appSettings.mapboxAccount : null + property Fact _mapboxStyleFact: _settingsManager ? _settingsManager.appSettings.mapboxStyle : null property Fact _esriFact: _settingsManager ? _settingsManager.appSettings.esriToken : null property string mapType: _fmSettings ? (_fmSettings.mapProvider.value + " " + _fmSettings.mapType.value) : "" @@ -316,6 +318,40 @@ Item { font.pointSize: _adjustableFontPointSize } + Item { width: 1; height: 1; visible: _mapboxAccountFact ? _mapboxAccountFact.visible : false } + QGCLabel { text: qsTr("Mapbox User Name"); visible: _mapboxAccountFact ? _mapboxAccountFact.visible : false } + FactTextField { + fact: _mapboxAccountFact + visible: _mapboxAccountFact ? _mapboxAccountFact.visible : false + maximumLength: 256 + width: ScreenTools.defaultFontPixelWidth * 30 + } + QGCLabel { + anchors.left: parent.left + anchors.right: parent.right + wrapMode: Text.WordWrap + text: qsTr("To enable custom Mapbox styles, enter your account name.") + visible: _mapboxAccountFact ? _mapboxAccountFact.visible : false + font.pointSize: _adjustableFontPointSize + } + + Item { width: 1; height: 1; visible: _mapboxStyleFact ? _mapboxStyleFact.visible : false } + QGCLabel { text: qsTr("Mapbox Style ID"); visible: _mapboxStyleFact ? _mapboxStyleFact.visible : false } + FactTextField { + fact: _mapboxStyleFact + visible: _mapboxStyleFact ? _mapboxStyleFact.visible : false + maximumLength: 256 + width: ScreenTools.defaultFontPixelWidth * 30 + } + QGCLabel { + anchors.left: parent.left + anchors.right: parent.right + wrapMode: Text.WordWrap + text: qsTr("To enable custom Mapbox styles, enter your style ID.") + visible: _mapboxStyleFact ? _mapboxStyleFact.visible : false + font.pointSize: _adjustableFontPointSize + } + Item { width: 1; height: 1; visible: _esriFact ? _esriFact.visible : false } QGCLabel { text: qsTr("Esri Access Token"); visible: _esriFact ? _esriFact.visible : false } FactTextField { diff --git a/src/Settings/App.SettingsGroup.json b/src/Settings/App.SettingsGroup.json index 412a386659dfc6d73a77c91b55c0e3c669dd50ba..939c154821476fd26926e3eb60d50a5565177827 100644 --- a/src/Settings/App.SettingsGroup.json +++ b/src/Settings/App.SettingsGroup.json @@ -196,6 +196,20 @@ "type": "string", "default": "" }, +{ + "name": "mapboxAccount", + "shortDesc": "Account name for Mapbox maps", + "longDesc": "Your personal account name for Mapbox maps", + "type": "string", + "default": "" +}, +{ + "name": "mapboxStyle", + "shortDesc": "Map style ID", + "longDesc": "Map design style ID for Mapbox maps", + "type": "string", + "default": "" +}, { "name": "esriToken", "shortDesc": "Access token to Esri maps", diff --git a/src/Settings/AppSettings.cc b/src/Settings/AppSettings.cc index f889f9959e0ec26a6b55c8ec4454511b8e71821f..3ad8f74aab70ff230eda90654774fa15edd9462f 100644 --- a/src/Settings/AppSettings.cc +++ b/src/Settings/AppSettings.cc @@ -119,6 +119,8 @@ DECLARE_SETTINGSFACT(AppSettings, savePath) DECLARE_SETTINGSFACT(AppSettings, useChecklist) DECLARE_SETTINGSFACT(AppSettings, enforceChecklist) DECLARE_SETTINGSFACT(AppSettings, mapboxToken) +DECLARE_SETTINGSFACT(AppSettings, mapboxAccount) +DECLARE_SETTINGSFACT(AppSettings, mapboxStyle) DECLARE_SETTINGSFACT(AppSettings, esriToken) DECLARE_SETTINGSFACT(AppSettings, defaultFirmwareType) DECLARE_SETTINGSFACT(AppSettings, gstDebugLevel) diff --git a/src/Settings/AppSettings.h b/src/Settings/AppSettings.h index 89c366ca2f22918d87f1891fa8414c3b36b6e37b..636c3321ab18961ca18918faaf72f051e959fd36 100644 --- a/src/Settings/AppSettings.h +++ b/src/Settings/AppSettings.h @@ -47,6 +47,8 @@ public: DEFINE_SETTINGFACT(useChecklist) DEFINE_SETTINGFACT(enforceChecklist) DEFINE_SETTINGFACT(mapboxToken) + DEFINE_SETTINGFACT(mapboxAccount) + DEFINE_SETTINGFACT(mapboxStyle) DEFINE_SETTINGFACT(esriToken) DEFINE_SETTINGFACT(defaultFirmwareType) DEFINE_SETTINGFACT(gstDebugLevel)