diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2017-09-11 18:30:10 -0400 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2017-09-13 23:35:27 +0300 |
commit | e9914bf0344b0ef996f831ec2d80e5103df8b949 (patch) | |
tree | 937362928f4e6ea9b6344d92fa265171fa500b75 /platform/node/src/node_map.cpp | |
parent | cda418198f17df87962e1797e024714eaceadcd7 (diff) | |
download | qtlocation-mapboxgl-e9914bf0344b0ef996f831ec2d80e5103df8b949.tar.gz |
[node] Implement GeoJSON converter
Diffstat (limited to 'platform/node/src/node_map.cpp')
-rw-r--r-- | platform/node/src/node_map.cpp | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index fcc394bbe5..d9e47ea998 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -151,19 +151,6 @@ void NodeMap::New(const Nan::FunctionCallbackInfo<v8::Value>& info) { info.GetReturnValue().Set(info.This()); } -std::string StringifyStyle(v8::Local<v8::Value> styleHandle) { - Nan::HandleScope scope; - - v8::Local<v8::Object> JSON = Nan::To<v8::Object>( - Nan::Get( - Nan::GetCurrentContext()->Global(), - Nan::New("JSON").ToLocalChecked() - ).ToLocalChecked() - ).ToLocalChecked(); - - return *Nan::Utf8String(Nan::MakeCallback(JSON, "stringify", 1, &styleHandle)); -} - /** * Load a stylesheet * @@ -197,7 +184,8 @@ void NodeMap::Load(const Nan::FunctionCallbackInfo<v8::Value>& info) { std::string style; if (info[0]->IsObject()) { - style = StringifyStyle(info[0]); + Nan::JSON JSON; + style = *Nan::Utf8String(JSON.Stringify(info[0]->ToObject()).ToLocalChecked()); } else if (info[0]->IsString()) { style = *Nan::Utf8String(info[0]); } else { @@ -545,6 +533,10 @@ void NodeMap::AddSource(const Nan::FunctionCallbackInfo<v8::Value>& info) { return Nan::ThrowTypeError("First argument must be a string"); } + if (!info[1]->IsObject()) { + return Nan::ThrowTypeError("Second argument must be an object"); + } + Error error; mbgl::optional<std::unique_ptr<Source>> source = convert<std::unique_ptr<Source>>(info[1], error, *Nan::Utf8String(info[0])); if (!source) { |