mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 16:10:04 +00:00
Common layer naming
This commit is contained in:
parent
a5cee797d9
commit
3392a9a402
6 changed files with 85 additions and 63 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
#include <scwx/qt/map/alert_layer.hpp>
|
#include <scwx/qt/map/alert_layer.hpp>
|
||||||
#include <scwx/qt/manager/text_event_manager.hpp>
|
#include <scwx/qt/manager/text_event_manager.hpp>
|
||||||
#include <scwx/qt/settings/palette_settings.hpp>
|
#include <scwx/qt/settings/palette_settings.hpp>
|
||||||
|
#include <scwx/qt/types/layer_types.hpp>
|
||||||
#include <scwx/qt/util/color.hpp>
|
#include <scwx/qt/util/color.hpp>
|
||||||
#include <scwx/util/logger.hpp>
|
#include <scwx/util/logger.hpp>
|
||||||
#include <scwx/util/threads.hpp>
|
#include <scwx/util/threads.hpp>
|
||||||
|
|
@ -132,33 +133,31 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
AlertLayer::AlertLayer(std::shared_ptr<MapContext> context) :
|
AlertLayer::AlertLayer(std::shared_ptr<MapContext> context) :
|
||||||
DrawLayer(context), p(std::make_unique<AlertLayerImpl>(context))
|
p(std::make_unique<AlertLayerImpl>(context))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
AlertLayer::~AlertLayer() = default;
|
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)
|
const QString beforeLayer {QString::fromStdString(before)};
|
||||||
{
|
|
||||||
gl::OpenGLFunctions& gl = context()->gl();
|
|
||||||
|
|
||||||
DrawLayer::Render(params);
|
// Add/update GeoJSON sources and create layers
|
||||||
|
for (bool alertActive : {false, true})
|
||||||
SCWX_GL_CHECK_ERROR();
|
{
|
||||||
}
|
p->UpdateSource(phenomenon, alertActive);
|
||||||
|
AddAlertLayer(map, phenomenon, alertActive, beforeLayer);
|
||||||
void AlertLayer::Deinitialize()
|
}
|
||||||
{
|
|
||||||
logger_->debug("Deinitialize()");
|
|
||||||
|
|
||||||
DrawLayer::Deinitialize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AlertLayer::AddLayers(const std::string& before)
|
void AlertLayer::AddLayers(const std::string& before)
|
||||||
|
|
@ -396,13 +395,16 @@ static void AddAlertLayer(std::shared_ptr<QMapLibreGL::Map> map,
|
||||||
settings::PaletteSettings& paletteSettings =
|
settings::PaletteSettings& paletteSettings =
|
||||||
settings::PaletteSettings::Instance();
|
settings::PaletteSettings::Instance();
|
||||||
|
|
||||||
|
QString layerPrefix = QString::fromStdString(
|
||||||
|
types::GetLayerName(types::LayerType::Alert, phenomenon));
|
||||||
|
|
||||||
QString sourceId = GetSourceId(phenomenon, alertActive);
|
QString sourceId = GetSourceId(phenomenon, alertActive);
|
||||||
QString idSuffix = GetSuffix(phenomenon, alertActive);
|
QString idSuffix = GetSuffix(phenomenon, alertActive);
|
||||||
auto outlineColor = util::color::ToRgba8PixelT(
|
auto outlineColor = util::color::ToRgba8PixelT(
|
||||||
paletteSettings.alert_color(phenomenon, alertActive).GetValue());
|
paletteSettings.alert_color(phenomenon, alertActive).GetValue());
|
||||||
|
|
||||||
QString bgLayerId = QString("alertPolygonLayerBg-%1").arg(idSuffix);
|
QString bgLayerId = QString("%1::bg-%2").arg(layerPrefix).arg(idSuffix);
|
||||||
QString fgLayerId = QString("alertPolygonLayerFg-%1").arg(idSuffix);
|
QString fgLayerId = QString("%1::fg-%2").arg(layerPrefix).arg(idSuffix);
|
||||||
|
|
||||||
if (map->layerExists(bgLayerId))
|
if (map->layerExists(bgLayerId))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <scwx/qt/map/draw_layer.hpp>
|
#include <scwx/awips/phenomenon.hpp>
|
||||||
|
#include <scwx/qt/map/map_context.hpp>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
{
|
{
|
||||||
|
|
@ -11,16 +14,13 @@ namespace map
|
||||||
|
|
||||||
class AlertLayerImpl;
|
class AlertLayerImpl;
|
||||||
|
|
||||||
class AlertLayer : public DrawLayer
|
class AlertLayer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit AlertLayer(std::shared_ptr<MapContext> context);
|
explicit AlertLayer(std::shared_ptr<MapContext> context);
|
||||||
~AlertLayer();
|
~AlertLayer();
|
||||||
|
|
||||||
void Initialize() override final;
|
void AddLayers(awips::Phenomenon phenomenon, const std::string& before = {});
|
||||||
void Render(const QMapLibreGL::CustomLayerRenderParameters&) override final;
|
|
||||||
void Deinitialize() override final;
|
|
||||||
|
|
||||||
void AddLayers(const std::string& before = {});
|
void AddLayers(const std::string& before = {});
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include <scwx/qt/map/radar_range_layer.hpp>
|
#include <scwx/qt/map/radar_range_layer.hpp>
|
||||||
|
#include <scwx/qt/types/layer_types.hpp>
|
||||||
#include <scwx/qt/util/geographic_lib.hpp>
|
#include <scwx/qt/util/geographic_lib.hpp>
|
||||||
#include <scwx/util/logger.hpp>
|
#include <scwx/util/logger.hpp>
|
||||||
|
|
||||||
|
|
@ -22,11 +23,14 @@ void RadarRangeLayer::Add(std::shared_ptr<QMapLibreGL::Map> map,
|
||||||
QMapLibreGL::Coordinate center,
|
QMapLibreGL::Coordinate center,
|
||||||
const QString& before)
|
const QString& before)
|
||||||
{
|
{
|
||||||
|
static const QString layerId = QString::fromStdString(types::GetLayerName(
|
||||||
|
types::LayerType::Data, types::DataLayer::RadarRange));
|
||||||
|
|
||||||
logger_->debug("Add()");
|
logger_->debug("Add()");
|
||||||
|
|
||||||
if (map->layerExists("rangeCircleLayer"))
|
if (map->layerExists(layerId))
|
||||||
{
|
{
|
||||||
map->removeLayer("rangeCircleLayer");
|
map->removeLayer(layerId);
|
||||||
}
|
}
|
||||||
if (map->sourceExists("rangeCircleSource"))
|
if (map->sourceExists("rangeCircleSource"))
|
||||||
{
|
{
|
||||||
|
|
@ -39,12 +43,10 @@ void RadarRangeLayer::Add(std::shared_ptr<QMapLibreGL::Map> map,
|
||||||
map->addSource(
|
map->addSource(
|
||||||
"rangeCircleSource",
|
"rangeCircleSource",
|
||||||
{{"type", "geojson"}, {"data", QVariant::fromValue(*rangeCircle)}});
|
{{"type", "geojson"}, {"data", QVariant::fromValue(*rangeCircle)}});
|
||||||
map->addLayer({{"id", "rangeCircleLayer"},
|
map->addLayer(
|
||||||
{"type", "line"},
|
{{"id", layerId}, {"type", "line"}, {"source", "rangeCircleSource"}},
|
||||||
{"source", "rangeCircleSource"}},
|
before);
|
||||||
before);
|
map->setPaintProperty(layerId, "line-color", "rgba(128, 128, 128, 128)");
|
||||||
map->setPaintProperty(
|
|
||||||
"rangeCircleLayer", "line-color", "rgba(128, 128, 128, 128)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadarRangeLayer::Update(std::shared_ptr<QMapLibreGL::Map> map,
|
void RadarRangeLayer::Update(std::shared_ptr<QMapLibreGL::Map> map,
|
||||||
|
|
|
||||||
|
|
@ -601,35 +601,8 @@ QVariant LayerModel::data(const QModelIndex& index, int role) const
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (std::holds_alternative<std::string>(layer.description_))
|
return QString::fromStdString(
|
||||||
{
|
types::GetLayerDescriptionName(layer.description_));
|
||||||
return QString::fromStdString(
|
|
||||||
std::get<std::string>(layer.description_));
|
|
||||||
}
|
|
||||||
else if (std::holds_alternative<types::DataLayer>(
|
|
||||||
layer.description_))
|
|
||||||
{
|
|
||||||
return QString::fromStdString(types::GetDataLayerName(
|
|
||||||
std::get<types::DataLayer>(layer.description_)));
|
|
||||||
}
|
|
||||||
else if (std::holds_alternative<types::InformationLayer>(
|
|
||||||
layer.description_))
|
|
||||||
{
|
|
||||||
return QString::fromStdString(types::GetInformationLayerName(
|
|
||||||
std::get<types::InformationLayer>(layer.description_)));
|
|
||||||
}
|
|
||||||
else if (std::holds_alternative<types::MapLayer>(
|
|
||||||
layer.description_))
|
|
||||||
{
|
|
||||||
return QString::fromStdString(types::GetMapLayerName(
|
|
||||||
std::get<types::MapLayer>(layer.description_)));
|
|
||||||
}
|
|
||||||
else if (std::holds_alternative<awips::Phenomenon>(
|
|
||||||
layer.description_))
|
|
||||||
{
|
|
||||||
return QString::fromStdString(awips::GetPhenomenonText(
|
|
||||||
std::get<awips::Phenomenon>(layer.description_)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/json.hpp>
|
#include <boost/json.hpp>
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
{
|
{
|
||||||
|
|
@ -131,6 +132,46 @@ std::string GetMapLayerName(MapLayer layer)
|
||||||
return mapLayerName_.at(layer);
|
return mapLayerName_.at(layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string GetLayerDescriptionName(LayerDescription description)
|
||||||
|
{
|
||||||
|
if (std::holds_alternative<std::string>(description))
|
||||||
|
{
|
||||||
|
return std::get<std::string>(description);
|
||||||
|
}
|
||||||
|
else if (std::holds_alternative<DataLayer>(description))
|
||||||
|
{
|
||||||
|
return GetDataLayerName(std::get<DataLayer>(description));
|
||||||
|
}
|
||||||
|
else if (std::holds_alternative<InformationLayer>(description))
|
||||||
|
{
|
||||||
|
return GetInformationLayerName(std::get<InformationLayer>(description));
|
||||||
|
}
|
||||||
|
else if (std::holds_alternative<MapLayer>(description))
|
||||||
|
{
|
||||||
|
return GetMapLayerName(std::get<MapLayer>(description));
|
||||||
|
}
|
||||||
|
else if (std::holds_alternative<awips::Phenomenon>(description))
|
||||||
|
{
|
||||||
|
return awips::GetPhenomenonText(std::get<awips::Phenomenon>(description));
|
||||||
|
}
|
||||||
|
else if (std::holds_alternative<std::monostate>(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,
|
void tag_invoke(boost::json::value_from_tag,
|
||||||
boost::json::value& jv,
|
boost::json::value& jv,
|
||||||
const LayerInfo& record)
|
const LayerInfo& record)
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,10 @@ std::string GetInformationLayerName(InformationLayer layer);
|
||||||
MapLayer GetMapLayer(const std::string& name);
|
MapLayer GetMapLayer(const std::string& name);
|
||||||
std::string GetMapLayerName(MapLayer layer);
|
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,
|
void tag_invoke(boost::json::value_from_tag,
|
||||||
boost::json::value& jv,
|
boost::json::value& jv,
|
||||||
const LayerInfo& record);
|
const LayerInfo& record);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue