-
Notifications
You must be signed in to change notification settings - Fork 17
/
geojson-extent.js
1 lines (1 loc) · 18.9 KB
/
geojson-extent.js
1
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.geojsonExtent=e()}}(function(){return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){function getExtent(_){for(var ext=extent(),coords=geojsonCoords(_),i=0;i<coords.length;i++)ext.include(coords[i]);return ext}var geojsonCoords=require("@mapbox/geojson-coords"),traverse=require("neotraverse/legacy"),extent=require("@mapbox/extent"),geojsonTypesByDataAttributes={features:["FeatureCollection"],coordinates:["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"],geometry:["Feature"],geometries:["GeometryCollection"]},dataAttributes=Object.keys(geojsonTypesByDataAttributes);module.exports=function(_){return getExtent(_).bbox()},module.exports.polygon=function(_){return getExtent(_).polygon()},module.exports.bboxify=function(_){return traverse(_).map(function(value){if(value){var isValid=dataAttributes.some(function(attribute){return value[attribute]?-1!==geojsonTypesByDataAttributes[attribute].indexOf(value.type):!1});isValid&&(value.bbox=getExtent(value).bbox(),this.update(value))}})}},{"@mapbox/extent":2,"@mapbox/geojson-coords":4,"neotraverse/legacy":7}],2:[function(require,module,exports){function Extent(bbox){return this instanceof Extent?(this._bbox=bbox||[1/0,1/0,-(1/0),-(1/0)],void(this._valid=!!bbox)):new Extent(bbox)}module.exports=Extent,Extent.prototype.include=function(ll){return this._valid=!0,this._bbox[0]=Math.min(this._bbox[0],ll[0]),this._bbox[1]=Math.min(this._bbox[1],ll[1]),this._bbox[2]=Math.max(this._bbox[2],ll[0]),this._bbox[3]=Math.max(this._bbox[3],ll[1]),this},Extent.prototype.equals=function(_){var other;return other=_ instanceof Extent?_.bbox():_,this._bbox[0]==other[0]&&this._bbox[1]==other[1]&&this._bbox[2]==other[2]&&this._bbox[3]==other[3]},Extent.prototype.center=function(_){return this._valid?[(this._bbox[0]+this._bbox[2])/2,(this._bbox[1]+this._bbox[3])/2]:null},Extent.prototype.union=function(_){this._valid=!0;var other;return other=_ instanceof Extent?_.bbox():_,this._bbox[0]=Math.min(this._bbox[0],other[0]),this._bbox[1]=Math.min(this._bbox[1],other[1]),this._bbox[2]=Math.max(this._bbox[2],other[2]),this._bbox[3]=Math.max(this._bbox[3],other[3]),this},Extent.prototype.bbox=function(){return this._valid?this._bbox:null},Extent.prototype.contains=function(ll){if(!ll)return this._fastContains();if(!this._valid)return null;var lon=ll[0],lat=ll[1];return this._bbox[0]<=lon&&this._bbox[1]<=lat&&this._bbox[2]>=lon&&this._bbox[3]>=lat},Extent.prototype.intersect=function(_){if(!this._valid)return null;var other;return other=_ instanceof Extent?_.bbox():_,!(this._bbox[0]>other[2]||this._bbox[2]<other[0]||this._bbox[3]<other[1]||this._bbox[1]>other[3])},Extent.prototype._fastContains=function(){if(!this._valid)return new Function("return null;");var body="return "+this._bbox[0]+"<= ll[0] &&"+this._bbox[1]+"<= ll[1] &&"+this._bbox[2]+">= ll[0] &&"+this._bbox[3]+">= ll[1]";return new Function("ll",body)},Extent.prototype.polygon=function(){return this._valid?{type:"Polygon",coordinates:[[[this._bbox[0],this._bbox[1]],[this._bbox[2],this._bbox[1]],[this._bbox[2],this._bbox[3]],[this._bbox[0],this._bbox[3]],[this._bbox[0],this._bbox[1]]]]}:null}},{}],3:[function(require,module,exports){module.exports=function(list){function _flatten(list){return Array.isArray(list)&&list.length&&"number"==typeof list[0]?[list]:list.reduce(function(acc,item){return Array.isArray(item)&&Array.isArray(item[0])?acc.concat(_flatten(item)):(acc.push(item),acc)},[])}return _flatten(list)}},{}],4:[function(require,module,exports){var geojsonNormalize=require("@mapbox/geojson-normalize"),geojsonFlatten=require("geojson-flatten"),flatten=require("./flatten");geojsonFlatten instanceof Function||(geojsonFlatten=geojsonFlatten["default"]),module.exports=function(_){if(!_)return[];var normalized=geojsonFlatten(geojsonNormalize(_)),coordinates=[];return normalized.features.forEach(function(feature){feature.geometry&&(coordinates=coordinates.concat(flatten(feature.geometry.coordinates)))}),coordinates}},{"./flatten":3,"@mapbox/geojson-normalize":5,"geojson-flatten":6}],5:[function(require,module,exports){function normalize(gj){if(!gj||!gj.type)return null;var type=types[gj.type];return type?"geometry"===type?{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:gj}]}:"feature"===type?{type:"FeatureCollection",features:[gj]}:"featurecollection"===type?gj:void 0:null}module.exports=normalize;var types={Point:"geometry",MultiPoint:"geometry",LineString:"geometry",MultiLineString:"geometry",Polygon:"geometry",MultiPolygon:"geometry",GeometryCollection:"geometry",Feature:"feature",FeatureCollection:"featurecollection"}},{}],6:[function(require,module,exports){module.exports=function e(t){switch(t&&t.type||null){case"FeatureCollection":return t.features=t.features.reduce(function(t,r){return t.concat(e(r))},[]),t;case"Feature":return t.geometry?e(t.geometry).map(function(e){var r={type:"Feature",properties:JSON.parse(JSON.stringify(t.properties)),geometry:e};return void 0!==t.id&&(r.id=t.id),r}):[t];case"MultiPoint":return t.coordinates.map(function(e){return{type:"Point",coordinates:e}});case"MultiPolygon":return t.coordinates.map(function(e){return{type:"Polygon",coordinates:e}});case"MultiLineString":return t.coordinates.map(function(e){return{type:"LineString",coordinates:e}});case"GeometryCollection":return t.geometries.map(e).reduce(function(e,t){return e.concat(t)},[]);case"Point":case"Polygon":case"LineString":return[t]}}},{}],7:[function(require,module,exports){"use strict";function _array_like_to_array(arr,len){(null==len||len>arr.length)&&(len=arr.length);for(var i=0,arr2=new Array(len);len>i;i++)arr2[i]=arr[i];return arr2}function _array_with_holes(arr){return Array.isArray(arr)?arr:void 0}function _class_call_check(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}}function _create_class(Constructor,protoProps,staticProps){return protoProps&&_defineProperties(Constructor.prototype,protoProps),staticProps&&_defineProperties(Constructor,staticProps),Constructor}function _instanceof(left,right){return null!=right&&"undefined"!=typeof Symbol&&right[Symbol.hasInstance]?!!right[Symbol.hasInstance](left):left instanceof right}function _iterable_to_array_limit(arr,i){var _i=null==arr?null:"undefined"!=typeof Symbol&&arr[Symbol.iterator]||arr["@@iterator"];if(null!=_i){var _s,_e,_arr=[],_n=!0,_d=!1;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!i||_arr.length!==i);_n=!0);}catch(err){_d=!0,_e=err}finally{try{_n||null==_i["return"]||_i["return"]()}finally{if(_d)throw _e}}return _arr}}function _non_iterable_rest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _sliced_to_array(arr,i){return _array_with_holes(arr)||_iterable_to_array_limit(arr,i)||_unsupported_iterable_to_array(arr,i)||_non_iterable_rest()}function _type_of(obj){"@swc/helpers - typeof";return obj&&"undefined"!=typeof Symbol&&obj.constructor===Symbol?"symbol":typeof obj}function _unsupported_iterable_to_array(o,minLen){if(o){if("string"==typeof o)return _array_like_to_array(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);return"Object"===n&&o.constructor&&(n=o.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_array_like_to_array(o,minLen):void 0}}function own_enumerable_keys(obj){for(var res=Object.keys(obj),symbols=get_own_property_symbols(obj),i=0;i<symbols.length;i++)is_property_enumerable.call(obj,symbols[i])&&res.push(symbols[i]);return res}function is_writable(object,key){var _gopd;return!(null===(_gopd=gopd(object,key))||void 0===_gopd?void 0:_gopd.writable)}function copy(src,options){if("object"===("undefined"==typeof src?"undefined":_type_of(src))&&null!==src){var dst;if(is_array(src))dst=[];else if(is_date(src))dst=new Date(src.getTime?src.getTime():src);else if(is_regexp(src))dst=new RegExp(src);else if(is_error(src))dst={message:src.message};else if(is_boolean(src)||is_number(src)||is_string(src))dst=Object(src);else{if(is_typed_array(src))return src.slice();dst=Object.create(Object.getPrototypeOf(src))}var iterator_function=options.includeSymbols?own_enumerable_keys:Object.keys,_iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0;try{for(var _step,_iterator=iterator_function(src)[Symbol.iterator]();!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=!0){var key=_step.value;dst[key]=src[key]}}catch(err){_didIteratorError=!0,_iteratorError=err}finally{try{_iteratorNormalCompletion||null==_iterator["return"]||_iterator["return"]()}finally{if(_didIteratorError)throw _iteratorError}}return dst}return src}function walk(root,cb){var options=arguments.length>2&&void 0!==arguments[2]?arguments[2]:empty_null,path=[],parents=[],alive=!0,iterator_function=options.includeSymbols?own_enumerable_keys:Object.keys,immutable=!!options.immutable;return function walker(node_){function update_state(){if("object"===_type_of(state.node)&&null!==state.node){state.keys&&state.node_===state.node||(state.keys=iterator_function(state.node)),state.isLeaf=0===state.keys.length;for(var i=0;i<parents.length;i++)if(parents[i].node_===node_){state.circular=parents[i];break}}else state.isLeaf=!0,state.keys=null;state.notLeaf=!state.isLeaf,state.notRoot=!state.isRoot}var node=immutable?copy(node_,options):node_,modifiers={},keep_going=!0,state={node:node,node_:node_,path:[].concat(path),parent:parents[parents.length-1],parents:parents,key:path[path.length-1],isRoot:0===path.length,level:path.length,circular:void 0,isLeaf:!1,notLeaf:!0,notRoot:!0,isFirst:!1,isLast:!1,update:function(x){var stopHere=arguments.length>1&&void 0!==arguments[1]?arguments[1]:!1;state.isRoot||(state.parent.node[state.key]=x),state.node=x,stopHere&&(keep_going=!1)},"delete":function(stopHere){delete state.parent.node[state.key],stopHere&&(keep_going=!1)},remove:function(stopHere){is_array(state.parent.node)?state.parent.node.splice(state.key,1):delete state.parent.node[state.key],stopHere&&(keep_going=!1)},keys:null,before:function(f){modifiers.before=f},after:function(f){modifiers.after=f},pre:function(f){modifiers.pre=f},post:function(f){modifiers.post=f},stop:function(){alive=!1},block:function(){keep_going=!1}};if(!alive)return state;update_state();var ret=cb.call(state,state.node);if(void 0!==ret&&state.update&&state.update(ret),modifiers.before&&modifiers.before.call(state,state.node),!keep_going)return state;if("object"===_type_of(state.node)&&null!==state.node&&!state.circular){parents.push(state),update_state();var _state_keys,_iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0;try{for(var _step,_iterator=Object.entries(null!==(_state_keys=state.keys)&&void 0!==_state_keys?_state_keys:[])[Symbol.iterator]();!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=!0){var _state_keys1,_step_value=_sliced_to_array(_step.value,2),index=_step_value[0],key=_step_value[1];path.push(key),modifiers.pre&&modifiers.pre.call(state,state.node[key],key);var child=walker(state.node[key]);immutable&&has_own_property.call(state.node,key)&&!is_writable(state.node,key)&&(state.node[key]=child.node),child.isLast=(null===(_state_keys1=state.keys)||void 0===_state_keys1?void 0:_state_keys1.length)?+index===state.keys.length-1:!1,child.isFirst=0===+index,modifiers.post&&modifiers.post.call(state,child),path.pop()}}catch(err){_didIteratorError=!0,_iteratorError=err}finally{try{_iteratorNormalCompletion||null==_iterator["return"]||_iterator["return"]()}finally{if(_didIteratorError)throw _iteratorError}}parents.pop()}return modifiers.after&&modifiers.after.call(state,state.node),state}(root).node}var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__typeError=function(msg){throw TypeError(msg)},__export=function(target,all){for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=function(to,from,except,desc){if(from&&"object"===("undefined"==typeof from?"undefined":_type_of(from))||"function"==typeof from){var _iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0;try{for(var _step,_loop=function(){var key=_step.value;__hasOwnProp.call(to,key)||key===except||__defProp(to,key,{get:function(){return from[key]},enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})},_iterator=__getOwnPropNames(from)[Symbol.iterator]();!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=!0)_loop()}catch(err){_didIteratorError=!0,_iteratorError=err}finally{try{_iteratorNormalCompletion||null==_iterator["return"]||_iterator["return"]()}finally{if(_didIteratorError)throw _iteratorError}}}return to},__toCommonJS=function(mod){return __copyProps(__defProp({},"__esModule",{value:!0}),mod)},__accessCheck=function(obj,member,msg){return member.has(obj)||__typeError("Cannot "+msg)},__privateGet=function(obj,member,getter){return __accessCheck(obj,member,"read from private field"),getter?getter.call(obj):member.get(obj)},__privateAdd=function(obj,member,value){return member.has(obj)?__typeError("Cannot add the same private member more than once"):_instanceof(member,WeakSet)?member.add(obj):member.set(obj,value)},__privateSet=function(obj,member,value,setter){return __accessCheck(obj,member,"write to private field"),setter?setter.call(obj,value):member.set(obj,value),value},legacy_exports={};__export(legacy_exports,{"default":function(){return src_default}}),module.exports=__toCommonJS(legacy_exports);var _value,_options,to_string=function(obj){return Object.prototype.toString.call(obj)},is_typed_array=function(value){return ArrayBuffer.isView(value)&&!_instanceof(value,DataView)},is_date=function(obj){return"[object Date]"===to_string(obj)},is_regexp=function(obj){return"[object RegExp]"===to_string(obj)},is_error=function(obj){return"[object Error]"===to_string(obj)},is_boolean=function(obj){return"[object Boolean]"===to_string(obj)},is_number=function(obj){return"[object Number]"===to_string(obj)},is_string=function(obj){return"[object String]"===to_string(obj)},is_array=Array.isArray,gopd=Object.getOwnPropertyDescriptor,is_property_enumerable=Object.prototype.propertyIsEnumerable,get_own_property_symbols=Object.getOwnPropertySymbols,has_own_property=Object.prototype.hasOwnProperty,empty_null={includeSymbols:!1,immutable:!1},Traverse=function(){function Traverse(obj){var options=arguments.length>1&&void 0!==arguments[1]?arguments[1]:empty_null;_class_call_check(this,Traverse),__privateAdd(this,_value),__privateAdd(this,_options),__privateSet(this,_value,obj),__privateSet(this,_options,options)}return _create_class(Traverse,[{key:"get",value:function(paths){for(var node=__privateGet(this,_value),i=0;node&&i<paths.length;i++){var key=paths[i];if(!has_own_property.call(node,key)||!__privateGet(this,_options).includeSymbols&&"symbol"===("undefined"==typeof key?"undefined":_type_of(key)))return void 0;node=node[key]}return node}},{key:"has",value:function(paths){for(var node=__privateGet(this,_value),i=0;node&&i<paths.length;i++){var key=paths[i];if(!has_own_property.call(node,key)||!__privateGet(this,_options).includeSymbols&&"symbol"===("undefined"==typeof key?"undefined":_type_of(key)))return!1;node=node[key]}return!0}},{key:"set",value:function(path,value){var node=__privateGet(this,_value),i=0;for(i=0;i<path.length-1;i++){var key=path[i];has_own_property.call(node,key)||(node[key]={}),node=node[key]}return node[path[i]]=value,value}},{key:"map",value:function(cb){return walk(__privateGet(this,_value),cb,{immutable:!0,includeSymbols:!!__privateGet(this,_options).includeSymbols})}},{key:"forEach",value:function(cb){return __privateSet(this,_value,walk(__privateGet(this,_value),cb,__privateGet(this,_options))),__privateGet(this,_value)}},{key:"reduce",value:function(cb,init){var skip=1===arguments.length,acc=skip?__privateGet(this,_value):init;return this.forEach(function(x){this.isRoot&&skip||(acc=cb.call(this,acc,x))}),acc}},{key:"paths",value:function(){var acc=[];return this.forEach(function(){acc.push(this.path)}),acc}},{key:"nodes",value:function(){var acc=[];return this.forEach(function(){acc.push(this.node)}),acc}},{key:"clone",value:function(){var parents=[],nodes=[],options=__privateGet(this,_options);return is_typed_array(__privateGet(this,_value))?__privateGet(this,_value).slice():function clone(src){for(var i=0;i<parents.length;i++)if(parents[i]===src)return nodes[i];if("object"===("undefined"==typeof src?"undefined":_type_of(src))&&null!==src){var dst=copy(src,options);parents.push(src),nodes.push(dst);var iteratorFunction=options.includeSymbols?own_enumerable_keys:Object.keys,_iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0;try{for(var _step,_iterator=iteratorFunction(src)[Symbol.iterator]();!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=!0){var key=_step.value;dst[key]=clone(src[key])}}catch(err){_didIteratorError=!0,_iteratorError=err}finally{try{_iteratorNormalCompletion||null==_iterator["return"]||_iterator["return"]()}finally{if(_didIteratorError)throw _iteratorError}}return parents.pop(),nodes.pop(),dst}return src}(__privateGet(this,_value))}}]),Traverse}();_value=new WeakMap,_options=new WeakMap;var traverse=function(obj,options){return new Traverse(obj,options)};traverse.get=function(obj,paths,options){return new Traverse(obj,options).get(paths)},traverse.set=function(obj,path,value,options){return new Traverse(obj,options).set(path,value)},traverse.has=function(obj,paths,options){return new Traverse(obj,options).has(paths)},traverse.map=function(obj,cb,options){return new Traverse(obj,options).map(cb)},traverse.forEach=function(obj,cb,options){return new Traverse(obj,options).forEach(cb)},traverse.reduce=function(obj,cb,init,options){return new Traverse(obj,options).reduce(cb,init)},traverse.paths=function(obj,options){return new Traverse(obj,options).paths()},traverse.nodes=function(obj,options){return new Traverse(obj,options).nodes()},traverse.clone=function(obj,options){return new Traverse(obj,options).clone()};var src_default=traverse;module.exports=src_default},{}]},{},[1])(1)});