UNPKG

geojson-bounding-box

Version:
2 lines (1 loc) 1.01 kB
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):(e=e||self).GeojsonBoundingBox=o()}(this,function(){"use strict";return function(e){const o=[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY];let t=2;for(const n of function*e(o){switch(o.type){case"Point":yield o.coordinates;break;case"LineString":case"MultiPoint":yield*o.coordinates;break;case"Polygon":case"MultiLineString":for(const e of o.coordinates)yield*e;break;case"MultiPolygon":for(const e of o.coordinates)for(const o of e)yield*o;break;case"GeometryCollection":for(const t of o.geometries)yield*e(t);break;case"FeatureCollection":for(const t of o.features)yield*e(t);break;default:yield*e(o.geometry)}}(e)){t=Math.max(t,n.length);for(let e=0;e<n.length;++e){const t=3+e;o[e]=Math.min(o[e],n[e]),o[t]=Math.max(o[t],n[e])}}return 3!==t?[o[0],o[1],o[3],o[4]]:o}});