Draw overlay layer regardless of radar product view, general layer organization

This commit is contained in:
Dan Paulat 2022-03-01 22:50:21 -06:00
parent 410eb85d3f
commit b9c4b9e9c7
2 changed files with 48 additions and 46 deletions

View file

@ -54,6 +54,7 @@ public:
widget_ {widget}, widget_ {widget},
settings_(settings), settings_(settings),
map_(), map_(),
layerList_ {},
radarProductManager_ {manager::RadarProductManager::Instance("KLSX")}, radarProductManager_ {manager::RadarProductManager::Instance("KLSX")},
radarProductLayer_ {nullptr}, radarProductLayer_ {nullptr},
overlayLayer_ {nullptr}, overlayLayer_ {nullptr},
@ -70,6 +71,9 @@ public:
} }
~MapWidgetImpl() = default; ~MapWidgetImpl() = default;
void AddLayer(const std::string& id,
std::shared_ptr<GenericLayer> layer,
const std::string& before = {});
bool UpdateStoredMapParameters(); bool UpdateStoredMapParameters();
std::shared_ptr<MapContext> context_; std::shared_ptr<MapContext> context_;
@ -77,6 +81,7 @@ public:
MapWidget* widget_; MapWidget* widget_;
QMapboxGLSettings settings_; QMapboxGLSettings settings_;
std::shared_ptr<QMapboxGL> map_; std::shared_ptr<QMapboxGL> map_;
std::list<std::string> layerList_;
std::shared_ptr<manager::RadarProductManager> radarProductManager_; std::shared_ptr<manager::RadarProductManager> radarProductManager_;
@ -276,41 +281,22 @@ void MapWidget::changeStyle()
void MapWidget::AddLayers() void MapWidget::AddLayers()
{ {
if (p->context_->radarProductView_ == nullptr) // Clear custom layers
for (const std::string& id : p->layerList_)
{ {
return; p->map_->removeLayer(id.c_str());
} }
p->layerList_.clear();
// TODO: Improve this if (p->context_->radarProductView_ != nullptr)
if (p->map_->layerExists("radar"))
{ {
p->map_->removeLayer("radar");
}
if (p->map_->layerExists("overlay"))
{
p->map_->removeLayer("overlay");
}
if (p->map_->layerExists("colorTable"))
{
p->map_->removeLayer("colorTable");
}
p->radarProductLayer_ = std::make_shared<RadarProductLayer>(p->context_); p->radarProductLayer_ = std::make_shared<RadarProductLayer>(p->context_);
p->overlayLayer_ = std::make_shared<OverlayLayer>(p->context_);
p->colorTableLayer_ = std::make_shared<ColorTableLayer>(p->context_); p->colorTableLayer_ = std::make_shared<ColorTableLayer>(p->context_);
// QMapboxGL::addCustomLayer will take ownership of the std::unique_ptr
std::unique_ptr<QMapbox::CustomLayerHostInterface> pHost =
std::make_unique<LayerWrapper>(p->radarProductLayer_);
std::unique_ptr<QMapbox::CustomLayerHostInterface> pOverlayHost =
std::make_unique<LayerWrapper>(p->overlayLayer_);
std::unique_ptr<QMapbox::CustomLayerHostInterface> pColorTableHost =
std::make_unique<LayerWrapper>(p->colorTableLayer_);
std::shared_ptr<config::RadarSite> radarSite = std::shared_ptr<config::RadarSite> radarSite =
p->radarProductManager_->radar_site(); p->radarProductManager_->radar_site();
QString before = "ferry"; std::string before = "ferry";
for (const QString& layer : p->map_->layerIds()) for (const QString& layer : p->map_->layerIds())
{ {
@ -318,17 +304,33 @@ void MapWidget::AddLayers()
if (layer.startsWith("tunnel") || layer.startsWith("ferry") || if (layer.startsWith("tunnel") || layer.startsWith("ferry") ||
layer.startsWith("road")) layer.startsWith("road"))
{ {
before = layer; before = layer.toStdString();
break; break;
} }
} }
p->map_->addCustomLayer("radar", std::move(pHost), before); p->AddLayer("radar", p->radarProductLayer_, before);
RadarRangeLayer::Add(p->map_, RadarRangeLayer::Add(p->map_,
p->context_->radarProductView_->range(), p->context_->radarProductView_->range(),
{radarSite->latitude(), radarSite->longitude()}); {radarSite->latitude(), radarSite->longitude()});
p->map_->addCustomLayer("colorTable", std::move(pColorTableHost)); p->AddLayer("colorTable", p->colorTableLayer_);
p->map_->addCustomLayer("overlay", std::move(pOverlayHost)); }
p->overlayLayer_ = std::make_shared<OverlayLayer>(p->context_);
p->AddLayer("overlay", p->overlayLayer_);
}
void MapWidgetImpl::AddLayer(const std::string& id,
std::shared_ptr<GenericLayer> layer,
const std::string& before)
{
// QMapboxGL::addCustomLayer will take ownership of the std::unique_ptr
std::unique_ptr<QMapbox::CustomLayerHostInterface> pHost =
std::make_unique<LayerWrapper>(layer);
map_->addCustomLayer(id.c_str(), std::move(pHost), before.c_str());
layerList_.push_back(id);
} }
void MapWidget::keyPressEvent(QKeyEvent* ev) void MapWidget::keyPressEvent(QKeyEvent* ev)

View file

@ -103,7 +103,7 @@ void OverlayLayer::Render(const QMapbox::CustomLayerRenderParameters& params)
gl::OpenGLFunctions& gl = context()->gl_; gl::OpenGLFunctions& gl = context()->gl_;
if (p->sweepTimeNeedsUpdate_) if (p->sweepTimeNeedsUpdate_ && context()->radarProductView_ != nullptr)
{ {
using namespace std::chrono; using namespace std::chrono;
auto sweepTime = auto sweepTime =