summaryrefslogtreecommitdiff
path: root/platform/node
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2018-01-24 12:46:49 -0800
committerKonstantin Käfer <mail@kkaefer.com>2018-01-24 16:35:47 -0800
commitd511f74ce45b8d18c376e7c3d806819cbe438627 (patch)
tree6e95e0dd93d6cbe6a9d3ca6593891642fef91eda /platform/node
parent2502a3ab2bf793dcb3a41deb5c93290b3c6ce5fd (diff)
downloadqtlocation-mapboxgl-d511f74ce45b8d18c376e7c3d806819cbe438627.tar.gz
[node] add setLight support
Diffstat (limited to 'platform/node')
-rw-r--r--platform/node/src/node_map.cpp51
-rw-r--r--platform/node/src/node_map.hpp1
-rw-r--r--platform/node/test/js/map.test.js1
-rw-r--r--platform/node/test/suite_implementation.js3
4 files changed, 50 insertions, 6 deletions
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp
index 5dd5e6b490..3e66aaa789 100644
--- a/platform/node/src/node_map.cpp
+++ b/platform/node/src/node_map.cpp
@@ -9,6 +9,7 @@
#include <mbgl/style/conversion/source.hpp>
#include <mbgl/style/conversion/layer.hpp>
#include <mbgl/style/conversion/filter.hpp>
+#include <mbgl/style/conversion/light.hpp>
#include <mbgl/style/layers/background_layer.hpp>
#include <mbgl/style/layers/circle_layer.hpp>
@@ -21,6 +22,7 @@
#include <mbgl/style/style.hpp>
#include <mbgl/style/image.hpp>
+#include <mbgl/style/light.hpp>
#include <mbgl/map/map_observer.hpp>
#include <mbgl/util/premultiply.hpp>
@@ -31,6 +33,7 @@ namespace node_mbgl {
struct NodeMap::RenderOptions {
double zoom = 0;
double bearing = 0;
+ mbgl::style::Light light;
double pitch = 0;
double latitude = 0;
double longitude = 0;
@@ -77,6 +80,7 @@ void NodeMap::Init(v8::Local<v8::Object> target) {
Nan::SetPrototypeMethod(tpl, "setZoom", SetZoom);
Nan::SetPrototypeMethod(tpl, "setBearing", SetBearing);
Nan::SetPrototypeMethod(tpl, "setPitch", SetPitch);
+ Nan::SetPrototypeMethod(tpl, "setLight", SetLight);
Nan::SetPrototypeMethod(tpl, "setAxonometric", SetAxonometric);
Nan::SetPrototypeMethod(tpl, "setXSkew", SetXSkew);
Nan::SetPrototypeMethod(tpl, "setYSkew", SetYSkew);
@@ -266,6 +270,16 @@ NodeMap::RenderOptions NodeMap::ParseOptions(v8::Local<v8::Object> obj) {
options.pitch = Nan::Get(obj, Nan::New("pitch").ToLocalChecked()).ToLocalChecked()->NumberValue();
}
+ if (Nan::Has(obj, Nan::New("light").ToLocalChecked()).FromJust()) {
+ auto lightObj = Nan::Get(obj, Nan::New("light").ToLocalChecked()).ToLocalChecked();
+ mbgl::style::conversion::Error conversionError;
+ if (auto light = mbgl::style::conversion::convert<mbgl::style::Light>(lightObj, conversionError)) {
+ options.light = *light;
+ } else {
+ throw conversionError;
+ }
+ }
+
if (Nan::Has(obj, Nan::New("axonometric").ToLocalChecked()).FromJust()) {
options.axonometric = Nan::Get(obj, Nan::New("axonometric").ToLocalChecked()).ToLocalChecked()->BooleanValue();
}
@@ -373,14 +387,14 @@ void NodeMap::Render(const Nan::FunctionCallbackInfo<v8::Value>& info) {
return Nan::ThrowError("Map is currently rendering an image");
}
- auto options = ParseOptions(Nan::To<v8::Object>(info[0]).ToLocalChecked());
-
- assert(!nodeMap->callback);
- assert(!nodeMap->image.data);
- nodeMap->callback = std::make_unique<Nan::Callback>(info[1].As<v8::Function>());
-
try {
+ auto options = ParseOptions(Nan::To<v8::Object>(info[0]).ToLocalChecked());
+ assert(!nodeMap->callback);
+ assert(!nodeMap->image.data);
+ nodeMap->callback = std::make_unique<Nan::Callback>(info[1].As<v8::Function>());
nodeMap->startRender(std::move(options));
+ } catch (mbgl::style::conversion::Error& err) {
+ return Nan::ThrowTypeError(err.message.c_str());
} catch (mbgl::util::Exception &ex) {
return Nan::ThrowError(ex.what());
}
@@ -924,6 +938,31 @@ void NodeMap::SetPitch(const Nan::FunctionCallbackInfo<v8::Value>& info) {
info.GetReturnValue().SetUndefined();
}
+void NodeMap::SetLight(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());
+
+ if (info.Length() <= 0 || !info[0]->IsObject()) {
+ return Nan::ThrowTypeError("First argument must be an object");
+ }
+
+ try {
+ Error conversionError;
+ if (auto light = convert<mbgl::style::Light>(info[0], conversionError)) {
+ nodeMap->map->getStyle().setLight(std::make_unique<Light>(*light));
+ } else {
+ return Nan::ThrowTypeError(conversionError.message.c_str());
+ }
+ } catch (const std::exception &ex) {
+ return Nan::ThrowError(ex.what());
+ }
+
+ info.GetReturnValue().SetUndefined();
+}
+
void NodeMap::SetAxonometric(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 b84f4d576f..efa6f6cee0 100644
--- a/platform/node/src/node_map.hpp
+++ b/platform/node/src/node_map.hpp
@@ -57,6 +57,7 @@ public:
static void SetZoom(const Nan::FunctionCallbackInfo<v8::Value>&);
static void SetBearing(const Nan::FunctionCallbackInfo<v8::Value>&);
static void SetPitch(const Nan::FunctionCallbackInfo<v8::Value>&);
+ static void SetLight(const Nan::FunctionCallbackInfo<v8::Value>&);
static void SetAxonometric(const Nan::FunctionCallbackInfo<v8::Value>&);
static void SetXSkew(const Nan::FunctionCallbackInfo<v8::Value>&);
static void SetYSkew(const Nan::FunctionCallbackInfo<v8::Value>&);
diff --git a/platform/node/test/js/map.test.js b/platform/node/test/js/map.test.js
index e3c8031908..81c15f9c1b 100644
--- a/platform/node/test/js/map.test.js
+++ b/platform/node/test/js/map.test.js
@@ -121,6 +121,7 @@ test('Map', function(t) {
'setZoom',
'setBearing',
'setPitch',
+ 'setLight',
'setAxonometric',
'setXSkew',
'setYSkew',
diff --git a/platform/node/test/suite_implementation.js b/platform/node/test/suite_implementation.js
index b0be2fa0eb..c09e8f50bf 100644
--- a/platform/node/test/suite_implementation.js
+++ b/platform/node/test/suite_implementation.js
@@ -53,6 +53,7 @@ module.exports = function (style, options, callback) {
options.zoom = style.zoom || 0;
options.bearing = style.bearing || 0;
options.pitch = style.pitch || 0;
+ options.light = style.light || {};
map.load(style, { defaultStyleCamera: true });
@@ -129,6 +130,8 @@ module.exports = function (style, options, callback) {
options.bearing = operation[1];
} else if (operation[0] === 'setPitch') {
options.pitch = operation[1];
+ } else if (operation[0] === 'setLight') {
+ options.light = operation[1];
}
map[operation[0]].apply(map, operation.slice(1));