mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 20:20:06 +00:00
Move code from map_widget and custom_layer_dialog to util/maplibre
This commit is contained in:
parent
fee00b737a
commit
a7c6be2bab
4 changed files with 64 additions and 66 deletions
|
|
@ -185,8 +185,6 @@ public:
|
|||
bool UpdateStoredMapParameters();
|
||||
void CheckLevel3Availability();
|
||||
|
||||
std::string FindMapSymbologyLayer();
|
||||
|
||||
common::Level2Product
|
||||
GetLevel2ProductOrDefault(const std::string& productName) const;
|
||||
|
||||
|
|
@ -1146,43 +1144,6 @@ void MapWidget::DumpLayerList() const
|
|||
logger_->info("Layers: {}", p->map_->layerIds().join(", ").toStdString());
|
||||
}
|
||||
|
||||
std::string MapWidgetImpl::FindMapSymbologyLayer()
|
||||
{
|
||||
std::string before = "ferry";
|
||||
|
||||
for (const QString& qlayer : styleLayers_)
|
||||
{
|
||||
const std::string layer = qlayer.toStdString();
|
||||
|
||||
// Draw below layers defined in map style
|
||||
auto it = std::find_if(currentStyle_->drawBelow_.cbegin(),
|
||||
currentStyle_->drawBelow_.cend(),
|
||||
[&layer](const std::string& styleLayer) -> bool
|
||||
{
|
||||
// Perform case-insensitive matching
|
||||
RE2 re {"(?i)" + styleLayer};
|
||||
if (re.ok())
|
||||
{
|
||||
return RE2::FullMatch(layer, re);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fall back to basic comparison if RE
|
||||
// doesn't compile
|
||||
return layer == styleLayer;
|
||||
}
|
||||
});
|
||||
|
||||
if (it != currentStyle_->drawBelow_.cend())
|
||||
{
|
||||
before = layer;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return before;
|
||||
}
|
||||
|
||||
void MapWidgetImpl::AddLayers()
|
||||
{
|
||||
if (styleLayers_.isEmpty())
|
||||
|
|
@ -1218,7 +1179,8 @@ void MapWidgetImpl::AddLayers()
|
|||
{
|
||||
// Subsequent layers are drawn underneath the map symbology layer
|
||||
case types::MapLayer::MapUnderlay:
|
||||
before = FindMapSymbologyLayer();
|
||||
before = util::maplibre::FindMapSymbologyLayer(
|
||||
styleLayers_, currentStyle_->drawBelow_);
|
||||
break;
|
||||
|
||||
// Subsequent layers are drawn after all style-defined layers
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
#include "custom_layer_dialog.hpp"
|
||||
#include "ui_custom_layer_dialog.h"
|
||||
|
||||
#include <re2/re2.h>
|
||||
#include <scwx/qt/settings/general_settings.hpp>
|
||||
#include <scwx/qt/util/maplibre.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
#include <scwx/qt/map/map_provider.hpp>
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace scwx::qt::ui
|
||||
|
|
@ -36,43 +37,26 @@ public:
|
|||
std::shared_ptr<QMapLibre::Map> map_;
|
||||
};
|
||||
|
||||
// TODO Duplicated form map_widget, Should probably be moved.
|
||||
static bool match_layer(const std::string& pattern, const std::string& layer)
|
||||
{
|
||||
// Perform case-insensitive matching
|
||||
const RE2 re {"(?i)" + pattern};
|
||||
if (re.ok())
|
||||
{
|
||||
return RE2::FullMatch(layer, re);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fall back to basic comparison if RE
|
||||
// doesn't compile
|
||||
return layer == pattern;
|
||||
}
|
||||
}
|
||||
|
||||
void CustomLayerDialogImpl::handle_mapChanged(QMapLibre::Map::MapChange change)
|
||||
{
|
||||
if (change == QMapLibre::Map::MapChange::MapChangeDidFinishLoadingStyle)
|
||||
{
|
||||
auto& generalSettings = settings::GeneralSettings::Instance();
|
||||
const std::string& customStyleDrawLayer =
|
||||
generalSettings.custom_style_draw_layer().GetValue();
|
||||
generalSettings.custom_style_draw_layer().GetStagedOrValue();
|
||||
|
||||
const QStringList layerIds = map_->layerIds();
|
||||
self_->ui->layerListWidget->clear();
|
||||
self_->ui->layerListWidget->addItems(layerIds);
|
||||
|
||||
for (int i = 0; i < self_->ui->layerListWidget->count(); i++)
|
||||
{
|
||||
auto* item = self_->ui->layerListWidget->item(i);
|
||||
std::string symbologyLayer = util::maplibre::FindMapSymbologyLayer(
|
||||
layerIds, {customStyleDrawLayer});
|
||||
|
||||
if (match_layer(customStyleDrawLayer, item->text().toStdString()))
|
||||
const auto& symbologyItems = self_->ui->layerListWidget->findItems(
|
||||
symbologyLayer.c_str(), Qt::MatchExactly);
|
||||
if (!symbologyItems.isEmpty())
|
||||
{
|
||||
self_->ui->layerListWidget->setCurrentItem(item);
|
||||
}
|
||||
self_->ui->layerListWidget->setCurrentItem(symbologyItems.first());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
#include <scwx/qt/util/maplibre.hpp>
|
||||
|
||||
#include <QMapLibre/Utils>
|
||||
#include <algorithm>
|
||||
#include <mbgl/util/constants.hpp>
|
||||
#include <re2/re2.h>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
|
|
@ -120,6 +122,44 @@ void SetMapStyleUrl(const std::shared_ptr<map::MapContext>& mapContext,
|
|||
}
|
||||
}
|
||||
|
||||
std::string FindMapSymbologyLayer(const QStringList& styleLayers,
|
||||
const std::vector<std::string>& drawBelow)
|
||||
{
|
||||
std::string before = "ferry";
|
||||
|
||||
for (const QString& qlayer : styleLayers)
|
||||
{
|
||||
const std::string layer = qlayer.toStdString();
|
||||
|
||||
// Draw below layers defined in map style
|
||||
auto it =
|
||||
std::ranges::find_if(drawBelow,
|
||||
[&layer](const std::string& styleLayer) -> bool
|
||||
{
|
||||
// Perform case-insensitive matching
|
||||
RE2 re {"(?i)" + styleLayer};
|
||||
if (re.ok())
|
||||
{
|
||||
return RE2::FullMatch(layer, re);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fall back to basic comparison if RE
|
||||
// doesn't compile
|
||||
return layer == styleLayer;
|
||||
}
|
||||
});
|
||||
|
||||
if (it != drawBelow.cend())
|
||||
{
|
||||
before = layer;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return before;
|
||||
}
|
||||
|
||||
} // namespace maplibre
|
||||
} // namespace util
|
||||
} // namespace qt
|
||||
|
|
|
|||
|
|
@ -37,6 +37,18 @@ glm::vec2 LatLongToScreenCoordinate(const QMapLibre::Coordinate& coordinate);
|
|||
void SetMapStyleUrl(const std::shared_ptr<map::MapContext>& mapContext,
|
||||
const std::string& url);
|
||||
|
||||
/**
|
||||
* @brief Find the first layer which should be drawn above the radar products
|
||||
*
|
||||
* @param [in] styleLayers The layers of the style
|
||||
* @param [in] drawBelow A list of RE2 compatible regex's describing the layers
|
||||
* to draw below
|
||||
*
|
||||
* @return The first layer to be drawn above the radar products
|
||||
*/
|
||||
std::string FindMapSymbologyLayer(const QStringList& styleLayers,
|
||||
const std::vector<std::string>& drawBelow);
|
||||
|
||||
} // namespace maplibre
|
||||
} // namespace util
|
||||
} // namespace qt
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue