summaryrefslogtreecommitdiff
path: root/platform/node
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2019-03-19 16:57:36 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2019-03-20 21:30:08 +0200
commitd5868d3da822f2bf3297229bd879e76853108a63 (patch)
treeb3d28aab92b938cf541f917f1027d2bbd06d9780 /platform/node
parentd1762d7111b39d45430bd7bb75ea60b7a5d85bd2 (diff)
downloadqtlocation-mapboxgl-d5868d3da822f2bf3297229bd879e76853108a63.tar.gz
[core] Remove file source from public Map ctor
Diffstat (limited to 'platform/node')
-rw-r--r--platform/node/src/node_map.cpp48
-rw-r--r--platform/node/src/node_map.hpp24
2 files changed, 32 insertions, 40 deletions
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp
index 0d69e606c1..0b27d378a7 100644
--- a/platform/node/src/node_map.cpp
+++ b/platform/node/src/node_map.cpp
@@ -20,15 +20,25 @@
#include <mbgl/style/layers/raster_layer.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
+#include <mbgl/storage/resource_options.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/style/image.hpp>
#include <mbgl/style/light.hpp>
+#include <mbgl/map/map.hpp>
#include <mbgl/map/map_observer.hpp>
#include <mbgl/util/exception.hpp>
#include <mbgl/util/premultiply.hpp>
#include <unistd.h>
+namespace mbgl {
+
+std::shared_ptr<FileSource> FileSource::createPlatformFileSource(const ResourceOptions& options) {
+ return std::make_shared<node_mbgl::NodeFileSource>(reinterpret_cast<node_mbgl::NodeMap*>(options.platformContext()));
+}
+
+} // namespace mbgl
+
namespace node_mbgl {
struct NodeMap::RenderOptions {
@@ -621,13 +631,14 @@ void NodeMap::cancel() {
});
frontend = std::make_unique<mbgl::HeadlessFrontend>(mbgl::Size{ 256, 256 }, pixelRatio, threadpool);
- mbgl::MapOptions options;
- options.withMapMode(mode)
- .withConstrainMode(mbgl::ConstrainMode::HeightOnly)
- .withViewportMode(mbgl::ViewportMode::Default)
- .withCrossSourceCollisions(crossSourceCollisions);
+ auto mapOptions = mbgl::MapOptions()
+ .withMapMode(mode)
+ .withCrossSourceCollisions(crossSourceCollisions);
+
+ auto resourceOptions = mbgl::ResourceOptions().withPlatformContext(reinterpret_cast<void*>(this));
+
map = std::make_unique<mbgl::Map>(*frontend, mapObserver, frontend->getSize(), pixelRatio,
- fileSource, threadpool, options);
+ threadpool, mapOptions, resourceOptions);
// FIXME: Reload the style after recreating the map. We need to find
// a better way of canceling an ongoing rendering on the core level
@@ -1205,20 +1216,11 @@ NodeMap::NodeMap(v8::Local<v8::Object> options)
: true;
}())
, mapObserver(NodeMapObserver())
- , fileSource(this)
, frontend(std::make_unique<mbgl::HeadlessFrontend>(mbgl::Size { 256, 256 }, pixelRatio, threadpool))
- , map(std::make_unique<mbgl::Map>(*frontend,
- mapObserver,
- frontend->getSize(),
- pixelRatio,
- fileSource,
- threadpool,
- mbgl::MapOptions().withMapMode(mode)
- .withConstrainMode(mbgl::ConstrainMode::HeightOnly)
- .withViewportMode(mbgl::ViewportMode::Default)
- .withCrossSourceCollisions(crossSourceCollisions))),
- async(new uv_async_t) {
-
+ , map(std::make_unique<mbgl::Map>(*frontend, mapObserver, frontend->getSize(), pixelRatio, threadpool,
+ mbgl::MapOptions().withMapMode(mode).withCrossSourceCollisions(crossSourceCollisions),
+ mbgl::ResourceOptions().withPlatformContext(reinterpret_cast<void*>(this))))
+ , async(new uv_async_t) {
async->data = this;
uv_async_init(uv_default_loop(), async, [](uv_async_t* h) {
reinterpret_cast<NodeMap *>(h->data)->renderFinished();
@@ -1232,8 +1234,6 @@ NodeMap::~NodeMap() {
if (map) release();
}
-NodeFileSource::NodeFileSource(NodeMap* nodeMap_) : nodeMap(nodeMap_) {}
-
std::unique_ptr<mbgl::AsyncRequest> NodeFileSource::request(const mbgl::Resource& resource, mbgl::FileSource::Callback callback_) {
assert(nodeMap);
@@ -1248,15 +1248,15 @@ std::unique_ptr<mbgl::AsyncRequest> NodeFileSource::request(const mbgl::Resource
Nan::New<v8::External>(&callback_)
};
- auto instance = Nan::NewInstance(Nan::New(NodeRequest::constructor), 2, argv).ToLocalChecked();
+ auto instance = Nan::NewInstance(Nan::New(node_mbgl::NodeRequest::constructor), 2, argv).ToLocalChecked();
Nan::Set(instance, Nan::New("url").ToLocalChecked(), Nan::New(resource.url).ToLocalChecked());
Nan::Set(instance, Nan::New("kind").ToLocalChecked(), Nan::New<v8::Integer>(resource.kind));
- auto request = Nan::ObjectWrap::Unwrap<NodeRequest>(instance);
+ auto request = Nan::ObjectWrap::Unwrap<node_mbgl::NodeRequest>(instance);
request->Execute();
- return std::make_unique<NodeRequest::NodeAsyncRequest>(request);
+ return std::make_unique<node_mbgl::NodeRequest::NodeAsyncRequest>(request);
}
} // namespace node_mbgl
diff --git a/platform/node/src/node_map.hpp b/platform/node/src/node_map.hpp
index 9e3eb1ad12..65664b34bb 100644
--- a/platform/node/src/node_map.hpp
+++ b/platform/node/src/node_map.hpp
@@ -15,26 +15,13 @@
#pragma GCC diagnostic pop
namespace mbgl {
-class Map;
class HeadlessFrontend;
} // namespace mbgl
namespace node_mbgl {
-class NodeMapObserver : public mbgl::MapObserver {
- void onDidFailLoadingMap(mbgl::MapLoadError, const std::string&) 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;
+struct NodeMapObserver : public mbgl::MapObserver {
+ void onDidFailLoadingMap(mbgl::MapLoadError, const std::string&) final;
};
class RenderRequest;
@@ -94,7 +81,6 @@ public:
bool crossSourceCollisions;
NodeThreadPool threadpool;
NodeMapObserver mapObserver;
- NodeFileSource fileSource;
std::unique_ptr<mbgl::HeadlessFrontend> frontend;
std::unique_ptr<mbgl::Map> map;
@@ -108,4 +94,10 @@ public:
bool loaded = false;
};
+struct NodeFileSource : public mbgl::FileSource {
+ NodeFileSource(NodeMap* nodeMap_) : nodeMap(nodeMap_) {}
+ std::unique_ptr<mbgl::AsyncRequest> request(const mbgl::Resource&, mbgl::FileSource::Callback) final;
+ NodeMap* nodeMap;
+};
+
} // namespace node_mbgl