-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathmapnik_vector_tile_clear.cpp
More file actions
79 lines (71 loc) · 1.8 KB
/
mapnik_vector_tile_clear.cpp
File metadata and controls
79 lines (71 loc) · 1.8 KB
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
#include "mapnik_vector_tile.hpp"
namespace {
struct AsyncClear : Napi::AsyncWorker
{
AsyncClear(mapnik::vector_tile_impl::merc_tile_ptr const& tile, Napi::Function const& callback)
: Napi::AsyncWorker(callback),
tile_(tile) {}
void Execute() override
{
try
{
tile_->clear();
}
catch (std::exception const& ex)
{
// No reason this should ever throw an exception, not currently testable.
// LCOV_EXCL_START
SetError(ex.what());
// LCOV_EXCL_STOP
}
}
private:
mapnik::vector_tile_impl::merc_tile_ptr tile_;
};
} // namespace
/**
* Remove all data from this vector tile (synchronously)
* @name clearSync
* @memberof VectorTile
* @instance
* @example
* vt.clearSync();
* console.log(vt.getData().length); // 0
*/
Napi::Value VectorTile::clearSync(Napi::CallbackInfo const& info)
{
Napi::Env env = info.Env();
tile_->clear();
return env.Undefined();
}
/**
* Remove all data from this vector tile
*
* @memberof VectorTile
* @instance
* @name clear
* @param {Function} callback
* @example
* vt.clear(function(err) {
* if (err) throw err;
* console.log(vt.getData().length); // 0
* });
*/
Napi::Value VectorTile::clear(Napi::CallbackInfo const& info)
{
if (info.Length() == 0)
{
return clearSync(info);
}
Napi::Env env = info.Env();
// ensure callback is a function
Napi::Value callback = info[info.Length() - 1];
if (!callback.IsFunction())
{
Napi::TypeError::New(env, "last argument must be a callback function").ThrowAsJavaScriptException();
return env.Undefined();
}
auto* worker = new AsyncClear(tile_, callback.As<Napi::Function>());
worker->Queue();
return env.Undefined();
}