summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2019-08-15 17:18:42 +0300
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2019-08-15 18:25:10 +0300
commit148d65bcede0ee167f8bc1bd162de5de3c397b4e (patch)
tree4904289bc5bc3963c0705c3072a872a42a8b49ff
parent2f9a544f9bee077bee004ebb67b2a81f7bafac07 (diff)
downloadqtlocation-mapboxgl-148d65bcede0ee167f8bc1bd162de5de3c397b4e.tar.gz
[core][node] Serialize formatted expression's text-color option
This enables proper round-tripping for serialized format expression.
-rw-r--r--include/mbgl/util/color.hpp2
-rw-r--r--platform/node/src/node_expression.cpp5
-rw-r--r--src/mbgl/util/color.cpp7
3 files changed, 14 insertions, 0 deletions
diff --git a/include/mbgl/util/color.hpp b/include/mbgl/util/color.hpp
index 01a4c8f292..1ff44ce085 100644
--- a/include/mbgl/util/color.hpp
+++ b/include/mbgl/util/color.hpp
@@ -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) {
diff --git a/platform/node/src/node_expression.cpp b/platform/node/src/node_expression.cpp
index 041f60d029..e1c3ba0c39 100644
--- a/platform/node/src/node_expression.cpp
+++ b/platform/node/src/node_expression.cpp
@@ -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);
diff --git a/src/mbgl/util/color.cpp b/src/mbgl/util/color.cpp
index b8574174f1..4c2814cf14 100644
--- a/src/mbgl/util/color.cpp
+++ b/src/mbgl/util/color.cpp
@@ -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