@arcgis/core 4.34.0-next.34 → 4.34.0-next.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/Graphic.js +1 -1
  2. package/arcade/ArcadeDate.js +1 -1
  3. package/arcade/ArcadeModuleResolver.js +1 -1
  4. package/arcade/featureset/actions/GroupBy.js +1 -1
  5. package/arcade/functions/date.js +1 -1
  6. package/assets/esri/core/workers/RemoteClient.js +1 -1
  7. package/assets/esri/core/workers/chunks/{28e04ef3575f164f611a.js → 00870a35b254295bc408.js} +1 -1
  8. package/assets/esri/core/workers/chunks/017adbbb77c9c9b4d49f.js +1 -0
  9. package/assets/esri/core/workers/chunks/{b4b30a7f1b673461dc55.js → 0997e09fe5b0aba1f804.js} +1 -1
  10. package/assets/esri/core/workers/chunks/{9bc6d974b0fce9db64ef.js → 15a5a89cd228a9364332.js} +1 -1
  11. package/assets/esri/core/workers/chunks/{847455bf4fc33d6e6efc.js → 1dc410bc070cabb7198d.js} +1 -1
  12. package/assets/esri/core/workers/chunks/{94a3474e3f45efa4a4fe.js → 2c816d3a737e39e6eb84.js} +1 -1
  13. package/assets/esri/core/workers/chunks/2de11a8e5d426c381991.js +1 -0
  14. package/assets/esri/core/workers/chunks/3a7e43675163f7bed6ac.js +1 -0
  15. package/assets/esri/core/workers/chunks/40b0c5368b8322498189.js +1 -0
  16. package/assets/esri/core/workers/chunks/{4778acd0cfaf0cebeec7.js → 439128f23fa091633d2d.js} +1 -1
  17. package/assets/esri/core/workers/chunks/6000a302369799ea42a6.js +1 -0
  18. package/assets/esri/core/workers/chunks/{5d0c92aaa5891e6cb8f0.js → 641ca71d7c1a07bde66a.js} +1 -1
  19. package/assets/esri/core/workers/chunks/646227b500b92999f2c8.js +1 -0
  20. package/assets/esri/core/workers/chunks/{98f6d4ea026ed96fd3f3.js → 773feb0e0fad26df57ef.js} +1 -1
  21. package/assets/esri/core/workers/chunks/7b1d14a921d30c95d68b.js +1 -0
  22. package/assets/esri/core/workers/chunks/{b78d00c4e493086741e1.js → 7d25f57299c642e727a6.js} +1 -1
  23. package/assets/esri/core/workers/chunks/8b7f6f2d1692b6b6dbd5.js +1 -0
  24. package/assets/esri/core/workers/chunks/91d48c32bf11ad1405c8.js +1 -0
  25. package/assets/esri/core/workers/chunks/9228f760129e48585b54.js +1 -0
  26. package/assets/esri/core/workers/chunks/a36be186ad10200c420c.js +1 -0
  27. package/assets/esri/core/workers/chunks/aa12ba96fb8c91105473.js +1 -0
  28. package/assets/esri/core/workers/chunks/{ea240d9e594bfbd8af68.js → aaf696a1026de569c82d.js} +1 -1
  29. package/assets/esri/core/workers/chunks/b331543767c35e5edcc6.js +1 -0
  30. package/assets/esri/core/workers/chunks/{7d852617e91b51121ea7.js → ba29c535128c4e8ae2d3.js} +1 -1
  31. package/assets/esri/core/workers/chunks/bf60d4da0dff1e14da8e.js +1 -0
  32. package/assets/esri/core/workers/chunks/{39bff604d4b4a1295038.js → c038472cb7f60af9426e.js} +1 -1
  33. package/assets/esri/core/workers/chunks/{ca46f78aac1133d127fa.js → c1e5e2a6e7e2d7a1d63c.js} +1 -1
  34. package/assets/esri/core/workers/chunks/{a809042fdce7ced2a415.js → cc3ca1729af33688c1e3.js} +1 -1
  35. package/assets/esri/core/workers/chunks/cde79c3644166d4798a8.js +1 -0
  36. package/assets/esri/core/workers/chunks/{181f8bbe670b4468307a.js → ce8f0ed9179c0d314df8.js} +1 -1
  37. package/assets/esri/core/workers/chunks/{ac30cf2f9a94597f7665.js → d6b2ab614f308db50c4a.js} +2 -2
  38. package/assets/esri/core/workers/chunks/{abe2cdfc2eda46b00812.js → d9045b964f536695840b.js} +1 -1
  39. package/assets/esri/core/workers/chunks/dde6000aa2f69f6ecad0.js +1 -0
  40. package/assets/esri/core/workers/chunks/dec9656997683ef01ba6.js +1 -0
  41. package/assets/esri/core/workers/chunks/e18bb372457cedbf4f8c.js +1 -0
  42. package/assets/esri/core/workers/chunks/e892ed8b0b990d7eba28.js +1 -0
  43. package/assets/esri/core/workers/chunks/{dc5a8cf2a44a5ac201c5.js → ed05399f9a07fea66685.js} +1 -1
  44. package/config.js +1 -1
  45. package/core/BidiEngine.js +1 -1
  46. package/core/Promise.js +1 -1
  47. package/core/promiseUtils.js +1 -1
  48. package/core/sql/SqlInterval.js +1 -1
  49. package/core/sql/sqlDateParsingUtils.js +1 -1
  50. package/core/unitUtils.js +1 -1
  51. package/geometry/support/coordinateSystem.js +1 -1
  52. package/graphic/BuildingGraphicOrigin.d.ts +4 -0
  53. package/graphic/BuildingGraphicOrigin.js +5 -0
  54. package/graphic/CSVGraphicOrigin.d.ts +4 -0
  55. package/graphic/CSVGraphicOrigin.js +5 -0
  56. package/graphic/CatalogGraphicOrigin.d.ts +4 -0
  57. package/graphic/CatalogGraphicOrigin.js +5 -0
  58. package/graphic/FeatureGraphicOrigin.d.ts +4 -0
  59. package/graphic/FeatureGraphicOrigin.js +5 -0
  60. package/graphic/GeoJSONGraphicOrigin.d.ts +4 -0
  61. package/graphic/GeoJSONGraphicOrigin.js +5 -0
  62. package/graphic/GraphicOrigin.d.ts +4 -0
  63. package/graphic/GraphicOrigin.js +5 -0
  64. package/graphic/IntegratedMesh3DTilesGraphicOrigin.d.ts +4 -0
  65. package/graphic/IntegratedMesh3DTilesGraphicOrigin.js +5 -0
  66. package/graphic/IntegratedMeshGraphicOrigin.d.ts +4 -0
  67. package/graphic/IntegratedMeshGraphicOrigin.js +5 -0
  68. package/graphic/OGCFeatureGraphicOrigin.d.ts +4 -0
  69. package/graphic/OGCFeatureGraphicOrigin.js +5 -0
  70. package/graphic/PointCloudGraphicOrigin.d.ts +4 -0
  71. package/graphic/PointCloudGraphicOrigin.js +5 -0
  72. package/graphic/SceneGraphicOrigin.d.ts +4 -0
  73. package/graphic/SceneGraphicOrigin.js +5 -0
  74. package/graphic/StreamGraphicOrigin.d.ts +4 -0
  75. package/graphic/StreamGraphicOrigin.js +5 -0
  76. package/graphic/VectorTileGraphicOrigin.d.ts +4 -0
  77. package/graphic/VectorTileGraphicOrigin.js +5 -0
  78. package/graphic/VoxelGraphicOrigin.d.ts +4 -0
  79. package/graphic/VoxelGraphicOrigin.js +5 -0
  80. package/graphic/WFSGraphicOrigin.d.ts +4 -0
  81. package/graphic/WFSGraphicOrigin.js +5 -0
  82. package/graphic/graphicOriginUtils.js +5 -0
  83. package/graphic/graphicOrigins.d.ts +14 -0
  84. package/graphic/graphicOrigins.js +5 -0
  85. package/graphic/isBuildingGraphicOrigin.js +5 -0
  86. package/graphic/isCSVGraphicOrigin.js +5 -0
  87. package/graphic/isCatalogGraphicOrigin.js +5 -0
  88. package/graphic/isFeatureGraphicOrigin.js +5 -0
  89. package/graphic/isGeoJSONGraphicOrigin.js +5 -0
  90. package/graphic/isIntegratedMesh3DTilesGraphicOrigin.js +5 -0
  91. package/graphic/isIntegratedMeshGraphicOrigin.js +5 -0
  92. package/graphic/isOGCFeatureGraphicOrigin.js +5 -0
  93. package/graphic/isPointCloudGraphicOrigin.js +5 -0
  94. package/graphic/isSceneGraphicOrigin.js +5 -0
  95. package/graphic/isStreamGraphicOrigin.js +5 -0
  96. package/graphic/isVectorTileGraphicOrigin.js +5 -0
  97. package/graphic/isVoxelGraphicOrigin.js +5 -0
  98. package/graphic/isWFSGraphicOrigin.js +5 -0
  99. package/interfaces.d.ts +354 -13
  100. package/kernel.js +1 -1
  101. package/layers/graphics/controllers/FeatureTileController3D.js +1 -1
  102. package/layers/support/Field.js +1 -1
  103. package/layers/support/featurePopupQueryUtils.js +1 -1
  104. package/layers/voxel/NCTimeParser.js +1 -1
  105. package/package.json +1 -1
  106. package/rest/knowledgeGraphService.js +1 -1
  107. package/smartMapping/statistics/support/utils.js +1 -1
  108. package/support/arcadeExpressionUtils.js +1 -1
  109. package/support/revision.js +1 -1
  110. package/symbols/support/svgUtils.js +1 -1
  111. package/views/2d/engine/vectorTiles/VectorTileFeatureIndex.js +1 -1
  112. package/views/2d/engine/webgl/FeatureDisplayList.js +1 -1
  113. package/views/2d/engine/webgl/Painter.js +1 -1
  114. package/views/2d/engine/webgl/mesh/templates/segmentUtils.js +1 -1
  115. package/views/2d/engine/webgl/shaderGraph/techniques/labels/LabelTechnique.js +1 -1
  116. package/views/2d/layers/FeatureLayerView2D.js +1 -1
  117. package/views/2d/layers/VectorTileLayerView2D.js +1 -1
  118. package/views/2d/layers/features/layerAdapters/CatalogFootprintLayerAdapter.js +1 -1
  119. package/views/3d/analysis/VolumeMeasurement/CutFillVolumeMeasurementComputation.js +5 -0
  120. package/views/3d/analysis/VolumeMeasurement/CutFillVolumeMeasurementController.js +1 -1
  121. package/views/3d/interactive/snapping/featureSources/featureServiceSource/FeatureServiceTiles3D.js +1 -1
  122. package/views/3d/layers/BuildingComponentSublayerView3D.js +1 -1
  123. package/views/3d/layers/CSVLayerView3D.js +1 -1
  124. package/views/3d/layers/CatalogFootprintLayerView3D.js +1 -1
  125. package/views/3d/layers/FeatureLayerView3D.js +1 -1
  126. package/views/3d/layers/FeatureLikeLayerView3D.js +1 -1
  127. package/views/3d/layers/FlowSubView3D.js +1 -1
  128. package/views/3d/layers/GeoJSONLayerView3D.js +1 -1
  129. package/views/3d/layers/IntegratedMeshLayerView3D.js +1 -1
  130. package/views/3d/layers/OGCFeatureLayerView3D.js +1 -1
  131. package/views/3d/layers/PointCloudLayerView3D.js +1 -1
  132. package/views/3d/layers/SceneLayerGraphicsView3D.js +1 -1
  133. package/views/3d/layers/SceneLayerView3D.js +1 -1
  134. package/views/3d/layers/StreamLayerView3D.js +1 -1
  135. package/views/3d/layers/WFSLayerView3D.js +1 -1
  136. package/views/3d/layers/graphics/Graphics3DFeatureProcessor.js +1 -1
  137. package/views/3d/layers/graphics/StreamController.js +1 -1
  138. package/views/3d/layers/graphics/pipeline/Feature3DPipeline.js +1 -1
  139. package/views/3d/layers/graphics/pipeline/Feature3DPipelineWorkerHandle.js +1 -1
  140. package/views/3d/layers/graphics/pipeline/Tile3DManager.js +1 -1
  141. package/views/3d/layers/support/FeatureTileDescriptor.js +1 -1
  142. package/views/3d/layers/support/FeatureTileFetcher3D.js +1 -1
  143. package/views/3d/layers/support/FeatureTileFetcher3DContext.js +1 -1
  144. package/views/3d/layers/support/FeatureTileMeasurements3D.js +1 -1
  145. package/views/3d/layers/support/FeatureTileTree3D.js +1 -1
  146. package/views/3d/layers/support/FeatureTileTree3DDebugger.js +1 -1
  147. package/views/3d/layers/support/FeatureTileVisibility3D.js +1 -1
  148. package/views/3d/layers/support/Tiles3DIntersectionHandler.js +1 -1
  149. package/views/3d/state/ConstraintsManager.js +1 -1
  150. package/views/3d/support/flow/geometryUtils.js +1 -1
  151. package/views/3d/terrain/OverlayManager.js +1 -1
  152. package/views/3d/terrain/TerrainSurface.js +1 -1
  153. package/views/3d/terrain/Tile.js +1 -1
  154. package/views/3d/webgl-engine/core/FBOCache.js +1 -1
  155. package/views/SceneView.js +1 -1
  156. package/views/interactive/Tooltip.js +1 -1
  157. package/views/layers/FeatureLayerView.js +1 -1
  158. package/views/layers/support/popupUtils.js +1 -1
  159. package/widgets/Editor/UpdateFeaturesWorkflow.js +1 -1
  160. package/assets/esri/core/workers/chunks/07b2cc0f6b064277632f.js +0 -1
  161. package/assets/esri/core/workers/chunks/13f9e92e7e5d44d9f95c.js +0 -1
  162. package/assets/esri/core/workers/chunks/140efe4735605258ecc9.js +0 -1
  163. package/assets/esri/core/workers/chunks/2b76e716f478468b6798.js +0 -1
  164. package/assets/esri/core/workers/chunks/386ab72a45102c2d47f2.js +0 -1
  165. package/assets/esri/core/workers/chunks/3fb6146d914f9b410c2e.js +0 -1
  166. package/assets/esri/core/workers/chunks/432365fcd7becd508541.js +0 -1
  167. package/assets/esri/core/workers/chunks/439ce953a25b2776cb7f.js +0 -1
  168. package/assets/esri/core/workers/chunks/4c8d2334fcdb1354ff43.js +0 -1
  169. package/assets/esri/core/workers/chunks/5f321be63ed5447b04a1.js +0 -1
  170. package/assets/esri/core/workers/chunks/6006fbdb90c3bfc493a6.js +0 -1
  171. package/assets/esri/core/workers/chunks/700c641347853b1034d9.js +0 -1
  172. package/assets/esri/core/workers/chunks/7c35c61e3673cf94cdfd.js +0 -1
  173. package/assets/esri/core/workers/chunks/7c75876a0c6460585055.js +0 -1
  174. package/assets/esri/core/workers/chunks/949dc266ac6f3505d357.js +0 -1
  175. package/assets/esri/core/workers/chunks/a84af1b8b64b86b49bd3.js +0 -1
  176. package/assets/esri/core/workers/chunks/a9d83a442d8d7a376fc0.js +0 -1
  177. package/assets/esri/core/workers/chunks/ba1b21a90b257ac9a342.js +0 -1
  178. package/assets/esri/core/workers/chunks/f9ad37dfbe1d14c6a352.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.34/esri/copyright.txt for details.
4
4
  */
5
- import{destroyMaybe as e}from"../../../../core/maybe.js";import{createFeatureTileQuery3D as t}from"./featureTileQuery3D.js";class r{constructor(e){this._memoryCache=null;const r=e.layerView.layer;this._layerView=e.layerView,this.objectIdField=r.objectIdField,this.globalIdField="globalIdField"in r?r.globalIdField:null,this._returnZ=e.returnZ,this._returnM=e.returnM;const i=this._layerView.view.resourceController;this.query=t(this._layerView,i.normal),i&&this._memoryCacheEnabled&&(this._memoryCache=i.memoryController.newCache(`fl-${r.uid}`))}get _memoryCacheEnabled(){switch(this._layerView.layer.source.type){case"feature-layer":case"ogc-feature":case"oriented-imagery":return!0;case"csv":case"parquet":case"geojson":case"memory":case"wfs":return!1}}destroy(){this._memoryCache=e(this._memoryCache),this.query.destroy()}createQuery(){const e=this._layerView.layer.createQuery();return e.outFields=this._layerView.availableFields,e.returnZ=this._returnZ,e.returnM=this._returnM,e.outSpatialReference=this.tilingScheme.spatialReference,e}get memoryCache(){return this._memoryCache}get viewingMode(){return this._layerView.view.state.viewingMode}get tilingScheme(){return this._layerView.view.featureTiles.tilingScheme}get scheduler(){return this._layerView.view.resourceController?.scheduler}get geometryType(){return this._layerView.layer.geometryType}get fullExtent(){return this._layerView.layer.fullExtent}get tileMaxRecordCount(){return this._layerView.layer.capabilities.query.tileMaxRecordCount}get standardMaxRecordCount(){return this._layerView.layer.capabilities.query.standardMaxRecordCount}get maxRecordCount(){return this._layerView.layer.capabilities.query.maxRecordCount}get isDraped(){return"on-the-ground"===this._layerView.layer.elevationInfo?.mode}get effectiveDisplayFilter(){return this._layerView.displayFilterEnabled?this._layerView.effectiveDisplayFilter:null}get highlightIds(){return this._layerView.displayFilterEnabled?this._layerView.highlightIds:null}get capabilities(){return this._capabilities??=i(this._layerView.layer),this._capabilities}logFetchError(e,t){e.error("#fetchTile()",this._layerView.layer,t?.message??t)}}function i(e){const t=e.capabilities.query;return{supportsMultipleResolutions:a(e),supportsPagination:!(!t||!t.supportsPagination),supportsResultType:!(!t||!t.supportsResultType),supportsCacheHint:!(!t||!t.supportsCacheHint),supportsQuantization:!(!t||!t.supportsQuantization),supportsQuantizationEditMode:!(!t||!t.supportsQuantizationEditMode),supportsMaxRecordCountFactor:!(!t||!t.supportsMaxRecordCountFactor),supportsFormatPBF:!(!t||!t.supportsFormatPBF)}}function a(e){switch(e.geometryType){case"polyline":return!0;case"polygon":return e.capabilities&&e.capabilities.query&&e.capabilities.query.supportsQuantization;default:return!1}}export{r as FeatureTileFetcher3DContext,i as contextCapabilitiesFromLayer};
5
+ import{destroyMaybe as e}from"../../../../core/maybe.js";import{createFeatureTileQuery3D as t}from"./featureTileQuery3D.js";class r{constructor(e){this._memoryCache=null;const r=e.layerView.layer;this._layerView=e.layerView,this.objectIdField=r.objectIdField,this.globalIdField="globalIdField"in r?r.globalIdField:null,this._returnZ=e.returnZ,this._returnM=e.returnM;const i=this._layerView.view.resourceController;this.query=t(this._layerView,i.normal),i&&this._memoryCacheEnabled&&(this._memoryCache=i.memoryController.newCache(`fl-${r.uid}`))}get _memoryCacheEnabled(){switch(this._layerView.layer.source.type){case"feature-layer":case"ogc-feature":case"oriented-imagery":return!0;case"csv":case"parquet":case"geojson":case"memory":case"wfs":return!1}}destroy(){this._memoryCache=e(this._memoryCache),this.query.destroy()}createQuery(){const e=this._layerView.layer.createQuery();return e.outFields=this._layerView.availableFields,e.returnZ=this._returnZ,e.returnM=this._returnM,e.outSpatialReference=this.tilingScheme?.spatialReference??this._layerView.view.spatialReference,e}get memoryCache(){return this._memoryCache}get viewingMode(){return this._layerView.view.state.viewingMode}get tilingScheme(){return this._layerView.view.featureTiles?.tilingScheme}get scheduler(){return this._layerView.view.resourceController?.scheduler}get geometryType(){return this._layerView.layer.geometryType}get fullExtent(){return this._layerView.layer.fullExtent}get tileMaxRecordCount(){return this._layerView.layer.capabilities.query.tileMaxRecordCount}get standardMaxRecordCount(){return this._layerView.layer.capabilities.query.standardMaxRecordCount}get maxRecordCount(){return this._layerView.layer.capabilities.query.maxRecordCount}get isDraped(){return"on-the-ground"===this._layerView.layer.elevationInfo?.mode}get effectiveDisplayFilter(){return this._layerView.displayFilterEnabled?this._layerView.effectiveDisplayFilter:null}get highlightIds(){return this._layerView.displayFilterEnabled?this._layerView.highlightIds:null}get capabilities(){return this._capabilities??=i(this._layerView.layer),this._capabilities}logFetchError(e,t){e.error("#fetchTile()",this._layerView.layer,t?.message??t)}}function i(e){const t=e.capabilities.query;return{supportsMultipleResolutions:a(e),supportsPagination:!(!t||!t.supportsPagination),supportsResultType:!(!t||!t.supportsResultType),supportsCacheHint:!(!t||!t.supportsCacheHint),supportsQuantization:!(!t||!t.supportsQuantization),supportsQuantizationEditMode:!(!t||!t.supportsQuantizationEditMode),supportsMaxRecordCountFactor:!(!t||!t.supportsMaxRecordCountFactor),supportsFormatPBF:!(!t||!t.supportsFormatPBF)}}function a(e){switch(e.geometryType){case"polyline":return!0;case"polygon":return e.capabilities&&e.capabilities.query&&e.capabilities.query.supportsQuantization;default:return!1}}export{r as FeatureTileFetcher3DContext,i as contextCapabilitiesFromLayer};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{H as e,i as t,n as s,e as i,g as o,c as r,F as a}from"../../../../chunks/vec32.js";import{freeze as n,ZEROS as l,create as c}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{distance as d}from"../../../../geometry/support/aaBoundingRect.js";import{intersectsPoint as h}from"../../../../geometry/support/frustum.js";import{fromValues as m}from"../../../../geometry/support/ray.js";import{FeatureTileVisibility3D as p,minTileLOD as u}from"./FeatureTileVisibility3D.js";import _ from"../../webgl/RenderCamera.js";class f{constructor(e,t,s){this._renderCoordsHelper=e,this._tilingScheme=t,this._camera=new _,this._surfaceElevation=0,this._focusOnMap=[0,0],this._visibility=new p(e,s)}set opaqueGround(e){this._visibility.opaqueGround=e}setup(e,t,s){this._camera.copyFrom(e),this._surfaceElevation=s,this._focusOnMap[0]=t.x,this._focusOnMap[1]=t.y,this._visibility.setup(this._camera)}done(){this._visibility.done()}update(e){const{measures:t,extent:s,level:i}=e;t.visible=this._visibility.compute(e),t.distance=d(s,this._focusOnMap),t.mergeable=!0,t.lodLevel=u,t.splitPriority=Math.max(0,u-i),t.visible&&(this._isGlobal?this._updateSplitAndLodGlobal(e):this._updateSplitAndLodLocal(e))}_updateSplitAndLodGlobal(r){const a=r.level,n=this._renderCoordsHelper,{eye:l,fov:c}=this._camera,d=n.referenceEllipsoid.radius,h=e(l)-d;if(2*Math.atan(d/h)<c&&h>0)return void(r.measures.lodLevel=Math.max(a,u));const m=v,{extent:p}=r,{_surfaceElevation:_}=this;t(m[0],p[0],p[1],_),t(m[1],p[2],p[1],_),t(m[2],p[2],p[3],_),t(m[3],p[0],p[3],_);const f=t(M,.5*(p[0]+p[2]),.5*(p[1]+p[3]),_),y=this._tilingScheme.spatialReference;for(let e=0;e<4;++e)n.toRenderCoords(m[e],y,m[e]);n.toRenderCoords(f,y,f);const x=s(b.direction,f),L=i(l,x),S=o(g,x,L);this._updateSplitAndLod(r,m,f,S)}_updateSplitAndLodLocal(e){const s=v,{extent:i}=e,{_surfaceElevation:o}=this;t(s[0],i[0],i[1],o),t(s[1],i[2],i[1],o),t(s[2],i[2],i[3],o),t(s[3],i[0],i[3],o);const a=this._tilingScheme.spatialReference;for(let t=0;t<4;++t)this._renderCoordsHelper.toRenderCoords(s[t],a,s[t]);const n=t(M,.5*(s[0][0]+s[2][0]),.5*(s[0][1]+s[2][1]),.25*(s[0][2]+s[1][2]+s[2][2]+s[3][2])),l=t(y,n[0],n[1],0),{eye:c,far:d}=this._camera,h=t(g,l[0],l[1],c[2]);t(b.origin,l[0],l[1],c[2]-2*d),r(b.direction,x),this._updateSplitAndLod(e,s,n,h)}_updateSplitAndLod(e,t,s,o){const r=Math.max(a(t[0],t[2]),a(t[1],t[3]),a(t[0],s)+a(s,t[2]),a(t[1],s)+a(s,t[3])),{eye:n,near:l,fov:c,viewForward:d,width:m,height:p,pixelRatio:u,frustum:_}=this._camera,f=i(n,d),v=i(s,d)-f,M=a(s,n);let y=v,g=v,x=M,b=M;const R=(e,t)=>t<l?1:Math.sqrt(e*e-t*t)/t;let j=R(M,v);for(const h of t){const e=i(h,d)-f;y=Math.min(y,e),g=Math.max(g,e);const t=a(h,n);b=Math.max(b,t),x=Math.min(x,t);const s=R(t,e);j=Math.min(j,s)}if(g<l)return void(e.measures.lodLevel=0);const w=Math.cos(.5*c),A=a(n,o);j>w&&A>S*r&&(g=C*b,y=C*x);const G=.5*Math.sqrt(m*m+p*p)/u,E=2*Math.tan(.5*c),H=e=>Math.max(l,e)*L/G*E,q=e.level,F=r*2**q*Math.max(1,E),O=H(y),P=Math.ceil(Math.log2(Math.max(1,F/O)));if(e.measures.lodLevel=Math.max(P,e.measures.lodLevel),e.measures.splitPriority+=e.measures.lodLevel-q,q<P){const s=+h(_,t[0])+ +h(_,t[1])+ +h(_,t[2])+ +h(_,t[3]);e.measures.splitPriority+=s}const k=H(g)/O;k>2.5&&(e.measures.splitPriority+=k)}get _isGlobal(){return 1===this._renderCoordsHelper.viewingMode}}const v=[c(),c(),c(),c()],M=c(),y=c(),g=c(),x=n(0,0,1),b=m(l,x),L=312,S=.5,C=2;export{f as FeatureTileMeasurements3D};
5
+ import{H as e,i as t,n as s,e as i,g as o,c as r,F as a}from"../../../../chunks/vec32.js";import{create as n,freeze as l,ZEROS as c}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{distance as d}from"../../../../geometry/support/aaBoundingRect.js";import{intersectsPoint as h}from"../../../../geometry/support/frustum.js";import{fromValues as m}from"../../../../geometry/support/ray.js";import{FeatureTileVisibility3D as p,minTileLOD as u}from"./FeatureTileVisibility3D.js";import _ from"../../webgl/RenderCamera.js";class f{constructor(e,t,s){this._renderCoordsHelper=e,this._tilingScheme=t,this._camera=new _,this._surfaceElevation=0,this._focusOnMap=[0,0],this._visibility=new p(e,s)}set opaqueGround(e){this._visibility.opaqueGround=e}setup(e,t,s){this._camera.copyFrom(e),this._surfaceElevation=s,this._focusOnMap[0]=t.x,this._focusOnMap[1]=t.y,this._visibility.setup(this._camera)}done(){this._visibility.done()}update(e){const{measures:t,extent:s,level:i}=e;s&&(t.visible=this._visibility.compute(e),t.distance=d(s,this._focusOnMap),t.mergeable=!0,t.lodLevel=u,t.splitPriority=Math.max(0,u-i),t.visible&&(this._isGlobal?this._updateSplitAndLodGlobal(e):this._updateSplitAndLodLocal(e)))}_updateSplitAndLodGlobal(r){const a=r.level,n=this._renderCoordsHelper,{eye:l,fov:c}=this._camera,d=n.referenceEllipsoid.radius,h=e(l)-d;if(2*Math.atan(d/h)<c&&h>0)return void(r.measures.lodLevel=Math.max(a,u));const m=v,{extent:p}=r;if(!p)return;const{_surfaceElevation:_}=this;t(m[0],p[0],p[1],_),t(m[1],p[2],p[1],_),t(m[2],p[2],p[3],_),t(m[3],p[0],p[3],_);const f=t(M,.5*(p[0]+p[2]),.5*(p[1]+p[3]),_),y=this._tilingScheme.spatialReference;for(let e=0;e<4;++e)n.toRenderCoords(m[e],y,m[e]);n.toRenderCoords(f,y,f);const x=s(b.direction,f),L=i(l,x),S=o(g,x,L);this._updateSplitAndLod(r,m,f,S)}_updateSplitAndLodLocal(e){const s=v,{extent:i}=e;if(!i)return;const{_surfaceElevation:o}=this;t(s[0],i[0],i[1],o),t(s[1],i[2],i[1],o),t(s[2],i[2],i[3],o),t(s[3],i[0],i[3],o);const a=this._tilingScheme.spatialReference;for(let t=0;t<4;++t)this._renderCoordsHelper.toRenderCoords(s[t],a,s[t]);const n=t(M,.5*(s[0][0]+s[2][0]),.5*(s[0][1]+s[2][1]),.25*(s[0][2]+s[1][2]+s[2][2]+s[3][2])),l=t(y,n[0],n[1],0),{eye:c,far:d}=this._camera,h=t(g,l[0],l[1],c[2]);t(b.origin,l[0],l[1],c[2]-2*d),r(b.direction,x),this._updateSplitAndLod(e,s,n,h)}_updateSplitAndLod(e,t,s,o){const r=Math.max(a(t[0],t[2]),a(t[1],t[3]),a(t[0],s)+a(s,t[2]),a(t[1],s)+a(s,t[3])),{eye:n,near:l,fov:c,viewForward:d,width:m,height:p,pixelRatio:u,frustum:_}=this._camera,f=i(n,d),v=i(s,d)-f,M=a(s,n);let y=v,g=v,x=M,b=M;const R=(e,t)=>t<l?1:Math.sqrt(e*e-t*t)/t;let j=R(M,v);for(const h of t){const e=i(h,d)-f;y=Math.min(y,e),g=Math.max(g,e);const t=a(h,n);b=Math.max(b,t),x=Math.min(x,t);const s=R(t,e);j=Math.min(j,s)}if(g<l)return void(e.measures.lodLevel=0);const w=Math.cos(.5*c),A=a(n,o);j>w&&A>S*r&&(g=C*b,y=C*x);const G=.5*Math.sqrt(m*m+p*p)/u,E=2*Math.tan(.5*c),H=e=>Math.max(l,e)*L/G*E,q=e.level,F=r*2**q*Math.max(1,E),O=H(y),P=Math.ceil(Math.log2(Math.max(1,F/O)));if(e.measures.lodLevel=Math.max(P,e.measures.lodLevel),e.measures.splitPriority+=e.measures.lodLevel-q,q<P){const s=+h(_,t[0])+ +h(_,t[1])+ +h(_,t[2])+ +h(_,t[3]);e.measures.splitPriority+=s}const k=H(g)/O;k>2.5&&(e.measures.splitPriority+=k)}get _isGlobal(){return 1===this._renderCoordsHelper.viewingMode}}const v=[n(),n(),n(),n()],M=n(),y=n(),g=n(),x=l(0,0,1),b=m(c,x),L=312,S=.5,C=2;export{f as FeatureTileMeasurements3D};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import t from"../../../../core/Accessor.js";import s from"../../../../core/Collection.js";import{makeHandle as i}from"../../../../core/handleUtils.js";import"../../../../core/has.js";import r from"../../../../core/Logger.js";import{removeMaybe as o}from"../../../../core/maybe.js";import l from"../../../../core/PooledArray.js";import{watch as n,syncAndInitial as a,sync as u}from"../../../../core/reactiveUtils.js";import{signal as h}from"../../../../core/signal.js";import{generateUID as d}from"../../../../core/uid.js";import{property as c}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/RandomLCG.js";import{subclass as m}from"../../../../core/accessorSupport/decorators/subclass.js";import{create as p,intersects as _}from"../../../../geometry/support/aaBoundingRect.js";import{FeatureTileDescriptor as f,getFeatureTileId as g}from"./FeatureTileDescriptor.js";import{FeatureTileMeasurements3D as T}from"./FeatureTileMeasurements3D.js";import{maxLODLevelDelta as v}from"./FeatureTileVisibility3D.js";import{toBoundingRect as y}from"../../support/extentUtils.js";import{TaskPriority as w,noBudget as E}from"../../../support/Scheduler.js";const S=60;let R=class extends t{constructor(e){super(e),this.tiles=new s,this.tileSize=512,this._idToTile=new Map,this._clients=new Set,this._dirty=h(!1),this._pendingTiles=h(null),this._newTiles=new l,this._tests=!1,this._measurements=new T(e.renderCoordsHelper,e.tilingSchemeOwner.tilingScheme,this._opaqueGround)}initialize(){const e=()=>this._setDirty(),t=()=>this._reset();this.addHandles([n(()=>this.tileSize,t,a),n(()=>this.cameraOnSurface?.location,e,a),n(()=>this.viewState?.contentCamera,e,a),n(()=>this.focus?.location,e,a),n(()=>this.terrain?.baseOpacity??1,e),n(()=>this.tilingScheme,e=>{this._reset(),this._measurements=new T(this.renderCoordsHelper,e,this._opaqueGround)},u),n(()=>this._opaqueGround,e=>this._measurements.opaqueGround=e,u)]),this._frameWorker=this.scheduler?.registerTask(w.FEATURE_TILE_TREE,this)}destroy(){this._frameWorker=o(this._frameWorker),this._measurements=null,this._newTiles.prune()}get tilingScheme(){const e=this.tilingSchemeOwner.tilingScheme;if(!e)return null;return e.clone()}set filterExtent(e){if(null!=e&&!e.spatialReference.equals(this.viewState.spatialReference))return void r.getLogger(this).error("#extent","extent spatial reference needs to be in the same spatial reference as the view");const t=this._get("filterExtent");if(t===e||null!=t&&e&&t.equals(e))return;const s=null!=e?e.clone():null;this._set("filterExtent",s),this._setDirty()}get _filterExtentRect(){if(null==this.filterExtent)return null;const e=p();return y(this.filterExtent,e,this.tilingScheme.spatialReference),e}get _rootTileIds(){const{tilingScheme:e}=this;return this._filterExtentRect&&e?e.rootTilesInExtent(this._filterExtentRect):[[0,0,0]]}set suspended(e){e!==this._get("suspended")&&(this._set("suspended",e),this._setDirty())}get updating(){return this._dirty.value||!!this._pendingTiles.value}addClient(){const e=d();return this._clients.add(e),1===this._clients.size&&this._setDirty(),i(()=>this._removeClient(e))}_removeClient(e){this._clients.delete(e),this._hasClients||this._clear()}get _hasClients(){return this._clients.size>0}get _opaqueGround(){return 1===(this.terrain?.baseOpacity??1)}_setDirty(){this._hasClients&&!this.suspended&&(this._frameWorker?this._dirty.value=!0:this.runTask(E))}_clear(){this.tiles.removeAll(),this._idToTile.clear(),this._reset(),this._dirty.value=!1}get running(){return this.updating}_reset(){this._newTiles.clear(),this._pendingTiles.value=null,this._setDirty()}_getRootTiles(){const e=this.tilingScheme;return this._rootTileIds.map(t=>new f(t[0],t[1],t[2],e))}runTask(e){e=this._tests?E:e,this._dirty.value=!1,this._pendingTiles.value||(this._startUpdate(e),null!=this._frameWorker&&(this._frameWorker.priority=w.FEATURE_TILE_TREE_ACTIVE)),this._splitPendingTiles(e),this._pendingTiles.value||null==this._frameWorker||(this._frameWorker.priority=w.FEATURE_TILE_TREE)}_startUpdate(e){if(this.suspended)return;if(!this.tilingScheme)return void this._clear();const{_measurements:t,_filterExtentRect:s,_newTiles:i}=this;t.setup(this.viewState.contentCamera,this.focus.location,this.cameraOnSurface.location.z??0),this._pendingTiles.value=this._getRootTiles().filter(e=>{if(t.update(e),e.measures.visible&&(!s||_(e.extent,s))){if(e.measures.splitPriority>0)return!0;i.push(e)}return!1}).sort(x),this._newTiles.clear(),e.madeProgress()}_splitPendingTiles(e){const t=this._pendingTiles.value;if(!t)return;const{tilingScheme:s,_filterExtentRect:i,_newTiles:r,_measurements:o}=this;for(;t.length>0&&this._tileBudgetRatio<=2;){const l=t.pop();if(e.madeProgress(),l.measures.splitPriority>0){s.ensureMaxLod(l.level+1);const e=l.createChildren();for(const s of e)o.update(s),!s.measures.visible||i&&!_(s.extent,i)||(s.measures.splitPriority>0?t.push(s):r.push(s));t.sort(x),this._mergeNewTiles(2),this._mergeNewTiles(2,!0)}else r.push(l);if(e.done)return}r.pushArray(t),this._pendingTiles.value=null,this._updateTiles(),r.clear(),o.done()}get _tileBudgetRatio(){return(this._newTiles.length+(this._pendingTiles.value?.length??0))/S}_mergeNewTiles(e,t=!1){if(this._tileBudgetRatio<=e)return;const{_newTiles:s,_measurements:i}=this;s.sort((e,t)=>t.measures.distance-e.measures.distance);const r=new Map(s.map(e=>[e.id,e])),o=s.length;for(const l of r.values()){const{lij:o,measures:n}=l;if(!n.mergeable||o[1]%2!=0||o[2]%2!=0||o[0]<=1||l.lodLevelDelta>=v)continue;const a=n.lodLevel;let u=a,h=!0;const d=r.get(g(o[0],o[1]+1,o[2]));let c=Math.abs((d?.measures.lodLevel??0)-a),m=0===c||t&&d?.measures.mergeable&&c<=1;if(!d||!m)continue;u+=d.measures.lodLevel,h&&=0===c;const p=r.get(g(o[0],o[1],o[2]+1));if(c=Math.abs((p?.measures.lodLevel??0)-a),m=0===c||t&&p?.measures.mergeable&&c<=1,!p||!m)continue;u+=p.measures.lodLevel,h&&=0===c;const _=r.get(g(o[0],o[1]+1,o[2]+1));if(c=Math.abs((_?.measures.lodLevel??0)-a),m=0===c||t&&_?.measures.mergeable&&c<=1,!_||!m)continue;u+=_.measures.lodLevel,h&&=0===c,s.removeUnordered(l),s.removeUnordered(d),s.removeUnordered(p),s.removeUnordered(_),r.delete(l.id),r.delete(d.id),r.delete(p.id),r.delete(_.id);const T=new f(o[0]-1,o[1]/2,o[2]/2,this.tilingScheme);if(i.update(T),T.measures.visible=!0,T.measures.lodLevel=u/4,T.measures.mergeable=h,s.push(T),r.set(T.id,T),this._tileBudgetRatio<=e)return}s.length<o&&this._mergeNewTiles(e,t)}_updateTiles(){this._mergeNewTiles(1),this._mergeNewTiles(1,!0);for(const i of this.tiles.items)i.used=!1;let e=!1;const t=this._newTiles.filter(t=>{const s=this._idToTile.get(t.id);return s?(e||=s.measures.lodLevel!==t.measures.lodLevel,s.measures={...t.measures},s.used=!0):this._idToTile.set(t.id,t),!s}),s=this.tiles.items.filter(e=>!e.used&&(this._idToTile.delete(e.id),!0));this.tiles.removeMany(s),this.tiles.addMany(t),this._sortTiles(),!e||s.length||t.length||this.tiles.emit("change")}_sortTiles(){this.viewState.fixedContentCamera||this.tiles.sort((e,t)=>e.measures.distance-t.measures.distance),this.tiles.forEach((e,t)=>e.loadPriority=t)}};function x(e,t){return e.lodLevelDelta-t.lodLevelDelta||e.measures.splitPriority-t.measures.splitPriority||t.measures.distance-e.measures.distance}e([c({constructOnly:!0})],R.prototype,"scheduler",void 0),e([c({constructOnly:!0})],R.prototype,"renderCoordsHelper",void 0),e([c({constructOnly:!0})],R.prototype,"tilingSchemeOwner",void 0),e([c({constructOnly:!0})],R.prototype,"cameraOnSurface",void 0),e([c({constructOnly:!0})],R.prototype,"focus",void 0),e([c({constructOnly:!0})],R.prototype,"viewState",void 0),e([c({constructOnly:!0})],R.prototype,"terrain",void 0),e([c()],R.prototype,"tiles",void 0),e([c()],R.prototype,"tileSize",void 0),e([c({readOnly:!0})],R.prototype,"tilingScheme",null),e([c()],R.prototype,"filterExtent",null),e([c({readOnly:!0})],R.prototype,"_filterExtentRect",null),e([c({readOnly:!0})],R.prototype,"_rootTileIds",null),e([c({value:!1})],R.prototype,"suspended",null),e([c({readOnly:!0})],R.prototype,"updating",null),R=e([m("esri.views.3d.layers.support.FeatureTileTree3D")],R);export{R as FeatureTileTree3D};
5
+ import{__decorate as e}from"tslib";import t from"../../../../core/Accessor.js";import s from"../../../../core/Collection.js";import"../../../../core/has.js";import i from"../../../../core/Logger.js";import{removeMaybe as r}from"../../../../core/maybe.js";import o from"../../../../core/PooledArray.js";import{watch as n,syncAndInitial as l,sync as a}from"../../../../core/reactiveUtils.js";import{signal as u}from"../../../../core/signal.js";import{property as h}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/RandomLCG.js";import{subclass as d}from"../../../../core/accessorSupport/decorators/subclass.js";import{create as m,intersects as p}from"../../../../geometry/support/aaBoundingRect.js";import{FeatureTileDescriptor as c,getFeatureTileId as _}from"./FeatureTileDescriptor.js";import{FeatureTileMeasurements3D as f}from"./FeatureTileMeasurements3D.js";import{maxLODLevelDelta as g}from"./FeatureTileVisibility3D.js";import{toBoundingRect as T}from"../../support/extentUtils.js";import{TaskPriority as v,noBudget as y}from"../../../support/Scheduler.js";const w=60;let E=class extends t{constructor(e){super(e),this.tiles=new s,this.tileSize=512,this._idToTile=new Map,this._dirty=u(!1),this._pendingTiles=u(null),this._newTiles=new o,this._tests=!1,this._measurements=new f(e.renderCoordsHelper,e.terrain.tilingScheme,this._opaqueGround)}initialize(){this.addHandles([n(()=>this.tileSize,()=>this._reset(),l),n(()=>[this.pointsOfInterest.cameraOnSurface?.location,this.viewState?.contentCamera,this.pointsOfInterest.focus?.location,this.terrain?.baseOpacity??1],()=>this._setDirty(),l),n(()=>this.tilingScheme,e=>{this._reset(),this._measurements=new f(this.renderCoordsHelper,e,this._opaqueGround)},a),n(()=>this._opaqueGround,e=>this._measurements.opaqueGround=e,a)]),this._frameWorker=this.scheduler?.registerTask(v.FEATURE_TILE_TREE,this)}destroy(){this._frameWorker=r(this._frameWorker),this._measurements=null,this._newTiles.prune()}get tilingScheme(){return this.terrain.tilingScheme?.clone()}set filterExtent(e){if(null!=e&&!e.spatialReference.equals(this.viewState.spatialReference))return void i.getLogger(this).error("#extent","extent spatial reference needs to be in the same spatial reference as the view");const t=this._get("filterExtent");if(t===e||null!=t&&e&&t.equals(e))return;const s=null!=e?e.clone():null;this._set("filterExtent",s),this._setDirty()}get _filterExtentRect(){if(null==this.filterExtent)return null;const e=m();return T(this.filterExtent,e,this.tilingScheme.spatialReference),e}get _rootTileIds(){const{tilingScheme:e}=this;return this._filterExtentRect&&e?e.rootTilesInExtent(this._filterExtentRect):[[0,0,0]]}set suspended(e){e!==this._get("suspended")&&(this._set("suspended",e),this._setDirty())}get updating(){return this._dirty.value||!!this._pendingTiles.value}get _opaqueGround(){return 1===(this.terrain?.baseOpacity??1)}_setDirty(){this.suspended||(this._frameWorker?this._dirty.value=!0:this.runTask(y))}_clear(){this.tiles.removeAll(),this._idToTile.clear(),this._reset(!1),this._dirty.value=!1}get running(){return this.updating}_reset(e=!0){this._newTiles.clear(),this._pendingTiles.value=null,e&&this._setDirty()}_getRootTiles(){const e=this.tilingScheme;return this._rootTileIds.map(t=>new c(t[0],t[1],t[2],e))}runTask(e){e=this._tests?y:e,this._dirty.value=!1,this._pendingTiles.value||(this._startUpdate(e),null!=this._frameWorker&&(this._frameWorker.priority=v.FEATURE_TILE_TREE_ACTIVE)),this._splitPendingTiles(e),this._pendingTiles.value||null==this._frameWorker||(this._frameWorker.priority=v.FEATURE_TILE_TREE)}_startUpdate(e){if(this.suspended)return;if(!this.tilingScheme)return void this._clear();const{_measurements:t,_filterExtentRect:s,_newTiles:i}=this;t.setup(this.viewState.contentCamera,this.pointsOfInterest.focus.location,this.pointsOfInterest.cameraOnSurface.location.z??0),this._pendingTiles.value=this._getRootTiles().filter(e=>{if(t.update(e),e.measures.visible&&(!s||!e.extent||p(e.extent,s))){if(e.measures.splitPriority>0)return!0;i.push(e)}return!1}).sort(x),this._newTiles.clear(),e.madeProgress()}_splitPendingTiles(e){const t=this._pendingTiles.value;if(!t)return;const{tilingScheme:s,_filterExtentRect:i,_newTiles:r,_measurements:o}=this;for(;t.length>0&&this._tileBudgetRatio<=2;){const n=t.pop();if(e.madeProgress(),n.measures.splitPriority>0){s.ensureMaxLod(n.level+1);const e=n.createChildren();for(const s of e)o.update(s),!s.measures.visible||i&&s.extent&&!p(s.extent,i)||(s.measures.splitPriority>0?t.push(s):r.push(s));t.sort(x),this._mergeNewTiles(2),this._mergeNewTiles(2,!0)}else r.push(n);if(e.done)return}r.pushArray(t),this._pendingTiles.value=null,this._updateTiles(),r.clear(),o.done()}get _tileBudgetRatio(){return(this._newTiles.length+(this._pendingTiles.value?.length??0))/w}_mergeNewTiles(e,t=!1){if(this._tileBudgetRatio<=e)return;const{_newTiles:s,_measurements:i}=this;s.sort((e,t)=>t.measures.distance-e.measures.distance);const r=new Map(s.map(e=>[e.id,e])),o=s.length;for(const n of r.values()){const{lij:o,measures:l}=n;if(!l.mergeable||o[1]%2!=0||o[2]%2!=0||o[0]<=1||n.lodLevelDelta>=g)continue;const a=l.lodLevel;let u=a,h=!0;const d=r.get(_(o[0],o[1]+1,o[2]));let m=Math.abs((d?.measures.lodLevel??0)-a),p=0===m||t&&d?.measures.mergeable&&m<=1;if(!d||!p)continue;u+=d.measures.lodLevel,h&&=0===m;const f=r.get(_(o[0],o[1],o[2]+1));if(m=Math.abs((f?.measures.lodLevel??0)-a),p=0===m||t&&f?.measures.mergeable&&m<=1,!f||!p)continue;u+=f.measures.lodLevel,h&&=0===m;const T=r.get(_(o[0],o[1]+1,o[2]+1));if(m=Math.abs((T?.measures.lodLevel??0)-a),p=0===m||t&&T?.measures.mergeable&&m<=1,!T||!p)continue;u+=T.measures.lodLevel,h&&=0===m,s.removeUnordered(n),s.removeUnordered(d),s.removeUnordered(f),s.removeUnordered(T),r.delete(n.id),r.delete(d.id),r.delete(f.id),r.delete(T.id);const v=new c(o[0]-1,o[1]/2,o[2]/2,this.tilingScheme);if(i.update(v),v.measures.visible=!0,v.measures.lodLevel=u/4,v.measures.mergeable=h,s.push(v),r.set(v.id,v),this._tileBudgetRatio<=e)return}s.length<o&&this._mergeNewTiles(e,t)}_updateTiles(){this._mergeNewTiles(1),this._mergeNewTiles(1,!0);for(const i of this.tiles.items)i.used=!1;let e=!1;const t=this._newTiles.filter(t=>{const s=this._idToTile.get(t.id);return s?(e||=s.measures.lodLevel!==t.measures.lodLevel,s.measures={...t.measures},s.used=!0):this._idToTile.set(t.id,t),!s}),s=this.tiles.items.filter(e=>!e.used&&(this._idToTile.delete(e.id),!0));this.tiles.removeMany(s),this.tiles.addMany(t),this._sortTiles(),!e||s.length||t.length||this.tiles.emit("change")}_sortTiles(){this.viewState.fixedContentCamera||this.tiles.sort((e,t)=>e.measures.distance-t.measures.distance),this.tiles.forEach((e,t)=>e.loadPriority=t)}};function x(e,t){return e.lodLevelDelta-t.lodLevelDelta||e.measures.splitPriority-t.measures.splitPriority||t.measures.distance-e.measures.distance}e([h({constructOnly:!0})],E.prototype,"scheduler",void 0),e([h({constructOnly:!0})],E.prototype,"renderCoordsHelper",void 0),e([h({constructOnly:!0})],E.prototype,"pointsOfInterest",void 0),e([h({constructOnly:!0})],E.prototype,"viewState",void 0),e([h({constructOnly:!0})],E.prototype,"terrain",void 0),e([h()],E.prototype,"tiles",void 0),e([h()],E.prototype,"tileSize",void 0),e([h({readOnly:!0})],E.prototype,"tilingScheme",null),e([h()],E.prototype,"filterExtent",null),e([h({readOnly:!0})],E.prototype,"_filterExtentRect",null),e([h({readOnly:!0})],E.prototype,"_rootTileIds",null),e([h({value:!1})],E.prototype,"suspended",null),e([h({readOnly:!0})],E.prototype,"updating",null),E=e([d("esri.views.3d.layers.support.FeatureTileTree3D")],E);export{E as FeatureTileTree3D};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as t}from"tslib";import{initial as e}from"../../../../core/reactiveUtils.js";import{property as r}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/has.js";import"../../../../core/Logger.js";import"../../../../core/RandomLCG.js";import{subclass as o}from"../../../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as i}from"../../../../core/support/UpdatingHandles.js";import s from"../../../../geometry/Polygon.js";import{TileTreeDebugger as a}from"../../../support/TileTreeDebugger.js";let p=class extends a{get updating(){return this._watchUpdatingTracking?.updating??!1}constructor(t){super(t),this._watchUpdatingTracking=new i}initialize(){const{featureTiles:t}=this.view;this.addHandles(t.addClient()),this._watchUpdatingTracking.addOnCollectionChange(()=>t?.tiles,()=>this.update(),e)}destroy(){this._watchUpdatingTracking.destroy()}getTiles(){const t=t=>{const[e,r,o]=t.lij;return s.fromExtent(this.view.featureTiles.tilingScheme.getExtentGeometry(e,r,o))};return this.view.featureTiles.tiles.toArray().sort((t,e)=>t.loadPriority-e.loadPriority).map(e=>({...e,level:e.level,geometry:t(e)}))}};t([r()],p.prototype,"_watchUpdatingTracking",void 0),t([r()],p.prototype,"updating",null),t([r()],p.prototype,"view",void 0),p=t([o("esri.views.3d.layers.support.FeatureTileTree3DDebugger")],p);export{p as FeatureTileTree3DDebugger};
5
+ import{__decorate as t}from"tslib";import{initial as e}from"../../../../core/reactiveUtils.js";import{property as r}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/has.js";import"../../../../core/Logger.js";import"../../../../core/RandomLCG.js";import{subclass as o}from"../../../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as i}from"../../../../core/support/UpdatingHandles.js";import s from"../../../../geometry/Polygon.js";import{TileTreeDebugger as a}from"../../../support/TileTreeDebugger.js";let p=class extends a{get updating(){return this._watchUpdatingTracking?.updating??!1}constructor(t){super(t),this._watchUpdatingTracking=new i}initialize(){this.addHandles(this.view.enableFeatureTiles()),this._watchUpdatingTracking.addOnCollectionChange(()=>this.view.featureTiles?.tiles,()=>this.update(),e)}destroy(){this._watchUpdatingTracking.destroy()}getTiles(){const t=this.view.featureTiles;if(!t)return[];const e=e=>{const[r,o,i]=e.lij;return s.fromExtent(t.tilingScheme.getExtentGeometry(r,o,i))};return t.tiles.toArray().sort((t,e)=>t.loadPriority-e.loadPriority).map(t=>({...t,level:t.level,geometry:e(t)}))}};t([r()],p.prototype,"_watchUpdatingTracking",void 0),t([r()],p.prototype,"updating",null),t([r()],p.prototype,"view",void 0),p=t([o("esri.views.3d.layers.support.FeatureTileTree3DDebugger")],p);export{p as FeatureTileTree3DDebugger};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{n as t,c as r,a as n,e,b as s,i as o,F as i,h as u,f as c,g as f,H as a}from"../../../../chunks/vec32.js";import{create as h,fromValues as l,freeze as m}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as p}from"../../../../geometry/ellipsoidUtils.js";import{getSphericalPCPF as d}from"../../../../geometry/spatialReferenceEllipsoidUtils.js";import{projectBuffer as _}from"../../../../geometry/projection/projectBuffer.js";import{projectVec3Array as g}from"../../../../geometry/projection/projectVec3Array.js";import{fromValues as b,signedDistance as F}from"../../../../geometry/support/plane.js";import{Frustum as M}from"../../state/Frustum.js";class S{constructor(t,r){this._renderCoordsHelper=t,this.opaqueGround=r,this._cache=new Map,this._cameraForward=h(),this._cameraEye=h(),this._cameraFovY=55*Math.PI/180,this._frustumBoundingSphereCenter=h(),this._frustumBoundingSphereRadius=0,this._frustum=new M(t),this._renderSR=t.spatialReference;const n=d(this._renderSR);this._renderSREllipsoidRadius=p(n).radius}setup(n){this._aboveGround=n.aboveGround,this._frustum.update(n),t(this._cameraForward,n.viewForward),r(this._cameraEye,n.eye),this._cameraFovY=n.fovY,this._updateFrustumBoundingSphere()}done(){this._cache.clear()}compute(t){if(this._cache.has(t.id))return this._cache.get(t.id);const r=this._isVisibleInFrustum(t);return this._cache.set(t.id,r),r}_isVisibleInFrustum(t){return 2===this._renderCoordsHelper.viewingMode?this._isTileVisibleInFrustumLocal(t):this._isTileVisibleInFrustumGlobal(t)}_updateFrustumBoundingSphere(){const r=this._frustum,o=r.origin,i=A;t(i,r.direction);const u=r.points,c=W;n(c,u[4],o);const f=.5*e(c,c)/e(i,c),a=this._frustumBoundingSphereCenter;s(a,o,i,f);const h=1+f;this._frustumBoundingSphereRadius=h}_isTileVisibleInFrustumLocal(t){const r=t.spatialReference,u=t.extent,c=this._renderSR;if(C[0]=u[0],C[1]=u[1],C[2]=0,C[3]=u[2],C[4]=u[3],C[5]=0,!_(C,r,0,C,c,0))return!1;o(E[0],C[0],C[1],0),o(E[1],C[3],C[1],0),o(E[2],C[3],C[4],0),o(E[3],C[0],C[4],0),o(k,.5*(C[0]+C[3]),.5*(C[1]+C[4]),.5*(C[2]+C[5]));const f=St,a=.5*i(E[0],E[2]),h=this._frustum,l=this._frustumBoundingSphereRadius,m=this._frustumBoundingSphereCenter,p=D;n(p,m,k);const d=e(f,p),g=z;s(g,k,f,d);if(i(g,m)>a+l)return!1;const b=this._cameraForward,F=e(b,St),M=this._cameraFovY,S=this._cameraEye;if(Math.abs(F)<Math.abs(Math.cos(.5*M))){let t=!0;const r=o(Rt,b[0],b[1],0),n=e(S,r);for(let s=0;s<4;++s){const o=E[s];if(e(o,r)-n>0){t=!1;break}}if(t)return!1}{const t=E[0],r=E[2];if(t[0]<=S[0]&&S[0]<=r[0]&&t[1]<=S[1]&&S[1]<=r[1])return!0}const R=x,v=this.opaqueGround&&this._aboveGround,G=this.opaqueGround&&!this._aboveGround,j=Math.min(G?gt:1/0,d+l),B=Math.max(v?-gt:-1/0,d-l);for(let n=0;n<4;++n)s(R[n],E[n],f,j),s(R[n+4],E[n],f,B);if(y(h.planes,R,8))return!1;if(q(h.planes,R,8))return!0;for(let n=0;n<4;++n){const t=R[n],r=R[n+4];if(vt(h.planes,t,r))return!0;const e=R[(n+1)%4];if(vt(h.planes,t,e))return!0;const s=R[4+(n+1)%4];if(vt(h.planes,r,s))return!0}if(Bt[0][3]=+E[0][0],Bt[1][3]=-E[2][0],Bt[2][3]=+E[0][1],Bt[3][3]=-E[2][1],Bt[4][3]=+B,Bt[5][3]=-j,q(Bt,h.points))return!0;if(q(Bt,h.points))return!0;for(let n=0;n<4;++n){const t=S,r=h.points[n+4];if(Gt(Bt,t,r))return!0;const e=h.points[4+(n+1)%4];if(Gt(Bt,r,e))return!0}return!1}_isTileVisibleInFrustumGlobal(r){if(r.level<w)return!0;const l=r.spatialReference,m=r.extent,p=this.opaqueGround&&this._aboveGround,d=this.opaqueGround&&!this._aboveGround,_=E,b=.5*(m[0]+m[2]);if(o(_[0],m[0],m[1],0),o(_[1],m[2],m[1],0),o(_[2],m[2],m[3],0),o(_[3],m[0],m[3],0),o(_[4],b,m[1],0),o(_[5],b,m[3],0),!g(_,l,0,_,this._renderSR,0,6))return!1;const M=_[0][2]>0,S=_[3][2]<0,j=M||S,B=this._renderSREllipsoidRadius;if(j){const t=T;R(t,yt,_[0]);const r=Y;if(R(r,yt,_[1]),M){const n=P,e=_[4],s=H;R(s,e,yt),R(n,s,e);const o=_[0];u(o,t,n),G(o,B);const i=_[1];u(i,r,n),G(i,B)}else if(S){const n=P,e=_[5],s=H;R(s,e,yt),R(n,e,s);const o=_[3];u(o,n,t),G(o,B);const i=_[2];u(i,n,r),G(i,B)}}const q=k,I=n(Q,_[3],_[0]);t(I,I);const x=c(X,_[0],_[3]);f(x,x,.5);const C=-e(x,I),A=c(Z,_[0],_[1]);f(A,A,.5);const W=c($,_[2],_[3]);f(W,W,.5);const z=n(tt,W,A);t(z,z);const D=-(C+e(I,A))/e(I,z);s(q,A,z,D),G(q,B);const ot=this._frustumBoundingSphereRadius,mt=this._frustumBoundingSphereCenter,pt=this._frustum,dt=pt.planes,St=L;t(St,q);const Rt=e(_[0],St)/a(_[0]),vt=pt.origin,Gt=pt.points;let jt=!1;if(p){{jt=!0;const r=t(bt,vt);for(let s=0;s<4;++s){const o=Gt[4+s],i=n(h(),o,vt);t(i,i);const c=u(h(),r,i);t(c,c);const f=u(h(),i,c);t(f,f);if(e(vt,f)>B){jt=!1;break}}}if(jt){if(e(vt,St)<B*Rt-gt)return!1}const r=t(bt,pt.origin);if(e(r,St)<0)return!1;{const r=t(Ft,pt.direction);if(e(r,St)>Mt)return!1}}const Bt=Math.sqrt(1-Rt*Rt);if(Bt>.9)return!0;let qt=!1;const wt=e(St,mt),It=a(mt);if(It<=ot&&!dt.some(t=>F(t,J)>0)){if(!p)return!0;qt=!0}const Vt=wt/It;if(!qt&&wt<=0){if(-wt>ot)return!1}const xt=ot/It;if(Math.sqrt(1-Vt*Vt)*Math.sqrt(1-xt*xt)-xt*Vt>Bt)return!1;if(!jt){if(_.some(t=>pt.intersectsPoint(t)))return!0;if(pt.intersectsPoint(q))return!0}const Ct=K;n(Ct,mt,J);const Et=e(Ct,St),kt=U;f(kt,St,Et);const Pt=i(kt,mt),Tt=l.isWGS84,Yt=r.lij,Ht=Tt&&Yt[2]===2**Yt[0]-1,Lt=Tt&&0===Yt[2],Ut=Lt?at:Ht?ct:it,At=Lt?ht:Ht?ft:ut;if(!qt){const t=_,r=lt,n=rt,e=nt,s=J;for(const o of Ut){const i=t[o];if(v(n,t[(o+1)%4],i),v(e,s,i),R(r,e,n),V(r,Gt,1))return!1}}let Wt=null;if(!p&&Et<1.01*ot){const t=2.5*ot;if(Pt>Rt*t+ot)return!1;const r=O,n=t/Rt;for(let e=0;e<4;++e)f(r[e],_[e],n/B);o(r[4],0,0,0),Wt=r}else{const t=(d?B+gt:Et+ot)/Rt,r=p?B-gt:(Et-ot)/Rt,n=N;for(let e=0;e<4;++e){const s=_[e];f(n[e],s,r/B),f(n[e+4],s,t/B)}Wt=n}if(y(dt,Wt,Wt.length))return!1;const zt=pt.lines,Dt=et,Jt=st;for(const e of zt){t(Jt,e.direction);for(const r of At){const e=Wt[r];if(t(Dt,e),_t(Jt,Dt,Wt,Gt))return!1;const s=(r+1)%4;if(p){const r=Wt[s];if(n(Dt,r,e),t(Dt,Dt),_t(Jt,Dt,Wt,Gt))return!1}if(d){const e=Wt[4+r],o=Wt[4+s];if(n(Dt,o,e),t(Dt,Dt),_t(Jt,Dt,Wt,Gt))return!1}}}return!0}}function R(r,n,e){return u(r,n,e),t(r,r),r}function v(r,e,s){return n(r,e,s),t(r,r),r}function G(t,r){return f(t,t,r/a(t)),t}const j=[0,1,2,3,5];function B(t,r,n){for(let e=0;e<n;++e)if(F(t,r[e])<=0)return!1;return!0}function y(t,r,n){for(const e of j)if(B(t[e],r,n))return!0;return!1}function q(t,r,n=r.length){for(let e=0;e<n;++e){const n=r[e];let s=!0;for(const r of t){if(F(r,n)>0){s=!1;break}}if(s)return!0}return!1}const w=2,I=4;function V(t,r,n){for(const s of r)if(e(s,t)<n)return!1;return!0}const x=[h(),h(),h(),h(),h(),h(),h(),h()],C=[0,0,0,0,0,0],E=[h(),h(),h(),h(),h(),h()],k=h(),P=h(),T=h(),Y=h(),H=h(),L=h(),U=h(),A=h(),W=h(),z=h(),D=h(),J=m(0,0,0),K=h(),N=[h(),h(),h(),h(),h(),h(),h(),h()],O=[h(),h(),h(),h(),h()],Q=h(),X=h(),Z=h(),$=h(),tt=h(),rt=h(),nt=h(),et=h(),st=h(),ot=h(),it=[0,1,2,3],ut=[0,1,2,3],ct=[0,1,3],ft=[0,1,3],at=[1,2,3],ht=[1,2,3],lt=h();function mt(t,r,n){let s=1/0,o=-1/0;for(const i of n){const t=e(r,i);s=Math.min(s,t),o=Math.max(o,t)}t[0]=s,t[1]=o}function pt(t,r,n,s){let o=1/0,i=-1/0;for(const u of s){const s=e(n,u);if(o=Math.min(o,s),i=Math.max(i,s),o<=r&&i>=t)return!1}return!0}const dt=[0,0];function _t(t,r,n,e){const s=n.length,o=e.length;if(0===s||0===o)return!0;const i=ot;R(i,t,r);const u=o<s,c=u?n:e,f=dt;return mt(f,i,u?e:n),pt(f[0],f[1],i,c)}const gt=430,bt=h(),Ft=h(),Mt=Math.cos(.25*Math.PI),St=l(0,0,1),Rt=h();function vt(t,r,n){const e={t0:0,t1:1};for(const s of j){if(!jt(t[s],r,n,e))return!1}return e.t0<e.t1}function Gt(t,r,n){const e={t0:0,t1:1};for(const s of t){if(!jt(s,r,n,e))return!1}return e.t0<e.t1}function jt(t,r,n,e){let{t0:s,t1:o}=e;const i=F(t,r),u=F(t,n);if(i>=0&&u>=0)return!1;if(i<0&&u>=0){const t=-i/(u-i);if(t<s)return!1;t<o&&(o=t)}else if(i>=0&&u<0){const t=i/(i-u);if(t>o)return!1;t>s&&(s=t)}return e.t0=s,e.t1=o,!0}const Bt=[b(-1,0,0,1),b(1,0,0,-1),b(0,-1,0,1),b(0,1,0,-1),b(0,0,-1,1),b(0,0,1,-1)],yt=m(0,0,1);export{S as FeatureTileVisibility3D,q as isAnyVertexInPolyhedron,y as isConvexHullOutsideOfFrustum,I as maxLODLevelDelta,w as minTileLOD};
5
+ import{n as t,c as r,a as n,e,b as s,i as o,F as i,h as u,f as c,g as f,H as a}from"../../../../chunks/vec32.js";import{create as h,fromValues as l,freeze as m}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as p}from"../../../../geometry/ellipsoidUtils.js";import{getSphericalPCPF as d}from"../../../../geometry/spatialReferenceEllipsoidUtils.js";import{projectBuffer as _}from"../../../../geometry/projection/projectBuffer.js";import{projectVec3Array as g}from"../../../../geometry/projection/projectVec3Array.js";import{fromValues as b,signedDistance as F}from"../../../../geometry/support/plane.js";import{Frustum as M}from"../../state/Frustum.js";class S{constructor(t,r){this._renderCoordsHelper=t,this.opaqueGround=r,this._cache=new Map,this._cameraForward=h(),this._cameraEye=h(),this._cameraFovY=55*Math.PI/180,this._frustumBoundingSphereCenter=h(),this._frustumBoundingSphereRadius=0,this._frustum=new M(t),this._renderSR=t.spatialReference;const n=d(this._renderSR);this._renderSREllipsoidRadius=p(n).radius}setup(n){this._aboveGround=n.aboveGround,this._frustum.update(n),t(this._cameraForward,n.viewForward),r(this._cameraEye,n.eye),this._cameraFovY=n.fovY,this._updateFrustumBoundingSphere()}done(){this._cache.clear()}compute(t){if(this._cache.has(t.id))return this._cache.get(t.id);const r=this._isVisibleInFrustum(t);return this._cache.set(t.id,r),r}_isVisibleInFrustum(t){return 2===this._renderCoordsHelper.viewingMode?this._isTileVisibleInFrustumLocal(t):this._isTileVisibleInFrustumGlobal(t)}_updateFrustumBoundingSphere(){const r=this._frustum,o=r.origin,i=A;t(i,r.direction);const u=r.points,c=W;n(c,u[4],o);const f=.5*e(c,c)/e(i,c),a=this._frustumBoundingSphereCenter;s(a,o,i,f);const h=1+f;this._frustumBoundingSphereRadius=h}_isTileVisibleInFrustumLocal(t){const r=t.spatialReference,u=t.extent,c=this._renderSR;if(!u)return!0;if(C[0]=u[0],C[1]=u[1],C[2]=0,C[3]=u[2],C[4]=u[3],C[5]=0,!_(C,r,0,C,c,0))return!1;o(E[0],C[0],C[1],0),o(E[1],C[3],C[1],0),o(E[2],C[3],C[4],0),o(E[3],C[0],C[4],0),o(k,.5*(C[0]+C[3]),.5*(C[1]+C[4]),.5*(C[2]+C[5]));const f=St,a=.5*i(E[0],E[2]),h=this._frustum,l=this._frustumBoundingSphereRadius,m=this._frustumBoundingSphereCenter,p=D;n(p,m,k);const d=e(f,p),g=z;s(g,k,f,d);if(i(g,m)>a+l)return!1;const b=this._cameraForward,F=e(b,St),M=this._cameraFovY,S=this._cameraEye;if(Math.abs(F)<Math.abs(Math.cos(.5*M))){let t=!0;const r=o(Rt,b[0],b[1],0),n=e(S,r);for(let s=0;s<4;++s){const o=E[s];if(e(o,r)-n>0){t=!1;break}}if(t)return!1}{const t=E[0],r=E[2];if(t[0]<=S[0]&&S[0]<=r[0]&&t[1]<=S[1]&&S[1]<=r[1])return!0}const R=x,v=this.opaqueGround&&this._aboveGround,G=this.opaqueGround&&!this._aboveGround,j=Math.min(G?gt:1/0,d+l),B=Math.max(v?-gt:-1/0,d-l);for(let n=0;n<4;++n)s(R[n],E[n],f,j),s(R[n+4],E[n],f,B);if(y(h.planes,R,8))return!1;if(q(h.planes,R,8))return!0;for(let n=0;n<4;++n){const t=R[n],r=R[n+4];if(vt(h.planes,t,r))return!0;const e=R[(n+1)%4];if(vt(h.planes,t,e))return!0;const s=R[4+(n+1)%4];if(vt(h.planes,r,s))return!0}if(Bt[0][3]=+E[0][0],Bt[1][3]=-E[2][0],Bt[2][3]=+E[0][1],Bt[3][3]=-E[2][1],Bt[4][3]=+B,Bt[5][3]=-j,q(Bt,h.points))return!0;if(q(Bt,h.points))return!0;for(let n=0;n<4;++n){const t=S,r=h.points[n+4];if(Gt(Bt,t,r))return!0;const e=h.points[4+(n+1)%4];if(Gt(Bt,r,e))return!0}return!1}_isTileVisibleInFrustumGlobal(r){if(r.level<w)return!0;const l=r.spatialReference,m=r.extent;if(!m||!l)return!0;const p=this.opaqueGround&&this._aboveGround,d=this.opaqueGround&&!this._aboveGround,_=E,b=.5*(m[0]+m[2]);if(o(_[0],m[0],m[1],0),o(_[1],m[2],m[1],0),o(_[2],m[2],m[3],0),o(_[3],m[0],m[3],0),o(_[4],b,m[1],0),o(_[5],b,m[3],0),!g(_,l,0,_,this._renderSR,0,6))return!1;const M=_[0][2]>0,S=_[3][2]<0,j=M||S,B=this._renderSREllipsoidRadius;if(j){const t=T;R(t,yt,_[0]);const r=Y;if(R(r,yt,_[1]),M){const n=P,e=_[4],s=H;R(s,e,yt),R(n,s,e);const o=_[0];u(o,t,n),G(o,B);const i=_[1];u(i,r,n),G(i,B)}else if(S){const n=P,e=_[5],s=H;R(s,e,yt),R(n,e,s);const o=_[3];u(o,n,t),G(o,B);const i=_[2];u(i,n,r),G(i,B)}}const q=k,I=n(Q,_[3],_[0]);t(I,I);const x=c(X,_[0],_[3]);f(x,x,.5);const C=-e(x,I),A=c(Z,_[0],_[1]);f(A,A,.5);const W=c($,_[2],_[3]);f(W,W,.5);const z=n(tt,W,A);t(z,z);const D=-(C+e(I,A))/e(I,z);s(q,A,z,D),G(q,B);const ot=this._frustumBoundingSphereRadius,mt=this._frustumBoundingSphereCenter,pt=this._frustum,dt=pt.planes,St=L;t(St,q);const Rt=e(_[0],St)/a(_[0]),vt=pt.origin,Gt=pt.points;let jt=!1;if(p){{jt=!0;const r=t(bt,vt);for(let s=0;s<4;++s){const o=Gt[4+s],i=n(h(),o,vt);t(i,i);const c=u(h(),r,i);t(c,c);const f=u(h(),i,c);t(f,f);if(e(vt,f)>B){jt=!1;break}}}if(jt){if(e(vt,St)<B*Rt-gt)return!1}const r=t(bt,pt.origin);if(e(r,St)<0)return!1;{const r=t(Ft,pt.direction);if(e(r,St)>Mt)return!1}}const Bt=Math.sqrt(1-Rt*Rt);if(Bt>.9)return!0;let qt=!1;const wt=e(St,mt),It=a(mt);if(It<=ot&&!dt.some(t=>F(t,J)>0)){if(!p)return!0;qt=!0}const Vt=wt/It;if(!qt&&wt<=0){if(-wt>ot)return!1}const xt=ot/It;if(Math.sqrt(1-Vt*Vt)*Math.sqrt(1-xt*xt)-xt*Vt>Bt)return!1;if(!jt){if(_.some(t=>pt.intersectsPoint(t)))return!0;if(pt.intersectsPoint(q))return!0}const Ct=K;n(Ct,mt,J);const Et=e(Ct,St),kt=U;f(kt,St,Et);const Pt=i(kt,mt),Tt=l.isWGS84,Yt=r.lij,Ht=Tt&&Yt[2]===2**Yt[0]-1,Lt=Tt&&0===Yt[2],Ut=Lt?at:Ht?ct:it,At=Lt?ht:Ht?ft:ut;if(!qt){const t=_,r=lt,n=rt,e=nt,s=J;for(const o of Ut){const i=t[o];if(v(n,t[(o+1)%4],i),v(e,s,i),R(r,e,n),V(r,Gt,1))return!1}}let Wt=null;if(!p&&Et<1.01*ot){const t=2.5*ot;if(Pt>Rt*t+ot)return!1;const r=O,n=t/Rt;for(let e=0;e<4;++e)f(r[e],_[e],n/B);o(r[4],0,0,0),Wt=r}else{const t=(d?B+gt:Et+ot)/Rt,r=p?B-gt:(Et-ot)/Rt,n=N;for(let e=0;e<4;++e){const s=_[e];f(n[e],s,r/B),f(n[e+4],s,t/B)}Wt=n}if(y(dt,Wt,Wt.length))return!1;const zt=pt.lines,Dt=et,Jt=st;for(const e of zt){t(Jt,e.direction);for(const r of At){const e=Wt[r];if(t(Dt,e),_t(Jt,Dt,Wt,Gt))return!1;const s=(r+1)%4;if(p){const r=Wt[s];if(n(Dt,r,e),t(Dt,Dt),_t(Jt,Dt,Wt,Gt))return!1}if(d){const e=Wt[4+r],o=Wt[4+s];if(n(Dt,o,e),t(Dt,Dt),_t(Jt,Dt,Wt,Gt))return!1}}}return!0}}function R(r,n,e){return u(r,n,e),t(r,r),r}function v(r,e,s){return n(r,e,s),t(r,r),r}function G(t,r){return f(t,t,r/a(t)),t}const j=[0,1,2,3,5];function B(t,r,n){for(let e=0;e<n;++e)if(F(t,r[e])<=0)return!1;return!0}function y(t,r,n){for(const e of j)if(B(t[e],r,n))return!0;return!1}function q(t,r,n=r.length){for(let e=0;e<n;++e){const n=r[e];let s=!0;for(const r of t){if(F(r,n)>0){s=!1;break}}if(s)return!0}return!1}const w=2,I=4;function V(t,r,n){for(const s of r)if(e(s,t)<n)return!1;return!0}const x=[h(),h(),h(),h(),h(),h(),h(),h()],C=[0,0,0,0,0,0],E=[h(),h(),h(),h(),h(),h()],k=h(),P=h(),T=h(),Y=h(),H=h(),L=h(),U=h(),A=h(),W=h(),z=h(),D=h(),J=m(0,0,0),K=h(),N=[h(),h(),h(),h(),h(),h(),h(),h()],O=[h(),h(),h(),h(),h()],Q=h(),X=h(),Z=h(),$=h(),tt=h(),rt=h(),nt=h(),et=h(),st=h(),ot=h(),it=[0,1,2,3],ut=[0,1,2,3],ct=[0,1,3],ft=[0,1,3],at=[1,2,3],ht=[1,2,3],lt=h();function mt(t,r,n){let s=1/0,o=-1/0;for(const i of n){const t=e(r,i);s=Math.min(s,t),o=Math.max(o,t)}t[0]=s,t[1]=o}function pt(t,r,n,s){let o=1/0,i=-1/0;for(const u of s){const s=e(n,u);if(o=Math.min(o,s),i=Math.max(i,s),o<=r&&i>=t)return!1}return!0}const dt=[0,0];function _t(t,r,n,e){const s=n.length,o=e.length;if(0===s||0===o)return!0;const i=ot;R(i,t,r);const u=o<s,c=u?n:e,f=dt;return mt(f,i,u?e:n),pt(f[0],f[1],i,c)}const gt=430,bt=h(),Ft=h(),Mt=Math.cos(.25*Math.PI),St=l(0,0,1),Rt=h();function vt(t,r,n){const e={t0:0,t1:1};for(const s of j){if(!jt(t[s],r,n,e))return!1}return e.t0<e.t1}function Gt(t,r,n){const e={t0:0,t1:1};for(const s of t){if(!jt(s,r,n,e))return!1}return e.t0<e.t1}function jt(t,r,n,e){let{t0:s,t1:o}=e;const i=F(t,r),u=F(t,n);if(i>=0&&u>=0)return!1;if(i<0&&u>=0){const t=-i/(u-i);if(t<s)return!1;t<o&&(o=t)}else if(i>=0&&u<0){const t=i/(i-u);if(t>o)return!1;t>s&&(s=t)}return e.t0=s,e.t1=o,!0}const Bt=[b(-1,0,0,1),b(1,0,0,-1),b(0,-1,0,1),b(0,1,0,-1),b(0,0,-1,1),b(0,0,1,-1)],yt=m(0,0,1);export{S as FeatureTileVisibility3D,q as isAnyVertexInPolyhedron,y as isConvexHullOutsideOfFrustum,I as maxLODLevelDelta,w as minTileLOD};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../../../Graphic.js";import{Tiles3DTarget as i}from"../i3s/Intersector.js";import{IntersectorResult as t}from"../../webgl-engine/lib/IntersectorResult.js";import{MeshIntersectionOptions as r}from"../../webgl-engine/lib/RayIntersections.js";class s{constructor(e){this.type=8,this.slicePlaneEnabled=!1,this.isGround=!0,this.layerView=e,this.layerViewUid=e.uid}intersect(e,s,n,l,o,a){if(e.options.filteredLayerViewUids.includes(this.layerView.uid))return;const c=e.results,u=2===e.options.store,d=this.layerView.view.stage.renderView.componentObjectCollection,h=new r(a,e.options.normalRequired);this.layerView.objects.forEach(r=>{r.visible&&r.intersectionGeometry&&d.intersect(r,n,l,e.tolerance,null,h,(r,o,a,d)=>{if(o>=0){if(null!=s&&!s(n,l,o))return;const r=e=>{const t=new i(this.layerView.layer.uid,()=>this._createTiles3DGraphic(this.layerView.layer,{}));e.set(this.type,t,o,a)};if(this.isGround&&(null==c.ground.distance||o<c.ground.distance)&&r(c.ground),e.options.isFiltered)return;if((null==c.min.distance||o<c.min.distance)&&r(c.min),(null==c.max.distance||o>c.max.distance)&&r(c.max),u){const i=new t(e.ray);r(i),e.results.all.push(i)}}})})}_createTiles3DGraphic(i,t){return new e({layer:i,sourceLayer:i,attributes:t})}}export{s as Tiles3DIntersectionHandler};
5
+ import e from"../../../../Graphic.js";import i from"../../../../graphic/IntegratedMesh3DTilesGraphicOrigin.js";import{Tiles3DTarget as r}from"../i3s/Intersector.js";import{IntersectorResult as t}from"../../webgl-engine/lib/IntersectorResult.js";import{MeshIntersectionOptions as s}from"../../webgl-engine/lib/RayIntersections.js";class n{constructor(e){this.type=8,this.slicePlaneEnabled=!1,this.isGround=!0,this.layerView=e,this.layerViewUid=e.uid,this._graphicOrigin=new i(this.layerView.layer)}intersect(e,i,n,l,o,a){if(e.options.filteredLayerViewUids.includes(this.layerView.uid))return;const c=e.results,h=2===e.options.store,u=this.layerView.view.stage.renderView.componentObjectCollection,d=new s(a,e.options.normalRequired);this.layerView.objects.forEach(s=>{s.visible&&s.intersectionGeometry&&u.intersect(s,n,l,e.tolerance,null,d,(s,o,a,u)=>{if(o>=0){if(null!=i&&!i(n,l,o))return;const s=e=>{const i=new r(this.layerView.layer.uid,()=>this._createTiles3DGraphic(this.layerView.layer,{}));e.set(this.type,i,o,a)};if(this.isGround&&(null==c.ground.distance||o<c.ground.distance)&&s(c.ground),e.options.isFiltered)return;if((null==c.min.distance||o<c.min.distance)&&s(c.min),(null==c.max.distance||o>c.max.distance)&&s(c.max),h){const i=new t(e.ray);s(i),e.results.all.push(i)}}})})}_createTiles3DGraphic(i,r){return new e({layer:i,sourceLayer:i,origin:this._graphicOrigin,attributes:r})}}export{n as Tiles3DIntersectionHandler};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as t}from"tslib";import i from"../../../core/Accessor.js";import{deg2rad as e,rad2deg as a}from"../../../core/mathUtils.js";import{watch as s,sync as n,initial as r}from"../../../core/reactiveUtils.js";import{property as o}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as c}from"../../../core/accessorSupport/decorators/subclass.js";import{applyAll as l}from"../camera/constraintUtils.js";import{surfaceElevationBelowRenderLocation as u}from"../camera/intersectionUtils.js";import{ConstraintOptions as h}from"../camera/constraintUtils/ConstraintOptions.js";import{createNearFarHeuristic as p}from"./NearFarHeuristic.js";import{SurfaceCollisionConstraint as d}from"./SurfaceCollisionConstraint.js";let m=class extends i{constructor(t){super(t),this.nearFarHeuristic=p(t.view.state.viewingMode,t.view.basemapTerrain,t.view.renderCoordsHelper.spatialReference)}initialize(){this.addHandles([s(()=>[this.view.constraints?.clipDistance?.near,this.view.constraints?.clipDistance?.far],()=>this._clipDistanceNearFarChanged()),s(()=>this.view.constraints?.clipDistance?.mode,()=>this._updateNearFar()),this.view.state.events.on("before-camera-change",({camera:t,sceneDepthRange:i})=>this._updateCameraNearFar(t,i)),s(()=>this.view.stage.renderer.sceneDepthRange.value,()=>this._updateNearFar(),n),s(()=>this.view.renderDataExtent,()=>this._updateNearFar(),n),s(()=>[this.view.constraints?.altitude?.min,this.view.constraints?.altitude?.max],()=>this._updateAltitude(),n),s(()=>this.view.constraints?.tilt?.max,()=>this._updateTiltMax(),n),s(()=>this.view.constraints?.tilt?.mode,()=>this._updateTilt(),n),s(()=>this.view.state?.camera,()=>this._updateTiltAutoMax(),n),s(()=>[this.view.map?.ground?.navigationConstraint?.type,this.view.state?.constraints?.collision?.enabled],()=>this._updateCollision(),n)]),this.view.state.isLocal&&this.addHandles(s(()=>this.view.renderDataExtent,t=>this._updateLocalSurfaceDistance(t),r)),this._updateNearFar(),2!==this.view.state.viewingMode&&this._updateAltitude(),this._updateTilt(),this._updateCollision(),this._set("surfaceCollisionConstraint",new d({view:this.view}))}destroy(){this.surfaceCollisionConstraint&&(this.surfaceCollisionConstraint.destroy(),this._set("surfaceCollisionConstraint",null))}_clipDistanceNearFarChanged(){const t=this.view.constraints?.clipDistance;t&&"auto"!==t.mode&&this.view.state.updateCamera(i=>v(i,t))}_updateNearFar(){this.view.state.updateCamera(t=>this._updateCameraNearFar(t))}_updateCameraNearFar(t,i){const e=this.view.constraints&&this.view.constraints.clipDistance;"manual"===(e?e.mode:"auto")?v(t,e):this._updateCameraNearFarAuto(t,e,i)}_updateCameraNearFarAuto(t,i,e){const a=u(this.view,t.eye),s=this.nearFarHeuristic.compute(t,this.view.renderDataExtent,e??this.view.stage.renderer.sceneDepthRange.value,a);t.near=s.near,t.far=s.far,i&&i.autoUpdate(t.near,t.far)}_updateCollision(){const t=this.view.map?.ground?.navigationConstraint?.type,i=!t||"stay-above"===t,e=this.view.state.constraints.collision;if(i!==e.enabled){e.enabled=i,i&&this._reapplyConstraints(8);const t=this.view.constraints&&this.view.constraints.tilt;t&&"auto"!==t.mode||this._updateTiltAuto()}}_updateAltitude(){const t=this.view.constraints&&this.view.constraints.altitude;t&&2!==this.view.state.viewingMode?this.view.state.constraints.altitude={min:t.min,max:t.max}:this.view.state.constraints.altitude=null,this._reapplyConstraints()}_updateTiltMax(){const t=this.view.constraints&&this.view.constraints.tilt;t&&"auto"!==t.mode&&(this._updateTiltManual(t),this._reapplyConstraints())}_updateTilt(){const t=this.view.constraints&&this.view.constraints.tilt;"manual"===(t?t.mode:"auto")?this._updateTiltManual(t):this._updateTiltAuto(),this._reapplyConstraints()}_updateTiltManual(t){const i=this.view.state.constraints;i.tilt=i.createConstantMaxTilt(e(t.max))}_updateTiltAuto(){const t=this.view.state.constraints;t.tilt=t.createDefaultTilt(),this._updateTiltAutoMax()}_updateTiltAutoMax(){const t=this.view.constraints&&this.view.constraints.tilt;if(!t||"auto"!==t.mode)return;const i=this.view.state.constraints;if(i.tilt){const e=i.tilt(this.view.state.camera.distance).max;t.autoUpdate(a(e))}}_updateLocalSurfaceDistance(t){if(null==t)return;let i=Math.max(t.width,t.height);if(i<=0)return;null!=t.zmax&&null!=t.zmin&&(i=Math.max(i,t.zmax-t.zmin));const e=this.view.state,a=3*i/Math.atan(e.camera.fov/2);a!==e.constraints.distance&&(e.constraints.distance=a)}_reapplyConstraints(t=15){this.view.state.updateCamera(i=>l(this.view,i,new h(t,0,null)))}};function v(t,i){i&&(t.near=i.near,t.far=i.far)}t([o({constructOnly:!0})],m.prototype,"view",void 0),t([o({readOnly:!0})],m.prototype,"surfaceCollisionConstraint",void 0),m=t([c("esri.views.3d.state.ConstraintsManager")],m);export{m as ConstraintsManager};
5
+ import{__decorate as t}from"tslib";import i from"../../../core/Accessor.js";import{deg2rad as e,rad2deg as a}from"../../../core/mathUtils.js";import{watch as s,sync as n,initial as r}from"../../../core/reactiveUtils.js";import{property as o}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as c}from"../../../core/accessorSupport/decorators/subclass.js";import{applyAll as l}from"../camera/constraintUtils.js";import{surfaceElevationBelowRenderLocation as u}from"../camera/intersectionUtils.js";import{ConstraintOptions as h}from"../camera/constraintUtils/ConstraintOptions.js";import{createNearFarHeuristic as p}from"./NearFarHeuristic.js";import{SurfaceCollisionConstraint as d}from"./SurfaceCollisionConstraint.js";let m=class extends i{constructor(t){super(t),this.nearFarHeuristic=p(t.view.state.viewingMode,t.view.basemapTerrain,t.view.renderCoordsHelper.spatialReference)}initialize(){this.addHandles([s(()=>[this.view.constraints?.clipDistance?.near,this.view.constraints?.clipDistance?.far],()=>this._clipDistanceNearFarChanged()),s(()=>this.view.constraints?.clipDistance?.mode,()=>this._updateNearFar()),this.view.state.events.on("before-camera-change",({camera:t,sceneDepthRange:i})=>this._updateCameraNearFar(t,i)),s(()=>this.view.stage.renderer.sceneDepthRange.value,()=>this._updateNearFar(),n),s(()=>this.view.renderDataExtent,()=>this._updateNearFar(),n),s(()=>[this.view.constraints?.altitude?.min,this.view.constraints?.altitude?.max],()=>this._updateAltitude(),n),s(()=>this.view.constraints?.tilt?.max,()=>this._updateTiltMax(),n),s(()=>this.view.constraints?.tilt?.mode,()=>this._updateTilt(),n),s(()=>this.view.state?.camera,()=>this._updateTiltAutoMax(),n),s(()=>[this.view.map?.ground?.navigationConstraint?.type,this.view.state?.constraints?.collision?.enabled],()=>this._updateCollision(),n)]),this.view.state.isLocal&&this.addHandles(s(()=>this.view.renderDataExtent,t=>this._updateLocalSurfaceDistance(t),r)),this._updateNearFar(),2!==this.view.state.viewingMode&&this._updateAltitude(),this._updateTilt(),this._updateCollision(),this._set("surfaceCollisionConstraint",new d({view:this.view}))}destroy(){this.surfaceCollisionConstraint&&(this.surfaceCollisionConstraint.destroy(),this._set("surfaceCollisionConstraint",null))}_clipDistanceNearFarChanged(){const t=this.view.constraints?.clipDistance;t&&"auto"!==t.mode&&this.view.state.updateCamera(i=>v(i,t))}_updateNearFar(){this.view.state.updateCamera(t=>this._updateCameraNearFar(t))}_updateCameraNearFar(t,i){const e=this.view.constraints?.clipDistance;"manual"===(e?e.mode:"auto")?v(t,e):this._updateCameraNearFarAuto(t,e,i)}_updateCameraNearFarAuto(t,i,e){const a=u(this.view,t.eye),s=this.nearFarHeuristic.compute(t,this.view.renderDataExtent,e??this.view.stage.renderer.sceneDepthRange.value,a);t.near=s.near,t.far=s.far,i&&i.autoUpdate(t.near,t.far)}_updateCollision(){const t=this.view.map?.ground?.navigationConstraint?.type,i=!t||"stay-above"===t,e=this.view.state.constraints.collision;if(i!==e.enabled){e.enabled=i,i&&this._reapplyConstraints(8);const t=this.view.constraints&&this.view.constraints.tilt;t&&"auto"!==t.mode||this._updateTiltAuto()}}_updateAltitude(){const t=this.view.constraints&&this.view.constraints.altitude;t&&2!==this.view.state.viewingMode?this.view.state.constraints.altitude={min:t.min,max:t.max}:this.view.state.constraints.altitude=null,this._reapplyConstraints()}_updateTiltMax(){const t=this.view.constraints&&this.view.constraints.tilt;t&&"auto"!==t.mode&&(this._updateTiltManual(t),this._reapplyConstraints())}_updateTilt(){const t=this.view.constraints&&this.view.constraints.tilt;"manual"===(t?t.mode:"auto")?this._updateTiltManual(t):this._updateTiltAuto(),this._reapplyConstraints()}_updateTiltManual(t){const i=this.view.state.constraints;i.tilt=i.createConstantMaxTilt(e(t.max))}_updateTiltAuto(){const t=this.view.state.constraints;t.tilt=t.createDefaultTilt(),this._updateTiltAutoMax()}_updateTiltAutoMax(){const t=this.view.constraints&&this.view.constraints.tilt;if(!t||"auto"!==t.mode)return;const i=this.view.state.constraints;if(i.tilt){const e=i.tilt(this.view.state.camera.distance).max;t.autoUpdate(a(e))}}_updateLocalSurfaceDistance(t){if(null==t)return;let i=Math.max(t.width,t.height);if(i<=0)return;null!=t.zmax&&null!=t.zmin&&(i=Math.max(i,t.zmax-t.zmin));const e=this.view.state,a=3*i/Math.atan(e.camera.fov/2);a!==e.constraints.distance&&(e.constraints.distance=a)}_reapplyConstraints(t=15){this.view.state.updateCamera(i=>l(this.view,i,new h(t,0,null)))}};function v(t,i){i&&(t.near=i.near,t.far=i.far)}t([o({constructOnly:!0})],m.prototype,"view",void 0),t([o({readOnly:!0})],m.prototype,"surfaceCollisionConstraint",void 0),m=t([c("esri.views.3d.state.ConstraintsManager")],m);export{m as ConstraintsManager};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import t from"../../../../Color.js";import{fromValues as o}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{newHalfFloatArray as e}from"../../../../geometry/support/HalfFloatArray.js";import{zValueInAbsoluteHeightMode as n}from"../../../../support/elevationInfoUtils.js";import{lineStripsToParameters as r,createGeometry as i}from"../engineContent/line.js";function l(t,l,s,c,h,m){const{spatialReference:p}=t,g=[];for(let e=0;e<s.length;e+=3){const r=[s[e],s[e+1]],[i,a]=f(r,l),{absoluteZ:h}=n(i,a,0,p,t,c),m=o(i,a,h);t.renderCoordsHelper.toRenderCoords(m,p,m),g.push(m)}const u=Math.floor(s.length/3),d=e(u);for(let o=0;o<u;o++)d[o]=s[3*o+2];a(d,Math.floor(m.getIntRange(0,d.length)));const j=r([g],void 0,[d]);return i(h,j[0])}function s(o){return null==o?{}:{color:t.toUnitRGBA(o.color),width:o.trailWidth,cap:2,animationSpeed:o.flowSpeed,trailLength:o.trailLength,animation:3}}function f([t,o],e){const{extent:n,size:[r,i]}=e;return[t/r*n.width+n.xmin,(i-o)/i*n.height+n.ymin]}function a(t,o){if(0===t.length||o<0||o>=t.length)return;const e=t[o];for(let n=0;n<t.length;n++)t[n]-=e}export{l as createStreamlineGeometry,s as materialParametersFromRenderer};
5
+ import t from"../../../../Color.js";import{fromValues as o}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{newHalfFloatArray as e}from"../../../../geometry/support/HalfFloatArray.js";import{zValueInAbsoluteHeightMode as n}from"../../../../support/elevationInfoUtils.js";import{lineStripsToParameters as r,createGeometry as i}from"../engineContent/line.js";function l(t,l,s,c,h,m){const{spatialReference:p}=t,g=[];for(let e=0;e<s.length;e+=3){const r=[s[e],s[e+1]],[i,a]=f(r,l),{absoluteZ:h}=n(i,a,0,p,t,c),m=o(i,a,h);t.renderCoordsHelper.toRenderCoords(m,p,m),g.push(m)}const u=Math.floor(s.length/3),d=e(u);for(let o=0;o<u;o++)d[o]=s[3*o+2];a(d,Math.floor(m.getIntRange(0,d.length)));const j=r([g],void 0,[d]);return i(h,j[0])}function s(o,e){return null==o?{}:{color:t.toUnitRGBA(o.color),width:o.trailWidth,cap:2,animationSpeed:o.flowSpeed,trailLength:o.trailLength,animation:3,emissiveStrength:e}}function f([t,o],e){const{extent:n,size:[r,i]}=e;return[t/r*n.width+n.xmin,(i-o)/i*n.height+n.ymin]}function a(t,o){if(0===t.length||o<0||o>=t.length)return;const e=t[o];for(let n=0;n<t.length;n++)t[n]-=e}export{l as createStreamlineGeometry,s as materialParametersFromRenderer};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import{Cyclical as r,cyclicalPI as s}from"../../../core/Cyclical.js";import"../../../core/has.js";import{clamp as i,deg2rad as n}from"../../../core/mathUtils.js";import{destroyMaybe as a}from"../../../core/maybe.js";import{watch as o,sync as l}from"../../../core/reactiveUtils.js";import{property as h}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as c}from"../../../core/accessorSupport/decorators/subclass.js";import{subtract as d}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{f as u,d as p,c as m,j as g}from"../../../chunks/vec32.js";import{create as _}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{t as y,d as f,g as v}from"../../../chunks/vec42.js";import{fromValues as x,create as w}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{getReferenceEllipsoid as R}from"../../../geometry/ellipsoidUtils.js";import{projectVectorToVector as S}from"../../../geometry/projection/projectVectorToVector.js";import{create as O,width as P,copy as D,center as T,height as M,intersection as j,contains as b,intersects as I,offset as C}from"../../../geometry/support/aaBoundingRect.js";import{create as U,wrap as E}from"../../../geometry/support/ray.js";import{e as A,b as q,t as V}from"../../../chunks/sphere.js";import{angleAroundAxis as F}from"../../../geometry/support/vector.js";import{y2lat as G}from"../../../geometry/support/webMercatorUtils.js";import{viewAngle as H}from"../state/utils/viewUtils.js";import{debugFlags as L}from"../support/debugFlags.js";import{DebugPoint as z}from"../support/debugUtils.js";import{OverlayRenderer as k}from"./OverlayRenderer.js";import{Intersector as B}from"../webgl-engine/lib/Intersector.js";import{fromValues as W}from"../webgl-engine/lib/LocalOriginFactory.js";import{SortedRenderGeometryRenderer as Y}from"../webgl-engine/lib/SortedRenderGeometryRenderer.js";import{applyTextureResizeModulo as N,ensureTextureSize as X}from"../webgl-engine/lib/textureUtils.js";import{removeLoadedShaderModules as Z}from"../webgl-engine/parts/renderUtils.js";import{TaskPriority as J,noBudget as K}from"../../support/Scheduler.js";import{Yield as Q}from"../../support/Yield.js";const $=1.3,ee=[[-.1,-2,3.9,2],[-.1,-3.9,3.9,.1],[-2,-3.9,2,.1],[-3.9,-3.9,.1,.1],[-3.9,-2,.1,2],[-3.9,-.1,.1,3.9],[-2,-.1,2,3.9],[-.1,-.1,3.9,3.9]];let te,re=class extends t{constructor(e){super(e),this._renderSR=null,this._overlaySREqualsRenderSR=!0,this._drapeSources=new Set,this._drapeTargets=new Set,this._placementDirty=!1,this._contentUpdated=!1,this._drawTexturesDirty=!1,this._drawTexturesAnimateDirty=!1,this._latestOriginId=0}initialize(){const e=this.view;this.renderer=new k({parent:this}),e.stage.renderer.plugins.add(this.renderer);const t=()=>this.requestRender();this._groundIntersector=new B(this.view.state.viewingMode),this._groundIntersector.options.backfacesTerrain=!0,this._groundIntersector.options.invisibleTerrain=!0,this._groundIntersector.options.hud=!1,this.addHandles([o(()=>this.renderer.hasHighlights,t),this.renderer.events.on("has-water",()=>e.stage?.renderer.updateHasFlags()),this.renderer.events.on("content-changed",t),o(()=>e.state.camera.pixelRatio,t),o(()=>e.state.alignPixelEnabled,t),this.renderer.events.on("textures-disposed",()=>this.surface.requestRender()),o(()=>[e.pointsOfInterest?.renderPointOfView,e.pointsOfInterest?.centerOnSurfaceFrequent?.location],()=>this.setPlacementDirty()),o(()=>[e.state?.pixelRatio,e.state?.contentPixelRatio],()=>this.setPlacementDirty(),l),this.surface.on("elevation-change",()=>this.setPlacementDirty()),e.on("resize",()=>this.setPlacementDirty()),e.resourceController.scheduler.registerTask(J.OVERLAY,this)]),e.stage.renderer.overlay=this}destroy(){this.view?.stage&&(this.view.stage.renderer.plugins.remove(this.renderer),this.view.stage.renderer.overlay=null),te&&(te.hide(),te=null),this.renderer=a(this.renderer)}get spatialReference(){return this._spatialReference}set spatialReference(e){this._spatialReference=e,this.renderer.longitudeCyclical=null;const t=this.view.renderSpatialReference;null!=e&&null!=t?(this._renderSR=t,this._overlaySREqualsRenderSR=e.equals(this._renderSR),this._isSpherical&&(this.renderer.longitudeCyclical=e.isWebMercator?new r(-20037508.342787,20037508.342787):new r(-180,180))):this.renderer.disposeOverlays()}get running(){return this._placementDirty&&(this._drapeSources.size>0||this.view.graphics.length>0||L.OVERLAY_DRAW_DEBUG_TEXTURE)&&!!this._spatialReference&&!this.suspended&&this.surface.ready}get _isSpherical(){return this.view.state.isGlobal}get worldToPCSRatio(){return null!=this._spatialReference&&this._spatialReference.isGeographic&&!this.view.state.isLocal?R(this._spatialReference).metersPerDegree:1}get _overlayStretch(){return $/this.view.resolutionScale}get _longitudeCyclical(){return this.renderer.longitudeCyclical}get suspended(){return this.surface.suspended}get updating(){return this.running||this.renderer.updating||this._contentUpdated}render(){return this._contentUpdated=!1,this.renderer.processSyncDrapeSources(),this.renderer.precompileShaders(this.view.state)?this._drawOverlays():null}get hasOverlays(){return this.renderer.hasOverlays}registerDrapeSource(e,t){this._drapeSources.add(e),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources),this.renderer.registerDrapeSource(e,t),this._updateDrapeSourceExtent(e),this._setContentDirty(),this.notifyChange("running")}registerGeometryDrapeSource(e){const t=new Y({stage:this.view.stage,drapeSource:e,rendererContext:this.renderer});return this.registerDrapeSource(e,t),t}_updateDrapeSourceExtent(e){2===this.renderer.overlays.length&&null!=e.setDrapingExtent&&null!=this._spatialReference&&e.setDrapingExtent(this.renderer.overlays,this._spatialReference)}unregisterDrapeSource(e){this._drapeSources.has(e)&&(this._drapeSources.delete(e),this.renderer.removeDrapeSourceRenderer(e),this.renderer.ensureDrapeSources(this._drapeSources),this._setContentDirty(),this.notifyChange("running"))}registerDrapeTarget(e){this._drapeTargets.add(e),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources)}unregisterDrapeTarget(e){this._drapeTargets.delete(e),this.renderer.ensureDrapeTargets(this._drapeTargets)}_setContentDirty(){this.setPlacementDirty(),this.requestRender()}setPlacementDirty(){this._placementDirty=!0}runTask(e){return this.updateOverlays(e,this.view.state.contentCamera,1)}updateOverlays(e,t,r){if(!this._spatialReference)return Q;const s=this._computeOverlayHeight(t);this._computeOverlayExtents(t,s,oe),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources,oe.stretch);const i=this._updateOverlay(0,oe.inner,s,1*oe.pixelRatioAdjustment,oe.mapUnitsPerPixel),n=P(oe.inner)/P(oe.outer),a=this._updateOverlay(1,oe.outer,s,n*oe.pixelRatioAdjustment,oe.mapUnitsPerPixel);1!==i&&1!==a||(this._drapeSources.forEach(e=>this._updateDrapeSourceExtent(e)),this.updateOverlayParameters(r)),0===i&&0===a||this.requestRender(),this._placementDirty=!1,e.madeProgress()}_computeOverlayHeight(e){const t=this.view.state.contentPixelRatio*this.view.resolutionScale,r=e.fullWidth/e.pixelRatio*t,s=e.fullHeight/e.pixelRatio*t,i=Math.ceil(1.5*Math.max(r,s)),{maxPreferredTexturePixels:n,maxTextureSize:a}=this.view.stage.renderView.renderingContext.parameters,o=.5*a;return N(X({width:i,height:i},{maxPreferredTexturePixels:2*n,maxTextureSize:o})[1],o)}_updateOverlay(e,t,r,s,i){if(0===this.renderer.overlays.length)return 0;const n=this.renderer.overlays[e],a=n.mapUnitsPerPixel;if(n.mapUnitsPerPixel=i,n.pixelRatio=s,se(t,n.extent)&&r===n.resolution)return a===i?0:2;D(n.extent,t),n.resolution=r;const o=T(n.extent);return n.renderLocalOrigin=W(o[0],o[1],0,"OV_"+this._latestOriginId++),1}updateOverlayParameters(e){this.surface.allTiles.forAll(e=>this.updateTileOverlayParameters(e)),this.surface.requestRender(e)}updateTileOverlayParameters(e){if(!e.renderData)return;const t=e.renderData.overlay;if(0===this.renderer.overlays.length)this._clearTileOverlayData(0,t),this._clearTileOverlayData(1,t);else{const[r,s]=this.renderer.overlays,i=e.extent;this._rectInsideRect(r.extent,i)||this._rectanglesOverlap(i,r.extent)||this._rectanglesOverlap(i,s.extent)?(this._setTileOverlayData(i,0,t),this._setTileOverlayData(i,1,t)):(this._clearTileOverlayData(0,t),this._clearTileOverlayData(1,t))}}overlayPixelSizeInMapUnits(e,t){if(0===this.renderer.overlays.length)return t();const r=this.renderer.overlays[0],s=this.renderer.overlays[1],i=this._pointIsInExtent(e,r.extent)?r:s;return(i.extent[2]-i.extent[0])/i.resolution}_setTileOverlayData(e,t,r){if(0===this.renderer.overlays.length)return;const s=this.renderer.overlays[t].extent,i=P(s),n=M(s);let a=e[0];if(this._longitudeCyclical){a=this._longitudeCyclical.minimalMonotonic(s[0],a);const t=this._longitudeCyclical.minimalMonotonic(s[0],e[2]);a>t&&(a=t-(e[2]-e[0]))}r.setScale(t,P(e)/i,M(e)/n),r.setOffset(t,(a-s[0])/i,(e[1]-s[1])/n)}_clearTileOverlayData(e,t){t.setScale(e,-1,-1),t.setOffset(e,-1,-1)}reloadShaders(){Z(),this.requestRender(),this.runTask(K)}requestRender(e=1){this.renderer.hasOverlays?(1===e?(this._contentUpdated=!0,this._drawTexturesDirty=!0):this._drawTexturesAnimateDirty=!0,this.view.stage.renderView.requestRender(e)):this.setPlacementDirty()}_intersectGroundFromView(e,t,r,s,i){const n=this.view.sceneIntersectionHelper.getCenterRayWithSubpixelOffset(e,ce,t,r);if(null==n)return!1;const a=n.origin,o=u(ae,n.origin,n.direction);this._groundIntersector.reset(a,o,e),this._groundIntersector.intersect([]),this.view.basemapTerrain.intersect(this._groundIntersector,null,a,o);const l=this._groundIntersector.results.min;return l.getIntersectionPoint(i)&&l.withinDistance(s)}_findHorizonBasedPointOfInterest(e,t){let r=.5;const n=.55,a=this.view.renderCoordsHelper.getAltitude(e.eye),o=this.view.pointsOfInterest.centerOnSurfaceFrequent,l=1e-5,h=i(o.estimatedSurfaceAltitude,e.aboveGround?-1/0:a+l,e.aboveGround?a-l:1/0),c=e.aboveGround;if("global"===this.view.viewingMode){const t=ae;A(q(V,R(this.view.spatialReference).radius+h),E(e.eye,e.viewForward),t),p(t,t,e.eye);const i=s.normalize(F(e.viewForward,t,e.viewRight))/e.fovY+.5,a=i<=0||i>=1?.5:n;r=c?a*i:i+a*(1-i)}else{const t=.5*Math.PI-Math.acos(-e.viewForward[2]),s=Math.tan(t),a=x(0,s,1,0),o=y(a,a,e.projectionMatrix)[1],l=i(.5+.5*o,0,1);r=1===l||0===l?.5:c?l*n:1-(1-l)*n}return this._intersectGroundFromView(e,.5,r,o.distance,t)}_computeOverlayExtents(e,t,r){const s=this.view.pointsOfInterest.centerOnSurfaceFrequent.renderLocation,i=_();this._findHorizonBasedPointOfInterest(e,i)||m(i,s),L.OVERLAY_SHOW_CENTER?(null==te&&(te=new z(this.view.graphics,"red")),te.show(i,this._renderSR)):null!=te&&te.hide();const a=Math.max(.1,g(e.eye,i)),o=H(this.view.renderCoordsHelper,s,e.eye);this._overlaySREqualsRenderSR||S(i,this._renderSR,i,this._spatialReference);const l=this.surface.extent,h=!this._isSpherical&&this._spatialReference?.isGeographic,c=h&&this._spatialReference?1/R(this._spatialReference).metersPerDegree:1,u=this.view.state.contentPixelRatio,p=e.perScreenPixelRatio/u*a*c;r.mapUnitsPerPixel=p/this.worldToPCSRatio,r.stretch=this._overlayStretch;let y=t*p/2*r.stretch,x=!1,w=h?90:1/0;this._isSpherical&&l&&this._spatialReference&&(this._spatialReference.isWebMercator?(y/=Math.cos(G(i[1])),w=l[3]):(x=!0,y/=R(this._spatialReference).metersPerDegree,w=90),y>=w&&(y=w,i[1]=0,this._spatialReference.isWebMercator&&(i[0]=0)));let O=1;x&&(O=1/Math.max(.2,Math.cos(Math.abs(n(i[1])))),y*O>180&&(O=180/y),r.mapUnitsPerPixel*=O);const T=Math.log(2)/12;y=Math.exp(Math.round(Math.log(y)/T)*T);const M=y*O,I=32,C=.5*t/(I*M),U=.5*t/(I*y);i[0]=Math.round(i[0]*C)/C,i[1]=Math.round(i[1]*U)/U;const E=r.inner;E[0]=i[0]-M,E[1]=i[1]-y,E[2]=i[0]+M,E[3]=i[1]+y,this._isSpherical&&this._shiftExtentToFitBounds(E,1/0,w);const A=r.outer;if(6*M>P(l))D(A,l);else{if(Math.PI/2-Math.abs(o-Math.PI/2)<=.25*Math.PI)A[0]=E[0]-M,A[1]=E[1]-y,A[2]=E[2]+M,A[3]=E[3]+y;else{S(e.eye,this._renderSR,ae,this._spatialReference),d(ne,i,ae);let t=-Math.atan2(ne[1],ne[0])+.125*Math.PI;t<0&&(t+=2*Math.PI);const r=Math.floor(t/(.25*Math.PI));f(ne,ee[r],2*y),ne[0]*=O,ne[2]*=O,v(A,E,ne)}}if(this._isSpherical)A[0]=this._longitudeCyclical.clamp(A[0]),A[2]=this._longitudeCyclical.clamp(A[2]),A[1]=Math.max(A[1],-w),A[3]=Math.min(A[3],w);else{const e=j(E,l,le),t=j(A,l,he);b(e,t)&&(A[2]=A[0],A[3]=A[1])}const q=Math.abs(E[2]-E[0])/t;r.mapUnitsPerPixel=Math.max(r.mapUnitsPerPixel,q),r.pixelRatioAdjustment=r.mapUnitsPerPixel/q}_drawOverlays(e=this.view.state){if(!this._drawTexturesDirty&&!this._drawTexturesAnimateDirty)return this.renderer;const t=!this._drawTexturesDirty&&this._drawTexturesAnimateDirty?0:1;this._drawTexturesDirty=this._drawTexturesAnimateDirty=!1;const r=this.renderer.computeValidity();this.renderer.releaseRenderTargets(t),this.renderer.drawOverlays(e,t);return r!==this.renderer.computeValidity()&&this.updateOverlayParameters(1),this.surface.requestRender(t),1===t&&this.surface.requestUpdate(),this.renderer}_rectanglesOverlap(e,t){return null!=e&&(this._longitudeCyclical?(this._longitudeCyclical.contains(t[0],t[2],e[0])||this._longitudeCyclical.contains(t[0],t[2],e[2])||this._longitudeCyclical.contains(e[0],e[2],t[0]))&&!(e[1]>t[3]||e[3]<t[1]):I(e,t))}_rectInsideRect(e,t){return null!=t&&(this._longitudeCyclical?this._longitudeCyclical.contains(e[0],e[2],t[0])&&this._longitudeCyclical.contains(e[0],e[2],t[2])&&t[1]>e[1]&&t[3]<e[3]:b(e,t))}_pointIsInExtent(e,t){if(this._longitudeCyclical)return this._longitudeCyclical.contains(t[0],t[2],e.x)&&e.y>=t[1]&&e.y<=t[3];const r=e.x,s=e.y;return r>t[0]&&r<t[2]&&s>t[1]&&s<t[3]}_shiftExtentToFitBounds(e,t,r){let s=0,i=0;e[0]<-t?s=e[0]+t:e[2]>t&&(s=t-e[2]),e[1]<-r?i=e[1]+r:e[3]>r&&(i=r-e[3]),C(e,s,i)}get test(){}};function se(e,t){const r=1e-5,s=L.TESTS_DISABLE_OPTIMIZATIONS?0:r*Math.max(e[2]-e[0],e[3]-e[1],t[2]-t[0],t[3]-t[1]);return Math.abs(t[0]-e[0])<=s&&Math.abs(t[1]-e[1])<=s&&Math.abs(t[2]-e[2])<=s&&Math.abs(t[3]-e[3])<=s}e([h()],re.prototype,"_spatialReference",void 0),e([h({readOnly:!0})],re.prototype,"running",null),e([h()],re.prototype,"_placementDirty",void 0),e([h()],re.prototype,"_contentUpdated",void 0),e([h()],re.prototype,"_isSpherical",null),e([h()],re.prototype,"worldToPCSRatio",null),e([h()],re.prototype,"renderer",void 0),e([h({constructOnly:!0})],re.prototype,"view",void 0),e([h({constructOnly:!0})],re.prototype,"surface",void 0),e([h()],re.prototype,"suspended",null),e([h()],re.prototype,"updating",null),re=e([c("esri.views.3d.terrain.OverlayManager")],re);class ie{constructor(){this.inner=O(),this.outer=O(),this.mapUnitsPerPixel=0,this.pixelRatioAdjustment=1,this.stretch=$}}const ne=w(),ae=_(),oe=new ie,le=O(),he=O(),ce=U();export{re as OverlayManager};
5
+ import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import{Cyclical as r,cyclicalPI as s}from"../../../core/Cyclical.js";import"../../../core/has.js";import{clamp as i,deg2rad as n}from"../../../core/mathUtils.js";import{destroyMaybe as a}from"../../../core/maybe.js";import{watch as o,sync as l}from"../../../core/reactiveUtils.js";import{property as h}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as c}from"../../../core/accessorSupport/decorators/subclass.js";import{subtract as d}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{f as u,d as p,c as m,j as g}from"../../../chunks/vec32.js";import{create as _}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{t as y,d as f,g as v}from"../../../chunks/vec42.js";import{fromValues as x,create as w}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{getReferenceEllipsoid as R}from"../../../geometry/ellipsoidUtils.js";import{projectVectorToVector as S}from"../../../geometry/projection/projectVectorToVector.js";import{create as O,width as P,copy as D,center as T,height as M,intersection as j,contains as b,intersects as I,offset as C}from"../../../geometry/support/aaBoundingRect.js";import{create as U,wrap as E}from"../../../geometry/support/ray.js";import{e as A,b as q,t as V}from"../../../chunks/sphere.js";import{angleAroundAxis as F}from"../../../geometry/support/vector.js";import{y2lat as G}from"../../../geometry/support/webMercatorUtils.js";import{viewAngle as H}from"../state/utils/viewUtils.js";import{debugFlags as L}from"../support/debugFlags.js";import{DebugPoint as z}from"../support/debugUtils.js";import{OverlayRenderer as k}from"./OverlayRenderer.js";import{Intersector as B}from"../webgl-engine/lib/Intersector.js";import{fromValues as W}from"../webgl-engine/lib/LocalOriginFactory.js";import{SortedRenderGeometryRenderer as Y}from"../webgl-engine/lib/SortedRenderGeometryRenderer.js";import{applyTextureResizeModulo as N,ensureTextureSize as X}from"../webgl-engine/lib/textureUtils.js";import{removeLoadedShaderModules as Z}from"../webgl-engine/parts/renderUtils.js";import{TaskPriority as J,noBudget as K}from"../../support/Scheduler.js";import{Yield as Q}from"../../support/Yield.js";const $=1.3,ee=[[-.1,-2,3.9,2],[-.1,-3.9,3.9,.1],[-2,-3.9,2,.1],[-3.9,-3.9,.1,.1],[-3.9,-2,.1,2],[-3.9,-.1,.1,3.9],[-2,-.1,2,3.9],[-.1,-.1,3.9,3.9]];let te,re=class extends t{constructor(e){super(e),this._renderSR=null,this._overlaySREqualsRenderSR=!0,this._drapeSources=new Set,this._drapeTargets=new Set,this._placementDirty=!1,this._contentUpdated=!1,this._drawTexturesDirty=!1,this._drawTexturesAnimateDirty=!1,this._latestOriginId=0}initialize(){const e=this.view;this.renderer=new k({parent:this}),e.stage.renderer.plugins.add(this.renderer);const t=()=>this.requestRender();this._groundIntersector=new B(this.view.state.viewingMode),this._groundIntersector.options.backfacesTerrain=!0,this._groundIntersector.options.invisibleTerrain=!0,this._groundIntersector.options.hud=!1,this.addHandles([o(()=>this.renderer.hasHighlights,t),this.renderer.events.on("has-water",()=>e.stage?.renderer.updateHasFlags()),this.renderer.events.on("content-changed",t),o(()=>e.state.camera.pixelRatio,t),o(()=>e.state.alignPixelEnabled,t),this.renderer.events.on("textures-disposed",()=>this.surface.requestRender()),o(()=>[e.pointsOfInterest?.renderPointOfView,e.pointsOfInterest?.centerOnSurfaceFrequent?.location],()=>this.setPlacementDirty()),o(()=>[e.state?.pixelRatio,e.state?.contentPixelRatio],()=>this.setPlacementDirty(),l),this.surface.on("elevation-change",()=>this.setPlacementDirty()),e.on("resize",()=>this.setPlacementDirty()),e.resourceController.scheduler.registerTask(J.OVERLAY,this)]),e.stage.renderer.overlay=this}destroy(){this.view?.stage&&(this.view.stage.renderer.plugins.remove(this.renderer),this.view.stage.renderer.overlay=null,a(this.renderer)),te&&(te.hide(),te=null),this.renderer=null}get spatialReference(){return this._spatialReference}set spatialReference(e){this._spatialReference=e,this.renderer.longitudeCyclical=null;const t=this.view.renderSpatialReference;null!=e&&null!=t?(this._renderSR=t,this._overlaySREqualsRenderSR=e.equals(this._renderSR),this._isSpherical&&(this.renderer.longitudeCyclical=e.isWebMercator?new r(-20037508.342787,20037508.342787):new r(-180,180))):this.renderer.disposeOverlays()}get running(){return this._placementDirty&&(this._drapeSources.size>0||this.view.graphics.length>0||L.OVERLAY_DRAW_DEBUG_TEXTURE)&&!!this._spatialReference&&!this.suspended&&this.surface.ready}get _isSpherical(){return this.view.state.isGlobal}get worldToPCSRatio(){return null!=this._spatialReference&&this._spatialReference.isGeographic&&!this.view.state.isLocal?R(this._spatialReference).metersPerDegree:1}get _overlayStretch(){return $/this.view.resolutionScale}get _longitudeCyclical(){return this.renderer.longitudeCyclical}get suspended(){return this.surface.suspended}get updating(){return this.running||!!this.renderer?.updating||this._contentUpdated}render(){return this._contentUpdated=!1,this.renderer.processSyncDrapeSources(),this.renderer.precompileShaders(this.view.state)?this._drawOverlays():null}get hasOverlays(){return this.renderer.hasOverlays}registerDrapeSource(e,t){this._drapeSources.add(e),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources),this.renderer.registerDrapeSource(e,t),this._updateDrapeSourceExtent(e),this._setContentDirty(),this.notifyChange("running")}registerGeometryDrapeSource(e){const t=new Y({stage:this.view.stage,drapeSource:e,rendererContext:this.renderer});return this.registerDrapeSource(e,t),t}_updateDrapeSourceExtent(e){2===this.renderer.overlays.length&&null!=e.setDrapingExtent&&null!=this._spatialReference&&e.setDrapingExtent(this.renderer.overlays,this._spatialReference)}unregisterDrapeSource(e){this._drapeSources.has(e)&&(this._drapeSources.delete(e),this.renderer.removeDrapeSourceRenderer(e),this.renderer.ensureDrapeSources(this._drapeSources),this._setContentDirty(),this.notifyChange("running"))}registerDrapeTarget(e){this._drapeTargets.add(e),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources)}unregisterDrapeTarget(e){this._drapeTargets.delete(e),this.renderer.ensureDrapeTargets(this._drapeTargets)}_setContentDirty(){this.setPlacementDirty(),this.requestRender()}setPlacementDirty(){this._placementDirty=!0}runTask(e){return this.updateOverlays(e,this.view.state.contentCamera,1)}updateOverlays(e,t,r){if(!this._spatialReference)return Q;const s=this._computeOverlayHeight(t);this._computeOverlayExtents(t,s,oe),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources,oe.stretch);const i=this._updateOverlay(0,oe.inner,s,1*oe.pixelRatioAdjustment,oe.mapUnitsPerPixel),n=P(oe.inner)/P(oe.outer),a=this._updateOverlay(1,oe.outer,s,n*oe.pixelRatioAdjustment,oe.mapUnitsPerPixel);1!==i&&1!==a||(this._drapeSources.forEach(e=>this._updateDrapeSourceExtent(e)),this.updateOverlayParameters(r)),0===i&&0===a||this.requestRender(),this._placementDirty=!1,e.madeProgress()}_computeOverlayHeight(e){const t=this.view.state.contentPixelRatio*this.view.resolutionScale,r=e.fullWidth/e.pixelRatio*t,s=e.fullHeight/e.pixelRatio*t,i=Math.ceil(1.5*Math.max(r,s)),{maxPreferredTexturePixels:n,maxTextureSize:a}=this.view.stage.renderView.renderingContext.parameters,o=.5*a;return N(X({width:i,height:i},{maxPreferredTexturePixels:2*n,maxTextureSize:o})[1],o)}_updateOverlay(e,t,r,s,i){if(0===this.renderer.overlays.length)return 0;const n=this.renderer.overlays[e],a=n.mapUnitsPerPixel;if(n.mapUnitsPerPixel=i,n.pixelRatio=s,se(t,n.extent)&&r===n.resolution)return a===i?0:2;D(n.extent,t),n.resolution=r;const o=T(n.extent);return n.renderLocalOrigin=W(o[0],o[1],0,"OV_"+this._latestOriginId++),1}updateOverlayParameters(e){this.surface.allTiles.forAll(e=>this.updateTileOverlayParameters(e)),this.surface.requestRender(e)}updateTileOverlayParameters(e){if(!e.renderData)return;const t=e.renderData.overlay;if(0===this.renderer.overlays.length)this._clearTileOverlayData(0,t),this._clearTileOverlayData(1,t);else{const[r,s]=this.renderer.overlays,i=e.extent;this._rectInsideRect(r.extent,i)||this._rectanglesOverlap(i,r.extent)||this._rectanglesOverlap(i,s.extent)?(this._setTileOverlayData(i,0,t),this._setTileOverlayData(i,1,t)):(this._clearTileOverlayData(0,t),this._clearTileOverlayData(1,t))}}overlayPixelSizeInMapUnits(e,t){if(0===this.renderer.overlays.length)return t();const r=this.renderer.overlays[0],s=this.renderer.overlays[1],i=this._pointIsInExtent(e,r.extent)?r:s;return(i.extent[2]-i.extent[0])/i.resolution}_setTileOverlayData(e,t,r){if(0===this.renderer.overlays.length)return;const s=this.renderer.overlays[t].extent,i=P(s),n=M(s);let a=e[0];if(this._longitudeCyclical){a=this._longitudeCyclical.minimalMonotonic(s[0],a);const t=this._longitudeCyclical.minimalMonotonic(s[0],e[2]);a>t&&(a=t-(e[2]-e[0]))}r.setScale(t,P(e)/i,M(e)/n),r.setOffset(t,(a-s[0])/i,(e[1]-s[1])/n)}_clearTileOverlayData(e,t){t.setScale(e,-1,-1),t.setOffset(e,-1,-1)}reloadShaders(){Z(),this.requestRender(),this.runTask(K)}requestRender(e=1){this.renderer.hasOverlays?(1===e?(this._contentUpdated=!0,this._drawTexturesDirty=!0):this._drawTexturesAnimateDirty=!0,this.view.stage.renderView.requestRender(e)):this.setPlacementDirty()}_intersectGroundFromView(e,t,r,s,i){const n=this.view.sceneIntersectionHelper.getCenterRayWithSubpixelOffset(e,ce,t,r);if(null==n)return!1;const a=n.origin,o=u(ae,n.origin,n.direction);this._groundIntersector.reset(a,o,e),this._groundIntersector.intersect([]),this.view.basemapTerrain.intersect(this._groundIntersector,null,a,o);const l=this._groundIntersector.results.min;return l.getIntersectionPoint(i)&&l.withinDistance(s)}_findHorizonBasedPointOfInterest(e,t){let r=.5;const n=.55,a=this.view.renderCoordsHelper.getAltitude(e.eye),o=this.view.pointsOfInterest.centerOnSurfaceFrequent,l=1e-5,h=i(o.estimatedSurfaceAltitude,e.aboveGround?-1/0:a+l,e.aboveGround?a-l:1/0),c=e.aboveGround;if("global"===this.view.viewingMode){const t=ae;A(q(V,R(this.view.spatialReference).radius+h),E(e.eye,e.viewForward),t),p(t,t,e.eye);const i=s.normalize(F(e.viewForward,t,e.viewRight))/e.fovY+.5,a=i<=0||i>=1?.5:n;r=c?a*i:i+a*(1-i)}else{const t=.5*Math.PI-Math.acos(-e.viewForward[2]),s=Math.tan(t),a=x(0,s,1,0),o=y(a,a,e.projectionMatrix)[1],l=i(.5+.5*o,0,1);r=1===l||0===l?.5:c?l*n:1-(1-l)*n}return this._intersectGroundFromView(e,.5,r,o.distance,t)}_computeOverlayExtents(e,t,r){const s=this.view.pointsOfInterest.centerOnSurfaceFrequent.renderLocation,i=_();this._findHorizonBasedPointOfInterest(e,i)||m(i,s),L.OVERLAY_SHOW_CENTER?(null==te&&(te=new z(this.view.graphics,"red")),te.show(i,this._renderSR)):null!=te&&te.hide();const a=Math.max(.1,g(e.eye,i)),o=H(this.view.renderCoordsHelper,s,e.eye);this._overlaySREqualsRenderSR||S(i,this._renderSR,i,this._spatialReference);const l=this.surface.extent,h=!this._isSpherical&&this._spatialReference?.isGeographic,c=h&&this._spatialReference?1/R(this._spatialReference).metersPerDegree:1,u=this.view.state.contentPixelRatio,p=e.perScreenPixelRatio/u*a*c;r.mapUnitsPerPixel=p/this.worldToPCSRatio,r.stretch=this._overlayStretch;let y=t*p/2*r.stretch,x=!1,w=h?90:1/0;this._isSpherical&&l&&this._spatialReference&&(this._spatialReference.isWebMercator?(y/=Math.cos(G(i[1])),w=l[3]):(x=!0,y/=R(this._spatialReference).metersPerDegree,w=90),y>=w&&(y=w,i[1]=0,this._spatialReference.isWebMercator&&(i[0]=0)));let O=1;x&&(O=1/Math.max(.2,Math.cos(Math.abs(n(i[1])))),y*O>180&&(O=180/y),r.mapUnitsPerPixel*=O);const T=Math.log(2)/12;y=Math.exp(Math.round(Math.log(y)/T)*T);const M=y*O,I=32,C=.5*t/(I*M),U=.5*t/(I*y);i[0]=Math.round(i[0]*C)/C,i[1]=Math.round(i[1]*U)/U;const E=r.inner;E[0]=i[0]-M,E[1]=i[1]-y,E[2]=i[0]+M,E[3]=i[1]+y,this._isSpherical&&this._shiftExtentToFitBounds(E,1/0,w);const A=r.outer;if(6*M>P(l))D(A,l);else{if(Math.PI/2-Math.abs(o-Math.PI/2)<=.25*Math.PI)A[0]=E[0]-M,A[1]=E[1]-y,A[2]=E[2]+M,A[3]=E[3]+y;else{S(e.eye,this._renderSR,ae,this._spatialReference),d(ne,i,ae);let t=-Math.atan2(ne[1],ne[0])+.125*Math.PI;t<0&&(t+=2*Math.PI);const r=Math.floor(t/(.25*Math.PI));f(ne,ee[r],2*y),ne[0]*=O,ne[2]*=O,v(A,E,ne)}}if(this._isSpherical)A[0]=this._longitudeCyclical.clamp(A[0]),A[2]=this._longitudeCyclical.clamp(A[2]),A[1]=Math.max(A[1],-w),A[3]=Math.min(A[3],w);else{const e=j(E,l,le),t=j(A,l,he);b(e,t)&&(A[2]=A[0],A[3]=A[1])}const q=Math.abs(E[2]-E[0])/t;r.mapUnitsPerPixel=Math.max(r.mapUnitsPerPixel,q),r.pixelRatioAdjustment=r.mapUnitsPerPixel/q}_drawOverlays(e=this.view.state){if(!this._drawTexturesDirty&&!this._drawTexturesAnimateDirty)return this.renderer;const t=!this._drawTexturesDirty&&this._drawTexturesAnimateDirty?0:1;this._drawTexturesDirty=this._drawTexturesAnimateDirty=!1;const r=this.renderer.computeValidity();this.renderer.releaseRenderTargets(t),this.renderer.drawOverlays(e,t);return r!==this.renderer.computeValidity()&&this.updateOverlayParameters(1),this.surface.requestRender(t),1===t&&this.surface.requestUpdate(),this.renderer}_rectanglesOverlap(e,t){return null!=e&&(this._longitudeCyclical?(this._longitudeCyclical.contains(t[0],t[2],e[0])||this._longitudeCyclical.contains(t[0],t[2],e[2])||this._longitudeCyclical.contains(e[0],e[2],t[0]))&&!(e[1]>t[3]||e[3]<t[1]):I(e,t))}_rectInsideRect(e,t){return null!=t&&(this._longitudeCyclical?this._longitudeCyclical.contains(e[0],e[2],t[0])&&this._longitudeCyclical.contains(e[0],e[2],t[2])&&t[1]>e[1]&&t[3]<e[3]:b(e,t))}_pointIsInExtent(e,t){if(this._longitudeCyclical)return this._longitudeCyclical.contains(t[0],t[2],e.x)&&e.y>=t[1]&&e.y<=t[3];const r=e.x,s=e.y;return r>t[0]&&r<t[2]&&s>t[1]&&s<t[3]}_shiftExtentToFitBounds(e,t,r){let s=0,i=0;e[0]<-t?s=e[0]+t:e[2]>t&&(s=t-e[2]),e[1]<-r?i=e[1]+r:e[3]>r&&(i=r-e[3]),C(e,s,i)}get test(){}};function se(e,t){const r=1e-5,s=L.TESTS_DISABLE_OPTIMIZATIONS?0:r*Math.max(e[2]-e[0],e[3]-e[1],t[2]-t[0],t[3]-t[1]);return Math.abs(t[0]-e[0])<=s&&Math.abs(t[1]-e[1])<=s&&Math.abs(t[2]-e[2])<=s&&Math.abs(t[3]-e[3])<=s}e([h()],re.prototype,"_spatialReference",void 0),e([h({readOnly:!0})],re.prototype,"running",null),e([h()],re.prototype,"_placementDirty",void 0),e([h()],re.prototype,"_contentUpdated",void 0),e([h()],re.prototype,"_isSpherical",null),e([h()],re.prototype,"worldToPCSRatio",null),e([h()],re.prototype,"renderer",void 0),e([h({constructOnly:!0})],re.prototype,"view",void 0),e([h({constructOnly:!0})],re.prototype,"surface",void 0),e([h()],re.prototype,"suspended",null),e([h()],re.prototype,"updating",null),re=e([c("esri.views.3d.terrain.OverlayManager")],re);class ie{constructor(){this.inner=O(),this.outer=O(),this.mapUnitsPerPixel=0,this.pixelRatioAdjustment=1,this.stretch=$}}const ne=w(),ae=_(),oe=new ie,le=O(),he=O(),ce=U();export{re as OverlayManager};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import t from"../../../Color.js";import{difference as i}from"../../../core/arrayUtils.js";import r from"../../../core/CollectionFlattener.js";import{toConst as s}from"../../../core/compilerUtils.js";import a from"../../../core/Evented.js";import"../../../core/has.js";import n from"../../../core/Logger.js";import{clamp as l}from"../../../core/mathUtils.js";import{destroyMaybe as o}from"../../../core/maybe.js";import{MemCachePool as h}from"../../../core/MemCachePool.js";import d from"../../../core/ObjectPool.js";import u from"../../../core/PooledArray.js";import{throwIfAborted as p,isAbortError as c,isAborted as g}from"../../../core/promiseUtils.js";import{watch as _,syncAndInitial as m,sync as f,initial as y}from"../../../core/reactiveUtils.js";import{getMetersPerUnitForSR as T}from"../../../core/unitUtils.js";import{property as v}from"../../../core/accessorSupport/decorators/property.js";import{subclass as w}from"../../../core/accessorSupport/decorators/subclass.js";import{i as S,c as C}from"../../../chunks/vec32.js";import{create as b}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as x}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as E}from"../../../geometry/ellipsoidUtils.js";import L from"../../../geometry/SpatialReference.js";import{getProjector as P}from"../../../geometry/projection/projectors.js";import{projectPointToVector as U}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as M}from"../../../geometry/projection/projectVectorToVector.js";import{create as D,equals as R,intersection as j,intersectsSphere as B,empty as I,expand as k}from"../../../geometry/support/aaBoundingRect.js";import{create as A,copy as V}from"../../../geometry/support/frustum.js";import{isPlateCarree as O}from"../../../geometry/support/spatialReferenceUtils.js";import{h as q,c as G,a as N}from"../../../chunks/sphere.js";import{ElevationQueryTileCache as F}from"../../../layers/support/ElevationQueryTileCache.js";import{isBaseLayer as W}from"../../../layers/support/layerUtils.js";import{debugFlags as H}from"../support/debugFlags.js";import{ElevationRange as $}from"../support/ElevationRange.js";import{ElevationUpdateEvent as Q}from"../support/ElevationUpdateEvent.js";import{toBoundingRect as z}from"../support/extentUtils.js";import{updatingProgress as Y}from"../support/updatingProperties.js";import{ElevationBounds as X}from"./ElevationBounds.js";import{ElevationData as K,sampleElevation as J}from"./ElevationData.js";import{create as Z}from"./ExtentHelper.js";import{LayerClasses as ee}from"./LayerClass.js";import{OverlayManager as te}from"./OverlayManager.js";import{PlanarPatch as ie}from"./PlanarPatch.js";import{ScaleRangeQueries as re}from"./ScaleRangeQueries.js";import{SphericalPatch as se}from"./SphericalPatch.js";import{SplitLimits as ae}from"./SplitLimits.js";import{maxRootTiles as ne,tooManyRootTilesAfterChangeError as le,tooManyRootTilesForLayerError as oe,maxTileNeighborLevelDelta as he,maxMemoryLodBias as de}from"./TerrainConst.js";import{TerrainRenderer as ue}from"./TerrainRenderer.js";import pe from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as ce,isVectorTileLayerView as ge,neighborEdgeIndices as _e,internalAssert as me,oppositeEdge as fe,isSurfaceLayerView as ye,isGroupLayerView as Te,isMapTileLayerView as ve,isBlendableLayerView as we,isElevationLayerView as Se,releaseTerrainData as Ce,enableTerrainInternalChecks as be,oppositeCorner as xe,enableWaterproofTests as Ee,enableInternalTerrainChecks as Le,enableTerrainWaterproofChecks as Pe,neighborCornerIndices as Ue}from"./terrainUtils.js";import{Tile as Me,lijEquals as De}from"./Tile.js";import{printAllocations as Re}from"./TilePerLayerInfo.js";import{IteratorPreorder as je,IteratorPostorder as Be,compareTilesByLij as Ie,hasLoadableSiblings as ke,sortTilesByPOI as Ae}from"./tileUtils.js";import{TilingSchemeLogic as Ve}from"./TilingSchemeLogic.js";import{UpsampleInfo as Oe}from"./UpsampleInfo.js";import{isCompositeBlendMode as qe,blendModeFromString as Ge}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{hasLayerBasedScaleVisibility as Ne}from"../../support/layerViewUtils.js";import{ImmediateTask as Fe,TaskPriority as We,noBudget as He}from"../../support/Scheduler.js";import{TextureCompressionTracker as $e}from"../../support/TextureCompressionTracker.js";import{Yield as Qe}from"../../support/Yield.js";var ze;let Ye=class extends a.EventedAccessor{static{ze=this}get allTiles(){return s(this._allTiles)}get demResolution(){const{_allTiles:e,tilingScheme:t}=this;if(0===e.length)return{min:1,max:1};const i=T(t.spatialReference);let r=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY;for(const a of e){const e=t.resolutionAtLevel(a.level)*i;r=Math.min(r,e),s=Math.max(s,e)}return{min:r,max:s}}constructor(e){super(e),this.terrainTextureCompressionTracker=new $e,this._iteratorPool=new d(je,e=>e.remove=()=>this._iteratorPool.release(e)),this._postorderIterator=new Be,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._usedMemory=null,this._performanceInfo=new pe,this._viewChanged=!1,this.heading=0,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=b(),this._eyePosSurfaceSR=b(),this._splitLimits=new ae,this._frustum=A(),this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._watchUpdatingTracking=new x,this._frameTask=Fe,this._allTiles=new u,this._upsampleInfoPool=new d(Oe),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=D(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=L.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationBounds=new X(1/0,-1/0),this.rootTileElevationBounds=new X(1/0,-1/0),this._projectorCache=new Map,this._radiusModifier=Math.cos(Math.PI/16/16),this._tilingSchemeSpatialReference=null,this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._oneBatchPerFrameTask=!0,this._layerViewsDirty=!1,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._isWebMercator=!1,this._isWebMercatorOnPlateCarree=!1;const t=e.view;this.overlayManager=new te({...e,surface:this}),this._isGlobal=!t.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?se:ie,this._ellipsoid=E(t.spatialReference),this._renderer=new ue(this.overlayManager.renderer,t.stage,this._allTiles,this._ellipsoid.radius,this.terrainTextureCompressionTracker,t.resourceController.memoryController),Ne()||(this._scaleRangeQueries=new re)}initialize(){const e=this.view,t=e.resourceController,i=t.memoryController;this._tileCache=new h((e,t)=>i.newCache(e,t),"terrain-tile"),this._upsampleMapCache=i.newCache("terrain-upsample",e=>e.unloadMapData()),this._elevationQueryCache=new F(i.newCache("elevation-query"));const s=this.overlayManager;this.addHandles([_(()=>s.renderer.isEmpty,()=>this._evaluateTransparency()),_(()=>this.renderer.visible,e=>this.suspended=!e),_(()=>this.heading,e=>{this._renderer.updateHeading(e),this._updateTileTextures(0)}),_(()=>({heading:e.camera?.heading,state:e.state?.mode}),({heading:e,state:t})=>{if(null==e)return;if(this.isGlobal&&this.isGeographic||this.isWebMercatorOnPlateCarree)return void(this.heading=90*Math.round(e/90)%360);const i=Math.round(e)%360,r=Math.abs(i-this.heading);(2===t||Math.min(r,360-r)>=30)&&(this.heading=i)})],"overlayManager"),this.addHandles([_(()=>this.baseOpacity,()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?1:2)},m),_(()=>this.hasCompositeBlendMode,()=>this._updateTileTextures(this._evaluateTransparency()?1:2),m),_(()=>this.backgroundColor,(e,t)=>{e?.equals(t)||(this._handleLayerViewChanges(),this._renderer.updateTileBackground(e))},f),_(()=>this.snapLevel,()=>this._viewChanged=!0,f),_(()=>this.view.pointsOfInterest,e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add(()=>e.focus?.renderLocation,()=>this._allTilesSorted=!1)}),_(()=>H.TERRAIN_TILE_TREE_SHOW_TILES,t=>{t&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then(({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&H.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))}):t||(this._treeDebugger=o(this._treeDebugger))},y)]);const{spatialReference:a}=e;this._extentHelper=Z(this.viewingMode,{layers:e.map.allLayers,layerViews:e.allLayerViews,viewSpatialReference:a});const n=new r({getCollections:()=>e.defaultsFromMap?.mapCollections?.map(({layers:e})=>e),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}),l=new Ve({layers:n,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set("tilingSchemeLogic",l),this._updateTilingScheme(),this._elevationDataRequester=t.createStreamDataRequester(0),this._mapDataRequester=t.createStreamDataRequester(1);const d=t.scheduler;this._frameTask=d.registerTask(We.TERRAIN_SURFACE,this),this.addHandles([_(()=>this._extentHelper.stencilEnabledExtents,e=>this._renderer.setStencilEnabledLayerExtents(e),y),_(()=>this.tilingSchemeLogic.tilingScheme,()=>this._updateTilingScheme(),f),_(()=>this.extent,()=>this._updateRootTiles(),y),e.on("resize",()=>this._viewChangeUpdate()),_(()=>{const t=e.state;return[this._lodBias,this.lodSnappingEnabled,e.quality,t.camera,t.contentCamera,t.fixedContentCamera]},()=>this._viewChangeUpdate(),m),_(()=>e.qualitySettings?.fadeDuration,e=>this._renderer.textureFadingEnabled=e>0,y),_(()=>e.qualitySettings?.physicallyBasedRenderingEnabled,e=>this._renderer.pbrMode=e?5:0,y),_(()=>e.qualitySettings?.tiledSurface.elevationLevelDelta,()=>this._updateAllTileGeometries()),_(()=>this._userClippingExtent,()=>this._updateClippingExtent(),f)]),this.addHandles(e.allLayerViews.on("after-changes",()=>this._layerViewsDirty=!0)),this._layerViewsDirty=!0,this._handleLayerViewChanges(),this._renderer.updateTileBackground(this.backgroundColor)}clearHandles(){this._watchUpdatingTracking?.removeAll(),this.removeAllHandles(),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear()}destroy(){this._frameTask.remove(),this._frameTask=Fe,this._watchUpdatingTracking?.destroy(),this._removeAllTiles(),this._set("tilingSchemeLogic",o(this.tilingSchemeLogic)),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear(),this._elevationDataRequester=null,this._mapDataRequester=null,this._set("overlayManager",o(this.overlayManager)),this._tileCache=o(this._tileCache),this._allTiles.prune(),Me.prune(),this._treeDebugger=o(this._treeDebugger),this._renderer.destroy(),this._renderer=null,this._iteratorPool=o(this._iteratorPool),this._upsampleMapCache=o(this._upsampleMapCache),this._elevationQueryCache=o(this._elevationQueryCache),this._set("view",null),this._extentHelper=o(this._extentHelper),this._upsampleInfoPool=o(this._upsampleInfoPool),Re(),this._layerViews.forEach(e=>e.length=0),this._performanceInfo=null}get renderer(){return this._renderer}get frustum(){return this._frustum}get snapLevel(){if(this.lodSnappingEnabled){const{view:e,tilingScheme:t}=this,i=e.scale;if(t&&i){const r=t.levelAtScale(i)+e.qualitySettings.tiledSurface.lodBias,s=t.getMaxLod();return r<=0?null:Math.min(r,s||1/0)}}return null}get lodSnappingEnabled(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get hasStencilEnabledExtents(){return this._extentHelper.stencilEnabledExtents.length>0}get _userClippingExtent(){const{spatialReference:e}=this,{clippingArea:t}=this.view;if(null==t||null==e)return null;const i=D(),r=z(t,i,e)?i:null,s=this._get("extent");return R(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get extent(){const e=j(this.groundExtent,this._userClippingExtent,D()),t=this._get("extent");return R(e,t)?t:e}get groundExtent(){return null!=this._tilingSchemeExtent?this._tilingSchemeExtent:this._rootTilesExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),!!((this.running||this._watchUpdatingTracking?.updating||this._asyncWorkItems>0)&&this.ready&&!this.suspended||this.overlayManager?.updating||this.terrainTextureCompressionTracker.compressing)}get running(){return(this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||!this._allTilesSorted||this._layerViewsDirty||this._scaleRangeQueries?.updating||this._frameTask.updating)&&this.ready&&!this.suspended}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get baseOpacity(){return this.view?.map?.ground?.opacity??1}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return null!=this._rootTiles}set renderOrder(e){this._renderer.renderOrder=e,this._set("renderOrder",e)}get rootTiles(){return this._rootTiles}get spatialReference(){return this.tilingScheme?.spatialReference??null}get backgroundColor(){return this.view?.map?.ground?.surfaceColor}set backgroundColor(e){this.view.map.ground.surfaceColor=e}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set("slicePlaneEnabled",e),this._evaluateTransparency()}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}get wireframe(){return this._renderer?.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}get opaque(){return 0===this._renderer.transparency}get invisible(){return 3===this._renderer.transparency}set suspended(e){this._set("suspended",e),this._viewChangeUpdate()}get fadeDuration(){return this.view.qualitySettings.fadeDuration??0}intersect(e,t,i,r){this._renderer.intersect(e,t,i,r)}getElevationLevelDelta(e){return e<4?3:this.view.qualitySettings.tiledSurface.elevationLevelDelta}getElevation(e,t,i,r){const s=this._rootTiles;if(!s?.length)return null;if(0===s[0].layerInfo[0].length)return null;let a=this._elevationProjectorCache.get(r);if(void 0===a&&(a=P(r,this._spatialReference)??null,this._elevationProjectorCache.set(r,a)),null==a)return n.getLogger(this).error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;const l=S(Ke,e,t,i);a(l,0,l,0);return rt(s,l[0],l[1])}getElevations(e,t,i){const r=this._rootTiles,s=r?r[0].layerInfo[0].length:0;if(r?.length&&0!==s)for(let a=0;a<t;++a){const t=3*a;i(a,rt(r,e[t],e[t+1]))}else for(let a=0;a<t;++a)i(a,null)}getLayerIndexByUID(e,t){return this._layerIndexByUid[e].get(t)}getScale(e){if(!this.tilingScheme)return null;if(!U(e,Ke,this.spatialReference))return n.getLogger(this).error("TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system"),null;const t=this._rootTiles;if(null!=t)for(const i of t)if(i?.containsPoint(Ke)){let e=i;for(;e.children[0]&&!e.rendered;){const t=e.children[0].extent;let i=0;Ke[0]>t[2]&&(i+=1),Ke[1]<t[1]&&(i+=2),e=e.children[i]}return this._getLodBiasCorrectedScale(e.level)}return 1/0}_ensureProjector(e){const t=this._projectorCache.get(e);if(t)return t;const i=P(e,this._tilingSchemeSpatialReference)??null;return this._projectorCache.set(e,i),i}getSphereElevationBounds(e,t){const i=this._ensureProjector(t);if(null==i)return n.getLogger(this).error("TerrainSurface.getSphereElevationBounds(): could not project given point to tiling scheme coordinate system"),null;q(e,Je);const r=N(Je);i(r,0,r,0);const s=new $,a=this._rootTiles;if(null!=a){const e=[];for(const i of a)e.push(i);let t=0;for(;t<e.length;){const i=e[t];if(++t,!B(i.extent,Je))continue;const r=i.children;if(null==r[0]||i.rendered)s.expandElevationRangeValues(i.elevationBoundsMin,i.elevationBoundsMax);else for(const t of r)e.push(t)}}return s}getRootElevationBounds(){return new $(this.rootTileElevationBounds.min,this.rootTileElevationBounds.max)}getLowerBoundRadius(){const e=(this._ellipsoid.radius+this.visibleElevationBounds.min)*this._radiusModifier;return Math.min(e,this._ellipsoid.radius)}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!U(e,N(Je),this.spatialReference))return n.getLogger(this).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;Je[3]=t;let i=null;const r=e=>{if(e&&B(e.extent,Je)){const t=e.children;if(t[0]&&!e.rendered)for(const e of t)r(e);else{const t=this._getLodBiasCorrectedScale(e.level);i=null==i?t:Math.min(i,t)}}},s=this._rootTiles;if(null!=s)for(const a of s)r(a);return i}queryVisibleScaleRange(e,t,i,r){if(!this._scaleRangeQueries)return;const s=t?this.tilingScheme.levelAtScale(t):0,a=i?this.tilingScheme.levelAtScale(i):1/0,n=this._lodBias;this._scaleRangeQueries.queryVisibleLevelRange(e,s+n,a+n,r)}_evaluateTransparency(){const e=this.baseOpacity,t=this.overlayManager.renderer.isEmpty,i=this._renderer.transparency,r=this._isFullyTransparent?t?3:2:e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?0:1;return this._renderer.transparency=r,i!==r}_updateTilingScheme(){const e=this.tilingSchemeLogic.tilingScheme;if(!(e!==this.tilingScheme))return;ce(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();const t=e?.spatialReference??L.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateCarree=this._isWebMercator&&O(this.view?.renderSpatialReference),this._isGeographic=t?.isGeographic??!1,this._set("tilingScheme",e),this._tilingSchemeSpatialReference=this.tilingScheme?.spatialReference,this._projectorCache.clear(),this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.tileSize=e.pixelSize,this.overlayManager.spatialReference=e.spatialReference,this._updateRootTiles())}static{this._tileMemcacheKey="TerrainTileMemcache"}_acquireTile(e,t,i,r){const s=this._tileCache.pop(ze._tileMemcacheKey);return s?(s.init(e,t,i,r,this),s):new this._tileConstructor(e,t,i,r,this)}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){const{extent:e,tilingScheme:t}=this;if(!t)return;const r=Ze;let s=t.rootTilesInExtent(e,r,5*ne);if(null!=this._rootTiles){if(s.length>ne)return void n.getLogger(this).warn(le);const e=this._rootTiles.map(e=>e.lij),t=i(e,s,De);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this._rootTiles.filter(e=>!(t.removed.findIndex(t=>De(t,e.lij))>-1)||(this._purgeTile(e),!1));t.added.forEach(t=>e.push(this._newRootTile(t))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,s.length>ne&&(n.getLogger(this).warn(oe),s=t.rootTilesInExtent(e,r,ne)),this._setRootTiles(s.map(e=>this._newRootTile(e)));R(r,this._rootTilesExtent)||(this._rootTilesExtent=D(r)),this.renderer.visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange("ready"),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness()}_updateAllTileGeometries(){const e=this._allTiles.filter(e=>e.loaded&&e.intersectsClippingArea);e.sort(Ie),e.forEach(e=>this._renderer.updateTileGeometryState(e)),e.forEach(e=>e.renderData.updateNeighborData()),this._updateTilesGeometries(e),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){if(0===e.length)return;e.sort(Ie);const t=this.renderer;e.forEach(e=>t.updateGeometryIfNeeded(e)),e.forEach(e=>this._pendingTilesForElevationUpdateEvent.add(e))}_shouldSplit(e){return 1===e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.snapLevel)}_newRootTile(e){const t=this._acquireTile(0,e[1],e[2],null);return this._shouldSplit(t)&&t.setPendingUpdate(1),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationBounds(),t}_setRootTiles(e){if(this._rootTiles=e,this._allTiles.clear(),null!=e){const t=this._iteratorPool.acquire();for(t.reset(e);!t.done;)this._allTiles.push(t.next());t.remove()}this._renderer.setRootTiles(this._rootTiles),this._updateTilesVisibility(e),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles})}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.suspended&&this.tilingScheme&&this.renderer.visible&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this._rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.extent)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(null==e)return;const t=ke(e),i=this.visibleElevationBounds;let r=t?i.min:1/0,s=t?i.max:-1/0;const a=this.extent,n=this.view.state.contentCamera.viewProjectionMatrix;this.setTileTreeDirty();const l=this._iteratorPool.acquire();for(l.reset(e);!l.done;){const e=l.next();e.updateClippingStatus(a)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e),e.computeVisibility(),e.updateScreenDepth(n),e.renderData&&(r=Math.min(e.elevationBoundsMin,r),s=Math.max(e.elevationBoundsMax,s))}l.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._updatePendingTileGeometries(),isFinite(r)&&isFinite(s)&&(i.min!==r||i.max!==s)&&(this.visibleElevationBounds=new X(r,s))}_updateRootTileElevationBounds(){let e=1/0,t=-1/0;const i=this._rootTiles;null!=i&&i.forEach(({elevationBoundsMin:i,elevationBoundsMax:r})=>{e=Math.min(e,i),t=Math.max(t,r)});const r=this.rootTileElevationBounds;r.min===e&&r.max===t||(this.rootTileElevationBounds=new X(e,t))}_updateViewDependentParameters(){const{camera:e,contentCamera:t}=this.view.state,i=Math.tan(.5*t.fovX),r=Math.tan(.5*t.fovY),s=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=i,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=s/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=s/e.height*this.maxTextureScale*a,this._splitLimits.maxLod=this.tilingScheme.getMaxLod(),this._splitLimits.angledSplitBias=this.view.qualitySettings.tiledSurface.angledSplitBias,this.view.state.fixedContentCamera?this._splitLimits.frustum=V(this._splitLimits.frustum??A(),t.frustum):this._splitLimits.frustum=null,V(this._frustum,e.frustum),C(this._eyePosRenderSR,t.eye),M(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateTileGeometryState(e){e.updateVisibility();this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this.setMemoryDirty()}_markAllTileNeighborsForUpdate(e){e.forEachLoadedNeighbor(e=>{this._layerViews[1].some(ge)&&e.setPendingUpdate(32),this._pendingTilesToUpdate.add(e)})}_updateTileTexture(e,t){const i=e.resetPendingUpdate(32)?32:!!e.resetPendingUpdate(16)&&16;i&&(this._renderer.updateTileTexture(e,i),this._usedMemory=null,t.madeProgress())}_emitElevationUpdateEventForTiles(){if(!this._shouldEmitChangeEvent)return;const e=tt.extent;I(e),this._pendingTilesForElevationUpdateEvent.forEach(t=>k(e,t.extent,e)),this._pendingTilesForElevationUpdateEvent.clear(),tt.spatialReference=this.spatialReference,this.emit("elevation-change",tt),this._shouldEmitChangeEvent=!1}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this.renderer.processScaleRangeQueries(this._scaleRangeQueries,e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateAllTilesStatus(e),this._sortTiles(e);const t=!this.view.state.fixedContentCamera;if(this._mergeAndSplit(e,t),this._updateElevation(e),this._updateTextures(e),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty(),this._updatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&e.hasProgressed&&this.requestUpdate(),this.notifyChange("updatingProgressValue"),be&&this._checkTileInvariant(),!e.hasProgressed)return Qe}_checkTileInvariant(){const e=new Map;this._allTiles.forAll(t=>e.set(t,new Set)),this._allTiles.forAll(t=>{if(ce(t.rendered===t.leaf,` rendered ${t.rendered} != ${t.leaf} leaf`),!t.leaf){const e=e=>0===e.unmergableChildCount&&0===e.maxLevelDeltaNeighborCount,i=t.children.reduce((t,i)=>t+(e(i)?0:1),0);if(ce(t.unmergableChildCount===i,` Tile[${t.lij.toString()}] unmergeable child count mismatch: actual ${t.unmergableChildCount} vs ${i}`),t.hasPendingUpdate(4)){ce(!t.hasPendingUpdate(1),"Tile can be both split and merge at the same time");for(const e of t.children)ce(e.leaf||e.hasPendingUpdate(4),"Child of tile to merge must also merge")}}for(let i=0;i<4;++i){if(t.rendered){const e=t.renderData?.geometryState.edgePeerNeighbors[i];if(null!=e){{const r=t.level-e.level<=he;r||(console.log(`tile level delta [${t.lij.toString()}] vs [${e.lij.toString()}] > ${he} (edge[${i}])`),ce(r,`tile level delta [${t.level}] vs [${e.level}] > ${he}`))}ce(t.level-e.level<=he,`Max tile lod delta exceeded: [${t.lij.toString()}] vs [${e.lij.toString()}]`)}}const r=t.level-he,s=e=>e.leaf||e.level===t.level,a=t.findNeighborTile(_e[i],s);if(null!=a){if(t.leaf&&t.level>=he){let i=a;for(;t.level-i.level<he;)i=i.parent;const s=[r,t.lij[1]>>he,t.lij[2]>>he];if(!De(s,i.lij)){const r=e.get(i);ce(!r.has(t),"Cannot already have neighbor"),r.add(t)}}ce(a.rendered||a.level===t.level,"Non-same-level-neighbor of rendered must be rendered"),ce(t.level-a.level<=he,`Tile level delta [${t.level}] vs [${a.level}] > ${he}`)}}}),this._allTiles.forAll(t=>{const i=t.maxLevelDeltaNeighborCount,r=e.get(t);ce(i===r.size,`Tile[${t.lij.toString()}] merge-blocker mismatch: actual ${i} vs ${r.size}`)})}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;const t=new st(this._allTiles.length);t.pushAll(this._rootTiles);const i=this.snapLevel,r=this._splitLimits,s=this._eyePosRenderSR;this._allTiles.forAll(e=>{e.maxLevelDeltaNeighborCount=0,e.unmergableChildCount=0});const a=this.view.state.contentCamera.viewProjectionMatrix;for(;!t.empty;){const e=t.pop(),n=e.parent,l=null!=n&&n.hasPendingUpdate(4),o=l?4:e.shouldSplit(r,s,i),h=1===o;e.leaf?at(e,h):t.pushAll(e.children),l?(e.resetPendingUpdate(1),e.leaf||e.setPendingUpdate(4),this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(a)):h?(e.resetPendingUpdate(4),e.leaf&&e.setPendingUpdate(1)):(e.resetPendingUpdate(1)&&e.updateAgentSuspension(),2===o&&e.updateAgents(0),e.leaf||(e.setPendingUpdate(4),e.resetPendingUpdate(1)))}this.requestUpdate(),(this._shortBatches||!this._oneBatchPerFrameTask)&&this._updatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||!this.view.pointsOfInterest?.focus||(Ae(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger&&this._treeDebugger.update(),e.madeProgress())}_markTileToUpdate(e){me(e.loaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForUpdate(e))}_updatePendingTileGeometries(){const e=this._pendingTilesToUpdate,t=Array.from(e.keys()).filter(e=>e.loaded&&e.intersectsClippingArea);if(0===t.length)return void e.clear();const i=(i,r)=>{!r?.loaded||!r.intersectsClippingArea||r.level<i.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(Ie);const r=t.length;for(let s=0;s<r;++s){const r=t[s];me(r.loaded),me(r.intersectsClippingArea);const a=r.renderData;a.updateNeighborData();const n=a.dirtyEdgeResolutions,l=a.geometryState,o=e=>{const t=Ue[e];i(r,l.cornerPeerNeighbors[e]?.findCorner(xe(t),e=>e.loaded))};for(let t=0;t<4;++t)if(n&1<<t){const s=a.geometryState.edgePeerNeighbors[t];s&&s?.level>=r.level&&s.forAllSubtreeOnSide(fe(_e[t]),t=>!(!t.loaded||!t.intersectsClippingArea)&&(me(e.has(t)||Ie(r,t)<0),i(r,t),!0)),o((t+1)%4),o(t)}}e.clear(),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,be&&Ee&&this.checkAllTilesWaterproofness()}_mergeAndSplit(e,t){if(this.suspended||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let i=!1;const r=this.view.state.fixedContentCamera;let s=!1;for(;!e.done;){s=!0;let a=!1;const n=!this._allTiles.some(s=>{if(!i&&!r&&!s.visible)return e.done;let n=s;if(s.hasPendingUpdate(4)){if(!t||s.unmergableChildCount>0)return e.done;for(s.resetPendingUpdate(4);null!=n.parent&&0===n.parent.unmergableChildCount&&n.parent.resetPendingUpdate(4);)n=n.parent;this._mergeTile(n),a=!0,e.madeProgress()}else if(s.resetPendingUpdate(1)){let t=!0;const i=s.level;if(i>=he){const e=e=>e.leaf||i-e.level<he;for(let r=0;r<4;++r){const a=s.findNeighborTile(_e[r],e);null!=a&&i-a.level===he&&(t=!1,be&&(me(a.leaf),me(a.hasPendingUpdate(1))))}}t?(this._splitTile(s),e.madeProgress(),a=!0):s.setPendingUpdate(1)}return e.done});if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0,!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries()),n){if(!i){i=!0;continue}if(!a)break}else this._allTilesDirty=!0}s?e.madeProgress():this._allTilesDirty=!0,!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries(),this._sortTiles(e)}_updateElevation(e){e.done||(this._allTiles.some(t=>(t.resetPendingUpdate(8)&&(this._updateTileGeometryState(t),this._shortBatches&&this._updatePendingTileGeometries(),e.madeProgress()),e.done)),!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries())}_updateTextures(e){e.done||this._allTiles.some(t=>(this._updateTileTexture(t,e),e.done))}_updateClippingExtent(){this.spatialReference&&(this.overlayManager?.updateOverlayParameters(1),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){const e=this.view.quality;return this.view.qualitySettings.tiledSurface.lodBias-(1-e)*de}_getLodBiasCorrectedScale(e){const t=this.tilingScheme.levels,i=l(e-this._lodBias,0,t.length-1),r=i-Math.floor(i);return t[Math.floor(i)].scale*(1-r)+t[Math.ceil(i)].scale*r}_removeAllTiles(){null!=this._rootTiles&&(this._rootTiles.forEach(e=>this._purgeTile(e)),this._setRootTiles(null),this.notifyChange("ready")),this._allTiles.clear(),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles}),this.renderer.visible=!1}_purgeSubtree(e){const t=e.children;t[0]&&(this._purgeTile(t[0]),this._purgeTile(t[1]),this._purgeTile(t[2]),this._purgeTile(t[3]),e.clearChildren())}_purgeTile(e){e.leaf?lt(e):this._purgeSubtree(e),this._allTiles.removeUnordered(e),this._unloadTile(e),e.dispose(),this._tileCache.put(ze._tileMemcacheKey,e),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles})}_unloadTile(e){this._pendingTilesToUpdate.delete(e),this._pendingTilesForElevationUpdateEvent.delete(e),e.unload()}_splitTile(e){ce(e.leaf,"Tile that is already split should not be split again!"),ce(e.rendered,"Tile marked to split is not rendered"),lt(e);const t=e.createChildren();this._allTiles.pushArray(t),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles}),e.updateAgentSuspension(),ce(e.rendered,"parent should be rendered"),t.forEach(e=>this._loadTile(e)),t.forEach(e=>this._pendingTilesToUpdate.add(e)),this._unloadTile(e),this._markAllTileNeighborsForUpdate(e),this._emitTileScaleChange(e,e.level+1),this._allTilesDirty=!0,this._shortBatches&&this._updatePendingTileGeometries(),t.forEach(e=>at(e,e.hasPendingUpdate(1))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){it.spatialReference=this.spatialReference,it.extent=e.extent,it.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",it)}createTile(e,t,i,r){ce(!!r,"createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.extent),s.updateScreenDepth(this.view.state.contentCamera.viewProjectionMatrix),this._shouldSplit(s)&&s.setPendingUpdate(1),s}get _shortBatches(){return 2!==this.view.state.mode}_mergeTile(e){ce(!e.hasPendingUpdate(1),"_mergeTile sanity check"),ce(!e.leaf,"Cannot merge a leaf"),e.leaf||(this._purgeSubtree(e),ce(!e.renderData,"Merging tile with existing render data?"),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),at(e,!1),this._allTilesDirty=!0,++this._performanceInfo.numMerged)}_loadTile(e){e.load(),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager?.hasOverlays&&this.overlayManager.updateTileOverlayParameters(e)}_handleLayerViewChanges(e=He){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1;const i=new Set;let r=-1;for(let s=this.view.allLayerViews.length-1;s>=0;s--){const e=this.view.allLayerViews.items[s];if(i.add(e.uid),ye(e)||Te(e))if(this._basemapLayerViewHandles.has(e.uid)&&!Te(e)){const i=this._layerClassFromLayerView(e),s=this.getLayerIndexByUID(i,e.uid);null!=s&&((s<r||null==r)&&(t=!0),r=s)}else this._registerTiledLayerView(e),e.layer.loaded&&(t=!0)}this._basemapLayerViewHandles.forEach((e,r)=>{i.has(r)||(this._unregisterTiledLayerView(r),t=!0)}),t&&this._updateTiledLayers(),this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._evaluateTransparency(),e.madeProgress()}get _isFullyTransparent(){if(this.view.map?.ground?.opacity>0)return!1;for(const e of this.view.allLayerViews.items)if(ve(e)&&!W(e.layer)&&0!==e.fullOpacity)return!1;return!0}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if((we(e)||Te(e))&&qe(Ge[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return Se(e)?0:1}_registerTiledLayerView(e){const t=[];if((we(e)||Te(e))&&t.push(_(()=>e.layer.blendMode,()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(2)})),!Te(e)){const i=this._layerClassFromLayerView(e);t.push(_(()=>!e.destroyed&&e.suspended,()=>this._updateTiledLayers())),t.push(_(()=>!e.destroyed&&e.fullOpacity,()=>this._updateTileTextures(2)));const{layer:r}=e;"effectiveScaleRange"in r&&t.push(_(()=>!e.destroyed&&r.effectiveScaleRange,()=>this._restartAllAgents(i))),t.push(e.on("data-changed",()=>{const t=this.getLayerIndexByUID(i,e.uid);null!=t&&this._invalidateLayerData(t,i)}))}this._unregisterTiledLayerView(e.uid),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){const t=this._basemapLayerViewHandles.get(e);if(t){for(const e of t)e.remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;const e=this.view.allLayerViews,t=[[],[]];let i=null;e.forEach(e=>{if(!e.layer||e.suspended||!ye(e)||!e.fullExtent)return;const r=this._layerClassFromLayerView(e);if(1===r){const t=e.displayLevelRange.maxLevel;t!==1/0&&(null===i||t>i)&&(i=t)}t[r].push(e)});for(const r of ee){const e=this._layerViews[r],i=t[r];i.reverse();const s=i.length;let a=e.length!==s;const n=new Array(s),l=new Array(e.length);this._layerIndexByUid[r].clear();for(let t=0;t<s;t++){const s=i[t].uid;this._layerIndexByUid[r].set(s,t);const o=e.indexOf(i[t]);n[t]=o,t!==o&&(a=!0),o>-1&&(l[o]=t)}if(a){const e=this._postorderIterator;for(e.reset(this._rootTiles);!e.done;)e.next().modifyLayers(l,n,r);this._layerViews[r]=i,this._restartAllAgents(r),this._updateTilesVisibility(this._rootTiles)}}this.tilingScheme.ensureMaxLod(i)&&(this._viewChangeUpdate(),this.notifyChange("tilingScheme"))}_restartAllAgents(e){const t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;){const i=t.next();i.restartAgents(e),0===e&&i.computeElevationBounds()}this._updateRootTileElevationBounds()}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll(t=>{t.updateAgents(1),1===e?this.renderer.updateTileTexture(t,16):t.updateRenderData(1,e)}),this._evaluateTransparency()}_invalidateLayerData(e,t){this._allTiles.forAll(i=>i.removeLayerAgent(e,t)),this._allTiles.forAll(i=>i.invalidateLayerData(e,t))}setTileTreeDirty(){this._allTilesDirty=!0}requestRender(e=1){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||ge(s)?this._requestTileData(e,i,s,r):(++this._asyncWorkItems,a.tilemapCache.fetchAvailability(e.level,e.lij[1],e.lij[2],{...r,timeout:6e3}).then(()=>--this._asyncWorkItems).catch(t=>{throw--this._asyncWorkItems,p(r),c(t)||this._dataMissing(e,i,s),t}).then(()=>this._frameTask.schedule(()=>this._requestTileData(e,i,s,r),r.signal)))}_requestTileData(e,t,i,r){if(this.destroying)return Promise.resolve();const s=0===t;return r.requester??=s?this._elevationDataRequester:this._mapDataRequester,s?Se(i)?this._requestElevationTileData(e,i,r):Promise.reject():ve(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{!g(i)&&r&&(this.setMemoryDirty(),this.requestUpdate(),this._elevationDataArrived(e,t,r))},s=i=>{c(i)||(n.getLogger(this).error(`Tile ${e.lij.toString()} layer 0/${t.uid} error ${i}`),this._dataMissing(e,0,t),this.requestUpdate())};return t.fetchElevationTile(e,i).then(e=>this._frameTask.schedule(()=>r(e)),s).finally(()=>--this._asyncWorkItems)}_elevationDataArrived(e,t,i){const r=this._layerIndexByUid[0].get(t.uid);if(null==r)return void n.getLogger(this).warn("TerrainSurface: received data from unknown layer %d %s",0,e.lij.toString());const s=new K(e.lij,e.extent,i);e.dataArrived(r,0,s),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:0});const a=[e],l=e.level,o=this._iteratorPool.acquire();for(o.reset(a);!o.done;){const e=o.next();e.findElevationBoundsForLayer(r,l),e.computeElevationBounds()}0===l&&this._updateRootTileElevationBounds(),o.remove(),this._updateTilesVisibility(a)}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{Ce(s),g(i)||(console.error(`Tile ${e.lij.toString()} layer 1/${t.uid} error ${r}`),this._dataMissing(e,1,t),this.requestUpdate())},s=e=>t=>r(t,e),a=r=>this._frameTask.schedule(()=>{this.requestUpdate(),g(i)?Ce(r):this._mapTileDataArrived(e,t,r)},i.signal,s(r)).catch(s(r)),n=(e,t=null)=>this._frameTask.schedule(()=>r(e,t));return t.fetchTile(e.lij,i).then(a,n).finally(()=>--this._asyncWorkItems)}_mapTileDataArrived(e,t,i){const r=this.getLayerIndexByUID(1,t.uid);if(null==r)return Ce(i),void n.getLogger(this).warn("TerrainSurface: received data from unknown layer");e.dataArrived(r,1,i),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:1})}_dataMissing(e,t,i){const r=this.getLayerIndexByUID(t,i.uid);null!=r?(e.dataMissing(r,t),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:t})):n.getLogger(this).warn("TerrainSurface: received data from unknown layer")}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.leaf&&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}setMemoryDirty(){this._usedMemory=null}get usedMemory(){return this.tilingScheme?(null==this._usedMemory&&(this._usedMemory=this._recalculateUsedMemory()),this._usedMemory??0):0}_recalculateUsedMemory(){return this.tilingScheme?Math.round(this._allTiles.reduce((e,t)=>e+t.usedMemory,0)):null}getUsedMemoryForLayerView(e){let t=0;const i=this._layerClassFromLayerView(e),r=this.getLayerIndexByUID(i,e.uid);return null!=r&&this._allTiles.forAll(e=>t+=e.getUsedMemoryForLayer(i,r)),t}get renderPatchBorders(){return this._renderer.renderPatchBorders}set renderPatchBorders(e){this._renderer.renderPatchBorders=e}get visualizeNormals(){return this._renderer.visualizeNormals}set visualizeNormals(e){this._renderer.visualizeNormals=e}get renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){}checkAllTilesWaterproofness(){if(!Ee)return;const e=this._rootTiles;if(null==e)return;const t=e=>e?.renderData?.geometry?.indices?.length>0,i=(e,i)=>{t(e)&&console.error("Tile[",e.lij,"] has geometry although parent[",i.lij,"] has geom")},r=e=>{if(e.intersectsClippingArea)if(e.renderData&&!e.renderData.geometryState&&console.error("Tile[",e.lij,"] has renderData but not geometryState"),e.renderData&&!e.renderData.geometry&&console.error("Tile[",e.lij,"] has renderData but not geometryInfo"),!e.renderData?.geometry||(e.renderData.geometry.indices?.length??0)>0||console.error("Tile[",e.lij,"] has renderData but no indices - geometryInfo: ",e.renderData.geometry),t(e)){e.checkGeometryWaterproofness();for(const t of e.children)i(t,e)}else if(e.leaf)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.leaf)for(const a of e.children)s(a)};for(const a of e)r(a),s(a)}get isGlobal(){return this._isGlobal}get isGeographic(){return this._isGeographic}get isWebMercator(){return this._isWebMercator}get isWebMercatorOnPlateCarree(){return this._isWebMercatorOnPlateCarree}isEastEndWrap(e){return this._isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this._isGlobal&&0===e[2]}lijEastEnd(e){return 1<<e+(this._isGeographic?1:0)}wrapEastWest(e){const t=this.lijEastEnd(e[0]),i=e[2];if(0<=i&&i<t)return e;if(!this._isGlobal)return null;const r=(i+(i<0?t:0))%t;return[e[0],e[1],r]}enableInternalChecks(e){Le(e)}enableWaterproofnessChecks(e){Pe(e)}static cleanupTerrainSurface(){et.prune()}};e([v()],Ye.prototype,"_renderer",void 0),e([v({constructOnly:!0})],Ye.prototype,"_scaleRangeQueries",void 0),e([v({constructOnly:!0})],Ye.prototype,"view",void 0),e([v({constructOnly:!0})],Ye.prototype,"overlayManager",void 0),e([v({constructOnly:!0})],Ye.prototype,"terrainTextureCompressionTracker",void 0),e([v()],Ye.prototype,"_hasPendingUpdates",void 0),e([v()],Ye.prototype,"_asyncWorkItems",void 0),e([v()],Ye.prototype,"_allTilesDirty",void 0),e([v()],Ye.prototype,"_allTilesSorted",void 0),e([v()],Ye.prototype,"_viewChanged",void 0),e([v({type:Number})],Ye.prototype,"heading",void 0),e([v()],Ye.prototype,"_splitLimits",void 0),e([v({readOnly:!0})],Ye.prototype,"_watchUpdatingTracking",void 0),e([v()],Ye.prototype,"_frameTask",void 0),e([v()],Ye.prototype,"demResolution",null),e([v({readOnly:!0})],Ye.prototype,"snapLevel",null),e([v({readOnly:!0})],Ye.prototype,"lodSnappingEnabled",null),e([v()],Ye.prototype,"_userClippingExtent",null),e([v()],Ye.prototype,"_rootTilesExtent",void 0),e([v({readOnly:!0})],Ye.prototype,"extent",null),e([v({readOnly:!0})],Ye.prototype,"groundExtent",null),e([v({readOnly:!0})],Ye.prototype,"_tilingSchemeExtent",null),e([v({readOnly:!0})],Ye.prototype,"updating",null),e([v({readOnly:!0})],Ye.prototype,"running",null),e([v(Y)],Ye.prototype,"updatingProgress",void 0),e([v({readOnly:!0})],Ye.prototype,"updatingProgressValue",null),e([v()],Ye.prototype,"_maxNumUpdating",void 0),e([v()],Ye.prototype,"baseOpacity",null),e([v()],Ye.prototype,"hasCompositeBlendMode",void 0),e([v({readOnly:!0})],Ye.prototype,"viewingMode",null),e([v()],Ye.prototype,"maxTextureScale",void 0),e([v({readOnly:!0})],Ye.prototype,"ready",null),e([v({value:1})],Ye.prototype,"renderOrder",null),e([v({readOnly:!0})],Ye.prototype,"rootTiles",null),e([v()],Ye.prototype,"_rootTiles",void 0),e([v({readOnly:!0})],Ye.prototype,"spatialReference",null),e([v({type:t})],Ye.prototype,"backgroundColor",null),e([v({value:!1})],Ye.prototype,"slicePlaneEnabled",null),e([v({readOnly:!0})],Ye.prototype,"tilingScheme",void 0),e([v({readOnly:!0})],Ye.prototype,"tilingSchemeLocked",null),e([v({readOnly:!0})],Ye.prototype,"tilingSchemeLogic",void 0),e([v()],Ye.prototype,"wireframe",null),e([v({value:!1})],Ye.prototype,"suspended",null),e([v()],Ye.prototype,"fadeDuration",null),e([v()],Ye.prototype,"visibleElevationBounds",void 0),e([v()],Ye.prototype,"rootTileElevationBounds",void 0),e([v()],Ye.prototype,"_layerViewsDirty",void 0),e([v()],Ye.prototype,"renderPatchBorders",null),e([v()],Ye.prototype,"visualizeNormals",null),e([v()],Ye.prototype,"renderingDisabled",null),Ye=ze=e([w("esri.views.3d.terrain.TerrainSurface")],Ye);const Xe=Ye,Ke=b(),Je=G(),Ze=D(),et=new u,tt=new Q("ground"),it={spatialReference:null,extent:null,scale:0};function rt(e,t,i){for(const r of e){if(!r.containsPointXY(t,i))continue;let e=r;for(;e&&!e.renderData;){const r=(t>e.extentMidX?1:0)+(i<e.extentMidY?2:0);e=e.children[r]}const s=e?.renderData?.geometryState.samplerData??null;return J(t,i,s)}return null}class st{constructor(e){this.capacity=e,this._head=0,this._tail=0,this._data=new Array(e)}push(e){const t=this._tail;if(!(t<this.capacity))throw new Error("Queue full");this._data[t]=e,this._tail=t+1}pushAll(e){const t=e.length;if(0===t)return;const i=this._tail;if(!(i+t<=this.capacity))throw new Error("Queue full");for(let r=0;r<t;++r)this._data[i+r]=e[r];this._tail=i+t}pop(){const e=this._head;if(e<this._tail){const t=this._data[e];return this._head=e+1,t}}get empty(){return this._head>=this._tail}get full(){return this._tail>=this._data.length}}function at(e,t){!e.leaf||e.level<he||ht(e,e=>{t&&nt(e);const i=ot(e);if(e.maxLevelDeltaNeighborCount++,i){let t=e.parent;for(;t;){const e=ot(t);if(t.unmergableChildCount++,!e)break;t=t.parent}}})}function nt(e){if(e.hasPendingUpdate(1))return;let t=e.parent;for(;t?.resetPendingUpdate(4);)t=t.parent;e.resetPendingUpdate(4),e.leaf&&e.setPendingUpdate(1),e.level<he||ht(e,e=>{nt(e)})}function lt(e){e.level<he||ht(e,e=>{if(e.maxLevelDeltaNeighborCount--,0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount){let t=e.parent;for(;t&&(t.unmergableChildCount--,ot(t));)t=t.parent}})}function ot(e){return 0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount}function ht(e,t){if(e.level<he)return;const i=e.level-he,r=e.lij[1]>>he,s=e.lij[2]>>he,a=e=>e.leaf||e.level===i;for(let n=0;n<4;++n){const l=e.findNeighborTile(_e[n],a);if(!l||l.level!==i)continue;const o=l.lij;o[1]===r&&o[2]===s||t(l)}}export{Xe as default};
5
+ import{__decorate as e}from"tslib";import t from"../../../Color.js";import{difference as i}from"../../../core/arrayUtils.js";import r from"../../../core/CollectionFlattener.js";import{toConst as s}from"../../../core/compilerUtils.js";import a from"../../../core/Evented.js";import"../../../core/has.js";import n from"../../../core/Logger.js";import{clamp as l}from"../../../core/mathUtils.js";import{destroyMaybe as o}from"../../../core/maybe.js";import{MemCachePool as h}from"../../../core/MemCachePool.js";import d from"../../../core/ObjectPool.js";import u from"../../../core/PooledArray.js";import{throwIfAborted as p,isAbortError as c,isAborted as g}from"../../../core/promiseUtils.js";import{watch as _,syncAndInitial as m,sync as f,initial as y}from"../../../core/reactiveUtils.js";import{getMetersPerUnitForSR as T}from"../../../core/unitUtils.js";import{property as v}from"../../../core/accessorSupport/decorators/property.js";import{subclass as w}from"../../../core/accessorSupport/decorators/subclass.js";import{i as S,c as C}from"../../../chunks/vec32.js";import{create as b}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as x}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as E}from"../../../geometry/ellipsoidUtils.js";import L from"../../../geometry/SpatialReference.js";import{getProjector as P}from"../../../geometry/projection/projectors.js";import{projectPointToVector as U}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as M}from"../../../geometry/projection/projectVectorToVector.js";import{create as D,equals as R,intersection as j,intersectsSphere as B,empty as I,expand as k}from"../../../geometry/support/aaBoundingRect.js";import{create as A,copy as V}from"../../../geometry/support/frustum.js";import{isPlateCarree as O}from"../../../geometry/support/spatialReferenceUtils.js";import{h as q,c as G,a as N}from"../../../chunks/sphere.js";import{ElevationQueryTileCache as F}from"../../../layers/support/ElevationQueryTileCache.js";import{isBaseLayer as W}from"../../../layers/support/layerUtils.js";import{debugFlags as H}from"../support/debugFlags.js";import{ElevationRange as $}from"../support/ElevationRange.js";import{ElevationUpdateEvent as Q}from"../support/ElevationUpdateEvent.js";import{toBoundingRect as z}from"../support/extentUtils.js";import{updatingProgress as Y}from"../support/updatingProperties.js";import{ElevationBounds as X}from"./ElevationBounds.js";import{ElevationData as K,sampleElevation as J}from"./ElevationData.js";import{create as Z}from"./ExtentHelper.js";import{LayerClasses as ee}from"./LayerClass.js";import{OverlayManager as te}from"./OverlayManager.js";import{PlanarPatch as ie}from"./PlanarPatch.js";import{ScaleRangeQueries as re}from"./ScaleRangeQueries.js";import{SphericalPatch as se}from"./SphericalPatch.js";import{SplitLimits as ae}from"./SplitLimits.js";import{maxRootTiles as ne,tooManyRootTilesAfterChangeError as le,tooManyRootTilesForLayerError as oe,maxTileNeighborLevelDelta as he,maxMemoryLodBias as de}from"./TerrainConst.js";import{TerrainRenderer as ue}from"./TerrainRenderer.js";import pe from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as ce,isVectorTileLayerView as ge,neighborEdgeIndices as _e,internalAssert as me,oppositeEdge as fe,isSurfaceLayerView as ye,isGroupLayerView as Te,isMapTileLayerView as ve,isBlendableLayerView as we,isElevationLayerView as Se,releaseTerrainData as Ce,enableTerrainInternalChecks as be,oppositeCorner as xe,enableWaterproofTests as Ee,enableInternalTerrainChecks as Le,enableTerrainWaterproofChecks as Pe,neighborCornerIndices as Ue}from"./terrainUtils.js";import{Tile as Me,lijEquals as De}from"./Tile.js";import{printAllocations as Re}from"./TilePerLayerInfo.js";import{IteratorPreorder as je,IteratorPostorder as Be,compareTilesByLij as Ie,hasLoadableSiblings as ke,sortTilesByPOI as Ae}from"./tileUtils.js";import{TilingSchemeLogic as Ve}from"./TilingSchemeLogic.js";import{UpsampleInfo as Oe}from"./UpsampleInfo.js";import{isCompositeBlendMode as qe,blendModeFromString as Ge}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{hasLayerBasedScaleVisibility as Ne}from"../../support/layerViewUtils.js";import{ImmediateTask as Fe,TaskPriority as We,noBudget as He}from"../../support/Scheduler.js";import{TextureCompressionTracker as $e}from"../../support/TextureCompressionTracker.js";import{Yield as Qe}from"../../support/Yield.js";var ze;let Ye=class extends a.EventedAccessor{static{ze=this}get allTiles(){return s(this._allTiles)}get demResolution(){const{_allTiles:e,tilingScheme:t}=this;if(0===e.length)return{min:1,max:1};const i=T(t.spatialReference);let r=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY;for(const a of e){const e=t.resolutionAtLevel(a.level)*i;r=Math.min(r,e),s=Math.max(s,e)}return{min:r,max:s}}constructor(e){super(e),this.terrainTextureCompressionTracker=new $e,this._iteratorPool=new d(je,e=>e.remove=()=>this._iteratorPool.release(e)),this._postorderIterator=new Be,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._usedMemory=null,this._performanceInfo=new pe,this._viewChanged=!1,this.heading=0,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=b(),this._eyePosSurfaceSR=b(),this._splitLimits=new ae,this._frustum=A(),this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._watchUpdatingTracking=new x,this._frameTask=Fe,this._allTiles=new u,this._upsampleInfoPool=new d(Oe),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=D(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=L.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationBounds=new X(1/0,-1/0),this.rootTileElevationBounds=new X(1/0,-1/0),this._projectorCache=new Map,this._radiusModifier=Math.cos(Math.PI/16/16),this._tilingSchemeSpatialReference=null,this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._oneBatchPerFrameTask=!0,this._layerViewsDirty=!1,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._isWebMercator=!1,this._isWebMercatorOnPlateCarree=!1;const t=e.view;this.overlayManager=new te({...e,surface:this}),this._isGlobal=!t.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?se:ie,this._ellipsoid=E(t.spatialReference),this._renderer=new ue(this.overlayManager.renderer,t.stage,this._allTiles,this._ellipsoid.radius,this.terrainTextureCompressionTracker,t.resourceController.memoryController),Ne()||(this._scaleRangeQueries=new re)}initialize(){const e=this.view,t=e.resourceController,i=t.memoryController;this._tileCache=new h((e,t)=>i.newCache(e,t),"terrain-tile"),this._upsampleMapCache=i.newCache("terrain-upsample",e=>e.unloadMapData()),this._elevationQueryCache=new F(i.newCache("elevation-query"));const s=this.overlayManager;this.addHandles([_(()=>s.renderer.isEmpty,()=>this._evaluateTransparency()),_(()=>this.renderer.visible,e=>this.suspended=!e),_(()=>this.heading,e=>{this._renderer.updateHeading(e),this._updateTileTextures(0)}),_(()=>({heading:e.camera?.heading,state:e.state?.mode}),({heading:e,state:t})=>{if(null==e)return;if(this.isGlobal&&this.isGeographic||this.isWebMercatorOnPlateCarree)return void(this.heading=90*Math.round(e/90)%360);const i=Math.round(e)%360,r=Math.abs(i-this.heading);(2===t||Math.min(r,360-r)>=30)&&(this.heading=i)})],"overlayManager"),this.addHandles([_(()=>this.baseOpacity,()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?1:2)},m),_(()=>this.hasCompositeBlendMode,()=>this._updateTileTextures(this._evaluateTransparency()?1:2),m),_(()=>this.backgroundColor,(e,t)=>{e?.equals(t)||(this._handleLayerViewChanges(),this._renderer.updateTileBackground(e))},f),_(()=>this.snapLevel,()=>this._viewChanged=!0,f),_(()=>this.view.pointsOfInterest,e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add(()=>e.focus?.renderLocation,()=>this._allTilesSorted=!1)}),_(()=>H.TERRAIN_TILE_TREE_SHOW_TILES,t=>{t&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then(({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&H.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))}):t||(this._treeDebugger=o(this._treeDebugger))},y)]);const{spatialReference:a}=e;this._extentHelper=Z(this.viewingMode,{layers:e.map.allLayers,layerViews:e.allLayerViews,viewSpatialReference:a});const n=new r({getCollections:()=>e.defaultsFromMap?.mapCollections?.map(({layers:e})=>e),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}),l=new Ve({layers:n,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set("tilingSchemeLogic",l),this._updateTilingScheme(),this._elevationDataRequester=t.createStreamDataRequester(0),this._mapDataRequester=t.createStreamDataRequester(1);const d=t.scheduler;this._frameTask=d.registerTask(We.TERRAIN_SURFACE,this),this.addHandles([_(()=>this._extentHelper.stencilEnabledExtents,e=>this._renderer.setStencilEnabledLayerExtents(e),y),_(()=>this.tilingSchemeLogic.tilingScheme,()=>this._updateTilingScheme(),f),_(()=>this.extent,()=>this._updateRootTiles(),y),e.on("resize",()=>this._viewChangeUpdate()),_(()=>{const t=e.state;return[this._lodBias,this.lodSnappingEnabled,e.quality,t.camera,t.contentCamera,t.fixedContentCamera]},()=>this._viewChangeUpdate(),m),_(()=>e.qualitySettings?.fadeDuration,e=>this._renderer.textureFadingEnabled=e>0,y),_(()=>e.qualitySettings?.physicallyBasedRenderingEnabled,e=>this._renderer.pbrMode=e?5:0,y),_(()=>e.qualitySettings?.tiledSurface.elevationLevelDelta,()=>this._updateAllTileGeometries()),_(()=>this._userClippingExtent,()=>this._updateClippingExtent(),f)]),this.addHandles(e.allLayerViews.on("after-changes",()=>this._layerViewsDirty=!0)),this._layerViewsDirty=!0,this._handleLayerViewChanges(),this._renderer.updateTileBackground(this.backgroundColor)}clearHandles(){this._watchUpdatingTracking?.removeAll(),this.removeAllHandles(),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear()}destroy(){this._frameTask.remove(),this._frameTask=Fe,this._watchUpdatingTracking?.destroy(),this._removeAllTiles(),this._set("tilingSchemeLogic",o(this.tilingSchemeLogic)),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear(),this._elevationDataRequester=null,this._mapDataRequester=null,this._set("overlayManager",o(this.overlayManager)),this._tileCache=o(this._tileCache),this._allTiles.prune(),Me.prune(),this._treeDebugger=o(this._treeDebugger),this._renderer.destroyed||this._renderer.destroy(),this._renderer=null,this._iteratorPool=o(this._iteratorPool),this._upsampleMapCache=o(this._upsampleMapCache),this._elevationQueryCache=o(this._elevationQueryCache),this._set("view",null),this._extentHelper=o(this._extentHelper),this._upsampleInfoPool=o(this._upsampleInfoPool),Re(),this._layerViews.forEach(e=>e.length=0),this._performanceInfo=null}get renderer(){return this._renderer}get frustum(){return this._frustum}get snapLevel(){if(this.lodSnappingEnabled){const{view:e,tilingScheme:t}=this,i=e.scale;if(t&&i){const r=t.levelAtScale(i)+e.qualitySettings.tiledSurface.lodBias,s=t.getMaxLod();return r<=0?null:Math.min(r,s||1/0)}}return null}get lodSnappingEnabled(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get hasStencilEnabledExtents(){return this._extentHelper.stencilEnabledExtents.length>0}get _userClippingExtent(){const{spatialReference:e}=this,t=this.view?.clippingArea;if(null==t||null==e)return null;const i=D(),r=z(t,i,e)?i:null,s=this._get("extent");return R(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get extent(){const e=j(this.groundExtent,this._userClippingExtent,D()),t=this._get("extent");return R(e,t)?t:e}get groundExtent(){return null!=this._tilingSchemeExtent?this._tilingSchemeExtent:this._rootTilesExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),!!((this.running||this._watchUpdatingTracking?.updating||this._asyncWorkItems>0)&&this.ready&&!this.suspended||this.overlayManager?.updating||this.terrainTextureCompressionTracker.compressing)}get running(){return(this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||!this._allTilesSorted||this._layerViewsDirty||this._scaleRangeQueries?.updating||this._frameTask.updating)&&this.ready&&!this.suspended}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get baseOpacity(){return this.view?.map?.ground?.opacity??1}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return null!=this._rootTiles}set renderOrder(e){this._renderer.renderOrder=e,this._set("renderOrder",e)}get rootTiles(){return this._rootTiles}get spatialReference(){return this.tilingScheme?.spatialReference??null}get backgroundColor(){return this.view?.map?.ground?.surfaceColor}set backgroundColor(e){this.view.map.ground.surfaceColor=e}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set("slicePlaneEnabled",e),this._evaluateTransparency()}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}get wireframe(){return this._renderer?.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}get opaque(){return 0===this._renderer.transparency}get invisible(){return 3===this._renderer.transparency}set suspended(e){this._set("suspended",e),this._viewChangeUpdate()}get fadeDuration(){return this.view.qualitySettings.fadeDuration??0}intersect(e,t,i,r){this._renderer.intersect(e,t,i,r)}getElevationLevelDelta(e){return e<4?3:this.view.qualitySettings.tiledSurface.elevationLevelDelta}getElevation(e,t,i,r){const s=this._rootTiles;if(!s?.length)return null;if(0===s[0].layerInfo[0].length)return null;let a=this._elevationProjectorCache.get(r);if(void 0===a&&(a=P(r,this._spatialReference)??null,this._elevationProjectorCache.set(r,a)),null==a)return n.getLogger(this).error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;const l=S(Ke,e,t,i);a(l,0,l,0);return rt(s,l[0],l[1])}getElevations(e,t,i){const r=this._rootTiles,s=r?r[0].layerInfo[0].length:0;if(r?.length&&0!==s)for(let a=0;a<t;++a){const t=3*a;i(a,rt(r,e[t],e[t+1]))}else for(let a=0;a<t;++a)i(a,null)}getLayerIndexByUID(e,t){return this._layerIndexByUid[e].get(t)}getScale(e){if(!this.tilingScheme)return null;if(!U(e,Ke,this.spatialReference))return n.getLogger(this).error("TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system"),null;const t=this._rootTiles;if(null!=t)for(const i of t)if(i?.containsPoint(Ke)){let e=i;for(;e.children[0]&&!e.rendered;){const t=e.children[0].extent;let i=0;Ke[0]>t[2]&&(i+=1),Ke[1]<t[1]&&(i+=2),e=e.children[i]}return this._getLodBiasCorrectedScale(e.level)}return 1/0}_ensureProjector(e){const t=this._projectorCache.get(e);if(t)return t;const i=P(e,this._tilingSchemeSpatialReference)??null;return this._projectorCache.set(e,i),i}getSphereElevationBounds(e,t){const i=this._ensureProjector(t);if(null==i)return n.getLogger(this).error("TerrainSurface.getSphereElevationBounds(): could not project given point to tiling scheme coordinate system"),null;q(e,Je);const r=N(Je);i(r,0,r,0);const s=new $,a=this._rootTiles;if(null!=a){const e=[];for(const i of a)e.push(i);let t=0;for(;t<e.length;){const i=e[t];if(++t,!B(i.extent,Je))continue;const r=i.children;if(null==r[0]||i.rendered)s.expandElevationRangeValues(i.elevationBoundsMin,i.elevationBoundsMax);else for(const t of r)e.push(t)}}return s}getRootElevationBounds(){return new $(this.rootTileElevationBounds.min,this.rootTileElevationBounds.max)}getLowerBoundRadius(){const e=(this._ellipsoid.radius+this.visibleElevationBounds.min)*this._radiusModifier;return Math.min(e,this._ellipsoid.radius)}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!U(e,N(Je),this.spatialReference))return n.getLogger(this).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;Je[3]=t;let i=null;const r=e=>{if(e&&B(e.extent,Je)){const t=e.children;if(t[0]&&!e.rendered)for(const e of t)r(e);else{const t=this._getLodBiasCorrectedScale(e.level);i=null==i?t:Math.min(i,t)}}},s=this._rootTiles;if(null!=s)for(const a of s)r(a);return i}queryVisibleScaleRange(e,t,i,r){if(!this._scaleRangeQueries)return;const s=t?this.tilingScheme.levelAtScale(t):0,a=i?this.tilingScheme.levelAtScale(i):1/0,n=this._lodBias;this._scaleRangeQueries.queryVisibleLevelRange(e,s+n,a+n,r)}_evaluateTransparency(){const e=this.baseOpacity,t=this.overlayManager.renderer.isEmpty,i=this._renderer.transparency,r=this._isFullyTransparent?t?3:2:e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?0:1;return this._renderer.transparency=r,i!==r}_updateTilingScheme(){const e=this.tilingSchemeLogic.tilingScheme;if(!(e!==this.tilingScheme))return;ce(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();const t=e?.spatialReference??L.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateCarree=this._isWebMercator&&O(this.view?.renderSpatialReference),this._isGeographic=t?.isGeographic??!1,this._set("tilingScheme",e),this._tilingSchemeSpatialReference=this.tilingScheme?.spatialReference,this._projectorCache.clear(),this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.tileSize=e.pixelSize,this.overlayManager.spatialReference=e.spatialReference,this._updateRootTiles())}static{this._tileMemcacheKey="TerrainTileMemcache"}_acquireTile(e,t,i,r){const s=this._tileCache.pop(ze._tileMemcacheKey);return s?(s.init(e,t,i,r,this),s):new this._tileConstructor(e,t,i,r,this)}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){const{extent:e,tilingScheme:t}=this;if(!t)return;const r=Ze;let s=t.rootTilesInExtent(e,r,5*ne);if(null!=this._rootTiles){if(s.length>ne)return void n.getLogger(this).warn(le);const e=this._rootTiles.map(e=>e.lij),t=i(e,s,De);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this._rootTiles.filter(e=>!(t.removed.findIndex(t=>De(t,e.lij))>-1)||(this._purgeTile(e),!1));t.added.forEach(t=>e.push(this._newRootTile(t))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,s.length>ne&&(n.getLogger(this).warn(oe),s=t.rootTilesInExtent(e,r,ne)),this._setRootTiles(s.map(e=>this._newRootTile(e)));R(r,this._rootTilesExtent)||(this._rootTilesExtent=D(r)),this.renderer.visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange("ready"),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness()}_updateAllTileGeometries(){const e=this._allTiles.filter(e=>e.loaded&&e.intersectsClippingArea);e.sort(Ie),e.forEach(e=>this._renderer.updateTileGeometryState(e)),e.forEach(e=>e.renderData.updateNeighborData()),this._updateTilesGeometries(e),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){if(0===e.length)return;e.sort(Ie);const t=this.renderer;e.forEach(e=>t.updateGeometryIfNeeded(e)),e.forEach(e=>this._pendingTilesForElevationUpdateEvent.add(e))}_shouldSplit(e){return 1===e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.snapLevel)}_newRootTile(e){const t=this._acquireTile(0,e[1],e[2],null);return this._shouldSplit(t)&&t.setPendingUpdate(1),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationBounds(),t}_setRootTiles(e){if(this._rootTiles=e,this._allTiles.clear(),null!=e){const t=this._iteratorPool.acquire();for(t.reset(e);!t.done;)this._allTiles.push(t.next());t.remove()}this._renderer.setRootTiles(this._rootTiles),this._updateTilesVisibility(e),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles})}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.suspended&&this.tilingScheme&&this.renderer.visible&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this._rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.extent)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(null==e)return;const t=ke(e),i=this.visibleElevationBounds;let r=t?i.min:1/0,s=t?i.max:-1/0;const a=this.extent,n=this.view.state.contentCamera.viewProjectionMatrix;this.setTileTreeDirty();const l=this._iteratorPool.acquire();for(l.reset(e);!l.done;){const e=l.next();e.updateClippingStatus(a)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e),e.computeVisibility(),e.updateScreenDepth(n),e.renderData&&(r=Math.min(e.elevationBoundsMin,r),s=Math.max(e.elevationBoundsMax,s))}l.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._updatePendingTileGeometries(),isFinite(r)&&isFinite(s)&&(i.min!==r||i.max!==s)&&(this.visibleElevationBounds=new X(r,s))}_updateRootTileElevationBounds(){let e=1/0,t=-1/0;const i=this._rootTiles;null!=i&&i.forEach(({elevationBoundsMin:i,elevationBoundsMax:r})=>{e=Math.min(e,i),t=Math.max(t,r)});const r=this.rootTileElevationBounds;r.min===e&&r.max===t||(this.rootTileElevationBounds=new X(e,t))}_updateViewDependentParameters(){const{camera:e,contentCamera:t}=this.view.state,i=Math.tan(.5*t.fovX),r=Math.tan(.5*t.fovY),s=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=i,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=s/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=s/e.height*this.maxTextureScale*a,this._splitLimits.maxLod=this.tilingScheme.getMaxLod(),this._splitLimits.angledSplitBias=this.view.qualitySettings.tiledSurface.angledSplitBias,this.view.state.fixedContentCamera?this._splitLimits.frustum=V(this._splitLimits.frustum??A(),t.frustum):this._splitLimits.frustum=null,V(this._frustum,e.frustum),C(this._eyePosRenderSR,t.eye),M(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateTileGeometryState(e){e.updateVisibility();this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this.setMemoryDirty()}_markAllTileNeighborsForUpdate(e){e.forEachLoadedNeighbor(e=>{this._layerViews[1].some(ge)&&e.setPendingUpdate(32),this._pendingTilesToUpdate.add(e)})}_updateTileTexture(e,t){const i=e.resetPendingUpdate(32)?32:!!e.resetPendingUpdate(16)&&16;i&&(this._renderer.updateTileTexture(e,i),this._usedMemory=null,t.madeProgress())}_emitElevationUpdateEventForTiles(){if(!this._shouldEmitChangeEvent)return;const e=tt.extent;I(e),this._pendingTilesForElevationUpdateEvent.forEach(t=>k(e,t.extent,e)),this._pendingTilesForElevationUpdateEvent.clear(),tt.spatialReference=this.spatialReference,this.emit("elevation-change",tt),this._shouldEmitChangeEvent=!1}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this.renderer.processScaleRangeQueries(this._scaleRangeQueries,e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateAllTilesStatus(e),this._sortTiles(e);const t=!this.view.state.fixedContentCamera;if(this._mergeAndSplit(e,t),this._updateElevation(e),this._updateTextures(e),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty(),this._updatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&e.hasProgressed&&this.requestUpdate(),this.notifyChange("updatingProgressValue"),be&&this._checkTileInvariant(),!e.hasProgressed)return Qe}_checkTileInvariant(){const e=new Map;this._allTiles.forAll(t=>e.set(t,new Set)),this._allTiles.forAll(t=>{if(ce(t.rendered===t.leaf,` rendered ${t.rendered} != ${t.leaf} leaf`),!t.leaf){const e=e=>0===e.unmergableChildCount&&0===e.maxLevelDeltaNeighborCount,i=t.children.reduce((t,i)=>t+(e(i)?0:1),0);if(ce(t.unmergableChildCount===i,` Tile[${t.lij.toString()}] unmergeable child count mismatch: actual ${t.unmergableChildCount} vs ${i}`),t.hasPendingUpdate(4)){ce(!t.hasPendingUpdate(1),"Tile can be both split and merge at the same time");for(const e of t.children)ce(e.leaf||e.hasPendingUpdate(4),"Child of tile to merge must also merge")}}for(let i=0;i<4;++i){if(t.rendered){const e=t.renderData?.geometryState.edgePeerNeighbors[i];if(null!=e){{const r=t.level-e.level<=he;r||(console.log(`tile level delta [${t.lij.toString()}] vs [${e.lij.toString()}] > ${he} (edge[${i}])`),ce(r,`tile level delta [${t.level}] vs [${e.level}] > ${he}`))}ce(t.level-e.level<=he,`Max tile lod delta exceeded: [${t.lij.toString()}] vs [${e.lij.toString()}]`)}}const r=t.level-he,s=e=>e.leaf||e.level===t.level,a=t.findNeighborTile(_e[i],s);if(null!=a){if(t.leaf&&t.level>=he){let i=a;for(;t.level-i.level<he;)i=i.parent;const s=[r,t.lij[1]>>he,t.lij[2]>>he];if(!De(s,i.lij)){const r=e.get(i);ce(!r.has(t),"Cannot already have neighbor"),r.add(t)}}ce(a.rendered||a.level===t.level,"Non-same-level-neighbor of rendered must be rendered"),ce(t.level-a.level<=he,`Tile level delta [${t.level}] vs [${a.level}] > ${he}`)}}}),this._allTiles.forAll(t=>{const i=t.maxLevelDeltaNeighborCount,r=e.get(t);ce(i===r.size,`Tile[${t.lij.toString()}] merge-blocker mismatch: actual ${i} vs ${r.size}`)})}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;const t=new st(this._allTiles.length);t.pushAll(this._rootTiles);const i=this.snapLevel,r=this._splitLimits,s=this._eyePosRenderSR;this._allTiles.forAll(e=>{e.maxLevelDeltaNeighborCount=0,e.unmergableChildCount=0});const a=this.view.state.contentCamera.viewProjectionMatrix;for(;!t.empty;){const e=t.pop(),n=e.parent,l=null!=n&&n.hasPendingUpdate(4),o=l?4:e.shouldSplit(r,s,i),h=1===o;e.leaf?at(e,h):t.pushAll(e.children),l?(e.resetPendingUpdate(1),e.leaf||e.setPendingUpdate(4),this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(a)):h?(e.resetPendingUpdate(4),e.leaf&&e.setPendingUpdate(1)):(e.resetPendingUpdate(1)&&e.updateAgentSuspension(),2===o&&e.updateAgents(0),e.leaf||(e.setPendingUpdate(4),e.resetPendingUpdate(1)))}this.requestUpdate(),(this._shortBatches||!this._oneBatchPerFrameTask)&&this._updatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||!this.view.pointsOfInterest?.focus||(Ae(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger&&this._treeDebugger.update(),e.madeProgress())}_markTileToUpdate(e){me(e.loaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForUpdate(e))}_updatePendingTileGeometries(){const e=this._pendingTilesToUpdate,t=Array.from(e.keys()).filter(e=>e.loaded&&e.intersectsClippingArea);if(0===t.length)return void e.clear();const i=(i,r)=>{!r?.loaded||!r.intersectsClippingArea||r.level<i.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(Ie);const r=t.length;for(let s=0;s<r;++s){const r=t[s];me(r.loaded),me(r.intersectsClippingArea);const a=r.renderData;a.updateNeighborData();const n=a.dirtyEdgeResolutions,l=a.geometryState,o=e=>{const t=Ue[e];i(r,l.cornerPeerNeighbors[e]?.findCorner(xe(t),e=>e.loaded))};for(let t=0;t<4;++t)if(n&1<<t){const s=a.geometryState.edgePeerNeighbors[t];s&&s?.level>=r.level&&s.forAllSubtreeOnSide(fe(_e[t]),t=>!(!t.loaded||!t.intersectsClippingArea)&&(me(e.has(t)||Ie(r,t)<0),i(r,t),!0)),o((t+1)%4),o(t)}}e.clear(),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,be&&Ee&&this.checkAllTilesWaterproofness()}_mergeAndSplit(e,t){if(this.suspended||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let i=!1;const r=this.view.state.fixedContentCamera;let s=!1;for(;!e.done;){s=!0;let a=!1;const n=!this._allTiles.some(s=>{if(!i&&!r&&!s.visible)return e.done;let n=s;if(s.hasPendingUpdate(4)){if(!t||s.unmergableChildCount>0)return e.done;for(s.resetPendingUpdate(4);null!=n.parent&&0===n.parent.unmergableChildCount&&n.parent.resetPendingUpdate(4);)n=n.parent;this._mergeTile(n),a=!0,e.madeProgress()}else if(s.resetPendingUpdate(1)){let t=!0;const i=s.level;if(i>=he){const e=e=>e.leaf||i-e.level<he;for(let r=0;r<4;++r){const a=s.findNeighborTile(_e[r],e);null!=a&&i-a.level===he&&(t=!1,be&&(me(a.leaf),me(a.hasPendingUpdate(1))))}}t?(this._splitTile(s),e.madeProgress(),a=!0):s.setPendingUpdate(1)}return e.done});if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0,!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries()),n){if(!i){i=!0;continue}if(!a)break}else this._allTilesDirty=!0}s?e.madeProgress():this._allTilesDirty=!0,!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries(),this._sortTiles(e)}_updateElevation(e){e.done||(this._allTiles.some(t=>(t.resetPendingUpdate(8)&&(this._updateTileGeometryState(t),this._shortBatches&&this._updatePendingTileGeometries(),e.madeProgress()),e.done)),!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries())}_updateTextures(e){e.done||this._allTiles.some(t=>(this._updateTileTexture(t,e),e.done))}_updateClippingExtent(){this.spatialReference&&(this.overlayManager?.updateOverlayParameters(1),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){const e=this.view.quality;return this.view.qualitySettings.tiledSurface.lodBias-(1-e)*de}_getLodBiasCorrectedScale(e){const t=this.tilingScheme.levels,i=l(e-this._lodBias,0,t.length-1),r=i-Math.floor(i);return t[Math.floor(i)].scale*(1-r)+t[Math.ceil(i)].scale*r}_removeAllTiles(){null!=this._rootTiles&&(this._rootTiles.forEach(e=>this._purgeTile(e)),this._setRootTiles(null),this.notifyChange("ready")),this._allTiles.clear(),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles}),this.renderer.visible=!1}_purgeSubtree(e){const t=e.children;t[0]&&(this._purgeTile(t[0]),this._purgeTile(t[1]),this._purgeTile(t[2]),this._purgeTile(t[3]),e.clearChildren())}_purgeTile(e){e.leaf?lt(e):this._purgeSubtree(e),this._allTiles.removeUnordered(e),this._unloadTile(e),e.dispose(),this._tileCache.put(ze._tileMemcacheKey,e),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles})}_unloadTile(e){this._pendingTilesToUpdate.delete(e),this._pendingTilesForElevationUpdateEvent.delete(e),e.unload()}_splitTile(e){ce(e.leaf,"Tile that is already split should not be split again!"),ce(e.rendered,"Tile marked to split is not rendered"),lt(e);const t=e.createChildren();this._allTiles.pushArray(t),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles}),e.updateAgentSuspension(),ce(e.rendered,"parent should be rendered"),t.forEach(e=>this._loadTile(e)),t.forEach(e=>this._pendingTilesToUpdate.add(e)),this._unloadTile(e),this._markAllTileNeighborsForUpdate(e),this._emitTileScaleChange(e,e.level+1),this._allTilesDirty=!0,this._shortBatches&&this._updatePendingTileGeometries(),t.forEach(e=>at(e,e.hasPendingUpdate(1))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){it.spatialReference=this.spatialReference,it.extent=e.extent,it.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",it)}createTile(e,t,i,r){ce(!!r,"createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.extent),s.updateScreenDepth(this.view.state.contentCamera.viewProjectionMatrix),this._shouldSplit(s)&&s.setPendingUpdate(1),s}get _shortBatches(){return 2!==this.view.state.mode}_mergeTile(e){ce(!e.hasPendingUpdate(1),"_mergeTile sanity check"),ce(!e.leaf,"Cannot merge a leaf"),e.leaf||(this._purgeSubtree(e),ce(!e.renderData,"Merging tile with existing render data?"),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),at(e,!1),this._allTilesDirty=!0,++this._performanceInfo.numMerged)}_loadTile(e){e.load(),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager?.hasOverlays&&this.overlayManager.updateTileOverlayParameters(e)}_handleLayerViewChanges(e=He){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1;const i=new Set;let r=-1;for(let s=this.view.allLayerViews.length-1;s>=0;s--){const e=this.view.allLayerViews.items[s];if(i.add(e.uid),ye(e)||Te(e))if(this._basemapLayerViewHandles.has(e.uid)&&!Te(e)){const i=this._layerClassFromLayerView(e),s=this.getLayerIndexByUID(i,e.uid);null!=s&&((s<r||null==r)&&(t=!0),r=s)}else this._registerTiledLayerView(e),e.layer.loaded&&(t=!0)}this._basemapLayerViewHandles.forEach((e,r)=>{i.has(r)||(this._unregisterTiledLayerView(r),t=!0)}),t&&this._updateTiledLayers(),this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._evaluateTransparency(),e.madeProgress()}get _isFullyTransparent(){if(this.view.map?.ground?.opacity>0)return!1;for(const e of this.view.allLayerViews.items)if(ve(e)&&!W(e.layer)&&0!==e.fullOpacity)return!1;return!0}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if((we(e)||Te(e))&&qe(Ge[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return Se(e)?0:1}_registerTiledLayerView(e){const t=[];if((we(e)||Te(e))&&t.push(_(()=>e.layer.blendMode,()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(2)})),!Te(e)){const i=this._layerClassFromLayerView(e);t.push(_(()=>!e.destroyed&&e.suspended,()=>this._updateTiledLayers())),t.push(_(()=>!e.destroyed&&e.fullOpacity,()=>this._updateTileTextures(2)));const{layer:r}=e;"effectiveScaleRange"in r&&t.push(_(()=>!e.destroyed&&r.effectiveScaleRange,()=>this._restartAllAgents(i))),t.push(e.on("data-changed",()=>{const t=this.getLayerIndexByUID(i,e.uid);null!=t&&this._invalidateLayerData(t,i)}))}this._unregisterTiledLayerView(e.uid),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){const t=this._basemapLayerViewHandles.get(e);if(t){for(const e of t)e.remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;const e=this.view.allLayerViews,t=[[],[]];let i=null;e.forEach(e=>{if(!e.layer||e.suspended||!ye(e)||!e.fullExtent)return;const r=this._layerClassFromLayerView(e);if(1===r){const t=e.displayLevelRange.maxLevel;t!==1/0&&(null===i||t>i)&&(i=t)}t[r].push(e)});for(const r of ee){const e=this._layerViews[r],i=t[r];i.reverse();const s=i.length;let a=e.length!==s;const n=new Array(s),l=new Array(e.length);this._layerIndexByUid[r].clear();for(let t=0;t<s;t++){const s=i[t].uid;this._layerIndexByUid[r].set(s,t);const o=e.indexOf(i[t]);n[t]=o,t!==o&&(a=!0),o>-1&&(l[o]=t)}if(a){const e=this._postorderIterator;for(e.reset(this._rootTiles);!e.done;)e.next().modifyLayers(l,n,r);this._layerViews[r]=i,this._restartAllAgents(r),this._updateTilesVisibility(this._rootTiles)}}this.tilingScheme.ensureMaxLod(i)&&(this._viewChangeUpdate(),this.notifyChange("tilingScheme"))}_restartAllAgents(e){const t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;){const i=t.next();i.restartAgents(e),0===e&&i.computeElevationBounds()}this._updateRootTileElevationBounds()}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll(t=>{t.updateAgents(1),1===e?this.renderer.updateTileTexture(t,16):t.updateRenderData(1,e)}),this._evaluateTransparency()}_invalidateLayerData(e,t){this._allTiles.forAll(i=>i.removeLayerAgent(e,t)),this._allTiles.forAll(i=>i.invalidateLayerData(e,t))}setTileTreeDirty(){this._allTilesDirty=!0}requestRender(e=1){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||ge(s)?this._requestTileData(e,i,s,r):(++this._asyncWorkItems,a.tilemapCache.fetchAvailability(e.level,e.lij[1],e.lij[2],{...r,timeout:6e3}).then(()=>--this._asyncWorkItems).catch(t=>{throw--this._asyncWorkItems,p(r),c(t)||this._dataMissing(e,i,s),t}).then(()=>this._frameTask.schedule(()=>this._requestTileData(e,i,s,r),r.signal)))}_requestTileData(e,t,i,r){if(this.destroying)return Promise.resolve();const s=0===t;return r.requester??=s?this._elevationDataRequester:this._mapDataRequester,s?Se(i)?this._requestElevationTileData(e,i,r):Promise.reject():ve(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{!g(i)&&r&&(this.setMemoryDirty(),this.requestUpdate(),this._elevationDataArrived(e,t,r))},s=i=>{c(i)||(n.getLogger(this).error(`Tile ${e.lij.toString()} layer 0/${t.uid} error ${i}`),this._dataMissing(e,0,t),this.requestUpdate())};return t.fetchElevationTile(e,i).then(e=>this._frameTask.schedule(()=>r(e)),s).finally(()=>--this._asyncWorkItems)}_elevationDataArrived(e,t,i){const r=this._layerIndexByUid[0].get(t.uid);if(null==r)return void n.getLogger(this).warn("TerrainSurface: received data from unknown layer %d %s",0,e.lij.toString());const s=new K(e.lij,e.extent,i);e.dataArrived(r,0,s),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:0});const a=[e],l=e.level,o=this._iteratorPool.acquire();for(o.reset(a);!o.done;){const e=o.next();e.findElevationBoundsForLayer(r,l),e.computeElevationBounds()}0===l&&this._updateRootTileElevationBounds(),o.remove(),this._updateTilesVisibility(a)}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{Ce(s),g(i)||(console.error(`Tile ${e.lij.toString()} layer 1/${t.uid} error ${r}`),this._dataMissing(e,1,t),this.requestUpdate())},s=e=>t=>r(t,e),a=r=>this._frameTask.schedule(()=>{this.requestUpdate(),g(i)?Ce(r):this._mapTileDataArrived(e,t,r)},i.signal,s(r)).catch(s(r)),n=(e,t=null)=>this._frameTask.schedule(()=>r(e,t));return t.fetchTile(e.lij,i).then(a,n).finally(()=>--this._asyncWorkItems)}_mapTileDataArrived(e,t,i){const r=this.getLayerIndexByUID(1,t.uid);if(null==r)return Ce(i),void n.getLogger(this).warn("TerrainSurface: received data from unknown layer");e.dataArrived(r,1,i),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:1})}_dataMissing(e,t,i){const r=this.getLayerIndexByUID(t,i.uid);null!=r?(e.dataMissing(r,t),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:t})):n.getLogger(this).warn("TerrainSurface: received data from unknown layer")}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.leaf&&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}setMemoryDirty(){this._usedMemory=null}get usedMemory(){return this.tilingScheme?(null==this._usedMemory&&(this._usedMemory=this._recalculateUsedMemory()),this._usedMemory??0):0}_recalculateUsedMemory(){return this.tilingScheme?Math.round(this._allTiles.reduce((e,t)=>e+t.usedMemory,0)):null}getUsedMemoryForLayerView(e){let t=0;const i=this._layerClassFromLayerView(e),r=this.getLayerIndexByUID(i,e.uid);return null!=r&&this._allTiles.forAll(e=>t+=e.getUsedMemoryForLayer(i,r)),t}get renderPatchBorders(){return this._renderer.renderPatchBorders}set renderPatchBorders(e){this._renderer.renderPatchBorders=e}get visualizeNormals(){return this._renderer.visualizeNormals}set visualizeNormals(e){this._renderer.visualizeNormals=e}get renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){}checkAllTilesWaterproofness(){if(!Ee)return;const e=this._rootTiles;if(null==e)return;const t=e=>e?.renderData?.geometry?.indices?.length>0,i=(e,i)=>{t(e)&&console.error("Tile[",e.lij,"] has geometry although parent[",i.lij,"] has geom")},r=e=>{if(e.intersectsClippingArea)if(e.renderData&&!e.renderData.geometryState&&console.error("Tile[",e.lij,"] has renderData but not geometryState"),e.renderData&&!e.renderData.geometry&&console.error("Tile[",e.lij,"] has renderData but not geometryInfo"),!e.renderData?.geometry||(e.renderData.geometry.indices?.length??0)>0||console.error("Tile[",e.lij,"] has renderData but no indices - geometryInfo: ",e.renderData.geometry),t(e)){e.checkGeometryWaterproofness();for(const t of e.children)i(t,e)}else if(e.leaf)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.leaf)for(const a of e.children)s(a)};for(const a of e)r(a),s(a)}get isGlobal(){return this._isGlobal}get isGeographic(){return this._isGeographic}get isWebMercator(){return this._isWebMercator}get isWebMercatorOnPlateCarree(){return this._isWebMercatorOnPlateCarree}isEastEndWrap(e){return this._isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this._isGlobal&&0===e[2]}lijEastEnd(e){return 1<<e+(this._isGeographic?1:0)}wrapEastWest(e){const t=this.lijEastEnd(e[0]),i=e[2];if(0<=i&&i<t)return e;if(!this._isGlobal)return null;const r=(i+(i<0?t:0))%t;return[e[0],e[1],r]}enableInternalChecks(e){Le(e)}enableWaterproofnessChecks(e){Pe(e)}static cleanupTerrainSurface(){et.prune()}};e([v()],Ye.prototype,"_renderer",void 0),e([v({constructOnly:!0})],Ye.prototype,"_scaleRangeQueries",void 0),e([v({constructOnly:!0})],Ye.prototype,"view",void 0),e([v({constructOnly:!0})],Ye.prototype,"overlayManager",void 0),e([v({constructOnly:!0})],Ye.prototype,"terrainTextureCompressionTracker",void 0),e([v()],Ye.prototype,"_hasPendingUpdates",void 0),e([v()],Ye.prototype,"_asyncWorkItems",void 0),e([v()],Ye.prototype,"_allTilesDirty",void 0),e([v()],Ye.prototype,"_allTilesSorted",void 0),e([v()],Ye.prototype,"_viewChanged",void 0),e([v({type:Number})],Ye.prototype,"heading",void 0),e([v()],Ye.prototype,"_splitLimits",void 0),e([v({readOnly:!0})],Ye.prototype,"_watchUpdatingTracking",void 0),e([v()],Ye.prototype,"_frameTask",void 0),e([v()],Ye.prototype,"demResolution",null),e([v({readOnly:!0})],Ye.prototype,"snapLevel",null),e([v({readOnly:!0})],Ye.prototype,"lodSnappingEnabled",null),e([v()],Ye.prototype,"_userClippingExtent",null),e([v()],Ye.prototype,"_rootTilesExtent",void 0),e([v({readOnly:!0})],Ye.prototype,"extent",null),e([v({readOnly:!0})],Ye.prototype,"groundExtent",null),e([v({readOnly:!0})],Ye.prototype,"_tilingSchemeExtent",null),e([v({readOnly:!0})],Ye.prototype,"updating",null),e([v({readOnly:!0})],Ye.prototype,"running",null),e([v(Y)],Ye.prototype,"updatingProgress",void 0),e([v({readOnly:!0})],Ye.prototype,"updatingProgressValue",null),e([v()],Ye.prototype,"_maxNumUpdating",void 0),e([v()],Ye.prototype,"baseOpacity",null),e([v()],Ye.prototype,"hasCompositeBlendMode",void 0),e([v({readOnly:!0})],Ye.prototype,"viewingMode",null),e([v()],Ye.prototype,"maxTextureScale",void 0),e([v({readOnly:!0})],Ye.prototype,"ready",null),e([v({value:1})],Ye.prototype,"renderOrder",null),e([v({readOnly:!0})],Ye.prototype,"rootTiles",null),e([v()],Ye.prototype,"_rootTiles",void 0),e([v({readOnly:!0})],Ye.prototype,"spatialReference",null),e([v({type:t})],Ye.prototype,"backgroundColor",null),e([v({value:!1})],Ye.prototype,"slicePlaneEnabled",null),e([v({readOnly:!0})],Ye.prototype,"tilingScheme",void 0),e([v({readOnly:!0})],Ye.prototype,"tilingSchemeLocked",null),e([v({readOnly:!0})],Ye.prototype,"tilingSchemeLogic",void 0),e([v()],Ye.prototype,"wireframe",null),e([v({value:!1})],Ye.prototype,"suspended",null),e([v()],Ye.prototype,"fadeDuration",null),e([v()],Ye.prototype,"visibleElevationBounds",void 0),e([v()],Ye.prototype,"rootTileElevationBounds",void 0),e([v()],Ye.prototype,"_layerViewsDirty",void 0),e([v()],Ye.prototype,"renderPatchBorders",null),e([v()],Ye.prototype,"visualizeNormals",null),e([v()],Ye.prototype,"renderingDisabled",null),Ye=ze=e([w("esri.views.3d.terrain.TerrainSurface")],Ye);const Xe=Ye,Ke=b(),Je=G(),Ze=D(),et=new u,tt=new Q("ground"),it={spatialReference:null,extent:null,scale:0};function rt(e,t,i){for(const r of e){if(!r.containsPointXY(t,i))continue;let e=r;for(;e&&!e.renderData;){const r=(t>e.extentMidX?1:0)+(i<e.extentMidY?2:0);e=e.children[r]}const s=e?.renderData?.geometryState.samplerData??null;return J(t,i,s)}return null}class st{constructor(e){this.capacity=e,this._head=0,this._tail=0,this._data=new Array(e)}push(e){const t=this._tail;if(!(t<this.capacity))throw new Error("Queue full");this._data[t]=e,this._tail=t+1}pushAll(e){const t=e.length;if(0===t)return;const i=this._tail;if(!(i+t<=this.capacity))throw new Error("Queue full");for(let r=0;r<t;++r)this._data[i+r]=e[r];this._tail=i+t}pop(){const e=this._head;if(e<this._tail){const t=this._data[e];return this._head=e+1,t}}get empty(){return this._head>=this._tail}get full(){return this._tail>=this._data.length}}function at(e,t){!e.leaf||e.level<he||ht(e,e=>{t&&nt(e);const i=ot(e);if(e.maxLevelDeltaNeighborCount++,i){let t=e.parent;for(;t;){const e=ot(t);if(t.unmergableChildCount++,!e)break;t=t.parent}}})}function nt(e){if(e.hasPendingUpdate(1))return;let t=e.parent;for(;t?.resetPendingUpdate(4);)t=t.parent;e.resetPendingUpdate(4),e.leaf&&e.setPendingUpdate(1),e.level<he||ht(e,e=>{nt(e)})}function lt(e){e.level<he||ht(e,e=>{if(e.maxLevelDeltaNeighborCount--,0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount){let t=e.parent;for(;t&&(t.unmergableChildCount--,ot(t));)t=t.parent}})}function ot(e){return 0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount}function ht(e,t){if(e.level<he)return;const i=e.level-he,r=e.lij[1]>>he,s=e.lij[2]>>he,a=e=>e.leaf||e.level===i;for(let n=0;n<4;++n){const l=e.findNeighborTile(_e[n],a);if(!l||l.level!==i)continue;const o=l.lij;o[1]===r&&o[2]===s||t(l)}}export{Xe as default};