@maptalks/3dtiles 0.88.0 → 0.88.1

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.
@@ -1,11 +1,11 @@
1
1
  /*!
2
- * @maptalks/3dtiles v0.88.0
2
+ * @maptalks/3dtiles v0.88.1
3
3
  * LICENSE : UNLICENSED
4
4
  * (c) 2016-2023 maptalks.org
5
5
  */
6
- import*as t from"maptalks";import*as e from"@maptalks/gl";import{reshader as n,mat4 as r,HighlightUtil as s,vec3 as i,mat3 as o,vec4 as a,quat as c,MaskRendererMixin as h,createREGL as u,MaskLayerMixin as f}from"@maptalks/gl";import{intersectsBox as l,intersectsSphere as d,intersectsOrientedBox as m}from"frustum-intersects";import{GLTFLoader as p,Ajax as y}from"@maptalks/gltf-loader";import{quat as b,mat4 as g,vec3 as T,mat3 as w}from"gl-matrix";const _='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],o=e[2],i=e[3],a=e[4],c=e[5],u=e[6],f=e[7],l=e[8],h=e[9],y=e[10],m=e[11],d=e[12],p=e[13],b=e[14],w=e[15],T=n[0],g=n[1],A=n[2],_=n[3];return t[0]=T*r+g*a+A*l+_*d,t[1]=T*s+g*c+A*h+_*p,t[2]=T*o+g*u+A*y+_*b,t[3]=T*i+g*f+A*m+_*w,T=n[4],g=n[5],A=n[6],_=n[7],t[4]=T*r+g*a+A*l+_*d,t[5]=T*s+g*c+A*h+_*p,t[6]=T*o+g*u+A*y+_*b,t[7]=T*i+g*f+A*m+_*w,T=n[8],g=n[9],A=n[10],_=n[11],t[8]=T*r+g*a+A*l+_*d,t[9]=T*s+g*c+A*h+_*p,t[10]=T*o+g*u+A*y+_*b,t[11]=T*i+g*f+A*m+_*w,T=n[12],g=n[13],A=n[14],_=n[15],t[12]=T*r+g*a+A*l+_*d,t[13]=T*s+g*c+A*h+_*p,t[14]=T*o+g*u+A*y+_*b,t[15]=T*i+g*f+A*m+_*w,t}function o(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 i(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],o=e[3],i=n+n,a=r+r,c=s+s,u=n*i,f=r*i,l=r*a,h=s*i,y=s*a,m=s*c,d=o*i,p=o*a,b=o*c;return t[0]=1-l-m,t[1]=f+b,t[2]=h-p,t[3]=0,t[4]=f-b,t[5]=1-u-m,t[6]=y+d,t[7]=0,t[8]=h+p,t[9]=y-d,t[10]=1-u-l,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 l(t,n,r){var s=new e(3);return s[0]=t,s[1]=n,s[2]=r,s}function h(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function y(t,e,n,r){return t[0]=e,t[1]=n,t[2]=r,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 d(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t[2]=e[2]*n[2],t}function p(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t}function b(t,e){var n=e[0],r=e[1],s=e[2],o=n*n+r*r+s*s;return o>0&&(o=1/Math.sqrt(o),t[0]=e[0]*o,t[1]=e[1]*o,t[2]=e[2]*o),t}function w(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function T(t,e,n){var r=e[0],s=e[1],o=e[2],i=n[0],a=n[1],c=n[2];return t[0]=s*c-o*a,t[1]=o*i-r*c,t[2]=r*a-s*i,t}function g(t,e,n){var r=e[0],s=e[1],o=e[2],i=n[3]*r+n[7]*s+n[11]*o+n[15];return i=i||1,t[0]=(n[0]*r+n[4]*s+n[8]*o+n[12])/i,t[1]=(n[1]*r+n[5]*s+n[9]*o+n[13])/i,t[2]=(n[2]*r+n[6]*s+n[10]*o+n[14])/i,t}var A=function(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t},_=d,S=f;function M(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],o=e[2],i=e[3];return t[0]=n[0]*r+n[4]*s+n[8]*o+n[12]*i,t[1]=n[1]*r+n[5]*s+n[9]*o+n[13]*i,t[2]=n[2]*r+n[6]*s+n[10]*o+n[14]*i,t[3]=n[3]*r+n[7]*s+n[11]*o+n[15]*i,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 I(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}function v(t,e,n,r){var s=e[0],o=e[1],i=e[2],a=e[3],c=n[0],u=n[1],f=n[2],l=n[3],h=void 0,y=void 0,m=void 0,d=void 0,p=void 0;return(y=s*c+o*u+i*f+a*l)<0&&(y=-y,c=-c,u=-u,f=-f,l=-l),1-y>1e-6?(h=Math.acos(y),m=Math.sin(h),d=Math.sin((1-r)*h)/m,p=Math.sin(r*h)/m):(d=1-r,p=r),t[0]=d*s+p*c,t[1]=d*o+p*u,t[2]=d*i+p*f,t[3]=d*a+p*l,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 C,U=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t};u(),l(1,0,0),l(0,1,0),x(),x(),C=new e(9),e!=Float32Array&&(C[1]=0,C[2]=0,C[3]=0,C[5]=0,C[6]=0,C[7]=0),C[0]=1,C[4]=1,C[8]=1;\n/*!\n * @maptalks/gltf-loader v0.88.0\n * LICENSE : UNLICENSED\n * (c) 2016-2023 maptalks.org\n */\nlet E=0;function P(t){return null==t}function N(t){return!P(t)}function B(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 F(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=[],V=[],k=[0,0,0],j=I([]),q=[1,1,1];function G(t,e,n,r,s,o,i){const a=F(i);if((0===s||s===r*a.BYTES_PER_ELEMENT)&&o%a.BYTES_PER_ELEMENT==0){const s=new a(e,o,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 i=0;i<n;i++){let n=null;const u=new Uint8Array(e,s*i+o,r*a.BYTES_PER_ELEMENT);c.set(u),n=new a(c.buffer,0,r);for(let e=0;e<r;e++)t[i*r+e]=n[e]}return t}const H="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function $(t,e,n){const r=new Uint8Array(t,e,n);return H.decode(r)}const X={get:function(t,e={}){e||(e={});const n=new AbortController,r=n.signal,s=B({},e);s.signal=r,s.method||(s.method="GET");const o=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 o.xhr=n,o},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",X.get(t,e)),getJSON:function(t,e={}){return e&&e.jsonp?X.jsonp(t):((e=e||{}).responseType="json",X.get(t,e))},jsonp:function(t){const e="_maptalks_jsonp_"+E++;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 J{constructor(t,e,n){this.s=t,this.decoders=e,this.o=n,this.images={},this.i={}}requestImageFromBufferURI(t,e,n){if(this.buffers[t.id]){const r=this.buffers[t.id],s=this.u(e,r);return this.getImageByBuffer(s,n)}if(this.i[t.id])return this.i[t.id].then(()=>{const r=this.buffers[t.id],s=this.u(e,r);return this.getImageByBuffer(s,n)});if(D(t.uri)){const r=this.buffers[t.id]=R(t.uri),s=this.u(e,r);return this.getImageByBuffer(s,n)}return this.i[t.id]=X.getArrayBuffer(t.uri,null).then(r=>{const s=this.buffers[t.id]=r.data,o=this.u(e,s);return this.getImageByBuffer(o,n)})}getImageByBuffer(t,e){if(this.images[e.id])return Promise.resolve(this.images[e.id]);const n=this.decoders;if(n[e.mimeType])return n[e.mimeType](t,{supportedFormats:this.o});if("image/crn"===e.mimeType||"image/ktx2"===e.mimeType||"image/cttf"===e.mimeType)return console.warn("missing transcoder for "+e.mimeType,", visit https://maptalks.com/docs/transcoders for details"),Promise.resolve(null);{const n=new Blob([t],{type:e.mimeType}),r=URL.createObjectURL(n);return this.l(e.id,r)}}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.i[t.id]?this.i[t.id].then(()=>this.images[t.id]):this.i[t.id]=this.l(t.id,e)}l(t,e){return new Promise((n,r)=>{this.s(e,(s,o)=>{s?r(s):(URL.revokeObjectURL(e),this.images[t]=o,n(this.images[t]))})})}}const K=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],Y=[];class Q{constructor(t,e,n){this.rootPath=t,this.gltf=e,this.h=!1,this.glbBuffer=n,this.buffers={},this.requests={},this.accessors={},this.m()}p(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.g(s).then(n=>{const{buffer:s,byteOffset:o}=n;return this.accessors[r.id]=this.T(t,e,s,o)})}g(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]=X.getArrayBuffer(t,null).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,o=s.accessors[e],i=void 0!==o.bufferView?s.bufferViews[o.bufferView]:{},a=(i.byteOffset||0)+r,c=this.A(o.type),u=F(o.componentType),f=i.byteStride||0,l={array:void 0,name:t,accessorName:e,byteLength:o.count*c*u.BYTES_PER_ELEMENT,componentType:o.componentType,count:o.count,type:o.type,itemSize:c,max:o.max,min:o.min,extensions:o.extensions};if(o.min&&(l.min=o.min),o.max&&(l.max=o.max),n)if(this.h)l.byteStride=f,l.byteOffset=a+(o.byteOffset||0),!f||f===c*u.BYTES_PER_ELEMENT||"indices"===t||"input"===t||"output"===t||t.indexOf("morph")>=0?(l.array=this._(n,o.count,c,a+(o.byteOffset||0),u),l.array.buffer.byteLength===l.byteLength&&(l.byteOffset=0)):l.array=new Uint8Array(n,a,i.byteLength);else if(o.interleaved){l.byteStride=0,l.byteOffset=0;const t=new u(o.count*c);if(l.array=G(t,n,o.count,c,f,a+(o.byteOffset||0),o.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){Y[0]=l.array[n],Y[1]=l.array[n+1],Y[2]=l.array[n+2],Y[3]=1;const r=O(Y,Y,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._(n,o.count,c,a+(o.byteOffset||0),u),l.byteOffset=l.array.byteOffset;else{l.array=new u(o.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}m(){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)}_(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=K.indexOf(t);return K[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.g(e).then(r=>{const{buffer:s,byteOffset:o}=r,i=$(s,o+(e.byteOffset||0),n);return t.content=i,t})}if(t.uri){if(D(t.uri)){const e=R(t.uri),n=$(e,0,e.byteLength);return t.content=n,Promise.resolve(t)}{const e=this.rootPath+"/"+t.uri;return X.get(e).then(e=>(t.content=e,t))}}return Promise.resolve(t)});return Promise.all(n).then(()=>t)}}class W extends J{constructor(t,e,n,r,s,o){super(r,s,o),this.rootPath=t,this.gltf=e,this.requests={},this.buffers={},this.glbBuffer=n,this.accessor=new Q(t,e,n)}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(N(t.name)&&(e.name=t.name),N(t.children)&&(e.children=t.children),N(t.jointName)&&(e.jointName=t.jointName),N(t.matrix)&&(e.matrix=t.matrix),N(t.rotation)&&(e.rotation=t.rotation),N(t.scale)&&(e.scale=t.scale),N(t.translation)&&(e.translation=t.translation),N(t.extras)&&(e.extras=t.extras),N(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=o(L,e.translation||k),r=a(z,e.rotation||j),c=i(V,e.scale||q);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,o;r.instanceTechnique&&r.instanceTechnique.values?(s=r.instanceTechnique,o=s.values.diffuse):(s=r,o=s.values.tex||s.values.diffuseTex||s.values.diffuse);const i={baseColorTexture:{index:o}};r.name&&(i.name=r.name),r.extensions&&(i.extensions=r.extensions),r.extras&&(i.extras=r.extras),e[n]=i}return e}M(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,o=this.buffers[e.bufferView]=new Uint8Array(this.glbBuffer.buffer,r,s);return this.getImageByBuffer(o,t)}return this.requestExternalImage(t)}O(t){const e=this.gltf.textures[t];if(!e)return null;const n=this.gltf.images[e.source];return this.M(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 o=this.gltf.samplers[s.sampler];return{format:s.format||6408,internalFormat:s.internalFormat||6408,type:s.type||5121,sampler:o,source:this.gltf.images[s.source]}}getMaterial(){return null}getAnimations(){return null}}class Z extends J{constructor(t,e,n,r,s,o){super(r,s,o),this.rootPath=t,this.gltf=e,this.glbBuffer=n,this.buffers={},this.requests={},this.accessor=new Q(t,e,n)}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 B(e,t),!N(t.weights)&&this.gltf.meshes&&N(e.mesh)?e.weights=this.gltf.meshes[e.mesh].weights:t.weights&&(e.weights=t.weights),e}O(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),!N(n))return null;const r=this.gltf.images[n];return this.M(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}};B(n,e);const s=N(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})}M(t){if(!N(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.I(e,t)}return null}I(t,e){const n=this.u(t,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(n,e)}u(t,e,n){n=n||0;const r=t.byteOffset+n,s=t.byteLength;return new Uint8Array(e,r,s)}v(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++)(N(t[n].input)||N(t[n].output))&&(e.push(this.accessor.p("input",t[n].input)),e.push(this.accessor.p("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 tt="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class et{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 et.readV1(r,e);if(2===s)return et.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=nt(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 o=new DataView(t,e+12);let i=0;for(;i<o.byteLength;){const a=o.getUint32(i,!0);i+=4;const c=o.getUint32(i,!0);if(i+=4,1313821514===c)n=nt(t,e+12+i,a);else if(5130562===c){s=e+12+i,r=a;break}i+=a}return{json:JSON.parse(n),glbBuffer:{byteOffset:s,buffer:t,byteLength:r}}}}function nt(t,e,n){if(tt){const r=new Uint8Array(t,e,n);return tt.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=rt[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 rt=[1,1,1,1,2,2,3,0],st=[0,0,0],ot=[0,0,0,1],it=[1,1,1],at={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},ct={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},ut={C(t,e,n,r,s,o,i,a){const c=N(t)?e.animations:[e.animations[0]],u={};for(let e=0;e<c.length;e++){const f=c[e],l=f.name||e;if(N(t)&&l!==t)continue;const y=f.channelsMap[n];if(y)for(let t=0;t<y.length;t++){const e=y[t];"translation"===e.target.path?(this.U(s,f.samplers[e.sampler],r,1),u.translation=h(st,s)):"rotation"===e.target.path?(this.P(o,f.samplers[e.sampler],r,1),u.rotation=U(ot,o)):"scale"===e.target.path?(this.U(i,f.samplers[e.sampler],r,1),u.scale=h(it,i)):"weights"===e.target.path&&a&&(this.U(a,f.samplers[e.sampler],r,a.length),u.weights=a)}}return u},U(t,e,n,r){switch(e.interpolation){case"LINEAR":{const s=this.N(ct,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.N(ct,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.N(ct,e,n,3*r);s&&(t=this.B(t,s,e.input.array,3*r));break}}return t},P(t,e,n){switch(e.interpolation){case"LINEAR":{const r=this.N(ct,e,n,1);r&&v(t,r.PREVIOUS,r.NEXT,r.INTERPOLATION);break}case"STEP":{const r=this.N(ct,e,n,1);r&&(t=M(t,...r.PREVIOUS));break}case"CUBICSPLINE":{const r=this.N(ct,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.B(t,r,e.input.array,3);for(let e=0;e<t.length;e++)t[e]=Math.cos(t[e])}break}}return t},F(t,e){const n=t.length;let r,s,o,i=0,a=n-1,c=Math.floor((i+a)/2);for(;i<=n-1&&a>=0;){if(i===a)return null;if(t[c]<=e&&e<=t[c+1]){const n=t[c];return r=c,s=c+1,o=(e-n)/(t[c+1]-n),{preIndx:r,nextIndex:s,interpolation:o}}e<t[c]?(a=c,c=Math.floor((i+a)/2)):t[c+1]<e&&(i=c,c=Math.floor((i+a)/2))}return null},N(t,e,n,r){const s=e.input.array,o=e.output.array,i=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.F(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 l=i*r;return t.PREVIOUS=o.subarray(t.PREINDEX*l,(t.PREINDEX+1)*l),t.NEXT=o.subarray(t.NEXTINDEX*l,(t.NEXTINDEX+1)*l),t},B(t,e,n,r){const s=e.INTERPOLATION,o=n[e.PREINDEX],i=n[e.NEXTINDEX];for(let n=0;n<3;n++){const a=e.PREVIOUS[r+n],c=(i-o)*e.PREVIOUS[2*r+n],u=e.NEXT[3+n],f=(i-o)*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))*u+(Math.pow(s,3)-Math.pow(s,2))*f;t[n]=l}return t},getAnimationClip(t,e,n,r){const s=t.nodes[e]&&t.nodes[e].weights;return y(st,...at.TRANSLATION),M(ot,...at.ROTATION),y(it,...at.SCALE),this.C(r,t,e,n,st,ot,it,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 o=e.channels;for(let t=0;t<o.length;t++){const n=o[t],i=e.samplers[n.sampler].input.array;i[i.length-1]>r&&(r=i[i.length-1]),i[0]<s&&(s=i[0])}const i=e.name||n;t.timeSpan[i]={max:r,min:s}}),t.timeSpan},getTimeSpanByName(t,e){const n=this.getTimeSpan(t);return n?N(e)?n[e]:n[Object.keys(n)[0]]:null}};let ft=!1;if("undefined"!=typeof OffscreenCanvas){let t;try{t=new OffscreenCanvas(2,2).getContext("2d")}catch(oe){}t&&"undefined"!=typeof createImageBitmap&&(ft=!0)}const lt="undefined"==typeof document?null:document.createElement("canvas");class ht{constructor(t,e,n){if(this.options=n||{},this.options.decoders||(this.options.decoders={}),e.buffer instanceof ArrayBuffer){const{json:n,glbBuffer:r}=et.read(e.buffer,e.byteOffset,e.byteLength);this.D(t,n,r)}else this.D(t,e);this.R=new Q(this.rootPath,this.gltf,this.glbBuffer),this.L()}L(){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")}}V(){const t=this.gltf.extensions;return t&&t.KHR_techniques_webgl?this.R.requestKHRTechniquesWebgl(t.KHR_techniques_webgl).then(e=>(t.KHR_techniques_webgl=e,t)):Promise.resolve(t)}load(t){t=t||{};const e=this.k(t),n=this.j(),r=this.q(),s=this.V();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 ut.getAnimationClip(t,e,n,r)}static getAnimationTimeSpan(t,e){return ut.getTimeSpanByName(t,e)}static getTypedArrayCtor(t){return F(t)}static readInterleavedArray(t,e,n,r,s,o,i){return G(t,e,n,r,s,o,i)}D(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=ft?pt.bind(this):this.options.requestImage||yt,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new Z(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{}),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 W(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{}),this.adapter.iterate((t,e,n)=>{e.id="accessor_"+n},"accessors"),this.adapter.iterate((t,e,n)=>{e.id="image_"+n},"images"))}G(t,e){if(t.children&&t.children.length>0){if(!("number"==typeof(n=t.children[0])&&isFinite(n)||function(t){return!P(t)&&("string"==typeof t||null!==t.constructor&&t.constructor===String)}(t.children[0])))return t;const r=t.children.map(t=>{const n=e[t];return n.nodeIndex=t,this.G(n,e)});t.children=r}var n;return t}k(t){return this.H(t).then(t=>{const e=this.scenes=[];let n;for(const e in t)t[e]=this.G(t[e],t),t[e].nodeIndex=Number(e)?Number(e):e;this.adapter.iterate((r,s,o)=>{const i={};s.name&&(i.name=s.name),s.nodes&&(i.nodes=s.nodes.map(e=>t[e])),this.gltf.scene===r&&(n=o),e.push(i)},"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 r})}H(t){return this.$(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})}X(){this.skins=[];const t=[];return this.adapter.iterate((e,n,r)=>{t.push(this.J(n).then(t=>{t.index=r,this.skins.push(t)}))},"skins"),t}J(t){const e=t.inverseBindMatrices;return this.adapter.accessor.p("inverseBindMatrices",e).then(e=>(t.inverseBindMatrices=e,e&&e.buffer&&this.transferables&&this.transferables.indexOf(e.buffer)<0&&this.transferables.push(e.buffer),t))}j(){const t=this.gltf.animations;return N(t)?this.adapter.getAnimations(t):null}$(t){this.meshes={};let e=[];return this.adapter.iterate((n,r,s)=>{e.push(this.K(r,t).then(t=>{t.index=s,this.meshes[n]=t}))},"meshes"),e=e.concat(this.X()),Promise.all(e)}K(t,e){const n=t.primitives.map(t=>this.Y(t,e)).filter(t=>!!t);return Promise.all(n).then(e=>{const n={};return B(n,t),n.primitives=e,n})}q(){const t=this.gltf.textures;if(!t)return null;const e=[];for(const n in t)e.push(this.adapter.O(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})}Y(t,e){let n;const r=[],s=t.extensions;if(N(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.p(`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:o,attributes:i}=s.KHR_draco_mesh_compression,a=this.gltf.bufferViews[o],c=this.R.g(a).then(n=>{const{buffer:r,byteOffset:s}=n;let{byteOffset:o}=a;const c=a.byteLength;o||(o=0);const u=new DataView(r,s+o,c),f={attributes:i,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.p(t,e[t]);n&&r.push(n)}if(N(t.indices)){const e=this.adapter.accessor.p("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 o={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,o=s.length/r;for(let e=0;e<o;e++)for(let o=0;o<r;o++){const i=e*r+o;s[i]<t[o]&&(t[o]=s[i]),s[i]>n[o]&&(n[o]=s[i])}if(e.quantization){const r=e.quantization,s=r.range/(1<<r.quantizationBits),o=r.minValues;p(t,t,s),m(t,t,o),p(n,n,s),m(n,n,o)}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&&(o.indices=n),r&&(o.morphTargets=r),o.mode=N(t.mode)?t.mode:4,N(t.extras)&&(o.extras=t.extras),o})}}function yt(t,e){const n=new Image;n.crossOrigin="",n.onload=()=>{if(!lt)return void e(new Error("There is no canvas to draw image!"));lt.width=n.width,lt.height=n.height;const t=lt.getContext("2d",{willReadFrequently:!0});t.drawImage(n,0,0,n.width,n.height);const r=t.getImageData(0,0,n.width,n.height),s={width:n.width,height:n.height,data:new Uint8Array(r.data)};e(null,s)},n.onerror=function(t){e(t)},n.src=t}let mt,dt;function pt(t,e){mt||(mt=new OffscreenCanvas(2,2),dt=mt.getContext("2d",{willReadFrequently:!0})),fetch(t).then(t=>t.arrayBuffer()).then(t=>{const e=new Blob([new Uint8Array(t)]);return createImageBitmap(e)}).then(t=>{let{width:n,height:r}=t;bt(n)||(n=wt(n)),bt(r)||(r=wt(r));const s=this.options.maxTextureSize;s&&(n=Math.min(s,n),r=Math.min(s,r)),mt.width=n,mt.height=r,dt.drawImage(t,0,0,n,r),t.close();const o=dt.getImageData(0,0,n,r);e(null,{width:n,height:r,data:new Uint8Array(o.data)})}).catch(t=>{console.warn(t),e(t)})}function bt(t){return 0==(t&t-1)&&0!==t}function wt(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}function Tt(t){return"object"==typeof t&&!!t}function gt(t){return t/Math.PI*180}function At(t){return Math.sign?Math.sign(t):0===(t=+t)||isNaN(t)?Number(t):t>0?1:-1}const _t=[1,1,1,1,2,2,3,0];function St(t){const e=t.length;let n="";for(let r=0;r<e;){let s=t[r++];if(128&s){let n=_t[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 Mt=[1/6378137,1/6378137,1/6356752.314245179],Ot=[1/40680631590769,1/40680631590769,1/40408299984661.445],xt=new Array(3),It=new Array(3),vt=new Array(3);function Ct(t,e){const n=Ot,r=function(t,e,n,r,s){const o=e[0],i=e[1],a=e[2],c=n[0],u=n[1],f=n[2],l=o*o*c*c,h=i*i*u*u,y=a*a*f*f,m=l+h+y,d=Math.sqrt(1/m),b=p(Ut,e,d);if(m<s)return isFinite(d)?b:void 0;const w=r[0],T=r[1],g=r[2],A=Et;A[0]=b[0]*w*2,A[1]=b[1]*T*2,A[2]=b[2]*g*2;let _,S,M,O,x,I,v,C,U,E,P,N=(1-d)*Pt(e)/(.5*Pt(A)),B=0;do{N-=B,M=1/(1+N*w),O=1/(1+N*T),x=1/(1+N*g),I=M*M,v=O*O,C=x*x,U=I*M,E=v*O,P=C*x,_=l*I+h*v+y*C-1,S=l*U*w+h*E*T+y*P*g;B=_/(-2*S)}while(Math.abs(_)>1e-12);return t[0]=o*M,t[1]=i*O,t[2]=a*x,t}(xt,e,Mt,n,.1);let s=_(It,r,n);s=function(t,e){const n=e[0],r=e[1],s=e[2];let o=n*n+r*r+s*s;o>0&&(o=Math.sqrt(o),t[0]=e[0]/o,t[1]=e[1]/o,t[2]=e[2]/o);return t}(s,s);const o=A(vt,e,r),i=Math.atan2(s[1],s[0]),a=Math.asin(s[2]),c=At(w(o,e))*Pt(o);return t[0]=gt(i),t[1]=gt(a),t[2]=c,t}const Ut=new Array(3),Et=new Array(3);function Pt(t){return f(t)}function Nt(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 Bt(t,e){let n="";for(let r=0;r<4;r++){const s=t.getUint8(e+r);n+=String.fromCharCode(s)}return n}const Ft="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function Dt(t,e,n){const r=new Uint8Array(t,e,n);return Ft?JSON.parse(Ft.decode(r)):JSON.parse(St(r))}function Rt(t,e,n){const r=new Uint8Array(t,e,n);return Ft?JSON.parse(Ft.decode(r)):JSON.parse(St(r))}function Lt(t,e,n){return{offset:e,byteLength:n}}function zt(t,e,n,r){const{byteOffset:s,componentType:o,type:i}=t,{ctor:a,type:c}=function(t){return jt[t]}(o||"UNSIGNED_SHORT"),u=function(t){if(!t)return 1;return kt[t]}(i);return{byteStride:0,byteOffset:s+n,itemSize:u,count:r*u,componentType:c,array:new a(e,n+s,r*u)}}function Vt(t,e,n,r){const s=zt(t,e,n,r);return s.array.buffer.byteLength!==e.byteLength&&(s.array=s.array.slice()),s}const kt={"SCALAR":1,"VEC2":2,"VEC3":3,"VEC4":4};const jt={"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 qt(t){for(const e in jt)if(t===jt[e].ctor)return jt[e].type;throw new Error("unrecognized ctor:"+t)}function Gt(t,e,n,r){const s=t,o=e.length/3;for(let t=0;t<o;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 Ht(t,e,n){const r=t.getUint32(12,!0),s=t.getUint32(16,!0),o=t.getUint32(20,!0),i=t.getUint32(24,!0),a=t.buffer;let c,u={},f={},l=null;r>0&&(u=Dt(a,e,r),e+=r),s>0&&(c=function(t,e,n){return{offset:e,byteLength:n}}(0,e,s),e+=s),o>0&&(f=Rt(a,e,o),e+=o);const h=Lt(0,e,i);return l=a.slice(h.offset,h.offset+h.byteLength),n.push(l),{featureTable:u,featureTableBin:c,batchTable:f,batchTableBin:l}}const $t={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"}},Xt={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},Jt={},Kt={east:[],north:[],up:[],west:[],south:[],down:[]};let Yt=[],Qt=[],Wt=[];const Zt=[0,0,0];const te=function(t,e){const n=$t[t][e];let r;const s=t+e;return Jt[s]?r=Jt[s]:(r=function(r,s,o){if(function(t,e){var n=t[0],r=t[1],s=t[2],o=e[0],i=e[1],a=e[2];return Math.abs(n-o)<=1e-6*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(r-i)<=1e-6*Math.max(1,Math.abs(r),Math.abs(i))&&Math.abs(s-a)<=1e-6*Math.max(1,Math.abs(s),Math.abs(a))}(r,Zt))h(Yt,Xt[t]),h(Qt,Xt[e]),h(Wt,Xt[n]);else if(Nt(r[0],0,1e-14)&&Nt(r[1],0,1e-14)){const s=At(r[2]);h(Yt,Xt[t]),"east"!==t&&"west"!==t&&p(Yt,Yt,s),h(Qt,Xt[e]),"east"!==e&&"west"!==e&&p(Qt,Qt,s),h(Wt,Xt[n]),"east"!==n&&"west"!==n&&p(Wt,Wt,s)}else{!function(t,e){d(e,t,Ot),b(e,e)}(r,Kt.up);const s=Kt.up,o=Kt.east;o[0]=-r[1],o[1]=r[0],o[2]=0,b(Kt.east,o),T(Kt.north,s,o),p(Kt.down,Kt.up,-1),p(Kt.west,Kt.east,-1),p(Kt.south,Kt.north,-1),Yt=Kt[t],Qt=Kt[e],Wt=Kt[n]}return o[0]=Yt[0],o[1]=Yt[1],o[2]=Yt[2],o[3]=0,o[4]=Qt[0],o[5]=Qt[1],o[6]=Qt[2],o[7]=0,o[8]=Wt[0],o[9]=Wt[1],o[10]=Wt[2],o[11]=0,o[12]=r[0],o[13]=r[1],o[14]=r[2],o[15]=1,o},Jt[s]=r),r}("east","north"),ee={5120:Int8Array,5122:Int16Array,5124:Int32Array,5121:Uint8Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};function ne(t){for(const e in ee)if(t===ee[e])return+e;throw new Error("unrecognized ctor:"+t)}\n/*!\n * @maptalks/gl v0.88.0\n * LICENSE : UNLICENSED\n * (c) 2016-2023 maptalks.com\n */const re=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")},se=re(),oe=se.gl_trans__coders=se.gl_trans__coders||{};oe.inject=function(t){const e=t.toString(),n=e.indexOf("{")+1,r=e.substring(0,n),s=se.gl_trans__coders=se.gl_trans__coders||{};let o=`${r}\\n const _____getGlobal = ${re.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&&(o+=\'tran_____scoders["\'+t+\'"] =\'+s[t].toString()+"\\n;");return o+="\\n"+e.substring(r.length),o},oe.registerTranscoder=function(t,e){oe[t]=e},oe.getTranscoder=function(t){return oe[t]};let ie=null;function ae(){return ie||(ie={"image/crn":oe.crn&&oe.crn(),"image/ktx2":oe.ktx2&&oe.ktx2(),"image/cttf":oe.ktx2&&oe.ktx2(),"draco":oe.draco&&oe.draco()}),ie}class ce{constructor(t,e,n){this.s=t,this.W=e||ht,this.o=n,this.Z=ae()}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.tt(t,e,n,r,s)):X.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.tt(t,s,n,r)})}tt(t,e,n,r,s){const o=s&&s.maxTextureSize,i=this.et(e,n,r,t);if(i.error)return Promise.resolve(i);const a=t.substring(0,t.lastIndexOf("/")),c=new this.W(a,i.glb,{transferable:!0,requestImage:this.s,decoders:this.Z,supportedFormats:this.o,maxTextureSize:o});return c.load({skipAttributeTransform:!1}).then(e=>{e.url=`${t}-${n}-${r}`;const s=c.transferables;for(let t=0;t<i.transferables.length;t++)s.indexOf(i.transferables[t])<0&&s.push(i.transferables[t]);return{magic:"b3dm",count:i.count,transferables:s,featureTable:i.featureTable,batchTable:i.batchTable,batchTableBin:i.batchTableBin,gltf:e}})}et(t,e,n,r){const s=new DataView(t,e,n),o=s.getUint32(4,!0);if(1!==o){const t="Unsupported b3dm version: "+o+", 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 i,a=s.getUint32(12,!0),c=s.getUint32(16,!0),u=s.getUint32(20,!0),f=s.getUint32(24,!0),l=28+e;u>=570425344?(l-=8,i=a,u=c,f=0,a=0,c=0):f>=570425344&&(l-=4,i=u,u=a,f=c,a=0,c=0);const h=[t];let y,m,d;if(a>0?(y=Dt(t,l,a),l+=a,i=y.BATCH_LENGTH):y={"BATCH_LENGTH":i},c>0&&(l+=c),u>0&&(m=Rt(t,l,u),l+=u,f>0)){const e=Lt(0,l,f);d=t.slice(e.offset,e.offset+e.byteLength),l+=f,h.push(d)}const p=y.BATCH_LENGTH,b={};if(y&&y.BATCH_ID){b.BATCH_ID=Vt(y.BATCH_ID,t,(void 0).offset,p);const e=b.BATCH_ID.array&&b.BATCH_ID.array.buffer;e&&h.indexOf(e)<0&&h.push(e)}return{count:i,transferables:h,featureTable:y,batchTable:m,batchTableBin:d,b3dm:b,glb:{buffer:t,byteOffset:l,byteLength:s.byteLength+s.byteOffset-l}}}nt(){return null}}class ue{constructor(t,e,n,r){this.s=t,this.W=e||ht,this.o=n,this.Z=ae(),this.rt=r}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.tt(t,e,n,r,s)):X.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.tt(t,s,n,r)})}tt(t,e,n,r,s){return this.st(t,e,n,r,s).then(({gltf:s,transferables:o})=>{const i=this.ot(e,n,r,t);if(i.error)return Promise.resolve(i);for(let t=0;t<o.length;t++)-1===i.transferables.indexOf(o[t])&&i.transferables.push(o[t]);return delete s.transferables,Promise.resolve({magic:"i3dm",count:i.count,transferables:i.transferables,featureTable:i.featureTable,batchTable:i.batchTable,batchTableBin:i.batchTableBin,i3dm:i.i3dm,gltf:s})})}st(t,e,n,r,s){const o=s&&s.maxTextureSize,i={transferable:!0,requestImage:this.s,decoders:this.Z,supportedFormats:this.o,maxTextureSize:o},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=St(new Uint8Array(e,c+n,a.byteLength-c));-1==r.indexOf("://")&&(r=t.substring(0,t.lastIndexOf("/"))+"/"+r);return r.indexOf(".glb")>0?X.getArrayBuffer(r,{}).then(t=>this.it(r,{buffer:t.data,byteOffset:0},i)):X.getJSON(r,{}).then(t=>this.it(r,t,i))}{const r={buffer:e,byteOffset:c+n,byteLength:a.byteLength-c};return this.it(t,r,i)}}it(t,e,n){const r=t.substring(0,t.lastIndexOf("/")),s=new this.W(r,e,n);return s.load({skipAttributeTransform:!0}).then(n=>{let r=0,o=0;return e.buffer&&(r=e.byteOffset||0,o=e.byteLength||0),n.url=`${t}-${r}-${o}`,{transferables:s.transferables,gltf:n}})}ot(t,e,n,r){const s=new DataView(t,e,n),o=s.getUint32(4,!0);if(1!==o){const t="Unsupported pnts version: "+o+", 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 i=[t],{featureTable:a,featureTableBin:c,batchTable:u,batchTableBin:f}=Ht(s,32+e,i),l={},h=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;l.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},i.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:h,componentType:5126,array:this.ct(new Uint16Array(t,r+c.offset,3*h),e,n)},i.push(l.POSITION.array.buffer)}if(a.BATCH_ID){l.BATCH_ID=Vt(a.BATCH_ID,t,c.offset,h);const e=l.BATCH_ID.array&&l.BATCH_ID.array.buffer;e&&i.indexOf(e)<0&&i.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;l.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},i.push(l.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,l.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},i.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:h,componentType:5126,array:this.ut(new Uint16Array(t,e+c.offset,2*h))},i.push(l.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,l.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.ut(new Uint16Array(t,e+c.offset,2*h))},i.push(l.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;l.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,h).slice()},i.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:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},i.push(l.SCALE_NON_UNIFORM.array.buffer)}return{count:h,batchTable:u,batchTableBin:f,featureTable:a,i3dm:l,transferables:i}}ut(t){const e=t.length/2,n=new Float32Array(3*e),r=[];for(let s=0;s<e;s++)fe(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}ct(t,e,n){return Gt(new Float32Array(t.length),t,e,n)}nt(){return null}}function fe(t,e,n,r){if(t[0]=le(e,r),t[1]=le(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]))*he(e),t[1]=(1-Math.abs(e))*he(t[1])}return b(t,t)}function le(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 he(t){return t<0?-1:1}class ye{constructor(){}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.tt(t,e,n,r)):X.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.tt(t,s,n,r)})}tt(t,e,n,r){return this.ft(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})}ft(t,e,n,r){const s=new DataView(t,e,n),o=s.getUint32(4,!0);if(1!==o){const t="Unsupported pnts version: "+o+", 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 i=[t],{featureTable:a,featureTableBin:c,batchTable:u,batchTableBin:f}=Ht(s,e+28,i),l=a.QUANTIZED_VOLUME_OFFSET,h=a.QUANTIZED_VOLUME_SCALE,y=a.POINTS_LENGTH;let m,d={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){d=a.extensions["3DTILES_draco_point_compression"],m=new DataView(t,d.byteOffset+c.offset,d.byteLength);const e={attributes:d.properties,useUniqueIDs:!1};return this.lt||(this.lt=ae().draco),this.lt(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.ht(t,e.attributes,c.offset,y,i,l,h);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:qt(t.constructor),array:t},i.push(t.buffer)}else if(a.BATCH_ID||Object.keys(u).length){a.BATCH_ID?r.BATCH_ID=Vt(a.BATCH_ID,t,c.offset,y):r.BATCH_ID=me(y);const e=r.BATCH_ID.array&&r.BATCH_ID.array.buffer;e&&i.indexOf(e)<0&&i.push(e)}return{count:y,batchTable:u,batchTableBin:f,featureTable:a,pnts:r,transferables:i}})}const p=this.ht(t,a,c.offset,y,i,l,h);if(a.BATCH_ID||Object.keys(u).length){a.BATCH_ID?p.BATCH_ID=Vt(a.BATCH_ID,t,c.offset,y):p.BATCH_ID=me(y);const e=p.BATCH_ID.array&&p.BATCH_ID.array.buffer;e&&i.indexOf(e)<0&&i.push(e)}return Promise.resolve({count:y,batchTable:u,batchTableBin:f,featureTable:a,pnts:p,transferables:i})}ht(t,e,n,r,s,o,i){const a={};if(e.POSITION){let{byteOffset:o,array:i}=e.POSITION;o=o||0;const c=i?0:n;if(!i){const e=t.slice(o+c,o+c+3*r*4);i=new Float32Array(e)}a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:i},s.push(i.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.ct(u||new Uint16Array(t,c+f,3*r),o,i)},s.push(a.POSITION.array.buffer)}if(e.RGBA){let{byteOffset:o,array:i}=e.RGBA;o=o||0;const c=i?0:n;if(!i){const e=t.slice(o+c,o+c+4*r);i=new Uint8Array(e)}a.RGBA={byteStride:0,byteOffset:0,itemSize:4,count:r,componentType:5121,array:i},s.push(i.buffer)}else if(e.RGB){let{byteOffset:o,array:i}=e.RGB;o=o||0;const c=i?0:n;if(!i){const e=t.slice(o+c,o+c+3*r);i=new Uint8Array(e)}a.RGB={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5121,array:i},s.push(i.buffer)}else if(e.RGB565){let{byteOffset:o,array:i}=e.RGB565;o=o||0;const c=i?0:n;if(!i){const e=t.slice(o+c,o+c+2*r);i=new Uint16Array(e)}a.RGB565={byteStride:0,byteOffset:0,itemSize:1,count:r,componentType:5123,array:i},s.push(i.buffer)}if(e.NORMAL){let{byteOffset:o,array:i}=e.NORMAL;o=o||0;const c=i?0:n;if(!i){const e=t.slice(o+c,o+c+3*r*4);i=new Float32Array(e)}a.NORMAL={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:i},s.push(i.buffer)}else if(e.NORMAL_OCT16P){let{byteOffset:o,array:i}=e.NORMAL_OCT16P;o=o||0;const c=i?0:n;if(!i){const e=t.slice(o+c,o+c+2*r);i=new Uint8Array(e)}a.NORMAL_OCT16P={byteStride:0,byteOffset:0,itemSize:2,count:r,componentType:5121,array:i},s.push(i.buffer)}return a}ct(t,e,n){return Gt(new Float32Array(t.length),t,e,n)}nt(){return null}}function me(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:qt(e),array:r}}class de{constructor(t,e,n,r){this.o=n,this.s=t,this.W=e||ht,this.rt=r}load(t,e,n=0,r=0,s){return e?this.tt(t,e,n,r,s):X.getArrayBuffer(t,{}).then(e=>{const s=e.data;return this.tt(t,s,n,r)})}tt(t,e,n,r,s){r||(r=e.byteLength);const o=this.yt(e,t,n,r),i=[];for(let n=0;n<o.length;n++){let r;if("b3dm"===o[n].magic)r=new ce(this.s,this.W,this.o);else if("i3dm"===o[n].magic)r=new ue(this.s,this.W,this.o,this.rt);else if("pnts"===o[n].magic)r=new ye;else{if("cmpt"!==o[n].magic){console.warn("Unsupported magic in CMPT tile:",o[n].magic);continue}r=new de(this.s,this.W,this.o,this.rt)}i.push(r.load(t,e,o[n].offset,o[n].byteLength,s).then(t=>t))}return Promise.all(i).then(t=>({magic:"cmpt",tiles:t}))}yt(t,e,n,r){const s=new DataView(t,n,r),o=s.getUint32(4,!0);if(1!==o){const t="Unsupported cmpt version: "+o+", url:"+e;return console.warn(t),{error:t}}if(16===s.byteLength)return[];const i=[],a=s.getUint32(12,!0);let c=16;for(let e=0;e<a;e++){const e=Bt(s,c),r=s.getUint32(c+8,!0);i.push({magic:e,buffer:t,offset:c+n,byteLength:r}),c+=r}return i}}function pe(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=[];Se(r[n],s,t,e)}}}const be=[],we=[],Te=[],ge=[0,0,0],Ae=I([]),_e=[1,1,1];function Se(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=o(be,t.translation||ge),n=a(we,t.rotation||Ae),r=i(Te,t.scale||_e);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++)Se(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),o=s.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 Me(t,e){let{byteOffset:n,byteStride:r,count:s}=t;const{componentType:o,itemSize:i}=t,a=t.array.buffer,c=o?ht.getTypedArrayCtor(o):t.array.constructor;if(n=void 0===n?t.array.byteOffset:n,r=r||0,s=s||t.array.length/i,(!r||r===i*c.BYTES_PER_ELEMENT)&&n%c.BYTES_PER_ELEMENT==0){const t=new c(a,n,s*i);for(let r=0;r<s*i;r+=i){e(new c(t.buffer,n+r*c.BYTES_PER_ELEMENT,i),r/i)}return}const u=new Uint8Array(i*c.BYTES_PER_ELEMENT);r||(r=i*c.BYTES_PER_ELEMENT);for(let t=0;t<s;t++){const s=new Uint8Array(a,r*t+n,i*c.BYTES_PER_ELEMENT);u.set(s);e(new c(u.buffer),t),s.set(u)}}var Oe=Ue("DXT1"),xe=Ue("DXT3"),Ie=Ue("DXT5"),ve=Ue("DX10"),Ce=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 Oe:e=8,n="dxt1";break;case xe:e=16,n="dxt3";break;case Ie:e=16,n="dxt5";break;case 116:n="rgba32f";break;case ve:var o=new Uint32Array(t.slice(128,148));n=o[0];var i=o[1];if(o[2],o[3],o[4],3!==i||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 l,h=r[4],y=r[3],m=r[1]+4,d=h,p=y,b=[];s===ve&&(m+=20);if(f)for(var w=0;w<6;w++){if("rgba32f"!==n)throw new Error("Only RGBA32f cubemaps are supported");h=d,y=p;for(var T=Math.log(h)/Math.log(2)+1,g=0;g<T;g++)l=h*y*16,b.push({offset:m,length:l,shape:[h,y]}),g<u&&(m+=l),h=Math.floor(h/2),y=Math.floor(y/2)}else for(g=0;g<u;g++)l=Math.max(4,h)/4*Math.max(4,y)/4*e,b.push({offset:m,length:l,shape:[h,y]}),m+=l,h=Math.floor(h/2),y=Math.floor(y/2);return{shape:[d,p],images:b,format:n,flags:c,cubemap:f}};function Ue(t){return t.charCodeAt(0)+(t.charCodeAt(1)<<8)+(t.charCodeAt(2)<<16)+(t.charCodeAt(3)<<24)}const Ee=Math.PI/180,Pe=6378137*Math.PI/180;function Ne(t,e,n){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 o;o=0===s?0:Math.log(Math.tan((90+s)*Ee/2))/Ee;return t[0]=r*Pe,t[1]=o*Pe,t}(t,e);if("EPSG:4326"===n||"EPSG:4490"===n||"identity"===n)return Be(t,e);if("baidu"===n)return Be(t,e);throw new Error("unsupported projection:"+n)}function Be(t,e){return t[0]=e[0],t[1]=e[1],t}const Fe=r([]),De=ae().draco,Re=ae().ktx2,Le={"pbrMetallicRoughness":{"baseColorFactor":[.5,.5,.5,1],"metallicFactor":0,"roughnessFactor":.5}},ze={"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 Ve(t,e,n,s){const o=[],i=[],a=[];for(let e=0;e<t.meshes.length;e++){const{geometry:n,material:r}=t.meshes[e],s=X.getArrayBuffer(n.url);s.xhr.url=n.url,a.push(s.xhr);const c=s.then(t=>({buffer:t}));o.push(c);const u=[];if(Xe(r,u),u.length){const t=u.map(t=>{const e=X.getArrayBuffer(t.url);return e.xhr.url=t.url,a.push(e.xhr),e.then(e=>e&&e.status?null:{buffer:e,mimeType:t.mimeType,format:t.format})});o.push(...t)}i[e]=u.length}const c=Promise.all(o).then(o=>{for(let t=0;t<o.length;t++)if(!o[t]||!o[t].buffer)return Promise.resolve(null);const a=[];let c=0;for(let t=0;t<i.length;t++){const e=i[t];a.push({geoBuffer:{data:o[c].buffer.data},textureBuffers:o.slice(c+1,e+c+1).map(t=>({data:t.buffer.data,mimeType:t.mimeType,format:t.format}))}),c+=1+e}return function(t,e,n,s,o){const i={asset:{generator:"i3s",version:"2.0"},extensions:{},scene:0,scenes:[{nodes:[]}],nodes:{},meshes:{},materials:[],skins:[],animations:null,textures:[],transferables:[]},a=[];for(let c=0;c<t.meshes.length;c++){let{material:u}=t.meshes[c];const{geometry:f}=t.meshes[c];let l;const h=e[c].geoBuffer.data;if(!h)continue;const y=Ze(h);l=y?je(i,c,f,h,t.transform,t.center,o):Ge(i,c,f,h,t.transform,t.center,o),a.push(l),i.nodes[c]={mesh:c,nodeIndex:c,matrix:r([])},i.scenes[0].nodes[c]=i.nodes[c],u||(u=Le);const m=$e(c,i,u,e[c].textureBuffers,n,s);a.push(m)}return Promise.all(a).then(()=>({gltf:i,featureTable:{BATCH_LENGTH:0},transferables:i.transferables}))}(t,a,e,s,n)});return c.xhr=a,c}const ke={"magFilter":9728,"minFilter":9728,"wrapR":33071,"wrapS":33071,"wrapT":33071};function je(t,e,n,r,s,o,i){const a=n.info.compressedAttributes.attributes.reduce((t,e,n)=>{const r=ze[e];if(!r)return t;return t[r.name||e]=n,t},{});return De(r,{attributes:a,metadatas:{"POSITION":[{name:"i3s-scale_x",type:"double"},{name:"i3s-scale_y",type:"double"}]},useUniqueIDs:!1,skipAttributeTransform:!1}).then(n=>He(n,t,e,s,o,i))}const qe={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 Ge(t,e,n,r,s,o,i){const a={vertexCount:0},c=new DataView(r);try{let t=0;a.vertexCount=c.getUint32(t,1),t+=4,a.featureCount=c.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++)qe[n[e]]?t=qe[n[e]](a,r,t):console.error("Unknown decoder for",n[e])}else{const e=n.info;let s=e.ordering,o=e.featureAttributeOrder;const i=null;i&&i.geometryData&&i.geometryData[0]&&i.geometryData[0].params;for(let e=0;e<s.length;e++){const n=qe[s[e]];n||console.log(s[e]),t=n(a,r,t)}for(let e=0;e<o.length;e++){const n=qe[o[e]];n||console.log(o[e]),t=n(a,r,t)}}}catch(t){}a.scale_x=1,a.scale_y=1;const u={};for(const t in a){const e=ze[t]&&ze[t].name;e&&(u[e]=a[t])}if(a.faceRange){const t=a.faceRange.array,e=t.length/2,n=(f=e)<=255?Uint8Array:f<=65535?Uint16Array:Uint32Array,r=new n(u.POSITION.array.length/3);for(let e=0;e<t.length-1;e+=2){const n=e/2,s=t[e],o=t[e+1];for(let t=s;t<=o;t++)r[3*t]=n,r[3*t+1]=n,r[3*t+2]=n}u._BATCHID={componentType:ne(n),array:r,itemSize:1,count:r.length,type:"SCALAR"}}var f;return He({attributes:u},t,e,s,o,i)}function He(t,e,n,r,s,o){const i={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 a=function(t,e,n,r){const s=n;let o,i=[0,0,0,1];const a=[0,0],u=Ne([],n,r);u[2]=n[2];const f=e&&c(Fe,e);return Me(t,t=>(i[0]=t[0],i[1]=t[1],i[2]=t[2],f||(i=g(i,i,e)),s&&m(i,i,s),Ne(a,i,r),o=i[2],t[0]=a[0]-u[0],t[1]=a[1]-u[1],t[2]=o-u[2],t)),u}(t.attributes.POSITION,r,s,o);e.meshes[n]={primitives:[i],index:n},e.extensions.MAPTALKS_RTC={projCenter:a},e.extensions.CESIUM_RTC={rtcCoord:s};for(const n in t.attributes)We(e.transferables,t.attributes[n].array.buffer);return t.indices&&We(e.transferables,t.indices.array.buffer),i}function $e(t,e,n,r,s,o){const i=r.map(t=>function(t,e,n,r,s){if("dds"===e){const e=Ce(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:ke,format:s})}if("png"===e||"jpg"===e)return function(t,e){Je||(Je=new OffscreenCanvas(2,2),Ke=Je.getContext("2d",{willReadFrequently:!0}));const n=new Blob([new Uint8Array(t)]);return createImageBitmap(n).then(t=>{let{width:n,height:r}=t;Ye(n)||(n=Qe(n)),Ye(r)||(r=Qe(r));const s=e;s&&(n=Math.min(s,n),r=Math.min(s,r)),Je.width=n,Je.height=r,Ke.drawImage(t,0,0,n,r),t.close();const o=Ke.getImageData(0,0,n,r);return{width:n,height:r,array:new Uint8Array(o.data)}}).catch(()=>({width:2,height:2,array:new Uint8Array(4)}))}(t,s).then(t=>{t.mimeType=n;return{image:t,sampler:ke,format:6408}});if("ktx2"===e)return Re(t,r).then(t=>(t.mimeType=n,{image:t,sampler:ke,format:t.format}));return null}(t.data,t.format,t.mimeType,s,o).then(t=>{if(t.image)if(t.image.array)We(e.transferables,t.image.array.buffer);else if(t.image.mipmap)for(let n=0;n<t.image.mipmap.length;n++)We(e.transferables,t.image.mipmap[n].buffer);return t}));return Promise.all(i).then(r=>{!function t(e,n,r,s){const o=JSON.parse(JSON.stringify(r)),i=n.textures;s.ptr||(s.ptr=0);for(const e in r)r[e]&&r[e].url?(i.push(s[s.ptr++]),o[e]={index:i.length-1},void 0!==r[e].factor&&(o[e].scale=r[e].factor)):Tt(r[e])&&(o[e]=t(-1,n,r[e],s));e>=0&&(n.materials[e]=o);return o}(t,e,n,r)})}function Xe(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}):Tt(t[n])&&Xe(t[n],e)}let Je,Ke;function Ye(t){return 0==(t&t-1)&&0!==t}function Qe(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}function We(t,e){e&&(t.indexOf(e)>=0||t.push(e))}function Ze(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 tn=[1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],en=[0,0,1,0,0,1,0,0,-1,0,0,0,0,0,0,1],nn="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;let rn,sn=!1;if("undefined"!=typeof OffscreenCanvas){try{rn=new OffscreenCanvas(2,2).getContext("2d",{willReadFrequently:!0})}catch(t){}rn&&"undefined"!=typeof createImageBitmap&&(sn=!0)}const on=r([]),an=[0,0,0],cn=[],un=[],fn=[],ln=[],hn={"POSITION":1,"TEXCOORD_0":1,"TEXCOORD_1":1,"NORMAL":1,"TANGENT":1};class yn{constructor(t,e,n,r){this.id=t,this.options=e,this.dt=this.requestImage.bind(this),this.pt=n,this.bt={},r(null,{},[])}wt(t){this.Tt||(this.o=t,this.gt=new ye,this.Tt=new ce(this.dt,ht,t),this.At=new ue(this.dt,ht,t))}requestImage(t,e){sn?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,rn.drawImage(t,0,0);const n=rn.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.pt("requestImage",{url:t},null,e)}loadTile(t,e){this.wt(t.supportedFormats);const n=t.service,r=t.url,s=t.arraybuffer;if(function(t){return t.indexOf("i3s:")>=0}(r)){const s=t.i3sInfo,o=n.maxTextureSize||1024,i=Ve(s,t.supportedFormats,this.options.projection,o);return i.then(t=>{if(delete this.bt[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._t(t.gltf),e(null,t,n)}),void(this.bt[r]=i.xhr)}if(s){delete this.bt[r];const n=Bt(new DataView(s),0);if("{"===n[0]||" "===n[0]||"<"===n[0]){const n=function(t,e,n){if(nn){const r=new Uint8Array(t,e,n);return nn.decode(r)}return St(new Uint8Array(t,e,n))}(s,0,s.byteLength),o=JSON.parse(n);this.St(t.rootIdx,o,s,r,e)}else this.Mt(s,r,t,n,e)}else{let s=n.urlParams;s&&(s=(r.indexOf("?")>0?"&":"?")+s);const o=r.replace(/\\+/g,"%2B");let i=X.getArrayBuffer(o+(s||""),n.fetchOptions);const a=i.xhr;i=i.then(n=>{delete this.bt[r],n&&n.status?e(n):(t.arraybuffer=n&&n.data,this.loadTile(t,e))}).catch(t=>{delete this.bt[r],e(t)}),this.bt[r]=a}}Mt(t,e,n,r,s){const o=n.service;if("b3dm"===r){this.Tt.load(e,t,0,0,{maxTextureSize:o.maxTextureSize||1024}).then(t=>{if(t.error)return void s(t);const{content:e,transferables:r}=this.Ot(t,n);this._t(e.gltf),s(null,e,r)}).catch(t=>{s(t)})}else if("pnts"===r){const r=n.transform;this.gt.load(e,t).then(t=>{const{content:e,transferables:o}=this.xt(t,r,n.rootIdx);this.It(e),s(null,e,o)})}else if("i3dm"===r){const r=n.transform;this.At.load(e,t,0,0,{maxTextureSize:o.maxTextureSize||1024}).then(t=>{const{content:e,transferables:o}=this.xt(t,r,n.rootIdx);this._t(e.gltf),s(null,e,o)})}else if("cmpt"===r){new de(this.dt,ht,this.o,o.maxTextureSize||1024).load(e,t,0,0,{maxTextureSize:o.maxTextureSize||1024}).then(t=>{const{content:e,transferables:r}=this.vt(t,n);this.Ct(e),s(null,e,r)}).catch(t=>{s(t)})}}Ct(t){t.content?t.content.forEach(t=>{this.Ct(t)}):this._t(t.gltf)}_t(t){if(!t||!t.meshes||t.extensionsUsed&&t.extensionsUsed.indexOf("KHR_techniques_webgl")>-1)return;const e=t.meshes;for(const t in e){e[t].primitives.forEach(t=>{t.compressed_int16_params={};const e=t.attributes;for(const n in e)if(hn[n]&&e[n].array&&e[n].array instanceof Float32Array){const{array:r,range:s}=Tn(e[n].array,e[n].min,e[n].max);e[n].array=r,t.compressed_int16_params[n]=s}})}}It(t){if(!t||!t.pnts)return;const e=t.pnts;t.compressed_int16_params={};for(const n in e)if(hn[n]&&e[n].array&&e[n].array instanceof Float32Array){const{array:r,range:s}=Tn(e[n].array,e[n].min,e[n].max);e[n].array=r,t.compressed_int16_params[n]=s}}Ut(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)}vt(t,e){const{tiles:n}=t,r={magic:"cmpt",content:[]},s=[];for(let t=0;t<n.length;t++){const{magic:o}=n[t];if("b3dm"===o){const{content:o,transferables:i}=this.Ot(n[t],e);bn(s,i),r.content.push(o)}else if("i3dm"===o||"pnts"===o){const{transform:o,rootIdx:i}=e,{content:a,transferables:c}=this.xt(n[t],o,i);bn(s,c),r.content.push(a)}else if("cmpt"===o){const{content:o,transferables:i}=this.vt(n[t],e);bn(s,i),r.content.push(o)}}return{content:r,transferables:s}}Ot(t,e){const{gltf:n,transferables:r,featureTable:s}=t,o=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:o}=s;if(o)for(let t=0;t<o.length;t++){const r=o[t].attributes&&o[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}(n);return this.Et(t.gltf),t.gltf.asset||(t.gltf.asset={}),o?(t.gltf.asset.sharePosition=!0,this.Pt(n,s,e.upAxis,e.transform)):this.Nt(n,s,e.upAxis,e.transform),delete t.transferables,{content:t,transferables:r}}xt(t,e,r){const{featureTable:s}=t,o=t.pnts||t.i3dm,i=s&&s.RTC_CENTER||[0,0,0];if(s.EAST_NORTH_UP&&!o.NORMAL_UP&&!o.NORMAL_UP_OCT32P){const e=new Float32Array(3*o.POSITION.array.length),r=[],s=[],a=[];Me(o.POSITION,(t,o)=>{m(a,t,i),te(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*o,9*(o+1)),s)}),o.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};dn(o.POSITION.array,3,i,on,a);const c=pn(a),u=h([],c),f=[1/0,1/0,1/0],l=[-1/0,-1/0,-1/0];Me(o.POSITION,t=>{t[0]=t[0]+i[0]-u[0],t[1]=t[1]+i[1]-u[1],t[2]=t[2]+i[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]>l[0]&&(l[0]=t[0]),t[1]>l[1]&&(l[1]=t[1]),t[2]>l[2]&&(l[2]=t[2])}),o.POSITION.min=f,o.POSITION.max=l,e&&g(c,c,e);const y=this.Bt(c);t.rtcCenter=u,t.rtcCoord=y,t.rootIdx=r;const d=t.transferables;return delete t.transferables,{content:t,transferables:d}}Et(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],o=n[2],i=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]!==o||n[t+3]!==i){a=!1;break}a&&(e[t].image.color=[r/255,s/255,o/255,i/255],delete e[t].image.array)}}}abortTileLoading(t,e){const n=this.bt[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.bt[t.url],e(null)}Ft(t,e,n,o){const i=e&&e.RTC_CENTER||t.extensions&&t.extensions.CESIUM_RTC&&t.extensions.CESIUM_RTC.center;let a=tn;"X"===(n=n&&n.toUpperCase())?a=en:"Z"===n&&(a=on),t.extensions=t.extensions||{},t.extensions.CESIUM_RTC||(t.extensions.CESIUM_RTC={}),i&&(t.extensions.CESIUM_RTC.center=i),t.extensions.MAPTALKS_RTC={};const c={xmin:1/0,xmax:-1/0,ymin:1/0,ymax:-1/0,hmin:1/0,hmax:-1/0};pe(t,t=>{if(!(t.attributes&&t.attributes.POSITION))return;const e=r(cn);t.matrices&&wn(e,t.matrices);const n=t.attributes.POSITION.array,u=t.attributes.POSITION.itemSize;s(e,a,e),o&&s(e,o,e),dn(n,u,i||an,e,c,t.compressUniforms)});const u=pn(c);return{rtcCenter:i,modelCenter:u,upAxisTransform:a}}Pt(t,e,n,o){const{modelCenter:i,upAxisTransform:a,rtcCenter:c}=this.Ft(t,e,n),u=h([],i);o&&g(i,i,o),t.extensions.CESIUM_RTC.rtcCoord=this.Bt(i),c||(pe(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(cn);t.matrices&&wn(n,t.matrices),s(n,a,n);const o=function(t,e){var n=e[0],r=e[1],s=e[2],o=e[3],i=e[4],a=e[5],c=e[6],u=e[7],f=e[8],l=e[9],h=e[10],y=e[11],m=e[12],d=e[13],p=e[14],b=e[15],w=n*a-r*i,T=n*c-s*i,g=n*u-o*i,A=r*c-s*a,_=r*u-o*a,S=s*u-o*c,M=f*d-l*m,O=f*p-h*m,x=f*b-y*m,I=l*p-h*d,v=l*b-y*d,C=h*b-y*p,U=w*C-T*v+g*I+A*x-_*O+S*M;return U?(U=1/U,t[0]=(a*C-c*v+u*I)*U,t[1]=(s*v-r*C-o*I)*U,t[2]=(d*S-p*_+b*A)*U,t[3]=(h*_-l*S-y*A)*U,t[4]=(c*x-i*C-u*O)*U,t[5]=(n*C-s*x+o*O)*U,t[6]=(p*g-m*S-b*T)*U,t[7]=(f*S-h*g+y*T)*U,t[8]=(i*v-a*x+u*M)*U,t[9]=(r*x-n*v-o*M)*U,t[10]=(m*_-d*g+b*w)*U,t[11]=(l*g-f*_-y*w)*U,t[12]=(a*O-i*I-c*M)*U,t[13]=(n*I-r*O+s*M)*U,t[14]=(d*T-m*A-p*w)*U,t[15]=(f*A-l*T+h*w)*U,t):null}(un,n),i=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];Me(e,t=>{g(t,t,n),t[0]=t[0]-u[0],t[1]=t[1]-u[1],t[2]=t[2]-u[2],g(t,t,o),t[0]<i[0]&&(i[0]=t[0]),t[1]<i[1]&&(i[1]=t[1]),t[2]<i[2]&&(i[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=i,e.max=c,e.array.buffer.projected||(e.array.buffer.projected={}),e.array.buffer.projected[e.byteOffset]=1}}),t.extensions.CESIUM_RTC.center=u)}Nt(t,e,n,r){const{modelCenter:s,rtcCenter:o}=this.Ft(t,e,n,r),i=this.Dt(s);t.extensions.MAPTALKS_RTC.projCenter=i,t.extensions.CESIUM_RTC.rtcCoord=this.Bt(s),pe(t,e=>{if(e.attributes&&e.attributes.POSITION){e.attributes.NORMAL&&this.Rt(e.attributes.NORMAL,e.matrices,n),e.attributes.TANGENT&&this.Rt(e.attributes.TANGENT,e.matrices,n);const{newPositions:s}=this.Lt(e.attributes.POSITION,e.matrices,o,t.extensions.MAPTALKS_RTC,n,r,e.compressUniforms),{componentType:i}=e.attributes.POSITION;5126!==i&&(e.attributes.POSITION.array=new Float32Array(s))}});for(const e in t.nodes){t.nodes[e].matrix=on}}Dt(t){0===S(t)?y(fn,0,0,-6378137):Ct(fn,t);const e=this.options.projection;Ne(ln,fn,e);const n=fn[2],r=[];return r[0]=ln[0],r[1]=ln[1],r[2]=n,r}Rt(t,e,r){let s;s="Y"===r?tn:"X"===r?en:on;const o=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(wn(o,e),c(o,on))return;const i=n([],o),a=[];Me(t,t=>(function(t,e,n){var r=e[0],s=e[1],o=e[2];t[0]=r*n[0]+s*n[3]+o*n[6],t[1]=r*n[1]+s*n[4]+o*n[7],t[2]=r*n[2]+s*n[5]+o*n[8]}(a,t,i),b(a,a),h(t,a),a))}Lt(t,e,n,s,o,i,a){if(t.array.buffer.projected&&t.array.buffer.projected[t.byteOffset])return null;const u=r([]);wn(u,e);const f=this.options.projection;o=o&&o.toUpperCase();const l=n;let h=null;"Y"===o?h=tn:"X"===o&&(h=en);let d=[0,0,0,1];const p=[0,0,0],b=[0,0],w=s.projCenter,T=i&&c(on,i),A=t.min=t.min||[],_=t.max=t.max||[];y(A,1/0,1/0,1/0),y(_,-1/0,-1/0,-1/0);const M=a||{},{decode_position_min:O,decode_position_normConstant:x}=M;let I=[0,0,0,0],v=1;O&&(I=O),x&&(v=x);const C=[];return Me(t,t=>{if(d[0]=t[0]*v+I[0],d[1]=t[1]*v+I[1],d[2]=t[2]*v+I[2],d=g(d,d,u),h&&(d=g(d,d,h)),l&&m(d,d,l),i&&!T&&(d=g(d,d,i)),0===S(d)?y(p,0,0,-6378137):Ct(p,d),Ne(b,p,f),t instanceof Float32Array)t[0]=b[0]-w[0],t[1]=b[1]-w[1],t[2]=p[2]-w[2];else{const e=b[0]-w[0],n=b[1]-w[1],r=p[2]-w[2];C.push(e),C.push(n),C.push(r),C.push(t[3])}return t[0]<A[0]&&(A[0]=t[0]),t[1]<A[1]&&(A[1]=t[1]),t[2]<A[2]&&(A[2]=t[2]),t[0]>_[0]&&(_[0]=t[0]),t[1]>_[1]&&(_[1]=t[1]),t[2]>_[2]&&(_[2]=t[2]),t}),t.array.buffer.projected||(t.array.buffer.projected={}),t.array.buffer.projected[t.byteOffset]=1,{projCenter:w,newPositions:C}}Bt(t){return 0===S(t)?y([],0,0,-6378137):Ct([],t)}onRemove(){}}const mn=[];function dn(t,e,n,r,s,o){const i=o||{},{decode_position_min:a,decode_position_normConstant:c}=i;let u=[0,0,0,0],f=1;a&&(u=a),c&&(f=c);for(let o=0,i=t.length;o<i;o+=e){const{xmin:i,ymin:a,xmax:c,ymax:l,hmin:h,hmax:d}=s;y(mn,t[o]*f+u[0],t[o+1]*f+u[1],t[o+2]*f+u[2]),g(mn,mn,r);const p=m(mn,n,mn);p[0]<i&&(s.xmin=p[0]),p[0]>c&&(s.xmax=p[0]),p[1]<a&&(s.ymin=p[1]),p[1]>l&&(s.ymax=p[1]),e>2&&(p[2]<h&&(s.hmin=p[2]),p[2]>d&&(s.hmax=p[2]))}}function pn(t){const{xmax:e,ymax:n,xmin:r,ymin:s,hmin:o,hmax:i}=t,a=[(r+e)/2,(s+n)/2,(o+i)/2];return e===-1/0&&(a[0]=0),n===-1/0&&(a[1]=0),i===-1/0&&(a[2]=0),isNaN(a[2])&&(a[2]=0),a}function bn(t,e){for(let n=0;n<e.length;n++)t.indexOf(e[n])<0&&t.push(e[n])}function wn(t,e){const n=t;for(let t=e.length-1;t>=0;t--)s(n,e[t],n);return n}function Tn(t,e,n){let r,s;if(e&&n)r=Math.min(...e),s=Math.max(...n);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);r=e,s=n}const o=new Int16Array(t.length);for(let e=0;e<t.length;e++){const n=2*(t[e]-r)/(s-r)-1,i=Math.max(-1,Math.min(1,n));o[e]=i<0?32768*i:32767*i}return{array:o,range:[r,s]}}let gn=0;class An{constructor(t){this.workerId=t,this.workers={},this.zt={}}addLayer({actorId:t,mapId:e,layerId:n,params:r},s){if(this.Vt(e,n))return;const o=this.kt(e,n),i=r.options,a=this.send.bind(this,t);this.workers[o]=new yn(n,i,a,s)}removeLayer({mapId:t,layerId:e},n){const r=this.Vt(t,e),s=this.kt(t,e);delete this.workers[s],r&&r.onRemove(n)}loadTile({mapId:t,layerId:e,params:n},r){const s=this.Vt(t,e);s&&s.loadTile(n,r)}abortTileLoading({mapId:t,layerId:e,params:n},r){const s=this.Vt(t,e);s&&s.abortTileLoading(n,r)}receive(t){const e=t.callback,n=this.zt[e];delete this.zt[e],n&&t.error?n(new Error(t.error)):n&&n(null,t.data)}send(t,e,n,r,s){const o=s?`${t}-${gn++}`:null;s&&(this.zt[o]=s),postMessage({type:"<request>",workerId:this.workerId,actorId:t,command:e,params:n,callback:String(o)},r||[])}kt(t,e){return`${t}-${e}`}Vt(t,e){const n=this.kt(t,e);return this.workers[n]}}t.initialize=function(){},t.onmessage=function(t,e){const n=t.data;this.dispatcher||(this.dispatcher=new An(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 instanceof Error&&(t={message:t.message}),e(t,n,r)})},Object.defineProperty(t,"jt",{value:!0})}';function O(t){return null==t}function A(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 I(t){return null!=t&&("function"==typeof t||null!==t.constructor&&t.constructor===Function)}function x(t){return"object"==typeof t&&!!t}function S(t){return"number"==typeof t&&!isNaN(t)}function M(t){return t*Math.PI/180}function N(t){return t/Math.PI*180}function E(t){let e=document.createElement("a");return e.href=t,t=e.href,e=null,t}function v(t){return Math.sign?Math.sign(t):0===(t=+t)||isNaN(t)?Number(t):t>0?1:-1}const C=[1,1,1,1,2,2,3,0];function R(t){const e=t.length;let n="";for(let r=0;r<e;){let s=t[r++];if(128&s){let n=C[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}function U(t,e,n){return t[3*n]=e[0],t[3*n+1]=e[1],t[3*n+2]=e[2],t}function L(t){return t.flat?t.flat(1/0):t.reduce((t,e)=>t.concat(e),[])}function P(t){return t<256?Uint8Array:t<65536?Uint16Array:Uint32Array}function B(t){return 0===t.indexOf("data:")}function D(t){const e=t.indexOf("base64,"),n=t.substring(e+7),r=window.atob(n),s=r.length,i=new Uint8Array(s);for(let t=0;t<s;t++)i[t]=r.charCodeAt(t);return i.buffer}function F(t){for(let e=1;e<arguments.length;e++){const n=arguments[e];if(n)for(let e=0,r=n.length;e<r;e++)t.push(n[e])}return t.length}var k=Object.freeze({__proto__:null,isNil:O,extend:A,isFunction:I,isObject:x,isNumber:S,toRadian:M,toDegree:N,getAbsoluteURL:E,sign:v,stringFromUTF8Array:R,setColumn3:U,flatArr:L,getBatchIdArrayType:P,isBase64:B,base64URLToArrayBuffer:D,pushIn:F});const H="undefined"==typeof document?null:document.createElement("canvas");class V extends t.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(!H)return void e(new Error("There is no canvas to draw image!"));const t=function(t){if(z(t.width)&&z(t.height))return t;let e=t.width,n=t.height;z(e)||(e=G(e));z(n)||(n=G(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);H.width=t.width,H.height=t.height;const r=H.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 z(t){return 0==(t&t-1)&&0!==t}function G(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}class j{constructor(t,e){this.max=t,this.currentSize=0,this.onRemove=e,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){const t=this.data.keys();let e=t.next();for(;this.currentSize>this.max&&void 0!==e.value;){if(!this.data.get(e.value).current){const t=this.getAndRemove(e.value);t&&this.onRemove(t)}e=t.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 q(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=[];Q(r[n],s,t,e)}}}const X=[],K=[],$=[],W=[0,0,0],Y=b.identity([]),Z=[1,1,1];function Q(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=g.fromTranslation(X,t.translation||W),n=g.fromQuat(K,t.rotation||Y),r=g.fromScaling($,t.scale||Z);g.multiply(r,n,r);const i=g.multiply([],e,r);s.push(i)}if(t.children&&t.children.length)for(let e=0,i=t.children.length;e<i;e++)Q(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 J(t,e,n){let{byteOffset:r,byteStride:s}=e;const{componentType:i,itemSize:o}=e,a=e.array.buffer,c=i?p.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 tt(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]}const et=new Array(3),nt=new Array(3),rt=[40680631590769,40680631590769,40408299984661.445];function st(t,e,n,r){const s=rt,i=Math.cos(n);et[0]=i*Math.cos(e),et[1]=i*Math.sin(e),et[2]=Math.sin(n),mt(et,et),T.multiply(nt,s,et);const o=Math.sqrt(T.dot(et,nt));var a,c,h;return c=nt,h=o,(a=nt)[0]=c[0]/h,a[1]=c[1]/h,a[2]=c[2]/h,T.scale(et,et,r),T.add(t,nt,et)}const it=[1/6378137,1/6378137,1/6356752.314245179],ot=[1/40680631590769,1/40680631590769,1/40408299984661.445],at=new Array(3),ct=new Array(3),ht=new Array(3);function ut(t,e){const n=ot,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],f=i*i*c*c,l=o*o*h*h,d=a*a*u*u,m=f+l+d,p=Math.sqrt(1/m),y=T.scale(ft,e,p);if(m<s)return isFinite(p)?y:void 0;const b=r[0],g=r[1],w=r[2],_=lt;_[0]=y[0]*b*2,_[1]=y[1]*g*2,_[2]=y[2]*w*2;let O,A,I,x,S,M,N,E,v,C,R,U=(1-p)*dt(e)/(.5*dt(_)),L=0;do{U-=L,I=1/(1+U*b),x=1/(1+U*g),S=1/(1+U*w),M=I*I,N=x*x,E=S*S,v=M*I,C=N*x,R=E*S,O=f*M+l*N+d*E-1,A=f*v*b+l*C*g+d*R*w;L=O/(-2*A)}while(Math.abs(O)>1e-12);return t[0]=i*I,t[1]=o*x,t[2]=a*S,t}(at,e,it,n,.1);let s=T.mul(ct,r,n);s=mt(s,s);const i=T.sub(ht,e,r),o=Math.atan2(s[1],s[0]),a=Math.asin(s[2]),c=v(T.dot(i,e))*dt(i);return t[0]=N(o),t[1]=N(a),t[2]=c,t}const ft=new Array(3),lt=new Array(3);function dt(t){return T.length(t)}function mt(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 pt(t,e){return T.multiply(e,t,ot),T.normalize(e,e)}function yt(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,T.normalize(e,e)}var bt=Object.freeze({__proto__:null,radianToCartesian3:st,cartesian3ToDegree:ut,normalizeCartesian:mt,geodeticSurfaceNormal:pt,geodeticSurfaceNormalCartographic:yt});function gt(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 Tt(t,e){let n="";for(let r=0;r<4;r++){const s=t.getUint8(e+r);n+=String.fromCharCode(s)}return n}const wt="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function _t(t,e,n){const r=new Uint8Array(t,e,n);return wt?JSON.parse(wt.decode(r)):JSON.parse(R(r))}function Ot(t,e,n){const r=new Uint8Array(t,e,n);return wt?JSON.parse(wt.decode(r)):JSON.parse(R(r))}function At(t,e,n){return{offset:e,byteLength:n}}function It(t,e,n,r){const{byteOffset:s,componentType:i,type:o}=t,{ctor:a,type:c}=vt(i||"UNSIGNED_SHORT"),h=Nt(o);return{byteStride:0,byteOffset:s+n,itemSize:h,count:r*h,componentType:c,array:new a(e,n+s,r*h)}}function xt(t,e,n,r){const s=It(t,e,n,r);return s.array.buffer.byteLength!==e.byteLength&&(s.array=s.array.slice()),s}function St(t,e,n,r){const{byteOffset:s,componentType:i,type:o}=t,{ctor:a}=vt(i||"UNSIGNED_SHORT"),c=Nt(o),h=new a(e,s,n*c);return 1===c?h[r]:h.subarray(r*c,r*c+c)}const Mt={"SCALAR":1,"VEC2":2,"VEC3":3,"VEC4":4};function Nt(t){return t?Mt[t]:1}const Et={"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 vt(t){return Et[t]}function Ct(t){for(const e in Et)if(t===Et[e].ctor)return Et[e].type;throw new Error("unrecognized ctor:"+t)}function Rt(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 Ut(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={},f=null;r>0&&(h=_t(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=Ot(a,e,i),e+=i);const l=At(0,e,o);return f=a.slice(l.offset,l.offset+l.byteLength),n.push(f),{featureTable:h,featureTableBin:c,batchTable:u,batchTableBin:f}}const Lt={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"}},Pt={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},Bt={},Dt={east:[],north:[],up:[],west:[],south:[],down:[]};let Ft=[],kt=[],Ht=[];const Vt=[0,0,0];function zt(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 Gt=function(t,e){const n=Lt[t][e];let r;const s=t+e;return Bt[s]?r=Bt[s]:(r=function(r,s,i){if(T.equals(r,Vt))T.copy(Ft,Pt[t]),T.copy(kt,Pt[e]),T.copy(Ht,Pt[n]);else if(gt(r[0],0,1e-14)&&gt(r[1],0,1e-14)){const s=v(r[2]);T.copy(Ft,Pt[t]),"east"!==t&&"west"!==t&&T.scale(Ft,Ft,s),T.copy(kt,Pt[e]),"east"!==e&&"west"!==e&&T.scale(kt,kt,s),T.copy(Ht,Pt[n]),"east"!==n&&"west"!==n&&T.scale(Ht,Ht,s)}else{pt(r,Dt.up);const s=Dt.up,i=Dt.east;i[0]=-r[1],i[1]=r[0],i[2]=0,T.normalize(Dt.east,i),T.cross(Dt.north,s,i),T.scale(Dt.down,Dt.up,-1),T.scale(Dt.west,Dt.east,-1),T.scale(Dt.south,Dt.north,-1),Ft=Dt[t],kt=Dt[e],Ht=Dt[n]}return i[0]=Ft[0],i[1]=Ft[1],i[2]=Ft[2],i[3]=0,i[4]=kt[0],i[5]=kt[1],i[6]=kt[2],i[7]=0,i[8]=Ht[0],i[9]=Ht[1],i[10]=Ht[2],i[11]=0,i[12]=r[0],i[13]=r[1],i[14]=r[2],i[15]=1,i},Bt[s]=r),r}("east","north"),jt=[],qt=[],Xt=[],Kt=[],$t=[],Wt=[],Yt=[],Zt={x:0,y:0},Qt={x:0,y:0},Jt=Math.PI/180;const{getTextureMagFilter:te,getTextureMinFilter:ee,getTextureWrap:ne,getMaterialType:re,getMaterialFormat:se,getPrimitive:ie,getUniqueREGLBuffer:oe}=n.REGLHelper,ae=[1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],ce=[0,0,1,0,0,1,0,0,-1,0,0,0,0,0,0,1],{loginIBLResOnCanvas:he,logoutIBLResOnCanvas:ue,getIBLResOnCanvas:fe,getPBRUniforms:le}=n.pbr.PBRUtils,de={factor:0,units:0},me={specularStrength:0,materialShininess:1},pe=[1,1,1],ye=r.identity([]),be=[0,0],ge=t=>t.material instanceof n.PhongMaterial,Te=t=>t.material instanceof n.pbr.StandardMaterial,we=[],_e=new t.Coordinate(0,0),Oe=new t.Point(0,0),Ae=new t.Point(0,0),Ie=new t.Point(0,0),xe=[],Se=[],Me=[],Ne=[],Ee={"POSITION":"POSITION","NORMAL":"NORMAL","TEXCOORD_0":"TEXCOORD_0","TEXCOORD_1":"TEXCOORD_1","COLOR_0":"COLOR_0","TANGENT":"TANGENT","_BATCHID":"_BATCHID"};class ve{constructor(e,r){this.t=r,this.s=r.getRenderer().canvas,this.pickingFBO=r.getRenderer().pickingFBO,this.i=new t.SpatialReference,this.o=e,this.h=new n.Renderer(e),this.u={},this.l={},this.m={},this.p={},this.g={},this.T={},this._={},this.O=new n.Scene,this.A=new n.Scene,this.I=new n.Scene,this.S=new n.Scene,this.M=new n.ResourceLoader(e.texture(2)),this.N=this.v.bind(this),this.C=new n.PhongMaterial({"baseColorFactor":[1,1,1,1]}),this.R(),this.U=new n.KHRTechniquesWebglManager(this.o,this.L(),this.M);const s=this.getMap();s.altitudeToPoint&&(this.P=s.altitudeToPoint(100,s.getGLRes())/100)}getI3DMMeshes(){return this.g}getPNTSMeshes(){return this.p}getB3DMMeshes(){return this.m}getPaintedMeshes(){return this.B}getMap(){return this.t.getMap()}paint(t,e,n){const r=n&&n.renderTarget,i=n&&n.sceneFilter,o=this.getMap();if(!t.length||!o)return null;const a=this.D(),c=o.projViewMatrix,h=[],u=[],f=[],d=[],m=[],p=this.F(t);for(let r=0,i=t.length;r<i;r++){const i=t[r].data.node;let o=this.k(i);if(!o)continue;const a=this.t.H(i.V),y=a.heightOffset||0,b=a.coordOffset||be;this.T[i.id]&&(o=this.T[i.id],o=L(o));let g=a.polygonOffset||de;I(g)&&(g=g()),Array.isArray(o)||(h[0]=o,o=h);for(let t=0,r=o.length;t<r;t++){const r=o[t].properties.magic;if(o[t].properties.heightOffset===y&&o[t].properties.coordOffset[0]===b[0]&&o[t].properties.coordOffset[1]===b[1]||this.G(o[t]),"b3dm"===r){if(o[t].getBoundingBox&&!l(c,o[t].getBoundingBox()))continue;const{batchIdData:e,batchIdMap:r}=o[t].geometry.properties;if(e&&r){const e=o[t].properties.node.V;this.j&&this.j[e]?s.highlightMesh(this.o,o[t],this.j[e],this.q,r):this.j&&this.j[e]||s.highlightMesh(this.o,o[t],null,this.q,r),s.showOnly(this.o,o[t],this.X&&this.X[e],this.K,r)}n&&n.bloom&&o[t].properties.hlBloomMesh&&(o[t].properties.hlBloomMesh.properties.depthFunc="always",o[t].properties.hlBloomMesh.properties.polygonOffset=g,f.push(o[t].properties.hlBloomMesh)),f.push(o[t])}else"pnts"===r?d.push(o[t]):"i3dm"===r&&m.push(o[t]);o[t].properties.isLeaf=!!e[i.id],o[t].properties.level=p.get(i.$),o[t].properties.polygonOffset=g,o[t].W=i,e[i.id]||u.push(o[t]),this.Y(o[t])}}let y=0;const b=this.U.getExcludeFilter();y+=this.Z(this.J,a,[i,ge,b],r,u,f,m),y+=this.Z(this.tt,a,[i,Te,b],r,u,f,m),this.U.forEachShader((t,e,n)=>{const s=this.D(n);y+=this.Z(t,s,[i,e],r,u,f,m)}),this.A.setMeshes(d);const g=this.et();return y+=this.h.render(this.nt,g,this.A,r&&r.fbo),this.B={pntsMeshes:d,i3dmMeshes:m,b3dmMeshes:f},y}Z(t,e,n,r,s,i,o){t.filter=n.filter(t=>!!t),e.debug=!1,e.debug=!1;let a=0;return this.O.setMeshes(i),a+=this.h.render(t,e,this.O,r&&r.fbo),this.I.setMeshes(o),a+=this.h.render(t,e,this.I,r&&r.fbo),a}rt(t,e){return e.W.st-t.W.st}paintRegion(t,e,n,r,s){const i=this.getMap();if(!t.length&&!e.length)return;const o=i.projViewMatrix,a=[];for(let n=0,r=(t=t.concat(e)).length;n<r;n++){const e=t[n].node,r=this.it(e);r&&(r.getBoundingBox&&!l(o,r.getBoundingBox())||a.push(r))}this.ot.filter=r,this.S.setMeshes(a);const c=this.ct(n);this.h.render(this.ot,c,this.S,s&&s.fbo)}deleteTile(t){const e=t.node.id;this.ht(e)}ht(t){const e=this.l[t];e&&(e.geometry.dispose(),e.dispose(),delete this.l[t]);const n=this.m[t]||this.p[t]||this.g[t]||this.T[t]||this.u[t];this.T[t]?this.ut(t):n&&(this.ft(n),delete this.m[t],delete this.p[t],delete this.g[t],delete this.u[t])}ut(t){let e=this.T[t];e=L(e);for(let t=0;t<e.length;t++){const{id:n}=e[t].properties;this.ht(n)}delete this.T[t]}ft(t){if(Array.isArray(t))for(let e=0,n=t.length;e<n;e++)this.ft(t[e]);else{s.showOnly(this.o,t),s.highlightMesh(this.o,t);const e=t.geometry.properties.url;if(e){const t=this._[e];t&&(t.refCount--,t.refCount<=0&&(t.geometry.dispose(),t.material.dispose(),delete this._[e]))}else t.geometry.dispose(),t.material&&t.material.dispose();t.dispose()}}remove(){const t=this.t;ue(t.getRenderer().canvas,t.getMap());for(const t in this.T)this.ut(t);this.T={};for(const t in this.m)this.ht(t);this.m={};for(const t in this.p)this.ht(t);this.p={};for(const t in this.g)this.ht(t);this.g={};for(const t in this.u)this.ht(t);this.u={};for(const t in this.l)this.ht(t);this.l={},this.J&&(this.J.dispose(),delete this.J),this.tt&&(this.tt.dispose(),delete this.tt),this.nt&&(this.nt.dispose(),delete this.nt),this.ot&&(this.ot.dispose(),delete this.ot),this.U.dispose(),this.picking&&this.picking.dispose()}it(e){if(!e.boundingVolume||!e.boundingVolume.region)return null;if(this.l[e.id])return this.l[e.id];const s=e.boundingVolume.region;let i=new t.Coordinate(N(s[0]),N(s[1])),o=new t.Coordinate(N(s[2]),N(s[3]));i=this.lt(i),o=this.lt(o);const a=i.add(o).dt(.5);i.pt(a),o.pt(a);const c=this.yt(s[4],s[5]),h=c.x,u=c.y,f=[i.x,i.y,u,o.x,i.y,u,o.x,o.y,u,i.x,o.y,u,i.x,i.y,h,o.x,i.y,h,o.x,o.y,h,i.x,o.y,h],l=new n.Geometry({aPosition:f},[0,1,1,2,2,3,3,0,0,4,1,5,2,6,3,7,4,5,5,6,6,7,7,4],0,{primitive:"lines"});l.generateBuffers(this.o);const d=new n.Mesh(l),m=r.identity([]);return d.setLocalTransform(r.translate(m,m,[a.x,a.y,0])),this.l[e.id]=d,d}k(t){return this.m[t.id]||this.p[t.id]||this.g[t.id]||this.T[t.id]}has(t){return this.k(t)||this.u[t.id]}G(t){const e=t.properties.magic;"b3dm"===e?this.bt(t):"i3dm"===e?this.gt(t):"pnts"===e&&this.Tt(t)}createPntsMesh(t,e,r,s){if(this.p[e]){const t=this.p[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,u=new n.Geometry(i,null,h,{primitive:"points",positionAttribute:"POSITION"});u.generateBuffers(this.o);const f={};i.POSITION?f.HAS_POSITION=1:i.POSITION_QUANTIZED&&(f.HAS_POSITION_QUANTIZED=1),i.RGB?f.HAS_RGB=1:i.RGBA?f.HAS_RGBA=1:i.RGB565&&(f.HAS_RGB565=1),(i.NORMAL||i.NORMAL_OCT16P)&&(f.HAS_NORMAL=1,i.NORMAL_OCT16P&&(f.HAS_NORMAL_OCT16P=1)),this.wt(f,c),t.featureTable.CONSTANT_RGBA&&(t.featureTable.CONSTANT_RGBA=t.featureTable.CONSTANT_RGBA.map(t=>t/255));const{rtcCenter:l,rtcCoord:d}=t,m=this.t.H(a),p=new n.Mesh(u);return p.properties.magic="pnts",p.properties.id=e,p.properties.node=r,p.properties.count=h,p.properties.batchTable=t.batchTable,p.properties.batchTableBin=t.batchTableBin,p.properties.serviceIndex=a,p.properties.rtcCoord=d,p.properties.rtcCenter=l,p.setDefines(f),Object.defineProperty(p.uniforms,"pointColor",{enumerable:!0,get:function(){return t.featureTable.CONSTANT_RGBA?t.featureTable.CONSTANT_RGBA:m&&m.pointColor||[1,1,1,1]}}),Object.defineProperty(p.uniforms,"pointSize",{enumerable:!0,get:function(){return m&&m.pointSize||2}}),Object.defineProperty(p.uniforms,"pointOpacity",{enumerable:!0,get:function(){return m&&m.pointOpacity||1}}),this._t(p,c),this.Tt(p),this.p[e]=p,s(null,{id:e,mesh:[p]}),[p]}Tt(t){const{rtcCenter:e,rtcCoord:n,node:s}=t.properties,i=this.Ot(Me,n),o=t.localTransform||[];this.At(o,s,e,n),r.multiply(o,o,i);const a=this.t.H(s.V);if(a.coordOffset){const t=this.It(s.V,n);r.multiply(o,t,o)}t.setLocalTransform(o),t.properties.heightOffset=a.heightOffset||0,t.properties.coordOffset=a.coordOffset&&a.coordOffset.slice(0)||be}createI3DMMesh(t,e,s,o){if(this.g[e]){const t=this.g[e];return console.warn(`i3dm mesh with id(${e}) was already created.`),this.u[e]||o(null,{id:e,mesh:t}),t}const a=this.t.H(s.V),h=this.xt(s.St),{i3dm:u,featureTable:f,gltf:l,batchTable:d,batchTableBin:m,count:y}=t,b=f.INSTANCES_LENGTH,{rtcCenter:g,rtcCoord:T}=t,w=this.Ot(Me,T),_=this.At(Ne,s,g,T);r.multiply(w,_,w);const{POSITION:O,NORMAL_UP:A,NORMAL_RIGHT:I,SCALE:x,SCALE_NON_UNIFORM:S,INSTANCE_ROTATION:M}=u,N={"instance_vectorA":new Float32Array(4*b),"instance_vectorB":new Float32Array(4*b),"instance_vectorC":new Float32Array(4*b)},E=new Float32Array(3),v=new Float32Array(3),C=[],R=new Float32Array(1),L=new Float32Array(3),P=[],B=[],D=[],F=[],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?p.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)}}(O,(t,e)=>{A?(J(v,I,e),J(E,A,e),i.cross(C,v,E),i.normalize(C,C),U(P,v,0),U(P,E,1),U(P,C,2),c.fromMat3(B,P)):M?(J(k,M,e),c.fromMat3(B,k)):c.identity(B),x?(J(R,x,e),i.set(D,R[0],R[0],R[0])):S?(J(L,S,e),i.set(D,...L)):i.set(D,1,1,1),r.fromRotationTranslationScale(F,B,t,D),tt(N.instance_vectorA,e,F,0),tt(N.instance_vectorB,e,F,1),tt(N.instance_vectorC,e,F,2)});const H={};for(const t in N)H[t]={buffer:this.o.buffer({dimension:N[t].length/b,data:N[t]}),divisor:1};const V=a.shader||"pbr";let z=0,G=!0;const j=[];return q(l,(t,i,o,a)=>{const{geometry:c,material:u}=this.Mt(t,i,o,a,s,!0,V);u&&!u.isReady()&&(G=!1,z++);const f=new n.InstancedMesh(H,b,c,u);f.properties.magic="i3dm",f.properties.id=e,f.properties.count=y,f.properties.batchTable=d,f.properties.batchTableBin=m,f.properties.serviceIndex=s.V,f.properties.rtcCoord=T,f.properties.rtcCenter=g,f.properties.node=s;const l=this.Nt(t,c,u,s.V,a);t.compressed_int16_params&&this._t(f,t.compressed_int16_params),this.Et(f,t.attributes);const p=r.identity([]);if(t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)r.multiply(p,p,t.matrices[e]);r.multiply(p,h,p),f.setPositionMatrix(p),this.gt(f,w),f.setDefines(l),f.properties.polygonOffset={offset:0,factor:0},j.push(f),delete t.attributes}),G?(this.g[e]=j,o(null,{id:e,mesh:j})):(this.u[e]={meshes:j,count:z},j.vt=o),j}gt(t,e){const{rtcCenter:n,rtcCoord:s,node:i}=t.properties;if(!e){e=this.Ot(Me,s);const t=this.At(Ne,i,n,s);r.multiply(e,t,e)}const o=this.t.H(i.V),a=t.localTransform||[];if(o.coordOffset){const t=this.It(i.V,s);r.multiply(a,t,e)}else r.copy(a,e);t.setLocalTransform(a),t.properties.heightOffset=o.heightOffset||0,t.properties.coordOffset=o.coordOffset&&o.coordOffset.slice(0)||be}createB3DMMesh(e,s,i,o){if(this.m[s]||this.u[s]){const t=this.m[s];return console.warn(`mesh with id(${s}) was already created.`),this.u[s]||o(null,{id:s,mesh:t}),t}let a;if(i.maxExtent){const e=new t.Extent(i.maxExtent).convertTo(t=>this._pointToPrj(t));a=[e.xmin,e.ymin,e.xmax,e.ymax]}const c=e.gltf,{projCenter:h}=c.extensions.MAPTALKS_RTC,{rtcCoord:u,center:f}=c.extensions.CESIUM_RTC,l=c.asset.sharePosition,d=this.xt(i.St);let m;m=l?this.Ot(Me,u):this.Ct(Me,u,h,i.V);const p=this.t.H(i.V);let y=p.shader||"pbr";if(c.materials)for(let t=0;t<c.materials.length;t++)if(c.materials[t]&&c.materials[t].extensions&&c.materials[t].extensions.KHR_materials_unlit){y=p.shader="phong";break}const b=[];let g=0,T=!0;return q(c,(t,o,c,w)=>{const{geometry:_,material:O}=this.Mt(t,o,c,w,i,!1,y);O&&!O.isReady()&&(T=!1,g++);const A=new n.Mesh(_,O);A.properties.magic="b3dm",A.properties.id=s,A.properties.node=i,A.properties.batchTable=e.batchTable,A.properties.batchTableBin=e.batchTableBin,A.properties.count=e.featureTable.BATCH_LENGTH,A.properties.serviceIndex=i.V;const I=this.Nt(t,_,O,i.V,w);A.setDefines(I);const x=t.compressUniforms;if(x)for(const t in x)A.setUniform(t,x[t]);t.compressed_int16_params&&this._t(A,t.compressed_int16_params),this.Et(A,t.attributes),a&&(I.USE_MAX_EXTENT=1,A.setUniform("maxPrjExtent",a)),Object.prototype.hasOwnProperty.call(A.uniforms,"polygonOpacity")||Object.defineProperty(A.uniforms,"polygonOpacity",{enumerable:!0,get:function(){return S(p.opacity)?p.opacity:1}});const M=r.identity([]);if(l&&t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)r.multiply(M,M,t.matrices[e]);l&&r.multiply(M,d,M),A.properties.node=i,A.properties.projCenter=h,A.properties.nodeMatrix=M,A.properties.isSharedPosition=l,A.properties.rtcCoord=u,A.properties.rtcCenter=f,this.bt(A,m),b.push(A),delete t.attributes}),T?(this.m[s]=b,o(null,{id:s,mesh:b})):(this.u[s]={meshes:b,count:g},b.vt=o),b}_t(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)}bt(t,e){const{isSharedPosition:n,rtcCoord:s,rtcCenter:i,projCenter:o,nodeMatrix:a,node:c}=t.properties;e||(e=n?this.Ot(Me,s):this.Ct(Me,s,o,c.V));const h=t.localTransform||r.identity([]);if(n){const t=this.At(Ne,c,i,s);r.multiply(h,e,a),r.multiply(h,t,h)}else r.multiply(h,e,a);const u=this.t.H(c.V);if(u.coordOffset){const t=this.It(Ne,c.V,s);r.multiply(h,t,h)}t.setLocalTransform(h),t.properties.heightOffset=u.heightOffset||0,t.properties.coordOffset=u.coordOffset&&u.coordOffset.slice(0)||be}Et(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)}}At(e,n,s,o){const a=this.getMap(),c=this.t.H(n.V).heightOffset||0,h=new t.Coordinate(o);let u;u=a.altitudeToPoint?this.P:a.distanceToPointAtRes(100,100,a.getGLRes(),h).y/100;const f=n.matrix?r.copy(e,n.matrix):r.identity(e);if(s){zt(f,i.transformMat4(we,s,f),f)}const l=function(t,e,n,r,s,i,o){e=T.copy(jt,e);const a=st(jt,e[0]*Jt,e[1]*Jt,e[2]),c=g.getTranslation(qt,n),h=r.ellipsoid;let u;u=0===T.len(c)?T.set(Xt,0,0,-6378137):ut(Xt,c),Zt.x=u[0],Zt.y=u[1];const f=r.project(Zt,Qt);Kt[0]=f.x/s,Kt[1]=f.y/s,Kt[2]=(u[2]+o)*i;const l=Gt(a,h,$t),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],f=t[10],l=e[0],d=e[1],m=e[2],p=e[3],y=e[4],b=e[5],g=e[6],T=e[7],w=e[8],_=r*l+o*d+h*m,O=s*l+a*d+u*m,A=i*l+c*d+f*m,I=r*p+o*y+h*b,x=s*p+a*y+u*b,S=i*p+c*y+f*b,M=r*g+o*T+h*w,N=s*g+a*T+u*w,E=i*g+c*T+f*w;return n[0]=_,n[1]=O,n[2]=A,n[3]=0,n[4]=I,n[5]=x,n[6]=S,n[7]=0,n[8]=M,n[9]=N,n[10]=E,n[11]=0,n[12]=t[12],n[13]=t[13],n[14]=t[14],n[15]=t[15],n}(g.invert(Wt,l),w.fromMat4(Yt,n),t);return zt(t,Kt,d),t}(f,o,f,a.getProjection(),a.getGLRes(),u,c),d=function(t,e){return T.set(t,e[12],e[13],e[14]),t}(Se,l);let m=this.t.options.offset;if(I(m)){m=m(this.t.Rt(n.id).center)}return i.set(xe,m[0],m[1],0),i.add(d,d,xe),zt(l,d,l),l}It(t,e,n){const s=this.t.H(e);if(!s.coordOffset)return null;const o=this.getMap(),a=o.getGLRes();_e.set(n[0],n[1]);const c=o.coordToPointAtRes(_e,a,Ae),h=s.coordOffset,u=_e.set(n[0]+h[0],n[1]+h[1]),f=o.coordToPointAtRes(u,a,Ie),l=f.x-c.x,d=f.y-c.y,m=this.Ut(),p=i.set(xe,l,d,(h[2]||0)*m);return r.fromTranslation(t,p)}Ut(){const t=this.getMap();let e;return e=t.altitudeToPoint?this.P:t.distanceToPointAtRes(100,100,t.getGLRes(),_e).y/100,e}createCMPTMesh(t,e,n,r){if(this.T[e]){const t=this.T[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.T[e]=i,r(null,{id:e,mesh:i}),i}Nt(t,e,n,r,s){const i=("phong"===(this.t.H(r).shader||"pbr")?this.J:this.tt).getGeometryDefines(e);s.asset&&"S3M"===s.asset.generator&&this.Lt(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.t.Pt&&(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),this.wt(i,t.compressed_int16_params);return A(i,t.compressDefines),i}wt(t,e){e&&(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))}Y(t){const e=this.t.getRenderer();e&&e.updateMaskDefines(t)}Lt(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)}Mt(t,e,n,r,s,i,o){let a=!1;r.asset&&"S3M"===r.asset.generator&&(a=!0,r.extensions=r.extensions||{});const c=r.url+"-"+e+"-"+n;if(this._[c])return this._[c].refCount++,this._[c];let h,u;const f=r.materials&&r.materials[t.material];if(r.extensions&&r.extensions.KHR_techniques_webgl&&f.extensions&&f.extensions.KHR_techniques_webgl){const e=this.Bt(t,r,i,a);h=e.material,u=e.geometry;this.t.H(s.V).fillEmptyDataInMissingAttribute&&(u.desc.fillEmptyDataInMissingAttribute=!0)}else{u=this.Dt(t,i,Ee);const e=this.t.H(s.V),n=e.ambientLight;let a=e.environmentExposure;const c=e.material,f=this.getMap().getLightManager(),l=f&&f.getAmbientLight();if(n&&(!l||l.color)&&void 0===a){const t=l&&l.color?l.color[0]:.2;a=n[0]/t}h=this.Ft(t.material,r,o,c||me,a||1)}h&&!h.isReady()?h.kt=s.id:h||(h=this.C);const l={refCount:1,geometry:u,material:h};return u.properties.url=c,this._[c]=l,l}Bt(t,e,n,r){const{geometry:s,material:i}=this.U.createMesh(t,e,n,r);return{geometry:s,material:i}}Dt(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=oe(this.o,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.Geometry(o,a,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":ie(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}
6
+ import*as t from"maptalks";import*as e from"@maptalks/gl";import{reshader as n,mat4 as r,HighlightUtil as s,vec3 as i,mat3 as o,vec4 as a,quat as c,MaskRendererMixin as h,createREGL as u,MaskLayerMixin as f}from"@maptalks/gl";import{intersectsBox as l,intersectsSphere as d,intersectsOrientedBox as m}from"frustum-intersects";import{GLTFLoader as p,Ajax as y}from"@maptalks/gltf-loader";import{quat as b,mat4 as g,vec3 as T,mat3 as w}from"gl-matrix";const _='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],o=e[2],i=e[3],a=e[4],c=e[5],u=e[6],f=e[7],l=e[8],h=e[9],y=e[10],m=e[11],d=e[12],p=e[13],b=e[14],w=e[15],T=n[0],g=n[1],A=n[2],_=n[3];return t[0]=T*r+g*a+A*l+_*d,t[1]=T*s+g*c+A*h+_*p,t[2]=T*o+g*u+A*y+_*b,t[3]=T*i+g*f+A*m+_*w,T=n[4],g=n[5],A=n[6],_=n[7],t[4]=T*r+g*a+A*l+_*d,t[5]=T*s+g*c+A*h+_*p,t[6]=T*o+g*u+A*y+_*b,t[7]=T*i+g*f+A*m+_*w,T=n[8],g=n[9],A=n[10],_=n[11],t[8]=T*r+g*a+A*l+_*d,t[9]=T*s+g*c+A*h+_*p,t[10]=T*o+g*u+A*y+_*b,t[11]=T*i+g*f+A*m+_*w,T=n[12],g=n[13],A=n[14],_=n[15],t[12]=T*r+g*a+A*l+_*d,t[13]=T*s+g*c+A*h+_*p,t[14]=T*o+g*u+A*y+_*b,t[15]=T*i+g*f+A*m+_*w,t}function o(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 i(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],o=e[3],i=n+n,a=r+r,c=s+s,u=n*i,f=r*i,l=r*a,h=s*i,y=s*a,m=s*c,d=o*i,p=o*a,b=o*c;return t[0]=1-l-m,t[1]=f+b,t[2]=h-p,t[3]=0,t[4]=f-b,t[5]=1-u-m,t[6]=y+d,t[7]=0,t[8]=h+p,t[9]=y-d,t[10]=1-u-l,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 l(t,n,r){var s=new e(3);return s[0]=t,s[1]=n,s[2]=r,s}function h(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function y(t,e,n,r){return t[0]=e,t[1]=n,t[2]=r,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 d(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t[2]=e[2]*n[2],t}function p(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t}function b(t,e){var n=e[0],r=e[1],s=e[2],o=n*n+r*r+s*s;return o>0&&(o=1/Math.sqrt(o),t[0]=e[0]*o,t[1]=e[1]*o,t[2]=e[2]*o),t}function w(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function T(t,e,n){var r=e[0],s=e[1],o=e[2],i=n[0],a=n[1],c=n[2];return t[0]=s*c-o*a,t[1]=o*i-r*c,t[2]=r*a-s*i,t}function g(t,e,n){var r=e[0],s=e[1],o=e[2],i=n[3]*r+n[7]*s+n[11]*o+n[15];return i=i||1,t[0]=(n[0]*r+n[4]*s+n[8]*o+n[12])/i,t[1]=(n[1]*r+n[5]*s+n[9]*o+n[13])/i,t[2]=(n[2]*r+n[6]*s+n[10]*o+n[14])/i,t}var A=function(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t},_=d,S=f;function M(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],o=e[2],i=e[3];return t[0]=n[0]*r+n[4]*s+n[8]*o+n[12]*i,t[1]=n[1]*r+n[5]*s+n[9]*o+n[13]*i,t[2]=n[2]*r+n[6]*s+n[10]*o+n[14]*i,t[3]=n[3]*r+n[7]*s+n[11]*o+n[15]*i,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 I(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}function v(t,e,n,r){var s=e[0],o=e[1],i=e[2],a=e[3],c=n[0],u=n[1],f=n[2],l=n[3],h=void 0,y=void 0,m=void 0,d=void 0,p=void 0;return(y=s*c+o*u+i*f+a*l)<0&&(y=-y,c=-c,u=-u,f=-f,l=-l),1-y>1e-6?(h=Math.acos(y),m=Math.sin(h),d=Math.sin((1-r)*h)/m,p=Math.sin(r*h)/m):(d=1-r,p=r),t[0]=d*s+p*c,t[1]=d*o+p*u,t[2]=d*i+p*f,t[3]=d*a+p*l,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 C,U=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t};u(),l(1,0,0),l(0,1,0),x(),x(),C=new e(9),e!=Float32Array&&(C[1]=0,C[2]=0,C[3]=0,C[5]=0,C[6]=0,C[7]=0),C[0]=1,C[4]=1,C[8]=1;\n/*!\n * @maptalks/gltf-loader v0.88.0\n * LICENSE : UNLICENSED\n * (c) 2016-2023 maptalks.org\n */\nlet E=0;function P(t){return null==t}function N(t){return!P(t)}function B(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 F(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=[],V=[],k=[0,0,0],j=I([]),q=[1,1,1];function G(t,e,n,r,s,o,i){const a=F(i);if((0===s||s===r*a.BYTES_PER_ELEMENT)&&o%a.BYTES_PER_ELEMENT==0){const s=new a(e,o,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 i=0;i<n;i++){let n=null;const u=new Uint8Array(e,s*i+o,r*a.BYTES_PER_ELEMENT);c.set(u),n=new a(c.buffer,0,r);for(let e=0;e<r;e++)t[i*r+e]=n[e]}return t}const H="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function $(t,e,n){const r=new Uint8Array(t,e,n);return H.decode(r)}const X={get:function(t,e={}){e||(e={});const n=new AbortController,r=n.signal,s=B({},e);s.signal=r,s.method||(s.method="GET");const o=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 o.xhr=n,o},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",X.get(t,e)),getJSON:function(t,e={}){return e&&e.jsonp?X.jsonp(t):((e=e||{}).responseType="json",X.get(t,e))},jsonp:function(t){const e="_maptalks_jsonp_"+E++;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 J{constructor(t,e,n){this.s=t,this.decoders=e,this.o=n,this.images={},this.i={}}requestImageFromBufferURI(t,e,n){if(this.buffers[t.id]){const r=this.buffers[t.id],s=this.u(e,r);return this.getImageByBuffer(s,n)}if(this.i[t.id])return this.i[t.id].then(()=>{const r=this.buffers[t.id],s=this.u(e,r);return this.getImageByBuffer(s,n)});if(D(t.uri)){const r=this.buffers[t.id]=R(t.uri),s=this.u(e,r);return this.getImageByBuffer(s,n)}return this.i[t.id]=X.getArrayBuffer(t.uri,null).then(r=>{const s=this.buffers[t.id]=r.data,o=this.u(e,s);return this.getImageByBuffer(o,n)})}getImageByBuffer(t,e){if(this.images[e.id])return Promise.resolve(this.images[e.id]);const n=this.decoders;if(n[e.mimeType])return n[e.mimeType](t,{supportedFormats:this.o});if("image/crn"===e.mimeType||"image/ktx2"===e.mimeType||"image/cttf"===e.mimeType)return console.warn("missing transcoder for "+e.mimeType,", visit https://maptalks.com/docs/transcoders for details"),Promise.resolve(null);{const n=new Blob([t],{type:e.mimeType}),r=URL.createObjectURL(n);return this.l(e.id,r)}}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.i[t.id]?this.i[t.id].then(()=>this.images[t.id]):this.i[t.id]=this.l(t.id,e)}l(t,e){return new Promise((n,r)=>{this.s(e,(s,o)=>{s?r(s):(URL.revokeObjectURL(e),this.images[t]=o,n(this.images[t]))})})}}const K=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],Y=[];class Q{constructor(t,e,n){this.rootPath=t,this.gltf=e,this.h=!1,this.glbBuffer=n,this.buffers={},this.requests={},this.accessors={},this.m()}p(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.g(s).then(n=>{const{buffer:s,byteOffset:o}=n;return this.accessors[r.id]=this.T(t,e,s,o)})}g(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]=X.getArrayBuffer(t,null).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,o=s.accessors[e],i=void 0!==o.bufferView?s.bufferViews[o.bufferView]:{},a=(i.byteOffset||0)+r,c=this.A(o.type),u=F(o.componentType),f=i.byteStride||0,l={array:void 0,name:t,accessorName:e,byteLength:o.count*c*u.BYTES_PER_ELEMENT,componentType:o.componentType,count:o.count,type:o.type,itemSize:c,max:o.max,min:o.min,extensions:o.extensions};if(o.min&&(l.min=o.min),o.max&&(l.max=o.max),n)if(this.h)l.byteStride=f,l.byteOffset=a+(o.byteOffset||0),!f||f===c*u.BYTES_PER_ELEMENT||"indices"===t||"input"===t||"output"===t||t.indexOf("morph")>=0?(l.array=this._(n,o.count,c,a+(o.byteOffset||0),u),l.array.buffer.byteLength===l.byteLength&&(l.byteOffset=0)):l.array=new Uint8Array(n,a,i.byteLength);else if(o.interleaved){l.byteStride=0,l.byteOffset=0;const t=new u(o.count*c);if(l.array=G(t,n,o.count,c,f,a+(o.byteOffset||0),o.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){Y[0]=l.array[n],Y[1]=l.array[n+1],Y[2]=l.array[n+2],Y[3]=1;const r=O(Y,Y,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._(n,o.count,c,a+(o.byteOffset||0),u),l.byteOffset=l.array.byteOffset;else{l.array=new u(o.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}m(){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)}_(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=K.indexOf(t);return K[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.g(e).then(r=>{const{buffer:s,byteOffset:o}=r,i=$(s,o+(e.byteOffset||0),n);return t.content=i,t})}if(t.uri){if(D(t.uri)){const e=R(t.uri),n=$(e,0,e.byteLength);return t.content=n,Promise.resolve(t)}{const e=this.rootPath+"/"+t.uri;return X.get(e).then(e=>(t.content=e,t))}}return Promise.resolve(t)});return Promise.all(n).then(()=>t)}}class W extends J{constructor(t,e,n,r,s,o){super(r,s,o),this.rootPath=t,this.gltf=e,this.requests={},this.buffers={},this.glbBuffer=n,this.accessor=new Q(t,e,n)}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(N(t.name)&&(e.name=t.name),N(t.children)&&(e.children=t.children),N(t.jointName)&&(e.jointName=t.jointName),N(t.matrix)&&(e.matrix=t.matrix),N(t.rotation)&&(e.rotation=t.rotation),N(t.scale)&&(e.scale=t.scale),N(t.translation)&&(e.translation=t.translation),N(t.extras)&&(e.extras=t.extras),N(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=o(L,e.translation||k),r=a(z,e.rotation||j),c=i(V,e.scale||q);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,o;r.instanceTechnique&&r.instanceTechnique.values?(s=r.instanceTechnique,o=s.values.diffuse):(s=r,o=s.values.tex||s.values.diffuseTex||s.values.diffuse);const i={baseColorTexture:{index:o}};r.name&&(i.name=r.name),r.extensions&&(i.extensions=r.extensions),r.extras&&(i.extras=r.extras),e[n]=i}return e}M(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,o=this.buffers[e.bufferView]=new Uint8Array(this.glbBuffer.buffer,r,s);return this.getImageByBuffer(o,t)}return this.requestExternalImage(t)}O(t){const e=this.gltf.textures[t];if(!e)return null;const n=this.gltf.images[e.source];return this.M(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 o=this.gltf.samplers[s.sampler];return{format:s.format||6408,internalFormat:s.internalFormat||6408,type:s.type||5121,sampler:o,source:this.gltf.images[s.source]}}getMaterial(){return null}getAnimations(){return null}}class Z extends J{constructor(t,e,n,r,s,o){super(r,s,o),this.rootPath=t,this.gltf=e,this.glbBuffer=n,this.buffers={},this.requests={},this.accessor=new Q(t,e,n)}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 B(e,t),!N(t.weights)&&this.gltf.meshes&&N(e.mesh)?e.weights=this.gltf.meshes[e.mesh].weights:t.weights&&(e.weights=t.weights),e}O(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),!N(n))return null;const r=this.gltf.images[n];return this.M(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}};B(n,e);const s=N(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})}M(t){if(!N(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.I(e,t)}return null}I(t,e){const n=this.u(t,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(n,e)}u(t,e,n){n=n||0;const r=t.byteOffset+n,s=t.byteLength;return new Uint8Array(e,r,s)}v(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++)(N(t[n].input)||N(t[n].output))&&(e.push(this.accessor.p("input",t[n].input)),e.push(this.accessor.p("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 tt="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class et{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 et.readV1(r,e);if(2===s)return et.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=nt(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 o=new DataView(t,e+12);let i=0;for(;i<o.byteLength;){const a=o.getUint32(i,!0);i+=4;const c=o.getUint32(i,!0);if(i+=4,1313821514===c)n=nt(t,e+12+i,a);else if(5130562===c){s=e+12+i,r=a;break}i+=a}return{json:JSON.parse(n),glbBuffer:{byteOffset:s,buffer:t,byteLength:r}}}}function nt(t,e,n){if(tt){const r=new Uint8Array(t,e,n);return tt.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=rt[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 rt=[1,1,1,1,2,2,3,0],st=[0,0,0],ot=[0,0,0,1],it=[1,1,1],at={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},ct={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},ut={C(t,e,n,r,s,o,i,a){const c=N(t)?e.animations:[e.animations[0]],u={};for(let e=0;e<c.length;e++){const f=c[e],l=f.name||e;if(N(t)&&l!==t)continue;const y=f.channelsMap[n];if(y)for(let t=0;t<y.length;t++){const e=y[t];"translation"===e.target.path?(this.U(s,f.samplers[e.sampler],r,1),u.translation=h(st,s)):"rotation"===e.target.path?(this.P(o,f.samplers[e.sampler],r,1),u.rotation=U(ot,o)):"scale"===e.target.path?(this.U(i,f.samplers[e.sampler],r,1),u.scale=h(it,i)):"weights"===e.target.path&&a&&(this.U(a,f.samplers[e.sampler],r,a.length),u.weights=a)}}return u},U(t,e,n,r){switch(e.interpolation){case"LINEAR":{const s=this.N(ct,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.N(ct,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.N(ct,e,n,3*r);s&&(t=this.B(t,s,e.input.array,3*r));break}}return t},P(t,e,n){switch(e.interpolation){case"LINEAR":{const r=this.N(ct,e,n,1);r&&v(t,r.PREVIOUS,r.NEXT,r.INTERPOLATION);break}case"STEP":{const r=this.N(ct,e,n,1);r&&(t=M(t,...r.PREVIOUS));break}case"CUBICSPLINE":{const r=this.N(ct,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.B(t,r,e.input.array,3);for(let e=0;e<t.length;e++)t[e]=Math.cos(t[e])}break}}return t},F(t,e){const n=t.length;let r,s,o,i=0,a=n-1,c=Math.floor((i+a)/2);for(;i<=n-1&&a>=0;){if(i===a)return null;if(t[c]<=e&&e<=t[c+1]){const n=t[c];return r=c,s=c+1,o=(e-n)/(t[c+1]-n),{preIndx:r,nextIndex:s,interpolation:o}}e<t[c]?(a=c,c=Math.floor((i+a)/2)):t[c+1]<e&&(i=c,c=Math.floor((i+a)/2))}return null},N(t,e,n,r){const s=e.input.array,o=e.output.array,i=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.F(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 l=i*r;return t.PREVIOUS=o.subarray(t.PREINDEX*l,(t.PREINDEX+1)*l),t.NEXT=o.subarray(t.NEXTINDEX*l,(t.NEXTINDEX+1)*l),t},B(t,e,n,r){const s=e.INTERPOLATION,o=n[e.PREINDEX],i=n[e.NEXTINDEX];for(let n=0;n<3;n++){const a=e.PREVIOUS[r+n],c=(i-o)*e.PREVIOUS[2*r+n],u=e.NEXT[3+n],f=(i-o)*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))*u+(Math.pow(s,3)-Math.pow(s,2))*f;t[n]=l}return t},getAnimationClip(t,e,n,r){const s=t.nodes[e]&&t.nodes[e].weights;return y(st,...at.TRANSLATION),M(ot,...at.ROTATION),y(it,...at.SCALE),this.C(r,t,e,n,st,ot,it,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 o=e.channels;for(let t=0;t<o.length;t++){const n=o[t],i=e.samplers[n.sampler].input.array;i[i.length-1]>r&&(r=i[i.length-1]),i[0]<s&&(s=i[0])}const i=e.name||n;t.timeSpan[i]={max:r,min:s}}),t.timeSpan},getTimeSpanByName(t,e){const n=this.getTimeSpan(t);return n?N(e)?n[e]:n[Object.keys(n)[0]]:null}};let ft=!1;if("undefined"!=typeof OffscreenCanvas){let t;try{t=new OffscreenCanvas(2,2).getContext("2d")}catch(oe){}t&&"undefined"!=typeof createImageBitmap&&(ft=!0)}const lt="undefined"==typeof document?null:document.createElement("canvas");class ht{constructor(t,e,n){if(this.options=n||{},this.options.decoders||(this.options.decoders={}),e.buffer instanceof ArrayBuffer){const{json:n,glbBuffer:r}=et.read(e.buffer,e.byteOffset,e.byteLength);this.D(t,n,r)}else this.D(t,e);this.R=new Q(this.rootPath,this.gltf,this.glbBuffer),this.L()}L(){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")}}V(){const t=this.gltf.extensions;return t&&t.KHR_techniques_webgl?this.R.requestKHRTechniquesWebgl(t.KHR_techniques_webgl).then(e=>(t.KHR_techniques_webgl=e,t)):Promise.resolve(t)}load(t){t=t||{};const e=this.k(t),n=this.j(),r=this.q(),s=this.V();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 ut.getAnimationClip(t,e,n,r)}static getAnimationTimeSpan(t,e){return ut.getTimeSpanByName(t,e)}static getTypedArrayCtor(t){return F(t)}static readInterleavedArray(t,e,n,r,s,o,i){return G(t,e,n,r,s,o,i)}D(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=ft?pt.bind(this):this.options.requestImage||yt,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new Z(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{}),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 W(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{}),this.adapter.iterate((t,e,n)=>{e.id="accessor_"+n},"accessors"),this.adapter.iterate((t,e,n)=>{e.id="image_"+n},"images"))}G(t,e){if(t.children&&t.children.length>0){if(!("number"==typeof(n=t.children[0])&&isFinite(n)||function(t){return!P(t)&&("string"==typeof t||null!==t.constructor&&t.constructor===String)}(t.children[0])))return t;const r=t.children.map(t=>{const n=e[t];return n.nodeIndex=t,this.G(n,e)});t.children=r}var n;return t}k(t){return this.H(t).then(t=>{const e=this.scenes=[];let n;for(const e in t)t[e]=this.G(t[e],t),t[e].nodeIndex=Number(e)?Number(e):e;this.adapter.iterate((r,s,o)=>{const i={};s.name&&(i.name=s.name),s.nodes&&(i.nodes=s.nodes.map(e=>t[e])),this.gltf.scene===r&&(n=o),e.push(i)},"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 r})}H(t){return this.$(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})}X(){this.skins=[];const t=[];return this.adapter.iterate((e,n,r)=>{t.push(this.J(n).then(t=>{t.index=r,this.skins.push(t)}))},"skins"),t}J(t){const e=t.inverseBindMatrices;return this.adapter.accessor.p("inverseBindMatrices",e).then(e=>(t.inverseBindMatrices=e,e&&e.buffer&&this.transferables&&this.transferables.indexOf(e.buffer)<0&&this.transferables.push(e.buffer),t))}j(){const t=this.gltf.animations;return N(t)?this.adapter.getAnimations(t):null}$(t){this.meshes={};let e=[];return this.adapter.iterate((n,r,s)=>{e.push(this.K(r,t).then(t=>{t.index=s,this.meshes[n]=t}))},"meshes"),e=e.concat(this.X()),Promise.all(e)}K(t,e){const n=t.primitives.map(t=>this.Y(t,e)).filter(t=>!!t);return Promise.all(n).then(e=>{const n={};return B(n,t),n.primitives=e,n})}q(){const t=this.gltf.textures;if(!t)return null;const e=[];for(const n in t)e.push(this.adapter.O(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})}Y(t,e){let n;const r=[],s=t.extensions;if(N(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.p(`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:o,attributes:i}=s.KHR_draco_mesh_compression,a=this.gltf.bufferViews[o],c=this.R.g(a).then(n=>{const{buffer:r,byteOffset:s}=n;let{byteOffset:o}=a;const c=a.byteLength;o||(o=0);const u=new DataView(r,s+o,c),f={attributes:i,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.p(t,e[t]);n&&r.push(n)}if(N(t.indices)){const e=this.adapter.accessor.p("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 o={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,o=s.length/r;for(let e=0;e<o;e++)for(let o=0;o<r;o++){const i=e*r+o;s[i]<t[o]&&(t[o]=s[i]),s[i]>n[o]&&(n[o]=s[i])}if(e.quantization){const r=e.quantization,s=r.range/(1<<r.quantizationBits),o=r.minValues;p(t,t,s),m(t,t,o),p(n,n,s),m(n,n,o)}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&&(o.indices=n),r&&(o.morphTargets=r),o.mode=N(t.mode)?t.mode:4,N(t.extras)&&(o.extras=t.extras),o})}}function yt(t,e){const n=new Image;n.crossOrigin="",n.onload=()=>{if(!lt)return void e(new Error("There is no canvas to draw image!"));lt.width=n.width,lt.height=n.height;const t=lt.getContext("2d",{willReadFrequently:!0});t.drawImage(n,0,0,n.width,n.height);const r=t.getImageData(0,0,n.width,n.height),s={width:n.width,height:n.height,data:new Uint8Array(r.data)};e(null,s)},n.onerror=function(t){e(t)},n.src=t}let mt,dt;function pt(t,e){mt||(mt=new OffscreenCanvas(2,2),dt=mt.getContext("2d",{willReadFrequently:!0})),fetch(t).then(t=>t.arrayBuffer()).then(t=>{const e=new Blob([new Uint8Array(t)]);return createImageBitmap(e)}).then(t=>{let{width:n,height:r}=t;bt(n)||(n=wt(n)),bt(r)||(r=wt(r));const s=this.options.maxTextureSize;s&&(n=Math.min(s,n),r=Math.min(s,r)),mt.width=n,mt.height=r,dt.drawImage(t,0,0,n,r),t.close();const o=dt.getImageData(0,0,n,r);e(null,{width:n,height:r,data:new Uint8Array(o.data)})}).catch(t=>{console.warn(t),e(t)})}function bt(t){return 0==(t&t-1)&&0!==t}function wt(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}function Tt(t){return"object"==typeof t&&!!t}function gt(t){return t/Math.PI*180}function At(t){return Math.sign?Math.sign(t):0===(t=+t)||isNaN(t)?Number(t):t>0?1:-1}const _t=[1,1,1,1,2,2,3,0];function St(t){const e=t.length;let n="";for(let r=0;r<e;){let s=t[r++];if(128&s){let n=_t[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 Mt=[1/6378137,1/6378137,1/6356752.314245179],Ot=[1/40680631590769,1/40680631590769,1/40408299984661.445],xt=new Array(3),It=new Array(3),vt=new Array(3);function Ct(t,e){const n=Ot,r=function(t,e,n,r,s){const o=e[0],i=e[1],a=e[2],c=n[0],u=n[1],f=n[2],l=o*o*c*c,h=i*i*u*u,y=a*a*f*f,m=l+h+y,d=Math.sqrt(1/m),b=p(Ut,e,d);if(m<s)return isFinite(d)?b:void 0;const w=r[0],T=r[1],g=r[2],A=Et;A[0]=b[0]*w*2,A[1]=b[1]*T*2,A[2]=b[2]*g*2;let _,S,M,O,x,I,v,C,U,E,P,N=(1-d)*Pt(e)/(.5*Pt(A)),B=0;do{N-=B,M=1/(1+N*w),O=1/(1+N*T),x=1/(1+N*g),I=M*M,v=O*O,C=x*x,U=I*M,E=v*O,P=C*x,_=l*I+h*v+y*C-1,S=l*U*w+h*E*T+y*P*g;B=_/(-2*S)}while(Math.abs(_)>1e-12);return t[0]=o*M,t[1]=i*O,t[2]=a*x,t}(xt,e,Mt,n,.1);let s=_(It,r,n);s=function(t,e){const n=e[0],r=e[1],s=e[2];let o=n*n+r*r+s*s;o>0&&(o=Math.sqrt(o),t[0]=e[0]/o,t[1]=e[1]/o,t[2]=e[2]/o);return t}(s,s);const o=A(vt,e,r),i=Math.atan2(s[1],s[0]),a=Math.asin(s[2]),c=At(w(o,e))*Pt(o);return t[0]=gt(i),t[1]=gt(a),t[2]=c,t}const Ut=new Array(3),Et=new Array(3);function Pt(t){return f(t)}function Nt(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 Bt(t,e){let n="";for(let r=0;r<4;r++){const s=t.getUint8(e+r);n+=String.fromCharCode(s)}return n}const Ft="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function Dt(t,e,n){const r=new Uint8Array(t,e,n);return Ft?JSON.parse(Ft.decode(r)):JSON.parse(St(r))}function Rt(t,e,n){const r=new Uint8Array(t,e,n);return Ft?JSON.parse(Ft.decode(r)):JSON.parse(St(r))}function Lt(t,e,n){return{offset:e,byteLength:n}}function zt(t,e,n,r){const{byteOffset:s,componentType:o,type:i}=t,{ctor:a,type:c}=function(t){return jt[t]}(o||"UNSIGNED_SHORT"),u=function(t){if(!t)return 1;return kt[t]}(i);return{byteStride:0,byteOffset:s+n,itemSize:u,count:r*u,componentType:c,array:new a(e,n+s,r*u)}}function Vt(t,e,n,r){const s=zt(t,e,n,r);return s.array.buffer.byteLength!==e.byteLength&&(s.array=s.array.slice()),s}const kt={"SCALAR":1,"VEC2":2,"VEC3":3,"VEC4":4};const jt={"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 qt(t){for(const e in jt)if(t===jt[e].ctor)return jt[e].type;throw new Error("unrecognized ctor:"+t)}function Gt(t,e,n,r){const s=t,o=e.length/3;for(let t=0;t<o;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 Ht(t,e,n){const r=t.getUint32(12,!0),s=t.getUint32(16,!0),o=t.getUint32(20,!0),i=t.getUint32(24,!0),a=t.buffer;let c,u={},f={},l=null;r>0&&(u=Dt(a,e,r),e+=r),s>0&&(c=function(t,e,n){return{offset:e,byteLength:n}}(0,e,s),e+=s),o>0&&(f=Rt(a,e,o),e+=o);const h=Lt(0,e,i);return l=a.slice(h.offset,h.offset+h.byteLength),n.push(l),{featureTable:u,featureTableBin:c,batchTable:f,batchTableBin:l}}const $t={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"}},Xt={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},Jt={},Kt={east:[],north:[],up:[],west:[],south:[],down:[]};let Yt=[],Qt=[],Wt=[];const Zt=[0,0,0];const te=function(t,e){const n=$t[t][e];let r;const s=t+e;return Jt[s]?r=Jt[s]:(r=function(r,s,o){if(function(t,e){var n=t[0],r=t[1],s=t[2],o=e[0],i=e[1],a=e[2];return Math.abs(n-o)<=1e-6*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(r-i)<=1e-6*Math.max(1,Math.abs(r),Math.abs(i))&&Math.abs(s-a)<=1e-6*Math.max(1,Math.abs(s),Math.abs(a))}(r,Zt))h(Yt,Xt[t]),h(Qt,Xt[e]),h(Wt,Xt[n]);else if(Nt(r[0],0,1e-14)&&Nt(r[1],0,1e-14)){const s=At(r[2]);h(Yt,Xt[t]),"east"!==t&&"west"!==t&&p(Yt,Yt,s),h(Qt,Xt[e]),"east"!==e&&"west"!==e&&p(Qt,Qt,s),h(Wt,Xt[n]),"east"!==n&&"west"!==n&&p(Wt,Wt,s)}else{!function(t,e){d(e,t,Ot),b(e,e)}(r,Kt.up);const s=Kt.up,o=Kt.east;o[0]=-r[1],o[1]=r[0],o[2]=0,b(Kt.east,o),T(Kt.north,s,o),p(Kt.down,Kt.up,-1),p(Kt.west,Kt.east,-1),p(Kt.south,Kt.north,-1),Yt=Kt[t],Qt=Kt[e],Wt=Kt[n]}return o[0]=Yt[0],o[1]=Yt[1],o[2]=Yt[2],o[3]=0,o[4]=Qt[0],o[5]=Qt[1],o[6]=Qt[2],o[7]=0,o[8]=Wt[0],o[9]=Wt[1],o[10]=Wt[2],o[11]=0,o[12]=r[0],o[13]=r[1],o[14]=r[2],o[15]=1,o},Jt[s]=r),r}("east","north"),ee={5120:Int8Array,5122:Int16Array,5124:Int32Array,5121:Uint8Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};function ne(t){for(const e in ee)if(t===ee[e])return+e;throw new Error("unrecognized ctor:"+t)}\n/*!\n * @maptalks/gl v0.88.1\n * LICENSE : UNLICENSED\n * (c) 2016-2023 maptalks.com\n */const re=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")},se=re(),oe=se.gl_trans__coders=se.gl_trans__coders||{};oe.inject=function(t){const e=t.toString(),n=e.indexOf("{")+1,r=e.substring(0,n),s=se.gl_trans__coders=se.gl_trans__coders||{};let o=`${r}\\n const _____getGlobal = ${re.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&&(o+=\'tran_____scoders["\'+t+\'"] =\'+s[t].toString()+"\\n;");return o+="\\n"+e.substring(r.length),o},oe.registerTranscoder=function(t,e){oe[t]=e},oe.getTranscoder=function(t){return oe[t]};let ie=null;function ae(){return ie||(ie={"image/crn":oe.crn&&oe.crn(),"image/ktx2":oe.ktx2&&oe.ktx2(),"image/cttf":oe.ktx2&&oe.ktx2(),"draco":oe.draco&&oe.draco()}),ie}class ce{constructor(t,e,n){this.s=t,this.W=e||ht,this.o=n,this.Z=ae()}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.tt(t,e,n,r,s)):X.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.tt(t,s,n,r)})}tt(t,e,n,r,s){const o=s&&s.maxTextureSize,i=this.et(e,n,r,t);if(i.error)return Promise.resolve(i);const a=t.substring(0,t.lastIndexOf("/")),c=new this.W(a,i.glb,{transferable:!0,requestImage:this.s,decoders:this.Z,supportedFormats:this.o,maxTextureSize:o});return c.load({skipAttributeTransform:!1}).then(e=>{e.url=`${t}-${n}-${r}`;const s=c.transferables;for(let t=0;t<i.transferables.length;t++)s.indexOf(i.transferables[t])<0&&s.push(i.transferables[t]);return{magic:"b3dm",count:i.count,transferables:s,featureTable:i.featureTable,batchTable:i.batchTable,batchTableBin:i.batchTableBin,gltf:e}})}et(t,e,n,r){const s=new DataView(t,e,n),o=s.getUint32(4,!0);if(1!==o){const t="Unsupported b3dm version: "+o+", 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 i,a=s.getUint32(12,!0),c=s.getUint32(16,!0),u=s.getUint32(20,!0),f=s.getUint32(24,!0),l=28+e;u>=570425344?(l-=8,i=a,u=c,f=0,a=0,c=0):f>=570425344&&(l-=4,i=u,u=a,f=c,a=0,c=0);const h=[t];let y,m,d;if(a>0?(y=Dt(t,l,a),l+=a,i=y.BATCH_LENGTH):y={"BATCH_LENGTH":i},c>0&&(l+=c),u>0&&(m=Rt(t,l,u),l+=u,f>0)){const e=Lt(0,l,f);d=t.slice(e.offset,e.offset+e.byteLength),l+=f,h.push(d)}const p=y.BATCH_LENGTH,b={};if(y&&y.BATCH_ID){b.BATCH_ID=Vt(y.BATCH_ID,t,(void 0).offset,p);const e=b.BATCH_ID.array&&b.BATCH_ID.array.buffer;e&&h.indexOf(e)<0&&h.push(e)}return{count:i,transferables:h,featureTable:y,batchTable:m,batchTableBin:d,b3dm:b,glb:{buffer:t,byteOffset:l,byteLength:s.byteLength+s.byteOffset-l}}}nt(){return null}}class ue{constructor(t,e,n,r){this.s=t,this.W=e||ht,this.o=n,this.Z=ae(),this.rt=r}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.tt(t,e,n,r,s)):X.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.tt(t,s,n,r)})}tt(t,e,n,r,s){return this.st(t,e,n,r,s).then(({gltf:s,transferables:o})=>{const i=this.ot(e,n,r,t);if(i.error)return Promise.resolve(i);for(let t=0;t<o.length;t++)-1===i.transferables.indexOf(o[t])&&i.transferables.push(o[t]);return delete s.transferables,Promise.resolve({magic:"i3dm",count:i.count,transferables:i.transferables,featureTable:i.featureTable,batchTable:i.batchTable,batchTableBin:i.batchTableBin,i3dm:i.i3dm,gltf:s})})}st(t,e,n,r,s){const o=s&&s.maxTextureSize,i={transferable:!0,requestImage:this.s,decoders:this.Z,supportedFormats:this.o,maxTextureSize:o},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=St(new Uint8Array(e,c+n,a.byteLength-c));-1==r.indexOf("://")&&(r=t.substring(0,t.lastIndexOf("/"))+"/"+r);return r.indexOf(".glb")>0?X.getArrayBuffer(r,{}).then(t=>this.it(r,{buffer:t.data,byteOffset:0},i)):X.getJSON(r,{}).then(t=>this.it(r,t,i))}{const r={buffer:e,byteOffset:c+n,byteLength:a.byteLength-c};return this.it(t,r,i)}}it(t,e,n){const r=t.substring(0,t.lastIndexOf("/")),s=new this.W(r,e,n);return s.load({skipAttributeTransform:!0}).then(n=>{let r=0,o=0;return e.buffer&&(r=e.byteOffset||0,o=e.byteLength||0),n.url=`${t}-${r}-${o}`,{transferables:s.transferables,gltf:n}})}ot(t,e,n,r){const s=new DataView(t,e,n),o=s.getUint32(4,!0);if(1!==o){const t="Unsupported pnts version: "+o+", 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 i=[t],{featureTable:a,featureTableBin:c,batchTable:u,batchTableBin:f}=Ht(s,32+e,i),l={},h=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;l.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},i.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:h,componentType:5126,array:this.ct(new Uint16Array(t,r+c.offset,3*h),e,n)},i.push(l.POSITION.array.buffer)}if(a.BATCH_ID){l.BATCH_ID=Vt(a.BATCH_ID,t,c.offset,h);const e=l.BATCH_ID.array&&l.BATCH_ID.array.buffer;e&&i.indexOf(e)<0&&i.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;l.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},i.push(l.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,l.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},i.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:h,componentType:5126,array:this.ut(new Uint16Array(t,e+c.offset,2*h))},i.push(l.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,l.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.ut(new Uint16Array(t,e+c.offset,2*h))},i.push(l.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;l.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,h).slice()},i.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:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},i.push(l.SCALE_NON_UNIFORM.array.buffer)}return{count:h,batchTable:u,batchTableBin:f,featureTable:a,i3dm:l,transferables:i}}ut(t){const e=t.length/2,n=new Float32Array(3*e),r=[];for(let s=0;s<e;s++)fe(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}ct(t,e,n){return Gt(new Float32Array(t.length),t,e,n)}nt(){return null}}function fe(t,e,n,r){if(t[0]=le(e,r),t[1]=le(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]))*he(e),t[1]=(1-Math.abs(e))*he(t[1])}return b(t,t)}function le(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 he(t){return t<0?-1:1}class ye{constructor(){}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.tt(t,e,n,r)):X.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.tt(t,s,n,r)})}tt(t,e,n,r){return this.ft(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})}ft(t,e,n,r){const s=new DataView(t,e,n),o=s.getUint32(4,!0);if(1!==o){const t="Unsupported pnts version: "+o+", 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 i=[t],{featureTable:a,featureTableBin:c,batchTable:u,batchTableBin:f}=Ht(s,e+28,i),l=a.QUANTIZED_VOLUME_OFFSET,h=a.QUANTIZED_VOLUME_SCALE,y=a.POINTS_LENGTH;let m,d={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){d=a.extensions["3DTILES_draco_point_compression"],m=new DataView(t,d.byteOffset+c.offset,d.byteLength);const e={attributes:d.properties,useUniqueIDs:!1};return this.lt||(this.lt=ae().draco),this.lt(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.ht(t,e.attributes,c.offset,y,i,l,h);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:qt(t.constructor),array:t},i.push(t.buffer)}else if(a.BATCH_ID||Object.keys(u).length){a.BATCH_ID?r.BATCH_ID=Vt(a.BATCH_ID,t,c.offset,y):r.BATCH_ID=me(y);const e=r.BATCH_ID.array&&r.BATCH_ID.array.buffer;e&&i.indexOf(e)<0&&i.push(e)}return{count:y,batchTable:u,batchTableBin:f,featureTable:a,pnts:r,transferables:i}})}const p=this.ht(t,a,c.offset,y,i,l,h);if(a.BATCH_ID||Object.keys(u).length){a.BATCH_ID?p.BATCH_ID=Vt(a.BATCH_ID,t,c.offset,y):p.BATCH_ID=me(y);const e=p.BATCH_ID.array&&p.BATCH_ID.array.buffer;e&&i.indexOf(e)<0&&i.push(e)}return Promise.resolve({count:y,batchTable:u,batchTableBin:f,featureTable:a,pnts:p,transferables:i})}ht(t,e,n,r,s,o,i){const a={};if(e.POSITION){let{byteOffset:o,array:i}=e.POSITION;o=o||0;const c=i?0:n;if(!i){const e=t.slice(o+c,o+c+3*r*4);i=new Float32Array(e)}a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:i},s.push(i.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.ct(u||new Uint16Array(t,c+f,3*r),o,i)},s.push(a.POSITION.array.buffer)}if(e.RGBA){let{byteOffset:o,array:i}=e.RGBA;o=o||0;const c=i?0:n;if(!i){const e=t.slice(o+c,o+c+4*r);i=new Uint8Array(e)}a.RGBA={byteStride:0,byteOffset:0,itemSize:4,count:r,componentType:5121,array:i},s.push(i.buffer)}else if(e.RGB){let{byteOffset:o,array:i}=e.RGB;o=o||0;const c=i?0:n;if(!i){const e=t.slice(o+c,o+c+3*r);i=new Uint8Array(e)}a.RGB={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5121,array:i},s.push(i.buffer)}else if(e.RGB565){let{byteOffset:o,array:i}=e.RGB565;o=o||0;const c=i?0:n;if(!i){const e=t.slice(o+c,o+c+2*r);i=new Uint16Array(e)}a.RGB565={byteStride:0,byteOffset:0,itemSize:1,count:r,componentType:5123,array:i},s.push(i.buffer)}if(e.NORMAL){let{byteOffset:o,array:i}=e.NORMAL;o=o||0;const c=i?0:n;if(!i){const e=t.slice(o+c,o+c+3*r*4);i=new Float32Array(e)}a.NORMAL={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:i},s.push(i.buffer)}else if(e.NORMAL_OCT16P){let{byteOffset:o,array:i}=e.NORMAL_OCT16P;o=o||0;const c=i?0:n;if(!i){const e=t.slice(o+c,o+c+2*r);i=new Uint8Array(e)}a.NORMAL_OCT16P={byteStride:0,byteOffset:0,itemSize:2,count:r,componentType:5121,array:i},s.push(i.buffer)}return a}ct(t,e,n){return Gt(new Float32Array(t.length),t,e,n)}nt(){return null}}function me(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:qt(e),array:r}}class de{constructor(t,e,n,r){this.o=n,this.s=t,this.W=e||ht,this.rt=r}load(t,e,n=0,r=0,s){return e?this.tt(t,e,n,r,s):X.getArrayBuffer(t,{}).then(e=>{const s=e.data;return this.tt(t,s,n,r)})}tt(t,e,n,r,s){r||(r=e.byteLength);const o=this.yt(e,t,n,r),i=[];for(let n=0;n<o.length;n++){let r;if("b3dm"===o[n].magic)r=new ce(this.s,this.W,this.o);else if("i3dm"===o[n].magic)r=new ue(this.s,this.W,this.o,this.rt);else if("pnts"===o[n].magic)r=new ye;else{if("cmpt"!==o[n].magic){console.warn("Unsupported magic in CMPT tile:",o[n].magic);continue}r=new de(this.s,this.W,this.o,this.rt)}i.push(r.load(t,e,o[n].offset,o[n].byteLength,s).then(t=>t))}return Promise.all(i).then(t=>({magic:"cmpt",tiles:t}))}yt(t,e,n,r){const s=new DataView(t,n,r),o=s.getUint32(4,!0);if(1!==o){const t="Unsupported cmpt version: "+o+", url:"+e;return console.warn(t),{error:t}}if(16===s.byteLength)return[];const i=[],a=s.getUint32(12,!0);let c=16;for(let e=0;e<a;e++){const e=Bt(s,c),r=s.getUint32(c+8,!0);i.push({magic:e,buffer:t,offset:c+n,byteLength:r}),c+=r}return i}}function pe(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=[];Se(r[n],s,t,e)}}}const be=[],we=[],Te=[],ge=[0,0,0],Ae=I([]),_e=[1,1,1];function Se(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=o(be,t.translation||ge),n=a(we,t.rotation||Ae),r=i(Te,t.scale||_e);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++)Se(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),o=s.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 Me(t,e){let{byteOffset:n,byteStride:r,count:s}=t;const{componentType:o,itemSize:i}=t,a=t.array.buffer,c=o?ht.getTypedArrayCtor(o):t.array.constructor;if(n=void 0===n?t.array.byteOffset:n,r=r||0,s=s||t.array.length/i,(!r||r===i*c.BYTES_PER_ELEMENT)&&n%c.BYTES_PER_ELEMENT==0){const t=new c(a,n,s*i);for(let r=0;r<s*i;r+=i){e(new c(t.buffer,n+r*c.BYTES_PER_ELEMENT,i),r/i)}return}const u=new Uint8Array(i*c.BYTES_PER_ELEMENT);r||(r=i*c.BYTES_PER_ELEMENT);for(let t=0;t<s;t++){const s=new Uint8Array(a,r*t+n,i*c.BYTES_PER_ELEMENT);u.set(s);e(new c(u.buffer),t),s.set(u)}}var Oe=Ue("DXT1"),xe=Ue("DXT3"),Ie=Ue("DXT5"),ve=Ue("DX10"),Ce=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 Oe:e=8,n="dxt1";break;case xe:e=16,n="dxt3";break;case Ie:e=16,n="dxt5";break;case 116:n="rgba32f";break;case ve:var o=new Uint32Array(t.slice(128,148));n=o[0];var i=o[1];if(o[2],o[3],o[4],3!==i||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 l,h=r[4],y=r[3],m=r[1]+4,d=h,p=y,b=[];s===ve&&(m+=20);if(f)for(var w=0;w<6;w++){if("rgba32f"!==n)throw new Error("Only RGBA32f cubemaps are supported");h=d,y=p;for(var T=Math.log(h)/Math.log(2)+1,g=0;g<T;g++)l=h*y*16,b.push({offset:m,length:l,shape:[h,y]}),g<u&&(m+=l),h=Math.floor(h/2),y=Math.floor(y/2)}else for(g=0;g<u;g++)l=Math.max(4,h)/4*Math.max(4,y)/4*e,b.push({offset:m,length:l,shape:[h,y]}),m+=l,h=Math.floor(h/2),y=Math.floor(y/2);return{shape:[d,p],images:b,format:n,flags:c,cubemap:f}};function Ue(t){return t.charCodeAt(0)+(t.charCodeAt(1)<<8)+(t.charCodeAt(2)<<16)+(t.charCodeAt(3)<<24)}const Ee=Math.PI/180,Pe=6378137*Math.PI/180;function Ne(t,e,n){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 o;o=0===s?0:Math.log(Math.tan((90+s)*Ee/2))/Ee;return t[0]=r*Pe,t[1]=o*Pe,t}(t,e);if("EPSG:4326"===n||"EPSG:4490"===n||"identity"===n)return Be(t,e);if("baidu"===n)return Be(t,e);throw new Error("unsupported projection:"+n)}function Be(t,e){return t[0]=e[0],t[1]=e[1],t}const Fe=r([]),De=ae().draco,Re=ae().ktx2,Le={"pbrMetallicRoughness":{"baseColorFactor":[.5,.5,.5,1],"metallicFactor":0,"roughnessFactor":.5}},ze={"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 Ve(t,e,n,s){const o=[],i=[],a=[];for(let e=0;e<t.meshes.length;e++){const{geometry:n,material:r}=t.meshes[e],s=X.getArrayBuffer(n.url);s.xhr.url=n.url,a.push(s.xhr);const c=s.then(t=>({buffer:t}));o.push(c);const u=[];if(Xe(r,u),u.length){const t=u.map(t=>{const e=X.getArrayBuffer(t.url);return e.xhr.url=t.url,a.push(e.xhr),e.then(e=>e&&e.status?null:{buffer:e,mimeType:t.mimeType,format:t.format})});o.push(...t)}i[e]=u.length}const c=Promise.all(o).then(o=>{for(let t=0;t<o.length;t++)if(!o[t]||!o[t].buffer)return Promise.resolve(null);const a=[];let c=0;for(let t=0;t<i.length;t++){const e=i[t];a.push({geoBuffer:{data:o[c].buffer.data},textureBuffers:o.slice(c+1,e+c+1).map(t=>({data:t.buffer.data,mimeType:t.mimeType,format:t.format}))}),c+=1+e}return function(t,e,n,s,o){const i={asset:{generator:"i3s",version:"2.0"},extensions:{},scene:0,scenes:[{nodes:[]}],nodes:{},meshes:{},materials:[],skins:[],animations:null,textures:[],transferables:[]},a=[];for(let c=0;c<t.meshes.length;c++){let{material:u}=t.meshes[c];const{geometry:f}=t.meshes[c];let l;const h=e[c].geoBuffer.data;if(!h)continue;const y=Ze(h);l=y?je(i,c,f,h,t.transform,t.center,o):Ge(i,c,f,h,t.transform,t.center,o),a.push(l),i.nodes[c]={mesh:c,nodeIndex:c,matrix:r([])},i.scenes[0].nodes[c]=i.nodes[c],u||(u=Le);const m=$e(c,i,u,e[c].textureBuffers,n,s);a.push(m)}return Promise.all(a).then(()=>({gltf:i,featureTable:{BATCH_LENGTH:0},transferables:i.transferables}))}(t,a,e,s,n)});return c.xhr=a,c}const ke={"magFilter":9728,"minFilter":9728,"wrapR":33071,"wrapS":33071,"wrapT":33071};function je(t,e,n,r,s,o,i){const a=n.info.compressedAttributes.attributes.reduce((t,e,n)=>{const r=ze[e];if(!r)return t;return t[r.name||e]=n,t},{});return De(r,{attributes:a,metadatas:{"POSITION":[{name:"i3s-scale_x",type:"double"},{name:"i3s-scale_y",type:"double"}]},useUniqueIDs:!1,skipAttributeTransform:!1}).then(n=>He(n,t,e,s,o,i))}const qe={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 Ge(t,e,n,r,s,o,i){const a={vertexCount:0},c=new DataView(r);try{let t=0;a.vertexCount=c.getUint32(t,1),t+=4,a.featureCount=c.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++)qe[n[e]]?t=qe[n[e]](a,r,t):console.error("Unknown decoder for",n[e])}else{const e=n.info;let s=e.ordering,o=e.featureAttributeOrder;const i=null;i&&i.geometryData&&i.geometryData[0]&&i.geometryData[0].params;for(let e=0;e<s.length;e++){const n=qe[s[e]];n||console.log(s[e]),t=n(a,r,t)}for(let e=0;e<o.length;e++){const n=qe[o[e]];n||console.log(o[e]),t=n(a,r,t)}}}catch(t){}a.scale_x=1,a.scale_y=1;const u={};for(const t in a){const e=ze[t]&&ze[t].name;e&&(u[e]=a[t])}if(a.faceRange){const t=a.faceRange.array,e=t.length/2,n=(f=e)<=255?Uint8Array:f<=65535?Uint16Array:Uint32Array,r=new n(u.POSITION.array.length/3);for(let e=0;e<t.length-1;e+=2){const n=e/2,s=t[e],o=t[e+1];for(let t=s;t<=o;t++)r[3*t]=n,r[3*t+1]=n,r[3*t+2]=n}u._BATCHID={componentType:ne(n),array:r,itemSize:1,count:r.length,type:"SCALAR"}}var f;return He({attributes:u},t,e,s,o,i)}function He(t,e,n,r,s,o){const i={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 a=function(t,e,n,r){const s=n;let o,i=[0,0,0,1];const a=[0,0],u=Ne([],n,r);u[2]=n[2];const f=e&&c(Fe,e);return Me(t,t=>(i[0]=t[0],i[1]=t[1],i[2]=t[2],f||(i=g(i,i,e)),s&&m(i,i,s),Ne(a,i,r),o=i[2],t[0]=a[0]-u[0],t[1]=a[1]-u[1],t[2]=o-u[2],t)),u}(t.attributes.POSITION,r,s,o);e.meshes[n]={primitives:[i],index:n},e.extensions.MAPTALKS_RTC={projCenter:a},e.extensions.CESIUM_RTC={rtcCoord:s};for(const n in t.attributes)We(e.transferables,t.attributes[n].array.buffer);return t.indices&&We(e.transferables,t.indices.array.buffer),i}function $e(t,e,n,r,s,o){const i=r.map(t=>function(t,e,n,r,s){if("dds"===e){const e=Ce(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:ke,format:s})}if("png"===e||"jpg"===e)return function(t,e){Je||(Je=new OffscreenCanvas(2,2),Ke=Je.getContext("2d",{willReadFrequently:!0}));const n=new Blob([new Uint8Array(t)]);return createImageBitmap(n).then(t=>{let{width:n,height:r}=t;Ye(n)||(n=Qe(n)),Ye(r)||(r=Qe(r));const s=e;s&&(n=Math.min(s,n),r=Math.min(s,r)),Je.width=n,Je.height=r,Ke.drawImage(t,0,0,n,r),t.close();const o=Ke.getImageData(0,0,n,r);return{width:n,height:r,array:new Uint8Array(o.data)}}).catch(()=>({width:2,height:2,array:new Uint8Array(4)}))}(t,s).then(t=>{t.mimeType=n;return{image:t,sampler:ke,format:6408}});if("ktx2"===e)return Re(t,r).then(t=>(t.mimeType=n,{image:t,sampler:ke,format:t.format}));return null}(t.data,t.format,t.mimeType,s,o).then(t=>{if(t.image)if(t.image.array)We(e.transferables,t.image.array.buffer);else if(t.image.mipmap)for(let n=0;n<t.image.mipmap.length;n++)We(e.transferables,t.image.mipmap[n].buffer);return t}));return Promise.all(i).then(r=>{!function t(e,n,r,s){const o=JSON.parse(JSON.stringify(r)),i=n.textures;s.ptr||(s.ptr=0);for(const e in r)r[e]&&r[e].url?(i.push(s[s.ptr++]),o[e]={index:i.length-1},void 0!==r[e].factor&&(o[e].scale=r[e].factor)):Tt(r[e])&&(o[e]=t(-1,n,r[e],s));e>=0&&(n.materials[e]=o);return o}(t,e,n,r)})}function Xe(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}):Tt(t[n])&&Xe(t[n],e)}let Je,Ke;function Ye(t){return 0==(t&t-1)&&0!==t}function Qe(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}function We(t,e){e&&(t.indexOf(e)>=0||t.push(e))}function Ze(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 tn=[1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],en=[0,0,1,0,0,1,0,0,-1,0,0,0,0,0,0,1],nn="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;let rn,sn=!1;if("undefined"!=typeof OffscreenCanvas){try{rn=new OffscreenCanvas(2,2).getContext("2d",{willReadFrequently:!0})}catch(t){}rn&&"undefined"!=typeof createImageBitmap&&(sn=!0)}const on=r([]),an=[0,0,0],cn=[],un=[],fn=[],ln=[],hn={"POSITION":1,"TEXCOORD_0":1,"TEXCOORD_1":1,"NORMAL":1,"TANGENT":1};class yn{constructor(t,e,n,r){this.id=t,this.options=e,this.dt=this.requestImage.bind(this),this.pt=n,this.bt={},r(null,{},[])}wt(t){this.Tt||(this.o=t,this.gt=new ye,this.Tt=new ce(this.dt,ht,t),this.At=new ue(this.dt,ht,t))}requestImage(t,e){sn?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,rn.drawImage(t,0,0);const n=rn.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.pt("requestImage",{url:t},null,e)}loadTile(t,e){this.wt(t.supportedFormats);const n=t.service,r=t.url,s=t.arraybuffer;if(function(t){return t.indexOf("i3s:")>=0}(r)){const s=t.i3sInfo,o=n.maxTextureSize||1024,i=Ve(s,t.supportedFormats,this.options.projection,o);return i.then(t=>{if(delete this.bt[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._t(t.gltf),e(null,t,n)}),void(this.bt[r]=i.xhr)}if(s){delete this.bt[r];const n=Bt(new DataView(s),0);if("{"===n[0]||" "===n[0]||"<"===n[0]){const n=function(t,e,n){if(nn){const r=new Uint8Array(t,e,n);return nn.decode(r)}return St(new Uint8Array(t,e,n))}(s,0,s.byteLength),o=JSON.parse(n);this.St(t.rootIdx,o,s,r,e)}else this.Mt(s,r,t,n,e)}else{let s=n.urlParams;s&&(s=(r.indexOf("?")>0?"&":"?")+s);const o=r.replace(/\\+/g,"%2B");let i=X.getArrayBuffer(o+(s||""),n.fetchOptions);const a=i.xhr;i=i.then(n=>{delete this.bt[r],n&&n.status?e(n):(t.arraybuffer=n&&n.data,this.loadTile(t,e))}).catch(t=>{delete this.bt[r],e(t)}),this.bt[r]=a}}Mt(t,e,n,r,s){const o=n.service;if("b3dm"===r){this.Tt.load(e,t,0,0,{maxTextureSize:o.maxTextureSize||1024}).then(t=>{if(t.error)return void s(t);const{content:e,transferables:r}=this.Ot(t,n);this._t(e.gltf),s(null,e,r)}).catch(t=>{s(t)})}else if("pnts"===r){const r=n.transform;this.gt.load(e,t).then(t=>{const{content:e,transferables:o}=this.xt(t,r,n.rootIdx);this.It(e),s(null,e,o)})}else if("i3dm"===r){const r=n.transform;this.At.load(e,t,0,0,{maxTextureSize:o.maxTextureSize||1024}).then(t=>{const{content:e,transferables:o}=this.xt(t,r,n.rootIdx);this._t(e.gltf),s(null,e,o)})}else if("cmpt"===r){new de(this.dt,ht,this.o,o.maxTextureSize||1024).load(e,t,0,0,{maxTextureSize:o.maxTextureSize||1024}).then(t=>{const{content:e,transferables:r}=this.vt(t,n);this.Ct(e),s(null,e,r)}).catch(t=>{s(t)})}}Ct(t){t.content?t.content.forEach(t=>{this.Ct(t)}):this._t(t.gltf)}_t(t){if(!t||!t.meshes||t.extensionsUsed&&t.extensionsUsed.indexOf("KHR_techniques_webgl")>-1)return;const e=t.meshes;for(const t in e){e[t].primitives.forEach(t=>{t.compressed_int16_params={};const e=t.attributes;for(const n in e)if(hn[n]&&e[n].array&&e[n].array instanceof Float32Array){const{array:r,range:s}=Tn(e[n].array,e[n].min,e[n].max);e[n].array=r,t.compressed_int16_params[n]=s}})}}It(t){if(!t||!t.pnts)return;const e=t.pnts;t.compressed_int16_params={};for(const n in e)if(hn[n]&&e[n].array&&e[n].array instanceof Float32Array){const{array:r,range:s}=Tn(e[n].array,e[n].min,e[n].max);e[n].array=r,t.compressed_int16_params[n]=s}}Ut(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)}vt(t,e){const{tiles:n}=t,r={magic:"cmpt",content:[]},s=[];for(let t=0;t<n.length;t++){const{magic:o}=n[t];if("b3dm"===o){const{content:o,transferables:i}=this.Ot(n[t],e);bn(s,i),r.content.push(o)}else if("i3dm"===o||"pnts"===o){const{transform:o,rootIdx:i}=e,{content:a,transferables:c}=this.xt(n[t],o,i);bn(s,c),r.content.push(a)}else if("cmpt"===o){const{content:o,transferables:i}=this.vt(n[t],e);bn(s,i),r.content.push(o)}}return{content:r,transferables:s}}Ot(t,e){const{gltf:n,transferables:r,featureTable:s}=t,o=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:o}=s;if(o)for(let t=0;t<o.length;t++){const r=o[t].attributes&&o[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}(n);return this.Et(t.gltf),t.gltf.asset||(t.gltf.asset={}),o?(t.gltf.asset.sharePosition=!0,this.Pt(n,s,e.upAxis,e.transform)):this.Nt(n,s,e.upAxis,e.transform),delete t.transferables,{content:t,transferables:r}}xt(t,e,r){const{featureTable:s}=t,o=t.pnts||t.i3dm,i=s&&s.RTC_CENTER||[0,0,0];if(s.EAST_NORTH_UP&&!o.NORMAL_UP&&!o.NORMAL_UP_OCT32P){const e=new Float32Array(3*o.POSITION.array.length),r=[],s=[],a=[];Me(o.POSITION,(t,o)=>{m(a,t,i),te(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*o,9*(o+1)),s)}),o.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};dn(o.POSITION.array,3,i,on,a);const c=pn(a),u=h([],c),f=[1/0,1/0,1/0],l=[-1/0,-1/0,-1/0];Me(o.POSITION,t=>{t[0]=t[0]+i[0]-u[0],t[1]=t[1]+i[1]-u[1],t[2]=t[2]+i[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]>l[0]&&(l[0]=t[0]),t[1]>l[1]&&(l[1]=t[1]),t[2]>l[2]&&(l[2]=t[2])}),o.POSITION.min=f,o.POSITION.max=l,e&&g(c,c,e);const y=this.Bt(c);t.rtcCenter=u,t.rtcCoord=y,t.rootIdx=r;const d=t.transferables;return delete t.transferables,{content:t,transferables:d}}Et(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],o=n[2],i=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]!==o||n[t+3]!==i){a=!1;break}a&&(e[t].image.color=[r/255,s/255,o/255,i/255],delete e[t].image.array)}}}abortTileLoading(t,e){const n=this.bt[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.bt[t.url],e(null)}Ft(t,e,n,o){const i=e&&e.RTC_CENTER||t.extensions&&t.extensions.CESIUM_RTC&&t.extensions.CESIUM_RTC.center;let a=tn;"X"===(n=n&&n.toUpperCase())?a=en:"Z"===n&&(a=on),t.extensions=t.extensions||{},t.extensions.CESIUM_RTC||(t.extensions.CESIUM_RTC={}),i&&(t.extensions.CESIUM_RTC.center=i),t.extensions.MAPTALKS_RTC={};const c={xmin:1/0,xmax:-1/0,ymin:1/0,ymax:-1/0,hmin:1/0,hmax:-1/0};pe(t,t=>{if(!(t.attributes&&t.attributes.POSITION))return;const e=r(cn);t.matrices&&wn(e,t.matrices);const n=t.attributes.POSITION.array,u=t.attributes.POSITION.itemSize;s(e,a,e),o&&s(e,o,e),dn(n,u,i||an,e,c,t.compressUniforms)});const u=pn(c);return{rtcCenter:i,modelCenter:u,upAxisTransform:a}}Pt(t,e,n,o){const{modelCenter:i,upAxisTransform:a,rtcCenter:c}=this.Ft(t,e,n),u=h([],i);o&&g(i,i,o),t.extensions.CESIUM_RTC.rtcCoord=this.Bt(i),c||(pe(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(cn);t.matrices&&wn(n,t.matrices),s(n,a,n);const o=function(t,e){var n=e[0],r=e[1],s=e[2],o=e[3],i=e[4],a=e[5],c=e[6],u=e[7],f=e[8],l=e[9],h=e[10],y=e[11],m=e[12],d=e[13],p=e[14],b=e[15],w=n*a-r*i,T=n*c-s*i,g=n*u-o*i,A=r*c-s*a,_=r*u-o*a,S=s*u-o*c,M=f*d-l*m,O=f*p-h*m,x=f*b-y*m,I=l*p-h*d,v=l*b-y*d,C=h*b-y*p,U=w*C-T*v+g*I+A*x-_*O+S*M;return U?(U=1/U,t[0]=(a*C-c*v+u*I)*U,t[1]=(s*v-r*C-o*I)*U,t[2]=(d*S-p*_+b*A)*U,t[3]=(h*_-l*S-y*A)*U,t[4]=(c*x-i*C-u*O)*U,t[5]=(n*C-s*x+o*O)*U,t[6]=(p*g-m*S-b*T)*U,t[7]=(f*S-h*g+y*T)*U,t[8]=(i*v-a*x+u*M)*U,t[9]=(r*x-n*v-o*M)*U,t[10]=(m*_-d*g+b*w)*U,t[11]=(l*g-f*_-y*w)*U,t[12]=(a*O-i*I-c*M)*U,t[13]=(n*I-r*O+s*M)*U,t[14]=(d*T-m*A-p*w)*U,t[15]=(f*A-l*T+h*w)*U,t):null}(un,n),i=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];Me(e,t=>{g(t,t,n),t[0]=t[0]-u[0],t[1]=t[1]-u[1],t[2]=t[2]-u[2],g(t,t,o),t[0]<i[0]&&(i[0]=t[0]),t[1]<i[1]&&(i[1]=t[1]),t[2]<i[2]&&(i[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=i,e.max=c,e.array.buffer.projected||(e.array.buffer.projected={}),e.array.buffer.projected[e.byteOffset]=1}}),t.extensions.CESIUM_RTC.center=u)}Nt(t,e,n,r){const{modelCenter:s,rtcCenter:o}=this.Ft(t,e,n,r),i=this.Dt(s);t.extensions.MAPTALKS_RTC.projCenter=i,t.extensions.CESIUM_RTC.rtcCoord=this.Bt(s),pe(t,e=>{if(e.attributes&&e.attributes.POSITION){e.attributes.NORMAL&&this.Rt(e.attributes.NORMAL,e.matrices,n),e.attributes.TANGENT&&this.Rt(e.attributes.TANGENT,e.matrices,n);const{newPositions:s}=this.Lt(e.attributes.POSITION,e.matrices,o,t.extensions.MAPTALKS_RTC,n,r,e.compressUniforms),{componentType:i}=e.attributes.POSITION;5126!==i&&(e.attributes.POSITION.array=new Float32Array(s))}});for(const e in t.nodes){t.nodes[e].matrix=on}}Dt(t){0===S(t)?y(fn,0,0,-6378137):Ct(fn,t);const e=this.options.projection;Ne(ln,fn,e);const n=fn[2],r=[];return r[0]=ln[0],r[1]=ln[1],r[2]=n,r}Rt(t,e,r){let s;s="Y"===r?tn:"X"===r?en:on;const o=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(wn(o,e),c(o,on))return;const i=n([],o),a=[];Me(t,t=>(function(t,e,n){var r=e[0],s=e[1],o=e[2];t[0]=r*n[0]+s*n[3]+o*n[6],t[1]=r*n[1]+s*n[4]+o*n[7],t[2]=r*n[2]+s*n[5]+o*n[8]}(a,t,i),b(a,a),h(t,a),a))}Lt(t,e,n,s,o,i,a){if(t.array.buffer.projected&&t.array.buffer.projected[t.byteOffset])return null;const u=r([]);wn(u,e);const f=this.options.projection;o=o&&o.toUpperCase();const l=n;let h=null;"Y"===o?h=tn:"X"===o&&(h=en);let d=[0,0,0,1];const p=[0,0,0],b=[0,0],w=s.projCenter,T=i&&c(on,i),A=t.min=t.min||[],_=t.max=t.max||[];y(A,1/0,1/0,1/0),y(_,-1/0,-1/0,-1/0);const M=a||{},{decode_position_min:O,decode_position_normConstant:x}=M;let I=[0,0,0,0],v=1;O&&(I=O),x&&(v=x);const C=[];return Me(t,t=>{if(d[0]=t[0]*v+I[0],d[1]=t[1]*v+I[1],d[2]=t[2]*v+I[2],d=g(d,d,u),h&&(d=g(d,d,h)),l&&m(d,d,l),i&&!T&&(d=g(d,d,i)),0===S(d)?y(p,0,0,-6378137):Ct(p,d),Ne(b,p,f),t instanceof Float32Array)t[0]=b[0]-w[0],t[1]=b[1]-w[1],t[2]=p[2]-w[2];else{const e=b[0]-w[0],n=b[1]-w[1],r=p[2]-w[2];C.push(e),C.push(n),C.push(r),C.push(t[3])}return t[0]<A[0]&&(A[0]=t[0]),t[1]<A[1]&&(A[1]=t[1]),t[2]<A[2]&&(A[2]=t[2]),t[0]>_[0]&&(_[0]=t[0]),t[1]>_[1]&&(_[1]=t[1]),t[2]>_[2]&&(_[2]=t[2]),t}),t.array.buffer.projected||(t.array.buffer.projected={}),t.array.buffer.projected[t.byteOffset]=1,{projCenter:w,newPositions:C}}Bt(t){return 0===S(t)?y([],0,0,-6378137):Ct([],t)}onRemove(){}}const mn=[];function dn(t,e,n,r,s,o){const i=o||{},{decode_position_min:a,decode_position_normConstant:c}=i;let u=[0,0,0,0],f=1;a&&(u=a),c&&(f=c);for(let o=0,i=t.length;o<i;o+=e){const{xmin:i,ymin:a,xmax:c,ymax:l,hmin:h,hmax:d}=s;y(mn,t[o]*f+u[0],t[o+1]*f+u[1],t[o+2]*f+u[2]),g(mn,mn,r);const p=m(mn,n,mn);p[0]<i&&(s.xmin=p[0]),p[0]>c&&(s.xmax=p[0]),p[1]<a&&(s.ymin=p[1]),p[1]>l&&(s.ymax=p[1]),e>2&&(p[2]<h&&(s.hmin=p[2]),p[2]>d&&(s.hmax=p[2]))}}function pn(t){const{xmax:e,ymax:n,xmin:r,ymin:s,hmin:o,hmax:i}=t,a=[(r+e)/2,(s+n)/2,(o+i)/2];return e===-1/0&&(a[0]=0),n===-1/0&&(a[1]=0),i===-1/0&&(a[2]=0),isNaN(a[2])&&(a[2]=0),a}function bn(t,e){for(let n=0;n<e.length;n++)t.indexOf(e[n])<0&&t.push(e[n])}function wn(t,e){const n=t;for(let t=e.length-1;t>=0;t--)s(n,e[t],n);return n}function Tn(t,e,n){let r,s;if(e&&n)r=Math.min(...e),s=Math.max(...n);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);r=e,s=n}const o=new Int16Array(t.length);for(let e=0;e<t.length;e++){const n=2*(t[e]-r)/(s-r)-1,i=Math.max(-1,Math.min(1,n));o[e]=i<0?32768*i:32767*i}return{array:o,range:[r,s]}}let gn=0;class An{constructor(t){this.workerId=t,this.workers={},this.zt={}}addLayer({actorId:t,mapId:e,layerId:n,params:r},s){if(this.Vt(e,n))return;const o=this.kt(e,n),i=r.options,a=this.send.bind(this,t);this.workers[o]=new yn(n,i,a,s)}removeLayer({mapId:t,layerId:e},n){const r=this.Vt(t,e),s=this.kt(t,e);delete this.workers[s],r&&r.onRemove(n)}loadTile({mapId:t,layerId:e,params:n},r){const s=this.Vt(t,e);s&&s.loadTile(n,r)}abortTileLoading({mapId:t,layerId:e,params:n},r){const s=this.Vt(t,e);s&&s.abortTileLoading(n,r)}receive(t){const e=t.callback,n=this.zt[e];delete this.zt[e],n&&t.error?n(new Error(t.error)):n&&n(null,t.data)}send(t,e,n,r,s){const o=s?`${t}-${gn++}`:null;s&&(this.zt[o]=s),postMessage({type:"<request>",workerId:this.workerId,actorId:t,command:e,params:n,callback:String(o)},r||[])}kt(t,e){return`${t}-${e}`}Vt(t,e){const n=this.kt(t,e);return this.workers[n]}}t.initialize=function(){},t.onmessage=function(t,e){const n=t.data;this.dispatcher||(this.dispatcher=new An(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 instanceof Error&&(t={message:t.message}),e(t,n,r)})},Object.defineProperty(t,"jt",{value:!0})}';function O(t){return null==t}function A(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 I(t){return null!=t&&("function"==typeof t||null!==t.constructor&&t.constructor===Function)}function x(t){return"object"==typeof t&&!!t}function S(t){return"number"==typeof t&&!isNaN(t)}function M(t){return t*Math.PI/180}function N(t){return t/Math.PI*180}function E(t){let e=document.createElement("a");return e.href=t,t=e.href,e=null,t}function v(t){return Math.sign?Math.sign(t):0===(t=+t)||isNaN(t)?Number(t):t>0?1:-1}const C=[1,1,1,1,2,2,3,0];function R(t){const e=t.length;let n="";for(let r=0;r<e;){let s=t[r++];if(128&s){let n=C[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}function U(t,e,n){return t[3*n]=e[0],t[3*n+1]=e[1],t[3*n+2]=e[2],t}function L(t){return t.flat?t.flat(1/0):t.reduce((t,e)=>t.concat(e),[])}function B(t){return t<256?Uint8Array:t<65536?Uint16Array:Uint32Array}function P(t){return 0===t.indexOf("data:")}function D(t){const e=t.indexOf("base64,"),n=t.substring(e+7),r=window.atob(n),s=r.length,i=new Uint8Array(s);for(let t=0;t<s;t++)i[t]=r.charCodeAt(t);return i.buffer}function F(t){for(let e=1;e<arguments.length;e++){const n=arguments[e];if(n)for(let e=0,r=n.length;e<r;e++)t.push(n[e])}return t.length}var k=Object.freeze({__proto__:null,isNil:O,extend:A,isFunction:I,isObject:x,isNumber:S,toRadian:M,toDegree:N,getAbsoluteURL:E,sign:v,stringFromUTF8Array:R,setColumn3:U,flatArr:L,getBatchIdArrayType:B,isBase64:P,base64URLToArrayBuffer:D,pushIn:F});const H="undefined"==typeof document?null:document.createElement("canvas");class V extends t.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(!H)return void e(new Error("There is no canvas to draw image!"));const t=function(t){if(z(t.width)&&z(t.height))return t;let e=t.width,n=t.height;z(e)||(e=G(e));z(n)||(n=G(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);H.width=t.width,H.height=t.height;const r=H.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 z(t){return 0==(t&t-1)&&0!==t}function G(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}class j{constructor(t,e){this.max=t,this.currentSize=0,this.onRemove=e,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){const t=this.data.keys();let e=t.next();for(;this.currentSize>this.max&&void 0!==e.value;){if(!this.data.get(e.value).current){const t=this.getAndRemove(e.value);t&&this.onRemove(t)}e=t.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 q(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=[];Q(r[n],s,t,e)}}}const X=[],K=[],$=[],W=[0,0,0],Y=b.identity([]),Z=[1,1,1];function Q(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=g.fromTranslation(X,t.translation||W),n=g.fromQuat(K,t.rotation||Y),r=g.fromScaling($,t.scale||Z);g.multiply(r,n,r);const i=g.multiply([],e,r);s.push(i)}if(t.children&&t.children.length)for(let e=0,i=t.children.length;e<i;e++)Q(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 J(t,e,n){let{byteOffset:r,byteStride:s}=e;const{componentType:i,itemSize:o}=e,a=e.array.buffer,c=i?p.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 tt(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]}const et=new Array(3),nt=new Array(3),rt=[40680631590769,40680631590769,40408299984661.445];function st(t,e,n,r){const s=rt,i=Math.cos(n);et[0]=i*Math.cos(e),et[1]=i*Math.sin(e),et[2]=Math.sin(n),mt(et,et),T.multiply(nt,s,et);const o=Math.sqrt(T.dot(et,nt));var a,c,h;return c=nt,h=o,(a=nt)[0]=c[0]/h,a[1]=c[1]/h,a[2]=c[2]/h,T.scale(et,et,r),T.add(t,nt,et)}const it=[1/6378137,1/6378137,1/6356752.314245179],ot=[1/40680631590769,1/40680631590769,1/40408299984661.445],at=new Array(3),ct=new Array(3),ht=new Array(3);function ut(t,e){const n=ot,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],f=i*i*c*c,l=o*o*h*h,d=a*a*u*u,m=f+l+d,p=Math.sqrt(1/m),y=T.scale(ft,e,p);if(m<s)return isFinite(p)?y:void 0;const b=r[0],g=r[1],w=r[2],_=lt;_[0]=y[0]*b*2,_[1]=y[1]*g*2,_[2]=y[2]*w*2;let O,A,I,x,S,M,N,E,v,C,R,U=(1-p)*dt(e)/(.5*dt(_)),L=0;do{U-=L,I=1/(1+U*b),x=1/(1+U*g),S=1/(1+U*w),M=I*I,N=x*x,E=S*S,v=M*I,C=N*x,R=E*S,O=f*M+l*N+d*E-1,A=f*v*b+l*C*g+d*R*w;L=O/(-2*A)}while(Math.abs(O)>1e-12);return t[0]=i*I,t[1]=o*x,t[2]=a*S,t}(at,e,it,n,.1);let s=T.mul(ct,r,n);s=mt(s,s);const i=T.sub(ht,e,r),o=Math.atan2(s[1],s[0]),a=Math.asin(s[2]),c=v(T.dot(i,e))*dt(i);return t[0]=N(o),t[1]=N(a),t[2]=c,t}const ft=new Array(3),lt=new Array(3);function dt(t){return T.length(t)}function mt(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 pt(t,e){return T.multiply(e,t,ot),T.normalize(e,e)}function yt(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,T.normalize(e,e)}var bt=Object.freeze({__proto__:null,radianToCartesian3:st,cartesian3ToDegree:ut,normalizeCartesian:mt,geodeticSurfaceNormal:pt,geodeticSurfaceNormalCartographic:yt});function gt(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 Tt(t,e){let n="";for(let r=0;r<4;r++){const s=t.getUint8(e+r);n+=String.fromCharCode(s)}return n}const wt="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function _t(t,e,n){const r=new Uint8Array(t,e,n);return wt?JSON.parse(wt.decode(r)):JSON.parse(R(r))}function Ot(t,e,n){const r=new Uint8Array(t,e,n);return wt?JSON.parse(wt.decode(r)):JSON.parse(R(r))}function At(t,e,n){return{offset:e,byteLength:n}}function It(t,e,n,r){const{byteOffset:s,componentType:i,type:o}=t,{ctor:a,type:c}=vt(i||"UNSIGNED_SHORT"),h=Nt(o);return{byteStride:0,byteOffset:s+n,itemSize:h,count:r*h,componentType:c,array:new a(e,n+s,r*h)}}function xt(t,e,n,r){const s=It(t,e,n,r);return s.array.buffer.byteLength!==e.byteLength&&(s.array=s.array.slice()),s}function St(t,e,n,r){const{byteOffset:s,componentType:i,type:o}=t,{ctor:a}=vt(i||"UNSIGNED_SHORT"),c=Nt(o),h=new a(e,s,n*c);return 1===c?h[r]:h.subarray(r*c,r*c+c)}const Mt={"SCALAR":1,"VEC2":2,"VEC3":3,"VEC4":4};function Nt(t){return t?Mt[t]:1}const Et={"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 vt(t){return Et[t]}function Ct(t){for(const e in Et)if(t===Et[e].ctor)return Et[e].type;throw new Error("unrecognized ctor:"+t)}function Rt(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 Ut(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={},f=null;r>0&&(h=_t(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=Ot(a,e,i),e+=i);const l=At(0,e,o);return f=a.slice(l.offset,l.offset+l.byteLength),n.push(f),{featureTable:h,featureTableBin:c,batchTable:u,batchTableBin:f}}const Lt={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"}},Bt={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},Pt={},Dt={east:[],north:[],up:[],west:[],south:[],down:[]};let Ft=[],kt=[],Ht=[];const Vt=[0,0,0];function zt(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 Gt=function(t,e){const n=Lt[t][e];let r;const s=t+e;return Pt[s]?r=Pt[s]:(r=function(r,s,i){if(T.equals(r,Vt))T.copy(Ft,Bt[t]),T.copy(kt,Bt[e]),T.copy(Ht,Bt[n]);else if(gt(r[0],0,1e-14)&&gt(r[1],0,1e-14)){const s=v(r[2]);T.copy(Ft,Bt[t]),"east"!==t&&"west"!==t&&T.scale(Ft,Ft,s),T.copy(kt,Bt[e]),"east"!==e&&"west"!==e&&T.scale(kt,kt,s),T.copy(Ht,Bt[n]),"east"!==n&&"west"!==n&&T.scale(Ht,Ht,s)}else{pt(r,Dt.up);const s=Dt.up,i=Dt.east;i[0]=-r[1],i[1]=r[0],i[2]=0,T.normalize(Dt.east,i),T.cross(Dt.north,s,i),T.scale(Dt.down,Dt.up,-1),T.scale(Dt.west,Dt.east,-1),T.scale(Dt.south,Dt.north,-1),Ft=Dt[t],kt=Dt[e],Ht=Dt[n]}return i[0]=Ft[0],i[1]=Ft[1],i[2]=Ft[2],i[3]=0,i[4]=kt[0],i[5]=kt[1],i[6]=kt[2],i[7]=0,i[8]=Ht[0],i[9]=Ht[1],i[10]=Ht[2],i[11]=0,i[12]=r[0],i[13]=r[1],i[14]=r[2],i[15]=1,i},Pt[s]=r),r}("east","north"),jt=[],qt=[],Xt=[],Kt=[],$t=[],Wt=[],Yt=[],Zt={x:0,y:0},Qt={x:0,y:0},Jt=Math.PI/180;const{getTextureMagFilter:te,getTextureMinFilter:ee,getTextureWrap:ne,getMaterialType:re,getMaterialFormat:se,getPrimitive:ie,getUniqueREGLBuffer:oe}=n.REGLHelper,ae=[1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],ce=[0,0,1,0,0,1,0,0,-1,0,0,0,0,0,0,1],{loginIBLResOnCanvas:he,logoutIBLResOnCanvas:ue,getIBLResOnCanvas:fe,getPBRUniforms:le}=n.pbr.PBRUtils,de={factor:0,units:0},me={specularStrength:0,materialShininess:1},pe=[1,1,1],ye=r.identity([]),be=[0,0],ge=t=>t.material instanceof n.PhongMaterial,Te=t=>t.material instanceof n.pbr.StandardMaterial,we=[],_e=new t.Coordinate(0,0),Oe=new t.Point(0,0),Ae=new t.Point(0,0),Ie=new t.Point(0,0),xe=[],Se=[],Me=[],Ne=[],Ee={"POSITION":"POSITION","NORMAL":"NORMAL","TEXCOORD_0":"TEXCOORD_0","TEXCOORD_1":"TEXCOORD_1","COLOR_0":"COLOR_0","TANGENT":"TANGENT","_BATCHID":"_BATCHID"};class ve{constructor(e,r){this.t=r,this.s=r.getRenderer().canvas,this.pickingFBO=r.getRenderer().pickingFBO,this.i=new t.SpatialReference,this.o=e,this.h=new n.Renderer(e),this.u={},this.l={},this.m={},this.p={},this.g={},this.T={},this._={},this.O=new n.Scene,this.A=new n.Scene,this.I=new n.Scene,this.S=new n.Scene,this.M=new n.ResourceLoader(e.texture(2)),this.N=this.v.bind(this),this.C=new n.PhongMaterial({"baseColorFactor":[1,1,1,1]}),this.R(),this.U=new n.KHRTechniquesWebglManager(this.o,this.L(),this.M);const s=this.getMap();s.altitudeToPoint&&(this.B=s.altitudeToPoint(100,s.getGLRes())/100)}getI3DMMeshes(){return this.g}getPNTSMeshes(){return this.p}getB3DMMeshes(){return this.m}getPaintedMeshes(){return this.P}getMap(){return this.t.getMap()}paint(t,e,n){const r=n&&n.renderTarget,i=n&&n.sceneFilter,o=this.getMap();if(!t.length||!o)return null;const a=this.D(),c=o.projViewMatrix,h=[],u=[],f=[],d=[],m=[],p=this.F(t);for(let r=0,i=t.length;r<i;r++){const i=t[r].data.node;let o=this.k(i);if(!o)continue;const a=this.t.H(i.V),y=a.heightOffset||0,b=a.coordOffset||be;this.T[i.id]&&(o=this.T[i.id],o=L(o));let g=a.polygonOffset||de;I(g)&&(g=g()),Array.isArray(o)||(h[0]=o,o=h);for(let t=0,r=o.length;t<r;t++){const r=o[t].properties.magic;if(o[t].properties.heightOffset===y&&o[t].properties.coordOffset[0]===b[0]&&o[t].properties.coordOffset[1]===b[1]||this.G(o[t]),"b3dm"===r){if(o[t].getBoundingBox&&!l(c,o[t].getBoundingBox()))continue;const{batchIdData:e,batchIdMap:r}=o[t].geometry.properties;if(e&&r){const e=o[t].properties.node.V;this.j&&this.j[e]?s.highlightMesh(this.o,o[t],this.j[e],this.q,r):this.j&&this.j[e]||s.highlightMesh(this.o,o[t],null,this.q,r),s.showOnly(this.o,o[t],this.X&&this.X[e],this.K,r)}n&&n.bloom&&o[t].properties.hlBloomMesh&&(o[t].properties.hlBloomMesh.properties.depthFunc="always",o[t].properties.hlBloomMesh.properties.polygonOffset=g,f.push(o[t].properties.hlBloomMesh)),f.push(o[t])}else"pnts"===r?d.push(o[t]):"i3dm"===r&&m.push(o[t]);o[t].properties.isLeaf=!!e[i.id],o[t].properties.level=p.get(i.$),o[t].properties.polygonOffset=g,o[t].W=i,e[i.id]||u.push(o[t]),this.Y(o[t])}}let y=0;const b=this.U.getExcludeFilter();y+=this.Z(this.J,a,[i,ge,b],r,u,f,m),y+=this.Z(this.tt,a,[i,Te,b],r,u,f,m),this.U.forEachShader((t,e,n)=>{const s=this.D(n);y+=this.Z(t,s,[i,e],r,u,f,m)}),this.A.setMeshes(d);const g=this.et();return y+=this.h.render(this.nt,g,this.A,r&&r.fbo),this.P={pntsMeshes:d,i3dmMeshes:m,b3dmMeshes:f},y}Z(t,e,n,r,s,i,o){t.filter=n.filter(t=>!!t),e.debug=!1,e.debug=!1;let a=0;return this.O.setMeshes(i),a+=this.h.render(t,e,this.O,r&&r.fbo),this.I.setMeshes(o),a+=this.h.render(t,e,this.I,r&&r.fbo),a}rt(t,e){return e.W.st-t.W.st}paintRegion(t,e,n,r,s){const i=this.getMap();if(!t.length&&!e.length)return;const o=i.projViewMatrix,a=[];for(let n=0,r=(t=t.concat(e)).length;n<r;n++){const e=t[n].node,r=this.it(e);r&&(r.getBoundingBox&&!l(o,r.getBoundingBox())||a.push(r))}this.ot.filter=r,this.S.setMeshes(a);const c=this.ct(n);this.h.render(this.ot,c,this.S,s&&s.fbo)}deleteTile(t){const e=t.node.id;this.ht(e)}ht(t){const e=this.l[t];e&&(e.geometry.dispose(),e.dispose(),delete this.l[t]);const n=this.m[t]||this.p[t]||this.g[t]||this.T[t]||this.u[t];this.T[t]?this.ut(t):n&&(this.ft(n),delete this.m[t],delete this.p[t],delete this.g[t],delete this.u[t])}ut(t){let e=this.T[t];e=L(e);for(let t=0;t<e.length;t++){const{id:n}=e[t].properties;this.ht(n)}delete this.T[t]}ft(t){if(Array.isArray(t))for(let e=0,n=t.length;e<n;e++)this.ft(t[e]);else{s.showOnly(this.o,t),s.highlightMesh(this.o,t);const e=t.geometry.properties.url;if(e){const t=this._[e];t&&(t.refCount--,t.refCount<=0&&(t.geometry.dispose(),t.material.dispose(),delete this._[e]))}else t.geometry.dispose(),t.material&&t.material.dispose();t.dispose()}}remove(){const t=this.t;ue(t.getRenderer().canvas,t.getMap());for(const t in this.T)this.ut(t);this.T={};for(const t in this.m)this.ht(t);this.m={};for(const t in this.p)this.ht(t);this.p={};for(const t in this.g)this.ht(t);this.g={};for(const t in this.u)this.ht(t);this.u={};for(const t in this.l)this.ht(t);this.l={},this.J&&(this.J.dispose(),delete this.J),this.tt&&(this.tt.dispose(),delete this.tt),this.nt&&(this.nt.dispose(),delete this.nt),this.ot&&(this.ot.dispose(),delete this.ot),this.U.dispose(),this.picking&&this.picking.dispose()}it(e){if(!e.boundingVolume||!e.boundingVolume.region)return null;if(this.l[e.id])return this.l[e.id];const s=e.boundingVolume.region;let i=new t.Coordinate(N(s[0]),N(s[1])),o=new t.Coordinate(N(s[2]),N(s[3]));i=this.lt(i),o=this.lt(o);const a=i.add(o).dt(.5);i.pt(a),o.pt(a);const c=this.yt(s[4],s[5]),h=c.x,u=c.y,f=[i.x,i.y,u,o.x,i.y,u,o.x,o.y,u,i.x,o.y,u,i.x,i.y,h,o.x,i.y,h,o.x,o.y,h,i.x,o.y,h],l=new n.Geometry({aPosition:f},[0,1,1,2,2,3,3,0,0,4,1,5,2,6,3,7,4,5,5,6,6,7,7,4],0,{primitive:"lines"});l.generateBuffers(this.o);const d=new n.Mesh(l),m=r.identity([]);return d.setLocalTransform(r.translate(m,m,[a.x,a.y,0])),this.l[e.id]=d,d}k(t){return this.m[t.id]||this.p[t.id]||this.g[t.id]||this.T[t.id]}has(t){return this.k(t)||this.u[t.id]}G(t){const e=t.properties.magic;"b3dm"===e?this.bt(t):"i3dm"===e?this.gt(t):"pnts"===e&&this.Tt(t)}createPntsMesh(t,e,r,s){if(this.p[e]){const t=this.p[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,u=new n.Geometry(i,null,h,{primitive:"points",positionAttribute:"POSITION"});u.generateBuffers(this.o);const f={};i.POSITION?f.HAS_POSITION=1:i.POSITION_QUANTIZED&&(f.HAS_POSITION_QUANTIZED=1),i.RGB?f.HAS_RGB=1:i.RGBA?f.HAS_RGBA=1:i.RGB565&&(f.HAS_RGB565=1),(i.NORMAL||i.NORMAL_OCT16P)&&(f.HAS_NORMAL=1,i.NORMAL_OCT16P&&(f.HAS_NORMAL_OCT16P=1)),this.wt(f,c),t.featureTable.CONSTANT_RGBA&&(t.featureTable.CONSTANT_RGBA=t.featureTable.CONSTANT_RGBA.map(t=>t/255));const{rtcCenter:l,rtcCoord:d}=t,m=this.t.H(a),p=new n.Mesh(u);return p.properties.magic="pnts",p.properties.id=e,p.properties.node=r,p.properties.count=h,p.properties.batchTable=t.batchTable,p.properties.batchTableBin=t.batchTableBin,p.properties.serviceIndex=a,p.properties.rtcCoord=d,p.properties.rtcCenter=l,p.setDefines(f),Object.defineProperty(p.uniforms,"pointColor",{enumerable:!0,get:function(){return t.featureTable.CONSTANT_RGBA?t.featureTable.CONSTANT_RGBA:m&&m.pointColor||[1,1,1,1]}}),Object.defineProperty(p.uniforms,"pointSize",{enumerable:!0,get:function(){return m&&m.pointSize||2}}),Object.defineProperty(p.uniforms,"pointOpacity",{enumerable:!0,get:function(){return m&&m.pointOpacity||1}}),this._t(p,c),this.Tt(p),this.p[e]=p,s(null,{id:e,mesh:[p]}),[p]}Tt(t){const{rtcCenter:e,rtcCoord:n,node:s}=t.properties,i=this.Ot(Me,n),o=t.localTransform||[];this.At(o,s,e,n),r.multiply(o,o,i);const a=this.t.H(s.V);if(a.coordOffset){const t=this.It(s.V,n);r.multiply(o,t,o)}t.setLocalTransform(o),t.properties.heightOffset=a.heightOffset||0,t.properties.coordOffset=a.coordOffset&&a.coordOffset.slice(0)||be}createI3DMMesh(t,e,s,o){if(this.g[e]){const t=this.g[e];return console.warn(`i3dm mesh with id(${e}) was already created.`),this.u[e]||o(null,{id:e,mesh:t}),t}const a=this.t.H(s.V),h=this.xt(s.St),{i3dm:u,featureTable:f,gltf:l,batchTable:d,batchTableBin:m,count:y}=t,b=f.INSTANCES_LENGTH,{rtcCenter:g,rtcCoord:T}=t,w=this.Ot(Me,T),_=this.At(Ne,s,g,T);r.multiply(w,_,w);const{POSITION:O,NORMAL_UP:A,NORMAL_RIGHT:I,SCALE:x,SCALE_NON_UNIFORM:S,INSTANCE_ROTATION:M}=u,N={"instance_vectorA":new Float32Array(4*b),"instance_vectorB":new Float32Array(4*b),"instance_vectorC":new Float32Array(4*b)},E=new Float32Array(3),v=new Float32Array(3),C=[],R=new Float32Array(1),L=new Float32Array(3),B=[],P=[],D=[],F=[],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?p.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)}}(O,(t,e)=>{A?(J(v,I,e),J(E,A,e),i.cross(C,v,E),i.normalize(C,C),U(B,v,0),U(B,E,1),U(B,C,2),c.fromMat3(P,B)):M?(J(k,M,e),c.fromMat3(P,k)):c.identity(P),x?(J(R,x,e),i.set(D,R[0],R[0],R[0])):S?(J(L,S,e),i.set(D,...L)):i.set(D,1,1,1),r.fromRotationTranslationScale(F,P,t,D),tt(N.instance_vectorA,e,F,0),tt(N.instance_vectorB,e,F,1),tt(N.instance_vectorC,e,F,2)});const H={};for(const t in N)H[t]={buffer:this.o.buffer({dimension:N[t].length/b,data:N[t]}),divisor:1};const V=a.shader||"pbr";let z=0,G=!0;const j=[];return q(l,(t,i,o,a)=>{const{geometry:c,material:u}=this.Mt(t,i,o,a,s,!0,V);u&&!u.isReady()&&(G=!1,z++);const f=new n.InstancedMesh(H,b,c,u);f.properties.magic="i3dm",f.properties.id=e,f.properties.count=y,f.properties.batchTable=d,f.properties.batchTableBin=m,f.properties.serviceIndex=s.V,f.properties.rtcCoord=T,f.properties.rtcCenter=g,f.properties.node=s;const l=this.Nt(t,c,u,s.V,a);t.compressed_int16_params&&this._t(f,t.compressed_int16_params),this.Et(f,t.attributes);const p=r.identity([]);if(t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)r.multiply(p,p,t.matrices[e]);r.multiply(p,h,p),f.setPositionMatrix(p),this.gt(f,w),f.setDefines(l),f.properties.polygonOffset={offset:0,factor:0},j.push(f),delete t.attributes}),G?(this.g[e]=j,o(null,{id:e,mesh:j})):(this.u[e]={meshes:j,count:z},j.vt=o),j}gt(t,e){const{rtcCenter:n,rtcCoord:s,node:i}=t.properties;if(!e){e=this.Ot(Me,s);const t=this.At(Ne,i,n,s);r.multiply(e,t,e)}const o=this.t.H(i.V),a=t.localTransform||[];if(o.coordOffset){const t=this.It(i.V,s);r.multiply(a,t,e)}else r.copy(a,e);t.setLocalTransform(a),t.properties.heightOffset=o.heightOffset||0,t.properties.coordOffset=o.coordOffset&&o.coordOffset.slice(0)||be}createB3DMMesh(e,s,i,o){if(this.m[s]||this.u[s]){const t=this.m[s];return console.warn(`mesh with id(${s}) was already created.`),this.u[s]||o(null,{id:s,mesh:t}),t}let a;if(i.maxExtent){const e=new t.Extent(i.maxExtent).convertTo(t=>this._pointToPrj(t));a=[e.xmin,e.ymin,e.xmax,e.ymax]}const c=e.gltf,{projCenter:h}=c.extensions.MAPTALKS_RTC,{rtcCoord:u,center:f}=c.extensions.CESIUM_RTC,l=c.asset.sharePosition,d=this.xt(i.St);let m;m=l?this.Ot(Me,u):this.Ct(Me,u,h,i.V);const p=this.t.H(i.V);let y=p.shader||"pbr";if(c.materials)for(let t=0;t<c.materials.length;t++)if(c.materials[t]&&c.materials[t].extensions&&c.materials[t].extensions.KHR_materials_unlit){y=p.shader="phong";break}const b=[];let g=0,T=!0;return q(c,(t,o,c,w)=>{const{geometry:_,material:O}=this.Mt(t,o,c,w,i,!1,y);O&&!O.isReady()&&(T=!1,g++);const A=new n.Mesh(_,O);A.properties.magic="b3dm",A.properties.id=s,A.properties.node=i,A.properties.batchTable=e.batchTable,A.properties.batchTableBin=e.batchTableBin,A.properties.count=e.featureTable.BATCH_LENGTH,A.properties.serviceIndex=i.V;const I=this.Nt(t,_,O,i.V,w);A.setDefines(I);const x=t.compressUniforms;if(x)for(const t in x)A.setUniform(t,x[t]);t.compressed_int16_params&&this._t(A,t.compressed_int16_params),this.Et(A,t.attributes),a&&(I.USE_MAX_EXTENT=1,A.setUniform("maxPrjExtent",a)),Object.prototype.hasOwnProperty.call(A.uniforms,"polygonOpacity")||Object.defineProperty(A.uniforms,"polygonOpacity",{enumerable:!0,get:function(){return S(p.opacity)?p.opacity:1}});const M=r.identity([]);if(l&&t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)r.multiply(M,M,t.matrices[e]);l&&r.multiply(M,d,M),A.properties.node=i,A.properties.projCenter=h,A.properties.nodeMatrix=M,A.properties.isSharedPosition=l,A.properties.rtcCoord=u,A.properties.rtcCenter=f,this.bt(A,m),b.push(A),delete t.attributes}),T?(this.m[s]=b,o(null,{id:s,mesh:b})):(this.u[s]={meshes:b,count:g},b.vt=o),b}_t(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)}bt(t,e){const{isSharedPosition:n,rtcCoord:s,rtcCenter:i,projCenter:o,nodeMatrix:a,node:c}=t.properties;e||(e=n?this.Ot(Me,s):this.Ct(Me,s,o,c.V));const h=t.localTransform||r.identity([]);if(n){const t=this.At(Ne,c,i,s);r.multiply(h,e,a),r.multiply(h,t,h)}else r.multiply(h,e,a);const u=this.t.H(c.V);if(u.coordOffset){const t=this.It(Ne,c.V,s);r.multiply(h,t,h)}t.setLocalTransform(h),t.properties.heightOffset=u.heightOffset||0,t.properties.coordOffset=u.coordOffset&&u.coordOffset.slice(0)||be}Et(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)}}At(e,n,s,o){const a=this.getMap(),c=this.t.H(n.V).heightOffset||0,h=new t.Coordinate(o);let u;u=a.altitudeToPoint?this.B:a.distanceToPointAtRes(100,100,a.getGLRes(),h).y/100;const f=n.matrix?r.copy(e,n.matrix):r.identity(e);if(s){zt(f,i.transformMat4(we,s,f),f)}const l=function(t,e,n,r,s,i,o){e=T.copy(jt,e);const a=st(jt,e[0]*Jt,e[1]*Jt,e[2]),c=g.getTranslation(qt,n),h=r.ellipsoid;let u;u=0===T.len(c)?T.set(Xt,0,0,-6378137):ut(Xt,c),Zt.x=u[0],Zt.y=u[1];const f=r.project(Zt,Qt);Kt[0]=f.x/s,Kt[1]=f.y/s,Kt[2]=(u[2]+o)*i;const l=Gt(a,h,$t),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],f=t[10],l=e[0],d=e[1],m=e[2],p=e[3],y=e[4],b=e[5],g=e[6],T=e[7],w=e[8],_=r*l+o*d+h*m,O=s*l+a*d+u*m,A=i*l+c*d+f*m,I=r*p+o*y+h*b,x=s*p+a*y+u*b,S=i*p+c*y+f*b,M=r*g+o*T+h*w,N=s*g+a*T+u*w,E=i*g+c*T+f*w;return n[0]=_,n[1]=O,n[2]=A,n[3]=0,n[4]=I,n[5]=x,n[6]=S,n[7]=0,n[8]=M,n[9]=N,n[10]=E,n[11]=0,n[12]=t[12],n[13]=t[13],n[14]=t[14],n[15]=t[15],n}(g.invert(Wt,l),w.fromMat4(Yt,n),t);return zt(t,Kt,d),t}(f,o,f,a.getProjection(),a.getGLRes(),u,c),d=function(t,e){return T.set(t,e[12],e[13],e[14]),t}(Se,l);let m=this.t.options.offset;if(I(m)){m=m(this.t.Rt(n.id).center)}return i.set(xe,m[0],m[1],0),i.add(d,d,xe),zt(l,d,l),l}It(t,e,n){const s=this.t.H(e);if(!s.coordOffset)return null;const o=this.getMap(),a=o.getGLRes();_e.set(n[0],n[1]);const c=o.coordToPointAtRes(_e,a,Ae),h=s.coordOffset,u=_e.set(n[0]+h[0],n[1]+h[1]),f=o.coordToPointAtRes(u,a,Ie),l=f.x-c.x,d=f.y-c.y,m=this.Ut(),p=i.set(xe,l,d,(h[2]||0)*m);return r.fromTranslation(t,p)}Ut(){const t=this.getMap();let e;return e=t.altitudeToPoint?this.B:t.distanceToPointAtRes(100,100,t.getGLRes(),_e).y/100,e}createCMPTMesh(t,e,n,r){if(this.T[e]){const t=this.T[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.T[e]=i,r(null,{id:e,mesh:i}),i}Nt(t,e,n,r,s){const i=("phong"===(this.t.H(r).shader||"pbr")?this.J:this.tt).getGeometryDefines(e);s.asset&&"S3M"===s.asset.generator&&this.Lt(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.t.Bt&&(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),this.wt(i,t.compressed_int16_params);return A(i,t.compressDefines),i}wt(t,e){e&&(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))}Y(t){const e=this.t.getRenderer();e&&e.updateMaskDefines(t)}Lt(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)}Mt(t,e,n,r,s,i,o){let a=!1;r.asset&&"S3M"===r.asset.generator&&(a=!0,r.extensions=r.extensions||{});const c=r.url+"-"+e+"-"+n;if(this._[c])return this._[c].refCount++,this._[c];let h,u;const f=r.materials&&r.materials[t.material];if(r.extensions&&r.extensions.KHR_techniques_webgl&&f.extensions&&f.extensions.KHR_techniques_webgl){const e=this.Pt(t,r,i,a);h=e.material,u=e.geometry;this.t.H(s.V).fillEmptyDataInMissingAttribute&&(u.desc.fillEmptyDataInMissingAttribute=!0)}else{u=this.Dt(t,i,Ee);const e=this.t.H(s.V),n=e.ambientLight;let a=e.environmentExposure;const c=e.material,f=this.getMap().getLightManager(),l=f&&f.getAmbientLight();if(n&&(!l||l.color)&&void 0===a){const t=l&&l.color?l.color[0]:.2;a=n[0]/t}h=this.Ft(t.material,r,o,c||me,a||1)}h&&!h.isReady()?h.kt=s.id:h||(h=this.C);const l={refCount:1,geometry:u,material:h};return u.properties.url=c,this._[c]=l,l}Pt(t,e,n,r){const{geometry:s,material:i}=this.U.createMesh(t,e,n,r);return{geometry:s,material:i}}Dt(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=oe(this.o,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.Geometry(o,a,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":ie(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}
7
7
  /*!
8
- * @maptalks/gl v0.88.0
8
+ * @maptalks/gl v0.88.1
9
9
  * LICENSE : UNLICENSED
10
10
  * (c) 2016-2023 maptalks.com
11
- */(i,a)),c.generateBuffers(this.o,{excludeElementsInVAO:e}),c}Ct(t,e,n,s){const o=r.identity(t),a=this.getMap();_e.x=n[0],_e.y=n[1];const c=this._prjToPoint(_e),h=this.Ht(),u=1/(a.getGLZoom?a.getResolution(a.getGLZoom()):a.getGLRes());_e.x=e[0],_e.y=e[1];const f=this.Ut();let l=this.t.options.offset;I(l)&&(l=l(_e));const d=this.t.H(s).heightOffset||0;return i.set(Se,c.x+l[0],c.y+l[1],f*n[2]+f*d),r.translate(o,o,Se),i.set(h,u,u,f),r.scale(o,o,h),o}Ot(t,e){const n=r.identity(t),s=this.getMap(),o=this.Ht();_e.x=e[0],_e.y=e[1];const a=s.distanceToPointAtRes(100,100,s.getGLRes(),_e);let c;return c=s.altitudeToPoint?this.P:a.y/100,i.set(o,a.x/100*1.01,a.y/100*1.01,c),r.scale(n,n,o),n}R(){const t={x:0,y:0,width:()=>this.s?this.s.width:1,height:()=>this.s?this.s.height:1};this.ot=new n.MeshShader({vert:"attribute vec3 aPosition;\n\n\n\nuniform mat4 projViewModelMatrix;\n\n\n\nvoid main() {\n\n gl_Position = projViewModelMatrix * vec4(aPosition, 1.0);\n\n}\n\n",frag:"precision mediump float;\n\n\n\nuniform vec3 color;\n\n\n\nvoid main() {\n\n gl_FragColor = vec4(color, 1.0);\n\n}\n\n",uniforms:["color",{name:"projViewModelMatrix",type:"function",fn:(t,e)=>r.multiply([],e.projViewMatrix,e.modelMatrix)}],extraCommandProps:{viewport:t}});const e=[],s=[];this.nt=new n.MeshShader({vert:"const 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#include <draco_decode_vert>\n\nvoid main() {\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_POSITION\n\n vec3 localPos = decode_getPosition(POSITION);\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\n\n gl_Position = projViewModelMatrix * vec4(localPos, 1.0);\n\n gl_PointSize = pointSize;\n\n}\n\n",frag:"#define SHADER_NAME PNTS\n\nprecision mediump float;\n\n\n\nvarying vec4 vColor;\n\n\n\nvoid main() {\n\n gl_FragColor = vColor;\n\n}\n\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:(t,e)=>r.multiply(s,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,n)=>o.fromMat4(e,n.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 i=this.L();this.J=new n.PhongShader({extraCommandProps:i}),this.tt=new n.pbr.StandardShader({extraCommandProps:i});const a=this.t;he(a.getRenderer().canvas,this.o,a.getMap()),this.picking=new n.FBORayPicking(this.h,{vert:this.tt.vert,extraCommandProps:i,uniforms:this.tt.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap())}L(){return{viewport:{x:0,y:0,width:()=>this.s?this.s.width:1,height:()=>this.s?this.s.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}}}ct(t){return{projViewMatrix:this.getMap().projViewMatrix,color:t&&t.color||[0,1,0]}}et(t){const e=this.getMap(),n=e.getLightManager(),r=(n&&n.getDirectionalLight()||{}).direction||[1,1,-1],s=t&&t.pointOpacity||1;return{projViewMatrix:e.projViewMatrix,pointOpacity:s,lightDir:i.normalize(r,r)}}D(){const t=this.getMap(),e=this.t.getRenderer().canvas,{iblTexes:n,dfgLUT:r}=fe(e),s=le(t,n,r),i=this.t.getRenderer().getMaskUniforms();return A(s,{czm_lightDirectionEC:s.light0_viewDirection,lightSpecular:[1,1,1],viewMatrix:t.viewMatrix,projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,outSize:[e.width,e.height],polygonFill:[1,1,1,1],polygonOpacity:1}),A(s,i),s}Ft(t,e,r,s,i){const o=e.materials&&e.materials[t];if(!o||!o.baseColorTexture&&!o.pbrMetallicRoughness)return null;const c=A({},s);if(o.baseColorTexture){const t=e.textures[o.baseColorTexture.index];let n;t&&!t.image.color&&(n=this.Vt(t)),c.baseColorFactor=t&&t.image.color||o.baseColorFactor||[1,1,1,1],n&&(c.baseColorTexture=n)}else{if(o.normalTexture){const t=this.Vt(e.textures[o.normalTexture.index]),n=o.normalTexture.scale||1;c.normalTexture=t,c.normalMapFactor=n}if(o.occlusionTexture){const t=this.Vt(e.textures[o.occlusionTexture.index]),n=o.occlusionTexture.strength||1;c.occlusionTexture=t,c.occlusionFactor=n}if(o.emissiveTexture){const t=this.Vt(e.textures[o.emissiveTexture.index]);c.emissiveTexture=t}o.emissiveFactor&&(c.emissiveFactor=o.emissiveFactor);const t=o.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(c.baseColorFactor=t.baseColorFactor),t.baseColorTexture&&void 0!==t.baseColorTexture.index){const n=e.textures[t.baseColorTexture.index];n.image&&n.image.color?c.baseColorFactor=c.baseColorFactor?a.multiply(c.baseColorFactor,c.baseColorFactor,n.image.color):n.image.color:(c.baseColorTexture=this.Vt(n),c.baseColorTexture.getREGLTexture(this.o))}if(O(t.metallicFactor)||(c.metallicFactor=t.metallicFactor),O(t.roughnessFactor)||(c.roughnessFactor=t.roughnessFactor),o.metallicRoughnessTexture){const t=this.Vt(e.textures[o.metallicRoughnessTexture.index]);c.metallicRoughnessTexture=t}}}if(o.s3mMaterial)return new n.Material(c);if(c.environmentExposure=i,o.extensions&&o.extensions.KHR_materials_unlit)return c.environmentExposure=1,c.ambientColor=[1,1,1],c.light0_diffuse=[0,0,0,0],c.lightSpecular=[0,0,0],new n.PhongMaterial(c);c.alphaTest=.99;let h=new n.pbr.StandardMaterial(c);"phong"===r&&(h=n.PhongMaterial.convertFrom(h));const u=o.pbrMetallicRoughness,f=u&&u.baseColorTexture&&u.baseColorTexture.extensions;return f&&f.KHR_texture_transform&&(h.set("khr_offset",f.KHR_texture_transform.offset||[0,0]),h.set("khr_rotation",f.KHR_texture_transform.rotation||0),h.set("khr_scale",f.KHR_texture_transform.scale||[1,1])),h.once("complete",this.N),h}Vt(t){const e={type:t.type?re(t.type):"uint8",format:t.format?se(t.format):"rgba",flipY:!!t.flipY},r=t.image;r.array?e.data=r.array:r.mipmap&&(e.mipmap=r.mipmap),e.width=r.width,e.height=r.height;const s=t.sampler||t.texture&&t.texture.sampler;return s&&(s.magFilter&&(e.mag=te(s.magFilter)),s.minFilter&&(e.min=ee(s.minFilter)),s.wrapS&&(e.wrapS=ne(s.wrapS)),s.wrapT&&(e.wrapT=ne(s.wrapT))),new n.Texture2D(e,this.M)}v({target:t}){const e=t.kt,n=this.u[e];if(n.count--,!n.count){const t=n.meshes;this.m[e]=t,delete this.u[e];const r=t.vt;delete t.vt,r(null,{mesh:n.meshes,id:e})}}Ht(){return pe}lt(t){return this.t.lt(t)}yt(t,e){const n=this.getMap();return n.getGLZoom?n.distanceToPoint(t,e,n.getGLZoom()):n.distanceToPointAtRes(t,e,n.getGLRes())}_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(),Oe)}xt(t){return"Y"===t?ae:"X"===t?ce:ye}pick(t,e,n=3){const r=this.t;if(!r||!r.options.picking)return[];if(!this.pickingFBO||!this.picking)return[];const s=this.getMap(),i=this.D(),o=this.picking;o.render(this.O.getMeshes().filter(t=>!t.bloom),i,!0);let a={};o.getRenderedMeshes().length&&(a=o.pick(t,e,n,i,{viewMatrix:s.viewMatrix,projMatrix:s.projMatrix,returnPoint:r.options.pickingPoint}));const{meshId:c,pickingId:h,point:u,coordinate:f}=a,l=(0===c||c)&&o.getMeshAt(c);if(!l||!l.geometry)return[];const d=l.properties;u&&u.length&&(u[0]=Math.round(1e5*u[0])/1e5,u[1]=Math.round(1e5*u[1])/1e5,u[2]=Math.round(1e5*u[2])/1e5);const m={batchId:h};if(r.options.debug&&(m.debugInfo=d),d&&d.batchTable){const{batchTable:t,batchTableBin:e,count:n}=d,r=h;for(const s in t)void 0!==t[s].byteOffset?m[s]=St(t[s],e,n,r):m[s]=t[s][r]}return[{service:l.properties.serviceIndex,data:m,point:u,coordinate:f}]}F(t){let e=new Set;for(let n=0,r=t.length;n<r;n++){const r=t[n].data.node;this.k(r)&&e.add(r.$)}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.j=t;const e=this.t.getRenderer();this.q=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelAllHighlight(){this.j=null;const t=this.t.getRenderer();this.q=t.getFrameTimestamp(),t.setToRedraw(!0)}showOnly(t){this.X=t;const e=this.t.getRenderer();this.K=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelShowOnly(){this.X=null;const t=this.t.getRenderer();this.K=t.getFrameTimestamp(),t.setToRedraw(!0)}zt(){if(!this.B)return[];const t={},e=[];for(const n in this.B){const r=this.B[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())}}const Ce=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")},Re=Ce(),Ue=Re.gl_trans__coders=Re.gl_trans__coders||{};function Le(t,e){if(e)for(let n=0;n<e.length;n++){t[e[n].id||e[n].index]=e[n]}}Ue.inject=function(t){const e=t.toString(),n=e.indexOf("{")+1,r=e.substring(0,n),s=Re.gl_trans__coders=Re.gl_trans__coders||{};let i=`${r}\n const _____getGlobal = ${Ce.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},Ue.registerTranscoder=function(t,e){Ue[t]=e},Ue.getTranscoder=function(t){return Ue[t]};const Pe=[];class Be{constructor(t,e,n,r){this.Gt=t,this.V=e,this.jt=r,this.qt=n.version,t.indexOf("i3s:tileset:")<0?(this.qt<=1.6?this.Xt="root":this.Xt=0,n.version=this.qt):(this.Xt=t.substring("i3s:tileset:".length),this.qt>1.6&&(this.Xt=parseInt(this.Xt))),this.Gt=t,this.Kt=n}load(){const t=this.Kt,e=t.layerScene.baseUrl;if(this.qt<=1.6)return t[this.Xt]&&t[this.Xt].lodSelection?(this.$t=t[this.Xt],this.Wt()):new Promise(n=>{let r=e+"/nodes/"+this.Xt;t.layerScene.eslpk&&(r+="/3dNodeIndexDocument.json"),this.jt(this.V,r,()=>{this.$t=t[this.Xt],n(this.Wt())})});if(this.qt>=1.7){if(t[this.Xt])return this.$t=t[this.Xt],this.Wt();const n=Math.floor(this.Xt/t.nodesPerPage);return new Promise(r=>{let s=e+"/nodepages/"+n;t.layerScene.eslpk&&(s+=".json"),this.jt(this.V,s,()=>{this.$t=t[this.Xt],r(this.Wt())})})}return null}getTileset(){return this.Yt}getChildrenURL(){return this.Zt}Wt(){const t=this.Kt,e=t.layerScene.baseUrl,n=this.$t.children,r=[],s={};if(n)for(let i=0;i<n.length;i++)if(this.qt<=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.jt(this.V,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.jt(this.V,r,()=>{n()})}),r.push(s[a]))}return r.length?Promise.all(r).then(()=>this.Qt()):this.Qt()}Qt(){return Promise.resolve(this.Jt())}te(t){Le(this.Kt,t)}Jt(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.ee(this.$t,!0)}}ee(t){const e=this.qt,n=this.Kt,r=t,s=r.obb,i=r.mbs,o={};let a;if(i)a=De([],i[0],i[1],i[2]),o.sphere=[...a,i[3]];else if(s){a=De([],s.center[0],s.center[1],s.center[2]);const t=function(t,e,n){const r=w.fromQuat([],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]}(a,s.halfSize,s.quaternion),e=t[3]+t[6]+t[9],n=t[4]+t[7]+t[10],r=t[5]+t[8]+t[11];T.set(Pe,e,n,r);const i=T.len(Pe);o.sphere=[...a,i]}let c=1/0,h=0;if(r.mbs?h=r.mbs[3]:r.obb&&(h=Math.max(Math.max(r.obb.halfSize[0],r.obb.halfSize[1]),r.obb.halfSize[2])),void 0!==r.lodThreshold)if("maxScreenThresholdSQ"===n.lodSelectionMetricType){c=h/(Math.sqrt(r.lodThreshold)/(.25*Math.PI))}else console.error("Unsupported lodSelectionMetricType in Layer");else if(void 0!==r.lodSelection)for(let t=0;t<r.lodSelection.length;t++)"maxScreenThreshold"===r.lodSelection[t].metricType&&(c=h/r.lodSelection[t].maxError);(c===1/0||isNaN(c))&&(c=1e5);const u=16*c,f=g.identity([]),l=r.children;let d;if(l){d=[];const t=this.Kt;for(let n=0;n<l.length;n++){const r=e<=1.6?l[n].id:l[n];if(!t[r]){d=null;break}d.push(this.ee(t[r]))}}const m={refine:"REPLACE",boundingVolume:o,transform:f,geometricError:u};return e<=1.6?t.lodSelection?t.geometryData&&(m.content={uri:"i3s:mesh:"+(t.id||t.index)}):m.content={uri:"i3s:tileset:"+(t.id||t.index)}:l&&l.length&&!d?m.content={uri:"i3s:tileset:"+(t.id||t.index)}:r.mesh&&(m.content={uri:"i3s:mesh:"+(t.id||t.index)}),d&&d.length&&(m.children=d),m}getJSON(){return this.$t}}function De(t,e,n,r){return st(t,M(e),M(n),r)}const Fe=!!Ue.ktx2,ke=r.identity([]),He=(()=>{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 Ve(t){return t.indexOf("i3s:mesh")>=0}const ze="i3s:mesh:".length;function Ge(t,e,n,r,s){const i=e.layerScene.eslpk,o=function(t,e){const n=e.substring(ze);return t>=1.7?parseInt(n):n}(e.version,t),a=e[o],c=e.layerScene.baseUrl,h=[];let u=!1;const f=ke;let l,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{l=a.mesh.geometry,d=a.mesh.material;const t=e.layerScene.geometryDefinitions[l.definition],{geometryBuffers:o}=t;u=r&&2===o.length;const f=Ue.draco&&u?o[1]:o[0],m=Ue.draco&&u?1:0;let p=c+`/nodes/${l.resource}/geometries/`+m;i&&(p+=".bin");const y={geometry:{url:p,info:f}};if(s&&He&&u&&!Ue.draco)throw new Error("Must import @maptalks/transcoder.draco to load i3s draco compressed geometry");const b=e.layerScene.materialDefinitions,g=e.layerScene.textureSetDefinitions;let T,w=0;if(d&&(w=b[d.definition]),b){T=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=je(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 x(e[a])&&t(e[a],n,r,s,i,o)}(o,e,n,r,s,i),o}(w,g,c,d.resource,n,e.layerScene.eslpk)}else T={pbrMetallicRoughness:{metallicFactor:0}};y.material=T,h.push(y)}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:f}}function je(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&&Fe)return t[n]}return null}const qe=[];class Xe extends(h(t.renderer.CanvasRenderer)){constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new j(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.ne={},this.re=[],this.jt=this.se.bind(this)}getAnalysisMeshes(){if(!this.painter)return qe;const t=this.painter.getPaintedMeshes();if(!t)return qe;const e=[],{b3dmMeshes:n,pntsMeshes:r,i3dmMeshes:s}=t;return n.length&&F(e,n),r.length&&F(e,r),s.length&&F(e,s),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.re.length||super.needToRedraw())}getFrameTimestamp(){return this.ie}drawOnInteracting(t,e,n){this.draw(e,n)}draw(t,e){this.ie=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.oe(),this.ae();const{selectedTiles:o,leaves:a,requests:c}=this.ce(r,s);c.length&&this.loadTiles(c),this.he(o,a,e),this.ue(),c.length||this.completeRender()}ce(t,e){const n=this.layer.getRootTiles();let r=[];this.fe();let s=0;const i=this.le(),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.V];o[h.id]=1;let f=!1;const l=this.getCachedTile(h.id);if(this.de(h.id)?(s++,f=c=!0,this.tilesLoading[h.id].current=!0):l?(this.getTileOpacity(l)<1&&(f=c=!0),(!i.node.me||u.isS3M||!i.node.children||i.node.me<=500)&&(a=!0,i.selected=!0,i.data=l)):this.painter.has(h)||(f=c=!0,r.push(h)),!f)continue;if(this.pe(i))a=!0;else{this.ye(i).length&&(a=!0)}}let h=[],u={};if(a&&({selectedTiles:h,leaves:u}=this.be(t)),r.length>1&&(r.sort(Ke),i)){const t=i-s;r=t>0?r.slice(0,t):[]}return{loading:c,requests:r,selectedTiles:h,leaves:u}}be(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.ge===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.ge=s.length}for(let t=0;t<o.length;t++)s.push(o[t])}return{selectedTiles:e,leaves:n}}pe(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}ye(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const n=t.$+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.Te(s[i],t);n.selected=!0,n.data=this.tileCache.get(o),t.children.push(n),e.push(n)}else s[i].$<=n&&r.push(s[i])}}return e}he(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(B(e)){const n=D(e);return this.we(e,n,t),null}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const n=t.V,r=this._e[n];return new Be(e,n,r,this.jt).load().then(n=>{this.onTilesetLoad(n,t,e)})}t&&-1===e.indexOf("http://")&&-1===e.indexOf("https://")&&!Ve(e)&&(e=t.baseUrl+e);const n=this.layer.H(t.V);if(n.ajaxInMainThread){let r=n.urlParams;r&&(r=(e.indexOf("?")>0?"&":"?")+r);let s=y.getArrayBuffer(e+(r||""),n.fetchOptions);const i=s.xhr;s=s.then(n=>{delete this.ne[e],n?this.we(e,n.data,t):this.onTileError(null,t)}).catch(n=>{delete this.ne[e],this.onTileError(n,t)}),this.ne[e]=i}else this.we(e,null,t);return null}we(t,e,r){let s=this.Oe;s||(s=n.Util.getSupportedFormats(this.gl.gl||this.gl),this.Oe=s);const i=this.layer.H(r.V);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:t=this.layer.getTileUrl(t,r.baseUrl,i),arraybuffer:e,rootIdx:r.V,upAxis:r.St,transform:r.matrix,supportedFormats:s};if(Ve(t)){const e=this._e[r.V];if(o.i3sInfo=Ge(t,e,this.regl,this.layer.options.enableI3SCompressedGeometry,this.layer.options.forceI3SCompressedGeometry),!o.i3sInfo)return void this.onTileError({status:404},r)}o.service=A({},i),i.offset&&delete o.service.offset,this.workerConn.loadTile(this.layer.getId(),o,(e,n)=>{if(e)return void this.onTileError(e,r);const{magic:s}=n;"b3dm"===s||"pnts"===s||"i3dm"===s||"cmpt"===s?this.re.push({data:n,tile:r}):this.onTilesetLoad(n,r,t)})}ae(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let n=0;for(;this.re.length&&(n<e||!t.isInteracting());){const{data:t,tile:e}=this.re.shift(),{magic:r}=t;"b3dm"===r?this.painter.createB3DMMesh(t,e.id,e,(n,{mesh:r})=>{this.Ae(t,e,n,r)}):"pnts"===r?this.painter.createPntsMesh(t,e.id,e,(n,{mesh:r})=>{this.Ae(t,e,n,r)}):"i3dm"===r?this.painter.createI3DMMesh(t,e.id,e,(n,{mesh:r})=>{this.Ae(t,e,n,r)}):"cmpt"===r&&this.painter.createCMPTMesh(t,e.id,e,(n,{mesh:r})=>{this.Ae(t,e,n,r)}),n++}}Ae(t,e,n,r){if(n)this.onTileError(n,e);else{const n=this.Ie(r);e.memorySize=n,this.onTileLoad(t,e)}}Ie(t){let e=0;if(Array.isArray(t))for(let n=0;n<t.length;n++)t[n]&&(e+=this.Ie(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.xe(e),this.setToRedraw(),this.layer.fire("tileload",{node:e}))}onTilesetLoad(t,e,n){this.layer&&(this.layer.Pt=t.extensions&&t.extensions["s3m:VertexCompressionType"],t.capabilities||t.layers&&t.layers[0]&&t.layers[0].capabilities?this.Se(t,e,n):(delete this.tilesLoading[e.id],this.layer.onTilesetLoad(t,e,n)))}onTileError(t,e){if(!this.layer)return;const n=e.content.url;console.warn("failed to load 3d tile: "+n),console.warn(t),delete this.tilesLoading[e.id],this.Me(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}Me(e,n){const r={loadTime:t.Util.now(),current:!0,error:n,node:e};this.tileCache.add(e.id,r)}xe(e){const n={loadTime:t.Util.now(),current:!0,node:e};this.tileCache.add(e.id,n)}abortTileLoading(t){if(!t||!this.workerConn)return;const e=t.node.content.url;if(this.layer.H(t.node.V).ajaxInMainThread){const t=this.ne[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.ne[e]}fe(){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},n=this.canvas.gl&&this.canvas.gl.wrap;n?(this.gl=this.canvas.gl.wrap(),this.regl=this.canvas.gl.regl):(this.glOptions=e,this.gl=this.Ne(this.canvas,e)),this.regl=this.regl||u({gl:this.gl,attributes:e,extensions:["OES_element_index_uint"],optionalExtensions:t.options.optionalExtensions||[]}),n&&(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 ve(this.regl,t),this.layer.Ee()}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new V("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let n=this.layer.options||{};n=A({},n),delete n.offset,n.projection=t.getSpatialReference().getProjection().code;const r=this.layer.getId();e.addLayer(r,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.ue(!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}ue(t){this.ve||(this.ve=Date.now());const e=Date.now();if(t||!(e-this.ve<this.layer.options.retireInterval)){this.ve=e;for(const e in this.tilesLoading){const n=this.tilesLoading[e];!t&&n.current||this.abortTileLoading(n)}}}le(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}Ne(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}de(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 It(t,e,0,n)}oe(){if(!this.Ce)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const n=[];for(const r in this.Ce){const s=this.Ce[r];if("pending"===s.status)continue;s.status="pending";const i=s.rootIdx;if(n.push(y.getJSON(r).then(t=>{delete this.Ce[r];const e=this._e[i];if(e){t.nodes?Le(e,t.nodes):(e[t.id]=t,Le(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)}se(t,e,n){this.Ce||(this.Ce={}),this.Ce[e]=this.Ce[e]||[],this.Ce[e].rootIdx=t,this.Ce[e].push(n),this.setToRedraw()}Se(t,e,n){this._e||(this._e=[]);const r=e.V;this._e[r]||(this._e[r]={});const s=this._e[r],i=this.layer.H(r);t.layers&&(t=t.layers[0],"/"!==n[n.length-1]&&(n+="/"),n+="layers/0"),s.version=+(i.i3sVersion||t.store.version),function(t,e,n,r,s,i){if(!s.layerScene){s.layerScene=t,s.nodesPerPage=t.nodePages&&t.nodePages.nodesPerPage||64,s.lodSelectionMetricType=t.nodePages&&t.nodePages.lodSelectionMetricType;let e=r;s.layerScene.eslpk=e.indexOf("3dSceneLayer.json")>=0;if(e.endsWith(".json")){const t=r.lastIndexOf("/");e=t<0?"./":r.substring(0,t)}s.layerScene.baseUrl=function(t){return t.split("?")[0]}(e)}return new Be(r,e,s,i).load()}(t,r,0,n,s,this.jt).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.j||(this.j=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const n=t[e].service||0;let r=this.j[n];r||(r=this.j[n]=new Map),r.set(t[e].id,t[e])}else{const e=t.service||0;let n=this.j[e];n||(n=this.j[e]=new Map),n.set(t.id,t)}this.painter.highlight(this.j)}cancelHighlight(t,e){if(!this.j)return;const n=this.j[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.j[t]=null),this.painter.highlight(this.j)}}cancelAllHighlight(){delete this.j,this.painter.cancelAllHighlight()}showOnly(t){if(this.X||(this.X=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const n=t[e].service||0;let r=this.X[n];r||(r=this.X[n]=new Map),r.set(t[e].id,t[e])}else{const e=t.service||0;let n=this.X[e];n||(n=this.X[e]=new Map),n.set(t.id,t)}this.painter.showOnly(this.X)}cancelShowOnly(){delete this.X,this.painter.cancelShowOnly()}zt(){return this.painter?this.painter.zt():[]}}function Ke(t,e){return t.st-e.st}function $e(t,e,n){return t[0]=e[n],t[1]=e[n+3],t[2]=e[n+6],t}function We(t,e,n){return Math.sqrt(function(t,e,n){const r=T.subtract(Ye,n,t),s=$e(Ze,e,0),i=$e(Qe,e,1),o=$e(Je,e,2),a=T.len(s),c=T.len(i),h=T.len(o);T.normalize(s,s),T.normalize(i,i),T.normalize(o,o);const u=tn;u[0]=T.dot(r,s),u[1]=T.dot(r,i),u[2]=T.dot(r,o);let f,l=0;u[0]<-a?(f=u[0]+a,l+=f*f):u[0]>a&&(f=u[0]-a,l+=f*f);u[1]<-c?(f=u[1]+c,l+=f*f):u[1]>c&&(f=u[1]-c,l+=f*f);u[2]<-h?(f=u[2]+h,l+=f*f):u[2]>h&&(f=u[2]-h,l+=f*f);return l}(t,e,n))}const Ye=[],Ze=[],Qe=[],Je=[],tn=[];const en=2*Math.PI;class nn{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+=en,n<0&&(n+=en)),(n>s||gt(n,s,1e-14))&&(n<i||gt(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 rn=[0,0,1];function sn(t,e){return st(e,t[0],t[1],t[2])}class on{constructor(t,e){this.normal=i.copy([],t),this.distance=e}static fromPointNormal(t,e,n){const r=-i.dot(e,t);return i.copy(n.normal,e),n.distance=r,n}}const an=[],cn=[],hn=[],un=[],fn=[],ln=[],dn=[],mn=[],pn=[],yn=[],bn=new on([1,0,0],0),gn=[];class Tn{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new nn(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){let n=0;if(!nn.contains(this.rectangle,e)){const e=this.southwestCornerCartesian,r=this.northeastCornerCartesian,s=this.westNormal,o=this.southNormal,a=this.eastNormal,c=this.northNormal,h=i.subtract(gn,t,e),u=i.dot(h,s),f=i.dot(h,o),l=i.subtract(gn,t,r),d=i.dot(l,a),m=i.dot(l,c);u>0?n+=u*u:d>0&&(n+=d*d),f>0?n+=f*f:m>0&&(n+=m*m)}const r=e[2],s=this.minimumHeight,o=this.maximumHeight;if(r>o){const t=r-o;n+=t*t}else if(r<s){const t=s-r;n+=t*t}return Math.sqrt(n)}computeBox(t){const e=this;sn(nn.southwest(t,cn),e.southwestCornerCartesian),sn(nn.northeast(t,cn),e.northeastCornerCartesian),an[0]=t.west,an[1]=.5*(t.south+t.north),an[2]=0;const n=sn(an,hn),r=i.cross(fn,n,rn);i.normalize(e.westNormal,r),an[0]=t.east;const s=sn(an,mn),o=i.cross(fn,rn,s);i.normalize(e.eastNormal,o);const a=i.subtract(fn,n,s),c=i.normalize(un,a),h=t.south;let u;if(h>0){an[0]=.5*(t.west+t.east),an[1]=h;const n=sn(an,pn);i.copy(yn,c);const r=on.fromPointNormal(e.southwestCornerCartesian,e.westNormal,bn);wn(pn,yn,r,e.southwestCornerCartesian),u=pt(n,ln)}else u=yt(nn.southeast(t,cn),ln);const f=i.cross(dn,u,a);i.normalize(e.southNormal,f);const l=t.north;let d;if(l<0){an[0]=.5*(t.west+t.east),an[1]=l;const n=sn(an,pn);i.scale(yn,c,-1);const r=on.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,bn);wn(pn,yn,r,e.northeastCornerCartesian),d=pt(n,ln)}else d=yt(nn.northwest(t,cn),ln);const m=i.cross(dn,a,d);i.normalize(e.northNormal,m)}}function wn(t,e,n,r){const s=t,o=e,a=n.normal,c=i.dot(a,o);if(Math.abs(c)<1e-15)return;const h=(-n.distance-i.dot(a,s))/c;return h<0?void 0:(r=i.scale(r,o,h),i.add(r,s,r))}const _n=new t.Extent(0,0,0,0),On=new t.Extent(0,0,0,0),An=[],In=[],xn=[],Sn=[],Mn=new t.Point(0,0),Nn=[],En=new t.Coordinate(0,0),vn=r.identity([]),Cn=[0,0];class Rn extends(f(t.Layer)){constructor(t,e){super(t,e),this.Re(),this.ne={},this.Ue=[]}Re(){const t=this.options.services.map(t=>t.url);this.Le=this.Le||{},this.Pe=this.Pe||[];for(let e=0;e<t.length;e++){const n=t[e];let r=this.Le[n];void 0===r&&(r=this.Le[n]=this.Pe.length),this.Pe[r]=Pn(n,r,this.options.services[e])}this.fire("rootready",{roots:this.Pe.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.Re();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]&&A(n[t],e),!O(e.visible)){const r=n[t].url,s=this.Le[r];this.Pe&&this.Pe[s]&&(this.Pe[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.Le[n];this.Pe[r]&&(this.Pe[r]=null),delete this.Le[n],e.splice(t,1)}const n=this.getRenderer();return n&&n.setToRedraw(),this}getTileUrl(t,e,n){if(n.subdomains){const e=n.subdomains.length;if(e){const r=[...t].reduce((t,e)=>t+e.charCodeAt()-96,0)%e;return t.replace("%7Bs%7D",n.subdomains[r])}}return t}getExtent(e){if(!e&&0!==e){const e=new t.Extent;for(let t=0;t<this.Pe.length;t++)if(this.Pe[t].boundingVolume){const n=this.boundingVolumeToExtent(this.Pe[t]);e._combine(n)}return e}return this.Pe[e]&&this.Pe[e].boundingVolume?this.boundingVolumeToExtent(this.Pe[e]):null}boundingVolumeToExtent(e){const n=e.boundingVolume.Be?vn:e.matrix,r=this.getMap();if(e.boundingVolume.region){const n=e.boundingVolume.region;return new t.Extent(N(n[0]),N(n[1]),N(n[2]),N(n[3]))}if(e.boundingVolume.sphere){const s=e.boundingVolume.sphere,o=ut([],i.transformMat4([],s,n)),a=s[3],c=r.locate(o,-a,a),h=r.locate(o,a,-a);return new t.Extent(c,h)}if(e.boundingVolume.box){const s=e.boundingVolume.box,a=i.transformMat4([],s,n),c=new t.Coordinate(ut([],a)),h=s.slice(3);o.multiply(h,o.fromMat4([],e.matrix),h);const u=i.length(h.slice(0,3)),f=i.length(h.slice(3,6)),l=i.length(h.slice(6,9)),d=Math.max(u,f,l),m=r.locate(c,-d,d),p=r.locate(c,d,-d);return new t.Extent(m,p)}return null}getRootTiles(){return this.Pe}getTiles(){const t=this.getRenderer();if(!t.ready)return this.De(),{tiles:Sn};const e=this.getMap(),n=e.cameraPosition;let r,s;if(e.getGLZoom)s=e.pointToDistance(n[2],0,e.getGLZoom()),En.set(n[0],n[1]),r=e.pointToCoord(En,e.getGLZoom());else{const t=e.getGLRes();s=e.pointAtResToDistance(n[2],0,t),En.set(n[0],n[1]),r=e.pointAtResToCoord(En,t)}this.Fe=this.Fe||[],i.set(this.Fe,M(r.x),M(r.y),s),this.ke=st(this.ke||[],this.Fe[0],this.Fe[1],this.Fe[2]),this.He=2*Math.tan(.5*M(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const h=[];for(let e=0;e<this.Pe.length;e++){const n=this.Pe[e];if(!n||!n.visible)continue;let r=1/0;const s=[n],i=this.Ve(e);for(;s.length>0;){const e=s.pop();for(e.id||this.ze(e);c.level>=e.$;)c=c.parent;const n=this.Ge(e,i,o);if(n<1){let t=c;for(;t&&!t.content;)t=t.parent;0===n&&t&&t.content&&this.je(h,t);if(!1===this.options.services[e.V].alwaysShow)continue;if(!(0===n&&e.$<=r))continue;e.content&&(r=e.$)}e.st<1/0&&this.qe(e);const a=this.Te(e,c);c.children.push(a);const u=e.children,f=u&&u.length,l=a.content;if(!f&&l&&this.je(h,a),f){l&&"add"===e.refine&&this.je(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].St=e.St,u[i].baseUrl=e.baseUrl;const t=u[i].content&&(u[i].content.url||u[i].content.uri);t&&(B(t)||t.indexOf("i3s:")>=0?u[i].baseUrl=e.baseUrl:-1===t.indexOf("http://")&&-1===t.indexOf("https://")?u[i].content.url=e.baseUrl+t:u[i].baseUrl=t.substring(0,t.lastIndexOf("/")+1))}s.push(u[i])}!r&&l&&this.je(h,a)}}}return{root:a,tiles:h}}je(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 Un(n,e);if(n.box)return 0===Ln(n,e)}return!1}(this.Fe,this.ke,n)||t.push(e)}Te(t,e){return{id:t.id,node:t,children:[],level:t.$,parent:e,content:t.content&&t.content.url}}ze(e){e.id=t.Util.GUID(),e.matrix=e.transform||r.identity([]),e.Xe=this.Ke(e),e.parent&&(function(t){return t.content&&t.content.uri&&t.content.uri.indexOf("i3s:")>=0}(e)||(e.matrix=r.multiply(e.matrix,e.parent.matrix,e.matrix)),e.V=e.parent.V,void 0===e.$&&(e.$=e.parent.$+1),e.maxExtent=e.parent.maxExtent),e.refine=e.refine&&e.refine.toLowerCase()||"replace",e.content&&!e.content.url&&e.content.uri&&(e.content.url=e.content.uri)}H(t){return this.Pe[t].service}$e(t){const e=t.boundingVolume;if(!e||e.Be&&!this.We(t))return;const n=this.H(t.V),s=n.heightOffset||0,o=this.options.offset,a=I(o)||o[0]||o[1],c=n.coordOffset||Cn;if(!Array.isArray(c))throw new Error("service.coordOffset must be an array");if(!e.Be&&(!t.boundingVolume||!s&&r.exactEquals(t.matrix,vn)&&!a&&c===Cn))return;const{region:h,box:u,sphere:f}=e;if(e.coordOffset=[c[0],c[1]],e.heightOffset=s,h){e.originalVolume||(e.originalVolume=h.slice(0));const t=e.originalVolume,n=this.Ye([N(t[0]),N(t[1])]);h[0]=M(n.x+c[0]),h[1]=M(n.y+c[1]);const r=this.Ye([N(t[2]),N(t[3])]);h[2]=M(r.x+c[0]),h[3]=M(r.y+c[1]),h[4]=t[4]+s+(c[2]||0),h[5]=t[5]+s+(c[2]||0)}else if(u||f){e.originalVolume||(e.originalVolume=(u||f).slice(0));const n=u||f,r=e.originalVolume,o=i.transformMat4(An,r,t.matrix),a=ut(In,o),h=this.Ye([a[0]+c[0],a[1]+c[1]]);a[0]=h.x,a[1]=h.y,a[2]+=s+(c[2]||0),st(n,M(a[0]),M(a[1]),a[2])}e.Be=!0}We(t){const e=t.boundingVolume,n=this.H(t.V),r=n.heightOffset||0,s=n.coordOffset||Cn;return e.coordOffset[0]!==s[0]||e.coordOffset[1]!==s[1]||e.heightOffset!==r}Ke(t){return void 0===t.geometricError||!t.boundingVolume}qe(t){let e=t.parent;for(;e&&e.Xe&&!(e.st<=t.st);)e.st=t.st,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,n){if(!t)return void console.warn("invalid tileset at : "+n);const s=this.H(e.V),i=(t.asset&&t.asset.gltfUpAxis||e&&e.St||s.upAxis||"Y").toUpperCase();t.root.baseUrl=n.substring(0,n.lastIndexOf("/")+1);const o=n.indexOf("realspace/")>-1;0===e.$&&(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.St=i,e){const n=e.V,s=this.Pe[n];c&&!s.isS3M&&(s.isS3M=c);const i=e.boundingVolume;A(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=r.multiply([],e.parent.matrix,o)):e.matrix=o),e.Ze=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.Xe=this.Ke(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||B(h)||-1!==h.indexOf("http://")||-1!==h.indexOf("https://")||(e.content.url=e.baseUrl+h)}this.De(),this.fire("loadtileset",{tileset:t,index:e&&e.V,url:n})}Ge(t,e,n){if(t.st=1/0,0===t.$||t.Xe)return 1;if(this.$e(t),!this.Qe(t,e,n))return-1;if(0===t.geometricError)return 1;let r=this.H(t.V).maximumScreenSpaceError;null==r&&(r=16);let s=this.Je(t);return 0===s&&t.parent&&(s=.5*(t.parent.me||0)),s>=r?1:0}lt(e,n){n||(n=new t.Point(0,0));const r=this.getMap();return r.getGLZoom?r.coordToPoint(e,r.getGLZoom(),n):r.coordToPointAtRes(e,r.getGLRes(),n)}Qe(e,n,s){const a=e.id;let c=this.Ue[a];const{boundingVolume:h}=e,u=h.sphere;let f=h.region;const p=h.box;if(!c){let n,s,l;if(p&&(f=function(t,e){for(let e=0;e<9;e++)t[e+3]!==1/0&&t[e+3]!==-1/0||(t[e+3]=6378137*Math.sign(t[e+3])*3),qn[e]=t[e+3];const n=qn;r.exactEquals(e,vn)||o.multiply(n,o.fromMat4(Nn,e),n);const s=i.copy(Bn,t),a=i.set(Dn,n[0],n[1],n[2]),c=i.set(Fn,n[3],n[4],n[5]),h=i.set(kn,n[6],n[7],n[8]);Hn[0]=Hn[0]||[];const u=i.copy(Hn[0],s);i.sub(u,u,a),i.sub(u,u,c),i.sub(u,u,h),Hn[1]=Hn[1]||[];const f=i.copy(Hn[1],s);i.sub(f,f,a),i.sub(f,f,c),i.add(f,f,h),Hn[2]=Hn[2]||[];const l=i.copy(Hn[2],s);i.sub(l,l,a),i.add(l,l,c),i.sub(l,l,h),Hn[3]=Hn[3]||[];const d=i.copy(Hn[3],s);i.sub(d,d,a),i.add(d,d,c),i.add(d,d,h),Hn[4]=Hn[4]||[];const m=i.copy(Hn[4],s);i.add(m,m,a),i.sub(m,m,c),i.sub(m,m,h),Hn[5]=Hn[5]||[];const p=i.copy(Hn[5],s);i.add(p,p,a),i.sub(p,p,c),i.add(p,p,h),Hn[6]=Hn[6]||[];const y=i.copy(Hn[6],s);i.add(y,y,a),i.add(y,y,c),i.sub(y,y,h),Hn[7]=Hn[7]||[];const b=i.copy(Hn[7],s);i.add(b,b,a),i.add(b,b,c),i.add(b,b,h);for(let t=0;t<Hn.length;t++)Vn[t]=Vn[t]||[],ut(Vn[t],Hn[t]),zn[t]=Vn[t][0],Gn[t]=Vn[t][1],jn[t]=Vn[t][2];return[M(Math.min(...zn)),M(Math.min(...Gn)),M(Math.max(...zn)),M(Math.max(...Gn)),Math.min(...jn),Math.max(...jn)]}(p,e.matrix),h.region=f),f){n=_n.set(N(f[0]),N(f[1]),N(f[2]),N(f[3]));const t=n.getCenter(),e=this.tn(t);n=n.convertTo(t=>this.lt(t,Mn),On),l=f[4],s=f[5],c=this.Ue[a]=[[n.xmin,n.ymin,l*e[2]],[n.xmax,n.ymax,s*e[2]]],c.center=t}else if(u){const e=ut(An,u),n=new t.Coordinate(e),r=this.lt(n,Mn).toArray(),s=this.tn(n);r.push(e[2]*s[2]),c=this.Ue[a]=[r,u[3]*s[2]],c.center=n}}if(n){if(f)_n.xmin=c[0][0],_n.ymin=c[0][1],_n.xmax=c[1][0],_n.ymax=c[1][1];else if(u){const t=c[2];_n.xmin=c[0][0]-t,_n.ymin=c[0][1]-t,_n.xmax=c[0][0]+t,_n.ymax=c[0][1]+t}else if(p){const t=c[1],e=c[2];_n.xmin=c[0][0]-t,_n.ymin=c[0][1]-e,_n.xmax=c[0][0]+t,_n.ymax=c[0][1]+e}if(!n.intersects(_n))return!1}return f?l(s,c):u?d(s,c):!!p&&m(s,c)}tn(t){const e=this.getMap(),n=e.distanceToPointAtRes(100,100,e.getGLRes(),t);let r;return r=e.altitudeToPoint?e.altitudeToPoint(100,e.getGLRes())/100:n.y/100,i.set(xn,n.x/100*1.01,n.y/100*1.01,r),xn}Ye(e){Array.isArray(e)&&(e=new t.Coordinate(e));let n=this.options.offset;if(I(n)&&(n=n(Array.isArray(e)?new t.Coordinate(e):e)),n[0]||n[1]){const t=this.getMap(),r=t.getGLRes(),s=t.coordToPointAtRes(e,r);return s._add(n),t.pointAtResToCoord(s,r)}return e}Ve(e){const n=this.H(e).maxExtent;if(!n)return null;const r=this.Pe[e];return r.maxExtent||(r.maxExtent=new t.Extent(n).convertTo(t=>this.lt(t))),r.maxExtent}Je(t){const e=this.He,n=t.geometricError;if(0===n)return t.me=0,0;const r=this.getMap();let s;t.boundingVolume.region?s=function(t,e,n){t.en||(t.en=new Tn(t.boundingVolume.region));return t.en.distanceToCamera(e,n)}(t,this.ke,this.Fe):t.boundingVolume.sphere?s=Un(t.boundingVolume,this.ke):t.boundingVolume.box&&(s=Ln(t.boundingVolume,this.ke));const i=Math.max(Math.abs(s),1e-7),o=n*r.height/(i*e);return t.st=s,t.me=o,o}De(){const t=this.getRenderer();t&&t.setToRedraw()}Rt(t){return this.Ue[t]}identify(e,n={}){const r=this.getMap(),s=this.getRenderer();if(!r||!s)return[];const i=r.coordToContainerPoint(new t.Coordinate(e));return this.identifyAtPoint(i,n)}identifyAtPoint(t,e={}){const n=[];if(!e.excludeMasks){const r=this.identifyMask(t,e);r&&r.length&&F(n,r)}const r=this.getMap(),s=this.getRenderer();if(!r||!s)return[];const i=r.getDevicePixelRatio();return F(n,s.pick(t.x*i,t.y*i,e)),n}getCurrentBatchIDs(){const t=this.getMap(),e=this.getRenderer();return t&&e?e.zt():[]}highlight(t){const e=this.getRenderer();return e?(e.highlight(t),this):(this.j||(this.j=[]),this.j.push(t),this)}Ee(){if(this.j){for(let t=0;t<this.j.length;t++)this.highlight(this.j[t]);delete this.j}}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.X||(this.X=[]),this.X.push(t),this)}nn(){if(this.X){for(let t=0;t<this.X.length;t++)this.showOnly(this.X[t]);delete this.X}}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}}function Un(t,e){const n=t.sphere,r=i.dist(n,e),s=t.sphere[3];return r<s?0:r-s}function Ln(t,e){const n=t.box;return We(i.set(An,n[0],n[1],n[2]),o.set(Nn,n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10],n[11]),e)}function Pn(t,e,n){t=E(t);return{service:n,visible:O(n.visible)?1:n.visible,baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:r.identity([]),V:e,$:0}}Rn.mergeOptions({"maxGPUMemory":512,"retireInterval":2e3,"loadingLimitOnInteracting":5,"loadingLimit":0,"renderer":"gl","forceRenderOnZooming":!0,"forceRenderOnRotating":!0,"forceRenderOnMoving":!0,"debug":!1,"debugOutline":[0,1,0],"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]}),Rn.registerRenderer("gl",Xe),Rn.registerJSONType("Geo3DTilesLayer");const Bn=[],Dn=[],Fn=[],kn=[],Hn=[],Vn=[],zn=[],Gn=[],jn=[],qn=[];let Xn=null;function Kn(){return Xn||(Xn={"image/crn":Ue.crn&&Ue.crn(),"image/ktx2":Ue.ktx2&&Ue.ktx2(),"image/cttf":Ue.ktx2&&Ue.ktx2(),"draco":Ue.draco&&Ue.draco()}),Xn}class $n{constructor(t,e,n){this.rn=t,this.sn=e||p,this.Oe=n,this.in=Kn()}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.an(t,e,n,r,s)):y.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.an(t,s,n,r)})}an(t,e,n,r,s){const i=s&&s.maxTextureSize,o=this.cn(e,n,r,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.sn(a,o.glb,{transferable:!0,requestImage:this.rn,decoders:this.in,supportedFormats:this.Oe,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}})}cn(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),f=28+e;h>=570425344?(f-=8,o=a,h=c,u=0,a=0,c=0):u>=570425344&&(f-=4,o=h,h=a,u=c,a=0,c=0);const l=[t];let d,m,p;if(a>0?(d=_t(t,f,a),f+=a,o=d.BATCH_LENGTH):d={"BATCH_LENGTH":o},c>0&&(f+=c),h>0&&(m=Ot(t,f,h),f+=h,u>0)){const e=At(0,f,u);p=t.slice(e.offset,e.offset+e.byteLength),f+=u,l.push(p)}const y=d.BATCH_LENGTH,b={};if(d&&d.BATCH_ID){b.BATCH_ID=xt(d.BATCH_ID,t,(void 0).offset,y);const e=b.BATCH_ID.array&&b.BATCH_ID.array.buffer;e&&l.indexOf(e)<0&&l.push(e)}return{count:o,transferables:l,featureTable:d,batchTable:m,batchTableBin:p,b3dm:b,glb:{buffer:t,byteOffset:f,byteLength:s.byteLength+s.byteOffset-f}}}hn(){return null}}class Wn{constructor(t,e,n,r){this.rn=t,this.sn=e||p,this.Oe=n,this.in=Kn(),this.un=r}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.an(t,e,n,r,s)):y.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.an(t,s,n,r)})}an(t,e,n,r,s){return this.ln(t,e,n,r,s).then(({gltf:s,transferables:i})=>{const o=this.dn(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})})}ln(t,e,n,r,s){const i=s&&s.maxTextureSize,o={transferable:!0,requestImage:this.rn,decoders:this.in,supportedFormats:this.Oe,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=R(new Uint8Array(e,c+n,a.byteLength-c));-1==r.indexOf("://")&&(r=t.substring(0,t.lastIndexOf("/"))+"/"+r);return r.indexOf(".glb")>0?y.getArrayBuffer(r,{}).then(t=>this.mn(r,{buffer:t.data,byteOffset:0},o)):y.getJSON(r,{}).then(t=>this.mn(r,t,o))}{const r={buffer:e,byteOffset:c+n,byteLength:a.byteLength-c};return this.mn(t,r,o)}}mn(t,e,n){const r=t.substring(0,t.lastIndexOf("/")),s=new this.sn(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}})}dn(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}=Ut(s,32+e,o),f={},l=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;f.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(f.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,n=a.QUANTIZED_VOLUME_SCALE,{byteOffset:r}=a.POSITION_QUANTIZED;f.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:l,componentType:5126,array:this.pn(new Uint16Array(t,r+c.offset,3*l),e,n)},o.push(f.POSITION.array.buffer)}if(a.BATCH_ID){f.BATCH_ID=xt(a.BATCH_ID,t,c.offset,l);const e=f.BATCH_ID.array&&f.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;f.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(f.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,f.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(f.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;f.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:this.yn(new Uint16Array(t,e+c.offset,2*l))},o.push(f.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,f.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:this.yn(new Uint16Array(t,e+c.offset,2*l))},o.push(f.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;f.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,l).slice()},o.push(f.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;f.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(f.SCALE_NON_UNIFORM.array.buffer)}return{count:l,batchTable:h,batchTableBin:u,featureTable:a,i3dm:f,transferables:o}}yn(t){const e=t.length/2,n=new Float32Array(3*e),r=[];for(let s=0;s<e;s++)Yn(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}pn(t,e,n){return Rt(new Float32Array(t.length),t,e,n)}hn(){return null}}function Yn(t,e,n,r){if(t[0]=Zn(e,r),t[1]=Zn(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]))*Qn(e),t[1]=(1-Math.abs(e))*Qn(t[1])}return T.normalize(t,t)}function Zn(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 Qn(t){return t<0?-1:1}class Jn{constructor(){}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.an(t,e,n,r)):y.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.an(t,s,n,r)})}an(t,e,n,r){return this.bn(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})}bn(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}=Ut(s,e+28,o),f=a.QUANTIZED_VOLUME_OFFSET,l=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.gn||(this.gn=Kn().draco),this.gn(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.Tn(t,e.attributes,c.offset,d,o,f,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:Ct(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?r.BATCH_ID=xt(a.BATCH_ID,t,c.offset,d):r.BATCH_ID=tr(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 y=this.Tn(t,a,c.offset,d,o,f,l);if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?y.BATCH_ID=xt(a.BATCH_ID,t,c.offset,d):y.BATCH_ID=tr(d);const e=y.BATCH_ID.array&&y.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:d,batchTable:h,batchTableBin:u,featureTable:a,pnts:y,transferables:o})}Tn(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.pn(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}pn(t,e,n){return Rt(new Float32Array(t.length),t,e,n)}hn(){return null}}function tr(t){const e=P(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:Ct(e),array:n}}class er{constructor(t,e,n,r){this.Oe=n,this.rn=t,this.sn=e||p,this.un=r}load(t,e,n=0,r=0,s){return e?this.an(t,e,n,r,s):y.getArrayBuffer(t,{}).then(e=>{const s=e.data;return this.an(t,s,n,r)})}an(t,e,n,r,s){r||(r=e.byteLength);const i=this.wn(e,t,n,r),o=[];for(let n=0;n<i.length;n++){let r;if("b3dm"===i[n].magic)r=new $n(this.rn,this.sn,this.Oe);else if("i3dm"===i[n].magic)r=new Wn(this.rn,this.sn,this.Oe,this.un);else if("pnts"===i[n].magic)r=new Jn;else{if("cmpt"!==i[n].magic){console.warn("Unsupported magic in CMPT tile:",i[n].magic);continue}r=new er(this.rn,this.sn,this.Oe,this.un)}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}))}wn(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=Tt(s,c),r=s.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+n,byteLength:r}),c+=r}return o}}if(e.transcoders){const n=t.Map.VERSION;if(n.indexOf("1.0.0-beta")>=0||n.indexOf("1.0.0-alpha")>=0){const n=e.transcoders.inject(_);t.registerWorkerAdapter("@maptalks/3dtiles",n)}else t.registerWorkerAdapter("@maptalks/3dtiles",(function(){return e.transcoders.inject(_)}))}else t.registerWorkerAdapter("@maptalks/3dtiles",_);export{$n as B3DMLoader,er as CMPTLoader,Rn as Geo3DTilesLayer,k as Geo3DTilesUtil,bt as Geo3DTransform};"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.88.0");
11
+ */(i,a)),c.generateBuffers(this.o,{excludeElementsInVAO:e}),c}Ct(t,e,n,s){const o=r.identity(t),a=this.getMap();_e.x=n[0],_e.y=n[1];const c=this._prjToPoint(_e),h=this.Ht(),u=1/(a.getGLZoom?a.getResolution(a.getGLZoom()):a.getGLRes());_e.x=e[0],_e.y=e[1];const f=this.Ut();let l=this.t.options.offset;I(l)&&(l=l(_e));const d=this.t.H(s).heightOffset||0;return i.set(Se,c.x+l[0],c.y+l[1],f*n[2]+f*d),r.translate(o,o,Se),i.set(h,u,u,f),r.scale(o,o,h),o}Ot(t,e){const n=r.identity(t),s=this.getMap(),o=this.Ht();_e.x=e[0],_e.y=e[1];const a=s.distanceToPointAtRes(100,100,s.getGLRes(),_e);let c;return c=s.altitudeToPoint?this.B:a.y/100,i.set(o,a.x/100*1.01,a.y/100*1.01,c),r.scale(n,n,o),n}R(){const t={x:0,y:0,width:()=>this.s?this.s.width:1,height:()=>this.s?this.s.height:1};this.ot=new n.MeshShader({vert:"attribute vec3 aPosition;\n\n\n\nuniform mat4 projViewModelMatrix;\n\n\n\nvoid main() {\n\n gl_Position = projViewModelMatrix * vec4(aPosition, 1.0);\n\n}\n\n",frag:"precision mediump float;\n\n\n\nuniform vec3 color;\n\n\n\nvoid main() {\n\n gl_FragColor = vec4(color, 1.0);\n\n}\n\n",uniforms:["color",{name:"projViewModelMatrix",type:"function",fn:(t,e)=>r.multiply([],e.projViewMatrix,e.modelMatrix)}],extraCommandProps:{viewport:t}});const e=[],s=[];this.nt=new n.MeshShader({vert:"const 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#include <draco_decode_vert>\n\nvoid main() {\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_POSITION\n\n vec3 localPos = decode_getPosition(POSITION);\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\n\n gl_Position = projViewModelMatrix * vec4(localPos, 1.0);\n\n gl_PointSize = pointSize;\n\n}\n\n",frag:"#define SHADER_NAME PNTS\n\nprecision mediump float;\n\n\n\nvarying vec4 vColor;\n\n\n\nvoid main() {\n\n gl_FragColor = vColor;\n\n}\n\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:(t,e)=>r.multiply(s,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,n)=>o.fromMat4(e,n.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 i=this.L();this.J=new n.PhongShader({extraCommandProps:i}),this.tt=new n.pbr.StandardShader({extraCommandProps:i});const a=this.t;he(a.getRenderer().canvas,this.o,a.getMap()),this.picking=new n.FBORayPicking(this.h,{vert:this.tt.vert,extraCommandProps:i,uniforms:this.tt.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap())}L(){return{viewport:{x:0,y:0,width:()=>this.s?this.s.width:1,height:()=>this.s?this.s.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}}}ct(t){return{projViewMatrix:this.getMap().projViewMatrix,color:t&&t.color||[0,1,0]}}et(t){const e=this.getMap(),n=e.getLightManager(),r=(n&&n.getDirectionalLight()||{}).direction||[1,1,-1],s=t&&t.pointOpacity||1;return{projViewMatrix:e.projViewMatrix,pointOpacity:s,lightDir:i.normalize(r,r)}}D(){const t=this.getMap(),e=this.t.getRenderer().canvas,{iblTexes:n,dfgLUT:r}=fe(e),s=le(t,n,r),i=this.t.getRenderer().getMaskUniforms();return A(s,{czm_lightDirectionEC:s.light0_viewDirection,lightSpecular:[1,1,1],viewMatrix:t.viewMatrix,projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,outSize:[e.width,e.height],polygonFill:[1,1,1,1],polygonOpacity:1}),A(s,i),s}Ft(t,e,r,s,i){const o=e.materials&&e.materials[t];if(!o||!o.baseColorTexture&&!o.pbrMetallicRoughness)return null;const c=A({},s);if(o.baseColorTexture){const t=e.textures[o.baseColorTexture.index];let n;t&&!t.image.color&&(n=this.Vt(t)),c.baseColorFactor=t&&t.image.color||o.baseColorFactor||[1,1,1,1],n&&(c.baseColorTexture=n)}else{if(o.normalTexture){const t=this.Vt(e.textures[o.normalTexture.index]),n=o.normalTexture.scale||1;c.normalTexture=t,c.normalMapFactor=n}if(o.occlusionTexture){const t=this.Vt(e.textures[o.occlusionTexture.index]),n=o.occlusionTexture.strength||1;c.occlusionTexture=t,c.occlusionFactor=n}if(o.emissiveTexture){const t=this.Vt(e.textures[o.emissiveTexture.index]);c.emissiveTexture=t}o.emissiveFactor&&(c.emissiveFactor=o.emissiveFactor);const t=o.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(c.baseColorFactor=t.baseColorFactor),t.baseColorTexture&&void 0!==t.baseColorTexture.index){const n=e.textures[t.baseColorTexture.index];n.image&&n.image.color?c.baseColorFactor=c.baseColorFactor?a.multiply(c.baseColorFactor,c.baseColorFactor,n.image.color):n.image.color:(c.baseColorTexture=this.Vt(n),c.baseColorTexture.getREGLTexture(this.o))}if(O(t.metallicFactor)||(c.metallicFactor=t.metallicFactor),O(t.roughnessFactor)||(c.roughnessFactor=t.roughnessFactor),o.metallicRoughnessTexture){const t=this.Vt(e.textures[o.metallicRoughnessTexture.index]);c.metallicRoughnessTexture=t}}}if(o.s3mMaterial)return new n.Material(c);if(c.environmentExposure=i,o.extensions&&o.extensions.KHR_materials_unlit)return c.environmentExposure=1,c.ambientColor=[1,1,1],c.light0_diffuse=[0,0,0,0],c.lightSpecular=[0,0,0],new n.PhongMaterial(c);c.alphaTest=.99;let h=new n.pbr.StandardMaterial(c);"phong"===r&&(h=n.PhongMaterial.convertFrom(h));const u=o.pbrMetallicRoughness,f=u&&u.baseColorTexture&&u.baseColorTexture.extensions;return f&&f.KHR_texture_transform&&(h.set("khr_offset",f.KHR_texture_transform.offset||[0,0]),h.set("khr_rotation",f.KHR_texture_transform.rotation||0),h.set("khr_scale",f.KHR_texture_transform.scale||[1,1])),h.once("complete",this.N),h}Vt(t){const e={type:t.type?re(t.type):"uint8",format:t.format?se(t.format):"rgba",flipY:!!t.flipY},r=t.image;r.array?e.data=r.array:r.mipmap&&(e.mipmap=r.mipmap),e.width=r.width,e.height=r.height;const s=t.sampler||t.texture&&t.texture.sampler;return s&&(s.magFilter&&(e.mag=te(s.magFilter)),s.minFilter&&(e.min=ee(s.minFilter)),s.wrapS&&(e.wrapS=ne(s.wrapS)),s.wrapT&&(e.wrapT=ne(s.wrapT))),new n.Texture2D(e,this.M)}v({target:t}){const e=t.kt,n=this.u[e];if(n.count--,!n.count){const t=n.meshes;this.m[e]=t,delete this.u[e];const r=t.vt;delete t.vt,r(null,{mesh:n.meshes,id:e})}}Ht(){return pe}lt(t){return this.t.lt(t)}yt(t,e){const n=this.getMap();return n.getGLZoom?n.distanceToPoint(t,e,n.getGLZoom()):n.distanceToPointAtRes(t,e,n.getGLRes())}_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(),Oe)}xt(t){return"Y"===t?ae:"X"===t?ce:ye}pick(t,e,n=3){const r=this.t;if(!r||!r.options.picking)return[];if(!this.pickingFBO||!this.picking)return[];const s=this.getMap(),i=this.D(),o=this.picking;o.render(this.O.getMeshes().filter(t=>!t.bloom),i,!0);let a={};o.getRenderedMeshes().length&&(a=o.pick(t,e,n,i,{viewMatrix:s.viewMatrix,projMatrix:s.projMatrix,returnPoint:r.options.pickingPoint}));const{meshId:c,pickingId:h,point:u,coordinate:f}=a,l=(0===c||c)&&o.getMeshAt(c);if(!l||!l.geometry)return[];const d=l.properties;u&&u.length&&(u[0]=Math.round(1e5*u[0])/1e5,u[1]=Math.round(1e5*u[1])/1e5,u[2]=Math.round(1e5*u[2])/1e5);const m={batchId:h};if(r.options.debug&&(m.debugInfo=d),d&&d.batchTable){const{batchTable:t,batchTableBin:e,count:n}=d,r=h;for(const s in t)void 0!==t[s].byteOffset?m[s]=St(t[s],e,n,r):m[s]=t[s][r]}return[{service:l.properties.serviceIndex,data:m,point:u,coordinate:f}]}F(t){let e=new Set;for(let n=0,r=t.length;n<r;n++){const r=t[n].data.node;this.k(r)&&e.add(r.$)}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.j=t;const e=this.t.getRenderer();this.q=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelAllHighlight(){this.j=null;const t=this.t.getRenderer();this.q=t.getFrameTimestamp(),t.setToRedraw(!0)}showOnly(t){this.X=t;const e=this.t.getRenderer();this.K=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelShowOnly(){this.X=null;const t=this.t.getRenderer();this.K=t.getFrameTimestamp(),t.setToRedraw(!0)}zt(){if(!this.P)return[];const t={},e=[];for(const n in this.P){const r=this.P[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())}}const Ce=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")},Re=Ce(),Ue=Re.gl_trans__coders=Re.gl_trans__coders||{};function Le(t,e){if(e)for(let n=0;n<e.length;n++){t[e[n].id||e[n].index]=e[n]}}Ue.inject=function(t){const e=t.toString(),n=e.indexOf("{")+1,r=e.substring(0,n),s=Re.gl_trans__coders=Re.gl_trans__coders||{};let i=`${r}\n const _____getGlobal = ${Ce.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},Ue.registerTranscoder=function(t,e){Ue[t]=e},Ue.getTranscoder=function(t){return Ue[t]};const Be=[];class Pe{constructor(t,e,n,r){this.Gt=t,this.V=e,this.jt=r,this.qt=n.version,t.indexOf("i3s:tileset:")<0?(this.qt<=1.6?this.Xt="root":this.Xt=0,n.version=this.qt):(this.Xt=t.substring("i3s:tileset:".length),this.qt>1.6&&(this.Xt=parseInt(this.Xt))),this.Gt=t,this.Kt=n}load(){const t=this.Kt,e=t.layerScene.baseUrl;if(this.qt<=1.6)return t[this.Xt]&&t[this.Xt].lodSelection?(this.$t=t[this.Xt],this.Wt()):new Promise(n=>{let r=e+"/nodes/"+this.Xt;t.layerScene.eslpk&&(r+="/3dNodeIndexDocument.json"),this.jt(this.V,r,()=>{this.$t=t[this.Xt],n(this.Wt())})});if(this.qt>=1.7){if(t[this.Xt])return this.$t=t[this.Xt],this.Wt();const n=Math.floor(this.Xt/t.nodesPerPage);return new Promise(r=>{let s=e+"/nodepages/"+n;t.layerScene.eslpk&&(s+=".json"),this.jt(this.V,s,()=>{this.$t=t[this.Xt],r(this.Wt())})})}return null}getTileset(){return this.Yt}getChildrenURL(){return this.Zt}Wt(){const t=this.Kt,e=t.layerScene.baseUrl,n=this.$t.children,r=[],s={};if(n)for(let i=0;i<n.length;i++)if(this.qt<=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.jt(this.V,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.jt(this.V,r,()=>{n()})}),r.push(s[a]))}return r.length?Promise.all(r).then(()=>this.Qt()):this.Qt()}Qt(){return Promise.resolve(this.Jt())}te(t){Le(this.Kt,t)}Jt(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.ee(this.$t,!0)}}ee(t){const e=this.qt,n=this.Kt,r=t,s=r.obb,i=r.mbs,o={};let a;if(i)a=De([],i[0],i[1],i[2]),o.sphere=[...a,i[3]];else if(s){a=De([],s.center[0],s.center[1],s.center[2]);const t=function(t,e,n){const r=w.fromQuat([],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]}(a,s.halfSize,s.quaternion),e=t[3]+t[6]+t[9],n=t[4]+t[7]+t[10],r=t[5]+t[8]+t[11];T.set(Be,e,n,r);const i=T.len(Be);o.sphere=[...a,i]}let c=1/0,h=0;if(r.mbs?h=r.mbs[3]:r.obb&&(h=Math.max(Math.max(r.obb.halfSize[0],r.obb.halfSize[1]),r.obb.halfSize[2])),void 0!==r.lodThreshold)if("maxScreenThresholdSQ"===n.lodSelectionMetricType){c=h/(Math.sqrt(r.lodThreshold)/(.25*Math.PI))}else console.error("Unsupported lodSelectionMetricType in Layer");else if(void 0!==r.lodSelection)for(let t=0;t<r.lodSelection.length;t++)"maxScreenThreshold"===r.lodSelection[t].metricType&&(c=h/r.lodSelection[t].maxError);(c===1/0||isNaN(c))&&(c=1e5);const u=16*c,f=g.identity([]),l=r.children;let d;if(l){d=[];const t=this.Kt;for(let n=0;n<l.length;n++){const r=e<=1.6?l[n].id:l[n];if(!t[r]){d=null;break}d.push(this.ee(t[r]))}}const m={refine:"REPLACE",boundingVolume:o,transform:f,geometricError:u};return e<=1.6?t.lodSelection?t.geometryData&&(m.content={uri:"i3s:mesh:"+(t.id||t.index)}):m.content={uri:"i3s:tileset:"+(t.id||t.index)}:l&&l.length&&!d?m.content={uri:"i3s:tileset:"+(t.id||t.index)}:r.mesh&&(m.content={uri:"i3s:mesh:"+(t.id||t.index)}),d&&d.length&&(m.children=d),m}getJSON(){return this.$t}}function De(t,e,n,r){return st(t,M(e),M(n),r)}const Fe=!!Ue.ktx2,ke=r.identity([]),He=(()=>{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 Ve(t){return t.indexOf("i3s:mesh")>=0}const ze="i3s:mesh:".length;function Ge(t,e,n,r,s){const i=e.layerScene.eslpk,o=function(t,e){const n=e.substring(ze);return t>=1.7?parseInt(n):n}(e.version,t),a=e[o],c=e.layerScene.baseUrl,h=[];let u=!1;const f=ke;let l,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{l=a.mesh.geometry,d=a.mesh.material;const t=e.layerScene.geometryDefinitions[l.definition],{geometryBuffers:o}=t;u=r&&2===o.length;const f=Ue.draco&&u?o[1]:o[0],m=Ue.draco&&u?1:0;let p=c+`/nodes/${l.resource}/geometries/`+m;i&&(p+=".bin");const y={geometry:{url:p,info:f}};if(s&&He&&u&&!Ue.draco)throw new Error("Must import @maptalks/transcoder.draco to load i3s draco compressed geometry");const b=e.layerScene.materialDefinitions,g=e.layerScene.textureSetDefinitions;let T,w=0;if(d&&(w=b[d.definition]),b){T=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=je(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 x(e[a])&&t(e[a],n,r,s,i,o)}(o,e,n,r,s,i),o}(w,g,c,d.resource,n,e.layerScene.eslpk)}else T={pbrMetallicRoughness:{metallicFactor:0}};y.material=T,h.push(y)}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:f}}function je(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&&Fe)return t[n]}return null}const qe=[];class Xe extends(h(t.renderer.CanvasRenderer)){constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new j(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.ne={},this.re=[],this.jt=this.se.bind(this)}getAnalysisMeshes(){if(!this.painter)return qe;const t=this.painter.getPaintedMeshes();if(!t)return qe;const e=[],{b3dmMeshes:n,pntsMeshes:r,i3dmMeshes:s}=t;return n.length&&F(e,n),r.length&&F(e,r),s.length&&F(e,s),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.re.length||super.needToRedraw())}getFrameTimestamp(){return this.ie}drawOnInteracting(t,e,n){this.draw(e,n)}draw(t,e){this.ie=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.oe(),this.ae();const{selectedTiles:o,leaves:a,requests:c}=this.ce(r,s);c.length&&this.loadTiles(c),this.he(o,a,e),this.ue(),c.length||this.completeRender()}ce(t,e){const n=this.layer.getRootTiles();let r=[];this.fe();let s=0;const i=this.le(),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.V];o[h.id]=1;let f=!1;const l=this.getCachedTile(h.id);if(this.de(h.id)?(s++,f=c=!0,this.tilesLoading[h.id].current=!0):l?(this.getTileOpacity(l)<1&&(f=c=!0),(!i.node.me||u.isS3M||!i.node.children||i.node.me<=500)&&(a=!0,i.selected=!0,i.data=l)):this.painter.has(h)||(f=c=!0,r.push(h)),!f)continue;if(this.pe(i))a=!0;else{this.ye(i).length&&(a=!0)}}let h=[],u={};if(a&&({selectedTiles:h,leaves:u}=this.be(t)),r.length>1&&(r.sort(Ke),i)){const t=i-s;r=t>0?r.slice(0,t):[]}return{loading:c,requests:r,selectedTiles:h,leaves:u}}be(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.ge===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.ge=s.length}for(let t=0;t<o.length;t++)s.push(o[t])}return{selectedTiles:e,leaves:n}}pe(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}ye(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const n=t.$+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.Te(s[i],t);n.selected=!0,n.data=this.tileCache.get(o),t.children.push(n),e.push(n)}else s[i].$<=n&&r.push(s[i])}}return e}he(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(P(e)){const n=D(e);return this.we(e,n,t),null}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const n=t.V,r=this._e[n];return new Pe(e,n,r,this.jt).load().then(n=>{this.onTilesetLoad(n,t,e)})}t&&-1===e.indexOf("http://")&&-1===e.indexOf("https://")&&!Ve(e)&&(e=t.baseUrl+e);const n=this.layer.H(t.V);if(n.ajaxInMainThread){let r=n.urlParams;r&&(r=(e.indexOf("?")>0?"&":"?")+r);let s=y.getArrayBuffer(e+(r||""),n.fetchOptions);const i=s.xhr;s=s.then(n=>{delete this.ne[e],n?this.we(e,n.data,t):this.onTileError(null,t,e)}).catch(n=>{delete this.ne[e],this.onTileError(n,t,e)}),this.ne[e]=i}else this.we(e,null,t);return null}we(t,e,r){let s=this.Oe;s||(s=n.Util.getSupportedFormats(this.gl.gl||this.gl),this.Oe=s);const i=this.layer.H(r.V);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:t=this.layer.getTileUrl(t,r.baseUrl,this.layer.Ae[r.V]),arraybuffer:e,rootIdx:r.V,upAxis:r.St,transform:r.matrix,supportedFormats:s};if(Ve(t)){const e=this._e[r.V];if(o.i3sInfo=Ge(t,e,this.regl,this.layer.options.enableI3SCompressedGeometry,this.layer.options.forceI3SCompressedGeometry),!o.i3sInfo)return void this.onTileError({status:404},r,t)}o.service=A({},i),i.offset&&delete o.service.offset,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?this.re.push({data:n,tile:r}):this.onTilesetLoad(n,r,t)})}ae(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let n=0;for(;this.re.length&&(n<e||!t.isInteracting());){const{data:t,tile:e}=this.re.shift(),{magic:r}=t;"b3dm"===r?this.painter.createB3DMMesh(t,e.id,e,(n,{mesh:r})=>{this.Ie(t,e,n,r)}):"pnts"===r?this.painter.createPntsMesh(t,e.id,e,(n,{mesh:r})=>{this.Ie(t,e,n,r)}):"i3dm"===r?this.painter.createI3DMMesh(t,e.id,e,(n,{mesh:r})=>{this.Ie(t,e,n,r)}):"cmpt"===r&&this.painter.createCMPTMesh(t,e.id,e,(n,{mesh:r})=>{this.Ie(t,e,n,r)}),n++}}Ie(t,e,n,r){if(n)this.onTileError(n,e);else{const n=this.xe(r);e.memorySize=n,this.onTileLoad(t,e)}}xe(t){let e=0;if(Array.isArray(t))for(let n=0;n<t.length;n++)t[n]&&(e+=this.xe(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.Se(e),this.setToRedraw(),this.layer.fire("tileload",{node:e}))}onTilesetLoad(t,e,n){this.layer&&(this.layer.Bt=t.extensions&&t.extensions["s3m:VertexCompressionType"],t.capabilities||t.layers&&t.layers[0]&&t.layers[0].capabilities?this.Me(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;console.warn("failed to load 3d tile: "+r),console.warn(t),delete this.tilesLoading[e.id],this.Ne(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}Ne(e,n){const r={loadTime:t.Util.now(),current:!0,error:n,node:e};this.tileCache.add(e.id,r)}Se(e){const n={loadTime:t.Util.now(),current:!0,node:e};this.tileCache.add(e.id,n)}abortTileLoading(t){if(!t||!this.workerConn)return;const e=t.node.content.url;if(this.layer.H(t.node.V).ajaxInMainThread){const t=this.ne[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.ne[e]}fe(){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},n=this.canvas.gl&&this.canvas.gl.wrap;n?(this.gl=this.canvas.gl.wrap(),this.regl=this.canvas.gl.regl):(this.glOptions=e,this.gl=this.Ee(this.canvas,e)),this.regl=this.regl||u({gl:this.gl,attributes:e,extensions:["OES_element_index_uint"],optionalExtensions:t.options.optionalExtensions||[]}),n&&(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 ve(this.regl,t),this.layer.ve()}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new V("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let n=this.layer.options||{};n=A({},n),delete n.offset,n.projection=t.getSpatialReference().getProjection().code;const r=this.layer.getId();e.addLayer(r,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.ue(!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}ue(t){this.Ce||(this.Ce=Date.now());const e=Date.now();if(t||!(e-this.Ce<this.layer.options.retireInterval)){this.Ce=e;for(const e in this.tilesLoading){const n=this.tilesLoading[e];!t&&n.current||this.abortTileLoading(n)}}}le(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}Ee(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}de(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 It(t,e,0,n)}oe(){if(!this.Re)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const n=[];for(const r in this.Re){const s=this.Re[r];if("pending"===s.status)continue;s.status="pending";const i=s.rootIdx;if(n.push(y.getJSON(r).then(t=>{delete this.Re[r];const e=this._e[i];if(e){t.nodes?Le(e,t.nodes):(e[t.id]=t,Le(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)}se(t,e,n){this.Re||(this.Re={}),this.Re[e]=this.Re[e]||[],this.Re[e].rootIdx=t,this.Re[e].push(n),this.setToRedraw()}Me(t,e,n){this._e||(this._e=[]);const r=e.V;this._e[r]||(this._e[r]={});const s=this._e[r],i=this.layer.H(r);t.layers&&(t=t.layers[0],"/"!==n[n.length-1]&&(n+="/"),n+="layers/0"),s.version=+(i.i3sVersion||t.store.version),function(t,e,n,r,s,i){if(!s.layerScene){s.layerScene=t,s.nodesPerPage=t.nodePages&&t.nodePages.nodesPerPage||64,s.lodSelectionMetricType=t.nodePages&&t.nodePages.lodSelectionMetricType;let e=r;s.layerScene.eslpk=e.indexOf("3dSceneLayer.json")>=0;if(e.endsWith(".json")){const t=r.lastIndexOf("/");e=t<0?"./":r.substring(0,t)}s.layerScene.baseUrl=function(t){return t.split("?")[0]}(e)}return new Pe(r,e,s,i).load()}(t,r,0,n,s,this.jt).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.j||(this.j=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const n=t[e].service||0;let r=this.j[n];r||(r=this.j[n]=new Map),r.set(t[e].id,t[e])}else{const e=t.service||0;let n=this.j[e];n||(n=this.j[e]=new Map),n.set(t.id,t)}this.painter.highlight(this.j)}cancelHighlight(t,e){if(!this.j)return;const n=this.j[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.j[t]=null),this.painter.highlight(this.j)}}cancelAllHighlight(){delete this.j,this.painter.cancelAllHighlight()}showOnly(t){if(this.X||(this.X=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const n=t[e].service||0;let r=this.X[n];r||(r=this.X[n]=new Map),r.set(t[e].id,t[e])}else{const e=t.service||0;let n=this.X[e];n||(n=this.X[e]=new Map),n.set(t.id,t)}this.painter.showOnly(this.X)}cancelShowOnly(){delete this.X,this.painter.cancelShowOnly()}zt(){return this.painter?this.painter.zt():[]}}function Ke(t,e){return t.st-e.st}function $e(t,e,n){return t[0]=e[n],t[1]=e[n+3],t[2]=e[n+6],t}function We(t,e,n){return Math.sqrt(function(t,e,n){const r=T.subtract(Ye,n,t),s=$e(Ze,e,0),i=$e(Qe,e,1),o=$e(Je,e,2),a=T.len(s),c=T.len(i),h=T.len(o);T.normalize(s,s),T.normalize(i,i),T.normalize(o,o);const u=tn;u[0]=T.dot(r,s),u[1]=T.dot(r,i),u[2]=T.dot(r,o);let f,l=0;u[0]<-a?(f=u[0]+a,l+=f*f):u[0]>a&&(f=u[0]-a,l+=f*f);u[1]<-c?(f=u[1]+c,l+=f*f):u[1]>c&&(f=u[1]-c,l+=f*f);u[2]<-h?(f=u[2]+h,l+=f*f):u[2]>h&&(f=u[2]-h,l+=f*f);return l}(t,e,n))}const Ye=[],Ze=[],Qe=[],Je=[],tn=[];const en=2*Math.PI;class nn{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+=en,n<0&&(n+=en)),(n>s||gt(n,s,1e-14))&&(n<i||gt(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 rn=[0,0,1];function sn(t,e){return st(e,t[0],t[1],t[2])}class on{constructor(t,e){this.normal=i.copy([],t),this.distance=e}static fromPointNormal(t,e,n){const r=-i.dot(e,t);return i.copy(n.normal,e),n.distance=r,n}}const an=[],cn=[],hn=[],un=[],fn=[],ln=[],dn=[],mn=[],pn=[],yn=[],bn=new on([1,0,0],0),gn=[];class Tn{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new nn(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){let n=0;if(!nn.contains(this.rectangle,e)){const e=this.southwestCornerCartesian,r=this.northeastCornerCartesian,s=this.westNormal,o=this.southNormal,a=this.eastNormal,c=this.northNormal,h=i.subtract(gn,t,e),u=i.dot(h,s),f=i.dot(h,o),l=i.subtract(gn,t,r),d=i.dot(l,a),m=i.dot(l,c);u>0?n+=u*u:d>0&&(n+=d*d),f>0?n+=f*f:m>0&&(n+=m*m)}const r=e[2],s=this.minimumHeight,o=this.maximumHeight;if(r>o){const t=r-o;n+=t*t}else if(r<s){const t=s-r;n+=t*t}return Math.sqrt(n)}computeBox(t){const e=this;sn(nn.southwest(t,cn),e.southwestCornerCartesian),sn(nn.northeast(t,cn),e.northeastCornerCartesian),an[0]=t.west,an[1]=.5*(t.south+t.north),an[2]=0;const n=sn(an,hn),r=i.cross(fn,n,rn);i.normalize(e.westNormal,r),an[0]=t.east;const s=sn(an,mn),o=i.cross(fn,rn,s);i.normalize(e.eastNormal,o);const a=i.subtract(fn,n,s),c=i.normalize(un,a),h=t.south;let u;if(h>0){an[0]=.5*(t.west+t.east),an[1]=h;const n=sn(an,pn);i.copy(yn,c);const r=on.fromPointNormal(e.southwestCornerCartesian,e.westNormal,bn);wn(pn,yn,r,e.southwestCornerCartesian),u=pt(n,ln)}else u=yt(nn.southeast(t,cn),ln);const f=i.cross(dn,u,a);i.normalize(e.southNormal,f);const l=t.north;let d;if(l<0){an[0]=.5*(t.west+t.east),an[1]=l;const n=sn(an,pn);i.scale(yn,c,-1);const r=on.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,bn);wn(pn,yn,r,e.northeastCornerCartesian),d=pt(n,ln)}else d=yt(nn.northwest(t,cn),ln);const m=i.cross(dn,a,d);i.normalize(e.northNormal,m)}}function wn(t,e,n,r){const s=t,o=e,a=n.normal,c=i.dot(a,o);if(Math.abs(c)<1e-15)return;const h=(-n.distance-i.dot(a,s))/c;return h<0?void 0:(r=i.scale(r,o,h),i.add(r,s,r))}const _n=new t.Extent(0,0,0,0),On=new t.Extent(0,0,0,0),An=[],In=[],xn=[],Sn=[],Mn=new t.Point(0,0),Nn=[],En=new t.Coordinate(0,0),vn=r.identity([]),Cn=[0,0];class Rn extends(f(t.Layer)){constructor(t,e){super(t,e),this.Ue(),this.ne={},this.Le=[]}Ue(){const t=this.options.services.map(t=>t.url);this.Be=this.Be||{},this.Ae=this.Ae||[];for(let e=0;e<t.length;e++){const n=t[e];let r=this.Be[n];void 0===r&&(r=this.Be[n]=this.Ae.length),this.Ae[r]=Bn(n,r,this.options.services[e])}this.fire("rootready",{roots:this.Ae.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.Ue();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]&&A(n[t],e),!O(e.visible)){const r=n[t].url,s=this.Be[r];this.Ae&&this.Ae[s]&&(this.Ae[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.Be[n];this.Ae[r]&&(this.Ae[r]=null),delete this.Be[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()-96,0)%e;return t.replace(n.domainKey,r[s])}}return t}getExtent(e){if(!e&&0!==e){const e=new t.Extent;for(let t=0;t<this.Ae.length;t++)if(this.Ae[t].boundingVolume){const n=this.boundingVolumeToExtent(this.Ae[t]);e._combine(n)}return e}return this.Ae[e]&&this.Ae[e].boundingVolume?this.boundingVolumeToExtent(this.Ae[e]):null}boundingVolumeToExtent(e){const n=e.boundingVolume.Pe?vn:e.matrix,r=this.getMap();if(e.boundingVolume.region){const n=e.boundingVolume.region;return new t.Extent(N(n[0]),N(n[1]),N(n[2]),N(n[3]))}if(e.boundingVolume.sphere){const s=e.boundingVolume.sphere,o=ut([],i.transformMat4([],s,n)),a=s[3],c=r.locate(o,-a,a),h=r.locate(o,a,-a);return new t.Extent(c,h)}if(e.boundingVolume.box){const s=e.boundingVolume.box,a=i.transformMat4([],s,n),c=new t.Coordinate(ut([],a)),h=s.slice(3);o.multiply(h,o.fromMat4([],e.matrix),h);const u=i.length(h.slice(0,3)),f=i.length(h.slice(3,6)),l=i.length(h.slice(6,9)),d=Math.max(u,f,l),m=r.locate(c,-d,d),p=r.locate(c,d,-d);return new t.Extent(m,p)}return null}getRootTiles(){return this.Ae}getTiles(){const t=this.getRenderer();if(!t.ready)return this.De(),{tiles:Sn};const e=this.getMap(),n=e.cameraPosition;let r,s;if(e.getGLZoom)s=e.pointToDistance(n[2],0,e.getGLZoom()),En.set(n[0],n[1]),r=e.pointToCoord(En,e.getGLZoom());else{const t=e.getGLRes();s=e.pointAtResToDistance(n[2],0,t),En.set(n[0],n[1]),r=e.pointAtResToCoord(En,t)}this.Fe=this.Fe||[],i.set(this.Fe,M(r.x),M(r.y),s),this.ke=st(this.ke||[],this.Fe[0],this.Fe[1],this.Fe[2]),this.He=2*Math.tan(.5*M(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const h=[];for(let e=0;e<this.Ae.length;e++){const n=this.Ae[e];if(!n||!n.visible)continue;let r=1/0;const s=[n],i=this.Ve(e);for(;s.length>0;){const e=s.pop();for(e.id||this.ze(e);c.level>=e.$;)c=c.parent;const n=this.Ge(e,i,o);if(n<1){let t=c;for(;t&&!t.content;)t=t.parent;0===n&&t&&t.content&&this.je(h,t);if(!1===this.options.services[e.V].alwaysShow)continue;if(!(0===n&&e.$<=r))continue;e.content&&(r=e.$)}e.st<1/0&&this.qe(e);const a=this.Te(e,c);c.children.push(a);const u=e.children,f=u&&u.length,l=a.content;if(!f&&l&&this.je(h,a),f){l&&"add"===e.refine&&this.je(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].St=e.St,u[i].baseUrl=e.baseUrl;const t=u[i].content&&(u[i].content.url||u[i].content.uri);t&&(P(t)||t.indexOf("i3s:")>=0?u[i].baseUrl=e.baseUrl:-1===t.indexOf("http://")&&-1===t.indexOf("https://")?u[i].content.url=e.baseUrl+t:u[i].baseUrl=t.substring(0,t.lastIndexOf("/")+1))}s.push(u[i])}!r&&l&&this.je(h,a)}}}return{root:a,tiles:h}}je(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 Un(n,e);if(n.box)return 0===Ln(n,e)}return!1}(this.Fe,this.ke,n)||t.push(e)}Te(t,e){return{id:t.id,node:t,children:[],level:t.$,parent:e,content:t.content&&t.content.url}}ze(e){e.id=t.Util.GUID(),e.matrix=e.transform||r.identity([]),e.Xe=this.Ke(e),e.parent&&(function(t){return t.content&&t.content.uri&&t.content.uri.indexOf("i3s:")>=0}(e)||(e.matrix=r.multiply(e.matrix,e.parent.matrix,e.matrix)),e.V=e.parent.V,void 0===e.$&&(e.$=e.parent.$+1),e.maxExtent=e.parent.maxExtent),e.refine=e.refine&&e.refine.toLowerCase()||"replace",e.content&&!e.content.url&&e.content.uri&&(e.content.url=e.content.uri)}H(t){return this.Ae[t].service}$e(t){const e=t.boundingVolume;if(!e||e.Pe&&!this.We(t))return;const n=this.H(t.V),s=n.heightOffset||0,o=this.options.offset,a=I(o)||o[0]||o[1],c=n.coordOffset||Cn;if(!Array.isArray(c))throw new Error("service.coordOffset must be an array");if(!e.Pe&&(!t.boundingVolume||!s&&r.exactEquals(t.matrix,vn)&&!a&&c===Cn))return;const{region:h,box:u,sphere:f}=e;if(e.coordOffset=[c[0],c[1]],e.heightOffset=s,h){e.originalVolume||(e.originalVolume=h.slice(0));const t=e.originalVolume,n=this.Ye([N(t[0]),N(t[1])]);h[0]=M(n.x+c[0]),h[1]=M(n.y+c[1]);const r=this.Ye([N(t[2]),N(t[3])]);h[2]=M(r.x+c[0]),h[3]=M(r.y+c[1]),h[4]=t[4]+s+(c[2]||0),h[5]=t[5]+s+(c[2]||0)}else if(u||f){e.originalVolume||(e.originalVolume=(u||f).slice(0));const n=u||f,r=e.originalVolume,o=i.transformMat4(An,r,t.matrix),a=ut(In,o),h=this.Ye([a[0]+c[0],a[1]+c[1]]);a[0]=h.x,a[1]=h.y,a[2]+=s+(c[2]||0),st(n,M(a[0]),M(a[1]),a[2])}e.Pe=!0}We(t){const e=t.boundingVolume,n=this.H(t.V),r=n.heightOffset||0,s=n.coordOffset||Cn;return e.coordOffset[0]!==s[0]||e.coordOffset[1]!==s[1]||e.heightOffset!==r}Ke(t){return void 0===t.geometricError||!t.boundingVolume}qe(t){let e=t.parent;for(;e&&e.Xe&&!(e.st<=t.st);)e.st=t.st,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,n){if(!t)return void console.warn("invalid tileset at : "+n);const s=this.H(e.V),i=(t.asset&&t.asset.gltfUpAxis||e&&e.St||s.upAxis||"Y").toUpperCase();t.root.baseUrl=n.substring(0,n.lastIndexOf("/")+1);const o=n.indexOf("realspace/")>-1;0===e.$&&(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.St=i,e){const n=e.V,s=this.Ae[n];c&&!s.isS3M&&(s.isS3M=c);const i=e.boundingVolume;A(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=r.multiply([],e.parent.matrix,o)):e.matrix=o),e.Ze=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.Xe=this.Ke(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||P(h)||-1!==h.indexOf("http://")||-1!==h.indexOf("https://")||(e.content.url=e.baseUrl+h)}this.De(),this.fire("loadtileset",{tileset:t,index:e&&e.V,url:n})}Ge(t,e,n){if(t.st=1/0,0===t.$||t.Xe)return 1;if(this.$e(t),!this.Qe(t,e,n))return-1;if(0===t.geometricError)return 1;let r=this.H(t.V).maximumScreenSpaceError;null==r&&(r=16);let s=this.Je(t);return 0===s&&t.parent&&(s=.5*(t.parent.me||0)),s>=r?1:0}lt(e,n){n||(n=new t.Point(0,0));const r=this.getMap();return r.getGLZoom?r.coordToPoint(e,r.getGLZoom(),n):r.coordToPointAtRes(e,r.getGLRes(),n)}Qe(e,n,s){const a=e.id;let c=this.Le[a];const{boundingVolume:h}=e,u=h.sphere;let f=h.region;const p=h.box;if(!c){let n,s,l;if(p&&(f=function(t,e){for(let e=0;e<9;e++)t[e+3]!==1/0&&t[e+3]!==-1/0||(t[e+3]=6378137*Math.sign(t[e+3])*3),qn[e]=t[e+3];const n=qn;r.exactEquals(e,vn)||o.multiply(n,o.fromMat4(Nn,e),n);const s=i.copy(Pn,t),a=i.set(Dn,n[0],n[1],n[2]),c=i.set(Fn,n[3],n[4],n[5]),h=i.set(kn,n[6],n[7],n[8]);Hn[0]=Hn[0]||[];const u=i.copy(Hn[0],s);i.sub(u,u,a),i.sub(u,u,c),i.sub(u,u,h),Hn[1]=Hn[1]||[];const f=i.copy(Hn[1],s);i.sub(f,f,a),i.sub(f,f,c),i.add(f,f,h),Hn[2]=Hn[2]||[];const l=i.copy(Hn[2],s);i.sub(l,l,a),i.add(l,l,c),i.sub(l,l,h),Hn[3]=Hn[3]||[];const d=i.copy(Hn[3],s);i.sub(d,d,a),i.add(d,d,c),i.add(d,d,h),Hn[4]=Hn[4]||[];const m=i.copy(Hn[4],s);i.add(m,m,a),i.sub(m,m,c),i.sub(m,m,h),Hn[5]=Hn[5]||[];const p=i.copy(Hn[5],s);i.add(p,p,a),i.sub(p,p,c),i.add(p,p,h),Hn[6]=Hn[6]||[];const y=i.copy(Hn[6],s);i.add(y,y,a),i.add(y,y,c),i.sub(y,y,h),Hn[7]=Hn[7]||[];const b=i.copy(Hn[7],s);i.add(b,b,a),i.add(b,b,c),i.add(b,b,h);for(let t=0;t<Hn.length;t++)Vn[t]=Vn[t]||[],ut(Vn[t],Hn[t]),zn[t]=Vn[t][0],Gn[t]=Vn[t][1],jn[t]=Vn[t][2];return[M(Math.min(...zn)),M(Math.min(...Gn)),M(Math.max(...zn)),M(Math.max(...Gn)),Math.min(...jn),Math.max(...jn)]}(p,e.matrix),h.region=f),f){n=_n.set(N(f[0]),N(f[1]),N(f[2]),N(f[3]));const t=n.getCenter(),e=this.tn(t);n=n.convertTo(t=>this.lt(t,Mn),On),l=f[4],s=f[5],c=this.Le[a]=[[n.xmin,n.ymin,l*e[2]],[n.xmax,n.ymax,s*e[2]]],c.center=t}else if(u){const e=ut(An,u),n=new t.Coordinate(e),r=this.lt(n,Mn).toArray(),s=this.tn(n);r.push(e[2]*s[2]),c=this.Le[a]=[r,u[3]*s[2]],c.center=n}}if(n){if(f)_n.xmin=c[0][0],_n.ymin=c[0][1],_n.xmax=c[1][0],_n.ymax=c[1][1];else if(u){const t=c[2];_n.xmin=c[0][0]-t,_n.ymin=c[0][1]-t,_n.xmax=c[0][0]+t,_n.ymax=c[0][1]+t}else if(p){const t=c[1],e=c[2];_n.xmin=c[0][0]-t,_n.ymin=c[0][1]-e,_n.xmax=c[0][0]+t,_n.ymax=c[0][1]+e}if(!n.intersects(_n))return!1}return f?l(s,c):u?d(s,c):!!p&&m(s,c)}tn(t){const e=this.getMap(),n=e.distanceToPointAtRes(100,100,e.getGLRes(),t);let r;return r=e.altitudeToPoint?e.altitudeToPoint(100,e.getGLRes())/100:n.y/100,i.set(xn,n.x/100*1.01,n.y/100*1.01,r),xn}Ye(e){Array.isArray(e)&&(e=new t.Coordinate(e));let n=this.options.offset;if(I(n)&&(n=n(Array.isArray(e)?new t.Coordinate(e):e)),n[0]||n[1]){const t=this.getMap(),r=t.getGLRes(),s=t.coordToPointAtRes(e,r);return s._add(n),t.pointAtResToCoord(s,r)}return e}Ve(e){const n=this.H(e).maxExtent;if(!n)return null;const r=this.Ae[e];return r.maxExtent||(r.maxExtent=new t.Extent(n).convertTo(t=>this.lt(t))),r.maxExtent}Je(t){const e=this.He,n=t.geometricError;if(0===n)return t.me=0,0;const r=this.getMap();let s;t.boundingVolume.region?s=function(t,e,n){t.en||(t.en=new Tn(t.boundingVolume.region));return t.en.distanceToCamera(e,n)}(t,this.ke,this.Fe):t.boundingVolume.sphere?s=Un(t.boundingVolume,this.ke):t.boundingVolume.box&&(s=Ln(t.boundingVolume,this.ke));const i=Math.max(Math.abs(s),1e-7),o=n*r.height/(i*e);return t.st=s,t.me=o,o}De(){const t=this.getRenderer();t&&t.setToRedraw()}Rt(t){return this.Le[t]}identify(e,n={}){const r=this.getMap(),s=this.getRenderer();if(!r||!s)return[];const i=r.coordToContainerPoint(new t.Coordinate(e));return this.identifyAtPoint(i,n)}identifyAtPoint(t,e={}){const n=[];if(!e.excludeMasks){const r=this.identifyMask(t,e);r&&r.length&&F(n,r)}const r=this.getMap(),s=this.getRenderer();if(!r||!s)return[];const i=r.getDevicePixelRatio();return F(n,s.pick(t.x*i,t.y*i,e)),n}getCurrentBatchIDs(){const t=this.getMap(),e=this.getRenderer();return t&&e?e.zt():[]}highlight(t){const e=this.getRenderer();return e?(e.highlight(t),this):(this.j||(this.j=[]),this.j.push(t),this)}ve(){if(this.j){for(let t=0;t<this.j.length;t++)this.highlight(this.j[t]);delete this.j}}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.X||(this.X=[]),this.X.push(t),this)}nn(){if(this.X){for(let t=0;t<this.X.length;t++)this.showOnly(this.X[t]);delete this.X}}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}}function Un(t,e){const n=t.sphere,r=i.dist(n,e),s=t.sphere[3];return r<s?0:r-s}function Ln(t,e){const n=t.box;return We(i.set(An,n[0],n[1],n[2]),o.set(Nn,n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10],n[11]),e)}function Bn(t,e,n){const s=(t=E(t)).indexOf("{s}")>=0?"{s}":t.indexOf("%7Bs%7D")>=0?"%7Bs%7D":null;return{service:n,visible:O(n.visible)?1:n.visible,baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:r.identity([]),V:e,$:0,domainKey:s}}Rn.mergeOptions({"maxGPUMemory":512,"retireInterval":2e3,"loadingLimitOnInteracting":5,"loadingLimit":0,"renderer":"gl","forceRenderOnZooming":!0,"forceRenderOnRotating":!0,"forceRenderOnMoving":!0,"debug":!1,"debugOutline":[0,1,0],"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]}),Rn.registerRenderer("gl",Xe),Rn.registerJSONType("Geo3DTilesLayer");const Pn=[],Dn=[],Fn=[],kn=[],Hn=[],Vn=[],zn=[],Gn=[],jn=[],qn=[];let Xn=null;function Kn(){return Xn||(Xn={"image/crn":Ue.crn&&Ue.crn(),"image/ktx2":Ue.ktx2&&Ue.ktx2(),"image/cttf":Ue.ktx2&&Ue.ktx2(),"draco":Ue.draco&&Ue.draco()}),Xn}class $n{constructor(t,e,n){this.rn=t,this.sn=e||p,this.Oe=n,this.in=Kn()}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.an(t,e,n,r,s)):y.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.an(t,s,n,r)})}an(t,e,n,r,s){const i=s&&s.maxTextureSize,o=this.cn(e,n,r,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.sn(a,o.glb,{transferable:!0,requestImage:this.rn,decoders:this.in,supportedFormats:this.Oe,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}})}cn(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),f=28+e;h>=570425344?(f-=8,o=a,h=c,u=0,a=0,c=0):u>=570425344&&(f-=4,o=h,h=a,u=c,a=0,c=0);const l=[t];let d,m,p;if(a>0?(d=_t(t,f,a),f+=a,o=d.BATCH_LENGTH):d={"BATCH_LENGTH":o},c>0&&(f+=c),h>0&&(m=Ot(t,f,h),f+=h,u>0)){const e=At(0,f,u);p=t.slice(e.offset,e.offset+e.byteLength),f+=u,l.push(p)}const y=d.BATCH_LENGTH,b={};if(d&&d.BATCH_ID){b.BATCH_ID=xt(d.BATCH_ID,t,(void 0).offset,y);const e=b.BATCH_ID.array&&b.BATCH_ID.array.buffer;e&&l.indexOf(e)<0&&l.push(e)}return{count:o,transferables:l,featureTable:d,batchTable:m,batchTableBin:p,b3dm:b,glb:{buffer:t,byteOffset:f,byteLength:s.byteLength+s.byteOffset-f}}}hn(){return null}}class Wn{constructor(t,e,n,r){this.rn=t,this.sn=e||p,this.Oe=n,this.in=Kn(),this.un=r}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.an(t,e,n,r,s)):y.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.an(t,s,n,r)})}an(t,e,n,r,s){return this.ln(t,e,n,r,s).then(({gltf:s,transferables:i})=>{const o=this.dn(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})})}ln(t,e,n,r,s){const i=s&&s.maxTextureSize,o={transferable:!0,requestImage:this.rn,decoders:this.in,supportedFormats:this.Oe,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=R(new Uint8Array(e,c+n,a.byteLength-c));-1==r.indexOf("://")&&(r=t.substring(0,t.lastIndexOf("/"))+"/"+r);return r.indexOf(".glb")>0?y.getArrayBuffer(r,{}).then(t=>this.mn(r,{buffer:t.data,byteOffset:0},o)):y.getJSON(r,{}).then(t=>this.mn(r,t,o))}{const r={buffer:e,byteOffset:c+n,byteLength:a.byteLength-c};return this.mn(t,r,o)}}mn(t,e,n){const r=t.substring(0,t.lastIndexOf("/")),s=new this.sn(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}})}dn(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}=Ut(s,32+e,o),f={},l=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;f.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(f.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,n=a.QUANTIZED_VOLUME_SCALE,{byteOffset:r}=a.POSITION_QUANTIZED;f.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:l,componentType:5126,array:this.pn(new Uint16Array(t,r+c.offset,3*l),e,n)},o.push(f.POSITION.array.buffer)}if(a.BATCH_ID){f.BATCH_ID=xt(a.BATCH_ID,t,c.offset,l);const e=f.BATCH_ID.array&&f.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;f.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(f.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,f.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(f.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;f.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:this.yn(new Uint16Array(t,e+c.offset,2*l))},o.push(f.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,f.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:this.yn(new Uint16Array(t,e+c.offset,2*l))},o.push(f.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;f.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,l).slice()},o.push(f.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;f.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(f.SCALE_NON_UNIFORM.array.buffer)}return{count:l,batchTable:h,batchTableBin:u,featureTable:a,i3dm:f,transferables:o}}yn(t){const e=t.length/2,n=new Float32Array(3*e),r=[];for(let s=0;s<e;s++)Yn(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}pn(t,e,n){return Rt(new Float32Array(t.length),t,e,n)}hn(){return null}}function Yn(t,e,n,r){if(t[0]=Zn(e,r),t[1]=Zn(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]))*Qn(e),t[1]=(1-Math.abs(e))*Qn(t[1])}return T.normalize(t,t)}function Zn(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 Qn(t){return t<0?-1:1}class Jn{constructor(){}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.an(t,e,n,r)):y.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.an(t,s,n,r)})}an(t,e,n,r){return this.bn(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})}bn(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}=Ut(s,e+28,o),f=a.QUANTIZED_VOLUME_OFFSET,l=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.gn||(this.gn=Kn().draco),this.gn(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.Tn(t,e.attributes,c.offset,d,o,f,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:Ct(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?r.BATCH_ID=xt(a.BATCH_ID,t,c.offset,d):r.BATCH_ID=tr(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 y=this.Tn(t,a,c.offset,d,o,f,l);if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?y.BATCH_ID=xt(a.BATCH_ID,t,c.offset,d):y.BATCH_ID=tr(d);const e=y.BATCH_ID.array&&y.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:d,batchTable:h,batchTableBin:u,featureTable:a,pnts:y,transferables:o})}Tn(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.pn(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}pn(t,e,n){return Rt(new Float32Array(t.length),t,e,n)}hn(){return null}}function tr(t){const e=B(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:Ct(e),array:n}}class er{constructor(t,e,n,r){this.Oe=n,this.rn=t,this.sn=e||p,this.un=r}load(t,e,n=0,r=0,s){return e?this.an(t,e,n,r,s):y.getArrayBuffer(t,{}).then(e=>{const s=e.data;return this.an(t,s,n,r)})}an(t,e,n,r,s){r||(r=e.byteLength);const i=this.wn(e,t,n,r),o=[];for(let n=0;n<i.length;n++){let r;if("b3dm"===i[n].magic)r=new $n(this.rn,this.sn,this.Oe);else if("i3dm"===i[n].magic)r=new Wn(this.rn,this.sn,this.Oe,this.un);else if("pnts"===i[n].magic)r=new Jn;else{if("cmpt"!==i[n].magic){console.warn("Unsupported magic in CMPT tile:",i[n].magic);continue}r=new er(this.rn,this.sn,this.Oe,this.un)}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}))}wn(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=Tt(s,c),r=s.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+n,byteLength:r}),c+=r}return o}}if(e.transcoders){const n=t.Map.VERSION;if(n.indexOf("1.0.0-beta")>=0||n.indexOf("1.0.0-alpha")>=0){const n=e.transcoders.inject(_);t.registerWorkerAdapter("@maptalks/3dtiles",n)}else t.registerWorkerAdapter("@maptalks/3dtiles",(function(){return e.transcoders.inject(_)}))}else t.registerWorkerAdapter("@maptalks/3dtiles",_);export{$n as B3DMLoader,er as CMPTLoader,Rn as Geo3DTilesLayer,k as Geo3DTilesUtil,bt as Geo3DTransform};"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.88.1");