Map provider test fixes

This commit is contained in:
Dan Paulat 2024-03-06 23:54:27 -06:00
parent 7cfb55a4de
commit d905abd3e7
2 changed files with 22 additions and 8 deletions

View file

@ -51,7 +51,7 @@ static const std::unordered_map<MapProvider, MapProviderInfo> mapProviderInfo_ {
{.name_ {"Bubble"}, {.name_ {"Bubble"},
.url_ { .url_ {
"mapbox://styles/mapbox-map-design/cl4wxue5j000c14r17uqrjpqb"}, "mapbox://styles/mapbox-map-design/cl4wxue5j000c14r17uqrjpqb"},
.drawBelow_ {mapboxDrawBelow_}}, .drawBelow_ {"com\\.mapbox\\.annotations\\.points"}},
{.name_ {"Cali Terrain"}, {.name_ {"Cali Terrain"},
.url_ {"mapbox://styles/mapbox/cjerxnqt3cgvp2rmyuxbeqme7"}, .url_ {"mapbox://styles/mapbox/cjerxnqt3cgvp2rmyuxbeqme7"},
.drawBelow_ {"major roads casing"}}, .drawBelow_ {"major roads casing"}},

View file

@ -1,4 +1,6 @@
#include <scwx/qt/map/map_provider.hpp> #include <scwx/qt/map/map_provider.hpp>
#include <scwx/qt/settings/general_settings.hpp>
#include <scwx/qt/util/maplibre.hpp>
#include <scwx/util/environment.hpp> #include <scwx/util/environment.hpp>
#include <scwx/util/logger.hpp> #include <scwx/util/logger.hpp>
@ -47,15 +49,27 @@ TEST_P(ByMapProviderTest, MapProviderLayers)
// Configure QMapLibre // Configure QMapLibre
QMapLibre::Settings mapSettings {}; QMapLibre::Settings mapSettings {};
mapSettings.setProviderTemplate(mapProviderInfo.providerTemplate_); if (mapProvider == map::MapProvider::Mapbox)
mapSettings.setApiKey(QString::fromStdString(apiKey)); {
mapSettings.setProviderTemplate(mapProviderInfo.providerTemplate_);
mapSettings.setApiKey(QString::fromStdString(apiKey));
}
else if (mapProvider == map::MapProvider::MapTiler)
{
settings::GeneralSettings::Instance().maptiler_api_key().SetValue(apiKey);
}
QMapLibre::Map map(nullptr, mapSettings, QSize(1, 1)); std::shared_ptr<map::MapContext> mapContext =
std::make_shared<map::MapContext>();
std::shared_ptr<QMapLibre::Map> map =
std::make_shared<QMapLibre::Map>(nullptr, mapSettings, QSize(1, 1));
mapContext->set_map(map);
mapContext->set_map_provider(mapProvider);
application.processEvents(); application.processEvents();
// Connect style load completion signal // Connect style load completion signal
QObject::connect( QObject::connect(
&map, map.get(),
&QMapLibre::Map::mapChanged, &QMapLibre::Map::mapChanged,
[&](QMapLibre::Map::MapChange mapChange) [&](QMapLibre::Map::MapChange mapChange)
{ {
@ -88,7 +102,7 @@ TEST_P(ByMapProviderTest, MapProviderLayers)
// Load style // Load style
timeout = false; timeout = false;
map.setStyleUrl(QString::fromStdString(mapStyle.url_)); util::maplibre::SetMapStyleUrl(mapContext, mapStyle.url_);
timeoutTimer.start(5000ms); timeoutTimer.start(5000ms);
application.exec(); application.exec();
timeoutTimer.stop(); timeoutTimer.stop();
@ -97,12 +111,12 @@ TEST_P(ByMapProviderTest, MapProviderLayers)
if (!timeout) if (!timeout)
{ {
// Print layer names for debug // Print layer names for debug
std::string layerIdsString = map.layerIds().join(", ").toStdString(); std::string layerIdsString = map->layerIds().join(", ").toStdString();
logger_->debug("{} Layers: [{}]", mapStyle.name_, layerIdsString); logger_->debug("{} Layers: [{}]", mapStyle.name_, layerIdsString);
// Search layer list // Search layer list
bool foundMatch = false; bool foundMatch = false;
for (const QString& qlayer : map.layerIds()) for (const QString& qlayer : map->layerIds())
{ {
const std::string layer = qlayer.toStdString(); const std::string layer = qlayer.toStdString();