diff --git a/scwx-qt/source/scwx/qt/main/main_window.cpp b/scwx-qt/source/scwx/qt/main/main_window.cpp index d064488b..85cff2fe 100644 --- a/scwx-qt/source/scwx/qt/main/main_window.cpp +++ b/scwx-qt/source/scwx/qt/main/main_window.cpp @@ -120,8 +120,11 @@ public: std::string mapProviderApiKey = map::GetMapProviderApiKey(mapProvider_); - settings_.setProviderTemplate(mapProviderInfo.providerTemplate_); - settings_.setApiKey(QString {mapProviderApiKey.c_str()}); + if (mapProvider_ == map::MapProvider::Mapbox) + { + settings_.setProviderTemplate(mapProviderInfo.providerTemplate_); + 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_provider.cpp b/scwx-qt/source/scwx/qt/map/map_provider.cpp index 8dbdc6ba..14ffb2b5 100644 --- a/scwx-qt/source/scwx/qt/map/map_provider.cpp +++ b/scwx-qt/source/scwx/qt/map/map_provider.cpp @@ -77,49 +77,52 @@ static const std::unordered_map mapProviderInfo_ { QMapLibre::Settings::ProviderTemplate::MapTilerProvider}, .mapStyles_ { {.name_ {"Satellite"}, - .url_ {"maptiler://maps/hybrid"}, + .url_ {"https://api.maptiler.com/maps/hybrid/style.json"}, .drawBelow_ {"tunnel"}}, {.name_ {"Streets"}, - .url_ {"maptiler://maps/streets-v2"}, + .url_ {"https://api.maptiler.com/maps/streets-v2/style.json"}, .drawBelow_ {"aeroway"}}, {.name_ {"Streets Dark"}, - .url_ {"maptiler://maps/streets-v2-dark"}, + .url_ {"https://api.maptiler.com/maps/streets-v2-dark/style.json"}, .drawBelow_ {"aeroway"}}, {.name_ {"Basic"}, - .url_ {"maptiler://maps/basic-v2"}, + .url_ {"https://api.maptiler.com/maps/basic-v2/style.json"}, .drawBelow_ {"railway_transit_tunnel", "Transit tunnel"}}, {.name_ {"Bright"}, - .url_ {"maptiler://maps/bright-v2"}, + .url_ {"https://api.maptiler.com/maps/bright-v2/style.json"}, .drawBelow_ {"ferry"}}, {.name_ {"Dataviz"}, - .url_ {"maptiler://maps/dataviz"}, + .url_ {"https://api.maptiler.com/maps/dataviz/style.json"}, .drawBelow_ {"aeroway"}}, {.name_ {"Dataviz Dark"}, - .url_ {"maptiler://maps/dataviz-dark"}, + .url_ {"https://api.maptiler.com/maps/dataviz-dark/style.json"}, .drawBelow_ {"aeroway"}}, {.name_ {"Outdoor"}, - .url_ {"maptiler://maps/outdoor-v2"}, + .url_ {"https://api.maptiler.com/maps/outdoor-v2/style.json"}, .drawBelow_ {"aeroway_runway", "Aeroway"}}, {.name_ {"Swisstopo"}, - .url_ {"maptiler://maps/ch-swisstopo-lbm"}, + .url_ {"https://api.maptiler.com/maps/ch-swisstopo-lbm/style.json"}, .drawBelow_ {"pattern_landcover_vineyard", "Vineyard pattern"}}, {.name_ {"Swisstopo Dark"}, - .url_ {"maptiler://maps/ch-swisstopo-lbm-dark"}, + .url_ { + "https://api.maptiler.com/maps/ch-swisstopo-lbm-dark/style.json"}, .drawBelow_ {"pattern_landcover_vineyard", "Vineyard pattern"}}, {.name_ {"Swisstopo Grey"}, - .url_ {"maptiler://maps/ch-swisstopo-lbm-grey"}, + .url_ { + "https://api.maptiler.com/maps/ch-swisstopo-lbm-grey/style.json"}, .drawBelow_ {"pattern_landcover_vineyard", "Vineyard pattern"}}, {.name_ {"Swisstopo Vivid"}, - .url_ {"maptiler://maps/ch-swisstopo-lbm-vivid"}, + .url_ {"https://api.maptiler.com/maps/ch-swisstopo-lbm-vivid/" + "style.json"}, .drawBelow_ {"pattern_landcover_vineyard", "Vineyard pattern"}}, {.name_ {"Topo"}, - .url_ {"maptiler://maps/topo-v2"}, + .url_ {"https://api.maptiler.com/maps/topo-v2/style.json"}, .drawBelow_ {"aeroway_runway", "Runway"}}, {.name_ {"Topo Dark"}, - .url_ {"maptiler://maps/topo-v2-dark"}, + .url_ {"https://api.maptiler.com/maps/topo-v2-dark/style.json"}, .drawBelow_ {"aeroway_runway", "Runway"}}, {.name_ {"Winter"}, - .url_ {"maptiler://maps/winter-v2"}, + .url_ {"https://api.maptiler.com/maps/winter-v2/style.json"}, .drawBelow_ {"aeroway_runway", "Aeroway"}}}}}, {MapProvider::Unknown, MapProviderInfo {}}}; diff --git a/scwx-qt/source/scwx/qt/map/map_widget.cpp b/scwx-qt/source/scwx/qt/map/map_widget.cpp index 11367bbe..3412e7c0 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.cpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.cpp @@ -737,7 +737,8 @@ void MapWidget::SetMapStyle(const std::string& styleName) logger_->debug("Updating style: {}", styles[i].name_); - p->map_->setStyleUrl(styles[i].url_.c_str()); + util::maplibre::SetMapStyleUrl( + p->map_, p->mapProvider_, styles[i].url_); if (++p->currentStyleIndex_ == styles.size()) { @@ -763,7 +764,8 @@ void MapWidget::changeStyle() logger_->debug("Updating style: {}", styles[p->currentStyleIndex_].name_); - p->map_->setStyleUrl(styles[p->currentStyleIndex_].url_.c_str()); + util::maplibre::SetMapStyleUrl( + p->map_, p->mapProvider_, styles[p->currentStyleIndex_].url_); if (++p->currentStyleIndex_ == styles.size()) { diff --git a/scwx-qt/source/scwx/qt/util/maplibre.cpp b/scwx-qt/source/scwx/qt/util/maplibre.cpp index 7a7b9c00..0adff1ed 100644 --- a/scwx-qt/source/scwx/qt/util/maplibre.cpp +++ b/scwx-qt/source/scwx/qt/util/maplibre.cpp @@ -88,6 +88,21 @@ glm::vec2 LatLongToScreenCoordinate(const QMapLibre::Coordinate& coordinate) return screen; } +void SetMapStyleUrl(const std::shared_ptr& map, + map::MapProvider mapProvider, + const std::string& url) +{ + QString qUrl = QString::fromStdString(url); + + if (mapProvider == map::MapProvider::MapTiler) + { + qUrl.append("?key="); + qUrl.append(map::GetMapProviderApiKey(mapProvider)); + } + + map->setStyleUrl(qUrl); +} + } // namespace maplibre } // namespace util } // namespace qt diff --git a/scwx-qt/source/scwx/qt/util/maplibre.hpp b/scwx-qt/source/scwx/qt/util/maplibre.hpp index 62fb9cb2..619ba2ca 100644 --- a/scwx-qt/source/scwx/qt/util/maplibre.hpp +++ b/scwx-qt/source/scwx/qt/util/maplibre.hpp @@ -1,5 +1,8 @@ #pragma once +#include + +#include #include #include #include @@ -31,6 +34,10 @@ bool IsPointInPolygon(const std::vector& vertices, glm::vec2 LatLongToScreenCoordinate(const QMapLibre::Coordinate& coordinate); +void SetMapStyleUrl(const std::shared_ptr& map, + map::MapProvider mapProvider, + const std::string& url); + } // namespace maplibre } // namespace util } // namespace qt