@openglobus/openglobus-react 0.4.7 → 0.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +1 -1
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +2 -2
package/dist/index.umd.cjs
CHANGED
|
@@ -937,5 +937,5 @@ vec3 Uncharted2ToneMapping(vec3 color){color*=exposure;return saturate(Uncharted
|
|
|
937
937
|
void main(void) {
|
|
938
938
|
float c = LinearizeDepth(tc);
|
|
939
939
|
fragColor = vec4(c, c, c, 1.0);
|
|
940
|
-
}`})]),this.sceneFramebuffer=new so(this.handler,{size:1,msaa:this._msaa,internalFormat:this._internalFormat,filter:"LINEAR"}),this.sceneFramebuffer.init(),this.blitFramebuffer=new Re(this.handler,{size:1,useDepth:!1,targets:[{internalFormat:this._internalFormat,format:this._format,type:this._type,filter:"NEAREST"}]}),this.blitFramebuffer.init(),this.toneMappingFramebuffer=new Re(this.handler,{useDepth:!1}),this.toneMappingFramebuffer.init(),this._fnScreenFrame=this._screenFrameMSAA,this.screenTexture={screen:this.toneMappingFramebuffer.textures[0],picking:this.pickingFramebuffer.textures[0],depth:this.screenDepthFramebuffer.textures[0],frustum:this.depthFramebuffer.textures[0]}}this.handler.ONCANVASRESIZE=()=>{this._resizeStart(),this.events.dispatch(this.events.resize,this.handler.canvas),this._resizeEnd(),this.events.dispatch(this.events.resizeend,this.handler.canvas)},this.screenFramePositionBuffer=this.handler.createArrayBuffer(new Float32Array([1,1,-1,1,1,-1,-1,-1]),2,4),this.outputTexture=this.screenTexture.screen,this._initializeRenderNodes(),this._initializeControls()}}_initializeControls(){let e=this.controls;this.controls={};for(let t in e)this.addControl(e[t])}resize(){this._resizeEnd()}setCurrentScreen(e){this._currentOutput=e,this.screenTexture[e]&&(this.outputTexture=this.screenTexture[e])}_resizeStart(){let e=this.handler.canvas;this.activeCamera.setViewportSize(e.width,e.height),this.sceneFramebuffer.setSize(.5*e.width,.5*e.height),this.blitFramebuffer&&this.blitFramebuffer.setSize(.5*e.width,.5*e.height,!0)}_resizeEnd(){let e=this.handler.canvas;this.activeCamera.setViewportSize(e.width,e.height),this.sceneFramebuffer.setSize(e.width,e.height),this.blitFramebuffer&&this.blitFramebuffer.setSize(e.width,e.height,!0),this.toneMappingFramebuffer&&this.toneMappingFramebuffer.setSize(e.width,e.height,!0),this.screenDepthFramebuffer&&this.screenDepthFramebuffer.setSize(e.clientWidth,e.clientHeight,!0),this.handler.gl.type==="webgl"?(this.screenTexture.screen=this.sceneFramebuffer.textures[0],this.screenTexture.picking=this.pickingFramebuffer.textures[0],this.screenTexture.depth=this.screenDepthFramebuffer.textures[0],this.screenTexture.frustum=this.depthFramebuffer.textures[0]):(this.screenTexture.screen=this.toneMappingFramebuffer.textures[0],this.screenTexture.picking=this.pickingFramebuffer.textures[0],this.screenTexture.depth=this.screenDepthFramebuffer.textures[0],this.screenTexture.frustum=this.depthFramebuffer.textures[0]),this.setCurrentScreen(this._currentOutput)}removeNode(e){e.remove()}addNode(e){this.renderNodes[e.name]?Qe.logWrn(`Node name ${e.name} already exists.`):(e.assign(this),this._renderNodesArr.unshift(e),this.renderNodes[e.name]=e)}_initializeRenderNodes(){for(let e=0;e<this._renderNodesArr.length;e++)this._renderNodesArr[e].initialize()}addNodeBefore(e,t){if(this.renderNodes[e.name])Qe.logWrn(`Node name ${e.name} already exists.`);else{e.assign(this),this.renderNodes[e.name]=e;for(let i=0;i<this._renderNodesArr.length;i++)if(this._renderNodesArr[i].isEqual(t)){this._renderNodesArr.splice(i,0,e);break}this._renderNodesArr.unshift(e)}}addNodes(e){for(let t=0;t<e.length;t++)this.addNode(e[t])}getMaxMSAA(e){let t=this.handler.gl;return t.getInternalformatParameter(t.RENDERBUFFER,t[e],t.SAMPLES)[0]}getMSAA(){return this._msaa}enqueueEntityCollectionsToDraw(e,t=0){this._entityCollections[t]||(this._entityCollections[t]=[]),this._entityCollections[t].push(...e)}markForDepthRefresh(){this._depthRefreshRequired=!0}_drawEntityCollections(e){let t=this._entityCollections[e];if(t.length){let i=this.handler.gl;this.enableBlendDefault();let r=t.length;for(;r--;)t[r]._fadingOpacity&&t[r].pointCloudHandler.draw();for(r=t.length;r--;){let n=t[r];t[r]._fadingOpacity&&(n.events.dispatch(n.events.draw,n),t[r].geoObjectHandler.draw())}for(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this.billboardsTextureAtlas.texture),r=t.length;r--;){let n=t[r];n._fadingOpacity&&n.billboardHandler.draw()}let s=this.fontAtlas.atlasesArr;for(r=0;r<s.length;r++)i.activeTexture(i.TEXTURE0+r),i.bindTexture(i.TEXTURE_2D,s[r].texture);for(r=t.length;r--;)t[r]._fadingOpacity&&t[r].labelHandler.draw();for(r=t.length;r--;)t[r]._fadingOpacity&&t[r].rayHandler.draw();for(r=t.length;r--;)t[r]._fadingOpacity&&t[r].polylineHandler.draw();for(r=t.length;r--;)t[r]._fadingOpacity&&t[r].stripHandler.draw()}}_drawPickingEntityCollections(e){let t=this._entityCollections[e];if(t.length){let i=t.length;for(;i--;)t[i]._fadingOpacity&&t[i].billboardHandler.drawPicking();for(i=t.length;i--;)t[i]._fadingOpacity&&t[i].geoObjectHandler.drawPicking();for(i=t.length;i--;)t[i]._fadingOpacity&&t[i].labelHandler.drawPicking();for(i=t.length;i--;)t[i]._fadingOpacity&&t[i].rayHandler.drawPicking();for(i=t.length;i--;)t[i]._visibility&&t[i].polylineHandler.drawPicking();for(i=t.length;i--;)t[i]._visibility&&t[i].stripHandler.drawPicking()}}_drawDepthEntityCollections(e){let t=this._entityCollections[e];if(t.length){let i=t.length;for(;i--;)t[i]._fadingOpacity&&t[i].geoObjectHandler.drawDepth()}}_clearEntityCollectionQueue(e){this._entityCollections[e].length=0,this._entityCollections[e]=[]}draw(){this.activeCamera.checkMoveEnd();let e=this.events,t=e.pointerEvent(),i=!e.mouseState.leftButtonDown&&!e.mouseState.rightButtonDown,r=e.touchState.touchStart||e.touchState.touchEnd;const s=t&&i||r||this._depthRefreshRequired;this._depthRefreshRequired=!1,e.handleEvents();let n=this.sceneFramebuffer;n.activate();let a=this.handler.gl;a.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT),this.enableBlendDefault(),e.dispatch(e.draw,this),this.activeCamera.checkFly();let l=this.activeCamera.frustums,h=this._renderNodesArr,c=l.length;for(;c--;){this.activeCamera.setCurrentFrustum(c),a.clear(a.DEPTH_BUFFER_BIT);let d=h.length;for(;d--;)h[d].preDrawNode();for(d=h.length;d--;)this.enableBlendDefault(),h[d].drawNode();this._drawEntityCollections(0),e.dispatch(e.drawtransparent,this),s&&this._drawPickingBuffer(0),this._drawDepthBuffer(0),this._clearEntityCollectionQueue(0)}for(let d=1;d<this._entityCollections.length;d++){a.clear(a.DEPTH_BUFFER_BIT);let u=l.length;for(;u--;)this.activeCamera.setCurrentFrustum(u),this._drawEntityCollections(d),s&&this._drawPickingBuffer(d),this._drawDepthBuffer(d);this._clearEntityCollectionQueue(d)}n.deactivate(),this.blitFramebuffer&&n.blitTo(this.blitFramebuffer,0),s&&(this._readPickingBuffer(),this._readDepthBuffer()),this._fnScreenFrame(),e.dispatch(e.postdraw,this),e.mouseState.wheelDelta=0,e.mouseState.justStopped=!1,e.mouseState.moving=!1,e.touchState.moving=!1}getImageDataURL(e="image/png",t=1){return this.draw(),this.handler.canvas?this.handler.canvas.toDataURL(e,t):""}_screenFrameMSAA(){let e=this.handler,t=e.programs.toneMapping,i=t._program,r=e.gl;r.disable(r.DEPTH_TEST),r.bindBuffer(r.ARRAY_BUFFER,this.screenFramePositionBuffer),r.vertexAttribPointer(i.attributes.corners,2,r.FLOAT,!1,0,0),this.toneMappingFramebuffer.activate(),r.clearColor(0,0,0,0),r.clear(r.COLOR_BUFFER_BIT),t.activate(),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,this.blitFramebuffer.textures[0]),r.uniform1i(i.uniforms.hdrBuffer,0),r.uniform1f(i.uniforms.gamma,this.gamma),r.uniform1f(i.uniforms.exposure,this.exposure),r.uniform1f(i.uniforms.whitepoint,this.whitepoint),r.drawArrays(r.TRIANGLE_STRIP,0,4),this.toneMappingFramebuffer.deactivate(),t=e.programs.screenFrame,i=t._program,t.activate(),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,this.outputTexture),r.uniform1i(i.uniforms.texture,0),r.drawArrays(r.TRIANGLE_STRIP,0,4),r.enable(r.DEPTH_TEST)}_screenFrameNoMSAA(){let e=this.handler,t=e.programs.screenFrame,i=t._program,r=e.gl;r.disable(r.DEPTH_TEST),t.activate(),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,this.outputTexture),r.uniform1i(i.uniforms.texture,0),r.bindBuffer(r.ARRAY_BUFFER,this.screenFramePositionBuffer),r.vertexAttribPointer(i.attributes.corners,2,r.FLOAT,!1,0,0),r.drawArrays(r.TRIANGLE_STRIP,0,4),r.enable(r.DEPTH_TEST)}_drawPickingBuffer(e){this.pickingFramebuffer.activate();let t=this.handler.gl;if(this.activeCamera.isFirstPass&&e===0?(t.clearColor(0,0,0,1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT)):t.clear(t.DEPTH_BUFFER_BIT),t.disable(t.BLEND),e===0){let i=this._pickingCallbacks;for(let r=0,s=i.length;r<s;r++)i[r].callback.call(i[r].sender)}this._drawPickingEntityCollections(e),t.enable(t.BLEND),this.pickingFramebuffer.deactivate()}_drawDepthBuffer(e){this.depthFramebuffer.activate();let t=this.handler,i=t.gl;if(i.disable(i.BLEND),this.activeCamera.isFirstPass&&e===0?(i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT)):i.clear(i.DEPTH_BUFFER_BIT),e===0){let r=this._depthCallbacks,s=r.length;for(;s--;)r[s].callback.call(r[s].sender)}if(this._drawDepthEntityCollections(e),this.depthFramebuffer.deactivate(),this._currentOutput==="depth"||this._currentOutput==="frustum"){this.screenDepthFramebuffer.activate();let r=t.programs.depth,s=r._program;i.bindBuffer(i.ARRAY_BUFFER,this.screenFramePositionBuffer),i.vertexAttribPointer(s.attributes.corners,2,i.FLOAT,!1,0,0),r.activate(),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this.depthFramebuffer.textures[1]),i.uniform1i(s.uniforms.depthTexture,0),i.drawArrays(i.TRIANGLE_STRIP,0,4),this.screenDepthFramebuffer.deactivate()}i.enable(i.BLEND)}_readDepthBuffer(e){this.depthFramebuffer.readPixelBuffersAsync(e)}_readPickingBuffer_webgl1(){this.pickingFramebuffer.readPixelBuffersAsync()}_readPickingBuffer_webgl2(){this.pickingFramebuffer.readPixelBuffersAsync()}readPickingColor(e,t,i){var r;let s=this.pickingFramebuffer.width,n=this.pickingFramebuffer.height;e=Math.round(e*s);let a=4*((t=Math.round(t*n))*s+e),l=(r=this.pickingFramebuffer)==null?void 0:r.pixelBuffers[0].data;l&&(i[0]=l[a],i[1]=l[a+1],i[2]=l[a+2])}readDepth(e,t,i){let r=new Float32Array(4),s=new Uint8Array(4);this.depthFramebuffer.readData(e,t,s,0),this.depthFramebuffer.readData(e,t,r,1),i[0]=r[0],i[1]=Math.round(s[0]/10)-1}getDistanceFromPixel(e){let t=this.activeCamera,i=this.handler.canvas,r=e.x/i.width,s=(i.height-e.y)/i.height;if(Zt[0]=Zt[1]=0,this.readDepth(r,s,Zt),Zt[1]===-1)return;let n=Zt[0],a=t.frustums[Zt[1]];if(!a)return;let l=new te(2*r-1,2*s-1,2*n-1,1),h=a.inverseProjectionMatrix.mulVec4(l),c=-h.z/h.w;if(t.isOrthographic)return c;let d=e.direction||t.unproject(e.x,e.y);return c/Math.max(1e-6,d.dot(t.getForward()))}getCartesianFromPixel(e){let t=this.getDistanceFromPixel(e);if(t){if(this.activeCamera.isOrthographic){let i=new m;return this.activeCamera.unproject(e.x,e.y,t,i),i}return(e.direction||this.activeCamera.unproject(e.x,e.y)).scaleTo(t).addA(this.activeCamera.eye)}}getCartesianFromPixelAsync(e){return new Promise(((t,i)=>{this._readDepthBuffer((()=>{t(this.getCartesianFromPixel(e))}))}))}getDepthMinDistance(){let e=this.handler.canvas,t=e.width,i=e.height,r=ar,s=i*t,n=new N;for(let a=0;a<s;a++){n.x=a%t,n.y=Math.floor(a/t);let l=this.getDistanceFromPixel(n);l&&l<r&&(r=l)}return r<ar?r:0}getDepthMinDistanceAsync(){return new Promise(((e,t)=>{this._readDepthBuffer((()=>{e(this.getDepthMinDistance())}))}))}async setOrthographicProjection(e){if(e!==this.activeCamera.isOrthographic){let t=await this.getDepthMinDistanceAsync();t&&e&&(this.activeCamera.focusDistance=t),this.activeCamera.isOrthographic=e,this.events.dispatch(this.events.projchanged,this.activeCamera)}}start(){this._initialized||this.initialize(),this.handler.start()}destroy(){for(let e in this.controls)this.controls[e].remove();for(let e=0;e<this._renderNodesArr.length;e++)this._renderNodesArr[e].remove();this.div=null,this._renderNodesArr=[],this.renderNodes={},this.activeCamera=null,this.controls={},this.controlsBag={},this.colorObjects.clear(),this.colorObjects=null,this._pickingCallbacks=[],this.pickingFramebuffer=null,this._tempPickingPix_=null,this._depthCallbacks=[],this.depthFramebuffer=null,this.sceneFramebuffer=null,this.blitFramebuffer=null,this.toneMappingFramebuffer=null,this._entityCollections=[[]],this.handler.ONCANVASRESIZE=null,this.handler.destroy(),this.handler=null,this._initialized=!1}}const Po="/res",So=class nr{constructor(e){this.$target=null,this._instanceID=`__globus${nr.__counter__++?nr.__counter__:""}__`,window[this._instanceID]=this,this._canvas=document.createElement("canvas"),this._canvas.id=`canvas${this._instanceID}`,this._canvas.style.width="100%",this._canvas.style.height="100%",this._canvas.style.display="block",this._canvas.style.opacity="0.0",this._canvas.style.transition="opacity 150ms",this.$inner=document.createElement("div"),this.$inner.classList.add("og-inner"),this.$inner.appendChild(this._canvas),this.$inner.attributions=document.createElement("div"),e.attributionContainer?e.attributionContainer.appendChild(this.$inner.attributions):(this.$inner.attributions.classList.add("og-attribution"),this.$inner.appendChild(this.$inner.attributions)),e.target&&this.attachTo(e.target);const t=n=>{n.preventDefault()};this._canvas.onmouseenter=function(){document.addEventListener("mousewheel",t,{capture:!1,passive:!1})},this._canvas.onmouseleave=function(){document.removeEventListener("mousewheel",t)},this.renderer=new Md(new Tt(this._canvas,{autoActivate:!1,pixelRatio:e.dpi||window.devicePixelRatio+.15,context:{alpha:e.transparentBackground,antialias:!1,premultipliedAlpha:!0,preserveDrawingBuffer:!1}}),{autoActivate:!1,msaa:e.msaa,fontsSrc:e.fontsSrc,gamma:e.gamma,exposure:e.exposure,...e.transparentBackground&&{clearColor:[0,0,0,0]}}),this.renderer.div=this.$inner,e.skybox&&this.renderer.addNode(e.skybox),this._planetName=e.name?e.name:"globus_planet_"+nr.__counter__,this.planet=new Ai({name:this._planetName,frustums:e.frustums,ellipsoid:e.ellipsoid,maxGridSize:e.maxGridSize,nightTextureSrc:e.nightTextureSrc===null?null:e.nightTextureSrc||`${e.resourcesSrc||Po}/night.png`,specularTextureSrc:e.specularTextureSrc===null?null:e.specularTextureSrc||`${e.resourcesSrc||Po}/spec.png`,minAltitude:e.minAltitude,maxAltitude:e.maxAltitude||15e6,maxEqualZoomAltitude:e.maxEqualZoomAltitude,minEqualZoomAltitude:e.minEqualZoomAltitude,minEqualZoomCameraSlope:e.minEqualZoomCameraSlope,quadTreeStrategyPrototype:e.quadTreeStrategyPrototype,maxLoadingRequests:e.maxLoadingRequests,atmosphereEnabled:e.atmosphereEnabled,transitionOpacityEnabled:e.transitionOpacityEnabled,atmosphereParameters:e.atmosphereParameters,minDistanceBeforeMemClear:e.minDistanceBeforeMemClear,vectorTileSize:e.vectorTileSize,maxNodesCount:e.maxNodesCount,transparentBackground:e.transparentBackground}),e.terrain?Array.isArray(e.terrain)?this.planet.setTerrain(e.terrain[0]):this.planet.setTerrain(e.terrain):this.planet.setTerrain(new ms),this.renderer.addNode(this.planet),e.controls?this.planet.addControls(e.controls):this.planet.addControls([new Ra,new ya,new Ma,new pa,new La,new nn,new ns]);const i=this.renderer.controls;let r;for(let n in i)if(i[n]instanceof Qr){r=i[n];break}r?this.sun=r:(this.sun=new Qr,this.planet.addControl(this.sun)),e.sun&&(e.sun.active===void 0||e.sun.active||this.sun.deactivate(),e.sun.stopped===!0&&this.sun.stop()),e.layers&&this.planet.addLayers(e.layers);let s=e.viewExtent;s&&(s instanceof Array?this.planet.viewExtentArr(s):this.planet.viewExtent(s)),(e.autoActivate||Ue(e.autoActivate))&&this.start()}start(){this.renderer.start(),this.fadeIn()}fadeIn(){this._canvas.style.opacity="1.0"}fadeOut(){this._canvas.style.opacity="0"}attachTo(e,t){let i;this.detach(),i=e instanceof HTMLElement?e:document.getElementById(e)||document.querySelector(e),i?(this.$target=i,t&&this.$target.firstChild?this.$target.insertBefore(this.$inner,this.$target.firstChild):i.appendChild(this.$inner)):console.warn(`Target container not found. Provided target: ${e}`)}detach(){this.$target&&(this.$target.removeChild(this.$inner),this.$target=null)}destroy(){this.detach(),this.planet.layers.forEach((e=>e.remove())),this.planet.destroy(),this.renderer.destroy(),window[this._instanceID]=null}};So.__counter__=0;let Rd=So;new pr(3396200,3389508),new pr(1737400,1737400);class Bd{static async load(e){const t=await fetch(e);if(!t.ok)throw new Error(`Unable to load '${e}'`);const i=await t.arrayBuffer(),r=new DataView(i);if(r.getUint32(0,!0)!==1179937895)throw new Error("Not a valid GLB");r.getUint32(4,!0);const s=this.getChunks(r);return this.parseChunks(s)}static getChunks(e){const t=[];let i=12;do{const r=this.getChunk(e,i);i+=8+r.length,t.push(r)}while(i<e.byteLength);return t}static getChunk(e,t){const i=e.getUint32(t,!0);return{length:i,type:this.getChunkType(e.getUint32(t+4,!0)),chunkData:e.buffer.slice(t+8,t+8+i)}}static getChunkType(e){switch(e){case 1313821514:return 0;case 5130562:return 1;default:return 2}}static parseChunks(e){let t,i=[];for(const r of e)switch(r.type){case 0:t=this.parseJsonChunk(r);break;case 1:i.push(r.chunkData)}if(t===void 0)throw new Error("GLB json data extraction failed");return{gltf:t,bin:i}}static parseJsonChunk(e){return JSON.parse(new TextDecoder().decode(e.chunkData))}}var Rt=(o=>(o[o.byte=5120]="byte",o[o.ubyte=5121]="ubyte",o[o.short=5122]="short",o[o.ushort=5123]="ushort",o[o.uint=5125]="uint",o[o.float=5126]="float",o))(Rt||{}),yt=(o=>(o.scalar="SCALAR",o.vec2="VEC2",o.vec3="VEC3",o.vec4="VEC4",o.mat2="MAT2",o.mat3="MAT3",o.mat4="MAT4",o))(yt||{}),ws=(o=>(o[o.points=0]="points",o[o.lines=1]="lines",o[o.lineLoop=2]="lineLoop",o[o.lineStrip=3]="lineStrip",o[o.triangles=4]="triangles",o[o.triangleStrip=5]="triangleStrip",o[o.triangleFan=6]="triangleFan",o))(ws||{});const Mo=class dt{constructor(e){var t;if(this.gltf=e,this._materials=[],this._images=[],this.meshes=[],((t=e.gltf.extensionsRequired)==null?void 0:t.includes("KHR_draco_mesh_compression"))&&dt._dracoDecoderModule===null)throw new Error("Unable to import GLTF. Draco decoder module is not connected");this._initImages(),this._initMaterials(),this._initMeshes()}static connectDracoDecoderModule(e){dt._dracoDecoderModule=e}static async loadGlb(e){const t=await Bd.load(e);return new dt(t)}getObjects3d(){const e=[];for(let t=0;t<this.meshes.length;t++)for(let i=0;i<this.meshes[t].primitives.length;i++)this.meshes[t].primitives[i].object3d!==void 0&&e.push(this.meshes[t].primitives[i].object3d);return e}toEntities(){const e=[];for(const t of this.gltf.gltf.scenes){if(t===void 0||t.nodes===void 0)return[];for(const i of t.nodes){const r=this.gltf.gltf.nodes[i];r.mesh===void 0&&r.children===void 0||e.push(this._nodeToEntity(r))}}return e}_nodeToEntity(e,t){const i=new V({name:e.name,cartesian:new m(0,0,0),relativePosition:t!==void 0});let r=null;if(e.mesh!==void 0&&(r=this.meshToEntity(this.meshes[e.mesh],t),i.appendChild(r)),e.matrix!==void 0){const s=new re;s.set(e.matrix),i.setCartesian3v(s.getPosition()),i.setDirectQuaternionRotation(s.getQuat()),i.setScale3v(s.getScaling())}if(e.translation!==void 0&&e.matrix===void 0&&(i.relativePosition=!0,i.setCartesian(e.translation[0],e.translation[1],e.translation[2])),e.rotation!==void 0&&e.matrix===void 0&&i.setDirectQuaternionRotation(new O(e.rotation[0],e.rotation[1],e.rotation[2],e.rotation[3])),e.scale!==void 0&&e.matrix===void 0&&i.setScale3v(new m(e.scale[0],e.scale[1],e.scale[2])),e.children!==void 0)for(const s of e.children){const n=this._nodeToEntity(this.gltf.gltf.nodes[s],i);r?r.appendChild(n):i.appendChild(n)}return i}meshToEntity(e,t){const i=new V({name:e.name,cartesian:new m(0,0,0),relativePosition:!0,independentPicking:!0});return e.primitives.map((r=>{i.appendChild(new V({name:r.name,relativePosition:!0,geoObject:{object3d:r.object3d,tag:r.name}}))})),i}_initImages(){if(this.gltf.gltf.images)for(const e of this.gltf.gltf.images)this._images.push({src:e.uri,element:this._getImage(e.mimeType,e.bufferView),mimeType:e.mimeType,name:e.name})}_getImage(e,t){if(t&&e){const i=this.gltf.gltf.bufferViews[t],r=URL.createObjectURL(new Blob([this.gltf.bin[i.buffer].slice(i.byteOffset,i.byteOffset+i.byteLength)],{type:e})),s=new Image;return s.src=r,s}}_initMaterials(){if(this.gltf.gltf.materials)for(const e of this.gltf.gltf.materials){const t={name:e.name,emissiveFactor:e.emissiveFactor,alphaMode:e.alphaMode,alphaCutoff:e.alphaCutoff,doubleSided:e.doubleSided};if(e.pbrMetallicRoughness){if(e.pbrMetallicRoughness.baseColorFactor&&(t.baseColorFactor=e.pbrMetallicRoughness.baseColorFactor),e.pbrMetallicRoughness.baseColorTexture){const i=this.gltf.gltf.textures[e.pbrMetallicRoughness.baseColorTexture.index].source;i!==void 0&&(t.baseColorTexture={image:this._images[i],texCoord:e.pbrMetallicRoughness.baseColorTexture.texCoord})}if(e.pbrMetallicRoughness.metallicRoughnessTexture){const i=this.gltf.gltf.textures[e.pbrMetallicRoughness.metallicRoughnessTexture.index].source;i!==void 0&&(t.metallicRoughnessTexture={image:this._images[i],texCoord:e.pbrMetallicRoughness.metallicRoughnessTexture.texCoord})}}if(e.normalTexture){const i=this.gltf.gltf.textures[e.normalTexture.index].source;i!==void 0&&(t.normalTexture={image:this._images[i],texCoord:e.normalTexture.texCoord,scale:e.normalTexture.scale})}if(e.occlusionTexture){const i=this.gltf.gltf.textures[e.occlusionTexture.index].source;i!==void 0&&(t.occlusionTexture={image:this._images[i],texCoord:e.occlusionTexture.texCoord,strength:e.occlusionTexture.strength})}if(e.emissiveTexture){const i=this.gltf.gltf.textures[e.emissiveTexture.index].source;i!==void 0&&(t.emissiveTexture={image:this._images[i],texCoord:e.emissiveTexture.texCoord})}this._materials.push(t)}}_initMeshes(){this.meshes=[];for(let e=0;e<this.gltf.gltf.meshes.length;e++){const t=this.gltf.gltf.meshes[e],i={name:t.name,primitives:[]};for(let r=0;r<t.primitives.length;r++)i.primitives.push(this._buildPrimitive(t,t.primitives[r],`${e}-${r}`));this.meshes.push(i)}}_buildPrimitive(e,t,i){var r,s;let n=null;const a=this._materials[t.material||0],l=(r=a.baseColorTexture)!=null&&r.texCoord?`TEXCOORD_${a.baseColorTexture.texCoord}`:"TEXCOORD_0";if((s=t.extensions)!=null&&s.KHR_draco_mesh_compression){const h=t.extensions.KHR_draco_mesh_compression,c=this.gltf.gltf.bufferViews[h.bufferView],d=c.byteOffset||0,u=dt._dracoDecoderModule,g=new u.Decoder,f=new u.DecoderBuffer;if(f.Init(new Int8Array(this.gltf.bin[c.buffer].slice(d,d+c.byteLength)),c.byteLength),g.GetEncodedGeometryType(f)!==u.TRIANGULAR_MESH)throw new Error("Draco compressed data is not a mesh");const p=new u.Mesh;if(!g.DecodeBufferToMesh(f,p).ok()||p.ptr===0)throw new Error("Failed to decode Draco mesh");const _=p.num_faces(),v=new Uint32Array(3*_),x=new u.DracoInt32Array;for(let w=0;w<_;w++)g.GetFaceFromMesh(p,w,x),v[3*w]=x.GetValue(0),v[3*w+1]=x.GetValue(1),v[3*w+2]=x.GetValue(2);u.destroy(x);const y={};for(const w in h.attributes){const b=h.attributes[w],C=g.GetAttributeByUniqueId(p,b),E=p.num_points(),T=C.num_components(),L=new u.DracoFloat32Array;g.GetAttributeFloatForAllPoints(p,C,L);const S=new Float32Array(E*T);for(let R=0;R<S.length;R++)S[R]=L.GetValue(R);u.destroy(L),y[w]=S}u.destroy(p),u.destroy(f),u.destroy(g),n={name:`${e.name}/${a.name}/${i}`,vertices:y.POSITION,indices:v,mode:t.mode?t.mode:ws.triangles,material:this._materials[t.material||0]||void 0,normals:y.NORMAL,texCoords:void 0}}else{const h=l?t.attributes[l]:void 0,c=h?this.gltf.gltf.accessors[h]:void 0;n={name:`${e.name}/${a.name}/${i}`,indices:t.indices?dt._access(this.gltf.gltf.accessors[t.indices],this.gltf):void 0,mode:t.mode?t.mode:ws.triangles,material:this._materials[t.material||0]||void 0,vertices:dt._access(this.gltf.gltf.accessors[t.attributes.POSITION],this.gltf),normals:dt._access(this.gltf.gltf.accessors[t.attributes.NORMAL],this.gltf),texCoords:c?dt._access(c,this.gltf):void 0}}if(n===null)throw new Error("Unable to build primitive");return n.object3d=dt._toObject3d(n),n}static _toObject3d(e){var t,i,r,s,n,a,l,h,c,d,u,g,f;return new $({name:e.name,vertices:Array.from(e.vertices),normals:Array.from(e.normals),texCoords:e.texCoords?Array.from(e.texCoords):void 0,indices:Array.from(e.indices),normalTextureImage:(i=(t=e.material)==null?void 0:t.normalTexture)==null?void 0:i.image.element,normalTextureSrc:(s=(r=e.material)==null?void 0:r.normalTexture)==null?void 0:s.image.src,colorTextureImage:(a=(n=e.material)==null?void 0:n.baseColorTexture)==null?void 0:a.image.element,colorTextureSrc:(h=(l=e.material)==null?void 0:l.baseColorTexture)==null?void 0:h.image.src,metallicRoughnessTextureImage:(d=(c=e.material)==null?void 0:c.occlusionTexture)==null?void 0:d.image.element,metallicRoughnessTextureSrc:(g=(u=e.material)==null?void 0:u.occlusionTexture)==null?void 0:g.image.src,color:(f=e.material)==null?void 0:f.baseColorFactor})}static _access(e,t){const i=t.gltf.bufferViews[e.bufferView],r=t.bin[i.buffer];let s=i.byteOffset||0;e.byteOffset!==void 0&&(s+=e.byteOffset);const n=r.slice(s,s+i.byteLength);switch(e.type){case yt.scalar:return this._getTensor(n,e,1,i.byteStride);case yt.vec2:return this._getTensor(n,e,2,i.byteStride);case yt.vec3:return this._getTensor(n,e,3,i.byteStride);case yt.vec4:case yt.mat2:return this._getTensor(n,e,4,i.byteStride);case yt.mat3:return this._getTensor(n,e,9,i.byteStride);case yt.mat4:return this._getTensor(n,e,16,i.byteStride);default:throw new Error("Unknown accessor type")}}static _getTensor(e,t,i,r){if(t.componentType===Rt.ushort)return new Uint16Array(e,0,t.count*i);if(t.componentType===Rt.short)return new Int16Array(e,0,t.count*i);if(t.componentType===Rt.uint)return new Uint32Array(e,0,t.count*i);if(t.componentType===Rt.float)return new Float32Array(e,0,t.count*i);if(t.componentType===Rt.ubyte)return new Uint8Array(e,0,t.count*i);if(t.componentType===Rt.byte)return new Int8Array(e,0,t.count*i);throw new Error("Unknown component type")}};Mo._dracoDecoderModule=null;let kd=Mo;const Id=({children:o,onDraw:e,...t})=>{const i=M.useRef(null),{setGlobe:r}=ut(),[s,n]=M.useState(t),a=M.useRef(null);return M.useEffect(()=>{if(a&&a.current&&t.viewExtent!==void 0){const l=t.viewExtent instanceof j?t.viewExtent:new j(new P(t.viewExtent[0],t.viewExtent[1]),new P(t.viewExtent[2],t.viewExtent[3]));a.current.planet.viewExtent(l)}},[t.viewExtent]),M.useEffect(()=>{a&&a.current&&t.atmosphereEnabled!==void 0&&(a.current.planet.atmosphereEnabled=t.atmosphereEnabled)},[t.atmosphereEnabled]),M.useEffect(()=>{a&&a.current&&t.sunActive!==void 0&&(t.sunActive?a.current?.sun.activate():a.current?.sun.deactivate())},[t.sunActive]),M.useEffect(()=>{if(a.current)i.current=a.current.$target;else{const l=new Eo("OSM"),h=new Ao("Microsoft Bing");a.current=new Rd({target:i.current,name:"Earth",terrain:new Co,layers:[l,h],autoActivate:!0,atmosphereEnabled:!0,...s}),e&&a.current.planet.events.on("draw",e)}return r(a.current),()=>{a.current&&(e&&a.current.planet.events.off("draw",e),a.current.destroy(),a.current=null)}},[s]),Ve.createElement("div",{style:{width:"100%",height:"100%"},ref:i},o)},zd=({name:o,...e})=>{const{globe:t}=ut(),i=M.useRef(null);return M.useEffect(()=>{typeof e.src=="string"&&i.current&&i.current?.setSrc(e.src)},[e.src]),M.useEffect(()=>{if(t)return i.current=new hs(o,e),t.planet.addLayer(i.current),()=>{i.current&&t.planet.removeLayer(i.current)}},[t]),null},Dd=({name:o,...e})=>{const{globe:t}=ut(),i=M.useRef(null);return M.useEffect(()=>{typeof e.src=="string"&&i.current&&i.current?.setSrc(e.src)},[e.src]),M.useEffect(()=>{if(t)return i.current=new To(o,e),t.planet.addLayer(i.current),()=>{i.current&&t.planet.removeLayer(i.current)}},[t]),null},Fd=({name:o,...e})=>{const{globe:t}=ut(),i=M.useRef(null);return M.useEffect(()=>{typeof e.url=="string"&&i.current&&i.current?.setUrl(e.url)},[e.url]),M.useEffect(()=>{if(t)return i.current=new Li(o,{...e}),t.planet.addLayer(i.current),()=>{i.current&&t.planet.removeLayer(i.current)}},[t]),Ve.createElement(Cs,{layerRef:i,name:o,...e})},Cs=({opacity:o,children:e,name:t,layerRef:i,...r})=>{const[s,n]=Ve.useState(!1);return M.useEffect(()=>{i&&i.current&&typeof o=="number"&&s&&(i.current.opacity=o)},[o]),M.useEffect(()=>(s&&i&&i.current&&(r.onVisibilityChange&&i.current?.events.on("visibilitychange",r.onVisibilityChange),r.onAdd&&i.current?.events.on("add",r.onAdd),r.onRemove&&i.current?.events.on("remove",r.onRemove),r.onMouseMove&&i.current?.events.on("mousemove",r.onMouseMove),r.onMouseEnter&&i.current?.events.on("mouseenter",r.onMouseEnter),r.onMouseLeave&&i.current?.events.on("mouseleave",r.onMouseLeave),r.onLclick&&i.current?.events.on("lclick",r.onLclick),r.onRclick&&i.current?.events.on("rclick",r.onRclick),r.onMclick&&i.current?.events.on("mclick",r.onMclick),r.onLdblclick&&i.current?.events.on("ldblclick",r.onLdblclick),r.onRdblclick&&i.current?.events.on("rdblclick",r.onRdblclick),r.onMdblclick&&i.current?.events.on("mdblclick",r.onMdblclick),r.onLup&&i.current?.events.on("lup",r.onLup),r.onRup&&i.current?.events.on("rup",r.onRup),r.onMup&&i.current?.events.on("mup",r.onMup),r.onLdown&&i.current?.events.on("ldown",r.onLdown),r.onRdown&&i.current?.events.on("rdown",r.onRdown),r.onMdown&&i.current?.events.on("mdown",r.onMdown),r.onLhold&&i.current?.events.on("lhold",r.onLhold),r.onRhold&&i.current?.events.on("rhold",r.onRhold),r.onMhold&&i.current?.events.on("mhold",r.onMhold),r.onMouseWheel&&i.current?.events.on("mousewheel",r.onMouseWheel),r.onTouchMove&&i.current?.events.on("touchmove",r.onTouchMove),r.onTouchStart&&i.current?.events.on("touchstart",r.onTouchStart),r.onTouchEnd&&i.current?.events.on("touchend",r.onTouchEnd),r.onDoubleTouch&&i.current?.events.on("doubletouch",r.onDoubleTouch)),()=>{r.onLclick&&i?.current?.events.off("lclick",r.onLclick),n(!1)}),[s]),i?.current&&!s&&n(!0),Ve.createElement(Ve.Fragment,null,e)},Ts=M.createContext({addEntity:()=>{},removeEntity:()=>{},addLabel:()=>{},removeLabel:()=>{},addBillboard:()=>{},removeBillboard:()=>{},addGeoObject:()=>{},removeGeoObject:()=>{},addGeometry:()=>{},removeGeometry:()=>{},addPolyline:()=>{},removePolyline:()=>{},addStrip:()=>{},removeStrip:()=>{},addGltf:(o,e)=>{},removeGltf:(o,e)=>{}}),Od=({visibility:o,children:e,name:t,...i})=>{const{globe:r}=ut(),s=M.useRef(null),[n,a]=M.useState([]),l=M.useRef(new Set);M.useEffect(()=>{typeof o=="boolean"&&s.current&&s.current.setVisibility(o)},[o]),M.useEffect(()=>{if(r)return s.current=new fe(t,i),r.planet.addLayer(s.current),i.onDraw&&s.current?.events.on("draw",i.onDraw),i.onMouseEnter&&s.current?.events.on("mouseenter",i.onMouseEnter),()=>{s.current&&(r.planet.removeLayer(s.current),i.onDraw&&s.current?.events.off("draw",i.onDraw),i.onMouseEnter&&s.current?.events.off("mouseenter",i.onMouseEnter))}},[r]),M.useEffect(()=>{if(s.current&&n.length>0){const L=n.filter(S=>!l.current.has(S));s.current.addEntities(L),L.forEach(S=>l.current.add(S))}},[n]);const h=M.useCallback(L=>{a(S=>S.includes(L)?S:[...S,L])},[]),c=M.useCallback(L=>{a(S=>S.filter(R=>R!==L)),s.current&&(s.current.removeEntity(L),l.current.delete(L))},[]),d=M.useCallback((L,S)=>{L.setBillboard(S)},[]),u=M.useCallback(L=>{L.billboard?.remove()},[]),g=M.useCallback((L,S)=>{L.setGeoObject(S)},[]),f=M.useCallback(L=>{L.geoObject?.remove()},[]),p=M.useCallback((L,S)=>{L.setLabel(S)},[]),_=M.useCallback(L=>{L.label?.remove()},[]),v=M.useCallback((L,S)=>{L.setGeometry(S)},[]),x=M.useCallback(L=>{L.geometry?.remove()},[]),y=M.useCallback((L,S)=>{L.setPolyline(S)},[]),w=M.useCallback(L=>{L.polyline?.remove()},[]),b=M.useCallback((L,S)=>{L.setStrip(S)},[]),C=M.useCallback(L=>{L.strip?.remove()},[]),E=M.useCallback((L,S)=>{L.appendChildren(S,!0)},[]),T=M.useCallback((L,S)=>{S.forEach(R=>{R.parent===L&&R.remove()})},[]);return Ve.createElement(Ts.Provider,{value:{addEntity:h,removeEntity:c,addBillboard:d,removeBillboard:u,addGeoObject:g,removeGeoObject:f,addLabel:p,removeLabel:_,addGeometry:v,removeGeometry:x,addPolyline:y,removePolyline:w,addStrip:b,removeStrip:C,addGltf:E,removeGltf:T}},Ve.createElement(Cs,{layerRef:s,name:t,...i},e))},Nd=({visibility:o,src:e,size:t,color:i,rotation:r,offset:s,_addBillboard:n,_removeBillboard:a,...l})=>{const h=M.useRef(null);return M.useEffect(()=>{typeof o=="boolean"&&h.current&&h.current?.setVisibility(o)},[o]),M.useEffect(()=>{typeof e=="string"&&h.current&&h.current?.setSrc(e)},[e]),M.useEffect(()=>{typeof r=="number"&&h.current&&h.current?.setRotation(r*Math.PI/180)},[r]),M.useEffect(()=>{s&&h.current&&(s instanceof m?h.current?.setOffset(s.x,s.y,s.z):s instanceof N?h.current?.setOffset(s.x,s.y):h.current?.setOffset(s[0],s[1],s[2]))},[s]),M.useEffect(()=>{t&&h.current&&h.current?.setSize(t[0],t[1])},[t]),M.useEffect(()=>{typeof i=="string"&&h.current&&h.current?.setColorHTML(i)},[i]),M.useEffect(()=>(h.current=new mn({...l,color:i,size:t,src:e,offset:s,visibility:o,rotation:r?r*Math.PI/180:0}),h.current&&n&&n(h.current),()=>{h.current&&a&&a(h.current)}),[n,a]),null},Hd=({color:o,objSrc:e,scale:t,visibility:i,_addGeoObject:r,_removeGeoObject:s,...n})=>{const a=M.useRef(null);return M.useEffect(()=>{t&&a.current&&a.current?.setScale(t)},[t]),M.useEffect(()=>{a.current&&(typeof o=="string"?a.current?.setColorHTML(o):o instanceof te?a.current?.setColor4v(o):Array.isArray(o)&&a.current?.setColor(...o))},[o]),M.useEffect(()=>{e&&a.current&&a.current?.setObjectSrc(e)},[e]),M.useEffect(()=>{typeof i=="boolean"&&a.current&&a.current?.setVisibility(i)},[i]),M.useEffect(()=>(a.current=new wn({color:o,objSrc:e,scale:t,visibility:i,...n}),a.current&&r&&r(a.current),()=>{a.current&&s&&s(a.current)}),[r,s]),null},Vd=({visibility:o,size:e,color:t,rotation:i,offset:r,text:s,face:n,isRTL:a,align:l,outline:h,outlineColor:c,opacity:d,_addLabel:u,_removeLabel:g,...f})=>{const p=M.useRef(null);return M.useEffect(()=>{typeof o=="boolean"&&p.current&&p.current?.setVisibility(o)},[o]),M.useEffect(()=>{typeof i=="number"&&p.current&&p.current?.setRotation(i*Math.PI/180)},[i]),M.useEffect(()=>{typeof e=="number"&&p.current&&p.current?.setSize(e)},[e]),M.useEffect(()=>{typeof h=="number"&&p.current&&p.current?.setOutline(h)},[h]),M.useEffect(()=>{typeof d=="number"&&p.current&&p.current?.setOpacity(d)},[d]),M.useEffect(()=>{typeof a=="boolean"&&p.current&&p.current?.setRtl(a)},[a]),M.useEffect(()=>{r&&p.current&&(r instanceof m?p.current?.setOffset(r.x,r.y,r.z):r instanceof N?p.current?.setOffset(r.x,r.y):p.current?.setOffset(r[0],r[1],r[2]))},[r]),M.useEffect(()=>{typeof s=="string"&&p.current&&p.current?.setText(s)},[s]),M.useEffect(()=>{typeof n=="string"&&p.current&&p.current?.setFace(n)},[n]),M.useEffect(()=>{typeof l=="string"&&p.current&&p.current?.setAlign(l)},[l]),M.useEffect(()=>{typeof t=="string"&&p.current&&p.current?.setColorHTML(t)},[t]),M.useEffect(()=>{typeof c=="string"&&p.current&&p.current?.setOutlineColorHTML(c)},[c]),M.useEffect(()=>(p.current=new Tn({...f,color:t,size:e,text:s,face:n,isRTL:a,align:l,outline:h,outlineColor:c,opacity:d,offset:r,visibility:o,rotation:i?i*Math.PI/180:0}),p.current&&u&&u(p.current),()=>{p.current&&g&&g(p.current)}),[u,g]),null};function Ud(o){switch(o.type){case"POINT":return Array.isArray(o.coordinates)&&o.coordinates.length>=2&&typeof o.coordinates[0]=="number";case"LINESTRING":return Array.isArray(o.coordinates)&&o.coordinates.every(e=>Array.isArray(e)&&e.length>=2&&typeof e[0]=="number");case"POLYGON":return Array.isArray(o.coordinates)&&o.coordinates.every(e=>Array.isArray(e)&&e.every(t=>Array.isArray(t)&&t.length>=2&&typeof t[0]=="number"));case"MULTIPOLYGON":return Array.isArray(o.coordinates)&&o.coordinates.every(e=>Array.isArray(e)&&e.every(t=>Array.isArray(t)&&t.every(i=>Array.isArray(i)&&i.length>=2&&typeof i[0]=="number")));case"MULTILINESTRING":return Array.isArray(o.coordinates)&&o.coordinates.every(e=>Array.isArray(e)&&e.every(t=>Array.isArray(t)&&t.length>=2&&typeof t[0]=="number"));default:return!1}}const Gd=o=>{const{visibility:e,fillColor:t,lineColor:i,strokeColor:r,lineWidth:s,strokeWidth:n,type:a,coordinates:l,_addGeometry:h,_removeGeometry:c}=o,d=M.useRef(null);if(!Ud({type:a,coordinates:l}))throw new Error(`Invalid coordinates for type ${a}`);return M.useEffect(()=>{typeof e=="boolean"&&d.current&&d.current.setVisibility(e)},[e]),M.useEffect(()=>{if(t!==void 0&&d.current){if(t instanceof te)d.current.setFillColor4v(t);else if(Array.isArray(t))d.current.setFillColor(...t);else if(typeof t=="string"&&d.current){const u=ji.htmlColorToRgba(t);d.current.setFillColor4v(u)}}},[t]),M.useEffect(()=>{if(i!==void 0&&d.current){if(i instanceof te)d.current.setLineColor4v(i);else if(Array.isArray(i))d.current.setLineColor(...i);else if(typeof i=="string"&&d.current){const u=ji.htmlColorToRgba(i);d.current.setLineColor4v(u)}}},[i]),M.useEffect(()=>{if(r!==void 0&&d.current){if(r instanceof te)d.current.setStrokeColor4v(r);else if(Array.isArray(r))d.current.setStrokeColor(...r);else if(typeof r=="string"&&d.current){const u=ji.htmlColorToRgba(r);d.current.setStrokeColor4v(u)}}},[r]),M.useEffect(()=>{typeof s=="number"&&d.current&&d.current.setLineWidth(s)},[s]),M.useEffect(()=>{typeof n=="number"&&d.current&&d.current.setStrokeWidth(n)},[n]),M.useEffect(()=>(d.current=new yn({...o,type:a,coordinates:l,style:{fillColor:t,lineColor:i,strokeColor:r,lineWidth:s,strokeWidth:n},visibility:e}),d.current&&h&&h(d.current),()=>{d.current&&c&&c(d.current)}),[h,c]),null},Ro=o=>Array.isArray(o)&&o.length>0&&o[0][0]instanceof m,Bo=o=>Array.isArray(o)&&o.length>0&&(o[0][0]instanceof P||o[0][0]instanceof Array),jd=o=>o.map(e=>e.map(t=>P.createFromArray(t))),qd=o=>typeof o=="string"||Array.isArray(o),ko=o=>Array.isArray(o)&&o.every(e=>Array.isArray(e)&&e.every(qd)),Yd=o=>Array.isArray(o)&&o.every(e=>Array.isArray(e)&&e.every(t=>Array.isArray(t)&&t.length===4&&t.every(i=>typeof i=="number"))),Io=o=>ko(o)?o.map(e=>e.map(t=>{const i=ji.htmlColorToRgba(t);return[i.x,i.y,i.z,i.w]})):o,Wd=({visibility:o,color:e,altitude:t,thickness:i,opacity:r,isClosed:s,pathColors:n,path:a,_addPolyline:l,_removePolyline:h,...c})=>{const d=M.useRef(null);return M.useEffect(()=>{typeof o=="boolean"&&d.current&&d.current?.setVisibility(o)},[o]),M.useEffect(()=>{typeof e=="string"&&d.current&&d.current?.setColorHTML(e)},[e]),M.useEffect(()=>{typeof t=="number"&&d.current&&d.current?.setAltitude(t)},[t]),M.useEffect(()=>{typeof i=="number"&&d.current&&d.current?.setThickness(i)},[i]),M.useEffect(()=>{typeof r=="number"&&d.current&&d.current?.setOpacity(r)},[r]),M.useEffect(()=>{if(d.current&&a!==void 0)if(Bo(a))d.current?.setPathLonLat(a);else if(Ro(a))d.current?.setPath3v(a);else{const u=jd(a);u&&d.current?.setPathLonLat(u)}},[a]),M.useEffect(()=>{if(n&&Array.isArray(n)&&n.length>0)if(ko(n)){const u=Io(n);u&&d.current?.setPathColors(u)}else Yd(n)&&d.current?.setPathColors(n)},[n]),M.useEffect(()=>(d.current=new Ln({...c,color:e,visibility:o,opacity:r,thickness:i,pathLonLat:a&&Bo(a)?a:void 0,path3v:a&&Ro(a)?a:void 0,pathColors:Io(n),altitude:t}),d.current&&l&&l(d.current),()=>{d.current&&h&&h(d.current)}),[l,h]),null},$d=o=>Array.isArray(o)&&o.length>0&&o[0][0]instanceof m,Xd=o=>Array.isArray(o)&&o.length>0&&o[0][0]instanceof P,zo=(o,e)=>e?$d(e)?e:Xd(e)?e.map(t=>t.map(i=>o.lonLatToCartesian(i))):e.map(t=>t.map(i=>o.lonLatToCartesian(P.createFromArray(i)))):[],Zd=({visibility:o,color:e,opacity:t,path:i,_addStrip:r,_removeStrip:s,...n})=>{const a=M.useRef(null),{globe:l}=ut();return M.useEffect(()=>{typeof o=="boolean"&&a.current&&a.current?.setVisibility(o)},[o]),M.useEffect(()=>{typeof t=="number"&&a.current&&a.current?.setOpacity(t)},[t]),M.useEffect(()=>{l&&i!==void 0&&a.current&&a.current?.setPath(zo(l.planet.ellipsoid,i))},[i]),M.useEffect(()=>{typeof e=="string"&&a.current&&a.current?.setColorHTML(e)},[e]),M.useEffect(()=>(l&&(a.current=new Mn({...n,color:e,visibility:o,path:zo(l.planet.ellipsoid,i),opacity:t}),a.current&&r&&r(a.current)),()=>{a.current&&s&&s(a.current)}),[r,s,l]),null},Qd=({visibility:o,lon:e,lat:t,alt:i,lonlat:r,name:s,children:n,yaw:a,pitch:l,roll:h,cartesian:c,_addEntity:d,_removeEntity:u,relativePosition:g,...f})=>{const{globe:p}=ut(),{addEntity:_,removeEntity:v,addBillboard:x,removeBillboard:y,addGeoObject:w,removeGeoObject:b,addLabel:C,removeLabel:E,addGeometry:T,removeGeometry:L,addPolyline:S,removePolyline:R,addStrip:z,removeStrip:F,addGltf:B,removeGltf:D}=M.useContext(Ts),A=M.useRef(null),[I,k]=M.useState(null),[U,Fe]=M.useState(null),[ge,ke]=M.useState(null),[Ee,ie]=M.useState(null),[xe,Ie]=M.useState(null),[Bt,Qt]=M.useState(null),[kt,Do]=M.useState(null),[Fo,sr]=M.useState(!1),ft=M.useRef([]);M.useEffect(()=>{r&&(r instanceof P||(r=P.createFromArray(r)),A.current?.setLonLat(r))},[r,I]),M.useEffect(()=>{typeof e=="number"&&typeof t=="number"&&typeof i=="number"&&A.current?.setLonLat2(e,t,i)},[e,t,i]),M.useEffect(()=>{typeof o=="boolean"&&A.current&&A.current?.setVisibility(o)},[o]),M.useEffect(()=>{Array.isArray(c)&&A.current&&A.current?.setCartesian(c[0],c[1],c[2])},[]),M.useEffect(()=>{typeof a=="number"&&A.current&&A.current?.setYaw(a*_r.RADIANS)},[a]),M.useEffect(()=>{typeof h=="number"&&A.current&&A.current?.setRoll(h*_r.RADIANS)},[h]),M.useEffect(()=>{typeof l=="number"&&A.current&&A.current?.setPitch(l*_r.RADIANS)},[l]),M.useEffect(()=>{typeof g=="boolean"&&A.current&&(A.current.relativePosition=g)},[g]),M.useLayoutEffect(()=>{if(!p||d)return;const Z=new V({lonlat:r||new P(e,t,i),name:s,...f});return A.current=Z,_(Z),sr(!0),xe&&A.current&&B(A.current,xe),ft.current.length&&A.current&&(ft.current.forEach(lt=>A.current.appendChild(lt)),ft.current=[]),()=>{A.current&&v(A.current),sr(!1)}},[p,_,v,d]),M.useEffect(()=>{if(!d)return;const Z=new V({visibility:o,name:s,yaw:a,pitch:l,roll:h,lonlat:r||new P(e,t,i),cartesian:c,relativePosition:g,...f});return A.current=Z,d(Z),xe&&A.current&&B(A.current,xe),sr(!0),ft.current.length&&A.current&&(ft.current.forEach(lt=>A.current.appendChild(lt)),ft.current=[]),()=>{u?.(Z),sr(!1)}},[d,u]),M.useEffect(()=>{xe&&A.current&&Fo&&B(A.current,xe)},[xe,Fo]),M.useEffect(()=>{I&&!A.current?.billboard&&A.current?.setBillboard(I)},[I]),M.useEffect(()=>{U&&!A.current?.geoObject&&A.current?.setGeoObject(U)},[U]),M.useEffect(()=>{ge&&!A.current?.label&&A.current?.setLabel(ge)},[ge]),M.useEffect(()=>{Ee&&!A.current?.geometry&&A.current?.setGeometry(Ee)},[Ee]),M.useEffect(()=>{Bt&&!A.current?.polyline&&A.current?.setPolyline(Bt)},[Bt]),M.useEffect(()=>{kt&&!A.current?.strip&&A.current?.setStrip(kt)},[kt]);const Oo=M.useCallback(Z=>{k(Z),A.current&&x(A.current,Z)},[x]),No=M.useCallback(()=>{A.current&&y(A.current),k(null)},[y]),Ho=M.useCallback(Z=>{Fe(Z),A.current&&w(A.current,Z)},[w]),Vo=M.useCallback(()=>{A.current&&b(A.current),Fe(null)},[b]),Uo=M.useCallback(Z=>{ke(Z),A.current&&C(A.current,Z)},[C]),Go=M.useCallback(()=>{A.current&&E(A.current),ke(null)},[E]),jo=M.useCallback(Z=>{ie(Z),A.current&&T(A.current,Z)},[T]),qo=M.useCallback(()=>{A.current&&L(A.current),ie(null)},[L]),Yo=M.useCallback(Z=>{Qt(Z),A.current&&S(A.current,Z)},[S]),Wo=M.useCallback(()=>{A.current&&R(A.current),Qt(null)},[R]),$o=M.useCallback(Z=>{Do(Z),A.current&&z(A.current,Z)},[z]),Xo=M.useCallback(()=>{A.current&&F(A.current),Do(null)},[F]),Zo=M.useCallback(Z=>{Ie(Z)},[]),Qo=M.useCallback(()=>{Ie(null)},[]),Ko=M.useCallback(Z=>{A.current?A.current.appendChild(Z):ft.current.push(Z)},[]),Jo=M.useCallback(Z=>{if(A.current){const lt=A.current.childEntities||[],el=lt.indexOf(Z);el!==-1&<.splice(el,1)}else ft.current=ft.current.filter(lt=>lt!==Z)},[]),eu=M.useMemo(()=>({_addEntity:Ko,_removeEntity:Jo,_addGeometry:jo,_removeGeometry:qo,_addLabel:Uo,_removeLabel:Go,_addBillboard:Oo,_removeBillboard:No,_addGeoObject:Ho,_removeGeoObject:Vo,_addPolyline:Yo,_removePolyline:Wo,_addStrip:$o,_removeStrip:Xo,_addGltf:Zo,_removeGltf:Qo}),[Ko,Jo,jo,qo,Uo,Go,Oo,No,Ho,Vo,Yo,Wo,$o,Xo,Zo,Qo]);return n?Ve.createElement(Ve.Fragment,null,Ve.Children.map(n,(Z,lt)=>Ve.isValidElement(Z)?Ve.cloneElement(Z,{...eu,key:Z.key??lt}):Z)):null},Kd=({src:o,_addGltf:e,_removeGltf:t})=>{const i=M.useRef(null);return M.useEffect(()=>{let r=!0;return(async()=>{const n=(await kd.loadGlb(o)).toEntities();i.current=n,r&&e&&e(n)})(),()=>{r=!1,t&&i.current&&t(i.current)}},[o]),null},Jd=({lon:o,lat:e,alt:t,lookLon:i,lookLat:r,lookAlt:s,viewAngle:n,...a})=>{const{globe:l}=ut();return M.useEffect(()=>{l&&typeof o=="number"&&typeof e=="number"&&typeof t=="number"&&l.planet.flyLonLat(new P(o,e,t),new P(i,r,s))},[o,e,t,i,r,s,l]),M.useEffect(()=>{l&&typeof n=="number"&&l.planet.camera.setViewAngle(n)},[n,l]),null};he.Billboard=Nd,he.Entity=Qd,he.GeoImage=zd,he.GeoObject=Hd,he.GeoVideo=Dd,he.Geometry=Gd,he.Globe=Id,he.GlobeContextProvider=El,he.Gltf=Kd,he.Label=Vd,he.Layer=Cs,he.PlanetCamera=Jd,he.Polyline=Wd,he.Strip=Zd,he.Vector=Od,he.VectorContext=Ts,he.XYZ=Fd,he.useGlobeContext=ut,Object.defineProperty(he,Symbol.toStringTag,{value:"Module"})}));
|
|
940
|
+
}`})]),this.sceneFramebuffer=new so(this.handler,{size:1,msaa:this._msaa,internalFormat:this._internalFormat,filter:"LINEAR"}),this.sceneFramebuffer.init(),this.blitFramebuffer=new Re(this.handler,{size:1,useDepth:!1,targets:[{internalFormat:this._internalFormat,format:this._format,type:this._type,filter:"NEAREST"}]}),this.blitFramebuffer.init(),this.toneMappingFramebuffer=new Re(this.handler,{useDepth:!1}),this.toneMappingFramebuffer.init(),this._fnScreenFrame=this._screenFrameMSAA,this.screenTexture={screen:this.toneMappingFramebuffer.textures[0],picking:this.pickingFramebuffer.textures[0],depth:this.screenDepthFramebuffer.textures[0],frustum:this.depthFramebuffer.textures[0]}}this.handler.ONCANVASRESIZE=()=>{this._resizeStart(),this.events.dispatch(this.events.resize,this.handler.canvas),this._resizeEnd(),this.events.dispatch(this.events.resizeend,this.handler.canvas)},this.screenFramePositionBuffer=this.handler.createArrayBuffer(new Float32Array([1,1,-1,1,1,-1,-1,-1]),2,4),this.outputTexture=this.screenTexture.screen,this._initializeRenderNodes(),this._initializeControls()}}_initializeControls(){let e=this.controls;this.controls={};for(let t in e)this.addControl(e[t])}resize(){this._resizeEnd()}setCurrentScreen(e){this._currentOutput=e,this.screenTexture[e]&&(this.outputTexture=this.screenTexture[e])}_resizeStart(){let e=this.handler.canvas;this.activeCamera.setViewportSize(e.width,e.height),this.sceneFramebuffer.setSize(.5*e.width,.5*e.height),this.blitFramebuffer&&this.blitFramebuffer.setSize(.5*e.width,.5*e.height,!0)}_resizeEnd(){let e=this.handler.canvas;this.activeCamera.setViewportSize(e.width,e.height),this.sceneFramebuffer.setSize(e.width,e.height),this.blitFramebuffer&&this.blitFramebuffer.setSize(e.width,e.height,!0),this.toneMappingFramebuffer&&this.toneMappingFramebuffer.setSize(e.width,e.height,!0),this.screenDepthFramebuffer&&this.screenDepthFramebuffer.setSize(e.clientWidth,e.clientHeight,!0),this.handler.gl.type==="webgl"?(this.screenTexture.screen=this.sceneFramebuffer.textures[0],this.screenTexture.picking=this.pickingFramebuffer.textures[0],this.screenTexture.depth=this.screenDepthFramebuffer.textures[0],this.screenTexture.frustum=this.depthFramebuffer.textures[0]):(this.screenTexture.screen=this.toneMappingFramebuffer.textures[0],this.screenTexture.picking=this.pickingFramebuffer.textures[0],this.screenTexture.depth=this.screenDepthFramebuffer.textures[0],this.screenTexture.frustum=this.depthFramebuffer.textures[0]),this.setCurrentScreen(this._currentOutput)}removeNode(e){e.remove()}addNode(e){this.renderNodes[e.name]?Qe.logWrn(`Node name ${e.name} already exists.`):(e.assign(this),this._renderNodesArr.unshift(e),this.renderNodes[e.name]=e)}_initializeRenderNodes(){for(let e=0;e<this._renderNodesArr.length;e++)this._renderNodesArr[e].initialize()}addNodeBefore(e,t){if(this.renderNodes[e.name])Qe.logWrn(`Node name ${e.name} already exists.`);else{e.assign(this),this.renderNodes[e.name]=e;for(let i=0;i<this._renderNodesArr.length;i++)if(this._renderNodesArr[i].isEqual(t)){this._renderNodesArr.splice(i,0,e);break}this._renderNodesArr.unshift(e)}}addNodes(e){for(let t=0;t<e.length;t++)this.addNode(e[t])}getMaxMSAA(e){let t=this.handler.gl;return t.getInternalformatParameter(t.RENDERBUFFER,t[e],t.SAMPLES)[0]}getMSAA(){return this._msaa}enqueueEntityCollectionsToDraw(e,t=0){this._entityCollections[t]||(this._entityCollections[t]=[]),this._entityCollections[t].push(...e)}markForDepthRefresh(){this._depthRefreshRequired=!0}_drawEntityCollections(e){let t=this._entityCollections[e];if(t.length){let i=this.handler.gl;this.enableBlendDefault();let r=t.length;for(;r--;)t[r]._fadingOpacity&&t[r].pointCloudHandler.draw();for(r=t.length;r--;){let n=t[r];t[r]._fadingOpacity&&(n.events.dispatch(n.events.draw,n),t[r].geoObjectHandler.draw())}for(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this.billboardsTextureAtlas.texture),r=t.length;r--;){let n=t[r];n._fadingOpacity&&n.billboardHandler.draw()}let s=this.fontAtlas.atlasesArr;for(r=0;r<s.length;r++)i.activeTexture(i.TEXTURE0+r),i.bindTexture(i.TEXTURE_2D,s[r].texture);for(r=t.length;r--;)t[r]._fadingOpacity&&t[r].labelHandler.draw();for(r=t.length;r--;)t[r]._fadingOpacity&&t[r].rayHandler.draw();for(r=t.length;r--;)t[r]._fadingOpacity&&t[r].polylineHandler.draw();for(r=t.length;r--;)t[r]._fadingOpacity&&t[r].stripHandler.draw()}}_drawPickingEntityCollections(e){let t=this._entityCollections[e];if(t.length){let i=t.length;for(;i--;)t[i]._fadingOpacity&&t[i].billboardHandler.drawPicking();for(i=t.length;i--;)t[i]._fadingOpacity&&t[i].geoObjectHandler.drawPicking();for(i=t.length;i--;)t[i]._fadingOpacity&&t[i].labelHandler.drawPicking();for(i=t.length;i--;)t[i]._fadingOpacity&&t[i].rayHandler.drawPicking();for(i=t.length;i--;)t[i]._visibility&&t[i].polylineHandler.drawPicking();for(i=t.length;i--;)t[i]._visibility&&t[i].stripHandler.drawPicking()}}_drawDepthEntityCollections(e){let t=this._entityCollections[e];if(t.length){let i=t.length;for(;i--;)t[i]._fadingOpacity&&t[i].geoObjectHandler.drawDepth()}}_clearEntityCollectionQueue(e){this._entityCollections[e].length=0,this._entityCollections[e]=[]}draw(){this.activeCamera.checkMoveEnd();let e=this.events,t=e.pointerEvent(),i=!e.mouseState.leftButtonDown&&!e.mouseState.rightButtonDown,r=e.touchState.touchStart||e.touchState.touchEnd;const s=t&&i||r||this._depthRefreshRequired;this._depthRefreshRequired=!1,e.handleEvents();let n=this.sceneFramebuffer;n.activate();let a=this.handler.gl;a.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT),this.enableBlendDefault(),e.dispatch(e.draw,this),this.activeCamera.checkFly();let l=this.activeCamera.frustums,h=this._renderNodesArr,c=l.length;for(;c--;){this.activeCamera.setCurrentFrustum(c),a.clear(a.DEPTH_BUFFER_BIT);let d=h.length;for(;d--;)h[d].preDrawNode();for(d=h.length;d--;)this.enableBlendDefault(),h[d].drawNode();this._drawEntityCollections(0),e.dispatch(e.drawtransparent,this),s&&this._drawPickingBuffer(0),this._drawDepthBuffer(0),this._clearEntityCollectionQueue(0)}for(let d=1;d<this._entityCollections.length;d++){a.clear(a.DEPTH_BUFFER_BIT);let u=l.length;for(;u--;)this.activeCamera.setCurrentFrustum(u),this._drawEntityCollections(d),s&&this._drawPickingBuffer(d),this._drawDepthBuffer(d);this._clearEntityCollectionQueue(d)}n.deactivate(),this.blitFramebuffer&&n.blitTo(this.blitFramebuffer,0),s&&(this._readPickingBuffer(),this._readDepthBuffer()),this._fnScreenFrame(),e.dispatch(e.postdraw,this),e.mouseState.wheelDelta=0,e.mouseState.justStopped=!1,e.mouseState.moving=!1,e.touchState.moving=!1}getImageDataURL(e="image/png",t=1){return this.draw(),this.handler.canvas?this.handler.canvas.toDataURL(e,t):""}_screenFrameMSAA(){let e=this.handler,t=e.programs.toneMapping,i=t._program,r=e.gl;r.disable(r.DEPTH_TEST),r.bindBuffer(r.ARRAY_BUFFER,this.screenFramePositionBuffer),r.vertexAttribPointer(i.attributes.corners,2,r.FLOAT,!1,0,0),this.toneMappingFramebuffer.activate(),r.clearColor(0,0,0,0),r.clear(r.COLOR_BUFFER_BIT),t.activate(),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,this.blitFramebuffer.textures[0]),r.uniform1i(i.uniforms.hdrBuffer,0),r.uniform1f(i.uniforms.gamma,this.gamma),r.uniform1f(i.uniforms.exposure,this.exposure),r.uniform1f(i.uniforms.whitepoint,this.whitepoint),r.drawArrays(r.TRIANGLE_STRIP,0,4),this.toneMappingFramebuffer.deactivate(),t=e.programs.screenFrame,i=t._program,t.activate(),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,this.outputTexture),r.uniform1i(i.uniforms.texture,0),r.drawArrays(r.TRIANGLE_STRIP,0,4),r.enable(r.DEPTH_TEST)}_screenFrameNoMSAA(){let e=this.handler,t=e.programs.screenFrame,i=t._program,r=e.gl;r.disable(r.DEPTH_TEST),t.activate(),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,this.outputTexture),r.uniform1i(i.uniforms.texture,0),r.bindBuffer(r.ARRAY_BUFFER,this.screenFramePositionBuffer),r.vertexAttribPointer(i.attributes.corners,2,r.FLOAT,!1,0,0),r.drawArrays(r.TRIANGLE_STRIP,0,4),r.enable(r.DEPTH_TEST)}_drawPickingBuffer(e){this.pickingFramebuffer.activate();let t=this.handler.gl;if(this.activeCamera.isFirstPass&&e===0?(t.clearColor(0,0,0,1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT)):t.clear(t.DEPTH_BUFFER_BIT),t.disable(t.BLEND),e===0){let i=this._pickingCallbacks;for(let r=0,s=i.length;r<s;r++)i[r].callback.call(i[r].sender)}this._drawPickingEntityCollections(e),t.enable(t.BLEND),this.pickingFramebuffer.deactivate()}_drawDepthBuffer(e){this.depthFramebuffer.activate();let t=this.handler,i=t.gl;if(i.disable(i.BLEND),this.activeCamera.isFirstPass&&e===0?(i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT)):i.clear(i.DEPTH_BUFFER_BIT),e===0){let r=this._depthCallbacks,s=r.length;for(;s--;)r[s].callback.call(r[s].sender)}if(this._drawDepthEntityCollections(e),this.depthFramebuffer.deactivate(),this._currentOutput==="depth"||this._currentOutput==="frustum"){this.screenDepthFramebuffer.activate();let r=t.programs.depth,s=r._program;i.bindBuffer(i.ARRAY_BUFFER,this.screenFramePositionBuffer),i.vertexAttribPointer(s.attributes.corners,2,i.FLOAT,!1,0,0),r.activate(),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this.depthFramebuffer.textures[1]),i.uniform1i(s.uniforms.depthTexture,0),i.drawArrays(i.TRIANGLE_STRIP,0,4),this.screenDepthFramebuffer.deactivate()}i.enable(i.BLEND)}_readDepthBuffer(e){this.depthFramebuffer.readPixelBuffersAsync(e)}_readPickingBuffer_webgl1(){this.pickingFramebuffer.readPixelBuffersAsync()}_readPickingBuffer_webgl2(){this.pickingFramebuffer.readPixelBuffersAsync()}readPickingColor(e,t,i){var r;let s=this.pickingFramebuffer.width,n=this.pickingFramebuffer.height;e=Math.round(e*s);let a=4*((t=Math.round(t*n))*s+e),l=(r=this.pickingFramebuffer)==null?void 0:r.pixelBuffers[0].data;l&&(i[0]=l[a],i[1]=l[a+1],i[2]=l[a+2])}readDepth(e,t,i){let r=new Float32Array(4),s=new Uint8Array(4);this.depthFramebuffer.readData(e,t,s,0),this.depthFramebuffer.readData(e,t,r,1),i[0]=r[0],i[1]=Math.round(s[0]/10)-1}getDistanceFromPixel(e){let t=this.activeCamera,i=this.handler.canvas,r=e.x/i.width,s=(i.height-e.y)/i.height;if(Zt[0]=Zt[1]=0,this.readDepth(r,s,Zt),Zt[1]===-1)return;let n=Zt[0],a=t.frustums[Zt[1]];if(!a)return;let l=new te(2*r-1,2*s-1,2*n-1,1),h=a.inverseProjectionMatrix.mulVec4(l),c=-h.z/h.w;if(t.isOrthographic)return c;let d=e.direction||t.unproject(e.x,e.y);return c/Math.max(1e-6,d.dot(t.getForward()))}getCartesianFromPixel(e){let t=this.getDistanceFromPixel(e);if(t){if(this.activeCamera.isOrthographic){let i=new m;return this.activeCamera.unproject(e.x,e.y,t,i),i}return(e.direction||this.activeCamera.unproject(e.x,e.y)).scaleTo(t).addA(this.activeCamera.eye)}}getCartesianFromPixelAsync(e){return new Promise(((t,i)=>{this._readDepthBuffer((()=>{t(this.getCartesianFromPixel(e))}))}))}getDepthMinDistance(){let e=this.handler.canvas,t=e.width,i=e.height,r=ar,s=i*t,n=new N;for(let a=0;a<s;a++){n.x=a%t,n.y=Math.floor(a/t);let l=this.getDistanceFromPixel(n);l&&l<r&&(r=l)}return r<ar?r:0}getDepthMinDistanceAsync(){return new Promise(((e,t)=>{this._readDepthBuffer((()=>{e(this.getDepthMinDistance())}))}))}async setOrthographicProjection(e){if(e!==this.activeCamera.isOrthographic){let t=await this.getDepthMinDistanceAsync();t&&e&&(this.activeCamera.focusDistance=t),this.activeCamera.isOrthographic=e,this.events.dispatch(this.events.projchanged,this.activeCamera)}}start(){this._initialized||this.initialize(),this.handler.start()}destroy(){for(let e in this.controls)this.controls[e].remove();for(let e=0;e<this._renderNodesArr.length;e++)this._renderNodesArr[e].remove();this.div=null,this._renderNodesArr=[],this.renderNodes={},this.activeCamera=null,this.controls={},this.controlsBag={},this.colorObjects.clear(),this._pickingCallbacks=[],this.pickingFramebuffer=null,this._tempPickingPix_=null,this._depthCallbacks=[],this.depthFramebuffer=null,this.sceneFramebuffer=null,this.blitFramebuffer=null,this.toneMappingFramebuffer=null,this._entityCollections=[[]],this.handler.ONCANVASRESIZE=null,this.handler.destroy(),this.handler=null,this._initialized=!1}}const Po="/res",So=class nr{constructor(e){this.$target=null,this._instanceID=`__globus${nr.__counter__++?nr.__counter__:""}__`,window[this._instanceID]=this,this._canvas=document.createElement("canvas"),this._canvas.id=`canvas${this._instanceID}`,this._canvas.style.width="100%",this._canvas.style.height="100%",this._canvas.style.display="block",this._canvas.style.opacity="0.0",this._canvas.style.transition="opacity 150ms",this.$inner=document.createElement("div"),this.$inner.classList.add("og-inner"),this.$inner.appendChild(this._canvas),this.$inner.attributions=document.createElement("div"),e.attributionContainer?e.attributionContainer.appendChild(this.$inner.attributions):(this.$inner.attributions.classList.add("og-attribution"),this.$inner.appendChild(this.$inner.attributions)),e.target&&this.attachTo(e.target);const t=n=>{n.preventDefault()};this._canvas.onmouseenter=function(){document.addEventListener("mousewheel",t,{capture:!1,passive:!1})},this._canvas.onmouseleave=function(){document.removeEventListener("mousewheel",t)},this.renderer=new Md(new Tt(this._canvas,{autoActivate:!1,pixelRatio:e.dpi||window.devicePixelRatio+.15,context:{alpha:e.transparentBackground,antialias:!1,premultipliedAlpha:!0,preserveDrawingBuffer:!1}}),{autoActivate:!1,msaa:e.msaa,fontsSrc:e.fontsSrc,gamma:e.gamma,exposure:e.exposure,...e.transparentBackground&&{clearColor:[0,0,0,0]}}),this.renderer.div=this.$inner,e.skybox&&this.renderer.addNode(e.skybox),this._planetName=e.name?e.name:"globus_planet_"+nr.__counter__,this.planet=new Ai({name:this._planetName,frustums:e.frustums,ellipsoid:e.ellipsoid,maxGridSize:e.maxGridSize,nightTextureSrc:e.nightTextureSrc===null?null:e.nightTextureSrc||`${e.resourcesSrc||Po}/night.png`,specularTextureSrc:e.specularTextureSrc===null?null:e.specularTextureSrc||`${e.resourcesSrc||Po}/spec.png`,minAltitude:e.minAltitude,maxAltitude:e.maxAltitude||15e6,maxEqualZoomAltitude:e.maxEqualZoomAltitude,minEqualZoomAltitude:e.minEqualZoomAltitude,minEqualZoomCameraSlope:e.minEqualZoomCameraSlope,quadTreeStrategyPrototype:e.quadTreeStrategyPrototype,maxLoadingRequests:e.maxLoadingRequests,atmosphereEnabled:e.atmosphereEnabled,transitionOpacityEnabled:e.transitionOpacityEnabled,atmosphereParameters:e.atmosphereParameters,minDistanceBeforeMemClear:e.minDistanceBeforeMemClear,vectorTileSize:e.vectorTileSize,maxNodesCount:e.maxNodesCount,transparentBackground:e.transparentBackground}),e.terrain?Array.isArray(e.terrain)?this.planet.setTerrain(e.terrain[0]):this.planet.setTerrain(e.terrain):this.planet.setTerrain(new ms),this.renderer.addNode(this.planet),e.controls?this.planet.addControls(e.controls):this.planet.addControls([new Ra,new ya,new Ma,new pa,new La,new nn,new ns]);const i=this.renderer.controls;let r;for(let n in i)if(i[n]instanceof Qr){r=i[n];break}r?this.sun=r:(this.sun=new Qr,this.planet.addControl(this.sun)),e.sun&&(e.sun.active===void 0||e.sun.active||this.sun.deactivate(),e.sun.stopped===!0&&this.sun.stop()),e.layers&&this.planet.addLayers(e.layers);let s=e.viewExtent;s&&(s instanceof Array?this.planet.viewExtentArr(s):this.planet.viewExtent(s)),(e.autoActivate||Ue(e.autoActivate))&&this.start()}start(){this.renderer.start(),this.fadeIn()}fadeIn(){this._canvas.style.opacity="1.0"}fadeOut(){this._canvas.style.opacity="0"}attachTo(e,t){let i;this.detach(),i=e instanceof HTMLElement?e:document.getElementById(e)||document.querySelector(e),i?(this.$target=i,t&&this.$target.firstChild?this.$target.insertBefore(this.$inner,this.$target.firstChild):i.appendChild(this.$inner)):console.warn(`Target container not found. Provided target: ${e}`)}detach(){this.$target&&(this.$target.removeChild(this.$inner),this.$target=null)}destroy(){this.detach(),this.planet.layers.forEach((e=>e.remove())),this.planet.destroy(),this.renderer.destroy(),window[this._instanceID]=null}};So.__counter__=0;let Rd=So;new pr(3396200,3389508),new pr(1737400,1737400);class Bd{static async load(e){const t=await fetch(e);if(!t.ok)throw new Error(`Unable to load '${e}'`);const i=await t.arrayBuffer(),r=new DataView(i);if(r.getUint32(0,!0)!==1179937895)throw new Error("Not a valid GLB");r.getUint32(4,!0);const s=this.getChunks(r);return this.parseChunks(s)}static getChunks(e){const t=[];let i=12;do{const r=this.getChunk(e,i);i+=8+r.length,t.push(r)}while(i<e.byteLength);return t}static getChunk(e,t){const i=e.getUint32(t,!0);return{length:i,type:this.getChunkType(e.getUint32(t+4,!0)),chunkData:e.buffer.slice(t+8,t+8+i)}}static getChunkType(e){switch(e){case 1313821514:return 0;case 5130562:return 1;default:return 2}}static parseChunks(e){let t,i=[];for(const r of e)switch(r.type){case 0:t=this.parseJsonChunk(r);break;case 1:i.push(r.chunkData)}if(t===void 0)throw new Error("GLB json data extraction failed");return{gltf:t,bin:i}}static parseJsonChunk(e){return JSON.parse(new TextDecoder().decode(e.chunkData))}}var Rt=(o=>(o[o.byte=5120]="byte",o[o.ubyte=5121]="ubyte",o[o.short=5122]="short",o[o.ushort=5123]="ushort",o[o.uint=5125]="uint",o[o.float=5126]="float",o))(Rt||{}),yt=(o=>(o.scalar="SCALAR",o.vec2="VEC2",o.vec3="VEC3",o.vec4="VEC4",o.mat2="MAT2",o.mat3="MAT3",o.mat4="MAT4",o))(yt||{}),ws=(o=>(o[o.points=0]="points",o[o.lines=1]="lines",o[o.lineLoop=2]="lineLoop",o[o.lineStrip=3]="lineStrip",o[o.triangles=4]="triangles",o[o.triangleStrip=5]="triangleStrip",o[o.triangleFan=6]="triangleFan",o))(ws||{});const Mo=class dt{constructor(e){var t;if(this.gltf=e,this._materials=[],this._images=[],this.meshes=[],((t=e.gltf.extensionsRequired)==null?void 0:t.includes("KHR_draco_mesh_compression"))&&dt._dracoDecoderModule===null)throw new Error("Unable to import GLTF. Draco decoder module is not connected");this._initImages(),this._initMaterials(),this._initMeshes()}static connectDracoDecoderModule(e){dt._dracoDecoderModule=e}static async loadGlb(e){const t=await Bd.load(e);return new dt(t)}getObjects3d(){const e=[];for(let t=0;t<this.meshes.length;t++)for(let i=0;i<this.meshes[t].primitives.length;i++)this.meshes[t].primitives[i].object3d!==void 0&&e.push(this.meshes[t].primitives[i].object3d);return e}toEntities(){const e=[];for(const t of this.gltf.gltf.scenes){if(t===void 0||t.nodes===void 0)return[];for(const i of t.nodes){const r=this.gltf.gltf.nodes[i];r.mesh===void 0&&r.children===void 0||e.push(this._nodeToEntity(r))}}return e}_nodeToEntity(e,t){const i=new V({name:e.name,cartesian:new m(0,0,0),relativePosition:t!==void 0});let r=null;if(e.mesh!==void 0&&(r=this.meshToEntity(this.meshes[e.mesh],t),i.appendChild(r)),e.matrix!==void 0){const s=new re;s.set(e.matrix),i.setCartesian3v(s.getPosition()),i.setDirectQuaternionRotation(s.getQuat()),i.setScale3v(s.getScaling())}if(e.translation!==void 0&&e.matrix===void 0&&(i.relativePosition=!0,i.setCartesian(e.translation[0],e.translation[1],e.translation[2])),e.rotation!==void 0&&e.matrix===void 0&&i.setDirectQuaternionRotation(new O(e.rotation[0],e.rotation[1],e.rotation[2],e.rotation[3])),e.scale!==void 0&&e.matrix===void 0&&i.setScale3v(new m(e.scale[0],e.scale[1],e.scale[2])),e.children!==void 0)for(const s of e.children){const n=this._nodeToEntity(this.gltf.gltf.nodes[s],i);r?r.appendChild(n):i.appendChild(n)}return i}meshToEntity(e,t){const i=new V({name:e.name,cartesian:new m(0,0,0),relativePosition:!0,independentPicking:!0});return e.primitives.map((r=>{i.appendChild(new V({name:r.name,relativePosition:!0,geoObject:{object3d:r.object3d,tag:r.name}}))})),i}_initImages(){if(this.gltf.gltf.images)for(const e of this.gltf.gltf.images)this._images.push({src:e.uri,element:this._getImage(e.mimeType,e.bufferView),mimeType:e.mimeType,name:e.name})}_getImage(e,t){if(t&&e){const i=this.gltf.gltf.bufferViews[t],r=URL.createObjectURL(new Blob([this.gltf.bin[i.buffer].slice(i.byteOffset,i.byteOffset+i.byteLength)],{type:e})),s=new Image;return s.src=r,s}}_initMaterials(){if(this.gltf.gltf.materials)for(const e of this.gltf.gltf.materials){const t={name:e.name,emissiveFactor:e.emissiveFactor,alphaMode:e.alphaMode,alphaCutoff:e.alphaCutoff,doubleSided:e.doubleSided};if(e.pbrMetallicRoughness){if(e.pbrMetallicRoughness.baseColorFactor&&(t.baseColorFactor=e.pbrMetallicRoughness.baseColorFactor),e.pbrMetallicRoughness.baseColorTexture){const i=this.gltf.gltf.textures[e.pbrMetallicRoughness.baseColorTexture.index].source;i!==void 0&&(t.baseColorTexture={image:this._images[i],texCoord:e.pbrMetallicRoughness.baseColorTexture.texCoord})}if(e.pbrMetallicRoughness.metallicRoughnessTexture){const i=this.gltf.gltf.textures[e.pbrMetallicRoughness.metallicRoughnessTexture.index].source;i!==void 0&&(t.metallicRoughnessTexture={image:this._images[i],texCoord:e.pbrMetallicRoughness.metallicRoughnessTexture.texCoord})}}if(e.normalTexture){const i=this.gltf.gltf.textures[e.normalTexture.index].source;i!==void 0&&(t.normalTexture={image:this._images[i],texCoord:e.normalTexture.texCoord,scale:e.normalTexture.scale})}if(e.occlusionTexture){const i=this.gltf.gltf.textures[e.occlusionTexture.index].source;i!==void 0&&(t.occlusionTexture={image:this._images[i],texCoord:e.occlusionTexture.texCoord,strength:e.occlusionTexture.strength})}if(e.emissiveTexture){const i=this.gltf.gltf.textures[e.emissiveTexture.index].source;i!==void 0&&(t.emissiveTexture={image:this._images[i],texCoord:e.emissiveTexture.texCoord})}this._materials.push(t)}}_initMeshes(){this.meshes=[];for(let e=0;e<this.gltf.gltf.meshes.length;e++){const t=this.gltf.gltf.meshes[e],i={name:t.name,primitives:[]};for(let r=0;r<t.primitives.length;r++)i.primitives.push(this._buildPrimitive(t,t.primitives[r],`${e}-${r}`));this.meshes.push(i)}}_buildPrimitive(e,t,i){var r,s;let n=null;const a=this._materials[t.material||0],l=(r=a.baseColorTexture)!=null&&r.texCoord?`TEXCOORD_${a.baseColorTexture.texCoord}`:"TEXCOORD_0";if((s=t.extensions)!=null&&s.KHR_draco_mesh_compression){const h=t.extensions.KHR_draco_mesh_compression,c=this.gltf.gltf.bufferViews[h.bufferView],d=c.byteOffset||0,u=dt._dracoDecoderModule,g=new u.Decoder,f=new u.DecoderBuffer;if(f.Init(new Int8Array(this.gltf.bin[c.buffer].slice(d,d+c.byteLength)),c.byteLength),g.GetEncodedGeometryType(f)!==u.TRIANGULAR_MESH)throw new Error("Draco compressed data is not a mesh");const p=new u.Mesh;if(!g.DecodeBufferToMesh(f,p).ok()||p.ptr===0)throw new Error("Failed to decode Draco mesh");const _=p.num_faces(),v=new Uint32Array(3*_),x=new u.DracoInt32Array;for(let w=0;w<_;w++)g.GetFaceFromMesh(p,w,x),v[3*w]=x.GetValue(0),v[3*w+1]=x.GetValue(1),v[3*w+2]=x.GetValue(2);u.destroy(x);const y={};for(const w in h.attributes){const b=h.attributes[w],C=g.GetAttributeByUniqueId(p,b),E=p.num_points(),T=C.num_components(),L=new u.DracoFloat32Array;g.GetAttributeFloatForAllPoints(p,C,L);const S=new Float32Array(E*T);for(let R=0;R<S.length;R++)S[R]=L.GetValue(R);u.destroy(L),y[w]=S}u.destroy(p),u.destroy(f),u.destroy(g),n={name:`${e.name}/${a.name}/${i}`,vertices:y.POSITION,indices:v,mode:t.mode?t.mode:ws.triangles,material:this._materials[t.material||0]||void 0,normals:y.NORMAL,texCoords:void 0}}else{const h=l?t.attributes[l]:void 0,c=h?this.gltf.gltf.accessors[h]:void 0;n={name:`${e.name}/${a.name}/${i}`,indices:t.indices?dt._access(this.gltf.gltf.accessors[t.indices],this.gltf):void 0,mode:t.mode?t.mode:ws.triangles,material:this._materials[t.material||0]||void 0,vertices:dt._access(this.gltf.gltf.accessors[t.attributes.POSITION],this.gltf),normals:dt._access(this.gltf.gltf.accessors[t.attributes.NORMAL],this.gltf),texCoords:c?dt._access(c,this.gltf):void 0}}if(n===null)throw new Error("Unable to build primitive");return n.object3d=dt._toObject3d(n),n}static _toObject3d(e){var t,i,r,s,n,a,l,h,c,d,u,g,f;return new $({name:e.name,vertices:Array.from(e.vertices),normals:Array.from(e.normals),texCoords:e.texCoords?Array.from(e.texCoords):void 0,indices:Array.from(e.indices),normalTextureImage:(i=(t=e.material)==null?void 0:t.normalTexture)==null?void 0:i.image.element,normalTextureSrc:(s=(r=e.material)==null?void 0:r.normalTexture)==null?void 0:s.image.src,colorTextureImage:(a=(n=e.material)==null?void 0:n.baseColorTexture)==null?void 0:a.image.element,colorTextureSrc:(h=(l=e.material)==null?void 0:l.baseColorTexture)==null?void 0:h.image.src,metallicRoughnessTextureImage:(d=(c=e.material)==null?void 0:c.occlusionTexture)==null?void 0:d.image.element,metallicRoughnessTextureSrc:(g=(u=e.material)==null?void 0:u.occlusionTexture)==null?void 0:g.image.src,color:(f=e.material)==null?void 0:f.baseColorFactor})}static _access(e,t){const i=t.gltf.bufferViews[e.bufferView],r=t.bin[i.buffer];let s=i.byteOffset||0;e.byteOffset!==void 0&&(s+=e.byteOffset);const n=r.slice(s,s+i.byteLength);switch(e.type){case yt.scalar:return this._getTensor(n,e,1,i.byteStride);case yt.vec2:return this._getTensor(n,e,2,i.byteStride);case yt.vec3:return this._getTensor(n,e,3,i.byteStride);case yt.vec4:case yt.mat2:return this._getTensor(n,e,4,i.byteStride);case yt.mat3:return this._getTensor(n,e,9,i.byteStride);case yt.mat4:return this._getTensor(n,e,16,i.byteStride);default:throw new Error("Unknown accessor type")}}static _getTensor(e,t,i,r){if(t.componentType===Rt.ushort)return new Uint16Array(e,0,t.count*i);if(t.componentType===Rt.short)return new Int16Array(e,0,t.count*i);if(t.componentType===Rt.uint)return new Uint32Array(e,0,t.count*i);if(t.componentType===Rt.float)return new Float32Array(e,0,t.count*i);if(t.componentType===Rt.ubyte)return new Uint8Array(e,0,t.count*i);if(t.componentType===Rt.byte)return new Int8Array(e,0,t.count*i);throw new Error("Unknown component type")}};Mo._dracoDecoderModule=null;let kd=Mo;const Id=({children:o,onDraw:e,...t})=>{const i=M.useRef(null),{setGlobe:r}=ut(),[s,n]=M.useState(t),a=M.useRef(null);return M.useEffect(()=>{if(a&&a.current&&t.viewExtent!==void 0){const l=t.viewExtent instanceof j?t.viewExtent:new j(new P(t.viewExtent[0],t.viewExtent[1]),new P(t.viewExtent[2],t.viewExtent[3]));a.current.planet.viewExtent(l)}},[t.viewExtent]),M.useEffect(()=>{a&&a.current&&t.atmosphereEnabled!==void 0&&(a.current.planet.atmosphereEnabled=t.atmosphereEnabled)},[t.atmosphereEnabled]),M.useEffect(()=>{a&&a.current&&t.sunActive!==void 0&&(t.sunActive?a.current?.sun.activate():a.current?.sun.deactivate())},[t.sunActive]),M.useEffect(()=>{if(a.current)i.current=a.current.$target;else{const l=new Eo("OSM"),h=new Ao("Microsoft Bing");a.current=new Rd({target:i.current,name:"Earth",terrain:new Co,layers:[l,h],autoActivate:!0,atmosphereEnabled:!0,...s}),e&&a.current.planet.events.on("draw",e)}return r(a.current),()=>{a.current&&(e&&a.current.planet.events.off("draw",e),a.current.destroy(),a.current=null)}},[s]),Ve.createElement("div",{style:{width:"100%",height:"100%"},ref:i},o)},zd=({name:o,...e})=>{const{globe:t}=ut(),i=M.useRef(null);return M.useEffect(()=>{typeof e.src=="string"&&i.current&&i.current?.setSrc(e.src)},[e.src]),M.useEffect(()=>{if(t)return i.current=new hs(o,e),t.planet.addLayer(i.current),()=>{i.current&&t.planet.removeLayer(i.current)}},[t]),null},Dd=({name:o,...e})=>{const{globe:t}=ut(),i=M.useRef(null);return M.useEffect(()=>{typeof e.src=="string"&&i.current&&i.current?.setSrc(e.src)},[e.src]),M.useEffect(()=>{if(t)return i.current=new To(o,e),t.planet.addLayer(i.current),()=>{i.current&&t.planet.removeLayer(i.current)}},[t]),null},Fd=({name:o,...e})=>{const{globe:t}=ut(),i=M.useRef(null);return M.useEffect(()=>{typeof e.url=="string"&&i.current&&i.current?.setUrl(e.url)},[e.url]),M.useEffect(()=>{if(t)return i.current=new Li(o,{...e}),t.planet.addLayer(i.current),()=>{i.current&&t.planet.removeLayer(i.current)}},[t]),Ve.createElement(Cs,{layerRef:i,name:o,...e})},Cs=({opacity:o,children:e,name:t,layerRef:i,...r})=>{const[s,n]=Ve.useState(!1);return M.useEffect(()=>{i&&i.current&&typeof o=="number"&&s&&(i.current.opacity=o)},[o]),M.useEffect(()=>(s&&i&&i.current&&(r.onVisibilityChange&&i.current?.events.on("visibilitychange",r.onVisibilityChange),r.onAdd&&i.current?.events.on("add",r.onAdd),r.onRemove&&i.current?.events.on("remove",r.onRemove),r.onMouseMove&&i.current?.events.on("mousemove",r.onMouseMove),r.onMouseEnter&&i.current?.events.on("mouseenter",r.onMouseEnter),r.onMouseLeave&&i.current?.events.on("mouseleave",r.onMouseLeave),r.onLclick&&i.current?.events.on("lclick",r.onLclick),r.onRclick&&i.current?.events.on("rclick",r.onRclick),r.onMclick&&i.current?.events.on("mclick",r.onMclick),r.onLdblclick&&i.current?.events.on("ldblclick",r.onLdblclick),r.onRdblclick&&i.current?.events.on("rdblclick",r.onRdblclick),r.onMdblclick&&i.current?.events.on("mdblclick",r.onMdblclick),r.onLup&&i.current?.events.on("lup",r.onLup),r.onRup&&i.current?.events.on("rup",r.onRup),r.onMup&&i.current?.events.on("mup",r.onMup),r.onLdown&&i.current?.events.on("ldown",r.onLdown),r.onRdown&&i.current?.events.on("rdown",r.onRdown),r.onMdown&&i.current?.events.on("mdown",r.onMdown),r.onLhold&&i.current?.events.on("lhold",r.onLhold),r.onRhold&&i.current?.events.on("rhold",r.onRhold),r.onMhold&&i.current?.events.on("mhold",r.onMhold),r.onMouseWheel&&i.current?.events.on("mousewheel",r.onMouseWheel),r.onTouchMove&&i.current?.events.on("touchmove",r.onTouchMove),r.onTouchStart&&i.current?.events.on("touchstart",r.onTouchStart),r.onTouchEnd&&i.current?.events.on("touchend",r.onTouchEnd),r.onDoubleTouch&&i.current?.events.on("doubletouch",r.onDoubleTouch)),()=>{r.onLclick&&i?.current?.events.off("lclick",r.onLclick),n(!1)}),[s]),i?.current&&!s&&n(!0),Ve.createElement(Ve.Fragment,null,e)},Ts=M.createContext({addEntity:()=>{},removeEntity:()=>{},addLabel:()=>{},removeLabel:()=>{},addBillboard:()=>{},removeBillboard:()=>{},addGeoObject:()=>{},removeGeoObject:()=>{},addGeometry:()=>{},removeGeometry:()=>{},addPolyline:()=>{},removePolyline:()=>{},addStrip:()=>{},removeStrip:()=>{},addGltf:(o,e)=>{},removeGltf:(o,e)=>{}}),Od=({visibility:o,children:e,name:t,...i})=>{const{globe:r}=ut(),s=M.useRef(null),[n,a]=M.useState([]),l=M.useRef(new Set);M.useEffect(()=>{typeof o=="boolean"&&s.current&&s.current.setVisibility(o)},[o]),M.useEffect(()=>{if(r)return s.current=new fe(t,i),r.planet.addLayer(s.current),i.onDraw&&s.current?.events.on("draw",i.onDraw),i.onMouseEnter&&s.current?.events.on("mouseenter",i.onMouseEnter),()=>{s.current&&(r.planet.removeLayer(s.current),i.onDraw&&s.current?.events.off("draw",i.onDraw),i.onMouseEnter&&s.current?.events.off("mouseenter",i.onMouseEnter))}},[r]),M.useEffect(()=>{if(s.current&&n.length>0){const L=n.filter(S=>!l.current.has(S));s.current.addEntities(L),L.forEach(S=>l.current.add(S))}},[n]);const h=M.useCallback(L=>{a(S=>S.includes(L)?S:[...S,L])},[]),c=M.useCallback(L=>{a(S=>S.filter(R=>R!==L)),s.current&&(s.current.removeEntity(L),l.current.delete(L))},[]),d=M.useCallback((L,S)=>{L.setBillboard(S)},[]),u=M.useCallback(L=>{L.billboard?.remove()},[]),g=M.useCallback((L,S)=>{L.setGeoObject(S)},[]),f=M.useCallback(L=>{L.geoObject?.remove()},[]),p=M.useCallback((L,S)=>{L.setLabel(S)},[]),_=M.useCallback(L=>{L.label?.remove()},[]),v=M.useCallback((L,S)=>{L.setGeometry(S)},[]),x=M.useCallback(L=>{L.geometry?.remove()},[]),y=M.useCallback((L,S)=>{L.setPolyline(S)},[]),w=M.useCallback(L=>{L.polyline?.remove()},[]),b=M.useCallback((L,S)=>{L.setStrip(S)},[]),C=M.useCallback(L=>{L.strip?.remove()},[]),E=M.useCallback((L,S)=>{L.appendChildren(S,!0)},[]),T=M.useCallback((L,S)=>{S.forEach(R=>{R.parent===L&&R.remove()})},[]);return Ve.createElement(Ts.Provider,{value:{addEntity:h,removeEntity:c,addBillboard:d,removeBillboard:u,addGeoObject:g,removeGeoObject:f,addLabel:p,removeLabel:_,addGeometry:v,removeGeometry:x,addPolyline:y,removePolyline:w,addStrip:b,removeStrip:C,addGltf:E,removeGltf:T}},Ve.createElement(Cs,{layerRef:s,name:t,...i},e))},Nd=({visibility:o,src:e,size:t,color:i,rotation:r,offset:s,_addBillboard:n,_removeBillboard:a,...l})=>{const h=M.useRef(null);return M.useEffect(()=>{typeof o=="boolean"&&h.current&&h.current?.setVisibility(o)},[o]),M.useEffect(()=>{typeof e=="string"&&h.current&&h.current?.setSrc(e)},[e]),M.useEffect(()=>{typeof r=="number"&&h.current&&h.current?.setRotation(r*Math.PI/180)},[r]),M.useEffect(()=>{s&&h.current&&(s instanceof m?h.current?.setOffset(s.x,s.y,s.z):s instanceof N?h.current?.setOffset(s.x,s.y):h.current?.setOffset(s[0],s[1],s[2]))},[s]),M.useEffect(()=>{t&&h.current&&h.current?.setSize(t[0],t[1])},[t]),M.useEffect(()=>{typeof i=="string"&&h.current&&h.current?.setColorHTML(i)},[i]),M.useEffect(()=>(h.current=new mn({...l,color:i,size:t,src:e,offset:s,visibility:o,rotation:r?r*Math.PI/180:0}),h.current&&n&&n(h.current),()=>{h.current&&a&&a(h.current)}),[n,a]),null},Hd=({color:o,objSrc:e,scale:t,visibility:i,_addGeoObject:r,_removeGeoObject:s,...n})=>{const a=M.useRef(null);return M.useEffect(()=>{t&&a.current&&a.current?.setScale(t)},[t]),M.useEffect(()=>{a.current&&(typeof o=="string"?a.current?.setColorHTML(o):o instanceof te?a.current?.setColor4v(o):Array.isArray(o)&&a.current?.setColor(...o))},[o]),M.useEffect(()=>{e&&a.current&&a.current?.setObjectSrc(e)},[e]),M.useEffect(()=>{typeof i=="boolean"&&a.current&&a.current?.setVisibility(i)},[i]),M.useEffect(()=>(a.current=new wn({color:o,objSrc:e,scale:t,visibility:i,...n}),a.current&&r&&r(a.current),()=>{a.current&&s&&s(a.current)}),[r,s]),null},Vd=({visibility:o,size:e,color:t,rotation:i,offset:r,text:s,face:n,isRTL:a,align:l,outline:h,outlineColor:c,opacity:d,_addLabel:u,_removeLabel:g,...f})=>{const p=M.useRef(null);return M.useEffect(()=>{typeof o=="boolean"&&p.current&&p.current?.setVisibility(o)},[o]),M.useEffect(()=>{typeof i=="number"&&p.current&&p.current?.setRotation(i*Math.PI/180)},[i]),M.useEffect(()=>{typeof e=="number"&&p.current&&p.current?.setSize(e)},[e]),M.useEffect(()=>{typeof h=="number"&&p.current&&p.current?.setOutline(h)},[h]),M.useEffect(()=>{typeof d=="number"&&p.current&&p.current?.setOpacity(d)},[d]),M.useEffect(()=>{typeof a=="boolean"&&p.current&&p.current?.setRtl(a)},[a]),M.useEffect(()=>{r&&p.current&&(r instanceof m?p.current?.setOffset(r.x,r.y,r.z):r instanceof N?p.current?.setOffset(r.x,r.y):p.current?.setOffset(r[0],r[1],r[2]))},[r]),M.useEffect(()=>{typeof s=="string"&&p.current&&p.current?.setText(s)},[s]),M.useEffect(()=>{typeof n=="string"&&p.current&&p.current?.setFace(n)},[n]),M.useEffect(()=>{typeof l=="string"&&p.current&&p.current?.setAlign(l)},[l]),M.useEffect(()=>{typeof t=="string"&&p.current&&p.current?.setColorHTML(t)},[t]),M.useEffect(()=>{typeof c=="string"&&p.current&&p.current?.setOutlineColorHTML(c)},[c]),M.useEffect(()=>(p.current=new Tn({...f,color:t,size:e,text:s,face:n,isRTL:a,align:l,outline:h,outlineColor:c,opacity:d,offset:r,visibility:o,rotation:i?i*Math.PI/180:0}),p.current&&u&&u(p.current),()=>{p.current&&g&&g(p.current)}),[u,g]),null};function Ud(o){switch(o.type){case"POINT":return Array.isArray(o.coordinates)&&o.coordinates.length>=2&&typeof o.coordinates[0]=="number";case"LINESTRING":return Array.isArray(o.coordinates)&&o.coordinates.every(e=>Array.isArray(e)&&e.length>=2&&typeof e[0]=="number");case"POLYGON":return Array.isArray(o.coordinates)&&o.coordinates.every(e=>Array.isArray(e)&&e.every(t=>Array.isArray(t)&&t.length>=2&&typeof t[0]=="number"));case"MULTIPOLYGON":return Array.isArray(o.coordinates)&&o.coordinates.every(e=>Array.isArray(e)&&e.every(t=>Array.isArray(t)&&t.every(i=>Array.isArray(i)&&i.length>=2&&typeof i[0]=="number")));case"MULTILINESTRING":return Array.isArray(o.coordinates)&&o.coordinates.every(e=>Array.isArray(e)&&e.every(t=>Array.isArray(t)&&t.length>=2&&typeof t[0]=="number"));default:return!1}}const Gd=o=>{const{visibility:e,fillColor:t,lineColor:i,strokeColor:r,lineWidth:s,strokeWidth:n,type:a,coordinates:l,_addGeometry:h,_removeGeometry:c}=o,d=M.useRef(null);if(!Ud({type:a,coordinates:l}))throw new Error(`Invalid coordinates for type ${a}`);return M.useEffect(()=>{typeof e=="boolean"&&d.current&&d.current.setVisibility(e)},[e]),M.useEffect(()=>{if(t!==void 0&&d.current){if(t instanceof te)d.current.setFillColor4v(t);else if(Array.isArray(t))d.current.setFillColor(...t);else if(typeof t=="string"&&d.current){const u=ji.htmlColorToRgba(t);d.current.setFillColor4v(u)}}},[t]),M.useEffect(()=>{if(i!==void 0&&d.current){if(i instanceof te)d.current.setLineColor4v(i);else if(Array.isArray(i))d.current.setLineColor(...i);else if(typeof i=="string"&&d.current){const u=ji.htmlColorToRgba(i);d.current.setLineColor4v(u)}}},[i]),M.useEffect(()=>{if(r!==void 0&&d.current){if(r instanceof te)d.current.setStrokeColor4v(r);else if(Array.isArray(r))d.current.setStrokeColor(...r);else if(typeof r=="string"&&d.current){const u=ji.htmlColorToRgba(r);d.current.setStrokeColor4v(u)}}},[r]),M.useEffect(()=>{typeof s=="number"&&d.current&&d.current.setLineWidth(s)},[s]),M.useEffect(()=>{typeof n=="number"&&d.current&&d.current.setStrokeWidth(n)},[n]),M.useEffect(()=>(d.current=new yn({...o,type:a,coordinates:l,style:{fillColor:t,lineColor:i,strokeColor:r,lineWidth:s,strokeWidth:n},visibility:e}),d.current&&h&&h(d.current),()=>{d.current&&c&&c(d.current)}),[h,c]),null},Ro=o=>Array.isArray(o)&&o.length>0&&o[0][0]instanceof m,Bo=o=>Array.isArray(o)&&o.length>0&&(o[0][0]instanceof P||o[0][0]instanceof Array),jd=o=>o.map(e=>e.map(t=>P.createFromArray(t))),qd=o=>typeof o=="string"||Array.isArray(o),ko=o=>Array.isArray(o)&&o.every(e=>Array.isArray(e)&&e.every(qd)),Yd=o=>Array.isArray(o)&&o.every(e=>Array.isArray(e)&&e.every(t=>Array.isArray(t)&&t.length===4&&t.every(i=>typeof i=="number"))),Io=o=>ko(o)?o.map(e=>e.map(t=>{const i=ji.htmlColorToRgba(t);return[i.x,i.y,i.z,i.w]})):o,Wd=({visibility:o,color:e,altitude:t,thickness:i,opacity:r,isClosed:s,pathColors:n,path:a,_addPolyline:l,_removePolyline:h,...c})=>{const d=M.useRef(null);return M.useEffect(()=>{typeof o=="boolean"&&d.current&&d.current?.setVisibility(o)},[o]),M.useEffect(()=>{typeof e=="string"&&d.current&&d.current?.setColorHTML(e)},[e]),M.useEffect(()=>{typeof t=="number"&&d.current&&d.current?.setAltitude(t)},[t]),M.useEffect(()=>{typeof i=="number"&&d.current&&d.current?.setThickness(i)},[i]),M.useEffect(()=>{typeof r=="number"&&d.current&&d.current?.setOpacity(r)},[r]),M.useEffect(()=>{if(d.current&&a!==void 0)if(Bo(a))d.current?.setPathLonLat(a);else if(Ro(a))d.current?.setPath3v(a);else{const u=jd(a);u&&d.current?.setPathLonLat(u)}},[a]),M.useEffect(()=>{if(n&&Array.isArray(n)&&n.length>0)if(ko(n)){const u=Io(n);u&&d.current?.setPathColors(u)}else Yd(n)&&d.current?.setPathColors(n)},[n]),M.useEffect(()=>(d.current=new Ln({...c,color:e,visibility:o,opacity:r,thickness:i,pathLonLat:a&&Bo(a)?a:void 0,path3v:a&&Ro(a)?a:void 0,pathColors:Io(n),altitude:t}),d.current&&l&&l(d.current),()=>{d.current&&h&&h(d.current)}),[l,h]),null},$d=o=>Array.isArray(o)&&o.length>0&&o[0][0]instanceof m,Xd=o=>Array.isArray(o)&&o.length>0&&o[0][0]instanceof P,zo=(o,e)=>e?$d(e)?e:Xd(e)?e.map(t=>t.map(i=>o.lonLatToCartesian(i))):e.map(t=>t.map(i=>o.lonLatToCartesian(P.createFromArray(i)))):[],Zd=({visibility:o,color:e,opacity:t,path:i,_addStrip:r,_removeStrip:s,...n})=>{const a=M.useRef(null),{globe:l}=ut();return M.useEffect(()=>{typeof o=="boolean"&&a.current&&a.current?.setVisibility(o)},[o]),M.useEffect(()=>{typeof t=="number"&&a.current&&a.current?.setOpacity(t)},[t]),M.useEffect(()=>{l&&i!==void 0&&a.current&&a.current?.setPath(zo(l.planet.ellipsoid,i))},[i]),M.useEffect(()=>{typeof e=="string"&&a.current&&a.current?.setColorHTML(e)},[e]),M.useEffect(()=>(l&&(a.current=new Mn({...n,color:e,visibility:o,path:zo(l.planet.ellipsoid,i),opacity:t}),a.current&&r&&r(a.current)),()=>{a.current&&s&&s(a.current)}),[r,s,l]),null},Qd=({visibility:o,lon:e,lat:t,alt:i,lonlat:r,name:s,children:n,yaw:a,pitch:l,roll:h,cartesian:c,_addEntity:d,_removeEntity:u,relativePosition:g,...f})=>{const{globe:p}=ut(),{addEntity:_,removeEntity:v,addBillboard:x,removeBillboard:y,addGeoObject:w,removeGeoObject:b,addLabel:C,removeLabel:E,addGeometry:T,removeGeometry:L,addPolyline:S,removePolyline:R,addStrip:z,removeStrip:F,addGltf:B,removeGltf:D}=M.useContext(Ts),A=M.useRef(null),[I,k]=M.useState(null),[U,Fe]=M.useState(null),[ge,ke]=M.useState(null),[Ee,ie]=M.useState(null),[xe,Ie]=M.useState(null),[Bt,Qt]=M.useState(null),[kt,Do]=M.useState(null),[Fo,sr]=M.useState(!1),ft=M.useRef([]);M.useEffect(()=>{r&&(r instanceof P||(r=P.createFromArray(r)),A.current?.setLonLat(r))},[r,I]),M.useEffect(()=>{typeof e=="number"&&typeof t=="number"&&typeof i=="number"&&A.current?.setLonLat2(e,t,i)},[e,t,i]),M.useEffect(()=>{typeof o=="boolean"&&A.current&&A.current?.setVisibility(o)},[o]),M.useEffect(()=>{Array.isArray(c)&&A.current&&A.current?.setCartesian(c[0],c[1],c[2])},[]),M.useEffect(()=>{typeof a=="number"&&A.current&&A.current?.setYaw(a*_r.RADIANS)},[a]),M.useEffect(()=>{typeof h=="number"&&A.current&&A.current?.setRoll(h*_r.RADIANS)},[h]),M.useEffect(()=>{typeof l=="number"&&A.current&&A.current?.setPitch(l*_r.RADIANS)},[l]),M.useEffect(()=>{typeof g=="boolean"&&A.current&&(A.current.relativePosition=g)},[g]),M.useLayoutEffect(()=>{if(!p||d)return;const Z=new V({lonlat:r||new P(e,t,i),name:s,...f});return A.current=Z,_(Z),sr(!0),xe&&A.current&&B(A.current,xe),ft.current.length&&A.current&&(ft.current.forEach(lt=>A.current.appendChild(lt)),ft.current=[]),()=>{A.current&&v(A.current),sr(!1)}},[p,_,v,d]),M.useEffect(()=>{if(!d)return;const Z=new V({visibility:o,name:s,yaw:a,pitch:l,roll:h,lonlat:r||new P(e,t,i),cartesian:c,relativePosition:g,...f});return A.current=Z,d(Z),xe&&A.current&&B(A.current,xe),sr(!0),ft.current.length&&A.current&&(ft.current.forEach(lt=>A.current.appendChild(lt)),ft.current=[]),()=>{u?.(Z),sr(!1)}},[d,u]),M.useEffect(()=>{xe&&A.current&&Fo&&B(A.current,xe)},[xe,Fo]),M.useEffect(()=>{I&&!A.current?.billboard&&A.current?.setBillboard(I)},[I]),M.useEffect(()=>{U&&!A.current?.geoObject&&A.current?.setGeoObject(U)},[U]),M.useEffect(()=>{ge&&!A.current?.label&&A.current?.setLabel(ge)},[ge]),M.useEffect(()=>{Ee&&!A.current?.geometry&&A.current?.setGeometry(Ee)},[Ee]),M.useEffect(()=>{Bt&&!A.current?.polyline&&A.current?.setPolyline(Bt)},[Bt]),M.useEffect(()=>{kt&&!A.current?.strip&&A.current?.setStrip(kt)},[kt]);const Oo=M.useCallback(Z=>{k(Z),A.current&&x(A.current,Z)},[x]),No=M.useCallback(()=>{A.current&&y(A.current),k(null)},[y]),Ho=M.useCallback(Z=>{Fe(Z),A.current&&w(A.current,Z)},[w]),Vo=M.useCallback(()=>{A.current&&b(A.current),Fe(null)},[b]),Uo=M.useCallback(Z=>{ke(Z),A.current&&C(A.current,Z)},[C]),Go=M.useCallback(()=>{A.current&&E(A.current),ke(null)},[E]),jo=M.useCallback(Z=>{ie(Z),A.current&&T(A.current,Z)},[T]),qo=M.useCallback(()=>{A.current&&L(A.current),ie(null)},[L]),Yo=M.useCallback(Z=>{Qt(Z),A.current&&S(A.current,Z)},[S]),Wo=M.useCallback(()=>{A.current&&R(A.current),Qt(null)},[R]),$o=M.useCallback(Z=>{Do(Z),A.current&&z(A.current,Z)},[z]),Xo=M.useCallback(()=>{A.current&&F(A.current),Do(null)},[F]),Zo=M.useCallback(Z=>{Ie(Z)},[]),Qo=M.useCallback(()=>{Ie(null)},[]),Ko=M.useCallback(Z=>{A.current?A.current.appendChild(Z):ft.current.push(Z)},[]),Jo=M.useCallback(Z=>{if(A.current){const lt=A.current.childEntities||[],el=lt.indexOf(Z);el!==-1&<.splice(el,1)}else ft.current=ft.current.filter(lt=>lt!==Z)},[]),eu=M.useMemo(()=>({_addEntity:Ko,_removeEntity:Jo,_addGeometry:jo,_removeGeometry:qo,_addLabel:Uo,_removeLabel:Go,_addBillboard:Oo,_removeBillboard:No,_addGeoObject:Ho,_removeGeoObject:Vo,_addPolyline:Yo,_removePolyline:Wo,_addStrip:$o,_removeStrip:Xo,_addGltf:Zo,_removeGltf:Qo}),[Ko,Jo,jo,qo,Uo,Go,Oo,No,Ho,Vo,Yo,Wo,$o,Xo,Zo,Qo]);return n?Ve.createElement(Ve.Fragment,null,Ve.Children.map(n,(Z,lt)=>Ve.isValidElement(Z)?Ve.cloneElement(Z,{...eu,key:Z.key??lt}):Z)):null},Kd=({src:o,_addGltf:e,_removeGltf:t})=>{const i=M.useRef(null);return M.useEffect(()=>{let r=!0;return(async()=>{const n=(await kd.loadGlb(o)).toEntities();i.current=n,r&&e&&e(n)})(),()=>{r=!1,t&&i.current&&t(i.current)}},[o]),null},Jd=({lon:o,lat:e,alt:t,lookLon:i,lookLat:r,lookAlt:s,viewAngle:n,...a})=>{const{globe:l}=ut();return M.useEffect(()=>{l&&typeof o=="number"&&typeof e=="number"&&typeof t=="number"&&l.planet.flyLonLat(new P(o,e,t),new P(i,r,s))},[o,e,t,i,r,s,l]),M.useEffect(()=>{l&&typeof n=="number"&&l.planet.camera.setViewAngle(n)},[n,l]),null};he.Billboard=Nd,he.Entity=Qd,he.GeoImage=zd,he.GeoObject=Hd,he.GeoVideo=Dd,he.Geometry=Gd,he.Globe=Id,he.GlobeContextProvider=El,he.Gltf=Kd,he.Label=Vd,he.Layer=Cs,he.PlanetCamera=Jd,he.Polyline=Wd,he.Strip=Zd,he.Vector=Od,he.VectorContext=Ts,he.XYZ=Fd,he.useGlobeContext=ut,Object.defineProperty(he,Symbol.toStringTag,{value:"Module"})}));
|
|
941
941
|
//# sourceMappingURL=index.umd.cjs.map
|