With MapTiler, use https for style URLs

- Eliminates issues with rewriting maptiler:// to incorrect URLs
This commit is contained in:
Dan Paulat 2024-03-02 00:10:21 -06:00
parent a74fb22c88
commit e0c1138250
5 changed files with 49 additions and 19 deletions

View file

@ -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);

View file

@ -77,49 +77,52 @@ static const std::unordered_map<MapProvider, MapProviderInfo> 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 {}}};

View file

@ -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())
{

View file

@ -88,6 +88,21 @@ glm::vec2 LatLongToScreenCoordinate(const QMapLibre::Coordinate& coordinate)
return screen;
}
void SetMapStyleUrl(const std::shared_ptr<QMapLibre::Map>& 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

View file

@ -1,5 +1,8 @@
#pragma once
#include <scwx/qt/map/map_provider.hpp>
#include <QMapLibre/Map>
#include <QMapLibre/Types>
#include <glm/gtc/type_ptr.hpp>
#include <units/length.h>
@ -31,6 +34,10 @@ bool IsPointInPolygon(const std::vector<glm::vec2>& vertices,
glm::vec2 LatLongToScreenCoordinate(const QMapLibre::Coordinate& coordinate);
void SetMapStyleUrl(const std::shared_ptr<QMapLibre::Map>& map,
map::MapProvider mapProvider,
const std::string& url);
} // namespace maplibre
} // namespace util
} // namespace qt