diff --git a/scwx-qt/source/scwx/qt/main/main_window.cpp b/scwx-qt/source/scwx/qt/main/main_window.cpp index 4b87d60b..4a54b1a7 100644 --- a/scwx-qt/source/scwx/qt/main/main_window.cpp +++ b/scwx-qt/source/scwx/qt/main/main_window.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -74,10 +75,18 @@ public: elevationButtonsChanged_ {false}, resizeElevationButtons_ {false} { + map::MapProvider mapProvider = + map::GetMapProvider(manager::SettingsManager::general_settings() + .map_provider() + .GetValue()); + const map::MapProviderInfo& mapProviderInfo = + map::GetMapProviderInfo(mapProvider); + std::string appDataPath { QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) .toStdString()}; - std::string cacheDbPath {appDataPath + "/mbgl-cache.db"}; + std::string cacheDbPath {appDataPath + "/" + + mapProviderInfo.cacheDbName_}; if (!std::filesystem::exists(appDataPath)) { @@ -89,12 +98,10 @@ public: } } - std::string mapboxApiKey = manager::SettingsManager::general_settings() - .mapbox_api_key() - .GetValue(); + std::string mapProviderApiKey = map::GetMapProviderApiKey(mapProvider); - settings_.resetToTemplate(QMapLibreGL::Settings::MapboxSettings); - settings_.setApiKey(QString {mapboxApiKey.c_str()}); + settings_.resetToTemplate(mapProviderInfo.settingsTemplate_); + settings_.setApiKey(QString {mapProviderApiKey.c_str()}); settings_.setCacheDatabasePath(QString {cacheDbPath.c_str()}); settings_.setCacheDatabaseMaximumSize(20 * 1024 * 1024); } diff --git a/scwx-qt/source/scwx/qt/map/map_widget.cpp b/scwx-qt/source/scwx/qt/map/map_widget.cpp index 5de29c5e..6a7a06ce 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.cpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -39,20 +40,6 @@ namespace map static const std::string logPrefix_ = "scwx::qt::map::map_widget"; static const auto logger_ = scwx::util::Logger::Create(logPrefix_); -typedef std::pair MapStyle; - -// clang-format off -static const MapStyle streets { "mapbox://styles/mapbox/streets-v11", "Streets"}; -static const MapStyle outdoors { "mapbox://styles/mapbox/outdoors-v11", "Outdoors"}; -static const MapStyle light { "mapbox://styles/mapbox/light-v10", "Light"}; -static const MapStyle dark { "mapbox://styles/mapbox/dark-v10", "Dark" }; -static const MapStyle satellite { "mapbox://styles/mapbox/satellite-v9", "Satellite" }; -static const MapStyle satelliteStreets { "mapbox://styles/mapbox/satellite-streets-v11", "Satellite Streets" }; -// clang-format on - -static const std::array mapboxStyles_ = { - {streets, outdoors, light, dark, satellite, satelliteStreets}}; - class MapWidgetImpl : public QObject { Q_OBJECT @@ -84,9 +71,10 @@ public: prevBearing_ {0.0}, prevPitch_ {0.0} { - SetRadarSite(scwx::qt::manager::SettingsManager::general_settings() - .default_radar_site() - .GetValue()); + auto& generalSettings = + scwx::qt::manager::SettingsManager::general_settings(); + + SetRadarSite(generalSettings.default_radar_site().GetValue()); // Create ImGui Context static size_t currentMapId_ {0u}; @@ -97,6 +85,9 @@ public: // Initialize ImGui Qt backend ImGui_ImplQt_Init(); ImGui_ImplQt_RegisterWidget(widget_); + + // Set Map Provider Details + mapProvider_ = GetMapProvider(generalSettings.map_provider().GetValue()); } ~MapWidgetImpl() @@ -134,6 +125,7 @@ public: std::shared_ptr context_; MapWidget* widget_; + MapProvider mapProvider_; QMapLibreGL::Settings settings_; std::shared_ptr map_; std::list layerList_; @@ -545,11 +537,12 @@ qreal MapWidget::pixelRatio() void MapWidget::changeStyle() { - auto& styles = mapboxStyles_; + const auto& mapProviderInfo = GetMapProviderInfo(p->mapProvider_); + auto& styles = mapProviderInfo.mapStyles_; - p->map_->setStyleUrl(styles[p->currentStyleIndex_].first.c_str()); - setWindowTitle(QString("Mapbox GL: ") + - styles[p->currentStyleIndex_].second.c_str()); + logger_->debug("Updating style: {}", styles[p->currentStyleIndex_].name_); + + p->map_->setStyleUrl(styles[p->currentStyleIndex_].url_.c_str()); if (++p->currentStyleIndex_ == styles.size()) { @@ -578,13 +571,21 @@ void MapWidget::AddLayers() std::shared_ptr radarSite = p->radarProductManager_->radar_site(); + const auto& mapStyle = + GetMapProviderInfo(p->mapProvider_).mapStyles_[p->currentStyleIndex_]; + std::string before = "ferry"; for (const QString& layer : p->map_->layerIds()) { - // Draw below tunnels, ferries and roads - if (layer.startsWith("tunnel") || layer.startsWith("ferry") || - layer.startsWith("road")) + // Draw below layers defined in map style + auto it = std::find_if( + mapStyle.drawBelow_.cbegin(), + mapStyle.drawBelow_.cend(), + [&layer](const std::string& styleLayer) -> bool + { return layer.startsWith(QString::fromStdString(styleLayer)); }); + + if (it != mapStyle.drawBelow_.cend()) { before = layer.toStdString(); break; @@ -740,16 +741,8 @@ void MapWidget::initializeGL() p->prevBearing_, p->prevPitch_); - QString styleUrl = qgetenv("MAPBOX_STYLE_URL"); - if (styleUrl.isEmpty()) - { - changeStyle(); - } - else - { - p->map_->setStyleUrl(styleUrl); - setWindowTitle(QString("Mapbox GL: ") + styleUrl); - } + // Update style + changeStyle(); connect(p->map_.get(), &QMapLibreGL::Map::mapChanged,