UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 45.1 kB
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Color.js";import i from"../../../core/Accessor.js";import{difference as r}from"../../../core/arrayUtils.js";import s from"../../../core/CollectionFlattener.js";import a from"../../../core/Evented.js";import n from"../../../core/Handles.js";import l from"../../../core/Logger.js";import{clamp as o}from"../../../core/mathUtils.js";import{releaseMaybe as h,destroyMaybe as d,isNone as p,isSome as u}from"../../../core/maybe.js";import c from"../../../core/ObjectPool.js";import _ from"../../../core/PooledArray.js";import{throwIfAborted as g,isAbortError as m,isAborted as T,createAbortError as y}from"../../../core/promiseUtils.js";import{watch as f,syncAndInitial as v,sync as w,initial as E}from"../../../core/reactiveUtils.js";import{property as S}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as L}from"../../../core/accessorSupport/decorators/subclass.js";import{m as D}from"../../../chunks/mat4.js";import{c as P}from"../../../chunks/mat4f64.js";import{c as b}from"../../../chunks/vec3.js";import{c as C}from"../../../chunks/vec3f64.js";import{c as U}from"../../../chunks/vec4f64.js";import{WatchUpdatingTracking as R}from"../../../core/support/WatchUpdatingTracking.js";import{getReferenceEllipsoid as x}from"../../../geometry/ellipsoidUtils.js";import{projectVectorToVector as M,projectPointToVector as j}from"../../../geometry/projection.js";import A from"../../../geometry/SpatialReference.js";import{create as I,equals as O,intersection as V,empty as k,expand as B,intersectsSphere as N}from"../../../geometry/support/aaBoundingRect.js";import{create as F,copy as q}from"../../../geometry/support/frustum.js";import{isPlateCarree as G}from"../../../geometry/support/spatialReferenceUtils.js";import{isRefreshableLayer as W}from"../../../layers/mixins/RefreshableLayer.js";import{ElevationQueryTileCache as H}from"../../../layers/support/ElevationQueryTileCache.js";import{ElevationTileData as Q}from"../../../layers/support/ElevationTileData.js";import{isBaseLayer as z}from"../../../layers/support/layerUtils.js";import{acquireDecoder as X}from"../../../layers/support/LercDecoder.js";import{printAllocations as Y}from"../../2d/engine/vectorTiles/VectorTile.js";import{directionToHeadingTilt as $}from"../support/cameraUtils.js";import K from"../support/debugFlags.js";import{toBoundingRect as J}from"../support/extentUtils.js";import{ClientType as Z}from"../support/index.js";import{updatingProgress as ee}from"../support/updatingProperties.js";import{ElevationBounds as te}from"./ElevationBounds.js";import{ElevationData as ie,sampleElevation as re}from"./ElevationData.js";import{create as se}from"./ExtentHelper.js";import{LODSnapping as ae,TextureUpdate as ne}from"./interfaces.js";import{LayerClass as le,LayerClasses as oe}from"./LayerClass.js";import{OverlayManager as he}from"./OverlayManager.js";import{PlanarPatch as de}from"./PlanarPatch.js";import{RenderOrder as pe}from"./RenderOrder.js";import{ScaleRangeQueries as ue}from"./ScaleRangeQueries.js";import{SphericalPatch as ce}from"./SphericalPatch.js";import{SplitLimits as _e}from"./SplitLimits.js";import{MAX_ROOT_TILES as ge,TOO_MANY_ROOT_TILES_AFTER_CHANGE_ERROR as me,TOO_MANY_ROOT_TILES_FOR_LAYER_ERROR as Te,MAX_MEMORY_LOD_BIAS as ye,ELEVATION_NODATA_VALUE as fe}from"./TerrainConst.js";import{TerrainRenderer as ve,TransparencyMode as we}from"./TerrainRenderer.js";import Ee from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as Se,internalAssert as Le,oppositeEdge as De,isSurfaceLayerView as Pe,isGroupLayerView as be,isMapTileLayerView as Ce,isBlendableLayerView as Ue,isElevationLayerView as Re,isVectorTileLayerView as xe,useFetchTileForLayer as Me,isImageryTileLayerView as je,isTileLayerView as Ae,releaseTileData as Ie,neighborEdgeIndices as Oe,ENABLE_TERRAIN_INTERNAL_CHECKS as Ve,ENABLE_WATERPROOFNESS_TESTS as ke,enableTerrainInternalChecks as Be,enableTerrainWaterproofnessChecks as Ne}from"./terrainUtils.js";import{Tile as Fe}from"./Tile.js";import{printAllocations as qe}from"./TilePerLayerInfo.js";import{TileUpdate as Ge}from"./TileUpdate.js";import{IteratorPreorder as We,IteratorPostorder as He,compareTilesByLij as Qe,hasLoadableSiblings as ze,sortTilesByPOI as Xe,sortTiles as Ye}from"./tileUtils.js";import{TilingSchemeLogic as $e}from"./TilingSchemeLogic.js";import{UpsampleInfo as Ke}from"./UpsampleInfo.js";import{isCompositeBlendMode as Je,blendModeFromString as Ze}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{PBRMode as et}from"../webgl-engine/core/shaderLibrary/shading/PhysicallyBasedRenderingParameters.glsl.js";import{RenderRequestType as tt}from"../webgl-engine/lib/basicInterfaces.js";import{RenderState as it}from"../../support/RenderState.js";import{ImmediateTask as rt,TaskPriority as st,noBudget as at}from"../../support/Scheduler.js";let nt=class extends(a.EventedMixin(i)){constructor(e){super(e),this._scaleRangeQueries=new ue,this._iteratorPool=new c(We,(e=>e.remove=()=>this._iteratorPool.release(e))),this._postorderIterator=new He,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._visibleCached=!1,this._usedMemory=null,this._performanceInfo=new Ee,this._viewChanged=!1,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=C(),this._eyePosSurfaceSR=C(),this._splitLimits=new _e,this._frustum=F(),this._viewProjectionMatrix=P(),this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._handles=new n,this._watchUpdatingTracking=new R,this._frameTask=rt,this._allTiles=new _,this._upsampleInfoPool=new c(Ke),this._rootTilesExtent=I(),this.updatingProgress=0,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=A.WebMercator,this.visibleElevationBounds=new te(1/0,-1/0),this.rootTileElevationBounds=new te(1/0,-1/0),this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this.oneBatchPerFrameTask=!0,this._layerViewsDirty=!1,this._shading=!0,this._isWebMercator=!1,this._isWebMercatorOnPlateeCarree=!1,this._isGlobal=!e.view?.state?.isLocal}initialize(){this._lercDecoder=X(this.view.resourceController),this._tilePool=this.view.state.isLocal?new c(de):new c(ce);const e=this.view.resourceController.memoryController;this._upsampleMapCache=e.newCache("esri.views.3d.terrain.upsample",(e=>e.unloadMapData())),this._elevationQueryCache=new H(e.newCache("elevation-query")),this._set("overlayManager",new he({surface:this})),this._handles.add([f((()=>this.overlayManager.hasHighlights),(e=>this._renderer.setNeedsHighlight(e))),f((()=>this.overlayManager.rendersOccluded),(e=>this._renderer.setRenderOccludedOverlay(e))),f((()=>this.overlayManager.renderer.isEmpty),(()=>this._evaluateTransparency()))],"overlayManager"),this._renderer=new ve({_overlayRenderer:this.overlayManager.renderer,_ellipsoidRadius:x(this.view.spatialReference).radius,_stage:this.view._stage,_allTiles:this._allTiles}),this._handles.add([f((()=>this.baseOpacity),(()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?ne.UNFADED:ne.IMMEDIATE)}),v),f((()=>this.hasCompositeBlendMode),(()=>this._updateTileTextures(this._evaluateTransparency()?ne.UNFADED:ne.IMMEDIATE)),v),f((()=>this.renderingDisabled),(()=>this.view?._stage?.renderer.setParameters({terrainRenderingEnabled:!this.renderingDisabled})),w),f((()=>this.backgroundColor),(e=>{this._handleLayerViewChanges(),this._renderer.updateTileBackground(e)}),v),f((()=>this.snapLevel),(()=>this._viewChanged=!0),w),f((()=>this.view.pointsOfInterest),(e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add((()=>e.focus.renderLocation),(()=>this._allTilesSorted=!1))})),f((()=>K.TERRAIN_TILE_TREE_SHOW_TILES),(e=>{e&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then((({TerrainTileTree3DDebugger:e})=>{!this._treeDebugger&&K.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new e({view:this.view}))})):e||(this._treeDebugger=d(this._treeDebugger))}),E)]);const{spatialReference:t}=this.view;this._extentHelper=se(this.viewingMode,{layers:this.view.map.allLayers,layerViews:this.view.allLayerViews,viewSpatialReference:t});const i=new s({getCollections:()=>this.view?.defaultsFromMap?.mapCollections?.map((({layers:e})=>e)),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}),r=new $e({layers:i,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:t});this._set("tilingSchemeLogic",r),this._updateTilingScheme(),this._elevationDataRequester=this.view.resourceController.createStreamDataRequester(Z.ELEVATION),this._mapDataRequester=this.view.resourceController.createStreamDataRequester(Z.BASEMAP);const a=this.view.resourceController.scheduler;this._frameTask=a.registerTask(st.TERRAIN_SURFACE,this),this._handles.add([f((()=>this._extentHelper.stencilEnabledExtents),(e=>this._renderer.setStencilEnabledLayerExtents(e)),E),f((()=>this.tilingSchemeLogic.tilingScheme),(()=>this._updateTilingScheme()),w),f((()=>this.extent),(()=>this._updateRootTiles()),E),this.view.on("resize",(()=>this._viewChangeUpdate())),f((()=>{const e=this.view,t=e.state;return[this._lodBias,this.lodSnapping,e.resourceController?.memoryController?.memoryFactor,t.camera,t.contentCamera,t.fixedContentCamera]}),(()=>this._viewChangeUpdate()),v),f((()=>this.view.qualitySettings?.tiledSurface?.textureFadeDuration),(e=>this._renderer.textureFadingEnabled=e>0),E),f((()=>this.view.qualitySettings?.physicallyBasedRenderingEnabled),(e=>this._renderer.pbrMode=e?et.Terrain:et.Disabled),E),f((()=>this._userClippingExtent),(()=>this._updateClippingExtent()),w)]),this._handles.add(this.view.allLayerViews.on("after-changes",(()=>this._layerViewsDirty=!0))),this._handles.add([f((()=>this.view?.map.ground.shading),(()=>{this._updateShadingIfChanged()}))]),this._updateShading(),this._layerViewsDirty=!0,this._handleLayerViewChanges()}destroy(){this._frameTask.remove(),this._handles.destroy(),this._watchUpdatingTracking.destroy(),this._lercDecoder=h(this._lercDecoder),this._removeAllTiles(),this._upsampleMapCache=d(this._upsampleMapCache),this._elevationQueryCache=d(this._elevationQueryCache);const e=this.tilingSchemeLogic.layers;this._set("tilingSchemeLogic",d(this.tilingSchemeLogic)),e.destroy(),this._basemapLayerViewHandles.forEach(((e,t)=>this._unregisterTiledLayerView(t))),this._elevationDataRequester=null,this._mapDataRequester=null,this._set("overlayManager",d(this.overlayManager)),this._tilePool=d(this._tilePool),Fe.prune(),this._treeDebugger=d(this._treeDebugger),this._renderer=d(this._renderer),this._iteratorPool=d(this._iteratorPool),this._set("view",null),this._upsampleInfoPool=d(this._upsampleInfoPool),Y(),qe()}get renderer(){return this._renderer}get frustum(){return this._frustum}get snapLevel(){if(this.lodSnapping===ae.ON){const e=this.view,t=this.tilingScheme,i=e.pointsOfInterest?.cameraOnSurface?.scale;if(i&&t){const r=e.state.contentCamera;let s=$(e,r.eye,r.viewForward,r.up).tilt;s>90&&(s=180-s);const a=2*(s/90)**2,n=t.levelAtScale(i)-a;return Math.round(n)}}return null}get lodSnapping(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences?ae.ON:ae.OFF}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get mapTileRequester(){return this._mapDataRequester}get _userClippingExtent(){const{spatialReference:e}=this,{clippingArea:t}=this.view;if(p(t)||p(e))return null;const i=I(),r=J(t,i,e)?i:null,s=this._get("extent");return O(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get extent(){const e=V(this.groundExtent,this._userClippingExtent,I()),t=this._get("extent");return O(e,t)?t:e}get groundExtent(){return u(this._tilingSchemeExtent)?this._tilingSchemeExtent:this._rootTilesExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),!!((this.running||this._watchUpdatingTracking.updating||this._asyncWorkItems>0)&&this.ready&&!this.suspended||this.overlayManager.updating)}get running(){return(this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||!this._allTilesSorted||this._layerViewsDirty||this._scaleRangeQueries.updating||this._frameTask.updating)&&this.ready&&!this.suspended}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get baseOpacity(){return this.view.map.ground.opacity}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return u(this._rootTiles)}set renderOrder(e){this._renderer.renderOrder=e,this._set("renderOrder",e)}get rootTiles(){return this._rootTiles}get spatialReference(){return this.tilingScheme?.spatialReference??null}get backgroundColor(){return this.view.map.ground.surfaceColor}set backgroundColor(e){this.view.map.ground.surfaceColor=e}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set("slicePlaneEnabled",e),this._evaluateTransparency()}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}set velvetOverground(e){this._renderer.velvetOverground=e,this._set("velvetOverground",e)}get wireframe(){return this._renderer.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}set _visible(e){e!==this._visibleCached&&(this._visibleCached=e,this._renderer.setVisibility(e),this.suspended=!e)}get opaque(){return this._renderer.transparency===we.Opaque}set suspended(e){this._set("suspended",e),this._viewChangeUpdate()}get textureFadeDuration(){return this.view.qualitySettings.tiledSurface.textureFadeDuration??0}intersect(e,t,i,r){this._renderer.intersect(e,t,i,r)}getElevation(e,t,i,r){const s=this._rootTiles;if(p(s)||!s.length)return null;if(0===s[0].layerInfo[le.ELEVATION].length)return null;const a=pt;if(a[0]=e,a[1]=t,a[2]=i,!M(a,r,a,this._spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;return Tt(s,a[0],a[1])}getElevations(e,t,i){const r=this._rootTiles,s=r?r[0].layerInfo[le.ELEVATION].length:0;if(!p(r)&&r.length&&0!==s)for(let a=0;a<t;++a){const t=3*a;i(a,Tt(r,e[t+0],e[t+1]))}else for(let a=0;a<t;++a)i(a,null)}getScale(e){if(!this.tilingScheme)return null;if(!j(e,pt,this.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system"),null;const t=this._rootTiles;if(u(t))for(const i of t)if(i?.containsPoint(pt)){let e=i;for(;e.children[0]&&!e.rendered;){const t=e.children[0].extent;let i=0;pt[0]>t[2]&&(i+=1),pt[1]<t[1]&&(i+=2),e=e.children[i]}return this._getLodBiasCorrectedScale(e.level)}return 1/0}getSphereElevationBounds(e,t,i,r,s){if(pt[0]=e,pt[1]=t,pt[2]=i,pt[3]=r,!M(pt,s,pt,this.tilingScheme?.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getSphereElevationBounds(): could not project given point to tiling scheme coordinate system"),null;let a=1/0,n=-1/0;const o=e=>{if(e&&N(e.extent,pt))if(e.isLeaf||e.rendered)a=Math.min(a,e.elevationBounds[0]),n=Math.max(n,e.elevationBounds[1]);else for(const t of e.children)o(t)},h=this._rootTiles;if(u(h))for(const l of h)o(l);return{min:a,max:n}}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!j(e,pt,this.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;pt[3]=t;let i=null;const r=e=>{if(e&&N(e.extent,pt)){const t=e.children;if(t[0]&&!e.rendered)for(const e of t)r(e);else{const t=this._getLodBiasCorrectedScale(e.level);i=null==i?t:Math.min(i,t)}}},s=this._rootTiles;if(u(s))for(const a of s)r(a);return i}queryVisibleScaleRange(e,t,i,r){const s=t?this.tilingScheme.levelAtScale(t):0,a=i?this.tilingScheme.levelAtScale(i):1/0,n=this._lodBias;this._scaleRangeQueries.queryVisibleLevelRange(e,s+n,a+n,r)}_evaluateTransparency(){const e=this.baseOpacity,t=this.overlayManager.renderer.isEmpty,i=this._renderer.transparency,r=this._allSurfaceLayersTransparent()?t?we.Empty:we.TransparentWithDraped:e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?we.Opaque:we.Semitransparent,s=i!==r;return s&&(this._renderer.transparency=r,this.view?._stage?.renderer.setParameters({terrainTransparency:this._renderer.transparency})),s}_updateTilingScheme(){const e=this.tilingSchemeLogic.tilingScheme;if(!(e!==this.tilingScheme))return;Se(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();const t=e?.spatialReference??A.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateeCarree=this._isWebMercator&&G(this.view?.renderSpatialReference),this._set("tilingScheme",e),this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.setTileSize(e.pixelSize),this.overlayManager.setSpatialReference(e.spatialReference),this._updateRootTiles())}_acquireTile(e,t,i,r){const s=this._tilePool.acquire();return ct[0]=e,ct[1]=t,ct[2]=i,s.init(ct,r,this),s}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){const{extent:e,tilingScheme:t}=this;if(!t)return;const i=ut;let s=t.rootTilesInExtent(e,i,5*ge);if(u(this._rootTiles)){if(s.length>ge)return void l.getLogger(this.declaredClass).warn(me);const e=this._rootTiles.map((e=>e.lij)),t=r(e,s,ot);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this._rootTiles.filter((e=>!(t.removed.findIndex((t=>ot(t,e.lij)))>-1)||(this._purgeTile(e),!1)));t.added.forEach((t=>e.push(this._newRootTile(t)))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,s.length>ge&&(l.getLogger(this.declaredClass).warn(Te),s=t.rootTilesInExtent(e,i,ge)),this._setRootTiles(s.map((e=>this._newRootTile(e))));O(i,this._rootTilesExtent)||(this._rootTilesExtent=I(i)),this._visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange("ready"),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness()}_updateAllTileGeometries(){const e=this._allTiles.filter((e=>e.isLoaded&&e.intersectsClippingArea));e.forEach((e=>this._renderer.updateTileGeometryState(e))),e.forEach((e=>e.renderData.updateNeighborData())),this._updateTilesGeometries(e),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){if(0===e.length)return;e.sort(Qe);const t=this.renderer;e.forEach((e=>t.updateGeometryIfNeeded(e))),e.forEach((e=>this._pendingTilesForElevationUpdateEvent.add(e)))}_shouldSplit(e){return e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.snapLevel)===Ge.SPLIT}_newRootTile(e){const t=this._acquireTile(0,e[1],e[2],null);return this._shouldSplit(t)&&t.setPendingUpdate(Ge.SPLIT),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationBounds(),t}_setRootTiles(e){if(this._rootTiles=e,this._allTiles.clear(),u(e)){const t=this._iteratorPool.acquire();for(t.reset(e);!t.done;)this._allTiles.push(t.next());t.remove()}this._renderer.setRootTiles(this._rootTiles),this._updateTilesVisibility(e)}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.suspended&&this.tilingScheme&&this._visibleCached&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this._rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.extent)&&e.resetPendingUpdate(Ge.GEOMETRY)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(p(e))return;const t=ze(e),i=this.visibleElevationBounds;let r=t?i.min:1/0,s=t?i.max:-1/0;const a=this.extent,n=this._viewProjectionMatrix;this.setTileTreeDirty();const l=this._iteratorPool.acquire();for(l.reset(e);!l.done;){const e=l.next();e.updateClippingStatus(a)&&e.resetPendingUpdate(Ge.GEOMETRY)&&this._updateTileGeometryState(e),e.setPendingUpdate(Ge.RENDERDATA),e.computeVisibility(),e.updateScreenDepth(n),e.renderData&&(r=Math.min(e.elevationBounds[0],r),s=Math.max(e.elevationBounds[1],s))}l.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._batchUpdatePendingTileGeometries(),isFinite(r)&&isFinite(s)&&(i.min!==r||i.max!==s)&&(this.visibleElevationBounds=new te(r,s))}_updateRootTileElevationBounds(){let e=1/0,t=-1/0;const i=this._rootTiles;u(i)&&i.forEach((({elevationBounds:i})=>{e=Math.min(e,i[0]),t=Math.max(t,i[1])}));const r=this.rootTileElevationBounds;r.min===e&&r.max===t||(this.rootTileElevationBounds=new te(e,t))}_updateViewDependentParameters(){const{camera:e,contentCamera:t}=this.view.state,i=Math.tan(.5*t.fovX),r=Math.tan(.5*t.fovY),s=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=i,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=s/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=s/e.height*this.maxTextureScale*a,this._splitLimits.maxLod=this.tilingScheme.getMaxLod(),this._splitLimits.angledSplitBias=this.view.qualitySettings.tiledSurface.angledSplitBias,this.view.state.fixedContentCamera?(p(this._splitLimits.frustum)&&(this._splitLimits.frustum=F()),q(this._splitLimits.frustum,t.frustum)):this._splitLimits.frustum=null,q(this._frustum,e.frustum),D(this._viewProjectionMatrix,t.projectionMatrix,t.viewMatrix),b(this._eyePosRenderSR,t.eye),M(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateRenderData(e){e.rendered&&!e.shouldLoad&&(ht(e)?this._loadChildren(e):dt(e)&&this._loadParent(e))}_updateTileGeometryState(e){e.updateVisibility();this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this._usedMemory=null}_markAllTileNeighborsForGeometryUpdate(e){const t=this._pendingTilesToUpdate;e.forEachLoadedNeighbor((e=>{t.add(e)}))}_updateTileTexture(e,t){const i=e.resetPendingUpdate(Ge.TEXTURE_FADING)?Ge.TEXTURE_FADING:!!e.resetPendingUpdate(Ge.TEXTURE_NOFADING)&&Ge.TEXTURE_NOFADING;i&&(this._renderer.updateTileTexture(e,i),this._usedMemory=null,t.madeProgress())}_emitElevationUpdateEventForTiles(){const e=gt.extent;k(e),this._pendingTilesForElevationUpdateEvent.forEach((t=>B(e,t.extent,e))),this._pendingTilesForElevationUpdateEvent.clear(),gt.spatialReference=this.spatialReference,this.emit("elevation-change",gt)}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this.renderer.processScaleRangeQueries(this._scaleRangeQueries,e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateAllTilesStatus(e),this._sortTiles(e);const t=!this.view.state.fixedContentCamera;this._mergeAndSplit(e,t),this._updateElevation(e),this._updateTextures(e),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty(),this._batchUpdatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&e.hasProgressed?this.requestUpdate():this.getUsedMemory(),this.notifyChange("updatingProgressValue")}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;const t=this._iteratorPool.acquire();t.reset(this._rootTiles);const i=this.snapLevel,r=this._splitLimits,s=this._eyePosRenderSR;for(;!t.done;){const e=t.next(),a=e.shouldSplit(r,s,i);if(a!==Ge.SPLIT){if(e.resetPendingUpdate(Ge.SPLIT)&&e.updateAgentSuspension(),a===Ge.VSPLITMERGE&&e.updateAgents(le.ELEVATION),t.skipSubtree(),!e.isLeaf){e.setPendingUpdate(Ge.MERGE),e.resetPendingUpdate(Ge.SPLIT);const t=this._iteratorPool.acquire();t.resetOne(e);const i=this._viewProjectionMatrix;for(let e=t.next();!t.done;e=t.next())this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(i);t.remove()}}else e.resetPendingUpdate(Ge.MERGE),e.isLeaf&&(e.setPendingUpdate(Ge.SPLIT),t.skipSubtree()),e.rendered&&e.setPendingUpdate(Ge.RENDERDATA)}t.remove(),this.requestUpdate(),(this.shortBatches||!this.oneBatchPerFrameTask)&&this._batchUpdatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||(Xe(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger&&this._treeDebugger.update(),e.madeProgress())}_markTileToUpdate(e){Le(e.isLoaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForGeometryUpdate(e))}_batchUpdatePendingTileGeometries(){const e=this._pendingTilesToUpdate;if(0===e.size)return;const t=Array.from(this._pendingTilesToUpdate.keys()).filter((e=>e.isLoaded&&e.intersectsClippingArea)),i=(i,r)=>{!r?.isLoaded||!r.intersectsClippingArea||r.level<i.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(Qe);const r=t.length;for(let s=0;s<r;++s){const r=t[s];Le(r.isLoaded),Le(r.intersectsClippingArea);const a=r.renderData;a.updateNeighborData();const n=a._dirtyEdgeResolutions,l=a.geometryState.neighborData;for(let t=0;t<4;++t)if(n&1<<t){const s=a.geometryState.neighborData.edgePeerNeighbors[t];s&&s?.level>=r.level&&s.forAllSubtreeOnSide(De(Oe[t]),(t=>!(!t.isLoaded||!t.intersectsClippingArea)&&(Le(e.has(t)||Qe(r,t)<0),i(r,t),!0))),i(r,l.cornerPeerNeighbors[t]),i(r,l.cornerPeerNeighbors[(t+1)%4])}}e.clear(),this._updateTilesGeometries(t),Ve&&ke&&this.checkAllTilesWaterproofness()}_mergeAndSplit(e,t){if(this.suspended||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let i=!1;const r=this.view.state.fixedContentCamera;let s=!1;for(;!e.done;){s=!0;let a=!1;const n=!this._allTiles.some((s=>{if(!i&&!r&&!s.visible)return e.done;let n=s;if(s.resetPendingUpdate(Ge.MERGE)){if(!t)return s.setPendingUpdate(Ge.MERGE),e.done;for(;n.parent?.resetPendingUpdate(Ge.MERGE);)n=n.parent;this._mergeTile(n),a=!0,e.madeProgress()}else s.resetPendingUpdate(Ge.SPLIT)&&(this._splitTile(s),a=!0,e.madeProgress());return!e.done&&n===s&&s.resetPendingUpdate(Ge.RENDERDATA)&&(this._updateRenderData(s),e.madeProgress()),e.done}));if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0),n){if(!i){i=!0;continue}if(!a)break}else this._allTilesDirty=!0}s?e.madeProgress():this._allTilesDirty=!0,!this.oneBatchPerFrameTask&&this._batchUpdatePendingTileGeometries(),this._sortTiles(e)}_updateElevation(e){e.done||(this._allTiles.some((t=>(t.resetPendingUpdate(Ge.GEOMETRY)&&(this._updateTileGeometryState(t),this._updateTileTexture(t,e),this.shortBatches&&this._batchUpdatePendingTileGeometries(),e.madeProgress()),e.done))),!this.oneBatchPerFrameTask&&this._batchUpdatePendingTileGeometries())}_updateTextures(e){e.done||this._allTiles.some((t=>(this._updateTileTexture(t,e),e.done)))}_updateClippingExtent(){this.spatialReference&&(this.updateTileOverlayParams(tt.UPDATE),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){const e=this.view.resourceController.memoryController.memoryFactor;return this.view.qualitySettings.tiledSurface.lodBias-(1-e)*ye}_getLodBiasCorrectedScale(e){const t=this.tilingScheme.levels,i=o(e-this._lodBias,0,t.length-1),r=i-Math.floor(i);return t[Math.floor(i)].scale*(1-r)+t[Math.ceil(i)].scale*r}_removeAllTiles(){u(this._rootTiles)&&(this._rootTiles.forEach((e=>this._purgeTile(e))),this._setRootTiles(null),this.notifyChange("ready")),this._allTiles.clear(),this._visible=!1}_purgeDescendantTiles(e){if(!e.children[0])return!1;let t=!1;for(let i=0;i<4;++i)t=this._purgeTile(e.children[i])||t;return e.unsetChildren(),t}_purgeTile(e){const t=this._purgeDescendantTiles(e)||e.rendered;return this._allTiles.removeUnordered(e),this._unloadTile(e),this._tilePool.release(e),t}_unloadTile(e){this._pendingTilesToUpdate.delete(e),this._pendingTilesForElevationUpdateEvent.delete(e),e.unload(this._renderer)}_splitTile(e){Se(e.isLeaf,"tile that is already split should not be split again!");const t=e.level+1,i=2*e.lij[1],r=2*e.lij[2];e.setChildren(this._createTile(t,i,r,e),this._createTile(t,i,r+1,e),this._createTile(t,i+1,r,e),this._createTile(t,i+1,r+1,e)),e.setPendingUpdate(Ge.RENDERDATA),e.updateAgentSuspension(),this._allTiles.pushArray(e.children),this._allTilesDirty=!0,++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){mt.spatialReference=this.spatialReference,mt.extent=e.extent,mt.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",mt)}_createTile(e,t,i,r){Se(!!r,"_createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.extent),s.updateScreenDepth(this._viewProjectionMatrix),this._shouldSplit(s)&&s.setPendingUpdate(Ge.SPLIT),s}get shortBatches(){return this.view.state.mode!==it.IDLE}_mergeTile(e){Se(!e.hasPendingUpdate(Ge.SPLIT),"_mergeTile sanity check"),this._purgeDescendantTiles(e)&&(Se(!e.renderData,"_mergeTile sanity check"),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this.shortBatches&&this._batchUpdatePendingTileGeometries()),this._allTilesDirty=!0,++this._performanceInfo.numMerged}_loadChildren(e){Se(e.rendered,"parent should be rendered"),this._unloadTile(e);const t=e.children;t.forEach((e=>this._loadTile(e))),t.forEach((e=>this._pendingTilesToUpdate.add(e))),this._markAllTileNeighborsForGeometryUpdate(e),this._emitTileScaleChange(e,e.level+1),this.shortBatches&&this._batchUpdatePendingTileGeometries()}_loadParent(e){const t=e.parent;this._unloadChildren(t),this._loadTile(t),this._markTileToUpdate(t),this._emitTileScaleChange(t,t.level),this.shortBatches&&this._batchUpdatePendingTileGeometries()}_unloadChildren(e){const t=e.children;if(t[0])for(let i=0;i<4;++i){const e=t[i];this._unloadChildren(e),this._unloadTile(e)}}_loadTile(e){e.load(),e.setPendingUpdate(Ge.RENDERDATA),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager&&this.overlayManager.hasOverlays&&this.overlayManager.setTileParameters(e)}_elevationDataArrived(e,t,i){const r=new ie(e.lij,e.extent,i);e.dataArrived(t,le.ELEVATION,r);const s=[e],a=e.level,n=this._iteratorPool.acquire();for(n.reset(s);!n.done;){const e=n.next();e.findElevationBoundsForLayer(t,a),e.computeElevationBounds()}0===a&&this._updateRootTileElevationBounds(),n.remove(),this._updateTilesVisibility(s)}_handleLayerViewChanges(e=at){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1;const i=new Set;let r=-1;for(const s of this.view.allLayerViews.items)if(i.add(s.uid),Pe(s)||be(s))if(this._basemapLayerViewHandles.has(s.uid)&&!be(s)){const e=this._layerClassFromLayerView(s),i=this._getLayerIdxByUID(e,s.uid);u(i)&&((i<r||p(r))&&(t=!0),r=i)}else this._registerTiledLayerView(s),s.layer.loaded&&(t=!0);this._basemapLayerViewHandles.forEach(((e,r)=>{i.has(r)||(this._unregisterTiledLayerView(r),t=!0)})),t&&this._updateTiledLayers(),this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._evaluateTransparency(),e.madeProgress()}_allSurfaceLayersTransparent(){let e=0===this.view.map?.ground?.opacity;for(const t of this.view.allLayerViews.items)if(Ce(t)&&!z(t.layer)&&0!==t.fullOpacity)return e=!1,e;return e}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if((Ue(e)||be(e))&&Je(Ze[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return Re(e)?le.ELEVATION:le.MAP}_registerTiledLayerView(e){const t=[];if((Ue(e)||be(e))&&t.push(f((()=>e.layer.blendMode),(()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(ne.UNFADED)}))),be(e))return;const i=this._layerClassFromLayerView(e);t.push(f((()=>e.suspended),(()=>this._updateTiledLayers()))),t.push(f((()=>e.fullOpacity),(()=>this._updateTileTextures(ne.UNFADED)))),t.push(f((()=>"effectiveScaleRange"in e.layer?e.layer.effectiveScaleRange:null),(()=>this._restartAllAgents(i)))),e.on("data-changed",(()=>{const t=this._getLayerIdxByUID(i,e.uid);u(t)&&this._invalidateLayerData(t,i)})),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){const t=this._basemapLayerViewHandles.get(e);if(t){for(let e=0;e<t.length;e++)t[e].remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;const e=this.view.allLayerViews,t=[[],[]];let i=null;e.forEach((e=>{if(!e.layer||e.suspended||!Pe(e)||!e.fullExtent)return;const r=this._layerClassFromLayerView(e);if(r===le.MAP){const t=e.displayLevelRange.maxLevel;t!==1/0&&(null===i||t>i)&&(i=t)}t[r].push(e)}));for(const r of oe){const e=this._layerViews[r],i=t[r];i.reverse();const s=i.length;let a=e.length!==s;const n=new Array(s),l=new Array(e.length);this._layerIndexByUid[r].clear();for(let t=0;t<s;t++){const s=i[t].uid;this._layerIndexByUid[r].set(s,t);const o=e.indexOf(i[t]);n[t]=o,t!==o&&(a=!0),o>-1&&(l[o]=t)}if(a){const e=this._postorderIterator;for(e.reset(this._rootTiles);!e.done;)e.next().modifyLayers(l,n,r);this._layerViews[r]=i,this._restartAllAgents(r),this._updateTilesVisibility(this._rootTiles)}}this.tilingScheme.ensureMaxLod(i)&&this._viewChangeUpdate()}_restartAllAgents(e){const t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;){const i=t.next();i.restartAgents(e),e===le.ELEVATION&&i.computeElevationBounds()}this._updateRootTileElevationBounds()}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll((t=>{t.updateAgents(le.MAP),e===ne.IMMEDIATE?this.renderer.updateTileTexture(t,Ge.TEXTURE_NOFADING):t.updateRenderData(le.MAP,e)})),this._evaluateTransparency()}_invalidateLayerData(e,t){this._allTiles.forAll((i=>i.removeLayerAgent(e,t))),this._allTiles.forAll((i=>i.invalidateLayerData(e,t)))}setTileTreeDirty(){this._allTilesDirty=!0}requestRender(e=tt.UPDATE){this.renderer.setNeedsRender(e)}requestUpdate(){1==++this._pendingUpdates&&(this._hasPendingUpdates=!0)}requestTileData(e,t,i,r){const s=this.layerViewByIndex(t,i),a=s.layer;return!a.tilemapCache||xe(s)?this._requestTileData(e,i,s,r):(++this._asyncWorkItems,a.tilemapCache.fetchAvailability(e.lij[0],e.lij[1],e.lij[2],{...r,timeout:6e3}).then((()=>--this._asyncWorkItems)).catch((t=>{throw--this._asyncWorkItems,g(r),m(t)||this._dataMissing(e,i,s,{notInTilemap:!0}),t})).then((()=>this._frameTask.schedule((()=>this._requestTileData(e,i,s,r)),r.signal))))}_requestTileData(e,t,i,r){return t===le.ELEVATION?Re(i)?this._requestElevationTileData(e,i,r):Promise.reject():Ce(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{if(T(i))return;const s=this._layerIndexByUid[le.ELEVATION].get(t.uid);null!=s?(this._usedMemory=null,this.requestUpdate(),this._elevationDataArrived(e,s,r)):l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer %d %s",le.ELEVATION,e.lij.toString())},s=i=>{m(i)||(this._dataMissing(e,le.ELEVATION,t,i),this.requestUpdate())};if(Me(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],{noDataValue:fe,signal:i.signal}).then((e=>{if(!T(i))return this._frameTask.schedule((()=>r(e)),i.signal,s);l.getLogger(this.declaredClass).warnOnce("A call to fetchTile resolved even though the request was aborted. fetchTile should not resolve if options.signal.aborted is true.")}),s).finally((()=>{--this._asyncWorkItems}));const a=t.getTileUrl(e.lij[0],e.lij[1],e.lij[2]);return this._elevationDataRequester.request(a,"binary",i).then((e=>this._lercDecoder.decode(e,{noDataValue:fe},i.signal))).then((e=>{e?r(new Q(e)):s(new Error("LERC decoding failed"))}),s).finally((()=>{--this._asyncWorkItems}))}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{--this._asyncWorkItems,Ie(s),T(i)||(this._dataMissing(e,le.MAP,t,r),this.requestUpdate())},s=e=>t=>r(t,e),a=r=>this._frameTask.schedule((()=>{--this._asyncWorkItems,this.requestUpdate(),T(i)?Ie(r):this._mapTileDataArrived(e,t,r)}),i.signal,s(r)).catch(s(r)),n=(e,t=null)=>this._frameTask.schedule((()=>r(e,t)));if(xe(t)){const r=t.schemaHelper.getLevelRowColumn(e.lij);return t.fetchTile(r[0],r[1],r[2],i).then(a,n)}if(je(t))return t.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then(a,n);if(Ae(t)&&Me(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then((e=>{if(T(i))return l.getLogger(this.declaredClass).warnOnce("A call to fetchTile resolved even though the request was aborted. fetchTile should not resolve if options.signal.aborted is true."),void n(y());a(e)}),n);let o=t.getTileUrl(e.lij[0],e.lij[1],e.lij[2]);W(t.layer)&&t.layer.refreshTimestamp&&(o+=`${o.includes("?")?"&":"?"}_ts=${t.layer.refreshTimestamp}`);const h=t.hasMixedImageFormats?"image+type":"image";return this._mapDataRequester.request(o,h,i).then(a,n)}_mapTileDataArrived(e,t,i){const r=this._getLayerIdxByUID(le.MAP,t.uid);u(r)?e.dataArrived(r,le.MAP,i):(Ie(i),l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer"))}_getLayerIdxByUID(e,t){return this._layerIndexByUid[e].get(t)}_dataMissing(e,t,i,r){const s=this._getLayerIdxByUID(t,i.uid);u(s)?e.dataMissing(s,t,r):l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer")}updateTileOverlayParams(e){this._rootTiles&&this.overlayManager&&(this._allTiles.forAll((e=>{e.renderData&&this.overlayManager.setTileParameters(e)})),this._renderer.setNeedsRender(e))}get performanceInfo(){const e=this._performanceInfo;return e.numNodes=this._allTiles.length,e.numLeaves=e.numVisible=e.numRendered=e.numLoadedPerLevel.length=e.numRenderedPerLevel.length=0,this._allTiles.forAll((t=>{t.isLeaf&&e.numLeaves++;const i=t.level;t.renderData&&(e.numLoadedPerLevel[i]=(e.numLoadedPerLevel[i]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[i]=(e.numRenderedPerLevel[i]||0)+1,e.numRendered++))})),e}getUsedMemory(){return this.tilingScheme?(p(this._usedMemory)&&(this._usedMemory=this._recalculateUsedMemory()),u(this._usedMemory)?this._usedMemory:0):0}_recalculateUsedMemory(){return this.tilingScheme?this._allTiles.reduce(((e,t)=>e+t.usedMemory),0):null}getUsedMemoryForLayerView(e){let t=0;const i=this._layerClassFromLayerView(e),r=this._getLayerIdxByUID(i,e.uid);return u(r)&&this._allTiles.forAll((e=>t+=e.getUsedMemoryForLayer(i,r))),t}getTile(e){if(p(e)||p(this._rootTiles))return null;const t=e.split("/").map((e=>+e));if(0===t[0])return this._rootTiles.find((e=>e.lij[1]===t[1]&&e.lij[2]===t[2]));const i=2**t[0],r=Math.floor(t[1]/i),s=Math.floor(t[2]/i);let a;if(this._rootTiles.some((e=>e.lij[1]===r&&e.lij[2]===s&&(a=e,!0))),a){let e=1<<t[0]-1;for(;a.lij[0]<t[0];){let i=t[1]&e?2:0;if((t[2]&e)>0&&i++,!a.children[i])return null;a=a.children[i],e>>=1}return Se(a.lij[0]===t[0]&&a.lij[1]===t[1]&&a.lij[2]===t[2],"not the right tile?"),a}return null}get renderPatchBorders(){return this._renderer.renderPatchBorders}set renderPatchBorders(e){this._renderer.renderPatchBorders=e}get visualizeNormals(){return this._renderer.visualizeNormals}set visualizeNormals(e){this._renderer.visualizeNormals=e}get renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){const e=this;return{renderer:e._renderer,lercDecoder:e._lercDecoder,forceReload:()=>{u(e._rootTiles)&&e._rootTiles.length>0&&(e._mergeTile(e._rootTiles[0]),e._viewChangeUpdate())},getTiles:()=>e._allTiles.toArray(),getRenderedTiles(){_t.clear(),e._allTiles.forAll((e=>{e.visible&&e.rendered&&_t.push(e)}));const t=_t.toArray();return Ye(e.renderOrder,t),t},lockTilingScheme(t,i){e._extentHelper.defaultTiledLayersExtent=i,e.tilingSchemeLogic.test.lockTilingScheme(t)}}}checkAllTilesWaterproofness(){if(!ke)return;const e=this._rootTiles;if(p(e))return;const t=e=>e?.renderData?.geometryInfo?.indices?.length>0,i=(e,i)=>{t(e)&&console.error("Tile[",e.lij,"] has geometry although parent[",i.lij,"] has geom")},r=e=>{if(e.intersectsClippingArea)if(e.renderData&&!e.renderData.geometryState&&console.error("Tile[",e.lij,"] has renderData but not geometryState"),e.renderData&&!e.renderData.geometryInfo&&console.error("Tile[",e.lij,"] has renderData but not geometryInfo"),!e.renderData?.geometryInfo||(e.renderData.geometryInfo.indices?.length??0)>0||console.error("Tile[",e.lij,"] has renderData but no indices - geometryInfo: ",e.renderData.geometryInfo),t(e)){e.checkGeometryWaterproofness();for(const t of e.children)i(t,e)}else if(e.isLeaf)console.error("Tile[",e.lij,"] has no geometry and no children, from root to leaf");else for(const t of e.children)r(t)},s=e=>{const t=e.parent?.visible??!0,i=e.visible;e.computeVisibility();const r=e.visible;if(i!==r&&t&&console.error(" Tile[",e.lij,"] has out of date visibility: ",i," instead of ",r),!e.isLeaf)for(const a of e.children)s(a)};for(const a of e)r(a),s(a)}get isGlobal(){return this._isGlobal}get shading(){return this._shading}_updateShadingIfChanged(){const e=this.view?.map?.ground?.shading;e!==this._shading&&this._updateShading()}_updateShading(){const e=this.view?.map?.ground?.shading;this._shading=e,this.renderer&&(this.renderer.shading=e,this.renderer.setNeedsRender()),this._updateAllTileGeometries()}get isWebMercator(){return this._isWebMercator}get isWebMercatorOnPlateeCarree(){return this._isWebMercatorOnPlateeCarree}isEastEndWrap(e){return this.isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this.isGlobal&&0===e[2]}lijEastEnd(e){return 2**(e+(u(this.spatialReference)&&this.spatialReference.isGeographic?1:0))}wrapEastWest(e){const t=this.lijEastEnd(e[0]),i=e[2];if(0<=i&&i<t)return e;if(!this.isGlobal)return null;const r=(i+(i<0?t:0))%t;return[e[0],e[1],r]}enableInternalChecks(e){Be(e)}enableWaterproofnessChecks(e){Ne(e)}};e([S()],nt.prototype,"_renderer",void 0),e([S({constructOnly:!0})],nt.prototype,"_scaleRangeQueries",void 0),e([S()],nt.prototype,"_hasPendingUpdates",void 0),e([S()],nt.prototype,"_asyncWorkItems",void 0),e([S()],nt.prototype,"_allTilesDirty",void 0),e([S()],nt.prototype,"_allTilesSorted",void 0),e([S()],nt.prototype,"_viewChanged",void 0),e([S({readOnly:!0})],nt.prototype,"_watchUpdatingTracking",void 0),e([S()],nt.prototype,"_frameTask",void 0),e([S({readOnly:!0})],nt.prototype,"snapLevel",null),e([S({readOnly:!0})],nt.prototype,"lodSnapping",null),e([S({constructOnly:!0})],nt.prototype,"view",void 0),e([S()],nt.prototype,"_userClippingExtent",null),e([S()],nt.prototype,"_rootTilesExtent",void 0),e([S({readOnly:!0})],nt.prototype,"extent",null),e([S({readOnly:!0})],nt.prototype,"groundExtent",null),e([S({readOnly:!0})],nt.prototype,"_tilingSchemeExtent",null),e([S({readOnly:!0})],nt.prototype,"updating",null),e([S({readOnly:!0})],nt.prototype,"running",null),e([S(ee)],nt.prototype,"updatingProgress",void 0),e([S({readOnly:!0})],nt.prototype,"updatingProgressValue",null),e([S()],nt.prototype,"_maxNumUpdating",void 0),e([S()],nt.prototype,"baseOpacity",null),e([S()],nt.prototype,"hasCompositeBlendMode",void 0),e([S({readOnly:!0})],nt.prototype,"overlayManager",void 0),e([S({readOnly:!0})],nt.prototype,"viewingMode",null),e([S()],nt.prototype,"maxTextureScale",void 0),e([S({readOnly:!0})],nt.prototype,"ready",null),e([S({value:pe.FRONT_TO_BACK})],nt.prototype,"renderOrder",null),e([S({readOnly:!0})],nt.prototype,"rootTiles",null),e([S()],nt.prototype,"_rootTiles",void 0),e([S({readOnly:!0})],nt.prototype,"spatialReference",null),e([S({type:t})],nt.prototype,"backgroundColor",null),e([S({value:!1})],nt.prototype,"slicePlaneEnabled",null),e([S({readOnly:!0})],nt.prototype,"tilingScheme",void 0),e([S({readOnly:!0})],nt.prototype,"tilingSchemeLocked",null),e([S({readOnly:!0})],nt.prototype,"tilingSchemeLogic",void 0),e([S({value:!0})],nt.prototype,"velvetOverground",null),e([S()],nt.prototype,"wireframe",null),e([S({value:!1})],nt.prototype,"suspended",null),e([S()],nt.prototype,"textureFadeDuration",null),e([S()],nt.prototype,"visibleElevationBounds",void 0),e([S()],nt.prototype,"rootTileElevationBounds",void 0),e([S()],nt.prototype,"_layerViewsDirty",void 0),e([S()],nt.prototype,"renderPatchBorders",null),e([S()],nt.prototype,"visualizeNormals",null),e([S()],nt.prototype,"renderingDisabled",null),nt=e([L("esri.views.3d.terrain.TerrainSurface")],nt);const lt=nt;function ot(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function ht(e){const t=e.children;if(!t[0])return!1;for(const i of t)if(i.shouldLoad)return!0;for(const i of t)if(ht(i))return!0;return!1}function dt(e){return e.isLeaf&&(e.parent?.shouldLoad??!1)}const pt=U(),ut=I(),ct=[0,0,0],_t=new _,gt={spatialReference:null,extent:I(),context:"ground"},mt={spatialReference:null,extent:null,scale:0};function Tt(e,t,i){for(const r of e){if(!r.containsPointXY(t,i))continue;let e=r;for(;e&&!e.renderData;){const r=(t>e.extentMidX?1:0)+(i<e.extentMidY?2:0);e=e.children[r]}const s=e?.renderData?.geometryState.samplerData??null;return re(t,i,s)}return null}export{lt as default};