From e9914bf0344b0ef996f831ec2d80e5103df8b949 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Mon, 11 Sep 2017 18:30:10 -0400 Subject: [node] Implement GeoJSON converter --- platform/node/src/node_geojson.hpp | 8 +++++--- platform/node/src/node_map.cpp | 20 ++++++-------------- platform/node/test/ignores.json | 8 +++----- 3 files changed, 14 insertions(+), 22 deletions(-) (limited to 'platform') diff --git a/platform/node/src/node_geojson.hpp b/platform/node/src/node_geojson.hpp index 9bae86b76a..8a3927e2cf 100644 --- a/platform/node/src/node_geojson.hpp +++ b/platform/node/src/node_geojson.hpp @@ -1,13 +1,15 @@ #include +#include namespace mbgl { namespace style { namespace conversion { template <> -optional Converter::operator()(const v8::Local&, Error& error) const { - error = { "not implemented" }; - return {}; +optional Converter::operator()(const v8::Local& value, Error& error) const { + Nan::JSON JSON; + std::string string = *Nan::Utf8String(JSON.Stringify(value->ToObject()).ToLocalChecked()); + return convert(string, error); } } // namespace conversion 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& info) { info.GetReturnValue().Set(info.This()); } -std::string StringifyStyle(v8::Local styleHandle) { - Nan::HandleScope scope; - - v8::Local JSON = Nan::To( - 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& 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& 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> source = convert>(info[1], error, *Nan::Utf8String(info[0])); if (!source) { diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json index a6e43da0b3..845c7e8a37 100644 --- a/platform/node/test/ignores.json +++ b/platform/node/test/ignores.json @@ -38,14 +38,12 @@ "render-tests/line-join/property-function-dasharray": "https://github.com/mapbox/mapbox-gl-js/pull/5020", "render-tests/line-opacity/step-curve": "https://github.com/mapbox/mapbox-gl-native/pull/9439", "render-tests/regressions/mapbox-gl-js#2305": "https://github.com/mapbox/mapbox-gl-native/issues/6927", - "render-tests/regressions/mapbox-gl-js#3548": "skip - needs issue", "render-tests/regressions/mapbox-gl-js#3682": "https://github.com/mapbox/mapbox-gl-js/issues/3682", "render-tests/regressions/mapbox-gl-native#7357": "https://github.com/mapbox/mapbox-gl-native/issues/7357", "render-tests/regressions/mapbox-gl-native#9900": "skip - https://github.com/mapbox/mapbox-gl-native/pull/9905", - "render-tests/runtime-styling/image-add-sdf": "skip - https://github.com/mapbox/mapbox-gl-native/issues/9847", - "render-tests/runtime-styling/paint-property-fill-flat-to-extrude": "skip - https://github.com/mapbox/mapbox-gl-native/issues/6745", - "render-tests/runtime-styling/set-style-paint-property-fill-flat-to-extrude": "skip - needs issue", - "render-tests/runtime-styling/source-add-geojson-inline": "skip - needs issue", + "render-tests/runtime-styling/image-add-sdf": "https://github.com/mapbox/mapbox-gl-native/issues/9847", + "render-tests/runtime-styling/paint-property-fill-flat-to-extrude": "https://github.com/mapbox/mapbox-gl-native/issues/6745", + "render-tests/runtime-styling/set-style-paint-property-fill-flat-to-extrude": "https://github.com/mapbox/mapbox-gl-native/issues/6745", "render-tests/symbol-placement/line": "needs issue", "render-tests/text-font/camera-function": "https://github.com/mapbox/mapbox-gl-native/pull/9439", "render-tests/text-keep-upright/line-placement-true-offset": "https://github.com/mapbox/mapbox-gl-native/issues/9271", -- cgit v1.2.1