From f3146e43cd19bdf85957d6d62132ac7c31eacc50 Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Thu, 26 Sep 2019 17:53:49 +0300 Subject: [core] ValueFactory for `expression::formatted`, other improvements --- src/mbgl/style/expression/formatted.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/mbgl/style/expression') 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 { -- cgit v1.2.1