-
Notifications
You must be signed in to change notification settings - Fork 166
/
map_generation.test.js
86 lines (77 loc) · 2.4 KB
/
map_generation.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
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
80
81
82
83
84
85
86
"use strict";
var test = require('tape');
var mapnik = require('../');
var path = require('path');
var exists = require('fs').existsSync || require('path').existsSync;
mapnik.register_datasource(path.join(mapnik.settings.paths.input_plugins,'shape.input'));
test('should render async (blank)', (assert) => {
var map = new mapnik.Map(600, 400);
assert.ok(map instanceof mapnik.Map);
map.extent = map.extent;
var im = new mapnik.Image(map.width, map.height);
map.render(im, {scale: 1, buffer_size: 1}, function(err, image) {
assert.ok(image);
assert.ok(!err);
var buffer = im.encodeSync('png');
assert.ok(buffer);
assert.end();
});
});
test('should render async (real data)', (assert) => {
var filename = './test/tmp/renderFile2.png';
var map = new mapnik.Map(600, 400);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
map.renderFile(filename, function(error) {
assert.ok(!error);
assert.ok(exists(filename));
assert.end();
});
});
test('should render async to file (png)', (assert) => {
var filename = './test/tmp/renderFile2.png';
var map = new mapnik.Map(600, 400);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
map.renderFile(filename, function(error) {
assert.ok(!error);
assert.ok(exists(filename));
assert.end();
});
});
test('should render async to file (cairo format)', (assert) => {
if (mapnik.supports.cairo) {
var filename = './test/tmp/renderFile2.pdf';
var map = new mapnik.Map(600, 400);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
map.renderFile(filename, { format: 'pdf' }, function(error) {
assert.ok(!error);
assert.ok(exists(filename));
assert.end();
});
} else { assert.end(); }
});
test('should render async to file (guessing format)', (assert) => {
var filename = './test/tmp/renderFile.jpg';
var map = new mapnik.Map(600, 400);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
map.renderFile(filename, function(error) {
assert.ok(!error);
assert.ok(exists(filename));
assert.end();
});
});
test('should render async and throw with invalid format', (assert) => {
var filename = './test/tmp/renderFile2.pdf';
var map = new mapnik.Map(600, 400);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
try {
map.renderFile(filename, null, function(error) { assert.ok(error); });
} catch (ex) {
assert.ok(ex);
assert.end();
}
});