[node] Use new FileSourceManager interface
This commit is contained in:
@@ -53,6 +53,9 @@ target_include_directories(mbgl-node INTERFACE
|
||||
target_link_libraries(mbgl-node INTERFACE
|
||||
mbgl-core
|
||||
mbgl-loop-node
|
||||
# link against default filesource code, so that the node map
|
||||
# can register it's default resource loader.
|
||||
mbgl-filesource
|
||||
)
|
||||
|
||||
set_target_properties(mbgl-node.all PROPERTIES FOLDER "Node.js")
|
||||
|
||||
@@ -20,25 +20,19 @@
|
||||
#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/storage/file_source_manager.hpp>
|
||||
#include <mbgl/storage/resource_options.hpp>
|
||||
#include <mbgl/style/image.hpp>
|
||||
#include <mbgl/style/light.hpp>
|
||||
#include <mbgl/style/style.hpp>
|
||||
#include <mbgl/util/async_request.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 {
|
||||
@@ -197,6 +191,12 @@ void NodeMap::New(const Nan::FunctionCallbackInfo<v8::Value>& info) {
|
||||
|
||||
info.This()->SetInternalField(1, options);
|
||||
|
||||
mbgl::FileSourceManager::get()->registerFileSourceFactory(
|
||||
mbgl::FileSourceType::ResourceLoader, [](const mbgl::ResourceOptions& resourceOptions) {
|
||||
return std::make_unique<node_mbgl::NodeFileSource>(
|
||||
reinterpret_cast<node_mbgl::NodeMap*>(resourceOptions.platformContext()));
|
||||
});
|
||||
|
||||
try {
|
||||
auto nodeMap = new NodeMap(options);
|
||||
nodeMap->Wrap(info.This());
|
||||
@@ -1455,4 +1455,8 @@ std::unique_ptr<mbgl::AsyncRequest> NodeFileSource::request(const mbgl::Resource
|
||||
return asyncRequest;
|
||||
}
|
||||
|
||||
bool NodeFileSource::canRequest(const mbgl::Resource&) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace node_mbgl
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
#include <mbgl/util/async_request.hpp>
|
||||
#include <mbgl/util/image.hpp>
|
||||
|
||||
#include <exception>
|
||||
@@ -98,6 +99,7 @@ struct NodeFileSource : public mbgl::FileSource {
|
||||
NodeFileSource(NodeMap* nodeMap_) : nodeMap(nodeMap_) {}
|
||||
~NodeFileSource() {}
|
||||
std::unique_ptr<mbgl::AsyncRequest> request(const mbgl::Resource&, mbgl::FileSource::Callback) final;
|
||||
bool canRequest(const mbgl::Resource&) const override;
|
||||
NodeMap* nodeMap;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
#include <nan.h>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#include <mbgl/storage/resource.hpp>
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
#include <mbgl/storage/resource.hpp>
|
||||
#include <mbgl/util/async_request.hpp>
|
||||
|
||||
namespace node_mbgl {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user