diff options
author | Chris Loer <chris.loer@gmail.com> | 2018-10-02 17:03:50 -0700 |
---|---|---|
committer | Chris Loer <chris.loer@mapbox.com> | 2018-10-15 13:15:46 -0700 |
commit | ce76bde13d0f4381ee861f81daf636defaff0bc5 (patch) | |
tree | e37d93d14fc64620069bac5488bae871af2fa431 /platform/node/src | |
parent | bc718257748f1ad87658e85f8c31b574afca57a9 (diff) | |
download | qtlocation-mapboxgl-ce76bde13d0f4381ee861f81daf636defaff0bc5.tar.gz |
[core] Initial implementation of 'format' expression
Diffstat (limited to 'platform/node/src')
-rw-r--r-- | platform/node/src/node_expression.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/platform/node/src/node_expression.cpp b/platform/node/src/node_expression.cpp index c0b512a899..4f1e392505 100644 --- a/platform/node/src/node_expression.cpp +++ b/platform/node/src/node_expression.cpp @@ -37,10 +37,11 @@ type::Type parseType(v8::Local<v8::Object> type) { static std::unordered_map<std::string, type::Type> types = { {"string", type::String}, {"number", type::Number}, - {"noolean", type::Boolean}, + {"boolean", type::Boolean}, {"object", type::Object}, {"color", type::Color}, - {"value", type::Value} + {"value", type::Value}, + {"formatted", type::Formatted} }; v8::Local<v8::Value> v8kind = Nan::Get(type, Nan::New("kind").ToLocalChecked()).ToLocalChecked(); @@ -151,6 +152,33 @@ struct ToValue { Nan::EscapableHandleScope scope; return scope.Escape(Nan::Null()); } + + v8::Local<v8::Value> operator()(const Formatted& formatted) { + // This mimics the internal structure of the Formatted class in formatted.js + // A better approach might be to use the explicit serialized form + // both here and on the JS side? e.g. toJS(fromExpressionValue<mbgl::Value>(formatted)) + std::unordered_map<std::string, mbgl::Value> serialized; + std::vector<mbgl::Value> sections; + for (const auto& section : formatted.sections) { + std::unordered_map<std::string, mbgl::Value> serializedSection; + serializedSection.emplace("text", section.text); + if (section.fontScale) { + serializedSection.emplace("scale", *section.fontScale); + } else { + serializedSection.emplace("scale", mbgl::NullValue()); + } + if (section.fontStack) { + std::string fontStackString; + serializedSection.emplace("fontStack", mbgl::fontStackToString(*section.fontStack)); + } else { + serializedSection.emplace("fontStack", mbgl::NullValue()); + } + sections.push_back(serializedSection); + } + serialized.emplace("sections", sections); + + return toJS(serialized); + } v8::Local<v8::Value> operator()(const mbgl::Color& color) { return operator()(std::vector<Value> { |