summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-06-23 12:00:25 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-06-24 09:39:51 -0700
commit021d4199cb9ee754e9f0f5bc42f7f75285afd405 (patch)
tree9396f291348c0ab5f3a75e1a217a78fc4dbff4b2 /platform
parent16c435b1517b15a5ea8654987979ef58800b838b (diff)
downloadqtlocation-mapboxgl-021d4199cb9ee754e9f0f5bc42f7f75285afd405.tar.gz
[core, node] Implement bindings for addSource
Diffstat (limited to 'platform')
-rw-r--r--platform/default/mbgl/storage/offline_download.cpp4
-rw-r--r--platform/node/src/node_geojson.hpp14
-rw-r--r--platform/node/src/node_map.cpp27
-rw-r--r--platform/node/src/node_map.hpp1
4 files changed, 44 insertions, 2 deletions
diff --git a/platform/default/mbgl/storage/offline_download.cpp b/platform/default/mbgl/storage/offline_download.cpp
index 2aaeb30fab..bad23cadbe 100644
--- a/platform/default/mbgl/storage/offline_download.cpp
+++ b/platform/default/mbgl/storage/offline_download.cpp
@@ -127,7 +127,7 @@ OfflineRegionStatus OfflineDownload::getStatus() const {
case SourceType::GeoJSON: {
style::GeoJSONSource::Impl* geojsonSource = static_cast<style::GeoJSONSource::Impl*>(source->baseImpl.get());
- const variant<std::string, style::GeoJSONSource::Impl::GeoJSON>& urlOrGeoJSON = geojsonSource->getURLOrGeoJSON();
+ const variant<std::string, GeoJSON>& urlOrGeoJSON = geojsonSource->getURLOrGeoJSON();
if (urlOrGeoJSON.is<std::string>()) {
result.requiredResourceCount += 1;
@@ -190,7 +190,7 @@ void OfflineDownload::activateDownload() {
case SourceType::GeoJSON: {
style::GeoJSONSource::Impl* geojsonSource = static_cast<style::GeoJSONSource::Impl*>(source->baseImpl.get());
- const variant<std::string, style::GeoJSONSource::Impl::GeoJSON>& urlOrGeoJSON = geojsonSource->getURLOrGeoJSON();
+ const variant<std::string, GeoJSON>& urlOrGeoJSON = geojsonSource->getURLOrGeoJSON();
if (urlOrGeoJSON.is<std::string>()) {
ensureResource(Resource::source(urlOrGeoJSON.get<std::string>()));
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);