summaryrefslogtreecommitdiff
path: root/platform/node/src/node_map.hpp
blob: 2214035b178c8dcbad1f9176f52a718d530c33cd (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#pragma once

#include "node_thread_pool.hpp"

#include <mbgl/map/map.hpp>
#include <mbgl/storage/file_source.hpp>
#include <mbgl/util/image.hpp>

#include <exception>

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

namespace mbgl {
class Map;
class HeadlessFrontend;
} // namespace mbgl

namespace node_mbgl {

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:
    struct RenderOptions;
    class RenderWorker;

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

    static Nan::Persistent<v8::Function> constructor;
    static Nan::Persistent<v8::Object> parseError;

    static void Init(v8::Local<v8::Object>);

    static void New(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void Load(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void Loaded(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void Render(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void Release(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void Cancel(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void AddSource(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void RemoveSource(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void AddLayer(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void RemoveLayer(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void AddImage(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void RemoveImage(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void SetLayerZoomRange(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void SetLayoutProperty(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void SetPaintProperty(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void SetFilter(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void SetCenter(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void SetZoom(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void SetBearing(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void SetPitch(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void SetLight(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void SetAxonometric(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void SetXSkew(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void SetYSkew(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void DumpDebugLogs(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void QueryRenderedFeatures(const Nan::FunctionCallbackInfo<v8::Value>&);

    static v8::Local<v8::Value> ParseError(const char* msg);

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

    void release();
    void cancel();

    static RenderOptions ParseOptions(v8::Local<v8::Object>);

    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;

    std::exception_ptr error;
    mbgl::PremultipliedImage image;
    std::unique_ptr<RenderRequest> req;

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

    bool loaded = false;
};

} // namespace node_mbgl