mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 23:30:04 +00:00
Add map copyrights and map provider to map context
This commit is contained in:
parent
6b00c55bac
commit
5c7c7e6a19
5 changed files with 73 additions and 25 deletions
|
|
@ -29,6 +29,9 @@ public:
|
||||||
int16_t radarProductCode_ {0};
|
int16_t radarProductCode_ {0};
|
||||||
QMapLibre::CustomLayerRenderParameters renderParameters_ {};
|
QMapLibre::CustomLayerRenderParameters renderParameters_ {};
|
||||||
|
|
||||||
|
MapProvider mapProvider_ {MapProvider::Unknown};
|
||||||
|
std::string mapCopyrights_ {};
|
||||||
|
|
||||||
std::shared_ptr<view::OverlayProductView> overlayProductView_ {nullptr};
|
std::shared_ptr<view::OverlayProductView> overlayProductView_ {nullptr};
|
||||||
std::shared_ptr<view::RadarProductView> radarProductView_;
|
std::shared_ptr<view::RadarProductView> radarProductView_;
|
||||||
};
|
};
|
||||||
|
|
@ -48,6 +51,16 @@ std::weak_ptr<QMapLibre::Map> MapContext::map() const
|
||||||
return p->map_;
|
return p->map_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string MapContext::map_copyrights() const
|
||||||
|
{
|
||||||
|
return p->mapCopyrights_;
|
||||||
|
}
|
||||||
|
|
||||||
|
MapProvider MapContext::map_provider() const
|
||||||
|
{
|
||||||
|
return p->mapProvider_;
|
||||||
|
}
|
||||||
|
|
||||||
MapSettings& MapContext::settings()
|
MapSettings& MapContext::settings()
|
||||||
{
|
{
|
||||||
return p->settings_;
|
return p->settings_;
|
||||||
|
|
@ -94,6 +107,16 @@ void MapContext::set_map(const std::shared_ptr<QMapLibre::Map>& map)
|
||||||
p->map_ = map;
|
p->map_ = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapContext::set_map_copyrights(const std::string& copyrights)
|
||||||
|
{
|
||||||
|
p->mapCopyrights_ = copyrights;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapContext::set_map_provider(MapProvider provider)
|
||||||
|
{
|
||||||
|
p->mapProvider_ = provider;
|
||||||
|
}
|
||||||
|
|
||||||
void MapContext::set_overlay_product_view(
|
void MapContext::set_overlay_product_view(
|
||||||
const std::shared_ptr<view::OverlayProductView>& overlayProductView)
|
const std::shared_ptr<view::OverlayProductView>& overlayProductView)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <scwx/qt/gl/gl_context.hpp>
|
#include <scwx/qt/gl/gl_context.hpp>
|
||||||
|
#include <scwx/qt/map/map_provider.hpp>
|
||||||
#include <scwx/common/products.hpp>
|
#include <scwx/common/products.hpp>
|
||||||
|
|
||||||
#include <qmaplibre.hpp>
|
#include <qmaplibre.hpp>
|
||||||
|
|
@ -36,6 +37,8 @@ public:
|
||||||
MapContext& operator=(MapContext&&) noexcept;
|
MapContext& operator=(MapContext&&) noexcept;
|
||||||
|
|
||||||
std::weak_ptr<QMapLibre::Map> map() const;
|
std::weak_ptr<QMapLibre::Map> map() const;
|
||||||
|
std::string map_copyrights() const;
|
||||||
|
MapProvider map_provider() const;
|
||||||
MapSettings& settings();
|
MapSettings& settings();
|
||||||
float pixel_ratio() const;
|
float pixel_ratio() const;
|
||||||
std::shared_ptr<view::OverlayProductView> overlay_product_view() const;
|
std::shared_ptr<view::OverlayProductView> overlay_product_view() const;
|
||||||
|
|
@ -46,6 +49,8 @@ public:
|
||||||
QMapLibre::CustomLayerRenderParameters render_parameters() const;
|
QMapLibre::CustomLayerRenderParameters render_parameters() const;
|
||||||
|
|
||||||
void set_map(const std::shared_ptr<QMapLibre::Map>& map);
|
void set_map(const std::shared_ptr<QMapLibre::Map>& map);
|
||||||
|
void set_map_copyrights(const std::string& copyrights);
|
||||||
|
void set_map_provider(MapProvider provider);
|
||||||
void set_overlay_product_view(
|
void set_overlay_product_view(
|
||||||
const std::shared_ptr<view::OverlayProductView>& overlayProductView);
|
const std::shared_ptr<view::OverlayProductView>& overlayProductView);
|
||||||
void set_pixel_ratio(float pixelRatio);
|
void set_pixel_ratio(float pixelRatio);
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QTextDocument>
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
{
|
{
|
||||||
|
|
@ -94,11 +95,13 @@ public:
|
||||||
overlayProductView->SetAutoRefresh(autoRefreshEnabled_);
|
overlayProductView->SetAutoRefresh(autoRefreshEnabled_);
|
||||||
overlayProductView->SetAutoUpdate(autoUpdateEnabled_);
|
overlayProductView->SetAutoUpdate(autoUpdateEnabled_);
|
||||||
|
|
||||||
// Initialize context
|
|
||||||
context_->set_overlay_product_view(overlayProductView);
|
|
||||||
|
|
||||||
auto& generalSettings = settings::GeneralSettings::Instance();
|
auto& generalSettings = settings::GeneralSettings::Instance();
|
||||||
|
|
||||||
|
// Initialize context
|
||||||
|
context_->set_map_provider(
|
||||||
|
GetMapProvider(generalSettings.map_provider().GetValue()));
|
||||||
|
context_->set_overlay_product_view(overlayProductView);
|
||||||
|
|
||||||
SetRadarSite(generalSettings.default_radar_site().GetValue());
|
SetRadarSite(generalSettings.default_radar_site().GetValue());
|
||||||
|
|
||||||
// Create ImGui Context
|
// Create ImGui Context
|
||||||
|
|
@ -110,9 +113,6 @@ public:
|
||||||
// Initialize ImGui Qt backend
|
// Initialize ImGui Qt backend
|
||||||
ImGui_ImplQt_Init();
|
ImGui_ImplQt_Init();
|
||||||
|
|
||||||
// Set Map Provider Details
|
|
||||||
mapProvider_ = GetMapProvider(generalSettings.map_provider().GetValue());
|
|
||||||
|
|
||||||
ConnectSignals();
|
ConnectSignals();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,6 +143,7 @@ public:
|
||||||
void AddLayers();
|
void AddLayers();
|
||||||
void AddPlacefileLayer(const std::string& placefileName,
|
void AddPlacefileLayer(const std::string& placefileName,
|
||||||
const std::string& before);
|
const std::string& before);
|
||||||
|
void ConnectMapSignals();
|
||||||
void ConnectSignals();
|
void ConnectSignals();
|
||||||
void ImGuiCheckFonts();
|
void ImGuiCheckFonts();
|
||||||
void InitializeNewRadarProductView(const std::string& colorPalette);
|
void InitializeNewRadarProductView(const std::string& colorPalette);
|
||||||
|
|
@ -170,7 +171,6 @@ public:
|
||||||
std::shared_ptr<MapContext> context_;
|
std::shared_ptr<MapContext> context_;
|
||||||
|
|
||||||
MapWidget* widget_;
|
MapWidget* widget_;
|
||||||
MapProvider mapProvider_;
|
|
||||||
QMapLibre::Settings settings_;
|
QMapLibre::Settings settings_;
|
||||||
std::shared_ptr<QMapLibre::Map> map_;
|
std::shared_ptr<QMapLibre::Map> map_;
|
||||||
std::list<std::string> layerList_;
|
std::list<std::string> layerList_;
|
||||||
|
|
@ -250,6 +250,24 @@ MapWidget::~MapWidget()
|
||||||
makeCurrent();
|
makeCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapWidgetImpl::ConnectMapSignals()
|
||||||
|
{
|
||||||
|
connect(map_.get(),
|
||||||
|
&QMapLibre::Map::needsRendering,
|
||||||
|
this,
|
||||||
|
&MapWidgetImpl::Update);
|
||||||
|
connect(map_.get(),
|
||||||
|
&QMapLibre::Map::copyrightsChanged,
|
||||||
|
this,
|
||||||
|
[this](const QString& copyrightsHtml)
|
||||||
|
{
|
||||||
|
QTextDocument document {};
|
||||||
|
document.setHtml(copyrightsHtml);
|
||||||
|
context_->set_map_copyrights(
|
||||||
|
document.toPlainText().toStdString());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void MapWidgetImpl::ConnectSignals()
|
void MapWidgetImpl::ConnectSignals()
|
||||||
{
|
{
|
||||||
connect(placefileManager_.get(),
|
connect(placefileManager_.get(),
|
||||||
|
|
@ -725,7 +743,8 @@ void MapWidget::SetInitialMapStyle(const std::string& styleName)
|
||||||
|
|
||||||
void MapWidget::SetMapStyle(const std::string& styleName)
|
void MapWidget::SetMapStyle(const std::string& styleName)
|
||||||
{
|
{
|
||||||
const auto& mapProviderInfo = GetMapProviderInfo(p->mapProvider_);
|
const auto mapProvider = p->context_->map_provider();
|
||||||
|
const auto& mapProviderInfo = GetMapProviderInfo(mapProvider);
|
||||||
auto& styles = mapProviderInfo.mapStyles_;
|
auto& styles = mapProviderInfo.mapStyles_;
|
||||||
|
|
||||||
for (size_t i = 0u; i < styles.size(); ++i)
|
for (size_t i = 0u; i < styles.size(); ++i)
|
||||||
|
|
@ -737,8 +756,7 @@ void MapWidget::SetMapStyle(const std::string& styleName)
|
||||||
|
|
||||||
logger_->debug("Updating style: {}", styles[i].name_);
|
logger_->debug("Updating style: {}", styles[i].name_);
|
||||||
|
|
||||||
util::maplibre::SetMapStyleUrl(
|
util::maplibre::SetMapStyleUrl(p->context_, styles[i].url_);
|
||||||
p->map_, p->mapProvider_, styles[i].url_);
|
|
||||||
|
|
||||||
if (++p->currentStyleIndex_ == styles.size())
|
if (++p->currentStyleIndex_ == styles.size())
|
||||||
{
|
{
|
||||||
|
|
@ -757,15 +775,16 @@ qreal MapWidget::pixelRatio()
|
||||||
|
|
||||||
void MapWidget::changeStyle()
|
void MapWidget::changeStyle()
|
||||||
{
|
{
|
||||||
const auto& mapProviderInfo = GetMapProviderInfo(p->mapProvider_);
|
const auto mapProvider = p->context_->map_provider();
|
||||||
|
const auto& mapProviderInfo = GetMapProviderInfo(mapProvider);
|
||||||
auto& styles = mapProviderInfo.mapStyles_;
|
auto& styles = mapProviderInfo.mapStyles_;
|
||||||
|
|
||||||
p->currentStyle_ = &styles[p->currentStyleIndex_];
|
p->currentStyle_ = &styles[p->currentStyleIndex_];
|
||||||
|
|
||||||
logger_->debug("Updating style: {}", styles[p->currentStyleIndex_].name_);
|
logger_->debug("Updating style: {}", styles[p->currentStyleIndex_].name_);
|
||||||
|
|
||||||
util::maplibre::SetMapStyleUrl(
|
util::maplibre::SetMapStyleUrl(p->context_,
|
||||||
p->map_, p->mapProvider_, styles[p->currentStyleIndex_].url_);
|
styles[p->currentStyleIndex_].url_);
|
||||||
|
|
||||||
if (++p->currentStyleIndex_ == styles.size())
|
if (++p->currentStyleIndex_ == styles.size())
|
||||||
{
|
{
|
||||||
|
|
@ -1135,10 +1154,7 @@ void MapWidget::initializeGL()
|
||||||
p->map_.reset(
|
p->map_.reset(
|
||||||
new QMapLibre::Map(nullptr, p->settings_, size(), pixelRatio()));
|
new QMapLibre::Map(nullptr, p->settings_, size(), pixelRatio()));
|
||||||
p->context_->set_map(p->map_);
|
p->context_->set_map(p->map_);
|
||||||
connect(p->map_.get(),
|
p->ConnectMapSignals();
|
||||||
&QMapLibre::Map::needsRendering,
|
|
||||||
p.get(),
|
|
||||||
&MapWidgetImpl::Update);
|
|
||||||
|
|
||||||
// Set default location to radar site
|
// Set default location to radar site
|
||||||
std::shared_ptr<config::RadarSite> radarSite =
|
std::shared_ptr<config::RadarSite> radarSite =
|
||||||
|
|
|
||||||
|
|
@ -88,10 +88,11 @@ glm::vec2 LatLongToScreenCoordinate(const QMapLibre::Coordinate& coordinate)
|
||||||
return screen;
|
return screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetMapStyleUrl(const std::shared_ptr<QMapLibre::Map>& map,
|
void SetMapStyleUrl(const std::shared_ptr<map::MapContext>& mapContext,
|
||||||
map::MapProvider mapProvider,
|
const std::string& url)
|
||||||
const std::string& url)
|
|
||||||
{
|
{
|
||||||
|
const auto mapProvider = mapContext->map_provider();
|
||||||
|
|
||||||
QString qUrl = QString::fromStdString(url);
|
QString qUrl = QString::fromStdString(url);
|
||||||
|
|
||||||
if (mapProvider == map::MapProvider::MapTiler)
|
if (mapProvider == map::MapProvider::MapTiler)
|
||||||
|
|
@ -100,7 +101,11 @@ void SetMapStyleUrl(const std::shared_ptr<QMapLibre::Map>& map,
|
||||||
qUrl.append(map::GetMapProviderApiKey(mapProvider));
|
qUrl.append(map::GetMapProviderApiKey(mapProvider));
|
||||||
}
|
}
|
||||||
|
|
||||||
map->setStyleUrl(qUrl);
|
auto map = mapContext->map().lock();
|
||||||
|
if (map != nullptr)
|
||||||
|
{
|
||||||
|
map->setStyleUrl(qUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace maplibre
|
} // namespace maplibre
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <scwx/qt/map/map_provider.hpp>
|
#include <scwx/qt/map/map_context.hpp>
|
||||||
|
|
||||||
#include <QMapLibre/Map>
|
#include <QMapLibre/Map>
|
||||||
#include <QMapLibre/Types>
|
#include <QMapLibre/Types>
|
||||||
|
|
@ -34,9 +34,8 @@ bool IsPointInPolygon(const std::vector<glm::vec2>& vertices,
|
||||||
|
|
||||||
glm::vec2 LatLongToScreenCoordinate(const QMapLibre::Coordinate& coordinate);
|
glm::vec2 LatLongToScreenCoordinate(const QMapLibre::Coordinate& coordinate);
|
||||||
|
|
||||||
void SetMapStyleUrl(const std::shared_ptr<QMapLibre::Map>& map,
|
void SetMapStyleUrl(const std::shared_ptr<map::MapContext>& mapContext,
|
||||||
map::MapProvider mapProvider,
|
const std::string& url);
|
||||||
const std::string& url);
|
|
||||||
|
|
||||||
} // namespace maplibre
|
} // namespace maplibre
|
||||||
} // namespace util
|
} // namespace util
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue