[node] Support mbgl::MapObserver

This commit is contained in:
Bruno de Oliveira Abinader
2017-03-13 15:09:40 +02:00
parent 2aa20ff471
commit d152efb8cb
2 changed files with 14 additions and 8 deletions

View File

@@ -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();

View File

@@ -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;