From ec4387112ebb81a6d542056b86e4826574cb4042 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Fri, 4 Oct 2024 16:40:56 -0400 Subject: [PATCH] Add poi layer --- scwx-qt/source/scwx/qt/map/poi_layer.cpp | 97 ++++++++++++++++++++ scwx-qt/source/scwx/qt/map/poi_layer.hpp | 33 +++++++ scwx-qt/source/scwx/qt/types/layer_types.cpp | 1 + scwx-qt/source/scwx/qt/types/layer_types.hpp | 1 + 4 files changed, 132 insertions(+) create mode 100644 scwx-qt/source/scwx/qt/map/poi_layer.cpp create mode 100644 scwx-qt/source/scwx/qt/map/poi_layer.hpp diff --git a/scwx-qt/source/scwx/qt/map/poi_layer.cpp b/scwx-qt/source/scwx/qt/map/poi_layer.cpp new file mode 100644 index 00000000..a1b0e630 --- /dev/null +++ b/scwx-qt/source/scwx/qt/map/poi_layer.cpp @@ -0,0 +1,97 @@ +#include +#include +#include +#include +#include +#include + +namespace scwx +{ +namespace qt +{ +namespace map +{ + +static const std::string logPrefix_ = "scwx::qt::map::poi_layer"; +static const auto logger_ = scwx::util::Logger::Create(logPrefix_); + + +class POILayer::Impl +{ +public: + explicit Impl(std::shared_ptr context) : + geoIcons_ {std::make_shared(context)} + { + } + ~Impl() {} + + void ReloadPOIs(); + + const std::string& poiIconName_ { + types::GetTextureName(types::ImageTexture::Crosshairs24)}; + + std::shared_ptr geoIcons_; +}; + +void POILayer::Impl::ReloadPOIs() +{ + logger_->debug("ReloadPOIs"); + auto poiManager = manager::POIManager::Instance(); + + geoIcons_->StartIcons(); + + for (size_t i = 0; i < poiManager->poi_count(); i++) + { + types::PointOfInterest poi = poiManager->get_poi(i); + std::shared_ptr icon = geoIcons_->AddIcon(); + geoIcons_->SetIconTexture(icon, poiIconName_, 0); + geoIcons_->SetIconLocation(icon, poi.latitude_, poi.longitude_); + } + + geoIcons_->FinishIcons(); +} + +POILayer::POILayer(const std::shared_ptr& context) : + DrawLayer(context), + p(std::make_unique(context)) +{ + AddDrawItem(p->geoIcons_); +} + +POILayer::~POILayer() = default; + +void POILayer::Initialize() +{ + logger_->debug("Initialize()"); + DrawLayer::Initialize(); + + p->geoIcons_->StartIconSheets(); + p->geoIcons_->AddIconSheet(p->poiIconName_); + p->geoIcons_->FinishIconSheets(); +} + +void POILayer::Render( + const QMapLibre::CustomLayerRenderParameters& params) +{ + //auto poiManager = manager::POIManager::Instance(); + gl::OpenGLFunctions& gl = context()->gl(); + + // TODO. do not redo this every time + p->ReloadPOIs(); + + DrawLayer::Render(params); + + SCWX_GL_CHECK_ERROR(); +} + +void POILayer::Deinitialize() +{ + logger_->debug("Deinitialize()"); + + DrawLayer::Deinitialize(); +} + +} // namespace map +} // namespace qt +} // namespace scwx + diff --git a/scwx-qt/source/scwx/qt/map/poi_layer.hpp b/scwx-qt/source/scwx/qt/map/poi_layer.hpp new file mode 100644 index 00000000..5bc12660 --- /dev/null +++ b/scwx-qt/source/scwx/qt/map/poi_layer.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include + +#include + +namespace scwx +{ +namespace qt +{ +namespace map +{ + +class POILayer : public DrawLayer +{ + Q_OBJECT + +public: + explicit POILayer(const std::shared_ptr& context); + ~POILayer(); + + void Initialize() override final; + void Render(const QMapLibre::CustomLayerRenderParameters&) override final; + void Deinitialize() override final; + +private: + class Impl; + std::unique_ptr p; +}; + +} // namespace map +} // namespace qt +} // namespace scwx diff --git a/scwx-qt/source/scwx/qt/types/layer_types.cpp b/scwx-qt/source/scwx/qt/types/layer_types.cpp index 6e66c5d1..3ab775e3 100644 --- a/scwx-qt/source/scwx/qt/types/layer_types.cpp +++ b/scwx-qt/source/scwx/qt/types/layer_types.cpp @@ -31,6 +31,7 @@ static const std::unordered_map informationLayerName_ {{InformationLayer::MapOverlay, "Map Overlay"}, {InformationLayer::RadarSite, "Radar Sites"}, {InformationLayer::ColorTable, "Color Table"}, + {InformationLayer::POILayer, "Point of Interest"}, {InformationLayer::Unknown, "?"}}; static const std::unordered_map mapLayerName_ { diff --git a/scwx-qt/source/scwx/qt/types/layer_types.hpp b/scwx-qt/source/scwx/qt/types/layer_types.hpp index f0561a6e..04a4aef9 100644 --- a/scwx-qt/source/scwx/qt/types/layer_types.hpp +++ b/scwx-qt/source/scwx/qt/types/layer_types.hpp @@ -44,6 +44,7 @@ enum class InformationLayer MapOverlay, RadarSite, ColorTable, + POILayer, Unknown };