diff options
-rw-r--r-- | platform/node/src/node_map.cpp | 19 | ||||
-rw-r--r-- | platform/node/src/node_map.hpp | 20 |
2 files changed, 27 insertions, 12 deletions
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index b12d3552a4..d56d71ab6b 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -615,14 +615,14 @@ void NodeMap::cancel() { reinterpret_cast<NodeMap *>(h->data)->renderFinished(); }); - frontend = std::make_unique<mbgl::HeadlessFrontend>(mbgl::Size{ 256, 256 }, pixelRatio, *this, threadpool); + frontend = std::make_unique<mbgl::HeadlessFrontend>(mbgl::Size{ 256, 256 }, pixelRatio, fileSource, threadpool); mbgl::MapOptions options; options.withMapMode(mode) .withConstrainMode(mbgl::ConstrainMode::HeightOnly) .withViewportMode(mbgl::ViewportMode::Default) .withCrossSourceCollisions(crossSourceCollisions); map = std::make_unique<mbgl::Map>(*frontend, mapObserver, frontend->getSize(), pixelRatio, - *this, threadpool, options); + fileSource, threadpool, options); // FIXME: Reload the style after recreating the map. We need to find // a better way of canceling an ongoing rendering on the core level @@ -1200,12 +1200,13 @@ NodeMap::NodeMap(v8::Local<v8::Object> options) : true; }()) , mapObserver(NodeMapObserver()) - , frontend(std::make_unique<mbgl::HeadlessFrontend>(mbgl::Size { 256, 256 }, pixelRatio, *this, threadpool)) + , fileSource(this) + , frontend(std::make_unique<mbgl::HeadlessFrontend>(mbgl::Size { 256, 256 }, pixelRatio, fileSource, threadpool)) , map(std::make_unique<mbgl::Map>(*frontend, mapObserver, frontend->getSize(), pixelRatio, - *this, + fileSource, threadpool, mbgl::MapOptions().withMapMode(mode) .withConstrainMode(mbgl::ConstrainMode::HeightOnly) @@ -1226,15 +1227,19 @@ NodeMap::~NodeMap() { if (map) release(); } -std::unique_ptr<mbgl::AsyncRequest> NodeMap::request(const mbgl::Resource& resource, mbgl::FileSource::Callback callback_) { +NodeFileSource::NodeFileSource(NodeMap* nodeMap_) : nodeMap(nodeMap_) {} + +std::unique_ptr<mbgl::AsyncRequest> NodeFileSource::request(const mbgl::Resource& resource, mbgl::FileSource::Callback callback_) { + assert(nodeMap); + Nan::HandleScope scope; // Because this method may be called while this NodeMap is already eligible for garbage collection, // we need to explicitly hold onto our own handle here so that GC during a v8 call doesn't destroy // *this while we're still executing code. - handle(); + nodeMap->handle(); v8::Local<v8::Value> argv[] = { - Nan::New<v8::External>(this), + Nan::New<v8::External>(nodeMap), Nan::New<v8::External>(&callback_) }; diff --git a/platform/node/src/node_map.hpp b/platform/node/src/node_map.hpp index b83a238681..2214035b17 100644 --- a/platform/node/src/node_map.hpp +++ b/platform/node/src/node_map.hpp @@ -25,10 +25,21 @@ class NodeMapObserver : public mbgl::MapObserver { void onDidFailLoadingMap(std::exception_ptr) override; }; +class NodeMap; + +class NodeFileSource : public mbgl::FileSource { +public: + NodeFileSource(NodeMap*); + + std::unique_ptr<mbgl::AsyncRequest> request(const mbgl::Resource&, mbgl::FileSource::Callback) final; + +private: + NodeMap* nodeMap; +}; + class RenderRequest; -class NodeMap : public Nan::ObjectWrap, - public mbgl::FileSource { +class NodeMap : public Nan::ObjectWrap { public: struct RenderOptions; class RenderWorker; @@ -78,13 +89,12 @@ public: static RenderOptions ParseOptions(v8::Local<v8::Object>); - std::unique_ptr<mbgl::AsyncRequest> request(const mbgl::Resource&, mbgl::FileSource::Callback); - const float pixelRatio; mbgl::MapMode mode; bool crossSourceCollisions; NodeThreadPool threadpool; NodeMapObserver mapObserver; + NodeFileSource fileSource; std::unique_ptr<mbgl::HeadlessFrontend> frontend; std::unique_ptr<mbgl::Map> map; @@ -98,4 +108,4 @@ public: bool loaded = false; }; -} +} // namespace node_mbgl |