Add map center icon to overlay layer

This commit is contained in:
Dan Paulat 2024-04-20 00:32:48 -05:00
parent 5beb16271a
commit fcf6ef800b

View file

@ -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<manager::PositionManager> 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<gl::draw::IconDrawItem> compassIcon_ {};
std::shared_ptr<gl::draw::IconDrawItem> mapCenterIcon_ {};
double lastBearing_ {0.0};
std::shared_ptr<gl::draw::IconDrawItem> 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());