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
|
#include "node_map_render_worker.hpp"
#include "node_file_source.hpp"
#include <mbgl/util/image.hpp>
namespace node_mbgl {
NodeMap::RenderWorker::RenderWorker(NodeMap *nodeMap_, std::unique_ptr<RenderOptions> options_,
NanCallback *callback_)
: NanAsyncWorker(callback_), nodeMap(nodeMap_), options(std::move(options_)) {
nodeMap->Ref();
}
NodeMap::RenderWorker::~RenderWorker() {
nodeMap->Unref();
}
void NodeMap::RenderWorker::Execute() {
try {
nodeMap->view.resize(options->width, options->height, options->ratio);
nodeMap->map.setAccessToken(options->accessToken);
nodeMap->map.resize(options->width, options->height, options->ratio);
nodeMap->map.setClasses(options->classes);
nodeMap->map.setLonLatZoom(options->longitude, options->latitude, options->zoom);
nodeMap->map.setBearing(options->bearing);
// Run the loop. It will terminate when we don't have any further listeners.
nodeMap->map.run();
const unsigned int width = options->width * options->ratio;
const unsigned int height = options->height * options->ratio;
auto pixels = nodeMap->view.readPixels();
image = mbgl::util::compress_png(width, height, pixels.get());
} catch (mbgl::exception &ex) {
SetErrorMessage(ex.what());
}
}
void NodeMap::RenderWorker::WorkComplete() {
NanAsyncWorker::WorkComplete();
// Continue processing remaining items in the queue.
nodeMap->processNext();
}
void NodeMap::RenderWorker::HandleOKCallback() {
NanScope();
v8::Local<v8::Value> argv[] = {
NanNull(),
NanNewBufferHandle(image.data(), image.length())
};
callback->Call(2, argv);
};
} // ns node_mbgl
|