@maptalks/3dtiles 0.20.0 → 0.21.0

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.20.0
2
+ * @maptalks/3dtiles v0.21.0
3
3
  * LICENSE : UNLICENSED
4
4
  * (c) 2016-2022 maptalks.org
5
5
  */
@@ -20,4 +20,4 @@ let st=0;function ot(t){return null==t}function at(t){return!ot(t)}function ct(t
20
20
  * @maptalks/gl v0.78.0
21
21
  * LICENSE : UNLICENSED
22
22
  * (c) 2016-2022 maptalks.com
23
- */(s,a)),c.generateBuffers(this.rt,{excludeElementsInVAO:e}),c}ie(t,e,r,i){const o=n.identity(t),a=this.getMap();Or.x=r[0],Or.y=r[1];const c=this._prjToPoint(Or),l=this.he(),f=1/(a.getGLZoom?a.getResolution(a.getGLZoom()):a.getGLRes());let h;Or.x=e[0],Or.y=e[1],h=a.altitudeToPoint?this.Nt:a.distanceToPointAtRes(100,100,a.getGLRes(),Or).y/100;let u=this.J.options.offset;g(u)&&(u=u(Or));const _=this.J.options.services[i].heightOffset||0;return s.set(Cr,c.x-u[0],c.y-u[1],h*r[2]+h*_),n.translate(o,o,Cr),s.set(l,f,f,h),n.scale(o,o,l),o}$t(t,e){const r=n.identity(t),i=this.getMap(),o=this.he();Or.x=e[0],Or.y=e[1];const a=i.distanceToPointAtRes(100,100,i.getGLRes(),Or);let c;return c=i.altitudeToPoint?this.Nt:a.y/100,s.set(o,a.x/100*1.01,a.y/100*1.01,c),n.scale(r,r,o),r}Rt(){const t={x:0,y:0,width:()=>this.tt?this.tt.width:1,height:()=>this.tt?this.tt.height:1};this.zt=new r.MeshShader({vert:"attribute vec3 aPosition;\n\n\n\nuniform mat4 projViewModelMatrix;\n\n\n\nvoid main() {\n\n gl_Position = projViewModelMatrix * vec4(aPosition, 1.0);\n\n}\n\n",frag:"precision mediump float;\nuniform vec3 color;\nvoid main() {\n gl_FragColor = vec4(color, 1.0);\n}\n",uniforms:["color",{name:"projViewModelMatrix",type:"function",fn:(t,e)=>n.multiply([],e.projViewMatrix,e.modelMatrix)}],extraCommandProps:{viewport:t}});const e=[],i=[];this.kt=new r.MeshShader({vert:"const float SHIFT_RIGHT_11 = 1.0 / 2048.0;\n\nconst float SHIFT_RIGHT_5 = 1.0 / 32.0;\n\nconst float SHIFT_LEFT_11 = 2048.0;\n\nconst float SHIFT_LEFT_5 = 32.0;\n\nconst float NORMALIZE_6 = 1.0 / 64.0;\n\nconst float NORMALIZE_5 = 1.0 / 32.0;\n\n\n\n#ifdef HAS_POSITION\n\n attribute vec3 POSITION;\n\n#endif\n\n\n\n#if defined(HAS_RGB)\n\n attribute vec3 RGB;\n\n#elif defined(HAS_RGBA)\n\n attribute vec4 RGBA;\n\n#elif defined(HAS_RGB565)\n\n attribute float RGB565;\n\n#endif\n\n\n\nuniform vec4 pointColor;\n\nuniform float pointSize;\n\n\n\nuniform mat4 projViewModelMatrix;\n\nuniform float pointOpacity;\n\n\n\nvarying vec4 vColor;\n\n\n\n#ifdef HAS_NORMAL\n\n #ifdef HAS_NORMAL_OCT16P\n\n attribute vec2 NORMAL_OCT16P;\n\n float signNotZero(float value) {\n\n return value >= 0.0 ? 1.0 : -1.0;\n\n }\n\n vec2 signNotZero(vec2 value) {\n\n return vec2(signNotZero(value.x), signNotZero(value.y));\n\n }\n\n vec3 octDecode(vec2 encoded, float range) {\n\n if (encoded.x == 0.0 && encoded.y == 0.0) {\n\n return vec3(0.0, 0.0, 0.0);\n\n }\n\n encoded = encoded / range * 2.0 - 1.0;\n\n vec3 v = vec3(encoded.x, encoded.y, 1.0 - abs(encoded.x) - abs(encoded.y));\n\n if (v.z < 0.0) {\n\n v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);\n\n }\n\n return normalize(v);\n\n }\n\n vec3 octDecode(vec2 encoded) {\n\n return octDecode(encoded, 255.0);\n\n }\n\n #else\n\n attribute vec3 NORMAL;\n\n #endif\n\n uniform vec3 lightDir;\n\n uniform mat3 modelNormalMatrix;\n\n uniform mat4 positionMatrix;\n\n float getLambertDiffuse(vec3 lightDir, vec3 normal) {\n\n return max(dot(-lightDir, normal), 0.0);\n\n }\n\n#endif\n\n\n\nvoid main() {\n\n #if defined(HAS_RGB)\n\n vColor = vec4(RGB / 255.0, 1.0) * pointOpacity;\n\n #elif defined(HAS_RGBA)\n\n vColor = RGBA / 255.0 * pointOpacity;\n\n #elif defined(HAS_RGB565)\n\n float compressed = RGB565;\n\n float r = floor(compressed * SHIFT_RIGHT_11);\n\n compressed -= r * SHIFT_LEFT_11;\n\n float g = floor(compressed * SHIFT_RIGHT_5);\n\n compressed -= g * SHIFT_LEFT_5;\n\n float b = compressed;\n\n vec3 rgb = vec3(r * NORMALIZE_5, g * NORMALIZE_6, b * NORMALIZE_5);\n\n vColor = vec4(rgb, 1.0);\n\n #else\n\n vColor = pointColor;\n\n #endif\n\n\n\n #ifdef HAS_POSITION\n\n vec3 localPos = POSITION;\n\n #endif\n\n\n\n #ifdef HAS_NORMAL\n\n mat3 positionNormalMatrix = mat3(positionMatrix);\n\n mat3 normalMatrix = modelNormalMatrix * positionNormalMatrix;\n\n #ifdef HAS_NORMAL_OCT16P\n\n vec3 localNormal = octDecode(NORMAL_OCT16P);\n\n #else\n\n vec3 localNormal = NORMAL;\n\n #endif\n\n vec3 normal = normalize(normalMatrix * localNormal);\n\n float colorStrength = getLambertDiffuse(lightDir, normal);\n\n colorStrength = max(colorStrength, 0.5);\n\n vColor *= colorStrength;\n\n #endif\n\n\n\n gl_Position = projViewModelMatrix * vec4(localPos, 1.0);\n\n gl_PointSize = pointSize;\n\n}\n\n",frag:"#define SHADER_NAME PNTS\n\nprecision mediump float;\n\n\n\nvarying vec4 vColor;\n\n\n\nvoid main() {\n\n gl_FragColor = vColor;\n\n}\n\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:(t,e)=>n.multiply(i,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,r)=>o.fromMat4(e,r.modelMatrix)}],extraCommandProps:{viewport:t,blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"},depth:{enable:!0,range:[0,1],func:"<"}}});const s=this.It();this.Pt=new r.PhongShader({extraCommandProps:s}),this.Dt=new r.pbr.StandardShader({extraCommandProps:s});const a=this.J;Tr(a.getRenderer().canvas,this.rt,a.getMap()),this.picking=new r.FBORayPicking(this.nt,{vert:this.Dt.vert,extraCommandProps:s,uniforms:this.Dt.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap())}It(){return{viewport:{x:0,y:0,width:()=>this.tt?this.tt.width:1,height:()=>this.tt?this.tt.height:1},colorMask:(t,e)=>e.colorMask||Sr,cull:{enable:!0,face:(t,e)=>e.cullFace||"back"},stencil:{enable:(t,e)=>!0===e.stencilEnable,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}}}Xt(t){return{projViewMatrix:this.getMap().projViewMatrix,color:t&&t.color||[0,1,0]}}Ft(t){const e=this.getMap(),r=e.getLightManager(),n=(r&&r.getDirectionalLight()||{}).direction||[1,1,-1],i=t&&t.pointOpacity||1;return{projViewMatrix:e.projViewMatrix,pointOpacity:i,lightDir:s.normalize(n,n)}}wt(){const t=this.getMap(),e=this.J.getRenderer().canvas,{iblTexes:r,dfgLUT:n}=Ar(e),i=pr(t,r,n);return y(i,{czm_lightDirectionEC:i.light0_viewDirection,lightSpecular:[1,1,1],viewMatrix:t.viewMatrix,projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,outSize:[e.width,e.height],polygonFill:[1,1,1,1],polygonOpacity:1}),i}le(t,e,n,i){const s=e.materials[t];if(!s||!s.baseColorTexture&&!s.pbrMetallicRoughness)return null;const o=y({},i);if(s.baseColorTexture){const t=e.textures[s.baseColorTexture.index];let r;t&&!t.image.color&&(r=this.S(t)),o.baseColorFactor=t&&t.image.color||s.baseColorFactor||[1,1,1,1],r&&(o.baseColorTexture=r)}else{if(s.normalTexture){const t=this.S(e.textures[s.normalTexture.index]),r=s.normalTexture.scale||1;o.normalTexture=t,o.normalMapFactor=r}if(s.occlusionTexture){const t=this.S(e.textures[s.occlusionTexture.index]),r=s.occlusionTexture.strength||1;o.occlusionTexture=t,o.occlusionFactor=r}if(s.emissiveTexture){const t=this.S(e.textures[s.emissiveTexture.index]);o.emissiveTexture=t}s.emissiveFactor;const t=s.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(o.baseColorFactor=t.baseColorFactor),t.baseColorTexture&&void 0!==t.baseColorTexture.index){const r=e.textures[t.baseColorTexture.index];r.image&&r.image.color?o.baseColorFactor=o.baseColorFactor?a.multiply(o.baseColorFactor,o.baseColorFactor,r.image.color):r.image.color:(o.baseColorTexture=this.S(r),o.baseColorTexture.getREGLTexture(this.rt))}if(p(t.metallicFactor)||(o.metallicFactor=t.metallicFactor),p(t.roughnessFactor)||(o.roughnessFactor=t.roughnessFactor),s.metallicRoughnessTexture){const t=this.S(e.textures[s.metallicRoughnessTexture.index]);o.metallicRoughnessTexture=t}}}if(s.s3mMaterial)return new r.Material(o);let c=new r.pbr.StandardMaterial(o);return"phong"===n&&(c=r.PhongMaterial.convertFrom(c)),c.once("complete",this.At),c}S(t){const e={type:t.type?fr(t.type):"uint8",format:t.format?hr(t.format):"rgba",flipY:!!t.flipY},n=t.image;n.array?e.data=n.array:n.mipmap&&(e.mipmap=n.mipmap),e.width=n.width,e.height=n.height;const i=t.sampler||t.texture&&t.texture.sampler;return i&&(i.magFilter&&(e.mag=ar(i.magFilter)),i.minFilter&&(e.min=cr(i.minFilter)),i.wrapS&&(e.wrapS=lr(i.wrapS)),i.wrapT&&(e.wrapT=lr(i.wrapT))),new r.Texture2D(e,this.Tt)}ue(t){const e=t.image,r=window.URL||window.webkitURL,n=new Blob([e.array],{type:e.mimeType});return r.createObjectURL(n)}yt({target:t}){const e=t.fe,r=this.it[e];if(r.count--,!r.count){const t=r.meshes;this.ot[e]=t,delete this.it[e];const n=t.ne;delete t.ne,n(null,{mesh:r.meshes,id:e})}}he(){return Rr}Kt(t){return this.J.Kt(t)}qt(t,e){const r=this.getMap();return r.getGLZoom?r.distanceToPoint(t,e,r.getGLZoom()):r.distanceToPointAtRes(t,e,r.getGLRes())}_pointToPrj(t){const e=this.getMap();return e.getGLZoom?e._pointToPrj(t,e.getGLZoom()):e._pointToPrjAtRes(t,e.getGLRes())}_prjToPoint(t){const e=this.getMap();return e.getGLZoom?e._prjToPoint(t,e.getGLZoom()):e._prjToPointAtRes(t,e.getGLRes(),Mr)}Jt(t){return"Y"===t?dr:"X"===t?Er:br}pick(t,e,r=3){const n=this.J;if(!n||!n.options.picking)return[];if(!this.pickingFBO||!this.picking)return[];const i=this.getMap(),s=this.wt(),o=this.picking;o.render(this.ut.getMeshes().filter((t=>!t.bloom)),s,!0);let a={};o.getRenderedMeshes().length&&(a=o.pick(t,e,r,s,{viewMatrix:i.viewMatrix,projMatrix:i.projMatrix,returnPoint:n.options.pickingPoint}));const{meshId:c,pickingId:l,point:f,coordinate:h}=a,u=(0===c||c)&&o.getMeshAt(c);if(!u||!u.geometry)return[];const _=u.properties;f&&f.length&&(f[0]=Math.round(1e5*f[0])/1e5,f[1]=Math.round(1e5*f[1])/1e5,f[2]=Math.round(1e5*f[2])/1e5);const d={batchId:l};if(n.options.debug&&(d.debugInfo=_),_&&_.batchTable){const{batchTable:t,batchTableBin:e,count:r}=_,n=l;for(const i in t)void 0!==t[i].byteOffset?d[i]=Oe(t[i],e,r,n):d[i]=t[i][n]}return[{data:d,point:f,coordinate:h}]}Ot(t){let e=new Set;for(let r=0,n=t.length;r<n;r++){const n=t[r].data.node;this.Mt(n)&&e.add(n.vt)}e=Array.from(e),e.sort();const r=new Map,n=e.length;for(let t=0;t<n;t++)r.set(e[t],t);return r}highlight(t){this.Ct=t;const e=this.J.getRenderer();this.Ut=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelAllHighlight(){this.Ct=null;const t=this.J.getRenderer();this.Ut=t.getFrameTimestamp(),t.setToRedraw(!0)}}const Pr=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")},Dr=Pr(),Fr=Dr.gl_trans__coders=Dr.gl_trans__coders||{};function kr(t,e){if(e)for(let r=0;r<e.length;r++){t[e[r].id||e[r].index]=e[r]}}Fr.inject=function(t){const e=t.toString(),r=e.indexOf("{")+1,n=e.substring(0,r),i=Dr.gl_trans__coders=Dr.gl_trans__coders||{};let s=`${n}\n const _____getGlobal = ${Pr.toString()};\n const g___lobals = _____getGlobal()\n const tran_____scoders = g___lobals['gl_trans__coders'] = g___lobals['gl_trans__coders'] || {};`;for(const t in i)"inject"!==t&&"getTranscoder"!==t&&"registerTranscoder"!==t&&(s+='tran_____scoders["'+t+'"] ='+i[t].toString()+"\n;");return s+="\n"+e.substring(n.length),s},Fr.registerTranscoder=function(t,e){Fr[t]=e},Fr.getTranscoder=function(t){return Fr[t]};const Gr=[];class Hr{constructor(t,e,r,n){this._e=t,this.xt=e,this.de=n,this.Ee=r.version,t.indexOf("i3s:tileset:")<0?(this.Ee<=1.6?this.Te="root":this.Te=0,r.version=this.Ee):(this.Te=t.substring("i3s:tileset:".length),this.Ee>1.6&&(this.Te=parseInt(this.Te))),this._e=t,this.me=r}load(){const t=this.me,e=t.layerScene.baseUrl;if(this.Ee<=1.6)return t[this.Te]&&t[this.Te].lodSelection?(this.Ae=t[this.Te],this.pe()):new Promise((r=>{let n=e+"/nodes/"+this.Te;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.de(this.xt,n,(()=>{this.Ae=t[this.Te],r(this.pe())}))}));if(this.Ee>=1.7){if(t[this.Te])return this.Ae=t[this.Te],this.pe();const r=Math.floor(this.Te/t.nodesPerPage);return new Promise((n=>{let i=e+"/nodepages/"+r;t.layerScene.eslpk&&(i+=".json"),this.de(this.xt,i,(()=>{this.Ae=t[this.Te],n(this.pe())}))}))}return null}getTileset(){return this.ye}getChildrenURL(){return this.ge}pe(){const t=this.me,e=t.layerScene.baseUrl,r=this.Ae.children,n=[],i={};if(r)for(let s=0;s<r.length;s++)if(this.Ee<=1.6){const o=r[s].id;if(t[o])continue;const a=o;i[a]||(i[a]=new Promise((r=>{let n=e+"/nodes/"+a;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.de(this.xt,n,(()=>{r()}))})),n.push(i[a]))}else{const o=r[s];if(t[o])continue;const a=Math.floor(o/t.nodesPerPage);i[a]||(i[a]=new Promise((r=>{let n=e+"/nodepages/"+a;t.layerScene.eslpk&&(n+=".json"),this.de(this.xt,n,(()=>{r()}))})),n.push(i[a]))}return n.length?Promise.all(n).then((()=>this.Re())):this.Re()}Re(){return Promise.resolve(this.be())}Ie(t){kr(this.me,t)}be(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.Ne(this.Ae,!0)}}Ne(t){const e=this.Ee,r=this.me,n=t;var i,s=n.obb,o=n.mbs,a={};if(o)i=Vr([],o[0],o[1],o[2]),a.sphere=[...i,o[3]];else if(s){const t=function(t,e,r){const n=function(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=r+r,a=n+n,c=i+i,l=r*o,f=n*o,h=n*a,u=i*o,_=i*a,d=i*c,E=s*o,T=s*a,m=s*c;return t[0]=1-h-d,t[3]=f-m,t[6]=u+T,t[1]=f+m,t[4]=1-l-d,t[7]=_-E,t[2]=u-T,t[5]=_+E,t[8]=1-l-h,t}([],r);return n[0]=n[0]*e[0],n[1]=n[1]*e[0],n[2]=n[2]*e[0],n[3]=n[3]*e[1],n[4]=n[4]*e[1],n[5]=n[5]*e[1],n[6]=n[6]*e[2],n[7]=n[7]*e[2],n[8]=n[8]*e[2],[...t,...n]}(i=Vr([],s.center[0],s.center[1],s.center[2]),s.halfSize,s.quaternion),e=t[3]+t[6]+t[9],r=t[4]+t[7]+t[10],n=t[5]+t[8]+t[11];z(Gr,e,r,n);const o=J(Gr);a.sphere=[...i,o]}var c=1/0,l=0;if(n.mbs?l=n.mbs[3]:n.obb&&(l=Math.max(Math.max(n.obb.halfSize[0],n.obb.halfSize[1]),n.obb.halfSize[2])),void 0!==n.lodThreshold)"maxScreenThresholdSQ"===r.lodSelectionMetricType?c=l/(Math.sqrt(n.lodThreshold)/(.25*Math.PI)):console.error("Unsupported lodSelectionMetricType in Layer");else if(void 0!==n.lodSelection)for(var f=0;f<n.lodSelection.length;f++)"maxScreenThreshold"===n.lodSelection[f].metricType&&(c=l/n.lodSelection[f].maxError);(c===1/0||isNaN(c))&&(c=1e5);var h=16*c;const u=D([]),_=n.children;var d;if(_){d=[];const t=this.me;for(let r=0;r<_.length;r++){const n=e<=1.6?_[r].id:_[r];if(!t[n]){d=null;break}d.push(this.Ne(t[n]))}}var E={refine:"REPLACE",boundingVolume:a,transform:u,geometricError:h};return e<=1.6?t.lodSelection?t.geometryData&&(E.content={uri:"i3s:mesh:"+(t.id||t.index)}):E.content={uri:"i3s:tileset:"+(t.id||t.index)}:_&&_.length&&!d?E.content={uri:"i3s:tileset:"+(t.id||t.index)}:n.mesh&&(E.content={uri:"i3s:mesh:"+(t.id||t.index)}),d&&d.length&&(E.children=d),E}getJSON(){return this.Ae}}function Vr(t,e,r,n){return oe(t,b(e),b(r),n)}const zr=!!Fr.ktx2,Xr=n.identity([]),Yr=(()=>{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 Wr(t){return t.indexOf("i3s:mesh")>=0}const Zr="i3s:mesh:".length;function Kr(t,e,r,n,i){const s=e.layerScene.eslpk,o=function(t,e){const r=e.substring(Zr);return t>=1.7?parseInt(r):r}(e.version,t),a=e[o],c=e.layerScene.baseUrl,l=[];let f=!1;const h=Xr;let u,_;if(e.version<=1.6){if(!a.geometryData)return null;const t=a.geometryData.length;let r=c+`/nodes/${a.id}/`+a.geometryData[t-1].href;s&&(r+=".bin");const n={geometry:{url:r,info:e.layerScene.store.defaultGeometrySchema}};let i=a.textureData&&a.textureData[0]&&a.textureData[0].href;if(i){const t=e.layerScene.store.textureEncoding[0];let r;r="image/jpeg"===t?"jpg":"png",s&&(i+="."+r);const o={pbrMetallicRoughness:{baseColorTexture:{url:c+`/nodes/${a.id}/`+i,factor:1,format:r,mimeType:t},metallicFactor:0}};n.material=o}l.push(n)}else{u=a.mesh.geometry,_=a.mesh.material;const t=e.layerScene.geometryDefinitions[u.definition],{geometryBuffers:o}=t;f=n&&2===o.length;const h=Fr.draco&&f?o[1]:o[0],d=Fr.draco&&f?1:0;let E=c+`/nodes/${u.resource}/geometries/`+d;s&&(E+=".bin");const T={geometry:{url:E,info:h}};if(i&&Yr&&f&&!Fr.draco)throw new Error("Must import @maptalks/transcoder.draco to load i3s draco compressed geometry");const m=e.layerScene.materialDefinitions,A=e.layerScene.textureSetDefinitions;let p,y=0;if(_&&(y=m[_.definition]),m){p=function(t,e,r,n,i,s){const o=JSON.parse(JSON.stringify(t));return jr(o,e,r,n,i,s),o}(y,A,c,_.resource,r,e.layerScene.eslpk)}else p={pbrMetallicRoughness:{metallicFactor:0}};T.material=p,l.push(T)}return{dracoCompression:f,meshes:l,nodeIndex:o,center:a.obb&&a.obb.center||a.mbs&&[a.mbs[0],a.mbs[1],a.mbs[2]],transform:h}}function jr(t,e,r,n,i,s){for(const o in t)if(t[o]&&t[o].textureSetDefinitionId>=0){const a=e[t[o].textureSetDefinitionId],c="images/"+a.formats[0].format,l=qr(a.formats,i),f={url:r+`/nodes/${n}/textures/${l.name}`,factor:void 0===t[o].factor?1:t[o].factor,format:l.format,mimeType:c};if(s){let t="";switch(l.format){case"dds":t="bin.dds";break;case"jpg":case"png":t=l.format}f.url+="."+t}t[o]=f}else R(t[o])&&jr(t[o],e,r,n,i,s)}function qr(t,e){for(let r=0;r<=t.length;r++){const n=t[r].format;if("dds"===n&&e.hasExtension("WEBGL_compressed_texture_s3tc"))return t[r];if("jpg"===n||"png"===n)return t[r];if("ktx2"===n&&zr)return t[r]}return null}const $r=[];class Qr extends t.renderer.CanvasRenderer{constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new Qt(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.Se={},this.we=[],this.de=this.Oe.bind(this)}getAnalysisMeshes(){if(!this.painter)return $r;const t=this.painter.getPaintedMeshes();if(!t)return $r;const e=[],{b3dmMeshes:r,pntsMeshes:n,i3dmMeshes:i}=t;return r.length&&B(e,r),n.length&&B(e,n),i.length&&B(e,i),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.we.length||super.needToRedraw())}getFrameTimestamp(){return this.Me}drawOnInteracting(t,e,r){this.draw(e,r)}draw(t,e){this.Me=t;const r=this.prepareCanvas();if(r&&!r.intersects(this.canvasExtent2D))return void this.completeRender();const{root:n,tiles:i}=this.layer.getTiles(),s=i.length;if(!i||!s)return void this.completeRender();this.xe(),this.Ce();const{selectedTiles:o,leaves:a,requests:c}=this.Ue(n,i);c.length&&this.loadTiles(c),this.ve(o,a,e),this.Be(),c.length||this.completeRender()}Ue(t,e){let r=[];this.Le();let n=0;const i=this.Pe(),s={};let o=!1,a=!1;for(let t=0;t<e.length;t++){const i=e[t],c=i.node;if(s[c.id])continue;s[c.id]=1;let l=!1;const f=this.getCachedTile(c.id);if(this.De(c.id)?(n++,l=a=!0,this.tilesLoading[c.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=a=!0),(!i.node.Fe||i.node.Fe<=500)&&(o=!0,i.selected=!0,i.data=f)):this.painter.has(c)||(l=a=!0,r.push(c)),!l)continue;if(this.ke(i))o=!0;else{this.Ge(i).length&&(o=!0)}}let c=[],l={};if(o&&({selectedTiles:c,leaves:l}=this.He(t)),r.length>1&&(r.sort(Jr),i)){const t=i-n;r=t>0?r.slice(0,t):[]}return{loading:a,requests:r,selectedTiles:c,leaves:l}}He(t){const e=[],r={};let n;const i=[t],s=[];for(;i.length>0||s.length>0;){if(s.length>0){const t=s[s.length-1];if(t.Ve===i.length){s.pop(),t===n&&(t.leave=!0,r[t.node.id]=1),e.push(t);continue}}const t=i.pop(),o=t.children;if(t.selected)if("add"===t.node.refine)r[t.node.id]=1,t.selectionDepth=s.length,e.push(t);else{if(t.selectionDepth=s.length,n=t,0===o.length){t.leave=!0,r[t.node.id]=1,e.push(t);continue}s.push(t),t.Ve=i.length}for(let t=0;t<o.length;t++)i.push(o[t])}return{selectedTiles:e,leaves:r}}ke(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}Ge(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const r=t.vt+1,n=[t.node];for(;n.length>0;){const i=n.pop().children;for(let s=0,o=i.length;s<o;s++){if((!i[s].content||!i[s].content.url)&&i[s].children&&i[s].children.length){n.push(i[s]);continue}const o=i[s].id;if(this.tileCache.has(o)){const r=this.layer.ze(i[s],t);r.selected=!0,r.data=this.tileCache.get(o),t.children.push(r),e.push(r)}else i[s].vt<=r&&n.push(i[s])}}return e}ve(t,e,r){this.tileCache.markAll(!1);for(let e=0,r=t.length;e<r;e++){const r=t[e].data;r.current=!0,this.tileCache.add(t[e].node.id,r)}this.tileCache.shrink();const n={tiles:t,leaves:e};this.onDrawTileStart(n);const i=this.painter.paint(t,e,r);this.onDrawTileEnd(n),i&&this.layer.fire("canvasisdirty",{renderCount:i})}onDrawTileStart(){}onDrawTileEnd(){}loadTiles(t){for(let e=0,r=t.length;e<r;e++){const r=t[e];this.tilesLoading[r.id]={current:!0,node:r},this.loadTile(r)}}loadTile(t){let e=t.content.url;if(U(e)){const r=v(e);return void this.Xe(e,r,t)}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const r=t.xt,n=this.Ye[r];return new Hr(e,r,n,this.de).load().then((r=>{this.onTilesetLoad(r,t,e)}))}t&&-1===e.indexOf("http://")&&-1===e.indexOf("https://")&&!Wr(e)&&(e=t.baseUrl+e);const r=this.layer.options.services[t.xt];if(r.ajaxInMainThread){let n=r.urlParams;n&&(n=(e.indexOf("?")>0?"&":"?")+n);let i=gt.getArrayBuffer(e+(n||""),r.fetchOptions);const s=i.xhr;i=i.then((r=>{delete this.Se[e],r?this.Xe(e,r.data,t):this.onTileError(null,t)})).catch((r=>{delete this.Se[e],this.onTileError(r,t)})),this.Se[e]=s}else this.Xe(e,null,t)}Xe(t,e,n){let i=this.o;i||(i=r.Util.getSupportedFormats(this.gl.gl||this.gl),this.o=i);const s=this.layer.options.services[n.xt];s.isSuperMapiServer&&(t=function(t,e){const r=t.substring(e.length).split("/"),n=[];for(let t=0;t<r.length;t++)n.push(encodeURIComponent(r[t]));return e+n.join("/")}(t,n.baseUrl));const o={url:t=this.layer.getTileUrl(t,n.baseUrl,s),arraybuffer:e,rootIdx:n.xt,upAxis:n.te,transform:n.matrix,supportedFormats:i};if(Wr(t)){const e=this.Ye[n.xt];if(o.i3sInfo=Kr(t,e,this.regl,this.layer.options.enableI3SCompressedGeometry,this.layer.options.forceI3SCompressedGeometry),!o.i3sInfo)return void this.onTileError({status:404},n)}this.workerConn.loadTile(this.layer.getId(),o,((e,r)=>{if(e)return void this.onTileError(e,n);const{magic:i}=r;"b3dm"===i||"pnts"===i||"i3dm"===i||"cmpt"===i?this.we.push({data:r,tile:n}):this.onTilesetLoad(r,n,t)}))}Ce(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let r=0;for(;this.we.length&&(r<e||!t.isInteracting());){const{data:t,tile:e}=this.we.shift(),{magic:n}=t;"b3dm"===n?this.painter.createB3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.We(t,e,r,n)})):"pnts"===n?this.painter.createPntsMesh(t,e.id,e,((r,{mesh:n})=>{this.We(t,e,r,n)})):"i3dm"===n?this.painter.createI3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.We(t,e,r,n)})):"cmpt"===n&&this.painter.createCMPTMesh(t,e.id,e,((r,{mesh:n})=>{this.We(t,e,r,n)})),r++}}We(t,e,r,n){if(r)this.onTileError(r,e);else{const r=this.Ze(n);e.memorySize=r,this.onTileLoad(t,e)}}Ze(t){let e=0;if(Array.isArray(t))for(let r=0;r<t.length;r++)t[r]&&(e+=this.Ze(t[r]));else t&&(e+=t.getMemorySize());return e}onTileLoad(t,e){this.layer&&(delete this.tilesLoading[e.id],this.layer.onTileLoad(t,e),this.Ke(e),this.setToRedraw(),this.layer.fire("tileload",{node:e}))}onTilesetLoad(t,e,r){this.layer&&(t.capabilities||t.layers&&t.layers[0]&&t.layers[0].capabilities?this.je(t,e,r):(delete this.tilesLoading[e.id],this.layer.onTilesetLoad(t,e,r)))}onTileError(t,e){if(!this.layer)return;const r=e.content.url;console.warn("failed to load 3d tile: "+r),console.warn(t),delete this.tilesLoading[e.id],this.qe(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}qe(e,r){const n={loadTime:t.Util.now(),current:!0,error:r,node:e};this.tileCache.add(e.id,n)}Ke(e){const r={loadTime:t.Util.now(),current:!0,node:e};this.tileCache.add(e.id,r)}abortTileLoading(t){if(!t||!this.workerConn)return;const e=t.node.content.url;if(this.layer.options.services[t.node.xt].ajaxInMainThread){const t=this.Se[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.Se[e]}Le(){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.$e(this.canvas,e)),this.regl=this.regl||l({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 Lr(this.regl,t),this.layer.Qe()}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new jt("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let r=this.layer.options||{};r=y({},r),delete r.offset,r.projection=t.getSpatialReference().getProjection().code;const n=this.layer.getId();e.addLayer(n,r,(t=>{if(t)throw t;this.layer&&(this.ready=!0,this.layer.fire("workerready"))}))}onRemove(){this.painter&&this.painter.remove(),this.pickingFBO&&(this.canvas.pickingFBO||this.pickingFBO.destroy(),delete this.pickingFBO),this.workerConn&&(this.workerConn.removeLayer(this.layer.getId(),(t=>{if(t)throw t})),this.workerConn.remove(),delete this.workerConn),this.clear(),delete this.tileCache,super.onRemove()}clear(){this.Be(!0),this.tileCache.reset(),this.tilesLoading={},super.clear()}clearCanvas(){this.regl&&this.regl.clear({color:[0,0,0,0],depth:1,stencil:0}),super.clearCanvas()}getTileOpacity(){return 1}getStencilValue(){return 0}Be(t){this.Je||(this.Je=Date.now());const e=Date.now();if(t||!(e-this.Je<this.layer.options.retireInterval)){this.Je=e;for(const e in this.tilesLoading){const r=this.tilesLoading[e];!t&&r.current||this.abortTileLoading(r)}}}Pe(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}$e(t,e){const r=["webgl","experimental-webgl"];let n=null;for(let i=0;i<r.length;++i){try{n=t.getContext(r[i],e)}catch(t){}if(n)break}return n}De(t){return!!this.tilesLoading[t]}getI3DMMeshes(){return this.painter.getI3DMMeshes()}getPNTSMeshes(){return this.painter.getPNTSMeshes()}getB3DMMeshes(){return this.painter.getB3DMMeshes()}readBatchData(t,e,r){return Se(t,e,0,r)}xe(){if(!this.tr)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const r=[];for(const n in this.tr){const i=this.tr[n];if("pending"===i.status)continue;i.status="pending";const s=i.rootIdx;if(r.push(gt.getJSON(n).then((t=>{delete this.tr[n];const e=this.Ye[s];if(e){t.nodes?kr(e,t.nodes):(e[t.id]=t,kr(e,t.children));for(let t=0;t<i.length;t++)i[t]();this.setToRedraw()}else this.setToRedraw()}))),e++,e>=t)break}r.length&&Promise.all(r)}Oe(t,e,r){this.tr||(this.tr={}),this.tr[e]=this.tr[e]||[],this.tr[e].rootIdx=t,this.tr[e].push(r),this.setToRedraw()}je(t,e,r){this.Ye||(this.Ye=[]);const n=e.xt;this.Ye[n]||(this.Ye[n]={});const i=this.Ye[n],s=this.layer.options.services[n];t.layers&&(t=t.layers[0],"/"!==r[r.length-1]&&(r+="/"),r+="layers/0"),i.version=+(s.i3sVersion||t.store.version),function(t,e,r,n,i,s){if(!i.layerScene){i.layerScene=t,i.nodesPerPage=t.nodePages&&t.nodePages.nodesPerPage||64,i.lodSelectionMetricType=t.nodePages&&t.nodePages.lodSelectionMetricType;let e=n;if(i.layerScene.eslpk=e.indexOf("3dSceneLayer.json")>=0,e.endsWith(".json")){const t=n.lastIndexOf("/");e=t<0?"./":n.substring(0,t)}i.layerScene.baseUrl=function(t){return t.split("?")[0]}(e)}return new Hr(n,e,i,s).load()}(t,n,0,r,i,this.de).then((t=>{this.onTilesetLoad(t,e,r)}))}pick(t,e,r){return this.painter?this.painter.pick(t,e,r&&r.tolerance):[]}highlight(t){if(this.Ct||(this.Ct=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const r=t[e].service||0;let n=this.Ct[r];n||(n=this.Ct[r]=new Map),n.set(t[e].id,t[e])}else{const e=t.service||0;let r=this.Ct[e];r||(r=this.Ct[e]=new Map),r.set(t.id,t)}this.painter.highlight(this.Ct)}cancelHighlight(t,e){if(!this.Ct)return;const r=this.Ct[t];if(r){if(Array.isArray(e))for(let t=0;t<e.length;t++)r.delete(e[t]);else r.delete(e);this.painter.highlight(this.Ct)}}cancelAllHighlight(){delete this.Ct,this.painter.cancelAllHighlight()}}function Jr(t,e){return t.Ht-e.Ht}function tn(t,e,r){return t[0]=e[r],t[1]=e[r+3],t[2]=e[r+6],t}function en(t,e,r){return Math.sqrt(function(t,e,r){var n=Y(rn,r,t),i=tn(nn,e,0),s=tn(sn,e,1),o=tn(on,e,2),a=J(i),c=J(s),l=J(o);K(i,i),K(s,s),K(o,o);var f=an;f[0]=j(n,i),f[1]=j(n,s),f[2]=j(n,o);var h,u=0;f[0]<-a?u+=(h=f[0]+a)*h:f[0]>a&&(u+=(h=f[0]-a)*h);f[1]<-c?u+=(h=f[1]+c)*h:f[1]>c&&(u+=(h=f[1]-c)*h);f[2]<-l?u+=(h=f[2]+l)*h:f[2]>l&&(u+=(h=f[2]-l)*h);return u}(t,e,r))}const rn=[],nn=[],sn=[],on=[],an=[];const cn=2*Math.PI;class ln{constructor(t,e,r,n){this.west=t,this.south=e,this.east=r,this.north=n}static contains(t,e){var r=e[0],n=e[1],i=t.west,s=t.east;return s<i&&(s+=cn,r<0&&(r+=cn)),(r>i||ye(r,i,1e-14))&&(r<s||ye(r,s,1e-14))&&n>=t.south&&n<=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 fn=[0,0,1];function hn(t,e){return oe(e,t[0],t[1],t[2])}class un{constructor(t,e){this.normal=s.copy([],t),this.distance=e}static fromPointNormal(t,e,r){var n=-s.dot(e,t);return s.copy(r.normal,e),r.distance=n,r}}const _n=[],dn=[],En=[],Tn=[],mn=[],An=[],pn=[],yn=[],gn=[],Rn=[],bn=new un([1,0,0],0),In=[];class Nn{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new ln(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){var r,n,i,o=0;if(!ln.contains(this.rectangle,e)){var a=this.southwestCornerCartesian,c=this.northeastCornerCartesian,l=this.westNormal,f=this.southNormal,h=this.eastNormal,u=this.northNormal,_=s.subtract(In,t,a),d=s.dot(_,l),E=s.dot(_,f),T=s.subtract(In,t,c),m=s.dot(T,h),A=s.dot(T,u);d>0?o+=d*d:m>0&&(o+=m*m),E>0?o+=E*E:A>0&&(o+=A*A)}if(r=e[2],n=this.minimumHeight,r>(i=this.maximumHeight)){var p=r-i;o+=p*p}else if(r<n){var y=n-r;o+=y*y}return Math.sqrt(o)}computeBox(t){const e=this;hn(ln.southwest(t,dn),e.southwestCornerCartesian),hn(ln.northeast(t,dn),e.northeastCornerCartesian),_n[0]=t.west,_n[1]=.5*(t.south+t.north),_n[2]=0;var r=hn(_n,En),n=s.cross(mn,r,fn);s.normalize(e.westNormal,n),_n[0]=t.east;var i=hn(_n,yn),o=s.cross(mn,fn,i);s.normalize(e.eastNormal,o);var a,c=s.subtract(mn,r,i),l=s.normalize(Tn,c),f=t.south;if(f>0){_n[0]=.5*(t.west+t.east),_n[1]=f;var h=hn(_n,gn);s.copy(Rn,l);var u=un.fromPointNormal(e.southwestCornerCartesian,e.westNormal,bn);Sn(gn,Rn,u,e.southwestCornerCartesian),a=me(h,An)}else a=Ae(ln.southeast(t,dn),An);var _=s.cross(pn,a,c);s.normalize(e.southNormal,_);var d,E=t.north;if(E<0){_n[0]=.5*(t.west+t.east),_n[1]=E;var T=hn(_n,gn);s.scale(Rn,l,-1);var m=un.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,bn);Sn(gn,Rn,m,e.northeastCornerCartesian),d=me(T,An)}else d=Ae(ln.northwest(t,dn),An);var A=s.cross(pn,c,d);s.normalize(e.northNormal,A)}}function Sn(t,e,r,n){var i=t,o=e,a=r.normal,c=s.dot(a,o);if(!(Math.abs(c)<1e-15)){var l=(-r.distance-s.dot(a,i))/c;if(!(l<0))return n=s.scale(n,o,l),s.add(n,i,n)}}const wn=new t.Extent(0,0,0,0),On=new t.Extent(0,0,0,0),Mn=[],xn=[],Cn=[],Un=[],vn=new t.Point(0,0),Bn=[],Ln=new t.Coordinate(0,0),Pn=n.identity([]);class Dn extends t.Layer{constructor(t,e){super(t,e),this.er(),this.Se={},this.rr=[]}er(){let t=this.options.services.map((t=>t.url));this.nr=t.map(((t,e)=>function(t,e){t=N(t);return{visible:1,baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:n.identity([]),xt:e,vt:0}}(t,e))),this.fire("rootready",{roots:this.nr.slice(0)})}showService(t){return this.ir(t,1),this}hideService(t){return this.ir(t,0),this}ir(t,e){const r=this.nr[t];if(!r)return;r.visible=e;const n=this.getRenderer();n&&n.setToRedraw()}getTileUrl(t){return t}getExtent(e){if(!e&&0!==e){const e=new t.Extent;for(let t=0;t<this.nr.length;t++)if(this.nr[t].boundingVolume){const r=this.boundingVolumeToExtent(this.nr[t]);e._combine(r)}return e}return this.nr[e]&&this.nr[e].boundingVolume?this.boundingVolumeToExtent(this.nr[e]):null}boundingVolumeToExtent(e){const r=e.boundingVolume.sr?Pn:e.matrix,n=this.getMap();if(e.boundingVolume.region){const r=e.boundingVolume.region;return new t.Extent(I(r[0]),I(r[1]),I(r[2]),I(r[3]))}if(e.boundingVolume.sphere){const i=e.boundingVolume.sphere,o=ue([],s.transformMat4([],i,r)),a=i[3],c=n.locate(o,-a,a),l=n.locate(o,a,-a);return new t.Extent(c,l)}if(e.boundingVolume.box){const i=e.boundingVolume.box,a=s.transformMat4([],i,r),c=new t.Coordinate(ue([],a)),l=i.slice(3);o.multiply(l,o.fromMat4([],e.matrix),l);const f=s.length(l.slice(0,3)),h=s.length(l.slice(3,6)),u=s.length(l.slice(6,9)),_=Math.max(f,h,u),d=n.locate(c,-_,_),E=n.locate(c,_,-_);return new t.Extent(d,E)}return null}getRootTiles(){return this.nr}getTiles(){const t=this.getRenderer();if(!t.ready)return this.ar(),{tiles:Un};const e=this.getMap(),r=e.cameraPosition;let n,i;if(e.getGLZoom)i=e.pointToDistance(r[2],0,e.getGLZoom()),Ln.set(r[0],r[1]),n=e.pointToCoord(Ln,e.getGLZoom());else{const t=e.getGLRes();i=e.pointAtResToDistance(r[2],0,t),Ln.set(r[0],r[1]),n=e.pointAtResToCoord(Ln,t)}this.cr=this.cr||[],s.set(this.cr,b(n.x),b(n.y),i),this.lr=oe(this.lr||[],this.cr[0],this.cr[1],this.cr[2]),this.hr=2*Math.tan(.5*b(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const l=[];for(let e=0;e<this.nr.length;e++){const r=this.nr[e];if(!r.visible)continue;let n=1/0;const i=[r],s=this.ur(e);for(;i.length>0;){const e=i.pop();for(e.id||this._r(e);c.level>=e.vt;)c=c.parent;const r=this.dr(e,s,o);if(r<1){let t=c;for(;t&&!t.content;)t=t.parent;0===r&&t&&t.content&&this.Er(l,t);if(!1===this.options.services[e.xt].alwaysShow)continue;if(!(0===r&&e.vt<=n))continue;e.content&&(n=e.vt)}e.Ht<1/0&&this.Tr(e);const a=this.ze(e,c);c.children.push(a);const f=e.children,h=f&&f.length,u=a.content;if(!h&&u&&this.Er(l,a),h){u&&"add"===e.refine&&this.Er(l,a),c=a;const r=f[0].parent;let n=!1;for(let s=0,o=f.length;s<o;s++){if(r){const e=t.getCachedTile(f[s].id);if(e&&e.error&&404!==e.error.status)continue;n=!0}else{n=!0,f[s].parent=e,f[s].te=e.te,f[s].baseUrl=e.baseUrl;const t=f[s].content&&(f[s].content.url||f[s].content.uri);t&&(U(t)||t.indexOf("i3s:")>=0?f[s].baseUrl=e.baseUrl:-1===t.indexOf("http://")&&-1===t.indexOf("https://")?f[s].content.url=e.baseUrl+t:f[s].baseUrl=t.substring(0,t.lastIndexOf("/")+1))}i.push(f[s])}!n&&u&&this.Er(l,a)}}}return{root:a,tiles:l}}Er(t,e){const{viewerRequestVolume:r}=e.node;r&&!function(t,e,r){if(r.region){const e=r.region;if(t[0]>=e[0]&&t[0]<=e[2]&&t[1]>=e[1]&&t[1]<=e[3])return!0}else{if(r.sphere)return Fn(r,e);if(r.box)return 0===kn(r,e)}return!1}(this.cr,this.lr,r)||t.push(e)}ze(t,e){return{id:t.id,node:t,children:[],level:t.vt,parent:e,content:t.content&&t.content.url}}_r(e){e.id=t.Util.GUID(),e.matrix=e.transform||n.identity([]),e.mr=this.Ar(e),e.parent&&(function(t){return t.content&&t.content.uri&&t.content.uri.indexOf("i3s:")>=0}(e)||(e.matrix=n.multiply(e.matrix,e.parent.matrix,e.matrix)),e.xt=e.parent.xt,void 0===e.vt&&(e.vt=e.parent.vt+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),this.pr(e)}pr(t){const e=t.boundingVolume;if(!e||e.sr)return;const r=this.options.services[t.xt].heightOffset||0,i=this.options.offset,o=g(i)||i[0]||i[1];if(!t.boundingVolume||!r&&n.exactEquals(t.matrix,Pn)&&!o)return;const{region:a,box:c,sphere:l}=e;if(a){const t=this.yr([I(a[0]),I(a[1])]);a[0]=b(t.x),a[1]=b(t.y);const e=this.yr([I(a[2]),I(a[3])]);a[2]=b(e.x),a[3]=b(e.y),a[4]+=r,a[5]+=r}else if(c||l){const e=c||l,n=s.transformMat4(Mn,e,t.matrix),i=ue(xn,n),o=this.yr([i[0],i[1]]);i[0]=o.x,i[1]=o.y,i[2]+=r,oe(e,b(i[0]),b(i[1]),i[2])}e.sr=!0}Ar(t){return void 0===t.geometricError||!t.boundingVolume}Tr(t){let e=t.parent;for(;e&&e.mr&&!(e.Ht<=t.Ht);)e.Ht=t.Ht,e=t.parent}onTileLoad(t,e){if(t.children&&(!e.children||!e.children.length)){e.children=t.children;const r=e.content.url;e.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const n=this.getRenderer();n&&n.setToRedraw()}}onTilesetLoad(t,e,r){if(!t)return void console.warn("invalid tileset at : "+r);const i=this.options.services[e.xt],s=(t.asset&&t.asset.gltfUpAxis||e&&e.te||i.upAxis||"Y").toUpperCase();t.root.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const o=r.indexOf("realspace/")>-1;0===e.vt&&(t.asset&&t.asset.s3mType&&o||i.isSuperMapiServer)&&(t.root.baseUrl+="data/path/");const a=t.asset.i3s;if(t.root.te=s,e){const r=e.boundingVolume;y(e,t.root),e.refine=e.refine&&e.refine.toLowerCase()||"replace",r&&(e.boundingVolume=r);const i=t.root.transform;i&&(e.parent?a||(e.matrix=n.multiply([],e.parent.matrix,i)):e.matrix=i),this.pr(e),e.gr=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.mr=this.Ar(e);const s=e.content&&(e.content.url||e.content.uri);s&&e.content.uri&&(e.content.url=e.content.uri,delete e.content.uri),a||!s||U(s)||-1!==s.indexOf("http://")||-1!==s.indexOf("https://")||(e.content.url=e.baseUrl+s)}this.ar(),this.fire("loadtileset",{tileset:t,index:e.xt,url:r})}dr(t,e,r){if(t.Ht=1/0,0===t.vt||t.mr)return 1;if(!this.Rr(t,e,r))return-1;if(0===t.geometricError)return 1;let n=this.options.services[t.xt].maximumScreenSpaceError;null==n&&(n=8);let i=this.br(t);return 0===i&&t.parent&&(i=.5*(t.parent.Fe||0)),i>=n?1:0}Kt(e,r){r||(r=new t.Point(0,0));const n=this.getMap();return n.getGLZoom?n.coordToPoint(e,n.getGLZoom(),r):n.coordToPointAtRes(e,n.getGLRes(),r)}Rr(e,r,i){const a=e.id;let c=this.rr[a];const{boundingVolume:l}=e,f=l.sphere;let u=l.region;const _=l.box;if(!c){let r,i,h;if(_&&(u=function(t,e){for(let e=0;e<9;e++)jn[e]=t[e+3];const r=jn;n.exactEquals(e,Pn)||o.multiply(r,o.fromMat4(Bn,e),r);const i=s.copy(Gn,t),a=s.set(Hn,r[0],r[1],r[2]),c=s.set(Vn,r[3],r[4],r[5]),l=s.set(zn,r[6],r[7],r[8]);Xn[0]=Xn[0]||[];const f=s.copy(Xn[0],i);s.sub(f,f,a),s.sub(f,f,c),s.sub(f,f,l),Xn[1]=Xn[1]||[];const h=s.copy(Xn[1],i);s.sub(h,h,a),s.sub(h,h,c),s.add(h,h,l),Xn[2]=Xn[2]||[];const u=s.copy(Xn[2],i);s.sub(u,u,a),s.add(u,u,c),s.sub(u,u,l),Xn[3]=Xn[3]||[];const _=s.copy(Xn[3],i);s.sub(_,_,a),s.add(_,_,c),s.add(_,_,l),Xn[4]=Xn[4]||[];const d=s.copy(Xn[4],i);s.add(d,d,a),s.sub(d,d,c),s.sub(d,d,l),Xn[5]=Xn[5]||[];const E=s.copy(Xn[5],i);s.add(E,E,a),s.sub(E,E,c),s.add(E,E,l),Xn[6]=Xn[6]||[];const T=s.copy(Xn[6],i);s.add(T,T,a),s.add(T,T,c),s.sub(T,T,l),Xn[7]=Xn[7]||[];const m=s.copy(Xn[7],i);s.add(m,m,a),s.add(m,m,c),s.add(m,m,l);for(let t=0;t<Xn.length;t++)Yn[t]=Yn[t]||[],ue(Yn[t],Xn[t]),Wn[t]=Yn[t][0],Zn[t]=Yn[t][1],Kn[t]=Yn[t][2];return[b(Math.min(...Wn)),b(Math.min(...Zn)),b(Math.max(...Wn)),b(Math.max(...Zn)),Math.min(...Kn),Math.max(...Kn)]}(_,e.matrix),l.region=u),u){r=wn.set(I(u[0]),I(u[1]),I(u[2]),I(u[3]));const t=r.getCenter(),e=this.Ir(t);r=r.convertTo((t=>this.Kt(t,vn)),On),h=u[4],i=u[5],c=this.rr[a]=[[r.xmin,r.ymin,h*e[2]],[r.xmax,r.ymax,i*e[2]]],c.center=t}else if(f){const e=ue(Mn,f),r=new t.Coordinate(e),n=this.Kt(r,vn).toArray(),i=this.Ir(r);n.push(e[2]*i[2]),c=this.rr[a]=[n,f[3]*i[2]],c.center=r}}if(r){if(u)wn.xmin=c[0][0],wn.ymin=c[0][1],wn.xmax=c[1][0],wn.ymax=c[1][1];else if(f){const t=c[2];wn.xmin=c[0][0]-t,wn.ymin=c[0][1]-t,wn.xmax=c[0][0]+t,wn.ymax=c[0][1]+t}else if(_){const t=c[1],e=c[2];wn.xmin=c[0][0]-t,wn.ymin=c[0][1]-e,wn.xmax=c[0][0]+t,wn.ymax=c[0][1]+e}if(!r.intersects(wn))return!1}return u?d(i,c):f?function(t,e,r){T(t);for(var n=e[0],i=-e[1],s=0;s<6;s++)if((!r||"0"!==r.charAt(s))&&A(h[s],n)<i)return!1;return!0}(i,c):!!_&&function(t,e,r){T(t);for(var n=0;n<6;n++)if(!(r&&"0"===r.charAt(n)||E(h[n],e)))return!1;return!0}(i,c)}Ir(t){const e=this.getMap(),r=e.distanceToPointAtRes(100,100,e.getGLRes(),t);let n;return n=e.altitudeToPoint?e.altitudeToPoint(100,e.getGLRes())/100:r.y/100,s.set(Cn,r.x/100*1.01,r.y/100*1.01,n),Cn}yr(e){Array.isArray(e)&&(e=new t.Coordinate(e));let r=this.options.offset;if(g(r)&&(r=r(Array.isArray(e)?new t.Coordinate(e):e)),r[0]||r[1]){const t=this.getMap(),n=t.getGLRes(),i=t.coordToPointAtRes(e,n);return i._sub(r),t.pointAtResToCoord(i,n)}return e}ur(e){const r=this.options.services[e].maxExtent;if(!r)return null;const n=this.nr[e];return n.maxExtent||(n.maxExtent=new t.Extent(r).convertTo((t=>this.Kt(t)))),n.maxExtent}br(t){const e=this.hr,r=t.geometricError;if(0===r)return t.Fe=0,0;const n=this.getMap();let i;t.boundingVolume.region?i=function(t,e,r){t.Nr||(t.Nr=new Nn(t.boundingVolume.region));return t.Nr.distanceToCamera(e,r)}(t,this.lr,this.cr):t.boundingVolume.sphere?i=Fn(t.boundingVolume,this.lr):t.boundingVolume.box&&(i=kn(t.boundingVolume,this.lr));const s=Math.max(Math.abs(i),1e-7),o=r*n.height/(s*e);return t.Ht=i,t.Fe=o,o}ar(){const t=this.getRenderer();t&&t.setToRedraw()}se(t){return this.rr[t]}identify(e,r={}){const n=this.getMap(),i=this.getRenderer();if(!n||!i)return[];const s=n.coordToContainerPoint(new t.Coordinate(e));return this.identifyAtPoint(s,r)}identifyAtPoint(t,e={}){const r=this.getMap(),n=this.getRenderer();if(!r||!n)return[];const i=r.getDevicePixelRatio();return n.pick(t.x*i,t.y*i,e)}highlight(t){const e=this.getRenderer();return e?(e.highlight(t),this):(this.Ct||(this.Ct=[]),this.Ct.push(t),this)}Qe(){if(this.Ct){for(let t=0;t<this.Ct.length;t++)this.highlight(this.Ct[t]);delete this.Ct}}cancelHighlight(t,e){const r=this.getRenderer();return r?(r.cancelHighlight(t,e),this):this}cancelAllHighlight(){const t=this.getRenderer();return t?(t.cancelAllHighlight(),this):this}}function Fn(t,e){const r=t.sphere,n=s.dist(r,e),i=t.sphere[3];return n<i?0:n-i}function kn(t,e){const r=t.box;return en(s.set(Mn,r[0],r[1],r[2]),o.set(Bn,r[3],r[4],r[5],r[6],r[7],r[8],r[9],r[10],r[11]),e)}Dn.mergeOptions({"maxGPUMemory":512,"retireInterval":2e3,"loadingLimitOnInteracting":5,"loadingLimit":0,"renderer":"gl","forceRenderOnZooming":!0,"forceRenderOnRotating":!0,"forceRenderOnMoving":!0,"debug":!1,"debugOutline":[0,1,0],"meshLimitPerFrame":1,"i3sNodepageLimitPerFrame":1,"enableI3SCompressedGeometry":!0,"forceI3SCompressedGeometry":!0,"picking":!0,"pickingPoint":!0,"geometryEvents":!1,"antialias":!1,"optionalExtensions":["ANGLE_instanced_arrays","OES_element_index_uint","OES_standard_derivatives","OES_vertex_array_object","OES_texture_half_float","OES_texture_half_float_linear","OES_texture_float","OES_texture_float_linear","WEBGL_depth_texture","EXT_shader_texture_lod","WEBGL_compressed_texture_astc","WEBGL_compressed_texture_etc","WEBGL_compressed_texture_etc1","WEBGL_compressed_texture_pvrtc","WEBGL_compressed_texture_s3tc","WEBGL_compressed_texture_s3tc_srgb"],"offset":[0,0]}),Dn.registerRenderer("gl",Qr),Dn.registerJSONType("Geo3DTilesLayer");const Gn=[],Hn=[],Vn=[],zn=[],Xn=[],Yn=[],Wn=[],Zn=[],Kn=[],jn=[];class qn{constructor(t,e,r){this.i=t,this.Sr=e||Ht,this.o=r,this.wr={"image/crn":Fr.crn&&Fr.crn(),"image/ktx2":Fr.ktx2&&Fr.ktx2(),"image/cttf":Fr.ktx2&&Fr.ktx2(),"draco":Fr.draco&&Fr.draco()}}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.Or(t,e,r,n,i)):gt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Or(t,i,r,n)}))}Or(t,e,r,n,i){const s=i&&i.maxTextureSize,o=this.Mr(e,r,n,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.Sr(a,o.glb,{transferable:!0,requestImage:this.i,decoders:this.wr,supportedFormats:this.o,maxTextureSize:s});return c.load({skipAttributeTransform:!1}).then((e=>{e.url=`${t}-${r}-${n}`;const i=c.transferables;for(let t=0;t<o.transferables.length;t++)i.indexOf(o.transferables[t])<0&&i.push(o.transferables[t]);return{magic:"b3dm",count:o.count,transferables:i,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,gltf:e}}))}Mr(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported b3dm version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in b3dm header is inconsistent with b3dm's byte length, url: "+n;return console.warn(t),{error:t}}let o,a=i.getUint32(12,!0),c=i.getUint32(16,!0),l=i.getUint32(20,!0),f=i.getUint32(24,!0),h=28+e;l>=570425344?(h-=8,o=a,l=c,f=0,a=0,c=0):f>=570425344&&(h-=4,o=l,l=a,f=c,a=0,c=0);const u=[t];let _,d,E;if(a>0?(_=be(t,h,a),h+=a,o=_.BATCH_LENGTH):_={"BATCH_LENGTH":o},c>0&&(h+=c),l>0&&(d=Ie(t,h,l),h+=l,f>0)){const e=Ne(0,h,f);E=t.slice(e.offset,e.offset+e.byteLength),h+=f,u.push(E)}const T=_.BATCH_LENGTH,m={};if(_&&_.BATCH_ID){m.BATCH_ID=we(_.BATCH_ID,t,undefined.offset,T);const e=m.BATCH_ID.array&&m.BATCH_ID.array.buffer;e&&u.indexOf(e)<0&&u.push(e)}return{count:o,transferables:u,featureTable:_,batchTable:d,batchTableBin:E,b3dm:m,glb:{buffer:t,byteOffset:h,byteLength:i.byteLength+i.byteOffset-h}}}Cr(){return null}}class $n{constructor(t,e,r,n){this.i=t,this.Sr=e||Ht,this.o=r,this.wr={"image/crn":Fr.crn&&Fr.crn(),"image/ktx2":Fr.ktx2&&Fr.ktx2(),"image/cttf":Fr.ktx2&&Fr.ktx2(),"draco":Fr.draco&&Fr.draco()},this.Ur=n}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.Or(t,e,r,n,i)):gt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Or(t,i,r,n)}))}Or(t,e,r,n,i){return this.vr(t,e,r,n,i).then((({gltf:i,transferables:s})=>{const o=this.Br(e,r,n,t);if(o.error)return Promise.resolve(o);for(let t=0;t<s.length;t++)-1===o.transferables.indexOf(s[t])&&o.transferables.push(s[t]);return delete i.transferables,Promise.resolve({magic:"i3dm",count:o.count,transferables:o.transferables,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,i3dm:o.i3dm,gltf:i})}))}vr(t,e,r,n,i){const s=i&&i.maxTextureSize,o={transferable:!0,requestImage:this.i,decoders:this.wr,supportedFormats:this.o,maxTextureSize:s},a=new DataView(e,r,n),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 n=O(new Uint8Array(e,c+r,a.byteLength-c));-1==n.indexOf("://")&&(n=t.substring(0,t.lastIndexOf("/"))+"/"+n);return n.indexOf(".glb")>0?gt.getArrayBuffer(n,{}).then((t=>this.Lr(n,{buffer:t.data,byteOffset:0},o))):gt.getJSON(n,{}).then((t=>this.Lr(n,t,o)))}{const n={buffer:e,byteOffset:c+r,byteLength:a.byteLength-c};return this.Lr(t,n,o)}}Lr(t,e,r){const n=t.substring(0,t.lastIndexOf("/")),i=new this.Sr(n,e,r);return i.load({skipAttributeTransform:!0}).then((r=>{let n=0,s=0;return e.buffer&&(n=e.byteOffset||0,s=e.byteLength||0),r.url=`${t}-${n}-${s}`,{transferables:i.transferables,gltf:r}}))}Br(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported pnts version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+n;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:l,batchTableBin:f}=Le(i,32+e,o),h={},u=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;h.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,r=a.QUANTIZED_VOLUME_SCALE,{byteOffset:n}=a.POSITION_QUANTIZED;h.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:u,componentType:5126,array:this.Pr(new Uint16Array(t,n+c.offset,3*u),e,r)},o.push(h.POSITION.array.buffer)}if(a.BATCH_ID){h.BATCH_ID=we(a.BATCH_ID,t,c.offset,u);const e=h.BATCH_ID.array&&h.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;h.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,h.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;h.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:this.Dr(new Uint16Array(t,e+c.offset,2*u))},o.push(h.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,h.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:this.Dr(new Uint16Array(t,e+c.offset,2*u))},o.push(h.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;h.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,u).slice()},o.push(h.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;h.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.SCALE_NON_UNIFORM.array.buffer)}return{count:u,batchTable:l,batchTableBin:f,featureTable:a,i3dm:h,transferables:o}}Dr(t){const e=t.length/2,r=new Float32Array(3*e),n=[];for(let i=0;i<e;i++)Qn(n,t[2*i],t[2*i+1],65535),r[3*i]=n[0],r[3*i+1]=n[1],r[3*i+2]=n[2];return r}Pr(t,e,r){return Be(new Float32Array(t.length),t,e,r)}Cr(){return null}}function Qn(t,e,r,n){if(t[0]=Jn(e,n),t[1]=Jn(r,n),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]))*ti(e),t[1]=(1-Math.abs(e))*ti(t[1])}return K(t,t)}function Jn(t,e){return function(t,e,r){return t<e?e:t>r?r:t}(t,0,e=function(t,e){if(null!=t)return t;return e}(e,255))/e*2-1}function ti(t){return t<0?-1:1}class ei{constructor(){}load(t,e,r=0,n=0){return e?(n||(n=e.byteLength),this.Or(t,e,r,n)):gt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Or(t,i,r,n)}))}Or(t,e,r,n){return this.Fr(e,r,n,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}))}Fr(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported pnts version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+n;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:l,batchTableBin:f}=Le(i,e+28,o),h=a.QUANTIZED_VOLUME_OFFSET,u=a.QUANTIZED_VOLUME_SCALE,_=a.POINTS_LENGTH;let d,E={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){E=a.extensions["3DTILES_draco_point_compression"],d=new DataView(t,E.byteOffset+c.offset,E.byteLength);const e={attributes:E.properties,useUniqueIDs:!1};return this.kr||(this.kr=Fr.draco()),this.kr(d,e).then((e=>{const r=e.attributes;!a.POSITION&&!a.POSITION_QUANTIZED||r.POSITION||r.POSITION_QUANTIZED||(r.POSITION=a.POSITION,r.POSITION_QUANTIZED=a.POSITION_QUANTIZED),!(a.RGB||a.RGBA||a.RGB565)||r.RGB||r.RGBA||r.RGB565||(r.RGB=a.RGB,r.RGBA=a.RGBA,r.RGB565=a.RGB565),!a.NORMAL&&!a.NORMAL_OCT16P||r.NORMAL||r.NORMAL_OCT16P||(r.NORMAL=a.NORMAL,r.NORMAL_OCT16P=a.NORMAL_OCT16P);const n=this.Gr(t,e.attributes,c.offset,_,o,h,u);if(e.attributes.BATCH_ID){const t=e.attributes.BATCH_ID.array;n.BATCH_ID={byteStride:0,byteOffset:0,itemSize:1,count:t.length,componentType:ve(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?n.BATCH_ID=we(a.BATCH_ID,t,c.offset,_):n.BATCH_ID=ri(_);const e=n.BATCH_ID.array&&n.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return{count:_,batchTable:l,batchTableBin:f,featureTable:a,pnts:n,transferables:o}}))}const T=this.Gr(t,a,c.offset,_,o,h,u);if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?T.BATCH_ID=we(a.BATCH_ID,t,c.offset,_):T.BATCH_ID=ri(_);const e=T.BATCH_ID.array&&T.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:_,batchTable:l,batchTableBin:f,featureTable:a,pnts:T,transferables:o})}Gr(t,e,r,n,i,s,o){const a={};if(e.POSITION){let{byteOffset:s,array:o}=e.POSITION;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n*4);o=new Float32Array(e)}a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:o},i.push(o.buffer)}else if(e.POSITION_QUANTIZED){let{byteOffset:c,array:l}=e.POSITION_QUANTIZED;c=c||0;const f=l?0:r;a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:this.Pr(l||new Uint16Array(t,c+f,3*n),s,o)},i.push(a.POSITION.array.buffer)}if(e.RGBA){let{byteOffset:s,array:o}=e.RGBA;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+4*n);o=new Uint8Array(e)}a.RGBA={byteStride:0,byteOffset:0,itemSize:4,count:n,componentType:5121,array:o},i.push(o.buffer)}else if(e.RGB){let{byteOffset:s,array:o}=e.RGB;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n);o=new Uint8Array(e)}a.RGB={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5121,array:o},i.push(o.buffer)}else if(e.RGB565){let{byteOffset:s,array:o}=e.RGB565;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+2*n);o=new Uint16Array(e)}a.RGB565={byteStride:0,byteOffset:0,itemSize:1,count:n,componentType:5123,array:o},i.push(o.buffer)}if(e.NORMAL){let{byteOffset:s,array:o}=e.NORMAL;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n*4);o=new Float32Array(e)}a.NORMAL={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:o},i.push(o.buffer)}else if(e.NORMAL_OCT16P){let{byteOffset:s,array:o}=e.NORMAL_OCT16P;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+2*n);o=new Uint8Array(e)}a.NORMAL_OCT16P={byteStride:0,byteOffset:0,itemSize:2,count:n,componentType:5121,array:o},i.push(o.buffer)}return a}Pr(t,e,r){return Be(new Float32Array(t.length),t,e,r)}Cr(){return null}}function ri(t){const e=C(t),r=new e(t);for(let e=0;e<t;e++)r[e]=e;return{byteStride:0,byteOffset:0,itemSize:1,count:t,componentType:ve(e),array:r}}class ni{constructor(t,e){this.i=t,this.Sr=e||Ht}load(t,e,r=0,n=0,i){return e?this.Or(t,e,r,n,i):gt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return this.Or(t,i,r,n)}))}Or(t,e,r,n,i){n||(n=e.byteLength);const s=this.Hr(e,t,r,n),o=[];for(let r=0;r<s.length;r++){let n;if("b3dm"===s[r].magic)n=new qn(this.i,this.Sr);else if("i3dm"===s[r].magic)n=new $n(this.i,this.Sr);else if("pnts"===s[r].magic)n=new ei;else{if("cmpt"!==s[r].magic){console.warn("Unsupported magic in CMPT tile:",s[r].magic);continue}n=new ni(this.i,this.Sr)}o.push(n.load(t,e,s[r].offset,s[r].byteLength,i).then((t=>t)))}return Promise.all(o).then((t=>({magic:"cmpt",tiles:t})))}Hr(t,e,r,n){const i=new DataView(t,r,n),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported cmpt version: "+s+", url:"+e;return console.warn(t),{error:t}}if(16===i.byteLength)return[];const o=[],a=i.getUint32(12,!0);let c=16;for(let e=0;e<a;e++){const e=ge(i,c),n=i.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+r,byteLength:n}),c+=n}return o}}if(e.transcoders){const r=t.Map.VERSION;if(r.indexOf("1.0.0-beta")>=0||r.indexOf("1.0.0-alpha")>=0){const r=e.transcoders.inject(f);t.registerWorkerAdapter("@maptalks/3dtiles",r)}else t.registerWorkerAdapter("@maptalks/3dtiles",(function(){return e.transcoders.inject(f)}))}else t.registerWorkerAdapter("@maptalks/3dtiles",f);export{qn as B3DMLoader,ni as CMPTLoader,Dn as Geo3DTilesLayer,L as Geo3DTilesUtil,pe as Geo3DTransform};"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.20.0");
23
+ */(s,a)),c.generateBuffers(this.rt,{excludeElementsInVAO:e}),c}ie(t,e,r,i){const o=n.identity(t),a=this.getMap();Or.x=r[0],Or.y=r[1];const c=this._prjToPoint(Or),l=this.he(),f=1/(a.getGLZoom?a.getResolution(a.getGLZoom()):a.getGLRes());let h;Or.x=e[0],Or.y=e[1],h=a.altitudeToPoint?this.Nt:a.distanceToPointAtRes(100,100,a.getGLRes(),Or).y/100;let u=this.J.options.offset;g(u)&&(u=u(Or));const _=this.J.options.services[i].heightOffset||0;return s.set(Cr,c.x-u[0],c.y-u[1],h*r[2]+h*_),n.translate(o,o,Cr),s.set(l,f,f,h),n.scale(o,o,l),o}$t(t,e){const r=n.identity(t),i=this.getMap(),o=this.he();Or.x=e[0],Or.y=e[1];const a=i.distanceToPointAtRes(100,100,i.getGLRes(),Or);let c;return c=i.altitudeToPoint?this.Nt:a.y/100,s.set(o,a.x/100*1.01,a.y/100*1.01,c),n.scale(r,r,o),r}Rt(){const t={x:0,y:0,width:()=>this.tt?this.tt.width:1,height:()=>this.tt?this.tt.height:1};this.zt=new r.MeshShader({vert:"attribute vec3 aPosition;\n\n\n\nuniform mat4 projViewModelMatrix;\n\n\n\nvoid main() {\n\n gl_Position = projViewModelMatrix * vec4(aPosition, 1.0);\n\n}\n\n",frag:"precision mediump float;\nuniform vec3 color;\nvoid main() {\n gl_FragColor = vec4(color, 1.0);\n}\n",uniforms:["color",{name:"projViewModelMatrix",type:"function",fn:(t,e)=>n.multiply([],e.projViewMatrix,e.modelMatrix)}],extraCommandProps:{viewport:t}});const e=[],i=[];this.kt=new r.MeshShader({vert:"const float SHIFT_RIGHT_11 = 1.0 / 2048.0;\n\nconst float SHIFT_RIGHT_5 = 1.0 / 32.0;\n\nconst float SHIFT_LEFT_11 = 2048.0;\n\nconst float SHIFT_LEFT_5 = 32.0;\n\nconst float NORMALIZE_6 = 1.0 / 64.0;\n\nconst float NORMALIZE_5 = 1.0 / 32.0;\n\n\n\n#ifdef HAS_POSITION\n\n attribute vec3 POSITION;\n\n#endif\n\n\n\n#if defined(HAS_RGB)\n\n attribute vec3 RGB;\n\n#elif defined(HAS_RGBA)\n\n attribute vec4 RGBA;\n\n#elif defined(HAS_RGB565)\n\n attribute float RGB565;\n\n#endif\n\n\n\nuniform vec4 pointColor;\n\nuniform float pointSize;\n\n\n\nuniform mat4 projViewModelMatrix;\n\nuniform float pointOpacity;\n\n\n\nvarying vec4 vColor;\n\n\n\n#ifdef HAS_NORMAL\n\n #ifdef HAS_NORMAL_OCT16P\n\n attribute vec2 NORMAL_OCT16P;\n\n float signNotZero(float value) {\n\n return value >= 0.0 ? 1.0 : -1.0;\n\n }\n\n vec2 signNotZero(vec2 value) {\n\n return vec2(signNotZero(value.x), signNotZero(value.y));\n\n }\n\n vec3 octDecode(vec2 encoded, float range) {\n\n if (encoded.x == 0.0 && encoded.y == 0.0) {\n\n return vec3(0.0, 0.0, 0.0);\n\n }\n\n encoded = encoded / range * 2.0 - 1.0;\n\n vec3 v = vec3(encoded.x, encoded.y, 1.0 - abs(encoded.x) - abs(encoded.y));\n\n if (v.z < 0.0) {\n\n v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);\n\n }\n\n return normalize(v);\n\n }\n\n vec3 octDecode(vec2 encoded) {\n\n return octDecode(encoded, 255.0);\n\n }\n\n #else\n\n attribute vec3 NORMAL;\n\n #endif\n\n uniform vec3 lightDir;\n\n uniform mat3 modelNormalMatrix;\n\n uniform mat4 positionMatrix;\n\n float getLambertDiffuse(vec3 lightDir, vec3 normal) {\n\n return max(dot(-lightDir, normal), 0.0);\n\n }\n\n#endif\n\n\n\nvoid main() {\n\n #if defined(HAS_RGB)\n\n vColor = vec4(RGB / 255.0, 1.0) * pointOpacity;\n\n #elif defined(HAS_RGBA)\n\n vColor = RGBA / 255.0 * pointOpacity;\n\n #elif defined(HAS_RGB565)\n\n float compressed = RGB565;\n\n float r = floor(compressed * SHIFT_RIGHT_11);\n\n compressed -= r * SHIFT_LEFT_11;\n\n float g = floor(compressed * SHIFT_RIGHT_5);\n\n compressed -= g * SHIFT_LEFT_5;\n\n float b = compressed;\n\n vec3 rgb = vec3(r * NORMALIZE_5, g * NORMALIZE_6, b * NORMALIZE_5);\n\n vColor = vec4(rgb, 1.0);\n\n #else\n\n vColor = pointColor;\n\n #endif\n\n\n\n #ifdef HAS_POSITION\n\n vec3 localPos = POSITION;\n\n #endif\n\n\n\n #ifdef HAS_NORMAL\n\n mat3 positionNormalMatrix = mat3(positionMatrix);\n\n mat3 normalMatrix = modelNormalMatrix * positionNormalMatrix;\n\n #ifdef HAS_NORMAL_OCT16P\n\n vec3 localNormal = octDecode(NORMAL_OCT16P);\n\n #else\n\n vec3 localNormal = NORMAL;\n\n #endif\n\n vec3 normal = normalize(normalMatrix * localNormal);\n\n float colorStrength = getLambertDiffuse(lightDir, normal);\n\n colorStrength = max(colorStrength, 0.5);\n\n vColor *= colorStrength;\n\n #endif\n\n\n\n gl_Position = projViewModelMatrix * vec4(localPos, 1.0);\n\n gl_PointSize = pointSize;\n\n}\n\n",frag:"#define SHADER_NAME PNTS\n\nprecision mediump float;\n\n\n\nvarying vec4 vColor;\n\n\n\nvoid main() {\n\n gl_FragColor = vColor;\n\n}\n\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:(t,e)=>n.multiply(i,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,r)=>o.fromMat4(e,r.modelMatrix)}],extraCommandProps:{viewport:t,blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"},depth:{enable:!0,range:[0,1],func:"<"}}});const s=this.It();this.Pt=new r.PhongShader({extraCommandProps:s}),this.Dt=new r.pbr.StandardShader({extraCommandProps:s});const a=this.J;Tr(a.getRenderer().canvas,this.rt,a.getMap()),this.picking=new r.FBORayPicking(this.nt,{vert:this.Dt.vert,extraCommandProps:s,uniforms:this.Dt.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap())}It(){return{viewport:{x:0,y:0,width:()=>this.tt?this.tt.width:1,height:()=>this.tt?this.tt.height:1},colorMask:(t,e)=>e.colorMask||Sr,cull:{enable:!0,face:(t,e)=>e.cullFace||"back"},stencil:{enable:(t,e)=>!0===e.stencilEnable,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}}}Xt(t){return{projViewMatrix:this.getMap().projViewMatrix,color:t&&t.color||[0,1,0]}}Ft(t){const e=this.getMap(),r=e.getLightManager(),n=(r&&r.getDirectionalLight()||{}).direction||[1,1,-1],i=t&&t.pointOpacity||1;return{projViewMatrix:e.projViewMatrix,pointOpacity:i,lightDir:s.normalize(n,n)}}wt(){const t=this.getMap(),e=this.J.getRenderer().canvas,{iblTexes:r,dfgLUT:n}=Ar(e),i=pr(t,r,n);return y(i,{czm_lightDirectionEC:i.light0_viewDirection,lightSpecular:[1,1,1],viewMatrix:t.viewMatrix,projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,outSize:[e.width,e.height],polygonFill:[1,1,1,1],polygonOpacity:1}),i}le(t,e,n,i){const s=e.materials[t];if(!s||!s.baseColorTexture&&!s.pbrMetallicRoughness)return null;const o=y({},i);if(s.baseColorTexture){const t=e.textures[s.baseColorTexture.index];let r;t&&!t.image.color&&(r=this.S(t)),o.baseColorFactor=t&&t.image.color||s.baseColorFactor||[1,1,1,1],r&&(o.baseColorTexture=r)}else{if(s.normalTexture){const t=this.S(e.textures[s.normalTexture.index]),r=s.normalTexture.scale||1;o.normalTexture=t,o.normalMapFactor=r}if(s.occlusionTexture){const t=this.S(e.textures[s.occlusionTexture.index]),r=s.occlusionTexture.strength||1;o.occlusionTexture=t,o.occlusionFactor=r}if(s.emissiveTexture){const t=this.S(e.textures[s.emissiveTexture.index]);o.emissiveTexture=t}s.emissiveFactor;const t=s.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(o.baseColorFactor=t.baseColorFactor),t.baseColorTexture&&void 0!==t.baseColorTexture.index){const r=e.textures[t.baseColorTexture.index];r.image&&r.image.color?o.baseColorFactor=o.baseColorFactor?a.multiply(o.baseColorFactor,o.baseColorFactor,r.image.color):r.image.color:(o.baseColorTexture=this.S(r),o.baseColorTexture.getREGLTexture(this.rt))}if(p(t.metallicFactor)||(o.metallicFactor=t.metallicFactor),p(t.roughnessFactor)||(o.roughnessFactor=t.roughnessFactor),s.metallicRoughnessTexture){const t=this.S(e.textures[s.metallicRoughnessTexture.index]);o.metallicRoughnessTexture=t}}}if(s.s3mMaterial)return new r.Material(o);let c=new r.pbr.StandardMaterial(o);"phong"===n&&(c=r.PhongMaterial.convertFrom(c));const l=s.pbrMetallicRoughness,f=l&&l.baseColorTexture&&l.baseColorTexture.extensions;return f&&f.KHR_texture_transform&&(c.set("khr_offset",f.KHR_texture_transform.offset||[0,0]),c.set("khr_rotation",f.KHR_texture_transform.rotation||0),c.set("khr_scale",f.KHR_texture_transform.scale||[1,1])),c.once("complete",this.At),c}S(t){const e={type:t.type?fr(t.type):"uint8",format:t.format?hr(t.format):"rgba",flipY:!!t.flipY},n=t.image;n.array?e.data=n.array:n.mipmap&&(e.mipmap=n.mipmap),e.width=n.width,e.height=n.height;const i=t.sampler||t.texture&&t.texture.sampler;return i&&(i.magFilter&&(e.mag=ar(i.magFilter)),i.minFilter&&(e.min=cr(i.minFilter)),i.wrapS&&(e.wrapS=lr(i.wrapS)),i.wrapT&&(e.wrapT=lr(i.wrapT))),new r.Texture2D(e,this.Tt)}ue(t){const e=t.image,r=window.URL||window.webkitURL,n=new Blob([e.array],{type:e.mimeType});return r.createObjectURL(n)}yt({target:t}){const e=t.fe,r=this.it[e];if(r.count--,!r.count){const t=r.meshes;this.ot[e]=t,delete this.it[e];const n=t.ne;delete t.ne,n(null,{mesh:r.meshes,id:e})}}he(){return Rr}Kt(t){return this.J.Kt(t)}qt(t,e){const r=this.getMap();return r.getGLZoom?r.distanceToPoint(t,e,r.getGLZoom()):r.distanceToPointAtRes(t,e,r.getGLRes())}_pointToPrj(t){const e=this.getMap();return e.getGLZoom?e._pointToPrj(t,e.getGLZoom()):e._pointToPrjAtRes(t,e.getGLRes())}_prjToPoint(t){const e=this.getMap();return e.getGLZoom?e._prjToPoint(t,e.getGLZoom()):e._prjToPointAtRes(t,e.getGLRes(),Mr)}Jt(t){return"Y"===t?dr:"X"===t?Er:br}pick(t,e,r=3){const n=this.J;if(!n||!n.options.picking)return[];if(!this.pickingFBO||!this.picking)return[];const i=this.getMap(),s=this.wt(),o=this.picking;o.render(this.ut.getMeshes().filter((t=>!t.bloom)),s,!0);let a={};o.getRenderedMeshes().length&&(a=o.pick(t,e,r,s,{viewMatrix:i.viewMatrix,projMatrix:i.projMatrix,returnPoint:n.options.pickingPoint}));const{meshId:c,pickingId:l,point:f,coordinate:h}=a,u=(0===c||c)&&o.getMeshAt(c);if(!u||!u.geometry)return[];const _=u.properties;f&&f.length&&(f[0]=Math.round(1e5*f[0])/1e5,f[1]=Math.round(1e5*f[1])/1e5,f[2]=Math.round(1e5*f[2])/1e5);const d={batchId:l};if(n.options.debug&&(d.debugInfo=_),_&&_.batchTable){const{batchTable:t,batchTableBin:e,count:r}=_,n=l;for(const i in t)void 0!==t[i].byteOffset?d[i]=Oe(t[i],e,r,n):d[i]=t[i][n]}return[{data:d,point:f,coordinate:h}]}Ot(t){let e=new Set;for(let r=0,n=t.length;r<n;r++){const n=t[r].data.node;this.Mt(n)&&e.add(n.vt)}e=Array.from(e),e.sort();const r=new Map,n=e.length;for(let t=0;t<n;t++)r.set(e[t],t);return r}highlight(t){this.Ct=t;const e=this.J.getRenderer();this.Ut=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelAllHighlight(){this.Ct=null;const t=this.J.getRenderer();this.Ut=t.getFrameTimestamp(),t.setToRedraw(!0)}}const Pr=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")},Dr=Pr(),Fr=Dr.gl_trans__coders=Dr.gl_trans__coders||{};function kr(t,e){if(e)for(let r=0;r<e.length;r++){t[e[r].id||e[r].index]=e[r]}}Fr.inject=function(t){const e=t.toString(),r=e.indexOf("{")+1,n=e.substring(0,r),i=Dr.gl_trans__coders=Dr.gl_trans__coders||{};let s=`${n}\n const _____getGlobal = ${Pr.toString()};\n const g___lobals = _____getGlobal()\n const tran_____scoders = g___lobals['gl_trans__coders'] = g___lobals['gl_trans__coders'] || {};`;for(const t in i)"inject"!==t&&"getTranscoder"!==t&&"registerTranscoder"!==t&&(s+='tran_____scoders["'+t+'"] ='+i[t].toString()+"\n;");return s+="\n"+e.substring(n.length),s},Fr.registerTranscoder=function(t,e){Fr[t]=e},Fr.getTranscoder=function(t){return Fr[t]};const Gr=[];class Hr{constructor(t,e,r,n){this._e=t,this.xt=e,this.de=n,this.Ee=r.version,t.indexOf("i3s:tileset:")<0?(this.Ee<=1.6?this.Te="root":this.Te=0,r.version=this.Ee):(this.Te=t.substring("i3s:tileset:".length),this.Ee>1.6&&(this.Te=parseInt(this.Te))),this._e=t,this.me=r}load(){const t=this.me,e=t.layerScene.baseUrl;if(this.Ee<=1.6)return t[this.Te]&&t[this.Te].lodSelection?(this.Ae=t[this.Te],this.pe()):new Promise((r=>{let n=e+"/nodes/"+this.Te;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.de(this.xt,n,(()=>{this.Ae=t[this.Te],r(this.pe())}))}));if(this.Ee>=1.7){if(t[this.Te])return this.Ae=t[this.Te],this.pe();const r=Math.floor(this.Te/t.nodesPerPage);return new Promise((n=>{let i=e+"/nodepages/"+r;t.layerScene.eslpk&&(i+=".json"),this.de(this.xt,i,(()=>{this.Ae=t[this.Te],n(this.pe())}))}))}return null}getTileset(){return this.ye}getChildrenURL(){return this.ge}pe(){const t=this.me,e=t.layerScene.baseUrl,r=this.Ae.children,n=[],i={};if(r)for(let s=0;s<r.length;s++)if(this.Ee<=1.6){const o=r[s].id;if(t[o])continue;const a=o;i[a]||(i[a]=new Promise((r=>{let n=e+"/nodes/"+a;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.de(this.xt,n,(()=>{r()}))})),n.push(i[a]))}else{const o=r[s];if(t[o])continue;const a=Math.floor(o/t.nodesPerPage);i[a]||(i[a]=new Promise((r=>{let n=e+"/nodepages/"+a;t.layerScene.eslpk&&(n+=".json"),this.de(this.xt,n,(()=>{r()}))})),n.push(i[a]))}return n.length?Promise.all(n).then((()=>this.Re())):this.Re()}Re(){return Promise.resolve(this.be())}Ie(t){kr(this.me,t)}be(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.Ne(this.Ae,!0)}}Ne(t){const e=this.Ee,r=this.me,n=t;var i,s=n.obb,o=n.mbs,a={};if(o)i=Vr([],o[0],o[1],o[2]),a.sphere=[...i,o[3]];else if(s){const t=function(t,e,r){const n=function(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=r+r,a=n+n,c=i+i,l=r*o,f=n*o,h=n*a,u=i*o,_=i*a,d=i*c,E=s*o,T=s*a,m=s*c;return t[0]=1-h-d,t[3]=f-m,t[6]=u+T,t[1]=f+m,t[4]=1-l-d,t[7]=_-E,t[2]=u-T,t[5]=_+E,t[8]=1-l-h,t}([],r);return n[0]=n[0]*e[0],n[1]=n[1]*e[0],n[2]=n[2]*e[0],n[3]=n[3]*e[1],n[4]=n[4]*e[1],n[5]=n[5]*e[1],n[6]=n[6]*e[2],n[7]=n[7]*e[2],n[8]=n[8]*e[2],[...t,...n]}(i=Vr([],s.center[0],s.center[1],s.center[2]),s.halfSize,s.quaternion),e=t[3]+t[6]+t[9],r=t[4]+t[7]+t[10],n=t[5]+t[8]+t[11];z(Gr,e,r,n);const o=J(Gr);a.sphere=[...i,o]}var c=1/0,l=0;if(n.mbs?l=n.mbs[3]:n.obb&&(l=Math.max(Math.max(n.obb.halfSize[0],n.obb.halfSize[1]),n.obb.halfSize[2])),void 0!==n.lodThreshold)"maxScreenThresholdSQ"===r.lodSelectionMetricType?c=l/(Math.sqrt(n.lodThreshold)/(.25*Math.PI)):console.error("Unsupported lodSelectionMetricType in Layer");else if(void 0!==n.lodSelection)for(var f=0;f<n.lodSelection.length;f++)"maxScreenThreshold"===n.lodSelection[f].metricType&&(c=l/n.lodSelection[f].maxError);(c===1/0||isNaN(c))&&(c=1e5);var h=16*c;const u=D([]),_=n.children;var d;if(_){d=[];const t=this.me;for(let r=0;r<_.length;r++){const n=e<=1.6?_[r].id:_[r];if(!t[n]){d=null;break}d.push(this.Ne(t[n]))}}var E={refine:"REPLACE",boundingVolume:a,transform:u,geometricError:h};return e<=1.6?t.lodSelection?t.geometryData&&(E.content={uri:"i3s:mesh:"+(t.id||t.index)}):E.content={uri:"i3s:tileset:"+(t.id||t.index)}:_&&_.length&&!d?E.content={uri:"i3s:tileset:"+(t.id||t.index)}:n.mesh&&(E.content={uri:"i3s:mesh:"+(t.id||t.index)}),d&&d.length&&(E.children=d),E}getJSON(){return this.Ae}}function Vr(t,e,r,n){return oe(t,b(e),b(r),n)}const zr=!!Fr.ktx2,Xr=n.identity([]),Yr=(()=>{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 Wr(t){return t.indexOf("i3s:mesh")>=0}const Zr="i3s:mesh:".length;function Kr(t,e,r,n,i){const s=e.layerScene.eslpk,o=function(t,e){const r=e.substring(Zr);return t>=1.7?parseInt(r):r}(e.version,t),a=e[o],c=e.layerScene.baseUrl,l=[];let f=!1;const h=Xr;let u,_;if(e.version<=1.6){if(!a.geometryData)return null;const t=a.geometryData.length;let r=c+`/nodes/${a.id}/`+a.geometryData[t-1].href;s&&(r+=".bin");const n={geometry:{url:r,info:e.layerScene.store.defaultGeometrySchema}};let i=a.textureData&&a.textureData[0]&&a.textureData[0].href;if(i){const t=e.layerScene.store.textureEncoding[0];let r;r="image/jpeg"===t?"jpg":"png",s&&(i+="."+r);const o={pbrMetallicRoughness:{baseColorTexture:{url:c+`/nodes/${a.id}/`+i,factor:1,format:r,mimeType:t},metallicFactor:0}};n.material=o}l.push(n)}else{u=a.mesh.geometry,_=a.mesh.material;const t=e.layerScene.geometryDefinitions[u.definition],{geometryBuffers:o}=t;f=n&&2===o.length;const h=Fr.draco&&f?o[1]:o[0],d=Fr.draco&&f?1:0;let E=c+`/nodes/${u.resource}/geometries/`+d;s&&(E+=".bin");const T={geometry:{url:E,info:h}};if(i&&Yr&&f&&!Fr.draco)throw new Error("Must import @maptalks/transcoder.draco to load i3s draco compressed geometry");const m=e.layerScene.materialDefinitions,A=e.layerScene.textureSetDefinitions;let p,y=0;if(_&&(y=m[_.definition]),m){p=function(t,e,r,n,i,s){const o=JSON.parse(JSON.stringify(t));return jr(o,e,r,n,i,s),o}(y,A,c,_.resource,r,e.layerScene.eslpk)}else p={pbrMetallicRoughness:{metallicFactor:0}};T.material=p,l.push(T)}return{dracoCompression:f,meshes:l,nodeIndex:o,center:a.obb&&a.obb.center||a.mbs&&[a.mbs[0],a.mbs[1],a.mbs[2]],transform:h}}function jr(t,e,r,n,i,s){for(const o in t)if(t[o]&&t[o].textureSetDefinitionId>=0){const a=e[t[o].textureSetDefinitionId],c="images/"+a.formats[0].format,l=qr(a.formats,i),f={url:r+`/nodes/${n}/textures/${l.name}`,factor:void 0===t[o].factor?1:t[o].factor,format:l.format,mimeType:c};if(s){let t="";switch(l.format){case"dds":t="bin.dds";break;case"jpg":case"png":t=l.format}f.url+="."+t}t[o]=f}else R(t[o])&&jr(t[o],e,r,n,i,s)}function qr(t,e){for(let r=0;r<=t.length;r++){const n=t[r].format;if("dds"===n&&e.hasExtension("WEBGL_compressed_texture_s3tc"))return t[r];if("jpg"===n||"png"===n)return t[r];if("ktx2"===n&&zr)return t[r]}return null}const $r=[];class Qr extends t.renderer.CanvasRenderer{constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new Qt(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.Se={},this.we=[],this.de=this.Oe.bind(this)}getAnalysisMeshes(){if(!this.painter)return $r;const t=this.painter.getPaintedMeshes();if(!t)return $r;const e=[],{b3dmMeshes:r,pntsMeshes:n,i3dmMeshes:i}=t;return r.length&&B(e,r),n.length&&B(e,n),i.length&&B(e,i),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.we.length||super.needToRedraw())}getFrameTimestamp(){return this.Me}drawOnInteracting(t,e,r){this.draw(e,r)}draw(t,e){this.Me=t;const r=this.prepareCanvas();if(r&&!r.intersects(this.canvasExtent2D))return void this.completeRender();const{root:n,tiles:i}=this.layer.getTiles(),s=i.length;if(!i||!s)return void this.completeRender();this.xe(),this.Ce();const{selectedTiles:o,leaves:a,requests:c}=this.Ue(n,i);c.length&&this.loadTiles(c),this.ve(o,a,e),this.Be(),c.length||this.completeRender()}Ue(t,e){let r=[];this.Le();let n=0;const i=this.Pe(),s={};let o=!1,a=!1;for(let t=0;t<e.length;t++){const i=e[t],c=i.node;if(s[c.id])continue;s[c.id]=1;let l=!1;const f=this.getCachedTile(c.id);if(this.De(c.id)?(n++,l=a=!0,this.tilesLoading[c.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=a=!0),(!i.node.Fe||i.node.Fe<=500)&&(o=!0,i.selected=!0,i.data=f)):this.painter.has(c)||(l=a=!0,r.push(c)),!l)continue;if(this.ke(i))o=!0;else{this.Ge(i).length&&(o=!0)}}let c=[],l={};if(o&&({selectedTiles:c,leaves:l}=this.He(t)),r.length>1&&(r.sort(Jr),i)){const t=i-n;r=t>0?r.slice(0,t):[]}return{loading:a,requests:r,selectedTiles:c,leaves:l}}He(t){const e=[],r={};let n;const i=[t],s=[];for(;i.length>0||s.length>0;){if(s.length>0){const t=s[s.length-1];if(t.Ve===i.length){s.pop(),t===n&&(t.leave=!0,r[t.node.id]=1),e.push(t);continue}}const t=i.pop(),o=t.children;if(t.selected)if("add"===t.node.refine)r[t.node.id]=1,t.selectionDepth=s.length,e.push(t);else{if(t.selectionDepth=s.length,n=t,0===o.length){t.leave=!0,r[t.node.id]=1,e.push(t);continue}s.push(t),t.Ve=i.length}for(let t=0;t<o.length;t++)i.push(o[t])}return{selectedTiles:e,leaves:r}}ke(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}Ge(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const r=t.vt+1,n=[t.node];for(;n.length>0;){const i=n.pop().children;for(let s=0,o=i.length;s<o;s++){if((!i[s].content||!i[s].content.url)&&i[s].children&&i[s].children.length){n.push(i[s]);continue}const o=i[s].id;if(this.tileCache.has(o)){const r=this.layer.ze(i[s],t);r.selected=!0,r.data=this.tileCache.get(o),t.children.push(r),e.push(r)}else i[s].vt<=r&&n.push(i[s])}}return e}ve(t,e,r){this.tileCache.markAll(!1);for(let e=0,r=t.length;e<r;e++){const r=t[e].data;r.current=!0,this.tileCache.add(t[e].node.id,r)}this.tileCache.shrink();const n={tiles:t,leaves:e};this.onDrawTileStart(n);const i=this.painter.paint(t,e,r);this.onDrawTileEnd(n),i&&this.layer.fire("canvasisdirty",{renderCount:i})}onDrawTileStart(){}onDrawTileEnd(){}loadTiles(t){for(let e=0,r=t.length;e<r;e++){const r=t[e];this.tilesLoading[r.id]={current:!0,node:r},this.loadTile(r)}}loadTile(t){let e=t.content.url;if(U(e)){const r=v(e);return void this.Xe(e,r,t)}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const r=t.xt,n=this.Ye[r];return new Hr(e,r,n,this.de).load().then((r=>{this.onTilesetLoad(r,t,e)}))}t&&-1===e.indexOf("http://")&&-1===e.indexOf("https://")&&!Wr(e)&&(e=t.baseUrl+e);const r=this.layer.options.services[t.xt];if(r.ajaxInMainThread){let n=r.urlParams;n&&(n=(e.indexOf("?")>0?"&":"?")+n);let i=gt.getArrayBuffer(e+(n||""),r.fetchOptions);const s=i.xhr;i=i.then((r=>{delete this.Se[e],r?this.Xe(e,r.data,t):this.onTileError(null,t)})).catch((r=>{delete this.Se[e],this.onTileError(r,t)})),this.Se[e]=s}else this.Xe(e,null,t)}Xe(t,e,n){let i=this.o;i||(i=r.Util.getSupportedFormats(this.gl.gl||this.gl),this.o=i);const s=this.layer.options.services[n.xt];s.isSuperMapiServer&&(t=function(t,e){const r=t.substring(e.length).split("/"),n=[];for(let t=0;t<r.length;t++)n.push(encodeURIComponent(r[t]));return e+n.join("/")}(t,n.baseUrl));const o={url:t=this.layer.getTileUrl(t,n.baseUrl,s),arraybuffer:e,rootIdx:n.xt,upAxis:n.te,transform:n.matrix,supportedFormats:i};if(Wr(t)){const e=this.Ye[n.xt];if(o.i3sInfo=Kr(t,e,this.regl,this.layer.options.enableI3SCompressedGeometry,this.layer.options.forceI3SCompressedGeometry),!o.i3sInfo)return void this.onTileError({status:404},n)}this.workerConn.loadTile(this.layer.getId(),o,((e,r)=>{if(e)return void this.onTileError(e,n);const{magic:i}=r;"b3dm"===i||"pnts"===i||"i3dm"===i||"cmpt"===i?this.we.push({data:r,tile:n}):this.onTilesetLoad(r,n,t)}))}Ce(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let r=0;for(;this.we.length&&(r<e||!t.isInteracting());){const{data:t,tile:e}=this.we.shift(),{magic:n}=t;"b3dm"===n?this.painter.createB3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.We(t,e,r,n)})):"pnts"===n?this.painter.createPntsMesh(t,e.id,e,((r,{mesh:n})=>{this.We(t,e,r,n)})):"i3dm"===n?this.painter.createI3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.We(t,e,r,n)})):"cmpt"===n&&this.painter.createCMPTMesh(t,e.id,e,((r,{mesh:n})=>{this.We(t,e,r,n)})),r++}}We(t,e,r,n){if(r)this.onTileError(r,e);else{const r=this.Ze(n);e.memorySize=r,this.onTileLoad(t,e)}}Ze(t){let e=0;if(Array.isArray(t))for(let r=0;r<t.length;r++)t[r]&&(e+=this.Ze(t[r]));else t&&(e+=t.getMemorySize());return e}onTileLoad(t,e){this.layer&&(delete this.tilesLoading[e.id],this.layer.onTileLoad(t,e),this.Ke(e),this.setToRedraw(),this.layer.fire("tileload",{node:e}))}onTilesetLoad(t,e,r){this.layer&&(t.capabilities||t.layers&&t.layers[0]&&t.layers[0].capabilities?this.je(t,e,r):(delete this.tilesLoading[e.id],this.layer.onTilesetLoad(t,e,r)))}onTileError(t,e){if(!this.layer)return;const r=e.content.url;console.warn("failed to load 3d tile: "+r),console.warn(t),delete this.tilesLoading[e.id],this.qe(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}qe(e,r){const n={loadTime:t.Util.now(),current:!0,error:r,node:e};this.tileCache.add(e.id,n)}Ke(e){const r={loadTime:t.Util.now(),current:!0,node:e};this.tileCache.add(e.id,r)}abortTileLoading(t){if(!t||!this.workerConn)return;const e=t.node.content.url;if(this.layer.options.services[t.node.xt].ajaxInMainThread){const t=this.Se[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.Se[e]}Le(){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.$e(this.canvas,e)),this.regl=this.regl||l({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 Lr(this.regl,t),this.layer.Qe()}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new jt("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let r=this.layer.options||{};r=y({},r),delete r.offset,r.projection=t.getSpatialReference().getProjection().code;const n=this.layer.getId();e.addLayer(n,r,(t=>{if(t)throw t;this.layer&&(this.ready=!0,this.layer.fire("workerready"))}))}onRemove(){this.painter&&this.painter.remove(),this.pickingFBO&&(this.canvas.pickingFBO||this.pickingFBO.destroy(),delete this.pickingFBO),this.workerConn&&(this.workerConn.removeLayer(this.layer.getId(),(t=>{if(t)throw t})),this.workerConn.remove(),delete this.workerConn),this.clear(),delete this.tileCache,super.onRemove()}clear(){this.Be(!0),this.tileCache.reset(),this.tilesLoading={},super.clear()}clearCanvas(){this.regl&&this.regl.clear({color:[0,0,0,0],depth:1,stencil:0}),super.clearCanvas()}getTileOpacity(){return 1}getStencilValue(){return 0}Be(t){this.Je||(this.Je=Date.now());const e=Date.now();if(t||!(e-this.Je<this.layer.options.retireInterval)){this.Je=e;for(const e in this.tilesLoading){const r=this.tilesLoading[e];!t&&r.current||this.abortTileLoading(r)}}}Pe(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}$e(t,e){const r=["webgl","experimental-webgl"];let n=null;for(let i=0;i<r.length;++i){try{n=t.getContext(r[i],e)}catch(t){}if(n)break}return n}De(t){return!!this.tilesLoading[t]}getI3DMMeshes(){return this.painter.getI3DMMeshes()}getPNTSMeshes(){return this.painter.getPNTSMeshes()}getB3DMMeshes(){return this.painter.getB3DMMeshes()}readBatchData(t,e,r){return Se(t,e,0,r)}xe(){if(!this.tr)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const r=[];for(const n in this.tr){const i=this.tr[n];if("pending"===i.status)continue;i.status="pending";const s=i.rootIdx;if(r.push(gt.getJSON(n).then((t=>{delete this.tr[n];const e=this.Ye[s];if(e){t.nodes?kr(e,t.nodes):(e[t.id]=t,kr(e,t.children));for(let t=0;t<i.length;t++)i[t]();this.setToRedraw()}else this.setToRedraw()}))),e++,e>=t)break}r.length&&Promise.all(r)}Oe(t,e,r){this.tr||(this.tr={}),this.tr[e]=this.tr[e]||[],this.tr[e].rootIdx=t,this.tr[e].push(r),this.setToRedraw()}je(t,e,r){this.Ye||(this.Ye=[]);const n=e.xt;this.Ye[n]||(this.Ye[n]={});const i=this.Ye[n],s=this.layer.options.services[n];t.layers&&(t=t.layers[0],"/"!==r[r.length-1]&&(r+="/"),r+="layers/0"),i.version=+(s.i3sVersion||t.store.version),function(t,e,r,n,i,s){if(!i.layerScene){i.layerScene=t,i.nodesPerPage=t.nodePages&&t.nodePages.nodesPerPage||64,i.lodSelectionMetricType=t.nodePages&&t.nodePages.lodSelectionMetricType;let e=n;if(i.layerScene.eslpk=e.indexOf("3dSceneLayer.json")>=0,e.endsWith(".json")){const t=n.lastIndexOf("/");e=t<0?"./":n.substring(0,t)}i.layerScene.baseUrl=function(t){return t.split("?")[0]}(e)}return new Hr(n,e,i,s).load()}(t,n,0,r,i,this.de).then((t=>{this.onTilesetLoad(t,e,r)}))}pick(t,e,r){return this.painter?this.painter.pick(t,e,r&&r.tolerance):[]}highlight(t){if(this.Ct||(this.Ct=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const r=t[e].service||0;let n=this.Ct[r];n||(n=this.Ct[r]=new Map),n.set(t[e].id,t[e])}else{const e=t.service||0;let r=this.Ct[e];r||(r=this.Ct[e]=new Map),r.set(t.id,t)}this.painter.highlight(this.Ct)}cancelHighlight(t,e){if(!this.Ct)return;const r=this.Ct[t];if(r){if(Array.isArray(e))for(let t=0;t<e.length;t++)r.delete(e[t]);else r.delete(e);this.painter.highlight(this.Ct)}}cancelAllHighlight(){delete this.Ct,this.painter.cancelAllHighlight()}}function Jr(t,e){return t.Ht-e.Ht}function tn(t,e,r){return t[0]=e[r],t[1]=e[r+3],t[2]=e[r+6],t}function en(t,e,r){return Math.sqrt(function(t,e,r){var n=Y(rn,r,t),i=tn(nn,e,0),s=tn(sn,e,1),o=tn(on,e,2),a=J(i),c=J(s),l=J(o);K(i,i),K(s,s),K(o,o);var f=an;f[0]=j(n,i),f[1]=j(n,s),f[2]=j(n,o);var h,u=0;f[0]<-a?u+=(h=f[0]+a)*h:f[0]>a&&(u+=(h=f[0]-a)*h);f[1]<-c?u+=(h=f[1]+c)*h:f[1]>c&&(u+=(h=f[1]-c)*h);f[2]<-l?u+=(h=f[2]+l)*h:f[2]>l&&(u+=(h=f[2]-l)*h);return u}(t,e,r))}const rn=[],nn=[],sn=[],on=[],an=[];const cn=2*Math.PI;class ln{constructor(t,e,r,n){this.west=t,this.south=e,this.east=r,this.north=n}static contains(t,e){var r=e[0],n=e[1],i=t.west,s=t.east;return s<i&&(s+=cn,r<0&&(r+=cn)),(r>i||ye(r,i,1e-14))&&(r<s||ye(r,s,1e-14))&&n>=t.south&&n<=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 fn=[0,0,1];function hn(t,e){return oe(e,t[0],t[1],t[2])}class un{constructor(t,e){this.normal=s.copy([],t),this.distance=e}static fromPointNormal(t,e,r){var n=-s.dot(e,t);return s.copy(r.normal,e),r.distance=n,r}}const _n=[],dn=[],En=[],Tn=[],mn=[],An=[],pn=[],yn=[],gn=[],Rn=[],bn=new un([1,0,0],0),In=[];class Nn{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new ln(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){var r,n,i,o=0;if(!ln.contains(this.rectangle,e)){var a=this.southwestCornerCartesian,c=this.northeastCornerCartesian,l=this.westNormal,f=this.southNormal,h=this.eastNormal,u=this.northNormal,_=s.subtract(In,t,a),d=s.dot(_,l),E=s.dot(_,f),T=s.subtract(In,t,c),m=s.dot(T,h),A=s.dot(T,u);d>0?o+=d*d:m>0&&(o+=m*m),E>0?o+=E*E:A>0&&(o+=A*A)}if(r=e[2],n=this.minimumHeight,r>(i=this.maximumHeight)){var p=r-i;o+=p*p}else if(r<n){var y=n-r;o+=y*y}return Math.sqrt(o)}computeBox(t){const e=this;hn(ln.southwest(t,dn),e.southwestCornerCartesian),hn(ln.northeast(t,dn),e.northeastCornerCartesian),_n[0]=t.west,_n[1]=.5*(t.south+t.north),_n[2]=0;var r=hn(_n,En),n=s.cross(mn,r,fn);s.normalize(e.westNormal,n),_n[0]=t.east;var i=hn(_n,yn),o=s.cross(mn,fn,i);s.normalize(e.eastNormal,o);var a,c=s.subtract(mn,r,i),l=s.normalize(Tn,c),f=t.south;if(f>0){_n[0]=.5*(t.west+t.east),_n[1]=f;var h=hn(_n,gn);s.copy(Rn,l);var u=un.fromPointNormal(e.southwestCornerCartesian,e.westNormal,bn);Sn(gn,Rn,u,e.southwestCornerCartesian),a=me(h,An)}else a=Ae(ln.southeast(t,dn),An);var _=s.cross(pn,a,c);s.normalize(e.southNormal,_);var d,E=t.north;if(E<0){_n[0]=.5*(t.west+t.east),_n[1]=E;var T=hn(_n,gn);s.scale(Rn,l,-1);var m=un.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,bn);Sn(gn,Rn,m,e.northeastCornerCartesian),d=me(T,An)}else d=Ae(ln.northwest(t,dn),An);var A=s.cross(pn,c,d);s.normalize(e.northNormal,A)}}function Sn(t,e,r,n){var i=t,o=e,a=r.normal,c=s.dot(a,o);if(!(Math.abs(c)<1e-15)){var l=(-r.distance-s.dot(a,i))/c;if(!(l<0))return n=s.scale(n,o,l),s.add(n,i,n)}}const wn=new t.Extent(0,0,0,0),On=new t.Extent(0,0,0,0),Mn=[],xn=[],Cn=[],Un=[],vn=new t.Point(0,0),Bn=[],Ln=new t.Coordinate(0,0),Pn=n.identity([]);class Dn extends t.Layer{constructor(t,e){super(t,e),this.er(),this.Se={},this.rr=[]}er(){let t=this.options.services.map((t=>t.url));this.nr=t.map(((t,e)=>function(t,e){t=N(t);return{visible:1,baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:n.identity([]),xt:e,vt:0}}(t,e))),this.fire("rootready",{roots:this.nr.slice(0)})}showService(t){return this.ir(t,1),this}hideService(t){return this.ir(t,0),this}ir(t,e){const r=this.nr[t];if(!r)return;r.visible=e;const n=this.getRenderer();n&&n.setToRedraw()}getTileUrl(t){return t}getExtent(e){if(!e&&0!==e){const e=new t.Extent;for(let t=0;t<this.nr.length;t++)if(this.nr[t].boundingVolume){const r=this.boundingVolumeToExtent(this.nr[t]);e._combine(r)}return e}return this.nr[e]&&this.nr[e].boundingVolume?this.boundingVolumeToExtent(this.nr[e]):null}boundingVolumeToExtent(e){const r=e.boundingVolume.sr?Pn:e.matrix,n=this.getMap();if(e.boundingVolume.region){const r=e.boundingVolume.region;return new t.Extent(I(r[0]),I(r[1]),I(r[2]),I(r[3]))}if(e.boundingVolume.sphere){const i=e.boundingVolume.sphere,o=ue([],s.transformMat4([],i,r)),a=i[3],c=n.locate(o,-a,a),l=n.locate(o,a,-a);return new t.Extent(c,l)}if(e.boundingVolume.box){const i=e.boundingVolume.box,a=s.transformMat4([],i,r),c=new t.Coordinate(ue([],a)),l=i.slice(3);o.multiply(l,o.fromMat4([],e.matrix),l);const f=s.length(l.slice(0,3)),h=s.length(l.slice(3,6)),u=s.length(l.slice(6,9)),_=Math.max(f,h,u),d=n.locate(c,-_,_),E=n.locate(c,_,-_);return new t.Extent(d,E)}return null}getRootTiles(){return this.nr}getTiles(){const t=this.getRenderer();if(!t.ready)return this.ar(),{tiles:Un};const e=this.getMap(),r=e.cameraPosition;let n,i;if(e.getGLZoom)i=e.pointToDistance(r[2],0,e.getGLZoom()),Ln.set(r[0],r[1]),n=e.pointToCoord(Ln,e.getGLZoom());else{const t=e.getGLRes();i=e.pointAtResToDistance(r[2],0,t),Ln.set(r[0],r[1]),n=e.pointAtResToCoord(Ln,t)}this.cr=this.cr||[],s.set(this.cr,b(n.x),b(n.y),i),this.lr=oe(this.lr||[],this.cr[0],this.cr[1],this.cr[2]),this.hr=2*Math.tan(.5*b(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const l=[];for(let e=0;e<this.nr.length;e++){const r=this.nr[e];if(!r.visible)continue;let n=1/0;const i=[r],s=this.ur(e);for(;i.length>0;){const e=i.pop();for(e.id||this._r(e);c.level>=e.vt;)c=c.parent;const r=this.dr(e,s,o);if(r<1){let t=c;for(;t&&!t.content;)t=t.parent;0===r&&t&&t.content&&this.Er(l,t);if(!1===this.options.services[e.xt].alwaysShow)continue;if(!(0===r&&e.vt<=n))continue;e.content&&(n=e.vt)}e.Ht<1/0&&this.Tr(e);const a=this.ze(e,c);c.children.push(a);const f=e.children,h=f&&f.length,u=a.content;if(!h&&u&&this.Er(l,a),h){u&&"add"===e.refine&&this.Er(l,a),c=a;const r=f[0].parent;let n=!1;for(let s=0,o=f.length;s<o;s++){if(r){const e=t.getCachedTile(f[s].id);if(e&&e.error&&404!==e.error.status)continue;n=!0}else{n=!0,f[s].parent=e,f[s].te=e.te,f[s].baseUrl=e.baseUrl;const t=f[s].content&&(f[s].content.url||f[s].content.uri);t&&(U(t)||t.indexOf("i3s:")>=0?f[s].baseUrl=e.baseUrl:-1===t.indexOf("http://")&&-1===t.indexOf("https://")?f[s].content.url=e.baseUrl+t:f[s].baseUrl=t.substring(0,t.lastIndexOf("/")+1))}i.push(f[s])}!n&&u&&this.Er(l,a)}}}return{root:a,tiles:l}}Er(t,e){const{viewerRequestVolume:r}=e.node;r&&!function(t,e,r){if(r.region){const e=r.region;if(t[0]>=e[0]&&t[0]<=e[2]&&t[1]>=e[1]&&t[1]<=e[3])return!0}else{if(r.sphere)return Fn(r,e);if(r.box)return 0===kn(r,e)}return!1}(this.cr,this.lr,r)||t.push(e)}ze(t,e){return{id:t.id,node:t,children:[],level:t.vt,parent:e,content:t.content&&t.content.url}}_r(e){e.id=t.Util.GUID(),e.matrix=e.transform||n.identity([]),e.mr=this.Ar(e),e.parent&&(function(t){return t.content&&t.content.uri&&t.content.uri.indexOf("i3s:")>=0}(e)||(e.matrix=n.multiply(e.matrix,e.parent.matrix,e.matrix)),e.xt=e.parent.xt,void 0===e.vt&&(e.vt=e.parent.vt+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),this.pr(e)}pr(t){const e=t.boundingVolume;if(!e||e.sr)return;const r=this.options.services[t.xt].heightOffset||0,i=this.options.offset,o=g(i)||i[0]||i[1];if(!t.boundingVolume||!r&&n.exactEquals(t.matrix,Pn)&&!o)return;const{region:a,box:c,sphere:l}=e;if(a){const t=this.yr([I(a[0]),I(a[1])]);a[0]=b(t.x),a[1]=b(t.y);const e=this.yr([I(a[2]),I(a[3])]);a[2]=b(e.x),a[3]=b(e.y),a[4]+=r,a[5]+=r}else if(c||l){const e=c||l,n=s.transformMat4(Mn,e,t.matrix),i=ue(xn,n),o=this.yr([i[0],i[1]]);i[0]=o.x,i[1]=o.y,i[2]+=r,oe(e,b(i[0]),b(i[1]),i[2])}e.sr=!0}Ar(t){return void 0===t.geometricError||!t.boundingVolume}Tr(t){let e=t.parent;for(;e&&e.mr&&!(e.Ht<=t.Ht);)e.Ht=t.Ht,e=t.parent}onTileLoad(t,e){if(t.children&&(!e.children||!e.children.length)){e.children=t.children;const r=e.content.url;e.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const n=this.getRenderer();n&&n.setToRedraw()}}onTilesetLoad(t,e,r){if(!t)return void console.warn("invalid tileset at : "+r);const i=this.options.services[e.xt],s=(t.asset&&t.asset.gltfUpAxis||e&&e.te||i.upAxis||"Y").toUpperCase();t.root.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const o=r.indexOf("realspace/")>-1;0===e.vt&&(t.asset&&t.asset.s3mType&&o||i.isSuperMapiServer)&&(t.root.baseUrl+="data/path/");const a=t.asset.i3s;if(t.root.te=s,e){const r=e.boundingVolume;y(e,t.root),e.refine=e.refine&&e.refine.toLowerCase()||"replace",r&&(e.boundingVolume=r);const i=t.root.transform;i&&(e.parent?a||(e.matrix=n.multiply([],e.parent.matrix,i)):e.matrix=i),this.pr(e),e.gr=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.mr=this.Ar(e);const s=e.content&&(e.content.url||e.content.uri);s&&e.content.uri&&(e.content.url=e.content.uri,delete e.content.uri),a||!s||U(s)||-1!==s.indexOf("http://")||-1!==s.indexOf("https://")||(e.content.url=e.baseUrl+s)}this.ar(),this.fire("loadtileset",{tileset:t,index:e.xt,url:r})}dr(t,e,r){if(t.Ht=1/0,0===t.vt||t.mr)return 1;if(!this.Rr(t,e,r))return-1;if(0===t.geometricError)return 1;let n=this.options.services[t.xt].maximumScreenSpaceError;null==n&&(n=8);let i=this.br(t);return 0===i&&t.parent&&(i=.5*(t.parent.Fe||0)),i>=n?1:0}Kt(e,r){r||(r=new t.Point(0,0));const n=this.getMap();return n.getGLZoom?n.coordToPoint(e,n.getGLZoom(),r):n.coordToPointAtRes(e,n.getGLRes(),r)}Rr(e,r,i){const a=e.id;let c=this.rr[a];const{boundingVolume:l}=e,f=l.sphere;let u=l.region;const _=l.box;if(!c){let r,i,h;if(_&&(u=function(t,e){for(let e=0;e<9;e++)jn[e]=t[e+3];const r=jn;n.exactEquals(e,Pn)||o.multiply(r,o.fromMat4(Bn,e),r);const i=s.copy(Gn,t),a=s.set(Hn,r[0],r[1],r[2]),c=s.set(Vn,r[3],r[4],r[5]),l=s.set(zn,r[6],r[7],r[8]);Xn[0]=Xn[0]||[];const f=s.copy(Xn[0],i);s.sub(f,f,a),s.sub(f,f,c),s.sub(f,f,l),Xn[1]=Xn[1]||[];const h=s.copy(Xn[1],i);s.sub(h,h,a),s.sub(h,h,c),s.add(h,h,l),Xn[2]=Xn[2]||[];const u=s.copy(Xn[2],i);s.sub(u,u,a),s.add(u,u,c),s.sub(u,u,l),Xn[3]=Xn[3]||[];const _=s.copy(Xn[3],i);s.sub(_,_,a),s.add(_,_,c),s.add(_,_,l),Xn[4]=Xn[4]||[];const d=s.copy(Xn[4],i);s.add(d,d,a),s.sub(d,d,c),s.sub(d,d,l),Xn[5]=Xn[5]||[];const E=s.copy(Xn[5],i);s.add(E,E,a),s.sub(E,E,c),s.add(E,E,l),Xn[6]=Xn[6]||[];const T=s.copy(Xn[6],i);s.add(T,T,a),s.add(T,T,c),s.sub(T,T,l),Xn[7]=Xn[7]||[];const m=s.copy(Xn[7],i);s.add(m,m,a),s.add(m,m,c),s.add(m,m,l);for(let t=0;t<Xn.length;t++)Yn[t]=Yn[t]||[],ue(Yn[t],Xn[t]),Wn[t]=Yn[t][0],Zn[t]=Yn[t][1],Kn[t]=Yn[t][2];return[b(Math.min(...Wn)),b(Math.min(...Zn)),b(Math.max(...Wn)),b(Math.max(...Zn)),Math.min(...Kn),Math.max(...Kn)]}(_,e.matrix),l.region=u),u){r=wn.set(I(u[0]),I(u[1]),I(u[2]),I(u[3]));const t=r.getCenter(),e=this.Ir(t);r=r.convertTo((t=>this.Kt(t,vn)),On),h=u[4],i=u[5],c=this.rr[a]=[[r.xmin,r.ymin,h*e[2]],[r.xmax,r.ymax,i*e[2]]],c.center=t}else if(f){const e=ue(Mn,f),r=new t.Coordinate(e),n=this.Kt(r,vn).toArray(),i=this.Ir(r);n.push(e[2]*i[2]),c=this.rr[a]=[n,f[3]*i[2]],c.center=r}}if(r){if(u)wn.xmin=c[0][0],wn.ymin=c[0][1],wn.xmax=c[1][0],wn.ymax=c[1][1];else if(f){const t=c[2];wn.xmin=c[0][0]-t,wn.ymin=c[0][1]-t,wn.xmax=c[0][0]+t,wn.ymax=c[0][1]+t}else if(_){const t=c[1],e=c[2];wn.xmin=c[0][0]-t,wn.ymin=c[0][1]-e,wn.xmax=c[0][0]+t,wn.ymax=c[0][1]+e}if(!r.intersects(wn))return!1}return u?d(i,c):f?function(t,e,r){T(t);for(var n=e[0],i=-e[1],s=0;s<6;s++)if((!r||"0"!==r.charAt(s))&&A(h[s],n)<i)return!1;return!0}(i,c):!!_&&function(t,e,r){T(t);for(var n=0;n<6;n++)if(!(r&&"0"===r.charAt(n)||E(h[n],e)))return!1;return!0}(i,c)}Ir(t){const e=this.getMap(),r=e.distanceToPointAtRes(100,100,e.getGLRes(),t);let n;return n=e.altitudeToPoint?e.altitudeToPoint(100,e.getGLRes())/100:r.y/100,s.set(Cn,r.x/100*1.01,r.y/100*1.01,n),Cn}yr(e){Array.isArray(e)&&(e=new t.Coordinate(e));let r=this.options.offset;if(g(r)&&(r=r(Array.isArray(e)?new t.Coordinate(e):e)),r[0]||r[1]){const t=this.getMap(),n=t.getGLRes(),i=t.coordToPointAtRes(e,n);return i._sub(r),t.pointAtResToCoord(i,n)}return e}ur(e){const r=this.options.services[e].maxExtent;if(!r)return null;const n=this.nr[e];return n.maxExtent||(n.maxExtent=new t.Extent(r).convertTo((t=>this.Kt(t)))),n.maxExtent}br(t){const e=this.hr,r=t.geometricError;if(0===r)return t.Fe=0,0;const n=this.getMap();let i;t.boundingVolume.region?i=function(t,e,r){t.Nr||(t.Nr=new Nn(t.boundingVolume.region));return t.Nr.distanceToCamera(e,r)}(t,this.lr,this.cr):t.boundingVolume.sphere?i=Fn(t.boundingVolume,this.lr):t.boundingVolume.box&&(i=kn(t.boundingVolume,this.lr));const s=Math.max(Math.abs(i),1e-7),o=r*n.height/(s*e);return t.Ht=i,t.Fe=o,o}ar(){const t=this.getRenderer();t&&t.setToRedraw()}se(t){return this.rr[t]}identify(e,r={}){const n=this.getMap(),i=this.getRenderer();if(!n||!i)return[];const s=n.coordToContainerPoint(new t.Coordinate(e));return this.identifyAtPoint(s,r)}identifyAtPoint(t,e={}){const r=this.getMap(),n=this.getRenderer();if(!r||!n)return[];const i=r.getDevicePixelRatio();return n.pick(t.x*i,t.y*i,e)}highlight(t){const e=this.getRenderer();return e?(e.highlight(t),this):(this.Ct||(this.Ct=[]),this.Ct.push(t),this)}Qe(){if(this.Ct){for(let t=0;t<this.Ct.length;t++)this.highlight(this.Ct[t]);delete this.Ct}}cancelHighlight(t,e){const r=this.getRenderer();return r?(r.cancelHighlight(t,e),this):this}cancelAllHighlight(){const t=this.getRenderer();return t?(t.cancelAllHighlight(),this):this}}function Fn(t,e){const r=t.sphere,n=s.dist(r,e),i=t.sphere[3];return n<i?0:n-i}function kn(t,e){const r=t.box;return en(s.set(Mn,r[0],r[1],r[2]),o.set(Bn,r[3],r[4],r[5],r[6],r[7],r[8],r[9],r[10],r[11]),e)}Dn.mergeOptions({"maxGPUMemory":512,"retireInterval":2e3,"loadingLimitOnInteracting":5,"loadingLimit":0,"renderer":"gl","forceRenderOnZooming":!0,"forceRenderOnRotating":!0,"forceRenderOnMoving":!0,"debug":!1,"debugOutline":[0,1,0],"meshLimitPerFrame":1,"i3sNodepageLimitPerFrame":1,"enableI3SCompressedGeometry":!0,"forceI3SCompressedGeometry":!0,"picking":!0,"pickingPoint":!0,"geometryEvents":!1,"antialias":!1,"optionalExtensions":["ANGLE_instanced_arrays","OES_element_index_uint","OES_standard_derivatives","OES_vertex_array_object","OES_texture_half_float","OES_texture_half_float_linear","OES_texture_float","OES_texture_float_linear","WEBGL_depth_texture","EXT_shader_texture_lod","WEBGL_compressed_texture_astc","WEBGL_compressed_texture_etc","WEBGL_compressed_texture_etc1","WEBGL_compressed_texture_pvrtc","WEBGL_compressed_texture_s3tc","WEBGL_compressed_texture_s3tc_srgb"],"offset":[0,0]}),Dn.registerRenderer("gl",Qr),Dn.registerJSONType("Geo3DTilesLayer");const Gn=[],Hn=[],Vn=[],zn=[],Xn=[],Yn=[],Wn=[],Zn=[],Kn=[],jn=[];class qn{constructor(t,e,r){this.i=t,this.Sr=e||Ht,this.o=r,this.wr={"image/crn":Fr.crn&&Fr.crn(),"image/ktx2":Fr.ktx2&&Fr.ktx2(),"image/cttf":Fr.ktx2&&Fr.ktx2(),"draco":Fr.draco&&Fr.draco()}}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.Or(t,e,r,n,i)):gt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Or(t,i,r,n)}))}Or(t,e,r,n,i){const s=i&&i.maxTextureSize,o=this.Mr(e,r,n,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.Sr(a,o.glb,{transferable:!0,requestImage:this.i,decoders:this.wr,supportedFormats:this.o,maxTextureSize:s});return c.load({skipAttributeTransform:!1}).then((e=>{e.url=`${t}-${r}-${n}`;const i=c.transferables;for(let t=0;t<o.transferables.length;t++)i.indexOf(o.transferables[t])<0&&i.push(o.transferables[t]);return{magic:"b3dm",count:o.count,transferables:i,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,gltf:e}}))}Mr(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported b3dm version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in b3dm header is inconsistent with b3dm's byte length, url: "+n;return console.warn(t),{error:t}}let o,a=i.getUint32(12,!0),c=i.getUint32(16,!0),l=i.getUint32(20,!0),f=i.getUint32(24,!0),h=28+e;l>=570425344?(h-=8,o=a,l=c,f=0,a=0,c=0):f>=570425344&&(h-=4,o=l,l=a,f=c,a=0,c=0);const u=[t];let _,d,E;if(a>0?(_=be(t,h,a),h+=a,o=_.BATCH_LENGTH):_={"BATCH_LENGTH":o},c>0&&(h+=c),l>0&&(d=Ie(t,h,l),h+=l,f>0)){const e=Ne(0,h,f);E=t.slice(e.offset,e.offset+e.byteLength),h+=f,u.push(E)}const T=_.BATCH_LENGTH,m={};if(_&&_.BATCH_ID){m.BATCH_ID=we(_.BATCH_ID,t,undefined.offset,T);const e=m.BATCH_ID.array&&m.BATCH_ID.array.buffer;e&&u.indexOf(e)<0&&u.push(e)}return{count:o,transferables:u,featureTable:_,batchTable:d,batchTableBin:E,b3dm:m,glb:{buffer:t,byteOffset:h,byteLength:i.byteLength+i.byteOffset-h}}}Cr(){return null}}class $n{constructor(t,e,r,n){this.i=t,this.Sr=e||Ht,this.o=r,this.wr={"image/crn":Fr.crn&&Fr.crn(),"image/ktx2":Fr.ktx2&&Fr.ktx2(),"image/cttf":Fr.ktx2&&Fr.ktx2(),"draco":Fr.draco&&Fr.draco()},this.Ur=n}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.Or(t,e,r,n,i)):gt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Or(t,i,r,n)}))}Or(t,e,r,n,i){return this.vr(t,e,r,n,i).then((({gltf:i,transferables:s})=>{const o=this.Br(e,r,n,t);if(o.error)return Promise.resolve(o);for(let t=0;t<s.length;t++)-1===o.transferables.indexOf(s[t])&&o.transferables.push(s[t]);return delete i.transferables,Promise.resolve({magic:"i3dm",count:o.count,transferables:o.transferables,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,i3dm:o.i3dm,gltf:i})}))}vr(t,e,r,n,i){const s=i&&i.maxTextureSize,o={transferable:!0,requestImage:this.i,decoders:this.wr,supportedFormats:this.o,maxTextureSize:s},a=new DataView(e,r,n),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 n=O(new Uint8Array(e,c+r,a.byteLength-c));-1==n.indexOf("://")&&(n=t.substring(0,t.lastIndexOf("/"))+"/"+n);return n.indexOf(".glb")>0?gt.getArrayBuffer(n,{}).then((t=>this.Lr(n,{buffer:t.data,byteOffset:0},o))):gt.getJSON(n,{}).then((t=>this.Lr(n,t,o)))}{const n={buffer:e,byteOffset:c+r,byteLength:a.byteLength-c};return this.Lr(t,n,o)}}Lr(t,e,r){const n=t.substring(0,t.lastIndexOf("/")),i=new this.Sr(n,e,r);return i.load({skipAttributeTransform:!0}).then((r=>{let n=0,s=0;return e.buffer&&(n=e.byteOffset||0,s=e.byteLength||0),r.url=`${t}-${n}-${s}`,{transferables:i.transferables,gltf:r}}))}Br(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported pnts version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+n;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:l,batchTableBin:f}=Le(i,32+e,o),h={},u=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;h.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,r=a.QUANTIZED_VOLUME_SCALE,{byteOffset:n}=a.POSITION_QUANTIZED;h.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:u,componentType:5126,array:this.Pr(new Uint16Array(t,n+c.offset,3*u),e,r)},o.push(h.POSITION.array.buffer)}if(a.BATCH_ID){h.BATCH_ID=we(a.BATCH_ID,t,c.offset,u);const e=h.BATCH_ID.array&&h.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;h.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,h.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;h.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:this.Dr(new Uint16Array(t,e+c.offset,2*u))},o.push(h.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,h.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:this.Dr(new Uint16Array(t,e+c.offset,2*u))},o.push(h.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;h.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,u).slice()},o.push(h.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;h.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.SCALE_NON_UNIFORM.array.buffer)}return{count:u,batchTable:l,batchTableBin:f,featureTable:a,i3dm:h,transferables:o}}Dr(t){const e=t.length/2,r=new Float32Array(3*e),n=[];for(let i=0;i<e;i++)Qn(n,t[2*i],t[2*i+1],65535),r[3*i]=n[0],r[3*i+1]=n[1],r[3*i+2]=n[2];return r}Pr(t,e,r){return Be(new Float32Array(t.length),t,e,r)}Cr(){return null}}function Qn(t,e,r,n){if(t[0]=Jn(e,n),t[1]=Jn(r,n),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]))*ti(e),t[1]=(1-Math.abs(e))*ti(t[1])}return K(t,t)}function Jn(t,e){return function(t,e,r){return t<e?e:t>r?r:t}(t,0,e=function(t,e){if(null!=t)return t;return e}(e,255))/e*2-1}function ti(t){return t<0?-1:1}class ei{constructor(){}load(t,e,r=0,n=0){return e?(n||(n=e.byteLength),this.Or(t,e,r,n)):gt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Or(t,i,r,n)}))}Or(t,e,r,n){return this.Fr(e,r,n,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}))}Fr(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported pnts version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+n;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:l,batchTableBin:f}=Le(i,e+28,o),h=a.QUANTIZED_VOLUME_OFFSET,u=a.QUANTIZED_VOLUME_SCALE,_=a.POINTS_LENGTH;let d,E={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){E=a.extensions["3DTILES_draco_point_compression"],d=new DataView(t,E.byteOffset+c.offset,E.byteLength);const e={attributes:E.properties,useUniqueIDs:!1};return this.kr||(this.kr=Fr.draco()),this.kr(d,e).then((e=>{const r=e.attributes;!a.POSITION&&!a.POSITION_QUANTIZED||r.POSITION||r.POSITION_QUANTIZED||(r.POSITION=a.POSITION,r.POSITION_QUANTIZED=a.POSITION_QUANTIZED),!(a.RGB||a.RGBA||a.RGB565)||r.RGB||r.RGBA||r.RGB565||(r.RGB=a.RGB,r.RGBA=a.RGBA,r.RGB565=a.RGB565),!a.NORMAL&&!a.NORMAL_OCT16P||r.NORMAL||r.NORMAL_OCT16P||(r.NORMAL=a.NORMAL,r.NORMAL_OCT16P=a.NORMAL_OCT16P);const n=this.Gr(t,e.attributes,c.offset,_,o,h,u);if(e.attributes.BATCH_ID){const t=e.attributes.BATCH_ID.array;n.BATCH_ID={byteStride:0,byteOffset:0,itemSize:1,count:t.length,componentType:ve(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?n.BATCH_ID=we(a.BATCH_ID,t,c.offset,_):n.BATCH_ID=ri(_);const e=n.BATCH_ID.array&&n.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return{count:_,batchTable:l,batchTableBin:f,featureTable:a,pnts:n,transferables:o}}))}const T=this.Gr(t,a,c.offset,_,o,h,u);if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?T.BATCH_ID=we(a.BATCH_ID,t,c.offset,_):T.BATCH_ID=ri(_);const e=T.BATCH_ID.array&&T.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:_,batchTable:l,batchTableBin:f,featureTable:a,pnts:T,transferables:o})}Gr(t,e,r,n,i,s,o){const a={};if(e.POSITION){let{byteOffset:s,array:o}=e.POSITION;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n*4);o=new Float32Array(e)}a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:o},i.push(o.buffer)}else if(e.POSITION_QUANTIZED){let{byteOffset:c,array:l}=e.POSITION_QUANTIZED;c=c||0;const f=l?0:r;a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:this.Pr(l||new Uint16Array(t,c+f,3*n),s,o)},i.push(a.POSITION.array.buffer)}if(e.RGBA){let{byteOffset:s,array:o}=e.RGBA;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+4*n);o=new Uint8Array(e)}a.RGBA={byteStride:0,byteOffset:0,itemSize:4,count:n,componentType:5121,array:o},i.push(o.buffer)}else if(e.RGB){let{byteOffset:s,array:o}=e.RGB;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n);o=new Uint8Array(e)}a.RGB={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5121,array:o},i.push(o.buffer)}else if(e.RGB565){let{byteOffset:s,array:o}=e.RGB565;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+2*n);o=new Uint16Array(e)}a.RGB565={byteStride:0,byteOffset:0,itemSize:1,count:n,componentType:5123,array:o},i.push(o.buffer)}if(e.NORMAL){let{byteOffset:s,array:o}=e.NORMAL;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n*4);o=new Float32Array(e)}a.NORMAL={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:o},i.push(o.buffer)}else if(e.NORMAL_OCT16P){let{byteOffset:s,array:o}=e.NORMAL_OCT16P;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+2*n);o=new Uint8Array(e)}a.NORMAL_OCT16P={byteStride:0,byteOffset:0,itemSize:2,count:n,componentType:5121,array:o},i.push(o.buffer)}return a}Pr(t,e,r){return Be(new Float32Array(t.length),t,e,r)}Cr(){return null}}function ri(t){const e=C(t),r=new e(t);for(let e=0;e<t;e++)r[e]=e;return{byteStride:0,byteOffset:0,itemSize:1,count:t,componentType:ve(e),array:r}}class ni{constructor(t,e){this.i=t,this.Sr=e||Ht}load(t,e,r=0,n=0,i){return e?this.Or(t,e,r,n,i):gt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return this.Or(t,i,r,n)}))}Or(t,e,r,n,i){n||(n=e.byteLength);const s=this.Hr(e,t,r,n),o=[];for(let r=0;r<s.length;r++){let n;if("b3dm"===s[r].magic)n=new qn(this.i,this.Sr);else if("i3dm"===s[r].magic)n=new $n(this.i,this.Sr);else if("pnts"===s[r].magic)n=new ei;else{if("cmpt"!==s[r].magic){console.warn("Unsupported magic in CMPT tile:",s[r].magic);continue}n=new ni(this.i,this.Sr)}o.push(n.load(t,e,s[r].offset,s[r].byteLength,i).then((t=>t)))}return Promise.all(o).then((t=>({magic:"cmpt",tiles:t})))}Hr(t,e,r,n){const i=new DataView(t,r,n),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported cmpt version: "+s+", url:"+e;return console.warn(t),{error:t}}if(16===i.byteLength)return[];const o=[],a=i.getUint32(12,!0);let c=16;for(let e=0;e<a;e++){const e=ge(i,c),n=i.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+r,byteLength:n}),c+=n}return o}}if(e.transcoders){const r=t.Map.VERSION;if(r.indexOf("1.0.0-beta")>=0||r.indexOf("1.0.0-alpha")>=0){const r=e.transcoders.inject(f);t.registerWorkerAdapter("@maptalks/3dtiles",r)}else t.registerWorkerAdapter("@maptalks/3dtiles",(function(){return e.transcoders.inject(f)}))}else t.registerWorkerAdapter("@maptalks/3dtiles",f);export{qn as B3DMLoader,ni as CMPTLoader,Dn as Geo3DTilesLayer,L as Geo3DTilesUtil,pe as Geo3DTransform};"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.21.0");
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @maptalks/3dtiles v0.20.0
2
+ * @maptalks/3dtiles v0.21.0
3
3
  * LICENSE : UNLICENSED
4
4
  * (c) 2016-2022 maptalks.org
5
5
  */
@@ -20,4 +20,4 @@ let rt=0;function nt(t){return null==t}function it(t){return!nt(t)}function st(t
20
20
  * @maptalks/gl v0.78.0
21
21
  * LICENSE : UNLICENSED
22
22
  * (c) 2016-2022 maptalks.com
23
- */(s,a)),c.generateBuffers(this.nt,{excludeElementsInVAO:e}),c}se(t,e,n,i){const s=r.mat4.identity(t),o=this.getMap();Nr.x=n[0],Nr.y=n[1];const a=this._prjToPoint(Nr),c=this.ue(),l=1/(o.getGLZoom?o.getResolution(o.getGLZoom()):o.getGLRes());let f;Nr.x=e[0],Nr.y=e[1],f=o.altitudeToPoint?this.St:o.distanceToPointAtRes(100,100,o.getGLRes(),Nr).y/100;let h=this.tt.options.offset;m(h)&&(h=h(Nr));const u=this.tt.options.services[i].heightOffset||0;return r.vec3.set(Or,a.x-h[0],a.y-h[1],f*n[2]+f*u),r.mat4.translate(s,s,Or),r.vec3.set(c,l,l,f),r.mat4.scale(s,s,c),s}Qt(t,e){const n=r.mat4.identity(t),i=this.getMap(),s=this.ue();Nr.x=e[0],Nr.y=e[1];const o=i.distanceToPointAtRes(100,100,i.getGLRes(),Nr);let a;return a=i.altitudeToPoint?this.St:o.y/100,r.vec3.set(s,o.x/100*1.01,o.y/100*1.01,a),r.mat4.scale(n,n,s),n}bt(){const t={x:0,y:0,width:()=>this.et?this.et.width:1,height:()=>this.et?this.et.height:1};this.Xt=new r.reshader.MeshShader({vert:"attribute vec3 aPosition;\n\n\n\nuniform mat4 projViewModelMatrix;\n\n\n\nvoid main() {\n\n gl_Position = projViewModelMatrix * vec4(aPosition, 1.0);\n\n}\n\n",frag:"precision mediump float;\nuniform vec3 color;\nvoid main() {\n gl_FragColor = vec4(color, 1.0);\n}\n",uniforms:["color",{name:"projViewModelMatrix",type:"function",fn:(t,e)=>r.mat4.multiply([],e.projViewMatrix,e.modelMatrix)}],extraCommandProps:{viewport:t}});const e=[],n=[];this.Gt=new r.reshader.MeshShader({vert:"const float SHIFT_RIGHT_11 = 1.0 / 2048.0;\n\nconst float SHIFT_RIGHT_5 = 1.0 / 32.0;\n\nconst float SHIFT_LEFT_11 = 2048.0;\n\nconst float SHIFT_LEFT_5 = 32.0;\n\nconst float NORMALIZE_6 = 1.0 / 64.0;\n\nconst float NORMALIZE_5 = 1.0 / 32.0;\n\n\n\n#ifdef HAS_POSITION\n\n attribute vec3 POSITION;\n\n#endif\n\n\n\n#if defined(HAS_RGB)\n\n attribute vec3 RGB;\n\n#elif defined(HAS_RGBA)\n\n attribute vec4 RGBA;\n\n#elif defined(HAS_RGB565)\n\n attribute float RGB565;\n\n#endif\n\n\n\nuniform vec4 pointColor;\n\nuniform float pointSize;\n\n\n\nuniform mat4 projViewModelMatrix;\n\nuniform float pointOpacity;\n\n\n\nvarying vec4 vColor;\n\n\n\n#ifdef HAS_NORMAL\n\n #ifdef HAS_NORMAL_OCT16P\n\n attribute vec2 NORMAL_OCT16P;\n\n float signNotZero(float value) {\n\n return value >= 0.0 ? 1.0 : -1.0;\n\n }\n\n vec2 signNotZero(vec2 value) {\n\n return vec2(signNotZero(value.x), signNotZero(value.y));\n\n }\n\n vec3 octDecode(vec2 encoded, float range) {\n\n if (encoded.x == 0.0 && encoded.y == 0.0) {\n\n return vec3(0.0, 0.0, 0.0);\n\n }\n\n encoded = encoded / range * 2.0 - 1.0;\n\n vec3 v = vec3(encoded.x, encoded.y, 1.0 - abs(encoded.x) - abs(encoded.y));\n\n if (v.z < 0.0) {\n\n v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);\n\n }\n\n return normalize(v);\n\n }\n\n vec3 octDecode(vec2 encoded) {\n\n return octDecode(encoded, 255.0);\n\n }\n\n #else\n\n attribute vec3 NORMAL;\n\n #endif\n\n uniform vec3 lightDir;\n\n uniform mat3 modelNormalMatrix;\n\n uniform mat4 positionMatrix;\n\n float getLambertDiffuse(vec3 lightDir, vec3 normal) {\n\n return max(dot(-lightDir, normal), 0.0);\n\n }\n\n#endif\n\n\n\nvoid main() {\n\n #if defined(HAS_RGB)\n\n vColor = vec4(RGB / 255.0, 1.0) * pointOpacity;\n\n #elif defined(HAS_RGBA)\n\n vColor = RGBA / 255.0 * pointOpacity;\n\n #elif defined(HAS_RGB565)\n\n float compressed = RGB565;\n\n float r = floor(compressed * SHIFT_RIGHT_11);\n\n compressed -= r * SHIFT_LEFT_11;\n\n float g = floor(compressed * SHIFT_RIGHT_5);\n\n compressed -= g * SHIFT_LEFT_5;\n\n float b = compressed;\n\n vec3 rgb = vec3(r * NORMALIZE_5, g * NORMALIZE_6, b * NORMALIZE_5);\n\n vColor = vec4(rgb, 1.0);\n\n #else\n\n vColor = pointColor;\n\n #endif\n\n\n\n #ifdef HAS_POSITION\n\n vec3 localPos = POSITION;\n\n #endif\n\n\n\n #ifdef HAS_NORMAL\n\n mat3 positionNormalMatrix = mat3(positionMatrix);\n\n mat3 normalMatrix = modelNormalMatrix * positionNormalMatrix;\n\n #ifdef HAS_NORMAL_OCT16P\n\n vec3 localNormal = octDecode(NORMAL_OCT16P);\n\n #else\n\n vec3 localNormal = NORMAL;\n\n #endif\n\n vec3 normal = normalize(normalMatrix * localNormal);\n\n float colorStrength = getLambertDiffuse(lightDir, normal);\n\n colorStrength = max(colorStrength, 0.5);\n\n vColor *= colorStrength;\n\n #endif\n\n\n\n gl_Position = projViewModelMatrix * vec4(localPos, 1.0);\n\n gl_PointSize = pointSize;\n\n}\n\n",frag:"#define SHADER_NAME PNTS\n\nprecision mediump float;\n\n\n\nvarying vec4 vColor;\n\n\n\nvoid main() {\n\n gl_FragColor = vColor;\n\n}\n\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:(t,e)=>r.mat4.multiply(n,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,n)=>r.mat3.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.Nt();this.Dt=new r.reshader.PhongShader({extraCommandProps:i}),this.Ft=new r.reshader.pbr.StandardShader({extraCommandProps:i});const s=this.tt;_r(s.getRenderer().canvas,this.nt,s.getMap()),this.picking=new r.reshader.FBORayPicking(this.it,{vert:this.Ft.vert,extraCommandProps:i,uniforms:this.Ft.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap())}Nt(){return{viewport:{x:0,y:0,width:()=>this.et?this.et.width:1,height:()=>this.et?this.et.height:1},colorMask:(t,e)=>e.colorMask||br,cull:{enable:!0,face:(t,e)=>e.cullFace||"back"},stencil:{enable:(t,e)=>!0===e.stencilEnable,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}}}Yt(t){return{projViewMatrix:this.getMap().projViewMatrix,color:t&&t.color||[0,1,0]}}kt(t){const e=this.getMap(),n=e.getLightManager(),i=(n&&n.getDirectionalLight()||{}).direction||[1,1,-1],s=t&&t.pointOpacity||1;return{projViewMatrix:e.projViewMatrix,pointOpacity:s,lightDir:r.vec3.normalize(i,i)}}Ot(){const t=this.getMap(),e=this.tt.getRenderer().canvas,{iblTexes:r,dfgLUT:n}=Er(e),i=Tr(t,r,n);return T(i,{czm_lightDirectionEC:i.light0_viewDirection,lightSpecular:[1,1,1],viewMatrix:t.viewMatrix,projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,outSize:[e.width,e.height],polygonFill:[1,1,1,1],polygonOpacity:1}),i}fe(t,e,n,i){const s=e.materials[t];if(!s||!s.baseColorTexture&&!s.pbrMetallicRoughness)return null;const o=T({},i);if(s.baseColorTexture){const t=e.textures[s.baseColorTexture.index];let r;t&&!t.image.color&&(r=this.O(t)),o.baseColorFactor=t&&t.image.color||s.baseColorFactor||[1,1,1,1],r&&(o.baseColorTexture=r)}else{if(s.normalTexture){const t=this.O(e.textures[s.normalTexture.index]),r=s.normalTexture.scale||1;o.normalTexture=t,o.normalMapFactor=r}if(s.occlusionTexture){const t=this.O(e.textures[s.occlusionTexture.index]),r=s.occlusionTexture.strength||1;o.occlusionTexture=t,o.occlusionFactor=r}if(s.emissiveTexture){const t=this.O(e.textures[s.emissiveTexture.index]);o.emissiveTexture=t}s.emissiveFactor;const t=s.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(o.baseColorFactor=t.baseColorFactor),t.baseColorTexture&&void 0!==t.baseColorTexture.index){const n=e.textures[t.baseColorTexture.index];n.image&&n.image.color?o.baseColorFactor=o.baseColorFactor?r.vec4.multiply(o.baseColorFactor,o.baseColorFactor,n.image.color):n.image.color:(o.baseColorTexture=this.O(n),o.baseColorTexture.getREGLTexture(this.nt))}if(E(t.metallicFactor)||(o.metallicFactor=t.metallicFactor),E(t.roughnessFactor)||(o.roughnessFactor=t.roughnessFactor),s.metallicRoughnessTexture){const t=this.O(e.textures[s.metallicRoughnessTexture.index]);o.metallicRoughnessTexture=t}}}if(s.s3mMaterial)return new r.reshader.Material(o);let a=new r.reshader.pbr.StandardMaterial(o);return"phong"===n&&(a=r.reshader.PhongMaterial.convertFrom(a)),a.once("complete",this.yt),a}O(t){const e={type:t.type?ar(t.type):"uint8",format:t.format?cr(t.format):"rgba",flipY:!!t.flipY},n=t.image;n.array?e.data=n.array:n.mipmap&&(e.mipmap=n.mipmap),e.width=n.width,e.height=n.height;const i=t.sampler||t.texture&&t.texture.sampler;return i&&(i.magFilter&&(e.mag=ir(i.magFilter)),i.minFilter&&(e.min=sr(i.minFilter)),i.wrapS&&(e.wrapS=or(i.wrapS)),i.wrapT&&(e.wrapT=or(i.wrapT))),new r.reshader.Texture2D(e,this.At)}_e(t){const e=t.image,r=window.URL||window.webkitURL,n=new Blob([e.array],{type:e.mimeType});return r.createObjectURL(n)}gt({target:t}){const e=t.he,r=this.st[e];if(r.count--,!r.count){const t=r.meshes;this.ct[e]=t,delete this.st[e];const n=t.ie;delete t.ie,n(null,{mesh:r.meshes,id:e})}}ue(){return pr}jt(t){return this.tt.jt(t)}$t(t,e){const r=this.getMap();return r.getGLZoom?r.distanceToPoint(t,e,r.getGLZoom()):r.distanceToPointAtRes(t,e,r.getGLRes())}_pointToPrj(t){const e=this.getMap();return e.getGLZoom?e._pointToPrj(t,e.getGLZoom()):e._pointToPrjAtRes(t,e.getGLRes())}_prjToPoint(t){const e=this.getMap();return e.getGLZoom?e._prjToPoint(t,e.getGLZoom()):e._prjToPointAtRes(t,e.getGLRes(),Sr)}te(t){return"Y"===t?hr:"X"===t?ur:yr}pick(t,e,r=3){const n=this.tt;if(!n||!n.options.picking)return[];if(!this.pickingFBO||!this.picking)return[];const i=this.getMap(),s=this.Ot(),o=this.picking;o.render(this._t.getMeshes().filter((t=>!t.bloom)),s,!0);let a={};o.getRenderedMeshes().length&&(a=o.pick(t,e,r,s,{viewMatrix:i.viewMatrix,projMatrix:i.projMatrix,returnPoint:n.options.pickingPoint}));const{meshId:c,pickingId:l,point:f,coordinate:h}=a,u=(0===c||c)&&o.getMeshAt(c);if(!u||!u.geometry)return[];const _=u.properties;f&&f.length&&(f[0]=Math.round(1e5*f[0])/1e5,f[1]=Math.round(1e5*f[1])/1e5,f[2]=Math.round(1e5*f[2])/1e5);const d={batchId:l};if(n.options.debug&&(d.debugInfo=_),_&&_.batchTable){const{batchTable:t,batchTableBin:e,count:r}=_,n=l;for(const i in t)void 0!==t[i].byteOffset?d[i]=Ne(t[i],e,r,n):d[i]=t[i][n]}return[{data:d,point:f,coordinate:h}]}Mt(t){let e=new Set;for(let r=0,n=t.length;r<n;r++){const n=t[r].data.node;this.xt(n)&&e.add(n.Bt)}e=Array.from(e),e.sort();const r=new Map,n=e.length;for(let t=0;t<n;t++)r.set(e[t],t);return r}highlight(t){this.Ut=t;const e=this.tt.getRenderer();this.vt=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelAllHighlight(){this.Ut=null;const t=this.tt.getRenderer();this.vt=t.getFrameTimestamp(),t.setToRedraw(!0)}}const vr=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")},Br=vr(),Lr=Br.gl_trans__coders=Br.gl_trans__coders||{};function Pr(t,e){if(e)for(let r=0;r<e.length;r++){t[e[r].id||e[r].index]=e[r]}}Lr.inject=function(t){const e=t.toString(),r=e.indexOf("{")+1,n=e.substring(0,r),i=Br.gl_trans__coders=Br.gl_trans__coders||{};let s=`${n}\n const _____getGlobal = ${vr.toString()};\n const g___lobals = _____getGlobal()\n const tran_____scoders = g___lobals['gl_trans__coders'] = g___lobals['gl_trans__coders'] || {};`;for(const t in i)"inject"!==t&&"getTranscoder"!==t&&"registerTranscoder"!==t&&(s+='tran_____scoders["'+t+'"] ='+i[t].toString()+"\n;");return s+="\n"+e.substring(n.length),s},Lr.registerTranscoder=function(t,e){Lr[t]=e},Lr.getTranscoder=function(t){return Lr[t]};const Dr=[];class Fr{constructor(t,e,r,n){this.de=t,this.Ct=e,this.Ee=n,this.Te=r.version,t.indexOf("i3s:tileset:")<0?(this.Te<=1.6?this.me="root":this.me=0,r.version=this.Te):(this.me=t.substring("i3s:tileset:".length),this.Te>1.6&&(this.me=parseInt(this.me))),this.de=t,this.Ae=r}load(){const t=this.Ae,e=t.layerScene.baseUrl;if(this.Te<=1.6)return t[this.me]&&t[this.me].lodSelection?(this.pe=t[this.me],this.ye()):new Promise((r=>{let n=e+"/nodes/"+this.me;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.Ee(this.Ct,n,(()=>{this.pe=t[this.me],r(this.ye())}))}));if(this.Te>=1.7){if(t[this.me])return this.pe=t[this.me],this.ye();const r=Math.floor(this.me/t.nodesPerPage);return new Promise((n=>{let i=e+"/nodepages/"+r;t.layerScene.eslpk&&(i+=".json"),this.Ee(this.Ct,i,(()=>{this.pe=t[this.me],n(this.ye())}))}))}return null}getTileset(){return this.ge}getChildrenURL(){return this.Re}ye(){const t=this.Ae,e=t.layerScene.baseUrl,r=this.pe.children,n=[],i={};if(r)for(let s=0;s<r.length;s++)if(this.Te<=1.6){const o=r[s].id;if(t[o])continue;const a=o;i[a]||(i[a]=new Promise((r=>{let n=e+"/nodes/"+a;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.Ee(this.Ct,n,(()=>{r()}))})),n.push(i[a]))}else{const o=r[s];if(t[o])continue;const a=Math.floor(o/t.nodesPerPage);i[a]||(i[a]=new Promise((r=>{let n=e+"/nodepages/"+a;t.layerScene.eslpk&&(n+=".json"),this.Ee(this.Ct,n,(()=>{r()}))})),n.push(i[a]))}return n.length?Promise.all(n).then((()=>this.be())):this.be()}be(){return Promise.resolve(this.Ie())}Ne(t){Pr(this.Ae,t)}Ie(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.Se(this.pe,!0)}}Se(t){const e=this.Te,r=this.Ae,n=t;var i,s=n.obb,o=n.mbs,a={};if(o)i=kr([],o[0],o[1],o[2]),a.sphere=[...i,o[3]];else if(s){const t=function(t,e,r){const n=function(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=r+r,a=n+n,c=i+i,l=r*o,f=n*o,h=n*a,u=i*o,_=i*a,d=i*c,E=s*o,T=s*a,m=s*c;return t[0]=1-h-d,t[3]=f-m,t[6]=u+T,t[1]=f+m,t[4]=1-l-d,t[7]=_-E,t[2]=u-T,t[5]=_+E,t[8]=1-l-h,t}([],r);return n[0]=n[0]*e[0],n[1]=n[1]*e[0],n[2]=n[2]*e[0],n[3]=n[3]*e[1],n[4]=n[4]*e[1],n[5]=n[5]*e[1],n[6]=n[6]*e[2],n[7]=n[7]*e[2],n[8]=n[8]*e[2],[...t,...n]}(i=kr([],s.center[0],s.center[1],s.center[2]),s.halfSize,s.quaternion),e=t[3]+t[6]+t[9],r=t[4]+t[7]+t[10],n=t[5]+t[8]+t[11];G(Dr,e,r,n);const o=q(Dr);a.sphere=[...i,o]}var c=1/0,l=0;if(n.mbs?l=n.mbs[3]:n.obb&&(l=Math.max(Math.max(n.obb.halfSize[0],n.obb.halfSize[1]),n.obb.halfSize[2])),void 0!==n.lodThreshold)"maxScreenThresholdSQ"===r.lodSelectionMetricType?c=l/(Math.sqrt(n.lodThreshold)/(.25*Math.PI)):console.error("Unsupported lodSelectionMetricType in Layer");else if(void 0!==n.lodSelection)for(var f=0;f<n.lodSelection.length;f++)"maxScreenThreshold"===n.lodSelection[f].metricType&&(c=l/n.lodSelection[f].maxError);(c===1/0||isNaN(c))&&(c=1e5);var h=16*c;const u=B([]),_=n.children;var d;if(_){d=[];const t=this.Ae;for(let r=0;r<_.length;r++){const n=e<=1.6?_[r].id:_[r];if(!t[n]){d=null;break}d.push(this.Se(t[n]))}}var E={refine:"REPLACE",boundingVolume:a,transform:u,geometricError:h};return e<=1.6?t.lodSelection?t.geometryData&&(E.content={uri:"i3s:mesh:"+(t.id||t.index)}):E.content={uri:"i3s:tileset:"+(t.id||t.index)}:_&&_.length&&!d?E.content={uri:"i3s:tileset:"+(t.id||t.index)}:n.mesh&&(E.content={uri:"i3s:mesh:"+(t.id||t.index)}),d&&d.length&&(E.children=d),E}getJSON(){return this.pe}}function kr(t,e,r,n){return ne(t,p(e),p(r),n)}const Gr=!!Lr.ktx2,Hr=r.mat4.identity([]),Vr=(()=>{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 zr(t){return t.indexOf("i3s:mesh")>=0}const Xr="i3s:mesh:".length;function Yr(t,e,r,n,i){const s=e.layerScene.eslpk,o=function(t,e){const r=e.substring(Xr);return t>=1.7?parseInt(r):r}(e.version,t),a=e[o],c=e.layerScene.baseUrl,l=[];let f=!1;const h=Hr;let u,_;if(e.version<=1.6){if(!a.geometryData)return null;const t=a.geometryData.length;let r=c+`/nodes/${a.id}/`+a.geometryData[t-1].href;s&&(r+=".bin");const n={geometry:{url:r,info:e.layerScene.store.defaultGeometrySchema}};let i=a.textureData&&a.textureData[0]&&a.textureData[0].href;if(i){const t=e.layerScene.store.textureEncoding[0];let r;r="image/jpeg"===t?"jpg":"png",s&&(i+="."+r);const o={pbrMetallicRoughness:{baseColorTexture:{url:c+`/nodes/${a.id}/`+i,factor:1,format:r,mimeType:t},metallicFactor:0}};n.material=o}l.push(n)}else{u=a.mesh.geometry,_=a.mesh.material;const t=e.layerScene.geometryDefinitions[u.definition],{geometryBuffers:o}=t;f=n&&2===o.length;const h=Lr.draco&&f?o[1]:o[0],d=Lr.draco&&f?1:0;let E=c+`/nodes/${u.resource}/geometries/`+d;s&&(E+=".bin");const T={geometry:{url:E,info:h}};if(i&&Vr&&f&&!Lr.draco)throw new Error("Must import @maptalks/transcoder.draco to load i3s draco compressed geometry");const m=e.layerScene.materialDefinitions,A=e.layerScene.textureSetDefinitions;let p,y=0;if(_&&(y=m[_.definition]),m){p=function(t,e,r,n,i,s){const o=JSON.parse(JSON.stringify(t));return Wr(o,e,r,n,i,s),o}(y,A,c,_.resource,r,e.layerScene.eslpk)}else p={pbrMetallicRoughness:{metallicFactor:0}};T.material=p,l.push(T)}return{dracoCompression:f,meshes:l,nodeIndex:o,center:a.obb&&a.obb.center||a.mbs&&[a.mbs[0],a.mbs[1],a.mbs[2]],transform:h}}function Wr(t,e,r,n,i,s){for(const o in t)if(t[o]&&t[o].textureSetDefinitionId>=0){const a=e[t[o].textureSetDefinitionId],c="images/"+a.formats[0].format,l=Zr(a.formats,i),f={url:r+`/nodes/${n}/textures/${l.name}`,factor:void 0===t[o].factor?1:t[o].factor,format:l.format,mimeType:c};if(s){let t="";switch(l.format){case"dds":t="bin.dds";break;case"jpg":case"png":t=l.format}f.url+="."+t}t[o]=f}else A(t[o])&&Wr(t[o],e,r,n,i,s)}function Zr(t,e){for(let r=0;r<=t.length;r++){const n=t[r].format;if("dds"===n&&e.hasExtension("WEBGL_compressed_texture_s3tc"))return t[r];if("jpg"===n||"png"===n)return t[r];if("ktx2"===n&&Gr)return t[r]}return null}const Kr=[];class jr extends i.renderer.CanvasRenderer{constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new jt(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.we={},this.Oe=[],this.Ee=this.Me.bind(this)}getAnalysisMeshes(){if(!this.painter)return Kr;const t=this.painter.getPaintedMeshes();if(!t)return Kr;const e=[],{b3dmMeshes:r,pntsMeshes:n,i3dmMeshes:i}=t;return r.length&&x(e,r),n.length&&x(e,n),i.length&&x(e,i),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.Oe.length||super.needToRedraw())}getFrameTimestamp(){return this.xe}drawOnInteracting(t,e,r){this.draw(e,r)}draw(t,e){this.xe=t;const r=this.prepareCanvas();if(r&&!r.intersects(this.canvasExtent2D))return void this.completeRender();const{root:n,tiles:i}=this.layer.getTiles(),s=i.length;if(!i||!s)return void this.completeRender();this.Ce(),this.Ue();const{selectedTiles:o,leaves:a,requests:c}=this.ve(n,i);c.length&&this.loadTiles(c),this.Be(o,a,e),this.Le(),c.length||this.completeRender()}ve(t,e){let r=[];this.Pe();let n=0;const i=this.De(),s={};let o=!1,a=!1;for(let t=0;t<e.length;t++){const i=e[t],c=i.node;if(s[c.id])continue;s[c.id]=1;let l=!1;const f=this.getCachedTile(c.id);if(this.Fe(c.id)?(n++,l=a=!0,this.tilesLoading[c.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=a=!0),(!i.node.ke||i.node.ke<=500)&&(o=!0,i.selected=!0,i.data=f)):this.painter.has(c)||(l=a=!0,r.push(c)),!l)continue;if(this.Ge(i))o=!0;else{this.He(i).length&&(o=!0)}}let c=[],l={};if(o&&({selectedTiles:c,leaves:l}=this.Ve(t)),r.length>1&&(r.sort(qr),i)){const t=i-n;r=t>0?r.slice(0,t):[]}return{loading:a,requests:r,selectedTiles:c,leaves:l}}Ve(t){const e=[],r={};let n;const i=[t],s=[];for(;i.length>0||s.length>0;){if(s.length>0){const t=s[s.length-1];if(t.ze===i.length){s.pop(),t===n&&(t.leave=!0,r[t.node.id]=1),e.push(t);continue}}const t=i.pop(),o=t.children;if(t.selected)if("add"===t.node.refine)r[t.node.id]=1,t.selectionDepth=s.length,e.push(t);else{if(t.selectionDepth=s.length,n=t,0===o.length){t.leave=!0,r[t.node.id]=1,e.push(t);continue}s.push(t),t.ze=i.length}for(let t=0;t<o.length;t++)i.push(o[t])}return{selectedTiles:e,leaves:r}}Ge(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}He(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const r=t.Bt+1,n=[t.node];for(;n.length>0;){const i=n.pop().children;for(let s=0,o=i.length;s<o;s++){if((!i[s].content||!i[s].content.url)&&i[s].children&&i[s].children.length){n.push(i[s]);continue}const o=i[s].id;if(this.tileCache.has(o)){const r=this.layer.Xe(i[s],t);r.selected=!0,r.data=this.tileCache.get(o),t.children.push(r),e.push(r)}else i[s].Bt<=r&&n.push(i[s])}}return e}Be(t,e,r){this.tileCache.markAll(!1);for(let e=0,r=t.length;e<r;e++){const r=t[e].data;r.current=!0,this.tileCache.add(t[e].node.id,r)}this.tileCache.shrink();const n={tiles:t,leaves:e};this.onDrawTileStart(n);const i=this.painter.paint(t,e,r);this.onDrawTileEnd(n),i&&this.layer.fire("canvasisdirty",{renderCount:i})}onDrawTileStart(){}onDrawTileEnd(){}loadTiles(t){for(let e=0,r=t.length;e<r;e++){const r=t[e];this.tilesLoading[r.id]={current:!0,node:r},this.loadTile(r)}}loadTile(t){let e=t.content.url;if(O(e)){const r=M(e);return void this.Ye(e,r,t)}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const r=t.Ct,n=this.We[r];return new Fr(e,r,n,this.Ee).load().then((r=>{this.onTilesetLoad(r,t,e)}))}t&&-1===e.indexOf("http://")&&-1===e.indexOf("https://")&&!zr(e)&&(e=t.baseUrl+e);const r=this.layer.options.services[t.Ct];if(r.ajaxInMainThread){let n=r.urlParams;n&&(n=(e.indexOf("?")>0?"&":"?")+n);let i=At.getArrayBuffer(e+(n||""),r.fetchOptions);const s=i.xhr;i=i.then((r=>{delete this.we[e],r?this.Ye(e,r.data,t):this.onTileError(null,t)})).catch((r=>{delete this.we[e],this.onTileError(r,t)})),this.we[e]=s}else this.Ye(e,null,t)}Ye(t,e,n){let i=this.l;i||(i=r.reshader.Util.getSupportedFormats(this.gl.gl||this.gl),this.l=i);const s=this.layer.options.services[n.Ct];s.isSuperMapiServer&&(t=function(t,e){const r=t.substring(e.length).split("/"),n=[];for(let t=0;t<r.length;t++)n.push(encodeURIComponent(r[t]));return e+n.join("/")}(t,n.baseUrl));const o={url:t=this.layer.getTileUrl(t,n.baseUrl,s),arraybuffer:e,rootIdx:n.Ct,upAxis:n.ee,transform:n.matrix,supportedFormats:i};if(zr(t)){const e=this.We[n.Ct];if(o.i3sInfo=Yr(t,e,this.regl,this.layer.options.enableI3SCompressedGeometry,this.layer.options.forceI3SCompressedGeometry),!o.i3sInfo)return void this.onTileError({status:404},n)}this.workerConn.loadTile(this.layer.getId(),o,((e,r)=>{if(e)return void this.onTileError(e,n);const{magic:i}=r;"b3dm"===i||"pnts"===i||"i3dm"===i||"cmpt"===i?this.Oe.push({data:r,tile:n}):this.onTilesetLoad(r,n,t)}))}Ue(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let r=0;for(;this.Oe.length&&(r<e||!t.isInteracting());){const{data:t,tile:e}=this.Oe.shift(),{magic:n}=t;"b3dm"===n?this.painter.createB3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.Ze(t,e,r,n)})):"pnts"===n?this.painter.createPntsMesh(t,e.id,e,((r,{mesh:n})=>{this.Ze(t,e,r,n)})):"i3dm"===n?this.painter.createI3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.Ze(t,e,r,n)})):"cmpt"===n&&this.painter.createCMPTMesh(t,e.id,e,((r,{mesh:n})=>{this.Ze(t,e,r,n)})),r++}}Ze(t,e,r,n){if(r)this.onTileError(r,e);else{const r=this.Ke(n);e.memorySize=r,this.onTileLoad(t,e)}}Ke(t){let e=0;if(Array.isArray(t))for(let r=0;r<t.length;r++)t[r]&&(e+=this.Ke(t[r]));else t&&(e+=t.getMemorySize());return e}onTileLoad(t,e){this.layer&&(delete this.tilesLoading[e.id],this.layer.onTileLoad(t,e),this.je(e),this.setToRedraw(),this.layer.fire("tileload",{node:e}))}onTilesetLoad(t,e,r){this.layer&&(t.capabilities||t.layers&&t.layers[0]&&t.layers[0].capabilities?this.qe(t,e,r):(delete this.tilesLoading[e.id],this.layer.onTilesetLoad(t,e,r)))}onTileError(t,e){if(!this.layer)return;const r=e.content.url;console.warn("failed to load 3d tile: "+r),console.warn(t),delete this.tilesLoading[e.id],this.$e(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}$e(t,e){const r={loadTime:i.Util.now(),current:!0,error:e,node:t};this.tileCache.add(t.id,r)}je(t){const e={loadTime:i.Util.now(),current:!0,node:t};this.tileCache.add(t.id,e)}abortTileLoading(t){if(!t||!this.workerConn)return;const e=t.node.content.url;if(this.layer.options.services[t.node.Ct].ajaxInMainThread){const t=this.we[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.we[e]}Pe(){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.Qe(this.canvas,e)),this.regl=this.regl||r.createREGL({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 Ur(this.regl,t),this.layer.Je()}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new Wt("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let r=this.layer.options||{};r=T({},r),delete r.offset,r.projection=t.getSpatialReference().getProjection().code;const n=this.layer.getId();e.addLayer(n,r,(t=>{if(t)throw t;this.layer&&(this.ready=!0,this.layer.fire("workerready"))}))}onRemove(){this.painter&&this.painter.remove(),this.pickingFBO&&(this.canvas.pickingFBO||this.pickingFBO.destroy(),delete this.pickingFBO),this.workerConn&&(this.workerConn.removeLayer(this.layer.getId(),(t=>{if(t)throw t})),this.workerConn.remove(),delete this.workerConn),this.clear(),delete this.tileCache,super.onRemove()}clear(){this.Le(!0),this.tileCache.reset(),this.tilesLoading={},super.clear()}clearCanvas(){this.regl&&this.regl.clear({color:[0,0,0,0],depth:1,stencil:0}),super.clearCanvas()}getTileOpacity(){return 1}getStencilValue(){return 0}Le(t){this.tr||(this.tr=Date.now());const e=Date.now();if(t||!(e-this.tr<this.layer.options.retireInterval)){this.tr=e;for(const e in this.tilesLoading){const r=this.tilesLoading[e];!t&&r.current||this.abortTileLoading(r)}}}De(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}Qe(t,e){const r=["webgl","experimental-webgl"];let n=null;for(let i=0;i<r.length;++i){try{n=t.getContext(r[i],e)}catch(t){}if(n)break}return n}Fe(t){return!!this.tilesLoading[t]}getI3DMMeshes(){return this.painter.getI3DMMeshes()}getPNTSMeshes(){return this.painter.getPNTSMeshes()}getB3DMMeshes(){return this.painter.getB3DMMeshes()}readBatchData(t,e,r){return be(t,e,0,r)}Ce(){if(!this.er)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const r=[];for(const n in this.er){const i=this.er[n];if("pending"===i.status)continue;i.status="pending";const s=i.rootIdx;if(r.push(At.getJSON(n).then((t=>{delete this.er[n];const e=this.We[s];if(e){t.nodes?Pr(e,t.nodes):(e[t.id]=t,Pr(e,t.children));for(let t=0;t<i.length;t++)i[t]();this.setToRedraw()}else this.setToRedraw()}))),e++,e>=t)break}r.length&&Promise.all(r)}Me(t,e,r){this.er||(this.er={}),this.er[e]=this.er[e]||[],this.er[e].rootIdx=t,this.er[e].push(r),this.setToRedraw()}qe(t,e,r){this.We||(this.We=[]);const n=e.Ct;this.We[n]||(this.We[n]={});const i=this.We[n],s=this.layer.options.services[n];t.layers&&(t=t.layers[0],"/"!==r[r.length-1]&&(r+="/"),r+="layers/0"),i.version=+(s.i3sVersion||t.store.version),function(t,e,r,n,i,s){if(!i.layerScene){i.layerScene=t,i.nodesPerPage=t.nodePages&&t.nodePages.nodesPerPage||64,i.lodSelectionMetricType=t.nodePages&&t.nodePages.lodSelectionMetricType;let e=n;if(i.layerScene.eslpk=e.indexOf("3dSceneLayer.json")>=0,e.endsWith(".json")){const t=n.lastIndexOf("/");e=t<0?"./":n.substring(0,t)}i.layerScene.baseUrl=function(t){return t.split("?")[0]}(e)}return new Fr(n,e,i,s).load()}(t,n,0,r,i,this.Ee).then((t=>{this.onTilesetLoad(t,e,r)}))}pick(t,e,r){return this.painter?this.painter.pick(t,e,r&&r.tolerance):[]}highlight(t){if(this.Ut||(this.Ut=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const r=t[e].service||0;let n=this.Ut[r];n||(n=this.Ut[r]=new Map),n.set(t[e].id,t[e])}else{const e=t.service||0;let r=this.Ut[e];r||(r=this.Ut[e]=new Map),r.set(t.id,t)}this.painter.highlight(this.Ut)}cancelHighlight(t,e){if(!this.Ut)return;const r=this.Ut[t];if(r){if(Array.isArray(e))for(let t=0;t<e.length;t++)r.delete(e[t]);else r.delete(e);this.painter.highlight(this.Ut)}}cancelAllHighlight(){delete this.Ut,this.painter.cancelAllHighlight()}}function qr(t,e){return t.Vt-e.Vt}function $r(t,e,r){return t[0]=e[r],t[1]=e[r+3],t[2]=e[r+6],t}function Qr(t,e,r){return Math.sqrt(function(t,e,r){var n=V(Jr,r,t),i=$r(tn,e,0),s=$r(en,e,1),o=$r(rn,e,2),a=q(i),c=q(s),l=q(o);Y(i,i),Y(s,s),Y(o,o);var f=nn;f[0]=W(n,i),f[1]=W(n,s),f[2]=W(n,o);var h,u=0;f[0]<-a?u+=(h=f[0]+a)*h:f[0]>a&&(u+=(h=f[0]-a)*h);f[1]<-c?u+=(h=f[1]+c)*h:f[1]>c&&(u+=(h=f[1]-c)*h);f[2]<-l?u+=(h=f[2]+l)*h:f[2]>l&&(u+=(h=f[2]-l)*h);return u}(t,e,r))}const Jr=[],tn=[],en=[],rn=[],nn=[];const sn=2*Math.PI;class on{constructor(t,e,r,n){this.west=t,this.south=e,this.east=r,this.north=n}static contains(t,e){var r=e[0],n=e[1],i=t.west,s=t.east;return s<i&&(s+=sn,r<0&&(r+=sn)),(r>i||me(r,i,1e-14))&&(r<s||me(r,s,1e-14))&&n>=t.south&&n<=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 an=[0,0,1];function cn(t,e){return ne(e,t[0],t[1],t[2])}class ln{constructor(t,e){this.normal=r.vec3.copy([],t),this.distance=e}static fromPointNormal(t,e,n){var i=-r.vec3.dot(e,t);return r.vec3.copy(n.normal,e),n.distance=i,n}}const fn=[],hn=[],un=[],_n=[],dn=[],En=[],Tn=[],mn=[],An=[],pn=[],yn=new ln([1,0,0],0),gn=[];class Rn{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new on(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){var n,i,s,o=0;if(!on.contains(this.rectangle,e)){var a=this.southwestCornerCartesian,c=this.northeastCornerCartesian,l=this.westNormal,f=this.southNormal,h=this.eastNormal,u=this.northNormal,_=r.vec3.subtract(gn,t,a),d=r.vec3.dot(_,l),E=r.vec3.dot(_,f),T=r.vec3.subtract(gn,t,c),m=r.vec3.dot(T,h),A=r.vec3.dot(T,u);d>0?o+=d*d:m>0&&(o+=m*m),E>0?o+=E*E:A>0&&(o+=A*A)}if(n=e[2],i=this.minimumHeight,n>(s=this.maximumHeight)){var p=n-s;o+=p*p}else if(n<i){var y=i-n;o+=y*y}return Math.sqrt(o)}computeBox(t){const e=this;cn(on.southwest(t,hn),e.southwestCornerCartesian),cn(on.northeast(t,hn),e.northeastCornerCartesian),fn[0]=t.west,fn[1]=.5*(t.south+t.north),fn[2]=0;var n=cn(fn,un),i=r.vec3.cross(dn,n,an);r.vec3.normalize(e.westNormal,i),fn[0]=t.east;var s=cn(fn,mn),o=r.vec3.cross(dn,an,s);r.vec3.normalize(e.eastNormal,o);var a,c=r.vec3.subtract(dn,n,s),l=r.vec3.normalize(_n,c),f=t.south;if(f>0){fn[0]=.5*(t.west+t.east),fn[1]=f;var h=cn(fn,An);r.vec3.copy(pn,l);var u=ln.fromPointNormal(e.southwestCornerCartesian,e.westNormal,yn);bn(An,pn,u,e.southwestCornerCartesian),a=de(h,En)}else a=Ee(on.southeast(t,hn),En);var _=r.vec3.cross(Tn,a,c);r.vec3.normalize(e.southNormal,_);var d,E=t.north;if(E<0){fn[0]=.5*(t.west+t.east),fn[1]=E;var T=cn(fn,An);r.vec3.scale(pn,l,-1);var m=ln.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,yn);bn(An,pn,m,e.northeastCornerCartesian),d=de(T,En)}else d=Ee(on.northwest(t,hn),En);var A=r.vec3.cross(Tn,c,d);r.vec3.normalize(e.northNormal,A)}}function bn(t,e,n,i){var s=t,o=e,a=n.normal,c=r.vec3.dot(a,o);if(!(Math.abs(c)<1e-15)){var l=(-n.distance-r.vec3.dot(a,s))/c;if(!(l<0))return i=r.vec3.scale(i,o,l),r.vec3.add(i,s,i)}}const In=new i.Extent(0,0,0,0),Nn=new i.Extent(0,0,0,0),Sn=[],wn=[],On=[],Mn=[],xn=new i.Point(0,0),Cn=[],Un=new i.Coordinate(0,0),vn=r.mat4.identity([]);class Bn extends i.Layer{constructor(t,e){super(t,e),this.rr(),this.we={},this.nr=[]}rr(){let t=this.options.services.map((t=>t.url));this.ir=t.map(((t,e)=>function(t,e){t=g(t);return{visible:1,baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:r.mat4.identity([]),Ct:e,Bt:0}}(t,e))),this.fire("rootready",{roots:this.ir.slice(0)})}showService(t){return this.sr(t,1),this}hideService(t){return this.sr(t,0),this}sr(t,e){const r=this.ir[t];if(!r)return;r.visible=e;const n=this.getRenderer();n&&n.setToRedraw()}getTileUrl(t){return t}getExtent(t){if(!t&&0!==t){const t=new i.Extent;for(let e=0;e<this.ir.length;e++)if(this.ir[e].boundingVolume){const r=this.boundingVolumeToExtent(this.ir[e]);t._combine(r)}return t}return this.ir[t]&&this.ir[t].boundingVolume?this.boundingVolumeToExtent(this.ir[t]):null}boundingVolumeToExtent(t){const e=t.boundingVolume.ar?vn:t.matrix,n=this.getMap();if(t.boundingVolume.region){const e=t.boundingVolume.region;return new i.Extent(y(e[0]),y(e[1]),y(e[2]),y(e[3]))}if(t.boundingVolume.sphere){const s=t.boundingVolume.sphere,o=le([],r.vec3.transformMat4([],s,e)),a=s[3],c=n.locate(o,-a,a),l=n.locate(o,a,-a);return new i.Extent(c,l)}if(t.boundingVolume.box){const s=t.boundingVolume.box,o=r.vec3.transformMat4([],s,e),a=new i.Coordinate(le([],o)),c=s.slice(3);r.mat3.multiply(c,r.mat3.fromMat4([],t.matrix),c);const l=r.vec3.length(c.slice(0,3)),f=r.vec3.length(c.slice(3,6)),h=r.vec3.length(c.slice(6,9)),u=Math.max(l,f,h),_=n.locate(a,-u,u),d=n.locate(a,u,-u);return new i.Extent(_,d)}return null}getRootTiles(){return this.ir}getTiles(){const t=this.getRenderer();if(!t.ready)return this.cr(),{tiles:Mn};const e=this.getMap(),n=e.cameraPosition;let i,s;if(e.getGLZoom)s=e.pointToDistance(n[2],0,e.getGLZoom()),Un.set(n[0],n[1]),i=e.pointToCoord(Un,e.getGLZoom());else{const t=e.getGLRes();s=e.pointAtResToDistance(n[2],0,t),Un.set(n[0],n[1]),i=e.pointAtResToCoord(Un,t)}this.lr=this.lr||[],r.vec3.set(this.lr,p(i.x),p(i.y),s),this.hr=ne(this.hr||[],this.lr[0],this.lr[1],this.lr[2]),this.ur=2*Math.tan(.5*p(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const l=[];for(let e=0;e<this.ir.length;e++){const r=this.ir[e];if(!r.visible)continue;let n=1/0;const i=[r],s=this._r(e);for(;i.length>0;){const e=i.pop();for(e.id||this.dr(e);c.level>=e.Bt;)c=c.parent;const r=this.Er(e,s,o);if(r<1){let t=c;for(;t&&!t.content;)t=t.parent;0===r&&t&&t.content&&this.Tr(l,t);if(!1===this.options.services[e.Ct].alwaysShow)continue;if(!(0===r&&e.Bt<=n))continue;e.content&&(n=e.Bt)}e.Vt<1/0&&this.mr(e);const a=this.Xe(e,c);c.children.push(a);const f=e.children,h=f&&f.length,u=a.content;if(!h&&u&&this.Tr(l,a),h){u&&"add"===e.refine&&this.Tr(l,a),c=a;const r=f[0].parent;let n=!1;for(let s=0,o=f.length;s<o;s++){if(r){const e=t.getCachedTile(f[s].id);if(e&&e.error&&404!==e.error.status)continue;n=!0}else{n=!0,f[s].parent=e,f[s].ee=e.ee,f[s].baseUrl=e.baseUrl;const t=f[s].content&&(f[s].content.url||f[s].content.uri);t&&(O(t)||t.indexOf("i3s:")>=0?f[s].baseUrl=e.baseUrl:-1===t.indexOf("http://")&&-1===t.indexOf("https://")?f[s].content.url=e.baseUrl+t:f[s].baseUrl=t.substring(0,t.lastIndexOf("/")+1))}i.push(f[s])}!n&&u&&this.Tr(l,a)}}}return{root:a,tiles:l}}Tr(t,e){const{viewerRequestVolume:r}=e.node;r&&!function(t,e,r){if(r.region){const e=r.region;if(t[0]>=e[0]&&t[0]<=e[2]&&t[1]>=e[1]&&t[1]<=e[3])return!0}else{if(r.sphere)return Ln(r,e);if(r.box)return 0===Pn(r,e)}return!1}(this.lr,this.hr,r)||t.push(e)}Xe(t,e){return{id:t.id,node:t,children:[],level:t.Bt,parent:e,content:t.content&&t.content.url}}dr(t){t.id=i.Util.GUID(),t.matrix=t.transform||r.mat4.identity([]),t.Ar=this.pr(t),t.parent&&(function(t){return t.content&&t.content.uri&&t.content.uri.indexOf("i3s:")>=0}(t)||(t.matrix=r.mat4.multiply(t.matrix,t.parent.matrix,t.matrix)),t.Ct=t.parent.Ct,void 0===t.Bt&&(t.Bt=t.parent.Bt+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),this.yr(t)}yr(t){const e=t.boundingVolume;if(!e||e.ar)return;const n=this.options.services[t.Ct].heightOffset||0,i=this.options.offset,s=m(i)||i[0]||i[1];if(!t.boundingVolume||!n&&r.mat4.exactEquals(t.matrix,vn)&&!s)return;const{region:o,box:a,sphere:c}=e;if(o){const t=this.gr([y(o[0]),y(o[1])]);o[0]=p(t.x),o[1]=p(t.y);const e=this.gr([y(o[2]),y(o[3])]);o[2]=p(e.x),o[3]=p(e.y),o[4]+=n,o[5]+=n}else if(a||c){const e=a||c,i=r.vec3.transformMat4(Sn,e,t.matrix),s=le(wn,i),o=this.gr([s[0],s[1]]);s[0]=o.x,s[1]=o.y,s[2]+=n,ne(e,p(s[0]),p(s[1]),s[2])}e.ar=!0}pr(t){return void 0===t.geometricError||!t.boundingVolume}mr(t){let e=t.parent;for(;e&&e.Ar&&!(e.Vt<=t.Vt);)e.Vt=t.Vt,e=t.parent}onTileLoad(t,e){if(t.children&&(!e.children||!e.children.length)){e.children=t.children;const r=e.content.url;e.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const n=this.getRenderer();n&&n.setToRedraw()}}onTilesetLoad(t,e,n){if(!t)return void console.warn("invalid tileset at : "+n);const i=this.options.services[e.Ct],s=(t.asset&&t.asset.gltfUpAxis||e&&e.ee||i.upAxis||"Y").toUpperCase();t.root.baseUrl=n.substring(0,n.lastIndexOf("/")+1);const o=n.indexOf("realspace/")>-1;0===e.Bt&&(t.asset&&t.asset.s3mType&&o||i.isSuperMapiServer)&&(t.root.baseUrl+="data/path/");const a=t.asset.i3s;if(t.root.ee=s,e){const n=e.boundingVolume;T(e,t.root),e.refine=e.refine&&e.refine.toLowerCase()||"replace",n&&(e.boundingVolume=n);const i=t.root.transform;i&&(e.parent?a||(e.matrix=r.mat4.multiply([],e.parent.matrix,i)):e.matrix=i),this.yr(e),e.Rr=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.Ar=this.pr(e);const s=e.content&&(e.content.url||e.content.uri);s&&e.content.uri&&(e.content.url=e.content.uri,delete e.content.uri),a||!s||O(s)||-1!==s.indexOf("http://")||-1!==s.indexOf("https://")||(e.content.url=e.baseUrl+s)}this.cr(),this.fire("loadtileset",{tileset:t,index:e.Ct,url:n})}Er(t,e,r){if(t.Vt=1/0,0===t.Bt||t.Ar)return 1;if(!this.br(t,e,r))return-1;if(0===t.geometricError)return 1;let n=this.options.services[t.Ct].maximumScreenSpaceError;null==n&&(n=8);let i=this.Ir(t);return 0===i&&t.parent&&(i=.5*(t.parent.ke||0)),i>=n?1:0}jt(t,e){e||(e=new i.Point(0,0));const r=this.getMap();return r.getGLZoom?r.coordToPoint(t,r.getGLZoom(),e):r.coordToPointAtRes(t,r.getGLRes(),e)}br(t,e,n){const s=t.id;let o=this.nr[s];const{boundingVolume:c}=t,l=c.sphere;let _=c.region;const E=c.box;if(!o){let e,n,a;if(E&&(_=function(t,e){for(let e=0;e<9;e++)Wn[e]=t[e+3];const n=Wn;r.mat4.exactEquals(e,vn)||r.mat3.multiply(n,r.mat3.fromMat4(Cn,e),n);const i=r.vec3.copy(Dn,t),s=r.vec3.set(Fn,n[0],n[1],n[2]),o=r.vec3.set(kn,n[3],n[4],n[5]),a=r.vec3.set(Gn,n[6],n[7],n[8]);Hn[0]=Hn[0]||[];const c=r.vec3.copy(Hn[0],i);r.vec3.sub(c,c,s),r.vec3.sub(c,c,o),r.vec3.sub(c,c,a),Hn[1]=Hn[1]||[];const l=r.vec3.copy(Hn[1],i);r.vec3.sub(l,l,s),r.vec3.sub(l,l,o),r.vec3.add(l,l,a),Hn[2]=Hn[2]||[];const f=r.vec3.copy(Hn[2],i);r.vec3.sub(f,f,s),r.vec3.add(f,f,o),r.vec3.sub(f,f,a),Hn[3]=Hn[3]||[];const h=r.vec3.copy(Hn[3],i);r.vec3.sub(h,h,s),r.vec3.add(h,h,o),r.vec3.add(h,h,a),Hn[4]=Hn[4]||[];const u=r.vec3.copy(Hn[4],i);r.vec3.add(u,u,s),r.vec3.sub(u,u,o),r.vec3.sub(u,u,a),Hn[5]=Hn[5]||[];const _=r.vec3.copy(Hn[5],i);r.vec3.add(_,_,s),r.vec3.sub(_,_,o),r.vec3.add(_,_,a),Hn[6]=Hn[6]||[];const d=r.vec3.copy(Hn[6],i);r.vec3.add(d,d,s),r.vec3.add(d,d,o),r.vec3.sub(d,d,a),Hn[7]=Hn[7]||[];const E=r.vec3.copy(Hn[7],i);r.vec3.add(E,E,s),r.vec3.add(E,E,o),r.vec3.add(E,E,a);for(let t=0;t<Hn.length;t++)Vn[t]=Vn[t]||[],le(Vn[t],Hn[t]),zn[t]=Vn[t][0],Xn[t]=Vn[t][1],Yn[t]=Vn[t][2];return[p(Math.min(...zn)),p(Math.min(...Xn)),p(Math.max(...zn)),p(Math.max(...Xn)),Math.min(...Yn),Math.max(...Yn)]}(E,t.matrix),c.region=_),_){e=In.set(y(_[0]),y(_[1]),y(_[2]),y(_[3]));const t=e.getCenter(),r=this.Nr(t);e=e.convertTo((t=>this.jt(t,xn)),Nn),a=_[4],n=_[5],o=this.nr[s]=[[e.xmin,e.ymin,a*r[2]],[e.xmax,e.ymax,n*r[2]]],o.center=t}else if(l){const t=le(Sn,l),e=new i.Coordinate(t),r=this.jt(e,xn).toArray(),n=this.Nr(e);r.push(t[2]*n[2]),o=this.nr[s]=[r,l[3]*n[2]],o.center=e}}if(e){if(_)In.xmin=o[0][0],In.ymin=o[0][1],In.xmax=o[1][0],In.ymax=o[1][1];else if(l){const t=o[2];In.xmin=o[0][0]-t,In.ymin=o[0][1]-t,In.xmax=o[0][0]+t,In.ymax=o[0][1]+t}else if(E){const t=o[1],e=o[2];In.xmin=o[0][0]-t,In.ymin=o[0][1]-e,In.xmax=o[0][0]+t,In.ymax=o[0][1]+e}if(!e.intersects(In))return!1}return _?f(n,o):l?function(t,e,r){u(t);for(var n=e[0],i=-e[1],s=0;s<6;s++)if((!r||"0"!==r.charAt(s))&&d(a[s],n)<i)return!1;return!0}(n,o):!!E&&function(t,e,r){u(t);for(var n=0;n<6;n++)if(!(r&&"0"===r.charAt(n)||h(a[n],e)))return!1;return!0}(n,o)}Nr(t){const e=this.getMap(),n=e.distanceToPointAtRes(100,100,e.getGLRes(),t);let i;return i=e.altitudeToPoint?e.altitudeToPoint(100,e.getGLRes())/100:n.y/100,r.vec3.set(On,n.x/100*1.01,n.y/100*1.01,i),On}gr(t){Array.isArray(t)&&(t=new i.Coordinate(t));let e=this.options.offset;if(m(e)&&(e=e(Array.isArray(t)?new i.Coordinate(t):t)),e[0]||e[1]){const r=this.getMap(),n=r.getGLRes(),i=r.coordToPointAtRes(t,n);return i._sub(e),r.pointAtResToCoord(i,n)}return t}_r(t){const e=this.options.services[t].maxExtent;if(!e)return null;const r=this.ir[t];return r.maxExtent||(r.maxExtent=new i.Extent(e).convertTo((t=>this.jt(t)))),r.maxExtent}Ir(t){const e=this.ur,r=t.geometricError;if(0===r)return t.ke=0,0;const n=this.getMap();let i;t.boundingVolume.region?i=function(t,e,r){t.Sr||(t.Sr=new Rn(t.boundingVolume.region));return t.Sr.distanceToCamera(e,r)}(t,this.hr,this.lr):t.boundingVolume.sphere?i=Ln(t.boundingVolume,this.hr):t.boundingVolume.box&&(i=Pn(t.boundingVolume,this.hr));const s=Math.max(Math.abs(i),1e-7),o=r*n.height/(s*e);return t.Vt=i,t.ke=o,o}cr(){const t=this.getRenderer();t&&t.setToRedraw()}oe(t){return this.nr[t]}identify(t,e={}){const r=this.getMap(),n=this.getRenderer();if(!r||!n)return[];const s=r.coordToContainerPoint(new i.Coordinate(t));return this.identifyAtPoint(s,e)}identifyAtPoint(t,e={}){const r=this.getMap(),n=this.getRenderer();if(!r||!n)return[];const i=r.getDevicePixelRatio();return n.pick(t.x*i,t.y*i,e)}highlight(t){const e=this.getRenderer();return e?(e.highlight(t),this):(this.Ut||(this.Ut=[]),this.Ut.push(t),this)}Je(){if(this.Ut){for(let t=0;t<this.Ut.length;t++)this.highlight(this.Ut[t]);delete this.Ut}}cancelHighlight(t,e){const r=this.getRenderer();return r?(r.cancelHighlight(t,e),this):this}cancelAllHighlight(){const t=this.getRenderer();return t?(t.cancelAllHighlight(),this):this}}function Ln(t,e){const n=t.sphere,i=r.vec3.dist(n,e),s=t.sphere[3];return i<s?0:i-s}function Pn(t,e){const n=t.box;return Qr(r.vec3.set(Sn,n[0],n[1],n[2]),r.mat3.set(Cn,n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10],n[11]),e)}Bn.mergeOptions({"maxGPUMemory":512,"retireInterval":2e3,"loadingLimitOnInteracting":5,"loadingLimit":0,"renderer":"gl","forceRenderOnZooming":!0,"forceRenderOnRotating":!0,"forceRenderOnMoving":!0,"debug":!1,"debugOutline":[0,1,0],"meshLimitPerFrame":1,"i3sNodepageLimitPerFrame":1,"enableI3SCompressedGeometry":!0,"forceI3SCompressedGeometry":!0,"picking":!0,"pickingPoint":!0,"geometryEvents":!1,"antialias":!1,"optionalExtensions":["ANGLE_instanced_arrays","OES_element_index_uint","OES_standard_derivatives","OES_vertex_array_object","OES_texture_half_float","OES_texture_half_float_linear","OES_texture_float","OES_texture_float_linear","WEBGL_depth_texture","EXT_shader_texture_lod","WEBGL_compressed_texture_astc","WEBGL_compressed_texture_etc","WEBGL_compressed_texture_etc1","WEBGL_compressed_texture_pvrtc","WEBGL_compressed_texture_s3tc","WEBGL_compressed_texture_s3tc_srgb"],"offset":[0,0]}),Bn.registerRenderer("gl",jr),Bn.registerJSONType("Geo3DTilesLayer");const Dn=[],Fn=[],kn=[],Gn=[],Hn=[],Vn=[],zn=[],Xn=[],Yn=[],Wn=[];class Zn{constructor(t,e,r){this.o=t,this.wr=e||Ft,this.l=r,this.Or={"image/crn":Lr.crn&&Lr.crn(),"image/ktx2":Lr.ktx2&&Lr.ktx2(),"image/cttf":Lr.ktx2&&Lr.ktx2(),"draco":Lr.draco&&Lr.draco()}}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.Mr(t,e,r,n,i)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Mr(t,i,r,n)}))}Mr(t,e,r,n,i){const s=i&&i.maxTextureSize,o=this.Cr(e,r,n,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.wr(a,o.glb,{transferable:!0,requestImage:this.o,decoders:this.Or,supportedFormats:this.l,maxTextureSize:s});return c.load({skipAttributeTransform:!1}).then((e=>{e.url=`${t}-${r}-${n}`;const i=c.transferables;for(let t=0;t<o.transferables.length;t++)i.indexOf(o.transferables[t])<0&&i.push(o.transferables[t]);return{magic:"b3dm",count:o.count,transferables:i,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,gltf:e}}))}Cr(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported b3dm version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in b3dm header is inconsistent with b3dm's byte length, url: "+n;return console.warn(t),{error:t}}let o,a=i.getUint32(12,!0),c=i.getUint32(16,!0),l=i.getUint32(20,!0),f=i.getUint32(24,!0),h=28+e;l>=570425344?(h-=8,o=a,l=c,f=0,a=0,c=0):f>=570425344&&(h-=4,o=l,l=a,f=c,a=0,c=0);const u=[t];let _,d,E;if(a>0?(_=ye(t,h,a),h+=a,o=_.BATCH_LENGTH):_={"BATCH_LENGTH":o},c>0&&(h+=c),l>0&&(d=ge(t,h,l),h+=l,f>0)){const e=Re(0,h,f);E=t.slice(e.offset,e.offset+e.byteLength),h+=f,u.push(E)}const T=_.BATCH_LENGTH,m={};if(_&&_.BATCH_ID){m.BATCH_ID=Ie(_.BATCH_ID,t,undefined.offset,T);const e=m.BATCH_ID.array&&m.BATCH_ID.array.buffer;e&&u.indexOf(e)<0&&u.push(e)}return{count:o,transferables:u,featureTable:_,batchTable:d,batchTableBin:E,b3dm:m,glb:{buffer:t,byteOffset:h,byteLength:i.byteLength+i.byteOffset-h}}}Ur(){return null}}class Kn{constructor(t,e,r,n){this.o=t,this.wr=e||Ft,this.l=r,this.Or={"image/crn":Lr.crn&&Lr.crn(),"image/ktx2":Lr.ktx2&&Lr.ktx2(),"image/cttf":Lr.ktx2&&Lr.ktx2(),"draco":Lr.draco&&Lr.draco()},this.vr=n}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.Mr(t,e,r,n,i)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Mr(t,i,r,n)}))}Mr(t,e,r,n,i){return this.Br(t,e,r,n,i).then((({gltf:i,transferables:s})=>{const o=this.Lr(e,r,n,t);if(o.error)return Promise.resolve(o);for(let t=0;t<s.length;t++)-1===o.transferables.indexOf(s[t])&&o.transferables.push(s[t]);return delete i.transferables,Promise.resolve({magic:"i3dm",count:o.count,transferables:o.transferables,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,i3dm:o.i3dm,gltf:i})}))}Br(t,e,r,n,i){const s=i&&i.maxTextureSize,o={transferable:!0,requestImage:this.o,decoders:this.Or,supportedFormats:this.l,maxTextureSize:s},a=new DataView(e,r,n),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 n=I(new Uint8Array(e,c+r,a.byteLength-c));-1==n.indexOf("://")&&(n=t.substring(0,t.lastIndexOf("/"))+"/"+n);return n.indexOf(".glb")>0?At.getArrayBuffer(n,{}).then((t=>this.Pr(n,{buffer:t.data,byteOffset:0},o))):At.getJSON(n,{}).then((t=>this.Pr(n,t,o)))}{const n={buffer:e,byteOffset:c+r,byteLength:a.byteLength-c};return this.Pr(t,n,o)}}Pr(t,e,r){const n=t.substring(0,t.lastIndexOf("/")),i=new this.wr(n,e,r);return i.load({skipAttributeTransform:!0}).then((r=>{let n=0,s=0;return e.buffer&&(n=e.byteOffset||0,s=e.byteLength||0),r.url=`${t}-${n}-${s}`,{transferables:i.transferables,gltf:r}}))}Lr(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported pnts version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+n;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:l,batchTableBin:f}=Ue(i,32+e,o),h={},u=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;h.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,r=a.QUANTIZED_VOLUME_SCALE,{byteOffset:n}=a.POSITION_QUANTIZED;h.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:u,componentType:5126,array:this.Dr(new Uint16Array(t,n+c.offset,3*u),e,r)},o.push(h.POSITION.array.buffer)}if(a.BATCH_ID){h.BATCH_ID=Ie(a.BATCH_ID,t,c.offset,u);const e=h.BATCH_ID.array&&h.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;h.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,h.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;h.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:this.Fr(new Uint16Array(t,e+c.offset,2*u))},o.push(h.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,h.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:this.Fr(new Uint16Array(t,e+c.offset,2*u))},o.push(h.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;h.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,u).slice()},o.push(h.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;h.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.SCALE_NON_UNIFORM.array.buffer)}return{count:u,batchTable:l,batchTableBin:f,featureTable:a,i3dm:h,transferables:o}}Fr(t){const e=t.length/2,r=new Float32Array(3*e),n=[];for(let i=0;i<e;i++)jn(n,t[2*i],t[2*i+1],65535),r[3*i]=n[0],r[3*i+1]=n[1],r[3*i+2]=n[2];return r}Dr(t,e,r){return Ce(new Float32Array(t.length),t,e,r)}Ur(){return null}}function jn(t,e,r,n){if(t[0]=qn(e,n),t[1]=qn(r,n),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]))*$n(e),t[1]=(1-Math.abs(e))*$n(t[1])}return Y(t,t)}function qn(t,e){return function(t,e,r){return t<e?e:t>r?r:t}(t,0,e=function(t,e){if(null!=t)return t;return e}(e,255))/e*2-1}function $n(t){return t<0?-1:1}class Qn{constructor(){}load(t,e,r=0,n=0){return e?(n||(n=e.byteLength),this.Mr(t,e,r,n)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Mr(t,i,r,n)}))}Mr(t,e,r,n){return this.kr(e,r,n,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}))}kr(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported pnts version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+n;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:l,batchTableBin:f}=Ue(i,e+28,o),h=a.QUANTIZED_VOLUME_OFFSET,u=a.QUANTIZED_VOLUME_SCALE,_=a.POINTS_LENGTH;let d,E={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){E=a.extensions["3DTILES_draco_point_compression"],d=new DataView(t,E.byteOffset+c.offset,E.byteLength);const e={attributes:E.properties,useUniqueIDs:!1};return this.Gr||(this.Gr=Lr.draco()),this.Gr(d,e).then((e=>{const r=e.attributes;!a.POSITION&&!a.POSITION_QUANTIZED||r.POSITION||r.POSITION_QUANTIZED||(r.POSITION=a.POSITION,r.POSITION_QUANTIZED=a.POSITION_QUANTIZED),!(a.RGB||a.RGBA||a.RGB565)||r.RGB||r.RGBA||r.RGB565||(r.RGB=a.RGB,r.RGBA=a.RGBA,r.RGB565=a.RGB565),!a.NORMAL&&!a.NORMAL_OCT16P||r.NORMAL||r.NORMAL_OCT16P||(r.NORMAL=a.NORMAL,r.NORMAL_OCT16P=a.NORMAL_OCT16P);const n=this.Hr(t,e.attributes,c.offset,_,o,h,u);if(e.attributes.BATCH_ID){const t=e.attributes.BATCH_ID.array;n.BATCH_ID={byteStride:0,byteOffset:0,itemSize:1,count:t.length,componentType:xe(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?n.BATCH_ID=Ie(a.BATCH_ID,t,c.offset,_):n.BATCH_ID=Jn(_);const e=n.BATCH_ID.array&&n.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return{count:_,batchTable:l,batchTableBin:f,featureTable:a,pnts:n,transferables:o}}))}const T=this.Hr(t,a,c.offset,_,o,h,u);if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?T.BATCH_ID=Ie(a.BATCH_ID,t,c.offset,_):T.BATCH_ID=Jn(_);const e=T.BATCH_ID.array&&T.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:_,batchTable:l,batchTableBin:f,featureTable:a,pnts:T,transferables:o})}Hr(t,e,r,n,i,s,o){const a={};if(e.POSITION){let{byteOffset:s,array:o}=e.POSITION;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n*4);o=new Float32Array(e)}a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:o},i.push(o.buffer)}else if(e.POSITION_QUANTIZED){let{byteOffset:c,array:l}=e.POSITION_QUANTIZED;c=c||0;const f=l?0:r;a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:this.Dr(l||new Uint16Array(t,c+f,3*n),s,o)},i.push(a.POSITION.array.buffer)}if(e.RGBA){let{byteOffset:s,array:o}=e.RGBA;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+4*n);o=new Uint8Array(e)}a.RGBA={byteStride:0,byteOffset:0,itemSize:4,count:n,componentType:5121,array:o},i.push(o.buffer)}else if(e.RGB){let{byteOffset:s,array:o}=e.RGB;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n);o=new Uint8Array(e)}a.RGB={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5121,array:o},i.push(o.buffer)}else if(e.RGB565){let{byteOffset:s,array:o}=e.RGB565;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+2*n);o=new Uint16Array(e)}a.RGB565={byteStride:0,byteOffset:0,itemSize:1,count:n,componentType:5123,array:o},i.push(o.buffer)}if(e.NORMAL){let{byteOffset:s,array:o}=e.NORMAL;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n*4);o=new Float32Array(e)}a.NORMAL={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:o},i.push(o.buffer)}else if(e.NORMAL_OCT16P){let{byteOffset:s,array:o}=e.NORMAL_OCT16P;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+2*n);o=new Uint8Array(e)}a.NORMAL_OCT16P={byteStride:0,byteOffset:0,itemSize:2,count:n,componentType:5121,array:o},i.push(o.buffer)}return a}Dr(t,e,r){return Ce(new Float32Array(t.length),t,e,r)}Ur(){return null}}function Jn(t){const e=w(t),r=new e(t);for(let e=0;e<t;e++)r[e]=e;return{byteStride:0,byteOffset:0,itemSize:1,count:t,componentType:xe(e),array:r}}class ti{constructor(t,e){this.o=t,this.wr=e||Ft}load(t,e,r=0,n=0,i){return e?this.Mr(t,e,r,n,i):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return this.Mr(t,i,r,n)}))}Mr(t,e,r,n,i){n||(n=e.byteLength);const s=this.Vr(e,t,r,n),o=[];for(let r=0;r<s.length;r++){let n;if("b3dm"===s[r].magic)n=new Zn(this.o,this.wr);else if("i3dm"===s[r].magic)n=new Kn(this.o,this.wr);else if("pnts"===s[r].magic)n=new Qn;else{if("cmpt"!==s[r].magic){console.warn("Unsupported magic in CMPT tile:",s[r].magic);continue}n=new ti(this.o,this.wr)}o.push(n.load(t,e,s[r].offset,s[r].byteLength,i).then((t=>t)))}return Promise.all(o).then((t=>({magic:"cmpt",tiles:t})))}Vr(t,e,r,n){const i=new DataView(t,r,n),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported cmpt version: "+s+", url:"+e;return console.warn(t),{error:t}}if(16===i.byteLength)return[];const o=[],a=i.getUint32(12,!0);let c=16;for(let e=0;e<a;e++){const e=Ae(i,c),n=i.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+r,byteLength:n}),c+=n}return o}}if(s.transcoders){const t=i.Map.VERSION;if(t.indexOf("1.0.0-beta")>=0||t.indexOf("1.0.0-alpha")>=0){const t=s.transcoders.inject(o);i.registerWorkerAdapter("@maptalks/3dtiles",t)}else i.registerWorkerAdapter("@maptalks/3dtiles",(function(){return s.transcoders.inject(o)}))}else i.registerWorkerAdapter("@maptalks/3dtiles",o);t.B3DMLoader=Zn,t.CMPTLoader=ti,t.Geo3DTilesLayer=Bn,t.Geo3DTilesUtil=C,t.Geo3DTransform=Te,Object.defineProperty(t,"t",{value:!0}),"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.20.0")}));
23
+ */(s,a)),c.generateBuffers(this.nt,{excludeElementsInVAO:e}),c}se(t,e,n,i){const s=r.mat4.identity(t),o=this.getMap();Nr.x=n[0],Nr.y=n[1];const a=this._prjToPoint(Nr),c=this.ue(),l=1/(o.getGLZoom?o.getResolution(o.getGLZoom()):o.getGLRes());let f;Nr.x=e[0],Nr.y=e[1],f=o.altitudeToPoint?this.St:o.distanceToPointAtRes(100,100,o.getGLRes(),Nr).y/100;let h=this.tt.options.offset;m(h)&&(h=h(Nr));const u=this.tt.options.services[i].heightOffset||0;return r.vec3.set(Or,a.x-h[0],a.y-h[1],f*n[2]+f*u),r.mat4.translate(s,s,Or),r.vec3.set(c,l,l,f),r.mat4.scale(s,s,c),s}Qt(t,e){const n=r.mat4.identity(t),i=this.getMap(),s=this.ue();Nr.x=e[0],Nr.y=e[1];const o=i.distanceToPointAtRes(100,100,i.getGLRes(),Nr);let a;return a=i.altitudeToPoint?this.St:o.y/100,r.vec3.set(s,o.x/100*1.01,o.y/100*1.01,a),r.mat4.scale(n,n,s),n}bt(){const t={x:0,y:0,width:()=>this.et?this.et.width:1,height:()=>this.et?this.et.height:1};this.Xt=new r.reshader.MeshShader({vert:"attribute vec3 aPosition;\n\n\n\nuniform mat4 projViewModelMatrix;\n\n\n\nvoid main() {\n\n gl_Position = projViewModelMatrix * vec4(aPosition, 1.0);\n\n}\n\n",frag:"precision mediump float;\nuniform vec3 color;\nvoid main() {\n gl_FragColor = vec4(color, 1.0);\n}\n",uniforms:["color",{name:"projViewModelMatrix",type:"function",fn:(t,e)=>r.mat4.multiply([],e.projViewMatrix,e.modelMatrix)}],extraCommandProps:{viewport:t}});const e=[],n=[];this.Gt=new r.reshader.MeshShader({vert:"const float SHIFT_RIGHT_11 = 1.0 / 2048.0;\n\nconst float SHIFT_RIGHT_5 = 1.0 / 32.0;\n\nconst float SHIFT_LEFT_11 = 2048.0;\n\nconst float SHIFT_LEFT_5 = 32.0;\n\nconst float NORMALIZE_6 = 1.0 / 64.0;\n\nconst float NORMALIZE_5 = 1.0 / 32.0;\n\n\n\n#ifdef HAS_POSITION\n\n attribute vec3 POSITION;\n\n#endif\n\n\n\n#if defined(HAS_RGB)\n\n attribute vec3 RGB;\n\n#elif defined(HAS_RGBA)\n\n attribute vec4 RGBA;\n\n#elif defined(HAS_RGB565)\n\n attribute float RGB565;\n\n#endif\n\n\n\nuniform vec4 pointColor;\n\nuniform float pointSize;\n\n\n\nuniform mat4 projViewModelMatrix;\n\nuniform float pointOpacity;\n\n\n\nvarying vec4 vColor;\n\n\n\n#ifdef HAS_NORMAL\n\n #ifdef HAS_NORMAL_OCT16P\n\n attribute vec2 NORMAL_OCT16P;\n\n float signNotZero(float value) {\n\n return value >= 0.0 ? 1.0 : -1.0;\n\n }\n\n vec2 signNotZero(vec2 value) {\n\n return vec2(signNotZero(value.x), signNotZero(value.y));\n\n }\n\n vec3 octDecode(vec2 encoded, float range) {\n\n if (encoded.x == 0.0 && encoded.y == 0.0) {\n\n return vec3(0.0, 0.0, 0.0);\n\n }\n\n encoded = encoded / range * 2.0 - 1.0;\n\n vec3 v = vec3(encoded.x, encoded.y, 1.0 - abs(encoded.x) - abs(encoded.y));\n\n if (v.z < 0.0) {\n\n v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);\n\n }\n\n return normalize(v);\n\n }\n\n vec3 octDecode(vec2 encoded) {\n\n return octDecode(encoded, 255.0);\n\n }\n\n #else\n\n attribute vec3 NORMAL;\n\n #endif\n\n uniform vec3 lightDir;\n\n uniform mat3 modelNormalMatrix;\n\n uniform mat4 positionMatrix;\n\n float getLambertDiffuse(vec3 lightDir, vec3 normal) {\n\n return max(dot(-lightDir, normal), 0.0);\n\n }\n\n#endif\n\n\n\nvoid main() {\n\n #if defined(HAS_RGB)\n\n vColor = vec4(RGB / 255.0, 1.0) * pointOpacity;\n\n #elif defined(HAS_RGBA)\n\n vColor = RGBA / 255.0 * pointOpacity;\n\n #elif defined(HAS_RGB565)\n\n float compressed = RGB565;\n\n float r = floor(compressed * SHIFT_RIGHT_11);\n\n compressed -= r * SHIFT_LEFT_11;\n\n float g = floor(compressed * SHIFT_RIGHT_5);\n\n compressed -= g * SHIFT_LEFT_5;\n\n float b = compressed;\n\n vec3 rgb = vec3(r * NORMALIZE_5, g * NORMALIZE_6, b * NORMALIZE_5);\n\n vColor = vec4(rgb, 1.0);\n\n #else\n\n vColor = pointColor;\n\n #endif\n\n\n\n #ifdef HAS_POSITION\n\n vec3 localPos = POSITION;\n\n #endif\n\n\n\n #ifdef HAS_NORMAL\n\n mat3 positionNormalMatrix = mat3(positionMatrix);\n\n mat3 normalMatrix = modelNormalMatrix * positionNormalMatrix;\n\n #ifdef HAS_NORMAL_OCT16P\n\n vec3 localNormal = octDecode(NORMAL_OCT16P);\n\n #else\n\n vec3 localNormal = NORMAL;\n\n #endif\n\n vec3 normal = normalize(normalMatrix * localNormal);\n\n float colorStrength = getLambertDiffuse(lightDir, normal);\n\n colorStrength = max(colorStrength, 0.5);\n\n vColor *= colorStrength;\n\n #endif\n\n\n\n gl_Position = projViewModelMatrix * vec4(localPos, 1.0);\n\n gl_PointSize = pointSize;\n\n}\n\n",frag:"#define SHADER_NAME PNTS\n\nprecision mediump float;\n\n\n\nvarying vec4 vColor;\n\n\n\nvoid main() {\n\n gl_FragColor = vColor;\n\n}\n\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:(t,e)=>r.mat4.multiply(n,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,n)=>r.mat3.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.Nt();this.Dt=new r.reshader.PhongShader({extraCommandProps:i}),this.Ft=new r.reshader.pbr.StandardShader({extraCommandProps:i});const s=this.tt;_r(s.getRenderer().canvas,this.nt,s.getMap()),this.picking=new r.reshader.FBORayPicking(this.it,{vert:this.Ft.vert,extraCommandProps:i,uniforms:this.Ft.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap())}Nt(){return{viewport:{x:0,y:0,width:()=>this.et?this.et.width:1,height:()=>this.et?this.et.height:1},colorMask:(t,e)=>e.colorMask||br,cull:{enable:!0,face:(t,e)=>e.cullFace||"back"},stencil:{enable:(t,e)=>!0===e.stencilEnable,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}}}Yt(t){return{projViewMatrix:this.getMap().projViewMatrix,color:t&&t.color||[0,1,0]}}kt(t){const e=this.getMap(),n=e.getLightManager(),i=(n&&n.getDirectionalLight()||{}).direction||[1,1,-1],s=t&&t.pointOpacity||1;return{projViewMatrix:e.projViewMatrix,pointOpacity:s,lightDir:r.vec3.normalize(i,i)}}Ot(){const t=this.getMap(),e=this.tt.getRenderer().canvas,{iblTexes:r,dfgLUT:n}=Er(e),i=Tr(t,r,n);return T(i,{czm_lightDirectionEC:i.light0_viewDirection,lightSpecular:[1,1,1],viewMatrix:t.viewMatrix,projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,outSize:[e.width,e.height],polygonFill:[1,1,1,1],polygonOpacity:1}),i}fe(t,e,n,i){const s=e.materials[t];if(!s||!s.baseColorTexture&&!s.pbrMetallicRoughness)return null;const o=T({},i);if(s.baseColorTexture){const t=e.textures[s.baseColorTexture.index];let r;t&&!t.image.color&&(r=this.O(t)),o.baseColorFactor=t&&t.image.color||s.baseColorFactor||[1,1,1,1],r&&(o.baseColorTexture=r)}else{if(s.normalTexture){const t=this.O(e.textures[s.normalTexture.index]),r=s.normalTexture.scale||1;o.normalTexture=t,o.normalMapFactor=r}if(s.occlusionTexture){const t=this.O(e.textures[s.occlusionTexture.index]),r=s.occlusionTexture.strength||1;o.occlusionTexture=t,o.occlusionFactor=r}if(s.emissiveTexture){const t=this.O(e.textures[s.emissiveTexture.index]);o.emissiveTexture=t}s.emissiveFactor;const t=s.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(o.baseColorFactor=t.baseColorFactor),t.baseColorTexture&&void 0!==t.baseColorTexture.index){const n=e.textures[t.baseColorTexture.index];n.image&&n.image.color?o.baseColorFactor=o.baseColorFactor?r.vec4.multiply(o.baseColorFactor,o.baseColorFactor,n.image.color):n.image.color:(o.baseColorTexture=this.O(n),o.baseColorTexture.getREGLTexture(this.nt))}if(E(t.metallicFactor)||(o.metallicFactor=t.metallicFactor),E(t.roughnessFactor)||(o.roughnessFactor=t.roughnessFactor),s.metallicRoughnessTexture){const t=this.O(e.textures[s.metallicRoughnessTexture.index]);o.metallicRoughnessTexture=t}}}if(s.s3mMaterial)return new r.reshader.Material(o);let a=new r.reshader.pbr.StandardMaterial(o);"phong"===n&&(a=r.reshader.PhongMaterial.convertFrom(a));const c=s.pbrMetallicRoughness,l=c&&c.baseColorTexture&&c.baseColorTexture.extensions;return l&&l.KHR_texture_transform&&(a.set("khr_offset",l.KHR_texture_transform.offset||[0,0]),a.set("khr_rotation",l.KHR_texture_transform.rotation||0),a.set("khr_scale",l.KHR_texture_transform.scale||[1,1])),a.once("complete",this.yt),a}O(t){const e={type:t.type?ar(t.type):"uint8",format:t.format?cr(t.format):"rgba",flipY:!!t.flipY},n=t.image;n.array?e.data=n.array:n.mipmap&&(e.mipmap=n.mipmap),e.width=n.width,e.height=n.height;const i=t.sampler||t.texture&&t.texture.sampler;return i&&(i.magFilter&&(e.mag=ir(i.magFilter)),i.minFilter&&(e.min=sr(i.minFilter)),i.wrapS&&(e.wrapS=or(i.wrapS)),i.wrapT&&(e.wrapT=or(i.wrapT))),new r.reshader.Texture2D(e,this.At)}_e(t){const e=t.image,r=window.URL||window.webkitURL,n=new Blob([e.array],{type:e.mimeType});return r.createObjectURL(n)}gt({target:t}){const e=t.he,r=this.st[e];if(r.count--,!r.count){const t=r.meshes;this.ct[e]=t,delete this.st[e];const n=t.ie;delete t.ie,n(null,{mesh:r.meshes,id:e})}}ue(){return pr}jt(t){return this.tt.jt(t)}$t(t,e){const r=this.getMap();return r.getGLZoom?r.distanceToPoint(t,e,r.getGLZoom()):r.distanceToPointAtRes(t,e,r.getGLRes())}_pointToPrj(t){const e=this.getMap();return e.getGLZoom?e._pointToPrj(t,e.getGLZoom()):e._pointToPrjAtRes(t,e.getGLRes())}_prjToPoint(t){const e=this.getMap();return e.getGLZoom?e._prjToPoint(t,e.getGLZoom()):e._prjToPointAtRes(t,e.getGLRes(),Sr)}te(t){return"Y"===t?hr:"X"===t?ur:yr}pick(t,e,r=3){const n=this.tt;if(!n||!n.options.picking)return[];if(!this.pickingFBO||!this.picking)return[];const i=this.getMap(),s=this.Ot(),o=this.picking;o.render(this._t.getMeshes().filter((t=>!t.bloom)),s,!0);let a={};o.getRenderedMeshes().length&&(a=o.pick(t,e,r,s,{viewMatrix:i.viewMatrix,projMatrix:i.projMatrix,returnPoint:n.options.pickingPoint}));const{meshId:c,pickingId:l,point:f,coordinate:h}=a,u=(0===c||c)&&o.getMeshAt(c);if(!u||!u.geometry)return[];const _=u.properties;f&&f.length&&(f[0]=Math.round(1e5*f[0])/1e5,f[1]=Math.round(1e5*f[1])/1e5,f[2]=Math.round(1e5*f[2])/1e5);const d={batchId:l};if(n.options.debug&&(d.debugInfo=_),_&&_.batchTable){const{batchTable:t,batchTableBin:e,count:r}=_,n=l;for(const i in t)void 0!==t[i].byteOffset?d[i]=Ne(t[i],e,r,n):d[i]=t[i][n]}return[{data:d,point:f,coordinate:h}]}Mt(t){let e=new Set;for(let r=0,n=t.length;r<n;r++){const n=t[r].data.node;this.xt(n)&&e.add(n.Bt)}e=Array.from(e),e.sort();const r=new Map,n=e.length;for(let t=0;t<n;t++)r.set(e[t],t);return r}highlight(t){this.Ut=t;const e=this.tt.getRenderer();this.vt=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelAllHighlight(){this.Ut=null;const t=this.tt.getRenderer();this.vt=t.getFrameTimestamp(),t.setToRedraw(!0)}}const vr=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")},Br=vr(),Lr=Br.gl_trans__coders=Br.gl_trans__coders||{};function Pr(t,e){if(e)for(let r=0;r<e.length;r++){t[e[r].id||e[r].index]=e[r]}}Lr.inject=function(t){const e=t.toString(),r=e.indexOf("{")+1,n=e.substring(0,r),i=Br.gl_trans__coders=Br.gl_trans__coders||{};let s=`${n}\n const _____getGlobal = ${vr.toString()};\n const g___lobals = _____getGlobal()\n const tran_____scoders = g___lobals['gl_trans__coders'] = g___lobals['gl_trans__coders'] || {};`;for(const t in i)"inject"!==t&&"getTranscoder"!==t&&"registerTranscoder"!==t&&(s+='tran_____scoders["'+t+'"] ='+i[t].toString()+"\n;");return s+="\n"+e.substring(n.length),s},Lr.registerTranscoder=function(t,e){Lr[t]=e},Lr.getTranscoder=function(t){return Lr[t]};const Dr=[];class Fr{constructor(t,e,r,n){this.de=t,this.Ct=e,this.Ee=n,this.Te=r.version,t.indexOf("i3s:tileset:")<0?(this.Te<=1.6?this.me="root":this.me=0,r.version=this.Te):(this.me=t.substring("i3s:tileset:".length),this.Te>1.6&&(this.me=parseInt(this.me))),this.de=t,this.Ae=r}load(){const t=this.Ae,e=t.layerScene.baseUrl;if(this.Te<=1.6)return t[this.me]&&t[this.me].lodSelection?(this.pe=t[this.me],this.ye()):new Promise((r=>{let n=e+"/nodes/"+this.me;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.Ee(this.Ct,n,(()=>{this.pe=t[this.me],r(this.ye())}))}));if(this.Te>=1.7){if(t[this.me])return this.pe=t[this.me],this.ye();const r=Math.floor(this.me/t.nodesPerPage);return new Promise((n=>{let i=e+"/nodepages/"+r;t.layerScene.eslpk&&(i+=".json"),this.Ee(this.Ct,i,(()=>{this.pe=t[this.me],n(this.ye())}))}))}return null}getTileset(){return this.ge}getChildrenURL(){return this.Re}ye(){const t=this.Ae,e=t.layerScene.baseUrl,r=this.pe.children,n=[],i={};if(r)for(let s=0;s<r.length;s++)if(this.Te<=1.6){const o=r[s].id;if(t[o])continue;const a=o;i[a]||(i[a]=new Promise((r=>{let n=e+"/nodes/"+a;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.Ee(this.Ct,n,(()=>{r()}))})),n.push(i[a]))}else{const o=r[s];if(t[o])continue;const a=Math.floor(o/t.nodesPerPage);i[a]||(i[a]=new Promise((r=>{let n=e+"/nodepages/"+a;t.layerScene.eslpk&&(n+=".json"),this.Ee(this.Ct,n,(()=>{r()}))})),n.push(i[a]))}return n.length?Promise.all(n).then((()=>this.be())):this.be()}be(){return Promise.resolve(this.Ie())}Ne(t){Pr(this.Ae,t)}Ie(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.Se(this.pe,!0)}}Se(t){const e=this.Te,r=this.Ae,n=t;var i,s=n.obb,o=n.mbs,a={};if(o)i=kr([],o[0],o[1],o[2]),a.sphere=[...i,o[3]];else if(s){const t=function(t,e,r){const n=function(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=r+r,a=n+n,c=i+i,l=r*o,f=n*o,h=n*a,u=i*o,_=i*a,d=i*c,E=s*o,T=s*a,m=s*c;return t[0]=1-h-d,t[3]=f-m,t[6]=u+T,t[1]=f+m,t[4]=1-l-d,t[7]=_-E,t[2]=u-T,t[5]=_+E,t[8]=1-l-h,t}([],r);return n[0]=n[0]*e[0],n[1]=n[1]*e[0],n[2]=n[2]*e[0],n[3]=n[3]*e[1],n[4]=n[4]*e[1],n[5]=n[5]*e[1],n[6]=n[6]*e[2],n[7]=n[7]*e[2],n[8]=n[8]*e[2],[...t,...n]}(i=kr([],s.center[0],s.center[1],s.center[2]),s.halfSize,s.quaternion),e=t[3]+t[6]+t[9],r=t[4]+t[7]+t[10],n=t[5]+t[8]+t[11];G(Dr,e,r,n);const o=q(Dr);a.sphere=[...i,o]}var c=1/0,l=0;if(n.mbs?l=n.mbs[3]:n.obb&&(l=Math.max(Math.max(n.obb.halfSize[0],n.obb.halfSize[1]),n.obb.halfSize[2])),void 0!==n.lodThreshold)"maxScreenThresholdSQ"===r.lodSelectionMetricType?c=l/(Math.sqrt(n.lodThreshold)/(.25*Math.PI)):console.error("Unsupported lodSelectionMetricType in Layer");else if(void 0!==n.lodSelection)for(var f=0;f<n.lodSelection.length;f++)"maxScreenThreshold"===n.lodSelection[f].metricType&&(c=l/n.lodSelection[f].maxError);(c===1/0||isNaN(c))&&(c=1e5);var h=16*c;const u=B([]),_=n.children;var d;if(_){d=[];const t=this.Ae;for(let r=0;r<_.length;r++){const n=e<=1.6?_[r].id:_[r];if(!t[n]){d=null;break}d.push(this.Se(t[n]))}}var E={refine:"REPLACE",boundingVolume:a,transform:u,geometricError:h};return e<=1.6?t.lodSelection?t.geometryData&&(E.content={uri:"i3s:mesh:"+(t.id||t.index)}):E.content={uri:"i3s:tileset:"+(t.id||t.index)}:_&&_.length&&!d?E.content={uri:"i3s:tileset:"+(t.id||t.index)}:n.mesh&&(E.content={uri:"i3s:mesh:"+(t.id||t.index)}),d&&d.length&&(E.children=d),E}getJSON(){return this.pe}}function kr(t,e,r,n){return ne(t,p(e),p(r),n)}const Gr=!!Lr.ktx2,Hr=r.mat4.identity([]),Vr=(()=>{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 zr(t){return t.indexOf("i3s:mesh")>=0}const Xr="i3s:mesh:".length;function Yr(t,e,r,n,i){const s=e.layerScene.eslpk,o=function(t,e){const r=e.substring(Xr);return t>=1.7?parseInt(r):r}(e.version,t),a=e[o],c=e.layerScene.baseUrl,l=[];let f=!1;const h=Hr;let u,_;if(e.version<=1.6){if(!a.geometryData)return null;const t=a.geometryData.length;let r=c+`/nodes/${a.id}/`+a.geometryData[t-1].href;s&&(r+=".bin");const n={geometry:{url:r,info:e.layerScene.store.defaultGeometrySchema}};let i=a.textureData&&a.textureData[0]&&a.textureData[0].href;if(i){const t=e.layerScene.store.textureEncoding[0];let r;r="image/jpeg"===t?"jpg":"png",s&&(i+="."+r);const o={pbrMetallicRoughness:{baseColorTexture:{url:c+`/nodes/${a.id}/`+i,factor:1,format:r,mimeType:t},metallicFactor:0}};n.material=o}l.push(n)}else{u=a.mesh.geometry,_=a.mesh.material;const t=e.layerScene.geometryDefinitions[u.definition],{geometryBuffers:o}=t;f=n&&2===o.length;const h=Lr.draco&&f?o[1]:o[0],d=Lr.draco&&f?1:0;let E=c+`/nodes/${u.resource}/geometries/`+d;s&&(E+=".bin");const T={geometry:{url:E,info:h}};if(i&&Vr&&f&&!Lr.draco)throw new Error("Must import @maptalks/transcoder.draco to load i3s draco compressed geometry");const m=e.layerScene.materialDefinitions,A=e.layerScene.textureSetDefinitions;let p,y=0;if(_&&(y=m[_.definition]),m){p=function(t,e,r,n,i,s){const o=JSON.parse(JSON.stringify(t));return Wr(o,e,r,n,i,s),o}(y,A,c,_.resource,r,e.layerScene.eslpk)}else p={pbrMetallicRoughness:{metallicFactor:0}};T.material=p,l.push(T)}return{dracoCompression:f,meshes:l,nodeIndex:o,center:a.obb&&a.obb.center||a.mbs&&[a.mbs[0],a.mbs[1],a.mbs[2]],transform:h}}function Wr(t,e,r,n,i,s){for(const o in t)if(t[o]&&t[o].textureSetDefinitionId>=0){const a=e[t[o].textureSetDefinitionId],c="images/"+a.formats[0].format,l=Zr(a.formats,i),f={url:r+`/nodes/${n}/textures/${l.name}`,factor:void 0===t[o].factor?1:t[o].factor,format:l.format,mimeType:c};if(s){let t="";switch(l.format){case"dds":t="bin.dds";break;case"jpg":case"png":t=l.format}f.url+="."+t}t[o]=f}else A(t[o])&&Wr(t[o],e,r,n,i,s)}function Zr(t,e){for(let r=0;r<=t.length;r++){const n=t[r].format;if("dds"===n&&e.hasExtension("WEBGL_compressed_texture_s3tc"))return t[r];if("jpg"===n||"png"===n)return t[r];if("ktx2"===n&&Gr)return t[r]}return null}const Kr=[];class jr extends i.renderer.CanvasRenderer{constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new jt(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.we={},this.Oe=[],this.Ee=this.Me.bind(this)}getAnalysisMeshes(){if(!this.painter)return Kr;const t=this.painter.getPaintedMeshes();if(!t)return Kr;const e=[],{b3dmMeshes:r,pntsMeshes:n,i3dmMeshes:i}=t;return r.length&&x(e,r),n.length&&x(e,n),i.length&&x(e,i),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.Oe.length||super.needToRedraw())}getFrameTimestamp(){return this.xe}drawOnInteracting(t,e,r){this.draw(e,r)}draw(t,e){this.xe=t;const r=this.prepareCanvas();if(r&&!r.intersects(this.canvasExtent2D))return void this.completeRender();const{root:n,tiles:i}=this.layer.getTiles(),s=i.length;if(!i||!s)return void this.completeRender();this.Ce(),this.Ue();const{selectedTiles:o,leaves:a,requests:c}=this.ve(n,i);c.length&&this.loadTiles(c),this.Be(o,a,e),this.Le(),c.length||this.completeRender()}ve(t,e){let r=[];this.Pe();let n=0;const i=this.De(),s={};let o=!1,a=!1;for(let t=0;t<e.length;t++){const i=e[t],c=i.node;if(s[c.id])continue;s[c.id]=1;let l=!1;const f=this.getCachedTile(c.id);if(this.Fe(c.id)?(n++,l=a=!0,this.tilesLoading[c.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=a=!0),(!i.node.ke||i.node.ke<=500)&&(o=!0,i.selected=!0,i.data=f)):this.painter.has(c)||(l=a=!0,r.push(c)),!l)continue;if(this.Ge(i))o=!0;else{this.He(i).length&&(o=!0)}}let c=[],l={};if(o&&({selectedTiles:c,leaves:l}=this.Ve(t)),r.length>1&&(r.sort(qr),i)){const t=i-n;r=t>0?r.slice(0,t):[]}return{loading:a,requests:r,selectedTiles:c,leaves:l}}Ve(t){const e=[],r={};let n;const i=[t],s=[];for(;i.length>0||s.length>0;){if(s.length>0){const t=s[s.length-1];if(t.ze===i.length){s.pop(),t===n&&(t.leave=!0,r[t.node.id]=1),e.push(t);continue}}const t=i.pop(),o=t.children;if(t.selected)if("add"===t.node.refine)r[t.node.id]=1,t.selectionDepth=s.length,e.push(t);else{if(t.selectionDepth=s.length,n=t,0===o.length){t.leave=!0,r[t.node.id]=1,e.push(t);continue}s.push(t),t.ze=i.length}for(let t=0;t<o.length;t++)i.push(o[t])}return{selectedTiles:e,leaves:r}}Ge(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}He(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const r=t.Bt+1,n=[t.node];for(;n.length>0;){const i=n.pop().children;for(let s=0,o=i.length;s<o;s++){if((!i[s].content||!i[s].content.url)&&i[s].children&&i[s].children.length){n.push(i[s]);continue}const o=i[s].id;if(this.tileCache.has(o)){const r=this.layer.Xe(i[s],t);r.selected=!0,r.data=this.tileCache.get(o),t.children.push(r),e.push(r)}else i[s].Bt<=r&&n.push(i[s])}}return e}Be(t,e,r){this.tileCache.markAll(!1);for(let e=0,r=t.length;e<r;e++){const r=t[e].data;r.current=!0,this.tileCache.add(t[e].node.id,r)}this.tileCache.shrink();const n={tiles:t,leaves:e};this.onDrawTileStart(n);const i=this.painter.paint(t,e,r);this.onDrawTileEnd(n),i&&this.layer.fire("canvasisdirty",{renderCount:i})}onDrawTileStart(){}onDrawTileEnd(){}loadTiles(t){for(let e=0,r=t.length;e<r;e++){const r=t[e];this.tilesLoading[r.id]={current:!0,node:r},this.loadTile(r)}}loadTile(t){let e=t.content.url;if(O(e)){const r=M(e);return void this.Ye(e,r,t)}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const r=t.Ct,n=this.We[r];return new Fr(e,r,n,this.Ee).load().then((r=>{this.onTilesetLoad(r,t,e)}))}t&&-1===e.indexOf("http://")&&-1===e.indexOf("https://")&&!zr(e)&&(e=t.baseUrl+e);const r=this.layer.options.services[t.Ct];if(r.ajaxInMainThread){let n=r.urlParams;n&&(n=(e.indexOf("?")>0?"&":"?")+n);let i=At.getArrayBuffer(e+(n||""),r.fetchOptions);const s=i.xhr;i=i.then((r=>{delete this.we[e],r?this.Ye(e,r.data,t):this.onTileError(null,t)})).catch((r=>{delete this.we[e],this.onTileError(r,t)})),this.we[e]=s}else this.Ye(e,null,t)}Ye(t,e,n){let i=this.l;i||(i=r.reshader.Util.getSupportedFormats(this.gl.gl||this.gl),this.l=i);const s=this.layer.options.services[n.Ct];s.isSuperMapiServer&&(t=function(t,e){const r=t.substring(e.length).split("/"),n=[];for(let t=0;t<r.length;t++)n.push(encodeURIComponent(r[t]));return e+n.join("/")}(t,n.baseUrl));const o={url:t=this.layer.getTileUrl(t,n.baseUrl,s),arraybuffer:e,rootIdx:n.Ct,upAxis:n.ee,transform:n.matrix,supportedFormats:i};if(zr(t)){const e=this.We[n.Ct];if(o.i3sInfo=Yr(t,e,this.regl,this.layer.options.enableI3SCompressedGeometry,this.layer.options.forceI3SCompressedGeometry),!o.i3sInfo)return void this.onTileError({status:404},n)}this.workerConn.loadTile(this.layer.getId(),o,((e,r)=>{if(e)return void this.onTileError(e,n);const{magic:i}=r;"b3dm"===i||"pnts"===i||"i3dm"===i||"cmpt"===i?this.Oe.push({data:r,tile:n}):this.onTilesetLoad(r,n,t)}))}Ue(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let r=0;for(;this.Oe.length&&(r<e||!t.isInteracting());){const{data:t,tile:e}=this.Oe.shift(),{magic:n}=t;"b3dm"===n?this.painter.createB3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.Ze(t,e,r,n)})):"pnts"===n?this.painter.createPntsMesh(t,e.id,e,((r,{mesh:n})=>{this.Ze(t,e,r,n)})):"i3dm"===n?this.painter.createI3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.Ze(t,e,r,n)})):"cmpt"===n&&this.painter.createCMPTMesh(t,e.id,e,((r,{mesh:n})=>{this.Ze(t,e,r,n)})),r++}}Ze(t,e,r,n){if(r)this.onTileError(r,e);else{const r=this.Ke(n);e.memorySize=r,this.onTileLoad(t,e)}}Ke(t){let e=0;if(Array.isArray(t))for(let r=0;r<t.length;r++)t[r]&&(e+=this.Ke(t[r]));else t&&(e+=t.getMemorySize());return e}onTileLoad(t,e){this.layer&&(delete this.tilesLoading[e.id],this.layer.onTileLoad(t,e),this.je(e),this.setToRedraw(),this.layer.fire("tileload",{node:e}))}onTilesetLoad(t,e,r){this.layer&&(t.capabilities||t.layers&&t.layers[0]&&t.layers[0].capabilities?this.qe(t,e,r):(delete this.tilesLoading[e.id],this.layer.onTilesetLoad(t,e,r)))}onTileError(t,e){if(!this.layer)return;const r=e.content.url;console.warn("failed to load 3d tile: "+r),console.warn(t),delete this.tilesLoading[e.id],this.$e(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}$e(t,e){const r={loadTime:i.Util.now(),current:!0,error:e,node:t};this.tileCache.add(t.id,r)}je(t){const e={loadTime:i.Util.now(),current:!0,node:t};this.tileCache.add(t.id,e)}abortTileLoading(t){if(!t||!this.workerConn)return;const e=t.node.content.url;if(this.layer.options.services[t.node.Ct].ajaxInMainThread){const t=this.we[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.we[e]}Pe(){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.Qe(this.canvas,e)),this.regl=this.regl||r.createREGL({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 Ur(this.regl,t),this.layer.Je()}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new Wt("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let r=this.layer.options||{};r=T({},r),delete r.offset,r.projection=t.getSpatialReference().getProjection().code;const n=this.layer.getId();e.addLayer(n,r,(t=>{if(t)throw t;this.layer&&(this.ready=!0,this.layer.fire("workerready"))}))}onRemove(){this.painter&&this.painter.remove(),this.pickingFBO&&(this.canvas.pickingFBO||this.pickingFBO.destroy(),delete this.pickingFBO),this.workerConn&&(this.workerConn.removeLayer(this.layer.getId(),(t=>{if(t)throw t})),this.workerConn.remove(),delete this.workerConn),this.clear(),delete this.tileCache,super.onRemove()}clear(){this.Le(!0),this.tileCache.reset(),this.tilesLoading={},super.clear()}clearCanvas(){this.regl&&this.regl.clear({color:[0,0,0,0],depth:1,stencil:0}),super.clearCanvas()}getTileOpacity(){return 1}getStencilValue(){return 0}Le(t){this.tr||(this.tr=Date.now());const e=Date.now();if(t||!(e-this.tr<this.layer.options.retireInterval)){this.tr=e;for(const e in this.tilesLoading){const r=this.tilesLoading[e];!t&&r.current||this.abortTileLoading(r)}}}De(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}Qe(t,e){const r=["webgl","experimental-webgl"];let n=null;for(let i=0;i<r.length;++i){try{n=t.getContext(r[i],e)}catch(t){}if(n)break}return n}Fe(t){return!!this.tilesLoading[t]}getI3DMMeshes(){return this.painter.getI3DMMeshes()}getPNTSMeshes(){return this.painter.getPNTSMeshes()}getB3DMMeshes(){return this.painter.getB3DMMeshes()}readBatchData(t,e,r){return be(t,e,0,r)}Ce(){if(!this.er)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const r=[];for(const n in this.er){const i=this.er[n];if("pending"===i.status)continue;i.status="pending";const s=i.rootIdx;if(r.push(At.getJSON(n).then((t=>{delete this.er[n];const e=this.We[s];if(e){t.nodes?Pr(e,t.nodes):(e[t.id]=t,Pr(e,t.children));for(let t=0;t<i.length;t++)i[t]();this.setToRedraw()}else this.setToRedraw()}))),e++,e>=t)break}r.length&&Promise.all(r)}Me(t,e,r){this.er||(this.er={}),this.er[e]=this.er[e]||[],this.er[e].rootIdx=t,this.er[e].push(r),this.setToRedraw()}qe(t,e,r){this.We||(this.We=[]);const n=e.Ct;this.We[n]||(this.We[n]={});const i=this.We[n],s=this.layer.options.services[n];t.layers&&(t=t.layers[0],"/"!==r[r.length-1]&&(r+="/"),r+="layers/0"),i.version=+(s.i3sVersion||t.store.version),function(t,e,r,n,i,s){if(!i.layerScene){i.layerScene=t,i.nodesPerPage=t.nodePages&&t.nodePages.nodesPerPage||64,i.lodSelectionMetricType=t.nodePages&&t.nodePages.lodSelectionMetricType;let e=n;if(i.layerScene.eslpk=e.indexOf("3dSceneLayer.json")>=0,e.endsWith(".json")){const t=n.lastIndexOf("/");e=t<0?"./":n.substring(0,t)}i.layerScene.baseUrl=function(t){return t.split("?")[0]}(e)}return new Fr(n,e,i,s).load()}(t,n,0,r,i,this.Ee).then((t=>{this.onTilesetLoad(t,e,r)}))}pick(t,e,r){return this.painter?this.painter.pick(t,e,r&&r.tolerance):[]}highlight(t){if(this.Ut||(this.Ut=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const r=t[e].service||0;let n=this.Ut[r];n||(n=this.Ut[r]=new Map),n.set(t[e].id,t[e])}else{const e=t.service||0;let r=this.Ut[e];r||(r=this.Ut[e]=new Map),r.set(t.id,t)}this.painter.highlight(this.Ut)}cancelHighlight(t,e){if(!this.Ut)return;const r=this.Ut[t];if(r){if(Array.isArray(e))for(let t=0;t<e.length;t++)r.delete(e[t]);else r.delete(e);this.painter.highlight(this.Ut)}}cancelAllHighlight(){delete this.Ut,this.painter.cancelAllHighlight()}}function qr(t,e){return t.Vt-e.Vt}function $r(t,e,r){return t[0]=e[r],t[1]=e[r+3],t[2]=e[r+6],t}function Qr(t,e,r){return Math.sqrt(function(t,e,r){var n=V(Jr,r,t),i=$r(tn,e,0),s=$r(en,e,1),o=$r(rn,e,2),a=q(i),c=q(s),l=q(o);Y(i,i),Y(s,s),Y(o,o);var f=nn;f[0]=W(n,i),f[1]=W(n,s),f[2]=W(n,o);var h,u=0;f[0]<-a?u+=(h=f[0]+a)*h:f[0]>a&&(u+=(h=f[0]-a)*h);f[1]<-c?u+=(h=f[1]+c)*h:f[1]>c&&(u+=(h=f[1]-c)*h);f[2]<-l?u+=(h=f[2]+l)*h:f[2]>l&&(u+=(h=f[2]-l)*h);return u}(t,e,r))}const Jr=[],tn=[],en=[],rn=[],nn=[];const sn=2*Math.PI;class on{constructor(t,e,r,n){this.west=t,this.south=e,this.east=r,this.north=n}static contains(t,e){var r=e[0],n=e[1],i=t.west,s=t.east;return s<i&&(s+=sn,r<0&&(r+=sn)),(r>i||me(r,i,1e-14))&&(r<s||me(r,s,1e-14))&&n>=t.south&&n<=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 an=[0,0,1];function cn(t,e){return ne(e,t[0],t[1],t[2])}class ln{constructor(t,e){this.normal=r.vec3.copy([],t),this.distance=e}static fromPointNormal(t,e,n){var i=-r.vec3.dot(e,t);return r.vec3.copy(n.normal,e),n.distance=i,n}}const fn=[],hn=[],un=[],_n=[],dn=[],En=[],Tn=[],mn=[],An=[],pn=[],yn=new ln([1,0,0],0),gn=[];class Rn{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new on(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){var n,i,s,o=0;if(!on.contains(this.rectangle,e)){var a=this.southwestCornerCartesian,c=this.northeastCornerCartesian,l=this.westNormal,f=this.southNormal,h=this.eastNormal,u=this.northNormal,_=r.vec3.subtract(gn,t,a),d=r.vec3.dot(_,l),E=r.vec3.dot(_,f),T=r.vec3.subtract(gn,t,c),m=r.vec3.dot(T,h),A=r.vec3.dot(T,u);d>0?o+=d*d:m>0&&(o+=m*m),E>0?o+=E*E:A>0&&(o+=A*A)}if(n=e[2],i=this.minimumHeight,n>(s=this.maximumHeight)){var p=n-s;o+=p*p}else if(n<i){var y=i-n;o+=y*y}return Math.sqrt(o)}computeBox(t){const e=this;cn(on.southwest(t,hn),e.southwestCornerCartesian),cn(on.northeast(t,hn),e.northeastCornerCartesian),fn[0]=t.west,fn[1]=.5*(t.south+t.north),fn[2]=0;var n=cn(fn,un),i=r.vec3.cross(dn,n,an);r.vec3.normalize(e.westNormal,i),fn[0]=t.east;var s=cn(fn,mn),o=r.vec3.cross(dn,an,s);r.vec3.normalize(e.eastNormal,o);var a,c=r.vec3.subtract(dn,n,s),l=r.vec3.normalize(_n,c),f=t.south;if(f>0){fn[0]=.5*(t.west+t.east),fn[1]=f;var h=cn(fn,An);r.vec3.copy(pn,l);var u=ln.fromPointNormal(e.southwestCornerCartesian,e.westNormal,yn);bn(An,pn,u,e.southwestCornerCartesian),a=de(h,En)}else a=Ee(on.southeast(t,hn),En);var _=r.vec3.cross(Tn,a,c);r.vec3.normalize(e.southNormal,_);var d,E=t.north;if(E<0){fn[0]=.5*(t.west+t.east),fn[1]=E;var T=cn(fn,An);r.vec3.scale(pn,l,-1);var m=ln.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,yn);bn(An,pn,m,e.northeastCornerCartesian),d=de(T,En)}else d=Ee(on.northwest(t,hn),En);var A=r.vec3.cross(Tn,c,d);r.vec3.normalize(e.northNormal,A)}}function bn(t,e,n,i){var s=t,o=e,a=n.normal,c=r.vec3.dot(a,o);if(!(Math.abs(c)<1e-15)){var l=(-n.distance-r.vec3.dot(a,s))/c;if(!(l<0))return i=r.vec3.scale(i,o,l),r.vec3.add(i,s,i)}}const In=new i.Extent(0,0,0,0),Nn=new i.Extent(0,0,0,0),Sn=[],wn=[],On=[],Mn=[],xn=new i.Point(0,0),Cn=[],Un=new i.Coordinate(0,0),vn=r.mat4.identity([]);class Bn extends i.Layer{constructor(t,e){super(t,e),this.rr(),this.we={},this.nr=[]}rr(){let t=this.options.services.map((t=>t.url));this.ir=t.map(((t,e)=>function(t,e){t=g(t);return{visible:1,baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:r.mat4.identity([]),Ct:e,Bt:0}}(t,e))),this.fire("rootready",{roots:this.ir.slice(0)})}showService(t){return this.sr(t,1),this}hideService(t){return this.sr(t,0),this}sr(t,e){const r=this.ir[t];if(!r)return;r.visible=e;const n=this.getRenderer();n&&n.setToRedraw()}getTileUrl(t){return t}getExtent(t){if(!t&&0!==t){const t=new i.Extent;for(let e=0;e<this.ir.length;e++)if(this.ir[e].boundingVolume){const r=this.boundingVolumeToExtent(this.ir[e]);t._combine(r)}return t}return this.ir[t]&&this.ir[t].boundingVolume?this.boundingVolumeToExtent(this.ir[t]):null}boundingVolumeToExtent(t){const e=t.boundingVolume.ar?vn:t.matrix,n=this.getMap();if(t.boundingVolume.region){const e=t.boundingVolume.region;return new i.Extent(y(e[0]),y(e[1]),y(e[2]),y(e[3]))}if(t.boundingVolume.sphere){const s=t.boundingVolume.sphere,o=le([],r.vec3.transformMat4([],s,e)),a=s[3],c=n.locate(o,-a,a),l=n.locate(o,a,-a);return new i.Extent(c,l)}if(t.boundingVolume.box){const s=t.boundingVolume.box,o=r.vec3.transformMat4([],s,e),a=new i.Coordinate(le([],o)),c=s.slice(3);r.mat3.multiply(c,r.mat3.fromMat4([],t.matrix),c);const l=r.vec3.length(c.slice(0,3)),f=r.vec3.length(c.slice(3,6)),h=r.vec3.length(c.slice(6,9)),u=Math.max(l,f,h),_=n.locate(a,-u,u),d=n.locate(a,u,-u);return new i.Extent(_,d)}return null}getRootTiles(){return this.ir}getTiles(){const t=this.getRenderer();if(!t.ready)return this.cr(),{tiles:Mn};const e=this.getMap(),n=e.cameraPosition;let i,s;if(e.getGLZoom)s=e.pointToDistance(n[2],0,e.getGLZoom()),Un.set(n[0],n[1]),i=e.pointToCoord(Un,e.getGLZoom());else{const t=e.getGLRes();s=e.pointAtResToDistance(n[2],0,t),Un.set(n[0],n[1]),i=e.pointAtResToCoord(Un,t)}this.lr=this.lr||[],r.vec3.set(this.lr,p(i.x),p(i.y),s),this.hr=ne(this.hr||[],this.lr[0],this.lr[1],this.lr[2]),this.ur=2*Math.tan(.5*p(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const l=[];for(let e=0;e<this.ir.length;e++){const r=this.ir[e];if(!r.visible)continue;let n=1/0;const i=[r],s=this._r(e);for(;i.length>0;){const e=i.pop();for(e.id||this.dr(e);c.level>=e.Bt;)c=c.parent;const r=this.Er(e,s,o);if(r<1){let t=c;for(;t&&!t.content;)t=t.parent;0===r&&t&&t.content&&this.Tr(l,t);if(!1===this.options.services[e.Ct].alwaysShow)continue;if(!(0===r&&e.Bt<=n))continue;e.content&&(n=e.Bt)}e.Vt<1/0&&this.mr(e);const a=this.Xe(e,c);c.children.push(a);const f=e.children,h=f&&f.length,u=a.content;if(!h&&u&&this.Tr(l,a),h){u&&"add"===e.refine&&this.Tr(l,a),c=a;const r=f[0].parent;let n=!1;for(let s=0,o=f.length;s<o;s++){if(r){const e=t.getCachedTile(f[s].id);if(e&&e.error&&404!==e.error.status)continue;n=!0}else{n=!0,f[s].parent=e,f[s].ee=e.ee,f[s].baseUrl=e.baseUrl;const t=f[s].content&&(f[s].content.url||f[s].content.uri);t&&(O(t)||t.indexOf("i3s:")>=0?f[s].baseUrl=e.baseUrl:-1===t.indexOf("http://")&&-1===t.indexOf("https://")?f[s].content.url=e.baseUrl+t:f[s].baseUrl=t.substring(0,t.lastIndexOf("/")+1))}i.push(f[s])}!n&&u&&this.Tr(l,a)}}}return{root:a,tiles:l}}Tr(t,e){const{viewerRequestVolume:r}=e.node;r&&!function(t,e,r){if(r.region){const e=r.region;if(t[0]>=e[0]&&t[0]<=e[2]&&t[1]>=e[1]&&t[1]<=e[3])return!0}else{if(r.sphere)return Ln(r,e);if(r.box)return 0===Pn(r,e)}return!1}(this.lr,this.hr,r)||t.push(e)}Xe(t,e){return{id:t.id,node:t,children:[],level:t.Bt,parent:e,content:t.content&&t.content.url}}dr(t){t.id=i.Util.GUID(),t.matrix=t.transform||r.mat4.identity([]),t.Ar=this.pr(t),t.parent&&(function(t){return t.content&&t.content.uri&&t.content.uri.indexOf("i3s:")>=0}(t)||(t.matrix=r.mat4.multiply(t.matrix,t.parent.matrix,t.matrix)),t.Ct=t.parent.Ct,void 0===t.Bt&&(t.Bt=t.parent.Bt+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),this.yr(t)}yr(t){const e=t.boundingVolume;if(!e||e.ar)return;const n=this.options.services[t.Ct].heightOffset||0,i=this.options.offset,s=m(i)||i[0]||i[1];if(!t.boundingVolume||!n&&r.mat4.exactEquals(t.matrix,vn)&&!s)return;const{region:o,box:a,sphere:c}=e;if(o){const t=this.gr([y(o[0]),y(o[1])]);o[0]=p(t.x),o[1]=p(t.y);const e=this.gr([y(o[2]),y(o[3])]);o[2]=p(e.x),o[3]=p(e.y),o[4]+=n,o[5]+=n}else if(a||c){const e=a||c,i=r.vec3.transformMat4(Sn,e,t.matrix),s=le(wn,i),o=this.gr([s[0],s[1]]);s[0]=o.x,s[1]=o.y,s[2]+=n,ne(e,p(s[0]),p(s[1]),s[2])}e.ar=!0}pr(t){return void 0===t.geometricError||!t.boundingVolume}mr(t){let e=t.parent;for(;e&&e.Ar&&!(e.Vt<=t.Vt);)e.Vt=t.Vt,e=t.parent}onTileLoad(t,e){if(t.children&&(!e.children||!e.children.length)){e.children=t.children;const r=e.content.url;e.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const n=this.getRenderer();n&&n.setToRedraw()}}onTilesetLoad(t,e,n){if(!t)return void console.warn("invalid tileset at : "+n);const i=this.options.services[e.Ct],s=(t.asset&&t.asset.gltfUpAxis||e&&e.ee||i.upAxis||"Y").toUpperCase();t.root.baseUrl=n.substring(0,n.lastIndexOf("/")+1);const o=n.indexOf("realspace/")>-1;0===e.Bt&&(t.asset&&t.asset.s3mType&&o||i.isSuperMapiServer)&&(t.root.baseUrl+="data/path/");const a=t.asset.i3s;if(t.root.ee=s,e){const n=e.boundingVolume;T(e,t.root),e.refine=e.refine&&e.refine.toLowerCase()||"replace",n&&(e.boundingVolume=n);const i=t.root.transform;i&&(e.parent?a||(e.matrix=r.mat4.multiply([],e.parent.matrix,i)):e.matrix=i),this.yr(e),e.Rr=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.Ar=this.pr(e);const s=e.content&&(e.content.url||e.content.uri);s&&e.content.uri&&(e.content.url=e.content.uri,delete e.content.uri),a||!s||O(s)||-1!==s.indexOf("http://")||-1!==s.indexOf("https://")||(e.content.url=e.baseUrl+s)}this.cr(),this.fire("loadtileset",{tileset:t,index:e.Ct,url:n})}Er(t,e,r){if(t.Vt=1/0,0===t.Bt||t.Ar)return 1;if(!this.br(t,e,r))return-1;if(0===t.geometricError)return 1;let n=this.options.services[t.Ct].maximumScreenSpaceError;null==n&&(n=8);let i=this.Ir(t);return 0===i&&t.parent&&(i=.5*(t.parent.ke||0)),i>=n?1:0}jt(t,e){e||(e=new i.Point(0,0));const r=this.getMap();return r.getGLZoom?r.coordToPoint(t,r.getGLZoom(),e):r.coordToPointAtRes(t,r.getGLRes(),e)}br(t,e,n){const s=t.id;let o=this.nr[s];const{boundingVolume:c}=t,l=c.sphere;let _=c.region;const E=c.box;if(!o){let e,n,a;if(E&&(_=function(t,e){for(let e=0;e<9;e++)Wn[e]=t[e+3];const n=Wn;r.mat4.exactEquals(e,vn)||r.mat3.multiply(n,r.mat3.fromMat4(Cn,e),n);const i=r.vec3.copy(Dn,t),s=r.vec3.set(Fn,n[0],n[1],n[2]),o=r.vec3.set(kn,n[3],n[4],n[5]),a=r.vec3.set(Gn,n[6],n[7],n[8]);Hn[0]=Hn[0]||[];const c=r.vec3.copy(Hn[0],i);r.vec3.sub(c,c,s),r.vec3.sub(c,c,o),r.vec3.sub(c,c,a),Hn[1]=Hn[1]||[];const l=r.vec3.copy(Hn[1],i);r.vec3.sub(l,l,s),r.vec3.sub(l,l,o),r.vec3.add(l,l,a),Hn[2]=Hn[2]||[];const f=r.vec3.copy(Hn[2],i);r.vec3.sub(f,f,s),r.vec3.add(f,f,o),r.vec3.sub(f,f,a),Hn[3]=Hn[3]||[];const h=r.vec3.copy(Hn[3],i);r.vec3.sub(h,h,s),r.vec3.add(h,h,o),r.vec3.add(h,h,a),Hn[4]=Hn[4]||[];const u=r.vec3.copy(Hn[4],i);r.vec3.add(u,u,s),r.vec3.sub(u,u,o),r.vec3.sub(u,u,a),Hn[5]=Hn[5]||[];const _=r.vec3.copy(Hn[5],i);r.vec3.add(_,_,s),r.vec3.sub(_,_,o),r.vec3.add(_,_,a),Hn[6]=Hn[6]||[];const d=r.vec3.copy(Hn[6],i);r.vec3.add(d,d,s),r.vec3.add(d,d,o),r.vec3.sub(d,d,a),Hn[7]=Hn[7]||[];const E=r.vec3.copy(Hn[7],i);r.vec3.add(E,E,s),r.vec3.add(E,E,o),r.vec3.add(E,E,a);for(let t=0;t<Hn.length;t++)Vn[t]=Vn[t]||[],le(Vn[t],Hn[t]),zn[t]=Vn[t][0],Xn[t]=Vn[t][1],Yn[t]=Vn[t][2];return[p(Math.min(...zn)),p(Math.min(...Xn)),p(Math.max(...zn)),p(Math.max(...Xn)),Math.min(...Yn),Math.max(...Yn)]}(E,t.matrix),c.region=_),_){e=In.set(y(_[0]),y(_[1]),y(_[2]),y(_[3]));const t=e.getCenter(),r=this.Nr(t);e=e.convertTo((t=>this.jt(t,xn)),Nn),a=_[4],n=_[5],o=this.nr[s]=[[e.xmin,e.ymin,a*r[2]],[e.xmax,e.ymax,n*r[2]]],o.center=t}else if(l){const t=le(Sn,l),e=new i.Coordinate(t),r=this.jt(e,xn).toArray(),n=this.Nr(e);r.push(t[2]*n[2]),o=this.nr[s]=[r,l[3]*n[2]],o.center=e}}if(e){if(_)In.xmin=o[0][0],In.ymin=o[0][1],In.xmax=o[1][0],In.ymax=o[1][1];else if(l){const t=o[2];In.xmin=o[0][0]-t,In.ymin=o[0][1]-t,In.xmax=o[0][0]+t,In.ymax=o[0][1]+t}else if(E){const t=o[1],e=o[2];In.xmin=o[0][0]-t,In.ymin=o[0][1]-e,In.xmax=o[0][0]+t,In.ymax=o[0][1]+e}if(!e.intersects(In))return!1}return _?f(n,o):l?function(t,e,r){u(t);for(var n=e[0],i=-e[1],s=0;s<6;s++)if((!r||"0"!==r.charAt(s))&&d(a[s],n)<i)return!1;return!0}(n,o):!!E&&function(t,e,r){u(t);for(var n=0;n<6;n++)if(!(r&&"0"===r.charAt(n)||h(a[n],e)))return!1;return!0}(n,o)}Nr(t){const e=this.getMap(),n=e.distanceToPointAtRes(100,100,e.getGLRes(),t);let i;return i=e.altitudeToPoint?e.altitudeToPoint(100,e.getGLRes())/100:n.y/100,r.vec3.set(On,n.x/100*1.01,n.y/100*1.01,i),On}gr(t){Array.isArray(t)&&(t=new i.Coordinate(t));let e=this.options.offset;if(m(e)&&(e=e(Array.isArray(t)?new i.Coordinate(t):t)),e[0]||e[1]){const r=this.getMap(),n=r.getGLRes(),i=r.coordToPointAtRes(t,n);return i._sub(e),r.pointAtResToCoord(i,n)}return t}_r(t){const e=this.options.services[t].maxExtent;if(!e)return null;const r=this.ir[t];return r.maxExtent||(r.maxExtent=new i.Extent(e).convertTo((t=>this.jt(t)))),r.maxExtent}Ir(t){const e=this.ur,r=t.geometricError;if(0===r)return t.ke=0,0;const n=this.getMap();let i;t.boundingVolume.region?i=function(t,e,r){t.Sr||(t.Sr=new Rn(t.boundingVolume.region));return t.Sr.distanceToCamera(e,r)}(t,this.hr,this.lr):t.boundingVolume.sphere?i=Ln(t.boundingVolume,this.hr):t.boundingVolume.box&&(i=Pn(t.boundingVolume,this.hr));const s=Math.max(Math.abs(i),1e-7),o=r*n.height/(s*e);return t.Vt=i,t.ke=o,o}cr(){const t=this.getRenderer();t&&t.setToRedraw()}oe(t){return this.nr[t]}identify(t,e={}){const r=this.getMap(),n=this.getRenderer();if(!r||!n)return[];const s=r.coordToContainerPoint(new i.Coordinate(t));return this.identifyAtPoint(s,e)}identifyAtPoint(t,e={}){const r=this.getMap(),n=this.getRenderer();if(!r||!n)return[];const i=r.getDevicePixelRatio();return n.pick(t.x*i,t.y*i,e)}highlight(t){const e=this.getRenderer();return e?(e.highlight(t),this):(this.Ut||(this.Ut=[]),this.Ut.push(t),this)}Je(){if(this.Ut){for(let t=0;t<this.Ut.length;t++)this.highlight(this.Ut[t]);delete this.Ut}}cancelHighlight(t,e){const r=this.getRenderer();return r?(r.cancelHighlight(t,e),this):this}cancelAllHighlight(){const t=this.getRenderer();return t?(t.cancelAllHighlight(),this):this}}function Ln(t,e){const n=t.sphere,i=r.vec3.dist(n,e),s=t.sphere[3];return i<s?0:i-s}function Pn(t,e){const n=t.box;return Qr(r.vec3.set(Sn,n[0],n[1],n[2]),r.mat3.set(Cn,n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10],n[11]),e)}Bn.mergeOptions({"maxGPUMemory":512,"retireInterval":2e3,"loadingLimitOnInteracting":5,"loadingLimit":0,"renderer":"gl","forceRenderOnZooming":!0,"forceRenderOnRotating":!0,"forceRenderOnMoving":!0,"debug":!1,"debugOutline":[0,1,0],"meshLimitPerFrame":1,"i3sNodepageLimitPerFrame":1,"enableI3SCompressedGeometry":!0,"forceI3SCompressedGeometry":!0,"picking":!0,"pickingPoint":!0,"geometryEvents":!1,"antialias":!1,"optionalExtensions":["ANGLE_instanced_arrays","OES_element_index_uint","OES_standard_derivatives","OES_vertex_array_object","OES_texture_half_float","OES_texture_half_float_linear","OES_texture_float","OES_texture_float_linear","WEBGL_depth_texture","EXT_shader_texture_lod","WEBGL_compressed_texture_astc","WEBGL_compressed_texture_etc","WEBGL_compressed_texture_etc1","WEBGL_compressed_texture_pvrtc","WEBGL_compressed_texture_s3tc","WEBGL_compressed_texture_s3tc_srgb"],"offset":[0,0]}),Bn.registerRenderer("gl",jr),Bn.registerJSONType("Geo3DTilesLayer");const Dn=[],Fn=[],kn=[],Gn=[],Hn=[],Vn=[],zn=[],Xn=[],Yn=[],Wn=[];class Zn{constructor(t,e,r){this.o=t,this.wr=e||Ft,this.l=r,this.Or={"image/crn":Lr.crn&&Lr.crn(),"image/ktx2":Lr.ktx2&&Lr.ktx2(),"image/cttf":Lr.ktx2&&Lr.ktx2(),"draco":Lr.draco&&Lr.draco()}}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.Mr(t,e,r,n,i)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Mr(t,i,r,n)}))}Mr(t,e,r,n,i){const s=i&&i.maxTextureSize,o=this.Cr(e,r,n,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.wr(a,o.glb,{transferable:!0,requestImage:this.o,decoders:this.Or,supportedFormats:this.l,maxTextureSize:s});return c.load({skipAttributeTransform:!1}).then((e=>{e.url=`${t}-${r}-${n}`;const i=c.transferables;for(let t=0;t<o.transferables.length;t++)i.indexOf(o.transferables[t])<0&&i.push(o.transferables[t]);return{magic:"b3dm",count:o.count,transferables:i,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,gltf:e}}))}Cr(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported b3dm version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in b3dm header is inconsistent with b3dm's byte length, url: "+n;return console.warn(t),{error:t}}let o,a=i.getUint32(12,!0),c=i.getUint32(16,!0),l=i.getUint32(20,!0),f=i.getUint32(24,!0),h=28+e;l>=570425344?(h-=8,o=a,l=c,f=0,a=0,c=0):f>=570425344&&(h-=4,o=l,l=a,f=c,a=0,c=0);const u=[t];let _,d,E;if(a>0?(_=ye(t,h,a),h+=a,o=_.BATCH_LENGTH):_={"BATCH_LENGTH":o},c>0&&(h+=c),l>0&&(d=ge(t,h,l),h+=l,f>0)){const e=Re(0,h,f);E=t.slice(e.offset,e.offset+e.byteLength),h+=f,u.push(E)}const T=_.BATCH_LENGTH,m={};if(_&&_.BATCH_ID){m.BATCH_ID=Ie(_.BATCH_ID,t,undefined.offset,T);const e=m.BATCH_ID.array&&m.BATCH_ID.array.buffer;e&&u.indexOf(e)<0&&u.push(e)}return{count:o,transferables:u,featureTable:_,batchTable:d,batchTableBin:E,b3dm:m,glb:{buffer:t,byteOffset:h,byteLength:i.byteLength+i.byteOffset-h}}}Ur(){return null}}class Kn{constructor(t,e,r,n){this.o=t,this.wr=e||Ft,this.l=r,this.Or={"image/crn":Lr.crn&&Lr.crn(),"image/ktx2":Lr.ktx2&&Lr.ktx2(),"image/cttf":Lr.ktx2&&Lr.ktx2(),"draco":Lr.draco&&Lr.draco()},this.vr=n}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.Mr(t,e,r,n,i)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Mr(t,i,r,n)}))}Mr(t,e,r,n,i){return this.Br(t,e,r,n,i).then((({gltf:i,transferables:s})=>{const o=this.Lr(e,r,n,t);if(o.error)return Promise.resolve(o);for(let t=0;t<s.length;t++)-1===o.transferables.indexOf(s[t])&&o.transferables.push(s[t]);return delete i.transferables,Promise.resolve({magic:"i3dm",count:o.count,transferables:o.transferables,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,i3dm:o.i3dm,gltf:i})}))}Br(t,e,r,n,i){const s=i&&i.maxTextureSize,o={transferable:!0,requestImage:this.o,decoders:this.Or,supportedFormats:this.l,maxTextureSize:s},a=new DataView(e,r,n),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 n=I(new Uint8Array(e,c+r,a.byteLength-c));-1==n.indexOf("://")&&(n=t.substring(0,t.lastIndexOf("/"))+"/"+n);return n.indexOf(".glb")>0?At.getArrayBuffer(n,{}).then((t=>this.Pr(n,{buffer:t.data,byteOffset:0},o))):At.getJSON(n,{}).then((t=>this.Pr(n,t,o)))}{const n={buffer:e,byteOffset:c+r,byteLength:a.byteLength-c};return this.Pr(t,n,o)}}Pr(t,e,r){const n=t.substring(0,t.lastIndexOf("/")),i=new this.wr(n,e,r);return i.load({skipAttributeTransform:!0}).then((r=>{let n=0,s=0;return e.buffer&&(n=e.byteOffset||0,s=e.byteLength||0),r.url=`${t}-${n}-${s}`,{transferables:i.transferables,gltf:r}}))}Lr(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported pnts version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+n;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:l,batchTableBin:f}=Ue(i,32+e,o),h={},u=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;h.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,r=a.QUANTIZED_VOLUME_SCALE,{byteOffset:n}=a.POSITION_QUANTIZED;h.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:u,componentType:5126,array:this.Dr(new Uint16Array(t,n+c.offset,3*u),e,r)},o.push(h.POSITION.array.buffer)}if(a.BATCH_ID){h.BATCH_ID=Ie(a.BATCH_ID,t,c.offset,u);const e=h.BATCH_ID.array&&h.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;h.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,h.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;h.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:this.Fr(new Uint16Array(t,e+c.offset,2*u))},o.push(h.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,h.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:this.Fr(new Uint16Array(t,e+c.offset,2*u))},o.push(h.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;h.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,u).slice()},o.push(h.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;h.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.SCALE_NON_UNIFORM.array.buffer)}return{count:u,batchTable:l,batchTableBin:f,featureTable:a,i3dm:h,transferables:o}}Fr(t){const e=t.length/2,r=new Float32Array(3*e),n=[];for(let i=0;i<e;i++)jn(n,t[2*i],t[2*i+1],65535),r[3*i]=n[0],r[3*i+1]=n[1],r[3*i+2]=n[2];return r}Dr(t,e,r){return Ce(new Float32Array(t.length),t,e,r)}Ur(){return null}}function jn(t,e,r,n){if(t[0]=qn(e,n),t[1]=qn(r,n),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]))*$n(e),t[1]=(1-Math.abs(e))*$n(t[1])}return Y(t,t)}function qn(t,e){return function(t,e,r){return t<e?e:t>r?r:t}(t,0,e=function(t,e){if(null!=t)return t;return e}(e,255))/e*2-1}function $n(t){return t<0?-1:1}class Qn{constructor(){}load(t,e,r=0,n=0){return e?(n||(n=e.byteLength),this.Mr(t,e,r,n)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Mr(t,i,r,n)}))}Mr(t,e,r,n){return this.kr(e,r,n,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}))}kr(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported pnts version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+n;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:l,batchTableBin:f}=Ue(i,e+28,o),h=a.QUANTIZED_VOLUME_OFFSET,u=a.QUANTIZED_VOLUME_SCALE,_=a.POINTS_LENGTH;let d,E={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){E=a.extensions["3DTILES_draco_point_compression"],d=new DataView(t,E.byteOffset+c.offset,E.byteLength);const e={attributes:E.properties,useUniqueIDs:!1};return this.Gr||(this.Gr=Lr.draco()),this.Gr(d,e).then((e=>{const r=e.attributes;!a.POSITION&&!a.POSITION_QUANTIZED||r.POSITION||r.POSITION_QUANTIZED||(r.POSITION=a.POSITION,r.POSITION_QUANTIZED=a.POSITION_QUANTIZED),!(a.RGB||a.RGBA||a.RGB565)||r.RGB||r.RGBA||r.RGB565||(r.RGB=a.RGB,r.RGBA=a.RGBA,r.RGB565=a.RGB565),!a.NORMAL&&!a.NORMAL_OCT16P||r.NORMAL||r.NORMAL_OCT16P||(r.NORMAL=a.NORMAL,r.NORMAL_OCT16P=a.NORMAL_OCT16P);const n=this.Hr(t,e.attributes,c.offset,_,o,h,u);if(e.attributes.BATCH_ID){const t=e.attributes.BATCH_ID.array;n.BATCH_ID={byteStride:0,byteOffset:0,itemSize:1,count:t.length,componentType:xe(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?n.BATCH_ID=Ie(a.BATCH_ID,t,c.offset,_):n.BATCH_ID=Jn(_);const e=n.BATCH_ID.array&&n.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return{count:_,batchTable:l,batchTableBin:f,featureTable:a,pnts:n,transferables:o}}))}const T=this.Hr(t,a,c.offset,_,o,h,u);if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?T.BATCH_ID=Ie(a.BATCH_ID,t,c.offset,_):T.BATCH_ID=Jn(_);const e=T.BATCH_ID.array&&T.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:_,batchTable:l,batchTableBin:f,featureTable:a,pnts:T,transferables:o})}Hr(t,e,r,n,i,s,o){const a={};if(e.POSITION){let{byteOffset:s,array:o}=e.POSITION;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n*4);o=new Float32Array(e)}a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:o},i.push(o.buffer)}else if(e.POSITION_QUANTIZED){let{byteOffset:c,array:l}=e.POSITION_QUANTIZED;c=c||0;const f=l?0:r;a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:this.Dr(l||new Uint16Array(t,c+f,3*n),s,o)},i.push(a.POSITION.array.buffer)}if(e.RGBA){let{byteOffset:s,array:o}=e.RGBA;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+4*n);o=new Uint8Array(e)}a.RGBA={byteStride:0,byteOffset:0,itemSize:4,count:n,componentType:5121,array:o},i.push(o.buffer)}else if(e.RGB){let{byteOffset:s,array:o}=e.RGB;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n);o=new Uint8Array(e)}a.RGB={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5121,array:o},i.push(o.buffer)}else if(e.RGB565){let{byteOffset:s,array:o}=e.RGB565;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+2*n);o=new Uint16Array(e)}a.RGB565={byteStride:0,byteOffset:0,itemSize:1,count:n,componentType:5123,array:o},i.push(o.buffer)}if(e.NORMAL){let{byteOffset:s,array:o}=e.NORMAL;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n*4);o=new Float32Array(e)}a.NORMAL={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:o},i.push(o.buffer)}else if(e.NORMAL_OCT16P){let{byteOffset:s,array:o}=e.NORMAL_OCT16P;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+2*n);o=new Uint8Array(e)}a.NORMAL_OCT16P={byteStride:0,byteOffset:0,itemSize:2,count:n,componentType:5121,array:o},i.push(o.buffer)}return a}Dr(t,e,r){return Ce(new Float32Array(t.length),t,e,r)}Ur(){return null}}function Jn(t){const e=w(t),r=new e(t);for(let e=0;e<t;e++)r[e]=e;return{byteStride:0,byteOffset:0,itemSize:1,count:t,componentType:xe(e),array:r}}class ti{constructor(t,e){this.o=t,this.wr=e||Ft}load(t,e,r=0,n=0,i){return e?this.Mr(t,e,r,n,i):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return this.Mr(t,i,r,n)}))}Mr(t,e,r,n,i){n||(n=e.byteLength);const s=this.Vr(e,t,r,n),o=[];for(let r=0;r<s.length;r++){let n;if("b3dm"===s[r].magic)n=new Zn(this.o,this.wr);else if("i3dm"===s[r].magic)n=new Kn(this.o,this.wr);else if("pnts"===s[r].magic)n=new Qn;else{if("cmpt"!==s[r].magic){console.warn("Unsupported magic in CMPT tile:",s[r].magic);continue}n=new ti(this.o,this.wr)}o.push(n.load(t,e,s[r].offset,s[r].byteLength,i).then((t=>t)))}return Promise.all(o).then((t=>({magic:"cmpt",tiles:t})))}Vr(t,e,r,n){const i=new DataView(t,r,n),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported cmpt version: "+s+", url:"+e;return console.warn(t),{error:t}}if(16===i.byteLength)return[];const o=[],a=i.getUint32(12,!0);let c=16;for(let e=0;e<a;e++){const e=Ae(i,c),n=i.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+r,byteLength:n}),c+=n}return o}}if(s.transcoders){const t=i.Map.VERSION;if(t.indexOf("1.0.0-beta")>=0||t.indexOf("1.0.0-alpha")>=0){const t=s.transcoders.inject(o);i.registerWorkerAdapter("@maptalks/3dtiles",t)}else i.registerWorkerAdapter("@maptalks/3dtiles",(function(){return s.transcoders.inject(o)}))}else i.registerWorkerAdapter("@maptalks/3dtiles",o);t.B3DMLoader=Zn,t.CMPTLoader=ti,t.Geo3DTilesLayer=Bn,t.Geo3DTilesUtil=C,t.Geo3DTransform=Te,Object.defineProperty(t,"t",{value:!0}),"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.21.0")}));
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @maptalks/3dtiles v0.20.0
2
+ * @maptalks/3dtiles v0.21.0
3
3
  * LICENSE : UNLICENSED
4
4
  * (c) 2016-2022 maptalks.org
5
5
  */
@@ -8,4 +8,4 @@ import*as t from"maptalks";import*as e from"@maptalks/gl";import{reshader as r,m
8
8
  * @maptalks/gl v0.78.0
9
9
  * LICENSE : UNLICENSED
10
10
  * (c) 2016-2022 maptalks.com
11
- */(s,a)),c.generateBuffers(this.l,{excludeElementsInVAO:e}),c}yt(t,e,r,i){const o=n.identity(t),a=this.getMap();Te.x=r[0],Te.y=r[1];const c=this._prjToPoint(Te),l=this.Ot(),f=1/(a.getGLZoom?a.getResolution(a.getGLZoom()):a.getGLRes());let h;Te.x=e[0],Te.y=e[1],h=a.altitudeToPoint?this.P:a.distanceToPointAtRes(100,100,a.getGLRes(),Te).y/100;let u=this.t.options.offset;g(u)&&(u=u(Te));const _=this.t.options.services[i].heightOffset||0;return s.set(pe,c.x-u[0],c.y-u[1],h*r[2]+h*_),n.translate(o,o,pe),s.set(l,f,f,h),n.scale(o,o,l),o}ht(t,e){const r=n.identity(t),i=this.getMap(),o=this.Ot();Te.x=e[0],Te.y=e[1];const a=i.distanceToPointAtRes(100,100,i.getGLRes(),Te);let c;return c=i.altitudeToPoint?this.P:a.y/100,s.set(o,a.x/100*1.01,a.y/100*1.01,c),n.scale(r,r,o),r}v(){const t={x:0,y:0,width:()=>this.i?this.i.width:1,height:()=>this.i?this.i.height:1};this.rt=new r.MeshShader({vert:"attribute vec3 aPosition;\n\n\n\nuniform mat4 projViewModelMatrix;\n\n\n\nvoid main() {\n\n gl_Position = projViewModelMatrix * vec4(aPosition, 1.0);\n\n}\n\n",frag:"precision mediump float;\nuniform vec3 color;\nvoid main() {\n gl_FragColor = vec4(color, 1.0);\n}\n",uniforms:["color",{name:"projViewModelMatrix",type:"function",fn:(t,e)=>n.multiply([],e.projViewMatrix,e.modelMatrix)}],extraCommandProps:{viewport:t}});const e=[],i=[];this.$=new r.MeshShader({vert:"const float SHIFT_RIGHT_11 = 1.0 / 2048.0;\n\nconst float SHIFT_RIGHT_5 = 1.0 / 32.0;\n\nconst float SHIFT_LEFT_11 = 2048.0;\n\nconst float SHIFT_LEFT_5 = 32.0;\n\nconst float NORMALIZE_6 = 1.0 / 64.0;\n\nconst float NORMALIZE_5 = 1.0 / 32.0;\n\n\n\n#ifdef HAS_POSITION\n\n attribute vec3 POSITION;\n\n#endif\n\n\n\n#if defined(HAS_RGB)\n\n attribute vec3 RGB;\n\n#elif defined(HAS_RGBA)\n\n attribute vec4 RGBA;\n\n#elif defined(HAS_RGB565)\n\n attribute float RGB565;\n\n#endif\n\n\n\nuniform vec4 pointColor;\n\nuniform float pointSize;\n\n\n\nuniform mat4 projViewModelMatrix;\n\nuniform float pointOpacity;\n\n\n\nvarying vec4 vColor;\n\n\n\n#ifdef HAS_NORMAL\n\n #ifdef HAS_NORMAL_OCT16P\n\n attribute vec2 NORMAL_OCT16P;\n\n float signNotZero(float value) {\n\n return value >= 0.0 ? 1.0 : -1.0;\n\n }\n\n vec2 signNotZero(vec2 value) {\n\n return vec2(signNotZero(value.x), signNotZero(value.y));\n\n }\n\n vec3 octDecode(vec2 encoded, float range) {\n\n if (encoded.x == 0.0 && encoded.y == 0.0) {\n\n return vec3(0.0, 0.0, 0.0);\n\n }\n\n encoded = encoded / range * 2.0 - 1.0;\n\n vec3 v = vec3(encoded.x, encoded.y, 1.0 - abs(encoded.x) - abs(encoded.y));\n\n if (v.z < 0.0) {\n\n v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);\n\n }\n\n return normalize(v);\n\n }\n\n vec3 octDecode(vec2 encoded) {\n\n return octDecode(encoded, 255.0);\n\n }\n\n #else\n\n attribute vec3 NORMAL;\n\n #endif\n\n uniform vec3 lightDir;\n\n uniform mat3 modelNormalMatrix;\n\n uniform mat4 positionMatrix;\n\n float getLambertDiffuse(vec3 lightDir, vec3 normal) {\n\n return max(dot(-lightDir, normal), 0.0);\n\n }\n\n#endif\n\n\n\nvoid main() {\n\n #if defined(HAS_RGB)\n\n vColor = vec4(RGB / 255.0, 1.0) * pointOpacity;\n\n #elif defined(HAS_RGBA)\n\n vColor = RGBA / 255.0 * pointOpacity;\n\n #elif defined(HAS_RGB565)\n\n float compressed = RGB565;\n\n float r = floor(compressed * SHIFT_RIGHT_11);\n\n compressed -= r * SHIFT_LEFT_11;\n\n float g = floor(compressed * SHIFT_RIGHT_5);\n\n compressed -= g * SHIFT_LEFT_5;\n\n float b = compressed;\n\n vec3 rgb = vec3(r * NORMALIZE_5, g * NORMALIZE_6, b * NORMALIZE_5);\n\n vColor = vec4(rgb, 1.0);\n\n #else\n\n vColor = pointColor;\n\n #endif\n\n\n\n #ifdef HAS_POSITION\n\n vec3 localPos = POSITION;\n\n #endif\n\n\n\n #ifdef HAS_NORMAL\n\n mat3 positionNormalMatrix = mat3(positionMatrix);\n\n mat3 normalMatrix = modelNormalMatrix * positionNormalMatrix;\n\n #ifdef HAS_NORMAL_OCT16P\n\n vec3 localNormal = octDecode(NORMAL_OCT16P);\n\n #else\n\n vec3 localNormal = NORMAL;\n\n #endif\n\n vec3 normal = normalize(normalMatrix * localNormal);\n\n float colorStrength = getLambertDiffuse(lightDir, normal);\n\n colorStrength = max(colorStrength, 0.5);\n\n vColor *= colorStrength;\n\n #endif\n\n\n\n gl_Position = projViewModelMatrix * vec4(localPos, 1.0);\n\n gl_PointSize = pointSize;\n\n}\n\n",frag:"#define SHADER_NAME PNTS\n\nprecision mediump float;\n\n\n\nvarying vec4 vColor;\n\n\n\nvoid main() {\n\n gl_FragColor = vColor;\n\n}\n\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:(t,e)=>n.multiply(i,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,r)=>o.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.L();this.K=new r.PhongShader({extraCommandProps:s}),this.j=new r.pbr.StandardShader({extraCommandProps:s});const a=this.t;ie(a.getRenderer().canvas,this.l,a.getMap()),this.picking=new r.FBORayPicking(this.h,{vert:this.j.vert,extraCommandProps:s,uniforms:this.j.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap())}L(){return{viewport:{x:0,y:0,width:()=>this.i?this.i.width:1,height:()=>this.i?this.i.height:1},colorMask:(t,e)=>e.colorMask||de,cull:{enable:!0,face:(t,e)=>e.cullFace||"back"},stencil:{enable:(t,e)=>!0===e.stencilEnable,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}}}nt(t){return{projViewMatrix:this.getMap().projViewMatrix,color:t&&t.color||[0,1,0]}}q(t){const e=this.getMap(),r=e.getLightManager(),n=(r&&r.getDirectionalLight()||{}).direction||[1,1,-1],i=t&&t.pointOpacity||1;return{projViewMatrix:e.projViewMatrix,pointOpacity:i,lightDir:s.normalize(n,n)}}F(){const t=this.getMap(),e=this.t.getRenderer().canvas,{iblTexes:r,dfgLUT:n}=oe(e),i=ae(t,r,n);return y(i,{czm_lightDirectionEC:i.light0_viewDirection,lightSpecular:[1,1,1],viewMatrix:t.viewMatrix,projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,outSize:[e.width,e.height],polygonFill:[1,1,1,1],polygonOpacity:1}),i}Nt(t,e,n,i){const s=e.materials[t];if(!s||!s.baseColorTexture&&!s.pbrMetallicRoughness)return null;const o=y({},i);if(s.baseColorTexture){const t=e.textures[s.baseColorTexture.index];let r;t&&!t.image.color&&(r=this.Mt(t)),o.baseColorFactor=t&&t.image.color||s.baseColorFactor||[1,1,1,1],r&&(o.baseColorTexture=r)}else{if(s.normalTexture){const t=this.Mt(e.textures[s.normalTexture.index]),r=s.normalTexture.scale||1;o.normalTexture=t,o.normalMapFactor=r}if(s.occlusionTexture){const t=this.Mt(e.textures[s.occlusionTexture.index]),r=s.occlusionTexture.strength||1;o.occlusionTexture=t,o.occlusionFactor=r}if(s.emissiveTexture){const t=this.Mt(e.textures[s.emissiveTexture.index]);o.emissiveTexture=t}s.emissiveFactor;const t=s.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(o.baseColorFactor=t.baseColorFactor),t.baseColorTexture&&void 0!==t.baseColorTexture.index){const r=e.textures[t.baseColorTexture.index];r.image&&r.image.color?o.baseColorFactor=o.baseColorFactor?a.multiply(o.baseColorFactor,o.baseColorFactor,r.image.color):r.image.color:(o.baseColorTexture=this.Mt(r),o.baseColorTexture.getREGLTexture(this.l))}if(p(t.metallicFactor)||(o.metallicFactor=t.metallicFactor),p(t.roughnessFactor)||(o.roughnessFactor=t.roughnessFactor),s.metallicRoughnessTexture){const t=this.Mt(e.textures[s.metallicRoughnessTexture.index]);o.metallicRoughnessTexture=t}}}if(s.s3mMaterial)return new r.Material(o);let c=new r.pbr.StandardMaterial(o);return"phong"===n&&(c=r.PhongMaterial.convertFrom(c)),c.once("complete",this.M),c}Mt(t){const e={type:t.type?Qt(t.type):"uint8",format:t.format?Jt(t.format):"rgba",flipY:!!t.flipY},n=t.image;n.array?e.data=n.array:n.mipmap&&(e.mipmap=n.mipmap),e.width=n.width,e.height=n.height;const i=t.sampler||t.texture&&t.texture.sampler;return i&&(i.magFilter&&(e.mag=jt(i.magFilter)),i.minFilter&&(e.min=qt(i.minFilter)),i.wrapS&&(e.wrapS=$t(i.wrapS)),i.wrapT&&(e.wrapT=$t(i.wrapT))),new r.Texture2D(e,this.O)}wt(t){const e=t.image,r=window.URL||window.webkitURL,n=new Blob([e.array],{type:e.mimeType});return r.createObjectURL(n)}C({target:t}){const e=t.St,r=this.u[e];if(r.count--,!r.count){const t=r.meshes;this.T[e]=t,delete this.u[e];const n=t.At;delete t.At,n(null,{mesh:r.meshes,id:e})}}Ot(){return fe}ct(t){return this.t.ct(t)}ft(t,e){const r=this.getMap();return r.getGLZoom?r.distanceToPoint(t,e,r.getGLZoom()):r.distanceToPointAtRes(t,e,r.getGLRes())}_pointToPrj(t){const e=this.getMap();return e.getGLZoom?e._pointToPrj(t,e.getGLZoom()):e._pointToPrjAtRes(t,e.getGLRes())}_prjToPoint(t){const e=this.getMap();return e.getGLZoom?e._prjToPoint(t,e.getGLZoom()):e._prjToPointAtRes(t,e.getGLRes(),me)}_t(t){return"Y"===t?re:"X"===t?ne:he}pick(t,e,r=3){const n=this.t;if(!n||!n.options.picking)return[];if(!this.pickingFBO||!this.picking)return[];const i=this.getMap(),s=this.F(),o=this.picking;o.render(this.R.getMeshes().filter((t=>!t.bloom)),s,!0);let a={};o.getRenderedMeshes().length&&(a=o.pick(t,e,r,s,{viewMatrix:i.viewMatrix,projMatrix:i.projMatrix,returnPoint:n.options.pickingPoint}));const{meshId:c,pickingId:l,point:f,coordinate:h}=a,u=(0===c||c)&&o.getMeshAt(c);if(!u||!u.geometry)return[];const _=u.properties;f&&f.length&&(f[0]=Math.round(1e5*f[0])/1e5,f[1]=Math.round(1e5*f[1])/1e5,f[2]=Math.round(1e5*f[2])/1e5);const d={batchId:l};if(n.options.debug&&(d.debugInfo=_),_&&_.batchTable){const{batchTable:t,batchTableBin:e,count:r}=_,n=l;for(const i in t)void 0!==t[i].byteOffset?d[i]=Tt(t[i],e,r,n):d[i]=t[i][n]}return[{data:d,point:f,coordinate:h}]}G(t){let e=new Set;for(let r=0,n=t.length;r<n;r++){const n=t[r].data.node;this.k(n)&&e.add(n.Y)}e=Array.from(e),e.sort();const r=new Map,n=e.length;for(let t=0;t<n;t++)r.set(e[t],t);return r}highlight(t){this.V=t;const e=this.t.getRenderer();this.X=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelAllHighlight(){this.V=null;const t=this.t.getRenderer();this.X=t.getFrameTimestamp(),t.setToRedraw(!0)}}const Ie=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")},Ne=Ie(),Se=Ne.gl_trans__coders=Ne.gl_trans__coders||{};function Oe(t,e){if(e)for(let r=0;r<e.length;r++){t[e[r].id||e[r].index]=e[r]}}Se.inject=function(t){const e=t.toString(),r=e.indexOf("{")+1,n=e.substring(0,r),i=Ne.gl_trans__coders=Ne.gl_trans__coders||{};let s=`${n}\n const _____getGlobal = ${Ie.toString()};\n const g___lobals = _____getGlobal()\n const tran_____scoders = g___lobals['gl_trans__coders'] = g___lobals['gl_trans__coders'] || {};`;for(const t in i)"inject"!==t&&"getTranscoder"!==t&&"registerTranscoder"!==t&&(s+='tran_____scoders["'+t+'"] ='+i[t].toString()+"\n;");return s+="\n"+e.substring(n.length),s},Se.registerTranscoder=function(t,e){Se[t]=e},Se.getTranscoder=function(t){return Se[t]};const Me=[];class we{constructor(t,e,r,n){this.Ct=t,this.H=e,this.xt=n,this.Ut=r.version,t.indexOf("i3s:tileset:")<0?(this.Ut<=1.6?this.vt="root":this.vt=0,r.version=this.Ut):(this.vt=t.substring("i3s:tileset:".length),this.Ut>1.6&&(this.vt=parseInt(this.vt))),this.Ct=t,this.Bt=r}load(){const t=this.Bt,e=t.layerScene.baseUrl;if(this.Ut<=1.6)return t[this.vt]&&t[this.vt].lodSelection?(this.Lt=t[this.vt],this.Pt()):new Promise((r=>{let n=e+"/nodes/"+this.vt;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.xt(this.H,n,(()=>{this.Lt=t[this.vt],r(this.Pt())}))}));if(this.Ut>=1.7){if(t[this.vt])return this.Lt=t[this.vt],this.Pt();const r=Math.floor(this.vt/t.nodesPerPage);return new Promise((n=>{let i=e+"/nodepages/"+r;t.layerScene.eslpk&&(i+=".json"),this.xt(this.H,i,(()=>{this.Lt=t[this.vt],n(this.Pt())}))}))}return null}getTileset(){return this.Dt}getChildrenURL(){return this.Ft}Pt(){const t=this.Bt,e=t.layerScene.baseUrl,r=this.Lt.children,n=[],i={};if(r)for(let s=0;s<r.length;s++)if(this.Ut<=1.6){const o=r[s].id;if(t[o])continue;const a=o;i[a]||(i[a]=new Promise((r=>{let n=e+"/nodes/"+a;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.xt(this.H,n,(()=>{r()}))})),n.push(i[a]))}else{const o=r[s];if(t[o])continue;const a=Math.floor(o/t.nodesPerPage);i[a]||(i[a]=new Promise((r=>{let n=e+"/nodepages/"+a;t.layerScene.eslpk&&(n+=".json"),this.xt(this.H,n,(()=>{r()}))})),n.push(i[a]))}return n.length?Promise.all(n).then((()=>this.Gt())):this.Gt()}Gt(){return Promise.resolve(this.kt())}Ht(t){Oe(this.Bt,t)}kt(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.Vt(this.Lt,!0)}}Vt(t){const e=this.Ut,r=this.Bt,n=t;var i,s=n.obb,o=n.mbs,a={};if(o)i=Ce([],o[0],o[1],o[2]),a.sphere=[...i,o[3]];else if(s){const t=function(t,e,r){const n=m.fromQuat([],r);return n[0]=n[0]*e[0],n[1]=n[1]*e[0],n[2]=n[2]*e[0],n[3]=n[3]*e[1],n[4]=n[4]*e[1],n[5]=n[5]*e[1],n[6]=n[6]*e[2],n[7]=n[7]*e[2],n[8]=n[8]*e[2],[...t,...n]}(i=Ce([],s.center[0],s.center[1],s.center[2]),s.halfSize,s.quaternion),e=t[3]+t[6]+t[9],r=t[4]+t[7]+t[10],n=t[5]+t[8]+t[11];E.set(Me,e,r,n);const o=E.len(Me);a.sphere=[...i,o]}var c=1/0,l=0;if(n.mbs?l=n.mbs[3]:n.obb&&(l=Math.max(Math.max(n.obb.halfSize[0],n.obb.halfSize[1]),n.obb.halfSize[2])),void 0!==n.lodThreshold)"maxScreenThresholdSQ"===r.lodSelectionMetricType?c=l/(Math.sqrt(n.lodThreshold)/(.25*Math.PI)):console.error("Unsupported lodSelectionMetricType in Layer");else if(void 0!==n.lodSelection)for(var f=0;f<n.lodSelection.length;f++)"maxScreenThreshold"===n.lodSelection[f].metricType&&(c=l/n.lodSelection[f].maxError);(c===1/0||isNaN(c))&&(c=1e5);var h=16*c;const u=T.identity([]),_=n.children;var d;if(_){d=[];const t=this.Bt;for(let r=0;r<_.length;r++){const n=e<=1.6?_[r].id:_[r];if(!t[n]){d=null;break}d.push(this.Vt(t[n]))}}var A={refine:"REPLACE",boundingVolume:a,transform:u,geometricError:h};return e<=1.6?t.lodSelection?t.geometryData&&(A.content={uri:"i3s:mesh:"+(t.id||t.index)}):A.content={uri:"i3s:tileset:"+(t.id||t.index)}:_&&_.length&&!d?A.content={uri:"i3s:tileset:"+(t.id||t.index)}:n.mesh&&(A.content={uri:"i3s:mesh:"+(t.id||t.index)}),d&&d.length&&(A.children=d),A}getJSON(){return this.Lt}}function Ce(t,e,r,n){return K(t,b(e),b(r),n)}const xe=!!Se.ktx2,Ue=n.identity([]),ve=(()=>{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 Be(t){return t.indexOf("i3s:mesh")>=0}const Le="i3s:mesh:".length;function Pe(t,e,r,n,i){const s=e.layerScene.eslpk,o=function(t,e){const r=e.substring(Le);return t>=1.7?parseInt(r):r}(e.version,t),a=e[o],c=e.layerScene.baseUrl,l=[];let f=!1;const h=Ue;let u,_;if(e.version<=1.6){if(!a.geometryData)return null;const t=a.geometryData.length;let r=c+`/nodes/${a.id}/`+a.geometryData[t-1].href;s&&(r+=".bin");const n={geometry:{url:r,info:e.layerScene.store.defaultGeometrySchema}};let i=a.textureData&&a.textureData[0]&&a.textureData[0].href;if(i){const t=e.layerScene.store.textureEncoding[0];let r;r="image/jpeg"===t?"jpg":"png",s&&(i+="."+r);const o={pbrMetallicRoughness:{baseColorTexture:{url:c+`/nodes/${a.id}/`+i,factor:1,format:r,mimeType:t},metallicFactor:0}};n.material=o}l.push(n)}else{u=a.mesh.geometry,_=a.mesh.material;const t=e.layerScene.geometryDefinitions[u.definition],{geometryBuffers:o}=t;f=n&&2===o.length;const h=Se.draco&&f?o[1]:o[0],d=Se.draco&&f?1:0;let E=c+`/nodes/${u.resource}/geometries/`+d;s&&(E+=".bin");const T={geometry:{url:E,info:h}};if(i&&ve&&f&&!Se.draco)throw new Error("Must import @maptalks/transcoder.draco to load i3s draco compressed geometry");const m=e.layerScene.materialDefinitions,A=e.layerScene.textureSetDefinitions;let p,y=0;if(_&&(y=m[_.definition]),m){p=function(t,e,r,n,i,s){const o=JSON.parse(JSON.stringify(t));return De(o,e,r,n,i,s),o}(y,A,c,_.resource,r,e.layerScene.eslpk)}else p={pbrMetallicRoughness:{metallicFactor:0}};T.material=p,l.push(T)}return{dracoCompression:f,meshes:l,nodeIndex:o,center:a.obb&&a.obb.center||a.mbs&&[a.mbs[0],a.mbs[1],a.mbs[2]],transform:h}}function De(t,e,r,n,i,s){for(const o in t)if(t[o]&&t[o].textureSetDefinitionId>=0){const a=e[t[o].textureSetDefinitionId],c="images/"+a.formats[0].format,l=Fe(a.formats,i),f={url:r+`/nodes/${n}/textures/${l.name}`,factor:void 0===t[o].factor?1:t[o].factor,format:l.format,mimeType:c};if(s){let t="";switch(l.format){case"dds":t="bin.dds";break;case"jpg":case"png":t=l.format}f.url+="."+t}t[o]=f}else R(t[o])&&De(t[o],e,r,n,i,s)}function Fe(t,e){for(let r=0;r<=t.length;r++){const n=t[r].format;if("dds"===n&&e.hasExtension("WEBGL_compressed_texture_s3tc"))return t[r];if("jpg"===n||"png"===n)return t[r];if("ktx2"===n&&xe)return t[r]}return null}const Ge=[];class ke extends t.renderer.CanvasRenderer{constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new k(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.zt={},this.Xt=[],this.xt=this.Yt.bind(this)}getAnalysisMeshes(){if(!this.painter)return Ge;const t=this.painter.getPaintedMeshes();if(!t)return Ge;const e=[],{b3dmMeshes:r,pntsMeshes:n,i3dmMeshes:i}=t;return r.length&&B(e,r),n.length&&B(e,n),i.length&&B(e,i),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.Xt.length||super.needToRedraw())}getFrameTimestamp(){return this.Zt}drawOnInteracting(t,e,r){this.draw(e,r)}draw(t,e){this.Zt=t;const r=this.prepareCanvas();if(r&&!r.intersects(this.canvasExtent2D))return void this.completeRender();const{root:n,tiles:i}=this.layer.getTiles(),s=i.length;if(!i||!s)return void this.completeRender();this.Wt(),this.Kt();const{selectedTiles:o,leaves:a,requests:c}=this.jt(n,i);c.length&&this.loadTiles(c),this.qt(o,a,e),this.$t(),c.length||this.completeRender()}jt(t,e){let r=[];this.Qt();let n=0;const i=this.Jt(),s={};let o=!1,a=!1;for(let t=0;t<e.length;t++){const i=e[t],c=i.node;if(s[c.id])continue;s[c.id]=1;let l=!1;const f=this.getCachedTile(c.id);if(this.te(c.id)?(n++,l=a=!0,this.tilesLoading[c.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=a=!0),(!i.node.ee||i.node.ee<=500)&&(o=!0,i.selected=!0,i.data=f)):this.painter.has(c)||(l=a=!0,r.push(c)),!l)continue;if(this.re(i))o=!0;else{this.ne(i).length&&(o=!0)}}let c=[],l={};if(o&&({selectedTiles:c,leaves:l}=this.ie(t)),r.length>1&&(r.sort(He),i)){const t=i-n;r=t>0?r.slice(0,t):[]}return{loading:a,requests:r,selectedTiles:c,leaves:l}}ie(t){const e=[],r={};let n;const i=[t],s=[];for(;i.length>0||s.length>0;){if(s.length>0){const t=s[s.length-1];if(t.se===i.length){s.pop(),t===n&&(t.leave=!0,r[t.node.id]=1),e.push(t);continue}}const t=i.pop(),o=t.children;if(t.selected)if("add"===t.node.refine)r[t.node.id]=1,t.selectionDepth=s.length,e.push(t);else{if(t.selectionDepth=s.length,n=t,0===o.length){t.leave=!0,r[t.node.id]=1,e.push(t);continue}s.push(t),t.se=i.length}for(let t=0;t<o.length;t++)i.push(o[t])}return{selectedTiles:e,leaves:r}}re(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}ne(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const r=t.Y+1,n=[t.node];for(;n.length>0;){const i=n.pop().children;for(let s=0,o=i.length;s<o;s++){if((!i[s].content||!i[s].content.url)&&i[s].children&&i[s].children.length){n.push(i[s]);continue}const o=i[s].id;if(this.tileCache.has(o)){const r=this.layer.oe(i[s],t);r.selected=!0,r.data=this.tileCache.get(o),t.children.push(r),e.push(r)}else i[s].Y<=r&&n.push(i[s])}}return e}qt(t,e,r){this.tileCache.markAll(!1);for(let e=0,r=t.length;e<r;e++){const r=t[e].data;r.current=!0,this.tileCache.add(t[e].node.id,r)}this.tileCache.shrink();const n={tiles:t,leaves:e};this.onDrawTileStart(n);const i=this.painter.paint(t,e,r);this.onDrawTileEnd(n),i&&this.layer.fire("canvasisdirty",{renderCount:i})}onDrawTileStart(){}onDrawTileEnd(){}loadTiles(t){for(let e=0,r=t.length;e<r;e++){const r=t[e];this.tilesLoading[r.id]={current:!0,node:r},this.loadTile(r)}}loadTile(t){let e=t.content.url;if(U(e)){const r=v(e);return void this.ae(e,r,t)}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const r=t.H,n=this.ce[r];return new we(e,r,n,this.xt).load().then((r=>{this.onTilesetLoad(r,t,e)}))}t&&-1===e.indexOf("http://")&&-1===e.indexOf("https://")&&!Be(e)&&(e=t.baseUrl+e);const r=this.layer.options.services[t.H];if(r.ajaxInMainThread){let n=r.urlParams;n&&(n=(e.indexOf("?")>0?"&":"?")+n);let i=d.getArrayBuffer(e+(n||""),r.fetchOptions);const s=i.xhr;i=i.then((r=>{delete this.zt[e],r?this.ae(e,r.data,t):this.onTileError(null,t)})).catch((r=>{delete this.zt[e],this.onTileError(r,t)})),this.zt[e]=s}else this.ae(e,null,t)}ae(t,e,n){let i=this.le;i||(i=r.Util.getSupportedFormats(this.gl.gl||this.gl),this.le=i);const s=this.layer.options.services[n.H];s.isSuperMapiServer&&(t=function(t,e){const r=t.substring(e.length).split("/"),n=[];for(let t=0;t<r.length;t++)n.push(encodeURIComponent(r[t]));return e+n.join("/")}(t,n.baseUrl));const o={url:t=this.layer.getTileUrl(t,n.baseUrl,s),arraybuffer:e,rootIdx:n.H,upAxis:n.dt,transform:n.matrix,supportedFormats:i};if(Be(t)){const e=this.ce[n.H];if(o.i3sInfo=Pe(t,e,this.regl,this.layer.options.enableI3SCompressedGeometry,this.layer.options.forceI3SCompressedGeometry),!o.i3sInfo)return void this.onTileError({status:404},n)}this.workerConn.loadTile(this.layer.getId(),o,((e,r)=>{if(e)return void this.onTileError(e,n);const{magic:i}=r;"b3dm"===i||"pnts"===i||"i3dm"===i||"cmpt"===i?this.Xt.push({data:r,tile:n}):this.onTilesetLoad(r,n,t)}))}Kt(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let r=0;for(;this.Xt.length&&(r<e||!t.isInteracting());){const{data:t,tile:e}=this.Xt.shift(),{magic:n}=t;"b3dm"===n?this.painter.createB3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.fe(t,e,r,n)})):"pnts"===n?this.painter.createPntsMesh(t,e.id,e,((r,{mesh:n})=>{this.fe(t,e,r,n)})):"i3dm"===n?this.painter.createI3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.fe(t,e,r,n)})):"cmpt"===n&&this.painter.createCMPTMesh(t,e.id,e,((r,{mesh:n})=>{this.fe(t,e,r,n)})),r++}}fe(t,e,r,n){if(r)this.onTileError(r,e);else{const r=this.he(n);e.memorySize=r,this.onTileLoad(t,e)}}he(t){let e=0;if(Array.isArray(t))for(let r=0;r<t.length;r++)t[r]&&(e+=this.he(t[r]));else t&&(e+=t.getMemorySize());return e}onTileLoad(t,e){this.layer&&(delete this.tilesLoading[e.id],this.layer.onTileLoad(t,e),this.ue(e),this.setToRedraw(),this.layer.fire("tileload",{node:e}))}onTilesetLoad(t,e,r){this.layer&&(t.capabilities||t.layers&&t.layers[0]&&t.layers[0].capabilities?this._e(t,e,r):(delete this.tilesLoading[e.id],this.layer.onTilesetLoad(t,e,r)))}onTileError(t,e){if(!this.layer)return;const r=e.content.url;console.warn("failed to load 3d tile: "+r),console.warn(t),delete this.tilesLoading[e.id],this.de(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}de(e,r){const n={loadTime:t.Util.now(),current:!0,error:r,node:e};this.tileCache.add(e.id,n)}ue(e){const r={loadTime:t.Util.now(),current:!0,node:e};this.tileCache.add(e.id,r)}abortTileLoading(t){if(!t||!this.workerConn)return;const e=t.node.content.url;if(this.layer.options.services[t.node.H].ajaxInMainThread){const t=this.zt[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.zt[e]}Qt(){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.Ee(this.canvas,e)),this.regl=this.regl||l({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 be(this.regl,t),this.layer.Te()}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new D("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let r=this.layer.options||{};r=y({},r),delete r.offset,r.projection=t.getSpatialReference().getProjection().code;const n=this.layer.getId();e.addLayer(n,r,(t=>{if(t)throw t;this.layer&&(this.ready=!0,this.layer.fire("workerready"))}))}onRemove(){this.painter&&this.painter.remove(),this.pickingFBO&&(this.canvas.pickingFBO||this.pickingFBO.destroy(),delete this.pickingFBO),this.workerConn&&(this.workerConn.removeLayer(this.layer.getId(),(t=>{if(t)throw t})),this.workerConn.remove(),delete this.workerConn),this.clear(),delete this.tileCache,super.onRemove()}clear(){this.$t(!0),this.tileCache.reset(),this.tilesLoading={},super.clear()}clearCanvas(){this.regl&&this.regl.clear({color:[0,0,0,0],depth:1,stencil:0}),super.clearCanvas()}getTileOpacity(){return 1}getStencilValue(){return 0}$t(t){this.me||(this.me=Date.now());const e=Date.now();if(t||!(e-this.me<this.layer.options.retireInterval)){this.me=e;for(const e in this.tilesLoading){const r=this.tilesLoading[e];!t&&r.current||this.abortTileLoading(r)}}}Jt(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}Ee(t,e){const r=["webgl","experimental-webgl"];let n=null;for(let i=0;i<r.length;++i){try{n=t.getContext(r[i],e)}catch(t){}if(n)break}return n}te(t){return!!this.tilesLoading[t]}getI3DMMeshes(){return this.painter.getI3DMMeshes()}getPNTSMeshes(){return this.painter.getPNTSMeshes()}getB3DMMeshes(){return this.painter.getB3DMMeshes()}readBatchData(t,e,r){return dt(t,e,0,r)}Wt(){if(!this.Ae)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const r=[];for(const n in this.Ae){const i=this.Ae[n];if("pending"===i.status)continue;i.status="pending";const s=i.rootIdx;if(r.push(d.getJSON(n).then((t=>{delete this.Ae[n];const e=this.ce[s];if(e){t.nodes?Oe(e,t.nodes):(e[t.id]=t,Oe(e,t.children));for(let t=0;t<i.length;t++)i[t]();this.setToRedraw()}else this.setToRedraw()}))),e++,e>=t)break}r.length&&Promise.all(r)}Yt(t,e,r){this.Ae||(this.Ae={}),this.Ae[e]=this.Ae[e]||[],this.Ae[e].rootIdx=t,this.Ae[e].push(r),this.setToRedraw()}_e(t,e,r){this.ce||(this.ce=[]);const n=e.H;this.ce[n]||(this.ce[n]={});const i=this.ce[n],s=this.layer.options.services[n];t.layers&&(t=t.layers[0],"/"!==r[r.length-1]&&(r+="/"),r+="layers/0"),i.version=+(s.i3sVersion||t.store.version),function(t,e,r,n,i,s){if(!i.layerScene){i.layerScene=t,i.nodesPerPage=t.nodePages&&t.nodePages.nodesPerPage||64,i.lodSelectionMetricType=t.nodePages&&t.nodePages.lodSelectionMetricType;let e=n;if(i.layerScene.eslpk=e.indexOf("3dSceneLayer.json")>=0,e.endsWith(".json")){const t=n.lastIndexOf("/");e=t<0?"./":n.substring(0,t)}i.layerScene.baseUrl=function(t){return t.split("?")[0]}(e)}return new we(n,e,i,s).load()}(t,n,0,r,i,this.xt).then((t=>{this.onTilesetLoad(t,e,r)}))}pick(t,e,r){return this.painter?this.painter.pick(t,e,r&&r.tolerance):[]}highlight(t){if(this.V||(this.V=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const r=t[e].service||0;let n=this.V[r];n||(n=this.V[r]=new Map),n.set(t[e].id,t[e])}else{const e=t.service||0;let r=this.V[e];r||(r=this.V[e]=new Map),r.set(t.id,t)}this.painter.highlight(this.V)}cancelHighlight(t,e){if(!this.V)return;const r=this.V[t];if(r){if(Array.isArray(e))for(let t=0;t<e.length;t++)r.delete(e[t]);else r.delete(e);this.painter.highlight(this.V)}}cancelAllHighlight(){delete this.V,this.painter.cancelAllHighlight()}}function He(t,e){return t.tt-e.tt}function Ve(t,e,r){return t[0]=e[r],t[1]=e[r+3],t[2]=e[r+6],t}function ze(t,e,r){return Math.sqrt(function(t,e,r){var n=E.subtract(Xe,r,t),i=Ve(Ye,e,0),s=Ve(Ze,e,1),o=Ve(We,e,2),a=E.len(i),c=E.len(s),l=E.len(o);E.normalize(i,i),E.normalize(s,s),E.normalize(o,o);var f=Ke;f[0]=E.dot(n,i),f[1]=E.dot(n,s),f[2]=E.dot(n,o);var h,u=0;f[0]<-a?u+=(h=f[0]+a)*h:f[0]>a&&(u+=(h=f[0]-a)*h);f[1]<-c?u+=(h=f[1]+c)*h:f[1]>c&&(u+=(h=f[1]-c)*h);f[2]<-l?u+=(h=f[2]+l)*h:f[2]>l&&(u+=(h=f[2]-l)*h);return u}(t,e,r))}const Xe=[],Ye=[],Ze=[],We=[],Ke=[];const je=2*Math.PI;class qe{constructor(t,e,r,n){this.west=t,this.south=e,this.east=r,this.north=n}static contains(t,e){var r=e[0],n=e[1],i=t.west,s=t.east;return s<i&&(s+=je,r<0&&(r+=je)),(r>i||ct(r,i,1e-14))&&(r<s||ct(r,s,1e-14))&&n>=t.south&&n<=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 $e=[0,0,1];function Qe(t,e){return K(e,t[0],t[1],t[2])}class Je{constructor(t,e){this.normal=s.copy([],t),this.distance=e}static fromPointNormal(t,e,r){var n=-s.dot(e,t);return s.copy(r.normal,e),r.distance=n,r}}const tr=[],er=[],rr=[],nr=[],ir=[],sr=[],or=[],ar=[],cr=[],lr=[],fr=new Je([1,0,0],0),hr=[];class ur{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new qe(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){var r,n,i,o=0;if(!qe.contains(this.rectangle,e)){var a=this.southwestCornerCartesian,c=this.northeastCornerCartesian,l=this.westNormal,f=this.southNormal,h=this.eastNormal,u=this.northNormal,_=s.subtract(hr,t,a),d=s.dot(_,l),E=s.dot(_,f),T=s.subtract(hr,t,c),m=s.dot(T,h),A=s.dot(T,u);d>0?o+=d*d:m>0&&(o+=m*m),E>0?o+=E*E:A>0&&(o+=A*A)}if(r=e[2],n=this.minimumHeight,r>(i=this.maximumHeight)){var p=r-i;o+=p*p}else if(r<n){var y=n-r;o+=y*y}return Math.sqrt(o)}computeBox(t){const e=this;Qe(qe.southwest(t,er),e.southwestCornerCartesian),Qe(qe.northeast(t,er),e.northeastCornerCartesian),tr[0]=t.west,tr[1]=.5*(t.south+t.north),tr[2]=0;var r=Qe(tr,rr),n=s.cross(ir,r,$e);s.normalize(e.westNormal,n),tr[0]=t.east;var i=Qe(tr,ar),o=s.cross(ir,$e,i);s.normalize(e.eastNormal,o);var a,c=s.subtract(ir,r,i),l=s.normalize(nr,c),f=t.south;if(f>0){tr[0]=.5*(t.west+t.east),tr[1]=f;var h=Qe(tr,cr);s.copy(lr,l);var u=Je.fromPointNormal(e.southwestCornerCartesian,e.westNormal,fr);_r(cr,lr,u,e.southwestCornerCartesian),a=st(h,sr)}else a=ot(qe.southeast(t,er),sr);var _=s.cross(or,a,c);s.normalize(e.southNormal,_);var d,E=t.north;if(E<0){tr[0]=.5*(t.west+t.east),tr[1]=E;var T=Qe(tr,cr);s.scale(lr,l,-1);var m=Je.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,fr);_r(cr,lr,m,e.northeastCornerCartesian),d=st(T,sr)}else d=ot(qe.northwest(t,er),sr);var A=s.cross(or,c,d);s.normalize(e.northNormal,A)}}function _r(t,e,r,n){var i=t,o=e,a=r.normal,c=s.dot(a,o);if(!(Math.abs(c)<1e-15)){var l=(-r.distance-s.dot(a,i))/c;if(!(l<0))return n=s.scale(n,o,l),s.add(n,i,n)}}const dr=new t.Extent(0,0,0,0),Er=new t.Extent(0,0,0,0),Tr=[],mr=[],Ar=[],pr=[],yr=new t.Point(0,0),gr=[],Rr=new t.Coordinate(0,0),br=n.identity([]);class Ir extends t.Layer{constructor(t,e){super(t,e),this.pe(),this.zt={},this.ye=[]}pe(){let t=this.options.services.map((t=>t.url));this.ge=t.map(((t,e)=>function(t,e){t=N(t);return{visible:1,baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:n.identity([]),H:e,Y:0}}(t,e))),this.fire("rootready",{roots:this.ge.slice(0)})}showService(t){return this.Re(t,1),this}hideService(t){return this.Re(t,0),this}Re(t,e){const r=this.ge[t];if(!r)return;r.visible=e;const n=this.getRenderer();n&&n.setToRedraw()}getTileUrl(t){return t}getExtent(e){if(!e&&0!==e){const e=new t.Extent;for(let t=0;t<this.ge.length;t++)if(this.ge[t].boundingVolume){const r=this.boundingVolumeToExtent(this.ge[t]);e._combine(r)}return e}return this.ge[e]&&this.ge[e].boundingVolume?this.boundingVolumeToExtent(this.ge[e]):null}boundingVolumeToExtent(e){const r=e.boundingVolume.be?br:e.matrix,n=this.getMap();if(e.boundingVolume.region){const r=e.boundingVolume.region;return new t.Extent(I(r[0]),I(r[1]),I(r[2]),I(r[3]))}if(e.boundingVolume.sphere){const i=e.boundingVolume.sphere,o=tt([],s.transformMat4([],i,r)),a=i[3],c=n.locate(o,-a,a),l=n.locate(o,a,-a);return new t.Extent(c,l)}if(e.boundingVolume.box){const i=e.boundingVolume.box,a=s.transformMat4([],i,r),c=new t.Coordinate(tt([],a)),l=i.slice(3);o.multiply(l,o.fromMat4([],e.matrix),l);const f=s.length(l.slice(0,3)),h=s.length(l.slice(3,6)),u=s.length(l.slice(6,9)),_=Math.max(f,h,u),d=n.locate(c,-_,_),E=n.locate(c,_,-_);return new t.Extent(d,E)}return null}getRootTiles(){return this.ge}getTiles(){const t=this.getRenderer();if(!t.ready)return this.Ie(),{tiles:pr};const e=this.getMap(),r=e.cameraPosition;let n,i;if(e.getGLZoom)i=e.pointToDistance(r[2],0,e.getGLZoom()),Rr.set(r[0],r[1]),n=e.pointToCoord(Rr,e.getGLZoom());else{const t=e.getGLRes();i=e.pointAtResToDistance(r[2],0,t),Rr.set(r[0],r[1]),n=e.pointAtResToCoord(Rr,t)}this.Ne=this.Ne||[],s.set(this.Ne,b(n.x),b(n.y),i),this.Se=K(this.Se||[],this.Ne[0],this.Ne[1],this.Ne[2]),this.Oe=2*Math.tan(.5*b(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const l=[];for(let e=0;e<this.ge.length;e++){const r=this.ge[e];if(!r.visible)continue;let n=1/0;const i=[r],s=this.Me(e);for(;i.length>0;){const e=i.pop();for(e.id||this.we(e);c.level>=e.Y;)c=c.parent;const r=this.Ce(e,s,o);if(r<1){let t=c;for(;t&&!t.content;)t=t.parent;0===r&&t&&t.content&&this.xe(l,t);if(!1===this.options.services[e.H].alwaysShow)continue;if(!(0===r&&e.Y<=n))continue;e.content&&(n=e.Y)}e.tt<1/0&&this.Ue(e);const a=this.oe(e,c);c.children.push(a);const f=e.children,h=f&&f.length,u=a.content;if(!h&&u&&this.xe(l,a),h){u&&"add"===e.refine&&this.xe(l,a),c=a;const r=f[0].parent;let n=!1;for(let s=0,o=f.length;s<o;s++){if(r){const e=t.getCachedTile(f[s].id);if(e&&e.error&&404!==e.error.status)continue;n=!0}else{n=!0,f[s].parent=e,f[s].dt=e.dt,f[s].baseUrl=e.baseUrl;const t=f[s].content&&(f[s].content.url||f[s].content.uri);t&&(U(t)||t.indexOf("i3s:")>=0?f[s].baseUrl=e.baseUrl:-1===t.indexOf("http://")&&-1===t.indexOf("https://")?f[s].content.url=e.baseUrl+t:f[s].baseUrl=t.substring(0,t.lastIndexOf("/")+1))}i.push(f[s])}!n&&u&&this.xe(l,a)}}}return{root:a,tiles:l}}xe(t,e){const{viewerRequestVolume:r}=e.node;r&&!function(t,e,r){if(r.region){const e=r.region;if(t[0]>=e[0]&&t[0]<=e[2]&&t[1]>=e[1]&&t[1]<=e[3])return!0}else{if(r.sphere)return Nr(r,e);if(r.box)return 0===Sr(r,e)}return!1}(this.Ne,this.Se,r)||t.push(e)}oe(t,e){return{id:t.id,node:t,children:[],level:t.Y,parent:e,content:t.content&&t.content.url}}we(e){e.id=t.Util.GUID(),e.matrix=e.transform||n.identity([]),e.ve=this.Be(e),e.parent&&(function(t){return t.content&&t.content.uri&&t.content.uri.indexOf("i3s:")>=0}(e)||(e.matrix=n.multiply(e.matrix,e.parent.matrix,e.matrix)),e.H=e.parent.H,void 0===e.Y&&(e.Y=e.parent.Y+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),this.Le(e)}Le(t){const e=t.boundingVolume;if(!e||e.be)return;const r=this.options.services[t.H].heightOffset||0,i=this.options.offset,o=g(i)||i[0]||i[1];if(!t.boundingVolume||!r&&n.exactEquals(t.matrix,br)&&!o)return;const{region:a,box:c,sphere:l}=e;if(a){const t=this.Pe([I(a[0]),I(a[1])]);a[0]=b(t.x),a[1]=b(t.y);const e=this.Pe([I(a[2]),I(a[3])]);a[2]=b(e.x),a[3]=b(e.y),a[4]+=r,a[5]+=r}else if(c||l){const e=c||l,n=s.transformMat4(Tr,e,t.matrix),i=tt(mr,n),o=this.Pe([i[0],i[1]]);i[0]=o.x,i[1]=o.y,i[2]+=r,K(e,b(i[0]),b(i[1]),i[2])}e.be=!0}Be(t){return void 0===t.geometricError||!t.boundingVolume}Ue(t){let e=t.parent;for(;e&&e.ve&&!(e.tt<=t.tt);)e.tt=t.tt,e=t.parent}onTileLoad(t,e){if(t.children&&(!e.children||!e.children.length)){e.children=t.children;const r=e.content.url;e.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const n=this.getRenderer();n&&n.setToRedraw()}}onTilesetLoad(t,e,r){if(!t)return void console.warn("invalid tileset at : "+r);const i=this.options.services[e.H],s=(t.asset&&t.asset.gltfUpAxis||e&&e.dt||i.upAxis||"Y").toUpperCase();t.root.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const o=r.indexOf("realspace/")>-1;0===e.Y&&(t.asset&&t.asset.s3mType&&o||i.isSuperMapiServer)&&(t.root.baseUrl+="data/path/");const a=t.asset.i3s;if(t.root.dt=s,e){const r=e.boundingVolume;y(e,t.root),e.refine=e.refine&&e.refine.toLowerCase()||"replace",r&&(e.boundingVolume=r);const i=t.root.transform;i&&(e.parent?a||(e.matrix=n.multiply([],e.parent.matrix,i)):e.matrix=i),this.Le(e),e.De=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.ve=this.Be(e);const s=e.content&&(e.content.url||e.content.uri);s&&e.content.uri&&(e.content.url=e.content.uri,delete e.content.uri),a||!s||U(s)||-1!==s.indexOf("http://")||-1!==s.indexOf("https://")||(e.content.url=e.baseUrl+s)}this.Ie(),this.fire("loadtileset",{tileset:t,index:e.H,url:r})}Ce(t,e,r){if(t.tt=1/0,0===t.Y||t.ve)return 1;if(!this.Fe(t,e,r))return-1;if(0===t.geometricError)return 1;let n=this.options.services[t.H].maximumScreenSpaceError;null==n&&(n=8);let i=this.Ge(t);return 0===i&&t.parent&&(i=.5*(t.parent.ee||0)),i>=n?1:0}ct(e,r){r||(r=new t.Point(0,0));const n=this.getMap();return n.getGLZoom?n.coordToPoint(e,n.getGLZoom(),r):n.coordToPointAtRes(e,n.getGLRes(),r)}Fe(e,r,i){const a=e.id;let c=this.ye[a];const{boundingVolume:l}=e,_=l.sphere;let d=l.region;const E=l.box;if(!c){let r,i,f;if(E&&(d=function(t,e){for(let e=0;e<9;e++)Pr[e]=t[e+3];const r=Pr;n.exactEquals(e,br)||o.multiply(r,o.fromMat4(gr,e),r);const i=s.copy(Or,t),a=s.set(Mr,r[0],r[1],r[2]),c=s.set(wr,r[3],r[4],r[5]),l=s.set(Cr,r[6],r[7],r[8]);xr[0]=xr[0]||[];const f=s.copy(xr[0],i);s.sub(f,f,a),s.sub(f,f,c),s.sub(f,f,l),xr[1]=xr[1]||[];const h=s.copy(xr[1],i);s.sub(h,h,a),s.sub(h,h,c),s.add(h,h,l),xr[2]=xr[2]||[];const u=s.copy(xr[2],i);s.sub(u,u,a),s.add(u,u,c),s.sub(u,u,l),xr[3]=xr[3]||[];const _=s.copy(xr[3],i);s.sub(_,_,a),s.add(_,_,c),s.add(_,_,l),xr[4]=xr[4]||[];const d=s.copy(xr[4],i);s.add(d,d,a),s.sub(d,d,c),s.sub(d,d,l),xr[5]=xr[5]||[];const E=s.copy(xr[5],i);s.add(E,E,a),s.sub(E,E,c),s.add(E,E,l),xr[6]=xr[6]||[];const T=s.copy(xr[6],i);s.add(T,T,a),s.add(T,T,c),s.sub(T,T,l),xr[7]=xr[7]||[];const m=s.copy(xr[7],i);s.add(m,m,a),s.add(m,m,c),s.add(m,m,l);for(let t=0;t<xr.length;t++)Ur[t]=Ur[t]||[],tt(Ur[t],xr[t]),vr[t]=Ur[t][0],Br[t]=Ur[t][1],Lr[t]=Ur[t][2];return[b(Math.min(...vr)),b(Math.min(...Br)),b(Math.max(...vr)),b(Math.max(...Br)),Math.min(...Lr),Math.max(...Lr)]}(E,e.matrix),l.region=d),d){r=dr.set(I(d[0]),I(d[1]),I(d[2]),I(d[3]));const t=r.getCenter(),e=this.ke(t);r=r.convertTo((t=>this.ct(t,yr)),Er),f=d[4],i=d[5],c=this.ye[a]=[[r.xmin,r.ymin,f*e[2]],[r.xmax,r.ymax,i*e[2]]],c.center=t}else if(_){const e=tt(Tr,_),r=new t.Coordinate(e),n=this.ct(r,yr).toArray(),i=this.ke(r);n.push(e[2]*i[2]),c=this.ye[a]=[n,_[3]*i[2]],c.center=r}}if(r){if(d)dr.xmin=c[0][0],dr.ymin=c[0][1],dr.xmax=c[1][0],dr.ymax=c[1][1];else if(_){const t=c[2];dr.xmin=c[0][0]-t,dr.ymin=c[0][1]-t,dr.xmax=c[0][0]+t,dr.ymax=c[0][1]+t}else if(E){const t=c[1],e=c[2];dr.xmin=c[0][0]-t,dr.ymin=c[0][1]-e,dr.xmax=c[0][0]+t,dr.ymax=c[0][1]+e}if(!r.intersects(dr))return!1}return d?f(i,c):_?h(i,c):!!E&&u(i,c)}ke(t){const e=this.getMap(),r=e.distanceToPointAtRes(100,100,e.getGLRes(),t);let n;return n=e.altitudeToPoint?e.altitudeToPoint(100,e.getGLRes())/100:r.y/100,s.set(Ar,r.x/100*1.01,r.y/100*1.01,n),Ar}Pe(e){Array.isArray(e)&&(e=new t.Coordinate(e));let r=this.options.offset;if(g(r)&&(r=r(Array.isArray(e)?new t.Coordinate(e):e)),r[0]||r[1]){const t=this.getMap(),n=t.getGLRes(),i=t.coordToPointAtRes(e,n);return i._sub(r),t.pointAtResToCoord(i,n)}return e}Me(e){const r=this.options.services[e].maxExtent;if(!r)return null;const n=this.ge[e];return n.maxExtent||(n.maxExtent=new t.Extent(r).convertTo((t=>this.ct(t)))),n.maxExtent}Ge(t){const e=this.Oe,r=t.geometricError;if(0===r)return t.ee=0,0;const n=this.getMap();let i;t.boundingVolume.region?i=function(t,e,r){t.He||(t.He=new ur(t.boundingVolume.region));return t.He.distanceToCamera(e,r)}(t,this.Se,this.Ne):t.boundingVolume.sphere?i=Nr(t.boundingVolume,this.Se):t.boundingVolume.box&&(i=Sr(t.boundingVolume,this.Se));const s=Math.max(Math.abs(i),1e-7),o=r*n.height/(s*e);return t.tt=i,t.ee=o,o}Ie(){const t=this.getRenderer();t&&t.setToRedraw()}gt(t){return this.ye[t]}identify(e,r={}){const n=this.getMap(),i=this.getRenderer();if(!n||!i)return[];const s=n.coordToContainerPoint(new t.Coordinate(e));return this.identifyAtPoint(s,r)}identifyAtPoint(t,e={}){const r=this.getMap(),n=this.getRenderer();if(!r||!n)return[];const i=r.getDevicePixelRatio();return n.pick(t.x*i,t.y*i,e)}highlight(t){const e=this.getRenderer();return e?(e.highlight(t),this):(this.V||(this.V=[]),this.V.push(t),this)}Te(){if(this.V){for(let t=0;t<this.V.length;t++)this.highlight(this.V[t]);delete this.V}}cancelHighlight(t,e){const r=this.getRenderer();return r?(r.cancelHighlight(t,e),this):this}cancelAllHighlight(){const t=this.getRenderer();return t?(t.cancelAllHighlight(),this):this}}function Nr(t,e){const r=t.sphere,n=s.dist(r,e),i=t.sphere[3];return n<i?0:n-i}function Sr(t,e){const r=t.box;return ze(s.set(Tr,r[0],r[1],r[2]),o.set(gr,r[3],r[4],r[5],r[6],r[7],r[8],r[9],r[10],r[11]),e)}Ir.mergeOptions({"maxGPUMemory":512,"retireInterval":2e3,"loadingLimitOnInteracting":5,"loadingLimit":0,"renderer":"gl","forceRenderOnZooming":!0,"forceRenderOnRotating":!0,"forceRenderOnMoving":!0,"debug":!1,"debugOutline":[0,1,0],"meshLimitPerFrame":1,"i3sNodepageLimitPerFrame":1,"enableI3SCompressedGeometry":!0,"forceI3SCompressedGeometry":!0,"picking":!0,"pickingPoint":!0,"geometryEvents":!1,"antialias":!1,"optionalExtensions":["ANGLE_instanced_arrays","OES_element_index_uint","OES_standard_derivatives","OES_vertex_array_object","OES_texture_half_float","OES_texture_half_float_linear","OES_texture_float","OES_texture_float_linear","WEBGL_depth_texture","EXT_shader_texture_lod","WEBGL_compressed_texture_astc","WEBGL_compressed_texture_etc","WEBGL_compressed_texture_etc1","WEBGL_compressed_texture_pvrtc","WEBGL_compressed_texture_s3tc","WEBGL_compressed_texture_s3tc_srgb"],"offset":[0,0]}),Ir.registerRenderer("gl",ke),Ir.registerJSONType("Geo3DTilesLayer");const Or=[],Mr=[],wr=[],Cr=[],xr=[],Ur=[],vr=[],Br=[],Lr=[],Pr=[];class Dr{constructor(t,e,r){this.Ve=t,this.ze=e||_,this.le=r,this.Xe={"image/crn":Se.crn&&Se.crn(),"image/ktx2":Se.ktx2&&Se.ktx2(),"image/cttf":Se.ktx2&&Se.ktx2(),"draco":Se.draco&&Se.draco()}}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.Ye(t,e,r,n,i)):d.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Ye(t,i,r,n)}))}Ye(t,e,r,n,i){const s=i&&i.maxTextureSize,o=this.Ze(e,r,n,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.ze(a,o.glb,{transferable:!0,requestImage:this.Ve,decoders:this.Xe,supportedFormats:this.le,maxTextureSize:s});return c.load({skipAttributeTransform:!1}).then((e=>{e.url=`${t}-${r}-${n}`;const i=c.transferables;for(let t=0;t<o.transferables.length;t++)i.indexOf(o.transferables[t])<0&&i.push(o.transferables[t]);return{magic:"b3dm",count:o.count,transferables:i,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,gltf:e}}))}Ze(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported b3dm version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in b3dm header is inconsistent with b3dm's byte length, url: "+n;return console.warn(t),{error:t}}let o,a=i.getUint32(12,!0),c=i.getUint32(16,!0),l=i.getUint32(20,!0),f=i.getUint32(24,!0),h=28+e;l>=570425344?(h-=8,o=a,l=c,f=0,a=0,c=0):f>=570425344&&(h-=4,o=l,l=a,f=c,a=0,c=0);const u=[t];let _,d,E;if(a>0?(_=ht(t,h,a),h+=a,o=_.BATCH_LENGTH):_={"BATCH_LENGTH":o},c>0&&(h+=c),l>0&&(d=ut(t,h,l),h+=l,f>0)){const e=_t(0,h,f);E=t.slice(e.offset,e.offset+e.byteLength),h+=f,u.push(E)}const T=_.BATCH_LENGTH,m={};if(_&&_.BATCH_ID){m.BATCH_ID=Et(_.BATCH_ID,t,undefined.offset,T);const e=m.BATCH_ID.array&&m.BATCH_ID.array.buffer;e&&u.indexOf(e)<0&&u.push(e)}return{count:o,transferables:u,featureTable:_,batchTable:d,batchTableBin:E,b3dm:m,glb:{buffer:t,byteOffset:h,byteLength:i.byteLength+i.byteOffset-h}}}We(){return null}}class Fr{constructor(t,e,r,n){this.Ve=t,this.ze=e||_,this.le=r,this.Xe={"image/crn":Se.crn&&Se.crn(),"image/ktx2":Se.ktx2&&Se.ktx2(),"image/cttf":Se.ktx2&&Se.ktx2(),"draco":Se.draco&&Se.draco()},this.Ke=n}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.Ye(t,e,r,n,i)):d.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Ye(t,i,r,n)}))}Ye(t,e,r,n,i){return this.je(t,e,r,n,i).then((({gltf:i,transferables:s})=>{const o=this.qe(e,r,n,t);if(o.error)return Promise.resolve(o);for(let t=0;t<s.length;t++)-1===o.transferables.indexOf(s[t])&&o.transferables.push(s[t]);return delete i.transferables,Promise.resolve({magic:"i3dm",count:o.count,transferables:o.transferables,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,i3dm:o.i3dm,gltf:i})}))}je(t,e,r,n,i){const s=i&&i.maxTextureSize,o={transferable:!0,requestImage:this.Ve,decoders:this.Xe,supportedFormats:this.le,maxTextureSize:s},a=new DataView(e,r,n),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 n=M(new Uint8Array(e,c+r,a.byteLength-c));-1==n.indexOf("://")&&(n=t.substring(0,t.lastIndexOf("/"))+"/"+n);return n.indexOf(".glb")>0?d.getArrayBuffer(n,{}).then((t=>this.$e(n,{buffer:t.data,byteOffset:0},o))):d.getJSON(n,{}).then((t=>this.$e(n,t,o)))}{const n={buffer:e,byteOffset:c+r,byteLength:a.byteLength-c};return this.$e(t,n,o)}}$e(t,e,r){const n=t.substring(0,t.lastIndexOf("/")),i=new this.ze(n,e,r);return i.load({skipAttributeTransform:!0}).then((r=>{let n=0,s=0;return e.buffer&&(n=e.byteOffset||0,s=e.byteLength||0),r.url=`${t}-${n}-${s}`,{transferables:i.transferables,gltf:r}}))}qe(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported pnts version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+n;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:l,batchTableBin:f}=bt(i,32+e,o),h={},u=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;h.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,r=a.QUANTIZED_VOLUME_SCALE,{byteOffset:n}=a.POSITION_QUANTIZED;h.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:u,componentType:5126,array:this.Qe(new Uint16Array(t,n+c.offset,3*u),e,r)},o.push(h.POSITION.array.buffer)}if(a.BATCH_ID){h.BATCH_ID=Et(a.BATCH_ID,t,c.offset,u);const e=h.BATCH_ID.array&&h.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;h.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,h.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;h.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:this.Je(new Uint16Array(t,e+c.offset,2*u))},o.push(h.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,h.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:this.Je(new Uint16Array(t,e+c.offset,2*u))},o.push(h.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;h.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,u).slice()},o.push(h.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;h.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.SCALE_NON_UNIFORM.array.buffer)}return{count:u,batchTable:l,batchTableBin:f,featureTable:a,i3dm:h,transferables:o}}Je(t){const e=t.length/2,r=new Float32Array(3*e),n=[];for(let i=0;i<e;i++)Gr(n,t[2*i],t[2*i+1],65535),r[3*i]=n[0],r[3*i+1]=n[1],r[3*i+2]=n[2];return r}Qe(t,e,r){return Rt(new Float32Array(t.length),t,e,r)}We(){return null}}function Gr(t,e,r,n){if(t[0]=kr(e,n),t[1]=kr(r,n),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]))*Hr(e),t[1]=(1-Math.abs(e))*Hr(t[1])}return E.normalize(t,t)}function kr(t,e){return function(t,e,r){return t<e?e:t>r?r:t}(t,0,e=function(t,e){if(null!=t)return t;return e}(e,255))/e*2-1}function Hr(t){return t<0?-1:1}class Vr{constructor(){}load(t,e,r=0,n=0){return e?(n||(n=e.byteLength),this.Ye(t,e,r,n)):d.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Ye(t,i,r,n)}))}Ye(t,e,r,n){return this.tr(e,r,n,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}))}tr(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported pnts version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+n;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:l,batchTableBin:f}=bt(i,e+28,o),h=a.QUANTIZED_VOLUME_OFFSET,u=a.QUANTIZED_VOLUME_SCALE,_=a.POINTS_LENGTH;let d,E={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){E=a.extensions["3DTILES_draco_point_compression"],d=new DataView(t,E.byteOffset+c.offset,E.byteLength);const e={attributes:E.properties,useUniqueIDs:!1};return this.er||(this.er=Se.draco()),this.er(d,e).then((e=>{const r=e.attributes;!a.POSITION&&!a.POSITION_QUANTIZED||r.POSITION||r.POSITION_QUANTIZED||(r.POSITION=a.POSITION,r.POSITION_QUANTIZED=a.POSITION_QUANTIZED),!(a.RGB||a.RGBA||a.RGB565)||r.RGB||r.RGBA||r.RGB565||(r.RGB=a.RGB,r.RGBA=a.RGBA,r.RGB565=a.RGB565),!a.NORMAL&&!a.NORMAL_OCT16P||r.NORMAL||r.NORMAL_OCT16P||(r.NORMAL=a.NORMAL,r.NORMAL_OCT16P=a.NORMAL_OCT16P);const n=this.rr(t,e.attributes,c.offset,_,o,h,u);if(e.attributes.BATCH_ID){const t=e.attributes.BATCH_ID.array;n.BATCH_ID={byteStride:0,byteOffset:0,itemSize:1,count:t.length,componentType:gt(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?n.BATCH_ID=Et(a.BATCH_ID,t,c.offset,_):n.BATCH_ID=zr(_);const e=n.BATCH_ID.array&&n.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return{count:_,batchTable:l,batchTableBin:f,featureTable:a,pnts:n,transferables:o}}))}const T=this.rr(t,a,c.offset,_,o,h,u);if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?T.BATCH_ID=Et(a.BATCH_ID,t,c.offset,_):T.BATCH_ID=zr(_);const e=T.BATCH_ID.array&&T.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:_,batchTable:l,batchTableBin:f,featureTable:a,pnts:T,transferables:o})}rr(t,e,r,n,i,s,o){const a={};if(e.POSITION){let{byteOffset:s,array:o}=e.POSITION;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n*4);o=new Float32Array(e)}a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:o},i.push(o.buffer)}else if(e.POSITION_QUANTIZED){let{byteOffset:c,array:l}=e.POSITION_QUANTIZED;c=c||0;const f=l?0:r;a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:this.Qe(l||new Uint16Array(t,c+f,3*n),s,o)},i.push(a.POSITION.array.buffer)}if(e.RGBA){let{byteOffset:s,array:o}=e.RGBA;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+4*n);o=new Uint8Array(e)}a.RGBA={byteStride:0,byteOffset:0,itemSize:4,count:n,componentType:5121,array:o},i.push(o.buffer)}else if(e.RGB){let{byteOffset:s,array:o}=e.RGB;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n);o=new Uint8Array(e)}a.RGB={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5121,array:o},i.push(o.buffer)}else if(e.RGB565){let{byteOffset:s,array:o}=e.RGB565;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+2*n);o=new Uint16Array(e)}a.RGB565={byteStride:0,byteOffset:0,itemSize:1,count:n,componentType:5123,array:o},i.push(o.buffer)}if(e.NORMAL){let{byteOffset:s,array:o}=e.NORMAL;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n*4);o=new Float32Array(e)}a.NORMAL={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:o},i.push(o.buffer)}else if(e.NORMAL_OCT16P){let{byteOffset:s,array:o}=e.NORMAL_OCT16P;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+2*n);o=new Uint8Array(e)}a.NORMAL_OCT16P={byteStride:0,byteOffset:0,itemSize:2,count:n,componentType:5121,array:o},i.push(o.buffer)}return a}Qe(t,e,r){return Rt(new Float32Array(t.length),t,e,r)}We(){return null}}function zr(t){const e=x(t),r=new e(t);for(let e=0;e<t;e++)r[e]=e;return{byteStride:0,byteOffset:0,itemSize:1,count:t,componentType:gt(e),array:r}}class Xr{constructor(t,e){this.Ve=t,this.ze=e||_}load(t,e,r=0,n=0,i){return e?this.Ye(t,e,r,n,i):d.getArrayBuffer(t,{}).then((e=>{const i=e.data;return this.Ye(t,i,r,n)}))}Ye(t,e,r,n,i){n||(n=e.byteLength);const s=this.nr(e,t,r,n),o=[];for(let r=0;r<s.length;r++){let n;if("b3dm"===s[r].magic)n=new Dr(this.Ve,this.ze);else if("i3dm"===s[r].magic)n=new Fr(this.Ve,this.ze);else if("pnts"===s[r].magic)n=new Vr;else{if("cmpt"!==s[r].magic){console.warn("Unsupported magic in CMPT tile:",s[r].magic);continue}n=new Xr(this.Ve,this.ze)}o.push(n.load(t,e,s[r].offset,s[r].byteLength,i).then((t=>t)))}return Promise.all(o).then((t=>({magic:"cmpt",tiles:t})))}nr(t,e,r,n){const i=new DataView(t,r,n),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported cmpt version: "+s+", url:"+e;return console.warn(t),{error:t}}if(16===i.byteLength)return[];const o=[],a=i.getUint32(12,!0);let c=16;for(let e=0;e<a;e++){const e=lt(i,c),n=i.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+r,byteLength:n}),c+=n}return o}}if(e.transcoders){const r=t.Map.VERSION;if(r.indexOf("1.0.0-beta")>=0||r.indexOf("1.0.0-alpha")>=0){const r=e.transcoders.inject(A);t.registerWorkerAdapter("@maptalks/3dtiles",r)}else t.registerWorkerAdapter("@maptalks/3dtiles",(function(){return e.transcoders.inject(A)}))}else t.registerWorkerAdapter("@maptalks/3dtiles",A);export{Dr as B3DMLoader,Xr as CMPTLoader,Ir as Geo3DTilesLayer,L as Geo3DTilesUtil,at as Geo3DTransform};"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.20.0");
11
+ */(s,a)),c.generateBuffers(this.l,{excludeElementsInVAO:e}),c}yt(t,e,r,i){const o=n.identity(t),a=this.getMap();Te.x=r[0],Te.y=r[1];const c=this._prjToPoint(Te),l=this.Ot(),f=1/(a.getGLZoom?a.getResolution(a.getGLZoom()):a.getGLRes());let h;Te.x=e[0],Te.y=e[1],h=a.altitudeToPoint?this.P:a.distanceToPointAtRes(100,100,a.getGLRes(),Te).y/100;let u=this.t.options.offset;g(u)&&(u=u(Te));const _=this.t.options.services[i].heightOffset||0;return s.set(pe,c.x-u[0],c.y-u[1],h*r[2]+h*_),n.translate(o,o,pe),s.set(l,f,f,h),n.scale(o,o,l),o}ht(t,e){const r=n.identity(t),i=this.getMap(),o=this.Ot();Te.x=e[0],Te.y=e[1];const a=i.distanceToPointAtRes(100,100,i.getGLRes(),Te);let c;return c=i.altitudeToPoint?this.P:a.y/100,s.set(o,a.x/100*1.01,a.y/100*1.01,c),n.scale(r,r,o),r}v(){const t={x:0,y:0,width:()=>this.i?this.i.width:1,height:()=>this.i?this.i.height:1};this.rt=new r.MeshShader({vert:"attribute vec3 aPosition;\n\n\n\nuniform mat4 projViewModelMatrix;\n\n\n\nvoid main() {\n\n gl_Position = projViewModelMatrix * vec4(aPosition, 1.0);\n\n}\n\n",frag:"precision mediump float;\nuniform vec3 color;\nvoid main() {\n gl_FragColor = vec4(color, 1.0);\n}\n",uniforms:["color",{name:"projViewModelMatrix",type:"function",fn:(t,e)=>n.multiply([],e.projViewMatrix,e.modelMatrix)}],extraCommandProps:{viewport:t}});const e=[],i=[];this.$=new r.MeshShader({vert:"const float SHIFT_RIGHT_11 = 1.0 / 2048.0;\n\nconst float SHIFT_RIGHT_5 = 1.0 / 32.0;\n\nconst float SHIFT_LEFT_11 = 2048.0;\n\nconst float SHIFT_LEFT_5 = 32.0;\n\nconst float NORMALIZE_6 = 1.0 / 64.0;\n\nconst float NORMALIZE_5 = 1.0 / 32.0;\n\n\n\n#ifdef HAS_POSITION\n\n attribute vec3 POSITION;\n\n#endif\n\n\n\n#if defined(HAS_RGB)\n\n attribute vec3 RGB;\n\n#elif defined(HAS_RGBA)\n\n attribute vec4 RGBA;\n\n#elif defined(HAS_RGB565)\n\n attribute float RGB565;\n\n#endif\n\n\n\nuniform vec4 pointColor;\n\nuniform float pointSize;\n\n\n\nuniform mat4 projViewModelMatrix;\n\nuniform float pointOpacity;\n\n\n\nvarying vec4 vColor;\n\n\n\n#ifdef HAS_NORMAL\n\n #ifdef HAS_NORMAL_OCT16P\n\n attribute vec2 NORMAL_OCT16P;\n\n float signNotZero(float value) {\n\n return value >= 0.0 ? 1.0 : -1.0;\n\n }\n\n vec2 signNotZero(vec2 value) {\n\n return vec2(signNotZero(value.x), signNotZero(value.y));\n\n }\n\n vec3 octDecode(vec2 encoded, float range) {\n\n if (encoded.x == 0.0 && encoded.y == 0.0) {\n\n return vec3(0.0, 0.0, 0.0);\n\n }\n\n encoded = encoded / range * 2.0 - 1.0;\n\n vec3 v = vec3(encoded.x, encoded.y, 1.0 - abs(encoded.x) - abs(encoded.y));\n\n if (v.z < 0.0) {\n\n v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);\n\n }\n\n return normalize(v);\n\n }\n\n vec3 octDecode(vec2 encoded) {\n\n return octDecode(encoded, 255.0);\n\n }\n\n #else\n\n attribute vec3 NORMAL;\n\n #endif\n\n uniform vec3 lightDir;\n\n uniform mat3 modelNormalMatrix;\n\n uniform mat4 positionMatrix;\n\n float getLambertDiffuse(vec3 lightDir, vec3 normal) {\n\n return max(dot(-lightDir, normal), 0.0);\n\n }\n\n#endif\n\n\n\nvoid main() {\n\n #if defined(HAS_RGB)\n\n vColor = vec4(RGB / 255.0, 1.0) * pointOpacity;\n\n #elif defined(HAS_RGBA)\n\n vColor = RGBA / 255.0 * pointOpacity;\n\n #elif defined(HAS_RGB565)\n\n float compressed = RGB565;\n\n float r = floor(compressed * SHIFT_RIGHT_11);\n\n compressed -= r * SHIFT_LEFT_11;\n\n float g = floor(compressed * SHIFT_RIGHT_5);\n\n compressed -= g * SHIFT_LEFT_5;\n\n float b = compressed;\n\n vec3 rgb = vec3(r * NORMALIZE_5, g * NORMALIZE_6, b * NORMALIZE_5);\n\n vColor = vec4(rgb, 1.0);\n\n #else\n\n vColor = pointColor;\n\n #endif\n\n\n\n #ifdef HAS_POSITION\n\n vec3 localPos = POSITION;\n\n #endif\n\n\n\n #ifdef HAS_NORMAL\n\n mat3 positionNormalMatrix = mat3(positionMatrix);\n\n mat3 normalMatrix = modelNormalMatrix * positionNormalMatrix;\n\n #ifdef HAS_NORMAL_OCT16P\n\n vec3 localNormal = octDecode(NORMAL_OCT16P);\n\n #else\n\n vec3 localNormal = NORMAL;\n\n #endif\n\n vec3 normal = normalize(normalMatrix * localNormal);\n\n float colorStrength = getLambertDiffuse(lightDir, normal);\n\n colorStrength = max(colorStrength, 0.5);\n\n vColor *= colorStrength;\n\n #endif\n\n\n\n gl_Position = projViewModelMatrix * vec4(localPos, 1.0);\n\n gl_PointSize = pointSize;\n\n}\n\n",frag:"#define SHADER_NAME PNTS\n\nprecision mediump float;\n\n\n\nvarying vec4 vColor;\n\n\n\nvoid main() {\n\n gl_FragColor = vColor;\n\n}\n\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:(t,e)=>n.multiply(i,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,r)=>o.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.L();this.K=new r.PhongShader({extraCommandProps:s}),this.j=new r.pbr.StandardShader({extraCommandProps:s});const a=this.t;ie(a.getRenderer().canvas,this.l,a.getMap()),this.picking=new r.FBORayPicking(this.h,{vert:this.j.vert,extraCommandProps:s,uniforms:this.j.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap())}L(){return{viewport:{x:0,y:0,width:()=>this.i?this.i.width:1,height:()=>this.i?this.i.height:1},colorMask:(t,e)=>e.colorMask||de,cull:{enable:!0,face:(t,e)=>e.cullFace||"back"},stencil:{enable:(t,e)=>!0===e.stencilEnable,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}}}nt(t){return{projViewMatrix:this.getMap().projViewMatrix,color:t&&t.color||[0,1,0]}}q(t){const e=this.getMap(),r=e.getLightManager(),n=(r&&r.getDirectionalLight()||{}).direction||[1,1,-1],i=t&&t.pointOpacity||1;return{projViewMatrix:e.projViewMatrix,pointOpacity:i,lightDir:s.normalize(n,n)}}F(){const t=this.getMap(),e=this.t.getRenderer().canvas,{iblTexes:r,dfgLUT:n}=oe(e),i=ae(t,r,n);return y(i,{czm_lightDirectionEC:i.light0_viewDirection,lightSpecular:[1,1,1],viewMatrix:t.viewMatrix,projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,outSize:[e.width,e.height],polygonFill:[1,1,1,1],polygonOpacity:1}),i}Nt(t,e,n,i){const s=e.materials[t];if(!s||!s.baseColorTexture&&!s.pbrMetallicRoughness)return null;const o=y({},i);if(s.baseColorTexture){const t=e.textures[s.baseColorTexture.index];let r;t&&!t.image.color&&(r=this.Mt(t)),o.baseColorFactor=t&&t.image.color||s.baseColorFactor||[1,1,1,1],r&&(o.baseColorTexture=r)}else{if(s.normalTexture){const t=this.Mt(e.textures[s.normalTexture.index]),r=s.normalTexture.scale||1;o.normalTexture=t,o.normalMapFactor=r}if(s.occlusionTexture){const t=this.Mt(e.textures[s.occlusionTexture.index]),r=s.occlusionTexture.strength||1;o.occlusionTexture=t,o.occlusionFactor=r}if(s.emissiveTexture){const t=this.Mt(e.textures[s.emissiveTexture.index]);o.emissiveTexture=t}s.emissiveFactor;const t=s.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(o.baseColorFactor=t.baseColorFactor),t.baseColorTexture&&void 0!==t.baseColorTexture.index){const r=e.textures[t.baseColorTexture.index];r.image&&r.image.color?o.baseColorFactor=o.baseColorFactor?a.multiply(o.baseColorFactor,o.baseColorFactor,r.image.color):r.image.color:(o.baseColorTexture=this.Mt(r),o.baseColorTexture.getREGLTexture(this.l))}if(p(t.metallicFactor)||(o.metallicFactor=t.metallicFactor),p(t.roughnessFactor)||(o.roughnessFactor=t.roughnessFactor),s.metallicRoughnessTexture){const t=this.Mt(e.textures[s.metallicRoughnessTexture.index]);o.metallicRoughnessTexture=t}}}if(s.s3mMaterial)return new r.Material(o);let c=new r.pbr.StandardMaterial(o);"phong"===n&&(c=r.PhongMaterial.convertFrom(c));const l=s.pbrMetallicRoughness,f=l&&l.baseColorTexture&&l.baseColorTexture.extensions;return f&&f.KHR_texture_transform&&(c.set("khr_offset",f.KHR_texture_transform.offset||[0,0]),c.set("khr_rotation",f.KHR_texture_transform.rotation||0),c.set("khr_scale",f.KHR_texture_transform.scale||[1,1])),c.once("complete",this.M),c}Mt(t){const e={type:t.type?Qt(t.type):"uint8",format:t.format?Jt(t.format):"rgba",flipY:!!t.flipY},n=t.image;n.array?e.data=n.array:n.mipmap&&(e.mipmap=n.mipmap),e.width=n.width,e.height=n.height;const i=t.sampler||t.texture&&t.texture.sampler;return i&&(i.magFilter&&(e.mag=jt(i.magFilter)),i.minFilter&&(e.min=qt(i.minFilter)),i.wrapS&&(e.wrapS=$t(i.wrapS)),i.wrapT&&(e.wrapT=$t(i.wrapT))),new r.Texture2D(e,this.O)}wt(t){const e=t.image,r=window.URL||window.webkitURL,n=new Blob([e.array],{type:e.mimeType});return r.createObjectURL(n)}C({target:t}){const e=t.St,r=this.u[e];if(r.count--,!r.count){const t=r.meshes;this.T[e]=t,delete this.u[e];const n=t.At;delete t.At,n(null,{mesh:r.meshes,id:e})}}Ot(){return fe}ct(t){return this.t.ct(t)}ft(t,e){const r=this.getMap();return r.getGLZoom?r.distanceToPoint(t,e,r.getGLZoom()):r.distanceToPointAtRes(t,e,r.getGLRes())}_pointToPrj(t){const e=this.getMap();return e.getGLZoom?e._pointToPrj(t,e.getGLZoom()):e._pointToPrjAtRes(t,e.getGLRes())}_prjToPoint(t){const e=this.getMap();return e.getGLZoom?e._prjToPoint(t,e.getGLZoom()):e._prjToPointAtRes(t,e.getGLRes(),me)}_t(t){return"Y"===t?re:"X"===t?ne:he}pick(t,e,r=3){const n=this.t;if(!n||!n.options.picking)return[];if(!this.pickingFBO||!this.picking)return[];const i=this.getMap(),s=this.F(),o=this.picking;o.render(this.R.getMeshes().filter((t=>!t.bloom)),s,!0);let a={};o.getRenderedMeshes().length&&(a=o.pick(t,e,r,s,{viewMatrix:i.viewMatrix,projMatrix:i.projMatrix,returnPoint:n.options.pickingPoint}));const{meshId:c,pickingId:l,point:f,coordinate:h}=a,u=(0===c||c)&&o.getMeshAt(c);if(!u||!u.geometry)return[];const _=u.properties;f&&f.length&&(f[0]=Math.round(1e5*f[0])/1e5,f[1]=Math.round(1e5*f[1])/1e5,f[2]=Math.round(1e5*f[2])/1e5);const d={batchId:l};if(n.options.debug&&(d.debugInfo=_),_&&_.batchTable){const{batchTable:t,batchTableBin:e,count:r}=_,n=l;for(const i in t)void 0!==t[i].byteOffset?d[i]=Tt(t[i],e,r,n):d[i]=t[i][n]}return[{data:d,point:f,coordinate:h}]}G(t){let e=new Set;for(let r=0,n=t.length;r<n;r++){const n=t[r].data.node;this.k(n)&&e.add(n.Y)}e=Array.from(e),e.sort();const r=new Map,n=e.length;for(let t=0;t<n;t++)r.set(e[t],t);return r}highlight(t){this.V=t;const e=this.t.getRenderer();this.X=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelAllHighlight(){this.V=null;const t=this.t.getRenderer();this.X=t.getFrameTimestamp(),t.setToRedraw(!0)}}const Ie=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")},Ne=Ie(),Se=Ne.gl_trans__coders=Ne.gl_trans__coders||{};function Oe(t,e){if(e)for(let r=0;r<e.length;r++){t[e[r].id||e[r].index]=e[r]}}Se.inject=function(t){const e=t.toString(),r=e.indexOf("{")+1,n=e.substring(0,r),i=Ne.gl_trans__coders=Ne.gl_trans__coders||{};let s=`${n}\n const _____getGlobal = ${Ie.toString()};\n const g___lobals = _____getGlobal()\n const tran_____scoders = g___lobals['gl_trans__coders'] = g___lobals['gl_trans__coders'] || {};`;for(const t in i)"inject"!==t&&"getTranscoder"!==t&&"registerTranscoder"!==t&&(s+='tran_____scoders["'+t+'"] ='+i[t].toString()+"\n;");return s+="\n"+e.substring(n.length),s},Se.registerTranscoder=function(t,e){Se[t]=e},Se.getTranscoder=function(t){return Se[t]};const Me=[];class we{constructor(t,e,r,n){this.Ct=t,this.H=e,this.xt=n,this.Ut=r.version,t.indexOf("i3s:tileset:")<0?(this.Ut<=1.6?this.vt="root":this.vt=0,r.version=this.Ut):(this.vt=t.substring("i3s:tileset:".length),this.Ut>1.6&&(this.vt=parseInt(this.vt))),this.Ct=t,this.Bt=r}load(){const t=this.Bt,e=t.layerScene.baseUrl;if(this.Ut<=1.6)return t[this.vt]&&t[this.vt].lodSelection?(this.Lt=t[this.vt],this.Pt()):new Promise((r=>{let n=e+"/nodes/"+this.vt;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.xt(this.H,n,(()=>{this.Lt=t[this.vt],r(this.Pt())}))}));if(this.Ut>=1.7){if(t[this.vt])return this.Lt=t[this.vt],this.Pt();const r=Math.floor(this.vt/t.nodesPerPage);return new Promise((n=>{let i=e+"/nodepages/"+r;t.layerScene.eslpk&&(i+=".json"),this.xt(this.H,i,(()=>{this.Lt=t[this.vt],n(this.Pt())}))}))}return null}getTileset(){return this.Dt}getChildrenURL(){return this.Ft}Pt(){const t=this.Bt,e=t.layerScene.baseUrl,r=this.Lt.children,n=[],i={};if(r)for(let s=0;s<r.length;s++)if(this.Ut<=1.6){const o=r[s].id;if(t[o])continue;const a=o;i[a]||(i[a]=new Promise((r=>{let n=e+"/nodes/"+a;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.xt(this.H,n,(()=>{r()}))})),n.push(i[a]))}else{const o=r[s];if(t[o])continue;const a=Math.floor(o/t.nodesPerPage);i[a]||(i[a]=new Promise((r=>{let n=e+"/nodepages/"+a;t.layerScene.eslpk&&(n+=".json"),this.xt(this.H,n,(()=>{r()}))})),n.push(i[a]))}return n.length?Promise.all(n).then((()=>this.Gt())):this.Gt()}Gt(){return Promise.resolve(this.kt())}Ht(t){Oe(this.Bt,t)}kt(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.Vt(this.Lt,!0)}}Vt(t){const e=this.Ut,r=this.Bt,n=t;var i,s=n.obb,o=n.mbs,a={};if(o)i=Ce([],o[0],o[1],o[2]),a.sphere=[...i,o[3]];else if(s){const t=function(t,e,r){const n=m.fromQuat([],r);return n[0]=n[0]*e[0],n[1]=n[1]*e[0],n[2]=n[2]*e[0],n[3]=n[3]*e[1],n[4]=n[4]*e[1],n[5]=n[5]*e[1],n[6]=n[6]*e[2],n[7]=n[7]*e[2],n[8]=n[8]*e[2],[...t,...n]}(i=Ce([],s.center[0],s.center[1],s.center[2]),s.halfSize,s.quaternion),e=t[3]+t[6]+t[9],r=t[4]+t[7]+t[10],n=t[5]+t[8]+t[11];E.set(Me,e,r,n);const o=E.len(Me);a.sphere=[...i,o]}var c=1/0,l=0;if(n.mbs?l=n.mbs[3]:n.obb&&(l=Math.max(Math.max(n.obb.halfSize[0],n.obb.halfSize[1]),n.obb.halfSize[2])),void 0!==n.lodThreshold)"maxScreenThresholdSQ"===r.lodSelectionMetricType?c=l/(Math.sqrt(n.lodThreshold)/(.25*Math.PI)):console.error("Unsupported lodSelectionMetricType in Layer");else if(void 0!==n.lodSelection)for(var f=0;f<n.lodSelection.length;f++)"maxScreenThreshold"===n.lodSelection[f].metricType&&(c=l/n.lodSelection[f].maxError);(c===1/0||isNaN(c))&&(c=1e5);var h=16*c;const u=T.identity([]),_=n.children;var d;if(_){d=[];const t=this.Bt;for(let r=0;r<_.length;r++){const n=e<=1.6?_[r].id:_[r];if(!t[n]){d=null;break}d.push(this.Vt(t[n]))}}var A={refine:"REPLACE",boundingVolume:a,transform:u,geometricError:h};return e<=1.6?t.lodSelection?t.geometryData&&(A.content={uri:"i3s:mesh:"+(t.id||t.index)}):A.content={uri:"i3s:tileset:"+(t.id||t.index)}:_&&_.length&&!d?A.content={uri:"i3s:tileset:"+(t.id||t.index)}:n.mesh&&(A.content={uri:"i3s:mesh:"+(t.id||t.index)}),d&&d.length&&(A.children=d),A}getJSON(){return this.Lt}}function Ce(t,e,r,n){return K(t,b(e),b(r),n)}const xe=!!Se.ktx2,Ue=n.identity([]),ve=(()=>{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 Be(t){return t.indexOf("i3s:mesh")>=0}const Le="i3s:mesh:".length;function Pe(t,e,r,n,i){const s=e.layerScene.eslpk,o=function(t,e){const r=e.substring(Le);return t>=1.7?parseInt(r):r}(e.version,t),a=e[o],c=e.layerScene.baseUrl,l=[];let f=!1;const h=Ue;let u,_;if(e.version<=1.6){if(!a.geometryData)return null;const t=a.geometryData.length;let r=c+`/nodes/${a.id}/`+a.geometryData[t-1].href;s&&(r+=".bin");const n={geometry:{url:r,info:e.layerScene.store.defaultGeometrySchema}};let i=a.textureData&&a.textureData[0]&&a.textureData[0].href;if(i){const t=e.layerScene.store.textureEncoding[0];let r;r="image/jpeg"===t?"jpg":"png",s&&(i+="."+r);const o={pbrMetallicRoughness:{baseColorTexture:{url:c+`/nodes/${a.id}/`+i,factor:1,format:r,mimeType:t},metallicFactor:0}};n.material=o}l.push(n)}else{u=a.mesh.geometry,_=a.mesh.material;const t=e.layerScene.geometryDefinitions[u.definition],{geometryBuffers:o}=t;f=n&&2===o.length;const h=Se.draco&&f?o[1]:o[0],d=Se.draco&&f?1:0;let E=c+`/nodes/${u.resource}/geometries/`+d;s&&(E+=".bin");const T={geometry:{url:E,info:h}};if(i&&ve&&f&&!Se.draco)throw new Error("Must import @maptalks/transcoder.draco to load i3s draco compressed geometry");const m=e.layerScene.materialDefinitions,A=e.layerScene.textureSetDefinitions;let p,y=0;if(_&&(y=m[_.definition]),m){p=function(t,e,r,n,i,s){const o=JSON.parse(JSON.stringify(t));return De(o,e,r,n,i,s),o}(y,A,c,_.resource,r,e.layerScene.eslpk)}else p={pbrMetallicRoughness:{metallicFactor:0}};T.material=p,l.push(T)}return{dracoCompression:f,meshes:l,nodeIndex:o,center:a.obb&&a.obb.center||a.mbs&&[a.mbs[0],a.mbs[1],a.mbs[2]],transform:h}}function De(t,e,r,n,i,s){for(const o in t)if(t[o]&&t[o].textureSetDefinitionId>=0){const a=e[t[o].textureSetDefinitionId],c="images/"+a.formats[0].format,l=Fe(a.formats,i),f={url:r+`/nodes/${n}/textures/${l.name}`,factor:void 0===t[o].factor?1:t[o].factor,format:l.format,mimeType:c};if(s){let t="";switch(l.format){case"dds":t="bin.dds";break;case"jpg":case"png":t=l.format}f.url+="."+t}t[o]=f}else R(t[o])&&De(t[o],e,r,n,i,s)}function Fe(t,e){for(let r=0;r<=t.length;r++){const n=t[r].format;if("dds"===n&&e.hasExtension("WEBGL_compressed_texture_s3tc"))return t[r];if("jpg"===n||"png"===n)return t[r];if("ktx2"===n&&xe)return t[r]}return null}const Ge=[];class ke extends t.renderer.CanvasRenderer{constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new k(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.zt={},this.Xt=[],this.xt=this.Yt.bind(this)}getAnalysisMeshes(){if(!this.painter)return Ge;const t=this.painter.getPaintedMeshes();if(!t)return Ge;const e=[],{b3dmMeshes:r,pntsMeshes:n,i3dmMeshes:i}=t;return r.length&&B(e,r),n.length&&B(e,n),i.length&&B(e,i),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.Xt.length||super.needToRedraw())}getFrameTimestamp(){return this.Zt}drawOnInteracting(t,e,r){this.draw(e,r)}draw(t,e){this.Zt=t;const r=this.prepareCanvas();if(r&&!r.intersects(this.canvasExtent2D))return void this.completeRender();const{root:n,tiles:i}=this.layer.getTiles(),s=i.length;if(!i||!s)return void this.completeRender();this.Wt(),this.Kt();const{selectedTiles:o,leaves:a,requests:c}=this.jt(n,i);c.length&&this.loadTiles(c),this.qt(o,a,e),this.$t(),c.length||this.completeRender()}jt(t,e){let r=[];this.Qt();let n=0;const i=this.Jt(),s={};let o=!1,a=!1;for(let t=0;t<e.length;t++){const i=e[t],c=i.node;if(s[c.id])continue;s[c.id]=1;let l=!1;const f=this.getCachedTile(c.id);if(this.te(c.id)?(n++,l=a=!0,this.tilesLoading[c.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=a=!0),(!i.node.ee||i.node.ee<=500)&&(o=!0,i.selected=!0,i.data=f)):this.painter.has(c)||(l=a=!0,r.push(c)),!l)continue;if(this.re(i))o=!0;else{this.ne(i).length&&(o=!0)}}let c=[],l={};if(o&&({selectedTiles:c,leaves:l}=this.ie(t)),r.length>1&&(r.sort(He),i)){const t=i-n;r=t>0?r.slice(0,t):[]}return{loading:a,requests:r,selectedTiles:c,leaves:l}}ie(t){const e=[],r={};let n;const i=[t],s=[];for(;i.length>0||s.length>0;){if(s.length>0){const t=s[s.length-1];if(t.se===i.length){s.pop(),t===n&&(t.leave=!0,r[t.node.id]=1),e.push(t);continue}}const t=i.pop(),o=t.children;if(t.selected)if("add"===t.node.refine)r[t.node.id]=1,t.selectionDepth=s.length,e.push(t);else{if(t.selectionDepth=s.length,n=t,0===o.length){t.leave=!0,r[t.node.id]=1,e.push(t);continue}s.push(t),t.se=i.length}for(let t=0;t<o.length;t++)i.push(o[t])}return{selectedTiles:e,leaves:r}}re(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}ne(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const r=t.Y+1,n=[t.node];for(;n.length>0;){const i=n.pop().children;for(let s=0,o=i.length;s<o;s++){if((!i[s].content||!i[s].content.url)&&i[s].children&&i[s].children.length){n.push(i[s]);continue}const o=i[s].id;if(this.tileCache.has(o)){const r=this.layer.oe(i[s],t);r.selected=!0,r.data=this.tileCache.get(o),t.children.push(r),e.push(r)}else i[s].Y<=r&&n.push(i[s])}}return e}qt(t,e,r){this.tileCache.markAll(!1);for(let e=0,r=t.length;e<r;e++){const r=t[e].data;r.current=!0,this.tileCache.add(t[e].node.id,r)}this.tileCache.shrink();const n={tiles:t,leaves:e};this.onDrawTileStart(n);const i=this.painter.paint(t,e,r);this.onDrawTileEnd(n),i&&this.layer.fire("canvasisdirty",{renderCount:i})}onDrawTileStart(){}onDrawTileEnd(){}loadTiles(t){for(let e=0,r=t.length;e<r;e++){const r=t[e];this.tilesLoading[r.id]={current:!0,node:r},this.loadTile(r)}}loadTile(t){let e=t.content.url;if(U(e)){const r=v(e);return void this.ae(e,r,t)}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const r=t.H,n=this.ce[r];return new we(e,r,n,this.xt).load().then((r=>{this.onTilesetLoad(r,t,e)}))}t&&-1===e.indexOf("http://")&&-1===e.indexOf("https://")&&!Be(e)&&(e=t.baseUrl+e);const r=this.layer.options.services[t.H];if(r.ajaxInMainThread){let n=r.urlParams;n&&(n=(e.indexOf("?")>0?"&":"?")+n);let i=d.getArrayBuffer(e+(n||""),r.fetchOptions);const s=i.xhr;i=i.then((r=>{delete this.zt[e],r?this.ae(e,r.data,t):this.onTileError(null,t)})).catch((r=>{delete this.zt[e],this.onTileError(r,t)})),this.zt[e]=s}else this.ae(e,null,t)}ae(t,e,n){let i=this.le;i||(i=r.Util.getSupportedFormats(this.gl.gl||this.gl),this.le=i);const s=this.layer.options.services[n.H];s.isSuperMapiServer&&(t=function(t,e){const r=t.substring(e.length).split("/"),n=[];for(let t=0;t<r.length;t++)n.push(encodeURIComponent(r[t]));return e+n.join("/")}(t,n.baseUrl));const o={url:t=this.layer.getTileUrl(t,n.baseUrl,s),arraybuffer:e,rootIdx:n.H,upAxis:n.dt,transform:n.matrix,supportedFormats:i};if(Be(t)){const e=this.ce[n.H];if(o.i3sInfo=Pe(t,e,this.regl,this.layer.options.enableI3SCompressedGeometry,this.layer.options.forceI3SCompressedGeometry),!o.i3sInfo)return void this.onTileError({status:404},n)}this.workerConn.loadTile(this.layer.getId(),o,((e,r)=>{if(e)return void this.onTileError(e,n);const{magic:i}=r;"b3dm"===i||"pnts"===i||"i3dm"===i||"cmpt"===i?this.Xt.push({data:r,tile:n}):this.onTilesetLoad(r,n,t)}))}Kt(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let r=0;for(;this.Xt.length&&(r<e||!t.isInteracting());){const{data:t,tile:e}=this.Xt.shift(),{magic:n}=t;"b3dm"===n?this.painter.createB3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.fe(t,e,r,n)})):"pnts"===n?this.painter.createPntsMesh(t,e.id,e,((r,{mesh:n})=>{this.fe(t,e,r,n)})):"i3dm"===n?this.painter.createI3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.fe(t,e,r,n)})):"cmpt"===n&&this.painter.createCMPTMesh(t,e.id,e,((r,{mesh:n})=>{this.fe(t,e,r,n)})),r++}}fe(t,e,r,n){if(r)this.onTileError(r,e);else{const r=this.he(n);e.memorySize=r,this.onTileLoad(t,e)}}he(t){let e=0;if(Array.isArray(t))for(let r=0;r<t.length;r++)t[r]&&(e+=this.he(t[r]));else t&&(e+=t.getMemorySize());return e}onTileLoad(t,e){this.layer&&(delete this.tilesLoading[e.id],this.layer.onTileLoad(t,e),this.ue(e),this.setToRedraw(),this.layer.fire("tileload",{node:e}))}onTilesetLoad(t,e,r){this.layer&&(t.capabilities||t.layers&&t.layers[0]&&t.layers[0].capabilities?this._e(t,e,r):(delete this.tilesLoading[e.id],this.layer.onTilesetLoad(t,e,r)))}onTileError(t,e){if(!this.layer)return;const r=e.content.url;console.warn("failed to load 3d tile: "+r),console.warn(t),delete this.tilesLoading[e.id],this.de(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}de(e,r){const n={loadTime:t.Util.now(),current:!0,error:r,node:e};this.tileCache.add(e.id,n)}ue(e){const r={loadTime:t.Util.now(),current:!0,node:e};this.tileCache.add(e.id,r)}abortTileLoading(t){if(!t||!this.workerConn)return;const e=t.node.content.url;if(this.layer.options.services[t.node.H].ajaxInMainThread){const t=this.zt[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.zt[e]}Qt(){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.Ee(this.canvas,e)),this.regl=this.regl||l({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 be(this.regl,t),this.layer.Te()}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new D("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let r=this.layer.options||{};r=y({},r),delete r.offset,r.projection=t.getSpatialReference().getProjection().code;const n=this.layer.getId();e.addLayer(n,r,(t=>{if(t)throw t;this.layer&&(this.ready=!0,this.layer.fire("workerready"))}))}onRemove(){this.painter&&this.painter.remove(),this.pickingFBO&&(this.canvas.pickingFBO||this.pickingFBO.destroy(),delete this.pickingFBO),this.workerConn&&(this.workerConn.removeLayer(this.layer.getId(),(t=>{if(t)throw t})),this.workerConn.remove(),delete this.workerConn),this.clear(),delete this.tileCache,super.onRemove()}clear(){this.$t(!0),this.tileCache.reset(),this.tilesLoading={},super.clear()}clearCanvas(){this.regl&&this.regl.clear({color:[0,0,0,0],depth:1,stencil:0}),super.clearCanvas()}getTileOpacity(){return 1}getStencilValue(){return 0}$t(t){this.me||(this.me=Date.now());const e=Date.now();if(t||!(e-this.me<this.layer.options.retireInterval)){this.me=e;for(const e in this.tilesLoading){const r=this.tilesLoading[e];!t&&r.current||this.abortTileLoading(r)}}}Jt(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}Ee(t,e){const r=["webgl","experimental-webgl"];let n=null;for(let i=0;i<r.length;++i){try{n=t.getContext(r[i],e)}catch(t){}if(n)break}return n}te(t){return!!this.tilesLoading[t]}getI3DMMeshes(){return this.painter.getI3DMMeshes()}getPNTSMeshes(){return this.painter.getPNTSMeshes()}getB3DMMeshes(){return this.painter.getB3DMMeshes()}readBatchData(t,e,r){return dt(t,e,0,r)}Wt(){if(!this.Ae)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const r=[];for(const n in this.Ae){const i=this.Ae[n];if("pending"===i.status)continue;i.status="pending";const s=i.rootIdx;if(r.push(d.getJSON(n).then((t=>{delete this.Ae[n];const e=this.ce[s];if(e){t.nodes?Oe(e,t.nodes):(e[t.id]=t,Oe(e,t.children));for(let t=0;t<i.length;t++)i[t]();this.setToRedraw()}else this.setToRedraw()}))),e++,e>=t)break}r.length&&Promise.all(r)}Yt(t,e,r){this.Ae||(this.Ae={}),this.Ae[e]=this.Ae[e]||[],this.Ae[e].rootIdx=t,this.Ae[e].push(r),this.setToRedraw()}_e(t,e,r){this.ce||(this.ce=[]);const n=e.H;this.ce[n]||(this.ce[n]={});const i=this.ce[n],s=this.layer.options.services[n];t.layers&&(t=t.layers[0],"/"!==r[r.length-1]&&(r+="/"),r+="layers/0"),i.version=+(s.i3sVersion||t.store.version),function(t,e,r,n,i,s){if(!i.layerScene){i.layerScene=t,i.nodesPerPage=t.nodePages&&t.nodePages.nodesPerPage||64,i.lodSelectionMetricType=t.nodePages&&t.nodePages.lodSelectionMetricType;let e=n;if(i.layerScene.eslpk=e.indexOf("3dSceneLayer.json")>=0,e.endsWith(".json")){const t=n.lastIndexOf("/");e=t<0?"./":n.substring(0,t)}i.layerScene.baseUrl=function(t){return t.split("?")[0]}(e)}return new we(n,e,i,s).load()}(t,n,0,r,i,this.xt).then((t=>{this.onTilesetLoad(t,e,r)}))}pick(t,e,r){return this.painter?this.painter.pick(t,e,r&&r.tolerance):[]}highlight(t){if(this.V||(this.V=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const r=t[e].service||0;let n=this.V[r];n||(n=this.V[r]=new Map),n.set(t[e].id,t[e])}else{const e=t.service||0;let r=this.V[e];r||(r=this.V[e]=new Map),r.set(t.id,t)}this.painter.highlight(this.V)}cancelHighlight(t,e){if(!this.V)return;const r=this.V[t];if(r){if(Array.isArray(e))for(let t=0;t<e.length;t++)r.delete(e[t]);else r.delete(e);this.painter.highlight(this.V)}}cancelAllHighlight(){delete this.V,this.painter.cancelAllHighlight()}}function He(t,e){return t.tt-e.tt}function Ve(t,e,r){return t[0]=e[r],t[1]=e[r+3],t[2]=e[r+6],t}function ze(t,e,r){return Math.sqrt(function(t,e,r){var n=E.subtract(Xe,r,t),i=Ve(Ye,e,0),s=Ve(Ze,e,1),o=Ve(We,e,2),a=E.len(i),c=E.len(s),l=E.len(o);E.normalize(i,i),E.normalize(s,s),E.normalize(o,o);var f=Ke;f[0]=E.dot(n,i),f[1]=E.dot(n,s),f[2]=E.dot(n,o);var h,u=0;f[0]<-a?u+=(h=f[0]+a)*h:f[0]>a&&(u+=(h=f[0]-a)*h);f[1]<-c?u+=(h=f[1]+c)*h:f[1]>c&&(u+=(h=f[1]-c)*h);f[2]<-l?u+=(h=f[2]+l)*h:f[2]>l&&(u+=(h=f[2]-l)*h);return u}(t,e,r))}const Xe=[],Ye=[],Ze=[],We=[],Ke=[];const je=2*Math.PI;class qe{constructor(t,e,r,n){this.west=t,this.south=e,this.east=r,this.north=n}static contains(t,e){var r=e[0],n=e[1],i=t.west,s=t.east;return s<i&&(s+=je,r<0&&(r+=je)),(r>i||ct(r,i,1e-14))&&(r<s||ct(r,s,1e-14))&&n>=t.south&&n<=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 $e=[0,0,1];function Qe(t,e){return K(e,t[0],t[1],t[2])}class Je{constructor(t,e){this.normal=s.copy([],t),this.distance=e}static fromPointNormal(t,e,r){var n=-s.dot(e,t);return s.copy(r.normal,e),r.distance=n,r}}const tr=[],er=[],rr=[],nr=[],ir=[],sr=[],or=[],ar=[],cr=[],lr=[],fr=new Je([1,0,0],0),hr=[];class ur{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new qe(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){var r,n,i,o=0;if(!qe.contains(this.rectangle,e)){var a=this.southwestCornerCartesian,c=this.northeastCornerCartesian,l=this.westNormal,f=this.southNormal,h=this.eastNormal,u=this.northNormal,_=s.subtract(hr,t,a),d=s.dot(_,l),E=s.dot(_,f),T=s.subtract(hr,t,c),m=s.dot(T,h),A=s.dot(T,u);d>0?o+=d*d:m>0&&(o+=m*m),E>0?o+=E*E:A>0&&(o+=A*A)}if(r=e[2],n=this.minimumHeight,r>(i=this.maximumHeight)){var p=r-i;o+=p*p}else if(r<n){var y=n-r;o+=y*y}return Math.sqrt(o)}computeBox(t){const e=this;Qe(qe.southwest(t,er),e.southwestCornerCartesian),Qe(qe.northeast(t,er),e.northeastCornerCartesian),tr[0]=t.west,tr[1]=.5*(t.south+t.north),tr[2]=0;var r=Qe(tr,rr),n=s.cross(ir,r,$e);s.normalize(e.westNormal,n),tr[0]=t.east;var i=Qe(tr,ar),o=s.cross(ir,$e,i);s.normalize(e.eastNormal,o);var a,c=s.subtract(ir,r,i),l=s.normalize(nr,c),f=t.south;if(f>0){tr[0]=.5*(t.west+t.east),tr[1]=f;var h=Qe(tr,cr);s.copy(lr,l);var u=Je.fromPointNormal(e.southwestCornerCartesian,e.westNormal,fr);_r(cr,lr,u,e.southwestCornerCartesian),a=st(h,sr)}else a=ot(qe.southeast(t,er),sr);var _=s.cross(or,a,c);s.normalize(e.southNormal,_);var d,E=t.north;if(E<0){tr[0]=.5*(t.west+t.east),tr[1]=E;var T=Qe(tr,cr);s.scale(lr,l,-1);var m=Je.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,fr);_r(cr,lr,m,e.northeastCornerCartesian),d=st(T,sr)}else d=ot(qe.northwest(t,er),sr);var A=s.cross(or,c,d);s.normalize(e.northNormal,A)}}function _r(t,e,r,n){var i=t,o=e,a=r.normal,c=s.dot(a,o);if(!(Math.abs(c)<1e-15)){var l=(-r.distance-s.dot(a,i))/c;if(!(l<0))return n=s.scale(n,o,l),s.add(n,i,n)}}const dr=new t.Extent(0,0,0,0),Er=new t.Extent(0,0,0,0),Tr=[],mr=[],Ar=[],pr=[],yr=new t.Point(0,0),gr=[],Rr=new t.Coordinate(0,0),br=n.identity([]);class Ir extends t.Layer{constructor(t,e){super(t,e),this.pe(),this.zt={},this.ye=[]}pe(){let t=this.options.services.map((t=>t.url));this.ge=t.map(((t,e)=>function(t,e){t=N(t);return{visible:1,baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:n.identity([]),H:e,Y:0}}(t,e))),this.fire("rootready",{roots:this.ge.slice(0)})}showService(t){return this.Re(t,1),this}hideService(t){return this.Re(t,0),this}Re(t,e){const r=this.ge[t];if(!r)return;r.visible=e;const n=this.getRenderer();n&&n.setToRedraw()}getTileUrl(t){return t}getExtent(e){if(!e&&0!==e){const e=new t.Extent;for(let t=0;t<this.ge.length;t++)if(this.ge[t].boundingVolume){const r=this.boundingVolumeToExtent(this.ge[t]);e._combine(r)}return e}return this.ge[e]&&this.ge[e].boundingVolume?this.boundingVolumeToExtent(this.ge[e]):null}boundingVolumeToExtent(e){const r=e.boundingVolume.be?br:e.matrix,n=this.getMap();if(e.boundingVolume.region){const r=e.boundingVolume.region;return new t.Extent(I(r[0]),I(r[1]),I(r[2]),I(r[3]))}if(e.boundingVolume.sphere){const i=e.boundingVolume.sphere,o=tt([],s.transformMat4([],i,r)),a=i[3],c=n.locate(o,-a,a),l=n.locate(o,a,-a);return new t.Extent(c,l)}if(e.boundingVolume.box){const i=e.boundingVolume.box,a=s.transformMat4([],i,r),c=new t.Coordinate(tt([],a)),l=i.slice(3);o.multiply(l,o.fromMat4([],e.matrix),l);const f=s.length(l.slice(0,3)),h=s.length(l.slice(3,6)),u=s.length(l.slice(6,9)),_=Math.max(f,h,u),d=n.locate(c,-_,_),E=n.locate(c,_,-_);return new t.Extent(d,E)}return null}getRootTiles(){return this.ge}getTiles(){const t=this.getRenderer();if(!t.ready)return this.Ie(),{tiles:pr};const e=this.getMap(),r=e.cameraPosition;let n,i;if(e.getGLZoom)i=e.pointToDistance(r[2],0,e.getGLZoom()),Rr.set(r[0],r[1]),n=e.pointToCoord(Rr,e.getGLZoom());else{const t=e.getGLRes();i=e.pointAtResToDistance(r[2],0,t),Rr.set(r[0],r[1]),n=e.pointAtResToCoord(Rr,t)}this.Ne=this.Ne||[],s.set(this.Ne,b(n.x),b(n.y),i),this.Se=K(this.Se||[],this.Ne[0],this.Ne[1],this.Ne[2]),this.Oe=2*Math.tan(.5*b(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const l=[];for(let e=0;e<this.ge.length;e++){const r=this.ge[e];if(!r.visible)continue;let n=1/0;const i=[r],s=this.Me(e);for(;i.length>0;){const e=i.pop();for(e.id||this.we(e);c.level>=e.Y;)c=c.parent;const r=this.Ce(e,s,o);if(r<1){let t=c;for(;t&&!t.content;)t=t.parent;0===r&&t&&t.content&&this.xe(l,t);if(!1===this.options.services[e.H].alwaysShow)continue;if(!(0===r&&e.Y<=n))continue;e.content&&(n=e.Y)}e.tt<1/0&&this.Ue(e);const a=this.oe(e,c);c.children.push(a);const f=e.children,h=f&&f.length,u=a.content;if(!h&&u&&this.xe(l,a),h){u&&"add"===e.refine&&this.xe(l,a),c=a;const r=f[0].parent;let n=!1;for(let s=0,o=f.length;s<o;s++){if(r){const e=t.getCachedTile(f[s].id);if(e&&e.error&&404!==e.error.status)continue;n=!0}else{n=!0,f[s].parent=e,f[s].dt=e.dt,f[s].baseUrl=e.baseUrl;const t=f[s].content&&(f[s].content.url||f[s].content.uri);t&&(U(t)||t.indexOf("i3s:")>=0?f[s].baseUrl=e.baseUrl:-1===t.indexOf("http://")&&-1===t.indexOf("https://")?f[s].content.url=e.baseUrl+t:f[s].baseUrl=t.substring(0,t.lastIndexOf("/")+1))}i.push(f[s])}!n&&u&&this.xe(l,a)}}}return{root:a,tiles:l}}xe(t,e){const{viewerRequestVolume:r}=e.node;r&&!function(t,e,r){if(r.region){const e=r.region;if(t[0]>=e[0]&&t[0]<=e[2]&&t[1]>=e[1]&&t[1]<=e[3])return!0}else{if(r.sphere)return Nr(r,e);if(r.box)return 0===Sr(r,e)}return!1}(this.Ne,this.Se,r)||t.push(e)}oe(t,e){return{id:t.id,node:t,children:[],level:t.Y,parent:e,content:t.content&&t.content.url}}we(e){e.id=t.Util.GUID(),e.matrix=e.transform||n.identity([]),e.ve=this.Be(e),e.parent&&(function(t){return t.content&&t.content.uri&&t.content.uri.indexOf("i3s:")>=0}(e)||(e.matrix=n.multiply(e.matrix,e.parent.matrix,e.matrix)),e.H=e.parent.H,void 0===e.Y&&(e.Y=e.parent.Y+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),this.Le(e)}Le(t){const e=t.boundingVolume;if(!e||e.be)return;const r=this.options.services[t.H].heightOffset||0,i=this.options.offset,o=g(i)||i[0]||i[1];if(!t.boundingVolume||!r&&n.exactEquals(t.matrix,br)&&!o)return;const{region:a,box:c,sphere:l}=e;if(a){const t=this.Pe([I(a[0]),I(a[1])]);a[0]=b(t.x),a[1]=b(t.y);const e=this.Pe([I(a[2]),I(a[3])]);a[2]=b(e.x),a[3]=b(e.y),a[4]+=r,a[5]+=r}else if(c||l){const e=c||l,n=s.transformMat4(Tr,e,t.matrix),i=tt(mr,n),o=this.Pe([i[0],i[1]]);i[0]=o.x,i[1]=o.y,i[2]+=r,K(e,b(i[0]),b(i[1]),i[2])}e.be=!0}Be(t){return void 0===t.geometricError||!t.boundingVolume}Ue(t){let e=t.parent;for(;e&&e.ve&&!(e.tt<=t.tt);)e.tt=t.tt,e=t.parent}onTileLoad(t,e){if(t.children&&(!e.children||!e.children.length)){e.children=t.children;const r=e.content.url;e.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const n=this.getRenderer();n&&n.setToRedraw()}}onTilesetLoad(t,e,r){if(!t)return void console.warn("invalid tileset at : "+r);const i=this.options.services[e.H],s=(t.asset&&t.asset.gltfUpAxis||e&&e.dt||i.upAxis||"Y").toUpperCase();t.root.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const o=r.indexOf("realspace/")>-1;0===e.Y&&(t.asset&&t.asset.s3mType&&o||i.isSuperMapiServer)&&(t.root.baseUrl+="data/path/");const a=t.asset.i3s;if(t.root.dt=s,e){const r=e.boundingVolume;y(e,t.root),e.refine=e.refine&&e.refine.toLowerCase()||"replace",r&&(e.boundingVolume=r);const i=t.root.transform;i&&(e.parent?a||(e.matrix=n.multiply([],e.parent.matrix,i)):e.matrix=i),this.Le(e),e.De=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.ve=this.Be(e);const s=e.content&&(e.content.url||e.content.uri);s&&e.content.uri&&(e.content.url=e.content.uri,delete e.content.uri),a||!s||U(s)||-1!==s.indexOf("http://")||-1!==s.indexOf("https://")||(e.content.url=e.baseUrl+s)}this.Ie(),this.fire("loadtileset",{tileset:t,index:e.H,url:r})}Ce(t,e,r){if(t.tt=1/0,0===t.Y||t.ve)return 1;if(!this.Fe(t,e,r))return-1;if(0===t.geometricError)return 1;let n=this.options.services[t.H].maximumScreenSpaceError;null==n&&(n=8);let i=this.Ge(t);return 0===i&&t.parent&&(i=.5*(t.parent.ee||0)),i>=n?1:0}ct(e,r){r||(r=new t.Point(0,0));const n=this.getMap();return n.getGLZoom?n.coordToPoint(e,n.getGLZoom(),r):n.coordToPointAtRes(e,n.getGLRes(),r)}Fe(e,r,i){const a=e.id;let c=this.ye[a];const{boundingVolume:l}=e,_=l.sphere;let d=l.region;const E=l.box;if(!c){let r,i,f;if(E&&(d=function(t,e){for(let e=0;e<9;e++)Pr[e]=t[e+3];const r=Pr;n.exactEquals(e,br)||o.multiply(r,o.fromMat4(gr,e),r);const i=s.copy(Or,t),a=s.set(Mr,r[0],r[1],r[2]),c=s.set(wr,r[3],r[4],r[5]),l=s.set(Cr,r[6],r[7],r[8]);xr[0]=xr[0]||[];const f=s.copy(xr[0],i);s.sub(f,f,a),s.sub(f,f,c),s.sub(f,f,l),xr[1]=xr[1]||[];const h=s.copy(xr[1],i);s.sub(h,h,a),s.sub(h,h,c),s.add(h,h,l),xr[2]=xr[2]||[];const u=s.copy(xr[2],i);s.sub(u,u,a),s.add(u,u,c),s.sub(u,u,l),xr[3]=xr[3]||[];const _=s.copy(xr[3],i);s.sub(_,_,a),s.add(_,_,c),s.add(_,_,l),xr[4]=xr[4]||[];const d=s.copy(xr[4],i);s.add(d,d,a),s.sub(d,d,c),s.sub(d,d,l),xr[5]=xr[5]||[];const E=s.copy(xr[5],i);s.add(E,E,a),s.sub(E,E,c),s.add(E,E,l),xr[6]=xr[6]||[];const T=s.copy(xr[6],i);s.add(T,T,a),s.add(T,T,c),s.sub(T,T,l),xr[7]=xr[7]||[];const m=s.copy(xr[7],i);s.add(m,m,a),s.add(m,m,c),s.add(m,m,l);for(let t=0;t<xr.length;t++)Ur[t]=Ur[t]||[],tt(Ur[t],xr[t]),vr[t]=Ur[t][0],Br[t]=Ur[t][1],Lr[t]=Ur[t][2];return[b(Math.min(...vr)),b(Math.min(...Br)),b(Math.max(...vr)),b(Math.max(...Br)),Math.min(...Lr),Math.max(...Lr)]}(E,e.matrix),l.region=d),d){r=dr.set(I(d[0]),I(d[1]),I(d[2]),I(d[3]));const t=r.getCenter(),e=this.ke(t);r=r.convertTo((t=>this.ct(t,yr)),Er),f=d[4],i=d[5],c=this.ye[a]=[[r.xmin,r.ymin,f*e[2]],[r.xmax,r.ymax,i*e[2]]],c.center=t}else if(_){const e=tt(Tr,_),r=new t.Coordinate(e),n=this.ct(r,yr).toArray(),i=this.ke(r);n.push(e[2]*i[2]),c=this.ye[a]=[n,_[3]*i[2]],c.center=r}}if(r){if(d)dr.xmin=c[0][0],dr.ymin=c[0][1],dr.xmax=c[1][0],dr.ymax=c[1][1];else if(_){const t=c[2];dr.xmin=c[0][0]-t,dr.ymin=c[0][1]-t,dr.xmax=c[0][0]+t,dr.ymax=c[0][1]+t}else if(E){const t=c[1],e=c[2];dr.xmin=c[0][0]-t,dr.ymin=c[0][1]-e,dr.xmax=c[0][0]+t,dr.ymax=c[0][1]+e}if(!r.intersects(dr))return!1}return d?f(i,c):_?h(i,c):!!E&&u(i,c)}ke(t){const e=this.getMap(),r=e.distanceToPointAtRes(100,100,e.getGLRes(),t);let n;return n=e.altitudeToPoint?e.altitudeToPoint(100,e.getGLRes())/100:r.y/100,s.set(Ar,r.x/100*1.01,r.y/100*1.01,n),Ar}Pe(e){Array.isArray(e)&&(e=new t.Coordinate(e));let r=this.options.offset;if(g(r)&&(r=r(Array.isArray(e)?new t.Coordinate(e):e)),r[0]||r[1]){const t=this.getMap(),n=t.getGLRes(),i=t.coordToPointAtRes(e,n);return i._sub(r),t.pointAtResToCoord(i,n)}return e}Me(e){const r=this.options.services[e].maxExtent;if(!r)return null;const n=this.ge[e];return n.maxExtent||(n.maxExtent=new t.Extent(r).convertTo((t=>this.ct(t)))),n.maxExtent}Ge(t){const e=this.Oe,r=t.geometricError;if(0===r)return t.ee=0,0;const n=this.getMap();let i;t.boundingVolume.region?i=function(t,e,r){t.He||(t.He=new ur(t.boundingVolume.region));return t.He.distanceToCamera(e,r)}(t,this.Se,this.Ne):t.boundingVolume.sphere?i=Nr(t.boundingVolume,this.Se):t.boundingVolume.box&&(i=Sr(t.boundingVolume,this.Se));const s=Math.max(Math.abs(i),1e-7),o=r*n.height/(s*e);return t.tt=i,t.ee=o,o}Ie(){const t=this.getRenderer();t&&t.setToRedraw()}gt(t){return this.ye[t]}identify(e,r={}){const n=this.getMap(),i=this.getRenderer();if(!n||!i)return[];const s=n.coordToContainerPoint(new t.Coordinate(e));return this.identifyAtPoint(s,r)}identifyAtPoint(t,e={}){const r=this.getMap(),n=this.getRenderer();if(!r||!n)return[];const i=r.getDevicePixelRatio();return n.pick(t.x*i,t.y*i,e)}highlight(t){const e=this.getRenderer();return e?(e.highlight(t),this):(this.V||(this.V=[]),this.V.push(t),this)}Te(){if(this.V){for(let t=0;t<this.V.length;t++)this.highlight(this.V[t]);delete this.V}}cancelHighlight(t,e){const r=this.getRenderer();return r?(r.cancelHighlight(t,e),this):this}cancelAllHighlight(){const t=this.getRenderer();return t?(t.cancelAllHighlight(),this):this}}function Nr(t,e){const r=t.sphere,n=s.dist(r,e),i=t.sphere[3];return n<i?0:n-i}function Sr(t,e){const r=t.box;return ze(s.set(Tr,r[0],r[1],r[2]),o.set(gr,r[3],r[4],r[5],r[6],r[7],r[8],r[9],r[10],r[11]),e)}Ir.mergeOptions({"maxGPUMemory":512,"retireInterval":2e3,"loadingLimitOnInteracting":5,"loadingLimit":0,"renderer":"gl","forceRenderOnZooming":!0,"forceRenderOnRotating":!0,"forceRenderOnMoving":!0,"debug":!1,"debugOutline":[0,1,0],"meshLimitPerFrame":1,"i3sNodepageLimitPerFrame":1,"enableI3SCompressedGeometry":!0,"forceI3SCompressedGeometry":!0,"picking":!0,"pickingPoint":!0,"geometryEvents":!1,"antialias":!1,"optionalExtensions":["ANGLE_instanced_arrays","OES_element_index_uint","OES_standard_derivatives","OES_vertex_array_object","OES_texture_half_float","OES_texture_half_float_linear","OES_texture_float","OES_texture_float_linear","WEBGL_depth_texture","EXT_shader_texture_lod","WEBGL_compressed_texture_astc","WEBGL_compressed_texture_etc","WEBGL_compressed_texture_etc1","WEBGL_compressed_texture_pvrtc","WEBGL_compressed_texture_s3tc","WEBGL_compressed_texture_s3tc_srgb"],"offset":[0,0]}),Ir.registerRenderer("gl",ke),Ir.registerJSONType("Geo3DTilesLayer");const Or=[],Mr=[],wr=[],Cr=[],xr=[],Ur=[],vr=[],Br=[],Lr=[],Pr=[];class Dr{constructor(t,e,r){this.Ve=t,this.ze=e||_,this.le=r,this.Xe={"image/crn":Se.crn&&Se.crn(),"image/ktx2":Se.ktx2&&Se.ktx2(),"image/cttf":Se.ktx2&&Se.ktx2(),"draco":Se.draco&&Se.draco()}}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.Ye(t,e,r,n,i)):d.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Ye(t,i,r,n)}))}Ye(t,e,r,n,i){const s=i&&i.maxTextureSize,o=this.Ze(e,r,n,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.ze(a,o.glb,{transferable:!0,requestImage:this.Ve,decoders:this.Xe,supportedFormats:this.le,maxTextureSize:s});return c.load({skipAttributeTransform:!1}).then((e=>{e.url=`${t}-${r}-${n}`;const i=c.transferables;for(let t=0;t<o.transferables.length;t++)i.indexOf(o.transferables[t])<0&&i.push(o.transferables[t]);return{magic:"b3dm",count:o.count,transferables:i,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,gltf:e}}))}Ze(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported b3dm version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in b3dm header is inconsistent with b3dm's byte length, url: "+n;return console.warn(t),{error:t}}let o,a=i.getUint32(12,!0),c=i.getUint32(16,!0),l=i.getUint32(20,!0),f=i.getUint32(24,!0),h=28+e;l>=570425344?(h-=8,o=a,l=c,f=0,a=0,c=0):f>=570425344&&(h-=4,o=l,l=a,f=c,a=0,c=0);const u=[t];let _,d,E;if(a>0?(_=ht(t,h,a),h+=a,o=_.BATCH_LENGTH):_={"BATCH_LENGTH":o},c>0&&(h+=c),l>0&&(d=ut(t,h,l),h+=l,f>0)){const e=_t(0,h,f);E=t.slice(e.offset,e.offset+e.byteLength),h+=f,u.push(E)}const T=_.BATCH_LENGTH,m={};if(_&&_.BATCH_ID){m.BATCH_ID=Et(_.BATCH_ID,t,undefined.offset,T);const e=m.BATCH_ID.array&&m.BATCH_ID.array.buffer;e&&u.indexOf(e)<0&&u.push(e)}return{count:o,transferables:u,featureTable:_,batchTable:d,batchTableBin:E,b3dm:m,glb:{buffer:t,byteOffset:h,byteLength:i.byteLength+i.byteOffset-h}}}We(){return null}}class Fr{constructor(t,e,r,n){this.Ve=t,this.ze=e||_,this.le=r,this.Xe={"image/crn":Se.crn&&Se.crn(),"image/ktx2":Se.ktx2&&Se.ktx2(),"image/cttf":Se.ktx2&&Se.ktx2(),"draco":Se.draco&&Se.draco()},this.Ke=n}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.Ye(t,e,r,n,i)):d.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Ye(t,i,r,n)}))}Ye(t,e,r,n,i){return this.je(t,e,r,n,i).then((({gltf:i,transferables:s})=>{const o=this.qe(e,r,n,t);if(o.error)return Promise.resolve(o);for(let t=0;t<s.length;t++)-1===o.transferables.indexOf(s[t])&&o.transferables.push(s[t]);return delete i.transferables,Promise.resolve({magic:"i3dm",count:o.count,transferables:o.transferables,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,i3dm:o.i3dm,gltf:i})}))}je(t,e,r,n,i){const s=i&&i.maxTextureSize,o={transferable:!0,requestImage:this.Ve,decoders:this.Xe,supportedFormats:this.le,maxTextureSize:s},a=new DataView(e,r,n),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 n=M(new Uint8Array(e,c+r,a.byteLength-c));-1==n.indexOf("://")&&(n=t.substring(0,t.lastIndexOf("/"))+"/"+n);return n.indexOf(".glb")>0?d.getArrayBuffer(n,{}).then((t=>this.$e(n,{buffer:t.data,byteOffset:0},o))):d.getJSON(n,{}).then((t=>this.$e(n,t,o)))}{const n={buffer:e,byteOffset:c+r,byteLength:a.byteLength-c};return this.$e(t,n,o)}}$e(t,e,r){const n=t.substring(0,t.lastIndexOf("/")),i=new this.ze(n,e,r);return i.load({skipAttributeTransform:!0}).then((r=>{let n=0,s=0;return e.buffer&&(n=e.byteOffset||0,s=e.byteLength||0),r.url=`${t}-${n}-${s}`,{transferables:i.transferables,gltf:r}}))}qe(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported pnts version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+n;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:l,batchTableBin:f}=bt(i,32+e,o),h={},u=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;h.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,r=a.QUANTIZED_VOLUME_SCALE,{byteOffset:n}=a.POSITION_QUANTIZED;h.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:u,componentType:5126,array:this.Qe(new Uint16Array(t,n+c.offset,3*u),e,r)},o.push(h.POSITION.array.buffer)}if(a.BATCH_ID){h.BATCH_ID=Et(a.BATCH_ID,t,c.offset,u);const e=h.BATCH_ID.array&&h.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;h.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,h.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;h.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:this.Je(new Uint16Array(t,e+c.offset,2*u))},o.push(h.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,h.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:this.Je(new Uint16Array(t,e+c.offset,2*u))},o.push(h.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;h.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,u).slice()},o.push(h.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;h.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:u,componentType:5126,array:new Float32Array(t,e+c.offset,3*u).slice()},o.push(h.SCALE_NON_UNIFORM.array.buffer)}return{count:u,batchTable:l,batchTableBin:f,featureTable:a,i3dm:h,transferables:o}}Je(t){const e=t.length/2,r=new Float32Array(3*e),n=[];for(let i=0;i<e;i++)Gr(n,t[2*i],t[2*i+1],65535),r[3*i]=n[0],r[3*i+1]=n[1],r[3*i+2]=n[2];return r}Qe(t,e,r){return Rt(new Float32Array(t.length),t,e,r)}We(){return null}}function Gr(t,e,r,n){if(t[0]=kr(e,n),t[1]=kr(r,n),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]))*Hr(e),t[1]=(1-Math.abs(e))*Hr(t[1])}return E.normalize(t,t)}function kr(t,e){return function(t,e,r){return t<e?e:t>r?r:t}(t,0,e=function(t,e){if(null!=t)return t;return e}(e,255))/e*2-1}function Hr(t){return t<0?-1:1}class Vr{constructor(){}load(t,e,r=0,n=0){return e?(n||(n=e.byteLength),this.Ye(t,e,r,n)):d.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Ye(t,i,r,n)}))}Ye(t,e,r,n){return this.tr(e,r,n,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}))}tr(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported pnts version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+n;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:l,batchTableBin:f}=bt(i,e+28,o),h=a.QUANTIZED_VOLUME_OFFSET,u=a.QUANTIZED_VOLUME_SCALE,_=a.POINTS_LENGTH;let d,E={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){E=a.extensions["3DTILES_draco_point_compression"],d=new DataView(t,E.byteOffset+c.offset,E.byteLength);const e={attributes:E.properties,useUniqueIDs:!1};return this.er||(this.er=Se.draco()),this.er(d,e).then((e=>{const r=e.attributes;!a.POSITION&&!a.POSITION_QUANTIZED||r.POSITION||r.POSITION_QUANTIZED||(r.POSITION=a.POSITION,r.POSITION_QUANTIZED=a.POSITION_QUANTIZED),!(a.RGB||a.RGBA||a.RGB565)||r.RGB||r.RGBA||r.RGB565||(r.RGB=a.RGB,r.RGBA=a.RGBA,r.RGB565=a.RGB565),!a.NORMAL&&!a.NORMAL_OCT16P||r.NORMAL||r.NORMAL_OCT16P||(r.NORMAL=a.NORMAL,r.NORMAL_OCT16P=a.NORMAL_OCT16P);const n=this.rr(t,e.attributes,c.offset,_,o,h,u);if(e.attributes.BATCH_ID){const t=e.attributes.BATCH_ID.array;n.BATCH_ID={byteStride:0,byteOffset:0,itemSize:1,count:t.length,componentType:gt(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?n.BATCH_ID=Et(a.BATCH_ID,t,c.offset,_):n.BATCH_ID=zr(_);const e=n.BATCH_ID.array&&n.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return{count:_,batchTable:l,batchTableBin:f,featureTable:a,pnts:n,transferables:o}}))}const T=this.rr(t,a,c.offset,_,o,h,u);if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?T.BATCH_ID=Et(a.BATCH_ID,t,c.offset,_):T.BATCH_ID=zr(_);const e=T.BATCH_ID.array&&T.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:_,batchTable:l,batchTableBin:f,featureTable:a,pnts:T,transferables:o})}rr(t,e,r,n,i,s,o){const a={};if(e.POSITION){let{byteOffset:s,array:o}=e.POSITION;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n*4);o=new Float32Array(e)}a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:o},i.push(o.buffer)}else if(e.POSITION_QUANTIZED){let{byteOffset:c,array:l}=e.POSITION_QUANTIZED;c=c||0;const f=l?0:r;a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:this.Qe(l||new Uint16Array(t,c+f,3*n),s,o)},i.push(a.POSITION.array.buffer)}if(e.RGBA){let{byteOffset:s,array:o}=e.RGBA;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+4*n);o=new Uint8Array(e)}a.RGBA={byteStride:0,byteOffset:0,itemSize:4,count:n,componentType:5121,array:o},i.push(o.buffer)}else if(e.RGB){let{byteOffset:s,array:o}=e.RGB;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n);o=new Uint8Array(e)}a.RGB={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5121,array:o},i.push(o.buffer)}else if(e.RGB565){let{byteOffset:s,array:o}=e.RGB565;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+2*n);o=new Uint16Array(e)}a.RGB565={byteStride:0,byteOffset:0,itemSize:1,count:n,componentType:5123,array:o},i.push(o.buffer)}if(e.NORMAL){let{byteOffset:s,array:o}=e.NORMAL;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n*4);o=new Float32Array(e)}a.NORMAL={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:o},i.push(o.buffer)}else if(e.NORMAL_OCT16P){let{byteOffset:s,array:o}=e.NORMAL_OCT16P;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+2*n);o=new Uint8Array(e)}a.NORMAL_OCT16P={byteStride:0,byteOffset:0,itemSize:2,count:n,componentType:5121,array:o},i.push(o.buffer)}return a}Qe(t,e,r){return Rt(new Float32Array(t.length),t,e,r)}We(){return null}}function zr(t){const e=x(t),r=new e(t);for(let e=0;e<t;e++)r[e]=e;return{byteStride:0,byteOffset:0,itemSize:1,count:t,componentType:gt(e),array:r}}class Xr{constructor(t,e){this.Ve=t,this.ze=e||_}load(t,e,r=0,n=0,i){return e?this.Ye(t,e,r,n,i):d.getArrayBuffer(t,{}).then((e=>{const i=e.data;return this.Ye(t,i,r,n)}))}Ye(t,e,r,n,i){n||(n=e.byteLength);const s=this.nr(e,t,r,n),o=[];for(let r=0;r<s.length;r++){let n;if("b3dm"===s[r].magic)n=new Dr(this.Ve,this.ze);else if("i3dm"===s[r].magic)n=new Fr(this.Ve,this.ze);else if("pnts"===s[r].magic)n=new Vr;else{if("cmpt"!==s[r].magic){console.warn("Unsupported magic in CMPT tile:",s[r].magic);continue}n=new Xr(this.Ve,this.ze)}o.push(n.load(t,e,s[r].offset,s[r].byteLength,i).then((t=>t)))}return Promise.all(o).then((t=>({magic:"cmpt",tiles:t})))}nr(t,e,r,n){const i=new DataView(t,r,n),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported cmpt version: "+s+", url:"+e;return console.warn(t),{error:t}}if(16===i.byteLength)return[];const o=[],a=i.getUint32(12,!0);let c=16;for(let e=0;e<a;e++){const e=lt(i,c),n=i.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+r,byteLength:n}),c+=n}return o}}if(e.transcoders){const r=t.Map.VERSION;if(r.indexOf("1.0.0-beta")>=0||r.indexOf("1.0.0-alpha")>=0){const r=e.transcoders.inject(A);t.registerWorkerAdapter("@maptalks/3dtiles",r)}else t.registerWorkerAdapter("@maptalks/3dtiles",(function(){return e.transcoders.inject(A)}))}else t.registerWorkerAdapter("@maptalks/3dtiles",A);export{Dr as B3DMLoader,Xr as CMPTLoader,Ir as Geo3DTilesLayer,L as Geo3DTilesUtil,at as Geo3DTransform};"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.21.0");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maptalks/3dtiles",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "description": "3d tiles layer for maptalks",
5
5
  "main": "dist/maptalks.3dtiles.js",
6
6
  "browser": "dist/maptalks.3dtiles.js",