From 447d24bb198a44e9dbb25ba696c484fcd7873c42 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 14 Sep 2017 09:40:31 -0400 Subject: [node] Added 'removeSource' --- platform/node/src/node_map.cpp | 19 +++++++++++++++++++ platform/node/src/node_map.hpp | 1 + platform/node/test/js/map.test.js | 1 + 3 files changed, 21 insertions(+) diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index d9e47ea998..9a7ebce445 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -53,6 +53,7 @@ void NodeMap::Init(v8::Local target) { Nan::SetPrototypeMethod(tpl, "cancel", Cancel); Nan::SetPrototypeMethod(tpl, "addSource", AddSource); + Nan::SetPrototypeMethod(tpl, "removeSource", RemoveSource); Nan::SetPrototypeMethod(tpl, "addLayer", AddLayer); Nan::SetPrototypeMethod(tpl, "removeLayer", RemoveLayer); Nan::SetPrototypeMethod(tpl, "addImage", AddImage); @@ -547,6 +548,24 @@ void NodeMap::AddSource(const Nan::FunctionCallbackInfo& info) { nodeMap->map->getStyle().addSource(std::move(*source)); } +void NodeMap::RemoveSource(const Nan::FunctionCallbackInfo& info) { + using namespace mbgl::style; + using namespace mbgl::style::conversion; + + auto nodeMap = Nan::ObjectWrap::Unwrap(info.Holder()); + if (!nodeMap->map) return Nan::ThrowError(releasedMessage()); + + if (info.Length() != 1) { + return Nan::ThrowTypeError("One argument required"); + } + + if (!info[0]->IsString()) { + return Nan::ThrowTypeError("First argument must be a string"); + } + + nodeMap->map->getStyle().removeSource(*Nan::Utf8String(info[0])); +} + void NodeMap::AddLayer(const Nan::FunctionCallbackInfo& info) { 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 7bd3b99bea..c8e33bb347 100644 --- a/platform/node/src/node_map.hpp +++ b/platform/node/src/node_map.hpp @@ -45,6 +45,7 @@ public: static void Release(const Nan::FunctionCallbackInfo&); static void Cancel(const Nan::FunctionCallbackInfo&); static void AddSource(const Nan::FunctionCallbackInfo&); + static void RemoveSource(const Nan::FunctionCallbackInfo&); static void AddLayer(const Nan::FunctionCallbackInfo&); static void RemoveLayer(const Nan::FunctionCallbackInfo&); static void AddImage(const Nan::FunctionCallbackInfo&); diff --git a/platform/node/test/js/map.test.js b/platform/node/test/js/map.test.js index 04d02d0558..39665e41ef 100644 --- a/platform/node/test/js/map.test.js +++ b/platform/node/test/js/map.test.js @@ -109,6 +109,7 @@ test('Map', function(t) { 'release', 'cancel', 'addSource', + 'removeSource', 'addLayer', 'removeLayer', 'addImage', -- cgit v1.2.1