UNPKG

732 BJavaScriptView Raw
1var geojsonCoords = require('geojson-coords'),
2 traverse = require('traverse'),
3 extent = require('extent');
4
5module.exports = function(_) {
6 return getExtent(_).bbox();
7};
8
9module.exports.polygon = function(_) {
10 return getExtent(_).polygon();
11};
12
13module.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
22function 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}