summaryrefslogtreecommitdiff
path: root/platform/node
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2017-03-13 15:09:40 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2017-03-15 14:53:32 +0200
commitd152efb8cb978cb65a8f724f9adf15a0bdf70adc (patch)
treef21bc2159faa5769edaa069f715bf058f73a133d /platform/node
parent2aa20ff47128e1840a51357e02cc691656cffe74 (diff)
downloadqtlocation-mapboxgl-d152efb8cb978cb65a8f724f9adf15a0bdf70adc.tar.gz
[node] Support mbgl::MapObserver
Diffstat (limited to 'platform/node')
-rw-r--r--platform/node/src/node_map.cpp14
-rw-r--r--platform/node/src/node_map.hpp8
2 files changed, 14 insertions, 8 deletions
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp
index 686766ed19..3046652c21 100644
--- a/platform/node/src/node_map.cpp
+++ b/platform/node/src/node_map.cpp
@@ -39,6 +39,13 @@ static const char* releasedMessage() {
return "Map resources have already been released";
}
+NodeBackend::NodeBackend()
+ : HeadlessBackend(sharedDisplay()) {}
+
+void NodeBackend::onDidFailLoadingMap() {
+ throw std::runtime_error("Requires a map style to be a valid style JSON");
+}
+
void NodeMap::Init(v8::Local<v8::Object> target) {
v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(New);
@@ -953,7 +960,6 @@ NodeMap::NodeMap(v8::Local<v8::Object> options)
->NumberValue()
: 1.0;
}()),
- backend(sharedDisplay()),
map(std::make_unique<mbgl::Map>(backend,
mbgl::Size{ 256, 256 },
pixelRatio,
@@ -962,12 +968,6 @@ NodeMap::NodeMap(v8::Local<v8::Object> options)
mbgl::MapMode::Still)),
async(new uv_async_t) {
- backend.setMapChangeCallback([&](mbgl::MapChange change) {
- if (change == mbgl::MapChangeDidFailLoadingMap) {
- throw std::runtime_error("Requires a map style to be a valid style JSON");
- }
- });
-
async->data = this;
uv_async_init(uv_default_loop(), async, [](uv_async_t* h) {
reinterpret_cast<NodeMap *>(h->data)->renderFinished();
diff --git a/platform/node/src/node_map.hpp b/platform/node/src/node_map.hpp
index 47a5385ad6..122e491442 100644
--- a/platform/node/src/node_map.hpp
+++ b/platform/node/src/node_map.hpp
@@ -15,6 +15,12 @@
namespace node_mbgl {
+class NodeBackend : public mbgl::HeadlessBackend {
+public:
+ NodeBackend();
+ void onDidFailLoadingMap() final;
+};
+
class NodeMap : public Nan::ObjectWrap,
public mbgl::FileSource {
public:
@@ -59,7 +65,7 @@ public:
std::unique_ptr<mbgl::AsyncRequest> request(const mbgl::Resource&, mbgl::FileSource::Callback);
const float pixelRatio;
- mbgl::HeadlessBackend backend;
+ NodeBackend backend;
std::unique_ptr<mbgl::OffscreenView> view;
NodeThreadPool threadpool;
std::unique_ptr<mbgl::Map> map;