Move code from map_widget and custom_layer_dialog to util/maplibre

This commit is contained in:
AdenKoperczak 2025-03-25 10:22:12 -04:00
parent fee00b737a
commit a7c6be2bab
4 changed files with 64 additions and 66 deletions

View file

@ -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

View file

@ -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