-
Notifications
You must be signed in to change notification settings - Fork 166
/
layers.test.js
68 lines (63 loc) · 2.54 KB
/
layers.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
"use strict";
var test = require('tape');
var mapnik = require('../');
var path = require('path');
test('should throw with invalid usage', (assert) => {
// no 'new' keyword
assert.throws(function() { mapnik.Layer('foo'); });
// invalid args
assert.throws(function() { new mapnik.Layer(); });
assert.throws(function() { new mapnik.Layer('foo', null); });
assert.throws(function() { new mapnik.Layer(1); });
assert.throws(function() { new mapnik.Layer('a', 'b', 'c'); });
assert.throws(function() { new mapnik.Layer(new mapnik.Layer('foo')); });
assert.end();
});
test('should initialize properly', (assert) => {
mapnik.register_datasource(path.join(mapnik.settings.paths.input_plugins,'shape.input'));
var layer = new mapnik.Layer('foo', 'epsg:4326');
assert.equal(layer.name, 'foo');
layer.active = true;
assert.equal(layer.active, true);
layer.queryable = false;
assert.equal(layer.queryable, false);
layer.clear_label_cache = false;
assert.equal(layer.clear_label_cache, false);
layer.minimum_scale_denominator = 1;
assert.equal(layer.minimum_scale_denominator, 1);
layer.maximum_scale_denominator = 50;
assert.equal(layer.maximum_scale_denominator, 50);
assert.throws(function() { layer.name = null; });
assert.throws(function() { layer.srs = null; });
assert.throws(function() { layer.styles = null; });
assert.throws(function() { layer.datasource = null; });
assert.throws(function() { layer.datasource = {}; });
assert.throws(function() { layer.active = null; });
assert.throws(function() { layer.minimum_scale_denominator = null; });
assert.throws(function() { layer.maximum_scale_denominator = null; });
assert.throws(function() { layer.queryable = null; });
assert.throws(function() { layer.clear_label_cache = null; });
assert.equal(layer.srs, 'epsg:4326');
assert.deepEqual(layer.styles, []);
// will be empty/undefined
assert.ok(!layer.datasource);
var options = {
type: 'shape',
file: './test/data/world_merc.shp'
};
var ds = new mapnik.Datasource(options);
layer.datasource = ds;
//assert.ok(layer.datasource instanceof mapnik.Datasource);
// json representation
var meta = layer.describe();
assert.equal(meta.minimum_scale_denominator, 1);
assert.equal(meta.maximum_scale_denominator, 50);
assert.equal(meta.active, true);
assert.equal(meta.queryable, false);
assert.equal(meta.clear_label_cache, false);
assert.equal(meta.name, 'foo');
assert.equal(meta.srs, 'epsg:4326');
assert.deepEqual(meta.styles, []);
assert.deepEqual(meta.datasource, options);
assert.end();
});