Add location icon to overlay layer

This commit is contained in:
Dan Paulat 2023-11-23 08:22:19 -06:00
parent c91b1c9a65
commit 9590e2cc52

View file

@ -1,5 +1,8 @@
#include <scwx/qt/map/overlay_layer.hpp> #include <scwx/qt/map/overlay_layer.hpp>
#include <scwx/qt/gl/draw/geo_icons.hpp>
#include <scwx/qt/gl/draw/rectangle.hpp> #include <scwx/qt/gl/draw/rectangle.hpp>
#include <scwx/qt/manager/position_manager.hpp>
#include <scwx/qt/types/texture_types.hpp>
#include <scwx/util/logger.hpp> #include <scwx/util/logger.hpp>
#include <scwx/util/time.hpp> #include <scwx/util/time.hpp>
@ -10,6 +13,7 @@
#endif #endif
#include <imgui.h> #include <imgui.h>
#include <QGeoPositionInfo>
#if !defined(_MSC_VER) #if !defined(_MSC_VER)
# include <date/date.h> # include <date/date.h>
@ -34,13 +38,24 @@ class OverlayLayerImpl
public: public:
explicit OverlayLayerImpl(std::shared_ptr<MapContext> context) : explicit OverlayLayerImpl(std::shared_ptr<MapContext> context) :
activeBoxOuter_ {std::make_shared<gl::draw::Rectangle>(context)}, activeBoxOuter_ {std::make_shared<gl::draw::Rectangle>(context)},
activeBoxInner_ {std::make_shared<gl::draw::Rectangle>(context)} activeBoxInner_ {std::make_shared<gl::draw::Rectangle>(context)},
icons_ {std::make_shared<gl::draw::GeoIcons>(context)},
locationIconName_ {
types::GetTextureName(types::ImageTexture::Crosshairs32)}
{ {
} }
~OverlayLayerImpl() = default; ~OverlayLayerImpl() = default;
std::shared_ptr<manager::PositionManager> positionManager_ {
manager::PositionManager::Instance()};
QGeoPositionInfo currentPosition_ {};
std::shared_ptr<gl::draw::Rectangle> activeBoxOuter_; std::shared_ptr<gl::draw::Rectangle> activeBoxOuter_;
std::shared_ptr<gl::draw::Rectangle> activeBoxInner_; std::shared_ptr<gl::draw::Rectangle> activeBoxInner_;
std::shared_ptr<gl::draw::GeoIcons> icons_;
const std::string& locationIconName_;
std::shared_ptr<gl::draw::GeoIconDrawItem> locationIcon_ {};
std::string sweepTimeString_ {}; std::string sweepTimeString_ {};
bool sweepTimeNeedsUpdate_ {true}; bool sweepTimeNeedsUpdate_ {true};
@ -52,6 +67,7 @@ OverlayLayer::OverlayLayer(std::shared_ptr<MapContext> context) :
{ {
AddDrawItem(p->activeBoxOuter_); AddDrawItem(p->activeBoxOuter_);
AddDrawItem(p->activeBoxInner_); AddDrawItem(p->activeBoxInner_);
AddDrawItem(p->icons_);
p->activeBoxOuter_->SetPosition(0.0f, 0.0f); p->activeBoxOuter_->SetPosition(0.0f, 0.0f);
} }
@ -73,6 +89,42 @@ void OverlayLayer::Initialize()
this, this,
&OverlayLayer::UpdateSweepTimeNextFrame); &OverlayLayer::UpdateSweepTimeNextFrame);
} }
p->currentPosition_ = p->positionManager_->position();
auto coordinate = p->currentPosition_.coordinate();
p->icons_->StartIconSheets();
p->icons_->AddIconSheet(p->locationIconName_);
p->icons_->FinishIconSheets();
p->icons_->StartIcons();
p->locationIcon_ = p->icons_->AddIcon();
gl::draw::GeoIcons::SetIconTexture(
p->locationIcon_, p->locationIconName_, 0);
gl::draw::GeoIcons::SetIconLocation(
p->locationIcon_, coordinate.latitude(), coordinate.longitude());
p->icons_->FinishIcons();
connect(p->positionManager_.get(),
&manager::PositionManager::LocationTrackingChanged,
this,
[this]() { Q_EMIT NeedsRendering(); });
connect(p->positionManager_.get(),
&manager::PositionManager::PositionUpdated,
this,
[this](const QGeoPositionInfo& position)
{
auto coordinate = position.coordinate();
if (position.isValid() &&
p->currentPosition_.coordinate() != coordinate)
{
gl::draw::GeoIcons::SetIconLocation(p->locationIcon_,
coordinate.latitude(),
coordinate.longitude());
Q_EMIT NeedsRendering();
}
p->currentPosition_ = position;
});
} }
void OverlayLayer::Render( void OverlayLayer::Render(
@ -85,6 +137,9 @@ void OverlayLayer::Render(
context()->set_render_parameters(params); context()->set_render_parameters(params);
// Set OpenGL blend mode for transparency
gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
p->sweepTimePicked_ = false; p->sweepTimePicked_ = false;
if (p->sweepTimeNeedsUpdate_ && radarProductView != nullptr) if (p->sweepTimeNeedsUpdate_ && radarProductView != nullptr)
@ -117,6 +172,10 @@ void OverlayLayer::Render(
p->activeBoxInner_->SetBorder(1.0f * pixelRatio, {255, 255, 255, 255}); p->activeBoxInner_->SetBorder(1.0f * pixelRatio, {255, 255, 255, 255});
} }
// Location Icon
p->icons_->SetVisible(p->currentPosition_.isValid() &&
p->positionManager_->IsLocationTracked());
DrawLayer::Render(params); DrawLayer::Render(params);
if (radarProductView != nullptr) if (radarProductView != nullptr)
@ -198,6 +257,17 @@ void OverlayLayer::Deinitialize()
this, this,
&OverlayLayer::UpdateSweepTimeNextFrame); &OverlayLayer::UpdateSweepTimeNextFrame);
} }
disconnect(p->positionManager_.get(),
&manager::PositionManager::LocationTrackingChanged,
this,
nullptr);
disconnect(p->positionManager_.get(),
&manager::PositionManager::PositionUpdated,
this,
nullptr);
p->locationIcon_ = nullptr;
} }
bool OverlayLayer::RunMousePicking( bool OverlayLayer::RunMousePicking(