-
Notifications
You must be signed in to change notification settings - Fork 165
/
mapnik_plugins.hpp
70 lines (55 loc) · 1.92 KB
/
mapnik_plugins.hpp
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
#ifndef __NODE_MAPNIK_PLUGINS_H__
#define __NODE_MAPNIK_PLUGINS_H__
// v8
#include <v8.h>
// node
#include <node.h>
// mapnik
#include <mapnik/datasource_cache.hpp>
#include <mapnik/version.hpp>
// stl
#include <vector>
#include "utils.hpp"
using namespace v8;
using namespace node;
namespace node_mapnik {
static inline Handle<Value> available_input_plugins(const Arguments& args)
{
HandleScope scope;
#if MAPNIK_VERSION >= 200200
std::vector<std::string> names = mapnik::datasource_cache::instance().plugin_names();
#else
std::vector<std::string> names = mapnik::datasource_cache::instance()->plugin_names();
#endif
Local<Array> a = Array::New(names.size());
for (unsigned i = 0; i < names.size(); ++i)
{
a->Set(i, String::New(names[i].c_str()));
}
return scope.Close(a);
}
static inline Handle<Value> register_datasources(const Arguments& args)
{
HandleScope scope;
if (args.Length() != 1 || !args[0]->IsString())
return ThrowException(Exception::TypeError(
String::New("first argument must be a path to a directory of mapnik input plugins")));
#if MAPNIK_VERSION >= 200200
std::vector<std::string> names_before = mapnik::datasource_cache::instance().plugin_names();
#else
std::vector<std::string> names_before = mapnik::datasource_cache::instance()->plugin_names();
#endif
std::string path = TOSTR(args[0]);
#if MAPNIK_VERSION >= 200200
mapnik::datasource_cache::instance().register_datasources(path);
std::vector<std::string> names_after = mapnik::datasource_cache::instance().plugin_names();
#else
mapnik::datasource_cache::instance()->register_datasources(path);
std::vector<std::string> names_after = mapnik::datasource_cache::instance()->plugin_names();
#endif
if (names_after.size() > names_before.size())
return scope.Close(True());
return scope.Close(False());
}
}
#endif // __NODE_MAPNIK_PLUGINS_H__