Integrating map provider into existing map widget

This commit is contained in:
Dan Paulat 2023-04-29 01:05:10 -05:00
parent ee99b51003
commit 271756bba9
2 changed files with 40 additions and 40 deletions

View file

@ -5,6 +5,7 @@
#include <scwx/qt/map/alert_layer.hpp>
#include <scwx/qt/map/color_table_layer.hpp>
#include <scwx/qt/map/layer_wrapper.hpp>
#include <scwx/qt/map/map_provider.hpp>
#include <scwx/qt/map/overlay_layer.hpp>
#include <scwx/qt/map/radar_product_layer.hpp>
#include <scwx/qt/map/radar_range_layer.hpp>
@ -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<std::string, std::string> 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<MapStyle, 6> 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<MapContext> context_;
MapWidget* widget_;
MapProvider mapProvider_;
QMapLibreGL::Settings settings_;
std::shared_ptr<QMapLibreGL::Map> map_;
std::list<std::string> 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<config::RadarSite> 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,