forked from mapnik/node-mapnik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
render-async.test.js
167 lines (155 loc) · 7.48 KB
/
render-async.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
"use strict";
var mapnik = require('../');
var assert = require('assert');
var exists = require('fs').existsSync || require('path').existsSync;
var path = require('path');
mapnik.register_datasource(path.join(mapnik.settings.paths.input_plugins,'shape.input'));
mapnik.register_datasource(path.join(mapnik.settings.paths.input_plugins,'gdal.input'));
describe('mapnik async rendering', function() {
it('should render to a file', function(done) {
var map = new mapnik.Map(600, 400);
var filename = './test/tmp/renderFile.png';
map.renderFile(filename, {scale:1, scale_denominator:0, buffer_size:0, variables:{pizza:'pie'}}, function(error) {
assert.ok(!error);
assert.ok(exists(filename));
done();
});
});
it('should fail to render two things at once', function() {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
var im = new mapnik.Image(map.width, map.height);
assert.throws(function() {
map.render(im, function(err, result) {});
map.render(im, function(err, result) {});
});
});
it('should fail to render two things at once with sync', function() {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
var im = new mapnik.Image(map.width, map.height);
assert.throws(function() {
map.render(im, function(err, result) {});
map.renderSync(im);
});
});
it('should fail to renderFile two things at once', function() {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
assert.throws(function() {
map.renderFile('./test/tmp/foo1.png', function(err, result) {});
map.renderFile('./test/tmp/foo2.png', function(err, result) {});
});
});
it('should fail to renderFile two things at once with Sync', function() {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
assert.throws(function() {
map.renderFile('./test/tmp/foo1.png', function(err, result) {});
map.renderFileSync('./test/tmp/foo2.png');
});
});
it('should fail to render to an image gray8', function(done) {
var map = new mapnik.Map(256, 256);
map.load('./test/stylesheet.xml', function(err,map) {
if (err) throw err;
map.zoomAll();
var im = new mapnik.Image(map.width, map.height, {type:mapnik.imageType.gray8});
assert.throws(function() { map.render(); } );
assert.throws(function() { map.render(im, null); } );
assert.throws(function() { map.render(null, function(err, im) {}); } );
assert.throws(function() { map.render({}, function(err, im) {}); } );
assert.throws(function() { map.render(im, null, function(err, im) {}); } );
assert.throws(function() { map.render(im, {buffer_size:null}, function(err, im) {}); } );
assert.throws(function() { map.render(im, {scale:null}, function(err, im) {}); } );
assert.throws(function() { map.render(im, {scale_denominator:null}, function(err, im) {}); } );
assert.throws(function() { map.render(im, {offset_x:null}, function(err, im) {}); } );
assert.throws(function() { map.render(im, {offset_y:null}, function(err, im) {}); } );
assert.throws(function() { map.render(im, {variables:null}, function(err, im) {}); } );
map.render(im, function(err, im) {
assert.throws(function() { if (err) throw err; });
done();
});
});
});
it('should fail to renderFile', function(done) {
var map = new mapnik.Map(256, 256);
map.load('./test/stylesheet.xml', function(err,map) {
if (err) throw err;
map.zoomAll();
map.srs = '+init=pizza';
var im = 'test/data/tmp';
assert.throws(function() { map.renderFile(); } );
assert.throws(function() { map.renderFile(im, null); } );
assert.throws(function() { map.renderFile(null, function(err, im) {}); } );
assert.throws(function() { map.renderFile({}, function(err, im) {}); } );
assert.throws(function() { map.renderFile(im, null, function(err, im) {}); } );
assert.throws(function() { map.renderFile(im, {buffer_size:null}, function(err, im) {}); } );
assert.throws(function() { map.renderFile(im, {scale:null}, function(err, im) {}); } );
assert.throws(function() { map.renderFile(im, {scale_denominator:null}, function(err, im) {}); } );
assert.throws(function() { map.renderFile(im, {format:null}, function(err, im) {}); } );
assert.throws(function() { map.renderFile(im, {format:''}, function(err, im) {}); } );
assert.throws(function() { map.renderFile(im, {variables:null}, function(err, im) {}); } );
assert.throws(function() { map.renderFile(im, {palette:null}, function(err, im) {}); } );
assert.throws(function() { map.renderFile(im, {palette:{}}, function(err, im) {}); } );
map.renderFile(im, function(err, im) {
assert.throws(function() { if (err) throw err; });
done();
});
});
});
it('should render to an image', function(done) {
var map = new mapnik.Map(256, 256);
map.load('./test/stylesheet.xml', function(err,map) {
if (err) throw err;
map.zoomAll();
var im = new mapnik.Image(map.width, map.height);
map.render(im, {variables: {pizza:'pie'}}, function(err, im) {
im.encode('png', {variables: {pizza:'pie'}}, function(err,buffer) {
assert.ok(buffer);
var string = im.toString();
assert.ok(string);
done();
});
});
});
});
it('should render to an image', function(done) {
var map = new mapnik.Map(256, 256);
map.load('./test/stylesheet.xml', function(err,map) {
if (err) throw err;
map.zoomAll();
var im = new mapnik.Image(map.width, map.height);
map.render(im, {variables: {pizza:'pie'}}, function(err, im) {
im.encode('png', {variables: {pizza:'pie'}}, function(err,buffer) {
assert.ok(buffer);
var string = im.toString();
assert.ok(string);
done();
});
});
});
});
it('should render to an image - raster', function(done) {
var map = new mapnik.Map(100, 100);
map.load('./test/raster.xml', function(err,map) {
if (err) throw err;
map.zoomAll();
var im = new mapnik.Image(map.width, map.height);
var im2 = new mapnik.Image.open('./test/data/images/sat_image-expected-100x100-near.png');
map.render(im, {variables: {pizza:'pie'}}, function(err, im) {
assert.equal(0, im.compare(im2));
im.encode('png', {variables: {pizza:'pie'}}, function(err,buffer) {
assert.ok(buffer);
var string = im.toString();
assert.ok(string);
done();
});
});
});
});
});