1 | var geojsonCoords = require('geojson-coords'),
|
2 | traverse = require('traverse'),
|
3 | extent = require('extent');
|
4 |
|
5 | module.exports = function(_) {
|
6 | return getExtent(_).bbox();
|
7 | };
|
8 |
|
9 | module.exports.polygon = function(_) {
|
10 | return getExtent(_).polygon();
|
11 | };
|
12 |
|
13 | module.exports.bboxify = function(_) {
|
14 | return traverse(_).map(function(value) {
|
15 | if (value && typeof value.type === 'string') {
|
16 | value.bbox = getExtent(value).bbox();
|
17 | this.update(value);
|
18 | }
|
19 | });
|
20 | };
|
21 |
|
22 | function getExtent(_) {
|
23 | var bbox = [Infinity, Infinity, -Infinity, -Infinity],
|
24 | ext = extent(),
|
25 | coords = geojsonCoords(_);
|
26 | for (var i = 0; i < coords.length; i++) ext.include(coords[i]);
|
27 | return ext;
|
28 | }
|