@maptalks/3dtiles 0.95.4 → 0.95.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/maptalks.3dtiles.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @maptalks/3dtiles v0.95.
|
|
2
|
+
* @maptalks/3dtiles v0.95.6
|
|
3
3
|
* LICENSE : UNLICENSED
|
|
4
|
-
* (c) 2016-
|
|
4
|
+
* (c) 2016-2024 maptalks.org
|
|
5
5
|
*/
|
|
6
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("maptalks"),require("@maptalks/gl")):"function"==typeof define&&define.amd?define(["exports","maptalks","@maptalks/gl"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).maptalks=t.maptalks||{},t.maptalks,t.maptalksgl)}(this,(function(t,e,n){"use strict";function r(t){if(t&&t.t)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var s=r(e),i=r(n);const o='function(t){var e="undefined"!=typeof Float32Array?Float32Array:Array;function n(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t}function r(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function s(t,e,n){var r=e[0],s=e[1],i=e[2],o=e[3],a=e[4],c=e[5],u=e[6],f=e[7],h=e[8],l=e[9],d=e[10],y=e[11],m=e[12],b=e[13],p=e[14],w=e[15],g=n[0],v=n[1],M=n[2],T=n[3];return t[0]=g*r+v*a+M*h+T*m,t[1]=g*s+v*c+M*l+T*b,t[2]=g*i+v*u+M*d+T*p,t[3]=g*o+v*f+M*y+T*w,g=n[4],v=n[5],M=n[6],T=n[7],t[4]=g*r+v*a+M*h+T*m,t[5]=g*s+v*c+M*l+T*b,t[6]=g*i+v*u+M*d+T*p,t[7]=g*o+v*f+M*y+T*w,g=n[8],v=n[9],M=n[10],T=n[11],t[8]=g*r+v*a+M*h+T*m,t[9]=g*s+v*c+M*l+T*b,t[10]=g*i+v*u+M*d+T*p,t[11]=g*o+v*f+M*y+T*w,g=n[12],v=n[13],M=n[14],T=n[15],t[12]=g*r+v*a+M*h+T*m,t[13]=g*s+v*c+M*l+T*b,t[14]=g*i+v*u+M*d+T*p,t[15]=g*o+v*f+M*y+T*w,t}function i(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=e[0],t[13]=e[1],t[14]=e[2],t[15]=1,t}function o(t,e){return t[0]=e[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=e[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=e[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function a(t,e){var n=e[0],r=e[1],s=e[2],i=e[3],o=n+n,a=r+r,c=s+s,u=n*o,f=r*o,h=r*a,l=s*o,d=s*a,y=s*c,m=i*o,b=i*a,p=i*c;return t[0]=1-h-y,t[1]=f+p,t[2]=l-b,t[3]=0,t[4]=f-p,t[5]=1-u-y,t[6]=d+m,t[7]=0,t[8]=l+b,t[9]=d-m,t[10]=1-u-h,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function c(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]&&t[4]===e[4]&&t[5]===e[5]&&t[6]===e[6]&&t[7]===e[7]&&t[8]===e[8]&&t[9]===e[9]&&t[10]===e[10]&&t[11]===e[11]&&t[12]===e[12]&&t[13]===e[13]&&t[14]===e[14]&&t[15]===e[15]}function u(){var t=new e(3);return e!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function f(t){var e=t[0],n=t[1],r=t[2];return Math.sqrt(e*e+n*n+r*r)}function h(t,n,r){var s=new e(3);return s[0]=t,s[1]=n,s[2]=r,s}function l(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function d(t,e,n,r){return t[0]=e,t[1]=n,t[2]=r,t}function y(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t}function m(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t[2]=e[2]*n[2],t}function b(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t}function p(t,e){var n=e[0],r=e[1],s=e[2],i=n*n+r*r+s*s;return i>0&&(i=1/Math.sqrt(i),t[0]=e[0]*i,t[1]=e[1]*i,t[2]=e[2]*i),t}function w(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function g(t,e,n){var r=e[0],s=e[1],i=e[2],o=n[0],a=n[1],c=n[2];return t[0]=s*c-i*a,t[1]=i*o-r*c,t[2]=r*a-s*o,t}function v(t,e,n){var r=e[0],s=e[1],i=e[2],o=n[3]*r+n[7]*s+n[11]*i+n[15];return o=o||1,t[0]=(n[0]*r+n[4]*s+n[8]*i+n[12])/o,t[1]=(n[1]*r+n[5]*s+n[9]*i+n[13])/o,t[2]=(n[2]*r+n[6]*s+n[10]*i+n[14])/o,t}var M=function(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t},T=m,A=f;function _(t,e,n,r,s){return t[0]=e,t[1]=n,t[2]=r,t[3]=s,t}function O(t,e,n){var r=e[0],s=e[1],i=e[2],o=e[3];return t[0]=n[0]*r+n[4]*s+n[8]*i+n[12]*o,t[1]=n[1]*r+n[5]*s+n[9]*i+n[13]*o,t[2]=n[2]*r+n[6]*s+n[10]*i+n[14]*o,t[3]=n[3]*r+n[7]*s+n[11]*i+n[15]*o,t}function x(){var t=new e(4);return e!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function S(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}function I(t,e,n,r){var s=e[0],i=e[1],o=e[2],a=e[3],c=n[0],u=n[1],f=n[2],h=n[3],l=void 0,d=void 0,y=void 0,m=void 0,b=void 0;return(d=s*c+i*u+o*f+a*h)<0&&(d=-d,c=-c,u=-u,f=-f,h=-h),1-d>1e-6?(l=Math.acos(d),y=Math.sin(l),m=Math.sin((1-r)*l)/y,b=Math.sin(r*l)/y):(m=1-r,b=r),t[0]=m*s+b*c,t[1]=m*i+b*u,t[2]=m*o+b*f,t[3]=m*a+b*h,t}u(),function(){var t,n=(t=new e(4),e!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t)}();var k,E=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t};u(),h(1,0,0),h(0,1,0),x(),x(),k=new e(9),e!=Float32Array&&(k[1]=0,k[2]=0,k[3]=0,k[5]=0,k[6]=0,k[7]=0),k[0]=1,k[4]=1,k[8]=1;\n/*!\n * @maptalks/gltf-loader v0.95.2\n * LICENSE : UNLICENSED\n * (c) 2016-2023 maptalks.org\n */\nlet C=0;function U(t){return null==t}function F(t){return!U(t)}function N(t){return!U(t)&&("string"==typeof t||null!==t.constructor&&t.constructor===String)}function P(t){for(let e=1;e<arguments.length;e++){const n=arguments[e];for(const e in n)t[e]=n[e]}return t}function B(t){switch(t){case 5120:return Int8Array;case 5121:return Uint8Array;case 5122:return Int16Array;case 5123:return Uint16Array;case 5124:return Int32Array;case 5125:return Uint32Array;case 5126:return Float32Array}throw new Error("unsupported bufferView\'s component type: "+t)}function D(t){return 0===t.indexOf("data:")&&t.indexOf("base64,")>0}function R(t){const e=function(t){return"undefined"!=typeof self?self.atob(t):window.atob(t)}(t.substring(t.indexOf(",")+1)),n=e.length,r=new Uint8Array(n);for(let t=0;t<n;t++)r[t]=e.charCodeAt(t);return r.buffer}const L=[],z=[],j=[],V=[0,0,0],q=S([]),G=[1,1,1];function $(t,e,n,r,s,i,o){const a=B(o);if((0===s||s===r*a.BYTES_PER_ELEMENT)&&i%a.BYTES_PER_ELEMENT==0){const s=new a(e,i,n*r);return t.set(s),t}0===s&&(s=r*a.BYTES_PER_ELEMENT);const c=new Uint8Array(r*a.BYTES_PER_ELEMENT);for(let o=0;o<n;o++){let n=null;const u=new Uint8Array(e,s*o+i,r*a.BYTES_PER_ELEMENT);c.set(u),n=new a(c.buffer,0,r);for(let e=0;e<r;e++)t[o*r+e]=n[e]}return t}const X="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function H(t,e,n){const r=new Uint8Array(t,e,n);return X.decode(r)}const J={get:function(t,e={}){e||(e={});const n=new AbortController,r=n.signal,s=P({},e);s.signal=r,s.method||(s.method="GET");const i=fetch(t,s).then(t=>{const n=this.t(t,e.responseType);return n.message?n:n.then(n=>"arraybuffer"===e.responseType?{data:n,cacheControl:t.headers.get("Cache-Control"),expires:t.headers.get("Expires"),contentType:t.headers.get("Content-Type")}:n).catch(t=>{if(!t.code||t.code!==DOMException.ABORT_ERR)throw t})}).catch(t=>{if(!t.code||t.code!==DOMException.ABORT_ERR)throw t});return i.xhr=n,i},t:(t,e)=>200!==t.status?{status:t.status,statusText:t.statusText,message:`incorrect http request with status code(${t.status}): ${t.statusText}`}:"arraybuffer"===e?t.arrayBuffer():"json"===e?t.json():t.text(),getArrayBuffer:(t,e={})=>(e||(e={}),e.responseType="arraybuffer",J.get(t,e)),getJSON:function(t,e={}){return e&&e.jsonp?J.jsonp(t):((e=e||{}).responseType="json",J.get(t,e))},jsonp:function(t){const e="_maptalks_jsonp_"+C++;t.match(/\\?/)?t+="&callback="+e:t+="?callback="+e;let n=document.createElement("script");return n.type="text/javascript",n.src=t,new Promise(t=>{window[e]=function(r){document.getElementsByTagName("head")[0].removeChild(n),n=null,delete window[e],t(r)},document.getElementsByTagName("head")[0].appendChild(n)})}};class K{constructor(t,e,n,r){this.s=t,this.decoders=e,this.i=n,this.images={},this.o={},this.u=r||{}}requestImageFromBufferURI(t,e,n){if(this.buffers[t.id]){const r=this.buffers[t.id],s=this.h(e,r);return this.getImageByBuffer(s,n)}if(this.o[t.id])return this.o[t.id].then(()=>{const r=this.buffers[t.id],s=this.h(e,r);return this.getImageByBuffer(s,n)});if(D(t.uri)){const r=this.buffers[t.id]=R(t.uri),s=this.h(e,r);return this.getImageByBuffer(s,n)}let r;const s=t.uri.indexOf("blob:")>=0;return r=t.uri.indexOf("://")>0||s?t.uri:this.rootPath+"/"+t.uri,this.o[t.id]=J.getArrayBuffer(r,this.u).then(r=>{const s=this.buffers[t.id]=r.data,i=this.h(e,s);return this.getImageByBuffer(i,n)})}getImageByBuffer(t,e){if(this.images[e.id])return Promise.resolve(this.images[e.id]);const n=this.decoders;return n[e.mimeType]?n[e.mimeType](t,{supportedFormats:this.i}):"image/crn"===e.mimeType||"image/ktx2"===e.mimeType||"image/cttf"===e.mimeType?(console.warn("missing transcoder for "+e.mimeType,", visit https://maptalks.com/docs/transcoders for details"),Promise.resolve(null)):this.m(e.id,t)}requestExternalImage(t){if(this.images[t.id])return Promise.resolve(this.images[t.id]);const e=0===t.uri.indexOf("data:image/")?t.uri:this.rootPath+"/"+t.uri;return this.o[t.id]?this.o[t.id].then(()=>this.images[t.id]):this.o[t.id]=this.m(t.id,e)}m(t,e){return new Promise((n,r)=>{this.s(e,this.u,(s,i)=>{s?r(s):(URL.revokeObjectURL(e),this.images[t]=i,n(this.images[t]))})})}}const Y=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],Q=[];class W{constructor(t,e,n,r){this.rootPath=t,this.gltf=e,this.p=!1,this.glbBuffer=n,this.buffers={},this.requests={},this.accessors={},this.v(),this.u=r}M(t,e){const n=this.gltf,r=n.accessors[e];if(void 0===r.bufferView)return this.accessors[r.id]=this.T(t,e,null,0),Promise.resolve(this.accessors[r.id]);if(r&&this.accessors[r.id])return Promise.resolve(this.accessors[r.id]);const s=n.bufferViews[r.bufferView];return this.A(s).then(n=>{const{buffer:s,byteOffset:i}=n;return this.accessors[r.id]=this.T(t,e,s,i)})}A(t){const e=this.gltf.buffers[t.buffer];if(this.buffers[e.id]){const t=this.buffers[e.id];return Promise.resolve({buffer:t,byteOffset:0})}if(this.requests[e.id])return this.requests[e.id].then(()=>{const t=this.buffers[e.id];return Promise.resolve({buffer:t,byteOffset:0})});if("binary_glTF"!==t.buffer&&"KHR_binary_glTF"!==t.buffer&&e.uri){if(D(e.uri)){const t=this.buffers[e.id]=R(e.uri);return Promise.resolve({buffer:t,byteOffset:0})}let t;const n=e.uri.indexOf("blob:")>=0;return t=e.uri.indexOf("://")>0||n?e.uri:this.rootPath+"/"+e.uri,this.requests[e.id]=J.getArrayBuffer(t,this.u).then(r=>(n&&URL.revokeObjectURL(t),{buffer:this.buffers[e.id]=r.data,byteOffset:0}))}return Promise.resolve({buffer:this.glbBuffer.buffer,byteOffset:this.glbBuffer.byteOffset})}T(t,e,n,r=0){const s=this.gltf,i=s.accessors[e],o=void 0!==i.bufferView?s.bufferViews[i.bufferView]:{},a=(o.byteOffset||0)+r,c=this._(i.type),u=B(i.componentType),f=o.byteStride||0,h={array:void 0,name:t,accessorName:e,byteLength:i.count*c*u.BYTES_PER_ELEMENT,componentType:i.componentType,count:i.count,type:i.type,itemSize:c,max:i.max,min:i.min,extensions:i.extensions};if(i.min&&(h.min=i.min),i.max&&(h.max=i.max),n)if(this.p)h.byteStride=f,h.byteOffset=a+(i.byteOffset||0),!f||f===c*u.BYTES_PER_ELEMENT||"indices"===t||"input"===t||"output"===t||t.indexOf("morph")>=0?(h.array=this.O(n,i.count,c,a+(i.byteOffset||0),u),h.array.buffer.byteLength===h.byteLength&&(h.byteOffset=0)):h.array=new Uint8Array(n,a,o.byteLength);else if(i.interleaved){h.byteStride=0,h.byteOffset=0;const t=new u(i.count*c);if(h.array=$(t,n,i.count,c,f,a+(i.byteOffset||0),i.componentType),h.extensions&&h.extensions.WEB3D_quantized_attributes&&c>2){const t=new Float32Array(h.array.length),{decodeMatrix:e}=h.extensions.WEB3D_quantized_attributes;for(let n=0;n<h.array.length;n+=c){Q[0]=h.array[n],Q[1]=h.array[n+1],Q[2]=h.array[n+2],Q[3]=1;const r=O(Q,Q,e);t[n]=r[0],t[n+1]=r[1],t[n+2]=r[2]}h.componentType=5126,h.array=t}}else h.byteStride=0,h.array=this.O(n,i.count,c,a+(i.byteOffset||0),u),h.byteOffset=h.array.byteOffset;else{h.array=new u(i.count);const t=h.min||h.max;t&&(h.array[0]=t[0],h.array[1]=t[1],h.array[2]=t[2])}return h}v(){const t=this.gltf.accessors;if(Array.isArray(t))for(let e=0;e<t.length;e++)for(let n=0;n<t.length;n++)e!==n&&t[e].bufferView===t[n].bufferView&&(t[e].interleaved=t[n].interleaved=!0);else for(const e in t)for(const n in t)e!==n&&t[e].bufferView===t[n].bufferView&&(t[e].interleaved=t[n].interleaved=!0)}O(t,e,n,r,s){return r%s.BYTES_PER_ELEMENT!=0&&(t=t.slice(r,r+e*n*s.BYTES_PER_ELEMENT),r=0),new s(t,r,n*e)}_(t){const e=Y.indexOf(t);return Y[e+1]}requestKHRTechniquesWebgl(t){const{shaders:e}=t,n=e.map(t=>{if(void 0!==t.bufferView){const e=this.gltf.bufferViews[t.bufferView],{byteLength:n}=e;return this.A(e).then(r=>{const{buffer:s,byteOffset:i}=r,o=H(s,i+(e.byteOffset||0),n);return t.content=o,t})}if(t.uri){if(D(t.uri)){const e=R(t.uri),n=H(e,0,e.byteLength);return t.content=n,Promise.resolve(t)}{const e=this.rootPath+"/"+t.uri;return J.get(e,this.u).then(e=>(t.content=e,t))}}return Promise.resolve(t)});return Promise.all(n).then(()=>t)}}class Z extends K{constructor(t,e,n,r,s,i,o){super(r,s,i,o),this.rootPath=t,this.gltf=e,this.requests={},this.buffers={},this.glbBuffer=n,this.accessor=new W(t,e,n,o)}iterate(t,e){const n=this.gltf[e];if(!n)return;let r=0;for(const e in n)t(e,n[e],r++)}createNode(t){const e={};if(F(t.name)&&(e.name=t.name),F(t.children)&&(e.children=t.children),F(t.jointName)&&(e.jointName=t.jointName),F(t.matrix)&&(e.matrix=t.matrix),F(t.rotation)&&(e.rotation=t.rotation),F(t.scale)&&(e.scale=t.scale),F(t.translation)&&(e.translation=t.translation),F(t.extras)&&(e.extras=t.extras),F(t.meshes)&&(e.mesh=t.meshes[0]),e.translation||e.rotation||e.scale){const t=function(t,e){if(e.matrix)return e.matrix;if(e.translation||e.scale||e.rotation){const n=i(L,e.translation||V),r=a(z,e.rotation||q),c=o(j,e.scale||G);return s(c,r,c),s(t,n,c)}return r(t)}([],e);delete e.translation,delete e.rotation,delete e.scale,e.matrix=t}return e}S(t){const e={};for(const n in t){const r=t[n];let s,i;r.instanceTechnique&&r.instanceTechnique.values?(s=r.instanceTechnique,i=s.values.diffuse):(s=r,i=s.values.tex||s.values.diffuseTex||s.values.diffuse);const o={baseColorTexture:{index:i}};r.name&&(o.name=r.name),r.extensions&&(o.extensions=r.extensions),r.extras&&(o.extras=r.extras),e[n]=o}return e}I(t){if(t.bufferView||t.extensions&&(t.extensions.KHR_binary_glTF||t.extensions.binary_glTF)){const e=t.bufferView?t:t.extensions.KHR_binary_glTF||t.extensions.binary_glTF;t.extensions&&(t.mimeType=e.mimeType,t.width=e.width,t.height=e.height);const n=this.gltf.bufferViews[e.bufferView],r=(n.byteOffset||0)+this.glbBuffer.byteOffset,s=n.byteLength,i=this.buffers[e.bufferView]=new Uint8Array(this.glbBuffer.buffer,r,s);return this.getImageByBuffer(i,t)}return this.requestExternalImage(t)}k(t){const e=this.gltf.textures[t];if(!e)return null;const n=this.gltf.images[e.source];return this.I(n).then(t=>{const r=this.gltf.samplers[e.sampler];return{image:{array:t.data,width:t.width,height:t.height,index:e.source,mimeType:n.mimeType,name:n.name,extras:n.extras},sampler:r}})}getBaseColorTexture(t){const e=this.gltf.materials[t];let n,r;if(e.instanceTechnique&&e.instanceTechnique.values?(n=e.instanceTechnique,r=n.values.diffuse):(n=e,r=n.values.tex||n.values.diffuseTex||n.values.diffuse),void 0===r||void 0===this.gltf.textures)return null;const s=this.gltf.textures[r];if(!s)return null;const i=this.gltf.samplers[s.sampler];return{format:s.format||6408,internalFormat:s.internalFormat||6408,type:s.type||5121,sampler:i,source:this.gltf.images[s.source]}}getMaterial(){return null}getAnimations(){return null}}class tt extends K{constructor(t,e,n,r,s,i,o){super(r,s,i,o),this.rootPath=t,this.gltf=e,this.glbBuffer=n,this.buffers={},this.requests={},this.accessor=new W(t,e,n,o)}iterate(t,e){const n=this.gltf[e];if(n)for(let e=0;e<n.length;e++)t(e,n[e],e)}createNode(t){const e={};return P(e,t),!F(t.weights)&&this.gltf.meshes&&F(e.mesh)?e.weights=this.gltf.meshes[e.mesh].weights:t.weights&&(e.weights=t.weights),e}k(t){const e=this.gltf.textures[t];if(!e)return null;let n=e.source;if(e.extensions&&e.extensions.EXT_texture_webp&&(n=e.extensions.EXT_texture_webp.source),!F(n))return null;const r=this.gltf.images[n];return this.I(r).then(t=>{if(!t)return null;const n={image:{array:t.data,mipmap:t.mipmap,width:t.width,height:t.height,index:e.source,mimeType:r.mimeType,name:r.name,extensions:r.extensions,extras:r.extras}};P(n,e);const s=F(e.sampler)?this.gltf.samplers[e.sampler]:void 0;return s&&(n.sampler=s,n.sampler.magFilter=s.magFilter||9729,n.sampler.minFilter=s.minFilter||9729,n.sampler.wrapS=s.wrapS||10497,n.sampler.wrapT=s.wrapT||10497),t.format&&(n.format=t.format),n})}I(t){if(!F(t.bufferView))return this.requestExternalImage(t);{const e=this.gltf.bufferViews[t.bufferView],n=this.gltf.buffers[e.buffer];if(n.uri)return this.requestImageFromBufferURI(n,e,t);if(this.glbBuffer)return this.C(e,t)}return null}C(t,e){const n=this.h(t,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(n,e)}h(t,e,n){n=n||0;const r=t.byteOffset+n,s=t.byteLength;return new Uint8Array(e,r,s)}U(t,e){const n=new Array(t.byteLength);for(let e=0;e<t.byteLength;e++)n[e]=String.fromCharCode(t[e]);return n.join(""),"data:"+(e=e||"image/png")+";base64,"+function(t){return"undefined"!=typeof self?self.btoa(t):window.btoa(t)}(unescape(encodeURIComponent(n)))}getAnimations(t){const e=[];return t.forEach(t=>{e.push(this.getSamplers(t.samplers))}),Promise.all(e).then(e=>{for(let n=0;n<e.length;n++)t[n].samplers=e[n];return t})}getSamplers(t){const e=[];for(let n=0;n<t.length;n++)(F(t[n].input)||F(t[n].output))&&(e.push(this.accessor.M("input",t[n].input)),e.push(this.accessor.M("output",t[n].output)));return Promise.all(e).then(e=>{for(let n=0;n<e.length/2;n++)t[n].input=e[2*n],t[n].output=e[2*n+1],t[n].interpolation||(t[n].interpolation="LINEAR");return t})}}const et="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class nt{static read(t,e=0,n=0){n||(n=t.byteLength);const r=new DataView(t,e,n),s=r.getUint32(4,!0);if(1===s)return nt.readV1(r,e);if(2===s)return nt.readV2(t,e);throw new Error("Unsupported glb version : "+s)}static readV1(t,e){const n=t.getUint32(8,!0),r=t.getUint32(12,!0);if(n!==t.byteLength)throw new Error("Length in GLB header is inconsistent with glb\'s byte length.");const s=rt(t.buffer,20+e,r);return{json:JSON.parse(s),glbBuffer:{byteOffset:20+e+r,buffer:t.buffer,byteLength:n}}}static readV2(t,e){let n,r,s;const i=new DataView(t,e+12);let o=0;for(;o<i.byteLength;){const a=i.getUint32(o,!0);o+=4;const c=i.getUint32(o,!0);if(o+=4,1313821514===c)n=rt(t,e+12+o,a);else if(5130562===c){s=e+12+o,r=a;break}o+=a}return{json:JSON.parse(n),glbBuffer:{byteOffset:s,buffer:t,byteLength:r}}}}function rt(t,e,n){if(et){const r=new Uint8Array(t,e,n);return et.decode(r)}return function(t){const e=t.length;let n="";for(let r=0;r<e;){let s=t[r++];if(128&s){let n=st[s>>3&7];if(!(64&s)||!n||r+n>e)return null;for(s&=63>>n;n>0;n-=1){const e=t[r++];if(128!=(192&e))return null;s=s<<6|63&e}}n+=String.fromCharCode(s)}return n}(new Uint8Array(t,e,n))}const st=[1,1,1,1,2,2,3,0],it=[0,0,0],ot=[0,0,0,1],at=[1,1,1],ct={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},ut={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},ft={F(t,e,n,r,s,i,o,a){const c=F(t)?e.animations:[e.animations[0]],u={};for(let e=0;e<c.length;e++){const f=c[e],h=f.name||e;if(F(t)&&h!==t)continue;const d=f.channelsMap[n];if(d)for(let t=0;t<d.length;t++){const e=d[t];"translation"===e.target.path?(this.N(s,f.samplers[e.sampler],r,1),u.translation=l(it,s)):"rotation"===e.target.path?(this.P(i,f.samplers[e.sampler],r,1),u.rotation=E(ot,i)):"scale"===e.target.path?(this.N(o,f.samplers[e.sampler],r,1),u.scale=l(at,o)):"weights"===e.target.path&&a&&(this.N(a,f.samplers[e.sampler],r,a.length),u.weights=a)}}return u},N(t,e,n,r){switch(e.interpolation){case"LINEAR":{const s=this.B(ut,e,n,1*r);s&&(t=function(t,e,n,r){for(let s=0;s<t.length;s++)t[s]=e[s]+r*(n[s]-e[s]);return t}(t,s.PREVIOUS,s.NEXT,s.INTERPOLATION));break}case"STEP":{const s=this.B(ut,e,n,1*r);s&&(t=function(t,e){for(let n=0;n<t.length;n++)t[n]=e[n];return t}(t,...s.PREVIOUS));break}case"CUBICSPLINE":{const s=this.B(ut,e,n,3*r);s&&(t=this.D(t,s,e.input.array,3*r));break}}return t},P(t,e,n){switch(e.interpolation){case"LINEAR":{const r=this.B(ut,e,n,1);r&&I(t,r.PREVIOUS,r.NEXT,r.INTERPOLATION);break}case"STEP":{const r=this.B(ut,e,n,1);r&&(t=_(t,...r.PREVIOUS));break}case"CUBICSPLINE":{const r=this.B(ut,e,n,3);if(r){for(let t=0;t<r.PREVIOUS.length;t++)r.PREVIOUS[t]=Math.acos(r.PREVIOUS[t]),r.NEXT[t]=Math.acos(r.NEXT[t]);t=this.D(t,r,e.input.array,3);for(let e=0;e<t.length;e++)t[e]=Math.cos(t[e])}break}}return t},R(t,e){const n=t.length;let r,s,i,o=0,a=n-1,c=Math.floor((o+a)/2);for(;o<=n-1&&a>=0;){if(o===a)return null;if(t[c]<=e&&e<=t[c+1]){const n=t[c];return r=c,s=c+1,i=(e-n)/(t[c+1]-n),{preIndx:r,nextIndex:s,interpolation:i}}e<t[c]?(a=c,c=Math.floor((o+a)/2)):t[c+1]<e&&(o=c,c=Math.floor((o+a)/2))}return null},B(t,e,n,r){const s=e.input.array,i=e.output.array,o=e.output.itemSize;(n<s[0]||n>s[s.length-1])&&(n=Math.max(s[0],Math.min(s[s.length-1],n))),n===s[s.length-1]&&(n=s[0]);const a=this.R(s,n);if(!a||!a.nextIndex)return null;const{preIndx:c,nextIndex:u,interpolation:f}=a;t.PREINDEX=c,t.NEXTINDEX=u,t.INTERPOLATION=f;const h=o*r;return t.PREVIOUS=i.subarray(t.PREINDEX*h,(t.PREINDEX+1)*h),t.NEXT=i.subarray(t.NEXTINDEX*h,(t.NEXTINDEX+1)*h),t},D(t,e,n,r){const s=e.INTERPOLATION,i=n[e.PREINDEX],o=n[e.NEXTINDEX];for(let n=0;n<3;n++){const a=e.PREVIOUS[r+n],c=(o-i)*e.PREVIOUS[2*r+n],u=e.NEXT[3+n],f=(o-i)*e.NEXT[n],h=(2*Math.pow(s,3)-3*Math.pow(s,2)+1)*a+(Math.pow(s,3)-2*Math.pow(s,2)+s)*c+(2*-Math.pow(s,3)+3*Math.pow(s,2))*u+(Math.pow(s,3)-Math.pow(s,2))*f;t[n]=h}return t},getAnimationClip(t,e,n,r){const s=t.nodes[e]&&t.nodes[e].weights;return d(it,...ct.TRANSLATION),_(ot,...ct.ROTATION),d(at,...ct.SCALE),this.F(r,t,e,n,it,ot,at,s)},getTimeSpan(t){if(!t.animations)return null;if(t.timeSpan)return t.timeSpan;const e=t.animations;return t.timeSpan={},e.forEach((e,n)=>{let r=-1/0,s=1/0;const i=e.channels;for(let t=0;t<i.length;t++){const n=i[t],o=e.samplers[n.sampler].input.array;o[o.length-1]>r&&(r=o[o.length-1]),o[0]<s&&(s=o[0])}const o=e.name||n;t.timeSpan[o]={max:r,min:s}}),t.timeSpan},getTimeSpanByName(t,e){const n=this.getTimeSpan(t);return n?F(e)?n[e]:n[Object.keys(n)[0]]:null}};let ht=!1;if("undefined"!=typeof OffscreenCanvas){let t;try{t=new OffscreenCanvas(2,2).getContext("2d")}catch(Qe){}t&&"undefined"!=typeof createImageBitmap&&(ht=!0)}const lt="undefined"==typeof document?null:document.createElement("canvas");class dt{constructor(t,e,n){if(this.options=n||{},this.options.decoders||(this.options.decoders={}),this.u=this.options.fetchOptions||{},e.buffer instanceof ArrayBuffer){const{json:n,glbBuffer:r}=nt.read(e.buffer,e.byteOffset,e.byteLength);this.L(t,n,r)}else this.L(t,e);this.j=new W(this.rootPath,this.gltf,this.glbBuffer,this.u),this.V()}V(){const t=this.gltf.extensionsRequired;if(t){if(t.indexOf("KHR_draco_mesh_compression")>=0&&!this.options.decoders.draco)throw new Error("KHR_draco_mesh_compression is required but @maptalks/transcoders.draco is not loaded");if(t.indexOf("KHR_texture_basisu")>=0&&!this.options.decoders.ktx2)throw new Error("KHR_texture_basisu is required but @maptalks/transcoders.ktx2 is not loaded")}}q(){const t=this.gltf.extensions;return t&&t.KHR_techniques_webgl?this.j.requestKHRTechniquesWebgl(t.KHR_techniques_webgl).then(e=>(t.KHR_techniques_webgl=e,t)):Promise.resolve(t)}load(t){t=t||{};const e=this.G(t),n=this.$(),r=this.X(),s=this.q();return Promise.all([e,n,r,s]).then(t=>(t[0].animations=t[1],t[0].textures=t[2],t[0].extensions=t[3],t[0].transferables=this.transferables||[],this.createChannelsMap(t[0]),t[0]))}createChannelsMap(t){const e=t.animations;if(e)for(let t=0;t<e.length;t++){const n=e[t];n.channelsMap={};for(let t=0;t<n.channels.length;t++){const e=n.channels[t];n.channelsMap[e.target.node]||(n.channelsMap[e.target.node]=[]),n.channelsMap[e.target.node].push(e)}}}getExternalResources(){const t=[];if(this.gltf){const{buffers:e,images:n}=this.gltf;for(let n=0;n<e.length;n++)e[n].uri&&e[n].uri.indexOf("data:application/octet-stream;base64")<0&&t.push({type:"buffer",uri:e[n].uri});for(let e=0;e<n.length;e++)n[e].uri&&n[e].uri.indexOf("data:image/")<0&&t.push({type:"image",uri:n[e].uri})}return t}static getAnimationClip(t,e,n,r){return ft.getAnimationClip(t,e,n,r)}static getAnimationTimeSpan(t,e){return ft.getTimeSpanByName(t,e)}static getTypedArrayCtor(t){return B(t)}static readInterleavedArray(t,e,n,r,s,i,o){return $(t,e,n,r,s,i,o)}L(t,e,n){this.gltf=e,this.glbBuffer=n,this.version=e.asset?+e.asset.version:1,this.rootPath=t,this.buffers={},this.requests={},this.options.requestImage=ht?pt.bind(this):this.options.requestImage||yt,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new tt(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this.u),this.adapter.iterate((t,e,n)=>{e.id="buffer_"+n},"buffers"),this.adapter.iterate((t,e,n)=>{e.id="image_"+n},"images"),this.adapter.iterate((t,e,n)=>{e.id="accessor_"+n},"accessors")):(this.adapter=new Z(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this.u),this.adapter.iterate((t,e,n)=>{e.id="accessor_"+n},"accessors"),this.adapter.iterate((t,e,n)=>{e.id="image_"+n},"images"))}H(t,e){if(t.children&&t.children.length>0){if(!("number"==typeof(n=t.children[0])&&isFinite(n)||N(t.children[0])))return t;const r=t.children.map(t=>{const n=e[t];return n.nodeIndex=t,this.H(n,e)});t.children=r}var n;return t}G(t){return this.J(t).then(t=>{const e=this.scenes=[];let n;for(const e in t)t[e]=this.H(t[e],t),t[e].nodeIndex=Number(e)?Number(e):e;this.adapter.iterate((r,s,i)=>{const o={};s.name&&(o.name=s.name),s.nodes&&(o.nodes=s.nodes.map(e=>t[e])),this.gltf.scene===r&&(n=i),e.push(o)},"scenes");const r={textures:this.gltf.textures,asset:this.gltf.asset,scene:n,scenes:e,nodes:t,meshes:this.meshes,materials:this.gltf.materials,skins:this.skins,extensionsRequired:this.gltf.extensionsRequired,extensionsUsed:this.gltf.extensionsUsed};if(this.gltf.extensions&&(r.extensions=this.gltf.extensions),1===this.version){const t=this.adapter.S(this.gltf.materials);r.materials=t}return delete this.gltf.buffers,r.json=this.gltf,r})}J(t){return this.K(t).then(()=>{const t=this.nodes={};return this.adapter.iterate((e,n)=>{const r=this.adapter.createNode(n,this.meshes,this.skins);t[e]=r},"nodes"),t})}Y(){this.skins=[];const t=[];return this.adapter.iterate((e,n,r)=>{t.push(this.W(n).then(t=>{t.index=r,this.skins.push(t)}))},"skins"),t}W(t){const e=t.inverseBindMatrices;return this.adapter.accessor.M("inverseBindMatrices",e).then(e=>(t.inverseBindMatrices=e,e&&e.buffer&&this.transferables&&this.transferables.indexOf(e.buffer)<0&&this.transferables.push(e.buffer),t))}$(){const t=this.gltf.animations;return F(t)?this.adapter.getAnimations(t):null}K(t){this.meshes={};let e=[];return this.adapter.iterate((n,r,s)=>{e.push(this.Z(r,t).then(t=>{t.index=s,this.meshes[n]=t}))},"meshes"),e=e.concat(this.Y()),Promise.all(e)}Z(t,e){const n=t.primitives.map(t=>this.tt(t,e)).filter(t=>!!t);return Promise.all(n).then(e=>{const n={};return P(n,t),n.primitives=e,n})}X(){const t=this.gltf.textures;if(!t)return null;const e=[];for(const n in t)e.push(this.adapter.k(n));return Promise.all(e).then(e=>{if(this.transferables)for(let t=0;t<e.length;t++){const n=e[t].image.array;if(e[t]&&n){let t;t=n instanceof ImageBitmap?n:n.buffer,t&&this.transferables.indexOf(t)<0&&this.transferables.push(t)}}if(!Array.isArray(t)){const n={},r=Object.keys(t);for(let t=0;t<e.length;t++)e[t]&&(n[r[t]]=e[t]);return n}return e})}tt(t,e){let n;const r=[],s=t.extensions;if(F(t.targets))for(let e=0;e<t.targets.length;e++){const n=t.targets[e];for(const t in n){const s=this.adapter.accessor.M(`morphTargets_${t}_${e}`,n[t]);s&&r.push(s)}}if(s&&s.KHR_draco_mesh_compression){if(!this.options.decoders.draco&&(!this.gltf.extensionsRequired||!this.gltf.extensionsRequired.indexOf("KHR_draco_mesh_compression")<0))return null;const t=this.options.decoders.draco,{bufferView:i,attributes:o}=s.KHR_draco_mesh_compression,a=this.gltf.bufferViews[i],c=this.j.A(a).then(n=>{const{buffer:r,byteOffset:s}=n;let{byteOffset:i}=a;const c=a.byteLength;i||(i=0);const u=new DataView(r,s+i,c),f={attributes:o,useUniqueIDs:!1,skipAttributeTransform:e.skipAttributeTransform};return t(u,f).then(t=>{const e=Object.values(t.attributes);return t.indices&&e.push(t.indices),e})});r.push(c),n=Promise.all(r)}else{const e=t.attributes;for(const t in e){const n=this.adapter.accessor.M(t,e[t]);n&&r.push(n)}if(F(t.indices)){const e=this.adapter.accessor.M("indices",t.indices);e&&r.push(e)}n=Promise.all(r)}return n.then(e=>{if(s&&s.KHR_draco_mesh_compression){const n=t.targets?t.targets.length:0;e[n]=e[n].concat(e.slice(0,n)),e=e[n]}let n,r;const i={attributes:e.reduce((t,e)=>{if("indices"===e.name)n=e;else if(e.name.indexOf("morphTargets_")>-1)r=r||{},r[e.name.slice(13)]=e;else{if(!("POSITION"!==e.name||e.min&&e.max)){const t=[1/0,1/0,1/0],n=[-1/0,-1/0,-1/0],{itemSize:r,array:s}=e,i=s.length/r;for(let e=0;e<i;e++)for(let i=0;i<r;i++){const o=e*r+i;s[o]<t[i]&&(t[i]=s[o]),s[o]>n[i]&&(n[i]=s[o])}if(e.quantization){const r=e.quantization,s=r.range/(1<<r.quantizationBits),i=r.minValues;b(t,t,s),y(t,t,i),b(n,n,s),y(n,n,i)}e.min=t,e.max=n}t[e.name]=e}return this.transferables&&e.array.buffer&&this.transferables.indexOf(e.array.buffer)<0&&this.transferables.push(e.array.buffer),t},{}),material:t.material};return n&&(i.indices=n),r&&(i.morphTargets=r),i.mode=F(t.mode)?t.mode:4,F(t.extras)&&(i.extras=t.extras),i})}}function yt(t,e,n){const r=new Image;r.crossOrigin="",r.onload=()=>{if(!lt)return void n(new Error("There is no canvas to draw image!"));lt.width=r.width,lt.height=r.height;const t=lt.getContext("2d",{willReadFrequently:!0});t.drawImage(r,0,0,r.width,r.height);const e=t.getImageData(0,0,r.width,r.height),s={width:r.width,height:r.height,data:new Uint8Array(e.data)};n(null,s)},r.onerror=function(t){n(t)},r.src=t}let mt,bt;function pt(t,e,n){mt||(mt=new OffscreenCanvas(2,2),bt=mt.getContext("2d",{willReadFrequently:!0}));let r=null;if(N(t))r=fetch(t,e).then(t=>t.arrayBuffer()).then(t=>{const e=new Blob([new Uint8Array(t)]);return createImageBitmap(e)});else{const e=new Blob([t]);r=createImageBitmap(e)}r.then(wt.bind(this)).then(t=>{n(null,t)}).catch(t=>{console.warn(t),n(t)})}function wt(t){let{width:e,height:n}=t;gt(e)||(e=vt(e)),gt(n)||(n=vt(n));const r=this.options.maxTextureSize;r&&(e=Math.min(r,e),n=Math.min(r,n)),mt.width=e,mt.height=n,bt.drawImage(t,0,0,e,n),t.close();const s=bt.getImageData(0,0,e,n);return{width:e,height:n,data:new Uint8Array(s.data)}}function gt(t){return 0==(t&t-1)&&0!==t}function vt(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}var Mt={exports:{}},Tt={"aliceblue":[240,248,255],"antiquewhite":[250,235,215],"aqua":[0,255,255],"aquamarine":[127,255,212],"azure":[240,255,255],"beige":[245,245,220],"bisque":[255,228,196],"black":[0,0,0],"blanchedalmond":[255,235,205],"blue":[0,0,255],"blueviolet":[138,43,226],"brown":[165,42,42],"burlywood":[222,184,135],"cadetblue":[95,158,160],"chartreuse":[127,255,0],"chocolate":[210,105,30],"coral":[255,127,80],"cornflowerblue":[100,149,237],"cornsilk":[255,248,220],"crimson":[220,20,60],"cyan":[0,255,255],"darkblue":[0,0,139],"darkcyan":[0,139,139],"darkgoldenrod":[184,134,11],"darkgray":[169,169,169],"darkgreen":[0,100,0],"darkgrey":[169,169,169],"darkkhaki":[189,183,107],"darkmagenta":[139,0,139],"darkolivegreen":[85,107,47],"darkorange":[255,140,0],"darkorchid":[153,50,204],"darkred":[139,0,0],"darksalmon":[233,150,122],"darkseagreen":[143,188,143],"darkslateblue":[72,61,139],"darkslategray":[47,79,79],"darkslategrey":[47,79,79],"darkturquoise":[0,206,209],"darkviolet":[148,0,211],"deeppink":[255,20,147],"deepskyblue":[0,191,255],"dimgray":[105,105,105],"dimgrey":[105,105,105],"dodgerblue":[30,144,255],"firebrick":[178,34,34],"floralwhite":[255,250,240],"forestgreen":[34,139,34],"fuchsia":[255,0,255],"gainsboro":[220,220,220],"ghostwhite":[248,248,255],"gold":[255,215,0],"goldenrod":[218,165,32],"gray":[128,128,128],"green":[0,128,0],"greenyellow":[173,255,47],"grey":[128,128,128],"honeydew":[240,255,240],"hotpink":[255,105,180],"indianred":[205,92,92],"indigo":[75,0,130],"ivory":[255,255,240],"khaki":[240,230,140],"lavender":[230,230,250],"lavenderblush":[255,240,245],"lawngreen":[124,252,0],"lemonchiffon":[255,250,205],"lightblue":[173,216,230],"lightcoral":[240,128,128],"lightcyan":[224,255,255],"lightgoldenrodyellow":[250,250,210],"lightgray":[211,211,211],"lightgreen":[144,238,144],"lightgrey":[211,211,211],"lightpink":[255,182,193],"lightsalmon":[255,160,122],"lightseagreen":[32,178,170],"lightskyblue":[135,206,250],"lightslategray":[119,136,153],"lightslategrey":[119,136,153],"lightsteelblue":[176,196,222],"lightyellow":[255,255,224],"lime":[0,255,0],"limegreen":[50,205,50],"linen":[250,240,230],"magenta":[255,0,255],"maroon":[128,0,0],"mediumaquamarine":[102,205,170],"mediumblue":[0,0,205],"mediumorchid":[186,85,211],"mediumpurple":[147,112,219],"mediumseagreen":[60,179,113],"mediumslateblue":[123,104,238],"mediumspringgreen":[0,250,154],"mediumturquoise":[72,209,204],"mediumvioletred":[199,21,133],"midnightblue":[25,25,112],"mintcream":[245,255,250],"mistyrose":[255,228,225],"moccasin":[255,228,181],"navajowhite":[255,222,173],"navy":[0,0,128],"oldlace":[253,245,230],"olive":[128,128,0],"olivedrab":[107,142,35],"orange":[255,165,0],"orangered":[255,69,0],"orchid":[218,112,214],"palegoldenrod":[238,232,170],"palegreen":[152,251,152],"paleturquoise":[175,238,238],"palevioletred":[219,112,147],"papayawhip":[255,239,213],"peachpuff":[255,218,185],"peru":[205,133,63],"pink":[255,192,203],"plum":[221,160,221],"powderblue":[176,224,230],"purple":[128,0,128],"rebeccapurple":[102,51,153],"red":[255,0,0],"rosybrown":[188,143,143],"royalblue":[65,105,225],"saddlebrown":[139,69,19],"salmon":[250,128,114],"sandybrown":[244,164,96],"seagreen":[46,139,87],"seashell":[255,245,238],"sienna":[160,82,45],"silver":[192,192,192],"skyblue":[135,206,235],"slateblue":[106,90,205],"slategray":[112,128,144],"slategrey":[112,128,144],"snow":[255,250,250],"springgreen":[0,255,127],"steelblue":[70,130,180],"tan":[210,180,140],"teal":[0,128,128],"thistle":[216,191,216],"tomato":[255,99,71],"turquoise":[64,224,208],"violet":[238,130,238],"wheat":[245,222,179],"white":[255,255,255],"whitesmoke":[245,245,245],"yellow":[255,255,0],"yellowgreen":[154,205,50]},At={exports:{}},_t=function(t){return!(!t||"string"==typeof t)&&(t instanceof Array||Array.isArray(t)||t.length>=0&&(t.splice instanceof Function||Object.getOwnPropertyDescriptor(t,t.length-1)&&"String"!==t.constructor.name))},Ot=Array.prototype.concat,xt=Array.prototype.slice,St=At.exports=function(t){for(var e=[],n=0,r=t.length;n<r;n++){var s=t[n];_t(s)?e=Ot.call(e,xt.call(s)):e.push(s)}return e};St.wrap=function(t){return function(){return t(St(arguments))}};var It=Tt,kt=At.exports,Et=Object.hasOwnProperty,Ct=Object.create(null);for(var Ut in It)Et.call(It,Ut)&&(Ct[It[Ut]]=Ut);var Ft=Mt.exports={to:{},get:{}};function Nt(t,e,n){return Math.min(Math.max(e,t),n)}function Pt(t){var e=Math.round(t).toString(16).toUpperCase();return e.length<2?"0"+e:e}Ft.get=function(t){var e,n;switch(t.substring(0,3).toLowerCase()){case"hsl":e=Ft.get.hsl(t),n="hsl";break;case"hwb":e=Ft.get.hwb(t),n="hwb";break;default:e=Ft.get.rgb(t),n="rgb"}return e?{model:n,value:e}:null},Ft.get.rgb=function(t){if(!t)return null;var e,n,r,s=[0,0,0,1];if(e=t.match(/^#([a-f0-9]{6})([a-f0-9]{2})?$/i)){for(r=e[2],e=e[1],n=0;n<3;n++){var i=2*n;s[n]=parseInt(e.slice(i,i+2),16)}r&&(s[3]=parseInt(r,16)/255)}else if(e=t.match(/^#([a-f0-9]{3,4})$/i)){for(r=(e=e[1])[3],n=0;n<3;n++)s[n]=parseInt(e[n]+e[n],16);r&&(s[3]=parseInt(r+r,16)/255)}else if(e=t.match(/^rgba?\\(\\s*([+-]?\\d+)(?=[\\s,])\\s*(?:,\\s*)?([+-]?\\d+)(?=[\\s,])\\s*(?:,\\s*)?([+-]?\\d+)\\s*(?:[,|\\/]\\s*([+-]?[\\d\\.]+)(%?)\\s*)?\\)$/)){for(n=0;n<3;n++)s[n]=parseInt(e[n+1],0);e[4]&&(e[5]?s[3]=.01*parseFloat(e[4]):s[3]=parseFloat(e[4]))}else{if(!(e=t.match(/^rgba?\\(\\s*([+-]?[\\d\\.]+)\\%\\s*,?\\s*([+-]?[\\d\\.]+)\\%\\s*,?\\s*([+-]?[\\d\\.]+)\\%\\s*(?:[,|\\/]\\s*([+-]?[\\d\\.]+)(%?)\\s*)?\\)$/)))return(e=t.match(/^(\\w+)$/))?"transparent"===e[1]?[0,0,0,0]:Et.call(It,e[1])?((s=It[e[1]])[3]=1,s):null:null;for(n=0;n<3;n++)s[n]=Math.round(2.55*parseFloat(e[n+1]));e[4]&&(e[5]?s[3]=.01*parseFloat(e[4]):s[3]=parseFloat(e[4]))}for(n=0;n<3;n++)s[n]=Nt(s[n],0,255);return s[3]=Nt(s[3],0,1),s},Ft.get.hsl=function(t){if(!t)return null;var e=t.match(/^hsla?\\(\\s*([+-]?(?:\\d{0,3}\\.)?\\d+)(?:deg)?\\s*,?\\s*([+-]?[\\d\\.]+)%\\s*,?\\s*([+-]?[\\d\\.]+)%\\s*(?:[,|\\/]\\s*([+-]?(?=\\.\\d|\\d)(?:0|[1-9]\\d*)?(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)\\s*)?\\)$/);if(e){var n=parseFloat(e[4]);return[(parseFloat(e[1])%360+360)%360,Nt(parseFloat(e[2]),0,100),Nt(parseFloat(e[3]),0,100),Nt(isNaN(n)?1:n,0,1)]}return null},Ft.get.hwb=function(t){if(!t)return null;var e=t.match(/^hwb\\(\\s*([+-]?\\d{0,3}(?:\\.\\d+)?)(?:deg)?\\s*,\\s*([+-]?[\\d\\.]+)%\\s*,\\s*([+-]?[\\d\\.]+)%\\s*(?:,\\s*([+-]?(?=\\.\\d|\\d)(?:0|[1-9]\\d*)?(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)\\s*)?\\)$/);if(e){var n=parseFloat(e[4]);return[(parseFloat(e[1])%360+360)%360,Nt(parseFloat(e[2]),0,100),Nt(parseFloat(e[3]),0,100),Nt(isNaN(n)?1:n,0,1)]}return null},Ft.to.hex=function(){var t=kt(arguments);return"#"+Pt(t[0])+Pt(t[1])+Pt(t[2])+(t[3]<1?Pt(Math.round(255*t[3])):"")},Ft.to.rgb=function(){var t=kt(arguments);return t.length<4||1===t[3]?"rgb("+Math.round(t[0])+", "+Math.round(t[1])+", "+Math.round(t[2])+")":"rgba("+Math.round(t[0])+", "+Math.round(t[1])+", "+Math.round(t[2])+", "+t[3]+")"},Ft.to.rgb.percent=function(){var t=kt(arguments),e=Math.round(t[0]/255*100),n=Math.round(t[1]/255*100),r=Math.round(t[2]/255*100);return t.length<4||1===t[3]?"rgb("+e+"%, "+n+"%, "+r+"%)":"rgba("+e+"%, "+n+"%, "+r+"%, "+t[3]+")"},Ft.to.hsl=function(){var t=kt(arguments);return t.length<4||1===t[3]?"hsl("+t[0]+", "+t[1]+"%, "+t[2]+"%)":"hsla("+t[0]+", "+t[1]+"%, "+t[2]+"%, "+t[3]+")"},Ft.to.hwb=function(){var t=kt(arguments),e="";return t.length>=4&&1!==t[3]&&(e=", "+t[3]),"hwb("+t[0]+", "+t[1]+"%, "+t[2]+"%"+e+")"},Ft.to.keyword=function(t){return Ct[t.slice(0,3)]};var Bt={exports:{}},Dt=Tt,Rt={};for(var Lt in Dt)Dt.hasOwnProperty(Lt)&&(Rt[Dt[Lt]]=Lt);var zt=Bt.exports={rgb:{channels:3,labels:"rgb"},hsl:{channels:3,labels:"hsl"},hsv:{channels:3,labels:"hsv"},hwb:{channels:3,labels:"hwb"},cmyk:{channels:4,labels:"cmyk"},xyz:{channels:3,labels:"xyz"},lab:{channels:3,labels:"lab"},lch:{channels:3,labels:"lch"},hex:{channels:1,labels:["hex"]},keyword:{channels:1,labels:["keyword"]},ansi16:{channels:1,labels:["ansi16"]},ansi256:{channels:1,labels:["ansi256"]},hcg:{channels:3,labels:["h","c","g"]},apple:{channels:3,labels:["r16","g16","b16"]},gray:{channels:1,labels:["gray"]}};for(var jt in zt)if(zt.hasOwnProperty(jt)){if(!("channels"in zt[jt]))throw new Error("missing channels property: "+jt);if(!("labels"in zt[jt]))throw new Error("missing channel labels property: "+jt);if(zt[jt].labels.length!==zt[jt].channels)throw new Error("channel and label counts mismatch: "+jt);var Vt=zt[jt].channels,qt=zt[jt].labels;delete zt[jt].channels,delete zt[jt].labels,Object.defineProperty(zt[jt],"channels",{value:Vt}),Object.defineProperty(zt[jt],"labels",{value:qt})}function Gt(t,e){return Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2)+Math.pow(t[2]-e[2],2)}zt.rgb.hsl=function(t){var e,n,r=t[0]/255,s=t[1]/255,i=t[2]/255,o=Math.min(r,s,i),a=Math.max(r,s,i),c=a-o;return a===o?e=0:r===a?e=(s-i)/c:s===a?e=2+(i-r)/c:i===a&&(e=4+(r-s)/c),(e=Math.min(60*e,360))<0&&(e+=360),n=(o+a)/2,[e,100*(a===o?0:n<=.5?c/(a+o):c/(2-a-o)),100*n]},zt.rgb.hsv=function(t){var e,n,r,s,i,o=t[0]/255,a=t[1]/255,c=t[2]/255,u=Math.max(o,a,c),f=u-Math.min(o,a,c),h=function(t){return(u-t)/6/f+.5};return 0===f?s=i=0:(i=f/u,e=h(o),n=h(a),r=h(c),o===u?s=r-n:a===u?s=1/3+e-r:c===u&&(s=2/3+n-e),s<0?s+=1:s>1&&(s-=1)),[360*s,100*i,100*u]},zt.rgb.hwb=function(t){var e=t[0],n=t[1],r=t[2];return[zt.rgb.hsl(t)[0],100*(1/255*Math.min(e,Math.min(n,r))),100*(r=1-1/255*Math.max(e,Math.max(n,r)))]},zt.rgb.cmyk=function(t){var e,n=t[0]/255,r=t[1]/255,s=t[2]/255;return[100*((1-n-(e=Math.min(1-n,1-r,1-s)))/(1-e)||0),100*((1-r-e)/(1-e)||0),100*((1-s-e)/(1-e)||0),100*e]},zt.rgb.keyword=function(t){var e=Rt[t];if(e)return e;var n,r=1/0;for(var s in Dt)if(Dt.hasOwnProperty(s)){var i=Gt(t,Dt[s]);i<r&&(r=i,n=s)}return n},zt.keyword.rgb=function(t){return Dt[t]},zt.rgb.xyz=function(t){var e=t[0]/255,n=t[1]/255,r=t[2]/255;return[100*(.4124*(e=e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92)+.3576*(n=n>.04045?Math.pow((n+.055)/1.055,2.4):n/12.92)+.1805*(r=r>.04045?Math.pow((r+.055)/1.055,2.4):r/12.92)),100*(.2126*e+.7152*n+.0722*r),100*(.0193*e+.1192*n+.9505*r)]},zt.rgb.lab=function(t){var e=zt.rgb.xyz(t),n=e[0],r=e[1],s=e[2];return r/=100,s/=108.883,n=(n/=95.047)>.008856?Math.pow(n,1/3):7.787*n+16/116,[116*(r=r>.008856?Math.pow(r,1/3):7.787*r+16/116)-16,500*(n-r),200*(r-(s=s>.008856?Math.pow(s,1/3):7.787*s+16/116))]},zt.hsl.rgb=function(t){var e,n,r,s,i,o=t[0]/360,a=t[1]/100,c=t[2]/100;if(0===a)return[i=255*c,i,i];e=2*c-(n=c<.5?c*(1+a):c+a-c*a),s=[0,0,0];for(var u=0;u<3;u++)(r=o+1/3*-(u-1))<0&&r++,r>1&&r--,i=6*r<1?e+6*(n-e)*r:2*r<1?n:3*r<2?e+(n-e)*(2/3-r)*6:e,s[u]=255*i;return s},zt.hsl.hsv=function(t){var e=t[0],n=t[1]/100,r=t[2]/100,s=n,i=Math.max(r,.01);return n*=(r*=2)<=1?r:2-r,s*=i<=1?i:2-i,[e,100*(0===r?2*s/(i+s):2*n/(r+n)),100*((r+n)/2)]},zt.hsv.rgb=function(t){var e=t[0]/60,n=t[1]/100,r=t[2]/100,s=Math.floor(e)%6,i=e-Math.floor(e),o=255*r*(1-n),a=255*r*(1-n*i),c=255*r*(1-n*(1-i));switch(r*=255,s){case 0:return[r,c,o];case 1:return[a,r,o];case 2:return[o,r,c];case 3:return[o,a,r];case 4:return[c,o,r];case 5:return[r,o,a]}},zt.hsv.hsl=function(t){var e,n,r,s=t[0],i=t[1]/100,o=t[2]/100,a=Math.max(o,.01);return r=(2-i)*o,n=i*a,[s,100*(n=(n/=(e=(2-i)*a)<=1?e:2-e)||0),100*(r/=2)]},zt.hwb.rgb=function(t){var e,n,r,s,i,o,a,c=t[0]/360,u=t[1]/100,f=t[2]/100,h=u+f;switch(h>1&&(u/=h,f/=h),r=6*c-(e=Math.floor(6*c)),0!=(1&e)&&(r=1-r),s=u+r*((n=1-f)-u),e){default:case 6:case 0:i=n,o=s,a=u;break;case 1:i=s,o=n,a=u;break;case 2:i=u,o=n,a=s;break;case 3:i=u,o=s,a=n;break;case 4:i=s,o=u,a=n;break;case 5:i=n,o=u,a=s}return[255*i,255*o,255*a]},zt.cmyk.rgb=function(t){var e=t[0]/100,n=t[1]/100,r=t[2]/100,s=t[3]/100;return[255*(1-Math.min(1,e*(1-s)+s)),255*(1-Math.min(1,n*(1-s)+s)),255*(1-Math.min(1,r*(1-s)+s))]},zt.xyz.rgb=function(t){var e,n,r,s=t[0]/100,i=t[1]/100,o=t[2]/100;return n=-.9689*s+1.8758*i+.0415*o,r=.0557*s+-.204*i+1.057*o,e=(e=3.2406*s+-1.5372*i+-.4986*o)>.0031308?1.055*Math.pow(e,1/2.4)-.055:12.92*e,n=n>.0031308?1.055*Math.pow(n,1/2.4)-.055:12.92*n,r=r>.0031308?1.055*Math.pow(r,1/2.4)-.055:12.92*r,[255*(e=Math.min(Math.max(0,e),1)),255*(n=Math.min(Math.max(0,n),1)),255*(r=Math.min(Math.max(0,r),1))]},zt.xyz.lab=function(t){var e=t[0],n=t[1],r=t[2];return n/=100,r/=108.883,e=(e/=95.047)>.008856?Math.pow(e,1/3):7.787*e+16/116,[116*(n=n>.008856?Math.pow(n,1/3):7.787*n+16/116)-16,500*(e-n),200*(n-(r=r>.008856?Math.pow(r,1/3):7.787*r+16/116))]},zt.lab.xyz=function(t){var e,n,r,s=t[0];e=t[1]/500+(n=(s+16)/116),r=n-t[2]/200;var i=Math.pow(n,3),o=Math.pow(e,3),a=Math.pow(r,3);return n=i>.008856?i:(n-16/116)/7.787,e=o>.008856?o:(e-16/116)/7.787,r=a>.008856?a:(r-16/116)/7.787,[e*=95.047,n*=100,r*=108.883]},zt.lab.lch=function(t){var e,n=t[0],r=t[1],s=t[2];return(e=360*Math.atan2(s,r)/2/Math.PI)<0&&(e+=360),[n,Math.sqrt(r*r+s*s),e]},zt.lch.lab=function(t){var e,n=t[0],r=t[1];return e=t[2]/360*2*Math.PI,[n,r*Math.cos(e),r*Math.sin(e)]},zt.rgb.ansi16=function(t){var e=t[0],n=t[1],r=t[2],s=1 in arguments?arguments[1]:zt.rgb.hsv(t)[2];if(0===(s=Math.round(s/50)))return 30;var i=30+(Math.round(r/255)<<2|Math.round(n/255)<<1|Math.round(e/255));return 2===s&&(i+=60),i},zt.hsv.ansi16=function(t){return zt.rgb.ansi16(zt.hsv.rgb(t),t[2])},zt.rgb.ansi256=function(t){var e=t[0],n=t[1],r=t[2];return e===n&&n===r?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(n/255*5)+Math.round(r/255*5)},zt.ansi16.rgb=function(t){var e=t%10;if(0===e||7===e)return t>50&&(e+=3.5),[e=e/10.5*255,e,e];var n=.5*(1+~~(t>50));return[(1&e)*n*255,(e>>1&1)*n*255,(e>>2&1)*n*255]},zt.ansi256.rgb=function(t){if(t>=232){var e=10*(t-232)+8;return[e,e,e]}var n;return t-=16,[Math.floor(t/36)/5*255,Math.floor((n=t%36)/6)/5*255,n%6/5*255]},zt.rgb.hex=function(t){var e=(((255&Math.round(t[0]))<<16)+((255&Math.round(t[1]))<<8)+(255&Math.round(t[2]))).toString(16).toUpperCase();return"000000".substring(e.length)+e},zt.hex.rgb=function(t){var e=t.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!e)return[0,0,0];var n=e[0];3===e[0].length&&(n=n.split("").map((function(t){return t+t})).join(""));var r=parseInt(n,16);return[r>>16&255,r>>8&255,255&r]},zt.rgb.hcg=function(t){var e,n=t[0]/255,r=t[1]/255,s=t[2]/255,i=Math.max(Math.max(n,r),s),o=Math.min(Math.min(n,r),s),a=i-o;return e=a<=0?0:i===n?(r-s)/a%6:i===r?2+(s-n)/a:4+(n-r)/a+4,e/=6,[360*(e%=1),100*a,100*(a<1?o/(1-a):0)]},zt.hsl.hcg=function(t){var e=t[1]/100,n=t[2]/100,r=1,s=0;return(r=n<.5?2*e*n:2*e*(1-n))<1&&(s=(n-.5*r)/(1-r)),[t[0],100*r,100*s]},zt.hsv.hcg=function(t){var e=t[1]/100,n=t[2]/100,r=e*n,s=0;return r<1&&(s=(n-r)/(1-r)),[t[0],100*r,100*s]},zt.hcg.rgb=function(t){var e=t[0]/360,n=t[1]/100,r=t[2]/100;if(0===n)return[255*r,255*r,255*r];var s,i=[0,0,0],o=e%1*6,a=o%1,c=1-a;switch(Math.floor(o)){case 0:i[0]=1,i[1]=a,i[2]=0;break;case 1:i[0]=c,i[1]=1,i[2]=0;break;case 2:i[0]=0,i[1]=1,i[2]=a;break;case 3:i[0]=0,i[1]=c,i[2]=1;break;case 4:i[0]=a,i[1]=0,i[2]=1;break;default:i[0]=1,i[1]=0,i[2]=c}return s=(1-n)*r,[255*(n*i[0]+s),255*(n*i[1]+s),255*(n*i[2]+s)]},zt.hcg.hsv=function(t){var e=t[1]/100,n=e+t[2]/100*(1-e),r=0;return n>0&&(r=e/n),[t[0],100*r,100*n]},zt.hcg.hsl=function(t){var e=t[1]/100,n=t[2]/100*(1-e)+.5*e,r=0;return n>0&&n<.5?r=e/(2*n):n>=.5&&n<1&&(r=e/(2*(1-n))),[t[0],100*r,100*n]},zt.hcg.hwb=function(t){var e=t[1]/100,n=e+t[2]/100*(1-e);return[t[0],100*(n-e),100*(1-n)]},zt.hwb.hcg=function(t){var e=t[1]/100,n=1-t[2]/100,r=n-e,s=0;return r<1&&(s=(n-r)/(1-r)),[t[0],100*r,100*s]},zt.apple.rgb=function(t){return[t[0]/65535*255,t[1]/65535*255,t[2]/65535*255]},zt.rgb.apple=function(t){return[t[0]/255*65535,t[1]/255*65535,t[2]/255*65535]},zt.gray.rgb=function(t){return[t[0]/100*255,t[0]/100*255,t[0]/100*255]},zt.gray.hsl=zt.gray.hsv=function(t){return[0,0,t[0]]},zt.gray.hwb=function(t){return[0,100,t[0]]},zt.gray.cmyk=function(t){return[0,0,0,t[0]]},zt.gray.lab=function(t){return[t[0],0,0]},zt.gray.hex=function(t){var e=255&Math.round(t[0]/100*255),n=((e<<16)+(e<<8)+e).toString(16).toUpperCase();return"000000".substring(n.length)+n},zt.rgb.gray=function(t){return[(t[0]+t[1]+t[2])/3/255*100]};var $t=Bt.exports;function Xt(t){var e=function(){for(var t={},e=Object.keys($t),n=e.length,r=0;r<n;r++)t[e[r]]={distance:-1,parent:null};return t}(),n=[t];for(e[t].distance=0;n.length;)for(var r=n.pop(),s=Object.keys($t[r]),i=s.length,o=0;o<i;o++){var a=s[o],c=e[a];-1===c.distance&&(c.distance=e[r].distance+1,c.parent=r,n.unshift(a))}return e}function Ht(t,e){return function(n){return e(t(n))}}function Jt(t,e){for(var n=[e[t].parent,t],r=$t[e[t].parent][t],s=e[t].parent;e[s].parent;)n.unshift(e[s].parent),r=Ht($t[e[s].parent][s],r),s=e[s].parent;return r.conversion=n,r}var Kt=Bt.exports,Yt=function(t){for(var e=Xt(t),n={},r=Object.keys(e),s=r.length,i=0;i<s;i++){var o=r[i];null!==e[o].parent&&(n[o]=Jt(o,e))}return n},Qt={};Object.keys(Kt).forEach((function(t){Qt[t]={},Object.defineProperty(Qt[t],"channels",{value:Kt[t].channels}),Object.defineProperty(Qt[t],"labels",{value:Kt[t].labels});var e=Yt(t);Object.keys(e).forEach((function(n){var r=e[n];Qt[t][n]=function(t){var e=function(e){if(null==e)return e;arguments.length>1&&(e=Array.prototype.slice.call(arguments));var n=t(e);if("object"==typeof n)for(var r=n.length,s=0;s<r;s++)n[s]=Math.round(n[s]);return n};return"conversion"in t&&(e.conversion=t.conversion),e}(r),Qt[t][n].raw=function(t){var e=function(e){return null==e?e:(arguments.length>1&&(e=Array.prototype.slice.call(arguments)),t(e))};return"conversion"in t&&(e.conversion=t.conversion),e}(r)}))}));var Wt=Qt,Zt=Mt.exports,te=Wt,ee=[].slice,ne=["keyword","gray","hex"],re={};Object.keys(te).forEach((function(t){re[ee.call(te[t].labels).sort().join("")]=t}));var se={};function ie(t,e){if(!(this instanceof ie))return new ie(t,e);if(e&&e in ne&&(e=null),e&&!(e in te))throw new Error("Unknown model: "+e);var n,r;if(null==t)this.model="rgb",this.color=[0,0,0],this.valpha=1;else if(t instanceof ie)this.model=t.model,this.color=t.color.slice(),this.valpha=t.valpha;else if("string"==typeof t){var s=Zt.get(t);if(null===s)throw new Error("Unable to parse color from string: "+t);this.model=s.model,r=te[this.model].channels,this.color=s.value.slice(0,r),this.valpha="number"==typeof s.value[r]?s.value[r]:1}else if(t.length){this.model=e||"rgb",r=te[this.model].channels;var i=ee.call(t,0,r);this.color=ue(i,r),this.valpha="number"==typeof t[r]?t[r]:1}else if("number"==typeof t)t&=16777215,this.model="rgb",this.color=[t>>16&255,t>>8&255,255&t],this.valpha=1;else{this.valpha=1;var o=Object.keys(t);"alpha"in t&&(o.splice(o.indexOf("alpha"),1),this.valpha="number"==typeof t.alpha?t.alpha:0);var a=o.sort().join("");if(!(a in re))throw new Error("Unable to parse color from object: "+JSON.stringify(t));this.model=re[a];var c=te[this.model].labels,u=[];for(n=0;n<c.length;n++)u.push(t[c[n]]);this.color=ue(u)}if(se[this.model])for(r=te[this.model].channels,n=0;n<r;n++){var f=se[this.model][n];f&&(this.color[n]=f(this.color[n]))}this.valpha=Math.max(0,Math.min(1,this.valpha)),Object.freeze&&Object.freeze(this)}function oe(t,e,n){return(t=Array.isArray(t)?t:[t]).forEach((function(t){(se[t]||(se[t]=[]))[e]=n})),t=t[0],function(r){var s;return arguments.length?(n&&(r=n(r)),(s=this[t]()).color[e]=r,s):(s=this[t]().color[e],n&&(s=n(s)),s)}}function ae(t){return function(e){return Math.max(0,Math.min(t,e))}}function ce(t){return Array.isArray(t)?t:[t]}function ue(t,e){for(var n=0;n<e;n++)"number"!=typeof t[n]&&(t[n]=0);return t}function fe(t){return null==t}function he(t){return"object"==typeof t&&!!t}function le(t){return t/Math.PI*180}function de(t){return Math.sign?Math.sign(t):0===(t=+t)||isNaN(t)?Number(t):t>0?1:-1}ie.prototype={toString:function(){return this.string()},toJSON:function(){return this[this.model]()},string:function(t){var e=this.model in Zt.to?this:this.rgb(),n=1===(e=e.round("number"==typeof t?t:1)).valpha?e.color:e.color.concat(this.valpha);return Zt.to[e.model](n)},percentString:function(t){var e=this.rgb().round("number"==typeof t?t:1),n=1===e.valpha?e.color:e.color.concat(this.valpha);return Zt.to.rgb.percent(n)},array:function(){return 1===this.valpha?this.color.slice():this.color.concat(this.valpha)},object:function(){for(var t={},e=te[this.model].channels,n=te[this.model].labels,r=0;r<e;r++)t[n[r]]=this.color[r];return 1!==this.valpha&&(t.alpha=this.valpha),t},unitArray:function(){var t=this.rgb().color;return t[0]/=255,t[1]/=255,t[2]/=255,1!==this.valpha&&t.push(this.valpha),t},unitObject:function(){var t=this.rgb().object();return t.r/=255,t.g/=255,t.b/=255,1!==this.valpha&&(t.alpha=this.valpha),t},round:function(t){return t=Math.max(t||0,0),new ie(this.color.map(function(t){return function(e){return function(t,e){return Number(t.toFixed(e))}(e,t)}}(t)).concat(this.valpha),this.model)},alpha:function(t){return arguments.length?new ie(this.color.concat(Math.max(0,Math.min(1,t))),this.model):this.valpha},red:oe("rgb",0,ae(255)),green:oe("rgb",1,ae(255)),blue:oe("rgb",2,ae(255)),hue:oe(["hsl","hsv","hsl","hwb","hcg"],0,(function(t){return(t%360+360)%360})),saturationl:oe("hsl",1,ae(100)),lightness:oe("hsl",2,ae(100)),saturationv:oe("hsv",1,ae(100)),value:oe("hsv",2,ae(100)),chroma:oe("hcg",1,ae(100)),gray:oe("hcg",2,ae(100)),white:oe("hwb",1,ae(100)),wblack:oe("hwb",2,ae(100)),cyan:oe("cmyk",0,ae(100)),magenta:oe("cmyk",1,ae(100)),yellow:oe("cmyk",2,ae(100)),black:oe("cmyk",3,ae(100)),x:oe("xyz",0,ae(100)),y:oe("xyz",1,ae(100)),z:oe("xyz",2,ae(100)),l:oe("lab",0,ae(100)),a:oe("lab",1),b:oe("lab",2),keyword:function(t){return arguments.length?new ie(t):te[this.model].keyword(this.color)},hex:function(t){return arguments.length?new ie(t):Zt.to.hex(this.rgb().round().color)},rgbNumber:function(){var t=this.rgb().color;return(255&t[0])<<16|(255&t[1])<<8|255&t[2]},luminosity:function(){for(var t=this.rgb().color,e=[],n=0;n<t.length;n++){var r=t[n]/255;e[n]=r<=.03928?r/12.92:Math.pow((r+.055)/1.055,2.4)}return.2126*e[0]+.7152*e[1]+.0722*e[2]},contrast:function(t){var e=this.luminosity(),n=t.luminosity();return e>n?(e+.05)/(n+.05):(n+.05)/(e+.05)},level:function(t){var e=this.contrast(t);return e>=7.1?"AAA":e>=4.5?"AA":""},isDark:function(){var t=this.rgb().color;return(299*t[0]+587*t[1]+114*t[2])/1e3<128},isLight:function(){return!this.isDark()},negate:function(){for(var t=this.rgb(),e=0;e<3;e++)t.color[e]=255-t.color[e];return t},lighten:function(t){var e=this.hsl();return e.color[2]+=e.color[2]*t,e},darken:function(t){var e=this.hsl();return e.color[2]-=e.color[2]*t,e},saturate:function(t){var e=this.hsl();return e.color[1]+=e.color[1]*t,e},desaturate:function(t){var e=this.hsl();return e.color[1]-=e.color[1]*t,e},whiten:function(t){var e=this.hwb();return e.color[1]+=e.color[1]*t,e},blacken:function(t){var e=this.hwb();return e.color[2]+=e.color[2]*t,e},grayscale:function(){var t=this.rgb().color,e=.3*t[0]+.59*t[1]+.11*t[2];return ie.rgb(e,e,e)},fade:function(t){return this.alpha(this.valpha-this.valpha*t)},opaquer:function(t){return this.alpha(this.valpha+this.valpha*t)},rotate:function(t){var e=this.hsl(),n=e.color[0];return n=(n=(n+t)%360)<0?360+n:n,e.color[0]=n,e},mix:function(t,e){if(!t||!t.rgb)throw new Error(\'Argument to "mix" was not a Color instance, but rather an instance of \'+typeof t);var n=t.rgb(),r=this.rgb(),s=void 0===e?.5:e,i=2*s-1,o=n.alpha()-r.alpha(),a=((i*o==-1?i:(i+o)/(1+i*o))+1)/2,c=1-a;return ie.rgb(a*n.red()+c*r.red(),a*n.green()+c*r.green(),a*n.blue()+c*r.blue(),n.alpha()*s+r.alpha()*(1-s))}},Object.keys(te).forEach((function(t){if(-1===ne.indexOf(t)){var e=te[t].channels;ie.prototype[t]=function(){if(this.model===t)return new ie(this);if(arguments.length)return new ie(arguments,t);var n="number"==typeof arguments[e]?e:this.valpha;return new ie(ce(te[this.model][t].raw(this.color)).concat(n),t)},ie[t]=function(n){return"number"==typeof n&&(n=ue(ee.call(arguments),e)),new ie(n,t)}}}));const ye=[1,1,1,1,2,2,3,0];function me(t){const e=t.length;let n="";for(let r=0;r<e;){let s=t[r++];if(128&s){let n=ye[s>>3&7];if(!(64&s)||!n||r+n>e)return null;for(s&=63>>n;n>0;n-=1){const e=t[r++];if(128!=(192&e))return null;s=s<<6|63&e}}n+=String.fromCharCode(s)}return n}new Array(3),new Array(3);const be=[1/6378137,1/6378137,1/6356752.314245179],pe=[1/40680631590769,1/40680631590769,1/40408299984661.445],we=new Array(3),ge=new Array(3),ve=new Array(3);function Me(t,e){const n=pe,r=function(t,e,n,r,s){const i=e[0],o=e[1],a=e[2],c=n[0],u=n[1],f=n[2],h=i*i*c*c,l=o*o*u*u,d=a*a*f*f,y=h+l+d,m=Math.sqrt(1/y),p=b(Te,e,m);if(y<s)return isFinite(m)?p:void 0;const w=r[0],g=r[1],v=r[2],M=Ae;M[0]=p[0]*w*2,M[1]=p[1]*g*2,M[2]=p[2]*v*2;let T,A,_,O,x,S,I,k,E,C,U,F=(1-m)*_e(e)/(.5*_e(M)),N=0;do{F-=N,_=1/(1+F*w),O=1/(1+F*g),x=1/(1+F*v),S=_*_,I=O*O,k=x*x,E=S*_,C=I*O,U=k*x,T=h*S+l*I+d*k-1,A=h*E*w+l*C*g+d*U*v;N=T/(-2*A)}while(Math.abs(T)>1e-12);return t[0]=i*_,t[1]=o*O,t[2]=a*x,t}(we,e,be,n,.1);let s=T(ge,r,n);s=function(t,e){const n=e[0],r=e[1],s=e[2];let i=n*n+r*r+s*s;i>0&&(i=Math.sqrt(i),t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i);return t}(s,s);const i=M(ve,e,r),o=Math.atan2(s[1],s[0]),a=Math.asin(s[2]),c=de(w(i,e))*_e(i);return t[0]=le(o),t[1]=le(a),t[2]=c,t}const Te=new Array(3),Ae=new Array(3);function _e(t){return f(t)}function Oe(t,e,n,r){n=n||0,r=r||n;const s=Math.abs(t-e);return s<=r||s<=n*Math.max(Math.abs(t),Math.abs(e))}function xe(t,e){let n="";for(let r=0;r<4;r++){const s=t.getUint8(e+r);n+=String.fromCharCode(s)}return n}const Se="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function Ie(t,e,n){const r=new Uint8Array(t,e,n);return Se?JSON.parse(Se.decode(r)):JSON.parse(me(r))}function ke(t,e,n){const r=new Uint8Array(t,e,n);return Se?JSON.parse(Se.decode(r)):JSON.parse(me(r))}function Ee(t,e,n){return{offset:e,byteLength:n}}function Ce(t,e,n,r){const{byteOffset:s,componentType:i,type:o}=t,{ctor:a,type:c}=function(t){return Ne[t]}(i||"UNSIGNED_SHORT"),u=function(t){if(!t)return 1;return Fe[t]}(o);return{byteStride:0,byteOffset:s+n,itemSize:u,count:r*u,componentType:c,array:new a(e,n+s,r*u)}}function Ue(t,e,n,r){const s=Ce(t,e,n,r);return s.array.buffer.byteLength!==e.byteLength&&(s.array=s.array.slice()),s}const Fe={"SCALAR":1,"VEC2":2,"VEC3":3,"VEC4":4};const Ne={"BYTE":{ctor:Int8Array,type:5120,name:"Int8Array"},"UNSIGNED_BYTE":{ctor:Uint8Array,type:5121,name:"Uint8Array"},"SHORT":{ctor:Int16Array,type:5122,name:"Int16Array"},"UNSIGNED_SHORT":{ctor:Uint16Array,type:5123,name:"Uint16Array"},"INT":{ctor:Int32Array,type:5124,name:"Int32Array"},"UNSIGNED_INT":{ctor:Uint32Array,type:5125,name:"Uint32Array"},"FLOAT":{ctor:Float32Array,type:5126,name:"Float32Array"},"DOUBLE":{ctor:Float64Array,type:5126,name:"Float64Array"}};function Pe(t){for(const e in Ne)if(t===Ne[e].ctor)return Ne[e].type;throw new Error("unrecognized ctor:"+t)}function Be(t,e,n,r){const s=t,i=e.length/3;for(let t=0;t<i;t++)s[3*t]=e[3*t]/65535*r[0]+n[0],s[3*t+1]=e[3*t+1]/65535*r[1]+n[1],s[3*t+2]=e[3*t+2]/65535*r[2]+n[2];return s}function De(t,e,n){const r=t.getUint32(12,!0),s=t.getUint32(16,!0),i=t.getUint32(20,!0),o=t.getUint32(24,!0),a=t.buffer;let c,u={},f={},h=null;r>0&&(u=Ie(a,e,r),e+=r),s>0&&(c=function(t,e,n){return{offset:e,byteLength:n}}(0,e,s),e+=s),i>0&&(f=ke(a,e,i),e+=i);const l=Ee(0,e,o);return h=a.slice(l.offset,l.offset+l.byteLength),n.push(h),{featureTable:u,featureTableBin:c,batchTable:f,batchTableBin:h}}const Re={up:{south:"east",north:"west",west:"south",east:"north"},down:{south:"west",north:"east",west:"north",east:"south"},south:{up:"west",down:"east",west:"down",east:"up"},north:{up:"east",down:"west",west:"up",east:"down"},west:{up:"north",down:"south",north:"down",south:"up"},east:{up:"south",down:"north",north:"up",south:"down"}},Le={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},ze={},je={east:[],north:[],up:[],west:[],south:[],down:[]};let Ve=[],qe=[],Ge=[];const $e=[0,0,0];const Xe=function(t,e){const n=Re[t][e];let r;const s=t+e;return ze[s]?r=ze[s]:(r=function(r,s,i){if(function(t,e){var n=t[0],r=t[1],s=t[2],i=e[0],o=e[1],a=e[2];return Math.abs(n-i)<=1e-6*Math.max(1,Math.abs(n),Math.abs(i))&&Math.abs(r-o)<=1e-6*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(s-a)<=1e-6*Math.max(1,Math.abs(s),Math.abs(a))}(r,$e))l(Ve,Le[t]),l(qe,Le[e]),l(Ge,Le[n]);else if(Oe(r[0],0,1e-14)&&Oe(r[1],0,1e-14)){const s=de(r[2]);l(Ve,Le[t]),"east"!==t&&"west"!==t&&b(Ve,Ve,s),l(qe,Le[e]),"east"!==e&&"west"!==e&&b(qe,qe,s),l(Ge,Le[n]),"east"!==n&&"west"!==n&&b(Ge,Ge,s)}else{!function(t,e){m(e,t,pe),p(e,e)}(r,je.up);const s=je.up,i=je.east;i[0]=-r[1],i[1]=r[0],i[2]=0,p(je.east,i),g(je.north,s,i),b(je.down,je.up,-1),b(je.west,je.east,-1),b(je.south,je.north,-1),Ve=je[t],qe=je[e],Ge=je[n]}return i[0]=Ve[0],i[1]=Ve[1],i[2]=Ve[2],i[3]=0,i[4]=qe[0],i[5]=qe[1],i[6]=qe[2],i[7]=0,i[8]=Ge[0],i[9]=Ge[1],i[10]=Ge[2],i[11]=0,i[12]=r[0],i[13]=r[1],i[14]=r[2],i[15]=1,i},ze[s]=r),r}("east","north"),He={5120:Int8Array,5122:Int16Array,5124:Int32Array,5121:Uint8Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};function Je(t){for(const e in He)if(t===He[e])return+e;throw new Error("unrecognized ctor:"+t)}\n/*!\n * @maptalks/gl v0.95.4\n * LICENSE : UNLICENSED\n * (c) 2016-2023 maptalks.com\n */const Ke=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof undefined)return global;throw new Error("unable to locate global object")},Ye=Ke(),Qe=Ye.gl_trans__coders=Ye.gl_trans__coders||{};Qe.inject=function(t){const e=t.toString(),n=e.indexOf("{")+1,r=e.substring(0,n),s=Ye.gl_trans__coders=Ye.gl_trans__coders||{};let i=`${r}\\n const _____getGlobal = ${Ke.toString()};\\n const g___lobals = _____getGlobal()\\n const tran_____scoders = g___lobals[\'gl_trans__coders\'] = g___lobals[\'gl_trans__coders\'] || {};`;for(const t in s)"inject"!==t&&"getTranscoder"!==t&&"registerTranscoder"!==t&&(i+=\'tran_____scoders["\'+t+\'"] =\'+s[t].toString()+"\\n;");return i+="\\n"+e.substring(r.length),i},Qe.registerTranscoder=function(t,e){Qe[t]=e},Qe.getTranscoder=function(t){return Qe[t]};let We=null;function Ze(){return We||(We={"image/crn":Qe.crn&&Qe.crn(),"image/ktx2":Qe.ktx2&&Qe.ktx2(),"image/cttf":Qe.ktx2&&Qe.ktx2(),"draco":Qe.draco&&Qe.draco()}),We}class tn{constructor(t,e,n){this.s=t,this.et=e||dt,this.i=n,this.nt=Ze()}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.rt(t,e,n,r,s)):J.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.rt(t,s,n,r)})}rt(t,e,n,r,s){const i=s&&s.maxTextureSize,o=this.st(e,n,r,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.et(a,o.glb,{transferable:!0,requestImage:this.s,decoders:this.nt,supportedFormats:this.i,maxTextureSize:i});return c.load({skipAttributeTransform:!1}).then(e=>{e.url=`${t}-${n}-${r}`;const s=c.transferables;for(let t=0;t<o.transferables.length;t++)s.indexOf(o.transferables[t])<0&&s.push(o.transferables[t]);return{magic:"b3dm",count:o.count,transferables:s,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,gltf:e}})}st(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported b3dm version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in b3dm header is inconsistent with b3dm\'s byte length, url: "+r;return console.warn(t),{error:t}}let o,a=s.getUint32(12,!0),c=s.getUint32(16,!0),u=s.getUint32(20,!0),f=s.getUint32(24,!0),h=28+e;u>=570425344?(h-=8,o=a,u=c,f=0,a=0,c=0):f>=570425344&&(h-=4,o=u,u=a,f=c,a=0,c=0);const l=[t];let d,y,m;if(a>0?(d=Ie(t,h,a),h+=a,o=d.BATCH_LENGTH):d={"BATCH_LENGTH":o},c>0&&(h+=c),u>0&&(y=ke(t,h,u),h+=u,f>0)){const e=Ee(0,h,f);m=t.slice(e.offset,e.offset+e.byteLength),h+=f,l.push(m)}const b=d.BATCH_LENGTH,p={};if(d&&d.BATCH_ID){p.BATCH_ID=Ue(d.BATCH_ID,t,(void 0).offset,b);const e=p.BATCH_ID.array&&p.BATCH_ID.array.buffer;e&&l.indexOf(e)<0&&l.push(e)}return{count:o,transferables:l,featureTable:d,batchTable:y,batchTableBin:m,b3dm:p,glb:{buffer:t,byteOffset:h,byteLength:s.byteLength+s.byteOffset-h}}}it(){return null}}class en{constructor(t,e,n,r){this.s=t,this.et=e||dt,this.i=n,this.nt=Ze(),this.ot=r}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.rt(t,e,n,r,s)):J.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.rt(t,s,n,r)})}rt(t,e,n,r,s){return this.ct(t,e,n,r,s).then(({gltf:s,transferables:i})=>{const o=this.ut(e,n,r,t);if(o.error)return Promise.resolve(o);for(let t=0;t<i.length;t++)-1===o.transferables.indexOf(i[t])&&o.transferables.push(i[t]);return delete s.transferables,Promise.resolve({magic:"i3dm",count:o.count,transferables:o.transferables,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,i3dm:o.i3dm,gltf:s})})}ct(t,e,n,r,s){const i=s&&s.maxTextureSize,o={transferable:!0,requestImage:this.s,decoders:this.nt,supportedFormats:this.i,maxTextureSize:i},a=new DataView(e,n,r),c=32+a.getUint32(12,!0)+a.getUint32(16,!0)+a.getUint32(20,!0)+a.getUint32(24,!0);if(0===a.getUint32(28,!0)){let r=me(new Uint8Array(e,c+n,a.byteLength-c));-1==r.indexOf("://")&&(r=t.substring(0,t.lastIndexOf("/"))+"/"+r);return r.indexOf(".glb")>0?J.getArrayBuffer(r,{}).then(t=>this.ft(r,{buffer:t.data,byteOffset:0},o)):J.getJSON(r,{}).then(t=>this.ft(r,t,o))}{const r={buffer:e,byteOffset:c+n,byteLength:a.byteLength-c};return this.ft(t,r,o)}}ft(t,e,n){const r=t.substring(0,t.lastIndexOf("/")),s=new this.et(r,e,n);return s.load({skipAttributeTransform:!0}).then(n=>{let r=0,i=0;return e.buffer&&(r=e.byteOffset||0,i=e.byteLength||0),n.url=`${t}-${r}-${i}`,{transferables:s.transferables,gltf:n}})}ut(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported pnts version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in pnts header is inconsistent with pnts\'s byte length, url: "+r;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:u,batchTableBin:f}=De(s,32+e,o),h={},l=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;h.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(h.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,n=a.QUANTIZED_VOLUME_SCALE,{byteOffset:r}=a.POSITION_QUANTIZED;h.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:l,componentType:5126,array:this.ht(new Uint16Array(t,r+c.offset,3*l),e,n)},o.push(h.POSITION.array.buffer)}if(a.BATCH_ID){h.BATCH_ID=Ue(a.BATCH_ID,t,c.offset,l);const e=h.BATCH_ID.array&&h.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;h.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(h.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,h.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(h.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;h.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:this.lt(new Uint16Array(t,e+c.offset,2*l))},o.push(h.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,h.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:this.lt(new Uint16Array(t,e+c.offset,2*l))},o.push(h.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;h.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,l).slice()},o.push(h.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;h.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(h.SCALE_NON_UNIFORM.array.buffer)}return{count:l,batchTable:u,batchTableBin:f,featureTable:a,i3dm:h,transferables:o}}lt(t){const e=t.length/2,n=new Float32Array(3*e),r=[];for(let s=0;s<e;s++)nn(r,t[2*s],t[2*s+1],65535),n[3*s]=r[0],n[3*s+1]=r[1],n[3*s+2]=r[2];return n}ht(t,e,n){return Be(new Float32Array(t.length),t,e,n)}it(){return null}}function nn(t,e,n,r){if(t[0]=rn(e,r),t[1]=rn(n,r),t[2]=1-(Math.abs(t[0])+Math.abs(t[1])),t[2]<0){const e=t[0];t[0]=(1-Math.abs(t[1]))*sn(e),t[1]=(1-Math.abs(e))*sn(t[1])}return p(t,t)}function rn(t,e){return function(t,e,n){return t<e?e:t>n?n:t}(t,0,e=function(t,e){if(null!=t)return t;return e}(e,255))/e*2-1}function sn(t){return t<0?-1:1}class on{constructor(){}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.rt(t,e,n,r)):J.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.rt(t,s,n,r)})}rt(t,e,n,r){return this.dt(e,n,r,t).then(t=>t.error?t:{magic:"pnts",count:t.count,transferables:t.transferables,featureTable:t.featureTable,batchTable:t.batchTable,batchTableBin:t.batchTableBin,pnts:t.pnts})}dt(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported pnts version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in pnts header is inconsistent with pnts\'s byte length, url: "+r;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:u,batchTableBin:f}=De(s,e+28,o),h=a.QUANTIZED_VOLUME_OFFSET,l=a.QUANTIZED_VOLUME_SCALE,d=a.POINTS_LENGTH;let y,m={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){m=a.extensions["3DTILES_draco_point_compression"],y=new DataView(t,m.byteOffset+c.offset,m.byteLength);const e={attributes:m.properties,useUniqueIDs:!1};return this.yt||(this.yt=Ze().draco),this.yt(y,e).then(e=>{const n=e.attributes;!a.POSITION&&!a.POSITION_QUANTIZED||n.POSITION||n.POSITION_QUANTIZED||(n.POSITION=a.POSITION,n.POSITION_QUANTIZED=a.POSITION_QUANTIZED),!(a.RGB||a.RGBA||a.RGB565)||n.RGB||n.RGBA||n.RGB565||(n.RGB=a.RGB,n.RGBA=a.RGBA,n.RGB565=a.RGB565),!a.NORMAL&&!a.NORMAL_OCT16P||n.NORMAL||n.NORMAL_OCT16P||(n.NORMAL=a.NORMAL,n.NORMAL_OCT16P=a.NORMAL_OCT16P);const r=this.bt(t,e.attributes,c.offset,d,o,h,l);if(e.attributes.BATCH_ID){const t=e.attributes.BATCH_ID.array;r.BATCH_ID={byteStride:0,byteOffset:0,itemSize:1,count:t.length,componentType:Pe(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(u).length){a.BATCH_ID?r.BATCH_ID=Ue(a.BATCH_ID,t,c.offset,d):r.BATCH_ID=an(d);const e=r.BATCH_ID.array&&r.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return{count:d,batchTable:u,batchTableBin:f,featureTable:a,pnts:r,transferables:o}})}const b=this.bt(t,a,c.offset,d,o,h,l);if(a.BATCH_ID||Object.keys(u).length){a.BATCH_ID?b.BATCH_ID=Ue(a.BATCH_ID,t,c.offset,d):b.BATCH_ID=an(d);const e=b.BATCH_ID.array&&b.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:d,batchTable:u,batchTableBin:f,featureTable:a,pnts:b,transferables:o})}bt(t,e,n,r,s,i,o){const a={};if(e.POSITION){let{byteOffset:i,array:o}=e.POSITION;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r*4);o=new Float32Array(e)}a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:o},s.push(o.buffer)}else if(e.POSITION_QUANTIZED){let{byteOffset:c}=e.POSITION_QUANTIZED;const{array:u}=e.POSITION_QUANTIZED;c=c||0;const f=u?0:n;a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:this.ht(u||new Uint16Array(t,c+f,3*r),i,o)},s.push(a.POSITION.array.buffer)}if(e.RGBA){let{byteOffset:i,array:o}=e.RGBA;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+4*r);o=new Uint8Array(e)}a.RGBA={byteStride:0,byteOffset:0,itemSize:4,count:r,componentType:5121,array:o},s.push(o.buffer)}else if(e.RGB){let{byteOffset:i,array:o}=e.RGB;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r);o=new Uint8Array(e)}a.RGB={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5121,array:o},s.push(o.buffer)}else if(e.RGB565){let{byteOffset:i,array:o}=e.RGB565;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+2*r);o=new Uint16Array(e)}a.RGB565={byteStride:0,byteOffset:0,itemSize:1,count:r,componentType:5123,array:o},s.push(o.buffer)}if(e.NORMAL){let{byteOffset:i,array:o}=e.NORMAL;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r*4);o=new Float32Array(e)}a.NORMAL={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:o},s.push(o.buffer)}else if(e.NORMAL_OCT16P){let{byteOffset:i,array:o}=e.NORMAL_OCT16P;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+2*r);o=new Uint8Array(e)}a.NORMAL_OCT16P={byteStride:0,byteOffset:0,itemSize:2,count:r,componentType:5121,array:o},s.push(o.buffer)}return a}ht(t,e,n){return Be(new Float32Array(t.length),t,e,n)}it(){return null}}function an(t){const e=(n=t)<256?Uint8Array:n<65536?Uint16Array:Uint32Array;var n;const r=new e(t);for(let e=0;e<t;e++)r[e]=e;return{byteStride:0,byteOffset:0,itemSize:1,count:t,componentType:Pe(e),array:r}}class cn{constructor(t,e,n,r){this.i=n,this.s=t,this.et=e||dt,this.ot=r}load(t,e,n=0,r=0,s){return e?this.rt(t,e,n,r,s):J.getArrayBuffer(t,{}).then(e=>{const s=e.data;return this.rt(t,s,n,r)})}rt(t,e,n,r,s){r||(r=e.byteLength);const i=this.pt(e,t,n,r),o=[];for(let n=0;n<i.length;n++){let r;if("b3dm"===i[n].magic)r=new tn(this.s,this.et,this.i);else if("i3dm"===i[n].magic)r=new en(this.s,this.et,this.i,this.ot);else if("pnts"===i[n].magic)r=new on;else{if("cmpt"!==i[n].magic){console.warn("Unsupported magic in CMPT tile:",i[n].magic);continue}r=new cn(this.s,this.et,this.i,this.ot)}o.push(r.load(t,e,i[n].offset,i[n].byteLength,s).then(t=>t))}return Promise.all(o).then(t=>({magic:"cmpt",tiles:t}))}pt(t,e,n,r){const s=new DataView(t,n,r),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported cmpt version: "+i+", url:"+e;return console.warn(t),{error:t}}if(16===s.byteLength)return[];const o=[],a=s.getUint32(12,!0);let c=16;for(let e=0;e<a;e++){const e=xe(s,c),r=s.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+n,byteLength:r}),c+=r}return o}}function un(t,e){if(t.scenes&&t.scenes.length)for(let n=0,r=t.scenes.length;n<r;n++){const r=t.scenes[n].nodes;for(let n=0,s=r.length;n<s;n++){const s=[];bn(r[n],s,t,e)}}}const fn=[],hn=[],ln=[],dn=[0,0,0],yn=S([]),mn=[1,1,1];function bn(t,e,n,r){const c=e.slice(0);if(t.matrix)c.push(t.matrix);else if(t.rotation||t.translation||t.scale){const e=i(fn,t.translation||dn),n=a(hn,t.rotation||yn),r=o(ln,t.scale||mn);s(r,n,r);const u=s([],e,r);c.push(u)}if(t.children&&t.children.length)for(let e=0,s=t.children.length;e<s;e++)bn(t.children[e],c,n,r);if(void 0!==t.mesh){const e=t.mesh,s=n.meshes[e];if(s){const t=c.slice(0),i=s.primitives;for(let s=0,o=i.length;s<o;s++){const o=i[s];o&&(o.matrices=t,r(o,e,s,n))}}}}function pn(t,e){let{byteOffset:n,byteStride:r,count:s}=t;const{componentType:i,itemSize:o}=t,a=t.array.buffer,c=i?dt.getTypedArrayCtor(i):t.array.constructor;if(n=void 0===n?t.array.byteOffset:n,r=r||0,s=s||t.array.length/o,(!r||r===o*c.BYTES_PER_ELEMENT)&&n%c.BYTES_PER_ELEMENT==0){const t=new c(a,n,s*o);for(let r=0;r<s*o;r+=o){e(new c(t.buffer,n+r*c.BYTES_PER_ELEMENT,o),r/o)}return}const u=new Uint8Array(o*c.BYTES_PER_ELEMENT);r||(r=o*c.BYTES_PER_ELEMENT);for(let t=0;t<s;t++){const s=new Uint8Array(a,r*t+n,o*c.BYTES_PER_ELEMENT);u.set(s);e(new c(u.buffer),t),s.set(u)}}var wn=An("DXT1"),gn=An("DXT3"),vn=An("DXT5"),Mn=An("DX10"),Tn=function(t){var e,n,r=new Int32Array(t,0,31);if(542327876!==r[0])throw new Error("Invalid magic number in DDS header");if(4&!r[20])throw new Error("Unsupported format, must contain a FourCC code");var s=r[21];switch(s){case wn:e=8,n="dxt1";break;case gn:e=16,n="dxt3";break;case vn:e=16,n="dxt5";break;case 116:n="rgba32f";break;case Mn:var i=new Uint32Array(t.slice(128,148));n=i[0];var o=i[1];if(i[2],i[3],i[4],3!==o||2!==n)throw new Error("Unsupported DX10 texture format "+n);n="rgba32f";break;default:throw new Error("Unsupported FourCC code: "+(a=s,String.fromCharCode(255&a,a>>8&255,a>>16&255,a>>24&255)))}var a;var c=r[2],u=1;131072&c&&(u=Math.max(1,r[7]));var f=!1;512&r[28]&&(f=!0);var h,l=r[4],d=r[3],y=r[1]+4,m=l,b=d,p=[];s===Mn&&(y+=20);if(f)for(var w=0;w<6;w++){if("rgba32f"!==n)throw new Error("Only RGBA32f cubemaps are supported");l=m,d=b;for(var g=Math.log(l)/Math.log(2)+1,v=0;v<g;v++)h=l*d*16,p.push({offset:y,length:h,shape:[l,d]}),v<u&&(y+=h),l=Math.floor(l/2),d=Math.floor(d/2)}else for(v=0;v<u;v++)h=Math.max(4,l)/4*Math.max(4,d)/4*e,p.push({offset:y,length:h,shape:[l,d]}),y+=h,l=Math.floor(l/2),d=Math.floor(d/2);return{shape:[m,b],images:p,format:n,flags:c,cubemap:f}};function An(t){return t.charCodeAt(0)+(t.charCodeAt(1)<<8)+(t.charCodeAt(2)<<16)+(t.charCodeAt(3)<<24)}var _n=Math.abs,On=Math.sin,xn=Math.cos,Sn=Math.tan,In=Math.atan,kn=Math.atan2,En=Math.sqrt,Cn=Math.log,Un=Math.hypot,Fn=Math.sinh,Nn=Math.cosh;function Pn(t){var e,n,r,s,i,o,a=[],c=[],u=[],f=[];function h(t,e){for(var n,r=2*xn(2*e),s=t.length-1,i=t[s],o=0;--s>=0;)n=r*i-o+t[s],o=i,i=n;return e+n*On(2*e)}function l(t,e,n){for(var r,s,i=On(e),o=xn(e),a=Fn(n),c=Nn(n),u=2*o*c,f=-2*i*a,h=t.length-1,l=t[h],d=0,y=0,m=0;--h>=0;)r=y,s=d,l=u*(y=l)-r-f*(d=m)+t[h],m=f*y-s+u*d;return[(u=i*c)*l-(f=o*a)*m,u*m+f*l]}t.es,i=s=(r=t.es/(1+En(1-t.es)))/(2-r),a[0]=s*(2+s*(-2/3+s*(s*(116/45+s*(26/45+s*(-2854/675)))-2))),c[0]=s*(s*(2/3+s*(4/3+s*(-82/45+s*(32/45+s*(4642/4725)))))-2),i*=s,a[1]=i*(7/3+s*(s*(-227/45+s*(2704/315+s*(2323/945)))-1.6)),c[1]=i*(5/3+s*(-16/15+s*(-13/9+s*(904/315+s*(-1522/945))))),i*=s,a[2]=i*(56/15+s*(-136/35+s*(-1262/105+s*(73814/2835)))),c[2]=i*(-26/15+s*(34/21+s*(1.6+s*(-12686/2835)))),i*=s,a[3]=i*(4279/630+s*(-332/35+s*(-399572/14175))),c[3]=i*(1237/630+s*(s*(-24832/14175)-2.4)),i*=s,a[4]=i*(4174/315+s*(-144838/6237)),c[4]=i*(-734/315+s*(109598/31185)),i*=s,a[5]=i*(601676/22275),c[5]=i*(444337/155925),i=s*s,e=t.k0/(1+s)*(1+i*(1/4+i*(1/64+i/256))),u[0]=s*(s*(2/3+s*(-37/96+s*(1/360+s*(81/512+s*(-96199/604800)))))-.5),f[0]=s*(.5+s*(-2/3+s*(5/16+s*(41/180+s*(-127/288+s*(7891/37800)))))),u[1]=i*(-1/48+s*(-1/15+s*(437/1440+s*(-46/105+s*(1118711/3870720))))),f[1]=i*(13/48+s*(s*(557/1440+s*(281/630+s*(-1983433/1935360)))-.6)),i*=s,u[2]=i*(-17/480+s*(37/840+s*(209/4480+s*(-5569/90720)))),f[2]=i*(61/240+s*(-103/140+s*(15061/26880+s*(167603/181440)))),i*=s,u[3]=i*(-4397/161280+s*(11/504+s*(830251/7257600))),f[3]=i*(49561/161280+s*(-179/168+s*(6601661/7257600))),i*=s,u[4]=i*(-4583/161280+s*(108847/3991680)),f[4]=i*(34729/80640+s*(-3418889/1995840)),i*=s,u[5]=i*(-20648693/638668800),f[5]=.6650675310896665*i,o=h(c,t.phi0),n=-e*(o+function(t,e){var n,r=2*xn(e),s=t.length-1,i=t[s],o=0;for(;--s>=0;)n=r*i-o+t[s],o=i,i=n;return On(e)*n}(f,2*o)),t.fwd=function(t,r){var s,i,o,a,u,d=t.phi,y=t.lam;d=h(c,d),s=On(d),i=xn(d),a=On(y),o=xn(y),d=kn(s,o*i),y=kn(a*i,Un(s,i*o)),y=function(t){var e=_n(t);return e=function(t){var e=1+t,n=e-1;return 0===n?t:t*Cn(e)/n}(e*(1+e/(Un(1,e)+1))),t<0?-e:e}(Sn(y)),u=l(f,2*d,2*y),d+=u[0],y+=u[1],_n(y)<=2.623395162778?(r.y=e*d+n,r.x=e*y):r.x=r.y=1/0},t.inv=function(t,r){var s,i,o,c,f,d=t.y,y=t.x;d=(d-n)/e,_n(y/=e)<=2.623395162778?(f=l(u,2*d,2*y),d+=f[0],y+=f[1],y=In(Fn(y)),s=On(d),i=xn(d),c=On(y),o=xn(y),y=kn(c,o*i),d=kn(s*o,Un(c,o*i)),r.phi=h(a,d),r.lam=y):r.phi=r.lam=1/0}}const Bn=Math.PI/180,Dn=6378137*Math.PI/180,Rn={};function Ln(t,e,n,r){if("EPSG:3857"===n)return function(t,e){const n=85.0511287798,r=e[0],s=Math.max(Math.min(n,e[1]),-n);let i;i=0===s?0:Math.log(Math.tan((90+s)*Bn/2))/Bn;return t[0]=r*Dn,t[1]=i*Dn,t}(t,e);if(!n||"EPSG:9807"!==n.code&&"Traverse_Mercator"!==n.code){if("EPSG:4326"===n||"EPSG:4490"===n||"identity"===n)return zn(t,e);if("baidu"===n)return zn(t,e);throw new Error("unsupported projection:"+n)}{if(!(!r||4326===r.wkid))return function(t,e){return t[0]=e[0],t[1]=e[1],t}(t,e);const s=JSON.stringify(n);let i=Rn[s];return i||(i=Rn[s]=function(t){const e={a:6378137,es:.0066943799901413165,x0:fe(t.falseEasting)?5e5:t.falseEasting,y0:fe(t.falseNorthing)?0:t.falseNorthing,k0:t.scaleFactor||.9996,lam0:(t.centralMeridian||0)*jn,phi0:(t.latitudeOfOrigin||0)*jn,originLam0:t.startLongtitude||0,originPhi0:t.startLatitude||0};Pn(e);const n={lam:0,phi:0},r={};let s=0,i=0;(e.originLam0||e.originPhi0)&&(n.lam=e.originLam0*jn-e.lam0,n.phi=e.originPhi0*jn,e.fwd(n,r),s=e.a*r.x+e.x0,i=e.a*r.y+e.y0);return{project:function(t,o){n.lam=t[0]*jn-e.lam0,n.phi=t[1]*jn,e.fwd(n,r);const a=e.a*r.x+e.x0-s,c=e.a*r.y+e.y0-i;return o[0]=a,o[1]=c,o}}}(n)),i.project(e,t)}}function zn(t,e){return t[0]=e[0],t[1]=e[1],t}const jn=.017453292519943295;const Vn=r([]),qn=Ze().draco,Gn=Ze().ktx2,$n={"pbrMetallicRoughness":{"baseColorFactor":[.5,.5,.5,1],"metallicFactor":0,"roughnessFactor":.5}},Xn={"position":{name:"POSITION",accessor:{"componentType":5126,"type":"VEC3"}},"normal":{name:"NORMAL",accessor:{"componentType":5126,"type":"VEC3"}},"uv0":{name:"TEXCOORD_0",accessor:{"componentType":5126,"type":"VEC2"}},"color":{name:"COLOR_0",accessor:{"componentType":5121,"type":"VEC4"}},"uv-region":{name:"uvRegion",accessor:{"componentType":5123,"type":"VEC4"}},"feature-index":{name:"_BATCHID",accessor:{"componentType":5125,"type":"SCALAR"}},"faceRange":{name:"faceRange",accessor:{"componentType":5125,"type":"VEC2"}}};function Hn(t,e,n,s,i,o){const a=[],c=[],u=[];for(let e=0;e<t.meshes.length;e++){const{geometry:n,material:r}=t.meshes[e],s=J.getArrayBuffer(n.url,o);s.xhr.url=n.url,u.push(s.xhr);const i=s.then(t=>({buffer:t}));a.push(i);const f=[];if(tr(r,f),f.length){const t=f.map(t=>{const e=J.getArrayBuffer(t.url,o);return e.xhr.url=t.url,u.push(e.xhr),e.then(e=>e&&e.status?null:{buffer:e,mimeType:t.mimeType,format:t.format})});a.push(...t)}c[e]=f.length}const f=Promise.all(a).then(o=>{for(let t=0;t<o.length;t++)if(!o[t]||!o[t].buffer)return Promise.resolve(null);const a=[];let u=0;for(let t=0;t<c.length;t++){const e=c[t];a.push({geoBuffer:{data:o[u].buffer.data},textureBuffers:o.slice(u+1,e+u+1).map(t=>({data:t.buffer.data,mimeType:t.mimeType,format:t.format}))}),u+=1+e}return function(t,e,n,s,i,o){const a={asset:{generator:"i3s",version:"2.0"},extensions:{},scene:0,scenes:[{nodes:[]}],nodes:{},meshes:{},materials:[],skins:[],animations:null,textures:[],transferables:[]},c=[];for(let u=0;u<t.meshes.length;u++){let{material:f}=t.meshes[u];const{geometry:h}=t.meshes[u];let l;const d=e[u].geoBuffer.data;if(!d)continue;const y=or(d);l=y?Kn(a,u,h,d,t.transform,t.center,i,o):Qn(a,u,h,d,t.transform,t.center,i,o),c.push(l),a.nodes[u]={mesh:u,nodeIndex:u,matrix:r([])},a.scenes[0].nodes[u]=a.nodes[u],f||(f=$n);const m=Zn(u,a,f,e[u].textureBuffers,n,s);c.push(m)}return Promise.all(c).then(()=>({gltf:a,featureTable:{BATCH_LENGTH:0},transferables:a.transferables}))}(t,a,e,i,n,s)});return f.xhr=u,f}const Jn={"magFilter":9728,"minFilter":9728,"wrapR":33071,"wrapS":33071,"wrapT":33071};function Kn(t,e,n,r,s,i,o,a){const c=n.info.compressedAttributes.attributes.reduce((t,e,n)=>{const r=Xn[e];if(!r)return t;return t[r.name||e]=n,t},{});return qn(r,{attributes:c,metadatas:{"POSITION":[{name:"i3s-scale_x",type:"double"},{name:"i3s-scale_y",type:"double"}]},useUniqueIDs:!1,skipAttributeTransform:!1}).then(n=>Wn(n,t,e,s,i,o,a))}const Yn={position:function(t,e,n){const r=3*t.vertexCount,s=new Float32Array(e,n,r);return t.position={array:s,componentType:5126,itemSize:3,count:r/3,meta:{"i3s-scale_x":1,"i3s-scale_y":1},type:"VEC3"},n+=4*r},normal:function(t,e,n){const r=3*t.vertexCount,s=new Float32Array(e,n,r);return t.normal={array:s,componentType:5126,itemSize:3,count:r/3,type:"VEC3"},n+=4*r},uv0:function(t,e,n){const r=2*t.vertexCount,s=new Float32Array(e,n,r);return t.uv0={array:s,componentType:5126,itemSize:2,count:r/2,type:"VEC2"},n+=4*r},color:function(t,e,n){const r=4*t.vertexCount,s=new Uint8Array(e,n,r);return t.color={array:s,componentType:5121,itemSize:4,count:r/4,type:"VEC4"},n+=r},featureId:function(t,e,n){return n+=8*t.featureCount},id:function(t,e,n){return n+=8*t.featureCount},faceRange:function(t,e,n){const r=2*t.featureCount,s=new Uint32Array(e,n,r);return t.faceRange={array:s,componentType:5125,itemSize:2,count:r/2,type:"VEC2"},n+=4*r},uvRegion:function(t,e,n){const r=4*t.vertexCount,s=new Uint16Array(e,n,r);return t["uv-region"]={array:s,componentType:5123,itemSize:4,count:r/4,type:"VEC4"},n+=2*r},region:function(t,e,n){const r=4*t.vertexCount,s=new Uint16Array(e,n,r);return t["uv-region"]={array:s,componentType:5123,itemSize:4,count:r/4,type:"VEC4"},n+=2*r}};function Qn(t,e,n,r,s,i,o,a){const c={vertexCount:0},u=new DataView(r);try{let t=0;c.vertexCount=u.getUint32(t,1),t+=4,c.featureCount=u.getUint32(t,1),t+=4;const e=n.info.ordering?null:n.info;if(e){const n=[];for(const t in e)"offset"!==t&&""!==t&&n.push(t);for(let e=0;e<n.length;e++)Yn[n[e]]?t=Yn[n[e]](c,r,t):console.error("Unknown decoder for",n[e])}else{const e=n.info;let s=e.ordering,i=e.featureAttributeOrder;const o=null;o&&o.geometryData&&o.geometryData[0]&&o.geometryData[0].params;for(let e=0;e<s.length;e++){const n=Yn[s[e]];n||console.log(s[e]),t=n(c,r,t)}for(let e=0;e<i.length;e++){const n=Yn[i[e]];n||console.log(i[e]),t=n(c,r,t)}}}catch(t){}c.scale_x=1,c.scale_y=1;const f={};for(const t in c){const e=Xn[t]&&Xn[t].name;e&&(f[e]=c[t])}if(c.faceRange){const t=c.faceRange.array,e=t.length/2,n=(h=e)<=255?Uint8Array:h<=65535?Uint16Array:Uint32Array,r=new n(f.POSITION.array.length/3);for(let e=0;e<t.length-1;e+=2){const n=e/2,s=t[e],i=t[e+1];for(let t=s;t<=i;t++)r[3*t]=n,r[3*t+1]=n,r[3*t+2]=n}f._BATCHID={componentType:Je(n),array:r,itemSize:1,count:r.length,type:"SCALAR"}}var h;return Wn({attributes:f},t,e,s,i,o,a)}function Wn(t,e,n,r,s,i,o){const a={attributes:t.attributes,material:n,indices:t.indices,mode:4};!function(t){const e=t.array,n=t.meta&&t.meta["i3s-scale_x"],r=t.meta&&t.meta["i3s-scale_y"];if(n&&r&&(1!==n||1!==r))for(let t=0;t<e.length;t+=3)e[t]*=n.value,e[t+1]*=r.value}(t.attributes.POSITION);const u=function(t,e,n,r,s){let i,o=[0,0,0,1];const a=[0,0],u=Ln([],n,r,s);u[2]=n[2];const f=e&&c(Vn,e);return pn(t,t=>(o[0]=t[0],o[1]=t[1],o[2]=t[2],f||(o=v(o,o,e)),n&&y(o,o,n),Ln(a,o,r,s),i=o[2],t[0]=a[0]-u[0],t[1]=a[1]-u[1],t[2]=i-u[2],t)),u}(t.attributes.POSITION,r,s,i,o);e.meshes[n]={primitives:[a],index:n},e.extensions.MAPTALKS_RTC={projCenter:u},e.extensions.CESIUM_RTC={rtcCoord:s};for(const n in t.attributes)ir(e.transferables,t.attributes[n].array.buffer);return t.indices&&ir(e.transferables,t.indices.array.buffer),a}function Zn(t,e,n,r,s,i){const o=r.map(t=>function(t,e,n,r,s){if("dds"===e){const e=Tn(t),r=e.images.map(e=>new Uint8Array(t,e.offset,e.length)),s="dxt1"===e.format?33777:33779;return Promise.resolve({image:{mipmap:r,width:e.shape[0],height:e.shape[1],mimeType:n},sampler:Jn,format:s})}if("png"===e||"jpg"===e)return function(t,e){er||(er=new OffscreenCanvas(2,2),nr=er.getContext("2d",{willReadFrequently:!0}));const n=new Blob([new Uint8Array(t)]);return createImageBitmap(n).then(t=>{let{width:n,height:r}=t;rr(n)||(n=sr(n)),rr(r)||(r=sr(r));const s=e;s&&(n=Math.min(s,n),r=Math.min(s,r)),er.width=n,er.height=r,nr.drawImage(t,0,0,n,r),t.close();const i=nr.getImageData(0,0,n,r);return{width:n,height:r,array:new Uint8Array(i.data)}}).catch(()=>({width:2,height:2,array:new Uint8Array(4)}))}(t,s).then(t=>{t.mimeType=n;return{image:t,sampler:Jn,format:6408}});if("ktx2"===e)return Gn(t,r).then(t=>(t.mimeType=n,{image:t,sampler:Jn,format:t.format}));return null}(t.data,t.format,t.mimeType,s,i).then(t=>{if(t.image)if(t.image.array)ir(e.transferables,t.image.array.buffer);else if(t.image.mipmap)for(let n=0;n<t.image.mipmap.length;n++)ir(e.transferables,t.image.mipmap[n].buffer);return t}));return Promise.all(o).then(r=>{!function t(e,n,r,s){const i=JSON.parse(JSON.stringify(r)),o=n.textures;s.ptr||(s.ptr=0);for(const e in r)r[e]&&r[e].url?(o.push(s[s.ptr++]),i[e]={index:o.length-1},void 0!==r[e].factor&&(i[e].scale=r[e].factor)):he(r[e])&&(i[e]=t(-1,n,r[e],s));e>=0&&(n.materials[e]=i);return i}(t,e,n,r)})}function tr(t,e){for(const n in t)t[n]&&t[n].url?e.push({url:t[n].url,mimeType:t[n].mimeType,format:t[n].format}):he(t[n])&&tr(t[n],e)}let er,nr;function rr(t){return 0==(t&t-1)&&0!==t}function sr(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}function ir(t,e){e&&(t.indexOf(e)>=0||t.push(e))}function or(t){const e=new Uint8Array(t,0,5);return e[0]==="D".charCodeAt()&&e[1]==="R".charCodeAt()&&e[2]==="A".charCodeAt()&&e[3]==="C".charCodeAt()&&e[4]==="O".charCodeAt()}const ar=[];const cr=[],ur=[],fr=[],hr=[],lr=[],dr=[],yr=[];function mr(t,e,n,r,s,i){d(hr,t[3*e],t[3*e+1],t[3*e+2]),d(lr,t[3*n],t[3*n+1],t[3*n+2]),d(dr,t[3*r],t[3*r+1],t[3*r+2]);const o=M(cr,dr,lr),a=M(ur,hr,lr),c=g(fr,o,a);p(yr,c),s[3*e]=s[3*e]||0,s[3*n]=s[3*n]||0,s[3*r]=s[3*r]||0,s[3*e+1]=s[3*e+1]||0,s[3*n+1]=s[3*n+1]||0,s[3*r+1]=s[3*r+1]||0,s[3*e+2]=s[3*e+2]||0,s[3*n+2]=s[3*n+2]||0,s[3*r+2]=s[3*r+2]||0,s[3*e]+=yr[0],s[3*n]+=yr[0],s[3*r]+=yr[0],s[3*e+1]+=yr[1],s[3*n+1]+=yr[1],s[3*r+1]+=yr[1],s[3*e+2]+=yr[2],s[3*n+2]+=yr[2],s[3*r+2]+=yr[2],i[e]+=1,i[n]+=1,i[r]+=1}const br=[1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],pr=[0,0,1,0,0,1,0,0,-1,0,0,0,0,0,0,1],wr=2*Math.PI*6378137/360,gr="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;let vr,Mr=!1;if("undefined"!=typeof OffscreenCanvas){try{vr=new OffscreenCanvas(2,2).getContext("2d",{willReadFrequently:!0})}catch(t){}vr&&"undefined"!=typeof createImageBitmap&&(Mr=!0)}const Tr=r([]),Ar=[0,0,0],_r=[],Or=[],xr=[],Sr=[],Ir={"POSITION":1,"TEXCOORD_0":1,"TEXCOORD_1":1,"NORMAL":1,"TANGENT":1},kr={"TEXCOORD_0":1e-4,"TEXCOORD_1":1e-4};class Er{constructor(t,e,n,r){this.id=t,this.options=e,this.wt=this.requestImage.bind(this),this.gt=n,this.vt={},r(null,{},[])}Mt(t){this.Tt||(this.i=t,this.At=new on,this.Tt=new tn(this.wt,dt,t),this._t=new en(this.wt,dt,t))}requestImage(t,e){Mr?fetch(t).then(t=>t.arrayBuffer()).then(t=>{const e=new self.Blob([new Uint8Array(t)]);return createImageBitmap(e)}).then(t=>{(void 0).width=t.width,(void 0).height=t.height,vr.drawImage(t,0,0);const n=vr.getImageData(0,0,(void 0).width,(void 0).height);t.close(),e(null,{width:t.width,height:t.height,data:new Uint8Array(n.data)})}):this.gt("requestImage",{url:t},null,e)}loadTile(t,e){this.Mt(t.supportedFormats);const n=t.service,r=t.url,s=t.arraybuffer,i=n.fetchOptions||{};if(i.referrer=t.referrer,i.referrerPolicy=i.referrerPolicy||"origin",function(t){return t.indexOf("i3s:")>=0}(r)){const s=t.i3sInfo,o=n.maxTextureSize||1024,a=Hn(s,t.supportedFormats,this.options.projection,t.projection,o,i);return a.then(t=>{if(delete this.vt[r],!t)return void e({status:404,url:r,i3sInfo:s});if(!Object.keys(t.gltf.meshes).length)return void e({status:404,url:r,i3sInfo:s});t.gltf.url=r;const{transferables:n}=t;t.magic="b3dm",this.Ot(t.gltf),e(null,t,n)}),void(this.vt[r]=a.xhr)}if(s){delete this.vt[r];const n=xe(new DataView(s),0);if("{"===n[0]||" "===n[0]||"<"===n[0]){const n=function(t,e,n){if(gr){const r=new Uint8Array(t,e,n);return gr.decode(r)}return me(new Uint8Array(t,e,n))}(s,0,s.byteLength),i=JSON.parse(n);i.accessors?this.xt(i,r,t,"gltf",e):this.St(t.rootIdx,i,s,r,e)}else this.xt(s,r,t,n,e)}else{let s=n.urlParams;s&&(s=(r.indexOf("?")>0?"&":"?")+s);const o=r.replace(/\\+/g,"%2B");let a=J.getArrayBuffer(o+(s||""),i);const c=a.xhr;a=a.then(n=>{delete this.vt[r],n&&n.status?e(n):(t.arraybuffer=n&&n.data,this.loadTile(t,e))}).catch(t=>{delete this.vt[r],e(t)}),this.vt[r]=c}}xt(t,e,n,r,s){r=r&&r.toLowerCase();const i=n.service;if("b3dm"===r){this.Tt.load(e,t,0,0,{maxTextureSize:i.maxTextureSize||1024}).then(t=>{if(t.error)return void s(t);const{content:e,transferables:r}=this.It(t,n);this.Ot(e.gltf),s(null,e,r)}).catch(t=>{s(t)})}else if("pnts"===r){const r=n.transform||Tr;this.At.load(e,t).then(t=>{const{content:e,transferables:i}=this.kt(t,r,n.rootIdx);this.Et(e),s(null,e,i)})}else if("i3dm"===r){const r=n.transform||Tr;this._t.load(e,t,0,0,{maxTextureSize:i.maxTextureSize||1024}).then(t=>{const{content:e,transferables:i}=this.Ct(t,r,n.rootIdx);this.Ot(e.gltf),s(null,e,i)})}else if("cmpt"===r){new cn(this.wt,dt,this.i,i.maxTextureSize||1024).load(e,t,0,0,{maxTextureSize:i.maxTextureSize||1024}).then(t=>{const{content:e,transferables:r}=this.Ut(t,n);this.Ft(e),s(null,e,r)}).catch(t=>{s(t)})}else if("gltf"===r){this.nt||(this.nt=Ze());const r=e.substring(0,e.lastIndexOf("/")),o=t instanceof ArrayBuffer&&{buffer:t,byteOffset:0,byteLength:t.byteLength}||t,a=new dt(r,o,{transferable:!0,requestImage:this.wt,decoders:this.nt,supportedFormats:this.i,maxTextureSize:i.maxTextureSize||1024});a.load({skipAttributeTransform:!1}).then(t=>{t.url=e,this.Nt(t,null,n),this.Ot(t),s(null,{magic:"gltf",gltf:t},a.transferables)})}else s(new Error("unsupported tile format: "+r))}Ft(t){t.content?t.content.forEach(t=>{this.Ft(t)}):this.Ot(t.gltf)}Pt(t,e){const n=e.materials[t.material];if(n&&n.extensions&&n.extensions.KHR_materials_unlit)return;if(t.attributes.TANGENT)return;if(t.attributes.TEXCOORD_0&&!t.attributes.NORMAL){const e=t.attributes.POSITION.array,n=function(t,e,n){const r=n||[];r.setLength&&r.setLength(t.length);const s=ar;s.length<t.length/3&&(s.length=t.length/3),s.fill(0,0,t.length/3);const i=void 0===e.length?e:e.length;for(let n=0;n<i/3;n++)void 0===e.length?mr(t,3*n,3*n+1,3*n+2,r,s):mr(t,e[3*n],e[3*n+1],e[3*n+2],r,s);for(let t=0;t<r.length;t+=3){const e=s[t/3];0!==e?(r[t]/=e,r[t+1]/=e,r[t+2]/=e):(r[t]=0,r[t+1]=0,r[t+2]=0)}return r}(e,t.indices.array,new Float32Array(e.length));t.attributes.NORMAL={array:n,byteLength:n.byteLength,byteOffset:0,byteStride:0,componentType:5126,count:n.length/3,itemSize:3,name:"NORMAL",type:"VEC3"}}}Ot(t){if(!t||!t.meshes||t.extensionsUsed&&t.extensionsUsed.indexOf("KHR_techniques_webgl")>-1)return;const e=t.meshes;for(const n in e){e[n].primitives.forEach(e=>{this.Pt(e,t),e.compressed_int16_params={};const n=e.attributes;for(const t in n)if(Ir[t]&&n[t].array&&n[t].array instanceof Float32Array){const r=this.options.projection;let s=1;"EPSG:4326"!==r&&"EPSG:4490"!==r||"POSITION"!==t||(s=wr,e.compressed_int16_params.compressed_ratio=s);const i=Br(n[t].array,s,n[t].min,n[t].max,t);if(!i)continue;const{array:o,range:a}=i;n[t].array=o,e.compressed_int16_params[t]=a}})}}Et(t){if(!t||!t.pnts)return;const e=t.pnts;t.compressed_int16_params={};for(const n in e)if(Ir[n]&&e[n].array&&e[n].array instanceof Float32Array){const r=this.options.projection;let s=1;"EPSG:4326"!==r&&"EPSG:4490"!==r||"POSITION"!==n||(s=wr,t.compressed_int16_params.compressed_ratio=s);const{array:i,range:o}=Br(e[n].array,s,e[n].min,e[n].max,n);e[n].array=i,t.compressed_int16_params[n]=o}}Bt(t){const e=[];for(let n=0;n<t.length;n++){const r=t[n];if(!r.childTile)continue;const s={boundingVolume:{sphere:[r.boundingSphere.center.x,r.boundingSphere.center.y,r.boundingSphere.center.z,r.boundingSphere.radius]},content:{uri:r.childTile},geometricError:r.boundingSphere.radius/r.rangeList*16,refine:"REPLACE"};e.push(s)}return e}St(t,e,n,r,s){return e.capabilities,void s(null,e)}Ut(t,e){const{tiles:n}=t,r={magic:"cmpt",content:[]},s=[];for(let t=0;t<n.length;t++){const{magic:i}=n[t];if("b3dm"===i){const{content:i,transferables:o}=this.It(n[t],e);Nr(s,o),r.content.push(i)}else if("i3dm"===i){const{transform:i,rootIdx:o}=e,{content:a,transferables:c}=this.Ct(n[t],i,o);Nr(s,c),r.content.push(a)}else if("pnts"===i){const{transform:i,rootIdx:o}=e,{content:a,transferables:c}=this.kt(n[t],i,o);Nr(s,c),r.content.push(a)}else if("cmpt"===i){const{content:i,transferables:o}=this.Ut(n[t],e);Nr(s,o),r.content.push(i)}}return{content:r,transferables:s}}It(t,e){const{gltf:n,transferables:r,featureTable:s}=t;return this.Nt(n,s,e),delete t.transferables,{content:t,transferables:r}}Nt(t,e,n){const r=function(t){if(!t||!t.meshes)return!1;let e=1;const n=[];for(const r in t.meshes){const s=t.meshes[r],{primitives:i}=s;if(i)for(let t=0;t<i.length;t++){const r=i[t].attributes&&i[t].attributes.POSITION;if(!r||!r.array)continue;r.array.buffer.visited||(r.array.buffer.visited=e++);const s=e-1+"-"+(r.byteOffset||0);if(n.indexOf(s)>=0)return!0;n.push(s)}}return!1}(t);this.Dt(t),t.asset||(t.asset={}),r?(t.asset.sharePosition=!0,this.Rt(t,e,n.upAxis,n.transform)):this.Lt(t,e,n.upAxis,n.transform)}Ct(t,e,r){const{featureTable:s}=t,i=t.i3dm,o=s&&s.RTC_CENTER||[0,0,0];if(s.EAST_NORTH_UP&&!i.NORMAL_UP&&!i.NORMAL_UP_OCT32P){const e=new Float32Array(3*i.POSITION.array.length),r=[],s=[],a=[];pn(i.POSITION,(t,i)=>{y(a,t,o),Xe(a,null,r),n(s,r);!function(t,e){t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8]}(e.subarray(9*i,9*(i+1)),s)}),i.INSTANCE_ROTATION={byteStride:0,byteOffset:0,itemSize:9,componentType:5126,array:e},t.transferables.push(e.buffer)}const a={xmin:1/0,xmax:-1/0,ymin:1/0,ymax:-1/0,hmin:1/0,hmax:-1/0};Ur(i.POSITION.array,3,o,Tr,a);const c=Fr(a),u=l([],c),f=[1/0,1/0,1/0],h=[-1/0,-1/0,-1/0];pn(i.POSITION,t=>{t[0]=t[0]+o[0]-u[0],t[1]=t[1]+o[1]-u[1],t[2]=t[2]+o[2]-u[2],t[0]<f[0]&&(f[0]=t[0]),t[1]<f[1]&&(f[1]=t[1]),t[2]<f[2]&&(f[2]=t[2]),t[0]>h[0]&&(h[0]=t[0]),t[1]>h[1]&&(h[1]=t[1]),t[2]>h[2]&&(h[2]=t[2])}),i.POSITION.min=f,i.POSITION.max=h,e&&v(c,c,e);const d=this.zt(c);t.rtcCenter=u,t.rtcCoord=d,t.rootIdx=r;const m=t.transferables;return delete t.transferables,{content:t,transferables:m}}kt(t,e,n){const{featureTable:r}=t,s=t.pnts,i=r&&r.RTC_CENTER||[0,0,0],o=this.options.projection,a=e&&c(Tr,e),u={xmin:1/0,xmax:-1/0,ymin:1/0,ymax:-1/0,hmin:1/0,hmax:-1/0};Ur(s.POSITION.array,3,i,e,u);const f=Fr(u),h=this.jt(f),y=l([],f),m=[1/0,1/0,1/0],b=[-1/0,-1/0,-1/0];let p=[0,0,0,1];const w=[0,0,0],g=[0,0];pn(s.POSITION,t=>(p[0]=t[0]+i[0],p[1]=t[1]+i[1],p[2]=t[2]+i[2],e&&!a&&(p=v(p,p,e)),0===A(p)?d(w,0,0,-6378137):Me(w,p),Ln(g,w,o),t[0]=g[0]-h[0],t[1]=g[1]-h[1],t[2]=w[2]-h[2],t[0]<m[0]&&(m[0]=t[0]),t[1]<m[1]&&(m[1]=t[1]),t[2]<m[2]&&(m[2]=t[2]),t[0]>b[0]&&(b[0]=t[0]),t[1]>b[1]&&(b[1]=t[1]),t[2]>b[2]&&(b[2]=t[2]),t)),s.POSITION.min=m,s.POSITION.max=b,e&&v(f,f,e);const M=this.zt(f);t.rtcCenter=y,t.projCenter=h,t.rtcCoord=M,t.rootIdx=n;const T=t.transferables;return delete t.transferables,{content:t,transferables:T}}Dt(t){if(!Array.isArray(t.textures))return;const e=t.textures;for(let t=0;t<e.length;t++){const n=e[t].image&&e[t].image.array;if(n&&n.length){const r=n[0],s=n[1],i=n[2],o=n[3];let a=!0;for(let t=4;t<n.length;t+=4)if(n[t]!==r||n[t+1]!==s||n[t+2]!==i||n[t+3]!==o){a=!1;break}a&&(e[t].image.color=[r/255,s/255,i/255,o/255],delete e[t].image.array)}}}abortTileLoading(t,e){const n=this.vt[t.url];if(Array.isArray(n))for(let t=0;t<n.length;t++)n[t].abort();else n&&n.abort&&n.abort();delete this.vt[t.url],e(null)}Vt(t,e,n,i){const o=e&&e.RTC_CENTER||t.extensions&&t.extensions.CESIUM_RTC&&t.extensions.CESIUM_RTC.center;let a=br;"X"===(n=n&&n.toUpperCase())?a=pr:"Z"===n&&(a=Tr),t.extensions=t.extensions||{},t.extensions.CESIUM_RTC||(t.extensions.CESIUM_RTC={}),o&&(t.extensions.CESIUM_RTC.center=o),t.extensions.MAPTALKS_RTC={};const c={xmin:1/0,xmax:-1/0,ymin:1/0,ymax:-1/0,hmin:1/0,hmax:-1/0};un(t,t=>{if(!(t.attributes&&t.attributes.POSITION))return;const e=r(_r);t.matrices&&Pr(e,t.matrices);const n=t.attributes.POSITION.array,u=t.attributes.POSITION.itemSize;s(e,a,e),i&&s(e,i,e),Ur(n,u,o||Ar,e,c,t.compressUniforms)});const u=Fr(c);return{rtcCenter:o,modelCenter:u,upAxisTransform:a}}Rt(t,e,n,i){const{modelCenter:o,upAxisTransform:a,rtcCenter:c}=this.Vt(t,e,n),u=l([],o);i&&v(o,o,i),t.extensions.CESIUM_RTC.rtcCoord=this.zt(o),c||(un(t,t=>{if(t.attributes&&t.attributes.POSITION){const e=t.attributes.POSITION;if(e.array.buffer.projected&&e.array.buffer.projected[e.byteOffset])return;const n=r(_r);t.matrices&&Pr(n,t.matrices),s(n,a,n);const i=function(t,e){var n=e[0],r=e[1],s=e[2],i=e[3],o=e[4],a=e[5],c=e[6],u=e[7],f=e[8],h=e[9],l=e[10],d=e[11],y=e[12],m=e[13],b=e[14],p=e[15],w=n*a-r*o,g=n*c-s*o,v=n*u-i*o,M=r*c-s*a,T=r*u-i*a,A=s*u-i*c,_=f*m-h*y,O=f*b-l*y,x=f*p-d*y,S=h*b-l*m,I=h*p-d*m,k=l*p-d*b,E=w*k-g*I+v*S+M*x-T*O+A*_;return E?(E=1/E,t[0]=(a*k-c*I+u*S)*E,t[1]=(s*I-r*k-i*S)*E,t[2]=(m*A-b*T+p*M)*E,t[3]=(l*T-h*A-d*M)*E,t[4]=(c*x-o*k-u*O)*E,t[5]=(n*k-s*x+i*O)*E,t[6]=(b*v-y*A-p*g)*E,t[7]=(f*A-l*v+d*g)*E,t[8]=(o*I-a*x+u*_)*E,t[9]=(r*x-n*I-i*_)*E,t[10]=(y*T-m*v+p*w)*E,t[11]=(h*v-f*T-d*w)*E,t[12]=(a*O-o*S-c*_)*E,t[13]=(n*S-r*O+s*_)*E,t[14]=(m*g-y*M-b*w)*E,t[15]=(f*M-h*g+l*w)*E,t):null}(Or,n),o=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];pn(e,t=>{v(t,t,n),t[0]=t[0]-u[0],t[1]=t[1]-u[1],t[2]=t[2]-u[2],v(t,t,i),t[0]<o[0]&&(o[0]=t[0]),t[1]<o[1]&&(o[1]=t[1]),t[2]<o[2]&&(o[2]=t[2]),t[0]>c[0]&&(c[0]=t[0]),t[1]>c[1]&&(c[1]=t[1]),t[2]>c[2]&&(c[2]=t[2])}),e.min=o,e.max=c,e.array.buffer.projected||(e.array.buffer.projected={}),e.array.buffer.projected[e.byteOffset]=1}}),t.extensions.CESIUM_RTC.center=u)}Lt(t,e,n,r){const{modelCenter:s,rtcCenter:i}=this.Vt(t,e,n,r),o=this.jt(s);t.extensions.MAPTALKS_RTC.projCenter=o,t.extensions.CESIUM_RTC.rtcCoord=this.zt(s),un(t,e=>{if(e.attributes&&e.attributes.POSITION){e.attributes.NORMAL&&this.qt(e.attributes.NORMAL,e.matrices,n),e.attributes.TANGENT&&this.qt(e.attributes.TANGENT,e.matrices,n);const{newPositions:s}=this.Gt(e.attributes.POSITION,e.matrices,i,t.extensions.MAPTALKS_RTC,n,r,e.compressUniforms),{componentType:o}=e.attributes.POSITION;5126!==o&&(e.attributes.POSITION.array=new Float32Array(s))}});for(const e in t.nodes){t.nodes[e].matrix=Tr}}jt(t){0===A(t)?d(xr,0,0,-6378137):Me(xr,t);const e=this.options.projection;Ln(Sr,xr,e);const n=xr[2],r=[];return r[0]=Sr[0],r[1]=Sr[1],r[2]=n,r}qt(t,e,r){let s;s="Y"===r?br:"X"===r?pr:Tr;const i=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}([],s);if(Pr(i,e),c(i,Tr))return;const o=n([],i),a=[];pn(t,t=>(function(t,e,n){var r=e[0],s=e[1],i=e[2];t[0]=r*n[0]+s*n[3]+i*n[6],t[1]=r*n[1]+s*n[4]+i*n[7],t[2]=r*n[2]+s*n[5]+i*n[8]}(a,t,o),p(a,a),l(t,a),a))}Gt(t,e,n,s,i,o,a){if(t.array.buffer.projected&&t.array.buffer.projected[t.byteOffset])return null;const u=r([]);Pr(u,e);const f=this.options.projection;i=i&&i.toUpperCase();const h=n;let l=null;"Y"===i?l=br:"X"===i&&(l=pr);let m=[0,0,0,1];const b=[0,0,0],p=[0,0],w=s.projCenter,g=o&&c(Tr,o),M=t.min=t.min||[],T=t.max=t.max||[];d(M,1/0,1/0,1/0),d(T,-1/0,-1/0,-1/0);const _=a||{},{decode_position_min:O,decode_position_normConstant:x}=_;let S=[0,0,0,0],I=1;O&&(S=O),x&&(I=x);const k=[];return pn(t,e=>{if(m[0]=e[0]*I+S[0],m[1]=e[1]*I+S[1],m[2]=e[2]*I+S[2],m=v(m,m,u),l&&(m=v(m,m,l)),h&&y(m,m,h),o&&!g&&(m=v(m,m,o)),0===A(m)?d(b,0,0,-6378137):Me(b,m),Ln(p,b,f),e instanceof Float32Array)e[0]=p[0]-w[0],e[1]=p[1]-w[1],e[2]=b[2]-w[2];else{const n=p[0]-w[0],r=p[1]-w[1],s=b[2]-w[2];5126!==t.componentType&&(k.push(n),k.push(r),k.push(s),k.push(e[3]))}return e[0]<M[0]&&(M[0]=e[0]),e[1]<M[1]&&(M[1]=e[1]),e[2]<M[2]&&(M[2]=e[2]),e[0]>T[0]&&(T[0]=e[0]),e[1]>T[1]&&(T[1]=e[1]),e[2]>T[2]&&(T[2]=e[2]),e}),t.array.buffer.projected||(t.array.buffer.projected={}),t.array.buffer.projected[t.byteOffset]=1,{projCenter:w,newPositions:k}}zt(t){return 0===A(t)?d([],0,0,-6378137):Me([],t)}onRemove(){}}const Cr=[];function Ur(t,e,n,r,s,i){const o=i||{},{decode_position_min:a,decode_position_normConstant:c}=o;let u=[0,0,0,0],f=1;a&&(u=a),c&&(f=c);for(let i=0,o=t.length;i<o;i+=e){const{xmin:o,ymin:a,xmax:c,ymax:h,hmin:l,hmax:m}=s;d(Cr,t[i]*f+u[0],t[i+1]*f+u[1],t[i+2]*f+u[2]),v(Cr,Cr,r);const b=y(Cr,n,Cr);b[0]<o&&(s.xmin=b[0]),b[0]>c&&(s.xmax=b[0]),b[1]<a&&(s.ymin=b[1]),b[1]>h&&(s.ymax=b[1]),e>2&&(b[2]<l&&(s.hmin=b[2]),b[2]>m&&(s.hmax=b[2]))}}function Fr(t){const{xmax:e,ymax:n,xmin:r,ymin:s,hmin:i,hmax:o}=t,a=[(r+e)/2,(s+n)/2,(i+o)/2];return e===-1/0&&(a[0]=0),n===-1/0&&(a[1]=0),o===-1/0&&(a[2]=0),isNaN(a[2])&&(a[2]=0),a}function Nr(t,e){for(let n=0;n<e.length;n++)t.indexOf(e[n])<0&&t.push(e[n])}function Pr(t,e){const n=t;for(let t=e.length-1;t>=0;t--)s(n,e[t],n);return n}function Br(t,e,n,r,s){if(e&&e>1)for(let n=0;n<t.length;n++)(n+1)%3!=0&&(t[n]*=e);let i,o;if(n&&r&&1===e)i=Math.min(...n),o=Math.max(...r);else{const{min:e,max:n}=function(t){let e=1/0,n=-1/0;for(let r=0;r<t.length;r++)t[r]>n&&(n=t[r]),t[r]<e&&(e=t[r]);return{min:e,max:n}}(t);i=e,o=n}return!function(t,e,n,r){for(let s=0;s<t.length;s++){const i=Dr(Rr(t[s],e,n),e,n);if(Math.abs(i-t[s])>kr[r])return!1}return!0}(t,i,o,s)&&kr[s]?null:function(t,e,n){const r=new Int16Array(t.length);for(let s=0;s<t.length;s++)r[s]=Rr(t[s],e,n);return{array:r,range:[e,n]}}(t,i,o)}function Dr(t,e,n){return((t>=32768?-(65536-t)/32768:t/32767)+1)*(n-e)/2+e}function Rr(t,e,n){const r=2*(t-e)/(n-e)-1,s=Math.max(-1,Math.min(1,r));return s<0?32768*s:32767*s}let Lr=0;class zr{constructor(t){this.workerId=t,this.workers={},this.$t={}}addLayer({actorId:t,mapId:e,layerId:n,params:r},s){if(this.Xt(e,n))return;const i=this.Ht(e,n),o=r.options,a=this.send.bind(this,t);this.workers[i]=new Er(n,o,a,s)}removeLayer({mapId:t,layerId:e},n){const r=this.Xt(t,e),s=this.Ht(t,e);delete this.workers[s],r&&r.onRemove(n)}loadTile({mapId:t,layerId:e,params:n},r){const s=this.Xt(t,e);s&&s.loadTile(n,r)}abortTileLoading({mapId:t,layerId:e,params:n},r){const s=this.Xt(t,e);s&&s.abortTileLoading(n,r)}receive(t){const e=t.callback,n=this.$t[e];delete this.$t[e],n&&t.error?n(new Error(t.error)):n&&n(null,t.data)}send(t,e,n,r,s){const i=s?`${t}-${Lr++}`:null;s&&(this.$t[i]=s),postMessage({type:"<request>",workerId:this.workerId,actorId:t,command:e,params:n,callback:String(i)},r||[])}Ht(t,e){return`${t}-${e}`}Xt(t,e){const n=this.Ht(t,e);return this.workers[n]}}t.initialize=function(){},t.onmessage=function(t,e){const n=t.data;this.dispatcher||(this.dispatcher=new zr(t.workerId)),"<response>"===t.type?this.dispatcher.workerId===t.workerId&&this.dispatcher.receive(t):this.dispatcher[n.command]({actorId:n.actorId,mapId:n.mapId,layerId:n.layerId,params:n.params},(t,n,r)=>{t&&console.error(t),t instanceof Error&&(t={message:t.message}),e(t,n,r)})},Object.defineProperty(t,"Jt",{value:!0})}';for(
|
|
6
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("maptalks"),require("@maptalks/gl")):"function"==typeof define&&define.amd?define(["exports","maptalks","@maptalks/gl"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).maptalks=t.maptalks||{},t.maptalks,t.maptalksgl)}(this,(function(t,e,n){"use strict";function r(t){if(t&&t.t)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var s=r(e),i=r(n);const o='function(t){var e="undefined"!=typeof Float32Array?Float32Array:Array;function n(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t}function r(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function s(t,e,n){var r=e[0],s=e[1],i=e[2],o=e[3],a=e[4],c=e[5],u=e[6],f=e[7],h=e[8],l=e[9],d=e[10],y=e[11],m=e[12],b=e[13],p=e[14],w=e[15],g=n[0],v=n[1],M=n[2],T=n[3];return t[0]=g*r+v*a+M*h+T*m,t[1]=g*s+v*c+M*l+T*b,t[2]=g*i+v*u+M*d+T*p,t[3]=g*o+v*f+M*y+T*w,g=n[4],v=n[5],M=n[6],T=n[7],t[4]=g*r+v*a+M*h+T*m,t[5]=g*s+v*c+M*l+T*b,t[6]=g*i+v*u+M*d+T*p,t[7]=g*o+v*f+M*y+T*w,g=n[8],v=n[9],M=n[10],T=n[11],t[8]=g*r+v*a+M*h+T*m,t[9]=g*s+v*c+M*l+T*b,t[10]=g*i+v*u+M*d+T*p,t[11]=g*o+v*f+M*y+T*w,g=n[12],v=n[13],M=n[14],T=n[15],t[12]=g*r+v*a+M*h+T*m,t[13]=g*s+v*c+M*l+T*b,t[14]=g*i+v*u+M*d+T*p,t[15]=g*o+v*f+M*y+T*w,t}function i(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=e[0],t[13]=e[1],t[14]=e[2],t[15]=1,t}function o(t,e){return t[0]=e[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=e[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=e[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function a(t,e){var n=e[0],r=e[1],s=e[2],i=e[3],o=n+n,a=r+r,c=s+s,u=n*o,f=r*o,h=r*a,l=s*o,d=s*a,y=s*c,m=i*o,b=i*a,p=i*c;return t[0]=1-h-y,t[1]=f+p,t[2]=l-b,t[3]=0,t[4]=f-p,t[5]=1-u-y,t[6]=d+m,t[7]=0,t[8]=l+b,t[9]=d-m,t[10]=1-u-h,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function c(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]&&t[4]===e[4]&&t[5]===e[5]&&t[6]===e[6]&&t[7]===e[7]&&t[8]===e[8]&&t[9]===e[9]&&t[10]===e[10]&&t[11]===e[11]&&t[12]===e[12]&&t[13]===e[13]&&t[14]===e[14]&&t[15]===e[15]}function u(){var t=new e(3);return e!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function f(t){var e=t[0],n=t[1],r=t[2];return Math.sqrt(e*e+n*n+r*r)}function h(t,n,r){var s=new e(3);return s[0]=t,s[1]=n,s[2]=r,s}function l(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function d(t,e,n,r){return t[0]=e,t[1]=n,t[2]=r,t}function y(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t}function m(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t[2]=e[2]*n[2],t}function b(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t}function p(t,e){var n=e[0],r=e[1],s=e[2],i=n*n+r*r+s*s;return i>0&&(i=1/Math.sqrt(i),t[0]=e[0]*i,t[1]=e[1]*i,t[2]=e[2]*i),t}function w(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function g(t,e,n){var r=e[0],s=e[1],i=e[2],o=n[0],a=n[1],c=n[2];return t[0]=s*c-i*a,t[1]=i*o-r*c,t[2]=r*a-s*o,t}function v(t,e,n){var r=e[0],s=e[1],i=e[2],o=n[3]*r+n[7]*s+n[11]*i+n[15];return o=o||1,t[0]=(n[0]*r+n[4]*s+n[8]*i+n[12])/o,t[1]=(n[1]*r+n[5]*s+n[9]*i+n[13])/o,t[2]=(n[2]*r+n[6]*s+n[10]*i+n[14])/o,t}var M=function(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t},T=m,A=f;function _(t,e,n,r,s){return t[0]=e,t[1]=n,t[2]=r,t[3]=s,t}function O(t,e,n){var r=e[0],s=e[1],i=e[2],o=e[3];return t[0]=n[0]*r+n[4]*s+n[8]*i+n[12]*o,t[1]=n[1]*r+n[5]*s+n[9]*i+n[13]*o,t[2]=n[2]*r+n[6]*s+n[10]*i+n[14]*o,t[3]=n[3]*r+n[7]*s+n[11]*i+n[15]*o,t}function x(){var t=new e(4);return e!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function S(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}function I(t,e,n,r){var s=e[0],i=e[1],o=e[2],a=e[3],c=n[0],u=n[1],f=n[2],h=n[3],l=void 0,d=void 0,y=void 0,m=void 0,b=void 0;return(d=s*c+i*u+o*f+a*h)<0&&(d=-d,c=-c,u=-u,f=-f,h=-h),1-d>1e-6?(l=Math.acos(d),y=Math.sin(l),m=Math.sin((1-r)*l)/y,b=Math.sin(r*l)/y):(m=1-r,b=r),t[0]=m*s+b*c,t[1]=m*i+b*u,t[2]=m*o+b*f,t[3]=m*a+b*h,t}u(),function(){var t,n=(t=new e(4),e!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t)}();var k,E=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t};u(),h(1,0,0),h(0,1,0),x(),x(),k=new e(9),e!=Float32Array&&(k[1]=0,k[2]=0,k[3]=0,k[5]=0,k[6]=0,k[7]=0),k[0]=1,k[4]=1,k[8]=1;\n/*!\n * @maptalks/gltf-loader v0.95.2\n * LICENSE : UNLICENSED\n * (c) 2016-2024 maptalks.org\n */\nlet C=0;function U(t){return null==t}function F(t){return!U(t)}function N(t){return!U(t)&&("string"==typeof t||null!==t.constructor&&t.constructor===String)}function P(t){for(let e=1;e<arguments.length;e++){const n=arguments[e];for(const e in n)t[e]=n[e]}return t}function B(t){switch(t){case 5120:return Int8Array;case 5121:return Uint8Array;case 5122:return Int16Array;case 5123:return Uint16Array;case 5124:return Int32Array;case 5125:return Uint32Array;case 5126:return Float32Array}throw new Error("unsupported bufferView\'s component type: "+t)}function D(t){return 0===t.indexOf("data:")&&t.indexOf("base64,")>0}function R(t){const e=function(t){return"undefined"!=typeof self?self.atob(t):window.atob(t)}(t.substring(t.indexOf(",")+1)),n=e.length,r=new Uint8Array(n);for(let t=0;t<n;t++)r[t]=e.charCodeAt(t);return r.buffer}const L=[],z=[],j=[],V=[0,0,0],q=S([]),G=[1,1,1];function $(t,e,n,r,s,i,o){const a=B(o);if((0===s||s===r*a.BYTES_PER_ELEMENT)&&i%a.BYTES_PER_ELEMENT==0){const s=new a(e,i,n*r);return t.set(s),t}0===s&&(s=r*a.BYTES_PER_ELEMENT);const c=new Uint8Array(r*a.BYTES_PER_ELEMENT);for(let o=0;o<n;o++){let n=null;const u=new Uint8Array(e,s*o+i,r*a.BYTES_PER_ELEMENT);c.set(u),n=new a(c.buffer,0,r);for(let e=0;e<r;e++)t[o*r+e]=n[e]}return t}const X="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function H(t,e,n){const r=new Uint8Array(t,e,n);return X.decode(r)}const J={get:function(t,e={}){e||(e={});const n=new AbortController,r=n.signal,s=P({},e);s.signal=r,s.method||(s.method="GET");const i=fetch(t,s).then(t=>{const n=this.t(t,e.responseType);return n.message?n:n.then(n=>"arraybuffer"===e.responseType?{data:n,cacheControl:t.headers.get("Cache-Control"),expires:t.headers.get("Expires"),contentType:t.headers.get("Content-Type")}:n).catch(t=>{if(!t.code||t.code!==DOMException.ABORT_ERR)throw t})}).catch(t=>{if(!t.code||t.code!==DOMException.ABORT_ERR)throw t});return i.xhr=n,i},t:(t,e)=>200!==t.status?{status:t.status,statusText:t.statusText,message:`incorrect http request with status code(${t.status}): ${t.statusText}`}:"arraybuffer"===e?t.arrayBuffer():"json"===e?t.json():t.text(),getArrayBuffer:(t,e={})=>(e||(e={}),e.responseType="arraybuffer",J.get(t,e)),getJSON:function(t,e={}){return e&&e.jsonp?J.jsonp(t):((e=e||{}).responseType="json",J.get(t,e))},jsonp:function(t){const e="_maptalks_jsonp_"+C++;t.match(/\\?/)?t+="&callback="+e:t+="?callback="+e;let n=document.createElement("script");return n.type="text/javascript",n.src=t,new Promise(t=>{window[e]=function(r){document.getElementsByTagName("head")[0].removeChild(n),n=null,delete window[e],t(r)},document.getElementsByTagName("head")[0].appendChild(n)})}};class K{constructor(t,e,n,r){this.s=t,this.decoders=e,this.i=n,this.images={},this.o={},this.u=r||{}}requestImageFromBufferURI(t,e,n){if(this.buffers[t.id]){const r=this.buffers[t.id],s=this.h(e,r);return this.getImageByBuffer(s,n)}if(this.o[t.id])return this.o[t.id].then(()=>{const r=this.buffers[t.id],s=this.h(e,r);return this.getImageByBuffer(s,n)});if(D(t.uri)){const r=this.buffers[t.id]=R(t.uri),s=this.h(e,r);return this.getImageByBuffer(s,n)}let r;const s=t.uri.indexOf("blob:")>=0;return r=t.uri.indexOf("://")>0||s?t.uri:this.rootPath+"/"+t.uri,this.o[t.id]=J.getArrayBuffer(r,this.u).then(r=>{const s=this.buffers[t.id]=r.data,i=this.h(e,s);return this.getImageByBuffer(i,n)})}getImageByBuffer(t,e){if(this.images[e.id])return Promise.resolve(this.images[e.id]);const n=this.decoders;return n[e.mimeType]?n[e.mimeType](t,{supportedFormats:this.i}):"image/crn"===e.mimeType||"image/ktx2"===e.mimeType||"image/cttf"===e.mimeType?(console.warn("missing transcoder for "+e.mimeType,", visit https://maptalks.com/docs/transcoders for details"),Promise.resolve(null)):this.m(e.id,t)}requestExternalImage(t){if(this.images[t.id])return Promise.resolve(this.images[t.id]);const e=0===t.uri.indexOf("data:image/")?t.uri:this.rootPath+"/"+t.uri;return this.o[t.id]?this.o[t.id].then(()=>this.images[t.id]):this.o[t.id]=this.m(t.id,e)}m(t,e){return new Promise((n,r)=>{this.s(e,this.u,(s,i)=>{s?r(s):(URL.revokeObjectURL(e),this.images[t]=i,n(this.images[t]))})})}}const Y=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],Q=[];class W{constructor(t,e,n,r){this.rootPath=t,this.gltf=e,this.p=!1,this.glbBuffer=n,this.buffers={},this.requests={},this.accessors={},this.v(),this.u=r}M(t,e){const n=this.gltf,r=n.accessors[e];if(void 0===r.bufferView)return this.accessors[r.id]=this.T(t,e,null,0),Promise.resolve(this.accessors[r.id]);if(r&&this.accessors[r.id])return Promise.resolve(this.accessors[r.id]);const s=n.bufferViews[r.bufferView];return this.A(s).then(n=>{const{buffer:s,byteOffset:i}=n;return this.accessors[r.id]=this.T(t,e,s,i)})}A(t){const e=this.gltf.buffers[t.buffer];if(this.buffers[e.id]){const t=this.buffers[e.id];return Promise.resolve({buffer:t,byteOffset:0})}if(this.requests[e.id])return this.requests[e.id].then(()=>{const t=this.buffers[e.id];return Promise.resolve({buffer:t,byteOffset:0})});if("binary_glTF"!==t.buffer&&"KHR_binary_glTF"!==t.buffer&&e.uri){if(D(e.uri)){const t=this.buffers[e.id]=R(e.uri);return Promise.resolve({buffer:t,byteOffset:0})}let t;const n=e.uri.indexOf("blob:")>=0;return t=e.uri.indexOf("://")>0||n?e.uri:this.rootPath+"/"+e.uri,this.requests[e.id]=J.getArrayBuffer(t,this.u).then(r=>(n&&URL.revokeObjectURL(t),{buffer:this.buffers[e.id]=r.data,byteOffset:0}))}return Promise.resolve({buffer:this.glbBuffer.buffer,byteOffset:this.glbBuffer.byteOffset})}T(t,e,n,r=0){const s=this.gltf,i=s.accessors[e],o=void 0!==i.bufferView?s.bufferViews[i.bufferView]:{},a=(o.byteOffset||0)+r,c=this._(i.type),u=B(i.componentType),f=o.byteStride||0,h={array:void 0,name:t,accessorName:e,byteLength:i.count*c*u.BYTES_PER_ELEMENT,componentType:i.componentType,count:i.count,type:i.type,itemSize:c,max:i.max,min:i.min,extensions:i.extensions};if(i.min&&(h.min=i.min),i.max&&(h.max=i.max),n)if(this.p)h.byteStride=f,h.byteOffset=a+(i.byteOffset||0),!f||f===c*u.BYTES_PER_ELEMENT||"indices"===t||"input"===t||"output"===t||t.indexOf("morph")>=0?(h.array=this.O(n,i.count,c,a+(i.byteOffset||0),u),h.array.buffer.byteLength===h.byteLength&&(h.byteOffset=0)):h.array=new Uint8Array(n,a,o.byteLength);else if(i.interleaved){h.byteStride=0,h.byteOffset=0;const t=new u(i.count*c);if(h.array=$(t,n,i.count,c,f,a+(i.byteOffset||0),i.componentType),h.extensions&&h.extensions.WEB3D_quantized_attributes&&c>2){const t=new Float32Array(h.array.length),{decodeMatrix:e}=h.extensions.WEB3D_quantized_attributes;for(let n=0;n<h.array.length;n+=c){Q[0]=h.array[n],Q[1]=h.array[n+1],Q[2]=h.array[n+2],Q[3]=1;const r=O(Q,Q,e);t[n]=r[0],t[n+1]=r[1],t[n+2]=r[2]}h.componentType=5126,h.array=t}}else h.byteStride=0,h.array=this.O(n,i.count,c,a+(i.byteOffset||0),u),h.byteOffset=h.array.byteOffset;else{h.array=new u(i.count);const t=h.min||h.max;t&&(h.array[0]=t[0],h.array[1]=t[1],h.array[2]=t[2])}return h}v(){const t=this.gltf.accessors;if(Array.isArray(t))for(let e=0;e<t.length;e++)for(let n=0;n<t.length;n++)e!==n&&t[e].bufferView===t[n].bufferView&&(t[e].interleaved=t[n].interleaved=!0);else for(const e in t)for(const n in t)e!==n&&t[e].bufferView===t[n].bufferView&&(t[e].interleaved=t[n].interleaved=!0)}O(t,e,n,r,s){return r%s.BYTES_PER_ELEMENT!=0&&(t=t.slice(r,r+e*n*s.BYTES_PER_ELEMENT),r=0),new s(t,r,n*e)}_(t){const e=Y.indexOf(t);return Y[e+1]}requestKHRTechniquesWebgl(t){const{shaders:e}=t,n=e.map(t=>{if(void 0!==t.bufferView){const e=this.gltf.bufferViews[t.bufferView],{byteLength:n}=e;return this.A(e).then(r=>{const{buffer:s,byteOffset:i}=r,o=H(s,i+(e.byteOffset||0),n);return t.content=o,t})}if(t.uri){if(D(t.uri)){const e=R(t.uri),n=H(e,0,e.byteLength);return t.content=n,Promise.resolve(t)}{const e=this.rootPath+"/"+t.uri;return J.get(e,this.u).then(e=>(t.content=e,t))}}return Promise.resolve(t)});return Promise.all(n).then(()=>t)}}class Z extends K{constructor(t,e,n,r,s,i,o){super(r,s,i,o),this.rootPath=t,this.gltf=e,this.requests={},this.buffers={},this.glbBuffer=n,this.accessor=new W(t,e,n,o)}iterate(t,e){const n=this.gltf[e];if(!n)return;let r=0;for(const e in n)t(e,n[e],r++)}createNode(t){const e={};if(F(t.name)&&(e.name=t.name),F(t.children)&&(e.children=t.children),F(t.jointName)&&(e.jointName=t.jointName),F(t.matrix)&&(e.matrix=t.matrix),F(t.rotation)&&(e.rotation=t.rotation),F(t.scale)&&(e.scale=t.scale),F(t.translation)&&(e.translation=t.translation),F(t.extras)&&(e.extras=t.extras),F(t.meshes)&&(e.mesh=t.meshes[0]),e.translation||e.rotation||e.scale){const t=function(t,e){if(e.matrix)return e.matrix;if(e.translation||e.scale||e.rotation){const n=i(L,e.translation||V),r=a(z,e.rotation||q),c=o(j,e.scale||G);return s(c,r,c),s(t,n,c)}return r(t)}([],e);delete e.translation,delete e.rotation,delete e.scale,e.matrix=t}return e}S(t){const e={};for(const n in t){const r=t[n];let s,i;r.instanceTechnique&&r.instanceTechnique.values?(s=r.instanceTechnique,i=s.values.diffuse):(s=r,i=s.values.tex||s.values.diffuseTex||s.values.diffuse);const o={baseColorTexture:{index:i}};r.name&&(o.name=r.name),r.extensions&&(o.extensions=r.extensions),r.extras&&(o.extras=r.extras),e[n]=o}return e}I(t){if(t.bufferView||t.extensions&&(t.extensions.KHR_binary_glTF||t.extensions.binary_glTF)){const e=t.bufferView?t:t.extensions.KHR_binary_glTF||t.extensions.binary_glTF;t.extensions&&(t.mimeType=e.mimeType,t.width=e.width,t.height=e.height);const n=this.gltf.bufferViews[e.bufferView],r=(n.byteOffset||0)+this.glbBuffer.byteOffset,s=n.byteLength,i=this.buffers[e.bufferView]=new Uint8Array(this.glbBuffer.buffer,r,s);return this.getImageByBuffer(i,t)}return this.requestExternalImage(t)}k(t){const e=this.gltf.textures[t];if(!e)return null;const n=this.gltf.images[e.source];return this.I(n).then(t=>{const r=this.gltf.samplers[e.sampler];return{image:{array:t.data,width:t.width,height:t.height,index:e.source,mimeType:n.mimeType,name:n.name,extras:n.extras},sampler:r}})}getBaseColorTexture(t){const e=this.gltf.materials[t];let n,r;if(e.instanceTechnique&&e.instanceTechnique.values?(n=e.instanceTechnique,r=n.values.diffuse):(n=e,r=n.values.tex||n.values.diffuseTex||n.values.diffuse),void 0===r||void 0===this.gltf.textures)return null;const s=this.gltf.textures[r];if(!s)return null;const i=this.gltf.samplers[s.sampler];return{format:s.format||6408,internalFormat:s.internalFormat||6408,type:s.type||5121,sampler:i,source:this.gltf.images[s.source]}}getMaterial(){return null}getAnimations(){return null}}class tt extends K{constructor(t,e,n,r,s,i,o){super(r,s,i,o),this.rootPath=t,this.gltf=e,this.glbBuffer=n,this.buffers={},this.requests={},this.accessor=new W(t,e,n,o)}iterate(t,e){const n=this.gltf[e];if(n)for(let e=0;e<n.length;e++)t(e,n[e],e)}createNode(t){const e={};return P(e,t),!F(t.weights)&&this.gltf.meshes&&F(e.mesh)?e.weights=this.gltf.meshes[e.mesh].weights:t.weights&&(e.weights=t.weights),e}k(t){const e=this.gltf.textures[t];if(!e)return null;let n=e.source;if(e.extensions&&e.extensions.EXT_texture_webp&&(n=e.extensions.EXT_texture_webp.source),!F(n))return null;const r=this.gltf.images[n];return this.I(r).then(t=>{if(!t)return null;const n={image:{array:t.data,mipmap:t.mipmap,width:t.width,height:t.height,index:e.source,mimeType:r.mimeType,name:r.name,extensions:r.extensions,extras:r.extras}};P(n,e);const s=F(e.sampler)?this.gltf.samplers[e.sampler]:void 0;return s&&(n.sampler=s,n.sampler.magFilter=s.magFilter||9729,n.sampler.minFilter=s.minFilter||9729,n.sampler.wrapS=s.wrapS||10497,n.sampler.wrapT=s.wrapT||10497),t.format&&(n.format=t.format),n})}I(t){if(!F(t.bufferView))return this.requestExternalImage(t);{const e=this.gltf.bufferViews[t.bufferView],n=this.gltf.buffers[e.buffer];if(n.uri)return this.requestImageFromBufferURI(n,e,t);if(this.glbBuffer)return this.C(e,t)}return null}C(t,e){const n=this.h(t,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(n,e)}h(t,e,n){n=n||0;const r=t.byteOffset+n,s=t.byteLength;return new Uint8Array(e,r,s)}U(t,e){const n=new Array(t.byteLength);for(let e=0;e<t.byteLength;e++)n[e]=String.fromCharCode(t[e]);return n.join(""),"data:"+(e=e||"image/png")+";base64,"+function(t){return"undefined"!=typeof self?self.btoa(t):window.btoa(t)}(unescape(encodeURIComponent(n)))}getAnimations(t){const e=[];return t.forEach(t=>{e.push(this.getSamplers(t.samplers))}),Promise.all(e).then(e=>{for(let n=0;n<e.length;n++)t[n].samplers=e[n];return t})}getSamplers(t){const e=[];for(let n=0;n<t.length;n++)(F(t[n].input)||F(t[n].output))&&(e.push(this.accessor.M("input",t[n].input)),e.push(this.accessor.M("output",t[n].output)));return Promise.all(e).then(e=>{for(let n=0;n<e.length/2;n++)t[n].input=e[2*n],t[n].output=e[2*n+1],t[n].interpolation||(t[n].interpolation="LINEAR");return t})}}const et="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class nt{static read(t,e=0,n=0){n||(n=t.byteLength);const r=new DataView(t,e,n),s=r.getUint32(4,!0);if(1===s)return nt.readV1(r,e);if(2===s)return nt.readV2(t,e);throw new Error("Unsupported glb version : "+s)}static readV1(t,e){const n=t.getUint32(8,!0),r=t.getUint32(12,!0);if(n!==t.byteLength)throw new Error("Length in GLB header is inconsistent with glb\'s byte length.");const s=rt(t.buffer,20+e,r);return{json:JSON.parse(s),glbBuffer:{byteOffset:20+e+r,buffer:t.buffer,byteLength:n}}}static readV2(t,e){let n,r,s;const i=new DataView(t,e+12);let o=0;for(;o<i.byteLength;){const a=i.getUint32(o,!0);o+=4;const c=i.getUint32(o,!0);if(o+=4,1313821514===c)n=rt(t,e+12+o,a);else if(5130562===c){s=e+12+o,r=a;break}o+=a}return{json:JSON.parse(n),glbBuffer:{byteOffset:s,buffer:t,byteLength:r}}}}function rt(t,e,n){if(et){const r=new Uint8Array(t,e,n);return et.decode(r)}return function(t){const e=t.length;let n="";for(let r=0;r<e;){let s=t[r++];if(128&s){let n=st[s>>3&7];if(!(64&s)||!n||r+n>e)return null;for(s&=63>>n;n>0;n-=1){const e=t[r++];if(128!=(192&e))return null;s=s<<6|63&e}}n+=String.fromCharCode(s)}return n}(new Uint8Array(t,e,n))}const st=[1,1,1,1,2,2,3,0],it=[0,0,0],ot=[0,0,0,1],at=[1,1,1],ct={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},ut={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},ft={F(t,e,n,r,s,i,o,a){const c=F(t)?e.animations:[e.animations[0]],u={};for(let e=0;e<c.length;e++){const f=c[e],h=f.name||e;if(F(t)&&h!==t)continue;const d=f.channelsMap[n];if(d)for(let t=0;t<d.length;t++){const e=d[t];"translation"===e.target.path?(this.N(s,f.samplers[e.sampler],r,1),u.translation=l(it,s)):"rotation"===e.target.path?(this.P(i,f.samplers[e.sampler],r,1),u.rotation=E(ot,i)):"scale"===e.target.path?(this.N(o,f.samplers[e.sampler],r,1),u.scale=l(at,o)):"weights"===e.target.path&&a&&(this.N(a,f.samplers[e.sampler],r,a.length),u.weights=a)}}return u},N(t,e,n,r){switch(e.interpolation){case"LINEAR":{const s=this.B(ut,e,n,1*r);s&&(t=function(t,e,n,r){for(let s=0;s<t.length;s++)t[s]=e[s]+r*(n[s]-e[s]);return t}(t,s.PREVIOUS,s.NEXT,s.INTERPOLATION));break}case"STEP":{const s=this.B(ut,e,n,1*r);s&&(t=function(t,e){for(let n=0;n<t.length;n++)t[n]=e[n];return t}(t,...s.PREVIOUS));break}case"CUBICSPLINE":{const s=this.B(ut,e,n,3*r);s&&(t=this.D(t,s,e.input.array,3*r));break}}return t},P(t,e,n){switch(e.interpolation){case"LINEAR":{const r=this.B(ut,e,n,1);r&&I(t,r.PREVIOUS,r.NEXT,r.INTERPOLATION);break}case"STEP":{const r=this.B(ut,e,n,1);r&&(t=_(t,...r.PREVIOUS));break}case"CUBICSPLINE":{const r=this.B(ut,e,n,3);if(r){for(let t=0;t<r.PREVIOUS.length;t++)r.PREVIOUS[t]=Math.acos(r.PREVIOUS[t]),r.NEXT[t]=Math.acos(r.NEXT[t]);t=this.D(t,r,e.input.array,3);for(let e=0;e<t.length;e++)t[e]=Math.cos(t[e])}break}}return t},R(t,e){const n=t.length;let r,s,i,o=0,a=n-1,c=Math.floor((o+a)/2);for(;o<=n-1&&a>=0;){if(o===a)return null;if(t[c]<=e&&e<=t[c+1]){const n=t[c];return r=c,s=c+1,i=(e-n)/(t[c+1]-n),{preIndx:r,nextIndex:s,interpolation:i}}e<t[c]?(a=c,c=Math.floor((o+a)/2)):t[c+1]<e&&(o=c,c=Math.floor((o+a)/2))}return null},B(t,e,n,r){const s=e.input.array,i=e.output.array,o=e.output.itemSize;(n<s[0]||n>s[s.length-1])&&(n=Math.max(s[0],Math.min(s[s.length-1],n))),n===s[s.length-1]&&(n=s[0]);const a=this.R(s,n);if(!a||!a.nextIndex)return null;const{preIndx:c,nextIndex:u,interpolation:f}=a;t.PREINDEX=c,t.NEXTINDEX=u,t.INTERPOLATION=f;const h=o*r;return t.PREVIOUS=i.subarray(t.PREINDEX*h,(t.PREINDEX+1)*h),t.NEXT=i.subarray(t.NEXTINDEX*h,(t.NEXTINDEX+1)*h),t},D(t,e,n,r){const s=e.INTERPOLATION,i=n[e.PREINDEX],o=n[e.NEXTINDEX];for(let n=0;n<3;n++){const a=e.PREVIOUS[r+n],c=(o-i)*e.PREVIOUS[2*r+n],u=e.NEXT[3+n],f=(o-i)*e.NEXT[n],h=(2*Math.pow(s,3)-3*Math.pow(s,2)+1)*a+(Math.pow(s,3)-2*Math.pow(s,2)+s)*c+(2*-Math.pow(s,3)+3*Math.pow(s,2))*u+(Math.pow(s,3)-Math.pow(s,2))*f;t[n]=h}return t},getAnimationClip(t,e,n,r){const s=t.nodes[e]&&t.nodes[e].weights;return d(it,...ct.TRANSLATION),_(ot,...ct.ROTATION),d(at,...ct.SCALE),this.F(r,t,e,n,it,ot,at,s)},getTimeSpan(t){if(!t.animations)return null;if(t.timeSpan)return t.timeSpan;const e=t.animations;return t.timeSpan={},e.forEach((e,n)=>{let r=-1/0,s=1/0;const i=e.channels;for(let t=0;t<i.length;t++){const n=i[t],o=e.samplers[n.sampler].input.array;o[o.length-1]>r&&(r=o[o.length-1]),o[0]<s&&(s=o[0])}const o=e.name||n;t.timeSpan[o]={max:r,min:s}}),t.timeSpan},getTimeSpanByName(t,e){const n=this.getTimeSpan(t);return n?F(e)?n[e]:n[Object.keys(n)[0]]:null}};let ht=!1;if("undefined"!=typeof OffscreenCanvas){let t;try{t=new OffscreenCanvas(2,2).getContext("2d")}catch(Qe){}t&&"undefined"!=typeof createImageBitmap&&(ht=!0)}const lt="undefined"==typeof document?null:document.createElement("canvas");class dt{constructor(t,e,n){if(this.options=n||{},this.options.decoders||(this.options.decoders={}),this.u=this.options.fetchOptions||{},e.buffer instanceof ArrayBuffer){const{json:n,glbBuffer:r}=nt.read(e.buffer,e.byteOffset,e.byteLength);this.L(t,n,r)}else this.L(t,e);this.j=new W(this.rootPath,this.gltf,this.glbBuffer,this.u),this.V()}V(){const t=this.gltf.extensionsRequired;if(t){if(t.indexOf("KHR_draco_mesh_compression")>=0&&!this.options.decoders.draco)throw new Error("KHR_draco_mesh_compression is required but @maptalks/transcoders.draco is not loaded");if(t.indexOf("KHR_texture_basisu")>=0&&!this.options.decoders.ktx2)throw new Error("KHR_texture_basisu is required but @maptalks/transcoders.ktx2 is not loaded")}}q(){const t=this.gltf.extensions;return t&&t.KHR_techniques_webgl?this.j.requestKHRTechniquesWebgl(t.KHR_techniques_webgl).then(e=>(t.KHR_techniques_webgl=e,t)):Promise.resolve(t)}load(t){t=t||{};const e=this.G(t),n=this.$(),r=this.X(),s=this.q();return Promise.all([e,n,r,s]).then(t=>(t[0].animations=t[1],t[0].textures=t[2],t[0].extensions=t[3],t[0].transferables=this.transferables||[],this.createChannelsMap(t[0]),t[0]))}createChannelsMap(t){const e=t.animations;if(e)for(let t=0;t<e.length;t++){const n=e[t];n.channelsMap={};for(let t=0;t<n.channels.length;t++){const e=n.channels[t];n.channelsMap[e.target.node]||(n.channelsMap[e.target.node]=[]),n.channelsMap[e.target.node].push(e)}}}getExternalResources(){const t=[];if(this.gltf){const{buffers:e,images:n}=this.gltf;for(let n=0;n<e.length;n++)e[n].uri&&e[n].uri.indexOf("data:application/octet-stream;base64")<0&&t.push({type:"buffer",uri:e[n].uri});for(let e=0;e<n.length;e++)n[e].uri&&n[e].uri.indexOf("data:image/")<0&&t.push({type:"image",uri:n[e].uri})}return t}static getAnimationClip(t,e,n,r){return ft.getAnimationClip(t,e,n,r)}static getAnimationTimeSpan(t,e){return ft.getTimeSpanByName(t,e)}static getTypedArrayCtor(t){return B(t)}static readInterleavedArray(t,e,n,r,s,i,o){return $(t,e,n,r,s,i,o)}L(t,e,n){this.gltf=e,this.glbBuffer=n,this.version=e.asset?+e.asset.version:1,this.rootPath=t,this.buffers={},this.requests={},this.options.requestImage=ht?pt.bind(this):this.options.requestImage||yt,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new tt(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this.u),this.adapter.iterate((t,e,n)=>{e.id="buffer_"+n},"buffers"),this.adapter.iterate((t,e,n)=>{e.id="image_"+n},"images"),this.adapter.iterate((t,e,n)=>{e.id="accessor_"+n},"accessors")):(this.adapter=new Z(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this.u),this.adapter.iterate((t,e,n)=>{e.id="accessor_"+n},"accessors"),this.adapter.iterate((t,e,n)=>{e.id="image_"+n},"images"))}H(t,e){if(t.children&&t.children.length>0){if(!("number"==typeof(n=t.children[0])&&isFinite(n)||N(t.children[0])))return t;const r=t.children.map(t=>{const n=e[t];return n.nodeIndex=t,this.H(n,e)});t.children=r}var n;return t}G(t){return this.J(t).then(t=>{const e=this.scenes=[];let n;for(const e in t)t[e]=this.H(t[e],t),t[e].nodeIndex=Number(e)?Number(e):e;this.adapter.iterate((r,s,i)=>{const o={};s.name&&(o.name=s.name),s.nodes&&(o.nodes=s.nodes.map(e=>t[e])),this.gltf.scene===r&&(n=i),e.push(o)},"scenes");const r={textures:this.gltf.textures,asset:this.gltf.asset,scene:n,scenes:e,nodes:t,meshes:this.meshes,materials:this.gltf.materials,skins:this.skins,extensionsRequired:this.gltf.extensionsRequired,extensionsUsed:this.gltf.extensionsUsed};if(this.gltf.extensions&&(r.extensions=this.gltf.extensions),1===this.version){const t=this.adapter.S(this.gltf.materials);r.materials=t}return delete this.gltf.buffers,r.json=this.gltf,r})}J(t){return this.K(t).then(()=>{const t=this.nodes={};return this.adapter.iterate((e,n)=>{const r=this.adapter.createNode(n,this.meshes,this.skins);t[e]=r},"nodes"),t})}Y(){this.skins=[];const t=[];return this.adapter.iterate((e,n,r)=>{t.push(this.W(n).then(t=>{t.index=r,this.skins.push(t)}))},"skins"),t}W(t){const e=t.inverseBindMatrices;return this.adapter.accessor.M("inverseBindMatrices",e).then(e=>(t.inverseBindMatrices=e,e&&e.buffer&&this.transferables&&this.transferables.indexOf(e.buffer)<0&&this.transferables.push(e.buffer),t))}$(){const t=this.gltf.animations;return F(t)?this.adapter.getAnimations(t):null}K(t){this.meshes={};let e=[];return this.adapter.iterate((n,r,s)=>{e.push(this.Z(r,t).then(t=>{t.index=s,this.meshes[n]=t}))},"meshes"),e=e.concat(this.Y()),Promise.all(e)}Z(t,e){const n=t.primitives.map(t=>this.tt(t,e)).filter(t=>!!t);return Promise.all(n).then(e=>{const n={};return P(n,t),n.primitives=e,n})}X(){const t=this.gltf.textures;if(!t)return null;const e=[];for(const n in t)e.push(this.adapter.k(n));return Promise.all(e).then(e=>{if(this.transferables)for(let t=0;t<e.length;t++){const n=e[t].image.array;if(e[t]&&n){let t;t=n instanceof ImageBitmap?n:n.buffer,t&&this.transferables.indexOf(t)<0&&this.transferables.push(t)}}if(!Array.isArray(t)){const n={},r=Object.keys(t);for(let t=0;t<e.length;t++)e[t]&&(n[r[t]]=e[t]);return n}return e})}tt(t,e){let n;const r=[],s=t.extensions;if(F(t.targets))for(let e=0;e<t.targets.length;e++){const n=t.targets[e];for(const t in n){const s=this.adapter.accessor.M(`morphTargets_${t}_${e}`,n[t]);s&&r.push(s)}}if(s&&s.KHR_draco_mesh_compression){if(!this.options.decoders.draco&&(!this.gltf.extensionsRequired||!this.gltf.extensionsRequired.indexOf("KHR_draco_mesh_compression")<0))return null;const t=this.options.decoders.draco,{bufferView:i,attributes:o}=s.KHR_draco_mesh_compression,a=this.gltf.bufferViews[i],c=this.j.A(a).then(n=>{const{buffer:r,byteOffset:s}=n;let{byteOffset:i}=a;const c=a.byteLength;i||(i=0);const u=new DataView(r,s+i,c),f={attributes:o,useUniqueIDs:!1,skipAttributeTransform:e.skipAttributeTransform};return t(u,f).then(t=>{const e=Object.values(t.attributes);return t.indices&&e.push(t.indices),e})});r.push(c),n=Promise.all(r)}else{const e=t.attributes;for(const t in e){const n=this.adapter.accessor.M(t,e[t]);n&&r.push(n)}if(F(t.indices)){const e=this.adapter.accessor.M("indices",t.indices);e&&r.push(e)}n=Promise.all(r)}return n.then(e=>{if(s&&s.KHR_draco_mesh_compression){const n=t.targets?t.targets.length:0;e[n]=e[n].concat(e.slice(0,n)),e=e[n]}let n,r;const i={attributes:e.reduce((t,e)=>{if("indices"===e.name)n=e;else if(e.name.indexOf("morphTargets_")>-1)r=r||{},r[e.name.slice(13)]=e;else{if(!("POSITION"!==e.name||e.min&&e.max)){const t=[1/0,1/0,1/0],n=[-1/0,-1/0,-1/0],{itemSize:r,array:s}=e,i=s.length/r;for(let e=0;e<i;e++)for(let i=0;i<r;i++){const o=e*r+i;s[o]<t[i]&&(t[i]=s[o]),s[o]>n[i]&&(n[i]=s[o])}if(e.quantization){const r=e.quantization,s=r.range/(1<<r.quantizationBits),i=r.minValues;b(t,t,s),y(t,t,i),b(n,n,s),y(n,n,i)}e.min=t,e.max=n}t[e.name]=e}return this.transferables&&e.array.buffer&&this.transferables.indexOf(e.array.buffer)<0&&this.transferables.push(e.array.buffer),t},{}),material:t.material};return n&&(i.indices=n),r&&(i.morphTargets=r),i.mode=F(t.mode)?t.mode:4,F(t.extras)&&(i.extras=t.extras),i})}}function yt(t,e,n){const r=new Image;r.crossOrigin="",r.onload=()=>{if(!lt)return void n(new Error("There is no canvas to draw image!"));lt.width=r.width,lt.height=r.height;const t=lt.getContext("2d",{willReadFrequently:!0});t.drawImage(r,0,0,r.width,r.height);const e=t.getImageData(0,0,r.width,r.height),s={width:r.width,height:r.height,data:new Uint8Array(e.data)};n(null,s)},r.onerror=function(t){n(t)},r.src=t}let mt,bt;function pt(t,e,n){mt||(mt=new OffscreenCanvas(2,2),bt=mt.getContext("2d",{willReadFrequently:!0}));let r=null;if(N(t))r=fetch(t,e).then(t=>t.arrayBuffer()).then(t=>{const e=new Blob([new Uint8Array(t)]);return createImageBitmap(e)});else{const e=new Blob([t]);r=createImageBitmap(e)}r.then(wt.bind(this)).then(t=>{n(null,t)}).catch(t=>{console.warn(t),n(t)})}function wt(t){let{width:e,height:n}=t;gt(e)||(e=vt(e)),gt(n)||(n=vt(n));const r=this.options.maxTextureSize;r&&(e=Math.min(r,e),n=Math.min(r,n)),mt.width=e,mt.height=n,bt.drawImage(t,0,0,e,n),t.close();const s=bt.getImageData(0,0,e,n);return{width:e,height:n,data:new Uint8Array(s.data)}}function gt(t){return 0==(t&t-1)&&0!==t}function vt(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}var Mt={exports:{}},Tt={"aliceblue":[240,248,255],"antiquewhite":[250,235,215],"aqua":[0,255,255],"aquamarine":[127,255,212],"azure":[240,255,255],"beige":[245,245,220],"bisque":[255,228,196],"black":[0,0,0],"blanchedalmond":[255,235,205],"blue":[0,0,255],"blueviolet":[138,43,226],"brown":[165,42,42],"burlywood":[222,184,135],"cadetblue":[95,158,160],"chartreuse":[127,255,0],"chocolate":[210,105,30],"coral":[255,127,80],"cornflowerblue":[100,149,237],"cornsilk":[255,248,220],"crimson":[220,20,60],"cyan":[0,255,255],"darkblue":[0,0,139],"darkcyan":[0,139,139],"darkgoldenrod":[184,134,11],"darkgray":[169,169,169],"darkgreen":[0,100,0],"darkgrey":[169,169,169],"darkkhaki":[189,183,107],"darkmagenta":[139,0,139],"darkolivegreen":[85,107,47],"darkorange":[255,140,0],"darkorchid":[153,50,204],"darkred":[139,0,0],"darksalmon":[233,150,122],"darkseagreen":[143,188,143],"darkslateblue":[72,61,139],"darkslategray":[47,79,79],"darkslategrey":[47,79,79],"darkturquoise":[0,206,209],"darkviolet":[148,0,211],"deeppink":[255,20,147],"deepskyblue":[0,191,255],"dimgray":[105,105,105],"dimgrey":[105,105,105],"dodgerblue":[30,144,255],"firebrick":[178,34,34],"floralwhite":[255,250,240],"forestgreen":[34,139,34],"fuchsia":[255,0,255],"gainsboro":[220,220,220],"ghostwhite":[248,248,255],"gold":[255,215,0],"goldenrod":[218,165,32],"gray":[128,128,128],"green":[0,128,0],"greenyellow":[173,255,47],"grey":[128,128,128],"honeydew":[240,255,240],"hotpink":[255,105,180],"indianred":[205,92,92],"indigo":[75,0,130],"ivory":[255,255,240],"khaki":[240,230,140],"lavender":[230,230,250],"lavenderblush":[255,240,245],"lawngreen":[124,252,0],"lemonchiffon":[255,250,205],"lightblue":[173,216,230],"lightcoral":[240,128,128],"lightcyan":[224,255,255],"lightgoldenrodyellow":[250,250,210],"lightgray":[211,211,211],"lightgreen":[144,238,144],"lightgrey":[211,211,211],"lightpink":[255,182,193],"lightsalmon":[255,160,122],"lightseagreen":[32,178,170],"lightskyblue":[135,206,250],"lightslategray":[119,136,153],"lightslategrey":[119,136,153],"lightsteelblue":[176,196,222],"lightyellow":[255,255,224],"lime":[0,255,0],"limegreen":[50,205,50],"linen":[250,240,230],"magenta":[255,0,255],"maroon":[128,0,0],"mediumaquamarine":[102,205,170],"mediumblue":[0,0,205],"mediumorchid":[186,85,211],"mediumpurple":[147,112,219],"mediumseagreen":[60,179,113],"mediumslateblue":[123,104,238],"mediumspringgreen":[0,250,154],"mediumturquoise":[72,209,204],"mediumvioletred":[199,21,133],"midnightblue":[25,25,112],"mintcream":[245,255,250],"mistyrose":[255,228,225],"moccasin":[255,228,181],"navajowhite":[255,222,173],"navy":[0,0,128],"oldlace":[253,245,230],"olive":[128,128,0],"olivedrab":[107,142,35],"orange":[255,165,0],"orangered":[255,69,0],"orchid":[218,112,214],"palegoldenrod":[238,232,170],"palegreen":[152,251,152],"paleturquoise":[175,238,238],"palevioletred":[219,112,147],"papayawhip":[255,239,213],"peachpuff":[255,218,185],"peru":[205,133,63],"pink":[255,192,203],"plum":[221,160,221],"powderblue":[176,224,230],"purple":[128,0,128],"rebeccapurple":[102,51,153],"red":[255,0,0],"rosybrown":[188,143,143],"royalblue":[65,105,225],"saddlebrown":[139,69,19],"salmon":[250,128,114],"sandybrown":[244,164,96],"seagreen":[46,139,87],"seashell":[255,245,238],"sienna":[160,82,45],"silver":[192,192,192],"skyblue":[135,206,235],"slateblue":[106,90,205],"slategray":[112,128,144],"slategrey":[112,128,144],"snow":[255,250,250],"springgreen":[0,255,127],"steelblue":[70,130,180],"tan":[210,180,140],"teal":[0,128,128],"thistle":[216,191,216],"tomato":[255,99,71],"turquoise":[64,224,208],"violet":[238,130,238],"wheat":[245,222,179],"white":[255,255,255],"whitesmoke":[245,245,245],"yellow":[255,255,0],"yellowgreen":[154,205,50]},At={exports:{}},_t=function(t){return!(!t||"string"==typeof t)&&(t instanceof Array||Array.isArray(t)||t.length>=0&&(t.splice instanceof Function||Object.getOwnPropertyDescriptor(t,t.length-1)&&"String"!==t.constructor.name))},Ot=Array.prototype.concat,xt=Array.prototype.slice,St=At.exports=function(t){for(var e=[],n=0,r=t.length;n<r;n++){var s=t[n];_t(s)?e=Ot.call(e,xt.call(s)):e.push(s)}return e};St.wrap=function(t){return function(){return t(St(arguments))}};var It=Tt,kt=At.exports,Et=Object.hasOwnProperty,Ct=Object.create(null);for(var Ut in It)Et.call(It,Ut)&&(Ct[It[Ut]]=Ut);var Ft=Mt.exports={to:{},get:{}};function Nt(t,e,n){return Math.min(Math.max(e,t),n)}function Pt(t){var e=Math.round(t).toString(16).toUpperCase();return e.length<2?"0"+e:e}Ft.get=function(t){var e,n;switch(t.substring(0,3).toLowerCase()){case"hsl":e=Ft.get.hsl(t),n="hsl";break;case"hwb":e=Ft.get.hwb(t),n="hwb";break;default:e=Ft.get.rgb(t),n="rgb"}return e?{model:n,value:e}:null},Ft.get.rgb=function(t){if(!t)return null;var e,n,r,s=[0,0,0,1];if(e=t.match(/^#([a-f0-9]{6})([a-f0-9]{2})?$/i)){for(r=e[2],e=e[1],n=0;n<3;n++){var i=2*n;s[n]=parseInt(e.slice(i,i+2),16)}r&&(s[3]=parseInt(r,16)/255)}else if(e=t.match(/^#([a-f0-9]{3,4})$/i)){for(r=(e=e[1])[3],n=0;n<3;n++)s[n]=parseInt(e[n]+e[n],16);r&&(s[3]=parseInt(r+r,16)/255)}else if(e=t.match(/^rgba?\\(\\s*([+-]?\\d+)(?=[\\s,])\\s*(?:,\\s*)?([+-]?\\d+)(?=[\\s,])\\s*(?:,\\s*)?([+-]?\\d+)\\s*(?:[,|\\/]\\s*([+-]?[\\d\\.]+)(%?)\\s*)?\\)$/)){for(n=0;n<3;n++)s[n]=parseInt(e[n+1],0);e[4]&&(e[5]?s[3]=.01*parseFloat(e[4]):s[3]=parseFloat(e[4]))}else{if(!(e=t.match(/^rgba?\\(\\s*([+-]?[\\d\\.]+)\\%\\s*,?\\s*([+-]?[\\d\\.]+)\\%\\s*,?\\s*([+-]?[\\d\\.]+)\\%\\s*(?:[,|\\/]\\s*([+-]?[\\d\\.]+)(%?)\\s*)?\\)$/)))return(e=t.match(/^(\\w+)$/))?"transparent"===e[1]?[0,0,0,0]:Et.call(It,e[1])?((s=It[e[1]])[3]=1,s):null:null;for(n=0;n<3;n++)s[n]=Math.round(2.55*parseFloat(e[n+1]));e[4]&&(e[5]?s[3]=.01*parseFloat(e[4]):s[3]=parseFloat(e[4]))}for(n=0;n<3;n++)s[n]=Nt(s[n],0,255);return s[3]=Nt(s[3],0,1),s},Ft.get.hsl=function(t){if(!t)return null;var e=t.match(/^hsla?\\(\\s*([+-]?(?:\\d{0,3}\\.)?\\d+)(?:deg)?\\s*,?\\s*([+-]?[\\d\\.]+)%\\s*,?\\s*([+-]?[\\d\\.]+)%\\s*(?:[,|\\/]\\s*([+-]?(?=\\.\\d|\\d)(?:0|[1-9]\\d*)?(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)\\s*)?\\)$/);if(e){var n=parseFloat(e[4]);return[(parseFloat(e[1])%360+360)%360,Nt(parseFloat(e[2]),0,100),Nt(parseFloat(e[3]),0,100),Nt(isNaN(n)?1:n,0,1)]}return null},Ft.get.hwb=function(t){if(!t)return null;var e=t.match(/^hwb\\(\\s*([+-]?\\d{0,3}(?:\\.\\d+)?)(?:deg)?\\s*,\\s*([+-]?[\\d\\.]+)%\\s*,\\s*([+-]?[\\d\\.]+)%\\s*(?:,\\s*([+-]?(?=\\.\\d|\\d)(?:0|[1-9]\\d*)?(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)\\s*)?\\)$/);if(e){var n=parseFloat(e[4]);return[(parseFloat(e[1])%360+360)%360,Nt(parseFloat(e[2]),0,100),Nt(parseFloat(e[3]),0,100),Nt(isNaN(n)?1:n,0,1)]}return null},Ft.to.hex=function(){var t=kt(arguments);return"#"+Pt(t[0])+Pt(t[1])+Pt(t[2])+(t[3]<1?Pt(Math.round(255*t[3])):"")},Ft.to.rgb=function(){var t=kt(arguments);return t.length<4||1===t[3]?"rgb("+Math.round(t[0])+", "+Math.round(t[1])+", "+Math.round(t[2])+")":"rgba("+Math.round(t[0])+", "+Math.round(t[1])+", "+Math.round(t[2])+", "+t[3]+")"},Ft.to.rgb.percent=function(){var t=kt(arguments),e=Math.round(t[0]/255*100),n=Math.round(t[1]/255*100),r=Math.round(t[2]/255*100);return t.length<4||1===t[3]?"rgb("+e+"%, "+n+"%, "+r+"%)":"rgba("+e+"%, "+n+"%, "+r+"%, "+t[3]+")"},Ft.to.hsl=function(){var t=kt(arguments);return t.length<4||1===t[3]?"hsl("+t[0]+", "+t[1]+"%, "+t[2]+"%)":"hsla("+t[0]+", "+t[1]+"%, "+t[2]+"%, "+t[3]+")"},Ft.to.hwb=function(){var t=kt(arguments),e="";return t.length>=4&&1!==t[3]&&(e=", "+t[3]),"hwb("+t[0]+", "+t[1]+"%, "+t[2]+"%"+e+")"},Ft.to.keyword=function(t){return Ct[t.slice(0,3)]};var Bt={exports:{}},Dt=Tt,Rt={};for(var Lt in Dt)Dt.hasOwnProperty(Lt)&&(Rt[Dt[Lt]]=Lt);var zt=Bt.exports={rgb:{channels:3,labels:"rgb"},hsl:{channels:3,labels:"hsl"},hsv:{channels:3,labels:"hsv"},hwb:{channels:3,labels:"hwb"},cmyk:{channels:4,labels:"cmyk"},xyz:{channels:3,labels:"xyz"},lab:{channels:3,labels:"lab"},lch:{channels:3,labels:"lch"},hex:{channels:1,labels:["hex"]},keyword:{channels:1,labels:["keyword"]},ansi16:{channels:1,labels:["ansi16"]},ansi256:{channels:1,labels:["ansi256"]},hcg:{channels:3,labels:["h","c","g"]},apple:{channels:3,labels:["r16","g16","b16"]},gray:{channels:1,labels:["gray"]}};for(var jt in zt)if(zt.hasOwnProperty(jt)){if(!("channels"in zt[jt]))throw new Error("missing channels property: "+jt);if(!("labels"in zt[jt]))throw new Error("missing channel labels property: "+jt);if(zt[jt].labels.length!==zt[jt].channels)throw new Error("channel and label counts mismatch: "+jt);var Vt=zt[jt].channels,qt=zt[jt].labels;delete zt[jt].channels,delete zt[jt].labels,Object.defineProperty(zt[jt],"channels",{value:Vt}),Object.defineProperty(zt[jt],"labels",{value:qt})}function Gt(t,e){return Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2)+Math.pow(t[2]-e[2],2)}zt.rgb.hsl=function(t){var e,n,r=t[0]/255,s=t[1]/255,i=t[2]/255,o=Math.min(r,s,i),a=Math.max(r,s,i),c=a-o;return a===o?e=0:r===a?e=(s-i)/c:s===a?e=2+(i-r)/c:i===a&&(e=4+(r-s)/c),(e=Math.min(60*e,360))<0&&(e+=360),n=(o+a)/2,[e,100*(a===o?0:n<=.5?c/(a+o):c/(2-a-o)),100*n]},zt.rgb.hsv=function(t){var e,n,r,s,i,o=t[0]/255,a=t[1]/255,c=t[2]/255,u=Math.max(o,a,c),f=u-Math.min(o,a,c),h=function(t){return(u-t)/6/f+.5};return 0===f?s=i=0:(i=f/u,e=h(o),n=h(a),r=h(c),o===u?s=r-n:a===u?s=1/3+e-r:c===u&&(s=2/3+n-e),s<0?s+=1:s>1&&(s-=1)),[360*s,100*i,100*u]},zt.rgb.hwb=function(t){var e=t[0],n=t[1],r=t[2];return[zt.rgb.hsl(t)[0],100*(1/255*Math.min(e,Math.min(n,r))),100*(r=1-1/255*Math.max(e,Math.max(n,r)))]},zt.rgb.cmyk=function(t){var e,n=t[0]/255,r=t[1]/255,s=t[2]/255;return[100*((1-n-(e=Math.min(1-n,1-r,1-s)))/(1-e)||0),100*((1-r-e)/(1-e)||0),100*((1-s-e)/(1-e)||0),100*e]},zt.rgb.keyword=function(t){var e=Rt[t];if(e)return e;var n,r=1/0;for(var s in Dt)if(Dt.hasOwnProperty(s)){var i=Gt(t,Dt[s]);i<r&&(r=i,n=s)}return n},zt.keyword.rgb=function(t){return Dt[t]},zt.rgb.xyz=function(t){var e=t[0]/255,n=t[1]/255,r=t[2]/255;return[100*(.4124*(e=e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92)+.3576*(n=n>.04045?Math.pow((n+.055)/1.055,2.4):n/12.92)+.1805*(r=r>.04045?Math.pow((r+.055)/1.055,2.4):r/12.92)),100*(.2126*e+.7152*n+.0722*r),100*(.0193*e+.1192*n+.9505*r)]},zt.rgb.lab=function(t){var e=zt.rgb.xyz(t),n=e[0],r=e[1],s=e[2];return r/=100,s/=108.883,n=(n/=95.047)>.008856?Math.pow(n,1/3):7.787*n+16/116,[116*(r=r>.008856?Math.pow(r,1/3):7.787*r+16/116)-16,500*(n-r),200*(r-(s=s>.008856?Math.pow(s,1/3):7.787*s+16/116))]},zt.hsl.rgb=function(t){var e,n,r,s,i,o=t[0]/360,a=t[1]/100,c=t[2]/100;if(0===a)return[i=255*c,i,i];e=2*c-(n=c<.5?c*(1+a):c+a-c*a),s=[0,0,0];for(var u=0;u<3;u++)(r=o+1/3*-(u-1))<0&&r++,r>1&&r--,i=6*r<1?e+6*(n-e)*r:2*r<1?n:3*r<2?e+(n-e)*(2/3-r)*6:e,s[u]=255*i;return s},zt.hsl.hsv=function(t){var e=t[0],n=t[1]/100,r=t[2]/100,s=n,i=Math.max(r,.01);return n*=(r*=2)<=1?r:2-r,s*=i<=1?i:2-i,[e,100*(0===r?2*s/(i+s):2*n/(r+n)),100*((r+n)/2)]},zt.hsv.rgb=function(t){var e=t[0]/60,n=t[1]/100,r=t[2]/100,s=Math.floor(e)%6,i=e-Math.floor(e),o=255*r*(1-n),a=255*r*(1-n*i),c=255*r*(1-n*(1-i));switch(r*=255,s){case 0:return[r,c,o];case 1:return[a,r,o];case 2:return[o,r,c];case 3:return[o,a,r];case 4:return[c,o,r];case 5:return[r,o,a]}},zt.hsv.hsl=function(t){var e,n,r,s=t[0],i=t[1]/100,o=t[2]/100,a=Math.max(o,.01);return r=(2-i)*o,n=i*a,[s,100*(n=(n/=(e=(2-i)*a)<=1?e:2-e)||0),100*(r/=2)]},zt.hwb.rgb=function(t){var e,n,r,s,i,o,a,c=t[0]/360,u=t[1]/100,f=t[2]/100,h=u+f;switch(h>1&&(u/=h,f/=h),r=6*c-(e=Math.floor(6*c)),0!=(1&e)&&(r=1-r),s=u+r*((n=1-f)-u),e){default:case 6:case 0:i=n,o=s,a=u;break;case 1:i=s,o=n,a=u;break;case 2:i=u,o=n,a=s;break;case 3:i=u,o=s,a=n;break;case 4:i=s,o=u,a=n;break;case 5:i=n,o=u,a=s}return[255*i,255*o,255*a]},zt.cmyk.rgb=function(t){var e=t[0]/100,n=t[1]/100,r=t[2]/100,s=t[3]/100;return[255*(1-Math.min(1,e*(1-s)+s)),255*(1-Math.min(1,n*(1-s)+s)),255*(1-Math.min(1,r*(1-s)+s))]},zt.xyz.rgb=function(t){var e,n,r,s=t[0]/100,i=t[1]/100,o=t[2]/100;return n=-.9689*s+1.8758*i+.0415*o,r=.0557*s+-.204*i+1.057*o,e=(e=3.2406*s+-1.5372*i+-.4986*o)>.0031308?1.055*Math.pow(e,1/2.4)-.055:12.92*e,n=n>.0031308?1.055*Math.pow(n,1/2.4)-.055:12.92*n,r=r>.0031308?1.055*Math.pow(r,1/2.4)-.055:12.92*r,[255*(e=Math.min(Math.max(0,e),1)),255*(n=Math.min(Math.max(0,n),1)),255*(r=Math.min(Math.max(0,r),1))]},zt.xyz.lab=function(t){var e=t[0],n=t[1],r=t[2];return n/=100,r/=108.883,e=(e/=95.047)>.008856?Math.pow(e,1/3):7.787*e+16/116,[116*(n=n>.008856?Math.pow(n,1/3):7.787*n+16/116)-16,500*(e-n),200*(n-(r=r>.008856?Math.pow(r,1/3):7.787*r+16/116))]},zt.lab.xyz=function(t){var e,n,r,s=t[0];e=t[1]/500+(n=(s+16)/116),r=n-t[2]/200;var i=Math.pow(n,3),o=Math.pow(e,3),a=Math.pow(r,3);return n=i>.008856?i:(n-16/116)/7.787,e=o>.008856?o:(e-16/116)/7.787,r=a>.008856?a:(r-16/116)/7.787,[e*=95.047,n*=100,r*=108.883]},zt.lab.lch=function(t){var e,n=t[0],r=t[1],s=t[2];return(e=360*Math.atan2(s,r)/2/Math.PI)<0&&(e+=360),[n,Math.sqrt(r*r+s*s),e]},zt.lch.lab=function(t){var e,n=t[0],r=t[1];return e=t[2]/360*2*Math.PI,[n,r*Math.cos(e),r*Math.sin(e)]},zt.rgb.ansi16=function(t){var e=t[0],n=t[1],r=t[2],s=1 in arguments?arguments[1]:zt.rgb.hsv(t)[2];if(0===(s=Math.round(s/50)))return 30;var i=30+(Math.round(r/255)<<2|Math.round(n/255)<<1|Math.round(e/255));return 2===s&&(i+=60),i},zt.hsv.ansi16=function(t){return zt.rgb.ansi16(zt.hsv.rgb(t),t[2])},zt.rgb.ansi256=function(t){var e=t[0],n=t[1],r=t[2];return e===n&&n===r?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(n/255*5)+Math.round(r/255*5)},zt.ansi16.rgb=function(t){var e=t%10;if(0===e||7===e)return t>50&&(e+=3.5),[e=e/10.5*255,e,e];var n=.5*(1+~~(t>50));return[(1&e)*n*255,(e>>1&1)*n*255,(e>>2&1)*n*255]},zt.ansi256.rgb=function(t){if(t>=232){var e=10*(t-232)+8;return[e,e,e]}var n;return t-=16,[Math.floor(t/36)/5*255,Math.floor((n=t%36)/6)/5*255,n%6/5*255]},zt.rgb.hex=function(t){var e=(((255&Math.round(t[0]))<<16)+((255&Math.round(t[1]))<<8)+(255&Math.round(t[2]))).toString(16).toUpperCase();return"000000".substring(e.length)+e},zt.hex.rgb=function(t){var e=t.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!e)return[0,0,0];var n=e[0];3===e[0].length&&(n=n.split("").map((function(t){return t+t})).join(""));var r=parseInt(n,16);return[r>>16&255,r>>8&255,255&r]},zt.rgb.hcg=function(t){var e,n=t[0]/255,r=t[1]/255,s=t[2]/255,i=Math.max(Math.max(n,r),s),o=Math.min(Math.min(n,r),s),a=i-o;return e=a<=0?0:i===n?(r-s)/a%6:i===r?2+(s-n)/a:4+(n-r)/a+4,e/=6,[360*(e%=1),100*a,100*(a<1?o/(1-a):0)]},zt.hsl.hcg=function(t){var e=t[1]/100,n=t[2]/100,r=1,s=0;return(r=n<.5?2*e*n:2*e*(1-n))<1&&(s=(n-.5*r)/(1-r)),[t[0],100*r,100*s]},zt.hsv.hcg=function(t){var e=t[1]/100,n=t[2]/100,r=e*n,s=0;return r<1&&(s=(n-r)/(1-r)),[t[0],100*r,100*s]},zt.hcg.rgb=function(t){var e=t[0]/360,n=t[1]/100,r=t[2]/100;if(0===n)return[255*r,255*r,255*r];var s,i=[0,0,0],o=e%1*6,a=o%1,c=1-a;switch(Math.floor(o)){case 0:i[0]=1,i[1]=a,i[2]=0;break;case 1:i[0]=c,i[1]=1,i[2]=0;break;case 2:i[0]=0,i[1]=1,i[2]=a;break;case 3:i[0]=0,i[1]=c,i[2]=1;break;case 4:i[0]=a,i[1]=0,i[2]=1;break;default:i[0]=1,i[1]=0,i[2]=c}return s=(1-n)*r,[255*(n*i[0]+s),255*(n*i[1]+s),255*(n*i[2]+s)]},zt.hcg.hsv=function(t){var e=t[1]/100,n=e+t[2]/100*(1-e),r=0;return n>0&&(r=e/n),[t[0],100*r,100*n]},zt.hcg.hsl=function(t){var e=t[1]/100,n=t[2]/100*(1-e)+.5*e,r=0;return n>0&&n<.5?r=e/(2*n):n>=.5&&n<1&&(r=e/(2*(1-n))),[t[0],100*r,100*n]},zt.hcg.hwb=function(t){var e=t[1]/100,n=e+t[2]/100*(1-e);return[t[0],100*(n-e),100*(1-n)]},zt.hwb.hcg=function(t){var e=t[1]/100,n=1-t[2]/100,r=n-e,s=0;return r<1&&(s=(n-r)/(1-r)),[t[0],100*r,100*s]},zt.apple.rgb=function(t){return[t[0]/65535*255,t[1]/65535*255,t[2]/65535*255]},zt.rgb.apple=function(t){return[t[0]/255*65535,t[1]/255*65535,t[2]/255*65535]},zt.gray.rgb=function(t){return[t[0]/100*255,t[0]/100*255,t[0]/100*255]},zt.gray.hsl=zt.gray.hsv=function(t){return[0,0,t[0]]},zt.gray.hwb=function(t){return[0,100,t[0]]},zt.gray.cmyk=function(t){return[0,0,0,t[0]]},zt.gray.lab=function(t){return[t[0],0,0]},zt.gray.hex=function(t){var e=255&Math.round(t[0]/100*255),n=((e<<16)+(e<<8)+e).toString(16).toUpperCase();return"000000".substring(n.length)+n},zt.rgb.gray=function(t){return[(t[0]+t[1]+t[2])/3/255*100]};var $t=Bt.exports;function Xt(t){var e=function(){for(var t={},e=Object.keys($t),n=e.length,r=0;r<n;r++)t[e[r]]={distance:-1,parent:null};return t}(),n=[t];for(e[t].distance=0;n.length;)for(var r=n.pop(),s=Object.keys($t[r]),i=s.length,o=0;o<i;o++){var a=s[o],c=e[a];-1===c.distance&&(c.distance=e[r].distance+1,c.parent=r,n.unshift(a))}return e}function Ht(t,e){return function(n){return e(t(n))}}function Jt(t,e){for(var n=[e[t].parent,t],r=$t[e[t].parent][t],s=e[t].parent;e[s].parent;)n.unshift(e[s].parent),r=Ht($t[e[s].parent][s],r),s=e[s].parent;return r.conversion=n,r}var Kt=Bt.exports,Yt=function(t){for(var e=Xt(t),n={},r=Object.keys(e),s=r.length,i=0;i<s;i++){var o=r[i];null!==e[o].parent&&(n[o]=Jt(o,e))}return n},Qt={};Object.keys(Kt).forEach((function(t){Qt[t]={},Object.defineProperty(Qt[t],"channels",{value:Kt[t].channels}),Object.defineProperty(Qt[t],"labels",{value:Kt[t].labels});var e=Yt(t);Object.keys(e).forEach((function(n){var r=e[n];Qt[t][n]=function(t){var e=function(e){if(null==e)return e;arguments.length>1&&(e=Array.prototype.slice.call(arguments));var n=t(e);if("object"==typeof n)for(var r=n.length,s=0;s<r;s++)n[s]=Math.round(n[s]);return n};return"conversion"in t&&(e.conversion=t.conversion),e}(r),Qt[t][n].raw=function(t){var e=function(e){return null==e?e:(arguments.length>1&&(e=Array.prototype.slice.call(arguments)),t(e))};return"conversion"in t&&(e.conversion=t.conversion),e}(r)}))}));var Wt=Qt,Zt=Mt.exports,te=Wt,ee=[].slice,ne=["keyword","gray","hex"],re={};Object.keys(te).forEach((function(t){re[ee.call(te[t].labels).sort().join("")]=t}));var se={};function ie(t,e){if(!(this instanceof ie))return new ie(t,e);if(e&&e in ne&&(e=null),e&&!(e in te))throw new Error("Unknown model: "+e);var n,r;if(null==t)this.model="rgb",this.color=[0,0,0],this.valpha=1;else if(t instanceof ie)this.model=t.model,this.color=t.color.slice(),this.valpha=t.valpha;else if("string"==typeof t){var s=Zt.get(t);if(null===s)throw new Error("Unable to parse color from string: "+t);this.model=s.model,r=te[this.model].channels,this.color=s.value.slice(0,r),this.valpha="number"==typeof s.value[r]?s.value[r]:1}else if(t.length){this.model=e||"rgb",r=te[this.model].channels;var i=ee.call(t,0,r);this.color=ue(i,r),this.valpha="number"==typeof t[r]?t[r]:1}else if("number"==typeof t)t&=16777215,this.model="rgb",this.color=[t>>16&255,t>>8&255,255&t],this.valpha=1;else{this.valpha=1;var o=Object.keys(t);"alpha"in t&&(o.splice(o.indexOf("alpha"),1),this.valpha="number"==typeof t.alpha?t.alpha:0);var a=o.sort().join("");if(!(a in re))throw new Error("Unable to parse color from object: "+JSON.stringify(t));this.model=re[a];var c=te[this.model].labels,u=[];for(n=0;n<c.length;n++)u.push(t[c[n]]);this.color=ue(u)}if(se[this.model])for(r=te[this.model].channels,n=0;n<r;n++){var f=se[this.model][n];f&&(this.color[n]=f(this.color[n]))}this.valpha=Math.max(0,Math.min(1,this.valpha)),Object.freeze&&Object.freeze(this)}function oe(t,e,n){return(t=Array.isArray(t)?t:[t]).forEach((function(t){(se[t]||(se[t]=[]))[e]=n})),t=t[0],function(r){var s;return arguments.length?(n&&(r=n(r)),(s=this[t]()).color[e]=r,s):(s=this[t]().color[e],n&&(s=n(s)),s)}}function ae(t){return function(e){return Math.max(0,Math.min(t,e))}}function ce(t){return Array.isArray(t)?t:[t]}function ue(t,e){for(var n=0;n<e;n++)"number"!=typeof t[n]&&(t[n]=0);return t}function fe(t){return null==t}function he(t){return"object"==typeof t&&!!t}function le(t){return t/Math.PI*180}function de(t){return Math.sign?Math.sign(t):0===(t=+t)||isNaN(t)?Number(t):t>0?1:-1}ie.prototype={toString:function(){return this.string()},toJSON:function(){return this[this.model]()},string:function(t){var e=this.model in Zt.to?this:this.rgb(),n=1===(e=e.round("number"==typeof t?t:1)).valpha?e.color:e.color.concat(this.valpha);return Zt.to[e.model](n)},percentString:function(t){var e=this.rgb().round("number"==typeof t?t:1),n=1===e.valpha?e.color:e.color.concat(this.valpha);return Zt.to.rgb.percent(n)},array:function(){return 1===this.valpha?this.color.slice():this.color.concat(this.valpha)},object:function(){for(var t={},e=te[this.model].channels,n=te[this.model].labels,r=0;r<e;r++)t[n[r]]=this.color[r];return 1!==this.valpha&&(t.alpha=this.valpha),t},unitArray:function(){var t=this.rgb().color;return t[0]/=255,t[1]/=255,t[2]/=255,1!==this.valpha&&t.push(this.valpha),t},unitObject:function(){var t=this.rgb().object();return t.r/=255,t.g/=255,t.b/=255,1!==this.valpha&&(t.alpha=this.valpha),t},round:function(t){return t=Math.max(t||0,0),new ie(this.color.map(function(t){return function(e){return function(t,e){return Number(t.toFixed(e))}(e,t)}}(t)).concat(this.valpha),this.model)},alpha:function(t){return arguments.length?new ie(this.color.concat(Math.max(0,Math.min(1,t))),this.model):this.valpha},red:oe("rgb",0,ae(255)),green:oe("rgb",1,ae(255)),blue:oe("rgb",2,ae(255)),hue:oe(["hsl","hsv","hsl","hwb","hcg"],0,(function(t){return(t%360+360)%360})),saturationl:oe("hsl",1,ae(100)),lightness:oe("hsl",2,ae(100)),saturationv:oe("hsv",1,ae(100)),value:oe("hsv",2,ae(100)),chroma:oe("hcg",1,ae(100)),gray:oe("hcg",2,ae(100)),white:oe("hwb",1,ae(100)),wblack:oe("hwb",2,ae(100)),cyan:oe("cmyk",0,ae(100)),magenta:oe("cmyk",1,ae(100)),yellow:oe("cmyk",2,ae(100)),black:oe("cmyk",3,ae(100)),x:oe("xyz",0,ae(100)),y:oe("xyz",1,ae(100)),z:oe("xyz",2,ae(100)),l:oe("lab",0,ae(100)),a:oe("lab",1),b:oe("lab",2),keyword:function(t){return arguments.length?new ie(t):te[this.model].keyword(this.color)},hex:function(t){return arguments.length?new ie(t):Zt.to.hex(this.rgb().round().color)},rgbNumber:function(){var t=this.rgb().color;return(255&t[0])<<16|(255&t[1])<<8|255&t[2]},luminosity:function(){for(var t=this.rgb().color,e=[],n=0;n<t.length;n++){var r=t[n]/255;e[n]=r<=.03928?r/12.92:Math.pow((r+.055)/1.055,2.4)}return.2126*e[0]+.7152*e[1]+.0722*e[2]},contrast:function(t){var e=this.luminosity(),n=t.luminosity();return e>n?(e+.05)/(n+.05):(n+.05)/(e+.05)},level:function(t){var e=this.contrast(t);return e>=7.1?"AAA":e>=4.5?"AA":""},isDark:function(){var t=this.rgb().color;return(299*t[0]+587*t[1]+114*t[2])/1e3<128},isLight:function(){return!this.isDark()},negate:function(){for(var t=this.rgb(),e=0;e<3;e++)t.color[e]=255-t.color[e];return t},lighten:function(t){var e=this.hsl();return e.color[2]+=e.color[2]*t,e},darken:function(t){var e=this.hsl();return e.color[2]-=e.color[2]*t,e},saturate:function(t){var e=this.hsl();return e.color[1]+=e.color[1]*t,e},desaturate:function(t){var e=this.hsl();return e.color[1]-=e.color[1]*t,e},whiten:function(t){var e=this.hwb();return e.color[1]+=e.color[1]*t,e},blacken:function(t){var e=this.hwb();return e.color[2]+=e.color[2]*t,e},grayscale:function(){var t=this.rgb().color,e=.3*t[0]+.59*t[1]+.11*t[2];return ie.rgb(e,e,e)},fade:function(t){return this.alpha(this.valpha-this.valpha*t)},opaquer:function(t){return this.alpha(this.valpha+this.valpha*t)},rotate:function(t){var e=this.hsl(),n=e.color[0];return n=(n=(n+t)%360)<0?360+n:n,e.color[0]=n,e},mix:function(t,e){if(!t||!t.rgb)throw new Error(\'Argument to "mix" was not a Color instance, but rather an instance of \'+typeof t);var n=t.rgb(),r=this.rgb(),s=void 0===e?.5:e,i=2*s-1,o=n.alpha()-r.alpha(),a=((i*o==-1?i:(i+o)/(1+i*o))+1)/2,c=1-a;return ie.rgb(a*n.red()+c*r.red(),a*n.green()+c*r.green(),a*n.blue()+c*r.blue(),n.alpha()*s+r.alpha()*(1-s))}},Object.keys(te).forEach((function(t){if(-1===ne.indexOf(t)){var e=te[t].channels;ie.prototype[t]=function(){if(this.model===t)return new ie(this);if(arguments.length)return new ie(arguments,t);var n="number"==typeof arguments[e]?e:this.valpha;return new ie(ce(te[this.model][t].raw(this.color)).concat(n),t)},ie[t]=function(n){return"number"==typeof n&&(n=ue(ee.call(arguments),e)),new ie(n,t)}}}));const ye=[1,1,1,1,2,2,3,0];function me(t){const e=t.length;let n="";for(let r=0;r<e;){let s=t[r++];if(128&s){let n=ye[s>>3&7];if(!(64&s)||!n||r+n>e)return null;for(s&=63>>n;n>0;n-=1){const e=t[r++];if(128!=(192&e))return null;s=s<<6|63&e}}n+=String.fromCharCode(s)}return n}new Array(3),new Array(3);const be=[1/6378137,1/6378137,1/6356752.314245179],pe=[1/40680631590769,1/40680631590769,1/40408299984661.445],we=new Array(3),ge=new Array(3),ve=new Array(3);function Me(t,e){const n=pe,r=function(t,e,n,r,s){const i=e[0],o=e[1],a=e[2],c=n[0],u=n[1],f=n[2],h=i*i*c*c,l=o*o*u*u,d=a*a*f*f,y=h+l+d,m=Math.sqrt(1/y),p=b(Te,e,m);if(y<s)return isFinite(m)?p:void 0;const w=r[0],g=r[1],v=r[2],M=Ae;M[0]=p[0]*w*2,M[1]=p[1]*g*2,M[2]=p[2]*v*2;let T,A,_,O,x,S,I,k,E,C,U,F=(1-m)*_e(e)/(.5*_e(M)),N=0;do{F-=N,_=1/(1+F*w),O=1/(1+F*g),x=1/(1+F*v),S=_*_,I=O*O,k=x*x,E=S*_,C=I*O,U=k*x,T=h*S+l*I+d*k-1,A=h*E*w+l*C*g+d*U*v;N=T/(-2*A)}while(Math.abs(T)>1e-12);return t[0]=i*_,t[1]=o*O,t[2]=a*x,t}(we,e,be,n,.1);let s=T(ge,r,n);s=function(t,e){const n=e[0],r=e[1],s=e[2];let i=n*n+r*r+s*s;i>0&&(i=Math.sqrt(i),t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i);return t}(s,s);const i=M(ve,e,r),o=Math.atan2(s[1],s[0]),a=Math.asin(s[2]),c=de(w(i,e))*_e(i);return t[0]=le(o),t[1]=le(a),t[2]=c,t}const Te=new Array(3),Ae=new Array(3);function _e(t){return f(t)}function Oe(t,e,n,r){n=n||0,r=r||n;const s=Math.abs(t-e);return s<=r||s<=n*Math.max(Math.abs(t),Math.abs(e))}function xe(t,e){let n="";for(let r=0;r<4;r++){const s=t.getUint8(e+r);n+=String.fromCharCode(s)}return n}const Se="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function Ie(t,e,n){const r=new Uint8Array(t,e,n);return Se?JSON.parse(Se.decode(r)):JSON.parse(me(r))}function ke(t,e,n){const r=new Uint8Array(t,e,n);return Se?JSON.parse(Se.decode(r)):JSON.parse(me(r))}function Ee(t,e,n){return{offset:e,byteLength:n}}function Ce(t,e,n,r){const{byteOffset:s,componentType:i,type:o}=t,{ctor:a,type:c}=function(t){return Ne[t]}(i||"UNSIGNED_SHORT"),u=function(t){if(!t)return 1;return Fe[t]}(o);return{byteStride:0,byteOffset:s+n,itemSize:u,count:r*u,componentType:c,array:new a(e,n+s,r*u)}}function Ue(t,e,n,r){const s=Ce(t,e,n,r);return s.array.buffer.byteLength!==e.byteLength&&(s.array=s.array.slice()),s}const Fe={"SCALAR":1,"VEC2":2,"VEC3":3,"VEC4":4};const Ne={"BYTE":{ctor:Int8Array,type:5120,name:"Int8Array"},"UNSIGNED_BYTE":{ctor:Uint8Array,type:5121,name:"Uint8Array"},"SHORT":{ctor:Int16Array,type:5122,name:"Int16Array"},"UNSIGNED_SHORT":{ctor:Uint16Array,type:5123,name:"Uint16Array"},"INT":{ctor:Int32Array,type:5124,name:"Int32Array"},"UNSIGNED_INT":{ctor:Uint32Array,type:5125,name:"Uint32Array"},"FLOAT":{ctor:Float32Array,type:5126,name:"Float32Array"},"DOUBLE":{ctor:Float64Array,type:5126,name:"Float64Array"}};function Pe(t){for(const e in Ne)if(t===Ne[e].ctor)return Ne[e].type;throw new Error("unrecognized ctor:"+t)}function Be(t,e,n,r){const s=t,i=e.length/3;for(let t=0;t<i;t++)s[3*t]=e[3*t]/65535*r[0]+n[0],s[3*t+1]=e[3*t+1]/65535*r[1]+n[1],s[3*t+2]=e[3*t+2]/65535*r[2]+n[2];return s}function De(t,e,n){const r=t.getUint32(12,!0),s=t.getUint32(16,!0),i=t.getUint32(20,!0),o=t.getUint32(24,!0),a=t.buffer;let c,u={},f={},h=null;r>0&&(u=Ie(a,e,r),e+=r),s>0&&(c=function(t,e,n){return{offset:e,byteLength:n}}(0,e,s),e+=s),i>0&&(f=ke(a,e,i),e+=i);const l=Ee(0,e,o);return h=a.slice(l.offset,l.offset+l.byteLength),n.push(h),{featureTable:u,featureTableBin:c,batchTable:f,batchTableBin:h}}const Re={up:{south:"east",north:"west",west:"south",east:"north"},down:{south:"west",north:"east",west:"north",east:"south"},south:{up:"west",down:"east",west:"down",east:"up"},north:{up:"east",down:"west",west:"up",east:"down"},west:{up:"north",down:"south",north:"down",south:"up"},east:{up:"south",down:"north",north:"up",south:"down"}},Le={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},ze={},je={east:[],north:[],up:[],west:[],south:[],down:[]};let Ve=[],qe=[],Ge=[];const $e=[0,0,0];const Xe=function(t,e){const n=Re[t][e];let r;const s=t+e;return ze[s]?r=ze[s]:(r=function(r,s,i){if(function(t,e){var n=t[0],r=t[1],s=t[2],i=e[0],o=e[1],a=e[2];return Math.abs(n-i)<=1e-6*Math.max(1,Math.abs(n),Math.abs(i))&&Math.abs(r-o)<=1e-6*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(s-a)<=1e-6*Math.max(1,Math.abs(s),Math.abs(a))}(r,$e))l(Ve,Le[t]),l(qe,Le[e]),l(Ge,Le[n]);else if(Oe(r[0],0,1e-14)&&Oe(r[1],0,1e-14)){const s=de(r[2]);l(Ve,Le[t]),"east"!==t&&"west"!==t&&b(Ve,Ve,s),l(qe,Le[e]),"east"!==e&&"west"!==e&&b(qe,qe,s),l(Ge,Le[n]),"east"!==n&&"west"!==n&&b(Ge,Ge,s)}else{!function(t,e){m(e,t,pe),p(e,e)}(r,je.up);const s=je.up,i=je.east;i[0]=-r[1],i[1]=r[0],i[2]=0,p(je.east,i),g(je.north,s,i),b(je.down,je.up,-1),b(je.west,je.east,-1),b(je.south,je.north,-1),Ve=je[t],qe=je[e],Ge=je[n]}return i[0]=Ve[0],i[1]=Ve[1],i[2]=Ve[2],i[3]=0,i[4]=qe[0],i[5]=qe[1],i[6]=qe[2],i[7]=0,i[8]=Ge[0],i[9]=Ge[1],i[10]=Ge[2],i[11]=0,i[12]=r[0],i[13]=r[1],i[14]=r[2],i[15]=1,i},ze[s]=r),r}("east","north"),He={5120:Int8Array,5122:Int16Array,5124:Int32Array,5121:Uint8Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};function Je(t){for(const e in He)if(t===He[e])return+e;throw new Error("unrecognized ctor:"+t)}\n/*!\n * @maptalks/gl v0.95.6\n * LICENSE : UNLICENSED\n * (c) 2016-2024 maptalks.com\n */const Ke=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof undefined)return global;throw new Error("unable to locate global object")},Ye=Ke(),Qe=Ye.gl_trans__coders=Ye.gl_trans__coders||{};Qe.inject=function(t){const e=t.toString(),n=e.indexOf("{")+1,r=e.substring(0,n),s=Ye.gl_trans__coders=Ye.gl_trans__coders||{};let i=`${r}\\n const _____getGlobal = ${Ke.toString()};\\n const g___lobals = _____getGlobal()\\n const tran_____scoders = g___lobals[\'gl_trans__coders\'] = g___lobals[\'gl_trans__coders\'] || {};`;for(const t in s)"inject"!==t&&"getTranscoder"!==t&&"registerTranscoder"!==t&&(i+=\'tran_____scoders["\'+t+\'"] =\'+s[t].toString()+"\\n;");return i+="\\n"+e.substring(r.length),i},Qe.registerTranscoder=function(t,e){Qe[t]=e},Qe.getTranscoder=function(t){return Qe[t]};let We=null;function Ze(){return We||(We={"image/crn":Qe.crn&&Qe.crn(),"image/ktx2":Qe.ktx2&&Qe.ktx2(),"image/cttf":Qe.ktx2&&Qe.ktx2(),"draco":Qe.draco&&Qe.draco()}),We}class tn{constructor(t,e,n){this.s=t,this.et=e||dt,this.i=n,this.nt=Ze()}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.rt(t,e,n,r,s)):J.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.rt(t,s,n,r)})}rt(t,e,n,r,s){const i=s&&s.maxTextureSize,o=this.st(e,n,r,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.et(a,o.glb,{transferable:!0,requestImage:this.s,decoders:this.nt,supportedFormats:this.i,maxTextureSize:i});return c.load({skipAttributeTransform:!1}).then(e=>{e.url=`${t}-${n}-${r}`;const s=c.transferables;for(let t=0;t<o.transferables.length;t++)s.indexOf(o.transferables[t])<0&&s.push(o.transferables[t]);return{magic:"b3dm",count:o.count,transferables:s,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,gltf:e}})}st(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported b3dm version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in b3dm header is inconsistent with b3dm\'s byte length, url: "+r;return console.warn(t),{error:t}}let o,a=s.getUint32(12,!0),c=s.getUint32(16,!0),u=s.getUint32(20,!0),f=s.getUint32(24,!0),h=28+e;u>=570425344?(h-=8,o=a,u=c,f=0,a=0,c=0):f>=570425344&&(h-=4,o=u,u=a,f=c,a=0,c=0);const l=[t];let d,y,m;if(a>0?(d=Ie(t,h,a),h+=a,o=d.BATCH_LENGTH):d={"BATCH_LENGTH":o},c>0&&(h+=c),u>0&&(y=ke(t,h,u),h+=u,f>0)){const e=Ee(0,h,f);m=t.slice(e.offset,e.offset+e.byteLength),h+=f,l.push(m)}const b=d.BATCH_LENGTH,p={};if(d&&d.BATCH_ID){p.BATCH_ID=Ue(d.BATCH_ID,t,(void 0).offset,b);const e=p.BATCH_ID.array&&p.BATCH_ID.array.buffer;e&&l.indexOf(e)<0&&l.push(e)}return{count:o,transferables:l,featureTable:d,batchTable:y,batchTableBin:m,b3dm:p,glb:{buffer:t,byteOffset:h,byteLength:s.byteLength+s.byteOffset-h}}}it(){return null}}class en{constructor(t,e,n,r){this.s=t,this.et=e||dt,this.i=n,this.nt=Ze(),this.ot=r}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.rt(t,e,n,r,s)):J.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.rt(t,s,n,r)})}rt(t,e,n,r,s){return this.ct(t,e,n,r,s).then(({gltf:s,transferables:i})=>{const o=this.ut(e,n,r,t);if(o.error)return Promise.resolve(o);for(let t=0;t<i.length;t++)-1===o.transferables.indexOf(i[t])&&o.transferables.push(i[t]);return delete s.transferables,Promise.resolve({magic:"i3dm",count:o.count,transferables:o.transferables,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,i3dm:o.i3dm,gltf:s})})}ct(t,e,n,r,s){const i=s&&s.maxTextureSize,o={transferable:!0,requestImage:this.s,decoders:this.nt,supportedFormats:this.i,maxTextureSize:i},a=new DataView(e,n,r),c=32+a.getUint32(12,!0)+a.getUint32(16,!0)+a.getUint32(20,!0)+a.getUint32(24,!0);if(0===a.getUint32(28,!0)){let r=me(new Uint8Array(e,c+n,a.byteLength-c));-1==r.indexOf("://")&&(r=t.substring(0,t.lastIndexOf("/"))+"/"+r);return r.indexOf(".glb")>0?J.getArrayBuffer(r,{}).then(t=>this.ft(r,{buffer:t.data,byteOffset:0},o)):J.getJSON(r,{}).then(t=>this.ft(r,t,o))}{const r={buffer:e,byteOffset:c+n,byteLength:a.byteLength-c};return this.ft(t,r,o)}}ft(t,e,n){const r=t.substring(0,t.lastIndexOf("/")),s=new this.et(r,e,n);return s.load({skipAttributeTransform:!0}).then(n=>{let r=0,i=0;return e.buffer&&(r=e.byteOffset||0,i=e.byteLength||0),n.url=`${t}-${r}-${i}`,{transferables:s.transferables,gltf:n}})}ut(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported pnts version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in pnts header is inconsistent with pnts\'s byte length, url: "+r;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:u,batchTableBin:f}=De(s,32+e,o),h={},l=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;h.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(h.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,n=a.QUANTIZED_VOLUME_SCALE,{byteOffset:r}=a.POSITION_QUANTIZED;h.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:l,componentType:5126,array:this.ht(new Uint16Array(t,r+c.offset,3*l),e,n)},o.push(h.POSITION.array.buffer)}if(a.BATCH_ID){h.BATCH_ID=Ue(a.BATCH_ID,t,c.offset,l);const e=h.BATCH_ID.array&&h.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;h.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(h.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,h.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(h.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;h.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:this.lt(new Uint16Array(t,e+c.offset,2*l))},o.push(h.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,h.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:this.lt(new Uint16Array(t,e+c.offset,2*l))},o.push(h.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;h.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,l).slice()},o.push(h.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;h.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(h.SCALE_NON_UNIFORM.array.buffer)}return{count:l,batchTable:u,batchTableBin:f,featureTable:a,i3dm:h,transferables:o}}lt(t){const e=t.length/2,n=new Float32Array(3*e),r=[];for(let s=0;s<e;s++)nn(r,t[2*s],t[2*s+1],65535),n[3*s]=r[0],n[3*s+1]=r[1],n[3*s+2]=r[2];return n}ht(t,e,n){return Be(new Float32Array(t.length),t,e,n)}it(){return null}}function nn(t,e,n,r){if(t[0]=rn(e,r),t[1]=rn(n,r),t[2]=1-(Math.abs(t[0])+Math.abs(t[1])),t[2]<0){const e=t[0];t[0]=(1-Math.abs(t[1]))*sn(e),t[1]=(1-Math.abs(e))*sn(t[1])}return p(t,t)}function rn(t,e){return function(t,e,n){return t<e?e:t>n?n:t}(t,0,e=function(t,e){if(null!=t)return t;return e}(e,255))/e*2-1}function sn(t){return t<0?-1:1}class on{constructor(){}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.rt(t,e,n,r)):J.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.rt(t,s,n,r)})}rt(t,e,n,r){return this.dt(e,n,r,t).then(t=>t.error?t:{magic:"pnts",count:t.count,transferables:t.transferables,featureTable:t.featureTable,batchTable:t.batchTable,batchTableBin:t.batchTableBin,pnts:t.pnts})}dt(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported pnts version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in pnts header is inconsistent with pnts\'s byte length, url: "+r;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:u,batchTableBin:f}=De(s,e+28,o),h=a.QUANTIZED_VOLUME_OFFSET,l=a.QUANTIZED_VOLUME_SCALE,d=a.POINTS_LENGTH;let y,m={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){m=a.extensions["3DTILES_draco_point_compression"],y=new DataView(t,m.byteOffset+c.offset,m.byteLength);const e={attributes:m.properties,useUniqueIDs:!1};return this.yt||(this.yt=Ze().draco),this.yt(y,e).then(e=>{const n=e.attributes;!a.POSITION&&!a.POSITION_QUANTIZED||n.POSITION||n.POSITION_QUANTIZED||(n.POSITION=a.POSITION,n.POSITION_QUANTIZED=a.POSITION_QUANTIZED),!(a.RGB||a.RGBA||a.RGB565)||n.RGB||n.RGBA||n.RGB565||(n.RGB=a.RGB,n.RGBA=a.RGBA,n.RGB565=a.RGB565),!a.NORMAL&&!a.NORMAL_OCT16P||n.NORMAL||n.NORMAL_OCT16P||(n.NORMAL=a.NORMAL,n.NORMAL_OCT16P=a.NORMAL_OCT16P);const r=this.bt(t,e.attributes,c.offset,d,o,h,l);if(e.attributes.BATCH_ID){const t=e.attributes.BATCH_ID.array;r.BATCH_ID={byteStride:0,byteOffset:0,itemSize:1,count:t.length,componentType:Pe(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(u).length){a.BATCH_ID?r.BATCH_ID=Ue(a.BATCH_ID,t,c.offset,d):r.BATCH_ID=an(d);const e=r.BATCH_ID.array&&r.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return{count:d,batchTable:u,batchTableBin:f,featureTable:a,pnts:r,transferables:o}})}const b=this.bt(t,a,c.offset,d,o,h,l);if(a.BATCH_ID||Object.keys(u).length){a.BATCH_ID?b.BATCH_ID=Ue(a.BATCH_ID,t,c.offset,d):b.BATCH_ID=an(d);const e=b.BATCH_ID.array&&b.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:d,batchTable:u,batchTableBin:f,featureTable:a,pnts:b,transferables:o})}bt(t,e,n,r,s,i,o){const a={};if(e.POSITION){let{byteOffset:i,array:o}=e.POSITION;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r*4);o=new Float32Array(e)}a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:o},s.push(o.buffer)}else if(e.POSITION_QUANTIZED){let{byteOffset:c}=e.POSITION_QUANTIZED;const{array:u}=e.POSITION_QUANTIZED;c=c||0;const f=u?0:n;a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:this.ht(u||new Uint16Array(t,c+f,3*r),i,o)},s.push(a.POSITION.array.buffer)}if(e.RGBA){let{byteOffset:i,array:o}=e.RGBA;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+4*r);o=new Uint8Array(e)}a.RGBA={byteStride:0,byteOffset:0,itemSize:4,count:r,componentType:5121,array:o},s.push(o.buffer)}else if(e.RGB){let{byteOffset:i,array:o}=e.RGB;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r);o=new Uint8Array(e)}a.RGB={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5121,array:o},s.push(o.buffer)}else if(e.RGB565){let{byteOffset:i,array:o}=e.RGB565;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+2*r);o=new Uint16Array(e)}a.RGB565={byteStride:0,byteOffset:0,itemSize:1,count:r,componentType:5123,array:o},s.push(o.buffer)}if(e.NORMAL){let{byteOffset:i,array:o}=e.NORMAL;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r*4);o=new Float32Array(e)}a.NORMAL={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:o},s.push(o.buffer)}else if(e.NORMAL_OCT16P){let{byteOffset:i,array:o}=e.NORMAL_OCT16P;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+2*r);o=new Uint8Array(e)}a.NORMAL_OCT16P={byteStride:0,byteOffset:0,itemSize:2,count:r,componentType:5121,array:o},s.push(o.buffer)}return a}ht(t,e,n){return Be(new Float32Array(t.length),t,e,n)}it(){return null}}function an(t){const e=(n=t)<256?Uint8Array:n<65536?Uint16Array:Uint32Array;var n;const r=new e(t);for(let e=0;e<t;e++)r[e]=e;return{byteStride:0,byteOffset:0,itemSize:1,count:t,componentType:Pe(e),array:r}}class cn{constructor(t,e,n,r){this.i=n,this.s=t,this.et=e||dt,this.ot=r}load(t,e,n=0,r=0,s){return e?this.rt(t,e,n,r,s):J.getArrayBuffer(t,{}).then(e=>{const s=e.data;return this.rt(t,s,n,r)})}rt(t,e,n,r,s){r||(r=e.byteLength);const i=this.pt(e,t,n,r),o=[];for(let n=0;n<i.length;n++){let r;if("b3dm"===i[n].magic)r=new tn(this.s,this.et,this.i);else if("i3dm"===i[n].magic)r=new en(this.s,this.et,this.i,this.ot);else if("pnts"===i[n].magic)r=new on;else{if("cmpt"!==i[n].magic){console.warn("Unsupported magic in CMPT tile:",i[n].magic);continue}r=new cn(this.s,this.et,this.i,this.ot)}o.push(r.load(t,e,i[n].offset,i[n].byteLength,s).then(t=>t))}return Promise.all(o).then(t=>({magic:"cmpt",tiles:t}))}pt(t,e,n,r){const s=new DataView(t,n,r),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported cmpt version: "+i+", url:"+e;return console.warn(t),{error:t}}if(16===s.byteLength)return[];const o=[],a=s.getUint32(12,!0);let c=16;for(let e=0;e<a;e++){const e=xe(s,c),r=s.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+n,byteLength:r}),c+=r}return o}}function un(t,e){if(t.scenes&&t.scenes.length)for(let n=0,r=t.scenes.length;n<r;n++){const r=t.scenes[n].nodes;for(let n=0,s=r.length;n<s;n++){const s=[];bn(r[n],s,t,e)}}}const fn=[],hn=[],ln=[],dn=[0,0,0],yn=S([]),mn=[1,1,1];function bn(t,e,n,r){const c=e.slice(0);if(t.matrix)c.push(t.matrix);else if(t.rotation||t.translation||t.scale){const e=i(fn,t.translation||dn),n=a(hn,t.rotation||yn),r=o(ln,t.scale||mn);s(r,n,r);const u=s([],e,r);c.push(u)}if(t.children&&t.children.length)for(let e=0,s=t.children.length;e<s;e++)bn(t.children[e],c,n,r);if(void 0!==t.mesh){const e=t.mesh,s=n.meshes[e];if(s){const t=c.slice(0),i=s.primitives;for(let s=0,o=i.length;s<o;s++){const o=i[s];o&&(o.matrices=t,r(o,e,s,n))}}}}function pn(t,e){let{byteOffset:n,byteStride:r,count:s}=t;const{componentType:i,itemSize:o}=t,a=t.array.buffer,c=i?dt.getTypedArrayCtor(i):t.array.constructor;if(n=void 0===n?t.array.byteOffset:n,r=r||0,s=s||t.array.length/o,(!r||r===o*c.BYTES_PER_ELEMENT)&&n%c.BYTES_PER_ELEMENT==0){const t=new c(a,n,s*o);for(let r=0;r<s*o;r+=o){e(new c(t.buffer,n+r*c.BYTES_PER_ELEMENT,o),r/o)}return}const u=new Uint8Array(o*c.BYTES_PER_ELEMENT);r||(r=o*c.BYTES_PER_ELEMENT);for(let t=0;t<s;t++){const s=new Uint8Array(a,r*t+n,o*c.BYTES_PER_ELEMENT);u.set(s);e(new c(u.buffer),t),s.set(u)}}var wn=An("DXT1"),gn=An("DXT3"),vn=An("DXT5"),Mn=An("DX10"),Tn=function(t){var e,n,r=new Int32Array(t,0,31);if(542327876!==r[0])throw new Error("Invalid magic number in DDS header");if(4&!r[20])throw new Error("Unsupported format, must contain a FourCC code");var s=r[21];switch(s){case wn:e=8,n="dxt1";break;case gn:e=16,n="dxt3";break;case vn:e=16,n="dxt5";break;case 116:n="rgba32f";break;case Mn:var i=new Uint32Array(t.slice(128,148));n=i[0];var o=i[1];if(i[2],i[3],i[4],3!==o||2!==n)throw new Error("Unsupported DX10 texture format "+n);n="rgba32f";break;default:throw new Error("Unsupported FourCC code: "+(a=s,String.fromCharCode(255&a,a>>8&255,a>>16&255,a>>24&255)))}var a;var c=r[2],u=1;131072&c&&(u=Math.max(1,r[7]));var f=!1;512&r[28]&&(f=!0);var h,l=r[4],d=r[3],y=r[1]+4,m=l,b=d,p=[];s===Mn&&(y+=20);if(f)for(var w=0;w<6;w++){if("rgba32f"!==n)throw new Error("Only RGBA32f cubemaps are supported");l=m,d=b;for(var g=Math.log(l)/Math.log(2)+1,v=0;v<g;v++)h=l*d*16,p.push({offset:y,length:h,shape:[l,d]}),v<u&&(y+=h),l=Math.floor(l/2),d=Math.floor(d/2)}else for(v=0;v<u;v++)h=Math.max(4,l)/4*Math.max(4,d)/4*e,p.push({offset:y,length:h,shape:[l,d]}),y+=h,l=Math.floor(l/2),d=Math.floor(d/2);return{shape:[m,b],images:p,format:n,flags:c,cubemap:f}};function An(t){return t.charCodeAt(0)+(t.charCodeAt(1)<<8)+(t.charCodeAt(2)<<16)+(t.charCodeAt(3)<<24)}var _n=Math.abs,On=Math.sin,xn=Math.cos,Sn=Math.tan,In=Math.atan,kn=Math.atan2,En=Math.sqrt,Cn=Math.log,Un=Math.hypot,Fn=Math.sinh,Nn=Math.cosh;function Pn(t){var e,n,r,s,i,o,a=[],c=[],u=[],f=[];function h(t,e){for(var n,r=2*xn(2*e),s=t.length-1,i=t[s],o=0;--s>=0;)n=r*i-o+t[s],o=i,i=n;return e+n*On(2*e)}function l(t,e,n){for(var r,s,i=On(e),o=xn(e),a=Fn(n),c=Nn(n),u=2*o*c,f=-2*i*a,h=t.length-1,l=t[h],d=0,y=0,m=0;--h>=0;)r=y,s=d,l=u*(y=l)-r-f*(d=m)+t[h],m=f*y-s+u*d;return[(u=i*c)*l-(f=o*a)*m,u*m+f*l]}t.es,i=s=(r=t.es/(1+En(1-t.es)))/(2-r),a[0]=s*(2+s*(-2/3+s*(s*(116/45+s*(26/45+s*(-2854/675)))-2))),c[0]=s*(s*(2/3+s*(4/3+s*(-82/45+s*(32/45+s*(4642/4725)))))-2),i*=s,a[1]=i*(7/3+s*(s*(-227/45+s*(2704/315+s*(2323/945)))-1.6)),c[1]=i*(5/3+s*(-16/15+s*(-13/9+s*(904/315+s*(-1522/945))))),i*=s,a[2]=i*(56/15+s*(-136/35+s*(-1262/105+s*(73814/2835)))),c[2]=i*(-26/15+s*(34/21+s*(1.6+s*(-12686/2835)))),i*=s,a[3]=i*(4279/630+s*(-332/35+s*(-399572/14175))),c[3]=i*(1237/630+s*(s*(-24832/14175)-2.4)),i*=s,a[4]=i*(4174/315+s*(-144838/6237)),c[4]=i*(-734/315+s*(109598/31185)),i*=s,a[5]=i*(601676/22275),c[5]=i*(444337/155925),i=s*s,e=t.k0/(1+s)*(1+i*(1/4+i*(1/64+i/256))),u[0]=s*(s*(2/3+s*(-37/96+s*(1/360+s*(81/512+s*(-96199/604800)))))-.5),f[0]=s*(.5+s*(-2/3+s*(5/16+s*(41/180+s*(-127/288+s*(7891/37800)))))),u[1]=i*(-1/48+s*(-1/15+s*(437/1440+s*(-46/105+s*(1118711/3870720))))),f[1]=i*(13/48+s*(s*(557/1440+s*(281/630+s*(-1983433/1935360)))-.6)),i*=s,u[2]=i*(-17/480+s*(37/840+s*(209/4480+s*(-5569/90720)))),f[2]=i*(61/240+s*(-103/140+s*(15061/26880+s*(167603/181440)))),i*=s,u[3]=i*(-4397/161280+s*(11/504+s*(830251/7257600))),f[3]=i*(49561/161280+s*(-179/168+s*(6601661/7257600))),i*=s,u[4]=i*(-4583/161280+s*(108847/3991680)),f[4]=i*(34729/80640+s*(-3418889/1995840)),i*=s,u[5]=i*(-20648693/638668800),f[5]=.6650675310896665*i,o=h(c,t.phi0),n=-e*(o+function(t,e){var n,r=2*xn(e),s=t.length-1,i=t[s],o=0;for(;--s>=0;)n=r*i-o+t[s],o=i,i=n;return On(e)*n}(f,2*o)),t.fwd=function(t,r){var s,i,o,a,u,d=t.phi,y=t.lam;d=h(c,d),s=On(d),i=xn(d),a=On(y),o=xn(y),d=kn(s,o*i),y=kn(a*i,Un(s,i*o)),y=function(t){var e=_n(t);return e=function(t){var e=1+t,n=e-1;return 0===n?t:t*Cn(e)/n}(e*(1+e/(Un(1,e)+1))),t<0?-e:e}(Sn(y)),u=l(f,2*d,2*y),d+=u[0],y+=u[1],_n(y)<=2.623395162778?(r.y=e*d+n,r.x=e*y):r.x=r.y=1/0},t.inv=function(t,r){var s,i,o,c,f,d=t.y,y=t.x;d=(d-n)/e,_n(y/=e)<=2.623395162778?(f=l(u,2*d,2*y),d+=f[0],y+=f[1],y=In(Fn(y)),s=On(d),i=xn(d),c=On(y),o=xn(y),y=kn(c,o*i),d=kn(s*o,Un(c,o*i)),r.phi=h(a,d),r.lam=y):r.phi=r.lam=1/0}}const Bn=Math.PI/180,Dn=6378137*Math.PI/180,Rn={};function Ln(t,e,n,r){if("EPSG:3857"===n)return function(t,e){const n=85.0511287798,r=e[0],s=Math.max(Math.min(n,e[1]),-n);let i;i=0===s?0:Math.log(Math.tan((90+s)*Bn/2))/Bn;return t[0]=r*Dn,t[1]=i*Dn,t}(t,e);if(!n||"EPSG:9807"!==n.code&&"Traverse_Mercator"!==n.code){if("EPSG:4326"===n||"EPSG:4490"===n||"identity"===n)return zn(t,e);if("baidu"===n)return zn(t,e);throw new Error("unsupported projection:"+n)}{if(!(!r||4326===r.wkid))return function(t,e){return t[0]=e[0],t[1]=e[1],t}(t,e);const s=JSON.stringify(n);let i=Rn[s];return i||(i=Rn[s]=function(t){const e={a:6378137,es:.0066943799901413165,x0:fe(t.falseEasting)?5e5:t.falseEasting,y0:fe(t.falseNorthing)?0:t.falseNorthing,k0:t.scaleFactor||.9996,lam0:(t.centralMeridian||0)*jn,phi0:(t.latitudeOfOrigin||0)*jn,originLam0:t.startLongtitude||0,originPhi0:t.startLatitude||0};Pn(e);const n={lam:0,phi:0},r={};let s=0,i=0;(e.originLam0||e.originPhi0)&&(n.lam=e.originLam0*jn-e.lam0,n.phi=e.originPhi0*jn,e.fwd(n,r),s=e.a*r.x+e.x0,i=e.a*r.y+e.y0);return{project:function(t,o){n.lam=t[0]*jn-e.lam0,n.phi=t[1]*jn,e.fwd(n,r);const a=e.a*r.x+e.x0-s,c=e.a*r.y+e.y0-i;return o[0]=a,o[1]=c,o}}}(n)),i.project(e,t)}}function zn(t,e){return t[0]=e[0],t[1]=e[1],t}const jn=.017453292519943295;const Vn=r([]),qn=Ze().draco,Gn=Ze().ktx2,$n={"pbrMetallicRoughness":{"baseColorFactor":[.5,.5,.5,1],"metallicFactor":0,"roughnessFactor":.5}},Xn={"position":{name:"POSITION",accessor:{"componentType":5126,"type":"VEC3"}},"normal":{name:"NORMAL",accessor:{"componentType":5126,"type":"VEC3"}},"uv0":{name:"TEXCOORD_0",accessor:{"componentType":5126,"type":"VEC2"}},"color":{name:"COLOR_0",accessor:{"componentType":5121,"type":"VEC4"}},"uv-region":{name:"uvRegion",accessor:{"componentType":5123,"type":"VEC4"}},"feature-index":{name:"_BATCHID",accessor:{"componentType":5125,"type":"SCALAR"}},"faceRange":{name:"faceRange",accessor:{"componentType":5125,"type":"VEC2"}}};function Hn(t,e,n,s,i,o){const a=[],c=[],u=[];for(let e=0;e<t.meshes.length;e++){const{geometry:n,material:r}=t.meshes[e],s=J.getArrayBuffer(n.url,o);s.xhr.url=n.url,u.push(s.xhr);const i=s.then(t=>({buffer:t}));a.push(i);const f=[];if(tr(r,f),f.length){const t=f.map(t=>{const e=J.getArrayBuffer(t.url,o);return e.xhr.url=t.url,u.push(e.xhr),e.then(e=>e&&e.status?null:{buffer:e,mimeType:t.mimeType,format:t.format})});a.push(...t)}c[e]=f.length}const f=Promise.all(a).then(o=>{for(let t=0;t<o.length;t++)if(!o[t]||!o[t].buffer)return Promise.resolve(null);const a=[];let u=0;for(let t=0;t<c.length;t++){const e=c[t];a.push({geoBuffer:{data:o[u].buffer.data},textureBuffers:o.slice(u+1,e+u+1).map(t=>({data:t.buffer.data,mimeType:t.mimeType,format:t.format}))}),u+=1+e}return function(t,e,n,s,i,o){const a={asset:{generator:"i3s",version:"2.0"},extensions:{},scene:0,scenes:[{nodes:[]}],nodes:{},meshes:{},materials:[],skins:[],animations:null,textures:[],transferables:[]},c=[];for(let u=0;u<t.meshes.length;u++){let{material:f}=t.meshes[u];const{geometry:h}=t.meshes[u];let l;const d=e[u].geoBuffer.data;if(!d)continue;const y=or(d);l=y?Kn(a,u,h,d,t.transform,t.center,i,o):Qn(a,u,h,d,t.transform,t.center,i,o),c.push(l),a.nodes[u]={mesh:u,nodeIndex:u,matrix:r([])},a.scenes[0].nodes[u]=a.nodes[u],f||(f=$n);const m=Zn(u,a,f,e[u].textureBuffers,n,s);c.push(m)}return Promise.all(c).then(()=>({gltf:a,featureTable:{BATCH_LENGTH:0},transferables:a.transferables}))}(t,a,e,i,n,s)});return f.xhr=u,f}const Jn={"magFilter":9728,"minFilter":9728,"wrapR":33071,"wrapS":33071,"wrapT":33071};function Kn(t,e,n,r,s,i,o,a){const c=n.info.compressedAttributes.attributes.reduce((t,e,n)=>{const r=Xn[e];if(!r)return t;return t[r.name||e]=n,t},{});return qn(r,{attributes:c,metadatas:{"POSITION":[{name:"i3s-scale_x",type:"double"},{name:"i3s-scale_y",type:"double"}]},useUniqueIDs:!1,skipAttributeTransform:!1}).then(n=>Wn(n,t,e,s,i,o,a))}const Yn={position:function(t,e,n){const r=3*t.vertexCount,s=new Float32Array(e,n,r);return t.position={array:s,componentType:5126,itemSize:3,count:r/3,meta:{"i3s-scale_x":1,"i3s-scale_y":1},type:"VEC3"},n+=4*r},normal:function(t,e,n){const r=3*t.vertexCount,s=new Float32Array(e,n,r);return t.normal={array:s,componentType:5126,itemSize:3,count:r/3,type:"VEC3"},n+=4*r},uv0:function(t,e,n){const r=2*t.vertexCount,s=new Float32Array(e,n,r);return t.uv0={array:s,componentType:5126,itemSize:2,count:r/2,type:"VEC2"},n+=4*r},color:function(t,e,n){const r=4*t.vertexCount,s=new Uint8Array(e,n,r);return t.color={array:s,componentType:5121,itemSize:4,count:r/4,type:"VEC4"},n+=r},featureId:function(t,e,n){return n+=8*t.featureCount},id:function(t,e,n){return n+=8*t.featureCount},faceRange:function(t,e,n){const r=2*t.featureCount,s=new Uint32Array(e,n,r);return t.faceRange={array:s,componentType:5125,itemSize:2,count:r/2,type:"VEC2"},n+=4*r},uvRegion:function(t,e,n){const r=4*t.vertexCount,s=new Uint16Array(e,n,r);return t["uv-region"]={array:s,componentType:5123,itemSize:4,count:r/4,type:"VEC4"},n+=2*r},region:function(t,e,n){const r=4*t.vertexCount,s=new Uint16Array(e,n,r);return t["uv-region"]={array:s,componentType:5123,itemSize:4,count:r/4,type:"VEC4"},n+=2*r}};function Qn(t,e,n,r,s,i,o,a){const c={vertexCount:0},u=new DataView(r);try{let t=0;c.vertexCount=u.getUint32(t,1),t+=4,c.featureCount=u.getUint32(t,1),t+=4;const e=n.info.ordering?null:n.info;if(e){const n=[];for(const t in e)"offset"!==t&&""!==t&&n.push(t);for(let e=0;e<n.length;e++)Yn[n[e]]?t=Yn[n[e]](c,r,t):console.error("Unknown decoder for",n[e])}else{const e=n.info;let s=e.ordering,i=e.featureAttributeOrder;const o=null;o&&o.geometryData&&o.geometryData[0]&&o.geometryData[0].params;for(let e=0;e<s.length;e++){const n=Yn[s[e]];n||console.log(s[e]),t=n(c,r,t)}for(let e=0;e<i.length;e++){const n=Yn[i[e]];n||console.log(i[e]),t=n(c,r,t)}}}catch(t){}c.scale_x=1,c.scale_y=1;const f={};for(const t in c){const e=Xn[t]&&Xn[t].name;e&&(f[e]=c[t])}if(c.faceRange){const t=c.faceRange.array,e=t.length/2,n=(h=e)<=255?Uint8Array:h<=65535?Uint16Array:Uint32Array,r=new n(f.POSITION.array.length/3);for(let e=0;e<t.length-1;e+=2){const n=e/2,s=t[e],i=t[e+1];for(let t=s;t<=i;t++)r[3*t]=n,r[3*t+1]=n,r[3*t+2]=n}f._BATCHID={componentType:Je(n),array:r,itemSize:1,count:r.length,type:"SCALAR"}}var h;return Wn({attributes:f},t,e,s,i,o,a)}function Wn(t,e,n,r,s,i,o){const a={attributes:t.attributes,material:n,indices:t.indices,mode:4};!function(t){const e=t.array,n=t.meta&&t.meta["i3s-scale_x"],r=t.meta&&t.meta["i3s-scale_y"];if(n&&r&&(1!==n||1!==r))for(let t=0;t<e.length;t+=3)e[t]*=n.value,e[t+1]*=r.value}(t.attributes.POSITION);const u=function(t,e,n,r,s){let i,o=[0,0,0,1];const a=[0,0],u=Ln([],n,r,s);u[2]=n[2];const f=e&&c(Vn,e);return pn(t,t=>(o[0]=t[0],o[1]=t[1],o[2]=t[2],f||(o=v(o,o,e)),n&&y(o,o,n),Ln(a,o,r,s),i=o[2],t[0]=a[0]-u[0],t[1]=a[1]-u[1],t[2]=i-u[2],t)),u}(t.attributes.POSITION,r,s,i,o);e.meshes[n]={primitives:[a],index:n},e.extensions.MAPTALKS_RTC={projCenter:u},e.extensions.CESIUM_RTC={rtcCoord:s};for(const n in t.attributes)ir(e.transferables,t.attributes[n].array.buffer);return t.indices&&ir(e.transferables,t.indices.array.buffer),a}function Zn(t,e,n,r,s,i){const o=r.map(t=>function(t,e,n,r,s){if("dds"===e){const e=Tn(t),r=e.images.map(e=>new Uint8Array(t,e.offset,e.length)),s="dxt1"===e.format?33777:33779;return Promise.resolve({image:{mipmap:r,width:e.shape[0],height:e.shape[1],mimeType:n},sampler:Jn,format:s})}if("png"===e||"jpg"===e)return function(t,e){er||(er=new OffscreenCanvas(2,2),nr=er.getContext("2d",{willReadFrequently:!0}));const n=new Blob([new Uint8Array(t)]);return createImageBitmap(n).then(t=>{let{width:n,height:r}=t;rr(n)||(n=sr(n)),rr(r)||(r=sr(r));const s=e;s&&(n=Math.min(s,n),r=Math.min(s,r)),er.width=n,er.height=r,nr.drawImage(t,0,0,n,r),t.close();const i=nr.getImageData(0,0,n,r);return{width:n,height:r,array:new Uint8Array(i.data)}}).catch(()=>({width:2,height:2,array:new Uint8Array(4)}))}(t,s).then(t=>{t.mimeType=n;return{image:t,sampler:Jn,format:6408}});if("ktx2"===e)return Gn(t,r).then(t=>(t.mimeType=n,{image:t,sampler:Jn,format:t.format}));return null}(t.data,t.format,t.mimeType,s,i).then(t=>{if(t.image)if(t.image.array)ir(e.transferables,t.image.array.buffer);else if(t.image.mipmap)for(let n=0;n<t.image.mipmap.length;n++)ir(e.transferables,t.image.mipmap[n].buffer);return t}));return Promise.all(o).then(r=>{!function t(e,n,r,s){const i=JSON.parse(JSON.stringify(r)),o=n.textures;s.ptr||(s.ptr=0);for(const e in r)r[e]&&r[e].url?(o.push(s[s.ptr++]),i[e]={index:o.length-1},void 0!==r[e].factor&&(i[e].scale=r[e].factor)):he(r[e])&&(i[e]=t(-1,n,r[e],s));e>=0&&(n.materials[e]=i);return i}(t,e,n,r)})}function tr(t,e){for(const n in t)t[n]&&t[n].url?e.push({url:t[n].url,mimeType:t[n].mimeType,format:t[n].format}):he(t[n])&&tr(t[n],e)}let er,nr;function rr(t){return 0==(t&t-1)&&0!==t}function sr(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}function ir(t,e){e&&(t.indexOf(e)>=0||t.push(e))}function or(t){const e=new Uint8Array(t,0,5);return e[0]==="D".charCodeAt()&&e[1]==="R".charCodeAt()&&e[2]==="A".charCodeAt()&&e[3]==="C".charCodeAt()&&e[4]==="O".charCodeAt()}const ar=[];const cr=[],ur=[],fr=[],hr=[],lr=[],dr=[],yr=[];function mr(t,e,n,r,s,i){d(hr,t[3*e],t[3*e+1],t[3*e+2]),d(lr,t[3*n],t[3*n+1],t[3*n+2]),d(dr,t[3*r],t[3*r+1],t[3*r+2]);const o=M(cr,dr,lr),a=M(ur,hr,lr),c=g(fr,o,a);p(yr,c),s[3*e]=s[3*e]||0,s[3*n]=s[3*n]||0,s[3*r]=s[3*r]||0,s[3*e+1]=s[3*e+1]||0,s[3*n+1]=s[3*n+1]||0,s[3*r+1]=s[3*r+1]||0,s[3*e+2]=s[3*e+2]||0,s[3*n+2]=s[3*n+2]||0,s[3*r+2]=s[3*r+2]||0,s[3*e]+=yr[0],s[3*n]+=yr[0],s[3*r]+=yr[0],s[3*e+1]+=yr[1],s[3*n+1]+=yr[1],s[3*r+1]+=yr[1],s[3*e+2]+=yr[2],s[3*n+2]+=yr[2],s[3*r+2]+=yr[2],i[e]+=1,i[n]+=1,i[r]+=1}const br=[1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],pr=[0,0,1,0,0,1,0,0,-1,0,0,0,0,0,0,1],wr=2*Math.PI*6378137/360,gr="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;let vr,Mr=!1;if("undefined"!=typeof OffscreenCanvas){try{vr=new OffscreenCanvas(2,2).getContext("2d",{willReadFrequently:!0})}catch(t){}vr&&"undefined"!=typeof createImageBitmap&&(Mr=!0)}const Tr=r([]),Ar=[0,0,0],_r=[],Or=[],xr=[],Sr=[],Ir={"POSITION":1,"TEXCOORD_0":1,"TEXCOORD_1":1,"NORMAL":1,"TANGENT":1},kr={"TEXCOORD_0":1e-4,"TEXCOORD_1":1e-4};class Er{constructor(t,e,n,r){this.id=t,this.options=e,this.wt=this.requestImage.bind(this),this.gt=n,this.vt={},r(null,{},[])}Mt(t){this.Tt||(this.i=t,this.At=new on,this.Tt=new tn(this.wt,dt,t),this._t=new en(this.wt,dt,t))}requestImage(t,e){Mr?fetch(t).then(t=>t.arrayBuffer()).then(t=>{const e=new self.Blob([new Uint8Array(t)]);return createImageBitmap(e)}).then(t=>{(void 0).width=t.width,(void 0).height=t.height,vr.drawImage(t,0,0);const n=vr.getImageData(0,0,(void 0).width,(void 0).height);t.close(),e(null,{width:t.width,height:t.height,data:new Uint8Array(n.data)})}):this.gt("requestImage",{url:t},null,e)}loadTile(t,e){this.Mt(t.supportedFormats);const n=t.service,r=t.url,s=t.arraybuffer,i=n.fetchOptions||{};if(i.referrer=t.referrer,i.referrerPolicy=i.referrerPolicy||"origin",function(t){return t.indexOf("i3s:")>=0}(r)){const s=t.i3sInfo,o=n.maxTextureSize||1024,a=Hn(s,t.supportedFormats,this.options.projection,t.projection,o,i);return a.then(t=>{if(delete this.vt[r],!t)return void e({status:404,url:r,i3sInfo:s});if(!Object.keys(t.gltf.meshes).length)return void e({status:404,url:r,i3sInfo:s});t.gltf.url=r;const{transferables:n}=t;t.magic="b3dm",this.Ot(t.gltf),e(null,t,n)}),void(this.vt[r]=a.xhr)}if(s){delete this.vt[r];const n=xe(new DataView(s),0);if("{"===n[0]||" "===n[0]||"<"===n[0]){const n=function(t,e,n){if(gr){const r=new Uint8Array(t,e,n);return gr.decode(r)}return me(new Uint8Array(t,e,n))}(s,0,s.byteLength),i=JSON.parse(n);i.accessors?this.xt(i,r,t,"gltf",e):this.St(t.rootIdx,i,s,r,e)}else this.xt(s,r,t,n,e)}else{let s=n.urlParams;s&&(s=(r.indexOf("?")>0?"&":"?")+s);const o=r.replace(/\\+/g,"%2B");let a=J.getArrayBuffer(o+(s||""),i);const c=a.xhr;a=a.then(n=>{delete this.vt[r],n&&n.status?e(n):(t.arraybuffer=n&&n.data,this.loadTile(t,e))}).catch(t=>{delete this.vt[r],e(t)}),this.vt[r]=c}}xt(t,e,n,r,s){r=r&&r.toLowerCase();const i=n.service;if("b3dm"===r){this.Tt.load(e,t,0,0,{maxTextureSize:i.maxTextureSize||1024}).then(t=>{if(t.error)return void s(t);const{content:e,transferables:r}=this.It(t,n);this.Ot(e.gltf),s(null,e,r)}).catch(t=>{s(t)})}else if("pnts"===r){const r=n.transform||Tr;this.At.load(e,t).then(t=>{const{content:e,transferables:i}=this.kt(t,r,n.rootIdx);this.Et(e),s(null,e,i)})}else if("i3dm"===r){const r=n.transform||Tr;this._t.load(e,t,0,0,{maxTextureSize:i.maxTextureSize||1024}).then(t=>{const{content:e,transferables:i}=this.Ct(t,r,n.rootIdx);this.Ot(e.gltf),s(null,e,i)})}else if("cmpt"===r){new cn(this.wt,dt,this.i,i.maxTextureSize||1024).load(e,t,0,0,{maxTextureSize:i.maxTextureSize||1024}).then(t=>{const{content:e,transferables:r}=this.Ut(t,n);this.Ft(e),s(null,e,r)}).catch(t=>{s(t)})}else if("gltf"===r){this.nt||(this.nt=Ze());const r=e.substring(0,e.lastIndexOf("/")),o=t instanceof ArrayBuffer&&{buffer:t,byteOffset:0,byteLength:t.byteLength}||t,a=new dt(r,o,{transferable:!0,requestImage:this.wt,decoders:this.nt,supportedFormats:this.i,maxTextureSize:i.maxTextureSize||1024});a.load({skipAttributeTransform:!1}).then(t=>{t.url=e,this.Nt(t,null,n),this.Ot(t),s(null,{magic:"gltf",gltf:t},a.transferables)})}else s(new Error("unsupported tile format: "+r))}Ft(t){t.content?t.content.forEach(t=>{this.Ft(t)}):this.Ot(t.gltf)}Pt(t,e){const n=e.materials[t.material];if(n&&n.extensions&&n.extensions.KHR_materials_unlit)return;if(t.attributes.TANGENT)return;if(t.attributes.TEXCOORD_0&&!t.attributes.NORMAL){const e=t.attributes.POSITION.array,n=function(t,e,n){const r=n||[];r.setLength&&r.setLength(t.length);const s=ar;s.length<t.length/3&&(s.length=t.length/3),s.fill(0,0,t.length/3);const i=void 0===e.length?e:e.length;for(let n=0;n<i/3;n++)void 0===e.length?mr(t,3*n,3*n+1,3*n+2,r,s):mr(t,e[3*n],e[3*n+1],e[3*n+2],r,s);for(let t=0;t<r.length;t+=3){const e=s[t/3];0!==e?(r[t]/=e,r[t+1]/=e,r[t+2]/=e):(r[t]=0,r[t+1]=0,r[t+2]=0)}return r}(e,t.indices.array,new Float32Array(e.length));t.attributes.NORMAL={array:n,byteLength:n.byteLength,byteOffset:0,byteStride:0,componentType:5126,count:n.length/3,itemSize:3,name:"NORMAL",type:"VEC3"}}}Ot(t){if(!t||!t.meshes||t.extensionsUsed&&t.extensionsUsed.indexOf("KHR_techniques_webgl")>-1)return;const e=t.meshes;for(const n in e){e[n].primitives.forEach(e=>{this.Pt(e,t),e.compressed_int16_params={};const n=e.attributes;for(const t in n)if(Ir[t]&&n[t].array&&n[t].array instanceof Float32Array){const r=this.options.projection;let s=1;"EPSG:4326"!==r&&"EPSG:4490"!==r||"POSITION"!==t||(s=wr,e.compressed_int16_params.compressed_ratio=s);const i=Br(n[t].array,s,n[t].min,n[t].max,t);if(!i)continue;const{array:o,range:a}=i;n[t].array=o,e.compressed_int16_params[t]=a}})}}Et(t){if(!t||!t.pnts)return;const e=t.pnts;t.compressed_int16_params={};for(const n in e)if(Ir[n]&&e[n].array&&e[n].array instanceof Float32Array){const r=this.options.projection;let s=1;"EPSG:4326"!==r&&"EPSG:4490"!==r||"POSITION"!==n||(s=wr,t.compressed_int16_params.compressed_ratio=s);const{array:i,range:o}=Br(e[n].array,s,e[n].min,e[n].max,n);e[n].array=i,t.compressed_int16_params[n]=o}}Bt(t){const e=[];for(let n=0;n<t.length;n++){const r=t[n];if(!r.childTile)continue;const s={boundingVolume:{sphere:[r.boundingSphere.center.x,r.boundingSphere.center.y,r.boundingSphere.center.z,r.boundingSphere.radius]},content:{uri:r.childTile},geometricError:r.boundingSphere.radius/r.rangeList*16,refine:"REPLACE"};e.push(s)}return e}St(t,e,n,r,s){return e.capabilities,void s(null,e)}Ut(t,e){const{tiles:n}=t,r={magic:"cmpt",content:[]},s=[];for(let t=0;t<n.length;t++){const{magic:i}=n[t];if("b3dm"===i){const{content:i,transferables:o}=this.It(n[t],e);Nr(s,o),r.content.push(i)}else if("i3dm"===i){const{transform:i,rootIdx:o}=e,{content:a,transferables:c}=this.Ct(n[t],i,o);Nr(s,c),r.content.push(a)}else if("pnts"===i){const{transform:i,rootIdx:o}=e,{content:a,transferables:c}=this.kt(n[t],i,o);Nr(s,c),r.content.push(a)}else if("cmpt"===i){const{content:i,transferables:o}=this.Ut(n[t],e);Nr(s,o),r.content.push(i)}}return{content:r,transferables:s}}It(t,e){const{gltf:n,transferables:r,featureTable:s}=t;return this.Nt(n,s,e),delete t.transferables,{content:t,transferables:r}}Nt(t,e,n){const r=function(t){if(!t||!t.meshes)return!1;let e=1;const n=[];for(const r in t.meshes){const s=t.meshes[r],{primitives:i}=s;if(i)for(let t=0;t<i.length;t++){const r=i[t].attributes&&i[t].attributes.POSITION;if(!r||!r.array)continue;r.array.buffer.visited||(r.array.buffer.visited=e++);const s=e-1+"-"+(r.byteOffset||0);if(n.indexOf(s)>=0)return!0;n.push(s)}}return!1}(t);this.Dt(t),t.asset||(t.asset={}),r?(t.asset.sharePosition=!0,this.Rt(t,e,n.upAxis,n.transform)):this.Lt(t,e,n.upAxis,n.transform)}Ct(t,e,r){const{featureTable:s}=t,i=t.i3dm,o=s&&s.RTC_CENTER||[0,0,0];if(s.EAST_NORTH_UP&&!i.NORMAL_UP&&!i.NORMAL_UP_OCT32P){const e=new Float32Array(3*i.POSITION.array.length),r=[],s=[],a=[];pn(i.POSITION,(t,i)=>{y(a,t,o),Xe(a,null,r),n(s,r);!function(t,e){t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8]}(e.subarray(9*i,9*(i+1)),s)}),i.INSTANCE_ROTATION={byteStride:0,byteOffset:0,itemSize:9,componentType:5126,array:e},t.transferables.push(e.buffer)}const a={xmin:1/0,xmax:-1/0,ymin:1/0,ymax:-1/0,hmin:1/0,hmax:-1/0};Ur(i.POSITION.array,3,o,Tr,a);const c=Fr(a),u=l([],c),f=[1/0,1/0,1/0],h=[-1/0,-1/0,-1/0];pn(i.POSITION,t=>{t[0]=t[0]+o[0]-u[0],t[1]=t[1]+o[1]-u[1],t[2]=t[2]+o[2]-u[2],t[0]<f[0]&&(f[0]=t[0]),t[1]<f[1]&&(f[1]=t[1]),t[2]<f[2]&&(f[2]=t[2]),t[0]>h[0]&&(h[0]=t[0]),t[1]>h[1]&&(h[1]=t[1]),t[2]>h[2]&&(h[2]=t[2])}),i.POSITION.min=f,i.POSITION.max=h,e&&v(c,c,e);const d=this.zt(c);t.rtcCenter=u,t.rtcCoord=d,t.rootIdx=r;const m=t.transferables;return delete t.transferables,{content:t,transferables:m}}kt(t,e,n){const{featureTable:r}=t,s=t.pnts,i=r&&r.RTC_CENTER||[0,0,0],o=this.options.projection,a=e&&c(Tr,e),u={xmin:1/0,xmax:-1/0,ymin:1/0,ymax:-1/0,hmin:1/0,hmax:-1/0};Ur(s.POSITION.array,3,i,e,u);const f=Fr(u),h=this.jt(f),y=l([],f),m=[1/0,1/0,1/0],b=[-1/0,-1/0,-1/0];let p=[0,0,0,1];const w=[0,0,0],g=[0,0];pn(s.POSITION,t=>(p[0]=t[0]+i[0],p[1]=t[1]+i[1],p[2]=t[2]+i[2],e&&!a&&(p=v(p,p,e)),0===A(p)?d(w,0,0,-6378137):Me(w,p),Ln(g,w,o),t[0]=g[0]-h[0],t[1]=g[1]-h[1],t[2]=w[2]-h[2],t[0]<m[0]&&(m[0]=t[0]),t[1]<m[1]&&(m[1]=t[1]),t[2]<m[2]&&(m[2]=t[2]),t[0]>b[0]&&(b[0]=t[0]),t[1]>b[1]&&(b[1]=t[1]),t[2]>b[2]&&(b[2]=t[2]),t)),s.POSITION.min=m,s.POSITION.max=b,e&&v(f,f,e);const M=this.zt(f);t.rtcCenter=y,t.projCenter=h,t.rtcCoord=M,t.rootIdx=n;const T=t.transferables;return delete t.transferables,{content:t,transferables:T}}Dt(t){if(!Array.isArray(t.textures))return;const e=t.textures;for(let t=0;t<e.length;t++){const n=e[t].image&&e[t].image.array;if(n&&n.length){const r=n[0],s=n[1],i=n[2],o=n[3];let a=!0;for(let t=4;t<n.length;t+=4)if(n[t]!==r||n[t+1]!==s||n[t+2]!==i||n[t+3]!==o){a=!1;break}a&&(e[t].image.color=[r/255,s/255,i/255,o/255],delete e[t].image.array)}}}abortTileLoading(t,e){const n=this.vt[t.url];if(Array.isArray(n))for(let t=0;t<n.length;t++)n[t].abort();else n&&n.abort&&n.abort();delete this.vt[t.url],e(null)}Vt(t,e,n,i){const o=e&&e.RTC_CENTER||t.extensions&&t.extensions.CESIUM_RTC&&t.extensions.CESIUM_RTC.center;let a=br;"X"===(n=n&&n.toUpperCase())?a=pr:"Z"===n&&(a=Tr),t.extensions=t.extensions||{},t.extensions.CESIUM_RTC||(t.extensions.CESIUM_RTC={}),o&&(t.extensions.CESIUM_RTC.center=o),t.extensions.MAPTALKS_RTC={};const c={xmin:1/0,xmax:-1/0,ymin:1/0,ymax:-1/0,hmin:1/0,hmax:-1/0};un(t,t=>{if(!(t.attributes&&t.attributes.POSITION))return;const e=r(_r);t.matrices&&Pr(e,t.matrices);const n=t.attributes.POSITION.array,u=t.attributes.POSITION.itemSize;s(e,a,e),i&&s(e,i,e),Ur(n,u,o||Ar,e,c,t.compressUniforms)});const u=Fr(c);return{rtcCenter:o,modelCenter:u,upAxisTransform:a}}Rt(t,e,n,i){const{modelCenter:o,upAxisTransform:a,rtcCenter:c}=this.Vt(t,e,n),u=l([],o);i&&v(o,o,i),t.extensions.CESIUM_RTC.rtcCoord=this.zt(o),c||(un(t,t=>{if(t.attributes&&t.attributes.POSITION){const e=t.attributes.POSITION;if(e.array.buffer.projected&&e.array.buffer.projected[e.byteOffset])return;const n=r(_r);t.matrices&&Pr(n,t.matrices),s(n,a,n);const i=function(t,e){var n=e[0],r=e[1],s=e[2],i=e[3],o=e[4],a=e[5],c=e[6],u=e[7],f=e[8],h=e[9],l=e[10],d=e[11],y=e[12],m=e[13],b=e[14],p=e[15],w=n*a-r*o,g=n*c-s*o,v=n*u-i*o,M=r*c-s*a,T=r*u-i*a,A=s*u-i*c,_=f*m-h*y,O=f*b-l*y,x=f*p-d*y,S=h*b-l*m,I=h*p-d*m,k=l*p-d*b,E=w*k-g*I+v*S+M*x-T*O+A*_;return E?(E=1/E,t[0]=(a*k-c*I+u*S)*E,t[1]=(s*I-r*k-i*S)*E,t[2]=(m*A-b*T+p*M)*E,t[3]=(l*T-h*A-d*M)*E,t[4]=(c*x-o*k-u*O)*E,t[5]=(n*k-s*x+i*O)*E,t[6]=(b*v-y*A-p*g)*E,t[7]=(f*A-l*v+d*g)*E,t[8]=(o*I-a*x+u*_)*E,t[9]=(r*x-n*I-i*_)*E,t[10]=(y*T-m*v+p*w)*E,t[11]=(h*v-f*T-d*w)*E,t[12]=(a*O-o*S-c*_)*E,t[13]=(n*S-r*O+s*_)*E,t[14]=(m*g-y*M-b*w)*E,t[15]=(f*M-h*g+l*w)*E,t):null}(Or,n),o=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];pn(e,t=>{v(t,t,n),t[0]=t[0]-u[0],t[1]=t[1]-u[1],t[2]=t[2]-u[2],v(t,t,i),t[0]<o[0]&&(o[0]=t[0]),t[1]<o[1]&&(o[1]=t[1]),t[2]<o[2]&&(o[2]=t[2]),t[0]>c[0]&&(c[0]=t[0]),t[1]>c[1]&&(c[1]=t[1]),t[2]>c[2]&&(c[2]=t[2])}),e.min=o,e.max=c,e.array.buffer.projected||(e.array.buffer.projected={}),e.array.buffer.projected[e.byteOffset]=1}}),t.extensions.CESIUM_RTC.center=u)}Lt(t,e,n,r){const{modelCenter:s,rtcCenter:i}=this.Vt(t,e,n,r),o=this.jt(s);t.extensions.MAPTALKS_RTC.projCenter=o,t.extensions.CESIUM_RTC.rtcCoord=this.zt(s),un(t,e=>{if(e.attributes&&e.attributes.POSITION){e.attributes.NORMAL&&this.qt(e.attributes.NORMAL,e.matrices,n),e.attributes.TANGENT&&this.qt(e.attributes.TANGENT,e.matrices,n);const{newPositions:s}=this.Gt(e.attributes.POSITION,e.matrices,i,t.extensions.MAPTALKS_RTC,n,r,e.compressUniforms),{componentType:o}=e.attributes.POSITION;5126!==o&&(e.attributes.POSITION.array=new Float32Array(s))}});for(const e in t.nodes){t.nodes[e].matrix=Tr}}jt(t){0===A(t)?d(xr,0,0,-6378137):Me(xr,t);const e=this.options.projection;Ln(Sr,xr,e);const n=xr[2],r=[];return r[0]=Sr[0],r[1]=Sr[1],r[2]=n,r}qt(t,e,r){let s;s="Y"===r?br:"X"===r?pr:Tr;const i=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}([],s);if(Pr(i,e),c(i,Tr))return;const o=n([],i),a=[];pn(t,t=>(function(t,e,n){var r=e[0],s=e[1],i=e[2];t[0]=r*n[0]+s*n[3]+i*n[6],t[1]=r*n[1]+s*n[4]+i*n[7],t[2]=r*n[2]+s*n[5]+i*n[8]}(a,t,o),p(a,a),l(t,a),a))}Gt(t,e,n,s,i,o,a){if(t.array.buffer.projected&&t.array.buffer.projected[t.byteOffset])return null;const u=r([]);Pr(u,e);const f=this.options.projection;i=i&&i.toUpperCase();const h=n;let l=null;"Y"===i?l=br:"X"===i&&(l=pr);let m=[0,0,0,1];const b=[0,0,0],p=[0,0],w=s.projCenter,g=o&&c(Tr,o),M=t.min=t.min||[],T=t.max=t.max||[];d(M,1/0,1/0,1/0),d(T,-1/0,-1/0,-1/0);const _=a||{},{decode_position_min:O,decode_position_normConstant:x}=_;let S=[0,0,0,0],I=1;O&&(S=O),x&&(I=x);const k=[];return pn(t,e=>{if(m[0]=e[0]*I+S[0],m[1]=e[1]*I+S[1],m[2]=e[2]*I+S[2],m=v(m,m,u),l&&(m=v(m,m,l)),h&&y(m,m,h),o&&!g&&(m=v(m,m,o)),0===A(m)?d(b,0,0,-6378137):Me(b,m),Ln(p,b,f),e instanceof Float32Array)e[0]=p[0]-w[0],e[1]=p[1]-w[1],e[2]=b[2]-w[2];else{const n=p[0]-w[0],r=p[1]-w[1],s=b[2]-w[2];5126!==t.componentType&&(k.push(n),k.push(r),k.push(s),k.push(e[3]))}return e[0]<M[0]&&(M[0]=e[0]),e[1]<M[1]&&(M[1]=e[1]),e[2]<M[2]&&(M[2]=e[2]),e[0]>T[0]&&(T[0]=e[0]),e[1]>T[1]&&(T[1]=e[1]),e[2]>T[2]&&(T[2]=e[2]),e}),t.array.buffer.projected||(t.array.buffer.projected={}),t.array.buffer.projected[t.byteOffset]=1,{projCenter:w,newPositions:k}}zt(t){return 0===A(t)?d([],0,0,-6378137):Me([],t)}onRemove(){}}const Cr=[];function Ur(t,e,n,r,s,i){const o=i||{},{decode_position_min:a,decode_position_normConstant:c}=o;let u=[0,0,0,0],f=1;a&&(u=a),c&&(f=c);for(let i=0,o=t.length;i<o;i+=e){const{xmin:o,ymin:a,xmax:c,ymax:h,hmin:l,hmax:m}=s;d(Cr,t[i]*f+u[0],t[i+1]*f+u[1],t[i+2]*f+u[2]),v(Cr,Cr,r);const b=y(Cr,n,Cr);b[0]<o&&(s.xmin=b[0]),b[0]>c&&(s.xmax=b[0]),b[1]<a&&(s.ymin=b[1]),b[1]>h&&(s.ymax=b[1]),e>2&&(b[2]<l&&(s.hmin=b[2]),b[2]>m&&(s.hmax=b[2]))}}function Fr(t){const{xmax:e,ymax:n,xmin:r,ymin:s,hmin:i,hmax:o}=t,a=[(r+e)/2,(s+n)/2,(i+o)/2];return e===-1/0&&(a[0]=0),n===-1/0&&(a[1]=0),o===-1/0&&(a[2]=0),isNaN(a[2])&&(a[2]=0),a}function Nr(t,e){for(let n=0;n<e.length;n++)t.indexOf(e[n])<0&&t.push(e[n])}function Pr(t,e){const n=t;for(let t=e.length-1;t>=0;t--)s(n,e[t],n);return n}function Br(t,e,n,r,s){if(e&&e>1)for(let n=0;n<t.length;n++)(n+1)%3!=0&&(t[n]*=e);let i,o;if(n&&r&&1===e)i=Math.min(...n),o=Math.max(...r);else{const{min:e,max:n}=function(t){let e=1/0,n=-1/0;for(let r=0;r<t.length;r++)t[r]>n&&(n=t[r]),t[r]<e&&(e=t[r]);return{min:e,max:n}}(t);i=e,o=n}return!function(t,e,n,r){for(let s=0;s<t.length;s++){const i=Dr(Rr(t[s],e,n),e,n);if(Math.abs(i-t[s])>kr[r])return!1}return!0}(t,i,o,s)&&kr[s]?null:function(t,e,n){const r=new Int16Array(t.length);for(let s=0;s<t.length;s++)r[s]=Rr(t[s],e,n);return{array:r,range:[e,n]}}(t,i,o)}function Dr(t,e,n){return((t>=32768?-(65536-t)/32768:t/32767)+1)*(n-e)/2+e}function Rr(t,e,n){const r=2*(t-e)/(n-e)-1,s=Math.max(-1,Math.min(1,r));return s<0?32768*s:32767*s}let Lr=0;class zr{constructor(t){this.workerId=t,this.workers={},this.$t={}}addLayer({actorId:t,mapId:e,layerId:n,params:r},s){if(this.Xt(e,n))return;const i=this.Ht(e,n),o=r.options,a=this.send.bind(this,t);this.workers[i]=new Er(n,o,a,s)}removeLayer({mapId:t,layerId:e},n){const r=this.Xt(t,e),s=this.Ht(t,e);delete this.workers[s],r&&r.onRemove(n)}loadTile({mapId:t,layerId:e,params:n},r){const s=this.Xt(t,e);s&&s.loadTile(n,r)}abortTileLoading({mapId:t,layerId:e,params:n},r){const s=this.Xt(t,e);s&&s.abortTileLoading(n,r)}receive(t){const e=t.callback,n=this.$t[e];delete this.$t[e],n&&t.error?n(new Error(t.error)):n&&n(null,t.data)}send(t,e,n,r,s){const i=s?`${t}-${Lr++}`:null;s&&(this.$t[i]=s),postMessage({type:"<request>",workerId:this.workerId,actorId:t,command:e,params:n,callback:String(i)},r||[])}Ht(t,e){return`${t}-${e}`}Xt(t,e){const n=this.Ht(t,e);return this.workers[n]}}t.initialize=function(){},t.onmessage=function(t,e){const n=t.data;this.dispatcher||(this.dispatcher=new zr(t.workerId)),"<response>"===t.type?this.dispatcher.workerId===t.workerId&&this.dispatcher.receive(t):this.dispatcher[n.command]({actorId:n.actorId,mapId:n.mapId,layerId:n.layerId,params:n.params},(t,n,r)=>{t&&console.error(t),t instanceof Error&&(t={message:t.message}),e(t,n,r)})},Object.defineProperty(t,"Jt",{value:!0})}';for(
|
|
7
7
|
/*!
|
|
8
8
|
* Contains code from THREE.js
|
|
9
9
|
* MIT License
|
|
@@ -13,11 +13,11 @@ var a=[],c=0;c<6;c++)a[c]=[];var h=[];function u(t,e,n){f(t);for(var r=0;r<6;r++
|
|
|
13
13
|
/*!
|
|
14
14
|
* @maptalks/gltf-loader v0.95.2
|
|
15
15
|
* LICENSE : UNLICENSED
|
|
16
|
-
* (c) 2016-
|
|
16
|
+
* (c) 2016-2024 maptalks.org
|
|
17
17
|
*/
|
|
18
|
-
let ee=0;function ne(t){return null==t}function re(t){return!ne(t)}function se(t){return!ne(t)&&("string"==typeof t||null!==t.constructor&&t.constructor===String)}function ie(t){for(let e=1;e<arguments.length;e++){const n=arguments[e];for(const e in n)t[e]=n[e]}return t}function oe(t){switch(t){case 5120:return Int8Array;case 5121:return Uint8Array;case 5122:return Int16Array;case 5123:return Uint16Array;case 5124:return Int32Array;case 5125:return Uint32Array;case 5126:return Float32Array}throw new Error("unsupported bufferView's component type: "+t)}function ae(t){return 0===t.indexOf("data:")&&t.indexOf("base64,")>0}function ce(t){const e=function(t){return"undefined"!=typeof self?self.atob(t):window.atob(t)}(t.substring(t.indexOf(",")+1)),n=e.length,r=new Uint8Array(n);for(let t=0;t<n;t++)r[t]=e.charCodeAt(t);return r.buffer}const he=[],ue=[],le=[],fe=[0,0,0],de=Zt([]),me=[1,1,1];function pe(t,e,n,r,s,i,o){const a=oe(o);if((0===s||s===r*a.BYTES_PER_ELEMENT)&&i%a.BYTES_PER_ELEMENT==0){const s=new a(e,i,n*r);return t.set(s),t}0===s&&(s=r*a.BYTES_PER_ELEMENT);const c=new Uint8Array(r*a.BYTES_PER_ELEMENT);for(let o=0;o<n;o++){let n=null;const h=new Uint8Array(e,s*o+i,r*a.BYTES_PER_ELEMENT);c.set(h),n=new a(c.buffer,0,r);for(let e=0;e<r;e++)t[o*r+e]=n[e]}return t}const be="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function ge(t,e,n){const r=new Uint8Array(t,e,n);return be.decode(r)}const ye={get:function(t,e={}){e||(e={});const n=new AbortController,r=n.signal,s=ie({},e);s.signal=r,s.method||(s.method="GET");const i=fetch(t,s).then(t=>{const n=this.s(t,e.responseType);return n.message?n:n.then(n=>"arraybuffer"===e.responseType?{data:n,cacheControl:t.headers.get("Cache-Control"),expires:t.headers.get("Expires"),contentType:t.headers.get("Content-Type")}:n).catch(t=>{if(!t.code||t.code!==DOMException.ABORT_ERR)throw t})}).catch(t=>{if(!t.code||t.code!==DOMException.ABORT_ERR)throw t});return i.xhr=n,i},s:(t,e)=>200!==t.status?{status:t.status,statusText:t.statusText,message:`incorrect http request with status code(${t.status}): ${t.statusText}`}:"arraybuffer"===e?t.arrayBuffer():"json"===e?t.json():t.text(),getArrayBuffer:(t,e={})=>(e||(e={}),e.responseType="arraybuffer",ye.get(t,e)),getJSON:function(t,e={}){return e&&e.jsonp?ye.jsonp(t):((e=e||{}).responseType="json",ye.get(t,e))},jsonp:function(t){const e="_maptalks_jsonp_"+ee++;t.match(/\?/)?t+="&callback="+e:t+="?callback="+e;let n=document.createElement("script");return n.type="text/javascript",n.src=t,new Promise(t=>{window[e]=function(r){document.getElementsByTagName("head")[0].removeChild(n),n=null,delete window[e],t(r)},document.getElementsByTagName("head")[0].appendChild(n)})}};class we{constructor(t,e,n,r){this.i=t,this.decoders=e,this.o=n,this.images={},this.h={},this.u=r||{}}requestImageFromBufferURI(t,e,n){if(this.buffers[t.id]){const r=this.buffers[t.id],s=this.m(e,r);return this.getImageByBuffer(s,n)}if(this.h[t.id])return this.h[t.id].then(()=>{const r=this.buffers[t.id],s=this.m(e,r);return this.getImageByBuffer(s,n)});if(ae(t.uri)){const r=this.buffers[t.id]=ce(t.uri),s=this.m(e,r);return this.getImageByBuffer(s,n)}let r;const s=t.uri.indexOf("blob:")>=0;return r=t.uri.indexOf("://")>0||s?t.uri:this.rootPath+"/"+t.uri,this.h[t.id]=ye.getArrayBuffer(r,this.u).then(r=>{const s=this.buffers[t.id]=r.data,i=this.m(e,s);return this.getImageByBuffer(i,n)})}getImageByBuffer(t,e){if(this.images[e.id])return Promise.resolve(this.images[e.id]);const n=this.decoders;return n[e.mimeType]?n[e.mimeType](t,{supportedFormats:this.o}):"image/crn"===e.mimeType||"image/ktx2"===e.mimeType||"image/cttf"===e.mimeType?(console.warn("missing transcoder for "+e.mimeType,", visit https://maptalks.com/docs/transcoders for details"),Promise.resolve(null)):this.p(e.id,t)}requestExternalImage(t){if(this.images[t.id])return Promise.resolve(this.images[t.id]);const e=0===t.uri.indexOf("data:image/")?t.uri:this.rootPath+"/"+t.uri;return this.h[t.id]?this.h[t.id].then(()=>this.images[t.id]):this.h[t.id]=this.p(t.id,e)}p(t,e){return new Promise((n,r)=>{this.i(e,this.u,(s,i)=>{s?r(s):(URL.revokeObjectURL(e),this.images[t]=i,n(this.images[t]))})})}}const ve=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],Te=[];class _e{constructor(t,e,n,r){this.rootPath=t,this.gltf=e,this.v=!1,this.glbBuffer=n,this.buffers={},this.requests={},this.accessors={},this.T(),this.u=r}_(t,e){const n=this.gltf,r=n.accessors[e];if(void 0===r.bufferView)return this.accessors[r.id]=this.M(t,e,null,0),Promise.resolve(this.accessors[r.id]);if(r&&this.accessors[r.id])return Promise.resolve(this.accessors[r.id]);const s=n.bufferViews[r.bufferView];return this.O(s).then(n=>{const{buffer:s,byteOffset:i}=n;return this.accessors[r.id]=this.M(t,e,s,i)})}O(t){const e=this.gltf.buffers[t.buffer];if(this.buffers[e.id]){const t=this.buffers[e.id];return Promise.resolve({buffer:t,byteOffset:0})}if(this.requests[e.id])return this.requests[e.id].then(()=>{const t=this.buffers[e.id];return Promise.resolve({buffer:t,byteOffset:0})});if("binary_glTF"!==t.buffer&&"KHR_binary_glTF"!==t.buffer&&e.uri){if(ae(e.uri)){const t=this.buffers[e.id]=ce(e.uri);return Promise.resolve({buffer:t,byteOffset:0})}let t;const n=e.uri.indexOf("blob:")>=0;return t=e.uri.indexOf("://")>0||n?e.uri:this.rootPath+"/"+e.uri,this.requests[e.id]=ye.getArrayBuffer(t,this.u).then(r=>(n&&URL.revokeObjectURL(t),{buffer:this.buffers[e.id]=r.data,byteOffset:0}))}return Promise.resolve({buffer:this.glbBuffer.buffer,byteOffset:this.glbBuffer.byteOffset})}M(t,e,n,r=0){const s=this.gltf,i=s.accessors[e],o=void 0!==i.bufferView?s.bufferViews[i.bufferView]:{},a=(o.byteOffset||0)+r,c=this.A(i.type),h=oe(i.componentType),u=o.byteStride||0,l={array:void 0,name:t,accessorName:e,byteLength:i.count*c*h.BYTES_PER_ELEMENT,componentType:i.componentType,count:i.count,type:i.type,itemSize:c,max:i.max,min:i.min,extensions:i.extensions};if(i.min&&(l.min=i.min),i.max&&(l.max=i.max),n)if(this.v)l.byteStride=u,l.byteOffset=a+(i.byteOffset||0),!u||u===c*h.BYTES_PER_ELEMENT||"indices"===t||"input"===t||"output"===t||t.indexOf("morph")>=0?(l.array=this.I(n,i.count,c,a+(i.byteOffset||0),h),l.array.buffer.byteLength===l.byteLength&&(l.byteOffset=0)):l.array=new Uint8Array(n,a,o.byteLength);else if(i.interleaved){l.byteStride=0,l.byteOffset=0;const t=new h(i.count*c);if(l.array=pe(t,n,i.count,c,u,a+(i.byteOffset||0),i.componentType),l.extensions&&l.extensions.WEB3D_quantized_attributes&&c>2){const t=new Float32Array(l.array.length),{decodeMatrix:e}=l.extensions.WEB3D_quantized_attributes;for(let n=0;n<l.array.length;n+=c){Te[0]=l.array[n],Te[1]=l.array[n+1],Te[2]=l.array[n+2],Te[3]=1;const r=Kt(Te,Te,e);t[n]=r[0],t[n+1]=r[1],t[n+2]=r[2]}l.componentType=5126,l.array=t}}else l.byteStride=0,l.array=this.I(n,i.count,c,a+(i.byteOffset||0),h),l.byteOffset=l.array.byteOffset;else{l.array=new h(i.count);const t=l.min||l.max;t&&(l.array[0]=t[0],l.array[1]=t[1],l.array[2]=t[2])}return l}T(){const t=this.gltf.accessors;if(Array.isArray(t))for(let e=0;e<t.length;e++)for(let n=0;n<t.length;n++)e!==n&&t[e].bufferView===t[n].bufferView&&(t[e].interleaved=t[n].interleaved=!0);else for(const e in t)for(const n in t)e!==n&&t[e].bufferView===t[n].bufferView&&(t[e].interleaved=t[n].interleaved=!0)}I(t,e,n,r,s){return r%s.BYTES_PER_ELEMENT!=0&&(t=t.slice(r,r+e*n*s.BYTES_PER_ELEMENT),r=0),new s(t,r,n*e)}A(t){const e=ve.indexOf(t);return ve[e+1]}requestKHRTechniquesWebgl(t){const{shaders:e}=t,n=e.map(t=>{if(void 0!==t.bufferView){const e=this.gltf.bufferViews[t.bufferView],{byteLength:n}=e;return this.O(e).then(r=>{const{buffer:s,byteOffset:i}=r,o=ge(s,i+(e.byteOffset||0),n);return t.content=o,t})}if(t.uri){if(ae(t.uri)){const e=ce(t.uri),n=ge(e,0,e.byteLength);return t.content=n,Promise.resolve(t)}{const e=this.rootPath+"/"+t.uri;return ye.get(e,this.u).then(e=>(t.content=e,t))}}return Promise.resolve(t)});return Promise.all(n).then(()=>t)}}class Me extends we{constructor(t,e,n,r,s,i,o){super(r,s,i,o),this.rootPath=t,this.gltf=e,this.requests={},this.buffers={},this.glbBuffer=n,this.accessor=new _e(t,e,n,o)}iterate(t,e){const n=this.gltf[e];if(!n)return;let r=0;for(const e in n)t(e,n[e],r++)}createNode(t){const e={};if(re(t.name)&&(e.name=t.name),re(t.children)&&(e.children=t.children),re(t.jointName)&&(e.jointName=t.jointName),re(t.matrix)&&(e.matrix=t.matrix),re(t.rotation)&&(e.rotation=t.rotation),re(t.scale)&&(e.scale=t.scale),re(t.translation)&&(e.translation=t.translation),re(t.extras)&&(e.extras=t.extras),re(t.meshes)&&(e.mesh=t.meshes[0]),e.translation||e.rotation||e.scale){const t=function(t,e){if(e.matrix)return e.matrix;if(e.translation||e.scale||e.rotation){const n=Nt(he,e.translation||fe),r=Pt(ue,e.rotation||de),s=Ct(le,e.scale||me);return Et(s,r,s),Et(t,n,s)}return St(t)}([],e);delete e.translation,delete e.rotation,delete e.scale,e.matrix=t}return e}S(t){const e={};for(const n in t){const r=t[n];let s,i;r.instanceTechnique&&r.instanceTechnique.values?(s=r.instanceTechnique,i=s.values.diffuse):(s=r,i=s.values.tex||s.values.diffuseTex||s.values.diffuse);const o={baseColorTexture:{index:i}};r.name&&(o.name=r.name),r.extensions&&(o.extensions=r.extensions),r.extras&&(o.extras=r.extras),e[n]=o}return e}N(t){if(t.bufferView||t.extensions&&(t.extensions.KHR_binary_glTF||t.extensions.binary_glTF)){const e=t.bufferView?t:t.extensions.KHR_binary_glTF||t.extensions.binary_glTF;t.extensions&&(t.mimeType=e.mimeType,t.width=e.width,t.height=e.height);const n=this.gltf.bufferViews[e.bufferView],r=(n.byteOffset||0)+this.glbBuffer.byteOffset,s=n.byteLength,i=this.buffers[e.bufferView]=new Uint8Array(this.glbBuffer.buffer,r,s);return this.getImageByBuffer(i,t)}return this.requestExternalImage(t)}C(t){const e=this.gltf.textures[t];if(!e)return null;const n=this.gltf.images[e.source];return this.N(n).then(t=>{const r=this.gltf.samplers[e.sampler];return{image:{array:t.data,width:t.width,height:t.height,index:e.source,mimeType:n.mimeType,name:n.name,extras:n.extras},sampler:r}})}getBaseColorTexture(t){const e=this.gltf.materials[t];let n,r;if(e.instanceTechnique&&e.instanceTechnique.values?(n=e.instanceTechnique,r=n.values.diffuse):(n=e,r=n.values.tex||n.values.diffuseTex||n.values.diffuse),void 0===r||void 0===this.gltf.textures)return null;const s=this.gltf.textures[r];if(!s)return null;const i=this.gltf.samplers[s.sampler];return{format:s.format||6408,internalFormat:s.internalFormat||6408,type:s.type||5121,sampler:i,source:this.gltf.images[s.source]}}getMaterial(){return null}getAnimations(){return null}}class Oe extends we{constructor(t,e,n,r,s,i,o){super(r,s,i,o),this.rootPath=t,this.gltf=e,this.glbBuffer=n,this.buffers={},this.requests={},this.accessor=new _e(t,e,n,o)}iterate(t,e){const n=this.gltf[e];if(n)for(let e=0;e<n.length;e++)t(e,n[e],e)}createNode(t){const e={};return ie(e,t),!re(t.weights)&&this.gltf.meshes&&re(e.mesh)?e.weights=this.gltf.meshes[e.mesh].weights:t.weights&&(e.weights=t.weights),e}C(t){const e=this.gltf.textures[t];if(!e)return null;let n=e.source;if(e.extensions&&e.extensions.EXT_texture_webp&&(n=e.extensions.EXT_texture_webp.source),!re(n))return null;const r=this.gltf.images[n];return this.N(r).then(t=>{if(!t)return null;const n={image:{array:t.data,mipmap:t.mipmap,width:t.width,height:t.height,index:e.source,mimeType:r.mimeType,name:r.name,extensions:r.extensions,extras:r.extras}};ie(n,e);const s=re(e.sampler)?this.gltf.samplers[e.sampler]:void 0;return s&&(n.sampler=s,n.sampler.magFilter=s.magFilter||9729,n.sampler.minFilter=s.minFilter||9729,n.sampler.wrapS=s.wrapS||10497,n.sampler.wrapT=s.wrapT||10497),t.format&&(n.format=t.format),n})}N(t){if(!re(t.bufferView))return this.requestExternalImage(t);{const e=this.gltf.bufferViews[t.bufferView],n=this.gltf.buffers[e.buffer];if(n.uri)return this.requestImageFromBufferURI(n,e,t);if(this.glbBuffer)return this.P(e,t)}return null}P(t,e){const n=this.m(t,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(n,e)}m(t,e,n){n=n||0;const r=t.byteOffset+n,s=t.byteLength;return new Uint8Array(e,r,s)}R(t,e){const n=new Array(t.byteLength);for(let e=0;e<t.byteLength;e++)n[e]=String.fromCharCode(t[e]);return n.join(""),"data:"+(e=e||"image/png")+";base64,"+function(t){return"undefined"!=typeof self?self.btoa(t):window.btoa(t)}(unescape(encodeURIComponent(n)))}getAnimations(t){const e=[];return t.forEach(t=>{e.push(this.getSamplers(t.samplers))}),Promise.all(e).then(e=>{for(let n=0;n<e.length;n++)t[n].samplers=e[n];return t})}getSamplers(t){const e=[];for(let n=0;n<t.length;n++)(re(t[n].input)||re(t[n].output))&&(e.push(this.accessor._("input",t[n].input)),e.push(this.accessor._("output",t[n].output)));return Promise.all(e).then(e=>{for(let n=0;n<e.length/2;n++)t[n].input=e[2*n],t[n].output=e[2*n+1],t[n].interpolation||(t[n].interpolation="LINEAR");return t})}}const xe="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class Ae{static read(t,e=0,n=0){n||(n=t.byteLength);const r=new DataView(t,e,n),s=r.getUint32(4,!0);if(1===s)return Ae.readV1(r,e);if(2===s)return Ae.readV2(t,e);throw new Error("Unsupported glb version : "+s)}static readV1(t,e){const n=t.getUint32(8,!0),r=t.getUint32(12,!0);if(n!==t.byteLength)throw new Error("Length in GLB header is inconsistent with glb's byte length.");const s=Ie(t.buffer,20+e,r);return{json:JSON.parse(s),glbBuffer:{byteOffset:20+e+r,buffer:t.buffer,byteLength:n}}}static readV2(t,e){let n,r,s;const i=new DataView(t,e+12);let o=0;for(;o<i.byteLength;){const a=i.getUint32(o,!0);o+=4;const c=i.getUint32(o,!0);if(o+=4,1313821514===c)n=Ie(t,e+12+o,a);else if(5130562===c){s=e+12+o,r=a;break}o+=a}return{json:JSON.parse(n),glbBuffer:{byteOffset:s,buffer:t,byteLength:r}}}}function Ie(t,e,n){if(xe){const r=new Uint8Array(t,e,n);return xe.decode(r)}return function(t){const e=t.length;let n="";for(let r=0;r<e;){let s=t[r++];if(128&s){let n=Se[s>>3&7];if(!(64&s)||!n||r+n>e)return null;for(s&=63>>n;n>0;n-=1){const e=t[r++];if(128!=(192&e))return null;s=s<<6|63&e}}n+=String.fromCharCode(s)}return n}(new Uint8Array(t,e,n))}const Se=[1,1,1,1,2,2,3,0],Ee=[0,0,0],Ne=[0,0,0,1],Ce=[1,1,1],Pe={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},Re={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},ke={k(t,e,n,r,s,i,o,a){const c=re(t)?e.animations:[e.animations[0]],h={};for(let e=0;e<c.length;e++){const u=c[e],l=u.name||e;if(re(t)&&l!==t)continue;const f=u.channelsMap[n];if(f)for(let t=0;t<f.length;t++){const e=f[t];"translation"===e.target.path?(this.L(s,u.samplers[e.sampler],r,1),h.translation=Bt(Ee,s)):"rotation"===e.target.path?(this.B(i,u.samplers[e.sampler],r,1),h.rotation=te(Ne,i)):"scale"===e.target.path?(this.L(o,u.samplers[e.sampler],r,1),h.scale=Bt(Ce,o)):"weights"===e.target.path&&a&&(this.L(a,u.samplers[e.sampler],r,a.length),h.weights=a)}}return h},L(t,e,n,r){switch(e.interpolation){case"LINEAR":{const s=this.U(Re,e,n,1*r);s&&(t=function(t,e,n,r){for(let s=0;s<t.length;s++)t[s]=e[s]+r*(n[s]-e[s]);return t}(t,s.PREVIOUS,s.NEXT,s.INTERPOLATION));break}case"STEP":{const s=this.U(Re,e,n,1*r);s&&(t=function(t,e){for(let n=0;n<t.length;n++)t[n]=e[n];return t}(t,...s.PREVIOUS));break}case"CUBICSPLINE":{const s=this.U(Re,e,n,3*r);s&&(t=this.F(t,s,e.input.array,3*r));break}}return t},B(t,e,n){switch(e.interpolation){case"LINEAR":{const r=this.U(Re,e,n,1);r&&Yt(t,r.PREVIOUS,r.NEXT,r.INTERPOLATION);break}case"STEP":{const r=this.U(Re,e,n,1);r&&(t=Jt(t,...r.PREVIOUS));break}case"CUBICSPLINE":{const r=this.U(Re,e,n,3);if(r){for(let t=0;t<r.PREVIOUS.length;t++)r.PREVIOUS[t]=Math.acos(r.PREVIOUS[t]),r.NEXT[t]=Math.acos(r.NEXT[t]);t=this.F(t,r,e.input.array,3);for(let e=0;e<t.length;e++)t[e]=Math.cos(t[e])}break}}return t},D(t,e){const n=t.length;let r,s,i,o=0,a=n-1,c=Math.floor((o+a)/2);for(;o<=n-1&&a>=0;){if(o===a)return null;if(t[c]<=e&&e<=t[c+1]){const n=t[c];return r=c,s=c+1,i=(e-n)/(t[c+1]-n),{preIndx:r,nextIndex:s,interpolation:i}}e<t[c]?(a=c,c=Math.floor((o+a)/2)):t[c+1]<e&&(o=c,c=Math.floor((o+a)/2))}return null},U(t,e,n,r){const s=e.input.array,i=e.output.array,o=e.output.itemSize;(n<s[0]||n>s[s.length-1])&&(n=Math.max(s[0],Math.min(s[s.length-1],n))),n===s[s.length-1]&&(n=s[0]);const a=this.D(s,n);if(!a||!a.nextIndex)return null;const{preIndx:c,nextIndex:h,interpolation:u}=a;t.PREINDEX=c,t.NEXTINDEX=h,t.INTERPOLATION=u;const l=o*r;return t.PREVIOUS=i.subarray(t.PREINDEX*l,(t.PREINDEX+1)*l),t.NEXT=i.subarray(t.NEXTINDEX*l,(t.NEXTINDEX+1)*l),t},F(t,e,n,r){const s=e.INTERPOLATION,i=n[e.PREINDEX],o=n[e.NEXTINDEX];for(let n=0;n<3;n++){const a=e.PREVIOUS[r+n],c=(o-i)*e.PREVIOUS[2*r+n],h=e.NEXT[3+n],u=(o-i)*e.NEXT[n],l=(2*Math.pow(s,3)-3*Math.pow(s,2)+1)*a+(Math.pow(s,3)-2*Math.pow(s,2)+s)*c+(2*-Math.pow(s,3)+3*Math.pow(s,2))*h+(Math.pow(s,3)-Math.pow(s,2))*u;t[n]=l}return t},getAnimationClip(t,e,n,r){const s=t.nodes[e]&&t.nodes[e].weights;return Ut(Ee,...Pe.TRANSLATION),Jt(Ne,...Pe.ROTATION),Ut(Ce,...Pe.SCALE),this.k(r,t,e,n,Ee,Ne,Ce,s)},getTimeSpan(t){if(!t.animations)return null;if(t.timeSpan)return t.timeSpan;const e=t.animations;return t.timeSpan={},e.forEach((e,n)=>{let r=-1/0,s=1/0;const i=e.channels;for(let t=0;t<i.length;t++){const n=i[t],o=e.samplers[n.sampler].input.array;o[o.length-1]>r&&(r=o[o.length-1]),o[0]<s&&(s=o[0])}const o=e.name||n;t.timeSpan[o]={max:r,min:s}}),t.timeSpan},getTimeSpanByName(t,e){const n=this.getTimeSpan(t);return n?re(e)?n[e]:n[Object.keys(n)[0]]:null}};let Le=!1;if("undefined"!=typeof OffscreenCanvas){let t;try{t=new OffscreenCanvas(2,2).getContext("2d")}catch(ds){}t&&"undefined"!=typeof createImageBitmap&&(Le=!0)}const Be="undefined"==typeof document?null:document.createElement("canvas");class Ue{constructor(t,e,n){if(this.options=n||{},this.options.decoders||(this.options.decoders={}),this.u=this.options.fetchOptions||{},e.buffer instanceof ArrayBuffer){const{json:n,glbBuffer:r}=Ae.read(e.buffer,e.byteOffset,e.byteLength);this.j(t,n,r)}else this.j(t,e);this.H=new _e(this.rootPath,this.gltf,this.glbBuffer,this.u),this.G()}G(){const t=this.gltf.extensionsRequired;if(t){if(t.indexOf("KHR_draco_mesh_compression")>=0&&!this.options.decoders.draco)throw new Error("KHR_draco_mesh_compression is required but @maptalks/transcoders.draco is not loaded");if(t.indexOf("KHR_texture_basisu")>=0&&!this.options.decoders.ktx2)throw new Error("KHR_texture_basisu is required but @maptalks/transcoders.ktx2 is not loaded")}}q(){const t=this.gltf.extensions;return t&&t.KHR_techniques_webgl?this.H.requestKHRTechniquesWebgl(t.KHR_techniques_webgl).then(e=>(t.KHR_techniques_webgl=e,t)):Promise.resolve(t)}load(t){t=t||{};const e=this.V(t),n=this.$(),r=this.X(),s=this.q();return Promise.all([e,n,r,s]).then(t=>(t[0].animations=t[1],t[0].textures=t[2],t[0].extensions=t[3],t[0].transferables=this.transferables||[],this.createChannelsMap(t[0]),t[0]))}createChannelsMap(t){const e=t.animations;if(e)for(let t=0;t<e.length;t++){const n=e[t];n.channelsMap={};for(let t=0;t<n.channels.length;t++){const e=n.channels[t];n.channelsMap[e.target.node]||(n.channelsMap[e.target.node]=[]),n.channelsMap[e.target.node].push(e)}}}getExternalResources(){const t=[];if(this.gltf){const{buffers:e,images:n}=this.gltf;for(let n=0;n<e.length;n++)e[n].uri&&e[n].uri.indexOf("data:application/octet-stream;base64")<0&&t.push({type:"buffer",uri:e[n].uri});for(let e=0;e<n.length;e++)n[e].uri&&n[e].uri.indexOf("data:image/")<0&&t.push({type:"image",uri:n[e].uri})}return t}static getAnimationClip(t,e,n,r){return ke.getAnimationClip(t,e,n,r)}static getAnimationTimeSpan(t,e){return ke.getTimeSpanByName(t,e)}static getTypedArrayCtor(t){return oe(t)}static readInterleavedArray(t,e,n,r,s,i,o){return pe(t,e,n,r,s,i,o)}j(t,e,n){this.gltf=e,this.glbBuffer=n,this.version=e.asset?+e.asset.version:1,this.rootPath=t,this.buffers={},this.requests={},this.options.requestImage=Le?ze.bind(this):this.options.requestImage||Fe,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new Oe(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this.u),this.adapter.iterate((t,e,n)=>{e.id="buffer_"+n},"buffers"),this.adapter.iterate((t,e,n)=>{e.id="image_"+n},"images"),this.adapter.iterate((t,e,n)=>{e.id="accessor_"+n},"accessors")):(this.adapter=new Me(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this.u),this.adapter.iterate((t,e,n)=>{e.id="accessor_"+n},"accessors"),this.adapter.iterate((t,e,n)=>{e.id="image_"+n},"images"))}J(t,e){if(t.children&&t.children.length>0){if(!("number"==typeof(n=t.children[0])&&isFinite(n)||se(t.children[0])))return t;const r=t.children.map(t=>{const n=e[t];return n.nodeIndex=t,this.J(n,e)});t.children=r}var n;return t}V(t){return this.K(t).then(t=>{const e=this.scenes=[];let n;for(const e in t)t[e]=this.J(t[e],t),t[e].nodeIndex=Number(e)?Number(e):e;this.adapter.iterate((r,s,i)=>{const o={};s.name&&(o.name=s.name),s.nodes&&(o.nodes=s.nodes.map(e=>t[e])),this.gltf.scene===r&&(n=i),e.push(o)},"scenes");const r={textures:this.gltf.textures,asset:this.gltf.asset,scene:n,scenes:e,nodes:t,meshes:this.meshes,materials:this.gltf.materials,skins:this.skins,extensionsRequired:this.gltf.extensionsRequired,extensionsUsed:this.gltf.extensionsUsed};if(this.gltf.extensions&&(r.extensions=this.gltf.extensions),1===this.version){const t=this.adapter.S(this.gltf.materials);r.materials=t}return delete this.gltf.buffers,r.json=this.gltf,r})}K(t){return this.Z(t).then(()=>{const t=this.nodes={};return this.adapter.iterate((e,n)=>{const r=this.adapter.createNode(n,this.meshes,this.skins);t[e]=r},"nodes"),t})}Y(){this.skins=[];const t=[];return this.adapter.iterate((e,n,r)=>{t.push(this.W(n).then(t=>{t.index=r,this.skins.push(t)}))},"skins"),t}W(t){const e=t.inverseBindMatrices;return this.adapter.accessor._("inverseBindMatrices",e).then(e=>(t.inverseBindMatrices=e,e&&e.buffer&&this.transferables&&this.transferables.indexOf(e.buffer)<0&&this.transferables.push(e.buffer),t))}$(){const t=this.gltf.animations;return re(t)?this.adapter.getAnimations(t):null}Z(t){this.meshes={};let e=[];return this.adapter.iterate((n,r,s)=>{e.push(this.tt(r,t).then(t=>{t.index=s,this.meshes[n]=t}))},"meshes"),e=e.concat(this.Y()),Promise.all(e)}tt(t,e){const n=t.primitives.map(t=>this.et(t,e)).filter(t=>!!t);return Promise.all(n).then(e=>{const n={};return ie(n,t),n.primitives=e,n})}X(){const t=this.gltf.textures;if(!t)return null;const e=[];for(const n in t)e.push(this.adapter.C(n));return Promise.all(e).then(e=>{if(this.transferables)for(let t=0;t<e.length;t++){const n=e[t].image.array;if(e[t]&&n){let t;t=n instanceof ImageBitmap?n:n.buffer,t&&this.transferables.indexOf(t)<0&&this.transferables.push(t)}}if(!Array.isArray(t)){const n={},r=Object.keys(t);for(let t=0;t<e.length;t++)e[t]&&(n[r[t]]=e[t]);return n}return e})}et(t,e){let n;const r=[],s=t.extensions;if(re(t.targets))for(let e=0;e<t.targets.length;e++){const n=t.targets[e];for(const t in n){const s=this.adapter.accessor._(`morphTargets_${t}_${e}`,n[t]);s&&r.push(s)}}if(s&&s.KHR_draco_mesh_compression){if(!this.options.decoders.draco&&(!this.gltf.extensionsRequired||!this.gltf.extensionsRequired.indexOf("KHR_draco_mesh_compression")<0))return null;const t=this.options.decoders.draco,{bufferView:i,attributes:o}=s.KHR_draco_mesh_compression,a=this.gltf.bufferViews[i],c=this.H.O(a).then(n=>{const{buffer:r,byteOffset:s}=n;let{byteOffset:i}=a;const c=a.byteLength;i||(i=0);const h=new DataView(r,s+i,c),u={attributes:o,useUniqueIDs:!1,skipAttributeTransform:e.skipAttributeTransform};return t(h,u).then(t=>{const e=Object.values(t.attributes);return t.indices&&e.push(t.indices),e})});r.push(c),n=Promise.all(r)}else{const e=t.attributes;for(const t in e){const n=this.adapter.accessor._(t,e[t]);n&&r.push(n)}if(re(t.indices)){const e=this.adapter.accessor._("indices",t.indices);e&&r.push(e)}n=Promise.all(r)}return n.then(e=>{if(s&&s.KHR_draco_mesh_compression){const n=t.targets?t.targets.length:0;e[n]=e[n].concat(e.slice(0,n)),e=e[n]}let n,r;const i={attributes:e.reduce((t,e)=>{if("indices"===e.name)n=e;else if(e.name.indexOf("morphTargets_")>-1)r=r||{},r[e.name.slice(13)]=e;else{if(!("POSITION"!==e.name||e.min&&e.max)){const t=[1/0,1/0,1/0],n=[-1/0,-1/0,-1/0],{itemSize:r,array:s}=e,i=s.length/r;for(let e=0;e<i;e++)for(let i=0;i<r;i++){const o=e*r+i;s[o]<t[i]&&(t[i]=s[o]),s[o]>n[i]&&(n[i]=s[o])}if(e.quantization){const r=e.quantization,s=r.range/(1<<r.quantizationBits),i=r.minValues;zt(t,t,s),Ft(t,t,i),zt(n,n,s),Ft(n,n,i)}e.min=t,e.max=n}t[e.name]=e}return this.transferables&&e.array.buffer&&this.transferables.indexOf(e.array.buffer)<0&&this.transferables.push(e.array.buffer),t},{}),material:t.material};return n&&(i.indices=n),r&&(i.morphTargets=r),i.mode=re(t.mode)?t.mode:4,re(t.extras)&&(i.extras=t.extras),i})}}function Fe(t,e,n){const r=new Image;r.crossOrigin="",r.onload=()=>{if(!Be)return void n(new Error("There is no canvas to draw image!"));Be.width=r.width,Be.height=r.height;const t=Be.getContext("2d",{willReadFrequently:!0});t.drawImage(r,0,0,r.width,r.height);const e=t.getImageData(0,0,r.width,r.height),s={width:r.width,height:r.height,data:new Uint8Array(e.data)};n(null,s)},r.onerror=function(t){n(t)},r.src=t}let De,je;function ze(t,e,n){De||(De=new OffscreenCanvas(2,2),je=De.getContext("2d",{willReadFrequently:!0}));let r=null;if(se(t))r=fetch(t,e).then(t=>t.arrayBuffer()).then(t=>{const e=new Blob([new Uint8Array(t)]);return createImageBitmap(e)});else{const e=new Blob([t]);r=createImageBitmap(e)}r.then(He.bind(this)).then(t=>{n(null,t)}).catch(t=>{console.warn(t),n(t)})}function He(t){let{width:e,height:n}=t;Ge(e)||(e=qe(e)),Ge(n)||(n=qe(n));const r=this.options.maxTextureSize;r&&(e=Math.min(r,e),n=Math.min(r,n)),De.width=e,De.height=n,je.drawImage(t,0,0,e,n),t.close();const s=je.getImageData(0,0,e,n);return{width:e,height:n,data:new Uint8Array(s.data)}}function Ge(t){return 0==(t&t-1)&&0!==t}function qe(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}const Ve="undefined"==typeof document?null:document.createElement("canvas");class $e extends s.worker.Actor{constructor(t,e){super(t),this.mapId=e}initialize(t){t(null)}loadTile(t,e,n){let r=null;e&&e.arraybuffer&&(r=[e.arraybuffer]);const s={mapId:this.mapId,layerId:t,command:"loadTile",params:e};this.send(s,r,n)}abortTileLoading(t,e,n){const r={mapId:this.mapId,layerId:t,command:"abortTileLoading",params:{url:e}};this.broadcast(r,null,n)}addLayer(t,e,n){const r={actorId:this.actorId,mapId:this.mapId,layerId:t,command:"addLayer",params:{options:e}};this.broadcast(r,null,n)}removeLayer(t,e){const n={mapId:this.mapId,layerId:t,command:"removeLayer"};this.broadcast(n,null,e)}requestImage({url:t},e){const n=new Image;n.onload=()=>{if(!this.isActive())return;if(!Ve)return void e(new Error("There is no canvas to draw image!"));const t=function(t){if(Xe(t.width)&&Xe(t.height))return t;let e=t.width,n=t.height;Xe(e)||(e=Je(e));Xe(n)||(n=Je(n));const r=document.createElement("canvas");r.width=e,r.height=n,r.getContext("2d").drawImage(t,0,0,e,n);const s=t.src,i=s.lastIndexOf("/")+1,o=s.substring(i);return console.warn(`Texture(${o})'s size is not power of two, resize from (${t.width}, ${t.height}) to (${e}, ${n})`),r}(n);Ve.width=t.width,Ve.height=t.height;const r=Ve.getContext("2d",{willReadFrequently:!0});r.drawImage(t,0,0,t.width,t.height);const s=r.getImageData(0,0,t.width,t.height),i={width:t.width,height:t.height,data:new Uint8Array(s.data)};e(null,i,[i.data.buffer])},n.onerror=function(t){e(t)},n.src=t}}function Xe(t){return 0==(t&t-1)&&0!==t}function Je(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}class Ke{constructor(t,e,n){this.nt=t,this.max=e,this.currentSize=0,this.onRemove=n,this.reset()}reset(){if(this.data){const t=this.data.values();for(const e of t)this.onRemove(e)}return this.data=new Map,this.currentSize=0,this}clear(){this.reset(),delete this.onRemove}add(t,e){if(!e)return this;if(e.node&&e.node.memorySize&&(this.currentSize+=e.node.memorySize),this.has(t)){const n=this.data.get(t);n&&n.node&&n.node.memorySize&&(this.currentSize-=n.node.memorySize),this.data.delete(t),this.data.set(t,e)}else this.data.set(t,e);return this}shrink(){if(this.currentSize>this.max){let t=!1;const e=this.data.keys();let n=e.next();for(;this.currentSize>this.max&&void 0!==n.value;){!t&&this.data.get(n.value).current&&(t=!0,console.warn(`layer(${this.nt})'s maxGPUMemory is not enough, one or more current tiles will be discarded.`));const r=this.getAndRemove(n.value);r&&this.onRemove(r),n=e.next()}}}has(t){return this.data.has(t)}keys(){const t=new Array(this.data.size);let e=0;const n=this.data.keys();for(const r of n)t[e++]=r;return t}getAndRemove(t){if(!this.has(t))return null;const e=this.data.get(t);return e.node&&e.node.memorySize&&(this.currentSize-=e.node.memorySize),this.data.delete(t),e}get(t){if(!this.has(t))return null;const e=this.data.get(t);return this.data.delete(t),this.data.set(t,e),e}remove(t){if(!this.has(t))return this;const e=this.data.get(t);return e.node&&e.node.memorySize&&(this.currentSize-=e.node.memorySize),this.data.delete(t),this.onRemove(e),this}setMaxSize(t){return this.max=t,this.shrink(),this}getMemorySize(){let t=0;const e=this.data.values();for(const n of e){const e=n&&n.node;e&&e.memorySize&&(t+=e.memorySize)}return t}markAll(t){const e=this.data.values();for(const n of e)n.current=t}}function Qe(t,e){if(t.scenes&&t.scenes.length)for(let n=0,r=t.scenes.length;n<r;n++){const r=t.scenes[n].nodes;for(let n=0,s=r.length;n<s;n++){const s=[];rn(r[n],s,t,e)}}}const Ze=[],Ye=[],We=[],tn=[0,0,0],en=Zt([]),nn=[1,1,1];function rn(t,e,n,r){const s=e.slice(0);if(t.matrix)s.push(t.matrix);else if(t.rotation||t.translation||t.scale){const e=Nt(Ze,t.translation||tn),n=Pt(Ye,t.rotation||en),r=Ct(We,t.scale||nn);Et(r,n,r);const i=Et([],e,r);s.push(i)}if(t.children&&t.children.length)for(let e=0,i=t.children.length;e<i;e++)rn(t.children[e],s,n,r);if(void 0!==t.mesh){const e=t.mesh,i=n.meshes[e];if(i){const t=s.slice(0),o=i.primitives;for(let s=0,i=o.length;s<i;s++){const i=o[s];i&&(i.matrices=t,r(i,e,s,n))}}}}function sn(t,e,n){let{byteOffset:r,byteStride:s}=e;const{componentType:i,itemSize:o}=e,a=e.array.buffer,c=i?Ue.getTypedArrayCtor(i):e.array.constructor;if(r=void 0===r?e.array.byteOffset:r,s=s||0,!s||s===o*c.BYTES_PER_ELEMENT&&r%c.BYTES_PER_ELEMENT==0){const e=new c(a,r+n*o*c.BYTES_PER_ELEMENT,o);return t.set(e),t}s||(s=o*c.BYTES_PER_ELEMENT);const h=new Uint8Array(a,s*n+r,o*c.BYTES_PER_ELEMENT);return new Uint8Array(t.buffer).set(h),t}function on(t,e,n,r){t[4*e]=n[r],t[4*e+1]=n[r+4],t[4*e+2]=n[r+8],t[4*e+3]=n[r+12]}var an="#include <gl2_vert>\n\nconst float SHIFT_RIGHT_11 = 1.0 / 2048.0;\n\nconst float SHIFT_RIGHT_5 = 1.0 / 32.0;\n\nconst float SHIFT_LEFT_11 = 2048.0;\n\nconst float SHIFT_LEFT_5 = 32.0;\n\nconst float NORMALIZE_6 = 1.0 / 64.0;\n\nconst float NORMALIZE_5 = 1.0 / 32.0;\n\n\n\n#ifdef HAS_POSITION\n\n attribute vec3 POSITION;\n\n#endif\n\n\n\n#if defined(HAS_RGB)\n\n attribute vec3 RGB;\n\n#elif defined(HAS_RGBA)\n\n attribute vec4 RGBA;\n\n#elif defined(HAS_RGB565)\n\n attribute float RGB565;\n\n#endif\n\n\n\nuniform vec4 pointColor;\n\nuniform float pointSize;\n\n\n\nuniform mat4 projViewModelMatrix;\n\nuniform float pointOpacity;\n\n\n\nvarying vec4 vColor;\n\n\n\n#ifdef HAS_NORMAL\n\n #ifdef HAS_NORMAL_OCT16P\n\n attribute vec2 NORMAL_OCT16P;\n\n float signNotZero(float value) {\n\n return value >= 0.0 ? 1.0 : -1.0;\n\n }\n\n vec2 signNotZero(vec2 value) {\n\n return vec2(signNotZero(value.x), signNotZero(value.y));\n\n }\n\n vec3 octDecode(vec2 encoded, float range) {\n\n if (encoded.x == 0.0 && encoded.y == 0.0) {\n\n return vec3(0.0, 0.0, 0.0);\n\n }\n\n encoded = encoded / range * 2.0 - 1.0;\n\n vec3 v = vec3(encoded.x, encoded.y, 1.0 - abs(encoded.x) - abs(encoded.y));\n\n if (v.z < 0.0) {\n\n v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);\n\n }\n\n return normalize(v);\n\n }\n\n vec3 octDecode(vec2 encoded) {\n\n return octDecode(encoded, 255.0);\n\n }\n\n #else\n\n attribute vec3 NORMAL;\n\n #endif\n\n uniform vec3 lightDir;\n\n uniform mat3 modelNormalMatrix;\n\n uniform mat4 positionMatrix;\n\n float getLambertDiffuse(vec3 lightDir, vec3 normal) {\n\n return max(dot(-lightDir, normal), 0.0);\n\n }\n\n#endif\n\n#ifdef PICKING_MODE\n\n #include <fbo_picking_vert>\n\n#endif\n\n#include <draco_decode_vert>\n\nvoid main() {\n\n #ifdef HAS_POSITION\n\n vec3 localPos = decode_getPosition(POSITION);\n\n #endif\n\n gl_Position = projViewModelMatrix * vec4(localPos, 1.0);\n\n gl_PointSize = pointSize;\n\n\n\n #ifdef PICKING_MODE\n\n fbo_picking_setData(gl_Position.w, true);\n\n #else\n\n #if defined(HAS_RGB)\n\n vColor = vec4(RGB / 255.0, 1.0) * pointOpacity;\n\n #elif defined(HAS_RGBA)\n\n vColor = RGBA / 255.0 * pointOpacity;\n\n #elif defined(HAS_RGB565)\n\n float compressed = RGB565;\n\n float r = floor(compressed * SHIFT_RIGHT_11);\n\n compressed -= r * SHIFT_LEFT_11;\n\n float g = floor(compressed * SHIFT_RIGHT_5);\n\n compressed -= g * SHIFT_LEFT_5;\n\n float b = compressed;\n\n vec3 rgb = vec3(r * NORMALIZE_5, g * NORMALIZE_6, b * NORMALIZE_5);\n\n vColor = vec4(rgb, 1.0);\n\n #else\n\n vColor = pointColor;\n\n #endif\n\n\n\n #ifdef HAS_NORMAL\n\n mat3 positionNormalMatrix = mat3(positionMatrix);\n\n mat3 normalMatrix = modelNormalMatrix * positionNormalMatrix;\n\n #ifdef HAS_NORMAL_OCT16P\n\n vec3 localNormal = octDecode(NORMAL_OCT16P);\n\n #else\n\n vec3 localNormal = NORMAL;\n\n #endif\n\n vec3 normal = normalize(normalMatrix * localNormal);\n\n float colorStrength = getLambertDiffuse(lightDir, normal);\n\n colorStrength = max(colorStrength, 0.5);\n\n vColor *= colorStrength;\n\n #endif\n\n #endif\n\n\n\n\n\n\n\n\n\n}\n\n";const cn=new Array(3),hn=new Array(3),un=[40680631590769,40680631590769,40408299984661.445];function ln(t,e,n,r){const s=un,i=Math.cos(n);cn[0]=i*Math.cos(e),cn[1]=i*Math.sin(e),cn[2]=Math.sin(n),Tn(cn,cn),jt(hn,s,cn);const o=Math.sqrt(Gt(cn,hn));var a,c,h;return c=hn,h=o,(a=hn)[0]=c[0]/h,a[1]=c[1]/h,a[2]=c[2]/h,zt(cn,cn,r),Ft(t,hn,cn)}const fn=[1/6378137,1/6378137,1/6356752.314245179],dn=[1/40680631590769,1/40680631590769,1/40408299984661.445],mn=new Array(3),pn=new Array(3),bn=new Array(3);function gn(t,e){const n=dn,r=function(t,e,n,r,s){const i=e[0],o=e[1],a=e[2],c=n[0],h=n[1],u=n[2],l=i*i*c*c,f=o*o*h*h,d=a*a*u*u,m=l+f+d,p=Math.sqrt(1/m),b=zt(yn,e,p);if(m<s)return isFinite(p)?b:void 0;const g=r[0],y=r[1],w=r[2],v=wn;v[0]=b[0]*g*2,v[1]=b[1]*y*2,v[2]=b[2]*w*2;let T,_,M,O,x,A,I,S,E,N,C,P=(1-p)*vn(e)/(.5*vn(v)),R=0;do{P-=R,M=1/(1+P*g),O=1/(1+P*y),x=1/(1+P*w),A=M*M,I=O*O,S=x*x,E=A*M,N=I*O,C=S*x,T=l*A+f*I+d*S-1,_=l*E*g+f*N*y+d*C*w;R=T/(-2*_)}while(Math.abs(T)>1e-12);return t[0]=i*M,t[1]=o*O,t[2]=a*x,t}(mn,e,fn,n,.1);let s=$t(pn,r,n);s=Tn(s,s);const i=Vt(bn,e,r),o=Math.atan2(s[1],s[0]),a=Math.asin(s[2]),c=dt(Gt(i,e))*vn(i);return t[0]=lt(o),t[1]=lt(a),t[2]=c,t}const yn=new Array(3),wn=new Array(3);function vn(t){return kt(t)}function Tn(t,e){const n=e[0],r=e[1],s=e[2];let i=n*n+r*r+s*s;return i>0&&(i=Math.sqrt(i),t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t}function _n(t,e){return jt(e,t,dn),Ht(e,e)}function Mn(t,e){const n=t[0],r=t[1],s=Math.cos(r),i=s*Math.cos(n),o=s*Math.sin(n),a=Math.sin(r);return e.x=i,e.y=o,e.z=a,Ht(e,e)}var On=Object.freeze({__proto__:null,radianToCartesian3:ln,cartesian3ToDegree:gn,normalizeCartesian:Tn,geodeticSurfaceNormal:_n,geodeticSurfaceNormalCartographic:Mn});function xn(t,e,n,r){n=n||0,r=r||n;const s=Math.abs(t-e);return s<=r||s<=n*Math.max(Math.abs(t),Math.abs(e))}function An(t,e){let n="";for(let r=0;r<4;r++){const s=t.getUint8(e+r);n+=String.fromCharCode(s)}return n}const In="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function Sn(t,e,n){const r=new Uint8Array(t,e,n);return In?JSON.parse(In.decode(r)):JSON.parse(pt(r))}function En(t,e,n){const r=new Uint8Array(t,e,n);return In?JSON.parse(In.decode(r)):JSON.parse(pt(r))}function Nn(t,e,n){return{offset:e,byteLength:n}}function Cn(t,e,n,r){const{byteOffset:s,componentType:i,type:o}=t,{ctor:a,type:c}=Un(i||"UNSIGNED_SHORT"),h=Ln(o);return{byteStride:0,byteOffset:s+n,itemSize:h,count:r*h,componentType:c,array:new a(e,n+s,r*h)}}function Pn(t,e,n,r){const s=Cn(t,e,n,r);return s.array.buffer.byteLength!==e.byteLength&&(s.array=s.array.slice()),s}function Rn(t,e,n,r){const{byteOffset:s,componentType:i,type:o}=t,{ctor:a}=Un(i||"UNSIGNED_SHORT"),c=Ln(o),h=new a(e,s,n*c);return 1===c?h[r]:h.subarray(r*c,r*c+c)}const kn={"SCALAR":1,"VEC2":2,"VEC3":3,"VEC4":4};function Ln(t){return t?kn[t]:1}const Bn={"BYTE":{ctor:Int8Array,type:5120,name:"Int8Array"},"UNSIGNED_BYTE":{ctor:Uint8Array,type:5121,name:"Uint8Array"},"SHORT":{ctor:Int16Array,type:5122,name:"Int16Array"},"UNSIGNED_SHORT":{ctor:Uint16Array,type:5123,name:"Uint16Array"},"INT":{ctor:Int32Array,type:5124,name:"Int32Array"},"UNSIGNED_INT":{ctor:Uint32Array,type:5125,name:"Uint32Array"},"FLOAT":{ctor:Float32Array,type:5126,name:"Float32Array"},"DOUBLE":{ctor:Float64Array,type:5126,name:"Float64Array"}};function Un(t){return Bn[t]}function Fn(t){for(const e in Bn)if(t===Bn[e].ctor)return Bn[e].type;throw new Error("unrecognized ctor:"+t)}function Dn(t,e,n,r){const s=t,i=e.length/3;for(let t=0;t<i;t++)s[3*t]=e[3*t]/65535*r[0]+n[0],s[3*t+1]=e[3*t+1]/65535*r[1]+n[1],s[3*t+2]=e[3*t+2]/65535*r[2]+n[2];return s}function jn(t,e,n){const r=t.getUint32(12,!0),s=t.getUint32(16,!0),i=t.getUint32(20,!0),o=t.getUint32(24,!0),a=t.buffer;let c,h={},u={},l=null;r>0&&(h=Sn(a,e,r),e+=r),s>0&&(c=function(t,e,n){return{offset:e,byteLength:n}}(0,e,s),e+=s),i>0&&(u=En(a,e,i),e+=i);const f=Nn(0,e,o);return l=a.slice(f.offset,f.offset+f.byteLength),n.push(l),{featureTable:h,featureTableBin:c,batchTable:u,batchTableBin:l}}const zn={up:{south:"east",north:"west",west:"south",east:"north"},down:{south:"west",north:"east",west:"north",east:"south"},south:{up:"west",down:"east",west:"down",east:"up"},north:{up:"east",down:"west",west:"up",east:"down"},west:{up:"north",down:"south",north:"down",south:"up"},east:{up:"south",down:"north",north:"up",south:"down"}},Hn={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},Gn={},qn={east:[],north:[],up:[],west:[],south:[],down:[]};let Vn=[],$n=[],Xn=[];const Jn=[0,0,0];function Kn(t,e,n){return n[0]=t[0],n[1]=t[1],n[2]=t[2],n[3]=t[3],n[4]=t[4],n[5]=t[5],n[6]=t[6],n[7]=t[7],n[8]=t[8],n[9]=t[9],n[10]=t[10],n[11]=t[11],n[12]=e[0],n[13]=e[1],n[14]=e[2],n[15]=t[15],n}const Qn=function(t,e){const n=zn[t][e];let r;const s=t+e;return Gn[s]?r=Gn[s]:(r=function(r,s,i){if(function(t,e){var n=t[0],r=t[1],s=t[2],i=e[0],o=e[1],a=e[2];return Math.abs(n-i)<=1e-6*Math.max(1,Math.abs(n),Math.abs(i))&&Math.abs(r-o)<=1e-6*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(s-a)<=1e-6*Math.max(1,Math.abs(s),Math.abs(a))}(r,Jn))Bt(Vn,Hn[t]),Bt($n,Hn[e]),Bt(Xn,Hn[n]);else if(xn(r[0],0,1e-14)&&xn(r[1],0,1e-14)){const s=dt(r[2]);Bt(Vn,Hn[t]),"east"!==t&&"west"!==t&&zt(Vn,Vn,s),Bt($n,Hn[e]),"east"!==e&&"west"!==e&&zt($n,$n,s),Bt(Xn,Hn[n]),"east"!==n&&"west"!==n&&zt(Xn,Xn,s)}else{_n(r,qn.up);const s=qn.up,i=qn.east;i[0]=-r[1],i[1]=r[0],i[2]=0,Ht(qn.east,i),qt(qn.north,s,i),zt(qn.down,qn.up,-1),zt(qn.west,qn.east,-1),zt(qn.south,qn.north,-1),Vn=qn[t],$n=qn[e],Xn=qn[n]}return i[0]=Vn[0],i[1]=Vn[1],i[2]=Vn[2],i[3]=0,i[4]=$n[0],i[5]=$n[1],i[6]=$n[2],i[7]=0,i[8]=Xn[0],i[9]=Xn[1],i[10]=Xn[2],i[11]=0,i[12]=r[0],i[13]=r[1],i[14]=r[2],i[15]=1,i},Gn[s]=r),r}("east","north"),Zn=[],Yn=[],Wn=[],tr=[],er=[],nr=[],rr=[],sr={x:0,y:0},ir={x:0,y:0},or=Math.PI/180;let ar;const cr={width:100,height:10};function hr(){if(!ar){const{width:t,height:e}=cr;OffscreenCanvas?ar=new OffscreenCanvas(t,e):(ar=document.createElement("canvas"),ar.width=t,ar.height=e)}return ar}class ur{constructor(t,e={}){if(!Array.isArray(t))return void console.error("colors is not array");if(t.length<2)return void console.error("colors.length should >1");this.colors=t;let n=1/0,r=-1/0;for(let e=0,s=t.length;e<s;e++){const s=t[e][0];n=Math.min(s,n),r=Math.max(s,r)}this.min=n,this.max=r,this.valueOffset=this.max-this.min,this.options=Object.assign({},cr,e),this.rt()}getImageData(){return this.imgData}rt(){const t=hr(),{width:e,height:n}=this.options;t.width=e,t.height=n;const r=t.getContext("2d");r.clearRect(0,0,t.width,t.height);const s=r.createLinearGradient(0,0,t.width,0),{colors:i,valueOffset:o}=this;for(let t=0,e=i.length;t<e;t++){const[e,n]=i[t],r=(e-this.min)/o;s.addColorStop(r,n)}r.fillStyle=s,r.fillRect(0,0,t.width,t.height),this.imgData=r.getImageData(0,0,t.width,t.height)}getColor(t){t=Math.max(this.min,t);const e=((t=Math.min(t,this.max))-this.min)/this.valueOffset;let n=Math.round(e*this.imgData.width);n=Math.min(n,this.imgData.width-1);const r=4*n;return[this.imgData.data[r],this.imgData.data[r+1],this.imgData.data[r+2],this.imgData.data[r+3]]}}var lr;function fr(t,e){for(let n=0;n<t.stops.length;n++)if(e===t.stops[n][0])return t.stops[n][1];return t.default}function dr(t,e){for(var n=0;n<t.stops.length&&!(e<t.stops[n][0]);n++);return t.stops[Math.max(n-1,0)][1]}function mr(t,e){for(var n=void 0!==t.base?t.base:1,r=0;!(r>=t.stops.length||e<=t.stops[r][0]);)r++;return 0===r?t.stops[r][1]:r===t.stops.length?t.stops[r-1][1]:function t(e,n,r,s,i,o){return"function"==typeof i?function(){var a=i.apply(void 0,arguments),c=o.apply(void 0,arguments);return t(e,n,r,s,a,c)}:i.length?function(t,e,n,r,s,i){var o=[];for(let a=0;a<s.length;a++)o[a]=yr(t,e,n,r,s[a],i[a]);return o}(e,n,r,s,i,o):yr(e,n,r,s,i,o)}(e,n,t.stops[r-1][0],t.stops[r][0],t.stops[r-1][1],t.stops[r][1])}"function"==typeof Map&&(lr=new Map);const pr={width:100,height:1};function br(t,e){const n=t.stops;if(n&&n.length>1){let t;if(lr){const e=JSON.stringify(n);if(!lr.has(e)){const t=new ur(n,pr);lr.set(e,t)}t=lr.get(e)}else t=new ur(n,pr);const[r,s,i,o]=t.getColor(e);return[r/255,s/255,i/255,o/255]}return n&&1===n.length?n[0][1]:null}function gr(t,e){return function(t,e,n){return void 0!==t?t:void 0!==e?e:void 0!==n?n:null}(e,t.default)}function yr(t,e,n,r,s,i){var o,a=r-n,c=t-n;return s*(1-(o=1===e?c/a:(Math.pow(e,c)-1)/(Math.pow(e,a)-1)))+i*o}function wr(t){return t&&"object"==typeof t&&(t.stops||t.property&&"identity"===t.type)}function vr(t){return function t(e,n){if(!wr(e))return function(){return e};e=JSON.parse(JSON.stringify(e));let r=!0,s=!0;const i=e.stops;if(i)for(let e=0;e<i.length;e++)if(wr(i[e][1])){const o=t(i[e][1],n);r=r&&o.isZoomConstant,s=s&&o.isFeatureConstant,i[e]=[i[e][0],o]}const o=function t(e,n){var r,s,i;if(wr(e)){var o,a=e.stops&&"object"==typeof e.stops[0][0],c=a||void 0!==e.property,h=a||!c,u=e.type||n||"exponential";if("exponential"===u)o=mr;else if("interval"===u)o=dr;else if("categorical"===u)o=fr;else if("identity"===u)o=gr;else{if("color-interpolate"!==u)throw new Error('Unknown function type "'+u+'"');o=br}if(a){var l={},f=[];for(let t=0;t<e.stops.length;t++){var d=e.stops[t];void 0===l[d[0].zoom]&&(l[d[0].zoom]={zoom:d[0].zoom,type:e.type,property:e.property,default:e.default,stops:[]}),l[d[0].zoom].stops.push([d[0].value,d[1]])}for(let e in l)f.push([l[e].zoom,t(l[e])]);r=function(t,n){const r=mr({stops:f,base:e.base},t)(t,n);return"function"==typeof r?r(t,n):r},s=!1,i=!1}else h?(r=function(t){const n=o(e,t);return"function"==typeof n?n(t):n},s=!0,i=!1):(r=function(t,n){const r=o(e,n?n[e.property]:null);return"function"==typeof r?r(t,n):r},s=!1,i=!0)}else r=function(){return e},s=!0,i=!0;return r.isZoomConstant=i,r.isFeatureConstant=s,r}(e,n);return o.isZoomConstant=r&&o.isZoomConstant,o.isFeatureConstant=s&&o.isFeatureConstant,o}(t,"exponential")}const{getTextureMagFilter:Tr,getTextureMinFilter:_r,getTextureWrap:Mr,getMaterialType:Or,getMaterialFormat:xr,getPrimitive:Ar,getUniqueREGLBuffer:Ir}=n.reshader.REGLHelper,Sr=[1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],Er=[0,0,1,0,0,1,0,0,-1,0,0,0,0,0,0,1],{loginIBLResOnCanvas:Nr,logoutIBLResOnCanvas:Cr,getIBLResOnCanvas:Pr,getPBRUniforms:Rr}=n.reshader.pbr.PBRUtils,kr={factor:0,units:0},Lr=[1,1,1,1],Br=[0,0,0],Ur={specularStrength:0,materialShininess:1},Fr=[1,1,1],Dr=n.mat4.identity([]),jr=[0,0],zr=t=>t.material instanceof n.reshader.PhongMaterial,Hr=t=>t.material instanceof n.reshader.pbr.StandardMaterial,Gr=[],qr=new s.Coordinate(0,0),Vr=new s.Point(0,0),$r=new s.Point(0,0),Xr=new s.Point(0,0),Jr=[],Kr=[],Qr=[],Zr=[],Yr=[],Wr=[],ts=[],es=[0,0,0],ns=[],rs=[],ss={"POSITION":"POSITION","NORMAL":"NORMAL","TEXCOORD_0":"TEXCOORD_0","TEXCOORD_1":"TEXCOORD_1","COLOR_0":"COLOR_0","TANGENT":"TANGENT","_BATCHID":"_BATCHID"},is=[0,1,1,2,2,3,3,0,0,4,1,5,2,6,3,7,4,5,5,6,6,7,7,4],os=function(t,e){const n=2*Math.PI/t,r=[],s=[];for(let s=0;s<=t;s++){const t=Math.cos(n*s)*e,i=Math.sin(n*s)*e,o=0;r[3*s]=t,r[3*s+1]=i,r[3*s+2]=o}for(let s=t;s<=2*t;s++){const t=Math.cos(n*s)*e,i=Math.sin(n*s)*e,o=0;r[3*s]=o,r[3*s+1]=t,r[3*s+2]=i}for(let s=2*t;s<=3*t;s++){const t=Math.cos(n*s)*e,i=Math.sin(n*s)*e,o=0;r[3*s]=t,r[3*s+1]=o,r[3*s+2]=i}const i=r.length/3-1;for(let e=0;e<i;e++)e!==t-1&&e!==2*t-1&&(s[2*e]=e,s[2*e+1]=e+1);return r.push(0,0,0),r.push(e,0,0),r.push(0,e,0),r.push(0,0,e),s.push(i+1,i+2),s.push(i+1,i+3),s.push(i+1,i+4),{vertices:r,indices:s}}
|
|
18
|
+
let ee=0;function ne(t){return null==t}function re(t){return!ne(t)}function se(t){return!ne(t)&&("string"==typeof t||null!==t.constructor&&t.constructor===String)}function ie(t){for(let e=1;e<arguments.length;e++){const n=arguments[e];for(const e in n)t[e]=n[e]}return t}function oe(t){switch(t){case 5120:return Int8Array;case 5121:return Uint8Array;case 5122:return Int16Array;case 5123:return Uint16Array;case 5124:return Int32Array;case 5125:return Uint32Array;case 5126:return Float32Array}throw new Error("unsupported bufferView's component type: "+t)}function ae(t){return 0===t.indexOf("data:")&&t.indexOf("base64,")>0}function ce(t){const e=function(t){return"undefined"!=typeof self?self.atob(t):window.atob(t)}(t.substring(t.indexOf(",")+1)),n=e.length,r=new Uint8Array(n);for(let t=0;t<n;t++)r[t]=e.charCodeAt(t);return r.buffer}const he=[],ue=[],le=[],fe=[0,0,0],de=Zt([]),me=[1,1,1];function pe(t,e,n,r,s,i,o){const a=oe(o);if((0===s||s===r*a.BYTES_PER_ELEMENT)&&i%a.BYTES_PER_ELEMENT==0){const s=new a(e,i,n*r);return t.set(s),t}0===s&&(s=r*a.BYTES_PER_ELEMENT);const c=new Uint8Array(r*a.BYTES_PER_ELEMENT);for(let o=0;o<n;o++){let n=null;const h=new Uint8Array(e,s*o+i,r*a.BYTES_PER_ELEMENT);c.set(h),n=new a(c.buffer,0,r);for(let e=0;e<r;e++)t[o*r+e]=n[e]}return t}const be="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function ge(t,e,n){const r=new Uint8Array(t,e,n);return be.decode(r)}const ye={get:function(t,e={}){e||(e={});const n=new AbortController,r=n.signal,s=ie({},e);s.signal=r,s.method||(s.method="GET");const i=fetch(t,s).then(t=>{const n=this.s(t,e.responseType);return n.message?n:n.then(n=>"arraybuffer"===e.responseType?{data:n,cacheControl:t.headers.get("Cache-Control"),expires:t.headers.get("Expires"),contentType:t.headers.get("Content-Type")}:n).catch(t=>{if(!t.code||t.code!==DOMException.ABORT_ERR)throw t})}).catch(t=>{if(!t.code||t.code!==DOMException.ABORT_ERR)throw t});return i.xhr=n,i},s:(t,e)=>200!==t.status?{status:t.status,statusText:t.statusText,message:`incorrect http request with status code(${t.status}): ${t.statusText}`}:"arraybuffer"===e?t.arrayBuffer():"json"===e?t.json():t.text(),getArrayBuffer:(t,e={})=>(e||(e={}),e.responseType="arraybuffer",ye.get(t,e)),getJSON:function(t,e={}){return e&&e.jsonp?ye.jsonp(t):((e=e||{}).responseType="json",ye.get(t,e))},jsonp:function(t){const e="_maptalks_jsonp_"+ee++;t.match(/\?/)?t+="&callback="+e:t+="?callback="+e;let n=document.createElement("script");return n.type="text/javascript",n.src=t,new Promise(t=>{window[e]=function(r){document.getElementsByTagName("head")[0].removeChild(n),n=null,delete window[e],t(r)},document.getElementsByTagName("head")[0].appendChild(n)})}};class we{constructor(t,e,n,r){this.i=t,this.decoders=e,this.o=n,this.images={},this.h={},this.u=r||{}}requestImageFromBufferURI(t,e,n){if(this.buffers[t.id]){const r=this.buffers[t.id],s=this.m(e,r);return this.getImageByBuffer(s,n)}if(this.h[t.id])return this.h[t.id].then(()=>{const r=this.buffers[t.id],s=this.m(e,r);return this.getImageByBuffer(s,n)});if(ae(t.uri)){const r=this.buffers[t.id]=ce(t.uri),s=this.m(e,r);return this.getImageByBuffer(s,n)}let r;const s=t.uri.indexOf("blob:")>=0;return r=t.uri.indexOf("://")>0||s?t.uri:this.rootPath+"/"+t.uri,this.h[t.id]=ye.getArrayBuffer(r,this.u).then(r=>{const s=this.buffers[t.id]=r.data,i=this.m(e,s);return this.getImageByBuffer(i,n)})}getImageByBuffer(t,e){if(this.images[e.id])return Promise.resolve(this.images[e.id]);const n=this.decoders;return n[e.mimeType]?n[e.mimeType](t,{supportedFormats:this.o}):"image/crn"===e.mimeType||"image/ktx2"===e.mimeType||"image/cttf"===e.mimeType?(console.warn("missing transcoder for "+e.mimeType,", visit https://maptalks.com/docs/transcoders for details"),Promise.resolve(null)):this.p(e.id,t)}requestExternalImage(t){if(this.images[t.id])return Promise.resolve(this.images[t.id]);const e=0===t.uri.indexOf("data:image/")?t.uri:this.rootPath+"/"+t.uri;return this.h[t.id]?this.h[t.id].then(()=>this.images[t.id]):this.h[t.id]=this.p(t.id,e)}p(t,e){return new Promise((n,r)=>{this.i(e,this.u,(s,i)=>{s?r(s):(URL.revokeObjectURL(e),this.images[t]=i,n(this.images[t]))})})}}const ve=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],Te=[];class _e{constructor(t,e,n,r){this.rootPath=t,this.gltf=e,this.v=!1,this.glbBuffer=n,this.buffers={},this.requests={},this.accessors={},this.T(),this.u=r}_(t,e){const n=this.gltf,r=n.accessors[e];if(void 0===r.bufferView)return this.accessors[r.id]=this.M(t,e,null,0),Promise.resolve(this.accessors[r.id]);if(r&&this.accessors[r.id])return Promise.resolve(this.accessors[r.id]);const s=n.bufferViews[r.bufferView];return this.O(s).then(n=>{const{buffer:s,byteOffset:i}=n;return this.accessors[r.id]=this.M(t,e,s,i)})}O(t){const e=this.gltf.buffers[t.buffer];if(this.buffers[e.id]){const t=this.buffers[e.id];return Promise.resolve({buffer:t,byteOffset:0})}if(this.requests[e.id])return this.requests[e.id].then(()=>{const t=this.buffers[e.id];return Promise.resolve({buffer:t,byteOffset:0})});if("binary_glTF"!==t.buffer&&"KHR_binary_glTF"!==t.buffer&&e.uri){if(ae(e.uri)){const t=this.buffers[e.id]=ce(e.uri);return Promise.resolve({buffer:t,byteOffset:0})}let t;const n=e.uri.indexOf("blob:")>=0;return t=e.uri.indexOf("://")>0||n?e.uri:this.rootPath+"/"+e.uri,this.requests[e.id]=ye.getArrayBuffer(t,this.u).then(r=>(n&&URL.revokeObjectURL(t),{buffer:this.buffers[e.id]=r.data,byteOffset:0}))}return Promise.resolve({buffer:this.glbBuffer.buffer,byteOffset:this.glbBuffer.byteOffset})}M(t,e,n,r=0){const s=this.gltf,i=s.accessors[e],o=void 0!==i.bufferView?s.bufferViews[i.bufferView]:{},a=(o.byteOffset||0)+r,c=this.A(i.type),h=oe(i.componentType),u=o.byteStride||0,l={array:void 0,name:t,accessorName:e,byteLength:i.count*c*h.BYTES_PER_ELEMENT,componentType:i.componentType,count:i.count,type:i.type,itemSize:c,max:i.max,min:i.min,extensions:i.extensions};if(i.min&&(l.min=i.min),i.max&&(l.max=i.max),n)if(this.v)l.byteStride=u,l.byteOffset=a+(i.byteOffset||0),!u||u===c*h.BYTES_PER_ELEMENT||"indices"===t||"input"===t||"output"===t||t.indexOf("morph")>=0?(l.array=this.I(n,i.count,c,a+(i.byteOffset||0),h),l.array.buffer.byteLength===l.byteLength&&(l.byteOffset=0)):l.array=new Uint8Array(n,a,o.byteLength);else if(i.interleaved){l.byteStride=0,l.byteOffset=0;const t=new h(i.count*c);if(l.array=pe(t,n,i.count,c,u,a+(i.byteOffset||0),i.componentType),l.extensions&&l.extensions.WEB3D_quantized_attributes&&c>2){const t=new Float32Array(l.array.length),{decodeMatrix:e}=l.extensions.WEB3D_quantized_attributes;for(let n=0;n<l.array.length;n+=c){Te[0]=l.array[n],Te[1]=l.array[n+1],Te[2]=l.array[n+2],Te[3]=1;const r=Kt(Te,Te,e);t[n]=r[0],t[n+1]=r[1],t[n+2]=r[2]}l.componentType=5126,l.array=t}}else l.byteStride=0,l.array=this.I(n,i.count,c,a+(i.byteOffset||0),h),l.byteOffset=l.array.byteOffset;else{l.array=new h(i.count);const t=l.min||l.max;t&&(l.array[0]=t[0],l.array[1]=t[1],l.array[2]=t[2])}return l}T(){const t=this.gltf.accessors;if(Array.isArray(t))for(let e=0;e<t.length;e++)for(let n=0;n<t.length;n++)e!==n&&t[e].bufferView===t[n].bufferView&&(t[e].interleaved=t[n].interleaved=!0);else for(const e in t)for(const n in t)e!==n&&t[e].bufferView===t[n].bufferView&&(t[e].interleaved=t[n].interleaved=!0)}I(t,e,n,r,s){return r%s.BYTES_PER_ELEMENT!=0&&(t=t.slice(r,r+e*n*s.BYTES_PER_ELEMENT),r=0),new s(t,r,n*e)}A(t){const e=ve.indexOf(t);return ve[e+1]}requestKHRTechniquesWebgl(t){const{shaders:e}=t,n=e.map(t=>{if(void 0!==t.bufferView){const e=this.gltf.bufferViews[t.bufferView],{byteLength:n}=e;return this.O(e).then(r=>{const{buffer:s,byteOffset:i}=r,o=ge(s,i+(e.byteOffset||0),n);return t.content=o,t})}if(t.uri){if(ae(t.uri)){const e=ce(t.uri),n=ge(e,0,e.byteLength);return t.content=n,Promise.resolve(t)}{const e=this.rootPath+"/"+t.uri;return ye.get(e,this.u).then(e=>(t.content=e,t))}}return Promise.resolve(t)});return Promise.all(n).then(()=>t)}}class Me extends we{constructor(t,e,n,r,s,i,o){super(r,s,i,o),this.rootPath=t,this.gltf=e,this.requests={},this.buffers={},this.glbBuffer=n,this.accessor=new _e(t,e,n,o)}iterate(t,e){const n=this.gltf[e];if(!n)return;let r=0;for(const e in n)t(e,n[e],r++)}createNode(t){const e={};if(re(t.name)&&(e.name=t.name),re(t.children)&&(e.children=t.children),re(t.jointName)&&(e.jointName=t.jointName),re(t.matrix)&&(e.matrix=t.matrix),re(t.rotation)&&(e.rotation=t.rotation),re(t.scale)&&(e.scale=t.scale),re(t.translation)&&(e.translation=t.translation),re(t.extras)&&(e.extras=t.extras),re(t.meshes)&&(e.mesh=t.meshes[0]),e.translation||e.rotation||e.scale){const t=function(t,e){if(e.matrix)return e.matrix;if(e.translation||e.scale||e.rotation){const n=Nt(he,e.translation||fe),r=Pt(ue,e.rotation||de),s=Ct(le,e.scale||me);return Et(s,r,s),Et(t,n,s)}return St(t)}([],e);delete e.translation,delete e.rotation,delete e.scale,e.matrix=t}return e}S(t){const e={};for(const n in t){const r=t[n];let s,i;r.instanceTechnique&&r.instanceTechnique.values?(s=r.instanceTechnique,i=s.values.diffuse):(s=r,i=s.values.tex||s.values.diffuseTex||s.values.diffuse);const o={baseColorTexture:{index:i}};r.name&&(o.name=r.name),r.extensions&&(o.extensions=r.extensions),r.extras&&(o.extras=r.extras),e[n]=o}return e}N(t){if(t.bufferView||t.extensions&&(t.extensions.KHR_binary_glTF||t.extensions.binary_glTF)){const e=t.bufferView?t:t.extensions.KHR_binary_glTF||t.extensions.binary_glTF;t.extensions&&(t.mimeType=e.mimeType,t.width=e.width,t.height=e.height);const n=this.gltf.bufferViews[e.bufferView],r=(n.byteOffset||0)+this.glbBuffer.byteOffset,s=n.byteLength,i=this.buffers[e.bufferView]=new Uint8Array(this.glbBuffer.buffer,r,s);return this.getImageByBuffer(i,t)}return this.requestExternalImage(t)}C(t){const e=this.gltf.textures[t];if(!e)return null;const n=this.gltf.images[e.source];return this.N(n).then(t=>{const r=this.gltf.samplers[e.sampler];return{image:{array:t.data,width:t.width,height:t.height,index:e.source,mimeType:n.mimeType,name:n.name,extras:n.extras},sampler:r}})}getBaseColorTexture(t){const e=this.gltf.materials[t];let n,r;if(e.instanceTechnique&&e.instanceTechnique.values?(n=e.instanceTechnique,r=n.values.diffuse):(n=e,r=n.values.tex||n.values.diffuseTex||n.values.diffuse),void 0===r||void 0===this.gltf.textures)return null;const s=this.gltf.textures[r];if(!s)return null;const i=this.gltf.samplers[s.sampler];return{format:s.format||6408,internalFormat:s.internalFormat||6408,type:s.type||5121,sampler:i,source:this.gltf.images[s.source]}}getMaterial(){return null}getAnimations(){return null}}class Oe extends we{constructor(t,e,n,r,s,i,o){super(r,s,i,o),this.rootPath=t,this.gltf=e,this.glbBuffer=n,this.buffers={},this.requests={},this.accessor=new _e(t,e,n,o)}iterate(t,e){const n=this.gltf[e];if(n)for(let e=0;e<n.length;e++)t(e,n[e],e)}createNode(t){const e={};return ie(e,t),!re(t.weights)&&this.gltf.meshes&&re(e.mesh)?e.weights=this.gltf.meshes[e.mesh].weights:t.weights&&(e.weights=t.weights),e}C(t){const e=this.gltf.textures[t];if(!e)return null;let n=e.source;if(e.extensions&&e.extensions.EXT_texture_webp&&(n=e.extensions.EXT_texture_webp.source),!re(n))return null;const r=this.gltf.images[n];return this.N(r).then(t=>{if(!t)return null;const n={image:{array:t.data,mipmap:t.mipmap,width:t.width,height:t.height,index:e.source,mimeType:r.mimeType,name:r.name,extensions:r.extensions,extras:r.extras}};ie(n,e);const s=re(e.sampler)?this.gltf.samplers[e.sampler]:void 0;return s&&(n.sampler=s,n.sampler.magFilter=s.magFilter||9729,n.sampler.minFilter=s.minFilter||9729,n.sampler.wrapS=s.wrapS||10497,n.sampler.wrapT=s.wrapT||10497),t.format&&(n.format=t.format),n})}N(t){if(!re(t.bufferView))return this.requestExternalImage(t);{const e=this.gltf.bufferViews[t.bufferView],n=this.gltf.buffers[e.buffer];if(n.uri)return this.requestImageFromBufferURI(n,e,t);if(this.glbBuffer)return this.P(e,t)}return null}P(t,e){const n=this.m(t,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(n,e)}m(t,e,n){n=n||0;const r=t.byteOffset+n,s=t.byteLength;return new Uint8Array(e,r,s)}R(t,e){const n=new Array(t.byteLength);for(let e=0;e<t.byteLength;e++)n[e]=String.fromCharCode(t[e]);return n.join(""),"data:"+(e=e||"image/png")+";base64,"+function(t){return"undefined"!=typeof self?self.btoa(t):window.btoa(t)}(unescape(encodeURIComponent(n)))}getAnimations(t){const e=[];return t.forEach(t=>{e.push(this.getSamplers(t.samplers))}),Promise.all(e).then(e=>{for(let n=0;n<e.length;n++)t[n].samplers=e[n];return t})}getSamplers(t){const e=[];for(let n=0;n<t.length;n++)(re(t[n].input)||re(t[n].output))&&(e.push(this.accessor._("input",t[n].input)),e.push(this.accessor._("output",t[n].output)));return Promise.all(e).then(e=>{for(let n=0;n<e.length/2;n++)t[n].input=e[2*n],t[n].output=e[2*n+1],t[n].interpolation||(t[n].interpolation="LINEAR");return t})}}const xe="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class Ae{static read(t,e=0,n=0){n||(n=t.byteLength);const r=new DataView(t,e,n),s=r.getUint32(4,!0);if(1===s)return Ae.readV1(r,e);if(2===s)return Ae.readV2(t,e);throw new Error("Unsupported glb version : "+s)}static readV1(t,e){const n=t.getUint32(8,!0),r=t.getUint32(12,!0);if(n!==t.byteLength)throw new Error("Length in GLB header is inconsistent with glb's byte length.");const s=Ie(t.buffer,20+e,r);return{json:JSON.parse(s),glbBuffer:{byteOffset:20+e+r,buffer:t.buffer,byteLength:n}}}static readV2(t,e){let n,r,s;const i=new DataView(t,e+12);let o=0;for(;o<i.byteLength;){const a=i.getUint32(o,!0);o+=4;const c=i.getUint32(o,!0);if(o+=4,1313821514===c)n=Ie(t,e+12+o,a);else if(5130562===c){s=e+12+o,r=a;break}o+=a}return{json:JSON.parse(n),glbBuffer:{byteOffset:s,buffer:t,byteLength:r}}}}function Ie(t,e,n){if(xe){const r=new Uint8Array(t,e,n);return xe.decode(r)}return function(t){const e=t.length;let n="";for(let r=0;r<e;){let s=t[r++];if(128&s){let n=Se[s>>3&7];if(!(64&s)||!n||r+n>e)return null;for(s&=63>>n;n>0;n-=1){const e=t[r++];if(128!=(192&e))return null;s=s<<6|63&e}}n+=String.fromCharCode(s)}return n}(new Uint8Array(t,e,n))}const Se=[1,1,1,1,2,2,3,0],Ee=[0,0,0],Ne=[0,0,0,1],Ce=[1,1,1],Pe={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},Re={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},ke={k(t,e,n,r,s,i,o,a){const c=re(t)?e.animations:[e.animations[0]],h={};for(let e=0;e<c.length;e++){const u=c[e],l=u.name||e;if(re(t)&&l!==t)continue;const f=u.channelsMap[n];if(f)for(let t=0;t<f.length;t++){const e=f[t];"translation"===e.target.path?(this.L(s,u.samplers[e.sampler],r,1),h.translation=Bt(Ee,s)):"rotation"===e.target.path?(this.B(i,u.samplers[e.sampler],r,1),h.rotation=te(Ne,i)):"scale"===e.target.path?(this.L(o,u.samplers[e.sampler],r,1),h.scale=Bt(Ce,o)):"weights"===e.target.path&&a&&(this.L(a,u.samplers[e.sampler],r,a.length),h.weights=a)}}return h},L(t,e,n,r){switch(e.interpolation){case"LINEAR":{const s=this.U(Re,e,n,1*r);s&&(t=function(t,e,n,r){for(let s=0;s<t.length;s++)t[s]=e[s]+r*(n[s]-e[s]);return t}(t,s.PREVIOUS,s.NEXT,s.INTERPOLATION));break}case"STEP":{const s=this.U(Re,e,n,1*r);s&&(t=function(t,e){for(let n=0;n<t.length;n++)t[n]=e[n];return t}(t,...s.PREVIOUS));break}case"CUBICSPLINE":{const s=this.U(Re,e,n,3*r);s&&(t=this.F(t,s,e.input.array,3*r));break}}return t},B(t,e,n){switch(e.interpolation){case"LINEAR":{const r=this.U(Re,e,n,1);r&&Yt(t,r.PREVIOUS,r.NEXT,r.INTERPOLATION);break}case"STEP":{const r=this.U(Re,e,n,1);r&&(t=Jt(t,...r.PREVIOUS));break}case"CUBICSPLINE":{const r=this.U(Re,e,n,3);if(r){for(let t=0;t<r.PREVIOUS.length;t++)r.PREVIOUS[t]=Math.acos(r.PREVIOUS[t]),r.NEXT[t]=Math.acos(r.NEXT[t]);t=this.F(t,r,e.input.array,3);for(let e=0;e<t.length;e++)t[e]=Math.cos(t[e])}break}}return t},D(t,e){const n=t.length;let r,s,i,o=0,a=n-1,c=Math.floor((o+a)/2);for(;o<=n-1&&a>=0;){if(o===a)return null;if(t[c]<=e&&e<=t[c+1]){const n=t[c];return r=c,s=c+1,i=(e-n)/(t[c+1]-n),{preIndx:r,nextIndex:s,interpolation:i}}e<t[c]?(a=c,c=Math.floor((o+a)/2)):t[c+1]<e&&(o=c,c=Math.floor((o+a)/2))}return null},U(t,e,n,r){const s=e.input.array,i=e.output.array,o=e.output.itemSize;(n<s[0]||n>s[s.length-1])&&(n=Math.max(s[0],Math.min(s[s.length-1],n))),n===s[s.length-1]&&(n=s[0]);const a=this.D(s,n);if(!a||!a.nextIndex)return null;const{preIndx:c,nextIndex:h,interpolation:u}=a;t.PREINDEX=c,t.NEXTINDEX=h,t.INTERPOLATION=u;const l=o*r;return t.PREVIOUS=i.subarray(t.PREINDEX*l,(t.PREINDEX+1)*l),t.NEXT=i.subarray(t.NEXTINDEX*l,(t.NEXTINDEX+1)*l),t},F(t,e,n,r){const s=e.INTERPOLATION,i=n[e.PREINDEX],o=n[e.NEXTINDEX];for(let n=0;n<3;n++){const a=e.PREVIOUS[r+n],c=(o-i)*e.PREVIOUS[2*r+n],h=e.NEXT[3+n],u=(o-i)*e.NEXT[n],l=(2*Math.pow(s,3)-3*Math.pow(s,2)+1)*a+(Math.pow(s,3)-2*Math.pow(s,2)+s)*c+(2*-Math.pow(s,3)+3*Math.pow(s,2))*h+(Math.pow(s,3)-Math.pow(s,2))*u;t[n]=l}return t},getAnimationClip(t,e,n,r){const s=t.nodes[e]&&t.nodes[e].weights;return Ut(Ee,...Pe.TRANSLATION),Jt(Ne,...Pe.ROTATION),Ut(Ce,...Pe.SCALE),this.k(r,t,e,n,Ee,Ne,Ce,s)},getTimeSpan(t){if(!t.animations)return null;if(t.timeSpan)return t.timeSpan;const e=t.animations;return t.timeSpan={},e.forEach((e,n)=>{let r=-1/0,s=1/0;const i=e.channels;for(let t=0;t<i.length;t++){const n=i[t],o=e.samplers[n.sampler].input.array;o[o.length-1]>r&&(r=o[o.length-1]),o[0]<s&&(s=o[0])}const o=e.name||n;t.timeSpan[o]={max:r,min:s}}),t.timeSpan},getTimeSpanByName(t,e){const n=this.getTimeSpan(t);return n?re(e)?n[e]:n[Object.keys(n)[0]]:null}};let Le=!1;if("undefined"!=typeof OffscreenCanvas){let t;try{t=new OffscreenCanvas(2,2).getContext("2d")}catch(fs){}t&&"undefined"!=typeof createImageBitmap&&(Le=!0)}const Be="undefined"==typeof document?null:document.createElement("canvas");class Ue{constructor(t,e,n){if(this.options=n||{},this.options.decoders||(this.options.decoders={}),this.u=this.options.fetchOptions||{},e.buffer instanceof ArrayBuffer){const{json:n,glbBuffer:r}=Ae.read(e.buffer,e.byteOffset,e.byteLength);this.j(t,n,r)}else this.j(t,e);this.H=new _e(this.rootPath,this.gltf,this.glbBuffer,this.u),this.G()}G(){const t=this.gltf.extensionsRequired;if(t){if(t.indexOf("KHR_draco_mesh_compression")>=0&&!this.options.decoders.draco)throw new Error("KHR_draco_mesh_compression is required but @maptalks/transcoders.draco is not loaded");if(t.indexOf("KHR_texture_basisu")>=0&&!this.options.decoders.ktx2)throw new Error("KHR_texture_basisu is required but @maptalks/transcoders.ktx2 is not loaded")}}q(){const t=this.gltf.extensions;return t&&t.KHR_techniques_webgl?this.H.requestKHRTechniquesWebgl(t.KHR_techniques_webgl).then(e=>(t.KHR_techniques_webgl=e,t)):Promise.resolve(t)}load(t){t=t||{};const e=this.V(t),n=this.$(),r=this.X(),s=this.q();return Promise.all([e,n,r,s]).then(t=>(t[0].animations=t[1],t[0].textures=t[2],t[0].extensions=t[3],t[0].transferables=this.transferables||[],this.createChannelsMap(t[0]),t[0]))}createChannelsMap(t){const e=t.animations;if(e)for(let t=0;t<e.length;t++){const n=e[t];n.channelsMap={};for(let t=0;t<n.channels.length;t++){const e=n.channels[t];n.channelsMap[e.target.node]||(n.channelsMap[e.target.node]=[]),n.channelsMap[e.target.node].push(e)}}}getExternalResources(){const t=[];if(this.gltf){const{buffers:e,images:n}=this.gltf;for(let n=0;n<e.length;n++)e[n].uri&&e[n].uri.indexOf("data:application/octet-stream;base64")<0&&t.push({type:"buffer",uri:e[n].uri});for(let e=0;e<n.length;e++)n[e].uri&&n[e].uri.indexOf("data:image/")<0&&t.push({type:"image",uri:n[e].uri})}return t}static getAnimationClip(t,e,n,r){return ke.getAnimationClip(t,e,n,r)}static getAnimationTimeSpan(t,e){return ke.getTimeSpanByName(t,e)}static getTypedArrayCtor(t){return oe(t)}static readInterleavedArray(t,e,n,r,s,i,o){return pe(t,e,n,r,s,i,o)}j(t,e,n){this.gltf=e,this.glbBuffer=n,this.version=e.asset?+e.asset.version:1,this.rootPath=t,this.buffers={},this.requests={},this.options.requestImage=Le?ze.bind(this):this.options.requestImage||Fe,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new Oe(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this.u),this.adapter.iterate((t,e,n)=>{e.id="buffer_"+n},"buffers"),this.adapter.iterate((t,e,n)=>{e.id="image_"+n},"images"),this.adapter.iterate((t,e,n)=>{e.id="accessor_"+n},"accessors")):(this.adapter=new Me(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this.u),this.adapter.iterate((t,e,n)=>{e.id="accessor_"+n},"accessors"),this.adapter.iterate((t,e,n)=>{e.id="image_"+n},"images"))}J(t,e){if(t.children&&t.children.length>0){if(!("number"==typeof(n=t.children[0])&&isFinite(n)||se(t.children[0])))return t;const r=t.children.map(t=>{const n=e[t];return n.nodeIndex=t,this.J(n,e)});t.children=r}var n;return t}V(t){return this.K(t).then(t=>{const e=this.scenes=[];let n;for(const e in t)t[e]=this.J(t[e],t),t[e].nodeIndex=Number(e)?Number(e):e;this.adapter.iterate((r,s,i)=>{const o={};s.name&&(o.name=s.name),s.nodes&&(o.nodes=s.nodes.map(e=>t[e])),this.gltf.scene===r&&(n=i),e.push(o)},"scenes");const r={textures:this.gltf.textures,asset:this.gltf.asset,scene:n,scenes:e,nodes:t,meshes:this.meshes,materials:this.gltf.materials,skins:this.skins,extensionsRequired:this.gltf.extensionsRequired,extensionsUsed:this.gltf.extensionsUsed};if(this.gltf.extensions&&(r.extensions=this.gltf.extensions),1===this.version){const t=this.adapter.S(this.gltf.materials);r.materials=t}return delete this.gltf.buffers,r.json=this.gltf,r})}K(t){return this.Z(t).then(()=>{const t=this.nodes={};return this.adapter.iterate((e,n)=>{const r=this.adapter.createNode(n,this.meshes,this.skins);t[e]=r},"nodes"),t})}Y(){this.skins=[];const t=[];return this.adapter.iterate((e,n,r)=>{t.push(this.W(n).then(t=>{t.index=r,this.skins.push(t)}))},"skins"),t}W(t){const e=t.inverseBindMatrices;return this.adapter.accessor._("inverseBindMatrices",e).then(e=>(t.inverseBindMatrices=e,e&&e.buffer&&this.transferables&&this.transferables.indexOf(e.buffer)<0&&this.transferables.push(e.buffer),t))}$(){const t=this.gltf.animations;return re(t)?this.adapter.getAnimations(t):null}Z(t){this.meshes={};let e=[];return this.adapter.iterate((n,r,s)=>{e.push(this.tt(r,t).then(t=>{t.index=s,this.meshes[n]=t}))},"meshes"),e=e.concat(this.Y()),Promise.all(e)}tt(t,e){const n=t.primitives.map(t=>this.et(t,e)).filter(t=>!!t);return Promise.all(n).then(e=>{const n={};return ie(n,t),n.primitives=e,n})}X(){const t=this.gltf.textures;if(!t)return null;const e=[];for(const n in t)e.push(this.adapter.C(n));return Promise.all(e).then(e=>{if(this.transferables)for(let t=0;t<e.length;t++){const n=e[t].image.array;if(e[t]&&n){let t;t=n instanceof ImageBitmap?n:n.buffer,t&&this.transferables.indexOf(t)<0&&this.transferables.push(t)}}if(!Array.isArray(t)){const n={},r=Object.keys(t);for(let t=0;t<e.length;t++)e[t]&&(n[r[t]]=e[t]);return n}return e})}et(t,e){let n;const r=[],s=t.extensions;if(re(t.targets))for(let e=0;e<t.targets.length;e++){const n=t.targets[e];for(const t in n){const s=this.adapter.accessor._(`morphTargets_${t}_${e}`,n[t]);s&&r.push(s)}}if(s&&s.KHR_draco_mesh_compression){if(!this.options.decoders.draco&&(!this.gltf.extensionsRequired||!this.gltf.extensionsRequired.indexOf("KHR_draco_mesh_compression")<0))return null;const t=this.options.decoders.draco,{bufferView:i,attributes:o}=s.KHR_draco_mesh_compression,a=this.gltf.bufferViews[i],c=this.H.O(a).then(n=>{const{buffer:r,byteOffset:s}=n;let{byteOffset:i}=a;const c=a.byteLength;i||(i=0);const h=new DataView(r,s+i,c),u={attributes:o,useUniqueIDs:!1,skipAttributeTransform:e.skipAttributeTransform};return t(h,u).then(t=>{const e=Object.values(t.attributes);return t.indices&&e.push(t.indices),e})});r.push(c),n=Promise.all(r)}else{const e=t.attributes;for(const t in e){const n=this.adapter.accessor._(t,e[t]);n&&r.push(n)}if(re(t.indices)){const e=this.adapter.accessor._("indices",t.indices);e&&r.push(e)}n=Promise.all(r)}return n.then(e=>{if(s&&s.KHR_draco_mesh_compression){const n=t.targets?t.targets.length:0;e[n]=e[n].concat(e.slice(0,n)),e=e[n]}let n,r;const i={attributes:e.reduce((t,e)=>{if("indices"===e.name)n=e;else if(e.name.indexOf("morphTargets_")>-1)r=r||{},r[e.name.slice(13)]=e;else{if(!("POSITION"!==e.name||e.min&&e.max)){const t=[1/0,1/0,1/0],n=[-1/0,-1/0,-1/0],{itemSize:r,array:s}=e,i=s.length/r;for(let e=0;e<i;e++)for(let i=0;i<r;i++){const o=e*r+i;s[o]<t[i]&&(t[i]=s[o]),s[o]>n[i]&&(n[i]=s[o])}if(e.quantization){const r=e.quantization,s=r.range/(1<<r.quantizationBits),i=r.minValues;zt(t,t,s),Ft(t,t,i),zt(n,n,s),Ft(n,n,i)}e.min=t,e.max=n}t[e.name]=e}return this.transferables&&e.array.buffer&&this.transferables.indexOf(e.array.buffer)<0&&this.transferables.push(e.array.buffer),t},{}),material:t.material};return n&&(i.indices=n),r&&(i.morphTargets=r),i.mode=re(t.mode)?t.mode:4,re(t.extras)&&(i.extras=t.extras),i})}}function Fe(t,e,n){const r=new Image;r.crossOrigin="",r.onload=()=>{if(!Be)return void n(new Error("There is no canvas to draw image!"));Be.width=r.width,Be.height=r.height;const t=Be.getContext("2d",{willReadFrequently:!0});t.drawImage(r,0,0,r.width,r.height);const e=t.getImageData(0,0,r.width,r.height),s={width:r.width,height:r.height,data:new Uint8Array(e.data)};n(null,s)},r.onerror=function(t){n(t)},r.src=t}let De,je;function ze(t,e,n){De||(De=new OffscreenCanvas(2,2),je=De.getContext("2d",{willReadFrequently:!0}));let r=null;if(se(t))r=fetch(t,e).then(t=>t.arrayBuffer()).then(t=>{const e=new Blob([new Uint8Array(t)]);return createImageBitmap(e)});else{const e=new Blob([t]);r=createImageBitmap(e)}r.then(He.bind(this)).then(t=>{n(null,t)}).catch(t=>{console.warn(t),n(t)})}function He(t){let{width:e,height:n}=t;Ge(e)||(e=qe(e)),Ge(n)||(n=qe(n));const r=this.options.maxTextureSize;r&&(e=Math.min(r,e),n=Math.min(r,n)),De.width=e,De.height=n,je.drawImage(t,0,0,e,n),t.close();const s=je.getImageData(0,0,e,n);return{width:e,height:n,data:new Uint8Array(s.data)}}function Ge(t){return 0==(t&t-1)&&0!==t}function qe(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}const Ve="undefined"==typeof document?null:document.createElement("canvas");class $e extends s.worker.Actor{constructor(t,e){super(t),this.mapId=e}initialize(t){t(null)}loadTile(t,e,n){let r=null;e&&e.arraybuffer&&(r=[e.arraybuffer]);const s={mapId:this.mapId,layerId:t,command:"loadTile",params:e};this.send(s,r,n)}abortTileLoading(t,e,n){const r={mapId:this.mapId,layerId:t,command:"abortTileLoading",params:{url:e}};this.broadcast(r,null,n)}addLayer(t,e,n){const r={actorId:this.actorId,mapId:this.mapId,layerId:t,command:"addLayer",params:{options:e}};this.broadcast(r,null,n)}removeLayer(t,e){const n={mapId:this.mapId,layerId:t,command:"removeLayer"};this.broadcast(n,null,e)}requestImage({url:t},e){const n=new Image;n.onload=()=>{if(!this.isActive())return;if(!Ve)return void e(new Error("There is no canvas to draw image!"));const t=function(t){if(Xe(t.width)&&Xe(t.height))return t;let e=t.width,n=t.height;Xe(e)||(e=Je(e));Xe(n)||(n=Je(n));const r=document.createElement("canvas");r.width=e,r.height=n,r.getContext("2d").drawImage(t,0,0,e,n);const s=t.src,i=s.lastIndexOf("/")+1,o=s.substring(i);return console.warn(`Texture(${o})'s size is not power of two, resize from (${t.width}, ${t.height}) to (${e}, ${n})`),r}(n);Ve.width=t.width,Ve.height=t.height;const r=Ve.getContext("2d",{willReadFrequently:!0});r.drawImage(t,0,0,t.width,t.height);const s=r.getImageData(0,0,t.width,t.height),i={width:t.width,height:t.height,data:new Uint8Array(s.data)};e(null,i,[i.data.buffer])},n.onerror=function(t){e(t)},n.src=t}}function Xe(t){return 0==(t&t-1)&&0!==t}function Je(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}function Ke(t,e){if(t.scenes&&t.scenes.length)for(let n=0,r=t.scenes.length;n<r;n++){const r=t.scenes[n].nodes;for(let n=0,s=r.length;n<s;n++){const s=[];nn(r[n],s,t,e)}}}const Qe=[],Ze=[],Ye=[],We=[0,0,0],tn=Zt([]),en=[1,1,1];function nn(t,e,n,r){const s=e.slice(0);if(t.matrix)s.push(t.matrix);else if(t.rotation||t.translation||t.scale){const e=Nt(Qe,t.translation||We),n=Pt(Ze,t.rotation||tn),r=Ct(Ye,t.scale||en);Et(r,n,r);const i=Et([],e,r);s.push(i)}if(t.children&&t.children.length)for(let e=0,i=t.children.length;e<i;e++)nn(t.children[e],s,n,r);if(void 0!==t.mesh){const e=t.mesh,i=n.meshes[e];if(i){const t=s.slice(0),o=i.primitives;for(let s=0,i=o.length;s<i;s++){const i=o[s];i&&(i.matrices=t,r(i,e,s,n))}}}}function rn(t,e,n){let{byteOffset:r,byteStride:s}=e;const{componentType:i,itemSize:o}=e,a=e.array.buffer,c=i?Ue.getTypedArrayCtor(i):e.array.constructor;if(r=void 0===r?e.array.byteOffset:r,s=s||0,!s||s===o*c.BYTES_PER_ELEMENT&&r%c.BYTES_PER_ELEMENT==0){const e=new c(a,r+n*o*c.BYTES_PER_ELEMENT,o);return t.set(e),t}s||(s=o*c.BYTES_PER_ELEMENT);const h=new Uint8Array(a,s*n+r,o*c.BYTES_PER_ELEMENT);return new Uint8Array(t.buffer).set(h),t}function sn(t,e,n,r){t[4*e]=n[r],t[4*e+1]=n[r+4],t[4*e+2]=n[r+8],t[4*e+3]=n[r+12]}var on="#include <gl2_vert>\n\nconst float SHIFT_RIGHT_11 = 1.0 / 2048.0;\n\nconst float SHIFT_RIGHT_5 = 1.0 / 32.0;\n\nconst float SHIFT_LEFT_11 = 2048.0;\n\nconst float SHIFT_LEFT_5 = 32.0;\n\nconst float NORMALIZE_6 = 1.0 / 64.0;\n\nconst float NORMALIZE_5 = 1.0 / 32.0;\n\n\n\n#ifdef HAS_POSITION\n\n attribute vec3 POSITION;\n\n#endif\n\n\n\n#if defined(HAS_RGB)\n\n attribute vec3 RGB;\n\n#elif defined(HAS_RGBA)\n\n attribute vec4 RGBA;\n\n#elif defined(HAS_RGB565)\n\n attribute float RGB565;\n\n#endif\n\n\n\nuniform vec4 pointColor;\n\nuniform float pointSize;\n\n\n\nuniform mat4 projViewModelMatrix;\n\nuniform float pointOpacity;\n\n\n\nvarying vec4 vColor;\n\n\n\n#ifdef HAS_NORMAL\n\n #ifdef HAS_NORMAL_OCT16P\n\n attribute vec2 NORMAL_OCT16P;\n\n float signNotZero(float value) {\n\n return value >= 0.0 ? 1.0 : -1.0;\n\n }\n\n vec2 signNotZero(vec2 value) {\n\n return vec2(signNotZero(value.x), signNotZero(value.y));\n\n }\n\n vec3 octDecode(vec2 encoded, float range) {\n\n if (encoded.x == 0.0 && encoded.y == 0.0) {\n\n return vec3(0.0, 0.0, 0.0);\n\n }\n\n encoded = encoded / range * 2.0 - 1.0;\n\n vec3 v = vec3(encoded.x, encoded.y, 1.0 - abs(encoded.x) - abs(encoded.y));\n\n if (v.z < 0.0) {\n\n v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);\n\n }\n\n return normalize(v);\n\n }\n\n vec3 octDecode(vec2 encoded) {\n\n return octDecode(encoded, 255.0);\n\n }\n\n #else\n\n attribute vec3 NORMAL;\n\n #endif\n\n uniform vec3 lightDir;\n\n uniform mat3 modelNormalMatrix;\n\n uniform mat4 positionMatrix;\n\n float getLambertDiffuse(vec3 lightDir, vec3 normal) {\n\n return max(dot(-lightDir, normal), 0.0);\n\n }\n\n#endif\n\n#ifdef PICKING_MODE\n\n #include <fbo_picking_vert>\n\n#endif\n\n#include <draco_decode_vert>\n\nvoid main() {\n\n #ifdef HAS_POSITION\n\n vec3 localPos = decode_getPosition(POSITION);\n\n #endif\n\n gl_Position = projViewModelMatrix * vec4(localPos, 1.0);\n\n gl_PointSize = pointSize;\n\n\n\n #ifdef PICKING_MODE\n\n fbo_picking_setData(gl_Position.w, true);\n\n #else\n\n #if defined(HAS_RGB)\n\n vColor = vec4(RGB / 255.0, 1.0) * pointOpacity;\n\n #elif defined(HAS_RGBA)\n\n vColor = RGBA / 255.0 * pointOpacity;\n\n #elif defined(HAS_RGB565)\n\n float compressed = RGB565;\n\n float r = floor(compressed * SHIFT_RIGHT_11);\n\n compressed -= r * SHIFT_LEFT_11;\n\n float g = floor(compressed * SHIFT_RIGHT_5);\n\n compressed -= g * SHIFT_LEFT_5;\n\n float b = compressed;\n\n vec3 rgb = vec3(r * NORMALIZE_5, g * NORMALIZE_6, b * NORMALIZE_5);\n\n vColor = vec4(rgb, 1.0);\n\n #else\n\n vColor = pointColor;\n\n #endif\n\n\n\n #ifdef HAS_NORMAL\n\n mat3 positionNormalMatrix = mat3(positionMatrix);\n\n mat3 normalMatrix = modelNormalMatrix * positionNormalMatrix;\n\n #ifdef HAS_NORMAL_OCT16P\n\n vec3 localNormal = octDecode(NORMAL_OCT16P);\n\n #else\n\n vec3 localNormal = NORMAL;\n\n #endif\n\n vec3 normal = normalize(normalMatrix * localNormal);\n\n float colorStrength = getLambertDiffuse(lightDir, normal);\n\n colorStrength = max(colorStrength, 0.5);\n\n vColor *= colorStrength;\n\n #endif\n\n #endif\n\n\n\n\n\n\n\n\n\n}\n\n";const an=new Array(3),cn=new Array(3),hn=[40680631590769,40680631590769,40408299984661.445];function un(t,e,n,r){const s=hn,i=Math.cos(n);an[0]=i*Math.cos(e),an[1]=i*Math.sin(e),an[2]=Math.sin(n),vn(an,an),jt(cn,s,an);const o=Math.sqrt(Gt(an,cn));var a,c,h;return c=cn,h=o,(a=cn)[0]=c[0]/h,a[1]=c[1]/h,a[2]=c[2]/h,zt(an,an,r),Ft(t,cn,an)}const ln=[1/6378137,1/6378137,1/6356752.314245179],fn=[1/40680631590769,1/40680631590769,1/40408299984661.445],dn=new Array(3),mn=new Array(3),pn=new Array(3);function bn(t,e){const n=fn,r=function(t,e,n,r,s){const i=e[0],o=e[1],a=e[2],c=n[0],h=n[1],u=n[2],l=i*i*c*c,f=o*o*h*h,d=a*a*u*u,m=l+f+d,p=Math.sqrt(1/m),b=zt(gn,e,p);if(m<s)return isFinite(p)?b:void 0;const g=r[0],y=r[1],w=r[2],v=yn;v[0]=b[0]*g*2,v[1]=b[1]*y*2,v[2]=b[2]*w*2;let T,_,M,O,x,A,I,S,E,N,C,P=(1-p)*wn(e)/(.5*wn(v)),R=0;do{P-=R,M=1/(1+P*g),O=1/(1+P*y),x=1/(1+P*w),A=M*M,I=O*O,S=x*x,E=A*M,N=I*O,C=S*x,T=l*A+f*I+d*S-1,_=l*E*g+f*N*y+d*C*w;R=T/(-2*_)}while(Math.abs(T)>1e-12);return t[0]=i*M,t[1]=o*O,t[2]=a*x,t}(dn,e,ln,n,.1);let s=$t(mn,r,n);s=vn(s,s);const i=Vt(pn,e,r),o=Math.atan2(s[1],s[0]),a=Math.asin(s[2]),c=dt(Gt(i,e))*wn(i);return t[0]=lt(o),t[1]=lt(a),t[2]=c,t}const gn=new Array(3),yn=new Array(3);function wn(t){return kt(t)}function vn(t,e){const n=e[0],r=e[1],s=e[2];let i=n*n+r*r+s*s;return i>0&&(i=Math.sqrt(i),t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t}function Tn(t,e){return jt(e,t,fn),Ht(e,e)}function _n(t,e){const n=t[0],r=t[1],s=Math.cos(r),i=s*Math.cos(n),o=s*Math.sin(n),a=Math.sin(r);return e.x=i,e.y=o,e.z=a,Ht(e,e)}var Mn=Object.freeze({__proto__:null,radianToCartesian3:un,cartesian3ToDegree:bn,normalizeCartesian:vn,geodeticSurfaceNormal:Tn,geodeticSurfaceNormalCartographic:_n});function On(t,e,n,r){n=n||0,r=r||n;const s=Math.abs(t-e);return s<=r||s<=n*Math.max(Math.abs(t),Math.abs(e))}function xn(t,e){let n="";for(let r=0;r<4;r++){const s=t.getUint8(e+r);n+=String.fromCharCode(s)}return n}const An="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function In(t,e,n){const r=new Uint8Array(t,e,n);return An?JSON.parse(An.decode(r)):JSON.parse(pt(r))}function Sn(t,e,n){const r=new Uint8Array(t,e,n);return An?JSON.parse(An.decode(r)):JSON.parse(pt(r))}function En(t,e,n){return{offset:e,byteLength:n}}function Nn(t,e,n,r){const{byteOffset:s,componentType:i,type:o}=t,{ctor:a,type:c}=Bn(i||"UNSIGNED_SHORT"),h=kn(o);return{byteStride:0,byteOffset:s+n,itemSize:h,count:r*h,componentType:c,array:new a(e,n+s,r*h)}}function Cn(t,e,n,r){const s=Nn(t,e,n,r);return s.array.buffer.byteLength!==e.byteLength&&(s.array=s.array.slice()),s}function Pn(t,e,n,r){const{byteOffset:s,componentType:i,type:o}=t,{ctor:a}=Bn(i||"UNSIGNED_SHORT"),c=kn(o),h=new a(e,s,n*c);return 1===c?h[r]:h.subarray(r*c,r*c+c)}const Rn={"SCALAR":1,"VEC2":2,"VEC3":3,"VEC4":4};function kn(t){return t?Rn[t]:1}const Ln={"BYTE":{ctor:Int8Array,type:5120,name:"Int8Array"},"UNSIGNED_BYTE":{ctor:Uint8Array,type:5121,name:"Uint8Array"},"SHORT":{ctor:Int16Array,type:5122,name:"Int16Array"},"UNSIGNED_SHORT":{ctor:Uint16Array,type:5123,name:"Uint16Array"},"INT":{ctor:Int32Array,type:5124,name:"Int32Array"},"UNSIGNED_INT":{ctor:Uint32Array,type:5125,name:"Uint32Array"},"FLOAT":{ctor:Float32Array,type:5126,name:"Float32Array"},"DOUBLE":{ctor:Float64Array,type:5126,name:"Float64Array"}};function Bn(t){return Ln[t]}function Un(t){for(const e in Ln)if(t===Ln[e].ctor)return Ln[e].type;throw new Error("unrecognized ctor:"+t)}function Fn(t,e,n,r){const s=t,i=e.length/3;for(let t=0;t<i;t++)s[3*t]=e[3*t]/65535*r[0]+n[0],s[3*t+1]=e[3*t+1]/65535*r[1]+n[1],s[3*t+2]=e[3*t+2]/65535*r[2]+n[2];return s}function Dn(t,e,n){const r=t.getUint32(12,!0),s=t.getUint32(16,!0),i=t.getUint32(20,!0),o=t.getUint32(24,!0),a=t.buffer;let c,h={},u={},l=null;r>0&&(h=In(a,e,r),e+=r),s>0&&(c=function(t,e,n){return{offset:e,byteLength:n}}(0,e,s),e+=s),i>0&&(u=Sn(a,e,i),e+=i);const f=En(0,e,o);return l=a.slice(f.offset,f.offset+f.byteLength),n.push(l),{featureTable:h,featureTableBin:c,batchTable:u,batchTableBin:l}}const jn={up:{south:"east",north:"west",west:"south",east:"north"},down:{south:"west",north:"east",west:"north",east:"south"},south:{up:"west",down:"east",west:"down",east:"up"},north:{up:"east",down:"west",west:"up",east:"down"},west:{up:"north",down:"south",north:"down",south:"up"},east:{up:"south",down:"north",north:"up",south:"down"}},zn={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},Hn={},Gn={east:[],north:[],up:[],west:[],south:[],down:[]};let qn=[],Vn=[],$n=[];const Xn=[0,0,0];function Jn(t,e,n){return n[0]=t[0],n[1]=t[1],n[2]=t[2],n[3]=t[3],n[4]=t[4],n[5]=t[5],n[6]=t[6],n[7]=t[7],n[8]=t[8],n[9]=t[9],n[10]=t[10],n[11]=t[11],n[12]=e[0],n[13]=e[1],n[14]=e[2],n[15]=t[15],n}const Kn=function(t,e){const n=jn[t][e];let r;const s=t+e;return Hn[s]?r=Hn[s]:(r=function(r,s,i){if(function(t,e){var n=t[0],r=t[1],s=t[2],i=e[0],o=e[1],a=e[2];return Math.abs(n-i)<=1e-6*Math.max(1,Math.abs(n),Math.abs(i))&&Math.abs(r-o)<=1e-6*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(s-a)<=1e-6*Math.max(1,Math.abs(s),Math.abs(a))}(r,Xn))Bt(qn,zn[t]),Bt(Vn,zn[e]),Bt($n,zn[n]);else if(On(r[0],0,1e-14)&&On(r[1],0,1e-14)){const s=dt(r[2]);Bt(qn,zn[t]),"east"!==t&&"west"!==t&&zt(qn,qn,s),Bt(Vn,zn[e]),"east"!==e&&"west"!==e&&zt(Vn,Vn,s),Bt($n,zn[n]),"east"!==n&&"west"!==n&&zt($n,$n,s)}else{Tn(r,Gn.up);const s=Gn.up,i=Gn.east;i[0]=-r[1],i[1]=r[0],i[2]=0,Ht(Gn.east,i),qt(Gn.north,s,i),zt(Gn.down,Gn.up,-1),zt(Gn.west,Gn.east,-1),zt(Gn.south,Gn.north,-1),qn=Gn[t],Vn=Gn[e],$n=Gn[n]}return i[0]=qn[0],i[1]=qn[1],i[2]=qn[2],i[3]=0,i[4]=Vn[0],i[5]=Vn[1],i[6]=Vn[2],i[7]=0,i[8]=$n[0],i[9]=$n[1],i[10]=$n[2],i[11]=0,i[12]=r[0],i[13]=r[1],i[14]=r[2],i[15]=1,i},Hn[s]=r),r}("east","north"),Qn=[],Zn=[],Yn=[],Wn=[],tr=[],er=[],nr=[],rr={x:0,y:0},sr={x:0,y:0},ir=Math.PI/180;let or;const ar={width:100,height:10};function cr(){if(!or){const{width:t,height:e}=ar;OffscreenCanvas?or=new OffscreenCanvas(t,e):(or=document.createElement("canvas"),or.width=t,or.height=e)}return or}class hr{constructor(t,e={}){if(!Array.isArray(t))return void console.error("colors is not array");if(t.length<2)return void console.error("colors.length should >1");this.colors=t;let n=1/0,r=-1/0;for(let e=0,s=t.length;e<s;e++){const s=t[e][0];n=Math.min(s,n),r=Math.max(s,r)}this.min=n,this.max=r,this.valueOffset=this.max-this.min,this.options=Object.assign({},ar,e),this.nt()}getImageData(){return this.imgData}nt(){const t=cr(),{width:e,height:n}=this.options;t.width=e,t.height=n;const r=t.getContext("2d");r.clearRect(0,0,t.width,t.height);const s=r.createLinearGradient(0,0,t.width,0),{colors:i,valueOffset:o}=this;for(let t=0,e=i.length;t<e;t++){const[e,n]=i[t],r=(e-this.min)/o;s.addColorStop(r,n)}r.fillStyle=s,r.fillRect(0,0,t.width,t.height),this.imgData=r.getImageData(0,0,t.width,t.height)}getColor(t){t=Math.max(this.min,t);const e=((t=Math.min(t,this.max))-this.min)/this.valueOffset;let n=Math.round(e*this.imgData.width);n=Math.min(n,this.imgData.width-1);const r=4*n;return[this.imgData.data[r],this.imgData.data[r+1],this.imgData.data[r+2],this.imgData.data[r+3]]}}var ur;function lr(t,e){for(let n=0;n<t.stops.length;n++)if(e===t.stops[n][0])return t.stops[n][1];return t.default}function fr(t,e){for(var n=0;n<t.stops.length&&!(e<t.stops[n][0]);n++);return t.stops[Math.max(n-1,0)][1]}function dr(t,e){for(var n=void 0!==t.base?t.base:1,r=0;!(r>=t.stops.length||e<=t.stops[r][0]);)r++;return 0===r?t.stops[r][1]:r===t.stops.length?t.stops[r-1][1]:function t(e,n,r,s,i,o){return"function"==typeof i?function(){var a=i.apply(void 0,arguments),c=o.apply(void 0,arguments);return t(e,n,r,s,a,c)}:i.length?function(t,e,n,r,s,i){var o=[];for(let a=0;a<s.length;a++)o[a]=gr(t,e,n,r,s[a],i[a]);return o}(e,n,r,s,i,o):gr(e,n,r,s,i,o)}(e,n,t.stops[r-1][0],t.stops[r][0],t.stops[r-1][1],t.stops[r][1])}"function"==typeof Map&&(ur=new Map);const mr={width:100,height:1};function pr(t,e){const n=t.stops;if(n&&n.length>1){let t;if(ur){const e=JSON.stringify(n);if(!ur.has(e)){const t=new hr(n,mr);ur.set(e,t)}t=ur.get(e)}else t=new hr(n,mr);const[r,s,i,o]=t.getColor(e);return[r/255,s/255,i/255,o/255]}return n&&1===n.length?n[0][1]:null}function br(t,e){return function(t,e,n){return void 0!==t?t:void 0!==e?e:void 0!==n?n:null}(e,t.default)}function gr(t,e,n,r,s,i){var o,a=r-n,c=t-n;return s*(1-(o=1===e?c/a:(Math.pow(e,c)-1)/(Math.pow(e,a)-1)))+i*o}function yr(t){return t&&"object"==typeof t&&(t.stops||t.property&&"identity"===t.type)}function wr(t){return function t(e,n){if(!yr(e))return function(){return e};e=JSON.parse(JSON.stringify(e));let r=!0,s=!0;const i=e.stops;if(i)for(let e=0;e<i.length;e++)if(yr(i[e][1])){const o=t(i[e][1],n);r=r&&o.isZoomConstant,s=s&&o.isFeatureConstant,i[e]=[i[e][0],o]}const o=function t(e,n){var r,s,i;if(yr(e)){var o,a=e.stops&&"object"==typeof e.stops[0][0],c=a||void 0!==e.property,h=a||!c,u=e.type||n||"exponential";if("exponential"===u)o=dr;else if("interval"===u)o=fr;else if("categorical"===u)o=lr;else if("identity"===u)o=br;else{if("color-interpolate"!==u)throw new Error('Unknown function type "'+u+'"');o=pr}if(a){var l={},f=[];for(let t=0;t<e.stops.length;t++){var d=e.stops[t];void 0===l[d[0].zoom]&&(l[d[0].zoom]={zoom:d[0].zoom,type:e.type,property:e.property,default:e.default,stops:[]}),l[d[0].zoom].stops.push([d[0].value,d[1]])}for(let e in l)f.push([l[e].zoom,t(l[e])]);r=function(t,n){const r=dr({stops:f,base:e.base},t)(t,n);return"function"==typeof r?r(t,n):r},s=!1,i=!1}else h?(r=function(t){const n=o(e,t);return"function"==typeof n?n(t):n},s=!0,i=!1):(r=function(t,n){const r=o(e,n?n[e.property]:null);return"function"==typeof r?r(t,n):r},s=!1,i=!0)}else r=function(){return e},s=!0,i=!0;return r.isZoomConstant=i,r.isFeatureConstant=s,r}(e,n);return o.isZoomConstant=r&&o.isZoomConstant,o.isFeatureConstant=s&&o.isFeatureConstant,o}(t,"exponential")}const{getTextureMagFilter:vr,getTextureMinFilter:Tr,getTextureWrap:_r,getMaterialType:Mr,getMaterialFormat:Or,getPrimitive:xr,getUniqueREGLBuffer:Ar}=n.reshader.REGLHelper,Ir=[1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],Sr=[0,0,1,0,0,1,0,0,-1,0,0,0,0,0,0,1],{loginIBLResOnCanvas:Er,logoutIBLResOnCanvas:Nr,getIBLResOnCanvas:Cr,getPBRUniforms:Pr}=n.reshader.pbr.PBRUtils,Rr={factor:0,units:0},kr=[1,1,1,1],Lr=[0,0,0],Br={specularStrength:0,materialShininess:1},Ur=[1,1,1],Fr=n.mat4.identity([]),Dr=[0,0],jr=t=>t.material instanceof n.reshader.PhongMaterial,zr=t=>t.material instanceof n.reshader.pbr.StandardMaterial,Hr=[],Gr=new s.Coordinate(0,0),qr=new s.Point(0,0),Vr=new s.Point(0,0),$r=new s.Point(0,0),Xr=[],Jr=[],Kr=[],Qr=[],Zr=[],Yr=[],Wr=[],ts=[0,0,0],es=[],ns=[],rs={"POSITION":"POSITION","NORMAL":"NORMAL","TEXCOORD_0":"TEXCOORD_0","TEXCOORD_1":"TEXCOORD_1","COLOR_0":"COLOR_0","TANGENT":"TANGENT","_BATCHID":"_BATCHID"},ss=[0,1,1,2,2,3,3,0,0,4,1,5,2,6,3,7,4,5,5,6,6,7,7,4],is=function(t,e){const n=2*Math.PI/t,r=[],s=[];for(let s=0;s<=t;s++){const t=Math.cos(n*s)*e,i=Math.sin(n*s)*e,o=0;r[3*s]=t,r[3*s+1]=i,r[3*s+2]=o}for(let s=t;s<=2*t;s++){const t=Math.cos(n*s)*e,i=Math.sin(n*s)*e,o=0;r[3*s]=o,r[3*s+1]=t,r[3*s+2]=i}for(let s=2*t;s<=3*t;s++){const t=Math.cos(n*s)*e,i=Math.sin(n*s)*e,o=0;r[3*s]=t,r[3*s+1]=o,r[3*s+2]=i}const i=r.length/3-1;for(let e=0;e<i;e++)e!==t-1&&e!==2*t-1&&(s[2*e]=e,s[2*e+1]=e+1);return r.push(0,0,0),r.push(e,0,0),r.push(0,e,0),r.push(0,0,e),s.push(i+1,i+2),s.push(i+1,i+3),s.push(i+1,i+4),{vertices:r,indices:s}}
|
|
19
19
|
/*!
|
|
20
|
-
* @maptalks/gl v0.95.
|
|
20
|
+
* @maptalks/gl v0.95.6
|
|
21
21
|
* LICENSE : UNLICENSED
|
|
22
|
-
* (c) 2016-
|
|
23
|
-
*/(100,1),as=[0,0,0,1],cs=[1,1,1];class hs{constructor(t,e){this.st=e,this.it=e.getRenderer().canvas,this.pickingFBO=e.getRenderer().pickingFBO,this.ot=new s.SpatialReference,this.ct=t,this.ht=new n.reshader.Renderer(t),this.ut={},this.lt={},this.ft={},this.dt={},this.pt={},this.bt={},this.gt=new n.reshader.Scene,this.yt=new n.reshader.Scene,this.wt=new n.reshader.Scene,this.vt=new n.reshader.Scene,this.Tt=new n.reshader.ResourceLoader(t.texture(2)),this._t=this.Mt.bind(this),this.Ot=new n.reshader.PhongMaterial({"baseColorFactor":[1,1,1,1]}),this.xt(),this.At=new n.reshader.KHRTechniquesWebglManager(this.ct,this.It(),this.Tt);const r=this.getMap();r.altitudeToPoint&&(this.St=r.altitudeToPoint(100,r.getGLRes())/100)}getI3DMMeshes(){return this.dt}getPNTSMeshes(){return this.ft}getB3DMMeshes(){return this.lt}getPaintedMeshes(){return this.Et}getMap(){return this.st.getMap()}paint(t,e,r){const s=r&&r.renderTarget,i=r&&r.sceneFilter,o=this.getMap();if(!t.length||!o)return null;const a=this.Nt(),c=o.projViewMatrix,h=[],l=[],f=[],d=[],m=[],p=this.Ct(t),b=[];for(let s=0,i=t.length;s<i;s++){const i=t[s].data.node;let o=this.Pt(i);if(!o)continue;const a=this.st.Rt(i.kt);i.Lt&&a.debugShowBoundingVolume&&b.push(i.Lt);const g=a.heightOffset||0,y=a.coordOffset||jr;this.pt[i.id]&&(o=this.pt[i.id],o=gt(o));let w=a.polygonOffset||kr;at(w)&&(w=w()),Array.isArray(o)||(h[0]=o,o=h);for(let t=0,s=o.length;t<s;t++){const s=o[t].properties.magic;if(o[t].properties.heightOffset===g&&o[t].properties.coordOffset[0]===y[0]&&o[t].properties.coordOffset[1]===y[1]||(this.Bt(o[t]),o[t].Ut=n.mat4.copy([],o[t].localTransform)),"b3dm"===s){if(o[t].getBoundingBox&&!u(c,o[t].getBoundingBox()))continue;const{batchIdData:e,batchIdMap:s}=o[t].geometry.properties;if(e&&s){const e=o[t].properties.node.kt;this.Ft&&this.Ft[e]?n.HighlightUtil.highlightMesh(this.ct,o[t],this.Ft[e],this.Dt,s):this.Ft&&this.Ft[e]||n.HighlightUtil.highlightMesh(this.ct,o[t],null,this.Dt,s),n.HighlightUtil.showOnly(this.ct,o[t],this.jt&&this.jt[e],this.zt,s)}r&&r.bloom&&o[t].properties.hlBloomMesh&&(o[t].properties.hlBloomMesh.properties.depthFunc="always",o[t].properties.hlBloomMesh.properties.polygonOffset=w,f.push(o[t].properties.hlBloomMesh)),f.push(o[t])}else"pnts"===s?d.push(o[t]):"i3dm"===s&&m.push(o[t]);o[t].properties.isLeaf=!!e[i.id],o[t].properties.level=p.get(i.Ht),o[t].properties.polygonOffset=w,o[t].Gt=i,e[i.id]||l.push(o[t]),this.qt(o[t]),this.Vt(o[t],i)}}let g=0;const y=this.At.getExcludeFilter();g+=this.$t(this.Xt,a,[i,zr,y],s,l,f,m),g+=this.$t(this.Jt,a,[i,Hr,y],s,l,f,m),this.At.forEachShader((t,e,n)=>{const r=this.Nt(n);g+=this.$t(t,r,[i,e],s,l,f,m)}),this.yt.setMeshes(d);const w=this.Kt();return g+=this.ht.render(this.Qt,w,this.yt,s&&s.fbo),this.Et={pntsMeshes:d,i3dmMeshes:m,b3dmMeshes:f},b.forEach(t=>{this.Zt(t)}),this.vt.setMeshes(b),this.ht.render(this.Yt,a,this.vt,s&&s.fbo),g}Zt(t){const e=t.properties.node,r=this.st.Rt(e.kt),s=r.heightOffset||0,i=this.Wt(),o=r.te,a=n.vec3.set(ns,0,0,i*(s-o));let c=r.rotation||[0,0,0];c=n.quat.fromEuler(Wr,c[0],c[1],c[2]);const h=r.scale||[1,1,1],u=n.mat4.fromRotationTranslationScale(Yr,c,a,h);n.mat4.multiply(t.localTransform,t.Ut,u)}$t(t,e,n,r,s,i,o){t.filter=n.filter(t=>!!t),e.debug=!1,e.debug=!1;let a=0;return this.gt.setMeshes(i),a+=this.ht.render(t,e,this.gt,r&&r.fbo),this.wt.setMeshes(o),a+=this.ht.render(t,e,this.wt,r&&r.fbo),a}ee(t,e){return e.Gt.ne-t.Gt.ne}deleteTile(t){const e=t.node;e.Lt&&(e.Lt.geometry.dispose(),e.Lt.dispose(),delete e.Lt);const n=e.id;this.re(n)}re(t){const e=this.lt[t]||this.ft[t]||this.dt[t]||this.pt[t]||this.ut[t];this.pt[t]?this.se(t):e&&(this.ie(e),delete this.lt[t],delete this.ft[t],delete this.dt[t],delete this.ut[t])}se(t){let e=this.pt[t];e=gt(e);for(let t=0;t<e.length;t++){const{id:n}=e[t].properties;this.re(n)}delete this.pt[t]}ie(t){if(Array.isArray(t))for(let e=0,n=t.length;e<n;e++)this.ie(t[e]);else{n.HighlightUtil.showOnly(this.ct,t),n.HighlightUtil.highlightMesh(this.ct,t);const e=t.geometry.properties.url;if(e){const n=this.bt[e];n&&n.refMeshes&&(n.refMeshes.delete(t.uuid),n.refMeshes.size||(n.geometry.dispose(),n.material.dispose(),delete this.bt[e]))}else t.geometry.dispose(),t.material&&t.material.dispose();t.dispose()}}remove(){const t=this.st;Cr(t.getRenderer().canvas,t.getMap());for(const t in this.pt)this.se(t);this.pt={};for(const t in this.lt)this.re(t);this.lt={};for(const t in this.ft)this.re(t);this.ft={};for(const t in this.dt)this.re(t);this.dt={};for(const t in this.ut)this.re(t);this.ut={},this.Xt&&(this.Xt.dispose(),delete this.Xt),this.Jt&&(this.Jt.dispose(),delete this.Jt),this.Qt&&(this.Qt.dispose(),delete this.Qt),this.Yt&&(this.Yt.dispose(),delete this.Yt),this.At.dispose(),this.picking&&this.picking.dispose()}Pt(t){return this.lt[t.id]||this.ft[t.id]||this.dt[t.id]||this.pt[t.id]}has(t){return this.Pt(t)||this.ut[t.id]}Bt(t){const e=t.properties.magic;"b3dm"===e?this.oe(t):"i3dm"===e?this.ae(t):"pnts"===e&&this.ce(t)}createPntsMesh(t,e,r,s){if(this.ft[e]){const t=this.ft[e];return console.warn(`pnts mesh with id(${e}) was already created.`),s(null,{id:e,mesh:t}),t}const{pnts:i,featureTable:o,rootIdx:a,compressed_int16_params:c}=t,h=o.POINTS_LENGTH;i.BATCH_ID||(i.BATCH_ID=new Uint8Array(h),i.BATCH_ID.fill(0));const u=new n.reshader.Geometry(i,null,h,{static:!0,primitive:"points",positionAttribute:"POSITION",pickingIdAttribute:"BATCH_ID"});u.generateBuffers(this.ct);const l={};i.POSITION?l.HAS_POSITION=1:i.POSITION_QUANTIZED&&(l.HAS_POSITION_QUANTIZED=1),i.RGB?l.HAS_RGB=1:i.RGBA?l.HAS_RGBA=1:i.RGB565&&(l.HAS_RGB565=1),(i.NORMAL||i.NORMAL_OCT16P)&&(l.HAS_NORMAL=1,i.NORMAL_OCT16P&&(l.HAS_NORMAL_OCT16P=1)),this.he(l,c),t.featureTable.CONSTANT_RGBA&&(t.featureTable.CONSTANT_RGBA=t.featureTable.CONSTANT_RGBA.map(t=>t/255));const{rtcCenter:f,rtcCoord:d,projCenter:m}=t,p=this.st.Rt(a),b=new n.reshader.Mesh(u);b.properties.magic="pnts",b.properties.id=e,b.properties.node=r,b.properties.count=h,b.properties.batchTable=t.batchTable,b.properties.batchTableBin=t.batchTableBin,b.properties.serviceIndex=a,b.properties.rtcCoord=d,b.properties.rtcCenter=f,b.properties.projCenter=m,b.setDefines(l),Object.defineProperty(b.uniforms,"pointColor",{enumerable:!0,get:function(){return t.featureTable.CONSTANT_RGBA?t.featureTable.CONSTANT_RGBA:p&&p.pointColor||[1,1,1,1]}});const g=this.getMap();let y=null,w=null;Object.defineProperty(b.uniforms,"pointSize",{enumerable:!0,get:function(){if(!p)return 2;if(wr(p.pointSize)){const t=JSON.stringify(p.pointSize);t!==y&&(w=vr(p.pointSize),y=t);return w(g.getZoom())}return p.pointSize||2}});let v=null,T=null;return Object.defineProperty(b.uniforms,"pointOpacity",{enumerable:!0,get:function(){if(!p)return 1;if(wr(p.pointOpacity)){const t=JSON.stringify(p.pointOpacity);t!==v&&(T=vr(p.pointOpacity),v=t);return T(g.getZoom())}return p.pointOpacity||1}}),this.ue(b,c),this.ce(b),b.Ut=n.mat4.copy([],b.localTransform),this.ft[e]=b,s(null,{id:e,mesh:[b]}),[b]}ce(t){const e=t.localTransform||[],{rtcCoord:n,node:r,projCenter:s}=t.properties;this.le(e,n,s,r.kt),t.setLocalTransform(e)}createI3DMMesh(t,e,r,s){if(this.dt[e]){const t=this.dt[e];return console.warn(`i3dm mesh with id(${e}) was already created.`),this.ut[e]||s(null,{id:e,mesh:t}),t}const i=this.st.Rt(r.kt),o=this.fe(r.de),{i3dm:a,featureTable:c,gltf:h,batchTable:u,batchTableBin:l,count:f}=t,d=c.INSTANCES_LENGTH,{rtcCenter:m,rtcCoord:p}=t,b=this.me(Qr,p),g=this.pe(Zr,r,m,p);n.mat4.multiply(b,g,b);const{POSITION:y,NORMAL_UP:w,NORMAL_RIGHT:v,SCALE:T,SCALE_NON_UNIFORM:_,INSTANCE_ROTATION:M}=a,O={"instance_vectorA":new Float32Array(4*d),"instance_vectorB":new Float32Array(4*d),"instance_vectorC":new Float32Array(4*d),"aPickingId":new Uint16Array(d)};for(let t=0;t<d;t++)O.aPickingId[t]=t;const x=new Float32Array(3),A=new Float32Array(3),I=[],S=new Float32Array(1),E=new Float32Array(3),N=[],C=[],P=[],R=[],k=new Float32Array(9);!function(t,e){let{byteOffset:n,byteStride:r,count:s}=t;const{componentType:i,itemSize:o}=t,a=t.array.buffer,c=i?Ue.getTypedArrayCtor(i):t.array.constructor;if(n=void 0===n?t.array.byteOffset:n,r=r||0,s=s||t.array.length/o,(!r||r===o*c.BYTES_PER_ELEMENT)&&n%c.BYTES_PER_ELEMENT==0){const t=new c(a,n,s*o);for(let r=0;r<s*o;r+=o){e(new c(t.buffer,n+r*c.BYTES_PER_ELEMENT,o),r/o)}return}const h=new Uint8Array(o*c.BYTES_PER_ELEMENT);r||(r=o*c.BYTES_PER_ELEMENT);for(let t=0;t<s;t++){const s=new Uint8Array(a,r*t+n,o*c.BYTES_PER_ELEMENT);h.set(s);e(new c(h.buffer),t),s.set(h)}}(y,(t,e)=>{w?(sn(A,v,e),sn(x,w,e),n.vec3.cross(I,A,x),n.vec3.normalize(I,I),bt(N,A,0),bt(N,x,1),bt(N,I,2),n.quat.fromMat3(C,N)):M?(sn(k,M,e),n.quat.fromMat3(C,k)):n.quat.identity(C),T?(sn(S,T,e),n.vec3.set(P,S[0],S[0],S[0])):_?(sn(E,_,e),n.vec3.set(P,...E)):n.vec3.set(P,1,1,1),n.mat4.fromRotationTranslationScale(R,C,t,P),on(O.instance_vectorA,e,R,0),on(O.instance_vectorB,e,R,1),on(O.instance_vectorC,e,R,2)});const L={};for(const t in O)L[t]={buffer:this.ct.buffer({dimension:O[t].length/d,data:O[t]}),divisor:1};const B=i.shader||"pbr";let U=0,F=!0;const D=[],j=[];return Qe(h,(t,s,i,a)=>{const c=this.be(t,s,i,a,r,!0,B,j),{geometry:h,material:g}=c;g&&!g.isReady()&&(F=!1,U++);const y=new n.reshader.InstancedMesh(L,d,h,g);c.refMeshes||(c.refMeshes=new Set,c.refMeshes.add(y.uuid)),y.properties.magic="i3dm",y.properties.id=e,y.properties.count=f,y.properties.batchTable=u,y.properties.batchTableBin=l,y.properties.serviceIndex=r.kt,y.properties.rtcCoord=p,y.properties.rtcCenter=m,y.properties.node=r;const w=this.ge(t,h,g,r.kt,a);t.compressed_int16_params&&this.ue(y,t.compressed_int16_params),this.ye(y,t.attributes);const v=n.mat4.identity([]);if(t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)n.mat4.multiply(v,v,t.matrices[e]);n.mat4.multiply(v,o,v),y.setPositionMatrix(v),this.ae(y,b),y.setDefines(w),y.properties.polygonOffset={offset:0,factor:0},D.push(y),delete t.attributes,y.Ut=n.mat4.copy([],y.localTransform)}),us(j),F?(this.dt[e]=D,s(null,{id:e,mesh:D})):(this.ut[e]={meshes:D,count:U},D.we=s),D}ae(t,e){const{rtcCenter:r,rtcCoord:s,node:i}=t.properties;if(!e){e=this.me(Qr,s);const t=this.pe(Zr,i,r,s);n.mat4.multiply(e,t,e)}const o=this.st.Rt(i.kt),a=t.localTransform||[];if(o.coordOffset){const t=this.ve(Zr,i.kt,s);n.mat4.multiply(a,t,e)}else n.mat4.copy(a,e);t.setLocalTransform(a),t.properties.heightOffset=o.heightOffset||0,t.properties.coordOffset=o.coordOffset&&o.coordOffset.slice(0)||jr}createB3DMMesh(t,e,r,i){if(t.gltf&&(t.gltf.transferables=null),this.lt[e]||this.ut[e]){const t=this.lt[e];return console.warn(`mesh with id(${e}) was already created.`),this.ut[e]||i(null,{id:e,mesh:t}),t}let o;if(r.maxExtent){const t=new s.Extent(r.maxExtent).convertTo(t=>this._pointToPrj(t));o=[t.xmin,t.ymin,t.xmax,t.ymax]}const a=t.gltf,{projCenter:c}=a.extensions.MAPTALKS_RTC,{rtcCoord:h,center:u}=a.extensions.CESIUM_RTC,l=a.asset.sharePosition,f=this.fe(r.de);let d;d=l?this.me(Qr,h):this.le(Qr,h,c,r.kt);const m=this.st.Rt(r.kt);let p=m.shader||"pbr";if(m.unlit)p="phong";else if(a.materials)for(let t=0;t<a.materials.length;t++)if(a.materials[t]&&a.materials[t].extensions&&a.materials[t].extensions.KHR_materials_unlit){p="phong";break}const b=[],g=[];let y=0,w=!0;return Qe(a,(s,i,a,v)=>{const T=this.be(s,i,a,v,r,!1,p,b),{geometry:_,material:M}=T;M&&!M.isReady()&&(w=!1,y++);const O=new n.reshader.Mesh(_,M);T.refMeshes||(T.refMeshes=new Set,T.refMeshes.add(O.uuid)),O.properties.magic="b3dm",O.properties.id=e,O.properties.node=r,t.batchTable&&(O.properties.batchTable=t.batchTable,O.properties.batchTableBin=t.batchTableBin),O.properties.count=t.featureTable&&t.featureTable.BATCH_LENGTH||0,O.properties.serviceIndex=r.kt;const x=this.ge(s,_,M,r.kt,v);O.setDefines(x);const A=s.compressUniforms;if(A)for(const t in A)O.setUniform(t,A[t]);s.compressed_int16_params&&this.ue(O,s.compressed_int16_params),this.ye(O,s.attributes),o&&(x.USE_MAX_EXTENT=1,O.setUniform("maxPrjExtent",o)),Object.prototype.hasOwnProperty.call(O.uniforms,"polygonOpacity")||Object.defineProperty(O.uniforms,"polygonOpacity",{enumerable:!0,get:function(){return ht(m.opacity)?m.opacity:1}}),Object.prototype.hasOwnProperty.call(O.uniforms,"polygonFill")||Object.defineProperty(O.uniforms,"polygonFill",{enumerable:!0,get:function(){return Mt([],m.polygonFill||Lr)}}),Object.prototype.hasOwnProperty.call(O.material.uniforms,"hsv")||Object.defineProperty(O.material.uniforms,"hsv",{enumerable:!0,get:function(){return m.hsv||Br}});const I=n.mat4.identity([]);if(l&&s.matrices&&s.matrices.length)for(let t=0;t<s.matrices.length;t++)n.mat4.multiply(I,I,s.matrices[t]);l&&n.mat4.multiply(I,f,I),O.properties.node=r,O.properties.projCenter=c,O.properties.nodeMatrix=I,O.properties.isSharedPosition=l,O.properties.rtcCoord=h,O.properties.rtcCenter=u,this.oe(O,d),g.push(O),delete s.attributes,O.Ut=n.mat4.copy([],O.localTransform)}),us(b),w?(this.lt[e]=g,i(null,{id:e,mesh:g})):(this.ut[e]={meshes:g,count:y},g.we=i),g}Te(t){const e=this.st._e[t.id];if(!e)return;let r,s,i,o;if(e.length){if(2===e.length){const t=e[0],n=e[1];r=os.vertices,s=os.indices,i=t,o=[n,n,n]}}else{r=e.boxPosition,s=is;i=this.st.Rt(t.kt).Me,o=cs}const a=new n.reshader.Geometry({POSITION:r},s,0,{primitive:"lines",positionAttribute:"POSITION"}),c=new n.reshader.Mesh(a,new n.reshader.Material({lineColor:[.8,.8,.1,1],lineOpacity:1})),h=n.mat4.identity([]);n.mat4.fromRotationTranslationScale(h,as,i,o),c.localTransform=h,c.Ut=n.mat4.copy([],h),c.properties.node=t,t.Lt=c}ue(t,e){e.POSITION&&t.setUniform("compressedPositionRange",e.POSITION),e.TEXCOORD_0&&t.setUniform("compressedTexcoordRange_0",e.TEXCOORD_0),e.TEXCOORD_1&&t.setUniform("compressedTexcoordRange_1",e.TEXCOORD_0),e.NORMAL&&t.setUniform("compressedNormalRange",e.NORMAL),e.TANGENT&&t.setUniform("compressedTangentRange",e.TANGENT),e.compressed_ratio&&t.setUniform("compressed_ratio",e.compressed_ratio)}oe(t,e){const{isSharedPosition:r,rtcCoord:s,rtcCenter:i,projCenter:o,nodeMatrix:a,node:c}=t.properties;e||(e=r?this.me(Qr,s):this.le(Qr,s,o,c.kt));const h=t.localTransform||n.mat4.identity([]);if(r){const t=this.pe(Zr,c,i,s);n.mat4.multiply(h,e,a),n.mat4.multiply(h,t,h)}else n.mat4.multiply(h,e,a);const u=this.st.Rt(c.kt);if(u.coordOffset){const t=this.ve(Zr,c.kt,s);n.mat4.multiply(h,t,h)}t.setLocalTransform(h),t.properties.heightOffset=u.heightOffset||0,t.properties.coordOffset=u.coordOffset&&u.coordOffset.slice(0)||jr}ye(t,e){if(e&&e.TEXCOORD_0&&e.TEXCOORD_0.extensions&&e.TEXCOORD_0.extensions.WEB3D_quantized_attributes){const n=e.TEXCOORD_0.extensions.WEB3D_quantized_attributes.decodeMatrix;t.setUniform("decodeMatrix",n)}}pe(t,e,r,i){const o=this.getMap(),a=this.st.Rt(e.kt).heightOffset||0,c=new s.Coordinate(i);let h;h=o.altitudeToPoint?this.St:o.distanceToPointAtRes(100,100,o.getGLRes(),c).y/100;const u=e.matrix?n.mat4.copy(t,e.matrix):n.mat4.identity(t);if(r){Kn(u,n.vec3.transformMat4(Gr,r,u),u)}const l=function(t,e,n,r,s,i,o){e=Bt(Zn,e);const a=ln(Zn,e[0]*or,e[1]*or,e[2]),c=function(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}(Yn,n),h=r.ellipsoid;let u;u=0===Xt(c)?Ut(Wn,0,0,-6378137):gn(Wn,c),sr.x=u[0],sr.y=u[1];const l=r.project(sr,ir);tr[0]=l.x/s,tr[1]=l.y/s,tr[2]=(u[2]+o)*i;const f=Qn(a,h,er),d=function(t,e,n){const r=t[0],s=t[1],i=t[2],o=t[4],a=t[5],c=t[6],h=t[8],u=t[9],l=t[10],f=e[0],d=e[1],m=e[2],p=e[3],b=e[4],g=e[5],y=e[6],w=e[7],v=e[8],T=r*f+o*d+h*m,_=s*f+a*d+u*m,M=i*f+c*d+l*m,O=r*p+o*b+h*g,x=s*p+a*b+u*g,A=i*p+c*b+l*g,I=r*y+o*w+h*v,S=s*y+a*w+u*v,E=i*y+c*w+l*v;return n[0]=T,n[1]=_,n[2]=M,n[3]=0,n[4]=O,n[5]=x,n[6]=A,n[7]=0,n[8]=I,n[9]=S,n[10]=E,n[11]=0,n[12]=t[12],n[13]=t[13],n[14]=t[14],n[15]=t[15],n}(function(t,e){var n=e[0],r=e[1],s=e[2],i=e[3],o=e[4],a=e[5],c=e[6],h=e[7],u=e[8],l=e[9],f=e[10],d=e[11],m=e[12],p=e[13],b=e[14],g=e[15],y=n*a-r*o,w=n*c-s*o,v=n*h-i*o,T=r*c-s*a,_=r*h-i*a,M=s*h-i*c,O=u*p-l*m,x=u*b-f*m,A=u*g-d*m,I=l*b-f*p,S=l*g-d*p,E=f*g-d*b,N=y*E-w*S+v*I+T*A-_*x+M*O;return N?(N=1/N,t[0]=(a*E-c*S+h*I)*N,t[1]=(s*S-r*E-i*I)*N,t[2]=(p*M-b*_+g*T)*N,t[3]=(f*_-l*M-d*T)*N,t[4]=(c*A-o*E-h*x)*N,t[5]=(n*E-s*A+i*x)*N,t[6]=(b*v-m*M-g*w)*N,t[7]=(u*M-f*v+d*w)*N,t[8]=(o*S-a*A+h*O)*N,t[9]=(r*A-n*S-i*O)*N,t[10]=(m*_-p*v+g*y)*N,t[11]=(l*v-u*_-d*y)*N,t[12]=(a*x-o*I-c*O)*N,t[13]=(n*I-r*x+s*O)*N,t[14]=(p*w-m*T-b*y)*N,t[15]=(u*T-l*w+f*y)*N,t):null}(nr,f),function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t}(rr,n),t);return Kn(t,tr,d),t}(u,i,u,o.getProjection(),o.getGLRes(),h,a),f=function(t,e){return Ut(t,e[12],e[13],e[14]),t}(Kr,l);let d=this.st.options.offset;if(at(d)){const t=this.st.Oe(e.id).center;d=d.call(this.st,t)}return n.vec3.set(Jr,d[0],d[1],0),n.vec3.sub(f,f,Jr),Kn(l,f,l),l}ve(t,e,r){const s=this.st.Rt(e);if(!s.coordOffset)return null;const i=this.getMap(),o=i.getGLRes();qr.set(r[0],r[1]);const a=i.coordToPointAtRes(qr,o,$r),c=s.coordOffset,h=qr.set(r[0]+c[0],r[1]+c[1]),u=i.coordToPointAtRes(h,o,Xr),l=u.x-a.x,f=u.y-a.y,d=this.Wt(),m=n.vec3.set(Jr,l,f,(c[2]||0)*d);return n.mat4.fromTranslation(t,m)}Wt(){const t=this.getMap();let e;return e=t.altitudeToPoint?this.St:t.distanceToPointAtRes(100,100,t.getGLRes(),qr).y/100,e}createCMPTMesh(t,e,n,r){if(this.pt[e]){const t=this.pt[e];return console.warn(`mesh with id(${e}) was already created.`),r(null,{id:e,mesh:t}),t}const{content:s}=t,i=[];for(let t=0;t<s.length;t++){const{magic:r}=s[t],o=e+"."+t;"b3dm"===r?this.createB3DMMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)}):"i3dm"===r?this.createI3DMMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)}):"pnts"===r?this.createPntsMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)}):"cmpt"===r&&this.createCMPTMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)})}return this.pt[e]=i,r(null,{id:e,mesh:i}),i}ge(t,e,n,r,s){const i=("phong"===(this.st.Rt(r).shader||"pbr")?this.Xt:this.Jt).getGeometryDefines(e);s.asset&&"S3M"===s.asset.generator&&this.xe(i,e),e.data.uvRegion&&(i.HAS_I3S_UVREGION=1),e.data[e.desc.normalAttribute]&&(i.VertexNormal=1),e.data[e.desc.color0Attribute]&&(i.VertexColor=1),e.data[e.desc.uv0Attribute]&&(i.TexCoord=1),e.data[e.desc.textureCoordMatrixAttribute]&&(i.HAS_TextureCoordMatrix=1),n.get("uTexture")&&(i.COMPUTE_TEXCOORD=1),n.get("uTexture2")&&(i.TexCoord2=1),"MESHOPT"===this.st.Ae&&(i.MeshOPT_Compress=1),this.hasIBL()&&(i.HAS_IBL_LIGHTING=1),t.attributes&&t.attributes.TEXCOORD_0&&"WEB3D_quantized_attributes"===t.attributes.TEXCOORD_0.extensions&&(i.HAS_WEB3D_quantized_attributes_TEXCOORD=1),i.HAS_MIN_ALTITUDE=1,i.HAS_LAYER_OPACITY=1,this.he(i,t.compressed_int16_params);return ot(i,t.compressDefines),i}he(t,e){e&&Object.keys(e).length>0&&(t.HAS_COMPRESSED_INT16=1,e.POSITION&&(t.HAS_COMPRESSED_INT16_POSITION=1),e.TEXCOORD_0&&(t.HAS_COMPRESSED_INT16_TEXCOORD_0=1),e.TEXCOORD_1&&(t.HAS_COMPRESSED_INT16_TEXCOORD_1=1),e.NORMAL&&(t.HAS_COMPRESSED_INT16_NORMAL=1),e.TANGENT&&(t.HAS_COMPRESSED_INT16_TANGENT=1),e.compressed_ratio&&(t.HAS_COMPRESSED_INT16_RATIO=1))}qt(t){const e=this.st.getRenderer();e&&e.updateMaskDefines(t)}xe(t,e){e.data.aNormal&&(t.VertexNormal=1),e.data.instanceId&&(t.Instance=1),e.data.aTexCoord0&&(t.TexCoord=1),e.data.aColor&&(t.VertexColor=1),e.data.aTexCoord1&&(t.TexCoord2=1),e.data.uv2&&(t.InstanceBim=1)}be(t,e,n,r,s,i,o,a){let c=!1;r.asset&&"S3M"===r.asset.generator&&(c=!0,r.extensions=r.extensions||{});const h=r.url+"-"+e+"-"+n;if(this.bt[h])return this.bt[h];let u,l;a.push(t);const f=r.materials&&r.materials[t.material],d=r.extensions&&r.extensions.KHR_techniques_webgl,m=this.st.Rt(s.kt);if(d&&f.extensions&&f.extensions.KHR_techniques_webgl){const e=this.Ie(t,r,i,c);u=e.material,l=e.geometry,m.fillEmptyDataInMissingAttribute&&(l.desc.fillEmptyDataInMissingAttribute=!0)}else{l=this.Se(t,i,ss);const e=m.ambientLight;let n=m.environmentExposure;const s=m.material,c=this.getMap().getLightManager(),h=c&&c.getAmbientLight();if(e&&(!h||h.color)&&void 0===n){const t=h&&h.color?h.color[0]:.2;n=e[0]/t}u=this.Ee(t.material,r,o,s||Ur,n||1,a,m)}u&&Object.defineProperty(u.uniforms,"alphaTest",{enumerable:!0,get:function(){const t=m.alphaTest;return it(t)?.1:t}}),u&&!u.isReady()?u.Ne=s.id:u||(u=this.Ot);const p={geometry:l,material:u};return l.properties.url=h,this.bt[h]=p,p}Ie(t,e,n,r){const{geometry:s,material:i}=this.At.createMesh(t,e,n,r);return{geometry:s,material:i}}Se(t,e,r){const s=t.attributes;let i=s._BATCHID&&s._BATCHID.array;if(i&&i.byteOffset&&(i=new i.constructor(i)),s.COLOR_0){const t=s.COLOR_0.array||s.COLOR_0;if(t instanceof Float32Array){const e=new Uint8Array(t.length);for(let n=0;n<e.length;n++)e[n]=Math.round(255*t[n]);s.COLOR_0.array?(s.COLOR_0.array=e,s.COLOR_0.componentType=5121):s.COLOR_0=e}}const o={};for(const t in s){const e=Ir(this.ct,s[t],{dimension:s[t].itemSize}),n=r[t]||t;o[n]={buffer:e},s[t].quantization&&(o[n].quantization=s[t].quantization),n===r.POSITION&&(o[n].array=s[t].array,o[n].min=s[t].min,o[n].max=s[t].max)}const a=t.indices?t.indices.array?t.indices.array.slice():t.indices:null,c=new n.reshader.Geometry(o,a,0,{static:!0,positionAttribute:r.POSITION,normalAttribute:r.NORMAL,uv0Attribute:r.TEXCOORD_0,uv1Attribute:r.TEXCOORD_1,color0Attribute:r.COLOR_0,tangentAttribute:r.TANGENT,pickingIdAttribute:r._BATCHID,primitive:void 0===t.mode?"triangles":Ar(t.mode)});return i&&a&&(c.properties.batchIdData=i,c.properties.batchIdMap=function(t,e){if(!e)return null;const n=new Map;for(let r=0;r<e.length;r++){const s=e[r],i=t[s];let o=n.get(i);o||(o=[],n.set(i,o)),o.push(s)}return n}(i,a)),c.generateBuffers(this.ct,{excludeElementsInVAO:e}),c}le(t,e,r,s){const i=n.mat4.identity(t),o=this.getMap();qr.x=r[0],qr.y=r[1];const a=this._prjToPoint(qr),c=this.Ce(),h=1/(o.getGLZoom?o.getResolution(o.getGLZoom()):o.getGLRes());qr.x=e[0],qr.y=e[1];const u=this.Wt();let l=this.st.options.offset;at(l)&&(l=l.call(this.st,qr));const f=this.st.Rt(s).heightOffset||0;return n.vec3.set(Kr,a.x-l[0],a.y-l[1],u*r[2]+u*f),n.mat4.translate(i,i,Kr),n.vec3.set(c,h,h,u),n.mat4.scale(i,i,c),i}Vt(t,e){const r=this.st.Rt(e.kt),s=r.Me;let i=r.rotation||[0,0,0];i=n.quat.fromEuler(ts,i[0],i[1],i[2]);const o=r.scale||[1,1,1],a=n.mat4.fromRotationTranslationScale([],i,es,o),c=n.mat4.identity([]),h=n.mat4.identity([]);n.mat4.translate(c,c,n.vec3.scale(rs,s,-1)),n.mat4.translate(h,h,s);const u=n.mat4.multiply(c,c,t.Ut);n.mat4.multiply(a,a,u);const l=n.mat4.multiply(h,h,a);t.localTransform=l}me(t,e){const r=n.mat4.identity(t),s=this.getMap(),i=this.Ce();qr.x=e[0],qr.y=e[1];const o=s.distanceToPointAtRes(100,100,s.getGLRes(),qr);let a;return a=s.altitudeToPoint?this.St:o.y/100,n.vec3.set(i,o.x/100*1.01,o.y/100*1.01,a),n.mat4.scale(r,r,i),r}xt(){const t={x:0,y:0,width:()=>this.it?this.it.width:1,height:()=>this.it?this.it.height:1},e=[],r=[];this.Qt=new n.reshader.MeshShader({vert:an,frag:"#define SHADER_NAME PNTS\n\nprecision mediump float;\n\n\n\nvarying vec4 vColor;\n\n\n\nvoid main() {\n\n vec2 circCoord = 2.0 * gl_PointCoord - 1.0;\n\n if (dot(circCoord, circCoord) > 1.0) {\n\n discard;\n\n } else {\n\n gl_FragColor = vColor;\n\n }\n\n}\n\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:(t,e)=>n.mat4.multiply(r,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,r)=>n.mat3.fromMat4(e,r.modelMatrix)}],extraCommandProps:{viewport:t,blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"},depth:{enable:!0,range:[0,1],func:"<"}}});const s=this.It();this.Xt=new n.reshader.PhongShader({extraCommandProps:s}),this.Jt=new n.reshader.pbr.StandardShader({extraCommandProps:s}),this.Yt=new n.reshader.EdgeShader({extraCommandProps:{viewport:{x:0,y:0,width:()=>this.it?this.it.width:1,height:()=>this.it?this.it.height:1},blend:{enable:!0,func:{srcRGB:"src alpha",srcAlpha:1,dstRGB:"one minus src alpha",dstAlpha:"one minus src alpha"},equation:"add"}}});const i=this.st;Nr(i.getRenderer().canvas,this.ct,i.getMap()),this.picking=new n.reshader.FBORayPicking(this.ht,{vert:this.Jt.vert,extraCommandProps:s,uniforms:this.Jt.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap()),this.Pe=new n.reshader.FBORayPicking(this.ht,{vert:an,extraCommandProps:s,uniforms:this.Qt.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap())}It(){return{viewport:{x:0,y:0,width:()=>this.it?this.it.width:1,height:()=>this.it?this.it.height:1},cull:{enable:!0},stencil:{enable:!0,func:{cmp:(t,e)=>e.meshProperties.isLeaf?"always":">=",ref:(t,e)=>e.meshProperties.level},opFront:{fail:"keep",zfail:"keep",zpass:"replace"},opBack:{fail:"keep",zfail:"keep",zpass:"replace"}},depth:{enable:!0,range:[0,1],func:(t,e)=>e.meshProperties.depthFunc||"<"},blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"},polygonOffset:{enable:!0,offset:(t,e)=>e.meshProperties.polygonOffset}}}Kt(t){const e=this.getMap(),r=e.getLightManager(),s=(r&&r.getDirectionalLight()||{}).direction||[1,1,-1],i=t&&t.pointOpacity||1;return{projViewMatrix:e.projViewMatrix,pointOpacity:i,lightDir:n.vec3.normalize(s,s)}}Nt(){const t=this.getMap(),e=this.st,n=e.getRenderer().canvas,{iblTexes:r,dfgLUT:s}=Pr(n),i=Rr(t,r,s),o=this.st.getRenderer(),a=o.getMaskUniforms();i.minAltitude=e.options.altitude||0;const c=o.canvas.gl&&o.canvas.gl.wrap?e.options.opacity||0:1;return i.layerOpacity=c,ot(i,{czm_lightDirectionEC:i.light0_viewDirection,lightSpecular:[1,1,1],viewMatrix:t.viewMatrix,projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,outSize:[n.width,n.height],polygonFill:[1,1,1,1],polygonOpacity:1}),ot(i,a),i}Ee(t,e,r,s,i,o,a){const c=e.materials&&e.materials[t];if(!c||!c.baseColorTexture&&!c.pbrMetallicRoughness)return null;const h=ot({},s);if(c.baseColorTexture){const t=e.textures[c.baseColorTexture.index];let n;t&&!t.image.color&&(n=this.C(t,o)),h.baseColorFactor=t&&t.image.color||c.baseColorFactor||[1,1,1,1],n&&(h.baseColorTexture=n)}else{if(c.normalTexture){const t=this.C(e.textures[c.normalTexture.index],o);if(t){const e=c.normalTexture.scale||1;h.normalTexture=t,h.normalMapFactor=e}}if(c.occlusionTexture){const t=this.C(e.textures[c.occlusionTexture.index],o);if(t){const e=c.occlusionTexture.strength||1;h.occlusionTexture=t,h.occlusionFactor=e}}if(c.emissiveTexture){const t=this.C(e.textures[c.emissiveTexture.index],o);t&&(h.emissiveTexture=t)}c.emissiveFactor&&(h.emissiveFactor=c.emissiveFactor);const t=c.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(h.baseColorFactor=t.baseColorFactor),t.baseColorTexture&&void 0!==t.baseColorTexture.index){const r=e.textures[t.baseColorTexture.index];if(r.image&&r.image.color)h.baseColorFactor=h.baseColorFactor?n.vec4.multiply(h.baseColorFactor,h.baseColorFactor,r.image.color):r.image.color;else{const t=this.C(r,o);t&&(h.baseColorTexture=t,h.baseColorTexture.getREGLTexture(this.ct))}}if(it(t.metallicFactor)||(h.metallicFactor=t.metallicFactor),it(t.roughnessFactor)||(h.roughnessFactor=t.roughnessFactor),c.metallicRoughnessTexture){const t=this.C(e.textures[c.metallicRoughnessTexture.index],o);t&&(h.metallicRoughnessTexture=t)}}}if(c.s3mMaterial)return new n.reshader.Material(h);if(h.environmentExposure=i,h.alphaTest=.1,a.unlit||c.extensions&&c.extensions.KHR_materials_unlit)return h.ambientColor=[1,1,1],h.light0_diffuse=[0,0,0,0],h.lightSpecular=[0,0,0],new n.reshader.PhongMaterial(h);let u=new n.reshader.pbr.StandardMaterial(h);"phong"===r&&(u=n.reshader.PhongMaterial.convertFrom(u));const l=c.pbrMetallicRoughness,f=l&&l.baseColorTexture&&l.baseColorTexture.extensions;return f&&f.KHR_texture_transform&&(u.set("khr_offset",f.KHR_texture_transform.offset||[0,0]),u.set("khr_rotation",f.KHR_texture_transform.rotation||0),u.set("khr_scale",f.KHR_texture_transform.scale||[1,1])),u.doubleSided=!(!a.doubleSided&&!c.doubleSided),u.once("complete",this._t),u}C(t,e){const r={type:t.type?Or(t.type):"uint8",format:t.format?xr(t.format):"rgba",flipY:!!t.flipY},s=t.image;if(e.push(s),s.array?r.data=s.array:s.mipmap&&(r.mipmap=s.mipmap),!r.data&&!r.mipmap)return null;if(r.width=s.width,r.height=s.height,r.mipmap&&(r.width<4||r.height<4))return null;const i=t.sampler||t.texture&&t.texture.sampler;return i&&(i.magFilter&&(r.mag=Tr(i.magFilter)),i.minFilter&&(r.min=_r(i.minFilter)),i.wrapS&&(r.wrapS=Mr(i.wrapS)),i.wrapT&&(r.wrapT=Mr(i.wrapT))),new n.reshader.Texture2D(r,this.Tt)}Mt({target:t}){const e=t.Ne,n=this.ut[e];if(n.count--,!n.count){const t=n.meshes;this.lt[e]=t,delete this.ut[e];const r=t.we;delete t.we,r(null,{mesh:n.meshes,id:e})}}Ce(){return Fr}Re(t){return this.st.Re(t)}_pointToPrj(t){const e=this.getMap();return e.getGLZoom?e._pointToPrj(t,e.getGLZoom()):e._pointToPrjAtRes(t,e.getGLRes())}_prjToPoint(t){const e=this.getMap();return e.getGLZoom?e._prjToPoint(t,e.getGLZoom()):e._prjToPointAtRes(t,e.getGLRes(),Vr)}fe(t){return"Y"===t?Sr:"X"===t?Er:Dr}pick(t,e,n=3){const r=this.st;if(!r||!r.options.picking)return[];if(!this.pickingFBO||!this.picking)return[];const s=[],i=this.Nt(),o=this.ke(this.picking,i,this.gt,t,e,n);o&&s.push(o);const a=this.ke(this.picking,i,this.wt,t,e,n);a&&s.push(a);const c=this.Kt(),h=this.ke(this.Pe,c,this.yt,t,e,n);return h&&s.push(h),s}ke(t,e,n,r,s,i){if(!n.getMeshes().length)return null;const o=this.st,a=this.getMap();t.render(n.getMeshes().filter(t=>!t.bloom),e,!0);let c={};t.getRenderedMeshes().length&&(c=t.pick(r,s,i,e,{viewMatrix:a.viewMatrix,projMatrix:a.projMatrix,returnPoint:o.options.pickingPoint}));const{meshId:h,pickingId:u,point:l,coordinate:f}=c,d=(0===h||h)&&t.getMeshAt(h);if(!d||!d.geometry)return null;const m=d.properties;l&&l.length&&(l[0]=Math.round(1e5*l[0])/1e5,l[1]=Math.round(1e5*l[1])/1e5,l[2]=Math.round(1e5*l[2])/1e5);const p={batchId:u};if(o.options.debug&&(p.debugInfo=m),m&&m.batchTable){const{batchTable:t,batchTableBin:e,count:n}=m,r=u;for(const s in t)void 0!==t[s].byteOffset?p[s]=Rn(t[s],e,n,r):p[s]=t[s][r]}return{service:d.properties.serviceIndex,data:p,point:l,coordinate:f}}Ct(t){let e=new Set;for(let n=0,r=t.length;n<r;n++){const r=t[n].data.node;this.Pt(r)&&e.add(r.Ht)}e=Array.from(e),e.sort();const n=new Map,r=e.length;for(let t=0;t<r;t++)n.set(e[t],t);return n}highlight(t){this.Ft=t;const e=this.st.getRenderer();this.Dt=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelAllHighlight(){this.Ft=null;const t=this.st.getRenderer();this.Dt=t.getFrameTimestamp(),t.setToRedraw(!0)}showOnly(t){this.jt=t;const e=this.st.getRenderer();this.zt=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelShowOnly(){this.jt=null;const t=this.st.getRenderer();this.zt=t.getFrameTimestamp(),t.setToRedraw(!0)}Le(){if(!this.Et)return[];const t={},e=[];for(const n in this.Et){const r=this.Et[n];if(r)for(let n=0;n<r.length;n++){const s=r[n],i=s&&s.geometry;if(!s||!i)continue;const o=s.properties.serviceIndex;t[o]||(t[o]=new Set);const a=i.properties.batchIdData;if(a)for(let n=0;n<a.length;n++)t[o].has(a[n])||(e.push({id:a[n],service:o}),t[o].add(a[n]))}}return e}hasIBL(){const t=this.getMap().getLightManager();return!!(t&&t.getAmbientResource())}}function us(t){for(let e=0;e<t.length;e++)t[e]&&(t[e].array&&(t[e].array=null),t[e].mipmap&&(t[e].mipmap=null),t[e].indices&&(t[e].indices=null))}const ls=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("unable to locate global object")},fs=ls(),ds=fs.gl_trans__coders=fs.gl_trans__coders||{};function ms(t,e){if(e)for(let n=0;n<e.length;n++){t[e[n].id||e[n].index]=e[n]}}ds.inject=function(t){const e=t.toString(),n=e.indexOf("{")+1,r=e.substring(0,n),s=fs.gl_trans__coders=fs.gl_trans__coders||{};let i=`${r}\n const _____getGlobal = ${ls.toString()};\n const g___lobals = _____getGlobal()\n const tran_____scoders = g___lobals['gl_trans__coders'] = g___lobals['gl_trans__coders'] || {};`;for(const t in s)"inject"!==t&&"getTranscoder"!==t&&"registerTranscoder"!==t&&(i+='tran_____scoders["'+t+'"] ='+s[t].toString()+"\n;");return i+="\n"+e.substring(r.length),i},ds.registerTranscoder=function(t,e){ds[t]=e},ds.getTranscoder=function(t){return ds[t]};const ps=[];class bs{constructor(t,e,n,r,s){this.st=r,this.Be=t,this.kt=e,this.Ue=s,this.Fe=n.version,t.indexOf("i3s:tileset:")<0?(this.Fe<=1.6?this.De="root":this.De=0,n.version=this.Fe):(this.De=t.substring("i3s:tileset:".length),this.Fe>1.6&&(this.De=parseInt(this.De))),this.Be=t,this.je=n}load(){const t=this.je,e=t.layerScene.baseUrl;if(this.Fe<=1.6)return t[this.De]&&t[this.De].lodSelection?(this.ze=t[this.De],this.He()):new Promise(n=>{let r=e+"/nodes/"+this.De;t.layerScene.eslpk&&(r+="/3dNodeIndexDocument.json"),this.Ue(this.kt,r,()=>{this.ze=t[this.De],n(this.He())})});if(this.Fe>=1.7){if(t[this.De])return this.ze=t[this.De],this.He();const n=Math.floor(this.De/t.nodesPerPage);return new Promise(r=>{let s=e+"/nodepages/"+n;t.layerScene.eslpk&&(s+=".json"),this.Ue(this.kt,s,()=>{this.ze=t[this.De],r(this.He())})})}return null}getTileset(){return this.Ge}getChildrenURL(){return this.qe}He(){const t=this.je,e=t.layerScene.baseUrl,n=this.ze.children,r=[],s={};if(n)for(let i=0;i<n.length;i++)if(this.Fe<=1.6){const o=n[i].id;if(t[o])continue;const a=o;s[a]||(s[a]=new Promise(n=>{let r=e+"/nodes/"+a;t.layerScene.eslpk&&(r+="/3dNodeIndexDocument.json"),this.Ue(this.kt,r,()=>{n()})}),r.push(s[a]))}else{const o=n[i];if(t[o])continue;const a=Math.floor(o/t.nodesPerPage);s[a]||(s[a]=new Promise(n=>{let r=e+"/nodepages/"+a;t.layerScene.eslpk&&(r+=".json"),this.Ue(this.kt,r,()=>{n()})}),r.push(s[a]))}return r.length?Promise.all(r).then(()=>this.Ve()):this.Ve()}Ve(){return Promise.resolve(this.$e())}Xe(t){ms(this.je,t)}$e(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.Je(this.ze,!0)}}Je(t){const e=this.st.getRenderer(),n=this.je.projection,r=!n||n&&4326===n.wkid,s=this.Fe,i=this.je,o=t,a=o.obb,c=o.mbs,h={};let u;if(c)u=Ut([],c[0],c[1],c[2]),r||(u=e.Ke(u,u)),u=gs([],u[0],u[1],u[2]),h.sphere=[...u,c[3]];else if(a){u=Ut([],a.center[0],a.center[1],a.center[2]),r||(u=e.Ke(u,u)),u=gs([],u[0],u[1],u[2]);const t=function(t,e,n){const r=function(t,e){var n=e[0],r=e[1],s=e[2],i=e[3],o=n+n,a=r+r,c=s+s,h=n*o,u=r*o,l=r*a,f=s*o,d=s*a,m=s*c,p=i*o,b=i*a,g=i*c;return t[0]=1-l-m,t[3]=u-g,t[6]=f+b,t[1]=u+g,t[4]=1-h-m,t[7]=d-p,t[2]=f-b,t[5]=d+p,t[8]=1-h-l,t}([],n);return r[0]=r[0]*e[0],r[1]=r[1]*e[0],r[2]=r[2]*e[0],r[3]=r[3]*e[1],r[4]=r[4]*e[1],r[5]=r[5]*e[1],r[6]=r[6]*e[2],r[7]=r[7]*e[2],r[8]=r[8]*e[2],[...t,...r]}(u,a.halfSize,a.quaternion),n=t[3]+t[6]+t[9],s=t[4]+t[7]+t[10],i=t[5]+t[8]+t[11];Ut(ps,n,s,i);const o=Xt(ps);h.sphere=[...u,o]}let l=1/0,f=0;if(o.mbs?f=o.mbs[3]:o.obb&&(f=Math.max(Math.max(o.obb.halfSize[0],o.obb.halfSize[1]),o.obb.halfSize[2])),void 0!==o.lodThreshold)if("maxScreenThresholdSQ"===i.lodSelectionMetricType){l=f/(Math.sqrt(o.lodThreshold)/(.25*Math.PI))}else console.error("Unsupported lodSelectionMetricType in Layer");else if(void 0!==o.lodSelection)for(let t=0;t<o.lodSelection.length;t++)"maxScreenThreshold"===o.lodSelection[t].metricType&&(l=f/o.lodSelection[t].maxError);(l===1/0||isNaN(l))&&(l=1e5);const d=16*l,m=St([]),p=o.children;let b;if(p){b=[];const t=this.je;for(let e=0;e<p.length;e++){const n=s<=1.6?p[e].id:p[e];if(!t[n]){b=null;break}b.push(this.Je(t[n]))}}const g={refine:"REPLACE",boundingVolume:h,transform:m,geometricError:d};return s<=1.6?t.lodSelection?t.geometryData&&(g.content={uri:"i3s:mesh:"+(t.id||t.index)}):g.content={uri:"i3s:tileset:"+(t.id||t.index)}:p&&p.length&&!b?g.content={uri:"i3s:tileset:"+(t.id||t.index)}:o.mesh&&(g.content={uri:"i3s:mesh:"+(t.id||t.index)}),b&&b.length&&(g.children=b),g}getJSON(){return this.ze}}function gs(t,e,n,r){return ln(t,ut(e),ut(n),r)}const ys=!!ds.ktx2,ws=n.mat4.identity([]),vs=(()=>{try{if("object"==typeof WebAssembly&&"function"==typeof WebAssembly.instantiate){const t=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));if(t instanceof WebAssembly.Module)return new WebAssembly.Instance(t)instanceof WebAssembly.Instance}}catch(t){}return!1})();function Ts(t){return t.indexOf("i3s:mesh")>=0}const _s="i3s:mesh:".length;function Ms(t,e,n,r,s){const i=e.layerScene.eslpk,o=function(t,e){const n=e.substring(_s);return t>=1.7?parseInt(n):n}(e.version,t),a=e[o],c=e.layerScene.baseUrl,h=[];let u=!1;const l=ws;let f,d;if(e.version<=1.6){if(!a.geometryData)return null;const t=a.geometryData.length;if(!t)return null;let n=c+`/nodes/${a.id}/`+a.geometryData[t-1].href;i&&(n+=".bin");const r={geometry:{url:n,info:e.layerScene.store.defaultGeometrySchema}};let s=a.textureData&&a.textureData[0]&&a.textureData[0].href;if(s){const t=e.layerScene.store.textureEncoding[0];let n;n="image/jpeg"===t?"jpg":"png",i&&(s+="."+n);const o={pbrMetallicRoughness:{baseColorTexture:{url:c+`/nodes/${a.id}/`+s,factor:1,format:n,mimeType:t},metallicFactor:0}};r.material=o}h.push(r)}else{f=a.mesh.geometry,d=a.mesh.material;const t=e.layerScene.geometryDefinitions[f.definition],{geometryBuffers:o}=t;u=r&&2===o.length;const l=ds.draco&&u?o[1]:o[0],m=ds.draco&&u?1:0;let p=c+`/nodes/${f.resource}/geometries/`+m;i&&(p+=".bin");const b={geometry:{url:p,info:l}};if(s&&vs&&u&&!ds.draco)throw new Error("Must import @maptalks/transcoder.draco to load i3s draco compressed geometry");const g=e.layerScene.materialDefinitions,y=e.layerScene.textureSetDefinitions;let w,v=0;if(d&&(v=g[d.definition]),g){w=function(t,e,n,r,s,i){const o=JSON.parse(JSON.stringify(t));return function t(e,n,r,s,i,o){for(const a in e)if(e[a]&&e[a].textureSetDefinitionId>=0){const t=n[e[a].textureSetDefinitionId],c="images/"+t.formats[0].format,h=Os(t.formats,i),u={url:r+`/nodes/${s}/textures/${h.name}`,factor:void 0===e[a].factor?1:e[a].factor,format:h.format,mimeType:c};if(o){let t="";switch(h.format){case"dds":t="bin.dds";break;case"jpg":case"png":t=h.format}u.url+="."+t}e[a]=u}else ct(e[a])&&t(e[a],n,r,s,i,o)}(o,e,n,r,s,i),o}(v,y,c,d.resource,n,e.layerScene.eslpk)}else w={pbrMetallicRoughness:{metallicFactor:0}};b.material=w,h.push(b)}return{dracoCompression:u,meshes:h,nodeIndex:o,center:a.obb&&a.obb.center||a.mbs&&[a.mbs[0],a.mbs[1],a.mbs[2]],transform:l}}function Os(t,e){for(let n=0;n<=t.length;n++){const r=t[n].format;if("dds"===r&&e.hasExtension("WEBGL_compressed_texture_s3tc"))return t[n];if("jpg"===r||"png"===r)return t[n];if("ktx2"===r&&ys)return t[n]}return null}const xs=new s.Coordinate(0,0),As=new s.Coordinate(0,0),Is=new Set,Ss=[];class Es extends(n.MaskRendererMixin(s.renderer.CanvasRenderer)){constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new Ke(t.getId(),1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.Qe={},this.Ze=[],this.Ue=this.Ye.bind(this)}getAnalysisMeshes(){if(!this.painter)return Ss;const t=this.painter.getPaintedMeshes();if(!t)return Ss;const e=[],{b3dmMeshes:n,pntsMeshes:r,i3dmMeshes:s}=t;return n.length&&Tt(e,n),r.length&&Tt(e,r),s.length&&Tt(e,s),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.Ze.length||super.needToRedraw())}getFrameTimestamp(){return this.We}drawOnInteracting(t,e,n){this.draw(e,n)}draw(t,e){this.We=t;const n=this.prepareCanvas();if(n&&!n.intersects(this.canvasExtent2D))return void this.completeRender();const{root:r,tiles:s}=this.layer.getTiles(),i=s.length;if(!s||!i)return void this.completeRender();this.tn(),this.nn();const{selectedTiles:o,leaves:a,requests:c}=this.rn(r,s);c.length&&this.loadTiles(c),this.sn(o,a,e),this.in(),c.length||this.completeRender()}rn(t,e){const n=this.layer.getRootTiles();let r=[];this.an();let s=0;const i=this.cn(),o={};let a=!1,c=!1;for(let t=0;t<e.length;t++){const i=e[t],h=i.node;if(o[h.id])continue;const u=n[h.kt];o[h.id]=1;let l=!1;const f=this.getCachedTile(h.id);if(this.hn(h.id)?(s++,l=c=!0,this.tilesLoading[h.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=c=!0),(!i.node.un||u.isS3M||!i.node.children||i.node.un<=500)&&(a=!0,i.selected=!0,i.data=f)):this.painter.has(h)||(l=c=!0,r.push(h)),!l)continue;if(this.ln(i))a=!0;else{this.dn(i).length&&(a=!0)}}let h=[],u={};if(a&&({selectedTiles:h,leaves:u}=this.mn(t)),r.length>1&&(r.sort(Ns),i)){const t=i-s;r=t>0?r.slice(0,t):[]}return{loading:c,requests:r,selectedTiles:h,leaves:u}}mn(t){const e=[],n={};let r;const s=[t],i=[];for(;s.length>0||i.length>0;){if(i.length>0){const t=i[i.length-1];if(t.pn===s.length){i.pop(),t===r&&(t.leave=!0,n[t.node.id]=1),e.push(t);continue}}const t=s.pop(),o=t.children;if(t.selected)if("add"===t.node.refine)n[t.node.id]=1,t.selectionDepth=i.length,e.push(t);else{if(t.selectionDepth=i.length,r=t,0===o.length){t.leave=!0,n[t.node.id]=1,e.push(t);continue}i.push(t),t.pn=s.length}for(let t=0;t<o.length;t++)s.push(o[t])}return{selectedTiles:e,leaves:n}}ln(t){if(!t.parent)return null;let e=t.parent;for(;e&&e.level>=0;){const t=e.node.id;if(this.tileCache.has(t))return e.selected=!0,e.data=this.tileCache.get(t),e;e=e.parent}return null}dn(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const n=t.Ht+1,r=[t.node];for(;r.length>0;){const s=r.pop().children;for(let i=0,o=s.length;i<o;i++){if((!s[i].content||!s[i].content.url)&&s[i].children&&s[i].children.length){r.push(s[i]);continue}const o=s[i].id;if(this.tileCache.has(o)){const n=this.layer.bn(s[i],t);n.selected=!0,n.data=this.tileCache.get(o),t.children.push(n),e.push(n)}else s[i].Ht<=n&&r.push(s[i])}}return e}sn(t,e,n){this.tileCache.markAll(!1);for(let e=0,n=t.length;e<n;e++){const n=t[e].data;n.current=!0,this.tileCache.add(t[e].node.id,n)}this.tileCache.shrink();const r={tiles:t,leaves:e};this.onDrawTileStart(r);const s=this.painter.paint(t,e,n);this.onDrawTileEnd(r),s&&this.layer.fire("canvasisdirty",{renderCount:s})}onDrawTileStart(){}onDrawTileEnd(){}loadTiles(t){for(let e=0,n=t.length;e<n;e++){const n=t[e];this.tilesLoading[n.id]={current:!0,node:n},this.loadTile(n)}}loadTile(t){let e=t.content.url;if(wt(e)){const n=vt(e);return this.gn(e,n,t),null}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const n=t.kt,r=this.yn[n];return new bs(e,n,r,this.layer,this.Ue).load().then(n=>{this.onTilesetLoad(n,t,e)})}return t&&xt(e)&&!Ts(e)&&(e=t.baseUrl+e),this.gn(e,null,t),null}gn(t,e,r){let s=this.o;s||(s=n.reshader.Util.getSupportedFormats(this.gl.gl||this.gl),this.o=s);const i=this.layer.Rt(r.kt);i.isSuperMapiServer&&(t=function(t,e){const n=t.substring(e.length).split("/"),r=[];for(let t=0;t<n.length;t++)r.push(encodeURIComponent(n[t]));return e+r.join("/")}(t,r.baseUrl));const o={url:this.layer.getTileUrl(t,r.baseUrl,this.layer.wn[r.kt]),arraybuffer:e,rootIdx:r.kt,upAxis:r.de,transform:r.matrix,supportedFormats:s};if(Ts(t)){const e=this.yn[r.kt];if(o.projection=e.projection,o.i3sInfo=Ms(t,e,this.regl,this.layer.options.enableI3SCompressedGeometry,this.layer.options.forceI3SCompressedGeometry),!o.i3sInfo)return void this.onTileError({status:404},r,t)}o.service=ot({},i),i.offset&&delete o.service.offset,o.referrer=window&&window.location.href,this.workerConn.loadTile(this.layer.getId(),o,(e,n)=>{if(e)return void this.onTileError(e,r,t);const{magic:s}=n;"b3dm"===s||"pnts"===s||"i3dm"===s||"cmpt"===s||"gltf"===s?(this.Ze.push({data:n,tile:r}),i.debugShowBoundingVolume&&this.painter.Te(r)):this.onTilesetLoad(n,r,t)})}nn(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let n=0;for(;this.Ze.length&&(n<e||!t.isInteracting());){const{data:t,tile:e}=this.Ze.shift(),{magic:r}=t;"b3dm"===r||"gltf"===r?this.painter.createB3DMMesh(t,e.id,e,(n,{mesh:r})=>{this.vn(t,e,n,r)}):"pnts"===r?this.painter.createPntsMesh(t,e.id,e,(n,{mesh:r})=>{this.vn(t,e,n,r)}):"i3dm"===r?this.painter.createI3DMMesh(t,e.id,e,(n,{mesh:r})=>{this.vn(t,e,n,r)}):"cmpt"===r&&this.painter.createCMPTMesh(t,e.id,e,(n,{mesh:r})=>{this.vn(t,e,n,r)}),n++}}vn(t,e,n,r){if(n)this.onTileError(n,e);else{const n=this.Tn(r);e.memorySize=n,this.onTileLoad(t,e)}}Tn(t){let e=0;if(Array.isArray(t))for(let n=0;n<t.length;n++)t[n]&&(e+=this.Tn(t[n]));else t&&(e+=t.getMemorySize());return e}onTileLoad(t,e){this.layer&&(delete this.tilesLoading[e.id],this.layer.onTileLoad(t,e),this._n(e),this.setToRedraw(),this.layer.fire("tileload",{node:e}))}onTilesetLoad(t,e,n){this.layer&&(this.layer.Ae=t.extensions&&t.extensions["s3m:VertexCompressionType"],t.capabilities||t.layers&&t.layers[0]&&t.layers[0].capabilities?this.Mn(t,e,n):(delete this.tilesLoading[e.id],this.layer.onTilesetLoad(t,e,n)))}onTileError(t,e,n){if(!this.layer)return;const r=n||e.content.url,s=t&&t.message||t;Is.has(s)||(console.warn("failed to load 3d tile: "+r),console.warn(t),Is.add(s)),delete this.tilesLoading[e.id],this.On(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}On(t,e){const n={loadTime:s.Util.now(),current:!0,error:e,node:t};this.tileCache.add(t.id,n)}_n(t){const e={loadTime:s.Util.now(),current:!0,node:t};this.tileCache.add(t.id,e)}abortTileLoading(t){if(!t||!this.workerConn)return;const e=t.node.content.url;this.workerConn.abortTileLoading(this.layer.getId(),e),delete this.Qe[e]}an(){if(this.tilesLoading)for(const t in this.tilesLoading)this.tilesLoading[t].current=!1}deleteTile(t){this.painter.deleteTile(t)}createContext(){const t=this.layer,e=t.options.glOptions||{alpha:!0,depth:!0,stencil:!0,preserveDrawingBuffer:!0,antialias:t.options.antialias},r=this.canvas.gl&&this.canvas.gl.wrap;r?(this.gl=this.canvas.gl.wrap(),this.regl=this.canvas.gl.regl):(this.glOptions=e,this.gl=this.xn(this.canvas,e)),this.regl=this.regl||n.createREGL({gl:this.gl,attributes:e,extensions:["OES_element_index_uint"],optionalExtensions:t.options.optionalExtensions||[]}),r&&(this.canvas.pickingFBO=this.canvas.pickingFBO||this.regl.framebuffer(this.canvas.width,this.canvas.height)),this.pickingFBO=this.canvas.pickingFBO||this.regl.framebuffer(this.canvas.width,this.canvas.height),this.painter=new hs(this.regl,t),this.layer.An(),this.layer.fire("contextcreate",{regl:this.regl})}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new $e("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let n=this.layer.options||{};n=ot({},n),delete n.offset;const r=t.options.spatialReference;n.projection=r&&r.coordType||r&&r.projection||t.getSpatialReference().getProjection().code;const s=this.layer.getId();e.addLayer(s,n,t=>{if(t)throw t;this.layer&&(this.ready=!0,this.layer.fire("workerready"))})}onRemove(){this.painter&&this.painter.remove(),this.pickingFBO&&(this.canvas.pickingFBO||this.pickingFBO.destroy(),delete this.pickingFBO),this.workerConn&&(this.workerConn.removeLayer(this.layer.getId(),t=>{if(t)throw t}),this.workerConn.remove(),delete this.workerConn),this.clear(),delete this.tileCache,super.onRemove()}clear(){this.in(!0),this.tileCache.reset(),this.tilesLoading={},super.clear()}clearCanvas(){this.regl&&this.regl.clear({color:[0,0,0,0],depth:1,stencil:0}),super.clearCanvas()}getTileOpacity(){return 1}getStencilValue(){return 0}in(t){this.In||(this.In=Date.now());const e=Date.now();if(t||!(e-this.In<this.layer.options.retireInterval)){this.In=e;for(const e in this.tilesLoading){const n=this.tilesLoading[e];!t&&n.current||this.abortTileLoading(n)}}}cn(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}xn(t,e){const n=["webgl","experimental-webgl"];let r=null;for(let s=0;s<n.length;++s){try{r=t.getContext(n[s],e)}catch(t){}if(r)break}return r}hn(t){return!!this.tilesLoading[t]}getI3DMMeshes(){return this.painter.getI3DMMeshes()}getPNTSMeshes(){return this.painter.getPNTSMeshes()}getB3DMMeshes(){return this.painter.getB3DMMeshes()}readBatchData(t,e,n){return Cn(t,e,0,n)}tn(){if(!this.Sn)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const n=[];for(const r in this.Sn){const s=this.Sn[r];if("pending"===s.status)continue;s.status="pending";const i=s.rootIdx,o=At(this.layer.Rt(i).fetchOptions);if(n.push(ye.getJSON(r,o).then(t=>{delete this.Sn[r];const e=this.yn[i];if(e){t.nodes?ms(e,t.nodes):(e[t.id]=t,ms(e,t.children));for(let t=0;t<s.length;t++)s[t]();this.setToRedraw()}else this.setToRedraw()})),e++,e>=t)break}n.length&&Promise.all(n)}Ye(t,e,n){this.Sn||(this.Sn={}),this.Sn[e]=this.Sn[e]||[],this.Sn[e].rootIdx=t,this.Sn[e].push(n),this.setToRedraw()}Mn(t,e,n){this.yn||(this.yn=[]);const r=e.kt;this.yn[r]||(this.yn[r]={});const s=this.yn[r],i=this.layer.Rt(r);t.layers&&(t=t.layers[0],"/"!==n[n.length-1]&&(n+="/"),n+="layers/0"),s.version=+(i.i3sVersion||t.store.version),!t.spatialReference||t.spatialReference.wkid&&4326===t.spatialReference.wkid||console.warn("i3s has a spatialReference other than 4326.",t.spatialReference),s.projection=t.spatialReference,function(t,e,n,r,s,i,o){if(!i.layerScene){i.layerScene=e,i.nodesPerPage=e.nodePages&&e.nodePages.nodesPerPage||64,i.lodSelectionMetricType=e.nodePages&&e.nodePages.lodSelectionMetricType;let t=s;i.layerScene.eslpk=t.indexOf("3dSceneLayer.json")>=0;if(t.endsWith(".json")){const e=s.lastIndexOf("/");t=e<0?"./":s.substring(0,e)}i.layerScene.baseUrl=function(t){return t.split("?")[0]}(t)}return new bs(s,n,i,t,o).load()}(this.layer,t,r,0,n,s,this.Ue).then(t=>{this.onTilesetLoad(t,e,n)})}pick(t,e,n){if(!this.painter)return[];const r=this.pickingFBO,{width:s,height:i}=this.canvas;return!this.pickingFBO||r.width===s&&r.height===i||r.resize(s,i),this.painter.pick(t,e,n&&n.tolerance)}highlight(t){if(this.Ft||(this.Ft=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const n=t[e].service||0;let r=this.Ft[n];r||(r=this.Ft[n]=new Map),r.set(t[e].id,t[e])}else{const e=t.service||0;let n=this.Ft[e];n||(n=this.Ft[e]=new Map),n.set(t.id,t)}this.painter.highlight(this.Ft)}cancelHighlight(t,e){if(!this.Ft)return;const n=this.Ft[t];if(n){if(Array.isArray(e))for(let t=0;t<e.length;t++)n.delete(e[t]);else n.delete(e);n.size||(this.Ft[t]=null),this.painter.highlight(this.Ft)}}cancelAllHighlight(){delete this.Ft,this.painter.cancelAllHighlight()}showOnly(t){if(this.jt||(this.jt=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const n=t[e].service||0;let r=this.jt[n];r||(r=this.jt[n]=new Map),r.set(t[e].id,t[e])}else{const e=t.service||0;let n=this.jt[e];n||(n=this.jt[e]=new Map),n.set(t.id,t)}this.painter.showOnly(this.jt)}cancelShowOnly(){delete this.jt,this.painter.cancelShowOnly()}Le(){return this.painter?this.painter.Le():[]}Ke(t,e){const n=this.getMap();if("identity"===n.getProjection().code.toLowerCase()){const n=this.En();return xs.x=e[0],xs.y=e[1],n.unproject(xs,As),t[0]=As.x,t[1]=As.y,t}return xs.x=e[0],xs.y=e[1],n.getProjection().unproject(xs,As),t[0]=As.x,t[1]=As.y,t}Nn(t,e){const n=this.En();return xs.x=e[0],xs.y=e[1],n.project(xs,As),t[0]=As.x,t[1]=As.y,t}Cn(t,e){const n=this.En();return xs.x=e[0],xs.y=e[1],n.unproject(xs,As),t[0]=As.x,t[1]=As.y,t}En(){const t=this.getMap().options.spatialReference.coordType;if(!t)throw new Error("Missing coordType in map spatialReference.");return this.Pn||(this.Pn=s.SpatialReference.getProjectionInstance(t)),this.Pn}}function Ns(t,e){return t.ne-e.ne}function Cs(t,e,n){return t[0]=e[n],t[1]=e[n+3],t[2]=e[n+6],t}function Ps(t,e,n){return Math.sqrt(function(t,e,n){const r=Dt(Rs,n,t),s=Cs(ks,e,0),i=Cs(Ls,e,1),o=Cs(Bs,e,2),a=Xt(s),c=Xt(i),h=Xt(o);Ht(s,s),Ht(i,i),Ht(o,o);const u=Us;u[0]=Gt(r,s),u[1]=Gt(r,i),u[2]=Gt(r,o);let l,f=0;u[0]<-a?(l=u[0]+a,f+=l*l):u[0]>a&&(l=u[0]-a,f+=l*l);u[1]<-c?(l=u[1]+c,f+=l*l):u[1]>c&&(l=u[1]-c,f+=l*l);u[2]<-h?(l=u[2]+h,f+=l*l):u[2]>h&&(l=u[2]-h,f+=l*l);return f}(t,e,n))}const Rs=[],ks=[],Ls=[],Bs=[],Us=[];const Fs=2*Math.PI;class Ds{constructor(t,e,n,r){this.west=t,this.south=e,this.east=n,this.north=r}static contains(t,e){let n=e[0];const r=e[1],s=t.west;let i=t.east;return i<s&&(i+=Fs,n<0&&(n+=Fs)),(n>s||xn(n,s,1e-14))&&(n<i||xn(n,i,1e-14))&&r>=t.south&&r<=t.north}static southwest(t,e){return e[0]=t.west,e[1]=t.south,e[2]=0,e}static northeast(t,e){return e[0]=t.east,e[1]=t.north,e[2]=0,e}static southeast(t,e){return e[0]=t.east,e[1]=t.south,e[2]=0,e}static northwest(t,e){return e[0]=t.west,e[1]=t.north,e[2]=0,e}}const js=[0,0,1];function zs(t,e){return ln(e,t[0],t[1],t[2])}class Hs{constructor(t,e){this.normal=n.vec3.copy([],t),this.distance=e}static fromPointNormal(t,e,r){const s=-n.vec3.dot(e,t);return n.vec3.copy(r.normal,e),r.distance=s,r}}const Gs=[],qs=[],Vs=[],$s=[],Xs=[],Js=[],Ks=[],Qs=[],Zs=[],Ys=[],Ws=new Hs([1,0,0],0),ti=[];class ei{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new Ds(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){let r=0;if(!Ds.contains(this.rectangle,e)){const e=this.southwestCornerCartesian,s=this.northeastCornerCartesian,i=this.westNormal,o=this.southNormal,a=this.eastNormal,c=this.northNormal,h=n.vec3.subtract(ti,t,e),u=n.vec3.dot(h,i),l=n.vec3.dot(h,o),f=n.vec3.subtract(ti,t,s),d=n.vec3.dot(f,a),m=n.vec3.dot(f,c);u>0?r+=u*u:d>0&&(r+=d*d),l>0?r+=l*l:m>0&&(r+=m*m)}const s=e[2],i=this.minimumHeight,o=this.maximumHeight;if(s>o){const t=s-o;r+=t*t}else if(s<i){const t=i-s;r+=t*t}return Math.sqrt(r)}computeBox(t){const e=this;zs(Ds.southwest(t,qs),e.southwestCornerCartesian),zs(Ds.northeast(t,qs),e.northeastCornerCartesian),Gs[0]=t.west,Gs[1]=.5*(t.south+t.north),Gs[2]=0;const r=zs(Gs,Vs),s=n.vec3.cross(Xs,r,js);n.vec3.normalize(e.westNormal,s),Gs[0]=t.east;const i=zs(Gs,Qs),o=n.vec3.cross(Xs,js,i);n.vec3.normalize(e.eastNormal,o);const a=n.vec3.subtract(Xs,r,i),c=n.vec3.normalize($s,a),h=t.south;let u;if(h>0){Gs[0]=.5*(t.west+t.east),Gs[1]=h;const r=zs(Gs,Zs);n.vec3.copy(Ys,c);const s=Hs.fromPointNormal(e.southwestCornerCartesian,e.westNormal,Ws);ni(Zs,Ys,s,e.southwestCornerCartesian),u=_n(r,Js)}else u=Mn(Ds.southeast(t,qs),Js);const l=n.vec3.cross(Ks,u,a);n.vec3.normalize(e.southNormal,l);const f=t.north;let d;if(f<0){Gs[0]=.5*(t.west+t.east),Gs[1]=f;const r=zs(Gs,Zs);n.vec3.scale(Ys,c,-1);const s=Hs.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,Ws);ni(Zs,Ys,s,e.northeastCornerCartesian),d=_n(r,Js)}else d=Mn(Ds.northwest(t,qs),Js);const m=n.vec3.cross(Ks,a,d);n.vec3.normalize(e.northNormal,m)}}function ni(t,e,r,s){const i=t,o=e,a=r.normal,c=n.vec3.dot(a,o);if(Math.abs(c)<1e-15)return;const h=(-r.distance-n.vec3.dot(a,i))/c;return h<0?void 0:(s=n.vec3.scale(s,o,h),n.vec3.add(s,i,s))}const ri={"maxGPUMemory":s.Browser.mobile?32:1024,"retireInterval":2e3,"loadingLimitOnInteracting":5,"loadingLimit":5,"renderer":"gl","forceRenderOnZooming":!0,"forceRenderOnRotating":!0,"forceRenderOnMoving":!0,"debug":!1,"meshLimitPerFrame":1,"i3sNodepageLimitPerFrame":1,"enableI3SCompressedGeometry":!0,"forceI3SCompressedGeometry":!0,"picking":!0,"pickingPoint":!0,"geometryEvents":!1,"antialias":!1,"optionalExtensions":["ANGLE_instanced_arrays","OES_element_index_uint","OES_standard_derivatives","OES_vertex_array_object","OES_texture_half_float","OES_texture_half_float_linear","OES_texture_float","OES_texture_float_linear","WEBGL_depth_texture","EXT_shader_texture_lod","WEBGL_compressed_texture_astc","WEBGL_compressed_texture_etc","WEBGL_compressed_texture_etc1","WEBGL_compressed_texture_pvrtc","WEBGL_compressed_texture_s3tc","WEBGL_compressed_texture_s3tc_srgb"],"offset":[0,0]},si=new s.Extent(0,0,0,0),ii=[],oi=[],ai=[],ci=[],hi=new s.Point(0,0),ui=[],li=new s.Coordinate(0,0),fi=n.mat4.identity([]),di=[0,0],mi=[1,1,1,1,-1,1,-1,-1,1,-1,1,1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1];class pi extends(n.MaskLayerMixin(s.Layer)){constructor(t,e){super(t,e),this.Rn(),this.Qe={},this._e=[]}Rn(){const t=this.options.services.map(t=>t.url);this.kn=this.kn||{},this.wn=this.wn||[];for(let e=0;e<t.length;e++){const n=t[e];let r=this.kn[n];void 0===r&&(r=this.kn[n]=this.wn.length),this.wn[r]=yi(n,r,this.options.services[e])}this.fire("rootready",{roots:this.wn.slice(0)})}showService(t){return this.updateService(t,{visible:1}),this}hideService(t){return this.updateService(t,{visible:0}),this}setToRedraw(){const t=this.getRenderer();t&&t.setToRedraw()}addService(t){this.options.services=this.options.services||[],this.options.services.push(t),this.Rn();const e=this.getRenderer();return e&&e.setToRedraw(),this}updateService(t,e){if(!e)return this;const n=this.options.services;if(n&&n[t]&&ot(n[t],e),!it(e.visible)){const r=n[t].url,s=this.kn[r];this.wn&&this.wn[s]&&(this.wn[s].visible=e.visible)}const r=this.getRenderer();return r&&r.setToRedraw(),this}removeService(t){const e=this.options.services;if(e&&e[t]){const n=e[t].url,r=this.kn[n];this.wn[r]&&(this.wn[r]=null),delete this.kn[n],e.splice(t,1)}const n=this.getRenderer();return n&&n.setToRedraw(),this}getTileUrl(t,e,n){const r=n&&n.service&&n.service.subdomains;if(r&&n.domainKey){const e=r.length;if(e){const s=[...t].reduce((t,e)=>t+e.charCodeAt(),0)%e;return t.replace(n.domainKey,r[s])}}return t}getExtent(t){if(!t&&0!==t){const t=new s.Extent;for(let e=0;e<this.wn.length;e++)if(this.wn[e].boundingVolume){const n=this.boundingVolumeToExtent(this.wn[e]);t._combine(n)}return t}return this.wn[t]&&this.wn[t].boundingVolume?this.boundingVolumeToExtent(this.wn[t]):null}boundingVolumeToExtent(t){const e=t.boundingVolume.Ln?fi:t.matrix,r=this.getMap(),i="identity"===r.getProjection().code.toLowerCase(),o=this.getRenderer();if(t.boundingVolume.region){const e=t.boundingVolume.region;return new s.Extent(lt(e[0]),lt(e[1]),lt(e[2]),lt(e[3]))}if(t.boundingVolume.sphere){const a=t.boundingVolume.sphere,c=gn([],n.vec3.transformMat4([],a,e));i&&o.Nn(c,c);const h=a[3],u=r.locate(c,-h,h),l=r.locate(c,h,-h);return new s.Extent(u,l)}if(t.boundingVolume.box){const a=t.boundingVolume.box,c=n.vec3.transformMat4([],a,e),h=new s.Coordinate(gn([],c));i&&o.Nn(h,h);const u=a.slice(3);n.mat3.multiply(u,n.mat3.fromMat4([],t.matrix),u);const l=n.vec3.length(u.slice(0,3)),f=n.vec3.length(u.slice(3,6)),d=n.vec3.length(u.slice(6,9)),m=Math.max(l,f,d),p=r.locate(h,-m,m),b=r.locate(h,m,-m);return new s.Extent(p,b)}return null}getRootTiles(){return this.wn}getTiles(){const t=this.getRenderer();if(!t.ready)return this.Bn(),{tiles:ci};const e=this.getMap(),r=e.cameraPosition,s=e.pointAtResToDistance(r[2],0,e.getGLRes()),i=this.Un(r);this.Fn=this.Fn||[],n.vec3.set(this.Fn,ut(i.x),ut(i.y),s),this.Dn=ln(this.Dn||[],this.Fn[0],this.Fn[1],this.Fn[2]),this.jn=2*Math.tan(.5*ut(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const h=[];for(let e=0;e<this.wn.length;e++){const n=this.wn[e];if(!n||!n.visible)continue;let r=1/0;const s=[n],i=this.zn(e);for(;s.length>0;){const e=s.pop();for(e.id||this.Hn(e);c.level>=e.Ht;)c=c.parent;const n=this.Gn(e,i,o);if(n<1){let t=c;for(;t&&!t.content;)t=t.parent;0===n&&t&&t.content&&this.qn(h,t);if(!1===this.options.services[e.kt].alwaysShow)continue;if(!(0===n&&e.Ht<=r))continue;e.content&&(r=e.Ht)}e.ne<1/0&&this.Vn(e);const a=this.bn(e,c);c.children.push(a);const u=e.children,l=u&&u.length,f=a.content;if(!l&&f&&this.qn(h,a),l){f&&"add"===e.refine&&this.qn(h,a),c=a;const n=u[0].parent;let r=!1;for(let i=0,o=u.length;i<o;i++){if(n){const e=t.getCachedTile(u[i].id);if(e&&e.error&&404!==e.error.status)continue;r=!0}else{r=!0,u[i].parent=e,u[i].de=e.de,u[i].baseUrl=e.baseUrl;const t=u[i].content&&(u[i].content.url||u[i].content.uri);t&&(wt(t)||t.indexOf("i3s:")>=0?u[i].baseUrl=e.baseUrl:xt(t)?u[i].content.url=e.baseUrl+t:u[i].baseUrl=t.substring(0,t.lastIndexOf("/")+1))}s.push(u[i])}!r&&f&&this.qn(h,a)}}}return{root:a,tiles:h}}qn(t,e){const{viewerRequestVolume:n}=e.node;n&&!function(t,e,n){if(n.region){const e=n.region;if(t[0]>=e[0]&&t[0]<=e[2]&&t[1]>=e[1]&&t[1]<=e[3])return!0}else{if(n.sphere)return bi(n,e);if(n.box)return 0===gi(n,e)}return!1}(this.Fn,this.Dn,n)||t.push(e)}bn(t,e){return{id:t.id,node:t,children:[],level:t.Ht,parent:e,content:t.content&&t.content.url}}Hn(t){t.id=s.Util.GUID(),t.matrix=t.transform||n.mat4.identity([]),t.$n=this.Xn(t),t.parent&&(function(t){return t.content&&t.content.uri&&t.content.uri.indexOf("i3s:")>=0}(t)||(t.matrix=n.mat4.multiply(t.matrix,t.parent.matrix,t.matrix)),t.kt=t.parent.kt,void 0===t.Ht&&(t.Ht=t.parent.Ht+1),t.maxExtent=t.parent.maxExtent),t.refine=t.refine&&t.refine.toLowerCase()||"replace",t.content&&!t.content.url&&t.content.uri&&(t.content.url=t.content.uri)}Rt(t){return this.wn[t].service}Jn(t){const e=t.boundingVolume;if(!e||e.Ln&&!this.Kn(t))return;const r=this.Rt(t.kt),s=r.heightOffset||0,i=this.options.offset,o=at(i)||i[0]||i[1],a=r.coordOffset||di;if(!Array.isArray(a))throw new Error("service.coordOffset must be an array");if(!e.Ln&&(!t.boundingVolume||!s&&n.mat4.exactEquals(t.matrix,fi)&&!o&&a===di))return;e.box&&e.region&&delete e.region;const{region:c,box:h,sphere:u}=e;if(e.coordOffset=[a[0],a[1]],e.heightOffset=s,c){e.originalVolume||(e.originalVolume=c.slice(0));const t=e.originalVolume,n=this.Qn([lt(t[0]),lt(t[1])]);c[0]=ut(n.x+a[0]),c[1]=ut(n.y+a[1]);const r=this.Qn([lt(t[2]),lt(t[3])]);c[2]=ut(r.x+a[0]),c[3]=ut(r.y+a[1]),c[4]=t[4]+s+(a[2]||0),c[5]=t[5]+s+(a[2]||0)}else if(h||u){e.originalVolume||(e.originalVolume=(h||u).slice(0));const r=h||u,i=e.originalVolume,o=n.vec3.transformMat4(ii,i,t.matrix),c=gn(oi,o),l=this.Qn([c[0]+a[0],c[1]+a[1]]);c[0]=l.x,c[1]=l.y,c[2]+=s+(a[2]||0),ln(r,ut(c[0]),ut(c[1]),c[2])}e.Ln=!0}Kn(t){const e=t.boundingVolume,n=this.Rt(t.kt),r=n.heightOffset||0,s=n.coordOffset||di;return e.coordOffset[0]!==s[0]||e.coordOffset[1]!==s[1]||e.heightOffset!==r}Xn(t){return void 0===t.geometricError||!t.boundingVolume}Vn(t){let e=t.parent;for(;e&&e.$n&&!(e.ne<=t.ne);)e.ne=t.ne,e=t.parent}onTileLoad(t,e){if(t.children&&(!e.children||!e.children.length)){e.children=t.children;const n=e.content.url;e.baseUrl=n.substring(0,n.lastIndexOf("/")+1);const r=this.getRenderer();r&&r.setToRedraw()}}onTilesetLoad(t,e,r){if(!t)return void console.warn("invalid tileset at : "+r);const s=this.Rt(e.kt),i=(t.asset&&t.asset.gltfUpAxis||e&&e.de||s.upAxis||"Y").toUpperCase();t.root.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const o=r.indexOf("realspace/")>-1;0===e.Ht&&(t.asset&&t.asset.s3mType&&o||s.isSuperMapiServer)&&(t.root.baseUrl+="data/path/");const a=t.asset.i3s,c=!!t.asset.s3mType;if(t.root.de=i,e){const r=e.kt,s=this.wn[r];c&&!s.isS3M&&(s.isS3M=c);const i=e.boundingVolume;ot(e,t.root),e.refine=e.refine&&e.refine.toLowerCase()||"replace",i&&(e.boundingVolume=i);const o=t.root.transform;o&&(e.parent?a||(e.matrix=n.mat4.multiply([],e.parent.matrix,o)):e.matrix=o),e.Zn=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.$n=this.Xn(e);const h=e.content&&(e.content.url||e.content.uri);h&&e.content.uri&&(e.content.url=e.content.uri,delete e.content.uri),!a&&h&&!wt(h)&&xt(h)&&(e.content.url=e.baseUrl+h),t.root&&!e.parent&&this.Yn(e)}this.Bn(),this.fire("loadtileset",{tileset:t,index:e&&e.kt,url:r})}Gn(t,e,n){if(t.ne=1/0,0===t.Ht||t.$n)return this.Yn(t),1;if(this.Jn(t),!this.Wn(t,e,n))return-1;if(0===t.geometricError)return 1;let r=this.Rt(t.kt).maximumScreenSpaceError;null==r&&(r=16);let s=this.tr(t);return 0===s&&t.parent&&(s=.5*(t.parent.un||0)),s>=r?1:0}Re(t,e){e||(e=new s.Point(0,0));const n=this.getMap();return n.getGLZoom?n.coordToPoint(t,n.getGLZoom(),e):n.coordToPointAtRes(t,n.getGLRes(),e)}Wn(t,e,n){const r=t.id;let i=this._e[r]&&this._e[r].obbox;const{boundingVolume:o}=t,c=o.region,h=o.box,d=o.sphere;if(!i)if(c)this._e[r]=this.er(t),i=this._e[r].bbox,i.center=this._e[r].coordCenter;else if(h)this._e[r]=this.nr(t),i=this._e[r].obbox,i.center=this._e[r].coordCenter;else if(d){i=this._e[r]=this.rr(t);const e=gn(ii,d),n=new s.Coordinate(e);i.center=n}if(e){if(c)si.xmin=i[0][0],si.ymin=i[0][1],si.xmax=i[1][0],si.ymax=i[1][1];else if(d){const t=i[2];si.xmin=i[0][0]-t,si.ymin=i[0][1]-t,si.xmax=i[0][0]+t,si.ymax=i[0][1]+t}else if(h){const t=i[1],e=i[2];si.xmin=i[0][0]-t,si.ymin=i[0][1]-e,si.xmax=i[0][0]+t,si.ymax=i[0][1]+e}if(!e.intersects(si))return!1}return c?u(n,i):d?function(t,e,n){f(t);for(var r=e[0],s=-e[1],i=0;i<6;i++){if(!n||"0"!==n.charAt(i))if(m(a[i],r)<s)return!1}return!0}(n,i):!!h&&function(t,e,n){f(t);for(var r=0;r<6;r++){if(!n||"0"!==n.charAt(r))if(!l(a[r],e))return!1}return!0}(n,i)}er(t){const e=this.getMap(),n=e.getGLRes(),r=t.boundingVolume.region;let{ws:i,en:o}=function(t){const e=t[0],n=t[1],r=t[2],s=t[3],i=t[4],o=t[5],a=ln([],e,n,i),c=ln([],r,s,o),h=gn(a,a),u=gn(c,c);return{ws:h,en:u}}(r);i=new s.Coordinate(i),o=new s.Coordinate(o);const a=e.coordToPointAtRes(i,n);a.z=e.altitudeToPoint(i.z,n);const c=e.coordToPointAtRes(o,n);c.z=e.altitudeToPoint(o.z,n);const h=[c.x,a.y,c.z,c.x,c.y,c.z,a.x,c.y,c.z,a.x,a.y,c.z,c.x,a.y,a.z,c.x,c.y,a.z,a.x,c.y,a.z,a.x,a.y,a.z],u=[(h[0]+h[18])/2,(h[1]+h[19])/2,(h[2]+h[20])/2],l=e.pointAtResToCoord(new s.Point(u),n);l.z=(i.z+o.z)/2;const f=this.Rt(t.kt).Me,d=[h.slice(21,24),h.slice(3,6)];if(f)for(let t=0;t<h.length;t+=3)h[t]-=f[0],h[t+1]-=f[1],h[t+2]-=f[2];return{bbox:d,boxPosition:h,pointCenter:u,coordCenter:l}}nr(t){const e=this.getRenderer(),r=this.getMap(),i="identity"===r.getProjection().code.toLowerCase(),o=r.getGLRes(),a=t.boundingVolume.box,c=a.slice(0,3),h=wi(this.sr(a,t.matrix),c),u=this.ir(t),l=[],f=this.Rt(t.kt).Me;hi.set(f[0],f[1]);const d=r.pointAtResToCoord(hi,o);for(let t=0;t<mi.length;t+=3){const a=mi.slice(t,t+3);n.vec3.transformMat4(a,a,h),gn(a,a),i&&e.Nn(a,a);const c=new s.Coordinate(a);let u=r.coordToPointAtRes(c,o);u=[u.x,u.y,r.altitudeToPoint(c.z,o)],l[t]=u[0]-f[0],l[t+1]=u[1]-f[1],l[t+2]=u[2]-f[2]}return{obbox:this.or(l,u),boxPosition:l,boxCenter:u,coordCenter:d}}rr(t){const e=this.getMap(),n=this.getRenderer(),r="identity"===e.getProjection().code.toLowerCase(),i=t.boundingVolume.sphere,o=i;let a=ii;0===o[0]&&0===o[1]&&0===o[2]?a=[0,0,-6378137]:gn(a,o),r&&n.Nn(a,a);const c=new s.Coordinate(a),h=this.Re(c,hi).toArray();h[2]=e.altitudeToPoint(c.z,e.getGLRes());const u=this.ar(c);return[h,i[3]*u[2]]}or(t,e){const n=[(t[3]+t[12])/2,(t[4]+t[13])/2,(t[5]+t[14])/2],r=[(t[3]+t[18])/2,(t[4]+t[19])/2,(t[5]+t[20])/2],s=[(t[3]+t[9])/2,(t[4]+t[10])/2,(t[5]+t[11])/2],i=e.slice(0);return i[3]=n[0]-e[0],i[4]=n[1]-e[1],i[5]=n[2]-e[2],i[6]=r[0]-e[0],i[7]=r[1]-e[1],i[8]=r[2]-e[2],i[9]=s[0]-e[0],i[10]=s[1]-e[1],i[11]=s[2]-e[2],i}ir(t){const e=this.getMap(),r=this.getRenderer(),i="identity"===e.getProjection().code.toLowerCase(),o=e.getGLRes(),a=t.boundingVolume.box,c=a.slice(0,3),h=wi(this.sr(a,t.matrix),c),u=[0,0,0];n.vec3.transformMat4(u,u,h),gn(u,u),i&&r.Nn(u,u);const l=new s.Coordinate(u),f=e.coordToPointAtRes(l,o);return[f.x,f.y,e.altitudeToPoint(l.z,o)]}Yn(t){if(!t.boundingVolume)return;const e=t.boundingVolume.box,n=t.boundingVolume.region,r=t.boundingVolume.sphere,s=this.Rt(t.kt);let i=null;if(e){i=this.cr(t).pointCenter}else if(n){i=this.hr(t).pointCenter}else r&&(i=this.rr(t)[0]);const o=s.heightOffset||0,a=s.coordOffset||[0,0];s.ur=[a[0]||0,a[1]||0],s.te=o,s.Me=i}hr(t){if(!t.boundingVolume)return null;this.Jn(t);return this.er(t)}cr(t){if(!t.boundingVolume)return null;this.Jn(t);const e=this.getMap(),r="identity"===e.getProjection().code.toLowerCase(),i=this.getRenderer(),o=e.getGLRes(),a=t.boundingVolume.box,c=a.slice(0,3),h=wi(this.sr(a,t.matrix),c),u=[0,0,0];n.vec3.transformMat4(u,u,h),gn(u,u),r&&i.Nn(u,u);const l=new s.Coordinate(u);let f=e.coordToPointAtRes(l,o);return f.z=e.altitudeToPoint(l.z,o),f=[f.x,f.y,f.z],{pointCenter:f,coordCenter:l}}sr(t,e){let n=t.slice(3,12);return n=function(t,e,n){const r=t[0]*e[0]+t[3]*e[1]+t[6]*e[2],s=t[1]*e[0]+t[4]*e[1]+t[7]*e[2],i=t[2]*e[0]+t[5]*e[1]+t[8]*e[2],o=t[0]*e[3]+t[3]*e[4]+t[6]*e[5],a=t[1]*e[3]+t[4]*e[4]+t[7]*e[5],c=t[2]*e[3]+t[5]*e[4]+t[8]*e[5],h=t[0]*e[6]+t[3]*e[7]+t[6]*e[8],u=t[1]*e[6]+t[4]*e[7]+t[7]*e[8],l=t[2]*e[6]+t[5]*e[7]+t[8]*e[8];return n[0]=r,n[1]=s,n[2]=i,n[3]=o,n[4]=a,n[5]=c,n[6]=h,n[7]=u,n[8]=l,n}(this.lr(e,[]),n,n),n}lr(t,e){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[4],e[4]=t[5],e[5]=t[6],e[6]=t[8],e[7]=t[9],e[8]=t[10],e}ar(t){const e=this.getMap(),r=e.distanceToPointAtRes(100,100,e.getGLRes(),t);let s;return s=e.altitudeToPoint?e.altitudeToPoint(100,e.getGLRes())/100:r.y/100,n.vec3.set(ai,r.x/100*1.01,r.y/100*1.01,s),ai}Qn(t){Array.isArray(t)&&(t=new s.Coordinate(t));let e=this.options.offset;if(at(e)&&(e=e.call(this,Array.isArray(t)?new s.Coordinate(t):t)),e[0]||e[1]){const n=this.getMap(),r=n.getGLRes(),s=n.coordToPointAtRes(t,r);return s._sub(e),n.pointAtResToCoord(s,r)}return t}zn(t){const e=this.Rt(t).maxExtent;if(!e)return null;const n=this.wn[t];return n.maxExtent||(n.maxExtent=new s.Extent(e).convertTo(t=>this.Re(t))),n.maxExtent}tr(t){const e=this.jn,n=t.geometricError;if(0===n)return t.un=0,0;const r=this.getMap();let s;t.boundingVolume.region?s=function(t,e,n){t.dr||(t.dr=new ei(t.boundingVolume.region));return t.dr.distanceToCamera(e,n)}(t,this.Dn,this.Fn):t.boundingVolume.sphere?s=bi(t.boundingVolume,this.Dn):t.boundingVolume.box&&(s=gi(t.boundingVolume,this.Dn));const i=Math.max(Math.abs(s),1e-7),o=n*r.height/(i*e);return t.ne=s,t.un=o,o}Bn(){const t=this.getRenderer();t&&t.setToRedraw()}Oe(t){return this._e[t]}identify(t,e={}){const n=this.getMap(),r=this.getRenderer();if(!n||!r)return[];const i=n.coordToContainerPoint(new s.Coordinate(t));return this.identifyAtPoint(i,e)}identifyAtPoint(t,e={}){const n=[];if(!e.excludeMasks){const r=this.identifyMask(t,e);r&&r.length&&Tt(n,r)}const r=this.getMap(),s=this.getRenderer();if(!r||!s)return[];const i=r.getDevicePixelRatio();return Tt(n,s.pick(t.x*i,t.y*i,e)),n}getCurrentBatchIDs(){const t=this.getMap(),e=this.getRenderer();return t&&e?e.Le():[]}highlight(t){const e=this.getRenderer();return e?(e.highlight(t),this):(this.Ft||(this.Ft=[]),this.Ft.push(t),this)}An(){if(this.Ft){for(let t=0;t<this.Ft.length;t++)this.highlight(this.Ft[t]);delete this.Ft}}cancelHighlight(t,e){const n=this.getRenderer();return n?(n.cancelHighlight(t,e),this):this}cancelAllHighlight(){const t=this.getRenderer();return t?(t.cancelAllHighlight(),this):this}showOnly(t){const e=this.getRenderer();return e?(e.showOnly(t),this):(this.jt||(this.jt=[]),this.jt.push(t),this)}mr(){if(this.jt){for(let t=0;t<this.jt.length;t++)this.showOnly(this.jt[t]);delete this.jt}}cancelShowOnly(t){const e=this.getRenderer();return e?(e.cancelShowOnly(t),this):this}setServiceOpacity(t,e){const n=this.options.services[t];n&&(n.opacity=e);const r=this.getRenderer();return r?(r.setToRedraw(),this):this}setServiceDebugBoundingVolume(t,e){const n=this.options.services[t];n&&(n.debugShowBoundingVolume=e);const r=this.getRenderer();return r?(r.setToRedraw(),this):this}Un(t){const e=this.getMap(),n=e.getGLRes();li.set(t[0],t[1]);const r=e.pointAtResToCoord(li,n);return"identity"===e.getProjection().code.toLowerCase()?(oi[0]=r.x,oi[1]=r.y,this.getRenderer().Cn(ii,oi),r.set(ii[0],ii[1]),r):r}}function bi(t,e){const r=t.sphere,s=n.vec3.dist(r,e),i=t.sphere[3];return s<i?0:s-i}function gi(t,e){const r=t.box;return Ps(n.vec3.set(ii,r[0],r[1],r[2]),n.mat3.set(ui,r[3],r[4],r[5],r[6],r[7],r[8],r[9],r[10],r[11]),e)}function yi(t,e,r){const s=(t=ft(t)).indexOf("{s}")>=0?"{s}":t.indexOf("%7Bs%7D")>=0?"%7Bs%7D":null;return{service:r,visible:it(r.visible)?1:r.visible,baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:n.mat4.identity([]),kt:e,Ht:0,domainKey:s}}function wi(t,e){return new vi(t[0],t[3],t[6],e[0],t[1],t[4],t[7],e[1],t[2],t[5],t[8],e[2],0,0,0,1)}function vi(t,e,n,r,s,i,o,a,c,h,u,l,f,d,m,p){this[0]=t||0,this[1]=s||0,this[2]=c||0,this[3]=f||0,this[4]=e||0,this[5]=i||0,this[6]=h||0,this[7]=d||0,this[8]=n||0,this[9]=o||0,this[10]=u||0,this[11]=m||0,this[12]=r||0,this[13]=a||0,this[14]=l||0,this[15]=p||0}pi.mergeOptions(ri),pi.registerRenderer("gl",Es),pi.registerJSONType("Geo3DTilesLayer");let Ti=null;function _i(){return Ti||(Ti={"image/crn":ds.crn&&ds.crn(),"image/ktx2":ds.ktx2&&ds.ktx2(),"image/cttf":ds.ktx2&&ds.ktx2(),"draco":ds.draco&&ds.draco()}),Ti}class Mi{constructor(t,e,n){this.i=t,this.pr=e||Ue,this.o=n,this.br=_i()}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.gr(t,e,n,r,s)):ye.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.gr(t,s,n,r)})}gr(t,e,n,r,s){const i=s&&s.maxTextureSize,o=this.yr(e,n,r,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.pr(a,o.glb,{transferable:!0,requestImage:this.i,decoders:this.br,supportedFormats:this.o,maxTextureSize:i});return c.load({skipAttributeTransform:!1}).then(e=>{e.url=`${t}-${n}-${r}`;const s=c.transferables;for(let t=0;t<o.transferables.length;t++)s.indexOf(o.transferables[t])<0&&s.push(o.transferables[t]);return{magic:"b3dm",count:o.count,transferables:s,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,gltf:e}})}yr(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported b3dm version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in b3dm header is inconsistent with b3dm's byte length, url: "+r;return console.warn(t),{error:t}}let o,a=s.getUint32(12,!0),c=s.getUint32(16,!0),h=s.getUint32(20,!0),u=s.getUint32(24,!0),l=28+e;h>=570425344?(l-=8,o=a,h=c,u=0,a=0,c=0):u>=570425344&&(l-=4,o=h,h=a,u=c,a=0,c=0);const f=[t];let d,m,p;if(a>0?(d=Sn(t,l,a),l+=a,o=d.BATCH_LENGTH):d={"BATCH_LENGTH":o},c>0&&(l+=c),h>0&&(m=En(t,l,h),l+=h,u>0)){const e=Nn(0,l,u);p=t.slice(e.offset,e.offset+e.byteLength),l+=u,f.push(p)}const b=d.BATCH_LENGTH,g={};if(d&&d.BATCH_ID){g.BATCH_ID=Pn(d.BATCH_ID,t,(void 0).offset,b);const e=g.BATCH_ID.array&&g.BATCH_ID.array.buffer;e&&f.indexOf(e)<0&&f.push(e)}return{count:o,transferables:f,featureTable:d,batchTable:m,batchTableBin:p,b3dm:g,glb:{buffer:t,byteOffset:l,byteLength:s.byteLength+s.byteOffset-l}}}wr(){return null}}class Oi{constructor(t,e,n,r){this.i=t,this.pr=e||Ue,this.o=n,this.br=_i(),this.vr=r}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.gr(t,e,n,r,s)):ye.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.gr(t,s,n,r)})}gr(t,e,n,r,s){return this.Tr(t,e,n,r,s).then(({gltf:s,transferables:i})=>{const o=this._r(e,n,r,t);if(o.error)return Promise.resolve(o);for(let t=0;t<i.length;t++)-1===o.transferables.indexOf(i[t])&&o.transferables.push(i[t]);return delete s.transferables,Promise.resolve({magic:"i3dm",count:o.count,transferables:o.transferables,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,i3dm:o.i3dm,gltf:s})})}Tr(t,e,n,r,s){const i=s&&s.maxTextureSize,o={transferable:!0,requestImage:this.i,decoders:this.br,supportedFormats:this.o,maxTextureSize:i},a=new DataView(e,n,r),c=32+a.getUint32(12,!0)+a.getUint32(16,!0)+a.getUint32(20,!0)+a.getUint32(24,!0);if(0===a.getUint32(28,!0)){let r=pt(new Uint8Array(e,c+n,a.byteLength-c));-1==r.indexOf("://")&&(r=t.substring(0,t.lastIndexOf("/"))+"/"+r);return r.indexOf(".glb")>0?ye.getArrayBuffer(r,{}).then(t=>this.Mr(r,{buffer:t.data,byteOffset:0},o)):ye.getJSON(r,{}).then(t=>this.Mr(r,t,o))}{const r={buffer:e,byteOffset:c+n,byteLength:a.byteLength-c};return this.Mr(t,r,o)}}Mr(t,e,n){const r=t.substring(0,t.lastIndexOf("/")),s=new this.pr(r,e,n);return s.load({skipAttributeTransform:!0}).then(n=>{let r=0,i=0;return e.buffer&&(r=e.byteOffset||0,i=e.byteLength||0),n.url=`${t}-${r}-${i}`,{transferables:s.transferables,gltf:n}})}_r(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported pnts version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+r;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:h,batchTableBin:u}=jn(s,32+e,o),l={},f=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;l.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,n=a.QUANTIZED_VOLUME_SCALE,{byteOffset:r}=a.POSITION_QUANTIZED;l.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.Or(new Uint16Array(t,r+c.offset,3*f),e,n)},o.push(l.POSITION.array.buffer)}if(a.BATCH_ID){l.BATCH_ID=Pn(a.BATCH_ID,t,c.offset,f);const e=l.BATCH_ID.array&&l.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;l.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,l.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;l.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.xr(new Uint16Array(t,e+c.offset,2*f))},o.push(l.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,l.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.xr(new Uint16Array(t,e+c.offset,2*f))},o.push(l.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;l.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,f).slice()},o.push(l.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;l.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.SCALE_NON_UNIFORM.array.buffer)}return{count:f,batchTable:h,batchTableBin:u,featureTable:a,i3dm:l,transferables:o}}xr(t){const e=t.length/2,n=new Float32Array(3*e),r=[];for(let s=0;s<e;s++)xi(r,t[2*s],t[2*s+1],65535),n[3*s]=r[0],n[3*s+1]=r[1],n[3*s+2]=r[2];return n}Or(t,e,n){return Dn(new Float32Array(t.length),t,e,n)}wr(){return null}}function xi(t,e,n,r){if(t[0]=Ai(e,r),t[1]=Ai(n,r),t[2]=1-(Math.abs(t[0])+Math.abs(t[1])),t[2]<0){const e=t[0];t[0]=(1-Math.abs(t[1]))*Ii(e),t[1]=(1-Math.abs(e))*Ii(t[1])}return Ht(t,t)}function Ai(t,e){return function(t,e,n){return t<e?e:t>n?n:t}(t,0,e=function(t,e){if(null!=t)return t;return e}(e,255))/e*2-1}function Ii(t){return t<0?-1:1}class Si{constructor(){}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.gr(t,e,n,r)):ye.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.gr(t,s,n,r)})}gr(t,e,n,r){return this.Ar(e,n,r,t).then(t=>t.error?t:{magic:"pnts",count:t.count,transferables:t.transferables,featureTable:t.featureTable,batchTable:t.batchTable,batchTableBin:t.batchTableBin,pnts:t.pnts})}Ar(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported pnts version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+r;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:h,batchTableBin:u}=jn(s,e+28,o),l=a.QUANTIZED_VOLUME_OFFSET,f=a.QUANTIZED_VOLUME_SCALE,d=a.POINTS_LENGTH;let m,p={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){p=a.extensions["3DTILES_draco_point_compression"],m=new DataView(t,p.byteOffset+c.offset,p.byteLength);const e={attributes:p.properties,useUniqueIDs:!1};return this.Ir||(this.Ir=_i().draco),this.Ir(m,e).then(e=>{const n=e.attributes;!a.POSITION&&!a.POSITION_QUANTIZED||n.POSITION||n.POSITION_QUANTIZED||(n.POSITION=a.POSITION,n.POSITION_QUANTIZED=a.POSITION_QUANTIZED),!(a.RGB||a.RGBA||a.RGB565)||n.RGB||n.RGBA||n.RGB565||(n.RGB=a.RGB,n.RGBA=a.RGBA,n.RGB565=a.RGB565),!a.NORMAL&&!a.NORMAL_OCT16P||n.NORMAL||n.NORMAL_OCT16P||(n.NORMAL=a.NORMAL,n.NORMAL_OCT16P=a.NORMAL_OCT16P);const r=this.Sr(t,e.attributes,c.offset,d,o,l,f);if(e.attributes.BATCH_ID){const t=e.attributes.BATCH_ID.array;r.BATCH_ID={byteStride:0,byteOffset:0,itemSize:1,count:t.length,componentType:Fn(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?r.BATCH_ID=Pn(a.BATCH_ID,t,c.offset,d):r.BATCH_ID=Ei(d);const e=r.BATCH_ID.array&&r.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return{count:d,batchTable:h,batchTableBin:u,featureTable:a,pnts:r,transferables:o}})}const b=this.Sr(t,a,c.offset,d,o,l,f);if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?b.BATCH_ID=Pn(a.BATCH_ID,t,c.offset,d):b.BATCH_ID=Ei(d);const e=b.BATCH_ID.array&&b.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:d,batchTable:h,batchTableBin:u,featureTable:a,pnts:b,transferables:o})}Sr(t,e,n,r,s,i,o){const a={};if(e.POSITION){let{byteOffset:i,array:o}=e.POSITION;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r*4);o=new Float32Array(e)}a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:o},s.push(o.buffer)}else if(e.POSITION_QUANTIZED){let{byteOffset:c}=e.POSITION_QUANTIZED;const{array:h}=e.POSITION_QUANTIZED;c=c||0;const u=h?0:n;a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:this.Or(h||new Uint16Array(t,c+u,3*r),i,o)},s.push(a.POSITION.array.buffer)}if(e.RGBA){let{byteOffset:i,array:o}=e.RGBA;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+4*r);o=new Uint8Array(e)}a.RGBA={byteStride:0,byteOffset:0,itemSize:4,count:r,componentType:5121,array:o},s.push(o.buffer)}else if(e.RGB){let{byteOffset:i,array:o}=e.RGB;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r);o=new Uint8Array(e)}a.RGB={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5121,array:o},s.push(o.buffer)}else if(e.RGB565){let{byteOffset:i,array:o}=e.RGB565;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+2*r);o=new Uint16Array(e)}a.RGB565={byteStride:0,byteOffset:0,itemSize:1,count:r,componentType:5123,array:o},s.push(o.buffer)}if(e.NORMAL){let{byteOffset:i,array:o}=e.NORMAL;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r*4);o=new Float32Array(e)}a.NORMAL={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:o},s.push(o.buffer)}else if(e.NORMAL_OCT16P){let{byteOffset:i,array:o}=e.NORMAL_OCT16P;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+2*r);o=new Uint8Array(e)}a.NORMAL_OCT16P={byteStride:0,byteOffset:0,itemSize:2,count:r,componentType:5121,array:o},s.push(o.buffer)}return a}Or(t,e,n){return Dn(new Float32Array(t.length),t,e,n)}wr(){return null}}function Ei(t){const e=yt(t),n=new e(t);for(let e=0;e<t;e++)n[e]=e;return{byteStride:0,byteOffset:0,itemSize:1,count:t,componentType:Fn(e),array:n}}class Ni{constructor(t,e,n,r){this.o=n,this.i=t,this.pr=e||Ue,this.vr=r}load(t,e,n=0,r=0,s){return e?this.gr(t,e,n,r,s):ye.getArrayBuffer(t,{}).then(e=>{const s=e.data;return this.gr(t,s,n,r)})}gr(t,e,n,r,s){r||(r=e.byteLength);const i=this.Er(e,t,n,r),o=[];for(let n=0;n<i.length;n++){let r;if("b3dm"===i[n].magic)r=new Mi(this.i,this.pr,this.o);else if("i3dm"===i[n].magic)r=new Oi(this.i,this.pr,this.o,this.vr);else if("pnts"===i[n].magic)r=new Si;else{if("cmpt"!==i[n].magic){console.warn("Unsupported magic in CMPT tile:",i[n].magic);continue}r=new Ni(this.i,this.pr,this.o,this.vr)}o.push(r.load(t,e,i[n].offset,i[n].byteLength,s).then(t=>t))}return Promise.all(o).then(t=>({magic:"cmpt",tiles:t}))}Er(t,e,n,r){const s=new DataView(t,n,r),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported cmpt version: "+i+", url:"+e;return console.warn(t),{error:t}}if(16===s.byteLength)return[];const o=[],a=s.getUint32(12,!0);let c=16;for(let e=0;e<a;e++){const e=An(s,c),r=s.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+n,byteLength:r}),c+=r}return o}}if(i.transcoders){const t=s.Map.VERSION;if(t.indexOf("1.0.0-beta")>=0||t.indexOf("1.0.0-alpha")>=0){const t=i.transcoders.inject(o);s.registerWorkerAdapter("@maptalks/3dtiles",t)}else s.registerWorkerAdapter("@maptalks/3dtiles",(function(){return i.transcoders.inject(o)}))}else s.registerWorkerAdapter("@maptalks/3dtiles",o);t.B3DMLoader=Mi,t.CMPTLoader=Ni,t.Geo3DTilesLayer=pi,t.Geo3DTilesUtil=Ot,t.Geo3DTransform=On,Object.defineProperty(t,"t",{value:!0}),"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.95.4")}));
|
|
22
|
+
* (c) 2016-2024 maptalks.com
|
|
23
|
+
*/(100,1),os=[0,0,0,1],as=[1,1,1];class cs{constructor(t,e){this.rt=e,this.st=e.getRenderer().canvas,this.pickingFBO=e.getRenderer().pickingFBO,this.it=new s.SpatialReference,this.ot=t,this.ct=new n.reshader.Renderer(t),this.ht={},this.ut={},this.lt={},this.ft={},this.dt={},this.pt={},this.bt=new n.reshader.Scene,this.gt=new n.reshader.Scene,this.yt=new n.reshader.Scene,this.wt=new n.reshader.Scene,this.vt=new n.reshader.ResourceLoader(t.texture(2)),this.Tt=this._t.bind(this),this.Mt=new n.reshader.PhongMaterial({"baseColorFactor":[1,1,1,1]}),this.Ot(),this.xt=new n.reshader.KHRTechniquesWebglManager(this.ot,this.At(),this.vt);const r=this.getMap();r.altitudeToPoint&&(this.It=r.altitudeToPoint(100,r.getGLRes())/100)}getI3DMMeshes(){return this.ft}getPNTSMeshes(){return this.lt}getB3DMMeshes(){return this.ut}getPaintedMeshes(){return this.St}getMap(){return this.rt.getMap()}paint(t,e,r){const s=r&&r.renderTarget,i=r&&r.sceneFilter,o=this.getMap();if(!t.length||!o)return null;const a=this.Et(),c=o.projViewMatrix,h=[],l=[],f=[],d=[],m=[],p=this.Nt(t),b=[];for(let s=0,i=t.length;s<i;s++){const i=t[s].data.node;let o=this.Ct(i);if(!o)continue;const a=this.rt.Pt(i.Rt);i.kt&&a.debugShowBoundingVolume&&b.push(i.kt);const g=a.heightOffset||0,y=a.coordOffset||Dr;this.dt[i.id]&&(o=this.dt[i.id],o=gt(o));let w=a.polygonOffset||Rr;at(w)&&(w=w()),Array.isArray(o)||(h[0]=o,o=h);for(let t=0,s=o.length;t<s;t++){const s=o[t].properties.magic;if(o[t].properties.heightOffset===g&&o[t].properties.coordOffset[0]===y[0]&&o[t].properties.coordOffset[1]===y[1]||(this.Lt(o[t]),o[t].Bt=n.mat4.copy([],o[t].localTransform)),"b3dm"===s){if(o[t].getBoundingBox&&!u(c,o[t].getBoundingBox()))continue;const{batchIdData:e,batchIdMap:s}=o[t].geometry.properties;if(e&&s){const e=o[t].properties.node.Rt;this.Ut&&this.Ut[e]?n.HighlightUtil.highlightMesh(this.ot,o[t],this.Ut[e],this.Ft,s):this.Ut&&this.Ut[e]||n.HighlightUtil.highlightMesh(this.ot,o[t],null,this.Ft,s),n.HighlightUtil.showOnly(this.ot,o[t],this.Dt&&this.Dt[e],this.jt,s)}r&&r.bloom&&o[t].properties.hlBloomMesh&&(o[t].properties.hlBloomMesh.properties.depthFunc="always",o[t].properties.hlBloomMesh.properties.polygonOffset=w,f.push(o[t].properties.hlBloomMesh)),f.push(o[t])}else"pnts"===s?d.push(o[t]):"i3dm"===s&&m.push(o[t]);o[t].properties.isLeaf=!!e[i.id],o[t].properties.level=p.get(i.zt),o[t].properties.polygonOffset=w,o[t].Ht=i,e[i.id]||l.push(o[t]),this.Gt(o[t]),this.qt(o[t],i)}}let g=0;const y=this.xt.getExcludeFilter();g+=this.Vt(this.$t,a,[i,jr,y],s,l,f,m),g+=this.Vt(this.Xt,a,[i,zr,y],s,l,f,m),this.xt.forEachShader((t,e,n)=>{const r=this.Et(n);g+=this.Vt(t,r,[i,e],s,l,f,m)}),this.gt.setMeshes(d);const w=this.Jt();return g+=this.ct.render(this.Kt,w,this.gt,s&&s.fbo),this.St={pntsMeshes:d,i3dmMeshes:m,b3dmMeshes:f},b.forEach(t=>{this.Qt(t)}),this.wt.setMeshes(b),this.ct.render(this.Zt,a,this.wt,s&&s.fbo),g}Qt(t){const e=t.properties.node,r=this.rt.Pt(e.Rt),s=this.rt.Yt(e.Rt),i=r.heightOffset||0,o=this.Wt(),a=s.te,c=n.vec3.set(es,0,0,o*(i-a));let h=r.rotation||[0,0,0];h=n.quat.fromEuler(Yr,h[0],h[1],h[2]);const u=r.scale||[1,1,1],l=n.mat4.fromRotationTranslationScale(Zr,h,c,u);n.mat4.multiply(t.localTransform,t.Bt,l)}Vt(t,e,n,r,s,i,o){t.filter=n.filter(t=>!!t),e.debug=!1,e.debug=!1;let a=0;return this.bt.setMeshes(i),a+=this.ct.render(t,e,this.bt,r&&r.fbo),this.yt.setMeshes(o),a+=this.ct.render(t,e,this.yt,r&&r.fbo),a}ee(t,e){return e.Ht.ne-t.Ht.ne}deleteTile(t){const e=t.node;e.kt&&(e.kt.geometry.dispose(),e.kt.dispose(),delete e.kt);const n=e.id;this.re(n)}re(t){const e=this.ut[t]||this.lt[t]||this.ft[t]||this.dt[t]||this.ht[t];this.dt[t]?this.se(t):e&&(this.ie(e),delete this.ut[t],delete this.lt[t],delete this.ft[t],delete this.ht[t])}se(t){let e=this.dt[t];e=gt(e);for(let t=0;t<e.length;t++){const{id:n}=e[t].properties;this.re(n)}delete this.dt[t]}ie(t){if(Array.isArray(t))for(let e=0,n=t.length;e<n;e++)this.ie(t[e]);else{n.HighlightUtil.showOnly(this.ot,t),n.HighlightUtil.highlightMesh(this.ot,t);const e=t.geometry.properties.url;if(e){const n=this.pt[e];n&&n.refMeshes&&(n.refMeshes.delete(t.uuid),n.refMeshes.size||(n.geometry.dispose(),n.material.dispose(),delete this.pt[e]))}else t.geometry.dispose(),t.material&&t.material.dispose();t.dispose()}}remove(){const t=this.rt;Nr(t.getRenderer().canvas,t.getMap());for(const t in this.dt)this.se(t);this.dt={};for(const t in this.ut)this.re(t);this.ut={};for(const t in this.lt)this.re(t);this.lt={};for(const t in this.ft)this.re(t);this.ft={};for(const t in this.ht)this.re(t);this.ht={},this.$t&&(this.$t.dispose(),delete this.$t),this.Xt&&(this.Xt.dispose(),delete this.Xt),this.Kt&&(this.Kt.dispose(),delete this.Kt),this.Zt&&(this.Zt.dispose(),delete this.Zt),this.xt.dispose(),this.picking&&this.picking.dispose()}Ct(t){return this.ut[t.id]||this.lt[t.id]||this.ft[t.id]||this.dt[t.id]}has(t){return this.Ct(t)||this.ht[t.id]}Lt(t){const e=t.properties.magic;"b3dm"===e?this.oe(t):"i3dm"===e?this.ae(t):"pnts"===e&&this.ce(t)}createPntsMesh(t,e,r,s){if(this.lt[e]){const t=this.lt[e];return console.warn(`pnts mesh with id(${e}) was already created.`),s(null,{id:e,mesh:t}),t}const{pnts:i,featureTable:o,rootIdx:a,compressed_int16_params:c}=t,h=o.POINTS_LENGTH;i.BATCH_ID||(i.BATCH_ID=new Uint8Array(h),i.BATCH_ID.fill(0));const u=new n.reshader.Geometry(i,null,h,{static:!0,primitive:"points",positionAttribute:"POSITION",pickingIdAttribute:"BATCH_ID"});u.generateBuffers(this.ot);const l={};i.POSITION?l.HAS_POSITION=1:i.POSITION_QUANTIZED&&(l.HAS_POSITION_QUANTIZED=1),i.RGB?l.HAS_RGB=1:i.RGBA?l.HAS_RGBA=1:i.RGB565&&(l.HAS_RGB565=1),(i.NORMAL||i.NORMAL_OCT16P)&&(l.HAS_NORMAL=1,i.NORMAL_OCT16P&&(l.HAS_NORMAL_OCT16P=1)),this.he(l,c),t.featureTable.CONSTANT_RGBA&&(t.featureTable.CONSTANT_RGBA=t.featureTable.CONSTANT_RGBA.map(t=>t/255));const{rtcCenter:f,rtcCoord:d,projCenter:m}=t,p=this.rt.Pt(a),b=new n.reshader.Mesh(u);b.properties.magic="pnts",b.properties.id=e,b.properties.node=r,b.properties.count=h,b.properties.batchTable=t.batchTable,b.properties.batchTableBin=t.batchTableBin,b.properties.serviceIndex=a,b.properties.rtcCoord=d,b.properties.rtcCenter=f,b.properties.projCenter=m,b.setDefines(l),Object.defineProperty(b.uniforms,"pointColor",{enumerable:!0,get:function(){return t.featureTable.CONSTANT_RGBA?t.featureTable.CONSTANT_RGBA:p&&p.pointColor||[1,1,1,1]}});const g=this.getMap();let y=null,w=null;Object.defineProperty(b.uniforms,"pointSize",{enumerable:!0,get:function(){if(!p)return 2;if(yr(p.pointSize)){const t=JSON.stringify(p.pointSize);t!==y&&(w=wr(p.pointSize),y=t);return w(g.getZoom())}return p.pointSize||2}});let v=null,T=null;return Object.defineProperty(b.uniforms,"pointOpacity",{enumerable:!0,get:function(){if(!p)return 1;if(yr(p.pointOpacity)){const t=JSON.stringify(p.pointOpacity);t!==v&&(T=wr(p.pointOpacity),v=t);return T(g.getZoom())}return p.pointOpacity||1}}),this.ue(b,c),this.ce(b),b.Bt=n.mat4.copy([],b.localTransform),this.lt[e]=b,s(null,{id:e,mesh:[b]}),[b]}ce(t){const e=t.localTransform||[],{rtcCoord:n,node:r,projCenter:s}=t.properties;this.le(e,n,s,r.Rt),t.setLocalTransform(e)}createI3DMMesh(t,e,r,s){if(this.ft[e]){const t=this.ft[e];return console.warn(`i3dm mesh with id(${e}) was already created.`),this.ht[e]||s(null,{id:e,mesh:t}),t}const i=this.rt.Pt(r.Rt),o=this.fe(r.de),{i3dm:a,featureTable:c,gltf:h,batchTable:u,batchTableBin:l,count:f}=t,d=c.INSTANCES_LENGTH,{rtcCenter:m,rtcCoord:p}=t,b=this.me(Kr,p),g=this.pe(Qr,r,m,p);n.mat4.multiply(b,g,b);const{POSITION:y,NORMAL_UP:w,NORMAL_RIGHT:v,SCALE:T,SCALE_NON_UNIFORM:_,INSTANCE_ROTATION:M}=a,O={"instance_vectorA":new Float32Array(4*d),"instance_vectorB":new Float32Array(4*d),"instance_vectorC":new Float32Array(4*d),"aPickingId":new Uint16Array(d)};for(let t=0;t<d;t++)O.aPickingId[t]=t;const x=new Float32Array(3),A=new Float32Array(3),I=[],S=new Float32Array(1),E=new Float32Array(3),N=[],C=[],P=[],R=[],k=new Float32Array(9);!function(t,e){let{byteOffset:n,byteStride:r,count:s}=t;const{componentType:i,itemSize:o}=t,a=t.array.buffer,c=i?Ue.getTypedArrayCtor(i):t.array.constructor;if(n=void 0===n?t.array.byteOffset:n,r=r||0,s=s||t.array.length/o,(!r||r===o*c.BYTES_PER_ELEMENT)&&n%c.BYTES_PER_ELEMENT==0){const t=new c(a,n,s*o);for(let r=0;r<s*o;r+=o){e(new c(t.buffer,n+r*c.BYTES_PER_ELEMENT,o),r/o)}return}const h=new Uint8Array(o*c.BYTES_PER_ELEMENT);r||(r=o*c.BYTES_PER_ELEMENT);for(let t=0;t<s;t++){const s=new Uint8Array(a,r*t+n,o*c.BYTES_PER_ELEMENT);h.set(s);e(new c(h.buffer),t),s.set(h)}}(y,(t,e)=>{w?(rn(A,v,e),rn(x,w,e),n.vec3.cross(I,A,x),n.vec3.normalize(I,I),bt(N,A,0),bt(N,x,1),bt(N,I,2),n.quat.fromMat3(C,N)):M?(rn(k,M,e),n.quat.fromMat3(C,k)):n.quat.identity(C),T?(rn(S,T,e),n.vec3.set(P,S[0],S[0],S[0])):_?(rn(E,_,e),n.vec3.set(P,...E)):n.vec3.set(P,1,1,1),n.mat4.fromRotationTranslationScale(R,C,t,P),sn(O.instance_vectorA,e,R,0),sn(O.instance_vectorB,e,R,1),sn(O.instance_vectorC,e,R,2)});const L={};for(const t in O)L[t]={buffer:this.ot.buffer({dimension:O[t].length/d,data:O[t]}),divisor:1};const B=i.shader||"pbr";let U=0,F=!0;const D=[],j=[];return Ke(h,(t,s,i,a)=>{const c=this.be(t,s,i,a,r,!0,B,j),{geometry:h,material:g}=c;g&&!g.isReady()&&(F=!1,U++);const y=new n.reshader.InstancedMesh(L,d,h,g);c.refMeshes||(c.refMeshes=new Set,c.refMeshes.add(y.uuid)),y.properties.magic="i3dm",y.properties.id=e,y.properties.count=f,y.properties.batchTable=u,y.properties.batchTableBin=l,y.properties.serviceIndex=r.Rt,y.properties.rtcCoord=p,y.properties.rtcCenter=m,y.properties.node=r;const w=this.ge(t,h,g,r.Rt,a);t.compressed_int16_params&&this.ue(y,t.compressed_int16_params),this.ye(y,t.attributes);const v=n.mat4.identity([]);if(t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)n.mat4.multiply(v,v,t.matrices[e]);n.mat4.multiply(v,o,v),y.setPositionMatrix(v),this.ae(y,b),y.setDefines(w),y.properties.polygonOffset={offset:0,factor:0},D.push(y),delete t.attributes,y.Bt=n.mat4.copy([],y.localTransform)}),hs(j),F?(this.ft[e]=D,s(null,{id:e,mesh:D})):(this.ht[e]={meshes:D,count:U},D.we=s),D}ae(t,e){const{rtcCenter:r,rtcCoord:s,node:i}=t.properties;if(!e){e=this.me(Kr,s);const t=this.pe(Qr,i,r,s);n.mat4.multiply(e,t,e)}const o=this.rt.Pt(i.Rt),a=t.localTransform||[];if(o.coordOffset){const t=this.ve(Qr,i.Rt,s);n.mat4.multiply(a,t,e)}else n.mat4.copy(a,e);t.setLocalTransform(a),t.properties.heightOffset=o.heightOffset||0,t.properties.coordOffset=o.coordOffset&&o.coordOffset.slice(0)||Dr}createB3DMMesh(t,e,r,i){if(t.gltf&&(t.gltf.transferables=null),this.ut[e]||this.ht[e]){const t=this.ut[e];return console.warn(`mesh with id(${e}) was already created.`),this.ht[e]||i(null,{id:e,mesh:t}),t}let o;if(r.maxExtent){const t=new s.Extent(r.maxExtent).convertTo(t=>this._pointToPrj(t));o=[t.xmin,t.ymin,t.xmax,t.ymax]}const a=t.gltf,{projCenter:c}=a.extensions.MAPTALKS_RTC,{rtcCoord:h,center:u}=a.extensions.CESIUM_RTC,l=a.asset.sharePosition,f=this.fe(r.de);let d;d=l?this.me(Kr,h):this.le(Kr,h,c,r.Rt);const m=this.rt.Pt(r.Rt);let p=m.shader||"pbr";if(m.unlit)p="phong";else if(a.materials)for(let t=0;t<a.materials.length;t++)if(a.materials[t]&&a.materials[t].extensions&&a.materials[t].extensions.KHR_materials_unlit){p="phong";break}const b=[],g=[];let y=0,w=!0;return Ke(a,(s,i,a,v)=>{const T=this.be(s,i,a,v,r,!1,p,b),{geometry:_,material:M}=T;M&&!M.isReady()&&(w=!1,y++);const O=new n.reshader.Mesh(_,M);T.refMeshes||(T.refMeshes=new Set,T.refMeshes.add(O.uuid)),O.properties.magic="b3dm",O.properties.id=e,O.properties.node=r,t.batchTable&&(O.properties.batchTable=t.batchTable,O.properties.batchTableBin=t.batchTableBin),O.properties.count=t.featureTable&&t.featureTable.BATCH_LENGTH||0,O.properties.serviceIndex=r.Rt;const x=this.ge(s,_,M,r.Rt,v);O.setDefines(x);const A=s.compressUniforms;if(A)for(const t in A)O.setUniform(t,A[t]);s.compressed_int16_params&&this.ue(O,s.compressed_int16_params),this.ye(O,s.attributes),o&&(x.USE_MAX_EXTENT=1,O.setUniform("maxPrjExtent",o)),Object.prototype.hasOwnProperty.call(O.uniforms,"polygonOpacity")||Object.defineProperty(O.uniforms,"polygonOpacity",{enumerable:!0,get:function(){return ht(m.opacity)?m.opacity:1}}),Object.prototype.hasOwnProperty.call(O.uniforms,"polygonFill")||Object.defineProperty(O.uniforms,"polygonFill",{enumerable:!0,get:function(){return Mt([],m.polygonFill||kr)}}),Object.prototype.hasOwnProperty.call(O.material.uniforms,"hsv")||Object.defineProperty(O.material.uniforms,"hsv",{enumerable:!0,get:function(){return m.hsv||Lr}});const I=n.mat4.identity([]);if(l&&s.matrices&&s.matrices.length)for(let t=0;t<s.matrices.length;t++)n.mat4.multiply(I,I,s.matrices[t]);l&&n.mat4.multiply(I,f,I),O.properties.node=r,O.properties.projCenter=c,O.properties.nodeMatrix=I,O.properties.isSharedPosition=l,O.properties.rtcCoord=h,O.properties.rtcCenter=u,this.oe(O,d),g.push(O),delete s.attributes,O.Bt=n.mat4.copy([],O.localTransform)}),hs(b),w?(this.ut[e]=g,i(null,{id:e,mesh:g})):(this.ht[e]={meshes:g,count:y},g.we=i),g}Te(t){const e=this.rt._e[t.id];if(!e)return;let r,s,i,o;if(e.length){if(2===e.length){const t=e[0],n=e[1];r=is.vertices,s=is.indices,i=t,o=[n,n,n]}}else{r=e.boxPosition,s=ss;i=this.rt.Yt(t.Rt).Me,o=as}const a=new n.reshader.Geometry({POSITION:r},s,0,{primitive:"lines",positionAttribute:"POSITION"}),c=new n.reshader.Mesh(a,new n.reshader.Material({lineColor:[.8,.8,.1,1],lineOpacity:1})),h=n.mat4.identity([]);n.mat4.fromRotationTranslationScale(h,os,i,o),c.localTransform=h,c.Bt=n.mat4.copy([],h),c.properties.node=t,t.kt=c}ue(t,e){e.POSITION&&t.setUniform("compressedPositionRange",e.POSITION),e.TEXCOORD_0&&t.setUniform("compressedTexcoordRange_0",e.TEXCOORD_0),e.TEXCOORD_1&&t.setUniform("compressedTexcoordRange_1",e.TEXCOORD_0),e.NORMAL&&t.setUniform("compressedNormalRange",e.NORMAL),e.TANGENT&&t.setUniform("compressedTangentRange",e.TANGENT),e.compressed_ratio&&t.setUniform("compressed_ratio",e.compressed_ratio)}oe(t,e){const{isSharedPosition:r,rtcCoord:s,rtcCenter:i,projCenter:o,nodeMatrix:a,node:c}=t.properties;e||(e=r?this.me(Kr,s):this.le(Kr,s,o,c.Rt));const h=t.localTransform||n.mat4.identity([]);if(r){const t=this.pe(Qr,c,i,s);n.mat4.multiply(h,e,a),n.mat4.multiply(h,t,h)}else n.mat4.multiply(h,e,a);const u=this.rt.Pt(c.Rt);if(u.coordOffset){const t=this.ve(Qr,c.Rt,s);n.mat4.multiply(h,t,h)}t.setLocalTransform(h),t.properties.heightOffset=u.heightOffset||0,t.properties.coordOffset=u.coordOffset&&u.coordOffset.slice(0)||Dr}ye(t,e){if(e&&e.TEXCOORD_0&&e.TEXCOORD_0.extensions&&e.TEXCOORD_0.extensions.WEB3D_quantized_attributes){const n=e.TEXCOORD_0.extensions.WEB3D_quantized_attributes.decodeMatrix;t.setUniform("decodeMatrix",n)}}pe(t,e,r,i){const o=this.getMap(),a=this.rt.Pt(e.Rt).heightOffset||0,c=new s.Coordinate(i);let h;h=o.altitudeToPoint?this.It:o.distanceToPointAtRes(100,100,o.getGLRes(),c).y/100;const u=e.matrix?n.mat4.copy(t,e.matrix):n.mat4.identity(t);if(r){Jn(u,n.vec3.transformMat4(Hr,r,u),u)}const l=function(t,e,n,r,s,i,o){e=Bt(Qn,e);const a=un(Qn,e[0]*ir,e[1]*ir,e[2]),c=function(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}(Zn,n),h=r.ellipsoid;let u;u=0===Xt(c)?Ut(Yn,0,0,-6378137):bn(Yn,c),rr.x=u[0],rr.y=u[1];const l=r.project(rr,sr);Wn[0]=l.x/s,Wn[1]=l.y/s,Wn[2]=(u[2]+o)*i;const f=Kn(a,h,tr),d=function(t,e,n){const r=t[0],s=t[1],i=t[2],o=t[4],a=t[5],c=t[6],h=t[8],u=t[9],l=t[10],f=e[0],d=e[1],m=e[2],p=e[3],b=e[4],g=e[5],y=e[6],w=e[7],v=e[8],T=r*f+o*d+h*m,_=s*f+a*d+u*m,M=i*f+c*d+l*m,O=r*p+o*b+h*g,x=s*p+a*b+u*g,A=i*p+c*b+l*g,I=r*y+o*w+h*v,S=s*y+a*w+u*v,E=i*y+c*w+l*v;return n[0]=T,n[1]=_,n[2]=M,n[3]=0,n[4]=O,n[5]=x,n[6]=A,n[7]=0,n[8]=I,n[9]=S,n[10]=E,n[11]=0,n[12]=t[12],n[13]=t[13],n[14]=t[14],n[15]=t[15],n}(function(t,e){var n=e[0],r=e[1],s=e[2],i=e[3],o=e[4],a=e[5],c=e[6],h=e[7],u=e[8],l=e[9],f=e[10],d=e[11],m=e[12],p=e[13],b=e[14],g=e[15],y=n*a-r*o,w=n*c-s*o,v=n*h-i*o,T=r*c-s*a,_=r*h-i*a,M=s*h-i*c,O=u*p-l*m,x=u*b-f*m,A=u*g-d*m,I=l*b-f*p,S=l*g-d*p,E=f*g-d*b,N=y*E-w*S+v*I+T*A-_*x+M*O;return N?(N=1/N,t[0]=(a*E-c*S+h*I)*N,t[1]=(s*S-r*E-i*I)*N,t[2]=(p*M-b*_+g*T)*N,t[3]=(f*_-l*M-d*T)*N,t[4]=(c*A-o*E-h*x)*N,t[5]=(n*E-s*A+i*x)*N,t[6]=(b*v-m*M-g*w)*N,t[7]=(u*M-f*v+d*w)*N,t[8]=(o*S-a*A+h*O)*N,t[9]=(r*A-n*S-i*O)*N,t[10]=(m*_-p*v+g*y)*N,t[11]=(l*v-u*_-d*y)*N,t[12]=(a*x-o*I-c*O)*N,t[13]=(n*I-r*x+s*O)*N,t[14]=(p*w-m*T-b*y)*N,t[15]=(u*T-l*w+f*y)*N,t):null}(er,f),function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t}(nr,n),t);return Jn(t,Wn,d),t}(u,i,u,o.getProjection(),o.getGLRes(),h,a),f=function(t,e){return Ut(t,e[12],e[13],e[14]),t}(Jr,l);let d=this.rt.options.offset;if(at(d)){const t=this.rt.Oe(e.id).center;d=d.call(this.rt,t)}return n.vec3.set(Xr,d[0],d[1],0),n.vec3.sub(f,f,Xr),Jn(l,f,l),l}ve(t,e,r){const s=this.rt.Pt(e);if(!s.coordOffset)return null;const i=this.getMap(),o=i.getGLRes();Gr.set(r[0],r[1]);const a=i.coordToPointAtRes(Gr,o,Vr),c=s.coordOffset,h=Gr.set(r[0]+c[0],r[1]+c[1]),u=i.coordToPointAtRes(h,o,$r),l=u.x-a.x,f=u.y-a.y,d=this.Wt(),m=n.vec3.set(Xr,l,f,(c[2]||0)*d);return n.mat4.fromTranslation(t,m)}Wt(){const t=this.getMap();let e;return e=t.altitudeToPoint?this.It:t.distanceToPointAtRes(100,100,t.getGLRes(),Gr).y/100,e}createCMPTMesh(t,e,n,r){if(this.dt[e]){const t=this.dt[e];return console.warn(`mesh with id(${e}) was already created.`),r(null,{id:e,mesh:t}),t}const{content:s}=t,i=[];for(let t=0;t<s.length;t++){const{magic:r}=s[t],o=e+"."+t;"b3dm"===r?this.createB3DMMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)}):"i3dm"===r?this.createI3DMMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)}):"pnts"===r?this.createPntsMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)}):"cmpt"===r&&this.createCMPTMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)})}return this.dt[e]=i,r(null,{id:e,mesh:i}),i}ge(t,e,n,r,s){const i=("phong"===(this.rt.Pt(r).shader||"pbr")?this.$t:this.Xt).getGeometryDefines(e);s.asset&&"S3M"===s.asset.generator&&this.xe(i,e),e.data.uvRegion&&(i.HAS_I3S_UVREGION=1),e.data[e.desc.normalAttribute]&&(i.VertexNormal=1),e.data[e.desc.color0Attribute]&&(i.VertexColor=1),e.data[e.desc.uv0Attribute]&&(i.TexCoord=1),e.data[e.desc.textureCoordMatrixAttribute]&&(i.HAS_TextureCoordMatrix=1),n.get("uTexture")&&(i.COMPUTE_TEXCOORD=1),n.get("uTexture2")&&(i.TexCoord2=1),"MESHOPT"===this.rt.Ae&&(i.MeshOPT_Compress=1),this.hasIBL()&&(i.HAS_IBL_LIGHTING=1),t.attributes&&t.attributes.TEXCOORD_0&&"WEB3D_quantized_attributes"===t.attributes.TEXCOORD_0.extensions&&(i.HAS_WEB3D_quantized_attributes_TEXCOORD=1),i.HAS_MIN_ALTITUDE=1,i.HAS_LAYER_OPACITY=1,this.he(i,t.compressed_int16_params);return ot(i,t.compressDefines),i}he(t,e){e&&Object.keys(e).length>0&&(t.HAS_COMPRESSED_INT16=1,e.POSITION&&(t.HAS_COMPRESSED_INT16_POSITION=1),e.TEXCOORD_0&&(t.HAS_COMPRESSED_INT16_TEXCOORD_0=1),e.TEXCOORD_1&&(t.HAS_COMPRESSED_INT16_TEXCOORD_1=1),e.NORMAL&&(t.HAS_COMPRESSED_INT16_NORMAL=1),e.TANGENT&&(t.HAS_COMPRESSED_INT16_TANGENT=1),e.compressed_ratio&&(t.HAS_COMPRESSED_INT16_RATIO=1))}Gt(t){const e=this.rt.getRenderer();e&&e.updateMaskDefines(t)}xe(t,e){e.data.aNormal&&(t.VertexNormal=1),e.data.instanceId&&(t.Instance=1),e.data.aTexCoord0&&(t.TexCoord=1),e.data.aColor&&(t.VertexColor=1),e.data.aTexCoord1&&(t.TexCoord2=1),e.data.uv2&&(t.InstanceBim=1)}be(t,e,n,r,s,i,o,a){let c=!1;r.asset&&"S3M"===r.asset.generator&&(c=!0,r.extensions=r.extensions||{});const h=r.url+"-"+e+"-"+n;if(this.pt[h])return this.pt[h];let u,l;a.push(t);const f=r.materials&&r.materials[t.material],d=r.extensions&&r.extensions.KHR_techniques_webgl,m=this.rt.Pt(s.Rt);if(d&&f.extensions&&f.extensions.KHR_techniques_webgl){const e=this.Ie(t,r,i,c);u=e.material,l=e.geometry,m.fillEmptyDataInMissingAttribute&&(l.desc.fillEmptyDataInMissingAttribute=!0)}else{l=this.Se(t,i,rs);const e=m.ambientLight;let n=m.environmentExposure;const s=m.material,c=this.getMap().getLightManager(),h=c&&c.getAmbientLight();if(e&&(!h||h.color)&&void 0===n){const t=h&&h.color?h.color[0]:.2;n=e[0]/t}u=this.Ee(t.material,r,o,s||Br,n||1,a,m)}u&&Object.defineProperty(u.uniforms,"alphaTest",{enumerable:!0,get:function(){const t=m.alphaTest;return it(t)?.1:t}}),u&&!u.isReady()?u.Ne=s.id:u||(u=this.Mt);const p={geometry:l,material:u};return l.properties.url=h,this.pt[h]=p,p}Ie(t,e,n,r){const{geometry:s,material:i}=this.xt.createMesh(t,e,n,r);return{geometry:s,material:i}}Se(t,e,r){const s=t.attributes;let i=s._BATCHID&&s._BATCHID.array;if(i&&i.byteOffset&&(i=new i.constructor(i)),s.COLOR_0){const t=s.COLOR_0.array||s.COLOR_0;if(t instanceof Float32Array){const e=new Uint8Array(t.length);for(let n=0;n<e.length;n++)e[n]=Math.round(255*t[n]);s.COLOR_0.array?(s.COLOR_0.array=e,s.COLOR_0.componentType=5121):s.COLOR_0=e}}const o={};for(const t in s){const e=Ar(this.ot,s[t],{dimension:s[t].itemSize}),n=r[t]||t;o[n]={buffer:e},s[t].quantization&&(o[n].quantization=s[t].quantization),n===r.POSITION&&(o[n].array=s[t].array,o[n].min=s[t].min,o[n].max=s[t].max)}const a=t.indices?t.indices.array?t.indices.array.slice():t.indices:null,c=new n.reshader.Geometry(o,a,0,{static:!0,positionAttribute:r.POSITION,normalAttribute:r.NORMAL,uv0Attribute:r.TEXCOORD_0,uv1Attribute:r.TEXCOORD_1,color0Attribute:r.COLOR_0,tangentAttribute:r.TANGENT,pickingIdAttribute:r._BATCHID,primitive:void 0===t.mode?"triangles":xr(t.mode)});return i&&a&&(c.properties.batchIdData=i,c.properties.batchIdMap=function(t,e){if(!e)return null;const n=new Map;for(let r=0;r<e.length;r++){const s=e[r],i=t[s];let o=n.get(i);o||(o=[],n.set(i,o)),o.push(s)}return n}(i,a)),c.generateBuffers(this.ot,{excludeElementsInVAO:e}),c}le(t,e,r,s){const i=n.mat4.identity(t),o=this.getMap();Gr.x=r[0],Gr.y=r[1];const a=this._prjToPoint(Gr),c=this.Ce(),h=1/(o.getGLZoom?o.getResolution(o.getGLZoom()):o.getGLRes());Gr.x=e[0],Gr.y=e[1];const u=this.Wt();let l=this.rt.options.offset;at(l)&&(l=l.call(this.rt,Gr));const f=this.rt.Pt(s).heightOffset||0;return n.vec3.set(Jr,a.x-l[0],a.y-l[1],u*r[2]+u*f),n.mat4.translate(i,i,Jr),n.vec3.set(c,h,h,u),n.mat4.scale(i,i,c),i}qt(t,e){const r=this.rt.Pt(e.Rt),s=this.rt.Yt(e.Rt).Me;let i=r.rotation||[0,0,0];i=n.quat.fromEuler(Wr,i[0],i[1],i[2]);const o=r.scale||[1,1,1],a=n.mat4.fromRotationTranslationScale([],i,ts,o),c=n.mat4.identity([]),h=n.mat4.identity([]);n.mat4.translate(c,c,n.vec3.scale(ns,s,-1)),n.mat4.translate(h,h,s);const u=n.mat4.multiply(c,c,t.Bt);n.mat4.multiply(a,a,u);const l=n.mat4.multiply(h,h,a);t.localTransform=l}me(t,e){const r=n.mat4.identity(t),s=this.getMap(),i=this.Ce();Gr.x=e[0],Gr.y=e[1];const o=s.distanceToPointAtRes(100,100,s.getGLRes(),Gr);let a;return a=s.altitudeToPoint?this.It:o.y/100,n.vec3.set(i,o.x/100*1.01,o.y/100*1.01,a),n.mat4.scale(r,r,i),r}Ot(){const t={x:0,y:0,width:()=>this.st?this.st.width:1,height:()=>this.st?this.st.height:1},e=[],r=[];this.Kt=new n.reshader.MeshShader({vert:on,frag:"#define SHADER_NAME PNTS\n\nprecision mediump float;\n\n\n\nvarying vec4 vColor;\n\n\n\nvoid main() {\n\n vec2 circCoord = 2.0 * gl_PointCoord - 1.0;\n\n if (dot(circCoord, circCoord) > 1.0) {\n\n discard;\n\n } else {\n\n gl_FragColor = vColor;\n\n }\n\n}\n\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:(t,e)=>n.mat4.multiply(r,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,r)=>n.mat3.fromMat4(e,r.modelMatrix)}],extraCommandProps:{viewport:t,blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"},depth:{enable:!0,range:[0,1],func:"<"}}});const s=this.At();this.$t=new n.reshader.PhongShader({extraCommandProps:s}),this.Xt=new n.reshader.pbr.StandardShader({extraCommandProps:s}),this.Zt=new n.reshader.EdgeShader({extraCommandProps:{viewport:{x:0,y:0,width:()=>this.st?this.st.width:1,height:()=>this.st?this.st.height:1},blend:{enable:!0,func:{srcRGB:"src alpha",srcAlpha:1,dstRGB:"one minus src alpha",dstAlpha:"one minus src alpha"},equation:"add"}}});const i=this.rt;Er(i.getRenderer().canvas,this.ot,i.getMap()),this.picking=new n.reshader.FBORayPicking(this.ct,{vert:this.Xt.vert,extraCommandProps:s,uniforms:this.Xt.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap()),this.Pe=new n.reshader.FBORayPicking(this.ct,{vert:on,extraCommandProps:s,uniforms:this.Kt.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap())}At(){return{viewport:{x:0,y:0,width:()=>this.st?this.st.width:1,height:()=>this.st?this.st.height:1},cull:{enable:!0},stencil:{enable:!0,func:{cmp:(t,e)=>e.meshProperties.isLeaf?"always":">=",ref:(t,e)=>e.meshProperties.level},opFront:{fail:"keep",zfail:"keep",zpass:"replace"},opBack:{fail:"keep",zfail:"keep",zpass:"replace"}},depth:{enable:!0,range:[0,1],func:(t,e)=>e.meshProperties.depthFunc||"<"},blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"},polygonOffset:{enable:!0,offset:(t,e)=>e.meshProperties.polygonOffset}}}Jt(t){const e=this.getMap(),r=e.getLightManager(),s=(r&&r.getDirectionalLight()||{}).direction||[1,1,-1],i=t&&t.pointOpacity||1;return{projViewMatrix:e.projViewMatrix,pointOpacity:i,lightDir:n.vec3.normalize(s,s)}}Et(){const t=this.getMap(),e=this.rt,n=e.getRenderer().canvas,{iblTexes:r,dfgLUT:s}=Cr(n),i=Pr(t,r,s),o=this.rt.getRenderer(),a=o.getMaskUniforms();i.minAltitude=e.options.altitude||0;const c=o.canvas.gl&&o.canvas.gl.wrap?e.options.opacity||0:1;return i.layerOpacity=c,ot(i,{czm_lightDirectionEC:i.light0_viewDirection,lightSpecular:[1,1,1],viewMatrix:t.viewMatrix,projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,outSize:[n.width,n.height],polygonFill:[1,1,1,1],polygonOpacity:1}),ot(i,a),i}Ee(t,e,r,s,i,o,a){const c=e.materials&&e.materials[t];if(!c||!c.baseColorTexture&&!c.pbrMetallicRoughness)return null;const h=ot({},s);if(c.baseColorTexture){const t=e.textures[c.baseColorTexture.index];let n;t&&!t.image.color&&(n=this.C(t,o)),h.baseColorFactor=t&&t.image.color||c.baseColorFactor||[1,1,1,1],n&&(h.baseColorTexture=n)}else{if(c.normalTexture){const t=this.C(e.textures[c.normalTexture.index],o);if(t){const e=c.normalTexture.scale||1;h.normalTexture=t,h.normalMapFactor=e}}if(c.occlusionTexture){const t=this.C(e.textures[c.occlusionTexture.index],o);if(t){const e=c.occlusionTexture.strength||1;h.occlusionTexture=t,h.occlusionFactor=e}}if(c.emissiveTexture){const t=this.C(e.textures[c.emissiveTexture.index],o);t&&(h.emissiveTexture=t)}c.emissiveFactor&&(h.emissiveFactor=c.emissiveFactor);const t=c.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(h.baseColorFactor=t.baseColorFactor),t.baseColorTexture&&void 0!==t.baseColorTexture.index){const r=e.textures[t.baseColorTexture.index];if(r.image&&r.image.color)h.baseColorFactor=h.baseColorFactor?n.vec4.multiply(h.baseColorFactor,h.baseColorFactor,r.image.color):r.image.color;else{const t=this.C(r,o);t&&(h.baseColorTexture=t,h.baseColorTexture.getREGLTexture(this.ot))}}if(it(t.metallicFactor)||(h.metallicFactor=t.metallicFactor),it(t.roughnessFactor)||(h.roughnessFactor=t.roughnessFactor),c.metallicRoughnessTexture){const t=this.C(e.textures[c.metallicRoughnessTexture.index],o);t&&(h.metallicRoughnessTexture=t)}}}if(c.s3mMaterial)return new n.reshader.Material(h);if(h.environmentExposure=i,h.alphaTest=.1,a.unlit||c.extensions&&c.extensions.KHR_materials_unlit)return h.ambientColor=[1,1,1],h.light0_diffuse=[0,0,0,0],h.lightSpecular=[0,0,0],new n.reshader.PhongMaterial(h);let u=new n.reshader.pbr.StandardMaterial(h);"phong"===r&&(u=n.reshader.PhongMaterial.convertFrom(u));const l=c.pbrMetallicRoughness,f=l&&l.baseColorTexture&&l.baseColorTexture.extensions;return f&&f.KHR_texture_transform&&(u.set("khr_offset",f.KHR_texture_transform.offset||[0,0]),u.set("khr_rotation",f.KHR_texture_transform.rotation||0),u.set("khr_scale",f.KHR_texture_transform.scale||[1,1])),u.doubleSided=!(!a.doubleSided&&!c.doubleSided),u.once("complete",this.Tt),u}C(t,e){const r={type:t.type?Mr(t.type):"uint8",format:t.format?Or(t.format):"rgba",flipY:!!t.flipY},s=t.image;if(e.push(s),s.array?r.data=s.array:s.mipmap&&(r.mipmap=s.mipmap),!r.data&&!r.mipmap)return null;if(r.width=s.width,r.height=s.height,r.mipmap&&(r.width<4||r.height<4))return null;const i=t.sampler||t.texture&&t.texture.sampler;return i&&(i.magFilter&&(r.mag=vr(i.magFilter)),i.minFilter&&(r.min=Tr(i.minFilter)),i.wrapS&&(r.wrapS=_r(i.wrapS)),i.wrapT&&(r.wrapT=_r(i.wrapT))),new n.reshader.Texture2D(r,this.vt)}_t({target:t}){const e=t.Ne,n=this.ht[e];if(n.count--,!n.count){const t=n.meshes;this.ut[e]=t,delete this.ht[e];const r=t.we;delete t.we,r(null,{mesh:n.meshes,id:e})}}Ce(){return Ur}Re(t){return this.rt.Re(t)}_pointToPrj(t){const e=this.getMap();return e.getGLZoom?e._pointToPrj(t,e.getGLZoom()):e._pointToPrjAtRes(t,e.getGLRes())}_prjToPoint(t){const e=this.getMap();return e.getGLZoom?e._prjToPoint(t,e.getGLZoom()):e._prjToPointAtRes(t,e.getGLRes(),qr)}fe(t){return"Y"===t?Ir:"X"===t?Sr:Fr}pick(t,e,n=3){const r=this.rt;if(!r||!r.options.picking)return[];if(!this.pickingFBO||!this.picking)return[];const s=[],i=this.Et(),o=this.ke(this.picking,i,this.bt,t,e,n);o&&s.push(o);const a=this.ke(this.picking,i,this.yt,t,e,n);a&&s.push(a);const c=this.Jt(),h=this.ke(this.Pe,c,this.gt,t,e,n);return h&&s.push(h),s}ke(t,e,n,r,s,i){if(!n.getMeshes().length)return null;const o=this.rt,a=this.getMap();t.render(n.getMeshes().filter(t=>!t.bloom),e,!0);let c={};t.getRenderedMeshes().length&&(c=t.pick(r,s,i,e,{viewMatrix:a.viewMatrix,projMatrix:a.projMatrix,returnPoint:o.options.pickingPoint}));const{meshId:h,pickingId:u,point:l,coordinate:f}=c,d=(0===h||h)&&t.getMeshAt(h);if(!d||!d.geometry)return null;const m=d.properties;l&&l.length&&(l[0]=Math.round(1e5*l[0])/1e5,l[1]=Math.round(1e5*l[1])/1e5,l[2]=Math.round(1e5*l[2])/1e5);const p={batchId:u};if(o.options.debug&&(p.debugInfo=m),m&&m.batchTable){const{batchTable:t,batchTableBin:e,count:n}=m,r=u;for(const s in t)void 0!==t[s].byteOffset?p[s]=Pn(t[s],e,n,r):p[s]=t[s][r]}return{service:d.properties.serviceIndex,data:p,point:l,coordinate:f}}Nt(t){let e=new Set;for(let n=0,r=t.length;n<r;n++){const r=t[n].data.node;this.Ct(r)&&e.add(r.zt)}e=Array.from(e),e.sort();const n=new Map,r=e.length;for(let t=0;t<r;t++)n.set(e[t],t);return n}highlight(t){this.Ut=t;const e=this.rt.getRenderer();this.Ft=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelAllHighlight(){this.Ut=null;const t=this.rt.getRenderer();this.Ft=t.getFrameTimestamp(),t.setToRedraw(!0)}showOnly(t){this.Dt=t;const e=this.rt.getRenderer();this.jt=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelShowOnly(){this.Dt=null;const t=this.rt.getRenderer();this.jt=t.getFrameTimestamp(),t.setToRedraw(!0)}Le(){if(!this.St)return[];const t={},e=[];for(const n in this.St){const r=this.St[n];if(r)for(let n=0;n<r.length;n++){const s=r[n],i=s&&s.geometry;if(!s||!i)continue;const o=s.properties.serviceIndex;t[o]||(t[o]=new Set);const a=i.properties.batchIdData;if(a)for(let n=0;n<a.length;n++)t[o].has(a[n])||(e.push({id:a[n],service:o}),t[o].add(a[n]))}}return e}hasIBL(){const t=this.getMap().getLightManager();return!!(t&&t.getAmbientResource())}}function hs(t){for(let e=0;e<t.length;e++)t[e]&&(t[e].array&&(t[e].array=null),t[e].mipmap&&(t[e].mipmap=null),t[e].indices&&(t[e].indices=null))}const us=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("unable to locate global object")},ls=us(),fs=ls.gl_trans__coders=ls.gl_trans__coders||{};function ds(t,e){if(e)for(let n=0;n<e.length;n++){t[e[n].id||e[n].index]=e[n]}}fs.inject=function(t){const e=t.toString(),n=e.indexOf("{")+1,r=e.substring(0,n),s=ls.gl_trans__coders=ls.gl_trans__coders||{};let i=`${r}\n const _____getGlobal = ${us.toString()};\n const g___lobals = _____getGlobal()\n const tran_____scoders = g___lobals['gl_trans__coders'] = g___lobals['gl_trans__coders'] || {};`;for(const t in s)"inject"!==t&&"getTranscoder"!==t&&"registerTranscoder"!==t&&(i+='tran_____scoders["'+t+'"] ='+s[t].toString()+"\n;");return i+="\n"+e.substring(r.length),i},fs.registerTranscoder=function(t,e){fs[t]=e},fs.getTranscoder=function(t){return fs[t]};const ms=[];class ps{constructor(t,e,n,r,s){this.rt=r,this.Be=t,this.Rt=e,this.Ue=s,this.Fe=n.version,t.indexOf("i3s:tileset:")<0?(this.Fe<=1.6?this.De="root":this.De=0,n.version=this.Fe):(this.De=t.substring("i3s:tileset:".length),this.Fe>1.6&&(this.De=parseInt(this.De))),this.Be=t,this.je=n}load(){const t=this.je,e=t.layerScene.baseUrl;if(this.Fe<=1.6)return t[this.De]&&t[this.De].lodSelection?(this.ze=t[this.De],this.He()):new Promise(n=>{let r=e+"/nodes/"+this.De;t.layerScene.eslpk&&(r+="/3dNodeIndexDocument.json"),this.Ue(this.Rt,r,()=>{this.ze=t[this.De],n(this.He())})});if(this.Fe>=1.7){if(t[this.De])return this.ze=t[this.De],this.He();const n=Math.floor(this.De/t.nodesPerPage);return new Promise(r=>{let s=e+"/nodepages/"+n;t.layerScene.eslpk&&(s+=".json"),this.Ue(this.Rt,s,()=>{this.ze=t[this.De],r(this.He())})})}return null}getTileset(){return this.Ge}getChildrenURL(){return this.qe}He(){const t=this.je,e=t.layerScene.baseUrl,n=this.ze.children,r=[],s={};if(n)for(let i=0;i<n.length;i++)if(this.Fe<=1.6){const o=n[i].id;if(t[o])continue;const a=o;s[a]||(s[a]=new Promise(n=>{let r=e+"/nodes/"+a;t.layerScene.eslpk&&(r+="/3dNodeIndexDocument.json"),this.Ue(this.Rt,r,()=>{n()})}),r.push(s[a]))}else{const o=n[i];if(t[o])continue;const a=Math.floor(o/t.nodesPerPage);s[a]||(s[a]=new Promise(n=>{let r=e+"/nodepages/"+a;t.layerScene.eslpk&&(r+=".json"),this.Ue(this.Rt,r,()=>{n()})}),r.push(s[a]))}return r.length?Promise.all(r).then(()=>this.Ve()):this.Ve()}Ve(){return Promise.resolve(this.$e())}Xe(t){ds(this.je,t)}$e(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.Je(this.ze,!0)}}Je(t){const e=this.rt.getRenderer(),n=this.je.projection,r=!n||n&&4326===n.wkid,s=this.Fe,i=this.je,o=t,a=o.obb,c=o.mbs,h={};let u;if(c)u=Ut([],c[0],c[1],c[2]),r||(u=e.Ke(u,u)),u=bs([],u[0],u[1],u[2]),h.sphere=[...u,c[3]];else if(a){u=Ut([],a.center[0],a.center[1],a.center[2]),r||(u=e.Ke(u,u)),u=bs([],u[0],u[1],u[2]);const t=function(t,e,n){const r=function(t,e){var n=e[0],r=e[1],s=e[2],i=e[3],o=n+n,a=r+r,c=s+s,h=n*o,u=r*o,l=r*a,f=s*o,d=s*a,m=s*c,p=i*o,b=i*a,g=i*c;return t[0]=1-l-m,t[3]=u-g,t[6]=f+b,t[1]=u+g,t[4]=1-h-m,t[7]=d-p,t[2]=f-b,t[5]=d+p,t[8]=1-h-l,t}([],n);return r[0]=r[0]*e[0],r[1]=r[1]*e[0],r[2]=r[2]*e[0],r[3]=r[3]*e[1],r[4]=r[4]*e[1],r[5]=r[5]*e[1],r[6]=r[6]*e[2],r[7]=r[7]*e[2],r[8]=r[8]*e[2],[...t,...r]}(u,a.halfSize,a.quaternion),n=t[3]+t[6]+t[9],s=t[4]+t[7]+t[10],i=t[5]+t[8]+t[11];Ut(ms,n,s,i);const o=Xt(ms);h.sphere=[...u,o]}let l=1/0,f=0;if(o.mbs?f=o.mbs[3]:o.obb&&(f=Math.max(Math.max(o.obb.halfSize[0],o.obb.halfSize[1]),o.obb.halfSize[2])),void 0!==o.lodThreshold)if("maxScreenThresholdSQ"===i.lodSelectionMetricType){l=f/(Math.sqrt(o.lodThreshold)/(.25*Math.PI))}else console.error("Unsupported lodSelectionMetricType in Layer");else if(void 0!==o.lodSelection)for(let t=0;t<o.lodSelection.length;t++)"maxScreenThreshold"===o.lodSelection[t].metricType&&(l=f/o.lodSelection[t].maxError);(l===1/0||isNaN(l))&&(l=1e5);const d=16*l,m=St([]),p=o.children;let b;if(p){b=[];const t=this.je;for(let e=0;e<p.length;e++){const n=s<=1.6?p[e].id:p[e];if(!t[n]){b=null;break}b.push(this.Je(t[n]))}}const g={refine:"REPLACE",boundingVolume:h,transform:m,geometricError:d};return s<=1.6?t.lodSelection?t.geometryData&&(g.content={uri:"i3s:mesh:"+(t.id||t.index)}):g.content={uri:"i3s:tileset:"+(t.id||t.index)}:p&&p.length&&!b?g.content={uri:"i3s:tileset:"+(t.id||t.index)}:o.mesh&&(g.content={uri:"i3s:mesh:"+(t.id||t.index)}),b&&b.length&&(g.children=b),g}getJSON(){return this.ze}}function bs(t,e,n,r){return un(t,ut(e),ut(n),r)}const gs=!!fs.ktx2,ys=n.mat4.identity([]),ws=(()=>{try{if("object"==typeof WebAssembly&&"function"==typeof WebAssembly.instantiate){const t=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));if(t instanceof WebAssembly.Module)return new WebAssembly.Instance(t)instanceof WebAssembly.Instance}}catch(t){}return!1})();function vs(t){return t.indexOf("i3s:mesh")>=0}const Ts="i3s:mesh:".length;function _s(t,e,n,r,s){const i=e.layerScene.eslpk,o=function(t,e){const n=e.substring(Ts);return t>=1.7?parseInt(n):n}(e.version,t),a=e[o],c=e.layerScene.baseUrl,h=[];let u=!1;const l=ys;let f,d;if(e.version<=1.6){if(!a.geometryData)return null;const t=a.geometryData.length;if(!t)return null;let n=c+`/nodes/${a.id}/`+a.geometryData[t-1].href;i&&(n+=".bin");const r={geometry:{url:n,info:e.layerScene.store.defaultGeometrySchema}};let s=a.textureData&&a.textureData[0]&&a.textureData[0].href;if(s){const t=e.layerScene.store.textureEncoding[0];let n;n="image/jpeg"===t?"jpg":"png",i&&(s+="."+n);const o={pbrMetallicRoughness:{baseColorTexture:{url:c+`/nodes/${a.id}/`+s,factor:1,format:n,mimeType:t},metallicFactor:0}};r.material=o}h.push(r)}else{f=a.mesh.geometry,d=a.mesh.material;const t=e.layerScene.geometryDefinitions[f.definition],{geometryBuffers:o}=t;u=r&&2===o.length;const l=fs.draco&&u?o[1]:o[0],m=fs.draco&&u?1:0;let p=c+`/nodes/${f.resource}/geometries/`+m;i&&(p+=".bin");const b={geometry:{url:p,info:l}};if(s&&ws&&u&&!fs.draco)throw new Error("Must import @maptalks/transcoder.draco to load i3s draco compressed geometry");const g=e.layerScene.materialDefinitions,y=e.layerScene.textureSetDefinitions;let w,v=0;if(d&&(v=g[d.definition]),g){w=function(t,e,n,r,s,i){const o=JSON.parse(JSON.stringify(t));return function t(e,n,r,s,i,o){for(const a in e)if(e[a]&&e[a].textureSetDefinitionId>=0){const t=n[e[a].textureSetDefinitionId],c="images/"+t.formats[0].format,h=Ms(t.formats,i),u={url:r+`/nodes/${s}/textures/${h.name}`,factor:void 0===e[a].factor?1:e[a].factor,format:h.format,mimeType:c};if(o){let t="";switch(h.format){case"dds":t="bin.dds";break;case"jpg":case"png":t=h.format}u.url+="."+t}e[a]=u}else ct(e[a])&&t(e[a],n,r,s,i,o)}(o,e,n,r,s,i),o}(v,y,c,d.resource,n,e.layerScene.eslpk)}else w={pbrMetallicRoughness:{metallicFactor:0}};b.material=w,h.push(b)}return{dracoCompression:u,meshes:h,nodeIndex:o,center:a.obb&&a.obb.center||a.mbs&&[a.mbs[0],a.mbs[1],a.mbs[2]],transform:l}}function Ms(t,e){for(let n=0;n<=t.length;n++){const r=t[n].format;if("dds"===r&&e.hasExtension("WEBGL_compressed_texture_s3tc"))return t[n];if("jpg"===r||"png"===r)return t[n];if("ktx2"===r&&gs)return t[n]}return null}const Os=new s.Coordinate(0,0),xs=new s.Coordinate(0,0),As=new Set,Is=[],Ss=new class{constructor(t,e){this.max=t,this.currentSize=0,this.data=new Map,this.onRemove=e}reset(t){if(this.data){const e=this.data.keys();for(const n of e){const e=this.data.get(n);t&&t!==e.renderer||this.Qe(n,e)}}return t||(this.data=new Map,this.currentSize=0),this}clear(t){this.reset(t)}add(t,e){if(!e)return this;if(e.node&&e.node.memorySize&&(this.currentSize+=e.node.memorySize),this.has(t)){const n=this.data.get(t);n&&n.node&&n.node.memorySize&&(this.currentSize-=n.node.memorySize),this.data.delete(t),this.data.set(t,e)}else this.data.set(t,e);return this}shrink(){if(this.currentSize>this.max){let t=!1;const e=this.data.keys();let n=e.next();for(;this.currentSize>this.max&&void 0!==n.value;){!t&&this.data.get(n.value).current&&(t=!0,console.warn(`current maxGPUMemory(${this.max/1024/1024}) for Geo3DTilesLayer is not enough, one or more current tiles will be discarded.`));const r=this.getAndRemove(n.value);r&&this.onRemove(r),n=e.next()}}}has(t){return this.data.has(t)}keys(){const t=new Array(this.data.size);let e=0;const n=this.data.keys();for(const r of n)t[e++]=r;return t}getAndRemove(t){if(!this.has(t))return null;const e=this.data.get(t);return e.node&&e.node.memorySize&&(this.currentSize-=e.node.memorySize),this.data.delete(t),e}get(t){if(!this.has(t))return null;const e=this.data.get(t);return this.data.delete(t),this.data.set(t,e),e}remove(t){if(!this.has(t))return this;const e=this.data.get(t);return this.Qe(t,e),this}Qe(t,e){e.node&&e.node.memorySize&&(this.currentSize-=e.node.memorySize),this.data.delete(t),this.onRemove(e)}setMaxSize(t){return this.max=t,this.shrink(),this}getMemorySize(){let t=0;const e=this.data.values();for(const n of e){const e=n&&n.node;e&&e.memorySize&&(t+=e.memorySize)}return t}markAll(t,e){const n=this.data.values();for(const r of n)t&&r.renderer!==t||(r.current=e)}}(1024*(s.Browser.mobile?32:1024)*1024,t=>{const e=t.renderer;delete t.renderer,e.deleteTile(t)});let Es=0;class Ns extends(n.MaskRendererMixin(s.renderer.CanvasRenderer)){constructor(t){super(t);const e=1024*t.options.maxGPUMemory*1024;e>Ss.max&&Ss.setMaxSize(e),this.tileCache=Ss,Es++,this.prepareWorker(),this.tilesLoading={},this.Ze={},this.Ye=[],this.Ue=this.We.bind(this)}getAnalysisMeshes(){if(!this.painter)return Is;const t=this.painter.getPaintedMeshes();if(!t)return Is;const e=[],{b3dmMeshes:n,pntsMeshes:r,i3dmMeshes:s}=t;return n.length&&Tt(e,n),r.length&&Tt(e,r),s.length&&Tt(e,s),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.Ye.length||super.needToRedraw())}getFrameTimestamp(){return this.tn}drawOnInteracting(t,e,n){this.draw(e,n)}draw(t,e){this.tn=t;const n=this.prepareCanvas();if(n&&!n.intersects(this.canvasExtent2D))return void this.completeRender();const{root:r,tiles:s}=this.layer.getTiles(),i=s.length;if(!s||!i)return void this.completeRender();this.nn(),this.rn();const{selectedTiles:o,leaves:a,requests:c}=this.sn(r,s);c.length&&this.loadTiles(c),this.in(o,a,e),this.an(),c.length||this.completeRender()}sn(t,e){const n=this.layer.getRootTiles();let r=[];this.cn();let s=0;const i=this.hn(),o={};let a=!1,c=!1;for(let t=0;t<e.length;t++){const i=e[t],h=i.node;if(o[h.id])continue;const u=n[h.Rt];o[h.id]=1;let l=!1;const f=this.getCachedTile(h.id);if(this.un(h.id)?(s++,l=c=!0,this.tilesLoading[h.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=c=!0),(!i.node.ln||u.isS3M||!i.node.children||i.node.ln<=500)&&(a=!0,i.selected=!0,i.data=f)):this.painter.has(h)||(l=c=!0,r.push(h)),!l)continue;if(this.dn(i))a=!0;else{this.mn(i).length&&(a=!0)}}let h=[],u={};if(a&&({selectedTiles:h,leaves:u}=this.pn(t)),r.length>1&&(r.sort(Cs),i)){const t=i-s;r=t>0?r.slice(0,t):[]}return{loading:c,requests:r,selectedTiles:h,leaves:u}}pn(t){const e=[],n={};let r;const s=[t],i=[];for(;s.length>0||i.length>0;){if(i.length>0){const t=i[i.length-1];if(t.bn===s.length){i.pop(),t===r&&(t.leave=!0,n[t.node.id]=1),e.push(t);continue}}const t=s.pop(),o=t.children;if(t.selected)if("add"===t.node.refine)n[t.node.id]=1,t.selectionDepth=i.length,e.push(t);else{if(t.selectionDepth=i.length,r=t,0===o.length){t.leave=!0,n[t.node.id]=1,e.push(t);continue}i.push(t),t.bn=s.length}for(let t=0;t<o.length;t++)s.push(o[t])}return{selectedTiles:e,leaves:n}}dn(t){if(!t.parent)return null;let e=t.parent;for(;e&&e.level>=0;){const t=e.node.id;if(this.tileCache.has(t))return e.selected=!0,e.data=this.tileCache.get(t),e;e=e.parent}return null}mn(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const n=t.zt+1,r=[t.node];for(;r.length>0;){const s=r.pop().children;for(let i=0,o=s.length;i<o;i++){if((!s[i].content||!s[i].content.url)&&s[i].children&&s[i].children.length){r.push(s[i]);continue}const o=s[i].id;if(this.tileCache.has(o)){const n=this.layer.gn(s[i],t);n.selected=!0,n.data=this.tileCache.get(o),t.children.push(n),e.push(n)}else s[i].zt<=n&&r.push(s[i])}}return e}in(t,e,n){this.tileCache.markAll(this,!1);for(let e=0,n=t.length;e<n;e++){const n=t[e].data;n.current=!0,n.renderer=this,this.tileCache.add(t[e].node.id,n)}this.tileCache.shrink();const r={tiles:t,leaves:e};this.onDrawTileStart(r);const s=this.painter.paint(t,e,n);this.onDrawTileEnd(r),s&&this.layer.fire("canvasisdirty",{renderCount:s})}onDrawTileStart(){}onDrawTileEnd(){}loadTiles(t){for(let e=0,n=t.length;e<n;e++){const n=t[e];this.tilesLoading[n.id]={current:!0,node:n},this.loadTile(n)}}loadTile(t){let e=t.content.url;if(wt(e)){const n=vt(e);return this.yn(e,n,t),null}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const n=t.Rt,r=this.wn[n];return new ps(e,n,r,this.layer,this.Ue).load().then(n=>{this.onTilesetLoad(n,t,e)})}return t&&xt(e)&&!vs(e)&&(e=t.baseUrl+e),this.yn(e,null,t),null}yn(t,e,r){let s=this.o;s||(s=n.reshader.Util.getSupportedFormats(this.gl.gl||this.gl),this.o=s);const i=this.layer.Pt(r.Rt);i.isSuperMapiServer&&(t=function(t,e){const n=t.substring(e.length).split("/"),r=[];for(let t=0;t<n.length;t++)r.push(encodeURIComponent(n[t]));return e+r.join("/")}(t,r.baseUrl));const o={url:this.layer.getTileUrl(t,r.baseUrl,this.layer.vn[r.Rt]),arraybuffer:e,rootIdx:r.Rt,upAxis:r.de,transform:r.matrix,supportedFormats:s};if(vs(t)){const e=this.wn[r.Rt];if(o.projection=e.projection,o.i3sInfo=_s(t,e,this.regl,this.layer.options.enableI3SCompressedGeometry,this.layer.options.forceI3SCompressedGeometry),!o.i3sInfo)return void this.onTileError({status:404},r,t)}o.service=ot({},i),i.offset&&delete o.service.offset,o.referrer=window&&window.location.href,this.workerConn.loadTile(this.layer.getId(),o,(e,n)=>{if(e)return void this.onTileError(e,r,t);const{magic:s}=n;"b3dm"===s||"pnts"===s||"i3dm"===s||"cmpt"===s||"gltf"===s?(this.Ye.push({data:n,tile:r}),i.debugShowBoundingVolume&&this.painter.Te(r)):this.onTilesetLoad(n,r,t)})}rn(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let n=0;for(;this.Ye.length&&(n<e||!t.isInteracting());){const{data:t,tile:e}=this.Ye.shift(),{magic:r}=t;"b3dm"===r||"gltf"===r?this.painter.createB3DMMesh(t,e.id,e,(n,{mesh:r})=>{this.Tn(t,e,n,r)}):"pnts"===r?this.painter.createPntsMesh(t,e.id,e,(n,{mesh:r})=>{this.Tn(t,e,n,r)}):"i3dm"===r?this.painter.createI3DMMesh(t,e.id,e,(n,{mesh:r})=>{this.Tn(t,e,n,r)}):"cmpt"===r&&this.painter.createCMPTMesh(t,e.id,e,(n,{mesh:r})=>{this.Tn(t,e,n,r)}),n++}}Tn(t,e,n,r){if(n)this.onTileError(n,e);else{const n=this._n(r);e.memorySize=n,this.onTileLoad(t,e)}}_n(t){let e=0;if(Array.isArray(t))for(let n=0;n<t.length;n++)t[n]&&(e+=this._n(t[n]));else t&&(e+=t.getMemorySize());return e}onTileLoad(t,e){this.layer&&(delete this.tilesLoading[e.id],this.layer.onTileLoad(t,e),this.Mn(e),this.setToRedraw(),this.layer.fire("tileload",{node:e}))}onTilesetLoad(t,e,n){this.layer&&(this.layer.Ae=t.extensions&&t.extensions["s3m:VertexCompressionType"],t.capabilities||t.layers&&t.layers[0]&&t.layers[0].capabilities?this.On(t,e,n):(delete this.tilesLoading[e.id],this.layer.onTilesetLoad(t,e,n)))}onTileError(t,e,n){if(!this.layer)return;const r=n||e.content.url,s=t&&t.message||t;As.has(s)||(console.warn("failed to load 3d tile: "+r),console.warn(t),As.add(s)),delete this.tilesLoading[e.id],this.xn(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}xn(t,e){const n={loadTime:s.Util.now(),current:!0,error:e,node:t};n.renderer=this,this.tileCache.add(t.id,n)}Mn(t){const e={loadTime:s.Util.now(),current:!0,node:t};e.renderer=this,this.tileCache.add(t.id,e)}abortTileLoading(t){if(!t||!this.workerConn)return;const e=t.node.content.url;this.workerConn.abortTileLoading(this.layer.getId(),e),delete this.Ze[e]}cn(){if(this.tilesLoading)for(const t in this.tilesLoading)this.tilesLoading[t].current=!1}deleteTile(t){this.painter.deleteTile(t)}createContext(){const t=this.layer,e=t.options.glOptions||{alpha:!0,depth:!0,stencil:!0,preserveDrawingBuffer:!0,antialias:t.options.antialias},r=this.canvas.gl&&this.canvas.gl.wrap;r?(this.gl=this.canvas.gl.wrap(),this.regl=this.canvas.gl.regl):(this.glOptions=e,this.gl=this.An(this.canvas,e)),this.regl=this.regl||n.createREGL({gl:this.gl,attributes:e,extensions:["OES_element_index_uint"],optionalExtensions:t.options.optionalExtensions||[]}),r&&(this.canvas.pickingFBO=this.canvas.pickingFBO||this.regl.framebuffer(this.canvas.width,this.canvas.height)),this.pickingFBO=this.canvas.pickingFBO||this.regl.framebuffer(this.canvas.width,this.canvas.height),this.painter=new cs(this.regl,t),this.layer.In(),this.layer.fire("contextcreate",{regl:this.regl})}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new $e("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let n=this.layer.options||{};n=ot({},n),delete n.offset;const r=t.options.spatialReference;n.projection=r&&r.coordType||r&&r.projection||t.getSpatialReference().getProjection().code;const s=this.layer.getId();e.addLayer(s,n,t=>{if(t)throw t;this.layer&&(this.ready=!0,this.layer.fire("workerready"))})}onRemove(){this.painter&&this.painter.remove(),this.pickingFBO&&(this.canvas.pickingFBO||this.pickingFBO.destroy(),delete this.pickingFBO),this.workerConn&&(this.workerConn.removeLayer(this.layer.getId(),t=>{if(t)throw t}),this.workerConn.remove(),delete this.workerConn),Es--,Es||Ss.reset(),this.clear(),delete this.tileCache,super.onRemove()}clear(){this.an(!0),this.tileCache.reset(this),this.tilesLoading={},super.clear()}clearCanvas(){this.regl&&this.regl.clear({color:[0,0,0,0],depth:1,stencil:0}),super.clearCanvas()}getTileOpacity(){return 1}getStencilValue(){return 0}an(t){this.Sn||(this.Sn=Date.now());const e=Date.now();if(!t&&e-this.Sn<this.layer.options.retireInterval)return;this.Sn=e;const n=[];for(const e in this.tilesLoading){const r=this.tilesLoading[e];!t&&r.current||(n.push(e),this.abortTileLoading(r))}for(let t=0;t<n.length;t++)delete this.tilesLoading[n[t]]}hn(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}An(t,e){const n=["webgl","experimental-webgl"];let r=null;for(let s=0;s<n.length;++s){try{r=t.getContext(n[s],e)}catch(t){}if(r)break}return r}un(t){return!!this.tilesLoading[t]}getI3DMMeshes(){return this.painter.getI3DMMeshes()}getPNTSMeshes(){return this.painter.getPNTSMeshes()}getB3DMMeshes(){return this.painter.getB3DMMeshes()}readBatchData(t,e,n){return Nn(t,e,0,n)}nn(){if(!this.En)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const n=[];for(const r in this.En){const s=this.En[r];if("pending"===s.status)continue;s.status="pending";const i=s.rootIdx,o=At(this.layer.Pt(i).fetchOptions);if(n.push(ye.getJSON(r,o).then(t=>{delete this.En[r];const e=this.wn[i];if(e){t.nodes?ds(e,t.nodes):(e[t.id]=t,ds(e,t.children));for(let t=0;t<s.length;t++)s[t]();this.setToRedraw()}else this.setToRedraw()})),e++,e>=t)break}n.length&&Promise.all(n)}We(t,e,n){this.En||(this.En={}),this.En[e]=this.En[e]||[],this.En[e].rootIdx=t,this.En[e].push(n),this.setToRedraw()}On(t,e,n){this.wn||(this.wn=[]);const r=e.Rt;this.wn[r]||(this.wn[r]={});const s=this.wn[r],i=this.layer.Pt(r);t.layers&&(t=t.layers[0],"/"!==n[n.length-1]&&(n+="/"),n+="layers/0"),s.version=+(i.i3sVersion||t.store.version),!t.spatialReference||t.spatialReference.wkid&&4326===t.spatialReference.wkid||console.warn("i3s has a spatialReference other than 4326.",t.spatialReference),s.projection=t.spatialReference,function(t,e,n,r,s,i,o){if(!i.layerScene){i.layerScene=e,i.nodesPerPage=e.nodePages&&e.nodePages.nodesPerPage||64,i.lodSelectionMetricType=e.nodePages&&e.nodePages.lodSelectionMetricType;let t=s;i.layerScene.eslpk=t.indexOf("3dSceneLayer.json")>=0;if(t.endsWith(".json")){const e=s.lastIndexOf("/");t=e<0?"./":s.substring(0,e)}i.layerScene.baseUrl=function(t){return t.split("?")[0]}(t)}return new ps(s,n,i,t,o).load()}(this.layer,t,r,0,n,s,this.Ue).then(t=>{this.onTilesetLoad(t,e,n)})}pick(t,e,n){if(!this.painter)return[];const r=this.pickingFBO,{width:s,height:i}=this.canvas;return!this.pickingFBO||r.width===s&&r.height===i||r.resize(s,i),this.painter.pick(t,e,n&&n.tolerance)}highlight(t){if(this.Ut||(this.Ut=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const n=t[e].service||0;let r=this.Ut[n];r||(r=this.Ut[n]=new Map),r.set(t[e].id,t[e])}else{const e=t.service||0;let n=this.Ut[e];n||(n=this.Ut[e]=new Map),n.set(t.id,t)}this.painter.highlight(this.Ut)}cancelHighlight(t,e){if(!this.Ut)return;const n=this.Ut[t];if(n){if(Array.isArray(e))for(let t=0;t<e.length;t++)n.delete(e[t]);else n.delete(e);n.size||(this.Ut[t]=null),this.painter.highlight(this.Ut)}}cancelAllHighlight(){delete this.Ut,this.painter.cancelAllHighlight()}showOnly(t){if(this.Dt||(this.Dt=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const n=t[e].service||0;let r=this.Dt[n];r||(r=this.Dt[n]=new Map),r.set(t[e].id,t[e])}else{const e=t.service||0;let n=this.Dt[e];n||(n=this.Dt[e]=new Map),n.set(t.id,t)}this.painter.showOnly(this.Dt)}cancelShowOnly(){delete this.Dt,this.painter.cancelShowOnly()}Le(){return this.painter?this.painter.Le():[]}Ke(t,e){const n=this.getMap();if("identity"===n.getProjection().code.toLowerCase()){const n=this.Nn();return Os.x=e[0],Os.y=e[1],n.unproject(Os,xs),t[0]=xs.x,t[1]=xs.y,t}return Os.x=e[0],Os.y=e[1],n.getProjection().unproject(Os,xs),t[0]=xs.x,t[1]=xs.y,t}Cn(t,e){const n=this.Nn();return Os.x=e[0],Os.y=e[1],n.project(Os,xs),t[0]=xs.x,t[1]=xs.y,t}Pn(t,e){const n=this.Nn();return Os.x=e[0],Os.y=e[1],n.unproject(Os,xs),t[0]=xs.x,t[1]=xs.y,t}Nn(){const t=this.getMap().options.spatialReference.coordType;if(!t)throw new Error("Missing coordType in map spatialReference.");return this.Rn||(this.Rn=s.SpatialReference.getProjectionInstance(t)),this.Rn}}function Cs(t,e){return t.ne-e.ne}function Ps(t,e,n){return t[0]=e[n],t[1]=e[n+3],t[2]=e[n+6],t}function Rs(t,e,n){return Math.sqrt(function(t,e,n){const r=Dt(ks,n,t),s=Ps(Ls,e,0),i=Ps(Bs,e,1),o=Ps(Us,e,2),a=Xt(s),c=Xt(i),h=Xt(o);Ht(s,s),Ht(i,i),Ht(o,o);const u=Fs;u[0]=Gt(r,s),u[1]=Gt(r,i),u[2]=Gt(r,o);let l,f=0;u[0]<-a?(l=u[0]+a,f+=l*l):u[0]>a&&(l=u[0]-a,f+=l*l);u[1]<-c?(l=u[1]+c,f+=l*l):u[1]>c&&(l=u[1]-c,f+=l*l);u[2]<-h?(l=u[2]+h,f+=l*l):u[2]>h&&(l=u[2]-h,f+=l*l);return f}(t,e,n))}const ks=[],Ls=[],Bs=[],Us=[],Fs=[];const Ds=2*Math.PI;class js{constructor(t,e,n,r){this.west=t,this.south=e,this.east=n,this.north=r}static contains(t,e){let n=e[0];const r=e[1],s=t.west;let i=t.east;return i<s&&(i+=Ds,n<0&&(n+=Ds)),(n>s||On(n,s,1e-14))&&(n<i||On(n,i,1e-14))&&r>=t.south&&r<=t.north}static southwest(t,e){return e[0]=t.west,e[1]=t.south,e[2]=0,e}static northeast(t,e){return e[0]=t.east,e[1]=t.north,e[2]=0,e}static southeast(t,e){return e[0]=t.east,e[1]=t.south,e[2]=0,e}static northwest(t,e){return e[0]=t.west,e[1]=t.north,e[2]=0,e}}const zs=[0,0,1];function Hs(t,e){return un(e,t[0],t[1],t[2])}class Gs{constructor(t,e){this.normal=n.vec3.copy([],t),this.distance=e}static fromPointNormal(t,e,r){const s=-n.vec3.dot(e,t);return n.vec3.copy(r.normal,e),r.distance=s,r}}const qs=[],Vs=[],$s=[],Xs=[],Js=[],Ks=[],Qs=[],Zs=[],Ys=[],Ws=[],ti=new Gs([1,0,0],0),ei=[];class ni{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new js(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){let r=0;if(!js.contains(this.rectangle,e)){const e=this.southwestCornerCartesian,s=this.northeastCornerCartesian,i=this.westNormal,o=this.southNormal,a=this.eastNormal,c=this.northNormal,h=n.vec3.subtract(ei,t,e),u=n.vec3.dot(h,i),l=n.vec3.dot(h,o),f=n.vec3.subtract(ei,t,s),d=n.vec3.dot(f,a),m=n.vec3.dot(f,c);u>0?r+=u*u:d>0&&(r+=d*d),l>0?r+=l*l:m>0&&(r+=m*m)}const s=e[2],i=this.minimumHeight,o=this.maximumHeight;if(s>o){const t=s-o;r+=t*t}else if(s<i){const t=i-s;r+=t*t}return Math.sqrt(r)}computeBox(t){const e=this;Hs(js.southwest(t,Vs),e.southwestCornerCartesian),Hs(js.northeast(t,Vs),e.northeastCornerCartesian),qs[0]=t.west,qs[1]=.5*(t.south+t.north),qs[2]=0;const r=Hs(qs,$s),s=n.vec3.cross(Js,r,zs);n.vec3.normalize(e.westNormal,s),qs[0]=t.east;const i=Hs(qs,Zs),o=n.vec3.cross(Js,zs,i);n.vec3.normalize(e.eastNormal,o);const a=n.vec3.subtract(Js,r,i),c=n.vec3.normalize(Xs,a),h=t.south;let u;if(h>0){qs[0]=.5*(t.west+t.east),qs[1]=h;const r=Hs(qs,Ys);n.vec3.copy(Ws,c);const s=Gs.fromPointNormal(e.southwestCornerCartesian,e.westNormal,ti);ri(Ys,Ws,s,e.southwestCornerCartesian),u=Tn(r,Ks)}else u=_n(js.southeast(t,Vs),Ks);const l=n.vec3.cross(Qs,u,a);n.vec3.normalize(e.southNormal,l);const f=t.north;let d;if(f<0){qs[0]=.5*(t.west+t.east),qs[1]=f;const r=Hs(qs,Ys);n.vec3.scale(Ws,c,-1);const s=Gs.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,ti);ri(Ys,Ws,s,e.northeastCornerCartesian),d=Tn(r,Ks)}else d=_n(js.northwest(t,Vs),Ks);const m=n.vec3.cross(Qs,a,d);n.vec3.normalize(e.northNormal,m)}}function ri(t,e,r,s){const i=t,o=e,a=r.normal,c=n.vec3.dot(a,o);if(Math.abs(c)<1e-15)return;const h=(-r.distance-n.vec3.dot(a,i))/c;return h<0?void 0:(s=n.vec3.scale(s,o,h),n.vec3.add(s,i,s))}const si={"maxGPUMemory":s.Browser.mobile?32:1536,"retireInterval":2e3,"loadingLimitOnInteracting":5,"loadingLimit":0,"renderer":"gl","forceRenderOnZooming":!0,"forceRenderOnRotating":!0,"forceRenderOnMoving":!0,"debug":!1,"meshLimitPerFrame":1,"i3sNodepageLimitPerFrame":1,"enableI3SCompressedGeometry":!0,"forceI3SCompressedGeometry":!0,"picking":!0,"pickingPoint":!0,"geometryEvents":!1,"antialias":!1,"optionalExtensions":["ANGLE_instanced_arrays","OES_element_index_uint","OES_standard_derivatives","OES_vertex_array_object","OES_texture_half_float","OES_texture_half_float_linear","OES_texture_float","OES_texture_float_linear","WEBGL_depth_texture","EXT_shader_texture_lod","WEBGL_compressed_texture_astc","WEBGL_compressed_texture_etc","WEBGL_compressed_texture_etc1","WEBGL_compressed_texture_pvrtc","WEBGL_compressed_texture_s3tc","WEBGL_compressed_texture_s3tc_srgb"],"offset":[0,0]},ii=new s.Extent(0,0,0,0),oi=[],ai=[],ci=[],hi=[],ui=[],li=new s.Coordinate(0,0),fi=new s.Point(0,0),di=[],mi=new s.Coordinate(0,0),pi=n.mat4.identity([]),bi=[0,0],gi=[1,1,1,1,-1,1,-1,-1,1,-1,1,1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1];class yi extends(n.MaskLayerMixin(s.Layer)){static fromJSON(t){return t&&"Geo3DTilesLayer"===t.type?new yi(t.id,t.options):null}constructor(t,e){super(t,e),this.kn(),this.Ze={},this._e=[]}kn(){const t=this.options.services.map(t=>t.url);this.Ln=this.Ln||{},this.vn=this.vn||[];for(let e=0;e<t.length;e++){const n=t[e];let r=this.Ln[n];void 0===r&&(r=this.Ln[n]=this.vn.length),this.vn[r]=Ti(n,r,this.options.services[e])}this.fire("rootready",{roots:this.vn.slice(0)})}showService(t){return this.updateService(t,{visible:1}),this}hideService(t){return this.updateService(t,{visible:0}),this}setToRedraw(){const t=this.getRenderer();t&&t.setToRedraw()}addService(t){this.options.services=this.options.services||[],this.options.services.push(t),this.kn();const e=this.getRenderer();return e&&e.setToRedraw(),this}updateService(t,e){if(!e)return this;const n=this.options.services;if(n&&n[t]&&ot(n[t],e),!it(e.visible)){const r=n[t].url,s=this.Ln[r];this.vn&&this.vn[s]&&(this.vn[s].visible=e.visible)}const r=this.getRenderer();return r&&r.setToRedraw(),this}removeService(t){const e=this.options.services;if(e&&e[t]){const n=e[t].url,r=this.Ln[n];this.vn[r]&&(this.vn[r]=null),delete this.Ln[n],e.splice(t,1)}const n=this.getRenderer();return n&&n.setToRedraw(),this}getTileUrl(t,e,n){const r=n&&n.service&&n.service.subdomains;if(r&&n.domainKey){const e=r.length;if(e){const s=[...t].reduce((t,e)=>t+e.charCodeAt(),0)%e;return t.replace(n.domainKey,r[s])}}return t}getExtent(t){if(!t&&0!==t){const t=new s.Extent;for(let e=0;e<this.vn.length;e++)if(this.vn[e].boundingVolume){const n=this.boundingVolumeToExtent(this.vn[e]);t._combine(n)}return t}return this.vn[t]&&this.vn[t].boundingVolume?this.boundingVolumeToExtent(this.vn[t]):null}boundingVolumeToExtent(t){const e=t.boundingVolume.Bn?pi:t.matrix,r=this.getMap(),i="identity"===r.getProjection().code.toLowerCase(),o=this.getRenderer();if(t.boundingVolume.region){const e=t.boundingVolume.region;return new s.Extent(lt(e[0]),lt(e[1]),lt(e[2]),lt(e[3]))}if(t.boundingVolume.sphere){const a=t.boundingVolume.sphere,c=bn([],n.vec3.transformMat4([],a,e));i&&o.Cn(c,c);const h=a[3],u=r.locate(c,-h,h),l=r.locate(c,h,-h);return new s.Extent(u,l)}if(t.boundingVolume.box){const a=t.boundingVolume.box,c=n.vec3.transformMat4([],a,e),h=new s.Coordinate(bn([],c));i&&o.Cn(h,h);const u=a.slice(3);n.mat3.multiply(u,n.mat3.fromMat4([],t.matrix),u);const l=n.vec3.length(u.slice(0,3)),f=n.vec3.length(u.slice(3,6)),d=n.vec3.length(u.slice(6,9)),m=Math.max(l,f,d),p=r.locate(h,-m,m),b=r.locate(h,m,-m);return new s.Extent(p,b)}return null}getRootTiles(){return this.vn}getTiles(){const t=this.getRenderer();if(!t.ready)return this.Un(),{tiles:ui};const e=this.getMap(),r=e.cameraPosition,s=e.pointAtResToDistance(r[2],0,e.getGLRes()),i=this.Fn(r);this.Dn=this.Dn||[],n.vec3.set(this.Dn,ut(i.x),ut(i.y),s),this.jn=un(this.jn||[],this.Dn[0],this.Dn[1],this.Dn[2]),this.zn=2*Math.tan(.5*ut(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const h=[];for(let e=0;e<this.vn.length;e++){const n=this.vn[e];if(!n||!n.visible)continue;let r=1/0;const s=[n],i=this.Hn(e);for(;s.length>0;){const e=s.pop();for(e.id||this.Gn(e);c.level>=e.zt;)c=c.parent;const n=this.qn(e,i,o);if(n<1){let t=c;for(;t&&!t.content;)t=t.parent;0===n&&t&&t.content&&this.Vn(h,t);if(!1===this.options.services[e.Rt].alwaysShow)continue;if(!(0===n&&e.zt<=r))continue;e.content&&(r=e.zt)}e.ne<1/0&&this.$n(e);const a=this.gn(e,c);c.children.push(a);const u=e.children,l=u&&u.length,f=a.content;if(!l&&f&&this.Vn(h,a),l){f&&"add"===e.refine&&this.Vn(h,a),c=a;const n=u[0].parent;let r=!1;for(let i=0,o=u.length;i<o;i++){if(n){const e=t.getCachedTile(u[i].id);if(e&&e.error&&404!==e.error.status)continue;r=!0}else{r=!0,u[i].parent=e,u[i].de=e.de,u[i].baseUrl=e.baseUrl;const t=u[i].content&&(u[i].content.url||u[i].content.uri);t&&(wt(t)||t.indexOf("i3s:")>=0?u[i].baseUrl=e.baseUrl:xt(t)?u[i].content.url=e.baseUrl+t:u[i].baseUrl=t.substring(0,t.lastIndexOf("/")+1))}s.push(u[i])}!r&&f&&this.Vn(h,a)}}}return{root:a,tiles:h}}Vn(t,e){const{viewerRequestVolume:n}=e.node;n&&!function(t,e,n){if(n.region){const e=n.region;if(t[0]>=e[0]&&t[0]<=e[2]&&t[1]>=e[1]&&t[1]<=e[3])return!0}else{if(n.sphere)return wi(n,e);if(n.box)return 0===vi(n,e)}return!1}(this.Dn,this.jn,n)||t.push(e)}gn(t,e){return{id:t.id,node:t,children:[],level:t.zt,parent:e,content:t.content&&t.content.url}}Gn(t){const e=this.getId();t.id=e+":"+s.Util.GUID(),t.matrix=t.transform||n.mat4.identity([]),t.Xn=this.Jn(t),t.parent&&(function(t){return t.content&&t.content.uri&&t.content.uri.indexOf("i3s:")>=0}(t)||(t.matrix=n.mat4.multiply(t.matrix,t.parent.matrix,t.matrix)),t.Rt=t.parent.Rt,void 0===t.zt&&(t.zt=t.parent.zt+1),t.maxExtent=t.parent.maxExtent),t.refine=t.refine&&t.refine.toLowerCase()||"replace",t.content&&!t.content.url&&t.content.uri&&(t.content.url=t.content.uri)}Pt(t){return this.vn[t].service}Kn(t){const e=t.boundingVolume;if(!e||e.Bn&&!this.Qn(t))return;const r=this.Pt(t.Rt),s=r.heightOffset||0,i=this.options.offset,o=at(i)||i[0]||i[1],a=r.coordOffset||bi;if(!Array.isArray(a))throw new Error("service.coordOffset must be an array");if(!e.Bn&&(!t.boundingVolume||!s&&n.mat4.exactEquals(t.matrix,pi)&&!o&&a===bi))return;e.box&&e.region&&delete e.region;const{region:c,box:h,sphere:u}=e;if(e.coordOffset=[a[0],a[1]],e.heightOffset=s,c){e.originalVolume||(e.originalVolume=c.slice(0));const t=e.originalVolume,n=this.Zn([lt(t[0]),lt(t[1])]);c[0]=ut(n.x+a[0]),c[1]=ut(n.y+a[1]);const r=this.Zn([lt(t[2]),lt(t[3])]);c[2]=ut(r.x+a[0]),c[3]=ut(r.y+a[1]),c[4]=t[4]+s+(a[2]||0),c[5]=t[5]+s+(a[2]||0)}else if(h||u){e.originalVolume||(e.originalVolume=(h||u).slice(0));const r=h||u,i=e.originalVolume,o=n.vec3.transformMat4(oi,i,t.matrix),c=bn(ai,o),l=this.Zn([c[0]+a[0],c[1]+a[1]]);c[0]=l.x,c[1]=l.y,c[2]+=s+(a[2]||0),un(r,ut(c[0]),ut(c[1]),c[2])}e.Bn=!0}Qn(t){const e=t.boundingVolume,n=this.Pt(t.Rt),r=n.heightOffset||0,s=n.coordOffset||bi;return e.coordOffset[0]!==s[0]||e.coordOffset[1]!==s[1]||e.heightOffset!==r}Jn(t){return void 0===t.geometricError||!t.boundingVolume}$n(t){let e=t.parent;for(;e&&e.Xn&&!(e.ne<=t.ne);)e.ne=t.ne,e=t.parent}onTileLoad(t,e){if(t.children&&(!e.children||!e.children.length)){e.children=t.children;const n=e.content.url;e.baseUrl=n.substring(0,n.lastIndexOf("/")+1);const r=this.getRenderer();r&&r.setToRedraw()}}onTilesetLoad(t,e,r){if(!t)return void console.warn("invalid tileset at : "+r);const s=this.Pt(e.Rt),i=(t.asset&&t.asset.gltfUpAxis||e&&e.de||s.upAxis||"Y").toUpperCase();t.root.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const o=r.indexOf("realspace/")>-1;0===e.zt&&(t.asset&&t.asset.s3mType&&o||s.isSuperMapiServer)&&(t.root.baseUrl+="data/path/");const a=t.asset.i3s,c=!!t.asset.s3mType;if(t.root.de=i,e){const r=e.Rt,s=this.vn[r];c&&!s.isS3M&&(s.isS3M=c);const i=e.boundingVolume;ot(e,t.root),e.refine=e.refine&&e.refine.toLowerCase()||"replace",i&&(e.boundingVolume=i);const o=t.root.transform;o&&(e.parent?a||(e.matrix=n.mat4.multiply([],e.parent.matrix,o)):e.matrix=o),e.Yn=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.Xn=this.Jn(e);const h=e.content&&(e.content.url||e.content.uri);h&&e.content.uri&&(e.content.url=e.content.uri,delete e.content.uri),!a&&h&&!wt(h)&&xt(h)&&(e.content.url=e.baseUrl+h),t.root&&!e.parent&&this.Wn(e)}this.Un(),this.fire("loadtileset",{tileset:t,index:e&&e.Rt,url:r})}qn(t,e,n){if(t.ne=1/0,0===t.zt||t.Xn)return this.Wn(t),1;if(this.Kn(t),!this.tr(t,e,n))return-1;if(0===t.geometricError)return 1;let r=this.Pt(t.Rt).maximumScreenSpaceError;null==r&&(r=16);let s=this.er(t);return 0===s&&t.parent&&(s=.5*(t.parent.ln||0)),s>=r?1:0}Re(t,e){e||(e=new s.Point(0,0));const n=this.getMap();return n.getGLZoom?n.coordToPoint(t,n.getGLZoom(),e):n.coordToPointAtRes(t,n.getGLRes(),e)}tr(t,e,n){const r=t.id;let i=this._e[r]&&this._e[r].obbox;const{boundingVolume:o}=t,c=o.region,h=o.box,d=o.sphere;if(!i)if(c)this._e[r]=this.nr(t),i=this._e[r].bbox,i.center=this._e[r].coordCenter;else if(h)this._e[r]=this.rr(t),i=this._e[r].obbox,i.center=this._e[r].coordCenter;else if(d){i=this._e[r]=this.sr(t);const e=bn(oi,d),n=new s.Coordinate(e);i.center=n}if(e){if(c)ii.xmin=i[0][0],ii.ymin=i[0][1],ii.xmax=i[1][0],ii.ymax=i[1][1];else if(d){const t=i[2];ii.xmin=i[0][0]-t,ii.ymin=i[0][1]-t,ii.xmax=i[0][0]+t,ii.ymax=i[0][1]+t}else if(h){const t=i[1],e=i[2];ii.xmin=i[0][0]-t,ii.ymin=i[0][1]-e,ii.xmax=i[0][0]+t,ii.ymax=i[0][1]+e}if(!e.intersects(ii))return!1}return c?u(n,i):d?function(t,e,n){f(t);for(var r=e[0],s=-e[1],i=0;i<6;i++){if(!n||"0"!==n.charAt(i))if(m(a[i],r)<s)return!1}return!0}(n,i):!!h&&function(t,e,n){f(t);for(var r=0;r<6;r++){if(!n||"0"!==n.charAt(r))if(!l(a[r],e))return!1}return!0}(n,i)}nr(t){const e=this.getMap(),n=e.getGLRes(),r=t.boundingVolume.region;let{ws:i,en:o}=function(t){const e=t[0],n=t[1],r=t[2],s=t[3],i=t[4],o=t[5],a=un([],e,n,i),c=un([],r,s,o),h=bn(a,a),u=bn(c,c);return{ws:h,en:u}}(r);i=new s.Coordinate(i),o=new s.Coordinate(o);const a=e.coordToPointAtRes(i,n);a.z=e.altitudeToPoint(i.z,n);const c=e.coordToPointAtRes(o,n);c.z=e.altitudeToPoint(o.z,n);const h=[c.x,a.y,c.z,c.x,c.y,c.z,a.x,c.y,c.z,a.x,a.y,c.z,c.x,a.y,a.z,c.x,c.y,a.z,a.x,c.y,a.z,a.x,a.y,a.z],u=[(h[0]+h[18])/2,(h[1]+h[19])/2,(h[2]+h[20])/2],l=e.pointAtResToCoord(new s.Point(u),n);l.z=(i.z+o.z)/2;const f=this.Yt(t.Rt).Me,d=[h.slice(21,24),h.slice(3,6)];if(f)for(let t=0;t<h.length;t+=3)h[t]-=f[0],h[t+1]-=f[1],h[t+2]-=f[2];return{bbox:d,boxPosition:h,pointCenter:u,coordCenter:l}}rr(t){const e=this.getRenderer(),r=this.getMap(),s="identity"===r.getProjection().code.toLowerCase(),i=r.getGLRes(),o=t.boundingVolume.box,a=o.slice(0,3),c=this.ir(o,t.matrix),h=(l=a,new _i((u=c)[0],u[3],u[6],l[0],u[1],u[4],u[7],l[1],u[2],u[5],u[8],l[2],0,0,0,1));var u,l;const f=this.or(t),d=[],m=this.Yt(t.Rt).Me;fi.set(m[0],m[1]);const p=r.pointAtResToCoord(fi,i),b=oi;for(let t=0;t<gi.length;t+=3){b[0]=gi[t],b[1]=gi[t+1],b[2]=gi[t+2],n.vec3.transformMat4(b,b,h),bn(b,b),s&&e.Cn(b,b);const o=li.set(...b);let a=r.coordToPointAtRes(o,i,fi);a=n.vec3.set(b,a.x,a.y,r.altitudeToPoint(o.z,i)),d[t]=a[0]-m[0],d[t+1]=a[1]-m[1],d[t+2]=a[2]-m[2]}return{obbox:this.ar(d,m,f),boxPosition:d,boxCenter:f,coordCenter:p}}sr(t){const e=this.getMap(),n=this.getRenderer(),r="identity"===e.getProjection().code.toLowerCase(),i=t.boundingVolume.sphere,o=i;let a=oi;0===o[0]&&0===o[1]&&0===o[2]?a=[0,0,-6378137]:bn(a,o),r&&n.Cn(a,a);const c=new s.Coordinate(a),h=this.Re(c,fi).toArray();h[2]=e.altitudeToPoint(c.z,e.getGLRes());const u=this.cr(c);return[h,i[3]*u[2]]}ar(t,e,r){const[s,i,o]=e,a=n.vec3.set(oi,(t[3]+t[12])/2+s,(t[4]+t[13])/2+i,(t[5]+t[14])/2+o),c=n.vec3.set(ai,(t[3]+t[18])/2+s,(t[4]+t[19])/2+i,(t[5]+t[20])/2+o),h=n.vec3.set(ci,(t[3]+t[9])/2+s,(t[4]+t[10])/2+i,(t[5]+t[11])/2+o),u=r.slice(0);return u[3]=a[0]-r[0],u[4]=a[1]-r[1],u[5]=a[2]-r[2],u[6]=c[0]-r[0],u[7]=c[1]-r[1],u[8]=c[2]-r[2],u[9]=h[0]-r[0],u[10]=h[1]-r[1],u[11]=h[2]-r[2],u}or(t){const e=this.getMap(),n=this.getRenderer(),r="identity"===e.getProjection().code.toLowerCase(),i=e.getGLRes(),o=t.boundingVolume.box.slice(0,3);bn(o,o),r&&n.Cn(o,o);const a=new s.Coordinate(o),c=e.coordToPointAtRes(a,i);return[c.x,c.y,e.altitudeToPoint(a.z,i)]}Wn(t){const e=this.Pt(t.Rt);if(!t.boundingVolume||this.hr(t,e))return;const n=t.boundingVolume.box,r=t.boundingVolume.region,s=t.boundingVolume.sphere;let i=null;if(n){i=this.ur(t).pointCenter}else if(r){i=this.lr(t).pointCenter}else s&&(i=this.sr(t)[0]);const o=e.heightOffset||0,a=e.coordOffset||[0,0];t.dr=[a[0]||0,a[1]||0],t.te=o,t.Me=i}hr(t,e){if(!t.dr)return!1;const n=e.coordOffset||bi;return t.dr[0]===n[0]&&t.dr[1]===n[1]&&t.te===(e.heightOffset||0)}lr(t){if(!t.boundingVolume)return null;this.Kn(t);return this.nr(t)}ur(t){if(!t.boundingVolume)return null;this.Kn(t);const e=t.boundingVolume.box.slice(0,3);bn(e,e);const n=new s.Coordinate(e);return{pointCenter:this.or(t),coordCenter:n}}ir(t,e){let n=t.slice(3,12);return n=function(t,e,n){const r=t[0]*e[0]+t[3]*e[1]+t[6]*e[2],s=t[1]*e[0]+t[4]*e[1]+t[7]*e[2],i=t[2]*e[0]+t[5]*e[1]+t[8]*e[2],o=t[0]*e[3]+t[3]*e[4]+t[6]*e[5],a=t[1]*e[3]+t[4]*e[4]+t[7]*e[5],c=t[2]*e[3]+t[5]*e[4]+t[8]*e[5],h=t[0]*e[6]+t[3]*e[7]+t[6]*e[8],u=t[1]*e[6]+t[4]*e[7]+t[7]*e[8],l=t[2]*e[6]+t[5]*e[7]+t[8]*e[8];return n[0]=r,n[1]=s,n[2]=i,n[3]=o,n[4]=a,n[5]=c,n[6]=h,n[7]=u,n[8]=l,n}(this.mr(e,[]),n,n),n}mr(t,e){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[4],e[4]=t[5],e[5]=t[6],e[6]=t[8],e[7]=t[9],e[8]=t[10],e}cr(t){const e=this.getMap(),r=e.distanceToPointAtRes(100,100,e.getGLRes(),t);let s;return s=e.altitudeToPoint?e.altitudeToPoint(100,e.getGLRes())/100:r.y/100,n.vec3.set(hi,r.x/100*1.01,r.y/100*1.01,s),hi}Zn(t){Array.isArray(t)&&(t=new s.Coordinate(t));let e=this.options.offset;if(at(e)&&(e=e.call(this,Array.isArray(t)?new s.Coordinate(t):t)),e[0]||e[1]){const n=this.getMap(),r=n.getGLRes(),s=n.coordToPointAtRes(t,r);return s._sub(e),n.pointAtResToCoord(s,r)}return t}Yt(t){return this.vn[t]}Hn(t){const e=this.Pt(t).maxExtent;if(!e)return null;const n=this.vn[t];return n.maxExtent||(n.maxExtent=new s.Extent(e).convertTo(t=>this.Re(t))),n.maxExtent}er(t){const e=this.zn,n=t.geometricError;if(0===n)return t.ln=0,0;const r=this.getMap();let s;t.boundingVolume.region?s=function(t,e,n){t.pr||(t.pr=new ni(t.boundingVolume.region));return t.pr.distanceToCamera(e,n)}(t,this.jn,this.Dn):t.boundingVolume.sphere?s=wi(t.boundingVolume,this.jn):t.boundingVolume.box&&(s=vi(t.boundingVolume,this.jn));const i=Math.max(Math.abs(s),1e-7),o=n*r.height/(i*e);return t.ne=s,t.ln=o,o}Un(){const t=this.getRenderer();t&&t.setToRedraw()}Oe(t){return this._e[t]}identify(t,e={}){const n=this.getMap(),r=this.getRenderer();if(!n||!r)return[];const i=n.coordToContainerPoint(new s.Coordinate(t));return this.identifyAtPoint(i,e)}identifyAtPoint(t,e={}){const n=[];if(!e.excludeMasks){const r=this.identifyMask(t,e);r&&r.length&&Tt(n,r)}const r=this.getMap(),s=this.getRenderer();if(!r||!s)return[];const i=r.getDevicePixelRatio();return Tt(n,s.pick(t.x*i,t.y*i,e)),n}getCurrentBatchIDs(){const t=this.getMap(),e=this.getRenderer();return t&&e?e.Le():[]}highlight(t){const e=this.getRenderer();return e?(e.highlight(t),this):(this.Ut||(this.Ut=[]),this.Ut.push(t),this)}In(){if(this.Ut){for(let t=0;t<this.Ut.length;t++)this.highlight(this.Ut[t]);delete this.Ut}}cancelHighlight(t,e){const n=this.getRenderer();return n?(n.cancelHighlight(t,e),this):this}cancelAllHighlight(){const t=this.getRenderer();return t?(t.cancelAllHighlight(),this):this}showOnly(t){const e=this.getRenderer();return e?(e.showOnly(t),this):(this.Dt||(this.Dt=[]),this.Dt.push(t),this)}br(){if(this.Dt){for(let t=0;t<this.Dt.length;t++)this.showOnly(this.Dt[t]);delete this.Dt}}cancelShowOnly(t){const e=this.getRenderer();return e?(e.cancelShowOnly(t),this):this}setServiceOpacity(t,e){const n=this.options.services[t];n&&(n.opacity=e);const r=this.getRenderer();return r?(r.setToRedraw(),this):this}setServiceDebugBoundingVolume(t,e){const n=this.options.services[t];n&&(n.debugShowBoundingVolume=e);const r=this.getRenderer();return r?(r.setToRedraw(),this):this}Fn(t){const e=this.getMap(),n=e.getGLRes();mi.set(t[0],t[1]);const r=e.pointAtResToCoord(mi,n);return"identity"===e.getProjection().code.toLowerCase()?(ai[0]=r.x,ai[1]=r.y,this.getRenderer().Pn(oi,ai),r.set(oi[0],oi[1]),r):r}toJSON(){return{"type":this.getJSONType(),"id":this.getId(),"options":this.config()}}}function wi(t,e){const r=t.sphere,s=n.vec3.dist(r,e),i=t.sphere[3];return s<i?0:s-i}function vi(t,e){const r=t.box;return Rs(n.vec3.set(oi,r[0],r[1],r[2]),n.mat3.set(di,r[3],r[4],r[5],r[6],r[7],r[8],r[9],r[10],r[11]),e)}function Ti(t,e,r){const s=(t=ft(t)).indexOf("{s}")>=0?"{s}":t.indexOf("%7Bs%7D")>=0?"%7Bs%7D":null;return{service:r,visible:it(r.visible)?1:r.visible,baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:n.mat4.identity([]),Rt:e,zt:0,domainKey:s}}function _i(t,e,n,r,s,i,o,a,c,h,u,l,f,d,m,p){this[0]=t||0,this[1]=s||0,this[2]=c||0,this[3]=f||0,this[4]=e||0,this[5]=i||0,this[6]=h||0,this[7]=d||0,this[8]=n||0,this[9]=o||0,this[10]=u||0,this[11]=m||0,this[12]=r||0,this[13]=a||0,this[14]=l||0,this[15]=p||0}yi.mergeOptions(si),yi.registerRenderer("gl",Ns),yi.registerJSONType("Geo3DTilesLayer");let Mi=null;function Oi(){return Mi||(Mi={"image/crn":fs.crn&&fs.crn(),"image/ktx2":fs.ktx2&&fs.ktx2(),"image/cttf":fs.ktx2&&fs.ktx2(),"draco":fs.draco&&fs.draco()}),Mi}class xi{constructor(t,e,n){this.i=t,this.gr=e||Ue,this.o=n,this.yr=Oi()}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.wr(t,e,n,r,s)):ye.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.wr(t,s,n,r)})}wr(t,e,n,r,s){const i=s&&s.maxTextureSize,o=this.vr(e,n,r,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.gr(a,o.glb,{transferable:!0,requestImage:this.i,decoders:this.yr,supportedFormats:this.o,maxTextureSize:i});return c.load({skipAttributeTransform:!1}).then(e=>{e.url=`${t}-${n}-${r}`;const s=c.transferables;for(let t=0;t<o.transferables.length;t++)s.indexOf(o.transferables[t])<0&&s.push(o.transferables[t]);return{magic:"b3dm",count:o.count,transferables:s,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,gltf:e}})}vr(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported b3dm version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in b3dm header is inconsistent with b3dm's byte length, url: "+r;return console.warn(t),{error:t}}let o,a=s.getUint32(12,!0),c=s.getUint32(16,!0),h=s.getUint32(20,!0),u=s.getUint32(24,!0),l=28+e;h>=570425344?(l-=8,o=a,h=c,u=0,a=0,c=0):u>=570425344&&(l-=4,o=h,h=a,u=c,a=0,c=0);const f=[t];let d,m,p;if(a>0?(d=In(t,l,a),l+=a,o=d.BATCH_LENGTH):d={"BATCH_LENGTH":o},c>0&&(l+=c),h>0&&(m=Sn(t,l,h),l+=h,u>0)){const e=En(0,l,u);p=t.slice(e.offset,e.offset+e.byteLength),l+=u,f.push(p)}const b=d.BATCH_LENGTH,g={};if(d&&d.BATCH_ID){g.BATCH_ID=Cn(d.BATCH_ID,t,(void 0).offset,b);const e=g.BATCH_ID.array&&g.BATCH_ID.array.buffer;e&&f.indexOf(e)<0&&f.push(e)}return{count:o,transferables:f,featureTable:d,batchTable:m,batchTableBin:p,b3dm:g,glb:{buffer:t,byteOffset:l,byteLength:s.byteLength+s.byteOffset-l}}}Tr(){return null}}class Ai{constructor(t,e,n,r){this.i=t,this.gr=e||Ue,this.o=n,this.yr=Oi(),this._r=r}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.wr(t,e,n,r,s)):ye.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.wr(t,s,n,r)})}wr(t,e,n,r,s){return this.Mr(t,e,n,r,s).then(({gltf:s,transferables:i})=>{const o=this.Or(e,n,r,t);if(o.error)return Promise.resolve(o);for(let t=0;t<i.length;t++)-1===o.transferables.indexOf(i[t])&&o.transferables.push(i[t]);return delete s.transferables,Promise.resolve({magic:"i3dm",count:o.count,transferables:o.transferables,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,i3dm:o.i3dm,gltf:s})})}Mr(t,e,n,r,s){const i=s&&s.maxTextureSize,o={transferable:!0,requestImage:this.i,decoders:this.yr,supportedFormats:this.o,maxTextureSize:i},a=new DataView(e,n,r),c=32+a.getUint32(12,!0)+a.getUint32(16,!0)+a.getUint32(20,!0)+a.getUint32(24,!0);if(0===a.getUint32(28,!0)){let r=pt(new Uint8Array(e,c+n,a.byteLength-c));-1==r.indexOf("://")&&(r=t.substring(0,t.lastIndexOf("/"))+"/"+r);return r.indexOf(".glb")>0?ye.getArrayBuffer(r,{}).then(t=>this.xr(r,{buffer:t.data,byteOffset:0},o)):ye.getJSON(r,{}).then(t=>this.xr(r,t,o))}{const r={buffer:e,byteOffset:c+n,byteLength:a.byteLength-c};return this.xr(t,r,o)}}xr(t,e,n){const r=t.substring(0,t.lastIndexOf("/")),s=new this.gr(r,e,n);return s.load({skipAttributeTransform:!0}).then(n=>{let r=0,i=0;return e.buffer&&(r=e.byteOffset||0,i=e.byteLength||0),n.url=`${t}-${r}-${i}`,{transferables:s.transferables,gltf:n}})}Or(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported pnts version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+r;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:h,batchTableBin:u}=Dn(s,32+e,o),l={},f=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;l.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,n=a.QUANTIZED_VOLUME_SCALE,{byteOffset:r}=a.POSITION_QUANTIZED;l.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.Ar(new Uint16Array(t,r+c.offset,3*f),e,n)},o.push(l.POSITION.array.buffer)}if(a.BATCH_ID){l.BATCH_ID=Cn(a.BATCH_ID,t,c.offset,f);const e=l.BATCH_ID.array&&l.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;l.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,l.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;l.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.Ir(new Uint16Array(t,e+c.offset,2*f))},o.push(l.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,l.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.Ir(new Uint16Array(t,e+c.offset,2*f))},o.push(l.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;l.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,f).slice()},o.push(l.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;l.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.SCALE_NON_UNIFORM.array.buffer)}return{count:f,batchTable:h,batchTableBin:u,featureTable:a,i3dm:l,transferables:o}}Ir(t){const e=t.length/2,n=new Float32Array(3*e),r=[];for(let s=0;s<e;s++)Ii(r,t[2*s],t[2*s+1],65535),n[3*s]=r[0],n[3*s+1]=r[1],n[3*s+2]=r[2];return n}Ar(t,e,n){return Fn(new Float32Array(t.length),t,e,n)}Tr(){return null}}function Ii(t,e,n,r){if(t[0]=Si(e,r),t[1]=Si(n,r),t[2]=1-(Math.abs(t[0])+Math.abs(t[1])),t[2]<0){const e=t[0];t[0]=(1-Math.abs(t[1]))*Ei(e),t[1]=(1-Math.abs(e))*Ei(t[1])}return Ht(t,t)}function Si(t,e){return function(t,e,n){return t<e?e:t>n?n:t}(t,0,e=function(t,e){if(null!=t)return t;return e}(e,255))/e*2-1}function Ei(t){return t<0?-1:1}class Ni{constructor(){}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.wr(t,e,n,r)):ye.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.wr(t,s,n,r)})}wr(t,e,n,r){return this.Sr(e,n,r,t).then(t=>t.error?t:{magic:"pnts",count:t.count,transferables:t.transferables,featureTable:t.featureTable,batchTable:t.batchTable,batchTableBin:t.batchTableBin,pnts:t.pnts})}Sr(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported pnts version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+r;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:h,batchTableBin:u}=Dn(s,e+28,o),l=a.QUANTIZED_VOLUME_OFFSET,f=a.QUANTIZED_VOLUME_SCALE,d=a.POINTS_LENGTH;let m,p={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){p=a.extensions["3DTILES_draco_point_compression"],m=new DataView(t,p.byteOffset+c.offset,p.byteLength);const e={attributes:p.properties,useUniqueIDs:!1};return this.Er||(this.Er=Oi().draco),this.Er(m,e).then(e=>{const n=e.attributes;!a.POSITION&&!a.POSITION_QUANTIZED||n.POSITION||n.POSITION_QUANTIZED||(n.POSITION=a.POSITION,n.POSITION_QUANTIZED=a.POSITION_QUANTIZED),!(a.RGB||a.RGBA||a.RGB565)||n.RGB||n.RGBA||n.RGB565||(n.RGB=a.RGB,n.RGBA=a.RGBA,n.RGB565=a.RGB565),!a.NORMAL&&!a.NORMAL_OCT16P||n.NORMAL||n.NORMAL_OCT16P||(n.NORMAL=a.NORMAL,n.NORMAL_OCT16P=a.NORMAL_OCT16P);const r=this.Nr(t,e.attributes,c.offset,d,o,l,f);if(e.attributes.BATCH_ID){const t=e.attributes.BATCH_ID.array;r.BATCH_ID={byteStride:0,byteOffset:0,itemSize:1,count:t.length,componentType:Un(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?r.BATCH_ID=Cn(a.BATCH_ID,t,c.offset,d):r.BATCH_ID=Ci(d);const e=r.BATCH_ID.array&&r.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return{count:d,batchTable:h,batchTableBin:u,featureTable:a,pnts:r,transferables:o}})}const b=this.Nr(t,a,c.offset,d,o,l,f);if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?b.BATCH_ID=Cn(a.BATCH_ID,t,c.offset,d):b.BATCH_ID=Ci(d);const e=b.BATCH_ID.array&&b.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:d,batchTable:h,batchTableBin:u,featureTable:a,pnts:b,transferables:o})}Nr(t,e,n,r,s,i,o){const a={};if(e.POSITION){let{byteOffset:i,array:o}=e.POSITION;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r*4);o=new Float32Array(e)}a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:o},s.push(o.buffer)}else if(e.POSITION_QUANTIZED){let{byteOffset:c}=e.POSITION_QUANTIZED;const{array:h}=e.POSITION_QUANTIZED;c=c||0;const u=h?0:n;a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:this.Ar(h||new Uint16Array(t,c+u,3*r),i,o)},s.push(a.POSITION.array.buffer)}if(e.RGBA){let{byteOffset:i,array:o}=e.RGBA;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+4*r);o=new Uint8Array(e)}a.RGBA={byteStride:0,byteOffset:0,itemSize:4,count:r,componentType:5121,array:o},s.push(o.buffer)}else if(e.RGB){let{byteOffset:i,array:o}=e.RGB;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r);o=new Uint8Array(e)}a.RGB={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5121,array:o},s.push(o.buffer)}else if(e.RGB565){let{byteOffset:i,array:o}=e.RGB565;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+2*r);o=new Uint16Array(e)}a.RGB565={byteStride:0,byteOffset:0,itemSize:1,count:r,componentType:5123,array:o},s.push(o.buffer)}if(e.NORMAL){let{byteOffset:i,array:o}=e.NORMAL;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r*4);o=new Float32Array(e)}a.NORMAL={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:o},s.push(o.buffer)}else if(e.NORMAL_OCT16P){let{byteOffset:i,array:o}=e.NORMAL_OCT16P;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+2*r);o=new Uint8Array(e)}a.NORMAL_OCT16P={byteStride:0,byteOffset:0,itemSize:2,count:r,componentType:5121,array:o},s.push(o.buffer)}return a}Ar(t,e,n){return Fn(new Float32Array(t.length),t,e,n)}Tr(){return null}}function Ci(t){const e=yt(t),n=new e(t);for(let e=0;e<t;e++)n[e]=e;return{byteStride:0,byteOffset:0,itemSize:1,count:t,componentType:Un(e),array:n}}class Pi{constructor(t,e,n,r){this.o=n,this.i=t,this.gr=e||Ue,this._r=r}load(t,e,n=0,r=0,s){return e?this.wr(t,e,n,r,s):ye.getArrayBuffer(t,{}).then(e=>{const s=e.data;return this.wr(t,s,n,r)})}wr(t,e,n,r,s){r||(r=e.byteLength);const i=this.Cr(e,t,n,r),o=[];for(let n=0;n<i.length;n++){let r;if("b3dm"===i[n].magic)r=new xi(this.i,this.gr,this.o);else if("i3dm"===i[n].magic)r=new Ai(this.i,this.gr,this.o,this._r);else if("pnts"===i[n].magic)r=new Ni;else{if("cmpt"!==i[n].magic){console.warn("Unsupported magic in CMPT tile:",i[n].magic);continue}r=new Pi(this.i,this.gr,this.o,this._r)}o.push(r.load(t,e,i[n].offset,i[n].byteLength,s).then(t=>t))}return Promise.all(o).then(t=>({magic:"cmpt",tiles:t}))}Cr(t,e,n,r){const s=new DataView(t,n,r),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported cmpt version: "+i+", url:"+e;return console.warn(t),{error:t}}if(16===s.byteLength)return[];const o=[],a=s.getUint32(12,!0);let c=16;for(let e=0;e<a;e++){const e=xn(s,c),r=s.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+n,byteLength:r}),c+=r}return o}}if(i.transcoders){const t=s.Map.VERSION;if(t.indexOf("1.0.0-beta")>=0||t.indexOf("1.0.0-alpha")>=0){const t=i.transcoders.inject(o);s.registerWorkerAdapter("@maptalks/3dtiles",t)}else s.registerWorkerAdapter("@maptalks/3dtiles",(function(){return i.transcoders.inject(o)}))}else s.registerWorkerAdapter("@maptalks/3dtiles",o);t.B3DMLoader=xi,t.CMPTLoader=Pi,t.Geo3DTilesLayer=yi,t.Geo3DTilesUtil=Ot,t.Geo3DTransform=Mn,Object.defineProperty(t,"t",{value:!0}),"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.95.6")}));
|