[core][node] Serialize formatted expression's text-color option
This enables proper round-tripping for serialized format expression.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/optional.hpp>
|
||||
#include <mbgl/util/feature.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
@@ -39,6 +40,7 @@ public:
|
||||
static optional<Color> parse(const std::string&);
|
||||
std::string stringify() const;
|
||||
std::array<double, 4> toArray() const;
|
||||
mbgl::Value toObject() const;
|
||||
};
|
||||
|
||||
inline bool operator==(const Color& colorA, const Color& colorB) {
|
||||
|
||||
@@ -192,6 +192,11 @@ struct ToValue {
|
||||
} else {
|
||||
serializedSection.emplace("fontStack", mbgl::NullValue());
|
||||
}
|
||||
if (section.textColor) {
|
||||
serializedSection.emplace("textColor", section.textColor->toObject());
|
||||
} else {
|
||||
serializedSection.emplace("textColor", mbgl::NullValue());
|
||||
}
|
||||
sections.emplace_back(serializedSection);
|
||||
}
|
||||
serialized.emplace("sections", sections);
|
||||
|
||||
@@ -44,4 +44,11 @@ std::array<double, 4> Color::toArray() const {
|
||||
}
|
||||
}
|
||||
|
||||
mbgl::Value Color::toObject() const {
|
||||
return std::unordered_map<std::string, mbgl::Value>{{"r", double(r)},
|
||||
{"g", double(g)},
|
||||
{"b", double(b)},
|
||||
{"a", double(a)}};
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
Reference in New Issue
Block a user