@arcgis/core 5.2.0-next.42 → 5.2.0-next.44

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 (182) hide show
  1. package/arcade/featureset/sources/FeatureLayerDynamic.js +1 -1
  2. package/assets/esri/core/workers/RemoteClient.js +1 -1
  3. package/assets/esri/core/workers/chunks/0115681a3de6df0aebdf.js +1 -0
  4. package/assets/esri/core/workers/chunks/025caafc70ac26f0a4ed.js +1 -0
  5. package/assets/esri/core/workers/chunks/{d66d58ed5d66520ab1bf.js → 04a167c110fb7811169d.js} +1 -1
  6. package/assets/esri/core/workers/chunks/{72fe7fb03c156f26a589.js → 08e18fb12533fc76e49c.js} +1 -1
  7. package/assets/esri/core/workers/chunks/{2e79fb1b8445b2091cdb.js → 0a0732ba8271d7dc985c.js} +1 -1
  8. package/assets/esri/core/workers/chunks/{e6b5c015205d38abe037.js → 127b111ee53e4b9184f8.js} +1 -1
  9. package/assets/esri/core/workers/chunks/{2d7cfc68a38dabd8898a.js → 176c5eaaa23a479c88e0.js} +1 -1
  10. package/assets/esri/core/workers/chunks/1d1f5578c7d8619f7a46.js +1 -0
  11. package/assets/esri/core/workers/chunks/268637fd6c50264acfc3.js +1 -0
  12. package/assets/esri/core/workers/chunks/296fa9fb80e521c30cb1.js +1 -0
  13. package/assets/esri/core/workers/chunks/{c50e4e8c6188e64e7d45.js → 2974cddb0b0f67df7d2d.js} +1 -1
  14. package/assets/esri/core/workers/chunks/{e9511627418c6864148a.js → 305ee2dd597c48a38e64.js} +1 -1
  15. package/assets/esri/core/workers/chunks/3252da57b800356116af.js +1 -0
  16. package/assets/esri/core/workers/chunks/{fd47ee8598e37fea03fe.js → 384b619854ef8a3f6e94.js} +1 -1
  17. package/assets/esri/core/workers/chunks/3af923abeb6e65c4468f.js +1 -0
  18. package/assets/esri/core/workers/chunks/3f4f1595c8a77d072b04.js +1 -0
  19. package/assets/esri/core/workers/chunks/4f09f208ece2ec1db727.js +1 -0
  20. package/assets/esri/core/workers/chunks/{67468c50ecb1fbedda87.js → 549295a5db9bf1536491.js} +1 -1
  21. package/assets/esri/core/workers/chunks/{284e88805184334396fe.js → 57374213084bef59b776.js} +1 -1
  22. package/assets/esri/core/workers/chunks/{2a8d791aef3123e6a3c4.js → 57970d43cdcc5cf57a30.js} +1 -1
  23. package/assets/esri/core/workers/chunks/{dedf678490572c500a19.js → 5b937c405788fd14be8b.js} +2 -2
  24. package/assets/esri/core/workers/chunks/5f9c4dad6952c4c58ebf.js +1 -0
  25. package/assets/esri/core/workers/chunks/706230b70a36d2e038f7.js +1 -0
  26. package/assets/esri/core/workers/chunks/76713b700e053f8bad29.js +1 -0
  27. package/assets/esri/core/workers/chunks/{90ace5f9b4af1beea6bf.js → 7b6b8d0673976c6c26de.js} +1 -1
  28. package/assets/esri/core/workers/chunks/{321dbc60f44819c2b4de.js → 81d55594cee124040565.js} +1 -1
  29. package/assets/esri/core/workers/chunks/8a01fe8d78ca85ea4784.js +1 -0
  30. package/assets/esri/core/workers/chunks/9114a575b78a7ea18d0f.js +1 -0
  31. package/assets/esri/core/workers/chunks/93e705c1147cc8ceca02.js +1 -0
  32. package/assets/esri/core/workers/chunks/{d082de5dd83bd73d209b.js → 94cebc34e49da1e295ed.js} +1 -1
  33. package/assets/esri/core/workers/chunks/{34fcb776e4de1d870bbd.js → a38a7e3a5aa9294ab918.js} +2 -2
  34. package/assets/esri/core/workers/chunks/a8033e606b2db1ee332d.js +1 -0
  35. package/assets/esri/core/workers/chunks/{6f408397e2c8a2ea9805.js → aea247138617e12b699b.js} +1 -1
  36. package/assets/esri/core/workers/chunks/{26e7884d8639df4d994b.js → b03dcf3d55266745f3d1.js} +1 -1
  37. package/assets/esri/core/workers/chunks/{f1d3cf674b6bea89e122.js → b3cefc1895bfd62fc440.js} +1 -1
  38. package/assets/esri/core/workers/chunks/{ec1a2e68957fae48e60b.js → b75db3b1becf8265ec59.js} +3 -3
  39. package/assets/esri/core/workers/chunks/{82f4aa0533db009b11d8.js → bac4d4a9f3a9b7f6864d.js} +2 -2
  40. package/assets/esri/core/workers/chunks/{2f29f08cddd5add9388e.js → c01a121ebe571a848452.js} +1 -1
  41. package/assets/esri/core/workers/chunks/{c1845682cc9a5aac8703.js → c316234837b7ca406b1c.js} +3 -3
  42. package/assets/esri/core/workers/chunks/c3cd38ca8690286d40d7.js +1 -0
  43. package/assets/esri/core/workers/chunks/c6042825f61cd70d54d8.js +1 -0
  44. package/assets/esri/core/workers/chunks/{0646524250bb9fe82935.js → d8b67ca02cdc1e8191e3.js} +1 -1
  45. package/assets/esri/core/workers/chunks/db416ba3132034e20642.js +1 -0
  46. package/assets/esri/core/workers/chunks/{590e977f8eeb379b86c8.js → e5c19e9b6fa53abdca8c.js} +21 -27
  47. package/assets/esri/core/workers/chunks/f9b2727b41943d83d4ca.js +1 -0
  48. package/assets/esri/core/workers/chunks/{934044f2ef6ce199b399.js → fc880b275f5eaf42171e.js} +1 -1
  49. package/assets/esri/libs/basisu/basis_encoder.wasm +0 -0
  50. package/assets/esri/libs/dxtEncoder/dxt_encoder.wasm +0 -0
  51. package/chunks/Component.glsl.js +2 -2
  52. package/chunks/CutFillTargetDepth.glsl.js +1 -2
  53. package/chunks/Fog.glsl.js +3 -3
  54. package/chunks/GlobalIllumination.glsl.js +21 -21
  55. package/chunks/GlobalIlluminationBlur.glsl.js +1 -1
  56. package/chunks/GlowComposition.glsl.js +3 -3
  57. package/chunks/OITAddEmission.glsl.js +1 -1
  58. package/chunks/Path.glsl.js +4 -4
  59. package/chunks/Terrain.glsl.js +2 -2
  60. package/chunks/basis_encoder.js +1 -1
  61. package/chunks/dxt_encoder.js +1 -1
  62. package/config.js +1 -1
  63. package/geometry/support/aaBoundingBox.js +1 -1
  64. package/geometry/support/frustum.js +1 -1
  65. package/kernel.js +1 -1
  66. package/layers/IntegratedMesh3DTilesLayer.js +1 -1
  67. package/package.json +2 -2
  68. package/support/revision.js +1 -1
  69. package/third-party-notices.txt +156 -0
  70. package/views/2d/engine/webgl/Painter.js +1 -1
  71. package/views/2d/engine/webgl/RenderingDevice.js +1 -1
  72. package/views/2d/engine/webgl/shaderGraph/techniques/animated/AAnimatedShader.js +1 -1
  73. package/views/2d/engine/webgl/shaderGraph/techniques/animated/AnimatedLineShader.js +1 -1
  74. package/views/2d/engine/webgl/shaderGraph/techniques/animated/AnimatedTechnique.js +1 -1
  75. package/views/2d/engine/webgl/shaderGraph/techniques/animated/AnimationUniformInfo.js +1 -1
  76. package/views/2d/engine/webgl/shaderGraph/techniques/blend/BlendTechnique.js +1 -1
  77. package/views/2d/engine/webgl/shaderGraph/techniques/bloom/BloomTechnique.js +1 -1
  78. package/views/2d/engine/webgl/shaderGraph/techniques/blur/BlurTechnique.js +1 -1
  79. package/views/2d/engine/webgl/shaderGraph/techniques/opacity/OpacityTechnique.js +1 -1
  80. package/views/2d/engine/webgl/shaderGraph/techniques/raster/RasterHighlightTechnique.js +1 -1
  81. package/views/2d/engine/webgl/shaderGraph/techniques/raster/processor/BaseRasterProcessorTechnique.js +1 -1
  82. package/views/2d/engine/webgl/shaderGraph/techniques/utility/BitBlitTechnique.js +1 -1
  83. package/views/2d/engine/webgl/shaderGraph/techniques/utility/HighlightTechnique.js +1 -1
  84. package/views/2d/layers/features/sources/FeatureSourceQueryInfo.js +1 -1
  85. package/views/2d/layers/features/sources/strategies/FeatureDrillDownTileLoadStrategy.js +1 -1
  86. package/views/2d/layers/features/sources/strategies/FeatureHybridTileLoadStrategy.js +1 -1
  87. package/views/2d/layers/features/sources/strategies/FeaturePagedTileLoadStrategy.js +1 -1
  88. package/views/2d/webglDeps.js +1 -1
  89. package/views/3d/analysis/LineOfSight/LineOfSightAggregateManipulatedObject3D.js +1 -1
  90. package/views/3d/analysis/LineOfSight/LineOfSightConfiguration.js +1 -1
  91. package/views/3d/analysis/LineOfSight/LineOfSightDrawToolRenderer.js +1 -1
  92. package/views/3d/analysis/LineOfSight/LineOfSightManipulators.js +1 -1
  93. package/views/3d/analysis/LineOfSight/LineOfSightReshapeTool3D.js +1 -1
  94. package/views/3d/analysis/LineOfSight/LineOfSightTool2.js +1 -1
  95. package/views/3d/input/SceneInputManager.js +1 -1
  96. package/views/3d/layers/I3SMeshView3D.js +1 -1
  97. package/views/3d/layers/i3s/I3SGeometryUtil.js +1 -1
  98. package/views/3d/layers/i3s/I3SIndex.js +1 -1
  99. package/views/3d/layers/i3s/I3SIntersectionHandler.js +1 -1
  100. package/views/3d/layers/i3s/I3SMeshViewFilter.js +1 -1
  101. package/views/3d/terrain/GeometryState.js +1 -1
  102. package/views/3d/terrain/PatchGeometryFactory.js +1 -1
  103. package/views/3d/terrain/PatchRenderData.js +1 -1
  104. package/views/3d/terrain/TerrainSurface.js +1 -1
  105. package/views/3d/terrain/Tile.js +1 -1
  106. package/views/3d/terrain/TileAgent.js +1 -1
  107. package/views/3d/webgl-engine/collections/Component/ComponentObject.js +1 -1
  108. package/views/3d/webgl-engine/collections/Component/ComponentObjectCollection.js +1 -1
  109. package/views/3d/webgl-engine/collections/Component/ComponentObjectElevationAgnosticBVH.js +1 -1
  110. package/views/3d/webgl-engine/collections/Component/ComponentObjectElevationAgnosticComponentGeometryBVH.js +1 -1
  111. package/views/3d/webgl-engine/collections/Component/ComponentObjectFixedBVH.js +1 -1
  112. package/views/3d/webgl-engine/collections/Component/ElevationAgnosticBVH.js +1 -1
  113. package/views/3d/webgl-engine/collections/Component/IntersectionGeometry.js +1 -1
  114. package/views/3d/webgl-engine/collections/Component/Material/ComponentData.glsl.js +1 -1
  115. package/views/3d/webgl-engine/collections/Component/Transform.js +1 -1
  116. package/views/3d/webgl-engine/core/shaderLibrary/default/DefaultMaterialAuxiliaryPasses.glsl.js +1 -1
  117. package/views/3d/webgl-engine/core/shaderLibrary/output/Emissions.glsl.js +4 -4
  118. package/views/3d/webgl-engine/core/shaderLibrary/output/OutputDepth.glsl.js +4 -10
  119. package/views/3d/webgl-engine/effects/WeatherFader.js +1 -1
  120. package/views/3d/webgl-engine/effects/debug/RenderNodeVisualizerNode.js +1 -1
  121. package/views/3d/webgl-engine/effects/fog/Fog.glsl.js +1 -1
  122. package/views/3d/webgl-engine/effects/fog/FogTechniqueConfiguration.js +1 -1
  123. package/views/3d/webgl-engine/effects/globalIllumination/GlobalIllumination.glsl.js +1 -1
  124. package/views/3d/webgl-engine/effects/globalIllumination/GlobalIllumination.js +1 -1
  125. package/views/3d/webgl-engine/effects/globalIllumination/GlobalIlluminationBlur.glsl.js +1 -1
  126. package/views/3d/webgl-engine/effects/globalIllumination/GlobalIlluminationTechniqueConfiguration.js +1 -1
  127. package/views/3d/webgl-engine/effects/glow/Glow.js +1 -1
  128. package/views/3d/webgl-engine/effects/glow/GlowBlurTechniqueConfiguration.js +1 -1
  129. package/views/3d/webgl-engine/effects/glow/GlowComposition.glsl.js +1 -1
  130. package/views/3d/webgl-engine/effects/glow/GlowCompositionTechniqueConfiguration.js +1 -1
  131. package/views/3d/webgl-engine/effects/transparency/OITAddEmission.glsl.js +1 -1
  132. package/views/3d/webgl-engine/effects/transparency/OITBlend.js +1 -1
  133. package/views/3d/webgl-engine/effects/transparency/OITBlendFragmentTechniqueConfiguration.js +1 -1
  134. package/views/3d/webgl-engine/effects/transparency/oitBlendFragment.glsl.js +1 -1
  135. package/views/3d/webgl-engine/lib/CutFillComputation.js +1 -1
  136. package/views/3d/webgl-engine/lib/TriangleIntersectionData.js +1 -1
  137. package/views/3d/webgl-engine/lib/screenPolygonOverlapUtils.js +1 -1
  138. package/views/3d/webgl-engine/lib/screenPolygonTriangleIntersections.js +1 -1
  139. package/views/3d/webgl-engine/shaders/CutFillTargetDepth.glsl.js +1 -1
  140. package/views/3d/webgl-engine/shaders/GaussianSplatCompositionTechniqueConfiguration.js +1 -1
  141. package/views/3d/webgl-engine/shaders/OutputColorHighlightOLID.glsl.js +2 -2
  142. package/views/3d/webgl-engine/shaders/{oitResolution.glsl.js → floatBlendScale.glsl.js} +1 -1
  143. package/views/GroundView.js +1 -1
  144. package/views/input/BrowserEventSource.js +1 -1
  145. package/views/input/InputManager.js +1 -1
  146. package/views/support/LayerViewManager.js +1 -1
  147. package/views/support/TextureCompressionWorker.js +1 -1
  148. package/views/support/imageReprojection.js +1 -1
  149. package/widgets/BatchAttributeForm/expressions/ExpressionsManager.js +1 -1
  150. package/widgets/BatchAttributeForm/inputs/FieldInput.js +1 -1
  151. package/widgets/BatchAttributeForm.js +1 -1
  152. package/widgets/Editor/UpdateRecordWorkflow.js +1 -1
  153. package/widgets/FeatureTable/Grid/EditorColumn.js +1 -1
  154. package/widgets/FeatureTable/Grid/GridViewModel.js +1 -1
  155. package/widgets/Sketch/SketchViewModel.js +1 -1
  156. package/widgets/support/dateUtils.js +1 -1
  157. package/assets/esri/core/workers/chunks/0d6afba80d2f8dcb5cf7.js +0 -1
  158. package/assets/esri/core/workers/chunks/1276df03201c1b855fee.js +0 -1
  159. package/assets/esri/core/workers/chunks/18d874739ee9ffad7480.js +0 -1
  160. package/assets/esri/core/workers/chunks/23570397304969f724b3.js +0 -1
  161. package/assets/esri/core/workers/chunks/474ea8c97d101e41b3f5.js +0 -1
  162. package/assets/esri/core/workers/chunks/551d0c5432f7a08dea77.js +0 -1
  163. package/assets/esri/core/workers/chunks/5923ebadd4f75be2c9cc.js +0 -1
  164. package/assets/esri/core/workers/chunks/7cb0681cc6a5e956cb15.js +0 -1
  165. package/assets/esri/core/workers/chunks/8b73694d5a97638a3a61.js +0 -1
  166. package/assets/esri/core/workers/chunks/8dee03779b569f233daf.js +0 -1
  167. package/assets/esri/core/workers/chunks/9ebc98746b1f085b82b7.js +0 -1
  168. package/assets/esri/core/workers/chunks/9ee3741eef73f3edb18b.js +0 -1
  169. package/assets/esri/core/workers/chunks/af97e19516dbbcfb5286.js +0 -1
  170. package/assets/esri/core/workers/chunks/b4047333265a2665aef9.js +0 -1
  171. package/assets/esri/core/workers/chunks/c3fae4f4522604a9c17e.js +0 -1
  172. package/assets/esri/core/workers/chunks/cce83896093279c70449.js +0 -1
  173. package/assets/esri/core/workers/chunks/d5561dff043789494845.js +0 -1
  174. package/assets/esri/core/workers/chunks/e2c9393bec747f7876bb.js +0 -1
  175. package/assets/esri/core/workers/chunks/e94f2d6037fba042dc6e.js +0 -1
  176. package/assets/esri/core/workers/chunks/f5d7f69047e1b1116202.js +0 -1
  177. package/views/2d/engine/webgl/MaterialManager.js +0 -2
  178. package/views/2d/engine/webgl/shaders/MaterialPrograms.js +0 -2
  179. package/views/2d/engine/webgl/shaders/sources/resolver.js +0 -2
  180. package/views/2d/engine/webgl/shaders/sources/shaderRepository.js +0 -2
  181. package/views/webgl/ShaderCompiler.js +0 -2
  182. /package/assets/esri/core/workers/chunks/{82f4aa0533db009b11d8.js.LICENSE.txt → bac4d4a9f3a9b7f6864d.js.LICENSE.txt} +0 -0
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{I3sTarget as e}from"./Intersector.js";import{IntersectorResult as t}from"../../webgl-engine/lib/IntersectorResult.js";import{MeshIntersectionOptions as n}from"../../webgl-engine/lib/RayIntersections.js";import{getVerticalOffsetI3S as i}from"../../webgl-engine/lib/verticalOffsetUtils.js";class r{constructor(e){this.type=2,this._needVerticalOffset=!1,this.layerViewUid=e.layerViewUid,this.sublayerId=e.sublayerId,this._collection=e.collection,this._traverseNodeHierarchy=e.traverseNodeHierarchy,this.slicePlaneEnabled=e.slicePlaneEnabled,this.isGround=e.isGround}updateElevationAlignState(e,t){this._needVerticalOffset=e&&1===t}intersectRay(r,l,o,a,c,d){const u=2===r.options.store,b=r.ray.direction;let y=e=>e,f=e=>e;const h=i(r.verticalOffset??(this._needVerticalOffset?0:null));null!=r.verticalOffset&&null!=h&&(y=e=>h.applyToMbs(e),f=e=>h.applyToObb(e));const{results:m,tolerance:R}=r,p=new n(R,d,r.options.normalRequired),g=(n,i)=>{if(0===n.childrenLoaded)return!1;const c=n.serviceObbInRenderSR?.isValid?n.serviceObbInRenderSR:null;if(c&&!f(c).intersectRay(o,b,R))return!1;const{serviceMbsInRenderSRElevationAdjusted:d}=n;return!i||!c&&d.isValid&&!s(y(d),o,b,R)||null!=n.geometryObbInRenderSR&&!f(n.geometryObbInRenderSR).intersectRay(o,b,R)||this._collection.intersectRay(i,o,a,h,p,(i,s,c,d)=>{if(s<0||null!=l&&!l(o,a,s))return;const b=t=>{const r=new e(this.layerViewUid,this.sublayerId,n.index,i,d);t.set(this.type,r,s,c)};if(this.isGround&&(null==m.ground.distance||s<m.ground.distance)&&b(m.ground),!r.options.isFiltered&&((null==m.min.distance||s<m.min.distance)&&b(m.min),(null==m.max.distance||s>m.max.distance)&&b(m.max),u)){const e=new t(r.ray);b(e),r.results.all.push(e)}}),!0};this._traverseNodeHierarchy(g)}}function s(e,t,n,i=0){const r=e.radius+i,s=t[0]-e.center[0],l=t[1]-e.center[1],o=t[2]-e.center[2],[a,c,d]=n,u=a*s+c*l+d*o;return u*u-(a*a+c*c+d*d)*(s*s+l*l+o*o-r*r)>=0}export{r as I3SIntersectionHandler};
2
+ import{intersectsSphere as e}from"../../../../geometry/support/frustum.js";import{I3sTarget as t}from"./Intersector.js";import{IntersectorResult as n}from"../../webgl-engine/lib/IntersectorResult.js";import{MeshIntersectionOptions as r}from"../../webgl-engine/lib/RayIntersections.js";import{getVerticalOffsetI3S as s}from"../../webgl-engine/lib/verticalOffsetUtils.js";class i{constructor(e,t){this.node=e,this.objectHandle=t}}class l{constructor(e){this.type=2,this._needVerticalOffset=!1,this.layerViewUid=e.layerViewUid,this.sublayerId=e.sublayerId,this._collection=e.collection,this._traverseNodeHierarchy=e.traverseNodeHierarchy,this.slicePlaneEnabled=e.slicePlaneEnabled,this.isGround=e.isGround}updateElevationAlignState(e,t){this._needVerticalOffset=e&&1===t}intersectRay(e,i,l,c,a,d){const u=2===e.options.store,b=e.ray.direction;let h=e=>e,f=e=>e;const y=s(e.verticalOffset??(this._needVerticalOffset?0:null));null!=e.verticalOffset&&null!=y&&(h=e=>y.applyToMbs(e),f=e=>y.applyToObb(e));const{results:R,tolerance:m}=e,p=new r(m,d,e.options.normalRequired),v=e=>{if(0===e.childrenLoaded)return!1;const t=e.serviceObbInRenderSR?.isValid?e.serviceObbInRenderSR:null;return!(t&&!f(t).intersectRay(l,b,m))};for(const{node:r,objectHandle:s}of this._traverseNodeHierarchy(v)){const a=r.serviceObbInRenderSR?.isValid?r.serviceObbInRenderSR:null,{serviceMbsInRenderSRElevationAdjusted:d}=r;!s||!a&&d.isValid&&!o(h(d),l,b,m)||null!=r.geometryObbInRenderSR&&!f(r.geometryObbInRenderSR).intersectRay(l,b,m)||this._collection.intersectRay(s,l,c,y,p,(s,o,a,d)=>{if(o<0||null!=i&&!i(l,c,o))return;const b=e=>{const n=new t(this.layerViewUid,this.sublayerId,r.index,s,d);e.set(this.type,n,o,a)};if(this.isGround&&(null==R.ground.distance||o<R.ground.distance)&&b(R.ground),!e.options.isFiltered&&((null==R.min.distance||o<R.min.distance)&&b(R.min),(null==R.max.distance||o>R.max.distance)&&b(R.max),u)){const t=new n(e.ray);b(t),e.results.all.push(t)}})}}*intersectScreenPolygon(n,r){if(null==n.camera)return;const i=s(this._needVerticalOffset?0:null),l=t=>{if(0===t.childrenLoaded)return!1;const n=t.serviceObbInRenderSR?.isValid?t.serviceObbInRenderSR:null;if(null!=n){if(!n.intersectsFrustumConservativeApproximation(r.broadPhaseFrustum))return!1}else{const n=t.serviceMbsInRenderSRElevationAdjusted;if(n.isValid&&!e(r.broadPhaseFrustum,n))return!1}return!0};for(const{node:e,objectHandle:s}of this._traverseNodeHierarchy(l))null!=s&&s.visible&&(null==e.geometryObbInRenderSR||e.geometryObbInRenderSR.intersectsFrustumConservativeApproximation(r.broadPhaseFrustum))&&(this._collection.intersectScreenPolygon(s,n,r,i,(r,s,i,l)=>{n.polygonResults.add(this.type,new t(this.layerViewUid,this.sublayerId,e.index,r,l),s)}),yield)}}function o(e,t,n,r=0){const s=e.radius+r,i=t[0]-e.center[0],l=t[1]-e.center[1],o=t[2]-e.center[2],[c,a,d]=n,u=c*i+a*l+d*o;return u*u-(c*c+a*a+d*d)*(i*i+l*l+o*o-s*s)>=0}export{l as I3SIntersectionHandler,i as TraversedIntersectionNode};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../../../core/Accessor.js";import{indexOf as r,PositionHint as i}from"../../../../core/arrayUtils.js";import s from"../../../../core/Logger.js";import{clamp as o}from"../../../../core/mathUtils.js";import{unwrapUpdating as n,updating as a,isUpdating as l}from"../../../../core/maybeUpdating.js";import{whenOnce as c}from"../../../../core/reactiveUtils.js";import{getUnitString as p,lengthUnits as u}from"../../../../core/units.js";import{property as m,subclass as d}from"../../../../core/accessorSupport/decorators.js";import{transformMat3 as g,add as f,set as y}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{fromValues as h}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import j from"../../../../core/sql/WhereClause.js";import{getReferenceEllipsoid as w}from"../../../../geometry/ellipsoidUtils.js";import{projectBoundingSphere as v}from"../../../../geometry/projection/projectBoundingSphere.js";import{projectVectorToVector as R}from"../../../../geometry/projection/projectVectorToVector.js";import{create as O}from"../../../../geometry/support/aaBoundingBox.js";import{fromValues as b,expandWithNestedArray as F,expand as S}from"../../../../geometry/support/aaBoundingRect.js";import{doubleArrayFrom as x}from"../../../../geometry/support/DoubleArray.js";import{earth as _}from"../../../../geometry/support/Ellipsoid.js";import{isWGS84 as k,isWebMercator as I}from"../../../../geometry/support/spatialReferenceUtils.js";import{Sphere as M}from"../../../../geometry/support/sphere.js";import G from"../../../../layers/support/FeatureFilter.js";import{objectIdFilter as L,filterInPlace as T}from"./I3SUtil.js";let B=class extends t{constructor(e){super(e)}initialize(){c(()=>this.viewFilter?.geometry||this.layerFilter).then(()=>Promise.all([this._loadOperator(import("../../../../geometry/operators/json/geodesicBufferOperator.js")),this._loadOperator(import("../../../../geometry/operators/json/bufferOperator.js")),this._loadOperator(import("../../../../geometry/operators/json/intersectsOperator.js")),this._loadOperator(import("../../../../geometry/operators/json/containsOperator.js")),this._loadOperator(import("../../../../geometry/operators/json/disjointOperator.js"))]).then(async e=>{this.destroyed||(this._geometryOperators=e)}))}_loadOperator(e){return this.loadAsyncModule(e).then(e=>"load"in e&&"function"==typeof e.load?e.load().then(()=>e):e)}get sortedObjectIds(){return null==this.viewFilter?.objectIds?null:x(this.viewFilter.objectIds).sort()}get parsedWhereClause(){const e=this.viewFilter?.where;if(null==e||!e)return null;try{return j.create(e,{fieldsIndex:this.layerFieldsIndex})}catch(t){s.getLogger(this).error(`Failed to parse filter where clause: ${t}`)}return null}addFilters(e,t,r,i){const o=this.sortedObjectIds;null!=o&&e.push(e=>L(o,!0,e)),this.addSqlFilter(e,this.parsedWhereClause),this.addTimeFilter(e,this.viewFilter?.timeExtent);const a=this._geometryOperators;if(!a)return;const l=()=>s.getLogger(this),c=n(this._layerMaskGeometries);if(c&&this.layerFilter){const s=this.layerFilter.spatialRelationship;e.push((e,o)=>J(l,a,e,o,i,t,r,c,s))}const p=n(this._viewMaskGeometries);if(p&&this.viewFilter){const s=this.viewFilter.spatialRelationship;e.push((e,o)=>J(l,a,e,o,i,t,r,p,s))}}isMBSGeometryVisible(e,t,r){const i=this._geometryOperators;if(!i)return!0;const o=n(this._layerMaskGeometries);if(o&&this.layerFilter){const n=this.layerFilter.spatialRelationship,a=o[0].spatialReference||t;if(!v(e,r,W,a))return s.getLogger(this).warnOnce("SceneLayer.mask geometry is using unsupported SpatialReference, skipping geometry filter for MBS"),!0;return A(i,W,o,a,n)}const a=n(this._viewMaskGeometries);if(a&&this.viewFilter){const o=this.viewFilter.spatialRelationship,n=a[0].spatialReference||t;if(!v(e,r,W,n))return s.getLogger(this).warnOnce("SceneLayerView.filter.geometry is using unsupported SpatialReference, skipping geometry filter for MBS"),!0;return A(i,W,a,n,o)}return!0}get parsedGeometry(){const e=n(this._viewMaskGeometries),t=n(this._layerMaskGeometries);return null==e||null==t?e??t:t.concat(e)}get _layerMaskGeometries(){const e=this.layerFilter;return null==e?null:null==this._geometryOperators?a:"disjoint"===e.spatialRelationship?e.geometries.map(e=>({type:"polygon",rings:e.rings,spatialReference:e.spatialReference,cache:{}})):[e.geometries.reduce((e,t)=>(e.rings=[...e.rings,...t.rings],e),{type:"polygon",rings:[],spatialReference:e.geometries[0].spatialReference,cache:{}})]}get _viewMaskGeometries(){const e=this.viewFilter?.geometry;if(!this.viewFilter||!e)return null;if(!this._geometryOperators)return a;const{distance:t,units:r}=this.viewFilter,i=this.viewFilter.spatialRelationship,o="mesh"===e.type?e.extent:e;if(null==t||0===t)return V(this._geometryOperators,o,i);try{const e=U(r,o.spatialReference),s=this._geometryOperators[0].execute(o.toJSON(),t,{unit:e});return V(this._geometryOperators,s,i)}catch(n){s.getLogger(this).error(`Filter by geodesic buffer (distance) unsupported, failed execute with input geometry (${JSON.stringify(o.toJSON())}).`)}return null}get updating(){return l(this._layerMaskGeometries)||l(this._viewMaskGeometries)}static checkSupport(e){return null!=e&&(!!N(e.spatialRelationship)||(s.getLogger(this.prototype).warn(`Filters with spatialRelationship other than ${C.join(", ")} are not supported for mesh scene layers`),!1))}};e([m()],B.prototype,"layerFilter",void 0),e([m({type:G})],B.prototype,"viewFilter",void 0),e([m()],B.prototype,"layerFieldsIndex",void 0),e([m()],B.prototype,"loadAsyncModule",void 0),e([m()],B.prototype,"addSqlFilter",void 0),e([m()],B.prototype,"addTimeFilter",void 0),e([m({readOnly:!0})],B.prototype,"sortedObjectIds",null),e([m({readOnly:!0})],B.prototype,"parsedWhereClause",null),e([m({readOnly:!0})],B.prototype,"parsedGeometry",null),e([m({readOnly:!0})],B.prototype,"_layerMaskGeometries",null),e([m({readOnly:!0})],B.prototype,"_viewMaskGeometries",null),e([m()],B.prototype,"updating",null),e([m()],B.prototype,"_geometryOperators",void 0),B=e([d("esri.views.3d.layers.i3s.I3SMeshViewFilter")],B);const C=(e=>e)(["contains","intersects","disjoint"]);function N(e){return null!=e&&C.includes(e)}function U(e,t){const r=e??p(t);return u.includes(r)?r:void 0}function V(e,t,s){if(null==t)return null;if("disjoint"===s&&"rings"in t){const s=t.spatialReference,o=t.rings.map(e=>{const t=b(1/0,1/0,-1/0,-1/0);return F(t,e),new q({rings:[e],spatialReference:s},t)});o.sort((e,t)=>e.aabr[0]-t.aabr[0]);const n=new Set,a=new i;for(let t=0;t<o.length;++t){const{polygon:i,aabr:s}=o[t],l=s[0];n.forEach(t=>{if(l>=t.aabr[2])return void n.delete(t);if(s[1]>t.aabr[3]||s[3]<t.aabr[1]||!e[2].execute(i,t.polygon))return;i.rings=i.rings.concat(t.polygon.rings),S(s,t.aabr,s),n.delete(t);const c=r(o,t,o.length,a);o.splice(c,1)}),n.add(o[t])}return o.map(({polygon:e})=>e)}return["toJSON"in t?t.toJSON():t]}function A(e,t,r,i,s){if(t.radius>=.5*(t.center[2]+w(i).radius))return!0;const o=$(e,t,i);return!o||r.every(t=>1!==P(e,t,o,s))}function J(e,t,r,i,s,o,n,a,l){const c=a[0].spatialReference||o.spatialReference;if(!v(i.node.serviceMbsInIndexSR,n,W,c))return void e().warnOnce("SceneLayerView.filter.geometry is using unsupported SpatialReference, skipping geometry filter");const p=$(t,W,c);if(!p)return;const u=E(l,o,c,s,i.objectHandle),m="intersects"===l;let d=null;for(const g of a){if(0===r.length)return;switch(P(t,g,p,l)){case 1:return m&&(i.weaklyRemovedIds=i.weaklyRemovedIds?.concat(r)??r.slice()),void(r.length=0);case 0:continue}T(r,i.featureIds,e=>!!H(t,g,e,u)||(m&&(d||=[],d.push(i.featureIds[e])),!1))}d&&(i.weaklyRemovedIds=i.weaklyRemovedIds?.concat(d)??d)}const W=new M;class q{constructor(e,t){this.aabr=t,this.polygon={rings:e.rings,spatialReference:e.spatialReference}}}function E(e,t,r,i,s){const o=t.renderSpatialReference,n=new Map,a={rings:[[[0,0,0],[0,0,0],[0,0,0],[0,0,0]]],spatialReference:r};a.rings[0][3]=a.rings[0][0];const l={indices:null,data:null,stride:0,startIndex:0,endIndex:0};let c,p;switch(e){case"intersects":c=(e,t,r)=>e[2].execute(t,r)?0:2,p=z;break;case"contains":c=(e,t,r)=>e[3].execute(t,r)?2:1,p=z;break;default:c=(e,t,r)=>e[4].execute(t,r)?2:1,p=D}return{collection:i,object:s,type:e,maskSR:r,renderSR:o,aabbCache:n,triangle:a,positions:l,triangleTest:c,geometryTest:p}}function $(e,t,r){const i={x:t.center[0],y:t.center[1],spatialReference:r},s=!k(r)&&!I(r),n=Number.isNaN(t.radius)?0:o(t.radius,0,2*_.radius);return s?e[1].execute(i,n):e[0].execute(i,n)}function P(e,t,r,i){if(!r)return 0;switch(i){case"intersects":case"contains":return z(e,t,r);case"disjoint":return D(e,t,r)}}function z(e,t,r){return e[2].execute(t,r)?e[3].execute(t,r)?0:2:1}function D(e,t,r){return e[2].execute(t,r)?e[3].execute(t,r)?1:2:0}function H(e,t,r,i){const{collection:s,object:o,renderSR:n,maskSR:a,geometryTest:l,aabbCache:c}=i;let p=c.get(r);if(!p){const e=s.getObjectTransform(o);s.getComponentAabb(o,r,K);const t=[h(K[0],K[1],0),h(K[0],K[4],0),h(K[3],K[4],0),h(K[3],K[1],0)];for(let r=0;r<4;++r)g(t[r],t[r],e.rotationScale),f(t[r],t[r],e.position),R(t[r],n,t[r],a);p={rings:[t],spatialReference:a},p.rings[0][4]=p.rings[0][0],c.set(r,p)}switch(l(e,t,p)){case 1:return!1;case 0:return!0}const{triangle:u,triangleTest:m,positions:d}=i,j=u.rings[0][0],w=u.rings[0][1],v=u.rings[0][2],O=s.getObjectTransform(o);s.getComponentPositions(o,r,d);const{indices:b,data:F,stride:S,startIndex:x,endIndex:_}=d;for(let h=x;h<_;h+=3){const r=S*b[h],i=S*b[h+1],s=S*b[h+2];switch(y(j,F[r],F[r+1],F[r+2]),y(w,F[i],F[i+1],F[i+2]),y(v,F[s],F[s+1],F[s+2]),g(j,j,O.rotationScale),g(w,w,O.rotationScale),g(v,v,O.rotationScale),f(j,j,O.position),f(w,w,O.position),f(v,v,O.position),R(j,n,j,a),R(w,n,w,a),R(v,n,v,a),m(e,t,u)){case 1:return!1;case 0:return!0}}return"intersects"!==i.type}const K=O();export{B as I3SMeshViewFilter};
2
+ import{__decorate as e}from"tslib";import t from"../../../../core/Accessor.js";import{indexOf as r,PositionHint as s}from"../../../../core/arrayUtils.js";import i from"../../../../core/Logger.js";import{clamp as o}from"../../../../core/mathUtils.js";import{unwrapUpdating as n,updating as a,isUpdating as l}from"../../../../core/maybeUpdating.js";import{whenOnce as c}from"../../../../core/reactiveUtils.js";import{getUnitString as p,lengthUnits as u}from"../../../../core/units.js";import{property as m,subclass as d}from"../../../../core/accessorSupport/decorators.js";import{set as g}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{fromValues as y}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import f from"../../../../core/sql/WhereClause.js";import{getReferenceEllipsoid as h}from"../../../../geometry/ellipsoidUtils.js";import{projectBoundingSphere as j}from"../../../../geometry/projection/projectBoundingSphere.js";import{projectVectorToVector as w}from"../../../../geometry/projection/projectVectorToVector.js";import{create as v}from"../../../../geometry/support/aaBoundingBox.js";import{fromValues as R,expandWithNestedArray as O,expand as b}from"../../../../geometry/support/aaBoundingRect.js";import{doubleArrayFrom as F}from"../../../../geometry/support/DoubleArray.js";import{earth as x}from"../../../../geometry/support/Ellipsoid.js";import{isWGS84 as S,isWebMercator as _}from"../../../../geometry/support/spatialReferenceUtils.js";import{Sphere as k}from"../../../../geometry/support/sphere.js";import I from"../../../../layers/support/FeatureFilter.js";import{objectIdFilter as M,filterInPlace as G}from"./I3SUtil.js";let V=class extends t{constructor(e){super(e)}initialize(){c(()=>this.viewFilter?.geometry||this.layerFilter).then(()=>Promise.all([this._loadOperator(import("../../../../geometry/operators/json/geodesicBufferOperator.js")),this._loadOperator(import("../../../../geometry/operators/json/bufferOperator.js")),this._loadOperator(import("../../../../geometry/operators/json/intersectsOperator.js")),this._loadOperator(import("../../../../geometry/operators/json/containsOperator.js")),this._loadOperator(import("../../../../geometry/operators/json/disjointOperator.js"))]).then(async e=>{this.destroyed||(this._geometryOperators=e)}))}_loadOperator(e){return this.loadAsyncModule(e).then(e=>"load"in e&&"function"==typeof e.load?e.load().then(()=>e):e)}get sortedObjectIds(){return null==this.viewFilter?.objectIds?null:F(this.viewFilter.objectIds).sort()}get parsedWhereClause(){const e=this.viewFilter?.where;if(null==e||!e)return null;try{return f.create(e,{fieldsIndex:this.layerFieldsIndex})}catch(t){i.getLogger(this).error(`Failed to parse filter where clause: ${t}`)}return null}addFilters(e,t,r,s){const o=this.sortedObjectIds;null!=o&&e.push(e=>M(o,!0,e)),this.addSqlFilter(e,this.parsedWhereClause),this.addTimeFilter(e,this.viewFilter?.timeExtent);const a=this._geometryOperators;if(!a)return;const l=()=>i.getLogger(this),c=n(this._layerMaskGeometries);if(c&&this.layerFilter){const i=this.layerFilter.spatialRelationship;e.push((e,o)=>U(l,a,e,o,s,t,r,c,i))}const p=n(this._viewMaskGeometries);if(p&&this.viewFilter){const i=this.viewFilter.spatialRelationship;e.push((e,o)=>U(l,a,e,o,s,t,r,p,i))}}isMBSGeometryVisible(e,t,r){const s=this._geometryOperators;if(!s)return!0;const o=n(this._layerMaskGeometries);if(o&&this.layerFilter){const n=this.layerFilter.spatialRelationship,a=o[0].spatialReference||t;if(!j(e,r,A,a))return i.getLogger(this).warnOnce("SceneLayer.mask geometry is using unsupported SpatialReference, skipping geometry filter for MBS"),!0;return N(s,A,o,a,n)}const a=n(this._viewMaskGeometries);if(a&&this.viewFilter){const o=this.viewFilter.spatialRelationship,n=a[0].spatialReference||t;if(!j(e,r,A,n))return i.getLogger(this).warnOnce("SceneLayerView.filter.geometry is using unsupported SpatialReference, skipping geometry filter for MBS"),!0;return N(s,A,a,n,o)}return!0}get parsedGeometry(){const e=n(this._viewMaskGeometries),t=n(this._layerMaskGeometries);return null==e||null==t?e??t:t.concat(e)}get _layerMaskGeometries(){const e=this.layerFilter;return null==e?null:null==this._geometryOperators?a:"disjoint"===e.spatialRelationship?e.geometries.map(e=>({type:"polygon",rings:e.rings,spatialReference:e.spatialReference,cache:{}})):[e.geometries.reduce((e,t)=>(e.rings=[...e.rings,...t.rings],e),{type:"polygon",rings:[],spatialReference:e.geometries[0].spatialReference,cache:{}})]}get _viewMaskGeometries(){const e=this.viewFilter?.geometry;if(!this.viewFilter||!e)return null;if(!this._geometryOperators)return a;const{distance:t,units:r}=this.viewFilter,s=this.viewFilter.spatialRelationship,o="mesh"===e.type?e.extent:e;if(null==t||0===t)return C(this._geometryOperators,o,s);try{const e=B(r,o.spatialReference),i=this._geometryOperators[0].execute(o.toJSON(),t,{unit:e});return C(this._geometryOperators,i,s)}catch(n){i.getLogger(this).error(`Filter by geodesic buffer (distance) unsupported, failed execute with input geometry (${JSON.stringify(o.toJSON())}).`)}return null}get updating(){return l(this._layerMaskGeometries)||l(this._viewMaskGeometries)}static checkSupport(e){return null!=e&&(!!T(e.spatialRelationship)||(i.getLogger(this.prototype).warn(`Filters with spatialRelationship other than ${L.join(", ")} are not supported for mesh scene layers`),!1))}};e([m()],V.prototype,"layerFilter",void 0),e([m({type:I})],V.prototype,"viewFilter",void 0),e([m()],V.prototype,"layerFieldsIndex",void 0),e([m()],V.prototype,"loadAsyncModule",void 0),e([m()],V.prototype,"addSqlFilter",void 0),e([m()],V.prototype,"addTimeFilter",void 0),e([m({readOnly:!0})],V.prototype,"sortedObjectIds",null),e([m({readOnly:!0})],V.prototype,"parsedWhereClause",null),e([m({readOnly:!0})],V.prototype,"parsedGeometry",null),e([m({readOnly:!0})],V.prototype,"_layerMaskGeometries",null),e([m({readOnly:!0})],V.prototype,"_viewMaskGeometries",null),e([m()],V.prototype,"updating",null),e([m()],V.prototype,"_geometryOperators",void 0),V=e([d("esri.views.3d.layers.i3s.I3SMeshViewFilter")],V);const L=(e=>e)(["contains","intersects","disjoint"]);function T(e){return null!=e&&L.includes(e)}function B(e,t){const r=e??p(t);return u.includes(r)?r:void 0}function C(e,t,i){if(null==t)return null;if("disjoint"===i&&"rings"in t){const i=t.spatialReference,o=t.rings.map(e=>{const t=R(1/0,1/0,-1/0,-1/0);return O(t,e),new J({rings:[e],spatialReference:i},t)});o.sort((e,t)=>e.aabr[0]-t.aabr[0]);const n=new Set,a=new s;for(let t=0;t<o.length;++t){const{polygon:s,aabr:i}=o[t],l=i[0];n.forEach(t=>{if(l>=t.aabr[2])return void n.delete(t);if(i[1]>t.aabr[3]||i[3]<t.aabr[1]||!e[2].execute(s,t.polygon))return;s.rings=s.rings.concat(t.polygon.rings),b(i,t.aabr,i),n.delete(t);const c=r(o,t,o.length,a);o.splice(c,1)}),n.add(o[t])}return o.map(({polygon:e})=>e)}return["toJSON"in t?t.toJSON():t]}function N(e,t,r,s,i){if(t.radius>=.5*(t.center[2]+h(s).radius))return!0;const o=q(e,t,s);return!o||r.every(t=>1!==E(e,t,o,i))}function U(e,t,r,s,i,o,n,a,l){const c=a[0].spatialReference||o.spatialReference;if(!j(s.node.serviceMbsInIndexSR,n,A,c))return void e().warnOnce("SceneLayerView.filter.geometry is using unsupported SpatialReference, skipping geometry filter");const p=q(t,A,c);if(!p)return;const u=W(l,o,c,i,s.objectHandle),m="intersects"===l;let d=null;for(const g of a){if(0===r.length)return;switch(E(t,g,p,l)){case 1:return m&&(s.weaklyRemovedIds=s.weaklyRemovedIds?.concat(r)??r.slice()),void(r.length=0);case 0:continue}G(r,s.featureIds,e=>!!z(t,g,e,u)||(m&&(d||=[],d.push(s.featureIds[e])),!1))}d&&(s.weaklyRemovedIds=s.weaklyRemovedIds?.concat(d)??d)}const A=new k;class J{constructor(e,t){this.aabr=t,this.polygon={rings:e.rings,spatialReference:e.spatialReference}}}function W(e,t,r,s,i){const o=t.renderSpatialReference,n=new Map,a={rings:[[[0,0,0],[0,0,0],[0,0,0],[0,0,0]]],spatialReference:r};a.rings[0][3]=a.rings[0][0];const l={indices:null,data:null,stride:0,startIndex:0,endIndex:0};let c,p;switch(e){case"intersects":c=(e,t,r)=>e[2].execute(t,r)?0:2,p=$;break;case"contains":c=(e,t,r)=>e[3].execute(t,r)?2:1,p=$;break;default:c=(e,t,r)=>e[4].execute(t,r)?2:1,p=P}return{collection:s,object:i,type:e,maskSR:r,renderSR:o,aabbCache:n,triangle:a,positions:l,triangleTest:c,geometryTest:p}}function q(e,t,r){const s={x:t.center[0],y:t.center[1],spatialReference:r},i=!S(r)&&!_(r),n=Number.isNaN(t.radius)?0:o(t.radius,0,2*x.radius);return i?e[1].execute(s,n):e[0].execute(s,n)}function E(e,t,r,s){if(!r)return 0;switch(s){case"intersects":case"contains":return $(e,t,r);case"disjoint":return P(e,t,r)}}function $(e,t,r){return e[2].execute(t,r)?e[3].execute(t,r)?0:2:1}function P(e,t,r){return e[2].execute(t,r)?e[3].execute(t,r)?1:2:0}function z(e,t,r,s){const{collection:i,object:o,renderSR:n,maskSR:a,geometryTest:l,aabbCache:c}=s;let p=c.get(r);if(!p){const e=i.getObjectTransform(o);i.getComponentAabb(o,r,D);const t=[y(D[0],D[1],0),y(D[0],D[4],0),y(D[3],D[4],0),y(D[3],D[1],0)];for(let r=0;r<4;++r)e.applyVec3(t[r],t[r]),w(t[r],n,t[r],a);p={rings:[t],spatialReference:a},p.rings[0][4]=p.rings[0][0],c.set(r,p)}switch(l(e,t,p)){case 1:return!1;case 0:return!0}const{triangle:u,triangleTest:m,positions:d}=s,f=u.rings[0][0],h=u.rings[0][1],j=u.rings[0][2],v=i.getObjectTransform(o);i.getComponentPositions(o,r,d);const{indices:R,data:O,stride:b,startIndex:F,endIndex:x}=d;for(let y=F;y<x;y+=3){const r=b*R[y],s=b*R[y+1],i=b*R[y+2];switch(g(f,O[r],O[r+1],O[r+2]),g(h,O[s],O[s+1],O[s+2]),g(j,O[i],O[i+1],O[i+2]),v.applyVec3(f,f),v.applyVec3(h,h),v.applyVec3(j,j),w(f,n,f,a),w(h,n,h,a),w(j,n,j,a),m(e,t,u)){case 1:return!1;case 0:return!0}}return"intersects"!==s.type}const D=v();export{V as I3SMeshViewFilter};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- class l{constructor(){this.numVerticesPerSide=0,this.samplerData=null,this.samplerDataVersion=0,this.clippingArea=null,this.wireframe=!1,this.cornerPeerNeighbors=[null,null,null,null],this.cornerNeighborCornerTiles=[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],this.cornerNeighborCornerTileSamplerVersions=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],this.edgeResolutions=[-1,-1,-1,-1],this.edgePeerNeighbors=[null,null,null,null],this.edgePeerNeighborSamplerVersions=[-1,-1,-1,-1]}}export{l as GeometryState};
2
+ class l{constructor(){this.numVerticesPerSide=0,this.samplerData=null,this.samplerDataSourceLevels=null,this.samplerDataVersion=0,this.clippingArea=null,this.wireframe=!1,this.cornerPeerNeighbors=[null,null,null,null],this.cornerNeighborCornerTiles=[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],this.cornerNeighborCornerTileSamplerVersions=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],this.edgeResolutions=[-1,-1,-1,-1],this.edgePeerNeighbors=[null,null,null,null],this.edgePeerNeighborSamplerVersions=[-1,-1,-1,-1]}}export{l as GeometryState};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{clamp as t,isPowerOfTwo as e}from"../../../core/mathUtils.js";import{maxUint16 as n}from"../../../core/typedArrayUtil.js";import{empty as o}from"../../../geometry/support/aaBoundingBox.js";import{fromValues as s}from"../../../geometry/support/aaBoundingRect.js";import{sampleElevation as r,sampleSingleElevation as i}from"./ElevationData.js";import{PatchGeometryLUT as a}from"./PatchGeometryLUT.js";import{zeroToFour as c,neighborTileIfLoadedOrSelf as l}from"./PatchRenderData.js";import{maxPatchTesselation as u,elevationNoDataValue as d}from"./TerrainConst.js";import{internalAssert as f,enableTerrainInternalChecks as m,neighborEdgeIndices as g,almostEquals as h}from"./terrainUtils.js";import{isCornerNeighbor as p}from"./Tile.js";import{compareTilesByLij as x}from"./tileUtils.js";import{compressNormal as M}from"../webgl-engine/lib/Normals.js";const y=65536;function S(t,e){const{tile:n,geometry:s,geometryState:r}=t,{extentInRadians:i,surface:a}=n,{isWebMercator:c,renderer:l}=a,{numVerticesPerSide:u,wireframe:d}=r,f=u-1,m=(u-2)**2,g=c&&(2===e||3===e),h=c&&(1===e||3===e),p=((g?1:0)+(h?1:0))*It*u,x=vt(r),M=m+p+4*x,y=l.tileGeometryCache.acquire(M);s.numVerticesPerSide=u,s.vertexAttributes=y,s.maxEdgeVertexCount=x;const{boundingBox:S}=s;o(S);const B=O(t);ct.update(f,i,B),v(t),s.poleVerticesStartIndex=m;const V=L(t,g,h);s.edgeVerticesStartIndex=m+p,_(t),C(t),J(s,V,d),t.intersectionData=null}function L(t,e,o){const{tile:s,localOrigin:r,geometry:i}=t,{extent:a,ellipsoid:c}=s,{boundingBox:l,numVerticesPerSide:u,vertexAttributes:d,poleVerticesStartIndex:f}=i,m=u-1,g=r[0],h=r[1],p=r[2],x=c.radius,y=a[1],S=a[3],L=[];let v=f;const B=(t,e)=>{const o=e*u;Lt(-g,-h,t*x-p,l),L.push(new it(1===t,o,1===t?0:2,v,It));const s=D(-1===t?y:S,x),r=t*Math.PI/2-s,i=.99*(1===t?1:-1),a=x+0,{position:c,uv0:f}=d,{typedBuffer:B,typedBufferStride:V}=d.normalCompressed;for(let u=1;u<=It;++u){const t=s+r*(u/It),e=Math.cos(t),o=Math.sin(t);for(let s=0;s<=m;s++){const t=s/m,r=ct.sinLonLUT[s],u=ct.cosLonLUT[s]*e,d=r*e,x=o,y=u*a-g,S=d*a-h,L=x*a-p;Lt(y,S,L,l),c.setValues(v,y,S,L),f.setValues(v,Math.round(t*n),Math.round(i*n)),M(B,v,u,d,x,V),++v}}};return e&&B(-1,0),o&&B(1,m),L}function v(t){const e=t.geometryState.samplerData,n=1===e?.length?e[0]:null;n?B(t,n):V(t)}function B(t,e){const{tile:n}=t;if(!n.intersectsClippingArea)return;const{geometry:o,geometryState:s,localOrigin:r}=t,{numVerticesPerSide:i}=s,a=i-2,c=i-1,{vertexAttributes:l,boundingBox:u}=o,{position:d,uv0:f}=l,{typedBuffer:m,typedBufferStride:g}=l.normalCompressed,{extent:h}=n,p=n.ellipsoid.radius,x=r[0],y=r[1],S=r[2],L=d.typedBuffer,v=d.typedBufferStride,B=f.typedBuffer,V=f.typedBufferStride;I(c,h,e);let T=0;const U=e.data.values;if(1<=a){const t=ut[1],e=ct.sinLatLUT[1],n=ct.cosLatLUT[1];for(let o=1;o<=a;o++){const s=ct.sinLonLUT[o],r=ct.cosLonLUT[o],i=p+b(o,1,U),a=i*r*n-x,c=i*s*n-y,l=i*e-S;Lt(a,c,l,u);const d=(o-1)*v;L[d]=a,L[d+1]=c,L[d+2]=l;const f=(o-1)*V;B[f]=ut[o],B[f+1]=t}}for(let I=1;I<=a;I++){const t=ct.sinLatLUT[I],e=ct.cosLatLUT[I],n=I+1,o=ut[n],s=ct.sinLatLUT[n],r=ct.cosLatLUT[n],i=ct.sinLonLUT[0],l=ct.cosLonLUT[0],d=p+b(0,I,U);let f=l*e*d-x,h=i*e*d-y,C=t*d-S;const A=T*v;let P=L[A],D=L[A+1],E=L[A+2];for(let w=1;w<=a;w++){const i=ct.sinLonLUT[w],l=ct.cosLonLUT[w];let d=0,A=0,O=0;if(w<a){const t=(T+1)*v;d=L[t],A=L[t+1],O=L[t+2]}else{const n=ct.sinLonLUT[c],o=ct.cosLonLUT[c],s=p+b(c,I,U);d=o*e*s-x,A=n*e*s-y,O=t*s-S}const R=f,N=h,j=C;f=P,h=D,C=E,P=d,D=A,E=O;const F=d-R,q=A-N,W=O-j;let k=0,z=0,G=0;if(I>1){const t=(T-a)*v;k=L[t],z=L[t+1],G=L[t+2]}else{const t=ct.sinLatLUT[0],e=ct.cosLatLUT[0],n=p+b(w,0,U);k=l*e*n-x,z=i*e*n-y,G=t*n-S}const H=p+b(w,n,U),J=l*r*H-x,K=i*r*H-y,Q=s*H-S;if(I<a){const t=T+a,e=t*v;L[e]=J,L[e+1]=K,L[e+2]=Q,Lt(J,K,Q,u);const n=t*V;B[n]=ut[w],B[n+1]=o}const X=k-J,Y=z-K,Z=G-Q;let $=l*e,_=i*e,tt=t;tt*tt<.999&&($=W*Y-q*Z,_=F*Z-W*X,tt=q*X-F*Y);const et=1/Math.sqrt($*$+_*_+tt*tt);M(m,T,$*et,_*et,tt*et,g),++T}}}function V(t){const{tile:e}=t;if(!e.intersectsClippingArea)return;const{geometry:o,geometryState:s,localOrigin:i}=t,{numVerticesPerSide:a,samplerData:c}=s,l=a-2,u=a-1,{vertexAttributes:d,boundingBox:f}=o,{position:m,uv0:g}=d,{typedBuffer:h,typedBufferStride:p}=d.normalCompressed,{extent:x}=e,y=x[0],S=x[2],L=x[1],v=x[3],B=e.ellipsoid.radius,V=i[0],I=i[1],b=i[2],T=m.typedBuffer,U=m.typedBufferStride,C=1/u;let A=0;if(1<=l){const t=C,e=L*(1-t)+v*t,o=ct.sinLatLUT[1],s=ct.cosLatLUT[1];for(let i=1;i<=l;i++){const a=i*C,l=y*(1-a)+S*a,u=ct.sinLonLUT[i],d=ct.cosLonLUT[i],m=B+r(l,e,c),h=m*d*s-V,p=m*u*s-I,x=m*o-b;Lt(h,p,x,f);const M=(i-1)*U;T[M]=h,T[M+1]=p,T[M+2]=x,g.setValues(i-1,Math.round(a*n),Math.round(t*n))}}for(let P=1;P<=l;P++){const t=P*C,e=L*(1-t)+v*t,o=ct.sinLatLUT[P],s=ct.cosLatLUT[P],i=P+1,a=i*C,d=L*(1-a)+v*a,m=ct.sinLatLUT[i],x=ct.cosLatLUT[i],D=ct.sinLonLUT[0],E=ct.cosLonLUT[0],w=B+r(y,e,c);let O=E*s*w-V,R=D*s*w-I,N=o*w-b;const j=A*U;let F=T[j],q=T[j+1],W=T[j+2];for(let v=1;v<=l;v++){const t=v*C,i=y*(1-t)+S*t,D=ct.sinLonLUT[v],E=ct.cosLonLUT[v];let w=0,j=0,k=0;if(v<l){const t=(A+1)*U;w=T[t],j=T[t+1],k=T[t+2]}else{const t=ct.sinLonLUT[u],n=ct.cosLonLUT[u],i=B+r(S,e,c);w=n*s*i-V,j=t*s*i-I,k=o*i-b}const z=O,G=R,H=N;O=F,R=q,N=W,F=w,q=j,W=k;const J=w-z,K=j-G,Q=k-H;let X=0,Y=0,Z=0;if(P>1){const t=(A-l)*U;X=T[t],Y=T[t+1],Z=T[t+2]}else{const t=ct.sinLatLUT[0],e=ct.cosLatLUT[0],n=B+r(i,L,c);X=E*e*n-V,Y=D*e*n-I,Z=t*n-b}const $=B+r(i,d,c),_=E*x*$-V,tt=D*x*$-I,et=m*$-b;if(P<l){const e=A+l,o=e*U;T[o]=_,T[o+1]=tt,T[o+2]=et,Lt(_,tt,et,f),g.setValues(e,Math.round(t*n),Math.round(a*n))}const nt=X-_,ot=Y-tt,st=Z-et;let rt=E*s,it=D*s,at=o;at*at<.999&&(rt=Q*ot-K*st,it=J*st-Q*nt,at=K*nt-J*ot);const lt=1/Math.sqrt(rt*rt+it*it+at*at);M(h,A,rt*lt,it*lt,at*lt,p),++A}}}function I(e,o,s){const r=o[0],i=o[2],a=o[1],c=o[3],l=1/e,{dx:u,dy:d,x0:f,y1:m,safeWidth:g}=s,h=s.data.width;for(let p=0;p<=e;p++){const e=p*l,o=t(u*(r*(1-e)+i*e-f),0,g),s=Math.floor(o);dt[p]=s,gt[p]=o-s;const x=t(d*(m-(a*(1-e)+c*e)),0,g),M=Math.floor(x);ft[p]=M*h,mt[p]=(M+1)*h,ht[p]=x-M,ut[p]=Math.round(e*n)}}function b(t,e,n){const o=dt[t],s=gt[t],r=ft[e],i=mt[e],a=ht[e],c=r+o,l=n[c],u=n[c+1],d=n[i+o],f=n[i+o+1];if(l+d+u+f>=lt)return 0;const m=l+(u-l)*s;return m+(d+(f-d)*s-m)*a}function T(t){t.tile.intersectsClippingArea&&(C(t),st(t),t.intersectionData=null)}function U(t){t.tile.intersectsClippingArea&&(tt(t),C(t),st(t),rt(t),t.intersectionData=null)}function C(t){t.tile.intersectsClippingArea&&(P(t),A(t))}function A(t){const{geometry:o,geometryState:s,tile:a,localOrigin:c}=t,{level:u,extent:d,extentInRadians:p,ellipsoid:y}=a,S=y.radius,L=p[0],v=p[2],B=p[1],V=p[3],{samplerData:I}=s,b=d[0],T=d[2],U=d[1],C=d[3],A=O(t),{boundingBox:P,vertexAttributes:D}=o,E=c[0],w=c[1],R=c[2],{position:N,uv0:j}=D,F=N.typedBuffer,q=N.typedBufferStride,W=j.typedBuffer,k=j.typedBufferStride,{typedBuffer:z,typedBufferStride:G}=D.normalCompressed,H=1===I?.length?I[0]:null,J=(t,e,n)=>H?i(t,e,H)??0:r(t,e,I)??0;for(let O=0;O<4;++O){const c=1===O||3===O,p=s.edgeResolutions[O];f(e(p));const y=p+1,D=l(a,s.edgePeerNeighbors[O]);if(Mt(a,D,O)){et(t,O,D);continue}const N=null!=D;f(!N||D.level===a.level),f(!N||x(a,D)<=0);const j=D?.renderData,K=j?.geometryState;if(m){const t=a.surface;if(!D&&t&&!t.updatingRootTiles){const e=g[O],n=a.findNeighborTile(e,t=>t.loaded||t.leaf||t.level===a.level);n?n.intersectsClippingArea&&(f(!n.loaded),f(!n.leaf),f(n.level===u)):f(null==t?.rootTiles||!a.shouldHaveNeighbor(e))}}const Q=1===O?d[2]:d[0],X=D?.extent,Y=X&&c?1===O?X[0]:X[2]:Q,Z=0===O?d[3]:d[1],$=1===O?1:0,_=0===O?1:0,tt=1===O?v:L,nt=0===O?V:B,ot=Math.sin(tt),st=Math.cos(tt),rt=Math.sin(nt),it=Math.cos(nt),at=K?.samplerData,ct=1===at?.length?at[0]:null,lt=(t,e,n)=>ct?i(n,e,ct)??0:r(n,e,at)??0,ut=N?(t,e,n)=>.5*(J(t,e)+lt(t,e,n)):J,dt=o.outerEdgesOffsetAndLength[2*O+0],ft=null!=H||null!=I&&I.some(t=>null!=t),mt=null!=ct||null!=at&&at.some(t=>null!=t),gt=ft||mt,ht=1/p,pt=n*ht,xt=$*n,yt=_*n,St=dt;f(!X||h(X[2]-X[0],d[2]-d[0]));(()=>{const t=1===O?-1:3===O?1:0,e=0===O?-1:2===O?1:0,n=(d[2]-d[0])*ht,o=t*n,s=e*n,a=c?t*((v-L)*ht):0,l=c?0:e*ht,u=_,f=c?tt+a:tt,m=c?Math.sin(f):ot,g=c?Math.cos(f):st,h=c?tt-a:tt,p=c?Math.sin(h):ot,x=c?Math.cos(h):st,B=c?nt:A(u+l),V=c?rt:Math.sin(B),D=c?it:Math.cos(B),j=c?nt:A(u-l),J=c?rt:Math.sin(j),K=c?it:Math.cos(j);let X=0,$=0,et=0;{const t=0*ht,e=c?Q:b*(1-t)+T*t,n=c?Y:e,o=c?U*(1-t)+C*t:Z,s=c?tt:L*(1-t)+v*t,r=c?ot:Math.sin(s),i=c?st:Math.cos(s),a=c?A(t):nt,l=c?Math.sin(a):rt,u=c?Math.cos(a):it,d=S+ut(e,o,n);X=i*u*d,$=r*u*d,et=l*d}let lt=0,dt=0,ft=0;{const t=1*ht,e=c?Q:b*(1-t)+T*t,n=c?Y:e,o=c?U*(1-t)+C*t:Z,s=c?tt:L*(1-t)+v*t,r=c?ot:Math.sin(s),i=c?st:Math.cos(s),a=c?A(t):nt,l=c?Math.sin(a):rt,u=c?Math.cos(a):it,d=S+ut(e,o,n);lt=i*u*d,dt=r*u*d,ft=l*d}for(let d=1;d<y-1;++d){let t=0,e=0,n=0;{const o=(d+1)*ht,s=c?Q:b*(1-o)+T*o,r=c?Y:s,i=c?U*(1-o)+C*o:Z,a=c?tt:L*(1-o)+v*o,l=c?ot:Math.sin(a),u=c?st:Math.cos(a),f=c?A(o):nt,m=c?Math.sin(f):rt,g=c?Math.cos(f):it,h=S+ut(s,i,r);t=u*g*h,e=l*g*h,n=m*h}const a=t,l=e,u=n,f=lt,h=dt,y=ft;lt=a,dt=l,ft=u;{const t=St+d,e=t*q,n=f-E,o=h-w,s=y-R;F[e]=n,F[e+1]=o,F[e+2]=s,Lt(n,o,s,P);const r=Math.round(d*pt),i=t*k;W[i]=c?xt:r,W[i+1]=c?r:yt}const B=X,j=$,_=et;X=f,$=h,et=y;const mt=f,Mt=h,vt=y,Bt=1/Math.sqrt(mt*mt+Mt*Mt+vt*vt),Vt=vt*Bt;let It=0,bt=0,Tt=0;if(gt&&Vt*Vt<.999){let t=0,e=0,n=0;{const o=0===O?-1:1;t=o*(a-B),e=o*(l-j),n=o*(u-_)}{const a=d*ht,l=c?Q:b*(1-a)+T*a,u=c?Y:l,f=c?U*(1-a)+C*a:Z,h=c?tt:L*(1-a)+v*a,M=c?ot:Math.sin(h),y=c?st:Math.cos(h),B=c?A(a):nt,P=c?Math.sin(B):rt,E=c?Math.cos(B):it;let w=mt,R=Mt,j=vt;if(N){const t=u-o,e=f-s,n=S+(ct?i(t,e,ct)??0:r(t,e,at)??0),a=c?E:K;w=(c?x:y)*a*n,R=(c?p:M)*a*n,j=(c?P:J)*n}{const a=l+o,u=f+s,d=S+(H?i(a,u,H)??0:r(a,u,I)??0),h=c?E:D,p=(c?g:y)*h*d,x=(c?m:M)*h*d,L=(c?P:V)*d;N||(w=2*mt-p,R=2*Mt-x,j=2*vt-L);const v=3===O?-1:1,B=v*(w-p),b=v*(R-x),T=v*(j-L);It=n*b-e*T,bt=t*T-n*B,Tt=e*B-t*b;const U=1/Math.sqrt(It*It+bt*bt+Tt*Tt);It*=U,bt*=U,Tt*=U}}}else It=mt*Bt,bt=Mt*Bt,Tt=vt*Bt;M(z,St+d,It,bt,Tt,G)}})()}}function P(t){nt(t)}function D(t,e){return Math.PI/2-2*Math.atan(Math.exp(-t/e))}function E(t,e,n,o){return D(t*(1-o)+e*o,n)}function w(t,e,n){return t*(1-n)+e*n}function O(t){const{tile:e}=t;if(e.surface.isWebMercator){const t=e.extent,n=e.ellipsoid.radius;return e=>E(t[1],t[3],n,e)}const n=e.extentInRadians;return t=>w(n[1],n[3],t)}function R(t){const{tile:e,geometryState:n,geometry:s}=t,{extent:r,surface:i}=e,{wireframe:a}=n,c=r[0],l=r[1],u=r[2]-c,d=r[3]-l,{numVerticesPerSide:f,clippingArea:m}=n,g=null!=m?Math.max(0,(m[0]-c)/u):0,h=null!=m?Math.max(0,(m[1]-l)/d):0,p=null!=m?Math.min(1,(m[2]-c)/u):1,x=null!=m?Math.min(1,(m[3]-l)/d):1,M=(f-2)**2,y=vt(n),S=M+4*y,L=i.renderer.tileGeometryCache.acquire(S),{boundingBox:v}=s;o(v),s.numVerticesPerSide=f,s.vertexAttributes=L,s.maxEdgeVertexCount=y,s.minu=g,s.minv=h,s.maxu=p,s.maxv=x,N(t),s.edgeVerticesStartIndex=M,_(t),q(t),J(s,[],a),t.intersectionData=null}function N(e){const o=e.tile;if(!o.intersectsClippingArea)return;const{geometry:s,geometryState:a,localOrigin:c}=e,{samplerData:l,clippingArea:u,numVerticesPerSide:d}=a,{surface:f,extent:m,ellipsoid:g}=o,{isWebMercatorOnPlateCarree:h}=f,p=null!=u?u:pt,x=m[0],y=m[1],S=m[2],L=m[3],v=Math.max(x,p[0]),B=Math.min(S,p[2]),V=Math.max(y,p[1]),I=Math.min(L,p[3]),b=g.radius,T=o.horizontalScale,U=d-1,C=d-2,{minu:A,minv:P,maxu:D,maxv:E,boundingBox:w,vertexAttributes:O}=s,{position:R,uv0:N}=O,{typedBuffer:j,typedBufferStride:F}=O.normalCompressed,q=c[0],W=c[1],k=c[2],z=R.typedBuffer,G=R.typedBufferStride;let H=0;const J=t(y,V,I),K=h?(Math.PI/2-2*Math.atan(Math.exp(-J/b)))*b:J*T,Q=1/U,X=t(y*(1-Q)+L*Q,V,I);let Y=K,Z=h?(Math.PI/2-2*Math.atan(Math.exp(-X/b)))*b:X*T;const $=1===l?.length?l[0]:null,_=$?(t,e)=>i(t,e,$)??0:(t,e)=>r(t,e,l)??0;for(let r=1;r<=C;r++){const e=r/U,o=t(y*(1-e)+L*e,V,I),s=t(e,P,E),i=Z,a=(r-1)/U,c=t(y*(1-a)+L*a,V,I),l=Y,u=(r+1)/U,d=t(y*(1-u)+L*u,V,I),f=h?(Math.PI/2-2*Math.atan(Math.exp(-d/b)))*b:d*T,m=t(u,P,E);Y=Z,Z=f;const g=t(x,v,B);let p=g*T,O=_(g,o);const R=1/U,J=t(R,A,D),K=t(x*(1-J)+S*J,v,B);let Q=J,X=K,$=K*T,tt=_(K,o);if(1===r){const e=$-q,o=Y-W,r=tt-k,i=0*G;z[i]=e,z[i+1]=o,z[i+2]=r,Lt(e,o,r,w);const a=t(R,A,D);N.setValues(H,Math.round(a*n),Math.round(s*n))}for(let h=1;h<=C;h++){const e=$,a=tt,u=(h+1)/U,g=t(u,A,D),y=t(x*(1-u)+S*u,v,B),L=X;X=y;{const t=H+1,e=t*G;if(1===r||h===C){const a=y*T,c=_(y,o);if(1===r&&h<C){const o=a-q,r=i-W,l=c-k;z[e]=o,z[e+1]=r,z[e+2]=l,Lt(o,r,l,w),N.setValues(t,Math.round(g*n),Math.round(s*n))}$=a,tt=c}else $=z[e]+q,tt=z[e+2]+k}const V=$,I=tt,b=p,P=O;p=e,O=a;const E=(H-C)*G,R=1===r?_(L,c):z[E+2]+k,J=_(L,d);if(r<C){const t=H+C,o=t*G,s=e-q,r=f-W,i=J-k;z[o]=s,z[o+1]=r,z[o+2]=i,Lt(s,r,i,w);const a=Q;Q=g,N.setValues(t,Math.round(a*n),Math.round(m*n))}{const t=V-b,e=l-f,n=e*(I-P),o=t*(R-J),s=-e*t,r=n*n+o*o+s*s;if(0===r)M(j,H,0,0,1,F);else{const t=1/Math.sqrt(r);M(j,H,n*t,o*t,s*t,F)}}++H}}}function j(t){t.tile.intersectsClippingArea&&(tt(t),q(t),st(t),rt(t),t.intersectionData=null)}function F(t){t.tile.intersectsClippingArea&&(q(t),st(t),t.intersectionData=null)}function q(t){t.tile.intersectsClippingArea&&(k(t),W(t))}function W(n){const{geometry:o,geometryState:s,localOrigin:a}=n,c=n.tile,{surface:u,extent:d}=c,{clippingArea:h,samplerData:p}=s,M=null!=h?h:pt,y=d[0],S=d[2],L=d[1],v=d[3],B=[v>M[3],S>M[2],L<M[1],y<M[0]],V=c.horizontalScale,I=H(u.isWebMercatorOnPlateCarree,c.ellipsoid.radius,V),{minu:b,minv:T,maxu:U,maxv:C,boundingBox:A}=o,P=Math.max(y,M[0]),D=Math.min(S,M[2]),E=Math.max(L,M[1]),w=Math.min(v,M[3]),O=a[0],R=a[1],N=a[2],j=1===p?.length?p[0]:void 0,F=j?(t,e)=>i(t,e,j)??0:(t,e)=>r(t,e,p)??0;for(let q=0;q<4;++q){const a=1===q||3===q,d=s.edgeResolutions[q];f(e(d));const h=d+1,M=B[q],j=l(c,s.edgePeerNeighbors[q]);if(!M&&Mt(c,j,q)){et(n,q,j);continue}const W=null!=j&&!M,k=j?.renderData,z=k?.geometryState;if(m&&(f(!W||j.level===c.level),f(!W||x(c,j)<=0),c&&!j&&!u.updatingRootTiles)){const t=g[q],e=c.findNeighborTile(t,t=>t.loaded||t.leaf||t.level===c.level);u.updatingRootTiles||(e?e.intersectsClippingArea&&(f(!e.loaded),f(!e.leaf),f(e.level===c.level)):f(null==u?.rootTiles||!c.shouldHaveNeighbor(t)))}const G=t(1===q?S:y,P,D),H=t(0===q?v:L,E,w),J=z?.samplerData,K=t(1===q?1:0,b,U),Q=t(0===q?1:0,T,C),X=1===J?.length?J[0]:null,Y=(t,e)=>X?i(t,e,X)??0:r(t,e,J)??0,Z=W?(t,e)=>.5*(Y(t,e)+F(t,e)):F,$=(S-y)/d,_=a?1===q?$:-$:0,tt=a?0:0===q?$:-$,nt=-_,ot=-tt;let st=0,rt=0,it=0;{const e=0/d,n=a?G:t(y*(1-e)+S*e,P,D),o=a?t(L*(1-e)+v*e,E,w):H,s=Z(n,o);st=n*V,rt=I(o),it=s}let at=0,ct=0,lt=0;{const e=1/d,n=a?G:t(y*(1-e)+S*e,P,D),o=a?t(L*(1-e)+v*e,E,w):H,s=Z(n,o);at=n*V,ct=I(o),lt=s}for(let e=1;e<h-1;++e){const n=e/d,s=at,i=ct,c=lt;{const r=a?K:t(n,b,U),l=a?t(n,T,C):Q,u=s-O,d=i-R,f=c-N;Lt(s,d,f,A),o.setEdgeVertexFromValuesRawPositionUV(q,e,u,d,f,r,l)}{const n=(e+1)/d,o=a?G:t(y*(1-n)+S*n,P,D),s=a?t(L*(1-n)+v*n,E,w):H,r=Z(o,s);at=o*V,ct=I(s),lt=r}const l=at,u=lt,f=st,m=rt,g=it;st=s,rt=i,it=c;let h=0,x=0,M=0;if(a){const e=ct-i,o=u-c,a=m-i,l=g-c,d=t(L*(1-n)+v*n,E,w),f=G+nt,y=f*V-s,S=r(f,d,p)-c,B=3===q?-1:1;if(h=B*(-a+e)*S,x=B*y*(-l+o),M=-B*y*(-a+e),W){const t=G+_,n=t*V-s;h=(-a+e)*(S-(r(t,d,J)-c)),x=(y-n)*(-l+o),M=-(y-n)*(-a+e)}}else{const e=l-s,o=u-c,a=f-s,d=g-c,m=t(y*(1-n)+S*n,P,D),L=H+ot,v=r(m,L,p)-c,B=I(L)-i,V=2===q?-1:1;if(h=V*B*(-d+o),x=V*(-a+e)*v,M=-V*B*(-a+e),W){const t=m,n=H+tt,s=I(n)-i;h=(-B+s)*(-d+o),x=(-a+e)*(-v+(r(t,n,J)-c)),M=-(-B+s)*(-a+e)}}const B=1/Math.sqrt(h*h+x*x+M*M);o.setEdgeNormalFromValues(q,e,h*B,x*B,M*B)}}}function k(t){nt(t)}function z(t,e){return(Math.PI/2-2*Math.atan(Math.exp(-t/e)))*e}function G(t,e){return t*e}function H(t,e,n){return t?t=>z(t,e):t=>G(t,n)}function J(t,e,n){const{numVerticesPerSide:o,vertexAttributes:s,maxEdgeVertexCount:r}=t,i=o-1,a=s.count,l=2*(o-3)*(o-3),u=4*(i+r-3),d=c.reduce((e,n)=>e+(i+t.getEdgeCount(n)-3),0),f=e.reduce((t,e)=>t+i*(2*(e.latitudeResolution-1)+1),0),m=3*(n?2:1),g=(l+u+f)*m,h=a>=y?new Uint32Array(g):new Uint16Array(g);for(let c=0;c<g;++c)h[c]=0;t.indices=h,t.indexCount=(l+d+f)*m,t.poleIndicesStartIndex=l*m,t.edgeIndicesStartIndex=(l+f)*m,n?(Y(t),Z(t,e),$(t)):(K(t),Q(t,e),X(t))}function K(t){const{numVerticesPerSide:e,indices:n,vertexAttributes:o}=t,{position:s}=o,{typedBuffer:r,typedBufferStride:i}=s,a=e-2,c=e-3,l=0,u=e-3;let d=0;for(let f=0;f<c;++f){const t=f*a;for(let e=l;e<u;++e){const o=t+e,s=o+1,c=s+a,l=c-1;Bt(o,s,c,l,i,r)?(n[d]=o,n[d+1]=s,n[d+2]=c,n[d+3]=c,n[d+4]=l,n[d+5]=o):(n[d]=o,n[d+1]=s,n[d+2]=l,n[d+3]=l,n[d+4]=s,n[d+5]=c),d+=6}}}function Q(t,e){const{numVerticesPerSide:n,indices:o,poleIndicesStartIndex:s}=t,r=n-1;let i=s;for(const a of e){const e=a.isNorth?1:2,s=a.isNorth?2:1,c=a.isNorth?3:4,l=a.isNorth?4:3;let u=t.getEdgeVertexIndex(a.connectedOuterEdgeOffset,0),d=1;for(let t=0;t<a.latitudeResolution;++t){const f=0===t?a.rowOffset:u+n;for(let n=0;n<r;n++){const r=f+n;o[i]=u,o[i+e]=u+1,o[i+s]=r,t<a.latitudeResolution-1?(o[i+c]=u+1,o[i+l]=r+1,o[i+5]=r,i+=6):i+=3,u+=d}u=f,d=1}}}function X(t){const{indices:e,numVerticesPerSide:n,edgeIndicesStartIndex:o}=t,s=n-1,r=s-2;let i=o;for(let a=0;a<4;++a){const n=St[a];let o=0,c=0;const l=t.getEdgeCount(a),u=n.count;f(u===s-1);const d=1===a||2===a,m=d?1:2,g=d?2:1,h=t.getEdgeFirstVertexIndex(a),p=1,x=n.vertex0Index,M=n.stride;for(;o<l-1||c<u-1;){const t=x+c*M,n=h+o*p,a=o<l-1,d=c<u-1,f=a&&(!d||(a?0+s*(o+.5)/(l-1):0)<=(d?1+r*(c+.5)/(u-1):0));f?++o:++c;const y=f?n+p:t+M;e[i]=t,e[i+m]=n,e[i+g]=y,i+=3}}t.indexCount=i}function Y(t){const{indices:e,numVerticesPerSide:n,vertexAttributes:o}=t,{position:s}=o,{typedBuffer:r,typedBufferStride:i}=s,a=n-2;let c=0;for(let l=0;l<n-3;++l){const t=l*a;for(let o=0;o<n-3;++o){const n=l*a+o,s=n+1,u=s+a,d=u-1,f=t+o,m=f+1,g=m+a;Bt(f,m,g,g-1,i,r)?(Vt(e,c,n,s,u),c+=6,Vt(e,c,u,d,n)):(Vt(e,c,n,s,d),c+=6,Vt(e,c,d,u,s)),c+=6}}}function Z(t,e){const{indices:n,numVerticesPerSide:o,poleIndicesStartIndex:s}=t,r=o-1;let i=s;for(const a of e){const e=a.connectedOuterEdgeOffset;let s=t.getEdgeVertexIndex(e,0),c=1;for(let t=0;t<a.latitudeResolution;++t){const e=0===t?a.rowOffset:s+o;for(let o=0;o<r;o++)Vt(n,i,s,s+1,e+o),i+=6,t<a.latitudeResolution-1&&(Vt(n,i,s+1,e+o+1,e+o),i+=6),s+=c;s=e,c=1}}}function $(t){const{indices:e,numVerticesPerSide:n,edgeIndicesStartIndex:o}=t,s=n-1,r=s-2;let i=o;for(let a=0;a<4;++a){const n=St[a];let o=0,c=0;const l=t.getEdgeCount(a),u=n.count;f(u===s-1);const d=1===a||2===a,m=d?1:3,g=d?3:1,h=t.getEdgeFirstVertexIndex(a),p=1,x=n.vertex0Index,M=n.stride;for(;o<l-1||c<u-1;){const t=x+c*M,n=h+o*p,a=o<l-1,d=c<u-1,f=a&&(!d||(a?0+s*(o+.5)/(l-1):0)<=(d?1+r*(c+.5)/(u-1):0));f?++o:++c;const y=f?n+p:t+M;e[i]=t,e[i+m]=n,e[i+m+1]=n,e[i+g]=y,e[i+g+1]=y,e[i+5]=t,i+=6}}t.indexCount=i}function _(t){const{geometry:e,geometryState:n}=t,{edgeResolutions:o}=n,{numVerticesPerSide:s,edgeVerticesStartIndex:r}=e,i=s-2;let a=r;for(let c=0;c<4;++c){{const t=0===c||2===c,e=(0===c?i-1:0)*i+(1===c?i-1:0),n=(t?0:1)*i+(t?1:0),o=St[c];o.vertex0Index=e,o.stride=n,o.count=i}{const t=o[c]+1;e.outerEdgesOffsetAndLength[2*c+0]=a,e.outerEdgesOffsetAndLength[2*c+1]=t,a+=t}}}function tt(t){_(t),t.geometryState.wireframe?$(t.geometry):X(t.geometry)}function et(o,s,r){const{geometryState:i,geometry:a,tile:c,localOrigin:l}=o,u=1===s||3===s,d=i.edgeResolutions[s];f(e(d));const m=d+1,{boundingBox:g,minu:h,minv:p,maxu:x,maxv:M,vertexAttributes:y}=a,S=t(1===s?1:0,h,x),L=t(0===s?1:0,p,M),v=r.renderData,B=v.geometryState,V=v.geometry,I=(s+2)%4,b=V.getEdgeCount(I),T=c.getNeighborEdgeStartVertexIndex(s,r)*d,U=d*2**(c.level-r.level);f(B.edgeResolutions[I]===U),f(b-1===U);const C=v.localOrigin[0]-l[0],A=v.localOrigin[1]-l[1],P=v.localOrigin[2]-l[2],D=a.getEdgeFirstVertexIndex(s),{position:E,uv0:w}=y,O=E.typedBuffer,R=E.typedBufferStride,N=y.normalCompressed,j=N.typedBuffer,F=N.typedBufferStride,q=V.vertexAttributes,W=V.getEdgeFirstVertexIndex(I),k=q.position.typedBuffer,z=q.position.typedBufferStride,G=q.normalCompressed.typedBuffer,H=q.normalCompressed.typedBufferStride;for(let e=1;e<m-1;++e){const o=D+e,s=W+(T+e),r=o*R,i=s*z,a=k[i]+C,c=k[i+1]+A,l=k[i+2]+P;O[r]=a,O[r+1]=c,O[r+2]=l,Lt(a,c,l,g);const f=o*F,m=s*H;j[f]=G[m],j[f+1]=G[m+1];const y=e/d,v=u?S:t(y,h,x),B=u?t(y,p,M):L;w.setValues(o,Math.round(v*n),Math.round(B*n))}}function nt(e){const{geometry:o,geometryState:s,localOrigin:i}=e,{clippingArea:a,samplerData:c}=s,{minu:l,minv:u,maxu:d,maxv:m,boundingBox:g,vertexAttributes:h}=o,p=e.tile,{surface:M,ellipsoid:y,extent:S,extentInRadians:L,horizontalScale:v}=p,B="local"===M.view?.viewingMode,V=y.radius;let I=0,b=0,T=0;const U=(t,e,n)=>{const o=L[0===e?1:3],s=L[0===t?0:2],r=Math.cos(o),i=Math.sin(o),a=Math.sin(s),c=Math.cos(s),l=V+n;I=c*r*l,b=a*r*l,T=i*l},C=B?(()=>{const e=a,n=null!=e&&(S[3]>e[3]||S[2]>e[2]||S[1]<e[1]||S[0]<e[0]),o=H(M.isWebMercatorOnPlateCarree,V,v);return(s,r,i)=>{const a=0===s?S[0]:S[2],c=0===r?S[1]:S[3],l=n?t(a,e[0],e[2]):a,u=n?t(c,e[1],e[3]):c,d=i;I=l*v,b=o(u),T=d}})():U;let A=0,P=0,D=0,E=0,w=0,R=0,N=0,j=0,F=0;const q=B&&M.isWebMercatorOnPlateCarree,W=(t,e,n,o,s)=>{let r=0,i=0,a=0;if(B){const t=e*v,s=q?(Math.PI/2-2*Math.atan(Math.exp(-n/V)))*V:n*v;r=t-I,i=s-b,a=o-T}else{const s=O(t),c=t.tile,l=c.extent,u=c.extentInRadians,d=(e-l[0])/(l[2]-l[0]),f=(n-l[1])/(l[3]-l[1]),m=u[0]*(1-d)+u[2]*d,g=s(f),h=Math.cos(g),p=Math.sin(g),x=Math.sin(m),M=Math.cos(m),y=V+o;r=M*h*y-I,i=x*h*y-b,a=p*y-T}switch(s){case 0:N+=r,j+=i,F+=a;break;case 1:E-=r,w-=i,R-=a;break;case 2:N-=r,j-=i,F-=a;break;case 3:E+=r,w+=i,R+=a}},k=a??pt,z=S[0],G=S[2],J=S[1],K=S[3],Q=[K>k[3],G>k[2],J<k[1],z<k[0]],X=Math.max(z,k[0]),Y=Math.min(G,k[2]),Z=Math.max(J,k[1]),$=Math.min(K,k[3]),_=t=>Math.max(k[0],Math.min(k[2],t)),tt=t=>Math.max(k[1],Math.min(k[3],t)),et=t=>{const e=s.cornerNeighborCornerTiles;A=0,P=0,D=1,E=0,w=0,R=0,N=0,j=0,F=0;let n=1/0;for(let s=0;s<4;++s){const o=e[4*t+s];n=Math.min(n,o?.level??1/0)}for(let s=0;s<4;++s){const o=e[4*t+s];xt[s]=o?.level===n?o:null}let o=1,i=0;for(let s=0;s<4;++s){const t=xt[s];t&&(o=Math.max(o,t?.renderData.geometryState.numVerticesPerSide),i=t.extent[2]-t.extent[0])}const a=i,c=o;f(c>1);const l=a/c;for(let s=0;s<4;++s){const t=xt[(s+3)%4],e=xt[s%4];if(!t&&!e)continue;const n=0===s?1:1===s?2:2===s?3:0,o=0===s?2:1===s?3:2===s?0:1;if(t&&e){const i=at[s][0]*l,a=at[s][1]*l,c=t.extent,u=_(c[0===n||1===n?2:0]+i),d=tt(c[0===n||3===n?3:1]+a),f=e.extent,m=_(f[0===o||1===o?2:0]+i),g=tt(f[0===o||3===o?3:1]+a),h=t.renderData,p=e.renderData,x=r(u,d,h.geometryState.samplerData),M=r(m,g,p.geometryState.samplerData);W(h,u,d,.5*(x+M),s)}else{const i=t??e,a=t?n:o,c=i.extent,u=at[s],d=_(c[0===a||1===a?2:0]+u[0]*l),f=tt(c[0===a||3===a?3:1]+u[1]*l),m=i.renderData,g=r(d,f,m.geometryState.samplerData);W(m,d,f,g,s)}}if(!B){const t=Math.sqrt(I*I+b*b+T*T);A=I/t,P=b/t,D=T/t}if(B||D*D<.999){const t=Math.sqrt(E*E+w*w+R*R);E/=t,w/=t,R/=t;const e=Math.sqrt(N*N+j*j+F*F);N/=e,j/=e,F/=e,A=R*j-w*F,P=E*F-R*N,D=w*N-E*j;const n=1/Math.sqrt(A*A+P*P+D*D);A*=n,P*=n,D*=n}},nt=s.cornerNeighborCornerTiles;for(let O=0;O<4;++O){const e=O,a=(O+1)%4,M=0===O||1===O?1:0,y=0===O||3===O?1:0,S=t(M,l,d),L=t(y,u,m),v=o.getEdgeFirstVertexIndex(e),B=o.getEdgeCount(e),V=0===O||3===O?B-1:0,U=o.getEdgeFirstVertexIndex(a),E=o.getEdgeCount(a),w=0===O||1===O?E-1:0;let R=-1;for(let t=0;t<4;++t){const e=nt[4*O+t],n=nt[4*O+R];e&&(-1===R||x(n,e)>0)&&(R=t)}const N=R,j=nt[4*O+N];if(j!==p){const t=p.level-j.level,e=2**t,o=[j.lij[0]+t,j.lij[1]*e,j.lij[2]*e],r=[o[1]+e===p.lij[1],0===O&&(1===N||0===N&&j!==nt[4*O+3])||1===O&&(0===N||1===N&&j!==nt[4*O+2]),o[1]===p.lij[1]+1,2===O&&(3===N||2===N&&j!==nt[4*O+1])||3===O&&(2===N||3===N&&j!==nt[4*O+0])],a=r.reduce((t,e)=>t+(e?1:0),0);f(1===a||2===a);let c=-1,l=-1;const u=j.renderData;if(1===a){const t=r.findIndex(t=>t);f(0<=t&&t<=3),c=(t+2)%4;const e=s.edgeResolutions[t];l=p.getNeighborEdgeStartVertexIndex(t,j)*e+e*(0===t&&0===O||1===t&&0===O||2===t&&1===O||3===t&&3===O?1:0)}else{f(r[1]||r[3]),c=r[1]?3:1;const t=u.geometryState.edgeResolutions[c];l=0===O||3===O?0:t}const d=u.geometry;{const t=v+V,e=U+w,o=d.getEdgeFirstVertexIndex(c)+l,s=d.vertexAttributes,r=u.localOrigin,a=s.position,f=a.typedBuffer,m=o*a.typedBufferStride,p=f[m]+r[0]-i[0],x=f[m+1]+r[1]-i[1],M=f[m+2]+r[2]-i[2];Lt(p,x,M,g);const y=h.position,B=y.typedBuffer,I=t*y.typedBufferStride;B[I]=p,B[I+1]=x,B[I+2]=M;const b=e*y.typedBufferStride;B[b]=p,B[b+1]=x,B[b+2]=M;const T=h.uv0;T.setValues(t,Math.round(S*n),Math.round(L*n)),T.setValues(e,Math.round(S*n),Math.round(L*n));{const n=s.normalCompressed.typedBuffer,r=o*s.normalCompressed.typedBufferStride,i=h.normalCompressed,a=i.typedBuffer;{const e=t*i.typedBufferStride;a[e]=n[r],a[e+1]=n[r+1]}{const t=e*i.typedBufferStride;a[t]=n[r],a[t+1]=n[r+1]}}}}else{const n=Q[e],s=Q[a];let l;if(n||s){const e=t(z*(1-M)+G*M,X,Y),n=t(J*(1-y)+K*y,Z,$);l=r(e,n,c)}else l=ot(nt,O);C(M,y,l),et(O);const u=I-i[0],d=b-i[1],f=T-i[2];Lt(u,d,f,g),o.setEdgeVertexFromValuesRawPositionUVNormal(e,V,u,d,f,S,L,A,P,D),o.setEdgeVertexFromValuesRawPositionUVNormal(a,w,u,d,f,S,L,A,P,D)}}for(let t=0;t<4;++t)xt[t]=null}function ot(t,e){const n=4*e,o=c.reduce((e,o)=>Math.min(e,t[n+o]?.level??1/0),1/0);m&&(f(!t[n+0]||!t[n+2]||p(t[n+0],t[n+2],5)),f(!t[n+1]||!t[n+3]||p(t[n+1],t[n+3],7)));let s=0,i=0;for(let c=0;c<4;++c){const e=t[n+c];if(e?.level===o){const t=0===c||1===c,n=0===c||3===c,o=e.extent,a=o[t?0:2],l=o[n?1:3],u=e.renderData?.geometryState?.samplerData;i+=r(a,l,u),s++}}const a=s?i/s:0;return f(null!=a),a}function st(t){const{vao:e,geometry:n}=t,{vertexAttributes:o,edgeVerticesStartIndex:s}=n,r=o.position.typedBuffer;e.buffer()?.setSubData(r,s,s,r.length)}function rt(t){const{vao:e,geometry:n}=t,{indices:o,indexCount:s,edgeIndicesStartIndex:r}=n;e.indexBuffer.setSubData(o,r,r,s)}class it{constructor(t,e,n,o,s){this.isNorth=t,this.connectedRowOffset=e,this.connectedOuterEdgeOffset=n,this.rowOffset=o,this.latitudeResolution=s}}const at=[[0,1],[1,0],[0,-1],[-1,0]],ct=new a,lt=.5*d,ut=new Uint16Array(u+1),dt=new Int32Array(u+1),ft=new Int32Array(u+1),mt=new Int32Array(u+1),gt=new Float64Array(u+1),ht=new Float64Array(u+1),pt=s(-1/0,-1/0,1/0,1/0),xt=[null,null,null,null];function Mt(t,e,n){if(!e)return!1;const o=x(t,e);return o>0||0===o&&n>=2}class yt{constructor(){this.vertex0Index=0,this.stride=1,this.count=0}getVertexIndex(t){return f(0<=t&&t<this.count),this.vertex0Index+this.stride*t}}const St=[new yt,new yt,new yt,new yt];function Lt(t,e,n,o){t<o[0]?o[0]=t:t>o[3]&&(o[3]=t),e<o[1]?o[1]=e:e>o[4]&&(o[4]=e),n<o[2]?o[2]=n:n>o[5]&&(o[5]=n)}function vt(t){const{edgeResolutions:e,numVerticesPerSide:n}=t,o=1+Math.max(...e);return Math.max(n,o)}function Bt(t,e,n,o,s,r){const i=t*s,a=r[i],c=r[i+1],l=r[i+2],u=e*s,d=r[u],f=r[u+1],m=r[u+2],g=n*s,h=r[g],p=r[g+1],x=r[g+2],M=o*s,y=r[M],S=r[M+1],L=r[M+2];return(d-y)*(d-y)+(f-S)*(f-S)+(m-L)*(m-L)>(a-h)*(a-h)+(c-p)*(c-p)+(l-x)*(l-x)}function Vt(t,e,n,o,s){t[e]=n,t[e+1]=o,t[e+2]=o,t[e+3]=s,t[e+4]=s,t[e+5]=n}const It=6;export{R as createPlanarGlobePatch,S as createSphericalGlobePatch,j as updateEdgeElevationsAndResolutionsPlanar,U as updateEdgeElevationsAndResolutionsSpherical,F as updateEdgesAndCornersPlanar,T as updateEdgesAndCornersSpherical};
2
+ import{clamp as t,isPowerOfTwo as e}from"../../../core/mathUtils.js";import{maxUint16 as n}from"../../../core/typedArrayUtil.js";import{empty as o}from"../../../geometry/support/aaBoundingBox.js";import{fromValues as r}from"../../../geometry/support/aaBoundingRect.js";import{sampleElevation as s,sampleSingleElevation as i}from"./ElevationData.js";import{PatchGeometryLUT as a}from"./PatchGeometryLUT.js";import{zeroToFour as c,neighborTileIfLoadedOrSelf as l}from"./PatchRenderData.js";import{maxPatchTesselation as u,elevationNoDataValue as d}from"./TerrainConst.js";import{internalAssert as f,enableTerrainInternalChecks as m,neighborEdgeIndices as g,almostEquals as h}from"./terrainUtils.js";import{isCornerNeighbor as p}from"./Tile.js";import{compareTilesByLij as x}from"./tileUtils.js";import{compressNormal as M}from"../webgl-engine/lib/Normals.js";const y=65536;function S(t,e){const{tile:n,geometry:r,geometryState:s}=t,{extentInRadians:i,surface:a}=n,{isWebMercator:c,renderer:l}=a,{numVerticesPerSide:u,wireframe:d}=s,f=u-1,m=(u-2)**2,g=c&&(2===e||3===e),h=c&&(1===e||3===e),p=((g?1:0)+(h?1:0))*It*u,x=vt(s),M=m+p+4*x,y=l.tileGeometryCache.acquire(M);r.numVerticesPerSide=u,r.vertexAttributes=y,r.maxEdgeVertexCount=x;const{boundingBox:S}=r;o(S);const B=O(t);ct.update(f,i,B),v(t),r.poleVerticesStartIndex=m;const V=L(t,g,h);r.edgeVerticesStartIndex=m+p,_(t),C(t),J(r,V,d),t.intersectionData=null}function L(t,e,o){const{tile:r,localOrigin:s,geometry:i}=t,{extent:a,ellipsoid:c}=r,{boundingBox:l,numVerticesPerSide:u,vertexAttributes:d,poleVerticesStartIndex:f}=i,m=u-1,g=s[0],h=s[1],p=s[2],x=c.radius,y=a[1],S=a[3],L=[];let v=f;const B=(t,e)=>{const o=e*u;Lt(-g,-h,t*x-p,l),L.push(new it(1===t,o,1===t?0:2,v,It));const r=D(-1===t?y:S,x),s=t*Math.PI/2-r,i=.99*(1===t?1:-1),a=x+0,{position:c,uv0:f}=d,{typedBuffer:B,typedBufferStride:V}=d.normalCompressed;for(let u=1;u<=It;++u){const t=r+s*(u/It),e=Math.cos(t),o=Math.sin(t);for(let r=0;r<=m;r++){const t=r/m,s=ct.sinLonLUT[r],u=ct.cosLonLUT[r]*e,d=s*e,x=o,y=u*a-g,S=d*a-h,L=x*a-p;Lt(y,S,L,l),c.setValues(v,y,S,L),f.setValues(v,Math.round(t*n),Math.round(i*n)),M(B,v,u,d,x,V),++v}}};return e&&B(-1,0),o&&B(1,m),L}function v(t){const e=t.geometryState.samplerData,n=1===e?.length?e[0]:null;n?B(t,n):V(t)}function B(t,e){const{tile:n}=t;if(!n.intersectsClippingArea)return;const{geometry:o,geometryState:r,localOrigin:s}=t,{numVerticesPerSide:i}=r,a=i-2,c=i-1,{vertexAttributes:l,boundingBox:u}=o,{position:d,uv0:f}=l,{typedBuffer:m,typedBufferStride:g}=l.normalCompressed,{extent:h}=n,p=n.ellipsoid.radius,x=s[0],y=s[1],S=s[2],L=d.typedBuffer,v=d.typedBufferStride,B=f.typedBuffer,V=f.typedBufferStride;I(c,h,e);let T=0;const U=e.data.values;if(1<=a){const t=ut[1],e=ct.sinLatLUT[1],n=ct.cosLatLUT[1];for(let o=1;o<=a;o++){const r=ct.sinLonLUT[o],s=ct.cosLonLUT[o],i=p+b(o,1,U),a=i*s*n-x,c=i*r*n-y,l=i*e-S;Lt(a,c,l,u);const d=(o-1)*v;L[d]=a,L[d+1]=c,L[d+2]=l;const f=(o-1)*V;B[f]=ut[o],B[f+1]=t}}for(let I=1;I<=a;I++){const t=ct.sinLatLUT[I],e=ct.cosLatLUT[I],n=I+1,o=ut[n],r=ct.sinLatLUT[n],s=ct.cosLatLUT[n],i=ct.sinLonLUT[0],l=ct.cosLonLUT[0],d=p+b(0,I,U);let f=l*e*d-x,h=i*e*d-y,C=t*d-S;const A=T*v;let P=L[A],D=L[A+1],E=L[A+2];for(let w=1;w<=a;w++){const i=ct.sinLonLUT[w],l=ct.cosLonLUT[w];let d=0,A=0,O=0;if(w<a){const t=(T+1)*v;d=L[t],A=L[t+1],O=L[t+2]}else{const n=ct.sinLonLUT[c],o=ct.cosLonLUT[c],r=p+b(c,I,U);d=o*e*r-x,A=n*e*r-y,O=t*r-S}const R=f,N=h,j=C;f=P,h=D,C=E,P=d,D=A,E=O;const F=d-R,q=A-N,W=O-j;let k=0,z=0,G=0;if(I>1){const t=(T-a)*v;k=L[t],z=L[t+1],G=L[t+2]}else{const t=ct.sinLatLUT[0],e=ct.cosLatLUT[0],n=p+b(w,0,U);k=l*e*n-x,z=i*e*n-y,G=t*n-S}const H=p+b(w,n,U),J=l*s*H-x,K=i*s*H-y,Q=r*H-S;if(I<a){const t=T+a,e=t*v;L[e]=J,L[e+1]=K,L[e+2]=Q,Lt(J,K,Q,u);const n=t*V;B[n]=ut[w],B[n+1]=o}const X=k-J,Y=z-K,Z=G-Q;let $=l*e,_=i*e,tt=t;tt*tt<.999&&($=W*Y-q*Z,_=F*Z-W*X,tt=q*X-F*Y);const et=1/Math.sqrt($*$+_*_+tt*tt);M(m,T,$*et,_*et,tt*et,g),++T}}}function V(t){const{tile:e}=t;if(!e.intersectsClippingArea)return;const{geometry:o,geometryState:r,localOrigin:i}=t,{numVerticesPerSide:a,samplerData:c}=r,l=a-2,u=a-1,{vertexAttributes:d,boundingBox:f}=o,{position:m,uv0:g}=d,{typedBuffer:h,typedBufferStride:p}=d.normalCompressed,{extent:x}=e,y=x[0],S=x[2],L=x[1],v=x[3],B=e.ellipsoid.radius,V=i[0],I=i[1],b=i[2],T=m.typedBuffer,U=m.typedBufferStride,C=1/u;let A=0;if(1<=l){const t=C,e=L*(1-t)+v*t,o=ct.sinLatLUT[1],r=ct.cosLatLUT[1];for(let i=1;i<=l;i++){const a=i*C,l=y*(1-a)+S*a,u=ct.sinLonLUT[i],d=ct.cosLonLUT[i],m=B+s(l,e,c),h=m*d*r-V,p=m*u*r-I,x=m*o-b;Lt(h,p,x,f);const M=(i-1)*U;T[M]=h,T[M+1]=p,T[M+2]=x,g.setValues(i-1,Math.round(a*n),Math.round(t*n))}}for(let P=1;P<=l;P++){const t=P*C,e=L*(1-t)+v*t,o=ct.sinLatLUT[P],r=ct.cosLatLUT[P],i=P+1,a=i*C,d=L*(1-a)+v*a,m=ct.sinLatLUT[i],x=ct.cosLatLUT[i],D=ct.sinLonLUT[0],E=ct.cosLonLUT[0],w=B+s(y,e,c);let O=E*r*w-V,R=D*r*w-I,N=o*w-b;const j=A*U;let F=T[j],q=T[j+1],W=T[j+2];for(let v=1;v<=l;v++){const t=v*C,i=y*(1-t)+S*t,D=ct.sinLonLUT[v],E=ct.cosLonLUT[v];let w=0,j=0,k=0;if(v<l){const t=(A+1)*U;w=T[t],j=T[t+1],k=T[t+2]}else{const t=ct.sinLonLUT[u],n=ct.cosLonLUT[u],i=B+s(S,e,c);w=n*r*i-V,j=t*r*i-I,k=o*i-b}const z=O,G=R,H=N;O=F,R=q,N=W,F=w,q=j,W=k;const J=w-z,K=j-G,Q=k-H;let X=0,Y=0,Z=0;if(P>1){const t=(A-l)*U;X=T[t],Y=T[t+1],Z=T[t+2]}else{const t=ct.sinLatLUT[0],e=ct.cosLatLUT[0],n=B+s(i,L,c);X=E*e*n-V,Y=D*e*n-I,Z=t*n-b}const $=B+s(i,d,c),_=E*x*$-V,tt=D*x*$-I,et=m*$-b;if(P<l){const e=A+l,o=e*U;T[o]=_,T[o+1]=tt,T[o+2]=et,Lt(_,tt,et,f),g.setValues(e,Math.round(t*n),Math.round(a*n))}const nt=X-_,ot=Y-tt,rt=Z-et;let st=E*r,it=D*r,at=o;at*at<.999&&(st=Q*ot-K*rt,it=J*rt-Q*nt,at=K*nt-J*ot);const lt=1/Math.sqrt(st*st+it*it+at*at);M(h,A,st*lt,it*lt,at*lt,p),++A}}}function I(e,o,r){const s=o[0],i=o[2],a=o[1],c=o[3],l=1/e,{dx:u,dy:d,x0:f,y1:m,safeWidth:g}=r,h=r.data.width;for(let p=0;p<=e;p++){const e=p*l,o=t(u*(s*(1-e)+i*e-f),0,g),r=Math.floor(o);dt[p]=r,gt[p]=o-r;const x=t(d*(m-(a*(1-e)+c*e)),0,g),M=Math.floor(x);ft[p]=M*h,mt[p]=(M+1)*h,ht[p]=x-M,ut[p]=Math.round(e*n)}}function b(t,e,n){const o=dt[t],r=gt[t],s=ft[e],i=mt[e],a=ht[e],c=s+o,l=n[c],u=n[c+1],d=n[i+o],f=n[i+o+1];if(l+d+u+f>=lt)return 0;const m=l+(u-l)*r;return m+(d+(f-d)*r-m)*a}function T(t){t.tile.intersectsClippingArea&&(C(t),rt(t),t.intersectionData=null)}function U(t){t.tile.intersectsClippingArea&&(tt(t),C(t),rt(t),st(t),t.intersectionData=null)}function C(t){t.tile.intersectsClippingArea&&(P(t),A(t))}function A(t){const{geometry:o,geometryState:r,tile:a,localOrigin:c}=t,{level:u,extent:d,extentInRadians:p,ellipsoid:y}=a,S=y.radius,L=p[0],v=p[2],B=p[1],V=p[3],{samplerData:I}=r,b=d[0],T=d[2],U=d[1],C=d[3],A=O(t),{boundingBox:P,vertexAttributes:D}=o,E=c[0],w=c[1],R=c[2],{position:N,uv0:j}=D,F=N.typedBuffer,q=N.typedBufferStride,W=j.typedBuffer,k=j.typedBufferStride,{typedBuffer:z,typedBufferStride:G}=D.normalCompressed,H=1===I?.length?I[0]:null,J=(t,e,n)=>H?i(t,e,H)??0:s(t,e,I)??0;for(let O=0;O<4;++O){const c=1===O||3===O,p=r.edgeResolutions[O];f(e(p));const y=p+1,D=l(a,r.edgePeerNeighbors[O]);if(Mt(a,D,O)){if(et(t,O,D))continue}const N=null!=D;f(!N||D.level===a.level),f(!N||x(a,D)<=0);const j=D?.renderData,K=j?.geometryState;if(m){const t=a.surface;if(!D&&t&&!t.updatingRootTiles){const e=g[O],n=a.findNeighborTile(e,t=>t.loaded||t.leaf||t.level===a.level);n?n.intersectsClippingArea&&(f(!n.loaded),f(!n.leaf),f(n.level===u)):f(null==t?.rootTiles||!a.shouldHaveNeighbor(e))}}const Q=1===O?d[2]:d[0],X=D?.extent,Y=X&&c?1===O?X[0]:X[2]:Q,Z=0===O?d[3]:d[1],$=1===O?1:0,_=0===O?1:0,tt=1===O?v:L,nt=0===O?V:B,ot=Math.sin(tt),rt=Math.cos(tt),st=Math.sin(nt),it=Math.cos(nt),at=K?.samplerData,ct=1===at?.length?at[0]:null,lt=(t,e,n)=>ct?i(n,e,ct)??0:s(n,e,at)??0,ut=N?(t,e,n)=>.5*(J(t,e)+lt(t,e,n)):J,dt=o.outerEdgesOffsetAndLength[2*O+0],ft=null!=H||null!=I&&I.some(t=>null!=t),mt=null!=ct||null!=at&&at.some(t=>null!=t),gt=ft||mt,ht=1/p,pt=n*ht,xt=$*n,yt=_*n,St=dt;f(!X||h(X[2]-X[0],d[2]-d[0]));(()=>{const t=1===O?-1:3===O?1:0,e=0===O?-1:2===O?1:0,n=(d[2]-d[0])*ht,o=t*n,r=e*n,a=c?t*((v-L)*ht):0,l=c?0:e*ht,u=_,f=c?tt+a:tt,m=c?Math.sin(f):ot,g=c?Math.cos(f):rt,h=c?tt-a:tt,p=c?Math.sin(h):ot,x=c?Math.cos(h):rt,B=c?nt:A(u+l),V=c?st:Math.sin(B),D=c?it:Math.cos(B),j=c?nt:A(u-l),J=c?st:Math.sin(j),K=c?it:Math.cos(j);let X=0,$=0,et=0;{const t=0*ht,e=c?Q:b*(1-t)+T*t,n=c?Y:e,o=c?U*(1-t)+C*t:Z,r=c?tt:L*(1-t)+v*t,s=c?ot:Math.sin(r),i=c?rt:Math.cos(r),a=c?A(t):nt,l=c?Math.sin(a):st,u=c?Math.cos(a):it,d=S+ut(e,o,n);X=i*u*d,$=s*u*d,et=l*d}let lt=0,dt=0,ft=0;{const t=1*ht,e=c?Q:b*(1-t)+T*t,n=c?Y:e,o=c?U*(1-t)+C*t:Z,r=c?tt:L*(1-t)+v*t,s=c?ot:Math.sin(r),i=c?rt:Math.cos(r),a=c?A(t):nt,l=c?Math.sin(a):st,u=c?Math.cos(a):it,d=S+ut(e,o,n);lt=i*u*d,dt=s*u*d,ft=l*d}for(let d=1;d<y-1;++d){let t=0,e=0,n=0;{const o=(d+1)*ht,r=c?Q:b*(1-o)+T*o,s=c?Y:r,i=c?U*(1-o)+C*o:Z,a=c?tt:L*(1-o)+v*o,l=c?ot:Math.sin(a),u=c?rt:Math.cos(a),f=c?A(o):nt,m=c?Math.sin(f):st,g=c?Math.cos(f):it,h=S+ut(r,i,s);t=u*g*h,e=l*g*h,n=m*h}const a=t,l=e,u=n,f=lt,h=dt,y=ft;lt=a,dt=l,ft=u;{const t=St+d,e=t*q,n=f-E,o=h-w,r=y-R;F[e]=n,F[e+1]=o,F[e+2]=r,Lt(n,o,r,P);const s=Math.round(d*pt),i=t*k;W[i]=c?xt:s,W[i+1]=c?s:yt}const B=X,j=$,_=et;X=f,$=h,et=y;const mt=f,Mt=h,vt=y,Bt=1/Math.sqrt(mt*mt+Mt*Mt+vt*vt),Vt=vt*Bt;let It=0,bt=0,Tt=0;if(gt&&Vt*Vt<.999){let t=0,e=0,n=0;{const o=0===O?-1:1;t=o*(a-B),e=o*(l-j),n=o*(u-_)}{const a=d*ht,l=c?Q:b*(1-a)+T*a,u=c?Y:l,f=c?U*(1-a)+C*a:Z,h=c?tt:L*(1-a)+v*a,M=c?ot:Math.sin(h),y=c?rt:Math.cos(h),B=c?A(a):nt,P=c?Math.sin(B):st,E=c?Math.cos(B):it;let w=mt,R=Mt,j=vt;if(N){const t=u-o,e=f-r,n=S+(ct?i(t,e,ct)??0:s(t,e,at)??0),a=c?E:K;w=(c?x:y)*a*n,R=(c?p:M)*a*n,j=(c?P:J)*n}{const a=l+o,u=f+r,d=S+(H?i(a,u,H)??0:s(a,u,I)??0),h=c?E:D,p=(c?g:y)*h*d,x=(c?m:M)*h*d,L=(c?P:V)*d;N||(w=2*mt-p,R=2*Mt-x,j=2*vt-L);const v=3===O?-1:1,B=v*(w-p),b=v*(R-x),T=v*(j-L);It=n*b-e*T,bt=t*T-n*B,Tt=e*B-t*b;const U=1/Math.sqrt(It*It+bt*bt+Tt*Tt);It*=U,bt*=U,Tt*=U}}}else It=mt*Bt,bt=Mt*Bt,Tt=vt*Bt;M(z,St+d,It,bt,Tt,G)}})()}}function P(t){nt(t)}function D(t,e){return Math.PI/2-2*Math.atan(Math.exp(-t/e))}function E(t,e,n,o){return D(t*(1-o)+e*o,n)}function w(t,e,n){return t*(1-n)+e*n}function O(t){const{tile:e}=t;if(e.surface.isWebMercator){const t=e.extent,n=e.ellipsoid.radius;return e=>E(t[1],t[3],n,e)}const n=e.extentInRadians;return t=>w(n[1],n[3],t)}function R(t){const{tile:e,geometryState:n,geometry:r}=t,{extent:s,surface:i}=e,{wireframe:a}=n,c=s[0],l=s[1],u=s[2]-c,d=s[3]-l,{numVerticesPerSide:f,clippingArea:m}=n,g=null!=m?Math.max(0,(m[0]-c)/u):0,h=null!=m?Math.max(0,(m[1]-l)/d):0,p=null!=m?Math.min(1,(m[2]-c)/u):1,x=null!=m?Math.min(1,(m[3]-l)/d):1,M=(f-2)**2,y=vt(n),S=M+4*y,L=i.renderer.tileGeometryCache.acquire(S),{boundingBox:v}=r;o(v),r.numVerticesPerSide=f,r.vertexAttributes=L,r.maxEdgeVertexCount=y,r.minu=g,r.minv=h,r.maxu=p,r.maxv=x,N(t),r.edgeVerticesStartIndex=M,_(t),q(t),J(r,[],a),t.intersectionData=null}function N(e){const o=e.tile;if(!o.intersectsClippingArea)return;const{geometry:r,geometryState:a,localOrigin:c}=e,{samplerData:l,clippingArea:u,numVerticesPerSide:d}=a,{surface:f,extent:m,ellipsoid:g}=o,{isWebMercatorOnPlateCarree:h}=f,p=null!=u?u:pt,x=m[0],y=m[1],S=m[2],L=m[3],v=Math.max(x,p[0]),B=Math.min(S,p[2]),V=Math.max(y,p[1]),I=Math.min(L,p[3]),b=g.radius,T=o.horizontalScale,U=d-1,C=d-2,{minu:A,minv:P,maxu:D,maxv:E,boundingBox:w,vertexAttributes:O}=r,{position:R,uv0:N}=O,{typedBuffer:j,typedBufferStride:F}=O.normalCompressed,q=c[0],W=c[1],k=c[2],z=R.typedBuffer,G=R.typedBufferStride;let H=0;const J=t(y,V,I),K=h?(Math.PI/2-2*Math.atan(Math.exp(-J/b)))*b:J*T,Q=1/U,X=t(y*(1-Q)+L*Q,V,I);let Y=K,Z=h?(Math.PI/2-2*Math.atan(Math.exp(-X/b)))*b:X*T;const $=1===l?.length?l[0]:null,_=$?(t,e)=>i(t,e,$)??0:(t,e)=>s(t,e,l)??0;for(let s=1;s<=C;s++){const e=s/U,o=t(y*(1-e)+L*e,V,I),r=t(e,P,E),i=Z,a=(s-1)/U,c=t(y*(1-a)+L*a,V,I),l=Y,u=(s+1)/U,d=t(y*(1-u)+L*u,V,I),f=h?(Math.PI/2-2*Math.atan(Math.exp(-d/b)))*b:d*T,m=t(u,P,E);Y=Z,Z=f;const g=t(x,v,B);let p=g*T,O=_(g,o);const R=1/U,J=t(R,A,D),K=t(x*(1-J)+S*J,v,B);let Q=J,X=K,$=K*T,tt=_(K,o);if(1===s){const e=$-q,o=Y-W,s=tt-k,i=0*G;z[i]=e,z[i+1]=o,z[i+2]=s,Lt(e,o,s,w);const a=t(R,A,D);N.setValues(H,Math.round(a*n),Math.round(r*n))}for(let h=1;h<=C;h++){const e=$,a=tt,u=(h+1)/U,g=t(u,A,D),y=t(x*(1-u)+S*u,v,B),L=X;X=y;{const t=H+1,e=t*G;if(1===s||h===C){const a=y*T,c=_(y,o);if(1===s&&h<C){const o=a-q,s=i-W,l=c-k;z[e]=o,z[e+1]=s,z[e+2]=l,Lt(o,s,l,w),N.setValues(t,Math.round(g*n),Math.round(r*n))}$=a,tt=c}else $=z[e]+q,tt=z[e+2]+k}const V=$,I=tt,b=p,P=O;p=e,O=a;const E=(H-C)*G,R=1===s?_(L,c):z[E+2]+k,J=_(L,d);if(s<C){const t=H+C,o=t*G,r=e-q,s=f-W,i=J-k;z[o]=r,z[o+1]=s,z[o+2]=i,Lt(r,s,i,w);const a=Q;Q=g,N.setValues(t,Math.round(a*n),Math.round(m*n))}{const t=V-b,e=l-f,n=e*(I-P),o=t*(R-J),r=-e*t,s=n*n+o*o+r*r;if(0===s)M(j,H,0,0,1,F);else{const t=1/Math.sqrt(s);M(j,H,n*t,o*t,r*t,F)}}++H}}}function j(t){t.tile.intersectsClippingArea&&(tt(t),q(t),rt(t),st(t),t.intersectionData=null)}function F(t){t.tile.intersectsClippingArea&&(q(t),rt(t),t.intersectionData=null)}function q(t){t.tile.intersectsClippingArea&&(k(t),W(t))}function W(n){const{geometry:o,geometryState:r,localOrigin:a}=n,c=n.tile,{surface:u,extent:d}=c,{clippingArea:h,samplerData:p}=r,M=null!=h?h:pt,y=d[0],S=d[2],L=d[1],v=d[3],B=[v>M[3],S>M[2],L<M[1],y<M[0]],V=c.horizontalScale,I=H(u.isWebMercatorOnPlateCarree,c.ellipsoid.radius,V),{minu:b,minv:T,maxu:U,maxv:C,boundingBox:A}=o,P=Math.max(y,M[0]),D=Math.min(S,M[2]),E=Math.max(L,M[1]),w=Math.min(v,M[3]),O=a[0],R=a[1],N=a[2],j=1===p?.length?p[0]:void 0,F=j?(t,e)=>i(t,e,j)??0:(t,e)=>s(t,e,p)??0;for(let q=0;q<4;++q){const a=1===q||3===q,d=r.edgeResolutions[q];f(e(d));const h=d+1,M=B[q],j=l(c,r.edgePeerNeighbors[q]);if(!M&&Mt(c,j,q)){if(et(n,q,j))continue}const W=null!=j&&!M,k=j?.renderData,z=k?.geometryState;if(m&&(f(!W||j.level===c.level),f(!W||x(c,j)<=0),c&&!j&&!u.updatingRootTiles)){const t=g[q],e=c.findNeighborTile(t,t=>t.loaded||t.leaf||t.level===c.level);u.updatingRootTiles||(e?e.intersectsClippingArea&&(f(!e.loaded),f(!e.leaf),f(e.level===c.level)):f(null==u?.rootTiles||!c.shouldHaveNeighbor(t)))}const G=t(1===q?S:y,P,D),H=t(0===q?v:L,E,w),J=z?.samplerData,K=t(1===q?1:0,b,U),Q=t(0===q?1:0,T,C),X=1===J?.length?J[0]:null,Y=(t,e)=>X?i(t,e,X)??0:s(t,e,J)??0,Z=W?(t,e)=>.5*(Y(t,e)+F(t,e)):F,$=(S-y)/d,_=a?1===q?$:-$:0,tt=a?0:0===q?$:-$,nt=-_,ot=-tt;let rt=0,st=0,it=0;{const e=0/d,n=a?G:t(y*(1-e)+S*e,P,D),o=a?t(L*(1-e)+v*e,E,w):H,r=Z(n,o);rt=n*V,st=I(o),it=r}let at=0,ct=0,lt=0;{const e=1/d,n=a?G:t(y*(1-e)+S*e,P,D),o=a?t(L*(1-e)+v*e,E,w):H,r=Z(n,o);at=n*V,ct=I(o),lt=r}for(let e=1;e<h-1;++e){const n=e/d,r=at,i=ct,c=lt;{const s=a?K:t(n,b,U),l=a?t(n,T,C):Q,u=r-O,d=i-R,f=c-N;Lt(r,d,f,A),o.setEdgeVertexFromValuesRawPositionUV(q,e,u,d,f,s,l)}{const n=(e+1)/d,o=a?G:t(y*(1-n)+S*n,P,D),r=a?t(L*(1-n)+v*n,E,w):H,s=Z(o,r);at=o*V,ct=I(r),lt=s}const l=at,u=lt,f=rt,m=st,g=it;rt=r,st=i,it=c;let h=0,x=0,M=0;if(a){const e=ct-i,o=u-c,a=m-i,l=g-c,d=t(L*(1-n)+v*n,E,w),f=G+nt,y=f*V-r,S=s(f,d,p)-c,B=3===q?-1:1;if(h=B*(-a+e)*S,x=B*y*(-l+o),M=-B*y*(-a+e),W){const t=G+_,n=t*V-r;h=(-a+e)*(S-(s(t,d,J)-c)),x=(y-n)*(-l+o),M=-(y-n)*(-a+e)}}else{const e=l-r,o=u-c,a=f-r,d=g-c,m=t(y*(1-n)+S*n,P,D),L=H+ot,v=s(m,L,p)-c,B=I(L)-i,V=2===q?-1:1;if(h=V*B*(-d+o),x=V*(-a+e)*v,M=-V*B*(-a+e),W){const t=m,n=H+tt,r=I(n)-i;h=(-B+r)*(-d+o),x=(-a+e)*(-v+(s(t,n,J)-c)),M=-(-B+r)*(-a+e)}}const B=1/Math.sqrt(h*h+x*x+M*M);o.setEdgeNormalFromValues(q,e,h*B,x*B,M*B)}}}function k(t){nt(t)}function z(t,e){return(Math.PI/2-2*Math.atan(Math.exp(-t/e)))*e}function G(t,e){return t*e}function H(t,e,n){return t?t=>z(t,e):t=>G(t,n)}function J(t,e,n){const{numVerticesPerSide:o,vertexAttributes:r,maxEdgeVertexCount:s}=t,i=o-1,a=r.count,l=2*(o-3)*(o-3),u=4*(i+s-3),d=c.reduce((e,n)=>e+(i+t.getEdgeCount(n)-3),0),f=e.reduce((t,e)=>t+i*(2*(e.latitudeResolution-1)+1),0),m=3*(n?2:1),g=(l+u+f)*m,h=a>=y?new Uint32Array(g):new Uint16Array(g);for(let c=0;c<g;++c)h[c]=0;t.indices=h,t.indexCount=(l+d+f)*m,t.poleIndicesStartIndex=l*m,t.edgeIndicesStartIndex=(l+f)*m,n?(Y(t),Z(t,e),$(t)):(K(t),Q(t,e),X(t))}function K(t){const{numVerticesPerSide:e,indices:n,vertexAttributes:o}=t,{position:r}=o,{typedBuffer:s,typedBufferStride:i}=r,a=e-2,c=e-3,l=0,u=e-3;let d=0;for(let f=0;f<c;++f){const t=f*a;for(let e=l;e<u;++e){const o=t+e,r=o+1,c=r+a,l=c-1;Bt(o,r,c,l,i,s)?(n[d]=o,n[d+1]=r,n[d+2]=c,n[d+3]=c,n[d+4]=l,n[d+5]=o):(n[d]=o,n[d+1]=r,n[d+2]=l,n[d+3]=l,n[d+4]=r,n[d+5]=c),d+=6}}}function Q(t,e){const{numVerticesPerSide:n,indices:o,poleIndicesStartIndex:r}=t,s=n-1;let i=r;for(const a of e){const e=a.isNorth?1:2,r=a.isNorth?2:1,c=a.isNorth?3:4,l=a.isNorth?4:3;let u=t.getEdgeVertexIndex(a.connectedOuterEdgeOffset,0),d=1;for(let t=0;t<a.latitudeResolution;++t){const f=0===t?a.rowOffset:u+n;for(let n=0;n<s;n++){const s=f+n;o[i]=u,o[i+e]=u+1,o[i+r]=s,t<a.latitudeResolution-1?(o[i+c]=u+1,o[i+l]=s+1,o[i+5]=s,i+=6):i+=3,u+=d}u=f,d=1}}}function X(t){const{indices:e,numVerticesPerSide:n,edgeIndicesStartIndex:o}=t,r=n-1,s=r-2;let i=o;for(let a=0;a<4;++a){const n=St[a];let o=0,c=0;const l=t.getEdgeCount(a),u=n.count;f(u===r-1);const d=1===a||2===a,m=d?1:2,g=d?2:1,h=t.getEdgeFirstVertexIndex(a),p=1,x=n.vertex0Index,M=n.stride;for(;o<l-1||c<u-1;){const t=x+c*M,n=h+o*p,a=o<l-1,d=c<u-1,f=a&&(!d||(a?0+r*(o+.5)/(l-1):0)<=(d?1+s*(c+.5)/(u-1):0));f?++o:++c;const y=f?n+p:t+M;e[i]=t,e[i+m]=n,e[i+g]=y,i+=3}}t.indexCount=i}function Y(t){const{indices:e,numVerticesPerSide:n,vertexAttributes:o}=t,{position:r}=o,{typedBuffer:s,typedBufferStride:i}=r,a=n-2;let c=0;for(let l=0;l<n-3;++l){const t=l*a;for(let o=0;o<n-3;++o){const n=l*a+o,r=n+1,u=r+a,d=u-1,f=t+o,m=f+1,g=m+a;Bt(f,m,g,g-1,i,s)?(Vt(e,c,n,r,u),c+=6,Vt(e,c,u,d,n)):(Vt(e,c,n,r,d),c+=6,Vt(e,c,d,u,r)),c+=6}}}function Z(t,e){const{indices:n,numVerticesPerSide:o,poleIndicesStartIndex:r}=t,s=o-1;let i=r;for(const a of e){const e=a.connectedOuterEdgeOffset;let r=t.getEdgeVertexIndex(e,0),c=1;for(let t=0;t<a.latitudeResolution;++t){const e=0===t?a.rowOffset:r+o;for(let o=0;o<s;o++)Vt(n,i,r,r+1,e+o),i+=6,t<a.latitudeResolution-1&&(Vt(n,i,r+1,e+o+1,e+o),i+=6),r+=c;r=e,c=1}}}function $(t){const{indices:e,numVerticesPerSide:n,edgeIndicesStartIndex:o}=t,r=n-1,s=r-2;let i=o;for(let a=0;a<4;++a){const n=St[a];let o=0,c=0;const l=t.getEdgeCount(a),u=n.count;f(u===r-1);const d=1===a||2===a,m=d?1:3,g=d?3:1,h=t.getEdgeFirstVertexIndex(a),p=1,x=n.vertex0Index,M=n.stride;for(;o<l-1||c<u-1;){const t=x+c*M,n=h+o*p,a=o<l-1,d=c<u-1,f=a&&(!d||(a?0+r*(o+.5)/(l-1):0)<=(d?1+s*(c+.5)/(u-1):0));f?++o:++c;const y=f?n+p:t+M;e[i]=t,e[i+m]=n,e[i+m+1]=n,e[i+g]=y,e[i+g+1]=y,e[i+5]=t,i+=6}}t.indexCount=i}function _(t){const{geometry:e,geometryState:n}=t,{edgeResolutions:o}=n,{numVerticesPerSide:r,edgeVerticesStartIndex:s}=e,i=r-2;let a=s;for(let c=0;c<4;++c){{const t=0===c||2===c,e=(0===c?i-1:0)*i+(1===c?i-1:0),n=(t?0:1)*i+(t?1:0),o=St[c];o.vertex0Index=e,o.stride=n,o.count=i}{const t=o[c]+1;e.outerEdgesOffsetAndLength[2*c+0]=a,e.outerEdgesOffsetAndLength[2*c+1]=t,a+=t}}}function tt(t){_(t),t.geometryState.wireframe?$(t.geometry):X(t.geometry)}function et(o,r,s){const{geometryState:i,geometry:a,tile:c,localOrigin:l}=o,u=1===r||3===r,d=i.edgeResolutions[r];f(e(d));const m=d+1,{boundingBox:g,minu:h,minv:p,maxu:x,maxv:M,vertexAttributes:y}=a,S=t(1===r?1:0,h,x),L=t(0===r?1:0,p,M),v=s.renderData,B=v.geometryState;if(!B||!v.geometry.vertexAttributes)return!1;const V=v.geometry,I=(r+2)%4,b=V.getEdgeCount(I),T=c.getNeighborEdgeStartVertexIndex(r,s)*d,U=d*2**(c.level-s.level);f(B.edgeResolutions[I]===U),f(b-1===U);const C=v.localOrigin[0]-l[0],A=v.localOrigin[1]-l[1],P=v.localOrigin[2]-l[2],D=a.getEdgeFirstVertexIndex(r),{position:E,uv0:w}=y,O=E.typedBuffer,R=E.typedBufferStride,N=y.normalCompressed,j=N.typedBuffer,F=N.typedBufferStride,q=V.vertexAttributes,W=V.getEdgeFirstVertexIndex(I),k=q.position.typedBuffer,z=q.position.typedBufferStride,G=q.normalCompressed.typedBuffer,H=q.normalCompressed.typedBufferStride;for(let e=1;e<m-1;++e){const o=D+e,r=W+(T+e),s=o*R,i=r*z,a=k[i]+C,c=k[i+1]+A,l=k[i+2]+P;O[s]=a,O[s+1]=c,O[s+2]=l,Lt(a,c,l,g);const f=o*F,m=r*H;j[f]=G[m],j[f+1]=G[m+1];const y=e/d,v=u?S:t(y,h,x),B=u?t(y,p,M):L;w.setValues(o,Math.round(v*n),Math.round(B*n))}return!0}function nt(e){const{geometry:o,geometryState:r,localOrigin:i}=e,{clippingArea:a,samplerData:c}=r,{minu:l,minv:u,maxu:d,maxv:m,boundingBox:g,vertexAttributes:h}=o,p=e.tile,{surface:M,ellipsoid:y,extent:S,extentInRadians:L,horizontalScale:v}=p,B="local"===M.view?.viewingMode,V=y.radius;let I=0,b=0,T=0;const U=(t,e,n)=>{const o=L[0===e?1:3],r=L[0===t?0:2],s=Math.cos(o),i=Math.sin(o),a=Math.sin(r),c=Math.cos(r),l=V+n;I=c*s*l,b=a*s*l,T=i*l},C=B?(()=>{const e=a,n=null!=e&&(S[3]>e[3]||S[2]>e[2]||S[1]<e[1]||S[0]<e[0]),o=H(M.isWebMercatorOnPlateCarree,V,v);return(r,s,i)=>{const a=0===r?S[0]:S[2],c=0===s?S[1]:S[3],l=n?t(a,e[0],e[2]):a,u=n?t(c,e[1],e[3]):c,d=i;I=l*v,b=o(u),T=d}})():U;let A=0,P=0,D=0,E=0,w=0,R=0,N=0,j=0,F=0;const q=B&&M.isWebMercatorOnPlateCarree,W=(t,e,n,o,r)=>{let s=0,i=0,a=0;if(B){const t=e*v,r=q?(Math.PI/2-2*Math.atan(Math.exp(-n/V)))*V:n*v;s=t-I,i=r-b,a=o-T}else{const r=O(t),c=t.tile,l=c.extent,u=c.extentInRadians,d=(e-l[0])/(l[2]-l[0]),f=(n-l[1])/(l[3]-l[1]),m=u[0]*(1-d)+u[2]*d,g=r(f),h=Math.cos(g),p=Math.sin(g),x=Math.sin(m),M=Math.cos(m),y=V+o;s=M*h*y-I,i=x*h*y-b,a=p*y-T}switch(r){case 0:N+=s,j+=i,F+=a;break;case 1:E-=s,w-=i,R-=a;break;case 2:N-=s,j-=i,F-=a;break;case 3:E+=s,w+=i,R+=a}},k=a??pt,z=S[0],G=S[2],J=S[1],K=S[3],Q=[K>k[3],G>k[2],J<k[1],z<k[0]],X=Math.max(z,k[0]),Y=Math.min(G,k[2]),Z=Math.max(J,k[1]),$=Math.min(K,k[3]),_=t=>Math.max(k[0],Math.min(k[2],t)),tt=t=>Math.max(k[1],Math.min(k[3],t)),et=t=>{const e=r.cornerNeighborCornerTiles;A=0,P=0,D=1,E=0,w=0,R=0,N=0,j=0,F=0;let n=1/0;for(let r=0;r<4;++r){const o=e[4*t+r];n=Math.min(n,o?.level??1/0)}for(let r=0;r<4;++r){const o=e[4*t+r];xt[r]=o?.level===n?o:null}let o=1,i=0;for(let r=0;r<4;++r){const t=xt[r];t&&(o=Math.max(o,t?.renderData.geometryState.numVerticesPerSide),i=t.extent[2]-t.extent[0])}const a=i,c=o;f(c>1);const l=a/c;for(let r=0;r<4;++r){const t=xt[(r+3)%4],e=xt[r%4];if(!t&&!e)continue;const n=0===r?1:1===r?2:2===r?3:0,o=0===r?2:1===r?3:2===r?0:1;if(t&&e){const i=at[r][0]*l,a=at[r][1]*l,c=t.extent,u=_(c[0===n||1===n?2:0]+i),d=tt(c[0===n||3===n?3:1]+a),f=e.extent,m=_(f[0===o||1===o?2:0]+i),g=tt(f[0===o||3===o?3:1]+a),h=t.renderData,p=e.renderData,x=s(u,d,h.geometryState.samplerData),M=s(m,g,p.geometryState.samplerData);W(h,u,d,.5*(x+M),r)}else{const i=t??e,a=t?n:o,c=i.extent,u=at[r],d=_(c[0===a||1===a?2:0]+u[0]*l),f=tt(c[0===a||3===a?3:1]+u[1]*l),m=i.renderData,g=s(d,f,m.geometryState.samplerData);W(m,d,f,g,r)}}if(!B){const t=Math.sqrt(I*I+b*b+T*T);A=I/t,P=b/t,D=T/t}if(B||D*D<.999){const t=Math.sqrt(E*E+w*w+R*R);E/=t,w/=t,R/=t;const e=Math.sqrt(N*N+j*j+F*F);N/=e,j/=e,F/=e,A=R*j-w*F,P=E*F-R*N,D=w*N-E*j;const n=1/Math.sqrt(A*A+P*P+D*D);A*=n,P*=n,D*=n}},nt=r.cornerNeighborCornerTiles;for(let O=0;O<4;++O){const e=O,a=(O+1)%4,M=0===O||1===O?1:0,y=0===O||3===O?1:0,S=t(M,l,d),L=t(y,u,m),v=o.getEdgeFirstVertexIndex(e),B=o.getEdgeCount(e),V=0===O||3===O?B-1:0,U=o.getEdgeFirstVertexIndex(a),E=o.getEdgeCount(a),w=0===O||1===O?E-1:0;let R=-1;for(let t=0;t<4;++t){const e=nt[4*O+t],n=nt[4*O+R];e&&(-1===R||x(n,e)>0)&&(R=t)}const N=R,j=nt[4*O+N];if(j!==p){const t=p.level-j.level,e=2**t,o=[j.lij[0]+t,j.lij[1]*e,j.lij[2]*e],s=[o[1]+e===p.lij[1],0===O&&(1===N||0===N&&j!==nt[4*O+3])||1===O&&(0===N||1===N&&j!==nt[4*O+2]),o[1]===p.lij[1]+1,2===O&&(3===N||2===N&&j!==nt[4*O+1])||3===O&&(2===N||3===N&&j!==nt[4*O+0])],a=s.reduce((t,e)=>t+(e?1:0),0);f(1===a||2===a);let c=-1,l=-1;const u=j.renderData;if(1===a){const t=s.findIndex(t=>t);f(0<=t&&t<=3),c=(t+2)%4;const e=r.edgeResolutions[t];l=p.getNeighborEdgeStartVertexIndex(t,j)*e+e*(0===t&&0===O||1===t&&0===O||2===t&&1===O||3===t&&3===O?1:0)}else{f(s[1]||s[3]),c=s[1]?3:1;const t=u.geometryState.edgeResolutions[c];l=0===O||3===O?0:t}const d=u.geometry;{const t=v+V,e=U+w,o=d.getEdgeFirstVertexIndex(c)+l,r=d.vertexAttributes,s=u.localOrigin,a=r.position,f=a.typedBuffer,m=o*a.typedBufferStride,p=f[m]+s[0]-i[0],x=f[m+1]+s[1]-i[1],M=f[m+2]+s[2]-i[2];Lt(p,x,M,g);const y=h.position,B=y.typedBuffer,I=t*y.typedBufferStride;B[I]=p,B[I+1]=x,B[I+2]=M;const b=e*y.typedBufferStride;B[b]=p,B[b+1]=x,B[b+2]=M;const T=h.uv0;T.setValues(t,Math.round(S*n),Math.round(L*n)),T.setValues(e,Math.round(S*n),Math.round(L*n));{const n=r.normalCompressed.typedBuffer,s=o*r.normalCompressed.typedBufferStride,i=h.normalCompressed,a=i.typedBuffer;{const e=t*i.typedBufferStride;a[e]=n[s],a[e+1]=n[s+1]}{const t=e*i.typedBufferStride;a[t]=n[s],a[t+1]=n[s+1]}}}}else{const n=Q[e],r=Q[a];let l;if(n||r){const e=t(z*(1-M)+G*M,X,Y),n=t(J*(1-y)+K*y,Z,$);l=s(e,n,c)}else l=ot(nt,O);C(M,y,l),et(O);const u=I-i[0],d=b-i[1],f=T-i[2];Lt(u,d,f,g),o.setEdgeVertexFromValuesRawPositionUVNormal(e,V,u,d,f,S,L,A,P,D),o.setEdgeVertexFromValuesRawPositionUVNormal(a,w,u,d,f,S,L,A,P,D)}}for(let t=0;t<4;++t)xt[t]=null}function ot(t,e){const n=4*e,o=c.reduce((e,o)=>Math.min(e,t[n+o]?.level??1/0),1/0);m&&(f(!t[n+0]||!t[n+2]||p(t[n+0],t[n+2],5)),f(!t[n+1]||!t[n+3]||p(t[n+1],t[n+3],7)));let r=0,i=0;for(let c=0;c<4;++c){const e=t[n+c];if(e?.level===o){const t=0===c||1===c,n=0===c||3===c,o=e.extent,a=o[t?0:2],l=o[n?1:3],u=e.renderData?.geometryState?.samplerData;i+=s(a,l,u),r++}}const a=r?i/r:0;return f(null!=a),a}function rt(t){const{vao:e,geometry:n}=t,{vertexAttributes:o,edgeVerticesStartIndex:r}=n,s=o.position.typedBuffer;e.buffer()?.setSubData(s,r,r,s.length)}function st(t){const{vao:e,geometry:n}=t,{indices:o,indexCount:r,edgeIndicesStartIndex:s}=n;e.indexBuffer.setSubData(o,s,s,r)}class it{constructor(t,e,n,o,r){this.isNorth=t,this.connectedRowOffset=e,this.connectedOuterEdgeOffset=n,this.rowOffset=o,this.latitudeResolution=r}}const at=[[0,1],[1,0],[0,-1],[-1,0]],ct=new a,lt=.5*d,ut=new Uint16Array(u+1),dt=new Int32Array(u+1),ft=new Int32Array(u+1),mt=new Int32Array(u+1),gt=new Float64Array(u+1),ht=new Float64Array(u+1),pt=r(-1/0,-1/0,1/0,1/0),xt=[null,null,null,null];function Mt(t,e,n){if(!e)return!1;const o=x(t,e);return o>0||0===o&&n>=2}class yt{constructor(){this.vertex0Index=0,this.stride=1,this.count=0}getVertexIndex(t){return f(0<=t&&t<this.count),this.vertex0Index+this.stride*t}}const St=[new yt,new yt,new yt,new yt];function Lt(t,e,n,o){t<o[0]?o[0]=t:t>o[3]&&(o[3]=t),e<o[1]?o[1]=e:e>o[4]&&(o[4]=e),n<o[2]?o[2]=n:n>o[5]&&(o[5]=n)}function vt(t){const{edgeResolutions:e,numVerticesPerSide:n}=t,o=1+Math.max(...e);return Math.max(n,o)}function Bt(t,e,n,o,r,s){const i=t*r,a=s[i],c=s[i+1],l=s[i+2],u=e*r,d=s[u],f=s[u+1],m=s[u+2],g=n*r,h=s[g],p=s[g+1],x=s[g+2],M=o*r,y=s[M],S=s[M+1],L=s[M+2];return(d-y)*(d-y)+(f-S)*(f-S)+(m-L)*(m-L)>(a-h)*(a-h)+(c-p)*(c-p)+(l-x)*(l-x)}function Vt(t,e,n,o,r){t[e]=n,t[e+1]=o,t[e+2]=o,t[e+3]=r,t[e+4]=r,t[e+5]=n}const It=6;export{R as createPlanarGlobePatch,S as createSphericalGlobePatch,j as updateEdgeElevationsAndResolutionsPlanar,U as updateEdgeElevationsAndResolutionsSpherical,F as updateEdgesAndCornersPlanar,T as updateEdgesAndCornersSpherical};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{equals as e}from"../../../core/arrayUtils.js";import"../../../core/has.js";import{isPowerOfTwo as t}from"../../../core/mathUtils.js";import{disposeMaybe as r,releaseMaybe as i}from"../../../core/maybe.js";import{glLayout as s}from"../support/buffer/glUtil.js";import{GeometryState as a}from"./GeometryState.js";import{PatchGeometry as o}from"./PatchGeometry.js";import{checkPatchGeometryWaterproofness as n}from"./PatchRenderDataWaterproofness.js";import{maxTileNeighborLevelDelta as l}from"./TerrainConst.js";import{internalAssert as h,neighborEdgeIndices as d,oppositeEdge as u,neighborCornerIndices as m,enableTerrainInternalChecks as g}from"./terrainUtils.js";import{TextureFader as c}from"./TextureFader.js";import{TextureReference as f}from"./TextureReference.js";import _ from"./TileOverlayData.js";import{fallsWithinLayerView as y}from"./tileUtils.js";import{VertexArrayObject as p}from"../webgl-engine/lib/VertexArrayObject.js";import{BufferObject as x}from"../../webgl/BufferObject.js";import{VertexBuffer as D}from"../../webgl/VertexBuffer.js";class C{constructor(){this.geometry=new o,this.geometryState=null,this._texture=null,this._textureOpacity=1,this._textureFader=new c(()=>this._tile.surface.fadeDuration),this.overlay=new _,this._localOrigin=null,this._geometryStateChangedSinceLastUpdate=!0,this._hasGeometry=!1,this._modifiedFlags=0}get tile(){return this._tile}get localOrigin(){return this._localOrigin}init(e,t){this.clear(),this._tile=e,this.geometry.reset(),this.intersectionData=null,this.geometryState=new a,this._localOrigin=t,this.overlay.clear()}clear(){this.releaseGeometry(),this.releaseTexture(),this._textureFader.clear(),this._tile=null,this.intersectionData=null,this.geometryState=null}updateGeometryIfNeeded(e){if((!this._vao||this._geometryStateChangedSinceLastUpdate||this.wireframeChanged||this.clippingAreaChanged||this.samplerDataChanged||this.numVerticesPerSideChanged||this.dirtyCorners||this.dirtyEdgeResolutions||this.dirtyEdges)&&(this._updateGeometry(e),this._geometryStateChangedSinceLastUpdate=!1),g&&this.tile.intersectsClippingArea)for(let t=0;t<G;++t)h(this.geometry.getEdgeCount(t)===this.geometryState.edgeResolutions[t]+1)}_calculateEdgeResolution(e,t){const r=this.tile,i=this.geometryState.numVerticesPerSide-1;if(!r.surface.isGlobal){const t=r.surface.groundExtent;if(null!=t&&(0===e&&r.extent[3]>t[3]||1===e&&r.extent[2]>t[2]||2===e&&r.extent[1]<t[1]||3===e&&r.extent[0]<t[0]))return i}const s=r.level,a=d[e];if(!t)return h(null==r.surface?.rootTiles||r.surface.updatingRootTiles||!r.shouldHaveNeighbor(a)),i;if(t.loaded){const r=t,a=r.renderData.geometryState,o=s-r.level;if(h(o>=0),0===o){const e=a.numVerticesPerSide-1;return Math.max(e,i)}const n=2**o,l=a.edgeResolutions[(e+2)%4]/n;return Math.max(1,l)}h(!t.leaf);let o=i;return t.forAllSubtreeOnSide(u(a),e=>e===r||(e.loaded?(o=Math.max(o,2**(e.level-s)),!0):(h(!e.leaf),!1))),o}updateNeighborData(){const e=this.tile;if(!e.intersectsClippingArea)return;const r=e.renderData.geometryState,i=t=>(t.loaded||t.level===e.level)&&t.intersectsClippingArea,s=r.edgePeerNeighbors,a=r.edgePeerNeighborSamplerVersions;for(let o=0;o<G;++o){const n=e.findNeighborTile(d[o],i),u=v(e,n),m=u?.renderData?.geometryState.samplerDataVersion??-1,c=s[o],f=u!==v(e,c),_=a[o]!==m;g&&n&&(h(e.level>=n.level),h(e.level-n.level<=l)),s[o]=n,(f||_)&&(a[o]=m,this._markEdgeDirty(o));const y=r.edgeResolutions[o],p=this._calculateEdgeResolution(o,n);h(t(p)),h(p>=1),r.edgeResolutions[o]=p,y!==p&&this._markEdgeResolutionDirty(o)}for(let t=0;t<G;++t){const a=e.findNeighborTile(m[t],i);r.cornerPeerNeighbors[t]=a;const o=v(e,s[t]),n=v(e,s[(t+1)%G]),l=v(e,a);S[t]=l,S[(t+1)%G]=n,S[(t+2)%G]=e,S[(t+3)%G]=o,h(S.some(t=>t?.loaded||t===e));const d=S.reduce((e,t)=>Math.min(e,t?.level??1/0),1/0);S.forEach((e,t)=>{e&&e.level>d&&(S[t]=null)}),h(S.some(t=>t?.loaded||t===e));const u=r.cornerNeighborCornerTiles,c=r.cornerNeighborCornerTileSamplerVersions;for(let e=0;e<G;++e){const r=S[e],i=r?.renderData.geometryState.samplerDataVersion??-1,s=t*G+e,a=u[s]!==r,o=!a&&c[s]!==i;(a||o)&&(u[s]=r,c[s]=i,this._markCornerDirty(t))}g&&h(V.some(r=>{const i=u[t*G+r];return i?.loaded||i===e}))}g&&h(r.edgeResolutions.every(e=>e>0));for(let t=0;t<G;++t)S[t]=null}_updateGeometry(e){if(!this.tile.intersectsClippingArea)return;g&&h(!this.tile.intersectsClippingArea||this.geometryState.edgeResolutions.every(e=>e>0)),this.intersectionData=null;const{tile:t,_vao:r,geometry:i,geometryState:s}=this,{vertexAttributes:a}=i,o=!r||!a||this.wireframeChanged||this.samplerDataChanged||this.clippingAreaChanged,n=0!==this.dirtyEdgeResolutions,l=s.edgeResolutions.reduce((e,t)=>Math.max(e,t),0)+1,d=n&&l>i.maxEdgeVertexCount,u=o||this.numVerticesPerSideChanged||d,m=!u&&n,c=!m&&0!==this.dirtyEdges,f=!c&&0!==this.dirtyCorners;u?(this.releaseGeometry(),this._createGeometry(e)):m?t.updateEdgeElevationsAndResolutions():c||f?t.updateEdgeElevations():console.warn("Update for no reason?"),this._modifiedFlags=0}get hasGeometry(){return this._hasGeometry}releaseGeometry(){return this._hasGeometry=!1,this.intersectionData=null,!!this._vao&&(this._vao=r(this._vao),this.geometry.release(),!0)}ensureTexture(e,t,r,i){const s=t?6408:6407;return null!=this._texture&&(0===r&&this._tile.surface.fadeDuration>0&&this._isTextureVisible(this._texture)||this._texture.descriptor.width!==e||this._texture.descriptor.pixelFormat!==s)&&this.releaseTexture(),null==this._texture&&(this._texture=i(),this.tile.setMemoryDirty()),this._texture}releaseTexture(){this._texture&&(this._texture=i(this._texture),this.tile.setMemoryDirty())}reuseTexture(e,t){return!(!e||!this._texture)&&(e.setTextureReference(new f(this._texture,0,t,this._textureOpacity,0,1)),!0)}get numVerticesPerSideChanged(){return 0!==(this._modifiedFlags&F)}get samplerDataChanged(){return 0!==(this._modifiedFlags&b)}get clippingAreaChanged(){return 0!==(this._modifiedFlags&A)}get wireframeChanged(){return 0!==(this._modifiedFlags&T)}get dirtyEdges(){return this._modifiedFlags>>E&15}get dirtyCorners(){return this._modifiedFlags>>R&15}get dirtyEdgeResolutions(){return this._modifiedFlags>>w&15}_markCornerDirty(e){const t=1<<e<<R;this._modifiedFlags|=t}_markEdgeDirty(e){const t=1<<e<<E;this._modifiedFlags|=t,this._markCornerDirty((e+0)%4),this._markCornerDirty((e+3)%4)}_markEdgeResolutionDirty(e){const t=1<<e<<w;this._modifiedFlags|=t,this._markEdgeDirty(e)}_markAllEdgesAndCornersDirty(){this._modifiedFlags|=15<<R|15<<E|15<<w}updateGeometryState(){const t=this._elevationInfo,r=this.tile,i=t.samplerData?r.getElevationVerticesPerSide(t.maxTileLevel):r.minimumVerticesPerSide,s=Math.max(i,5);let a=r.clippingArea;r.intersectsClippingArea&&!r.withinClippingArea||(a=null);const o=this.geometryState;let n=!1;o.numVerticesPerSide!==s&&(this._modifiedFlags|=F,o.numVerticesPerSide=s,o.samplerDataVersion++,n=!0),t.changed&&(this._modifiedFlags|=b,o.samplerData=t.samplerData,o.samplerDataVersion++,n=!0),e(o.clippingArea,a)||(this._modifiedFlags|=A,o.clippingArea=a,n=!0);const l=r.surface.wireframe;return o.wireframe!==l&&(this._modifiedFlags|=T,o.wireframe=l,n=!0),this._geometryStateChangedSinceLastUpdate||=n,n&&this._markAllEdgesAndCornersDirty(),this._hasGeometry=!0,this._geometryStateChangedSinceLastUpdate}_createGeometry(e){this.tile.createGeometry();const{vertexAttributes:t,indices:r}=this.geometry,i=e.gl;this._vao=new p(e,new D(e,s(t.layout),t.buffer),x.createIndex(e,i.STATIC_DRAW,r)),this._hasGeometry=!0}get vao(){return this._vao}setTextureReference(e,t=0){e?.texture===this._texture?this._textureOpacity=e.opacities[0]:this.releaseTexture(),this._textureFader.push(e,t)}get textureReference(){return this._textureFader.current}get nextTextureReference(){return this._textureFader.next}get textureFadeFactor(){return this._textureFader.fadeFactor}get textureIsFading(){return this._textureFader.isFading}_isTextureVisible(e){return this._textureFader.current?.texture===e||this._textureFader.next?.texture===e&&this._textureFader.fadeFactor<1}get _elevationInfo(){const e=this.geometryState.samplerData,t=this.tile.layerInfo[0],r=t.length,i=new Array(r);let s=0,a=0,o=!1;for(let h=0;h<r;h++){const r=t[h],n=r.upsampleInfo?.tile;if(n){const t=n.layerInfo[0][h].data,r=t&&t.samplerData;e&&e[s]===r||(o=!0),i[s++]=r,a=Math.max(a,n.lij[0])}else if(r.data){const t=this.tile.surface.layerViewByIndex(h,0);if(y(this.tile,t)){const t=r.data;e&&e[s]===t.samplerData||(o=!0),i[s++]=t.samplerData,a=this.tile.level}}}null!=e&&e.length!==s&&(o=!0);const n=s>0,l=n?i:null;return n&&(i.length=s),{changed:o,samplerData:l,maxTileLevel:a}}get estimatedGeometryMemoryUsage(){const e=this.intersectionData?.estimatedMemoryUsage??0;return(this.geometry.indices?.byteLength??0)+(this.geometry.vertexAttributes?.byteLength??0)+e}get texture(){return this._texture}get test(){}checkGeometryWaterproofness(){n(this)}}const S=[null,null,null,null];function v(e,t){return t?.loaded||t===e?t:null}const F=1,b=2,A=4,T=8,E=4,R=8,w=12,G=4,V=[0,1,2,3];export{C as PatchRenderData,v as neighborTileIfLoadedOrSelf,V as zeroToFour};
2
+ import{equals as e}from"../../../core/arrayUtils.js";import"../../../core/has.js";import{isPowerOfTwo as t}from"../../../core/mathUtils.js";import{disposeMaybe as r,releaseMaybe as i}from"../../../core/maybe.js";import{glLayout as s}from"../support/buffer/glUtil.js";import{GeometryState as a}from"./GeometryState.js";import{PatchGeometry as o}from"./PatchGeometry.js";import{checkPatchGeometryWaterproofness as n}from"./PatchRenderDataWaterproofness.js";import{maxTileNeighborLevelDelta as l}from"./TerrainConst.js";import{internalAssert as h,neighborEdgeIndices as u,oppositeEdge as d,neighborCornerIndices as m,enableTerrainInternalChecks as g}from"./terrainUtils.js";import{TextureFader as c}from"./TextureFader.js";import{TextureReference as f}from"./TextureReference.js";import y from"./TileOverlayData.js";import{fallsWithinLayerView as p}from"./tileUtils.js";import{VertexArrayObject as _}from"../webgl-engine/lib/VertexArrayObject.js";import{BufferObject as x}from"../../webgl/BufferObject.js";import{VertexBuffer as D}from"../../webgl/VertexBuffer.js";class S{constructor(){this.geometry=new o,this.geometryState=null,this._texture=null,this._textureOpacity=1,this._textureFader=new c(()=>this._tile.surface.fadeDuration),this.overlay=new y,this._localOrigin=null,this._geometryStateChangedSinceLastUpdate=!0,this._hasGeometry=!1,this._modifiedFlags=0}get tile(){return this._tile}get localOrigin(){return this._localOrigin}init(e,t){this.clear(),this._tile=e,this.geometry.reset(),this.intersectionData=null,this.geometryState=new a,this._localOrigin=t,this.overlay.clear()}clear(){this.releaseGeometry(),this.releaseTexture(),this._textureFader.clear(),this._tile=null,this.intersectionData=null,this.geometryState=null}updateGeometryIfNeeded(e){if(!this._tile||!this.geometryState)return;if((!this._vao||this._geometryStateChangedSinceLastUpdate||this.wireframeChanged||this.clippingAreaChanged||this.samplerDataChanged||this.numVerticesPerSideChanged||this.dirtyCorners||this.dirtyEdgeResolutions||this.dirtyEdges)&&(this._updateGeometry(e),this._geometryStateChangedSinceLastUpdate=!1),g&&this.tile.intersectsClippingArea)for(let t=0;t<G;++t)h(this.geometry.getEdgeCount(t)===this.geometryState.edgeResolutions[t]+1)}_calculateEdgeResolution(e,t){const r=this.tile,i=this.geometryState.numVerticesPerSide-1;if(!r.surface.isGlobal){const t=r.surface.groundExtent;if(null!=t&&(0===e&&r.extent[3]>t[3]||1===e&&r.extent[2]>t[2]||2===e&&r.extent[1]<t[1]||3===e&&r.extent[0]<t[0]))return i}const s=r.level,a=u[e];if(!t)return h(null==r.surface?.rootTiles||r.surface.updatingRootTiles||!r.shouldHaveNeighbor(a)),i;if(t.loaded){const r=t,a=r.renderData?.geometryState;if(!a)return i;const o=s-r.level;if(h(o>=0),0===o){const e=a.numVerticesPerSide-1;return Math.max(e,i)}const n=2**o,l=a.edgeResolutions[(e+2)%4]/n;return Math.max(1,l)}h(!t.leaf);let o=i;return t.forAllSubtreeOnSide(d(a),e=>e===r||(e.loaded?(o=Math.max(o,2**(e.level-s)),!0):(h(!e.leaf),!1))),o}updateNeighborData(){const e=this.tile;if(!e.intersectsClippingArea)return;const r=e.renderData.geometryState,i=t=>(t.loaded||t.level===e.level)&&t.intersectsClippingArea,s=r.edgePeerNeighbors,a=r.edgePeerNeighborSamplerVersions;for(let o=0;o<G;++o){const n=e.findNeighborTile(u[o],i),d=C(e,n),m=d?.renderData?.geometryState.samplerDataVersion??-1,c=s[o],f=d!==C(e,c),y=a[o]!==m;g&&n&&(h(e.level>=n.level),h(e.level-n.level<=l)),s[o]=n,(f||y)&&(a[o]=m,this._markEdgeDirty(o));const p=r.edgeResolutions[o],_=this._calculateEdgeResolution(o,n);h(t(_)),h(_>=1),r.edgeResolutions[o]=_,p!==_&&this._markEdgeResolutionDirty(o)}for(let t=0;t<G;++t){const a=e.findNeighborTile(m[t],i);r.cornerPeerNeighbors[t]=a;const o=C(e,s[t]),n=C(e,s[(t+1)%G]),l=C(e,a);v[t]=l,v[(t+1)%G]=n,v[(t+2)%G]=e,v[(t+3)%G]=o,h(v.some(t=>t?.loaded||t===e));const u=v.reduce((e,t)=>Math.min(e,t?.level??1/0),1/0);v.forEach((e,t)=>{e&&e.level>u&&(v[t]=null)}),h(v.some(t=>t?.loaded||t===e));const d=r.cornerNeighborCornerTiles,c=r.cornerNeighborCornerTileSamplerVersions;for(let e=0;e<G;++e){const r=v[e],i=r?.renderData?.geometryState?.samplerDataVersion??-1,s=t*G+e,a=d[s]!==r,o=!a&&c[s]!==i;(a||o)&&(d[s]=r,c[s]=i,this._markCornerDirty(t))}g&&h(V.some(r=>{const i=d[t*G+r];return i?.loaded||i===e}))}g&&h(r.edgeResolutions.every(e=>e>0));for(let t=0;t<G;++t)v[t]=null}_updateGeometry(e){if(!this.tile.intersectsClippingArea)return;g&&h(!this.tile.intersectsClippingArea||this.geometryState.edgeResolutions.every(e=>e>0)),this.intersectionData=null;const{tile:t,_vao:r,geometry:i,geometryState:s}=this,{vertexAttributes:a}=i,o=!r||!a||this.wireframeChanged||this.samplerDataChanged||this.clippingAreaChanged,n=0!==this.dirtyEdgeResolutions,l=s.edgeResolutions.reduce((e,t)=>Math.max(e,t),0)+1,u=n&&l>i.maxEdgeVertexCount,d=o||this.numVerticesPerSideChanged||u,m=!d&&n,c=!m&&0!==this.dirtyEdges,f=!c&&0!==this.dirtyCorners;d?(this.releaseGeometry(),this._createGeometry(e)):m?t.updateEdgeElevationsAndResolutions():c||f?t.updateEdgeElevations():console.warn("Update for no reason?"),this._modifiedFlags=0}get hasGeometry(){return this._hasGeometry}releaseGeometry(){return this._hasGeometry=!1,this.intersectionData=null,!!this._vao&&(this._vao=r(this._vao),this.geometry.release(),!0)}ensureTexture(e,t,r,i){const s=t?6408:6407;return null!=this._texture&&(0===r&&this._tile.surface.fadeDuration>0&&this._isTextureVisible(this._texture)||this._texture.descriptor.width!==e||this._texture.descriptor.pixelFormat!==s)&&this.releaseTexture(),null==this._texture&&(this._texture=i(),this.tile.setMemoryDirty()),this._texture}releaseTexture(){this._texture&&(this._texture=i(this._texture),this.tile.setMemoryDirty())}reuseTexture(e,t){return!(!e||!this._texture)&&(e.setTextureReference(new f(this._texture,0,t,this._textureOpacity,0,1)),!0)}get numVerticesPerSideChanged(){return 0!==(this._modifiedFlags&F)}get samplerDataChanged(){return 0!==(this._modifiedFlags&b)}get clippingAreaChanged(){return 0!==(this._modifiedFlags&A)}get wireframeChanged(){return 0!==(this._modifiedFlags&T)}get dirtyEdges(){return this._modifiedFlags>>E&15}get dirtyCorners(){return this._modifiedFlags>>R&15}get dirtyEdgeResolutions(){return this._modifiedFlags>>w&15}_markCornerDirty(e){const t=1<<e<<R;this._modifiedFlags|=t}_markEdgeDirty(e){const t=1<<e<<E;this._modifiedFlags|=t,this._markCornerDirty((e+0)%4),this._markCornerDirty((e+3)%4)}_markEdgeResolutionDirty(e){const t=1<<e<<w;this._modifiedFlags|=t,this._markEdgeDirty(e)}_markAllEdgesAndCornersDirty(){this._modifiedFlags|=15<<R|15<<E|15<<w}updateGeometryState(){const t=this._elevationInfo,r=this.tile,i=t.samplerData?r.getElevationVerticesPerSide(t.maxTileLevel):r.minimumVerticesPerSide,s=Math.max(i,5);let a=r.clippingArea;r.intersectsClippingArea&&!r.withinClippingArea||(a=null);const o=this.geometryState;let n=!1;o.numVerticesPerSide!==s&&(this._modifiedFlags|=F,o.numVerticesPerSide=s,o.samplerDataVersion++,n=!0),t.changed&&(this._modifiedFlags|=b,o.samplerData=t.samplerData,o.samplerDataSourceLevels=t.samplerDataSourceLevels,o.samplerDataVersion++,n=!0),e(o.clippingArea,a)||(this._modifiedFlags|=A,o.clippingArea=a,n=!0);const l=r.surface.wireframe;return o.wireframe!==l&&(this._modifiedFlags|=T,o.wireframe=l,n=!0),this._geometryStateChangedSinceLastUpdate||=n,n&&this._markAllEdgesAndCornersDirty(),this._hasGeometry=!0,this._geometryStateChangedSinceLastUpdate}_createGeometry(e){this.tile.createGeometry();const{vertexAttributes:t,indices:r}=this.geometry,i=e.gl;this._vao=new _(e,new D(e,s(t.layout),t.buffer),x.createIndex(e,i.STATIC_DRAW,r)),this._hasGeometry=!0}get vao(){return this._vao}setTextureReference(e,t=0){e?.texture===this._texture?this._textureOpacity=e.opacities[0]:this.releaseTexture(),this._textureFader.push(e,t)}get textureReference(){return this._textureFader.current}get nextTextureReference(){return this._textureFader.next}get textureFadeFactor(){return this._textureFader.fadeFactor}get textureIsFading(){return this._textureFader.isFading}_isTextureVisible(e){return this._textureFader.current?.texture===e||this._textureFader.next?.texture===e&&this._textureFader.fadeFactor<1}get _elevationInfo(){const t=this.geometryState.samplerData,r=this.geometryState.samplerDataSourceLevels,i=this.tile.layerInfo[0],s=i.length,a=new Array(s),o=new Array(s);let n=0,l=0,h=!1;for(let e=0;e<s;e++){const r=i[e],s=r.upsampleInfo?.tile;if(s){const r=s.layerInfo[0][e].data,i=r&&r.samplerData;t&&t[n]===i||(h=!0),a[n++]=i,o[n-1]=r?.level??s.level,l=Math.max(l,s.lij[0])}else if(r.data){const i=this.tile.surface.layerViewByIndex(e,0);if(p(this.tile,i)){const e=r.data;t&&t[n]===e.samplerData||(h=!0),a[n++]=e.samplerData,o[n-1]=e.level,l=this.tile.level}}}null!=t&&t.length!==n&&(h=!0);const u=n>0,d=u?a:null,m=u?o:null;return u&&(a.length=n,o.length=n),e(r,m)||(h=!0),{changed:h,samplerData:d,samplerDataSourceLevels:m,maxTileLevel:l}}get estimatedGeometryMemoryUsage(){const e=this.intersectionData?.estimatedMemoryUsage??0;return(this.geometry.indices?.byteLength??0)+(this.geometry.vertexAttributes?.byteLength??0)+e}get texture(){return this._texture}get test(){}checkGeometryWaterproofness(){n(this)}}const v=[null,null,null,null];function C(e,t){return t?.loaded||t===e?t:null}const F=1,b=2,A=4,T=8,E=4,R=8,w=12,G=4,V=[0,1,2,3];export{S as PatchRenderData,C as neighborTileIfLoadedOrSelf,V as zeroToFour};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../../Color.js";import{filterInPlace as i,difference as r}from"../../../core/arrayUtils.js";import s from"../../../core/CollectionFlattener.js";import{toConst as a}from"../../../core/compilerUtils.js";import{EventedAccessor as n}from"../../../core/Evented.js";import"../../../core/has.js";import l from"../../../core/Logger.js";import{clamp as o}from"../../../core/mathUtils.js";import{destroyMaybe as h}from"../../../core/maybe.js";import{MemCachePool as d}from"../../../core/MemCachePool.js";import p from"../../../core/ObjectPool.js";import u from"../../../core/PooledArray.js";import{throwIfAborted as c,isAbortError as g,isAborted as m}from"../../../core/promiseUtils.js";import{watch as _,syncAndInitial as y,sync as f,initial as T}from"../../../core/reactiveUtils.js";import{getMetersPerUnitForSR as v}from"../../../core/units.js";import{property as w,subclass as C}from"../../../core/accessorSupport/decorators.js";import{exactEquals as S,set as b,copy as E}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as x}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as L}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as P,radiusModifier as R}from"../../../geometry/ellipsoidUtils.js";import U from"../../../geometry/SpatialReference.js";import{getProjector as M}from"../../../geometry/projection/projectors.js";import{projectPointToVector as D}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as j}from"../../../geometry/projection/projectVectorToVector.js";import{create as I,equals as k,intersection as V,intersectsSphere as A,empty as B,expand as O}from"../../../geometry/support/aaBoundingRect.js";import{copy as G,create as q}from"../../../geometry/support/frustum.js";import{createSpatialReferenceCyclical as N}from"../../../geometry/support/normalizeUtils.js";import{isPlateCarree as F}from"../../../geometry/support/spatialReferenceUtils.js";import{Sphere as W}from"../../../geometry/support/sphere.js";import{ElevationQueryTileCache as H}from"../../../layers/support/ElevationQueryTileCache.js";import{isBaseLayer as $}from"../../../layers/support/layerUtils.js";import{queueHighPriority as Q}from"../../../request/queue.js";import{debugFlags as z}from"../support/debugFlags.js";import{ElevationRange as Y}from"../support/ElevationRange.js";import{toBoundingRect as X}from"../support/extentUtils.js";import{updatingProgress as K}from"../support/updatingProperties.js";import{ElevationBounds as J}from"./ElevationBounds.js";import{ElevationData as Z,sampleElevation as ee}from"./ElevationData.js";import{ElevationUpdateEvent as te}from"./ElevationUpdateEvent.js";import{create as ie}from"./ExtentHelper.js";import{LayerClasses as re}from"./LayerClass.js";import{OverlayManager as se}from"./OverlayManager.js";import{PlanarPatch as ae}from"./PlanarPatch.js";import{Queue as ne}from"./Queue.js";import{ScaleRangeQueries as le}from"./ScaleRangeQueries.js";import{SphericalPatch as oe}from"./SphericalPatch.js";import{SplitLimits as he}from"./SplitLimits.js";import{maxRootTiles as de,tooManyRootTilesAfterChangeError as pe,tooManyRootTilesForLayerError as ue,maxTileNeighborLevelDelta as ce,maxMemoryLodBias as ge}from"./TerrainConst.js";import{TerrainRenderer as me}from"./TerrainRenderer.js";import _e from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as ye,isVectorTileLayerView as fe,neighborEdgeIndices as Te,internalAssert as ve,oppositeEdge as we,isSurfaceLayerView as Ce,isGroupLayerView as Se,isMapTileLayerView as be,isBlendableLayerView as Ee,isElevationLayerView as xe,releaseTerrainData as Le,enableTerrainInternalChecks as Pe,oppositeCorner as Re,enableWaterproofTests as Ue,enableInternalTerrainChecks as Me,enableTerrainWaterproofChecks as De,neighborCornerIndices as je}from"./terrainUtils.js";import{Tile as Ie,lijEquals as ke}from"./Tile.js";import{printAllocations as Ve}from"./TilePerLayerInfo.js";import{sortTiles as Ae,IteratorPreorder as Be,IteratorPostorder as Oe,compareTilesByLij as Ge,hasLoadableSiblings as qe,sortTilesByPOI as Ne,traverseTilesPreorder as Fe}from"./tileUtils.js";import{TilingSchemeLogic as We}from"./TilingSchemeLogic.js";import{UpsampleInfo as He}from"./UpsampleInfo.js";import{isCompositeBlendMode as $e,blendModeFromString as Qe}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{hasLayerBasedScaleVisibility as ze}from"../../support/layerViewUtils.js";import{ImmediateTask as Ye,TaskPriority as Xe,noBudget as Ke}from"../../support/Scheduler.js";import{TextureCompressionTracker as Je}from"../../support/TextureCompressionTracker.js";import{Yield as Ze}from"../../support/Yield.js";var et;let tt=class extends n{static{et=this}get allTilesCreated(){return this._allTilesCreated}get allTiles(){return a(this._allTiles)}get renderedTiles(){return Ae(i(this._allTiles.toArray(),e=>e.visible&&e.rendered))}get demResolution(){const{_allTiles:e,tilingScheme:t}=this;if(0===e.length)return{min:1,max:1};const i=v(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 Je,this._iteratorPool=new p(()=>new Be,e=>e.remove=()=>this._iteratorPool.release(e)),this._postorderIterator=new Oe,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._allTilesCreated=!1,this._usedMemory=null,this._performanceInfo=new _e,this._viewChanged=!1,this.heading=0,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=x(),this._eyePosSurfaceSR=x(),this._splitLimits=new he,this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._watchUpdatingTracking=new L,this._frameTask=Ye,this._allTiles=new u,this._upsampleInfoPool=new p(()=>new He),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=I(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=U.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationRange=new Y(1/0,-1/0),this._rootTileElevationRange=new Y(1/0,-1/0),this._projectorCache=new Map,this._tilingSchemeSpatialReference=null,this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._oneBatchPerFrameTask=!0,this._layerViewsDirty=!1,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._isWebMercator=!1,this._isWebMercatorOnPlateCarree=!1,this.enabled=!0;const{view:t}=e;this.overlayManager=new se({...e,terrainSurface:this}),this._isGlobal=!t.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?oe:ae,this._ellipsoid=P(t.spatialReference),this._renderer=new me(this.overlayManager.renderer,t.stage,this._allTiles,this.terrainTextureCompressionTracker,t.resourceController.memoryController),ze()||(this._scaleRangeQueries=new le)}initialize(){const{view:e}=this,{resourceController:t}=e,{memoryController:i}=t;this._tileCache=new d((e,t)=>i.newCache(e,t),"terrain-tile"),this._upsampleMapCache=i.newCache("terrain-upsample",({tile:e})=>e.unloadMapData()),this._elevationQueryCache=new H(i.newCache("elevation-query"));const r=this.overlayManager;this.addHandles([_(()=>r.renderer.isEmpty,()=>this._evaluateTransparency()),_(()=>this.renderer.visible,e=>this.suspended=!e),_(()=>this.heading,e=>{this._renderer.updateHeading(e),this._updateTileTextures(0)},y),_(()=>({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)},y),_(()=>this.hasCompositeBlendMode,()=>this._updateTileTextures(this._evaluateTransparency()?1:2),y),_(()=>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,{equals:S})}),_(()=>z.TERRAIN_TILE_TREE_SHOW_TILES,t=>{t&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then(({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&z.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))}):t||(this._treeDebugger=h(this._treeDebugger))},T)]);const{spatialReference:a}=e;this._extentHelper=ie(this.viewingMode,{layers:e.map.allLayers,layerViews:e.allLayerViews,viewSpatialReference:a});const n=new s({getCollections:()=>e.defaultsFromMap?.mapCollections?.map(({layers:e})=>e),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}),l=new We({layers:n,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set("tilingSchemeLogic",l),this._updateTilingScheme();const o=t.scheduler;this._frameTask=o.registerTask(Xe.TERRAIN_SURFACE,this),this.addHandles([_(()=>this._extentHelper.stencilEnabledExtents,e=>this._renderer.setStencilEnabledLayerExtents(e),T),_(()=>this.tilingSchemeLogic.tilingScheme,()=>this._updateTilingScheme(),f),_(()=>this.groundExtent,()=>this._updateRootTiles(),T),e.on("resize",()=>this._viewChangeUpdate()),_(()=>{const t=e.state;return[this._lodBias,this.lodSnappingEnabled,e.quality,t.camera,t.contentCamera,t.fixedContentCamera]},()=>this._viewChangeUpdate(),y),_(()=>e.qualitySettings?.fadeDuration,e=>this._renderer.textureFadingEnabled=e>0,T),_(()=>e.qualitySettings?.physicallyBasedRenderingEnabled,e=>this._renderer.pbrMode=e?5:0,T),_(()=>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=Ye,this._watchUpdatingTracking?.destroy(),this._removeAllTiles(),this._set("tilingSchemeLogic",h(this.tilingSchemeLogic)),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear(),this._set("overlayManager",h(this.overlayManager)),this._tileCache=h(this._tileCache),this._allTiles.prune(),Ie.prune(),this._treeDebugger=h(this._treeDebugger),this._renderer.destroyed||this._renderer.destroy(),this._renderer=null,this._iteratorPool=h(this._iteratorPool),this._upsampleMapCache=h(this._upsampleMapCache),this._elevationQueryCache=h(this._elevationQueryCache),this._set("view",null),this._extentHelper=h(this._extentHelper),this._upsampleInfoPool=h(this._upsampleInfoPool),Ve(),this._layerViews.forEach(e=>e.length=0),this._performanceInfo=null}get renderer(){return this._renderer}get frustum(){return this.view.state.camera.frustum}get snapLevel(){return this.lodSnappingEnabled?this.view.terrainLevel: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=I(),r=X(t,i,e)?i:null,s=this._get("userClippingExtent");return k(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get groundExtent(){const e=V(this.fullGroundExtent,this.userClippingExtent,I()),t=this._get("groundExtent");return k(e,t)?t:e}get fullGroundExtent(){return null!=this._tilingSchemeExtent?this._tilingSchemeExtent:this._rootTilesExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),this.enabled&&!!((this.readyToRun||this._watchUpdatingTracking?.updating||this._asyncWorkItems>0)&&this.ready&&!this.suspended||this.overlayManager?.updating||this.terrainTextureCompressionTracker.compressing)}get readyToRun(){return this.enabled&&(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!this.enabled||null!=this._rootTiles}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.intersectRay(e,t,i,r)}getElevationLevelDelta(e){return e<4?3:this.view.qualitySettings.tiledSurface.elevationLevelDelta}get _xNormalizer(){return N(this._spatialReference)}getElevation(e,t,i,r){const s=this._rootTiles;if(!s?.length||!this.enabled)return null;if(0===s[0].layerInfo[0].length)return null;let a=this._elevationProjectorCache.get(r);if(void 0===a&&(a=M(r,this._spatialReference)??null,this._elevationProjectorCache.set(r,a)),null==a)return l.getLogger(this).error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;const n=b(rt,e,t,i);a(n,0,n,0);return ht(s,this._xNormalizer?.normalize(n[0])??n[0],n[1])}getElevations(e,t,i){const r=this._rootTiles,s=r?r[0].layerInfo[0].length:0;if(r?.length&&0!==s&&this.enabled)for(let a=0;a<t;++a){const t=3*a;i(a,ht(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(!D(e,rt,this.spatialReference))return l.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(rt)){let e=i;for(;e.children[0]&&!e.rendered;){const t=e.children[0].extent;let i=0;rt[0]>t[2]&&(i+=1),rt[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=M(e,this._tilingSchemeSpatialReference)??null;return this._projectorCache.set(e,i),i}getSphereElevationRange(e,t){if(!this.enabled||null==this._rootTiles)return null;const i=this._ensureProjector(t);if(null==i)return l.getLogger(this).error("TerrainSurface.getSphereElevationRange(): could not project given point to tiling scheme coordinate system"),null;st.copyFrom(e),i(st.center,0,st.center,0);const r=new Y,s=this._rootTiles;if(null!=s){const e=[];for(const i of s)e.push(i);let t=0;for(;t<e.length;){const i=e[t];if(++t,!A(i.extent,st))continue;const s=i.children;if(null==s[0]||i.rendered)r.expandElevationRangeValues(i.elevationBoundsMin,i.elevationBoundsMax);else for(const t of s)e.push(t)}}return r}getRootElevationRange(){return this.enabled&&null!=this._rootTiles?new Y(this._rootTileElevationRange.minElevation,this._rootTileElevationRange.maxElevation):null}getLowerBoundRadius(){const e=(this._ellipsoid.radius+this.visibleElevationRange.minElevation)*R;return Math.min(e,this._ellipsoid.radius)}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!D(e,st.center,this.spatialReference))return l.getLogger(this).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;st.radius=t;let i=null;const r=e=>{if(e&&A(e.extent,st)){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&&(this.notifyChange("opaque"),this.notifyChange("invisible"),!0)}_updateTilingScheme(){const{tilingScheme:e}=this.tilingSchemeLogic;if(!(e!==this.tilingScheme))return;ye(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();const t=e?.spatialReference??U.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateCarree=this._isWebMercator&&F(this.view?.renderSpatialReference),this._isGeographic=t?.isGeographic??!1,this._set("tilingScheme",e),this._tilingSchemeSpatialReference=this.tilingScheme?.spatialReference,this._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(et._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{groundExtent:e,tilingScheme:t}=this;if(!t)return;if(!this.enabled)return void this._setRootTiles(null);const i=at;let s=t.rootTilesInExtent(e,i,5*de);if(null!=this._rootTiles){if(s.length>de)return void l.getLogger(this).warn(pe);const e=this._rootTiles.map(e=>e.lij),t=r(e,s,ke);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this._rootTiles.filter(e=>!(t.removed.findIndex(t=>ke(t,e.lij))>-1)||(this._purgeTile(e),!1));t.added.forEach(t=>e.push(this._newRootTile(t))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,s.length>de&&(l.getLogger(this).warn(ue),s=t.rootTilesInExtent(e,i,de)),this._setRootTiles(s.map(e=>this._newRootTile(e)));k(i,this._rootTilesExtent)||(this._rootTilesExtent=I(i)),this.renderer.visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange("ready"),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness()}_updateAllTileGeometries(){const e=this._allTiles.filter(e=>e.loaded&&e.intersectsClippingArea);e.sort(Ge),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;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._updateRootTileElevationRange(),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.groundExtent)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(null==e)return;const t=qe(e),i=this.visibleElevationRange;let r=t?i.minElevation:1/0,s=t?i.maxElevation:-1/0;const a=this.groundExtent,n=this.view.state.contentCamera.viewProjectionMatrix;this.setTileTreeDirty(!1);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.minElevation!==r||i.maxElevation!==s)&&(this.visibleElevationRange=new J(r,s))}_updateRootTileElevationRange(){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._rootTileElevationRange;r.minElevation===e&&r.maxElevation===t||(this._rootTileElevationRange=new J(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=G(this._splitLimits.frustum??q(),t.frustum):this._splitLimits.frustum=null,E(this._eyePosRenderSR,t.eye),j(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(fe)&&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=lt.extent;B(e),this._pendingTilesForElevationUpdateEvent.forEach(t=>O(e,t.extent,e)),this._pendingTilesForElevationUpdateEvent.clear(),lt.spatialReference=this.spatialReference,this.emit("elevation-change",lt),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"),Pe&&this._checkTileInvariant(),!e.hasProgressed)return Ze}_checkTileInvariant(){const e=new Map;this._allTiles.forAll(t=>e.set(t,new Set)),this._allTiles.forAll(t=>{if(ye(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(ye(t.unmergableChildCount===i,` Tile[${t.lij.toString()}] unmergeable child count mismatch: actual ${t.unmergableChildCount} vs ${i}`),t.hasPendingUpdate(4)){ye(!t.hasPendingUpdate(1),"Tile can be both split and merge at the same time");for(const e of t.children)ye(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<=ce;r||(console.log(`tile level delta [${t.lij.toString()}] vs [${e.lij.toString()}] > ${ce} (edge[${i}])`),ye(r,`tile level delta [${t.level}] vs [${e.level}] > ${ce}`))}ye(t.level-e.level<=ce,`Max tile lod delta exceeded: [${t.lij.toString()}] vs [${e.lij.toString()}]`)}}const r=t.level-ce,s=e=>e.leaf||e.level===t.level,a=t.findNeighborTile(Te[i],s);if(null!=a){if(t.leaf&&t.level>=ce){let i=a;for(;t.level-i.level<ce;)i=i.parent;const s=[r,t.lij[1]>>ce,t.lij[2]>>ce];if(!ke(s,i.lij)){const r=e.get(i);ye(!r.has(t),"Cannot already have neighbor"),r.add(t)}}ye(a.rendered||a.level===t.level,"Non-same-level-neighbor of rendered must be rendered"),ye(t.level-a.level<=ce,`Tile level delta [${t.level}] vs [${a.level}] > ${ce}`)}}}),this._allTiles.forAll(t=>{const i=t.maxLevelDeltaNeighborCount,r=e.get(t);ye(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;let t=!1;const i=new ne(this._allTiles.length);i.pushAll(this._rootTiles);const r=this.snapLevel,s=this._splitLimits,a=this._eyePosRenderSR;this._allTiles.forAll(e=>{e.maxLevelDeltaNeighborCount=0,e.unmergableChildCount=0});const n=this.view.state.contentCamera.viewProjectionMatrix;for(;!i.empty;){const e=i.pop(),l=e.parent,o=l?.hasPendingUpdate(4),h=o?4:e.shouldSplit(s,a,r),d=1===h;e.leaf?dt(e,d):i.pushAll(e.children),o?(e.resetPendingUpdate(1),e.leaf||(e.setPendingUpdate(4),t=!0),this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(n)):d?(e.resetPendingUpdate(4),e.leaf&&(e.setPendingUpdate(1),t=!0)):(e.resetPendingUpdate(1)&&e.updateAgentSuspension(),2===h&&e.updateAgents(0),e.leaf||(e.setPendingUpdate(4),e.resetPendingUpdate(1),t=!0))}this._allTilesDirty=t,this.requestUpdate(),(this._shortBatches||!this._oneBatchPerFrameTask)&&this._updatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||!this.view.pointsOfInterest?.focus||(Ne(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger?.update(),e.madeProgress())}_markTileToUpdate(e){ve(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(Ge);const r=t.length;for(let s=0;s<r;++s){const r=t[s];ve(r.loaded),ve(r.intersectsClippingArea);const a=r.renderData;a.updateNeighborData();const n=a.dirtyEdgeResolutions,l=a.geometryState,o=e=>{const t=je[e];i(r,l.cornerPeerNeighbors[e]?.findCorner(Re(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(we(Te[t]),t=>!(!t.loaded||!t.intersectsClippingArea)&&(ve(e.has(t)||Ge(r,t)<0),i(r,t),!0)),o((t+1)%4),o(t)}}e.clear(),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,Pe&&Ue&&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>=ce){const e=e=>e.leaf||i-e.level<ce;for(let r=0;r<4;++r){const a=s.findNeighborTile(Te[r],e);null!=a&&i-a.level===ce&&(t=!1,Pe&&(ve(a.leaf),ve(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._allTilesCreated=!this.allTiles.some(e=>e.hasPendingUpdate(1)||e.hasPendingUpdate(4)&&0===e.unmergableChildCount),this._sortTiles(e)}_updateElevation(e){e.done||(this._allTiles.some(t=>(t.resetPendingUpdate(8)&&(this._updateTileGeometryState(t),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.updateOverlayParameters(),this.requestRender(1),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){return this.view.qualitySettings.tiledSurface.lodBias-(1-this.view.quality)*ge}_getLodBiasCorrectedScale(e){const t=this.tilingScheme.levels,i=o(e-this._lodBias,0,t.length-1),r=i-Math.floor(i);return t[Math.floor(i)].scale*(1-r)+t[Math.ceil(i)].scale*r}_removeAllTiles(){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?ut(e):this._purgeSubtree(e),this._allTiles.removeUnordered(e),this._unloadTile(e),e.dispose(),this._tileCache.put(et._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){ye(e.leaf,"Tile that is already split should not be split again!"),ye(e.rendered,"Tile marked to split is not rendered"),ut(e);const t=e.createChildren();this._allTiles.pushArray(t),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles}),e.updateAgentSuspension(),ye(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=>dt(e,e.hasPendingUpdate(1))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){ot.spatialReference=this.spatialReference,ot.extent=e.extent,ot.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",ot)}createTile(e,t,i,r){ye(!!r,"createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.groundExtent),s.updateScreenDepth(this.view.state.contentCamera.viewProjectionMatrix),this._shouldSplit(s)&&s.setPendingUpdate(1),s}get _shortBatches(){return 2!==this.view.state.mode}_mergeTile(e){ye(!e.hasPendingUpdate(1),"_mergeTile sanity check"),ye(!e.leaf,"Cannot merge a leaf"),e.leaf||(this._purgeSubtree(e),ye(!e.renderData,"Merging tile with existing render data?"),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),dt(e,!1),this._allTilesDirty=!0,++this._performanceInfo.numMerged)}_loadTile(e){e.load(),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager?.hasOverlays&&e.updateOverlayParameters(this.overlayManager)}_handleLayerViewChanges(e=Ke){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),Ce(e)||Se(e))if(this._basemapLayerViewHandles.has(e.uid)&&!Se(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(be(e)&&!$(e.layer)&&0!==e.fullOpacity)return!1;return!0}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if((Ee(e)||Se(e))&&$e(Qe[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return xe(e)?0:1}_registerTiledLayerView(e){const t=[];if((Ee(e)||Se(e))&&t.push(_(()=>e.layer.blendMode,()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(2)})),!Se(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||!Ce(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 re){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._updateRootTileElevationRange()}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){null!=this._rootTiles&&(Fe(this._rootTiles,i=>i.removeLayerAgent(e,t)),Fe(this._rootTiles,i=>{i.invalidateLayerData(e,t),i.restartAgents(t)}))}setTileTreeDirty(e){this._allTilesDirty=!0,e&&(this._allTilesCreated=!1)}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||fe(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,c(r),g(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();return 0===t?xe(i)?this._requestElevationTileData(e,i,r):Promise.reject():be(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{!m(i)&&r&&(this.setMemoryDirty(),this.requestUpdate(),this._elevationDataArrived(e,t,r))},s=i=>{g(i)||(l.getLogger(this).error(`Tile ${e.lij.toString()} layer 0/${t.uid} error ${i}`),this._dataMissing(e,0,t),this.requestUpdate())};return t.fetchElevationTile(e,{...Q,...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 l.getLogger(this).warn("TerrainSurface: received data from unknown layer %d %s",0,e.lij.toString());const s=new Z(e.lij,e.extent,i);e.dataArrived(r,0,s),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:0});const a=[e],n=e.level,o=this._iteratorPool.acquire();for(o.reset(a);!o.done;){const e=o.next();e.findElevationBoundsForLayer(r,n),e.computeElevationBounds()}0===n&&this._updateRootTileElevationRange(),o.remove(),this._updateTilesVisibility(a)}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{Le(s),m(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(),m(i)?Le(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 Le(i),void l.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})):l.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 renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){}checkAllTilesWaterproofness(){if(!Ue)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){Me(e)}enableWaterproofnessChecks(e){De(e)}static cleanupTerrainSurface(){nt.prune()}enable(e){e!==this.enabled&&(this._set("enabled",e),e?(this._updateRootTiles(),this.suspended=!1,this.view.elevationProvider.register(0,this)):(this.view.elevationProvider.unregister(this),this.suspended=!0,this._removeAllTiles(),this._setRootTiles(null)),this.notifyChange("ready"))}updateOverlayParameters(){const{overlayManager:e}=this;this.allTiles.forAll(t=>t.updateOverlayParameters(e))}};e([w()],tt.prototype,"_renderer",void 0),e([w({constructOnly:!0})],tt.prototype,"_scaleRangeQueries",void 0),e([w({constructOnly:!0})],tt.prototype,"view",void 0),e([w({constructOnly:!0})],tt.prototype,"overlayManager",void 0),e([w({constructOnly:!0})],tt.prototype,"terrainTextureCompressionTracker",void 0),e([w()],tt.prototype,"_hasPendingUpdates",void 0),e([w()],tt.prototype,"_asyncWorkItems",void 0),e([w()],tt.prototype,"_allTilesDirty",void 0),e([w()],tt.prototype,"_allTilesSorted",void 0),e([w()],tt.prototype,"allTilesCreated",null),e([w()],tt.prototype,"_allTilesCreated",void 0),e([w()],tt.prototype,"_viewChanged",void 0),e([w({type:Number})],tt.prototype,"heading",void 0),e([w()],tt.prototype,"_splitLimits",void 0),e([w({readOnly:!0})],tt.prototype,"_watchUpdatingTracking",void 0),e([w()],tt.prototype,"_frameTask",void 0),e([w()],tt.prototype,"demResolution",null),e([w({readOnly:!0})],tt.prototype,"snapLevel",null),e([w({readOnly:!0})],tt.prototype,"lodSnappingEnabled",null),e([w({readOnly:!0})],tt.prototype,"userClippingExtent",null),e([w()],tt.prototype,"_rootTilesExtent",void 0),e([w({readOnly:!0})],tt.prototype,"groundExtent",null),e([w({readOnly:!0})],tt.prototype,"fullGroundExtent",null),e([w({readOnly:!0})],tt.prototype,"_tilingSchemeExtent",null),e([w({readOnly:!0})],tt.prototype,"updating",null),e([w({readOnly:!0})],tt.prototype,"readyToRun",null),e([w(K)],tt.prototype,"updatingProgress",void 0),e([w({readOnly:!0})],tt.prototype,"updatingProgressValue",null),e([w()],tt.prototype,"_maxNumUpdating",void 0),e([w()],tt.prototype,"baseOpacity",null),e([w()],tt.prototype,"hasCompositeBlendMode",void 0),e([w({readOnly:!0})],tt.prototype,"viewingMode",null),e([w()],tt.prototype,"maxTextureScale",void 0),e([w({readOnly:!0})],tt.prototype,"ready",null),e([w({readOnly:!0})],tt.prototype,"rootTiles",null),e([w()],tt.prototype,"_rootTiles",void 0),e([w({readOnly:!0})],tt.prototype,"spatialReference",null),e([w({type:t})],tt.prototype,"backgroundColor",null),e([w({value:!1})],tt.prototype,"slicePlaneEnabled",null),e([w({readOnly:!0})],tt.prototype,"tilingScheme",void 0),e([w({readOnly:!0})],tt.prototype,"tilingSchemeLocked",null),e([w({readOnly:!0})],tt.prototype,"tilingSchemeLogic",void 0),e([w()],tt.prototype,"wireframe",null),e([w()],tt.prototype,"opaque",null),e([w()],tt.prototype,"invisible",null),e([w({value:!1})],tt.prototype,"suspended",null),e([w()],tt.prototype,"fadeDuration",null),e([w()],tt.prototype,"_xNormalizer",null),e([w()],tt.prototype,"visibleElevationRange",void 0),e([w()],tt.prototype,"_rootTileElevationRange",void 0),e([w()],tt.prototype,"_layerViewsDirty",void 0),e([w()],tt.prototype,"renderPatchBorders",null),e([w()],tt.prototype,"renderingDisabled",null),e([w({readOnly:!0})],tt.prototype,"enabled",void 0),tt=et=e([C("esri.views.3d.terrain.TerrainSurface")],tt);const it=tt,rt=x(),st=new W,at=I(),nt=new u,lt=new te("ground"),ot={spatialReference:null,extent:null,scale:0};function ht(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 ee(t,i,s)}return null}function dt(e,t){!e.leaf||e.level<ce||gt(e,e=>{t&&pt(e);const i=ct(e);if(e.maxLevelDeltaNeighborCount++,i){let t=e.parent;for(;t;){const e=ct(t);if(t.unmergableChildCount++,!e)break;t=t.parent}}})}function pt(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<ce||gt(e,e=>{pt(e)})}function ut(e){e.level<ce||gt(e,e=>{if(e.maxLevelDeltaNeighborCount--,0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount){let t=e.parent;for(;t&&(t.unmergableChildCount--,ct(t));)t=t.parent}})}function ct(e){return 0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount}function gt(e,t){if(e.level<ce)return;const i=e.level-ce,r=e.lij[1]>>ce,s=e.lij[2]>>ce,a=e=>e.leaf||e.level===i;for(let n=0;n<4;++n){const l=e.findNeighborTile(Te[n],a);if(!l||l.level!==i)continue;const o=l.lij;o[1]===r&&o[2]===s||t(l)}}export{it as default};
2
+ import{__decorate as e}from"tslib";import t from"../../../Color.js";import{filterInPlace as i,difference as r}from"../../../core/arrayUtils.js";import s from"../../../core/CollectionFlattener.js";import{toConst as a}from"../../../core/compilerUtils.js";import{EventedAccessor as n}from"../../../core/Evented.js";import"../../../core/has.js";import l from"../../../core/Logger.js";import{clamp as o}from"../../../core/mathUtils.js";import{destroyMaybe as h}from"../../../core/maybe.js";import{MemCachePool as d}from"../../../core/MemCachePool.js";import p from"../../../core/ObjectPool.js";import u from"../../../core/PooledArray.js";import{throwIfAborted as c,isAbortError as g,isAborted as m}from"../../../core/promiseUtils.js";import{watch as _,syncAndInitial as y,sync as f,initial as T}from"../../../core/reactiveUtils.js";import{getMetersPerUnitForSR as v}from"../../../core/units.js";import{property as w,subclass as S}from"../../../core/accessorSupport/decorators.js";import{exactEquals as C,set as b,copy as E}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as x}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as U}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as L,radiusModifier as P}from"../../../geometry/ellipsoidUtils.js";import R from"../../../geometry/SpatialReference.js";import{getProjector as M}from"../../../geometry/projection/projectors.js";import{projectPointToVector as D}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as j}from"../../../geometry/projection/projectVectorToVector.js";import{create as I,equals as k,intersection as V,intersectsSphere as A,empty as B,expand as G}from"../../../geometry/support/aaBoundingRect.js";import{copy as O,create as q}from"../../../geometry/support/frustum.js";import{createSpatialReferenceCyclical as N}from"../../../geometry/support/normalizeUtils.js";import{isPlateCarree as F}from"../../../geometry/support/spatialReferenceUtils.js";import{Sphere as W}from"../../../geometry/support/sphere.js";import{ElevationQueryTileCache as H}from"../../../layers/support/ElevationQueryTileCache.js";import{isBaseLayer as $}from"../../../layers/support/layerUtils.js";import{queueHighPriority as Q}from"../../../request/queue.js";import{debugFlags as z}from"../support/debugFlags.js";import{ElevationRange as Y}from"../support/ElevationRange.js";import{toBoundingRect as X}from"../support/extentUtils.js";import{updatingProgress as K}from"../support/updatingProperties.js";import{ElevationBounds as J}from"./ElevationBounds.js";import{ElevationData as Z,sampleElevation as ee}from"./ElevationData.js";import{ElevationUpdateEvent as te}from"./ElevationUpdateEvent.js";import{create as ie}from"./ExtentHelper.js";import{LayerClasses as re}from"./LayerClass.js";import{OverlayManager as se}from"./OverlayManager.js";import{PlanarPatch as ae}from"./PlanarPatch.js";import{Queue as ne}from"./Queue.js";import{ScaleRangeQueries as le}from"./ScaleRangeQueries.js";import{SphericalPatch as oe}from"./SphericalPatch.js";import{SplitLimits as he}from"./SplitLimits.js";import{maxRootTiles as de,tooManyRootTilesAfterChangeError as pe,tooManyRootTilesForLayerError as ue,maxTileNeighborLevelDelta as ce,maxMemoryLodBias as ge}from"./TerrainConst.js";import{TerrainRenderer as me}from"./TerrainRenderer.js";import _e from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as ye,isVectorTileLayerView as fe,neighborEdgeIndices as Te,internalAssert as ve,oppositeEdge as we,isSurfaceLayerView as Se,isGroupLayerView as Ce,isMapTileLayerView as be,isBlendableLayerView as Ee,isElevationLayerView as xe,releaseTerrainData as Ue,enableTerrainInternalChecks as Le,oppositeCorner as Pe,enableWaterproofTests as Re,enableInternalTerrainChecks as Me,enableTerrainWaterproofChecks as De,neighborCornerIndices as je}from"./terrainUtils.js";import{Tile as Ie,lijEquals as ke}from"./Tile.js";import{printAllocations as Ve}from"./TilePerLayerInfo.js";import{sortTiles as Ae,IteratorPreorder as Be,IteratorPostorder as Ge,compareTilesByLij as Oe,hasLoadableSiblings as qe,sortTilesByPOI as Ne,traverseTilesPreorder as Fe}from"./tileUtils.js";import{TilingSchemeLogic as We}from"./TilingSchemeLogic.js";import{UpsampleInfo as He}from"./UpsampleInfo.js";import{isCompositeBlendMode as $e,blendModeFromString as Qe}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{hasLayerBasedScaleVisibility as ze}from"../../support/layerViewUtils.js";import{ImmediateTask as Ye,TaskPriority as Xe,noBudget as Ke}from"../../support/Scheduler.js";import{TextureCompressionTracker as Je}from"../../support/TextureCompressionTracker.js";import{Yield as Ze}from"../../support/Yield.js";var et;let tt=class extends n{static{et=this}get allTilesCreated(){return this._allTilesCreated}get allTiles(){return a(this._allTiles)}get renderedTiles(){return Ae(i(this._allTiles.toArray(),e=>e.visible&&e.rendered))}get demResolution(){const{_allTiles:e,tilingScheme:t}=this;if(0===e.length)return{min:1,max:1};const i=v(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 Je,this._iteratorPool=new p(()=>new Be,e=>e.remove=()=>this._iteratorPool.release(e)),this._postorderIterator=new Ge,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._allTilesCreated=!1,this._usedMemory=null,this._performanceInfo=new _e,this._viewChanged=!1,this.heading=0,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=x(),this._eyePosSurfaceSR=x(),this._splitLimits=new he,this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._watchUpdatingTracking=new U,this._frameTask=Ye,this._allTiles=new u,this._upsampleInfoPool=new p(()=>new He),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=I(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=R.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationRange=new Y(1/0,-1/0),this._rootTileElevationRange=new Y(1/0,-1/0),this._projectorCache=new Map,this._tilingSchemeSpatialReference=null,this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._oneBatchPerFrameTask=!0,this._layerViewsDirty=!1,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._isWebMercator=!1,this._isWebMercatorOnPlateCarree=!1,this.enabled=!0;const{view:t}=e;this.overlayManager=new se({...e,terrainSurface:this}),this._isGlobal=!t.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?oe:ae,this._ellipsoid=L(t.spatialReference),this._renderer=new me(this.overlayManager.renderer,t.stage,this._allTiles,this.terrainTextureCompressionTracker,t.resourceController.memoryController),ze()||(this._scaleRangeQueries=new le)}initialize(){const{view:e}=this,{resourceController:t}=e,{memoryController:i}=t;this._tileCache=new d((e,t)=>i.newCache(e,t),"terrain-tile"),this._upsampleMapCache=i.newCache("terrain-upsample",({tile:e})=>e.unloadMapData()),this._elevationQueryCache=new H(i.newCache("elevation-query"));const r=this.overlayManager;this.addHandles([_(()=>r.renderer.isEmpty,()=>this._evaluateTransparency()),_(()=>this.renderer.visible,e=>this.suspended=!e),_(()=>this.heading,e=>{this._renderer.updateHeading(e),this._updateTileTextures(0)},y),_(()=>({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)},y),_(()=>this.hasCompositeBlendMode,()=>this._updateTileTextures(this._evaluateTransparency()?1:2),y),_(()=>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,{equals:C})}),_(()=>z.TERRAIN_TILE_TREE_SHOW_TILES,t=>{t&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then(({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&z.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))}):t||(this._treeDebugger=h(this._treeDebugger))},T)]);const{spatialReference:a}=e;this._extentHelper=ie(this.viewingMode,{layers:e.map.allLayers,layerViews:e.allLayerViews,viewSpatialReference:a});const n=new s({getCollections:()=>e.defaultsFromMap?.mapCollections?.map(({layers:e})=>e),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}),l=new We({layers:n,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set("tilingSchemeLogic",l),this._updateTilingScheme();const o=t.scheduler;this._frameTask=o.registerTask(Xe.TERRAIN_SURFACE,this),this.addHandles([_(()=>this._extentHelper.stencilEnabledExtents,e=>this._renderer.setStencilEnabledLayerExtents(e),T),_(()=>this.tilingSchemeLogic.tilingScheme,()=>this._updateTilingScheme(),f),_(()=>this.groundExtent,()=>this._updateRootTiles(),T),e.on("resize",()=>this._viewChangeUpdate()),_(()=>{const t=e.state;return[this._lodBias,this.lodSnappingEnabled,e.quality,t.camera,t.contentCamera,t.fixedContentCamera]},()=>this._viewChangeUpdate(),y),_(()=>e.qualitySettings?.fadeDuration,e=>this._renderer.textureFadingEnabled=e>0,T),_(()=>e.qualitySettings?.physicallyBasedRenderingEnabled,e=>this._renderer.pbrMode=e?5:0,T),_(()=>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=Ye,this._watchUpdatingTracking?.destroy(),this._removeAllTiles(),this._set("tilingSchemeLogic",h(this.tilingSchemeLogic)),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear(),this._set("overlayManager",h(this.overlayManager)),this._tileCache=h(this._tileCache),this._allTiles.prune(),Ie.prune(),this._treeDebugger=h(this._treeDebugger),this._renderer.destroyed||this._renderer.destroy(),this._renderer=null,this._iteratorPool=h(this._iteratorPool),this._upsampleMapCache=h(this._upsampleMapCache),this._elevationQueryCache=h(this._elevationQueryCache),this._set("view",null),this._extentHelper=h(this._extentHelper),this._upsampleInfoPool=h(this._upsampleInfoPool),Ve(),this._layerViews.forEach(e=>e.length=0),this._performanceInfo=null}get renderer(){return this._renderer}get frustum(){return this.view.state.camera.frustum}get snapLevel(){return this.lodSnappingEnabled?this.view.terrainLevel: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=I(),r=X(t,i,e)?i:null,s=this._get("userClippingExtent");return k(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get groundExtent(){const e=V(this.fullGroundExtent,this.userClippingExtent,I()),t=this._get("groundExtent");return k(e,t)?t:e}get fullGroundExtent(){return null!=this._tilingSchemeExtent?this._tilingSchemeExtent:this._rootTilesExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),this.enabled&&!!((this.readyToRun||this._watchUpdatingTracking?.updating||this._asyncWorkItems>0)&&this.ready&&!this.suspended||this.overlayManager?.updating||this.terrainTextureCompressionTracker.compressing)}get readyToRun(){return this.enabled&&(this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||!this._allTilesSorted||this._hasElevationSourceUpdates||this._layerViewsDirty||this._scaleRangeQueries?.updating||this._frameTask.updating)&&this.ready&&!this.suspended}get _hasElevationSourceUpdates(){return this._allTiles.some(e=>e.needsElevationSourceUpdate())}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!this.enabled||null!=this._rootTiles}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.intersectRay(e,t,i,r)}getElevationLevelDelta(e){return e<4?3:this.view.qualitySettings.tiledSurface.elevationLevelDelta}get _xNormalizer(){return N(this._spatialReference)}getElevation(e,t,i,r){const s=this._rootTiles;if(!s?.length||!this.enabled)return null;if(0===s[0].layerInfo[0].length)return null;let a=this._elevationProjectorCache.get(r);if(void 0===a&&(a=M(r,this._spatialReference)??null,this._elevationProjectorCache.set(r,a)),null==a)return l.getLogger(this).error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;const n=b(rt,e,t,i);a(n,0,n,0);return ht(s,this._xNormalizer?.normalize(n[0])??n[0],n[1])}getElevations(e,t,i){const r=this._rootTiles,s=r?r[0].layerInfo[0].length:0;if(r?.length&&0!==s&&this.enabled)for(let a=0;a<t;++a){const t=3*a;i(a,ht(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(!D(e,rt,this.spatialReference))return l.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(rt)){let e=i;for(;e.children[0]&&!e.rendered;){const t=e.children[0].extent;let i=0;rt[0]>t[2]&&(i+=1),rt[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=M(e,this._tilingSchemeSpatialReference)??null;return this._projectorCache.set(e,i),i}getSphereElevationRange(e,t){if(!this.enabled||null==this._rootTiles)return null;const i=this._ensureProjector(t);if(null==i)return l.getLogger(this).error("TerrainSurface.getSphereElevationRange(): could not project given point to tiling scheme coordinate system"),null;st.copyFrom(e),i(st.center,0,st.center,0);const r=new Y,s=this._rootTiles;if(null!=s){const e=[];for(const i of s)e.push(i);let t=0;for(;t<e.length;){const i=e[t];if(++t,!A(i.extent,st))continue;const s=i.children;if(null==s[0]||i.rendered)r.expandElevationRangeValues(i.elevationBoundsMin,i.elevationBoundsMax);else for(const t of s)e.push(t)}}return r}getRootElevationRange(){return this.enabled&&null!=this._rootTiles?new Y(this._rootTileElevationRange.minElevation,this._rootTileElevationRange.maxElevation):null}getLowerBoundRadius(){const e=(this._ellipsoid.radius+this.visibleElevationRange.minElevation)*P;return Math.min(e,this._ellipsoid.radius)}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!D(e,st.center,this.spatialReference))return l.getLogger(this).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;st.radius=t;let i=null;const r=e=>{if(e&&A(e.extent,st)){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&&(this.notifyChange("opaque"),this.notifyChange("invisible"),!0)}_updateTilingScheme(){const{tilingScheme:e}=this.tilingSchemeLogic;if(!(e!==this.tilingScheme))return;ye(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();const t=e?.spatialReference??R.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateCarree=this._isWebMercator&&F(this.view?.renderSpatialReference),this._isGeographic=t?.isGeographic??!1,this._set("tilingScheme",e),this._tilingSchemeSpatialReference=this.tilingScheme?.spatialReference,this._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(et._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{groundExtent:e,tilingScheme:t}=this;if(!t)return;if(!this.enabled)return void this._setRootTiles(null);const i=at;let s=t.rootTilesInExtent(e,i,5*de);if(null!=this._rootTiles){if(s.length>de)return void l.getLogger(this).warn(pe);const e=this._rootTiles.map(e=>e.lij),t=r(e,s,ke);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this._rootTiles.filter(e=>!(t.removed.findIndex(t=>ke(t,e.lij))>-1)||(this._purgeTile(e),!1));t.added.forEach(t=>e.push(this._newRootTile(t))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,s.length>de&&(l.getLogger(this).warn(ue),s=t.rootTilesInExtent(e,i,de)),this._setRootTiles(s.map(e=>this._newRootTile(e)));k(i,this._rootTilesExtent)||(this._rootTilesExtent=I(i)),this.renderer.visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange("ready"),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness()}_updateAllTileGeometries(){const e=this._allTiles.filter(e=>this._canUpdateTileGeometry(e));0!==e.length?(e.sort(Oe),e.forEach(e=>this._renderer.updateTileGeometryState(e)),e.forEach(e=>e.renderData.updateNeighborData()),this._updateTilesGeometries(e),this._pendingTilesToUpdate.clear()):this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){const t=e.filter(e=>this._canUpdateTileGeometry(e));if(0===t.length)return;const i=this.renderer;for(const r of t)i.updateGeometryIfNeeded(r);for(const r of t)this._pendingTilesForElevationUpdateEvent.add(r)}_canUpdateTileGeometry(e){return e.loaded&&e.intersectsClippingArea&&e.hasGeometryState}_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._updateRootTileElevationRange(),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.groundExtent)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(null==e)return;const t=qe(e),i=this.visibleElevationRange;let r=t?i.minElevation:1/0,s=t?i.maxElevation:-1/0;const a=this.groundExtent,n=this.view.state.contentCamera.viewProjectionMatrix;this.setTileTreeDirty(!1);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.minElevation!==r||i.maxElevation!==s)&&(this.visibleElevationRange=new J(r,s))}_updateRootTileElevationRange(){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._rootTileElevationRange;r.minElevation===e&&r.maxElevation===t||(this._rootTileElevationRange=new J(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=O(this._splitLimits.frustum??q(),t.frustum):this._splitLimits.frustum=null,E(this._eyePosRenderSR,t.eye),j(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateTileGeometryState(e){e.updateVisibility();const t=this._renderer.updateTileGeometryState(e);e.needsElevationSourceUpdate()&&(e.updateAgents(0),e.markElevationSourceUpdateRequested(),this.requestUpdate()),t&&this._markTileToUpdate(e),this.setMemoryDirty()}_markAllTileNeighborsForUpdate(e){e.forEachLoadedNeighbor(e=>{this._layerViews[1].some(fe)&&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=lt.extent;B(e),this._pendingTilesForElevationUpdateEvent.forEach(t=>G(e,t.extent,e)),this._pendingTilesForElevationUpdateEvent.clear(),lt.spatialReference=this.spatialReference,this.emit("elevation-change",lt),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;this._mergeAndSplit(e,t),this._updateElevation(e),this._updateElevationSources(e),this._updateTextures(e),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty();const i=this._pendingTilesToUpdate.size>0,r=i&&this._hasPendingGeometryWithoutIndices();if(e.done&&!r||this._updatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&(e.hasProgressed||i&&!r)&&this.requestUpdate(),this.notifyChange("updatingProgressValue"),Le&&this._checkTileInvariant(),!e.hasProgressed)return Ze}_checkTileInvariant(){const e=new Map;this._allTiles.forAll(t=>e.set(t,new Set)),this._allTiles.forAll(t=>{if(ye(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(ye(t.unmergableChildCount===i,` Tile[${t.lij.toString()}] unmergeable child count mismatch: actual ${t.unmergableChildCount} vs ${i}`),t.hasPendingUpdate(4)){ye(!t.hasPendingUpdate(1),"Tile can be both split and merge at the same time");for(const e of t.children)ye(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<=ce;r||(console.log(`tile level delta [${t.lij.toString()}] vs [${e.lij.toString()}] > ${ce} (edge[${i}])`),ye(r,`tile level delta [${t.level}] vs [${e.level}] > ${ce}`))}ye(t.level-e.level<=ce,`Max tile lod delta exceeded: [${t.lij.toString()}] vs [${e.lij.toString()}]`)}}const r=t.level-ce,s=e=>e.leaf||e.level===t.level,a=t.findNeighborTile(Te[i],s);if(null!=a){if(t.leaf&&t.level>=ce){let i=a;for(;t.level-i.level<ce;)i=i.parent;const s=[r,t.lij[1]>>ce,t.lij[2]>>ce];if(!ke(s,i.lij)){const r=e.get(i);ye(!r.has(t),"Cannot already have neighbor"),r.add(t)}}ye(a.rendered||a.level===t.level,"Non-same-level-neighbor of rendered must be rendered"),ye(t.level-a.level<=ce,`Tile level delta [${t.level}] vs [${a.level}] > ${ce}`)}}}),this._allTiles.forAll(t=>{const i=t.maxLevelDeltaNeighborCount,r=e.get(t);ye(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;let t=!1;const i=new ne(this._allTiles.length);i.pushAll(this._rootTiles);const r=this.snapLevel,s=this._splitLimits,a=this._eyePosRenderSR;this._allTiles.forAll(e=>{e.maxLevelDeltaNeighborCount=0,e.unmergableChildCount=0});const n=this.view.state.contentCamera.viewProjectionMatrix;for(;!i.empty;){const e=i.pop(),l=e.parent,o=l?.hasPendingUpdate(4),h=o?4:e.shouldSplit(s,a,r),d=1===h;e.leaf?dt(e,d):i.pushAll(e.children),o?(e.resetPendingUpdate(1),e.leaf||(e.setPendingUpdate(4),t=!0),this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(n)):d?(e.resetPendingUpdate(4),e.leaf&&(e.setPendingUpdate(1),t=!0)):(e.resetPendingUpdate(1)&&e.updateAgentSuspension(),2===h&&e.updateAgents(0),e.leaf||(e.setPendingUpdate(4),e.resetPendingUpdate(1),t=!0))}this._allTilesDirty=t,this.requestUpdate(),(this._shortBatches||!this._oneBatchPerFrameTask)&&this._updatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||!this.view.pointsOfInterest?.focus||(Ne(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger?.update(),e.madeProgress())}_markTileToUpdate(e){ve(e.loaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForUpdate(e))}_hasPendingGeometryWithoutIndices(){for(const e of this._pendingTilesToUpdate)if(e.loaded&&e.intersectsClippingArea&&null==e.renderData?.vao?.indexBuffer)return!0;return!1}_updatePendingTileGeometries(){const e=this._pendingTilesToUpdate,t=[];if(e.forEach(e=>{this._canUpdateTileGeometry(e)&&t.push(e)}),0===t.length)return void e.clear();const i=(i,r)=>{!r||!this._canUpdateTileGeometry(r)||r.level<i.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(Oe);const r=t.length;for(let s=0;s<r;++s){const r=t[s];ve(r.loaded),ve(r.intersectsClippingArea);const a=r.renderData;if(!a?.geometryState)continue;a.updateNeighborData();const n=a.dirtyEdgeResolutions,l=a.geometryState,o=e=>{const t=je[e];i(r,l.cornerPeerNeighbors[e]?.findCorner(Pe(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(we(Te[t]),t=>!!this._canUpdateTileGeometry(t)&&(ve(e.has(t)||Oe(r,t)<0),i(r,t),!0)),o((t+1)%4),o(t)}}e.clear(),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,Le&&Re&&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>=ce){const e=e=>e.leaf||i-e.level<ce;for(let r=0;r<4;++r){const a=s.findNeighborTile(Te[r],e);null!=a&&i-a.level===ce&&(t=!1,Le&&(ve(a.leaf),ve(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._allTilesCreated=!this.allTiles.some(e=>e.hasPendingUpdate(1)||e.hasPendingUpdate(4)&&0===e.unmergableChildCount),this._sortTiles(e)}_updateElevation(e){e.done||(this._allTiles.some(t=>(t.resetPendingUpdate(8)&&(this._updateTileGeometryState(t),e.madeProgress()),e.done)),!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries())}_updateElevationSources(e){e.done||this._allTiles.some(t=>(t.needsElevationSourceUpdate()&&(t.updateAgents(0),t.markElevationSourceUpdateRequested(),e.madeProgress()),e.done))}_updateTextures(e){e.done||this._allTiles.some(t=>(this._updateTileTexture(t,e),e.done))}_updateClippingExtent(){this.spatialReference&&(this.updateOverlayParameters(),this.requestRender(1),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){return this.view.qualitySettings.tiledSurface.lodBias-(1-this.view.quality)*ge}_getLodBiasCorrectedScale(e){const t=this.tilingScheme.levels,i=o(e-this._lodBias,0,t.length-1),r=i-Math.floor(i);return t[Math.floor(i)].scale*(1-r)+t[Math.ceil(i)].scale*r}_removeAllTiles(){this._pendingTilesToUpdate.clear(),this._pendingTilesForElevationUpdateEvent.clear(),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?ut(e):this._purgeSubtree(e),this._allTiles.removeUnordered(e),this._unloadTile(e),e.dispose(),this._tileCache.put(et._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){ye(e.leaf,"Tile that is already split should not be split again!"),ye(e.rendered,"Tile marked to split is not rendered"),ut(e);const t=e.createChildren();this._allTiles.pushArray(t),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles}),e.updateAgentSuspension(),ye(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=>dt(e,e.hasPendingUpdate(1))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){ot.spatialReference=this.spatialReference,ot.extent=e.extent,ot.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",ot)}createTile(e,t,i,r){ye(!!r,"createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.groundExtent),s.updateScreenDepth(this.view.state.contentCamera.viewProjectionMatrix),this._shouldSplit(s)&&s.setPendingUpdate(1),s}get _shortBatches(){return 2!==this.view.state.mode}_mergeTile(e){ye(!e.hasPendingUpdate(1),"_mergeTile sanity check"),ye(!e.leaf,"Cannot merge a leaf"),e.leaf||(this._purgeSubtree(e),ye(!e.renderData,"Merging tile with existing render data?"),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),dt(e,!1),this._allTilesDirty=!0,++this._performanceInfo.numMerged)}_loadTile(e){e.load(),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager?.hasOverlays&&e.updateOverlayParameters(this.overlayManager)}_handleLayerViewChanges(e=Ke){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),Se(e)||Ce(e))if(this._basemapLayerViewHandles.has(e.uid)&&!Ce(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(be(e)&&!$(e.layer)&&0!==e.fullOpacity)return!1;return!0}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if((Ee(e)||Ce(e))&&$e(Qe[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return xe(e)?0:1}_registerTiledLayerView(e){const t=[];if((Ee(e)||Ce(e))&&t.push(_(()=>e.layer.blendMode,()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(2)})),!Ce(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||!Se(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 re){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._updateRootTileElevationRange()}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){null!=this._rootTiles&&(Fe(this._rootTiles,i=>i.removeLayerAgent(e,t)),Fe(this._rootTiles,i=>{i.invalidateLayerData(e,t),i.restartAgents(t)}))}setTileTreeDirty(e){this._allTilesDirty=!0,e&&(this._allTilesCreated=!1)}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||fe(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,c(r),g(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();return 0===t?xe(i)?this._requestElevationTileData(e,i,r):Promise.reject():be(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{!m(i)&&r&&(this.setMemoryDirty(),this.requestUpdate(),this._elevationDataArrived(e,t,r))},s=i=>{g(i)||(l.getLogger(this).error(`Tile ${e.lij.toString()} layer 0/${t.uid} error ${i}`),this._dataMissing(e,0,t),this.requestUpdate())};return t.fetchElevationTile(e,{...Q,...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 l.getLogger(this).warn("TerrainSurface: received data from unknown layer %d %s",0,e.lij.toString());const s=new Z(e.lij,e.extent,i);e.dataArrived(r,0,s),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:0});const a=[e],n=e.level,o=this._iteratorPool.acquire();for(o.reset(a);!o.done;){const e=o.next();e.findElevationBoundsForLayer(r,n),e.computeElevationBounds()}0===n&&this._updateRootTileElevationRange(),o.remove(),this._updateTilesVisibility(a)}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{Ue(s),m(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(),m(i)?Ue(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 Ue(i),void l.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})):l.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 renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){}checkAllTilesWaterproofness(){if(!Re)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){Me(e)}enableWaterproofnessChecks(e){De(e)}static cleanupTerrainSurface(){nt.prune()}enable(e){e!==this.enabled&&(this._set("enabled",e),e?(this._updateRootTiles(),this.suspended=!1,this.view.elevationProvider.register(0,this)):(this.view.elevationProvider.unregister(this),this.suspended=!0,this._removeAllTiles(),this._setRootTiles(null)),this.notifyChange("ready"))}updateOverlayParameters(){const{overlayManager:e}=this;this.allTiles.forAll(t=>t.updateOverlayParameters(e))}};e([w()],tt.prototype,"_renderer",void 0),e([w({constructOnly:!0})],tt.prototype,"_scaleRangeQueries",void 0),e([w({constructOnly:!0})],tt.prototype,"view",void 0),e([w({constructOnly:!0})],tt.prototype,"overlayManager",void 0),e([w({constructOnly:!0})],tt.prototype,"terrainTextureCompressionTracker",void 0),e([w()],tt.prototype,"_hasPendingUpdates",void 0),e([w()],tt.prototype,"_asyncWorkItems",void 0),e([w()],tt.prototype,"_allTilesDirty",void 0),e([w()],tt.prototype,"_allTilesSorted",void 0),e([w()],tt.prototype,"allTilesCreated",null),e([w()],tt.prototype,"_allTilesCreated",void 0),e([w()],tt.prototype,"_viewChanged",void 0),e([w({type:Number})],tt.prototype,"heading",void 0),e([w()],tt.prototype,"_splitLimits",void 0),e([w({readOnly:!0})],tt.prototype,"_watchUpdatingTracking",void 0),e([w()],tt.prototype,"_frameTask",void 0),e([w()],tt.prototype,"demResolution",null),e([w({readOnly:!0})],tt.prototype,"snapLevel",null),e([w({readOnly:!0})],tt.prototype,"lodSnappingEnabled",null),e([w({readOnly:!0})],tt.prototype,"userClippingExtent",null),e([w()],tt.prototype,"_rootTilesExtent",void 0),e([w({readOnly:!0})],tt.prototype,"groundExtent",null),e([w({readOnly:!0})],tt.prototype,"fullGroundExtent",null),e([w({readOnly:!0})],tt.prototype,"_tilingSchemeExtent",null),e([w({readOnly:!0})],tt.prototype,"updating",null),e([w({readOnly:!0})],tt.prototype,"readyToRun",null),e([w(K)],tt.prototype,"updatingProgress",void 0),e([w({readOnly:!0})],tt.prototype,"updatingProgressValue",null),e([w()],tt.prototype,"_maxNumUpdating",void 0),e([w()],tt.prototype,"baseOpacity",null),e([w()],tt.prototype,"hasCompositeBlendMode",void 0),e([w({readOnly:!0})],tt.prototype,"viewingMode",null),e([w()],tt.prototype,"maxTextureScale",void 0),e([w({readOnly:!0})],tt.prototype,"ready",null),e([w({readOnly:!0})],tt.prototype,"rootTiles",null),e([w()],tt.prototype,"_rootTiles",void 0),e([w({readOnly:!0})],tt.prototype,"spatialReference",null),e([w({type:t})],tt.prototype,"backgroundColor",null),e([w({value:!1})],tt.prototype,"slicePlaneEnabled",null),e([w({readOnly:!0})],tt.prototype,"tilingScheme",void 0),e([w({readOnly:!0})],tt.prototype,"tilingSchemeLocked",null),e([w({readOnly:!0})],tt.prototype,"tilingSchemeLogic",void 0),e([w()],tt.prototype,"wireframe",null),e([w()],tt.prototype,"opaque",null),e([w()],tt.prototype,"invisible",null),e([w({value:!1})],tt.prototype,"suspended",null),e([w()],tt.prototype,"fadeDuration",null),e([w()],tt.prototype,"_xNormalizer",null),e([w()],tt.prototype,"visibleElevationRange",void 0),e([w()],tt.prototype,"_rootTileElevationRange",void 0),e([w()],tt.prototype,"_layerViewsDirty",void 0),e([w()],tt.prototype,"renderPatchBorders",null),e([w()],tt.prototype,"renderingDisabled",null),e([w({readOnly:!0})],tt.prototype,"enabled",void 0),tt=et=e([S("esri.views.3d.terrain.TerrainSurface")],tt);const it=tt,rt=x(),st=new W,at=I(),nt=new u,lt=new te("ground"),ot={spatialReference:null,extent:null,scale:0};function ht(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 ee(t,i,s)}return null}function dt(e,t){!e.leaf||e.level<ce||gt(e,e=>{t&&pt(e);const i=ct(e);if(e.maxLevelDeltaNeighborCount++,i){let t=e.parent;for(;t;){const e=ct(t);if(t.unmergableChildCount++,!e)break;t=t.parent}}})}function pt(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<ce||gt(e,e=>{pt(e)})}function ut(e){e.level<ce||gt(e,e=>{if(e.maxLevelDeltaNeighborCount--,0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount){let t=e.parent;for(;t&&(t.unmergableChildCount--,ct(t));)t=t.parent}})}function ct(e){return 0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount}function gt(e,t){if(e.level<ce)return;const i=e.level-ce,r=e.lij[1]>>ce,s=e.lij[2]>>ce,a=e=>e.leaf||e.level===i;for(let n=0;n<4;++n){const l=e.findNeighborTile(Te[n],a);if(!l||l.level!==i)continue;const o=l.lij;o[1]===r&&o[2]===s||t(l)}}export{it as default};