-
Notifications
You must be signed in to change notification settings - Fork 165
/
render-sync.test.js
204 lines (181 loc) · 6.33 KB
/
render-sync.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
"use strict";
var test = require('tape');
var mapnik = require('../');
var exists = require('fs').existsSync || require('path').existsSync;
var helper = require('./support/helper');
var path = require('path');
mapnik.register_datasource(path.join(mapnik.settings.paths.input_plugins,'shape.input'));
test('should clear marker cache', (assert) => {
assert.equal(mapnik.clearCache(), undefined);
assert.end();
});
test('should render - png (default)', (assert) => {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
// Test some bad parameter passings
assert.throws(function() { map.renderSync(null); });
assert.throws(function() { map.renderSync({format:null}); });
assert.throws(function() { map.renderSync({palette:null}); });
assert.throws(function() { map.renderSync({palette:{}}); });
assert.throws(function() { map.renderSync({scale:null}); });
assert.throws(function() { map.renderSync({scale_denominator:null}); });
assert.throws(function() { map.renderSync({buffer_size:null}); });
var out = map.renderSync();
assert.ok(out);
assert.end();
});
test('should render - tiff', (assert) => {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
var out = map.renderSync({format:'tiff'});
assert.ok(out);
assert.end();
});
test('should render - scale', (assert) => {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
var out = map.renderSync({scale:2});
assert.ok(out);
assert.end();
});
test('should render - scale_denominator', (assert) => {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
var out = map.renderSync({scale_denominator:2});
assert.ok(out);
assert.end();
});
test('should render - buffer_size', (assert) => {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
var out = map.renderSync({buffer_size:2});
assert.ok(out);
assert.end();
});
test('should fail to render - png', (assert) => {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
map.srs = 'pie';
assert.throws(function() { map.renderSync(); });
assert.end();
});
test('should render to a file', (assert) => {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
var filename = helper.filename();
var layers = map.layers();
assert.equal(layers[0].describe().styles[0], 'style');
// Test some bad parameter passings
assert.throws(function() { map.renderFileSync(); });
assert.throws(function() { map.renderFileSync(1); });
assert.throws(function() { map.renderFileSync(filename,2,3); });
assert.throws(function() { map.renderFileSync(filename, null); });
assert.throws(function() { map.renderFileSync(filename, {format:null}); });
assert.throws(function() { map.renderFileSync(filename, {palette:null}); });
assert.throws(function() { map.renderFileSync(filename, {palette:{}}); });
assert.throws(function() { map.renderFileSync(filename, {scale:null}); });
assert.throws(function() { map.renderFileSync(filename, {scale_denominator:null}); });
assert.throws(function() { map.renderFileSync(filename, {buffer_size:null}); });
assert.throws(function() { map.renderFileSync('test/data/tmp', {format:''}); });
map.renderFileSync(filename);
assert.ok(exists(filename));
assert.end();
});
test('should fail render to a file', (assert) => {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
var layers = map.layers();
map.srs = 'pie';
layers[0].srs = 'pizza';
var filename = helper.filename();
assert.throws(function() { map.renderFileSync(filename, {format:''}); });
assert.end();
});
test('should render to a file - empty format', (assert) => {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
var filename = helper.filename();
map.renderFileSync(filename, {format:''});
assert.ok(exists(filename));
assert.end();
});
test('should render to a file - tiff', (assert) => {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
var filename = helper.filename();
map.renderFileSync(filename, {format:'tiff'});
assert.ok(exists(filename));
assert.end();
});
if (mapnik.supports.cairo) {
test('should render to a file - pdf', (assert) => {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
var filename = helper.filename();
map.renderFileSync(filename, {format:'pdf'});
assert.ok(exists(filename));
assert.end();
});
} else {
test.skip('should render to a file - pdf', function() { });
}
test('should render to a file - scale', (assert) => {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
var filename = helper.filename();
map.renderFileSync(filename, {scale:2});
assert.ok(exists(filename));
assert.end();
});
test('should render to a file - scale_denominator', (assert) => {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
var filename = helper.filename();
map.renderFileSync(filename, {scale_denominator:2});
assert.ok(exists(filename));
assert.end();
});
test('should render to a file - buffer_size', (assert) => {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
var filename = helper.filename();
map.renderFileSync(filename, {buffer_size:2});
assert.ok(exists(filename));
assert.end();
});
test('should render to a file - zoom to box', (assert) => {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
assert.throws(function() { map.zoomToBox(1); });
assert.throws(function() { map.zoomToBox(1,2,3); });
assert.throws(function() { map.zoomToBox('1',2,3,4); });
map.zoomToBox([10,10,11,11]);
map.zoomToBox(10,10,11,11);
var filename = helper.filename();
map.renderFileSync(filename);
assert.ok(exists(filename));
assert.end();
});
test('should fail to zoomAll properly - throwing exception', (assert) => {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
var layer = map.layers();
map.srs = 'pie';
layer[0].srs = 'pizza';
assert.throws(function() { map.zoomAll(); });
assert.end();
});