diff --git a/scwx-qt/source/scwx/qt/map/alert_layer.cpp b/scwx-qt/source/scwx/qt/map/alert_layer.cpp index 044cfb00..82a7bb3c 100644 --- a/scwx-qt/source/scwx/qt/map/alert_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/alert_layer.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -132,33 +133,31 @@ public: }; AlertLayer::AlertLayer(std::shared_ptr context) : - DrawLayer(context), p(std::make_unique(context)) + p(std::make_unique(context)) { } AlertLayer::~AlertLayer() = default; -void AlertLayer::Initialize() +void AlertLayer::AddLayers(awips::Phenomenon phenomenon, + const std::string& before) { - logger_->debug("Initialize()"); + logger_->debug("AddLayers(): {}", awips::GetPhenomenonCode(phenomenon)); - DrawLayer::Initialize(); -} + auto map = p->context_->map().lock(); + if (map == nullptr) + { + return; + } -void AlertLayer::Render(const QMapLibreGL::CustomLayerRenderParameters& params) -{ - gl::OpenGLFunctions& gl = context()->gl(); + const QString beforeLayer {QString::fromStdString(before)}; - DrawLayer::Render(params); - - SCWX_GL_CHECK_ERROR(); -} - -void AlertLayer::Deinitialize() -{ - logger_->debug("Deinitialize()"); - - DrawLayer::Deinitialize(); + // Add/update GeoJSON sources and create layers + for (bool alertActive : {false, true}) + { + p->UpdateSource(phenomenon, alertActive); + AddAlertLayer(map, phenomenon, alertActive, beforeLayer); + } } void AlertLayer::AddLayers(const std::string& before) @@ -396,13 +395,16 @@ static void AddAlertLayer(std::shared_ptr map, settings::PaletteSettings& paletteSettings = settings::PaletteSettings::Instance(); + QString layerPrefix = QString::fromStdString( + types::GetLayerName(types::LayerType::Alert, phenomenon)); + QString sourceId = GetSourceId(phenomenon, alertActive); QString idSuffix = GetSuffix(phenomenon, alertActive); auto outlineColor = util::color::ToRgba8PixelT( paletteSettings.alert_color(phenomenon, alertActive).GetValue()); - QString bgLayerId = QString("alertPolygonLayerBg-%1").arg(idSuffix); - QString fgLayerId = QString("alertPolygonLayerFg-%1").arg(idSuffix); + QString bgLayerId = QString("%1::bg-%2").arg(layerPrefix).arg(idSuffix); + QString fgLayerId = QString("%1::fg-%2").arg(layerPrefix).arg(idSuffix); if (map->layerExists(bgLayerId)) { diff --git a/scwx-qt/source/scwx/qt/map/alert_layer.hpp b/scwx-qt/source/scwx/qt/map/alert_layer.hpp index 8b081c64..e728118a 100644 --- a/scwx-qt/source/scwx/qt/map/alert_layer.hpp +++ b/scwx-qt/source/scwx/qt/map/alert_layer.hpp @@ -1,6 +1,9 @@ #pragma once -#include +#include +#include + +#include namespace scwx { @@ -11,16 +14,13 @@ namespace map class AlertLayerImpl; -class AlertLayer : public DrawLayer +class AlertLayer { public: explicit AlertLayer(std::shared_ptr context); ~AlertLayer(); - void Initialize() override final; - void Render(const QMapLibreGL::CustomLayerRenderParameters&) override final; - void Deinitialize() override final; - + void AddLayers(awips::Phenomenon phenomenon, const std::string& before = {}); void AddLayers(const std::string& before = {}); private: diff --git a/scwx-qt/source/scwx/qt/map/radar_range_layer.cpp b/scwx-qt/source/scwx/qt/map/radar_range_layer.cpp index ea4fa55b..a4738404 100644 --- a/scwx-qt/source/scwx/qt/map/radar_range_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/radar_range_layer.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -22,11 +23,14 @@ void RadarRangeLayer::Add(std::shared_ptr map, QMapLibreGL::Coordinate center, const QString& before) { + static const QString layerId = QString::fromStdString(types::GetLayerName( + types::LayerType::Data, types::DataLayer::RadarRange)); + logger_->debug("Add()"); - if (map->layerExists("rangeCircleLayer")) + if (map->layerExists(layerId)) { - map->removeLayer("rangeCircleLayer"); + map->removeLayer(layerId); } if (map->sourceExists("rangeCircleSource")) { @@ -39,12 +43,10 @@ void RadarRangeLayer::Add(std::shared_ptr map, map->addSource( "rangeCircleSource", {{"type", "geojson"}, {"data", QVariant::fromValue(*rangeCircle)}}); - map->addLayer({{"id", "rangeCircleLayer"}, - {"type", "line"}, - {"source", "rangeCircleSource"}}, - before); - map->setPaintProperty( - "rangeCircleLayer", "line-color", "rgba(128, 128, 128, 128)"); + map->addLayer( + {{"id", layerId}, {"type", "line"}, {"source", "rangeCircleSource"}}, + before); + map->setPaintProperty(layerId, "line-color", "rgba(128, 128, 128, 128)"); } void RadarRangeLayer::Update(std::shared_ptr map, diff --git a/scwx-qt/source/scwx/qt/model/layer_model.cpp b/scwx-qt/source/scwx/qt/model/layer_model.cpp index 6cace5a9..f52475e1 100644 --- a/scwx-qt/source/scwx/qt/model/layer_model.cpp +++ b/scwx-qt/source/scwx/qt/model/layer_model.cpp @@ -601,35 +601,8 @@ QVariant LayerModel::data(const QModelIndex& index, int role) const } else { - if (std::holds_alternative(layer.description_)) - { - return QString::fromStdString( - std::get(layer.description_)); - } - else if (std::holds_alternative( - layer.description_)) - { - return QString::fromStdString(types::GetDataLayerName( - std::get(layer.description_))); - } - else if (std::holds_alternative( - layer.description_)) - { - return QString::fromStdString(types::GetInformationLayerName( - std::get(layer.description_))); - } - else if (std::holds_alternative( - layer.description_)) - { - return QString::fromStdString(types::GetMapLayerName( - std::get(layer.description_))); - } - else if (std::holds_alternative( - layer.description_)) - { - return QString::fromStdString(awips::GetPhenomenonText( - std::get(layer.description_))); - } + return QString::fromStdString( + types::GetLayerDescriptionName(layer.description_)); } } break; diff --git a/scwx-qt/source/scwx/qt/types/layer_types.cpp b/scwx-qt/source/scwx/qt/types/layer_types.cpp index c6d042d8..0f7e1db8 100644 --- a/scwx-qt/source/scwx/qt/types/layer_types.cpp +++ b/scwx-qt/source/scwx/qt/types/layer_types.cpp @@ -4,6 +4,7 @@ #include #include +#include namespace scwx { @@ -131,6 +132,46 @@ std::string GetMapLayerName(MapLayer layer) return mapLayerName_.at(layer); } +std::string GetLayerDescriptionName(LayerDescription description) +{ + if (std::holds_alternative(description)) + { + return std::get(description); + } + else if (std::holds_alternative(description)) + { + return GetDataLayerName(std::get(description)); + } + else if (std::holds_alternative(description)) + { + return GetInformationLayerName(std::get(description)); + } + else if (std::holds_alternative(description)) + { + return GetMapLayerName(std::get(description)); + } + else if (std::holds_alternative(description)) + { + return awips::GetPhenomenonText(std::get(description)); + } + else if (std::holds_alternative(description)) + { + return ""; + } + else + { + return "?"; + } +} + +std::string GetLayerName(types::LayerType type, + types::LayerDescription description) +{ + return fmt::format("scwx.{}.{}", + types::GetLayerTypeName(type), + types::GetLayerDescriptionName(description)); +} + void tag_invoke(boost::json::value_from_tag, boost::json::value& jv, const LayerInfo& record) diff --git a/scwx-qt/source/scwx/qt/types/layer_types.hpp b/scwx-qt/source/scwx/qt/types/layer_types.hpp index d7c79a0a..6a00d03b 100644 --- a/scwx-qt/source/scwx/qt/types/layer_types.hpp +++ b/scwx-qt/source/scwx/qt/types/layer_types.hpp @@ -82,6 +82,10 @@ std::string GetInformationLayerName(InformationLayer layer); MapLayer GetMapLayer(const std::string& name); std::string GetMapLayerName(MapLayer layer); +std::string GetLayerDescriptionName(LayerDescription description); + +std::string GetLayerName(LayerType type, LayerDescription description); + void tag_invoke(boost::json::value_from_tag, boost::json::value& jv, const LayerInfo& record);