/
Magnacarto.js
43 lines (37 loc) · 1.22 KB
/
Magnacarto.js
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
var Magnacarto = require('magnacarto'),
semver = require('semver'),
_ = require('lodash');
var mc = function (project) {
this.project = project;
};
mc.prototype.render = function () {
var opts = {
baseDir: this.project.root,
},
mapnikVersion = this.project.mml.mapnik_version || this.project.config.parsed_opts.mapnik_version,
mml = '';
if (semver.gte(mapnikVersion, '3.0.0')) {
opts.builderType = 'mapnik3';
}
else {
opts.builderType = 'mapnik2';
}
if (typeof this.project.mml === 'object') {
if (_.has(this.project.mml, 'Stylesheet')) {
this.project.mml.Stylesheet = _.map(this.project.mml.Stylesheet, function (value) {
// move from {id: 'x', data: 'y'} format to plain string so that Magnacarto can read it
if (_.has(value, 'data')) {
return value.data;
}
return value;
});
}
mml = JSON.stringify(this.project.mml);
}
else {
mml = this.project.mml;
}
this.project.config.log('Using mapnik version', mapnikVersion);
return new Magnacarto(opts).buildFromString(mml);
};
exports.Renderer = mc;