@arcgis/core 4.29.6 → 4.29.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/{4984e2b79d862114d6a6.js → 1a8d56e01ddfec2257c3.js} +1 -1
- package/assets/esri/core/workers/chunks/{3afb525a131b6841276b.js → 1e4d779a884f13762601.js} +1 -1
- package/assets/esri/core/workers/chunks/{2447a4d5886aeb0ff72a.js → 205597cd91cb7ff3d2b4.js} +1 -1
- package/assets/esri/core/workers/chunks/{6c50daccd84ba5545bfe.js → 22ebdec0867e44d8d58c.js} +1 -1
- package/assets/esri/core/workers/chunks/{da4616b02dd0c3dd3d5d.js → 321547d796a2ecd72ab4.js} +1 -1
- package/assets/esri/core/workers/chunks/{6c3ae96ec90e9ed7dd50.js → 32be478638e9e643ea32.js} +1 -1
- package/assets/esri/core/workers/chunks/{a61f337802ae963d7f65.js → 59f03847a9eb96e5f65c.js} +1 -1
- package/assets/esri/core/workers/chunks/{7a98d2e026f63a581b1e.js → 5b08309b184f5d8345a0.js} +1 -1
- package/assets/esri/core/workers/chunks/631bda7b99a27f4453c1.js +1 -0
- package/assets/esri/core/workers/chunks/{c527692694688a5b3b07.js → 658a8ee9a4f24bc03f7f.js} +1 -1
- package/assets/esri/core/workers/chunks/99ac2a6a5be0604ee4c2.js +1 -0
- package/assets/esri/core/workers/chunks/{48db6e0bbb1a9c043193.js → b7a78246d25dc07f173d.js} +1 -1
- package/assets/esri/core/workers/chunks/{60ab18c6a04d4b2f1d4c.js → bb05528d2ca12c57a031.js} +1 -1
- package/assets/esri/core/workers/chunks/{5227f9eea6988aadad7f.js → cf0dc0ccbeaf9458de6e.js} +1 -1
- package/assets/esri/core/workers/chunks/{f59b5ea05caca8a1a398.js → d40408be9bbcb0021d18.js} +1 -1
- package/assets/esri/core/workers/chunks/df6fbabbc74a408575fc.js +1 -0
- package/chunks/Laserlines.glsl.js +1 -1
- package/chunks/sphere.js +1 -1
- package/chunks/vec32.js +1 -1
- package/chunks/vec42.js +1 -1
- package/core/libs/gl-matrix-2/math/quat.js +1 -1
- package/core/libs/gl-matrix-2/math/vec3.js +1 -1
- package/core/libs/gl-matrix-2/math/vec4.js +1 -1
- package/geometry/support/sphere.js +1 -1
- package/interfaces.d.ts +8 -2
- package/kernel.js +1 -1
- package/layers/Lyr3DWasmPerSceneView.js +1 -1
- package/layers/mixins/FeatureLayerBase.js +1 -1
- package/layers/orientedImagery/transformations/imageToGroundUtils.js +1 -1
- package/layers/support/SubtypeSublayer.js +1 -1
- package/layers/voxel/VoxelVolume.js +1 -1
- package/networks/UtilityNetwork.js +1 -1
- package/package.json +1 -1
- package/support/revision.js +1 -1
- package/views/2d/engine/webgl/mesh/MeshData.js +1 -1
- package/views/2d/engine/webgl/mesh/MultiTileMeshData.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/labels/LabelMeshWriter.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/text/TextMeshWriter.js +1 -1
- package/views/2d/layers/features/FeatureContainer.js +1 -1
- package/views/2d/layers/features/Processor.js +1 -1
- package/views/2d/layers/features/processor/BinningStrategy.js +1 -1
- package/views/2d/layers/features/processor/FeatureUpdateStrategy.js +1 -1
- package/views/2d/layers/features/sources/FeatureSource.js +1 -1
- package/views/2d/layers/features/sources/strategies/chunks/OverrideChunk.js +1 -1
- package/views/2d/layers/features/sources/strategies/chunks/SourceChunkStore.js +1 -1
- package/views/2d/layers/features/support/FeatureSetReader.js +1 -1
- package/views/2d/layers/features/support/FeatureSetReaderIndirect.js +1 -1
- package/views/2d/layers/features/support/GraphicsReader.js +1 -1
- package/views/3d/analysis/AreaMeasurement/support/MeasurementData.js +1 -1
- package/views/3d/camera/constraintUtils/distance.js +1 -1
- package/views/3d/camera/constraintUtils/tilt.js +1 -1
- package/views/3d/layers/I3SMeshView3D.js +1 -1
- package/views/3d/layers/graphics/Deconflictor.js +1 -1
- package/views/3d/layers/graphics/Graphics3DIconSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DWaterSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/objectResourceUtils.js +1 -1
- package/views/3d/layers/i3s/I3SClientNodeLoader.js +1 -1
- package/views/3d/layers/i3s/I3SIndex.js +1 -1
- package/views/3d/layers/i3s/I3SViewportQueries.js +1 -1
- package/views/3d/layers/support/FeatureTileVisibility3D.js +1 -1
- package/views/3d/layers/support/makeScheduleFunction.js +5 -0
- package/views/3d/state/controllers/GamepadKeyboardController.js +1 -1
- package/views/3d/state/controllers/global/PinchAndPanController.js +1 -1
- package/views/3d/state/controllers/global/ZoomController.js +1 -1
- package/views/3d/state/controllers/global/ZoomStepController.js +1 -1
- package/views/3d/state/controllers/momentum/ZoomSphericalMomentumController.js +1 -1
- package/views/3d/state/utils/navigationUtils.js +1 -1
- package/views/3d/support/geometryUtils/sphere.js +1 -1
- package/views/3d/terrain/OverlayManager.js +1 -1
- package/views/3d/terrain/PatchRenderData.js +1 -1
- package/views/3d/terrain/SphericalPatch.js +1 -1
- package/views/3d/terrain/TerrainSurface.js +1 -1
- package/views/3d/terrain/Tile.js +1 -1
- package/views/3d/webgl-engine/lib/Camera.js +1 -1
- package/views/3d/webgl-engine/lib/Object3D.js +1 -1
- package/views/3d/webgl-engine/lib/Octree.js +1 -1
- package/views/3d/webgl-engine/lib/RenderGeometry.js +1 -1
- package/views/3d/webgl-engine/lib/depthRangeUtils.js +1 -1
- package/views/3d/webgl-engine/lib/edgeRendering/EdgeView.js +1 -1
- package/views/3d/webgl-engine/lib/intersectorUtilsConversions.js +1 -1
- package/views/3d/webgl-engine/lib/lodRendering/InstanceOctree.js +1 -1
- package/views/3d/webgl-engine/lib/verticalOffsetUtils.js +1 -1
- package/views/interactive/sketch/constraints.js +1 -1
- package/views/interactive/snapping/featureSources/sceneLayerSource/sceneLayerSnappingUtils.js +1 -1
- package/views/support/geometry3dUtils.js +1 -1
- package/assets/esri/core/workers/chunks/a068f0c8c1c632e8b2cb.js +0 -1
- package/assets/esri/core/workers/chunks/a28b7d868346e13468bb.js +0 -1
- package/assets/esri/core/workers/chunks/ccd53b81c2688dd11584.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.29/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{create as r}from"../../../../geometry/support/ray.js";import{
|
|
5
|
+
import{create as r}from"../../../../geometry/support/ray.js";import{i as o}from"../../../../chunks/sphere.js";import{fromScreenAtEye as t}from"./ray.js";function s(r,s,p,e){const n=t(s,p,m);return o(r,n,e)}const m=r();export{s as intersectScreen};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.29/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Accessor.js";import{Cyclical as r,cyclicalPI as s}from"../../../core/Cyclical.js";import has from"../../../core/has.js";import{clamp as i,deg2rad as a}from"../../../core/mathUtils.js";import{destroyMaybe as n}from"../../../core/maybe.js";import{watch as o,sync as l}from"../../../core/reactiveUtils.js";import{Milliseconds as h}from"../../../core/time.js";import{property as c}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as d}from"../../../core/accessorSupport/decorators/subclass.js";import{subtract as u}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{g as p,f as m,w as _,c as y,q as g}from"../../../chunks/vec32.js";import{create as f}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{t as v,d as R,g as w}from"../../../chunks/vec42.js";import{create as O,fromValues as T}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{getReferenceEllipsoid as x}from"../../../geometry/ellipsoidUtils.js";import{projectVectorToVector as D}from"../../../geometry/projection/projectVectorToVector.js";import{create as S,width as E,copy as P,center as M,height as j,intersection as b,contains as I,intersects as C,offset as U}from"../../../geometry/support/aaBoundingRect.js";import{create as N,wrap as A}from"../../../geometry/support/ray.js";import{j as L,k as G,t as q}from"../../../chunks/sphere.js";import{angleAroundAxis as V}from"../../../geometry/support/vector.js";import{y2lat as F}from"../../../geometry/support/webMercatorUtils.js";import{viewAngle as B}from"../state/utils/viewUtils.js";import{debugFlags as k}from"../support/debugFlags.js";import{PointGraphics as H}from"../support/debugUtils.js";import{OverlayIndex as W}from"./interfaces.js";import{OverlayRenderer as Y}from"./OverlayRenderer.js";import{RenderRequestType as z}from"../webgl-engine/lib/basicInterfaces.js";import{newIntersector as X}from"../webgl-engine/lib/Intersector.js";import{fromValues as K}from"../webgl-engine/lib/LocalOriginFactory.js";import{UpdateParameters as Z}from"../webgl-engine/lib/Material.js";import{SortedRenderGeometryRenderer as J}from"../webgl-engine/lib/SortedRenderGeometryRenderer.js";import{applyTextureResizeModulo as Q}from"../webgl-engine/lib/textureUtils.js";import{removeLoadedShaderModules as $}from"../webgl-engine/parts/requireUtils.js";import{TaskPriority as ee,noBudget as te}from"../../support/Scheduler.js";import{Yield as re}from"../../support/Yield.js";const se=1.3,ie=[[-.1,-2,3.9,2],[-.1,-3.9,3.9,.1],[-2,-3.9,2,.1],[-3.9,-3.9,.1,.1],[-3.9,-2,.1,2],[-3.9,-.1,.1,3.9],[-2,-.1,2,3.9],[-.1,-.1,3.9,3.9]];let ae,ne=class extends t{constructor(e){super(e),this._spatialReference=null,this._renderSR=null,this._overlaySREqualsRenderSR=!0,this._drapeSources=new Set,this._drapeTargets=new Set,this._placementDirty=!1,this._contentUpdated=!1,this._drawTexturesDirty=!1,this._drawTexturesAnimateDirty=!1,this._longitudeCyclical=null,this._latestOriginId=0,this._maxResolution=has("esri-mobile")?2048:4096,this._animationTimeLast=0}initialize(){const e=this.view;this.renderer=new Y({view:e,worldToPCSRatio:this._worldToPCSRatio,spatialReference:this._spatialReference}),e._stage.renderer.plugins.add(this.renderer);const t=()=>this.setDrawTexturesDirty();this._groundIntersector=X(this.view.state.viewingMode),this._groundIntersector.options.backfacesTerrain=!0,this._groundIntersector.options.invisibleTerrain=!0,this._groundIntersector.options.hud=!1,this.addHandles([o((()=>this.renderer.hasHighlights),t),this.renderer.events.on("has-water",(t=>e._stage?.renderer.setParameters({hasOverlayWater:t}))),this.renderer.events.on("content-changed",t),o((()=>e.state.camera.pixelRatio),t),o((()=>e.state.alignPixelEnabled),t),this.renderer.events.on("textures-disposed",(()=>this.surface.requestRender())),o((()=>[e.pointsOfInterest?.renderPointOfView,e.pointsOfInterest?.centerOnSurfaceFrequent?.location]),(()=>this.setPlacementDirty())),o((()=>[e.state?.pixelRatio,e.state?.contentPixelRatio]),(()=>this.setPlacementDirty()),l),this.surface.on("elevation-change",(()=>this.setPlacementDirty())),e.on("resize",(()=>this.setPlacementDirty())),e.resourceController.scheduler.registerTask(ee.OVERLAY,this),e._stage.renderView.events.on("force-camera-for-screenshot",(e=>{this._updateOverlays(te,e.camera,z.BACKGROUND),this.renderer.hasOverlays&&this._drawOverlays(z.BACKGROUND,e)}))]),e._stage.renderer.renderOverlay=e=>this._renderOverlay(e)}destroy(){this.view?._stage&&(this.view._stage.renderer.plugins.remove(this.renderer),this.view._stage.renderer.renderOverlay=()=>{}),ae&&(ae.hide(),ae=null),this.renderer=n(this.renderer)}get running(){return this._placementDirty&&(this._drapeSources.size>0||this.view.graphics.length>0||k.OVERLAY_DRAW_DEBUG_TEXTURE)&&!!this._spatialReference&&!this.suspended&&this.surface.ready}get _isSpherical(){return this.view.state.isGlobal}get _worldToPCSRatio(){return null!=this._spatialReference&&this._spatialReference.isGeographic&&!this.view.state.isLocal?x(this._spatialReference).metersPerDegree:1}get _overlayStretch(){return se/this.view.resolutionScale}get suspended(){return this.surface.suspended}get updating(){return this.running||this.renderer.updating||this._contentUpdated}get rendersOccludedDraped(){return this.renderer.rendersOccludedDraped}_renderOverlay(e){if(this._contentUpdated=!1,this.renderer.processSyncDrapeSources(),this.renderer.hasOverlays)return this._dispatchAnimationUpdate(e),this._drawOverlays(z.UPDATE,this.view.state)}get hasOverlays(){return this.renderer.hasOverlays}setSpatialReference(e){this._spatialReference=e,this.renderer.spatialReference=e,this._longitudeCyclical=null;const t=this.view.renderSpatialReference;null!=e&&null!=t?(this._renderSR=t,this._overlaySREqualsRenderSR=e.equals(this._renderSR),this._isSpherical&&(this._longitudeCyclical=e.isWebMercator?new r(-20037508.342787,20037508.342787):new r(-180,180),this.renderer.longitudeCyclical=this._longitudeCyclical),this.renderer&&(this.renderer.worldToPCSRatio=this._worldToPCSRatio)):this.renderer.disposeOverlays()}registerDrapeSource(e,t,r){this._drapeSources.add(e),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources);const s=this.renderer.createDrapeSourceRenderer(e,t,r);return this._updateDrapeSourceExtent(e),this._setContentDirty(),this.notifyChange("running"),s}registerGeometryDrapeSource(e){return this.registerDrapeSource(e,J)}_updateDrapeSourceExtent(e){2===this.renderer.overlays.length&&null!=e.setDrapingExtent&&null!=this._spatialReference&&e.setDrapingExtent(this.renderer.overlays,this._spatialReference)}unregisterDrapeSource(e){this._drapeSources.has(e)&&(this._drapeSources.delete(e),this.renderer.removeDrapeSourceRenderer(e),this.renderer.ensureDrapeSources(this._drapeSources),this._setContentDirty(),this.notifyChange("running"))}registerDrapeTarget(e){this._drapeTargets.add(e),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources)}unregisterDrapeTarget(e){this._drapeTargets.delete(e),this.renderer.ensureDrapeTargets(this._drapeTargets)}_setContentDirty(){this.setPlacementDirty(),this.setDrawTexturesDirty()}setPlacementDirty(){this._placementDirty=!0}runTask(e){return this._updateOverlays(e,this.view.state.contentCamera,z.UPDATE)}_updateOverlays(e,t,r){if(!this._spatialReference)return re;const s=this._computeOverlayResolution(t);this._computeOverlayExtents(t,s,de),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources,de.stretch);const i=this._updateOverlay(W.INNER,de.inner,s,1*de.pixelRatioAdjustment,de.mapUnitsPerPixel),a=E(de.inner)/E(de.outer),n=this._updateOverlay(W.OUTER,de.outer,s,a*de.pixelRatioAdjustment,de.mapUnitsPerPixel);i!==_e.EXTENT&&n!==_e.EXTENT||(this._drapeSources.forEach((e=>this._updateDrapeSourceExtent(e))),this.surface.updateTileOverlayParams(r)),i===_e.NONE&&n===_e.NONE||this.setDrawTexturesDirty(),this._placementDirty=!1,e.madeProgress()}_computeOverlayResolution(e){const t=this.view.state.contentPixelRatio*this.view.resolutionScale,r=e.fullWidth/e.pixelRatio*t,s=e.fullHeight/e.pixelRatio*t,i=Math.ceil(1.5*Math.max(r,s));return Math.min(Q(i),this._maxResolution)}_updateOverlay(e,t,r,s,i){if(0===this.renderer.overlays.length)return _e.NONE;const a=this.renderer.overlays[e],n=a.mapUnitsPerPixel;if(a.mapUnitsPerPixel=i,a.pixelRatio=s,oe(t,a.extent)&&r===a.resolution)return n===i?_e.NONE:_e.RERENDER_ONLY;P(a.extent,t),a.resolution=r;const o=M(a.extent);return a.renderLocalOrigin=K(o[0],o[1],0,"OV_"+this._latestOriginId++),_e.EXTENT}setTileParameters(e){const t=e.renderData.overlay;if(this.renderer.overlays.length>0){const r=this.renderer.overlays[W.INNER],s=this.renderer.overlays[W.OUTER],i=e.extent;this._rectInsideRect(r.extent,i)||this._rectanglesOverlap(i,r.extent)||this._rectanglesOverlap(i,s.extent)?(this._setTileOverlayData(i,W.INNER,t),this._setTileOverlayData(i,W.OUTER,t)):(this._clearTileOverlayData(W.INNER,t),this._clearTileOverlayData(W.OUTER,t))}else this._clearTileOverlayData(W.INNER,t),this._clearTileOverlayData(W.OUTER,t)}overlayPixelSizeInMapUnits(e,t){if(0===this.renderer.overlays.length)return t();const r=this.renderer.overlays[W.INNER],s=this.renderer.overlays[W.OUTER],i=this._pointIsInExtent(e,r.extent)?r:s;return(i.extent[2]-i.extent[0])/i.resolution}_setTileOverlayData(e,t,r){if(0===this.renderer.overlays.length)return;const s=this.renderer.overlays[t].extent,i=E(s),a=j(s);let n=e[0];if(this._longitudeCyclical){n=this._longitudeCyclical.minimalMonotonic(s[0],n);const t=this._longitudeCyclical.minimalMonotonic(s[0],e[2]);n>t&&(n=t-(e[2]-e[0]))}r.setScale(t,E(e)/i,j(e)/a),r.setOffset(t,(n-s[0])/i,(e[1]-s[1])/a)}_clearTileOverlayData(e,t){t.setScale(e,-1,-1),t.setOffset(e,-1,-1)}async reloadShaders(){$(),await this.renderer.reloadShaders(),this.setDrawTexturesDirty(),this.runTask(te)}_dispatchAnimationUpdate(e){const t=h(e-this._animationTimeLast);if(t>=this.surface.view._stage.renderer.animationTimestep||null!=this.view.state.forcedAnimationTime||this._drawTexturesDirty||this._drawTexturesAnimateDirty){const r=h(t/this.surface.view._stage.renderer.animationTimeDilation),s=new Z(this.view.state.camera,r,this.view.state.forcedAnimationTime);this.renderer.updateAnimation(s)&&(this._drawTexturesAnimateDirty=!0),this._animationTimeLast=e}}setDrawTexturesDirty(){this.renderer.hasOverlays?(this._contentUpdated=!0,this._drawTexturesDirty=!0,this.view._stage.renderView.requestRender()):this.setPlacementDirty()}_intersectGroundFromView(e,t,r,s){const i=this.view.sceneIntersectionHelper.getCenterRayWithSubpixelOffset(e,me,t,r);if(null==i)return!1;const a=i.origin,n=p(ce,i.origin,i.direction);return this._groundIntersector.reset(a,n,e),this._groundIntersector.intersect([]),this.view.basemapTerrain.intersect(this._groundIntersector,null,a,n),this._groundIntersector.results.min.getIntersectionPoint(s)}_findHorizonBasedPointOfInterest(e,t){let r=.5;const a=.55,n=this.view.renderCoordsHelper.getAltitude(e.eye),o=this.view.pointsOfInterest.centerOnSurfaceFrequent,l=1e-5,h=i(o.estimatedSurfaceAltitude,e.aboveGround?-1/0:n+l,e.aboveGround?n-l:1/0),c=e.aboveGround;if("global"===this.view.viewingMode){const t=ce;L(G(q,x(this.view.spatialReference).radius+h),A(e.eye,e.viewForward),t),m(t,t,e.eye);const i=s.normalize(V(e.viewForward,t,e.viewRight))/e.fovY+.5,n=i<=0||i>=1?.5:a;r=c?n*i:i+n*(1-i)}else{const t=.5*Math.PI-Math.acos(-e.viewForward[2]),s=Math.tan(t),n=T(0,s,1,0),o=v(n,n,e.projectionMatrix)[1],l=i(.5+.5*o,0,1);r=1===l||0===l?.5:c?l*a:1-(1-l)*a}return!!this._intersectGroundFromView(e,.5,r,t)&&_(t,e.eye)<o.distance*o.distance}_computeOverlayExtents(e,t,r){const s=this.view.pointsOfInterest.centerOnSurfaceFrequent.renderLocation,i=f();this._findHorizonBasedPointOfInterest(e,i)||y(i,s),k.OVERLAY_SHOW_CENTER?(null==ae&&(ae=new H(this.view.graphics,"red")),ae.show(i,this._renderSR)):null!=ae&&ae.hide();const n=Math.max(.1,g(e.eye,i)),o=B(this.view.renderCoordsHelper,s,e.eye);this._overlaySREqualsRenderSR||D(i,this._renderSR,i,this._spatialReference);const l=this.surface.extent,h=!this._isSpherical&&this._spatialReference&&this._spatialReference.isGeographic,c=h&&this._spatialReference?1/x(this._spatialReference).metersPerDegree:1,d=this.view.state.contentPixelRatio,p=e.perScreenPixelRatio/d*n*c;r.mapUnitsPerPixel=p/this._worldToPCSRatio,r.stretch=this._overlayStretch;let m=t*p/2*r.stretch,_=!1,v=h?90:1/0;this._isSpherical&&l&&this._spatialReference&&(this._spatialReference.isWebMercator?(m/=Math.cos(F(i[1])),v=l[3]):(_=!0,m/=x(this._spatialReference).metersPerDegree,v=90),m>=v&&(m=v,i[1]=0,this._spatialReference.isWebMercator&&(i[0]=0)));let O=1;_&&(O=1/Math.max(.2,Math.cos(Math.abs(a(i[1])))),m*O>180&&(O=180/m),r.mapUnitsPerPixel*=O);const T=Math.log(2)/12;m=Math.exp(Math.round(Math.log(m)/T)*T);const S=m*O,M=32,j=.5*t/(M*S),C=.5*t/(M*m);i[0]=Math.round(i[0]*j)/j,i[1]=Math.round(i[1]*C)/C;const U=r.inner;U[0]=i[0]-S,U[1]=i[1]-m,U[2]=i[0]+S,U[3]=i[1]+m,this._isSpherical&&this._shiftExtentToFitBounds(U,1/0,v);const N=r.outer;if(6*S>E(l))P(N,l);else{if(Math.PI/2-Math.abs(o-Math.PI/2)<=.25*Math.PI)N[0]=U[0]-S,N[1]=U[1]-m,N[2]=U[2]+S,N[3]=U[3]+m;else{D(e.eye,this._renderSR,ce,this._spatialReference),u(he,i,ce);let t=-Math.atan2(he[1],he[0])+.125*Math.PI;t<0&&(t+=2*Math.PI);const r=Math.floor(t/(.25*Math.PI));R(he,ie[r],2*m),he[0]*=O,he[2]*=O,w(N,U,he)}}if(this._isSpherical)N[0]=this._longitudeCyclical.clamp(N[0]),N[2]=this._longitudeCyclical.clamp(N[2]),N[1]=Math.max(N[1],-v),N[3]=Math.min(N[3],v);else{const e=b(U,l,ue),t=b(N,l,pe);I(e,t)&&(N[2]=N[0],N[3]=N[1])}const A=Math.abs(U[2]-U[0])/t;r.mapUnitsPerPixel=Math.max(r.mapUnitsPerPixel,A),r.pixelRatioAdjustment=r.mapUnitsPerPixel/A}_drawOverlays(e,t){if(!this.renderer.hasOverlays)return;if(!this._drawTexturesDirty&&!this._drawTexturesAnimateDirty)return this.renderer;const r=this._drawTexturesDirty;this._drawTexturesDirty=this._drawTexturesAnimateDirty=!1;const s=this.renderer.computeValidity();this.renderer.releaseRenderTargets(),this.renderer.drawOverlays(t);return s!==this.renderer.computeValidity()&&this.surface.updateTileOverlayParams(z.UPDATE),r?(this.surface.requestRender(e),e===z.UPDATE&&this.surface.requestUpdate()):this.surface.requestRender(z.BACKGROUND),this.renderer}_rectanglesOverlap(e,t){return null!=e&&(this._longitudeCyclical?(this._longitudeCyclical.contains(t[0],t[2],e[0])||this._longitudeCyclical.contains(t[0],t[2],e[2])||this._longitudeCyclical.contains(e[0],e[2],t[0]))&&!(e[1]>t[3]||e[3]<t[1]):C(e,t))}_rectInsideRect(e,t){return null!=t&&(this._longitudeCyclical?this._longitudeCyclical.contains(e[0],e[2],t[0])&&this._longitudeCyclical.contains(e[0],e[2],t[2])&&t[1]>e[1]&&t[3]<e[3]:I(e,t))}_pointIsInExtent(e,t){if(this._longitudeCyclical)return this._longitudeCyclical.contains(t[0],t[2],e.x)&&e.y>=t[1]&&e.y<=t[3];const r=e.x,s=e.y;return r>t[0]&&r<t[2]&&s>t[1]&&s<t[3]}_shiftExtentToFitBounds(e,t,r){let s=0,i=0;e[0]<-t?s=e[0]+t:e[2]>t&&(s=t-e[2]),e[1]<-r?i=e[1]+r:e[3]>r&&(i=r-e[3]),U(e,s,i)}get test(){return{renderer:this.renderer,update:()=>this.runTask(te)}}};function oe(e,t){const r=1e-5,s=k.TESTS_DISABLE_OPTIMIZATIONS?0:r*Math.max(e[2]-e[0],e[3]-e[1],t[2]-t[0],t[3]-t[1]);return Math.abs(t[0]-e[0])<=s&&Math.abs(t[1]-e[1])<=s&&Math.abs(t[2]-e[2])<=s&&Math.abs(t[3]-e[3])<=s}e([c()],ne.prototype,"_spatialReference",void 0),e([c({readOnly:!0})],ne.prototype,"running",null),e([c()],ne.prototype,"_placementDirty",void 0),e([c()],ne.prototype,"_contentUpdated",void 0),e([c()],ne.prototype,"_isSpherical",null),e([c()],ne.prototype,"_worldToPCSRatio",null),e([c()],ne.prototype,"renderer",void 0),e([c({constructOnly:!0})],ne.prototype,"view",void 0),e([c({constructOnly:!0})],ne.prototype,"surface",void 0),e([c()],ne.prototype,"suspended",null),e([c()],ne.prototype,"updating",null),e([c({type:Boolean})],ne.prototype,"rendersOccludedDraped",null),ne=e([d("esri.views.3d.terrain.OverlayManager")],ne);class le{constructor(){this.inner=S(),this.outer=S(),this.mapUnitsPerPixel=0,this.pixelRatioAdjustment=1,this.stretch=se}}const he=O(),ce=f(),de=new le,ue=S(),pe=S(),me=N();var _e;!function(e){e[e.NONE=0]="NONE",e[e.EXTENT=1]="EXTENT",e[e.RERENDER_ONLY=2]="RERENDER_ONLY"}(_e||(_e={}));export{ne as OverlayManager};
|
|
5
|
+
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Accessor.js";import{Cyclical as r,cyclicalPI as s}from"../../../core/Cyclical.js";import has from"../../../core/has.js";import{clamp as i,deg2rad as a}from"../../../core/mathUtils.js";import{destroyMaybe as n}from"../../../core/maybe.js";import{watch as o,sync as l}from"../../../core/reactiveUtils.js";import{Milliseconds as h}from"../../../core/time.js";import{property as c}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as d}from"../../../core/accessorSupport/decorators/subclass.js";import{subtract as u}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{g as p,f as m,w as _,c as y,q as g}from"../../../chunks/vec32.js";import{create as f}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{t as v,b as R,f as w}from"../../../chunks/vec42.js";import{create as O,fromValues as T}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{getReferenceEllipsoid as x}from"../../../geometry/ellipsoidUtils.js";import{projectVectorToVector as D}from"../../../geometry/projection/projectVectorToVector.js";import{create as S,width as E,copy as P,center as M,height as b,intersection as j,contains as I,intersects as C,offset as U}from"../../../geometry/support/aaBoundingRect.js";import{create as N,wrap as A}from"../../../geometry/support/ray.js";import{e as L,h as G,t as q}from"../../../chunks/sphere.js";import{angleAroundAxis as V}from"../../../geometry/support/vector.js";import{y2lat as F}from"../../../geometry/support/webMercatorUtils.js";import{viewAngle as B}from"../state/utils/viewUtils.js";import{debugFlags as k}from"../support/debugFlags.js";import{PointGraphics as H}from"../support/debugUtils.js";import{OverlayIndex as W}from"./interfaces.js";import{OverlayRenderer as Y}from"./OverlayRenderer.js";import{RenderRequestType as z}from"../webgl-engine/lib/basicInterfaces.js";import{newIntersector as X}from"../webgl-engine/lib/Intersector.js";import{fromValues as K}from"../webgl-engine/lib/LocalOriginFactory.js";import{UpdateParameters as Z}from"../webgl-engine/lib/Material.js";import{SortedRenderGeometryRenderer as J}from"../webgl-engine/lib/SortedRenderGeometryRenderer.js";import{applyTextureResizeModulo as Q}from"../webgl-engine/lib/textureUtils.js";import{removeLoadedShaderModules as $}from"../webgl-engine/parts/requireUtils.js";import{TaskPriority as ee,noBudget as te}from"../../support/Scheduler.js";import{Yield as re}from"../../support/Yield.js";const se=1.3,ie=[[-.1,-2,3.9,2],[-.1,-3.9,3.9,.1],[-2,-3.9,2,.1],[-3.9,-3.9,.1,.1],[-3.9,-2,.1,2],[-3.9,-.1,.1,3.9],[-2,-.1,2,3.9],[-.1,-.1,3.9,3.9]];let ae,ne=class extends t{constructor(e){super(e),this._spatialReference=null,this._renderSR=null,this._overlaySREqualsRenderSR=!0,this._drapeSources=new Set,this._drapeTargets=new Set,this._placementDirty=!1,this._contentUpdated=!1,this._drawTexturesDirty=!1,this._drawTexturesAnimateDirty=!1,this._longitudeCyclical=null,this._latestOriginId=0,this._maxResolution=has("esri-mobile")?2048:4096,this._animationTimeLast=0}initialize(){const e=this.view;this.renderer=new Y({view:e,worldToPCSRatio:this._worldToPCSRatio,spatialReference:this._spatialReference}),e._stage.renderer.plugins.add(this.renderer);const t=()=>this.setDrawTexturesDirty();this._groundIntersector=X(this.view.state.viewingMode),this._groundIntersector.options.backfacesTerrain=!0,this._groundIntersector.options.invisibleTerrain=!0,this._groundIntersector.options.hud=!1,this.addHandles([o((()=>this.renderer.hasHighlights),t),this.renderer.events.on("has-water",(t=>e._stage?.renderer.setParameters({hasOverlayWater:t}))),this.renderer.events.on("content-changed",t),o((()=>e.state.camera.pixelRatio),t),o((()=>e.state.alignPixelEnabled),t),this.renderer.events.on("textures-disposed",(()=>this.surface.requestRender())),o((()=>[e.pointsOfInterest?.renderPointOfView,e.pointsOfInterest?.centerOnSurfaceFrequent?.location]),(()=>this.setPlacementDirty())),o((()=>[e.state?.pixelRatio,e.state?.contentPixelRatio]),(()=>this.setPlacementDirty()),l),this.surface.on("elevation-change",(()=>this.setPlacementDirty())),e.on("resize",(()=>this.setPlacementDirty())),e.resourceController.scheduler.registerTask(ee.OVERLAY,this),e._stage.renderView.events.on("force-camera-for-screenshot",(e=>{this._updateOverlays(te,e.camera,z.BACKGROUND),this.renderer.hasOverlays&&this._drawOverlays(z.BACKGROUND,e)}))]),e._stage.renderer.renderOverlay=e=>this._renderOverlay(e)}destroy(){this.view?._stage&&(this.view._stage.renderer.plugins.remove(this.renderer),this.view._stage.renderer.renderOverlay=()=>{}),ae&&(ae.hide(),ae=null),this.renderer=n(this.renderer)}get running(){return this._placementDirty&&(this._drapeSources.size>0||this.view.graphics.length>0||k.OVERLAY_DRAW_DEBUG_TEXTURE)&&!!this._spatialReference&&!this.suspended&&this.surface.ready}get _isSpherical(){return this.view.state.isGlobal}get _worldToPCSRatio(){return null!=this._spatialReference&&this._spatialReference.isGeographic&&!this.view.state.isLocal?x(this._spatialReference).metersPerDegree:1}get _overlayStretch(){return se/this.view.resolutionScale}get suspended(){return this.surface.suspended}get updating(){return this.running||this.renderer.updating||this._contentUpdated}get rendersOccludedDraped(){return this.renderer.rendersOccludedDraped}_renderOverlay(e){if(this._contentUpdated=!1,this.renderer.processSyncDrapeSources(),this.renderer.hasOverlays)return this._dispatchAnimationUpdate(e),this._drawOverlays(z.UPDATE,this.view.state)}get hasOverlays(){return this.renderer.hasOverlays}setSpatialReference(e){this._spatialReference=e,this.renderer.spatialReference=e,this._longitudeCyclical=null;const t=this.view.renderSpatialReference;null!=e&&null!=t?(this._renderSR=t,this._overlaySREqualsRenderSR=e.equals(this._renderSR),this._isSpherical&&(this._longitudeCyclical=e.isWebMercator?new r(-20037508.342787,20037508.342787):new r(-180,180),this.renderer.longitudeCyclical=this._longitudeCyclical),this.renderer&&(this.renderer.worldToPCSRatio=this._worldToPCSRatio)):this.renderer.disposeOverlays()}registerDrapeSource(e,t,r){this._drapeSources.add(e),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources);const s=this.renderer.createDrapeSourceRenderer(e,t,r);return this._updateDrapeSourceExtent(e),this._setContentDirty(),this.notifyChange("running"),s}registerGeometryDrapeSource(e){return this.registerDrapeSource(e,J)}_updateDrapeSourceExtent(e){2===this.renderer.overlays.length&&null!=e.setDrapingExtent&&null!=this._spatialReference&&e.setDrapingExtent(this.renderer.overlays,this._spatialReference)}unregisterDrapeSource(e){this._drapeSources.has(e)&&(this._drapeSources.delete(e),this.renderer.removeDrapeSourceRenderer(e),this.renderer.ensureDrapeSources(this._drapeSources),this._setContentDirty(),this.notifyChange("running"))}registerDrapeTarget(e){this._drapeTargets.add(e),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources)}unregisterDrapeTarget(e){this._drapeTargets.delete(e),this.renderer.ensureDrapeTargets(this._drapeTargets)}_setContentDirty(){this.setPlacementDirty(),this.setDrawTexturesDirty()}setPlacementDirty(){this._placementDirty=!0}runTask(e){return this._updateOverlays(e,this.view.state.contentCamera,z.UPDATE)}_updateOverlays(e,t,r){if(!this._spatialReference)return re;const s=this._computeOverlayResolution(t);this._computeOverlayExtents(t,s,de),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources,de.stretch);const i=this._updateOverlay(W.INNER,de.inner,s,1*de.pixelRatioAdjustment,de.mapUnitsPerPixel),a=E(de.inner)/E(de.outer),n=this._updateOverlay(W.OUTER,de.outer,s,a*de.pixelRatioAdjustment,de.mapUnitsPerPixel);i!==_e.EXTENT&&n!==_e.EXTENT||(this._drapeSources.forEach((e=>this._updateDrapeSourceExtent(e))),this.surface.updateTileOverlayParams(r)),i===_e.NONE&&n===_e.NONE||this.setDrawTexturesDirty(),this._placementDirty=!1,e.madeProgress()}_computeOverlayResolution(e){const t=this.view.state.contentPixelRatio*this.view.resolutionScale,r=e.fullWidth/e.pixelRatio*t,s=e.fullHeight/e.pixelRatio*t,i=Math.ceil(1.5*Math.max(r,s));return Math.min(Q(i),this._maxResolution)}_updateOverlay(e,t,r,s,i){if(0===this.renderer.overlays.length)return _e.NONE;const a=this.renderer.overlays[e],n=a.mapUnitsPerPixel;if(a.mapUnitsPerPixel=i,a.pixelRatio=s,oe(t,a.extent)&&r===a.resolution)return n===i?_e.NONE:_e.RERENDER_ONLY;P(a.extent,t),a.resolution=r;const o=M(a.extent);return a.renderLocalOrigin=K(o[0],o[1],0,"OV_"+this._latestOriginId++),_e.EXTENT}setTileParameters(e){const t=e.renderData.overlay;if(this.renderer.overlays.length>0){const r=this.renderer.overlays[W.INNER],s=this.renderer.overlays[W.OUTER],i=e.extent;this._rectInsideRect(r.extent,i)||this._rectanglesOverlap(i,r.extent)||this._rectanglesOverlap(i,s.extent)?(this._setTileOverlayData(i,W.INNER,t),this._setTileOverlayData(i,W.OUTER,t)):(this._clearTileOverlayData(W.INNER,t),this._clearTileOverlayData(W.OUTER,t))}else this._clearTileOverlayData(W.INNER,t),this._clearTileOverlayData(W.OUTER,t)}overlayPixelSizeInMapUnits(e,t){if(0===this.renderer.overlays.length)return t();const r=this.renderer.overlays[W.INNER],s=this.renderer.overlays[W.OUTER],i=this._pointIsInExtent(e,r.extent)?r:s;return(i.extent[2]-i.extent[0])/i.resolution}_setTileOverlayData(e,t,r){if(0===this.renderer.overlays.length)return;const s=this.renderer.overlays[t].extent,i=E(s),a=b(s);let n=e[0];if(this._longitudeCyclical){n=this._longitudeCyclical.minimalMonotonic(s[0],n);const t=this._longitudeCyclical.minimalMonotonic(s[0],e[2]);n>t&&(n=t-(e[2]-e[0]))}r.setScale(t,E(e)/i,b(e)/a),r.setOffset(t,(n-s[0])/i,(e[1]-s[1])/a)}_clearTileOverlayData(e,t){t.setScale(e,-1,-1),t.setOffset(e,-1,-1)}async reloadShaders(){$(),await this.renderer.reloadShaders(),this.setDrawTexturesDirty(),this.runTask(te)}_dispatchAnimationUpdate(e){const t=h(e-this._animationTimeLast);if(t>=this.surface.view._stage.renderer.animationTimestep||null!=this.view.state.forcedAnimationTime||this._drawTexturesDirty||this._drawTexturesAnimateDirty){const r=h(t/this.surface.view._stage.renderer.animationTimeDilation),s=new Z(this.view.state.camera,r,this.view.state.forcedAnimationTime);this.renderer.updateAnimation(s)&&(this._drawTexturesAnimateDirty=!0),this._animationTimeLast=e}}setDrawTexturesDirty(){this.renderer.hasOverlays?(this._contentUpdated=!0,this._drawTexturesDirty=!0,this.view._stage.renderView.requestRender()):this.setPlacementDirty()}_intersectGroundFromView(e,t,r,s){const i=this.view.sceneIntersectionHelper.getCenterRayWithSubpixelOffset(e,me,t,r);if(null==i)return!1;const a=i.origin,n=p(ce,i.origin,i.direction);return this._groundIntersector.reset(a,n,e),this._groundIntersector.intersect([]),this.view.basemapTerrain.intersect(this._groundIntersector,null,a,n),this._groundIntersector.results.min.getIntersectionPoint(s)}_findHorizonBasedPointOfInterest(e,t){let r=.5;const a=.55,n=this.view.renderCoordsHelper.getAltitude(e.eye),o=this.view.pointsOfInterest.centerOnSurfaceFrequent,l=1e-5,h=i(o.estimatedSurfaceAltitude,e.aboveGround?-1/0:n+l,e.aboveGround?n-l:1/0),c=e.aboveGround;if("global"===this.view.viewingMode){const t=ce;L(G(q,x(this.view.spatialReference).radius+h),A(e.eye,e.viewForward),t),m(t,t,e.eye);const i=s.normalize(V(e.viewForward,t,e.viewRight))/e.fovY+.5,n=i<=0||i>=1?.5:a;r=c?n*i:i+n*(1-i)}else{const t=.5*Math.PI-Math.acos(-e.viewForward[2]),s=Math.tan(t),n=T(0,s,1,0),o=v(n,n,e.projectionMatrix)[1],l=i(.5+.5*o,0,1);r=1===l||0===l?.5:c?l*a:1-(1-l)*a}return!!this._intersectGroundFromView(e,.5,r,t)&&_(t,e.eye)<o.distance*o.distance}_computeOverlayExtents(e,t,r){const s=this.view.pointsOfInterest.centerOnSurfaceFrequent.renderLocation,i=f();this._findHorizonBasedPointOfInterest(e,i)||y(i,s),k.OVERLAY_SHOW_CENTER?(null==ae&&(ae=new H(this.view.graphics,"red")),ae.show(i,this._renderSR)):null!=ae&&ae.hide();const n=Math.max(.1,g(e.eye,i)),o=B(this.view.renderCoordsHelper,s,e.eye);this._overlaySREqualsRenderSR||D(i,this._renderSR,i,this._spatialReference);const l=this.surface.extent,h=!this._isSpherical&&this._spatialReference&&this._spatialReference.isGeographic,c=h&&this._spatialReference?1/x(this._spatialReference).metersPerDegree:1,d=this.view.state.contentPixelRatio,p=e.perScreenPixelRatio/d*n*c;r.mapUnitsPerPixel=p/this._worldToPCSRatio,r.stretch=this._overlayStretch;let m=t*p/2*r.stretch,_=!1,v=h?90:1/0;this._isSpherical&&l&&this._spatialReference&&(this._spatialReference.isWebMercator?(m/=Math.cos(F(i[1])),v=l[3]):(_=!0,m/=x(this._spatialReference).metersPerDegree,v=90),m>=v&&(m=v,i[1]=0,this._spatialReference.isWebMercator&&(i[0]=0)));let O=1;_&&(O=1/Math.max(.2,Math.cos(Math.abs(a(i[1])))),m*O>180&&(O=180/m),r.mapUnitsPerPixel*=O);const T=Math.log(2)/12;m=Math.exp(Math.round(Math.log(m)/T)*T);const S=m*O,M=32,b=.5*t/(M*S),C=.5*t/(M*m);i[0]=Math.round(i[0]*b)/b,i[1]=Math.round(i[1]*C)/C;const U=r.inner;U[0]=i[0]-S,U[1]=i[1]-m,U[2]=i[0]+S,U[3]=i[1]+m,this._isSpherical&&this._shiftExtentToFitBounds(U,1/0,v);const N=r.outer;if(6*S>E(l))P(N,l);else{if(Math.PI/2-Math.abs(o-Math.PI/2)<=.25*Math.PI)N[0]=U[0]-S,N[1]=U[1]-m,N[2]=U[2]+S,N[3]=U[3]+m;else{D(e.eye,this._renderSR,ce,this._spatialReference),u(he,i,ce);let t=-Math.atan2(he[1],he[0])+.125*Math.PI;t<0&&(t+=2*Math.PI);const r=Math.floor(t/(.25*Math.PI));R(he,ie[r],2*m),he[0]*=O,he[2]*=O,w(N,U,he)}}if(this._isSpherical)N[0]=this._longitudeCyclical.clamp(N[0]),N[2]=this._longitudeCyclical.clamp(N[2]),N[1]=Math.max(N[1],-v),N[3]=Math.min(N[3],v);else{const e=j(U,l,ue),t=j(N,l,pe);I(e,t)&&(N[2]=N[0],N[3]=N[1])}const A=Math.abs(U[2]-U[0])/t;r.mapUnitsPerPixel=Math.max(r.mapUnitsPerPixel,A),r.pixelRatioAdjustment=r.mapUnitsPerPixel/A}_drawOverlays(e,t){if(!this.renderer.hasOverlays)return;if(!this._drawTexturesDirty&&!this._drawTexturesAnimateDirty)return this.renderer;const r=this._drawTexturesDirty;this._drawTexturesDirty=this._drawTexturesAnimateDirty=!1;const s=this.renderer.computeValidity();this.renderer.releaseRenderTargets(),this.renderer.drawOverlays(t);return s!==this.renderer.computeValidity()&&this.surface.updateTileOverlayParams(z.UPDATE),r?(this.surface.requestRender(e),e===z.UPDATE&&this.surface.requestUpdate()):this.surface.requestRender(z.BACKGROUND),this.renderer}_rectanglesOverlap(e,t){return null!=e&&(this._longitudeCyclical?(this._longitudeCyclical.contains(t[0],t[2],e[0])||this._longitudeCyclical.contains(t[0],t[2],e[2])||this._longitudeCyclical.contains(e[0],e[2],t[0]))&&!(e[1]>t[3]||e[3]<t[1]):C(e,t))}_rectInsideRect(e,t){return null!=t&&(this._longitudeCyclical?this._longitudeCyclical.contains(e[0],e[2],t[0])&&this._longitudeCyclical.contains(e[0],e[2],t[2])&&t[1]>e[1]&&t[3]<e[3]:I(e,t))}_pointIsInExtent(e,t){if(this._longitudeCyclical)return this._longitudeCyclical.contains(t[0],t[2],e.x)&&e.y>=t[1]&&e.y<=t[3];const r=e.x,s=e.y;return r>t[0]&&r<t[2]&&s>t[1]&&s<t[3]}_shiftExtentToFitBounds(e,t,r){let s=0,i=0;e[0]<-t?s=e[0]+t:e[2]>t&&(s=t-e[2]),e[1]<-r?i=e[1]+r:e[3]>r&&(i=r-e[3]),U(e,s,i)}get test(){return{renderer:this.renderer,update:()=>this.runTask(te)}}};function oe(e,t){const r=1e-5,s=k.TESTS_DISABLE_OPTIMIZATIONS?0:r*Math.max(e[2]-e[0],e[3]-e[1],t[2]-t[0],t[3]-t[1]);return Math.abs(t[0]-e[0])<=s&&Math.abs(t[1]-e[1])<=s&&Math.abs(t[2]-e[2])<=s&&Math.abs(t[3]-e[3])<=s}e([c()],ne.prototype,"_spatialReference",void 0),e([c({readOnly:!0})],ne.prototype,"running",null),e([c()],ne.prototype,"_placementDirty",void 0),e([c()],ne.prototype,"_contentUpdated",void 0),e([c()],ne.prototype,"_isSpherical",null),e([c()],ne.prototype,"_worldToPCSRatio",null),e([c()],ne.prototype,"renderer",void 0),e([c({constructOnly:!0})],ne.prototype,"view",void 0),e([c({constructOnly:!0})],ne.prototype,"surface",void 0),e([c()],ne.prototype,"suspended",null),e([c()],ne.prototype,"updating",null),e([c({type:Boolean})],ne.prototype,"rendersOccludedDraped",null),ne=e([d("esri.views.3d.terrain.OverlayManager")],ne);class le{constructor(){this.inner=S(),this.outer=S(),this.mapUnitsPerPixel=0,this.pixelRatioAdjustment=1,this.stretch=se}}const he=O(),ce=f(),de=new le,ue=S(),pe=S(),me=N();var _e;!function(e){e[e.NONE=0]="NONE",e[e.EXTENT=1]="EXTENT",e[e.RERENDER_ONLY=2]="RERENDER_ONLY"}(_e||(_e={}));export{ne as OverlayManager};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.29/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{equals as e}from"../../../core/arrayUtils.js";import{isPowerOfTwo as t}from"../../../core/mathUtils.js";import{disposeMaybe as r}from"../../../core/maybe.js";import{q as i,o as s,D as o,f as a,n,k as l,z as g,G as d}from"../../../chunks/vec32.js";import{create as h,clone as m}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{containsXY as u}from"../../../geometry/support/aaBoundingRect.js";import{earth as c}from"../../../geometry/support/Ellipsoid.js";import{glLayout as f}from"../support/buffer/glUtil.js";import{GeometryState as p}from"./GeometryState.js";import{NeighborIndex as y}from"./ITile.js";import{LayerClass as _}from"./LayerClass.js";import{PatchGeometry as x}from"./PatchGeometry.js";import{maxTileNeighborLevelDelta as v}from"./TerrainConst.js";import{enableTerrainInternalChecks as E,internalAssert as $,neighborEdgeIndices as S,oppositeEdge as C,neighborCornerIndices as D,v32s as T,lij2s as b}from"./terrainUtils.js";import{TextureFader as j,ActivationTime as A}from"./TextureFader.js";import{isEdgeNeighbor as V}from"./Tile.js";import R from"./TileOverlayData.js";import{fallsWithinLayer as w}from"./tileUtils.js";import{VertexArrayObject as L}from"../webgl-engine/lib/VertexArrayObject.js";import{terrainVertexAttributeLocations as N}from"../webgl-engine/shaders/TerrainTechnique.js";import{BufferObject as P}from"../../webgl/BufferObject.js";import{PixelFormat as F}from"../../webgl/enums.js";class G{constructor(){this.geometry=new x,this.intersectionData=null,this.geometryState=null,this._vao=null,this._texture=null,this._textureRef=new j((()=>this.tile.surface.fadeDuration)),this.overlay=new R,this._localOrigin=null,this._geometryStateChangedSinceLastUpdate=!0,this._hasGeometry=!1,this._modifiedFlags=0}get tile(){return this._tile}get localOrigin(){return this._localOrigin}init(e,t){this.clear(),this._tile=e,this.geometry.reset(),this.intersectionData=null,this.geometryState=new p,this._localOrigin=t,this.overlay.clear()}clear(){this.releaseGeometry(),this.releaseTexture(),this._textureRef.clear(),this._tile=null,this.intersectionData=null,this.geometryState=null}updateGeometryIfNeeded(e){if((!this._vao||this._geometryStateChangedSinceLastUpdate||this.wireframeChanged||this.clippingAreaChanged||this.samplerDataChanged||this.numVerticesPerSideChanged||this.dirtyCorners||this.dirtyEdgeResolutions||this.dirtyEdges)&&(this._updateGeometry(e),this._geometryStateChangedSinceLastUpdate=!1),E&&this.tile.intersectsClippingArea)for(let t=0;t<4;++t)$(this.geometry.getEdgeCount(t)===this.geometryState.edgeResolutions[t]+1)}_calculateEdgeResolution(e,t){const r=this.tile,i=this.geometryState.numVerticesPerSide-1;if(!r.surface.isGlobal){const t=r.surface.extent;if(null!=t&&(0===e&&r.extent[3]>t[3]||1===e&&r.extent[2]>t[2]||2===e&&r.extent[1]<t[1]||3===e&&r.extent[0]<t[0]))return i}const s=r.level,o=S[e];if(!t)return $(null==r.surface?.rootTiles||r.surface.updatingRootTiles||!r.shouldHaveNeighbor(o)),i;if(t.isLoaded){const r=t,o=r.renderData.geometryState,a=s-r.level;if($(a>=0),0===a){const e=o.numVerticesPerSide-1;return Math.max(e,i)}const n=2**a,l=o.edgeResolutions[(e+2)%4]/n;return Math.max(1,l)}$(!t.isLeaf);let a=i;return t.forAllSubtreeOnSide(C(o),(e=>e===r||(e.isLoaded?(a=Math.max(a,2**(e.level-s)),!0):($(!e.isLeaf),!1)))),a}updateNeighborData(){const e=this.tile;if(!e.intersectsClippingArea)return;const r=e.renderData.geometryState,i=t=>(t.isLoaded||t.level===e.level)&&t?.intersectsClippingArea,s=r.edgePeerNeighbors,o=r.edgePeerNeighborSamplerVersions;for(let a=0;a<4;++a){const n=e.findNeighborTile(S[a],i),l=W(e,n),g=l?.renderData?.geometryState.samplerDataVersion??-1,d=s[a],h=l!==W(e,d),m=o[a]!==g;E&&n&&($(e.level>=n.level),$(e.level-n.level<=v)),s[a]=n,(h||m)&&(o[a]=g,this._markEdgeDirty(a));const u=r.edgeResolutions[a],c=this._calculateEdgeResolution(a,n);$(t(c)),$(c>=1),r.edgeResolutions[a]=c,u!==c&&this._markEdgeResolutionDirty(a)}for(let t=0;t<4;++t){const o=e.findNeighborTile(D[t],i);r.cornerPeerNeighbors[t]=o;const a=W(e,s[t]),n=W(e,s[(t+1)%4]),l=W(e,o);H[t]=l,H[(t+1)%4]=n,H[(t+2)%4]=e,H[(t+3)%4]=a,$(H.some((t=>t?.isLoaded||t===e)));const g=H.reduce(((e,t)=>Math.min(e,t?.level??1/0)),1/0);H.forEach(((e,t)=>{e&&e?.level>g&&(H[t]=null)})),$(H.some((t=>t?.isLoaded||t===e)));const d=r.cornerNeighborCornerTiles,h=r.cornerNeighborCornerTileSamplerVersions;for(let e=0;e<4;++e){const r=H[e],i=r?.renderData.geometryState.samplerDataVersion??-1,s=4*t+e,o=d[s]!==r,a=!o&&h[s]!==i;(o||a)&&(d[s]=r,h[s]=i,this._markCornerDirty(t))}E&&$(ee.some((r=>d[4*t+r]?.isLoaded||d[4*t+r]===e)))}E&&$(this.geometryState.edgeResolutions.every((e=>e>0)));for(let t=0;t<4;++t)H[t]=null}_updateGeometry(e){if(!this.tile.intersectsClippingArea)return;E&&$(!this.tile.intersectsClippingArea||this.geometryState.edgeResolutions.every((e=>e>0))),this.intersectionData=null;const{tile:t,_vao:r,geometry:i,geometryState:s}=this,o=!r||!{geometry:i}||this.wireframeChanged||this.samplerDataChanged||this.clippingAreaChanged||this.numVerticesPerSideChanged,a=0!==this.dirtyEdgeResolutions,n=s.edgeResolutions.reduce(((e,t)=>e+t+1),0),l=o||a&&n>(i?.maxEdgeVertexCount??0),g=!l&&a,d=!g&&(0!==this.dirtyEdges||a),h=!d&&0!==this.dirtyCorners;l?(this.releaseGeometry(),this._createGeometry(e)):g?t.updateEdgeElevationsAndResolutions():d||h?t.updateEdgeElevations():h?t.updateCornerElevations():console.warn("Update for no reason?"),this._modifiedFlags=0}get hasGeometry(){return this._hasGeometry}releaseGeometry(){return this._hasGeometry=!1,this.intersectionData=null,!!this._vao&&(this._vao=r(this._vao),this.geometry.release(),!0)}ensureTexture(e,t,r){const i=t?F.RGBA:F.RGB;return null==this._texture||this._texture.descriptor.width===e&&this._texture.descriptor.pixelFormat===i||this.releaseTexture(),null==this._texture&&(this._texture=r(),this.tile.setMemoryDirty()),this._texture}releaseTexture(){null!=this._texture&&(this._texture.release(),this._texture=null,this.tile.setMemoryDirty())}get numVerticesPerSideChanged(){return 0!=(this._modifiedFlags&q)}get samplerDataChanged(){return 0!=(this._modifiedFlags&z)}get clippingAreaChanged(){return 0!=(this._modifiedFlags&J)}get wireframeChanged(){return 0!=(this._modifiedFlags&K)}get dirtyEdges(){return this._modifiedFlags>>Q&15}get dirtyCorners(){return this._modifiedFlags>>Y&15}get dirtyEdgeResolutions(){return this._modifiedFlags>>Z&15}_markCornerDirty(e){const t=1<<e<<Y;this._modifiedFlags|=t}_markEdgeDirty(e){const t=1<<e<<Q;this._modifiedFlags|=t,this._markCornerDirty((e+0)%4),this._markCornerDirty((e+3)%4)}_markEdgeResolutionDirty(e){const t=1<<e<<Z;this._modifiedFlags|=t,this._markEdgeDirty(e)}_markAllEdgesAndCornersDirty(){this._modifiedFlags|=15<<Y|15<<Q|15<<Z}updateGeometryState(){const t=this._getElevationInfo(),r=this.tile,i=t.samplerData?r.getElevationVerticesPerSide(t.maxTileLevel):r.getDefaultVerticesPerSide(),s=Math.max(i,5);let o=r.clippingArea;r.intersectsClippingArea&&!r.isWithinClippingArea||(o=null);const a=this.geometryState;let n=!1;a.numVerticesPerSide!==s&&(this._modifiedFlags|=1,a.numVerticesPerSide=s,a.samplerDataVersion++,n=!0),t.changed&&(this._modifiedFlags|=2,a.samplerData=t.samplerData,a.samplerDataVersion++,n=!0),e(a.clippingArea,o)||(this._modifiedFlags=4,a.clippingArea=o,n=!0);const l=r.surface.wireframe;return a.wireframe!==l&&(this._modifiedFlags=8,a.wireframe=l,n=!0),this._geometryStateChangedSinceLastUpdate||=n,n&&this._markAllEdgesAndCornersDirty(),this._hasGeometry=!0,this._geometryStateChangedSinceLastUpdate}_createGeometry(e){this.tile.createGeometry();const t=this.geometry.vertexAttributes,r=this.geometry.indices,i=e.gl;this._vao=new L(e,N,{geometry:f(t.layout)},{geometry:P.createVertex(e,i.STATIC_DRAW,t.buffer)},P.createIndex(e,i.STATIC_DRAW,r)),this._hasGeometry=!0}get vao(){return this._vao}setTextureReference(e,t=A.Immediate){null!=e&&e.texture!==this._texture&&this.releaseTexture(),this._textureRef.push(e,t)}get textureReference(){return this._textureRef.current}get nextTextureReference(){return this._textureRef.next}get textureFadeFactor(){return this._textureRef.fadeFactor}get textureIsFading(){return this._textureRef.isFading}_getElevationInfo(){const e=this.geometryState.samplerData,t=this.tile.layerInfo[_.ELEVATION],r=t.length,i=new Array(r);let s=0,o=0,a=!1;for(let g=0;g<r;g++){const r=t[g];if(null!=r.upsampleInfo){const t=r.upsampleInfo.tile,n=t.layerInfo[_.ELEVATION][g].data,l=n&&n.samplerData;e&&e[s]===l||(a=!0),i[s++]=l,o=Math.max(o,t.lij[0])}else if(r.data){const t=this.tile.surface.layerViewByIndex(g,_.ELEVATION);if(w(this.tile,t.layer,!1)){const t=r.data;e&&e[s]===t.samplerData||(a=!0),i[s++]=t.samplerData,o=this.tile.level}}}null!=e&&e.length!==s&&(a=!0);const n=s>0,l=n?i:null;return n&&(i.length=s),{changed:a,samplerData:l,maxTileLevel:o}}get estimatedGeometryMemoryUsage(){const e=this.intersectionData?.estimatedMemoryUsage??0;return(this.geometry.indices?.byteLength??0)+(this.geometry.vertexAttributes?.byteLength??0)+e}get texture(){return this._texture}get test(){return{hasTexture:null!=this._texture}}checkGeometryWaterproofness(){if(!E)return;const e=this.tile;if(!e.isLoaded||!e.intersectsClippingArea||0===e.level)return void $(e?.isLoaded);const r=e.surface.extent;if(null!=r&&!e.intersectsExtent(r))return;const f=S.map(((t,i)=>null!=r&&(i<2?-1:1)*(e.extent[3-i]-r[3-i])<0)),p=e.level;$(0===this.dirtyCorners),$(0===this.dirtyEdges),$(0===this.dirtyEdgeResolutions),$(!this.numVerticesPerSideChanged),$(!this.samplerDataChanged),$(!this.clippingAreaChanged),$(!this.wireframeChanged);const _=D.map((t=>e.findNeighborCornerTileExact(t,(t=>!t.intersectsClippingArea||t.isLoaded||t.level===e.level))??null)).map((e=>e?.intersectsClippingArea?e:null)),x=this.geometryState;for(let t=0;t<4;++t){const r=x.cornerPeerNeighbors[t],i=_[t];$(i===r,`Tile[${e.lij}].corner[${t}] out of date: cur=[${r?.lij}] exp=[${i?.lij}]`)}S.forEach(((r,_)=>{if(f[_])return;const x=e.findNeighborTile(r,(e=>(e.level===p||e?.isLoaded)&&e?.intersectsClippingArea));if(!x){const t=!e.surface.updatingRootTiles&&null!=e.surface.rootTiles&&e.surface.rootTiles.length>0&&e.shouldHaveNeighbor(r);return void $(!t)}$(x.isLoaded||x.level===e.level),$(x===this.geometryState.edgePeerNeighbors[_]);const v=p-x.level;if(!x.isLoaded)return $(!x.isLeaf),void $(0===v);const E=x.renderData;$(V(e,x,r)),$(v>=0);const S=2**v;if(v<0)return void $(!1);const C=e.renderData,D=C.geometry,j=C.localOrigin,A=D.getEdgeCount(_),R=D.numVerticesPerSide-1,w=E.geometry;if(!w)return void $(!1);const L=E.localOrigin,N=this.geometryState.edgePeerNeighbors[_];if(N?.isLoaded){const e=N.renderData;$(C.geometryState.edgePeerNeighborSamplerVersions[_]===e.geometryState.samplerDataVersion),$(this.geometryState.edgePeerNeighborSamplerVersions[_]===e.geometryState.samplerDataVersion)}const P=(_+2)%4,F=w.getEdgeCount(P),G=A-1,H=F-1;$(G*S===H,`Tile[${e.lij}]:e${_},res=${G} edgeRes mismatch with Neighbor[${x.lij}]:e${P},res=${H} (expected:${G*S})`);const W=e.extent,q=r===y.NORTH||r===y.SOUTH,z=F-1,J=z>>v,K=A-1;if(J<1)return void $(1===K);$(J===K),$(t(J));const Q=w.numVerticesPerSide-1;$(v>0||J===Math.max(Q,R));const Y=e.getNeighborEdgeStartVertexIndex(_,x);$(0<=Y&&Y<S);const Z=Y*J;$(0<=Z&&Z<=z-J);let ee=0,te=Z;D.getEdgeVertexPosition(_,O,j,0),D.getEdgeVertexPosition(_,I,j,A-1);const re=i(O,I),ie=Math.max(B,1e-4*re);for(let t=0;t<=J;++t){D.getEdgeVertexPosition(_,O,j,ee),w.getEdgeVertexPosition(P,I,L,te);const i=t/J,f=q?W[0]+i*(W[2]-W[0]):r===y.WEST?W[0]:W[2],p=q?r===y.SOUTH?W[1]:W[3]:W[1]+i*(W[3]-W[1]),v=e.surface.extent;if(null==v||u(v,f,p)){const t=s(O,I),r=o(O)-c.radius,i=o(I)-c.radius,u=t<ie;if(!u){console.warn(`Tile edge vertex position mismatch: between [${e.lij}].edge${_}[${ee}/${A}] and [${x.lij}].edge${P}[${te}/${F}]`),null!=v&&console.warn(" surface extent= ",v," x,y=",f,",",p);const s=h();a(s,C.localOrigin,E.localOrigin),o(s)>0&&console.warn(` localOrigins: ${C.localOrigin} vs ${E.localOrigin} d=${o(s)} [${s}]`);(()=>{const t=m(O),r=m(I);e.updateEdgeElevations(),x.updateEdgeElevations(),D.getEdgeVertexPosition(_,O,j,ee),w.getEdgeVertexPosition(P,I,L,te);const i=h();g(i,O,t),o(i)>0&&console.warn(` XXX Tile[${e.lij}] edge out of date: ${t} vs ${O} d=${o(i)} [${i}]`),g(i,I,r),o(i)>0&&console.warn(` XXX Neighbor[${x.lij}] edge out of date: ${r} vs ${I} d=${o(i)} [${i}]`)})();const n=D.getEdgeCount(_),l=w.getEdgeCount(F);$(u,`Mismatch in tile [${e.lij}].edge[${_}][${ee}/${n}] vs neighbor [${x.lij}].edge[${P}][${te}/${l}] ${T(O)} vs ${T(I)} dist=${t} h(t|n|d)=${r}|${i}|${i-r}`)}D.getEdgeNormal(_,M,ee),w.getEdgeNormal(P,U,te),n(k,M),n(X,U);const y=l(k,X),S=1-y<.01||!1||e===x;if(!S){const t=h();g(t,M,U);const r=()=>`Mismatch in tile edge normal ${b(e.lij)} (${ee}/${A-1}) edge ${_} vs neighbor ${b(x.lij)} (${te}/${F-1}) nedge ${P} :${T(M)} vs ${T(U)} dot = ${y} : ${T(t)}`;console.warn("Mismatch in tile edge normal: ",r());{e.updateEdgeElevations(),x.updateEdgeElevations();const t=h(),r=h();D.getEdgeNormal(_,t,ee),w.getEdgeNormal(P,r,te),d(M,t)||console.warn("Missing update in tile normal: ",T(M)," => ",T(t)),d(U,r)||console.warn("Missing update in neighbor normal: ",T(U)," => ",T(r))}$(S,r())}}ee+=1,te+=1}}))}}const O=h(),I=h(),M=h(),U=h(),k=h(),X=h(),B=1,H=[null,null,null,null];function W(e,t){return t?.isLoaded||t===e?t:null}const q=1,z=2,J=4,K=8,Q=4,Y=8,Z=12,ee=[0,1,2,3];export{A as ActivationTime,G as PatchRenderData,W as neighborTileIfLoadedOrSelf,ee as zeroToFour};
|
|
5
|
+
import{equals as e}from"../../../core/arrayUtils.js";import{isPowerOfTwo as t}from"../../../core/mathUtils.js";import{disposeMaybe as r}from"../../../core/maybe.js";import{q as i,o as s,H as o,f as a,n,k as l,z as g,G as d}from"../../../chunks/vec32.js";import{create as h,clone as m}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{containsXY as u}from"../../../geometry/support/aaBoundingRect.js";import{earth as c}from"../../../geometry/support/Ellipsoid.js";import{glLayout as f}from"../support/buffer/glUtil.js";import{GeometryState as p}from"./GeometryState.js";import{NeighborIndex as y}from"./ITile.js";import{LayerClass as _}from"./LayerClass.js";import{PatchGeometry as x}from"./PatchGeometry.js";import{maxTileNeighborLevelDelta as v}from"./TerrainConst.js";import{enableTerrainInternalChecks as E,internalAssert as $,neighborEdgeIndices as S,oppositeEdge as C,neighborCornerIndices as D,v32s as T,lij2s as b}from"./terrainUtils.js";import{TextureFader as j,ActivationTime as A}from"./TextureFader.js";import{isEdgeNeighbor as V}from"./Tile.js";import R from"./TileOverlayData.js";import{fallsWithinLayer as w}from"./tileUtils.js";import{VertexArrayObject as L}from"../webgl-engine/lib/VertexArrayObject.js";import{terrainVertexAttributeLocations as N}from"../webgl-engine/shaders/TerrainTechnique.js";import{BufferObject as P}from"../../webgl/BufferObject.js";import{PixelFormat as F}from"../../webgl/enums.js";class G{constructor(){this.geometry=new x,this.intersectionData=null,this.geometryState=null,this._vao=null,this._texture=null,this._textureRef=new j((()=>this.tile.surface.fadeDuration)),this.overlay=new R,this._localOrigin=null,this._geometryStateChangedSinceLastUpdate=!0,this._hasGeometry=!1,this._modifiedFlags=0}get tile(){return this._tile}get localOrigin(){return this._localOrigin}init(e,t){this.clear(),this._tile=e,this.geometry.reset(),this.intersectionData=null,this.geometryState=new p,this._localOrigin=t,this.overlay.clear()}clear(){this.releaseGeometry(),this.releaseTexture(),this._textureRef.clear(),this._tile=null,this.intersectionData=null,this.geometryState=null}updateGeometryIfNeeded(e){if((!this._vao||this._geometryStateChangedSinceLastUpdate||this.wireframeChanged||this.clippingAreaChanged||this.samplerDataChanged||this.numVerticesPerSideChanged||this.dirtyCorners||this.dirtyEdgeResolutions||this.dirtyEdges)&&(this._updateGeometry(e),this._geometryStateChangedSinceLastUpdate=!1),E&&this.tile.intersectsClippingArea)for(let t=0;t<4;++t)$(this.geometry.getEdgeCount(t)===this.geometryState.edgeResolutions[t]+1)}_calculateEdgeResolution(e,t){const r=this.tile,i=this.geometryState.numVerticesPerSide-1;if(!r.surface.isGlobal){const t=r.surface.extent;if(null!=t&&(0===e&&r.extent[3]>t[3]||1===e&&r.extent[2]>t[2]||2===e&&r.extent[1]<t[1]||3===e&&r.extent[0]<t[0]))return i}const s=r.level,o=S[e];if(!t)return $(null==r.surface?.rootTiles||r.surface.updatingRootTiles||!r.shouldHaveNeighbor(o)),i;if(t.isLoaded){const r=t,o=r.renderData.geometryState,a=s-r.level;if($(a>=0),0===a){const e=o.numVerticesPerSide-1;return Math.max(e,i)}const n=2**a,l=o.edgeResolutions[(e+2)%4]/n;return Math.max(1,l)}$(!t.isLeaf);let a=i;return t.forAllSubtreeOnSide(C(o),(e=>e===r||(e.isLoaded?(a=Math.max(a,2**(e.level-s)),!0):($(!e.isLeaf),!1)))),a}updateNeighborData(){const e=this.tile;if(!e.intersectsClippingArea)return;const r=e.renderData.geometryState,i=t=>(t.isLoaded||t.level===e.level)&&t?.intersectsClippingArea,s=r.edgePeerNeighbors,o=r.edgePeerNeighborSamplerVersions;for(let a=0;a<4;++a){const n=e.findNeighborTile(S[a],i),l=W(e,n),g=l?.renderData?.geometryState.samplerDataVersion??-1,d=s[a],h=l!==W(e,d),m=o[a]!==g;E&&n&&($(e.level>=n.level),$(e.level-n.level<=v)),s[a]=n,(h||m)&&(o[a]=g,this._markEdgeDirty(a));const u=r.edgeResolutions[a],c=this._calculateEdgeResolution(a,n);$(t(c)),$(c>=1),r.edgeResolutions[a]=c,u!==c&&this._markEdgeResolutionDirty(a)}for(let t=0;t<4;++t){const o=e.findNeighborTile(D[t],i);r.cornerPeerNeighbors[t]=o;const a=W(e,s[t]),n=W(e,s[(t+1)%4]),l=W(e,o);B[t]=l,B[(t+1)%4]=n,B[(t+2)%4]=e,B[(t+3)%4]=a,$(B.some((t=>t?.isLoaded||t===e)));const g=B.reduce(((e,t)=>Math.min(e,t?.level??1/0)),1/0);B.forEach(((e,t)=>{e&&e?.level>g&&(B[t]=null)})),$(B.some((t=>t?.isLoaded||t===e)));const d=r.cornerNeighborCornerTiles,h=r.cornerNeighborCornerTileSamplerVersions;for(let e=0;e<4;++e){const r=B[e],i=r?.renderData.geometryState.samplerDataVersion??-1,s=4*t+e,o=d[s]!==r,a=!o&&h[s]!==i;(o||a)&&(d[s]=r,h[s]=i,this._markCornerDirty(t))}E&&$(ee.some((r=>d[4*t+r]?.isLoaded||d[4*t+r]===e)))}E&&$(this.geometryState.edgeResolutions.every((e=>e>0)));for(let t=0;t<4;++t)B[t]=null}_updateGeometry(e){if(!this.tile.intersectsClippingArea)return;E&&$(!this.tile.intersectsClippingArea||this.geometryState.edgeResolutions.every((e=>e>0))),this.intersectionData=null;const{tile:t,_vao:r,geometry:i,geometryState:s}=this,o=!r||!{geometry:i}||this.wireframeChanged||this.samplerDataChanged||this.clippingAreaChanged||this.numVerticesPerSideChanged,a=0!==this.dirtyEdgeResolutions,n=s.edgeResolutions.reduce(((e,t)=>e+t+1),0),l=o||a&&n>(i?.maxEdgeVertexCount??0),g=!l&&a,d=!g&&(0!==this.dirtyEdges||a),h=!d&&0!==this.dirtyCorners;l?(this.releaseGeometry(),this._createGeometry(e)):g?t.updateEdgeElevationsAndResolutions():d||h?t.updateEdgeElevations():h?t.updateCornerElevations():console.warn("Update for no reason?"),this._modifiedFlags=0}get hasGeometry(){return this._hasGeometry}releaseGeometry(){return this._hasGeometry=!1,this.intersectionData=null,!!this._vao&&(this._vao=r(this._vao),this.geometry.release(),!0)}ensureTexture(e,t,r){const i=t?F.RGBA:F.RGB;return null==this._texture||this._texture.descriptor.width===e&&this._texture.descriptor.pixelFormat===i||this.releaseTexture(),null==this._texture&&(this._texture=r(),this.tile.setMemoryDirty()),this._texture}releaseTexture(){null!=this._texture&&(this._texture.release(),this._texture=null,this.tile.setMemoryDirty())}get numVerticesPerSideChanged(){return 0!=(this._modifiedFlags&q)}get samplerDataChanged(){return 0!=(this._modifiedFlags&z)}get clippingAreaChanged(){return 0!=(this._modifiedFlags&J)}get wireframeChanged(){return 0!=(this._modifiedFlags&K)}get dirtyEdges(){return this._modifiedFlags>>Q&15}get dirtyCorners(){return this._modifiedFlags>>Y&15}get dirtyEdgeResolutions(){return this._modifiedFlags>>Z&15}_markCornerDirty(e){const t=1<<e<<Y;this._modifiedFlags|=t}_markEdgeDirty(e){const t=1<<e<<Q;this._modifiedFlags|=t,this._markCornerDirty((e+0)%4),this._markCornerDirty((e+3)%4)}_markEdgeResolutionDirty(e){const t=1<<e<<Z;this._modifiedFlags|=t,this._markEdgeDirty(e)}_markAllEdgesAndCornersDirty(){this._modifiedFlags|=15<<Y|15<<Q|15<<Z}updateGeometryState(){const t=this._getElevationInfo(),r=this.tile,i=t.samplerData?r.getElevationVerticesPerSide(t.maxTileLevel):r.getDefaultVerticesPerSide(),s=Math.max(i,5);let o=r.clippingArea;r.intersectsClippingArea&&!r.isWithinClippingArea||(o=null);const a=this.geometryState;let n=!1;a.numVerticesPerSide!==s&&(this._modifiedFlags|=1,a.numVerticesPerSide=s,a.samplerDataVersion++,n=!0),t.changed&&(this._modifiedFlags|=2,a.samplerData=t.samplerData,a.samplerDataVersion++,n=!0),e(a.clippingArea,o)||(this._modifiedFlags=4,a.clippingArea=o,n=!0);const l=r.surface.wireframe;return a.wireframe!==l&&(this._modifiedFlags=8,a.wireframe=l,n=!0),this._geometryStateChangedSinceLastUpdate||=n,n&&this._markAllEdgesAndCornersDirty(),this._hasGeometry=!0,this._geometryStateChangedSinceLastUpdate}_createGeometry(e){this.tile.createGeometry();const t=this.geometry.vertexAttributes,r=this.geometry.indices,i=e.gl;this._vao=new L(e,N,{geometry:f(t.layout)},{geometry:P.createVertex(e,i.STATIC_DRAW,t.buffer)},P.createIndex(e,i.STATIC_DRAW,r)),this._hasGeometry=!0}get vao(){return this._vao}setTextureReference(e,t=A.Immediate){null!=e&&e.texture!==this._texture&&this.releaseTexture(),this._textureRef.push(e,t)}get textureReference(){return this._textureRef.current}get nextTextureReference(){return this._textureRef.next}get textureFadeFactor(){return this._textureRef.fadeFactor}get textureIsFading(){return this._textureRef.isFading}_getElevationInfo(){const e=this.geometryState.samplerData,t=this.tile.layerInfo[_.ELEVATION],r=t.length,i=new Array(r);let s=0,o=0,a=!1;for(let g=0;g<r;g++){const r=t[g];if(null!=r.upsampleInfo){const t=r.upsampleInfo.tile,n=t.layerInfo[_.ELEVATION][g].data,l=n&&n.samplerData;e&&e[s]===l||(a=!0),i[s++]=l,o=Math.max(o,t.lij[0])}else if(r.data){const t=this.tile.surface.layerViewByIndex(g,_.ELEVATION);if(w(this.tile,t.layer,!1)){const t=r.data;e&&e[s]===t.samplerData||(a=!0),i[s++]=t.samplerData,o=this.tile.level}}}null!=e&&e.length!==s&&(a=!0);const n=s>0,l=n?i:null;return n&&(i.length=s),{changed:a,samplerData:l,maxTileLevel:o}}get estimatedGeometryMemoryUsage(){const e=this.intersectionData?.estimatedMemoryUsage??0;return(this.geometry.indices?.byteLength??0)+(this.geometry.vertexAttributes?.byteLength??0)+e}get texture(){return this._texture}get test(){return{hasTexture:null!=this._texture}}checkGeometryWaterproofness(){if(!E)return;const e=this.tile;if(!e.isLoaded||!e.intersectsClippingArea||0===e.level)return void $(e?.isLoaded);const r=e.surface.extent;if(null!=r&&!e.intersectsExtent(r))return;const f=S.map(((t,i)=>null!=r&&(i<2?-1:1)*(e.extent[3-i]-r[3-i])<0)),p=e.level;$(0===this.dirtyCorners),$(0===this.dirtyEdges),$(0===this.dirtyEdgeResolutions),$(!this.numVerticesPerSideChanged),$(!this.samplerDataChanged),$(!this.clippingAreaChanged),$(!this.wireframeChanged);const _=D.map((t=>e.findNeighborCornerTileExact(t,(t=>!t.intersectsClippingArea||t.isLoaded||t.level===e.level))??null)).map((e=>e?.intersectsClippingArea?e:null)),x=this.geometryState;for(let t=0;t<4;++t){const r=x.cornerPeerNeighbors[t],i=_[t];$(i===r,`Tile[${e.lij}].corner[${t}] out of date: cur=[${r?.lij}] exp=[${i?.lij}]`)}S.forEach(((r,_)=>{if(f[_])return;const x=e.findNeighborTile(r,(e=>(e.level===p||e?.isLoaded)&&e?.intersectsClippingArea));if(!x){const t=!e.surface.updatingRootTiles&&null!=e.surface.rootTiles&&e.surface.rootTiles.length>0&&e.shouldHaveNeighbor(r);return void $(!t)}$(x.isLoaded||x.level===e.level),$(x===this.geometryState.edgePeerNeighbors[_]);const v=p-x.level;if(!x.isLoaded)return $(!x.isLeaf),void $(0===v);const E=x.renderData;$(V(e,x,r)),$(v>=0);const S=2**v;if(v<0)return void $(!1);const C=e.renderData,D=C.geometry,j=C.localOrigin,A=D.getEdgeCount(_),R=D.numVerticesPerSide-1,w=E.geometry;if(!w)return void $(!1);const L=E.localOrigin,N=this.geometryState.edgePeerNeighbors[_];if(N?.isLoaded){const e=N.renderData;$(C.geometryState.edgePeerNeighborSamplerVersions[_]===e.geometryState.samplerDataVersion),$(this.geometryState.edgePeerNeighborSamplerVersions[_]===e.geometryState.samplerDataVersion)}const P=(_+2)%4,F=w.getEdgeCount(P),G=A-1,B=F-1;$(G*S===B,`Tile[${e.lij}]:e${_},res=${G} edgeRes mismatch with Neighbor[${x.lij}]:e${P},res=${B} (expected:${G*S})`);const W=e.extent,q=r===y.NORTH||r===y.SOUTH,z=F-1,J=z>>v,K=A-1;if(J<1)return void $(1===K);$(J===K),$(t(J));const Q=w.numVerticesPerSide-1;$(v>0||J===Math.max(Q,R));const Y=e.getNeighborEdgeStartVertexIndex(_,x);$(0<=Y&&Y<S);const Z=Y*J;$(0<=Z&&Z<=z-J);let ee=0,te=Z;D.getEdgeVertexPosition(_,O,j,0),D.getEdgeVertexPosition(_,I,j,A-1);const re=i(O,I),ie=Math.max(X,1e-4*re);for(let t=0;t<=J;++t){D.getEdgeVertexPosition(_,O,j,ee),w.getEdgeVertexPosition(P,I,L,te);const i=t/J,f=q?W[0]+i*(W[2]-W[0]):r===y.WEST?W[0]:W[2],p=q?r===y.SOUTH?W[1]:W[3]:W[1]+i*(W[3]-W[1]),v=e.surface.extent;if(null==v||u(v,f,p)){const t=s(O,I),r=o(O)-c.radius,i=o(I)-c.radius,u=t<ie;if(!u){console.warn(`Tile edge vertex position mismatch: between [${e.lij}].edge${_}[${ee}/${A}] and [${x.lij}].edge${P}[${te}/${F}]`),null!=v&&console.warn(" surface extent= ",v," x,y=",f,",",p);const s=h();a(s,C.localOrigin,E.localOrigin),o(s)>0&&console.warn(` localOrigins: ${C.localOrigin} vs ${E.localOrigin} d=${o(s)} [${s}]`);(()=>{const t=m(O),r=m(I);e.updateEdgeElevations(),x.updateEdgeElevations(),D.getEdgeVertexPosition(_,O,j,ee),w.getEdgeVertexPosition(P,I,L,te);const i=h();g(i,O,t),o(i)>0&&console.warn(` XXX Tile[${e.lij}] edge out of date: ${t} vs ${O} d=${o(i)} [${i}]`),g(i,I,r),o(i)>0&&console.warn(` XXX Neighbor[${x.lij}] edge out of date: ${r} vs ${I} d=${o(i)} [${i}]`)})();const n=D.getEdgeCount(_),l=w.getEdgeCount(F);$(u,`Mismatch in tile [${e.lij}].edge[${_}][${ee}/${n}] vs neighbor [${x.lij}].edge[${P}][${te}/${l}] ${T(O)} vs ${T(I)} dist=${t} h(t|n|d)=${r}|${i}|${i-r}`)}D.getEdgeNormal(_,M,ee),w.getEdgeNormal(P,U,te),n(k,M),n(H,U);const y=l(k,H),S=1-y<.01||!1||e===x;if(!S){const t=h();g(t,M,U);const r=()=>`Mismatch in tile edge normal ${b(e.lij)} (${ee}/${A-1}) edge ${_} vs neighbor ${b(x.lij)} (${te}/${F-1}) nedge ${P} :${T(M)} vs ${T(U)} dot = ${y} : ${T(t)}`;console.warn("Mismatch in tile edge normal: ",r());{e.updateEdgeElevations(),x.updateEdgeElevations();const t=h(),r=h();D.getEdgeNormal(_,t,ee),w.getEdgeNormal(P,r,te),d(M,t)||console.warn("Missing update in tile normal: ",T(M)," => ",T(t)),d(U,r)||console.warn("Missing update in neighbor normal: ",T(U)," => ",T(r))}$(S,r())}}ee+=1,te+=1}}))}}const O=h(),I=h(),M=h(),U=h(),k=h(),H=h(),X=1,B=[null,null,null,null];function W(e,t){return t?.isLoaded||t===e?t:null}const q=1,z=2,J=4,K=8,Q=4,Y=8,Z=12,ee=[0,1,2,3];export{A as ActivationTime,G as PatchRenderData,W as neighborTileIfLoadedOrSelf,ee as zeroToFour};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.29/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{lerp as t}from"../../../core/mathUtils.js";import{n as e,s as i,g as s,h as o,
|
|
5
|
+
import{lerp as t}from"../../../core/mathUtils.js";import{n as e,s as i,g as s,h as o,H as n,b as r,k as l,o as a,z as h}from"../../../chunks/vec32.js";import{create as u}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{lonLatToSphericalPCPF as d}from"../../../geometry/projection/lonLatToSphericalPCPF.js";import{newDoubleArray as c}from"../../../geometry/support/DoubleArray.js";import{intersectsSphere as p,numPlanes as f,PlaneIndex as m}from"../../../geometry/support/frustum.js";import{c as g,g as x}from"../../../chunks/sphere.js";import{PatchType as $}from"./interfaces.js";import{TileFrustumVisibility as _}from"./ITile.js";import{createSphericalGlobePatch as v,updateCornerSpherical as M,updateEdgesAndCornersSpherical as S,updateEdgeElevationsAndResolutionsSpherical as b}from"./PatchGeometryFactory.js";import{enableTerrainInternalChecks as j,internalAssert as T,almostEquals as E}from"./terrainUtils.js";import{Tile as H,CenterPosition as I}from"./Tile.js";import{compareTilesByLij as B}from"./tileUtils.js";class D extends H{constructor(t,e,i,s,o){super(),this._convexHull=new Array(24),this._boundingSphere=g(),this._baseUsedMemory=1816,this.init(t,e,i,s,o)}init(i,s,o,n,r){super.init(i,s,o,n,r);const l=this.ellipsoid.radius,a=this.extentInRadians[0],h=this.extentInRadians[1],u=this.extentInRadians[2],c=this.extentInRadians[3],p=t(h,c,.5),f=t(a,u,.5),m=0===i?0:Math.min(Math.abs(h),Math.abs(c));this._edgeLen=(u-a)*Math.cos(m)*l,this._edgeLen2=this._edgeLen*this._edgeLen,this._curvatureHeight=l-Math.sqrt(l*l-this._edgeLen2/4),d(this.centerAtSeaLevel,f,p,this.ellipsoid.radius),e(this.up,this.centerAtSeaLevel),this.updateRadiusAndCenter()}updateRadiusAndCenter(){this._updateBoundingVolumes();const t=this._center;if(0===this.lij[0])i(x(t[I.MIDDLE]),0,0,0),i(t[I.TOP],0,0,0),i(t[I.BOTTOM],0,0,0),t[I.MIDDLE][3]=this.ellipsoid.radius+this.elevationBoundsMax;else{this._updateCenter();const e=t[I.MIDDLE],i=this.convexHull;let s=0;for(let t=0;t<8;++t)s=Math.max(s,y(x(e),i,3*t));t[I.MIDDLE][3]=Math.sqrt(s)}}_calculateFrustumVisibilityStatus(t){if(!p(t,this._boundingSphere))return _.OUTSIDE;if(this.lij[0]<10)return _.INTERSECTS;const e=this.convexHull,i=this.surface.view.state.camera.near;let s=!0;for(let o=0;o<f;o++){const n=o===m.NEAR,r=t[o],l=r[0],a=r[1],h=r[2],u=r[3]-(n?i:0);let d=!1;for(let t=0;t<8;++t){const i=3*t;if(l*e[i]+a*e[i+1]+h*e[i+2]+u<0){if(d=!0,!s)break}else s=!1}if(!d)return _.OUTSIDE}return s?_.INSIDE:_.INTERSECTS}computeElevationBounds(){super.computeElevationBounds(),this._updateBoundingVolumes()}createGeometry(){v(this.renderData,this._getPatchType()),this._updateBoundingVolumes(),this.setMemoryDirty()}_updateBoundingVolumes(){this._updateConvexHull(),this._updateBoundingSphere(),j&&this._checkBVs()}_updateBoundingSphere(){const t=this._boundingSphere,e=x(t),r=this.elevationBoundsMin,l=this.elevationBoundsMax,a=this.ellipsoid.radius,h=l;if(0===this.level)i(e,0,0,0),t[3]=a+h;else{const i=this.extentInRadians,h=.5*(i[0]+i[2]),u=i[1],d=i[3];O(A,h,u,a),O(V,h,d,a),s(e,A,V);o(e,e,(a+.5*(r+l))/n(e));const c=this.convexHull;let p=0;const f=(t,e)=>{const i=t[0]-c[3*e],s=t[1]-c[3*e+1],o=t[2]-c[3*e+2];return Math.sqrt(i*i+s*s+o*o)};for(let t=0;t<8;++t){const i=f(e,t);p=Math.max(p,i)}const m=p;t[3]=m+2}}_updateConvexHull(){const t=this.extentInRadians,i=this.ellipsoid.radius;if(0===this.level)return;const a=this.elevationBoundsMin,d=this.elevationBoundsMax,c=this._getPatchType(),p=this.surface.isWebMercator,f=p&&c===$.HAS_NORTH_POLE,m=p&&c===$.HAS_SOUTH_POLE,g=m||f,x=Math.PI/2,_=t[0],v=t[2],M=m?-x:t[1],S=f?x:t[3],b=.5*(_+v),j=a,H=i+(g?Math.min(0,j-1):j),I=(t,e,i)=>O(t,e,i,H),B=u(),D=u(),L=u(),y=u();I(B,_,M),I(D,_,S),I(L,v,S),I(y,v,M);const R=(t,e)=>{for(let i=0;i<3;++i)this._convexHull[3*e+i]=t[i]};R(B,0),R(D,1),R(L,2),R(y,3);const A=d,V=i+(g?Math.max(0,A+1):A),C=u(),N=u(),U=u();O(N,b,S,H),O(U,b,M,H),s(C,N,U),e(C,C);const k=u(),F=u(),w=(t,i)=>{h(F,t,i),e(F,F);const n=-l(t,k)/l(F,k);T(n>=0),o(F,F,n),s(t,t,F)};if(2**this.lij[0]>2*this.lij[1]){const t=U,i=u();r(i,P,t),e(i,i),r(k,t,i),e(k,k),T(E(l(k,t)/n(t),0)),w(B,D),w(y,L),R(B,0),R(y,3)}else if(2**this.lij[0]!==2*this.lij[1]){const t=N,i=u();r(i,P,t),e(i,i),r(k,i,t),e(k,k),w(D,B),w(L,y),R(D,1),R(L,2)}const q=(t,e)=>{const i=V/l(e,C);for(let s=0;s<3;++s)this._convexHull[3*t+s]=e[s]*i};q(4,B),q(5,D),q(6,L),q(7,y)}_getPatchType(){const t=this.lij[1],e=0===t,i=t===(1<<this.level)-1;return e?i?$.HAS_BOTH_POLES:$.HAS_NORTH_POLE:i?$.HAS_SOUTH_POLE:$.REGULAR}intersectsRay(t,e,i,s){const o=this._boundingSphere,n=o[3]+i,r=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],l=o[0]-t[0],a=o[1]-t[1],h=o[2]-t[2],u=(l*e[0]+a*e[1]+h*e[2])/r,d=e[0]*u-l,c=e[1]*u-a,p=e[2]*u-h;return d*d+c*c+p*p<n*n}getDefaultVerticesPerSide(){return this.level<L.length?L[this.level]+1:2}updateCornerElevations(){M(this.renderData),this._updateBoundingVolumes()}updateEdgeElevations(){S(this.renderData),this._updateBoundingVolumes()}updateEdgeElevationsAndResolutions(){b(this.renderData),this._updateBoundingVolumes()}_checkBVs(){if(!j)return;if(this.level<=2)return;const t=this._boundingSphere,i=t[3],o=x(t),d=u(),p=this.ellipsoid.radius,f=this.elevationBoundsMin,m=this.elevationBoundsMax,g=p+f,$=1,_=0,v=this._center[I.MIDDLE][3],M=this.convexHull,S=(t,e)=>{for(let i=0;i<3;++i)t[i]=M[3*e+i]};{const t=u(),i=u(),s=u(),o=u(),n=u(),a=(a,u,d,c)=>{S(i,a),S(s,u),S(o,d),h(i,i,s),h(o,o,s),r(t,i,o),e(t,t);const p=l(t,s);S(n,c);const f=l(t,n),m=Math.abs(f-p);T(E(m,0),`Non coplanar ${a},${u},${d},${c} diff = ${m}`)};a(0,1,2,3),a(4,5,6,7),a(0,1,4,5),a(1,2,5,6),a(2,3,6,7),a(3,0,7,4)}const b=c(24),H=(t,e,i)=>{const s=4*t;for(let o=0;o<3;++o)b[s+o]=e[o];b[s+3]=i},D=u(),L=u(),y=u(),P=u(),A=(t,i,s,o)=>{S(D,i),S(L,s),S(y,o),h(D,D,L),e(D,D),h(y,y,L),e(y,y),r(P,D,y),e(P,P);const n=l(P,L);H(t,P,n)};A(0,0,1,2),A(1,1,0,4),A(2,1,5,2),A(3,3,2,6),A(4,4,0,3),A(5,4,6,5);const V=1,C=(t,e,i,s)=>{const o=4*t;return b[o]*e+b[o+1]*i+b[o+2]*s-b[o+3]},N=(t,e,i,s)=>C(t,e,i,s)>=-V,U=(t,e)=>N(t,e[0],e[1],e[2]),k=2**this.lij[0]>2*this.lij[1],F=(t,e,s)=>Math.sqrt(R(t,e,s,o[0],o[1],o[2]))<i,w=t=>F(t[0],t[1],t[2]),q=(t,e)=>F(t[e],t[e+1],t[e+2]),G=this.extentInRadians,z=.5*(G[0]+G[2]),W=G[1],J=G[3],K=u(),Q=u();O(K,z,J,g),O(Q,z,W,g);const X=k?"Upper":"Lower";let Y=!0;for(let e=0;e<6;++e){for(let t=0;t<8;++t){const i=3*t,s=N(e,M[i],M[i+1],M[i+2]);Y&&=s,T(s,`Tile[${this.lij}] Convex hull point ${t} outside of plane ${e}`)}T(U(e,Q),`Tile[${this.lij}] (${X}) bottom mid outside of plane ${e}`),T(U(e,K),`Tile[${this.lij}] (${X}) top mid outside of plane ${e}`)}T(Y,"Not all convex hull points are inside convex hull polyhedron"),T(w(Q),`Tile[${this.lij}] (${X}) bottom mid outside of bounding sphere`),T(w(K),`Tile[${this.lij}] (${X}) top mid outside of bounding sphere`);for(let e=0;e<8;++e){const t=q(M,3*e);T(t,`Tile[${this.lij}] Convex hull point ${e} outside of bounding sphere`)}for(let e=0;e<6;++e)for(let t=0;t<8;++t){const i=3*t;N(e,M[i],M[i+1],M[i+2])||console.error(`Tile[${this.lij}] Convex hull point ${t} outside of plane ${e}`)}const{extentInRadians:Z}=this,tt=Math.max(Z[2]-Z[0],Z[3]-Z[1]),et=Math.round(tt*p),{renderData:it}=this;if(!it)return;const{geometry:st,geometryState:ot,localOrigin:nt}=it,rt=st.vertexAttributes?.position;if(!rt)return;const lt=u(),at=st.numVerticesPerSide-2,{indices:ht,indexCount:ut,edgeVerticesStartIndex:dt,poleVerticesStartIndex:ct}=st;if(!ht)return;const pt=new Set;for(let e=0;e<ut;++e){const t=ht[e];if(pt.has(t))continue;pt.add(t);const r=t<ct,l=t>=dt;let h=!1,u=-1;if(l){let e=dt;for(let i=0;i<4;++i){const s=ot.edgeResolutions[i];if(t===e||t===e+s-1){h=!0;break}if(e+=s,t<e){u=i;break}}}const c=l?ot.edgePeerNeighbors[u]:null,g=l&&c&&B(this,c)>0;rt.getVec(t,d),s(lt,d,nt);const x=n(lt)-p;let M=0,S=!1;const b=f-x,j=x-m,T=b>$,E=j>$,H=T||E,I=()=>{const e=r?"internal":l&&!h?"edge":h?"corner":"pole";return`Tile[${this.lij}].vertex[${t}]:${e}`+(T?"(below)":E?"(above)":"")+(g?"(Neighbor)":"")},D=a(lt,o);if(D>=i+_){const t=D-i;H||(console.error(`${I()} is out of the bounding sphere by ${t.toFixed(0)} / ${i.toFixed(0)}[tol=${_}] h=${x.toFixed(0)} / [${f.toFixed(0)}..${m.toFixed(0)}] (${(t/i).toFixed(0)})`),S=!0)}for(let e=0;e<6;++e)if(!N(e,lt[0],lt[1],lt[2])){const s=C(e,lt[0],lt[1],lt[2]),o=t%at,n=(t-o)/at;0===e&&b||5===e&&j||(console.error(`${I()} (${o},${n})|${at}] is out of the bounding trapezoid plane ${e} h=${Math.round(x)} / [${Math.round(f)}..${Math.round(m)}] dist=${Math.round(s)} radii = ${Math.round(i)}/${Math.round(v)}} : maxL = ${et}`),++M)}if(S||M>0)break}}get convexHull(){return this._convexHull}}const L=[128,64,64,32,16,8,8,4];function y(t,e,i){return R(t[0],t[1],t[2],e[i],e[i+1],e[i+2])}function R(t,e,i,s,o,n){const r=s-t,l=o-e,a=n-i;return r*r+l*l+a*a}const O=(t,e,i,s)=>{const o=Math.cos(e),n=Math.sin(e),r=Math.cos(i),l=Math.sin(i);t[0]=s*r*o,t[1]=s*r*n,t[2]=s*l},P=[0,0,1],A=u(),V=u();export{D as SphericalPatch};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.29/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
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/Logger.js";import{clamp as l}from"../../../core/mathUtils.js";import{releaseMaybe as o,destroyMaybe as h}from"../../../core/maybe.js";import{MemCachePool as d}from"../../../core/MemCachePool.js";import p from"../../../core/ObjectPool.js";import u from"../../../core/PooledArray.js";import{throwIfAborted as c,isAbortError as g,isAborted as _,createAbortError as m}from"../../../core/promiseUtils.js";import{watch as f,syncAndInitial as T,sync as y,initial as v}from"../../../core/reactiveUtils.js";import{property as E}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import{subclass as S}from"../../../core/accessorSupport/decorators/subclass.js";import{multiply as w}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{create as L}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{s as P,c as b}from"../../../chunks/vec32.js";import{create as C}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as D}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as j}from"../../../geometry/ellipsoidUtils.js";import M from"../../../geometry/SpatialReference.js";import{createEmptyProjectorCache as x,getProjector as U}from"../../../geometry/projection/projectors.js";import{projectPointToVector as R}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as A}from"../../../geometry/projection/projectVectorToVector.js";import{create as I,equals as B,intersection as V,intersectsSphere as k,empty as O,expand as N}from"../../../geometry/support/aaBoundingRect.js";import{create as G,copy as q}from"../../../geometry/support/frustum.js";import{isPlateCarree as F}from"../../../geometry/support/spatialReferenceUtils.js";import{c as W,g as H,d as $}from"../../../chunks/sphere.js";import{isRefreshableLayer as Q}from"../../../layers/mixins/RefreshableLayer.js";import{ElevationQueryTileCache as z}from"../../../layers/support/ElevationQueryTileCache.js";import{ElevationTileData as X}from"../../../layers/support/ElevationTileData.js";import{isBaseLayer as Y}from"../../../layers/support/layerUtils.js";import{acquireDecoder as K}from"../../../layers/support/LercDecoder.js";import{printAllocations as J}from"../../2d/engine/vectorTiles/VectorTile.js";import{directionToHeadingTilt as Z}from"../support/cameraUtils.js";import{debugFlags as ee}from"../support/debugFlags.js";import{ElevationRange as te}from"../support/ElevationRange.js";import{ElevationUpdateEvent as ie}from"../support/ElevationUpdateEvent.js";import{toBoundingRect as re}from"../support/extentUtils.js";import{ClientType as se}from"../support/index.js";import{updatingProgress as ae}from"../support/updatingProperties.js";import{ElevationBounds as ne}from"./ElevationBounds.js";import{ElevationData as le,sampleElevation as oe}from"./ElevationData.js";import{create as he}from"./ExtentHelper.js";import{LODSnapping as de,TextureUpdate as pe}from"./interfaces.js";import{LayerClass as ue,LayerClasses as ce}from"./LayerClass.js";import{OverlayManager as ge}from"./OverlayManager.js";import{PlanarPatch as _e}from"./PlanarPatch.js";import{RenderOrder as me}from"./RenderOrder.js";import{ScaleRangeQueries as fe}from"./ScaleRangeQueries.js";import{SphericalPatch as Te}from"./SphericalPatch.js";import{SplitLimits as ye}from"./SplitLimits.js";import{maxRootTiles as ve,tooManyRootTilesAfterChangeError as Ee,tooManyRootTilesForLayerError as Se,maxTileNeighborLevelDelta as we,maxMemoryLodBias as Le,elevationNodataValue as Pe}from"./TerrainConst.js";import{TerrainRenderer as be,TransparencyMode as Ce}from"./TerrainRenderer.js";import De from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as je,isVectorTileLayerView as Me,neighborEdgeIndices as xe,internalAssert as Ue,oppositeEdge as Re,isSurfaceLayerView as Ae,isGroupLayerView as Ie,isMapTileLayerView as Be,isBlendableLayerView as Ve,isElevationLayerView as ke,useFetchTileForLayer as Oe,isImageryTileLayerView as Ne,isTileLayerView as Ge,releaseTileData as qe,enableTerrainInternalChecks as Fe,neighborCornerIndices as We,oppositeCorner as He,enableWaterproofnessTests as $e,enableInternalTerrainChecks as Qe,enableTerrainWaterproofnessChecks as ze}from"./terrainUtils.js";import{Tile as Xe,lijEquals as Ye}from"./Tile.js";import{printAllocations as Ke}from"./TilePerLayerInfo.js";import{TileUpdate as Je}from"./TileUpdate.js";import{IteratorPreorder as Ze,IteratorPostorder as et,compareTilesByLij as tt,hasLoadableSiblings as it,sortTilesByPOI as rt,sortTiles as st}from"./tileUtils.js";import{TilingSchemeLogic as at}from"./TilingSchemeLogic.js";import{UpsampleInfo as nt}from"./UpsampleInfo.js";import{isCompositeBlendMode as lt,blendModeFromString as ot}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{PBRMode as ht}from"../webgl-engine/core/shaderLibrary/shading/PhysicallyBasedRenderingParameters.glsl.js";import{RenderRequestType as dt}from"../webgl-engine/lib/basicInterfaces.js";import{RenderState as pt}from"../../support/RenderState.js";import{ImmediateTask as ut,TaskPriority as ct,noBudget as gt}from"../../support/Scheduler.js";import{Yield as _t}from"../../support/Yield.js";var mt;let ft=mt=class extends(a.EventedMixin(i)){constructor(e){super(e),this._scaleRangeQueries=new fe,this._iteratorPool=new p(Ze,(e=>e.remove=()=>this._iteratorPool.release(e))),this._postorderIterator=new et,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._usedMemory=null,this._performanceInfo=new De,this._viewChanged=!1,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=C(),this._eyePosSurfaceSR=C(),this._splitLimits=new ye,this._frustum=G(),this._viewProjectionMatrix=L(),this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._watchUpdatingTracking=new D,this._frameTask=ut,this._allTiles=new u,this._upsampleInfoPool=new p(nt),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=I(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=M.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationBounds=new ne(1/0,-1/0),this.rootTileElevationBounds=new ne(1/0,-1/0),this._sebProjectorMap=new Map,this._sebProjectorCache=x(),this._tilingSchemeSpatialReference=null,this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._oneBatchPerFrameTask=!0,this._layerViewsDirty=!1,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._isWebMercator=!1,this._isWebMercatorOnPlateCarree=!1,this.overlayManager=new ge({...e,surface:this}),this._isGlobal=!e.view?.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?Te:_e}initialize(){const e=this.view,t=e.resourceController;this._lercDecoder=K(t);const i=t.memoryController;this._tileCache=new d(((e,t)=>i.newCache(e,t)),"terrain-tile"),this._upsampleMapCache=i.newCache("terrain-upsample",(e=>e.unloadMapData())),this._elevationQueryCache=new z(i.newCache("elevation-query"));const r=this.overlayManager;this._renderer=new be(r.renderer,e._stage,this._allTiles,j(e.spatialReference).radius,i),this.addHandles([f((()=>r.renderer.isEmpty),(()=>this._evaluateTransparency())),f((()=>this.renderer.visible),(e=>this.suspended=!e))],"overlayManager"),this.addHandles([f((()=>this.baseOpacity),(()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?pe.UNFADED:pe.IMMEDIATE)}),T),f((()=>this.hasCompositeBlendMode),(()=>this._updateTileTextures(this._evaluateTransparency()?pe.UNFADED:pe.IMMEDIATE)),T),f((()=>this.backgroundColor),((e,t)=>{e?.equals(t)||(this._handleLayerViewChanges(),this._renderer.updateTileBackground(e))}),y),f((()=>this.snapLevel),(()=>this._viewChanged=!0),y),f((()=>this.view.pointsOfInterest),(e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add((()=>e.focus.renderLocation),(()=>this._allTilesSorted=!1))})),f((()=>ee.TERRAIN_TILE_TREE_SHOW_TILES),(t=>{t&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then((({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&ee.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))})):t||(this._treeDebugger=h(this._treeDebugger))}),v)]);const{spatialReference:a}=e;this._extentHelper=he(this.viewingMode,{layers:e.map.allLayers,layerViews:e.allLayerViews,viewSpatialReference:a});const n=new s({getCollections:()=>e.defaultsFromMap?.mapCollections?.map((({layers:e})=>e)),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}),l=new at({layers:n,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set("tilingSchemeLogic",l),this._updateTilingScheme(),this._elevationDataRequester=t.createStreamDataRequester(se.ELEVATION),this._mapDataRequester=t.createStreamDataRequester(se.BASEMAP);const o=t.scheduler;this._frameTask=o.registerTask(ct.TERRAIN_SURFACE,this),this.addHandles([f((()=>this._extentHelper.stencilEnabledExtents),(e=>this._renderer.setStencilEnabledLayerExtents(e)),v),f((()=>this.tilingSchemeLogic.tilingScheme),(()=>this._updateTilingScheme()),y),f((()=>this.extent),(()=>this._updateRootTiles()),v),e.on("resize",(()=>this._viewChangeUpdate())),f((()=>{const t=e.state;return[this._lodBias,this.lodSnapping,e.quality,t.camera,t.contentCamera,t.fixedContentCamera]}),(()=>this._viewChangeUpdate()),T),f((()=>e.qualitySettings?.fadeDuration),(e=>this._renderer.textureFadingEnabled=e>0),v),f((()=>e.qualitySettings?.physicallyBasedRenderingEnabled),(e=>this._renderer.pbrMode=e?ht.Simplified:ht.Disabled),v),f((()=>this._userClippingExtent),(()=>this._updateClippingExtent()),y)]),this.addHandles(e.allLayerViews.on("after-changes",(()=>this._layerViewsDirty=!0))),this._layerViewsDirty=!0,this._handleLayerViewChanges(),this._renderer.updateTileBackground(this.backgroundColor)}destroy(){this._frameTask.remove(),this._watchUpdatingTracking.destroy(),this._lercDecoder=o(this._lercDecoder),this._removeAllTiles(),this._set("tilingSchemeLogic",h(this.tilingSchemeLogic)),this._basemapLayerViewHandles.forEach(((e,t)=>this._unregisterTiledLayerView(t))),this._elevationDataRequester=null,this._mapDataRequester=null,this._set("overlayManager",h(this.overlayManager)),this._tileCache=h(this._tileCache),Xe.prune(),this._treeDebugger=h(this._treeDebugger),this._renderer=h(this._renderer),this._iteratorPool=h(this._iteratorPool),this._upsampleMapCache=h(this._upsampleMapCache),this._elevationQueryCache=h(this._elevationQueryCache),this._set("view",null),this._extentHelper=h(this._extentHelper),this._upsampleInfoPool=h(this._upsampleInfoPool),J(),Ke()}get renderer(){return this._renderer}get frustum(){return this._frustum}get snapLevel(){if(this.lodSnapping===de.ON){const e=this.view,t=this.tilingScheme,i=e.pointsOfInterest?.cameraOnSurface?.scale;if(t&&i){const r=e.state.contentCamera;let s=Z(e,r.eye,r.viewForward,r.up).tilt;s>90&&(s=180-s);const a=2*(s/90)**2,n=t.levelAtScale(i)-a,l=Math.min(n+e.qualitySettings.tiledSurface.lodBias,this._splitLimits.maxLod||1/0);return l<=0?null:l}}return null}get lodSnapping(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences?de.ON:de.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(null==t||null==e)return null;const i=I(),r=re(t,i,e)?i:null,s=this._get("extent");return B(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get extent(){const e=V(this.groundExtent,this._userClippingExtent,I()),t=this._get("extent");return B(e,t)?t:e}get groundExtent(){return null!=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??1}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return null!=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}get wireframe(){return this._renderer?.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}get opaque(){return this._renderer.transparency===Ce.Opaque}set suspended(e){this._set("suspended",e),this._viewChangeUpdate()}get fadeDuration(){return this.view.qualitySettings.fadeDuration??0}intersect(e,t,i,r){this._renderer.intersect(e,t,i,r)}getElevation(e,t,i,r){const s=this._rootTiles;if(!s?.length)return null;if(0===s[0].layerInfo[ue.ELEVATION].length)return null;let a=this._elevationProjectorCache.get(r);if(void 0===a&&(a=U(r,this._spatialReference)??null,this._elevationProjectorCache.set(r,a)),null==a)return n.getLogger(this).error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;const l=P(yt,e,t,i);a(l,0,l,0);return Pt(s,l[0],l[1])}getElevations(e,t,i){const r=this._rootTiles,s=r?r[0].layerInfo[ue.ELEVATION].length:0;if(r?.length&&0!==s)for(let a=0;a<t;++a){const t=3*a;i(a,Pt(r,e[t],e[t+1]))}else for(let a=0;a<t;++a)i(a,null)}getScale(e){if(!this.tilingScheme)return null;if(!R(e,yt,this.spatialReference))return n.getLogger(this).error("TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system"),null;const t=this._rootTiles;if(null!=t)for(const i of t)if(i?.containsPoint(yt)){let e=i;for(;e.children[0]&&!e.rendered;){const t=e.children[0].extent;let i=0;yt[0]>t[2]&&(i+=1),yt[1]<t[1]&&(i+=2),e=e.children[i]}return this._getLodBiasCorrectedScale(e.level)}return 1/0}_ensureSEBProject(e){const t=this._sebProjectorMap.get(e);if(t)return t;const i=U(e,this._tilingSchemeSpatialReference,this._sebProjectorCache)??null;return this._sebProjectorMap.set(e,i),i}getSphereElevationBounds(e,t){const i=this._ensureSEBProject(t);if(null==i)return n.getLogger(this).error("TerrainSurface.getSphereElevationBounds(): could not project given point to tiling scheme coordinate system"),null;W(e,vt);const r=H(vt);i(r,0,r,0);const s=new te,a=this._rootTiles;if(null!=a){const e=[];for(const i of a)e.push(i);let t=0;for(;t<e.length;){const i=e[t];if(++t,!k(i.extent,vt))continue;const r=i.children;if(null==r[0]||i.rendered)s.expandElevationRangeValues(i.elevationBoundsMin,i.elevationBoundsMax);else for(const t of r)e.push(t)}}return s}getRootElevationBounds(){return new te(this.rootTileElevationBounds.min,this.rootTileElevationBounds.max)}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!R(e,H(vt),this.spatialReference))return n.getLogger(this).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;vt[3]=t;let i=null;const r=e=>{if(e&&k(e.extent,vt)){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(null!=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?Ce.Empty:Ce.TransparentWithDraped:e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?Ce.Opaque:Ce.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;je(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();const t=e?.spatialReference??M.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateCarree=this._isWebMercator&&F(this.view?.renderSpatialReference),this._isGeographic=t?.isGeographic??!1,this._set("tilingScheme",e),this._tilingSchemeSpatialReference=this.tilingScheme?.spatialReference,this._sebProjectorMap.clear(),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._tileCache.pop(mt._tileMemcacheKey);return s?(s.init(e,t,i,r,this),s):new this._tileConstructor(e,t,i,r,this)}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){const{extent:e,tilingScheme:t}=this;if(!t)return;const i=Et;let s=t.rootTilesInExtent(e,i,5*ve);if(null!=this._rootTiles){if(s.length>ve)return void n.getLogger(this).warn(Ee);const e=this._rootTiles.map((e=>e.lij)),t=r(e,s,Ye);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this._rootTiles.filter((e=>!(t.removed.findIndex((t=>Ye(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>ve&&(n.getLogger(this).warn(Se),s=t.rootTilesInExtent(e,i,ve)),this._setRootTiles(s.map((e=>this._newRootTile(e))));B(i,this._rootTilesExtent)||(this._rootTilesExtent=I(i)),this.renderer.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(tt);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)===Je.SPLIT}_newRootTile(e){const t=this._acquireTile(0,e[1],e[2],null);return this._shouldSplit(t)&&t.setPendingUpdate(Je.SPLIT),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationBounds(),t}_setRootTiles(e){if(this._rootTiles=e,this._allTiles.clear(),null!=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.renderer.visible&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this._rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.extent)&&e.resetPendingUpdate(Je.GEOMETRY)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(null==e)return;const t=it(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(Je.GEOMETRY)&&this._updateTileGeometryState(e),e.computeVisibility(),e.updateScreenDepth(n),e.renderData&&(r=Math.min(e.elevationBoundsMin,r),s=Math.max(e.elevationBoundsMax,s))}l.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._updatePendingTileGeometries(),isFinite(r)&&isFinite(s)&&(i.min!==r||i.max!==s)&&(this.visibleElevationBounds=new ne(r,s))}_updateRootTileElevationBounds(){let e=1/0,t=-1/0;const i=this._rootTiles;null!=i&&i.forEach((({elevationBoundsMin:i,elevationBoundsMax:r})=>{e=Math.min(e,i),t=Math.max(t,r)}));const r=this.rootTileElevationBounds;r.min===e&&r.max===t||(this.rootTileElevationBounds=new ne(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?this._splitLimits.frustum=q(this._splitLimits.frustum??G(),t.frustum):this._splitLimits.frustum=null,q(this._frustum,e.frustum),w(this._viewProjectionMatrix,t.projectionMatrix,t.viewMatrix),b(this._eyePosRenderSR,t.eye),A(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateTileGeometryState(e){e.updateVisibility();this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this._usedMemory=null}_markAllTileNeighborsForUpdate(e){e.forEachLoadedNeighbor((e=>{this._layerViews[ue.MAP].some(Me)&&e.setPendingUpdate(Je.TEXTURE_FADING),this._pendingTilesToUpdate.add(e)}))}_updateTileTexture(e,t){const i=e.resetPendingUpdate(Je.TEXTURE_FADING)?Je.TEXTURE_FADING:!!e.resetPendingUpdate(Je.TEXTURE_NOFADING)&&Je.TEXTURE_NOFADING;i&&(this._renderer.updateTileTexture(e,i),this._usedMemory=null,t.madeProgress())}_emitElevationUpdateEventForTiles(){if(!this._shouldEmitChangeEvent)return;const e=wt.extent;O(e),this._pendingTilesForElevationUpdateEvent.forEach((t=>N(e,t.extent,e))),this._pendingTilesForElevationUpdateEvent.clear(),wt.spatialReference=this.spatialReference,this.emit("elevation-change",wt),this._shouldEmitChangeEvent=!1}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;if(this._mergeAndSplit(e,t),this._updateElevation(e),this._updateTextures(e),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty(),this._updatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&e.hasProgressed&&this.requestUpdate(),this.notifyChange("updatingProgressValue"),Fe&&this._checkTileInvariant(),!e.hasProgressed)return _t}_checkTileInvariant(){const e=new Map;this._allTiles.forAll((t=>e.set(t,new Set))),this._allTiles.forAll((t=>{if(je(t.rendered===t.isLeaf,` rendered ${t.rendered} != ${t.isLeaf} leaf`),!t.isLeaf){const e=e=>0===e.unmergableChildCount&&0===e.maxLevelDeltaNeighborCount,i=t.children.reduce(((t,i)=>t+(e(i)?0:1)),0);if(je(t.unmergableChildCount===i,` Tile[${t.lij.toString()}] unmergeable child count mismatch: actual ${t.unmergableChildCount} vs ${i}`),t.hasPendingUpdate(Je.MERGE)){je(!t.hasPendingUpdate(Je.SPLIT),"Tile can be both split and merge at the same time");for(const e of t.children)je(e.isLeaf||e.hasPendingUpdate(Je.MERGE),"Child of tile to merge must also merge")}}for(let i=0;i<4;++i){if(t.rendered){const e=t.renderData?.geometryState.edgePeerNeighbors[i];if(null!=e){{const r=t.level-e.level<=we;r||(console.log(`tile level delta [${t.lij.toString()}] vs [${e.lij.toString()}] > ${we} (edge[${i}])`),je(r,`tile level delta [${t.level}] vs [${e.level}] > ${we}`))}je(t.level-e.level<=we,`Max tile lod delta exceeded: [${t.lij.toString()}] vs [${e.lij.toString()}]`)}}const r=t.level-we,s=e=>e.isLeaf||e.level===t.level,a=t.findNeighborTile(xe[i],s);if(null!=a){if(t.isLeaf&&t.level>=we){let i=a;for(;t.level-i.level<we;)i=i.parent;const s=[r,t.lij[1]>>we,t.lij[2]>>we];if(!Ye(s,i.lij)){const r=e.get(i);je(!r.has(t),"Cannot already have neighbor"),r.add(t)}}je(a.rendered||a.level===t.level,"Non-same-level-neighbor of rendered must be rendered"),je(t.level-a.level<=we,`Tile level delta [${t.level}] vs [${a.level}] > ${we}`)}}})),this._allTiles.forAll((t=>{const i=t.maxLevelDeltaNeighborCount,r=e.get(t);je(i===r.size,`Tile[${t.lij.toString()}] merge-blocker mismatch: actual ${i} vs ${r.size}`)}))}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;const t=new bt(this._allTiles.length);t.pushAll(this._rootTiles);const i=this.snapLevel,r=this._splitLimits,s=this._eyePosRenderSR;this._allTiles.forAll((e=>{e.maxLevelDeltaNeighborCount=0,e.unmergableChildCount=0}));const a=this._viewProjectionMatrix;for(;!t.empty;){const e=t.pop(),n=e.parent,l=null!=n&&n.hasPendingUpdate(Je.MERGE),o=l?Je.MERGE:e.shouldSplit(r,s,i),h=o===Je.SPLIT;e.isLeaf?Ct(e,h):t.pushAll(e.children),l?(e.resetPendingUpdate(Je.SPLIT),e.isLeaf||e.setPendingUpdate(Je.MERGE),this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(a)):h?(e.resetPendingUpdate(Je.MERGE),e.isLeaf&&e.setPendingUpdate(Je.SPLIT)):(e.resetPendingUpdate(Je.SPLIT)&&e.updateAgentSuspension(),o===Je.ELEVATION&&e.updateAgents(ue.ELEVATION),e.isLeaf||(e.setPendingUpdate(Je.MERGE),e.resetPendingUpdate(Je.SPLIT)))}this.requestUpdate(),(this._shortBatches||!this._oneBatchPerFrameTask)&&this._updatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||(rt(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger&&this._treeDebugger.update(),e.madeProgress())}_markTileToUpdate(e){Ue(e.isLoaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForUpdate(e))}_updatePendingTileGeometries(){const e=this._pendingTilesToUpdate,t=Array.from(e.keys()).filter((e=>e.isLoaded&&e.intersectsClippingArea));if(0===t.length)return void e.clear();const 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(tt);const r=t.length;for(let s=0;s<r;++s){const r=t[s];Ue(r.isLoaded),Ue(r.intersectsClippingArea);const a=r.renderData;a.updateNeighborData();const n=a.dirtyEdgeResolutions,l=a.geometryState,o=e=>{const t=We[e];i(r,l.cornerPeerNeighbors[e]?.findCorner(He(t),(e=>e.isLoaded)))};for(let t=0;t<4;++t)if(n&1<<t){const s=a.geometryState.edgePeerNeighbors[t];s&&s?.level>=r.level&&s.forAllSubtreeOnSide(Re(xe[t]),(t=>!(!t.isLoaded||!t.intersectsClippingArea)&&(Ue(e.has(t)||tt(r,t)<0),i(r,t),!0))),o((t+1)%4),o(t)}}e.clear(),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,Fe&&$e&&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.hasPendingUpdate(Je.MERGE)){if(!t||s.unmergableChildCount>0)return e.done;for(s.resetPendingUpdate(Je.MERGE);null!=n.parent&&0===n.parent.unmergableChildCount&&n.parent.resetPendingUpdate(Je.MERGE);)n=n.parent;this._mergeTile(n),a=!0,e.madeProgress()}else if(s.resetPendingUpdate(Je.SPLIT)){let t=!0;const i=s.level;if(i>=we){const e=e=>e.isLeaf||i-e.level<we;for(let r=0;r<4;++r){const a=s.findNeighborTile(xe[r],e);null!=a&&i-a.level===we&&(t=!1,Fe&&(Ue(a.isLeaf),Ue(a.hasPendingUpdate(Je.SPLIT))))}}t?(this._splitTile(s),e.madeProgress(),a=!0):s.setPendingUpdate(Je.SPLIT)}return e.done}));if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0,!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries()),n){if(!i){i=!0;continue}if(!a)break}else this._allTilesDirty=!0}s?e.madeProgress():this._allTilesDirty=!0,!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries(),this._sortTiles(e)}_updateElevation(e){e.done||(this._allTiles.some((t=>(t.resetPendingUpdate(Je.GEOMETRY)&&(this._updateTileGeometryState(t),this._shortBatches&&this._updatePendingTileGeometries(),e.madeProgress()),e.done))),!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries())}_updateTextures(e){e.done||this._allTiles.some((t=>(this._updateTileTexture(t,e),e.done)))}_updateClippingExtent(){this.spatialReference&&(this.updateTileOverlayParams(dt.UPDATE),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){const e=this.view.quality;return this.view.qualitySettings.tiledSurface.lodBias-(1-e)*Le}_getLodBiasCorrectedScale(e){const t=this.tilingScheme.levels,i=l(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(){null!=this._rootTiles&&(this._rootTiles.forEach((e=>this._purgeTile(e))),this._setRootTiles(null),this.notifyChange("ready")),this._allTiles.clear(),this.renderer.visible=!1}_purgeDescendantTiles(e){if(!e.children[0])return;const t=e.children.slice();e.unsetChildren();for(let i=0;i<4;++i)this._purgeTile(t[i])}_purgeTile(e){e.isLeaf?jt(e):this._purgeDescendantTiles(e),this._allTiles.removeUnordered(e),this._unloadTile(e),this._tileCache.put(mt._tileMemcacheKey,e)}_unloadTile(e){this._pendingTilesToUpdate.delete(e),this._pendingTilesForElevationUpdateEvent.delete(e),e.unload(this._renderer)}_splitTile(e){je(e.isLeaf,"Tile that is already split should not be split again!"),je(e.rendered,"Tile marked to split is not rendered"),jt(e);const t=e.level+1,i=2*e.lij[1],r=2*e.lij[2],s=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));this._allTiles.pushArray(s),e.updateAgentSuspension(),je(e.rendered,"parent should be rendered"),this._unloadTile(e),s.forEach((e=>this._loadTile(e))),s.forEach((e=>this._pendingTilesToUpdate.add(e))),this._markAllTileNeighborsForUpdate(e),this._emitTileScaleChange(e,e.level+1),this._allTilesDirty=!0,this._shortBatches&&this._updatePendingTileGeometries(),s.forEach((e=>Ct(e,e.hasPendingUpdate(Je.SPLIT)))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){Lt.spatialReference=this.spatialReference,Lt.extent=e.extent,Lt.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",Lt)}_createTile(e,t,i,r){je(!!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(Je.SPLIT),s}get _shortBatches(){return this.view.state.mode!==pt.IDLE}_mergeTile(e){je(!e.hasPendingUpdate(Je.SPLIT),"_mergeTile sanity check"),je(!e.isLeaf,"Cannot merge a leaf"),e.isLeaf||(this._purgeDescendantTiles(e),je(!e.renderData,"_mergeTile sanity check"),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),Ct(e,!1),this._allTilesDirty=!0,++this._performanceInfo.numMerged)}_loadTile(e){e.load(),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager&&this.overlayManager.hasOverlays&&this.overlayManager.setTileParameters(e)}_elevationDataArrived(e,t,i){const r=new le(e.lij,e.extent,i);e.dataArrived(t,ue.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=gt){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1;const i=new Set;let r=-1;for(let s=this.view.allLayerViews.length-1;s>=0;s--){const e=this.view.allLayerViews.items[s];if(i.add(e.uid),Ae(e)||Ie(e))if(this._basemapLayerViewHandles.has(e.uid)&&!Ie(e)){const i=this._layerClassFromLayerView(e),s=this._getLayerIdxByUID(i,e.uid);null!=s&&((s<r||null==r)&&(t=!0),r=s)}else this._registerTiledLayerView(e),e.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(Be(t)&&!Y(t.layer)&&0!==t.fullOpacity)return e=!1,e;return e}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if((Ve(e)||Ie(e))&<(ot[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return ke(e)?ue.ELEVATION:ue.MAP}_registerTiledLayerView(e){const t=[];if((Ve(e)||Ie(e))&&t.push(f((()=>e.layer.blendMode),(()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(pe.UNFADED)}))),!Ie(e)){const i=this._layerClassFromLayerView(e);t.push(f((()=>e.suspended),(()=>this._updateTiledLayers()))),t.push(f((()=>e.fullOpacity),(()=>this._updateTileTextures(pe.UNFADED)))),t.push(f((()=>"effectiveScaleRange"in e.layer?e.layer.effectiveScaleRange:null),(()=>this._restartAllAgents(i)))),t.push(e.on("data-changed",(()=>{const t=this._getLayerIdxByUID(i,e.uid);null!=t&&this._invalidateLayerData(t,i)})))}this._unregisterTiledLayerView(e.uid),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){const t=this._basemapLayerViewHandles.get(e);if(t){for(const e of 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||!Ae(e)||!e.fullExtent)return;const r=this._layerClassFromLayerView(e);if(r===ue.MAP){const t=e.displayLevelRange.maxLevel;t!==1/0&&(null===i||t>i)&&(i=t)}t[r].push(e)}));for(const r of ce){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===ue.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(ue.MAP),e===pe.IMMEDIATE?this.renderer.updateTileTexture(t,Je.TEXTURE_NOFADING):t.updateRenderData(ue.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=dt.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||Me(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,c(r),g(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===ue.ELEVATION?ke(i)?this._requestElevationTileData(e,i,r):Promise.reject():Be(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{if(_(i))return;const s=this._layerIndexByUid[ue.ELEVATION].get(t.uid);null!=s?(this._usedMemory=null,this.requestUpdate(),this._elevationDataArrived(e,s,r)):n.getLogger(this).warn("TerrainSurface: received data from unknown layer %d %s",ue.ELEVATION,e.lij.toString())},s=i=>{g(i)||(this._dataMissing(e,ue.ELEVATION,t,i),this.requestUpdate())};if(Oe(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],{noDataValue:Pe,signal:i.signal}).then((e=>{if(!_(i))return this._frameTask.schedule((()=>r(e)),i.signal,s);n.getLogger(this).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:Pe},i.signal))).then((e=>{e?r(new X(e)):s(new Error("LERC decoding failed"))}),s).finally((()=>{--this._asyncWorkItems}))}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{--this._asyncWorkItems,qe(s),_(i)||(this._dataMissing(e,ue.MAP,t,r),this.requestUpdate())},s=e=>t=>r(t,e),a=r=>this._frameTask.schedule((()=>{--this._asyncWorkItems,this.requestUpdate(),_(i)?qe(r):this._mapTileDataArrived(e,t,r)}),i.signal,s(r)).catch(s(r)),l=(e,t=null)=>this._frameTask.schedule((()=>r(e,t)));if(Me(t)){const r=t.schemaHelper.getLevelRowColumn(e.lij);return t.fetchTile(r[0],r[1],r[2],i).then(a,l)}if(Ne(t))return t.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then(a,l);if(Ge(t)&&Oe(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then((e=>{if(_(i))return n.getLogger(this).warnOnce("A call to fetchTile resolved even though the request was aborted. fetchTile should not resolve if options.signal.aborted is true."),void l(m());a(e)}),l);let o=t.getTileUrl(e.lij[0],e.lij[1],e.lij[2]);Q(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,l)}_mapTileDataArrived(e,t,i){const r=this._getLayerIdxByUID(ue.MAP,t.uid);null!=r?e.dataArrived(r,ue.MAP,i):(qe(i),n.getLogger(this).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);null!=s?e.dataMissing(s,t,r):n.getLogger(this).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}get usedMemory(){return this.tilingScheme?(null==this._usedMemory&&(this._usedMemory=this._recalculateUsedMemory()),this._usedMemory??0):0}_recalculateUsedMemory(){return this.tilingScheme?Math.round(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 null!=r&&this._allTiles.forAll((e=>t+=e.getUsedMemoryForLayer(i,r))),t}getTile(e){if(null==e||null==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=t[0],r=t[1]>>i,s=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 je(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:()=>{null!=e._rootTiles&&e._rootTiles.length>0&&(e._mergeTile(e._rootTiles[0]),e._viewChangeUpdate())},getTiles:()=>e._allTiles.toArray(),getRenderedTiles(){St.clear(),e._allTiles.forAll((e=>{e.visible&&e.rendered&&St.push(e)}));const t=St.toArray();return st(e.renderOrder,t),t},lockTilingScheme(t,i){e._extentHelper.defaultTiledLayersExtent=i,e.tilingSchemeLogic.test.lockTilingScheme(t)}}}checkAllTilesWaterproofness(){if(!$e)return;const e=this._rootTiles;if(null==e)return;const t=e=>e?.renderData?.geometry?.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.geometry&&console.error("Tile[",e.lij,"] has renderData but not geometryInfo"),!e.renderData?.geometry||(e.renderData.geometry.indices?.length??0)>0||console.error("Tile[",e.lij,"] has renderData but no indices - geometryInfo: ",e.renderData.geometry),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 isGeographic(){return this._isGeographic}get isWebMercator(){return this._isWebMercator}get isWebMercatorOnPlateCarree(){return this._isWebMercatorOnPlateCarree}isEastEndWrap(e){return this._isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this._isGlobal&&0===e[2]}lijEastEnd(e){return 1<<e+(this._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){Qe(e)}enableWaterproofnessChecks(e){ze(e)}};ft._tileMemcacheKey="TerrainTileMemcache",e([E()],ft.prototype,"_renderer",void 0),e([E({constructOnly:!0})],ft.prototype,"_scaleRangeQueries",void 0),e([E({constructOnly:!0})],ft.prototype,"view",void 0),e([E({constructOnly:!0})],ft.prototype,"overlayManager",void 0),e([E()],ft.prototype,"_hasPendingUpdates",void 0),e([E()],ft.prototype,"_asyncWorkItems",void 0),e([E()],ft.prototype,"_allTilesDirty",void 0),e([E()],ft.prototype,"_allTilesSorted",void 0),e([E()],ft.prototype,"_viewChanged",void 0),e([E()],ft.prototype,"_splitLimits",void 0),e([E({readOnly:!0})],ft.prototype,"_watchUpdatingTracking",void 0),e([E()],ft.prototype,"_frameTask",void 0),e([E({readOnly:!0})],ft.prototype,"snapLevel",null),e([E({readOnly:!0})],ft.prototype,"lodSnapping",null),e([E()],ft.prototype,"_userClippingExtent",null),e([E()],ft.prototype,"_rootTilesExtent",void 0),e([E({readOnly:!0})],ft.prototype,"extent",null),e([E({readOnly:!0})],ft.prototype,"groundExtent",null),e([E({readOnly:!0})],ft.prototype,"_tilingSchemeExtent",null),e([E({readOnly:!0})],ft.prototype,"updating",null),e([E({readOnly:!0})],ft.prototype,"running",null),e([E(ae)],ft.prototype,"updatingProgress",void 0),e([E({readOnly:!0})],ft.prototype,"updatingProgressValue",null),e([E()],ft.prototype,"_maxNumUpdating",void 0),e([E()],ft.prototype,"baseOpacity",null),e([E()],ft.prototype,"hasCompositeBlendMode",void 0),e([E({readOnly:!0})],ft.prototype,"viewingMode",null),e([E()],ft.prototype,"maxTextureScale",void 0),e([E({readOnly:!0})],ft.prototype,"ready",null),e([E({value:me.FRONT_TO_BACK})],ft.prototype,"renderOrder",null),e([E({readOnly:!0})],ft.prototype,"rootTiles",null),e([E()],ft.prototype,"_rootTiles",void 0),e([E({readOnly:!0})],ft.prototype,"spatialReference",null),e([E({type:t})],ft.prototype,"backgroundColor",null),e([E({value:!1})],ft.prototype,"slicePlaneEnabled",null),e([E({readOnly:!0})],ft.prototype,"tilingScheme",void 0),e([E({readOnly:!0})],ft.prototype,"tilingSchemeLocked",null),e([E({readOnly:!0})],ft.prototype,"tilingSchemeLogic",void 0),e([E()],ft.prototype,"wireframe",null),e([E({value:!1})],ft.prototype,"suspended",null),e([E()],ft.prototype,"fadeDuration",null),e([E()],ft.prototype,"visibleElevationBounds",void 0),e([E()],ft.prototype,"rootTileElevationBounds",void 0),e([E()],ft.prototype,"_layerViewsDirty",void 0),e([E()],ft.prototype,"renderPatchBorders",null),e([E()],ft.prototype,"visualizeNormals",null),e([E()],ft.prototype,"renderingDisabled",null),ft=mt=e([S("esri.views.3d.terrain.TerrainSurface")],ft);const Tt=ft,yt=C(),vt=$(),Et=I(),St=new u,wt=new ie("ground"),Lt={spatialReference:null,extent:null,scale:0};function Pt(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 oe(t,i,s)}return null}class bt{constructor(e){this.capacity=e,this._head=0,this._tail=0,this._data=new Array(e)}push(e){const t=this._tail;if(!(t<this.capacity))throw new Error("Queue full");this._data[t]=e,this._tail=t+1}pushAll(e){const t=e.length;if(0===t)return;const i=this._tail;if(!(i+t<=this.capacity))throw new Error("Queue full");for(let r=0;r<t;++r)this._data[i+r]=e[r];this._tail=i+t}pop(){const e=this._head;if(e<this._tail){const t=this._data[e];return this._head=e+1,t}}get empty(){return this._head>=this._tail}get full(){return this._tail>=this._data.length}}function Ct(e,t){!e.isLeaf||e.level<we||xt(e,(e=>{t&&Dt(e);const i=Mt(e);if(e.maxLevelDeltaNeighborCount++,i){let t=e.parent;for(;t;){const e=Mt(t);if(t.unmergableChildCount++,!e)break;t=t.parent}}}))}function Dt(e){if(e.hasPendingUpdate(Je.SPLIT))return;let t=e.parent;for(;t&&t.resetPendingUpdate(Je.MERGE);)t=t.parent;e.resetPendingUpdate(Je.MERGE),e.isLeaf&&e.setPendingUpdate(Je.SPLIT),e.level<we||xt(e,(e=>{Dt(e)}))}function jt(e){e.level<we||xt(e,(e=>{if(e.maxLevelDeltaNeighborCount--,0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount){let t=e.parent;for(;t&&(t.unmergableChildCount--,Mt(t));)t=t.parent}}))}function Mt(e){return 0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount}function xt(e,t){if(e.level<we)return;const i=e.level-we,r=e.lij[1]>>we,s=e.lij[2]>>we,a=e=>e.isLeaf||e.level===i;for(let n=0;n<4;++n){const l=e.findNeighborTile(xe[n],a);if(!l||l.level!==i)continue;const o=l.lij;o[1]===r&&o[2]===s||t(l)}}export{Tt as default};
|
|
5
|
+
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/Logger.js";import{clamp as l}from"../../../core/mathUtils.js";import{releaseMaybe as o,destroyMaybe as h}from"../../../core/maybe.js";import{MemCachePool as d}from"../../../core/MemCachePool.js";import p from"../../../core/ObjectPool.js";import u from"../../../core/PooledArray.js";import{throwIfAborted as c,isAbortError as g,isAborted as _,createAbortError as m}from"../../../core/promiseUtils.js";import{watch as f,syncAndInitial as T,sync as y,initial as v}from"../../../core/reactiveUtils.js";import{property as E}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import{subclass as S}from"../../../core/accessorSupport/decorators/subclass.js";import{multiply as w}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{create as L}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{s as P,c as b}from"../../../chunks/vec32.js";import{create as C}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as D}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as j}from"../../../geometry/ellipsoidUtils.js";import M from"../../../geometry/SpatialReference.js";import{createEmptyProjectorCache as x,getProjector as U}from"../../../geometry/projection/projectors.js";import{projectPointToVector as R}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as A}from"../../../geometry/projection/projectVectorToVector.js";import{create as I,equals as B,intersection as V,intersectsSphere as k,empty as O,expand as N}from"../../../geometry/support/aaBoundingRect.js";import{create as G,copy as q}from"../../../geometry/support/frustum.js";import{isPlateCarree as F}from"../../../geometry/support/spatialReferenceUtils.js";import{a as W,g as H,c as $}from"../../../chunks/sphere.js";import{isRefreshableLayer as Q}from"../../../layers/mixins/RefreshableLayer.js";import{ElevationQueryTileCache as z}from"../../../layers/support/ElevationQueryTileCache.js";import{ElevationTileData as X}from"../../../layers/support/ElevationTileData.js";import{isBaseLayer as Y}from"../../../layers/support/layerUtils.js";import{acquireDecoder as K}from"../../../layers/support/LercDecoder.js";import{printAllocations as J}from"../../2d/engine/vectorTiles/VectorTile.js";import{directionToHeadingTilt as Z}from"../support/cameraUtils.js";import{debugFlags as ee}from"../support/debugFlags.js";import{ElevationRange as te}from"../support/ElevationRange.js";import{ElevationUpdateEvent as ie}from"../support/ElevationUpdateEvent.js";import{toBoundingRect as re}from"../support/extentUtils.js";import{ClientType as se}from"../support/index.js";import{updatingProgress as ae}from"../support/updatingProperties.js";import{ElevationBounds as ne}from"./ElevationBounds.js";import{ElevationData as le,sampleElevation as oe}from"./ElevationData.js";import{create as he}from"./ExtentHelper.js";import{LODSnapping as de,TextureUpdate as pe}from"./interfaces.js";import{LayerClass as ue,LayerClasses as ce}from"./LayerClass.js";import{OverlayManager as ge}from"./OverlayManager.js";import{PlanarPatch as _e}from"./PlanarPatch.js";import{RenderOrder as me}from"./RenderOrder.js";import{ScaleRangeQueries as fe}from"./ScaleRangeQueries.js";import{SphericalPatch as Te}from"./SphericalPatch.js";import{SplitLimits as ye}from"./SplitLimits.js";import{maxRootTiles as ve,tooManyRootTilesAfterChangeError as Ee,tooManyRootTilesForLayerError as Se,maxTileNeighborLevelDelta as we,maxMemoryLodBias as Le,elevationNodataValue as Pe}from"./TerrainConst.js";import{TerrainRenderer as be,TransparencyMode as Ce}from"./TerrainRenderer.js";import De from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as je,isVectorTileLayerView as Me,neighborEdgeIndices as xe,internalAssert as Ue,oppositeEdge as Re,isSurfaceLayerView as Ae,isGroupLayerView as Ie,isMapTileLayerView as Be,isBlendableLayerView as Ve,isElevationLayerView as ke,useFetchTileForLayer as Oe,isImageryTileLayerView as Ne,isTileLayerView as Ge,releaseTileData as qe,enableTerrainInternalChecks as Fe,neighborCornerIndices as We,oppositeCorner as He,enableWaterproofnessTests as $e,enableInternalTerrainChecks as Qe,enableTerrainWaterproofnessChecks as ze}from"./terrainUtils.js";import{Tile as Xe,lijEquals as Ye}from"./Tile.js";import{printAllocations as Ke}from"./TilePerLayerInfo.js";import{TileUpdate as Je}from"./TileUpdate.js";import{IteratorPreorder as Ze,IteratorPostorder as et,compareTilesByLij as tt,hasLoadableSiblings as it,sortTilesByPOI as rt,sortTiles as st}from"./tileUtils.js";import{TilingSchemeLogic as at}from"./TilingSchemeLogic.js";import{UpsampleInfo as nt}from"./UpsampleInfo.js";import{isCompositeBlendMode as lt,blendModeFromString as ot}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{PBRMode as ht}from"../webgl-engine/core/shaderLibrary/shading/PhysicallyBasedRenderingParameters.glsl.js";import{RenderRequestType as dt}from"../webgl-engine/lib/basicInterfaces.js";import{RenderState as pt}from"../../support/RenderState.js";import{ImmediateTask as ut,TaskPriority as ct,noBudget as gt}from"../../support/Scheduler.js";import{Yield as _t}from"../../support/Yield.js";var mt;let ft=mt=class extends(a.EventedMixin(i)){constructor(e){super(e),this._scaleRangeQueries=new fe,this._iteratorPool=new p(Ze,(e=>e.remove=()=>this._iteratorPool.release(e))),this._postorderIterator=new et,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._usedMemory=null,this._performanceInfo=new De,this._viewChanged=!1,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=C(),this._eyePosSurfaceSR=C(),this._splitLimits=new ye,this._frustum=G(),this._viewProjectionMatrix=L(),this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._watchUpdatingTracking=new D,this._frameTask=ut,this._allTiles=new u,this._upsampleInfoPool=new p(nt),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=I(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=M.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationBounds=new ne(1/0,-1/0),this.rootTileElevationBounds=new ne(1/0,-1/0),this._sebProjectorMap=new Map,this._sebProjectorCache=x(),this._tilingSchemeSpatialReference=null,this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._oneBatchPerFrameTask=!0,this._layerViewsDirty=!1,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._isWebMercator=!1,this._isWebMercatorOnPlateCarree=!1,this.overlayManager=new ge({...e,surface:this}),this._isGlobal=!e.view?.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?Te:_e}initialize(){const e=this.view,t=e.resourceController;this._lercDecoder=K(t);const i=t.memoryController;this._tileCache=new d(((e,t)=>i.newCache(e,t)),"terrain-tile"),this._upsampleMapCache=i.newCache("terrain-upsample",(e=>e.unloadMapData())),this._elevationQueryCache=new z(i.newCache("elevation-query"));const r=this.overlayManager;this._renderer=new be(r.renderer,e._stage,this._allTiles,j(e.spatialReference).radius,i),this.addHandles([f((()=>r.renderer.isEmpty),(()=>this._evaluateTransparency())),f((()=>this.renderer.visible),(e=>this.suspended=!e))],"overlayManager"),this.addHandles([f((()=>this.baseOpacity),(()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?pe.UNFADED:pe.IMMEDIATE)}),T),f((()=>this.hasCompositeBlendMode),(()=>this._updateTileTextures(this._evaluateTransparency()?pe.UNFADED:pe.IMMEDIATE)),T),f((()=>this.backgroundColor),((e,t)=>{e?.equals(t)||(this._handleLayerViewChanges(),this._renderer.updateTileBackground(e))}),y),f((()=>this.snapLevel),(()=>this._viewChanged=!0),y),f((()=>this.view.pointsOfInterest),(e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add((()=>e.focus.renderLocation),(()=>this._allTilesSorted=!1))})),f((()=>ee.TERRAIN_TILE_TREE_SHOW_TILES),(t=>{t&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then((({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&ee.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))})):t||(this._treeDebugger=h(this._treeDebugger))}),v)]);const{spatialReference:a}=e;this._extentHelper=he(this.viewingMode,{layers:e.map.allLayers,layerViews:e.allLayerViews,viewSpatialReference:a});const n=new s({getCollections:()=>e.defaultsFromMap?.mapCollections?.map((({layers:e})=>e)),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}),l=new at({layers:n,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set("tilingSchemeLogic",l),this._updateTilingScheme(),this._elevationDataRequester=t.createStreamDataRequester(se.ELEVATION),this._mapDataRequester=t.createStreamDataRequester(se.BASEMAP);const o=t.scheduler;this._frameTask=o.registerTask(ct.TERRAIN_SURFACE,this),this.addHandles([f((()=>this._extentHelper.stencilEnabledExtents),(e=>this._renderer.setStencilEnabledLayerExtents(e)),v),f((()=>this.tilingSchemeLogic.tilingScheme),(()=>this._updateTilingScheme()),y),f((()=>this.extent),(()=>this._updateRootTiles()),v),e.on("resize",(()=>this._viewChangeUpdate())),f((()=>{const t=e.state;return[this._lodBias,this.lodSnapping,e.quality,t.camera,t.contentCamera,t.fixedContentCamera]}),(()=>this._viewChangeUpdate()),T),f((()=>e.qualitySettings?.fadeDuration),(e=>this._renderer.textureFadingEnabled=e>0),v),f((()=>e.qualitySettings?.physicallyBasedRenderingEnabled),(e=>this._renderer.pbrMode=e?ht.Simplified:ht.Disabled),v),f((()=>this._userClippingExtent),(()=>this._updateClippingExtent()),y)]),this.addHandles(e.allLayerViews.on("after-changes",(()=>this._layerViewsDirty=!0))),this._layerViewsDirty=!0,this._handleLayerViewChanges(),this._renderer.updateTileBackground(this.backgroundColor)}destroy(){this._frameTask.remove(),this._watchUpdatingTracking.destroy(),this._lercDecoder=o(this._lercDecoder),this._removeAllTiles(),this._set("tilingSchemeLogic",h(this.tilingSchemeLogic)),this._basemapLayerViewHandles.forEach(((e,t)=>this._unregisterTiledLayerView(t))),this._elevationDataRequester=null,this._mapDataRequester=null,this._set("overlayManager",h(this.overlayManager)),this._tileCache=h(this._tileCache),Xe.prune(),this._treeDebugger=h(this._treeDebugger),this._renderer=h(this._renderer),this._iteratorPool=h(this._iteratorPool),this._upsampleMapCache=h(this._upsampleMapCache),this._elevationQueryCache=h(this._elevationQueryCache),this._set("view",null),this._extentHelper=h(this._extentHelper),this._upsampleInfoPool=h(this._upsampleInfoPool),J(),Ke()}get renderer(){return this._renderer}get frustum(){return this._frustum}get snapLevel(){if(this.lodSnapping===de.ON){const e=this.view,t=this.tilingScheme,i=e.pointsOfInterest?.cameraOnSurface?.scale;if(t&&i){const r=e.state.contentCamera;let s=Z(e,r.eye,r.viewForward,r.up).tilt;s>90&&(s=180-s);const a=2*(s/90)**2,n=t.levelAtScale(i)-a,l=Math.min(n+e.qualitySettings.tiledSurface.lodBias,this._splitLimits.maxLod||1/0);return l<=0?null:l}}return null}get lodSnapping(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences?de.ON:de.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(null==t||null==e)return null;const i=I(),r=re(t,i,e)?i:null,s=this._get("extent");return B(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get extent(){const e=V(this.groundExtent,this._userClippingExtent,I()),t=this._get("extent");return B(e,t)?t:e}get groundExtent(){return null!=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??1}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return null!=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}get wireframe(){return this._renderer?.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}get opaque(){return this._renderer.transparency===Ce.Opaque}set suspended(e){this._set("suspended",e),this._viewChangeUpdate()}get fadeDuration(){return this.view.qualitySettings.fadeDuration??0}intersect(e,t,i,r){this._renderer.intersect(e,t,i,r)}getElevation(e,t,i,r){const s=this._rootTiles;if(!s?.length)return null;if(0===s[0].layerInfo[ue.ELEVATION].length)return null;let a=this._elevationProjectorCache.get(r);if(void 0===a&&(a=U(r,this._spatialReference)??null,this._elevationProjectorCache.set(r,a)),null==a)return n.getLogger(this).error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;const l=P(yt,e,t,i);a(l,0,l,0);return Pt(s,l[0],l[1])}getElevations(e,t,i){const r=this._rootTiles,s=r?r[0].layerInfo[ue.ELEVATION].length:0;if(r?.length&&0!==s)for(let a=0;a<t;++a){const t=3*a;i(a,Pt(r,e[t],e[t+1]))}else for(let a=0;a<t;++a)i(a,null)}getScale(e){if(!this.tilingScheme)return null;if(!R(e,yt,this.spatialReference))return n.getLogger(this).error("TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system"),null;const t=this._rootTiles;if(null!=t)for(const i of t)if(i?.containsPoint(yt)){let e=i;for(;e.children[0]&&!e.rendered;){const t=e.children[0].extent;let i=0;yt[0]>t[2]&&(i+=1),yt[1]<t[1]&&(i+=2),e=e.children[i]}return this._getLodBiasCorrectedScale(e.level)}return 1/0}_ensureSEBProject(e){const t=this._sebProjectorMap.get(e);if(t)return t;const i=U(e,this._tilingSchemeSpatialReference,this._sebProjectorCache)??null;return this._sebProjectorMap.set(e,i),i}getSphereElevationBounds(e,t){const i=this._ensureSEBProject(t);if(null==i)return n.getLogger(this).error("TerrainSurface.getSphereElevationBounds(): could not project given point to tiling scheme coordinate system"),null;W(e,vt);const r=H(vt);i(r,0,r,0);const s=new te,a=this._rootTiles;if(null!=a){const e=[];for(const i of a)e.push(i);let t=0;for(;t<e.length;){const i=e[t];if(++t,!k(i.extent,vt))continue;const r=i.children;if(null==r[0]||i.rendered)s.expandElevationRangeValues(i.elevationBoundsMin,i.elevationBoundsMax);else for(const t of r)e.push(t)}}return s}getRootElevationBounds(){return new te(this.rootTileElevationBounds.min,this.rootTileElevationBounds.max)}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!R(e,H(vt),this.spatialReference))return n.getLogger(this).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;vt[3]=t;let i=null;const r=e=>{if(e&&k(e.extent,vt)){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(null!=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?Ce.Empty:Ce.TransparentWithDraped:e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?Ce.Opaque:Ce.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;je(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();const t=e?.spatialReference??M.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateCarree=this._isWebMercator&&F(this.view?.renderSpatialReference),this._isGeographic=t?.isGeographic??!1,this._set("tilingScheme",e),this._tilingSchemeSpatialReference=this.tilingScheme?.spatialReference,this._sebProjectorMap.clear(),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._tileCache.pop(mt._tileMemcacheKey);return s?(s.init(e,t,i,r,this),s):new this._tileConstructor(e,t,i,r,this)}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){const{extent:e,tilingScheme:t}=this;if(!t)return;const i=Et;let s=t.rootTilesInExtent(e,i,5*ve);if(null!=this._rootTiles){if(s.length>ve)return void n.getLogger(this).warn(Ee);const e=this._rootTiles.map((e=>e.lij)),t=r(e,s,Ye);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this._rootTiles.filter((e=>!(t.removed.findIndex((t=>Ye(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>ve&&(n.getLogger(this).warn(Se),s=t.rootTilesInExtent(e,i,ve)),this._setRootTiles(s.map((e=>this._newRootTile(e))));B(i,this._rootTilesExtent)||(this._rootTilesExtent=I(i)),this.renderer.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(tt);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)===Je.SPLIT}_newRootTile(e){const t=this._acquireTile(0,e[1],e[2],null);return this._shouldSplit(t)&&t.setPendingUpdate(Je.SPLIT),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationBounds(),t}_setRootTiles(e){if(this._rootTiles=e,this._allTiles.clear(),null!=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.renderer.visible&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this._rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.extent)&&e.resetPendingUpdate(Je.GEOMETRY)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(null==e)return;const t=it(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(Je.GEOMETRY)&&this._updateTileGeometryState(e),e.computeVisibility(),e.updateScreenDepth(n),e.renderData&&(r=Math.min(e.elevationBoundsMin,r),s=Math.max(e.elevationBoundsMax,s))}l.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._updatePendingTileGeometries(),isFinite(r)&&isFinite(s)&&(i.min!==r||i.max!==s)&&(this.visibleElevationBounds=new ne(r,s))}_updateRootTileElevationBounds(){let e=1/0,t=-1/0;const i=this._rootTiles;null!=i&&i.forEach((({elevationBoundsMin:i,elevationBoundsMax:r})=>{e=Math.min(e,i),t=Math.max(t,r)}));const r=this.rootTileElevationBounds;r.min===e&&r.max===t||(this.rootTileElevationBounds=new ne(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?this._splitLimits.frustum=q(this._splitLimits.frustum??G(),t.frustum):this._splitLimits.frustum=null,q(this._frustum,e.frustum),w(this._viewProjectionMatrix,t.projectionMatrix,t.viewMatrix),b(this._eyePosRenderSR,t.eye),A(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateTileGeometryState(e){e.updateVisibility();this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this._usedMemory=null}_markAllTileNeighborsForUpdate(e){e.forEachLoadedNeighbor((e=>{this._layerViews[ue.MAP].some(Me)&&e.setPendingUpdate(Je.TEXTURE_FADING),this._pendingTilesToUpdate.add(e)}))}_updateTileTexture(e,t){const i=e.resetPendingUpdate(Je.TEXTURE_FADING)?Je.TEXTURE_FADING:!!e.resetPendingUpdate(Je.TEXTURE_NOFADING)&&Je.TEXTURE_NOFADING;i&&(this._renderer.updateTileTexture(e,i),this._usedMemory=null,t.madeProgress())}_emitElevationUpdateEventForTiles(){if(!this._shouldEmitChangeEvent)return;const e=wt.extent;O(e),this._pendingTilesForElevationUpdateEvent.forEach((t=>N(e,t.extent,e))),this._pendingTilesForElevationUpdateEvent.clear(),wt.spatialReference=this.spatialReference,this.emit("elevation-change",wt),this._shouldEmitChangeEvent=!1}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;if(this._mergeAndSplit(e,t),this._updateElevation(e),this._updateTextures(e),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty(),this._updatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&e.hasProgressed&&this.requestUpdate(),this.notifyChange("updatingProgressValue"),Fe&&this._checkTileInvariant(),!e.hasProgressed)return _t}_checkTileInvariant(){const e=new Map;this._allTiles.forAll((t=>e.set(t,new Set))),this._allTiles.forAll((t=>{if(je(t.rendered===t.isLeaf,` rendered ${t.rendered} != ${t.isLeaf} leaf`),!t.isLeaf){const e=e=>0===e.unmergableChildCount&&0===e.maxLevelDeltaNeighborCount,i=t.children.reduce(((t,i)=>t+(e(i)?0:1)),0);if(je(t.unmergableChildCount===i,` Tile[${t.lij.toString()}] unmergeable child count mismatch: actual ${t.unmergableChildCount} vs ${i}`),t.hasPendingUpdate(Je.MERGE)){je(!t.hasPendingUpdate(Je.SPLIT),"Tile can be both split and merge at the same time");for(const e of t.children)je(e.isLeaf||e.hasPendingUpdate(Je.MERGE),"Child of tile to merge must also merge")}}for(let i=0;i<4;++i){if(t.rendered){const e=t.renderData?.geometryState.edgePeerNeighbors[i];if(null!=e){{const r=t.level-e.level<=we;r||(console.log(`tile level delta [${t.lij.toString()}] vs [${e.lij.toString()}] > ${we} (edge[${i}])`),je(r,`tile level delta [${t.level}] vs [${e.level}] > ${we}`))}je(t.level-e.level<=we,`Max tile lod delta exceeded: [${t.lij.toString()}] vs [${e.lij.toString()}]`)}}const r=t.level-we,s=e=>e.isLeaf||e.level===t.level,a=t.findNeighborTile(xe[i],s);if(null!=a){if(t.isLeaf&&t.level>=we){let i=a;for(;t.level-i.level<we;)i=i.parent;const s=[r,t.lij[1]>>we,t.lij[2]>>we];if(!Ye(s,i.lij)){const r=e.get(i);je(!r.has(t),"Cannot already have neighbor"),r.add(t)}}je(a.rendered||a.level===t.level,"Non-same-level-neighbor of rendered must be rendered"),je(t.level-a.level<=we,`Tile level delta [${t.level}] vs [${a.level}] > ${we}`)}}})),this._allTiles.forAll((t=>{const i=t.maxLevelDeltaNeighborCount,r=e.get(t);je(i===r.size,`Tile[${t.lij.toString()}] merge-blocker mismatch: actual ${i} vs ${r.size}`)}))}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;const t=new bt(this._allTiles.length);t.pushAll(this._rootTiles);const i=this.snapLevel,r=this._splitLimits,s=this._eyePosRenderSR;this._allTiles.forAll((e=>{e.maxLevelDeltaNeighborCount=0,e.unmergableChildCount=0}));const a=this._viewProjectionMatrix;for(;!t.empty;){const e=t.pop(),n=e.parent,l=null!=n&&n.hasPendingUpdate(Je.MERGE),o=l?Je.MERGE:e.shouldSplit(r,s,i),h=o===Je.SPLIT;e.isLeaf?Ct(e,h):t.pushAll(e.children),l?(e.resetPendingUpdate(Je.SPLIT),e.isLeaf||e.setPendingUpdate(Je.MERGE),this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(a)):h?(e.resetPendingUpdate(Je.MERGE),e.isLeaf&&e.setPendingUpdate(Je.SPLIT)):(e.resetPendingUpdate(Je.SPLIT)&&e.updateAgentSuspension(),o===Je.ELEVATION&&e.updateAgents(ue.ELEVATION),e.isLeaf||(e.setPendingUpdate(Je.MERGE),e.resetPendingUpdate(Je.SPLIT)))}this.requestUpdate(),(this._shortBatches||!this._oneBatchPerFrameTask)&&this._updatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||(rt(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger&&this._treeDebugger.update(),e.madeProgress())}_markTileToUpdate(e){Ue(e.isLoaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForUpdate(e))}_updatePendingTileGeometries(){const e=this._pendingTilesToUpdate,t=Array.from(e.keys()).filter((e=>e.isLoaded&&e.intersectsClippingArea));if(0===t.length)return void e.clear();const 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(tt);const r=t.length;for(let s=0;s<r;++s){const r=t[s];Ue(r.isLoaded),Ue(r.intersectsClippingArea);const a=r.renderData;a.updateNeighborData();const n=a.dirtyEdgeResolutions,l=a.geometryState,o=e=>{const t=We[e];i(r,l.cornerPeerNeighbors[e]?.findCorner(He(t),(e=>e.isLoaded)))};for(let t=0;t<4;++t)if(n&1<<t){const s=a.geometryState.edgePeerNeighbors[t];s&&s?.level>=r.level&&s.forAllSubtreeOnSide(Re(xe[t]),(t=>!(!t.isLoaded||!t.intersectsClippingArea)&&(Ue(e.has(t)||tt(r,t)<0),i(r,t),!0))),o((t+1)%4),o(t)}}e.clear(),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,Fe&&$e&&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.hasPendingUpdate(Je.MERGE)){if(!t||s.unmergableChildCount>0)return e.done;for(s.resetPendingUpdate(Je.MERGE);null!=n.parent&&0===n.parent.unmergableChildCount&&n.parent.resetPendingUpdate(Je.MERGE);)n=n.parent;this._mergeTile(n),a=!0,e.madeProgress()}else if(s.resetPendingUpdate(Je.SPLIT)){let t=!0;const i=s.level;if(i>=we){const e=e=>e.isLeaf||i-e.level<we;for(let r=0;r<4;++r){const a=s.findNeighborTile(xe[r],e);null!=a&&i-a.level===we&&(t=!1,Fe&&(Ue(a.isLeaf),Ue(a.hasPendingUpdate(Je.SPLIT))))}}t?(this._splitTile(s),e.madeProgress(),a=!0):s.setPendingUpdate(Je.SPLIT)}return e.done}));if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0,!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries()),n){if(!i){i=!0;continue}if(!a)break}else this._allTilesDirty=!0}s?e.madeProgress():this._allTilesDirty=!0,!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries(),this._sortTiles(e)}_updateElevation(e){e.done||(this._allTiles.some((t=>(t.resetPendingUpdate(Je.GEOMETRY)&&(this._updateTileGeometryState(t),this._shortBatches&&this._updatePendingTileGeometries(),e.madeProgress()),e.done))),!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries())}_updateTextures(e){e.done||this._allTiles.some((t=>(this._updateTileTexture(t,e),e.done)))}_updateClippingExtent(){this.spatialReference&&(this.updateTileOverlayParams(dt.UPDATE),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){const e=this.view.quality;return this.view.qualitySettings.tiledSurface.lodBias-(1-e)*Le}_getLodBiasCorrectedScale(e){const t=this.tilingScheme.levels,i=l(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(){null!=this._rootTiles&&(this._rootTiles.forEach((e=>this._purgeTile(e))),this._setRootTiles(null),this.notifyChange("ready")),this._allTiles.clear(),this.renderer.visible=!1}_purgeDescendantTiles(e){if(!e.children[0])return;const t=e.children.slice();e.unsetChildren();for(let i=0;i<4;++i)this._purgeTile(t[i])}_purgeTile(e){e.isLeaf?jt(e):this._purgeDescendantTiles(e),this._allTiles.removeUnordered(e),this._unloadTile(e),this._tileCache.put(mt._tileMemcacheKey,e)}_unloadTile(e){this._pendingTilesToUpdate.delete(e),this._pendingTilesForElevationUpdateEvent.delete(e),e.unload(this._renderer)}_splitTile(e){je(e.isLeaf,"Tile that is already split should not be split again!"),je(e.rendered,"Tile marked to split is not rendered"),jt(e);const t=e.level+1,i=2*e.lij[1],r=2*e.lij[2],s=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));this._allTiles.pushArray(s),e.updateAgentSuspension(),je(e.rendered,"parent should be rendered"),this._unloadTile(e),s.forEach((e=>this._loadTile(e))),s.forEach((e=>this._pendingTilesToUpdate.add(e))),this._markAllTileNeighborsForUpdate(e),this._emitTileScaleChange(e,e.level+1),this._allTilesDirty=!0,this._shortBatches&&this._updatePendingTileGeometries(),s.forEach((e=>Ct(e,e.hasPendingUpdate(Je.SPLIT)))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){Lt.spatialReference=this.spatialReference,Lt.extent=e.extent,Lt.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",Lt)}_createTile(e,t,i,r){je(!!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(Je.SPLIT),s}get _shortBatches(){return this.view.state.mode!==pt.IDLE}_mergeTile(e){je(!e.hasPendingUpdate(Je.SPLIT),"_mergeTile sanity check"),je(!e.isLeaf,"Cannot merge a leaf"),e.isLeaf||(this._purgeDescendantTiles(e),je(!e.renderData,"_mergeTile sanity check"),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),Ct(e,!1),this._allTilesDirty=!0,++this._performanceInfo.numMerged)}_loadTile(e){e.load(),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager&&this.overlayManager.hasOverlays&&this.overlayManager.setTileParameters(e)}_elevationDataArrived(e,t,i){const r=new le(e.lij,e.extent,i);e.dataArrived(t,ue.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=gt){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1;const i=new Set;let r=-1;for(let s=this.view.allLayerViews.length-1;s>=0;s--){const e=this.view.allLayerViews.items[s];if(i.add(e.uid),Ae(e)||Ie(e))if(this._basemapLayerViewHandles.has(e.uid)&&!Ie(e)){const i=this._layerClassFromLayerView(e),s=this._getLayerIdxByUID(i,e.uid);null!=s&&((s<r||null==r)&&(t=!0),r=s)}else this._registerTiledLayerView(e),e.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(Be(t)&&!Y(t.layer)&&0!==t.fullOpacity)return e=!1,e;return e}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if((Ve(e)||Ie(e))&<(ot[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return ke(e)?ue.ELEVATION:ue.MAP}_registerTiledLayerView(e){const t=[];if((Ve(e)||Ie(e))&&t.push(f((()=>e.layer.blendMode),(()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(pe.UNFADED)}))),!Ie(e)){const i=this._layerClassFromLayerView(e);t.push(f((()=>e.suspended),(()=>this._updateTiledLayers()))),t.push(f((()=>e.fullOpacity),(()=>this._updateTileTextures(pe.UNFADED)))),t.push(f((()=>"effectiveScaleRange"in e.layer?e.layer.effectiveScaleRange:null),(()=>this._restartAllAgents(i)))),t.push(e.on("data-changed",(()=>{const t=this._getLayerIdxByUID(i,e.uid);null!=t&&this._invalidateLayerData(t,i)})))}this._unregisterTiledLayerView(e.uid),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){const t=this._basemapLayerViewHandles.get(e);if(t){for(const e of 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||!Ae(e)||!e.fullExtent)return;const r=this._layerClassFromLayerView(e);if(r===ue.MAP){const t=e.displayLevelRange.maxLevel;t!==1/0&&(null===i||t>i)&&(i=t)}t[r].push(e)}));for(const r of ce){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===ue.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(ue.MAP),e===pe.IMMEDIATE?this.renderer.updateTileTexture(t,Je.TEXTURE_NOFADING):t.updateRenderData(ue.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=dt.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||Me(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,c(r),g(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===ue.ELEVATION?ke(i)?this._requestElevationTileData(e,i,r):Promise.reject():Be(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{if(_(i))return;const s=this._layerIndexByUid[ue.ELEVATION].get(t.uid);null!=s?(this._usedMemory=null,this.requestUpdate(),this._elevationDataArrived(e,s,r)):n.getLogger(this).warn("TerrainSurface: received data from unknown layer %d %s",ue.ELEVATION,e.lij.toString())},s=i=>{g(i)||(this._dataMissing(e,ue.ELEVATION,t,i),this.requestUpdate())};if(Oe(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],{noDataValue:Pe,signal:i.signal}).then((e=>{if(!_(i))return this._frameTask.schedule((()=>r(e)),i.signal,s);n.getLogger(this).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:Pe},i.signal))).then((e=>{e?r(new X(e)):s(new Error("LERC decoding failed"))}),s).finally((()=>{--this._asyncWorkItems}))}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{--this._asyncWorkItems,qe(s),_(i)||(this._dataMissing(e,ue.MAP,t,r),this.requestUpdate())},s=e=>t=>r(t,e),a=r=>this._frameTask.schedule((()=>{--this._asyncWorkItems,this.requestUpdate(),_(i)?qe(r):this._mapTileDataArrived(e,t,r)}),i.signal,s(r)).catch(s(r)),l=(e,t=null)=>this._frameTask.schedule((()=>r(e,t)));if(Me(t)){const r=t.schemaHelper.getLevelRowColumn(e.lij);return t.fetchTile(r[0],r[1],r[2],i).then(a,l)}if(Ne(t))return t.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then(a,l);if(Ge(t)&&Oe(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then((e=>{if(_(i))return n.getLogger(this).warnOnce("A call to fetchTile resolved even though the request was aborted. fetchTile should not resolve if options.signal.aborted is true."),void l(m());a(e)}),l);let o=t.getTileUrl(e.lij[0],e.lij[1],e.lij[2]);Q(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,l)}_mapTileDataArrived(e,t,i){const r=this._getLayerIdxByUID(ue.MAP,t.uid);null!=r?e.dataArrived(r,ue.MAP,i):(qe(i),n.getLogger(this).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);null!=s?e.dataMissing(s,t,r):n.getLogger(this).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}get usedMemory(){return this.tilingScheme?(null==this._usedMemory&&(this._usedMemory=this._recalculateUsedMemory()),this._usedMemory??0):0}_recalculateUsedMemory(){return this.tilingScheme?Math.round(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 null!=r&&this._allTiles.forAll((e=>t+=e.getUsedMemoryForLayer(i,r))),t}getTile(e){if(null==e||null==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=t[0],r=t[1]>>i,s=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 je(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:()=>{null!=e._rootTiles&&e._rootTiles.length>0&&(e._mergeTile(e._rootTiles[0]),e._viewChangeUpdate())},getTiles:()=>e._allTiles.toArray(),getRenderedTiles(){St.clear(),e._allTiles.forAll((e=>{e.visible&&e.rendered&&St.push(e)}));const t=St.toArray();return st(e.renderOrder,t),t},lockTilingScheme(t,i){e._extentHelper.defaultTiledLayersExtent=i,e.tilingSchemeLogic.test.lockTilingScheme(t)}}}checkAllTilesWaterproofness(){if(!$e)return;const e=this._rootTiles;if(null==e)return;const t=e=>e?.renderData?.geometry?.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.geometry&&console.error("Tile[",e.lij,"] has renderData but not geometryInfo"),!e.renderData?.geometry||(e.renderData.geometry.indices?.length??0)>0||console.error("Tile[",e.lij,"] has renderData but no indices - geometryInfo: ",e.renderData.geometry),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 isGeographic(){return this._isGeographic}get isWebMercator(){return this._isWebMercator}get isWebMercatorOnPlateCarree(){return this._isWebMercatorOnPlateCarree}isEastEndWrap(e){return this._isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this._isGlobal&&0===e[2]}lijEastEnd(e){return 1<<e+(this._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){Qe(e)}enableWaterproofnessChecks(e){ze(e)}};ft._tileMemcacheKey="TerrainTileMemcache",e([E()],ft.prototype,"_renderer",void 0),e([E({constructOnly:!0})],ft.prototype,"_scaleRangeQueries",void 0),e([E({constructOnly:!0})],ft.prototype,"view",void 0),e([E({constructOnly:!0})],ft.prototype,"overlayManager",void 0),e([E()],ft.prototype,"_hasPendingUpdates",void 0),e([E()],ft.prototype,"_asyncWorkItems",void 0),e([E()],ft.prototype,"_allTilesDirty",void 0),e([E()],ft.prototype,"_allTilesSorted",void 0),e([E()],ft.prototype,"_viewChanged",void 0),e([E()],ft.prototype,"_splitLimits",void 0),e([E({readOnly:!0})],ft.prototype,"_watchUpdatingTracking",void 0),e([E()],ft.prototype,"_frameTask",void 0),e([E({readOnly:!0})],ft.prototype,"snapLevel",null),e([E({readOnly:!0})],ft.prototype,"lodSnapping",null),e([E()],ft.prototype,"_userClippingExtent",null),e([E()],ft.prototype,"_rootTilesExtent",void 0),e([E({readOnly:!0})],ft.prototype,"extent",null),e([E({readOnly:!0})],ft.prototype,"groundExtent",null),e([E({readOnly:!0})],ft.prototype,"_tilingSchemeExtent",null),e([E({readOnly:!0})],ft.prototype,"updating",null),e([E({readOnly:!0})],ft.prototype,"running",null),e([E(ae)],ft.prototype,"updatingProgress",void 0),e([E({readOnly:!0})],ft.prototype,"updatingProgressValue",null),e([E()],ft.prototype,"_maxNumUpdating",void 0),e([E()],ft.prototype,"baseOpacity",null),e([E()],ft.prototype,"hasCompositeBlendMode",void 0),e([E({readOnly:!0})],ft.prototype,"viewingMode",null),e([E()],ft.prototype,"maxTextureScale",void 0),e([E({readOnly:!0})],ft.prototype,"ready",null),e([E({value:me.FRONT_TO_BACK})],ft.prototype,"renderOrder",null),e([E({readOnly:!0})],ft.prototype,"rootTiles",null),e([E()],ft.prototype,"_rootTiles",void 0),e([E({readOnly:!0})],ft.prototype,"spatialReference",null),e([E({type:t})],ft.prototype,"backgroundColor",null),e([E({value:!1})],ft.prototype,"slicePlaneEnabled",null),e([E({readOnly:!0})],ft.prototype,"tilingScheme",void 0),e([E({readOnly:!0})],ft.prototype,"tilingSchemeLocked",null),e([E({readOnly:!0})],ft.prototype,"tilingSchemeLogic",void 0),e([E()],ft.prototype,"wireframe",null),e([E({value:!1})],ft.prototype,"suspended",null),e([E()],ft.prototype,"fadeDuration",null),e([E()],ft.prototype,"visibleElevationBounds",void 0),e([E()],ft.prototype,"rootTileElevationBounds",void 0),e([E()],ft.prototype,"_layerViewsDirty",void 0),e([E()],ft.prototype,"renderPatchBorders",null),e([E()],ft.prototype,"visualizeNormals",null),e([E()],ft.prototype,"renderingDisabled",null),ft=mt=e([S("esri.views.3d.terrain.TerrainSurface")],ft);const Tt=ft,yt=C(),vt=$(),Et=I(),St=new u,wt=new ie("ground"),Lt={spatialReference:null,extent:null,scale:0};function Pt(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 oe(t,i,s)}return null}class bt{constructor(e){this.capacity=e,this._head=0,this._tail=0,this._data=new Array(e)}push(e){const t=this._tail;if(!(t<this.capacity))throw new Error("Queue full");this._data[t]=e,this._tail=t+1}pushAll(e){const t=e.length;if(0===t)return;const i=this._tail;if(!(i+t<=this.capacity))throw new Error("Queue full");for(let r=0;r<t;++r)this._data[i+r]=e[r];this._tail=i+t}pop(){const e=this._head;if(e<this._tail){const t=this._data[e];return this._head=e+1,t}}get empty(){return this._head>=this._tail}get full(){return this._tail>=this._data.length}}function Ct(e,t){!e.isLeaf||e.level<we||xt(e,(e=>{t&&Dt(e);const i=Mt(e);if(e.maxLevelDeltaNeighborCount++,i){let t=e.parent;for(;t;){const e=Mt(t);if(t.unmergableChildCount++,!e)break;t=t.parent}}}))}function Dt(e){if(e.hasPendingUpdate(Je.SPLIT))return;let t=e.parent;for(;t&&t.resetPendingUpdate(Je.MERGE);)t=t.parent;e.resetPendingUpdate(Je.MERGE),e.isLeaf&&e.setPendingUpdate(Je.SPLIT),e.level<we||xt(e,(e=>{Dt(e)}))}function jt(e){e.level<we||xt(e,(e=>{if(e.maxLevelDeltaNeighborCount--,0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount){let t=e.parent;for(;t&&(t.unmergableChildCount--,Mt(t));)t=t.parent}}))}function Mt(e){return 0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount}function xt(e,t){if(e.level<we)return;const i=e.level-we,r=e.lij[1]>>we,s=e.lij[2]>>we,a=e=>e.isLeaf||e.level===i;for(let n=0;n<4;++n){const l=e.findNeighborTile(xe[n],a);if(!l||l.level!==i)continue;const o=l.lij;o[1]===r&&o[2]===s||t(l)}}export{Tt as default};
|
package/views/3d/terrain/Tile.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.29/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{clamp as e}from"../../../core/mathUtils.js";import{abortMaybe as t}from"../../../core/maybe.js";import i from"../../../core/ObjectPool.js";import{f as s,p as n,k as r,h as a,g as o,l,c as h}from"../../../chunks/vec32.js";import{create as u,unitZ as d}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getEpsilon as c}from"../../../core/libs/gl-matrix-2/math/common.js";import{getReferenceEllipsoid as g}from"../../../geometry/ellipsoidUtils.js";import{create as p,equals as f}from"../../../geometry/support/aaBoundingRect.js";import{d as _,g as m}from"../../../chunks/sphere.js";import{isGroupLayer as y}from"../../../layers/support/layerUtils.js";import{VectorTile as A}from"../../2d/engine/vectorTiles/VectorTile.js";import{ImageWithType as M}from"../support/StreamDataLoader.js";import{ElevationBounds as T}from"./ElevationBounds.js";import{ElevationTileAgent as v}from"./ElevationTileAgent.js";import{TextureUpdate as E}from"./interfaces.js";import{TileFrustumVisibility as I,NeighborIndex as D}from"./ITile.js";import{LayerClasses as L,LayerClass as x}from"./LayerClass.js";import{MapTileAgent as S}from"./MapTileAgent.js";import{RasterTile as O}from"./RasterTile.js";import{maxPatchTesselation as N,getElevationDesiredResolutionLevel as b}from"./TerrainConst.js";import{weakAssert as j,getLayerWithExtentRange as U,isBlendableLayerView as C,oppositeCorner as B,internalAssert as P,enableTerrainInternalChecks as R,neighborEdgeIndices as V,oppositeEdge as w,neighborCornerIndices as G,isNorth as W,isSouth as q,isWest as F,isEast as H,enableWaterproofnessTests as k,almostEquals as X,isWestCorner as Y,isNorthCorner as z}from"./terrainUtils.js";import{tileAgentDone as $}from"./TileAgent.js";import{TilePerLayerInfo as J}from"./TilePerLayerInfo.js";import Q from"./TileTexture.js";import{TileUpdate as K}from"./TileUpdate.js";import{fallsWithinLayer as Z}from"./tileUtils.js";const ee=.1;class te{constructor(){this._lij=[0,0,0],this._children=[null,null,null,null],this._pendingUpdates=0,this.renderData=null,this._dirty=!0,this._previouslyRendered=!1,this.extent=p(),this._elevationBoundsMin=NaN,this._elevationBoundsMax=0,this.layerInfo=[[],[]],this.extentInRadians=p(),this.centerAtSeaLevel=u(),this._center=[u(),_(),u()],this.up=d(),this._isWithinClippingArea=!0,this._intersectsClippingArea=!0,this._maxTesselation=0,this._usedMemory=null,this._mapTileMemoryInternal=0,this._mapDataRefCount=0,this.screenDepth=0,this.renderOrder=0,this._edgeLen=0,this._edgeLen2=0,this._curvatureHeight=0,this.extentMidX=0,this.extentMidY=0,this.distanceToPOI=-1,this._lastPOI=u(),this.maxLevelDeltaNeighborCount=0,this.unmergableChildCount=0}get lij(){return this._lij}static prune(){ne.prune(0),re.prune(0),J.prune()}get _isCached(){return!this.isLeaf&&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 elevationBoundsMin(){return this._elevationBoundsMin}get elevationBoundsMax(){return this._elevationBoundsMax}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[oe.MIDDLE][3]}get visible(){return this._dirty&&this.computeVisibility(),this._visible}get frustumVisibility(){return this._dirty&&this.computeVisibility(),this._frustumVisibility}computeVisibility(){this._dirty=!1;const e=this.parent,t=e?.frustumVisibility??I.INTERSECTS;this._frustumVisibility=t===I.INSIDE?I.INSIDE:t===I.OUTSIDE?I.OUTSIDE:this._calculateFrustumVisibilityStatus(this.surface.frustum);const i=this._frustumVisibility!==I.OUTSIDE&&this._intersectsClippingArea;i!==this._visible&&(this._visible=i,this._surface.emit("tiles-visibility-changed"),this._surface.renderer.setDirty(),this.updateAgentSuspension())}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.setDirty()),e}init(e,t,i,s,n){this._lij[0]=e,this._lij[1]=t,this._lij[2]=i,this.ellipsoid=g(n.tilingScheme.spatialReference),n.tilingScheme.getExtent(e,t,i,this.extent),n.tilingScheme.convertExtentToRadians(this.extent,this.extentInRadians),this.extentMidX=.5*(this.extent[0]+this.extent[2]),this.extentMidY=.5*(this.extent[1]+this.extent[3]),this._isWithinClippingArea=!0,this._intersectsClippingArea=!0,this._clippingArea=null,this._mapDataRefCount=0,n.upsampleMapCache.pop(this.key),this._edgeLen=0,this._edgeLen2=0,this._center[oe.MIDDLE][3]=0,this.elevationLevel=e,s&&!Number.isNaN(s.elevationBoundsMin)?(this._elevationBoundsMin=s.elevationBoundsMin,this._elevationBoundsMax=s.elevationBoundsMax):(this._elevationBoundsMin=0,this._elevationBoundsMax=0),this._pendingUpdates=0,this.renderData=null,this.screenDepth=0,this._visible=!1,this._previouslyRendered=!1,this._parent=s,this.unsetChildren(),this._surface=n,this.updateVisibility(),this.maxLevelDeltaNeighborCount=0,this.unmergableChildCount=0;for(const r of L){const e=n.numLayers(r),t=this.layerInfo[r];for(const i of t)i.release();t.length=e;for(let i=0;i<e;i++)t[i]=J.acquire(this._surface.upsampleInfoPool),r===x.ELEVATION&&this.findElevationBoundsForLayer(i,-1)}this.computeElevationBounds(),this._maxTesselation=Math.min(n.tilingScheme.pixelSize,N)}dispose(){j(!this.renderData,"tile.renderData was not unloaded"),this._surface.upsampleMapCache.pop(this.key);for(const e of L){for(const t of this.layerInfo[e])t.release();this.layerInfo[e].length=0}this._parent=null;for(let e=0;e<4;++e)this._children[e]=null;this._surface=null,this.setMemoryDirty()}refMapData(){++this._mapDataRefCount,this._isCached||this._surface.upsampleMapCache.pop(this.key)}unrefMapData(){if(--this._mapDataRefCount,this._isCached){this.setMemoryDirty();const e=this._cachedMemory;e>0&&this._surface.upsampleMapCache.put(this.key,this,e)}}setMemoryDirty(){this._usedMemory=null}get usedMemory(){return this._ensureUsedMemory()+(this._isCached?0:this._mapTileMemoryInternal)}get _cachedMemory(){return this._isCached?this._mapTileMemory:0}get _mapTileMemory(){return this._ensureUsedMemory(),this.layerInfo[x.MAP].reduce(((e,t)=>e+(t instanceof A?t.usedMemory/t.referenced:0)),this._mapTileMemoryInternal)}get _cpuImageMemorySize(){const e=4,t=this._surface.tilingScheme.pixelSize;return t*t*e}_ensureUsedMemory(){if(null!=this._usedMemory)return this._usedMemory;this._usedMemory=this._baseUsedMemory,this._mapTileMemoryInternal=0;let e=0;for(const{data:i}of this.layerInfo[x.MAP])i instanceof A?e+=this._getTerrainDataMemory(i):this._mapTileMemoryInternal+=this._getTerrainDataMemory(i);const t=this._cpuImageMemorySize;for(const i of this.layerInfo[x.ELEVATION])this._usedMemory+=i.data?t:0;return this.renderData&&(this._usedMemory+=this.renderData.estimatedGeometryMemoryUsage,this._mapTileMemoryInternal+=this.renderData.texture?.usedMemory??0),this._isCached&&this._surface.upsampleMapCache.updateSize(this.key,this,this._mapTileMemoryInternal+e),this._usedMemory}getUsedMemoryForLayer(e,t){const i=this.layerInfo[e][t];return i?.data?e===x.MAP?this._isCached?0:this._getTerrainDataMemory(i.data):e===x.ELEVATION?this._cpuImageMemorySize:0:0}_getTerrainDataMemory(e){return e instanceof Q?e.texture.usedMemory:e instanceof HTMLImageElement||e instanceof M?this._cpuImageMemorySize:e instanceof O?e.memoryUsage:e instanceof A?e.usedMemory/e.referenced:0}updateScreenDepth(e){const t=this._center[oe.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,t,i){if(!this.visible)return K.NONE;if(e.frustum&&(!this._intersectsClippingArea||this._calculateFrustumVisibilityStatus(e.frustum)===I.OUTSIDE))return K.NONE;const h=this.level;s(pe,m(this._center[oe.MIDDLE]),t);let u=n(pe),d=pe,c=m(this._center[oe.MIDDLE]);s(fe,this._center[oe.TOP],t);const g=n(fe);g<u&&(u=g,d=fe,c=this._center[oe.TOP]),s(_e,this._center[oe.BOTTOM],t);const p=n(_e);if(p<u&&(u=p,d=_e,c=this._center[oe.BOTTOM]),this._edgeLen2>u&&h<e.maxLod)return K.SPLIT;const f=Math.sqrt(u),_=e.fovX*f*2,y=this._edgeLen/_,A=()=>{if(h<e.maxLod)return this.elevationLevel=h,K.NONE;const t=h+Math.ceil(-Math.log2(e.relativeWidthLimit/y));return t!==this.elevationLevel?(this.elevationLevel=t,K.ELEVATION):K.NONE},M=null!=i?i-h:1/0;if(M<=.5)return A();const T=r(this.up,pe),v=this._elevationBoundsMax-this._elevationBoundsMin,E=v/this.edgeLen;if(e.aboveGround&&T>0&&E<.001){if(T/f-Math.sin(this._curvatureHeight/(this.edgeLen*Math.SQRT1_2)*Math.PI)-E>0)return K.NONE}const D=null!=i?3-Math.min(M,2):1;if(y*D<e.relativeWidthLimit||h>=e.maxLod)return A();if(h<7)return K.SPLIT;a(me,this.up,T),s(me,me,d);const L=n(me);if(L<=this.radius*this.radius)return K.SPLIT;a(me,me,this.radius/Math.sqrt(L)),o(me,me,c),s(me,t,me);const x=Math.min(1,(Math.abs(r(me,this.up))+.5*v+this._curvatureHeight)/l(me)),S=ee/e.angledSplitBias,O=e.fovY*f*2;return x*(this._edgeLen/O*D)<S*e.relativeHeightLimit?K.NONE:K.SPLIT}setChildren(e,t,i,s){j(!!(e&&t&&i&&s),"Null child passed");const n=this._children;return n[0]=e,n[1]=t,n[2]=i,n[3]=s,n}unsetChildren(){this._children[0]=null,this._children[1]=null,this._children[2]=null,this._children[3]=null}get isLoaded(){return this.renderData?.hasGeometry??!1}load(){this.refMapData();for(const e of L)this._createOrUpdateAgents(0,e);this.surface.renderer.loadTile(this)}unload(e){e.unloadTile(this);for(const t of L){const e=this.layerInfo[t];for(const t of e)t.loadingAgent&&t.loadingAgent!==$&&(se(t.loadingAgent),t.loadingAgent=null),t.pendingUpdates=0}this.resetPendingUpdate(K.GEOMETRY),this.resetPendingUpdate(K.TEXTURE_NOFADING),this.resetPendingUpdate(K.TEXTURE_FADING),this.unrefMapData()}unloadMapData(){const e=this.layerInfo[x.MAP];for(const t of e)t.loadingAgent&&t.loadingAgent!==$&&(se(t.loadingAgent),t.loadingAgent=null),t.pendingUpdates=0;this.renderData&&this.renderData.releaseTexture(),this.setMemoryDirty()}updateClippingStatus(e){if(f(e,this._clippingArea))return!1;const t=this._intersectsClippingArea,i=this._isWithinClippingArea;null!=e?(this._intersectsClippingArea=this.intersectsExtent(e),this._isWithinClippingArea=this._isWithinExtent(e)):(this._intersectsClippingArea=!0,this._isWithinClippingArea=!0),this._clippingArea=e,this.updateVisibility();const s=i&&this._isWithinClippingArea,n=!(i||t||this._isWithinClippingArea||this._intersectsClippingArea);return!this.renderData||s||n||this.setPendingUpdate(K.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?.data||i.dataInvalidated)}get updating(){if(this.hasPendingUpdates)return!0;for(const e of L){const t=this.layerInfo[e];for(const e of t)if(e.loadingAgent&&e.loadingAgent!==$&&e.loadingAgent.updating)return!0}return!1}_isSuspended(e){return!!this.hasPendingUpdate(K.SPLIT)||e!==x.ELEVATION&&!this.loadable}get hasPendingUpdates(){return 0!==this._pendingUpdates}hasPendingUpdate(e){return(this._pendingUpdates&e)===e}setPendingUpdate(e){const t=this._pendingUpdates;return this._pendingUpdates|=e,e===K.SPLIT||e===K.MERGE?this._surface.setTileTreeDirty():this._surface.requestUpdate(),t!==this._pendingUpdates}resetPendingUpdate(e){return!!this.hasPendingUpdate(e)&&(this._pendingUpdates&=~e,!0)}requestLayerData(e,i,s){const n=this.layerInfo[i][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(),i,e),!0;if(n.waitingAgents.push(s),n.data&&!n.dataInvalidated){console.warn("agent requested existing data (tile %s, agent tile %s, layer: %d/%d)",this._lij.toString(),s.tile.lij.toString(),i,e);const t=n.data&&"type"in n.data&&"vector-tile"===n.data.type;return s.dataArrived(this,t),!0}if(n.requestPromise)return!0;t(n.requestAbort),n.requestAbort=new AbortController;const r=this._surface.requestTileData(this,e,i,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;const t=this._children;if(!t[0])return null;return t[0].findByLij(e)||t[1].findByLij(e)||t[2].findByLij(e)||t[3].findByLij(e)}distanceToSquared(e){return n(s(me,m(this._center[oe.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]}containsPointXY(e,t){const i=this.extent;return e>=i[0]&&t>=i[1]&&e<=i[2]&&t<=i[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.setMemoryDirty())}dataArrived(e,t,i){const s=null!=i&&"type"in i&&"vector-tile"===i.type,n=this.layerInfo[t][e];n.data=i,n.dataInvalidated=!1,n.waitingAgents.forAll((e=>e.dataArrived(this,s))),n.waitingAgents.clear(),this.setMemoryDirty()}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.setMemoryDirty()}updateRenderData(e,t,i){switch(i&&this.forEachLoadedNeighbor((i=>i.updateRenderData(e,t))),e){case x.MAP:return this._updateTexture(t);case x.ELEVATION:return this._updateGeometry()}}_updateTexture(e){this.renderData&&(this.resetPendingUpdate(e===E.FADING?K.TEXTURE_NOFADING:K.TEXTURE_FADING),this.setPendingUpdate(e===E.FADING?K.TEXTURE_FADING:K.TEXTURE_NOFADING))}_updateGeometry(){this.setPendingUpdate(K.GEOMETRY);for(const e of this.layerInfo[x.ELEVATION])e.pendingUpdates|=K.GEOMETRY}invalidateLayerData(e,t){this.layerInfo[t][e].invalidateSourceData(),this.restartAgents(t)}computeElevationBounds(){const e=this._elevationBoundsMin,t=this._elevationBoundsMax;let i=1/0,s=-1/0;const n=this.layerInfo[x.ELEVATION];let r=!0;for(const a of n)null!=a.elevationBounds&&(i=Math.min(i,a.elevationBounds.min),s=Math.max(s,a.elevationBounds.max),a.elevationBounds.hasNoDataValues||(r=!1));r&&(i=Math.min(i,0),s=Math.max(s,0)),e===i&&t===s||(this._elevationBoundsMin=i,this._elevationBoundsMax=s,this.updateRadiusAndCenter(),this._surface.setTileTreeDirty())}_updateCenter(){const e=this._elevationBoundsMin,t=this._elevationBoundsMax,i=.5*(e+t),s=this._center;a(me,this.up,i),o(m(s[oe.MIDDLE]),this.centerAtSeaLevel,me),a(me,this.up,e),o(s[oe.TOP],this.centerAtSeaLevel,me),a(me,this.up,t),o(s[oe.BOTTOM],this.centerAtSeaLevel,me)}findElevationBoundsForLayer(e,t){const i=this.layerInfo[x.ELEVATION][e],s=b(this.level),n=Math.max(this.elevationLevel-s,0),r=i.elevationBounds;if(null!=r&&r.level>=t&&r.level<=n)return;const a=this._surface.layerViewByIndex(e,x.ELEVATION),o=U(a);if(!Z(this,o,!1))return;const l=ae;let h=!1;const u=i.data;if(u&&u.level<=n){const e=i.data;l.min=e.samplerData.data.minValue,l.max=e.samplerData.data.maxValue,l.hasNoDataValues=e.samplerData.data.hasNoDataValues,l.level=this.level,h=!0}else{let t,i,r=0;for(let a=this._parent;a&&(!i||r<s)&&(r=this.elevationLevel-a.level,t=i||t,i=a.layerInfo[x.ELEVATION][e].data,!(!i&&t&&a.level<=n));a=a.parent);i=i||t,i&&(i.computeMinMaxValue(this._lij[0],this._lij[1],this._lij[2],l),l.min!==1/0&&(l.level=i.level,h=!0))}h&&(null==i.elevationBounds&&(i.elevationBounds=new T),i.elevationBounds.copyFrom(l))}modifyLayers(e,t,i){const s=this.layerInfo[i];for(const a of s)a.loadingAgent&&a.loadingAgent!==$&&(se(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]:J.acquire(this._surface.upsampleInfoPool)}this.setMemoryDirty()}restartAgents(e){this.renderData&&(this._createOrUpdateAgents(0,e),this.updateRenderData(e,E.FADING))}updateAgents(e){if(this.renderData){const t=this.layerInfo[e];for(const e of t)e.loadingAgent===$&&(e.loadingAgent=null);this._createOrUpdateAgents(0,e)}}updateAgentSuspension(){for(const e of L){const t=this._isSuspended(e);for(const i of this.layerInfo[e])i.loadingAgent&&i.loadingAgent!==$&&(i.loadingAgent.setSuspension(t),i.loadingAgent===$&&this.updateRenderData(e,E.FADING))}}removeLayerAgent(e,t){const i=this.layerInfo[t][e];i.loadingAgent&&i.loadingAgent!==$&&i.loadingAgent.dispose(),i.loadingAgent=null}agentDone(e,t){const i=this.layerInfo[t][e];i.loadingAgent=$,i.data||null!=i.upsampleInfo||this._createOrUpdateAgents(e+1,t)}_hasBlendableAncestor(e){return"normal"!==e.blendMode||y(e.parent)&&this._hasBlendableAncestor(e.parent)}_hasBlendModes(e,t,i){for(let s=e;s<t;++s){const e=this._surface.layerViewByIndex(s,i);if(C(e)&&"normal"!==e?.layer?.blendMode||y(e?.layer?.parent)&&this._hasBlendableAncestor(e?.layer?.parent))return!0}return!1}_createOrUpdateAgents(e,t){const i=this.layerInfo[t];if(0===i.length)return;const s=this._isSuspended(t);for(let n=e;n<i.length;++n){const r=i[n];let a=!1;const o=this._surface.layerViewByIndex(n,t),l=U(o);if(r.loadingAgent?Z(this,l,!1)?(r.loadingAgent!==$&&r.loadingAgent.setSuspension(s),r.loadingAgent!==$&&(a=r.loadingAgent.update())):r.dispose():Z(this,l,!1)&&(r.loadingAgent=ie(this,n,t,s),a=r.loadingAgent.startLoading(),a?r.loadingAgent===$&&this.setPendingUpdate(K.GEOMETRY):(se(r.loadingAgent),r.loadingAgent=$)),r.loadingAgent===$&&this.updateRenderData(t,E.FADING),!this._hasBlendModes(e,i.length,t)&&a&&o.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]}getElevationVerticesPerSide(t){const i=this.elevationLevel-this.level,s=Math.max(this.level-t,b(this.level)-i),n=e(1+(this.maxTesselation>>s),2,this.maxTesselation+1),r=this.getDefaultVerticesPerSide();return Math.max(n,r)}get test(){return{cachedMemory:this._cachedMemory}}_findLIJ(e,t){if(!e)return null;const i=this.surface.rootTiles;if(null!=i)for(const s of i)if(le(s,e)){let i=s,n=e[0]-i.level-1;for(;n>=0&&!i.isLeaf&&!t(i);){const t=e[1]>>n&1,s=e[2]>>n&1;i=i.children[2*t+s],n--}return t(i)?i:null}return null}findNeighborTile(e,t){const i=this._lij,s=this.getNeighborLIJ(i,e);return s?he(i,s)?t(this)?this:null:this._findLIJ(s,t):null}findCorner(e,t){const i=e===D.NORTH_EAST?1:e===D.NORTH_WEST?0:e===D.SOUTH_WEST?2:3;let s=this;for(;s.children[0]&&(!t||!t(s));)s=s.children[i];return s}findNeighborCornerTileExact(e,t){return this.findNeighborTile(e,(e=>t(e)||e.level===this.level))?.findCorner(B(e),t)||null}forAllSubtreeOnSide(e,t){const i=e===D.NORTH?[0,1]:e===D.NORTH_EAST?[1]:e===D.EAST?[1,3]:e===D.SOUTH_EAST?[3]:e===D.SOUTH?[2,3]:e===D.SOUTH_WEST?[2]:e===D.WEST?[0,2]:[0],s=e=>{const n=e.children;!t(e)&&n[0]&&i.forEach((e=>s(n[e])))};s(this)}getNeighborEdgeStartVertexIndex(e,t){if(!t)return 0;const i=this.level-t.level;if(P(!R||i>=0),0===i)return 0;const s=2**i,n=1==(1&e),r=n?0:1,a=t.lij[r+1]*s,o=this._lij[r+1],l=o-a,h=n?s-1-l:l;return R&&(P(a<=o&&o<a+s),P(0<=h&&h<s)),h}forEachLoadedNeighbor(e){const t=this.level,i=e=>e.level===t||e.isLoaded;V.forEach((t=>{const s=this.findNeighborTile(t,i);null!=s&&s!==this&&s.forAllSubtreeOnSide(w(t),(i=>!!i.isLoaded&&(e(i,t),!0)))})),G.forEach((t=>{const s=this.findNeighborTile(t,i)?.findCorner(B(t),(e=>e.isLoaded));P(!s||de(this,s,t)),s?.isLoaded&&e(s,t)}))}getNeighborLIJ(e,t){const i=W(t)?-1:q(t)?1:0,s=F(t)?-1:H(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(){const e=this.surface.extent,t=e?.[1]??null;return null!=t&&this.extent[1]+c()>=t}checkGeometryWaterproofness(){k&&(P(this.isLoaded),this.renderData?.checkGeometryWaterproofness())}shouldHaveNeighbor(e){const t=this.extent,i=this.surface.rootTilesExtent,s=.25*(t[2]-t[0]);if(W(e)&&t[3]+s>=i[3])return!1;if(q(e)&&t[1]-s<=i[1])return!1;const n=this.surface.isGlobal;return!(!n&&F(e)&&t[0]-s<=i[0])&&!(!n&&H(e)&&t[2]+s>=i[2])}updateDistanceToPOI(e){const t=this._lastPOI;if(this.distanceToPOI>=0&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return;h(this._lastPOI,e);const i=this._center[oe.MIDDLE],s=e[0]-i[0],n=e[1]-i[1],r=e[2]-i[2];this.distanceToPOI=s*s+n*n+r*r}}function ie(e,t,i,s){const n=i===x.ELEVATION?re.acquire():ne.acquire();return n.init(e,t,i,s),n}function se(e){e.dispose(),e instanceof v?re.release(e):e instanceof S&&ne.release(e)}const ne=new i(S),re=new i(v),ae=new T;var oe;function le(e,t){const i=e.lij,s=t[0]-i[0];return!(s<0)&&(t[1]>>s===i[1]&&t[2]>>s===i[2])}function he(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function ue(e,t,i){if(null==e||null==t)return!1;if(0===e.level&&0===t.level){if(e.isEastEnd&&t.isWestEnd&&i===D.EAST)return!0;if(e.isWestEnd&&t.isEastEnd&&i===D.WEST)return!0}const s=Math.max(1e-6*(e.extent[2]-e.extent[0]),1);switch(i){case D.NORTH:return X(e.extent[3],t.extent[1],s);case D.SOUTH:return X(e.extent[1],t.extent[3],s);case D.EAST:return X(e.extent[2],t.extent[0],s)||X(e.extent[2],-t.extent[0],s);case D.WEST:return X(e.extent[0],t.extent[2],s)||X(e.extent[0],-t.extent[2],s)}}function de(e,t,i){return null!=e&&null!=t&&t!==e&&(e.level>=t.level?ce(e,t,i):ce(t,e,B(i)))}function ce(e,t,i){P(e.level>=t.level);const s=Y(i),n=z(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]),u=X(o[0],l[0],h)||e.surface.isGlobal&&X(o[0],-l[0],h),d=X(o[1],l[1],h);if(u&&d)return!0;if(e.level===t.level)return P(!1),!1;if(!u&&!d)return P(!1),!1;const c=u?ge(a[1],a[3],r[1],r[3],h):ge(a[0],a[2],r[0],r[2],h);return P(c),c}function ge(e,t,i,s,n){return e-n<=i&&i<=s&&s<=t+n}!function(e){e[e.TOP=0]="TOP",e[e.MIDDLE=1]="MIDDLE",e[e.BOTTOM=2]="BOTTOM"}(oe||(oe={}));const pe=u(),fe=u(),_e=u(),me=u();export{oe as CenterPosition,te as Tile,de as isCornerNeighbor,ue as isEdgeNeighbor,he as lijEquals};
|
|
5
|
+
import{clamp as e}from"../../../core/mathUtils.js";import{abortMaybe as t}from"../../../core/maybe.js";import i from"../../../core/ObjectPool.js";import{f as s,p as n,k as r,h as a,g as o,l,c as h}from"../../../chunks/vec32.js";import{create as u,unitZ as d}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getEpsilon as c}from"../../../core/libs/gl-matrix-2/math/common.js";import{getReferenceEllipsoid as g}from"../../../geometry/ellipsoidUtils.js";import{create as p,equals as f}from"../../../geometry/support/aaBoundingRect.js";import{c as _,g as m}from"../../../chunks/sphere.js";import{isGroupLayer as y}from"../../../layers/support/layerUtils.js";import{VectorTile as A}from"../../2d/engine/vectorTiles/VectorTile.js";import{ImageWithType as M}from"../support/StreamDataLoader.js";import{ElevationBounds as T}from"./ElevationBounds.js";import{ElevationTileAgent as v}from"./ElevationTileAgent.js";import{TextureUpdate as E}from"./interfaces.js";import{TileFrustumVisibility as I,NeighborIndex as D}from"./ITile.js";import{LayerClasses as L,LayerClass as x}from"./LayerClass.js";import{MapTileAgent as S}from"./MapTileAgent.js";import{RasterTile as O}from"./RasterTile.js";import{maxPatchTesselation as N,getElevationDesiredResolutionLevel as b}from"./TerrainConst.js";import{weakAssert as j,getLayerWithExtentRange as U,isBlendableLayerView as C,oppositeCorner as B,internalAssert as P,enableTerrainInternalChecks as R,neighborEdgeIndices as V,oppositeEdge as w,neighborCornerIndices as G,isNorth as W,isSouth as q,isWest as F,isEast as H,enableWaterproofnessTests as k,almostEquals as X,isWestCorner as Y,isNorthCorner as z}from"./terrainUtils.js";import{tileAgentDone as $}from"./TileAgent.js";import{TilePerLayerInfo as J}from"./TilePerLayerInfo.js";import Q from"./TileTexture.js";import{TileUpdate as K}from"./TileUpdate.js";import{fallsWithinLayer as Z}from"./tileUtils.js";const ee=.1;class te{constructor(){this._lij=[0,0,0],this._children=[null,null,null,null],this._pendingUpdates=0,this.renderData=null,this._dirty=!0,this._previouslyRendered=!1,this.extent=p(),this._elevationBoundsMin=NaN,this._elevationBoundsMax=0,this.layerInfo=[[],[]],this.extentInRadians=p(),this.centerAtSeaLevel=u(),this._center=[u(),_(),u()],this.up=d(),this._isWithinClippingArea=!0,this._intersectsClippingArea=!0,this._maxTesselation=0,this._usedMemory=null,this._mapTileMemoryInternal=0,this._mapDataRefCount=0,this.screenDepth=0,this.renderOrder=0,this._edgeLen=0,this._edgeLen2=0,this._curvatureHeight=0,this.extentMidX=0,this.extentMidY=0,this.distanceToPOI=-1,this._lastPOI=u(),this.maxLevelDeltaNeighborCount=0,this.unmergableChildCount=0}get lij(){return this._lij}static prune(){ne.prune(0),re.prune(0),J.prune()}get _isCached(){return!this.isLeaf&&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 elevationBoundsMin(){return this._elevationBoundsMin}get elevationBoundsMax(){return this._elevationBoundsMax}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[oe.MIDDLE][3]}get visible(){return this._dirty&&this.computeVisibility(),this._visible}get frustumVisibility(){return this._dirty&&this.computeVisibility(),this._frustumVisibility}computeVisibility(){this._dirty=!1;const e=this.parent,t=e?.frustumVisibility??I.INTERSECTS;this._frustumVisibility=t===I.INSIDE?I.INSIDE:t===I.OUTSIDE?I.OUTSIDE:this._calculateFrustumVisibilityStatus(this.surface.frustum);const i=this._frustumVisibility!==I.OUTSIDE&&this._intersectsClippingArea;i!==this._visible&&(this._visible=i,this._surface.emit("tiles-visibility-changed"),this._surface.renderer.setDirty(),this.updateAgentSuspension())}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.setDirty()),e}init(e,t,i,s,n){this._lij[0]=e,this._lij[1]=t,this._lij[2]=i,this.ellipsoid=g(n.tilingScheme.spatialReference),n.tilingScheme.getExtent(e,t,i,this.extent),n.tilingScheme.convertExtentToRadians(this.extent,this.extentInRadians),this.extentMidX=.5*(this.extent[0]+this.extent[2]),this.extentMidY=.5*(this.extent[1]+this.extent[3]),this._isWithinClippingArea=!0,this._intersectsClippingArea=!0,this._clippingArea=null,this._mapDataRefCount=0,n.upsampleMapCache.pop(this.key),this._edgeLen=0,this._edgeLen2=0,this._center[oe.MIDDLE][3]=0,this.elevationLevel=e,s&&!Number.isNaN(s.elevationBoundsMin)?(this._elevationBoundsMin=s.elevationBoundsMin,this._elevationBoundsMax=s.elevationBoundsMax):(this._elevationBoundsMin=0,this._elevationBoundsMax=0),this._pendingUpdates=0,this.renderData=null,this.screenDepth=0,this._visible=!1,this._previouslyRendered=!1,this._parent=s,this.unsetChildren(),this._surface=n,this.updateVisibility(),this.maxLevelDeltaNeighborCount=0,this.unmergableChildCount=0;for(const r of L){const e=n.numLayers(r),t=this.layerInfo[r];for(const i of t)i.release();t.length=e;for(let i=0;i<e;i++)t[i]=J.acquire(this._surface.upsampleInfoPool),r===x.ELEVATION&&this.findElevationBoundsForLayer(i,-1)}this.computeElevationBounds(),this._maxTesselation=Math.min(n.tilingScheme.pixelSize,N)}dispose(){j(!this.renderData,"tile.renderData was not unloaded"),this._surface.upsampleMapCache.pop(this.key);for(const e of L){for(const t of this.layerInfo[e])t.release();this.layerInfo[e].length=0}this._parent=null;for(let e=0;e<4;++e)this._children[e]=null;this._surface=null,this.setMemoryDirty()}refMapData(){++this._mapDataRefCount,this._isCached||this._surface.upsampleMapCache.pop(this.key)}unrefMapData(){if(--this._mapDataRefCount,this._isCached){this.setMemoryDirty();const e=this._cachedMemory;e>0&&this._surface.upsampleMapCache.put(this.key,this,e)}}setMemoryDirty(){this._usedMemory=null}get usedMemory(){return this._ensureUsedMemory()+(this._isCached?0:this._mapTileMemoryInternal)}get _cachedMemory(){return this._isCached?this._mapTileMemory:0}get _mapTileMemory(){return this._ensureUsedMemory(),this.layerInfo[x.MAP].reduce(((e,t)=>e+(t instanceof A?t.usedMemory/t.referenced:0)),this._mapTileMemoryInternal)}get _cpuImageMemorySize(){const e=4,t=this._surface.tilingScheme.pixelSize;return t*t*e}_ensureUsedMemory(){if(null!=this._usedMemory)return this._usedMemory;this._usedMemory=this._baseUsedMemory,this._mapTileMemoryInternal=0;let e=0;for(const{data:i}of this.layerInfo[x.MAP])i instanceof A?e+=this._getTerrainDataMemory(i):this._mapTileMemoryInternal+=this._getTerrainDataMemory(i);const t=this._cpuImageMemorySize;for(const i of this.layerInfo[x.ELEVATION])this._usedMemory+=i.data?t:0;return this.renderData&&(this._usedMemory+=this.renderData.estimatedGeometryMemoryUsage,this._mapTileMemoryInternal+=this.renderData.texture?.usedMemory??0),this._isCached&&this._surface.upsampleMapCache.updateSize(this.key,this,this._mapTileMemoryInternal+e),this._usedMemory}getUsedMemoryForLayer(e,t){const i=this.layerInfo[e][t];return i?.data?e===x.MAP?this._isCached?0:this._getTerrainDataMemory(i.data):e===x.ELEVATION?this._cpuImageMemorySize:0:0}_getTerrainDataMemory(e){return e instanceof Q?e.texture.usedMemory:e instanceof HTMLImageElement||e instanceof M?this._cpuImageMemorySize:e instanceof O?e.memoryUsage:e instanceof A?e.usedMemory/e.referenced:0}updateScreenDepth(e){const t=this._center[oe.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,t,i){if(!this.visible)return K.NONE;if(e.frustum&&(!this._intersectsClippingArea||this._calculateFrustumVisibilityStatus(e.frustum)===I.OUTSIDE))return K.NONE;const h=this.level;s(pe,m(this._center[oe.MIDDLE]),t);let u=n(pe),d=pe,c=m(this._center[oe.MIDDLE]);s(fe,this._center[oe.TOP],t);const g=n(fe);g<u&&(u=g,d=fe,c=this._center[oe.TOP]),s(_e,this._center[oe.BOTTOM],t);const p=n(_e);if(p<u&&(u=p,d=_e,c=this._center[oe.BOTTOM]),this._edgeLen2>u&&h<e.maxLod)return K.SPLIT;const f=Math.sqrt(u),_=e.fovX*f*2,y=this._edgeLen/_,A=()=>{if(h<e.maxLod)return this.elevationLevel=h,K.NONE;const t=h+Math.ceil(-Math.log2(e.relativeWidthLimit/y));return t!==this.elevationLevel?(this.elevationLevel=t,K.ELEVATION):K.NONE},M=null!=i?i-h:1/0;if(M<=.5)return A();const T=r(this.up,pe),v=this._elevationBoundsMax-this._elevationBoundsMin,E=v/this.edgeLen;if(e.aboveGround&&T>0&&E<.001){if(T/f-Math.sin(this._curvatureHeight/(this.edgeLen*Math.SQRT1_2)*Math.PI)-E>0)return K.NONE}const D=null!=i?3-Math.min(M,2):1;if(y*D<e.relativeWidthLimit||h>=e.maxLod)return A();if(h<7)return K.SPLIT;a(me,this.up,T),s(me,me,d);const L=n(me);if(L<=this.radius*this.radius)return K.SPLIT;a(me,me,this.radius/Math.sqrt(L)),o(me,me,c),s(me,t,me);const x=Math.min(1,(Math.abs(r(me,this.up))+.5*v+this._curvatureHeight)/l(me)),S=ee/e.angledSplitBias,O=e.fovY*f*2;return x*(this._edgeLen/O*D)<S*e.relativeHeightLimit?K.NONE:K.SPLIT}setChildren(e,t,i,s){j(!!(e&&t&&i&&s),"Null child passed");const n=this._children;return n[0]=e,n[1]=t,n[2]=i,n[3]=s,n}unsetChildren(){this._children[0]=null,this._children[1]=null,this._children[2]=null,this._children[3]=null}get isLoaded(){return this.renderData?.hasGeometry??!1}load(){this.refMapData();for(const e of L)this._createOrUpdateAgents(0,e);this.surface.renderer.loadTile(this)}unload(e){e.unloadTile(this);for(const t of L){const e=this.layerInfo[t];for(const t of e)t.loadingAgent&&t.loadingAgent!==$&&(se(t.loadingAgent),t.loadingAgent=null),t.pendingUpdates=0}this.resetPendingUpdate(K.GEOMETRY),this.resetPendingUpdate(K.TEXTURE_NOFADING),this.resetPendingUpdate(K.TEXTURE_FADING),this.unrefMapData()}unloadMapData(){const e=this.layerInfo[x.MAP];for(const t of e)t.loadingAgent&&t.loadingAgent!==$&&(se(t.loadingAgent),t.loadingAgent=null),t.pendingUpdates=0;this.renderData&&this.renderData.releaseTexture(),this.setMemoryDirty()}updateClippingStatus(e){if(f(e,this._clippingArea))return!1;const t=this._intersectsClippingArea,i=this._isWithinClippingArea;null!=e?(this._intersectsClippingArea=this.intersectsExtent(e),this._isWithinClippingArea=this._isWithinExtent(e)):(this._intersectsClippingArea=!0,this._isWithinClippingArea=!0),this._clippingArea=e,this.updateVisibility();const s=i&&this._isWithinClippingArea,n=!(i||t||this._isWithinClippingArea||this._intersectsClippingArea);return!this.renderData||s||n||this.setPendingUpdate(K.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?.data||i.dataInvalidated)}get updating(){if(this.hasPendingUpdates)return!0;for(const e of L){const t=this.layerInfo[e];for(const e of t)if(e.loadingAgent&&e.loadingAgent!==$&&e.loadingAgent.updating)return!0}return!1}_isSuspended(e){return!!this.hasPendingUpdate(K.SPLIT)||e!==x.ELEVATION&&!this.loadable}get hasPendingUpdates(){return 0!==this._pendingUpdates}hasPendingUpdate(e){return(this._pendingUpdates&e)===e}setPendingUpdate(e){const t=this._pendingUpdates;return this._pendingUpdates|=e,e===K.SPLIT||e===K.MERGE?this._surface.setTileTreeDirty():this._surface.requestUpdate(),t!==this._pendingUpdates}resetPendingUpdate(e){return!!this.hasPendingUpdate(e)&&(this._pendingUpdates&=~e,!0)}requestLayerData(e,i,s){const n=this.layerInfo[i][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(),i,e),!0;if(n.waitingAgents.push(s),n.data&&!n.dataInvalidated){console.warn("agent requested existing data (tile %s, agent tile %s, layer: %d/%d)",this._lij.toString(),s.tile.lij.toString(),i,e);const t=n.data&&"type"in n.data&&"vector-tile"===n.data.type;return s.dataArrived(this,t),!0}if(n.requestPromise)return!0;t(n.requestAbort),n.requestAbort=new AbortController;const r=this._surface.requestTileData(this,e,i,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;const t=this._children;if(!t[0])return null;return t[0].findByLij(e)||t[1].findByLij(e)||t[2].findByLij(e)||t[3].findByLij(e)}distanceToSquared(e){return n(s(me,m(this._center[oe.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]}containsPointXY(e,t){const i=this.extent;return e>=i[0]&&t>=i[1]&&e<=i[2]&&t<=i[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.setMemoryDirty())}dataArrived(e,t,i){const s=null!=i&&"type"in i&&"vector-tile"===i.type,n=this.layerInfo[t][e];n.data=i,n.dataInvalidated=!1,n.waitingAgents.forAll((e=>e.dataArrived(this,s))),n.waitingAgents.clear(),this.setMemoryDirty()}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.setMemoryDirty()}updateRenderData(e,t,i){switch(i&&this.forEachLoadedNeighbor((i=>i.updateRenderData(e,t))),e){case x.MAP:return this._updateTexture(t);case x.ELEVATION:return this._updateGeometry()}}_updateTexture(e){this.renderData&&(this.resetPendingUpdate(e===E.FADING?K.TEXTURE_NOFADING:K.TEXTURE_FADING),this.setPendingUpdate(e===E.FADING?K.TEXTURE_FADING:K.TEXTURE_NOFADING))}_updateGeometry(){this.setPendingUpdate(K.GEOMETRY);for(const e of this.layerInfo[x.ELEVATION])e.pendingUpdates|=K.GEOMETRY}invalidateLayerData(e,t){this.layerInfo[t][e].invalidateSourceData(),this.restartAgents(t)}computeElevationBounds(){const e=this._elevationBoundsMin,t=this._elevationBoundsMax;let i=1/0,s=-1/0;const n=this.layerInfo[x.ELEVATION];let r=!0;for(const a of n)null!=a.elevationBounds&&(i=Math.min(i,a.elevationBounds.min),s=Math.max(s,a.elevationBounds.max),a.elevationBounds.hasNoDataValues||(r=!1));r&&(i=Math.min(i,0),s=Math.max(s,0)),e===i&&t===s||(this._elevationBoundsMin=i,this._elevationBoundsMax=s,this.updateRadiusAndCenter(),this._surface.setTileTreeDirty())}_updateCenter(){const e=this._elevationBoundsMin,t=this._elevationBoundsMax,i=.5*(e+t),s=this._center;a(me,this.up,i),o(m(s[oe.MIDDLE]),this.centerAtSeaLevel,me),a(me,this.up,e),o(s[oe.TOP],this.centerAtSeaLevel,me),a(me,this.up,t),o(s[oe.BOTTOM],this.centerAtSeaLevel,me)}findElevationBoundsForLayer(e,t){const i=this.layerInfo[x.ELEVATION][e],s=b(this.level),n=Math.max(this.elevationLevel-s,0),r=i.elevationBounds;if(null!=r&&r.level>=t&&r.level<=n)return;const a=this._surface.layerViewByIndex(e,x.ELEVATION),o=U(a);if(!Z(this,o,!1))return;const l=ae;let h=!1;const u=i.data;if(u&&u.level<=n){const e=i.data;l.min=e.samplerData.data.minValue,l.max=e.samplerData.data.maxValue,l.hasNoDataValues=e.samplerData.data.hasNoDataValues,l.level=this.level,h=!0}else{let t,i,r=0;for(let a=this._parent;a&&(!i||r<s)&&(r=this.elevationLevel-a.level,t=i||t,i=a.layerInfo[x.ELEVATION][e].data,!(!i&&t&&a.level<=n));a=a.parent);i=i||t,i&&(i.computeMinMaxValue(this._lij[0],this._lij[1],this._lij[2],l),l.min!==1/0&&(l.level=i.level,h=!0))}h&&(null==i.elevationBounds&&(i.elevationBounds=new T),i.elevationBounds.copyFrom(l))}modifyLayers(e,t,i){const s=this.layerInfo[i];for(const a of s)a.loadingAgent&&a.loadingAgent!==$&&(se(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]:J.acquire(this._surface.upsampleInfoPool)}this.setMemoryDirty()}restartAgents(e){this.renderData&&(this._createOrUpdateAgents(0,e),this.updateRenderData(e,E.FADING))}updateAgents(e){if(this.renderData){const t=this.layerInfo[e];for(const e of t)e.loadingAgent===$&&(e.loadingAgent=null);this._createOrUpdateAgents(0,e)}}updateAgentSuspension(){for(const e of L){const t=this._isSuspended(e);for(const i of this.layerInfo[e])i.loadingAgent&&i.loadingAgent!==$&&(i.loadingAgent.setSuspension(t),i.loadingAgent===$&&this.updateRenderData(e,E.FADING))}}removeLayerAgent(e,t){const i=this.layerInfo[t][e];i.loadingAgent&&i.loadingAgent!==$&&i.loadingAgent.dispose(),i.loadingAgent=null}agentDone(e,t){const i=this.layerInfo[t][e];i.loadingAgent=$,i.data||null!=i.upsampleInfo||this._createOrUpdateAgents(e+1,t)}_hasBlendableAncestor(e){return"normal"!==e.blendMode||y(e.parent)&&this._hasBlendableAncestor(e.parent)}_hasBlendModes(e,t,i){for(let s=e;s<t;++s){const e=this._surface.layerViewByIndex(s,i);if(C(e)&&"normal"!==e?.layer?.blendMode||y(e?.layer?.parent)&&this._hasBlendableAncestor(e?.layer?.parent))return!0}return!1}_createOrUpdateAgents(e,t){const i=this.layerInfo[t];if(0===i.length)return;const s=this._isSuspended(t);for(let n=e;n<i.length;++n){const r=i[n];let a=!1;const o=this._surface.layerViewByIndex(n,t),l=U(o);if(r.loadingAgent?Z(this,l,!1)?(r.loadingAgent!==$&&r.loadingAgent.setSuspension(s),r.loadingAgent!==$&&(a=r.loadingAgent.update())):r.dispose():Z(this,l,!1)&&(r.loadingAgent=ie(this,n,t,s),a=r.loadingAgent.startLoading(),a?r.loadingAgent===$&&this.setPendingUpdate(K.GEOMETRY):(se(r.loadingAgent),r.loadingAgent=$)),r.loadingAgent===$&&this.updateRenderData(t,E.FADING),!this._hasBlendModes(e,i.length,t)&&a&&o.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]}getElevationVerticesPerSide(t){const i=this.elevationLevel-this.level,s=Math.max(this.level-t,b(this.level)-i),n=e(1+(this.maxTesselation>>s),2,this.maxTesselation+1),r=this.getDefaultVerticesPerSide();return Math.max(n,r)}get test(){return{cachedMemory:this._cachedMemory}}_findLIJ(e,t){if(!e)return null;const i=this.surface.rootTiles;if(null!=i)for(const s of i)if(le(s,e)){let i=s,n=e[0]-i.level-1;for(;n>=0&&!i.isLeaf&&!t(i);){const t=e[1]>>n&1,s=e[2]>>n&1;i=i.children[2*t+s],n--}return t(i)?i:null}return null}findNeighborTile(e,t){const i=this._lij,s=this.getNeighborLIJ(i,e);return s?he(i,s)?t(this)?this:null:this._findLIJ(s,t):null}findCorner(e,t){const i=e===D.NORTH_EAST?1:e===D.NORTH_WEST?0:e===D.SOUTH_WEST?2:3;let s=this;for(;s.children[0]&&(!t||!t(s));)s=s.children[i];return s}findNeighborCornerTileExact(e,t){return this.findNeighborTile(e,(e=>t(e)||e.level===this.level))?.findCorner(B(e),t)||null}forAllSubtreeOnSide(e,t){const i=e===D.NORTH?[0,1]:e===D.NORTH_EAST?[1]:e===D.EAST?[1,3]:e===D.SOUTH_EAST?[3]:e===D.SOUTH?[2,3]:e===D.SOUTH_WEST?[2]:e===D.WEST?[0,2]:[0],s=e=>{const n=e.children;!t(e)&&n[0]&&i.forEach((e=>s(n[e])))};s(this)}getNeighborEdgeStartVertexIndex(e,t){if(!t)return 0;const i=this.level-t.level;if(P(!R||i>=0),0===i)return 0;const s=2**i,n=1==(1&e),r=n?0:1,a=t.lij[r+1]*s,o=this._lij[r+1],l=o-a,h=n?s-1-l:l;return R&&(P(a<=o&&o<a+s),P(0<=h&&h<s)),h}forEachLoadedNeighbor(e){const t=this.level,i=e=>e.level===t||e.isLoaded;V.forEach((t=>{const s=this.findNeighborTile(t,i);null!=s&&s!==this&&s.forAllSubtreeOnSide(w(t),(i=>!!i.isLoaded&&(e(i,t),!0)))})),G.forEach((t=>{const s=this.findNeighborTile(t,i)?.findCorner(B(t),(e=>e.isLoaded));P(!s||de(this,s,t)),s?.isLoaded&&e(s,t)}))}getNeighborLIJ(e,t){const i=W(t)?-1:q(t)?1:0,s=F(t)?-1:H(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(){const e=this.surface.extent,t=e?.[1]??null;return null!=t&&this.extent[1]+c()>=t}checkGeometryWaterproofness(){k&&(P(this.isLoaded),this.renderData?.checkGeometryWaterproofness())}shouldHaveNeighbor(e){const t=this.extent,i=this.surface.rootTilesExtent,s=.25*(t[2]-t[0]);if(W(e)&&t[3]+s>=i[3])return!1;if(q(e)&&t[1]-s<=i[1])return!1;const n=this.surface.isGlobal;return!(!n&&F(e)&&t[0]-s<=i[0])&&!(!n&&H(e)&&t[2]+s>=i[2])}updateDistanceToPOI(e){const t=this._lastPOI;if(this.distanceToPOI>=0&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return;h(this._lastPOI,e);const i=this._center[oe.MIDDLE],s=e[0]-i[0],n=e[1]-i[1],r=e[2]-i[2];this.distanceToPOI=s*s+n*n+r*r}}function ie(e,t,i,s){const n=i===x.ELEVATION?re.acquire():ne.acquire();return n.init(e,t,i,s),n}function se(e){e.dispose(),e instanceof v?re.release(e):e instanceof S&&ne.release(e)}const ne=new i(S),re=new i(v),ae=new T;var oe;function le(e,t){const i=e.lij,s=t[0]-i[0];return!(s<0)&&(t[1]>>s===i[1]&&t[2]>>s===i[2])}function he(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function ue(e,t,i){if(null==e||null==t)return!1;if(0===e.level&&0===t.level){if(e.isEastEnd&&t.isWestEnd&&i===D.EAST)return!0;if(e.isWestEnd&&t.isEastEnd&&i===D.WEST)return!0}const s=Math.max(1e-6*(e.extent[2]-e.extent[0]),1);switch(i){case D.NORTH:return X(e.extent[3],t.extent[1],s);case D.SOUTH:return X(e.extent[1],t.extent[3],s);case D.EAST:return X(e.extent[2],t.extent[0],s)||X(e.extent[2],-t.extent[0],s);case D.WEST:return X(e.extent[0],t.extent[2],s)||X(e.extent[0],-t.extent[2],s)}}function de(e,t,i){return null!=e&&null!=t&&t!==e&&(e.level>=t.level?ce(e,t,i):ce(t,e,B(i)))}function ce(e,t,i){P(e.level>=t.level);const s=Y(i),n=z(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]),u=X(o[0],l[0],h)||e.surface.isGlobal&&X(o[0],-l[0],h),d=X(o[1],l[1],h);if(u&&d)return!0;if(e.level===t.level)return P(!1),!1;if(!u&&!d)return P(!1),!1;const c=u?ge(a[1],a[3],r[1],r[3],h):ge(a[0],a[2],r[0],r[2],h);return P(c),c}function ge(e,t,i,s,n){return e-n<=i&&i<=s&&s<=t+n}!function(e){e[e.TOP=0]="TOP",e[e.MIDDLE=1]="MIDDLE",e[e.BOTTOM=2]="BOTTOM"}(oe||(oe={}));const pe=u(),fe=u(),_e=u(),me=u();export{oe as CenterPosition,te as Tile,de as isCornerNeighbor,ue as isEdgeNeighbor,he as lijEquals};
|