summaryrefslogtreecommitdiff
path: root/platform/node
diff options
context:
space:
mode:
authorAsheem Mamoowala <asheemm@gmail.com>2017-02-21 18:34:45 -0800
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2017-03-04 15:42:07 -0800
commit60d10dd27df38ac4e97214d1cd514198c381695c (patch)
treef4ce0ecbf3a7eeb5c19f994d02152fc624b458d9 /platform/node
parentac4e13416a36905b35401fc1a982c680ca37a3d0 (diff)
downloadqtlocation-mapboxgl-60d10dd27df38ac4e97214d1cd514198c381695c.tar.gz
[core] Add support for queryRenderedFeatures filter
Diffstat (limited to 'platform/node')
-rw-r--r--platform/node/src/node_map.cpp41
-rw-r--r--platform/node/test/suite_implementation.js2
2 files changed, 40 insertions, 3 deletions
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp
index 66cdb3eda7..174db7d737 100644
--- a/platform/node/src/node_map.cpp
+++ b/platform/node/src/node_map.cpp
@@ -10,6 +10,7 @@
#include <mbgl/style/conversion/layer.hpp>
#include <mbgl/style/conversion/filter.hpp>
#include <mbgl/sprite/sprite_image.cpp>
+#include <mbgl/map/query.hpp>
#include <unistd.h>
@@ -866,6 +867,9 @@ void NodeMap::DumpDebugLogs(const Nan::FunctionCallbackInfo<v8::Value>& info) {
}
void NodeMap::QueryRenderedFeatures(const Nan::FunctionCallbackInfo<v8::Value>& info) {
+ using namespace mbgl::style;
+ using namespace mbgl::style::conversion;
+
auto nodeMap = Nan::ObjectWrap::Unwrap<NodeMap>(info.Holder());
if (!nodeMap->map) return Nan::ThrowError(releasedMessage());
@@ -878,6 +882,39 @@ void NodeMap::QueryRenderedFeatures(const Nan::FunctionCallbackInfo<v8::Value>&
return Nan::ThrowTypeError("First argument must have two components");
}
+ mbgl::QueryOptions queryOptions;
+ if (!info[1]->IsNull() && !info[1]->IsUndefined()) {
+ if (!info[1]->IsObject()) {
+ return Nan::ThrowTypeError("options argument must be an object");
+ }
+
+ auto options = Nan::To<v8::Object>(info[1]).ToLocalChecked();
+
+ //Check if layers is set. If provided, it must be an array of strings
+ if (Nan::Has(options, Nan::New("layers").ToLocalChecked()).FromJust()) {
+ auto layersOption = Nan::Get(options, Nan::New("layers").ToLocalChecked()).ToLocalChecked();
+ if (!layersOption->IsArray()) {
+ return Nan::ThrowTypeError("Requires options.layers property to be an array");
+ }
+ auto layers = layersOption.As<v8::Array>();
+ std::vector<std::string> layersVec;
+ for (uint32_t i=0; i < layers->Length(); i++) {
+ layersVec.push_back(*Nan::Utf8String(Nan::Get(layers,i).ToLocalChecked()));
+ }
+ queryOptions.layerIDs = layersVec;
+ }
+
+ //Check if filter is provided. If set it must be a valid Filter object
+ if (Nan::Has(options, Nan::New("filter").ToLocalChecked()).FromJust()) {
+ auto filterOption = Nan::Get(options, Nan::New("filter").ToLocalChecked()).ToLocalChecked();
+ Result<Filter> converted = convert<Filter>(filterOption);
+ if (!converted) {
+ return Nan::ThrowTypeError(converted.error().message.c_str());
+ }
+ queryOptions.filter = std::move(*converted);
+ }
+ }
+
try {
std::vector<mbgl::Feature> result;
@@ -894,13 +931,13 @@ void NodeMap::QueryRenderedFeatures(const Nan::FunctionCallbackInfo<v8::Value>&
Nan::Get(pos1, 0).ToLocalChecked()->NumberValue(),
Nan::Get(pos1, 1).ToLocalChecked()->NumberValue()
}
- });
+ }, queryOptions);
} else {
result = nodeMap->map->queryRenderedFeatures(mbgl::ScreenCoordinate {
Nan::Get(posOrBox, 0).ToLocalChecked()->NumberValue(),
Nan::Get(posOrBox, 1).ToLocalChecked()->NumberValue()
- });
+ }, queryOptions);
}
auto array = Nan::New<v8::Array>();
diff --git a/platform/node/test/suite_implementation.js b/platform/node/test/suite_implementation.js
index 6648757a98..ef97652893 100644
--- a/platform/node/test/suite_implementation.js
+++ b/platform/node/test/suite_implementation.js
@@ -49,7 +49,7 @@ module.exports = function (style, options, callback) {
applyOperations(options.operations, function() {
map.render(options, function (err, pixels) {
var results = options.queryGeometry ?
- map.queryRenderedFeatures(options.queryGeometry) :
+ map.queryRenderedFeatures(options.queryGeometry, options.queryOptions || {}) :
[];
map.release();
if (timedOut) return;