diff options
author | Anand Thakker <github@anandthakker.net> | 2017-10-18 15:32:57 -0400 |
---|---|---|
committer | Anand Thakker <github@anandthakker.net> | 2017-10-25 11:53:47 -0400 |
commit | 7a5101a8f669b39c78db98f73c2b4e0ce53c4257 (patch) | |
tree | fecb58d3e5c19cf80118db65b59652b90702cdf0 | |
parent | 39e0cb6eab8efe17be777db033b6300021fc4174 (diff) | |
download | qtlocation-mapboxgl-7a5101a8f669b39c78db98f73c2b4e0ce53c4257.tar.gz |
Handle `heatmapDensity` expression evaluation parameter in node bindings
-rw-r--r-- | include/mbgl/style/expression/expression.hpp | 5 | ||||
-rw-r--r-- | platform/node/src/node_expression.cpp | 14 | ||||
-rw-r--r-- | platform/node/test/expression.test.js | 5 | ||||
-rw-r--r-- | src/mbgl/style/function/expression.cpp | 4 |
4 files changed, 17 insertions, 11 deletions
diff --git a/include/mbgl/style/expression/expression.hpp b/include/mbgl/style/expression/expression.hpp index b57af0906b..6c0f11a675 100644 --- a/include/mbgl/style/expression/expression.hpp +++ b/include/mbgl/style/expression/expression.hpp @@ -27,6 +27,9 @@ struct EvaluationParameters { EvaluationParameters(float zoom_, GeometryTileFeature const * feature_) : zoom(zoom_), feature(feature_) {} + EvaluationParameters(optional<float> zoom_, GeometryTileFeature const * feature_, optional<double> heatmapDensity_) : + zoom(std::move(zoom_)), feature(feature_), heatmapDensity(std::move(heatmapDensity_)) + {} optional<float> zoom; GeometryTileFeature const * feature; @@ -114,9 +117,9 @@ public: bool isFeatureConstant() const; bool isZoomConstant() const; - EvaluationResult evaluate(float z, const Feature& feature) const; type::Type getType() const { return type; }; + EvaluationResult evaluate(optional<float> zoom, const Feature& feature, optional<double> heatmapDensity) const; private: type::Type type; }; diff --git a/platform/node/src/node_expression.cpp b/platform/node/src/node_expression.cpp index e75478320c..38a444f203 100644 --- a/platform/node/src/node_expression.cpp +++ b/platform/node/src/node_expression.cpp @@ -168,11 +168,17 @@ void NodeExpression::Evaluate(const Nan::FunctionCallbackInfo<v8::Value>& info) NodeExpression* nodeExpr = ObjectWrap::Unwrap<NodeExpression>(info.Holder()); const std::unique_ptr<Expression>& expression = nodeExpr->expression; - if (info.Length() < 2) { - return Nan::ThrowTypeError("Requires arguments zoom and feature arguments."); + if (info.Length() < 2 || !info[0]->IsObject()) { + return Nan::ThrowTypeError("Requires globals and feature arguments."); } - float zoom = info[0]->NumberValue(); + mbgl::optional<float> zoom; + v8::Local<v8::Value> v8zoom = Nan::Get(info[0]->ToObject(), Nan::New("zoom").ToLocalChecked()).ToLocalChecked(); + if (v8zoom->IsNumber()) zoom = v8zoom->NumberValue(); + + mbgl::optional<double> heatmapDensity; + v8::Local<v8::Value> v8heatmapDensity = Nan::Get(info[0]->ToObject(), Nan::New("heatmapDensity").ToLocalChecked()).ToLocalChecked(); + if (v8heatmapDensity->IsNumber()) heatmapDensity = v8heatmapDensity->NumberValue(); Nan::JSON NanJSON; conversion::Error conversionError; @@ -184,7 +190,7 @@ void NodeExpression::Evaluate(const Nan::FunctionCallbackInfo<v8::Value>& info) try { mapbox::geojson::feature feature = geoJSON->get<mapbox::geojson::feature>(); - auto result = expression->evaluate(zoom, feature); + auto result = expression->evaluate(zoom, feature, heatmapDensity); if (result) { info.GetReturnValue().Set(toJS(*result)); } else { diff --git a/platform/node/test/expression.test.js b/platform/node/test/expression.test.js index b54dd342e5..6ffea28d40 100644 --- a/platform/node/test/expression.test.js +++ b/platform/node/test/expression.test.js @@ -47,16 +47,13 @@ suite.run('native', {tests: tests}, (fixture) => { const evaluate = fixture.inputs || []; const evaluateResults = []; for (const input of evaluate) { - const zoom = typeof input[0].zoom === 'number' ? - input[0].zoom : -1; - const feature = Object.assign({ type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [0, 0] } }, input[1]) - const output = expression.evaluate(zoom, feature); + const output = expression.evaluate(input[0], feature); evaluateResults.push(output); } diff --git a/src/mbgl/style/function/expression.cpp b/src/mbgl/style/function/expression.cpp index ccbc59a5f0..e9cc0b0e1c 100644 --- a/src/mbgl/style/function/expression.cpp +++ b/src/mbgl/style/function/expression.cpp @@ -59,9 +59,9 @@ bool Expression::isZoomConstant() const { return zoomConstant; } -EvaluationResult Expression::evaluate(float z, const Feature& feature) const { +EvaluationResult Expression::evaluate(optional<float> zoom, const Feature& feature, optional<double> heatmapDensity) const { GeoJSONFeature f(feature); - return this->evaluate(EvaluationParameters(z, &f)); + return this->evaluate(EvaluationParameters(zoom, &f, heatmapDensity)); } } // namespace expression |