17 lines
160 KiB
JavaScript
17 lines
160 KiB
JavaScript
![]() |
/*!
|
|||
|
* kml与geojson互转工具类
|
|||
|
* 版本信息:v1.2.2, hash值: 2c1fdbb0bba3ef235857
|
|||
|
* 编译日期:2023-01-09 15:28:28
|
|||
|
* 版权所有:Copyright by 木遥 https://github.com/muyao1987/kml-geojson
|
|||
|
*
|
|||
|
*/
|
|||
|
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("kgUtil",[],e):"object"==typeof exports?exports.kgUtil=e():t.kgUtil=e()}(window,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=16)}([function(t,e,r){"use strict";(function(t){r.d(e,"a",(function(){return _}));var n,i=r(2),o=r.n(i),a=/\s*/g,s=/^\s*|\s*$/g,u=/\s+/;function l(t){if(!t||!t.length)return 0;for(var e=0,r=0;e<t.length;e++)r=(r<<5)-r+t.charCodeAt(e)|0;return r}function c(t,e){return t.getElementsByTagName(e)}function h(t,e){return t.getAttribute(e)}function f(t,e){var r=c(t,e);return r.length?r[0]:null}function d(t){for(var e=0,r=[];e<t.length;e++)r[e]=parseFloat(t[e]);return r}function p(t){var e;return t&&(e=t).normalize&&e.normalize(),t&&t.textContent||""}function m(t){return d(t.replace(a,"").split(","))}function g(t){for(var e=t.replace(s,"").split(u),r=[],n=0;n<e.length;n++)r.push(m(e[n]));return r}function y(t){return void 0!==t.xml?t.xml:n.serializeToString(t)}function _(t){for(var e={type:"FeatureCollection",features:[]},r={},n={},i={},o=["Polygon","LineString","Point","Track","gx:Track"],a=c(t,"Placemark"),s=c(t,"Style"),u=c(t,"StyleMap"),_=0;_<s.length;_++){var v=l(y(s[_])).toString(16);r["#"+h(s[_],"id")]=v,n[v]=s[_]}for(var w=0;w<u.length;w++){r["#"+h(u[w],"id")]=l(y(u[w])).toString(16);for(var b=c(u[w],"Pair"),k={},E=0;E<b.length;E++)k[p(f(b[E],"key"))]=p(f(b[E],"styleUrl"));i["#"+h(u[w],"id")]=k}for(var x=0;x<a.length;x++)e.features=e.features.concat(T(a[x]));function S(t){var e,r;return"#"===(t=t||"").substr(0,1)&&(t=t.substr(1)),6!==t.length&&3!==t.length||(e=t),8===t.length&&(r=parseInt(t.substr(0,2),16)/255,e="#"+t.substr(6,2)+t.substr(4,2)+t.substr(2,2)),[e,isNaN(r)?void 0:r]}function A(t){var e=c(t,"coord"),r=[],n=[];0===e.length&&(e=c(t,"gx:coord"));for(var i=0;i<e.length;i++)r.push(d(p(e[i]).split(" ")));for(var o=c(t,"when"),a=0;a<o.length;a++)n.push(p(o[a]));return{coords:r,times:n}}function T(t){var e,a=function t(e){var r,n,i,a,s,u=[],l=[];if(f(e,"MultiGeometry"))return t(f(e,"MultiGeometry"));if(f(e,"MultiTrack"))return t(f(e,"MultiTrack"));if(f(e,"gx:MultiTrack"))return t(f(e,"gx:MultiTrack"));for(i=0;i<o.length;i++)if(n=c(e,o[i]))for(a=0;a<n.length;a++)if(r=n[a],"Point"===o[i])u.push({type:"Point",coordinates:m(p(f(r,"coordinates")))});else if("LineString"===o[i])u.push({type:"LineString",coordinates:g(p(f(r,"coordinates")))});else if("Polygon"===o[i]){var h=c(r,"LinearRing"),d=[];for(s=0;s<h.length;s++)d.push(g(p(f(h[s],"coordinates"))));u.push({type:"Polygon",coordinates:d})}else if("Track"===o[i]||"gx:Track"===o[i]){var y=A(r);u.push({type:"LineString",coordinates:y.coords}),y.times.length&&l.push(y.times)}return{geoms:u,coordTimes:l}}(t),s={},u=p(f(t,"name")),l=p(f(t,"styleUrl")),d=p(f(t,"description")),y=f(t,"TimeSpan"),_=f(t,"TimeStamp"),v=f(t,"ExtendedData"),w=f(t,"LineStyle"),b=f(t,"PolyStyle"),k=f(t,"visibility");if(!a.geoms.length)return[];if(u&&(s.name=u),l){"#"!==l[0]&&(l="#"+l),s.styleUrl=l,r[l]&&(s.styleHash=r[l]),i[l]&&(s.styleMapHash=i[l],s.styleHash=r[i[l].normal]);var E=n[s.styleHash];E&&(w||(w=f(E,"LineStyle")),b||(b=f(E,"PolyStyle")))}if(d&&(s.description=d),y){var x=
|
|||
|
/*!
|
|||
|
* The buffer module from node.js, for the browser.
|
|||
|
*
|
|||
|
* @author Feross Aboukhadijeh <http://feross.org>
|
|||
|
* @license MIT
|
|||
|
*/
|
|||
|
var n=r(7),i=r(8),o=r(9);function a(){return u.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function s(t,e){if(a()<e)throw new RangeError("Invalid typed array length");return u.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=u.prototype:(null===t&&(t=new u(e)),t.length=e),t}function u(t,e,r){if(!(u.TYPED_ARRAY_SUPPORT||this instanceof u))return new u(t,e,r);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return h(this,t)}return l(this,t,e,r)}function l(t,e,r,n){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,r,n){if(e.byteLength,r<0||e.byteLength<r)throw new RangeError("'offset' is out of bounds");if(e.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");e=void 0===r&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,r):new Uint8Array(e,r,n);u.TYPED_ARRAY_SUPPORT?(t=e).__proto__=u.prototype:t=f(t,e);return t}(t,e,r,n):"string"==typeof e?function(t,e,r){"string"==typeof r&&""!==r||(r="utf8");if(!u.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|p(e,r),i=(t=s(t,n)).write(e,r);i!==n&&(t=t.slice(0,i));return t}(t,e,r):function(t,e){if(u.isBuffer(e)){var r=0|d(e.length);return 0===(t=s(t,r)).length||e.copy(t,0,0,r),t}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(n=e.length)!=n?s(t,0):f(t,e);if("Buffer"===e.type&&o(e.data))return f(t,e.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function c(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function h(t,e){if(c(e),t=s(t,e<0?0:0|d(e)),!u.TYPED_ARRAY_SUPPORT)for(var r=0;r<e;++r)t[r]=0;return t}function f(t,e){var r=e.length<0?0:0|d(e.length);t=s(t,r);for(var n=0;n<r;n+=1)t[n]=255&e[n];return t}function d(t){if(t>=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function p(t,e){if(u.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return M(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return j(t).length;default:if(n)return M(t).length;e=(""+e).toLowerCase(),n=!0}}function m(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return N(this,e,r);case"utf8":case"utf-8":return A(this,e,r);case"ascii":return T(this,e,r);case"latin1":case"binary":return C(this,e,r);case"base64":return S(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function g(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function y(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=u.from(e,n)),u.isBuffer(e))return 0===e.length?-1:_(t,e,r,n,i);if("number"==typeof e)return e&=255,u.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):_(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function _(t,e,r,n,i){var o,a=1,s=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"uc
|
|||
|
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|||
|
e.read=function(t,e,r,n,i){var o,a,s=8*i-n-1,u=(1<<s)-1,l=u>>1,c=-7,h=r?i-1:0,f=r?-1:1,d=t[e+h];for(h+=f,o=d&(1<<-c)-1,d>>=-c,c+=s;c>0;o=256*o+t[e+h],h+=f,c-=8);for(a=o&(1<<-c)-1,o>>=-c,c+=n;c>0;a=256*a+t[e+h],h+=f,c-=8);if(0===o)o=1-l;else{if(o===u)return a?NaN:1/0*(d?-1:1);a+=Math.pow(2,n),o-=l}return(d?-1:1)*a*Math.pow(2,o-n)},e.write=function(t,e,r,n,i,o){var a,s,u,l=8*o-i-1,c=(1<<l)-1,h=c>>1,f=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:o-1,p=n?1:-1,m=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(s=isNaN(e)?1:0,a=c):(a=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-a))<1&&(a--,u*=2),(e+=a+h>=1?f/u:f*Math.pow(2,1-h))*u>=2&&(a++,u/=2),a+h>=c?(s=0,a=c):a+h>=1?(s=(e*u-1)*Math.pow(2,i),a+=h):(s=e*Math.pow(2,h-1)*Math.pow(2,i),a=0));i>=8;t[r+d]=255&s,d+=p,s/=256,i-=8);for(a=a<<i|s,l+=i;l>0;t[r+d]=255&a,d+=p,a/=256,l-=8);t[r+d-p]|=128*m}},function(t,e){var r={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==r.call(t)}},function(t,e,r){(function(t){var n=void 0!==t&&t||"undefined"!=typeof self&&self||window,i=Function.prototype.apply;function o(t,e){this._id=t,this._clearFn=e}e.setTimeout=function(){return new o(i.call(setTimeout,n,arguments),clearTimeout)},e.setInterval=function(){return new o(i.call(setInterval,n,arguments),clearInterval)},e.clearTimeout=e.clearInterval=function(t){t&&t.close()},o.prototype.unref=o.prototype.ref=function(){},o.prototype.close=function(){this._clearFn.call(n,this._id)},e.enroll=function(t,e){clearTimeout(t._idleTimeoutId),t._idleTimeout=e},e.unenroll=function(t){clearTimeout(t._idleTimeoutId),t._idleTimeout=-1},e._unrefActive=e.active=function(t){clearTimeout(t._idleTimeoutId);var e=t._idleTimeout;e>=0&&(t._idleTimeoutId=setTimeout((function(){t._onTimeout&&t._onTimeout()}),e))},r(11),e.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==t&&t.setImmediate||this&&this.setImmediate,e.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==t&&t.clearImmediate||this&&this.clearImmediate}).call(this,r(1))},function(t,e,r){(function(t,e){!function(t,r){"use strict";if(!t.setImmediate){var n,i,o,a,s,u=1,l={},c=!1,h=t.document,f=Object.getPrototypeOf&&Object.getPrototypeOf(t);f=f&&f.setTimeout?f:t,"[object process]"==={}.toString.call(t.process)?n=function(t){e.nextTick((function(){p(t)}))}:!function(){if(t.postMessage&&!t.importScripts){var e=!0,r=t.onmessage;return t.onmessage=function(){e=!1},t.postMessage("","*"),t.onmessage=r,e}}()?t.MessageChannel?((o=new MessageChannel).port1.onmessage=function(t){p(t.data)},n=function(t){o.port2.postMessage(t)}):h&&"onreadystatechange"in h.createElement("script")?(i=h.documentElement,n=function(t){var e=h.createElement("script");e.onreadystatechange=function(){p(t),e.onreadystatechange=null,i.removeChild(e),e=null},i.appendChild(e)}):n=function(t){setTimeout(p,0,t)}:(a="setImmediate$"+Math.random()+"$",s=function(e){e.source===t&&"string"==typeof e.data&&0===e.data.indexOf(a)&&p(+e.data.slice(a.length))},t.addEventListener?t.addEventListener("message",s,!1):t.attachEvent("onmessage",s),n=function(e){t.postMessage(a+e,"*")}),f.setImmediate=function(t){"function"!=typeof t&&(t=new Function(""+t));for(var e=new Array(arguments.length-1),r=0;r<e.length;r++)e[r]=arguments[r+1];var i={callback:t,args:e};return l[u]=i,n(u),u++},f.clearImmediate=d}function d(t){delete l[t]}function p(t){if(c)setTimeout(p,0,t);else{var e=l[t];if(e){c=!0;try{!function(t){var e=t.callback,r=t.args;switch(r.length){case 0:e();break;case 1:e(r[0]);break;case 2:e(r[0],r[1]);break;case 3:e(r[0],r[1],r[2]);break;default:e.apply(void 0,r)}}(e)}finally{d(t),c=!1}}}}}("undefined"==typeof self?void 0===t?this:t:self)}).call(this,r(1),r(3))},function(t,e){function r(t){var e=new Error("Cannot find module '"+t+"'");throw e.code="MODULE_NOT_FOUND",e}r.keys=function(){return[]},r.resolve=r,t.exports=r,r.id=12},function(t,e,r){function n(t){this.options=t||{locator:{}}}function i(){this.cdata=!1}function o(t,e){e.lineNumber=t.lineNumber,e.columnNumber=t.columnNumber}function a(t){if(t)return"\n@"+(t.systemId||"")+"#[line:
|