[core] Fix Color serialization
This commit is contained in:
@@ -318,7 +318,7 @@ struct ValueFactory<TransitionOptions> {
|
||||
|
||||
template <>
|
||||
struct ValueFactory<Color> {
|
||||
static Value make(const Color& color) { return color.toObject(); }
|
||||
static Value make(const Color& color) { return color.serialize(); }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@@ -358,11 +358,14 @@ Value makeValue(T&& arg) {
|
||||
template <typename T>
|
||||
StyleProperty makeStyleProperty(const PropertyValue<T>& value) {
|
||||
return value.match([](const Undefined&) -> StyleProperty { return {}; },
|
||||
[](const T& t) -> StyleProperty {
|
||||
return {makeValue(t), StyleProperty::Kind::Constant};
|
||||
[](const Color& c) -> StyleProperty {
|
||||
return {makeValue(c), StyleProperty::Kind::Expression};
|
||||
},
|
||||
[](const PropertyExpression<T>& fn) -> StyleProperty {
|
||||
return {fn.getExpression().serialize(), StyleProperty::Kind::Expression};
|
||||
},
|
||||
[](const auto& t) -> StyleProperty {
|
||||
return {makeValue(t), StyleProperty::Kind::Constant};
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
std::string stringify() const;
|
||||
std::array<double, 4> toArray() const;
|
||||
mbgl::Value toObject() const;
|
||||
mbgl::Value serialize() const;
|
||||
};
|
||||
|
||||
inline bool operator==(const Color& colorA, const Color& colorB) {
|
||||
|
||||
@@ -126,16 +126,7 @@ Value ValueConverter<mbgl::Value>::toExpressionValue(const mbgl::Value& value) {
|
||||
|
||||
mbgl::Value ValueConverter<mbgl::Value>::fromExpressionValue(const Value& value) {
|
||||
return value.match(
|
||||
[&](const Color& color) -> mbgl::Value {
|
||||
std::array<double, 4> array = color.toArray();
|
||||
return std::vector<mbgl::Value>{
|
||||
std::string("rgba"),
|
||||
array[0],
|
||||
array[1],
|
||||
array[2],
|
||||
array[3],
|
||||
};
|
||||
},
|
||||
[&](const Color& color) -> mbgl::Value { return color.serialize(); },
|
||||
[&](const Collator&) -> mbgl::Value {
|
||||
// fromExpressionValue can't be used for Collator values,
|
||||
// because they have no meaningful representation as an mbgl::Value
|
||||
|
||||
@@ -48,4 +48,15 @@ mbgl::Value Color::toObject() const {
|
||||
return mapbox::base::ValueObject{{"r", double(r)}, {"g", double(g)}, {"b", double(b)}, {"a", double(a)}};
|
||||
}
|
||||
|
||||
mbgl::Value Color::serialize() const {
|
||||
std::array<double, 4> array = toArray();
|
||||
return std::vector<mbgl::Value>{
|
||||
std::string("rgba"),
|
||||
array[0],
|
||||
array[1],
|
||||
array[2],
|
||||
array[3],
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
Reference in New Issue
Block a user