diff --git a/src/Airmap/AirmapSettings.qml b/src/Airmap/AirmapSettings.qml index bf733eaa7a220a365172859b0aa005cb14b38d96..3cf68d668c3d4c7b12fad715f19ed85b91e3beba 100644 --- a/src/Airmap/AirmapSettings.qml +++ b/src/Airmap/AirmapSettings.qml @@ -681,7 +681,7 @@ Item { visible: !QGroundControl.airspaceManager.flightPlan.loadingFlightList && _flightList.count > 0 && tableView.currentRow >= 0 function updateActiveMapType() { var settings = QGroundControl.settingsManager.flightMapSettings - var fullMapName = settings.mapProvider.enumStringValue + " " + settings.mapType.enumStringValue + var fullMapName = settings.mapProvider.value + " " + settings.mapType.value for (var i = 0; i < map.supportedMapTypes.length; i++) { if (fullMapName === map.supportedMapTypes[i].name) { map.activeMapType = map.supportedMapTypes[i] diff --git a/src/FlightMap/FlightMap.qml b/src/FlightMap/FlightMap.qml index 5cad4ab1bb701689cdaf4d3bdaa2682efb0062f6..afb59804da64059acecbe43f90f57fb8078767ac 100644 --- a/src/FlightMap/FlightMap.qml +++ b/src/FlightMap/FlightMap.qml @@ -95,7 +95,10 @@ Map { function updateActiveMapType() { var settings = QGroundControl.settingsManager.flightMapSettings - var fullMapName = settings.mapProvider.enumStringValue + " " + settings.mapType.enumStringValue + //var fullMapName = settings.mapProvider.value + " " + settings.mapType.value + var fullMapName = settings.mapProvider.value + + console.log("updateActiveMapType",fullMapName) for (var i = 0; i < _map.supportedMapTypes.length; i++) { if (fullMapName === _map.supportedMapTypes[i].name) { _map.activeMapType = _map.supportedMapTypes[i] diff --git a/src/QtLocationPlugin/GoogleMapProvider.h b/src/QtLocationPlugin/GoogleMapProvider.h index fcb808a82551a3a3655e39f6a623ee259df1cf72..154bb883da4ba4432303129fec2cada0094c6256 100644 --- a/src/QtLocationPlugin/GoogleMapProvider.h +++ b/src/QtLocationPlugin/GoogleMapProvider.h @@ -56,9 +56,9 @@ class GoogleMapProvider : public MapProvider { // CycleMap, // CustomMap = 100 -const unsigned int AVERAGE_GOOGLE_STREET_MAP = 4913; -const unsigned int AVERAGE_GOOGLE_SAT_MAP = 56887; -const unsigned int AVERAGE_GOOGLE_TERRAIN_MAP = 19391; +const quint32 AVERAGE_GOOGLE_STREET_MAP = 4913; +const quint32 AVERAGE_GOOGLE_SAT_MAP = 56887; +const quint32 AVERAGE_GOOGLE_TERRAIN_MAP = 19391; // ----------------------------------------------------------- // Google Street Map diff --git a/src/QtLocationPlugin/MapProvider.h b/src/QtLocationPlugin/MapProvider.h index 7f36b4aad1013f03f37d2c0132cabeff25ab2c09..4da03bee4cd68cd339ad9907957538e4d0a14782 100644 --- a/src/QtLocationPlugin/MapProvider.h +++ b/src/QtLocationPlugin/MapProvider.h @@ -11,12 +11,12 @@ static const unsigned char pngSignature[] = {0x89, 0x50, 0x4E, 0x47, 0x0D, static const unsigned char jpegSignature[] = {0xFF, 0xD8, 0xFF, 0x00}; static const unsigned char gifSignature[] = {0x47, 0x49, 0x46, 0x38, 0x00}; -const unsigned int AVERAGE_BING_STREET_MAP = 1297; -const unsigned int AVERAGE_BING_SAT_MAP = 19597; -const unsigned int AVERAGE_MAPBOX_SAT_MAP = 15739; -const unsigned int AVERAGE_MAPBOX_STREET_MAP = 5648; -const unsigned int AVERAGE_TILE_SIZE = 13652; -const unsigned int AVERAGE_AIRMAP_ELEV_SIZE = 2786; +const quint32 AVERAGE_BING_STREET_MAP = 1297; +const quint32 AVERAGE_BING_SAT_MAP = 19597; +const quint32 AVERAGE_MAPBOX_SAT_MAP = 15739; +const quint32 AVERAGE_MAPBOX_STREET_MAP = 5648; +const quint32 AVERAGE_TILE_SIZE = 13652; +const quint32 AVERAGE_AIRMAP_ELEV_SIZE = 2786; class MapProvider : public QObject { Q_OBJECT diff --git a/src/QtLocationPlugin/QGCMapUrlEngine.cpp b/src/QtLocationPlugin/QGCMapUrlEngine.cpp index b8a2426f7a68f60146934dbbc8853ddd7799d8da..6b3e536ec7febb782b09b3ec639a03226468d5f5 100644 --- a/src/QtLocationPlugin/QGCMapUrlEngine.cpp +++ b/src/QtLocationPlugin/QGCMapUrlEngine.cpp @@ -7,70 +7,72 @@ * ****************************************************************************/ - /** * @file * @author Gus Grubba - * Original work: The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * Original work: The OpenPilot Team, http://www.openpilot.org Copyright (C) + * 2012. */ //#define DEBUG_GOOGLE_MAPS +#include "AppSettings.h" #include "QGCApplication.h" #include "QGCMapEngine.h" -#include "AppSettings.h" #include "SettingsManager.h" -#include -#include +#include #include -#include +#include +#include #include -#include - - +#include //----------------------------------------------------------------------------- -UrlFactory::UrlFactory() - : _timeout(5 * 1000) -{ +UrlFactory::UrlFactory() : _timeout(5 * 1000) { // BingMaps //_versionBingMaps = "563"; #ifndef QGC_NO_GOOGLE_MAPS - _providersTable["GoogleStreet"] = new GoogleStreetMapProvider(this); - _providersTable["GoogleSatellite"] = new GoogleSatelliteMapProvider(this); + _providersTable["Google Street Map"] = new GoogleStreetMapProvider(this); + _providersTable["Google Satellite"] = new GoogleSatelliteMapProvider(this); + _providersTable["Google Terrain"] = new GoogleTerrainMapProvider(this); #endif } -void UrlFactory::registerProvider(QString name, MapProvider* provider){ - _providersTable[name]=provider; +void UrlFactory::registerProvider(QString name, MapProvider* provider) { + _providersTable[name] = provider; } //----------------------------------------------------------------------------- -UrlFactory::~UrlFactory() -{ -} - -QString -UrlFactory::getImageFormat(int id, const QByteArray& image) -{ - return _providersTable[getTypeFromId(id)]->getImageFormat(image); +UrlFactory::~UrlFactory() {} + +QString UrlFactory::getImageFormat(int id, const QByteArray& image) { + QString type = getTypeFromId(id); + if (_providersTable.find(type) != _providersTable.end()) { + return _providersTable[getTypeFromId(id)]->getImageFormat(image); + } else { + return ""; + } } //----------------------------------------------------------------------------- -QString -UrlFactory::getImageFormat(QString type, const QByteArray& image) -{ - return _providersTable[type]->getImageFormat(image); - //QString format; - //if(image.size() > 2) +QString UrlFactory::getImageFormat(QString type, const QByteArray& image) { + if (_providersTable.find(type) != _providersTable.end()) { + return _providersTable[type]->getImageFormat(image); + } else { + return ""; + } + // QString format; + // if(image.size() > 2) //{ // if (image.startsWith(reinterpret_cast(pngSignature))) // format = "png"; - // else if (image.startsWith(reinterpret_cast(jpegSignature))) + // else if (image.startsWith(reinterpret_cast(jpegSignature))) // format = "jpg"; - // else if (image.startsWith(reinterpret_cast(gifSignature))) + // else if (image.startsWith(reinterpret_cast(gifSignature))) // format = "gif"; // else { // switch (type) { @@ -119,40 +121,44 @@ UrlFactory::getImageFormat(QString type, const QByteArray& image) // format = "jpg"; // break; // default: - // qWarning("UrlFactory::getImageFormat() Unknown map id %d", type); - // break; + // qWarning("UrlFactory::getImageFormat() Unknown map id %d", + // type); break; // } // } //} - //return format; + // return format; } -QNetworkRequest -UrlFactory::getTileURL(int id, int x, int y, int zoom, QNetworkAccessManager* networkManager){ +QNetworkRequest UrlFactory::getTileURL(int id, int x, int y, int zoom, + QNetworkAccessManager* networkManager) { - return _providersTable[getTypeFromId(id)]->getTileURL(x,y,zoom,networkManager); + QString type = getTypeFromId(id); + if (_providersTable.find(type) != _providersTable.end()) { + return _providersTable[type]->getTileURL(x, y, zoom, networkManager); + } + return QNetworkRequest(QUrl()); } //----------------------------------------------------------------------------- -QNetworkRequest -UrlFactory::getTileURL(QString type, int x, int y, int zoom, QNetworkAccessManager* networkManager) -{ - return _providersTable[type]->getTileURL(x,y,zoom,networkManager); +QNetworkRequest UrlFactory::getTileURL(QString type, int x, int y, int zoom, + QNetworkAccessManager* networkManager) { + return _providersTable[type]->getTileURL(x, y, zoom, networkManager); ////-- Build URL - //QNetworkRequest request; - //QString url = _getURL(type, x, y, zoom, networkManager); - //if(url.isEmpty()) { + // QNetworkRequest request; + // QString url = _getURL(type, x, y, zoom, networkManager); + // if(url.isEmpty()) { // return request; //} - //request.setUrl(QUrl(url)); - //request.setRawHeader("Accept", "*/*"); - //switch (type) { -// // case GoogleMap: -// // case GoogleSatellite: -// // case GoogleLabels: -// // case GoogleTerrain: -// // case GoogleHybrid: -// // request.setRawHeader("Referrer", "https://www.google.com/maps/preview"); -// // break; + // request.setUrl(QUrl(url)); + // request.setRawHeader("Accept", "*/*"); + // switch (type) { + // // case GoogleMap: + // // case GoogleSatellite: + // // case GoogleLabels: + // // case GoogleTerrain: + // // case GoogleHybrid: + // // request.setRawHeader("Referrer", + // "https://www.google.com/maps/preview"); + // // break; // case BingHybrid: // case BingMap: // case BingSatellite: @@ -171,15 +177,17 @@ UrlFactory::getTileURL(QString type, int x, int y, int zoom, QNetworkAccessManag // break; // case OpenStreetMap: // case OpenStreetOsm: - // request.setRawHeader("Referrer", "https://www.openstreetmap.org/"); - // break; + // request.setRawHeader("Referrer", + // "https://www.openstreetmap.org/"); break; // */ // case EsriWorldStreet: // case EsriWorldSatellite: // case EsriTerrain: { - // QByteArray token = qgcApp()->toolbox()->settingsManager()->appSettings()->esriToken()->rawValue().toString().toLatin1(); - // request.setRawHeader("User-Agent", QByteArrayLiteral("Qt Location based application")); + // QByteArray token = + // qgcApp()->toolbox()->settingsManager()->appSettings()->esriToken()->rawValue().toString().toLatin1(); + // request.setRawHeader("User-Agent", QByteArrayLiteral("Qt + // Location based application")); // request.setRawHeader("User-Token", token); // } // return request; @@ -191,8 +199,8 @@ UrlFactory::getTileURL(QString type, int x, int y, int zoom, QNetworkAccessManag // default: // break; //} - //request.setRawHeader("User-Agent", _userAgent); - //return request; + // request.setRawHeader("User-Agent", _userAgent); + // return request; } //----------------------------------------------------------------------------- @@ -455,59 +463,62 @@ UrlFactory::_getURL(QString type, int x, int y, int zoom, QNetworkAccessManager* #endif - //----------------------------------------------------------------------------- -quint32 -UrlFactory::averageSizeForType(QString type) -{ - return _providersTable[type]->getAverageSize(); - -// switch (type) { -// case GoogleMap: -// return AVERAGE_GOOGLE_STREET_MAP; -// case BingMap: -// return AVERAGE_BING_STREET_MAP; -// case GoogleSatellite: -// return AVERAGE_GOOGLE_SAT_MAP; -// case MapboxSatellite: -// return AVERAGE_MAPBOX_SAT_MAP; -// case BingHybrid: -// case BingSatellite: -// return AVERAGE_BING_SAT_MAP; -// case GoogleTerrain: -// return AVERAGE_GOOGLE_TERRAIN_MAP; -// case MapboxStreets: -// case MapboxStreetsBasic: -// case MapboxRunBikeHike: -// return AVERAGE_MAPBOX_STREET_MAP; -// case AirmapElevation: -// return AVERAGE_AIRMAP_ELEV_SIZE; -// case GoogleLabels: -// case MapboxDark: -// case MapboxLight: -// case MapboxOutdoors: -// case MapboxPencil: -// case OpenStreetMap: -// case GoogleHybrid: -// case MapboxComic: -// case MapboxEmerald: -// case MapboxHighContrast: -// case MapboxHybrid: -// case MapboxPirates: -// case MapboxWheatPaste: -// default: -// break; -// } -// return AVERAGE_TILE_SIZE; +quint32 UrlFactory::averageSizeForType(QString type) { + qDebug() << "UrlFactory::averageSizeForType for" << type; + if (_providersTable.find(type) != _providersTable.end()) { + return _providersTable[type]->getAverageSize(); + } else { + qDebug() << "UrlFactory::averageSizeForType " << type + << " Not registered"; + } + + // switch (type) { + // case GoogleMap: + // return AVERAGE_GOOGLE_STREET_MAP; + // case BingMap: + // return AVERAGE_BING_STREET_MAP; + // case GoogleSatellite: + // return AVERAGE_GOOGLE_SAT_MAP; + // case MapboxSatellite: + // return AVERAGE_MAPBOX_SAT_MAP; + // case BingHybrid: + // case BingSatellite: + // return AVERAGE_BING_SAT_MAP; + // case GoogleTerrain: + // return AVERAGE_GOOGLE_TERRAIN_MAP; + // case MapboxStreets: + // case MapboxStreetsBasic: + // case MapboxRunBikeHike: + // return AVERAGE_MAPBOX_STREET_MAP; + // case AirmapElevation: + // return AVERAGE_AIRMAP_ELEV_SIZE; + // case GoogleLabels: + // case MapboxDark: + // case MapboxLight: + // case MapboxOutdoors: + // case MapboxPencil: + // case OpenStreetMap: + // case GoogleHybrid: + // case MapboxComic: + // case MapboxEmerald: + // case MapboxHighContrast: + // case MapboxHybrid: + // case MapboxPirates: + // case MapboxWheatPaste: + // default: + // break; + // } + // return AVERAGE_TILE_SIZE; } -QString UrlFactory::getTypeFromId(int id){ +QString UrlFactory::getTypeFromId(int id) { QHashIterator i(_providersTable); - while(i.hasNext()){ + while (i.hasNext()) { i.next(); - if(abs(qHash(i.key())) == id){ + if (abs(qHash(i.key())) == id) { return i.key(); } } @@ -517,6 +528,4 @@ QString UrlFactory::getTypeFromId(int id){ // Todo : qHash produce a uint bigger than max(int) // There is still a low probability for abs to // generate similar hash for different types -int UrlFactory::getIdFromType(QString type){ - return abs(qHash(type)); -} +int UrlFactory::getIdFromType(QString type) { return abs(qHash(type)); } diff --git a/src/QtLocationPlugin/QMLControl/OfflineMap.qml b/src/QtLocationPlugin/QMLControl/OfflineMap.qml index 433ccc20c279d906445dd0141a885b1ed7e05530..253d5513489efadbcbae0e8da2dfaba799edd1cd 100644 --- a/src/QtLocationPlugin/QMLControl/OfflineMap.qml +++ b/src/QtLocationPlugin/QMLControl/OfflineMap.qml @@ -38,7 +38,7 @@ Item { property Fact _mapboxFact: _settingsManager ? _settingsManager.appSettings.mapboxToken : null property Fact _esriFact: _settingsManager ? _settingsManager.appSettings.esriToken : null - property string mapType: _fmSettings ? (_fmSettings.mapProvider.enumStringValue + " " + _fmSettings.mapType.enumStringValue) : "" + property string mapType: _fmSettings ? (_fmSettings.mapProvider.value + " " + _fmSettings.mapType.value) : "" property bool isMapInteractive: false property var savedCenter: undefined property real savedZoom: 3 @@ -93,10 +93,10 @@ Item { function updateMap() { for (var i = 0; i < _map.supportedMapTypes.length; i++) { - //console.log(_map.supportedMapTypes[i].name) + console.log(_map.supportedMapTypes[i].name, i) if (mapType === _map.supportedMapTypes[i].name) { _map.activeMapType = _map.supportedMapTypes[i] - //console.log("Update Map:" + " " + _map.activeMapType) + console.log("Update Map:" + " " + _map.activeMapType) handleChanges() return } diff --git a/src/Settings/FlightMap.SettingsGroup.json b/src/Settings/FlightMap.SettingsGroup.json index 1a4d9484e96f06974d4e894c28e8dc55af1e41f3..41edd20bb840696b6140d1314d5e04e76f209a19 100644 --- a/src/Settings/FlightMap.SettingsGroup.json +++ b/src/Settings/FlightMap.SettingsGroup.json @@ -2,17 +2,12 @@ { "name": "mapProvider", "shortDescription": "Currently selected map provider for flight maps", - "type": "uint32", - "enumStrings": "Bing,Google,Statkart,Mapbox,Esri,Eniro,VWorld", - "enumValues": "0,1,2,3,4,5,6", - "defaultValue": 0 + "type": "string" }, { "name": "mapType", "shortDescription": "Currently selected map type for flight maps", - "type": "uint32", - "enumStrings": "Street Map,Satellite Map,Hybrid Map,Terrain Map", - "enumValues": "0,1,2,3", - "defaultValue": 2 + "type": "string", + "default": "" } ] diff --git a/src/Settings/FlightMapSettings.cc b/src/Settings/FlightMapSettings.cc index d18f840fb7f9582c05700a7aa9093dc587ada713..b0b8e88ee64f22e2126a26e0dee2b6959adbc2b2 100644 --- a/src/Settings/FlightMapSettings.cc +++ b/src/Settings/FlightMapSettings.cc @@ -19,106 +19,7 @@ DECLARE_SETTINGGROUP(FlightMap, "FlightMap") { qmlRegisterUncreatableType("QGroundControl.SettingsManager", 1, 0, "FlightMapSettings", "Reference only"); - - // Save the original version since we modify based on map provider - _savedMapTypeStrings = _nameToMetaDataMap[mapTypeName]->enumStrings(); - _savedMapTypeValues = _nameToMetaDataMap[mapTypeName]->enumValues(); - -#ifdef QGC_NO_GOOGLE_MAPS - //-- Remove Google - _excludeProvider(mapProviderGoogle); -#endif - if(qgcApp()->toolbox()->settingsManager()->appSettings()->mapboxToken()->rawValue().toString().isEmpty()) { - _excludeProvider(mapProviderMapbox); - } - if(qgcApp()->toolbox()->settingsManager()->appSettings()->esriToken()->rawValue().toString().isEmpty()) { - _excludeProvider(mapProviderEsri); - } - _newMapProvider(mapProvider()->rawValue()); } +DECLARE_SETTINGSFACT(FlightMapSettings, mapProvider) DECLARE_SETTINGSFACT(FlightMapSettings, mapType) - -DECLARE_SETTINGSFACT_NO_FUNC(FlightMapSettings, mapProvider) -{ - if (!_mapProviderFact) { - _mapProviderFact = _createSettingsFact(mapProviderName); - connect(_mapProviderFact, &Fact::rawValueChanged, this, &FlightMapSettings::_newMapProvider); - } - return _mapProviderFact; -} - -void FlightMapSettings::_excludeProvider(MapProvider_t provider) -{ - FactMetaData* metaData = _nameToMetaDataMap[mapProviderName]; - QVariantList enumValues = metaData->enumValues(); - QStringList enumStrings = metaData->enumStrings(); - _removeEnumValue(provider, enumStrings, enumValues); - metaData->setEnumInfo(enumStrings, enumValues); -} - -void FlightMapSettings::_removeEnumValue(int value, QStringList& enumStrings, QVariantList& enumValues) -{ - bool found = false; - int removeIndex; - for (removeIndex=0; removeIndexsetEnumInfo(enumStrings, enumValues); - emit mapTypeChanged(); - - // Check that map type is still valid for this new map provider - - bool found = false; - int currentMapType = mapType()->rawValue().toInt(); - for (int i=0; isetRawValue(0); - } -} diff --git a/src/Settings/FlightMapSettings.h b/src/Settings/FlightMapSettings.h index 452bddeb106d3fdcf01f3f26fe78bbd7835cbd64..9932410b43eb93faa2a2f542b7e9e876f8f2bd5a 100644 --- a/src/Settings/FlightMapSettings.h +++ b/src/Settings/FlightMapSettings.h @@ -18,39 +18,9 @@ class FlightMapSettings : public SettingsGroup public: FlightMapSettings(QObject* parent = nullptr); - // This enum must match the json meta data - typedef enum { - mapProviderBing, - mapProviderGoogle, - mapProviderStarkart, - mapProviderMapbox, - mapProviderEsri, - mapProviderEniro, - mapProviderVWorld - } MapProvider_t; - - // This enum must match the json meta data - typedef enum { - mapTypeStreet, - mapTypeSatellite, - mapTypeHybrid, - mapTypeTerrain - } MapType_t; DEFINE_SETTING_NAME_GROUP() DEFINE_SETTINGFACT(mapProvider) DEFINE_SETTINGFACT(mapType) -signals: - void mapTypeChanged(void); - -private slots: - void _newMapProvider(QVariant value); - -private: - void _removeEnumValue(int value, QStringList& enumStrings, QVariantList& enumValues); - void _excludeProvider(MapProvider_t provider); - - QStringList _savedMapTypeStrings; - QVariantList _savedMapTypeValues; }; diff --git a/src/ui/preferences/GeneralSettings.qml b/src/ui/preferences/GeneralSettings.qml index 1ad8c600b65713f00e8440df83b2aeb2644a982b..c422ca9e65d843ae6f316d1077fa0b6e79a24237 100644 --- a/src/ui/preferences/GeneralSettings.qml +++ b/src/ui/preferences/GeneralSettings.qml @@ -38,8 +38,8 @@ Rectangle { property real _labelWidth: ScreenTools.defaultFontPixelWidth * 20 property real _comboFieldWidth: ScreenTools.defaultFontPixelWidth * 28 property real _valueFieldWidth: ScreenTools.defaultFontPixelWidth * 10 - property Fact _mapProvider: QGroundControl.settingsManager.flightMapSettings.mapProvider - property Fact _mapType: QGroundControl.settingsManager.flightMapSettings.mapType + property string _mapProvider: QGroundControl.settingsManager.flightMapSettings.mapProvider.value + property string _mapType: QGroundControl.settingsManager.flightMapSettings.mapType.value property Fact _followTarget: QGroundControl.settingsManager.appSettings.followTarget property real _panelWidth: _root.width * _internalWidthRatio property real _margins: ScreenTools.defaultFontPixelWidth @@ -160,30 +160,19 @@ Rectangle { QGCLabel { text: qsTr("Map Provider") width: _labelWidth - visible: _mapProvider.visible + //visible: _mapProvider.visible } - FactComboBox { + QGCComboBox { + id: mapCombo + model: QGroundControl.mapEngineManager.mapList Layout.preferredWidth: _comboFieldWidth - fact: _mapProvider - indexModel: false - visible: _mapProvider.visible - } - - QGCLabel { - text: qsTr("Map Type") - visible: _mapType && _mapType.visible + onActivated: { + _mapProvider = textAt(index) + QGroundControl.settingsManager.flightMapSettings.mapProvider.value=textAt(index) } - FactComboBox { - id: mapTypes - Layout.preferredWidth: _comboFieldWidth - fact: _mapType - indexModel: false - visible: _mapType && _mapType.visible - Connections { - target: QGroundControl.settingsManager.flightMapSettings - onMapTypeChanged: { - mapTypes.model = _mapType.enumStrings - } + Component.onCompleted: { + var index = mapCombo.find(_mapProvider) + mapCombo.currentIndex = index } }