@maptalks/3dtiles 0.95.7 → 0.95.8

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,5 +1,5 @@
1
1
  /*!
2
- * @maptalks/3dtiles v0.95.7
2
+ * @maptalks/3dtiles v0.95.8
3
3
  * LICENSE : UNLICENSED
4
4
  * (c) 2016-2024 maptalks.org
5
5
  */
@@ -8,4 +8,4 @@ import*as t from"maptalks";import*as e from"@maptalks/gl";import{reshader as n,m
8
8
  * @maptalks/gl v0.95.6
9
9
  * LICENSE : UNLICENSED
10
10
  * (c) 2016-2024 maptalks.com
11
- */(100,1),Jn=[0,0,0,1],Qn=[1,1,1];class Kn{constructor(e,r){this.s=r,this.i=r.getRenderer().canvas,this.pickingFBO=r.getRenderer().pickingFBO,this.o=new t.SpatialReference,this.h=e,this.u=new n.Renderer(e),this.m={},this.p={},this.v={},this.T={},this.O={},this._={},this.M=new n.Scene,this.A=new n.Scene,this.I=new n.Scene,this.S=new n.Scene,this.N=new n.ResourceLoader(e.texture(2)),this.C=this.P.bind(this),this.R=new n.PhongMaterial({"baseColorFactor":[1,1,1,1]}),this.L(),this.k=new n.KHRTechniquesWebglManager(this.h,this.B(),this.N);const s=this.getMap();s.altitudeToPoint&&(this.U=s.altitudeToPoint(100,s.getGLRes())/100)}getI3DMMeshes(){return this.T}getPNTSMeshes(){return this.v}getB3DMMeshes(){return this.p}getPaintedMeshes(){return this.F}getMap(){return this.s.getMap()}paint(t,e,n){const i=n&&n.renderTarget,o=n&&n.sceneFilter,a=this.getMap();if(!t.length||!a)return null;const c=this.D(),h=a.projViewMatrix,u=[],l=[],d=[],m=[],p=[],b=this.j(t),g=[];for(let i=0,o=t.length;i<o;i++){const o=t[i].data.node;let a=this.G(o);if(!a)continue;const c=this.s.H(o.V);o.q&&c.debugShowBoundingVolume&&g.push(o.q);const y=c.heightOffset||0,w=c.coordOffset||In;this.O[o.id]&&(a=this.O[o.id],a=_t(a));let v=c.polygonOffset||Tn;dt(v)&&(v=v()),Array.isArray(a)||(u[0]=a,a=u);for(let t=0,i=a.length;t<i;t++){const i=a[t].properties.magic;if(a[t].properties.heightOffset===y&&a[t].properties.coordOffset[0]===w[0]&&a[t].properties.coordOffset[1]===w[1]||(this.$(a[t]),a[t].X=r.copy([],a[t].localTransform)),"b3dm"===i){if(a[t].getBoundingBox&&!f(h,a[t].getBoundingBox()))continue;const{batchIdData:e,batchIdMap:r}=a[t].geometry.properties;if(e&&r){const e=a[t].properties.node.V;this.J&&this.J[e]?s.highlightMesh(this.h,a[t],this.J[e],this.K,r):this.J&&this.J[e]||s.highlightMesh(this.h,a[t],null,this.K,r),s.showOnly(this.h,a[t],this.Z&&this.Z[e],this.Y,r)}n&&n.bloom&&a[t].properties.hlBloomMesh&&(a[t].properties.hlBloomMesh.properties.depthFunc="always",a[t].properties.hlBloomMesh.properties.polygonOffset=v,d.push(a[t].properties.hlBloomMesh)),d.push(a[t])}else"pnts"===i?m.push(a[t]):"i3dm"===i&&p.push(a[t]);a[t].properties.isLeaf=!!e[o.id],a[t].properties.level=b.get(o.W),a[t].properties.polygonOffset=v,a[t].tt=o,e[o.id]||l.push(a[t]),this.et(a[t]),this.nt(a[t],o)}}let y=0;const w=this.k.getExcludeFilter();y+=this.rt(this.st,c,[o,Sn,w],i,l,d,p),y+=this.rt(this.it,c,[o,En,w],i,l,d,p),this.k.forEachShader((t,e,n)=>{const r=this.D(n);y+=this.rt(t,r,[o,e],i,l,d,p)}),this.A.setMeshes(m);const v=this.ot();return y+=this.u.render(this.ct,v,this.A,i&&i.fbo),this.F={pntsMeshes:m,i3dmMeshes:p,b3dmMeshes:d},g.forEach(t=>{this.ht(t)}),this.S.setMeshes(g),this.u.render(this.ut,c,this.S,i&&i.fbo),y}ht(t){const e=t.properties.node,n=this.s.H(e.V),s=this.s.lt(e.V),a=n.heightOffset||0,c=this.ft(),h=s.dt,u=i.set(Hn,0,0,c*(a-h));let l=n.rotation||[0,0,0];l=o.fromEuler(zn,l[0],l[1],l[2]);const f=n.scale||[1,1,1],d=r.fromRotationTranslationScale(Dn,l,u,f);r.multiply(t.localTransform,t.X,d)}rt(t,e,n,r,s,i,o){t.filter=n.filter(t=>!!t),e.debug=!1,e.debug=!1;let a=0;return this.M.setMeshes(i),a+=this.u.render(t,e,this.M,r&&r.fbo),this.I.setMeshes(o),a+=this.u.render(t,e,this.I,r&&r.fbo),a}pt(t,e){return e.tt.bt-t.tt.bt}deleteTile(t){const e=t.node;e.q&&(e.q.geometry.dispose(),e.q.dispose(),delete e.q);const n=e.id;this.gt(n)}gt(t){const e=this.p[t]||this.v[t]||this.T[t]||this.O[t]||this.m[t];this.O[t]?this.yt(t):e&&(this.wt(e),delete this.p[t],delete this.v[t],delete this.T[t],delete this.m[t])}yt(t){let e=this.O[t];e=_t(e);for(let t=0;t<e.length;t++){const{id:n}=e[t].properties;this.gt(n)}delete this.O[t]}wt(t){if(Array.isArray(t))for(let e=0,n=t.length;e<n;e++)this.wt(t[e]);else{s.showOnly(this.h,t),s.highlightMesh(this.h,t);const e=t.geometry.properties.url;if(e){const n=this._[e];n&&n.refMeshes&&(n.refMeshes.delete(t.uuid),n.refMeshes.size||(n.geometry.dispose(),n.material.dispose(),delete this._[e]))}else t.geometry.dispose(),t.material&&t.material.dispose();t.dispose()}}remove(){const t=this.s;yn(t.getRenderer().canvas,t.getMap());for(const t in this.O)this.yt(t);this.O={};for(const t in this.p)this.gt(t);this.p={};for(const t in this.v)this.gt(t);this.v={};for(const t in this.T)this.gt(t);this.T={};for(const t in this.m)this.gt(t);this.m={},this.st&&(this.st.dispose(),delete this.st),this.it&&(this.it.dispose(),delete this.it),this.ct&&(this.ct.dispose(),delete this.ct),this.ut&&(this.ut.dispose(),delete this.ut),this.k.dispose(),this.picking&&this.picking.dispose()}G(t){return this.p[t.id]||this.v[t.id]||this.T[t.id]||this.O[t.id]}has(t){return this.G(t)||this.m[t.id]}$(t){const e=t.properties.magic;"b3dm"===e?this.vt(t):"i3dm"===e?this.Tt(t):"pnts"===e&&this.Ot(t)}createPntsMesh(t,e,s,i){if(this.v[e]){const t=this.v[e];return console.warn(`pnts mesh with id(${e}) was already created.`),i(null,{id:e,mesh:t}),t}const{pnts:o,featureTable:a,rootIdx:c,compressed_int16_params:h}=t,u=a.POINTS_LENGTH;o.BATCH_ID||(o.BATCH_ID=new Uint8Array(u),o.BATCH_ID.fill(0));const l=new n.Geometry(o,null,u,{static:!0,primitive:"points",positionAttribute:"POSITION",pickingIdAttribute:"BATCH_ID"});l.generateBuffers(this.h);const f={};o.POSITION?f.HAS_POSITION=1:o.POSITION_QUANTIZED&&(f.HAS_POSITION_QUANTIZED=1),o.RGB?f.HAS_RGB=1:o.RGBA?f.HAS_RGBA=1:o.RGB565&&(f.HAS_RGB565=1),(o.NORMAL||o.NORMAL_OCT16P)&&(f.HAS_NORMAL=1,o.NORMAL_OCT16P&&(f.HAS_NORMAL_OCT16P=1)),this._t(f,h),t.featureTable.CONSTANT_RGBA&&(t.featureTable.CONSTANT_RGBA=t.featureTable.CONSTANT_RGBA.map(t=>t/255));const{rtcCenter:d,rtcCoord:m,projCenter:p}=t,b=this.s.H(c),g=new n.Mesh(l);g.properties.magic="pnts",g.properties.id=e,g.properties.node=s,g.properties.count=u,g.properties.batchTable=t.batchTable,g.properties.batchTableBin=t.batchTableBin,g.properties.serviceIndex=c,g.properties.rtcCoord=m,g.properties.rtcCenter=d,g.properties.projCenter=p,g.setDefines(f),Object.defineProperty(g.uniforms,"pointColor",{enumerable:!0,get:function(){return t.featureTable.CONSTANT_RGBA?t.featureTable.CONSTANT_RGBA:b&&b.pointColor||[1,1,1,1]}});const y=this.getMap();let w=null,v=null;Object.defineProperty(g.uniforms,"pointSize",{enumerable:!0,get:function(){if(!b)return 2;if(on(b.pointSize)){const t=JSON.stringify(b.pointSize);t!==w&&(v=an(b.pointSize),w=t);return v(y.getZoom())}return b.pointSize||2}});let T=null,O=null;return Object.defineProperty(g.uniforms,"pointOpacity",{enumerable:!0,get:function(){if(!b)return 1;if(on(b.pointOpacity)){const t=JSON.stringify(b.pointOpacity);t!==T&&(O=an(b.pointOpacity),T=t);return O(y.getZoom())}return b.pointOpacity||1}}),this.Mt(g,h),this.Ot(g),g.X=r.copy([],g.localTransform),this.v[e]=g,i(null,{id:e,mesh:[g]}),[g]}Ot(t){const e=t.localTransform||[],{rtcCoord:n,node:r,projCenter:s}=t.properties;this.xt(e,n,s,r.V),t.setLocalTransform(e)}createI3DMMesh(t,e,s,a){if(this.T[e]){const t=this.T[e];return console.warn(`i3dm mesh with id(${e}) was already created.`),this.m[e]||a(null,{id:e,mesh:t}),t}const c=this.s.H(s.V),h=this.At(s.It),{i3dm:u,featureTable:l,gltf:f,batchTable:d,batchTableBin:m,count:b}=t,g=l.INSTANCES_LENGTH,{rtcCenter:y,rtcCoord:w}=t,v=this.St(Un,w),T=this.Et(Fn,s,y,w);r.multiply(v,T,v);const{POSITION:O,NORMAL_UP:_,NORMAL_RIGHT:M,SCALE:x,SCALE_NON_UNIFORM:A,INSTANCE_ROTATION:I}=u,S={"instance_vectorA":new Float32Array(4*g),"instance_vectorB":new Float32Array(4*g),"instance_vectorC":new Float32Array(4*g),"aPickingId":new Uint16Array(g)};for(let t=0;t<g;t++)S.aPickingId[t]=t;const E=new Float32Array(3),N=new Float32Array(3),C=[],P=new Float32Array(1),R=new Float32Array(3),L=[],k=[],B=[],U=[],F=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)=>{_?(qt(N,M,e),qt(E,_,e),i.cross(C,N,E),i.normalize(C,C),Ot(L,N,0),Ot(L,E,1),Ot(L,C,2),o.fromMat3(k,L)):I?(qt(F,I,e),o.fromMat3(k,F)):o.identity(k),x?(qt(P,x,e),i.set(B,P[0],P[0],P[0])):A?(qt(R,A,e),i.set(B,...R)):i.set(B,1,1,1),r.fromRotationTranslationScale(U,k,t,B),$t(S.instance_vectorA,e,U,0),$t(S.instance_vectorB,e,U,1),$t(S.instance_vectorC,e,U,2)});const D={};for(const t in S)D[t]={buffer:this.h.buffer({dimension:S[t].length/g,data:S[t]}),divisor:1};const z=c.shader||"pbr";let j=0,G=!0;const H=[],V=[];return Ut(f,(t,i,o,a)=>{const c=this.Nt(t,i,o,a,s,!0,z,V),{geometry:u,material:l}=c;l&&!l.isReady()&&(G=!1,j++);const f=new n.InstancedMesh(D,g,u,l);c.refMeshes||(c.refMeshes=new Set,c.refMeshes.add(f.uuid)),f.properties.magic="i3dm",f.properties.id=e,f.properties.count=b,f.properties.batchTable=d,f.properties.batchTableBin=m,f.properties.serviceIndex=s.V,f.properties.rtcCoord=w,f.properties.rtcCenter=y,f.properties.node=s;const p=this.Ct(t,u,l,s.V,a);t.compressed_int16_params&&this.Mt(f,t.compressed_int16_params),this.Pt(f,t.attributes);const T=r.identity([]);if(t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)r.multiply(T,T,t.matrices[e]);r.multiply(T,h,T),f.setPositionMatrix(T),this.Tt(f,v),f.setDefines(p),f.properties.polygonOffset={offset:0,factor:0},H.push(f),delete t.attributes,f.X=r.copy([],f.localTransform)}),Zn(V),G?(this.T[e]=H,a(null,{id:e,mesh:H})):(this.m[e]={meshes:H,count:j},H.Rt=a),H}Tt(t,e){const{rtcCenter:n,rtcCoord:s,node:i}=t.properties;if(!e){e=this.St(Un,s);const t=this.Et(Fn,i,n,s);r.multiply(e,t,e)}const o=this.s.H(i.V),a=t.localTransform||[];if(o.coordOffset){const t=this.Lt(Fn,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)||In}createB3DMMesh(e,s,i,o){if(e.gltf&&(e.gltf.transferables=null),this.p[s]||this.m[s]){const t=this.p[s];return console.warn(`mesh with id(${s}) was already created.`),this.m[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:l}=c.extensions.CESIUM_RTC,f=c.asset.sharePosition,d=this.At(i.It);let m;m=f?this.St(Un,u):this.xt(Un,u,h,i.V);const p=this.s.H(i.V);let b=p.shader||"pbr";if(p.unlit)b="phong";else 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){b="phong";break}const g=[],y=[];let w=0,v=!0;return Ut(c,(t,o,c,T)=>{const O=this.Nt(t,o,c,T,i,!1,b,g),{geometry:_,material:M}=O;M&&!M.isReady()&&(v=!1,w++);const x=new n.Mesh(_,M);O.refMeshes||(O.refMeshes=new Set,O.refMeshes.add(x.uuid)),x.properties.magic="b3dm",x.properties.id=s,x.properties.node=i,e.batchTable&&(x.properties.batchTable=e.batchTable,x.properties.batchTableBin=e.batchTableBin),x.properties.count=e.featureTable&&e.featureTable.BATCH_LENGTH||0,x.properties.serviceIndex=i.V;const A=this.Ct(t,_,M,i.V,T);x.setDefines(A);const I=t.compressUniforms;if(I)for(const t in I)x.setUniform(t,I[t]);t.compressed_int16_params&&this.Mt(x,t.compressed_int16_params),this.Pt(x,t.attributes),a&&(A.USE_MAX_EXTENT=1,x.setUniform("maxPrjExtent",a)),Object.prototype.hasOwnProperty.call(x.uniforms,"polygonOpacity")||Object.defineProperty(x.uniforms,"polygonOpacity",{enumerable:!0,get:function(){return pt(p.opacity)?p.opacity:1}}),Object.prototype.hasOwnProperty.call(x.uniforms,"polygonFill")||Object.defineProperty(x.uniforms,"polygonFill",{enumerable:!0,get:function(){return Et([],p.polygonFill||On)}}),Object.prototype.hasOwnProperty.call(x.material.uniforms,"hsv")||Object.defineProperty(x.material.uniforms,"hsv",{enumerable:!0,get:function(){return p.hsv||_n}});const S=r.identity([]);if(f&&t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)r.multiply(S,S,t.matrices[e]);f&&r.multiply(S,d,S),x.properties.node=i,x.properties.projCenter=h,x.properties.nodeMatrix=S,x.properties.isSharedPosition=f,x.properties.rtcCoord=u,x.properties.rtcCenter=l,this.vt(x,m),y.push(x),delete t.attributes,x.X=r.copy([],x.localTransform)}),Zn(g),v?(this.p[s]=y,o(null,{id:s,mesh:y})):(this.m[s]={meshes:y,count:w},y.Rt=o),y}kt(t){const e=this.s.Bt[t.id];if(!e)return;let s,i,o,a;if(e.length){if(2===e.length){const t=e[0],n=e[1];s=Xn.vertices,i=Xn.indices,o=t,a=[n,n,n]}}else{s=e.boxPosition,i=$n;o=this.s.lt(t.V).Ut,a=Qn}const c=new n.Geometry({POSITION:s},i,0,{primitive:"lines",positionAttribute:"POSITION"}),h=new n.Mesh(c,new n.Material({lineColor:[.8,.8,.1,1],lineOpacity:1})),u=r.identity([]);r.fromRotationTranslationScale(u,Jn,o,a),h.localTransform=u,h.X=r.copy([],u),h.properties.node=t,t.q=h}Mt(t,e){e.POSITION&&t.setUniform("compressedPositionRange",e.POSITION),e.TEXCOORD_0&&t.setUniform("compressedTexcoordRange_0",e.TEXCOORD_0),e.TEXCOORD_1&&t.setUniform("compressedTexcoordRange_1",e.TEXCOORD_0),e.NORMAL&&t.setUniform("compressedNormalRange",e.NORMAL),e.TANGENT&&t.setUniform("compressedTangentRange",e.TANGENT),e.compressed_ratio&&t.setUniform("compressed_ratio",e.compressed_ratio)}vt(t,e){const{isSharedPosition:n,rtcCoord:s,rtcCenter:i,projCenter:o,nodeMatrix:a,node:c}=t.properties;e||(e=n?this.St(Un,s):this.xt(Un,s,o,c.V));const h=t.localTransform||r.identity([]);if(n){const t=this.Et(Fn,c,i,s);r.multiply(h,e,a),r.multiply(h,t,h)}else r.multiply(h,e,a);const u=this.s.H(c.V);if(u.coordOffset){const t=this.Lt(Fn,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)||In}Pt(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)}}Et(e,n,s,o){const a=this.getMap(),c=this.s.H(n.V).heightOffset||0,h=new t.Coordinate(o);let u;u=a.altitudeToPoint?this.U:a.distanceToPointAtRes(100,100,a.getGLRes(),h).y/100;const l=n.matrix?r.copy(e,n.matrix):r.identity(e);if(s){ke(l,i.transformMat4(Nn,s,l),l)}const f=function(t,e,n,r,s,i,o){e=w.copy(Ue,e);const a=Zt(Ue,e[0]*$e,e[1]*$e,e[2]),c=y.getTranslation(Fe,n),h=r.ellipsoid;let u;u=0===w.len(c)?w.set(De,0,0,-6378137):re(De,c),Ve.x=u[0],Ve.y=u[1];const l=r.project(Ve,qe);ze[0]=l.x/s,ze[1]=l.y/s,ze[2]=(u[2]+o)*i;const f=Be(a,h,je),d=function(t,e,n){const r=t[0],s=t[1],i=t[2],o=t[4],a=t[5],c=t[6],h=t[8],u=t[9],l=t[10],f=e[0],d=e[1],m=e[2],p=e[3],b=e[4],g=e[5],y=e[6],w=e[7],v=e[8],T=r*f+o*d+h*m,O=s*f+a*d+u*m,_=i*f+c*d+l*m,M=r*p+o*b+h*g,x=s*p+a*b+u*g,A=i*p+c*b+l*g,I=r*y+o*w+h*v,S=s*y+a*w+u*v,E=i*y+c*w+l*v;return n[0]=T,n[1]=O,n[2]=_,n[3]=0,n[4]=M,n[5]=x,n[6]=A,n[7]=0,n[8]=I,n[9]=S,n[10]=E,n[11]=0,n[12]=t[12],n[13]=t[13],n[14]=t[14],n[15]=t[15],n}(y.invert(Ge,f),v.fromMat4(He,n),t);return ke(t,ze,d),t}(l,o,l,a.getProjection(),a.getGLRes(),u,c),d=function(t,e){return w.set(t,e[12],e[13],e[14]),t}(Bn,f);let m=this.s.options.offset;if(dt(m)){const t=this.s.Ft(n.id).center;m=m.call(this.s,t)}return i.set(kn,m[0],m[1],0),i.sub(d,d,kn),ke(f,d,f),f}Lt(t,e,n){const s=this.s.H(e);if(!s.coordOffset)return null;const o=this.getMap(),a=o.getGLRes();Cn.set(n[0],n[1]);const c=o.coordToPointAtRes(Cn,a,Rn),h=s.coordOffset,u=Cn.set(n[0]+h[0],n[1]+h[1]),l=o.coordToPointAtRes(u,a,Ln),f=l.x-c.x,d=l.y-c.y,m=this.ft(),p=i.set(kn,f,d,(h[2]||0)*m);return r.fromTranslation(t,p)}ft(){const t=this.getMap();let e;return e=t.altitudeToPoint?this.U:t.distanceToPointAtRes(100,100,t.getGLRes(),Cn).y/100,e}createCMPTMesh(t,e,n,r){if(this.O[e]){const t=this.O[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.O[e]=i,r(null,{id:e,mesh:i}),i}Ct(t,e,n,r,s){const i=("phong"===(this.s.H(r).shader||"pbr")?this.st:this.it).getGeometryDefines(e);s.asset&&"S3M"===s.asset.generator&&this.Dt(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.s.zt&&(i.MeshOPT_Compress=1),this.hasIBL()&&(i.HAS_IBL_LIGHTING=1),t.attributes&&t.attributes.TEXCOORD_0&&"WEB3D_quantized_attributes"===t.attributes.TEXCOORD_0.extensions&&(i.HAS_WEB3D_quantized_attributes_TEXCOORD=1),i.HAS_MIN_ALTITUDE=1,i.HAS_LAYER_OPACITY=1,this._t(i,t.compressed_int16_params);return ft(i,t.compressDefines),i}_t(t,e){e&&Object.keys(e).length>0&&(t.HAS_COMPRESSED_INT16=1,e.POSITION&&(t.HAS_COMPRESSED_INT16_POSITION=1),e.TEXCOORD_0&&(t.HAS_COMPRESSED_INT16_TEXCOORD_0=1),e.TEXCOORD_1&&(t.HAS_COMPRESSED_INT16_TEXCOORD_1=1),e.NORMAL&&(t.HAS_COMPRESSED_INT16_NORMAL=1),e.TANGENT&&(t.HAS_COMPRESSED_INT16_TANGENT=1),e.compressed_ratio&&(t.HAS_COMPRESSED_INT16_RATIO=1))}et(t){const e=this.s.getRenderer();e&&e.updateMaskDefines(t)}Dt(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)}Nt(t,e,n,r,s,i,o,a){let c=!1;r.asset&&"S3M"===r.asset.generator&&(c=!0,r.extensions=r.extensions||{});const h=r.url+"-"+e+"-"+n;if(this._[h])return this._[h];let u,l;a.push(t);const f=r.materials&&r.materials[t.material],d=r.extensions&&r.extensions.KHR_techniques_webgl,m=this.s.H(s.V);if(d&&f.extensions&&f.extensions.KHR_techniques_webgl){const e=this.jt(t,r,i,c);u=e.material,l=e.geometry,m.fillEmptyDataInMissingAttribute&&(l.desc.fillEmptyDataInMissingAttribute=!0)}else{l=this.Gt(t,i,qn);const e=m.ambientLight;let n=m.environmentExposure;const s=m.material,c=this.getMap().getLightManager(),h=c&&c.getAmbientLight();if(e&&(!h||h.color)&&void 0===n){const t=h&&h.color?h.color[0]:.2;n=e[0]/t}u=this.Ht(t.material,r,o,s||Mn,n||1,a,m)}u&&Object.defineProperty(u.uniforms,"alphaTest",{enumerable:!0,get:function(){const t=m.alphaTest;return lt(t)?.1:t}}),u&&!u.isReady()?u.Vt=s.id:u||(u=this.R);const p={geometry:l,material:u};return l.properties.url=h,this._[h]=p,p}jt(t,e,n,r){const{geometry:s,material:i}=this.k.createMesh(t,e,n,r);return{geometry:s,material:i}}Gt(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=mn(this.h,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,{static:!0,positionAttribute:r.POSITION,normalAttribute:r.NORMAL,uv0Attribute:r.TEXCOORD_0,uv1Attribute:r.TEXCOORD_1,color0Attribute:r.COLOR_0,tangentAttribute:r.TANGENT,pickingIdAttribute:r._BATCHID,primitive:void 0===t.mode?"triangles":dn(t.mode)});return i&&a&&(c.properties.batchIdData=i,c.properties.batchIdMap=function(t,e){if(!e)return null;const n=new Map;for(let r=0;r<e.length;r++){const s=e[r],i=t[s];let o=n.get(i);o||(o=[],n.set(i,o)),o.push(s)}return n}(i,a)),c.generateBuffers(this.h,{excludeElementsInVAO:e}),c}xt(t,e,n,s){const o=r.identity(t),a=this.getMap();Cn.x=n[0],Cn.y=n[1];const c=this._prjToPoint(Cn),h=this.qt(),u=1/(a.getGLZoom?a.getResolution(a.getGLZoom()):a.getGLRes());Cn.x=e[0],Cn.y=e[1];const l=this.ft();let f=this.s.options.offset;dt(f)&&(f=f.call(this.s,Cn));const d=this.s.H(s).heightOffset||0;return i.set(Bn,c.x-f[0],c.y-f[1],l*n[2]+l*d),r.translate(o,o,Bn),i.set(h,u,u,l),r.scale(o,o,h),o}nt(t,e){const n=this.s.H(e.V),s=this.s.lt(e.V).Ut;let a=n.rotation||[0,0,0];a=o.fromEuler(jn,a[0],a[1],a[2]);const c=n.scale||[1,1,1],h=r.fromRotationTranslationScale([],a,Gn,c),u=r.identity([]),l=r.identity([]);r.translate(u,u,i.scale(Vn,s,-1)),r.translate(l,l,s);const f=r.multiply(u,u,t.X);r.multiply(h,h,f);const d=r.multiply(l,l,h);t.localTransform=d}St(t,e){const n=r.identity(t),s=this.getMap(),o=this.qt();Cn.x=e[0],Cn.y=e[1];const a=s.distanceToPointAtRes(100,100,s.getGLRes(),Cn);let c;return c=s.altitudeToPoint?this.U:a.y/100,i.set(o,a.x/100*1.01,a.y/100*1.01,c),r.scale(n,n,o),n}L(){const t={x:0,y:0,width:()=>this.i?this.i.width:1,height:()=>this.i?this.i.height:1},e=[],s=[];this.ct=new n.MeshShader({vert:Xt,frag:"#define SHADER_NAME PNTS\n\nprecision mediump float;\n\n\n\nvarying vec4 vColor;\n\n\n\nvoid main() {\n\n vec2 circCoord = 2.0 * gl_PointCoord - 1.0;\n\n if (dot(circCoord, circCoord) > 1.0) {\n\n discard;\n\n } else {\n\n gl_FragColor = vColor;\n\n }\n\n}\n\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:(t,e)=>r.multiply(s,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,n)=>a.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.B();this.st=new n.PhongShader({extraCommandProps:i}),this.it=new n.pbr.StandardShader({extraCommandProps:i}),this.ut=new n.EdgeShader({extraCommandProps:{viewport:{x:0,y:0,width:()=>this.i?this.i.width:1,height:()=>this.i?this.i.height:1},blend:{enable:!0,func:{srcRGB:"src alpha",srcAlpha:1,dstRGB:"one minus src alpha",dstAlpha:"one minus src alpha"},equation:"add"}}});const o=this.s;gn(o.getRenderer().canvas,this.h,o.getMap()),this.picking=new n.FBORayPicking(this.u,{vert:this.it.vert,extraCommandProps:i,uniforms:this.it.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap()),this.$t=new n.FBORayPicking(this.u,{vert:Xt,extraCommandProps:i,uniforms:this.ct.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap())}B(){return{viewport:{x:0,y:0,width:()=>this.i?this.i.width:1,height:()=>this.i?this.i.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}}}ot(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.s,n=e.getRenderer().canvas,{iblTexes:r,dfgLUT:s}=wn(n),i=vn(t,r,s),o=this.s.getRenderer(),a=o.getMaskUniforms();i.minAltitude=e.options.altitude||0;const c=o.canvas.gl&&o.canvas.gl.wrap?e.options.opacity||0:1;return i.layerOpacity=c,ft(i,{czm_lightDirectionEC:i.light0_viewDirection,lightSpecular:[1,1,1],viewMatrix:t.viewMatrix,projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,outSize:[n.width,n.height],polygonFill:[1,1,1,1],polygonOpacity:1}),ft(i,a),i}Ht(t,e,r,s,i,o,a){const h=e.materials&&e.materials[t];if(!h||!h.baseColorTexture&&!h.pbrMetallicRoughness)return null;const u=ft({},s);if(h.baseColorTexture){const t=e.textures[h.baseColorTexture.index];let n;t&&!t.image.color&&(n=this.Xt(t,o)),u.baseColorFactor=t&&t.image.color||h.baseColorFactor||[1,1,1,1],n&&(u.baseColorTexture=n)}else{if(h.normalTexture){const t=this.Xt(e.textures[h.normalTexture.index],o);if(t){const e=h.normalTexture.scale||1;u.normalTexture=t,u.normalMapFactor=e}}if(h.occlusionTexture){const t=this.Xt(e.textures[h.occlusionTexture.index],o);if(t){const e=h.occlusionTexture.strength||1;u.occlusionTexture=t,u.occlusionFactor=e}}if(h.emissiveTexture){const t=this.Xt(e.textures[h.emissiveTexture.index],o);t&&(u.emissiveTexture=t)}h.emissiveFactor&&(u.emissiveFactor=h.emissiveFactor);const t=h.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(u.baseColorFactor=t.baseColorFactor),t.baseColorTexture&&void 0!==t.baseColorTexture.index){const n=e.textures[t.baseColorTexture.index];if(n.image&&n.image.color)u.baseColorFactor=u.baseColorFactor?c.multiply(u.baseColorFactor,u.baseColorFactor,n.image.color):n.image.color;else{const t=this.Xt(n,o);t&&(u.baseColorTexture=t,u.baseColorTexture.getREGLTexture(this.h))}}if(lt(t.metallicFactor)||(u.metallicFactor=t.metallicFactor),lt(t.roughnessFactor)||(u.roughnessFactor=t.roughnessFactor),h.metallicRoughnessTexture){const t=this.Xt(e.textures[h.metallicRoughnessTexture.index],o);t&&(u.metallicRoughnessTexture=t)}}}if(h.s3mMaterial)return new n.Material(u);if(u.environmentExposure=i,u.alphaTest=.1,a.unlit||h.extensions&&h.extensions.KHR_materials_unlit)return u.ambientColor=[1,1,1],u.light0_diffuse=[0,0,0,0],u.lightSpecular=[0,0,0],new n.PhongMaterial(u);let l=new n.pbr.StandardMaterial(u);"phong"===r&&(l=n.PhongMaterial.convertFrom(l));const f=h.pbrMetallicRoughness,d=f&&f.baseColorTexture&&f.baseColorTexture.extensions;return d&&d.KHR_texture_transform&&(l.set("khr_offset",d.KHR_texture_transform.offset||[0,0]),l.set("khr_rotation",d.KHR_texture_transform.rotation||0),l.set("khr_scale",d.KHR_texture_transform.scale||[1,1])),l.doubleSided=!(!a.doubleSided&&!h.doubleSided),l.once("complete",this.C),l}Xt(t,e){const r={type:t.type?ln(t.type):"uint8",format:t.format?fn(t.format):"rgba",flipY:!!t.flipY},s=t.image;if(e.push(s),s.array?r.data=s.array:s.mipmap&&(r.mipmap=s.mipmap),!r.data&&!r.mipmap)return null;if(r.width=s.width,r.height=s.height,r.mipmap&&(r.width<4||r.height<4))return null;const i=t.sampler||t.texture&&t.texture.sampler;return i&&(i.magFilter&&(r.mag=cn(i.magFilter)),i.minFilter&&(r.min=hn(i.minFilter)),i.wrapS&&(r.wrapS=un(i.wrapS)),i.wrapT&&(r.wrapT=un(i.wrapT))),new n.Texture2D(r,this.N)}P({target:t}){const e=t.Vt,n=this.m[e];if(n.count--,!n.count){const t=n.meshes;this.p[e]=t,delete this.m[e];const r=t.Rt;delete t.Rt,r(null,{mesh:n.meshes,id:e})}}qt(){return xn}Jt(t){return this.s.Jt(t)}_pointToPrj(t){const e=this.getMap();return e.getGLZoom?e._pointToPrj(t,e.getGLZoom()):e._pointToPrjAtRes(t,e.getGLRes())}_prjToPoint(t){const e=this.getMap();return e.getGLZoom?e._prjToPoint(t,e.getGLZoom()):e._prjToPointAtRes(t,e.getGLRes(),Pn)}At(t){return"Y"===t?pn:"X"===t?bn:An}pick(t,e,n=3){const r=this.s;if(!r||!r.options.picking)return[];if(!this.pickingFBO||!this.picking)return[];const s=[],i=this.D(),o=this.Qt(this.picking,i,this.M,t,e,n);o&&s.push(o);const a=this.Qt(this.picking,i,this.I,t,e,n);a&&s.push(a);const c=this.ot(),h=this.Qt(this.$t,c,this.A,t,e,n);return h&&s.push(h),s}Qt(t,e,n,r,s,i){if(!n.getMeshes().length)return null;const o=this.s,a=this.getMap();t.render(n.getMeshes().filter(t=>!t.bloom),e,!0);let c={};t.getRenderedMeshes().length&&(c=t.pick(r,s,i,e,{viewMatrix:a.viewMatrix,projMatrix:a.projMatrix,returnPoint:o.options.pickingPoint}));const{meshId:h,pickingId:u,point:l,coordinate:f}=c,d=(0===h||h)&&t.getMeshAt(h);if(!d||!d.geometry)return null;const m=d.properties;l&&l.length&&(l[0]=Math.round(1e5*l[0])/1e5,l[1]=Math.round(1e5*l[1])/1e5,l[2]=Math.round(1e5*l[2])/1e5);const p={batchId:u};if(o.options.debug&&(p.debugInfo=m),m&&m.batchTable){const{batchTable:t,batchTableBin:e,count:n}=m,r=u;for(const s in t)void 0!==t[s].byteOffset?p[s]=we(t[s],e,n,r):p[s]=t[s][r]}return{service:d.properties.serviceIndex,data:p,point:l,coordinate:f}}j(t){let e=new Set;for(let n=0,r=t.length;n<r;n++){const r=t[n].data.node;this.G(r)&&e.add(r.W)}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.s.getRenderer();this.K=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelAllHighlight(){this.J=null;const t=this.s.getRenderer();this.K=t.getFrameTimestamp(),t.setToRedraw(!0)}showOnly(t){this.Z=t;const e=this.s.getRenderer();this.Y=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelShowOnly(){this.Z=null;const t=this.s.getRenderer();this.Y=t.getFrameTimestamp(),t.setToRedraw(!0)}Kt(){if(!this.F)return[];const t={},e=[];for(const n in this.F){const r=this.F[n];if(r)for(let n=0;n<r.length;n++){const s=r[n],i=s&&s.geometry;if(!s||!i)continue;const o=s.properties.serviceIndex;t[o]||(t[o]=new Set);const a=i.properties.batchIdData;if(a)for(let n=0;n<a.length;n++)t[o].has(a[n])||(e.push({id:a[n],service:o}),t[o].add(a[n]))}}return e}hasIBL(){const t=this.getMap().getLightManager();return!!(t&&t.getAmbientResource())}}function Zn(t){for(let e=0;e<t.length;e++)t[e]&&(t[e].array&&(t[e].array=null),t[e].mipmap&&(t[e].mipmap=null),t[e].indices&&(t[e].indices=null))}const Yn=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")},Wn=Yn(),tr=Wn.gl_trans__coders=Wn.gl_trans__coders||{};function er(t,e){if(e)for(let n=0;n<e.length;n++){t[e[n].id||e[n].index]=e[n]}}tr.inject=function(t){const e=t.toString(),n=e.indexOf("{")+1,r=e.substring(0,n),s=Wn.gl_trans__coders=Wn.gl_trans__coders||{};let i=`${r}\n const _____getGlobal = ${Yn.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},tr.registerTranscoder=function(t,e){tr[t]=e},tr.getTranscoder=function(t){return tr[t]};const nr=[];class rr{constructor(t,e,n,r,s){this.s=r,this.Zt=t,this.V=e,this.Yt=s,this.Wt=n.version,t.indexOf("i3s:tileset:")<0?(this.Wt<=1.6?this.te="root":this.te=0,n.version=this.Wt):(this.te=t.substring("i3s:tileset:".length),this.Wt>1.6&&(this.te=parseInt(this.te))),this.Zt=t,this.ee=n}load(){const t=this.ee,e=t.layerScene.baseUrl;if(this.Wt<=1.6)return t[this.te]&&t[this.te].lodSelection?(this.ne=t[this.te],this.re()):new Promise(n=>{let r=e+"/nodes/"+this.te;t.layerScene.eslpk&&(r+="/3dNodeIndexDocument.json"),this.Yt(this.V,r,()=>{this.ne=t[this.te],n(this.re())})});if(this.Wt>=1.7){if(t[this.te])return this.ne=t[this.te],this.re();const n=Math.floor(this.te/t.nodesPerPage);return new Promise(r=>{let s=e+"/nodepages/"+n;t.layerScene.eslpk&&(s+=".json"),this.Yt(this.V,s,()=>{this.ne=t[this.te],r(this.re())})})}return null}getTileset(){return this.se}getChildrenURL(){return this.ie}re(){const t=this.ee,e=t.layerScene.baseUrl,n=this.ne.children,r=[],s={};if(n)for(let i=0;i<n.length;i++)if(this.Wt<=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.Yt(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.Yt(this.V,r,()=>{n()})}),r.push(s[a]))}return r.length?Promise.all(r).then(()=>this.oe()):this.oe()}oe(){return Promise.resolve(this.ae())}ce(t){er(this.ee,t)}ae(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.he(this.ne,!0)}}he(t){const e=this.s.getRenderer(),n=this.ee.projection,r=!n||n&&4326===n.wkid,s=this.Wt,i=this.ee,o=t,a=o.obb,c=o.mbs,h={};let u;if(c)u=w.set([],c[0],c[1],c[2]),r||(u=e.ue(u,u)),u=sr([],u[0],u[1],u[2]),h.sphere=[...u,c[3]];else if(a){u=w.set([],a.center[0],a.center[1],a.center[2]),r||(u=e.ue(u,u)),u=sr([],u[0],u[1],u[2]);const t=function(t,e,n){const r=v.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]}(u,a.halfSize,a.quaternion),n=t[3]+t[6]+t[9],s=t[4]+t[7]+t[10],i=t[5]+t[8]+t[11];w.set(nr,n,s,i);const o=w.len(nr);h.sphere=[...u,o]}let l=1/0,f=0;if(o.mbs?f=o.mbs[3]:o.obb&&(f=Math.max(Math.max(o.obb.halfSize[0],o.obb.halfSize[1]),o.obb.halfSize[2])),void 0!==o.lodThreshold)if("maxScreenThresholdSQ"===i.lodSelectionMetricType){l=f/(Math.sqrt(o.lodThreshold)/(.25*Math.PI))}else console.error("Unsupported lodSelectionMetricType in Layer");else if(void 0!==o.lodSelection)for(let t=0;t<o.lodSelection.length;t++)"maxScreenThreshold"===o.lodSelection[t].metricType&&(l=f/o.lodSelection[t].maxError);(l===1/0||isNaN(l))&&(l=1e5);const d=16*l,m=y.identity([]),p=o.children;let b;if(p){b=[];const t=this.ee;for(let e=0;e<p.length;e++){const n=s<=1.6?p[e].id:p[e];if(!t[n]){b=null;break}b.push(this.he(t[n]))}}const g={refine:"REPLACE",boundingVolume:h,transform:m,geometricError:d};return s<=1.6?t.lodSelection?t.geometryData&&(g.content={uri:"i3s:mesh:"+(t.id||t.index)}):g.content={uri:"i3s:tileset:"+(t.id||t.index)}:p&&p.length&&!b?g.content={uri:"i3s:tileset:"+(t.id||t.index)}:o.mesh&&(g.content={uri:"i3s:mesh:"+(t.id||t.index)}),b&&b.length&&(g.children=b),g}getJSON(){return this.ne}}function sr(t,e,n,r){return Zt(t,bt(e),bt(n),r)}const ir=!!tr.ktx2,or=r.identity([]),ar=(()=>{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 cr(t){return t.indexOf("i3s:mesh")>=0}const hr="i3s:mesh:".length;function ur(t,e,n,r,s){const i=e.layerScene.eslpk,o=function(t,e){const n=e.substring(hr);return t>=1.7?parseInt(n):n}(e.version,t),a=e[o],c=e.layerScene.baseUrl,h=[];let u=!1;const l=or;let f,d;if(e.version<=1.6){if(!a.geometryData)return null;const t=a.geometryData.length;if(!t)return null;let n=c+`/nodes/${a.id}/`+a.geometryData[t-1].href;i&&(n+=".bin");const r={geometry:{url:n,info:e.layerScene.store.defaultGeometrySchema}};let s=a.textureData&&a.textureData[0]&&a.textureData[0].href;if(s){const t=e.layerScene.store.textureEncoding[0];let n;n="image/jpeg"===t?"jpg":"png",i&&(s+="."+n);const o={pbrMetallicRoughness:{baseColorTexture:{url:c+`/nodes/${a.id}/`+s,factor:1,format:n,mimeType:t},metallicFactor:0}};r.material=o}h.push(r)}else{f=a.mesh.geometry,d=a.mesh.material;const t=e.layerScene.geometryDefinitions[f.definition],{geometryBuffers:o}=t;u=r&&2===o.length;const l=tr.draco&&u?o[1]:o[0],m=tr.draco&&u?1:0;let p=c+`/nodes/${f.resource}/geometries/`+m;i&&(p+=".bin");const b={geometry:{url:p,info:l}};if(s&&ar&&u&&!tr.draco)throw new Error("Must import @maptalks/transcoder.draco to load i3s draco compressed geometry");const g=e.layerScene.materialDefinitions,y=e.layerScene.textureSetDefinitions;let w,v=0;if(d&&(v=g[d.definition]),g){w=function(t,e,n,r,s,i){const o=JSON.parse(JSON.stringify(t));return function t(e,n,r,s,i,o){for(const a in e)if(e[a]&&e[a].textureSetDefinitionId>=0){const t=n[e[a].textureSetDefinitionId],c="images/"+t.formats[0].format,h=lr(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 mt(e[a])&&t(e[a],n,r,s,i,o)}(o,e,n,r,s,i),o}(v,y,c,d.resource,n,e.layerScene.eslpk)}else w={pbrMetallicRoughness:{metallicFactor:0}};b.material=w,h.push(b)}return{dracoCompression:u,meshes:h,nodeIndex:o,center:a.obb&&a.obb.center||a.mbs&&[a.mbs[0],a.mbs[1],a.mbs[2]],transform:l}}function lr(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&&ir)return t[n]}return null}const fr=new t.Coordinate(0,0),dr=new t.Coordinate(0,0),mr=new Set,pr=[],br=new class{constructor(t,e){this.max=t,this.currentSize=0,this.data=new Map,this.onRemove=e}reset(t){if(this.data){const e=this.data.keys();for(const n of e){const e=this.data.get(n);t&&t!==e.renderer||this.le(n,e)}}return t||(this.data=new Map,this.currentSize=0),this}clear(t){this.reset(t)}add(t,e){if(!e)return this;if(e.node&&e.node.memorySize&&(this.currentSize+=e.node.memorySize),this.has(t)){const n=this.data.get(t);n&&n.node&&n.node.memorySize&&(this.currentSize-=n.node.memorySize),this.data.delete(t),this.data.set(t,e)}else this.data.set(t,e);return this}shrink(){if(this.currentSize>this.max){let t=!1;const e=this.data.keys();let n=e.next();for(;this.currentSize>this.max&&void 0!==n.value;){!t&&this.data.get(n.value).current&&(t=!0,console.warn(`current maxGPUMemory(${this.max/1024/1024}) for Geo3DTilesLayer is not enough, one or more current tiles will be discarded.`));const r=this.getAndRemove(n.value);r&&this.onRemove(r),n=e.next()}}}has(t){return this.data.has(t)}keys(){const t=new Array(this.data.size);let e=0;const n=this.data.keys();for(const r of n)t[e++]=r;return t}getAndRemove(t){if(!this.has(t))return null;const e=this.data.get(t);return e.node&&e.node.memorySize&&(this.currentSize-=e.node.memorySize),this.data.delete(t),e}get(t){if(!this.has(t))return null;const e=this.data.get(t);return this.data.delete(t),this.data.set(t,e),e}remove(t){if(!this.has(t))return this;const e=this.data.get(t);return this.le(t,e),this}le(t,e){e.node&&e.node.memorySize&&(this.currentSize-=e.node.memorySize),this.data.delete(t),this.onRemove(e)}setMaxSize(t){return this.max=t,this.shrink(),this}getMemorySize(){let t=0;const e=this.data.values();for(const n of e){const e=n&&n.node;e&&e.memorySize&&(t+=e.memorySize)}return t}markAll(t,e){const n=this.data.values();for(const r of n)t&&r.renderer!==t||(r.current=e)}}(1024*(t.Browser.mobile?32:1024)*1024,t=>{const e=t.renderer;delete t.renderer,e.deleteTile(t)});let gr=0;class yr extends(h(t.renderer.CanvasRenderer)){constructor(t){super(t);const e=1024*t.options.maxGPUMemory*1024;e>br.max&&br.setMaxSize(e),this.tileCache=br,gr++,this.prepareWorker(),this.tilesLoading={},this.fe={},this.de=[],this.Yt=this.me.bind(this)}getAnalysisMeshes(){if(!this.painter)return pr;const t=this.painter.getPaintedMeshes();if(!t)return pr;const e=[],{b3dmMeshes:n,pntsMeshes:r,i3dmMeshes:s}=t;return n.length&&It(e,n),r.length&&It(e,r),s.length&&It(e,s),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.de.length||super.needToRedraw())}getFrameTimestamp(){return this.pe}drawOnInteracting(t,e,n){this.draw(e,n)}draw(t,e){this.pe=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.be(),this.ge();const{selectedTiles:o,leaves:a,requests:c}=this.ye(r,s);c.length&&this.loadTiles(c),this.we(o,a,e),this.ve(),c.length||this.completeRender()}ye(t,e){const n=this.layer.getRootTiles();let r=[];this.Te();let s=0;const i=this.Oe(),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 l=!1;const f=this.getCachedTile(h.id);if(this._e(h.id)?(s++,l=c=!0,this.tilesLoading[h.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=c=!0),(!i.node.Me||u.isS3M||!i.node.children||i.node.Me<=500)&&(a=!0,i.selected=!0,i.data=f)):this.painter.has(h)||(l=c=!0,r.push(h)),!l)continue;if(this.xe(i))a=!0;else{this.Ae(i).length&&(a=!0)}}let h=[],u={};if(a&&({selectedTiles:h,leaves:u}=this.Ie(t)),r.length>1&&(r.sort(wr),i)){const t=i-s;r=t>0?r.slice(0,t):[]}return{loading:c,requests:r,selectedTiles:h,leaves:u}}Ie(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.Se===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.Se=s.length}for(let t=0;t<o.length;t++)s.push(o[t])}return{selectedTiles:e,leaves:n}}xe(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}Ae(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const n=t.W+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.Ee(s[i],t);n.selected=!0,n.data=this.tileCache.get(o),t.children.push(n),e.push(n)}else s[i].W<=n&&r.push(s[i])}}return e}we(t,e,n){this.tileCache.markAll(this,!1);for(let e=0,n=t.length;e<n;e++){const n=t[e].data;n.current=!0,n.renderer=this,this.tileCache.add(t[e].node.id,n)}this.tileCache.shrink();const r={tiles:t,leaves:e};this.onDrawTileStart(r);const s=this.painter.paint(t,e,n);this.onDrawTileEnd(r),s&&this.layer.fire("canvasisdirty",{renderCount:s})}onDrawTileStart(){}onDrawTileEnd(){}loadTiles(t){for(let e=0,n=t.length;e<n;e++){const n=t[e];this.tilesLoading[n.id]={current:!0,node:n},this.loadTile(n)}}loadTile(t){let e=t.content.url;if(xt(e)){const n=At(e);return this.Ne(e,n,t),null}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const n=t.V,r=this.Ce[n];return new rr(e,n,r,this.layer,this.Yt).load().then(n=>{this.onTilesetLoad(n,t,e)})}return t&&Ct(e)&&!cr(e)&&(e=t.baseUrl+e),this.Ne(e,null,t),null}Ne(t,e,r){let s=this.Pe;s||(s=n.Util.getSupportedFormats(this.gl.gl||this.gl),this.Pe=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:this.layer.getTileUrl(t,r.baseUrl,this.layer.Re[r.V]),arraybuffer:e,rootIdx:r.V,upAxis:r.It,transform:r.matrix,supportedFormats:s};if(cr(t)){const e=this.Ce[r.V];if(o.projection=e.projection,o.i3sInfo=ur(t,e,this.regl,this.layer.options.enableI3SCompressedGeometry,this.layer.options.forceI3SCompressedGeometry),!o.i3sInfo)return void this.onTileError({status:404},r,t)}o.service=ft({},i),i.offset&&delete o.service.offset,o.referrer=window&&window.location.href,this.workerConn.loadTile(this.layer.getId(),o,(e,n)=>{if(e)return void this.onTileError(e,r,t);const{magic:s}=n;"b3dm"===s||"pnts"===s||"i3dm"===s||"cmpt"===s||"gltf"===s?(this.de.push({data:n,tile:r}),i.debugShowBoundingVolume&&this.painter.kt(r)):this.onTilesetLoad(n,r,t)})}ge(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let n=0;for(;this.de.length&&(n<e||!t.isInteracting());){const{data:t,tile:e}=this.de.shift(),{magic:r}=t;"b3dm"===r||"gltf"===r?this.painter.createB3DMMesh(t,e.id,e,(n,{mesh:r})=>{this.Le(t,e,n,r)}):"pnts"===r?this.painter.createPntsMesh(t,e.id,e,(n,{mesh:r})=>{this.Le(t,e,n,r)}):"i3dm"===r?this.painter.createI3DMMesh(t,e.id,e,(n,{mesh:r})=>{this.Le(t,e,n,r)}):"cmpt"===r&&this.painter.createCMPTMesh(t,e.id,e,(n,{mesh:r})=>{this.Le(t,e,n,r)}),n++}}Le(t,e,n,r){if(n)this.onTileError(n,e);else{const n=this.ke(r);e.memorySize=n,this.onTileLoad(t,e)}}ke(t){let e=0;if(Array.isArray(t))for(let n=0;n<t.length;n++)t[n]&&(e+=this.ke(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.Be(e),this.setToRedraw(),this.layer.fire("tileload",{node:e}))}onTilesetLoad(t,e,n){this.layer&&(this.layer.zt=t.extensions&&t.extensions["s3m:VertexCompressionType"],t.capabilities||t.layers&&t.layers[0]&&t.layers[0].capabilities?this.Ue(t,e,n):(delete this.tilesLoading[e.id],this.layer.onTilesetLoad(t,e,n)))}onTileError(t,e,n){if(!this.layer)return;const r=n||e.content.url,s=t&&t.message||t;mr.has(s)||(console.warn("failed to load 3d tile: "+r),console.warn(t),mr.add(s)),delete this.tilesLoading[e.id],this.Fe(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}Fe(e,n){const r={loadTime:t.Util.now(),current:!0,error:n,node:e};r.renderer=this,this.tileCache.add(e.id,r)}Be(e){const n={loadTime:t.Util.now(),current:!0,node:e};n.renderer=this,this.tileCache.add(e.id,n)}abortTileLoading(t){if(!t||!this.workerConn)return;const e=t.node.content.url;this.workerConn.abortTileLoading(this.layer.getId(),e),delete this.fe[e]}Te(){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.De(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 Kn(this.regl,t),this.layer.ze(),this.layer.fire("contextcreate",{regl:this.regl})}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new Lt("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let n=this.layer.options||{};n=ft({},n),delete n.offset;const r=t.options.spatialReference;n.projection=r&&r.coordType||r&&r.projection||t.getSpatialReference().getProjection().code;const s=this.layer.getId();e.addLayer(s,n,t=>{if(t)throw t;this.layer&&(this.ready=!0,this.layer.fire("workerready"))})}onRemove(){this.painter&&this.painter.remove(),this.pickingFBO&&(this.canvas.pickingFBO||this.pickingFBO.destroy(),delete this.pickingFBO),this.workerConn&&(this.workerConn.removeLayer(this.layer.getId(),t=>{if(t)throw t}),this.workerConn.remove(),delete this.workerConn),gr--,gr||br.reset(),this.clear(),delete this.tileCache,super.onRemove()}clear(){this.ve(!0),this.tileCache.reset(this),this.tilesLoading={},super.clear()}clearCanvas(){this.regl&&this.regl.clear({color:[0,0,0,0],depth:1,stencil:0}),super.clearCanvas()}getTileOpacity(){return 1}getStencilValue(){return 0}ve(t){this.je||(this.je=Date.now());const e=Date.now();if(!t&&e-this.je<this.layer.options.retireInterval)return;this.je=e;const n=[];for(const e in this.tilesLoading){const r=this.tilesLoading[e];!t&&r.current||(n.push(e),this.abortTileLoading(r))}for(let t=0;t<n.length;t++)delete this.tilesLoading[n[t]]}Oe(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}De(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}_e(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 ge(t,e,0,n)}be(){if(!this.Ge)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const n=[];for(const r in this.Ge){const s=this.Ge[r];if("pending"===s.status)continue;s.status="pending";const i=s.rootIdx,o=Pt(this.layer.H(i).fetchOptions);if(n.push(b.getJSON(r,o).then(t=>{delete this.Ge[r];const e=this.Ce[i];if(e){t.nodes?er(e,t.nodes):(e[t.id]=t,er(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)}me(t,e,n){this.Ge||(this.Ge={}),this.Ge[e]=this.Ge[e]||[],this.Ge[e].rootIdx=t,this.Ge[e].push(n),this.setToRedraw()}Ue(t,e,n){this.Ce||(this.Ce=[]);const r=e.V;this.Ce[r]||(this.Ce[r]={});const s=this.Ce[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),!t.spatialReference||t.spatialReference.wkid&&4326===t.spatialReference.wkid||console.warn("i3s has a spatialReference other than 4326.",t.spatialReference),s.projection=t.spatialReference,function(t,e,n,r,s,i,o){if(!i.layerScene){i.layerScene=e,i.nodesPerPage=e.nodePages&&e.nodePages.nodesPerPage||64,i.lodSelectionMetricType=e.nodePages&&e.nodePages.lodSelectionMetricType;let t=s;i.layerScene.eslpk=t.indexOf("3dSceneLayer.json")>=0;if(t.endsWith(".json")){const e=s.lastIndexOf("/");t=e<0?"./":s.substring(0,e)}i.layerScene.baseUrl=function(t){return t.split("?")[0]}(t)}return new rr(s,n,i,t,o).load()}(this.layer,t,r,0,n,s,this.Yt).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.Z||(this.Z=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const n=t[e].service||0;let r=this.Z[n];r||(r=this.Z[n]=new Map),r.set(t[e].id,t[e])}else{const e=t.service||0;let n=this.Z[e];n||(n=this.Z[e]=new Map),n.set(t.id,t)}this.painter.showOnly(this.Z)}cancelShowOnly(){delete this.Z,this.painter.cancelShowOnly()}Kt(){return this.painter?this.painter.Kt():[]}ue(t,e){const n=this.getMap();if("identity"===n.getProjection().code.toLowerCase()){const n=this.He();return fr.x=e[0],fr.y=e[1],n.unproject(fr,dr),t[0]=dr.x,t[1]=dr.y,t}return fr.x=e[0],fr.y=e[1],n.getProjection().unproject(fr,dr),t[0]=dr.x,t[1]=dr.y,t}Ve(t,e){const n=this.He();return fr.x=e[0],fr.y=e[1],n.project(fr,dr),t[0]=dr.x,t[1]=dr.y,t}qe(t,e){const n=this.He();return fr.x=e[0],fr.y=e[1],n.unproject(fr,dr),t[0]=dr.x,t[1]=dr.y,t}He(){const e=this.getMap().options.spatialReference.coordType;if(!e)throw new Error("Missing coordType in map spatialReference.");return this.$e||(this.$e=t.SpatialReference.getProjectionInstance(e)),this.$e}}function wr(t,e){return t.bt-e.bt}function vr(t,e,n){return t[0]=e[n],t[1]=e[n+3],t[2]=e[n+6],t}function Tr(t,e,n){return Math.sqrt(function(t,e,n){const r=w.subtract(Or,n,t),s=vr(_r,e,0),i=vr(Mr,e,1),o=vr(xr,e,2),a=w.len(s),c=w.len(i),h=w.len(o);w.normalize(s,s),w.normalize(i,i),w.normalize(o,o);const u=Ar;u[0]=w.dot(r,s),u[1]=w.dot(r,i),u[2]=w.dot(r,o);let l,f=0;u[0]<-a?(l=u[0]+a,f+=l*l):u[0]>a&&(l=u[0]-a,f+=l*l);u[1]<-c?(l=u[1]+c,f+=l*l):u[1]>c&&(l=u[1]-c,f+=l*l);u[2]<-h?(l=u[2]+h,f+=l*l):u[2]>h&&(l=u[2]-h,f+=l*l);return f}(t,e,n))}const Or=[],_r=[],Mr=[],xr=[],Ar=[];const Ir=2*Math.PI;class Sr{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+=Ir,n<0&&(n+=Ir)),(n>s||le(n,s,1e-14))&&(n<i||le(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 Er=[0,0,1];function Nr(t,e){return Zt(e,t[0],t[1],t[2])}class Cr{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 Pr=[],Rr=[],Lr=[],kr=[],Br=[],Ur=[],Fr=[],Dr=[],zr=[],jr=[],Gr=new Cr([1,0,0],0),Hr=[];class Vr{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new Sr(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){let n=0;if(!Sr.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(Hr,t,e),u=i.dot(h,s),l=i.dot(h,o),f=i.subtract(Hr,t,r),d=i.dot(f,a),m=i.dot(f,c);u>0?n+=u*u:d>0&&(n+=d*d),l>0?n+=l*l: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;Nr(Sr.southwest(t,Rr),e.southwestCornerCartesian),Nr(Sr.northeast(t,Rr),e.northeastCornerCartesian),Pr[0]=t.west,Pr[1]=.5*(t.south+t.north),Pr[2]=0;const n=Nr(Pr,Lr),r=i.cross(Br,n,Er);i.normalize(e.westNormal,r),Pr[0]=t.east;const s=Nr(Pr,Dr),o=i.cross(Br,Er,s);i.normalize(e.eastNormal,o);const a=i.subtract(Br,n,s),c=i.normalize(kr,a),h=t.south;let u;if(h>0){Pr[0]=.5*(t.west+t.east),Pr[1]=h;const n=Nr(Pr,zr);i.copy(jr,c);const r=Cr.fromPointNormal(e.southwestCornerCartesian,e.westNormal,Gr);qr(zr,jr,r,e.southwestCornerCartesian),u=ce(n,Ur)}else u=he(Sr.southeast(t,Rr),Ur);const l=i.cross(Fr,u,a);i.normalize(e.southNormal,l);const f=t.north;let d;if(f<0){Pr[0]=.5*(t.west+t.east),Pr[1]=f;const n=Nr(Pr,zr);i.scale(jr,c,-1);const r=Cr.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,Gr);qr(zr,jr,r,e.northeastCornerCartesian),d=ce(n,Ur)}else d=he(Sr.northwest(t,Rr),Ur);const m=i.cross(Fr,a,d);i.normalize(e.northNormal,m)}}function qr(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 $r={"maxGPUMemory":t.Browser.mobile?32:1536,"retireInterval":2e3,"loadingLimitOnInteracting":5,"loadingLimit":10,"renderer":"gl","forceRenderOnZooming":!0,"forceRenderOnRotating":!0,"forceRenderOnMoving":!0,"debug":!1,"meshLimitPerFrame":1,"i3sNodepageLimitPerFrame":1,"enableI3SCompressedGeometry":!0,"forceI3SCompressedGeometry":!0,"picking":!0,"pickingPoint":!0,"geometryEvents":!1,"antialias":!1,"optionalExtensions":["ANGLE_instanced_arrays","OES_element_index_uint","OES_standard_derivatives","OES_vertex_array_object","OES_texture_half_float","OES_texture_half_float_linear","OES_texture_float","OES_texture_float_linear","WEBGL_depth_texture","EXT_shader_texture_lod","WEBGL_compressed_texture_astc","WEBGL_compressed_texture_etc","WEBGL_compressed_texture_etc1","WEBGL_compressed_texture_pvrtc","WEBGL_compressed_texture_s3tc","WEBGL_compressed_texture_s3tc_srgb"],"offset":[0,0]},Xr=new t.Extent(0,0,0,0),Jr=[],Qr=[],Kr=[],Zr=[],Yr=[],Wr=new t.Coordinate(0,0),ts=new t.Point(0,0),es=[],ns=new t.Coordinate(0,0),rs=r.identity([]),ss=[0,0],is=[1,1,1,1,-1,1,-1,-1,1,-1,1,1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1];class os extends(l(t.Layer)){static fromJSON(t){return t&&"Geo3DTilesLayer"===t.type?new os(t.id,t.options):null}constructor(t,e){super(t,e),this.Xe(),this.fe={},this.Bt=[]}Xe(){const t=this.options.services.map(t=>t.url);this.Je=this.Je||{},this.Re=this.Re||[];for(let e=0;e<t.length;e++){const n=t[e];let r=this.Je[n];void 0===r&&(r=this.Je[n]=this.Re.length),this.Re[r]=hs(n,r,this.options.services[e])}this.fire("rootready",{roots:this.Re.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.Xe();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]&&ft(n[t],e),!lt(e.visible)){const r=n[t].url,s=this.Je[r];this.Re&&this.Re[s]&&(this.Re[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.Je[n];this.Re[r]&&(this.Re[r]=null),delete this.Je[n],e.splice(t,1)}const n=this.getRenderer();return n&&n.setToRedraw(),this}getTileUrl(t,e,n){const r=n&&n.service&&n.service.subdomains;if(r&&n.domainKey){const e=r.length;if(e){const s=[...t].reduce((t,e)=>t+e.charCodeAt(),0)%e;return t.replace(n.domainKey,r[s])}}return t}getExtent(e){if(!e&&0!==e){const e=new t.Extent;for(let t=0;t<this.Re.length;t++)if(this.Re[t].boundingVolume){const n=this.boundingVolumeToExtent(this.Re[t]);e._combine(n)}return e}return this.Re[e]&&this.Re[e].boundingVolume?this.boundingVolumeToExtent(this.Re[e]):null}boundingVolumeToExtent(e){const n=e.boundingVolume.Qe?rs:e.matrix,r=this.getMap(),s="identity"===r.getProjection().code.toLowerCase(),o=this.getRenderer();if(e.boundingVolume.region){const n=e.boundingVolume.region;return new t.Extent(gt(n[0]),gt(n[1]),gt(n[2]),gt(n[3]))}if(e.boundingVolume.sphere){const a=e.boundingVolume.sphere,c=re([],i.transformMat4([],a,n));s&&o.Ve(c,c);const h=a[3],u=r.locate(c,-h,h),l=r.locate(c,h,-h);return new t.Extent(u,l)}if(e.boundingVolume.box){const c=e.boundingVolume.box,h=i.transformMat4([],c,n),u=new t.Coordinate(re([],h));s&&o.Ve(u,u);const l=c.slice(3);a.multiply(l,a.fromMat4([],e.matrix),l);const f=i.length(l.slice(0,3)),d=i.length(l.slice(3,6)),m=i.length(l.slice(6,9)),p=Math.max(f,d,m),b=r.locate(u,-p,p),g=r.locate(u,p,-p);return new t.Extent(b,g)}return null}getRootTiles(){return this.Re}getTiles(){const t=this.getRenderer();if(!t.ready)return this.Ke(),{tiles:Yr};const e=this.getMap(),n=e.cameraPosition,r=e.pointAtResToDistance(n[2],0,e.getGLRes()),s=this.Ze(n);this.Ye=this.Ye||[],i.set(this.Ye,bt(s.x),bt(s.y),r),this.We=Zt(this.We||[],this.Ye[0],this.Ye[1],this.Ye[2]),this.tn=2*Math.tan(.5*bt(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const h=[];for(let e=0;e<this.Re.length;e++){const n=this.Re[e];if(!n||!n.visible)continue;let r=1/0;const s=[n],i=this.nn(e);for(;s.length>0;){const e=s.pop();for(e.id||this.rn(e);c.level>=e.W;)c=c.parent;const n=this.sn(e,i,o);if(n<1){let t=c;for(;t&&!t.content;)t=t.parent;0===n&&t&&t.content&&this.in(h,t);if(!1===this.options.services[e.V].alwaysShow)continue;if(!(0===n&&e.W<=r))continue;e.content&&(r=e.W)}e.bt<1/0&&this.an(e);const a=this.Ee(e,c);c.children.push(a);const u=e.children,l=u&&u.length,f=a.content;if(!l&&f&&this.in(h,a),l){f&&"add"===e.refine&&this.in(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].It=e.It,u[i].baseUrl=e.baseUrl;const t=u[i].content&&(u[i].content.url||u[i].content.uri);t&&(xt(t)||t.indexOf("i3s:")>=0?u[i].baseUrl=e.baseUrl:Ct(t)?u[i].content.url=e.baseUrl+t:u[i].baseUrl=t.substring(0,t.lastIndexOf("/")+1))}s.push(u[i])}!r&&f&&this.in(h,a)}}}return{root:a,tiles:h}}in(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 as(n,e);if(n.box)return 0===cs(n,e)}return!1}(this.Ye,this.We,n)||t.push(e)}Ee(t,e){return{id:t.id,node:t,children:[],level:t.W,parent:e,content:t.content&&t.content.url}}rn(e){const n=this.getId();e.id=n+":"+t.Util.GUID(),e.matrix=e.transform||r.identity([]),e.cn=this.hn(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.W&&(e.W=e.parent.W+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.Re[t].service}un(t){const e=t.boundingVolume;if(!e||e.Qe&&!this.ln(t))return;const n=this.H(t.V),s=n.heightOffset||0,o=this.options.offset,a=dt(o)||o[0]||o[1],c=n.coordOffset||ss;if(!Array.isArray(c))throw new Error("service.coordOffset must be an array");if(!e.Qe&&(!t.boundingVolume||!s&&r.exactEquals(t.matrix,rs)&&!a&&c===ss))return;e.box&&e.region&&delete e.region;const{region:h,box:u,sphere:l}=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.dn([gt(t[0]),gt(t[1])]);h[0]=bt(n.x+c[0]),h[1]=bt(n.y+c[1]);const r=this.dn([gt(t[2]),gt(t[3])]);h[2]=bt(r.x+c[0]),h[3]=bt(r.y+c[1]),h[4]=t[4]+s+(c[2]||0),h[5]=t[5]+s+(c[2]||0)}else if(u||l){e.originalVolume||(e.originalVolume=(u||l).slice(0));const n=u||l,r=e.originalVolume,o=i.transformMat4(Jr,r,t.matrix),a=re(Qr,o),h=this.dn([a[0]+c[0],a[1]+c[1]]);a[0]=h.x,a[1]=h.y,a[2]+=s+(c[2]||0),Zt(n,bt(a[0]),bt(a[1]),a[2])}e.Qe=!0}ln(t){const e=t.boundingVolume,n=this.H(t.V),r=n.heightOffset||0,s=n.coordOffset||ss;return e.coordOffset[0]!==s[0]||e.coordOffset[1]!==s[1]||e.heightOffset!==r}hn(t){return void 0===t.geometricError||!t.boundingVolume}an(t){let e=t.parent;for(;e&&e.cn&&!(e.bt<=t.bt);)e.bt=t.bt,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.It||s.upAxis||"Y").toUpperCase();t.root.baseUrl=n.substring(0,n.lastIndexOf("/")+1);const o=n.indexOf("realspace/")>-1;0===e.W&&(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.It=i,e){const n=e.V,s=this.Re[n];c&&!s.isS3M&&(s.isS3M=c);const i=e.boundingVolume;ft(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.mn=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.cn=this.hn(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&&!xt(h)&&Ct(h)&&(e.content.url=e.baseUrl+h),t.root&&!e.parent&&this.pn(e)}this.Ke(),this.fire("loadtileset",{tileset:t,index:e&&e.V,url:n})}sn(t,e,n){if(t.bt=1/0,0===t.W||t.cn)return this.pn(t),1;if(this.un(t),!this.bn(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.gn(t);return 0===s&&t.parent&&(s=.5*(t.parent.Me||0)),s>=r?1:0}Jt(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)}bn(e,n,r){const s=e.id;let i=this.Bt[s]&&this.Bt[s].obbox;const{boundingVolume:o}=e,a=o.region,c=o.box,h=o.sphere;if(!i)if(a)this.Bt[s]=this.yn(e),i=this.Bt[s].bbox,i.center=this.Bt[s].coordCenter;else if(c)this.Bt[s]=this.wn(e),i=this.Bt[s].obbox,i.center=this.Bt[s].coordCenter;else if(h){i=this.Bt[s]=this.vn(e);const n=re(Jr,h),r=new t.Coordinate(n);i.center=r}if(n){if(a)Xr.xmin=i[0][0],Xr.ymin=i[0][1],Xr.xmax=i[1][0],Xr.ymax=i[1][1];else if(h){const t=i[2];Xr.xmin=i[0][0]-t,Xr.ymin=i[0][1]-t,Xr.xmax=i[0][0]+t,Xr.ymax=i[0][1]+t}else if(c){const t=i[1],e=i[2];Xr.xmin=i[0][0]-t,Xr.ymin=i[0][1]-e,Xr.xmax=i[0][0]+t,Xr.ymax=i[0][1]+e}if(!n.intersects(Xr))return!1}return a?f(r,i):h?d(r,i):!!c&&m(r,i)}yn(e){const n=this.getMap(),r=n.getGLRes(),s=e.boundingVolume.region;let{ws:i,en:o}=function(t){const e=t[0],n=t[1],r=t[2],s=t[3],i=t[4],o=t[5],a=Zt([],e,n,i),c=Zt([],r,s,o),h=re(a,a),u=re(c,c);return{ws:h,en:u}}(s);i=new t.Coordinate(i),o=new t.Coordinate(o);const a=n.coordToPointAtRes(i,r);a.z=n.altitudeToPoint(i.z,r);const c=n.coordToPointAtRes(o,r);c.z=n.altitudeToPoint(o.z,r);const h=[c.x,a.y,c.z,c.x,c.y,c.z,a.x,c.y,c.z,a.x,a.y,c.z,c.x,a.y,a.z,c.x,c.y,a.z,a.x,c.y,a.z,a.x,a.y,a.z],u=[(h[0]+h[18])/2,(h[1]+h[19])/2,(h[2]+h[20])/2],l=n.pointAtResToCoord(new t.Point(u),r);l.z=(i.z+o.z)/2;const f=this.lt(e.V).Ut,d=[h.slice(21,24),h.slice(3,6)];if(f)for(let t=0;t<h.length;t+=3)h[t]-=f[0],h[t+1]-=f[1],h[t+2]-=f[2];return{bbox:d,boxPosition:h,pointCenter:u,coordCenter:l}}wn(t){const e=this.getRenderer(),n=this.getMap(),r="identity"===n.getProjection().code.toLowerCase(),s=n.getGLRes(),o=t.boundingVolume.box,a=o.slice(0,3),c=this.Tn(o,t.matrix),h=(l=a,new us((u=c)[0],u[3],u[6],l[0],u[1],u[4],u[7],l[1],u[2],u[5],u[8],l[2],0,0,0,1));var u,l;const f=this.On(t),d=[],m=this.lt(t.V).Ut;ts.set(m[0],m[1]);const p=n.pointAtResToCoord(ts,s),b=Jr;for(let t=0;t<is.length;t+=3){b[0]=is[t],b[1]=is[t+1],b[2]=is[t+2],i.transformMat4(b,b,h),re(b,b),r&&e.Ve(b,b);const o=Wr.set(...b);let a=n.coordToPointAtRes(o,s,ts);a=i.set(b,a.x,a.y,n.altitudeToPoint(o.z,s)),d[t]=a[0]-m[0],d[t+1]=a[1]-m[1],d[t+2]=a[2]-m[2]}return{obbox:this._n(d,m,f),boxPosition:d,boxCenter:f,coordCenter:p}}vn(e){const n=this.getMap(),r=this.getRenderer(),s="identity"===n.getProjection().code.toLowerCase(),i=e.boundingVolume.sphere,o=i;let a=Jr;0===o[0]&&0===o[1]&&0===o[2]?a=[0,0,-6378137]:re(a,o),s&&r.Ve(a,a);const c=new t.Coordinate(a),h=this.Jt(c,ts).toArray();h[2]=n.altitudeToPoint(c.z,n.getGLRes());const u=this.Mn(c);return[h,i[3]*u[2]]}_n(t,e,n){const[r,s,o]=e,a=i.set(Jr,(t[3]+t[12])/2+r,(t[4]+t[13])/2+s,(t[5]+t[14])/2+o),c=i.set(Qr,(t[3]+t[18])/2+r,(t[4]+t[19])/2+s,(t[5]+t[20])/2+o),h=i.set(Kr,(t[3]+t[9])/2+r,(t[4]+t[10])/2+s,(t[5]+t[11])/2+o),u=n.slice(0);return u[3]=a[0]-n[0],u[4]=a[1]-n[1],u[5]=a[2]-n[2],u[6]=c[0]-n[0],u[7]=c[1]-n[1],u[8]=c[2]-n[2],u[9]=h[0]-n[0],u[10]=h[1]-n[1],u[11]=h[2]-n[2],u}On(e){const n=this.getMap(),r=this.getRenderer(),s="identity"===n.getProjection().code.toLowerCase(),i=n.getGLRes(),o=e.boundingVolume.box.slice(0,3);re(o,o),s&&r.Ve(o,o);const a=new t.Coordinate(o),c=n.coordToPointAtRes(a,i);return[c.x,c.y,n.altitudeToPoint(a.z,i)]}pn(t){const e=this.H(t.V);if(!t.boundingVolume||this.xn(t,e))return;const n=t.boundingVolume.box,r=t.boundingVolume.region,s=t.boundingVolume.sphere;let i=null;if(n){i=this.An(t).pointCenter}else if(r){i=this.In(t).pointCenter}else s&&(i=this.vn(t)[0]);const o=e.heightOffset||0,a=e.coordOffset||[0,0];t.Sn=[a[0]||0,a[1]||0],t.dt=o,t.Ut=i}xn(t,e){if(!t.Sn)return!1;const n=e.coordOffset||ss;return t.Sn[0]===n[0]&&t.Sn[1]===n[1]&&t.dt===(e.heightOffset||0)}In(t){if(!t.boundingVolume)return null;this.un(t);return this.yn(t)}An(e){if(!e.boundingVolume)return null;this.un(e);const n=e.boundingVolume.box.slice(0,3);re(n,n);const r=new t.Coordinate(n);return{pointCenter:this.On(e),coordCenter:r}}Tn(t,e){let n=t.slice(3,12);return n=function(t,e,n){const r=t[0]*e[0]+t[3]*e[1]+t[6]*e[2],s=t[1]*e[0]+t[4]*e[1]+t[7]*e[2],i=t[2]*e[0]+t[5]*e[1]+t[8]*e[2],o=t[0]*e[3]+t[3]*e[4]+t[6]*e[5],a=t[1]*e[3]+t[4]*e[4]+t[7]*e[5],c=t[2]*e[3]+t[5]*e[4]+t[8]*e[5],h=t[0]*e[6]+t[3]*e[7]+t[6]*e[8],u=t[1]*e[6]+t[4]*e[7]+t[7]*e[8],l=t[2]*e[6]+t[5]*e[7]+t[8]*e[8];return n[0]=r,n[1]=s,n[2]=i,n[3]=o,n[4]=a,n[5]=c,n[6]=h,n[7]=u,n[8]=l,n}(this.En(e,[]),n,n),n}En(t,e){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[4],e[4]=t[5],e[5]=t[6],e[6]=t[8],e[7]=t[9],e[8]=t[10],e}Mn(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(Zr,n.x/100*1.01,n.y/100*1.01,r),Zr}dn(e){Array.isArray(e)&&(e=new t.Coordinate(e));let n=this.options.offset;if(dt(n)&&(n=n.call(this,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._sub(n),t.pointAtResToCoord(s,r)}return e}lt(t){return this.Re[t]}nn(e){const n=this.H(e).maxExtent;if(!n)return null;const r=this.Re[e];return r.maxExtent||(r.maxExtent=new t.Extent(n).convertTo(t=>this.Jt(t))),r.maxExtent}gn(t){const e=this.tn,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.Nn||(t.Nn=new Vr(t.boundingVolume.region));return t.Nn.distanceToCamera(e,n)}(t,this.We,this.Ye):t.boundingVolume.sphere?s=as(t.boundingVolume,this.We):t.boundingVolume.box&&(s=cs(t.boundingVolume,this.We));const i=Math.max(Math.abs(s),1e-7),o=n*r.height/(i*e);return t.bt=s,t.Me=o,o}Ke(){const t=this.getRenderer();t&&t.setToRedraw()}Ft(t){return this.Bt[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&&It(n,r)}const r=this.getMap(),s=this.getRenderer();if(!r||!s)return[];const i=r.getDevicePixelRatio();return It(n,s.pick(t.x*i,t.y*i,e)),n}getCurrentBatchIDs(){const t=this.getMap(),e=this.getRenderer();return t&&e?e.Kt():[]}highlight(t){const e=this.getRenderer();return e?(e.highlight(t),this):(this.J||(this.J=[]),this.J.push(t),this)}ze(){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.Z||(this.Z=[]),this.Z.push(t),this)}Cn(){if(this.Z){for(let t=0;t<this.Z.length;t++)this.showOnly(this.Z[t]);delete this.Z}}cancelShowOnly(t){const e=this.getRenderer();return e?(e.cancelShowOnly(t),this):this}setServiceOpacity(t,e){const n=this.options.services[t];n&&(n.opacity=e);const r=this.getRenderer();return r?(r.setToRedraw(),this):this}setServiceDebugBoundingVolume(t,e){const n=this.options.services[t];n&&(n.debugShowBoundingVolume=e);const r=this.getRenderer();return r?(r.setToRedraw(),this):this}Ze(t){const e=this.getMap(),n=e.getGLRes();ns.set(t[0],t[1]);const r=e.pointAtResToCoord(ns,n);return"identity"===e.getProjection().code.toLowerCase()?(Qr[0]=r.x,Qr[1]=r.y,this.getRenderer().qe(Jr,Qr),r.set(Jr[0],Jr[1]),r):r}toJSON(){return{"type":this.getJSONType(),"id":this.getId(),"options":this.config()}}}function as(t,e){const n=t.sphere,r=i.dist(n,e),s=t.sphere[3];return r<s?0:r-s}function cs(t,e){const n=t.box;return Tr(i.set(Jr,n[0],n[1],n[2]),a.set(es,n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10],n[11]),e)}function hs(t,e,n){const s=(t=yt(t)).indexOf("{s}")>=0?"{s}":t.indexOf("%7Bs%7D")>=0?"%7Bs%7D":null;return{service:n,visible:lt(n.visible)?1:n.visible,baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:r.identity([]),V:e,W:0,domainKey:s}}function us(t,e,n,r,s,i,o,a,c,h,u,l,f,d,m,p){this[0]=t||0,this[1]=s||0,this[2]=c||0,this[3]=f||0,this[4]=e||0,this[5]=i||0,this[6]=h||0,this[7]=d||0,this[8]=n||0,this[9]=o||0,this[10]=u||0,this[11]=m||0,this[12]=r||0,this[13]=a||0,this[14]=l||0,this[15]=p||0}os.mergeOptions($r),os.registerRenderer("gl",yr),os.registerJSONType("Geo3DTilesLayer");let ls=null;function fs(){return ls||(ls={"image/crn":tr.crn&&tr.crn(),"image/ktx2":tr.ktx2&&tr.ktx2(),"image/cttf":tr.ktx2&&tr.ktx2(),"draco":tr.draco&&tr.draco()}),ls}class ds{constructor(t,e,n){this.Pn=t,this.Rn=e||p,this.Pe=n,this.Ln=fs()}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.kn(t,e,n,r,s)):b.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.kn(t,s,n,r)})}kn(t,e,n,r,s){const i=s&&s.maxTextureSize,o=this.Bn(e,n,r,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.Rn(a,o.glb,{transferable:!0,requestImage:this.Pn,decoders:this.Ln,supportedFormats:this.Pe,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}})}Bn(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported b3dm version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in b3dm header is inconsistent with b3dm's byte length, url: "+r;return console.warn(t),{error:t}}let o,a=s.getUint32(12,!0),c=s.getUint32(16,!0),h=s.getUint32(20,!0),u=s.getUint32(24,!0),l=28+e;h>=570425344?(l-=8,o=a,h=c,u=0,a=0,c=0):u>=570425344&&(l-=4,o=h,h=a,u=c,a=0,c=0);const f=[t];let d,m,p;if(a>0?(d=me(t,l,a),l+=a,o=d.BATCH_LENGTH):d={"BATCH_LENGTH":o},c>0&&(l+=c),h>0&&(m=pe(t,l,h),l+=h,u>0)){const e=be(0,l,u);p=t.slice(e.offset,e.offset+e.byteLength),l+=u,f.push(p)}const b=d.BATCH_LENGTH,g={};if(d&&d.BATCH_ID){g.BATCH_ID=ye(d.BATCH_ID,t,(void 0).offset,b);const e=g.BATCH_ID.array&&g.BATCH_ID.array.buffer;e&&f.indexOf(e)<0&&f.push(e)}return{count:o,transferables:f,featureTable:d,batchTable:m,batchTableBin:p,b3dm:g,glb:{buffer:t,byteOffset:l,byteLength:s.byteLength+s.byteOffset-l}}}Un(){return null}}class ms{constructor(t,e,n,r){this.Pn=t,this.Rn=e||p,this.Pe=n,this.Ln=fs(),this.Fn=r}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.kn(t,e,n,r,s)):b.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.kn(t,s,n,r)})}kn(t,e,n,r,s){return this.Dn(t,e,n,r,s).then(({gltf:s,transferables:i})=>{const o=this.zn(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})})}Dn(t,e,n,r,s){const i=s&&s.maxTextureSize,o={transferable:!0,requestImage:this.Pn,decoders:this.Ln,supportedFormats:this.Pe,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=Tt(new Uint8Array(e,c+n,a.byteLength-c));-1==r.indexOf("://")&&(r=t.substring(0,t.lastIndexOf("/"))+"/"+r);return r.indexOf(".glb")>0?b.getArrayBuffer(r,{}).then(t=>this.jn(r,{buffer:t.data,byteOffset:0},o)):b.getJSON(r,{}).then(t=>this.jn(r,t,o))}{const r={buffer:e,byteOffset:c+n,byteLength:a.byteLength-c};return this.jn(t,r,o)}}jn(t,e,n){const r=t.substring(0,t.lastIndexOf("/")),s=new this.Rn(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}})}zn(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}=Ae(s,32+e,o),l={},f=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;l.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,n=a.QUANTIZED_VOLUME_SCALE,{byteOffset:r}=a.POSITION_QUANTIZED;l.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.Gn(new Uint16Array(t,r+c.offset,3*f),e,n)},o.push(l.POSITION.array.buffer)}if(a.BATCH_ID){l.BATCH_ID=ye(a.BATCH_ID,t,c.offset,f);const e=l.BATCH_ID.array&&l.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;l.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,l.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;l.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.Hn(new Uint16Array(t,e+c.offset,2*f))},o.push(l.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,l.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.Hn(new Uint16Array(t,e+c.offset,2*f))},o.push(l.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;l.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,f).slice()},o.push(l.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;l.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.SCALE_NON_UNIFORM.array.buffer)}return{count:f,batchTable:h,batchTableBin:u,featureTable:a,i3dm:l,transferables:o}}Hn(t){const e=t.length/2,n=new Float32Array(3*e),r=[];for(let s=0;s<e;s++)ps(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}Gn(t,e,n){return xe(new Float32Array(t.length),t,e,n)}Un(){return null}}function ps(t,e,n,r){if(t[0]=bs(e,r),t[1]=bs(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]))*gs(e),t[1]=(1-Math.abs(e))*gs(t[1])}return w.normalize(t,t)}function bs(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 gs(t){return t<0?-1:1}class ys{constructor(){}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.kn(t,e,n,r)):b.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.kn(t,s,n,r)})}kn(t,e,n,r){return this.Vn(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})}Vn(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}=Ae(s,e+28,o),l=a.QUANTIZED_VOLUME_OFFSET,f=a.QUANTIZED_VOLUME_SCALE,d=a.POINTS_LENGTH;let m,p={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){p=a.extensions["3DTILES_draco_point_compression"],m=new DataView(t,p.byteOffset+c.offset,p.byteLength);const e={attributes:p.properties,useUniqueIDs:!1};return this.qn||(this.qn=fs().draco),this.qn(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.$n(t,e.attributes,c.offset,d,o,l,f);if(e.attributes.BATCH_ID){const t=e.attributes.BATCH_ID.array;r.BATCH_ID={byteStride:0,byteOffset:0,itemSize:1,count:t.length,componentType:Me(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?r.BATCH_ID=ye(a.BATCH_ID,t,c.offset,d):r.BATCH_ID=ws(d);const e=r.BATCH_ID.array&&r.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return{count:d,batchTable:h,batchTableBin:u,featureTable:a,pnts:r,transferables:o}})}const b=this.$n(t,a,c.offset,d,o,l,f);if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?b.BATCH_ID=ye(a.BATCH_ID,t,c.offset,d):b.BATCH_ID=ws(d);const e=b.BATCH_ID.array&&b.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:d,batchTable:h,batchTableBin:u,featureTable:a,pnts:b,transferables:o})}$n(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.Gn(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}Gn(t,e,n){return xe(new Float32Array(t.length),t,e,n)}Un(){return null}}function ws(t){const e=Mt(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:Me(e),array:n}}class vs{constructor(t,e,n,r){this.Pe=n,this.Pn=t,this.Rn=e||p,this.Fn=r}load(t,e,n=0,r=0,s){return e?this.kn(t,e,n,r,s):b.getArrayBuffer(t,{}).then(e=>{const s=e.data;return this.kn(t,s,n,r)})}kn(t,e,n,r,s){r||(r=e.byteLength);const i=this.Xn(e,t,n,r),o=[];for(let n=0;n<i.length;n++){let r;if("b3dm"===i[n].magic)r=new ds(this.Pn,this.Rn,this.Pe);else if("i3dm"===i[n].magic)r=new ms(this.Pn,this.Rn,this.Pe,this.Fn);else if("pnts"===i[n].magic)r=new ys;else{if("cmpt"!==i[n].magic){console.warn("Unsupported magic in CMPT tile:",i[n].magic);continue}r=new vs(this.Pn,this.Rn,this.Pe,this.Fn)}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}))}Xn(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=fe(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);t.registerWorkerAdapter("@maptalks/3dtiles",n)}else t.registerWorkerAdapter("@maptalks/3dtiles",(function(){return e.transcoders.inject(T)}))}else t.registerWorkerAdapter("@maptalks/3dtiles",T);export{ds as B3DMLoader,vs as CMPTLoader,os as Geo3DTilesLayer,Nt as Geo3DTilesUtil,ue as Geo3DTransform};"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.95.7");
11
+ */(100,1),Jn=[0,0,0,1],Qn=[1,1,1];class Kn{constructor(e,r){this.s=r,this.i=r.getRenderer().canvas,this.pickingFBO=r.getRenderer().pickingFBO,this.o=new t.SpatialReference,this.h=e,this.u=new n.Renderer(e),this.m={},this.p={},this.v={},this.T={},this.O={},this._={},this.M=new n.Scene,this.A=new n.Scene,this.I=new n.Scene,this.S=new n.Scene,this.N=new n.ResourceLoader(e.texture(2)),this.C=this.P.bind(this),this.R=new n.PhongMaterial({"baseColorFactor":[1,1,1,1]}),this.L(),this.k=new n.KHRTechniquesWebglManager(this.h,this.B(),this.N);const s=this.getMap();s.altitudeToPoint&&(this.U=s.altitudeToPoint(100,s.getGLRes())/100)}getI3DMMeshes(){return this.T}getPNTSMeshes(){return this.v}getB3DMMeshes(){return this.p}getPaintedMeshes(){return this.F}getMap(){return this.s.getMap()}paint(t,e,n){const i=n&&n.renderTarget,o=n&&n.sceneFilter,a=this.getMap();if(!t.length||!a)return null;const c=this.D(),h=a.projViewMatrix,u=[],l=[],d=[],m=[],p=[],b=this.j(t),g=[];for(let i=0,o=t.length;i<o;i++){const o=t[i].data.node;let a=this.G(o);if(!a)continue;const c=this.s.H(o.V);o.q&&c.debugShowBoundingVolume&&g.push(o.q);const y=c.heightOffset||0,w=c.coordOffset||In;this.O[o.id]&&(a=this.O[o.id],a=_t(a));let v=c.polygonOffset||Tn;dt(v)&&(v=v()),Array.isArray(a)||(u[0]=a,a=u);for(let t=0,i=a.length;t<i;t++){const i=a[t].properties.magic;if(a[t].properties.heightOffset===y&&a[t].properties.coordOffset[0]===w[0]&&a[t].properties.coordOffset[1]===w[1]||(this.$(a[t]),a[t].X=r.copy([],a[t].localTransform)),"b3dm"===i){if(a[t].getBoundingBox&&!f(h,a[t].getBoundingBox()))continue;const{batchIdData:e,batchIdMap:r}=a[t].geometry.properties;if(e&&r){const e=a[t].properties.node.V;this.J&&this.J[e]?s.highlightMesh(this.h,a[t],this.J[e],this.K,r):this.J&&this.J[e]||s.highlightMesh(this.h,a[t],null,this.K,r),s.showOnly(this.h,a[t],this.Z&&this.Z[e],this.Y,r)}n&&n.bloom&&a[t].properties.hlBloomMesh&&(a[t].properties.hlBloomMesh.properties.depthFunc="always",a[t].properties.hlBloomMesh.properties.polygonOffset=v,d.push(a[t].properties.hlBloomMesh)),d.push(a[t])}else"pnts"===i?m.push(a[t]):"i3dm"===i&&p.push(a[t]);a[t].properties.isLeaf=!!e[o.id],a[t].properties.level=b.get(o.W),a[t].properties.polygonOffset=v,a[t].tt=o,e[o.id]||l.push(a[t]),this.et(a[t]),this.nt(a[t],o)}}let y=0;const w=this.k.getExcludeFilter();y+=this.rt(this.st,c,[o,Sn,w],i,l,d,p),y+=this.rt(this.it,c,[o,En,w],i,l,d,p),this.k.forEachShader((t,e,n)=>{const r=this.D(n);y+=this.rt(t,r,[o,e],i,l,d,p)}),this.A.setMeshes(m);const v=this.ot();return y+=this.u.render(this.ct,v,this.A,i&&i.fbo),this.F={pntsMeshes:m,i3dmMeshes:p,b3dmMeshes:d},g.forEach(t=>{this.ht(t)}),this.S.setMeshes(g),this.u.render(this.ut,c,this.S,i&&i.fbo),y}ht(t){const e=t.properties.node,n=this.s.H(e.V),s=this.s.lt(e.V),a=n.heightOffset||0,c=this.ft(),h=s.dt,u=i.set(Hn,0,0,c*(a-h));let l=n.rotation||[0,0,0];l=o.fromEuler(zn,l[0],l[1],l[2]);const f=n.scale||[1,1,1],d=r.fromRotationTranslationScale(Dn,l,u,f);r.multiply(t.localTransform,t.X,d)}rt(t,e,n,r,s,i,o){t.filter=n.filter(t=>!!t),e.debug=!1,e.debug=!1;let a=0;return this.M.setMeshes(i),a+=this.u.render(t,e,this.M,r&&r.fbo),this.I.setMeshes(o),a+=this.u.render(t,e,this.I,r&&r.fbo),a}pt(t,e){return e.tt.bt-t.tt.bt}deleteTile(t){const e=t.node;e.q&&(e.q.geometry.dispose(),e.q.dispose(),delete e.q);const n=e.id;this.gt(n)}gt(t){const e=this.p[t]||this.v[t]||this.T[t]||this.O[t]||this.m[t];this.O[t]?this.yt(t):e&&(this.wt(e),delete this.p[t],delete this.v[t],delete this.T[t],delete this.m[t])}yt(t){let e=this.O[t];e=_t(e);for(let t=0;t<e.length;t++){const{id:n}=e[t].properties;this.gt(n)}delete this.O[t]}wt(t){if(Array.isArray(t))for(let e=0,n=t.length;e<n;e++)this.wt(t[e]);else{s.showOnly(this.h,t),s.highlightMesh(this.h,t);const e=t.geometry.properties.url;if(e){const n=this._[e];n&&n.refMeshes&&(n.refMeshes.delete(t.uuid),n.refMeshes.size||(n.geometry.dispose(),n.material.dispose(),delete this._[e]))}else t.geometry.dispose(),t.material&&t.material.dispose();t.dispose()}}remove(){const t=this.s;yn(t.getRenderer().canvas,t.getMap());for(const t in this.O)this.yt(t);this.O={};for(const t in this.p)this.gt(t);this.p={};for(const t in this.v)this.gt(t);this.v={};for(const t in this.T)this.gt(t);this.T={};for(const t in this.m)this.gt(t);this.m={},this.st&&(this.st.dispose(),delete this.st),this.it&&(this.it.dispose(),delete this.it),this.ct&&(this.ct.dispose(),delete this.ct),this.ut&&(this.ut.dispose(),delete this.ut),this.k.dispose(),this.picking&&this.picking.dispose()}G(t){return this.p[t.id]||this.v[t.id]||this.T[t.id]||this.O[t.id]}has(t){return this.G(t)||this.m[t.id]}$(t){const e=t.properties.magic;"b3dm"===e?this.vt(t):"i3dm"===e?this.Tt(t):"pnts"===e&&this.Ot(t)}createPntsMesh(t,e,s,i){if(this.v[e]){const t=this.v[e];return console.warn(`pnts mesh with id(${e}) was already created.`),i(null,{id:e,mesh:t}),t}const{pnts:o,featureTable:a,rootIdx:c,compressed_int16_params:h}=t,u=a.POINTS_LENGTH;o.BATCH_ID||(o.BATCH_ID=new Uint8Array(u),o.BATCH_ID.fill(0));const l=new n.Geometry(o,null,u,{static:!0,primitive:"points",positionAttribute:"POSITION",pickingIdAttribute:"BATCH_ID"});l.generateBuffers(this.h);const f={};o.POSITION?f.HAS_POSITION=1:o.POSITION_QUANTIZED&&(f.HAS_POSITION_QUANTIZED=1),o.RGB?f.HAS_RGB=1:o.RGBA?f.HAS_RGBA=1:o.RGB565&&(f.HAS_RGB565=1),(o.NORMAL||o.NORMAL_OCT16P)&&(f.HAS_NORMAL=1,o.NORMAL_OCT16P&&(f.HAS_NORMAL_OCT16P=1)),this._t(f,h),t.featureTable.CONSTANT_RGBA&&(t.featureTable.CONSTANT_RGBA=t.featureTable.CONSTANT_RGBA.map(t=>t/255));const{rtcCenter:d,rtcCoord:m,projCenter:p}=t,b=this.s.H(c),g=new n.Mesh(l);g.properties.magic="pnts",g.properties.id=e,g.properties.node=s,g.properties.count=u,g.properties.batchTable=t.batchTable,g.properties.batchTableBin=t.batchTableBin,g.properties.serviceIndex=c,g.properties.rtcCoord=m,g.properties.rtcCenter=d,g.properties.projCenter=p,g.setDefines(f),Object.defineProperty(g.uniforms,"pointColor",{enumerable:!0,get:function(){return t.featureTable.CONSTANT_RGBA?t.featureTable.CONSTANT_RGBA:b&&b.pointColor||[1,1,1,1]}});const y=this.getMap();let w=null,v=null;Object.defineProperty(g.uniforms,"pointSize",{enumerable:!0,get:function(){if(!b)return 2;if(on(b.pointSize)){const t=JSON.stringify(b.pointSize);t!==w&&(v=an(b.pointSize),w=t);return v(y.getZoom())}return b.pointSize||2}});let T=null,O=null;return Object.defineProperty(g.uniforms,"pointOpacity",{enumerable:!0,get:function(){if(!b)return 1;if(on(b.pointOpacity)){const t=JSON.stringify(b.pointOpacity);t!==T&&(O=an(b.pointOpacity),T=t);return O(y.getZoom())}return b.pointOpacity||1}}),this.Mt(g,h),this.Ot(g),g.X=r.copy([],g.localTransform),this.v[e]=g,i(null,{id:e,mesh:[g]}),[g]}Ot(t){const e=t.localTransform||[],{rtcCoord:n,node:r,projCenter:s}=t.properties;this.xt(e,n,s,r.V),t.setLocalTransform(e)}createI3DMMesh(t,e,s,a){if(this.T[e]){const t=this.T[e];return console.warn(`i3dm mesh with id(${e}) was already created.`),this.m[e]||a(null,{id:e,mesh:t}),t}const c=this.s.H(s.V),h=this.At(s.It),{i3dm:u,featureTable:l,gltf:f,batchTable:d,batchTableBin:m,count:b}=t,g=l.INSTANCES_LENGTH,{rtcCenter:y,rtcCoord:w}=t,v=this.St(Un,w),T=this.Et(Fn,s,y,w);r.multiply(v,T,v);const{POSITION:O,NORMAL_UP:_,NORMAL_RIGHT:M,SCALE:x,SCALE_NON_UNIFORM:A,INSTANCE_ROTATION:I}=u,S={"instance_vectorA":new Float32Array(4*g),"instance_vectorB":new Float32Array(4*g),"instance_vectorC":new Float32Array(4*g),"aPickingId":new Uint16Array(g)};for(let t=0;t<g;t++)S.aPickingId[t]=t;const E=new Float32Array(3),N=new Float32Array(3),C=[],P=new Float32Array(1),R=new Float32Array(3),L=[],k=[],B=[],U=[],F=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)=>{_?(qt(N,M,e),qt(E,_,e),i.cross(C,N,E),i.normalize(C,C),Ot(L,N,0),Ot(L,E,1),Ot(L,C,2),o.fromMat3(k,L)):I?(qt(F,I,e),o.fromMat3(k,F)):o.identity(k),x?(qt(P,x,e),i.set(B,P[0],P[0],P[0])):A?(qt(R,A,e),i.set(B,...R)):i.set(B,1,1,1),r.fromRotationTranslationScale(U,k,t,B),$t(S.instance_vectorA,e,U,0),$t(S.instance_vectorB,e,U,1),$t(S.instance_vectorC,e,U,2)});const D={};for(const t in S)D[t]={buffer:this.h.buffer({dimension:S[t].length/g,data:S[t]}),divisor:1};const z=c.shader||"pbr";let j=0,G=!0;const H=[],V=[];return Ut(f,(t,i,o,a)=>{const c=this.Nt(t,i,o,a,s,!0,z,V),{geometry:u,material:l}=c;l&&!l.isReady()&&(G=!1,j++);const f=new n.InstancedMesh(D,g,u,l);c.refMeshes||(c.refMeshes=new Set,c.refMeshes.add(f.uuid)),f.properties.magic="i3dm",f.properties.id=e,f.properties.count=b,f.properties.batchTable=d,f.properties.batchTableBin=m,f.properties.serviceIndex=s.V,f.properties.rtcCoord=w,f.properties.rtcCenter=y,f.properties.node=s;const p=this.Ct(t,u,l,s.V,a);t.compressed_int16_params&&this.Mt(f,t.compressed_int16_params),this.Pt(f,t.attributes);const T=r.identity([]);if(t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)r.multiply(T,T,t.matrices[e]);r.multiply(T,h,T),f.setPositionMatrix(T),this.Tt(f,v),f.setDefines(p),f.properties.polygonOffset={offset:0,factor:0},H.push(f),delete t.attributes,f.X=r.copy([],f.localTransform)}),Zn(V),G?(this.T[e]=H,a(null,{id:e,mesh:H})):(this.m[e]={meshes:H,count:j},H.Rt=a),H}Tt(t,e){const{rtcCenter:n,rtcCoord:s,node:i}=t.properties;if(!e){e=this.St(Un,s);const t=this.Et(Fn,i,n,s);r.multiply(e,t,e)}const o=this.s.H(i.V),a=t.localTransform||[];if(o.coordOffset){const t=this.Lt(Fn,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)||In}createB3DMMesh(e,s,i,o){if(e.gltf&&(e.gltf.transferables=null),this.p[s]||this.m[s]){const t=this.p[s];return console.warn(`mesh with id(${s}) was already created.`),this.m[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:l}=c.extensions.CESIUM_RTC,f=c.asset.sharePosition,d=this.At(i.It);let m;m=f?this.St(Un,u):this.xt(Un,u,h,i.V);const p=this.s.H(i.V);let b=p.shader||"pbr";if(p.unlit)b="phong";else 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){b="phong";break}const g=[],y=[];let w=0,v=!0;return Ut(c,(t,o,c,T)=>{const O=this.Nt(t,o,c,T,i,!1,b,g),{geometry:_,material:M}=O;M&&!M.isReady()&&(v=!1,w++);const x=new n.Mesh(_,M);O.refMeshes||(O.refMeshes=new Set,O.refMeshes.add(x.uuid)),x.properties.magic="b3dm",x.properties.id=s,x.properties.node=i,e.batchTable&&(x.properties.batchTable=e.batchTable,x.properties.batchTableBin=e.batchTableBin),x.properties.count=e.featureTable&&e.featureTable.BATCH_LENGTH||0,x.properties.serviceIndex=i.V;const A=this.Ct(t,_,M,i.V,T);x.setDefines(A);const I=t.compressUniforms;if(I)for(const t in I)x.setUniform(t,I[t]);t.compressed_int16_params&&this.Mt(x,t.compressed_int16_params),this.Pt(x,t.attributes),a&&(A.USE_MAX_EXTENT=1,x.setUniform("maxPrjExtent",a)),Object.prototype.hasOwnProperty.call(x.uniforms,"polygonOpacity")||Object.defineProperty(x.uniforms,"polygonOpacity",{enumerable:!0,get:function(){return pt(p.opacity)?p.opacity:1}}),Object.prototype.hasOwnProperty.call(x.uniforms,"polygonFill")||Object.defineProperty(x.uniforms,"polygonFill",{enumerable:!0,get:function(){return Et([],p.polygonFill||On)}}),Object.prototype.hasOwnProperty.call(x.material.uniforms,"hsv")||Object.defineProperty(x.material.uniforms,"hsv",{enumerable:!0,get:function(){return p.hsv||_n}});const S=r.identity([]);if(f&&t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)r.multiply(S,S,t.matrices[e]);f&&r.multiply(S,d,S),x.properties.node=i,x.properties.projCenter=h,x.properties.nodeMatrix=S,x.properties.isSharedPosition=f,x.properties.rtcCoord=u,x.properties.rtcCenter=l,this.vt(x,m),y.push(x),delete t.attributes,x.X=r.copy([],x.localTransform)}),Zn(g),v?(this.p[s]=y,o(null,{id:s,mesh:y})):(this.m[s]={meshes:y,count:w},y.Rt=o),y}kt(t){const e=this.s.Bt[t.id];if(!e)return;let s,i,o,a;if(e.length){if(2===e.length){const t=e[0],n=e[1];s=Xn.vertices,i=Xn.indices,o=t,a=[n,n,n]}}else{s=e.boxPosition,i=$n;o=this.s.lt(t.V).Ut,a=Qn}const c=new n.Geometry({POSITION:s},i,0,{primitive:"lines",positionAttribute:"POSITION"}),h=new n.Mesh(c,new n.Material({lineColor:[.8,.8,.1,1],lineOpacity:1})),u=r.identity([]);r.fromRotationTranslationScale(u,Jn,o,a),h.localTransform=u,h.X=r.copy([],u),h.properties.node=t,t.q=h}Mt(t,e){e.POSITION&&t.setUniform("compressedPositionRange",e.POSITION),e.TEXCOORD_0&&t.setUniform("compressedTexcoordRange_0",e.TEXCOORD_0),e.TEXCOORD_1&&t.setUniform("compressedTexcoordRange_1",e.TEXCOORD_0),e.NORMAL&&t.setUniform("compressedNormalRange",e.NORMAL),e.TANGENT&&t.setUniform("compressedTangentRange",e.TANGENT),e.compressed_ratio&&t.setUniform("compressed_ratio",e.compressed_ratio)}vt(t,e){const{isSharedPosition:n,rtcCoord:s,rtcCenter:i,projCenter:o,nodeMatrix:a,node:c}=t.properties;e||(e=n?this.St(Un,s):this.xt(Un,s,o,c.V));const h=t.localTransform||r.identity([]);if(n){const t=this.Et(Fn,c,i,s);r.multiply(h,e,a),r.multiply(h,t,h)}else r.multiply(h,e,a);const u=this.s.H(c.V);if(u.coordOffset){const t=this.Lt(Fn,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)||In}Pt(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)}}Et(e,n,s,o){const a=this.getMap(),c=this.s.H(n.V).heightOffset||0,h=new t.Coordinate(o);let u;u=a.altitudeToPoint?this.U:a.distanceToPointAtRes(100,100,a.getGLRes(),h).y/100;const l=n.matrix?r.copy(e,n.matrix):r.identity(e);if(s){ke(l,i.transformMat4(Nn,s,l),l)}const f=function(t,e,n,r,s,i,o){e=w.copy(Ue,e);const a=Zt(Ue,e[0]*$e,e[1]*$e,e[2]),c=y.getTranslation(Fe,n),h=r.ellipsoid;let u;u=0===w.len(c)?w.set(De,0,0,-6378137):re(De,c),Ve.x=u[0],Ve.y=u[1];const l=r.project(Ve,qe);ze[0]=l.x/s,ze[1]=l.y/s,ze[2]=(u[2]+o)*i;const f=Be(a,h,je),d=function(t,e,n){const r=t[0],s=t[1],i=t[2],o=t[4],a=t[5],c=t[6],h=t[8],u=t[9],l=t[10],f=e[0],d=e[1],m=e[2],p=e[3],b=e[4],g=e[5],y=e[6],w=e[7],v=e[8],T=r*f+o*d+h*m,O=s*f+a*d+u*m,_=i*f+c*d+l*m,M=r*p+o*b+h*g,x=s*p+a*b+u*g,A=i*p+c*b+l*g,I=r*y+o*w+h*v,S=s*y+a*w+u*v,E=i*y+c*w+l*v;return n[0]=T,n[1]=O,n[2]=_,n[3]=0,n[4]=M,n[5]=x,n[6]=A,n[7]=0,n[8]=I,n[9]=S,n[10]=E,n[11]=0,n[12]=t[12],n[13]=t[13],n[14]=t[14],n[15]=t[15],n}(y.invert(Ge,f),v.fromMat4(He,n),t);return ke(t,ze,d),t}(l,o,l,a.getProjection(),a.getGLRes(),u,c),d=function(t,e){return w.set(t,e[12],e[13],e[14]),t}(Bn,f);let m=this.s.options.offset;if(dt(m)){const t=this.s.Ft(n.id).center;m=m.call(this.s,t)}return i.set(kn,m[0],m[1],0),i.sub(d,d,kn),ke(f,d,f),f}Lt(t,e,n){const s=this.s.H(e);if(!s.coordOffset)return null;const o=this.getMap(),a=o.getGLRes();Cn.set(n[0],n[1]);const c=o.coordToPointAtRes(Cn,a,Rn),h=s.coordOffset,u=Cn.set(n[0]+h[0],n[1]+h[1]),l=o.coordToPointAtRes(u,a,Ln),f=l.x-c.x,d=l.y-c.y,m=this.ft(),p=i.set(kn,f,d,(h[2]||0)*m);return r.fromTranslation(t,p)}ft(){const t=this.getMap();let e;return e=t.altitudeToPoint?this.U:t.distanceToPointAtRes(100,100,t.getGLRes(),Cn).y/100,e}createCMPTMesh(t,e,n,r){if(this.O[e]){const t=this.O[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.O[e]=i,r(null,{id:e,mesh:i}),i}Ct(t,e,n,r,s){const i=("phong"===(this.s.H(r).shader||"pbr")?this.st:this.it).getGeometryDefines(e);s.asset&&"S3M"===s.asset.generator&&this.Dt(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.s.zt&&(i.MeshOPT_Compress=1),this.hasIBL()&&(i.HAS_IBL_LIGHTING=1),t.attributes&&t.attributes.TEXCOORD_0&&"WEB3D_quantized_attributes"===t.attributes.TEXCOORD_0.extensions&&(i.HAS_WEB3D_quantized_attributes_TEXCOORD=1),i.HAS_MIN_ALTITUDE=1,i.HAS_LAYER_OPACITY=1,this._t(i,t.compressed_int16_params);return ft(i,t.compressDefines),i}_t(t,e){e&&Object.keys(e).length>0&&(t.HAS_COMPRESSED_INT16=1,e.POSITION&&(t.HAS_COMPRESSED_INT16_POSITION=1),e.TEXCOORD_0&&(t.HAS_COMPRESSED_INT16_TEXCOORD_0=1),e.TEXCOORD_1&&(t.HAS_COMPRESSED_INT16_TEXCOORD_1=1),e.NORMAL&&(t.HAS_COMPRESSED_INT16_NORMAL=1),e.TANGENT&&(t.HAS_COMPRESSED_INT16_TANGENT=1),e.compressed_ratio&&(t.HAS_COMPRESSED_INT16_RATIO=1))}et(t){const e=this.s.getRenderer();e&&e.updateMaskDefines(t)}Dt(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)}Nt(t,e,n,r,s,i,o,a){let c=!1;r.asset&&"S3M"===r.asset.generator&&(c=!0,r.extensions=r.extensions||{});const h=r.url+"-"+e+"-"+n;if(this._[h])return this._[h];let u,l;a.push(t);const f=r.materials&&r.materials[t.material],d=r.extensions&&r.extensions.KHR_techniques_webgl,m=this.s.H(s.V);if(d&&f.extensions&&f.extensions.KHR_techniques_webgl){const e=this.jt(t,r,i,c);u=e.material,l=e.geometry,m.fillEmptyDataInMissingAttribute&&(l.desc.fillEmptyDataInMissingAttribute=!0)}else{l=this.Gt(t,i,qn);const e=m.ambientLight;let n=m.environmentExposure;const s=m.material,c=this.getMap().getLightManager(),h=c&&c.getAmbientLight();if(e&&(!h||h.color)&&void 0===n){const t=h&&h.color?h.color[0]:.2;n=e[0]/t}u=this.Ht(t.material,r,o,s||Mn,n||1,a,m)}u&&Object.defineProperty(u.uniforms,"alphaTest",{enumerable:!0,get:function(){const t=m.alphaTest;return lt(t)?.1:t}}),u&&!u.isReady()?u.Vt=s.id:u||(u=this.R);const p={geometry:l,material:u};return l.properties.url=h,this._[h]=p,p}jt(t,e,n,r){const{geometry:s,material:i}=this.k.createMesh(t,e,n,r);return{geometry:s,material:i}}Gt(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=mn(this.h,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,{static:!0,positionAttribute:r.POSITION,normalAttribute:r.NORMAL,uv0Attribute:r.TEXCOORD_0,uv1Attribute:r.TEXCOORD_1,color0Attribute:r.COLOR_0,tangentAttribute:r.TANGENT,pickingIdAttribute:r._BATCHID,primitive:void 0===t.mode?"triangles":dn(t.mode)});return i&&a&&(c.properties.batchIdData=i,c.properties.batchIdMap=function(t,e){if(!e)return null;const n=new Map;for(let r=0;r<e.length;r++){const s=e[r],i=t[s];let o=n.get(i);o||(o=[],n.set(i,o)),o.push(s)}return n}(i,a)),c.generateBuffers(this.h,{excludeElementsInVAO:e}),c}xt(t,e,n,s){const o=r.identity(t),a=this.getMap();Cn.x=n[0],Cn.y=n[1];const c=this._prjToPoint(Cn),h=this.qt(),u=1/(a.getGLZoom?a.getResolution(a.getGLZoom()):a.getGLRes());Cn.x=e[0],Cn.y=e[1];const l=this.ft();let f=this.s.options.offset;dt(f)&&(f=f.call(this.s,Cn));const d=this.s.H(s).heightOffset||0;return i.set(Bn,c.x-f[0],c.y-f[1],l*n[2]+l*d),r.translate(o,o,Bn),i.set(h,u,u,l),r.scale(o,o,h),o}nt(t,e){const n=this.s.H(e.V),s=this.s.lt(e.V).Ut;let a=n.rotation||[0,0,0];a=o.fromEuler(jn,a[0],a[1],a[2]);const c=n.scale||[1,1,1],h=r.fromRotationTranslationScale([],a,Gn,c),u=r.identity([]),l=r.identity([]);r.translate(u,u,i.scale(Vn,s,-1)),r.translate(l,l,s);const f=r.multiply(u,u,t.X);r.multiply(h,h,f);const d=r.multiply(l,l,h);t.localTransform=d}St(t,e){const n=r.identity(t),s=this.getMap(),o=this.qt();Cn.x=e[0],Cn.y=e[1];const a=s.distanceToPointAtRes(100,100,s.getGLRes(),Cn);let c;return c=s.altitudeToPoint?this.U:a.y/100,i.set(o,a.x/100*1.01,a.y/100*1.01,c),r.scale(n,n,o),n}L(){const t={x:0,y:0,width:()=>this.i?this.i.width:1,height:()=>this.i?this.i.height:1},e=[],s=[];this.ct=new n.MeshShader({vert:Xt,frag:"#define SHADER_NAME PNTS\n\nprecision mediump float;\n\n\n\nvarying vec4 vColor;\n\n\n\nvoid main() {\n\n vec2 circCoord = 2.0 * gl_PointCoord - 1.0;\n\n if (dot(circCoord, circCoord) > 1.0) {\n\n discard;\n\n } else {\n\n gl_FragColor = vColor;\n\n }\n\n}\n\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:(t,e)=>r.multiply(s,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,n)=>a.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.B();this.st=new n.PhongShader({extraCommandProps:i}),this.it=new n.pbr.StandardShader({extraCommandProps:i}),this.ut=new n.EdgeShader({extraCommandProps:{viewport:{x:0,y:0,width:()=>this.i?this.i.width:1,height:()=>this.i?this.i.height:1},blend:{enable:!0,func:{srcRGB:"src alpha",srcAlpha:1,dstRGB:"one minus src alpha",dstAlpha:"one minus src alpha"},equation:"add"}}});const o=this.s;gn(o.getRenderer().canvas,this.h,o.getMap()),this.picking=new n.FBORayPicking(this.u,{vert:this.it.vert,extraCommandProps:i,uniforms:this.it.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap()),this.$t=new n.FBORayPicking(this.u,{vert:Xt,extraCommandProps:i,uniforms:this.ct.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap())}B(){return{viewport:{x:0,y:0,width:()=>this.i?this.i.width:1,height:()=>this.i?this.i.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}}}ot(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.s,n=e.getRenderer().canvas,{iblTexes:r,dfgLUT:s}=wn(n),i=vn(t,r,s),o=this.s.getRenderer(),a=o.getMaskUniforms();i.minAltitude=e.options.altitude||0;const c=o.canvas.gl&&o.canvas.gl.wrap?e.options.opacity||0:1;return i.layerOpacity=c,ft(i,{czm_lightDirectionEC:i.light0_viewDirection,lightSpecular:[1,1,1],viewMatrix:t.viewMatrix,projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,outSize:[n.width,n.height],polygonFill:[1,1,1,1],polygonOpacity:1}),ft(i,a),i}Ht(t,e,r,s,i,o,a){const h=e.materials&&e.materials[t];if(!h||!h.baseColorTexture&&!h.pbrMetallicRoughness)return null;const u=ft({},s);if(h.baseColorTexture){const t=e.textures[h.baseColorTexture.index];let n;t&&!t.image.color&&(n=this.Xt(t,o)),u.baseColorFactor=t&&t.image.color||h.baseColorFactor||[1,1,1,1],n&&(u.baseColorTexture=n)}else{if(h.normalTexture){const t=this.Xt(e.textures[h.normalTexture.index],o);if(t){const e=h.normalTexture.scale||1;u.normalTexture=t,u.normalMapFactor=e}}if(h.occlusionTexture){const t=this.Xt(e.textures[h.occlusionTexture.index],o);if(t){const e=h.occlusionTexture.strength||1;u.occlusionTexture=t,u.occlusionFactor=e}}if(h.emissiveTexture){const t=this.Xt(e.textures[h.emissiveTexture.index],o);t&&(u.emissiveTexture=t)}h.emissiveFactor&&(u.emissiveFactor=h.emissiveFactor);const t=h.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(u.baseColorFactor=t.baseColorFactor),t.baseColorTexture&&void 0!==t.baseColorTexture.index){const n=e.textures[t.baseColorTexture.index];if(n.image&&n.image.color)u.baseColorFactor=u.baseColorFactor?c.multiply(u.baseColorFactor,u.baseColorFactor,n.image.color):n.image.color;else{const t=this.Xt(n,o);t&&(u.baseColorTexture=t,u.baseColorTexture.getREGLTexture(this.h))}}if(lt(t.metallicFactor)||(u.metallicFactor=t.metallicFactor),lt(t.roughnessFactor)||(u.roughnessFactor=t.roughnessFactor),h.metallicRoughnessTexture){const t=this.Xt(e.textures[h.metallicRoughnessTexture.index],o);t&&(u.metallicRoughnessTexture=t)}}}if(h.s3mMaterial)return new n.Material(u);if(u.environmentExposure=i,u.alphaTest=.1,a.unlit||h.extensions&&h.extensions.KHR_materials_unlit)return u.ambientColor=[1,1,1],u.light0_diffuse=[0,0,0,0],u.lightSpecular=[0,0,0],new n.PhongMaterial(u);let l=new n.pbr.StandardMaterial(u);"phong"===r&&(l=n.PhongMaterial.convertFrom(l));const f=h.pbrMetallicRoughness,d=f&&f.baseColorTexture&&f.baseColorTexture.extensions;return d&&d.KHR_texture_transform&&(l.set("khr_offset",d.KHR_texture_transform.offset||[0,0]),l.set("khr_rotation",d.KHR_texture_transform.rotation||0),l.set("khr_scale",d.KHR_texture_transform.scale||[1,1])),l.doubleSided=!(!a.doubleSided&&!h.doubleSided),l.once("complete",this.C),l}Xt(t,e){const r={type:t.type?ln(t.type):"uint8",format:t.format?fn(t.format):"rgba",flipY:!!t.flipY},s=t.image;if(e.push(s),s.array?r.data=s.array:s.mipmap&&(r.mipmap=s.mipmap),!r.data&&!r.mipmap)return null;if(r.width=s.width,r.height=s.height,r.mipmap&&(r.width<4||r.height<4))return null;const i=t.sampler||t.texture&&t.texture.sampler;return i&&(i.magFilter&&(r.mag=cn(i.magFilter)),i.minFilter&&(r.min=hn(i.minFilter)),i.wrapS&&(r.wrapS=un(i.wrapS)),i.wrapT&&(r.wrapT=un(i.wrapT))),new n.Texture2D(r,this.N)}P({target:t}){const e=t.Vt,n=this.m[e];if(n.count--,!n.count){const t=n.meshes;this.p[e]=t,delete this.m[e];const r=t.Rt;delete t.Rt,r(null,{mesh:n.meshes,id:e})}}qt(){return xn}Jt(t){return this.s.Jt(t)}_pointToPrj(t){const e=this.getMap();return e.getGLZoom?e._pointToPrj(t,e.getGLZoom()):e._pointToPrjAtRes(t,e.getGLRes())}_prjToPoint(t){const e=this.getMap();return e.getGLZoom?e._prjToPoint(t,e.getGLZoom()):e._prjToPointAtRes(t,e.getGLRes(),Pn)}At(t){return"Y"===t?pn:"X"===t?bn:An}pick(t,e,n=3){const r=this.s;if(!r||!r.options.picking)return[];if(!this.pickingFBO||!this.picking)return[];const s=[],i=this.D(),o=this.Qt(this.picking,i,this.M,t,e,n);o&&s.push(o);const a=this.Qt(this.picking,i,this.I,t,e,n);a&&s.push(a);const c=this.ot(),h=this.Qt(this.$t,c,this.A,t,e,n);return h&&s.push(h),s}Qt(t,e,n,r,s,i){if(!n.getMeshes().length)return null;const o=this.s,a=this.getMap();t.render(n.getMeshes().filter(t=>!t.bloom),e,!0);let c={};t.getRenderedMeshes().length&&(c=t.pick(r,s,i,e,{viewMatrix:a.viewMatrix,projMatrix:a.projMatrix,returnPoint:o.options.pickingPoint}));const{meshId:h,pickingId:u,point:l,coordinate:f}=c,d=(0===h||h)&&t.getMeshAt(h);if(!d||!d.geometry)return null;const m=d.properties;l&&l.length&&(l[0]=Math.round(1e5*l[0])/1e5,l[1]=Math.round(1e5*l[1])/1e5,l[2]=Math.round(1e5*l[2])/1e5);const p={batchId:u};if(o.options.debug&&(p.debugInfo=m),m&&m.batchTable){const{batchTable:t,batchTableBin:e,count:n}=m,r=u;for(const s in t)void 0!==t[s].byteOffset?p[s]=we(t[s],e,n,r):p[s]=t[s][r]}return{service:d.properties.serviceIndex,data:p,point:l,coordinate:f}}j(t){let e=new Set;for(let n=0,r=t.length;n<r;n++){const r=t[n].data.node;this.G(r)&&e.add(r.W)}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.s.getRenderer();this.K=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelAllHighlight(){this.J=null;const t=this.s.getRenderer();this.K=t.getFrameTimestamp(),t.setToRedraw(!0)}showOnly(t){this.Z=t;const e=this.s.getRenderer();this.Y=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelShowOnly(){this.Z=null;const t=this.s.getRenderer();this.Y=t.getFrameTimestamp(),t.setToRedraw(!0)}Kt(){if(!this.F)return[];const t={},e=[];for(const n in this.F){const r=this.F[n];if(r)for(let n=0;n<r.length;n++){const s=r[n],i=s&&s.geometry;if(!s||!i)continue;const o=s.properties.serviceIndex;t[o]||(t[o]=new Set);const a=i.properties.batchIdData;if(a)for(let n=0;n<a.length;n++)t[o].has(a[n])||(e.push({id:a[n],service:o}),t[o].add(a[n]))}}return e}hasIBL(){const t=this.getMap().getLightManager();return!!(t&&t.getAmbientResource())}}function Zn(t){for(let e=0;e<t.length;e++)t[e]&&(t[e].array&&(t[e].array=null),t[e].mipmap&&(t[e].mipmap=null),t[e].indices&&(t[e].indices=null))}const Yn=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")},Wn=Yn(),tr=Wn.gl_trans__coders=Wn.gl_trans__coders||{};function er(t,e){if(e)for(let n=0;n<e.length;n++){t[e[n].id||e[n].index]=e[n]}}tr.inject=function(t){const e=t.toString(),n=e.indexOf("{")+1,r=e.substring(0,n),s=Wn.gl_trans__coders=Wn.gl_trans__coders||{};let i=`${r}\n const _____getGlobal = ${Yn.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},tr.registerTranscoder=function(t,e){tr[t]=e},tr.getTranscoder=function(t){return tr[t]};const nr=[];class rr{constructor(t,e,n,r,s){this.s=r,this.Zt=t,this.V=e,this.Yt=s,this.Wt=n.version,t.indexOf("i3s:tileset:")<0?(this.Wt<=1.6?this.te="root":this.te=0,n.version=this.Wt):(this.te=t.substring("i3s:tileset:".length),this.Wt>1.6&&(this.te=parseInt(this.te))),this.Zt=t,this.ee=n}load(){const t=this.ee,e=t.layerScene.baseUrl;if(this.Wt<=1.6)return t[this.te]&&t[this.te].lodSelection?(this.ne=t[this.te],this.re()):new Promise(n=>{let r=e+"/nodes/"+this.te;t.layerScene.eslpk&&(r+="/3dNodeIndexDocument.json"),this.Yt(this.V,r,()=>{this.ne=t[this.te],n(this.re())})});if(this.Wt>=1.7){if(t[this.te])return this.ne=t[this.te],this.re();const n=Math.floor(this.te/t.nodesPerPage);return new Promise(r=>{let s=e+"/nodepages/"+n;t.layerScene.eslpk&&(s+=".json"),this.Yt(this.V,s,()=>{this.ne=t[this.te],r(this.re())})})}return null}getTileset(){return this.se}getChildrenURL(){return this.ie}re(){const t=this.ee,e=t.layerScene.baseUrl,n=this.ne.children,r=[],s={};if(n)for(let i=0;i<n.length;i++)if(this.Wt<=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.Yt(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.Yt(this.V,r,()=>{n()})}),r.push(s[a]))}return r.length?Promise.all(r).then(()=>this.oe()):this.oe()}oe(){return Promise.resolve(this.ae())}ce(t){er(this.ee,t)}ae(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.he(this.ne,!0)}}he(t){const e=this.s.getRenderer(),n=this.ee.projection,r=!n||n&&4326===n.wkid,s=this.Wt,i=this.ee,o=t,a=o.obb,c=o.mbs,h={};let u;if(c)u=w.set([],c[0],c[1],c[2]),r||(u=e.ue(u,u)),u=sr([],u[0],u[1],u[2]),h.sphere=[...u,c[3]];else if(a){u=w.set([],a.center[0],a.center[1],a.center[2]),r||(u=e.ue(u,u)),u=sr([],u[0],u[1],u[2]);const t=function(t,e,n){const r=v.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]}(u,a.halfSize,a.quaternion),n=t[3]+t[6]+t[9],s=t[4]+t[7]+t[10],i=t[5]+t[8]+t[11];w.set(nr,n,s,i);const o=w.len(nr);h.sphere=[...u,o]}let l=1/0,f=0;if(o.mbs?f=o.mbs[3]:o.obb&&(f=Math.max(Math.max(o.obb.halfSize[0],o.obb.halfSize[1]),o.obb.halfSize[2])),void 0!==o.lodThreshold)if("maxScreenThresholdSQ"===i.lodSelectionMetricType){l=f/(Math.sqrt(o.lodThreshold)/(.25*Math.PI))}else console.error("Unsupported lodSelectionMetricType in Layer");else if(void 0!==o.lodSelection)for(let t=0;t<o.lodSelection.length;t++)"maxScreenThreshold"===o.lodSelection[t].metricType&&(l=f/o.lodSelection[t].maxError);(l===1/0||isNaN(l))&&(l=1e5);const d=16*l,m=y.identity([]),p=o.children;let b;if(p){b=[];const t=this.ee;for(let e=0;e<p.length;e++){const n=s<=1.6?p[e].id:p[e];if(!t[n]){b=null;break}b.push(this.he(t[n]))}}const g={refine:"REPLACE",boundingVolume:h,transform:m,geometricError:d};return s<=1.6?t.lodSelection?t.geometryData&&(g.content={uri:"i3s:mesh:"+(t.id||t.index)}):g.content={uri:"i3s:tileset:"+(t.id||t.index)}:p&&p.length&&!b?g.content={uri:"i3s:tileset:"+(t.id||t.index)}:o.mesh&&(g.content={uri:"i3s:mesh:"+(t.id||t.index)}),b&&b.length&&(g.children=b),g}getJSON(){return this.ne}}function sr(t,e,n,r){return Zt(t,bt(e),bt(n),r)}const ir=!!tr.ktx2,or=r.identity([]),ar=(()=>{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 cr(t){return t.indexOf("i3s:mesh")>=0}const hr="i3s:mesh:".length;function ur(t,e,n,r,s){const i=e.layerScene.eslpk,o=function(t,e){const n=e.substring(hr);return t>=1.7?parseInt(n):n}(e.version,t),a=e[o],c=e.layerScene.baseUrl,h=[];let u=!1;const l=or;let f,d;if(e.version<=1.6){if(!a.geometryData)return null;const t=a.geometryData.length;if(!t)return null;let n=c+`/nodes/${a.id}/`+a.geometryData[t-1].href;i&&(n+=".bin");const r={geometry:{url:n,info:e.layerScene.store.defaultGeometrySchema}};let s=a.textureData&&a.textureData[0]&&a.textureData[0].href;if(s){const t=e.layerScene.store.textureEncoding[0];let n;n="image/jpeg"===t?"jpg":"png",i&&(s+="."+n);const o={pbrMetallicRoughness:{baseColorTexture:{url:c+`/nodes/${a.id}/`+s,factor:1,format:n,mimeType:t},metallicFactor:0}};r.material=o}h.push(r)}else{f=a.mesh.geometry,d=a.mesh.material;const t=e.layerScene.geometryDefinitions[f.definition],{geometryBuffers:o}=t;u=r&&2===o.length;const l=tr.draco&&u?o[1]:o[0],m=tr.draco&&u?1:0;let p=c+`/nodes/${f.resource}/geometries/`+m;i&&(p+=".bin");const b={geometry:{url:p,info:l}};if(s&&ar&&u&&!tr.draco)throw new Error("Must import @maptalks/transcoder.draco to load i3s draco compressed geometry");const g=e.layerScene.materialDefinitions,y=e.layerScene.textureSetDefinitions;let w,v=0;if(d&&(v=g[d.definition]),g){w=function(t,e,n,r,s,i){const o=JSON.parse(JSON.stringify(t));return function t(e,n,r,s,i,o){for(const a in e)if(e[a]&&e[a].textureSetDefinitionId>=0){const t=n[e[a].textureSetDefinitionId],c="images/"+t.formats[0].format,h=lr(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 mt(e[a])&&t(e[a],n,r,s,i,o)}(o,e,n,r,s,i),o}(v,y,c,d.resource,n,e.layerScene.eslpk)}else w={pbrMetallicRoughness:{metallicFactor:0}};b.material=w,h.push(b)}return{dracoCompression:u,meshes:h,nodeIndex:o,center:a.obb&&a.obb.center||a.mbs&&[a.mbs[0],a.mbs[1],a.mbs[2]],transform:l}}function lr(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&&ir)return t[n]}return null}const fr=new t.Coordinate(0,0),dr=new t.Coordinate(0,0),mr=new Set,pr=[],br=new class{constructor(t,e){this.max=t,this.currentSize=0,this.data=new Map,this.onRemove=e}reset(t){if(this.data){const e=this.data.keys();for(const n of e){const e=this.data.get(n);t&&t!==e.renderer||this.le(n,e)}}return t||(this.data=new Map,this.currentSize=0),this}clear(t){this.reset(t)}add(t,e){if(!e)return this;if(e.node&&e.node.memorySize&&(this.currentSize+=e.node.memorySize),this.has(t)){const n=this.data.get(t);n&&n.node&&n.node.memorySize&&(this.currentSize-=n.node.memorySize),this.data.delete(t),this.data.set(t,e)}else this.data.set(t,e);return this}shrink(){if(this.currentSize>this.max){let t=!1;const e=this.data.keys();let n=e.next();for(;this.currentSize>this.max&&void 0!==n.value;){!t&&this.data.get(n.value).current&&(t=!0,console.warn(`current maxGPUMemory(${this.max/1024/1024}) for Geo3DTilesLayer is not enough, one or more current tiles will be discarded.`));const r=this.getAndRemove(n.value);r&&this.onRemove(r),n=e.next()}}}has(t){return this.data.has(t)}keys(){const t=new Array(this.data.size);let e=0;const n=this.data.keys();for(const r of n)t[e++]=r;return t}getAndRemove(t){if(!this.has(t))return null;const e=this.data.get(t);return e.node&&e.node.memorySize&&(this.currentSize-=e.node.memorySize),this.data.delete(t),e}get(t){if(!this.has(t))return null;const e=this.data.get(t);return this.data.delete(t),this.data.set(t,e),e}remove(t){if(!this.has(t))return this;const e=this.data.get(t);return this.le(t,e),this}le(t,e){e.node&&e.node.memorySize&&(this.currentSize-=e.node.memorySize),this.data.delete(t),this.onRemove(e)}setMaxSize(t){return this.max=t,this.shrink(),this}getMemorySize(){let t=0;const e=this.data.values();for(const n of e){const e=n&&n.node;e&&e.memorySize&&(t+=e.memorySize)}return t}markAll(t,e){const n=this.data.values();for(const r of n)t&&r.renderer!==t||(r.current=e)}}(1024*(t.Browser.mobile?32:1024)*1024,t=>{const e=t.renderer;delete t.renderer,e.deleteTile(t)});let gr=0;class yr extends(h(t.renderer.CanvasRenderer)){constructor(t){super(t);const e=1024*t.options.maxGPUMemory*1024;e>br.max&&br.setMaxSize(e),this.tileCache=br,gr++,this.prepareWorker(),this.tilesLoading={},this.fe={},this.de=[],this.Yt=this.me.bind(this)}getAnalysisMeshes(){if(!this.painter)return pr;const t=this.painter.getPaintedMeshes();if(!t)return pr;const e=[],{b3dmMeshes:n,pntsMeshes:r,i3dmMeshes:s}=t;return n.length&&It(e,n),r.length&&It(e,r),s.length&&It(e,s),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.de.length||super.needToRedraw())}getFrameTimestamp(){return this.pe}drawOnInteracting(t,e,n){this.draw(e,n)}draw(t,e){this.pe=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.be(),this.ge();const{selectedTiles:o,leaves:a,requests:c}=this.ye(r,s);c.length&&this.loadTiles(c),this.we(o,a,e),this.ve(),c.length||this.completeRender()}ye(t,e){const n=this.layer.getRootTiles();let r=[];this.Te();let s=0;const i=this.Oe(),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 l=!1;const f=this.getCachedTile(h.id);if(this._e(h.id)?(s++,l=c=!0,this.tilesLoading[h.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=c=!0),(!i.node.Me||u.isS3M||!i.node.children||i.node.Me<=500)&&(a=!0,i.selected=!0,i.data=f)):this.painter.has(h)||(l=c=!0,r.push(h)),!l)continue;if(this.xe(i))a=!0;else{this.Ae(i).length&&(a=!0)}}let h=[],u={};if(a&&({selectedTiles:h,leaves:u}=this.Ie(t)),r.length>1&&(r.sort(wr),i)){const t=i-s;r=t>0?r.slice(0,t):[]}return{loading:c,requests:r,selectedTiles:h,leaves:u}}Ie(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.Se===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.Se=s.length}for(let t=0;t<o.length;t++)s.push(o[t])}return{selectedTiles:e,leaves:n}}xe(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}Ae(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const n=t.W+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.Ee(s[i],t);n.selected=!0,n.data=this.tileCache.get(o),t.children.push(n),e.push(n)}else s[i].W<=n&&r.push(s[i])}}return e}we(t,e,n){this.tileCache.markAll(this,!1);for(let e=0,n=t.length;e<n;e++){const n=t[e].data;n.current=!0,n.renderer=this,this.tileCache.add(t[e].node.id,n)}this.tileCache.shrink();const r={tiles:t,leaves:e};this.onDrawTileStart(r);const s=this.painter.paint(t,e,n);this.onDrawTileEnd(r),s&&this.layer.fire("canvasisdirty",{renderCount:s})}onDrawTileStart(){}onDrawTileEnd(){}loadTiles(t){for(let e=0,n=t.length;e<n;e++){const n=t[e];this.tilesLoading[n.id]={current:!0,node:n},this.loadTile(n)}}loadTile(t){let e=t.content.url;if(xt(e)){const n=At(e);return this.Ne(e,n,t),null}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const n=t.V,r=this.Ce[n];return new rr(e,n,r,this.layer,this.Yt).load().then(n=>{this.onTilesetLoad(n,t,e)})}return t&&Ct(e)&&!cr(e)&&(e=t.baseUrl+e),this.Ne(e,null,t),null}Ne(t,e,r){let s=this.Pe;s||(s=n.Util.getSupportedFormats(this.gl.gl||this.gl),this.Pe=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:this.layer.getTileUrl(t,r.baseUrl,this.layer.Re[r.V]),arraybuffer:e,rootIdx:r.V,upAxis:r.It,transform:r.matrix,supportedFormats:s};if(cr(t)){const e=this.Ce[r.V];if(o.projection=e.projection,o.i3sInfo=ur(t,e,this.regl,this.layer.options.enableI3SCompressedGeometry,this.layer.options.forceI3SCompressedGeometry),!o.i3sInfo)return void this.onTileError({status:404},r,t)}o.service=ft({},i),i.offset&&delete o.service.offset,o.referrer=window&&window.location.href,this.workerConn.loadTile(this.layer.getId(),o,(e,n)=>{if(e)return void this.onTileError(e,r,t);const{magic:s}=n;"b3dm"===s||"pnts"===s||"i3dm"===s||"cmpt"===s||"gltf"===s?(this.de.push({data:n,tile:r}),i.debugShowBoundingVolume&&this.painter.kt(r)):this.onTilesetLoad(n,r,t)})}ge(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let n=0;for(;this.de.length&&(n<e||!t.isInteracting());){const{data:t,tile:e}=this.de.shift(),{magic:r}=t;"b3dm"===r||"gltf"===r?this.painter.createB3DMMesh(t,e.id,e,(n,{mesh:r})=>{this.Le(t,e,n,r)}):"pnts"===r?this.painter.createPntsMesh(t,e.id,e,(n,{mesh:r})=>{this.Le(t,e,n,r)}):"i3dm"===r?this.painter.createI3DMMesh(t,e.id,e,(n,{mesh:r})=>{this.Le(t,e,n,r)}):"cmpt"===r&&this.painter.createCMPTMesh(t,e.id,e,(n,{mesh:r})=>{this.Le(t,e,n,r)}),n++}}Le(t,e,n,r){if(n)this.onTileError(n,e);else{const n=this.ke(r);e.memorySize=n,this.onTileLoad(t,e)}}ke(t){let e=0;if(Array.isArray(t))for(let n=0;n<t.length;n++)t[n]&&(e+=this.ke(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.Be(e),this.setToRedraw(),this.layer.fire("tileload",{node:e}))}onTilesetLoad(t,e,n){this.layer&&(this.layer.zt=t.extensions&&t.extensions["s3m:VertexCompressionType"],t.capabilities||t.layers&&t.layers[0]&&t.layers[0].capabilities?this.Ue(t,e,n):(delete this.tilesLoading[e.id],this.layer.onTilesetLoad(t,e,n)))}onTileError(t,e,n){if(!this.layer)return;const r=n||e.content.url,s=t&&t.message||t;mr.has(s)||(console.warn("failed to load 3d tile: "+r),console.warn(t),mr.add(s)),delete this.tilesLoading[e.id],this.Fe(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}Fe(e,n){const r={loadTime:t.Util.now(),current:!0,error:n,node:e};r.renderer=this,this.tileCache.add(e.id,r)}Be(e){const n={loadTime:t.Util.now(),current:!0,node:e};n.renderer=this,this.tileCache.add(e.id,n)}abortTileLoading(t){if(!t||!this.workerConn)return;const e=t.node.content.url;this.workerConn.abortTileLoading(this.layer.getId(),e),delete this.fe[e]}Te(){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.De(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 Kn(this.regl,t),this.layer.ze(),this.layer.fire("contextcreate",{regl:this.regl})}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new Lt("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let n=this.layer.options||{};n=ft({},n),delete n.offset;const r=t.options.spatialReference;n.projection=r&&r.coordType||r&&r.projection||t.getSpatialReference().getProjection().code;const s=this.layer.getId();e.addLayer(s,n,t=>{if(t)throw t;this.layer&&(this.ready=!0,this.layer.fire("workerready"))})}onRemove(){this.painter&&this.painter.remove(),this.pickingFBO&&(this.canvas.pickingFBO||this.pickingFBO.destroy(),delete this.pickingFBO),this.workerConn&&(this.workerConn.removeLayer(this.layer.getId(),t=>{if(t)throw t}),this.workerConn.remove(),delete this.workerConn),gr--,gr||br.reset(),this.clear(),delete this.tileCache,super.onRemove()}clear(){this.ve(!0),this.tileCache.reset(this),this.tilesLoading={},super.clear()}clearCanvas(){this.regl&&this.regl.clear({color:[0,0,0,0],depth:1,stencil:0}),super.clearCanvas()}getTileOpacity(){return 1}getStencilValue(){return 0}ve(t){this.je||(this.je=Date.now());const e=Date.now();if(!t&&e-this.je<this.layer.options.retireInterval)return;this.je=e;const n=[];for(const e in this.tilesLoading){const r=this.tilesLoading[e];!t&&r.current||(n.push(e),this.abortTileLoading(r))}for(let t=0;t<n.length;t++)delete this.tilesLoading[n[t]]}Oe(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}De(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}_e(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 ge(t,e,0,n)}be(){if(!this.Ge)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const n=[];for(const r in this.Ge){const s=this.Ge[r];if("pending"===s.status)continue;s.status="pending";const i=s.rootIdx,o=Pt(this.layer.H(i).fetchOptions);if(n.push(b.getJSON(r,o).then(t=>{delete this.Ge[r];const e=this.Ce[i];if(e){t.nodes?er(e,t.nodes):(e[t.id]=t,er(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)}me(t,e,n){this.Ge||(this.Ge={}),this.Ge[e]=this.Ge[e]||[],this.Ge[e].rootIdx=t,this.Ge[e].push(n),this.setToRedraw()}Ue(t,e,n){this.Ce||(this.Ce=[]);const r=e.V;this.Ce[r]||(this.Ce[r]={});const s=this.Ce[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),!t.spatialReference||t.spatialReference.wkid&&4326===t.spatialReference.wkid||console.warn("i3s has a spatialReference other than 4326.",t.spatialReference),s.projection=t.spatialReference,function(t,e,n,r,s,i,o){if(!i.layerScene){i.layerScene=e,i.nodesPerPage=e.nodePages&&e.nodePages.nodesPerPage||64,i.lodSelectionMetricType=e.nodePages&&e.nodePages.lodSelectionMetricType;let t=s;i.layerScene.eslpk=t.indexOf("3dSceneLayer.json")>=0;if(t.endsWith(".json")){const e=s.lastIndexOf("/");t=e<0?"./":s.substring(0,e)}i.layerScene.baseUrl=function(t){return t.split("?")[0]}(t)}return new rr(s,n,i,t,o).load()}(this.layer,t,r,0,n,s,this.Yt).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.Z||(this.Z=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const n=t[e].service||0;let r=this.Z[n];r||(r=this.Z[n]=new Map),r.set(t[e].id,t[e])}else{const e=t.service||0;let n=this.Z[e];n||(n=this.Z[e]=new Map),n.set(t.id,t)}this.painter.showOnly(this.Z)}cancelShowOnly(){delete this.Z,this.painter.cancelShowOnly()}Kt(){return this.painter?this.painter.Kt():[]}ue(t,e){const n=this.getMap();if("identity"===n.getProjection().code.toLowerCase()){const n=this.He();return fr.x=e[0],fr.y=e[1],n.unproject(fr,dr),t[0]=dr.x,t[1]=dr.y,t}return fr.x=e[0],fr.y=e[1],n.getProjection().unproject(fr,dr),t[0]=dr.x,t[1]=dr.y,t}Ve(t,e){const n=this.He();return fr.x=e[0],fr.y=e[1],n.project(fr,dr),t[0]=dr.x,t[1]=dr.y,t}qe(t,e){const n=this.He();return fr.x=e[0],fr.y=e[1],n.unproject(fr,dr),t[0]=dr.x,t[1]=dr.y,t}He(){const e=this.getMap().options.spatialReference.coordType;if(!e)throw new Error("Missing coordType in map spatialReference.");return this.$e||(this.$e=t.SpatialReference.getProjectionInstance(e)),this.$e}}function wr(t,e){return t.bt-e.bt}function vr(t,e,n){return t[0]=e[n],t[1]=e[n+3],t[2]=e[n+6],t}function Tr(t,e,n){return Math.sqrt(function(t,e,n){const r=w.subtract(Or,n,t),s=vr(_r,e,0),i=vr(Mr,e,1),o=vr(xr,e,2),a=w.len(s),c=w.len(i),h=w.len(o);w.normalize(s,s),w.normalize(i,i),w.normalize(o,o);const u=Ar;u[0]=w.dot(r,s),u[1]=w.dot(r,i),u[2]=w.dot(r,o);let l,f=0;u[0]<-a?(l=u[0]+a,f+=l*l):u[0]>a&&(l=u[0]-a,f+=l*l);u[1]<-c?(l=u[1]+c,f+=l*l):u[1]>c&&(l=u[1]-c,f+=l*l);u[2]<-h?(l=u[2]+h,f+=l*l):u[2]>h&&(l=u[2]-h,f+=l*l);return f}(t,e,n))}const Or=[],_r=[],Mr=[],xr=[],Ar=[];const Ir=2*Math.PI;class Sr{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+=Ir,n<0&&(n+=Ir)),(n>s||le(n,s,1e-14))&&(n<i||le(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 Er=[0,0,1];function Nr(t,e){return Zt(e,t[0],t[1],t[2])}class Cr{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 Pr=[],Rr=[],Lr=[],kr=[],Br=[],Ur=[],Fr=[],Dr=[],zr=[],jr=[],Gr=new Cr([1,0,0],0),Hr=[];class Vr{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new Sr(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){let n=0;if(!Sr.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(Hr,t,e),u=i.dot(h,s),l=i.dot(h,o),f=i.subtract(Hr,t,r),d=i.dot(f,a),m=i.dot(f,c);u>0?n+=u*u:d>0&&(n+=d*d),l>0?n+=l*l: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;Nr(Sr.southwest(t,Rr),e.southwestCornerCartesian),Nr(Sr.northeast(t,Rr),e.northeastCornerCartesian),Pr[0]=t.west,Pr[1]=.5*(t.south+t.north),Pr[2]=0;const n=Nr(Pr,Lr),r=i.cross(Br,n,Er);i.normalize(e.westNormal,r),Pr[0]=t.east;const s=Nr(Pr,Dr),o=i.cross(Br,Er,s);i.normalize(e.eastNormal,o);const a=i.subtract(Br,n,s),c=i.normalize(kr,a),h=t.south;let u;if(h>0){Pr[0]=.5*(t.west+t.east),Pr[1]=h;const n=Nr(Pr,zr);i.copy(jr,c);const r=Cr.fromPointNormal(e.southwestCornerCartesian,e.westNormal,Gr);qr(zr,jr,r,e.southwestCornerCartesian),u=ce(n,Ur)}else u=he(Sr.southeast(t,Rr),Ur);const l=i.cross(Fr,u,a);i.normalize(e.southNormal,l);const f=t.north;let d;if(f<0){Pr[0]=.5*(t.west+t.east),Pr[1]=f;const n=Nr(Pr,zr);i.scale(jr,c,-1);const r=Cr.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,Gr);qr(zr,jr,r,e.northeastCornerCartesian),d=ce(n,Ur)}else d=he(Sr.northwest(t,Rr),Ur);const m=i.cross(Fr,a,d);i.normalize(e.northNormal,m)}}function qr(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 $r={"maxGPUMemory":t.Browser.mobile?32:1536,"retireInterval":2e3,"loadingLimitOnInteracting":5,"loadingLimit":10,"renderer":"gl","forceRenderOnZooming":!0,"forceRenderOnRotating":!0,"forceRenderOnMoving":!0,"debug":!1,"meshLimitPerFrame":1,"i3sNodepageLimitPerFrame":1,"enableI3SCompressedGeometry":!0,"forceI3SCompressedGeometry":!0,"picking":!0,"pickingPoint":!0,"geometryEvents":!1,"antialias":!1,"optionalExtensions":["ANGLE_instanced_arrays","OES_element_index_uint","OES_standard_derivatives","OES_vertex_array_object","OES_texture_half_float","OES_texture_half_float_linear","OES_texture_float","OES_texture_float_linear","WEBGL_depth_texture","EXT_shader_texture_lod","WEBGL_compressed_texture_astc","WEBGL_compressed_texture_etc","WEBGL_compressed_texture_etc1","WEBGL_compressed_texture_pvrtc","WEBGL_compressed_texture_s3tc","WEBGL_compressed_texture_s3tc_srgb"],"offset":[0,0]},Xr=new t.Extent(0,0,0,0),Jr=[],Qr=[],Kr=[],Zr=[],Yr=[],Wr=new t.Coordinate(0,0),ts=new t.Point(0,0),es=[],ns=new t.Coordinate(0,0),rs=r.identity([]),ss=[0,0],is=[1,1,1,1,-1,1,-1,-1,1,-1,1,1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1];class os extends(l(t.Layer)){static fromJSON(t){return t&&"Geo3DTilesLayer"===t.type?new os(t.id,t.options):null}constructor(t,e){super(t,e),this.Xe(),this.fe={},this.Bt=[]}Xe(){const t=this.options.services.map(t=>t.url);this.Je=this.Je||{},this.Re=this.Re||[];for(let e=0;e<t.length;e++){const n=t[e];let r=this.Je[n];void 0===r&&(r=this.Je[n]=this.Re.length),this.Re[r]=hs(n,r,this.options.services[e])}this.fire("rootready",{roots:this.Re.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.Xe();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]&&ft(n[t],e),!lt(e.visible)){const r=n[t].url,s=this.Je[r];this.Re&&this.Re[s]&&(this.Re[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.Je[n];this.Re[r]&&(this.Re[r]=null),delete this.Je[n],e.splice(t,1)}const n=this.getRenderer();return n&&n.setToRedraw(),this}getTileUrl(t,e,n){const r=n&&n.service&&n.service.subdomains;if(r&&n.domainKey){const e=r.length;if(e){const s=[...t].reduce((t,e)=>t+e.charCodeAt(),0)%e;return t.replace(n.domainKey,r[s])}}return t}getExtent(e){if(!e&&0!==e){const e=new t.Extent;for(let t=0;t<this.Re.length;t++)if(this.Re[t].boundingVolume){const n=this.boundingVolumeToExtent(this.Re[t]);e._combine(n)}return e}return this.Re[e]&&this.Re[e].boundingVolume?this.boundingVolumeToExtent(this.Re[e]):null}boundingVolumeToExtent(e){const n=e.boundingVolume.Qe?rs:e.matrix,r=this.getMap(),s="identity"===r.getProjection().code.toLowerCase(),o=this.getRenderer();if(e.boundingVolume.region){const n=e.boundingVolume.region;return new t.Extent(gt(n[0]),gt(n[1]),gt(n[2]),gt(n[3]))}if(e.boundingVolume.sphere){const a=e.boundingVolume.sphere,c=re([],i.transformMat4([],a,n));s&&o.Ve(c,c);const h=a[3],u=r.locate(c,-h,h),l=r.locate(c,h,-h);return new t.Extent(u,l)}if(e.boundingVolume.box){const c=e.boundingVolume.box,h=i.transformMat4([],c,n),u=new t.Coordinate(re([],h));s&&o.Ve(u,u);const l=c.slice(3);a.multiply(l,a.fromMat4([],e.matrix),l);const f=i.length(l.slice(0,3)),d=i.length(l.slice(3,6)),m=i.length(l.slice(6,9)),p=Math.max(f,d,m),b=r.locate(u,-p,p),g=r.locate(u,p,-p);return new t.Extent(b,g)}return null}getRootTiles(){return this.Re}getTiles(){const t=this.getRenderer();if(!t.ready)return this.Ke(),{tiles:Yr};const e=this.getMap(),n=e.cameraPosition,r=e.pointAtResToDistance(n[2],0,e.getGLRes()),s=this.Ze(n);this.Ye=this.Ye||[],i.set(this.Ye,bt(s.x),bt(s.y),r),this.We=Zt(this.We||[],this.Ye[0],this.Ye[1],this.Ye[2]),this.tn=2*Math.tan(.5*bt(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const h=[];for(let e=0;e<this.Re.length;e++){const n=this.Re[e];if(!n||!n.visible)continue;let r=1/0;const s=[n],i=this.nn(e);for(;s.length>0;){const e=s.pop();for(e.id||this.rn(e);c.level>=e.W;)c=c.parent;const n=this.sn(e,i,o);if(n<1){let t=c;for(;t&&!t.content;)t=t.parent;0===n&&t&&t.content&&this.in(h,t);if(!1===this.options.services[e.V].alwaysShow)continue;if(!(0===n&&e.W<=r))continue;e.content&&(r=e.W)}e.bt<1/0&&this.an(e);const a=this.Ee(e,c);c.children.push(a);const u=e.children,l=u&&u.length,f=a.content;if(!l&&f&&this.in(h,a),l){f&&"add"===e.refine&&this.in(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].It=e.It,u[i].baseUrl=e.baseUrl;const t=u[i].content&&(u[i].content.url||u[i].content.uri);t&&(xt(t)||t.indexOf("i3s:")>=0?u[i].baseUrl=e.baseUrl:Ct(t)?u[i].content.url=e.baseUrl+t:u[i].baseUrl=t.substring(0,t.lastIndexOf("/")+1))}s.push(u[i])}!r&&f&&this.in(h,a)}}}return{root:a,tiles:h}}in(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 as(n,e);if(n.box)return 0===cs(n,e)}return!1}(this.Ye,this.We,n)||t.push(e)}Ee(t,e){return{id:t.id,node:t,children:[],level:t.W,parent:e,content:t.content&&t.content.url}}rn(e){const n=this.getId();e.id=n+":"+t.Util.GUID(),e.matrix=e.transform||r.identity([]),e.cn=this.hn(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.W&&(e.W=e.parent.W+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.Re[t].service}un(t){const e=t.boundingVolume;if(!e||e.Qe&&!this.ln(t))return;const n=this.H(t.V),s=n.heightOffset||0,o=this.options.offset,a=dt(o)||o[0]||o[1],c=n.coordOffset||ss;if(!Array.isArray(c))throw new Error("service.coordOffset must be an array");if(!e.Qe&&(!t.boundingVolume||!s&&r.exactEquals(t.matrix,rs)&&!a&&c===ss))return;e.box&&e.region&&delete e.region;const{region:h,box:u,sphere:l}=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.dn([gt(t[0]),gt(t[1])]);h[0]=bt(n.x+c[0]),h[1]=bt(n.y+c[1]);const r=this.dn([gt(t[2]),gt(t[3])]);h[2]=bt(r.x+c[0]),h[3]=bt(r.y+c[1]),h[4]=t[4]+s+(c[2]||0),h[5]=t[5]+s+(c[2]||0)}else if(u||l){e.originalVolume||(e.originalVolume=(u||l).slice(0));const n=u||l,r=e.originalVolume,o=i.transformMat4(Jr,r,t.matrix),a=re(Qr,o),h=this.dn([a[0]+c[0],a[1]+c[1]]);a[0]=h.x,a[1]=h.y,a[2]+=s+(c[2]||0),Zt(n,bt(a[0]),bt(a[1]),a[2])}e.Qe=!0}ln(t){const e=t.boundingVolume,n=this.H(t.V),r=n.heightOffset||0,s=n.coordOffset||ss;return e.coordOffset[0]!==s[0]||e.coordOffset[1]!==s[1]||e.heightOffset!==r}hn(t){return void 0===t.geometricError||!t.boundingVolume}an(t){let e=t.parent;for(;e&&e.cn&&!(e.bt<=t.bt);)e.bt=t.bt,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.It||s.upAxis||"Y").toUpperCase();t.root.baseUrl=n.substring(0,n.lastIndexOf("/")+1);const o=n.indexOf("realspace/")>-1;0===e.W&&(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.It=i,e){const n=e.V,s=this.Re[n];c&&!s.isS3M&&(s.isS3M=c);const i=e.boundingVolume;ft(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.mn=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.cn=this.hn(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&&!xt(h)&&Ct(h)&&(e.content.url=e.baseUrl+h),t.root&&!e.parent&&this.pn(e)}this.Ke(),this.fire("loadtileset",{tileset:t,index:e&&e.V,url:n})}sn(t,e,n){if(t.bt=1/0,0===t.W||t.cn)return this.pn(t),1;if(this.un(t),!this.bn(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.gn(t);return 0===s&&t.parent&&(s=.5*(t.parent.Me||0)),s>=r?1:0}Jt(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)}bn(e,n,r){const s=e.id;let i=this.Bt[s]&&this.Bt[s].obbox;const{boundingVolume:o}=e,a=o.region,c=o.box,h=o.sphere;if(!i)if(a)this.Bt[s]=this.yn(e),i=this.Bt[s].bbox,i.center=this.Bt[s].coordCenter;else if(c)this.Bt[s]=this.wn(e),i=this.Bt[s].obbox,i.center=this.Bt[s].coordCenter;else if(h){i=this.Bt[s]=this.vn(e);const n=re(Jr,h),r=new t.Coordinate(n);i.center=r}if(n){if(a)Xr.xmin=i[0][0],Xr.ymin=i[0][1],Xr.xmax=i[1][0],Xr.ymax=i[1][1];else if(h){const t=i[2];Xr.xmin=i[0][0]-t,Xr.ymin=i[0][1]-t,Xr.xmax=i[0][0]+t,Xr.ymax=i[0][1]+t}else if(c){const t=i[1],e=i[2];Xr.xmin=i[0][0]-t,Xr.ymin=i[0][1]-e,Xr.xmax=i[0][0]+t,Xr.ymax=i[0][1]+e}if(!n.intersects(Xr))return!1}return a?f(r,i):h?d(r,i):!!c&&m(r,i)}yn(e){const n=this.getMap(),r=n.getGLRes(),s=e.boundingVolume.region;let{ws:i,en:o}=function(t){const e=t[0],n=t[1],r=t[2],s=t[3],i=t[4],o=t[5],a=Zt([],e,n,i),c=Zt([],r,s,o),h=re(a,a),u=re(c,c);return{ws:h,en:u}}(s);i=new t.Coordinate(i),o=new t.Coordinate(o);const a=n.coordToPointAtRes(i,r);a.z=n.altitudeToPoint(i.z,r);const c=n.coordToPointAtRes(o,r);c.z=n.altitudeToPoint(o.z,r);const h=[c.x,a.y,c.z,c.x,c.y,c.z,a.x,c.y,c.z,a.x,a.y,c.z,c.x,a.y,a.z,c.x,c.y,a.z,a.x,c.y,a.z,a.x,a.y,a.z],u=[(h[0]+h[18])/2,(h[1]+h[19])/2,(h[2]+h[20])/2],l=n.pointAtResToCoord(new t.Point(u),r);l.z=(i.z+o.z)/2;const f=this.lt(e.V).Ut,d=[h.slice(21,24),h.slice(3,6)];if(f)for(let t=0;t<h.length;t+=3)h[t]-=f[0],h[t+1]-=f[1],h[t+2]-=f[2];return{bbox:d,boxPosition:h,pointCenter:u,coordCenter:l}}wn(t){const e=this.getRenderer(),n=this.getMap(),r="identity"===n.getProjection().code.toLowerCase(),s=n.getGLRes(),o=t.boundingVolume.box,a=o.slice(0,3),c=this.Tn(o,t.matrix),h=(l=a,new us((u=c)[0],u[3],u[6],l[0],u[1],u[4],u[7],l[1],u[2],u[5],u[8],l[2],0,0,0,1));var u,l;const f=this.On(t),d=[],m=this.lt(t.V).Ut;ts.set(m[0],m[1]);const p=n.pointAtResToCoord(ts,s),b=Jr;for(let t=0;t<is.length;t+=3){b[0]=is[t],b[1]=is[t+1],b[2]=is[t+2],i.transformMat4(b,b,h),re(b,b),r&&e.Ve(b,b);const o=Wr.set(...b);let a=n.coordToPointAtRes(o,s,ts);a=i.set(b,a.x,a.y,n.altitudeToPoint(o.z,s)),d[t]=a[0]-m[0],d[t+1]=a[1]-m[1],d[t+2]=a[2]-m[2]}return{obbox:this._n(d,m,f),boxPosition:d,boxCenter:f,coordCenter:p}}vn(e){const n=this.getMap(),r=this.getRenderer(),s="identity"===n.getProjection().code.toLowerCase(),i=e.boundingVolume.sphere,o=i;let a=Jr;0===o[0]&&0===o[1]&&0===o[2]?a=[0,0,-6378137]:re(a,o),s&&r.Ve(a,a);const c=new t.Coordinate(a),h=this.Jt(c,ts).toArray();h[2]=n.altitudeToPoint(c.z,n.getGLRes());const u=this.Mn(c);return[h,i[3]*u[2]]}_n(t,e,n){const[r,s,o]=e,a=i.set(Jr,(t[3]+t[12])/2+r,(t[4]+t[13])/2+s,(t[5]+t[14])/2+o),c=i.set(Qr,(t[3]+t[18])/2+r,(t[4]+t[19])/2+s,(t[5]+t[20])/2+o),h=i.set(Kr,(t[3]+t[9])/2+r,(t[4]+t[10])/2+s,(t[5]+t[11])/2+o),u=n.slice(0);return u[3]=a[0]-n[0],u[4]=a[1]-n[1],u[5]=a[2]-n[2],u[6]=c[0]-n[0],u[7]=c[1]-n[1],u[8]=c[2]-n[2],u[9]=h[0]-n[0],u[10]=h[1]-n[1],u[11]=h[2]-n[2],u}On(e){const n=this.getMap(),r=this.getRenderer(),s="identity"===n.getProjection().code.toLowerCase(),i=n.getGLRes(),o=e.boundingVolume.box.slice(0,3);re(o,o),s&&r.Ve(o,o);const a=new t.Coordinate(o),c=n.coordToPointAtRes(a,i);return[c.x,c.y,n.altitudeToPoint(a.z,i)]}pn(t){const e=this.H(t.V);if(!t.boundingVolume||this.xn(t,e))return;const n=t.boundingVolume.box,r=t.boundingVolume.region,s=t.boundingVolume.sphere;let i=null;if(n){i=this.An(t).pointCenter}else if(r){i=this.In(t).pointCenter}else s&&(i=this.vn(t)[0]);const o=e.heightOffset||0,a=e.coordOffset||[0,0];t.Sn=[a[0]||0,a[1]||0],t.dt=o,t.Ut=i}xn(t,e){if(!t.Sn)return!1;const n=e.coordOffset||ss;return t.Sn[0]===n[0]&&t.Sn[1]===n[1]&&t.dt===(e.heightOffset||0)}In(t){if(!t.boundingVolume)return null;this.un(t);return this.yn(t)}An(e){if(!e.boundingVolume)return null;this.un(e);const n=e.boundingVolume.box.slice(0,3);re(n,n);const r=new t.Coordinate(n);return{pointCenter:this.On(e),coordCenter:r}}Tn(t,e){let n=t.slice(3,12);return n=function(t,e,n){const r=t[0]*e[0]+t[3]*e[1]+t[6]*e[2],s=t[1]*e[0]+t[4]*e[1]+t[7]*e[2],i=t[2]*e[0]+t[5]*e[1]+t[8]*e[2],o=t[0]*e[3]+t[3]*e[4]+t[6]*e[5],a=t[1]*e[3]+t[4]*e[4]+t[7]*e[5],c=t[2]*e[3]+t[5]*e[4]+t[8]*e[5],h=t[0]*e[6]+t[3]*e[7]+t[6]*e[8],u=t[1]*e[6]+t[4]*e[7]+t[7]*e[8],l=t[2]*e[6]+t[5]*e[7]+t[8]*e[8];return n[0]=r,n[1]=s,n[2]=i,n[3]=o,n[4]=a,n[5]=c,n[6]=h,n[7]=u,n[8]=l,n}(this.En(e,[]),n,n),n}En(t,e){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[4],e[4]=t[5],e[5]=t[6],e[6]=t[8],e[7]=t[9],e[8]=t[10],e}Mn(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(Zr,n.x/100*1.01,n.y/100*1.01,r),Zr}dn(e){Array.isArray(e)&&(e=new t.Coordinate(e));let n=this.options.offset;if(dt(n)&&(n=n.call(this,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._sub(n),t.pointAtResToCoord(s,r)}return e}lt(t){return this.Re[t]}nn(e){const n=this.H(e).maxExtent;if(!n)return null;const r=this.Re[e];return r.maxExtent||(r.maxExtent=new t.Extent(n).convertTo(t=>this.Jt(t))),r.maxExtent}gn(t){const e=this.tn,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.Nn||(t.Nn=new Vr(t.boundingVolume.region));return t.Nn.distanceToCamera(e,n)}(t,this.We,this.Ye):t.boundingVolume.sphere?s=as(t.boundingVolume,this.We):t.boundingVolume.box&&(s=cs(t.boundingVolume,this.We));const i=Math.max(Math.abs(s),1e-7),o=n*r.height/(i*e);return t.bt=s,t.Me=o,o}Ke(){const t=this.getRenderer();t&&t.setToRedraw()}Ft(t){return this.Bt[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&&It(n,r)}const r=this.getMap(),s=this.getRenderer();if(!r||!s)return[];const i=r.getDevicePixelRatio();return It(n,s.pick(t.x*i,t.y*i,e)),n}getCurrentBatchIDs(){const t=this.getMap(),e=this.getRenderer();return t&&e?e.Kt():[]}highlight(t){const e=this.getRenderer();return e?(e.highlight(t),this):(this.J||(this.J=[]),this.J.push(t),this)}ze(){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.Z||(this.Z=[]),this.Z.push(t),this)}Cn(){if(this.Z){for(let t=0;t<this.Z.length;t++)this.showOnly(this.Z[t]);delete this.Z}}cancelShowOnly(t){const e=this.getRenderer();return e?(e.cancelShowOnly(t),this):this}setServiceOpacity(t,e){const n=this.options.services[t];n&&(n.opacity=e);const r=this.getRenderer();return r?(r.setToRedraw(),this):this}setServiceDebugBoundingVolume(t,e){const n=this.options.services[t];n&&(n.debugShowBoundingVolume=e);const r=this.getRenderer();return r?(r.setToRedraw(),this):this}Ze(t){const e=this.getMap(),n=e.getGLRes();ns.set(t[0],t[1]);const r=e.pointAtResToCoord(ns,n);return"identity"===e.getProjection().code.toLowerCase()?(Qr[0]=r.x,Qr[1]=r.y,this.getRenderer().qe(Jr,Qr),r.set(Jr[0],Jr[1]),r):r}toJSON(){return{"type":this.getJSONType(),"id":this.getId(),"options":this.config()}}}function as(t,e){const n=t.sphere,r=i.dist(n,e),s=t.sphere[3];return r<s?0:r-s}function cs(t,e){const n=t.box;return Tr(i.set(Jr,n[0],n[1],n[2]),a.set(es,n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10],n[11]),e)}function hs(t,e,n){const s=(t=yt(t)).indexOf("{s}")>=0?"{s}":t.indexOf("%7Bs%7D")>=0?"%7Bs%7D":null;return{service:n,visible:lt(n.visible)?1:n.visible,baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:r.identity([]),V:e,W:0,domainKey:s}}function us(t,e,n,r,s,i,o,a,c,h,u,l,f,d,m,p){this[0]=t||0,this[1]=s||0,this[2]=c||0,this[3]=f||0,this[4]=e||0,this[5]=i||0,this[6]=h||0,this[7]=d||0,this[8]=n||0,this[9]=o||0,this[10]=u||0,this[11]=m||0,this[12]=r||0,this[13]=a||0,this[14]=l||0,this[15]=p||0}os.mergeOptions($r),os.registerRenderer("gl",yr),os.registerJSONType("Geo3DTilesLayer");let ls=null;function fs(){return ls||(ls={"image/crn":tr.crn&&tr.crn(),"image/ktx2":tr.ktx2&&tr.ktx2(),"image/cttf":tr.ktx2&&tr.ktx2(),"draco":tr.draco&&tr.draco()}),ls}class ds{constructor(t,e,n){this.Pn=t,this.Rn=e||p,this.Pe=n,this.Ln=fs()}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.kn(t,e,n,r,s)):b.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.kn(t,s,n,r)})}kn(t,e,n,r,s){const i=s&&s.maxTextureSize,o=this.Bn(e,n,r,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.Rn(a,o.glb,{transferable:!0,requestImage:this.Pn,decoders:this.Ln,supportedFormats:this.Pe,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}})}Bn(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported b3dm version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in b3dm header is inconsistent with b3dm's byte length, url: "+r;return console.warn(t),{error:t}}let o,a=s.getUint32(12,!0),c=s.getUint32(16,!0),h=s.getUint32(20,!0),u=s.getUint32(24,!0),l=28+e;h>=570425344?(l-=8,o=a,h=c,u=0,a=0,c=0):u>=570425344&&(l-=4,o=h,h=a,u=c,a=0,c=0);const f=[t];let d,m,p;if(a>0?(d=me(t,l,a),l+=a,o=d.BATCH_LENGTH):d={"BATCH_LENGTH":o},c>0&&(l+=c),h>0&&(m=pe(t,l,h),l+=h,u>0)){const e=be(0,l,u);p=t.slice(e.offset,e.offset+e.byteLength),l+=u,f.push(p)}const b=d.BATCH_LENGTH,g={};if(d&&d.BATCH_ID){g.BATCH_ID=ye(d.BATCH_ID,t,(void 0).offset,b);const e=g.BATCH_ID.array&&g.BATCH_ID.array.buffer;e&&f.indexOf(e)<0&&f.push(e)}return{count:o,transferables:f,featureTable:d,batchTable:m,batchTableBin:p,b3dm:g,glb:{buffer:t,byteOffset:l,byteLength:s.byteLength+s.byteOffset-l}}}Un(){return null}}class ms{constructor(t,e,n,r){this.Pn=t,this.Rn=e||p,this.Pe=n,this.Ln=fs(),this.Fn=r}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.kn(t,e,n,r,s)):b.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.kn(t,s,n,r)})}kn(t,e,n,r,s){return this.Dn(t,e,n,r,s).then(({gltf:s,transferables:i})=>{const o=this.zn(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})})}Dn(t,e,n,r,s){const i=s&&s.maxTextureSize,o={transferable:!0,requestImage:this.Pn,decoders:this.Ln,supportedFormats:this.Pe,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=Tt(new Uint8Array(e,c+n,a.byteLength-c));-1==r.indexOf("://")&&(r=t.substring(0,t.lastIndexOf("/"))+"/"+r);return r.indexOf(".glb")>0?b.getArrayBuffer(r,{}).then(t=>this.jn(r,{buffer:t.data,byteOffset:0},o)):b.getJSON(r,{}).then(t=>this.jn(r,t,o))}{const r={buffer:e,byteOffset:c+n,byteLength:a.byteLength-c};return this.jn(t,r,o)}}jn(t,e,n){const r=t.substring(0,t.lastIndexOf("/")),s=new this.Rn(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}})}zn(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}=Ae(s,32+e,o),l={},f=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;l.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,n=a.QUANTIZED_VOLUME_SCALE,{byteOffset:r}=a.POSITION_QUANTIZED;l.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.Gn(new Uint16Array(t,r+c.offset,3*f),e,n)},o.push(l.POSITION.array.buffer)}if(a.BATCH_ID){l.BATCH_ID=ye(a.BATCH_ID,t,c.offset,f);const e=l.BATCH_ID.array&&l.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;l.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,l.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;l.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.Hn(new Uint16Array(t,e+c.offset,2*f))},o.push(l.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,l.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.Hn(new Uint16Array(t,e+c.offset,2*f))},o.push(l.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;l.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,f).slice()},o.push(l.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;l.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.SCALE_NON_UNIFORM.array.buffer)}return{count:f,batchTable:h,batchTableBin:u,featureTable:a,i3dm:l,transferables:o}}Hn(t){const e=t.length/2,n=new Float32Array(3*e),r=[];for(let s=0;s<e;s++)ps(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}Gn(t,e,n){return xe(new Float32Array(t.length),t,e,n)}Un(){return null}}function ps(t,e,n,r){if(t[0]=bs(e,r),t[1]=bs(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]))*gs(e),t[1]=(1-Math.abs(e))*gs(t[1])}return w.normalize(t,t)}function bs(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 gs(t){return t<0?-1:1}class ys{constructor(){}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.kn(t,e,n,r)):b.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.kn(t,s,n,r)})}kn(t,e,n,r){return this.Vn(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})}Vn(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}=Ae(s,e+28,o),l=a.QUANTIZED_VOLUME_OFFSET,f=a.QUANTIZED_VOLUME_SCALE,d=a.POINTS_LENGTH;let m,p={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){p=a.extensions["3DTILES_draco_point_compression"],m=new DataView(t,p.byteOffset+c.offset,p.byteLength);const e={attributes:p.properties,useUniqueIDs:!1};return this.qn||(this.qn=fs().draco),this.qn(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.$n(t,e.attributes,c.offset,d,o,l,f);if(e.attributes.BATCH_ID){const t=e.attributes.BATCH_ID.array;r.BATCH_ID={byteStride:0,byteOffset:0,itemSize:1,count:t.length,componentType:Me(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?r.BATCH_ID=ye(a.BATCH_ID,t,c.offset,d):r.BATCH_ID=ws(d);const e=r.BATCH_ID.array&&r.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return{count:d,batchTable:h,batchTableBin:u,featureTable:a,pnts:r,transferables:o}})}const b=this.$n(t,a,c.offset,d,o,l,f);if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?b.BATCH_ID=ye(a.BATCH_ID,t,c.offset,d):b.BATCH_ID=ws(d);const e=b.BATCH_ID.array&&b.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:d,batchTable:h,batchTableBin:u,featureTable:a,pnts:b,transferables:o})}$n(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.Gn(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}Gn(t,e,n){return xe(new Float32Array(t.length),t,e,n)}Un(){return null}}function ws(t){const e=Mt(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:Me(e),array:n}}class vs{constructor(t,e,n,r){this.Pe=n,this.Pn=t,this.Rn=e||p,this.Fn=r}load(t,e,n=0,r=0,s){return e?this.kn(t,e,n,r,s):b.getArrayBuffer(t,{}).then(e=>{const s=e.data;return this.kn(t,s,n,r)})}kn(t,e,n,r,s){r||(r=e.byteLength);const i=this.Xn(e,t,n,r),o=[];for(let n=0;n<i.length;n++){let r;if("b3dm"===i[n].magic)r=new ds(this.Pn,this.Rn,this.Pe);else if("i3dm"===i[n].magic)r=new ms(this.Pn,this.Rn,this.Pe,this.Fn);else if("pnts"===i[n].magic)r=new ys;else{if("cmpt"!==i[n].magic){console.warn("Unsupported magic in CMPT tile:",i[n].magic);continue}r=new vs(this.Pn,this.Rn,this.Pe,this.Fn)}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}))}Xn(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=fe(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);t.registerWorkerAdapter("@maptalks/3dtiles",n)}else t.registerWorkerAdapter("@maptalks/3dtiles",(function(){return e.transcoders.inject(T)}))}else t.registerWorkerAdapter("@maptalks/3dtiles",T);export{ds as B3DMLoader,vs as CMPTLoader,os as Geo3DTilesLayer,Nt as Geo3DTilesUtil,ue as Geo3DTransform};"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.95.8");
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @maptalks/3dtiles v0.95.7
2
+ * @maptalks/3dtiles v0.95.8
3
3
  * LICENSE : UNLICENSED
4
4
  * (c) 2016-2024 maptalks.org
5
5
  */
@@ -20,4 +20,4 @@ let ee=0;function ne(t){return null==t}function re(t){return!ne(t)}function se(t
20
20
  * @maptalks/gl v0.95.6
21
21
  * LICENSE : UNLICENSED
22
22
  * (c) 2016-2024 maptalks.com
23
- */(100,1),os=[0,0,0,1],as=[1,1,1];class cs{constructor(t,e){this.rt=e,this.st=e.getRenderer().canvas,this.pickingFBO=e.getRenderer().pickingFBO,this.it=new s.SpatialReference,this.ot=t,this.ct=new n.reshader.Renderer(t),this.ht={},this.ut={},this.lt={},this.ft={},this.dt={},this.pt={},this.bt=new n.reshader.Scene,this.gt=new n.reshader.Scene,this.yt=new n.reshader.Scene,this.wt=new n.reshader.Scene,this.vt=new n.reshader.ResourceLoader(t.texture(2)),this.Tt=this._t.bind(this),this.Mt=new n.reshader.PhongMaterial({"baseColorFactor":[1,1,1,1]}),this.Ot(),this.xt=new n.reshader.KHRTechniquesWebglManager(this.ot,this.At(),this.vt);const r=this.getMap();r.altitudeToPoint&&(this.It=r.altitudeToPoint(100,r.getGLRes())/100)}getI3DMMeshes(){return this.ft}getPNTSMeshes(){return this.lt}getB3DMMeshes(){return this.ut}getPaintedMeshes(){return this.St}getMap(){return this.rt.getMap()}paint(t,e,r){const s=r&&r.renderTarget,i=r&&r.sceneFilter,o=this.getMap();if(!t.length||!o)return null;const a=this.Et(),c=o.projViewMatrix,h=[],l=[],f=[],d=[],m=[],p=this.Nt(t),b=[];for(let s=0,i=t.length;s<i;s++){const i=t[s].data.node;let o=this.Ct(i);if(!o)continue;const a=this.rt.Pt(i.Rt);i.kt&&a.debugShowBoundingVolume&&b.push(i.kt);const g=a.heightOffset||0,y=a.coordOffset||Dr;this.dt[i.id]&&(o=this.dt[i.id],o=gt(o));let w=a.polygonOffset||Rr;at(w)&&(w=w()),Array.isArray(o)||(h[0]=o,o=h);for(let t=0,s=o.length;t<s;t++){const s=o[t].properties.magic;if(o[t].properties.heightOffset===g&&o[t].properties.coordOffset[0]===y[0]&&o[t].properties.coordOffset[1]===y[1]||(this.Lt(o[t]),o[t].Bt=n.mat4.copy([],o[t].localTransform)),"b3dm"===s){if(o[t].getBoundingBox&&!u(c,o[t].getBoundingBox()))continue;const{batchIdData:e,batchIdMap:s}=o[t].geometry.properties;if(e&&s){const e=o[t].properties.node.Rt;this.Ut&&this.Ut[e]?n.HighlightUtil.highlightMesh(this.ot,o[t],this.Ut[e],this.Ft,s):this.Ut&&this.Ut[e]||n.HighlightUtil.highlightMesh(this.ot,o[t],null,this.Ft,s),n.HighlightUtil.showOnly(this.ot,o[t],this.Dt&&this.Dt[e],this.jt,s)}r&&r.bloom&&o[t].properties.hlBloomMesh&&(o[t].properties.hlBloomMesh.properties.depthFunc="always",o[t].properties.hlBloomMesh.properties.polygonOffset=w,f.push(o[t].properties.hlBloomMesh)),f.push(o[t])}else"pnts"===s?d.push(o[t]):"i3dm"===s&&m.push(o[t]);o[t].properties.isLeaf=!!e[i.id],o[t].properties.level=p.get(i.zt),o[t].properties.polygonOffset=w,o[t].Ht=i,e[i.id]||l.push(o[t]),this.Gt(o[t]),this.qt(o[t],i)}}let g=0;const y=this.xt.getExcludeFilter();g+=this.Vt(this.$t,a,[i,jr,y],s,l,f,m),g+=this.Vt(this.Xt,a,[i,zr,y],s,l,f,m),this.xt.forEachShader((t,e,n)=>{const r=this.Et(n);g+=this.Vt(t,r,[i,e],s,l,f,m)}),this.gt.setMeshes(d);const w=this.Jt();return g+=this.ct.render(this.Kt,w,this.gt,s&&s.fbo),this.St={pntsMeshes:d,i3dmMeshes:m,b3dmMeshes:f},b.forEach(t=>{this.Qt(t)}),this.wt.setMeshes(b),this.ct.render(this.Zt,a,this.wt,s&&s.fbo),g}Qt(t){const e=t.properties.node,r=this.rt.Pt(e.Rt),s=this.rt.Yt(e.Rt),i=r.heightOffset||0,o=this.Wt(),a=s.te,c=n.vec3.set(es,0,0,o*(i-a));let h=r.rotation||[0,0,0];h=n.quat.fromEuler(Yr,h[0],h[1],h[2]);const u=r.scale||[1,1,1],l=n.mat4.fromRotationTranslationScale(Zr,h,c,u);n.mat4.multiply(t.localTransform,t.Bt,l)}Vt(t,e,n,r,s,i,o){t.filter=n.filter(t=>!!t),e.debug=!1,e.debug=!1;let a=0;return this.bt.setMeshes(i),a+=this.ct.render(t,e,this.bt,r&&r.fbo),this.yt.setMeshes(o),a+=this.ct.render(t,e,this.yt,r&&r.fbo),a}ee(t,e){return e.Ht.ne-t.Ht.ne}deleteTile(t){const e=t.node;e.kt&&(e.kt.geometry.dispose(),e.kt.dispose(),delete e.kt);const n=e.id;this.re(n)}re(t){const e=this.ut[t]||this.lt[t]||this.ft[t]||this.dt[t]||this.ht[t];this.dt[t]?this.se(t):e&&(this.ie(e),delete this.ut[t],delete this.lt[t],delete this.ft[t],delete this.ht[t])}se(t){let e=this.dt[t];e=gt(e);for(let t=0;t<e.length;t++){const{id:n}=e[t].properties;this.re(n)}delete this.dt[t]}ie(t){if(Array.isArray(t))for(let e=0,n=t.length;e<n;e++)this.ie(t[e]);else{n.HighlightUtil.showOnly(this.ot,t),n.HighlightUtil.highlightMesh(this.ot,t);const e=t.geometry.properties.url;if(e){const n=this.pt[e];n&&n.refMeshes&&(n.refMeshes.delete(t.uuid),n.refMeshes.size||(n.geometry.dispose(),n.material.dispose(),delete this.pt[e]))}else t.geometry.dispose(),t.material&&t.material.dispose();t.dispose()}}remove(){const t=this.rt;Nr(t.getRenderer().canvas,t.getMap());for(const t in this.dt)this.se(t);this.dt={};for(const t in this.ut)this.re(t);this.ut={};for(const t in this.lt)this.re(t);this.lt={};for(const t in this.ft)this.re(t);this.ft={};for(const t in this.ht)this.re(t);this.ht={},this.$t&&(this.$t.dispose(),delete this.$t),this.Xt&&(this.Xt.dispose(),delete this.Xt),this.Kt&&(this.Kt.dispose(),delete this.Kt),this.Zt&&(this.Zt.dispose(),delete this.Zt),this.xt.dispose(),this.picking&&this.picking.dispose()}Ct(t){return this.ut[t.id]||this.lt[t.id]||this.ft[t.id]||this.dt[t.id]}has(t){return this.Ct(t)||this.ht[t.id]}Lt(t){const e=t.properties.magic;"b3dm"===e?this.oe(t):"i3dm"===e?this.ae(t):"pnts"===e&&this.ce(t)}createPntsMesh(t,e,r,s){if(this.lt[e]){const t=this.lt[e];return console.warn(`pnts mesh with id(${e}) was already created.`),s(null,{id:e,mesh:t}),t}const{pnts:i,featureTable:o,rootIdx:a,compressed_int16_params:c}=t,h=o.POINTS_LENGTH;i.BATCH_ID||(i.BATCH_ID=new Uint8Array(h),i.BATCH_ID.fill(0));const u=new n.reshader.Geometry(i,null,h,{static:!0,primitive:"points",positionAttribute:"POSITION",pickingIdAttribute:"BATCH_ID"});u.generateBuffers(this.ot);const l={};i.POSITION?l.HAS_POSITION=1:i.POSITION_QUANTIZED&&(l.HAS_POSITION_QUANTIZED=1),i.RGB?l.HAS_RGB=1:i.RGBA?l.HAS_RGBA=1:i.RGB565&&(l.HAS_RGB565=1),(i.NORMAL||i.NORMAL_OCT16P)&&(l.HAS_NORMAL=1,i.NORMAL_OCT16P&&(l.HAS_NORMAL_OCT16P=1)),this.he(l,c),t.featureTable.CONSTANT_RGBA&&(t.featureTable.CONSTANT_RGBA=t.featureTable.CONSTANT_RGBA.map(t=>t/255));const{rtcCenter:f,rtcCoord:d,projCenter:m}=t,p=this.rt.Pt(a),b=new n.reshader.Mesh(u);b.properties.magic="pnts",b.properties.id=e,b.properties.node=r,b.properties.count=h,b.properties.batchTable=t.batchTable,b.properties.batchTableBin=t.batchTableBin,b.properties.serviceIndex=a,b.properties.rtcCoord=d,b.properties.rtcCenter=f,b.properties.projCenter=m,b.setDefines(l),Object.defineProperty(b.uniforms,"pointColor",{enumerable:!0,get:function(){return t.featureTable.CONSTANT_RGBA?t.featureTable.CONSTANT_RGBA:p&&p.pointColor||[1,1,1,1]}});const g=this.getMap();let y=null,w=null;Object.defineProperty(b.uniforms,"pointSize",{enumerable:!0,get:function(){if(!p)return 2;if(yr(p.pointSize)){const t=JSON.stringify(p.pointSize);t!==y&&(w=wr(p.pointSize),y=t);return w(g.getZoom())}return p.pointSize||2}});let v=null,T=null;return Object.defineProperty(b.uniforms,"pointOpacity",{enumerable:!0,get:function(){if(!p)return 1;if(yr(p.pointOpacity)){const t=JSON.stringify(p.pointOpacity);t!==v&&(T=wr(p.pointOpacity),v=t);return T(g.getZoom())}return p.pointOpacity||1}}),this.ue(b,c),this.ce(b),b.Bt=n.mat4.copy([],b.localTransform),this.lt[e]=b,s(null,{id:e,mesh:[b]}),[b]}ce(t){const e=t.localTransform||[],{rtcCoord:n,node:r,projCenter:s}=t.properties;this.le(e,n,s,r.Rt),t.setLocalTransform(e)}createI3DMMesh(t,e,r,s){if(this.ft[e]){const t=this.ft[e];return console.warn(`i3dm mesh with id(${e}) was already created.`),this.ht[e]||s(null,{id:e,mesh:t}),t}const i=this.rt.Pt(r.Rt),o=this.fe(r.de),{i3dm:a,featureTable:c,gltf:h,batchTable:u,batchTableBin:l,count:f}=t,d=c.INSTANCES_LENGTH,{rtcCenter:m,rtcCoord:p}=t,b=this.me(Kr,p),g=this.pe(Qr,r,m,p);n.mat4.multiply(b,g,b);const{POSITION:y,NORMAL_UP:w,NORMAL_RIGHT:v,SCALE:T,SCALE_NON_UNIFORM:_,INSTANCE_ROTATION:M}=a,O={"instance_vectorA":new Float32Array(4*d),"instance_vectorB":new Float32Array(4*d),"instance_vectorC":new Float32Array(4*d),"aPickingId":new Uint16Array(d)};for(let t=0;t<d;t++)O.aPickingId[t]=t;const x=new Float32Array(3),A=new Float32Array(3),I=[],S=new Float32Array(1),E=new Float32Array(3),N=[],C=[],P=[],R=[],k=new Float32Array(9);!function(t,e){let{byteOffset:n,byteStride:r,count:s}=t;const{componentType:i,itemSize:o}=t,a=t.array.buffer,c=i?Ue.getTypedArrayCtor(i):t.array.constructor;if(n=void 0===n?t.array.byteOffset:n,r=r||0,s=s||t.array.length/o,(!r||r===o*c.BYTES_PER_ELEMENT)&&n%c.BYTES_PER_ELEMENT==0){const t=new c(a,n,s*o);for(let r=0;r<s*o;r+=o){e(new c(t.buffer,n+r*c.BYTES_PER_ELEMENT,o),r/o)}return}const h=new Uint8Array(o*c.BYTES_PER_ELEMENT);r||(r=o*c.BYTES_PER_ELEMENT);for(let t=0;t<s;t++){const s=new Uint8Array(a,r*t+n,o*c.BYTES_PER_ELEMENT);h.set(s);e(new c(h.buffer),t),s.set(h)}}(y,(t,e)=>{w?(rn(A,v,e),rn(x,w,e),n.vec3.cross(I,A,x),n.vec3.normalize(I,I),bt(N,A,0),bt(N,x,1),bt(N,I,2),n.quat.fromMat3(C,N)):M?(rn(k,M,e),n.quat.fromMat3(C,k)):n.quat.identity(C),T?(rn(S,T,e),n.vec3.set(P,S[0],S[0],S[0])):_?(rn(E,_,e),n.vec3.set(P,...E)):n.vec3.set(P,1,1,1),n.mat4.fromRotationTranslationScale(R,C,t,P),sn(O.instance_vectorA,e,R,0),sn(O.instance_vectorB,e,R,1),sn(O.instance_vectorC,e,R,2)});const L={};for(const t in O)L[t]={buffer:this.ot.buffer({dimension:O[t].length/d,data:O[t]}),divisor:1};const B=i.shader||"pbr";let U=0,F=!0;const D=[],j=[];return Ke(h,(t,s,i,a)=>{const c=this.be(t,s,i,a,r,!0,B,j),{geometry:h,material:g}=c;g&&!g.isReady()&&(F=!1,U++);const y=new n.reshader.InstancedMesh(L,d,h,g);c.refMeshes||(c.refMeshes=new Set,c.refMeshes.add(y.uuid)),y.properties.magic="i3dm",y.properties.id=e,y.properties.count=f,y.properties.batchTable=u,y.properties.batchTableBin=l,y.properties.serviceIndex=r.Rt,y.properties.rtcCoord=p,y.properties.rtcCenter=m,y.properties.node=r;const w=this.ge(t,h,g,r.Rt,a);t.compressed_int16_params&&this.ue(y,t.compressed_int16_params),this.ye(y,t.attributes);const v=n.mat4.identity([]);if(t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)n.mat4.multiply(v,v,t.matrices[e]);n.mat4.multiply(v,o,v),y.setPositionMatrix(v),this.ae(y,b),y.setDefines(w),y.properties.polygonOffset={offset:0,factor:0},D.push(y),delete t.attributes,y.Bt=n.mat4.copy([],y.localTransform)}),hs(j),F?(this.ft[e]=D,s(null,{id:e,mesh:D})):(this.ht[e]={meshes:D,count:U},D.we=s),D}ae(t,e){const{rtcCenter:r,rtcCoord:s,node:i}=t.properties;if(!e){e=this.me(Kr,s);const t=this.pe(Qr,i,r,s);n.mat4.multiply(e,t,e)}const o=this.rt.Pt(i.Rt),a=t.localTransform||[];if(o.coordOffset){const t=this.ve(Qr,i.Rt,s);n.mat4.multiply(a,t,e)}else n.mat4.copy(a,e);t.setLocalTransform(a),t.properties.heightOffset=o.heightOffset||0,t.properties.coordOffset=o.coordOffset&&o.coordOffset.slice(0)||Dr}createB3DMMesh(t,e,r,i){if(t.gltf&&(t.gltf.transferables=null),this.ut[e]||this.ht[e]){const t=this.ut[e];return console.warn(`mesh with id(${e}) was already created.`),this.ht[e]||i(null,{id:e,mesh:t}),t}let o;if(r.maxExtent){const t=new s.Extent(r.maxExtent).convertTo(t=>this._pointToPrj(t));o=[t.xmin,t.ymin,t.xmax,t.ymax]}const a=t.gltf,{projCenter:c}=a.extensions.MAPTALKS_RTC,{rtcCoord:h,center:u}=a.extensions.CESIUM_RTC,l=a.asset.sharePosition,f=this.fe(r.de);let d;d=l?this.me(Kr,h):this.le(Kr,h,c,r.Rt);const m=this.rt.Pt(r.Rt);let p=m.shader||"pbr";if(m.unlit)p="phong";else if(a.materials)for(let t=0;t<a.materials.length;t++)if(a.materials[t]&&a.materials[t].extensions&&a.materials[t].extensions.KHR_materials_unlit){p="phong";break}const b=[],g=[];let y=0,w=!0;return Ke(a,(s,i,a,v)=>{const T=this.be(s,i,a,v,r,!1,p,b),{geometry:_,material:M}=T;M&&!M.isReady()&&(w=!1,y++);const O=new n.reshader.Mesh(_,M);T.refMeshes||(T.refMeshes=new Set,T.refMeshes.add(O.uuid)),O.properties.magic="b3dm",O.properties.id=e,O.properties.node=r,t.batchTable&&(O.properties.batchTable=t.batchTable,O.properties.batchTableBin=t.batchTableBin),O.properties.count=t.featureTable&&t.featureTable.BATCH_LENGTH||0,O.properties.serviceIndex=r.Rt;const x=this.ge(s,_,M,r.Rt,v);O.setDefines(x);const A=s.compressUniforms;if(A)for(const t in A)O.setUniform(t,A[t]);s.compressed_int16_params&&this.ue(O,s.compressed_int16_params),this.ye(O,s.attributes),o&&(x.USE_MAX_EXTENT=1,O.setUniform("maxPrjExtent",o)),Object.prototype.hasOwnProperty.call(O.uniforms,"polygonOpacity")||Object.defineProperty(O.uniforms,"polygonOpacity",{enumerable:!0,get:function(){return ht(m.opacity)?m.opacity:1}}),Object.prototype.hasOwnProperty.call(O.uniforms,"polygonFill")||Object.defineProperty(O.uniforms,"polygonFill",{enumerable:!0,get:function(){return Mt([],m.polygonFill||kr)}}),Object.prototype.hasOwnProperty.call(O.material.uniforms,"hsv")||Object.defineProperty(O.material.uniforms,"hsv",{enumerable:!0,get:function(){return m.hsv||Lr}});const I=n.mat4.identity([]);if(l&&s.matrices&&s.matrices.length)for(let t=0;t<s.matrices.length;t++)n.mat4.multiply(I,I,s.matrices[t]);l&&n.mat4.multiply(I,f,I),O.properties.node=r,O.properties.projCenter=c,O.properties.nodeMatrix=I,O.properties.isSharedPosition=l,O.properties.rtcCoord=h,O.properties.rtcCenter=u,this.oe(O,d),g.push(O),delete s.attributes,O.Bt=n.mat4.copy([],O.localTransform)}),hs(b),w?(this.ut[e]=g,i(null,{id:e,mesh:g})):(this.ht[e]={meshes:g,count:y},g.we=i),g}Te(t){const e=this.rt._e[t.id];if(!e)return;let r,s,i,o;if(e.length){if(2===e.length){const t=e[0],n=e[1];r=is.vertices,s=is.indices,i=t,o=[n,n,n]}}else{r=e.boxPosition,s=ss;i=this.rt.Yt(t.Rt).Me,o=as}const a=new n.reshader.Geometry({POSITION:r},s,0,{primitive:"lines",positionAttribute:"POSITION"}),c=new n.reshader.Mesh(a,new n.reshader.Material({lineColor:[.8,.8,.1,1],lineOpacity:1})),h=n.mat4.identity([]);n.mat4.fromRotationTranslationScale(h,os,i,o),c.localTransform=h,c.Bt=n.mat4.copy([],h),c.properties.node=t,t.kt=c}ue(t,e){e.POSITION&&t.setUniform("compressedPositionRange",e.POSITION),e.TEXCOORD_0&&t.setUniform("compressedTexcoordRange_0",e.TEXCOORD_0),e.TEXCOORD_1&&t.setUniform("compressedTexcoordRange_1",e.TEXCOORD_0),e.NORMAL&&t.setUniform("compressedNormalRange",e.NORMAL),e.TANGENT&&t.setUniform("compressedTangentRange",e.TANGENT),e.compressed_ratio&&t.setUniform("compressed_ratio",e.compressed_ratio)}oe(t,e){const{isSharedPosition:r,rtcCoord:s,rtcCenter:i,projCenter:o,nodeMatrix:a,node:c}=t.properties;e||(e=r?this.me(Kr,s):this.le(Kr,s,o,c.Rt));const h=t.localTransform||n.mat4.identity([]);if(r){const t=this.pe(Qr,c,i,s);n.mat4.multiply(h,e,a),n.mat4.multiply(h,t,h)}else n.mat4.multiply(h,e,a);const u=this.rt.Pt(c.Rt);if(u.coordOffset){const t=this.ve(Qr,c.Rt,s);n.mat4.multiply(h,t,h)}t.setLocalTransform(h),t.properties.heightOffset=u.heightOffset||0,t.properties.coordOffset=u.coordOffset&&u.coordOffset.slice(0)||Dr}ye(t,e){if(e&&e.TEXCOORD_0&&e.TEXCOORD_0.extensions&&e.TEXCOORD_0.extensions.WEB3D_quantized_attributes){const n=e.TEXCOORD_0.extensions.WEB3D_quantized_attributes.decodeMatrix;t.setUniform("decodeMatrix",n)}}pe(t,e,r,i){const o=this.getMap(),a=this.rt.Pt(e.Rt).heightOffset||0,c=new s.Coordinate(i);let h;h=o.altitudeToPoint?this.It:o.distanceToPointAtRes(100,100,o.getGLRes(),c).y/100;const u=e.matrix?n.mat4.copy(t,e.matrix):n.mat4.identity(t);if(r){Jn(u,n.vec3.transformMat4(Hr,r,u),u)}const l=function(t,e,n,r,s,i,o){e=Bt(Qn,e);const a=un(Qn,e[0]*ir,e[1]*ir,e[2]),c=function(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}(Zn,n),h=r.ellipsoid;let u;u=0===Xt(c)?Ut(Yn,0,0,-6378137):bn(Yn,c),rr.x=u[0],rr.y=u[1];const l=r.project(rr,sr);Wn[0]=l.x/s,Wn[1]=l.y/s,Wn[2]=(u[2]+o)*i;const f=Kn(a,h,tr),d=function(t,e,n){const r=t[0],s=t[1],i=t[2],o=t[4],a=t[5],c=t[6],h=t[8],u=t[9],l=t[10],f=e[0],d=e[1],m=e[2],p=e[3],b=e[4],g=e[5],y=e[6],w=e[7],v=e[8],T=r*f+o*d+h*m,_=s*f+a*d+u*m,M=i*f+c*d+l*m,O=r*p+o*b+h*g,x=s*p+a*b+u*g,A=i*p+c*b+l*g,I=r*y+o*w+h*v,S=s*y+a*w+u*v,E=i*y+c*w+l*v;return n[0]=T,n[1]=_,n[2]=M,n[3]=0,n[4]=O,n[5]=x,n[6]=A,n[7]=0,n[8]=I,n[9]=S,n[10]=E,n[11]=0,n[12]=t[12],n[13]=t[13],n[14]=t[14],n[15]=t[15],n}(function(t,e){var n=e[0],r=e[1],s=e[2],i=e[3],o=e[4],a=e[5],c=e[6],h=e[7],u=e[8],l=e[9],f=e[10],d=e[11],m=e[12],p=e[13],b=e[14],g=e[15],y=n*a-r*o,w=n*c-s*o,v=n*h-i*o,T=r*c-s*a,_=r*h-i*a,M=s*h-i*c,O=u*p-l*m,x=u*b-f*m,A=u*g-d*m,I=l*b-f*p,S=l*g-d*p,E=f*g-d*b,N=y*E-w*S+v*I+T*A-_*x+M*O;return N?(N=1/N,t[0]=(a*E-c*S+h*I)*N,t[1]=(s*S-r*E-i*I)*N,t[2]=(p*M-b*_+g*T)*N,t[3]=(f*_-l*M-d*T)*N,t[4]=(c*A-o*E-h*x)*N,t[5]=(n*E-s*A+i*x)*N,t[6]=(b*v-m*M-g*w)*N,t[7]=(u*M-f*v+d*w)*N,t[8]=(o*S-a*A+h*O)*N,t[9]=(r*A-n*S-i*O)*N,t[10]=(m*_-p*v+g*y)*N,t[11]=(l*v-u*_-d*y)*N,t[12]=(a*x-o*I-c*O)*N,t[13]=(n*I-r*x+s*O)*N,t[14]=(p*w-m*T-b*y)*N,t[15]=(u*T-l*w+f*y)*N,t):null}(er,f),function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t}(nr,n),t);return Jn(t,Wn,d),t}(u,i,u,o.getProjection(),o.getGLRes(),h,a),f=function(t,e){return Ut(t,e[12],e[13],e[14]),t}(Jr,l);let d=this.rt.options.offset;if(at(d)){const t=this.rt.Oe(e.id).center;d=d.call(this.rt,t)}return n.vec3.set(Xr,d[0],d[1],0),n.vec3.sub(f,f,Xr),Jn(l,f,l),l}ve(t,e,r){const s=this.rt.Pt(e);if(!s.coordOffset)return null;const i=this.getMap(),o=i.getGLRes();Gr.set(r[0],r[1]);const a=i.coordToPointAtRes(Gr,o,Vr),c=s.coordOffset,h=Gr.set(r[0]+c[0],r[1]+c[1]),u=i.coordToPointAtRes(h,o,$r),l=u.x-a.x,f=u.y-a.y,d=this.Wt(),m=n.vec3.set(Xr,l,f,(c[2]||0)*d);return n.mat4.fromTranslation(t,m)}Wt(){const t=this.getMap();let e;return e=t.altitudeToPoint?this.It:t.distanceToPointAtRes(100,100,t.getGLRes(),Gr).y/100,e}createCMPTMesh(t,e,n,r){if(this.dt[e]){const t=this.dt[e];return console.warn(`mesh with id(${e}) was already created.`),r(null,{id:e,mesh:t}),t}const{content:s}=t,i=[];for(let t=0;t<s.length;t++){const{magic:r}=s[t],o=e+"."+t;"b3dm"===r?this.createB3DMMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)}):"i3dm"===r?this.createI3DMMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)}):"pnts"===r?this.createPntsMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)}):"cmpt"===r&&this.createCMPTMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)})}return this.dt[e]=i,r(null,{id:e,mesh:i}),i}ge(t,e,n,r,s){const i=("phong"===(this.rt.Pt(r).shader||"pbr")?this.$t:this.Xt).getGeometryDefines(e);s.asset&&"S3M"===s.asset.generator&&this.xe(i,e),e.data.uvRegion&&(i.HAS_I3S_UVREGION=1),e.data[e.desc.normalAttribute]&&(i.VertexNormal=1),e.data[e.desc.color0Attribute]&&(i.VertexColor=1),e.data[e.desc.uv0Attribute]&&(i.TexCoord=1),e.data[e.desc.textureCoordMatrixAttribute]&&(i.HAS_TextureCoordMatrix=1),n.get("uTexture")&&(i.COMPUTE_TEXCOORD=1),n.get("uTexture2")&&(i.TexCoord2=1),"MESHOPT"===this.rt.Ae&&(i.MeshOPT_Compress=1),this.hasIBL()&&(i.HAS_IBL_LIGHTING=1),t.attributes&&t.attributes.TEXCOORD_0&&"WEB3D_quantized_attributes"===t.attributes.TEXCOORD_0.extensions&&(i.HAS_WEB3D_quantized_attributes_TEXCOORD=1),i.HAS_MIN_ALTITUDE=1,i.HAS_LAYER_OPACITY=1,this.he(i,t.compressed_int16_params);return ot(i,t.compressDefines),i}he(t,e){e&&Object.keys(e).length>0&&(t.HAS_COMPRESSED_INT16=1,e.POSITION&&(t.HAS_COMPRESSED_INT16_POSITION=1),e.TEXCOORD_0&&(t.HAS_COMPRESSED_INT16_TEXCOORD_0=1),e.TEXCOORD_1&&(t.HAS_COMPRESSED_INT16_TEXCOORD_1=1),e.NORMAL&&(t.HAS_COMPRESSED_INT16_NORMAL=1),e.TANGENT&&(t.HAS_COMPRESSED_INT16_TANGENT=1),e.compressed_ratio&&(t.HAS_COMPRESSED_INT16_RATIO=1))}Gt(t){const e=this.rt.getRenderer();e&&e.updateMaskDefines(t)}xe(t,e){e.data.aNormal&&(t.VertexNormal=1),e.data.instanceId&&(t.Instance=1),e.data.aTexCoord0&&(t.TexCoord=1),e.data.aColor&&(t.VertexColor=1),e.data.aTexCoord1&&(t.TexCoord2=1),e.data.uv2&&(t.InstanceBim=1)}be(t,e,n,r,s,i,o,a){let c=!1;r.asset&&"S3M"===r.asset.generator&&(c=!0,r.extensions=r.extensions||{});const h=r.url+"-"+e+"-"+n;if(this.pt[h])return this.pt[h];let u,l;a.push(t);const f=r.materials&&r.materials[t.material],d=r.extensions&&r.extensions.KHR_techniques_webgl,m=this.rt.Pt(s.Rt);if(d&&f.extensions&&f.extensions.KHR_techniques_webgl){const e=this.Ie(t,r,i,c);u=e.material,l=e.geometry,m.fillEmptyDataInMissingAttribute&&(l.desc.fillEmptyDataInMissingAttribute=!0)}else{l=this.Se(t,i,rs);const e=m.ambientLight;let n=m.environmentExposure;const s=m.material,c=this.getMap().getLightManager(),h=c&&c.getAmbientLight();if(e&&(!h||h.color)&&void 0===n){const t=h&&h.color?h.color[0]:.2;n=e[0]/t}u=this.Ee(t.material,r,o,s||Br,n||1,a,m)}u&&Object.defineProperty(u.uniforms,"alphaTest",{enumerable:!0,get:function(){const t=m.alphaTest;return it(t)?.1:t}}),u&&!u.isReady()?u.Ne=s.id:u||(u=this.Mt);const p={geometry:l,material:u};return l.properties.url=h,this.pt[h]=p,p}Ie(t,e,n,r){const{geometry:s,material:i}=this.xt.createMesh(t,e,n,r);return{geometry:s,material:i}}Se(t,e,r){const s=t.attributes;let i=s._BATCHID&&s._BATCHID.array;if(i&&i.byteOffset&&(i=new i.constructor(i)),s.COLOR_0){const t=s.COLOR_0.array||s.COLOR_0;if(t instanceof Float32Array){const e=new Uint8Array(t.length);for(let n=0;n<e.length;n++)e[n]=Math.round(255*t[n]);s.COLOR_0.array?(s.COLOR_0.array=e,s.COLOR_0.componentType=5121):s.COLOR_0=e}}const o={};for(const t in s){const e=Ar(this.ot,s[t],{dimension:s[t].itemSize}),n=r[t]||t;o[n]={buffer:e},s[t].quantization&&(o[n].quantization=s[t].quantization),n===r.POSITION&&(o[n].array=s[t].array,o[n].min=s[t].min,o[n].max=s[t].max)}const a=t.indices?t.indices.array?t.indices.array.slice():t.indices:null,c=new n.reshader.Geometry(o,a,0,{static:!0,positionAttribute:r.POSITION,normalAttribute:r.NORMAL,uv0Attribute:r.TEXCOORD_0,uv1Attribute:r.TEXCOORD_1,color0Attribute:r.COLOR_0,tangentAttribute:r.TANGENT,pickingIdAttribute:r._BATCHID,primitive:void 0===t.mode?"triangles":xr(t.mode)});return i&&a&&(c.properties.batchIdData=i,c.properties.batchIdMap=function(t,e){if(!e)return null;const n=new Map;for(let r=0;r<e.length;r++){const s=e[r],i=t[s];let o=n.get(i);o||(o=[],n.set(i,o)),o.push(s)}return n}(i,a)),c.generateBuffers(this.ot,{excludeElementsInVAO:e}),c}le(t,e,r,s){const i=n.mat4.identity(t),o=this.getMap();Gr.x=r[0],Gr.y=r[1];const a=this._prjToPoint(Gr),c=this.Ce(),h=1/(o.getGLZoom?o.getResolution(o.getGLZoom()):o.getGLRes());Gr.x=e[0],Gr.y=e[1];const u=this.Wt();let l=this.rt.options.offset;at(l)&&(l=l.call(this.rt,Gr));const f=this.rt.Pt(s).heightOffset||0;return n.vec3.set(Jr,a.x-l[0],a.y-l[1],u*r[2]+u*f),n.mat4.translate(i,i,Jr),n.vec3.set(c,h,h,u),n.mat4.scale(i,i,c),i}qt(t,e){const r=this.rt.Pt(e.Rt),s=this.rt.Yt(e.Rt).Me;let i=r.rotation||[0,0,0];i=n.quat.fromEuler(Wr,i[0],i[1],i[2]);const o=r.scale||[1,1,1],a=n.mat4.fromRotationTranslationScale([],i,ts,o),c=n.mat4.identity([]),h=n.mat4.identity([]);n.mat4.translate(c,c,n.vec3.scale(ns,s,-1)),n.mat4.translate(h,h,s);const u=n.mat4.multiply(c,c,t.Bt);n.mat4.multiply(a,a,u);const l=n.mat4.multiply(h,h,a);t.localTransform=l}me(t,e){const r=n.mat4.identity(t),s=this.getMap(),i=this.Ce();Gr.x=e[0],Gr.y=e[1];const o=s.distanceToPointAtRes(100,100,s.getGLRes(),Gr);let a;return a=s.altitudeToPoint?this.It:o.y/100,n.vec3.set(i,o.x/100*1.01,o.y/100*1.01,a),n.mat4.scale(r,r,i),r}Ot(){const t={x:0,y:0,width:()=>this.st?this.st.width:1,height:()=>this.st?this.st.height:1},e=[],r=[];this.Kt=new n.reshader.MeshShader({vert:on,frag:"#define SHADER_NAME PNTS\n\nprecision mediump float;\n\n\n\nvarying vec4 vColor;\n\n\n\nvoid main() {\n\n vec2 circCoord = 2.0 * gl_PointCoord - 1.0;\n\n if (dot(circCoord, circCoord) > 1.0) {\n\n discard;\n\n } else {\n\n gl_FragColor = vColor;\n\n }\n\n}\n\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:(t,e)=>n.mat4.multiply(r,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,r)=>n.mat3.fromMat4(e,r.modelMatrix)}],extraCommandProps:{viewport:t,blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"},depth:{enable:!0,range:[0,1],func:"<"}}});const s=this.At();this.$t=new n.reshader.PhongShader({extraCommandProps:s}),this.Xt=new n.reshader.pbr.StandardShader({extraCommandProps:s}),this.Zt=new n.reshader.EdgeShader({extraCommandProps:{viewport:{x:0,y:0,width:()=>this.st?this.st.width:1,height:()=>this.st?this.st.height:1},blend:{enable:!0,func:{srcRGB:"src alpha",srcAlpha:1,dstRGB:"one minus src alpha",dstAlpha:"one minus src alpha"},equation:"add"}}});const i=this.rt;Er(i.getRenderer().canvas,this.ot,i.getMap()),this.picking=new n.reshader.FBORayPicking(this.ct,{vert:this.Xt.vert,extraCommandProps:s,uniforms:this.Xt.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap()),this.Pe=new n.reshader.FBORayPicking(this.ct,{vert:on,extraCommandProps:s,uniforms:this.Kt.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap())}At(){return{viewport:{x:0,y:0,width:()=>this.st?this.st.width:1,height:()=>this.st?this.st.height:1},cull:{enable:!0},stencil:{enable:!0,func:{cmp:(t,e)=>e.meshProperties.isLeaf?"always":">=",ref:(t,e)=>e.meshProperties.level},opFront:{fail:"keep",zfail:"keep",zpass:"replace"},opBack:{fail:"keep",zfail:"keep",zpass:"replace"}},depth:{enable:!0,range:[0,1],func:(t,e)=>e.meshProperties.depthFunc||"<"},blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"},polygonOffset:{enable:!0,offset:(t,e)=>e.meshProperties.polygonOffset}}}Jt(t){const e=this.getMap(),r=e.getLightManager(),s=(r&&r.getDirectionalLight()||{}).direction||[1,1,-1],i=t&&t.pointOpacity||1;return{projViewMatrix:e.projViewMatrix,pointOpacity:i,lightDir:n.vec3.normalize(s,s)}}Et(){const t=this.getMap(),e=this.rt,n=e.getRenderer().canvas,{iblTexes:r,dfgLUT:s}=Cr(n),i=Pr(t,r,s),o=this.rt.getRenderer(),a=o.getMaskUniforms();i.minAltitude=e.options.altitude||0;const c=o.canvas.gl&&o.canvas.gl.wrap?e.options.opacity||0:1;return i.layerOpacity=c,ot(i,{czm_lightDirectionEC:i.light0_viewDirection,lightSpecular:[1,1,1],viewMatrix:t.viewMatrix,projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,outSize:[n.width,n.height],polygonFill:[1,1,1,1],polygonOpacity:1}),ot(i,a),i}Ee(t,e,r,s,i,o,a){const c=e.materials&&e.materials[t];if(!c||!c.baseColorTexture&&!c.pbrMetallicRoughness)return null;const h=ot({},s);if(c.baseColorTexture){const t=e.textures[c.baseColorTexture.index];let n;t&&!t.image.color&&(n=this.C(t,o)),h.baseColorFactor=t&&t.image.color||c.baseColorFactor||[1,1,1,1],n&&(h.baseColorTexture=n)}else{if(c.normalTexture){const t=this.C(e.textures[c.normalTexture.index],o);if(t){const e=c.normalTexture.scale||1;h.normalTexture=t,h.normalMapFactor=e}}if(c.occlusionTexture){const t=this.C(e.textures[c.occlusionTexture.index],o);if(t){const e=c.occlusionTexture.strength||1;h.occlusionTexture=t,h.occlusionFactor=e}}if(c.emissiveTexture){const t=this.C(e.textures[c.emissiveTexture.index],o);t&&(h.emissiveTexture=t)}c.emissiveFactor&&(h.emissiveFactor=c.emissiveFactor);const t=c.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(h.baseColorFactor=t.baseColorFactor),t.baseColorTexture&&void 0!==t.baseColorTexture.index){const r=e.textures[t.baseColorTexture.index];if(r.image&&r.image.color)h.baseColorFactor=h.baseColorFactor?n.vec4.multiply(h.baseColorFactor,h.baseColorFactor,r.image.color):r.image.color;else{const t=this.C(r,o);t&&(h.baseColorTexture=t,h.baseColorTexture.getREGLTexture(this.ot))}}if(it(t.metallicFactor)||(h.metallicFactor=t.metallicFactor),it(t.roughnessFactor)||(h.roughnessFactor=t.roughnessFactor),c.metallicRoughnessTexture){const t=this.C(e.textures[c.metallicRoughnessTexture.index],o);t&&(h.metallicRoughnessTexture=t)}}}if(c.s3mMaterial)return new n.reshader.Material(h);if(h.environmentExposure=i,h.alphaTest=.1,a.unlit||c.extensions&&c.extensions.KHR_materials_unlit)return h.ambientColor=[1,1,1],h.light0_diffuse=[0,0,0,0],h.lightSpecular=[0,0,0],new n.reshader.PhongMaterial(h);let u=new n.reshader.pbr.StandardMaterial(h);"phong"===r&&(u=n.reshader.PhongMaterial.convertFrom(u));const l=c.pbrMetallicRoughness,f=l&&l.baseColorTexture&&l.baseColorTexture.extensions;return f&&f.KHR_texture_transform&&(u.set("khr_offset",f.KHR_texture_transform.offset||[0,0]),u.set("khr_rotation",f.KHR_texture_transform.rotation||0),u.set("khr_scale",f.KHR_texture_transform.scale||[1,1])),u.doubleSided=!(!a.doubleSided&&!c.doubleSided),u.once("complete",this.Tt),u}C(t,e){const r={type:t.type?Mr(t.type):"uint8",format:t.format?Or(t.format):"rgba",flipY:!!t.flipY},s=t.image;if(e.push(s),s.array?r.data=s.array:s.mipmap&&(r.mipmap=s.mipmap),!r.data&&!r.mipmap)return null;if(r.width=s.width,r.height=s.height,r.mipmap&&(r.width<4||r.height<4))return null;const i=t.sampler||t.texture&&t.texture.sampler;return i&&(i.magFilter&&(r.mag=vr(i.magFilter)),i.minFilter&&(r.min=Tr(i.minFilter)),i.wrapS&&(r.wrapS=_r(i.wrapS)),i.wrapT&&(r.wrapT=_r(i.wrapT))),new n.reshader.Texture2D(r,this.vt)}_t({target:t}){const e=t.Ne,n=this.ht[e];if(n.count--,!n.count){const t=n.meshes;this.ut[e]=t,delete this.ht[e];const r=t.we;delete t.we,r(null,{mesh:n.meshes,id:e})}}Ce(){return Ur}Re(t){return this.rt.Re(t)}_pointToPrj(t){const e=this.getMap();return e.getGLZoom?e._pointToPrj(t,e.getGLZoom()):e._pointToPrjAtRes(t,e.getGLRes())}_prjToPoint(t){const e=this.getMap();return e.getGLZoom?e._prjToPoint(t,e.getGLZoom()):e._prjToPointAtRes(t,e.getGLRes(),qr)}fe(t){return"Y"===t?Ir:"X"===t?Sr:Fr}pick(t,e,n=3){const r=this.rt;if(!r||!r.options.picking)return[];if(!this.pickingFBO||!this.picking)return[];const s=[],i=this.Et(),o=this.ke(this.picking,i,this.bt,t,e,n);o&&s.push(o);const a=this.ke(this.picking,i,this.yt,t,e,n);a&&s.push(a);const c=this.Jt(),h=this.ke(this.Pe,c,this.gt,t,e,n);return h&&s.push(h),s}ke(t,e,n,r,s,i){if(!n.getMeshes().length)return null;const o=this.rt,a=this.getMap();t.render(n.getMeshes().filter(t=>!t.bloom),e,!0);let c={};t.getRenderedMeshes().length&&(c=t.pick(r,s,i,e,{viewMatrix:a.viewMatrix,projMatrix:a.projMatrix,returnPoint:o.options.pickingPoint}));const{meshId:h,pickingId:u,point:l,coordinate:f}=c,d=(0===h||h)&&t.getMeshAt(h);if(!d||!d.geometry)return null;const m=d.properties;l&&l.length&&(l[0]=Math.round(1e5*l[0])/1e5,l[1]=Math.round(1e5*l[1])/1e5,l[2]=Math.round(1e5*l[2])/1e5);const p={batchId:u};if(o.options.debug&&(p.debugInfo=m),m&&m.batchTable){const{batchTable:t,batchTableBin:e,count:n}=m,r=u;for(const s in t)void 0!==t[s].byteOffset?p[s]=Pn(t[s],e,n,r):p[s]=t[s][r]}return{service:d.properties.serviceIndex,data:p,point:l,coordinate:f}}Nt(t){let e=new Set;for(let n=0,r=t.length;n<r;n++){const r=t[n].data.node;this.Ct(r)&&e.add(r.zt)}e=Array.from(e),e.sort();const n=new Map,r=e.length;for(let t=0;t<r;t++)n.set(e[t],t);return n}highlight(t){this.Ut=t;const e=this.rt.getRenderer();this.Ft=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelAllHighlight(){this.Ut=null;const t=this.rt.getRenderer();this.Ft=t.getFrameTimestamp(),t.setToRedraw(!0)}showOnly(t){this.Dt=t;const e=this.rt.getRenderer();this.jt=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelShowOnly(){this.Dt=null;const t=this.rt.getRenderer();this.jt=t.getFrameTimestamp(),t.setToRedraw(!0)}Le(){if(!this.St)return[];const t={},e=[];for(const n in this.St){const r=this.St[n];if(r)for(let n=0;n<r.length;n++){const s=r[n],i=s&&s.geometry;if(!s||!i)continue;const o=s.properties.serviceIndex;t[o]||(t[o]=new Set);const a=i.properties.batchIdData;if(a)for(let n=0;n<a.length;n++)t[o].has(a[n])||(e.push({id:a[n],service:o}),t[o].add(a[n]))}}return e}hasIBL(){const t=this.getMap().getLightManager();return!!(t&&t.getAmbientResource())}}function hs(t){for(let e=0;e<t.length;e++)t[e]&&(t[e].array&&(t[e].array=null),t[e].mipmap&&(t[e].mipmap=null),t[e].indices&&(t[e].indices=null))}const us=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("unable to locate global object")},ls=us(),fs=ls.gl_trans__coders=ls.gl_trans__coders||{};function ds(t,e){if(e)for(let n=0;n<e.length;n++){t[e[n].id||e[n].index]=e[n]}}fs.inject=function(t){const e=t.toString(),n=e.indexOf("{")+1,r=e.substring(0,n),s=ls.gl_trans__coders=ls.gl_trans__coders||{};let i=`${r}\n const _____getGlobal = ${us.toString()};\n const g___lobals = _____getGlobal()\n const tran_____scoders = g___lobals['gl_trans__coders'] = g___lobals['gl_trans__coders'] || {};`;for(const t in s)"inject"!==t&&"getTranscoder"!==t&&"registerTranscoder"!==t&&(i+='tran_____scoders["'+t+'"] ='+s[t].toString()+"\n;");return i+="\n"+e.substring(r.length),i},fs.registerTranscoder=function(t,e){fs[t]=e},fs.getTranscoder=function(t){return fs[t]};const ms=[];class ps{constructor(t,e,n,r,s){this.rt=r,this.Be=t,this.Rt=e,this.Ue=s,this.Fe=n.version,t.indexOf("i3s:tileset:")<0?(this.Fe<=1.6?this.De="root":this.De=0,n.version=this.Fe):(this.De=t.substring("i3s:tileset:".length),this.Fe>1.6&&(this.De=parseInt(this.De))),this.Be=t,this.je=n}load(){const t=this.je,e=t.layerScene.baseUrl;if(this.Fe<=1.6)return t[this.De]&&t[this.De].lodSelection?(this.ze=t[this.De],this.He()):new Promise(n=>{let r=e+"/nodes/"+this.De;t.layerScene.eslpk&&(r+="/3dNodeIndexDocument.json"),this.Ue(this.Rt,r,()=>{this.ze=t[this.De],n(this.He())})});if(this.Fe>=1.7){if(t[this.De])return this.ze=t[this.De],this.He();const n=Math.floor(this.De/t.nodesPerPage);return new Promise(r=>{let s=e+"/nodepages/"+n;t.layerScene.eslpk&&(s+=".json"),this.Ue(this.Rt,s,()=>{this.ze=t[this.De],r(this.He())})})}return null}getTileset(){return this.Ge}getChildrenURL(){return this.qe}He(){const t=this.je,e=t.layerScene.baseUrl,n=this.ze.children,r=[],s={};if(n)for(let i=0;i<n.length;i++)if(this.Fe<=1.6){const o=n[i].id;if(t[o])continue;const a=o;s[a]||(s[a]=new Promise(n=>{let r=e+"/nodes/"+a;t.layerScene.eslpk&&(r+="/3dNodeIndexDocument.json"),this.Ue(this.Rt,r,()=>{n()})}),r.push(s[a]))}else{const o=n[i];if(t[o])continue;const a=Math.floor(o/t.nodesPerPage);s[a]||(s[a]=new Promise(n=>{let r=e+"/nodepages/"+a;t.layerScene.eslpk&&(r+=".json"),this.Ue(this.Rt,r,()=>{n()})}),r.push(s[a]))}return r.length?Promise.all(r).then(()=>this.Ve()):this.Ve()}Ve(){return Promise.resolve(this.$e())}Xe(t){ds(this.je,t)}$e(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.Je(this.ze,!0)}}Je(t){const e=this.rt.getRenderer(),n=this.je.projection,r=!n||n&&4326===n.wkid,s=this.Fe,i=this.je,o=t,a=o.obb,c=o.mbs,h={};let u;if(c)u=Ut([],c[0],c[1],c[2]),r||(u=e.Ke(u,u)),u=bs([],u[0],u[1],u[2]),h.sphere=[...u,c[3]];else if(a){u=Ut([],a.center[0],a.center[1],a.center[2]),r||(u=e.Ke(u,u)),u=bs([],u[0],u[1],u[2]);const t=function(t,e,n){const r=function(t,e){var n=e[0],r=e[1],s=e[2],i=e[3],o=n+n,a=r+r,c=s+s,h=n*o,u=r*o,l=r*a,f=s*o,d=s*a,m=s*c,p=i*o,b=i*a,g=i*c;return t[0]=1-l-m,t[3]=u-g,t[6]=f+b,t[1]=u+g,t[4]=1-h-m,t[7]=d-p,t[2]=f-b,t[5]=d+p,t[8]=1-h-l,t}([],n);return r[0]=r[0]*e[0],r[1]=r[1]*e[0],r[2]=r[2]*e[0],r[3]=r[3]*e[1],r[4]=r[4]*e[1],r[5]=r[5]*e[1],r[6]=r[6]*e[2],r[7]=r[7]*e[2],r[8]=r[8]*e[2],[...t,...r]}(u,a.halfSize,a.quaternion),n=t[3]+t[6]+t[9],s=t[4]+t[7]+t[10],i=t[5]+t[8]+t[11];Ut(ms,n,s,i);const o=Xt(ms);h.sphere=[...u,o]}let l=1/0,f=0;if(o.mbs?f=o.mbs[3]:o.obb&&(f=Math.max(Math.max(o.obb.halfSize[0],o.obb.halfSize[1]),o.obb.halfSize[2])),void 0!==o.lodThreshold)if("maxScreenThresholdSQ"===i.lodSelectionMetricType){l=f/(Math.sqrt(o.lodThreshold)/(.25*Math.PI))}else console.error("Unsupported lodSelectionMetricType in Layer");else if(void 0!==o.lodSelection)for(let t=0;t<o.lodSelection.length;t++)"maxScreenThreshold"===o.lodSelection[t].metricType&&(l=f/o.lodSelection[t].maxError);(l===1/0||isNaN(l))&&(l=1e5);const d=16*l,m=St([]),p=o.children;let b;if(p){b=[];const t=this.je;for(let e=0;e<p.length;e++){const n=s<=1.6?p[e].id:p[e];if(!t[n]){b=null;break}b.push(this.Je(t[n]))}}const g={refine:"REPLACE",boundingVolume:h,transform:m,geometricError:d};return s<=1.6?t.lodSelection?t.geometryData&&(g.content={uri:"i3s:mesh:"+(t.id||t.index)}):g.content={uri:"i3s:tileset:"+(t.id||t.index)}:p&&p.length&&!b?g.content={uri:"i3s:tileset:"+(t.id||t.index)}:o.mesh&&(g.content={uri:"i3s:mesh:"+(t.id||t.index)}),b&&b.length&&(g.children=b),g}getJSON(){return this.ze}}function bs(t,e,n,r){return un(t,ut(e),ut(n),r)}const gs=!!fs.ktx2,ys=n.mat4.identity([]),ws=(()=>{try{if("object"==typeof WebAssembly&&"function"==typeof WebAssembly.instantiate){const t=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));if(t instanceof WebAssembly.Module)return new WebAssembly.Instance(t)instanceof WebAssembly.Instance}}catch(t){}return!1})();function vs(t){return t.indexOf("i3s:mesh")>=0}const Ts="i3s:mesh:".length;function _s(t,e,n,r,s){const i=e.layerScene.eslpk,o=function(t,e){const n=e.substring(Ts);return t>=1.7?parseInt(n):n}(e.version,t),a=e[o],c=e.layerScene.baseUrl,h=[];let u=!1;const l=ys;let f,d;if(e.version<=1.6){if(!a.geometryData)return null;const t=a.geometryData.length;if(!t)return null;let n=c+`/nodes/${a.id}/`+a.geometryData[t-1].href;i&&(n+=".bin");const r={geometry:{url:n,info:e.layerScene.store.defaultGeometrySchema}};let s=a.textureData&&a.textureData[0]&&a.textureData[0].href;if(s){const t=e.layerScene.store.textureEncoding[0];let n;n="image/jpeg"===t?"jpg":"png",i&&(s+="."+n);const o={pbrMetallicRoughness:{baseColorTexture:{url:c+`/nodes/${a.id}/`+s,factor:1,format:n,mimeType:t},metallicFactor:0}};r.material=o}h.push(r)}else{f=a.mesh.geometry,d=a.mesh.material;const t=e.layerScene.geometryDefinitions[f.definition],{geometryBuffers:o}=t;u=r&&2===o.length;const l=fs.draco&&u?o[1]:o[0],m=fs.draco&&u?1:0;let p=c+`/nodes/${f.resource}/geometries/`+m;i&&(p+=".bin");const b={geometry:{url:p,info:l}};if(s&&ws&&u&&!fs.draco)throw new Error("Must import @maptalks/transcoder.draco to load i3s draco compressed geometry");const g=e.layerScene.materialDefinitions,y=e.layerScene.textureSetDefinitions;let w,v=0;if(d&&(v=g[d.definition]),g){w=function(t,e,n,r,s,i){const o=JSON.parse(JSON.stringify(t));return function t(e,n,r,s,i,o){for(const a in e)if(e[a]&&e[a].textureSetDefinitionId>=0){const t=n[e[a].textureSetDefinitionId],c="images/"+t.formats[0].format,h=Ms(t.formats,i),u={url:r+`/nodes/${s}/textures/${h.name}`,factor:void 0===e[a].factor?1:e[a].factor,format:h.format,mimeType:c};if(o){let t="";switch(h.format){case"dds":t="bin.dds";break;case"jpg":case"png":t=h.format}u.url+="."+t}e[a]=u}else ct(e[a])&&t(e[a],n,r,s,i,o)}(o,e,n,r,s,i),o}(v,y,c,d.resource,n,e.layerScene.eslpk)}else w={pbrMetallicRoughness:{metallicFactor:0}};b.material=w,h.push(b)}return{dracoCompression:u,meshes:h,nodeIndex:o,center:a.obb&&a.obb.center||a.mbs&&[a.mbs[0],a.mbs[1],a.mbs[2]],transform:l}}function Ms(t,e){for(let n=0;n<=t.length;n++){const r=t[n].format;if("dds"===r&&e.hasExtension("WEBGL_compressed_texture_s3tc"))return t[n];if("jpg"===r||"png"===r)return t[n];if("ktx2"===r&&gs)return t[n]}return null}const Os=new s.Coordinate(0,0),xs=new s.Coordinate(0,0),As=new Set,Is=[],Ss=new class{constructor(t,e){this.max=t,this.currentSize=0,this.data=new Map,this.onRemove=e}reset(t){if(this.data){const e=this.data.keys();for(const n of e){const e=this.data.get(n);t&&t!==e.renderer||this.Qe(n,e)}}return t||(this.data=new Map,this.currentSize=0),this}clear(t){this.reset(t)}add(t,e){if(!e)return this;if(e.node&&e.node.memorySize&&(this.currentSize+=e.node.memorySize),this.has(t)){const n=this.data.get(t);n&&n.node&&n.node.memorySize&&(this.currentSize-=n.node.memorySize),this.data.delete(t),this.data.set(t,e)}else this.data.set(t,e);return this}shrink(){if(this.currentSize>this.max){let t=!1;const e=this.data.keys();let n=e.next();for(;this.currentSize>this.max&&void 0!==n.value;){!t&&this.data.get(n.value).current&&(t=!0,console.warn(`current maxGPUMemory(${this.max/1024/1024}) for Geo3DTilesLayer is not enough, one or more current tiles will be discarded.`));const r=this.getAndRemove(n.value);r&&this.onRemove(r),n=e.next()}}}has(t){return this.data.has(t)}keys(){const t=new Array(this.data.size);let e=0;const n=this.data.keys();for(const r of n)t[e++]=r;return t}getAndRemove(t){if(!this.has(t))return null;const e=this.data.get(t);return e.node&&e.node.memorySize&&(this.currentSize-=e.node.memorySize),this.data.delete(t),e}get(t){if(!this.has(t))return null;const e=this.data.get(t);return this.data.delete(t),this.data.set(t,e),e}remove(t){if(!this.has(t))return this;const e=this.data.get(t);return this.Qe(t,e),this}Qe(t,e){e.node&&e.node.memorySize&&(this.currentSize-=e.node.memorySize),this.data.delete(t),this.onRemove(e)}setMaxSize(t){return this.max=t,this.shrink(),this}getMemorySize(){let t=0;const e=this.data.values();for(const n of e){const e=n&&n.node;e&&e.memorySize&&(t+=e.memorySize)}return t}markAll(t,e){const n=this.data.values();for(const r of n)t&&r.renderer!==t||(r.current=e)}}(1024*(s.Browser.mobile?32:1024)*1024,t=>{const e=t.renderer;delete t.renderer,e.deleteTile(t)});let Es=0;class Ns extends(n.MaskRendererMixin(s.renderer.CanvasRenderer)){constructor(t){super(t);const e=1024*t.options.maxGPUMemory*1024;e>Ss.max&&Ss.setMaxSize(e),this.tileCache=Ss,Es++,this.prepareWorker(),this.tilesLoading={},this.Ze={},this.Ye=[],this.Ue=this.We.bind(this)}getAnalysisMeshes(){if(!this.painter)return Is;const t=this.painter.getPaintedMeshes();if(!t)return Is;const e=[],{b3dmMeshes:n,pntsMeshes:r,i3dmMeshes:s}=t;return n.length&&Tt(e,n),r.length&&Tt(e,r),s.length&&Tt(e,s),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.Ye.length||super.needToRedraw())}getFrameTimestamp(){return this.tn}drawOnInteracting(t,e,n){this.draw(e,n)}draw(t,e){this.tn=t;const n=this.prepareCanvas();if(n&&!n.intersects(this.canvasExtent2D))return void this.completeRender();const{root:r,tiles:s}=this.layer.getTiles(),i=s.length;if(!s||!i)return void this.completeRender();this.nn(),this.rn();const{selectedTiles:o,leaves:a,requests:c}=this.sn(r,s);c.length&&this.loadTiles(c),this.in(o,a,e),this.an(),c.length||this.completeRender()}sn(t,e){const n=this.layer.getRootTiles();let r=[];this.cn();let s=0;const i=this.hn(),o={};let a=!1,c=!1;for(let t=0;t<e.length;t++){const i=e[t],h=i.node;if(o[h.id])continue;const u=n[h.Rt];o[h.id]=1;let l=!1;const f=this.getCachedTile(h.id);if(this.un(h.id)?(s++,l=c=!0,this.tilesLoading[h.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=c=!0),(!i.node.ln||u.isS3M||!i.node.children||i.node.ln<=500)&&(a=!0,i.selected=!0,i.data=f)):this.painter.has(h)||(l=c=!0,r.push(h)),!l)continue;if(this.dn(i))a=!0;else{this.mn(i).length&&(a=!0)}}let h=[],u={};if(a&&({selectedTiles:h,leaves:u}=this.pn(t)),r.length>1&&(r.sort(Cs),i)){const t=i-s;r=t>0?r.slice(0,t):[]}return{loading:c,requests:r,selectedTiles:h,leaves:u}}pn(t){const e=[],n={};let r;const s=[t],i=[];for(;s.length>0||i.length>0;){if(i.length>0){const t=i[i.length-1];if(t.bn===s.length){i.pop(),t===r&&(t.leave=!0,n[t.node.id]=1),e.push(t);continue}}const t=s.pop(),o=t.children;if(t.selected)if("add"===t.node.refine)n[t.node.id]=1,t.selectionDepth=i.length,e.push(t);else{if(t.selectionDepth=i.length,r=t,0===o.length){t.leave=!0,n[t.node.id]=1,e.push(t);continue}i.push(t),t.bn=s.length}for(let t=0;t<o.length;t++)s.push(o[t])}return{selectedTiles:e,leaves:n}}dn(t){if(!t.parent)return null;let e=t.parent;for(;e&&e.level>=0;){const t=e.node.id;if(this.tileCache.has(t))return e.selected=!0,e.data=this.tileCache.get(t),e;e=e.parent}return null}mn(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const n=t.zt+1,r=[t.node];for(;r.length>0;){const s=r.pop().children;for(let i=0,o=s.length;i<o;i++){if((!s[i].content||!s[i].content.url)&&s[i].children&&s[i].children.length){r.push(s[i]);continue}const o=s[i].id;if(this.tileCache.has(o)){const n=this.layer.gn(s[i],t);n.selected=!0,n.data=this.tileCache.get(o),t.children.push(n),e.push(n)}else s[i].zt<=n&&r.push(s[i])}}return e}in(t,e,n){this.tileCache.markAll(this,!1);for(let e=0,n=t.length;e<n;e++){const n=t[e].data;n.current=!0,n.renderer=this,this.tileCache.add(t[e].node.id,n)}this.tileCache.shrink();const r={tiles:t,leaves:e};this.onDrawTileStart(r);const s=this.painter.paint(t,e,n);this.onDrawTileEnd(r),s&&this.layer.fire("canvasisdirty",{renderCount:s})}onDrawTileStart(){}onDrawTileEnd(){}loadTiles(t){for(let e=0,n=t.length;e<n;e++){const n=t[e];this.tilesLoading[n.id]={current:!0,node:n},this.loadTile(n)}}loadTile(t){let e=t.content.url;if(wt(e)){const n=vt(e);return this.yn(e,n,t),null}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const n=t.Rt,r=this.wn[n];return new ps(e,n,r,this.layer,this.Ue).load().then(n=>{this.onTilesetLoad(n,t,e)})}return t&&xt(e)&&!vs(e)&&(e=t.baseUrl+e),this.yn(e,null,t),null}yn(t,e,r){let s=this.o;s||(s=n.reshader.Util.getSupportedFormats(this.gl.gl||this.gl),this.o=s);const i=this.layer.Pt(r.Rt);i.isSuperMapiServer&&(t=function(t,e){const n=t.substring(e.length).split("/"),r=[];for(let t=0;t<n.length;t++)r.push(encodeURIComponent(n[t]));return e+r.join("/")}(t,r.baseUrl));const o={url:this.layer.getTileUrl(t,r.baseUrl,this.layer.vn[r.Rt]),arraybuffer:e,rootIdx:r.Rt,upAxis:r.de,transform:r.matrix,supportedFormats:s};if(vs(t)){const e=this.wn[r.Rt];if(o.projection=e.projection,o.i3sInfo=_s(t,e,this.regl,this.layer.options.enableI3SCompressedGeometry,this.layer.options.forceI3SCompressedGeometry),!o.i3sInfo)return void this.onTileError({status:404},r,t)}o.service=ot({},i),i.offset&&delete o.service.offset,o.referrer=window&&window.location.href,this.workerConn.loadTile(this.layer.getId(),o,(e,n)=>{if(e)return void this.onTileError(e,r,t);const{magic:s}=n;"b3dm"===s||"pnts"===s||"i3dm"===s||"cmpt"===s||"gltf"===s?(this.Ye.push({data:n,tile:r}),i.debugShowBoundingVolume&&this.painter.Te(r)):this.onTilesetLoad(n,r,t)})}rn(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let n=0;for(;this.Ye.length&&(n<e||!t.isInteracting());){const{data:t,tile:e}=this.Ye.shift(),{magic:r}=t;"b3dm"===r||"gltf"===r?this.painter.createB3DMMesh(t,e.id,e,(n,{mesh:r})=>{this.Tn(t,e,n,r)}):"pnts"===r?this.painter.createPntsMesh(t,e.id,e,(n,{mesh:r})=>{this.Tn(t,e,n,r)}):"i3dm"===r?this.painter.createI3DMMesh(t,e.id,e,(n,{mesh:r})=>{this.Tn(t,e,n,r)}):"cmpt"===r&&this.painter.createCMPTMesh(t,e.id,e,(n,{mesh:r})=>{this.Tn(t,e,n,r)}),n++}}Tn(t,e,n,r){if(n)this.onTileError(n,e);else{const n=this._n(r);e.memorySize=n,this.onTileLoad(t,e)}}_n(t){let e=0;if(Array.isArray(t))for(let n=0;n<t.length;n++)t[n]&&(e+=this._n(t[n]));else t&&(e+=t.getMemorySize());return e}onTileLoad(t,e){this.layer&&(delete this.tilesLoading[e.id],this.layer.onTileLoad(t,e),this.Mn(e),this.setToRedraw(),this.layer.fire("tileload",{node:e}))}onTilesetLoad(t,e,n){this.layer&&(this.layer.Ae=t.extensions&&t.extensions["s3m:VertexCompressionType"],t.capabilities||t.layers&&t.layers[0]&&t.layers[0].capabilities?this.On(t,e,n):(delete this.tilesLoading[e.id],this.layer.onTilesetLoad(t,e,n)))}onTileError(t,e,n){if(!this.layer)return;const r=n||e.content.url,s=t&&t.message||t;As.has(s)||(console.warn("failed to load 3d tile: "+r),console.warn(t),As.add(s)),delete this.tilesLoading[e.id],this.xn(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}xn(t,e){const n={loadTime:s.Util.now(),current:!0,error:e,node:t};n.renderer=this,this.tileCache.add(t.id,n)}Mn(t){const e={loadTime:s.Util.now(),current:!0,node:t};e.renderer=this,this.tileCache.add(t.id,e)}abortTileLoading(t){if(!t||!this.workerConn)return;const e=t.node.content.url;this.workerConn.abortTileLoading(this.layer.getId(),e),delete this.Ze[e]}cn(){if(this.tilesLoading)for(const t in this.tilesLoading)this.tilesLoading[t].current=!1}deleteTile(t){this.painter.deleteTile(t)}createContext(){const t=this.layer,e=t.options.glOptions||{alpha:!0,depth:!0,stencil:!0,preserveDrawingBuffer:!0,antialias:t.options.antialias},r=this.canvas.gl&&this.canvas.gl.wrap;r?(this.gl=this.canvas.gl.wrap(),this.regl=this.canvas.gl.regl):(this.glOptions=e,this.gl=this.An(this.canvas,e)),this.regl=this.regl||n.createREGL({gl:this.gl,attributes:e,extensions:["OES_element_index_uint"],optionalExtensions:t.options.optionalExtensions||[]}),r&&(this.canvas.pickingFBO=this.canvas.pickingFBO||this.regl.framebuffer(this.canvas.width,this.canvas.height)),this.pickingFBO=this.canvas.pickingFBO||this.regl.framebuffer(this.canvas.width,this.canvas.height),this.painter=new cs(this.regl,t),this.layer.In(),this.layer.fire("contextcreate",{regl:this.regl})}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new $e("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let n=this.layer.options||{};n=ot({},n),delete n.offset;const r=t.options.spatialReference;n.projection=r&&r.coordType||r&&r.projection||t.getSpatialReference().getProjection().code;const s=this.layer.getId();e.addLayer(s,n,t=>{if(t)throw t;this.layer&&(this.ready=!0,this.layer.fire("workerready"))})}onRemove(){this.painter&&this.painter.remove(),this.pickingFBO&&(this.canvas.pickingFBO||this.pickingFBO.destroy(),delete this.pickingFBO),this.workerConn&&(this.workerConn.removeLayer(this.layer.getId(),t=>{if(t)throw t}),this.workerConn.remove(),delete this.workerConn),Es--,Es||Ss.reset(),this.clear(),delete this.tileCache,super.onRemove()}clear(){this.an(!0),this.tileCache.reset(this),this.tilesLoading={},super.clear()}clearCanvas(){this.regl&&this.regl.clear({color:[0,0,0,0],depth:1,stencil:0}),super.clearCanvas()}getTileOpacity(){return 1}getStencilValue(){return 0}an(t){this.Sn||(this.Sn=Date.now());const e=Date.now();if(!t&&e-this.Sn<this.layer.options.retireInterval)return;this.Sn=e;const n=[];for(const e in this.tilesLoading){const r=this.tilesLoading[e];!t&&r.current||(n.push(e),this.abortTileLoading(r))}for(let t=0;t<n.length;t++)delete this.tilesLoading[n[t]]}hn(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}An(t,e){const n=["webgl","experimental-webgl"];let r=null;for(let s=0;s<n.length;++s){try{r=t.getContext(n[s],e)}catch(t){}if(r)break}return r}un(t){return!!this.tilesLoading[t]}getI3DMMeshes(){return this.painter.getI3DMMeshes()}getPNTSMeshes(){return this.painter.getPNTSMeshes()}getB3DMMeshes(){return this.painter.getB3DMMeshes()}readBatchData(t,e,n){return Nn(t,e,0,n)}nn(){if(!this.En)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const n=[];for(const r in this.En){const s=this.En[r];if("pending"===s.status)continue;s.status="pending";const i=s.rootIdx,o=At(this.layer.Pt(i).fetchOptions);if(n.push(ye.getJSON(r,o).then(t=>{delete this.En[r];const e=this.wn[i];if(e){t.nodes?ds(e,t.nodes):(e[t.id]=t,ds(e,t.children));for(let t=0;t<s.length;t++)s[t]();this.setToRedraw()}else this.setToRedraw()})),e++,e>=t)break}n.length&&Promise.all(n)}We(t,e,n){this.En||(this.En={}),this.En[e]=this.En[e]||[],this.En[e].rootIdx=t,this.En[e].push(n),this.setToRedraw()}On(t,e,n){this.wn||(this.wn=[]);const r=e.Rt;this.wn[r]||(this.wn[r]={});const s=this.wn[r],i=this.layer.Pt(r);t.layers&&(t=t.layers[0],"/"!==n[n.length-1]&&(n+="/"),n+="layers/0"),s.version=+(i.i3sVersion||t.store.version),!t.spatialReference||t.spatialReference.wkid&&4326===t.spatialReference.wkid||console.warn("i3s has a spatialReference other than 4326.",t.spatialReference),s.projection=t.spatialReference,function(t,e,n,r,s,i,o){if(!i.layerScene){i.layerScene=e,i.nodesPerPage=e.nodePages&&e.nodePages.nodesPerPage||64,i.lodSelectionMetricType=e.nodePages&&e.nodePages.lodSelectionMetricType;let t=s;i.layerScene.eslpk=t.indexOf("3dSceneLayer.json")>=0;if(t.endsWith(".json")){const e=s.lastIndexOf("/");t=e<0?"./":s.substring(0,e)}i.layerScene.baseUrl=function(t){return t.split("?")[0]}(t)}return new ps(s,n,i,t,o).load()}(this.layer,t,r,0,n,s,this.Ue).then(t=>{this.onTilesetLoad(t,e,n)})}pick(t,e,n){if(!this.painter)return[];const r=this.pickingFBO,{width:s,height:i}=this.canvas;return!this.pickingFBO||r.width===s&&r.height===i||r.resize(s,i),this.painter.pick(t,e,n&&n.tolerance)}highlight(t){if(this.Ut||(this.Ut=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const n=t[e].service||0;let r=this.Ut[n];r||(r=this.Ut[n]=new Map),r.set(t[e].id,t[e])}else{const e=t.service||0;let n=this.Ut[e];n||(n=this.Ut[e]=new Map),n.set(t.id,t)}this.painter.highlight(this.Ut)}cancelHighlight(t,e){if(!this.Ut)return;const n=this.Ut[t];if(n){if(Array.isArray(e))for(let t=0;t<e.length;t++)n.delete(e[t]);else n.delete(e);n.size||(this.Ut[t]=null),this.painter.highlight(this.Ut)}}cancelAllHighlight(){delete this.Ut,this.painter.cancelAllHighlight()}showOnly(t){if(this.Dt||(this.Dt=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const n=t[e].service||0;let r=this.Dt[n];r||(r=this.Dt[n]=new Map),r.set(t[e].id,t[e])}else{const e=t.service||0;let n=this.Dt[e];n||(n=this.Dt[e]=new Map),n.set(t.id,t)}this.painter.showOnly(this.Dt)}cancelShowOnly(){delete this.Dt,this.painter.cancelShowOnly()}Le(){return this.painter?this.painter.Le():[]}Ke(t,e){const n=this.getMap();if("identity"===n.getProjection().code.toLowerCase()){const n=this.Nn();return Os.x=e[0],Os.y=e[1],n.unproject(Os,xs),t[0]=xs.x,t[1]=xs.y,t}return Os.x=e[0],Os.y=e[1],n.getProjection().unproject(Os,xs),t[0]=xs.x,t[1]=xs.y,t}Cn(t,e){const n=this.Nn();return Os.x=e[0],Os.y=e[1],n.project(Os,xs),t[0]=xs.x,t[1]=xs.y,t}Pn(t,e){const n=this.Nn();return Os.x=e[0],Os.y=e[1],n.unproject(Os,xs),t[0]=xs.x,t[1]=xs.y,t}Nn(){const t=this.getMap().options.spatialReference.coordType;if(!t)throw new Error("Missing coordType in map spatialReference.");return this.Rn||(this.Rn=s.SpatialReference.getProjectionInstance(t)),this.Rn}}function Cs(t,e){return t.ne-e.ne}function Ps(t,e,n){return t[0]=e[n],t[1]=e[n+3],t[2]=e[n+6],t}function Rs(t,e,n){return Math.sqrt(function(t,e,n){const r=Dt(ks,n,t),s=Ps(Ls,e,0),i=Ps(Bs,e,1),o=Ps(Us,e,2),a=Xt(s),c=Xt(i),h=Xt(o);Ht(s,s),Ht(i,i),Ht(o,o);const u=Fs;u[0]=Gt(r,s),u[1]=Gt(r,i),u[2]=Gt(r,o);let l,f=0;u[0]<-a?(l=u[0]+a,f+=l*l):u[0]>a&&(l=u[0]-a,f+=l*l);u[1]<-c?(l=u[1]+c,f+=l*l):u[1]>c&&(l=u[1]-c,f+=l*l);u[2]<-h?(l=u[2]+h,f+=l*l):u[2]>h&&(l=u[2]-h,f+=l*l);return f}(t,e,n))}const ks=[],Ls=[],Bs=[],Us=[],Fs=[];const Ds=2*Math.PI;class js{constructor(t,e,n,r){this.west=t,this.south=e,this.east=n,this.north=r}static contains(t,e){let n=e[0];const r=e[1],s=t.west;let i=t.east;return i<s&&(i+=Ds,n<0&&(n+=Ds)),(n>s||On(n,s,1e-14))&&(n<i||On(n,i,1e-14))&&r>=t.south&&r<=t.north}static southwest(t,e){return e[0]=t.west,e[1]=t.south,e[2]=0,e}static northeast(t,e){return e[0]=t.east,e[1]=t.north,e[2]=0,e}static southeast(t,e){return e[0]=t.east,e[1]=t.south,e[2]=0,e}static northwest(t,e){return e[0]=t.west,e[1]=t.north,e[2]=0,e}}const zs=[0,0,1];function Hs(t,e){return un(e,t[0],t[1],t[2])}class Gs{constructor(t,e){this.normal=n.vec3.copy([],t),this.distance=e}static fromPointNormal(t,e,r){const s=-n.vec3.dot(e,t);return n.vec3.copy(r.normal,e),r.distance=s,r}}const qs=[],Vs=[],$s=[],Xs=[],Js=[],Ks=[],Qs=[],Zs=[],Ys=[],Ws=[],ti=new Gs([1,0,0],0),ei=[];class ni{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new js(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){let r=0;if(!js.contains(this.rectangle,e)){const e=this.southwestCornerCartesian,s=this.northeastCornerCartesian,i=this.westNormal,o=this.southNormal,a=this.eastNormal,c=this.northNormal,h=n.vec3.subtract(ei,t,e),u=n.vec3.dot(h,i),l=n.vec3.dot(h,o),f=n.vec3.subtract(ei,t,s),d=n.vec3.dot(f,a),m=n.vec3.dot(f,c);u>0?r+=u*u:d>0&&(r+=d*d),l>0?r+=l*l:m>0&&(r+=m*m)}const s=e[2],i=this.minimumHeight,o=this.maximumHeight;if(s>o){const t=s-o;r+=t*t}else if(s<i){const t=i-s;r+=t*t}return Math.sqrt(r)}computeBox(t){const e=this;Hs(js.southwest(t,Vs),e.southwestCornerCartesian),Hs(js.northeast(t,Vs),e.northeastCornerCartesian),qs[0]=t.west,qs[1]=.5*(t.south+t.north),qs[2]=0;const r=Hs(qs,$s),s=n.vec3.cross(Js,r,zs);n.vec3.normalize(e.westNormal,s),qs[0]=t.east;const i=Hs(qs,Zs),o=n.vec3.cross(Js,zs,i);n.vec3.normalize(e.eastNormal,o);const a=n.vec3.subtract(Js,r,i),c=n.vec3.normalize(Xs,a),h=t.south;let u;if(h>0){qs[0]=.5*(t.west+t.east),qs[1]=h;const r=Hs(qs,Ys);n.vec3.copy(Ws,c);const s=Gs.fromPointNormal(e.southwestCornerCartesian,e.westNormal,ti);ri(Ys,Ws,s,e.southwestCornerCartesian),u=Tn(r,Ks)}else u=_n(js.southeast(t,Vs),Ks);const l=n.vec3.cross(Qs,u,a);n.vec3.normalize(e.southNormal,l);const f=t.north;let d;if(f<0){qs[0]=.5*(t.west+t.east),qs[1]=f;const r=Hs(qs,Ys);n.vec3.scale(Ws,c,-1);const s=Gs.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,ti);ri(Ys,Ws,s,e.northeastCornerCartesian),d=Tn(r,Ks)}else d=_n(js.northwest(t,Vs),Ks);const m=n.vec3.cross(Qs,a,d);n.vec3.normalize(e.northNormal,m)}}function ri(t,e,r,s){const i=t,o=e,a=r.normal,c=n.vec3.dot(a,o);if(Math.abs(c)<1e-15)return;const h=(-r.distance-n.vec3.dot(a,i))/c;return h<0?void 0:(s=n.vec3.scale(s,o,h),n.vec3.add(s,i,s))}const si={"maxGPUMemory":s.Browser.mobile?32:1536,"retireInterval":2e3,"loadingLimitOnInteracting":5,"loadingLimit":10,"renderer":"gl","forceRenderOnZooming":!0,"forceRenderOnRotating":!0,"forceRenderOnMoving":!0,"debug":!1,"meshLimitPerFrame":1,"i3sNodepageLimitPerFrame":1,"enableI3SCompressedGeometry":!0,"forceI3SCompressedGeometry":!0,"picking":!0,"pickingPoint":!0,"geometryEvents":!1,"antialias":!1,"optionalExtensions":["ANGLE_instanced_arrays","OES_element_index_uint","OES_standard_derivatives","OES_vertex_array_object","OES_texture_half_float","OES_texture_half_float_linear","OES_texture_float","OES_texture_float_linear","WEBGL_depth_texture","EXT_shader_texture_lod","WEBGL_compressed_texture_astc","WEBGL_compressed_texture_etc","WEBGL_compressed_texture_etc1","WEBGL_compressed_texture_pvrtc","WEBGL_compressed_texture_s3tc","WEBGL_compressed_texture_s3tc_srgb"],"offset":[0,0]},ii=new s.Extent(0,0,0,0),oi=[],ai=[],ci=[],hi=[],ui=[],li=new s.Coordinate(0,0),fi=new s.Point(0,0),di=[],mi=new s.Coordinate(0,0),pi=n.mat4.identity([]),bi=[0,0],gi=[1,1,1,1,-1,1,-1,-1,1,-1,1,1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1];class yi extends(n.MaskLayerMixin(s.Layer)){static fromJSON(t){return t&&"Geo3DTilesLayer"===t.type?new yi(t.id,t.options):null}constructor(t,e){super(t,e),this.kn(),this.Ze={},this._e=[]}kn(){const t=this.options.services.map(t=>t.url);this.Ln=this.Ln||{},this.vn=this.vn||[];for(let e=0;e<t.length;e++){const n=t[e];let r=this.Ln[n];void 0===r&&(r=this.Ln[n]=this.vn.length),this.vn[r]=Ti(n,r,this.options.services[e])}this.fire("rootready",{roots:this.vn.slice(0)})}showService(t){return this.updateService(t,{visible:1}),this}hideService(t){return this.updateService(t,{visible:0}),this}setToRedraw(){const t=this.getRenderer();t&&t.setToRedraw()}addService(t){this.options.services=this.options.services||[],this.options.services.push(t),this.kn();const e=this.getRenderer();return e&&e.setToRedraw(),this}updateService(t,e){if(!e)return this;const n=this.options.services;if(n&&n[t]&&ot(n[t],e),!it(e.visible)){const r=n[t].url,s=this.Ln[r];this.vn&&this.vn[s]&&(this.vn[s].visible=e.visible)}const r=this.getRenderer();return r&&r.setToRedraw(),this}removeService(t){const e=this.options.services;if(e&&e[t]){const n=e[t].url,r=this.Ln[n];this.vn[r]&&(this.vn[r]=null),delete this.Ln[n],e.splice(t,1)}const n=this.getRenderer();return n&&n.setToRedraw(),this}getTileUrl(t,e,n){const r=n&&n.service&&n.service.subdomains;if(r&&n.domainKey){const e=r.length;if(e){const s=[...t].reduce((t,e)=>t+e.charCodeAt(),0)%e;return t.replace(n.domainKey,r[s])}}return t}getExtent(t){if(!t&&0!==t){const t=new s.Extent;for(let e=0;e<this.vn.length;e++)if(this.vn[e].boundingVolume){const n=this.boundingVolumeToExtent(this.vn[e]);t._combine(n)}return t}return this.vn[t]&&this.vn[t].boundingVolume?this.boundingVolumeToExtent(this.vn[t]):null}boundingVolumeToExtent(t){const e=t.boundingVolume.Bn?pi:t.matrix,r=this.getMap(),i="identity"===r.getProjection().code.toLowerCase(),o=this.getRenderer();if(t.boundingVolume.region){const e=t.boundingVolume.region;return new s.Extent(lt(e[0]),lt(e[1]),lt(e[2]),lt(e[3]))}if(t.boundingVolume.sphere){const a=t.boundingVolume.sphere,c=bn([],n.vec3.transformMat4([],a,e));i&&o.Cn(c,c);const h=a[3],u=r.locate(c,-h,h),l=r.locate(c,h,-h);return new s.Extent(u,l)}if(t.boundingVolume.box){const a=t.boundingVolume.box,c=n.vec3.transformMat4([],a,e),h=new s.Coordinate(bn([],c));i&&o.Cn(h,h);const u=a.slice(3);n.mat3.multiply(u,n.mat3.fromMat4([],t.matrix),u);const l=n.vec3.length(u.slice(0,3)),f=n.vec3.length(u.slice(3,6)),d=n.vec3.length(u.slice(6,9)),m=Math.max(l,f,d),p=r.locate(h,-m,m),b=r.locate(h,m,-m);return new s.Extent(p,b)}return null}getRootTiles(){return this.vn}getTiles(){const t=this.getRenderer();if(!t.ready)return this.Un(),{tiles:ui};const e=this.getMap(),r=e.cameraPosition,s=e.pointAtResToDistance(r[2],0,e.getGLRes()),i=this.Fn(r);this.Dn=this.Dn||[],n.vec3.set(this.Dn,ut(i.x),ut(i.y),s),this.jn=un(this.jn||[],this.Dn[0],this.Dn[1],this.Dn[2]),this.zn=2*Math.tan(.5*ut(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const h=[];for(let e=0;e<this.vn.length;e++){const n=this.vn[e];if(!n||!n.visible)continue;let r=1/0;const s=[n],i=this.Hn(e);for(;s.length>0;){const e=s.pop();for(e.id||this.Gn(e);c.level>=e.zt;)c=c.parent;const n=this.qn(e,i,o);if(n<1){let t=c;for(;t&&!t.content;)t=t.parent;0===n&&t&&t.content&&this.Vn(h,t);if(!1===this.options.services[e.Rt].alwaysShow)continue;if(!(0===n&&e.zt<=r))continue;e.content&&(r=e.zt)}e.ne<1/0&&this.$n(e);const a=this.gn(e,c);c.children.push(a);const u=e.children,l=u&&u.length,f=a.content;if(!l&&f&&this.Vn(h,a),l){f&&"add"===e.refine&&this.Vn(h,a),c=a;const n=u[0].parent;let r=!1;for(let i=0,o=u.length;i<o;i++){if(n){const e=t.getCachedTile(u[i].id);if(e&&e.error&&404!==e.error.status)continue;r=!0}else{r=!0,u[i].parent=e,u[i].de=e.de,u[i].baseUrl=e.baseUrl;const t=u[i].content&&(u[i].content.url||u[i].content.uri);t&&(wt(t)||t.indexOf("i3s:")>=0?u[i].baseUrl=e.baseUrl:xt(t)?u[i].content.url=e.baseUrl+t:u[i].baseUrl=t.substring(0,t.lastIndexOf("/")+1))}s.push(u[i])}!r&&f&&this.Vn(h,a)}}}return{root:a,tiles:h}}Vn(t,e){const{viewerRequestVolume:n}=e.node;n&&!function(t,e,n){if(n.region){const e=n.region;if(t[0]>=e[0]&&t[0]<=e[2]&&t[1]>=e[1]&&t[1]<=e[3])return!0}else{if(n.sphere)return wi(n,e);if(n.box)return 0===vi(n,e)}return!1}(this.Dn,this.jn,n)||t.push(e)}gn(t,e){return{id:t.id,node:t,children:[],level:t.zt,parent:e,content:t.content&&t.content.url}}Gn(t){const e=this.getId();t.id=e+":"+s.Util.GUID(),t.matrix=t.transform||n.mat4.identity([]),t.Xn=this.Jn(t),t.parent&&(function(t){return t.content&&t.content.uri&&t.content.uri.indexOf("i3s:")>=0}(t)||(t.matrix=n.mat4.multiply(t.matrix,t.parent.matrix,t.matrix)),t.Rt=t.parent.Rt,void 0===t.zt&&(t.zt=t.parent.zt+1),t.maxExtent=t.parent.maxExtent),t.refine=t.refine&&t.refine.toLowerCase()||"replace",t.content&&!t.content.url&&t.content.uri&&(t.content.url=t.content.uri)}Pt(t){return this.vn[t].service}Kn(t){const e=t.boundingVolume;if(!e||e.Bn&&!this.Qn(t))return;const r=this.Pt(t.Rt),s=r.heightOffset||0,i=this.options.offset,o=at(i)||i[0]||i[1],a=r.coordOffset||bi;if(!Array.isArray(a))throw new Error("service.coordOffset must be an array");if(!e.Bn&&(!t.boundingVolume||!s&&n.mat4.exactEquals(t.matrix,pi)&&!o&&a===bi))return;e.box&&e.region&&delete e.region;const{region:c,box:h,sphere:u}=e;if(e.coordOffset=[a[0],a[1]],e.heightOffset=s,c){e.originalVolume||(e.originalVolume=c.slice(0));const t=e.originalVolume,n=this.Zn([lt(t[0]),lt(t[1])]);c[0]=ut(n.x+a[0]),c[1]=ut(n.y+a[1]);const r=this.Zn([lt(t[2]),lt(t[3])]);c[2]=ut(r.x+a[0]),c[3]=ut(r.y+a[1]),c[4]=t[4]+s+(a[2]||0),c[5]=t[5]+s+(a[2]||0)}else if(h||u){e.originalVolume||(e.originalVolume=(h||u).slice(0));const r=h||u,i=e.originalVolume,o=n.vec3.transformMat4(oi,i,t.matrix),c=bn(ai,o),l=this.Zn([c[0]+a[0],c[1]+a[1]]);c[0]=l.x,c[1]=l.y,c[2]+=s+(a[2]||0),un(r,ut(c[0]),ut(c[1]),c[2])}e.Bn=!0}Qn(t){const e=t.boundingVolume,n=this.Pt(t.Rt),r=n.heightOffset||0,s=n.coordOffset||bi;return e.coordOffset[0]!==s[0]||e.coordOffset[1]!==s[1]||e.heightOffset!==r}Jn(t){return void 0===t.geometricError||!t.boundingVolume}$n(t){let e=t.parent;for(;e&&e.Xn&&!(e.ne<=t.ne);)e.ne=t.ne,e=t.parent}onTileLoad(t,e){if(t.children&&(!e.children||!e.children.length)){e.children=t.children;const n=e.content.url;e.baseUrl=n.substring(0,n.lastIndexOf("/")+1);const r=this.getRenderer();r&&r.setToRedraw()}}onTilesetLoad(t,e,r){if(!t)return void console.warn("invalid tileset at : "+r);const s=this.Pt(e.Rt),i=(t.asset&&t.asset.gltfUpAxis||e&&e.de||s.upAxis||"Y").toUpperCase();t.root.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const o=r.indexOf("realspace/")>-1;0===e.zt&&(t.asset&&t.asset.s3mType&&o||s.isSuperMapiServer)&&(t.root.baseUrl+="data/path/");const a=t.asset.i3s,c=!!t.asset.s3mType;if(t.root.de=i,e){const r=e.Rt,s=this.vn[r];c&&!s.isS3M&&(s.isS3M=c);const i=e.boundingVolume;ot(e,t.root),e.refine=e.refine&&e.refine.toLowerCase()||"replace",i&&(e.boundingVolume=i);const o=t.root.transform;o&&(e.parent?a||(e.matrix=n.mat4.multiply([],e.parent.matrix,o)):e.matrix=o),e.Yn=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.Xn=this.Jn(e);const h=e.content&&(e.content.url||e.content.uri);h&&e.content.uri&&(e.content.url=e.content.uri,delete e.content.uri),!a&&h&&!wt(h)&&xt(h)&&(e.content.url=e.baseUrl+h),t.root&&!e.parent&&this.Wn(e)}this.Un(),this.fire("loadtileset",{tileset:t,index:e&&e.Rt,url:r})}qn(t,e,n){if(t.ne=1/0,0===t.zt||t.Xn)return this.Wn(t),1;if(this.Kn(t),!this.tr(t,e,n))return-1;if(0===t.geometricError)return 1;let r=this.Pt(t.Rt).maximumScreenSpaceError;null==r&&(r=16);let s=this.er(t);return 0===s&&t.parent&&(s=.5*(t.parent.ln||0)),s>=r?1:0}Re(t,e){e||(e=new s.Point(0,0));const n=this.getMap();return n.getGLZoom?n.coordToPoint(t,n.getGLZoom(),e):n.coordToPointAtRes(t,n.getGLRes(),e)}tr(t,e,n){const r=t.id;let i=this._e[r]&&this._e[r].obbox;const{boundingVolume:o}=t,c=o.region,h=o.box,d=o.sphere;if(!i)if(c)this._e[r]=this.nr(t),i=this._e[r].bbox,i.center=this._e[r].coordCenter;else if(h)this._e[r]=this.rr(t),i=this._e[r].obbox,i.center=this._e[r].coordCenter;else if(d){i=this._e[r]=this.sr(t);const e=bn(oi,d),n=new s.Coordinate(e);i.center=n}if(e){if(c)ii.xmin=i[0][0],ii.ymin=i[0][1],ii.xmax=i[1][0],ii.ymax=i[1][1];else if(d){const t=i[2];ii.xmin=i[0][0]-t,ii.ymin=i[0][1]-t,ii.xmax=i[0][0]+t,ii.ymax=i[0][1]+t}else if(h){const t=i[1],e=i[2];ii.xmin=i[0][0]-t,ii.ymin=i[0][1]-e,ii.xmax=i[0][0]+t,ii.ymax=i[0][1]+e}if(!e.intersects(ii))return!1}return c?u(n,i):d?function(t,e,n){f(t);for(var r=e[0],s=-e[1],i=0;i<6;i++){if(!n||"0"!==n.charAt(i))if(m(a[i],r)<s)return!1}return!0}(n,i):!!h&&function(t,e,n){f(t);for(var r=0;r<6;r++){if(!n||"0"!==n.charAt(r))if(!l(a[r],e))return!1}return!0}(n,i)}nr(t){const e=this.getMap(),n=e.getGLRes(),r=t.boundingVolume.region;let{ws:i,en:o}=function(t){const e=t[0],n=t[1],r=t[2],s=t[3],i=t[4],o=t[5],a=un([],e,n,i),c=un([],r,s,o),h=bn(a,a),u=bn(c,c);return{ws:h,en:u}}(r);i=new s.Coordinate(i),o=new s.Coordinate(o);const a=e.coordToPointAtRes(i,n);a.z=e.altitudeToPoint(i.z,n);const c=e.coordToPointAtRes(o,n);c.z=e.altitudeToPoint(o.z,n);const h=[c.x,a.y,c.z,c.x,c.y,c.z,a.x,c.y,c.z,a.x,a.y,c.z,c.x,a.y,a.z,c.x,c.y,a.z,a.x,c.y,a.z,a.x,a.y,a.z],u=[(h[0]+h[18])/2,(h[1]+h[19])/2,(h[2]+h[20])/2],l=e.pointAtResToCoord(new s.Point(u),n);l.z=(i.z+o.z)/2;const f=this.Yt(t.Rt).Me,d=[h.slice(21,24),h.slice(3,6)];if(f)for(let t=0;t<h.length;t+=3)h[t]-=f[0],h[t+1]-=f[1],h[t+2]-=f[2];return{bbox:d,boxPosition:h,pointCenter:u,coordCenter:l}}rr(t){const e=this.getRenderer(),r=this.getMap(),s="identity"===r.getProjection().code.toLowerCase(),i=r.getGLRes(),o=t.boundingVolume.box,a=o.slice(0,3),c=this.ir(o,t.matrix),h=(l=a,new _i((u=c)[0],u[3],u[6],l[0],u[1],u[4],u[7],l[1],u[2],u[5],u[8],l[2],0,0,0,1));var u,l;const f=this.or(t),d=[],m=this.Yt(t.Rt).Me;fi.set(m[0],m[1]);const p=r.pointAtResToCoord(fi,i),b=oi;for(let t=0;t<gi.length;t+=3){b[0]=gi[t],b[1]=gi[t+1],b[2]=gi[t+2],n.vec3.transformMat4(b,b,h),bn(b,b),s&&e.Cn(b,b);const o=li.set(...b);let a=r.coordToPointAtRes(o,i,fi);a=n.vec3.set(b,a.x,a.y,r.altitudeToPoint(o.z,i)),d[t]=a[0]-m[0],d[t+1]=a[1]-m[1],d[t+2]=a[2]-m[2]}return{obbox:this.ar(d,m,f),boxPosition:d,boxCenter:f,coordCenter:p}}sr(t){const e=this.getMap(),n=this.getRenderer(),r="identity"===e.getProjection().code.toLowerCase(),i=t.boundingVolume.sphere,o=i;let a=oi;0===o[0]&&0===o[1]&&0===o[2]?a=[0,0,-6378137]:bn(a,o),r&&n.Cn(a,a);const c=new s.Coordinate(a),h=this.Re(c,fi).toArray();h[2]=e.altitudeToPoint(c.z,e.getGLRes());const u=this.cr(c);return[h,i[3]*u[2]]}ar(t,e,r){const[s,i,o]=e,a=n.vec3.set(oi,(t[3]+t[12])/2+s,(t[4]+t[13])/2+i,(t[5]+t[14])/2+o),c=n.vec3.set(ai,(t[3]+t[18])/2+s,(t[4]+t[19])/2+i,(t[5]+t[20])/2+o),h=n.vec3.set(ci,(t[3]+t[9])/2+s,(t[4]+t[10])/2+i,(t[5]+t[11])/2+o),u=r.slice(0);return u[3]=a[0]-r[0],u[4]=a[1]-r[1],u[5]=a[2]-r[2],u[6]=c[0]-r[0],u[7]=c[1]-r[1],u[8]=c[2]-r[2],u[9]=h[0]-r[0],u[10]=h[1]-r[1],u[11]=h[2]-r[2],u}or(t){const e=this.getMap(),n=this.getRenderer(),r="identity"===e.getProjection().code.toLowerCase(),i=e.getGLRes(),o=t.boundingVolume.box.slice(0,3);bn(o,o),r&&n.Cn(o,o);const a=new s.Coordinate(o),c=e.coordToPointAtRes(a,i);return[c.x,c.y,e.altitudeToPoint(a.z,i)]}Wn(t){const e=this.Pt(t.Rt);if(!t.boundingVolume||this.hr(t,e))return;const n=t.boundingVolume.box,r=t.boundingVolume.region,s=t.boundingVolume.sphere;let i=null;if(n){i=this.ur(t).pointCenter}else if(r){i=this.lr(t).pointCenter}else s&&(i=this.sr(t)[0]);const o=e.heightOffset||0,a=e.coordOffset||[0,0];t.dr=[a[0]||0,a[1]||0],t.te=o,t.Me=i}hr(t,e){if(!t.dr)return!1;const n=e.coordOffset||bi;return t.dr[0]===n[0]&&t.dr[1]===n[1]&&t.te===(e.heightOffset||0)}lr(t){if(!t.boundingVolume)return null;this.Kn(t);return this.nr(t)}ur(t){if(!t.boundingVolume)return null;this.Kn(t);const e=t.boundingVolume.box.slice(0,3);bn(e,e);const n=new s.Coordinate(e);return{pointCenter:this.or(t),coordCenter:n}}ir(t,e){let n=t.slice(3,12);return n=function(t,e,n){const r=t[0]*e[0]+t[3]*e[1]+t[6]*e[2],s=t[1]*e[0]+t[4]*e[1]+t[7]*e[2],i=t[2]*e[0]+t[5]*e[1]+t[8]*e[2],o=t[0]*e[3]+t[3]*e[4]+t[6]*e[5],a=t[1]*e[3]+t[4]*e[4]+t[7]*e[5],c=t[2]*e[3]+t[5]*e[4]+t[8]*e[5],h=t[0]*e[6]+t[3]*e[7]+t[6]*e[8],u=t[1]*e[6]+t[4]*e[7]+t[7]*e[8],l=t[2]*e[6]+t[5]*e[7]+t[8]*e[8];return n[0]=r,n[1]=s,n[2]=i,n[3]=o,n[4]=a,n[5]=c,n[6]=h,n[7]=u,n[8]=l,n}(this.mr(e,[]),n,n),n}mr(t,e){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[4],e[4]=t[5],e[5]=t[6],e[6]=t[8],e[7]=t[9],e[8]=t[10],e}cr(t){const e=this.getMap(),r=e.distanceToPointAtRes(100,100,e.getGLRes(),t);let s;return s=e.altitudeToPoint?e.altitudeToPoint(100,e.getGLRes())/100:r.y/100,n.vec3.set(hi,r.x/100*1.01,r.y/100*1.01,s),hi}Zn(t){Array.isArray(t)&&(t=new s.Coordinate(t));let e=this.options.offset;if(at(e)&&(e=e.call(this,Array.isArray(t)?new s.Coordinate(t):t)),e[0]||e[1]){const n=this.getMap(),r=n.getGLRes(),s=n.coordToPointAtRes(t,r);return s._sub(e),n.pointAtResToCoord(s,r)}return t}Yt(t){return this.vn[t]}Hn(t){const e=this.Pt(t).maxExtent;if(!e)return null;const n=this.vn[t];return n.maxExtent||(n.maxExtent=new s.Extent(e).convertTo(t=>this.Re(t))),n.maxExtent}er(t){const e=this.zn,n=t.geometricError;if(0===n)return t.ln=0,0;const r=this.getMap();let s;t.boundingVolume.region?s=function(t,e,n){t.pr||(t.pr=new ni(t.boundingVolume.region));return t.pr.distanceToCamera(e,n)}(t,this.jn,this.Dn):t.boundingVolume.sphere?s=wi(t.boundingVolume,this.jn):t.boundingVolume.box&&(s=vi(t.boundingVolume,this.jn));const i=Math.max(Math.abs(s),1e-7),o=n*r.height/(i*e);return t.ne=s,t.ln=o,o}Un(){const t=this.getRenderer();t&&t.setToRedraw()}Oe(t){return this._e[t]}identify(t,e={}){const n=this.getMap(),r=this.getRenderer();if(!n||!r)return[];const i=n.coordToContainerPoint(new s.Coordinate(t));return this.identifyAtPoint(i,e)}identifyAtPoint(t,e={}){const n=[];if(!e.excludeMasks){const r=this.identifyMask(t,e);r&&r.length&&Tt(n,r)}const r=this.getMap(),s=this.getRenderer();if(!r||!s)return[];const i=r.getDevicePixelRatio();return Tt(n,s.pick(t.x*i,t.y*i,e)),n}getCurrentBatchIDs(){const t=this.getMap(),e=this.getRenderer();return t&&e?e.Le():[]}highlight(t){const e=this.getRenderer();return e?(e.highlight(t),this):(this.Ut||(this.Ut=[]),this.Ut.push(t),this)}In(){if(this.Ut){for(let t=0;t<this.Ut.length;t++)this.highlight(this.Ut[t]);delete this.Ut}}cancelHighlight(t,e){const n=this.getRenderer();return n?(n.cancelHighlight(t,e),this):this}cancelAllHighlight(){const t=this.getRenderer();return t?(t.cancelAllHighlight(),this):this}showOnly(t){const e=this.getRenderer();return e?(e.showOnly(t),this):(this.Dt||(this.Dt=[]),this.Dt.push(t),this)}br(){if(this.Dt){for(let t=0;t<this.Dt.length;t++)this.showOnly(this.Dt[t]);delete this.Dt}}cancelShowOnly(t){const e=this.getRenderer();return e?(e.cancelShowOnly(t),this):this}setServiceOpacity(t,e){const n=this.options.services[t];n&&(n.opacity=e);const r=this.getRenderer();return r?(r.setToRedraw(),this):this}setServiceDebugBoundingVolume(t,e){const n=this.options.services[t];n&&(n.debugShowBoundingVolume=e);const r=this.getRenderer();return r?(r.setToRedraw(),this):this}Fn(t){const e=this.getMap(),n=e.getGLRes();mi.set(t[0],t[1]);const r=e.pointAtResToCoord(mi,n);return"identity"===e.getProjection().code.toLowerCase()?(ai[0]=r.x,ai[1]=r.y,this.getRenderer().Pn(oi,ai),r.set(oi[0],oi[1]),r):r}toJSON(){return{"type":this.getJSONType(),"id":this.getId(),"options":this.config()}}}function wi(t,e){const r=t.sphere,s=n.vec3.dist(r,e),i=t.sphere[3];return s<i?0:s-i}function vi(t,e){const r=t.box;return Rs(n.vec3.set(oi,r[0],r[1],r[2]),n.mat3.set(di,r[3],r[4],r[5],r[6],r[7],r[8],r[9],r[10],r[11]),e)}function Ti(t,e,r){const s=(t=ft(t)).indexOf("{s}")>=0?"{s}":t.indexOf("%7Bs%7D")>=0?"%7Bs%7D":null;return{service:r,visible:it(r.visible)?1:r.visible,baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:n.mat4.identity([]),Rt:e,zt:0,domainKey:s}}function _i(t,e,n,r,s,i,o,a,c,h,u,l,f,d,m,p){this[0]=t||0,this[1]=s||0,this[2]=c||0,this[3]=f||0,this[4]=e||0,this[5]=i||0,this[6]=h||0,this[7]=d||0,this[8]=n||0,this[9]=o||0,this[10]=u||0,this[11]=m||0,this[12]=r||0,this[13]=a||0,this[14]=l||0,this[15]=p||0}yi.mergeOptions(si),yi.registerRenderer("gl",Ns),yi.registerJSONType("Geo3DTilesLayer");let Mi=null;function Oi(){return Mi||(Mi={"image/crn":fs.crn&&fs.crn(),"image/ktx2":fs.ktx2&&fs.ktx2(),"image/cttf":fs.ktx2&&fs.ktx2(),"draco":fs.draco&&fs.draco()}),Mi}class xi{constructor(t,e,n){this.i=t,this.gr=e||Ue,this.o=n,this.yr=Oi()}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.wr(t,e,n,r,s)):ye.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.wr(t,s,n,r)})}wr(t,e,n,r,s){const i=s&&s.maxTextureSize,o=this.vr(e,n,r,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.gr(a,o.glb,{transferable:!0,requestImage:this.i,decoders:this.yr,supportedFormats:this.o,maxTextureSize:i});return c.load({skipAttributeTransform:!1}).then(e=>{e.url=`${t}-${n}-${r}`;const s=c.transferables;for(let t=0;t<o.transferables.length;t++)s.indexOf(o.transferables[t])<0&&s.push(o.transferables[t]);return{magic:"b3dm",count:o.count,transferables:s,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,gltf:e}})}vr(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported b3dm version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in b3dm header is inconsistent with b3dm's byte length, url: "+r;return console.warn(t),{error:t}}let o,a=s.getUint32(12,!0),c=s.getUint32(16,!0),h=s.getUint32(20,!0),u=s.getUint32(24,!0),l=28+e;h>=570425344?(l-=8,o=a,h=c,u=0,a=0,c=0):u>=570425344&&(l-=4,o=h,h=a,u=c,a=0,c=0);const f=[t];let d,m,p;if(a>0?(d=In(t,l,a),l+=a,o=d.BATCH_LENGTH):d={"BATCH_LENGTH":o},c>0&&(l+=c),h>0&&(m=Sn(t,l,h),l+=h,u>0)){const e=En(0,l,u);p=t.slice(e.offset,e.offset+e.byteLength),l+=u,f.push(p)}const b=d.BATCH_LENGTH,g={};if(d&&d.BATCH_ID){g.BATCH_ID=Cn(d.BATCH_ID,t,(void 0).offset,b);const e=g.BATCH_ID.array&&g.BATCH_ID.array.buffer;e&&f.indexOf(e)<0&&f.push(e)}return{count:o,transferables:f,featureTable:d,batchTable:m,batchTableBin:p,b3dm:g,glb:{buffer:t,byteOffset:l,byteLength:s.byteLength+s.byteOffset-l}}}Tr(){return null}}class Ai{constructor(t,e,n,r){this.i=t,this.gr=e||Ue,this.o=n,this.yr=Oi(),this._r=r}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.wr(t,e,n,r,s)):ye.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.wr(t,s,n,r)})}wr(t,e,n,r,s){return this.Mr(t,e,n,r,s).then(({gltf:s,transferables:i})=>{const o=this.Or(e,n,r,t);if(o.error)return Promise.resolve(o);for(let t=0;t<i.length;t++)-1===o.transferables.indexOf(i[t])&&o.transferables.push(i[t]);return delete s.transferables,Promise.resolve({magic:"i3dm",count:o.count,transferables:o.transferables,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,i3dm:o.i3dm,gltf:s})})}Mr(t,e,n,r,s){const i=s&&s.maxTextureSize,o={transferable:!0,requestImage:this.i,decoders:this.yr,supportedFormats:this.o,maxTextureSize:i},a=new DataView(e,n,r),c=32+a.getUint32(12,!0)+a.getUint32(16,!0)+a.getUint32(20,!0)+a.getUint32(24,!0);if(0===a.getUint32(28,!0)){let r=pt(new Uint8Array(e,c+n,a.byteLength-c));-1==r.indexOf("://")&&(r=t.substring(0,t.lastIndexOf("/"))+"/"+r);return r.indexOf(".glb")>0?ye.getArrayBuffer(r,{}).then(t=>this.xr(r,{buffer:t.data,byteOffset:0},o)):ye.getJSON(r,{}).then(t=>this.xr(r,t,o))}{const r={buffer:e,byteOffset:c+n,byteLength:a.byteLength-c};return this.xr(t,r,o)}}xr(t,e,n){const r=t.substring(0,t.lastIndexOf("/")),s=new this.gr(r,e,n);return s.load({skipAttributeTransform:!0}).then(n=>{let r=0,i=0;return e.buffer&&(r=e.byteOffset||0,i=e.byteLength||0),n.url=`${t}-${r}-${i}`,{transferables:s.transferables,gltf:n}})}Or(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported pnts version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+r;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:h,batchTableBin:u}=Dn(s,32+e,o),l={},f=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;l.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,n=a.QUANTIZED_VOLUME_SCALE,{byteOffset:r}=a.POSITION_QUANTIZED;l.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.Ar(new Uint16Array(t,r+c.offset,3*f),e,n)},o.push(l.POSITION.array.buffer)}if(a.BATCH_ID){l.BATCH_ID=Cn(a.BATCH_ID,t,c.offset,f);const e=l.BATCH_ID.array&&l.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;l.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,l.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;l.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.Ir(new Uint16Array(t,e+c.offset,2*f))},o.push(l.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,l.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.Ir(new Uint16Array(t,e+c.offset,2*f))},o.push(l.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;l.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,f).slice()},o.push(l.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;l.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.SCALE_NON_UNIFORM.array.buffer)}return{count:f,batchTable:h,batchTableBin:u,featureTable:a,i3dm:l,transferables:o}}Ir(t){const e=t.length/2,n=new Float32Array(3*e),r=[];for(let s=0;s<e;s++)Ii(r,t[2*s],t[2*s+1],65535),n[3*s]=r[0],n[3*s+1]=r[1],n[3*s+2]=r[2];return n}Ar(t,e,n){return Fn(new Float32Array(t.length),t,e,n)}Tr(){return null}}function Ii(t,e,n,r){if(t[0]=Si(e,r),t[1]=Si(n,r),t[2]=1-(Math.abs(t[0])+Math.abs(t[1])),t[2]<0){const e=t[0];t[0]=(1-Math.abs(t[1]))*Ei(e),t[1]=(1-Math.abs(e))*Ei(t[1])}return Ht(t,t)}function Si(t,e){return function(t,e,n){return t<e?e:t>n?n:t}(t,0,e=function(t,e){if(null!=t)return t;return e}(e,255))/e*2-1}function Ei(t){return t<0?-1:1}class Ni{constructor(){}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.wr(t,e,n,r)):ye.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.wr(t,s,n,r)})}wr(t,e,n,r){return this.Sr(e,n,r,t).then(t=>t.error?t:{magic:"pnts",count:t.count,transferables:t.transferables,featureTable:t.featureTable,batchTable:t.batchTable,batchTableBin:t.batchTableBin,pnts:t.pnts})}Sr(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported pnts version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+r;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:h,batchTableBin:u}=Dn(s,e+28,o),l=a.QUANTIZED_VOLUME_OFFSET,f=a.QUANTIZED_VOLUME_SCALE,d=a.POINTS_LENGTH;let m,p={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){p=a.extensions["3DTILES_draco_point_compression"],m=new DataView(t,p.byteOffset+c.offset,p.byteLength);const e={attributes:p.properties,useUniqueIDs:!1};return this.Er||(this.Er=Oi().draco),this.Er(m,e).then(e=>{const n=e.attributes;!a.POSITION&&!a.POSITION_QUANTIZED||n.POSITION||n.POSITION_QUANTIZED||(n.POSITION=a.POSITION,n.POSITION_QUANTIZED=a.POSITION_QUANTIZED),!(a.RGB||a.RGBA||a.RGB565)||n.RGB||n.RGBA||n.RGB565||(n.RGB=a.RGB,n.RGBA=a.RGBA,n.RGB565=a.RGB565),!a.NORMAL&&!a.NORMAL_OCT16P||n.NORMAL||n.NORMAL_OCT16P||(n.NORMAL=a.NORMAL,n.NORMAL_OCT16P=a.NORMAL_OCT16P);const r=this.Nr(t,e.attributes,c.offset,d,o,l,f);if(e.attributes.BATCH_ID){const t=e.attributes.BATCH_ID.array;r.BATCH_ID={byteStride:0,byteOffset:0,itemSize:1,count:t.length,componentType:Un(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?r.BATCH_ID=Cn(a.BATCH_ID,t,c.offset,d):r.BATCH_ID=Ci(d);const e=r.BATCH_ID.array&&r.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return{count:d,batchTable:h,batchTableBin:u,featureTable:a,pnts:r,transferables:o}})}const b=this.Nr(t,a,c.offset,d,o,l,f);if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?b.BATCH_ID=Cn(a.BATCH_ID,t,c.offset,d):b.BATCH_ID=Ci(d);const e=b.BATCH_ID.array&&b.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:d,batchTable:h,batchTableBin:u,featureTable:a,pnts:b,transferables:o})}Nr(t,e,n,r,s,i,o){const a={};if(e.POSITION){let{byteOffset:i,array:o}=e.POSITION;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r*4);o=new Float32Array(e)}a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:o},s.push(o.buffer)}else if(e.POSITION_QUANTIZED){let{byteOffset:c}=e.POSITION_QUANTIZED;const{array:h}=e.POSITION_QUANTIZED;c=c||0;const u=h?0:n;a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:this.Ar(h||new Uint16Array(t,c+u,3*r),i,o)},s.push(a.POSITION.array.buffer)}if(e.RGBA){let{byteOffset:i,array:o}=e.RGBA;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+4*r);o=new Uint8Array(e)}a.RGBA={byteStride:0,byteOffset:0,itemSize:4,count:r,componentType:5121,array:o},s.push(o.buffer)}else if(e.RGB){let{byteOffset:i,array:o}=e.RGB;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r);o=new Uint8Array(e)}a.RGB={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5121,array:o},s.push(o.buffer)}else if(e.RGB565){let{byteOffset:i,array:o}=e.RGB565;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+2*r);o=new Uint16Array(e)}a.RGB565={byteStride:0,byteOffset:0,itemSize:1,count:r,componentType:5123,array:o},s.push(o.buffer)}if(e.NORMAL){let{byteOffset:i,array:o}=e.NORMAL;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r*4);o=new Float32Array(e)}a.NORMAL={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:o},s.push(o.buffer)}else if(e.NORMAL_OCT16P){let{byteOffset:i,array:o}=e.NORMAL_OCT16P;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+2*r);o=new Uint8Array(e)}a.NORMAL_OCT16P={byteStride:0,byteOffset:0,itemSize:2,count:r,componentType:5121,array:o},s.push(o.buffer)}return a}Ar(t,e,n){return Fn(new Float32Array(t.length),t,e,n)}Tr(){return null}}function Ci(t){const e=yt(t),n=new e(t);for(let e=0;e<t;e++)n[e]=e;return{byteStride:0,byteOffset:0,itemSize:1,count:t,componentType:Un(e),array:n}}class Pi{constructor(t,e,n,r){this.o=n,this.i=t,this.gr=e||Ue,this._r=r}load(t,e,n=0,r=0,s){return e?this.wr(t,e,n,r,s):ye.getArrayBuffer(t,{}).then(e=>{const s=e.data;return this.wr(t,s,n,r)})}wr(t,e,n,r,s){r||(r=e.byteLength);const i=this.Cr(e,t,n,r),o=[];for(let n=0;n<i.length;n++){let r;if("b3dm"===i[n].magic)r=new xi(this.i,this.gr,this.o);else if("i3dm"===i[n].magic)r=new Ai(this.i,this.gr,this.o,this._r);else if("pnts"===i[n].magic)r=new Ni;else{if("cmpt"!==i[n].magic){console.warn("Unsupported magic in CMPT tile:",i[n].magic);continue}r=new Pi(this.i,this.gr,this.o,this._r)}o.push(r.load(t,e,i[n].offset,i[n].byteLength,s).then(t=>t))}return Promise.all(o).then(t=>({magic:"cmpt",tiles:t}))}Cr(t,e,n,r){const s=new DataView(t,n,r),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported cmpt version: "+i+", url:"+e;return console.warn(t),{error:t}}if(16===s.byteLength)return[];const o=[],a=s.getUint32(12,!0);let c=16;for(let e=0;e<a;e++){const e=xn(s,c),r=s.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+n,byteLength:r}),c+=r}return o}}if(i.transcoders){const t=s.Map.VERSION;if(t.indexOf("1.0.0-beta")>=0||t.indexOf("1.0.0-alpha")>=0){const t=i.transcoders.inject(o);s.registerWorkerAdapter("@maptalks/3dtiles",t)}else s.registerWorkerAdapter("@maptalks/3dtiles",(function(){return i.transcoders.inject(o)}))}else s.registerWorkerAdapter("@maptalks/3dtiles",o);t.B3DMLoader=xi,t.CMPTLoader=Pi,t.Geo3DTilesLayer=yi,t.Geo3DTilesUtil=Ot,t.Geo3DTransform=Mn,Object.defineProperty(t,"t",{value:!0}),"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.95.7")}));
23
+ */(100,1),os=[0,0,0,1],as=[1,1,1];class cs{constructor(t,e){this.rt=e,this.st=e.getRenderer().canvas,this.pickingFBO=e.getRenderer().pickingFBO,this.it=new s.SpatialReference,this.ot=t,this.ct=new n.reshader.Renderer(t),this.ht={},this.ut={},this.lt={},this.ft={},this.dt={},this.pt={},this.bt=new n.reshader.Scene,this.gt=new n.reshader.Scene,this.yt=new n.reshader.Scene,this.wt=new n.reshader.Scene,this.vt=new n.reshader.ResourceLoader(t.texture(2)),this.Tt=this._t.bind(this),this.Mt=new n.reshader.PhongMaterial({"baseColorFactor":[1,1,1,1]}),this.Ot(),this.xt=new n.reshader.KHRTechniquesWebglManager(this.ot,this.At(),this.vt);const r=this.getMap();r.altitudeToPoint&&(this.It=r.altitudeToPoint(100,r.getGLRes())/100)}getI3DMMeshes(){return this.ft}getPNTSMeshes(){return this.lt}getB3DMMeshes(){return this.ut}getPaintedMeshes(){return this.St}getMap(){return this.rt.getMap()}paint(t,e,r){const s=r&&r.renderTarget,i=r&&r.sceneFilter,o=this.getMap();if(!t.length||!o)return null;const a=this.Et(),c=o.projViewMatrix,h=[],l=[],f=[],d=[],m=[],p=this.Nt(t),b=[];for(let s=0,i=t.length;s<i;s++){const i=t[s].data.node;let o=this.Ct(i);if(!o)continue;const a=this.rt.Pt(i.Rt);i.kt&&a.debugShowBoundingVolume&&b.push(i.kt);const g=a.heightOffset||0,y=a.coordOffset||Dr;this.dt[i.id]&&(o=this.dt[i.id],o=gt(o));let w=a.polygonOffset||Rr;at(w)&&(w=w()),Array.isArray(o)||(h[0]=o,o=h);for(let t=0,s=o.length;t<s;t++){const s=o[t].properties.magic;if(o[t].properties.heightOffset===g&&o[t].properties.coordOffset[0]===y[0]&&o[t].properties.coordOffset[1]===y[1]||(this.Lt(o[t]),o[t].Bt=n.mat4.copy([],o[t].localTransform)),"b3dm"===s){if(o[t].getBoundingBox&&!u(c,o[t].getBoundingBox()))continue;const{batchIdData:e,batchIdMap:s}=o[t].geometry.properties;if(e&&s){const e=o[t].properties.node.Rt;this.Ut&&this.Ut[e]?n.HighlightUtil.highlightMesh(this.ot,o[t],this.Ut[e],this.Ft,s):this.Ut&&this.Ut[e]||n.HighlightUtil.highlightMesh(this.ot,o[t],null,this.Ft,s),n.HighlightUtil.showOnly(this.ot,o[t],this.Dt&&this.Dt[e],this.jt,s)}r&&r.bloom&&o[t].properties.hlBloomMesh&&(o[t].properties.hlBloomMesh.properties.depthFunc="always",o[t].properties.hlBloomMesh.properties.polygonOffset=w,f.push(o[t].properties.hlBloomMesh)),f.push(o[t])}else"pnts"===s?d.push(o[t]):"i3dm"===s&&m.push(o[t]);o[t].properties.isLeaf=!!e[i.id],o[t].properties.level=p.get(i.zt),o[t].properties.polygonOffset=w,o[t].Ht=i,e[i.id]||l.push(o[t]),this.Gt(o[t]),this.qt(o[t],i)}}let g=0;const y=this.xt.getExcludeFilter();g+=this.Vt(this.$t,a,[i,jr,y],s,l,f,m),g+=this.Vt(this.Xt,a,[i,zr,y],s,l,f,m),this.xt.forEachShader((t,e,n)=>{const r=this.Et(n);g+=this.Vt(t,r,[i,e],s,l,f,m)}),this.gt.setMeshes(d);const w=this.Jt();return g+=this.ct.render(this.Kt,w,this.gt,s&&s.fbo),this.St={pntsMeshes:d,i3dmMeshes:m,b3dmMeshes:f},b.forEach(t=>{this.Qt(t)}),this.wt.setMeshes(b),this.ct.render(this.Zt,a,this.wt,s&&s.fbo),g}Qt(t){const e=t.properties.node,r=this.rt.Pt(e.Rt),s=this.rt.Yt(e.Rt),i=r.heightOffset||0,o=this.Wt(),a=s.te,c=n.vec3.set(es,0,0,o*(i-a));let h=r.rotation||[0,0,0];h=n.quat.fromEuler(Yr,h[0],h[1],h[2]);const u=r.scale||[1,1,1],l=n.mat4.fromRotationTranslationScale(Zr,h,c,u);n.mat4.multiply(t.localTransform,t.Bt,l)}Vt(t,e,n,r,s,i,o){t.filter=n.filter(t=>!!t),e.debug=!1,e.debug=!1;let a=0;return this.bt.setMeshes(i),a+=this.ct.render(t,e,this.bt,r&&r.fbo),this.yt.setMeshes(o),a+=this.ct.render(t,e,this.yt,r&&r.fbo),a}ee(t,e){return e.Ht.ne-t.Ht.ne}deleteTile(t){const e=t.node;e.kt&&(e.kt.geometry.dispose(),e.kt.dispose(),delete e.kt);const n=e.id;this.re(n)}re(t){const e=this.ut[t]||this.lt[t]||this.ft[t]||this.dt[t]||this.ht[t];this.dt[t]?this.se(t):e&&(this.ie(e),delete this.ut[t],delete this.lt[t],delete this.ft[t],delete this.ht[t])}se(t){let e=this.dt[t];e=gt(e);for(let t=0;t<e.length;t++){const{id:n}=e[t].properties;this.re(n)}delete this.dt[t]}ie(t){if(Array.isArray(t))for(let e=0,n=t.length;e<n;e++)this.ie(t[e]);else{n.HighlightUtil.showOnly(this.ot,t),n.HighlightUtil.highlightMesh(this.ot,t);const e=t.geometry.properties.url;if(e){const n=this.pt[e];n&&n.refMeshes&&(n.refMeshes.delete(t.uuid),n.refMeshes.size||(n.geometry.dispose(),n.material.dispose(),delete this.pt[e]))}else t.geometry.dispose(),t.material&&t.material.dispose();t.dispose()}}remove(){const t=this.rt;Nr(t.getRenderer().canvas,t.getMap());for(const t in this.dt)this.se(t);this.dt={};for(const t in this.ut)this.re(t);this.ut={};for(const t in this.lt)this.re(t);this.lt={};for(const t in this.ft)this.re(t);this.ft={};for(const t in this.ht)this.re(t);this.ht={},this.$t&&(this.$t.dispose(),delete this.$t),this.Xt&&(this.Xt.dispose(),delete this.Xt),this.Kt&&(this.Kt.dispose(),delete this.Kt),this.Zt&&(this.Zt.dispose(),delete this.Zt),this.xt.dispose(),this.picking&&this.picking.dispose()}Ct(t){return this.ut[t.id]||this.lt[t.id]||this.ft[t.id]||this.dt[t.id]}has(t){return this.Ct(t)||this.ht[t.id]}Lt(t){const e=t.properties.magic;"b3dm"===e?this.oe(t):"i3dm"===e?this.ae(t):"pnts"===e&&this.ce(t)}createPntsMesh(t,e,r,s){if(this.lt[e]){const t=this.lt[e];return console.warn(`pnts mesh with id(${e}) was already created.`),s(null,{id:e,mesh:t}),t}const{pnts:i,featureTable:o,rootIdx:a,compressed_int16_params:c}=t,h=o.POINTS_LENGTH;i.BATCH_ID||(i.BATCH_ID=new Uint8Array(h),i.BATCH_ID.fill(0));const u=new n.reshader.Geometry(i,null,h,{static:!0,primitive:"points",positionAttribute:"POSITION",pickingIdAttribute:"BATCH_ID"});u.generateBuffers(this.ot);const l={};i.POSITION?l.HAS_POSITION=1:i.POSITION_QUANTIZED&&(l.HAS_POSITION_QUANTIZED=1),i.RGB?l.HAS_RGB=1:i.RGBA?l.HAS_RGBA=1:i.RGB565&&(l.HAS_RGB565=1),(i.NORMAL||i.NORMAL_OCT16P)&&(l.HAS_NORMAL=1,i.NORMAL_OCT16P&&(l.HAS_NORMAL_OCT16P=1)),this.he(l,c),t.featureTable.CONSTANT_RGBA&&(t.featureTable.CONSTANT_RGBA=t.featureTable.CONSTANT_RGBA.map(t=>t/255));const{rtcCenter:f,rtcCoord:d,projCenter:m}=t,p=this.rt.Pt(a),b=new n.reshader.Mesh(u);b.properties.magic="pnts",b.properties.id=e,b.properties.node=r,b.properties.count=h,b.properties.batchTable=t.batchTable,b.properties.batchTableBin=t.batchTableBin,b.properties.serviceIndex=a,b.properties.rtcCoord=d,b.properties.rtcCenter=f,b.properties.projCenter=m,b.setDefines(l),Object.defineProperty(b.uniforms,"pointColor",{enumerable:!0,get:function(){return t.featureTable.CONSTANT_RGBA?t.featureTable.CONSTANT_RGBA:p&&p.pointColor||[1,1,1,1]}});const g=this.getMap();let y=null,w=null;Object.defineProperty(b.uniforms,"pointSize",{enumerable:!0,get:function(){if(!p)return 2;if(yr(p.pointSize)){const t=JSON.stringify(p.pointSize);t!==y&&(w=wr(p.pointSize),y=t);return w(g.getZoom())}return p.pointSize||2}});let v=null,T=null;return Object.defineProperty(b.uniforms,"pointOpacity",{enumerable:!0,get:function(){if(!p)return 1;if(yr(p.pointOpacity)){const t=JSON.stringify(p.pointOpacity);t!==v&&(T=wr(p.pointOpacity),v=t);return T(g.getZoom())}return p.pointOpacity||1}}),this.ue(b,c),this.ce(b),b.Bt=n.mat4.copy([],b.localTransform),this.lt[e]=b,s(null,{id:e,mesh:[b]}),[b]}ce(t){const e=t.localTransform||[],{rtcCoord:n,node:r,projCenter:s}=t.properties;this.le(e,n,s,r.Rt),t.setLocalTransform(e)}createI3DMMesh(t,e,r,s){if(this.ft[e]){const t=this.ft[e];return console.warn(`i3dm mesh with id(${e}) was already created.`),this.ht[e]||s(null,{id:e,mesh:t}),t}const i=this.rt.Pt(r.Rt),o=this.fe(r.de),{i3dm:a,featureTable:c,gltf:h,batchTable:u,batchTableBin:l,count:f}=t,d=c.INSTANCES_LENGTH,{rtcCenter:m,rtcCoord:p}=t,b=this.me(Kr,p),g=this.pe(Qr,r,m,p);n.mat4.multiply(b,g,b);const{POSITION:y,NORMAL_UP:w,NORMAL_RIGHT:v,SCALE:T,SCALE_NON_UNIFORM:_,INSTANCE_ROTATION:M}=a,O={"instance_vectorA":new Float32Array(4*d),"instance_vectorB":new Float32Array(4*d),"instance_vectorC":new Float32Array(4*d),"aPickingId":new Uint16Array(d)};for(let t=0;t<d;t++)O.aPickingId[t]=t;const x=new Float32Array(3),A=new Float32Array(3),I=[],S=new Float32Array(1),E=new Float32Array(3),N=[],C=[],P=[],R=[],k=new Float32Array(9);!function(t,e){let{byteOffset:n,byteStride:r,count:s}=t;const{componentType:i,itemSize:o}=t,a=t.array.buffer,c=i?Ue.getTypedArrayCtor(i):t.array.constructor;if(n=void 0===n?t.array.byteOffset:n,r=r||0,s=s||t.array.length/o,(!r||r===o*c.BYTES_PER_ELEMENT)&&n%c.BYTES_PER_ELEMENT==0){const t=new c(a,n,s*o);for(let r=0;r<s*o;r+=o){e(new c(t.buffer,n+r*c.BYTES_PER_ELEMENT,o),r/o)}return}const h=new Uint8Array(o*c.BYTES_PER_ELEMENT);r||(r=o*c.BYTES_PER_ELEMENT);for(let t=0;t<s;t++){const s=new Uint8Array(a,r*t+n,o*c.BYTES_PER_ELEMENT);h.set(s);e(new c(h.buffer),t),s.set(h)}}(y,(t,e)=>{w?(rn(A,v,e),rn(x,w,e),n.vec3.cross(I,A,x),n.vec3.normalize(I,I),bt(N,A,0),bt(N,x,1),bt(N,I,2),n.quat.fromMat3(C,N)):M?(rn(k,M,e),n.quat.fromMat3(C,k)):n.quat.identity(C),T?(rn(S,T,e),n.vec3.set(P,S[0],S[0],S[0])):_?(rn(E,_,e),n.vec3.set(P,...E)):n.vec3.set(P,1,1,1),n.mat4.fromRotationTranslationScale(R,C,t,P),sn(O.instance_vectorA,e,R,0),sn(O.instance_vectorB,e,R,1),sn(O.instance_vectorC,e,R,2)});const L={};for(const t in O)L[t]={buffer:this.ot.buffer({dimension:O[t].length/d,data:O[t]}),divisor:1};const B=i.shader||"pbr";let U=0,F=!0;const D=[],j=[];return Ke(h,(t,s,i,a)=>{const c=this.be(t,s,i,a,r,!0,B,j),{geometry:h,material:g}=c;g&&!g.isReady()&&(F=!1,U++);const y=new n.reshader.InstancedMesh(L,d,h,g);c.refMeshes||(c.refMeshes=new Set,c.refMeshes.add(y.uuid)),y.properties.magic="i3dm",y.properties.id=e,y.properties.count=f,y.properties.batchTable=u,y.properties.batchTableBin=l,y.properties.serviceIndex=r.Rt,y.properties.rtcCoord=p,y.properties.rtcCenter=m,y.properties.node=r;const w=this.ge(t,h,g,r.Rt,a);t.compressed_int16_params&&this.ue(y,t.compressed_int16_params),this.ye(y,t.attributes);const v=n.mat4.identity([]);if(t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)n.mat4.multiply(v,v,t.matrices[e]);n.mat4.multiply(v,o,v),y.setPositionMatrix(v),this.ae(y,b),y.setDefines(w),y.properties.polygonOffset={offset:0,factor:0},D.push(y),delete t.attributes,y.Bt=n.mat4.copy([],y.localTransform)}),hs(j),F?(this.ft[e]=D,s(null,{id:e,mesh:D})):(this.ht[e]={meshes:D,count:U},D.we=s),D}ae(t,e){const{rtcCenter:r,rtcCoord:s,node:i}=t.properties;if(!e){e=this.me(Kr,s);const t=this.pe(Qr,i,r,s);n.mat4.multiply(e,t,e)}const o=this.rt.Pt(i.Rt),a=t.localTransform||[];if(o.coordOffset){const t=this.ve(Qr,i.Rt,s);n.mat4.multiply(a,t,e)}else n.mat4.copy(a,e);t.setLocalTransform(a),t.properties.heightOffset=o.heightOffset||0,t.properties.coordOffset=o.coordOffset&&o.coordOffset.slice(0)||Dr}createB3DMMesh(t,e,r,i){if(t.gltf&&(t.gltf.transferables=null),this.ut[e]||this.ht[e]){const t=this.ut[e];return console.warn(`mesh with id(${e}) was already created.`),this.ht[e]||i(null,{id:e,mesh:t}),t}let o;if(r.maxExtent){const t=new s.Extent(r.maxExtent).convertTo(t=>this._pointToPrj(t));o=[t.xmin,t.ymin,t.xmax,t.ymax]}const a=t.gltf,{projCenter:c}=a.extensions.MAPTALKS_RTC,{rtcCoord:h,center:u}=a.extensions.CESIUM_RTC,l=a.asset.sharePosition,f=this.fe(r.de);let d;d=l?this.me(Kr,h):this.le(Kr,h,c,r.Rt);const m=this.rt.Pt(r.Rt);let p=m.shader||"pbr";if(m.unlit)p="phong";else if(a.materials)for(let t=0;t<a.materials.length;t++)if(a.materials[t]&&a.materials[t].extensions&&a.materials[t].extensions.KHR_materials_unlit){p="phong";break}const b=[],g=[];let y=0,w=!0;return Ke(a,(s,i,a,v)=>{const T=this.be(s,i,a,v,r,!1,p,b),{geometry:_,material:M}=T;M&&!M.isReady()&&(w=!1,y++);const O=new n.reshader.Mesh(_,M);T.refMeshes||(T.refMeshes=new Set,T.refMeshes.add(O.uuid)),O.properties.magic="b3dm",O.properties.id=e,O.properties.node=r,t.batchTable&&(O.properties.batchTable=t.batchTable,O.properties.batchTableBin=t.batchTableBin),O.properties.count=t.featureTable&&t.featureTable.BATCH_LENGTH||0,O.properties.serviceIndex=r.Rt;const x=this.ge(s,_,M,r.Rt,v);O.setDefines(x);const A=s.compressUniforms;if(A)for(const t in A)O.setUniform(t,A[t]);s.compressed_int16_params&&this.ue(O,s.compressed_int16_params),this.ye(O,s.attributes),o&&(x.USE_MAX_EXTENT=1,O.setUniform("maxPrjExtent",o)),Object.prototype.hasOwnProperty.call(O.uniforms,"polygonOpacity")||Object.defineProperty(O.uniforms,"polygonOpacity",{enumerable:!0,get:function(){return ht(m.opacity)?m.opacity:1}}),Object.prototype.hasOwnProperty.call(O.uniforms,"polygonFill")||Object.defineProperty(O.uniforms,"polygonFill",{enumerable:!0,get:function(){return Mt([],m.polygonFill||kr)}}),Object.prototype.hasOwnProperty.call(O.material.uniforms,"hsv")||Object.defineProperty(O.material.uniforms,"hsv",{enumerable:!0,get:function(){return m.hsv||Lr}});const I=n.mat4.identity([]);if(l&&s.matrices&&s.matrices.length)for(let t=0;t<s.matrices.length;t++)n.mat4.multiply(I,I,s.matrices[t]);l&&n.mat4.multiply(I,f,I),O.properties.node=r,O.properties.projCenter=c,O.properties.nodeMatrix=I,O.properties.isSharedPosition=l,O.properties.rtcCoord=h,O.properties.rtcCenter=u,this.oe(O,d),g.push(O),delete s.attributes,O.Bt=n.mat4.copy([],O.localTransform)}),hs(b),w?(this.ut[e]=g,i(null,{id:e,mesh:g})):(this.ht[e]={meshes:g,count:y},g.we=i),g}Te(t){const e=this.rt._e[t.id];if(!e)return;let r,s,i,o;if(e.length){if(2===e.length){const t=e[0],n=e[1];r=is.vertices,s=is.indices,i=t,o=[n,n,n]}}else{r=e.boxPosition,s=ss;i=this.rt.Yt(t.Rt).Me,o=as}const a=new n.reshader.Geometry({POSITION:r},s,0,{primitive:"lines",positionAttribute:"POSITION"}),c=new n.reshader.Mesh(a,new n.reshader.Material({lineColor:[.8,.8,.1,1],lineOpacity:1})),h=n.mat4.identity([]);n.mat4.fromRotationTranslationScale(h,os,i,o),c.localTransform=h,c.Bt=n.mat4.copy([],h),c.properties.node=t,t.kt=c}ue(t,e){e.POSITION&&t.setUniform("compressedPositionRange",e.POSITION),e.TEXCOORD_0&&t.setUniform("compressedTexcoordRange_0",e.TEXCOORD_0),e.TEXCOORD_1&&t.setUniform("compressedTexcoordRange_1",e.TEXCOORD_0),e.NORMAL&&t.setUniform("compressedNormalRange",e.NORMAL),e.TANGENT&&t.setUniform("compressedTangentRange",e.TANGENT),e.compressed_ratio&&t.setUniform("compressed_ratio",e.compressed_ratio)}oe(t,e){const{isSharedPosition:r,rtcCoord:s,rtcCenter:i,projCenter:o,nodeMatrix:a,node:c}=t.properties;e||(e=r?this.me(Kr,s):this.le(Kr,s,o,c.Rt));const h=t.localTransform||n.mat4.identity([]);if(r){const t=this.pe(Qr,c,i,s);n.mat4.multiply(h,e,a),n.mat4.multiply(h,t,h)}else n.mat4.multiply(h,e,a);const u=this.rt.Pt(c.Rt);if(u.coordOffset){const t=this.ve(Qr,c.Rt,s);n.mat4.multiply(h,t,h)}t.setLocalTransform(h),t.properties.heightOffset=u.heightOffset||0,t.properties.coordOffset=u.coordOffset&&u.coordOffset.slice(0)||Dr}ye(t,e){if(e&&e.TEXCOORD_0&&e.TEXCOORD_0.extensions&&e.TEXCOORD_0.extensions.WEB3D_quantized_attributes){const n=e.TEXCOORD_0.extensions.WEB3D_quantized_attributes.decodeMatrix;t.setUniform("decodeMatrix",n)}}pe(t,e,r,i){const o=this.getMap(),a=this.rt.Pt(e.Rt).heightOffset||0,c=new s.Coordinate(i);let h;h=o.altitudeToPoint?this.It:o.distanceToPointAtRes(100,100,o.getGLRes(),c).y/100;const u=e.matrix?n.mat4.copy(t,e.matrix):n.mat4.identity(t);if(r){Jn(u,n.vec3.transformMat4(Hr,r,u),u)}const l=function(t,e,n,r,s,i,o){e=Bt(Qn,e);const a=un(Qn,e[0]*ir,e[1]*ir,e[2]),c=function(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}(Zn,n),h=r.ellipsoid;let u;u=0===Xt(c)?Ut(Yn,0,0,-6378137):bn(Yn,c),rr.x=u[0],rr.y=u[1];const l=r.project(rr,sr);Wn[0]=l.x/s,Wn[1]=l.y/s,Wn[2]=(u[2]+o)*i;const f=Kn(a,h,tr),d=function(t,e,n){const r=t[0],s=t[1],i=t[2],o=t[4],a=t[5],c=t[6],h=t[8],u=t[9],l=t[10],f=e[0],d=e[1],m=e[2],p=e[3],b=e[4],g=e[5],y=e[6],w=e[7],v=e[8],T=r*f+o*d+h*m,_=s*f+a*d+u*m,M=i*f+c*d+l*m,O=r*p+o*b+h*g,x=s*p+a*b+u*g,A=i*p+c*b+l*g,I=r*y+o*w+h*v,S=s*y+a*w+u*v,E=i*y+c*w+l*v;return n[0]=T,n[1]=_,n[2]=M,n[3]=0,n[4]=O,n[5]=x,n[6]=A,n[7]=0,n[8]=I,n[9]=S,n[10]=E,n[11]=0,n[12]=t[12],n[13]=t[13],n[14]=t[14],n[15]=t[15],n}(function(t,e){var n=e[0],r=e[1],s=e[2],i=e[3],o=e[4],a=e[5],c=e[6],h=e[7],u=e[8],l=e[9],f=e[10],d=e[11],m=e[12],p=e[13],b=e[14],g=e[15],y=n*a-r*o,w=n*c-s*o,v=n*h-i*o,T=r*c-s*a,_=r*h-i*a,M=s*h-i*c,O=u*p-l*m,x=u*b-f*m,A=u*g-d*m,I=l*b-f*p,S=l*g-d*p,E=f*g-d*b,N=y*E-w*S+v*I+T*A-_*x+M*O;return N?(N=1/N,t[0]=(a*E-c*S+h*I)*N,t[1]=(s*S-r*E-i*I)*N,t[2]=(p*M-b*_+g*T)*N,t[3]=(f*_-l*M-d*T)*N,t[4]=(c*A-o*E-h*x)*N,t[5]=(n*E-s*A+i*x)*N,t[6]=(b*v-m*M-g*w)*N,t[7]=(u*M-f*v+d*w)*N,t[8]=(o*S-a*A+h*O)*N,t[9]=(r*A-n*S-i*O)*N,t[10]=(m*_-p*v+g*y)*N,t[11]=(l*v-u*_-d*y)*N,t[12]=(a*x-o*I-c*O)*N,t[13]=(n*I-r*x+s*O)*N,t[14]=(p*w-m*T-b*y)*N,t[15]=(u*T-l*w+f*y)*N,t):null}(er,f),function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t}(nr,n),t);return Jn(t,Wn,d),t}(u,i,u,o.getProjection(),o.getGLRes(),h,a),f=function(t,e){return Ut(t,e[12],e[13],e[14]),t}(Jr,l);let d=this.rt.options.offset;if(at(d)){const t=this.rt.Oe(e.id).center;d=d.call(this.rt,t)}return n.vec3.set(Xr,d[0],d[1],0),n.vec3.sub(f,f,Xr),Jn(l,f,l),l}ve(t,e,r){const s=this.rt.Pt(e);if(!s.coordOffset)return null;const i=this.getMap(),o=i.getGLRes();Gr.set(r[0],r[1]);const a=i.coordToPointAtRes(Gr,o,Vr),c=s.coordOffset,h=Gr.set(r[0]+c[0],r[1]+c[1]),u=i.coordToPointAtRes(h,o,$r),l=u.x-a.x,f=u.y-a.y,d=this.Wt(),m=n.vec3.set(Xr,l,f,(c[2]||0)*d);return n.mat4.fromTranslation(t,m)}Wt(){const t=this.getMap();let e;return e=t.altitudeToPoint?this.It:t.distanceToPointAtRes(100,100,t.getGLRes(),Gr).y/100,e}createCMPTMesh(t,e,n,r){if(this.dt[e]){const t=this.dt[e];return console.warn(`mesh with id(${e}) was already created.`),r(null,{id:e,mesh:t}),t}const{content:s}=t,i=[];for(let t=0;t<s.length;t++){const{magic:r}=s[t],o=e+"."+t;"b3dm"===r?this.createB3DMMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)}):"i3dm"===r?this.createI3DMMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)}):"pnts"===r?this.createPntsMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)}):"cmpt"===r&&this.createCMPTMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)})}return this.dt[e]=i,r(null,{id:e,mesh:i}),i}ge(t,e,n,r,s){const i=("phong"===(this.rt.Pt(r).shader||"pbr")?this.$t:this.Xt).getGeometryDefines(e);s.asset&&"S3M"===s.asset.generator&&this.xe(i,e),e.data.uvRegion&&(i.HAS_I3S_UVREGION=1),e.data[e.desc.normalAttribute]&&(i.VertexNormal=1),e.data[e.desc.color0Attribute]&&(i.VertexColor=1),e.data[e.desc.uv0Attribute]&&(i.TexCoord=1),e.data[e.desc.textureCoordMatrixAttribute]&&(i.HAS_TextureCoordMatrix=1),n.get("uTexture")&&(i.COMPUTE_TEXCOORD=1),n.get("uTexture2")&&(i.TexCoord2=1),"MESHOPT"===this.rt.Ae&&(i.MeshOPT_Compress=1),this.hasIBL()&&(i.HAS_IBL_LIGHTING=1),t.attributes&&t.attributes.TEXCOORD_0&&"WEB3D_quantized_attributes"===t.attributes.TEXCOORD_0.extensions&&(i.HAS_WEB3D_quantized_attributes_TEXCOORD=1),i.HAS_MIN_ALTITUDE=1,i.HAS_LAYER_OPACITY=1,this.he(i,t.compressed_int16_params);return ot(i,t.compressDefines),i}he(t,e){e&&Object.keys(e).length>0&&(t.HAS_COMPRESSED_INT16=1,e.POSITION&&(t.HAS_COMPRESSED_INT16_POSITION=1),e.TEXCOORD_0&&(t.HAS_COMPRESSED_INT16_TEXCOORD_0=1),e.TEXCOORD_1&&(t.HAS_COMPRESSED_INT16_TEXCOORD_1=1),e.NORMAL&&(t.HAS_COMPRESSED_INT16_NORMAL=1),e.TANGENT&&(t.HAS_COMPRESSED_INT16_TANGENT=1),e.compressed_ratio&&(t.HAS_COMPRESSED_INT16_RATIO=1))}Gt(t){const e=this.rt.getRenderer();e&&e.updateMaskDefines(t)}xe(t,e){e.data.aNormal&&(t.VertexNormal=1),e.data.instanceId&&(t.Instance=1),e.data.aTexCoord0&&(t.TexCoord=1),e.data.aColor&&(t.VertexColor=1),e.data.aTexCoord1&&(t.TexCoord2=1),e.data.uv2&&(t.InstanceBim=1)}be(t,e,n,r,s,i,o,a){let c=!1;r.asset&&"S3M"===r.asset.generator&&(c=!0,r.extensions=r.extensions||{});const h=r.url+"-"+e+"-"+n;if(this.pt[h])return this.pt[h];let u,l;a.push(t);const f=r.materials&&r.materials[t.material],d=r.extensions&&r.extensions.KHR_techniques_webgl,m=this.rt.Pt(s.Rt);if(d&&f.extensions&&f.extensions.KHR_techniques_webgl){const e=this.Ie(t,r,i,c);u=e.material,l=e.geometry,m.fillEmptyDataInMissingAttribute&&(l.desc.fillEmptyDataInMissingAttribute=!0)}else{l=this.Se(t,i,rs);const e=m.ambientLight;let n=m.environmentExposure;const s=m.material,c=this.getMap().getLightManager(),h=c&&c.getAmbientLight();if(e&&(!h||h.color)&&void 0===n){const t=h&&h.color?h.color[0]:.2;n=e[0]/t}u=this.Ee(t.material,r,o,s||Br,n||1,a,m)}u&&Object.defineProperty(u.uniforms,"alphaTest",{enumerable:!0,get:function(){const t=m.alphaTest;return it(t)?.1:t}}),u&&!u.isReady()?u.Ne=s.id:u||(u=this.Mt);const p={geometry:l,material:u};return l.properties.url=h,this.pt[h]=p,p}Ie(t,e,n,r){const{geometry:s,material:i}=this.xt.createMesh(t,e,n,r);return{geometry:s,material:i}}Se(t,e,r){const s=t.attributes;let i=s._BATCHID&&s._BATCHID.array;if(i&&i.byteOffset&&(i=new i.constructor(i)),s.COLOR_0){const t=s.COLOR_0.array||s.COLOR_0;if(t instanceof Float32Array){const e=new Uint8Array(t.length);for(let n=0;n<e.length;n++)e[n]=Math.round(255*t[n]);s.COLOR_0.array?(s.COLOR_0.array=e,s.COLOR_0.componentType=5121):s.COLOR_0=e}}const o={};for(const t in s){const e=Ar(this.ot,s[t],{dimension:s[t].itemSize}),n=r[t]||t;o[n]={buffer:e},s[t].quantization&&(o[n].quantization=s[t].quantization),n===r.POSITION&&(o[n].array=s[t].array,o[n].min=s[t].min,o[n].max=s[t].max)}const a=t.indices?t.indices.array?t.indices.array.slice():t.indices:null,c=new n.reshader.Geometry(o,a,0,{static:!0,positionAttribute:r.POSITION,normalAttribute:r.NORMAL,uv0Attribute:r.TEXCOORD_0,uv1Attribute:r.TEXCOORD_1,color0Attribute:r.COLOR_0,tangentAttribute:r.TANGENT,pickingIdAttribute:r._BATCHID,primitive:void 0===t.mode?"triangles":xr(t.mode)});return i&&a&&(c.properties.batchIdData=i,c.properties.batchIdMap=function(t,e){if(!e)return null;const n=new Map;for(let r=0;r<e.length;r++){const s=e[r],i=t[s];let o=n.get(i);o||(o=[],n.set(i,o)),o.push(s)}return n}(i,a)),c.generateBuffers(this.ot,{excludeElementsInVAO:e}),c}le(t,e,r,s){const i=n.mat4.identity(t),o=this.getMap();Gr.x=r[0],Gr.y=r[1];const a=this._prjToPoint(Gr),c=this.Ce(),h=1/(o.getGLZoom?o.getResolution(o.getGLZoom()):o.getGLRes());Gr.x=e[0],Gr.y=e[1];const u=this.Wt();let l=this.rt.options.offset;at(l)&&(l=l.call(this.rt,Gr));const f=this.rt.Pt(s).heightOffset||0;return n.vec3.set(Jr,a.x-l[0],a.y-l[1],u*r[2]+u*f),n.mat4.translate(i,i,Jr),n.vec3.set(c,h,h,u),n.mat4.scale(i,i,c),i}qt(t,e){const r=this.rt.Pt(e.Rt),s=this.rt.Yt(e.Rt).Me;let i=r.rotation||[0,0,0];i=n.quat.fromEuler(Wr,i[0],i[1],i[2]);const o=r.scale||[1,1,1],a=n.mat4.fromRotationTranslationScale([],i,ts,o),c=n.mat4.identity([]),h=n.mat4.identity([]);n.mat4.translate(c,c,n.vec3.scale(ns,s,-1)),n.mat4.translate(h,h,s);const u=n.mat4.multiply(c,c,t.Bt);n.mat4.multiply(a,a,u);const l=n.mat4.multiply(h,h,a);t.localTransform=l}me(t,e){const r=n.mat4.identity(t),s=this.getMap(),i=this.Ce();Gr.x=e[0],Gr.y=e[1];const o=s.distanceToPointAtRes(100,100,s.getGLRes(),Gr);let a;return a=s.altitudeToPoint?this.It:o.y/100,n.vec3.set(i,o.x/100*1.01,o.y/100*1.01,a),n.mat4.scale(r,r,i),r}Ot(){const t={x:0,y:0,width:()=>this.st?this.st.width:1,height:()=>this.st?this.st.height:1},e=[],r=[];this.Kt=new n.reshader.MeshShader({vert:on,frag:"#define SHADER_NAME PNTS\n\nprecision mediump float;\n\n\n\nvarying vec4 vColor;\n\n\n\nvoid main() {\n\n vec2 circCoord = 2.0 * gl_PointCoord - 1.0;\n\n if (dot(circCoord, circCoord) > 1.0) {\n\n discard;\n\n } else {\n\n gl_FragColor = vColor;\n\n }\n\n}\n\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:(t,e)=>n.mat4.multiply(r,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,r)=>n.mat3.fromMat4(e,r.modelMatrix)}],extraCommandProps:{viewport:t,blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"},depth:{enable:!0,range:[0,1],func:"<"}}});const s=this.At();this.$t=new n.reshader.PhongShader({extraCommandProps:s}),this.Xt=new n.reshader.pbr.StandardShader({extraCommandProps:s}),this.Zt=new n.reshader.EdgeShader({extraCommandProps:{viewport:{x:0,y:0,width:()=>this.st?this.st.width:1,height:()=>this.st?this.st.height:1},blend:{enable:!0,func:{srcRGB:"src alpha",srcAlpha:1,dstRGB:"one minus src alpha",dstAlpha:"one minus src alpha"},equation:"add"}}});const i=this.rt;Er(i.getRenderer().canvas,this.ot,i.getMap()),this.picking=new n.reshader.FBORayPicking(this.ct,{vert:this.Xt.vert,extraCommandProps:s,uniforms:this.Xt.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap()),this.Pe=new n.reshader.FBORayPicking(this.ct,{vert:on,extraCommandProps:s,uniforms:this.Kt.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap())}At(){return{viewport:{x:0,y:0,width:()=>this.st?this.st.width:1,height:()=>this.st?this.st.height:1},cull:{enable:!0},stencil:{enable:!0,func:{cmp:(t,e)=>e.meshProperties.isLeaf?"always":">=",ref:(t,e)=>e.meshProperties.level},opFront:{fail:"keep",zfail:"keep",zpass:"replace"},opBack:{fail:"keep",zfail:"keep",zpass:"replace"}},depth:{enable:!0,range:[0,1],func:(t,e)=>e.meshProperties.depthFunc||"<"},blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"},polygonOffset:{enable:!0,offset:(t,e)=>e.meshProperties.polygonOffset}}}Jt(t){const e=this.getMap(),r=e.getLightManager(),s=(r&&r.getDirectionalLight()||{}).direction||[1,1,-1],i=t&&t.pointOpacity||1;return{projViewMatrix:e.projViewMatrix,pointOpacity:i,lightDir:n.vec3.normalize(s,s)}}Et(){const t=this.getMap(),e=this.rt,n=e.getRenderer().canvas,{iblTexes:r,dfgLUT:s}=Cr(n),i=Pr(t,r,s),o=this.rt.getRenderer(),a=o.getMaskUniforms();i.minAltitude=e.options.altitude||0;const c=o.canvas.gl&&o.canvas.gl.wrap?e.options.opacity||0:1;return i.layerOpacity=c,ot(i,{czm_lightDirectionEC:i.light0_viewDirection,lightSpecular:[1,1,1],viewMatrix:t.viewMatrix,projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,outSize:[n.width,n.height],polygonFill:[1,1,1,1],polygonOpacity:1}),ot(i,a),i}Ee(t,e,r,s,i,o,a){const c=e.materials&&e.materials[t];if(!c||!c.baseColorTexture&&!c.pbrMetallicRoughness)return null;const h=ot({},s);if(c.baseColorTexture){const t=e.textures[c.baseColorTexture.index];let n;t&&!t.image.color&&(n=this.C(t,o)),h.baseColorFactor=t&&t.image.color||c.baseColorFactor||[1,1,1,1],n&&(h.baseColorTexture=n)}else{if(c.normalTexture){const t=this.C(e.textures[c.normalTexture.index],o);if(t){const e=c.normalTexture.scale||1;h.normalTexture=t,h.normalMapFactor=e}}if(c.occlusionTexture){const t=this.C(e.textures[c.occlusionTexture.index],o);if(t){const e=c.occlusionTexture.strength||1;h.occlusionTexture=t,h.occlusionFactor=e}}if(c.emissiveTexture){const t=this.C(e.textures[c.emissiveTexture.index],o);t&&(h.emissiveTexture=t)}c.emissiveFactor&&(h.emissiveFactor=c.emissiveFactor);const t=c.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(h.baseColorFactor=t.baseColorFactor),t.baseColorTexture&&void 0!==t.baseColorTexture.index){const r=e.textures[t.baseColorTexture.index];if(r.image&&r.image.color)h.baseColorFactor=h.baseColorFactor?n.vec4.multiply(h.baseColorFactor,h.baseColorFactor,r.image.color):r.image.color;else{const t=this.C(r,o);t&&(h.baseColorTexture=t,h.baseColorTexture.getREGLTexture(this.ot))}}if(it(t.metallicFactor)||(h.metallicFactor=t.metallicFactor),it(t.roughnessFactor)||(h.roughnessFactor=t.roughnessFactor),c.metallicRoughnessTexture){const t=this.C(e.textures[c.metallicRoughnessTexture.index],o);t&&(h.metallicRoughnessTexture=t)}}}if(c.s3mMaterial)return new n.reshader.Material(h);if(h.environmentExposure=i,h.alphaTest=.1,a.unlit||c.extensions&&c.extensions.KHR_materials_unlit)return h.ambientColor=[1,1,1],h.light0_diffuse=[0,0,0,0],h.lightSpecular=[0,0,0],new n.reshader.PhongMaterial(h);let u=new n.reshader.pbr.StandardMaterial(h);"phong"===r&&(u=n.reshader.PhongMaterial.convertFrom(u));const l=c.pbrMetallicRoughness,f=l&&l.baseColorTexture&&l.baseColorTexture.extensions;return f&&f.KHR_texture_transform&&(u.set("khr_offset",f.KHR_texture_transform.offset||[0,0]),u.set("khr_rotation",f.KHR_texture_transform.rotation||0),u.set("khr_scale",f.KHR_texture_transform.scale||[1,1])),u.doubleSided=!(!a.doubleSided&&!c.doubleSided),u.once("complete",this.Tt),u}C(t,e){const r={type:t.type?Mr(t.type):"uint8",format:t.format?Or(t.format):"rgba",flipY:!!t.flipY},s=t.image;if(e.push(s),s.array?r.data=s.array:s.mipmap&&(r.mipmap=s.mipmap),!r.data&&!r.mipmap)return null;if(r.width=s.width,r.height=s.height,r.mipmap&&(r.width<4||r.height<4))return null;const i=t.sampler||t.texture&&t.texture.sampler;return i&&(i.magFilter&&(r.mag=vr(i.magFilter)),i.minFilter&&(r.min=Tr(i.minFilter)),i.wrapS&&(r.wrapS=_r(i.wrapS)),i.wrapT&&(r.wrapT=_r(i.wrapT))),new n.reshader.Texture2D(r,this.vt)}_t({target:t}){const e=t.Ne,n=this.ht[e];if(n.count--,!n.count){const t=n.meshes;this.ut[e]=t,delete this.ht[e];const r=t.we;delete t.we,r(null,{mesh:n.meshes,id:e})}}Ce(){return Ur}Re(t){return this.rt.Re(t)}_pointToPrj(t){const e=this.getMap();return e.getGLZoom?e._pointToPrj(t,e.getGLZoom()):e._pointToPrjAtRes(t,e.getGLRes())}_prjToPoint(t){const e=this.getMap();return e.getGLZoom?e._prjToPoint(t,e.getGLZoom()):e._prjToPointAtRes(t,e.getGLRes(),qr)}fe(t){return"Y"===t?Ir:"X"===t?Sr:Fr}pick(t,e,n=3){const r=this.rt;if(!r||!r.options.picking)return[];if(!this.pickingFBO||!this.picking)return[];const s=[],i=this.Et(),o=this.ke(this.picking,i,this.bt,t,e,n);o&&s.push(o);const a=this.ke(this.picking,i,this.yt,t,e,n);a&&s.push(a);const c=this.Jt(),h=this.ke(this.Pe,c,this.gt,t,e,n);return h&&s.push(h),s}ke(t,e,n,r,s,i){if(!n.getMeshes().length)return null;const o=this.rt,a=this.getMap();t.render(n.getMeshes().filter(t=>!t.bloom),e,!0);let c={};t.getRenderedMeshes().length&&(c=t.pick(r,s,i,e,{viewMatrix:a.viewMatrix,projMatrix:a.projMatrix,returnPoint:o.options.pickingPoint}));const{meshId:h,pickingId:u,point:l,coordinate:f}=c,d=(0===h||h)&&t.getMeshAt(h);if(!d||!d.geometry)return null;const m=d.properties;l&&l.length&&(l[0]=Math.round(1e5*l[0])/1e5,l[1]=Math.round(1e5*l[1])/1e5,l[2]=Math.round(1e5*l[2])/1e5);const p={batchId:u};if(o.options.debug&&(p.debugInfo=m),m&&m.batchTable){const{batchTable:t,batchTableBin:e,count:n}=m,r=u;for(const s in t)void 0!==t[s].byteOffset?p[s]=Pn(t[s],e,n,r):p[s]=t[s][r]}return{service:d.properties.serviceIndex,data:p,point:l,coordinate:f}}Nt(t){let e=new Set;for(let n=0,r=t.length;n<r;n++){const r=t[n].data.node;this.Ct(r)&&e.add(r.zt)}e=Array.from(e),e.sort();const n=new Map,r=e.length;for(let t=0;t<r;t++)n.set(e[t],t);return n}highlight(t){this.Ut=t;const e=this.rt.getRenderer();this.Ft=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelAllHighlight(){this.Ut=null;const t=this.rt.getRenderer();this.Ft=t.getFrameTimestamp(),t.setToRedraw(!0)}showOnly(t){this.Dt=t;const e=this.rt.getRenderer();this.jt=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelShowOnly(){this.Dt=null;const t=this.rt.getRenderer();this.jt=t.getFrameTimestamp(),t.setToRedraw(!0)}Le(){if(!this.St)return[];const t={},e=[];for(const n in this.St){const r=this.St[n];if(r)for(let n=0;n<r.length;n++){const s=r[n],i=s&&s.geometry;if(!s||!i)continue;const o=s.properties.serviceIndex;t[o]||(t[o]=new Set);const a=i.properties.batchIdData;if(a)for(let n=0;n<a.length;n++)t[o].has(a[n])||(e.push({id:a[n],service:o}),t[o].add(a[n]))}}return e}hasIBL(){const t=this.getMap().getLightManager();return!!(t&&t.getAmbientResource())}}function hs(t){for(let e=0;e<t.length;e++)t[e]&&(t[e].array&&(t[e].array=null),t[e].mipmap&&(t[e].mipmap=null),t[e].indices&&(t[e].indices=null))}const us=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("unable to locate global object")},ls=us(),fs=ls.gl_trans__coders=ls.gl_trans__coders||{};function ds(t,e){if(e)for(let n=0;n<e.length;n++){t[e[n].id||e[n].index]=e[n]}}fs.inject=function(t){const e=t.toString(),n=e.indexOf("{")+1,r=e.substring(0,n),s=ls.gl_trans__coders=ls.gl_trans__coders||{};let i=`${r}\n const _____getGlobal = ${us.toString()};\n const g___lobals = _____getGlobal()\n const tran_____scoders = g___lobals['gl_trans__coders'] = g___lobals['gl_trans__coders'] || {};`;for(const t in s)"inject"!==t&&"getTranscoder"!==t&&"registerTranscoder"!==t&&(i+='tran_____scoders["'+t+'"] ='+s[t].toString()+"\n;");return i+="\n"+e.substring(r.length),i},fs.registerTranscoder=function(t,e){fs[t]=e},fs.getTranscoder=function(t){return fs[t]};const ms=[];class ps{constructor(t,e,n,r,s){this.rt=r,this.Be=t,this.Rt=e,this.Ue=s,this.Fe=n.version,t.indexOf("i3s:tileset:")<0?(this.Fe<=1.6?this.De="root":this.De=0,n.version=this.Fe):(this.De=t.substring("i3s:tileset:".length),this.Fe>1.6&&(this.De=parseInt(this.De))),this.Be=t,this.je=n}load(){const t=this.je,e=t.layerScene.baseUrl;if(this.Fe<=1.6)return t[this.De]&&t[this.De].lodSelection?(this.ze=t[this.De],this.He()):new Promise(n=>{let r=e+"/nodes/"+this.De;t.layerScene.eslpk&&(r+="/3dNodeIndexDocument.json"),this.Ue(this.Rt,r,()=>{this.ze=t[this.De],n(this.He())})});if(this.Fe>=1.7){if(t[this.De])return this.ze=t[this.De],this.He();const n=Math.floor(this.De/t.nodesPerPage);return new Promise(r=>{let s=e+"/nodepages/"+n;t.layerScene.eslpk&&(s+=".json"),this.Ue(this.Rt,s,()=>{this.ze=t[this.De],r(this.He())})})}return null}getTileset(){return this.Ge}getChildrenURL(){return this.qe}He(){const t=this.je,e=t.layerScene.baseUrl,n=this.ze.children,r=[],s={};if(n)for(let i=0;i<n.length;i++)if(this.Fe<=1.6){const o=n[i].id;if(t[o])continue;const a=o;s[a]||(s[a]=new Promise(n=>{let r=e+"/nodes/"+a;t.layerScene.eslpk&&(r+="/3dNodeIndexDocument.json"),this.Ue(this.Rt,r,()=>{n()})}),r.push(s[a]))}else{const o=n[i];if(t[o])continue;const a=Math.floor(o/t.nodesPerPage);s[a]||(s[a]=new Promise(n=>{let r=e+"/nodepages/"+a;t.layerScene.eslpk&&(r+=".json"),this.Ue(this.Rt,r,()=>{n()})}),r.push(s[a]))}return r.length?Promise.all(r).then(()=>this.Ve()):this.Ve()}Ve(){return Promise.resolve(this.$e())}Xe(t){ds(this.je,t)}$e(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.Je(this.ze,!0)}}Je(t){const e=this.rt.getRenderer(),n=this.je.projection,r=!n||n&&4326===n.wkid,s=this.Fe,i=this.je,o=t,a=o.obb,c=o.mbs,h={};let u;if(c)u=Ut([],c[0],c[1],c[2]),r||(u=e.Ke(u,u)),u=bs([],u[0],u[1],u[2]),h.sphere=[...u,c[3]];else if(a){u=Ut([],a.center[0],a.center[1],a.center[2]),r||(u=e.Ke(u,u)),u=bs([],u[0],u[1],u[2]);const t=function(t,e,n){const r=function(t,e){var n=e[0],r=e[1],s=e[2],i=e[3],o=n+n,a=r+r,c=s+s,h=n*o,u=r*o,l=r*a,f=s*o,d=s*a,m=s*c,p=i*o,b=i*a,g=i*c;return t[0]=1-l-m,t[3]=u-g,t[6]=f+b,t[1]=u+g,t[4]=1-h-m,t[7]=d-p,t[2]=f-b,t[5]=d+p,t[8]=1-h-l,t}([],n);return r[0]=r[0]*e[0],r[1]=r[1]*e[0],r[2]=r[2]*e[0],r[3]=r[3]*e[1],r[4]=r[4]*e[1],r[5]=r[5]*e[1],r[6]=r[6]*e[2],r[7]=r[7]*e[2],r[8]=r[8]*e[2],[...t,...r]}(u,a.halfSize,a.quaternion),n=t[3]+t[6]+t[9],s=t[4]+t[7]+t[10],i=t[5]+t[8]+t[11];Ut(ms,n,s,i);const o=Xt(ms);h.sphere=[...u,o]}let l=1/0,f=0;if(o.mbs?f=o.mbs[3]:o.obb&&(f=Math.max(Math.max(o.obb.halfSize[0],o.obb.halfSize[1]),o.obb.halfSize[2])),void 0!==o.lodThreshold)if("maxScreenThresholdSQ"===i.lodSelectionMetricType){l=f/(Math.sqrt(o.lodThreshold)/(.25*Math.PI))}else console.error("Unsupported lodSelectionMetricType in Layer");else if(void 0!==o.lodSelection)for(let t=0;t<o.lodSelection.length;t++)"maxScreenThreshold"===o.lodSelection[t].metricType&&(l=f/o.lodSelection[t].maxError);(l===1/0||isNaN(l))&&(l=1e5);const d=16*l,m=St([]),p=o.children;let b;if(p){b=[];const t=this.je;for(let e=0;e<p.length;e++){const n=s<=1.6?p[e].id:p[e];if(!t[n]){b=null;break}b.push(this.Je(t[n]))}}const g={refine:"REPLACE",boundingVolume:h,transform:m,geometricError:d};return s<=1.6?t.lodSelection?t.geometryData&&(g.content={uri:"i3s:mesh:"+(t.id||t.index)}):g.content={uri:"i3s:tileset:"+(t.id||t.index)}:p&&p.length&&!b?g.content={uri:"i3s:tileset:"+(t.id||t.index)}:o.mesh&&(g.content={uri:"i3s:mesh:"+(t.id||t.index)}),b&&b.length&&(g.children=b),g}getJSON(){return this.ze}}function bs(t,e,n,r){return un(t,ut(e),ut(n),r)}const gs=!!fs.ktx2,ys=n.mat4.identity([]),ws=(()=>{try{if("object"==typeof WebAssembly&&"function"==typeof WebAssembly.instantiate){const t=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));if(t instanceof WebAssembly.Module)return new WebAssembly.Instance(t)instanceof WebAssembly.Instance}}catch(t){}return!1})();function vs(t){return t.indexOf("i3s:mesh")>=0}const Ts="i3s:mesh:".length;function _s(t,e,n,r,s){const i=e.layerScene.eslpk,o=function(t,e){const n=e.substring(Ts);return t>=1.7?parseInt(n):n}(e.version,t),a=e[o],c=e.layerScene.baseUrl,h=[];let u=!1;const l=ys;let f,d;if(e.version<=1.6){if(!a.geometryData)return null;const t=a.geometryData.length;if(!t)return null;let n=c+`/nodes/${a.id}/`+a.geometryData[t-1].href;i&&(n+=".bin");const r={geometry:{url:n,info:e.layerScene.store.defaultGeometrySchema}};let s=a.textureData&&a.textureData[0]&&a.textureData[0].href;if(s){const t=e.layerScene.store.textureEncoding[0];let n;n="image/jpeg"===t?"jpg":"png",i&&(s+="."+n);const o={pbrMetallicRoughness:{baseColorTexture:{url:c+`/nodes/${a.id}/`+s,factor:1,format:n,mimeType:t},metallicFactor:0}};r.material=o}h.push(r)}else{f=a.mesh.geometry,d=a.mesh.material;const t=e.layerScene.geometryDefinitions[f.definition],{geometryBuffers:o}=t;u=r&&2===o.length;const l=fs.draco&&u?o[1]:o[0],m=fs.draco&&u?1:0;let p=c+`/nodes/${f.resource}/geometries/`+m;i&&(p+=".bin");const b={geometry:{url:p,info:l}};if(s&&ws&&u&&!fs.draco)throw new Error("Must import @maptalks/transcoder.draco to load i3s draco compressed geometry");const g=e.layerScene.materialDefinitions,y=e.layerScene.textureSetDefinitions;let w,v=0;if(d&&(v=g[d.definition]),g){w=function(t,e,n,r,s,i){const o=JSON.parse(JSON.stringify(t));return function t(e,n,r,s,i,o){for(const a in e)if(e[a]&&e[a].textureSetDefinitionId>=0){const t=n[e[a].textureSetDefinitionId],c="images/"+t.formats[0].format,h=Ms(t.formats,i),u={url:r+`/nodes/${s}/textures/${h.name}`,factor:void 0===e[a].factor?1:e[a].factor,format:h.format,mimeType:c};if(o){let t="";switch(h.format){case"dds":t="bin.dds";break;case"jpg":case"png":t=h.format}u.url+="."+t}e[a]=u}else ct(e[a])&&t(e[a],n,r,s,i,o)}(o,e,n,r,s,i),o}(v,y,c,d.resource,n,e.layerScene.eslpk)}else w={pbrMetallicRoughness:{metallicFactor:0}};b.material=w,h.push(b)}return{dracoCompression:u,meshes:h,nodeIndex:o,center:a.obb&&a.obb.center||a.mbs&&[a.mbs[0],a.mbs[1],a.mbs[2]],transform:l}}function Ms(t,e){for(let n=0;n<=t.length;n++){const r=t[n].format;if("dds"===r&&e.hasExtension("WEBGL_compressed_texture_s3tc"))return t[n];if("jpg"===r||"png"===r)return t[n];if("ktx2"===r&&gs)return t[n]}return null}const Os=new s.Coordinate(0,0),xs=new s.Coordinate(0,0),As=new Set,Is=[],Ss=new class{constructor(t,e){this.max=t,this.currentSize=0,this.data=new Map,this.onRemove=e}reset(t){if(this.data){const e=this.data.keys();for(const n of e){const e=this.data.get(n);t&&t!==e.renderer||this.Qe(n,e)}}return t||(this.data=new Map,this.currentSize=0),this}clear(t){this.reset(t)}add(t,e){if(!e)return this;if(e.node&&e.node.memorySize&&(this.currentSize+=e.node.memorySize),this.has(t)){const n=this.data.get(t);n&&n.node&&n.node.memorySize&&(this.currentSize-=n.node.memorySize),this.data.delete(t),this.data.set(t,e)}else this.data.set(t,e);return this}shrink(){if(this.currentSize>this.max){let t=!1;const e=this.data.keys();let n=e.next();for(;this.currentSize>this.max&&void 0!==n.value;){!t&&this.data.get(n.value).current&&(t=!0,console.warn(`current maxGPUMemory(${this.max/1024/1024}) for Geo3DTilesLayer is not enough, one or more current tiles will be discarded.`));const r=this.getAndRemove(n.value);r&&this.onRemove(r),n=e.next()}}}has(t){return this.data.has(t)}keys(){const t=new Array(this.data.size);let e=0;const n=this.data.keys();for(const r of n)t[e++]=r;return t}getAndRemove(t){if(!this.has(t))return null;const e=this.data.get(t);return e.node&&e.node.memorySize&&(this.currentSize-=e.node.memorySize),this.data.delete(t),e}get(t){if(!this.has(t))return null;const e=this.data.get(t);return this.data.delete(t),this.data.set(t,e),e}remove(t){if(!this.has(t))return this;const e=this.data.get(t);return this.Qe(t,e),this}Qe(t,e){e.node&&e.node.memorySize&&(this.currentSize-=e.node.memorySize),this.data.delete(t),this.onRemove(e)}setMaxSize(t){return this.max=t,this.shrink(),this}getMemorySize(){let t=0;const e=this.data.values();for(const n of e){const e=n&&n.node;e&&e.memorySize&&(t+=e.memorySize)}return t}markAll(t,e){const n=this.data.values();for(const r of n)t&&r.renderer!==t||(r.current=e)}}(1024*(s.Browser.mobile?32:1024)*1024,t=>{const e=t.renderer;delete t.renderer,e.deleteTile(t)});let Es=0;class Ns extends(n.MaskRendererMixin(s.renderer.CanvasRenderer)){constructor(t){super(t);const e=1024*t.options.maxGPUMemory*1024;e>Ss.max&&Ss.setMaxSize(e),this.tileCache=Ss,Es++,this.prepareWorker(),this.tilesLoading={},this.Ze={},this.Ye=[],this.Ue=this.We.bind(this)}getAnalysisMeshes(){if(!this.painter)return Is;const t=this.painter.getPaintedMeshes();if(!t)return Is;const e=[],{b3dmMeshes:n,pntsMeshes:r,i3dmMeshes:s}=t;return n.length&&Tt(e,n),r.length&&Tt(e,r),s.length&&Tt(e,s),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.Ye.length||super.needToRedraw())}getFrameTimestamp(){return this.tn}drawOnInteracting(t,e,n){this.draw(e,n)}draw(t,e){this.tn=t;const n=this.prepareCanvas();if(n&&!n.intersects(this.canvasExtent2D))return void this.completeRender();const{root:r,tiles:s}=this.layer.getTiles(),i=s.length;if(!s||!i)return void this.completeRender();this.nn(),this.rn();const{selectedTiles:o,leaves:a,requests:c}=this.sn(r,s);c.length&&this.loadTiles(c),this.in(o,a,e),this.an(),c.length||this.completeRender()}sn(t,e){const n=this.layer.getRootTiles();let r=[];this.cn();let s=0;const i=this.hn(),o={};let a=!1,c=!1;for(let t=0;t<e.length;t++){const i=e[t],h=i.node;if(o[h.id])continue;const u=n[h.Rt];o[h.id]=1;let l=!1;const f=this.getCachedTile(h.id);if(this.un(h.id)?(s++,l=c=!0,this.tilesLoading[h.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=c=!0),(!i.node.ln||u.isS3M||!i.node.children||i.node.ln<=500)&&(a=!0,i.selected=!0,i.data=f)):this.painter.has(h)||(l=c=!0,r.push(h)),!l)continue;if(this.dn(i))a=!0;else{this.mn(i).length&&(a=!0)}}let h=[],u={};if(a&&({selectedTiles:h,leaves:u}=this.pn(t)),r.length>1&&(r.sort(Cs),i)){const t=i-s;r=t>0?r.slice(0,t):[]}return{loading:c,requests:r,selectedTiles:h,leaves:u}}pn(t){const e=[],n={};let r;const s=[t],i=[];for(;s.length>0||i.length>0;){if(i.length>0){const t=i[i.length-1];if(t.bn===s.length){i.pop(),t===r&&(t.leave=!0,n[t.node.id]=1),e.push(t);continue}}const t=s.pop(),o=t.children;if(t.selected)if("add"===t.node.refine)n[t.node.id]=1,t.selectionDepth=i.length,e.push(t);else{if(t.selectionDepth=i.length,r=t,0===o.length){t.leave=!0,n[t.node.id]=1,e.push(t);continue}i.push(t),t.bn=s.length}for(let t=0;t<o.length;t++)s.push(o[t])}return{selectedTiles:e,leaves:n}}dn(t){if(!t.parent)return null;let e=t.parent;for(;e&&e.level>=0;){const t=e.node.id;if(this.tileCache.has(t))return e.selected=!0,e.data=this.tileCache.get(t),e;e=e.parent}return null}mn(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const n=t.zt+1,r=[t.node];for(;r.length>0;){const s=r.pop().children;for(let i=0,o=s.length;i<o;i++){if((!s[i].content||!s[i].content.url)&&s[i].children&&s[i].children.length){r.push(s[i]);continue}const o=s[i].id;if(this.tileCache.has(o)){const n=this.layer.gn(s[i],t);n.selected=!0,n.data=this.tileCache.get(o),t.children.push(n),e.push(n)}else s[i].zt<=n&&r.push(s[i])}}return e}in(t,e,n){this.tileCache.markAll(this,!1);for(let e=0,n=t.length;e<n;e++){const n=t[e].data;n.current=!0,n.renderer=this,this.tileCache.add(t[e].node.id,n)}this.tileCache.shrink();const r={tiles:t,leaves:e};this.onDrawTileStart(r);const s=this.painter.paint(t,e,n);this.onDrawTileEnd(r),s&&this.layer.fire("canvasisdirty",{renderCount:s})}onDrawTileStart(){}onDrawTileEnd(){}loadTiles(t){for(let e=0,n=t.length;e<n;e++){const n=t[e];this.tilesLoading[n.id]={current:!0,node:n},this.loadTile(n)}}loadTile(t){let e=t.content.url;if(wt(e)){const n=vt(e);return this.yn(e,n,t),null}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const n=t.Rt,r=this.wn[n];return new ps(e,n,r,this.layer,this.Ue).load().then(n=>{this.onTilesetLoad(n,t,e)})}return t&&xt(e)&&!vs(e)&&(e=t.baseUrl+e),this.yn(e,null,t),null}yn(t,e,r){let s=this.o;s||(s=n.reshader.Util.getSupportedFormats(this.gl.gl||this.gl),this.o=s);const i=this.layer.Pt(r.Rt);i.isSuperMapiServer&&(t=function(t,e){const n=t.substring(e.length).split("/"),r=[];for(let t=0;t<n.length;t++)r.push(encodeURIComponent(n[t]));return e+r.join("/")}(t,r.baseUrl));const o={url:this.layer.getTileUrl(t,r.baseUrl,this.layer.vn[r.Rt]),arraybuffer:e,rootIdx:r.Rt,upAxis:r.de,transform:r.matrix,supportedFormats:s};if(vs(t)){const e=this.wn[r.Rt];if(o.projection=e.projection,o.i3sInfo=_s(t,e,this.regl,this.layer.options.enableI3SCompressedGeometry,this.layer.options.forceI3SCompressedGeometry),!o.i3sInfo)return void this.onTileError({status:404},r,t)}o.service=ot({},i),i.offset&&delete o.service.offset,o.referrer=window&&window.location.href,this.workerConn.loadTile(this.layer.getId(),o,(e,n)=>{if(e)return void this.onTileError(e,r,t);const{magic:s}=n;"b3dm"===s||"pnts"===s||"i3dm"===s||"cmpt"===s||"gltf"===s?(this.Ye.push({data:n,tile:r}),i.debugShowBoundingVolume&&this.painter.Te(r)):this.onTilesetLoad(n,r,t)})}rn(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let n=0;for(;this.Ye.length&&(n<e||!t.isInteracting());){const{data:t,tile:e}=this.Ye.shift(),{magic:r}=t;"b3dm"===r||"gltf"===r?this.painter.createB3DMMesh(t,e.id,e,(n,{mesh:r})=>{this.Tn(t,e,n,r)}):"pnts"===r?this.painter.createPntsMesh(t,e.id,e,(n,{mesh:r})=>{this.Tn(t,e,n,r)}):"i3dm"===r?this.painter.createI3DMMesh(t,e.id,e,(n,{mesh:r})=>{this.Tn(t,e,n,r)}):"cmpt"===r&&this.painter.createCMPTMesh(t,e.id,e,(n,{mesh:r})=>{this.Tn(t,e,n,r)}),n++}}Tn(t,e,n,r){if(n)this.onTileError(n,e);else{const n=this._n(r);e.memorySize=n,this.onTileLoad(t,e)}}_n(t){let e=0;if(Array.isArray(t))for(let n=0;n<t.length;n++)t[n]&&(e+=this._n(t[n]));else t&&(e+=t.getMemorySize());return e}onTileLoad(t,e){this.layer&&(delete this.tilesLoading[e.id],this.layer.onTileLoad(t,e),this.Mn(e),this.setToRedraw(),this.layer.fire("tileload",{node:e}))}onTilesetLoad(t,e,n){this.layer&&(this.layer.Ae=t.extensions&&t.extensions["s3m:VertexCompressionType"],t.capabilities||t.layers&&t.layers[0]&&t.layers[0].capabilities?this.On(t,e,n):(delete this.tilesLoading[e.id],this.layer.onTilesetLoad(t,e,n)))}onTileError(t,e,n){if(!this.layer)return;const r=n||e.content.url,s=t&&t.message||t;As.has(s)||(console.warn("failed to load 3d tile: "+r),console.warn(t),As.add(s)),delete this.tilesLoading[e.id],this.xn(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}xn(t,e){const n={loadTime:s.Util.now(),current:!0,error:e,node:t};n.renderer=this,this.tileCache.add(t.id,n)}Mn(t){const e={loadTime:s.Util.now(),current:!0,node:t};e.renderer=this,this.tileCache.add(t.id,e)}abortTileLoading(t){if(!t||!this.workerConn)return;const e=t.node.content.url;this.workerConn.abortTileLoading(this.layer.getId(),e),delete this.Ze[e]}cn(){if(this.tilesLoading)for(const t in this.tilesLoading)this.tilesLoading[t].current=!1}deleteTile(t){this.painter.deleteTile(t)}createContext(){const t=this.layer,e=t.options.glOptions||{alpha:!0,depth:!0,stencil:!0,preserveDrawingBuffer:!0,antialias:t.options.antialias},r=this.canvas.gl&&this.canvas.gl.wrap;r?(this.gl=this.canvas.gl.wrap(),this.regl=this.canvas.gl.regl):(this.glOptions=e,this.gl=this.An(this.canvas,e)),this.regl=this.regl||n.createREGL({gl:this.gl,attributes:e,extensions:["OES_element_index_uint"],optionalExtensions:t.options.optionalExtensions||[]}),r&&(this.canvas.pickingFBO=this.canvas.pickingFBO||this.regl.framebuffer(this.canvas.width,this.canvas.height)),this.pickingFBO=this.canvas.pickingFBO||this.regl.framebuffer(this.canvas.width,this.canvas.height),this.painter=new cs(this.regl,t),this.layer.In(),this.layer.fire("contextcreate",{regl:this.regl})}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new $e("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let n=this.layer.options||{};n=ot({},n),delete n.offset;const r=t.options.spatialReference;n.projection=r&&r.coordType||r&&r.projection||t.getSpatialReference().getProjection().code;const s=this.layer.getId();e.addLayer(s,n,t=>{if(t)throw t;this.layer&&(this.ready=!0,this.layer.fire("workerready"))})}onRemove(){this.painter&&this.painter.remove(),this.pickingFBO&&(this.canvas.pickingFBO||this.pickingFBO.destroy(),delete this.pickingFBO),this.workerConn&&(this.workerConn.removeLayer(this.layer.getId(),t=>{if(t)throw t}),this.workerConn.remove(),delete this.workerConn),Es--,Es||Ss.reset(),this.clear(),delete this.tileCache,super.onRemove()}clear(){this.an(!0),this.tileCache.reset(this),this.tilesLoading={},super.clear()}clearCanvas(){this.regl&&this.regl.clear({color:[0,0,0,0],depth:1,stencil:0}),super.clearCanvas()}getTileOpacity(){return 1}getStencilValue(){return 0}an(t){this.Sn||(this.Sn=Date.now());const e=Date.now();if(!t&&e-this.Sn<this.layer.options.retireInterval)return;this.Sn=e;const n=[];for(const e in this.tilesLoading){const r=this.tilesLoading[e];!t&&r.current||(n.push(e),this.abortTileLoading(r))}for(let t=0;t<n.length;t++)delete this.tilesLoading[n[t]]}hn(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}An(t,e){const n=["webgl","experimental-webgl"];let r=null;for(let s=0;s<n.length;++s){try{r=t.getContext(n[s],e)}catch(t){}if(r)break}return r}un(t){return!!this.tilesLoading[t]}getI3DMMeshes(){return this.painter.getI3DMMeshes()}getPNTSMeshes(){return this.painter.getPNTSMeshes()}getB3DMMeshes(){return this.painter.getB3DMMeshes()}readBatchData(t,e,n){return Nn(t,e,0,n)}nn(){if(!this.En)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const n=[];for(const r in this.En){const s=this.En[r];if("pending"===s.status)continue;s.status="pending";const i=s.rootIdx,o=At(this.layer.Pt(i).fetchOptions);if(n.push(ye.getJSON(r,o).then(t=>{delete this.En[r];const e=this.wn[i];if(e){t.nodes?ds(e,t.nodes):(e[t.id]=t,ds(e,t.children));for(let t=0;t<s.length;t++)s[t]();this.setToRedraw()}else this.setToRedraw()})),e++,e>=t)break}n.length&&Promise.all(n)}We(t,e,n){this.En||(this.En={}),this.En[e]=this.En[e]||[],this.En[e].rootIdx=t,this.En[e].push(n),this.setToRedraw()}On(t,e,n){this.wn||(this.wn=[]);const r=e.Rt;this.wn[r]||(this.wn[r]={});const s=this.wn[r],i=this.layer.Pt(r);t.layers&&(t=t.layers[0],"/"!==n[n.length-1]&&(n+="/"),n+="layers/0"),s.version=+(i.i3sVersion||t.store.version),!t.spatialReference||t.spatialReference.wkid&&4326===t.spatialReference.wkid||console.warn("i3s has a spatialReference other than 4326.",t.spatialReference),s.projection=t.spatialReference,function(t,e,n,r,s,i,o){if(!i.layerScene){i.layerScene=e,i.nodesPerPage=e.nodePages&&e.nodePages.nodesPerPage||64,i.lodSelectionMetricType=e.nodePages&&e.nodePages.lodSelectionMetricType;let t=s;i.layerScene.eslpk=t.indexOf("3dSceneLayer.json")>=0;if(t.endsWith(".json")){const e=s.lastIndexOf("/");t=e<0?"./":s.substring(0,e)}i.layerScene.baseUrl=function(t){return t.split("?")[0]}(t)}return new ps(s,n,i,t,o).load()}(this.layer,t,r,0,n,s,this.Ue).then(t=>{this.onTilesetLoad(t,e,n)})}pick(t,e,n){if(!this.painter)return[];const r=this.pickingFBO,{width:s,height:i}=this.canvas;return!this.pickingFBO||r.width===s&&r.height===i||r.resize(s,i),this.painter.pick(t,e,n&&n.tolerance)}highlight(t){if(this.Ut||(this.Ut=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const n=t[e].service||0;let r=this.Ut[n];r||(r=this.Ut[n]=new Map),r.set(t[e].id,t[e])}else{const e=t.service||0;let n=this.Ut[e];n||(n=this.Ut[e]=new Map),n.set(t.id,t)}this.painter.highlight(this.Ut)}cancelHighlight(t,e){if(!this.Ut)return;const n=this.Ut[t];if(n){if(Array.isArray(e))for(let t=0;t<e.length;t++)n.delete(e[t]);else n.delete(e);n.size||(this.Ut[t]=null),this.painter.highlight(this.Ut)}}cancelAllHighlight(){delete this.Ut,this.painter.cancelAllHighlight()}showOnly(t){if(this.Dt||(this.Dt=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const n=t[e].service||0;let r=this.Dt[n];r||(r=this.Dt[n]=new Map),r.set(t[e].id,t[e])}else{const e=t.service||0;let n=this.Dt[e];n||(n=this.Dt[e]=new Map),n.set(t.id,t)}this.painter.showOnly(this.Dt)}cancelShowOnly(){delete this.Dt,this.painter.cancelShowOnly()}Le(){return this.painter?this.painter.Le():[]}Ke(t,e){const n=this.getMap();if("identity"===n.getProjection().code.toLowerCase()){const n=this.Nn();return Os.x=e[0],Os.y=e[1],n.unproject(Os,xs),t[0]=xs.x,t[1]=xs.y,t}return Os.x=e[0],Os.y=e[1],n.getProjection().unproject(Os,xs),t[0]=xs.x,t[1]=xs.y,t}Cn(t,e){const n=this.Nn();return Os.x=e[0],Os.y=e[1],n.project(Os,xs),t[0]=xs.x,t[1]=xs.y,t}Pn(t,e){const n=this.Nn();return Os.x=e[0],Os.y=e[1],n.unproject(Os,xs),t[0]=xs.x,t[1]=xs.y,t}Nn(){const t=this.getMap().options.spatialReference.coordType;if(!t)throw new Error("Missing coordType in map spatialReference.");return this.Rn||(this.Rn=s.SpatialReference.getProjectionInstance(t)),this.Rn}}function Cs(t,e){return t.ne-e.ne}function Ps(t,e,n){return t[0]=e[n],t[1]=e[n+3],t[2]=e[n+6],t}function Rs(t,e,n){return Math.sqrt(function(t,e,n){const r=Dt(ks,n,t),s=Ps(Ls,e,0),i=Ps(Bs,e,1),o=Ps(Us,e,2),a=Xt(s),c=Xt(i),h=Xt(o);Ht(s,s),Ht(i,i),Ht(o,o);const u=Fs;u[0]=Gt(r,s),u[1]=Gt(r,i),u[2]=Gt(r,o);let l,f=0;u[0]<-a?(l=u[0]+a,f+=l*l):u[0]>a&&(l=u[0]-a,f+=l*l);u[1]<-c?(l=u[1]+c,f+=l*l):u[1]>c&&(l=u[1]-c,f+=l*l);u[2]<-h?(l=u[2]+h,f+=l*l):u[2]>h&&(l=u[2]-h,f+=l*l);return f}(t,e,n))}const ks=[],Ls=[],Bs=[],Us=[],Fs=[];const Ds=2*Math.PI;class js{constructor(t,e,n,r){this.west=t,this.south=e,this.east=n,this.north=r}static contains(t,e){let n=e[0];const r=e[1],s=t.west;let i=t.east;return i<s&&(i+=Ds,n<0&&(n+=Ds)),(n>s||On(n,s,1e-14))&&(n<i||On(n,i,1e-14))&&r>=t.south&&r<=t.north}static southwest(t,e){return e[0]=t.west,e[1]=t.south,e[2]=0,e}static northeast(t,e){return e[0]=t.east,e[1]=t.north,e[2]=0,e}static southeast(t,e){return e[0]=t.east,e[1]=t.south,e[2]=0,e}static northwest(t,e){return e[0]=t.west,e[1]=t.north,e[2]=0,e}}const zs=[0,0,1];function Hs(t,e){return un(e,t[0],t[1],t[2])}class Gs{constructor(t,e){this.normal=n.vec3.copy([],t),this.distance=e}static fromPointNormal(t,e,r){const s=-n.vec3.dot(e,t);return n.vec3.copy(r.normal,e),r.distance=s,r}}const qs=[],Vs=[],$s=[],Xs=[],Js=[],Ks=[],Qs=[],Zs=[],Ys=[],Ws=[],ti=new Gs([1,0,0],0),ei=[];class ni{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new js(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){let r=0;if(!js.contains(this.rectangle,e)){const e=this.southwestCornerCartesian,s=this.northeastCornerCartesian,i=this.westNormal,o=this.southNormal,a=this.eastNormal,c=this.northNormal,h=n.vec3.subtract(ei,t,e),u=n.vec3.dot(h,i),l=n.vec3.dot(h,o),f=n.vec3.subtract(ei,t,s),d=n.vec3.dot(f,a),m=n.vec3.dot(f,c);u>0?r+=u*u:d>0&&(r+=d*d),l>0?r+=l*l:m>0&&(r+=m*m)}const s=e[2],i=this.minimumHeight,o=this.maximumHeight;if(s>o){const t=s-o;r+=t*t}else if(s<i){const t=i-s;r+=t*t}return Math.sqrt(r)}computeBox(t){const e=this;Hs(js.southwest(t,Vs),e.southwestCornerCartesian),Hs(js.northeast(t,Vs),e.northeastCornerCartesian),qs[0]=t.west,qs[1]=.5*(t.south+t.north),qs[2]=0;const r=Hs(qs,$s),s=n.vec3.cross(Js,r,zs);n.vec3.normalize(e.westNormal,s),qs[0]=t.east;const i=Hs(qs,Zs),o=n.vec3.cross(Js,zs,i);n.vec3.normalize(e.eastNormal,o);const a=n.vec3.subtract(Js,r,i),c=n.vec3.normalize(Xs,a),h=t.south;let u;if(h>0){qs[0]=.5*(t.west+t.east),qs[1]=h;const r=Hs(qs,Ys);n.vec3.copy(Ws,c);const s=Gs.fromPointNormal(e.southwestCornerCartesian,e.westNormal,ti);ri(Ys,Ws,s,e.southwestCornerCartesian),u=Tn(r,Ks)}else u=_n(js.southeast(t,Vs),Ks);const l=n.vec3.cross(Qs,u,a);n.vec3.normalize(e.southNormal,l);const f=t.north;let d;if(f<0){qs[0]=.5*(t.west+t.east),qs[1]=f;const r=Hs(qs,Ys);n.vec3.scale(Ws,c,-1);const s=Gs.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,ti);ri(Ys,Ws,s,e.northeastCornerCartesian),d=Tn(r,Ks)}else d=_n(js.northwest(t,Vs),Ks);const m=n.vec3.cross(Qs,a,d);n.vec3.normalize(e.northNormal,m)}}function ri(t,e,r,s){const i=t,o=e,a=r.normal,c=n.vec3.dot(a,o);if(Math.abs(c)<1e-15)return;const h=(-r.distance-n.vec3.dot(a,i))/c;return h<0?void 0:(s=n.vec3.scale(s,o,h),n.vec3.add(s,i,s))}const si={"maxGPUMemory":s.Browser.mobile?32:1536,"retireInterval":2e3,"loadingLimitOnInteracting":5,"loadingLimit":10,"renderer":"gl","forceRenderOnZooming":!0,"forceRenderOnRotating":!0,"forceRenderOnMoving":!0,"debug":!1,"meshLimitPerFrame":1,"i3sNodepageLimitPerFrame":1,"enableI3SCompressedGeometry":!0,"forceI3SCompressedGeometry":!0,"picking":!0,"pickingPoint":!0,"geometryEvents":!1,"antialias":!1,"optionalExtensions":["ANGLE_instanced_arrays","OES_element_index_uint","OES_standard_derivatives","OES_vertex_array_object","OES_texture_half_float","OES_texture_half_float_linear","OES_texture_float","OES_texture_float_linear","WEBGL_depth_texture","EXT_shader_texture_lod","WEBGL_compressed_texture_astc","WEBGL_compressed_texture_etc","WEBGL_compressed_texture_etc1","WEBGL_compressed_texture_pvrtc","WEBGL_compressed_texture_s3tc","WEBGL_compressed_texture_s3tc_srgb"],"offset":[0,0]},ii=new s.Extent(0,0,0,0),oi=[],ai=[],ci=[],hi=[],ui=[],li=new s.Coordinate(0,0),fi=new s.Point(0,0),di=[],mi=new s.Coordinate(0,0),pi=n.mat4.identity([]),bi=[0,0],gi=[1,1,1,1,-1,1,-1,-1,1,-1,1,1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1];class yi extends(n.MaskLayerMixin(s.Layer)){static fromJSON(t){return t&&"Geo3DTilesLayer"===t.type?new yi(t.id,t.options):null}constructor(t,e){super(t,e),this.kn(),this.Ze={},this._e=[]}kn(){const t=this.options.services.map(t=>t.url);this.Ln=this.Ln||{},this.vn=this.vn||[];for(let e=0;e<t.length;e++){const n=t[e];let r=this.Ln[n];void 0===r&&(r=this.Ln[n]=this.vn.length),this.vn[r]=Ti(n,r,this.options.services[e])}this.fire("rootready",{roots:this.vn.slice(0)})}showService(t){return this.updateService(t,{visible:1}),this}hideService(t){return this.updateService(t,{visible:0}),this}setToRedraw(){const t=this.getRenderer();t&&t.setToRedraw()}addService(t){this.options.services=this.options.services||[],this.options.services.push(t),this.kn();const e=this.getRenderer();return e&&e.setToRedraw(),this}updateService(t,e){if(!e)return this;const n=this.options.services;if(n&&n[t]&&ot(n[t],e),!it(e.visible)){const r=n[t].url,s=this.Ln[r];this.vn&&this.vn[s]&&(this.vn[s].visible=e.visible)}const r=this.getRenderer();return r&&r.setToRedraw(),this}removeService(t){const e=this.options.services;if(e&&e[t]){const n=e[t].url,r=this.Ln[n];this.vn[r]&&(this.vn[r]=null),delete this.Ln[n],e.splice(t,1)}const n=this.getRenderer();return n&&n.setToRedraw(),this}getTileUrl(t,e,n){const r=n&&n.service&&n.service.subdomains;if(r&&n.domainKey){const e=r.length;if(e){const s=[...t].reduce((t,e)=>t+e.charCodeAt(),0)%e;return t.replace(n.domainKey,r[s])}}return t}getExtent(t){if(!t&&0!==t){const t=new s.Extent;for(let e=0;e<this.vn.length;e++)if(this.vn[e].boundingVolume){const n=this.boundingVolumeToExtent(this.vn[e]);t._combine(n)}return t}return this.vn[t]&&this.vn[t].boundingVolume?this.boundingVolumeToExtent(this.vn[t]):null}boundingVolumeToExtent(t){const e=t.boundingVolume.Bn?pi:t.matrix,r=this.getMap(),i="identity"===r.getProjection().code.toLowerCase(),o=this.getRenderer();if(t.boundingVolume.region){const e=t.boundingVolume.region;return new s.Extent(lt(e[0]),lt(e[1]),lt(e[2]),lt(e[3]))}if(t.boundingVolume.sphere){const a=t.boundingVolume.sphere,c=bn([],n.vec3.transformMat4([],a,e));i&&o.Cn(c,c);const h=a[3],u=r.locate(c,-h,h),l=r.locate(c,h,-h);return new s.Extent(u,l)}if(t.boundingVolume.box){const a=t.boundingVolume.box,c=n.vec3.transformMat4([],a,e),h=new s.Coordinate(bn([],c));i&&o.Cn(h,h);const u=a.slice(3);n.mat3.multiply(u,n.mat3.fromMat4([],t.matrix),u);const l=n.vec3.length(u.slice(0,3)),f=n.vec3.length(u.slice(3,6)),d=n.vec3.length(u.slice(6,9)),m=Math.max(l,f,d),p=r.locate(h,-m,m),b=r.locate(h,m,-m);return new s.Extent(p,b)}return null}getRootTiles(){return this.vn}getTiles(){const t=this.getRenderer();if(!t.ready)return this.Un(),{tiles:ui};const e=this.getMap(),r=e.cameraPosition,s=e.pointAtResToDistance(r[2],0,e.getGLRes()),i=this.Fn(r);this.Dn=this.Dn||[],n.vec3.set(this.Dn,ut(i.x),ut(i.y),s),this.jn=un(this.jn||[],this.Dn[0],this.Dn[1],this.Dn[2]),this.zn=2*Math.tan(.5*ut(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const h=[];for(let e=0;e<this.vn.length;e++){const n=this.vn[e];if(!n||!n.visible)continue;let r=1/0;const s=[n],i=this.Hn(e);for(;s.length>0;){const e=s.pop();for(e.id||this.Gn(e);c.level>=e.zt;)c=c.parent;const n=this.qn(e,i,o);if(n<1){let t=c;for(;t&&!t.content;)t=t.parent;0===n&&t&&t.content&&this.Vn(h,t);if(!1===this.options.services[e.Rt].alwaysShow)continue;if(!(0===n&&e.zt<=r))continue;e.content&&(r=e.zt)}e.ne<1/0&&this.$n(e);const a=this.gn(e,c);c.children.push(a);const u=e.children,l=u&&u.length,f=a.content;if(!l&&f&&this.Vn(h,a),l){f&&"add"===e.refine&&this.Vn(h,a),c=a;const n=u[0].parent;let r=!1;for(let i=0,o=u.length;i<o;i++){if(n){const e=t.getCachedTile(u[i].id);if(e&&e.error&&404!==e.error.status)continue;r=!0}else{r=!0,u[i].parent=e,u[i].de=e.de,u[i].baseUrl=e.baseUrl;const t=u[i].content&&(u[i].content.url||u[i].content.uri);t&&(wt(t)||t.indexOf("i3s:")>=0?u[i].baseUrl=e.baseUrl:xt(t)?u[i].content.url=e.baseUrl+t:u[i].baseUrl=t.substring(0,t.lastIndexOf("/")+1))}s.push(u[i])}!r&&f&&this.Vn(h,a)}}}return{root:a,tiles:h}}Vn(t,e){const{viewerRequestVolume:n}=e.node;n&&!function(t,e,n){if(n.region){const e=n.region;if(t[0]>=e[0]&&t[0]<=e[2]&&t[1]>=e[1]&&t[1]<=e[3])return!0}else{if(n.sphere)return wi(n,e);if(n.box)return 0===vi(n,e)}return!1}(this.Dn,this.jn,n)||t.push(e)}gn(t,e){return{id:t.id,node:t,children:[],level:t.zt,parent:e,content:t.content&&t.content.url}}Gn(t){const e=this.getId();t.id=e+":"+s.Util.GUID(),t.matrix=t.transform||n.mat4.identity([]),t.Xn=this.Jn(t),t.parent&&(function(t){return t.content&&t.content.uri&&t.content.uri.indexOf("i3s:")>=0}(t)||(t.matrix=n.mat4.multiply(t.matrix,t.parent.matrix,t.matrix)),t.Rt=t.parent.Rt,void 0===t.zt&&(t.zt=t.parent.zt+1),t.maxExtent=t.parent.maxExtent),t.refine=t.refine&&t.refine.toLowerCase()||"replace",t.content&&!t.content.url&&t.content.uri&&(t.content.url=t.content.uri)}Pt(t){return this.vn[t].service}Kn(t){const e=t.boundingVolume;if(!e||e.Bn&&!this.Qn(t))return;const r=this.Pt(t.Rt),s=r.heightOffset||0,i=this.options.offset,o=at(i)||i[0]||i[1],a=r.coordOffset||bi;if(!Array.isArray(a))throw new Error("service.coordOffset must be an array");if(!e.Bn&&(!t.boundingVolume||!s&&n.mat4.exactEquals(t.matrix,pi)&&!o&&a===bi))return;e.box&&e.region&&delete e.region;const{region:c,box:h,sphere:u}=e;if(e.coordOffset=[a[0],a[1]],e.heightOffset=s,c){e.originalVolume||(e.originalVolume=c.slice(0));const t=e.originalVolume,n=this.Zn([lt(t[0]),lt(t[1])]);c[0]=ut(n.x+a[0]),c[1]=ut(n.y+a[1]);const r=this.Zn([lt(t[2]),lt(t[3])]);c[2]=ut(r.x+a[0]),c[3]=ut(r.y+a[1]),c[4]=t[4]+s+(a[2]||0),c[5]=t[5]+s+(a[2]||0)}else if(h||u){e.originalVolume||(e.originalVolume=(h||u).slice(0));const r=h||u,i=e.originalVolume,o=n.vec3.transformMat4(oi,i,t.matrix),c=bn(ai,o),l=this.Zn([c[0]+a[0],c[1]+a[1]]);c[0]=l.x,c[1]=l.y,c[2]+=s+(a[2]||0),un(r,ut(c[0]),ut(c[1]),c[2])}e.Bn=!0}Qn(t){const e=t.boundingVolume,n=this.Pt(t.Rt),r=n.heightOffset||0,s=n.coordOffset||bi;return e.coordOffset[0]!==s[0]||e.coordOffset[1]!==s[1]||e.heightOffset!==r}Jn(t){return void 0===t.geometricError||!t.boundingVolume}$n(t){let e=t.parent;for(;e&&e.Xn&&!(e.ne<=t.ne);)e.ne=t.ne,e=t.parent}onTileLoad(t,e){if(t.children&&(!e.children||!e.children.length)){e.children=t.children;const n=e.content.url;e.baseUrl=n.substring(0,n.lastIndexOf("/")+1);const r=this.getRenderer();r&&r.setToRedraw()}}onTilesetLoad(t,e,r){if(!t)return void console.warn("invalid tileset at : "+r);const s=this.Pt(e.Rt),i=(t.asset&&t.asset.gltfUpAxis||e&&e.de||s.upAxis||"Y").toUpperCase();t.root.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const o=r.indexOf("realspace/")>-1;0===e.zt&&(t.asset&&t.asset.s3mType&&o||s.isSuperMapiServer)&&(t.root.baseUrl+="data/path/");const a=t.asset.i3s,c=!!t.asset.s3mType;if(t.root.de=i,e){const r=e.Rt,s=this.vn[r];c&&!s.isS3M&&(s.isS3M=c);const i=e.boundingVolume;ot(e,t.root),e.refine=e.refine&&e.refine.toLowerCase()||"replace",i&&(e.boundingVolume=i);const o=t.root.transform;o&&(e.parent?a||(e.matrix=n.mat4.multiply([],e.parent.matrix,o)):e.matrix=o),e.Yn=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.Xn=this.Jn(e);const h=e.content&&(e.content.url||e.content.uri);h&&e.content.uri&&(e.content.url=e.content.uri,delete e.content.uri),!a&&h&&!wt(h)&&xt(h)&&(e.content.url=e.baseUrl+h),t.root&&!e.parent&&this.Wn(e)}this.Un(),this.fire("loadtileset",{tileset:t,index:e&&e.Rt,url:r})}qn(t,e,n){if(t.ne=1/0,0===t.zt||t.Xn)return this.Wn(t),1;if(this.Kn(t),!this.tr(t,e,n))return-1;if(0===t.geometricError)return 1;let r=this.Pt(t.Rt).maximumScreenSpaceError;null==r&&(r=16);let s=this.er(t);return 0===s&&t.parent&&(s=.5*(t.parent.ln||0)),s>=r?1:0}Re(t,e){e||(e=new s.Point(0,0));const n=this.getMap();return n.getGLZoom?n.coordToPoint(t,n.getGLZoom(),e):n.coordToPointAtRes(t,n.getGLRes(),e)}tr(t,e,n){const r=t.id;let i=this._e[r]&&this._e[r].obbox;const{boundingVolume:o}=t,c=o.region,h=o.box,d=o.sphere;if(!i)if(c)this._e[r]=this.nr(t),i=this._e[r].bbox,i.center=this._e[r].coordCenter;else if(h)this._e[r]=this.rr(t),i=this._e[r].obbox,i.center=this._e[r].coordCenter;else if(d){i=this._e[r]=this.sr(t);const e=bn(oi,d),n=new s.Coordinate(e);i.center=n}if(e){if(c)ii.xmin=i[0][0],ii.ymin=i[0][1],ii.xmax=i[1][0],ii.ymax=i[1][1];else if(d){const t=i[2];ii.xmin=i[0][0]-t,ii.ymin=i[0][1]-t,ii.xmax=i[0][0]+t,ii.ymax=i[0][1]+t}else if(h){const t=i[1],e=i[2];ii.xmin=i[0][0]-t,ii.ymin=i[0][1]-e,ii.xmax=i[0][0]+t,ii.ymax=i[0][1]+e}if(!e.intersects(ii))return!1}return c?u(n,i):d?function(t,e,n){f(t);for(var r=e[0],s=-e[1],i=0;i<6;i++){if(!n||"0"!==n.charAt(i))if(m(a[i],r)<s)return!1}return!0}(n,i):!!h&&function(t,e,n){f(t);for(var r=0;r<6;r++){if(!n||"0"!==n.charAt(r))if(!l(a[r],e))return!1}return!0}(n,i)}nr(t){const e=this.getMap(),n=e.getGLRes(),r=t.boundingVolume.region;let{ws:i,en:o}=function(t){const e=t[0],n=t[1],r=t[2],s=t[3],i=t[4],o=t[5],a=un([],e,n,i),c=un([],r,s,o),h=bn(a,a),u=bn(c,c);return{ws:h,en:u}}(r);i=new s.Coordinate(i),o=new s.Coordinate(o);const a=e.coordToPointAtRes(i,n);a.z=e.altitudeToPoint(i.z,n);const c=e.coordToPointAtRes(o,n);c.z=e.altitudeToPoint(o.z,n);const h=[c.x,a.y,c.z,c.x,c.y,c.z,a.x,c.y,c.z,a.x,a.y,c.z,c.x,a.y,a.z,c.x,c.y,a.z,a.x,c.y,a.z,a.x,a.y,a.z],u=[(h[0]+h[18])/2,(h[1]+h[19])/2,(h[2]+h[20])/2],l=e.pointAtResToCoord(new s.Point(u),n);l.z=(i.z+o.z)/2;const f=this.Yt(t.Rt).Me,d=[h.slice(21,24),h.slice(3,6)];if(f)for(let t=0;t<h.length;t+=3)h[t]-=f[0],h[t+1]-=f[1],h[t+2]-=f[2];return{bbox:d,boxPosition:h,pointCenter:u,coordCenter:l}}rr(t){const e=this.getRenderer(),r=this.getMap(),s="identity"===r.getProjection().code.toLowerCase(),i=r.getGLRes(),o=t.boundingVolume.box,a=o.slice(0,3),c=this.ir(o,t.matrix),h=(l=a,new _i((u=c)[0],u[3],u[6],l[0],u[1],u[4],u[7],l[1],u[2],u[5],u[8],l[2],0,0,0,1));var u,l;const f=this.or(t),d=[],m=this.Yt(t.Rt).Me;fi.set(m[0],m[1]);const p=r.pointAtResToCoord(fi,i),b=oi;for(let t=0;t<gi.length;t+=3){b[0]=gi[t],b[1]=gi[t+1],b[2]=gi[t+2],n.vec3.transformMat4(b,b,h),bn(b,b),s&&e.Cn(b,b);const o=li.set(...b);let a=r.coordToPointAtRes(o,i,fi);a=n.vec3.set(b,a.x,a.y,r.altitudeToPoint(o.z,i)),d[t]=a[0]-m[0],d[t+1]=a[1]-m[1],d[t+2]=a[2]-m[2]}return{obbox:this.ar(d,m,f),boxPosition:d,boxCenter:f,coordCenter:p}}sr(t){const e=this.getMap(),n=this.getRenderer(),r="identity"===e.getProjection().code.toLowerCase(),i=t.boundingVolume.sphere,o=i;let a=oi;0===o[0]&&0===o[1]&&0===o[2]?a=[0,0,-6378137]:bn(a,o),r&&n.Cn(a,a);const c=new s.Coordinate(a),h=this.Re(c,fi).toArray();h[2]=e.altitudeToPoint(c.z,e.getGLRes());const u=this.cr(c);return[h,i[3]*u[2]]}ar(t,e,r){const[s,i,o]=e,a=n.vec3.set(oi,(t[3]+t[12])/2+s,(t[4]+t[13])/2+i,(t[5]+t[14])/2+o),c=n.vec3.set(ai,(t[3]+t[18])/2+s,(t[4]+t[19])/2+i,(t[5]+t[20])/2+o),h=n.vec3.set(ci,(t[3]+t[9])/2+s,(t[4]+t[10])/2+i,(t[5]+t[11])/2+o),u=r.slice(0);return u[3]=a[0]-r[0],u[4]=a[1]-r[1],u[5]=a[2]-r[2],u[6]=c[0]-r[0],u[7]=c[1]-r[1],u[8]=c[2]-r[2],u[9]=h[0]-r[0],u[10]=h[1]-r[1],u[11]=h[2]-r[2],u}or(t){const e=this.getMap(),n=this.getRenderer(),r="identity"===e.getProjection().code.toLowerCase(),i=e.getGLRes(),o=t.boundingVolume.box.slice(0,3);bn(o,o),r&&n.Cn(o,o);const a=new s.Coordinate(o),c=e.coordToPointAtRes(a,i);return[c.x,c.y,e.altitudeToPoint(a.z,i)]}Wn(t){const e=this.Pt(t.Rt);if(!t.boundingVolume||this.hr(t,e))return;const n=t.boundingVolume.box,r=t.boundingVolume.region,s=t.boundingVolume.sphere;let i=null;if(n){i=this.ur(t).pointCenter}else if(r){i=this.lr(t).pointCenter}else s&&(i=this.sr(t)[0]);const o=e.heightOffset||0,a=e.coordOffset||[0,0];t.dr=[a[0]||0,a[1]||0],t.te=o,t.Me=i}hr(t,e){if(!t.dr)return!1;const n=e.coordOffset||bi;return t.dr[0]===n[0]&&t.dr[1]===n[1]&&t.te===(e.heightOffset||0)}lr(t){if(!t.boundingVolume)return null;this.Kn(t);return this.nr(t)}ur(t){if(!t.boundingVolume)return null;this.Kn(t);const e=t.boundingVolume.box.slice(0,3);bn(e,e);const n=new s.Coordinate(e);return{pointCenter:this.or(t),coordCenter:n}}ir(t,e){let n=t.slice(3,12);return n=function(t,e,n){const r=t[0]*e[0]+t[3]*e[1]+t[6]*e[2],s=t[1]*e[0]+t[4]*e[1]+t[7]*e[2],i=t[2]*e[0]+t[5]*e[1]+t[8]*e[2],o=t[0]*e[3]+t[3]*e[4]+t[6]*e[5],a=t[1]*e[3]+t[4]*e[4]+t[7]*e[5],c=t[2]*e[3]+t[5]*e[4]+t[8]*e[5],h=t[0]*e[6]+t[3]*e[7]+t[6]*e[8],u=t[1]*e[6]+t[4]*e[7]+t[7]*e[8],l=t[2]*e[6]+t[5]*e[7]+t[8]*e[8];return n[0]=r,n[1]=s,n[2]=i,n[3]=o,n[4]=a,n[5]=c,n[6]=h,n[7]=u,n[8]=l,n}(this.mr(e,[]),n,n),n}mr(t,e){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[4],e[4]=t[5],e[5]=t[6],e[6]=t[8],e[7]=t[9],e[8]=t[10],e}cr(t){const e=this.getMap(),r=e.distanceToPointAtRes(100,100,e.getGLRes(),t);let s;return s=e.altitudeToPoint?e.altitudeToPoint(100,e.getGLRes())/100:r.y/100,n.vec3.set(hi,r.x/100*1.01,r.y/100*1.01,s),hi}Zn(t){Array.isArray(t)&&(t=new s.Coordinate(t));let e=this.options.offset;if(at(e)&&(e=e.call(this,Array.isArray(t)?new s.Coordinate(t):t)),e[0]||e[1]){const n=this.getMap(),r=n.getGLRes(),s=n.coordToPointAtRes(t,r);return s._sub(e),n.pointAtResToCoord(s,r)}return t}Yt(t){return this.vn[t]}Hn(t){const e=this.Pt(t).maxExtent;if(!e)return null;const n=this.vn[t];return n.maxExtent||(n.maxExtent=new s.Extent(e).convertTo(t=>this.Re(t))),n.maxExtent}er(t){const e=this.zn,n=t.geometricError;if(0===n)return t.ln=0,0;const r=this.getMap();let s;t.boundingVolume.region?s=function(t,e,n){t.pr||(t.pr=new ni(t.boundingVolume.region));return t.pr.distanceToCamera(e,n)}(t,this.jn,this.Dn):t.boundingVolume.sphere?s=wi(t.boundingVolume,this.jn):t.boundingVolume.box&&(s=vi(t.boundingVolume,this.jn));const i=Math.max(Math.abs(s),1e-7),o=n*r.height/(i*e);return t.ne=s,t.ln=o,o}Un(){const t=this.getRenderer();t&&t.setToRedraw()}Oe(t){return this._e[t]}identify(t,e={}){const n=this.getMap(),r=this.getRenderer();if(!n||!r)return[];const i=n.coordToContainerPoint(new s.Coordinate(t));return this.identifyAtPoint(i,e)}identifyAtPoint(t,e={}){const n=[];if(!e.excludeMasks){const r=this.identifyMask(t,e);r&&r.length&&Tt(n,r)}const r=this.getMap(),s=this.getRenderer();if(!r||!s)return[];const i=r.getDevicePixelRatio();return Tt(n,s.pick(t.x*i,t.y*i,e)),n}getCurrentBatchIDs(){const t=this.getMap(),e=this.getRenderer();return t&&e?e.Le():[]}highlight(t){const e=this.getRenderer();return e?(e.highlight(t),this):(this.Ut||(this.Ut=[]),this.Ut.push(t),this)}In(){if(this.Ut){for(let t=0;t<this.Ut.length;t++)this.highlight(this.Ut[t]);delete this.Ut}}cancelHighlight(t,e){const n=this.getRenderer();return n?(n.cancelHighlight(t,e),this):this}cancelAllHighlight(){const t=this.getRenderer();return t?(t.cancelAllHighlight(),this):this}showOnly(t){const e=this.getRenderer();return e?(e.showOnly(t),this):(this.Dt||(this.Dt=[]),this.Dt.push(t),this)}br(){if(this.Dt){for(let t=0;t<this.Dt.length;t++)this.showOnly(this.Dt[t]);delete this.Dt}}cancelShowOnly(t){const e=this.getRenderer();return e?(e.cancelShowOnly(t),this):this}setServiceOpacity(t,e){const n=this.options.services[t];n&&(n.opacity=e);const r=this.getRenderer();return r?(r.setToRedraw(),this):this}setServiceDebugBoundingVolume(t,e){const n=this.options.services[t];n&&(n.debugShowBoundingVolume=e);const r=this.getRenderer();return r?(r.setToRedraw(),this):this}Fn(t){const e=this.getMap(),n=e.getGLRes();mi.set(t[0],t[1]);const r=e.pointAtResToCoord(mi,n);return"identity"===e.getProjection().code.toLowerCase()?(ai[0]=r.x,ai[1]=r.y,this.getRenderer().Pn(oi,ai),r.set(oi[0],oi[1]),r):r}toJSON(){return{"type":this.getJSONType(),"id":this.getId(),"options":this.config()}}}function wi(t,e){const r=t.sphere,s=n.vec3.dist(r,e),i=t.sphere[3];return s<i?0:s-i}function vi(t,e){const r=t.box;return Rs(n.vec3.set(oi,r[0],r[1],r[2]),n.mat3.set(di,r[3],r[4],r[5],r[6],r[7],r[8],r[9],r[10],r[11]),e)}function Ti(t,e,r){const s=(t=ft(t)).indexOf("{s}")>=0?"{s}":t.indexOf("%7Bs%7D")>=0?"%7Bs%7D":null;return{service:r,visible:it(r.visible)?1:r.visible,baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:n.mat4.identity([]),Rt:e,zt:0,domainKey:s}}function _i(t,e,n,r,s,i,o,a,c,h,u,l,f,d,m,p){this[0]=t||0,this[1]=s||0,this[2]=c||0,this[3]=f||0,this[4]=e||0,this[5]=i||0,this[6]=h||0,this[7]=d||0,this[8]=n||0,this[9]=o||0,this[10]=u||0,this[11]=m||0,this[12]=r||0,this[13]=a||0,this[14]=l||0,this[15]=p||0}yi.mergeOptions(si),yi.registerRenderer("gl",Ns),yi.registerJSONType("Geo3DTilesLayer");let Mi=null;function Oi(){return Mi||(Mi={"image/crn":fs.crn&&fs.crn(),"image/ktx2":fs.ktx2&&fs.ktx2(),"image/cttf":fs.ktx2&&fs.ktx2(),"draco":fs.draco&&fs.draco()}),Mi}class xi{constructor(t,e,n){this.i=t,this.gr=e||Ue,this.o=n,this.yr=Oi()}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.wr(t,e,n,r,s)):ye.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.wr(t,s,n,r)})}wr(t,e,n,r,s){const i=s&&s.maxTextureSize,o=this.vr(e,n,r,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.gr(a,o.glb,{transferable:!0,requestImage:this.i,decoders:this.yr,supportedFormats:this.o,maxTextureSize:i});return c.load({skipAttributeTransform:!1}).then(e=>{e.url=`${t}-${n}-${r}`;const s=c.transferables;for(let t=0;t<o.transferables.length;t++)s.indexOf(o.transferables[t])<0&&s.push(o.transferables[t]);return{magic:"b3dm",count:o.count,transferables:s,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,gltf:e}})}vr(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported b3dm version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in b3dm header is inconsistent with b3dm's byte length, url: "+r;return console.warn(t),{error:t}}let o,a=s.getUint32(12,!0),c=s.getUint32(16,!0),h=s.getUint32(20,!0),u=s.getUint32(24,!0),l=28+e;h>=570425344?(l-=8,o=a,h=c,u=0,a=0,c=0):u>=570425344&&(l-=4,o=h,h=a,u=c,a=0,c=0);const f=[t];let d,m,p;if(a>0?(d=In(t,l,a),l+=a,o=d.BATCH_LENGTH):d={"BATCH_LENGTH":o},c>0&&(l+=c),h>0&&(m=Sn(t,l,h),l+=h,u>0)){const e=En(0,l,u);p=t.slice(e.offset,e.offset+e.byteLength),l+=u,f.push(p)}const b=d.BATCH_LENGTH,g={};if(d&&d.BATCH_ID){g.BATCH_ID=Cn(d.BATCH_ID,t,(void 0).offset,b);const e=g.BATCH_ID.array&&g.BATCH_ID.array.buffer;e&&f.indexOf(e)<0&&f.push(e)}return{count:o,transferables:f,featureTable:d,batchTable:m,batchTableBin:p,b3dm:g,glb:{buffer:t,byteOffset:l,byteLength:s.byteLength+s.byteOffset-l}}}Tr(){return null}}class Ai{constructor(t,e,n,r){this.i=t,this.gr=e||Ue,this.o=n,this.yr=Oi(),this._r=r}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.wr(t,e,n,r,s)):ye.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.wr(t,s,n,r)})}wr(t,e,n,r,s){return this.Mr(t,e,n,r,s).then(({gltf:s,transferables:i})=>{const o=this.Or(e,n,r,t);if(o.error)return Promise.resolve(o);for(let t=0;t<i.length;t++)-1===o.transferables.indexOf(i[t])&&o.transferables.push(i[t]);return delete s.transferables,Promise.resolve({magic:"i3dm",count:o.count,transferables:o.transferables,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,i3dm:o.i3dm,gltf:s})})}Mr(t,e,n,r,s){const i=s&&s.maxTextureSize,o={transferable:!0,requestImage:this.i,decoders:this.yr,supportedFormats:this.o,maxTextureSize:i},a=new DataView(e,n,r),c=32+a.getUint32(12,!0)+a.getUint32(16,!0)+a.getUint32(20,!0)+a.getUint32(24,!0);if(0===a.getUint32(28,!0)){let r=pt(new Uint8Array(e,c+n,a.byteLength-c));-1==r.indexOf("://")&&(r=t.substring(0,t.lastIndexOf("/"))+"/"+r);return r.indexOf(".glb")>0?ye.getArrayBuffer(r,{}).then(t=>this.xr(r,{buffer:t.data,byteOffset:0},o)):ye.getJSON(r,{}).then(t=>this.xr(r,t,o))}{const r={buffer:e,byteOffset:c+n,byteLength:a.byteLength-c};return this.xr(t,r,o)}}xr(t,e,n){const r=t.substring(0,t.lastIndexOf("/")),s=new this.gr(r,e,n);return s.load({skipAttributeTransform:!0}).then(n=>{let r=0,i=0;return e.buffer&&(r=e.byteOffset||0,i=e.byteLength||0),n.url=`${t}-${r}-${i}`,{transferables:s.transferables,gltf:n}})}Or(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported pnts version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+r;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:h,batchTableBin:u}=Dn(s,32+e,o),l={},f=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;l.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,n=a.QUANTIZED_VOLUME_SCALE,{byteOffset:r}=a.POSITION_QUANTIZED;l.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.Ar(new Uint16Array(t,r+c.offset,3*f),e,n)},o.push(l.POSITION.array.buffer)}if(a.BATCH_ID){l.BATCH_ID=Cn(a.BATCH_ID,t,c.offset,f);const e=l.BATCH_ID.array&&l.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;l.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,l.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;l.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.Ir(new Uint16Array(t,e+c.offset,2*f))},o.push(l.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,l.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.Ir(new Uint16Array(t,e+c.offset,2*f))},o.push(l.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;l.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,f).slice()},o.push(l.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;l.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.SCALE_NON_UNIFORM.array.buffer)}return{count:f,batchTable:h,batchTableBin:u,featureTable:a,i3dm:l,transferables:o}}Ir(t){const e=t.length/2,n=new Float32Array(3*e),r=[];for(let s=0;s<e;s++)Ii(r,t[2*s],t[2*s+1],65535),n[3*s]=r[0],n[3*s+1]=r[1],n[3*s+2]=r[2];return n}Ar(t,e,n){return Fn(new Float32Array(t.length),t,e,n)}Tr(){return null}}function Ii(t,e,n,r){if(t[0]=Si(e,r),t[1]=Si(n,r),t[2]=1-(Math.abs(t[0])+Math.abs(t[1])),t[2]<0){const e=t[0];t[0]=(1-Math.abs(t[1]))*Ei(e),t[1]=(1-Math.abs(e))*Ei(t[1])}return Ht(t,t)}function Si(t,e){return function(t,e,n){return t<e?e:t>n?n:t}(t,0,e=function(t,e){if(null!=t)return t;return e}(e,255))/e*2-1}function Ei(t){return t<0?-1:1}class Ni{constructor(){}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.wr(t,e,n,r)):ye.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.wr(t,s,n,r)})}wr(t,e,n,r){return this.Sr(e,n,r,t).then(t=>t.error?t:{magic:"pnts",count:t.count,transferables:t.transferables,featureTable:t.featureTable,batchTable:t.batchTable,batchTableBin:t.batchTableBin,pnts:t.pnts})}Sr(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported pnts version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+r;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:h,batchTableBin:u}=Dn(s,e+28,o),l=a.QUANTIZED_VOLUME_OFFSET,f=a.QUANTIZED_VOLUME_SCALE,d=a.POINTS_LENGTH;let m,p={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){p=a.extensions["3DTILES_draco_point_compression"],m=new DataView(t,p.byteOffset+c.offset,p.byteLength);const e={attributes:p.properties,useUniqueIDs:!1};return this.Er||(this.Er=Oi().draco),this.Er(m,e).then(e=>{const n=e.attributes;!a.POSITION&&!a.POSITION_QUANTIZED||n.POSITION||n.POSITION_QUANTIZED||(n.POSITION=a.POSITION,n.POSITION_QUANTIZED=a.POSITION_QUANTIZED),!(a.RGB||a.RGBA||a.RGB565)||n.RGB||n.RGBA||n.RGB565||(n.RGB=a.RGB,n.RGBA=a.RGBA,n.RGB565=a.RGB565),!a.NORMAL&&!a.NORMAL_OCT16P||n.NORMAL||n.NORMAL_OCT16P||(n.NORMAL=a.NORMAL,n.NORMAL_OCT16P=a.NORMAL_OCT16P);const r=this.Nr(t,e.attributes,c.offset,d,o,l,f);if(e.attributes.BATCH_ID){const t=e.attributes.BATCH_ID.array;r.BATCH_ID={byteStride:0,byteOffset:0,itemSize:1,count:t.length,componentType:Un(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?r.BATCH_ID=Cn(a.BATCH_ID,t,c.offset,d):r.BATCH_ID=Ci(d);const e=r.BATCH_ID.array&&r.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return{count:d,batchTable:h,batchTableBin:u,featureTable:a,pnts:r,transferables:o}})}const b=this.Nr(t,a,c.offset,d,o,l,f);if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?b.BATCH_ID=Cn(a.BATCH_ID,t,c.offset,d):b.BATCH_ID=Ci(d);const e=b.BATCH_ID.array&&b.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:d,batchTable:h,batchTableBin:u,featureTable:a,pnts:b,transferables:o})}Nr(t,e,n,r,s,i,o){const a={};if(e.POSITION){let{byteOffset:i,array:o}=e.POSITION;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r*4);o=new Float32Array(e)}a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:o},s.push(o.buffer)}else if(e.POSITION_QUANTIZED){let{byteOffset:c}=e.POSITION_QUANTIZED;const{array:h}=e.POSITION_QUANTIZED;c=c||0;const u=h?0:n;a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:this.Ar(h||new Uint16Array(t,c+u,3*r),i,o)},s.push(a.POSITION.array.buffer)}if(e.RGBA){let{byteOffset:i,array:o}=e.RGBA;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+4*r);o=new Uint8Array(e)}a.RGBA={byteStride:0,byteOffset:0,itemSize:4,count:r,componentType:5121,array:o},s.push(o.buffer)}else if(e.RGB){let{byteOffset:i,array:o}=e.RGB;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r);o=new Uint8Array(e)}a.RGB={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5121,array:o},s.push(o.buffer)}else if(e.RGB565){let{byteOffset:i,array:o}=e.RGB565;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+2*r);o=new Uint16Array(e)}a.RGB565={byteStride:0,byteOffset:0,itemSize:1,count:r,componentType:5123,array:o},s.push(o.buffer)}if(e.NORMAL){let{byteOffset:i,array:o}=e.NORMAL;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r*4);o=new Float32Array(e)}a.NORMAL={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:o},s.push(o.buffer)}else if(e.NORMAL_OCT16P){let{byteOffset:i,array:o}=e.NORMAL_OCT16P;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+2*r);o=new Uint8Array(e)}a.NORMAL_OCT16P={byteStride:0,byteOffset:0,itemSize:2,count:r,componentType:5121,array:o},s.push(o.buffer)}return a}Ar(t,e,n){return Fn(new Float32Array(t.length),t,e,n)}Tr(){return null}}function Ci(t){const e=yt(t),n=new e(t);for(let e=0;e<t;e++)n[e]=e;return{byteStride:0,byteOffset:0,itemSize:1,count:t,componentType:Un(e),array:n}}class Pi{constructor(t,e,n,r){this.o=n,this.i=t,this.gr=e||Ue,this._r=r}load(t,e,n=0,r=0,s){return e?this.wr(t,e,n,r,s):ye.getArrayBuffer(t,{}).then(e=>{const s=e.data;return this.wr(t,s,n,r)})}wr(t,e,n,r,s){r||(r=e.byteLength);const i=this.Cr(e,t,n,r),o=[];for(let n=0;n<i.length;n++){let r;if("b3dm"===i[n].magic)r=new xi(this.i,this.gr,this.o);else if("i3dm"===i[n].magic)r=new Ai(this.i,this.gr,this.o,this._r);else if("pnts"===i[n].magic)r=new Ni;else{if("cmpt"!==i[n].magic){console.warn("Unsupported magic in CMPT tile:",i[n].magic);continue}r=new Pi(this.i,this.gr,this.o,this._r)}o.push(r.load(t,e,i[n].offset,i[n].byteLength,s).then(t=>t))}return Promise.all(o).then(t=>({magic:"cmpt",tiles:t}))}Cr(t,e,n,r){const s=new DataView(t,n,r),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported cmpt version: "+i+", url:"+e;return console.warn(t),{error:t}}if(16===s.byteLength)return[];const o=[],a=s.getUint32(12,!0);let c=16;for(let e=0;e<a;e++){const e=xn(s,c),r=s.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+n,byteLength:r}),c+=r}return o}}if(i.transcoders){const t=s.Map.VERSION;if(t.indexOf("1.0.0-beta")>=0||t.indexOf("1.0.0-alpha")>=0){const t=i.transcoders.inject(o);s.registerWorkerAdapter("@maptalks/3dtiles",t)}else s.registerWorkerAdapter("@maptalks/3dtiles",(function(){return i.transcoders.inject(o)}))}else s.registerWorkerAdapter("@maptalks/3dtiles",o);t.B3DMLoader=xi,t.CMPTLoader=Pi,t.Geo3DTilesLayer=yi,t.Geo3DTilesUtil=Ot,t.Geo3DTransform=Mn,Object.defineProperty(t,"t",{value:!0}),"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.95.8")}));
package/package.json CHANGED
@@ -1,66 +1,66 @@
1
- {
2
- "name": "@maptalks/3dtiles",
3
- "version": "0.95.7",
4
- "description": "3d tiles layer for maptalks",
5
- "main": "dist/maptalks.3dtiles.js",
6
- "module": "dist/maptalks.3dtiles.es.js",
7
- "scripts": {
8
- "lint": "eslint src/**/*.js test/**/*.js",
9
- "build": "npm run lint && rollup --environment BUILD:production -c rollup.config.js",
10
- "build-dev": "rollup -c rollup.config.js",
11
- "dev": "rollup -w -c rollup.config.js",
12
- "test": "electron-mocha -t 5000 --require-main ./test/ignore-gpu-blacklist.js --renderer ./test/**/*.spec.js",
13
- "tdd": "electron-mocha --interactive --renderer ./test/**/*.spec.js",
14
- "pretest": "npm run build",
15
- "prepare": "npm run build",
16
- "preversion": "npm test"
17
- },
18
- "repository": {
19
- "type": "git",
20
- "url": "git+https://github.com/maptalks/maptalks.3dtiles.git"
21
- },
22
- "keywords": [
23
- "maptalks",
24
- "3dtiles",
25
- "3d",
26
- "maps"
27
- ],
28
- "files": [
29
- "dist/maptalks.3dtiles.js",
30
- "dist/maptalks.3dtiles.es.js"
31
- ],
32
- "author": "fuzhenn",
33
- "license": "UNLICENSED",
34
- "bugs": {
35
- "url": "https://github.com/fuzhenn/3dtiles-issues/"
36
- },
37
- "homepage": "https://github.com/fuzhenn/3dtiles-issues/",
38
- "dependencies": {
39
- "@maptalks/function-type": "^1.3.1",
40
- "@maptalks/gltf-loader": "^0.95.2",
41
- "@maptalks/tbn-packer": "^1.4.5",
42
- "frustum-intersects": "^0.2.2",
43
- "gl-matrix": "^2.6.1",
44
- "pako": "^2.0.4",
45
- "parse-dds": "^1.2.1"
46
- },
47
- "devDependencies": {
48
- "@maptalks/gl": "^0.95.6",
49
- "@maptalks/transcoders.crn": "^0.95.6",
50
- "@maptalks/transcoders.draco": "^0.95.6",
51
- "@maptalks/transcoders.ktx2": "^0.95.6",
52
- "@rollup/plugin-commonjs": "^20.0.0",
53
- "@rollup/plugin-node-resolve": "^13.0.4",
54
- "@rollup/plugin-replace": "4.0.0",
55
- "electron": "^4.2.12",
56
- "electron-mocha": "^11.0.1",
57
- "eslint": "^8.46.0",
58
- "eslint-plugin-mocha": "^10.1.0",
59
- "express": "^4.17.1",
60
- "maptalks": "^1.0.0-rc.28",
61
- "pixelmatch": "^4.0.2",
62
- "rollup": "^2.56.2",
63
- "rollup-plugin-terser": "^5.3.1"
64
- },
65
- "gitHead": "9eeea4807723d460fa7e09969c6556d53f6bed84"
66
- }
1
+ {
2
+ "name": "@maptalks/3dtiles",
3
+ "version": "0.95.8",
4
+ "description": "3d tiles layer for maptalks",
5
+ "main": "dist/maptalks.3dtiles.js",
6
+ "module": "dist/maptalks.3dtiles.es.js",
7
+ "scripts": {
8
+ "lint": "eslint src/**/*.js test/**/*.js",
9
+ "build": "npm run lint && rollup --environment BUILD:production -c rollup.config.js",
10
+ "build-dev": "rollup -c rollup.config.js",
11
+ "dev": "rollup -w -c rollup.config.js",
12
+ "test": "electron-mocha -t 5000 --require-main ./test/ignore-gpu-blacklist.js --renderer ./test/**/*.spec.js",
13
+ "tdd": "electron-mocha --interactive --renderer ./test/**/*.spec.js",
14
+ "pretest": "npm run build",
15
+ "prepare": "npm run build",
16
+ "preversion": "npm test"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/maptalks/maptalks.3dtiles.git"
21
+ },
22
+ "keywords": [
23
+ "maptalks",
24
+ "3dtiles",
25
+ "3d",
26
+ "maps"
27
+ ],
28
+ "files": [
29
+ "dist/maptalks.3dtiles.js",
30
+ "dist/maptalks.3dtiles.es.js"
31
+ ],
32
+ "author": "fuzhenn",
33
+ "license": "UNLICENSED",
34
+ "bugs": {
35
+ "url": "https://github.com/fuzhenn/3dtiles-issues/"
36
+ },
37
+ "homepage": "https://github.com/fuzhenn/3dtiles-issues/",
38
+ "dependencies": {
39
+ "@maptalks/function-type": "^1.3.1",
40
+ "@maptalks/gltf-loader": "^0.95.2",
41
+ "@maptalks/tbn-packer": "^1.4.5",
42
+ "frustum-intersects": "^0.2.2",
43
+ "gl-matrix": "^2.6.1",
44
+ "pako": "^2.0.4",
45
+ "parse-dds": "^1.2.1"
46
+ },
47
+ "devDependencies": {
48
+ "@maptalks/gl": "^0.95.6",
49
+ "@maptalks/transcoders.crn": "^0.95.8",
50
+ "@maptalks/transcoders.draco": "^0.95.8",
51
+ "@maptalks/transcoders.ktx2": "^0.95.8",
52
+ "@rollup/plugin-commonjs": "^20.0.0",
53
+ "@rollup/plugin-node-resolve": "^13.0.4",
54
+ "@rollup/plugin-replace": "4.0.0",
55
+ "electron": "^4.2.12",
56
+ "electron-mocha": "^11.0.1",
57
+ "eslint": "^8.46.0",
58
+ "eslint-plugin-mocha": "^10.1.0",
59
+ "express": "^4.17.1",
60
+ "maptalks": "^1.0.0-rc.28",
61
+ "pixelmatch": "^4.0.2",
62
+ "rollup": "^2.56.2",
63
+ "rollup-plugin-terser": "^5.3.1"
64
+ },
65
+ "gitHead": "846a56a61ec195ab87c028c2db7d6e3c187355e3"
66
+ }