UNPKG

2.29 kBJavaScriptView Raw
1var test = require('tap').test,
2 geojsonExtent = require('../');
3
4
5test('corners', function(t) {
6 t.equal(geojsonExtent(null), null, 'null');
7 t.equal(geojsonExtent({
8 type: 'FeatureCollection',
9 features: []
10 }), null, 'no features');
11 t.end();
12});
13
14test('extent', function(t) {
15 t.deepEqual(geojsonExtent({
16 type: 'Point',
17 coordinates: [0, 0]
18 }), [0, 0, 0, 0], 'a single point');
19
20 t.deepEqual(geojsonExtent({
21 "type": "MultiPoint",
22 "coordinates": [ [100.0, 0.0], [101.0, 1.0] ]
23 }), [100, 0, 101, 1], 'multipoint');
24
25 t.deepEqual(geojsonExtent(
26 { "type": "GeometryCollection",
27 "geometries": [
28 { "type": "Point",
29 "coordinates": [100.0, 0.0]
30 },
31 { "type": "LineString",
32 "coordinates": [ [101.0, 0.0], [102.0, 1.0] ]
33 }
34 ]
35 }), [100, 0, 102, 1], 'multigeometry');
36
37 t.deepEqual(geojsonExtent({ "type": "MultiPolygon",
38 "coordinates": [
39 [[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],
40 [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
41 [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]
42 ]
43 }), [100, 0, 103, 3], 'multipolygon');
44
45 t.deepEqual(geojsonExtent( { "type": "FeatureCollection",
46 "features": [
47 { "type": "Feature",
48 "geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
49 "properties": {"prop0": "value0"}
50 },
51 { "type": "Feature",
52 "geometry": {
53 "type": "LineString",
54 "coordinates": [
55 [102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]
56 ]
57 },
58 "properties": {
59 "prop0": "value0",
60 "prop1": 0.0
61 }
62 },
63 { "type": "Feature",
64 "geometry": {
65 "type": "Polygon",
66 "coordinates": [
67 [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
68 [100.0, 1.0], [100.0, 0.0] ]
69 ]
70 },
71 "properties": {
72 "prop0": "value0",
73 "prop1": {"this": "that"}
74 }
75 }
76 ]
77 }), [100, 0, 105, 1], 'example from geojson.org');
78 t.end();
79});