From ead4ca599aa13520a9419130735e690f70d73357 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Tue, 20 Oct 2015 17:09:17 -0700 Subject: [PATCH] [core] Fix transition to default style when no classes are applied Some property transitions were being set to their fallback values when no classes are being used. This issue is particularly perceived when the default transition duration is not zero (animated transitions). --- src/mbgl/style/style_layer.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/mbgl/style/style_layer.cpp b/src/mbgl/style/style_layer.cpp index aea89fe58..8ab5b3e50 100644 --- a/src/mbgl/style/style_layer.cpp +++ b/src/mbgl/style/style_layer.cpp @@ -39,6 +39,12 @@ void StyleLayer::setClasses(const std::vector &class_names, const T // Stores all keys that we have already added transitions for. std::set already_applied; + // We only apply the default style values if there are no classes set. + if (class_names.empty()) { + applyClassProperties(ClassID::Default, already_applied, now, defaultTransition); + return; + } + // Reverse iterate through all class names and apply them last to first. for (auto it = class_names.rbegin(); it != class_names.rend(); ++it) { const std::string &class_name = *it; @@ -62,14 +68,16 @@ void StyleLayer::setClasses(const std::vector &class_names, const T AppliedClassPropertyValues &appliedProperties = property_pair.second; // Make sure that we don't do double transitions to the fallback value. - if (appliedProperties.mostRecent() != ClassID::Fallback) { - // This property key hasn't been set by a previous class, so we need to add a transition - // to the fallback value for that key. - const TimePoint begin = now + defaultTransition.delay; - const TimePoint end = begin + defaultTransition.duration; - const PropertyValue &value = PropertyFallbackValue::Get(key); - appliedProperties.add(ClassID::Fallback, begin, end, value); + if (appliedProperties.mostRecent() == ClassID::Fallback) { + continue; } + + // This property key hasn't been set by a previous class, so we need to add a transition + // to the fallback value for that key. + const TimePoint begin = now + defaultTransition.delay; + const TimePoint end = begin + defaultTransition.duration; + const PropertyValue &value = PropertyFallbackValue::Get(key); + appliedProperties.add(ClassID::Fallback, begin, end, value); } }