Unverified Commit 0030c00e authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #9018 from shatyuka/master

Add support for custom Mapbox style
parents 8c7e8cf6 92f97355
......@@ -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();
......
......@@ -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) {}
};
......@@ -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);
......
......@@ -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 {
......
......@@ -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",
......
......@@ -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)
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment