@maptalks/3dtiles 0.18.1 → 0.18.2
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.18.
|
|
2
|
+
* @maptalks/3dtiles v0.18.2
|
|
3
3
|
* LICENSE : UNLICENSED
|
|
4
4
|
* (c) 2016-2022 maptalks.org
|
|
5
5
|
*/
|
|
@@ -20,4 +20,4 @@ let it=0;function st(t){return null==t}function ot(t){return!st(t)}function at(t
|
|
|
20
20
|
* @maptalks/gl v0.68.1
|
|
21
21
|
* LICENSE : UNLICENSED
|
|
22
22
|
* (c) 2016-2022 maptalks.com
|
|
23
|
-
*/const Ur=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=Ur(),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 = ${Ur.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.le=t,this.xt=e,this.fe=n,this.ue=r.version,t.indexOf("i3s:tileset:")<0?(this.ue<=1.6?this.he="root":this.he=0,r.version=this.ue):(this.he=t.substring("i3s:tileset:".length),this.ue>1.6&&(this.he=parseInt(this.he))),this.le=t,this._e=r}load(){const t=this._e,e=t.layerScene.baseUrl;if(this.ue<=1.6)return t[this.he]&&t[this.he].lodSelection?(this.de=t[this.he],this.Ee()):new Promise((r=>{let n=e+"/nodes/"+this.he;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.fe(this.xt,n,(()=>{this.de=t[this.he],r(this.Ee())}))}));if(this.ue>=1.7){if(t[this.he])return this.de=t[this.he],this.Ee();const r=Math.floor(this.he/t.nodesPerPage);return new Promise((n=>{let i=e+"/nodepages/"+r;t.layerScene.eslpk&&(i+=".json"),this.fe(this.xt,i,(()=>{this.de=t[this.he],n(this.Ee())}))}))}return null}getTileset(){return this.Te}getChildrenURL(){return this.me}Ee(){const t=this._e,e=t.layerScene.baseUrl,r=this.de.children,n=[],i={};if(r)for(let s=0;s<r.length;s++)if(this.ue<=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.fe(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.fe(this.xt,n,(()=>{r()}))})),n.push(i[a]))}return n.length?Promise.all(n).then((()=>this.Ae())):this.Ae()}Ae(){return Promise.resolve(this.pe())}ye(t){Pr(this._e,t)}pe(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.ge(this.de,!0)}}ge(t){const e=this.ue,r=this._e,n=t;var i,s=n.obb,o=n.mbs,a={};if(o)i=Gr([],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,u=n*a,h=i*o,_=i*a,d=i*c,E=s*o,T=s*a,m=s*c;return t[0]=1-u-d,t[3]=f-m,t[6]=h+T,t[1]=f+m,t[4]=1-l-d,t[7]=_-E,t[2]=h-T,t[5]=_+E,t[8]=1-l-u,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=Gr([],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];V(Dr,e,r,n);const o=J(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 u=16*c;const h=P([]),_=n.children;var d;if(_){d=[];const t=this._e;for(let r=0;r<_.length;r++){const n=e<=1.6?_[r].id:_[r];if(!t[n]){d=null;break}d.push(this.ge(t[n]))}}var E={refine:"REPLACE",boundingVolume:a,transform:h,geometricError:u};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.de}}function Gr(t,e,r,n){return ne(t,R(e),R(r),n)}const kr=!!Lr.ktx2,Hr=n.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 u=Hr;let h,_;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{h=a.mesh.geometry,_=a.mesh.material;const t=e.layerScene.geometryDefinitions[h.definition],{geometryBuffers:o}=t;f=n&&2===o.length;const u=Lr.draco&&f?o[1]:o[0],d=Lr.draco&&f?1:0;let E=c+`/nodes/${h.resource}/geometries/`+d;s&&(E+=".bin");const T={geometry:{url:E,info:u}};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 Zr(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:u}}function Zr(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=Kr(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 g(t[o])&&Zr(t[o],e,r,n,i,s)}function Kr(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&&kr)return t[r]}return null}const Wr=[];class jr extends t.renderer.CanvasRenderer{constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new jt(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.Re={},this.be=[],this.fe=this.Ie.bind(this)}getAnalysisMeshes(){if(!this.painter)return Wr;const t=this.painter.getPaintedMeshes();if(!t)return Wr;const e=[],{b3dmMeshes:r,pntsMeshes:n,i3dmMeshes:i}=t;return r.length&&U(e,r),n.length&&U(e,n),i.length&&U(e,i),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.be.length||super.needToRedraw())}drawOnInteracting(t,e,r){this.draw(e,r)}draw(t,e){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.Ne(),this.Se();const{selectedTiles:o,leaves:a,requests:c}=this.we(n,i);c.length&&this.loadTiles(c),this.Oe(o,a,e),this.xe(),c.length||this.completeRender()}we(t,e){let r=[];this.Me();let n=0;const i=this.Ce(),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.ve(c.id)?(n++,l=a=!0,this.tilesLoading[c.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=a=!0),o=!0,i.selected=!0,i.data=f):this.painter.has(c)||(l=a=!0,r.push(c)),!l)continue;if(this.Ue(i))o=!0;else{this.Be(i).length&&(o=!0)}}let c=[],l={};if(o&&({selectedTiles:c,leaves:l}=this.Le(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}}Le(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.Pe===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.Pe=i.length}for(let t=0;t<o.length;t++)i.push(o[t])}return{selectedTiles:e,leaves:r}}Ue(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}Be(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const r=t.De+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.Fe(i[s],t);r.selected=!0,r.data=this.tileCache.get(o),t.children.push(r),e.push(r)}else i[s].De<=r&&n.push(i[s])}}return e}Oe(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=r&&r.renderTarget,s=r&&r.sceneFilter,o=this.painter.paint(t,e,s,i);this.layer.options.debug&&this.painter.paintRegion(t,{color:this.layer.options.debugOutline},s,i),this.onDrawTileEnd(n),o&&this.layer.fire("canvasisdirty",{renderCount:o})}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(C(e)){const r=v(e);return void this.Ge(e,r,t)}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const r=t.xt,n=this.ke[r];return new Fr(e,r,n,this.fe).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.xt];if(r.ajaxInMainThread){let n=r.urlParams;n&&(n=(e.indexOf("?")>0?"&":"?")+n);let i=yt.getArrayBuffer(e+(n||""),r.fetchOptions);const s=i.xhr;i=i.then((r=>{delete this.Re[e],r?this.Ge(e,r.data,t):this.onTileError(null,t)})).catch((r=>{delete this.Re[e],this.onTileError(r,t)})),this.Re[e]=s}else this.Ge(e,null,t)}Ge(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.qt,transform:n.matrix,supportedFormats:i};if(zr(t)){const e=this.ke[n.xt];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.be.push({data:r,tile:n}):this.onTilesetLoad(r,n,t)}))}Se(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let r=0;for(;this.be.length&&(r<e||!t.isInteracting());){const{data:t,tile:e}=this.be.shift(),{magic:n}=t;"b3dm"===n?this.painter.createB3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.He(t,e,r,n)})):"pnts"===n?this.painter.createPntsMesh(t,e.id,e,((r,{mesh:n})=>{this.He(t,e,r,n)})):"i3dm"===n?this.painter.createI3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.He(t,e,r,n)})):"cmpt"===n&&this.painter.createCMPTMesh(t,e.id,e,((r,{mesh:n})=>{this.He(t,e,r,n)})),r++}}He(t,e,r,n){if(r)this.onTileError(r,e);else{const r=this.Ve(n);e.memorySize=r,this.onTileLoad(t,e)}}Ve(t){let e=0;if(Array.isArray(t))for(let r=0;r<t.length;r++)t[r]&&(e+=this.Ve(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.ze(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.Xe(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.Ye(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}Ye(e,r){const n={loadTime:t.Util.now(),current:!0,error:r,node:e};this.tileCache.add(e.id,n)}ze(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.Re[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.Re[e]}Me(){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.Ze(this.canvas,e)),this.regl=this.regl||c({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 vr(this.regl,t)}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new Zt("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let r=this.layer.options||{};r=p({},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.xe(!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}xe(t){this.Ke||(this.Ke=Date.now());const e=Date.now();if(t||!(e-this.Ke<this.layer.options.retireInterval)){this.Ke=e;for(const e in this.tilesLoading){const r=this.tilesLoading[e];!t&&r.current||this.abortTileLoading(r)}}}Ce(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}Ze(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}ve(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)}Ne(){if(!this.We)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const r=[];for(const n in this.We){const i=this.We[n];if("pending"===i.status)continue;i.status="pending";const s=i.rootIdx;if(r.push(yt.getJSON(n).then((t=>{delete this.We[n];const e=this.ke[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)}Ie(t,e,r){this.We||(this.We={}),this.We[e]=this.We[e]||[],this.We[e].rootIdx=t,this.We[e].push(r),this.setToRedraw()}Xe(t,e,r){this.ke||(this.ke=[]);const n=e.xt;this.ke[n]||(this.ke[n]={});const i=this.ke[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.fe).then((t=>{this.onTilesetLoad(t,e,r)}))}pick(t,e,r){return this.painter?this.painter.pick(t,e,r&&r.tolerance):[]}}function qr(t,e){return t.Dt-e.Dt}function $r(t,e,r){return t[0]=e[r],t[1]=e[r+3],t[2]=e[r+6],t}function Jr(t,e,r){return Math.sqrt(function(t,e,r){var n=X(Qr,r,t),i=$r(tn,e,0),s=$r(en,e,1),o=$r(rn,e,2),a=J(i),c=J(s),l=J(o);K(i,i),K(s,s),K(o,o);var f=nn;f[0]=W(n,i),f[1]=W(n,s),f[2]=W(n,o);var u,h=0;f[0]<-a?h+=(u=f[0]+a)*u:f[0]>a&&(h+=(u=f[0]-a)*u);f[1]<-c?h+=(u=f[1]+c)*u:f[1]>c&&(h+=(u=f[1]-c)*u);f[2]<-l?h+=(u=f[2]+l)*u:f[2]>l&&(h+=(u=f[2]-l)*u);return h}(t,e,r))}const Qr=[],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=i.copy([],t),this.distance=e}static fromPointNormal(t,e,r){var n=-i.dot(e,t);return i.copy(r.normal,e),r.distance=n,r}}const fn=[],un=[],hn=[],_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 r,n,s,o=0;if(!on.contains(this.rectangle,e)){var a=this.southwestCornerCartesian,c=this.northeastCornerCartesian,l=this.westNormal,f=this.southNormal,u=this.eastNormal,h=this.northNormal,_=i.subtract(gn,t,a),d=i.dot(_,l),E=i.dot(_,f),T=i.subtract(gn,t,c),m=i.dot(T,u),A=i.dot(T,h);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>(s=this.maximumHeight)){var p=r-s;o+=p*p}else if(r<n){var y=n-r;o+=y*y}return Math.sqrt(o)}computeBox(t){const e=this;cn(on.southwest(t,un),e.southwestCornerCartesian),cn(on.northeast(t,un),e.northeastCornerCartesian),fn[0]=t.west,fn[1]=.5*(t.south+t.north),fn[2]=0;var r=cn(fn,hn),n=i.cross(dn,r,an);i.normalize(e.westNormal,n),fn[0]=t.east;var s=cn(fn,mn),o=i.cross(dn,an,s);i.normalize(e.eastNormal,o);var a,c=i.subtract(dn,r,s),l=i.normalize(_n,c),f=t.south;if(f>0){fn[0]=.5*(t.west+t.east),fn[1]=f;var u=cn(fn,An);i.copy(pn,l);var h=ln.fromPointNormal(e.southwestCornerCartesian,e.westNormal,yn);bn(An,pn,h,e.southwestCornerCartesian),a=de(u,En)}else a=Ee(on.southeast(t,un),En);var _=i.cross(Tn,a,c);i.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);i.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,un),En);var A=i.cross(Tn,c,d);i.normalize(e.northNormal,A)}}function bn(t,e,r,n){var s=t,o=e,a=r.normal,c=i.dot(a,o);if(!(Math.abs(c)<1e-15)){var l=(-r.distance-i.dot(a,s))/c;if(!(l<0))return n=i.scale(n,o,l),i.add(n,s,n)}}const In=new t.Extent(0,0,0,0),Nn=new t.Extent(0,0,0,0),Sn=[],wn=[],On=[],xn=[],Mn=new t.Point(0,0),Cn=[],vn=new t.Coordinate(0,0),Un=n.identity([]);class Bn extends t.Layer{constructor(t,e){super(t,e),this.je(),this.Re={},this.qe=[]}je(){let t=this.options.services.map((t=>t.url));this.$e=t.map(((t,e)=>function(t,e){t=I(t);return{baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:n.identity([]),xt:e,De:0}}(t,e))),this.fire("rootready",{roots:this.$e.slice(0)})}getTileUrl(t){return t}getExtent(e){if(!e&&0!==e){const e=new t.Extent;for(let t=0;t<this.$e.length;t++)if(this.$e[t].boundingVolume){const r=this.boundingVolumeToExtent(this.$e[t]);e._combine(r)}return e}return this.$e[e]&&this.$e[e].boundingVolume?this.boundingVolumeToExtent(this.$e[e]):null}boundingVolumeToExtent(e){const r=e.boundingVolume.Je?Un:e.matrix,n=this.getMap();if(e.boundingVolume.region){const r=e.boundingVolume.region;return new t.Extent(b(r[0]),b(r[1]),b(r[2]),b(r[3]))}if(e.boundingVolume.sphere){const s=e.boundingVolume.sphere,o=le([],i.transformMat4([],s,r)),a=s[3],c=n.locate(o,-a,a),l=n.locate(o,a,-a);return new t.Extent(c,l)}if(e.boundingVolume.box){const o=e.boundingVolume.box,a=i.transformMat4([],o,r),c=new t.Coordinate(le([],a)),l=o.slice(3);s.multiply(l,s.fromMat4([],e.matrix),l);const f=i.length(l.slice(0,3)),u=i.length(l.slice(3,6)),h=i.length(l.slice(6,9)),_=Math.max(f,u,h),d=n.locate(c,-_,_),E=n.locate(c,_,-_);return new t.Extent(d,E)}return null}getRootTiles(){return this.$e}getTiles(){const t=this.getRenderer();if(!t.ready)return this.Qe(),{tiles:xn};const e=this.getMap(),r=e.cameraPosition;let n,s;if(e.getGLZoom)s=e.pointToDistance(r[2],0,e.getGLZoom()),vn.set(r[0],r[1]),n=e.pointToCoord(vn,e.getGLZoom());else{const t=e.getGLRes();s=e.pointAtResToDistance(r[2],0,t),vn.set(r[0],r[1]),n=e.pointAtResToCoord(vn,t)}this.tr=this.tr||[],i.set(this.tr,R(n.x),R(n.y),s),this.er=ne(this.er||[],this.tr[0],this.tr[1],this.tr[2]),this.rr=2*Math.tan(.5*R(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const l=[];for(let e=0;e<this.$e.length;e++){let r=1/0;const n=[this.$e[e]],i=this.nr(e);for(;n.length>0;){const e=n.pop();for(e.id||this.ir(e);c.level>=e.De;)c=c.parent;const s=this.sr(e,i,o);if(s<1){let t=c;for(;t&&!t.content;)t=t.parent;0===s&&t&&t.content&&this.ar(l,t);if(!1===this.options.services[e.xt].alwaysShow)continue;if(!(0===s&&e.De<=r))continue;e.content&&(r=e.De)}e.Dt<1/0&&this.cr(e);const a=this.Fe(e,c);c.children.push(a);const f=e.children,u=f&&f.length,h=a.content;if(!u&&h&&this.ar(l,a),u){h&&"add"===e.refine&&this.ar(l,a),c=a;const r=f[0].parent;let i=!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;i=!0}else{i=!0,f[s].parent=e,f[s].qt=e.qt,f[s].baseUrl=e.baseUrl;const t=f[s].content&&(f[s].content.url||f[s].content.uri);t&&(C(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))}n.push(f[s])}!i&&h&&this.ar(l,a)}}}return{root:a,tiles:l}}ar(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.tr,this.er,r)||t.push(e)}Fe(t,e){return{id:t.id,node:t,children:[],level:t.De,parent:e,content:t.content&&t.content.url}}ir(e){e.id=t.Util.GUID(),e.matrix=e.transform||n.identity([]),e.lr=this.ur(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.De&&(e.De=e.parent.De+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.hr(e)}hr(t){const e=t.boundingVolume;if(!e||e.Je)return;const r=this.options.services[t.xt].heightOffset||0,s=this.options.offset,o=y(s)||s[0]||s[1];if(!t.boundingVolume||!r&&n.exactEquals(t.matrix,Un)&&!o)return;const{region:a,box:c,sphere:l}=e;if(a){const t=this._r([b(a[0]),b(a[1])]);a[0]=R(t.x),a[1]=R(t.y);const e=this._r([b(a[2]),b(a[3])]);a[2]=R(e.x),a[3]=R(e.y),a[4]+=r,a[5]+=r}else if(c||l){const e=c||l,n=i.transformMat4(Sn,e,t.matrix),s=le(wn,n),o=this._r([s[0],s[1]]);s[0]=o.x,s[1]=o.y,s[2]+=r,ne(e,R(s[0]),R(s[1]),s[2])}e.Je=!0}ur(t){return void 0===t.geometricError||!t.boundingVolume}cr(t){let e=t.parent;for(;e&&e.lr&&!(e.Dt<=t.Dt);)e.Dt=t.Dt,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.qt||i.upAxis||"Y").toUpperCase();t.root.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const o=r.indexOf("realspace/")>-1;0===e.De&&(t.asset&&t.asset.s3mType&&o||i.isSuperMapiServer)&&(t.root.baseUrl+="data/path/");const a=t.asset.i3s;if(t.root.qt=s,e){const r=e.boundingVolume;p(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.hr(e),e.dr=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.lr=this.ur(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||C(s)||-1!==s.indexOf("http://")||-1!==s.indexOf("https://")||(e.content.url=e.baseUrl+s)}this.Qe(),this.fire("loadtileset",{tileset:t,index:e.xt,url:r})}sr(t,e,r){if(t.Dt=1/0,0===t.De||t.lr)return 1;if(!this.Er(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.Tr(t);return 0===i&&t.parent&&(i=.5*(t.parent.mr||0)),i>=n?1:0}Xt(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)}Er(e,r,i){const o=e.id;let a=this.qe[o];const{boundingVolume:c}=e,l=c.sphere,u=c.region,h=c.box;if(!a){let r,i,c;if(u){r=In.set(b(u[0]),b(u[1]),b(u[2]),b(u[3]));const t=r.getCenter(),e=this.Ar(t);r=r.convertTo((t=>this.Xt(t,Mn)),Nn),c=u[4],i=u[5],a=this.qe[o]=[[r.xmin,r.ymin,c*e[2]],[r.xmax,r.ymax,i*e[2]]],a.center=t}else if(l){const e=le(Sn,l),r=new t.Coordinate(e),n=this.Xt(r,Mn).toArray(),i=this.Ar(r);n.push(e[2]*i[2]),a=this.qe[o]=[n,l[3]*i[2]],a.center=r}else if(h){const r=le(Sn,h),i=new t.Coordinate(r),c=this.Xt(i,Mn).toArray(),l=this.Ar(i);c.push(r[2]*l[2]);const f=h.slice(3);n.exactEquals(e.matrix,Un)||s.multiply(f,s.fromMat4(Cn,e.matrix),f);for(let t=0;t<f.length;t++)f[t]*=l[t%3],h[3+t]=f[t];a=this.qe[o]=[...c,...f],a.center=i}}if(r){if(u)In.xmin=a[0][0],In.ymin=a[0][1],In.xmax=a[1][0],In.ymax=a[1][1];else if(l){const t=a[2];In.xmin=a[0][0]-t,In.ymin=a[0][1]-t,In.xmax=a[0][0]+t,In.ymax=a[0][1]+t}else if(h){const t=a[1],e=a[2];In.xmin=a[0][0]-t,In.ymin=a[0][1]-e,In.xmax=a[0][0]+t,In.ymax=a[0][1]+e}if(!r.intersects(In))return!1}return u?_(i,a):l?function(t,e,r){E(t);for(var n=e[0],i=-e[1],s=0;s<6;s++)if((!r||"0"!==r.charAt(s))&&m(f[s],n)<i)return!1;return!0}(i,a):!!h&&function(t,e,r){E(t);for(var n=0;n<6;n++)if(!(r&&"0"===r.charAt(n)||d(f[n],e)))return!1;return!0}(i,a)}Ar(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,i.set(On,r.x/100*1.01,r.y/100*1.01,n),On}_r(e){Array.isArray(e)&&(e=new t.Coordinate(e));let r=this.options.offset;if(y(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}nr(e){const r=this.options.services[e].maxExtent;if(!r)return null;const n=this.$e[e];return n.maxExtent||(n.maxExtent=new t.Extent(r).convertTo((t=>this.Xt(t)))),n.maxExtent}Tr(t){const e=this.rr,r=t.geometricError;if(0===r)return 0;const n=this.getMap();let i;t.boundingVolume.region?i=function(t,e,r){t.pr||(t.pr=new Rn(t.boundingVolume.region));return t.pr.distanceToCamera(e,r)}(t,this.er,this.tr):t.boundingVolume.sphere?i=Ln(t.boundingVolume,this.er):t.boundingVolume.box&&(i=Pn(t.boundingVolume,this.er));const s=Math.max(Math.abs(i),1e-7),o=r*n.height/(s*e);return t.Dt=i,t.mr=o,o}Qe(){const t=this.getRenderer();t&&t.setToRedraw()}ee(t){return this.qe[t]}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)}}function Ln(t,e){const r=t.sphere,n=i.dist(r,e),s=t.sphere[3];return n<s?0:n-s}function Pn(t,e){const r=t.box;return Jr(i.set(Sn,r[0],r[1],r[2]),s.set(Cn,r[3],r[4],r[5],r[6],r[7],r[8],r[9],r[10],r[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");class Dn{constructor(t,e,r){this.i=t,this.yr=e||Ft,this.o=r,this.gr={"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.Rr(t,e,r,n,i)):yt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Rr(t,i,r,n)}))}Rr(t,e,r,n,i){const s=i&&i.maxTextureSize,o=this.br(e,r,n,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.yr(a,o.glb,{transferable:!0,requestImage:this.i,decoders:this.gr,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}}))}br(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),u=28+e;l>=570425344?(u-=8,o=a,l=c,f=0,a=0,c=0):f>=570425344&&(u-=4,o=l,l=a,f=c,a=0,c=0);const h=[t];let _,d,E;if(a>0?(_=ye(t,u,a),u+=a,o=_.BATCH_LENGTH):_={"BATCH_LENGTH":o},c>0&&(u+=c),l>0&&(d=ge(t,u,l),u+=l,f>0)){const e=Re(0,u,f);E=t.slice(e.offset,e.offset+e.byteLength),u+=f,h.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&&h.indexOf(e)<0&&h.push(e)}return{count:o,transferables:h,featureTable:_,batchTable:d,batchTableBin:E,b3dm:m,glb:{buffer:t,byteOffset:u,byteLength:i.byteLength+i.byteOffset-u}}}Ir(){return null}}class Fn{constructor(t,e,r,n){this.i=t,this.yr=e||Ft,this.o=r,this.gr={"image/crn":Lr.crn&&Lr.crn(),"image/ktx2":Lr.ktx2&&Lr.ktx2(),"image/cttf":Lr.ktx2&&Lr.ktx2(),"draco":Lr.draco&&Lr.draco()},this.Nr=n}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.Rr(t,e,r,n,i)):yt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Rr(t,i,r,n)}))}Rr(t,e,r,n,i){return this.Sr(t,e,r,n,i).then((({gltf:i,transferables:s})=>{const o=this.wr(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})}))}Sr(t,e,r,n,i){const s=i&&i.maxTextureSize,o={transferable:!0,requestImage:this.i,decoders:this.gr,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=w(new Uint8Array(e,c+r,a.byteLength-c));-1==n.indexOf("://")&&(n=t.substring(0,t.lastIndexOf("/"))+"/"+n);return n.indexOf(".glb")>0?yt.getArrayBuffer(n,{}).then((t=>this.Or(n,{buffer:t.data,byteOffset:0},o))):yt.getJSON(n,{}).then((t=>this.Or(n,t,o)))}{const n={buffer:e,byteOffset:c+r,byteLength:a.byteLength-c};return this.Or(t,n,o)}}Or(t,e,r){const n=t.substring(0,t.lastIndexOf("/")),i=new this.yr(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}}))}wr(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}=ve(i,32+e,o),u={},h=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;u.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,r=a.QUANTIZED_VOLUME_SCALE,{byteOffset:n}=a.POSITION_QUANTIZED;u.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.Mr(new Uint16Array(t,n+c.offset,3*h),e,r)},o.push(u.POSITION.array.buffer)}if(a.BATCH_ID){u.BATCH_ID=Ie(a.BATCH_ID,t,c.offset,h);const e=u.BATCH_ID.array&&u.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;u.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,u.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;u.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.Cr(new Uint16Array(t,e+c.offset,2*h))},o.push(u.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,u.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.Cr(new Uint16Array(t,e+c.offset,2*h))},o.push(u.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;u.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,h).slice()},o.push(u.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;u.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.SCALE_NON_UNIFORM.array.buffer)}return{count:h,batchTable:l,batchTableBin:f,featureTable:a,i3dm:u,transferables:o}}Cr(t){const e=t.length/2,r=new Float32Array(3*e),n=[];for(let i=0;i<e;i++)Gn(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}Mr(t,e,r){return Ce(new Float32Array(t.length),t,e,r)}Ir(){return null}}function Gn(t,e,r,n){if(t[0]=kn(e,n),t[1]=kn(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]))*Hn(e),t[1]=(1-Math.abs(e))*Hn(t[1])}return K(t,t)}function kn(t,e){return e=function(t,e){if(null!=t)return t;return e}(e,255),function(t,e,r){return t<e?e:t>r?r:t}(t,0,e)/e*2-1}function Hn(t){return t<0?-1:1}class Vn{constructor(){}load(t,e,r=0,n=0){return e?(n||(n=e.byteLength),this.Rr(t,e,r,n)):yt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Rr(t,i,r,n)}))}Rr(t,e,r,n){return this.vr(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}))}vr(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}=ve(i,e+28,o),u=a.QUANTIZED_VOLUME_OFFSET,h=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.Ur||(this.Ur=Lr.draco()),this.Ur(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.Br(t,e.attributes,c.offset,_,o,u,h);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:Me(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=zn(_);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.Br(t,a,c.offset,_,o,u,h);if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?T.BATCH_ID=Ie(a.BATCH_ID,t,c.offset,_):T.BATCH_ID=zn(_);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})}Br(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.Mr(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}Mr(t,e,r){return Ce(new Float32Array(t.length),t,e,r)}Ir(){return null}}function zn(t){const e=M(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:Me(e),array:r}}class Xn{constructor(t,e){this.i=t,this.yr=e||Ft}load(t,e,r=0,n=0,i){return e?this.Rr(t,e,r,n,i):yt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return this.Rr(t,i,r,n)}))}Rr(t,e,r,n,i){n||(n=e.byteLength);const s=this.Lr(e,t,r,n),o=[];for(let r=0;r<s.length;r++){let n;if("b3dm"===s[r].magic)n=new Dn(this.i,this.yr);else if("i3dm"===s[r].magic)n=new Fn(this.i,this.yr);else if("pnts"===s[r].magic)n=new Vn;else{if("cmpt"!==s[r].magic){console.warn("Unsupported magic in CMPT tile:",s[r].magic);continue}n=new Xn(this.i,this.yr)}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})))}Lr(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(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(l);t.registerWorkerAdapter("@maptalks/3dtiles",r)}else t.registerWorkerAdapter("@maptalks/3dtiles",(function(){return e.transcoders.inject(l)}))}else t.registerWorkerAdapter("@maptalks/3dtiles",l);export{Dn as B3DMLoader,Xn as CMPTLoader,Bn as Geo3DTilesLayer,B as Geo3DTilesUtil,Te as Geo3DTransform};"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.18.1");
|
|
23
|
+
*/const Ur=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=Ur(),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 = ${Ur.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.le=t,this.xt=e,this.fe=n,this.ue=r.version,t.indexOf("i3s:tileset:")<0?(this.ue<=1.6?this.he="root":this.he=0,r.version=this.ue):(this.he=t.substring("i3s:tileset:".length),this.ue>1.6&&(this.he=parseInt(this.he))),this.le=t,this._e=r}load(){const t=this._e,e=t.layerScene.baseUrl;if(this.ue<=1.6)return t[this.he]&&t[this.he].lodSelection?(this.de=t[this.he],this.Ee()):new Promise((r=>{let n=e+"/nodes/"+this.he;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.fe(this.xt,n,(()=>{this.de=t[this.he],r(this.Ee())}))}));if(this.ue>=1.7){if(t[this.he])return this.de=t[this.he],this.Ee();const r=Math.floor(this.he/t.nodesPerPage);return new Promise((n=>{let i=e+"/nodepages/"+r;t.layerScene.eslpk&&(i+=".json"),this.fe(this.xt,i,(()=>{this.de=t[this.he],n(this.Ee())}))}))}return null}getTileset(){return this.Te}getChildrenURL(){return this.me}Ee(){const t=this._e,e=t.layerScene.baseUrl,r=this.de.children,n=[],i={};if(r)for(let s=0;s<r.length;s++)if(this.ue<=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.fe(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.fe(this.xt,n,(()=>{r()}))})),n.push(i[a]))}return n.length?Promise.all(n).then((()=>this.Ae())):this.Ae()}Ae(){return Promise.resolve(this.pe())}ye(t){Pr(this._e,t)}pe(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.ge(this.de,!0)}}ge(t){const e=this.ue,r=this._e,n=t;var i,s=n.obb,o=n.mbs,a={};if(o)i=Gr([],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,u=n*a,h=i*o,_=i*a,d=i*c,E=s*o,T=s*a,m=s*c;return t[0]=1-u-d,t[3]=f-m,t[6]=h+T,t[1]=f+m,t[4]=1-l-d,t[7]=_-E,t[2]=h-T,t[5]=_+E,t[8]=1-l-u,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=Gr([],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];V(Dr,e,r,n);const o=J(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 u=16*c;const h=P([]),_=n.children;var d;if(_){d=[];const t=this._e;for(let r=0;r<_.length;r++){const n=e<=1.6?_[r].id:_[r];if(!t[n]){d=null;break}d.push(this.ge(t[n]))}}var E={refine:"REPLACE",boundingVolume:a,transform:h,geometricError:u};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.de}}function Gr(t,e,r,n){return ne(t,R(e),R(r),n)}const kr=!!Lr.ktx2,Hr=n.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 u=Hr;let h,_;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{h=a.mesh.geometry,_=a.mesh.material;const t=e.layerScene.geometryDefinitions[h.definition],{geometryBuffers:o}=t;f=n&&2===o.length;const u=Lr.draco&&f?o[1]:o[0],d=Lr.draco&&f?1:0;let E=c+`/nodes/${h.resource}/geometries/`+d;s&&(E+=".bin");const T={geometry:{url:E,info:u}};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 Zr(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:u}}function Zr(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=Kr(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 g(t[o])&&Zr(t[o],e,r,n,i,s)}function Kr(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&&kr)return t[r]}return null}const Wr=[];class jr extends t.renderer.CanvasRenderer{constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new jt(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.Re={},this.be=[],this.fe=this.Ie.bind(this)}getAnalysisMeshes(){if(!this.painter)return Wr;const t=this.painter.getPaintedMeshes();if(!t)return Wr;const e=[],{b3dmMeshes:r,pntsMeshes:n,i3dmMeshes:i}=t;return r.length&&U(e,r),n.length&&U(e,n),i.length&&U(e,i),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.be.length||super.needToRedraw())}drawOnInteracting(t,e,r){this.draw(e,r)}draw(t,e){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.Ne(),this.Se();const{selectedTiles:o,leaves:a,requests:c}=this.we(n,i);c.length&&this.loadTiles(c),this.Oe(o,a,e),this.xe(),c.length||this.completeRender()}we(t,e){let r=[];this.Me();let n=0;const i=this.Ce(),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.ve(c.id)?(n++,l=a=!0,this.tilesLoading[c.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=a=!0),o=!0,i.selected=!0,i.data=f):this.painter.has(c)||(l=a=!0,r.push(c)),!l)continue;if(this.Ue(i))o=!0;else{this.Be(i).length&&(o=!0)}}let c=[],l={};if(o&&({selectedTiles:c,leaves:l}=this.Le(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}}Le(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.Pe===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.Pe=i.length}for(let t=0;t<o.length;t++)i.push(o[t])}return{selectedTiles:e,leaves:r}}Ue(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}Be(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const r=t.De+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.Fe(i[s],t);r.selected=!0,r.data=this.tileCache.get(o),t.children.push(r),e.push(r)}else i[s].De<=r&&n.push(i[s])}}return e}Oe(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=r&&r.renderTarget,s=r&&r.sceneFilter,o=this.painter.paint(t,e,s,i);this.layer.options.debug&&this.painter.paintRegion(t,{color:this.layer.options.debugOutline},s,i),this.onDrawTileEnd(n),o&&this.layer.fire("canvasisdirty",{renderCount:o})}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(C(e)){const r=v(e);return void this.Ge(e,r,t)}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const r=t.xt,n=this.ke[r];return new Fr(e,r,n,this.fe).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.xt];if(r.ajaxInMainThread){let n=r.urlParams;n&&(n=(e.indexOf("?")>0?"&":"?")+n);let i=yt.getArrayBuffer(e+(n||""),r.fetchOptions);const s=i.xhr;i=i.then((r=>{delete this.Re[e],r?this.Ge(e,r.data,t):this.onTileError(null,t)})).catch((r=>{delete this.Re[e],this.onTileError(r,t)})),this.Re[e]=s}else this.Ge(e,null,t)}Ge(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.qt,transform:n.matrix,supportedFormats:i};if(zr(t)){const e=this.ke[n.xt];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.be.push({data:r,tile:n}):this.onTilesetLoad(r,n,t)}))}Se(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let r=0;for(;this.be.length&&(r<e||!t.isInteracting());){const{data:t,tile:e}=this.be.shift(),{magic:n}=t;"b3dm"===n?this.painter.createB3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.He(t,e,r,n)})):"pnts"===n?this.painter.createPntsMesh(t,e.id,e,((r,{mesh:n})=>{this.He(t,e,r,n)})):"i3dm"===n?this.painter.createI3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.He(t,e,r,n)})):"cmpt"===n&&this.painter.createCMPTMesh(t,e.id,e,((r,{mesh:n})=>{this.He(t,e,r,n)})),r++}}He(t,e,r,n){if(r)this.onTileError(r,e);else{const r=this.Ve(n);e.memorySize=r,this.onTileLoad(t,e)}}Ve(t){let e=0;if(Array.isArray(t))for(let r=0;r<t.length;r++)t[r]&&(e+=this.Ve(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.ze(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.Xe(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.Ye(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}Ye(e,r){const n={loadTime:t.Util.now(),current:!0,error:r,node:e};this.tileCache.add(e.id,n)}ze(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.Re[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.Re[e]}Me(){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.Ze(this.canvas,e)),this.regl=this.regl||c({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 vr(this.regl,t)}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new Zt("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let r=this.layer.options||{};r=p({},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.xe(!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}xe(t){this.Ke||(this.Ke=Date.now());const e=Date.now();if(t||!(e-this.Ke<this.layer.options.retireInterval)){this.Ke=e;for(const e in this.tilesLoading){const r=this.tilesLoading[e];!t&&r.current||this.abortTileLoading(r)}}}Ce(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}Ze(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}ve(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)}Ne(){if(!this.We)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const r=[];for(const n in this.We){const i=this.We[n];if("pending"===i.status)continue;i.status="pending";const s=i.rootIdx;if(r.push(yt.getJSON(n).then((t=>{delete this.We[n];const e=this.ke[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)}Ie(t,e,r){this.We||(this.We={}),this.We[e]=this.We[e]||[],this.We[e].rootIdx=t,this.We[e].push(r),this.setToRedraw()}Xe(t,e,r){this.ke||(this.ke=[]);const n=e.xt;this.ke[n]||(this.ke[n]={});const i=this.ke[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.fe).then((t=>{this.onTilesetLoad(t,e,r)}))}pick(t,e,r){return this.painter?this.painter.pick(t,e,r&&r.tolerance):[]}}function qr(t,e){return t.Dt-e.Dt}function $r(t,e,r){return t[0]=e[r],t[1]=e[r+3],t[2]=e[r+6],t}function Jr(t,e,r){return Math.sqrt(function(t,e,r){var n=X(Qr,r,t),i=$r(tn,e,0),s=$r(en,e,1),o=$r(rn,e,2),a=J(i),c=J(s),l=J(o);K(i,i),K(s,s),K(o,o);var f=nn;f[0]=W(n,i),f[1]=W(n,s),f[2]=W(n,o);var u,h=0;f[0]<-a?h+=(u=f[0]+a)*u:f[0]>a&&(h+=(u=f[0]-a)*u);f[1]<-c?h+=(u=f[1]+c)*u:f[1]>c&&(h+=(u=f[1]-c)*u);f[2]<-l?h+=(u=f[2]+l)*u:f[2]>l&&(h+=(u=f[2]-l)*u);return h}(t,e,r))}const Qr=[],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=i.copy([],t),this.distance=e}static fromPointNormal(t,e,r){var n=-i.dot(e,t);return i.copy(r.normal,e),r.distance=n,r}}const fn=[],un=[],hn=[],_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 r,n,s,o=0;if(!on.contains(this.rectangle,e)){var a=this.southwestCornerCartesian,c=this.northeastCornerCartesian,l=this.westNormal,f=this.southNormal,u=this.eastNormal,h=this.northNormal,_=i.subtract(gn,t,a),d=i.dot(_,l),E=i.dot(_,f),T=i.subtract(gn,t,c),m=i.dot(T,u),A=i.dot(T,h);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>(s=this.maximumHeight)){var p=r-s;o+=p*p}else if(r<n){var y=n-r;o+=y*y}return Math.sqrt(o)}computeBox(t){const e=this;cn(on.southwest(t,un),e.southwestCornerCartesian),cn(on.northeast(t,un),e.northeastCornerCartesian),fn[0]=t.west,fn[1]=.5*(t.south+t.north),fn[2]=0;var r=cn(fn,hn),n=i.cross(dn,r,an);i.normalize(e.westNormal,n),fn[0]=t.east;var s=cn(fn,mn),o=i.cross(dn,an,s);i.normalize(e.eastNormal,o);var a,c=i.subtract(dn,r,s),l=i.normalize(_n,c),f=t.south;if(f>0){fn[0]=.5*(t.west+t.east),fn[1]=f;var u=cn(fn,An);i.copy(pn,l);var h=ln.fromPointNormal(e.southwestCornerCartesian,e.westNormal,yn);bn(An,pn,h,e.southwestCornerCartesian),a=de(u,En)}else a=Ee(on.southeast(t,un),En);var _=i.cross(Tn,a,c);i.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);i.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,un),En);var A=i.cross(Tn,c,d);i.normalize(e.northNormal,A)}}function bn(t,e,r,n){var s=t,o=e,a=r.normal,c=i.dot(a,o);if(!(Math.abs(c)<1e-15)){var l=(-r.distance-i.dot(a,s))/c;if(!(l<0))return n=i.scale(n,o,l),i.add(n,s,n)}}const In=new t.Extent(0,0,0,0),Nn=new t.Extent(0,0,0,0),Sn=[],wn=[],On=[],xn=[],Mn=new t.Point(0,0),Cn=[],vn=new t.Coordinate(0,0),Un=n.identity([]);class Bn extends t.Layer{constructor(t,e){super(t,e),this.je(),this.Re={},this.qe=[]}je(){let t=this.options.services.map((t=>t.url));this.$e=t.map(((t,e)=>function(t,e){t=I(t);return{baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:n.identity([]),xt:e,De:0}}(t,e))),this.fire("rootready",{roots:this.$e.slice(0)})}getTileUrl(t){return t}getExtent(e){if(!e&&0!==e){const e=new t.Extent;for(let t=0;t<this.$e.length;t++)if(this.$e[t].boundingVolume){const r=this.boundingVolumeToExtent(this.$e[t]);e._combine(r)}return e}return this.$e[e]&&this.$e[e].boundingVolume?this.boundingVolumeToExtent(this.$e[e]):null}boundingVolumeToExtent(e){const r=e.boundingVolume.Je?Un:e.matrix,n=this.getMap();if(e.boundingVolume.region){const r=e.boundingVolume.region;return new t.Extent(b(r[0]),b(r[1]),b(r[2]),b(r[3]))}if(e.boundingVolume.sphere){const s=e.boundingVolume.sphere,o=le([],i.transformMat4([],s,r)),a=s[3],c=n.locate(o,-a,a),l=n.locate(o,a,-a);return new t.Extent(c,l)}if(e.boundingVolume.box){const o=e.boundingVolume.box,a=i.transformMat4([],o,r),c=new t.Coordinate(le([],a)),l=o.slice(3);s.multiply(l,s.fromMat4([],e.matrix),l);const f=i.length(l.slice(0,3)),u=i.length(l.slice(3,6)),h=i.length(l.slice(6,9)),_=Math.max(f,u,h),d=n.locate(c,-_,_),E=n.locate(c,_,-_);return new t.Extent(d,E)}return null}getRootTiles(){return this.$e}getTiles(){const t=this.getRenderer();if(!t.ready)return this.Qe(),{tiles:xn};const e=this.getMap(),r=e.cameraPosition;let n,s;if(e.getGLZoom)s=e.pointToDistance(r[2],0,e.getGLZoom()),vn.set(r[0],r[1]),n=e.pointToCoord(vn,e.getGLZoom());else{const t=e.getGLRes();s=e.pointAtResToDistance(r[2],0,t),vn.set(r[0],r[1]),n=e.pointAtResToCoord(vn,t)}this.tr=this.tr||[],i.set(this.tr,R(n.x),R(n.y),s),this.er=ne(this.er||[],this.tr[0],this.tr[1],this.tr[2]),this.rr=2*Math.tan(.5*R(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const l=[];for(let e=0;e<this.$e.length;e++){let r=1/0;const n=[this.$e[e]],i=this.nr(e);for(;n.length>0;){const e=n.pop();for(e.id||this.ir(e);c.level>=e.De;)c=c.parent;const s=this.sr(e,i,o);if(s<1){let t=c;for(;t&&!t.content;)t=t.parent;0===s&&t&&t.content&&this.ar(l,t);if(!1===this.options.services[e.xt].alwaysShow)continue;if(!(0===s&&e.De<=r))continue;e.content&&(r=e.De)}e.Dt<1/0&&this.cr(e);const a=this.Fe(e,c);c.children.push(a);const f=e.children,u=f&&f.length,h=a.content;if(!u&&h&&this.ar(l,a),u){h&&"add"===e.refine&&this.ar(l,a),c=a;const r=f[0].parent;let i=!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;i=!0}else{i=!0,f[s].parent=e,f[s].qt=e.qt,f[s].baseUrl=e.baseUrl;const t=f[s].content&&(f[s].content.url||f[s].content.uri);t&&(C(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))}n.push(f[s])}!i&&h&&this.ar(l,a)}}}return{root:a,tiles:l}}ar(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.tr,this.er,r)||t.push(e)}Fe(t,e){return{id:t.id,node:t,children:[],level:t.De,parent:e,content:t.content&&t.content.url}}ir(e){e.id=t.Util.GUID(),e.matrix=e.transform||n.identity([]),e.lr=this.ur(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.De&&(e.De=e.parent.De+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.hr(e)}hr(t){const e=t.boundingVolume;if(!e||e.Je)return;const r=this.options.services[t.xt].heightOffset||0,s=this.options.offset,o=y(s)||s[0]||s[1];if(!t.boundingVolume||!r&&n.exactEquals(t.matrix,Un)&&!o)return;const{region:a,box:c,sphere:l}=e;if(a){const t=this._r([b(a[0]),b(a[1])]);a[0]=R(t.x),a[1]=R(t.y);const e=this._r([b(a[2]),b(a[3])]);a[2]=R(e.x),a[3]=R(e.y),a[4]+=r,a[5]+=r}else if(c||l){const e=c||l,n=i.transformMat4(Sn,e,t.matrix),s=le(wn,n),o=this._r([s[0],s[1]]);s[0]=o.x,s[1]=o.y,s[2]+=r,ne(e,R(s[0]),R(s[1]),s[2])}e.Je=!0}ur(t){return void 0===t.geometricError||!t.boundingVolume}cr(t){let e=t.parent;for(;e&&e.lr&&!(e.Dt<=t.Dt);)e.Dt=t.Dt,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.qt||i.upAxis||"Y").toUpperCase();t.root.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const o=r.indexOf("realspace/")>-1;0===e.De&&(t.asset&&t.asset.s3mType&&o||i.isSuperMapiServer)&&(t.root.baseUrl+="data/path/");const a=t.asset.i3s;if(t.root.qt=s,e){const r=e.boundingVolume;p(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.hr(e),e.dr=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.lr=this.ur(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||C(s)||-1!==s.indexOf("http://")||-1!==s.indexOf("https://")||(e.content.url=e.baseUrl+s)}this.Qe(),this.fire("loadtileset",{tileset:t,index:e.xt,url:r})}sr(t,e,r){if(t.Dt=1/0,0===t.De||t.lr)return 1;if(!this.Er(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.Tr(t);return 0===i&&t.parent&&(i=.5*(t.parent.mr||0)),i>=n?1:0}Xt(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)}Er(e,r,i){const o=e.id;let a=this.qe[o];const{boundingVolume:c}=e,l=c.sphere,u=c.region,h=c.box;if(!a){let r,i,c;if(u){r=In.set(b(u[0]),b(u[1]),b(u[2]),b(u[3]));const t=r.getCenter(),e=this.Ar(t);r=r.convertTo((t=>this.Xt(t,Mn)),Nn),c=u[4],i=u[5],a=this.qe[o]=[[r.xmin,r.ymin,c*e[2]],[r.xmax,r.ymax,i*e[2]]],a.center=t}else if(l){const e=le(Sn,l),r=new t.Coordinate(e),n=this.Xt(r,Mn).toArray(),i=this.Ar(r);n.push(e[2]*i[2]),a=this.qe[o]=[n,l[3]*i[2]],a.center=r}else if(h){const r=le(Sn,h),i=new t.Coordinate(r),c=this.Xt(i,Mn).toArray(),l=this.Ar(i);c.push(r[2]*l[2]);const f=h.slice(3);n.exactEquals(e.matrix,Un)||s.multiply(f,s.fromMat4(Cn,e.matrix),f);for(let t=0;t<f.length;t++)f[t]*=l[t%3],h[3+t]=f[t];a=this.qe[o]=[...c,...f],a.center=i}}if(r){if(u)In.xmin=a[0][0],In.ymin=a[0][1],In.xmax=a[1][0],In.ymax=a[1][1];else if(l){const t=a[2];In.xmin=a[0][0]-t,In.ymin=a[0][1]-t,In.xmax=a[0][0]+t,In.ymax=a[0][1]+t}else if(h){const t=a[1],e=a[2];In.xmin=a[0][0]-t,In.ymin=a[0][1]-e,In.xmax=a[0][0]+t,In.ymax=a[0][1]+e}if(!r.intersects(In))return!1}return u?_(i,a):l?function(t,e,r){E(t);for(var n=e[0],i=-e[1],s=0;s<6;s++)if((!r||"0"!==r.charAt(s))&&m(f[s],n)<i)return!1;return!0}(i,a):!!h&&function(t,e,r){E(t);for(var n=0;n<6;n++)if(!(r&&"0"===r.charAt(n)||d(f[n],e)))return!1;return!0}(i,a)}Ar(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,i.set(On,r.x/100*1.01,r.y/100*1.01,n),On}_r(e){Array.isArray(e)&&(e=new t.Coordinate(e));let r=this.options.offset;if(y(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}nr(e){const r=this.options.services[e].maxExtent;if(!r)return null;const n=this.$e[e];return n.maxExtent||(n.maxExtent=new t.Extent(r).convertTo((t=>this.Xt(t)))),n.maxExtent}Tr(t){const e=this.rr,r=t.geometricError;if(0===r)return 0;const n=this.getMap();let i;t.boundingVolume.region?i=function(t,e,r){t.pr||(t.pr=new Rn(t.boundingVolume.region));return t.pr.distanceToCamera(e,r)}(t,this.er,this.tr):t.boundingVolume.sphere?i=Ln(t.boundingVolume,this.er):t.boundingVolume.box&&(i=Pn(t.boundingVolume,this.er));const s=Math.max(Math.abs(i),1e-7),o=r*n.height/(s*e);return t.Dt=i,t.mr=o,o}Qe(){const t=this.getRenderer();t&&t.setToRedraw()}ee(t){return this.qe[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)}}function Ln(t,e){const r=t.sphere,n=i.dist(r,e),s=t.sphere[3];return n<s?0:n-s}function Pn(t,e){const r=t.box;return Jr(i.set(Sn,r[0],r[1],r[2]),s.set(Cn,r[3],r[4],r[5],r[6],r[7],r[8],r[9],r[10],r[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");class Dn{constructor(t,e,r){this.i=t,this.yr=e||Ft,this.o=r,this.gr={"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.Rr(t,e,r,n,i)):yt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Rr(t,i,r,n)}))}Rr(t,e,r,n,i){const s=i&&i.maxTextureSize,o=this.br(e,r,n,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.yr(a,o.glb,{transferable:!0,requestImage:this.i,decoders:this.gr,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}}))}br(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),u=28+e;l>=570425344?(u-=8,o=a,l=c,f=0,a=0,c=0):f>=570425344&&(u-=4,o=l,l=a,f=c,a=0,c=0);const h=[t];let _,d,E;if(a>0?(_=ye(t,u,a),u+=a,o=_.BATCH_LENGTH):_={"BATCH_LENGTH":o},c>0&&(u+=c),l>0&&(d=ge(t,u,l),u+=l,f>0)){const e=Re(0,u,f);E=t.slice(e.offset,e.offset+e.byteLength),u+=f,h.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&&h.indexOf(e)<0&&h.push(e)}return{count:o,transferables:h,featureTable:_,batchTable:d,batchTableBin:E,b3dm:m,glb:{buffer:t,byteOffset:u,byteLength:i.byteLength+i.byteOffset-u}}}Ir(){return null}}class Fn{constructor(t,e,r,n){this.i=t,this.yr=e||Ft,this.o=r,this.gr={"image/crn":Lr.crn&&Lr.crn(),"image/ktx2":Lr.ktx2&&Lr.ktx2(),"image/cttf":Lr.ktx2&&Lr.ktx2(),"draco":Lr.draco&&Lr.draco()},this.Nr=n}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.Rr(t,e,r,n,i)):yt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Rr(t,i,r,n)}))}Rr(t,e,r,n,i){return this.Sr(t,e,r,n,i).then((({gltf:i,transferables:s})=>{const o=this.wr(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})}))}Sr(t,e,r,n,i){const s=i&&i.maxTextureSize,o={transferable:!0,requestImage:this.i,decoders:this.gr,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=w(new Uint8Array(e,c+r,a.byteLength-c));-1==n.indexOf("://")&&(n=t.substring(0,t.lastIndexOf("/"))+"/"+n);return n.indexOf(".glb")>0?yt.getArrayBuffer(n,{}).then((t=>this.Or(n,{buffer:t.data,byteOffset:0},o))):yt.getJSON(n,{}).then((t=>this.Or(n,t,o)))}{const n={buffer:e,byteOffset:c+r,byteLength:a.byteLength-c};return this.Or(t,n,o)}}Or(t,e,r){const n=t.substring(0,t.lastIndexOf("/")),i=new this.yr(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}}))}wr(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}=ve(i,32+e,o),u={},h=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;u.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,r=a.QUANTIZED_VOLUME_SCALE,{byteOffset:n}=a.POSITION_QUANTIZED;u.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.Mr(new Uint16Array(t,n+c.offset,3*h),e,r)},o.push(u.POSITION.array.buffer)}if(a.BATCH_ID){u.BATCH_ID=Ie(a.BATCH_ID,t,c.offset,h);const e=u.BATCH_ID.array&&u.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;u.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,u.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;u.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.Cr(new Uint16Array(t,e+c.offset,2*h))},o.push(u.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,u.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.Cr(new Uint16Array(t,e+c.offset,2*h))},o.push(u.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;u.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,h).slice()},o.push(u.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;u.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.SCALE_NON_UNIFORM.array.buffer)}return{count:h,batchTable:l,batchTableBin:f,featureTable:a,i3dm:u,transferables:o}}Cr(t){const e=t.length/2,r=new Float32Array(3*e),n=[];for(let i=0;i<e;i++)Gn(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}Mr(t,e,r){return Ce(new Float32Array(t.length),t,e,r)}Ir(){return null}}function Gn(t,e,r,n){if(t[0]=kn(e,n),t[1]=kn(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]))*Hn(e),t[1]=(1-Math.abs(e))*Hn(t[1])}return K(t,t)}function kn(t,e){return e=function(t,e){if(null!=t)return t;return e}(e,255),function(t,e,r){return t<e?e:t>r?r:t}(t,0,e)/e*2-1}function Hn(t){return t<0?-1:1}class Vn{constructor(){}load(t,e,r=0,n=0){return e?(n||(n=e.byteLength),this.Rr(t,e,r,n)):yt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Rr(t,i,r,n)}))}Rr(t,e,r,n){return this.vr(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}))}vr(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}=ve(i,e+28,o),u=a.QUANTIZED_VOLUME_OFFSET,h=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.Ur||(this.Ur=Lr.draco()),this.Ur(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.Br(t,e.attributes,c.offset,_,o,u,h);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:Me(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=zn(_);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.Br(t,a,c.offset,_,o,u,h);if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?T.BATCH_ID=Ie(a.BATCH_ID,t,c.offset,_):T.BATCH_ID=zn(_);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})}Br(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.Mr(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}Mr(t,e,r){return Ce(new Float32Array(t.length),t,e,r)}Ir(){return null}}function zn(t){const e=M(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:Me(e),array:r}}class Xn{constructor(t,e){this.i=t,this.yr=e||Ft}load(t,e,r=0,n=0,i){return e?this.Rr(t,e,r,n,i):yt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return this.Rr(t,i,r,n)}))}Rr(t,e,r,n,i){n||(n=e.byteLength);const s=this.Lr(e,t,r,n),o=[];for(let r=0;r<s.length;r++){let n;if("b3dm"===s[r].magic)n=new Dn(this.i,this.yr);else if("i3dm"===s[r].magic)n=new Fn(this.i,this.yr);else if("pnts"===s[r].magic)n=new Vn;else{if("cmpt"!==s[r].magic){console.warn("Unsupported magic in CMPT tile:",s[r].magic);continue}n=new Xn(this.i,this.yr)}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})))}Lr(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(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(l);t.registerWorkerAdapter("@maptalks/3dtiles",r)}else t.registerWorkerAdapter("@maptalks/3dtiles",(function(){return e.transcoders.inject(l)}))}else t.registerWorkerAdapter("@maptalks/3dtiles",l);export{Dn as B3DMLoader,Xn as CMPTLoader,Bn as Geo3DTilesLayer,B as Geo3DTilesUtil,Te as Geo3DTransform};"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.18.2");
|
package/dist/maptalks.3dtiles.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @maptalks/3dtiles v0.18.
|
|
2
|
+
* @maptalks/3dtiles v0.18.2
|
|
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.68.1
|
|
21
21
|
* LICENSE : UNLICENSED
|
|
22
22
|
* (c) 2016-2022 maptalks.com
|
|
23
|
-
*/const Cr=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")},vr=Cr(),Ur=vr.gl_trans__coders=vr.gl_trans__coders||{};function Br(t,e){if(e)for(let r=0;r<e.length;r++){t[e[r].id||e[r].index]=e[r]}}Ur.inject=function(t){const e=t.toString(),r=e.indexOf("{")+1,n=e.substring(0,r),i=vr.gl_trans__coders=vr.gl_trans__coders||{};let s=`${n}\n const _____getGlobal = ${Cr.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},Ur.registerTranscoder=function(t,e){Ur[t]=e},Ur.getTranscoder=function(t){return Ur[t]};const Lr=[];class Pr{constructor(t,e,r,n){this.fe=t,this.Mt=e,this.ue=n,this.he=r.version,t.indexOf("i3s:tileset:")<0?(this.he<=1.6?this._e="root":this._e=0,r.version=this.he):(this._e=t.substring("i3s:tileset:".length),this.he>1.6&&(this._e=parseInt(this._e))),this.fe=t,this.de=r}load(){const t=this.de,e=t.layerScene.baseUrl;if(this.he<=1.6)return t[this._e]&&t[this._e].lodSelection?(this.Ee=t[this._e],this.Te()):new Promise((r=>{let n=e+"/nodes/"+this._e;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.ue(this.Mt,n,(()=>{this.Ee=t[this._e],r(this.Te())}))}));if(this.he>=1.7){if(t[this._e])return this.Ee=t[this._e],this.Te();const r=Math.floor(this._e/t.nodesPerPage);return new Promise((n=>{let i=e+"/nodepages/"+r;t.layerScene.eslpk&&(i+=".json"),this.ue(this.Mt,i,(()=>{this.Ee=t[this._e],n(this.Te())}))}))}return null}getTileset(){return this.me}getChildrenURL(){return this.Ae}Te(){const t=this.de,e=t.layerScene.baseUrl,r=this.Ee.children,n=[],i={};if(r)for(let s=0;s<r.length;s++)if(this.he<=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.ue(this.Mt,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.ue(this.Mt,n,(()=>{r()}))})),n.push(i[a]))}return n.length?Promise.all(n).then((()=>this.pe())):this.pe()}pe(){return Promise.resolve(this.ye())}ge(t){Br(this.de,t)}ye(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.Re(this.Ee,!0)}}Re(t){const e=this.he,r=this.de,n=t;var i,s=n.obb,o=n.mbs,a={};if(o)i=Dr([],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,u=n*a,h=i*o,_=i*a,d=i*c,E=s*o,T=s*a,m=s*c;return t[0]=1-u-d,t[3]=f-m,t[6]=h+T,t[1]=f+m,t[4]=1-l-d,t[7]=_-E,t[2]=h-T,t[5]=_+E,t[8]=1-l-u,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=Dr([],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];k(Lr,e,r,n);const o=q(Lr);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 u=16*c;const h=B([]),_=n.children;var d;if(_){d=[];const t=this.de;for(let r=0;r<_.length;r++){const n=e<=1.6?_[r].id:_[r];if(!t[n]){d=null;break}d.push(this.Re(t[n]))}}var E={refine:"REPLACE",boundingVolume:a,transform:h,geometricError:u};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.Ee}}function Dr(t,e,r,n){return ee(t,p(e),p(r),n)}const Fr=!!Ur.ktx2,Gr=r.mat4.identity([]),kr=(()=>{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 Hr(t){return t.indexOf("i3s:mesh")>=0}const Vr="i3s:mesh:".length;function zr(t,e,r,n,i){const s=e.layerScene.eslpk,o=function(t,e){const r=e.substring(Vr);return t>=1.7?parseInt(r):r}(e.version,t),a=e[o],c=e.layerScene.baseUrl,l=[];let f=!1;const u=Gr;let h,_;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{h=a.mesh.geometry,_=a.mesh.material;const t=e.layerScene.geometryDefinitions[h.definition],{geometryBuffers:o}=t;f=n&&2===o.length;const u=Ur.draco&&f?o[1]:o[0],d=Ur.draco&&f?1:0;let E=c+`/nodes/${h.resource}/geometries/`+d;s&&(E+=".bin");const T={geometry:{url:E,info:u}};if(i&&kr&&f&&!Ur.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 Xr(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:u}}function Xr(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=Yr(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])&&Xr(t[o],e,r,n,i,s)}function Yr(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&&Fr)return t[r]}return null}const Zr=[];class Kr extends i.renderer.CanvasRenderer{constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new Kt(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.be={},this.Ie=[],this.ue=this.Ne.bind(this)}getAnalysisMeshes(){if(!this.painter)return Zr;const t=this.painter.getPaintedMeshes();if(!t)return Zr;const e=[],{b3dmMeshes:r,pntsMeshes:n,i3dmMeshes:i}=t;return r.length&&M(e,r),n.length&&M(e,n),i.length&&M(e,i),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.Ie.length||super.needToRedraw())}drawOnInteracting(t,e,r){this.draw(e,r)}draw(t,e){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.Se(),this.we();const{selectedTiles:o,leaves:a,requests:c}=this.Oe(n,i);c.length&&this.loadTiles(c),this.xe(o,a,e),this.Me(),c.length||this.completeRender()}Oe(t,e){let r=[];this.Ce();let n=0;const i=this.ve(),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.Ue(c.id)?(n++,l=a=!0,this.tilesLoading[c.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=a=!0),o=!0,i.selected=!0,i.data=f):this.painter.has(c)||(l=a=!0,r.push(c)),!l)continue;if(this.Be(i))o=!0;else{this.Le(i).length&&(o=!0)}}let c=[],l={};if(o&&({selectedTiles:c,leaves:l}=this.Pe(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}}Pe(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.De===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.De=i.length}for(let t=0;t<o.length;t++)i.push(o[t])}return{selectedTiles:e,leaves:r}}Be(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}Le(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const r=t.Fe+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.Ge(i[s],t);r.selected=!0,r.data=this.tileCache.get(o),t.children.push(r),e.push(r)}else i[s].Fe<=r&&n.push(i[s])}}return e}xe(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=r&&r.renderTarget,s=r&&r.sceneFilter,o=this.painter.paint(t,e,s,i);this.layer.options.debug&&this.painter.paintRegion(t,{color:this.layer.options.debugOutline},s,i),this.onDrawTileEnd(n),o&&this.layer.fire("canvasisdirty",{renderCount:o})}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=x(e);return void this.ke(e,r,t)}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const r=t.Mt,n=this.He[r];return new Pr(e,r,n,this.ue).load().then((r=>{this.onTilesetLoad(r,t,e)}))}t&&-1===e.indexOf("http://")&&-1===e.indexOf("https://")&&!Hr(e)&&(e=t.baseUrl+e);const r=this.layer.options.services[t.Mt];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.be[e],r?this.ke(e,r.data,t):this.onTileError(null,t)})).catch((r=>{delete this.be[e],this.onTileError(r,t)})),this.be[e]=s}else this.ke(e,null,t)}ke(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.Mt];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.Mt,upAxis:n.$t,transform:n.matrix,supportedFormats:i};if(Hr(t)){const e=this.He[n.Mt];if(o.i3sInfo=zr(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.Ie.push({data:r,tile:n}):this.onTilesetLoad(r,n,t)}))}we(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let r=0;for(;this.Ie.length&&(r<e||!t.isInteracting());){const{data:t,tile:e}=this.Ie.shift(),{magic:n}=t;"b3dm"===n?this.painter.createB3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.Ve(t,e,r,n)})):"pnts"===n?this.painter.createPntsMesh(t,e.id,e,((r,{mesh:n})=>{this.Ve(t,e,r,n)})):"i3dm"===n?this.painter.createI3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.Ve(t,e,r,n)})):"cmpt"===n&&this.painter.createCMPTMesh(t,e.id,e,((r,{mesh:n})=>{this.Ve(t,e,r,n)})),r++}}Ve(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.Xe(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.Ye(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.Ze(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}Ze(t,e){const r={loadTime:i.Util.now(),current:!0,error:e,node:t};this.tileCache.add(t.id,r)}Xe(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.Mt].ajaxInMainThread){const t=this.be[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.be[e]}Ce(){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.Ke(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 Mr(this.regl,t)}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new Xt("@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.Me(!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}Me(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)}}}ve(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}Ke(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}Ue(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 ge(t,e,0,r)}Se(){if(!this.We)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const r=[];for(const n in this.We){const i=this.We[n];if("pending"===i.status)continue;i.status="pending";const s=i.rootIdx;if(r.push(At.getJSON(n).then((t=>{delete this.We[n];const e=this.He[s];if(e){t.nodes?Br(e,t.nodes):(e[t.id]=t,Br(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)}Ne(t,e,r){this.We||(this.We={}),this.We[e]=this.We[e]||[],this.We[e].rootIdx=t,this.We[e].push(r),this.setToRedraw()}Ye(t,e,r){this.He||(this.He=[]);const n=e.Mt;this.He[n]||(this.He[n]={});const i=this.He[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 Pr(n,e,i,s).load()}(t,n,0,r,i,this.ue).then((t=>{this.onTilesetLoad(t,e,r)}))}pick(t,e,r){return this.painter?this.painter.pick(t,e,r&&r.tolerance):[]}}function jr(t,e){return t.Ft-e.Ft}function Wr(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($r,r,t),i=Wr(Jr,e,0),s=Wr(Qr,e,1),o=Wr(tn,e,2),a=q(i),c=q(s),l=q(o);Y(i,i),Y(s,s),Y(o,o);var f=en;f[0]=Z(n,i),f[1]=Z(n,s),f[2]=Z(n,o);var u,h=0;f[0]<-a?h+=(u=f[0]+a)*u:f[0]>a&&(h+=(u=f[0]-a)*u);f[1]<-c?h+=(u=f[1]+c)*u:f[1]>c&&(h+=(u=f[1]-c)*u);f[2]<-l?h+=(u=f[2]+l)*u:f[2]>l&&(h+=(u=f[2]-l)*u);return h}(t,e,r))}const $r=[],Jr=[],Qr=[],tn=[],en=[];const rn=2*Math.PI;class nn{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+=rn,r<0&&(r+=rn)),(r>i||Ee(r,i,1e-14))&&(r<s||Ee(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 sn=[0,0,1];function on(t,e){return ee(e,t[0],t[1],t[2])}class an{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 cn=[],ln=[],fn=[],un=[],hn=[],_n=[],dn=[],En=[],Tn=[],mn=[],An=new an([1,0,0],0),pn=[];class yn{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new nn(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){var n,i,s,o=0;if(!nn.contains(this.rectangle,e)){var a=this.southwestCornerCartesian,c=this.northeastCornerCartesian,l=this.westNormal,f=this.southNormal,u=this.eastNormal,h=this.northNormal,_=r.vec3.subtract(pn,t,a),d=r.vec3.dot(_,l),E=r.vec3.dot(_,f),T=r.vec3.subtract(pn,t,c),m=r.vec3.dot(T,u),A=r.vec3.dot(T,h);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;on(nn.southwest(t,ln),e.southwestCornerCartesian),on(nn.northeast(t,ln),e.northeastCornerCartesian),cn[0]=t.west,cn[1]=.5*(t.south+t.north),cn[2]=0;var n=on(cn,fn),i=r.vec3.cross(hn,n,sn);r.vec3.normalize(e.westNormal,i),cn[0]=t.east;var s=on(cn,En),o=r.vec3.cross(hn,sn,s);r.vec3.normalize(e.eastNormal,o);var a,c=r.vec3.subtract(hn,n,s),l=r.vec3.normalize(un,c),f=t.south;if(f>0){cn[0]=.5*(t.west+t.east),cn[1]=f;var u=on(cn,Tn);r.vec3.copy(mn,l);var h=an.fromPointNormal(e.southwestCornerCartesian,e.westNormal,An);gn(Tn,mn,h,e.southwestCornerCartesian),a=he(u,_n)}else a=_e(nn.southeast(t,ln),_n);var _=r.vec3.cross(dn,a,c);r.vec3.normalize(e.southNormal,_);var d,E=t.north;if(E<0){cn[0]=.5*(t.west+t.east),cn[1]=E;var T=on(cn,Tn);r.vec3.scale(mn,l,-1);var m=an.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,An);gn(Tn,mn,m,e.northeastCornerCartesian),d=he(T,_n)}else d=_e(nn.northwest(t,ln),_n);var A=r.vec3.cross(dn,c,d);r.vec3.normalize(e.northNormal,A)}}function gn(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 Rn=new i.Extent(0,0,0,0),bn=new i.Extent(0,0,0,0),In=[],Nn=[],Sn=[],wn=[],On=new i.Point(0,0),xn=[],Mn=new i.Coordinate(0,0),Cn=r.mat4.identity([]);class vn extends i.Layer{constructor(t,e){super(t,e),this.qe(),this.be={},this.$e=[]}qe(){let t=this.options.services.map((t=>t.url));this.Je=t.map(((t,e)=>function(t,e){t=g(t);return{baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:r.mat4.identity([]),Mt:e,Fe:0}}(t,e))),this.fire("rootready",{roots:this.Je.slice(0)})}getTileUrl(t){return t}getExtent(t){if(!t&&0!==t){const t=new i.Extent;for(let e=0;e<this.Je.length;e++)if(this.Je[e].boundingVolume){const r=this.boundingVolumeToExtent(this.Je[e]);t._combine(r)}return t}return this.Je[t]&&this.Je[t].boundingVolume?this.boundingVolumeToExtent(this.Je[t]):null}boundingVolumeToExtent(t){const e=t.boundingVolume.Qe?Cn: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=ae([],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(ae([],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)),u=r.vec3.length(c.slice(6,9)),h=Math.max(l,f,u),_=n.locate(a,-h,h),d=n.locate(a,h,-h);return new i.Extent(_,d)}return null}getRootTiles(){return this.Je}getTiles(){const t=this.getRenderer();if(!t.ready)return this.tr(),{tiles:wn};const e=this.getMap(),n=e.cameraPosition;let i,s;if(e.getGLZoom)s=e.pointToDistance(n[2],0,e.getGLZoom()),Mn.set(n[0],n[1]),i=e.pointToCoord(Mn,e.getGLZoom());else{const t=e.getGLRes();s=e.pointAtResToDistance(n[2],0,t),Mn.set(n[0],n[1]),i=e.pointAtResToCoord(Mn,t)}this.er=this.er||[],r.vec3.set(this.er,p(i.x),p(i.y),s),this.rr=ee(this.rr||[],this.er[0],this.er[1],this.er[2]),this.nr=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.Je.length;e++){let r=1/0;const n=[this.Je[e]],i=this.ir(e);for(;n.length>0;){const e=n.pop();for(e.id||this.sr(e);c.level>=e.Fe;)c=c.parent;const s=this.ar(e,i,o);if(s<1){let t=c;for(;t&&!t.content;)t=t.parent;0===s&&t&&t.content&&this.cr(l,t);if(!1===this.options.services[e.Mt].alwaysShow)continue;if(!(0===s&&e.Fe<=r))continue;e.content&&(r=e.Fe)}e.Ft<1/0&&this.lr(e);const a=this.Ge(e,c);c.children.push(a);const f=e.children,u=f&&f.length,h=a.content;if(!u&&h&&this.cr(l,a),u){h&&"add"===e.refine&&this.cr(l,a),c=a;const r=f[0].parent;let i=!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;i=!0}else{i=!0,f[s].parent=e,f[s].$t=e.$t,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))}n.push(f[s])}!i&&h&&this.cr(l,a)}}}return{root:a,tiles:l}}cr(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 Un(r,e);if(r.box)return 0===Bn(r,e)}return!1}(this.er,this.rr,r)||t.push(e)}Ge(t,e){return{id:t.id,node:t,children:[],level:t.Fe,parent:e,content:t.content&&t.content.url}}sr(t){t.id=i.Util.GUID(),t.matrix=t.transform||r.mat4.identity([]),t.ur=this.hr(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.Mt=t.parent.Mt,void 0===t.Fe&&(t.Fe=t.parent.Fe+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._r(t)}_r(t){const e=t.boundingVolume;if(!e||e.Qe)return;const n=this.options.services[t.Mt].heightOffset||0,i=this.options.offset,s=m(i)||i[0]||i[1];if(!t.boundingVolume||!n&&r.mat4.exactEquals(t.matrix,Cn)&&!s)return;const{region:o,box:a,sphere:c}=e;if(o){const t=this.dr([y(o[0]),y(o[1])]);o[0]=p(t.x),o[1]=p(t.y);const e=this.dr([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(In,e,t.matrix),s=ae(Nn,i),o=this.dr([s[0],s[1]]);s[0]=o.x,s[1]=o.y,s[2]+=n,ee(e,p(s[0]),p(s[1]),s[2])}e.Qe=!0}hr(t){return void 0===t.geometricError||!t.boundingVolume}lr(t){let e=t.parent;for(;e&&e.ur&&!(e.Ft<=t.Ft);)e.Ft=t.Ft,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.Mt],s=(t.asset&&t.asset.gltfUpAxis||e&&e.$t||i.upAxis||"Y").toUpperCase();t.root.baseUrl=n.substring(0,n.lastIndexOf("/")+1);const o=n.indexOf("realspace/")>-1;0===e.Fe&&(t.asset&&t.asset.s3mType&&o||i.isSuperMapiServer)&&(t.root.baseUrl+="data/path/");const a=t.asset.i3s;if(t.root.$t=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._r(e),e.Er=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.ur=this.hr(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.tr(),this.fire("loadtileset",{tileset:t,index:e.Mt,url:n})}ar(t,e,r){if(t.Ft=1/0,0===t.Fe||t.ur)return 1;if(!this.Tr(t,e,r))return-1;if(0===t.geometricError)return 1;let n=this.options.services[t.Mt].maximumScreenSpaceError;null==n&&(n=8);let i=this.mr(t);return 0===i&&t.parent&&(i=.5*(t.parent.Ar||0)),i>=n?1:0}Yt(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)}Tr(t,e,n){const s=t.id;let o=this.$e[s];const{boundingVolume:c}=t,l=c.sphere,_=c.region,E=c.box;if(!o){let e,n,a;if(_){e=Rn.set(y(_[0]),y(_[1]),y(_[2]),y(_[3]));const t=e.getCenter(),r=this.pr(t);e=e.convertTo((t=>this.Yt(t,On)),bn),a=_[4],n=_[5],o=this.$e[s]=[[e.xmin,e.ymin,a*r[2]],[e.xmax,e.ymax,n*r[2]]],o.center=t}else if(l){const t=ae(In,l),e=new i.Coordinate(t),r=this.Yt(e,On).toArray(),n=this.pr(e);r.push(t[2]*n[2]),o=this.$e[s]=[r,l[3]*n[2]],o.center=e}else if(E){const e=ae(In,E),n=new i.Coordinate(e),a=this.Yt(n,On).toArray(),c=this.pr(n);a.push(e[2]*c[2]);const l=E.slice(3);r.mat4.exactEquals(t.matrix,Cn)||r.mat3.multiply(l,r.mat3.fromMat4(xn,t.matrix),l);for(let t=0;t<l.length;t++)l[t]*=c[t%3],E[3+t]=l[t];o=this.$e[s]=[...a,...l],o.center=n}}if(e){if(_)Rn.xmin=o[0][0],Rn.ymin=o[0][1],Rn.xmax=o[1][0],Rn.ymax=o[1][1];else if(l){const t=o[2];Rn.xmin=o[0][0]-t,Rn.ymin=o[0][1]-t,Rn.xmax=o[0][0]+t,Rn.ymax=o[0][1]+t}else if(E){const t=o[1],e=o[2];Rn.xmin=o[0][0]-t,Rn.ymin=o[0][1]-e,Rn.xmax=o[0][0]+t,Rn.ymax=o[0][1]+e}if(!e.intersects(Rn))return!1}return _?f(n,o):l?function(t,e,r){h(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){h(t);for(var n=0;n<6;n++)if(!(r&&"0"===r.charAt(n)||u(a[n],e)))return!1;return!0}(n,o)}pr(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(Sn,n.x/100*1.01,n.y/100*1.01,i),Sn}dr(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}ir(t){const e=this.options.services[t].maxExtent;if(!e)return null;const r=this.Je[t];return r.maxExtent||(r.maxExtent=new i.Extent(e).convertTo((t=>this.Yt(t)))),r.maxExtent}mr(t){const e=this.nr,r=t.geometricError;if(0===r)return 0;const n=this.getMap();let i;t.boundingVolume.region?i=function(t,e,r){t.yr||(t.yr=new yn(t.boundingVolume.region));return t.yr.distanceToCamera(e,r)}(t,this.rr,this.er):t.boundingVolume.sphere?i=Un(t.boundingVolume,this.rr):t.boundingVolume.box&&(i=Bn(t.boundingVolume,this.rr));const s=Math.max(Math.abs(i),1e-7),o=r*n.height/(s*e);return t.Ft=i,t.Ar=o,o}tr(){const t=this.getRenderer();t&&t.setToRedraw()}re(t){return this.$e[t]}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)}}function Un(t,e){const n=t.sphere,i=r.vec3.dist(n,e),s=t.sphere[3];return i<s?0:i-s}function Bn(t,e){const n=t.box;return qr(r.vec3.set(In,n[0],n[1],n[2]),r.mat3.set(xn,n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10],n[11]),e)}vn.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]}),vn.registerRenderer("gl",Kr),vn.registerJSONType("Geo3DTilesLayer");class Ln{constructor(t,e,r){this.o=t,this.gr=e||Pt,this.l=r,this.Rr={"image/crn":Ur.crn&&Ur.crn(),"image/ktx2":Ur.ktx2&&Ur.ktx2(),"image/cttf":Ur.ktx2&&Ur.ktx2(),"draco":Ur.draco&&Ur.draco()}}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.br(t,e,r,n,i)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.br(t,i,r,n)}))}br(t,e,r,n,i){const s=i&&i.maxTextureSize,o=this.Ir(e,r,n,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.gr(a,o.glb,{transferable:!0,requestImage:this.o,decoders:this.Rr,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}}))}Ir(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),u=28+e;l>=570425344?(u-=8,o=a,l=c,f=0,a=0,c=0):f>=570425344&&(u-=4,o=l,l=a,f=c,a=0,c=0);const h=[t];let _,d,E;if(a>0?(_=Ae(t,u,a),u+=a,o=_.BATCH_LENGTH):_={"BATCH_LENGTH":o},c>0&&(u+=c),l>0&&(d=pe(t,u,l),u+=l,f>0)){const e=ye(0,u,f);E=t.slice(e.offset,e.offset+e.byteLength),u+=f,h.push(E)}const T=_.BATCH_LENGTH,m={};if(_&&_.BATCH_ID){m.BATCH_ID=Re(_.BATCH_ID,t,undefined.offset,T);const e=m.BATCH_ID.array&&m.BATCH_ID.array.buffer;e&&h.indexOf(e)<0&&h.push(e)}return{count:o,transferables:h,featureTable:_,batchTable:d,batchTableBin:E,b3dm:m,glb:{buffer:t,byteOffset:u,byteLength:i.byteLength+i.byteOffset-u}}}Nr(){return null}}class Pn{constructor(t,e,r,n){this.o=t,this.gr=e||Pt,this.l=r,this.Rr={"image/crn":Ur.crn&&Ur.crn(),"image/ktx2":Ur.ktx2&&Ur.ktx2(),"image/cttf":Ur.ktx2&&Ur.ktx2(),"draco":Ur.draco&&Ur.draco()},this.Sr=n}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.br(t,e,r,n,i)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.br(t,i,r,n)}))}br(t,e,r,n,i){return this.wr(t,e,r,n,i).then((({gltf:i,transferables:s})=>{const o=this.Or(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})}))}wr(t,e,r,n,i){const s=i&&i.maxTextureSize,o={transferable:!0,requestImage:this.o,decoders:this.Rr,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.Mr(n,{buffer:t.data,byteOffset:0},o))):At.getJSON(n,{}).then((t=>this.Mr(n,t,o)))}{const n={buffer:e,byteOffset:c+r,byteLength:a.byteLength-c};return this.Mr(t,n,o)}}Mr(t,e,r){const n=t.substring(0,t.lastIndexOf("/")),i=new this.gr(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}}))}Or(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}=Me(i,32+e,o),u={},h=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;u.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,r=a.QUANTIZED_VOLUME_SCALE,{byteOffset:n}=a.POSITION_QUANTIZED;u.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.Cr(new Uint16Array(t,n+c.offset,3*h),e,r)},o.push(u.POSITION.array.buffer)}if(a.BATCH_ID){u.BATCH_ID=Re(a.BATCH_ID,t,c.offset,h);const e=u.BATCH_ID.array&&u.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;u.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,u.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;u.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.vr(new Uint16Array(t,e+c.offset,2*h))},o.push(u.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,u.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.vr(new Uint16Array(t,e+c.offset,2*h))},o.push(u.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;u.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,h).slice()},o.push(u.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;u.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.SCALE_NON_UNIFORM.array.buffer)}return{count:h,batchTable:l,batchTableBin:f,featureTable:a,i3dm:u,transferables:o}}vr(t){const e=t.length/2,r=new Float32Array(3*e),n=[];for(let i=0;i<e;i++)Dn(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}Cr(t,e,r){return xe(new Float32Array(t.length),t,e,r)}Nr(){return null}}function Dn(t,e,r,n){if(t[0]=Fn(e,n),t[1]=Fn(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]))*Gn(e),t[1]=(1-Math.abs(e))*Gn(t[1])}return Y(t,t)}function Fn(t,e){return e=function(t,e){if(null!=t)return t;return e}(e,255),function(t,e,r){return t<e?e:t>r?r:t}(t,0,e)/e*2-1}function Gn(t){return t<0?-1:1}class kn{constructor(){}load(t,e,r=0,n=0){return e?(n||(n=e.byteLength),this.br(t,e,r,n)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.br(t,i,r,n)}))}br(t,e,r,n){return this.Ur(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}))}Ur(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}=Me(i,e+28,o),u=a.QUANTIZED_VOLUME_OFFSET,h=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.Br||(this.Br=Ur.draco()),this.Br(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.Lr(t,e.attributes,c.offset,_,o,u,h);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:Oe(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?n.BATCH_ID=Re(a.BATCH_ID,t,c.offset,_):n.BATCH_ID=Hn(_);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.Lr(t,a,c.offset,_,o,u,h);if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?T.BATCH_ID=Re(a.BATCH_ID,t,c.offset,_):T.BATCH_ID=Hn(_);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})}Lr(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.Cr(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}Cr(t,e,r){return xe(new Float32Array(t.length),t,e,r)}Nr(){return null}}function Hn(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:Oe(e),array:r}}class Vn{constructor(t,e){this.o=t,this.gr=e||Pt}load(t,e,r=0,n=0,i){return e?this.br(t,e,r,n,i):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return this.br(t,i,r,n)}))}br(t,e,r,n,i){n||(n=e.byteLength);const s=this.Pr(e,t,r,n),o=[];for(let r=0;r<s.length;r++){let n;if("b3dm"===s[r].magic)n=new Ln(this.o,this.gr);else if("i3dm"===s[r].magic)n=new Pn(this.o,this.gr);else if("pnts"===s[r].magic)n=new kn;else{if("cmpt"!==s[r].magic){console.warn("Unsupported magic in CMPT tile:",s[r].magic);continue}n=new Vn(this.o,this.gr)}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})))}Pr(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=Te(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=Ln,t.CMPTLoader=Vn,t.Geo3DTilesLayer=vn,t.Geo3DTilesUtil=C,t.Geo3DTransform=de,Object.defineProperty(t,"t",{value:!0}),"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.18.1")}));
|
|
23
|
+
*/const Cr=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")},vr=Cr(),Ur=vr.gl_trans__coders=vr.gl_trans__coders||{};function Br(t,e){if(e)for(let r=0;r<e.length;r++){t[e[r].id||e[r].index]=e[r]}}Ur.inject=function(t){const e=t.toString(),r=e.indexOf("{")+1,n=e.substring(0,r),i=vr.gl_trans__coders=vr.gl_trans__coders||{};let s=`${n}\n const _____getGlobal = ${Cr.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},Ur.registerTranscoder=function(t,e){Ur[t]=e},Ur.getTranscoder=function(t){return Ur[t]};const Lr=[];class Pr{constructor(t,e,r,n){this.fe=t,this.Mt=e,this.ue=n,this.he=r.version,t.indexOf("i3s:tileset:")<0?(this.he<=1.6?this._e="root":this._e=0,r.version=this.he):(this._e=t.substring("i3s:tileset:".length),this.he>1.6&&(this._e=parseInt(this._e))),this.fe=t,this.de=r}load(){const t=this.de,e=t.layerScene.baseUrl;if(this.he<=1.6)return t[this._e]&&t[this._e].lodSelection?(this.Ee=t[this._e],this.Te()):new Promise((r=>{let n=e+"/nodes/"+this._e;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.ue(this.Mt,n,(()=>{this.Ee=t[this._e],r(this.Te())}))}));if(this.he>=1.7){if(t[this._e])return this.Ee=t[this._e],this.Te();const r=Math.floor(this._e/t.nodesPerPage);return new Promise((n=>{let i=e+"/nodepages/"+r;t.layerScene.eslpk&&(i+=".json"),this.ue(this.Mt,i,(()=>{this.Ee=t[this._e],n(this.Te())}))}))}return null}getTileset(){return this.me}getChildrenURL(){return this.Ae}Te(){const t=this.de,e=t.layerScene.baseUrl,r=this.Ee.children,n=[],i={};if(r)for(let s=0;s<r.length;s++)if(this.he<=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.ue(this.Mt,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.ue(this.Mt,n,(()=>{r()}))})),n.push(i[a]))}return n.length?Promise.all(n).then((()=>this.pe())):this.pe()}pe(){return Promise.resolve(this.ye())}ge(t){Br(this.de,t)}ye(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.Re(this.Ee,!0)}}Re(t){const e=this.he,r=this.de,n=t;var i,s=n.obb,o=n.mbs,a={};if(o)i=Dr([],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,u=n*a,h=i*o,_=i*a,d=i*c,E=s*o,T=s*a,m=s*c;return t[0]=1-u-d,t[3]=f-m,t[6]=h+T,t[1]=f+m,t[4]=1-l-d,t[7]=_-E,t[2]=h-T,t[5]=_+E,t[8]=1-l-u,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=Dr([],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];k(Lr,e,r,n);const o=q(Lr);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 u=16*c;const h=B([]),_=n.children;var d;if(_){d=[];const t=this.de;for(let r=0;r<_.length;r++){const n=e<=1.6?_[r].id:_[r];if(!t[n]){d=null;break}d.push(this.Re(t[n]))}}var E={refine:"REPLACE",boundingVolume:a,transform:h,geometricError:u};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.Ee}}function Dr(t,e,r,n){return ee(t,p(e),p(r),n)}const Fr=!!Ur.ktx2,Gr=r.mat4.identity([]),kr=(()=>{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 Hr(t){return t.indexOf("i3s:mesh")>=0}const Vr="i3s:mesh:".length;function zr(t,e,r,n,i){const s=e.layerScene.eslpk,o=function(t,e){const r=e.substring(Vr);return t>=1.7?parseInt(r):r}(e.version,t),a=e[o],c=e.layerScene.baseUrl,l=[];let f=!1;const u=Gr;let h,_;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{h=a.mesh.geometry,_=a.mesh.material;const t=e.layerScene.geometryDefinitions[h.definition],{geometryBuffers:o}=t;f=n&&2===o.length;const u=Ur.draco&&f?o[1]:o[0],d=Ur.draco&&f?1:0;let E=c+`/nodes/${h.resource}/geometries/`+d;s&&(E+=".bin");const T={geometry:{url:E,info:u}};if(i&&kr&&f&&!Ur.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 Xr(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:u}}function Xr(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=Yr(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])&&Xr(t[o],e,r,n,i,s)}function Yr(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&&Fr)return t[r]}return null}const Zr=[];class Kr extends i.renderer.CanvasRenderer{constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new Kt(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.be={},this.Ie=[],this.ue=this.Ne.bind(this)}getAnalysisMeshes(){if(!this.painter)return Zr;const t=this.painter.getPaintedMeshes();if(!t)return Zr;const e=[],{b3dmMeshes:r,pntsMeshes:n,i3dmMeshes:i}=t;return r.length&&M(e,r),n.length&&M(e,n),i.length&&M(e,i),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.Ie.length||super.needToRedraw())}drawOnInteracting(t,e,r){this.draw(e,r)}draw(t,e){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.Se(),this.we();const{selectedTiles:o,leaves:a,requests:c}=this.Oe(n,i);c.length&&this.loadTiles(c),this.xe(o,a,e),this.Me(),c.length||this.completeRender()}Oe(t,e){let r=[];this.Ce();let n=0;const i=this.ve(),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.Ue(c.id)?(n++,l=a=!0,this.tilesLoading[c.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=a=!0),o=!0,i.selected=!0,i.data=f):this.painter.has(c)||(l=a=!0,r.push(c)),!l)continue;if(this.Be(i))o=!0;else{this.Le(i).length&&(o=!0)}}let c=[],l={};if(o&&({selectedTiles:c,leaves:l}=this.Pe(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}}Pe(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.De===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.De=i.length}for(let t=0;t<o.length;t++)i.push(o[t])}return{selectedTiles:e,leaves:r}}Be(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}Le(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const r=t.Fe+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.Ge(i[s],t);r.selected=!0,r.data=this.tileCache.get(o),t.children.push(r),e.push(r)}else i[s].Fe<=r&&n.push(i[s])}}return e}xe(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=r&&r.renderTarget,s=r&&r.sceneFilter,o=this.painter.paint(t,e,s,i);this.layer.options.debug&&this.painter.paintRegion(t,{color:this.layer.options.debugOutline},s,i),this.onDrawTileEnd(n),o&&this.layer.fire("canvasisdirty",{renderCount:o})}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=x(e);return void this.ke(e,r,t)}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const r=t.Mt,n=this.He[r];return new Pr(e,r,n,this.ue).load().then((r=>{this.onTilesetLoad(r,t,e)}))}t&&-1===e.indexOf("http://")&&-1===e.indexOf("https://")&&!Hr(e)&&(e=t.baseUrl+e);const r=this.layer.options.services[t.Mt];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.be[e],r?this.ke(e,r.data,t):this.onTileError(null,t)})).catch((r=>{delete this.be[e],this.onTileError(r,t)})),this.be[e]=s}else this.ke(e,null,t)}ke(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.Mt];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.Mt,upAxis:n.$t,transform:n.matrix,supportedFormats:i};if(Hr(t)){const e=this.He[n.Mt];if(o.i3sInfo=zr(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.Ie.push({data:r,tile:n}):this.onTilesetLoad(r,n,t)}))}we(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let r=0;for(;this.Ie.length&&(r<e||!t.isInteracting());){const{data:t,tile:e}=this.Ie.shift(),{magic:n}=t;"b3dm"===n?this.painter.createB3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.Ve(t,e,r,n)})):"pnts"===n?this.painter.createPntsMesh(t,e.id,e,((r,{mesh:n})=>{this.Ve(t,e,r,n)})):"i3dm"===n?this.painter.createI3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.Ve(t,e,r,n)})):"cmpt"===n&&this.painter.createCMPTMesh(t,e.id,e,((r,{mesh:n})=>{this.Ve(t,e,r,n)})),r++}}Ve(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.Xe(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.Ye(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.Ze(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}Ze(t,e){const r={loadTime:i.Util.now(),current:!0,error:e,node:t};this.tileCache.add(t.id,r)}Xe(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.Mt].ajaxInMainThread){const t=this.be[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.be[e]}Ce(){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.Ke(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 Mr(this.regl,t)}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new Xt("@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.Me(!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}Me(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)}}}ve(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}Ke(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}Ue(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 ge(t,e,0,r)}Se(){if(!this.We)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const r=[];for(const n in this.We){const i=this.We[n];if("pending"===i.status)continue;i.status="pending";const s=i.rootIdx;if(r.push(At.getJSON(n).then((t=>{delete this.We[n];const e=this.He[s];if(e){t.nodes?Br(e,t.nodes):(e[t.id]=t,Br(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)}Ne(t,e,r){this.We||(this.We={}),this.We[e]=this.We[e]||[],this.We[e].rootIdx=t,this.We[e].push(r),this.setToRedraw()}Ye(t,e,r){this.He||(this.He=[]);const n=e.Mt;this.He[n]||(this.He[n]={});const i=this.He[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 Pr(n,e,i,s).load()}(t,n,0,r,i,this.ue).then((t=>{this.onTilesetLoad(t,e,r)}))}pick(t,e,r){return this.painter?this.painter.pick(t,e,r&&r.tolerance):[]}}function jr(t,e){return t.Ft-e.Ft}function Wr(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($r,r,t),i=Wr(Jr,e,0),s=Wr(Qr,e,1),o=Wr(tn,e,2),a=q(i),c=q(s),l=q(o);Y(i,i),Y(s,s),Y(o,o);var f=en;f[0]=Z(n,i),f[1]=Z(n,s),f[2]=Z(n,o);var u,h=0;f[0]<-a?h+=(u=f[0]+a)*u:f[0]>a&&(h+=(u=f[0]-a)*u);f[1]<-c?h+=(u=f[1]+c)*u:f[1]>c&&(h+=(u=f[1]-c)*u);f[2]<-l?h+=(u=f[2]+l)*u:f[2]>l&&(h+=(u=f[2]-l)*u);return h}(t,e,r))}const $r=[],Jr=[],Qr=[],tn=[],en=[];const rn=2*Math.PI;class nn{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+=rn,r<0&&(r+=rn)),(r>i||Ee(r,i,1e-14))&&(r<s||Ee(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 sn=[0,0,1];function on(t,e){return ee(e,t[0],t[1],t[2])}class an{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 cn=[],ln=[],fn=[],un=[],hn=[],_n=[],dn=[],En=[],Tn=[],mn=[],An=new an([1,0,0],0),pn=[];class yn{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new nn(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){var n,i,s,o=0;if(!nn.contains(this.rectangle,e)){var a=this.southwestCornerCartesian,c=this.northeastCornerCartesian,l=this.westNormal,f=this.southNormal,u=this.eastNormal,h=this.northNormal,_=r.vec3.subtract(pn,t,a),d=r.vec3.dot(_,l),E=r.vec3.dot(_,f),T=r.vec3.subtract(pn,t,c),m=r.vec3.dot(T,u),A=r.vec3.dot(T,h);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;on(nn.southwest(t,ln),e.southwestCornerCartesian),on(nn.northeast(t,ln),e.northeastCornerCartesian),cn[0]=t.west,cn[1]=.5*(t.south+t.north),cn[2]=0;var n=on(cn,fn),i=r.vec3.cross(hn,n,sn);r.vec3.normalize(e.westNormal,i),cn[0]=t.east;var s=on(cn,En),o=r.vec3.cross(hn,sn,s);r.vec3.normalize(e.eastNormal,o);var a,c=r.vec3.subtract(hn,n,s),l=r.vec3.normalize(un,c),f=t.south;if(f>0){cn[0]=.5*(t.west+t.east),cn[1]=f;var u=on(cn,Tn);r.vec3.copy(mn,l);var h=an.fromPointNormal(e.southwestCornerCartesian,e.westNormal,An);gn(Tn,mn,h,e.southwestCornerCartesian),a=he(u,_n)}else a=_e(nn.southeast(t,ln),_n);var _=r.vec3.cross(dn,a,c);r.vec3.normalize(e.southNormal,_);var d,E=t.north;if(E<0){cn[0]=.5*(t.west+t.east),cn[1]=E;var T=on(cn,Tn);r.vec3.scale(mn,l,-1);var m=an.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,An);gn(Tn,mn,m,e.northeastCornerCartesian),d=he(T,_n)}else d=_e(nn.northwest(t,ln),_n);var A=r.vec3.cross(dn,c,d);r.vec3.normalize(e.northNormal,A)}}function gn(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 Rn=new i.Extent(0,0,0,0),bn=new i.Extent(0,0,0,0),In=[],Nn=[],Sn=[],wn=[],On=new i.Point(0,0),xn=[],Mn=new i.Coordinate(0,0),Cn=r.mat4.identity([]);class vn extends i.Layer{constructor(t,e){super(t,e),this.qe(),this.be={},this.$e=[]}qe(){let t=this.options.services.map((t=>t.url));this.Je=t.map(((t,e)=>function(t,e){t=g(t);return{baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:r.mat4.identity([]),Mt:e,Fe:0}}(t,e))),this.fire("rootready",{roots:this.Je.slice(0)})}getTileUrl(t){return t}getExtent(t){if(!t&&0!==t){const t=new i.Extent;for(let e=0;e<this.Je.length;e++)if(this.Je[e].boundingVolume){const r=this.boundingVolumeToExtent(this.Je[e]);t._combine(r)}return t}return this.Je[t]&&this.Je[t].boundingVolume?this.boundingVolumeToExtent(this.Je[t]):null}boundingVolumeToExtent(t){const e=t.boundingVolume.Qe?Cn: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=ae([],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(ae([],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)),u=r.vec3.length(c.slice(6,9)),h=Math.max(l,f,u),_=n.locate(a,-h,h),d=n.locate(a,h,-h);return new i.Extent(_,d)}return null}getRootTiles(){return this.Je}getTiles(){const t=this.getRenderer();if(!t.ready)return this.tr(),{tiles:wn};const e=this.getMap(),n=e.cameraPosition;let i,s;if(e.getGLZoom)s=e.pointToDistance(n[2],0,e.getGLZoom()),Mn.set(n[0],n[1]),i=e.pointToCoord(Mn,e.getGLZoom());else{const t=e.getGLRes();s=e.pointAtResToDistance(n[2],0,t),Mn.set(n[0],n[1]),i=e.pointAtResToCoord(Mn,t)}this.er=this.er||[],r.vec3.set(this.er,p(i.x),p(i.y),s),this.rr=ee(this.rr||[],this.er[0],this.er[1],this.er[2]),this.nr=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.Je.length;e++){let r=1/0;const n=[this.Je[e]],i=this.ir(e);for(;n.length>0;){const e=n.pop();for(e.id||this.sr(e);c.level>=e.Fe;)c=c.parent;const s=this.ar(e,i,o);if(s<1){let t=c;for(;t&&!t.content;)t=t.parent;0===s&&t&&t.content&&this.cr(l,t);if(!1===this.options.services[e.Mt].alwaysShow)continue;if(!(0===s&&e.Fe<=r))continue;e.content&&(r=e.Fe)}e.Ft<1/0&&this.lr(e);const a=this.Ge(e,c);c.children.push(a);const f=e.children,u=f&&f.length,h=a.content;if(!u&&h&&this.cr(l,a),u){h&&"add"===e.refine&&this.cr(l,a),c=a;const r=f[0].parent;let i=!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;i=!0}else{i=!0,f[s].parent=e,f[s].$t=e.$t,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))}n.push(f[s])}!i&&h&&this.cr(l,a)}}}return{root:a,tiles:l}}cr(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 Un(r,e);if(r.box)return 0===Bn(r,e)}return!1}(this.er,this.rr,r)||t.push(e)}Ge(t,e){return{id:t.id,node:t,children:[],level:t.Fe,parent:e,content:t.content&&t.content.url}}sr(t){t.id=i.Util.GUID(),t.matrix=t.transform||r.mat4.identity([]),t.ur=this.hr(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.Mt=t.parent.Mt,void 0===t.Fe&&(t.Fe=t.parent.Fe+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._r(t)}_r(t){const e=t.boundingVolume;if(!e||e.Qe)return;const n=this.options.services[t.Mt].heightOffset||0,i=this.options.offset,s=m(i)||i[0]||i[1];if(!t.boundingVolume||!n&&r.mat4.exactEquals(t.matrix,Cn)&&!s)return;const{region:o,box:a,sphere:c}=e;if(o){const t=this.dr([y(o[0]),y(o[1])]);o[0]=p(t.x),o[1]=p(t.y);const e=this.dr([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(In,e,t.matrix),s=ae(Nn,i),o=this.dr([s[0],s[1]]);s[0]=o.x,s[1]=o.y,s[2]+=n,ee(e,p(s[0]),p(s[1]),s[2])}e.Qe=!0}hr(t){return void 0===t.geometricError||!t.boundingVolume}lr(t){let e=t.parent;for(;e&&e.ur&&!(e.Ft<=t.Ft);)e.Ft=t.Ft,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.Mt],s=(t.asset&&t.asset.gltfUpAxis||e&&e.$t||i.upAxis||"Y").toUpperCase();t.root.baseUrl=n.substring(0,n.lastIndexOf("/")+1);const o=n.indexOf("realspace/")>-1;0===e.Fe&&(t.asset&&t.asset.s3mType&&o||i.isSuperMapiServer)&&(t.root.baseUrl+="data/path/");const a=t.asset.i3s;if(t.root.$t=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._r(e),e.Er=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.ur=this.hr(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.tr(),this.fire("loadtileset",{tileset:t,index:e.Mt,url:n})}ar(t,e,r){if(t.Ft=1/0,0===t.Fe||t.ur)return 1;if(!this.Tr(t,e,r))return-1;if(0===t.geometricError)return 1;let n=this.options.services[t.Mt].maximumScreenSpaceError;null==n&&(n=8);let i=this.mr(t);return 0===i&&t.parent&&(i=.5*(t.parent.Ar||0)),i>=n?1:0}Yt(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)}Tr(t,e,n){const s=t.id;let o=this.$e[s];const{boundingVolume:c}=t,l=c.sphere,_=c.region,E=c.box;if(!o){let e,n,a;if(_){e=Rn.set(y(_[0]),y(_[1]),y(_[2]),y(_[3]));const t=e.getCenter(),r=this.pr(t);e=e.convertTo((t=>this.Yt(t,On)),bn),a=_[4],n=_[5],o=this.$e[s]=[[e.xmin,e.ymin,a*r[2]],[e.xmax,e.ymax,n*r[2]]],o.center=t}else if(l){const t=ae(In,l),e=new i.Coordinate(t),r=this.Yt(e,On).toArray(),n=this.pr(e);r.push(t[2]*n[2]),o=this.$e[s]=[r,l[3]*n[2]],o.center=e}else if(E){const e=ae(In,E),n=new i.Coordinate(e),a=this.Yt(n,On).toArray(),c=this.pr(n);a.push(e[2]*c[2]);const l=E.slice(3);r.mat4.exactEquals(t.matrix,Cn)||r.mat3.multiply(l,r.mat3.fromMat4(xn,t.matrix),l);for(let t=0;t<l.length;t++)l[t]*=c[t%3],E[3+t]=l[t];o=this.$e[s]=[...a,...l],o.center=n}}if(e){if(_)Rn.xmin=o[0][0],Rn.ymin=o[0][1],Rn.xmax=o[1][0],Rn.ymax=o[1][1];else if(l){const t=o[2];Rn.xmin=o[0][0]-t,Rn.ymin=o[0][1]-t,Rn.xmax=o[0][0]+t,Rn.ymax=o[0][1]+t}else if(E){const t=o[1],e=o[2];Rn.xmin=o[0][0]-t,Rn.ymin=o[0][1]-e,Rn.xmax=o[0][0]+t,Rn.ymax=o[0][1]+e}if(!e.intersects(Rn))return!1}return _?f(n,o):l?function(t,e,r){h(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){h(t);for(var n=0;n<6;n++)if(!(r&&"0"===r.charAt(n)||u(a[n],e)))return!1;return!0}(n,o)}pr(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(Sn,n.x/100*1.01,n.y/100*1.01,i),Sn}dr(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}ir(t){const e=this.options.services[t].maxExtent;if(!e)return null;const r=this.Je[t];return r.maxExtent||(r.maxExtent=new i.Extent(e).convertTo((t=>this.Yt(t)))),r.maxExtent}mr(t){const e=this.nr,r=t.geometricError;if(0===r)return 0;const n=this.getMap();let i;t.boundingVolume.region?i=function(t,e,r){t.yr||(t.yr=new yn(t.boundingVolume.region));return t.yr.distanceToCamera(e,r)}(t,this.rr,this.er):t.boundingVolume.sphere?i=Un(t.boundingVolume,this.rr):t.boundingVolume.box&&(i=Bn(t.boundingVolume,this.rr));const s=Math.max(Math.abs(i),1e-7),o=r*n.height/(s*e);return t.Ft=i,t.Ar=o,o}tr(){const t=this.getRenderer();t&&t.setToRedraw()}re(t){return this.$e[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)}}function Un(t,e){const n=t.sphere,i=r.vec3.dist(n,e),s=t.sphere[3];return i<s?0:i-s}function Bn(t,e){const n=t.box;return qr(r.vec3.set(In,n[0],n[1],n[2]),r.mat3.set(xn,n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10],n[11]),e)}vn.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]}),vn.registerRenderer("gl",Kr),vn.registerJSONType("Geo3DTilesLayer");class Ln{constructor(t,e,r){this.o=t,this.gr=e||Pt,this.l=r,this.Rr={"image/crn":Ur.crn&&Ur.crn(),"image/ktx2":Ur.ktx2&&Ur.ktx2(),"image/cttf":Ur.ktx2&&Ur.ktx2(),"draco":Ur.draco&&Ur.draco()}}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.br(t,e,r,n,i)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.br(t,i,r,n)}))}br(t,e,r,n,i){const s=i&&i.maxTextureSize,o=this.Ir(e,r,n,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.gr(a,o.glb,{transferable:!0,requestImage:this.o,decoders:this.Rr,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}}))}Ir(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),u=28+e;l>=570425344?(u-=8,o=a,l=c,f=0,a=0,c=0):f>=570425344&&(u-=4,o=l,l=a,f=c,a=0,c=0);const h=[t];let _,d,E;if(a>0?(_=Ae(t,u,a),u+=a,o=_.BATCH_LENGTH):_={"BATCH_LENGTH":o},c>0&&(u+=c),l>0&&(d=pe(t,u,l),u+=l,f>0)){const e=ye(0,u,f);E=t.slice(e.offset,e.offset+e.byteLength),u+=f,h.push(E)}const T=_.BATCH_LENGTH,m={};if(_&&_.BATCH_ID){m.BATCH_ID=Re(_.BATCH_ID,t,undefined.offset,T);const e=m.BATCH_ID.array&&m.BATCH_ID.array.buffer;e&&h.indexOf(e)<0&&h.push(e)}return{count:o,transferables:h,featureTable:_,batchTable:d,batchTableBin:E,b3dm:m,glb:{buffer:t,byteOffset:u,byteLength:i.byteLength+i.byteOffset-u}}}Nr(){return null}}class Pn{constructor(t,e,r,n){this.o=t,this.gr=e||Pt,this.l=r,this.Rr={"image/crn":Ur.crn&&Ur.crn(),"image/ktx2":Ur.ktx2&&Ur.ktx2(),"image/cttf":Ur.ktx2&&Ur.ktx2(),"draco":Ur.draco&&Ur.draco()},this.Sr=n}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.br(t,e,r,n,i)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.br(t,i,r,n)}))}br(t,e,r,n,i){return this.wr(t,e,r,n,i).then((({gltf:i,transferables:s})=>{const o=this.Or(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})}))}wr(t,e,r,n,i){const s=i&&i.maxTextureSize,o={transferable:!0,requestImage:this.o,decoders:this.Rr,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.Mr(n,{buffer:t.data,byteOffset:0},o))):At.getJSON(n,{}).then((t=>this.Mr(n,t,o)))}{const n={buffer:e,byteOffset:c+r,byteLength:a.byteLength-c};return this.Mr(t,n,o)}}Mr(t,e,r){const n=t.substring(0,t.lastIndexOf("/")),i=new this.gr(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}}))}Or(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}=Me(i,32+e,o),u={},h=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;u.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,r=a.QUANTIZED_VOLUME_SCALE,{byteOffset:n}=a.POSITION_QUANTIZED;u.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.Cr(new Uint16Array(t,n+c.offset,3*h),e,r)},o.push(u.POSITION.array.buffer)}if(a.BATCH_ID){u.BATCH_ID=Re(a.BATCH_ID,t,c.offset,h);const e=u.BATCH_ID.array&&u.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;u.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,u.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;u.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.vr(new Uint16Array(t,e+c.offset,2*h))},o.push(u.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,u.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.vr(new Uint16Array(t,e+c.offset,2*h))},o.push(u.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;u.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,h).slice()},o.push(u.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;u.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.SCALE_NON_UNIFORM.array.buffer)}return{count:h,batchTable:l,batchTableBin:f,featureTable:a,i3dm:u,transferables:o}}vr(t){const e=t.length/2,r=new Float32Array(3*e),n=[];for(let i=0;i<e;i++)Dn(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}Cr(t,e,r){return xe(new Float32Array(t.length),t,e,r)}Nr(){return null}}function Dn(t,e,r,n){if(t[0]=Fn(e,n),t[1]=Fn(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]))*Gn(e),t[1]=(1-Math.abs(e))*Gn(t[1])}return Y(t,t)}function Fn(t,e){return e=function(t,e){if(null!=t)return t;return e}(e,255),function(t,e,r){return t<e?e:t>r?r:t}(t,0,e)/e*2-1}function Gn(t){return t<0?-1:1}class kn{constructor(){}load(t,e,r=0,n=0){return e?(n||(n=e.byteLength),this.br(t,e,r,n)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.br(t,i,r,n)}))}br(t,e,r,n){return this.Ur(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}))}Ur(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}=Me(i,e+28,o),u=a.QUANTIZED_VOLUME_OFFSET,h=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.Br||(this.Br=Ur.draco()),this.Br(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.Lr(t,e.attributes,c.offset,_,o,u,h);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:Oe(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?n.BATCH_ID=Re(a.BATCH_ID,t,c.offset,_):n.BATCH_ID=Hn(_);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.Lr(t,a,c.offset,_,o,u,h);if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?T.BATCH_ID=Re(a.BATCH_ID,t,c.offset,_):T.BATCH_ID=Hn(_);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})}Lr(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.Cr(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}Cr(t,e,r){return xe(new Float32Array(t.length),t,e,r)}Nr(){return null}}function Hn(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:Oe(e),array:r}}class Vn{constructor(t,e){this.o=t,this.gr=e||Pt}load(t,e,r=0,n=0,i){return e?this.br(t,e,r,n,i):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return this.br(t,i,r,n)}))}br(t,e,r,n,i){n||(n=e.byteLength);const s=this.Pr(e,t,r,n),o=[];for(let r=0;r<s.length;r++){let n;if("b3dm"===s[r].magic)n=new Ln(this.o,this.gr);else if("i3dm"===s[r].magic)n=new Pn(this.o,this.gr);else if("pnts"===s[r].magic)n=new kn;else{if("cmpt"!==s[r].magic){console.warn("Unsupported magic in CMPT tile:",s[r].magic);continue}n=new Vn(this.o,this.gr)}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})))}Pr(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=Te(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=Ln,t.CMPTLoader=Vn,t.Geo3DTilesLayer=vn,t.Geo3DTilesUtil=C,t.Geo3DTransform=de,Object.defineProperty(t,"t",{value:!0}),"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.18.2")}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @maptalks/3dtiles v0.18.
|
|
2
|
+
* @maptalks/3dtiles v0.18.2
|
|
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.68.1
|
|
9
9
|
* LICENSE : UNLICENSED
|
|
10
10
|
* (c) 2016-2022 maptalks.com
|
|
11
|
-
*/const be=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")},Ie=be(),Ne=Ie.gl_trans__coders=Ie.gl_trans__coders||{};function Se(t,e){if(e)for(let r=0;r<e.length;r++){t[e[r].id||e[r].index]=e[r]}}Ne.inject=function(t){const e=t.toString(),r=e.indexOf("{")+1,n=e.substring(0,r),i=Ie.gl_trans__coders=Ie.gl_trans__coders||{};let s=`${n}\n const _____getGlobal = ${be.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},Ne.registerTranscoder=function(t,e){Ne[t]=e},Ne.getTranscoder=function(t){return Ne[t]};const Oe=[];class xe{constructor(t,e,r,n){this.St=t,this.k=e,this.Ot=n,this.xt=r.version,t.indexOf("i3s:tileset:")<0?(this.xt<=1.6?this.wt="root":this.wt=0,r.version=this.xt):(this.wt=t.substring("i3s:tileset:".length),this.xt>1.6&&(this.wt=parseInt(this.wt))),this.St=t,this.Mt=r}load(){const t=this.Mt,e=t.layerScene.baseUrl;if(this.xt<=1.6)return t[this.wt]&&t[this.wt].lodSelection?(this.Ct=t[this.wt],this.vt()):new Promise((r=>{let n=e+"/nodes/"+this.wt;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.Ot(this.k,n,(()=>{this.Ct=t[this.wt],r(this.vt())}))}));if(this.xt>=1.7){if(t[this.wt])return this.Ct=t[this.wt],this.vt();const r=Math.floor(this.wt/t.nodesPerPage);return new Promise((n=>{let i=e+"/nodepages/"+r;t.layerScene.eslpk&&(i+=".json"),this.Ot(this.k,i,(()=>{this.Ct=t[this.wt],n(this.vt())}))}))}return null}getTileset(){return this.Ut}getChildrenURL(){return this.Bt}vt(){const t=this.Mt,e=t.layerScene.baseUrl,r=this.Ct.children,n=[],i={};if(r)for(let s=0;s<r.length;s++)if(this.xt<=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.Ot(this.k,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.Ot(this.k,n,(()=>{r()}))})),n.push(i[a]))}return n.length?Promise.all(n).then((()=>this.Lt())):this.Lt()}Lt(){return Promise.resolve(this.Pt())}Dt(t){Se(this.Mt,t)}Pt(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.Ft(this.Ct,!0)}}Ft(t){const e=this.xt,r=this.Mt,n=t;var i,s=n.obb,o=n.mbs,a={};if(o)i=we([],o[0],o[1],o[2]),a.sphere=[...i,o[3]];else if(s){const t=function(t,e,r){const n=T.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=we([],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];d.set(Oe,e,r,n);const o=d.len(Oe);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 u=16*c;const h=E.identity([]),_=n.children;var m;if(_){m=[];const t=this.Mt;for(let r=0;r<_.length;r++){const n=e<=1.6?_[r].id:_[r];if(!t[n]){m=null;break}m.push(this.Ft(t[n]))}}var A={refine:"REPLACE",boundingVolume:a,transform:h,geometricError:u};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&&!m?A.content={uri:"i3s:tileset:"+(t.id||t.index)}:n.mesh&&(A.content={uri:"i3s:mesh:"+(t.id||t.index)}),m&&m.length&&(A.children=m),A}getJSON(){return this.Ct}}function we(t,e,r,n){return K(t,g(e),g(r),n)}const Me=!!Ne.ktx2,Ce=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 Ue(t){return t.indexOf("i3s:mesh")>=0}const Be="i3s:mesh:".length;function Le(t,e,r,n,i){const s=e.layerScene.eslpk,o=function(t,e){const r=e.substring(Be);return t>=1.7?parseInt(r):r}(e.version,t),a=e[o],c=e.layerScene.baseUrl,l=[];let f=!1;const u=Ce;let h,_;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{h=a.mesh.geometry,_=a.mesh.material;const t=e.layerScene.geometryDefinitions[h.definition],{geometryBuffers:o}=t;f=n&&2===o.length;const u=Ne.draco&&f?o[1]:o[0],d=Ne.draco&&f?1:0;let E=c+`/nodes/${h.resource}/geometries/`+d;s&&(E+=".bin");const T={geometry:{url:E,info:u}};if(i&&ve&&f&&!Ne.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 Pe(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:u}}function Pe(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=De(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])&&Pe(t[o],e,r,n,i,s)}function De(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&&Me)return t[r]}return null}const Fe=[];class Ge extends t.renderer.CanvasRenderer{constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new G(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.Gt={},this.kt=[],this.Ot=this.Ht.bind(this)}getAnalysisMeshes(){if(!this.painter)return Fe;const t=this.painter.getPaintedMeshes();if(!t)return Fe;const e=[],{b3dmMeshes:r,pntsMeshes:n,i3dmMeshes:i}=t;return r.length&&U(e,r),n.length&&U(e,n),i.length&&U(e,i),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.kt.length||super.needToRedraw())}drawOnInteracting(t,e,r){this.draw(e,r)}draw(t,e){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.zt(),this.Vt();const{selectedTiles:o,leaves:a,requests:c}=this.Xt(n,i);c.length&&this.loadTiles(c),this.Yt(o,a,e),this.Zt(),c.length||this.completeRender()}Xt(t,e){let r=[];this.Kt();let n=0;const i=this.Wt(),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.jt(c.id)?(n++,l=a=!0,this.tilesLoading[c.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=a=!0),o=!0,i.selected=!0,i.data=f):this.painter.has(c)||(l=a=!0,r.push(c)),!l)continue;if(this.qt(i))o=!0;else{this.$t(i).length&&(o=!0)}}let c=[],l={};if(o&&({selectedTiles:c,leaves:l}=this.Jt(t)),r.length>1&&(r.sort(ke),i)){const t=i-n;r=t>0?r.slice(0,t):[]}return{loading:a,requests:r,selectedTiles:c,leaves:l}}Jt(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.Qt===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.Qt=i.length}for(let t=0;t<o.length;t++)i.push(o[t])}return{selectedTiles:e,leaves:r}}qt(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}$t(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const r=t.te+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.ee(i[s],t);r.selected=!0,r.data=this.tileCache.get(o),t.children.push(r),e.push(r)}else i[s].te<=r&&n.push(i[s])}}return e}Yt(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=r&&r.renderTarget,s=r&&r.sceneFilter,o=this.painter.paint(t,e,s,i);this.layer.options.debug&&this.painter.paintRegion(t,{color:this.layer.options.debugOutline},s,i),this.onDrawTileEnd(n),o&&this.layer.fire("canvasisdirty",{renderCount:o})}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(C(e)){const r=v(e);return void this.re(e,r,t)}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const r=t.k,n=this.ne[r];return new xe(e,r,n,this.Ot).load().then((r=>{this.onTilesetLoad(r,t,e)}))}t&&-1===e.indexOf("http://")&&-1===e.indexOf("https://")&&!Ue(e)&&(e=t.baseUrl+e);const r=this.layer.options.services[t.k];if(r.ajaxInMainThread){let n=r.urlParams;n&&(n=(e.indexOf("?")>0?"&":"?")+n);let i=_.getArrayBuffer(e+(n||""),r.fetchOptions);const s=i.xhr;i=i.then((r=>{delete this.Gt[e],r?this.re(e,r.data,t):this.onTileError(null,t)})).catch((r=>{delete this.Gt[e],this.onTileError(r,t)})),this.Gt[e]=s}else this.re(e,null,t)}re(t,e,n){let i=this.ie;i||(i=r.Util.getSupportedFormats(this.gl.gl||this.gl),this.ie=i);const s=this.layer.options.services[n.k];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.k,upAxis:n.ft,transform:n.matrix,supportedFormats:i};if(Ue(t)){const e=this.ne[n.k];if(o.i3sInfo=Le(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.kt.push({data:r,tile:n}):this.onTilesetLoad(r,n,t)}))}Vt(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let r=0;for(;this.kt.length&&(r<e||!t.isInteracting());){const{data:t,tile:e}=this.kt.shift(),{magic:n}=t;"b3dm"===n?this.painter.createB3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.se(t,e,r,n)})):"pnts"===n?this.painter.createPntsMesh(t,e.id,e,((r,{mesh:n})=>{this.se(t,e,r,n)})):"i3dm"===n?this.painter.createI3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.se(t,e,r,n)})):"cmpt"===n&&this.painter.createCMPTMesh(t,e.id,e,((r,{mesh:n})=>{this.se(t,e,r,n)})),r++}}se(t,e,r,n){if(r)this.onTileError(r,e);else{const r=this.oe(n);e.memorySize=r,this.onTileLoad(t,e)}}oe(t){let e=0;if(Array.isArray(t))for(let r=0;r<t.length;r++)t[r]&&(e+=this.oe(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.ae(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.ce(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.le(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}le(e,r){const n={loadTime:t.Util.now(),current:!0,error:r,node:e};this.tileCache.add(e.id,n)}ae(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.k].ajaxInMainThread){const t=this.Gt[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.Gt[e]}Kt(){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.fe(this.canvas,e)),this.regl=this.regl||c({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 ge(this.regl,t)}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new P("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let r=this.layer.options||{};r=p({},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.Zt(!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}Zt(t){this.ue||(this.ue=Date.now());const e=Date.now();if(t||!(e-this.ue<this.layer.options.retireInterval)){this.ue=e;for(const e in this.tilesLoading){const r=this.tilesLoading[e];!t&&r.current||this.abortTileLoading(r)}}}Wt(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}fe(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}jt(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 _t(t,e,0,r)}zt(){if(!this.he)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const r=[];for(const n in this.he){const i=this.he[n];if("pending"===i.status)continue;i.status="pending";const s=i.rootIdx;if(r.push(_.getJSON(n).then((t=>{delete this.he[n];const e=this.ne[s];if(e){t.nodes?Se(e,t.nodes):(e[t.id]=t,Se(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)}Ht(t,e,r){this.he||(this.he={}),this.he[e]=this.he[e]||[],this.he[e].rootIdx=t,this.he[e].push(r),this.setToRedraw()}ce(t,e,r){this.ne||(this.ne=[]);const n=e.k;this.ne[n]||(this.ne[n]={});const i=this.ne[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 xe(n,e,i,s).load()}(t,n,0,r,i,this.Ot).then((t=>{this.onTilesetLoad(t,e,r)}))}pick(t,e,r){return this.painter?this.painter.pick(t,e,r&&r.tolerance):[]}}function ke(t,e){return t.j-e.j}function He(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=d.subtract(Ve,r,t),i=He(Xe,e,0),s=He(Ye,e,1),o=He(Ze,e,2),a=d.len(i),c=d.len(s),l=d.len(o);d.normalize(i,i),d.normalize(s,s),d.normalize(o,o);var f=Ke;f[0]=d.dot(n,i),f[1]=d.dot(n,s),f[2]=d.dot(n,o);var u,h=0;f[0]<-a?h+=(u=f[0]+a)*u:f[0]>a&&(h+=(u=f[0]-a)*u);f[1]<-c?h+=(u=f[1]+c)*u:f[1]>c&&(h+=(u=f[1]-c)*u);f[2]<-l?h+=(u=f[2]+l)*u:f[2]>l&&(h+=(u=f[2]-l)*u);return h}(t,e,r))}const Ve=[],Xe=[],Ye=[],Ze=[],Ke=[];const We=2*Math.PI;class je{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+=We,r<0&&(r+=We)),(r>i||at(r,i,1e-14))&&(r<s||at(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 qe=[0,0,1];function $e(t,e){return K(e,t[0],t[1],t[2])}class Je{constructor(t,e){this.normal=i.copy([],t),this.distance=e}static fromPointNormal(t,e,r){var n=-i.dot(e,t);return i.copy(r.normal,e),r.distance=n,r}}const Qe=[],tr=[],er=[],rr=[],nr=[],ir=[],sr=[],or=[],ar=[],cr=[],lr=new Je([1,0,0],0),fr=[];class ur{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new je(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){var r,n,s,o=0;if(!je.contains(this.rectangle,e)){var a=this.southwestCornerCartesian,c=this.northeastCornerCartesian,l=this.westNormal,f=this.southNormal,u=this.eastNormal,h=this.northNormal,_=i.subtract(fr,t,a),d=i.dot(_,l),E=i.dot(_,f),T=i.subtract(fr,t,c),m=i.dot(T,u),A=i.dot(T,h);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>(s=this.maximumHeight)){var p=r-s;o+=p*p}else if(r<n){var y=n-r;o+=y*y}return Math.sqrt(o)}computeBox(t){const e=this;$e(je.southwest(t,tr),e.southwestCornerCartesian),$e(je.northeast(t,tr),e.northeastCornerCartesian),Qe[0]=t.west,Qe[1]=.5*(t.south+t.north),Qe[2]=0;var r=$e(Qe,er),n=i.cross(nr,r,qe);i.normalize(e.westNormal,n),Qe[0]=t.east;var s=$e(Qe,or),o=i.cross(nr,qe,s);i.normalize(e.eastNormal,o);var a,c=i.subtract(nr,r,s),l=i.normalize(rr,c),f=t.south;if(f>0){Qe[0]=.5*(t.west+t.east),Qe[1]=f;var u=$e(Qe,ar);i.copy(cr,l);var h=Je.fromPointNormal(e.southwestCornerCartesian,e.westNormal,lr);hr(ar,cr,h,e.southwestCornerCartesian),a=it(u,ir)}else a=st(je.southeast(t,tr),ir);var _=i.cross(sr,a,c);i.normalize(e.southNormal,_);var d,E=t.north;if(E<0){Qe[0]=.5*(t.west+t.east),Qe[1]=E;var T=$e(Qe,ar);i.scale(cr,l,-1);var m=Je.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,lr);hr(ar,cr,m,e.northeastCornerCartesian),d=it(T,ir)}else d=st(je.northwest(t,tr),ir);var A=i.cross(sr,c,d);i.normalize(e.northNormal,A)}}function hr(t,e,r,n){var s=t,o=e,a=r.normal,c=i.dot(a,o);if(!(Math.abs(c)<1e-15)){var l=(-r.distance-i.dot(a,s))/c;if(!(l<0))return n=i.scale(n,o,l),i.add(n,s,n)}}const _r=new t.Extent(0,0,0,0),dr=new t.Extent(0,0,0,0),Er=[],Tr=[],mr=[],Ar=[],pr=new t.Point(0,0),yr=[],Rr=new t.Coordinate(0,0),gr=n.identity([]);class br extends t.Layer{constructor(t,e){super(t,e),this._e(),this.Gt={},this.de=[]}_e(){let t=this.options.services.map((t=>t.url));this.Ee=t.map(((t,e)=>function(t,e){t=I(t);return{baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:n.identity([]),k:e,te:0}}(t,e))),this.fire("rootready",{roots:this.Ee.slice(0)})}getTileUrl(t){return t}getExtent(e){if(!e&&0!==e){const e=new t.Extent;for(let t=0;t<this.Ee.length;t++)if(this.Ee[t].boundingVolume){const r=this.boundingVolumeToExtent(this.Ee[t]);e._combine(r)}return e}return this.Ee[e]&&this.Ee[e].boundingVolume?this.boundingVolumeToExtent(this.Ee[e]):null}boundingVolumeToExtent(e){const r=e.boundingVolume.Te?gr:e.matrix,n=this.getMap();if(e.boundingVolume.region){const r=e.boundingVolume.region;return new t.Extent(b(r[0]),b(r[1]),b(r[2]),b(r[3]))}if(e.boundingVolume.sphere){const s=e.boundingVolume.sphere,o=Q([],i.transformMat4([],s,r)),a=s[3],c=n.locate(o,-a,a),l=n.locate(o,a,-a);return new t.Extent(c,l)}if(e.boundingVolume.box){const o=e.boundingVolume.box,a=i.transformMat4([],o,r),c=new t.Coordinate(Q([],a)),l=o.slice(3);s.multiply(l,s.fromMat4([],e.matrix),l);const f=i.length(l.slice(0,3)),u=i.length(l.slice(3,6)),h=i.length(l.slice(6,9)),_=Math.max(f,u,h),d=n.locate(c,-_,_),E=n.locate(c,_,-_);return new t.Extent(d,E)}return null}getRootTiles(){return this.Ee}getTiles(){const t=this.getRenderer();if(!t.ready)return this.me(),{tiles:Ar};const e=this.getMap(),r=e.cameraPosition;let n,s;if(e.getGLZoom)s=e.pointToDistance(r[2],0,e.getGLZoom()),Rr.set(r[0],r[1]),n=e.pointToCoord(Rr,e.getGLZoom());else{const t=e.getGLRes();s=e.pointAtResToDistance(r[2],0,t),Rr.set(r[0],r[1]),n=e.pointAtResToCoord(Rr,t)}this.Ae=this.Ae||[],i.set(this.Ae,g(n.x),g(n.y),s),this.pe=K(this.pe||[],this.Ae[0],this.Ae[1],this.Ae[2]),this.ye=2*Math.tan(.5*g(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const l=[];for(let e=0;e<this.Ee.length;e++){let r=1/0;const n=[this.Ee[e]],i=this.Re(e);for(;n.length>0;){const e=n.pop();for(e.id||this.ge(e);c.level>=e.te;)c=c.parent;const s=this.be(e,i,o);if(s<1){let t=c;for(;t&&!t.content;)t=t.parent;0===s&&t&&t.content&&this.Ie(l,t);if(!1===this.options.services[e.k].alwaysShow)continue;if(!(0===s&&e.te<=r))continue;e.content&&(r=e.te)}e.j<1/0&&this.Ne(e);const a=this.ee(e,c);c.children.push(a);const f=e.children,u=f&&f.length,h=a.content;if(!u&&h&&this.Ie(l,a),u){h&&"add"===e.refine&&this.Ie(l,a),c=a;const r=f[0].parent;let i=!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;i=!0}else{i=!0,f[s].parent=e,f[s].ft=e.ft,f[s].baseUrl=e.baseUrl;const t=f[s].content&&(f[s].content.url||f[s].content.uri);t&&(C(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))}n.push(f[s])}!i&&h&&this.Ie(l,a)}}}return{root:a,tiles:l}}Ie(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 Ir(r,e);if(r.box)return 0===Nr(r,e)}return!1}(this.Ae,this.pe,r)||t.push(e)}ee(t,e){return{id:t.id,node:t,children:[],level:t.te,parent:e,content:t.content&&t.content.url}}ge(e){e.id=t.Util.GUID(),e.matrix=e.transform||n.identity([]),e.Se=this.Oe(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.k=e.parent.k,void 0===e.te&&(e.te=e.parent.te+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.xe(e)}xe(t){const e=t.boundingVolume;if(!e||e.Te)return;const r=this.options.services[t.k].heightOffset||0,s=this.options.offset,o=y(s)||s[0]||s[1];if(!t.boundingVolume||!r&&n.exactEquals(t.matrix,gr)&&!o)return;const{region:a,box:c,sphere:l}=e;if(a){const t=this.we([b(a[0]),b(a[1])]);a[0]=g(t.x),a[1]=g(t.y);const e=this.we([b(a[2]),b(a[3])]);a[2]=g(e.x),a[3]=g(e.y),a[4]+=r,a[5]+=r}else if(c||l){const e=c||l,n=i.transformMat4(Er,e,t.matrix),s=Q(Tr,n),o=this.we([s[0],s[1]]);s[0]=o.x,s[1]=o.y,s[2]+=r,K(e,g(s[0]),g(s[1]),s[2])}e.Te=!0}Oe(t){return void 0===t.geometricError||!t.boundingVolume}Ne(t){let e=t.parent;for(;e&&e.Se&&!(e.j<=t.j);)e.j=t.j,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.k],s=(t.asset&&t.asset.gltfUpAxis||e&&e.ft||i.upAxis||"Y").toUpperCase();t.root.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const o=r.indexOf("realspace/")>-1;0===e.te&&(t.asset&&t.asset.s3mType&&o||i.isSuperMapiServer)&&(t.root.baseUrl+="data/path/");const a=t.asset.i3s;if(t.root.ft=s,e){const r=e.boundingVolume;p(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.xe(e),e.Me=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.Se=this.Oe(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||C(s)||-1!==s.indexOf("http://")||-1!==s.indexOf("https://")||(e.content.url=e.baseUrl+s)}this.me(),this.fire("loadtileset",{tileset:t,index:e.k,url:r})}be(t,e,r){if(t.j=1/0,0===t.te||t.Se)return 1;if(!this.Ce(t,e,r))return-1;if(0===t.geometricError)return 1;let n=this.options.services[t.k].maximumScreenSpaceError;null==n&&(n=8);let i=this.ve(t);return 0===i&&t.parent&&(i=.5*(t.parent.Ue||0)),i>=n?1:0}nt(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)}Ce(e,r,i){const o=e.id;let a=this.de[o];const{boundingVolume:c}=e,h=c.sphere,_=c.region,d=c.box;if(!a){let r,i,c;if(_){r=_r.set(b(_[0]),b(_[1]),b(_[2]),b(_[3]));const t=r.getCenter(),e=this.Be(t);r=r.convertTo((t=>this.nt(t,pr)),dr),c=_[4],i=_[5],a=this.de[o]=[[r.xmin,r.ymin,c*e[2]],[r.xmax,r.ymax,i*e[2]]],a.center=t}else if(h){const e=Q(Er,h),r=new t.Coordinate(e),n=this.nt(r,pr).toArray(),i=this.Be(r);n.push(e[2]*i[2]),a=this.de[o]=[n,h[3]*i[2]],a.center=r}else if(d){const r=Q(Er,d),i=new t.Coordinate(r),c=this.nt(i,pr).toArray(),l=this.Be(i);c.push(r[2]*l[2]);const f=d.slice(3);n.exactEquals(e.matrix,gr)||s.multiply(f,s.fromMat4(yr,e.matrix),f);for(let t=0;t<f.length;t++)f[t]*=l[t%3],d[3+t]=f[t];a=this.de[o]=[...c,...f],a.center=i}}if(r){if(_)_r.xmin=a[0][0],_r.ymin=a[0][1],_r.xmax=a[1][0],_r.ymax=a[1][1];else if(h){const t=a[2];_r.xmin=a[0][0]-t,_r.ymin=a[0][1]-t,_r.xmax=a[0][0]+t,_r.ymax=a[0][1]+t}else if(d){const t=a[1],e=a[2];_r.xmin=a[0][0]-t,_r.ymin=a[0][1]-e,_r.xmax=a[0][0]+t,_r.ymax=a[0][1]+e}if(!r.intersects(_r))return!1}return _?l(i,a):h?f(i,a):!!d&&u(i,a)}Be(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,i.set(mr,r.x/100*1.01,r.y/100*1.01,n),mr}we(e){Array.isArray(e)&&(e=new t.Coordinate(e));let r=this.options.offset;if(y(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}Re(e){const r=this.options.services[e].maxExtent;if(!r)return null;const n=this.Ee[e];return n.maxExtent||(n.maxExtent=new t.Extent(r).convertTo((t=>this.nt(t)))),n.maxExtent}ve(t){const e=this.ye,r=t.geometricError;if(0===r)return 0;const n=this.getMap();let i;t.boundingVolume.region?i=function(t,e,r){t.Le||(t.Le=new ur(t.boundingVolume.region));return t.Le.distanceToCamera(e,r)}(t,this.pe,this.Ae):t.boundingVolume.sphere?i=Ir(t.boundingVolume,this.pe):t.boundingVolume.box&&(i=Nr(t.boundingVolume,this.pe));const s=Math.max(Math.abs(i),1e-7),o=r*n.height/(s*e);return t.j=i,t.Ue=o,o}me(){const t=this.getRenderer();t&&t.setToRedraw()}Et(t){return this.de[t]}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)}}function Ir(t,e){const r=t.sphere,n=i.dist(r,e),s=t.sphere[3];return n<s?0:n-s}function Nr(t,e){const r=t.box;return ze(i.set(Er,r[0],r[1],r[2]),s.set(yr,r[3],r[4],r[5],r[6],r[7],r[8],r[9],r[10],r[11]),e)}br.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]}),br.registerRenderer("gl",Ge),br.registerJSONType("Geo3DTilesLayer");class Sr{constructor(t,e,r){this.Pe=t,this.De=e||h,this.ie=r,this.Fe={"image/crn":Ne.crn&&Ne.crn(),"image/ktx2":Ne.ktx2&&Ne.ktx2(),"image/cttf":Ne.ktx2&&Ne.ktx2(),"draco":Ne.draco&&Ne.draco()}}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.Ge(t,e,r,n,i)):_.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Ge(t,i,r,n)}))}Ge(t,e,r,n,i){const s=i&&i.maxTextureSize,o=this.ke(e,r,n,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.De(a,o.glb,{transferable:!0,requestImage:this.Pe,decoders:this.Fe,supportedFormats:this.ie,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}}))}ke(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),u=28+e;l>=570425344?(u-=8,o=a,l=c,f=0,a=0,c=0):f>=570425344&&(u-=4,o=l,l=a,f=c,a=0,c=0);const h=[t];let _,d,E;if(a>0?(_=ft(t,u,a),u+=a,o=_.BATCH_LENGTH):_={"BATCH_LENGTH":o},c>0&&(u+=c),l>0&&(d=ut(t,u,l),u+=l,f>0)){const e=ht(0,u,f);E=t.slice(e.offset,e.offset+e.byteLength),u+=f,h.push(E)}const T=_.BATCH_LENGTH,m={};if(_&&_.BATCH_ID){m.BATCH_ID=dt(_.BATCH_ID,t,undefined.offset,T);const e=m.BATCH_ID.array&&m.BATCH_ID.array.buffer;e&&h.indexOf(e)<0&&h.push(e)}return{count:o,transferables:h,featureTable:_,batchTable:d,batchTableBin:E,b3dm:m,glb:{buffer:t,byteOffset:u,byteLength:i.byteLength+i.byteOffset-u}}}He(){return null}}class Or{constructor(t,e,r,n){this.Pe=t,this.De=e||h,this.ie=r,this.Fe={"image/crn":Ne.crn&&Ne.crn(),"image/ktx2":Ne.ktx2&&Ne.ktx2(),"image/cttf":Ne.ktx2&&Ne.ktx2(),"draco":Ne.draco&&Ne.draco()},this.ze=n}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.Ge(t,e,r,n,i)):_.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Ge(t,i,r,n)}))}Ge(t,e,r,n,i){return this.Ve(t,e,r,n,i).then((({gltf:i,transferables:s})=>{const o=this.Xe(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})}))}Ve(t,e,r,n,i){const s=i&&i.maxTextureSize,o={transferable:!0,requestImage:this.Pe,decoders:this.Fe,supportedFormats:this.ie,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?_.getArrayBuffer(n,{}).then((t=>this.Ye(n,{buffer:t.data,byteOffset:0},o))):_.getJSON(n,{}).then((t=>this.Ye(n,t,o)))}{const n={buffer:e,byteOffset:c+r,byteLength:a.byteLength-c};return this.Ye(t,n,o)}}Ye(t,e,r){const n=t.substring(0,t.lastIndexOf("/")),i=new this.De(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}}))}Xe(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}=gt(i,32+e,o),u={},h=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;u.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,r=a.QUANTIZED_VOLUME_SCALE,{byteOffset:n}=a.POSITION_QUANTIZED;u.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.Ze(new Uint16Array(t,n+c.offset,3*h),e,r)},o.push(u.POSITION.array.buffer)}if(a.BATCH_ID){u.BATCH_ID=dt(a.BATCH_ID,t,c.offset,h);const e=u.BATCH_ID.array&&u.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;u.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,u.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;u.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.Ke(new Uint16Array(t,e+c.offset,2*h))},o.push(u.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,u.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.Ke(new Uint16Array(t,e+c.offset,2*h))},o.push(u.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;u.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,h).slice()},o.push(u.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;u.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.SCALE_NON_UNIFORM.array.buffer)}return{count:h,batchTable:l,batchTableBin:f,featureTable:a,i3dm:u,transferables:o}}Ke(t){const e=t.length/2,r=new Float32Array(3*e),n=[];for(let i=0;i<e;i++)xr(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}Ze(t,e,r){return Rt(new Float32Array(t.length),t,e,r)}He(){return null}}function xr(t,e,r,n){if(t[0]=wr(e,n),t[1]=wr(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]))*Mr(e),t[1]=(1-Math.abs(e))*Mr(t[1])}return d.normalize(t,t)}function wr(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 Mr(t){return t<0?-1:1}class Cr{constructor(){}load(t,e,r=0,n=0){return e?(n||(n=e.byteLength),this.Ge(t,e,r,n)):_.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Ge(t,i,r,n)}))}Ge(t,e,r,n){return this.We(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}))}We(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}=gt(i,e+28,o),u=a.QUANTIZED_VOLUME_OFFSET,h=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.je||(this.je=Ne.draco()),this.je(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.qe(t,e.attributes,c.offset,_,o,u,h);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:yt(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?n.BATCH_ID=dt(a.BATCH_ID,t,c.offset,_):n.BATCH_ID=vr(_);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.qe(t,a,c.offset,_,o,u,h);if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?T.BATCH_ID=dt(a.BATCH_ID,t,c.offset,_):T.BATCH_ID=vr(_);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})}qe(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.Ze(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}Ze(t,e,r){return Rt(new Float32Array(t.length),t,e,r)}He(){return null}}function vr(t){const e=M(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:yt(e),array:r}}class Ur{constructor(t,e){this.Pe=t,this.De=e||h}load(t,e,r=0,n=0,i){return e?this.Ge(t,e,r,n,i):_.getArrayBuffer(t,{}).then((e=>{const i=e.data;return this.Ge(t,i,r,n)}))}Ge(t,e,r,n,i){n||(n=e.byteLength);const s=this.$e(e,t,r,n),o=[];for(let r=0;r<s.length;r++){let n;if("b3dm"===s[r].magic)n=new Sr(this.Pe,this.De);else if("i3dm"===s[r].magic)n=new Or(this.Pe,this.De);else if("pnts"===s[r].magic)n=new Cr;else{if("cmpt"!==s[r].magic){console.warn("Unsupported magic in CMPT tile:",s[r].magic);continue}n=new Ur(this.Pe,this.De)}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})))}$e(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=ct(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(m);t.registerWorkerAdapter("@maptalks/3dtiles",r)}else t.registerWorkerAdapter("@maptalks/3dtiles",(function(){return e.transcoders.inject(m)}))}else t.registerWorkerAdapter("@maptalks/3dtiles",m);export{Sr as B3DMLoader,Ur as CMPTLoader,br as Geo3DTilesLayer,B as Geo3DTilesUtil,ot as Geo3DTransform};"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.18.1");
|
|
11
|
+
*/const be=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")},Ie=be(),Ne=Ie.gl_trans__coders=Ie.gl_trans__coders||{};function Se(t,e){if(e)for(let r=0;r<e.length;r++){t[e[r].id||e[r].index]=e[r]}}Ne.inject=function(t){const e=t.toString(),r=e.indexOf("{")+1,n=e.substring(0,r),i=Ie.gl_trans__coders=Ie.gl_trans__coders||{};let s=`${n}\n const _____getGlobal = ${be.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},Ne.registerTranscoder=function(t,e){Ne[t]=e},Ne.getTranscoder=function(t){return Ne[t]};const Oe=[];class xe{constructor(t,e,r,n){this.St=t,this.k=e,this.Ot=n,this.xt=r.version,t.indexOf("i3s:tileset:")<0?(this.xt<=1.6?this.wt="root":this.wt=0,r.version=this.xt):(this.wt=t.substring("i3s:tileset:".length),this.xt>1.6&&(this.wt=parseInt(this.wt))),this.St=t,this.Mt=r}load(){const t=this.Mt,e=t.layerScene.baseUrl;if(this.xt<=1.6)return t[this.wt]&&t[this.wt].lodSelection?(this.Ct=t[this.wt],this.vt()):new Promise((r=>{let n=e+"/nodes/"+this.wt;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.Ot(this.k,n,(()=>{this.Ct=t[this.wt],r(this.vt())}))}));if(this.xt>=1.7){if(t[this.wt])return this.Ct=t[this.wt],this.vt();const r=Math.floor(this.wt/t.nodesPerPage);return new Promise((n=>{let i=e+"/nodepages/"+r;t.layerScene.eslpk&&(i+=".json"),this.Ot(this.k,i,(()=>{this.Ct=t[this.wt],n(this.vt())}))}))}return null}getTileset(){return this.Ut}getChildrenURL(){return this.Bt}vt(){const t=this.Mt,e=t.layerScene.baseUrl,r=this.Ct.children,n=[],i={};if(r)for(let s=0;s<r.length;s++)if(this.xt<=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.Ot(this.k,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.Ot(this.k,n,(()=>{r()}))})),n.push(i[a]))}return n.length?Promise.all(n).then((()=>this.Lt())):this.Lt()}Lt(){return Promise.resolve(this.Pt())}Dt(t){Se(this.Mt,t)}Pt(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.Ft(this.Ct,!0)}}Ft(t){const e=this.xt,r=this.Mt,n=t;var i,s=n.obb,o=n.mbs,a={};if(o)i=we([],o[0],o[1],o[2]),a.sphere=[...i,o[3]];else if(s){const t=function(t,e,r){const n=T.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=we([],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];d.set(Oe,e,r,n);const o=d.len(Oe);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 u=16*c;const h=E.identity([]),_=n.children;var m;if(_){m=[];const t=this.Mt;for(let r=0;r<_.length;r++){const n=e<=1.6?_[r].id:_[r];if(!t[n]){m=null;break}m.push(this.Ft(t[n]))}}var A={refine:"REPLACE",boundingVolume:a,transform:h,geometricError:u};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&&!m?A.content={uri:"i3s:tileset:"+(t.id||t.index)}:n.mesh&&(A.content={uri:"i3s:mesh:"+(t.id||t.index)}),m&&m.length&&(A.children=m),A}getJSON(){return this.Ct}}function we(t,e,r,n){return K(t,g(e),g(r),n)}const Me=!!Ne.ktx2,Ce=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 Ue(t){return t.indexOf("i3s:mesh")>=0}const Be="i3s:mesh:".length;function Le(t,e,r,n,i){const s=e.layerScene.eslpk,o=function(t,e){const r=e.substring(Be);return t>=1.7?parseInt(r):r}(e.version,t),a=e[o],c=e.layerScene.baseUrl,l=[];let f=!1;const u=Ce;let h,_;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{h=a.mesh.geometry,_=a.mesh.material;const t=e.layerScene.geometryDefinitions[h.definition],{geometryBuffers:o}=t;f=n&&2===o.length;const u=Ne.draco&&f?o[1]:o[0],d=Ne.draco&&f?1:0;let E=c+`/nodes/${h.resource}/geometries/`+d;s&&(E+=".bin");const T={geometry:{url:E,info:u}};if(i&&ve&&f&&!Ne.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 Pe(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:u}}function Pe(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=De(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])&&Pe(t[o],e,r,n,i,s)}function De(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&&Me)return t[r]}return null}const Fe=[];class Ge extends t.renderer.CanvasRenderer{constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new G(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.Gt={},this.kt=[],this.Ot=this.Ht.bind(this)}getAnalysisMeshes(){if(!this.painter)return Fe;const t=this.painter.getPaintedMeshes();if(!t)return Fe;const e=[],{b3dmMeshes:r,pntsMeshes:n,i3dmMeshes:i}=t;return r.length&&U(e,r),n.length&&U(e,n),i.length&&U(e,i),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.kt.length||super.needToRedraw())}drawOnInteracting(t,e,r){this.draw(e,r)}draw(t,e){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.zt(),this.Vt();const{selectedTiles:o,leaves:a,requests:c}=this.Xt(n,i);c.length&&this.loadTiles(c),this.Yt(o,a,e),this.Zt(),c.length||this.completeRender()}Xt(t,e){let r=[];this.Kt();let n=0;const i=this.Wt(),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.jt(c.id)?(n++,l=a=!0,this.tilesLoading[c.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=a=!0),o=!0,i.selected=!0,i.data=f):this.painter.has(c)||(l=a=!0,r.push(c)),!l)continue;if(this.qt(i))o=!0;else{this.$t(i).length&&(o=!0)}}let c=[],l={};if(o&&({selectedTiles:c,leaves:l}=this.Jt(t)),r.length>1&&(r.sort(ke),i)){const t=i-n;r=t>0?r.slice(0,t):[]}return{loading:a,requests:r,selectedTiles:c,leaves:l}}Jt(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.Qt===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.Qt=i.length}for(let t=0;t<o.length;t++)i.push(o[t])}return{selectedTiles:e,leaves:r}}qt(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}$t(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const r=t.te+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.ee(i[s],t);r.selected=!0,r.data=this.tileCache.get(o),t.children.push(r),e.push(r)}else i[s].te<=r&&n.push(i[s])}}return e}Yt(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=r&&r.renderTarget,s=r&&r.sceneFilter,o=this.painter.paint(t,e,s,i);this.layer.options.debug&&this.painter.paintRegion(t,{color:this.layer.options.debugOutline},s,i),this.onDrawTileEnd(n),o&&this.layer.fire("canvasisdirty",{renderCount:o})}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(C(e)){const r=v(e);return void this.re(e,r,t)}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const r=t.k,n=this.ne[r];return new xe(e,r,n,this.Ot).load().then((r=>{this.onTilesetLoad(r,t,e)}))}t&&-1===e.indexOf("http://")&&-1===e.indexOf("https://")&&!Ue(e)&&(e=t.baseUrl+e);const r=this.layer.options.services[t.k];if(r.ajaxInMainThread){let n=r.urlParams;n&&(n=(e.indexOf("?")>0?"&":"?")+n);let i=_.getArrayBuffer(e+(n||""),r.fetchOptions);const s=i.xhr;i=i.then((r=>{delete this.Gt[e],r?this.re(e,r.data,t):this.onTileError(null,t)})).catch((r=>{delete this.Gt[e],this.onTileError(r,t)})),this.Gt[e]=s}else this.re(e,null,t)}re(t,e,n){let i=this.ie;i||(i=r.Util.getSupportedFormats(this.gl.gl||this.gl),this.ie=i);const s=this.layer.options.services[n.k];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.k,upAxis:n.ft,transform:n.matrix,supportedFormats:i};if(Ue(t)){const e=this.ne[n.k];if(o.i3sInfo=Le(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.kt.push({data:r,tile:n}):this.onTilesetLoad(r,n,t)}))}Vt(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let r=0;for(;this.kt.length&&(r<e||!t.isInteracting());){const{data:t,tile:e}=this.kt.shift(),{magic:n}=t;"b3dm"===n?this.painter.createB3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.se(t,e,r,n)})):"pnts"===n?this.painter.createPntsMesh(t,e.id,e,((r,{mesh:n})=>{this.se(t,e,r,n)})):"i3dm"===n?this.painter.createI3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.se(t,e,r,n)})):"cmpt"===n&&this.painter.createCMPTMesh(t,e.id,e,((r,{mesh:n})=>{this.se(t,e,r,n)})),r++}}se(t,e,r,n){if(r)this.onTileError(r,e);else{const r=this.oe(n);e.memorySize=r,this.onTileLoad(t,e)}}oe(t){let e=0;if(Array.isArray(t))for(let r=0;r<t.length;r++)t[r]&&(e+=this.oe(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.ae(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.ce(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.le(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}le(e,r){const n={loadTime:t.Util.now(),current:!0,error:r,node:e};this.tileCache.add(e.id,n)}ae(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.k].ajaxInMainThread){const t=this.Gt[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.Gt[e]}Kt(){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.fe(this.canvas,e)),this.regl=this.regl||c({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 ge(this.regl,t)}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new P("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let r=this.layer.options||{};r=p({},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.Zt(!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}Zt(t){this.ue||(this.ue=Date.now());const e=Date.now();if(t||!(e-this.ue<this.layer.options.retireInterval)){this.ue=e;for(const e in this.tilesLoading){const r=this.tilesLoading[e];!t&&r.current||this.abortTileLoading(r)}}}Wt(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}fe(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}jt(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 _t(t,e,0,r)}zt(){if(!this.he)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const r=[];for(const n in this.he){const i=this.he[n];if("pending"===i.status)continue;i.status="pending";const s=i.rootIdx;if(r.push(_.getJSON(n).then((t=>{delete this.he[n];const e=this.ne[s];if(e){t.nodes?Se(e,t.nodes):(e[t.id]=t,Se(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)}Ht(t,e,r){this.he||(this.he={}),this.he[e]=this.he[e]||[],this.he[e].rootIdx=t,this.he[e].push(r),this.setToRedraw()}ce(t,e,r){this.ne||(this.ne=[]);const n=e.k;this.ne[n]||(this.ne[n]={});const i=this.ne[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 xe(n,e,i,s).load()}(t,n,0,r,i,this.Ot).then((t=>{this.onTilesetLoad(t,e,r)}))}pick(t,e,r){return this.painter?this.painter.pick(t,e,r&&r.tolerance):[]}}function ke(t,e){return t.j-e.j}function He(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=d.subtract(Ve,r,t),i=He(Xe,e,0),s=He(Ye,e,1),o=He(Ze,e,2),a=d.len(i),c=d.len(s),l=d.len(o);d.normalize(i,i),d.normalize(s,s),d.normalize(o,o);var f=Ke;f[0]=d.dot(n,i),f[1]=d.dot(n,s),f[2]=d.dot(n,o);var u,h=0;f[0]<-a?h+=(u=f[0]+a)*u:f[0]>a&&(h+=(u=f[0]-a)*u);f[1]<-c?h+=(u=f[1]+c)*u:f[1]>c&&(h+=(u=f[1]-c)*u);f[2]<-l?h+=(u=f[2]+l)*u:f[2]>l&&(h+=(u=f[2]-l)*u);return h}(t,e,r))}const Ve=[],Xe=[],Ye=[],Ze=[],Ke=[];const We=2*Math.PI;class je{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+=We,r<0&&(r+=We)),(r>i||at(r,i,1e-14))&&(r<s||at(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 qe=[0,0,1];function $e(t,e){return K(e,t[0],t[1],t[2])}class Je{constructor(t,e){this.normal=i.copy([],t),this.distance=e}static fromPointNormal(t,e,r){var n=-i.dot(e,t);return i.copy(r.normal,e),r.distance=n,r}}const Qe=[],tr=[],er=[],rr=[],nr=[],ir=[],sr=[],or=[],ar=[],cr=[],lr=new Je([1,0,0],0),fr=[];class ur{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new je(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){var r,n,s,o=0;if(!je.contains(this.rectangle,e)){var a=this.southwestCornerCartesian,c=this.northeastCornerCartesian,l=this.westNormal,f=this.southNormal,u=this.eastNormal,h=this.northNormal,_=i.subtract(fr,t,a),d=i.dot(_,l),E=i.dot(_,f),T=i.subtract(fr,t,c),m=i.dot(T,u),A=i.dot(T,h);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>(s=this.maximumHeight)){var p=r-s;o+=p*p}else if(r<n){var y=n-r;o+=y*y}return Math.sqrt(o)}computeBox(t){const e=this;$e(je.southwest(t,tr),e.southwestCornerCartesian),$e(je.northeast(t,tr),e.northeastCornerCartesian),Qe[0]=t.west,Qe[1]=.5*(t.south+t.north),Qe[2]=0;var r=$e(Qe,er),n=i.cross(nr,r,qe);i.normalize(e.westNormal,n),Qe[0]=t.east;var s=$e(Qe,or),o=i.cross(nr,qe,s);i.normalize(e.eastNormal,o);var a,c=i.subtract(nr,r,s),l=i.normalize(rr,c),f=t.south;if(f>0){Qe[0]=.5*(t.west+t.east),Qe[1]=f;var u=$e(Qe,ar);i.copy(cr,l);var h=Je.fromPointNormal(e.southwestCornerCartesian,e.westNormal,lr);hr(ar,cr,h,e.southwestCornerCartesian),a=it(u,ir)}else a=st(je.southeast(t,tr),ir);var _=i.cross(sr,a,c);i.normalize(e.southNormal,_);var d,E=t.north;if(E<0){Qe[0]=.5*(t.west+t.east),Qe[1]=E;var T=$e(Qe,ar);i.scale(cr,l,-1);var m=Je.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,lr);hr(ar,cr,m,e.northeastCornerCartesian),d=it(T,ir)}else d=st(je.northwest(t,tr),ir);var A=i.cross(sr,c,d);i.normalize(e.northNormal,A)}}function hr(t,e,r,n){var s=t,o=e,a=r.normal,c=i.dot(a,o);if(!(Math.abs(c)<1e-15)){var l=(-r.distance-i.dot(a,s))/c;if(!(l<0))return n=i.scale(n,o,l),i.add(n,s,n)}}const _r=new t.Extent(0,0,0,0),dr=new t.Extent(0,0,0,0),Er=[],Tr=[],mr=[],Ar=[],pr=new t.Point(0,0),yr=[],Rr=new t.Coordinate(0,0),gr=n.identity([]);class br extends t.Layer{constructor(t,e){super(t,e),this._e(),this.Gt={},this.de=[]}_e(){let t=this.options.services.map((t=>t.url));this.Ee=t.map(((t,e)=>function(t,e){t=I(t);return{baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:n.identity([]),k:e,te:0}}(t,e))),this.fire("rootready",{roots:this.Ee.slice(0)})}getTileUrl(t){return t}getExtent(e){if(!e&&0!==e){const e=new t.Extent;for(let t=0;t<this.Ee.length;t++)if(this.Ee[t].boundingVolume){const r=this.boundingVolumeToExtent(this.Ee[t]);e._combine(r)}return e}return this.Ee[e]&&this.Ee[e].boundingVolume?this.boundingVolumeToExtent(this.Ee[e]):null}boundingVolumeToExtent(e){const r=e.boundingVolume.Te?gr:e.matrix,n=this.getMap();if(e.boundingVolume.region){const r=e.boundingVolume.region;return new t.Extent(b(r[0]),b(r[1]),b(r[2]),b(r[3]))}if(e.boundingVolume.sphere){const s=e.boundingVolume.sphere,o=Q([],i.transformMat4([],s,r)),a=s[3],c=n.locate(o,-a,a),l=n.locate(o,a,-a);return new t.Extent(c,l)}if(e.boundingVolume.box){const o=e.boundingVolume.box,a=i.transformMat4([],o,r),c=new t.Coordinate(Q([],a)),l=o.slice(3);s.multiply(l,s.fromMat4([],e.matrix),l);const f=i.length(l.slice(0,3)),u=i.length(l.slice(3,6)),h=i.length(l.slice(6,9)),_=Math.max(f,u,h),d=n.locate(c,-_,_),E=n.locate(c,_,-_);return new t.Extent(d,E)}return null}getRootTiles(){return this.Ee}getTiles(){const t=this.getRenderer();if(!t.ready)return this.me(),{tiles:Ar};const e=this.getMap(),r=e.cameraPosition;let n,s;if(e.getGLZoom)s=e.pointToDistance(r[2],0,e.getGLZoom()),Rr.set(r[0],r[1]),n=e.pointToCoord(Rr,e.getGLZoom());else{const t=e.getGLRes();s=e.pointAtResToDistance(r[2],0,t),Rr.set(r[0],r[1]),n=e.pointAtResToCoord(Rr,t)}this.Ae=this.Ae||[],i.set(this.Ae,g(n.x),g(n.y),s),this.pe=K(this.pe||[],this.Ae[0],this.Ae[1],this.Ae[2]),this.ye=2*Math.tan(.5*g(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const l=[];for(let e=0;e<this.Ee.length;e++){let r=1/0;const n=[this.Ee[e]],i=this.Re(e);for(;n.length>0;){const e=n.pop();for(e.id||this.ge(e);c.level>=e.te;)c=c.parent;const s=this.be(e,i,o);if(s<1){let t=c;for(;t&&!t.content;)t=t.parent;0===s&&t&&t.content&&this.Ie(l,t);if(!1===this.options.services[e.k].alwaysShow)continue;if(!(0===s&&e.te<=r))continue;e.content&&(r=e.te)}e.j<1/0&&this.Ne(e);const a=this.ee(e,c);c.children.push(a);const f=e.children,u=f&&f.length,h=a.content;if(!u&&h&&this.Ie(l,a),u){h&&"add"===e.refine&&this.Ie(l,a),c=a;const r=f[0].parent;let i=!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;i=!0}else{i=!0,f[s].parent=e,f[s].ft=e.ft,f[s].baseUrl=e.baseUrl;const t=f[s].content&&(f[s].content.url||f[s].content.uri);t&&(C(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))}n.push(f[s])}!i&&h&&this.Ie(l,a)}}}return{root:a,tiles:l}}Ie(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 Ir(r,e);if(r.box)return 0===Nr(r,e)}return!1}(this.Ae,this.pe,r)||t.push(e)}ee(t,e){return{id:t.id,node:t,children:[],level:t.te,parent:e,content:t.content&&t.content.url}}ge(e){e.id=t.Util.GUID(),e.matrix=e.transform||n.identity([]),e.Se=this.Oe(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.k=e.parent.k,void 0===e.te&&(e.te=e.parent.te+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.xe(e)}xe(t){const e=t.boundingVolume;if(!e||e.Te)return;const r=this.options.services[t.k].heightOffset||0,s=this.options.offset,o=y(s)||s[0]||s[1];if(!t.boundingVolume||!r&&n.exactEquals(t.matrix,gr)&&!o)return;const{region:a,box:c,sphere:l}=e;if(a){const t=this.we([b(a[0]),b(a[1])]);a[0]=g(t.x),a[1]=g(t.y);const e=this.we([b(a[2]),b(a[3])]);a[2]=g(e.x),a[3]=g(e.y),a[4]+=r,a[5]+=r}else if(c||l){const e=c||l,n=i.transformMat4(Er,e,t.matrix),s=Q(Tr,n),o=this.we([s[0],s[1]]);s[0]=o.x,s[1]=o.y,s[2]+=r,K(e,g(s[0]),g(s[1]),s[2])}e.Te=!0}Oe(t){return void 0===t.geometricError||!t.boundingVolume}Ne(t){let e=t.parent;for(;e&&e.Se&&!(e.j<=t.j);)e.j=t.j,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.k],s=(t.asset&&t.asset.gltfUpAxis||e&&e.ft||i.upAxis||"Y").toUpperCase();t.root.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const o=r.indexOf("realspace/")>-1;0===e.te&&(t.asset&&t.asset.s3mType&&o||i.isSuperMapiServer)&&(t.root.baseUrl+="data/path/");const a=t.asset.i3s;if(t.root.ft=s,e){const r=e.boundingVolume;p(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.xe(e),e.Me=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.Se=this.Oe(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||C(s)||-1!==s.indexOf("http://")||-1!==s.indexOf("https://")||(e.content.url=e.baseUrl+s)}this.me(),this.fire("loadtileset",{tileset:t,index:e.k,url:r})}be(t,e,r){if(t.j=1/0,0===t.te||t.Se)return 1;if(!this.Ce(t,e,r))return-1;if(0===t.geometricError)return 1;let n=this.options.services[t.k].maximumScreenSpaceError;null==n&&(n=8);let i=this.ve(t);return 0===i&&t.parent&&(i=.5*(t.parent.Ue||0)),i>=n?1:0}nt(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)}Ce(e,r,i){const o=e.id;let a=this.de[o];const{boundingVolume:c}=e,h=c.sphere,_=c.region,d=c.box;if(!a){let r,i,c;if(_){r=_r.set(b(_[0]),b(_[1]),b(_[2]),b(_[3]));const t=r.getCenter(),e=this.Be(t);r=r.convertTo((t=>this.nt(t,pr)),dr),c=_[4],i=_[5],a=this.de[o]=[[r.xmin,r.ymin,c*e[2]],[r.xmax,r.ymax,i*e[2]]],a.center=t}else if(h){const e=Q(Er,h),r=new t.Coordinate(e),n=this.nt(r,pr).toArray(),i=this.Be(r);n.push(e[2]*i[2]),a=this.de[o]=[n,h[3]*i[2]],a.center=r}else if(d){const r=Q(Er,d),i=new t.Coordinate(r),c=this.nt(i,pr).toArray(),l=this.Be(i);c.push(r[2]*l[2]);const f=d.slice(3);n.exactEquals(e.matrix,gr)||s.multiply(f,s.fromMat4(yr,e.matrix),f);for(let t=0;t<f.length;t++)f[t]*=l[t%3],d[3+t]=f[t];a=this.de[o]=[...c,...f],a.center=i}}if(r){if(_)_r.xmin=a[0][0],_r.ymin=a[0][1],_r.xmax=a[1][0],_r.ymax=a[1][1];else if(h){const t=a[2];_r.xmin=a[0][0]-t,_r.ymin=a[0][1]-t,_r.xmax=a[0][0]+t,_r.ymax=a[0][1]+t}else if(d){const t=a[1],e=a[2];_r.xmin=a[0][0]-t,_r.ymin=a[0][1]-e,_r.xmax=a[0][0]+t,_r.ymax=a[0][1]+e}if(!r.intersects(_r))return!1}return _?l(i,a):h?f(i,a):!!d&&u(i,a)}Be(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,i.set(mr,r.x/100*1.01,r.y/100*1.01,n),mr}we(e){Array.isArray(e)&&(e=new t.Coordinate(e));let r=this.options.offset;if(y(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}Re(e){const r=this.options.services[e].maxExtent;if(!r)return null;const n=this.Ee[e];return n.maxExtent||(n.maxExtent=new t.Extent(r).convertTo((t=>this.nt(t)))),n.maxExtent}ve(t){const e=this.ye,r=t.geometricError;if(0===r)return 0;const n=this.getMap();let i;t.boundingVolume.region?i=function(t,e,r){t.Le||(t.Le=new ur(t.boundingVolume.region));return t.Le.distanceToCamera(e,r)}(t,this.pe,this.Ae):t.boundingVolume.sphere?i=Ir(t.boundingVolume,this.pe):t.boundingVolume.box&&(i=Nr(t.boundingVolume,this.pe));const s=Math.max(Math.abs(i),1e-7),o=r*n.height/(s*e);return t.j=i,t.Ue=o,o}me(){const t=this.getRenderer();t&&t.setToRedraw()}Et(t){return this.de[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)}}function Ir(t,e){const r=t.sphere,n=i.dist(r,e),s=t.sphere[3];return n<s?0:n-s}function Nr(t,e){const r=t.box;return ze(i.set(Er,r[0],r[1],r[2]),s.set(yr,r[3],r[4],r[5],r[6],r[7],r[8],r[9],r[10],r[11]),e)}br.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]}),br.registerRenderer("gl",Ge),br.registerJSONType("Geo3DTilesLayer");class Sr{constructor(t,e,r){this.Pe=t,this.De=e||h,this.ie=r,this.Fe={"image/crn":Ne.crn&&Ne.crn(),"image/ktx2":Ne.ktx2&&Ne.ktx2(),"image/cttf":Ne.ktx2&&Ne.ktx2(),"draco":Ne.draco&&Ne.draco()}}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.Ge(t,e,r,n,i)):_.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Ge(t,i,r,n)}))}Ge(t,e,r,n,i){const s=i&&i.maxTextureSize,o=this.ke(e,r,n,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.De(a,o.glb,{transferable:!0,requestImage:this.Pe,decoders:this.Fe,supportedFormats:this.ie,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}}))}ke(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),u=28+e;l>=570425344?(u-=8,o=a,l=c,f=0,a=0,c=0):f>=570425344&&(u-=4,o=l,l=a,f=c,a=0,c=0);const h=[t];let _,d,E;if(a>0?(_=ft(t,u,a),u+=a,o=_.BATCH_LENGTH):_={"BATCH_LENGTH":o},c>0&&(u+=c),l>0&&(d=ut(t,u,l),u+=l,f>0)){const e=ht(0,u,f);E=t.slice(e.offset,e.offset+e.byteLength),u+=f,h.push(E)}const T=_.BATCH_LENGTH,m={};if(_&&_.BATCH_ID){m.BATCH_ID=dt(_.BATCH_ID,t,undefined.offset,T);const e=m.BATCH_ID.array&&m.BATCH_ID.array.buffer;e&&h.indexOf(e)<0&&h.push(e)}return{count:o,transferables:h,featureTable:_,batchTable:d,batchTableBin:E,b3dm:m,glb:{buffer:t,byteOffset:u,byteLength:i.byteLength+i.byteOffset-u}}}He(){return null}}class Or{constructor(t,e,r,n){this.Pe=t,this.De=e||h,this.ie=r,this.Fe={"image/crn":Ne.crn&&Ne.crn(),"image/ktx2":Ne.ktx2&&Ne.ktx2(),"image/cttf":Ne.ktx2&&Ne.ktx2(),"draco":Ne.draco&&Ne.draco()},this.ze=n}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.Ge(t,e,r,n,i)):_.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Ge(t,i,r,n)}))}Ge(t,e,r,n,i){return this.Ve(t,e,r,n,i).then((({gltf:i,transferables:s})=>{const o=this.Xe(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})}))}Ve(t,e,r,n,i){const s=i&&i.maxTextureSize,o={transferable:!0,requestImage:this.Pe,decoders:this.Fe,supportedFormats:this.ie,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?_.getArrayBuffer(n,{}).then((t=>this.Ye(n,{buffer:t.data,byteOffset:0},o))):_.getJSON(n,{}).then((t=>this.Ye(n,t,o)))}{const n={buffer:e,byteOffset:c+r,byteLength:a.byteLength-c};return this.Ye(t,n,o)}}Ye(t,e,r){const n=t.substring(0,t.lastIndexOf("/")),i=new this.De(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}}))}Xe(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}=gt(i,32+e,o),u={},h=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;u.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,r=a.QUANTIZED_VOLUME_SCALE,{byteOffset:n}=a.POSITION_QUANTIZED;u.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.Ze(new Uint16Array(t,n+c.offset,3*h),e,r)},o.push(u.POSITION.array.buffer)}if(a.BATCH_ID){u.BATCH_ID=dt(a.BATCH_ID,t,c.offset,h);const e=u.BATCH_ID.array&&u.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;u.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,u.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;u.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.Ke(new Uint16Array(t,e+c.offset,2*h))},o.push(u.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,u.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.Ke(new Uint16Array(t,e+c.offset,2*h))},o.push(u.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;u.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,h).slice()},o.push(u.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;u.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.SCALE_NON_UNIFORM.array.buffer)}return{count:h,batchTable:l,batchTableBin:f,featureTable:a,i3dm:u,transferables:o}}Ke(t){const e=t.length/2,r=new Float32Array(3*e),n=[];for(let i=0;i<e;i++)xr(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}Ze(t,e,r){return Rt(new Float32Array(t.length),t,e,r)}He(){return null}}function xr(t,e,r,n){if(t[0]=wr(e,n),t[1]=wr(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]))*Mr(e),t[1]=(1-Math.abs(e))*Mr(t[1])}return d.normalize(t,t)}function wr(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 Mr(t){return t<0?-1:1}class Cr{constructor(){}load(t,e,r=0,n=0){return e?(n||(n=e.byteLength),this.Ge(t,e,r,n)):_.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.Ge(t,i,r,n)}))}Ge(t,e,r,n){return this.We(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}))}We(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}=gt(i,e+28,o),u=a.QUANTIZED_VOLUME_OFFSET,h=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.je||(this.je=Ne.draco()),this.je(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.qe(t,e.attributes,c.offset,_,o,u,h);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:yt(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?n.BATCH_ID=dt(a.BATCH_ID,t,c.offset,_):n.BATCH_ID=vr(_);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.qe(t,a,c.offset,_,o,u,h);if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?T.BATCH_ID=dt(a.BATCH_ID,t,c.offset,_):T.BATCH_ID=vr(_);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})}qe(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.Ze(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}Ze(t,e,r){return Rt(new Float32Array(t.length),t,e,r)}He(){return null}}function vr(t){const e=M(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:yt(e),array:r}}class Ur{constructor(t,e){this.Pe=t,this.De=e||h}load(t,e,r=0,n=0,i){return e?this.Ge(t,e,r,n,i):_.getArrayBuffer(t,{}).then((e=>{const i=e.data;return this.Ge(t,i,r,n)}))}Ge(t,e,r,n,i){n||(n=e.byteLength);const s=this.$e(e,t,r,n),o=[];for(let r=0;r<s.length;r++){let n;if("b3dm"===s[r].magic)n=new Sr(this.Pe,this.De);else if("i3dm"===s[r].magic)n=new Or(this.Pe,this.De);else if("pnts"===s[r].magic)n=new Cr;else{if("cmpt"!==s[r].magic){console.warn("Unsupported magic in CMPT tile:",s[r].magic);continue}n=new Ur(this.Pe,this.De)}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})))}$e(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=ct(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(m);t.registerWorkerAdapter("@maptalks/3dtiles",r)}else t.registerWorkerAdapter("@maptalks/3dtiles",(function(){return e.transcoders.inject(m)}))}else t.registerWorkerAdapter("@maptalks/3dtiles",m);export{Sr as B3DMLoader,Ur as CMPTLoader,br as Geo3DTilesLayer,B as Geo3DTilesUtil,ot as Geo3DTransform};"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.18.2");
|