From fcf6ef800b5c7482c5b1d026d393e33ab6b559cd Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sat, 20 Apr 2024 00:32:48 -0500 Subject: [PATCH] Add map center icon to overlay layer --- scwx-qt/source/scwx/qt/map/overlay_layer.cpp | 24 +++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/scwx-qt/source/scwx/qt/map/overlay_layer.cpp b/scwx-qt/source/scwx/qt/map/overlay_layer.cpp index a088b4dc..5d6a80b0 100644 --- a/scwx-qt/source/scwx/qt/map/overlay_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/overlay_layer.cpp @@ -69,6 +69,9 @@ public: showMapAttributionCallbackUuid_ = generalSettings.show_map_attribution().RegisterValueChangedCallback( [this](const bool&) { Q_EMIT self_->NeedsRendering(); }); + showMapCenterCallbackUuid_ = + generalSettings.show_map_center().RegisterValueChangedCallback( + [this](const bool&) { Q_EMIT self_->NeedsRendering(); }); showMapLogoCallbackUuid_ = generalSettings.show_map_logo().RegisterValueChangedCallback( [this](const bool&) { Q_EMIT self_->NeedsRendering(); }); @@ -84,6 +87,8 @@ public: defaultTimeZoneCallbackUuid_); generalSettings.show_map_attribution().UnregisterValueChangedCallback( showMapAttributionCallbackUuid_); + generalSettings.show_map_center().UnregisterValueChangedCallback( + showMapCenterCallbackUuid_); generalSettings.show_map_logo().UnregisterValueChangedCallback( showMapLogoCallbackUuid_); } @@ -93,6 +98,7 @@ public: boost::uuids::uuid clockFormatCallbackUuid_; boost::uuids::uuid defaultTimeZoneCallbackUuid_; boost::uuids::uuid showMapAttributionCallbackUuid_; + boost::uuids::uuid showMapCenterCallbackUuid_; boost::uuids::uuid showMapLogoCallbackUuid_; std::shared_ptr positionManager_ { @@ -112,6 +118,8 @@ public: types::GetTextureName(types::ImageTexture::CardinalPoint24)}; const std::string& compassIconName_ { types::GetTextureName(types::ImageTexture::Compass24)}; + const std::string& mapCenterIconName_ { + types::GetTextureName(types::ImageTexture::Cursor17)}; const std::string& mapboxLogoImageName_ { types::GetTextureName(types::ImageTexture::MapboxLogo)}; @@ -119,6 +127,7 @@ public: types::GetTextureName(types::ImageTexture::MapTilerLogo)}; std::shared_ptr compassIcon_ {}; + std::shared_ptr mapCenterIcon_ {}; double lastBearing_ {0.0}; std::shared_ptr mapLogoIcon_ {}; @@ -185,6 +194,7 @@ void OverlayLayer::Initialize() p->icons_->StartIconSheets(); p->icons_->AddIconSheet(p->cardinalPointIconName_); p->icons_->AddIconSheet(p->compassIconName_); + p->icons_->AddIconSheet(p->mapCenterIconName_); p->icons_->AddIconSheet(p->mapboxLogoImageName_)->SetAnchor(0.0f, 1.0f); p->icons_->AddIconSheet(p->mapTilerLogoImageName_)->SetAnchor(0.0f, 1.0f); p->icons_->FinishIconSheets(); @@ -234,6 +244,9 @@ void OverlayLayer::Initialize() } }); + p->mapCenterIcon_ = p->icons_->AddIcon(); + p->icons_->SetIconTexture(p->mapCenterIcon_, p->mapCenterIconName_, 0); + p->mapLogoIcon_ = p->icons_->AddIcon(); if (context()->map_provider() == MapProvider::Mapbox) { @@ -411,6 +424,16 @@ void OverlayLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) auto& generalSettings = settings::GeneralSettings::Instance(); + // Map Center Icon + if (params.width != p->lastWidth_ || params.height != p->lastHeight_) + { + // Draw the icon in the center of the widget + p->icons_->SetIconLocation( + p->mapCenterIcon_, params.width / 2.0, params.height / 2.0); + } + p->icons_->SetIconVisible(p->mapCenterIcon_, + generalSettings.show_map_center().GetValue()); + QMargins colorTableMargins = context()->color_table_margins(); if (colorTableMargins != p->lastColorTableMargins_ || p->firstRender_) { @@ -418,7 +441,6 @@ void OverlayLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) p->icons_->SetIconLocation(p->mapLogoIcon_, 10 + colorTableMargins.left(), 10 + colorTableMargins.bottom()); - p->icons_->FinishIcons(); } p->icons_->SetIconVisible(p->mapLogoIcon_, generalSettings.show_map_logo().GetValue());