From 02a1a311364044820f3da096d8a6f31c8e7fc647 Mon Sep 17 00:00:00 2001 From: Alexander Shalamov Date: Tue, 25 Feb 2020 11:02:07 +0200 Subject: [core] Fix TransitionOptions serialization --- include/mbgl/style/conversion_impl.hpp | 11 +++-------- include/mbgl/style/transition_options.hpp | 13 +++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'include/mbgl/style') diff --git a/include/mbgl/style/conversion_impl.hpp b/include/mbgl/style/conversion_impl.hpp index 30aa132ce0..9606c7b58d 100644 --- a/include/mbgl/style/conversion_impl.hpp +++ b/include/mbgl/style/conversion_impl.hpp @@ -306,14 +306,7 @@ struct ValueFactory { template <> struct ValueFactory { - static Value make(const TransitionOptions& value) { - return mapbox::base::ValueArray{ - {std::chrono::duration_cast(value.duration.value_or(mbgl::Duration::zero())) - .count(), - std::chrono::duration_cast(value.delay.value_or(mbgl::Duration::zero())) - .count(), - value.enablePlacementTransitions}}; - } + static Value make(const TransitionOptions& value) { return value.serialize(); } }; template <> @@ -370,10 +363,12 @@ StyleProperty makeStyleProperty(const PropertyValue& value) { } inline StyleProperty makeStyleProperty(const TransitionOptions& value) { + if (!value.isDefined()) return {}; return {makeValue(value), StyleProperty::Kind::Transition}; } inline StyleProperty makeStyleProperty(const ColorRampPropertyValue& value) { + if (value.isUndefined()) return {}; return {makeValue(value), StyleProperty::Kind::Expression}; } diff --git a/include/mbgl/style/transition_options.hpp b/include/mbgl/style/transition_options.hpp index 9cb5c1f575..69479afaad 100644 --- a/include/mbgl/style/transition_options.hpp +++ b/include/mbgl/style/transition_options.hpp @@ -3,6 +3,8 @@ #include #include +#include + namespace mbgl { namespace style { @@ -30,6 +32,17 @@ public: bool isDefined() const { return duration || delay; } + + mapbox::base::Value serialize() const { + mapbox::base::ValueObject result; + if (duration) { + result.emplace("duration", std::chrono::duration_cast(*duration).count()); + } + if (delay) { + result.emplace("delay", std::chrono::duration_cast(*delay).count()); + } + return result; + } }; } // namespace style -- cgit v1.2.1