[core, node] Implement bindings for addSource

This commit is contained in:
John Firebaugh
2016-06-23 12:00:25 -07:00
parent 16c435b151
commit 021d4199cb
24 changed files with 361 additions and 251 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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);