diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-06-23 12:00:25 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-06-24 09:39:51 -0700 |
commit | 021d4199cb9ee754e9f0f5bc42f7f75285afd405 (patch) | |
tree | 9396f291348c0ab5f3a75e1a217a78fc4dbff4b2 /platform/node/src | |
parent | 16c435b1517b15a5ea8654987979ef58800b838b (diff) | |
download | qtlocation-mapboxgl-021d4199cb9ee754e9f0f5bc42f7f75285afd405.tar.gz |
[core, node] Implement bindings for addSource
Diffstat (limited to 'platform/node/src')
-rw-r--r-- | platform/node/src/node_geojson.hpp | 14 | ||||
-rw-r--r-- | platform/node/src/node_map.cpp | 27 | ||||
-rw-r--r-- | platform/node/src/node_map.hpp | 1 |
3 files changed, 42 insertions, 0 deletions
diff --git a/platform/node/src/node_geojson.hpp b/platform/node/src/node_geojson.hpp new file mode 100644 index 0000000000..ace4c91426 --- /dev/null +++ b/platform/node/src/node_geojson.hpp @@ -0,0 +1,14 @@ +#include <mbgl/style/conversion/geojson.hpp> + +namespace mbgl { +namespace style { +namespace conversion { + +template <> +Result<GeoJSON> convertGeoJSON(const v8::Local<v8::Value>&) { + return Error { "not implemented" }; +} + +} // namespace conversion +} // namespace style +} // namespace mbgl diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index c73d3850f2..7bcdd9cdda 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -2,9 +2,11 @@ #include "node_request.hpp" #include "node_feature.hpp" #include "node_conversion.hpp" +#include "node_geojson.hpp" #include <mbgl/platform/default/headless_display.hpp> #include <mbgl/util/exception.hpp> +#include <mbgl/style/conversion/source.hpp> #include <mbgl/style/conversion/layer.hpp> #include <mbgl/style/conversion/filter.hpp> @@ -56,6 +58,7 @@ NAN_MODULE_INIT(NodeMap::Init) { Nan::SetPrototypeMethod(tpl, "release", Release); Nan::SetPrototypeMethod(tpl, "addClass", AddClass); + Nan::SetPrototypeMethod(tpl, "addSource", AddSource); Nan::SetPrototypeMethod(tpl, "addLayer", AddLayer); Nan::SetPrototypeMethod(tpl, "setLayoutProperty", SetLayoutProperty); Nan::SetPrototypeMethod(tpl, "setPaintProperty", SetPaintProperty); @@ -484,6 +487,30 @@ NAN_METHOD(NodeMap::AddClass) { info.GetReturnValue().SetUndefined(); } +NAN_METHOD(NodeMap::AddSource) { + 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() != 2) { + return Nan::ThrowTypeError("Two argument required"); + } + + if (!info[0]->IsString()) { + return Nan::ThrowTypeError("First argument must be a string"); + } + + Result<std::unique_ptr<Source>> source = convert<std::unique_ptr<Source>>(info[1], *Nan::Utf8String(info[0])); + if (!source) { + Nan::ThrowTypeError(source.error().message); + return; + } + + nodeMap->map->addSource(std::move(*source)); +} + NAN_METHOD(NodeMap::AddLayer) { using namespace mbgl::style; using namespace mbgl::style::conversion; diff --git a/platform/node/src/node_map.hpp b/platform/node/src/node_map.hpp index 8e4b073134..d64d58013d 100644 --- a/platform/node/src/node_map.hpp +++ b/platform/node/src/node_map.hpp @@ -26,6 +26,7 @@ public: static NAN_METHOD(Render); static NAN_METHOD(Release); static NAN_METHOD(AddClass); + static NAN_METHOD(AddSource); static NAN_METHOD(AddLayer); static NAN_METHOD(SetLayoutProperty); static NAN_METHOD(SetPaintProperty); |