UNPKG

6.46 kBJavaScriptView Raw
1var test = require('tap').test,
2geojsonExtent = 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('bboxify', function(t) {
15 t.deepEqual(geojsonExtent.bboxify({
16 type: 'Point',
17 coordinates: [0, 0]
18 }), {
19 type: 'Point',
20 coordinates: [0, 0],
21 bbox: [0, 0, 0, 0]
22 }, 'a single point');
23
24 t.deepEqual(geojsonExtent.bboxify({ "type": "FeatureCollection",
25 "features": [
26 { "type": "Feature",
27 "geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
28 "properties": {"prop0": "value0"}
29 },
30 { "type": "Feature",
31 "geometry": {
32 "type": "LineString",
33 "coordinates": [
34 [102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]
35 ]
36 },
37 "properties": {
38 "prop0": "value0",
39 "prop1": 0.0
40 }
41 },
42 { "type": "Feature",
43 "geometry": {
44 "type": "Polygon",
45 "coordinates": [
46 [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
47 [100.0, 1.0], [100.0, 0.0] ]
48 ]
49 },
50 "properties": {
51 "prop0": "value0",
52 "prop1": {"this": "that"}
53 }
54 }
55 ]
56 }), {
57 "type": "FeatureCollection",
58 "features": [
59 {
60 "type": "Feature",
61 "properties": {
62 "prop0": "value0"
63 },
64 "geometry": {
65 "type": "Point",
66 "coordinates": [
67 102,
68 0.5
69 ],
70 "bbox": [
71 102,
72 0.5,
73 102,
74 0.5
75 ]
76 },
77 "bbox": [
78 102,
79 0.5,
80 102,
81 0.5
82 ]
83 },
84 {
85 "type": "Feature",
86 "properties": {
87 "prop0": "value0",
88 "prop1": 0
89 },
90 "geometry": {
91 "type": "LineString",
92 "coordinates": [
93 [
94 102,
95 0
96 ],
97 [
98 103,
99 1
100 ],
101 [
102 104,
103 0
104 ],
105 [
106 105,
107 1
108 ]
109 ],
110 "bbox": [
111 102,
112 0,
113 105,
114 1
115 ]
116 },
117 "bbox": [
118 102,
119 0,
120 105,
121 1
122 ]
123 },
124 {
125 "type": "Feature",
126 "properties": {
127 "prop0": "value0",
128 "prop1": {
129 "this": "that"
130 }
131 },
132 "geometry": {
133 "type": "Polygon",
134 "coordinates": [
135 [
136 [
137 100,
138 0
139 ],
140 [
141 101,
142 0
143 ],
144 [
145 101,
146 1
147 ],
148 [
149 100,
150 1
151 ],
152 [
153 100,
154 0
155 ]
156 ]
157 ],
158 "bbox": [
159 100,
160 0,
161 101,
162 1
163 ]
164 },
165 "bbox": [
166 100,
167 0,
168 101,
169 1
170 ]
171 }
172 ],
173 "bbox": [
174 100,
175 0,
176 105,
177 1
178 ]
179}, 'a single point');
180 t.end();
181});
182
183test('extent', function(t) {
184 t.deepEqual(geojsonExtent({
185 type: 'Point',
186 coordinates: [0, 0]
187 }), [0, 0, 0, 0], 'a single point');
188
189 t.deepEqual(geojsonExtent({
190 "type": "MultiPoint",
191 "coordinates": [ [100.0, 0.0], [101.0, 1.0] ]
192 }), [100, 0, 101, 1], 'multipoint');
193
194 t.deepEqual(geojsonExtent.polygon({
195 "type": "MultiPoint",
196 "coordinates": [ [100.0, 0.0], [101.0, 1.0] ]
197 }), {
198 type: 'Polygon',
199 coordinates: [[[100,0],[101,0],[101,1],[100,1],[100,0]]]
200 }, 'multipoint');
201
202 t.deepEqual(geojsonExtent(
203 { "type": "GeometryCollection",
204 "geometries": [
205 { "type": "Point",
206 "coordinates": [100.0, 0.0]
207 },
208 { "type": "LineString",
209 "coordinates": [ [101.0, 0.0], [102.0, 1.0] ]
210 }
211 ]
212 }), [100, 0, 102, 1], 'multigeometry');
213
214 t.deepEqual(geojsonExtent({ "type": "MultiPolygon",
215 "coordinates": [
216 [[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],
217 [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
218 [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]
219 ]
220 }), [100, 0, 103, 3], 'multipolygon');
221
222 t.deepEqual(geojsonExtent( { "type": "FeatureCollection",
223 "features": [
224 { "type": "Feature",
225 "geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
226 "properties": {"prop0": "value0"}
227 },
228 { "type": "Feature",
229 "geometry": {
230 "type": "LineString",
231 "coordinates": [
232 [102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]
233 ]
234 },
235 "properties": {
236 "prop0": "value0",
237 "prop1": 0.0
238 }
239 },
240 { "type": "Feature",
241 "geometry": {
242 "type": "Polygon",
243 "coordinates": [
244 [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
245 [100.0, 1.0], [100.0, 0.0] ]
246 ]
247 },
248 "properties": {
249 "prop0": "value0",
250 "prop1": {"this": "that"}
251 }
252 }
253 ]
254 }), [100, 0, 105, 1], 'example from geojson.org');
255 t.end();
256});