mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 22:20:04 +00:00
Integrating map provider into existing map widget
This commit is contained in:
parent
ee99b51003
commit
271756bba9
2 changed files with 40 additions and 40 deletions
|
|
@ -9,6 +9,7 @@
|
||||||
#include <scwx/qt/manager/settings_manager.hpp>
|
#include <scwx/qt/manager/settings_manager.hpp>
|
||||||
#include <scwx/qt/manager/text_event_manager.hpp>
|
#include <scwx/qt/manager/text_event_manager.hpp>
|
||||||
#include <scwx/qt/manager/update_manager.hpp>
|
#include <scwx/qt/manager/update_manager.hpp>
|
||||||
|
#include <scwx/qt/map/map_provider.hpp>
|
||||||
#include <scwx/qt/map/map_widget.hpp>
|
#include <scwx/qt/map/map_widget.hpp>
|
||||||
#include <scwx/qt/model/radar_product_model.hpp>
|
#include <scwx/qt/model/radar_product_model.hpp>
|
||||||
#include <scwx/qt/ui/alert_dock_widget.hpp>
|
#include <scwx/qt/ui/alert_dock_widget.hpp>
|
||||||
|
|
@ -74,10 +75,18 @@ public:
|
||||||
elevationButtonsChanged_ {false},
|
elevationButtonsChanged_ {false},
|
||||||
resizeElevationButtons_ {false}
|
resizeElevationButtons_ {false}
|
||||||
{
|
{
|
||||||
|
map::MapProvider mapProvider =
|
||||||
|
map::GetMapProvider(manager::SettingsManager::general_settings()
|
||||||
|
.map_provider()
|
||||||
|
.GetValue());
|
||||||
|
const map::MapProviderInfo& mapProviderInfo =
|
||||||
|
map::GetMapProviderInfo(mapProvider);
|
||||||
|
|
||||||
std::string appDataPath {
|
std::string appDataPath {
|
||||||
QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
|
QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
|
||||||
.toStdString()};
|
.toStdString()};
|
||||||
std::string cacheDbPath {appDataPath + "/mbgl-cache.db"};
|
std::string cacheDbPath {appDataPath + "/" +
|
||||||
|
mapProviderInfo.cacheDbName_};
|
||||||
|
|
||||||
if (!std::filesystem::exists(appDataPath))
|
if (!std::filesystem::exists(appDataPath))
|
||||||
{
|
{
|
||||||
|
|
@ -89,12 +98,10 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string mapboxApiKey = manager::SettingsManager::general_settings()
|
std::string mapProviderApiKey = map::GetMapProviderApiKey(mapProvider);
|
||||||
.mapbox_api_key()
|
|
||||||
.GetValue();
|
|
||||||
|
|
||||||
settings_.resetToTemplate(QMapLibreGL::Settings::MapboxSettings);
|
settings_.resetToTemplate(mapProviderInfo.settingsTemplate_);
|
||||||
settings_.setApiKey(QString {mapboxApiKey.c_str()});
|
settings_.setApiKey(QString {mapProviderApiKey.c_str()});
|
||||||
settings_.setCacheDatabasePath(QString {cacheDbPath.c_str()});
|
settings_.setCacheDatabasePath(QString {cacheDbPath.c_str()});
|
||||||
settings_.setCacheDatabaseMaximumSize(20 * 1024 * 1024);
|
settings_.setCacheDatabaseMaximumSize(20 * 1024 * 1024);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <scwx/qt/map/alert_layer.hpp>
|
#include <scwx/qt/map/alert_layer.hpp>
|
||||||
#include <scwx/qt/map/color_table_layer.hpp>
|
#include <scwx/qt/map/color_table_layer.hpp>
|
||||||
#include <scwx/qt/map/layer_wrapper.hpp>
|
#include <scwx/qt/map/layer_wrapper.hpp>
|
||||||
|
#include <scwx/qt/map/map_provider.hpp>
|
||||||
#include <scwx/qt/map/overlay_layer.hpp>
|
#include <scwx/qt/map/overlay_layer.hpp>
|
||||||
#include <scwx/qt/map/radar_product_layer.hpp>
|
#include <scwx/qt/map/radar_product_layer.hpp>
|
||||||
#include <scwx/qt/map/radar_range_layer.hpp>
|
#include <scwx/qt/map/radar_range_layer.hpp>
|
||||||
|
|
@ -39,20 +40,6 @@ namespace map
|
||||||
static const std::string logPrefix_ = "scwx::qt::map::map_widget";
|
static const std::string logPrefix_ = "scwx::qt::map::map_widget";
|
||||||
static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
|
static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
|
||||||
|
|
||||||
typedef std::pair<std::string, std::string> MapStyle;
|
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
static const MapStyle streets { "mapbox://styles/mapbox/streets-v11", "Streets"};
|
|
||||||
static const MapStyle outdoors { "mapbox://styles/mapbox/outdoors-v11", "Outdoors"};
|
|
||||||
static const MapStyle light { "mapbox://styles/mapbox/light-v10", "Light"};
|
|
||||||
static const MapStyle dark { "mapbox://styles/mapbox/dark-v10", "Dark" };
|
|
||||||
static const MapStyle satellite { "mapbox://styles/mapbox/satellite-v9", "Satellite" };
|
|
||||||
static const MapStyle satelliteStreets { "mapbox://styles/mapbox/satellite-streets-v11", "Satellite Streets" };
|
|
||||||
// clang-format on
|
|
||||||
|
|
||||||
static const std::array<MapStyle, 6> mapboxStyles_ = {
|
|
||||||
{streets, outdoors, light, dark, satellite, satelliteStreets}};
|
|
||||||
|
|
||||||
class MapWidgetImpl : public QObject
|
class MapWidgetImpl : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
@ -84,9 +71,10 @@ public:
|
||||||
prevBearing_ {0.0},
|
prevBearing_ {0.0},
|
||||||
prevPitch_ {0.0}
|
prevPitch_ {0.0}
|
||||||
{
|
{
|
||||||
SetRadarSite(scwx::qt::manager::SettingsManager::general_settings()
|
auto& generalSettings =
|
||||||
.default_radar_site()
|
scwx::qt::manager::SettingsManager::general_settings();
|
||||||
.GetValue());
|
|
||||||
|
SetRadarSite(generalSettings.default_radar_site().GetValue());
|
||||||
|
|
||||||
// Create ImGui Context
|
// Create ImGui Context
|
||||||
static size_t currentMapId_ {0u};
|
static size_t currentMapId_ {0u};
|
||||||
|
|
@ -97,6 +85,9 @@ public:
|
||||||
// Initialize ImGui Qt backend
|
// Initialize ImGui Qt backend
|
||||||
ImGui_ImplQt_Init();
|
ImGui_ImplQt_Init();
|
||||||
ImGui_ImplQt_RegisterWidget(widget_);
|
ImGui_ImplQt_RegisterWidget(widget_);
|
||||||
|
|
||||||
|
// Set Map Provider Details
|
||||||
|
mapProvider_ = GetMapProvider(generalSettings.map_provider().GetValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
~MapWidgetImpl()
|
~MapWidgetImpl()
|
||||||
|
|
@ -134,6 +125,7 @@ public:
|
||||||
std::shared_ptr<MapContext> context_;
|
std::shared_ptr<MapContext> context_;
|
||||||
|
|
||||||
MapWidget* widget_;
|
MapWidget* widget_;
|
||||||
|
MapProvider mapProvider_;
|
||||||
QMapLibreGL::Settings settings_;
|
QMapLibreGL::Settings settings_;
|
||||||
std::shared_ptr<QMapLibreGL::Map> map_;
|
std::shared_ptr<QMapLibreGL::Map> map_;
|
||||||
std::list<std::string> layerList_;
|
std::list<std::string> layerList_;
|
||||||
|
|
@ -545,11 +537,12 @@ qreal MapWidget::pixelRatio()
|
||||||
|
|
||||||
void MapWidget::changeStyle()
|
void MapWidget::changeStyle()
|
||||||
{
|
{
|
||||||
auto& styles = mapboxStyles_;
|
const auto& mapProviderInfo = GetMapProviderInfo(p->mapProvider_);
|
||||||
|
auto& styles = mapProviderInfo.mapStyles_;
|
||||||
|
|
||||||
p->map_->setStyleUrl(styles[p->currentStyleIndex_].first.c_str());
|
logger_->debug("Updating style: {}", styles[p->currentStyleIndex_].name_);
|
||||||
setWindowTitle(QString("Mapbox GL: ") +
|
|
||||||
styles[p->currentStyleIndex_].second.c_str());
|
p->map_->setStyleUrl(styles[p->currentStyleIndex_].url_.c_str());
|
||||||
|
|
||||||
if (++p->currentStyleIndex_ == styles.size())
|
if (++p->currentStyleIndex_ == styles.size())
|
||||||
{
|
{
|
||||||
|
|
@ -578,13 +571,21 @@ void MapWidget::AddLayers()
|
||||||
std::shared_ptr<config::RadarSite> radarSite =
|
std::shared_ptr<config::RadarSite> radarSite =
|
||||||
p->radarProductManager_->radar_site();
|
p->radarProductManager_->radar_site();
|
||||||
|
|
||||||
|
const auto& mapStyle =
|
||||||
|
GetMapProviderInfo(p->mapProvider_).mapStyles_[p->currentStyleIndex_];
|
||||||
|
|
||||||
std::string before = "ferry";
|
std::string before = "ferry";
|
||||||
|
|
||||||
for (const QString& layer : p->map_->layerIds())
|
for (const QString& layer : p->map_->layerIds())
|
||||||
{
|
{
|
||||||
// Draw below tunnels, ferries and roads
|
// Draw below layers defined in map style
|
||||||
if (layer.startsWith("tunnel") || layer.startsWith("ferry") ||
|
auto it = std::find_if(
|
||||||
layer.startsWith("road"))
|
mapStyle.drawBelow_.cbegin(),
|
||||||
|
mapStyle.drawBelow_.cend(),
|
||||||
|
[&layer](const std::string& styleLayer) -> bool
|
||||||
|
{ return layer.startsWith(QString::fromStdString(styleLayer)); });
|
||||||
|
|
||||||
|
if (it != mapStyle.drawBelow_.cend())
|
||||||
{
|
{
|
||||||
before = layer.toStdString();
|
before = layer.toStdString();
|
||||||
break;
|
break;
|
||||||
|
|
@ -740,16 +741,8 @@ void MapWidget::initializeGL()
|
||||||
p->prevBearing_,
|
p->prevBearing_,
|
||||||
p->prevPitch_);
|
p->prevPitch_);
|
||||||
|
|
||||||
QString styleUrl = qgetenv("MAPBOX_STYLE_URL");
|
// Update style
|
||||||
if (styleUrl.isEmpty())
|
changeStyle();
|
||||||
{
|
|
||||||
changeStyle();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
p->map_->setStyleUrl(styleUrl);
|
|
||||||
setWindowTitle(QString("Mapbox GL: ") + styleUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(p->map_.get(),
|
connect(p->map_.get(),
|
||||||
&QMapLibreGL::Map::mapChanged,
|
&QMapLibreGL::Map::mapChanged,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue