summaryrefslogtreecommitdiff
path: root/platform/node/src/node_map.hpp
blob: 8e4b0731347eba915e3df12d3b30292de12cc9d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once

#include <mbgl/map/map.hpp>
#include <mbgl/storage/file_source.hpp>
#include <mbgl/platform/default/headless_view.hpp>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wshadow"
#include <nan.h>
#pragma GCC diagnostic pop

namespace node_mbgl {

class NodeMap : public Nan::ObjectWrap,
                public mbgl::FileSource {
public:
    struct RenderOptions;
    class RenderWorker;

    static NAN_MODULE_INIT(Init);

    static NAN_METHOD(New);
    static NAN_METHOD(Load);
    static NAN_METHOD(Loaded);
    static NAN_METHOD(Render);
    static NAN_METHOD(Release);
    static NAN_METHOD(AddClass);
    static NAN_METHOD(AddLayer);
    static NAN_METHOD(SetLayoutProperty);
    static NAN_METHOD(SetPaintProperty);
    static NAN_METHOD(SetFilter);
    static NAN_METHOD(DumpDebugLogs);
    static NAN_METHOD(QueryRenderedFeatures);

    void startRender(RenderOptions options);
    void renderFinished();

    void release();

    static RenderOptions ParseOptions(v8::Local<v8::Object>);
    static Nan::Persistent<v8::Function> constructor;

    NodeMap(v8::Local<v8::Object>);
    ~NodeMap();

    std::unique_ptr<mbgl::AsyncRequest> request(const mbgl::Resource&, Callback);

    mbgl::HeadlessView view;
    std::unique_ptr<mbgl::Map> map;

    std::exception_ptr error;
    mbgl::PremultipliedImage image;
    std::unique_ptr<Nan::Callback> callback;

    // Async for delivering the notifications of render completion.
    uv_async_t *async;

    bool loaded = false;
};

}