diff --git a/include/llmr/style/applied_class_properties.hpp b/include/llmr/style/applied_class_properties.hpp index a2855d8e3..20edadc0a 100644 --- a/include/llmr/style/applied_class_properties.hpp +++ b/include/llmr/style/applied_class_properties.hpp @@ -31,6 +31,7 @@ public: void add(ClassID class_id, timestamp begin, timestamp end, const PropertyValue &value); bool hasTransitions() const; void cleanup(timestamp now); + bool empty() const; }; } diff --git a/src/style/applied_class_properties.cpp b/src/style/applied_class_properties.cpp index f0751b227..dfe419ebd 100644 --- a/src/style/applied_class_properties.cpp +++ b/src/style/applied_class_properties.cpp @@ -24,13 +24,29 @@ bool AppliedClassProperties::hasTransitions() const { // Erase all items in the property list that are before a completed transition. // Then, if the only remaining property is a Fallback value, remove it too. void AppliedClassProperties::cleanup(timestamp now) { + // Iterate backwards, but without using the rbegin/rend interface since we need forward + // iterators to use .erase(). for (auto it = properties.end(), begin = properties.begin(); it != begin;) { // If the property is finished, break iteration and delete all remaining items. if ((--it)->end <= now) { + // Removes all items that precede the current iterator, but *not* the element currently + // pointed to by the iterator. This preserves the last completed transition as the + // first element in the property list. properties.erase(begin, it); + + // Also erase the pivot element if it's a fallback value. This means we can remove the + // entire applied properties object as well, because we already have the fallback + // value set as the default. + if (it->name == ClassID::Fallback) { + properties.erase(it); + } break; } } } +bool AppliedClassProperties::empty() const { + return properties.empty(); +} + } \ No newline at end of file diff --git a/src/style/class_properties.cpp b/src/style/class_properties.cpp index 0dfe1603c..e326f5656 100644 --- a/src/style/class_properties.cpp +++ b/src/style/class_properties.cpp @@ -5,7 +5,6 @@ namespace llmr { const PropertyTransition &ClassProperties::getTransition(PropertyKey key, const PropertyTransition &defaultTransition) const { auto it = transitions.find(key); if (it == transitions.end()) { - fprintf(stderr, "using default transition: %d/%d\n", defaultTransition.duration, defaultTransition.delay); return defaultTransition; } else { return it->second; diff --git a/src/style/style_layer.cpp b/src/style/style_layer.cpp index e47ec6c43..2618fc63b 100644 --- a/src/style/style_layer.cpp +++ b/src/style/style_layer.cpp @@ -290,8 +290,18 @@ bool StyleLayer::hasTransitions() const { void StyleLayer::cleanupAppliedStyleProperties(timestamp now) { - for (std::pair &pair : appliedStyle) { - pair.second.cleanup(now); + auto it = appliedStyle.begin(); + const auto end = appliedStyle.end(); + while (it != end) { + AppliedClassProperties &properties = it->second; + properties.cleanup(now); + + // If the current properties object is empty, remove it from the map entirely. + if (properties.empty()) { + appliedStyle.erase(it++); + } else { + ++it; + } } }