Skip to content

Commit

Permalink
styles: Fix non-working geometry-name based styles (cause of lacking …
Browse files Browse the repository at this point in the history
…geometry name for self-contained geos).
  • Loading branch information
MisterGC committed Jan 21, 2025
1 parent 54717a3 commit 49f52e4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions libs/core/include/erdblick/visualization.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class FeatureLayerVisualization
*/
void addGeometry(
mapget::SelfContainedGeometry const& geom,
std::optional<std::string_view> geometryName,
std::string_view id,
FeatureStyleRule const& rule,
std::string const& mapLayerStyleRuleId,
Expand Down
9 changes: 8 additions & 1 deletion libs/core/src/rule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,15 @@ bool FeatureStyleRule::supports(const mapget::GeomType& g, std::optional<std::st
return false;
}

// Ensure that the geometry name is supported by the rule.
// Ensure that the geometry name matches the rule's requirements
if (geometryName_) {

// Empty regex: explicitly match features without a geometry name
// TODO: Check if there is any recognizable performance impact
if (std::regex_match("", *geometryName_)) {
return !geometryName || geometryName->empty();
}

if (!geometryName) {
return false;
}
Expand Down
14 changes: 9 additions & 5 deletions libs/core/src/visualization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,19 @@ void FeatureLayerVisualization::addGeometry(
if (!geom) {
return;
}
addGeometry(geom->toSelfContained(), id, rule, mapLayerStyleRuleId, evalFun, offset);
addGeometry(geom->toSelfContained(), geom->name(), id, rule, mapLayerStyleRuleId, evalFun, offset);
}

void FeatureLayerVisualization::addGeometry(
SelfContainedGeometry const& geom,
std::optional<std::string_view> geometryName,
std::string_view id,
FeatureStyleRule const& rule,
std::string const& mapLayerStyleRuleId,
BoundEvalFun& evalFun,
glm::dvec3 const& offset)
{
if (!rule.supports(geom.geomType_))
if (!rule.supports(geom.geomType_, geometryName))
return;

// Combine the ID with the mapTileKey to create an
Expand Down Expand Up @@ -772,6 +773,7 @@ void FeatureLayerVisualization::addAttribute(
{
addGeometry(
validity.computeGeometry(feature->geomOrNull()),
std::nullopt,
id,
rule,
mapLayerStyleRuleId,
Expand All @@ -781,8 +783,10 @@ void FeatureLayerVisualization::addAttribute(
});
}
else {
auto geom = feature->firstGeometry();
addGeometry(
feature->firstGeometry(),
geom,
std::nullopt,
id,
rule,
mapLayerStyleRuleId,
Expand Down Expand Up @@ -1004,7 +1008,7 @@ void RecursiveRelationVisualizationState::render(
if (auto sourceRule = rule_.relationSourceStyle()) {
for (auto const& sourceGeom : sourceGeoms) {
if (sourceGeom.points_.empty()) continue;
visu_.addGeometry(sourceGeom, UnselectableId, *sourceRule, "", boundEvalFun, offsetBase * sourceRule->offset());
visu_.addGeometry(sourceGeom, std::nullopt, UnselectableId, *sourceRule, "", boundEvalFun, offsetBase * sourceRule->offset());
}
}
}
Expand All @@ -1014,7 +1018,7 @@ void RecursiveRelationVisualizationState::render(
if (auto targetRule = rule_.relationTargetStyle()) {
for (auto const& targetGeom : targetGeoms) {
if (targetGeom.points_.empty()) continue;
visu_.addGeometry(targetGeom, UnselectableId, *targetRule, "", boundEvalFun, offsetBase * targetRule->offset());
visu_.addGeometry(targetGeom, std::nullopt, UnselectableId, *targetRule, "", boundEvalFun, offsetBase * targetRule->offset());
}
}
}
Expand Down

0 comments on commit 49f52e4

Please sign in to comment.