forked from mapnik/node-mapnik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid.test.js
162 lines (149 loc) · 5.83 KB
/
grid.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
"use strict";
var test = require('tape');
var mapnik = require('../');
var path = require('path');
if (mapnik.supports.grid) {
mapnik.register_datasource(path.join(mapnik.settings.paths.input_plugins,'csv.input'));
test('should throw with invalid usage', (assert) => {
// no 'new' keyword
assert.throws(function() { mapnik.Grid(1, 1); });
// invalid args
assert.throws(function() { new mapnik.Grid(); });
assert.throws(function() { new mapnik.Grid(1); });
assert.throws(function() { new mapnik.Grid('foo'); });
assert.throws(function() { new mapnik.Grid('a', 'b', 'c'); });
assert.throws(function() { new mapnik.Grid(256,256,null); });
assert.throws(function() { new mapnik.Grid(256,256,{key:null}); });
assert.end();
});
test('should be initialized properly', (assert) => {
var grid = new mapnik.Grid(256, 256);
assert.ok(grid instanceof mapnik.Grid);
assert.equal(grid.width(), 256);
assert.equal(grid.height(), 256);
var v = grid.view(0, 0, 256, 256);
assert.ok(v instanceof mapnik.GridView);
assert.equal(v.width(), 256);
assert.equal(v.height(), 256);
assert.equal(grid.encodeSync({features:true}).length, v.encodeSync().length);
assert.end();
});
test('should fail to encode properly', (assert) => {
var grid = new mapnik.Grid(256, 256);
assert.throws(function() { grid.encodeSync("foo"); });
assert.throws(function() { grid.encode("foo"); });
assert.throws(function() { grid.encode("foo", function(err, result) {}); });
assert.throws(function() { grid.encodeSync({features:null}); });
assert.throws(function() { grid.encodeSync({resolution:null}); });
assert.throws(function() { grid.encodeSync({resolution:0}); });
assert.throws(function() { grid.encode({features:null}, function(err, result) {}); });
assert.throws(function() { grid.encode({resolution:null}, function(err, result) {}); });
assert.throws(function() { grid.encode({resolution:0}, function(err, result) {}); });
assert.throws(function() { grid.encode({resolution:4}, null); });
assert.end();
});
test('should encode properly', (assert) => {
var grid = new mapnik.Grid(256, 256);
grid.encode({resolution:4, features:true}, function(err, result) {
if (err) throw err;
assert.ok(result);
assert.end();
});
});
test('should not be painted after rendering', (assert) => {
var grid_blank = new mapnik.Grid(4, 4);
assert.equal(grid_blank.painted(), false);
assert.equal(grid_blank.background, undefined);
var m = new mapnik.Map(4, 4);
var l = new mapnik.Layer('test');
m.add_layer(l);
m.render(grid_blank, {layer: 0},function(err,grid_blank) {
assert.equal(grid_blank.painted(), false);
// TODO - expose grid background
//assert.equal(grid_blank.background, undefined);
assert.end();
});
});
test('should be have background applied after rendering', (assert) => {
var grid_blank = new mapnik.Grid(4, 4);
var m = new mapnik.Map(4, 4);
var l = new mapnik.Layer('test');
m.add_layer(l);
m.background = new mapnik.Color('green');
m.render(grid_blank, {layer: 0},function(err,grid_blank2) {
assert.equal(grid_blank2.painted(), false);
// TODO - expose grid background
//assert.ok(grid_blank2.background);
assert.end();
});
});
test('should be painted after rendering 2', (assert) => {
var grid_blank3 = new mapnik.Grid(4, 4);
assert.equal(grid_blank3.painted(), false);
assert.equal(grid_blank3.background, undefined);
var m3 = new mapnik.Map(4, 4);
var s = '<Map>';
s += '<Style name="points">';
s += ' <Rule>';
s += ' <PointSymbolizer />';
s += ' </Rule>';
s += '</Style>';
s += '</Map>';
m3.fromStringSync(s);
var ds = new mapnik.Datasource({type:'csv', extent: '-180,-90,180,90', 'inline': "x,y\n0,0\n1,1\n2,2\n3,3"});
var l = new mapnik.Layer('test');
l.srs = m3.srs;
l.styles = ['points'];
l.datasource = ds;
m3.add_layer(l);
m3.zoomAll();
m3.render(grid_blank3, {layer: 0},function(err,grid_blank3) {
assert.equal(grid_blank3.painted(), true);
// TODO - expose grid background
//assert.equal(grid_blank3.background,undefined);
grid_blank3.key = "stuff";
assert.throws(function() { grid_blank3.key = null; });
assert.throws(function() { grid_blank3.clear(null); });
grid_blank3.clear(function(err, grid_blank4) {
assert.equal(grid_blank4.key, "stuff");
assert.equal(grid_blank4.painted(), false);
assert.end();
});
});
});
test('should be painted after rendering 3', (assert) => {
var grid_blank3 = new mapnik.Grid(4, 4);
assert.equal(grid_blank3.painted(), false);
assert.equal(grid_blank3.background, undefined);
var m3 = new mapnik.Map(4, 4);
var s = '<Map>';
s += '<Style name="points">';
s += ' <Rule>';
s += ' <PointSymbolizer />';
s += ' </Rule>';
s += '</Style>';
s += '</Map>';
m3.fromStringSync(s);
var ds = new mapnik.Datasource({type:'csv', extent: '-180,-90,180,90', 'inline': "x,y\n0,0\n1,1\n2,2\n3,3"});
var l = new mapnik.Layer('test');
l.srs = m3.srs;
l.styles = ['points'];
l.datasource = ds;
m3.add_layer(l);
m3.zoomAll();
m3.render(grid_blank3, {layer: 0},function(err,grid_blank3) {
assert.equal(grid_blank3.painted(), true);
assert.throws(function() { grid_blank3.addField(null); });
assert.throws(function() { grid_blank3.addField(); });
grid_blank3.addField("foo");
assert.deepEqual(grid_blank3.fields(), ["foo"]);
// TODO - expose grid background
//assert.equal(grid_blank3.background,undefined);
grid_blank3.clear();
assert.equal(grid_blank3.painted(), false);
grid_blank3.clearSync();
assert.equal(grid_blank3.painted(), false);
assert.end();
});
});
}