@arcgis/core 4.24.0-next.20220511 → 4.24.0-next.20220512
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/components/assets/icon/compactness16.json +1 -0
- package/assets/components/assets/icon/compactness24.json +1 -0
- package/assets/components/assets/icon/compactness32.json +1 -0
- package/assets/components/assets/icon/configure16.json +1 -0
- package/assets/components/assets/icon/configure24.json +1 -0
- package/assets/components/assets/icon/configure32.json +1 -0
- package/assets/components/assets/icon/debugScript16.json +1 -0
- package/assets/components/assets/icon/debugScript24.json +1 -0
- package/assets/components/assets/icon/debugScript32.json +1 -0
- package/assets/components/assets/icon/dissolveFeatures16.json +1 -0
- package/assets/components/assets/icon/dissolveFeatures24.json +1 -0
- package/assets/components/assets/icon/dissolveFeatures32.json +1 -0
- package/assets/components/assets/icon/distanceType16.json +1 -0
- package/assets/components/assets/icon/distanceType24.json +1 -0
- package/assets/components/assets/icon/distanceType32.json +1 -0
- package/assets/components/assets/icon/gridDiamond16.json +1 -0
- package/assets/components/assets/icon/gridDiamond24.json +1 -0
- package/assets/components/assets/icon/gridDiamond32.json +1 -0
- package/assets/components/assets/icon/gridHexagon16.json +1 -0
- package/assets/components/assets/icon/gridHexagon24.json +1 -0
- package/assets/components/assets/icon/gridHexagon32.json +1 -0
- package/assets/components/assets/icon/gridTriangle16.json +1 -0
- package/assets/components/assets/icon/gridTriangle24.json +1 -0
- package/assets/components/assets/icon/gridTriangle32.json +1 -0
- package/assets/components/assets/icon/insets16.json +1 -0
- package/assets/components/assets/icon/insets24.json +1 -0
- package/assets/components/assets/icon/insets32.json +1 -0
- package/assets/components/assets/icon/maximumTerritoryDistance16.json +1 -0
- package/assets/components/assets/icon/maximumTerritoryDistance24.json +1 -0
- package/assets/components/assets/icon/maximumTerritoryDistance32.json +1 -0
- package/assets/components/assets/icon/minDistanceBetweenCenters16.json +1 -0
- package/assets/components/assets/icon/minDistanceBetweenCenters24.json +1 -0
- package/assets/components/assets/icon/minDistanceBetweenCenters32.json +1 -0
- package/assets/components/assets/icon/numberOfTerritories16.json +1 -0
- package/assets/components/assets/icon/numberOfTerritories24.json +1 -0
- package/assets/components/assets/icon/numberOfTerritories32.json +1 -0
- package/assets/components/assets/icon/overlapFeatures16.json +1 -0
- package/assets/components/assets/icon/overlapFeatures24.json +1 -0
- package/assets/components/assets/icon/overlapFeatures32.json +1 -0
- package/assets/components/assets/icon/profileVariables16.json +1 -0
- package/assets/components/assets/icon/profileVariables24.json +1 -0
- package/assets/components/assets/icon/profileVariables32.json +1 -0
- package/assets/components/assets/icon/rasterAnalysis16.json +1 -0
- package/assets/components/assets/icon/rasterAnalysis24.json +1 -0
- package/assets/components/assets/icon/rasterAnalysis32.json +1 -0
- package/assets/components/assets/icon/recurrence16.json +1 -0
- package/assets/components/assets/icon/recurrence24.json +1 -0
- package/assets/components/assets/icon/recurrence32.json +1 -0
- package/assets/components/assets/icon/splitFeatures16.json +1 -0
- package/assets/components/assets/icon/splitFeatures24.json +1 -0
- package/assets/components/assets/icon/splitFeatures32.json +1 -0
- package/assets/components/assets/icon/territoryBufferDistance16.json +1 -0
- package/assets/components/assets/icon/territoryBufferDistance24.json +1 -0
- package/assets/components/assets/icon/territoryBufferDistance32.json +1 -0
- package/assets/components/assets/icon/testData16.json +1 -0
- package/assets/components/assets/icon/testData24.json +1 -0
- package/assets/components/assets/icon/testData32.json +1 -0
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/07eda3e958d29f86b37e.js +1 -0
- package/assets/esri/core/workers/chunks/0ecaa28b8bff1d779d66.js +1 -0
- package/assets/esri/core/workers/chunks/{adae54f116f311d72d97.js → 1aba8c73c62a64e0658c.js} +1 -1
- package/assets/esri/core/workers/chunks/1d109cd048170e2d529a.js +1 -0
- package/assets/esri/core/workers/chunks/366e5c1abd1ab6d3e548.js +1 -0
- package/assets/esri/core/workers/chunks/3e94e35f44aadbb332ff.js +1 -0
- package/assets/esri/core/workers/chunks/46411f32b29a0e783105.js +1 -0
- package/assets/esri/core/workers/chunks/4d1c87e3e0a02efcc082.js +1 -0
- package/assets/esri/core/workers/chunks/{b089058b64db3912478f.js → 5e46e60fab93ad034d3a.js} +1 -1
- package/assets/esri/core/workers/chunks/6281b15009712a5dee3c.js +1 -0
- package/assets/esri/core/workers/chunks/66f627d68dbb0fdb725f.js +1 -0
- package/assets/esri/core/workers/chunks/672da24bbf86718bf48d.js +1 -0
- package/assets/esri/core/workers/chunks/733625d85602127d62cd.js +1 -0
- package/assets/esri/core/workers/chunks/{c51c9b5da855f84b9a48.js → 7391422fc51acb96a25d.js} +1 -1
- package/assets/esri/core/workers/chunks/{f435dc615fdc8917f6ca.js → 7cf3cff7b28ff007dbad.js} +1 -1
- package/assets/esri/core/workers/chunks/7ea06c86adfc827fda08.js +1 -0
- package/assets/esri/core/workers/chunks/{a054a52712a118c6d505.js → 82bc24bdc9c6ebaf58c0.js} +1 -1
- package/assets/esri/core/workers/chunks/8965ab74e03506e3475e.js +1 -0
- package/assets/esri/core/workers/chunks/{5405f478af3563580926.js → 8b497d9c37a8f577a467.js} +1 -1
- package/assets/esri/core/workers/chunks/919d0d8b1c2176760973.js +1 -0
- package/assets/esri/core/workers/chunks/ab2a0480dc2b608deda3.js +1 -0
- package/assets/esri/core/workers/chunks/ab97a35f7a7d5cf1da19.js +2 -0
- package/assets/esri/core/workers/chunks/{dcd0653191cd4a1ccaae.js.LICENSE.txt → ab97a35f7a7d5cf1da19.js.LICENSE.txt} +1 -1
- package/assets/esri/core/workers/chunks/ae554c88e862a5761f2e.js +1 -0
- package/assets/esri/core/workers/chunks/ae5ce55cd1a32525f101.js +1 -0
- package/assets/esri/core/workers/chunks/b597c04a4abb98e29d1c.js +1 -0
- package/assets/esri/core/workers/chunks/{287c484fd40eee643f3a.js → b78c3e9d31c4a562cdf0.js} +1 -1
- package/assets/esri/core/workers/chunks/be4bf1e4cbe2a593f8b3.js +1 -0
- package/assets/esri/core/workers/chunks/{b7572b0921b23aef8b9d.js → c40d9caf5189be2c698e.js} +1 -1
- package/assets/esri/core/workers/chunks/{b28539c5a6bedb71b038.js → d63f736b3560c577a8a4.js} +1 -1
- package/assets/esri/core/workers/chunks/d869dabe937d3b60504e.js +1 -0
- package/assets/esri/core/workers/chunks/dd6c9a114ad38cf622ba.js +1 -0
- package/assets/esri/core/workers/chunks/e6b0f74226b9394bfa7a.js +1 -0
- package/assets/esri/themes/base/widgets/_Editor.scss +3 -2
- package/assets/esri/themes/dark/main.css +1 -1
- package/assets/esri/themes/light/main.css +1 -1
- package/assets/esri/themes/light/view.css +1 -1
- package/assets/esri/views/interactive/tooltip/t9n/Tooltip.json +1 -0
- package/assets/esri/views/interactive/tooltip/t9n/Tooltip_en.json +1 -0
- package/chunks/EdgeShader.glsl.js +3 -4
- package/interfaces.d.ts +463 -30
- package/layers/FeatureLayer.js +1 -1
- package/layers/GeoJSONLayer.js +1 -1
- package/layers/OGCFeatureLayer.js +1 -1
- package/layers/RouteLayer.js +1 -1
- package/layers/SceneLayer.js +1 -1
- package/layers/StreamLayer.js +1 -1
- package/layers/SubtypeGroupLayer.js +1 -1
- package/layers/WFSLayer.js +1 -1
- package/layers/buildingSublayers/BuildingComponentSublayer.js +1 -1
- package/layers/mixins/ArcGISImageService.js +1 -1
- package/layers/save/featureLayerUtils.js +1 -1
- package/layers/support/AggregateField.d.ts +4 -0
- package/layers/support/AggregateField.js +1 -1
- package/layers/support/FeatureReductionBinning.d.ts +4 -0
- package/layers/support/FeatureReductionBinning.js +1 -1
- package/layers/support/OutStatistic.d.ts +4 -0
- package/layers/support/Sublayer.js +1 -1
- package/layers/support/SubtypeSublayer.js +1 -1
- package/layers/support/rasterDatasets/ImageServerRaster.js +1 -1
- package/layers/support/rasterDatasets/wcsCoverageParser.js +1 -1
- package/layers/support/rasterFormats/TiffDecoder.js +1 -1
- package/package.json +3 -3
- package/portal/support/portalItemUtils.js +1 -1
- package/renderers/PieChartRenderer.d.ts +4 -0
- package/renderers/PieChartRenderer.js +5 -0
- package/renderers/Renderer.js +1 -1
- package/renderers/support/AuthoringInfo.js +1 -1
- package/renderers/support/RasterSymbolizer.js +1 -1
- package/renderers/support/clickToleranceUtils.js +1 -1
- package/renderers/support/rasterRendererHelper.js +1 -1
- package/renderers/support/types.js +1 -1
- package/renderers/support/utils.js +1 -1
- package/renderers.js +1 -1
- package/request.js +1 -1
- package/rest/imageService/fetchRasterInfo.js +5 -0
- package/rest/imageService/getCatalogItemRasterInfo.js +5 -0
- package/rest/print.js +1 -1
- package/smartMapping/renderers/color.js +1 -1
- package/smartMapping/renderers/dotDensity.js +1 -1
- package/smartMapping/renderers/heatmap.js +1 -1
- package/smartMapping/renderers/location.js +1 -1
- package/smartMapping/renderers/size.js +1 -1
- package/smartMapping/renderers/type.js +1 -1
- package/support/arcadeUtils.js +1 -1
- package/support/revision.js +1 -1
- package/symbols/cim/CIMSymbolHelper.js +1 -1
- package/symbols/cim/CurveHelper.js +1 -1
- package/symbols/cim/ExpandedCIM.js +1 -1
- package/symbols/cim/cimAnalyzer.js +1 -1
- package/symbols/cim/placements/PlacementInsidePolygon.js +1 -1
- package/views/2d/engine/brushes.js +1 -1
- package/views/2d/engine/vectorTiles/GlyphSource.js +1 -1
- package/views/2d/engine/vectorTiles/style/Filter.js +1 -1
- package/views/2d/engine/vectorTiles/style/StyleRepository.js +1 -1
- package/views/2d/engine/webgl/AttributeStoreView.js +1 -1
- package/views/2d/engine/webgl/Painter.js +1 -1
- package/views/2d/engine/webgl/Utils.js +1 -1
- package/views/2d/engine/webgl/brushes/WGLBrushPieChart.js +5 -0
- package/views/2d/engine/webgl/brushes/WGLGeometryBrush.js +1 -1
- package/views/2d/engine/webgl/brushes/WGLGeometryBrushFill.js +1 -1
- package/views/2d/engine/webgl/brushes/WGLGeometryBrushMarker.js +1 -1
- package/views/2d/engine/webgl/color.js +1 -1
- package/views/2d/engine/webgl/definitions.js +1 -1
- package/views/2d/engine/webgl/enums.js +1 -1
- package/views/2d/engine/webgl/mesh/templates/WGLBaseFillTemplate.js +1 -1
- package/views/2d/engine/webgl/mesh/templates/WGLBaseLineTemplate.js +1 -1
- package/views/2d/engine/webgl/mesh/templates/WGLDynamicFillTemplate.js +1 -1
- package/views/2d/engine/webgl/mesh/templates/WGLFillTemplate.js +1 -1
- package/views/2d/engine/webgl/mesh/templates/WGLMarkerTemplate.js +1 -1
- package/views/2d/engine/webgl/shaders/sources/shaderRepository.js +1 -1
- package/views/2d/engine/webgl/techniques/dotDensity/TechniqueDotDensity.js +1 -1
- package/views/2d/engine/webgl/techniques/pieChart/TechniquePieChart.js +5 -0
- package/views/2d/engine/webgl/techniques/utils.js +1 -1
- package/views/2d/engine/webgl/util/Matcher.js +1 -1
- package/views/2d/layers/features/schemaUtils.js +1 -1
- package/views/2d/layers/features/support/AttributeStore.js +1 -1
- package/views/2d/layers/features/tileRenderers/SymbolTileRenderer.js +1 -1
- package/views/2d/layers/features/tileRenderers/support/WGLFeatureView.js +1 -1
- package/views/2d/layers/imagery/ImageryTileView2D.js +1 -1
- package/views/3d/analysis/Dimensioning/DimensioningTool.js +1 -1
- package/views/3d/analysis/Dimensioning/LengthDimensionVisualization.js +1 -1
- package/views/3d/environment/SnowyWeather.d.ts +4 -0
- package/views/3d/layers/I3SMeshView3D.js +1 -1
- package/views/3d/layers/graphics/Graphics3DCore.js +1 -1
- package/views/3d/terrain/TerrainRenderer.js +1 -1
- package/views/3d/terrain/TerrainSurface.js +1 -1
- package/views/3d/terrain/TileRenderer.js +1 -1
- package/views/3d/webgl-engine/collections/Component/ComponentObjectCollection.js +1 -1
- package/views/3d/webgl-engine/collections/Component/Material/shader/ComponentData.glsl.js +5 -5
- package/views/3d/webgl-engine/lib/Renderer.js +1 -1
- package/views/3d/webgl-engine/lib/edgeRendering/EdgeRenderer.js +1 -1
- package/views/3d/webgl-engine/lib/edgeRendering/EdgeShaderTechniqueConfiguration.js +1 -1
- package/views/3d/webgl-engine/lib/edgeRendering/EdgeView.js +1 -1
- package/views/3d/webgl-engine/shaders/sources/edgeRenderer/EdgeUtil.glsl.js +37 -31
- package/views/draw/DrawOperation.js +1 -1
- package/views/interactive/snapping/FeatureSnappingEngine.js +1 -1
- package/views/interactive/snapping/SceneSnappingEngine.js +5 -0
- package/views/interactive/snapping/SnappingManager.js +1 -1
- package/views/interactive/snapping/snappingFactory.js +5 -0
- package/views/interactive/tooltip/content/TooltipContent.js +1 -1
- package/views/interactive/tooltip/content/TooltipContentDrawPoint.js +1 -1
- package/views/interactive/tooltip/content/TooltipContentDrawPolygon.js +1 -1
- package/views/interactive/tooltip/content/TooltipContentDrawPolyline.js +1 -1
- package/views/interactive/tooltip/content/TooltipContentTranslateVertex.js +1 -1
- package/widgets/Editor/workflowUtils.js +1 -1
- package/widgets/Editor.js +1 -1
- package/widgets/Popup/PopupViewModel.js +1 -1
- package/widgets/Popup/actionUtils.js +1 -1
- package/widgets/Sketch/SketchViewModel.js +1 -1
- package/assets/esri/core/workers/chunks/0564f1cfa3d17ff1aad3.js +0 -1
- package/assets/esri/core/workers/chunks/0806d5d706a864542bfb.js +0 -1
- package/assets/esri/core/workers/chunks/52478ee2d2a1354b6900.js +0 -1
- package/assets/esri/core/workers/chunks/5759af97f96f24c40105.js +0 -1
- package/assets/esri/core/workers/chunks/7bc828fbdd54c0b28aac.js +0 -1
- package/assets/esri/core/workers/chunks/875f26ee040f3d75c0db.js +0 -1
- package/assets/esri/core/workers/chunks/88384e7cafbfd2348598.js +0 -1
- package/assets/esri/core/workers/chunks/89acd5f888d6b8df4aad.js +0 -1
- package/assets/esri/core/workers/chunks/9d7533aaeac3b8d145c4.js +0 -1
- package/assets/esri/core/workers/chunks/a3bb600bfcb0282622f1.js +0 -1
- package/assets/esri/core/workers/chunks/b50ae3dc7e43ff452568.js +0 -1
- package/assets/esri/core/workers/chunks/b5b7bcbc19b3430903ee.js +0 -1
- package/assets/esri/core/workers/chunks/b758f3c419edc2306784.js +0 -1
- package/assets/esri/core/workers/chunks/cf47b605c31063e88357.js +0 -1
- package/assets/esri/core/workers/chunks/cfbb332d144e65a4a55d.js +0 -1
- package/assets/esri/core/workers/chunks/db937849b2c1af87b481.js +0 -1
- package/assets/esri/core/workers/chunks/dc3ed59f450283d97a19.js +0 -1
- package/assets/esri/core/workers/chunks/dcd0653191cd4a1ccaae.js +0 -2
- package/assets/esri/core/workers/chunks/dfb6a28039e5d5ce6fd4.js +0 -1
- package/assets/esri/core/workers/chunks/e4fdd1eaf987977d0a51.js +0 -1
- package/assets/esri/core/workers/chunks/f7e0bb11ba3677069c94.js +0 -1
- package/assets/esri/core/workers/chunks/f7f3dde4c8f9c687cc1e.js +0 -1
- package/assets/esri/core/workers/chunks/fc6beaf9466ea3898549.js +0 -1
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../../../chunks/tslib.es6.js";import"../../../../geometry.js";import"../../../../renderers/ClassBreaksRenderer.js";import"../../../../renderers/DictionaryRenderer.js";import"../../../../renderers/DotDensityRenderer.js";import"../../../../renderers/HeatmapRenderer.js";import"../../../../renderers/Renderer.js";import"../../../../renderers/SimpleRenderer.js";import t from"../../../../renderers/UniqueValueRenderer.js";import"../../../../renderers/support/jsonUtils.js";import"../../../../symbols.js";import i from"../../../../core/Accessor.js";import"../../../../core/has.js";import r from"../../../../core/Error.js";import s from"../../../../core/Handles.js";import{makeHandle as a}from"../../../../core/handleUtils.js";import{equalsShallow as n}from"../../../../core/lang.js";import o from"../../../../core/Logger.js";import{someMap as l,findInMap as h}from"../../../../core/MapUtils.js";import{isSome as d,unwrapOr as p,isNone as c,removeMaybe as y,destroyMaybe as m,get as g,unwrap as u}from"../../../../core/maybe.js";import b from"../../../../core/PooledArray.js";import{throwIfAborted as f,eachAlways as v,createDeferred as C,isAbortError as S}from"../../../../core/promiseUtils.js";import{watch as _,when as G,on as w,syncAndInitial as x,whenOnce as R}from"../../../../core/reactiveUtils.js";import{schedule as P}from"../../../../core/scheduling.js";import{property as D}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import{subclass as E}from"../../../../core/accessorSupport/decorators/subclass.js";import{diff as I,isEmpty as U}from"../../../../core/accessorSupport/diffUtils.js";import{s as O,a as A,g as L}from"../../../../chunks/vec3.js";import{c as j}from"../../../../chunks/vec3f64.js";import{projectVectorToVector as V,projectXYZToVector as F,canProjectWithoutEngine as T,projectBuffer as k}from"../../../../geometry/projection.js";import{create as M,center as W,fromRect as N,equals as z}from"../../../../geometry/support/aaBoundingBox.js";import{create as B}from"../../../../geometry/support/aaBoundingRect.js";import q from"../../../../layers/Layer.js";import{getObjectId as H,computeAABB as Y,hasGeometry as $}from"../../../../layers/graphics/dehydratedFeatures.js";import{hydrateGraphic as Z}from"../../../../layers/graphics/hydratedFeatures.js";import{isSupportedRenderer3D as J,validateTo3D as Q}from"../../../../renderers/support/rendererConversion.js";import{loadArcade as K}from"../../../../support/arcadeOnDemand.js";import{getDefaultSymbol3D as X}from"../../../../symbols/support/defaults3D.js";import{to3D as ee}from"../../../../symbols/support/symbolConversion.js";import{ViewElevationProvider as te}from"./ElevationQuery.js";import{VisibilityFlag as ie,VisibilityGroup as re}from"./enums.js";import{extractExpressionInfo as se,createContext as ae}from"./featureExpressionInfoUtils.js";import{Graphics3DFeatureStore as ne}from"./Graphics3DFeatureStore.js";import oe from"./Graphics3DGraphicCreationContext.js";import{Graphics3DSymbolCreationContext as le}from"./Graphics3DSymbolCreationContext.js";import{make as he}from"./Graphics3DSymbolFactory.js";import de from"./Graphics3DWebStyleSymbol.js";import{GraphicStateTracking as pe}from"./GraphicStateTracking.js";import{computeCentroid as ce}from"./graphicUtils.js";import{ApplyRendererDiffResult as ye}from"./interfaces.js";import{LoadStatus as me}from"./Loadable.js";import{SpatialIndex2D as ge}from"./SpatialIndex2D.js";import{averageSymbolComplexities as ue,defaultSymbolComplexity as be}from"./symbolComplexity.js";import{StageLayerElevationProvider as fe}from"../support/StageLayerElevationProvider.js";import{toBoundingRect as ve}from"../../support/extentUtils.js";import{PropertiesPool as Ce}from"../../support/PropertiesPool.js";import{UpdatePolicy as Se}from"../../webgl-engine/lib/basicInterfaces.js";import{GridLocalOriginFactory as _e}from"../../webgl-engine/lib/GridLocalOriginFactory.js";import{WebGLLayer as Ge}from"../../webgl-engine/lib/WebGLLayer.js";import{ImmediateTask as we,noBudget as xe,TaskPriority as Re}from"../../../support/Scheduler.js";import Pe from"../../../../geometry/Extent.js";import De from"../../../../geometry/Point.js";import Ee from"../../../../symbols/LabelSymbol3D.js";import Ie from"../../../../symbols/TextSymbol.js";import Ue from"../../../../symbols/WebStyleSymbol.js";var Oe;const Ae=j(),Le=M(),je=o.getLogger("esri.views.3d.layers.graphics.Graphics3DCore");let Ve=Oe=class extends i{constructor(e){super(e),this.propertiesPool=new Ce({computedExtent:Pe},this),this.computedExtent=null,this.currentRenderer=null,this.rendererHasGeometryOperations=!1,this.graphicStateTracking=null,this.symbolCreationContext=new le(((e,t)=>this._frameTask.schedule(e,t))),this.graphics3DGraphics=new Map,this.stageLayer=null,this.stage=null,this.graphicsDrapedUids=new Set,this.graphicsBySymbol=new Map,this.symbolConversionCache=new Map,this.symbols=new Map,this.graphicsWithoutSymbol=new Map,this.graphicsWaitingForSymbol=new Map,this.graphicsUpdateId=0,this._handles=new s,this._frameTask=we,this.suspendSymbolCleanup=!1,this._spatialReference=null,this.arcadeOnDemand=null,this.rendererChangeAbortController=null,this.elevationInfoChangeAbortController=null,this.setupAbortController=null,this.elevationAlignment=null,this.scaleVisibility=null,this.filterVisibility=null,this._spatialIndex=null,this.extentPadding=0,this._updatingPendingLoadedGraphicsChange=null,this.featureStore=null,this.deconflictor=null,this.labeler=null,this.objectStates=null,this.viewElevationProvider=null,this.stageLayerElevationProvider=null,this.sharedSymbolResourcesOwnerHandle=null,this.whenGraphics3DGraphicRequests={},this.pendingUpdates=new Map,this.numberOfGraphics=0,this.numberOfGraphicsProvidingElevation=0,this.pendingAdds=0,this.pendingRemoves=0,this._loadingSymbols=0,this.pendingUpdatesPool=new b({allocator:e=>e||new Te,deallocator:e=>(e.clear(),e)}),this.symbolWarningLogged=!1,this.geometryWarningLogged=!1,this.objectIdInvisibleSet=new Set,this._whenSymbolRemoved=new b,this.preferredUpdatePolicy=Se.SYNC,this.forcedUpdatePolicy=null,this.elevationFeatureExpressionEnabled=!0,this.owner=null,this.layer=null,this.graphicSymbolSupported=!0,this.getRenderingInfoWithoutRenderer=!1,this.hasZ=null,this.hasM=null,this._usedMemory=0,this._visible=void 0,this._startCreateGraphics=!1}get spatialIndex(){return this._spatialIndex||(this._spatialIndex=new ge({objectIdField:this.owner.layer?.objectIdField,spatialReference:this._spatialReference,hasZ:this.hasZ,hasM:this.hasM}),this._spatialIndex.setup(Array.from(this.graphics3DGraphics.values()))),this._spatialIndex.update(),this._spatialIndex}get effectiveUpdatePolicy(){return d(this.currentRenderer)&&"dictionary"===this.currentRenderer.type?Se.ASYNC:p(this.forcedUpdatePolicy,this.preferredUpdatePolicy)}get updating(){return!!(this.graphicsWaitingForSymbol.size>0||this.running||this.elevationAlignment?.updating||d(this.scaleVisibility)&&this.scaleVisibility.updating||this.filterVisibility?.updating||this.rendererChangeAbortController||this.elevationInfoChangeAbortController||this._updatingPendingLoadedGraphicsChange||this._frameTask.updating||this._loadingSymbols>0)}get running(){return this.pendingUpdates.size>0||!!this._spatialIndex?.updating}get suspendedOrOutsideOfView(){return this.owner.suspended||this.owner.suspendInfo?.outsideOfView}get updatingRemaining(){return this.updating?this.pendingUpdates.size+.1*(this._spatialIndex?.updatingRemaining||0)+.1*(this.elevationAlignment?.updatingRemaining||0):0}get displayFeatureLimit(){const e=this.owner&&this.owner.view&&this.owner.view.qualitySettings,t=e?e.graphics3D.minTotalNumberOfFeatures:0,i=e?e.graphics3D.maxTotalNumberOfFeatures:0,r=e?e.graphics3D.maxTotalNumberOfPrimitives:0,s=this.averageSymbolComplexity,a=Math.max(1,d(s)?s.primitivesPerFeature:1),n=d(s)&&s.drawCallsPerFeature>0?i/s.drawCallsPerFeature*.3:i,o=Math.ceil(r/a),l=Math.max(t,Math.min(i,o,n)),h=this._get("displayFeatureLimit");return h&&h.minimumTotalNumberOfFeatures===t&&h.maximumTotalNumberOfFeatures===i&&h.maximumTotalNumberOfPrimitives===r&&h.averageSymbolComplexity===s&&h.maximumNumberOfFeatures===l?h:{minimumTotalNumberOfFeatures:t,maximumTotalNumberOfFeatures:i,maximumTotalNumberOfPrimitives:r,averageSymbolComplexity:s,maximumNumberOfFeatures:l}}get averageSymbolComplexity(){const e=ue(this.symbolComplexities),t=this._get("averageSymbolComplexity");return 0===e.numComplexities||d(t)&&(e.estimated&&(t.primitivesPerFeature>=e.primitivesPerFeature||t.primitivesPerCoordinate>=e.primitivesPerCoordinate||t.drawCallsPerFeature>=e.drawCallsPerFeature)||t.primitivesPerFeature===e.primitivesPerFeature&&t.primitivesPerCoordinate===e.primitivesPerCoordinate&&t.drawCallsPerFeature===e.drawCallsPerFeature)?t:e}get spatialReference(){return this._spatialReference}get usedMemory(){const e=d(this.averageSymbolComplexity)&&this.labelsEnabled?this.averageSymbolComplexity.memory.bytesPerFeatureLabel*this.numberOfGraphics:0;return this._usedMemory+e}get usedMemoryPerGraphic(){if(this._usedMemory&&this.numberOfGraphics)return Math.abs(this.pendingAdds-this.pendingRemoves)/this.numberOfGraphics>30?0:this._usedMemory/this.numberOfGraphics;if(d(this.averageSymbolComplexity)){const e=this.labelsEnabled?this.averageSymbolComplexity.memory.bytesPerFeatureLabel:0;return this.averageSymbolComplexity.memory.bytesPerFeature+e}return 0}get unprocessedMemoryEstimate(){return Math.max(0,(this.pendingAdds-this.pendingRemoves)*this.usedMemoryPerGraphic)}get symbolComplexities(){return this.currentRenderer?this._getSymbolComplexitiesUsedOrRenderer(this.currentRenderer):this._getSymbolComplexitiesUsed()}_getConvertedSymbol(e){if("web-style"===e.type)return e.clone();const t=this.symbolConversionCache.get(e.id);if(d(t))return t;const i=ee(e,{retainId:!0,hasLabelingContext:this._hasLabelingContext(e)}),r=i.symbol||null;return c(r)&&i.error&&je.error(i.error.message),this.symbolConversionCache.set(e.id,r),r}_getSymbolComplexitiesUsedOrRenderer(e){if(c(e))return[];const t=e.getSymbols(),i="backgroundFillSymbol"in e&&e.backgroundFillSymbol;if(!(i||t&&t.length))return[];const r=[],s=this._getSymbolComplexityUsedOrRenderer(i);d(s)&&r.push(s);for(const a of t){const e=this._getSymbolComplexityUsedOrRenderer(a);d(e)&&r.push(e)}return r}_getSymbolComplexityUsedOrRenderer(e){if(c(e))return null;const t=this.symbols.get(e.id);if(d(t))return t.complexity;const i=this._getConvertedSymbol(e);return d(i)?be(i):null}_getSymbolComplexitiesUsed(){const e=[];return this.symbols.forEach((t=>{d(t)&&e.push(t.complexity)})),e}initialize(){this._spatialReference=this.owner.view.spatialReference,this._set("featureStore",new ne({objectIdField:this.owner.layer&&this.owner.layer.objectIdField,hasZ:this.hasZ,hasM:this.hasM,spatialReference:this._spatialReference,featureSpatialReference:this.owner.featureSpatialReference,getSpatialIndex:()=>this.spatialIndex,forAllGraphics:e=>this.graphics3DGraphics.forEach(e)}))}async setup(e){this.setupAbortController=new AbortController;const t=this.setupAbortController.signal;this._set("elevationAlignment",e.elevationAlignment),this._set("scaleVisibility",e.scaleVisibility),this._set("filterVisibility",e.filterVisibility),this._set("deconflictor",e.deconflictor),this._set("labeler",e.labeler),this._set("objectStates",e.objectStates);const i=this.owner.view;this.viewElevationProvider=new te(this._spatialReference,i),this._initializeStage(i,this.layer.uid),this.symbolCreationContext.sharedResources=i.sharedSymbolResources,this.sharedSymbolResourcesOwnerHandle=i.sharedSymbolResources.addGraphicsOwner(this.owner),d(this.currentRenderer)&&(this.symbolCreationContext.renderer=this.currentRenderer),this.symbolCreationContext.stage=this.stage,this.symbolCreationContext.streamDataRequester=i.sharedSymbolResources.streamDataRequester,this.symbolCreationContext.renderCoordsHelper=i.renderCoordsHelper,this.symbolCreationContext.layer=this.layer,this.symbolCreationContext.graphicsCoreOwner=this.owner,this.symbolCreationContext.localOriginFactory=new _e(i.renderSpatialReference),this.symbolCreationContext.elevationProvider=i.elevationProvider,this.symbolCreationContext.notifyGraphicGeometryChanged=e=>this.notifyGraphicGeometryChanged(e),this.symbolCreationContext.notifyGraphicVisibilityChanged=e=>this.notifyGraphicVisibilityChanged(e);const r=se(this.layer.elevationInfo,this.elevationFeatureExpressionEnabled);if(this.symbolCreationContext.featureExpressionInfoContext=await ae(r,this._spatialReference,je),f(t),this.symbolCreationContext.screenSizePerspectiveEnabled=i.screenSizePerspectiveEnabled&&this.layer.screenSizePerspectiveEnabled,this.symbolCreationContext.slicePlaneEnabled=!!this.owner.slicePlaneEnabled,this.symbolCreationContext.physicalBasedRenderingEnabled=!!this.owner.view.qualitySettings.physicallyBasedRenderingEnabled,"drapeSourceType"in this.owner){const{owner:e}=this;this.symbolCreationContext.drapeSourceRenderer=i.basemapTerrain.overlayManager.registerGeometryDrapeSource(e),this._handles.add(a((()=>i.basemapTerrain.overlayManager.unregisterDrapeSource(e))))}this._handles.add([_((()=>this.suspendedOrOutsideOfView),(()=>this._frameTask.reschedule((()=>this._updateLayerVisibility())))),_((()=>[this.layer?.screenSizePerspectiveEnabled,this.owner.view.screenSizePerspectiveEnabled]),(()=>{const e=i.screenSizePerspectiveEnabled&&this.layer.screenSizePerspectiveEnabled;e!==this.symbolCreationContext.screenSizePerspectiveEnabled&&(this.symbolCreationContext.screenSizePerspectiveEnabled=e,this.labeler?.reset(),this.recreateAllGraphicsAndSymbols())}),{equals:n}),_((()=>this.owner.slicePlaneEnabled),(e=>this._slicePlaneEnabledChange(!!e))),_((()=>this.owner.view.state?.pixelRatio),(()=>this._pixelRatioChange())),_((()=>this.owner.view.qualitySettings?.physicallyBasedRenderingEnabled),(e=>this._physicalBasedRenderingChange(e))),G((()=>i.basemapTerrain?.tilingScheme),(e=>{if(e.spatialReference.equals(this.symbolCreationContext.overlaySR)||(this.symbolCreationContext.overlaySR=i.basemapTerrain.spatialReference),this._handles.has("loaded-graphics"))this.recreateAllGraphics();else{const e=()=>this.owner?.loadedGraphics;this._handles.add([w(e,"change",(e=>{this._graphicsCollectionChanged(e),this._signalUpdatingDuringAsyncLoadedGraphicsChange()}),{onListenerAdd:()=>{this.recreateAllGraphics(),this._signalUpdatingDuringAsyncLoadedGraphicsChange()}})],"loaded-graphics")}}),{initial:!0}),_((()=>this.effectiveUpdatePolicy),(e=>{d(this.stageLayer)&&(this.stageLayer.updatePolicy=e),this.symbolCreationContext.isAsync=this.effectiveUpdatePolicy===Se.ASYNC,e===Se.SYNC&&this.runTask(xe)}),x)]),this._frameTask=i.resourceController.scheduler.registerTask(Re.GRAPHICS_CORE,this),this.layer&&"featureReduction"in this.layer&&this._handles.add(_((()=>this.layer.featureReduction),(()=>this.deconflictor.featureReductionChange()))),this.notifyChange("averageSymbolComplexity");try{await this.rendererChange(this.layer.renderer)}catch{}f(t),this.setupAbortController=null}_abortSetup(){this.setupAbortController&&(this.setupAbortController.abort(),this.setupAbortController=null)}destroy(){this._abortSetup(),this._abortRendererChange(),this._abortElevationInfoChange(),this.owner.view.deconflictor.removeGraphicsOwner(this),this.owner.view.labeler.removeGraphicsOwner(this),this._updatingPendingLoadedGraphicsChange=y(this._updatingPendingLoadedGraphicsChange),this.clear(),this.graphicStateTracking=m(this.graphicStateTracking),this.stage&&(this.stage.remove(this.stageLayer),this.stageLayer=null,this.stage=null),this._handles=m(this._handles),this._frameTask.remove(),this._frameTask=we,this._spatialReference=null,this._set("owner",null);for(const e in this.whenGraphics3DGraphicRequests)this.whenGraphics3DGraphicRequests[e].reject(new r("graphic:layer-destroyed","Layer has been destroyed"));this.whenGraphics3DGraphicRequests=null,this.sharedSymbolResourcesOwnerHandle=y(this.sharedSymbolResourcesOwnerHandle),this.propertiesPool=m(this.propertiesPool),this.pendingUpdatesPool=null,this.symbolConversionCache.clear(),this.objectIdInvisibleSet.clear(),this._spatialIndex=m(this._spatialIndex),this._set("featureStore",m(this.featureStore))}clear(){this.objectStates?.allGraphicsDeleted(),d(this.graphicStateTracking)&&this.graphicStateTracking.allGraphicsDeleted(),this.graphics3DGraphics.forEach((e=>e.destroy())),this._spatialIndex?.clear(),this.graphics3DGraphics.clear(),this.numberOfGraphics=0,this._usedMemory=0,this._updateLayerVisibility(),this.symbols.forEach(m),this.symbols.clear(),this.graphicsBySymbol.clear(),this.graphicsWithoutSymbol.clear(),this.graphicsWaitingForSymbol.clear(),this.pendingUpdates.clear(),this.pendingUpdatesPool.clear(),this.pendingAdds=0,this.pendingRemoves=0,this.notifyChange("updating"),this.notifyChange("running"),this.notifyChange("updatingRemaining"),this.featureStore.events.emit("changed")}_initializeStage(e,t){this.stage=e._stage,this.stageLayer=new Ge({isPickable:!this.suspendedOrOutsideOfView,updatePolicy:this.effectiveUpdatePolicy},t),this.stage.add(this.stageLayer);const i=this.stageLayer.events;i.on("objectTransformation",(e=>this.notifyGraphicGeometryChanged(e.metadata.graphicUid))),i.on("visibilityChanged",(e=>this.notifyGraphicVisibilityChanged(e.metadata.graphicUid))),i.on("objectGeometryAdded",(e=>this.notifyGraphicGeometryChanged(e.object.metadata.graphicUid))),i.on("objectGeometryRemoved",(e=>this.notifyGraphicGeometryChanged(e.object.metadata.graphicUid))),i.on("vertexAttrsUpdated",(e=>this.notifyGraphicGeometryChanged(e.object.metadata.graphicUid)))}notifyGraphicGeometryChanged(e){if(c(this.graphicStateTracking)||c(e))return;const t=this.graphics3DGraphics.get(e);t&&this.graphicStateTracking.updateGraphicGeometry(t)}notifyGraphicVisibilityChanged(e){if(c(this.graphicStateTracking)||c(e))return;const t=this.graphics3DGraphics.get(e);t&&this.graphicStateTracking.updateGraphicVisibility(t)}_updateLayerVisibility(){const e=this.displayFeatureLimit.maximumNumberOfFeatures,t=this.numberOfGraphics>e*ke,i=!this.suspendedOrOutsideOfView&&!t;i!==this._visible&&(this._visible=i,i?(this.stageLayer.isPickable=!0,this.updateAllGraphicsVisibility()):(this.stageLayer.isPickable=!1,this._hideAllGraphics()),this._updateStageLayerVisibility())}_updateStageLayerVisibility(){this.stageLayer.isVisible=this._visible&&(null==this.layer.opacity||this.layer.opacity>0)}getGraphics3DGraphicById(e){return this.graphics3DGraphics.get(e)}getGraphics3DGraphicByObjectId(e){return this.owner.layer?.objectIdField?this._findGraphics3DGraphicByObjectId(e):null}_getGraphicObjectID(e,t=this.owner.layer&&this.owner.layer.objectIdField){return H(e,t)}get graphics3DGraphicsByObjectID(){const e=this.owner.layer&&this.owner.layer.objectIdField;if(!e)return null;const t=new Map;return this.graphics3DGraphics.forEach((i=>{if(!i)return;const r=i.graphic,s=this._getGraphicObjectID(r,e);d(s)&&t.set(s,i)})),t}get labelsEnabled(){return!(!this.labeler||!this.labeler.layerLabelsEnabled())}async updateLabelingInfo(e){const t=this.deconflictor&&this.deconflictor.labelingInfoChange(e),i=this.labeler&&this.labeler.labelingInfoChange(e);await v([t,i])}updateVisibilityInfo(){this.deconflictor&&this.deconflictor.labelingInfoChange(),this.labeler&&this.labeler.visibilityInfoChange()}get symbolUpdateType(){if(this.pendingUpdates.size>0)return"unknown";let e=0,t=0;return l(this.symbols,((i,r)=>{if(d(i)){const s=i.getFastUpdateStatus();if(s.loading>0)return!0;this.graphicsBySymbol.has(r)&&(t+=s.fast,e+=s.slow)}return!1}))?"unknown":t>=0&&0===e?"fast":e>=0&&0===t?"slow":"mixed"}runTask(e){this._frameTask.processQueue(e),this._applyPendingUpdates(e),this.notifyChange("running"),this.running||this.notifyChange("updating"),this.notifyChange("updatingRemaining")}setObjectIdVisibility(e,t){t?this.objectIdInvisibleSet.delete(e):this.objectIdInvisibleSet.add(e);const i=this._findGraphics3DGraphicByObjectId(e);d(i)&&this._updateUserVisibility(i)}_findGraphics3DGraphicByObjectId(e){return h(this.graphics3DGraphics,(t=>this._getGraphicObjectID(t.graphic)===e))}_updateUserVisibility(e){if(c(e))return!1;const t=e.graphic,i=this._getGraphicObjectID(t),r=t.visible&&!this.owner.suspended&&(c(i)||!this.objectIdInvisibleSet.has(i));return e.setVisibilityFlag(ie.USER_SETTING,r,re.GRAPHIC)}_whenGraphics3DGraphic(e){const t=this.graphics3DGraphics.get(e.uid);if(t)return Promise.resolve(t);const i=this.whenGraphics3DGraphicRequests[e.uid];if(i)return i.promise;const r=C();return this.whenGraphics3DGraphicRequests[e.uid]=r,r.promise}async _boundsForGraphics3DGraphic(e,t){const i=this._spatialReference,r=this.owner.view.renderSpatialReference,s=this.owner.view.basemapTerrain.spatialReference,a=(e,t,s)=>k(e,r,t,e,i,t,s),n=(e,t,r)=>k(e,s,t,e,i,t,r),o=this.viewElevationProvider?{service:this.viewElevationProvider,useViewElevation:d(t)&&t.useViewElevation,minDemResolution:d(t)&&t.minDemResolution,minDemResolutionForPoints:this.owner.view.resolution}:null,l=await e.getProjectedBoundingBox(a,n,o,g(t,"signal"));if(!l)return null;const h=l.boundingBox;if(l.requiresDrapedElevation){const e=this.symbolCreationContext.elevationProvider;if(e){W(h,Ae);const t=p(e.getElevation(Ae[0],Ae[1],0,i,"ground"),0);h[2]=Math.min(h[2],t),h[5]=Math.max(h[5],t)}}return{boundingBox:h,screenSpaceObjects:l.screenSpaceObjects}}async whenGraphicBounds(e,t){await R((()=>this.owner?.loadedGraphics));const i=this.owner.layer&&this.owner.layer.objectIdField,s=this.owner.loadedGraphics.find((t=>t===e||i&&t.attributes&&e.attributes&&t.attributes[i]===e.attributes[i]));if(!s)throw new r("internal:graphic-not-part-of-view","Graphic is not part of this view");const a=await this._whenGraphics3DGraphic(s);return this._boundsForGraphics3DGraphic(a,t)}computeAttachmentOrigin(e,t){const i=this.graphics3DGraphics.get(e.uid);if(!i)return null;const r=i.computeAttachmentOrigin();if(0===r.render.num&&0===r.draped.num)return null;O(Me,0,0,0);let s=0;if(r.render.num>0){if(!V(r.render.origin,this.symbolCreationContext.renderCoordsHelper.spatialReference,We,t))return null;A(Me,Me,We),s++}if(r.draped.num>0){const[e,i]=r.draped.origin,a=p(this.viewElevationProvider.getElevation(e,i,"ground"),0);if(O(We,e,i,a),!V(We,this.viewElevationProvider.spatialReference,We,t))return null;A(Me,Me,We),s++}return s>1&&L(Me,Me,1/s),new De({x:Me[0],y:Me[1],z:Me[2],spatialReference:t})}getSymbolLayerSize(e,t){const i=this.symbols.get(e.id);if(c(i))throw new r("internal:symbol-not-part-of-view","Symbol is not part of this view");const s=e.symbolLayers.indexOf(t);if(-1===s)throw new r("internal:missing-symbol-layer","Symbol layer is not in symbol");const a=i.getSymbolLayerSize(s);if(null==a)throw new r("internal:missing-size","Symbol layer has no valid size");return a}_graphicsCollectionChanged(e){this._startCreateGraphics&&(this.add(e.added),this.remove(e.removed))}graphicUpdateHandler(e){const t=e.graphic.uid,i=this.graphics3DGraphics.get(t);if(!c(i)||!c(this.graphicsWithoutSymbol.get(t)))switch(e.property){case"visible":this._graphicUpdateVisibleHandler(i);break;case"geometry":this._graphicUpdateGeometryHandler(i,e);break;case"symbol":this._graphicUpdateSymbolHandler(i,e);break;case"attributes":break;case"transform":this._graphicUpdateTransformHandler(i,e)}}_graphicUpdateGeometryHandler(e,t){const i=t.graphic.geometry;if(c(i))return void this._recreateGraphic(t.graphic);if(c(e)){const e=t.graphic.symbol&&t.graphic.symbol.id;if(e){const t=this.symbols.get(e);if(d(t)&&t.loadStatus===me.LOADING)return}return void this._recreateGraphic(t.graphic)}const r=e.graphics3DSymbol;!c(t.newValue)&&r.updateGeometry(e,t.newValue)||this._recreateGraphic(e.graphic),this._expandComputedExtent(i)}_graphicUpdateSymbolHandler(e,t){const i=t.graphic,r=d(e)?e.graphics3DSymbol:d(t.oldValue)?this.symbols.get(t.oldValue.id):null;if(c(r)||c(t.newValue))return void this._recreateGraphic(i);const s=r.symbol,a=this._getConvertedSymbol(t.newValue);if(d(a)&&(a.type!==s.type||"web-style"===a.type)||"web-style"===s.type)return void this._recreateGraphic(i);const n=this.graphicsBySymbol.get(s.id);if(n&&1!==n.size)return void this._recreateGraphic(i);const o=I(s,a);if(c(o))return void this._updateSymbolMapping(s.id,a);const l={diff:o,graphics3DGraphicPatches:[],symbolStatePatches:[]};if(r.prepareSymbolPatch(l),!U(l.diff))return void this._recreateGraphic(i);const h=this._getRenderingInfo(i);if(c(h))return void this._recreateGraphic(i);const p=r.extentPadding;for(const d of l.symbolStatePatches)d();if(p!==r.extentPadding&&this._recomputeExtentPadding(),d(e))for(const d of l.graphics3DGraphicPatches)d(e,h);this._updateSymbolMapping(s.id,a)}_graphicUpdateVisibleHandler(e){this._updateUserVisibility(e)&&(this.labeler&&this.owner.view.labeler.setDirty(),this.owner.view.deconflictor.setDirty())}_graphicUpdateTransformHandler(e,t){}recreateGraphics(e){this.suspendSymbolCleanup=!0,this.remove(e),this.add(e),this.suspendSymbolCleanup=!1,this.effectiveUpdatePolicy===Se.SYNC&&this._cleanupSymbols()}_recreateGraphic(e){this.recreateGraphics([e])}_beginGraphicUpdate(e){const t=this.graphicsUpdateId;return this.graphicsUpdateId++,this.graphicsWaitingForSymbol.set(e.uid,t),1===this.graphicsWaitingForSymbol.size&&this.notifyChange("updating"),t}_endGraphicUpdate(e){e&&(this.graphicsWaitingForSymbol.delete(e.uid),0===this.graphicsWaitingForSymbol.size&&(this._cleanupSymbols(),this.notifyChange("updating")))}_recomputeExtentPadding(){let e=0;this.symbols.forEach((t=>{d(t)&&(e=Math.max(e,t.extentPadding))})),this._set("extentPadding",e)}_expandComputedExtent(e){const t=Le,i=e.spatialReference;Y(e,t);const r=this._spatialReference,s=Oe.tmpVec;if(i.equals(r)||F(t[0],t[1],0,i,s,r)&&(t[0]=s[0],t[1]=s[1],F(t[3],t[4],0,i,s,r),t[3]=s[0],t[4]=s[1]),!(isFinite(t[0])&&isFinite(t[3])&&isFinite(t[1])&&isFinite(t[4])))return;const a=this.computedExtent;let n=null;const o=isFinite(t[2])&&isFinite(t[5]),l=o&&(!a||null==a.zmin||t[2]<a.zmin),h=o&&(!a||null==a.zmax||t[5]>a.zmax);if(a){(t[0]<a.xmin||t[1]<a.ymin||t[3]>a.xmax||t[4]>a.ymax||l||h)&&(n=this.propertiesPool.get("computedExtent"),n.xmin=Math.min(t[0],a.xmin),n.ymin=Math.min(t[1],a.ymin),n.xmax=Math.max(t[3],a.xmax),n.ymax=Math.max(t[4],a.ymax),n.spatialReference=r)}else n=this.propertiesPool.get("computedExtent"),n.xmin=t[0],n.ymin=t[1],n.xmax=t[3],n.ymax=t[4],n.spatialReference=r;n&&(l&&(n.zmin=t[2]),h&&(n.zmax=t[5]),this._set("computedExtent",n))}_abortElevationInfoChange(){this.elevationInfoChangeAbortController&&(this.elevationInfoChangeAbortController.abort(),this.elevationInfoChangeAbortController=null)}async elevationInfoChange(){this._abortElevationInfoChange();const e=new AbortController;this.elevationInfoChangeAbortController=e;const t=se(this.layer.elevationInfo,this.elevationFeatureExpressionEnabled);this.symbolCreationContext.featureExpressionInfoContext=await ae(t,this._spatialReference,je),f(e),this.elevationInfoChangeAbortController=null,this.labeler?.elevationInfoChange(),this.forEachGraphics3DSymbol(((e,t,i)=>{e.globalPropertyChanged("elevationInfo",t)?t.forEach((e=>{const t=e.graphic,i=e.labelGraphics;for(const r of i){r.graphics3DSymbolLayer.updateGraphicElevationContext(t,r)}})):this._recreateSymbol(i)})),this.updateStageLayerElevationProvider(),this.elevationAlignment?.elevationInfoChange()}updateStageLayerElevationProvider(){this.stageLayerElevationProvider?(this.layer.elevationInfo&&"relative-to-scene"===this.layer.elevationInfo.mode||0===this.numberOfGraphicsProvidingElevation)&&(this.owner.view.elevationProvider.unregister(this.stageLayerElevationProvider),this.stageLayerElevationProvider.dispose(),this.stageLayerElevationProvider=null):(!this.layer.elevationInfo||this.layer.elevationInfo&&"relative-to-scene"!==this.layer.elevationInfo.mode)&&this.numberOfGraphicsProvidingElevation>0&&(this.stageLayerElevationProvider=new fe({layer:this.layer,stageLayer:this.stageLayer,view:this.owner.view}),this.owner.view.elevationProvider.register("scene",this.stageLayerElevationProvider))}_clearSymbolsAndGraphics(){this.clear(),this.filterVisibility?.clear(),this.labeler?.reset(),this.deconflictor?.clear(),this.elevationAlignment?.clear(),this.stageLayer?.invalidateSpatialQueryAccelerator(),this.stageLayerElevationProvider&&(this.owner.view.elevationProvider.unregister(this.stageLayerElevationProvider),this.stageLayerElevationProvider.dispose(),this.stageLayerElevationProvider=null)}startCreateGraphics(){this._startCreateGraphics=!0,this.recreateAllGraphics()}recreateAllGraphics(){this._recreateAllGraphics(!1)}recreateAllGraphicsAndSymbols(){this._recreateAllGraphics(!0)}_recreateAllGraphics(e=!1){if(!this._startCreateGraphics)return;const{loadedGraphics:t,view:i}=this.owner,r=i.basemapTerrain.tilingScheme&&t&&t.length?t.toArray():null;!e&&r||this._clearSymbolsAndGraphics(),this.symbolCreationContext.screenSizePerspectiveEnabled=this.owner.view.screenSizePerspectiveEnabled&&this.layer.screenSizePerspectiveEnabled,this.symbolCreationContext.slicePlaneEnabled=!!this.owner.slicePlaneEnabled,this._set("computedExtent",null),r&&(e?this.add(r):this.recreateGraphics(r))}_recreateSymbol(e){const t=this.graphicsBySymbol.get(e),i=[];t&&(t.forEach(((e,t)=>{const r=e.usedMemory;this._conditionalRemove(e,t),this._spatialIndex?.remove(e),i.push(e.graphic),e.destroy(),this._removeGraphics3DGraphic(t,r),this._updateLayerVisibility(),this.featureStore.events.emit("changed")})),this.graphicsBySymbol.set(e,new Map));const r=this.symbols.get(e);m(r),this.symbols.delete(e),this.add(i)}_recreateGraphicsForSymbol(e){const t=this.graphicsBySymbol.get(e);if(t){const e=[];t.forEach((t=>e.push(t.graphic))),this.recreateGraphics(e)}}_conditionalRemove(e,t){this.graphicsDrapedUids.delete(t),this.objectStates?.removeGraphic(e),this.labeler?.removeGraphic(e),this.deconflictor?.removeGraphic(e),d(this.graphicStateTracking)&&this.graphicStateTracking.removeGraphic(e)}add(e){e&&0!==e.length&&(this.owner.view.basemapTerrain&&this.owner.view.basemapTerrain.tilingScheme?(this._updatePolicyForGraphics(e)===Se.ASYNC?this._addDelayed(e):this._addImmediate(e),this.notifyChange("updating")):je.error("#add()","Cannot add graphics before terrain surface has been initialized"))}_updatePolicyForGraphics(e){if(this.effectiveUpdatePolicy===Se.SYNC&&("mesh"===this.layer.geometryType||null==this.layer.geometryType))for(const t of e)if(d(t.geometry)&&"mesh"===t.geometry.type&&!t.geometry.loaded)return Se.ASYNC;return this.effectiveUpdatePolicy}_addImmediate(e){this.geometryWarningLogged=!1,this.symbolWarningLogged=!1;for(const t of e)this._addGraphic(t,this._getRenderingInfo(t,je),Se.SYNC);this._cleanupSymbols(),this.labeler&&(this.owner.view.labeler.setDirty(),this._cleanupSymbols()),this.owner.view.deconflictor.setDirty()}_addDelayed(e){for(const t of e){const e=t.uid;let i=this.pendingUpdates.get(e);i?i.add?i.state!==Fe.NEW&&i.abortController.abort():this.pendingAdds++:(i=this.pendingUpdatesPool.pushNew(),this.pendingAdds++,this.pendingUpdates.set(e,i)),i.add=t}this.notifyChange("running"),this.notifyChange("updatingRemaining")}remove(e){this.effectiveUpdatePolicy===Se.ASYNC?this._removeDelayed(e):this._removeImmediate(e),this.notifyChange("updating")}_removeImmediate(e){for(const t of e)this._removeGraphic(t);this._cleanupSymbols(),this.labeler&&this.owner.view.labeler.setDirty(),this.owner.view.deconflictor.setDirty()}_removeDelayed(e){for(const t of e){const e=t.uid,i=this.pendingUpdates.get(e);if(i)i.add&&(i.remove?i.add=null:this.pendingUpdates.delete(e),i.state===Fe.LOADING&&i.abortController.abort(),this.pendingAdds--);else{const i=this.pendingUpdatesPool.pushNew();i.remove=t,this.pendingUpdates.set(e,i),this.pendingRemoves++}}0===this.pendingUpdates.size&&this._finishPendingUpdates(),this.notifyChange("running"),this.notifyChange("updatingRemaining")}_finishPendingUpdates(){this.pendingUpdatesPool.clear(),this._cleanupSymbols(),(this.pendingAdds||this.pendingRemoves)&&je.warn("pendingAdds/Removes in inconsistent state!"),this.pendingAdds=0,this.pendingRemoves=0}_applyPendingUpdates(e){if(this.geometryWarningLogged=!1,this.symbolWarningLogged=!1,0===this.pendingUpdates.size&&this._spatialIndex?.updating)this._spatialIndex.update();else{for(const[t,i]of this.pendingUpdates){if(e.done)break;i.add&&i.state===Fe.NEW&&this._processPendingUpdateNew(i);let r=this.effectiveUpdatePolicy;if(!i.remove||i.add&&i.state!==Fe.READY||(this.pendingRemoves--,e.madeProgress(),this._removeGraphic(i.remove),i.remove=null,r=Se.SYNC),i.add)switch(i.state){case Fe.READY:this._addGraphic(i.add,i.renderingInfo,r),i.add=null,this.pendingAdds--,e.madeProgress();break;case Fe.REJECTED:i.add=null,this.pendingAdds--;case Fe.LOADING:}null==i.remove&&null==i.add&&this.pendingUpdates.delete(t)}0===this.pendingUpdates.size&&(this._finishPendingUpdates(),this.notifyChange("running"))}}_processPendingUpdateNew(e){if(!e.add)return void(e.state=Fe.READY);const t=e.add.geometry;d(t)&&"mesh"===t.type&&!t.loaded?this._processPendingUpdateNewMesh(e,t):this._processPendingUpdateNewRenderingInfo(e)}async _processPendingUpdateNewMesh(e,t){e.state=Fe.LOADING,e.abortController=new AbortController;const i=e.abortController.signal;try{await t.load({signal:i})}catch(r){return this._processPendingUpdateNewError(e,r)}e.abortController=null,this._processPendingUpdateNewRenderingInfo(e)}_processPendingUpdateNewError(e,t){e.abortController=null,S(t)?e.state=Fe.NEW:e.state=Fe.REJECTED}async _processPendingUpdateNewRenderingInfo(e){if(c(this.layer.renderer)||"dictionary"!==this.layer.renderer.type)return e.renderingInfo=this._getRenderingInfo(e.add,je),void(e.state=Fe.READY);e.state=Fe.LOADING,e.abortController=new AbortController;let t=null;try{t=await this._getRenderingInfoAsync(e.add,{signal:e.abortController.signal})}catch(i){return e.abortController=null,void(S(i)?e.state=Fe.NEW:e.state=Fe.REJECTED)}c(t)||c(t.symbol)?(je&&!this.symbolWarningLogged&&(this.symbolWarningLogged=!0,je.warn(`Graphic in layer ${this.layer.id} has no symbol and will not render`)),e.renderingInfo=null):e.renderingInfo=t,e.state=Fe.READY}_addGraphic(e,t,i){if(this.graphicsWithoutSymbol.set(e.uid,e),c(t)||c(t.symbol)||!$(e))return;const r=t.symbol,s=this.getOrCreateGraphics3DSymbol(r,t.renderer);if(c(s))return;this._expandComputedExtent(e.geometry);const a=this._beginGraphicUpdate(e),n=new oe(e,t,this.layer);let o=!1;const l=e=>{e===s.symbol.id&&(o=!0)};this._whenSymbolRemoved.push(l);const h=()=>{if(--this._loadingSymbols,this.destroyed)return;this._whenSymbolRemoved.removeUnordered(l);if(this.graphicsWaitingForSymbol.get(e.uid)!==a||o||s.destroyed||this.graphicSymbolSupported&&e.symbol&&e.symbol.id!==s.symbol.id)--s.referenced,this._cleanupSymbols();else{const t=this._createGraphics3DGraphic(s,n);this._spatialIndex&&d(t)&&this._spatialIndex.add(t),--s.referenced,this._endGraphicUpdate(e)}this.featureStore.events.emit("changed"),this.labeler&&this.owner.view.labeler.setDirty()},p=t=>{--this._loadingSymbols,this.destroyed||(this._whenSymbolRemoved.removeUnordered(l),o||(S(t)?this.add([e]):s.destroyed||this._endGraphicUpdate(e)))};++this._loadingSymbols,i===Se.ASYNC?s.load((()=>this._frameTask.schedule(h)),(e=>this._frameTask.schedule((()=>p(e))))):s.load(h,p)}_removeGraphic(e){const t=e.uid,i=this.graphics3DGraphics.get(t);if(i){i.graphics3DSymbol.onRemoveGraphic(i);const e=i.usedMemory,r=i.isElevationSource;this._conditionalRemove(i,t),this._spatialIndex?.remove(i);const s=i.graphics3DSymbol.symbol.id;this.graphicsBySymbol.get(s).delete(t),this.graphicsWithoutSymbol.delete(t),this._removeGraphics3DGraphic(t,e,r),i.destroy(),this.featureStore.events.emit("changed")}else this.graphicsWithoutSymbol.delete(t),this.graphicsWaitingForSymbol.delete(t),0===this.graphicsWaitingForSymbol.size&&(this._cleanupSymbols(),this.notifyChange("updating"))}_hasLabelingContext(e){if(e instanceof Ee||e instanceof Ie){const t=this.symbolCreationContext.layer;return!!t.labelingInfo&&t.labelingInfo.some((t=>t.symbol===e))}return!1}_hasValidSymbolCreationContext(e){return!(e instanceof Ee&&!this._hasLabelingContext(e))||(je.error("LabelSymbol3D is only valid as part of a LabelClass. Using LabelSymbol3D as a renderer symbol is not supported."),!1)}_getRenderingInfo(e,t){const i=e.geometry;if(c(i))return t&&!this.geometryWarningLogged&&(this.geometryWarningLogged=!0,t.warn(`Graphic in layer ${this.layer.id} has no geometry and will not render`)),null;if(!T(i.spatialReference,this._spatialReference))return t&&!this.geometryWarningLogged&&(this.geometryWarningLogged=!0,t.warn(`Graphic in layer ${this.layer.id} has incompatible spatial reference and will not render`)),null;if(!this.graphicSymbolSupported&&d(e.symbol))return t&&!this.symbolWarningLogged&&(this.symbolWarningLogged=!0,t.warn(`Graphic in layer ${this.layer.id} is not allowed to have a symbol, use a renderer instead`)),null;const r=this.rendererHasGeometryOperations?Z(e,this.layer):e;let s;if(this.owner.getRenderingInfo&&(this.getRenderingInfoWithoutRenderer||d(this.currentRenderer)))s=this.owner.getRenderingInfo(r,this.currentRenderer,u(this.arcadeOnDemand));else{s={symbol:r.symbol||X(r.geometry)}}return c(s)||c(s.symbol)?(t&&!this.symbolWarningLogged&&(this.symbolWarningLogged=!0,t.warn(`Graphic in layer ${this.layer.id} has no symbol and will not render`)),null):s}_getRenderingInfoAsync(e,t){const i=e.geometry;if(c(i))return je&&!this.geometryWarningLogged&&(this.geometryWarningLogged=!0,je.warn(`Graphic in layer ${this.layer.id} has no geometry and will not render`)),null;if(!this.graphicSymbolSupported&&d(e.symbol))return je&&!this.symbolWarningLogged&&(this.symbolWarningLogged=!0,je.warn(`Graphic in layer ${this.layer.id} is not allowed to have a symbol, use a renderer instead`)),null;const r=this.rendererHasGeometryOperations?Z(e,this.layer):e;return this.owner.getRenderingInfoAsync(r,u(this.currentRenderer),u(this.arcadeOnDemand),t)}_createGraphics3DSymbol(e,t){if(!this._hasValidSymbolCreationContext(e))return null;const i=this._getConvertedSymbol(e);if(!i)return null;let r;if(d(t)&&"backgroundFillSymbol"in t&&t.backgroundFillSymbol){const e=ee(t.backgroundFillSymbol,{ignoreDrivers:!0});d(e.symbol)&&"web-style"!==e.symbol.type&&"cim"!==e.symbol.type&&(r=e.symbol.symbolLayers)}const s=he(i,this.symbolCreationContext,r);return s.load((()=>{const e=s.extentPadding;e>this.extentPadding&&this._set("extentPadding",e),this.notifyChange("averageSymbolComplexity")}),(()=>{})),s}getOrCreateGraphics3DSymbol(e,t){let i=this.symbols.get(e.id);return void 0===i&&(i=e instanceof Ue?new de(e,(e=>this._frameTask.schedule(e)),(e=>this._createGraphics3DSymbol(e,t))):this._createGraphics3DSymbol(e,t),this.symbols.set(e.id,i)),d(i)&&++i.referenced,i}trackGraphicState(e){return c(this.graphicStateTracking)&&(this.graphicStateTracking=new pe(this)),this.graphicStateTracking.add(e)}_addGraphics3DGraphic(e){this._usedMemory+=e.usedMemory,this.graphics3DGraphics.set(e.graphic.uid,e),this.numberOfGraphics++,e.isElevationSource&&(this.numberOfGraphicsProvidingElevation++,this.updateStageLayerElevationProvider()),this._updateLayerVisibility()}_removeGraphics3DGraphic(e,t,i=!1){this._usedMemory-=t,this.graphics3DGraphics.delete(e),this.numberOfGraphics--,i&&(this.numberOfGraphicsProvidingElevation--,this.updateStageLayerElevationProvider()),this._updateLayerVisibility()}_createGraphics3DGraphic(e,t){const i=t.graphic;if(this.graphicsWithoutSymbol.delete(i.uid),!this.symbols.has(e.symbol.id))return this.add([i]),null;if(this.graphics3DGraphics.has(i.uid))return null;const r=e.createGraphics3DGraphic(t);if(c(r))return null;this._addGraphics3DGraphic(r);const s=e.symbol.id;this.graphicsBySymbol.has(s)||this.graphicsBySymbol.set(s,new Map),this.graphicsBySymbol.get(s).set(i.uid,r);r.isDraped&&this.graphicsDrapedUids.add(i.uid),r.centroid=null,d(i.geometry)&&"point"!==i.geometry.type&&(r.centroid=ce(i.geometry,this._spatialReference)),this._updateUserVisibility(r),d(this.scaleVisibility)&&this.scaleVisibility.updateVisibility(r),this.filterVisibility?.updateVisibility(r),this.deconflictor?.addGraphic(r),this.labeler?.addGraphic(r),this.objectStates?.addGraphic(r),this.deconflictor&&this.owner.view.deconflictor.setInitialIconVisibilityFlag(this,r),r.initialize(this.stage,this.stageLayer,this.owner),d(this.graphicStateTracking)&&this.graphicStateTracking.addGraphic(r);const a=this.whenGraphics3DGraphicRequests[i.uid];return a&&(delete this.whenGraphics3DGraphicRequests[i.uid],a.resolve(r)),r}_abortRendererChange(){this.rendererChangeAbortController&&(this.rendererChangeAbortController.abort(),this.rendererChangeAbortController=null)}async rendererChange(e){if(this._abortRendererChange(),e!==this.currentRenderer)if(this._validateRenderer(e),c(e)&&this._currentRendererChange(null,!1),J(e))if(d(e)&&e.arcadeRequired){const t=new AbortController;this.rendererChangeAbortController=t;const{arcadeUtils:i}=await this._ensureArcade();f(t),i.hasGeometryOperations(e)&&(await i.enableGeometryOperations(),f(t)),this.effectiveUpdatePolicy===Se.ASYNC?await this._frameTask.schedule((()=>this._currentRendererChange(e,!0)),t.signal):this._currentRendererChange(e,!0),this.rendererChangeAbortController=null}else if(this.effectiveUpdatePolicy===Se.ASYNC){const t=new AbortController;this.rendererChangeAbortController=t,await this._frameTask.schedule((()=>this._currentRendererChange(e,!1)),t.signal),this.rendererChangeAbortController=null}else this._currentRendererChange(e,!1);else this._currentRendererChange(e,!1)}async _ensureArcade(){return c(this.arcadeOnDemand)?(this.arcadeOnDemand=await K(),this.arcadeOnDemand):this.arcadeOnDemand}_currentRendererChange(e,t){this.currentRenderer=e,this.rendererHasGeometryOperations=t,this.symbolCreationContext.arcade=u(this.arcadeOnDemand);const i=this.symbolCreationContext.renderer;if(e===i)return;if(this.symbolConversionCache.clear(),c(e))return this.symbolCreationContext.renderer=null,void this.recreateAllGraphicsAndSymbols();const r=I(i,e);this._updateUnchangedSymbolMappings(r,e,i),this.symbolCreationContext.renderer=e,c(r)||("complete"===r.type?this.recreateAllGraphicsAndSymbols():"partial"===r.type&&(this._applyRendererDiff(r,e,i)?this._volatileGraphicsUpdated():this.recreateAllGraphicsAndSymbols()),this.notifyChange("averageSymbolComplexity"))}_diffHasSymbolChange(e){for(const t in e.diff)switch(t){case"visualVariables":case"defaultSymbol":case"uniqueValueInfos":break;case"authoringInfo":case"fieldDelimiter":delete e.diff[t];break;default:return!0}return!1}_applySymbolSetDiff(e,t,i){e=e||[],t=t||[];const r=[];for(const s of t){const t=this.graphicsBySymbol.get(s.id);t&&t.forEach(((a,n)=>{const o=a.graphic,l=this.layer instanceof q?this.layer:null,h=u(this.arcadeOnDemand);if(s===i.defaultSymbol&&i.getSymbol(Z(o,l),{arcade:h})===i.defaultSymbol)return;const d=a.usedMemory;e.length||i.defaultSymbol?r.push(o):this.graphicsWithoutSymbol.set(n,o);const p=this.graphics3DGraphics.get(n);this._conditionalRemove(p,n),a.destroy(),t.delete(n),this._removeGraphics3DGraphic(n,d),this._updateLayerVisibility()})),this._whenSymbolRemoved.forAll((e=>e(s.id)))}(e.length||r.length)&&(this.graphicsWithoutSymbol.forEach((e=>r.push(e))),this.graphicsWithoutSymbol.clear(),this.add(r)),this._cleanupSymbols(),this.labeler&&this.owner.view.labeler.setDirty(),this.owner.view.deconflictor.setDirty()}_applyUniqueValueRendererDiff(e,t,i){const r=e.diff.defaultSymbol,s=e.diff.uniqueValueInfos;if(r||s){const a=s?s.added.map((e=>e.symbol)):[],n=s?s.removed.map((e=>e.symbol)):[];if(s)for(let e=0;e<s.changed.length;e++)a.push(s.changed[e].newValue.symbol),n.push(s.changed[e].oldValue.symbol);return r?(i.defaultSymbol&&n.push(i.defaultSymbol),t.defaultSymbol&&a.push(t.defaultSymbol)):i.defaultSymbol&&a.length&&n.push(t.defaultSymbol),this._applySymbolSetDiff(a,n,t),delete e.diff.defaultSymbol,delete e.diff.uniqueValueInfos,!0}return!1}_calculateUnchangedSymbolMapping(e,t,i){if("unique-value"!==t?.type||"unique-value"!==i?.type||d(e)&&"partial"!==e.type)return[];const r=e=>d(e)?e.id:null,s=e&&e.diff,a=s&&s.defaultSymbol,n=s&&s.uniqueValueInfos;let o;if(n)o=n.unchanged.map((e=>({oldId:r(e.oldValue.symbol),newId:r(e.newValue.symbol)})));else{o=[];for(const e of i.uniqueValueInfos){const i=r(e.symbol),s=t.uniqueValueInfos.find((t=>t.value===e.value));s&&i!==r(s.symbol)&&o.push({oldId:i,newId:r(s.symbol)})}}return!a&&i.defaultSymbol&&o.push({oldId:r(i.defaultSymbol),newId:r(t.defaultSymbol)}),o}_updateSymbolMapping(e,t){const i=d(t)&&t?"string"==typeof t?t:t.id:null;if(!e||e===i)return;const r=this.graphicsBySymbol.get(e);this.graphicsBySymbol.delete(e),void 0!==r&&this.graphicsBySymbol.set(i,r);const s=this.symbols.get(e);if(void 0!==s&&(this.symbols.delete(e),this.symbols.set(i,s),d(s))){const e="string"==typeof t?null:t;d(e)?s.symbol=e:s.symbol.id=i}}_updateUnchangedSymbolMappings(e,t,i){const r=this._calculateUnchangedSymbolMapping(e,t,i);for(const{oldId:s,newId:a}of r)this._updateSymbolMapping(s,a)}_applyRendererDiff(e,i,r){if(this._diffHasSymbolChange(e))return!1;if(i instanceof t&&r instanceof t&&this._applyUniqueValueRendererDiff(e,i,r)&&0===Object.keys(e.diff).length)return!0;for(const[t]of this.graphicsBySymbol){const r=this.symbols.get(t);if(d(r))switch(r.applyRendererDiff(e,i)){case ye.Recreate_Symbol:this._recreateSymbol(t);break;case ye.Recreate_Graphics:this._recreateGraphicsForSymbol(t);case ye.Fast_Update:}}return!0}opacityChange(){this.forEachGraphics3DSymbol(((e,t)=>e.globalPropertyChanged("opacity",t))),this._updateStageLayerVisibility()}_slicePlaneEnabledChange(e){e!==this.symbolCreationContext.slicePlaneEnabled&&(this.symbolCreationContext.slicePlaneEnabled=e,this.stageLayer.isSliceable=e,this.forEachGraphics3DSymbol(((e,t)=>e.globalPropertyChanged("slicePlaneEnabled",t))),this.deconflictor&&this.deconflictor.slicePlaneEnabledChange(),this.labeler&&this.labeler.slicePlaneEnabledChange())}_physicalBasedRenderingChange(e){e!==this.symbolCreationContext.physicalBasedRenderingEnabled&&(this.symbolCreationContext.physicalBasedRenderingEnabled=e,this.forEachGraphics3DSymbol(((e,t,i)=>{e.globalPropertyChanged("physicalBasedRenderingEnabled",t)||this._recreateSymbol(i)})))}_pixelRatioChange(){this.forEachGraphics3DSymbol(((e,t,i)=>{e.globalPropertyChanged("pixelRatio",t)||this._recreateSymbol(i)}))}_signalUpdatingDuringAsyncLoadedGraphicsChange(){this._updatingPendingLoadedGraphicsChange&&this._updatingPendingLoadedGraphicsChange.remove(),this._updatingPendingLoadedGraphicsChange=P((()=>{this._updatingPendingLoadedGraphicsChange=null}))}setClippingExtent(e,t){const i=this.symbolCreationContext.clippingExtent,r=B();return ve(e,r,t)?this.symbolCreationContext.clippingExtent=N(M(),r):this.symbolCreationContext.clippingExtent=null,!z(this.symbolCreationContext.clippingExtent,i)}modifyGraphics3DGraphicVisibilities(e){let t=!1;this.graphics3DGraphics.forEach((i=>{e(i)&&(t=!0)})),t&&(this.labeler&&this.owner.view.labeler.setDirty(),this.owner.view.deconflictor.setDirty())}forEachGraphics3DSymbol(e){for(const[t,i]of this.symbols){if(c(i))return;e(i,this.graphicsBySymbol.get(t)||Ne,t)}}updateAllGraphicsVisibility(){this.filterVisibility&&(this.filterVisibility.dirty=!0),this.modifyGraphics3DGraphicVisibilities((e=>{const t=this._updateUserVisibility(e),i=d(this.scaleVisibility)&&this.scaleVisibility.updateVisibility(e);return t||i}))}_hideAllGraphics(){this.modifyGraphics3DGraphicVisibilities((e=>e.setVisibilityFlag(ie.USER_SETTING,!1,re.GRAPHIC)))}_validateRenderer(e){const t=Q(e);if(t){const e=`Renderer for layer '${this.layer.title?`${this.layer.title}, `:""}, id:${this.layer.id}' is not supported in a SceneView`;je.warn(e,t.message)}}_volatileGraphicsUpdated(){this.labeler?.reset(),this.stageLayer.shaderTransformationChanged(),this.notifyChange("updating")}_cleanupSymbols(){if(this.graphicsWaitingForSymbol.size>0||this.suspendSymbolCleanup)return;let e=!1;this.symbols.forEach(((t,i)=>{if(c(t)||t.referenced>0)return;const r=this.graphicsBySymbol.get(i);r&&0!==r.size||(this.graphicsBySymbol.delete(i),this.symbols.delete(i),m(t),e=!0)})),e&&(this._recomputeExtentPadding(),this.notifyChange("averageSymbolComplexity"))}get test(){return{snapshotInternals:()=>({graphics:[...this.graphics3DGraphics.keys()].sort(),symbols:[...this.symbols.keys()].sort(),graphicsBySymbol:[...this.graphicsBySymbol.keys()].sort().map((e=>({symbolId:e,graphics:[...this.graphicsBySymbol.get(e).keys()].sort()}))),graphicsWithoutSymbol:[...this.graphicsWithoutSymbol.keys()].sort(),graphicsDrapedUids:[...this.graphicsDrapedUids].sort(),pendingUpdates:this.pendingUpdates}),symbols:this.symbols,filterVisibility:this.filterVisibility,numPending:this.pendingUpdates.size,forceUpdatePolicy:e=>{this.forcedUpdatePolicy=e}}}get performanceInfo(){return{visible:this.graphics3DGraphics.size,missing:this.graphicsWithoutSymbol.size,pending:this.pendingUpdates.size}}};var Fe;Ve.tmpVec=j(),e([D({readOnly:!0})],Ve.prototype,"computedExtent",void 0),e([D()],Ve.prototype,"currentRenderer",void 0),e([D()],Ve.prototype,"rendererHasGeometryOperations",void 0),e([D()],Ve.prototype,"_frameTask",void 0),e([D()],Ve.prototype,"rendererChangeAbortController",void 0),e([D()],Ve.prototype,"elevationInfoChangeAbortController",void 0),e([D()],Ve.prototype,"setupAbortController",void 0),e([D({readOnly:!0})],Ve.prototype,"elevationAlignment",void 0),e([D({readOnly:!0})],Ve.prototype,"scaleVisibility",void 0),e([D({readOnly:!0})],Ve.prototype,"filterVisibility",void 0),e([D()],Ve.prototype,"_spatialIndex",void 0),e([D({readOnly:!0})],Ve.prototype,"extentPadding",void 0),e([D()],Ve.prototype,"_updatingPendingLoadedGraphicsChange",void 0),e([D({readOnly:!0})],Ve.prototype,"featureStore",void 0),e([D({readOnly:!0})],Ve.prototype,"deconflictor",void 0),e([D({readOnly:!0})],Ve.prototype,"labeler",void 0),e([D({readOnly:!0})],Ve.prototype,"objectStates",void 0),e([D()],Ve.prototype,"_loadingSymbols",void 0),e([D()],Ve.prototype,"preferredUpdatePolicy",void 0),e([D()],Ve.prototype,"forcedUpdatePolicy",void 0),e([D({readOnly:!0})],Ve.prototype,"effectiveUpdatePolicy",null),e([D({constructOnly:!0})],Ve.prototype,"elevationFeatureExpressionEnabled",void 0),e([D({constructOnly:!0})],Ve.prototype,"owner",void 0),e([D({constructOnly:!0})],Ve.prototype,"layer",void 0),e([D({constructOnly:!0})],Ve.prototype,"graphicSymbolSupported",void 0),e([D({constructOnly:!0})],Ve.prototype,"getRenderingInfoWithoutRenderer",void 0),e([D({readOnly:!0})],Ve.prototype,"updating",null),e([D({readOnly:!0})],Ve.prototype,"running",null),e([D({readOnly:!0})],Ve.prototype,"suspendedOrOutsideOfView",null),e([D({readOnly:!0,dependsOn:[]})],Ve.prototype,"updatingRemaining",null),e([D({readOnly:!0,dependsOn:["owner.view.qualitySettings.graphics3D.maxTotalNumberOfPrimitives","owner.view.qualitySettings.graphics3D.maxTotalNumberOfFeatures","averageSymbolComplexity"]})],Ve.prototype,"displayFeatureLimit",null),e([D({readOnly:!0,dependsOn:[]})],Ve.prototype,"averageSymbolComplexity",null),e([D({constructOnly:!0})],Ve.prototype,"hasZ",void 0),e([D({constructOnly:!0})],Ve.prototype,"hasM",void 0),Ve=Oe=e([E("esri.views.3d.layers.graphics.Graphics3DCore")],Ve),function(e){e[e.NEW=0]="NEW",e[e.LOADING=1]="LOADING",e[e.READY=2]="READY",e[e.REJECTED=3]="REJECTED"}(Fe||(Fe={}));class Te{constructor(){this.add=null,this.renderingInfo=null,this.state=Fe.NEW,this.remove=null}clear(){this.add=null,this.renderingInfo=null,this.state=Fe.NEW,this.abortController=null,this.remove=null}}const ke=10,Me=j(),We=j(),Ne=new Map;export{Ve as Graphics3DCore};
|
|
5
|
+
import{_ as e}from"../../../../chunks/tslib.es6.js";import"../../../../geometry.js";import"../../../../renderers/ClassBreaksRenderer.js";import"../../../../renderers/DictionaryRenderer.js";import"../../../../renderers/DotDensityRenderer.js";import"../../../../renderers/HeatmapRenderer.js";import"../../../../renderers/PieChartRenderer.js";import"../../../../renderers/Renderer.js";import"../../../../renderers/SimpleRenderer.js";import t from"../../../../renderers/UniqueValueRenderer.js";import"../../../../renderers/support/jsonUtils.js";import"../../../../symbols.js";import i from"../../../../core/Accessor.js";import"../../../../core/has.js";import r from"../../../../core/Error.js";import s from"../../../../core/Handles.js";import{makeHandle as a}from"../../../../core/handleUtils.js";import{equalsShallow as n}from"../../../../core/lang.js";import o from"../../../../core/Logger.js";import{someMap as l,findInMap as h}from"../../../../core/MapUtils.js";import{isSome as d,unwrapOr as p,isNone as c,removeMaybe as y,destroyMaybe as m,get as g,unwrap as u}from"../../../../core/maybe.js";import b from"../../../../core/PooledArray.js";import{throwIfAborted as f,eachAlways as v,createDeferred as C,isAbortError as S}from"../../../../core/promiseUtils.js";import{watch as _,when as G,on as w,syncAndInitial as x,whenOnce as R}from"../../../../core/reactiveUtils.js";import{schedule as P}from"../../../../core/scheduling.js";import{property as D}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import{subclass as E}from"../../../../core/accessorSupport/decorators/subclass.js";import{diff as I,isEmpty as U}from"../../../../core/accessorSupport/diffUtils.js";import{s as O,a as A,g as L}from"../../../../chunks/vec3.js";import{c as j}from"../../../../chunks/vec3f64.js";import{projectVectorToVector as V,projectXYZToVector as F,canProjectWithoutEngine as T,projectBuffer as k}from"../../../../geometry/projection.js";import{create as M,center as W,fromRect as N,equals as z}from"../../../../geometry/support/aaBoundingBox.js";import{create as B}from"../../../../geometry/support/aaBoundingRect.js";import q from"../../../../layers/Layer.js";import{getObjectId as H,computeAABB as Y,hasGeometry as $}from"../../../../layers/graphics/dehydratedFeatures.js";import{hydrateGraphic as Z}from"../../../../layers/graphics/hydratedFeatures.js";import{isSupportedRenderer3D as J,validateTo3D as Q}from"../../../../renderers/support/rendererConversion.js";import{loadArcade as K}from"../../../../support/arcadeOnDemand.js";import{getDefaultSymbol3D as X}from"../../../../symbols/support/defaults3D.js";import{to3D as ee}from"../../../../symbols/support/symbolConversion.js";import{ViewElevationProvider as te}from"./ElevationQuery.js";import{VisibilityFlag as ie,VisibilityGroup as re}from"./enums.js";import{extractExpressionInfo as se,createContext as ae}from"./featureExpressionInfoUtils.js";import{Graphics3DFeatureStore as ne}from"./Graphics3DFeatureStore.js";import oe from"./Graphics3DGraphicCreationContext.js";import{Graphics3DSymbolCreationContext as le}from"./Graphics3DSymbolCreationContext.js";import{make as he}from"./Graphics3DSymbolFactory.js";import de from"./Graphics3DWebStyleSymbol.js";import{GraphicStateTracking as pe}from"./GraphicStateTracking.js";import{computeCentroid as ce}from"./graphicUtils.js";import{ApplyRendererDiffResult as ye}from"./interfaces.js";import{LoadStatus as me}from"./Loadable.js";import{SpatialIndex2D as ge}from"./SpatialIndex2D.js";import{averageSymbolComplexities as ue,defaultSymbolComplexity as be}from"./symbolComplexity.js";import{StageLayerElevationProvider as fe}from"../support/StageLayerElevationProvider.js";import{toBoundingRect as ve}from"../../support/extentUtils.js";import{PropertiesPool as Ce}from"../../support/PropertiesPool.js";import{UpdatePolicy as Se}from"../../webgl-engine/lib/basicInterfaces.js";import{GridLocalOriginFactory as _e}from"../../webgl-engine/lib/GridLocalOriginFactory.js";import{WebGLLayer as Ge}from"../../webgl-engine/lib/WebGLLayer.js";import{ImmediateTask as we,noBudget as xe,TaskPriority as Re}from"../../../support/Scheduler.js";import Pe from"../../../../geometry/Extent.js";import De from"../../../../geometry/Point.js";import Ee from"../../../../symbols/LabelSymbol3D.js";import Ie from"../../../../symbols/TextSymbol.js";import Ue from"../../../../symbols/WebStyleSymbol.js";var Oe;const Ae=j(),Le=M(),je=o.getLogger("esri.views.3d.layers.graphics.Graphics3DCore");let Ve=Oe=class extends i{constructor(e){super(e),this.propertiesPool=new Ce({computedExtent:Pe},this),this.computedExtent=null,this.currentRenderer=null,this.rendererHasGeometryOperations=!1,this.graphicStateTracking=null,this.symbolCreationContext=new le(((e,t)=>this._frameTask.schedule(e,t))),this.graphics3DGraphics=new Map,this.stageLayer=null,this.stage=null,this.graphicsDrapedUids=new Set,this.graphicsBySymbol=new Map,this.symbolConversionCache=new Map,this.symbols=new Map,this.graphicsWithoutSymbol=new Map,this.graphicsWaitingForSymbol=new Map,this.graphicsUpdateId=0,this._handles=new s,this._frameTask=we,this.suspendSymbolCleanup=!1,this._spatialReference=null,this.arcadeOnDemand=null,this.rendererChangeAbortController=null,this.elevationInfoChangeAbortController=null,this.setupAbortController=null,this.elevationAlignment=null,this.scaleVisibility=null,this.filterVisibility=null,this._spatialIndex=null,this.extentPadding=0,this._updatingPendingLoadedGraphicsChange=null,this.featureStore=null,this.deconflictor=null,this.labeler=null,this.objectStates=null,this.viewElevationProvider=null,this.stageLayerElevationProvider=null,this.sharedSymbolResourcesOwnerHandle=null,this.whenGraphics3DGraphicRequests={},this.pendingUpdates=new Map,this.numberOfGraphics=0,this.numberOfGraphicsProvidingElevation=0,this.pendingAdds=0,this.pendingRemoves=0,this._loadingSymbols=0,this.pendingUpdatesPool=new b({allocator:e=>e||new Te,deallocator:e=>(e.clear(),e)}),this.symbolWarningLogged=!1,this.geometryWarningLogged=!1,this.objectIdInvisibleSet=new Set,this._whenSymbolRemoved=new b,this.preferredUpdatePolicy=Se.SYNC,this.forcedUpdatePolicy=null,this.elevationFeatureExpressionEnabled=!0,this.owner=null,this.layer=null,this.graphicSymbolSupported=!0,this.getRenderingInfoWithoutRenderer=!1,this.hasZ=null,this.hasM=null,this._usedMemory=0,this._visible=void 0,this._startCreateGraphics=!1}get spatialIndex(){return this._spatialIndex||(this._spatialIndex=new ge({objectIdField:this.owner.layer?.objectIdField,spatialReference:this._spatialReference,hasZ:this.hasZ,hasM:this.hasM}),this._spatialIndex.setup(Array.from(this.graphics3DGraphics.values()))),this._spatialIndex.update(),this._spatialIndex}get effectiveUpdatePolicy(){return d(this.currentRenderer)&&"dictionary"===this.currentRenderer.type?Se.ASYNC:p(this.forcedUpdatePolicy,this.preferredUpdatePolicy)}get updating(){return!!(this.graphicsWaitingForSymbol.size>0||this.running||this.elevationAlignment?.updating||d(this.scaleVisibility)&&this.scaleVisibility.updating||this.filterVisibility?.updating||this.rendererChangeAbortController||this.elevationInfoChangeAbortController||this._updatingPendingLoadedGraphicsChange||this._frameTask.updating||this._loadingSymbols>0)}get running(){return this.pendingUpdates.size>0||!!this._spatialIndex?.updating}get suspendedOrOutsideOfView(){return this.owner.suspended||this.owner.suspendInfo?.outsideOfView}get updatingRemaining(){return this.updating?this.pendingUpdates.size+.1*(this._spatialIndex?.updatingRemaining||0)+.1*(this.elevationAlignment?.updatingRemaining||0):0}get displayFeatureLimit(){const e=this.owner&&this.owner.view&&this.owner.view.qualitySettings,t=e?e.graphics3D.minTotalNumberOfFeatures:0,i=e?e.graphics3D.maxTotalNumberOfFeatures:0,r=e?e.graphics3D.maxTotalNumberOfPrimitives:0,s=this.averageSymbolComplexity,a=Math.max(1,d(s)?s.primitivesPerFeature:1),n=d(s)&&s.drawCallsPerFeature>0?i/s.drawCallsPerFeature*.3:i,o=Math.ceil(r/a),l=Math.max(t,Math.min(i,o,n)),h=this._get("displayFeatureLimit");return h&&h.minimumTotalNumberOfFeatures===t&&h.maximumTotalNumberOfFeatures===i&&h.maximumTotalNumberOfPrimitives===r&&h.averageSymbolComplexity===s&&h.maximumNumberOfFeatures===l?h:{minimumTotalNumberOfFeatures:t,maximumTotalNumberOfFeatures:i,maximumTotalNumberOfPrimitives:r,averageSymbolComplexity:s,maximumNumberOfFeatures:l}}get averageSymbolComplexity(){const e=ue(this.symbolComplexities),t=this._get("averageSymbolComplexity");return 0===e.numComplexities||d(t)&&(e.estimated&&(t.primitivesPerFeature>=e.primitivesPerFeature||t.primitivesPerCoordinate>=e.primitivesPerCoordinate||t.drawCallsPerFeature>=e.drawCallsPerFeature)||t.primitivesPerFeature===e.primitivesPerFeature&&t.primitivesPerCoordinate===e.primitivesPerCoordinate&&t.drawCallsPerFeature===e.drawCallsPerFeature)?t:e}get spatialReference(){return this._spatialReference}get usedMemory(){const e=d(this.averageSymbolComplexity)&&this.labelsEnabled?this.averageSymbolComplexity.memory.bytesPerFeatureLabel*this.numberOfGraphics:0;return this._usedMemory+e}get usedMemoryPerGraphic(){if(this._usedMemory&&this.numberOfGraphics)return Math.abs(this.pendingAdds-this.pendingRemoves)/this.numberOfGraphics>30?0:this._usedMemory/this.numberOfGraphics;if(d(this.averageSymbolComplexity)){const e=this.labelsEnabled?this.averageSymbolComplexity.memory.bytesPerFeatureLabel:0;return this.averageSymbolComplexity.memory.bytesPerFeature+e}return 0}get unprocessedMemoryEstimate(){return Math.max(0,(this.pendingAdds-this.pendingRemoves)*this.usedMemoryPerGraphic)}get symbolComplexities(){return this.currentRenderer?this._getSymbolComplexitiesUsedOrRenderer(this.currentRenderer):this._getSymbolComplexitiesUsed()}_getConvertedSymbol(e){if("web-style"===e.type)return e.clone();const t=this.symbolConversionCache.get(e.id);if(d(t))return t;const i=ee(e,{retainId:!0,hasLabelingContext:this._hasLabelingContext(e)}),r=i.symbol||null;return c(r)&&i.error&&je.error(i.error.message),this.symbolConversionCache.set(e.id,r),r}_getSymbolComplexitiesUsedOrRenderer(e){if(c(e))return[];const t=e.getSymbols(),i="backgroundFillSymbol"in e&&e.backgroundFillSymbol;if(!(i||t&&t.length))return[];const r=[],s=this._getSymbolComplexityUsedOrRenderer(i);d(s)&&r.push(s);for(const a of t){const e=this._getSymbolComplexityUsedOrRenderer(a);d(e)&&r.push(e)}return r}_getSymbolComplexityUsedOrRenderer(e){if(c(e))return null;const t=this.symbols.get(e.id);if(d(t))return t.complexity;const i=this._getConvertedSymbol(e);return d(i)?be(i):null}_getSymbolComplexitiesUsed(){const e=[];return this.symbols.forEach((t=>{d(t)&&e.push(t.complexity)})),e}initialize(){this._spatialReference=this.owner.view.spatialReference,this._set("featureStore",new ne({objectIdField:this.owner.layer&&this.owner.layer.objectIdField,hasZ:this.hasZ,hasM:this.hasM,spatialReference:this._spatialReference,featureSpatialReference:this.owner.featureSpatialReference,getSpatialIndex:()=>this.spatialIndex,forAllGraphics:e=>this.graphics3DGraphics.forEach(e)}))}async setup(e){this.setupAbortController=new AbortController;const t=this.setupAbortController.signal;this._set("elevationAlignment",e.elevationAlignment),this._set("scaleVisibility",e.scaleVisibility),this._set("filterVisibility",e.filterVisibility),this._set("deconflictor",e.deconflictor),this._set("labeler",e.labeler),this._set("objectStates",e.objectStates);const i=this.owner.view;this.viewElevationProvider=new te(this._spatialReference,i),this._initializeStage(i,this.layer.uid),this.symbolCreationContext.sharedResources=i.sharedSymbolResources,this.sharedSymbolResourcesOwnerHandle=i.sharedSymbolResources.addGraphicsOwner(this.owner),d(this.currentRenderer)&&(this.symbolCreationContext.renderer=this.currentRenderer),this.symbolCreationContext.stage=this.stage,this.symbolCreationContext.streamDataRequester=i.sharedSymbolResources.streamDataRequester,this.symbolCreationContext.renderCoordsHelper=i.renderCoordsHelper,this.symbolCreationContext.layer=this.layer,this.symbolCreationContext.graphicsCoreOwner=this.owner,this.symbolCreationContext.localOriginFactory=new _e(i.renderSpatialReference),this.symbolCreationContext.elevationProvider=i.elevationProvider,this.symbolCreationContext.notifyGraphicGeometryChanged=e=>this.notifyGraphicGeometryChanged(e),this.symbolCreationContext.notifyGraphicVisibilityChanged=e=>this.notifyGraphicVisibilityChanged(e);const r=se(this.layer.elevationInfo,this.elevationFeatureExpressionEnabled);if(this.symbolCreationContext.featureExpressionInfoContext=await ae(r,this._spatialReference,je),f(t),this.symbolCreationContext.screenSizePerspectiveEnabled=i.screenSizePerspectiveEnabled&&this.layer.screenSizePerspectiveEnabled,this.symbolCreationContext.slicePlaneEnabled=!!this.owner.slicePlaneEnabled,this.symbolCreationContext.physicalBasedRenderingEnabled=!!this.owner.view.qualitySettings.physicallyBasedRenderingEnabled,"drapeSourceType"in this.owner){const{owner:e}=this;this.symbolCreationContext.drapeSourceRenderer=i.basemapTerrain.overlayManager.registerGeometryDrapeSource(e),this._handles.add(a((()=>i.basemapTerrain.overlayManager.unregisterDrapeSource(e))))}this._handles.add([_((()=>this.suspendedOrOutsideOfView),(()=>this._frameTask.reschedule((()=>this._updateLayerVisibility())))),_((()=>[this.layer?.screenSizePerspectiveEnabled,this.owner.view.screenSizePerspectiveEnabled]),(()=>{const e=i.screenSizePerspectiveEnabled&&this.layer.screenSizePerspectiveEnabled;e!==this.symbolCreationContext.screenSizePerspectiveEnabled&&(this.symbolCreationContext.screenSizePerspectiveEnabled=e,this.labeler?.reset(),this.recreateAllGraphicsAndSymbols())}),{equals:n}),_((()=>this.owner.slicePlaneEnabled),(e=>this._slicePlaneEnabledChange(!!e))),_((()=>this.owner.view.state?.pixelRatio),(()=>this._pixelRatioChange())),_((()=>this.owner.view.qualitySettings?.physicallyBasedRenderingEnabled),(e=>this._physicalBasedRenderingChange(e))),G((()=>i.basemapTerrain?.tilingScheme),(e=>{if(e.spatialReference.equals(this.symbolCreationContext.overlaySR)||(this.symbolCreationContext.overlaySR=i.basemapTerrain.spatialReference),this._handles.has("loaded-graphics"))this.recreateAllGraphics();else{const e=()=>this.owner?.loadedGraphics;this._handles.add([w(e,"change",(e=>{this._graphicsCollectionChanged(e),this._signalUpdatingDuringAsyncLoadedGraphicsChange()}),{onListenerAdd:()=>{this.recreateAllGraphics(),this._signalUpdatingDuringAsyncLoadedGraphicsChange()}})],"loaded-graphics")}}),{initial:!0}),_((()=>this.effectiveUpdatePolicy),(e=>{d(this.stageLayer)&&(this.stageLayer.updatePolicy=e),this.symbolCreationContext.isAsync=this.effectiveUpdatePolicy===Se.ASYNC,e===Se.SYNC&&this.runTask(xe)}),x)]),this._frameTask=i.resourceController.scheduler.registerTask(Re.GRAPHICS_CORE,this),this.layer&&"featureReduction"in this.layer&&this._handles.add(_((()=>this.layer.featureReduction),(()=>this.deconflictor.featureReductionChange()))),this.notifyChange("averageSymbolComplexity");try{await this.rendererChange(this.layer.renderer)}catch{}f(t),this.setupAbortController=null}_abortSetup(){this.setupAbortController&&(this.setupAbortController.abort(),this.setupAbortController=null)}destroy(){this._abortSetup(),this._abortRendererChange(),this._abortElevationInfoChange(),this.owner.view.deconflictor.removeGraphicsOwner(this),this.owner.view.labeler.removeGraphicsOwner(this),this._updatingPendingLoadedGraphicsChange=y(this._updatingPendingLoadedGraphicsChange),this.clear(),this.graphicStateTracking=m(this.graphicStateTracking),this.stage&&(this.stage.remove(this.stageLayer),this.stageLayer=null,this.stage=null),this._handles=m(this._handles),this._frameTask.remove(),this._frameTask=we,this._spatialReference=null,this._set("owner",null);for(const e in this.whenGraphics3DGraphicRequests)this.whenGraphics3DGraphicRequests[e].reject(new r("graphic:layer-destroyed","Layer has been destroyed"));this.whenGraphics3DGraphicRequests=null,this.sharedSymbolResourcesOwnerHandle=y(this.sharedSymbolResourcesOwnerHandle),this.propertiesPool=m(this.propertiesPool),this.pendingUpdatesPool=null,this.symbolConversionCache.clear(),this.objectIdInvisibleSet.clear(),this._spatialIndex=m(this._spatialIndex),this._set("featureStore",m(this.featureStore))}clear(){this.objectStates?.allGraphicsDeleted(),d(this.graphicStateTracking)&&this.graphicStateTracking.allGraphicsDeleted(),this.graphics3DGraphics.forEach((e=>e.destroy())),this._spatialIndex?.clear(),this.graphics3DGraphics.clear(),this.numberOfGraphics=0,this._usedMemory=0,this._updateLayerVisibility(),this.symbols.forEach(m),this.symbols.clear(),this.graphicsBySymbol.clear(),this.graphicsWithoutSymbol.clear(),this.graphicsWaitingForSymbol.clear(),this.pendingUpdates.clear(),this.pendingUpdatesPool.clear(),this.pendingAdds=0,this.pendingRemoves=0,this.notifyChange("updating"),this.notifyChange("running"),this.notifyChange("updatingRemaining"),this.featureStore.events.emit("changed")}_initializeStage(e,t){this.stage=e._stage,this.stageLayer=new Ge({isPickable:!this.suspendedOrOutsideOfView,updatePolicy:this.effectiveUpdatePolicy},t),this.stage.add(this.stageLayer);const i=this.stageLayer.events;i.on("objectTransformation",(e=>this.notifyGraphicGeometryChanged(e.metadata.graphicUid))),i.on("visibilityChanged",(e=>this.notifyGraphicVisibilityChanged(e.metadata.graphicUid))),i.on("objectGeometryAdded",(e=>this.notifyGraphicGeometryChanged(e.object.metadata.graphicUid))),i.on("objectGeometryRemoved",(e=>this.notifyGraphicGeometryChanged(e.object.metadata.graphicUid))),i.on("vertexAttrsUpdated",(e=>this.notifyGraphicGeometryChanged(e.object.metadata.graphicUid)))}notifyGraphicGeometryChanged(e){if(c(this.graphicStateTracking)||c(e))return;const t=this.graphics3DGraphics.get(e);t&&this.graphicStateTracking.updateGraphicGeometry(t)}notifyGraphicVisibilityChanged(e){if(c(this.graphicStateTracking)||c(e))return;const t=this.graphics3DGraphics.get(e);t&&this.graphicStateTracking.updateGraphicVisibility(t)}_updateLayerVisibility(){const e=this.displayFeatureLimit.maximumNumberOfFeatures,t=this.numberOfGraphics>e*ke,i=!this.suspendedOrOutsideOfView&&!t;i!==this._visible&&(this._visible=i,i?(this.stageLayer.isPickable=!0,this.updateAllGraphicsVisibility()):(this.stageLayer.isPickable=!1,this._hideAllGraphics()),this._updateStageLayerVisibility())}_updateStageLayerVisibility(){this.stageLayer.isVisible=this._visible&&(null==this.layer.opacity||this.layer.opacity>0)}getGraphics3DGraphicById(e){return this.graphics3DGraphics.get(e)}getGraphics3DGraphicByObjectId(e){return this.owner.layer?.objectIdField?this._findGraphics3DGraphicByObjectId(e):null}_getGraphicObjectID(e,t=this.owner.layer&&this.owner.layer.objectIdField){return H(e,t)}get graphics3DGraphicsByObjectID(){const e=this.owner.layer&&this.owner.layer.objectIdField;if(!e)return null;const t=new Map;return this.graphics3DGraphics.forEach((i=>{if(!i)return;const r=i.graphic,s=this._getGraphicObjectID(r,e);d(s)&&t.set(s,i)})),t}get labelsEnabled(){return!(!this.labeler||!this.labeler.layerLabelsEnabled())}async updateLabelingInfo(e){const t=this.deconflictor&&this.deconflictor.labelingInfoChange(e),i=this.labeler&&this.labeler.labelingInfoChange(e);await v([t,i])}updateVisibilityInfo(){this.deconflictor&&this.deconflictor.labelingInfoChange(),this.labeler&&this.labeler.visibilityInfoChange()}get symbolUpdateType(){if(this.pendingUpdates.size>0)return"unknown";let e=0,t=0;return l(this.symbols,((i,r)=>{if(d(i)){const s=i.getFastUpdateStatus();if(s.loading>0)return!0;this.graphicsBySymbol.has(r)&&(t+=s.fast,e+=s.slow)}return!1}))?"unknown":t>=0&&0===e?"fast":e>=0&&0===t?"slow":"mixed"}runTask(e){this._frameTask.processQueue(e),this._applyPendingUpdates(e),this.notifyChange("running"),this.running||this.notifyChange("updating"),this.notifyChange("updatingRemaining")}setObjectIdVisibility(e,t){t?this.objectIdInvisibleSet.delete(e):this.objectIdInvisibleSet.add(e);const i=this._findGraphics3DGraphicByObjectId(e);d(i)&&this._updateUserVisibility(i)}_findGraphics3DGraphicByObjectId(e){return h(this.graphics3DGraphics,(t=>this._getGraphicObjectID(t.graphic)===e))}_updateUserVisibility(e){if(c(e))return!1;const t=e.graphic,i=this._getGraphicObjectID(t),r=t.visible&&!this.owner.suspended&&(c(i)||!this.objectIdInvisibleSet.has(i));return e.setVisibilityFlag(ie.USER_SETTING,r,re.GRAPHIC)}_whenGraphics3DGraphic(e){const t=this.graphics3DGraphics.get(e.uid);if(t)return Promise.resolve(t);const i=this.whenGraphics3DGraphicRequests[e.uid];if(i)return i.promise;const r=C();return this.whenGraphics3DGraphicRequests[e.uid]=r,r.promise}async _boundsForGraphics3DGraphic(e,t){const i=this._spatialReference,r=this.owner.view.renderSpatialReference,s=this.owner.view.basemapTerrain.spatialReference,a=(e,t,s)=>k(e,r,t,e,i,t,s),n=(e,t,r)=>k(e,s,t,e,i,t,r),o=this.viewElevationProvider?{service:this.viewElevationProvider,useViewElevation:d(t)&&t.useViewElevation,minDemResolution:d(t)&&t.minDemResolution,minDemResolutionForPoints:this.owner.view.resolution}:null,l=await e.getProjectedBoundingBox(a,n,o,g(t,"signal"));if(!l)return null;const h=l.boundingBox;if(l.requiresDrapedElevation){const e=this.symbolCreationContext.elevationProvider;if(e){W(h,Ae);const t=p(e.getElevation(Ae[0],Ae[1],0,i,"ground"),0);h[2]=Math.min(h[2],t),h[5]=Math.max(h[5],t)}}return{boundingBox:h,screenSpaceObjects:l.screenSpaceObjects}}async whenGraphicBounds(e,t){await R((()=>this.owner?.loadedGraphics));const i=this.owner.layer&&this.owner.layer.objectIdField,s=this.owner.loadedGraphics.find((t=>t===e||i&&t.attributes&&e.attributes&&t.attributes[i]===e.attributes[i]));if(!s)throw new r("internal:graphic-not-part-of-view","Graphic is not part of this view");const a=await this._whenGraphics3DGraphic(s);return this._boundsForGraphics3DGraphic(a,t)}computeAttachmentOrigin(e,t){const i=this.graphics3DGraphics.get(e.uid);if(!i)return null;const r=i.computeAttachmentOrigin();if(0===r.render.num&&0===r.draped.num)return null;O(Me,0,0,0);let s=0;if(r.render.num>0){if(!V(r.render.origin,this.symbolCreationContext.renderCoordsHelper.spatialReference,We,t))return null;A(Me,Me,We),s++}if(r.draped.num>0){const[e,i]=r.draped.origin,a=p(this.viewElevationProvider.getElevation(e,i,"ground"),0);if(O(We,e,i,a),!V(We,this.viewElevationProvider.spatialReference,We,t))return null;A(Me,Me,We),s++}return s>1&&L(Me,Me,1/s),new De({x:Me[0],y:Me[1],z:Me[2],spatialReference:t})}getSymbolLayerSize(e,t){const i=this.symbols.get(e.id);if(c(i))throw new r("internal:symbol-not-part-of-view","Symbol is not part of this view");const s=e.symbolLayers.indexOf(t);if(-1===s)throw new r("internal:missing-symbol-layer","Symbol layer is not in symbol");const a=i.getSymbolLayerSize(s);if(null==a)throw new r("internal:missing-size","Symbol layer has no valid size");return a}_graphicsCollectionChanged(e){this._startCreateGraphics&&(this.add(e.added),this.remove(e.removed))}graphicUpdateHandler(e){const t=e.graphic.uid,i=this.graphics3DGraphics.get(t);if(!c(i)||!c(this.graphicsWithoutSymbol.get(t)))switch(e.property){case"visible":this._graphicUpdateVisibleHandler(i);break;case"geometry":this._graphicUpdateGeometryHandler(i,e);break;case"symbol":this._graphicUpdateSymbolHandler(i,e);break;case"attributes":break;case"transform":this._graphicUpdateTransformHandler(i,e)}}_graphicUpdateGeometryHandler(e,t){const i=t.graphic.geometry;if(c(i))return void this._recreateGraphic(t.graphic);if(c(e)){const e=t.graphic.symbol&&t.graphic.symbol.id;if(e){const t=this.symbols.get(e);if(d(t)&&t.loadStatus===me.LOADING)return}return void this._recreateGraphic(t.graphic)}const r=e.graphics3DSymbol;!c(t.newValue)&&r.updateGeometry(e,t.newValue)||this._recreateGraphic(e.graphic),this._expandComputedExtent(i)}_graphicUpdateSymbolHandler(e,t){const i=t.graphic,r=d(e)?e.graphics3DSymbol:d(t.oldValue)?this.symbols.get(t.oldValue.id):null;if(c(r)||c(t.newValue))return void this._recreateGraphic(i);const s=r.symbol,a=this._getConvertedSymbol(t.newValue);if(d(a)&&(a.type!==s.type||"web-style"===a.type)||"web-style"===s.type)return void this._recreateGraphic(i);const n=this.graphicsBySymbol.get(s.id);if(n&&1!==n.size)return void this._recreateGraphic(i);const o=I(s,a);if(c(o))return void this._updateSymbolMapping(s.id,a);const l={diff:o,graphics3DGraphicPatches:[],symbolStatePatches:[]};if(r.prepareSymbolPatch(l),!U(l.diff))return void this._recreateGraphic(i);const h=this._getRenderingInfo(i);if(c(h))return void this._recreateGraphic(i);const p=r.extentPadding;for(const d of l.symbolStatePatches)d();if(p!==r.extentPadding&&this._recomputeExtentPadding(),d(e))for(const d of l.graphics3DGraphicPatches)d(e,h);this._updateSymbolMapping(s.id,a)}_graphicUpdateVisibleHandler(e){this._updateUserVisibility(e)&&(this.labeler&&this.owner.view.labeler.setDirty(),this.owner.view.deconflictor.setDirty())}_graphicUpdateTransformHandler(e,t){}recreateGraphics(e){this.suspendSymbolCleanup=!0,this.remove(e),this.add(e),this.suspendSymbolCleanup=!1,this.effectiveUpdatePolicy===Se.SYNC&&this._cleanupSymbols()}_recreateGraphic(e){this.recreateGraphics([e])}_beginGraphicUpdate(e){const t=this.graphicsUpdateId;return this.graphicsUpdateId++,this.graphicsWaitingForSymbol.set(e.uid,t),1===this.graphicsWaitingForSymbol.size&&this.notifyChange("updating"),t}_endGraphicUpdate(e){e&&(this.graphicsWaitingForSymbol.delete(e.uid),0===this.graphicsWaitingForSymbol.size&&(this._cleanupSymbols(),this.notifyChange("updating")))}_recomputeExtentPadding(){let e=0;this.symbols.forEach((t=>{d(t)&&(e=Math.max(e,t.extentPadding))})),this._set("extentPadding",e)}_expandComputedExtent(e){const t=Le,i=e.spatialReference;Y(e,t);const r=this._spatialReference,s=Oe.tmpVec;if(i.equals(r)||F(t[0],t[1],0,i,s,r)&&(t[0]=s[0],t[1]=s[1],F(t[3],t[4],0,i,s,r),t[3]=s[0],t[4]=s[1]),!(isFinite(t[0])&&isFinite(t[3])&&isFinite(t[1])&&isFinite(t[4])))return;const a=this.computedExtent;let n=null;const o=isFinite(t[2])&&isFinite(t[5]),l=o&&(!a||null==a.zmin||t[2]<a.zmin),h=o&&(!a||null==a.zmax||t[5]>a.zmax);if(a){(t[0]<a.xmin||t[1]<a.ymin||t[3]>a.xmax||t[4]>a.ymax||l||h)&&(n=this.propertiesPool.get("computedExtent"),n.xmin=Math.min(t[0],a.xmin),n.ymin=Math.min(t[1],a.ymin),n.xmax=Math.max(t[3],a.xmax),n.ymax=Math.max(t[4],a.ymax),n.spatialReference=r)}else n=this.propertiesPool.get("computedExtent"),n.xmin=t[0],n.ymin=t[1],n.xmax=t[3],n.ymax=t[4],n.spatialReference=r;n&&(l&&(n.zmin=t[2]),h&&(n.zmax=t[5]),this._set("computedExtent",n))}_abortElevationInfoChange(){this.elevationInfoChangeAbortController&&(this.elevationInfoChangeAbortController.abort(),this.elevationInfoChangeAbortController=null)}async elevationInfoChange(){this._abortElevationInfoChange();const e=new AbortController;this.elevationInfoChangeAbortController=e;const t=se(this.layer.elevationInfo,this.elevationFeatureExpressionEnabled);this.symbolCreationContext.featureExpressionInfoContext=await ae(t,this._spatialReference,je),f(e),this.elevationInfoChangeAbortController=null,this.labeler?.elevationInfoChange(),this.forEachGraphics3DSymbol(((e,t,i)=>{e.globalPropertyChanged("elevationInfo",t)?t.forEach((e=>{const t=e.graphic,i=e.labelGraphics;for(const r of i){r.graphics3DSymbolLayer.updateGraphicElevationContext(t,r)}})):this._recreateSymbol(i)})),this.updateStageLayerElevationProvider(),this.elevationAlignment?.elevationInfoChange()}updateStageLayerElevationProvider(){this.stageLayerElevationProvider?(this.layer.elevationInfo&&"relative-to-scene"===this.layer.elevationInfo.mode||0===this.numberOfGraphicsProvidingElevation)&&(this.owner.view.elevationProvider.unregister(this.stageLayerElevationProvider),this.stageLayerElevationProvider.dispose(),this.stageLayerElevationProvider=null):(!this.layer.elevationInfo||this.layer.elevationInfo&&"relative-to-scene"!==this.layer.elevationInfo.mode)&&this.numberOfGraphicsProvidingElevation>0&&(this.stageLayerElevationProvider=new fe({layer:this.layer,stageLayer:this.stageLayer,view:this.owner.view}),this.owner.view.elevationProvider.register("scene",this.stageLayerElevationProvider))}_clearSymbolsAndGraphics(){this.clear(),this.filterVisibility?.clear(),this.labeler?.reset(),this.deconflictor?.clear(),this.elevationAlignment?.clear(),this.stageLayer?.invalidateSpatialQueryAccelerator(),this.stageLayerElevationProvider&&(this.owner.view.elevationProvider.unregister(this.stageLayerElevationProvider),this.stageLayerElevationProvider.dispose(),this.stageLayerElevationProvider=null)}startCreateGraphics(){this._startCreateGraphics=!0,this.recreateAllGraphics()}recreateAllGraphics(){this._recreateAllGraphics(!1)}recreateAllGraphicsAndSymbols(){this._recreateAllGraphics(!0)}_recreateAllGraphics(e=!1){if(!this._startCreateGraphics)return;const{loadedGraphics:t,view:i}=this.owner,r=i.basemapTerrain.tilingScheme&&t&&t.length?t.toArray():null;!e&&r||this._clearSymbolsAndGraphics(),this.symbolCreationContext.screenSizePerspectiveEnabled=this.owner.view.screenSizePerspectiveEnabled&&this.layer.screenSizePerspectiveEnabled,this.symbolCreationContext.slicePlaneEnabled=!!this.owner.slicePlaneEnabled,this._set("computedExtent",null),r&&(e?this.add(r):this.recreateGraphics(r))}_recreateSymbol(e){const t=this.graphicsBySymbol.get(e),i=[];t&&(t.forEach(((e,t)=>{const r=e.usedMemory;this._conditionalRemove(e,t),this._spatialIndex?.remove(e),i.push(e.graphic),e.destroy(),this._removeGraphics3DGraphic(t,r),this._updateLayerVisibility(),this.featureStore.events.emit("changed")})),this.graphicsBySymbol.set(e,new Map));const r=this.symbols.get(e);m(r),this.symbols.delete(e),this.add(i)}_recreateGraphicsForSymbol(e){const t=this.graphicsBySymbol.get(e);if(t){const e=[];t.forEach((t=>e.push(t.graphic))),this.recreateGraphics(e)}}_conditionalRemove(e,t){this.graphicsDrapedUids.delete(t),this.objectStates?.removeGraphic(e),this.labeler?.removeGraphic(e),this.deconflictor?.removeGraphic(e),d(this.graphicStateTracking)&&this.graphicStateTracking.removeGraphic(e)}add(e){e&&0!==e.length&&(this.owner.view.basemapTerrain&&this.owner.view.basemapTerrain.tilingScheme?(this._updatePolicyForGraphics(e)===Se.ASYNC?this._addDelayed(e):this._addImmediate(e),this.notifyChange("updating")):je.error("#add()","Cannot add graphics before terrain surface has been initialized"))}_updatePolicyForGraphics(e){if(this.effectiveUpdatePolicy===Se.SYNC&&("mesh"===this.layer.geometryType||null==this.layer.geometryType))for(const t of e)if(d(t.geometry)&&"mesh"===t.geometry.type&&!t.geometry.loaded)return Se.ASYNC;return this.effectiveUpdatePolicy}_addImmediate(e){this.geometryWarningLogged=!1,this.symbolWarningLogged=!1;for(const t of e)this._addGraphic(t,this._getRenderingInfo(t,je),Se.SYNC);this._cleanupSymbols(),this.labeler&&(this.owner.view.labeler.setDirty(),this._cleanupSymbols()),this.owner.view.deconflictor.setDirty()}_addDelayed(e){for(const t of e){const e=t.uid;let i=this.pendingUpdates.get(e);i?i.add?i.state!==Fe.NEW&&i.abortController.abort():this.pendingAdds++:(i=this.pendingUpdatesPool.pushNew(),this.pendingAdds++,this.pendingUpdates.set(e,i)),i.add=t}this.notifyChange("running"),this.notifyChange("updatingRemaining")}remove(e){this.effectiveUpdatePolicy===Se.ASYNC?this._removeDelayed(e):this._removeImmediate(e),this.notifyChange("updating")}_removeImmediate(e){for(const t of e)this._removeGraphic(t);this._cleanupSymbols(),this.labeler&&this.owner.view.labeler.setDirty(),this.owner.view.deconflictor.setDirty()}_removeDelayed(e){for(const t of e){const e=t.uid,i=this.pendingUpdates.get(e);if(i)i.add&&(i.remove?i.add=null:this.pendingUpdates.delete(e),i.state===Fe.LOADING&&i.abortController.abort(),this.pendingAdds--);else{const i=this.pendingUpdatesPool.pushNew();i.remove=t,this.pendingUpdates.set(e,i),this.pendingRemoves++}}0===this.pendingUpdates.size&&this._finishPendingUpdates(),this.notifyChange("running"),this.notifyChange("updatingRemaining")}_finishPendingUpdates(){this.pendingUpdatesPool.clear(),this._cleanupSymbols(),(this.pendingAdds||this.pendingRemoves)&&je.warn("pendingAdds/Removes in inconsistent state!"),this.pendingAdds=0,this.pendingRemoves=0}_applyPendingUpdates(e){if(this.geometryWarningLogged=!1,this.symbolWarningLogged=!1,0===this.pendingUpdates.size&&this._spatialIndex?.updating)this._spatialIndex.update();else{for(const[t,i]of this.pendingUpdates){if(e.done)break;i.add&&i.state===Fe.NEW&&this._processPendingUpdateNew(i);let r=this.effectiveUpdatePolicy;if(!i.remove||i.add&&i.state!==Fe.READY||(this.pendingRemoves--,e.madeProgress(),this._removeGraphic(i.remove),i.remove=null,r=Se.SYNC),i.add)switch(i.state){case Fe.READY:this._addGraphic(i.add,i.renderingInfo,r),i.add=null,this.pendingAdds--,e.madeProgress();break;case Fe.REJECTED:i.add=null,this.pendingAdds--;case Fe.LOADING:}null==i.remove&&null==i.add&&this.pendingUpdates.delete(t)}0===this.pendingUpdates.size&&(this._finishPendingUpdates(),this.notifyChange("running"))}}_processPendingUpdateNew(e){if(!e.add)return void(e.state=Fe.READY);const t=e.add.geometry;d(t)&&"mesh"===t.type&&!t.loaded?this._processPendingUpdateNewMesh(e,t):this._processPendingUpdateNewRenderingInfo(e)}async _processPendingUpdateNewMesh(e,t){e.state=Fe.LOADING,e.abortController=new AbortController;const i=e.abortController.signal;try{await t.load({signal:i})}catch(r){return this._processPendingUpdateNewError(e,r)}e.abortController=null,this._processPendingUpdateNewRenderingInfo(e)}_processPendingUpdateNewError(e,t){e.abortController=null,S(t)?e.state=Fe.NEW:e.state=Fe.REJECTED}async _processPendingUpdateNewRenderingInfo(e){if(c(this.layer.renderer)||"dictionary"!==this.layer.renderer.type)return e.renderingInfo=this._getRenderingInfo(e.add,je),void(e.state=Fe.READY);e.state=Fe.LOADING,e.abortController=new AbortController;let t=null;try{t=await this._getRenderingInfoAsync(e.add,{signal:e.abortController.signal})}catch(i){return e.abortController=null,void(S(i)?e.state=Fe.NEW:e.state=Fe.REJECTED)}c(t)||c(t.symbol)?(je&&!this.symbolWarningLogged&&(this.symbolWarningLogged=!0,je.warn(`Graphic in layer ${this.layer.id} has no symbol and will not render`)),e.renderingInfo=null):e.renderingInfo=t,e.state=Fe.READY}_addGraphic(e,t,i){if(this.graphicsWithoutSymbol.set(e.uid,e),c(t)||c(t.symbol)||!$(e))return;const r=t.symbol,s=this.getOrCreateGraphics3DSymbol(r,t.renderer);if(c(s))return;this._expandComputedExtent(e.geometry);const a=this._beginGraphicUpdate(e),n=new oe(e,t,this.layer);let o=!1;const l=e=>{e===s.symbol.id&&(o=!0)};this._whenSymbolRemoved.push(l);const h=()=>{if(--this._loadingSymbols,this.destroyed)return;this._whenSymbolRemoved.removeUnordered(l);if(this.graphicsWaitingForSymbol.get(e.uid)!==a||o||s.destroyed||this.graphicSymbolSupported&&e.symbol&&e.symbol.id!==s.symbol.id)--s.referenced,this._cleanupSymbols();else{const t=this._createGraphics3DGraphic(s,n);this._spatialIndex&&d(t)&&this._spatialIndex.add(t),--s.referenced,this._endGraphicUpdate(e)}this.featureStore.events.emit("changed"),this.labeler&&this.owner.view.labeler.setDirty()},p=t=>{--this._loadingSymbols,this.destroyed||(this._whenSymbolRemoved.removeUnordered(l),o||(S(t)?this.add([e]):s.destroyed||this._endGraphicUpdate(e)))};++this._loadingSymbols,i===Se.ASYNC?s.load((()=>this._frameTask.schedule(h)),(e=>this._frameTask.schedule((()=>p(e))))):s.load(h,p)}_removeGraphic(e){const t=e.uid,i=this.graphics3DGraphics.get(t);if(i){i.graphics3DSymbol.onRemoveGraphic(i);const e=i.usedMemory,r=i.isElevationSource;this._conditionalRemove(i,t),this._spatialIndex?.remove(i);const s=i.graphics3DSymbol.symbol.id;this.graphicsBySymbol.get(s).delete(t),this.graphicsWithoutSymbol.delete(t),this._removeGraphics3DGraphic(t,e,r),i.destroy(),this.featureStore.events.emit("changed")}else this.graphicsWithoutSymbol.delete(t),this.graphicsWaitingForSymbol.delete(t),0===this.graphicsWaitingForSymbol.size&&(this._cleanupSymbols(),this.notifyChange("updating"))}_hasLabelingContext(e){if(e instanceof Ee||e instanceof Ie){const t=this.symbolCreationContext.layer;return!!t.labelingInfo&&t.labelingInfo.some((t=>t.symbol===e))}return!1}_hasValidSymbolCreationContext(e){return!(e instanceof Ee&&!this._hasLabelingContext(e))||(je.error("LabelSymbol3D is only valid as part of a LabelClass. Using LabelSymbol3D as a renderer symbol is not supported."),!1)}_getRenderingInfo(e,t){const i=e.geometry;if(c(i))return t&&!this.geometryWarningLogged&&(this.geometryWarningLogged=!0,t.warn(`Graphic in layer ${this.layer.id} has no geometry and will not render`)),null;if(!T(i.spatialReference,this._spatialReference))return t&&!this.geometryWarningLogged&&(this.geometryWarningLogged=!0,t.warn(`Graphic in layer ${this.layer.id} has incompatible spatial reference and will not render`)),null;if(!this.graphicSymbolSupported&&d(e.symbol))return t&&!this.symbolWarningLogged&&(this.symbolWarningLogged=!0,t.warn(`Graphic in layer ${this.layer.id} is not allowed to have a symbol, use a renderer instead`)),null;const r=this.rendererHasGeometryOperations?Z(e,this.layer):e;let s;if(this.owner.getRenderingInfo&&(this.getRenderingInfoWithoutRenderer||d(this.currentRenderer)))s=this.owner.getRenderingInfo(r,this.currentRenderer,u(this.arcadeOnDemand));else{s={symbol:r.symbol||X(r.geometry)}}return c(s)||c(s.symbol)?(t&&!this.symbolWarningLogged&&(this.symbolWarningLogged=!0,t.warn(`Graphic in layer ${this.layer.id} has no symbol and will not render`)),null):s}_getRenderingInfoAsync(e,t){const i=e.geometry;if(c(i))return je&&!this.geometryWarningLogged&&(this.geometryWarningLogged=!0,je.warn(`Graphic in layer ${this.layer.id} has no geometry and will not render`)),null;if(!this.graphicSymbolSupported&&d(e.symbol))return je&&!this.symbolWarningLogged&&(this.symbolWarningLogged=!0,je.warn(`Graphic in layer ${this.layer.id} is not allowed to have a symbol, use a renderer instead`)),null;const r=this.rendererHasGeometryOperations?Z(e,this.layer):e;return this.owner.getRenderingInfoAsync(r,u(this.currentRenderer),u(this.arcadeOnDemand),t)}_createGraphics3DSymbol(e,t){if(!this._hasValidSymbolCreationContext(e))return null;const i=this._getConvertedSymbol(e);if(!i)return null;let r;if(d(t)&&"backgroundFillSymbol"in t&&t.backgroundFillSymbol){const e=ee(t.backgroundFillSymbol,{ignoreDrivers:!0});d(e.symbol)&&"web-style"!==e.symbol.type&&"cim"!==e.symbol.type&&(r=e.symbol.symbolLayers)}const s=he(i,this.symbolCreationContext,r);return s.load((()=>{const e=s.extentPadding;e>this.extentPadding&&this._set("extentPadding",e),this.notifyChange("averageSymbolComplexity")}),(()=>{})),s}getOrCreateGraphics3DSymbol(e,t){let i=this.symbols.get(e.id);return void 0===i&&(i=e instanceof Ue?new de(e,(e=>this._frameTask.schedule(e)),(e=>this._createGraphics3DSymbol(e,t))):this._createGraphics3DSymbol(e,t),this.symbols.set(e.id,i)),d(i)&&++i.referenced,i}trackGraphicState(e){return c(this.graphicStateTracking)&&(this.graphicStateTracking=new pe(this)),this.graphicStateTracking.add(e)}_addGraphics3DGraphic(e){this._usedMemory+=e.usedMemory,this.graphics3DGraphics.set(e.graphic.uid,e),this.numberOfGraphics++,e.isElevationSource&&(this.numberOfGraphicsProvidingElevation++,this.updateStageLayerElevationProvider()),this._updateLayerVisibility()}_removeGraphics3DGraphic(e,t,i=!1){this._usedMemory-=t,this.graphics3DGraphics.delete(e),this.numberOfGraphics--,i&&(this.numberOfGraphicsProvidingElevation--,this.updateStageLayerElevationProvider()),this._updateLayerVisibility()}_createGraphics3DGraphic(e,t){const i=t.graphic;if(this.graphicsWithoutSymbol.delete(i.uid),!this.symbols.has(e.symbol.id))return this.add([i]),null;if(this.graphics3DGraphics.has(i.uid))return null;const r=e.createGraphics3DGraphic(t);if(c(r))return null;this._addGraphics3DGraphic(r);const s=e.symbol.id;this.graphicsBySymbol.has(s)||this.graphicsBySymbol.set(s,new Map),this.graphicsBySymbol.get(s).set(i.uid,r);r.isDraped&&this.graphicsDrapedUids.add(i.uid),r.centroid=null,d(i.geometry)&&"point"!==i.geometry.type&&(r.centroid=ce(i.geometry,this._spatialReference)),this._updateUserVisibility(r),d(this.scaleVisibility)&&this.scaleVisibility.updateVisibility(r),this.filterVisibility?.updateVisibility(r),this.deconflictor?.addGraphic(r),this.labeler?.addGraphic(r),this.objectStates?.addGraphic(r),this.deconflictor&&this.owner.view.deconflictor.setInitialIconVisibilityFlag(this,r),r.initialize(this.stage,this.stageLayer,this.owner),d(this.graphicStateTracking)&&this.graphicStateTracking.addGraphic(r);const a=this.whenGraphics3DGraphicRequests[i.uid];return a&&(delete this.whenGraphics3DGraphicRequests[i.uid],a.resolve(r)),r}_abortRendererChange(){this.rendererChangeAbortController&&(this.rendererChangeAbortController.abort(),this.rendererChangeAbortController=null)}async rendererChange(e){if(this._abortRendererChange(),e!==this.currentRenderer)if(this._validateRenderer(e),c(e)&&this._currentRendererChange(null,!1),J(e))if(d(e)&&e.arcadeRequired){const t=new AbortController;this.rendererChangeAbortController=t;const{arcadeUtils:i}=await this._ensureArcade();f(t),i.hasGeometryOperations(e)&&(await i.enableGeometryOperations(),f(t)),this.effectiveUpdatePolicy===Se.ASYNC?await this._frameTask.schedule((()=>this._currentRendererChange(e,!0)),t.signal):this._currentRendererChange(e,!0),this.rendererChangeAbortController=null}else if(this.effectiveUpdatePolicy===Se.ASYNC){const t=new AbortController;this.rendererChangeAbortController=t,await this._frameTask.schedule((()=>this._currentRendererChange(e,!1)),t.signal),this.rendererChangeAbortController=null}else this._currentRendererChange(e,!1);else this._currentRendererChange(e,!1)}async _ensureArcade(){return c(this.arcadeOnDemand)?(this.arcadeOnDemand=await K(),this.arcadeOnDemand):this.arcadeOnDemand}_currentRendererChange(e,t){this.currentRenderer=e,this.rendererHasGeometryOperations=t,this.symbolCreationContext.arcade=u(this.arcadeOnDemand);const i=this.symbolCreationContext.renderer;if(e===i)return;if(this.symbolConversionCache.clear(),c(e))return this.symbolCreationContext.renderer=null,void this.recreateAllGraphicsAndSymbols();const r=I(i,e);this._updateUnchangedSymbolMappings(r,e,i),this.symbolCreationContext.renderer=e,c(r)||("complete"===r.type?this.recreateAllGraphicsAndSymbols():"partial"===r.type&&(this._applyRendererDiff(r,e,i)?this._volatileGraphicsUpdated():this.recreateAllGraphicsAndSymbols()),this.notifyChange("averageSymbolComplexity"))}_diffHasSymbolChange(e){for(const t in e.diff)switch(t){case"visualVariables":case"defaultSymbol":case"uniqueValueInfos":break;case"authoringInfo":case"fieldDelimiter":delete e.diff[t];break;default:return!0}return!1}_applySymbolSetDiff(e,t,i){e=e||[],t=t||[];const r=[];for(const s of t){const t=this.graphicsBySymbol.get(s.id);t&&t.forEach(((a,n)=>{const o=a.graphic,l=this.layer instanceof q?this.layer:null,h=u(this.arcadeOnDemand);if(s===i.defaultSymbol&&i.getSymbol(Z(o,l),{arcade:h})===i.defaultSymbol)return;const d=a.usedMemory;e.length||i.defaultSymbol?r.push(o):this.graphicsWithoutSymbol.set(n,o);const p=this.graphics3DGraphics.get(n);this._conditionalRemove(p,n),a.destroy(),t.delete(n),this._removeGraphics3DGraphic(n,d),this._updateLayerVisibility()})),this._whenSymbolRemoved.forAll((e=>e(s.id)))}(e.length||r.length)&&(this.graphicsWithoutSymbol.forEach((e=>r.push(e))),this.graphicsWithoutSymbol.clear(),this.add(r)),this._cleanupSymbols(),this.labeler&&this.owner.view.labeler.setDirty(),this.owner.view.deconflictor.setDirty()}_applyUniqueValueRendererDiff(e,t,i){const r=e.diff.defaultSymbol,s=e.diff.uniqueValueInfos;if(r||s){const a=s?s.added.map((e=>e.symbol)):[],n=s?s.removed.map((e=>e.symbol)):[];if(s)for(let e=0;e<s.changed.length;e++)a.push(s.changed[e].newValue.symbol),n.push(s.changed[e].oldValue.symbol);return r?(i.defaultSymbol&&n.push(i.defaultSymbol),t.defaultSymbol&&a.push(t.defaultSymbol)):i.defaultSymbol&&a.length&&n.push(t.defaultSymbol),this._applySymbolSetDiff(a,n,t),delete e.diff.defaultSymbol,delete e.diff.uniqueValueInfos,!0}return!1}_calculateUnchangedSymbolMapping(e,t,i){if("unique-value"!==t?.type||"unique-value"!==i?.type||d(e)&&"partial"!==e.type)return[];const r=e=>d(e)?e.id:null,s=e&&e.diff,a=s&&s.defaultSymbol,n=s&&s.uniqueValueInfos;let o;if(n)o=n.unchanged.map((e=>({oldId:r(e.oldValue.symbol),newId:r(e.newValue.symbol)})));else{o=[];for(const e of i.uniqueValueInfos){const i=r(e.symbol),s=t.uniqueValueInfos.find((t=>t.value===e.value));s&&i!==r(s.symbol)&&o.push({oldId:i,newId:r(s.symbol)})}}return!a&&i.defaultSymbol&&o.push({oldId:r(i.defaultSymbol),newId:r(t.defaultSymbol)}),o}_updateSymbolMapping(e,t){const i=d(t)&&t?"string"==typeof t?t:t.id:null;if(!e||e===i)return;const r=this.graphicsBySymbol.get(e);this.graphicsBySymbol.delete(e),void 0!==r&&this.graphicsBySymbol.set(i,r);const s=this.symbols.get(e);if(void 0!==s&&(this.symbols.delete(e),this.symbols.set(i,s),d(s))){const e="string"==typeof t?null:t;d(e)?s.symbol=e:s.symbol.id=i}}_updateUnchangedSymbolMappings(e,t,i){const r=this._calculateUnchangedSymbolMapping(e,t,i);for(const{oldId:s,newId:a}of r)this._updateSymbolMapping(s,a)}_applyRendererDiff(e,i,r){if(this._diffHasSymbolChange(e))return!1;if(i instanceof t&&r instanceof t&&this._applyUniqueValueRendererDiff(e,i,r)&&0===Object.keys(e.diff).length)return!0;for(const[t]of this.graphicsBySymbol){const r=this.symbols.get(t);if(d(r))switch(r.applyRendererDiff(e,i)){case ye.Recreate_Symbol:this._recreateSymbol(t);break;case ye.Recreate_Graphics:this._recreateGraphicsForSymbol(t);case ye.Fast_Update:}}return!0}opacityChange(){this.forEachGraphics3DSymbol(((e,t)=>e.globalPropertyChanged("opacity",t))),this._updateStageLayerVisibility()}_slicePlaneEnabledChange(e){e!==this.symbolCreationContext.slicePlaneEnabled&&(this.symbolCreationContext.slicePlaneEnabled=e,this.stageLayer.isSliceable=e,this.forEachGraphics3DSymbol(((e,t)=>e.globalPropertyChanged("slicePlaneEnabled",t))),this.deconflictor&&this.deconflictor.slicePlaneEnabledChange(),this.labeler&&this.labeler.slicePlaneEnabledChange())}_physicalBasedRenderingChange(e){e!==this.symbolCreationContext.physicalBasedRenderingEnabled&&(this.symbolCreationContext.physicalBasedRenderingEnabled=e,this.forEachGraphics3DSymbol(((e,t,i)=>{e.globalPropertyChanged("physicalBasedRenderingEnabled",t)||this._recreateSymbol(i)})))}_pixelRatioChange(){this.forEachGraphics3DSymbol(((e,t,i)=>{e.globalPropertyChanged("pixelRatio",t)||this._recreateSymbol(i)}))}_signalUpdatingDuringAsyncLoadedGraphicsChange(){this._updatingPendingLoadedGraphicsChange&&this._updatingPendingLoadedGraphicsChange.remove(),this._updatingPendingLoadedGraphicsChange=P((()=>{this._updatingPendingLoadedGraphicsChange=null}))}setClippingExtent(e,t){const i=this.symbolCreationContext.clippingExtent,r=B();return ve(e,r,t)?this.symbolCreationContext.clippingExtent=N(M(),r):this.symbolCreationContext.clippingExtent=null,!z(this.symbolCreationContext.clippingExtent,i)}modifyGraphics3DGraphicVisibilities(e){let t=!1;this.graphics3DGraphics.forEach((i=>{e(i)&&(t=!0)})),t&&(this.labeler&&this.owner.view.labeler.setDirty(),this.owner.view.deconflictor.setDirty())}forEachGraphics3DSymbol(e){for(const[t,i]of this.symbols){if(c(i))return;e(i,this.graphicsBySymbol.get(t)||Ne,t)}}updateAllGraphicsVisibility(){this.filterVisibility&&(this.filterVisibility.dirty=!0),this.modifyGraphics3DGraphicVisibilities((e=>{const t=this._updateUserVisibility(e),i=d(this.scaleVisibility)&&this.scaleVisibility.updateVisibility(e);return t||i}))}_hideAllGraphics(){this.modifyGraphics3DGraphicVisibilities((e=>e.setVisibilityFlag(ie.USER_SETTING,!1,re.GRAPHIC)))}_validateRenderer(e){const t=Q(e);if(t){const e=`Renderer for layer '${this.layer.title?`${this.layer.title}, `:""}, id:${this.layer.id}' is not supported in a SceneView`;je.warn(e,t.message)}}_volatileGraphicsUpdated(){this.labeler?.reset(),this.stageLayer.shaderTransformationChanged(),this.notifyChange("updating")}_cleanupSymbols(){if(this.graphicsWaitingForSymbol.size>0||this.suspendSymbolCleanup)return;let e=!1;this.symbols.forEach(((t,i)=>{if(c(t)||t.referenced>0)return;const r=this.graphicsBySymbol.get(i);r&&0!==r.size||(this.graphicsBySymbol.delete(i),this.symbols.delete(i),m(t),e=!0)})),e&&(this._recomputeExtentPadding(),this.notifyChange("averageSymbolComplexity"))}get test(){return{snapshotInternals:()=>({graphics:[...this.graphics3DGraphics.keys()].sort(),symbols:[...this.symbols.keys()].sort(),graphicsBySymbol:[...this.graphicsBySymbol.keys()].sort().map((e=>({symbolId:e,graphics:[...this.graphicsBySymbol.get(e).keys()].sort()}))),graphicsWithoutSymbol:[...this.graphicsWithoutSymbol.keys()].sort(),graphicsDrapedUids:[...this.graphicsDrapedUids].sort(),pendingUpdates:this.pendingUpdates}),symbols:this.symbols,filterVisibility:this.filterVisibility,numPending:this.pendingUpdates.size,forceUpdatePolicy:e=>{this.forcedUpdatePolicy=e}}}get performanceInfo(){return{visible:this.graphics3DGraphics.size,missing:this.graphicsWithoutSymbol.size,pending:this.pendingUpdates.size}}};var Fe;Ve.tmpVec=j(),e([D({readOnly:!0})],Ve.prototype,"computedExtent",void 0),e([D()],Ve.prototype,"currentRenderer",void 0),e([D()],Ve.prototype,"rendererHasGeometryOperations",void 0),e([D()],Ve.prototype,"_frameTask",void 0),e([D()],Ve.prototype,"rendererChangeAbortController",void 0),e([D()],Ve.prototype,"elevationInfoChangeAbortController",void 0),e([D()],Ve.prototype,"setupAbortController",void 0),e([D({readOnly:!0})],Ve.prototype,"elevationAlignment",void 0),e([D({readOnly:!0})],Ve.prototype,"scaleVisibility",void 0),e([D({readOnly:!0})],Ve.prototype,"filterVisibility",void 0),e([D()],Ve.prototype,"_spatialIndex",void 0),e([D({readOnly:!0})],Ve.prototype,"extentPadding",void 0),e([D()],Ve.prototype,"_updatingPendingLoadedGraphicsChange",void 0),e([D({readOnly:!0})],Ve.prototype,"featureStore",void 0),e([D({readOnly:!0})],Ve.prototype,"deconflictor",void 0),e([D({readOnly:!0})],Ve.prototype,"labeler",void 0),e([D({readOnly:!0})],Ve.prototype,"objectStates",void 0),e([D()],Ve.prototype,"_loadingSymbols",void 0),e([D()],Ve.prototype,"preferredUpdatePolicy",void 0),e([D()],Ve.prototype,"forcedUpdatePolicy",void 0),e([D({readOnly:!0})],Ve.prototype,"effectiveUpdatePolicy",null),e([D({constructOnly:!0})],Ve.prototype,"elevationFeatureExpressionEnabled",void 0),e([D({constructOnly:!0})],Ve.prototype,"owner",void 0),e([D({constructOnly:!0})],Ve.prototype,"layer",void 0),e([D({constructOnly:!0})],Ve.prototype,"graphicSymbolSupported",void 0),e([D({constructOnly:!0})],Ve.prototype,"getRenderingInfoWithoutRenderer",void 0),e([D({readOnly:!0})],Ve.prototype,"updating",null),e([D({readOnly:!0})],Ve.prototype,"running",null),e([D({readOnly:!0})],Ve.prototype,"suspendedOrOutsideOfView",null),e([D({readOnly:!0,dependsOn:[]})],Ve.prototype,"updatingRemaining",null),e([D({readOnly:!0,dependsOn:["owner.view.qualitySettings.graphics3D.maxTotalNumberOfPrimitives","owner.view.qualitySettings.graphics3D.maxTotalNumberOfFeatures","averageSymbolComplexity"]})],Ve.prototype,"displayFeatureLimit",null),e([D({readOnly:!0,dependsOn:[]})],Ve.prototype,"averageSymbolComplexity",null),e([D({constructOnly:!0})],Ve.prototype,"hasZ",void 0),e([D({constructOnly:!0})],Ve.prototype,"hasM",void 0),Ve=Oe=e([E("esri.views.3d.layers.graphics.Graphics3DCore")],Ve),function(e){e[e.NEW=0]="NEW",e[e.LOADING=1]="LOADING",e[e.READY=2]="READY",e[e.REJECTED=3]="REJECTED"}(Fe||(Fe={}));class Te{constructor(){this.add=null,this.renderingInfo=null,this.state=Fe.NEW,this.remove=null}clear(){this.add=null,this.renderingInfo=null,this.state=Fe.NEW,this.abortController=null,this.remove=null}}const ke=10,Me=j(),We=j(),Ne=new Map;export{Ve as Graphics3DCore};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Color.js";import i from"../../../core/Accessor.js";import{isSome as r,isNone as s}from"../../../core/maybe.js";import n from"../../../core/ObjectPool.js";import{property as a}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/arrayUtils.js";import"../../../core/has.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as o}from"../../../core/accessorSupport/decorators/subclass.js";import{I as l}from"../../../chunks/mat4f64.js";import{b as d,s as h,e as c}from"../../../chunks/vec3.js";import{Z as u,c as p}from"../../../chunks/vec3f64.js";import{Z as g,c as f}from"../../../chunks/vec4f64.js";import{create as m,set as T}from"../../../geometry/support/aaBoundingBox.js";import{BufferViewVec3f as _}from"../../../geometry/support/buffer/BufferView.js";import{requestImage as R}from"../../../support/requestImageUtils.js";import{ViewingMode as b}from"../../ViewingMode.js";import{TextureUpdate as y}from"./interfaces.js";import{LayerClass as A}from"./LayerClass.js";import{OverlaySource as O}from"./Overlay.js";import{overlayRenderOccludedFlag as v}from"./OverlayRenderer.js";import{clearCaches as x}from"./PatchGeometry.js";import{PatchRenderData as P}from"./PatchRenderData.js";import{RenderOrder as C}from"./RenderOrder.js";import{ScaleRangeQueries as E}from"./ScaleRangeQueries.js";import{DEFAULT_TILE_BACKGROUND as D}from"./TerrainConst.js";import"./terrainUtils.js";import{TileRenderer as q}from"./TileRenderer.js";import{TileUpdate as S}from"./TileUpdate.js";import{IteratorPreorder as I,sortTiles as N,compareTiles as w}from"./tileUtils.js";import{componentMinimalSizeForIntersectionData as L,ComponentIntersectionData as G}from"../webgl-engine/collections/Component/ComponentIntersectionData.js";import{ShaderOutput as j}from"../webgl-engine/core/shaderLibrary/ShaderOutputOptions.js";import{OverlayMode as k}from"../webgl-engine/core/shaderLibrary/terrain/Overlay.glsl.js";import{T as U}from"../../../chunks/Terrain.glsl.js";import{RenderRequestType as B}from"../webgl-engine/lib/basicInterfaces.js";import{createEmptyTexture as F}from"../webgl-engine/lib/glUtil3D.js";import{newIntersectorResult as M}from"../webgl-engine/lib/Intersector.js";import{IntersectorType as H,StoreResults as z}from"../webgl-engine/lib/IntersectorInterfaces.js";import{RenderOccludedFlag as V}from"../webgl-engine/lib/Material.js";import{RenderPass as Q}from"../webgl-engine/lib/RenderPass.js";import{RenderSlot as W}from"../webgl-engine/lib/RenderSlot.js";import{getSettings as Y}from"../webgl-engine/lib/screenSizePerspectiveUtils.js";import{VertexAttribute as X}from"../webgl-engine/lib/VertexAttribute.js";import{TERRAIN_ID as Z,getVerticalOffsetTerrain as K}from"../webgl-engine/lib/verticalOffsetUtils.js";import{DrawParameters as J}from"../webgl-engine/materials/DrawParameters.js";import{intersectAabbInvDirBefore as $,intersectTriangles as ee}from"../webgl-engine/materials/internal/MaterialUtil.js";import{TerrainTechnique as te}from"../webgl-engine/shaders/TerrainTechnique.js";import{TerrainTechniqueConfiguration as ie}from"../webgl-engine/shaders/TerrainTechniqueConfiguration.js";import{ClearBufferBit as re,PrimitiveType as se}from"../../webgl/enums.js";const ne=7,ae=10,oe=m(),le=f();let de=class extends i{constructor(e){super(e),this.type=H.TERRAIN,this.isGround=!0,this.tileSize=256,this._passParameters=new U,this.rctx=null,this._isTransparent=!1,this._scaleRangeQueries=new E,this.renderDataPool=new n(P),this._patchGroups=new Map,this.patchGroupsDirty=!0,this.tileIterator=new I,this.highestVisibleLODTile=null,this.visible=!0,this._opaque=!0,this._velvetOverground=!0,this.castShadows=!0,this.emptyTex=null,this.tileRenderer=null,this.tileBackgroundInitialized=!1,this.tileBackgroundUpdating=!1,this.stencilEnabledLayerExtents=[],this.numTilesRendered=0,this.numTilesCulled=0,this.numOriginsRendered=0,this.needsHighlight=!1,this.renderOccludedFlags=V.Occlude,this._lastBackgroundColorRequest=null}get isGlobal(){return this.stage.viewingMode===b.Global}initialize(){const e=[W.OPAQUE_TERRAIN,W.TRANSPARENT_TERRAIN,W.OCCLUDED_TERRAIN];this.stage.addRenderPlugin(e,this)}destroy(){this.stage.removeRenderPlugin(this),x()}get updating(){return!this.tileBackgroundInitialized||this.tileBackgroundUpdating}get canRender(){return this.visible&&!!this._rootTiles&&this.tileBackgroundInitialized&&!this.renderingDisabled}set renderingDisabled(e){this._set("renderingDisabled",!!e),this.setNeedsRender()}set opaque(e){this._opaque!==e&&(this._opaque=e,this.setNeedsRender())}get opaque(){return this._opaque&&!this._techniqueConfiguration.hasSlicePlane}get needsLinearDepth(){return this.overlayRenderer.hasWater}set isTransparent(e){this._isTransparent!==e&&(this._isTransparent=e,this.setNeedsRender())}get isTransparent(){return this._isTransparent}get renderPatchBorders(){return!!this._techniqueConfiguration.tileBorders}set renderPatchBorders(e){this._techniqueConfiguration.tileBorders!==e&&(this._techniqueConfiguration.tileBorders=e,this.setNeedsRender(),this.notifyChange("renderPatchBorders"))}get cullBackFaces(){return this._techniqueConfiguration.backfaceCullingEnabled}set cullBackFaces(e){this._techniqueConfiguration.backfaceCullingEnabled!==e&&(this._techniqueConfiguration.backfaceCullingEnabled=e,this.notifyChange("cullBackFaces"),this.setNeedsRender())}set renderOrder(e){this._set("renderOrder",e),this.setNeedsRender()}set velvetOverground(e){this._velvetOverground!==e&&(this._velvetOverground=e,this.setNeedsRender())}get layerUid(){return Z}get slicePlaneEnabled(){return this._techniqueConfiguration.hasSlicePlane}set slicePlaneEnabled(e){this._techniqueConfiguration.hasSlicePlane!==e&&(this._techniqueConfiguration.hasSlicePlane=e,this.setNeedsRender())}set textureFadingEnabled(e){this._techniqueConfiguration.textureFadingEnabled!==e&&(this._techniqueConfiguration.textureFadingEnabled=e,this.setNeedsRender())}setDebugScreenSizePerspective(e){this._techniqueConfiguration.screenSizePerspective!==e&&(this._techniqueConfiguration.screenSizePerspective=e,this.setNeedsRender())}setRootTiles(e){this._rootTiles=e,this.setNeedsRender()}setNeedsHighlight(e){this.needsHighlight=e,this.setNeedsRender()}setRenderOccludedOverlay(e){this.renderOccludedFlags=e?v:V.Occlude,this.setNeedsRender()}setStencilEnabledLayerExtents(e){this.stencilEnabledLayerExtents=e,this.setNeedsRender()}setTileSize(e){this.tileSize=e,this.tileRenderer&&(this.tileRenderer.tileSize=e),this.setNeedsRender()}_prepareTileForLoading(e){e.renderData||(e.renderData=this.renderDataPool.acquire(),e.renderData.init(e),e.renderData.localOrigin=this._getLocalOriginOfTile(e))}loadTile(e){this._prepareTileForLoading(e),this.updateTileGeometry(e),this.updateTileTexture(e,S.TEXTURE_FADING)}queryVisibleLevelRange(e,t,i,r){this._scaleRangeQueries.queryVisibleLevelRange(e,t,i,r),this.setNeedsRender()}updateTileTexture(e,t){this.tileRenderer&&this.tileBackgroundInitialized&&(this.tileRenderer.updateTileTexture(e,t===S.TEXTURE_FADING?y.FADING:y.UNFADED),this.setNeedsRender(),e.resetPendingUpdate(t))}updateTileGeometryState(e){this._prepareTileForLoading(e),e.renderData.updateGeometryStateAndPrepareForGeometryGeneration(this.wireframe)}updateTileGeometry(e){for(const t of e.layerInfo[A.ELEVATION])t.pendingUpdates&=~S.GEOMETRY;e.resetPendingUpdate(S.GEOMETRY);e.renderData.updateGeometryIfChanged(this.rctx,this.wireframe)&&this.setNeedsRender()}unloadTile(e){const t=e.renderData;t&&(t.releaseGeometry(),this.renderDataPool.release(t),t.clear(),e.renderData=null,e.setMemoryDirty(),this.setNeedsRender())}_getLocalOriginOfTile(e){const t=ae-ne,i=Math.max(0,Math.floor((e.level-t)/ne)*ne);if(this.isGlobal&&0===i)return u;for(;e.parent&&e.level>i;)e=e.parent;return e.centerAtSeaLevel}setVisibility(e){this.visible=e,this.setNeedsRender()}getStats(){return{numTilesRendered:this.numTilesRendered,numTilesCulled:this.numTilesCulled,numOriginsRendered:this.numOriginsRendered}}set wireframe(e){this._get("wireframe")!==e&&(this._set("wireframe",e),this.allTiles.forAll((e=>{e.isLoaded&&(this.updateTileGeometry(e),e.updateNeighborsAfterGeometryChange())})),this.setNeedsRender())}setNeedsRender(e=B.UPDATE){this.patchGroupsDirty=!0,this._context.requestRender(e)}initializeRenderContext(e){this._context=e,this.rctx=e.renderContext.rctx,this._techniqueRepository=e.shaderTechniqueRepository,this._techniqueConfiguration=new ie,this.tileRenderer=new q(this.rctx,this.tileSize,this._techniqueRepository),this.updateTileBackground(),this.emptyTex=F(this.rctx)}uninitializeRenderContext(){null!=this.emptyTex&&(this.emptyTex.dispose(),this.emptyTex=null),this.tileRenderer&&(this.tileRenderer.dispose(),this.tileRenderer=null)}intersect(e,t,i,n){if(!this._rootTiles||e.options.selectOpaqueTerrainOnly&&e.options.selectionMode&&!this._opaque)return;const a=ue,o=pe;d(a,n,i),h(o,1/a[0],1/a[1],1/a[2]);const u=e.results.min,p=e.results.max,g=e.results.ground,f=e.options.store===z.MIN,m=!!e.results.ground.target,R=K(e.verticalOffset),b=e.tolerance;let y,A=f&&r(u.dist)?u.dist:1/0;const O=h=>{const m=h.renderData;if(!m?.vao)return;const O=m.geometryInfo;T(oe,O.boundingBox);const v=m.localOrigin;r(R)&&(R.localOrigin=v,R.applyToAabb(oe));const x=oe;if(ge[0]=i[0]-v[0],ge[1]=i[1]-v[1],ge[2]=i[2]-v[2],!$(x,ge,o,b,A))return;const P=(e,t,i)=>{e.set(this.type,h,t,i,l),A=f&&r(u.dist)?u.dist:1/0},C=(o,l)=>{if(r(l)&&o>=0&&(e.options.backfacesTerrain||c(l,a)<0)&&(e.options.invisibleTerrain||!e.options.selectionMode||null==t||t(i,n,o))){if((null==g.dist||o<g.dist)&&P(g,o,l),e.options.isFiltered)return;e.options.store===z.ALL&&(s(y)?(y=M(e.ray),P(y,o,l),e.results.all.push(y)):o<y.dist&&P(y,o,l)),(null==u.dist||o<u.dist)&&P(u,o,l),e.options.store!==z.MIN&&(null==p.dist||o>p.dist)&&P(p,o,l)}},E=fe;d(E,n,v);const D=O.indices,q=O.vertexAttributes,S={data:q.getField(X.POSITION,_).typedBuffer,size:3,stride:q.stride/4},I=O.indexCount/3;if(s(R)&&I>L){const e=h.renderData;s(e.intersectionData)&&(e.intersectionData=new G(D,0,I,S)),e.intersectionData.intersectRay({r0:ge,r1:E},C)}else ee(ge,E,0,I,D,S,null,R,C)},v=this._rootTiles;if(r(v)){(()=>{const t=this.tileIterator;t.reset(v);const s=e.options.invisibleTerrain;for(;!t.done;){const e=t.next();!(e.visible||s&&e.intersectsClippingArea)||!r(R)&&!e.intersectsRay(i,a,b,A)||m&&this._useStencilForTile(e)?t.skipSubtree():O(e)}})()}}prepareTechnique(e){if(e.bindParameters.slot===W.OCCLUDED_TERRAIN){if(0==(e.renderOccludedMask&v))return null}else{const t=this.opaque?W.OPAQUE_TERRAIN:W.TRANSPARENT_TERRAIN;if(e.bindParameters.slot!==t)return null}switch(e.pass){case Q.MATERIAL:{this._techniqueConfiguration.hasScreenSpaceReflections=e.bindParameters.ssr.enabled,this._techniqueConfiguration.hasCloudsReflections=r(e.bindParameters.cloudsComposition.clouds),this._techniqueConfiguration.receiveShadows=e.bindParameters.shadowMap.ready,this._techniqueConfiguration.receiveAmbientOcclusion=e.bindParameters.ssaoHelper.ready,this._techniqueConfiguration.overlayMode=this.overlayRenderer.isEmpty()?k.Disabled:this.overlayRenderer.hasWater?k.EnabledWithWater:k.Enabled;const t=e.bindParameters.slot===W.OCCLUDED_TERRAIN?O.Occluded:O.ColorAndWater;return this._updateTechnique(j.Color,t===O.Occluded)}case Q.MATERIAL_DEPTH_SHADOWMAP_ALL:case Q.MATERIAL_DEPTH_SHADOWMAP_DEFAULT:return this.castShadows&&1===e.bindParameters.lighting.globalFactor?(this._techniqueConfiguration.receiveShadows=this._techniqueConfiguration.receiveAmbientOcclusion=!1,this._updateTechnique(j.Shadow,!1)):null;case Q.MATERIAL_DEPTH:return this.isTransparent&&this.overlayRenderer.isEmpty()?null:(this._techniqueConfiguration.receiveShadows=this._techniqueConfiguration.receiveAmbientOcclusion=!1,this._updateTechnique(j.Depth,!1));case Q.MATERIAL_NORMAL:return this._techniqueConfiguration.receiveShadows=this._techniqueConfiguration.receiveAmbientOcclusion=!1,this._updateTechnique(j.Normal,!1);case Q.MATERIAL_HIGHLIGHT:return this.needsHighlight?(this._techniqueConfiguration.receiveShadows=this._techniqueConfiguration.receiveAmbientOcclusion=!1,this._updateTechnique(j.Highlight,!1)):null}return null}render(e,t){const i=e.pass,r=1===e.bindParameters.lighting.globalFactor;switch(this._updatePatchGroups(),t.useStencil=!1,i){case Q.MATERIAL:{const i=e.bindParameters.slot===W.OCCLUDED_TERRAIN?O.Occluded:O.ColorAndWater;this._renderMaterialPass(e,t,i);break}case Q.MATERIAL_DEPTH_SHADOWMAP_ALL:case Q.MATERIAL_DEPTH_SHADOWMAP_DEFAULT:this.castShadows&&r&&this._renderAuxiliaryPass(e,t,O.None);break;case Q.MATERIAL_DEPTH:this.isTransparent&&this.overlayRenderer.isEmpty()||this._renderAuxiliaryPass(e,t,O.None);break;case Q.MATERIAL_NORMAL:this._renderAuxiliaryPass(e,t,O.None);break;case Q.MATERIAL_HIGHLIGHT:this.needsHighlight&&(this._renderAuxiliaryPass(e,t,O.Highlight),e.rctx.clearSafe(re.DEPTH_BUFFER_BIT))}this._scaleRangeQueries.hasPendingQueries()&&this.setNeedsRender()}_renderMaterialPass(e,t,i){const{rctx:r}=e;this._passParameters.overlaySource=i,r.bindTechnique(t,this._passParameters,e.bindParameters),this.numTilesRendered=0,this.numTilesCulled=0,this.numOriginsRendered=0,this._scaleRangeQueries.prepareQueries(),this.opaque?this._renderPatchGroups(e,t,i):e.offscreenRenderingHelper.renderToTargets((()=>this._renderPatchGroups(e,t,i)),e.offscreenRenderingHelper.tmpColor,e.offscreenRenderingHelper.mainDepth,[0,0,0,0]),this._scaleRangeQueries.processQueries()}_renderAuxiliaryPass(e,t,i){const r=e.rctx;this._passParameters.overlaySource=i,r.bindTechnique(t,this._passParameters,e.bindParameters),this._renderPatchGroupsAuxiliary(e,t,i)}updateTileBackground(e=null){if(!this.tileRenderer)return;this.tileBackgroundUpdating=!0;const i=()=>{this.tileBackgroundInitialized=!0,this.tileBackgroundUpdating=!1,this._techniqueConfiguration.useGrid=this.tileRenderer.backgroundIsGrid,this._techniqueConfiguration.hasBackgroundColor=!this.tileRenderer.backgroundIsGrid&&r(this.tileRenderer.backgroundColor),this.allTiles.forAll((e=>this.tileRenderer.updateTileTexture(e,y.FADING))),this.setNeedsRender()};if(this._lastBackgroundColorRequest=e,r(e)){const r=t.toUnitRGBA(e);this.tileRenderer.setBackground(r,!1),i()}else R(D).then((e=>{s(this._lastBackgroundColorRequest)&&this.tileRenderer&&(this.tileRenderer.setBackground(e,!0),i())}))}_updatePatchGroups(){if(this.patchGroupsDirty){if(this.highestVisibleLODTile=null,this._rebuildPatchGroups(),this.renderOrder!==C.NONE){const e=Array.from(this._patchGroups.values());e.forEach((e=>N(this.renderOrder,e))),e.sort(((e,t)=>w(e[0],t[0],this.renderOrder))),this._patchGroups=new Map(e.map((e=>[e[0].renderData.localOrigin,e])))}this.patchGroupsDirty=!1}}_rebuildPatchGroups(){const e=this._rootTiles;if(!s(e)){e[0]?.surface.checkAllTileWaterproofness(),this._patchGroups.clear();for(const t of e)this._rebuildPatchGroupsForRootTile(t)}}_rebuildPatchGroupsForRootTile(e){const t=this.tileIterator;for(t.resetOne(e);!t.done;){const e=t.next(),i=e.renderData;if(!i||e.visible)if(e.rendered){if(i){const r=this._patchGroups.get(i.localOrigin)||new Array;this._patchGroups.set(i.localOrigin,r),r.push(e),(!this.highestVisibleLODTile||e.vlevel>this.highestVisibleLODTile.vlevel)&&(this.highestVisibleLODTile=e),t.skipSubtree()}}else this.numTilesCulled++;else this.numTilesCulled++,t.skipSubtree()}}_useStencilForTile(e){for(const t of this.stencilEnabledLayerExtents)if(e.intersectsExtent(t))return!0;return!1}_renderPatchGroupsAuxiliary(e,t,i){const r=this.stencilEnabledLayerExtents.length>0;this._patchGroups.forEach((s=>{const n=s[0].renderData.localOrigin;t.program.bindDraw(new J(n),e.bindParameters);for(let a=0;a<s.length;a++)this._renderPatch(e,t,s[a],se.TRIANGLES,r,i)})),e.rctx.bindVAO(null)}_renderPatchGroups(e,t,i){const n=e.rctx,a=e.bindParameters.camera,o=t.program;if(this._techniqueConfiguration.screenSizePerspective&&this.pointsOfInterest){const e=Y(this.stage.viewingMode,this.ellipsoidRadius),t=this.pointsOfInterest.centerOnSurfaceFrequent.distance;e.update({distance:t,fovY:a.fovY})}const l=this.stencilEnabledLayerExtents.length>0,d=i===O.Occluded;d&&(o.bindTexture("tex",this.emptyTex),o.setUniform1f("blend",1),o.setUniform4fv("texOffsetAndScale",g));const h=r(this.tileRenderer.backgroundColor)?this.tileRenderer.backgroundColor:u;this._techniqueConfiguration.hasBackgroundColor&&o.setUniform3fv("backgroundColor",h);const c=this.wireframe?se.LINES:se.TRIANGLES;this._techniqueConfiguration.textureFadingEnabled&&o.bindTexture("texNext",this.emptyTex),this._patchGroups.forEach((n=>{const a=n[0].renderData.localOrigin;t.program.bindDraw(new J(a),e.bindParameters),this.numOriginsRendered++;for(let h=0;h<n.length;h++){const a=n[h],u=a.renderData.textureReference;if(!s(u)){if(!d){this._scaleRangeQueries.scaleQueriesForTile(a),ce(a.renderData.geometryInfo.uvOffsetAndScale,u.offsetAndScale,le),o.setUniform4fv("texOffsetAndScale",le),o.bindTexture("tex",u.texture.texture);const e=a.renderData.textureFadeFactor,t=e<1?a.renderData.nextTextureReference:null;this._techniqueConfiguration.textureFadingEnabled&&r(t)&&e<1?(ce(a.renderData.geometryInfo.uvOffsetAndScale,t.offsetAndScale,le),o.setUniform1f("fadeFactor",e),o.setUniform4fv("nextTexOffsetAndScale",le),o.setUniform3fv("nextTexOpacities",t.opacities),o.bindTexture("texNext",t.texture.texture)):o.setUniform1f("fadeFactor",1),a.renderData.textureIsFading&&this.setNeedsRender(),o.setUniform3fv("textureOpacities",u.opacities)}this._renderPatch(e,t,a,c,l,i),a.renderOrder=this.numTilesRendered,this.numTilesRendered++}}})),n.bindVAO(null)}_renderPatch(e,t,i,r,n,a){const o=i.renderData,l=o.vao,d=l.indexBuffer;if(s(d))return;const h=t.program;a!==O.None&&this._bindOverlayPatchData(h,o.overlay),n&&(t.useStencil=this._useStencilForTile(i),t.bindPipelineState(e.rctx,e.bindParameters.slot));const c=o.geometryInfo.indexCount;e.rctx.bindVAO(l),h.assertCompatibleVertexAttributeLocations(l),e.rctx.drawElements(r,c,d.indexType,0)}_bindOverlayPatchData(e,t){e.setUniform4fv("overlayTexOffset",t.offsets),e.setUniform4fv("overlayTexScale",t.scales)}_updateTechnique(e,t){return this._techniqueConfiguration.output=e,e===j.Color&&(this._techniqueConfiguration.atmosphere=this.isGlobal&&this._velvetOverground),this._techniqueConfiguration.renderOccluded=t,this._techniqueConfiguration.stencilEnabled=!1,this._shaderTechnique=this._techniqueRepository.releaseAndAcquire(te,this._techniqueConfiguration,this._shaderTechnique),this._shaderTechnique}get test(){return{tileRenderer:this.tileRenderer}}};e([a()],de.prototype,"tileBackgroundInitialized",void 0),e([a()],de.prototype,"tileBackgroundUpdating",void 0),e([a({constructOnly:!0})],de.prototype,"overlayRenderer",void 0),e([a({constructOnly:!0})],de.prototype,"stage",void 0),e([a({readOnly:!0})],de.prototype,"isGlobal",null),e([a({constructOnly:!0})],de.prototype,"allTiles",void 0),e([a({constructOnly:!0})],de.prototype,"ellipsoidRadius",void 0),e([a({readOnly:!0})],de.prototype,"updating",null),e([a({value:!1})],de.prototype,"renderingDisabled",null),e([a()],de.prototype,"renderPatchBorders",null),e([a()],de.prototype,"cullBackFaces",null),e([a({value:C.FRONT_TO_BACK})],de.prototype,"renderOrder",null),e([a()],de.prototype,"wireframe",null),de=e([o("esri.views.3d.terrain.TerrainRenderer")],de);const he=de;function ce(e,t,i){i[0]=e[0]*t[2]+t[0],i[1]=e[1]*t[3]+t[1],i[2]=e[2]*t[2],i[3]=e[3]*t[3]}const ue=p(),pe=p(),ge=p(),fe=p();export{he as default};
|
|
5
|
+
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Color.js";import i from"../../../core/Accessor.js";import{isSome as r,isNone as s}from"../../../core/maybe.js";import n from"../../../core/ObjectPool.js";import{property as a}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/arrayUtils.js";import"../../../core/has.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as o}from"../../../core/accessorSupport/decorators/subclass.js";import{I as l}from"../../../chunks/mat4f64.js";import{b as d,s as h,e as c}from"../../../chunks/vec3.js";import{Z as u,c as p}from"../../../chunks/vec3f64.js";import{Z as g,c as f}from"../../../chunks/vec4f64.js";import{create as m,set as T}from"../../../geometry/support/aaBoundingBox.js";import{BufferViewVec3f as _}from"../../../geometry/support/buffer/BufferView.js";import{requestImage as b}from"../../../support/requestImageUtils.js";import{ViewingMode as R}from"../../ViewingMode.js";import{TextureUpdate as y}from"./interfaces.js";import{LayerClass as A}from"./LayerClass.js";import{OverlaySource as O}from"./Overlay.js";import{overlayRenderOccludedFlag as v}from"./OverlayRenderer.js";import{clearCaches as x}from"./PatchGeometry.js";import{PatchRenderData as P}from"./PatchRenderData.js";import{RenderOrder as E}from"./RenderOrder.js";import{ScaleRangeQueries as C}from"./ScaleRangeQueries.js";import{DEFAULT_TILE_BACKGROUND as D}from"./TerrainConst.js";import"./terrainUtils.js";import{TileRenderer as q}from"./TileRenderer.js";import{TileUpdate as S}from"./TileUpdate.js";import{IteratorPreorder as I,sortTiles as N,compareTiles as w}from"./tileUtils.js";import{componentMinimalSizeForIntersectionData as L,ComponentIntersectionData as k}from"../webgl-engine/collections/Component/ComponentIntersectionData.js";import{ShaderOutput as G}from"../webgl-engine/core/shaderLibrary/ShaderOutputOptions.js";import{OverlayMode as j}from"../webgl-engine/core/shaderLibrary/terrain/Overlay.glsl.js";import{T as B}from"../../../chunks/Terrain.glsl.js";import{RenderRequestType as U}from"../webgl-engine/lib/basicInterfaces.js";import{createEmptyTexture as F}from"../webgl-engine/lib/glUtil3D.js";import{newIntersectorResult as M}from"../webgl-engine/lib/Intersector.js";import{IntersectorType as H,StoreResults as z}from"../webgl-engine/lib/IntersectorInterfaces.js";import{RenderOccludedFlag as V}from"../webgl-engine/lib/Material.js";import{RenderPass as Q}from"../webgl-engine/lib/RenderPass.js";import{RenderSlot as W}from"../webgl-engine/lib/RenderSlot.js";import{getSettings as Y}from"../webgl-engine/lib/screenSizePerspectiveUtils.js";import{VertexAttribute as X}from"../webgl-engine/lib/VertexAttribute.js";import{TERRAIN_ID as Z,getVerticalOffsetTerrain as K}from"../webgl-engine/lib/verticalOffsetUtils.js";import{DrawParameters as J}from"../webgl-engine/materials/DrawParameters.js";import{intersectAabbInvDirBefore as $,intersectTriangles as ee}from"../webgl-engine/materials/internal/MaterialUtil.js";import{TerrainTechnique as te}from"../webgl-engine/shaders/TerrainTechnique.js";import{TerrainTechniqueConfiguration as ie}from"../webgl-engine/shaders/TerrainTechniqueConfiguration.js";import{ClearBufferBit as re,PrimitiveType as se}from"../../webgl/enums.js";const ne=7,ae=10,oe=m(),le=f();let de=class extends i{constructor(e){super(e),this.type=H.TERRAIN,this.isGround=!0,this.tileSize=256,this._passParameters=new B,this.rctx=null,this._isTransparent=!1,this._scaleRangeQueries=new C,this.renderDataPool=new n(P),this._patchGroups=new Map,this.patchGroupsDirty=!0,this.tileIterator=new I,this.highestVisibleLODTile=null,this.visible=!0,this._opaque=!0,this._velvetOverground=!0,this.castShadows=!0,this.emptyTex=null,this.tileRenderer=null,this.tileBackgroundInitialized=!1,this.tileBackgroundUpdating=!1,this.stencilEnabledLayerExtents=[],this.numTilesRendered=0,this.numTilesCulled=0,this.numOriginsRendered=0,this.needsHighlight=!1,this.renderOccludedFlags=V.Occlude}get isGlobal(){return this.stage.viewingMode===R.Global}initialize(){const e=[W.OPAQUE_TERRAIN,W.TRANSPARENT_TERRAIN,W.OCCLUDED_TERRAIN];this.stage.addRenderPlugin(e,this)}destroy(){this.stage.removeRenderPlugin(this),x()}get updating(){return!this.tileBackgroundInitialized||this.tileBackgroundUpdating}get canRender(){return this.visible&&!!this._rootTiles&&this.tileBackgroundInitialized&&!this.renderingDisabled}set renderingDisabled(e){this._set("renderingDisabled",!!e),this.setNeedsRender()}set opaque(e){this._opaque!==e&&(this._opaque=e,this.setNeedsRender())}get opaque(){return this._opaque&&!this._techniqueConfiguration.hasSlicePlane}get needsLinearDepth(){return this.overlayRenderer.hasWater}set isTransparent(e){this._isTransparent!==e&&(this._isTransparent=e,this.setNeedsRender())}get isTransparent(){return this._isTransparent}get renderPatchBorders(){return!!this._techniqueConfiguration.tileBorders}set renderPatchBorders(e){this._techniqueConfiguration.tileBorders!==e&&(this._techniqueConfiguration.tileBorders=e,this.setNeedsRender(),this.notifyChange("renderPatchBorders"))}get cullBackFaces(){return this._techniqueConfiguration.backfaceCullingEnabled}set cullBackFaces(e){this._techniqueConfiguration.backfaceCullingEnabled!==e&&(this._techniqueConfiguration.backfaceCullingEnabled=e,this.notifyChange("cullBackFaces"),this.setNeedsRender())}set renderOrder(e){this._set("renderOrder",e),this.setNeedsRender()}set velvetOverground(e){this._velvetOverground!==e&&(this._velvetOverground=e,this.setNeedsRender())}get layerUid(){return Z}get slicePlaneEnabled(){return this._techniqueConfiguration.hasSlicePlane}set slicePlaneEnabled(e){this._techniqueConfiguration.hasSlicePlane!==e&&(this._techniqueConfiguration.hasSlicePlane=e,this.setNeedsRender())}set textureFadingEnabled(e){this._techniqueConfiguration.textureFadingEnabled!==e&&(this._techniqueConfiguration.textureFadingEnabled=e,this.setNeedsRender())}setDebugScreenSizePerspective(e){this._techniqueConfiguration.screenSizePerspective!==e&&(this._techniqueConfiguration.screenSizePerspective=e,this.setNeedsRender())}setRootTiles(e){this._rootTiles=e,this.setNeedsRender()}setNeedsHighlight(e){this.needsHighlight=e,this.setNeedsRender()}setRenderOccludedOverlay(e){this.renderOccludedFlags=e?v:V.Occlude,this.setNeedsRender()}setStencilEnabledLayerExtents(e){this.stencilEnabledLayerExtents=e,this.setNeedsRender()}setTileSize(e){this.tileSize=e,this.tileRenderer&&(this.tileRenderer.tileSize=e),this.setNeedsRender()}_prepareTileForLoading(e){e.renderData||(e.renderData=this.renderDataPool.acquire(),e.renderData.init(e),e.renderData.localOrigin=this._getLocalOriginOfTile(e))}loadTile(e){this._prepareTileForLoading(e),this.updateTileGeometry(e),this.updateTileTexture(e,S.TEXTURE_FADING)}queryVisibleLevelRange(e,t,i,r){this._scaleRangeQueries.queryVisibleLevelRange(e,t,i,r),this.setNeedsRender()}updateTileTexture(e,t){this.tileRenderer&&this.tileBackgroundInitialized&&(this.tileRenderer.updateTileTexture(e,t===S.TEXTURE_FADING?y.FADING:y.UNFADED),this.setNeedsRender(),e.resetPendingUpdate(t))}updateTileGeometryState(e){this._prepareTileForLoading(e),e.renderData.updateGeometryStateAndPrepareForGeometryGeneration(this.wireframe)}updateTileGeometry(e){for(const t of e.layerInfo[A.ELEVATION])t.pendingUpdates&=~S.GEOMETRY;e.resetPendingUpdate(S.GEOMETRY);e.renderData.updateGeometryIfChanged(this.rctx,this.wireframe)&&this.setNeedsRender()}unloadTile(e){const t=e.renderData;t&&(t.releaseGeometry(),this.renderDataPool.release(t),t.clear(),e.renderData=null,e.setMemoryDirty(),this.setNeedsRender())}_getLocalOriginOfTile(e){const t=ae-ne,i=Math.max(0,Math.floor((e.level-t)/ne)*ne);if(this.isGlobal&&0===i)return u;for(;e.parent&&e.level>i;)e=e.parent;return e.centerAtSeaLevel}setVisibility(e){this.visible=e,this.setNeedsRender()}getStats(){return{numTilesRendered:this.numTilesRendered,numTilesCulled:this.numTilesCulled,numOriginsRendered:this.numOriginsRendered}}set wireframe(e){this._get("wireframe")!==e&&(this._set("wireframe",e),this.allTiles.forAll((e=>{e.isLoaded&&(this.updateTileGeometry(e),e.updateNeighborsAfterGeometryChange())})),this.setNeedsRender())}setNeedsRender(e=U.UPDATE){this.patchGroupsDirty=!0,this._context.requestRender(e)}setTileBackground(e){this.tileBackground=e,this._updateTileBackground()}initializeRenderContext(e){this._context=e,this.rctx=e.renderContext.rctx,this._techniqueRepository=e.shaderTechniqueRepository,this._techniqueConfiguration=new ie,this.tileRenderer=new q(this.rctx,this.tileSize,this._techniqueRepository),this.tileBackground&&this._updateTileBackground(),this.emptyTex=F(this.rctx)}uninitializeRenderContext(){null!=this.emptyTex&&(this.emptyTex.dispose(),this.emptyTex=null),this.tileRenderer&&(this.tileRenderer.dispose(),this.tileRenderer=null)}intersect(e,t,i,n){if(!this._rootTiles||e.options.selectOpaqueTerrainOnly&&e.options.selectionMode&&!this._opaque)return;const a=ue,o=pe;d(a,n,i),h(o,1/a[0],1/a[1],1/a[2]);const u=e.results.min,p=e.results.max,g=e.results.ground,f=e.options.store===z.MIN,m=!!e.results.ground.target,b=K(e.verticalOffset),R=e.tolerance;let y,A=f&&r(u.dist)?u.dist:1/0;const O=h=>{const m=h.renderData;if(!m?.vao)return;const O=m.geometryInfo;T(oe,O.boundingBox);const v=m.localOrigin;r(b)&&(b.localOrigin=v,b.applyToAabb(oe));const x=oe;if(ge[0]=i[0]-v[0],ge[1]=i[1]-v[1],ge[2]=i[2]-v[2],!$(x,ge,o,R,A))return;const P=(e,t,i)=>{e.set(this.type,h,t,i,l),A=f&&r(u.dist)?u.dist:1/0},E=(o,l)=>{if(r(l)&&o>=0&&(e.options.backfacesTerrain||c(l,a)<0)&&(e.options.invisibleTerrain||!e.options.selectionMode||null==t||t(i,n,o))){if((null==g.dist||o<g.dist)&&P(g,o,l),e.options.isFiltered)return;e.options.store===z.ALL&&(s(y)?(y=M(e.ray),P(y,o,l),e.results.all.push(y)):o<y.dist&&P(y,o,l)),(null==u.dist||o<u.dist)&&P(u,o,l),e.options.store!==z.MIN&&(null==p.dist||o>p.dist)&&P(p,o,l)}},C=fe;d(C,n,v);const D=O.indices,q=O.vertexAttributes,S={data:q.getField(X.POSITION,_).typedBuffer,size:3,stride:q.stride/4},I=O.indexCount/3;if(s(b)&&I>L){const e=h.renderData;s(e.intersectionData)&&(e.intersectionData=new k(D,0,I,S)),e.intersectionData.intersectRay({r0:ge,r1:C},E)}else ee(ge,C,0,I,D,S,null,b,E)},v=this._rootTiles;if(r(v)){(()=>{const t=this.tileIterator;t.reset(v);const s=e.options.invisibleTerrain;for(;!t.done;){const e=t.next();!(e.visible||s&&e.intersectsClippingArea)||!r(b)&&!e.intersectsRay(i,a,R,A)||m&&this._useStencilForTile(e)?t.skipSubtree():O(e)}})()}}prepareTechnique(e){if(e.bindParameters.slot===W.OCCLUDED_TERRAIN){if(0==(e.renderOccludedMask&v))return null}else{const t=this.opaque?W.OPAQUE_TERRAIN:W.TRANSPARENT_TERRAIN;if(e.bindParameters.slot!==t)return null}switch(e.pass){case Q.MATERIAL:{this._techniqueConfiguration.hasScreenSpaceReflections=e.bindParameters.ssr.enabled,this._techniqueConfiguration.hasCloudsReflections=r(e.bindParameters.cloudsComposition.clouds),this._techniqueConfiguration.receiveShadows=e.bindParameters.shadowMap.ready,this._techniqueConfiguration.receiveAmbientOcclusion=e.bindParameters.ssaoHelper.ready,this._techniqueConfiguration.overlayMode=this.overlayRenderer.isEmpty()?j.Disabled:this.overlayRenderer.hasWater?j.EnabledWithWater:j.Enabled;const t=e.bindParameters.slot===W.OCCLUDED_TERRAIN?O.Occluded:O.ColorAndWater;return this._updateTechnique(G.Color,t===O.Occluded)}case Q.MATERIAL_DEPTH_SHADOWMAP_ALL:case Q.MATERIAL_DEPTH_SHADOWMAP_DEFAULT:return this.castShadows&&1===e.bindParameters.lighting.globalFactor?(this._techniqueConfiguration.receiveShadows=this._techniqueConfiguration.receiveAmbientOcclusion=!1,this._updateTechnique(G.Shadow,!1)):null;case Q.MATERIAL_DEPTH:return this.isTransparent&&this.overlayRenderer.isEmpty()?null:(this._techniqueConfiguration.receiveShadows=this._techniqueConfiguration.receiveAmbientOcclusion=!1,this._updateTechnique(G.Depth,!1));case Q.MATERIAL_NORMAL:return this._techniqueConfiguration.receiveShadows=this._techniqueConfiguration.receiveAmbientOcclusion=!1,this._updateTechnique(G.Normal,!1);case Q.MATERIAL_HIGHLIGHT:return this.needsHighlight?(this._techniqueConfiguration.receiveShadows=this._techniqueConfiguration.receiveAmbientOcclusion=!1,this._updateTechnique(G.Highlight,!1)):null}return null}render(e,t){const i=e.pass,r=1===e.bindParameters.lighting.globalFactor;switch(this._updatePatchGroups(),t.useStencil=!1,i){case Q.MATERIAL:{const i=e.bindParameters.slot===W.OCCLUDED_TERRAIN?O.Occluded:O.ColorAndWater;this._renderMaterialPass(e,t,i);break}case Q.MATERIAL_DEPTH_SHADOWMAP_ALL:case Q.MATERIAL_DEPTH_SHADOWMAP_DEFAULT:this.castShadows&&r&&this._renderAuxiliaryPass(e,t,O.None);break;case Q.MATERIAL_DEPTH:this.isTransparent&&this.overlayRenderer.isEmpty()||this._renderAuxiliaryPass(e,t,O.None);break;case Q.MATERIAL_NORMAL:this._renderAuxiliaryPass(e,t,O.None);break;case Q.MATERIAL_HIGHLIGHT:this.needsHighlight&&(this._renderAuxiliaryPass(e,t,O.Highlight),e.rctx.clearSafe(re.DEPTH_BUFFER_BIT))}this._scaleRangeQueries.hasPendingQueries()&&this.setNeedsRender()}_renderMaterialPass(e,t,i){const{rctx:r}=e;this._passParameters.overlaySource=i,r.bindTechnique(t,this._passParameters,e.bindParameters),this.numTilesRendered=0,this.numTilesCulled=0,this.numOriginsRendered=0,this._scaleRangeQueries.prepareQueries(),this.opaque?this._renderPatchGroups(e,t,i):e.offscreenRenderingHelper.renderToTargets((()=>this._renderPatchGroups(e,t,i)),e.offscreenRenderingHelper.tmpColor,e.offscreenRenderingHelper.mainDepth,[0,0,0,0]),this._scaleRangeQueries.processQueries()}_renderAuxiliaryPass(e,t,i){const r=e.rctx;this._passParameters.overlaySource=i,r.bindTechnique(t,this._passParameters,e.bindParameters),this._renderPatchGroupsAuxiliary(e,t,i)}_updateTileBackground(){if(!this.tileRenderer)return;this.tileBackgroundUpdating=!0;const e=()=>{this.tileBackgroundInitialized=!0,this.tileBackgroundUpdating=!1,this._techniqueConfiguration.useGrid=this.tileRenderer.backgroundIsGrid,this._techniqueConfiguration.hasBackgroundColor=!this.tileRenderer.backgroundIsGrid&&r(this.tileRenderer.backgroundColor),this.allTiles.forAll((e=>this.tileRenderer.updateTileTexture(e,y.FADING))),this.setNeedsRender()};if("string"==typeof this.tileBackground){const t=this.tileBackground;b(t).then((i=>{t===this.tileBackground&&this.tileRenderer&&(this.tileRenderer.setBackground(i,this.tileBackground===D),e())}))}else{const i=this.tileBackground?t.toUnitRGBA(this.tileBackground):[0,0,0,0];this.tileRenderer.setBackground(i,!1),e()}}_updatePatchGroups(){if(this.patchGroupsDirty){if(this.highestVisibleLODTile=null,this._rebuildPatchGroups(),this.renderOrder!==E.NONE){const e=Array.from(this._patchGroups.values());e.forEach((e=>N(this.renderOrder,e))),e.sort(((e,t)=>w(e[0],t[0],this.renderOrder))),this._patchGroups=new Map(e.map((e=>[e[0].renderData.localOrigin,e])))}this.patchGroupsDirty=!1}}_rebuildPatchGroups(){const e=this._rootTiles;if(!s(e)){e[0]?.surface.checkAllTileWaterproofness(),this._patchGroups.clear();for(const t of e)this._rebuildPatchGroupsForRootTile(t)}}_rebuildPatchGroupsForRootTile(e){const t=this.tileIterator;for(t.resetOne(e);!t.done;){const e=t.next(),i=e.renderData;if(!i||e.visible)if(e.rendered){if(i){const r=this._patchGroups.get(i.localOrigin)||new Array;this._patchGroups.set(i.localOrigin,r),r.push(e),(!this.highestVisibleLODTile||e.vlevel>this.highestVisibleLODTile.vlevel)&&(this.highestVisibleLODTile=e),t.skipSubtree()}}else this.numTilesCulled++;else this.numTilesCulled++,t.skipSubtree()}}_useStencilForTile(e){for(const t of this.stencilEnabledLayerExtents)if(e.intersectsExtent(t))return!0;return!1}_renderPatchGroupsAuxiliary(e,t,i){const r=this.stencilEnabledLayerExtents.length>0;this._patchGroups.forEach((s=>{const n=s[0].renderData.localOrigin;t.program.bindDraw(new J(n),e.bindParameters);for(let a=0;a<s.length;a++)this._renderPatch(e,t,s[a],se.TRIANGLES,r,i)})),e.rctx.bindVAO(null)}_renderPatchGroups(e,t,i){const n=e.rctx,a=e.bindParameters.camera,o=t.program;if(this._techniqueConfiguration.screenSizePerspective&&this.pointsOfInterest){const e=Y(this.stage.viewingMode,this.ellipsoidRadius),t=this.pointsOfInterest.centerOnSurfaceFrequent.distance;e.update({distance:t,fovY:a.fovY})}const l=this.stencilEnabledLayerExtents.length>0,d=i===O.Occluded;d&&(o.bindTexture("tex",this.emptyTex),o.setUniform1f("blend",1),o.setUniform4fv("texOffsetAndScale",g));const h=r(this.tileRenderer.backgroundColor)?this.tileRenderer.backgroundColor:u;this._techniqueConfiguration.hasBackgroundColor&&o.setUniform3fv("backgroundColor",h);const c=this.wireframe?se.LINES:se.TRIANGLES;this._techniqueConfiguration.textureFadingEnabled&&o.bindTexture("texNext",this.emptyTex),this._patchGroups.forEach((n=>{const a=n[0].renderData.localOrigin;t.program.bindDraw(new J(a),e.bindParameters),this.numOriginsRendered++;for(let h=0;h<n.length;h++){const a=n[h],u=a.renderData.textureReference;if(!s(u)){if(!d){this._scaleRangeQueries.scaleQueriesForTile(a),ce(a.renderData.geometryInfo.uvOffsetAndScale,u.offsetAndScale,le),o.setUniform4fv("texOffsetAndScale",le),o.bindTexture("tex",u.texture.texture);const e=a.renderData.textureFadeFactor,t=e<1?a.renderData.nextTextureReference:null;this._techniqueConfiguration.textureFadingEnabled&&r(t)&&e<1?(ce(a.renderData.geometryInfo.uvOffsetAndScale,t.offsetAndScale,le),o.setUniform1f("fadeFactor",e),o.setUniform4fv("nextTexOffsetAndScale",le),o.setUniform3fv("nextTexOpacities",t.opacities),o.bindTexture("texNext",t.texture.texture)):o.setUniform1f("fadeFactor",1),a.renderData.textureIsFading&&this.setNeedsRender(),o.setUniform3fv("textureOpacities",u.opacities)}this._renderPatch(e,t,a,c,l,i),a.renderOrder=this.numTilesRendered,this.numTilesRendered++}}})),n.bindVAO(null)}_renderPatch(e,t,i,r,n,a){const o=i.renderData,l=o.vao,d=l.indexBuffer;if(s(d))return;const h=t.program;a!==O.None&&this._bindOverlayPatchData(h,o.overlay),n&&(t.useStencil=this._useStencilForTile(i),t.bindPipelineState(e.rctx,e.bindParameters.slot));const c=o.geometryInfo.indexCount;e.rctx.bindVAO(l),h.assertCompatibleVertexAttributeLocations(l),e.rctx.drawElements(r,c,d.indexType,0)}_bindOverlayPatchData(e,t){e.setUniform4fv("overlayTexOffset",t.offsets),e.setUniform4fv("overlayTexScale",t.scales)}_updateTechnique(e,t){return this._techniqueConfiguration.output=e,e===G.Color&&(this._techniqueConfiguration.atmosphere=this.isGlobal&&this._velvetOverground),this._techniqueConfiguration.renderOccluded=t,this._techniqueConfiguration.stencilEnabled=!1,this._shaderTechnique=this._techniqueRepository.releaseAndAcquire(te,this._techniqueConfiguration,this._shaderTechnique),this._shaderTechnique}get test(){return{tileRenderer:this.tileRenderer}}};e([a()],de.prototype,"tileBackgroundInitialized",void 0),e([a()],de.prototype,"tileBackgroundUpdating",void 0),e([a({constructOnly:!0})],de.prototype,"overlayRenderer",void 0),e([a({constructOnly:!0})],de.prototype,"stage",void 0),e([a({readOnly:!0})],de.prototype,"isGlobal",null),e([a({constructOnly:!0})],de.prototype,"allTiles",void 0),e([a({constructOnly:!0})],de.prototype,"ellipsoidRadius",void 0),e([a({readOnly:!0})],de.prototype,"updating",null),e([a({value:!1})],de.prototype,"renderingDisabled",null),e([a()],de.prototype,"renderPatchBorders",null),e([a()],de.prototype,"cullBackFaces",null),e([a({value:E.FRONT_TO_BACK})],de.prototype,"renderOrder",null),e([a()],de.prototype,"wireframe",null),de=e([o("esri.views.3d.terrain.TerrainRenderer")],de);const he=de;function ce(e,t,i){i[0]=e[0]*t[2]+t[0],i[1]=e[1]*t[3]+t[1],i[2]=e[2]*t[2],i[3]=e[3]*t[3]}const ue=p(),pe=p(),ge=p(),fe=p();export{he as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Color.js";import i from"../../../core/Accessor.js";import{difference as r}from"../../../core/arrayUtils.js";import s from"../../../core/CollectionFlattener.js";import a from"../../../core/Evented.js";import n from"../../../core/Handles.js";import l from"../../../core/Logger.js";import{clamp as o}from"../../../core/mathUtils.js";import{releaseMaybe as h,destroyMaybe as d,isNone as p,isSome as u}from"../../../core/maybe.js";import c from"../../../core/ObjectPool.js";import _ from"../../../core/PooledArray.js";import{isAbortError as g,isAborted as m,createAbortError as f}from"../../../core/promiseUtils.js";import{watch as T,syncAndInitial as y,sync as v,initial as w}from"../../../core/reactiveUtils.js";import{aliasOf as S}from"../../../core/accessorSupport/decorators/aliasOf.js";import"../../../core/has.js";import"../../../core/accessorSupport/ensureType.js";import{property as L}from"../../../core/accessorSupport/decorators/property.js";import{subclass as E}from"../../../core/accessorSupport/decorators/subclass.js";import{m as b}from"../../../chunks/mat4.js";import{c as x}from"../../../chunks/mat4f64.js";import{c as D}from"../../../chunks/vec3.js";import{c as U}from"../../../chunks/vec3f64.js";import{c as P}from"../../../chunks/vec4f64.js";import{WatchUpdatingTracking as R}from"../../../core/support/WatchUpdatingTracking.js";import{projectVectorToVector as C,projectPointToVector as j}from"../../../geometry/projection.js";import{getReferenceEllipsoid as M}from"../../../geometry/projectionEllipsoid.js";import{create as A,equals as I,intersection as V,empty as O,expand as k,intersectsSphere as N}from"../../../geometry/support/aaBoundingRect.js";import{create as q,copy as B}from"../../../geometry/support/frustum.js";import{isPlateCarree as G}from"../../../geometry/support/spatialReferenceUtils.js";import{isRefreshableLayer as W}from"../../../layers/mixins/RefreshableLayer.js";import{ElevationQueryTileCache as F}from"../../../layers/support/ElevationQueryTileCache.js";import{isBaseLayer as H}from"../../../layers/support/layerUtils.js";import{acquireDecoder as Q}from"../../../layers/support/LercDecoder.js";import{printAllocations as X}from"../../2d/engine/vectorTiles/VectorTile.js";import{directionToHeadingTilt as z,scaleToZoom as Y}from"../support/cameraUtils.js";import $ from"../support/debugFlags.js";import{toBoundingRect as K}from"../support/extentUtils.js";import{ClientType as J}from"../support/index.js";import{updatingProgress as Z}from"../support/updatingProperties.js";import{ElevationBounds as ee}from"./ElevationBounds.js";import{sampleElevation as te,ElevationData as ie}from"./ElevationData.js";import{create as re}from"./ExtentHelper.js";import{LODSnapping as se,TextureUpdate as ae}from"./interfaces.js";import{LayerClass as ne,LayerClasses as le}from"./LayerClass.js";import{OverlayManager as oe}from"./OverlayManager.js";import{PlanarPatch as he}from"./PlanarPatch.js";import{RenderOrder as de}from"./RenderOrder.js";import{SphericalPatch as pe}from"./SphericalPatch.js";import{MAX_ROOT_TILES as ue,TOO_MANY_ROOT_TILES_AFTER_CHANGE_ERROR as ce,TOO_MANY_ROOT_TILES_FOR_LAYER_ERROR as _e,MAX_MEMORY_LOD_BIAS as ge,ELEVATION_NODATA_VALUE as me}from"./TerrainConst.js";import fe from"./TerrainRenderer.js";import Te from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as ye,internalAssert as ve,isSurfaceLayerView as we,isMapTileLayerView as Se,isElevationLayerView as Le,isBlendableLayerView as Ee,isVectorTileLayerView as be,useFetchTileForLayer as xe,isImageryTileLayerView as De,isTileLayerView as Ue,releaseTileData as Pe,ENABLE_WATERPROOFNESS_TESTS as Re}from"./terrainUtils.js";import{SplitLimits as Ce,Tile as je}from"./Tile.js";import{printAllocations as Me}from"./TilePerLayerInfo.js";import{TileUpdate as Ae}from"./TileUpdate.js";import{IteratorPreorder as Ie,IteratorPostorder as Ve,hasLoadableSiblings as Oe,sortTilesByPOI as ke,sortTiles as Ne}from"./tileUtils.js";import{TilingSchemeLogic as qe}from"./TilingSchemeLogic.js";import{UpsampleInfo as Be}from"./UpsampleInfo.js";import{RenderRequestType as Ge}from"../webgl-engine/lib/basicInterfaces.js";import{ImmediateTask as We,TaskPriority as Fe,noBudget as He}from"../../support/Scheduler.js";const Qe=l.getLogger("esri.views.3d.terrain.TerrainSurface"),Xe=.25;let ze=class extends(a.EventedMixin(i)){constructor(e){super(e),this._elevationBounds=new ee,this._iteratorPool=new c(Ie,(e=>e.remove=()=>this._iteratorPool.release(e))),this._postorderIterator=new Ve,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._visible=!1,this._usedMemory=Ze,this._performanceInfo=new Te,this._viewChanged=!1,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=U(),this._eyePosSurfaceSR=U(),this._splitLimits=new Ce,this._snapLevel=1/0,this._frustum=q(),this._viewProjectionMatrix=x(),this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._handles=new n,this._watchUpdatingTracking=new R,this._frameTask=We,this._allTiles=new _,this._upsampleInfoPool=new c(Be),this.isWebMercator=!1,this.isWebMercatorOnPlateeCarree=!1,this._rootTilesExtent=A(),this._maxNumUpdating=1,this.maxTextureScale=1.2,this.backgroundColor=null,this._updatingRootTiles=!1,this.deferTileNeighborUpdate=!1,this.neighborTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._layerViewsDirty=!1,this._isGlobal=!e.view?.state?.isLocal}initialize(){this._lercDecoder=Q(this.view.resourceController),this._tilePool=this.view.state.isLocal?new c(he):new c(pe);const e=this.view.resourceController.memoryController;this._upsampleMapCache=e.newCache("esri.views.3d.terrain.upsample",(e=>e.unloadMapData())),this._elevationQueryCache=new F(e.newCache("elevation-query")),this._set("overlayManager",new oe({surface:this})),this._handles.add([T((()=>this.overlayManager.hasHighlights),(e=>this._renderer.setNeedsHighlight(e))),T((()=>this.overlayManager.rendersOccluded),(e=>this._renderer.setRenderOccludedOverlay(e)))],"overlayManager"),this._renderer=new fe({overlayRenderer:this.overlayManager.renderer,ellipsoidRadius:M(this.view.spatialReference).radius,stage:this.view._stage,allTiles:this._allTiles}),this._handles.add([T((()=>this.baseOpacity),(e=>{this._handleLayerViewChanges(),this._updateBaseOpacity(e)}),y),T((()=>this.renderingDisabled),(()=>this._updateTransparentTerrain()),v),T((()=>this.backgroundColor),(()=>{this._handleLayerViewChanges(),this._renderer.updateTileBackground(this.backgroundColor)}),y),T((()=>this.view.pointsOfInterest),(e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add((()=>e.focus.renderLocation),(()=>()=>this._allTilesSorted=!1))})),T((()=>$.TERRAIN_TILE_TREE_SHOW_TILES),(e=>{e&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then((({TerrainTileTree3DDebugger:e})=>{!this._treeDebugger&&$.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new e({view:this.view}))})):e||(this._treeDebugger=d(this._treeDebugger))}),w)]),this._extentHelper=re(this.viewingMode,{layers:this.view.map.allLayers,layerViews:this.view.allLayerViews,viewSpatialReference:this.view.spatialReference});const t=this.view.defaultsFromMap?new s({getCollections:()=>this.view?.defaultsFromMap?.mapCollections?.map((({layers:e})=>e)),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}):this.view.map.allLayers,i=new qe({layers:t,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:this.view.spatialReference});this._set("tilingSchemeLogic",i),this._updateTilingScheme(),this._elevationDataRequester=this.view.resourceController.createStreamDataRequester(J.ELEVATION),this._mapDataRequester=this.view.resourceController.createStreamDataRequester(J.BASEMAP);const r=this.view.resourceController.scheduler;this._frameTask=r.registerTask(Fe.TERRAIN_SURFACE,this),this._handles.add([T((()=>this._extentHelper.stencilEnabledExtents),(e=>this._renderer.setStencilEnabledLayerExtents(e)),w),T((()=>this.tilingSchemeLogic.tilingScheme),(()=>this._updateTilingScheme()),v),T((()=>this.extent),(()=>this._updateRootTiles()),w),this.view.on("resize",(()=>this._viewChangeUpdate())),T((()=>{const e=this.view,t=e.state;return[this.lodBias,this.lodSnapping,e.resourceController?.memoryController?.memoryFactor,t.camera,t.contentCamera,t.fixedContentCamera]}),(()=>this._viewChangeUpdate()),y),T((()=>this.view.qualitySettings?.tiledSurface?.textureFadeDuration),(e=>this._renderer.textureFadingEnabled=e>0),w),T((()=>this._userClippingExtent),(()=>this._updateClippingExtent()),v)]),this._handles.add(this.view.allLayerViews.on("after-changes",(()=>this._layerViewsDirty=!0))),this._layerViewsDirty=!0,this._handleLayerViewChanges()}destroy(){this._frameTask.remove(),this._handles.destroy(),this._watchUpdatingTracking.destroy(),this._lercDecoder=h(this._lercDecoder),this._removeAllTiles(),this._upsampleMapCache=d(this._upsampleMapCache),this._elevationQueryCache=d(this._elevationQueryCache),this._set("tilingSchemeLogic",d(this.tilingSchemeLogic)),this._extentHelper=d(this._extentHelper),this._basemapLayerViewHandles.forEach(((e,t)=>this._unregisterTiledLayerView(t))),this._elevationDataRequester=null,this._mapDataRequester=null,this._set("overlayManager",d(this.overlayManager)),this._tilePool=d(this._tilePool),je.prune(),this._treeDebugger&&(this._treeDebugger.destroy(),this._treeDebugger=null),this._renderer=d(this._renderer),this._iteratorPool=d(this._iteratorPool),this._set("view",null),this._upsampleInfoPool=d(this._upsampleInfoPool),X(),Me()}get renderer(){return this._renderer}get frustum(){return this._frustum}get snapLevel(){const e=this.view.pointsOfInterest?.contentCameraOnSurface?.scale;if(e){const t=this.view.state.contentCamera;let i=z(this.view,t.eye,t.viewForward,t.up).tilt;i>90&&(i=180-i);const r=2*(i/90)**2,s=Y(this.view,e)-r;Math.abs(this._snapLevel-s)>Xe&&(Math.round(s)!==Math.round(this._snapLevel)&&(this._viewChanged=!0),this._snapLevel=s)}return Math.round(this._snapLevel)}get lodSnapping(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences?se.ON:se.OFF}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get mapTileRequester(){return this._mapDataRequester}get _userClippingExtent(){const{spatialReference:e}=this,{clippingArea:t}=this.view;if(p(t)||p(e))return null;const i=A(),r=K(t,i,e)?i:null,s=this._get("extent");return I(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get extent(){const e=V(this.groundExtent,this._userClippingExtent,A()),t=this._get("extent");return I(e,t)?t:e}get groundExtent(){return u(this._tilingSchemeExtent)?this._tilingSchemeExtent:this._rootTilesExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),!!((this._watchUpdatingTracking.updating||this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||this._asyncWorkItems>0||!this._allTilesSorted||this._renderer.updating||this._layerViewsDirty)&&this.ready&&!this.suspended||this.overlayManager.updating||this._frameTask.updating)}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get viewingMode(){return this.view.state.viewingMode}get ready(){return u(this.rootTiles)}set renderOrder(e){this._renderer.renderOrder=e,this._set("renderOrder",e)}get spatialReference(){return this.tilingScheme?.spatialReference??null}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set("slicePlaneEnabled",e),this._updateTransparentTerrain()}_updateTransparentTerrain(){const e=!this.renderingDisabled&&!this.opaque;this.view?._stage?.renderView.setRenderParameters({transparentTerrain:e})}set velvetOverground(e){e!==this.velvetOverground&&(this._renderer.velvetOverground=e),this._set("velvetOverground",e)}set visible(e){e!==this._visible&&(this._visible=e,this._renderer.setVisibility(e),this.suspended=!e)}get opaque(){return this._renderer.opaque}set suspended(e){this._set("suspended",e),this._viewChangeUpdate()}intersect(e,t,i,r){this._renderer.intersect(e,t,i,r)}getElevation(e,t,i,r){const s=this.getTileWithElevation(e,t,i,r,et);return p(s)?null:te(et[0],et[1],s.renderData.geometryState.samplerData)}getTileWithElevation(e,t,i,r,s=et){const a=this.rootTiles;if(p(a)||!a.length)return null;if(0===a[0].layerInfo[ne.ELEVATION].length)return null;if(s[0]=e,s[1]=t,s[2]=i,!C(s,r,s,this.tilingScheme?.spatialReference))return Qe.error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;for(let n of a){if(!n.containsPoint(s))continue;for(;n&&!n.rendered&&!n.isLeaf;){let e=0;s[0]>.5*(n.extent[0]+n.extent[2])&&(e+=1),s[1]<.5*(n.extent[1]+n.extent[3])&&(e+=2),n=n.children[e]}const e=n.renderData;return(e?e.geometryState.samplerData:null)?n:null}return null}get elevationBounds(){return this._elevationBounds}getScale(e){if(this.tilingScheme){if(!j(e,et,this.spatialReference))return Qe.error("TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system"),null;const t=this.rootTiles;if(u(t))for(let e of t)if(e.containsPoint(et)){for(;null!=e.children[0];){let t=0;et[0]>e.children[0].extent[2]&&(t+=1),et[1]<e.children[0].extent[1]&&(t+=2),e=e.children[t]}return this._getLodBiasCorrectedScale(e.level)}}return 1e100}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!j(e,et,this.spatialReference))return Qe.error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;et[3]=t;let i=null;const r=e=>{if(e&&N(e.extent,et))if(null!=e.children[0])for(const t of e.children)r(t);else{const t=this._getLodBiasCorrectedScale(e.level);i=null==i?t:Math.min(i,t)}},s=this.rootTiles;if(u(s))for(const a of s)r(a);return i}queryVisibleScaleRange(e,t,i,r){const s=t?this.tilingScheme.levelAtScale(t):0,a=i?this.tilingScheme.levelAtScale(i):1/0,n=this.lodBias;this._renderer.queryVisibleLevelRange(e,s+n,a+n,r)}_updateBaseOpacity(e){const t=this._renderer.opaque;this._renderer.opaque=e>=1,this._renderer.isTransparent=this._allSurfaceLayersTransparent();const i=t!==this._renderer.opaque;i&&this._updateTransparentTerrain(),this._updateTileTextures(i?ae.UNFADED:ae.IMMEDIATE)}_updateTilingScheme(){const e=this.tilingSchemeLogic.tilingScheme;if(!(e!==this.tilingScheme))return;ye(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles(),this._set("tilingScheme",e),this.isWebMercator=this.tilingScheme?.spatialReference.isWebMercator;const t=this.view?.renderSpatialReference,i=u(t)&&G(t);this.isWebMercatorOnPlateeCarree=this.isWebMercator&&i,this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.setTileSize(e.pixelSize),this.overlayManager.setSpatialReference(e.spatialReference),this._updateRootTiles())}_acquireTile(e,t,i,r){const s=this._tilePool.acquire();return it[0]=e,it[1]=t,it[2]=i,s.init(it,r,this),s}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){const{extent:e,tilingScheme:t}=this;if(!t)return;const i=tt;let s=t.rootTilesInExtent(e,i,5*ue);if(u(this.rootTiles)){if(s.length>ue)return void Qe.warn(ce);const e=this.rootTiles.map((e=>e.lij)),t=r(e,s,$e);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this.rootTiles.filter((e=>!(t.removed.findIndex((t=>$e(t,e.lij)))>-1)||(this._purgeTile(e,!0),!1)));t.added.forEach((t=>e.push(this._newRootTile(t)))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,s.length>ue&&(Qe.warn(_e),s=t.rootTilesInExtent(e,i,ue)),this._setRootTiles(s.map((e=>this._newRootTile(e))));I(i,this._rootTilesExtent)||(this._rootTilesExtent=A(i)),this.visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange("ready"),this._allTiles.forEach((e=>{e.isLoaded&&this._prepareToLoadTile(e)})),this._allTiles.forAll((e=>{e.isLoaded&&(this._updateTileGeometry(e),this._updateTileNeighborsAfterGeometryChange(e))})),this._updatingRootTiles=!1,this.checkAllTileWaterproofness()}_newRootTile(e){const t=this._acquireTile(0,e[1],e[2],null);return t.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.lodSnapping)===Ae.SPLIT&&t.setPendingUpdate(Ae.SPLIT),this._loadTile(t),t.checkGeometryWaterproofness(),t}_setRootTiles(e){if(this._set("rootTiles",e),this._allTiles.clear(),u(e)){const t=this._iteratorPool.acquire();for(t.reset(e);!t.done;)this._allTiles.push(t.next());t.remove()}this._renderer.setRootTiles(this.rootTiles),this._updateTilesVisibility(e)}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.suspended&&this.tilingScheme&&this._visible&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this.rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.extent)&&e.resetPendingUpdate(Ae.GEOMETRY)&&this._updateTileGeometry(e)}_updateTilesVisibility(e){if(p(e))return;const t=Oe(e);let i=t?this._elevationBounds.min:1/0,r=t?this._elevationBounds.max:-1/0;const s=this.extent,a=this._viewProjectionMatrix;this.setTileTreeDirty();const n=this._iteratorPool.acquire();for(n.reset(e);!n.done;){const e=n.next();e.updateClippingStatus(s)&&e.resetPendingUpdate(Ae.GEOMETRY)&&this._updateTileGeometry(e),e.setPendingUpdate(Ae.RENDERDATA),e.computeVisibility(),e.updateScreenDepth(a),e.renderData&&(i=Math.min(e.elevationBounds[0],i),r=Math.max(e.elevationBounds[1],r))}n.remove(),this._viewChanged=!0,this._allTilesDirty=!0,isFinite(i)&&isFinite(r)&&(this._elevationBounds.min===i&&this._elevationBounds.max===r||(this._elevationBounds.min=i,this._elevationBounds.max=r,this.emit("elevation-bounds-change",null)))}_updateViewDependentParameters(){const e=this.view.state.camera,t=this.view.state.contentCamera,i=Math.tan(.5*t.fovX),r=Math.tan(.5*t.fovY),s=this.tilingScheme.pixelSize,a=2**-this.lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=i,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=s/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=s/e.height*this.maxTextureScale*a,this._splitLimits.maxLod=this.tilingScheme.getMaxLod(),this._splitLimits.angledSplitBias=this.view.qualitySettings.tiledSurface.angledSplitBias,this.view.state.fixedContentCamera?(p(this._splitLimits.frustum)&&(this._splitLimits.frustum=q()),B(this._splitLimits.frustum,t.frustum)):this._splitLimits.frustum=null,B(this._frustum,e.frustum),b(this._viewProjectionMatrix,t.projectionMatrix,t.viewMatrix),D(this._eyePosRenderSR,t.eye),C(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateRenderData(e){e.rendered&&!e.shouldLoad&&(Ke(e)?(this._loadChildren(e),this._checkTileNeighborsWaterproofness(e),e.children.forEach((e=>e.checkGeometryWaterproofness()))):Je(e)&&this._loadParent(e))}_updateTileGeometry(e){e.updateVisibility(),this._renderer.updateTileGeometry(e),this._updateTileNeighborsAfterGeometryChange(e),this._elevationUpdate(e),this._usedMemory=Ze,this.deferTileNeighborUpdate&&this.neighborTilesToUpdate.delete(e)}_updateTileNeighborsAfterGeometryChange(e,t){if(this.deferTileNeighborUpdate){const t=this.neighborTilesToUpdate;e.forEachLoadedNeighbor((e=>{t.add(e)}))}else e.updateNeighborsAfterGeometryChange(t)}_updateTileTexture(e,t){const i=e.resetPendingUpdate(Ae.TEXTURE_FADING)?Ae.TEXTURE_FADING:!!e.resetPendingUpdate(Ae.TEXTURE_NOFADING)&&Ae.TEXTURE_NOFADING;i&&(this._renderer.updateTileTexture(e,i),this._usedMemory=Ze,t.madeProgress())}_elevationUpdate(e){st.spatialReference=this.spatialReference,st.tile=e,st.extent=e.extent,this.emit("elevation-change",st)}get running(){return this.updating&&this.ready&&!this.suspended}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateTileStatus(e),this._sortTiles(e);const t=!this.view.state.fixedContentCamera;this._mergeAndSplit(e,t),e.run((()=>this._updateElevation(e))),e.run((()=>this._updateTextures(e))),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty(),e.done&&this.requestUpdate(),this.notifyChange("updatingProgressValue")}_updateTileStatus(e){if(!this._viewChanged||!this.rootTiles||e.done)return;this._viewChanged=!1;const t=this._iteratorPool.acquire();for(t.reset(this.rootTiles);!t.done;){const e=t.next(),i=e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.lodSnapping);if(i!==Ae.SPLIT){if(e.resetPendingUpdate(Ae.SPLIT)&&e.updateAgentSuspension(),i===Ae.VSPLITMERGE&&e.updateAgents(ne.ELEVATION),t.skipSubtree(),!e.isLeaf){e.setPendingUpdate(Ae.MERGE),e.resetPendingUpdate(Ae.SPLIT);const t=this._iteratorPool.acquire();t.resetOne(e);for(let e=t.next();!t.done;e=t.next())this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(this._viewProjectionMatrix);t.remove()}}else e.resetPendingUpdate(Ae.MERGE),e.isLeaf&&(e.setPendingUpdate(Ae.SPLIT),t.skipSubtree())}t.remove(),this.requestUpdate(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||(ke(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger&&this._treeDebugger.update(),e.madeProgress())}_prepareBatchTileGeometryUpdate(){ve(0===this.neighborTilesToUpdate.size),this.deferTileNeighborUpdate=!0}_batchUpdateUpdatedTileNeighbors(){this.deferTileNeighborUpdate=!1;const e=this.neighborTilesToUpdate;(()=>{const t=()=>{for(const t of e)t.updateNeighborsWithChangedEdgeResolution()};(()=>{for(const t of e)t.updateNeighborDataAndGeometryIfNeeded()})(),t(),e.clear()})()}_mergeAndSplit(e,t){if(this.suspended||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let i=0;this._prepareBatchTileGeometryUpdate();let r=!1;for(;!e.done;){let s=!1;i=0;const a=!this._allTiles.some((a=>{if(r)i+=a.usedMemory;else if(!a.loadable)return e.done;if(a.resetPendingUpdate(Ae.MERGE)){if(!t)return a.setPendingUpdate(Ae.MERGE),e.done;this._mergeTile(a),s=!0,e.madeProgress()}else a.resetPendingUpdate(Ae.SPLIT)&&(this._splitTile(a),s=!0,e.madeProgress());return!e.done&&a.resetPendingUpdate(Ae.RENDERDATA)&&(this._updateRenderData(a),e.madeProgress()),e.done}));if(s&&(this._allTilesSorted=!1,this._allTilesDirty=!0),a){if(!r){r=!0;continue}if(this._usedMemory=i,!s)break;this._updateTilesVisibility(this.rootTiles)}else this._allTilesDirty=!0}0===i&&(this._allTilesDirty=!0),this._batchUpdateUpdatedTileNeighbors(),this._sortTiles(e)}_updateElevation(e){return this._prepareBatchTileGeometryUpdate(),this._allTiles.some((t=>(t.resetPendingUpdate(Ae.GEOMETRY)&&(this._updateTileGeometry(t),this._updateTileTexture(t,e),e.madeProgress()),e.done))),this._batchUpdateUpdatedTileNeighbors(),e.hasProgressed}_updateTextures(e){return this._allTiles.some((t=>(this._updateTileTexture(t,e),e.done))),e.hasProgressed}_updateClippingExtent(){this.spatialReference&&(this.updateTileOverlayParams(Ge.UPDATE),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get lodBias(){const e=this.view.resourceController.memoryController.memoryFactor;return this.view.qualitySettings.tiledSurface.lodBias-(1-e)*ge}_getLodBiasCorrectedScale(e){const t=this.tilingScheme.levels,i=o(e-this.lodBias,0,t.length-1),r=i-Math.floor(i);return t[Math.floor(i)].scale*(1-r)+t[Math.ceil(i)].scale*r}_removeAllTiles(){u(this.rootTiles)&&(this.rootTiles.forEach((e=>this._purgeTile(e,!1))),this._setRootTiles(null),this.notifyChange("ready")),this._allTiles.clear(),this.visible=!1}_purgeDescendantTiles(e){if(e.isLeaf)return!1;let t=!1;for(let i=0;i<4;++i)t=this._purgeTile(e.children[i],!1)||t;return e.unsetChildren(),t}_purgeTile(e,t){const i=this._purgeDescendantTiles(e)||e.rendered;return this._allTiles.removeUnordered(e),this._unloadTile(e),t&&this._updateTileNeighborsAfterGeometryChange(e),this._tilePool.release(e),i}_unloadTile(e){this.deferTileNeighborUpdate&&this.neighborTilesToUpdate.delete(e),e.unload(this._renderer)}_splitTile(e){ye(e.isLeaf,"tile that is already split should not be split again!");const t=e.level+1,i=2*e.lij[1],r=2*e.lij[2];e.setChildren(this._createTile(t,i,r,e),this._createTile(t,i,r+1,e),this._createTile(t,i+1,r,e),this._createTile(t,i+1,r+1,e)),e.setPendingUpdate(Ae.RENDERDATA),e.updateAgentSuspension(),this._allTiles.pushArray(e.children),this._allTilesDirty=!0,this._emitTileScaleChange(e,t),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){at.spatialReference=this.spatialReference,at.extent=e.extent,at.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",at)}_createTile(e,t,i,r){ye(!!r,"_createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.extent),s.updateScreenDepth(this._viewProjectionMatrix),s.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.lodSnapping)===Ae.SPLIT&&s.setPendingUpdate(Ae.SPLIT),s}_mergeTile(e){ye(!e.hasPendingUpdate(Ae.SPLIT),"_mergeTile sanity check"),this._purgeDescendantTiles(e)&&(ye(!e.renderData,"_mergeTile sanity check"),this._loadTile(e),this._updateTileNeighborsAfterGeometryChange(e),this._checkTileAndNeighborsWaterproofness(e)),this._allTilesDirty=!0,++this._performanceInfo.numMerged,this._emitTileScaleChange(e)}_checkTileAndNeighborsWaterproofness(e){e.checkGeometryWaterproofness(),this._checkTileNeighborsWaterproofness(e)}_checkTileNeighborsWaterproofness(e){Re&&e.forallNeighbors((e=>!!e.isLoaded&&(e.checkGeometryWaterproofness(),!0)))}_loadChildren(e){this._checkTileAndNeighborsWaterproofness(e),ye(e.rendered,"parent should be rendered"),this._unloadTile(e);const t=e.children;t.forEach((e=>this._prepareToLoadTile(e))),t.forEach((e=>this._loadTilePrepared(e))),this._updateTileNeighborsAfterGeometryChange(e,e.level+1),this.deferTileNeighborUpdate||t.forEach((e=>e.updateNeighborsWithChangedEdgeResolution())),t.forEach((e=>e.checkGeometryWaterproofness())),this._checkTileNeighborsWaterproofness(e)}_loadParent(e){this._checkTileAndNeighborsWaterproofness(e);const t=e.parent;this._unloadChildren(t),this._loadTile(t),this._updateTileNeighborsAfterGeometryChange(t),this._checkTileAndNeighborsWaterproofness(t)}_unloadChildren(e){if(!e.isLeaf)for(let t=0;t<4;++t){const i=e.children[t];this._unloadChildren(i),this._unloadTile(i)}}_postLoadTile(e){e.setPendingUpdate(Ae.RENDERDATA),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager&&this.overlayManager.hasOverlays&&this.overlayManager.setTileParameters(e),this._elevationUpdate(e)}_loadTile(e){e.load(this._renderer),this._postLoadTile(e)}_loadTilePrepared(e){e.loadPrepared(this._renderer),this._postLoadTile(e)}_prepareToLoadTile(e){e.prepareToLoad(this._renderer)}_elevationDataArrived(e,t,i){const r=new ie(e.lij,e.extent,i);e.dataArrived(t,ne.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()}n.remove(),this._updateTilesVisibility(s)}_handleLayerViewChanges(e=He){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1;const i=new Set;let r=-1;for(const s of this.view.allLayerViews.items)if(i.add(s.uid),we(s))if(this._basemapLayerViewHandles.has(s.uid)){const e=this._layerClassFromLayerView(s),i=this._layerIndexByUid[e].get(s.uid);i<r&&(t=!0),r=i}else this._registerTiledLayerView(s),s.layer.loaded&&(t=!0);this._basemapLayerViewHandles.forEach(((e,r)=>{i.has(r)||(this._unregisterTiledLayerView(r),t=!0)})),t&&this._updateTiledLayers(),this._renderer.isTransparent=this._allSurfaceLayersTransparent(),e.madeProgress()}_allSurfaceLayersTransparent(){let e=0===this.view.map?.ground?.opacity;for(const t of this.view.allLayerViews.items)if(Se(t)&&!H(t.layer)&&0!==t.fullOpacity)return e=!1,e;return e}_layerClassFromLayerView(e){return Le(e)?ne.ELEVATION:ne.MAP}_registerTiledLayerView(e){const t=[],i=this._layerClassFromLayerView(e);t.push(T((()=>e.suspended),(()=>this._updateTiledLayers()))),t.push(T((()=>e.fullOpacity),(()=>this._updateTileTextures(ae.UNFADED)))),t.push(T((()=>"effectiveScaleRange"in e.layer?e.layer.effectiveScaleRange:null),(()=>this._restartAllAgents(i)))),Ee(e)&&t.push(T((()=>e.layer.blendMode),(()=>this._updateTileTextures(ae.UNFADED)))),e.on("data-changed",(()=>{const t=this._layerIndexByUid[i].get(e.uid);null!=t&&this._invalidateLayerData(t,i)})),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){const t=this._basemapLayerViewHandles.get(e);if(t){for(let e=0;e<t.length;e++)t[e].remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;const e=this.view.allLayerViews,t=[[],[]];let i=null;const r=O();e.forEach((e=>{const s=e.layer;if(!s||e.suspended||!we(e))return;const a=e.fullExtent;if(!a)return void Qe.warn("Terrain: Map or elevation layer does not have fullExtent: "+s.id);k(r,a,r);const n=this._layerClassFromLayerView(e);if(n===ne.MAP){const t=e.displayLevelRange;t.maxLevel!==1/0&&(null===i||t.maxLevel>i)&&(i=t.maxLevel)}t[n].push(e)}));for(const s of le){const e=this._layerViews[s],i=t[s];i.reverse();const r=i.length;let a=e.length!==r;const n=new Array(r),l=new Array(e.length);this._layerIndexByUid[s].clear();for(let t=0;t<r;t++){const r=i[t].uid;this._layerIndexByUid[s].set(r,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,s);this._layerViews[s]=i,this._restartAllAgents(s),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===ne.ELEVATION&&i.computeElevationBounds()}}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll((t=>{t.updateAgents(ne.MAP),e===ae.IMMEDIATE?this.renderer.updateTileTexture(t,Ae.TEXTURE_NOFADING):t.updateRenderData(ne.MAP,e)})),this._renderer.isTransparent=this._allSurfaceLayersTransparent()}_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=Ge.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||be(s)?this._requestTileData(e,i,s,r):(++this._asyncWorkItems,a.tilemapCache.fetchAvailability(e.lij[0],e.lij[1],e.lij[2],{...r,timeout:6e3}).then((()=>--this._asyncWorkItems)).catch((t=>{throw--this._asyncWorkItems,g(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===ne.ELEVATION?Le(i)?this._requestElevationTileData(e,i,r):Promise.reject():Se(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{if(m(i))return;const s=this._layerIndexByUid[ne.ELEVATION].get(t.uid);null!=s?(this._usedMemory=Ze,this.requestUpdate(),this._elevationDataArrived(e,s,r)):Qe.warn("TerrainSurface: received data from unknown layer %d %s",ne.ELEVATION,e.lij.toString())},s=i=>{g(i)||(this._dataMissing(e,ne.ELEVATION,t,i),this.requestUpdate())};if(xe(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],{noDataValue:me,signal:i.signal}).then((e=>{if(!m(i))return this._frameTask.schedule((()=>r(e)),i.signal,s);Qe.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:me},i.signal))).then((e=>{e?r({values:e.pixelData,width:e.width,height:e.height,noDataValue:e.noDataValue,minValue:e.minValue,maxValue:e.maxValue}):s(new Error("LERC decoding failed"))}),s).finally((()=>{--this._asyncWorkItems}))}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{--this._asyncWorkItems,Pe(s),m(i)||(this._dataMissing(e,ne.MAP,t,r),this.requestUpdate())},s=e=>t=>r(t,e),a=r=>this._frameTask.schedule((()=>{--this._asyncWorkItems,this.requestUpdate(),m(i)?Pe(r):this._mapTileDataArrived(e,t,r)}),i.signal,s(r)).catch(s(r)),n=(e,t=null)=>this._frameTask.schedule((()=>r(e,t)));if(be(t)){const r=t.schemaHelper.getLevelRowColumn(e.lij);return t.fetchTile(r[0],r[1],r[2],i).then(a,n)}if(De(t))return t.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then(a,n);if(Ue(t)&&xe(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then((e=>{if(m(i))return Qe.warnOnce("A call to fetchTile resolved even though the request was aborted. fetchTile should not resolve if options.signal.aborted is true."),void n(f());a(e)}),n);let l=t.getTileUrl(e.lij[0],e.lij[1],e.lij[2]);W(t.layer)&&t.layer.refreshTimestamp&&(l+=`${l.includes("?")?"&":"?"}_ts=${t.layer.refreshTimestamp}`);const o=t.hasMixedImageFormats?"image+type":"image";return this._mapDataRequester.request(l,o,i).then(a,n)}_mapTileDataArrived(e,t,i){const r=this._layerIndexByUid[ne.MAP].get(t.uid);null!=r?e.dataArrived(r,ne.MAP,i):(Pe(i),Qe.warn("TerrainSurface: received data from unknown layer"))}_dataMissing(e,t,i,r){const s=this._layerIndexByUid[t].get(i.uid);null!=s?e.dataMissing(s,t,r):Qe.warn("TerrainSurface: received data from unknown layer")}updateTileOverlayParams(e){this.rootTiles&&this.overlayManager&&(this._allTiles.forAll((e=>{e.renderData&&this.overlayManager.setTileParameters(e)})),this._renderer.setNeedsRender(e))}get performanceInfo(){const e=this._performanceInfo;return e.numNodes=this._allTiles.length,e.numLeaves=e.numVisible=e.numRendered=e.numLoadedPerLevel.length=e.numRenderedPerLevel.length=0,this._allTiles.forAll((t=>{t.isLeaf&&e.numLeaves++;const i=t.level;t.renderData&&(e.numLoadedPerLevel[i]=(e.numLoadedPerLevel[i]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[i]=(e.numRenderedPerLevel[i]||0)+1,e.numRendered++))})),e}getUsedMemory(){return this.tilingScheme?(this._usedMemory===Ze&&(this._usedMemory=0,this._allTiles.forAll((e=>this._usedMemory+=e.usedMemory))),this._usedMemory):0}getUsedMemoryForLayerView(e){let t=0;const i=this._layerClassFromLayerView(e),r=this._layerIndexByUid[i].get(e.uid);return this._allTiles.forAll((e=>t+=e.getUsedMemoryForLayer(i,r))),t}getTile(e){if(p(e)||p(this.rootTiles))return null;const t=e.split("/").map((e=>+e));if(0===t[0])return this.rootTiles.find((e=>e.lij[1]===t[1]&&e.lij[2]===t[2]));const i=2**t[0],r=Math.floor(t[1]/i),s=Math.floor(t[2]/i);let a;if(this.rootTiles.some((e=>e.lij[1]===r&&e.lij[2]===s&&(a=e,!0))),a){let e=1<<t[0]-1;for(;a.lij[0]<t[0];){let i=t[1]&e?2:0;if((t[2]&e)>0&&i++,!a.children[i])return null;a=a.children[i],e>>=1}return ye(a.lij[0]===t[0]&&a.lij[1]===t[1]&&a.lij[2]===t[2],"not the right tile?"),a}return null}get test(){const e=this;return{renderer:e._renderer,lercDecoder:e._lercDecoder,forceReload:()=>{u(e.rootTiles)&&(e._mergeTile(e.rootTiles[0]),e._viewChangeUpdate())},getTiles:()=>e._allTiles.toArray(),getRenderedTiles(){rt.clear(),e._allTiles.forAll((e=>{e.visible&&e.rendered&&rt.push(e)}));const t=rt.toArray();return Ne(e.renderOrder,t),t},lockTilingScheme(t,i){e._extentHelper.defaultTiledLayersExtent=i,e.tilingSchemeLogic.test.lockTilingScheme(t)}}}checkAllTileWaterproofness(){if(!Re)return;const e=this.rootTiles;if(p(e))return;const t=e=>e?.renderData?.geometryInfo?.indices?.length>0??!1,i=(e,i)=>{t(e)&&console.error("Tile[",e.lij,"] has geometry although parent[",i.lij,"] has geom")},r=e=>{if(e.renderData&&!e.renderData.geometryState&&console.error("Tile[",e.lij,"] has renderData but not geometryState"),e.renderData&&!e.renderData.geometryInfo&&console.error("Tile[",e.lij,"] has renderData but not geometryInfo"),!e.renderData?.geometryInfo||(e.renderData.geometryInfo.indices?.length??0)>0||console.error("Tile[",e.lij,"] has renderData but no indices - geometryInfo: ",e.renderData.geometryInfo),t(e)){e.checkGeometryWaterproofness();for(const t of e.children)i(t,e)}else if(e.isLeaf)console.error("Tile[",e.lij,"] has no geometry and no children, from root to leaf");else for(const t of e.children)r(t)},s=e=>{const t=e.parent?.visible??!0,i=e.visible;e.computeVisibility();const r=e.visible;if(i!==r&&t&&console.error(" Tile[",e.lij,"] has out of date visibility: ",i," instead of ",r),!e.isLeaf)for(const a of e.children)s(a)};for(const a of e)r(a),s(a)}get isGlobal(){return this._isGlobal}isEastEndWrap(e){return this.isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this.isGlobal&&0===e[2]}lijEastEnd(e){return 2**(e+(this.spatialReference.isGeographic?1:0))}wrapEastWest(e){const t=this.lijEastEnd(e[0]),i=e[2];if(0<=i&&i<t)return e;if(!this.isGlobal)return null;const r=(i+(i<0?t:0))%t;return[e[0],e[1],r]}};e([L()],ze.prototype,"_renderer",void 0),e([L()],ze.prototype,"_hasPendingUpdates",void 0),e([L()],ze.prototype,"_asyncWorkItems",void 0),e([L()],ze.prototype,"_allTilesDirty",void 0),e([L()],ze.prototype,"_allTilesSorted",void 0),e([L()],ze.prototype,"_viewChanged",void 0),e([L({readOnly:!0})],ze.prototype,"_watchUpdatingTracking",void 0),e([L()],ze.prototype,"_frameTask",void 0),e([L({readOnly:!0})],ze.prototype,"snapLevel",null),e([L({readOnly:!0})],ze.prototype,"lodSnapping",null),e([L({constructOnly:!0})],ze.prototype,"view",void 0),e([L()],ze.prototype,"_userClippingExtent",null),e([L()],ze.prototype,"_rootTilesExtent",void 0),e([L({readOnly:!0})],ze.prototype,"extent",null),e([L({readOnly:!0})],ze.prototype,"groundExtent",null),e([L({readOnly:!0})],ze.prototype,"_tilingSchemeExtent",null),e([L({readOnly:!0})],ze.prototype,"updating",null),e([L(Z)],ze.prototype,"updatingProgress",void 0),e([L({readOnly:!0})],ze.prototype,"updatingProgressValue",null),e([L()],ze.prototype,"_maxNumUpdating",void 0),e([L({aliasOf:"view.map.ground.opacity"})],ze.prototype,"baseOpacity",void 0),e([L({readOnly:!0})],ze.prototype,"overlayManager",void 0),e([L({readOnly:!0})],ze.prototype,"viewingMode",null),e([L()],ze.prototype,"maxTextureScale",void 0),e([L({readOnly:!0})],ze.prototype,"ready",null),e([L({value:de.FRONT_TO_BACK})],ze.prototype,"renderOrder",null),e([L({readOnly:!0})],ze.prototype,"rootTiles",void 0),e([L({readOnly:!0})],ze.prototype,"spatialReference",null),e([L({type:t,aliasOf:"view.map.ground.surfaceColor"})],ze.prototype,"backgroundColor",void 0),e([L({value:!1})],ze.prototype,"slicePlaneEnabled",null),e([L({readOnly:!0})],ze.prototype,"tilingScheme",void 0),e([L({readOnly:!0,aliasOf:"tilingSchemeLogic.tilingSchemeLocked"})],ze.prototype,"tilingSchemeLocked",void 0),e([L({readOnly:!0})],ze.prototype,"tilingSchemeLogic",void 0),e([L({value:!0})],ze.prototype,"velvetOverground",null),e([S("_renderer.wireframe")],ze.prototype,"wireframe",void 0),e([L({value:!1})],ze.prototype,"suspended",null),e([L({readOnly:!0,aliasOf:"view.qualitySettings.tiledSurface.textureFadeDuration"})],ze.prototype,"textureFadeDuration",void 0),e([L()],ze.prototype,"_layerViewsDirty",void 0),e([S("_renderer.renderPatchBorders")],ze.prototype,"renderPatchBorders",void 0),e([S("_renderer.renderingDisabled")],ze.prototype,"renderingDisabled",void 0),ze=e([E("esri.views.3d.terrain.TerrainSurface")],ze);const Ye=ze;function $e(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function Ke(e){return!e.isLeaf&&(e.children.some((e=>e.shouldLoad))||e.children.some((e=>Ke(e))))}function Je(e){return e.isLeaf&&e.parent&&e.parent.shouldLoad}const Ze=-1,et=P(),tt=A(),it=[0,0,0],rt=new _,st={spatialReference:null,tile:null,extent:null,context:"ground"},at={spatialReference:null,extent:null,scale:0};export{Ye 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/Handles.js";import l from"../../../core/Logger.js";import{clamp as o}from"../../../core/mathUtils.js";import{releaseMaybe as h,destroyMaybe as d,isNone as p,isSome as u}from"../../../core/maybe.js";import c from"../../../core/ObjectPool.js";import _ from"../../../core/PooledArray.js";import{isAbortError as g,isAborted as m,createAbortError as f}from"../../../core/promiseUtils.js";import{watch as T,syncAndInitial as y,sync as v,initial as w}from"../../../core/reactiveUtils.js";import{aliasOf as S}from"../../../core/accessorSupport/decorators/aliasOf.js";import"../../../core/has.js";import"../../../core/accessorSupport/ensureType.js";import{property as L}from"../../../core/accessorSupport/decorators/property.js";import{subclass as E}from"../../../core/accessorSupport/decorators/subclass.js";import{m as b}from"../../../chunks/mat4.js";import{c as x}from"../../../chunks/mat4f64.js";import{c as D}from"../../../chunks/vec3.js";import{c as U}from"../../../chunks/vec3f64.js";import{c as P}from"../../../chunks/vec4f64.js";import{WatchUpdatingTracking as R}from"../../../core/support/WatchUpdatingTracking.js";import{projectVectorToVector as C,projectPointToVector as j}from"../../../geometry/projection.js";import{getReferenceEllipsoid as M}from"../../../geometry/projectionEllipsoid.js";import{create as A,equals as I,intersection as V,empty as O,expand as k,intersectsSphere as N}from"../../../geometry/support/aaBoundingRect.js";import{create as q,copy as B}from"../../../geometry/support/frustum.js";import{isPlateCarree as G}from"../../../geometry/support/spatialReferenceUtils.js";import{isRefreshableLayer as W}from"../../../layers/mixins/RefreshableLayer.js";import{ElevationQueryTileCache as F}from"../../../layers/support/ElevationQueryTileCache.js";import{isBaseLayer as H}from"../../../layers/support/layerUtils.js";import{acquireDecoder as Q}from"../../../layers/support/LercDecoder.js";import{printAllocations as X}from"../../2d/engine/vectorTiles/VectorTile.js";import{directionToHeadingTilt as z,scaleToZoom as Y}from"../support/cameraUtils.js";import $ from"../support/debugFlags.js";import{toBoundingRect as K}from"../support/extentUtils.js";import{ClientType as J}from"../support/index.js";import{updatingProgress as Z}from"../support/updatingProperties.js";import{ElevationBounds as ee}from"./ElevationBounds.js";import{sampleElevation as te,ElevationData as ie}from"./ElevationData.js";import{create as re}from"./ExtentHelper.js";import{LODSnapping as se,TextureUpdate as ae}from"./interfaces.js";import{LayerClass as ne,LayerClasses as le}from"./LayerClass.js";import{OverlayManager as oe}from"./OverlayManager.js";import{PlanarPatch as he}from"./PlanarPatch.js";import{RenderOrder as de}from"./RenderOrder.js";import{SphericalPatch as pe}from"./SphericalPatch.js";import{MAX_ROOT_TILES as ue,TOO_MANY_ROOT_TILES_AFTER_CHANGE_ERROR as ce,TOO_MANY_ROOT_TILES_FOR_LAYER_ERROR as _e,MAX_MEMORY_LOD_BIAS as ge,ELEVATION_NODATA_VALUE as me,DEFAULT_TILE_BACKGROUND as fe}from"./TerrainConst.js";import Te from"./TerrainRenderer.js";import ye from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as ve,internalAssert as we,isSurfaceLayerView as Se,isMapTileLayerView as Le,isElevationLayerView as Ee,isBlendableLayerView as be,isVectorTileLayerView as xe,useFetchTileForLayer as De,isImageryTileLayerView as Ue,isTileLayerView as Pe,releaseTileData as Re,ENABLE_WATERPROOFNESS_TESTS as Ce}from"./terrainUtils.js";import{SplitLimits as je,Tile as Me}from"./Tile.js";import{printAllocations as Ae}from"./TilePerLayerInfo.js";import{TileUpdate as Ie}from"./TileUpdate.js";import{IteratorPreorder as Ve,IteratorPostorder as Oe,hasLoadableSiblings as ke,sortTilesByPOI as Ne,sortTiles as qe}from"./tileUtils.js";import{TilingSchemeLogic as Be}from"./TilingSchemeLogic.js";import{UpsampleInfo as Ge}from"./UpsampleInfo.js";import{RenderRequestType as We}from"../webgl-engine/lib/basicInterfaces.js";import{ImmediateTask as Fe,TaskPriority as He,noBudget as Qe}from"../../support/Scheduler.js";const Xe=l.getLogger("esri.views.3d.terrain.TerrainSurface"),ze=.25;let Ye=class extends(a.EventedMixin(i)){constructor(e){super(e),this._elevationBounds=new ee,this._iteratorPool=new c(Ve,(e=>e.remove=()=>this._iteratorPool.release(e))),this._postorderIterator=new Oe,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._visible=!1,this._usedMemory=et,this._performanceInfo=new ye,this._viewChanged=!1,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=U(),this._eyePosSurfaceSR=U(),this._splitLimits=new je,this._snapLevel=1/0,this._frustum=q(),this._viewProjectionMatrix=x(),this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._handles=new n,this._watchUpdatingTracking=new R,this._frameTask=Fe,this._allTiles=new _,this._upsampleInfoPool=new c(Ge),this.isWebMercator=!1,this.isWebMercatorOnPlateeCarree=!1,this._rootTilesExtent=A(),this._maxNumUpdating=1,this.maxTextureScale=1.2,this.backgroundColor=null,this._updatingRootTiles=!1,this.deferTileNeighborUpdate=!1,this.neighborTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._layerViewsDirty=!1,this._isGlobal=!e.view?.state?.isLocal}initialize(){this._lercDecoder=Q(this.view.resourceController),this._tilePool=this.view.state.isLocal?new c(he):new c(pe);const e=this.view.resourceController.memoryController;this._upsampleMapCache=e.newCache("esri.views.3d.terrain.upsample",(e=>e.unloadMapData())),this._elevationQueryCache=new F(e.newCache("elevation-query")),this._set("overlayManager",new oe({surface:this})),this._handles.add([T((()=>this.overlayManager.hasHighlights),(e=>this._renderer.setNeedsHighlight(e))),T((()=>this.overlayManager.rendersOccluded),(e=>this._renderer.setRenderOccludedOverlay(e)))],"overlayManager"),this._renderer=new Te({overlayRenderer:this.overlayManager.renderer,ellipsoidRadius:M(this.view.spatialReference).radius,stage:this.view._stage,allTiles:this._allTiles}),this._handles.add([T((()=>this.baseOpacity),(e=>{this._handleLayerViewChanges(),this._updateBaseOpacity(e)}),y),T((()=>this.renderingDisabled),(()=>this._updateTransparentTerrain()),v),T((()=>this.backgroundColor),(e=>{this._handleLayerViewChanges(),this._renderer.setTileBackground(u(e)?e:fe)}),y),T((()=>this.view.pointsOfInterest),(e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add((()=>e.focus.renderLocation),(()=>()=>this._allTilesSorted=!1))})),T((()=>$.TERRAIN_TILE_TREE_SHOW_TILES),(e=>{e&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then((({TerrainTileTree3DDebugger:e})=>{!this._treeDebugger&&$.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new e({view:this.view}))})):e||(this._treeDebugger=d(this._treeDebugger))}),w)]),this._extentHelper=re(this.viewingMode,{layers:this.view.map.allLayers,layerViews:this.view.allLayerViews,viewSpatialReference:this.view.spatialReference});const t=this.view.defaultsFromMap?new s({getCollections:()=>this.view?.defaultsFromMap?.mapCollections?.map((({layers:e})=>e)),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}):this.view.map.allLayers,i=new Be({layers:t,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:this.view.spatialReference});this._set("tilingSchemeLogic",i),this._updateTilingScheme(),this._elevationDataRequester=this.view.resourceController.createStreamDataRequester(J.ELEVATION),this._mapDataRequester=this.view.resourceController.createStreamDataRequester(J.BASEMAP);const r=this.view.resourceController.scheduler;this._frameTask=r.registerTask(He.TERRAIN_SURFACE,this),this._handles.add([T((()=>this._extentHelper.stencilEnabledExtents),(e=>this._renderer.setStencilEnabledLayerExtents(e)),w),T((()=>this.tilingSchemeLogic.tilingScheme),(()=>this._updateTilingScheme()),v),T((()=>this.extent),(()=>this._updateRootTiles()),w),this.view.on("resize",(()=>this._viewChangeUpdate())),T((()=>{const e=this.view,t=e.state;return[this.lodBias,this.lodSnapping,e.resourceController?.memoryController?.memoryFactor,t.camera,t.contentCamera,t.fixedContentCamera]}),(()=>this._viewChangeUpdate()),y),T((()=>this.view.qualitySettings?.tiledSurface?.textureFadeDuration),(e=>this._renderer.textureFadingEnabled=e>0),w),T((()=>this._userClippingExtent),(()=>this._updateClippingExtent()),v)]),this._handles.add(this.view.allLayerViews.on("after-changes",(()=>this._layerViewsDirty=!0))),this._layerViewsDirty=!0,this._handleLayerViewChanges()}destroy(){this._frameTask.remove(),this._handles.destroy(),this._watchUpdatingTracking.destroy(),this._lercDecoder=h(this._lercDecoder),this._removeAllTiles(),this._upsampleMapCache=d(this._upsampleMapCache),this._elevationQueryCache=d(this._elevationQueryCache),this._set("tilingSchemeLogic",d(this.tilingSchemeLogic)),this._extentHelper=d(this._extentHelper),this._basemapLayerViewHandles.forEach(((e,t)=>this._unregisterTiledLayerView(t))),this._elevationDataRequester=null,this._mapDataRequester=null,this._set("overlayManager",d(this.overlayManager)),this._tilePool=d(this._tilePool),Me.prune(),this._treeDebugger&&(this._treeDebugger.destroy(),this._treeDebugger=null),this._renderer=d(this._renderer),this._iteratorPool=d(this._iteratorPool),this._set("view",null),this._upsampleInfoPool=d(this._upsampleInfoPool),X(),Ae()}get renderer(){return this._renderer}get frustum(){return this._frustum}get snapLevel(){const e=this.view.pointsOfInterest?.contentCameraOnSurface?.scale;if(e){const t=this.view.state.contentCamera;let i=z(this.view,t.eye,t.viewForward,t.up).tilt;i>90&&(i=180-i);const r=2*(i/90)**2,s=Y(this.view,e)-r;Math.abs(this._snapLevel-s)>ze&&(Math.round(s)!==Math.round(this._snapLevel)&&(this._viewChanged=!0),this._snapLevel=s)}return Math.round(this._snapLevel)}get lodSnapping(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences?se.ON:se.OFF}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get mapTileRequester(){return this._mapDataRequester}get _userClippingExtent(){const{spatialReference:e}=this,{clippingArea:t}=this.view;if(p(t)||p(e))return null;const i=A(),r=K(t,i,e)?i:null,s=this._get("extent");return I(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get extent(){const e=V(this.groundExtent,this._userClippingExtent,A()),t=this._get("extent");return I(e,t)?t:e}get groundExtent(){return u(this._tilingSchemeExtent)?this._tilingSchemeExtent:this._rootTilesExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),!!((this._watchUpdatingTracking.updating||this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||this._asyncWorkItems>0||!this._allTilesSorted||this._renderer.updating||this._layerViewsDirty)&&this.ready&&!this.suspended||this.overlayManager.updating||this._frameTask.updating)}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get viewingMode(){return this.view.state.viewingMode}get ready(){return u(this.rootTiles)}set renderOrder(e){this._renderer.renderOrder=e,this._set("renderOrder",e)}get spatialReference(){return this.tilingScheme?.spatialReference??null}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set("slicePlaneEnabled",e),this._updateTransparentTerrain()}_updateTransparentTerrain(){const e=!this.renderingDisabled&&!this.opaque;this.view?._stage?.renderView.setRenderParameters({transparentTerrain:e})}set velvetOverground(e){e!==this.velvetOverground&&(this._renderer.velvetOverground=e),this._set("velvetOverground",e)}set visible(e){e!==this._visible&&(this._visible=e,this._renderer.setVisibility(e),this.suspended=!e)}get opaque(){return this._renderer.opaque}set suspended(e){this._set("suspended",e),this._viewChangeUpdate()}intersect(e,t,i,r){this._renderer.intersect(e,t,i,r)}getElevation(e,t,i,r){const s=this.getTileWithElevation(e,t,i,r,tt);return p(s)?null:te(tt[0],tt[1],s.renderData.geometryState.samplerData)}getTileWithElevation(e,t,i,r,s=tt){const a=this.rootTiles;if(p(a)||!a.length)return null;if(0===a[0].layerInfo[ne.ELEVATION].length)return null;if(s[0]=e,s[1]=t,s[2]=i,!C(s,r,s,this.tilingScheme?.spatialReference))return Xe.error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;for(let n of a){if(!n.containsPoint(s))continue;for(;n&&!n.rendered&&!n.isLeaf;){let e=0;s[0]>.5*(n.extent[0]+n.extent[2])&&(e+=1),s[1]<.5*(n.extent[1]+n.extent[3])&&(e+=2),n=n.children[e]}const e=n.renderData;return(e?e.geometryState.samplerData:null)?n:null}return null}get elevationBounds(){return this._elevationBounds}getScale(e){if(this.tilingScheme){if(!j(e,tt,this.spatialReference))return Xe.error("TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system"),null;const t=this.rootTiles;if(u(t))for(let e of t)if(e.containsPoint(tt)){for(;null!=e.children[0];){let t=0;tt[0]>e.children[0].extent[2]&&(t+=1),tt[1]<e.children[0].extent[1]&&(t+=2),e=e.children[t]}return this._getLodBiasCorrectedScale(e.level)}}return 1e100}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!j(e,tt,this.spatialReference))return Xe.error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;tt[3]=t;let i=null;const r=e=>{if(e&&N(e.extent,tt))if(null!=e.children[0])for(const t of e.children)r(t);else{const t=this._getLodBiasCorrectedScale(e.level);i=null==i?t:Math.min(i,t)}},s=this.rootTiles;if(u(s))for(const a of s)r(a);return i}queryVisibleScaleRange(e,t,i,r){const s=t?this.tilingScheme.levelAtScale(t):0,a=i?this.tilingScheme.levelAtScale(i):1/0,n=this.lodBias;this._renderer.queryVisibleLevelRange(e,s+n,a+n,r)}_updateBaseOpacity(e){const t=this._renderer.opaque;this._renderer.opaque=e>=1,this._renderer.isTransparent=this._allSurfaceLayersTransparent();const i=t!==this._renderer.opaque;i&&this._updateTransparentTerrain(),this._updateTileTextures(i?ae.UNFADED:ae.IMMEDIATE)}_updateTilingScheme(){const e=this.tilingSchemeLogic.tilingScheme;if(!(e!==this.tilingScheme))return;ve(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles(),this._set("tilingScheme",e),this.isWebMercator=this.tilingScheme?.spatialReference.isWebMercator;const t=this.view?.renderSpatialReference,i=u(t)&&G(t);this.isWebMercatorOnPlateeCarree=this.isWebMercator&&i,this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.setTileSize(e.pixelSize),this.overlayManager.setSpatialReference(e.spatialReference),this._updateRootTiles())}_acquireTile(e,t,i,r){const s=this._tilePool.acquire();return rt[0]=e,rt[1]=t,rt[2]=i,s.init(rt,r,this),s}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){const{extent:e,tilingScheme:t}=this;if(!t)return;const i=it;let s=t.rootTilesInExtent(e,i,5*ue);if(u(this.rootTiles)){if(s.length>ue)return void Xe.warn(ce);const e=this.rootTiles.map((e=>e.lij)),t=r(e,s,Ke);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this.rootTiles.filter((e=>!(t.removed.findIndex((t=>Ke(t,e.lij)))>-1)||(this._purgeTile(e,!0),!1)));t.added.forEach((t=>e.push(this._newRootTile(t)))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,s.length>ue&&(Xe.warn(_e),s=t.rootTilesInExtent(e,i,ue)),this._setRootTiles(s.map((e=>this._newRootTile(e))));I(i,this._rootTilesExtent)||(this._rootTilesExtent=A(i)),this.visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange("ready"),this._allTiles.forEach((e=>{e.isLoaded&&this._prepareToLoadTile(e)})),this._allTiles.forAll((e=>{e.isLoaded&&(this._updateTileGeometry(e),this._updateTileNeighborsAfterGeometryChange(e))})),this._updatingRootTiles=!1,this.checkAllTileWaterproofness()}_newRootTile(e){const t=this._acquireTile(0,e[1],e[2],null);return t.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.lodSnapping)===Ie.SPLIT&&t.setPendingUpdate(Ie.SPLIT),this._loadTile(t),t.checkGeometryWaterproofness(),t}_setRootTiles(e){if(this._set("rootTiles",e),this._allTiles.clear(),u(e)){const t=this._iteratorPool.acquire();for(t.reset(e);!t.done;)this._allTiles.push(t.next());t.remove()}this._renderer.setRootTiles(this.rootTiles),this._updateTilesVisibility(e)}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.suspended&&this.tilingScheme&&this._visible&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this.rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.extent)&&e.resetPendingUpdate(Ie.GEOMETRY)&&this._updateTileGeometry(e)}_updateTilesVisibility(e){if(p(e))return;const t=ke(e);let i=t?this._elevationBounds.min:1/0,r=t?this._elevationBounds.max:-1/0;const s=this.extent,a=this._viewProjectionMatrix;this.setTileTreeDirty();const n=this._iteratorPool.acquire();for(n.reset(e);!n.done;){const e=n.next();e.updateClippingStatus(s)&&e.resetPendingUpdate(Ie.GEOMETRY)&&this._updateTileGeometry(e),e.setPendingUpdate(Ie.RENDERDATA),e.computeVisibility(),e.updateScreenDepth(a),e.renderData&&(i=Math.min(e.elevationBounds[0],i),r=Math.max(e.elevationBounds[1],r))}n.remove(),this._viewChanged=!0,this._allTilesDirty=!0,isFinite(i)&&isFinite(r)&&(this._elevationBounds.min===i&&this._elevationBounds.max===r||(this._elevationBounds.min=i,this._elevationBounds.max=r,this.emit("elevation-bounds-change",null)))}_updateViewDependentParameters(){const e=this.view.state.camera,t=this.view.state.contentCamera,i=Math.tan(.5*t.fovX),r=Math.tan(.5*t.fovY),s=this.tilingScheme.pixelSize,a=2**-this.lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=i,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=s/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=s/e.height*this.maxTextureScale*a,this._splitLimits.maxLod=this.tilingScheme.getMaxLod(),this._splitLimits.angledSplitBias=this.view.qualitySettings.tiledSurface.angledSplitBias,this.view.state.fixedContentCamera?(p(this._splitLimits.frustum)&&(this._splitLimits.frustum=q()),B(this._splitLimits.frustum,t.frustum)):this._splitLimits.frustum=null,B(this._frustum,e.frustum),b(this._viewProjectionMatrix,t.projectionMatrix,t.viewMatrix),D(this._eyePosRenderSR,t.eye),C(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateRenderData(e){e.rendered&&!e.shouldLoad&&(Je(e)?(this._loadChildren(e),this._checkTileNeighborsWaterproofness(e),e.children.forEach((e=>e.checkGeometryWaterproofness()))):Ze(e)&&this._loadParent(e))}_updateTileGeometry(e){e.updateVisibility(),this._renderer.updateTileGeometry(e),this._updateTileNeighborsAfterGeometryChange(e),this._elevationUpdate(e),this._usedMemory=et,this.deferTileNeighborUpdate&&this.neighborTilesToUpdate.delete(e)}_updateTileNeighborsAfterGeometryChange(e,t){if(this.deferTileNeighborUpdate){const t=this.neighborTilesToUpdate;e.forEachLoadedNeighbor((e=>{t.add(e)}))}else e.updateNeighborsAfterGeometryChange(t)}_updateTileTexture(e,t){const i=e.resetPendingUpdate(Ie.TEXTURE_FADING)?Ie.TEXTURE_FADING:!!e.resetPendingUpdate(Ie.TEXTURE_NOFADING)&&Ie.TEXTURE_NOFADING;i&&(this._renderer.updateTileTexture(e,i),this._usedMemory=et,t.madeProgress())}_elevationUpdate(e){at.spatialReference=this.spatialReference,at.tile=e,at.extent=e.extent,this.emit("elevation-change",at)}get running(){return this.updating&&this.ready&&!this.suspended}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateTileStatus(e),this._sortTiles(e);const t=!this.view.state.fixedContentCamera;this._mergeAndSplit(e,t),e.run((()=>this._updateElevation(e))),e.run((()=>this._updateTextures(e))),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty(),e.done&&this.requestUpdate(),this.notifyChange("updatingProgressValue")}_updateTileStatus(e){if(!this._viewChanged||!this.rootTiles||e.done)return;this._viewChanged=!1;const t=this._iteratorPool.acquire();for(t.reset(this.rootTiles);!t.done;){const e=t.next(),i=e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.lodSnapping);if(i!==Ie.SPLIT){if(e.resetPendingUpdate(Ie.SPLIT)&&e.updateAgentSuspension(),i===Ie.VSPLITMERGE&&e.updateAgents(ne.ELEVATION),t.skipSubtree(),!e.isLeaf){e.setPendingUpdate(Ie.MERGE),e.resetPendingUpdate(Ie.SPLIT);const t=this._iteratorPool.acquire();t.resetOne(e);for(let e=t.next();!t.done;e=t.next())this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(this._viewProjectionMatrix);t.remove()}}else e.resetPendingUpdate(Ie.MERGE),e.isLeaf&&(e.setPendingUpdate(Ie.SPLIT),t.skipSubtree())}t.remove(),this.requestUpdate(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||(Ne(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger&&this._treeDebugger.update(),e.madeProgress())}_prepareBatchTileGeometryUpdate(){we(0===this.neighborTilesToUpdate.size),this.deferTileNeighborUpdate=!0}_batchUpdateUpdatedTileNeighbors(){this.deferTileNeighborUpdate=!1;const e=this.neighborTilesToUpdate;(()=>{const t=()=>{for(const t of e)t.updateNeighborsWithChangedEdgeResolution()};(()=>{for(const t of e)t.updateNeighborDataAndGeometryIfNeeded()})(),t(),e.clear()})()}_mergeAndSplit(e,t){if(this.suspended||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let i=0;this._prepareBatchTileGeometryUpdate();let r=!1;for(;!e.done;){let s=!1;i=0;const a=!this._allTiles.some((a=>{if(r)i+=a.usedMemory;else if(!a.loadable)return e.done;if(a.resetPendingUpdate(Ie.MERGE)){if(!t)return a.setPendingUpdate(Ie.MERGE),e.done;this._mergeTile(a),s=!0,e.madeProgress()}else a.resetPendingUpdate(Ie.SPLIT)&&(this._splitTile(a),s=!0,e.madeProgress());return!e.done&&a.resetPendingUpdate(Ie.RENDERDATA)&&(this._updateRenderData(a),e.madeProgress()),e.done}));if(s&&(this._allTilesSorted=!1,this._allTilesDirty=!0),a){if(!r){r=!0;continue}if(this._usedMemory=i,!s)break;this._updateTilesVisibility(this.rootTiles)}else this._allTilesDirty=!0}0===i&&(this._allTilesDirty=!0),this._batchUpdateUpdatedTileNeighbors(),this._sortTiles(e)}_updateElevation(e){return this._prepareBatchTileGeometryUpdate(),this._allTiles.some((t=>(t.resetPendingUpdate(Ie.GEOMETRY)&&(this._updateTileGeometry(t),this._updateTileTexture(t,e),e.madeProgress()),e.done))),this._batchUpdateUpdatedTileNeighbors(),e.hasProgressed}_updateTextures(e){return this._allTiles.some((t=>(this._updateTileTexture(t,e),e.done))),e.hasProgressed}_updateClippingExtent(){this.spatialReference&&(this.updateTileOverlayParams(We.UPDATE),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get lodBias(){const e=this.view.resourceController.memoryController.memoryFactor;return this.view.qualitySettings.tiledSurface.lodBias-(1-e)*ge}_getLodBiasCorrectedScale(e){const t=this.tilingScheme.levels,i=o(e-this.lodBias,0,t.length-1),r=i-Math.floor(i);return t[Math.floor(i)].scale*(1-r)+t[Math.ceil(i)].scale*r}_removeAllTiles(){u(this.rootTiles)&&(this.rootTiles.forEach((e=>this._purgeTile(e,!1))),this._setRootTiles(null),this.notifyChange("ready")),this._allTiles.clear(),this.visible=!1}_purgeDescendantTiles(e){if(e.isLeaf)return!1;let t=!1;for(let i=0;i<4;++i)t=this._purgeTile(e.children[i],!1)||t;return e.unsetChildren(),t}_purgeTile(e,t){const i=this._purgeDescendantTiles(e)||e.rendered;return this._allTiles.removeUnordered(e),this._unloadTile(e),t&&this._updateTileNeighborsAfterGeometryChange(e),this._tilePool.release(e),i}_unloadTile(e){this.deferTileNeighborUpdate&&this.neighborTilesToUpdate.delete(e),e.unload(this._renderer)}_splitTile(e){ve(e.isLeaf,"tile that is already split should not be split again!");const t=e.level+1,i=2*e.lij[1],r=2*e.lij[2];e.setChildren(this._createTile(t,i,r,e),this._createTile(t,i,r+1,e),this._createTile(t,i+1,r,e),this._createTile(t,i+1,r+1,e)),e.setPendingUpdate(Ie.RENDERDATA),e.updateAgentSuspension(),this._allTiles.pushArray(e.children),this._allTilesDirty=!0,this._emitTileScaleChange(e,t),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){nt.spatialReference=this.spatialReference,nt.extent=e.extent,nt.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",nt)}_createTile(e,t,i,r){ve(!!r,"_createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.extent),s.updateScreenDepth(this._viewProjectionMatrix),s.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.lodSnapping)===Ie.SPLIT&&s.setPendingUpdate(Ie.SPLIT),s}_mergeTile(e){ve(!e.hasPendingUpdate(Ie.SPLIT),"_mergeTile sanity check"),this._purgeDescendantTiles(e)&&(ve(!e.renderData,"_mergeTile sanity check"),this._loadTile(e),this._updateTileNeighborsAfterGeometryChange(e),this._checkTileAndNeighborsWaterproofness(e)),this._allTilesDirty=!0,++this._performanceInfo.numMerged,this._emitTileScaleChange(e)}_checkTileAndNeighborsWaterproofness(e){e.checkGeometryWaterproofness(),this._checkTileNeighborsWaterproofness(e)}_checkTileNeighborsWaterproofness(e){Ce&&e.forallNeighbors((e=>!!e.isLoaded&&(e.checkGeometryWaterproofness(),!0)))}_loadChildren(e){this._checkTileAndNeighborsWaterproofness(e),ve(e.rendered,"parent should be rendered"),this._unloadTile(e);const t=e.children;t.forEach((e=>this._prepareToLoadTile(e))),t.forEach((e=>this._loadTilePrepared(e))),this._updateTileNeighborsAfterGeometryChange(e,e.level+1),this.deferTileNeighborUpdate||t.forEach((e=>e.updateNeighborsWithChangedEdgeResolution())),t.forEach((e=>e.checkGeometryWaterproofness())),this._checkTileNeighborsWaterproofness(e)}_loadParent(e){this._checkTileAndNeighborsWaterproofness(e);const t=e.parent;this._unloadChildren(t),this._loadTile(t),this._updateTileNeighborsAfterGeometryChange(t),this._checkTileAndNeighborsWaterproofness(t)}_unloadChildren(e){if(!e.isLeaf)for(let t=0;t<4;++t){const i=e.children[t];this._unloadChildren(i),this._unloadTile(i)}}_postLoadTile(e){e.setPendingUpdate(Ie.RENDERDATA),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager&&this.overlayManager.hasOverlays&&this.overlayManager.setTileParameters(e),this._elevationUpdate(e)}_loadTile(e){e.load(this._renderer),this._postLoadTile(e)}_loadTilePrepared(e){e.loadPrepared(this._renderer),this._postLoadTile(e)}_prepareToLoadTile(e){e.prepareToLoad(this._renderer)}_elevationDataArrived(e,t,i){const r=new ie(e.lij,e.extent,i);e.dataArrived(t,ne.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()}n.remove(),this._updateTilesVisibility(s)}_handleLayerViewChanges(e=Qe){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1;const i=new Set;let r=-1;for(const s of this.view.allLayerViews.items)if(i.add(s.uid),Se(s))if(this._basemapLayerViewHandles.has(s.uid)){const e=this._layerClassFromLayerView(s),i=this._layerIndexByUid[e].get(s.uid);i<r&&(t=!0),r=i}else this._registerTiledLayerView(s),s.layer.loaded&&(t=!0);this._basemapLayerViewHandles.forEach(((e,r)=>{i.has(r)||(this._unregisterTiledLayerView(r),t=!0)})),t&&this._updateTiledLayers(),this._renderer.isTransparent=this._allSurfaceLayersTransparent(),e.madeProgress()}_allSurfaceLayersTransparent(){let e=0===this.view.map?.ground?.opacity;for(const t of this.view.allLayerViews.items)if(Le(t)&&!H(t.layer)&&0!==t.fullOpacity)return e=!1,e;return e}_layerClassFromLayerView(e){return Ee(e)?ne.ELEVATION:ne.MAP}_registerTiledLayerView(e){const t=[],i=this._layerClassFromLayerView(e);t.push(T((()=>e.suspended),(()=>this._updateTiledLayers()))),t.push(T((()=>e.fullOpacity),(()=>this._updateTileTextures(ae.UNFADED)))),t.push(T((()=>"effectiveScaleRange"in e.layer?e.layer.effectiveScaleRange:null),(()=>this._restartAllAgents(i)))),be(e)&&t.push(T((()=>e.layer.blendMode),(()=>this._updateTileTextures(ae.UNFADED)))),e.on("data-changed",(()=>{const t=this._layerIndexByUid[i].get(e.uid);null!=t&&this._invalidateLayerData(t,i)})),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){const t=this._basemapLayerViewHandles.get(e);if(t){for(let e=0;e<t.length;e++)t[e].remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;const e=this.view.allLayerViews,t=[[],[]];let i=null;const r=O();e.forEach((e=>{const s=e.layer;if(!s||e.suspended||!Se(e))return;const a=e.fullExtent;if(!a)return void Xe.warn("Terrain: Map or elevation layer does not have fullExtent: "+s.id);k(r,a,r);const n=this._layerClassFromLayerView(e);if(n===ne.MAP){const t=e.displayLevelRange;t.maxLevel!==1/0&&(null===i||t.maxLevel>i)&&(i=t.maxLevel)}t[n].push(e)}));for(const s of le){const e=this._layerViews[s],i=t[s];i.reverse();const r=i.length;let a=e.length!==r;const n=new Array(r),l=new Array(e.length);this._layerIndexByUid[s].clear();for(let t=0;t<r;t++){const r=i[t].uid;this._layerIndexByUid[s].set(r,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,s);this._layerViews[s]=i,this._restartAllAgents(s),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===ne.ELEVATION&&i.computeElevationBounds()}}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll((t=>{t.updateAgents(ne.MAP),e===ae.IMMEDIATE?this.renderer.updateTileTexture(t,Ie.TEXTURE_NOFADING):t.updateRenderData(ne.MAP,e)})),this._renderer.isTransparent=this._allSurfaceLayersTransparent()}_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=We.UPDATE){this.renderer.setNeedsRender(e)}requestUpdate(){1==++this._pendingUpdates&&(this._hasPendingUpdates=!0)}requestTileData(e,t,i,r){const s=this.layerViewByIndex(t,i),a=s.layer;return!a.tilemapCache||xe(s)?this._requestTileData(e,i,s,r):(++this._asyncWorkItems,a.tilemapCache.fetchAvailability(e.lij[0],e.lij[1],e.lij[2],{...r,timeout:6e3}).then((()=>--this._asyncWorkItems)).catch((t=>{throw--this._asyncWorkItems,g(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===ne.ELEVATION?Ee(i)?this._requestElevationTileData(e,i,r):Promise.reject():Le(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{if(m(i))return;const s=this._layerIndexByUid[ne.ELEVATION].get(t.uid);null!=s?(this._usedMemory=et,this.requestUpdate(),this._elevationDataArrived(e,s,r)):Xe.warn("TerrainSurface: received data from unknown layer %d %s",ne.ELEVATION,e.lij.toString())},s=i=>{g(i)||(this._dataMissing(e,ne.ELEVATION,t,i),this.requestUpdate())};if(De(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],{noDataValue:me,signal:i.signal}).then((e=>{if(!m(i))return this._frameTask.schedule((()=>r(e)),i.signal,s);Xe.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:me},i.signal))).then((e=>{e?r({values:e.pixelData,width:e.width,height:e.height,noDataValue:e.noDataValue,minValue:e.minValue,maxValue:e.maxValue}):s(new Error("LERC decoding failed"))}),s).finally((()=>{--this._asyncWorkItems}))}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{--this._asyncWorkItems,Re(s),m(i)||(this._dataMissing(e,ne.MAP,t,r),this.requestUpdate())},s=e=>t=>r(t,e),a=r=>this._frameTask.schedule((()=>{--this._asyncWorkItems,this.requestUpdate(),m(i)?Re(r):this._mapTileDataArrived(e,t,r)}),i.signal,s(r)).catch(s(r)),n=(e,t=null)=>this._frameTask.schedule((()=>r(e,t)));if(xe(t)){const r=t.schemaHelper.getLevelRowColumn(e.lij);return t.fetchTile(r[0],r[1],r[2],i).then(a,n)}if(Ue(t))return t.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then(a,n);if(Pe(t)&&De(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then((e=>{if(m(i))return Xe.warnOnce("A call to fetchTile resolved even though the request was aborted. fetchTile should not resolve if options.signal.aborted is true."),void n(f());a(e)}),n);let l=t.getTileUrl(e.lij[0],e.lij[1],e.lij[2]);W(t.layer)&&t.layer.refreshTimestamp&&(l+=`${l.includes("?")?"&":"?"}_ts=${t.layer.refreshTimestamp}`);const o=t.hasMixedImageFormats?"image+type":"image";return this._mapDataRequester.request(l,o,i).then(a,n)}_mapTileDataArrived(e,t,i){const r=this._layerIndexByUid[ne.MAP].get(t.uid);null!=r?e.dataArrived(r,ne.MAP,i):(Re(i),Xe.warn("TerrainSurface: received data from unknown layer"))}_dataMissing(e,t,i,r){const s=this._layerIndexByUid[t].get(i.uid);null!=s?e.dataMissing(s,t,r):Xe.warn("TerrainSurface: received data from unknown layer")}updateTileOverlayParams(e){this.rootTiles&&this.overlayManager&&(this._allTiles.forAll((e=>{e.renderData&&this.overlayManager.setTileParameters(e)})),this._renderer.setNeedsRender(e))}get performanceInfo(){const e=this._performanceInfo;return e.numNodes=this._allTiles.length,e.numLeaves=e.numVisible=e.numRendered=e.numLoadedPerLevel.length=e.numRenderedPerLevel.length=0,this._allTiles.forAll((t=>{t.isLeaf&&e.numLeaves++;const i=t.level;t.renderData&&(e.numLoadedPerLevel[i]=(e.numLoadedPerLevel[i]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[i]=(e.numRenderedPerLevel[i]||0)+1,e.numRendered++))})),e}getUsedMemory(){return this.tilingScheme?(this._usedMemory===et&&(this._usedMemory=0,this._allTiles.forAll((e=>this._usedMemory+=e.usedMemory))),this._usedMemory):0}getUsedMemoryForLayerView(e){let t=0;const i=this._layerClassFromLayerView(e),r=this._layerIndexByUid[i].get(e.uid);return this._allTiles.forAll((e=>t+=e.getUsedMemoryForLayer(i,r))),t}getTile(e){if(p(e)||p(this.rootTiles))return null;const t=e.split("/").map((e=>+e));if(0===t[0])return this.rootTiles.find((e=>e.lij[1]===t[1]&&e.lij[2]===t[2]));const i=2**t[0],r=Math.floor(t[1]/i),s=Math.floor(t[2]/i);let a;if(this.rootTiles.some((e=>e.lij[1]===r&&e.lij[2]===s&&(a=e,!0))),a){let e=1<<t[0]-1;for(;a.lij[0]<t[0];){let i=t[1]&e?2:0;if((t[2]&e)>0&&i++,!a.children[i])return null;a=a.children[i],e>>=1}return ve(a.lij[0]===t[0]&&a.lij[1]===t[1]&&a.lij[2]===t[2],"not the right tile?"),a}return null}get test(){const e=this;return{renderer:e._renderer,lercDecoder:e._lercDecoder,forceReload:()=>{u(e.rootTiles)&&(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 qe(e.renderOrder,t),t},lockTilingScheme(t,i){e._extentHelper.defaultTiledLayersExtent=i,e.tilingSchemeLogic.test.lockTilingScheme(t)}}}checkAllTileWaterproofness(){if(!Ce)return;const e=this.rootTiles;if(p(e))return;const t=e=>e?.renderData?.geometryInfo?.indices?.length>0??!1,i=(e,i)=>{t(e)&&console.error("Tile[",e.lij,"] has geometry although parent[",i.lij,"] has geom")},r=e=>{if(e.renderData&&!e.renderData.geometryState&&console.error("Tile[",e.lij,"] has renderData but not geometryState"),e.renderData&&!e.renderData.geometryInfo&&console.error("Tile[",e.lij,"] has renderData but not geometryInfo"),!e.renderData?.geometryInfo||(e.renderData.geometryInfo.indices?.length??0)>0||console.error("Tile[",e.lij,"] has renderData but no indices - geometryInfo: ",e.renderData.geometryInfo),t(e)){e.checkGeometryWaterproofness();for(const t of e.children)i(t,e)}else if(e.isLeaf)console.error("Tile[",e.lij,"] has no geometry and no children, from root to leaf");else for(const t of e.children)r(t)},s=e=>{const t=e.parent?.visible??!0,i=e.visible;e.computeVisibility();const r=e.visible;if(i!==r&&t&&console.error(" Tile[",e.lij,"] has out of date visibility: ",i," instead of ",r),!e.isLeaf)for(const a of e.children)s(a)};for(const a of e)r(a),s(a)}get isGlobal(){return this._isGlobal}isEastEndWrap(e){return this.isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this.isGlobal&&0===e[2]}lijEastEnd(e){return 2**(e+(this.spatialReference.isGeographic?1:0))}wrapEastWest(e){const t=this.lijEastEnd(e[0]),i=e[2];if(0<=i&&i<t)return e;if(!this.isGlobal)return null;const r=(i+(i<0?t:0))%t;return[e[0],e[1],r]}};e([L()],Ye.prototype,"_renderer",void 0),e([L()],Ye.prototype,"_hasPendingUpdates",void 0),e([L()],Ye.prototype,"_asyncWorkItems",void 0),e([L()],Ye.prototype,"_allTilesDirty",void 0),e([L()],Ye.prototype,"_allTilesSorted",void 0),e([L()],Ye.prototype,"_viewChanged",void 0),e([L({readOnly:!0})],Ye.prototype,"_watchUpdatingTracking",void 0),e([L()],Ye.prototype,"_frameTask",void 0),e([L({readOnly:!0})],Ye.prototype,"snapLevel",null),e([L({readOnly:!0})],Ye.prototype,"lodSnapping",null),e([L({constructOnly:!0})],Ye.prototype,"view",void 0),e([L()],Ye.prototype,"_userClippingExtent",null),e([L()],Ye.prototype,"_rootTilesExtent",void 0),e([L({readOnly:!0})],Ye.prototype,"extent",null),e([L({readOnly:!0})],Ye.prototype,"groundExtent",null),e([L({readOnly:!0})],Ye.prototype,"_tilingSchemeExtent",null),e([L({readOnly:!0})],Ye.prototype,"updating",null),e([L(Z)],Ye.prototype,"updatingProgress",void 0),e([L({readOnly:!0})],Ye.prototype,"updatingProgressValue",null),e([L()],Ye.prototype,"_maxNumUpdating",void 0),e([L({aliasOf:"view.map.ground.opacity"})],Ye.prototype,"baseOpacity",void 0),e([L({readOnly:!0})],Ye.prototype,"overlayManager",void 0),e([L({readOnly:!0})],Ye.prototype,"viewingMode",null),e([L()],Ye.prototype,"maxTextureScale",void 0),e([L({readOnly:!0})],Ye.prototype,"ready",null),e([L({value:de.FRONT_TO_BACK})],Ye.prototype,"renderOrder",null),e([L({readOnly:!0})],Ye.prototype,"rootTiles",void 0),e([L({readOnly:!0})],Ye.prototype,"spatialReference",null),e([L({type:t,aliasOf:"view.map.ground.surfaceColor"})],Ye.prototype,"backgroundColor",void 0),e([L({value:!1})],Ye.prototype,"slicePlaneEnabled",null),e([L({readOnly:!0})],Ye.prototype,"tilingScheme",void 0),e([L({readOnly:!0,aliasOf:"tilingSchemeLogic.tilingSchemeLocked"})],Ye.prototype,"tilingSchemeLocked",void 0),e([L({readOnly:!0})],Ye.prototype,"tilingSchemeLogic",void 0),e([L({value:!0})],Ye.prototype,"velvetOverground",null),e([S("_renderer.wireframe")],Ye.prototype,"wireframe",void 0),e([L({value:!1})],Ye.prototype,"suspended",null),e([L({readOnly:!0,aliasOf:"view.qualitySettings.tiledSurface.textureFadeDuration"})],Ye.prototype,"textureFadeDuration",void 0),e([L()],Ye.prototype,"_layerViewsDirty",void 0),e([S("_renderer.renderPatchBorders")],Ye.prototype,"renderPatchBorders",void 0),e([S("_renderer.renderingDisabled")],Ye.prototype,"renderingDisabled",void 0),Ye=e([E("esri.views.3d.terrain.TerrainSurface")],Ye);const $e=Ye;function Ke(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function Je(e){return!e.isLeaf&&(e.children.some((e=>e.shouldLoad))||e.children.some((e=>Je(e))))}function Ze(e){return e.isLeaf&&e.parent&&e.parent.shouldLoad}const et=-1,tt=P(),it=A(),rt=[0,0,0],st=new _,at={spatialReference:null,tile:null,extent:null,context:"ground"},nt={spatialReference:null,extent:null,scale:0};export{$e as default};
|