summaryrefslogtreecommitdiff
path: root/src/mbgl/style/expression/formatted.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/style/expression/formatted.cpp')
-rw-r--r--src/mbgl/style/expression/formatted.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/mbgl/style/expression/formatted.cpp b/src/mbgl/style/expression/formatted.cpp
index 5d45806ecb..4591a50ed1 100644
--- a/src/mbgl/style/expression/formatted.cpp
+++ b/src/mbgl/style/expression/formatted.cpp
@@ -35,6 +35,35 @@ std::string Formatted::toString() const {
return result;
}
+mbgl::Value Formatted::toObject() const {
+ mapbox::base::ValueObject result;
+ mapbox::base::ValueArray sectionValues;
+ sectionValues.reserve(sections.size());
+ for (const auto& section : sections) {
+ mapbox::base::ValueObject serializedSection;
+ serializedSection.emplace("text", section.text);
+ if (section.fontScale) {
+ serializedSection.emplace("scale", *section.fontScale);
+ } else {
+ serializedSection.emplace("scale", NullValue());
+ }
+ if (section.fontStack) {
+ std::string fontStackString;
+ serializedSection.emplace("fontStack", fontStackToString(*section.fontStack));
+ } else {
+ serializedSection.emplace("fontStack", NullValue());
+ }
+ if (section.textColor) {
+ serializedSection.emplace("textColor", section.textColor->toObject());
+ } else {
+ serializedSection.emplace("textColor", NullValue());
+ }
+ sectionValues.emplace_back(serializedSection);
+ }
+ result.emplace("sections", std::move(sectionValues));
+ return result;
+}
+
} // namespace expression
namespace conversion {