summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-09-29 19:25:31 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-10-11 12:10:32 +0300
commit89f3270f722a1890ffe05f93fb6183e2d53fbad4 (patch)
tree2d6bf4729ae2ca5638ddb97ed1cfaba7fff47977
parentccef4be9959562bdb6cbb06dde79367109486b1c (diff)
downloadqtlocation-mapboxgl-89f3270f722a1890ffe05f93fb6183e2d53fbad4.tar.gz
[node] Added set{Bearing,Center} + updated -test-suite
This gives the ability to pan and/or rotate the map in a posterior step after initial render for testing purposes.
-rw-r--r--package.json2
-rw-r--r--platform/node/src/node_map.cpp42
-rw-r--r--platform/node/src/node_map.hpp2
-rw-r--r--platform/node/test/js/map.test.js2
4 files changed, 47 insertions, 1 deletions
diff --git a/package.json b/package.json
index b744ea6d55..f1281cf9fb 100644
--- a/package.json
+++ b/package.json
@@ -22,7 +22,7 @@
"express": "^4.11.1",
"mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#98a56d538b11fb331aa67a6d632d6ecd6821b007",
"mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#7f62a4fc9f21e619824d68abbc4b03cbc1685572",
- "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#694f0d0728f229d64d1639dc5ee7aff7f4b8ca41",
+ "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#0f6781a9fcd44d350ba8504060f74869c194cd4c",
"mkdirp": "^0.5.1",
"node-cmake": "^1.2.1",
"request": "^2.72.0",
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp
index 1fc9e987c7..4d4be5be66 100644
--- a/platform/node/src/node_map.cpp
+++ b/platform/node/src/node_map.cpp
@@ -61,6 +61,8 @@ void NodeMap::Init(v8::Local<v8::Object> target) {
Nan::SetPrototypeMethod(tpl, "setLayoutProperty", SetLayoutProperty);
Nan::SetPrototypeMethod(tpl, "setPaintProperty", SetPaintProperty);
Nan::SetPrototypeMethod(tpl, "setFilter", SetFilter);
+ Nan::SetPrototypeMethod(tpl, "setCenter", SetCenter);
+ Nan::SetPrototypeMethod(tpl, "setBearing", SetBearing);
Nan::SetPrototypeMethod(tpl, "dumpDebugLogs", DumpDebugLogs);
Nan::SetPrototypeMethod(tpl, "queryRenderedFeatures", QueryRenderedFeatures);
@@ -674,6 +676,46 @@ void NodeMap::SetFilter(const Nan::FunctionCallbackInfo<v8::Value>& info) {
layer->accept(SetFilterVisitor { filter });
}
+void NodeMap::SetCenter(const Nan::FunctionCallbackInfo<v8::Value>& info) {
+ auto nodeMap = Nan::ObjectWrap::Unwrap<NodeMap>(info.Holder());
+ if (!nodeMap->map) return Nan::ThrowError(releasedMessage());
+
+ if (info.Length() <= 0 || !info[0]->IsArray()) {
+ return Nan::ThrowTypeError("First argument must be an array");
+ }
+
+ auto center = info[0].As<v8::Array>();
+ double latitude = 0;
+ double longitude = 0;
+ if (center->Length() > 0) { longitude = Nan::Get(center, 0).ToLocalChecked()->NumberValue(); }
+ if (center->Length() > 1) { latitude = Nan::Get(center, 1).ToLocalChecked()->NumberValue(); }
+
+ try {
+ nodeMap->map->setLatLng(mbgl::LatLng { latitude, longitude });
+ } catch (const std::exception &ex) {
+ return Nan::ThrowError(ex.what());
+ }
+
+ info.GetReturnValue().SetUndefined();
+}
+
+void NodeMap::SetBearing(const Nan::FunctionCallbackInfo<v8::Value>& info) {
+ auto nodeMap = Nan::ObjectWrap::Unwrap<NodeMap>(info.Holder());
+ if (!nodeMap->map) return Nan::ThrowError(releasedMessage());
+
+ if (info.Length() <= 0 || !info[0]->IsNumber()) {
+ return Nan::ThrowTypeError("First argument must be a number");
+ }
+
+ try {
+ nodeMap->map->setBearing(info[0]->NumberValue());
+ } catch (const std::exception &ex) {
+ return Nan::ThrowError(ex.what());
+ }
+
+ info.GetReturnValue().SetUndefined();
+}
+
void NodeMap::DumpDebugLogs(const Nan::FunctionCallbackInfo<v8::Value>& info) {
auto nodeMap = Nan::ObjectWrap::Unwrap<NodeMap>(info.Holder());
if (!nodeMap->map) return Nan::ThrowError(releasedMessage());
diff --git a/platform/node/src/node_map.hpp b/platform/node/src/node_map.hpp
index 5f6176ba75..c0b025c369 100644
--- a/platform/node/src/node_map.hpp
+++ b/platform/node/src/node_map.hpp
@@ -37,6 +37,8 @@ public:
static void SetLayoutProperty(const Nan::FunctionCallbackInfo<v8::Value>&);
static void SetPaintProperty(const Nan::FunctionCallbackInfo<v8::Value>&);
static void SetFilter(const Nan::FunctionCallbackInfo<v8::Value>&);
+ static void SetCenter(const Nan::FunctionCallbackInfo<v8::Value>&);
+ static void SetBearing(const Nan::FunctionCallbackInfo<v8::Value>&);
static void DumpDebugLogs(const Nan::FunctionCallbackInfo<v8::Value>&);
static void QueryRenderedFeatures(const Nan::FunctionCallbackInfo<v8::Value>&);
diff --git a/platform/node/test/js/map.test.js b/platform/node/test/js/map.test.js
index 9300cac4e1..7321572637 100644
--- a/platform/node/test/js/map.test.js
+++ b/platform/node/test/js/map.test.js
@@ -114,6 +114,8 @@ test('Map', function(t) {
'setLayoutProperty',
'setPaintProperty',
'setFilter',
+ 'setCenter',
+ 'setBearing',
'dumpDebugLogs',
'queryRenderedFeatures'
]);