forked from springmeyer/mapnik-mongo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
46 lines (36 loc) · 1.24 KB
/
test.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
44
45
46
"use strict";
var fs = require("fs");
var mapnik = require("mapnik");
mapnik.register_datasources("..");
mapnik.register_fonts("/usr/share/fonts/truetype/ttf-dejavu");
var conf = [
{ extent: [ -180, -90, 0, 90 ], file: "1.png" },
{ extent: [ 0, -90, 180, 90 ], file: "2.png" }
];
var map = new mapnik.Map(256, 256);
map.load("test.xml", function(err, map) {
if (err)
return console.log("style load error:", err.message);
(function step(i) {
if (!conf[i]) return;
render(conf[i], function() { setImmediate(function() { step(i + 1) }); });
})(0);
});
function render(conf, callback) {
map.zoomToBox(conf.extent);
var img = new mapnik.Image(256, 256);
map.render(img, function(err, img) {
if (err)
return console.log("rendering error:", err.message);
img.encode("png", function(err, buffer) {
if (err)
return console.log("encoding error:", err.message);
fs.writeFile(conf.file, buffer, function(err) {
if (err)
return console.log("saving error:", err.message);
console.log("done:", conf.file);
return callback && callback();
});
});
});
}