@arcgis/core 4.24.0-next.20220429 → 4.24.0-next.20220430

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.
Files changed (52) hide show
  1. package/assets/esri/core/workers/RemoteClient.js +1 -1
  2. package/assets/esri/core/workers/chunks/{3a43a2918b44781aaf85.js → 055a0ebf22a82f859474.js} +1 -1
  3. package/assets/esri/core/workers/chunks/{3273b6be43eeb49ee842.js → 0b12ff7b2ed2838afbb8.js} +1 -1
  4. package/assets/esri/core/workers/chunks/0e25548573baf855e394.js +1 -0
  5. package/assets/esri/core/workers/chunks/{c388ac33496f004d56f3.js → 135a90ae61f3b3cae91b.js} +1 -1
  6. package/assets/esri/core/workers/chunks/{54f9b1ab9d472bf4baca.js → 1facbda248863cf72cbd.js} +1 -1
  7. package/assets/esri/core/workers/chunks/2133499e642193f6738f.js +1 -0
  8. package/assets/esri/core/workers/chunks/{3c572629f46e5093223c.js → 30333a95dc0a44e23fb5.js} +1 -1
  9. package/assets/esri/core/workers/chunks/{7afe89eafab00afb31f2.js → 30837d93116f0337972f.js} +1 -1
  10. package/assets/esri/core/workers/chunks/31df729c17470245288c.js +2 -0
  11. package/assets/esri/core/workers/chunks/{c0bf663240df7be68131.js.LICENSE.txt → 31df729c17470245288c.js.LICENSE.txt} +1 -1
  12. package/assets/esri/core/workers/chunks/{e5d6f3815ecab8560404.js → 4130ea1f5a9f197168d7.js} +1 -1
  13. package/assets/esri/core/workers/chunks/{f5855075104c12bf71d8.js → 59e341b2db44351bf557.js} +1 -1
  14. package/assets/esri/core/workers/chunks/{73630d52768e3d932f30.js → 5a10b58533b4116115ac.js} +1 -1
  15. package/assets/esri/core/workers/chunks/{dc193247a1980360ec4f.js → 8e98ff9404a802352037.js} +1 -1
  16. package/assets/esri/core/workers/chunks/{863cfe35ee640bac103f.js → 94e51fe1c539df6257c2.js} +1 -1
  17. package/assets/esri/core/workers/chunks/{cbe7e6283a427a618d4b.js → 9519a02b9b8db88a3150.js} +1 -1
  18. package/assets/esri/core/workers/chunks/a59ee7d2b98c85f27dd2.js +1 -0
  19. package/assets/esri/core/workers/chunks/{92ef9b0c61640e0ecbb4.js → a5dbab94697757c87c49.js} +1 -1
  20. package/assets/esri/core/workers/chunks/{147d3ee9aa81d7b2b7fa.js → a6406a248b7b2ed65f35.js} +1 -1
  21. package/assets/esri/core/workers/chunks/{ebdf61eb364ac0856f40.js → acbd0f4d72d1f5d8e4e8.js} +1 -1
  22. package/assets/esri/core/workers/chunks/ad68fe924456d6d7d4f0.js +1 -0
  23. package/assets/esri/core/workers/chunks/b06c949fc7d08e376a5f.js +1 -0
  24. package/assets/esri/core/workers/chunks/c9b09099488d0e719dfb.js +1 -0
  25. package/assets/esri/core/workers/chunks/{4a05d0dfa73ff570e1fa.js → d15e6662d90718411d62.js} +1 -1
  26. package/assets/esri/core/workers/chunks/{b74b9dceabbf7b1aec39.js → d16aac3461af9cee0c29.js} +1 -1
  27. package/assets/esri/core/workers/chunks/{b9d9be39cd64f28dd478.js → d60dd3e1028f714f2258.js} +1 -1
  28. package/assets/esri/core/workers/chunks/{cab6decfcb3f596a3837.js → d8c59b1d73650c060dfb.js} +1 -1
  29. package/assets/esri/core/workers/chunks/{d24339b37cc9316e6d99.js → dcb6e1b33402d7fa455b.js} +1 -1
  30. package/assets/esri/core/workers/chunks/{a8da24116180d708cf81.js → df653bca2b14dffc82d1.js} +1 -1
  31. package/chunks/index.js +1 -1
  32. package/config.js +1 -1
  33. package/interfaces.d.ts +8 -0
  34. package/layers/mixins/PortalLayer.js +1 -1
  35. package/package.json +2 -2
  36. package/request.js +1 -1
  37. package/support/revision.js +1 -1
  38. package/views/2d/engine/vectorTiles/TileParser.js +1 -1
  39. package/views/2d/layers/features/support/GraphicsReader.js +1 -1
  40. package/views/2d/layers/graphics/GraphicsView2D.js +1 -1
  41. package/views/3d/terrain/PatchRenderData.js +1 -1
  42. package/views/3d/terrain/TerrainSurface.js +1 -1
  43. package/views/3d/terrain/Tile.js +1 -1
  44. package/widgets/FeatureTable/Grid/Grid.js +2 -2
  45. package/widgets/Sketch/SketchViewModel.js +1 -1
  46. package/assets/esri/core/workers/chunks/3f6b17c9d2629ed396da.js +0 -1
  47. package/assets/esri/core/workers/chunks/68d57660c7c71b82ff3c.js +0 -1
  48. package/assets/esri/core/workers/chunks/6ef8de3aa9a8d9c22161.js +0 -1
  49. package/assets/esri/core/workers/chunks/b548bf032c8af34fe155.js +0 -1
  50. package/assets/esri/core/workers/chunks/bbcae04235830debd814.js +0 -1
  51. package/assets/esri/core/workers/chunks/c0bf663240df7be68131.js +0 -2
  52. package/assets/esri/core/workers/chunks/cd9668acbe3babd2b188.js +0 -1
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.24/esri/copyright.txt for details.
4
4
  */
5
- import{clamp as e}from"../../../core/mathUtils.js";import{isSome as t,abortMaybe as i,isNone as s}from"../../../core/maybe.js";import n from"../../../core/ObjectPool.js";import{c as r,b as a}from"../../../chunks/vec2.js";import{a as o}from"../../../chunks/vec2f64.js";import{b as l,p as h,e as d,g as u,a as c,l as g}from"../../../chunks/vec3.js";import{c as f,u as p}from"../../../chunks/vec3f64.js";import{E as _}from"../../../chunks/common.js";import{getReferenceEllipsoid as m}from"../../../geometry/projectionEllipsoid.js";import{create as T,equals as E}from"../../../geometry/support/aaBoundingRect.js";import{c as A}from"../../../chunks/sphere.js";import{VectorTile as y}from"../../2d/engine/vectorTiles/VectorTile.js";import{ImageWithType as v}from"../support/StreamDataLoader.js";import{ElevationBounds as S}from"./ElevationBounds.js";import{ElevationTileAgent as L}from"./ElevationTileAgent.js";import{NeighborIndex as M,LODSnapping as N,TextureUpdate as I}from"./interfaces.js";import{LayerClass as O,LayerClasses as D}from"./LayerClass.js";import{MapTileAgent as b}from"./MapTileAgent.js";import{RasterTile as U}from"./RasterTile.js";import{MAX_PATCH_TESSELATION as x,getElevationDesiredResolutionLevel as R}from"./TerrainConst.js";import{weakAssert as j,getLayerWithExtentRange as C,internalAssert as H,ENABLE_WATERPROOFNESS_TESTS as W}from"./terrainUtils.js";import{TILE_AGENT_DONE as P}from"./TileAgent.js";import{TilePerLayerInfo as B}from"./TilePerLayerInfo.js";import G from"./TileTexture.js";import{TileUpdate as V}from"./TileUpdate.js";import{fallsWithinLayer as w}from"./tileUtils.js";import{getGpuMemoryUsage as q}from"../../webgl/Util.js";const F=f(),k=f(),X=f(),z=.1;class J{constructor(){this.fovX=0,this.fovY=0,this.relativeWidthLimit=0,this.relativeHeightLimit=0,this.maxLod=0,this.angledSplitBias=0,this.aboveGround=!0}}class Y{constructor(){this.lij=[0,0,0],this._children=[null,null,null,null],this._pendingUpdates=0,this._dirty=!0,this._previouslyRendered=!1,this.extent=T(),this._elevationBounds=o(),this.layerInfo=[[],[]],this.extentInRadians=T(),this.centerAtSeaLevel=f(),this._center=[f(),A(),f()],this.up=p(),this._isWithinClippingArea=!0,this._intersectsClippingArea=!0,this._maxTesselation=0,this._usedMemory=te,this._mapTileMemory=0,this._mapDataRefCount=0,this._screenDepth=0,this.renderOrder=0,this._edgeLen=0,this._edgeLen2=0,this._curvatureHeight=0}static prune(){K.prune(0),Z.prune(0),B.prune()}get usedMemory(){return this._usedMemory===te&&this._updateMemoryUsed(),this._usedMemory+(this.isCached?0:this.mapTileMemory)}get cachedMemory(){return this.isCached?this.mapTileMemory:0}get mapTileMemory(){this._usedMemory===te&&this._updateMemoryUsed();let e=this._mapTileMemory;for(const{data:t}of this.layerInfo[O.MAP])t instanceof y&&(e+=t.memoryUsage);return e}get isCached(){return!this.shouldLoad&&this._mapDataRefCount<=0}get maxTesselation(){return this._maxTesselation}get isWithinClippingArea(){return this._isWithinClippingArea}get intersectsClippingArea(){return this._intersectsClippingArea}get clippingArea(){return this._clippingArea}get parent(){return this._parent}get children(){return this._children}get surface(){return this._surface}get elevationBounds(){return this._elevationBounds}get level(){return this.lij[0]}get key(){return`${this.lij[0]}/${this.lij[1]}/${this.lij[2]}`}get edgeLen(){return this._edgeLen}get radius(){return this._center[ie.MIDDLE][3]}get screenDepth(){return this._screenDepth}get visible(){return this._dirty&&this.computeVisibility(),this._visible}computeVisibility(){this._dirty=!1;const e=this._intersectsClippingArea&&this._isVisible(this.surface.frustum);return e!==this._visible&&(this._visible=e,this._surface.emit("tiles-visibility-changed"),this._surface.renderer.setNeedsRender(),this.updateAgentSuspension()),this._visible}get loadable(){return this.visible||this._surface.view.state.fixedContentCamera}get rendered(){const e=!!this.renderData;return e!==this._previouslyRendered&&(this._surface.emit("tiles-visibility-changed"),this._previouslyRendered=e,this._surface.renderer.setNeedsRender()),e}get shouldLoad(){if(this._surface.lodSnapping===N.ON){const e=this.level-this._surface.snapLevel;if(0===e)return!0;if(1===e)return!1}return this.isLeaf}init(e,t,i){this.lij[0]=e[0],this.lij[1]=e[1],this.lij[2]=e[2],this.ellipsoid=m(i.tilingScheme.spatialReference),i.tilingScheme.getExtent(e[0],e[1],e[2],this.extent),i.tilingScheme.convertExtentToRadians(this.extent,this.extentInRadians),this._isWithinClippingArea=!0,this._intersectsClippingArea=!0,this._clippingArea=null,this._mapDataRefCount=0,i.upsampleMapCache.pop(this.key),this._edgeLen=0,this._edgeLen2=0,this._center[ie.MIDDLE][3]=0,this.vlevel=e?e[0]:0,t&&t.elevationBounds?r(this._elevationBounds,t.elevationBounds):a(this._elevationBounds,0,0),this._pendingUpdates=0,this.renderData=null,this._screenDepth=0,this._visible=!1,this._previouslyRendered=!1,this._parent=t,this.unsetChildren(),this._surface=i,this.updateVisibility();for(const s of D){const e=i.numLayers(s),t=this.layerInfo[s];for(const i of t)i.release();t.length=e;for(let i=0;i<e;i++)t[i]=B.acquire(this._surface.upsampleInfoPool),s===O.ELEVATION&&this.findElevationBoundsForLayer(i,-1)}this.computeElevationBounds(),this._maxTesselation=Math.min(i.tilingScheme.pixelSize,x)}release(){j(!this.renderData,"tile.renderData was not unloaded"),this._surface.upsampleMapCache.pop(this.key);for(const e of D){for(const t of this.layerInfo[e])t.release();this.layerInfo[e].length=0}this._parent=null,this._surface=null,this._usedMemory=te}refMapData(){++this._mapDataRefCount,this.isCached||this._surface.upsampleMapCache.pop(this.key)}unrefMapData(){if(--this._mapDataRefCount,this.isCached){const e=this.cachedMemory;e>0&&(this._surface.upsampleMapCache.put(this.key,this,e),this.setMemoryDirty())}}setMemoryDirty(){this._usedMemory=te}get cpuImageMemorySize(){const e=4,t=this._surface.tilingScheme.pixelSize;return t*t*e}_updateMemoryUsed(){this._usedMemory=0,this._mapTileMemory=0;const e=this.cpuImageMemorySize;for(const{data:t}of this.layerInfo[O.MAP])t instanceof G?this._mapTileMemory+=q(t.texture):t instanceof HTMLImageElement||t instanceof v?this._mapTileMemory+=e:t instanceof U&&(this._mapTileMemory+=t.memoryUsage);for(const t of this.layerInfo[O.ELEVATION])this._usedMemory+=t.data?e:0;this.renderData&&(this._usedMemory+=this.renderData.estimatedGeometryMemoryUsage,this._mapTileMemory+=q(this.renderData.textureDescriptor)),this.isCached&&this._surface.upsampleMapCache.updateSize(this.key,this,this.cachedMemory)}getUsedMemoryForLayer(e,t){const i=this.layerInfo[e][t];if(!i||!i.data)return 0;if(e!==O.MAP||this.isCached){if(e===O.ELEVATION)return this.cpuImageMemorySize}else{const e=i.data;if(e instanceof G)return q(e.texture);if(e instanceof HTMLImageElement||e instanceof v)return this.cpuImageMemorySize;if(e instanceof y||e instanceof U)return e.memoryUsage}return 0}updateScreenDepth(e){const t=this._center[ie.MIDDLE],i=e,s=t[0],n=t[1],r=t[2],a=i[2]*s+i[6]*n+i[10]*r+i[14];this._screenDepth=a<0?0:a/(i[3]*s+i[7]*n+i[11]*r+i[15])}shouldSplit(e,i,s){if(t(e.frustum)&&(!this._intersectsClippingArea||!this._isVisible(e.frustum)))return V.NONE;const n=this.level;l(F,this._center[ie.MIDDLE],i);let r=h(F),a=ie.MIDDLE;l(k,this._center[ie.TOP],i);const o=h(k);o<r&&(r=o,a=ie.TOP),l(k,this._center[ie.BOTTOM],i);const f=h(k);if(f<r&&(r=f,a=ie.BOTTOM),this._edgeLen2>r&&n<e.maxLod)return V.SPLIT;const p=Math.sqrt(r),_=e.fovX*p*2,m=this._edgeLen/_,T=()=>{const t=n+Math.ceil(-Math.log2(e.relativeWidthLimit/m));return t!==this.vlevel?(this.vlevel=t,V.VSPLITMERGE):V.NONE_HIT_MAXLOD};if(s===N.ON){if(1===this._surface.snapLevel-n)return n>=e.maxLod?T():V.SPLIT}const E=d(this.up,F),A=this._elevationBounds[1]-this._elevationBounds[0],y=A/this.edgeLen;if(e.aboveGround&&E>0&&y<.001){if(E/p-Math.sin(this._curvatureHeight/(this.edgeLen*Math.SQRT1_2)*Math.PI)-y>0)return V.NONE}if(m<e.relativeWidthLimit)return this.vlevel!==this.level?(this.vlevel=this.level,V.VSPLITMERGE):V.NONE;if(n>=e.maxLod)return T();if(n>6){l(k,this._center[a],i),u(X,this.up,E),l(X,X,k);const t=h(X);if(t>this.radius*this.radius){u(X,X,this.radius/Math.sqrt(t)),c(X,X,this._center[a]),l(X,i,X);const s=Math.min(1,(Math.abs(d(X,this.up))+.5*A+this._curvatureHeight)/g(X)),n=z/e.angledSplitBias,r=e.fovY*p*2;if(s*(this._edgeLen/r)<n*e.relativeHeightLimit)return V.NONE}}return V.SPLIT}setChildren(e,t,i,s){j(!!(e&&t&&i&&s),"Null child passed"),this._children[0]=e,this._children[1]=t,this._children[2]=i,this._children[3]=s}unsetChildren(){this._children[0]=null,this._children[1]=null,this._children[2]=null,this._children[3]=null}get isLoaded(){var e,t;return null!=(e=null==(t=this.renderData)?void 0:t.hasGeometry)&&e}prepareToLoad(e){this.refMapData();for(const t of D)this._createOrUpdateAgents(0,t);e.updateTileGeometryState(this)}load(e){this.prepareToLoad(e),this.loadPrepared(e)}loadPrepared(e){e.loadTile(this)}unload(e){e.unloadTile(this);for(const t of D){const e=this.layerInfo[t];for(const t of e)t.loadingAgent&&t.loadingAgent!==P&&(Q(t.loadingAgent),t.loadingAgent=null),t.pendingUpdates=0}this.resetPendingUpdate(V.GEOMETRY),this.resetPendingUpdate(V.TEXTURE_NOFADING),this.resetPendingUpdate(V.TEXTURE_FADING),this.unrefMapData()}unloadMapData(){const e=this.layerInfo[O.MAP];for(const t of e)t.loadingAgent&&t.loadingAgent!==P&&(Q(t.loadingAgent),t.loadingAgent=null),t.pendingUpdates=0;this.renderData&&this.renderData.releaseTexture(),this.setMemoryDirty()}updateClippingStatus(e){if(E(e,this._clippingArea))return!1;const i=this._intersectsClippingArea,s=this._isWithinClippingArea;t(e)?(this._intersectsClippingArea=this.intersectsExtent(e),this._isWithinClippingArea=this._isWithinExtent(e)):(this._intersectsClippingArea=!0,this._isWithinClippingArea=!0),this._clippingArea=e,this.updateVisibility();const n=s&&this._isWithinClippingArea,r=!(s||i||this._isWithinClippingArea||this._intersectsClippingArea);return!this.renderData||n||r||this.setPendingUpdate(V.GEOMETRY),!0}updateVisibility(){this._dirty=!0,this._surface.setTileTreeDirty()}getLayerInfo(e,t){return this.layerInfo[t][e]}hasLayerData(e,t){const i=this.layerInfo[t][e];return!(!i||!i.data||i.dataInvalidated)}get updating(){if(this.hasPendingUpdates)return!0;for(const e of D){const t=this.layerInfo[e];for(const e of t)if(e.loadingAgent&&e.loadingAgent!==P&&e.loadingAgent.updating)return!0}return!1}_isSuspended(e){return!!this.hasPendingUpdate(V.SPLIT)||e!==O.ELEVATION&&!this.loadable}get hasPendingUpdates(){return 0!==this._pendingUpdates}hasPendingUpdate(e){return(this._pendingUpdates&e)===e}setPendingUpdate(e){this._pendingUpdates|=e,e===V.SPLIT||e===V.MERGE?this._surface.setTileTreeDirty():this._surface.requestUpdate()}resetPendingUpdate(e){return!!this.hasPendingUpdate(e)&&(this._pendingUpdates&=~e,!0)}requestLayerData(e,t,s){const n=this.layerInfo[t][e];if(n.waitingAgents.has(s))return console.warn("agent already requested this piece of map data (tile %s, agent tile %s, layer: %d/%d)",this.lij.toString(),s.tile.lij.toString(),t,e),!0;if(n.waitingAgents.push(s),n.data&&!n.dataInvalidated)return console.warn("agent requested existing data (tile %s, agent tile %s, layer: %d/%d)",this.lij.toString(),s.tile.lij.toString(),t,e),s.dataArrived(this),!0;if(n.requestPromise)return!0;i(n.requestAbort),n.requestAbort=new AbortController;const r=this._surface.requestTileData(this,e,t,n.requestAbort);if(!r)return n.requestAbort=null,!1;const a=()=>{n.requestPromise===r&&(n.requestPromise=null,n.requestAbort=null)};return n.requestPromise=r,r.then(a,a),!0}get isLeaf(){return null==this._children[0]}hasLij(e){return this.lij[0]===e[0]&&this.lij[1]===e[1]&&this.lij[2]===e[2]}findByLij(e){if(this.hasLij(e))return this;if(this.isLeaf)return null;const t=this._children[0].findByLij(e)||this._children[1].findByLij(e)||this._children[2].findByLij(e)||this._children[3].findByLij(e);return t||null}distanceToSquared(e){return h(l(X,this._center[ie.MIDDLE],e))}containsPoint(e){const t=this.extent;return e[0]>=t[0]&&e[1]>=t[1]&&e[0]<=t[2]&&e[1]<=t[3]}unrequestLayerData(e,t,i){const s=this.layerInfo[t][e],n=s.waitingAgents,r=null!=n.removeUnordered(i);j(r,"agent has not requested this piece of map data"),n.length<1&&(s.abortRequest(),this._updateMemoryUsed())}dataArrived(e,t,i){const s=this.layerInfo[t][e];s.data=i,s.dataInvalidated=!1,s.waitingAgents.forAll((e=>e.dataArrived(this))),s.waitingAgents.clear(),this._updateMemoryUsed()}dataMissing(e,t,i){i.notInTilemap||console.error(`Tile ${this.lij.toString()} layer ${t}/${e} error ${i}`);const s=this.layerInfo[t][e];s.dataMissing=!0,s.waitingAgents.forAll((e=>e.dataMissing())),s.waitingAgents.clear(),this._updateMemoryUsed()}updateRenderData(e,t){switch(e){case O.MAP:return this._updateTexture(t);case O.ELEVATION:return this._updateGeometry()}}_updateTexture(e){this.renderData&&(this.resetPendingUpdate(e===I.FADING?V.TEXTURE_NOFADING:V.TEXTURE_FADING),this.setPendingUpdate(e===I.FADING?V.TEXTURE_FADING:V.TEXTURE_NOFADING))}_updateGeometry(){this.setPendingUpdate(V.GEOMETRY);for(const e of this.layerInfo[O.ELEVATION])e.pendingUpdates|=V.GEOMETRY}invalidateLayerData(e,t){this.layerInfo[t][e].invalidateSourceData(),this.restartAgents(t)}computeElevationBounds(){const e=this._elevationBounds;a(e,Number.MAX_VALUE,-Number.MAX_VALUE);const i=this.layerInfo[O.ELEVATION];let s=!0;for(const n of i)t(n.elevationBounds)&&(e[0]=Math.min(e[0],n.elevationBounds.min),e[1]=Math.max(e[1],n.elevationBounds.max),n.elevationBounds.hasNoDataValues||(s=!1));s&&(e[0]=Math.min(e[0],0),e[1]=Math.max(e[1],0)),this.updateRadiusAndCenter(),this._surface.setTileTreeDirty()}_updateCenter(){const e=this._elevationBounds,t=.5*(e[0]+e[1]);u(X,this.up,t),c(this._center[ie.MIDDLE],this.centerAtSeaLevel,X),u(X,this.up,e[0]),c(this._center[ie.TOP],this.centerAtSeaLevel,X),u(X,this.up,e[1]),c(this._center[ie.BOTTOM],this.centerAtSeaLevel,X)}findElevationBoundsForLayer(e,i){const n=this.layerInfo[O.ELEVATION][e];if(t(n.elevationBounds)&&n.elevationBounds.level>=i)return;const r=this._surface.layerViewByIndex(e,O.ELEVATION),a=C(r);if(!w(this,a,!1))return;const o=ee;let l=!1;if(n.data){const e=n.data;o.min=e.bounds[0],o.max=e.bounds[1],o.hasNoDataValues=e.hasNoDataValues,o.level=this.level,l=!0}else{let t,i,s=0;for(let n=this._parent;n&&(!i||s<R(this.level))&&(s=this.vlevel-n.level,t=i||t,i=n.layerInfo[O.ELEVATION][e].data,!(!i&&t&&s>=R(this.level)));n=n.parent);i=i||t,i&&(i.computeMinMaxValue(this.lij[0],this.lij[1],this.lij[2],o),o.min!==1/0&&(o.level=i.level,l=!0))}l&&(s(n.elevationBounds)&&(n.elevationBounds=new S),n.elevationBounds.copyFrom(o))}modifyLayers(e,t,i){const s=this.layerInfo[i];for(const a of s)a.loadingAgent&&a.loadingAgent!==P&&(Q(a.loadingAgent),a.loadingAgent=null),a.waitingAgents.clear();for(let a=0;a<s.length;++a)void 0===e[a]&&s[a].release();const n=new Array(...s),r=t.length;s.length=r;for(let a=0;a<r;a++){const e=t[a];s[a]=e>-1?n[e]:B.acquire(this._surface.upsampleInfoPool)}this._updateMemoryUsed()}restartAgents(e){this.renderData&&(this._createOrUpdateAgents(0,e),this.updateRenderData(e,I.FADING))}updateAgents(e){if(this.renderData){const t=this.layerInfo[e];for(const e of t)e.loadingAgent===P&&(e.loadingAgent=null);this._createOrUpdateAgents(0,e)}}updateAgentSuspension(){for(const e of D){const t=this._isSuspended(e);for(const i of this.layerInfo[e])i.loadingAgent&&i.loadingAgent!==P&&(i.loadingAgent.setSuspension(t),i.loadingAgent===P&&this.updateRenderData(e,I.FADING))}}removeLayerAgent(e,t){const i=this.layerInfo[t][e];i.loadingAgent&&i.loadingAgent!==P&&i.loadingAgent.dispose(),i.loadingAgent=null}agentDone(e,t){const i=this.layerInfo[t][e];i.loadingAgent=P,!i.data&&s(i.upsampleInfo)&&this._createOrUpdateAgents(e+1,t)}_createOrUpdateAgents(e,t){const i=this._isSuspended(t),s=this.layerInfo[t];for(let n=e;n<s.length;++n){const e=s[n];let r=!1;const a=this._surface.layerViewByIndex(n,t),o=C(a);if(e.loadingAgent?w(this,o,!1)?(e.loadingAgent!==P&&e.loadingAgent.setSuspension(i),e.loadingAgent!==P&&(r=e.loadingAgent.update())):e.dispose():w(this,o,!1)&&(e.loadingAgent=$(this,n,t,i),r=e.loadingAgent.startLoading(),r?e.loadingAgent===P&&this.setPendingUpdate(V.GEOMETRY):(Q(e.loadingAgent),e.loadingAgent=P)),e.loadingAgent===P&&this.updateRenderData(t,I.FADING),r&&a.isOpaque)return}}_isWithinExtent(e){const t=this.extent;return t[0]>=e[0]&&e[2]>=t[2]&&t[1]>=e[1]&&e[3]>=t[3]}intersectsExtent(e){const t=this.extent;return t[2]>=e[0]&&e[2]>=t[0]&&t[3]>=e[1]&&e[3]>=t[1]}getElevationBasedVerticesPerSide(t){const i=this.vlevel-this.level,s=Math.max(this.level-t,R(this.level)-i);return e(1+(this.maxTesselation>>s),2,this.maxTesselation+1)}get test(){return{cachedMemory:this.cachedMemory}}_findLIJ(e,i){if(!e)return null;const s=this.surface.rootTiles;if(t(s))for(const t of s)if(se(t,e)){let s=t,n=e[0]-s.level-1;for(;n>=0&&!s.isLeaf&&!i(s);){const t=e[1]>>n&1,i=e[2]>>n&1;s=s.children[2*t+i],n--}return i(s)?s:null}return null}findNeighborTile(e,t){const i=this.lij,s=this.getNeighborLIJ(i,e);return s?ne(i,s)?t(this)?this:null:this._findLIJ(s,t):null}findCorner(e,t){const i=e===M.NORTH_EAST?1:e===M.NORTH_WEST?0:e===M.SOUTH_WEST?2:3;let s=this;for(;!(s.isLeaf||t&&t(s));)s=s.children[i];return s}findNeighborCornerTileExact(e,t){var i;return null==(i=this.findNeighborTile(e,(e=>t(e)||e.level===this.level)))?void 0:i.findCorner(de(e),t)}forAllSubtreeOnSide(e,t){const i=e===M.NORTH?[0,1]:e===M.NORTH_EAST?[1]:e===M.EAST?[1,3]:e===M.SOUTH_EAST?[3]:e===M.SOUTH?[2,3]:e===M.SOUTH_WEST?[2]:e===M.WEST?[0,2]:[0],s=e=>{t(e)||e.isLeaf||i.forEach((t=>s(e.children[t])))};s(this)}forallNeighbors(e){Ee.forEach((t=>this.findNeighborCornerTileExact(t,e))),Te.forEach((t=>{var i;return null==(i=this.findNeighborTile(t,(t=>t.level===this.level||e(t))))?void 0:i.forAllSubtreeOnSide(ue(t),e)}))}getNeighborEdgeStartVertexIndex(e,t){const i=null!=t?t:this.findNeighborTile(Te[e],(e=>e.isLoaded));if(!i||!this.isLoaded||!i.isLoaded)return 0;const s=this.level-i.level;if(0===s)return 0;const n=2**s,r=1==(1&e),a=r?0:1,o=i.lij[a+1]*n,l=this.lij[a+1]-o;return r?n-1-l:l}_updateNeighborsWithChangedEdgeResolution(){for(let e=0;e<4;++e)if(this.renderData.geometryState.neighborData.modifiedEdgeResolutions[e]){const t=Te[e],i=this.findNeighborTile(t,(e=>e.isLoaded||e.level===this.level));if(!i)continue;if(!i.isLoaded){H(!i.isLeaf);const s=(e+2)%4,n=ue(t);i.forAllSubtreeOnSide(n,(e=>e.isLoaded?(e.updateEdgeAfterResolutionChange(s),!0):(H(!e.isLeaf),!1)))}this.renderData.geometryState.neighborData.modifiedEdgeResolutions[e]=!1}}updateNeighborDataAndGeometryIfNeeded(){this.isLoaded&&this.renderData.updateNeighborDataAndGeometryIfNeeded()}updateNeighborsAfterGeometryChange(e=this.level){this._forEachLoadedNeighbor((e=>this._updateNeighbor(e))),Te.forEach((t=>{const i=this.findNeighborTile(t,(t=>t.isLoaded&&t.level<e));null==i||i.updateNeighborsWithChangedEdgeResolution()}))}updateNeighborsWithChangedEdgeResolution(){this.isLoaded&&this._updateNeighborsWithChangedEdgeResolution()}updateEdgeAfterResolutionChange(e){this.renderData.updateEdgeAfterResolutionChange(e)}_forEachLoadedNeighbor(e){const t=this.level,i=e=>e.level===t||e.isLoaded;Te.forEach(((t,s)=>{var n,r;const a=this.findNeighborTile(t,i);null!=a&&a!==this&&a.forAllSubtreeOnSide(ue(t),(t=>!!t.isLoaded&&(e(t),!0)));const o=null==(n=this.renderData)||null==(r=n.geometryState)?void 0:r.neighborData;o&&(o.modifiedEdgeResolutions[s]=!1)})),Ee.forEach((t=>{var s;const n=null==(s=this.findNeighborTile(t,i))?void 0:s.findCorner(de(t),(e=>e.isLoaded));H(!n||oe(this,n,t)),null!=n&&n.isLoaded&&e(n)}))}_updateNeighbor(e){null!=e&&e.isLoaded&&e.updateNeighborDataAndGeometryIfNeeded()}getNeighborLIJ(e,t){const i=me(t)?-1:_e(t)?1:0,s=fe(t)?-1:pe(t)?1:0,n=[e[0],e[1]+i,e[2]+s];return n[1]<0?null:this.surface.isGlobal?this.wrapLIJ(n):n[2]<0?null:n}wrapLIJ(e){return!e||e[1]<0||e[1]>=2**e[0]?null:this.surface.wrapEastWest(e)}get westNeighborWestExtent(){return this.extent[0]*(this.isWestEnd?-1:1)}get eastNeighborEastExtent(){return this.extent[2]*(this.isEastEnd?-1:1)}get isEastEnd(){return this.lij[2]===this.surface.lijEastEnd(this.level)-1}get isWestEnd(){return 0===this.lij[2]}get isNorthEnd(){return 0===this.lij[1]}get isSouthEnd(){return this.extent[1]+_>=this.surface.extent[1]}compareLIJs(e){const t=this.lij,i=t[0],s=e[0];if(i===s)return[t,e];const n=i-s;if(n<0){const i=2**-n;return[[s,t[1]*i,t[2]*i],e]}{const s=2**n;return[t,[i,e[1]*s,e[2]*s]]}}checkGeometryWaterproofness(){W&&(H(this.isLoaded),this.renderData.checkGeometryWaterproofness())}shouldHaveNeighbor(e){const t=this.extent,i=this.surface.rootTilesExtent,s=.25*(t[2]-t[0]);if(me(e)&&t[3]+s>=i[3])return!1;if(_e(e)&&t[1]-s<=i[1])return!1;const n=this.surface.isGlobal;return!(!n&&fe(e)&&t[0]-s<=i[0])&&!(!n&&pe(e)&&t[2]+s>=i[2])}}function $(e,t,i,s){const n=i===O.ELEVATION?Z.acquire():K.acquire();return n.init(e,t,i,s),n}function Q(e){e.dispose(),e instanceof L?Z.release(e):e instanceof b&&K.release(e)}const K=new n(b),Z=new n(L),ee=new S,te=-1;var ie;function se(e,t){const i=e.level,s=t[0];if(i>s)return!1;const n=s-i,r=t[1]>>n,a=t[2]>>n;return r===e.lij[1]&&a===e.lij[2]}function ne(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function re(e,t,i){return Math.abs(e-t)<=i}function ae(e,t,i){if(!e||!t)return!1;if(0===e.level&&0===t.level){if(e.isEastEnd&&t.isWestEnd&&i===M.EAST)return!0;if(e.isWestEnd&&t.isEastEnd&&i===M.WEST)return!0}const s=1e-6*(e.extent[2]-e.extent[0]);switch(i){case M.NORTH:return re(e.extent[3],t.extent[1],s);case M.SOUTH:return re(e.extent[1],t.extent[3],s);case M.EAST:return re(e.extent[2],t.extent[0],s)||re(e.extent[2],-t.extent[0],s);case M.WEST:return re(e.extent[0],t.extent[2],s)||re(e.extent[0],-t.extent[2],s)}}function oe(e,t,i){return!(!e||!t||t===e)&&(e.level>=t.level?le(e,t,i):le(t,e,de(i)))}function le(e,t,i){H(e.level>=t.level);const s=ce(i),n=ge(i),r=e.extent,a=t.extent,o=[s?r[0]:r[2],n?r[3]:r[1]],l=[s?a[2]:a[0],n?a[1]:a[3]],h=1e-5*(r[2]-r[0]),d=re(o[0],l[0],h)||e.surface.isGlobal&&re(o[0],-l[0],h),u=re(o[1],l[1],h);if(d&&u)return!0;if(e.level===t.level)return!1;if(!d&&!u)return!1;return d?he([a[1],a[3]],[r[1],r[3]],h):he([a[0],a[2]],[r[0],r[2]],h)}function he(e,t,i=_){return e[0]-i<=t[0]&&t[0]<=t[1]&&t[1]<=e[1]+i}function de(e){return e===M.NORTH_EAST?M.SOUTH_WEST:e===M.NORTH_WEST?M.SOUTH_EAST:e===M.SOUTH_WEST?M.NORTH_EAST:M.NORTH_WEST}function ue(e){return e===M.NORTH?M.SOUTH:e===M.EAST?M.WEST:e===M.SOUTH?M.NORTH:M.EAST}function ce(e){return e===M.NORTH_WEST||e===M.SOUTH_WEST}function ge(e){return e===M.NORTH_WEST||e===M.NORTH_EAST}function fe(e){return e===M.NORTH_WEST||e===M.WEST||e===M.SOUTH_WEST}function pe(e){return e===M.NORTH_EAST||e===M.EAST||e===M.SOUTH_EAST}function _e(e){return e===M.SOUTH_EAST||e===M.SOUTH||e===M.SOUTH_WEST}function me(e){return e===M.NORTH_EAST||e===M.NORTH||e===M.NORTH_WEST}!function(e){e[e.TOP=0]="TOP",e[e.MIDDLE=1]="MIDDLE",e[e.BOTTOM=2]="BOTTOM"}(ie||(ie={}));const Te=[M.NORTH,M.EAST,M.SOUTH,M.WEST],Ee=[M.NORTH_EAST,M.SOUTH_EAST,M.SOUTH_WEST,M.NORTH_WEST];export{ie as CenterPosition,J as SplitLimits,Y as Tile,re as almostEquals,oe as isCornerNeighbor,pe as isEast,ae as isEdgeNeighbor,me as isNorth,ge as isNorthCorner,_e as isSouth,fe as isWest,ce as isWestCorner,Ee as neighborCornerIndices,Te as neighborEdgeIndices,de as oppositeCorner,ue as oppositeEdge};
5
+ import{clamp as e}from"../../../core/mathUtils.js";import{isSome as t,abortMaybe as i,isNone as s}from"../../../core/maybe.js";import n from"../../../core/ObjectPool.js";import{c as r,b as a}from"../../../chunks/vec2.js";import{a as o}from"../../../chunks/vec2f64.js";import{b as l,p as h,e as d,g as u,a as c,l as g}from"../../../chunks/vec3.js";import{c as f,u as p}from"../../../chunks/vec3f64.js";import{E as m}from"../../../chunks/common.js";import{getReferenceEllipsoid as _}from"../../../geometry/projectionEllipsoid.js";import{create as T,equals as E}from"../../../geometry/support/aaBoundingRect.js";import{c as A}from"../../../chunks/sphere.js";import{VectorTile as y}from"../../2d/engine/vectorTiles/VectorTile.js";import{ImageWithType as v}from"../support/StreamDataLoader.js";import{ElevationBounds as S}from"./ElevationBounds.js";import{ElevationTileAgent as L}from"./ElevationTileAgent.js";import{NeighborIndex as M,LODSnapping as N,TextureUpdate as I}from"./interfaces.js";import{LayerClass as O,LayerClasses as D}from"./LayerClass.js";import{MapTileAgent as b}from"./MapTileAgent.js";import{RasterTile as U}from"./RasterTile.js";import{MAX_PATCH_TESSELATION as x,getElevationDesiredResolutionLevel as R}from"./TerrainConst.js";import{weakAssert as j,getLayerWithExtentRange as C,internalAssert as H,ENABLE_WATERPROOFNESS_TESTS as W}from"./terrainUtils.js";import{TILE_AGENT_DONE as P}from"./TileAgent.js";import{TilePerLayerInfo as B}from"./TilePerLayerInfo.js";import G from"./TileTexture.js";import{TileUpdate as V}from"./TileUpdate.js";import{fallsWithinLayer as w}from"./tileUtils.js";import{getGpuMemoryUsage as q}from"../../webgl/Util.js";const F=f(),k=f(),X=f(),z=.1;class J{constructor(){this.fovX=0,this.fovY=0,this.relativeWidthLimit=0,this.relativeHeightLimit=0,this.maxLod=0,this.angledSplitBias=0,this.aboveGround=!0}}class Y{constructor(){this.lij=[0,0,0],this._children=[null,null,null,null],this._pendingUpdates=0,this._dirty=!0,this._previouslyRendered=!1,this.extent=T(),this._elevationBounds=o(),this.layerInfo=[[],[]],this.extentInRadians=T(),this.centerAtSeaLevel=f(),this._center=[f(),A(),f()],this.up=p(),this._isWithinClippingArea=!0,this._intersectsClippingArea=!0,this._maxTesselation=0,this._usedMemory=te,this._mapTileMemory=0,this._mapDataRefCount=0,this._screenDepth=0,this.renderOrder=0,this._edgeLen=0,this._edgeLen2=0,this._curvatureHeight=0}static prune(){K.prune(0),Z.prune(0),B.prune()}get usedMemory(){return this._usedMemory===te&&this._updateMemoryUsed(),this._usedMemory+(this.isCached?0:this.mapTileMemory)}get cachedMemory(){return this.isCached?this.mapTileMemory:0}get mapTileMemory(){this._usedMemory===te&&this._updateMemoryUsed();let e=this._mapTileMemory;for(const{data:t}of this.layerInfo[O.MAP])t instanceof y&&(e+=t.memoryUsage);return e}get isCached(){return!this.shouldLoad&&this._mapDataRefCount<=0}get maxTesselation(){return this._maxTesselation}get isWithinClippingArea(){return this._isWithinClippingArea}get intersectsClippingArea(){return this._intersectsClippingArea}get clippingArea(){return this._clippingArea}get parent(){return this._parent}get children(){return this._children}get surface(){return this._surface}get elevationBounds(){return this._elevationBounds}get level(){return this.lij[0]}get key(){return`${this.lij[0]}/${this.lij[1]}/${this.lij[2]}`}get edgeLen(){return this._edgeLen}get radius(){return this._center[ie.MIDDLE][3]}get screenDepth(){return this._screenDepth}get visible(){return this._dirty&&this.computeVisibility(),this._visible}computeVisibility(){this._dirty=!1;const e=this._intersectsClippingArea&&this._isVisible(this.surface.frustum);return e!==this._visible&&(this._visible=e,this._surface.emit("tiles-visibility-changed"),this._surface.renderer.setNeedsRender(),this.updateAgentSuspension()),this._visible}get loadable(){return this.visible||this._surface.view.state.fixedContentCamera}get rendered(){const e=!!this.renderData;return e!==this._previouslyRendered&&(this._surface.emit("tiles-visibility-changed"),this._previouslyRendered=e,this._surface.renderer.setNeedsRender()),e}get shouldLoad(){if(this._surface.lodSnapping===N.ON){const e=this.level-this._surface.snapLevel;if(0===e)return!0;if(1===e)return!1}return this.isLeaf}init(e,t,i){this.lij[0]=e[0],this.lij[1]=e[1],this.lij[2]=e[2],this.ellipsoid=_(i.tilingScheme.spatialReference),i.tilingScheme.getExtent(e[0],e[1],e[2],this.extent),i.tilingScheme.convertExtentToRadians(this.extent,this.extentInRadians),this._isWithinClippingArea=!0,this._intersectsClippingArea=!0,this._clippingArea=null,this._mapDataRefCount=0,i.upsampleMapCache.pop(this.key),this._edgeLen=0,this._edgeLen2=0,this._center[ie.MIDDLE][3]=0,this.vlevel=e?e[0]:0,t&&t.elevationBounds?r(this._elevationBounds,t.elevationBounds):a(this._elevationBounds,0,0),this._pendingUpdates=0,this.renderData=null,this._screenDepth=0,this._visible=!1,this._previouslyRendered=!1,this._parent=t,this.unsetChildren(),this._surface=i,this.updateVisibility();for(const s of D){const e=i.numLayers(s),t=this.layerInfo[s];for(const i of t)i.release();t.length=e;for(let i=0;i<e;i++)t[i]=B.acquire(this._surface.upsampleInfoPool),s===O.ELEVATION&&this.findElevationBoundsForLayer(i,-1)}this.computeElevationBounds(),this._maxTesselation=Math.min(i.tilingScheme.pixelSize,x)}release(){j(!this.renderData,"tile.renderData was not unloaded"),this._surface.upsampleMapCache.pop(this.key);for(const e of D){for(const t of this.layerInfo[e])t.release();this.layerInfo[e].length=0}this._parent=null,this._surface=null,this._usedMemory=te}refMapData(){++this._mapDataRefCount,this.isCached||this._surface.upsampleMapCache.pop(this.key)}unrefMapData(){if(--this._mapDataRefCount,this.isCached){const e=this.cachedMemory;e>0&&(this._surface.upsampleMapCache.put(this.key,this,e),this.setMemoryDirty())}}setMemoryDirty(){this._usedMemory=te}get cpuImageMemorySize(){const e=4,t=this._surface.tilingScheme.pixelSize;return t*t*e}_updateMemoryUsed(){this._usedMemory=0,this._mapTileMemory=0;const e=this.cpuImageMemorySize;for(const{data:t}of this.layerInfo[O.MAP])t instanceof G?this._mapTileMemory+=q(t.texture):t instanceof HTMLImageElement||t instanceof v?this._mapTileMemory+=e:t instanceof U&&(this._mapTileMemory+=t.memoryUsage);for(const t of this.layerInfo[O.ELEVATION])this._usedMemory+=t.data?e:0;this.renderData&&(this._usedMemory+=this.renderData.estimatedGeometryMemoryUsage,this._mapTileMemory+=q(this.renderData.textureDescriptor)),this.isCached&&this._surface.upsampleMapCache.updateSize(this.key,this,this.cachedMemory)}getUsedMemoryForLayer(e,t){const i=this.layerInfo[e][t];if(!i||!i.data)return 0;if(e!==O.MAP||this.isCached){if(e===O.ELEVATION)return this.cpuImageMemorySize}else{const e=i.data;if(e instanceof G)return q(e.texture);if(e instanceof HTMLImageElement||e instanceof v)return this.cpuImageMemorySize;if(e instanceof y||e instanceof U)return e.memoryUsage}return 0}updateScreenDepth(e){const t=this._center[ie.MIDDLE],i=e,s=t[0],n=t[1],r=t[2],a=i[2]*s+i[6]*n+i[10]*r+i[14];this._screenDepth=a<0?0:a/(i[3]*s+i[7]*n+i[11]*r+i[15])}shouldSplit(e,i,s){if(t(e.frustum)&&(!this._intersectsClippingArea||!this._isVisible(e.frustum)))return V.NONE;const n=this.level;l(F,this._center[ie.MIDDLE],i);let r=h(F),a=ie.MIDDLE;l(k,this._center[ie.TOP],i);const o=h(k);o<r&&(r=o,a=ie.TOP),l(k,this._center[ie.BOTTOM],i);const f=h(k);if(f<r&&(r=f,a=ie.BOTTOM),this._edgeLen2>r&&n<e.maxLod)return V.SPLIT;const p=Math.sqrt(r),m=e.fovX*p*2,_=this._edgeLen/m,T=()=>{const t=n+Math.ceil(-Math.log2(e.relativeWidthLimit/_));return t!==this.vlevel?(this.vlevel=t,V.VSPLITMERGE):V.NONE_HIT_MAXLOD};if(s===N.ON){if(1===this._surface.snapLevel-n)return n>=e.maxLod?T():V.SPLIT}const E=d(this.up,F),A=this._elevationBounds[1]-this._elevationBounds[0],y=A/this.edgeLen;if(e.aboveGround&&E>0&&y<.001){if(E/p-Math.sin(this._curvatureHeight/(this.edgeLen*Math.SQRT1_2)*Math.PI)-y>0)return V.NONE}if(_<e.relativeWidthLimit)return this.vlevel!==this.level?(this.vlevel=this.level,V.VSPLITMERGE):V.NONE;if(n>=e.maxLod)return T();if(n>6){l(k,this._center[a],i),u(X,this.up,E),l(X,X,k);const t=h(X);if(t>this.radius*this.radius){u(X,X,this.radius/Math.sqrt(t)),c(X,X,this._center[a]),l(X,i,X);const s=Math.min(1,(Math.abs(d(X,this.up))+.5*A+this._curvatureHeight)/g(X)),n=z/e.angledSplitBias,r=e.fovY*p*2;if(s*(this._edgeLen/r)<n*e.relativeHeightLimit)return V.NONE}}return V.SPLIT}setChildren(e,t,i,s){j(!!(e&&t&&i&&s),"Null child passed"),this._children[0]=e,this._children[1]=t,this._children[2]=i,this._children[3]=s}unsetChildren(){this._children[0]=null,this._children[1]=null,this._children[2]=null,this._children[3]=null}get isLoaded(){var e,t;return null!=(e=null==(t=this.renderData)?void 0:t.hasGeometry)&&e}prepareToLoad(e){this.refMapData();for(const t of D)this._createOrUpdateAgents(0,t);e.updateTileGeometryState(this)}load(e){this.prepareToLoad(e),this.loadPrepared(e)}loadPrepared(e){e.loadTile(this)}unload(e){e.unloadTile(this);for(const t of D){const e=this.layerInfo[t];for(const t of e)t.loadingAgent&&t.loadingAgent!==P&&(Q(t.loadingAgent),t.loadingAgent=null),t.pendingUpdates=0}this.resetPendingUpdate(V.GEOMETRY),this.resetPendingUpdate(V.TEXTURE_NOFADING),this.resetPendingUpdate(V.TEXTURE_FADING),this.unrefMapData()}unloadMapData(){const e=this.layerInfo[O.MAP];for(const t of e)t.loadingAgent&&t.loadingAgent!==P&&(Q(t.loadingAgent),t.loadingAgent=null),t.pendingUpdates=0;this.renderData&&this.renderData.releaseTexture(),this.setMemoryDirty()}updateClippingStatus(e){if(E(e,this._clippingArea))return!1;const i=this._intersectsClippingArea,s=this._isWithinClippingArea;t(e)?(this._intersectsClippingArea=this.intersectsExtent(e),this._isWithinClippingArea=this._isWithinExtent(e)):(this._intersectsClippingArea=!0,this._isWithinClippingArea=!0),this._clippingArea=e,this.updateVisibility();const n=s&&this._isWithinClippingArea,r=!(s||i||this._isWithinClippingArea||this._intersectsClippingArea);return!this.renderData||n||r||this.setPendingUpdate(V.GEOMETRY),!0}updateVisibility(){this._dirty=!0,this._surface.setTileTreeDirty()}getLayerInfo(e,t){return this.layerInfo[t][e]}hasLayerData(e,t){const i=this.layerInfo[t][e];return!(!i||!i.data||i.dataInvalidated)}get updating(){if(this.hasPendingUpdates)return!0;for(const e of D){const t=this.layerInfo[e];for(const e of t)if(e.loadingAgent&&e.loadingAgent!==P&&e.loadingAgent.updating)return!0}return!1}_isSuspended(e){return!!this.hasPendingUpdate(V.SPLIT)||e!==O.ELEVATION&&!this.loadable}get hasPendingUpdates(){return 0!==this._pendingUpdates}hasPendingUpdate(e){return(this._pendingUpdates&e)===e}setPendingUpdate(e){this._pendingUpdates|=e,e===V.SPLIT||e===V.MERGE?this._surface.setTileTreeDirty():this._surface.requestUpdate()}resetPendingUpdate(e){return!!this.hasPendingUpdate(e)&&(this._pendingUpdates&=~e,!0)}requestLayerData(e,t,s){const n=this.layerInfo[t][e];if(n.waitingAgents.has(s))return console.warn("agent already requested this piece of map data (tile %s, agent tile %s, layer: %d/%d)",this.lij.toString(),s.tile.lij.toString(),t,e),!0;if(n.waitingAgents.push(s),n.data&&!n.dataInvalidated)return console.warn("agent requested existing data (tile %s, agent tile %s, layer: %d/%d)",this.lij.toString(),s.tile.lij.toString(),t,e),s.dataArrived(this),!0;if(n.requestPromise)return!0;i(n.requestAbort),n.requestAbort=new AbortController;const r=this._surface.requestTileData(this,e,t,n.requestAbort);if(!r)return n.requestAbort=null,!1;const a=()=>{n.requestPromise===r&&(n.requestPromise=null,n.requestAbort=null)};return n.requestPromise=r,r.then(a,a),!0}get isLeaf(){return null==this._children[0]}hasLij(e){return this.lij[0]===e[0]&&this.lij[1]===e[1]&&this.lij[2]===e[2]}findByLij(e){if(this.hasLij(e))return this;if(this.isLeaf)return null;const t=this._children[0].findByLij(e)||this._children[1].findByLij(e)||this._children[2].findByLij(e)||this._children[3].findByLij(e);return t||null}distanceToSquared(e){return h(l(X,this._center[ie.MIDDLE],e))}containsPoint(e){const t=this.extent;return e[0]>=t[0]&&e[1]>=t[1]&&e[0]<=t[2]&&e[1]<=t[3]}unrequestLayerData(e,t,i){const s=this.layerInfo[t][e],n=s.waitingAgents,r=null!=n.removeUnordered(i);j(r,"agent has not requested this piece of map data"),n.length<1&&(s.abortRequest(),this._updateMemoryUsed())}dataArrived(e,t,i){const s=this.layerInfo[t][e];s.data=i,s.dataInvalidated=!1,s.waitingAgents.forAll((e=>e.dataArrived(this))),s.waitingAgents.clear(),this._updateMemoryUsed()}dataMissing(e,t,i){i.notInTilemap||console.error(`Tile ${this.lij.toString()} layer ${t}/${e} error ${i}`);const s=this.layerInfo[t][e];s.dataMissing=!0,s.waitingAgents.forAll((e=>e.dataMissing())),s.waitingAgents.clear(),this._updateMemoryUsed()}updateRenderData(e,t){switch(e){case O.MAP:return this._updateTexture(t);case O.ELEVATION:return this._updateGeometry()}}_updateTexture(e){this.renderData&&(this.resetPendingUpdate(e===I.FADING?V.TEXTURE_NOFADING:V.TEXTURE_FADING),this.setPendingUpdate(e===I.FADING?V.TEXTURE_FADING:V.TEXTURE_NOFADING))}_updateGeometry(){this.setPendingUpdate(V.GEOMETRY);for(const e of this.layerInfo[O.ELEVATION])e.pendingUpdates|=V.GEOMETRY}invalidateLayerData(e,t){this.layerInfo[t][e].invalidateSourceData(),this.restartAgents(t)}computeElevationBounds(){const e=this._elevationBounds;a(e,Number.MAX_VALUE,-Number.MAX_VALUE);const i=this.layerInfo[O.ELEVATION];let s=!0;for(const n of i)t(n.elevationBounds)&&(e[0]=Math.min(e[0],n.elevationBounds.min),e[1]=Math.max(e[1],n.elevationBounds.max),n.elevationBounds.hasNoDataValues||(s=!1));s&&(e[0]=Math.min(e[0],0),e[1]=Math.max(e[1],0)),this.updateRadiusAndCenter(),this._surface.setTileTreeDirty()}_updateCenter(){const e=this._elevationBounds,t=.5*(e[0]+e[1]);u(X,this.up,t),c(this._center[ie.MIDDLE],this.centerAtSeaLevel,X),u(X,this.up,e[0]),c(this._center[ie.TOP],this.centerAtSeaLevel,X),u(X,this.up,e[1]),c(this._center[ie.BOTTOM],this.centerAtSeaLevel,X)}findElevationBoundsForLayer(e,i){const n=this.layerInfo[O.ELEVATION][e];if(t(n.elevationBounds)&&n.elevationBounds.level>=i)return;const r=this._surface.layerViewByIndex(e,O.ELEVATION),a=C(r);if(!w(this,a,!1))return;const o=ee;let l=!1;if(n.data){const e=n.data;o.min=e.bounds[0],o.max=e.bounds[1],o.hasNoDataValues=e.hasNoDataValues,o.level=this.level,l=!0}else{let t,i,s=0;for(let n=this._parent;n&&(!i||s<R(this.level))&&(s=this.vlevel-n.level,t=i||t,i=n.layerInfo[O.ELEVATION][e].data,!(!i&&t&&s>=R(this.level)));n=n.parent);i=i||t,i&&(i.computeMinMaxValue(this.lij[0],this.lij[1],this.lij[2],o),o.min!==1/0&&(o.level=i.level,l=!0))}l&&(s(n.elevationBounds)&&(n.elevationBounds=new S),n.elevationBounds.copyFrom(o))}modifyLayers(e,t,i){const s=this.layerInfo[i];for(const a of s)a.loadingAgent&&a.loadingAgent!==P&&(Q(a.loadingAgent),a.loadingAgent=null),a.waitingAgents.clear();for(let a=0;a<s.length;++a)void 0===e[a]&&s[a].release();const n=new Array(...s),r=t.length;s.length=r;for(let a=0;a<r;a++){const e=t[a];s[a]=e>-1?n[e]:B.acquire(this._surface.upsampleInfoPool)}this._updateMemoryUsed()}restartAgents(e){this.renderData&&(this._createOrUpdateAgents(0,e),this.updateRenderData(e,I.FADING))}updateAgents(e){if(this.renderData){const t=this.layerInfo[e];for(const e of t)e.loadingAgent===P&&(e.loadingAgent=null);this._createOrUpdateAgents(0,e)}}updateAgentSuspension(){for(const e of D){const t=this._isSuspended(e);for(const i of this.layerInfo[e])i.loadingAgent&&i.loadingAgent!==P&&(i.loadingAgent.setSuspension(t),i.loadingAgent===P&&this.updateRenderData(e,I.FADING))}}removeLayerAgent(e,t){const i=this.layerInfo[t][e];i.loadingAgent&&i.loadingAgent!==P&&i.loadingAgent.dispose(),i.loadingAgent=null}agentDone(e,t){const i=this.layerInfo[t][e];i.loadingAgent=P,!i.data&&s(i.upsampleInfo)&&this._createOrUpdateAgents(e+1,t)}_createOrUpdateAgents(e,t){const i=this._isSuspended(t),s=this.layerInfo[t];for(let n=e;n<s.length;++n){const e=s[n];let r=!1;const a=this._surface.layerViewByIndex(n,t),o=C(a);if(e.loadingAgent?w(this,o,!1)?(e.loadingAgent!==P&&e.loadingAgent.setSuspension(i),e.loadingAgent!==P&&(r=e.loadingAgent.update())):e.dispose():w(this,o,!1)&&(e.loadingAgent=$(this,n,t,i),r=e.loadingAgent.startLoading(),r?e.loadingAgent===P&&this.setPendingUpdate(V.GEOMETRY):(Q(e.loadingAgent),e.loadingAgent=P)),e.loadingAgent===P&&this.updateRenderData(t,I.FADING),r&&a.isOpaque)return}}_isWithinExtent(e){const t=this.extent;return t[0]>=e[0]&&e[2]>=t[2]&&t[1]>=e[1]&&e[3]>=t[3]}intersectsExtent(e){const t=this.extent;return t[2]>=e[0]&&e[2]>=t[0]&&t[3]>=e[1]&&e[3]>=t[1]}getElevationBasedVerticesPerSide(t){const i=this.vlevel-this.level,s=Math.max(this.level-t,R(this.level)-i);return e(1+(this.maxTesselation>>s),2,this.maxTesselation+1)}get test(){return{cachedMemory:this.cachedMemory}}_findLIJ(e,i){if(!e)return null;const s=this.surface.rootTiles;if(t(s))for(const t of s)if(se(t,e)){let s=t,n=e[0]-s.level-1;for(;n>=0&&!s.isLeaf&&!i(s);){const t=e[1]>>n&1,i=e[2]>>n&1;s=s.children[2*t+i],n--}return i(s)?s:null}return null}findNeighborTile(e,t){const i=this.lij,s=this.getNeighborLIJ(i,e);return s?ne(i,s)?t(this)?this:null:this._findLIJ(s,t):null}findCorner(e,t){const i=e===M.NORTH_EAST?1:e===M.NORTH_WEST?0:e===M.SOUTH_WEST?2:3;let s=this;for(;!(s.isLeaf||t&&t(s));)s=s.children[i];return s}findNeighborCornerTileExact(e,t){var i;return null==(i=this.findNeighborTile(e,(e=>t(e)||e.level===this.level)))?void 0:i.findCorner(de(e),t)}forAllSubtreeOnSide(e,t){const i=e===M.NORTH?[0,1]:e===M.NORTH_EAST?[1]:e===M.EAST?[1,3]:e===M.SOUTH_EAST?[3]:e===M.SOUTH?[2,3]:e===M.SOUTH_WEST?[2]:e===M.WEST?[0,2]:[0],s=e=>{t(e)||e.isLeaf||i.forEach((t=>s(e.children[t])))};s(this)}forallNeighbors(e){Ee.forEach((t=>this.findNeighborCornerTileExact(t,e))),Te.forEach((t=>{var i;return null==(i=this.findNeighborTile(t,(t=>t.level===this.level||e(t))))?void 0:i.forAllSubtreeOnSide(ue(t),e)}))}getNeighborEdgeStartVertexIndex(e,t){const i=null!=t?t:this.findNeighborTile(Te[e],(e=>e.isLoaded));if(!i||!this.isLoaded||!i.isLoaded)return 0;const s=this.level-i.level;if(0===s)return 0;const n=2**s,r=1==(1&e),a=r?0:1,o=i.lij[a+1]*n,l=this.lij[a+1]-o;return r?n-1-l:l}_updateNeighborsWithChangedEdgeResolution(){for(let e=0;e<4;++e)if(this.renderData.geometryState.neighborData.modifiedEdgeResolutions[e]){const t=Te[e],i=this.findNeighborTile(t,(e=>e.isLoaded||e.level===this.level));if(!i)continue;if(!i.isLoaded){H(!i.isLeaf);const s=(e+2)%4,n=ue(t);i.forAllSubtreeOnSide(n,(e=>e.isLoaded?(e.updateEdgeAfterResolutionChange(s),!0):(H(!e.isLeaf),!1)))}this.renderData.geometryState.neighborData.modifiedEdgeResolutions[e]=!1}}updateNeighborDataAndGeometryIfNeeded(){this.isLoaded&&this.renderData.updateNeighborDataAndGeometryIfNeeded()}updateNeighborsAfterGeometryChange(e=this.level){this.forEachLoadedNeighbor((e=>this._updateNeighbor(e))),Te.forEach((t=>{const i=this.findNeighborTile(t,(t=>t.isLoaded&&t.level<e));null==i||i.updateNeighborsWithChangedEdgeResolution()}))}updateNeighborsWithChangedEdgeResolution(){this.isLoaded&&this._updateNeighborsWithChangedEdgeResolution()}updateEdgeAfterResolutionChange(e){this.renderData.updateEdgeAfterResolutionChange(e)}forEachLoadedNeighbor(e){const t=this.level,i=e=>e.level===t||e.isLoaded;Te.forEach(((t,s)=>{var n,r;const a=this.findNeighborTile(t,i);null!=a&&a!==this&&a.forAllSubtreeOnSide(ue(t),(t=>!!t.isLoaded&&(e(t),!0)));const o=null==(n=this.renderData)||null==(r=n.geometryState)?void 0:r.neighborData;o&&(o.modifiedEdgeResolutions[s]=!1)})),Ee.forEach((t=>{var s;const n=null==(s=this.findNeighborTile(t,i))?void 0:s.findCorner(de(t),(e=>e.isLoaded));H(!n||oe(this,n,t)),null!=n&&n.isLoaded&&e(n)}))}_updateNeighbor(e){null!=e&&e.isLoaded&&e.updateNeighborDataAndGeometryIfNeeded()}getNeighborLIJ(e,t){const i=_e(t)?-1:me(t)?1:0,s=fe(t)?-1:pe(t)?1:0,n=[e[0],e[1]+i,e[2]+s];return n[1]<0?null:this.surface.isGlobal?this.wrapLIJ(n):n[2]<0?null:n}wrapLIJ(e){return!e||e[1]<0||e[1]>=2**e[0]?null:this.surface.wrapEastWest(e)}get westNeighborWestExtent(){return this.extent[0]*(this.isWestEnd?-1:1)}get eastNeighborEastExtent(){return this.extent[2]*(this.isEastEnd?-1:1)}get isEastEnd(){return this.lij[2]===this.surface.lijEastEnd(this.level)-1}get isWestEnd(){return 0===this.lij[2]}get isNorthEnd(){return 0===this.lij[1]}get isSouthEnd(){return this.extent[1]+m>=this.surface.extent[1]}compareLIJs(e){const t=this.lij,i=t[0],s=e[0];if(i===s)return[t,e];const n=i-s;if(n<0){const i=2**-n;return[[s,t[1]*i,t[2]*i],e]}{const s=2**n;return[t,[i,e[1]*s,e[2]*s]]}}checkGeometryWaterproofness(){W&&(H(this.isLoaded),this.renderData.checkGeometryWaterproofness())}shouldHaveNeighbor(e){const t=this.extent,i=this.surface.rootTilesExtent,s=.25*(t[2]-t[0]);if(_e(e)&&t[3]+s>=i[3])return!1;if(me(e)&&t[1]-s<=i[1])return!1;const n=this.surface.isGlobal;return!(!n&&fe(e)&&t[0]-s<=i[0])&&!(!n&&pe(e)&&t[2]+s>=i[2])}}function $(e,t,i,s){const n=i===O.ELEVATION?Z.acquire():K.acquire();return n.init(e,t,i,s),n}function Q(e){e.dispose(),e instanceof L?Z.release(e):e instanceof b&&K.release(e)}const K=new n(b),Z=new n(L),ee=new S,te=-1;var ie;function se(e,t){const i=e.level,s=t[0];if(i>s)return!1;const n=s-i,r=t[1]>>n,a=t[2]>>n;return r===e.lij[1]&&a===e.lij[2]}function ne(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function re(e,t,i){return Math.abs(e-t)<=i}function ae(e,t,i){if(!e||!t)return!1;if(0===e.level&&0===t.level){if(e.isEastEnd&&t.isWestEnd&&i===M.EAST)return!0;if(e.isWestEnd&&t.isEastEnd&&i===M.WEST)return!0}const s=1e-6*(e.extent[2]-e.extent[0]);switch(i){case M.NORTH:return re(e.extent[3],t.extent[1],s);case M.SOUTH:return re(e.extent[1],t.extent[3],s);case M.EAST:return re(e.extent[2],t.extent[0],s)||re(e.extent[2],-t.extent[0],s);case M.WEST:return re(e.extent[0],t.extent[2],s)||re(e.extent[0],-t.extent[2],s)}}function oe(e,t,i){return!(!e||!t||t===e)&&(e.level>=t.level?le(e,t,i):le(t,e,de(i)))}function le(e,t,i){H(e.level>=t.level);const s=ce(i),n=ge(i),r=e.extent,a=t.extent,o=[s?r[0]:r[2],n?r[3]:r[1]],l=[s?a[2]:a[0],n?a[1]:a[3]],h=1e-5*(r[2]-r[0]),d=re(o[0],l[0],h)||e.surface.isGlobal&&re(o[0],-l[0],h),u=re(o[1],l[1],h);if(d&&u)return!0;if(e.level===t.level)return!1;if(!d&&!u)return!1;return d?he([a[1],a[3]],[r[1],r[3]],h):he([a[0],a[2]],[r[0],r[2]],h)}function he(e,t,i=m){return e[0]-i<=t[0]&&t[0]<=t[1]&&t[1]<=e[1]+i}function de(e){return e===M.NORTH_EAST?M.SOUTH_WEST:e===M.NORTH_WEST?M.SOUTH_EAST:e===M.SOUTH_WEST?M.NORTH_EAST:M.NORTH_WEST}function ue(e){return e===M.NORTH?M.SOUTH:e===M.EAST?M.WEST:e===M.SOUTH?M.NORTH:M.EAST}function ce(e){return e===M.NORTH_WEST||e===M.SOUTH_WEST}function ge(e){return e===M.NORTH_WEST||e===M.NORTH_EAST}function fe(e){return e===M.NORTH_WEST||e===M.WEST||e===M.SOUTH_WEST}function pe(e){return e===M.NORTH_EAST||e===M.EAST||e===M.SOUTH_EAST}function me(e){return e===M.SOUTH_EAST||e===M.SOUTH||e===M.SOUTH_WEST}function _e(e){return e===M.NORTH_EAST||e===M.NORTH||e===M.NORTH_WEST}!function(e){e[e.TOP=0]="TOP",e[e.MIDDLE=1]="MIDDLE",e[e.BOTTOM=2]="BOTTOM"}(ie||(ie={}));const Te=[M.NORTH,M.EAST,M.SOUTH,M.WEST],Ee=[M.NORTH_EAST,M.SOUTH_EAST,M.SOUTH_WEST,M.NORTH_WEST];export{ie as CenterPosition,J as SplitLimits,Y as Tile,re as almostEquals,oe as isCornerNeighbor,pe as isEast,ae as isEdgeNeighbor,_e as isNorth,ge as isNorthCorner,me as isSouth,fe as isWest,ce as isWestCorner,Ee as neighborCornerIndices,Te as neighborEdgeIndices,de as oppositeCorner,ue as oppositeEdge};