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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/Basemap.d.ts +2 -2
  2. package/analysis/ShadowCastAnalysis.d.ts +11 -5
  3. package/arcgisGlobal.d.ts +1 -0
  4. package/assets/esri/core/libs/libtess/libtess-f32.wasm +0 -0
  5. package/assets/esri/core/libs/libtess/libtess-f64.wasm +0 -0
  6. package/assets/esri/core/workers/RemoteClient.js +1 -1
  7. package/assets/esri/core/workers/chunks/01f55004d64309f8538b.js +1 -0
  8. package/assets/esri/core/workers/chunks/0202eb8c2b2865f99981.js +1 -0
  9. package/assets/esri/core/workers/chunks/{67e533748435253aaba6.js → 0284f608d25c654fcc11.js} +1 -1
  10. package/assets/esri/core/workers/chunks/{7810586c35dfe1437516.js → 06102715e9a8f218e07c.js} +1 -1
  11. package/assets/esri/core/workers/chunks/{6029773458ab98600f67.js → 07e5482e1fc69be5de09.js} +1 -1
  12. package/assets/esri/core/workers/chunks/08140725277de5d2e41a.js +1 -0
  13. package/assets/esri/core/workers/chunks/{2d9a1f23ec6ce90723ac.js → 0d99bfb75dcb9fa29080.js} +1 -1
  14. package/assets/esri/core/workers/chunks/10ad7b35b6800d40444e.js +1 -0
  15. package/assets/esri/core/workers/chunks/1132e28aaa5825b10b6e.js +1 -0
  16. package/assets/esri/core/workers/chunks/{dd30b02c5978c1c5f511.js → 155861fbd0e5fc2db80c.js} +1 -1
  17. package/assets/esri/core/workers/chunks/165ca7a97b611c8f26c4.js +1 -0
  18. package/assets/esri/core/workers/chunks/1ae0c9345626e70affd3.js +2 -0
  19. package/assets/esri/core/workers/chunks/{cd355baab983033c3ef0.js → 1ec772eaa63eb6937231.js} +1 -1
  20. package/assets/esri/core/workers/chunks/{5c04835b0b52461183cd.js → 1fd82fcba2758741996a.js} +1 -1
  21. package/assets/esri/core/workers/chunks/21e1d423ee33f916547e.js +1 -0
  22. package/assets/esri/core/workers/chunks/{e8e54faf947a582b4cf7.js → 247617c0dbae2386ab3b.js} +1 -1
  23. package/assets/esri/core/workers/chunks/{97ec46605f16333144b7.js → 26ea39dfdf887f357fce.js} +1 -1
  24. package/assets/esri/core/workers/chunks/{85de980c5b296ec69323.js → 279089a6a3f08022c678.js} +1 -1
  25. package/assets/esri/core/workers/chunks/{b657363113f4a37e634b.js → 3223f9fbc76ba9ef8d13.js} +1 -1
  26. package/assets/esri/core/workers/chunks/322b22a5d54e404bebd5.js +1 -0
  27. package/assets/esri/core/workers/chunks/{122e75b21699a4e83b15.js → 338d800d4efcc91cead1.js} +1 -1
  28. package/assets/esri/core/workers/chunks/3537fe95b83a13b156cc.js +1 -0
  29. package/assets/esri/core/workers/chunks/{f09bc86cd52224febfcb.js → 3b380e64566a6cce59e2.js} +1 -1
  30. package/assets/esri/core/workers/chunks/{a1e8209d00809c9520a0.js → 3fe4c89acd325d36618d.js} +1 -1
  31. package/assets/esri/core/workers/chunks/449a2dee17b54946f245.js +1 -0
  32. package/assets/esri/core/workers/chunks/{311e4969f19df63451dd.js → 4e5405134d079bdf9b7a.js} +1 -1
  33. package/assets/esri/core/workers/chunks/{d070fcb73ce274ab80e4.js → 5504ec9bd9ee4d10af07.js} +1 -1
  34. package/assets/esri/core/workers/chunks/552c36b40e5a5ec117fb.js +1 -0
  35. package/assets/esri/core/workers/chunks/5622f3faa59434772857.js +1 -0
  36. package/assets/esri/core/workers/chunks/59a1b637d2c107504a04.js +1 -0
  37. package/assets/esri/core/workers/chunks/59a88dd53f8806bbec06.js +1 -0
  38. package/assets/esri/core/workers/chunks/5c2fe67527c9d7b4dba3.js +1 -0
  39. package/assets/esri/core/workers/chunks/5d781c2c6204cffffd0d.js +1 -0
  40. package/assets/esri/core/workers/chunks/61d36730564c5ac5edab.js +1 -0
  41. package/assets/esri/core/workers/chunks/6604272ef6fe85279032.js +1 -0
  42. package/assets/esri/core/workers/chunks/{90c1d10eae7ae71889b0.js → 7400b8c454b47ee4fb3c.js} +1 -1
  43. package/assets/esri/core/workers/chunks/796c6195b6bf59dcc9bd.js +1 -0
  44. package/assets/esri/core/workers/chunks/7b45ac83e279fe9516a5.js +1 -0
  45. package/assets/esri/core/workers/chunks/{2de077c7b971f2c215a6.js → 7ddbde8fdd1cf3c53f50.js} +1 -1
  46. package/assets/esri/core/workers/chunks/804606b194dc9e71d088.js +1 -0
  47. package/assets/esri/core/workers/chunks/8102f0bf5707c3be3310.js +1 -0
  48. package/assets/esri/core/workers/chunks/{676c8c0329d68f9f3ac4.js → 81bcc495e6eaf2cf7474.js} +1 -1
  49. package/assets/esri/core/workers/chunks/{d1d6154b4af1c9cc497b.js → 934e1f2153e6fad6ed23.js} +1 -1
  50. package/assets/esri/core/workers/chunks/{e096c1d9d53af74d3207.js → 990e96139b5a1dccb061.js} +1 -1
  51. package/assets/esri/core/workers/chunks/{f28b63c1179366dac8a2.js → 9e2c30b67bab5795306e.js} +1 -1
  52. package/assets/esri/core/workers/chunks/{9184c947cdefe06bf551.js → a18c3cbe505a19d29569.js} +1 -1
  53. package/assets/esri/core/workers/chunks/aa6ee2aa4ff6e6d41efb.js +1 -0
  54. package/assets/esri/core/workers/chunks/{3fd5c3cd8457ddc68798.js → aa779896fd9e5c341349.js} +1 -1
  55. package/assets/esri/core/workers/chunks/ac10c7d2c4829a150037.js +1 -0
  56. package/assets/esri/core/workers/chunks/{e0a7a75709121a26f255.js → afc8a9847f31bb66b13b.js} +1 -1
  57. package/assets/esri/core/workers/chunks/c7adb7b77721c75891f4.js +1 -0
  58. package/assets/esri/core/workers/chunks/{bead830a677690eeb6fb.js → ce8ef2eec290e1df6b2a.js} +1 -1
  59. package/assets/esri/core/workers/chunks/d3369ffed19f4c264dcd.js +1 -0
  60. package/assets/esri/core/workers/chunks/d3412518a7b518860fbb.js +1 -0
  61. package/assets/esri/core/workers/chunks/{3048e74e6246324ce6fc.js → d5916500514a41a4758f.js} +1 -1
  62. package/assets/esri/core/workers/chunks/{c034c30e577d620b8e28.js → dac69c0047488fdf986d.js} +1 -1
  63. package/assets/esri/core/workers/chunks/dcc782e4bf9e8a8202f9.js +1 -0
  64. package/assets/esri/core/workers/chunks/dcdf837a452dc0cac582.js +1 -0
  65. package/assets/esri/core/workers/chunks/{19a4fa965b70fc6f78f6.js → e209cb1f3f14bf576ebe.js} +1 -1
  66. package/assets/esri/core/workers/chunks/e67ea2f1714e5abeae44.js +1 -0
  67. package/assets/esri/core/workers/chunks/e8fb2ba7b7a4f0916325.js +1 -0
  68. package/assets/esri/core/workers/chunks/efcd38aad9aa667001b2.js +1 -0
  69. package/assets/esri/core/workers/chunks/{3aafdb905c697bc9b1ad.js → f372f4eb5527238c46f5.js} +1 -1
  70. package/assets/esri/core/workers/chunks/f497968055af459c5da4.js +1 -0
  71. package/assets/esri/core/workers/chunks/f7123ba1286f64e13e91.js +1 -0
  72. package/assets/esri/core/workers/chunks/fcb4707c2e95099b9f30.js +1 -0
  73. package/assets/esri/libs/lyr3d/lyr3DMain.wasm +0 -0
  74. package/assets/esri/libs/lyr3d/lyr3DWorker.wasm +0 -0
  75. package/chunks/BlurEmission.glsl.js +9 -4
  76. package/chunks/Terrain.glsl.js +9 -9
  77. package/chunks/libtess-f32.js +1 -1
  78. package/chunks/libtess-f64.js +1 -1
  79. package/chunks/lyr3DMain.js +1 -1
  80. package/chunks/lyr3DWorker.js +2 -2
  81. package/config.d.ts +3 -3
  82. package/config.js +1 -1
  83. package/core/mathUtils.js +1 -1
  84. package/form/FormTemplate.d.ts +1 -1
  85. package/geometry/libtess.js +1 -1
  86. package/geometry/projection/projectors.js +1 -1
  87. package/identity/Credential.d.ts +1 -1
  88. package/identity/IdentityManager.d.ts +1 -1
  89. package/identity/OAuthInfo.d.ts +1 -1
  90. package/identity/ServerInfo.d.ts +1 -1
  91. package/kernel.js +1 -1
  92. package/layers/CSVLayer.js +1 -1
  93. package/layers/GaussianSplatLayer.js +1 -1
  94. package/layers/IntegratedMesh3DTilesLayer.js +1 -1
  95. package/layers/Lyr3DWasmPerSceneView.js +1 -1
  96. package/layers/VectorTileLayer.d.ts +2 -2
  97. package/layers/VideoLayer.js +1 -1
  98. package/layers/graphics/controllers/I3SOnDemandController.js +1 -1
  99. package/layers/graphics/sources/CSVSource.js +1 -1
  100. package/layers/graphics/sources/GeoJSONSource.js +1 -1
  101. package/layers/graphics/sources/MemorySource.js +2 -2
  102. package/layers/graphics/sources/support/ParquetSourceWorker.js +1 -1
  103. package/layers/graphics/sources/support/QueryTask.js +1 -1
  104. package/layers/graphics/sources/support/timeQueryUtils.js +2 -0
  105. package/layers/mixins/APIKeyMixin.d.ts +1 -1
  106. package/layers/ogc/types.d.ts +1 -1
  107. package/layers/support/TelemetryData.d.ts +28 -4
  108. package/layers/support/TimeInformation.js +1 -1
  109. package/layers/support/tiles3DUtils.js +1 -1
  110. package/layers/support/timeInfoUtils.js +2 -0
  111. package/layers/video/videoUtils.js +1 -1
  112. package/package.json +2 -2
  113. package/rest/query/executeAttributeBinsQuery.js +1 -1
  114. package/rest/query/executeForExtent.js +1 -1
  115. package/rest/query/executeForTopCount.js +1 -1
  116. package/rest/query/executeForTopExtents.js +1 -1
  117. package/rest/query/executeForTopIds.js +1 -1
  118. package/rest/query/executeTopFeaturesQuery.js +1 -1
  119. package/rest/query/operations/query.js +1 -1
  120. package/rest/query/operations/queryAttributeBins.js +1 -1
  121. package/rest/query/operations/queryTopFeatures.js +1 -1
  122. package/rest/support/timeUtils.js +1 -1
  123. package/views/2d/engine/webgl/FeatureDisplayList.js +1 -1
  124. package/views/2d/engine/webgl/GlyphMosaic.js +1 -1
  125. package/views/2d/engine/webgl/GlyphWorker.js +1 -1
  126. package/views/2d/engine/webgl/TextureManager.js +1 -1
  127. package/views/2d/engine/webgl/materialKeyUtils.js +2 -0
  128. package/views/2d/engine/webgl/mesh/MeshData.js +1 -1
  129. package/views/2d/engine/webgl/mesh/templates/shapingUtils.js +1 -1
  130. package/views/2d/engine/webgl/shaderGraph/techniques/animated/AnimatedMarkerMeshWriter.js +1 -1
  131. package/views/2d/engine/webgl/shaderGraph/techniques/animated/AnimatedPolyMeshWriters.js +1 -1
  132. package/views/2d/engine/webgl/shaderGraph/techniques/fill/ComplexOutlineFillMeshWriter.js +1 -1
  133. package/views/2d/engine/webgl/shaderGraph/techniques/fill/GradientFillMeshWriter.js +1 -1
  134. package/views/2d/engine/webgl/shaderGraph/techniques/fill/PatternFillMeshWriter.js +1 -1
  135. package/views/2d/engine/webgl/shaderGraph/techniques/fill/PatternOutlineFillMeshWriter.js +1 -1
  136. package/views/2d/engine/webgl/shaderGraph/techniques/labels/LabelMeshWriter.js +1 -1
  137. package/views/2d/engine/webgl/shaderGraph/techniques/line/GradientStrokeMeshWriter.js +1 -1
  138. package/views/2d/engine/webgl/shaderGraph/techniques/line/TexturedLineMeshWriter.js +1 -1
  139. package/views/2d/engine/webgl/shaderGraph/techniques/markers/MarkerMeshWriter.js +1 -1
  140. package/views/2d/engine/webgl/shaderGraph/techniques/text/TextMeshWriter.js +1 -1
  141. package/views/2d/layers/VideoLayerView2D.js +1 -1
  142. package/views/3d/analysis/ShadowCast/ShadowCastError.d.ts +40 -0
  143. package/views/3d/analysis/ShadowCast/ShadowCastError.js +2 -0
  144. package/views/3d/analysis/ShadowCast/sunlightUtils.js +2 -0
  145. package/views/3d/analysis/ShadowCastAnalysisView3D.d.ts +16 -1
  146. package/views/3d/analysis/ShadowCastAnalysisView3D.js +1 -1
  147. package/views/3d/camera/constraintUtils/surfaceCollision.js +1 -1
  148. package/views/3d/camera/intersectionUtils.js +1 -1
  149. package/views/3d/layers/GaussianSplatLayerView3D.js +1 -1
  150. package/views/3d/layers/IntegratedMesh3DTilesLayerView3D.js +1 -1
  151. package/views/3d/layers/Lyr3DWorker.js +1 -1
  152. package/views/3d/layers/i3s/I3SIndex.js +1 -1
  153. package/views/3d/layers/i3s/I3SViewportQueries.js +1 -1
  154. package/views/3d/layers/support/FeatureMemory.js +1 -1
  155. package/views/3d/layers/support/FeatureTile.js +1 -1
  156. package/views/3d/navigation/modes/GroundNavigationMode3D.js +1 -1
  157. package/views/3d/state/Constraints.js +1 -1
  158. package/views/3d/state/NearFarHeuristic.js +1 -1
  159. package/views/3d/state/utils/groundNavigationUtils.js +1 -1
  160. package/views/3d/support/orientedBoundingBox.js +1 -1
  161. package/views/3d/support/sphereExtentUtils.js +1 -1
  162. package/views/3d/terrain/TerrainSurface.js +1 -1
  163. package/views/3d/terrain/TileRenderer.js +1 -1
  164. package/views/3d/terrain/tileUtils.js +1 -1
  165. package/views/3d/webgl-engine/lib/TextTextureAtlas.js +1 -1
  166. package/views/3d/webgl-engine/lib/lodRendering/LodRenderer.js +1 -1
  167. package/views/3d/webgl.d.ts +1 -1
  168. package/views/support/Scheduler.js +1 -1
  169. package/widgets/Directions.d.ts +1 -1
  170. package/assets/esri/core/workers/chunks/0f6c0d42100c21367e5c.js +0 -1
  171. package/assets/esri/core/workers/chunks/176d0a06ebff5a29dedf.js +0 -1
  172. package/assets/esri/core/workers/chunks/18776a130d96879a68b1.js +0 -1
  173. package/assets/esri/core/workers/chunks/20a698709c3c11ff2c16.js +0 -1
  174. package/assets/esri/core/workers/chunks/24ada9511b074dc5ae27.js +0 -1
  175. package/assets/esri/core/workers/chunks/277263466837e1673f56.js +0 -1
  176. package/assets/esri/core/workers/chunks/2c8ca43563c4f3e94535.js +0 -1
  177. package/assets/esri/core/workers/chunks/379ef56f6b32494832a6.js +0 -1
  178. package/assets/esri/core/workers/chunks/38d852676677e5697864.js +0 -1
  179. package/assets/esri/core/workers/chunks/38df7b1d58c4bcf693d0.js +0 -1
  180. package/assets/esri/core/workers/chunks/507ecc3692e6d0700958.js +0 -1
  181. package/assets/esri/core/workers/chunks/5a9b7eb26f936f03d02e.js +0 -1
  182. package/assets/esri/core/workers/chunks/5f07f52bb8b7721f08d3.js +0 -1
  183. package/assets/esri/core/workers/chunks/661847f1b7044f21600f.js +0 -1
  184. package/assets/esri/core/workers/chunks/6b5c073dddd89d06ed80.js +0 -1
  185. package/assets/esri/core/workers/chunks/6ddc29a144640acb1192.js +0 -1
  186. package/assets/esri/core/workers/chunks/6ebe73f69ae822053b70.js +0 -1
  187. package/assets/esri/core/workers/chunks/6f6d1873753a9c6994aa.js +0 -1
  188. package/assets/esri/core/workers/chunks/7582654a0fc70910731c.js +0 -1
  189. package/assets/esri/core/workers/chunks/7e211d8a8ad6c6a7cf3e.js +0 -1
  190. package/assets/esri/core/workers/chunks/849f446c718e892f39ce.js +0 -1
  191. package/assets/esri/core/workers/chunks/8517d96fc8ba7b21d845.js +0 -2
  192. package/assets/esri/core/workers/chunks/a107f16cd004626b5018.js +0 -1
  193. package/assets/esri/core/workers/chunks/a65951f1d5702cfd996e.js +0 -1
  194. package/assets/esri/core/workers/chunks/bf62be00f3040f91aaee.js +0 -1
  195. package/assets/esri/core/workers/chunks/c570b90995c65bbb2e14.js +0 -1
  196. package/assets/esri/core/workers/chunks/c576bef77e34920af188.js +0 -1
  197. package/assets/esri/core/workers/chunks/caad4f475d6eb01c2850.js +0 -1
  198. package/assets/esri/core/workers/chunks/cf1ec61eb2ad147bb931.js +0 -1
  199. package/assets/esri/core/workers/chunks/daae21cf77864f3293ef.js +0 -1
  200. package/assets/esri/core/workers/chunks/dc2f93453dfa40f623ab.js +0 -1
  201. package/assets/esri/core/workers/chunks/e81173724e8de8c1e65b.js +0 -1
  202. package/assets/esri/core/workers/chunks/e83f9abee611c5b80009.js +0 -1
  203. package/assets/esri/core/workers/chunks/ec8b7476eac4718eb0ac.js +0 -1
  204. package/assets/esri/core/workers/chunks/f45064066e1ab041a0b2.js +0 -1
  205. package/assets/esri/core/workers/chunks/ffe49d9e7df081bef4a5.js +0 -1
  206. package/views/2d/engine/webgl/hashMosaic.js +0 -2
  207. /package/assets/esri/core/workers/chunks/{8517d96fc8ba7b21d845.js.LICENSE.txt → 1ae0c9345626e70affd3.js.LICENSE.txt} +0 -0
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../../Color.js";import{filterInPlace as n,difference as r}from"../../../core/arrayUtils.js";import i from"../../../core/CollectionFlattener.js";import{toConst as a}from"../../../core/compilerUtils.js";import{EventedAccessor as o}from"../../../core/Evented.js";import has from"../../../core/has.js";import s from"../../../core/Logger.js";import{clamp as c}from"../../../core/mathUtils.js";import{removeMaybe as l,destroyMaybe as u}from"../../../core/maybe.js";import{MemCachePool as ee}from"../../../core/MemCachePool.js";import d from"../../../core/ObjectPool.js";import f from"../../../core/PooledArray.js";import{throwIfAborted as te,isAbortError as p,isAborted as m}from"../../../core/promiseUtils.js";import{watch as h,syncAndInitial as g,initial as _,sync as v}from"../../../core/reactiveUtils.js";import"../../../core/scheduling.js";import{getMetersPerUnitForSR as ne}from"../../../core/units.js";import{property as y,subclass as re}from"../../../core/accessorSupport/decorators.js";import{exactEquals as ie,set as ae,copy as oe}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as b}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as se}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as ce,radiusModifier as le}from"../../../geometry/ellipsoidUtils.js";import{projectWithoutEngine as ue}from"../../../geometry/projectionUtils.js";import x from"../../../geometry/SpatialReference.js";import{getProjector as de}from"../../../geometry/projection/projectors.js";import{projectPointToVector as S}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as fe}from"../../../geometry/projection/projectVectorToVector.js";import{create as C,fromExtent as pe,equals as w,intersection as me,intersectsSphere as T}from"../../../geometry/support/aaBoundingRect.js";import{copy as he,create as ge}from"../../../geometry/support/frustumPlanes.js";import{createSpatialReferenceCyclical as _e}from"../../../geometry/support/normalizeUtils.js";import{isPlateCarree as ve}from"../../../geometry/support/spatialReferenceUtils.js";import{Sphere as ye}from"../../../geometry/support/sphere.js";import{ElevationQueryTileCache as be}from"../../../layers/support/ElevationQueryTileCache.js";import{isIntegratedMeshLayer as xe,isBaseLayer as Se}from"../../../layers/support/layerUtils.js";import{queueHighPriority as Ce}from"../../../request/queue.js";import{debugFlags as E}from"../support/debugFlags.js";import{ElevationRange as D}from"../support/ElevationRange.js";import{ElevationUpdateEvent as we}from"../support/ElevationUpdateEvent.js";import{calculateElevationUpdateExtents as Te}from"../support/elevationUpdateExtentUtils.js";import{toBoundingRect as Ee}from"../support/extentUtils.js";import{updatingProgress as De}from"../support/updatingProperties.js";import{ElevationBounds as O}from"./ElevationBounds.js";import{ElevationData as Oe,sampleElevation as ke}from"./ElevationData.js";import{create as Ae}from"./ExtentHelper.js";import{LayerClasses as je}from"./LayerClass.js";import{OverlayManager as Me}from"./OverlayManager.js";import{PlanarPatch as Ne}from"./PlanarPatch.js";import{Queue as Pe}from"./Queue.js";import{ScaleRangeQueries as Fe}from"./ScaleRangeQueries.js";import{SphericalPatch as Ie}from"./SphericalPatch.js";import{SplitLimits as Le}from"./SplitLimits.js";import{maxRootTiles as k,tooManyRootTilesAfterChangeError as Re,tooManyRootTilesForLayerError as ze,maxTileNeighborLevelDelta as A,maxMemoryLodBias as Be}from"./TerrainConst.js";import{TerrainRenderer as Ve}from"./TerrainRenderer.js";import He from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as j,isVectorTileLayerView as M,internalAssert as N,oppositeEdge as Ue,neighborEdgeIndices as P,isSurfaceLayerView as F,isGroupLayerView as I,isMapTileLayerView as L,isBlendableLayerView as R,isElevationLayerView as z,releaseTerrainData as B,oppositeCorner as We,enableTerrainInternalChecks as V,enableWaterproofTests as Ge,enableInternalTerrainChecks as Ke,enableTerrainWaterproofChecks as qe,neighborCornerIndices as Je}from"./terrainUtils.js";import{Tile as Ye,lijEquals as H}from"./Tile.js";import{printAllocations as Xe}from"./TilePerLayerInfo.js";import{sortTiles as Ze,IteratorPreorder as Qe,IteratorPostorder as $e,compareTilesByLij as U,hasLoadableSiblings as et,sortTilesByPOI as tt,traverseTilesPreorder as W}from"./tileUtils.js";import{TilingSchemeLogic as nt}from"./TilingSchemeLogic.js";import{getGroundTransparencyModeFromOpacity as rt}from"./TransparencyMode.js";import{UpsampleInfo as it}from"./UpsampleInfo.js";import{isCompositeBlendMode as at,blendModeFromString as ot}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{hasLayerBasedScaleVisibility as st}from"../../support/layerViewUtils.js";import{ImmediateTask as G,TaskPriority as ct,noBudget as lt}from"../../support/Scheduler.js";import{TextureCompressionTracker as ut}from"../../support/TextureCompressionTracker.js";import{Yield as dt}from"../../support/Yield.js";var K;let q=class extends o{static{K=this}get allTilesCreated(){return this._allTilesCreated}get allTiles(){return a(this._allTiles)}get renderedTiles(){return Ze(n(this._allTiles.toArray(),e=>e.visible&&e.rendered))}get demResolution(){let{_allTiles:e,tilingScheme:t}=this;if(e.length===0)return{min:1,max:1};let n=ne(t.spatialReference),r=1/0,i=-1/0;for(let a of e){let e=t.resolutionAtLevel(a.level)*n;r=Math.min(r,e),i=Math.max(i,e)}return{min:r,max:i}}constructor(e){super(e),this.terrainTextureCompressionTracker=new ut,this._iteratorPool=new d(()=>new Qe,e=>e.remove=()=>this._iteratorPool.release(e)),this._postorderIterator=new $e,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._allTilesCreated=!1,this._usedMemory=null,this._performanceInfo=new He,this._waterproofnessErrorHandle=null,this._viewChanged=!1,this.heading=0,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=b(),this._eyePosSurfaceSR=b(),this._splitLimits=new Le,this._layerViews=[[],[]],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._updatingHandles=new se,this._poiWatchHandle=null,this._frameTask=G,this._allTiles=new f,this._upsampleInfoPool=new d(()=>new it),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=C(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=x.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationRange=new D(1/0,-1/0),this._rootTileElevationRange=new D(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._layerViewsDirty=!1,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._isWebMercator=!1,this._isWebMercatorOnPlateCarree=!1,this.enabled=!0;let{view:t}=e;this.overlayManager=new Me({...e,terrainSurface:this}),this._isGlobal=!t.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?Ie:Ne,this._ellipsoid=ce(t.spatialReference),this._renderer=new Ve(this,this.overlayManager.renderer,this._allTiles,this.terrainTextureCompressionTracker,t.resourceController.memoryController),st()||(this._scaleRangeQueries=new Fe)}initialize(){let{view:e}=this,{resourceController:t}=e,{memoryController:n}=t;e.stage.addRenderPlugin(this._renderer),this._tileCache=new ee((e,t)=>n.newCache(e,t),`terrain-tile`),this._upsampleMapCache=n.newCache(`terrain-upsample`,({tile:e})=>e.unloadMapData()),this._elevationQueryCache=new be(n.newCache(`elevation-query`));let r=this.overlayManager;this.addHandles([h(()=>r.renderer.isEmpty,()=>this._evaluateTransparency()),h(()=>this.renderer.visible,e=>this.freeze=!e),h(()=>this.heading,e=>{this._renderer.updateHeading(e),this._updateTileTextures(0)},g)],`overlayManager`),this._updatingHandles.add(()=>({heading:e.camera?.heading,state:e.state?.mode}),({heading:e,state:t})=>{if(e==null)return;if(this.isGlobal&&this.isGeographic||this.isWebMercatorOnPlateCarree){this.heading=Math.round(e/90)*90%360;return}let n=Math.round(e)%360,r=Math.abs(n-this.heading);(t===2||Math.min(r,360-r)>=30)&&(this.heading=n)},_),this.addHandles([h(()=>this.baseOpacity,()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?1:2)},g),h(()=>this.hasCompositeBlendMode,()=>this._updateTileTextures(this._evaluateTransparency()?1:2),g),h(()=>this.backgroundColor,(e,t)=>{e?.equals(t)||(this._handleLayerViewChanges(),this._renderer.updateTileBackground(e))},v),h(()=>this.snapLevel,()=>this._viewChanged=!0,v),h(()=>this.view.pointsOfInterest,e=>{this._renderer.pointsOfInterest=e,this._poiWatchHandle=l(this._poiWatchHandle),e&&(this._poiWatchHandle=this._updatingHandles.add(()=>e.focus?.renderLocation,()=>this._allTilesSorted=!1,{equals:ie}))}),h(()=>E.TERRAIN_TILE_TREE_SHOW_TILES,t=>{t&&!this._treeDebugger?import(`../layers/support/TerrainTileTree3DDebugger.js`).then(({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&E.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))}):t||(this._treeDebugger=u(this._treeDebugger))},_)]);let{spatialReference:a}=e;this._extentHelper=Ae(this.viewingMode,{layers:e.map.allLayers,layerViews:e.allLayerViews,viewSpatialReference:a});let o=new i({getCollections:()=>e.defaultsFromMap?.mapCollections?.map(({layers:e})=>e),getChildrenFunction:e=>e&&`layers`in e?e.layers:null}),s=new nt({layers:o,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set(`tilingSchemeLogic`,s),this._updateTilingScheme();let c=t.scheduler;this._frameTask=c.registerTask(ct.TERRAIN_SURFACE,this),this.addHandles([h(()=>this._stencilEnabledExtents,e=>this._renderer.setStencilEnabledLayerExtents(e),_),h(()=>this.tilingSchemeLogic.tilingScheme,()=>this._updateTilingScheme(),v),h(()=>this.groundExtent,()=>this._updateRootTiles(),_),e.on(`resize`,()=>this._viewChangeUpdate()),h(()=>{let t=e.state;return[this._lodBias,this.lodSnappingEnabled,e.quality,t.camera,t.contentCamera,t.fixedContentCamera]},()=>this._viewChangeUpdate(),g),h(()=>e.qualitySettings?.fadeDuration,e=>this._renderer.textureFadingEnabled=e>0,_),h(()=>e.qualitySettings?.physicallyBasedRenderingEnabled,e=>this._renderer.pbrMode=e?5:0,_),h(()=>e.qualitySettings?.tiledSurface.elevationLevelDelta,()=>{this._allTiles.forAll(e=>this.updateElevationSources(e)),this._updateAllTileGeometries()}),h(()=>this.userClippingExtent,()=>this._updateClippingExtent(),v)]),this.addHandles(e.allLayerViews.on(`after-changes`,()=>this._layerViewsDirty=!0)),this._layerViewsDirty=!0,this._handleLayerViewChanges(),this._renderer.updateTileBackground(this.backgroundColor)}clearHandles(){this._updatingHandles?.removeAll(),this.removeAllHandles(),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear()}destroy(){this._waterproofnessErrorHandle?.remove(),this._waterproofnessErrorHandle=null,this._frameTask.remove(),this._frameTask=G,this._updatingHandles?.destroy(),this._removeAllTiles(),this._set(`tilingSchemeLogic`,u(this.tilingSchemeLogic)),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear(),this._set(`overlayManager`,u(this.overlayManager)),this._tileCache=u(this._tileCache),this._allTiles.prune(),Ye.prune(),this._treeDebugger=u(this._treeDebugger),this._renderer.destroyed||(this.view.stage.removeRenderPlugin(this._renderer),this._renderer.destroy()),this._renderer=null,this._iteratorPool=u(this._iteratorPool),this._upsampleMapCache=u(this._upsampleMapCache),this._elevationQueryCache=u(this._elevationQueryCache),this._set(`view`,null),this._extentHelper=u(this._extentHelper),this._upsampleInfoPool=u(this._upsampleInfoPool),Xe(),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._stencilEnabledExtents?.length}get _stencilEnabledExtents(){let e=this.spatialReference,t=!!has(`enable-feature:im-as-ground`);return e==null?null:Iterator.from(this.view.allLayerViews).map(n=>{let{layer:r}=n;if(!xe(r)||t&&!r.isUsedAsGroundLayer)return null;let{fullExtent:i}=r,a=i==null||i.spatialReference.equals(e)?i:ue(i,i.spatialReference,e);return a?pe(a):null}).filter(e=>e!=null).toArray()}get userClippingExtent(){let{spatialReference:e}=this,t=this.view?.clippingArea;if(t==null||e==null)return null;let n=C(),r=Ee(t,n,e)?n:null,i=this._get(`userClippingExtent`);return w(r,i)?i:r}get rootTilesExtent(){return this._rootTilesExtent}get groundExtent(){let e=me(this.fullGroundExtent,this.userClippingExtent,C()),t=this._get(`groundExtent`);return w(e,t)?t:e}get fullGroundExtent(){return this._tilingSchemeExtent==null?this._rootTilesExtent:this._tilingSchemeExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),this.enabled&&!!((this.readyToRun||this._updatingHandles?.updating||this._asyncWorkItems>0)&&this.ready&&!this.freeze||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.freeze}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||this._rootTiles!=null}get rootTiles(){return this._rootTiles}get spatialReference(){return this.tilingScheme?.spatialReference??null}get backgroundColor(){return this.view?.map?.ground?.surfaceColor}set backgroundColor(e){this.view.map.ground.surfaceColor=e}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set(`slicePlaneEnabled`,e),this._evaluateTransparency()}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}get wireframe(){return this._renderer?.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}get opaque(){return this._renderer.transparency===0}get invisible(){return this._renderer.transparency===3}set freeze(e){this._set(`freeze`,e),this._viewChangeUpdate()}get fadeDuration(){return this.view.qualitySettings.fadeDuration??0}intersect(e,t,n,r){this._renderer.intersectRay(e,t,n,r)}getElevationLevelDelta(e){return e<4?3:this.view.qualitySettings.tiledSurface.elevationLevelDelta}get _xNormalizer(){return _e(this._spatialReference)}getElevation(e,t,n,r){let i=this._rootTiles;if(!i?.length||!this.enabled||i[0].layerInfo[0].length===0)return null;let a=this._elevationProjectorCache.get(r);if(a===void 0&&(a=de(r,this._spatialReference)??null,this._elevationProjectorCache.set(r,a)),a==null)return s.getLogger(this).error(`TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system`),null;let o=ae(J,e,t,n);a(o,0,o,0);let c=this._xNormalizer?.normalize(o[0])??o[0],l=o[1];return ht(i,c,l)}getElevations(e,t,n){let r=this._rootTiles,i=r?r[0].layerInfo[0].length:0;if(!r?.length||i===0||!this.enabled)for(let e=0;e<t;++e)n(e,null);else for(let i=0;i<t;++i){let t=i*3,a=e[t],o=e[t+1],s=ht(r,a,o);n(i,s)}}getLayerIndexByUID(e,t){return this._layerIndexByUid[e].get(t)}getScale(e){if(!this.tilingScheme)return null;if(!S(e,J,this.spatialReference))return s.getLogger(this).error(`TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system`),null;let t=this._rootTiles;if(t!=null){for(let e of t)if(e?.containsPoint(J)){let t=e;for(;t.children[0]&&!t.rendered;){let e=t.children[0].extent,n=0;J[0]>e[2]&&(n+=1),J[1]<e[1]&&(n+=2),t=t.children[n]}return this._getLodBiasCorrectedScale(t.level)}}return 1/0}_ensureProjector(e){let t=this._projectorCache.get(e);if(t)return t;let n=de(e,this._tilingSchemeSpatialReference)??null;return this._projectorCache.set(e,n),n}getSphereElevationRange(e,t){if(!this.enabled||this._rootTiles==null)return null;let n=this._ensureProjector(t);if(n==null)return s.getLogger(this).error(`TerrainSurface.getSphereElevationRange(): could not project given point to tiling scheme coordinate system`),null;Y.copyFrom(e),n(Y.center,0,Y.center,0);let r=new D,i=this._rootTiles;if(i!=null){let e=[];for(let t of i)e.push(t);let t=0;for(;t<e.length;){let n=e[t];if(++t,!T(n.extent,Y))continue;let i=n.children;if(i[0]==null||n.rendered)r.expandElevationRangeValues(n.elevationBoundsMin,n.elevationBoundsMax);else for(let t of i)e.push(t)}}return r}getRootElevationRange(){return this.enabled&&this._rootTiles!=null?new D(this._rootTileElevationRange.minElevation,this._rootTileElevationRange.maxElevation):null}getLowerBoundRadius(){let e=(this._ellipsoid.radius+this.visibleElevationRange.minElevation)*le;return Math.min(e,this._ellipsoid.radius)}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!S(e,Y.center,this.spatialReference))return s.getLogger(this).error(`TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system`),null;Y.radius=t;let n=null,r=e=>{if(e&&T(e.extent,Y)){let t=e.children;if(t[0]&&!e.rendered)for(let e of t)r(e);else{let t=this._getLodBiasCorrectedScale(e.level);n=n==null?t:Math.min(n,t)}}},i=this._rootTiles;if(i!=null)for(let e of i)r(e);return n}queryVisibleScaleRange(e,t,n,r){if(!this._scaleRangeQueries)return;let i=t?this.tilingScheme.levelAtScale(t):0,a=n?this.tilingScheme.levelAtScale(n):1/0,o=this._lodBias;this._scaleRangeQueries.queryVisibleLevelRange(e,i+o,a+o,r)}_evaluateTransparency(){let e=this.baseOpacity,t=this.overlayManager.renderer.isEmpty,n=this._renderer.transparency,r=this._isFullyTransparent?rt(0,t):e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?0:1;return this._renderer.transparency=r,n!==r&&(this.notifyChange(`opaque`),this.notifyChange(`invisible`),!0)}_updateTilingScheme(){let{tilingScheme:e}=this.tilingSchemeLogic;if(e===this.tilingScheme)return;j(!!e,`tiling scheme cannot be reset to undefined`),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();let t=e?.spatialReference??x.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateCarree=this._isWebMercator&&ve(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,n,r){let i=this._tileCache.pop(K._tileMemcacheKey);return i?(i.init(e,t,n,r,this),i):new this._tileConstructor(e,t,n,r,this)}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){let{groundExtent:e,tilingScheme:t}=this;if(!t)return;if(!this.enabled){this._setRootTiles(null);return}let n=pt,i=t.rootTilesInExtent(e,n,k*5);if(this._rootTiles!=null){if(i.length>k){s.getLogger(this).warn(Re);return}let e=this._rootTiles.map(e=>e.lij),t=r(e,i,H);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){let e=this._rootTiles.filter(e=>t.removed.findIndex(t=>H(t,e.lij))>-1?(this._purgeTile(e),!1):!0);t.added.forEach(t=>e.push(this._newRootTile(t))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,i.length>k&&(s.getLogger(this).warn(ze),i=t.rootTilesInExtent(e,n,k)),this._setRootTiles(i.map(e=>this._newRootTile(e)));w(n,this._rootTilesExtent)||(this._rootTilesExtent=C(n)),this.renderer.visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange(`ready`),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness(`root-tiles-updated`)}_updateAllTileGeometries(){let e=this._allTiles.filter(e=>this._canUpdateTileGeometry(e));e.length===0||(e.sort(U),e.forEach(e=>this._renderer.updateTileGeometryState(e)),e.forEach(e=>e.renderData.updateNeighborData()),this._updateTilesGeometries(e)),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){let t=e.filter(e=>this._canUpdateTileGeometry(e));if(t.length===0)return;let n=this.renderer;for(let e of t)n.updateGeometryIfNeeded(e);for(let e of t)this._pendingTilesForElevationUpdateEvent.add(e)}_canUpdateTileGeometry(e){return e.loaded&&e.intersectsClippingArea&&e.hasGeometryState}_shouldSplit(e){return e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.snapLevel)===1}_newRootTile(e){let 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(),e!=null){let 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.freeze&&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(e==null)return;let t=et(e),n=this.visibleElevationRange,r=t?n.minElevation:1/0,i=t?n.maxElevation:-1/0,a=this.groundExtent,o=this.view.state.contentCamera.viewProjectionMatrix;this.setTileTreeDirty(!1);let s=this._iteratorPool.acquire();for(s.reset(e);!s.done;){let e=s.next();e.updateClippingStatus(a)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e),e.computeVisibility(),e.updateScreenDepth(o),e.renderData&&(r=Math.min(e.elevationBoundsMin,r),i=Math.max(e.elevationBoundsMax,i))}s.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._updatePendingTileGeometries(),isFinite(r)&&isFinite(i)&&(n.minElevation!==r||n.maxElevation!==i)&&(this.visibleElevationRange=new O(r,i))}_updateRootTileElevationRange(){let e=1/0,t=-1/0;this._rootTiles?.forEach(({elevationBoundsMin:n,elevationBoundsMax:r})=>{e=Math.min(e,n),t=Math.max(t,r)});let n=this._rootTileElevationRange;(n.minElevation!==e||n.maxElevation!==t)&&(this._rootTileElevationRange=new O(e,t))}_updateViewDependentParameters(){let{camera:e,contentCamera:t}=this.view.state,n=Math.tan(t.fovX*.5),r=Math.tan(t.fovY*.5),i=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=n,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=i/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=i/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=he(this._splitLimits.frustum??ge(),t.frustum):this._splitLimits.frustum=null,oe(this._eyePosRenderSR,t.eye),fe(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateTileGeometryState(e){e.updateVisibility(),this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this.setMemoryDirty()}_markAllTileNeighborsForUpdate(e){let t;e.forEachLoadedNeighbor(e=>{t??=this._layerViews[1].some(M),t&&e.setPendingUpdate(32),this._pendingTilesToUpdate.add(e)})}_updateTileTexture(e,t){let n=e.resetPendingUpdate(32)?32:e.resetPendingUpdate(16)?16:!1;n&&(this._renderer.updateTileTexture(e,n),this._usedMemory=null,t.madeProgress())}_emitElevationUpdateEventForTiles(){if(!this._shouldEmitChangeEvent)return;let e=this._pendingTilesForElevationUpdateEvent;if(e.size>0){let t=new Float64Array(4*e.size),n=0;for(let r of e)t.set(r.extent,4*n),++n;e.clear();for(let e of Te(t,this.spatialReference)){let t=new we(this.spatialReference,e,`ground`);this.emit(`elevation-change`,t)}}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);let t=!this.view.state.fixedContentCamera;this._mergeAndSplit(e,t),this._updateElevation(e),this._updateTextures(e),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty();let n=this._pendingTilesToUpdate.size>0,r=n&&this._hasPendingGeometryWithoutIndices();if((!e.done||r)&&this._updatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&(e.hasProgressed||n&&!r)&&this.requestUpdate(),this.notifyChange(`updatingProgressValue`),!e.hasProgressed)return dt}_checkTileInvariant(){}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;let t=!1,n=new Pe(this._allTiles.length);n.pushAll(this._rootTiles);let r=this.snapLevel,i=this._splitLimits,a=this._eyePosRenderSR;this._allTiles.forAll(e=>{e.maxLevelDeltaNeighborCount=0,e.unmergableChildCount=0});let o=this.view.state.contentCamera.viewProjectionMatrix;for(;!n.empty;){let e=n.pop(),s=e.parent?.hasPendingUpdate(4),c=e.elevationLevel,l=s?4:e.shouldSplit(i,a,r),u=l===1;e.leaf?Z(e,u):n.pushAll(e.children),s?(e.resetPendingUpdate(1),e.leaf||(e.setPendingUpdate(4),t=!0),this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(o)):(u?(e.resetPendingUpdate(4),e.leaf&&(e.setPendingUpdate(1),t=!0)):(e.resetPendingUpdate(1)&&e.updateAgentSuspension(),l===2&&e.updateAgents(0),e.leaf||(e.setPendingUpdate(4),e.resetPendingUpdate(1),t=!0)),e.elevationLevel!==c&&this.updateElevationSources(e))}this._allTilesDirty=t,this.requestUpdate(),this._shortBatches&&this._updatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){!e.done&&!this._allTilesSorted&&this.view.pointsOfInterest?.focus&&(tt(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger?.update(),e.madeProgress())}_markTileToUpdate(e){N(e.loaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForUpdate(e))}_hasPendingGeometryWithoutIndices(){for(let e of this._pendingTilesToUpdate)if(e.loaded&&e.intersectsClippingArea&&e.renderData?.vao?.indexBuffer==null)return!0;return!1}_updatePendingTileGeometries(){let e=this._pendingTilesToUpdate,t=[];if(e.forEach(e=>{this._canUpdateTileGeometry(e)&&t.push(e)}),t.length===0){e.clear();return}let n=(n,r)=>{!r||!this._canUpdateTileGeometry(r)||r.level<n.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(U);let r=t.length;for(let i=0;i<r;++i){let r=t[i];N(r.loaded),N(r.intersectsClippingArea);let a=r.renderData;if(!a?.geometryState)continue;a.updateNeighborData();let o=a.dirtyEdgeResolutions,s=a.geometryState,c=e=>{let t=Je[e];n(r,s.cornerPeerNeighbors[e]?.findCorner(We(t),e=>e.loaded))};for(let t=0;t<4;++t)if(o&1<<t){let i=a.geometryState.edgePeerNeighbors[t];i&&i?.level>=r.level&&i.forAllSubtreeOnSide(Ue(P[t]),t=>this._canUpdateTileGeometry(t)?(N(e.has(t)||U(r,t)<0),n(r,t),!0):!1),c((t+1)%4),c(t)}}e.clear(),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,V&&Ge&&this.checkAllTilesWaterproofness(`pending-geometries-updated`)}_mergeAndSplit(e,t){if(this.freeze||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let n=!1,r=this.view.state.fixedContentCamera,i=!1;for(;!e.done;){i=!0;let a=!1,o=!this._allTiles.some(i=>{if(!n&&!r&&!i.visible)return e.done;let o=i;if(i.hasPendingUpdate(4)){if(!t||i.unmergableChildCount>0)return e.done;for(i.resetPendingUpdate(4);o.parent!=null&&o.parent.unmergableChildCount===0&&o.parent.resetPendingUpdate(4);)o=o.parent;this._mergeTile(o),a=!0,e.madeProgress()}else if(i.resetPendingUpdate(1)){let t=!0,n=i.level;if(n>=A){let e=e=>e.leaf||n-e.level<A;for(let r=0;r<4;++r){let a=i.findNeighborTile(P[r],e);a!=null&&n-a.level===A&&(t=!1,V&&(N(a.leaf),N(a.hasPendingUpdate(1))))}}t?(this._splitTile(i),e.madeProgress(),a=!0):i.setPendingUpdate(1)}return e.done});if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0),o){if(!n){n=!0;continue}if(!a)break}else this._allTilesDirty=!0}i?e.madeProgress():this._allTilesDirty=!0,this._allTilesCreated=!this.allTiles.some(e=>e.hasPendingUpdate(1)||e.hasPendingUpdate(4)&&e.unmergableChildCount===0),this._sortTiles(e)}_updateElevation(e){e.done||this._allTiles.some(t=>(t.resetPendingUpdate(8)&&(this._updateTileGeometryState(t),e.madeProgress()),e.done))}updateElevationSources(e){e.needsElevationSourceUpdate()&&(e.updateAgents(0),e.markElevationSourceUpdateRequested(),this.requestUpdate())}_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)*Be}_getLodBiasCorrectedScale(e){let t=this.tilingScheme.levels,n=c(e-this._lodBias,0,t.length-1),r=n-Math.floor(n),i=t[Math.floor(n)].scale,a=t[Math.ceil(n)].scale;return i*(1-r)+a*r}_removeAllTiles(){this._pendingTilesToUpdate.clear(),this._pendingTilesForElevationUpdateEvent.clear(),this._rootTiles!=null&&(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){let 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?_t(e):this._purgeSubtree(e),this._allTiles.removeUnordered(e),this._unloadTile(e),e.dispose(),this._tileCache.put(K._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){j(e.leaf,`Tile that is already split should not be split again!`),j(e.rendered,`Tile marked to split is not rendered`),_t(e);let t=e.createChildren();this._allTiles.pushArray(t),this.notifyChange(`demResolution`),this.emit(`tiles-changed`,{allTiles:this.allTiles}),e.updateAgentSuspension(),j(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=>Z(e,e.hasPendingUpdate(1))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){X.spatialReference=this.spatialReference,X.extent=e.extent,X.scale=this._getLodBiasCorrectedScale(t),this.emit(`scale-change`,X)}createTile(e,t,n,r){j(!!r,`createTile sanity check`);let i=this._acquireTile(e,t,n,r);return i.updateClippingStatus(this.groundExtent),i.updateScreenDepth(this.view.state.contentCamera.viewProjectionMatrix),this._shouldSplit(i)&&i.setPendingUpdate(1),i}get _shortBatches(){return this.view.state.mode!==2}_mergeTile(e){j(!e.hasPendingUpdate(1),`_mergeTile sanity check`),j(!e.leaf,`Cannot merge a leaf`),e.leaf||(this._purgeSubtree(e),j(!e.renderData,`Merging tile with existing render data?`),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),Z(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=lt){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1,n=new Set,r=-1;for(let e=this.view.allLayerViews.length-1;e>=0;e--){let i=this.view.allLayerViews.items[e];if(n.add(i.uid),F(i)||I(i)){if(this._basemapLayerViewHandles.has(i.uid)&&!I(i)){let e=this._layerClassFromLayerView(i),n=this.getLayerIndexByUID(e,i.uid);n!=null&&((n<r||r==null)&&(t=!0),r=n)}else this._registerTiledLayerView(i),i.layer.loaded&&(t=!0)}}this._basemapLayerViewHandles.forEach((e,r)=>{n.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(let e of this.view.allLayerViews.items)if(L(e)&&!Se(e.layer)&&e.fullOpacity!==0)return!1;return!0}_hasCompositeBlendMode(){for(let e of this.view.allLayerViews.items)if((R(e)||I(e))&&at(ot[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return+!z(e)}_registerTiledLayerView(e){let t=[];if((R(e)||I(e))&&t.push(h(()=>e.layer.blendMode,()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(2)})),!I(e)){let n=this._layerClassFromLayerView(e);t.push(h(()=>!e.destroyed&&e.suspended,()=>this._updateTiledLayers())),t.push(h(()=>!e.destroyed&&e.fullOpacity,()=>this._updateTileTextures(2)));let{layer:r}=e;`effectiveScaleRange`in r&&t.push(h(()=>!e.destroyed&&r.effectiveScaleRange,()=>this._restartAllAgents(n))),t.push(e.on(`data-changed`,()=>{let t=this.getLayerIndexByUID(n,e.uid);t!=null&&this._invalidateLayerData(t,n)}))}this._unregisterTiledLayerView(e.uid),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){let t=this._basemapLayerViewHandles.get(e);if(t){for(let e of t)e.remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;let e=this.view.allLayerViews,t=[[],[]],n=null;e.forEach(e=>{if(!e.layer||e.suspended||!F(e)||!e.fullExtent)return;let r=this._layerClassFromLayerView(e);if(r===1){let t=e.displayLevelRange.maxLevel;t!==1/0&&(n===null||t>n)&&(n=t)}t[r].push(e)});for(let e of je){let n=this._layerViews[e],r=t[e];r.reverse();let i=r.length,a=n.length!==i,o=Array(i),s=Array(n.length);this._layerIndexByUid[e].clear();for(let t=0;t<i;t++){let i=r[t].uid;this._layerIndexByUid[e].set(i,t);let c=n.indexOf(r[t]);o[t]=c,t!==c&&(a=!0),c>-1&&(s[c]=t)}if(a){let t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;)t.next().modifyLayers(s,o,e);this._layerViews[e]=r,this._restartAllAgents(e),this._updateTilesVisibility(this._rootTiles)}}this.tilingScheme.ensureMaxLod(n)&&(this._viewChangeUpdate(),this.notifyChange(`tilingScheme`))}_restartAllAgents(e){let t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;){let n=t.next();n.restartAgents(e),e===0&&n.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),e===1?this.renderer.updateTileTexture(t,16):t.updateRenderData(1,e)}),this._evaluateTransparency()}_invalidateLayerData(e,t){this._rootTiles!=null&&(W(this._rootTiles,n=>n.removeLayerAgent(e,t)),W(this._rootTiles,n=>{n.invalidateLayerData(e,t),n.restartAgents(t)}))}setTileTreeDirty(e){this._allTilesDirty=!0,e&&(this._allTilesCreated=!1)}requestRender(e=1){this.renderer.requestRender(e)}requestUpdate(){++this._pendingUpdates===1&&(this._hasPendingUpdates=!0)}requestTileData(e,t,n,r){let i=this.layerViewByIndex(t,n),{tilemapCache:a}=i;return!a||M(i)?this._requestTileData(e,n,i,r):(++this._asyncWorkItems,a.fetchAvailability(e.level,e.lij[1],e.lij[2],{...r,timeout:6e3}).catch(t=>{throw te(r),p(t)||this._dataMissing(e,n,i),t}).then(()=>this._frameTask.schedule(()=>this._requestTileData(e,n,i,r),r.signal)).finally(()=>--this._asyncWorkItems))}_requestTileData(e,t,n,r){return this.destroying?Promise.resolve():t===0?z(n)?this._requestElevationTileData(e,n,r):Promise.reject():L(n)?this._requestMapTileData(e,n,r):Promise.reject()}_requestElevationTileData(e,t,n){++this._asyncWorkItems;let r=r=>{!m(n)&&r&&(this.setMemoryDirty(),this.requestUpdate(),this._elevationDataArrived(e,t,r))},i=n=>{p(n)||(s.getLogger(this).error(`Tile ${e.lij.toString()} layer 0/${t.uid} error ${n}`),this._dataMissing(e,0,t),this.requestUpdate())};return t.fetchElevationTile(e,{...Ce,...n}).then(e=>this._frameTask.schedule(()=>r(e)),i).finally(()=>--this._asyncWorkItems)}_elevationDataArrived(e,t,n){let r=this._layerIndexByUid[0].get(t.uid);if(r==null){s.getLogger(this).warn(`TerrainSurface: received data from unknown layer %d %s`,0,e.lij.toString());return}let i=new Oe(e.lij,e.extent,n);e.dataArrived(r,0,i),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:0});let a=[e],o=e.level,c=this._iteratorPool.acquire();for(c.reset(a);!c.done;){let e=c.next();e.findElevationBoundsForLayer(r,o),e.computeElevationBounds()}o===0&&this._updateRootTileElevationRange(),c.remove(),this._updateTilesVisibility(a)}_requestMapTileData(e,t,n){++this._asyncWorkItems;let r=(r,i)=>{B(i),m(n)||(console.error(`Tile ${e.lij.toString()} layer 1/${t.uid} error ${r}`),this._dataMissing(e,1,t),this.requestUpdate())},i=e=>t=>r(t,e);return t.fetchTile(e.lij,n).then(r=>this._frameTask.schedule(()=>{this.requestUpdate(),m(n)?B(r):this._mapTileDataArrived(e,t,r)},n.signal,i(r)).catch(i(r)),(e,t=null)=>this._frameTask.schedule(()=>r(e,t))).finally(()=>--this._asyncWorkItems)}_mapTileDataArrived(e,t,n){let r=this.getLayerIndexByUID(1,t.uid);r==null?(B(n),s.getLogger(this).warn(`TerrainSurface: received data from unknown layer`)):(e.dataArrived(r,1,n),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:1}))}_dataMissing(e,t,n){let r=this.getLayerIndexByUID(t,n.uid);r==null?s.getLogger(this).warn(`TerrainSurface: received data from unknown layer`):(e.dataMissing(r,t),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:t}))}get performanceInfo(){let 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++;let n=t.level;t.renderData&&(e.numLoadedPerLevel[n]=(e.numLoadedPerLevel[n]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[n]=(e.numRenderedPerLevel[n]||0)+1,e.numRendered++))}),e}setMemoryDirty(){this._usedMemory=null}get usedMemory(){return this.tilingScheme?(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,n=this._layerClassFromLayerView(e),r=this.getLayerIndexByUID(n,e.uid);return r!=null&&this._allTiles.forAll(e=>t+=e.getUsedMemoryForLayer(n,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(e=`render-patch-groups`){}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&&e[2]===0}lijEastEnd(e){return 1<<e+ +!!this._isGeographic}wrapEastWest(e){let t=this.lijEastEnd(e[0]),n=e[2];if(0<=n&&n<t)return e;if(!this._isGlobal)return null;let r=(n+(n<0?t:0))%t;return[e[0],e[1],r]}enableInternalChecks(e){Ke(e)}enableWaterproofnessChecks(e){qe(e)}static cleanupTerrainSurface(){mt.prune()}enable(e){e!==this.enabled&&(this._set(`enabled`,e),e?(this._updateRootTiles(),this.freeze=!1,this.view.elevationProvider.register(0,this)):(this.view.elevationProvider.unregister(this),this.freeze=!0,this._removeAllTiles(),this._setRootTiles(null)),this.notifyChange(`ready`))}updateOverlayParameters(){let{overlayManager:e}=this;this.allTiles.forAll(t=>t.updateOverlayParameters(e))}};e([y()],q.prototype,`_renderer`,void 0),e([y({constructOnly:!0})],q.prototype,`_scaleRangeQueries`,void 0),e([y({constructOnly:!0})],q.prototype,`view`,void 0),e([y({constructOnly:!0})],q.prototype,`overlayManager`,void 0),e([y()],q.prototype,`_hasPendingUpdates`,void 0),e([y()],q.prototype,`_asyncWorkItems`,void 0),e([y()],q.prototype,`_allTilesDirty`,void 0),e([y()],q.prototype,`_allTilesSorted`,void 0),e([y()],q.prototype,`allTilesCreated`,null),e([y()],q.prototype,`_allTilesCreated`,void 0),e([y()],q.prototype,`_viewChanged`,void 0),e([y({type:Number})],q.prototype,`heading`,void 0),e([y()],q.prototype,`_splitLimits`,void 0),e([y()],q.prototype,`_frameTask`,void 0),e([y()],q.prototype,`demResolution`,null),e([y({readOnly:!0})],q.prototype,`snapLevel`,null),e([y({readOnly:!0})],q.prototype,`lodSnappingEnabled`,null),e([y()],q.prototype,`_stencilEnabledExtents`,null),e([y({readOnly:!0})],q.prototype,`userClippingExtent`,null),e([y()],q.prototype,`_rootTilesExtent`,void 0),e([y({readOnly:!0})],q.prototype,`groundExtent`,null),e([y({readOnly:!0})],q.prototype,`fullGroundExtent`,null),e([y({readOnly:!0})],q.prototype,`_tilingSchemeExtent`,null),e([y({readOnly:!0})],q.prototype,`updating`,null),e([y({readOnly:!0})],q.prototype,`readyToRun`,null),e([y(De)],q.prototype,`updatingProgress`,void 0),e([y({readOnly:!0})],q.prototype,`updatingProgressValue`,null),e([y()],q.prototype,`_maxNumUpdating`,void 0),e([y()],q.prototype,`baseOpacity`,null),e([y()],q.prototype,`hasCompositeBlendMode`,void 0),e([y({readOnly:!0})],q.prototype,`viewingMode`,null),e([y()],q.prototype,`maxTextureScale`,void 0),e([y({readOnly:!0})],q.prototype,`ready`,null),e([y({readOnly:!0})],q.prototype,`rootTiles`,null),e([y()],q.prototype,`_rootTiles`,void 0),e([y({readOnly:!0})],q.prototype,`spatialReference`,null),e([y({type:t})],q.prototype,`backgroundColor`,null),e([y({value:!1})],q.prototype,`slicePlaneEnabled`,null),e([y({readOnly:!0})],q.prototype,`tilingScheme`,void 0),e([y({readOnly:!0})],q.prototype,`tilingSchemeLocked`,null),e([y({readOnly:!0})],q.prototype,`tilingSchemeLogic`,void 0),e([y()],q.prototype,`wireframe`,null),e([y()],q.prototype,`opaque`,null),e([y()],q.prototype,`invisible`,null),e([y({value:!1})],q.prototype,`freeze`,null),e([y()],q.prototype,`fadeDuration`,null),e([y()],q.prototype,`_xNormalizer`,null),e([y()],q.prototype,`visibleElevationRange`,void 0),e([y()],q.prototype,`_rootTileElevationRange`,void 0),e([y()],q.prototype,`_layerViewsDirty`,void 0),e([y()],q.prototype,`renderPatchBorders`,null),e([y()],q.prototype,`renderingDisabled`,null),e([y({readOnly:!0})],q.prototype,`enabled`,void 0),q=K=e([re(`esri.views.3d.terrain.TerrainSurface`)],q);const ft=q,J=b(),Y=new ye,pt=C(),mt=new f,X={spatialReference:null,extent:null,scale:0};function ht(e,t,n){for(let r of e){if(!r.containsPointXY(t,n))continue;let e=r;for(;e&&!e.renderData;){let r=+(t>e.extentMidX)+(n<e.extentMidY?2:0);e=e.children[r]}let i=e?.renderData?.geometryState.samplerData??null;return ke(t,n,i)}return null}function Z(e,t){!e.leaf||e.level<A||$(e,e=>{t&&gt(e);let n=Q(e);if(e.maxLevelDeltaNeighborCount++,n){let t=e.parent;for(;t;){let e=Q(t);if(t.unmergableChildCount++,e)t=t.parent;else break}}})}function gt(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<A||$(e,e=>{gt(e)})}function _t(e){e.level<A||$(e,e=>{if(e.maxLevelDeltaNeighborCount--,e.maxLevelDeltaNeighborCount===0&&e.unmergableChildCount===0){let t=e.parent;for(;t&&(t.unmergableChildCount--,Q(t));)t=t.parent}})}function Q(e){return e.maxLevelDeltaNeighborCount===0&&e.unmergableChildCount===0}function $(e,t){if(e.level<A)return;let n=e.level-A,r=e.lij[1]>>A,i=e.lij[2]>>A,a=e=>e.leaf||e.level===n;for(let o=0;o<4;++o){let s=e.findNeighborTile(P[o],a);if(!s||s.level!==n)continue;let c=s.lij;(c[1]!==r||c[2]!==i)&&t(s)}}export{ft as default};
2
+ import{__decorate as e}from"tslib";import t from"../../../Color.js";import{filterInPlace as n,difference as r}from"../../../core/arrayUtils.js";import i from"../../../core/CollectionFlattener.js";import{toConst as a}from"../../../core/compilerUtils.js";import{EventedAccessor as o}from"../../../core/Evented.js";import has from"../../../core/has.js";import s from"../../../core/Logger.js";import{clamp as c}from"../../../core/mathUtils.js";import{removeMaybe as l,destroyMaybe as u}from"../../../core/maybe.js";import{MemCachePool as ee}from"../../../core/MemCachePool.js";import d from"../../../core/ObjectPool.js";import f from"../../../core/PooledArray.js";import{throwIfAborted as te,isAbortError as ne,isAborted as p}from"../../../core/promiseUtils.js";import{watch as m,syncAndInitial as h,initial as g,sync as _}from"../../../core/reactiveUtils.js";import"../../../core/scheduling.js";import{getMetersPerUnitForSR as re}from"../../../core/units.js";import{property as v,subclass as ie}from"../../../core/accessorSupport/decorators.js";import{exactEquals as ae,set as oe,copy as se}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as y}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as ce}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as b,radiusModifier as le}from"../../../geometry/ellipsoidUtils.js";import{projectWithoutEngine as ue}from"../../../geometry/projectionUtils.js";import x from"../../../geometry/SpatialReference.js";import{projectBoundingSphere as de}from"../../../geometry/projection/projectBoundingSphere.js";import{getProjector as fe}from"../../../geometry/projection/projectors.js";import{projectPointToVector as pe}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as me}from"../../../geometry/projection/projectVectorToVector.js";import{create as S,fromExtent as he,equals as C,intersection as ge,intersectsSphere as _e}from"../../../geometry/support/aaBoundingRect.js";import{copy as ve,create as ye}from"../../../geometry/support/frustumPlanes.js";import{createSpatialReferenceCyclical as be}from"../../../geometry/support/normalizeUtils.js";import{isGeographic as w,isPlateCarree as xe}from"../../../geometry/support/spatialReferenceUtils.js";import{Sphere as Se}from"../../../geometry/support/sphere.js";import{ElevationQueryTileCache as Ce}from"../../../layers/support/ElevationQueryTileCache.js";import{isIntegratedMeshLayer as we,isBaseLayer as Te}from"../../../layers/support/layerUtils.js";import{queueHighPriority as Ee}from"../../../request/queue.js";import{debugFlags as T}from"../support/debugFlags.js";import{ElevationRange as E}from"../support/ElevationRange.js";import{ElevationUpdateEvent as De}from"../support/ElevationUpdateEvent.js";import{calculateElevationUpdateExtents as Oe}from"../support/elevationUpdateExtentUtils.js";import{toBoundingRect as ke}from"../support/extentUtils.js";import{geographicMbsToGeographicExtent as Ae,mbsToGeographicExtent as je,intersectsGeographicExtent as Me}from"../support/sphereExtentUtils.js";import{isSupportedGCSOnGlobe as D}from"../support/supportedSpatialReference.js";import{updatingProgress as Ne}from"../support/updatingProperties.js";import{ElevationBounds as O}from"./ElevationBounds.js";import{ElevationData as Pe,sampleElevation as Fe}from"./ElevationData.js";import{create as Ie}from"./ExtentHelper.js";import{LayerClasses as Le}from"./LayerClass.js";import{OverlayManager as Re}from"./OverlayManager.js";import{PlanarPatch as ze}from"./PlanarPatch.js";import{Queue as Be}from"./Queue.js";import{ScaleRangeQueries as Ve}from"./ScaleRangeQueries.js";import{SphericalPatch as He}from"./SphericalPatch.js";import{SplitLimits as Ue}from"./SplitLimits.js";import{maxRootTiles as k,tooManyRootTilesAfterChangeError as We,tooManyRootTilesForLayerError as Ge,maxTileNeighborLevelDelta as A,maxMemoryLodBias as Ke}from"./TerrainConst.js";import{TerrainRenderer as qe}from"./TerrainRenderer.js";import Je from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as j,isVectorTileLayerView as M,internalAssert as N,oppositeEdge as Ye,neighborEdgeIndices as P,isSurfaceLayerView as F,isGroupLayerView as I,isMapTileLayerView as L,isBlendableLayerView as R,isElevationLayerView as z,releaseTerrainData as B,oppositeCorner as Xe,enableTerrainInternalChecks as V,enableWaterproofTests as Ze,enableInternalTerrainChecks as Qe,enableTerrainWaterproofChecks as $e,neighborCornerIndices as et}from"./terrainUtils.js";import{Tile as tt,lijEquals as H}from"./Tile.js";import{printAllocations as nt}from"./TilePerLayerInfo.js";import{sortTiles as rt,IteratorPreorder as it,IteratorPostorder as at,compareTilesByLij as U,hasLoadableSiblings as ot,sortTilesByPOI as st,traverseTilesPreorder as W}from"./tileUtils.js";import{TilingSchemeLogic as ct}from"./TilingSchemeLogic.js";import{getGroundTransparencyModeFromOpacity as lt}from"./TransparencyMode.js";import{UpsampleInfo as ut}from"./UpsampleInfo.js";import{isCompositeBlendMode as dt,blendModeFromString as ft}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{hasLayerBasedScaleVisibility as pt}from"../../support/layerViewUtils.js";import{ImmediateTask as G,TaskPriority as mt,noBudget as ht}from"../../support/Scheduler.js";import{TextureCompressionTracker as gt}from"../../support/TextureCompressionTracker.js";import{Yield as _t}from"../../support/Yield.js";var K;let q=class extends o{static{K=this}get allTilesCreated(){return this._allTilesCreated}get allTiles(){return a(this._allTiles)}get renderedTiles(){return rt(n(this._allTiles.toArray(),e=>e.visible&&e.rendered))}get demResolution(){let{_allTiles:e,tilingScheme:t}=this;if(e.length===0)return{min:1,max:1};let n=re(t.spatialReference),r=1/0,i=-1/0;for(let a of e){let e=t.resolutionAtLevel(a.level)*n;r=Math.min(r,e),i=Math.max(i,e)}return{min:r,max:i}}constructor(e){super(e),this.terrainTextureCompressionTracker=new gt,this._iteratorPool=new d(()=>new it,e=>e.remove=()=>this._iteratorPool.release(e)),this._postorderIterator=new at,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._allTilesCreated=!1,this._usedMemory=null,this._performanceInfo=new Je,this._waterproofnessErrorHandle=null,this._viewChanged=!1,this.heading=0,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=y(),this._eyePosSurfaceSR=y(),this._splitLimits=new Ue,this._layerViews=[[],[]],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._updatingHandles=new ce,this._poiWatchHandle=null,this._frameTask=G,this._allTiles=new f,this._upsampleInfoPool=new d(()=>new ut),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=S(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=x.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationRange=new E(1/0,-1/0),this._rootTileElevationRange=new E(1/0,-1/0),this._tilingSchemeSpatialReference=null,this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._layerViewsDirty=!1,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._isWebMercator=!1,this._isWebMercatorOnPlateCarree=!1,this.enabled=!0;let{view:t}=e;this.overlayManager=new Re({...e,terrainSurface:this}),this._isGlobal=!t.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?He:ze,this._ellipsoid=b(t.spatialReference),this._renderer=new qe(this,this.overlayManager.renderer,this._allTiles,this.terrainTextureCompressionTracker,t.resourceController.memoryController),pt()||(this._scaleRangeQueries=new Ve)}initialize(){let{view:e}=this,{resourceController:t}=e,{memoryController:n}=t;e.stage.addRenderPlugin(this._renderer),this._tileCache=new ee((e,t)=>n.newCache(e,t),`terrain-tile`),this._upsampleMapCache=n.newCache(`terrain-upsample`,({tile:e})=>e.unloadMapData()),this._elevationQueryCache=new Ce(n.newCache(`elevation-query`));let r=this.overlayManager;this.addHandles([m(()=>r.renderer.isEmpty,()=>this._evaluateTransparency()),m(()=>this.renderer.visible,e=>this.freeze=!e),m(()=>this.heading,e=>{this._renderer.updateHeading(e),this._updateTileTextures(0)},h)],`overlayManager`),this._updatingHandles.add(()=>({heading:e.camera?.heading,state:e.state?.mode}),({heading:e,state:t})=>{if(e==null)return;if(this.isGlobal&&this.isGeographic||this.isWebMercatorOnPlateCarree){this.heading=Math.round(e/90)*90%360;return}let n=Math.round(e)%360,r=Math.abs(n-this.heading);(t===2||Math.min(r,360-r)>=30)&&(this.heading=n)},g),this.addHandles([m(()=>this.baseOpacity,()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?1:2)},h),m(()=>this.hasCompositeBlendMode,()=>this._updateTileTextures(this._evaluateTransparency()?1:2),h),m(()=>this.backgroundColor,(e,t)=>{e?.equals(t)||(this._handleLayerViewChanges(),this._renderer.updateTileBackground(e))},_),m(()=>this.snapLevel,()=>this._viewChanged=!0,_),m(()=>this.view.pointsOfInterest,e=>{this._renderer.pointsOfInterest=e,this._poiWatchHandle=l(this._poiWatchHandle),e&&(this._poiWatchHandle=this._updatingHandles.add(()=>e.focus?.renderLocation,()=>this._allTilesSorted=!1,{equals:ae}))}),m(()=>T.TERRAIN_TILE_TREE_SHOW_TILES,t=>{t&&!this._treeDebugger?import(`../layers/support/TerrainTileTree3DDebugger.js`).then(({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&T.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))}):t||(this._treeDebugger=u(this._treeDebugger))},g)]);let{spatialReference:a}=e;this._extentHelper=Ie(this.viewingMode,{layers:e.map.allLayers,layerViews:e.allLayerViews,viewSpatialReference:a});let o=new i({getCollections:()=>e.defaultsFromMap?.mapCollections?.map(({layers:e})=>e),getChildrenFunction:e=>e&&`layers`in e?e.layers:null}),s=new ct({layers:o,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set(`tilingSchemeLogic`,s),this._updateTilingScheme();let c=t.scheduler;this._frameTask=c.registerTask(mt.TERRAIN_SURFACE,this),this.addHandles([m(()=>this._stencilEnabledExtents,e=>this._renderer.setStencilEnabledLayerExtents(e),g),m(()=>this.tilingSchemeLogic.tilingScheme,()=>this._updateTilingScheme(),_),m(()=>this.groundExtent,()=>this._updateRootTiles(),g),e.on(`resize`,()=>this._viewChangeUpdate()),m(()=>{let t=e.state;return[this._lodBias,this.lodSnappingEnabled,e.quality,t.camera,t.contentCamera,t.fixedContentCamera]},()=>this._viewChangeUpdate(),h),m(()=>e.qualitySettings?.fadeDuration,e=>this._renderer.textureFadingEnabled=e>0,g),m(()=>e.qualitySettings?.physicallyBasedRenderingEnabled,e=>this._renderer.pbrMode=e?5:0,g),m(()=>e.qualitySettings?.tiledSurface.elevationLevelDelta,()=>{this._allTiles.forAll(e=>this.updateElevationSources(e)),this._updateAllTileGeometries()}),m(()=>this.userClippingExtent,()=>this._updateClippingExtent(),_)]),this.addHandles(e.allLayerViews.on(`after-changes`,()=>this._layerViewsDirty=!0)),this._layerViewsDirty=!0,this._handleLayerViewChanges(),this._renderer.updateTileBackground(this.backgroundColor)}clearHandles(){this._updatingHandles?.removeAll(),this.removeAllHandles(),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear()}destroy(){this._waterproofnessErrorHandle?.remove(),this._waterproofnessErrorHandle=null,this._frameTask.remove(),this._frameTask=G,this._updatingHandles?.destroy(),this._removeAllTiles(),this._set(`tilingSchemeLogic`,u(this.tilingSchemeLogic)),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear(),this._set(`overlayManager`,u(this.overlayManager)),this._tileCache=u(this._tileCache),this._allTiles.prune(),tt.prune(),this._treeDebugger=u(this._treeDebugger),this._renderer.destroyed||(this.view.stage.removeRenderPlugin(this._renderer),this._renderer.destroy()),this._renderer=null,this._iteratorPool=u(this._iteratorPool),this._upsampleMapCache=u(this._upsampleMapCache),this._elevationQueryCache=u(this._elevationQueryCache),this._set(`view`,null),this._extentHelper=u(this._extentHelper),this._upsampleInfoPool=u(this._upsampleInfoPool),nt(),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._stencilEnabledExtents?.length}get _stencilEnabledExtents(){let e=this.spatialReference,t=!!has(`enable-feature:im-as-ground`);return e==null?null:Iterator.from(this.view.allLayerViews).map(n=>{let{layer:r}=n;if(!we(r)||t&&!r.isUsedAsGroundLayer)return null;let{fullExtent:i}=r,a=i==null||i.spatialReference.equals(e)?i:ue(i,i.spatialReference,e);return a?he(a):null}).filter(e=>e!=null).toArray()}get userClippingExtent(){let{spatialReference:e}=this,t=this.view?.clippingArea;if(t==null||e==null)return null;let n=S(),r=ke(t,n,e)?n:null,i=this._get(`userClippingExtent`);return C(r,i)?i:r}get rootTilesExtent(){return this._rootTilesExtent}get groundExtent(){let e=ge(this.fullGroundExtent,this.userClippingExtent,S()),t=this._get(`groundExtent`);return C(e,t)?t:e}get fullGroundExtent(){return this._tilingSchemeExtent==null?this._rootTilesExtent:this._tilingSchemeExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),this.enabled&&!!((this.readyToRun||this._updatingHandles?.updating||this._asyncWorkItems>0)&&this.ready&&!this.freeze||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.freeze}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||this._rootTiles!=null}get rootTiles(){return this._rootTiles}get spatialReference(){return this.tilingScheme?.spatialReference??null}get backgroundColor(){return this.view?.map?.ground?.surfaceColor}set backgroundColor(e){this.view.map.ground.surfaceColor=e}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set(`slicePlaneEnabled`,e),this._evaluateTransparency()}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}get wireframe(){return this._renderer?.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}get opaque(){return this._renderer.transparency===0}get invisible(){return this._renderer.transparency===3}set freeze(e){this._set(`freeze`,e),this._viewChangeUpdate()}get fadeDuration(){return this.view.qualitySettings.fadeDuration??0}intersect(e,t,n,r){this._renderer.intersectRay(e,t,n,r)}getElevationLevelDelta(e){return e<4?3:this.view.qualitySettings.tiledSurface.elevationLevelDelta}get _xNormalizer(){return be(this._spatialReference)}getElevation(e,t,n,r){let i=this._rootTiles;if(!i?.length||!this.enabled||i[0].layerInfo[0].length===0)return null;let a=this._elevationProjectorCache.get(r);if(a===void 0&&(a=fe(r,this._spatialReference)??null,this._elevationProjectorCache.set(r,a)),a==null)return s.getLogger(this).error(`TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system`),null;let o=oe(J,e,t,n);a(o,0,o,0);let c=this._xNormalizer?.normalize(o[0])??o[0],l=o[1];return St(i,c,l)}getElevations(e,t,n){let r=this._rootTiles,i=r?r[0].layerInfo[0].length:0;if(!r?.length||i===0||!this.enabled)for(let e=0;e<t;++e)n(e,null);else for(let i=0;i<t;++i){let t=i*3,a=e[t],o=e[t+1],s=St(r,a,o);n(i,s)}}getLayerIndexByUID(e,t){return this._layerIndexByUid[e].get(t)}getScale(e){if(!this.tilingScheme)return null;if(!pe(e,J,this.spatialReference))return s.getLogger(this).error(`TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system`),null;let t=this._rootTiles;if(t!=null){for(let e of t)if(e?.containsPoint(J)){let t=e;for(;t.children[0]&&!t.rendered;){let e=t.children[0].extent,n=0;J[0]>e[2]&&(n+=1),J[1]<e[1]&&(n+=2),t=t.children[n]}return this._getLodBiasCorrectedScale(t.level)}}return 1/0}getSphereElevationRange(e,t){if(!this.enabled)return null;let n=this._rootTiles,r=this._tilingSchemeSpatialReference;if(n==null||r==null||n.length===0)return null;let i=w(r);if(i){let n=w(t)&&D(t),i=b(t);if(n&&D(r)&&i===b(r))Ae(e,Y,i.radius);else if(!je(e,t,Y,r))return s.getLogger(this).error(`TerrainSurface.getSphereElevationRange(): could not project the query sphere`),null}else if(!de(e,t,yt,r))return s.getLogger(this).error(`TerrainSurface.getSphereElevationRange(): could not project the query sphere`),null;let a=new E,o=[];for(let e of n)o.push(e);let c=0;for(;c<o.length;){let e=o[c];if(++c,!(i?Me(e.extent,Y,r):_e(e.extent,yt)))continue;let t=e.children;if(t[0]==null||e.rendered)a.expandElevationRangeValues(e.elevationBoundsMin,e.elevationBoundsMax);else for(let e of t)o.push(e)}return a}getRootElevationRange(){return this.enabled&&this._rootTiles!=null?new E(this._rootTileElevationRange.minElevation,this._rootTileElevationRange.maxElevation):null}getLowerBoundRadius(){let e=(this._ellipsoid.radius+this.visibleElevationRange.minElevation)*le;return Math.min(e,this._ellipsoid.radius)}queryVisibleScaleRange(e,t,n,r){if(!this._scaleRangeQueries)return;let i=t?this.tilingScheme.levelAtScale(t):0,a=n?this.tilingScheme.levelAtScale(n):1/0,o=this._lodBias;this._scaleRangeQueries.queryVisibleLevelRange(e,i+o,a+o,r)}_evaluateTransparency(){let e=this.baseOpacity,t=this.overlayManager.renderer.isEmpty,n=this._renderer.transparency,r=this._isFullyTransparent?lt(0,t):e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?0:1;return this._renderer.transparency=r,n!==r&&(this.notifyChange(`opaque`),this.notifyChange(`invisible`),!0)}_updateTilingScheme(){let{tilingScheme:e}=this.tilingSchemeLogic;if(e===this.tilingScheme)return;j(!!e,`tiling scheme cannot be reset to undefined`),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();let t=e?.spatialReference??x.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateCarree=this._isWebMercator&&xe(this.view?.renderSpatialReference),this._isGeographic=t?.isGeographic??!1,this._set(`tilingScheme`,e),this._tilingSchemeSpatialReference=this.tilingScheme?.spatialReference,this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.tileSize=e.pixelSize,this.overlayManager.spatialReference=e.spatialReference,this._updateRootTiles())}static{this._tileMemcacheKey=`TerrainTileMemcache`}_acquireTile(e,t,n,r){let i=this._tileCache.pop(K._tileMemcacheKey);return i?(i.init(e,t,n,r,this),i):new this._tileConstructor(e,t,n,r,this)}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){let{groundExtent:e,tilingScheme:t}=this;if(!t)return;if(!this.enabled){this._setRootTiles(null);return}let n=bt,i=t.rootTilesInExtent(e,n,k*5);if(this._rootTiles!=null){if(i.length>k){s.getLogger(this).warn(We);return}let e=this._rootTiles.map(e=>e.lij),t=r(e,i,H);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){let e=this._rootTiles.filter(e=>t.removed.findIndex(t=>H(t,e.lij))>-1?(this._purgeTile(e),!1):!0);t.added.forEach(t=>e.push(this._newRootTile(t))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,i.length>k&&(s.getLogger(this).warn(Ge),i=t.rootTilesInExtent(e,n,k)),this._setRootTiles(i.map(e=>this._newRootTile(e)));C(n,this._rootTilesExtent)||(this._rootTilesExtent=S(n)),this.renderer.visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange(`ready`),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness(`root-tiles-updated`)}_updateAllTileGeometries(){let e=this._allTiles.filter(e=>this._canUpdateTileGeometry(e));e.length===0||(e.sort(U),e.forEach(e=>this._renderer.updateTileGeometryState(e)),e.forEach(e=>e.renderData.updateNeighborData()),this._updateTilesGeometries(e)),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){let t=e.filter(e=>this._canUpdateTileGeometry(e));if(t.length===0)return;let n=this.renderer;for(let e of t)n.updateGeometryIfNeeded(e);for(let e of t)this._pendingTilesForElevationUpdateEvent.add(e)}_canUpdateTileGeometry(e){return e.loaded&&e.intersectsClippingArea&&e.hasGeometryState}_shouldSplit(e){return e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.snapLevel)===1}_newRootTile(e){let 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(),e!=null){let 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.freeze&&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(e==null)return;let t=ot(e),n=this.visibleElevationRange,r=t?n.minElevation:1/0,i=t?n.maxElevation:-1/0,a=this.groundExtent,o=this.view.state.contentCamera.viewProjectionMatrix;this.setTileTreeDirty(!1);let s=this._iteratorPool.acquire();for(s.reset(e);!s.done;){let e=s.next();e.updateClippingStatus(a)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e),e.computeVisibility(),e.updateScreenDepth(o),e.renderData&&(r=Math.min(e.elevationBoundsMin,r),i=Math.max(e.elevationBoundsMax,i))}s.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._updatePendingTileGeometries(),isFinite(r)&&isFinite(i)&&(n.minElevation!==r||n.maxElevation!==i)&&(this.visibleElevationRange=new O(r,i))}_updateRootTileElevationRange(){let e=1/0,t=-1/0;this._rootTiles?.forEach(({elevationBoundsMin:n,elevationBoundsMax:r})=>{e=Math.min(e,n),t=Math.max(t,r)});let n=this._rootTileElevationRange;(n.minElevation!==e||n.maxElevation!==t)&&(this._rootTileElevationRange=new O(e,t))}_updateViewDependentParameters(){let{camera:e,contentCamera:t}=this.view.state,n=Math.tan(t.fovX*.5),r=Math.tan(t.fovY*.5),i=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=n,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=i/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=i/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=ve(this._splitLimits.frustum??ye(),t.frustum):this._splitLimits.frustum=null,se(this._eyePosRenderSR,t.eye),me(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateTileGeometryState(e){e.updateVisibility(),this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this.setMemoryDirty()}_markAllTileNeighborsForUpdate(e){let t;e.forEachLoadedNeighbor(e=>{t??=this._layerViews[1].some(M),t&&e.setPendingUpdate(32),this._pendingTilesToUpdate.add(e)})}_updateTileTexture(e,t){let n=e.resetPendingUpdate(32)?32:e.resetPendingUpdate(16)?16:!1;n&&(this._renderer.updateTileTexture(e,n),this._usedMemory=null,t.madeProgress())}_emitElevationUpdateEventForTiles(){if(!this._shouldEmitChangeEvent)return;let e=this._pendingTilesForElevationUpdateEvent;if(e.size>0){let t=new Float64Array(4*e.size),n=0;for(let r of e)t.set(r.extent,4*n),++n;e.clear();for(let e of Oe(t,this.spatialReference)){let t=new De(this.spatialReference,e,`ground`);this.emit(`elevation-change`,t)}}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);let t=!this.view.state.fixedContentCamera;this._mergeAndSplit(e,t),this._updateElevation(e),this._updateTextures(e),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty();let n=this._pendingTilesToUpdate.size>0,r=n&&this._hasPendingGeometryWithoutIndices();if((!e.done||r)&&this._updatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&(e.hasProgressed||n&&!r)&&this.requestUpdate(),this.notifyChange(`updatingProgressValue`),!e.hasProgressed)return _t}_checkTileInvariant(){}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;let t=!1,n=new Be(this._allTiles.length);n.pushAll(this._rootTiles);let r=this.snapLevel,i=this._splitLimits,a=this._eyePosRenderSR;this._allTiles.forAll(e=>{e.maxLevelDeltaNeighborCount=0,e.unmergableChildCount=0});let o=this.view.state.contentCamera.viewProjectionMatrix;for(;!n.empty;){let e=n.pop(),s=e.parent?.hasPendingUpdate(4),c=e.elevationLevel,l=s?4:e.shouldSplit(i,a,r),u=l===1;e.leaf?Z(e,u):n.pushAll(e.children),s?(e.resetPendingUpdate(1),e.leaf||(e.setPendingUpdate(4),t=!0),this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(o)):(u?(e.resetPendingUpdate(4),e.leaf&&(e.setPendingUpdate(1),t=!0)):(e.resetPendingUpdate(1)&&e.updateAgentSuspension(),l===2&&e.updateAgents(0),e.leaf||(e.setPendingUpdate(4),e.resetPendingUpdate(1),t=!0)),e.elevationLevel!==c&&this.updateElevationSources(e))}this._allTilesDirty=t,this.requestUpdate(),this._shortBatches&&this._updatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){!e.done&&!this._allTilesSorted&&this.view.pointsOfInterest?.focus&&(st(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger?.update(),e.madeProgress())}_markTileToUpdate(e){N(e.loaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForUpdate(e))}_hasPendingGeometryWithoutIndices(){for(let e of this._pendingTilesToUpdate)if(e.loaded&&e.intersectsClippingArea&&e.renderData?.vao?.indexBuffer==null)return!0;return!1}_updatePendingTileGeometries(){let e=this._pendingTilesToUpdate,t=[];if(e.forEach(e=>{this._canUpdateTileGeometry(e)&&t.push(e)}),t.length===0){e.clear();return}let n=(n,r)=>{!r||!this._canUpdateTileGeometry(r)||r.level<n.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(U);let r=t.length;for(let i=0;i<r;++i){let r=t[i];N(r.loaded),N(r.intersectsClippingArea);let a=r.renderData;if(!a?.geometryState)continue;a.updateNeighborData();let o=a.dirtyEdgeResolutions,s=a.geometryState,c=e=>{let t=et[e];n(r,s.cornerPeerNeighbors[e]?.findCorner(Xe(t),e=>e.loaded))};for(let t=0;t<4;++t)if(o&1<<t){let i=a.geometryState.edgePeerNeighbors[t];i&&i?.level>=r.level&&i.forAllSubtreeOnSide(Ye(P[t]),t=>this._canUpdateTileGeometry(t)?(N(e.has(t)||U(r,t)<0),n(r,t),!0):!1),c((t+1)%4),c(t)}}e.clear(),t.sort(U),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,V&&Ze&&this.checkAllTilesWaterproofness(`pending-geometries-updated`)}_mergeAndSplit(e,t){if(this.freeze||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let n=!1,r=this.view.state.fixedContentCamera,i=!1;for(;!e.done;){i=!0;let a=!1,o=!this._allTiles.some(i=>{if(!n&&!r&&!i.visible)return e.done;let o=i;if(i.hasPendingUpdate(4)){if(!t||i.unmergableChildCount>0)return e.done;for(i.resetPendingUpdate(4);o.parent!=null&&o.parent.unmergableChildCount===0&&o.parent.resetPendingUpdate(4);)o=o.parent;this._mergeTile(o),a=!0,e.madeProgress()}else if(i.resetPendingUpdate(1)){let t=!0,n=i.level;if(n>=A){let e=e=>e.leaf||n-e.level<A;for(let r=0;r<4;++r){let a=i.findNeighborTile(P[r],e);a!=null&&n-a.level===A&&(t=!1,V&&(N(a.leaf),N(a.hasPendingUpdate(1))))}}t?(this._splitTile(i),e.madeProgress(),a=!0):i.setPendingUpdate(1)}return e.done});if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0),o){if(!n){n=!0;continue}if(!a)break}else this._allTilesDirty=!0}i?e.madeProgress():this._allTilesDirty=!0,this._allTilesCreated=!this.allTiles.some(e=>e.hasPendingUpdate(1)||e.hasPendingUpdate(4)&&e.unmergableChildCount===0),this._sortTiles(e)}_updateElevation(e){e.done||this._allTiles.some(t=>(t.resetPendingUpdate(8)&&(this._updateTileGeometryState(t),e.madeProgress()),e.done))}updateElevationSources(e){e.needsElevationSourceUpdate()&&(e.updateAgents(0),e.markElevationSourceUpdateRequested(),this.requestUpdate())}_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)*Ke}_getLodBiasCorrectedScale(e){let t=this.tilingScheme.levels,n=c(e-this._lodBias,0,t.length-1),r=n-Math.floor(n),i=t[Math.floor(n)].scale,a=t[Math.ceil(n)].scale;return i*(1-r)+a*r}_removeAllTiles(){this._pendingTilesToUpdate.clear(),this._pendingTilesForElevationUpdateEvent.clear(),this._rootTiles!=null&&(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){let 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?wt(e):this._purgeSubtree(e),this._allTiles.removeUnordered(e),this._unloadTile(e),e.dispose(),this._tileCache.put(K._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){j(e.leaf,`Tile that is already split should not be split again!`),j(e.rendered,`Tile marked to split is not rendered`),wt(e);let t=e.createChildren();this._allTiles.pushArray(t),this.notifyChange(`demResolution`),this.emit(`tiles-changed`,{allTiles:this.allTiles}),e.updateAgentSuspension(),j(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=>Z(e,e.hasPendingUpdate(1))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){X.spatialReference=this.spatialReference,X.extent=e.extent,X.scale=this._getLodBiasCorrectedScale(t),this.emit(`scale-change`,X)}createTile(e,t,n,r){j(!!r,`createTile sanity check`);let i=this._acquireTile(e,t,n,r);return i.updateClippingStatus(this.groundExtent),i.updateScreenDepth(this.view.state.contentCamera.viewProjectionMatrix),this._shouldSplit(i)&&i.setPendingUpdate(1),i}get _shortBatches(){return this.view.state.mode!==2}_mergeTile(e){j(!e.hasPendingUpdate(1),`_mergeTile sanity check`),j(!e.leaf,`Cannot merge a leaf`),e.leaf||(this._purgeSubtree(e),j(!e.renderData,`Merging tile with existing render data?`),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),Z(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=ht){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1,n=new Set,r=-1;for(let e=this.view.allLayerViews.length-1;e>=0;e--){let i=this.view.allLayerViews.items[e];if(n.add(i.uid),F(i)||I(i)){if(this._basemapLayerViewHandles.has(i.uid)&&!I(i)){let e=this._layerClassFromLayerView(i),n=this.getLayerIndexByUID(e,i.uid);n!=null&&((n<r||r==null)&&(t=!0),r=n)}else this._registerTiledLayerView(i),i.layer.loaded&&(t=!0)}}this._basemapLayerViewHandles.forEach((e,r)=>{n.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(let e of this.view.allLayerViews.items)if(L(e)&&!Te(e.layer)&&e.fullOpacity!==0)return!1;return!0}_hasCompositeBlendMode(){for(let e of this.view.allLayerViews.items)if((R(e)||I(e))&&dt(ft[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return+!z(e)}_registerTiledLayerView(e){let t=[];if((R(e)||I(e))&&t.push(m(()=>e.layer.blendMode,()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(2)})),!I(e)){let n=this._layerClassFromLayerView(e);t.push(m(()=>!e.destroyed&&e.suspended,()=>this._updateTiledLayers())),t.push(m(()=>!e.destroyed&&e.fullOpacity,()=>this._updateTileTextures(2)));let{layer:r}=e;`effectiveScaleRange`in r&&t.push(m(()=>!e.destroyed&&r.effectiveScaleRange,()=>this._restartAllAgents(n))),t.push(e.on(`data-changed`,()=>{let t=this.getLayerIndexByUID(n,e.uid);t!=null&&this._invalidateLayerData(t,n)}))}this._unregisterTiledLayerView(e.uid),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){let t=this._basemapLayerViewHandles.get(e);if(t){for(let e of t)e.remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;let e=this.view.allLayerViews,t=[[],[]],n=null;e.forEach(e=>{if(!e.layer||e.suspended||!F(e)||!e.fullExtent)return;let r=this._layerClassFromLayerView(e);if(r===1){let t=e.displayLevelRange.maxLevel;t!==1/0&&(n===null||t>n)&&(n=t)}t[r].push(e)});for(let e of Le){let n=this._layerViews[e],r=t[e];r.reverse();let i=r.length,a=n.length!==i,o=Array(i),s=Array(n.length);this._layerIndexByUid[e].clear();for(let t=0;t<i;t++){let i=r[t].uid;this._layerIndexByUid[e].set(i,t);let c=n.indexOf(r[t]);o[t]=c,t!==c&&(a=!0),c>-1&&(s[c]=t)}if(a){let t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;)t.next().modifyLayers(s,o,e);this._layerViews[e]=r,this._restartAllAgents(e),this._updateTilesVisibility(this._rootTiles)}}this.tilingScheme.ensureMaxLod(n)&&(this._viewChangeUpdate(),this.notifyChange(`tilingScheme`))}_restartAllAgents(e){let t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;){let n=t.next();n.restartAgents(e),e===0&&n.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),e===1?this.renderer.updateTileTexture(t,16):t.updateRenderData(1,e)}),this._evaluateTransparency()}_invalidateLayerData(e,t){this._rootTiles!=null&&(W(this._rootTiles,n=>n.removeLayerAgent(e,t)),W(this._rootTiles,n=>{n.invalidateLayerData(e,t),n.restartAgents(t)}))}setTileTreeDirty(e){this._allTilesDirty=!0,e&&(this._allTilesCreated=!1)}requestRender(e=1){this.renderer.requestRender(e)}requestUpdate(){++this._pendingUpdates===1&&(this._hasPendingUpdates=!0)}requestTileData(e,t,n,r){let i=this.layerViewByIndex(t,n),{tilemapCache:a}=i;return!a||M(i)?this._requestTileData(e,n,i,r):(++this._asyncWorkItems,a.fetchAvailability(e.level,e.lij[1],e.lij[2],{...r,timeout:6e3}).catch(t=>{throw te(r),ne(t)||this._dataMissing(e,n,i),t}).then(()=>this._frameTask.schedule(()=>this._requestTileData(e,n,i,r),r.signal)).finally(()=>--this._asyncWorkItems))}_requestTileData(e,t,n,r){return this.destroying?Promise.resolve():t===0?z(n)?this._requestElevationTileData(e,n,r):Promise.reject():L(n)?this._requestMapTileData(e,n,r):Promise.reject()}_requestElevationTileData(e,t,n){++this._asyncWorkItems;let r=r=>{!p(n)&&r&&(this.setMemoryDirty(),this.requestUpdate(),this._elevationDataArrived(e,t,r))},i=n=>{ne(n)||(s.getLogger(this).error(`Tile ${e.lij.toString()} layer 0/${t.uid} error ${n}`),this._dataMissing(e,0,t),this.requestUpdate())};return t.fetchElevationTile(e,{...Ee,...n}).then(e=>this._frameTask.schedule(()=>r(e)),i).finally(()=>--this._asyncWorkItems)}_elevationDataArrived(e,t,n){let r=this._layerIndexByUid[0].get(t.uid);if(r==null){s.getLogger(this).warn(`TerrainSurface: received data from unknown layer %d %s`,0,e.lij.toString());return}let i=new Pe(e.lij,e.extent,n);e.dataArrived(r,0,i),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:0});let a=[e],o=e.level,c=this._iteratorPool.acquire();for(c.reset(a);!c.done;){let e=c.next();e.findElevationBoundsForLayer(r,o),e.computeElevationBounds()}o===0&&this._updateRootTileElevationRange(),c.remove(),this._updateTilesVisibility(a)}_requestMapTileData(e,t,n){++this._asyncWorkItems;let r=(r,i)=>{B(i),p(n)||(console.error(`Tile ${e.lij.toString()} layer 1/${t.uid} error ${r}`),this._dataMissing(e,1,t),this.requestUpdate())},i=e=>t=>r(t,e);return t.fetchTile(e.lij,n).then(r=>this._frameTask.schedule(()=>{this.requestUpdate(),p(n)?B(r):this._mapTileDataArrived(e,t,r)},n.signal,i(r)).catch(i(r)),(e,t=null)=>this._frameTask.schedule(()=>r(e,t))).finally(()=>--this._asyncWorkItems)}_mapTileDataArrived(e,t,n){let r=this.getLayerIndexByUID(1,t.uid);r==null?(B(n),s.getLogger(this).warn(`TerrainSurface: received data from unknown layer`)):(e.dataArrived(r,1,n),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:1}))}_dataMissing(e,t,n){let r=this.getLayerIndexByUID(t,n.uid);r==null?s.getLogger(this).warn(`TerrainSurface: received data from unknown layer`):(e.dataMissing(r,t),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:t}))}get performanceInfo(){let 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++;let n=t.level;t.renderData&&(e.numLoadedPerLevel[n]=(e.numLoadedPerLevel[n]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[n]=(e.numRenderedPerLevel[n]||0)+1,e.numRendered++))}),e}setMemoryDirty(){this._usedMemory=null}get usedMemory(){return this.tilingScheme?(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,n=this._layerClassFromLayerView(e),r=this.getLayerIndexByUID(n,e.uid);return r!=null&&this._allTiles.forAll(e=>t+=e.getUsedMemoryForLayer(n,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(e=`render-patch-groups`){}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&&e[2]===0}lijEastEnd(e){return 1<<e+ +!!this._isGeographic}wrapEastWest(e){let t=this.lijEastEnd(e[0]),n=e[2];if(0<=n&&n<t)return e;if(!this._isGlobal)return null;let r=(n+(n<0?t:0))%t;return[e[0],e[1],r]}enableInternalChecks(e){Qe(e)}enableWaterproofnessChecks(e){$e(e)}static cleanupTerrainSurface(){xt.prune()}enable(e){e!==this.enabled&&(this._set(`enabled`,e),e?(this._updateRootTiles(),this.freeze=!1,this.view.elevationProvider.register(0,this)):(this.view.elevationProvider.unregister(this),this.freeze=!0,this._removeAllTiles(),this._setRootTiles(null)),this.notifyChange(`ready`))}updateOverlayParameters(){let{overlayManager:e}=this;this.allTiles.forAll(t=>t.updateOverlayParameters(e))}};e([v()],q.prototype,`_renderer`,void 0),e([v({constructOnly:!0})],q.prototype,`_scaleRangeQueries`,void 0),e([v({constructOnly:!0})],q.prototype,`view`,void 0),e([v({constructOnly:!0})],q.prototype,`overlayManager`,void 0),e([v()],q.prototype,`_hasPendingUpdates`,void 0),e([v()],q.prototype,`_asyncWorkItems`,void 0),e([v()],q.prototype,`_allTilesDirty`,void 0),e([v()],q.prototype,`_allTilesSorted`,void 0),e([v()],q.prototype,`allTilesCreated`,null),e([v()],q.prototype,`_allTilesCreated`,void 0),e([v()],q.prototype,`_viewChanged`,void 0),e([v({type:Number})],q.prototype,`heading`,void 0),e([v()],q.prototype,`_splitLimits`,void 0),e([v()],q.prototype,`_frameTask`,void 0),e([v()],q.prototype,`demResolution`,null),e([v({readOnly:!0})],q.prototype,`snapLevel`,null),e([v({readOnly:!0})],q.prototype,`lodSnappingEnabled`,null),e([v()],q.prototype,`_stencilEnabledExtents`,null),e([v({readOnly:!0})],q.prototype,`userClippingExtent`,null),e([v()],q.prototype,`_rootTilesExtent`,void 0),e([v({readOnly:!0})],q.prototype,`groundExtent`,null),e([v({readOnly:!0})],q.prototype,`fullGroundExtent`,null),e([v({readOnly:!0})],q.prototype,`_tilingSchemeExtent`,null),e([v({readOnly:!0})],q.prototype,`updating`,null),e([v({readOnly:!0})],q.prototype,`readyToRun`,null),e([v(Ne)],q.prototype,`updatingProgress`,void 0),e([v({readOnly:!0})],q.prototype,`updatingProgressValue`,null),e([v()],q.prototype,`_maxNumUpdating`,void 0),e([v()],q.prototype,`baseOpacity`,null),e([v()],q.prototype,`hasCompositeBlendMode`,void 0),e([v({readOnly:!0})],q.prototype,`viewingMode`,null),e([v()],q.prototype,`maxTextureScale`,void 0),e([v({readOnly:!0})],q.prototype,`ready`,null),e([v({readOnly:!0})],q.prototype,`rootTiles`,null),e([v()],q.prototype,`_rootTiles`,void 0),e([v({readOnly:!0})],q.prototype,`spatialReference`,null),e([v({type:t})],q.prototype,`backgroundColor`,null),e([v({value:!1})],q.prototype,`slicePlaneEnabled`,null),e([v({readOnly:!0})],q.prototype,`tilingScheme`,void 0),e([v({readOnly:!0})],q.prototype,`tilingSchemeLocked`,null),e([v({readOnly:!0})],q.prototype,`tilingSchemeLogic`,void 0),e([v()],q.prototype,`wireframe`,null),e([v()],q.prototype,`opaque`,null),e([v()],q.prototype,`invisible`,null),e([v({value:!1})],q.prototype,`freeze`,null),e([v()],q.prototype,`fadeDuration`,null),e([v()],q.prototype,`_xNormalizer`,null),e([v()],q.prototype,`visibleElevationRange`,void 0),e([v()],q.prototype,`_rootTileElevationRange`,void 0),e([v()],q.prototype,`_layerViewsDirty`,void 0),e([v()],q.prototype,`renderPatchBorders`,null),e([v()],q.prototype,`renderingDisabled`,null),e([v({readOnly:!0})],q.prototype,`enabled`,void 0),q=K=e([ie(`esri.views.3d.terrain.TerrainSurface`)],q);const vt=q,J=y(),yt=new Se,Y=S(),bt=S(),xt=new f,X={spatialReference:null,extent:null,scale:0};function St(e,t,n){for(let r of e){if(!r.containsPointXY(t,n))continue;let e=r;for(;e&&!e.renderData;){let r=+(t>e.extentMidX)+(n<e.extentMidY?2:0);e=e.children[r]}let i=e?.renderData?.geometryState.samplerData??null;return Fe(t,n,i)}return null}function Z(e,t){!e.leaf||e.level<A||$(e,e=>{t&&Ct(e);let n=Q(e);if(e.maxLevelDeltaNeighborCount++,n){let t=e.parent;for(;t;){let e=Q(t);if(t.unmergableChildCount++,e)t=t.parent;else break}}})}function Ct(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<A||$(e,e=>{Ct(e)})}function wt(e){e.level<A||$(e,e=>{if(e.maxLevelDeltaNeighborCount--,e.maxLevelDeltaNeighborCount===0&&e.unmergableChildCount===0){let t=e.parent;for(;t&&(t.unmergableChildCount--,Q(t));)t=t.parent}})}function Q(e){return e.maxLevelDeltaNeighborCount===0&&e.unmergableChildCount===0}function $(e,t){if(e.level<A)return;let n=e.level-A,r=e.lij[1]>>A,i=e.lij[2]>>A,a=e=>e.leaf||e.level===n;for(let o=0;o<4;++o){let s=e.findNeighborTile(P[o],a);if(!s||s.level!==n)continue;let c=s.lij;(c[1]!==r||c[2]!==i)&&t(s)}}export{vt as default};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import"../../../core/has.js";import{disposeMaybe as e,releaseMaybe as t}from"../../../core/maybe.js";import{set as n,copy as r}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{ZEROS as i}from"../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{fromValues as a}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{isBaseLayer as o,isGroupLayer as s,isReferenceLayer as c}from"../../../layers/support/layerUtils.js";import{isLayerViewWithFlowRenderer as l}from"../support/flowUtils.js";import{BlendLayersPassParameters as u}from"./BlendLayersTechnique.js";import{isBlendableLayerView as d,isVectorTileLayerView as f,isVectorTileRenderInfo as p,isImageryTileRenderInfo as m,isImageSourceRenderInfo as h,isTextureTileRenderInfo as g,isVectorTilePerLayerInfo as _}from"./terrainUtils.js";import{TextureReference as v}from"./TextureReference.js";import{TileCompositor as y}from"./TileCompositor.js";import{TileRenderInfo as b}from"./TileRenderInfo.js";import{getCacheKey as x,TileTexture as S}from"./TileTexture.js";import{fallsWithinLayerView as C}from"./tileUtils.js";import{blendModeFromString as w}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{isCompressible as T}from"../../support/TextureCompressionWorkerHandle.js";import E from"../../webgl/Texture.js";import{TextureDescriptor as D}from"../../webgl/TextureDescriptor.js";class O{constructor(e,t,n,r,i,a){this._surface=e,this._rctx=t,this.tileSize=n,this._techniques=r,this._cache=i,this._compressionTracker=a,this._passParameters=new u,this._backgroundColor=null,this._maxAnisotropy=this._rctx.parameters.maxMaxAnisotropy,this._compositor=new y(this._rctx,this._techniques)}dispose(){this._compositor=e(this._compositor),this._sharedBackground=t(this._sharedBackground)}get backgroundIsGrid(){return this._backgroundColor==null}get backgroundColor(){return this._backgroundColor}updateHeading(e){this._compositor?.updateHeading(e)}updateTileTexture(e,t){if(!e.renderData)return;let n=this._prepareComposite(e),r=n.targetTextureSize/this.tileSize;n.numTexturedLayers===0||n.firstTexturedLayerIndex===null?this._useBackgroundTexture(e,n,t!==0):(n.numTexturedLayers!==1||n.backgroundVTLIndex!=null||n.foundBlendMode||!this._useLayerTexture(e,n.firstTexturedLayerIndex??0))&&this._composeLayers(e,t,r,F,n)}_prepareComposite(e){let t=this._surface,n=t.baseOpacity,r=t.view.state.contentPixelRatio,i=e.layerInfo[1],a=new P(e.lij,this.tileSize);F.clear(),I.length=0;for(let u=0;u<i.length;u++){let p=t.layerViewByIndex(u,1),m=p.layer,h=!C(e,p),g=m.opacity,_=p.fullOpacity;if(a.hasBasemapLayers=a.hasBasemapLayers||o(m),l(p))continue;if(d(p)){let e=p.layer.blendMode!==`normal`;if(s(m.parent)){let t=m.parent.uid;t!=null&&t!==``&&(e=j(m.parent)||e)}e&&(a.foundBlendMode=e,a.backgroundCovered=!1)}if(this._canSkipLayer(g,h,a.foundBlendMode)){this._clearTexturePendingUpdates(i[u]);continue}++a.numVisibleLayers;let v=f(p);a.backgroundVTLIndex==null&&v&&p.layer.styleRepository.backgroundBucketIds.length>0&&(a.backgroundVTLIndex=u);let y=k(e,u,v);if(!(!y||(this._clearTexturePendingUpdates(i[u]),!y.sourceLayerInfo.data))){if(s(m.parent)){let e=m.parent.uid;e!=null&&e!==``&&M(m.parent,u)}if(v)a.targetTextureSize=Math.max(a.targetTextureSize,this.tileSize*r);else{let e=this._prepareTextureForBackgroundCoverageCheck(y,c(m));n===1&&_===1&&(p.isOpaque||e?.descriptor.isOpaque===!0)&&(a.backgroundCovered=!0)}++a.numTexturedLayers,a.firstTexturedLayerIndex??=u}}return a.lastLayerIndex=i.length-1,a}_canSkipLayer(e,t,n){return this._isLayerNonContributing(e,t)&&!n}_isLayerNonContributing(e,t){return e===0||t}_clearTexturePendingUpdates(e){e.pendingUpdates&=-1}_prepareTextureForBackgroundCoverageCheck(e,t){return this._dataToTexture(e,t)?e.sourceLayerInfo.data:null}setBackground(e){this._backgroundColor!==e&&(this._backgroundColor=e,this._sharedBackground&&this._drawBackgroundTexture(this._sharedBackground))}_drawBackgroundTexture(e,t,n){if(this._passParameters.offset=i,this._passParameters.scale=1,this._passParameters.opacity=1,this.backgroundColor&&(this._passParameters.backgroundColor=this.backgroundColor),this._compositor.bind(this.tileSize),n?.backgroundVTLIndex==null||t==null)this._compositor.drawBackground(this._passParameters,this.backgroundColor!=null);else{let e=k(t,n.backgroundVTLIndex,!0);this._passParameters.opacity=this._surface.layerViewByIndex(n.backgroundVTLIndex,1).layer.opacity,this._compositor.drawVectorData(this._passParameters,this.backgroundIsGrid?3:2,n.targetTextureSize,0,e,n.targetTextureSize/this.tileSize,this.tileSize,!1)}this._compositor.copyFBOToTexture(e),this._compositor.unbind()}_useBackgroundTexture(e,t,n){let r=e.renderData,i=!n&&!r.textureReference?.isBackground&&(this._surface.view.layerViewManager.updating||t.numVisibleLayers>0)?5e3:0;r.setTextureReference(new v(this._composeBackground(e,t),!0,0,R,this._surface.baseOpacity,0,1),i)}_composeBackground(e,t){if(t?.backgroundVTLIndex==null)return this._sharedBackground??(this._sharedBackground=this._buildTexture(this.tileSize,!1),this._drawBackgroundTexture(this._sharedBackground)),this._sharedBackground;let n=e.renderData.ensureTexture(this.tileSize,!1,0,()=>this._buildTexture(this.tileSize,!1,9987));return this._drawBackgroundTexture(n,e,t),n}_useLayerTexture(e,t){let n=this._surface.layerViewByIndex(t,1),r=o(n.layer),i=r?this._surface.baseOpacity:1,s=r?1:this._surface.baseOpacity,l=n.fullOpacity,u=k(e,t,!1);return this._dataToTexture(u,c(n.layer))?(e.renderData.setTextureReference(new v(u.sourceLayerInfo.data,!1,0,a(u.offset[0],u.offset[1],u.scale,u.scale),i,s,l)),!0):!1}_composeLayers(e,t,n,r,a){let{lastLayerIndex:s,hasBasemapLayers:u,targetTextureSize:h,backgroundCovered:g,foundBlendMode:_,backgroundVTLIndex:y}=a;this._compositor.ensureBuffer(h);let b=!g||_,x=this._surface.baseOpacity,S=!1,T=9987,E=!1,D=0;for(let t=s;t>=0;t--){let a=this._surface.layerViewByIndex(t,1);if(l(a))continue;let s=a.layer,g=f(a),v=k(e,t,g),O=s.opacity,j=!C(e,a),M=!v?.sourceLayerInfo.data&&t===y;if(!v?.sourceLayerInfo.data&&!M||this._canSkipLayer(O,j,_))continue;let N=!o(s)&&!S;S||=N;let P=this._openGroupsAtLayer(t,h,x,u,b,N,r),F=P?4:b&&D===0?this.backgroundIsGrid?3:2:1,L=w[d(a)?a.layer.blendMode:`normal`];for(this._passParameters.baseOpacity=N&&!P&&x<1?x:1,this._passParameters.opacity=O,M||p(v)?E=this._compositor.drawVectorData(this._passParameters,F,h,L,v,n,this.tileSize,E):m(v)?(this._compositor.drawRasterData(this._passParameters,F,h,L,v),A(v)&&(T=9728)):this._dataToTexture(v,c(s))&&(this._passParameters.texture=v.sourceLayerInfo.data.texture,this._passParameters.offset=v.offset,this._passParameters.scale=v.scale,this._compositor.drawImageData(this._passParameters,F,h,L));I.length>0&&I[I.length-1].end===t;){let e=I.pop();this._passParameters.baseOpacity=e.baseOpacity,this._passParameters.opacity=e.opacity,this._passParameters.offset=i,this._passParameters.scale=1,this._compositor.drawGroup(this._passParameters,e.output,h,w[e.blendMode])}D++}let O=e.renderData,j=_||S&&x<1,M=O.ensureTexture(h,j,t,()=>this._buildTexture(h,j,T));this._compositor.copyFBOToTexture(M),this._compositor.unbind(),O.setTextureReference(new v(M,!1,t,R,S?1:x,0,1))}_openGroupsAtLayer(e,t,n,r,i,a,o){let s=!1;return o.forEach(o=>{o.start===e&&(o.output=r?1:i&&a?this.backgroundIsGrid?3:2:1,o.baseOpacity=a?n:1,I.push(o),this._compositor.openGroup(t),s=!0)}),s}_dataToTexture(e,t){if(h(e)){let n=e.sourceLayerInfo,r=!t;n.data=this._buildTexture(n.data,!0,r,e.scale!==1,e.tile.onCompressionFinished),e.tile.setMemoryDirty()}return g(e)}_buildTexture(e,t,n=9987,r=!1,i=()=>{}){return e==null?null:typeof e==`number`?this._buildTextureFromSize(e,t,n):this._buildTextureFromImage(e,t,n,r,i)}_buildTextureFromSize(e,t,n){let r=this._createTextureDescriptor(t,typeof n==`boolean`?9987:n);return r.width=r.height=e,this._buildTileTexture(r)}_buildTextureFromImage(e,t,n,r,i){let a=this._createTextureDescriptor(t,typeof n==`boolean`?9987:n);a.isOpaque=e.isOpaque,a.isOpaque&&(a.pixelFormat=6407);let{bitmap:o}=e;a.width=o.width,a.height=o.height;let s=typeof n==`boolean`&&n;return this._buildTileTexture(a,s,r,i,o)}_createTextureDescriptor(e,t){let n=new D;return n.wrapMode=33071,n.samplingMode=t,n.maxAnisotropy=this._maxAnisotropy,n.preMultiplyAlpha=!0,n.flipped=!0,n.hasMipmap=!0,e||(n.pixelFormat=6407),n}_buildTileTexture(e,t=!1,n=!1,r=()=>{},i){let a=this._cache.pop(x(e,!1))??this._cache.pop(x(e,!0));if(t&&=T(i,e),a)return a.retain(),t?a.texture.enableCompression({compressionTracker:this._compressionTracker,compressionCallback:r,preserveSourceBitmap:n}):a.texture.disableCompression(),a.texture.setData(i),a;e.compress=t?{compressionTracker:this._compressionTracker,compressionCallback:r,preserveSourceBitmap:n}:void 0;let o=new E(this._rctx,e,i);return new S(o,this._cache)}get test(){}}function k(e,t,i){L.layerIndex=t,L.vtlNeighborInfos.clear();let a=e.layerInfo[1][t];if(n(L.offset,0,0),L.tile=e,L.scale=1,L.sourceLod=e.lij,L.sourceLayerInfo=a,a.data)return i&&e.forEachLoadedNeighbor((n,r)=>{if(n.level!==e.level)return;let i=n.layerInfo[1][t];if(!_(i)||a.data===i.data)return;let o=L.vtlNeighborInfos.pushNew();o.offset=z[r],o.sourceLod=n.lij,o.sourceLayerInfo=i}),L;let o=a.upsampleInfo,s=o?.tile?.layerInfo[1][t];return s&&o.tile?(L.tile=o.tile,r(L.offset,o.offset),L.scale=o.scale,L.sourceLod=o.tile.lij,L.sourceLayerInfo=s,L):i?L:null}function A(e){let t=e.sourceLayerInfo.data;return t.source?t.interpolation===`nearest`:!1}function j(e){let t=e.blendMode!==`normal`;return s(e.parent)&&(t=j(e.parent)||t),t}function M(e,t){s(e.parent)&&M(e.parent,t);let n=e.uid;if(n!=null&&n!==``){let r=F.get(n);r?r.start=t:F.set(n,new N(t,t,e.blendMode,e.opacity,1,1))}}class N{constructor(e,t,n,r,i,a){this.start=e,this.end=t,this.blendMode=n,this.opacity=r,this.output=i,this.baseOpacity=a}}class P{constructor(e,t){this.lij=e,this.targetTextureSize=t,this.numTexturedLayers=0,this.numVisibleLayers=0,this.backgroundCovered=!1,this.hasBasemapLayers=!1,this.foundBlendMode=!1,this.lastLayerIndex=0}}const F=new Map,I=[],L=new b,R=a(0,0,1,1),z=[];z[0]=[0,-1],z[1]=[-1,-1],z[2]=[-1,0],z[3]=[-1,1],z[4]=[0,1],z[5]=[1,1],z[6]=[1,0],z[7]=[1,-1];function B(){L.sourceLayerInfo=null,L.tile=null,L.vtlNeighborInfos.prune()}export{N as GroupInfo,O as TileRenderer,B as cleanupTileRenderer};
2
+ import"../../../core/has.js";import{disposeMaybe as e,releaseMaybe as t}from"../../../core/maybe.js";import{set as n,copy as r}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{ZEROS as i}from"../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{fromValues as a}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{isBaseLayer as o,isGroupLayer as s,isReferenceLayer as c}from"../../../layers/support/layerUtils.js";import{isLayerViewWithFlowRenderer as l}from"../support/flowUtils.js";import{BlendLayersPassParameters as u}from"./BlendLayersTechnique.js";import{isBlendableLayerView as d,isVectorTileLayerView as f,isVectorTileRenderInfo as p,isImageryTileRenderInfo as m,isImageSourceRenderInfo as h,isTextureTileRenderInfo as g,isVectorTilePerLayerInfo as _}from"./terrainUtils.js";import{TextureReference as v}from"./TextureReference.js";import{TileCompositor as y}from"./TileCompositor.js";import{TileRenderInfo as b}from"./TileRenderInfo.js";import{getCacheKey as x,TileTexture as S}from"./TileTexture.js";import{fallsWithinLayerView as C}from"./tileUtils.js";import{blendModeFromString as w}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{isCompressible as T}from"../../support/TextureCompressionWorkerHandle.js";import E from"../../webgl/Texture.js";import{TextureDescriptor as D}from"../../webgl/TextureDescriptor.js";class O{constructor(e,t,n,r,i,a){this._surface=e,this._rctx=t,this.tileSize=n,this._techniques=r,this._cache=i,this._compressionTracker=a,this._passParameters=new u,this._backgroundColor=null,this._maxAnisotropy=this._rctx.parameters.maxMaxAnisotropy,this._compositor=new y(this._rctx,this._techniques)}dispose(){this._compositor=e(this._compositor),this._sharedBackground=t(this._sharedBackground)}get backgroundIsGrid(){return this._backgroundColor==null}get backgroundColor(){return this._backgroundColor}updateHeading(e){this._compositor?.updateHeading(e)}updateTileTexture(e,t){if(!e.renderData)return;let n=this._prepareComposite(e),r=n.targetTextureSize/this.tileSize;n.numTexturedLayers===0||n.firstTexturedLayerIndex===null?this._useBackgroundTexture(e,n,t!==0):(n.numTexturedLayers!==1||n.backgroundVTLIndex!=null||n.foundBlendMode||!this._useLayerTexture(e,n.firstTexturedLayerIndex??0))&&this._composeLayers(e,t,r,F,n)}_prepareComposite(e){let t=this._surface,n=t.baseOpacity,r=t.view.state.contentPixelRatio,i=e.layerInfo[1],a=new P(e.lij,this.tileSize);F.clear(),I.length=0;for(let u=0;u<i.length;u++){let p=t.layerViewByIndex(u,1),m=p.layer,h=!C(e,p),g=m.opacity,_=p.fullOpacity;if(a.hasBasemapLayers=a.hasBasemapLayers||o(m),l(p))continue;if(d(p)){let e=p.layer.blendMode!==`normal`;if(s(m.parent)){let t=m.parent.uid;t!=null&&t!==``&&(e=j(m.parent)||e)}e&&(a.foundBlendMode=e,a.backgroundCovered=!1)}if(this._canSkipLayer(g,h,a.foundBlendMode)){this._clearTexturePendingUpdates(i[u]);continue}++a.numVisibleLayers;let v=f(p);a.backgroundVTLIndex==null&&v&&p.layer.styleRepository.backgroundBucketIds.length>0&&(a.backgroundVTLIndex=u);let y=k(e,u,v);if(!(!y||(this._clearTexturePendingUpdates(i[u]),!y.sourceLayerInfo.data))){if(s(m.parent)){let e=m.parent.uid;e!=null&&e!==``&&M(m.parent,u)}if(v)a.targetTextureSize=Math.max(a.targetTextureSize,this.tileSize*r);else{let e=this._prepareTextureForBackgroundCoverageCheck(y,c(m));n===1&&_===1&&(p.isOpaque||e?.descriptor.isOpaque===!0)&&(a.backgroundCovered=!0)}++a.numTexturedLayers,a.firstTexturedLayerIndex??=u}}return a.lastLayerIndex=i.length-1,a}_canSkipLayer(e,t,n){return this._isLayerNonContributing(e,t)&&!n}_isLayerNonContributing(e,t){return e===0||t}_clearTexturePendingUpdates(e){e.pendingUpdates&=-1}_prepareTextureForBackgroundCoverageCheck(e,t){return this._dataToTexture(e,t)?e.sourceLayerInfo.data:null}setBackground(e){this._backgroundColor!==e&&(this._backgroundColor=e,this._sharedBackground&&this._drawBackgroundTexture(this._sharedBackground))}_drawBackgroundTexture(e,t,n){if(e.texture.setSamplingMode(9987),this._passParameters.offset=i,this._passParameters.scale=1,this._passParameters.opacity=1,this.backgroundColor&&(this._passParameters.backgroundColor=this.backgroundColor),this._compositor.bind(this.tileSize),n?.backgroundVTLIndex==null||t==null)this._compositor.drawBackground(this._passParameters,this.backgroundColor!=null);else{let e=k(t,n.backgroundVTLIndex,!0);this._passParameters.opacity=this._surface.layerViewByIndex(n.backgroundVTLIndex,1).layer.opacity,this._compositor.drawVectorData(this._passParameters,this.backgroundIsGrid?3:2,n.targetTextureSize,0,e,n.targetTextureSize/this.tileSize,this.tileSize,!1)}this._compositor.copyFBOToTexture(e),this._compositor.unbind()}_useBackgroundTexture(e,t,n){let r=e.renderData,i=!n&&!r.textureReference?.isBackground&&(this._surface.view.layerViewManager.updating||t.numVisibleLayers>0)?5e3:0;r.setTextureReference(new v(this._composeBackground(e,t),!0,0,R,this._surface.baseOpacity,0,1),i)}_composeBackground(e,t){if(t?.backgroundVTLIndex==null)return this._sharedBackground??(this._sharedBackground=this._buildTexture(this.tileSize,!1),this._drawBackgroundTexture(this._sharedBackground)),this._sharedBackground;let n=e.renderData.ensureTexture(this.tileSize,!1,0,()=>this._buildTexture(this.tileSize,!1,9987));return this._drawBackgroundTexture(n,e,t),n}_useLayerTexture(e,t){let n=this._surface.layerViewByIndex(t,1),r=o(n.layer),i=r?this._surface.baseOpacity:1,s=r?1:this._surface.baseOpacity,l=n.fullOpacity,u=k(e,t,!1);return this._dataToTexture(u,c(n.layer))?(e.renderData.setTextureReference(new v(u.sourceLayerInfo.data,!1,0,a(u.offset[0],u.offset[1],u.scale,u.scale),i,s,l)),!0):!1}_composeLayers(e,t,n,r,a){let{lastLayerIndex:s,hasBasemapLayers:u,targetTextureSize:h,backgroundCovered:g,foundBlendMode:_,backgroundVTLIndex:y}=a;this._compositor.ensureBuffer(h);let b=!g||_,x=this._surface.baseOpacity,S=!1,T=9987,E=!1,D=0;for(let t=s;t>=0;t--){let a=this._surface.layerViewByIndex(t,1);if(l(a))continue;let s=a.layer,g=f(a),v=k(e,t,g),O=s.opacity,j=!C(e,a),M=!v?.sourceLayerInfo.data&&t===y;if(!v?.sourceLayerInfo.data&&!M||this._canSkipLayer(O,j,_))continue;let N=!o(s)&&!S;S||=N;let P=this._openGroupsAtLayer(t,h,x,u,b,N,r),F=P?4:b&&D===0?this.backgroundIsGrid?3:2:1,L=w[d(a)?a.layer.blendMode:`normal`];for(this._passParameters.baseOpacity=N&&!P&&x<1?x:1,this._passParameters.opacity=O,M||p(v)?E=this._compositor.drawVectorData(this._passParameters,F,h,L,v,n,this.tileSize,E):m(v)?(this._compositor.drawRasterData(this._passParameters,F,h,L,v),A(v)&&(T=9728)):this._dataToTexture(v,c(s))&&(this._passParameters.texture=v.sourceLayerInfo.data.texture,this._passParameters.offset=v.offset,this._passParameters.scale=v.scale,this._compositor.drawImageData(this._passParameters,F,h,L));I.length>0&&I[I.length-1].end===t;){let e=I.pop();this._passParameters.baseOpacity=e.baseOpacity,this._passParameters.opacity=e.opacity,this._passParameters.offset=i,this._passParameters.scale=1,this._compositor.drawGroup(this._passParameters,e.output,h,w[e.blendMode])}D++}let O=e.renderData,j=_||S&&x<1,M=O.ensureTexture(h,j,t,()=>this._buildTexture(h,j,T));M.texture.setSamplingMode(T),this._compositor.copyFBOToTexture(M),this._compositor.unbind(),O.setTextureReference(new v(M,!1,t,R,S?1:x,0,1))}_openGroupsAtLayer(e,t,n,r,i,a,o){let s=!1;return o.forEach(o=>{o.start===e&&(o.output=r?1:i&&a?this.backgroundIsGrid?3:2:1,o.baseOpacity=a?n:1,I.push(o),this._compositor.openGroup(t),s=!0)}),s}_dataToTexture(e,t){if(h(e)){let n=e.sourceLayerInfo,r=!t;n.data=this._buildTexture(n.data,!0,r,e.scale!==1,e.tile.onCompressionFinished),e.tile.setMemoryDirty()}return g(e)}_buildTexture(e,t,n=9987,r=!1,i=()=>{}){return e==null?null:typeof e==`number`?this._buildTextureFromSize(e,t,n):this._buildTextureFromImage(e,t,n,r,i)}_buildTextureFromSize(e,t,n){let r=this._createTextureDescriptor(t,typeof n==`boolean`?9987:n);return r.width=r.height=e,this._buildTileTexture(r)}_buildTextureFromImage(e,t,n,r,i){let a=this._createTextureDescriptor(t,typeof n==`boolean`?9987:n);a.isOpaque=e.isOpaque,a.isOpaque&&(a.pixelFormat=6407);let{bitmap:o}=e;a.width=o.width,a.height=o.height;let s=typeof n==`boolean`&&n;return this._buildTileTexture(a,s,r,i,o)}_createTextureDescriptor(e,t){let n=new D;return n.wrapMode=33071,n.samplingMode=t,n.maxAnisotropy=this._maxAnisotropy,n.preMultiplyAlpha=!0,n.flipped=!0,n.hasMipmap=!0,e||(n.pixelFormat=6407),n}_buildTileTexture(e,t=!1,n=!1,r=()=>{},i){let a=this._cache.pop(x(e,!1))??this._cache.pop(x(e,!0));if(t&&=T(i,e),a)return a.retain(),a.texture.setSamplingMode(e.samplingMode),t?a.texture.enableCompression({compressionTracker:this._compressionTracker,compressionCallback:r,preserveSourceBitmap:n}):a.texture.disableCompression(),a.texture.setData(i),a;e.compress=t?{compressionTracker:this._compressionTracker,compressionCallback:r,preserveSourceBitmap:n}:void 0;let o=new E(this._rctx,e,i);return new S(o,this._cache)}get test(){}}function k(e,t,i){L.layerIndex=t,L.vtlNeighborInfos.clear();let a=e.layerInfo[1][t];if(n(L.offset,0,0),L.tile=e,L.scale=1,L.sourceLod=e.lij,L.sourceLayerInfo=a,a.data)return i&&e.forEachLoadedNeighbor((n,r)=>{if(n.level!==e.level)return;let i=n.layerInfo[1][t];if(!_(i)||a.data===i.data)return;let o=L.vtlNeighborInfos.pushNew();o.offset=z[r],o.sourceLod=n.lij,o.sourceLayerInfo=i}),L;let o=a.upsampleInfo,s=o?.tile?.layerInfo[1][t];return s&&o.tile?(L.tile=o.tile,r(L.offset,o.offset),L.scale=o.scale,L.sourceLod=o.tile.lij,L.sourceLayerInfo=s,L):i?L:null}function A(e){let t=e.sourceLayerInfo.data;return t.source?t.interpolation===`nearest`:!1}function j(e){let t=e.blendMode!==`normal`;return s(e.parent)&&(t=j(e.parent)||t),t}function M(e,t){s(e.parent)&&M(e.parent,t);let n=e.uid;if(n!=null&&n!==``){let r=F.get(n);r?r.start=t:F.set(n,new N(t,t,e.blendMode,e.opacity,1,1))}}class N{constructor(e,t,n,r,i,a){this.start=e,this.end=t,this.blendMode=n,this.opacity=r,this.output=i,this.baseOpacity=a}}class P{constructor(e,t){this.lij=e,this.targetTextureSize=t,this.numTexturedLayers=0,this.numVisibleLayers=0,this.backgroundCovered=!1,this.hasBasemapLayers=!1,this.foundBlendMode=!1,this.lastLayerIndex=0}}const F=new Map,I=[],L=new b,R=a(0,0,1,1),z=[];z[0]=[0,-1],z[1]=[-1,-1],z[2]=[-1,0],z[3]=[-1,1],z[4]=[0,1],z[5]=[1,1],z[6]=[1,0],z[7]=[1,-1];function B(){L.sourceLayerInfo=null,L.tile=null,L.vtlNeighborInfos.prune()}export{N as GroupInfo,O as TileRenderer,B as cleanupTileRenderer};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import e from"../../../core/PooledArray.js";import{isImageryTileLayerView as t}from"./terrainUtils.js";class n{constructor(){this._queue=new e,this.remove=()=>{}}get done(){return this._queue.length===0&&(!this._last||this._last.leaf)}resetOne(e){this._queue.clear(),this._queue.push(e),this._last=void 0}reset(e=null){this._queue.clear(),e!=null&&this._queue.pushArray(e),this._last=void 0}skipSubtree(){this._last=void 0}next(){let e=this._last?.children;return e?.[0]&&this._queue.pushArray(e),this._last=this._queue.pop(),this._last}}class r{constructor(){this._q=new e}get done(){return this._q.length===0}reset(e){if(this._q.clear(),e!=null){this._q.pushArray(e);for(let e=0;e<this._q.length;++e){let t=this._q.data[e];t.leaf||this._q.pushArray(t.children)}}}next(){return this._q.pop()}}function i(e,t,n=()=>!0){if(Array.isArray(e))for(let r=0;r<e.length;r++)a(e[r],t,n);else a(e,t,n)}function a(e,t,n=()=>!0){if(t(e),!e.leaf&&n(e))for(let n of e.children)a(n,t)}function o(e,t){let n=e.extent;return!(t.xmin>n[2]||t.ymin>n[3]||t.xmax<n[0]||t.ymax<n[1])}function s(e,t,n){let r=e.surface.tilingScheme.levels[e.level].scale;return!(t&&t>0&&r>t*1.00000001||n&&n>0&&r<n*.99999999)}function c(e,t){if(t==null||t.destroyed)return!1;let n=l(t);return!(n?.fullExtent==null||!o(e,n.fullExtent)||!s(e,n.minScale,n.maxScale))}function l(e){return t(e)||e.type===`wmts-3d`?{fullExtent:e.fullExtent,minScale:e.layer.minScale,maxScale:e.layer.maxScale}:e.layer}function u(e,t){let n=e.lij,r=t.lij;return n[0]-r[0]||n[1]-r[1]||n[2]-r[2]}function d(e,t=null){return t==null||t.length===0?e.sort(f):e.sort((e,n)=>m(e,n,t))}function f(e,t){let n=e.screenDepth-t.screenDepth;if(n!==0)return n;let r=e.lij,i=t.lij;return r[0]-i[0]||r[1]-i[1]||r[2]-i[2]}function p(e,t){let n=e.screenDepth,r=t.screenDepth;return n<r?-1:n>r?1:u(e,t)}function m(e,t,n){return h(e,n)===h(t,n)?p(e,t):e?1:-1}function h(e,t){return t?.some(t=>e.intersectsExtent(t))??!1}function g(e,t){let n=e.distanceToPOI-t.distanceToPOI;if(n!==0)return n;let r=e.lij,i=t.lij;return r[0]-i[0]||r[1]-i[1]||r[2]-i[2]}function _(e,t){let n=e.length;for(let r=0;r<n;++r)e.at(r).updateDistanceToPOI(t);e.sort(g)}function v(e,t,n){let r=1,i=0,a=0;for(;e!==t;)if(r*=.5,i*=.5,a*=.5,e.lij[2]&1&&(i+=.5),e.lij[1]&1||(a+=.5),e=e.parent,e==null)throw Error(`tile was not a descendant of upsampleTile`);n.init(t,i,a,r)}function y(e){for(let t=0;t<e.length;t++){let n=e[t],r=n.parent;if(r)for(let e=0;e<4;e++){let t=r.children[e];if(t&&t!==n)return!0}}return!1}function b(e,t){if(!e||!t||e[0]===t[0])return!1;let n=e[0]<t[0],r=n?e:t,i=n?t:e,a=1<<i[0]-r[0];return Math.floor(i[1]/a)===r[1]&&Math.floor(i[2]/a)===r[2]}function x(e,t){if(t<=e[0])return[[...e]];let n=1<<t-e[0],r=[],i=e[1]*n,a=e[2]*n;for(let e=0;e<n;++e)for(let o=0;o<n;++o)r.push([t,e+i,o+a]);return r}export{r as IteratorPostorder,n as IteratorPreorder,p as compareTiles,u as compareTilesByLij,m as compareTilesWithStencil,v as computeUpsampleInfo,x as descendantsAtLevel,c as fallsWithinLayerView,y as hasLoadableSiblings,d as sortTiles,_ as sortTilesByPOI,b as tilesAreRelated,i as traverseTilesPreorder,h as usesStencil};
2
+ import e from"../../../core/PooledArray.js";import{isImageryTileLayerView as t}from"./terrainUtils.js";class n{constructor(){this._queue=new e,this.remove=()=>{}}get done(){return this._queue.length===0&&(!this._last||this._last.leaf)}resetOne(e){this._queue.clear(),this._queue.push(e),this._last=void 0}reset(e=null){this._queue.clear(),e!=null&&this._queue.pushArray(e),this._last=void 0}skipSubtree(){this._last=void 0}next(){let e=this._last?.children;return e?.[0]&&this._queue.pushArray(e),this._last=this._queue.pop(),this._last}}class r{constructor(){this._q=new e}get done(){return this._q.length===0}reset(e){if(this._q.clear(),e!=null){this._q.pushArray(e);for(let e=0;e<this._q.length;++e){let t=this._q.data[e];t.leaf||this._q.pushArray(t.children)}}}next(){return this._q.pop()}}function i(e,t,n=()=>!0){if(Array.isArray(e))for(let r=0;r<e.length;r++)a(e[r],t,n);else a(e,t,n)}function a(e,t,n=()=>!0){if(t(e),!e.leaf&&n(e))for(let n of e.children)a(n,t)}function o(e,t){let n=e.extent;return!(t.xmin>n[2]||t.ymin>n[3]||t.xmax<n[0]||t.ymax<n[1])}function s(e,t,n){let r=e.surface.tilingScheme.levels[e.level].scale;return!(t&&t>0&&r>t*1.00000001||n&&n>0&&r<n*.99999999)}function c(e,t){if(t==null||t.destroyed)return!1;let n=l(t);return!(n?.fullExtent==null||!o(e,n.fullExtent)||!s(e,n.minScale,n.maxScale))}function l(e){return t(e)||e.type===`wmts-3d`?{fullExtent:e.fullExtent,minScale:e.layer.minScale,maxScale:e.layer.maxScale}:e.layer}function u(e,t){let n=e.lij,r=t.lij;return n[0]-r[0]||n[1]-r[1]||n[2]-r[2]}function d(e,t=null){return t==null||t.length===0?e.sort(f):e.sort((e,n)=>m(e,n,t))}function f(e,t){let n=e.screenDepth-t.screenDepth;if(n!==0)return n;let r=e.lij,i=t.lij;return r[0]-i[0]||r[1]-i[1]||r[2]-i[2]}function p(e,t){let n=e.screenDepth,r=t.screenDepth;return n<r?-1:n>r?1:u(e,t)}function m(e,t,n){let r=h(e,n);return r===h(t,n)?p(e,t):r?1:-1}function h(e,t){return t?.some(t=>e.intersectsExtent(t))??!1}function g(e,t){let n=e.distanceToPOI-t.distanceToPOI;if(n!==0)return n;let r=e.lij,i=t.lij;return r[0]-i[0]||r[1]-i[1]||r[2]-i[2]}function _(e,t){let n=e.length;for(let r=0;r<n;++r)e.at(r).updateDistanceToPOI(t);e.sort(g)}function v(e,t,n){let r=1,i=0,a=0;for(;e!==t;)if(r*=.5,i*=.5,a*=.5,e.lij[2]&1&&(i+=.5),e.lij[1]&1||(a+=.5),e=e.parent,e==null)throw Error(`tile was not a descendant of upsampleTile`);n.init(t,i,a,r)}function y(e){for(let t=0;t<e.length;t++){let n=e[t],r=n.parent;if(r)for(let e=0;e<4;e++){let t=r.children[e];if(t&&t!==n)return!0}}return!1}function b(e,t){if(!e||!t||e[0]===t[0])return!1;let n=e[0]<t[0],r=n?e:t,i=n?t:e,a=1<<i[0]-r[0];return Math.floor(i[1]/a)===r[1]&&Math.floor(i[2]/a)===r[2]}function x(e,t){if(t<=e[0])return[[...e]];let n=1<<t-e[0],r=[],i=e[1]*n,a=e[2]*n;for(let e=0;e<n;++e)for(let o=0;o<n;++o)r.push([t,e+i,o+a]);return r}export{r as IteratorPostorder,n as IteratorPreorder,p as compareTiles,u as compareTilesByLij,m as compareTilesWithStencil,v as computeUpsampleInfo,x as descendantsAtLevel,c as fallsWithinLayerView,y as hasLoadableSiblings,d as sortTiles,_ as sortTilesByPOI,b as tilesAreRelated,i as traverseTilesPreorder,h as usesStencil};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../../../core/Accessor.js";import{EventEmitter as n}from"../../../../core/Evented.js";import"../../../../core/has.js";import{disposeMaybe as r,removeMaybe as i}from"../../../../core/maybe.js";import{generateUID as a}from"../../../../core/uid.js";import{property as o,subclass as s}from"../../../../core/accessorSupport/decorators.js";import{exactEquals as c,set as l}from"../../../../core/libs/gl-matrix-2/math/vec4.js";import{ZEROS as u,create as d}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{textTextureAtlas as f}from"./testUtils.js";import{applyTextureResizeModuloCeil as p}from"./textureUtils.js";import{TaskPriority as m}from"../../../support/Scheduler.js";import{Yield as h}from"../../../support/Yield.js";import g from"../../../webgl/Texture.js";import{TextureDescriptor as _}from"../../../webgl/TextureDescriptor.js";const v=4096;let y=class extends t{constructor(e){super(e),this.id=a(),this.events=new n,this._texture=null,this._atlas=new C(256,256),this._needsRepack=!1,this._canRepack=!0,this._elementsToRender=new Map,this._elements=new Map,this._uvCallbacks=new Map,this.updating=!1}initialize(){this._canvas=document.createElement(`canvas`),this._canvas.setAttribute(`id`,`textAtlasCanvas`),this._canvas.setAttribute(`style`,`display:none`),this._ctx=this._canvas.getContext(`2d`),this._stage=this.view.stage,this._stage.addTexture(this),this._updateCanvasElementSize(this._atlas),this._reset()}unload(){this._texture=r(this._texture),this._frameWorker=i(this._frameWorker),this.updating=!1,this.events.emit(`unloaded`)}get loaded(){return this._texture!=null}get texture(){return this._texture}static get maxSize(){return T=f.stableRendering?b:0,[v-b-T,v-b-T-x]}load(e){if(this._texture)return this._texture;let t=new _;return t.wrapMode=33071,t.samplingMode=9987,t.hasMipmap=!0,t.preMultiplyAlpha=!0,t.maxAnisotropy=e.parameters.maxMaxAnisotropy,this._texture=new g(e,t,this._canvas),this._frameWorker=this.view.resourceController.scheduler.registerTask(m.TEXT_TEXTURE_ATLAS,this),this.setDirty(),this._texture}dispose(){this._elements.clear(),this._elementsToRender.clear(),this._frameWorker=i(this._frameWorker),this._texture&&=(this._stage.removeTexture(this),r(this._texture)),this._canvas.width=0,this._canvas.height=0,this._canvas=null,this._ctx=null}_updateCanvasElementSize(e){this._canvas.width=e.width,this._canvas.height=e.height}_resizeAtlas(e,t){let{width:n,height:r}=this._atlas;(n!==e||r!==t)&&(this._atlas.width=e,this._atlas.height=t,this._texture?.resize(e,t),this._texture?.updateData(0,0,0,n,r,this._canvas),this._updateCanvasElementSize(this._atlas),this._elements.forEach(e=>this._uvCallbacks.get(e.textRenderer.key)?.forEach(t=>t(e.uv))),this._reset())}_reset(){this._elementsToRender.clear(),this._atlas.reset(),this._needsRepack=!0,this.setDirty()}_addAtlasElement(e,t,n,r){let i=this._atlas;if(i.width<n||i.height<r)return!1;let a=i.cursors.get(r);if(!a){if(i.height<i.nextY+r)return!1;a=[new w(i.nextY)],i.cursors.set(r,a),i.nextY+=r}let o=a.find(e=>i.width>=e.x+n);if(o==null){if(i.height<i.nextY+r)return!1;o=new w(i.nextY),i.nextY+=r,a.push(o)}return e.setNewPosition(o),this._elements.set(t,e),this._elementsToRender.set(t,e),o.x+=n,!0}_ensureCallbacks(e){let t=this._uvCallbacks.get(e);if(t)return t;let n=new Set;return this._uvCallbacks.set(e,n),n}_addCallback(e,t){this._ensureCallbacks(e).add(t)}_removeCallback(e,t){let n=this._uvCallbacks.get(e);return n?.delete(t)&&n.size===0?(this._uvCallbacks.delete(e),!0):!1}_processAddition(e){let t=e.textRenderer.key;if(this._needsRepack){this._elements.set(t,e);return}let n=this._atlas,r=e.textRenderer.renderedWidth,i=e.textRenderer.renderedHeight,a=r+b,o=i+b+x;if(!this._addAtlasElement(e,t,a,o)){if(this._canRepack)this._reset();else if(n.width<a){let e=p(Math.max(a,n.width*1.5),v);this._resizeAtlas(e,n.height)}else{let e=n.nextY+o,t=p(Math.max(e,n.height*1.5),v);if(t>n.height)this._resizeAtlas(n.width,t);else if(n.width<v){let e=p(n.width*1.5,v);this._resizeAtlas(e,n.height)}}this._elements.set(t,e)}}_renderElement(e){let t=e.commitNewPosition(),n=e.textRenderer;this._ctx.clearRect(t[0]-b,t[1]-b,n.renderedWidth+2*b,n.renderedHeight+2*b),n.render(this._ctx,t[0],t[1]),this._uvCallbacks.get(n.key)?.forEach(t=>t(e.uv))}get readyToRun(){return this.updating}runTask(e){if(this._texture==null)return h;for(;this._needsRepack&&(this._canRepack||this._atlas.height<v&&this._atlas.height<v);){this._canRepack=this._needsRepack=!1;let t=this._elements;this._elements=new Map,t.forEach(e=>this._processAddition(e)),e.madeProgress()}if(this._elementsToRender.size>0){for(let[t,n]of this._elementsToRender){if(e.done)break;this._renderElement(n),this._elementsToRender.delete(t),e.madeProgress()}this._texture.setData(this._canvas)}this.updating=this._elementsToRender.size>0}addText(e,t){let n=e.key;this._addCallback(n,t);let r=this._elements.get(n);return r?c(r.uv,u)||t(r.uv):(r=new S(e),this._processAddition(r),this.setDirty()),{remove:()=>this._removeText(e,t)}}_removeText(e,t){let n=e.key;this._elements.get(n)&&this._removeCallback(n,t)&&(this._elements.delete(n),this._elementsToRender.delete(n),this._canRepack=!0)}setDirty(){this._texture&&(this.updating=!0)}get test(){}get usedMemory(){return(this._texture?.usedMemory??0)+(this._canvas?.width??0)*(this._canvas?.height??0)*4}};e([o({constructOnly:!0})],y.prototype,`view`,void 0),e([o({type:Boolean})],y.prototype,`updating`,void 0),y=e([s(`esri.views.3d.webgl-engine.lib.TextTextureAtlas`)],y);const b=2,x=2;class S{constructor(e){this.textRenderer=e,this._uv=d(),this._newPosition=[0,0]}get uv(){if(this._xOffset==null||this._yOffset==null)return u;let{renderedWidth:e,renderedHeight:t}=this.textRenderer;return l(this._uv,this._xOffset,this._yOffset+t,this._xOffset+e,this._yOffset)}setNewPosition(e){this._newPosition[0]=e.x,this._newPosition[1]=e.y}commitNewPosition(){return this._xOffset=this._newPosition[0],this._yOffset=this._newPosition[1],this._newPosition}get xOffset(){return this._xOffset}get yOffset(){return this._yOffset}}class C{constructor(e,t){this.width=e,this.height=t,this.cursors=new Map,this.nextY=0}reset(){this.cursors.clear(),this.nextY=T}}class w{constructor(e){this.y=e,this.x=T}}let T=0;export{y as TextTextureAtlas};
2
+ import{__decorate as e}from"tslib";import t from"../../../../core/Accessor.js";import{EventEmitter as n}from"../../../../core/Evented.js";import"../../../../core/has.js";import{disposeMaybe as r,removeMaybe as i}from"../../../../core/maybe.js";import{generateUID as a}from"../../../../core/uid.js";import{property as o,subclass as s}from"../../../../core/accessorSupport/decorators.js";import{exactEquals as c,set as l}from"../../../../core/libs/gl-matrix-2/math/vec4.js";import{ZEROS as u,create as d}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{textTextureAtlas as f}from"./testUtils.js";import{applyTextureResizeModuloCeil as p}from"./textureUtils.js";import{TaskPriority as m}from"../../../support/Scheduler.js";import{Yield as h}from"../../../support/Yield.js";import g from"../../../webgl/Texture.js";import{TextureDescriptor as _}from"../../../webgl/TextureDescriptor.js";const v=4096;let y=class extends t{constructor(e){super(e),this.id=a(),this.events=new n,this._texture=null,this._atlas=new C(256,256),this._needsRepack=!1,this._needsCleanup=!1,this._canRepack=!0,this._elementsToRender=new Map,this._elements=new Map,this._uvCallbacks=new Map,this.updating=!1}initialize(){this._stage=this.view.stage,this._stage.addTexture(this),this._updateCanvasElementSize(this._atlas),this._reset()}unload(){this._texture=r(this._texture),this._frameWorker=i(this._frameWorker),this.updating=!1,this.events.emit(`unloaded`)}get loaded(){return this._texture!=null}get texture(){return this._texture}static get maxSize(){return T=f.stableRendering?b:0,[v-b-T,v-b-T-x]}load(e){if(this._texture)return this._texture;let t=new _;return t.wrapMode=33071,t.samplingMode=9987,t.hasMipmap=!0,t.preMultiplyAlpha=!0,t.maxAnisotropy=e.parameters.maxMaxAnisotropy,this._texture=new g(e,t,this._canvas),this._frameWorker=this.view.resourceController.scheduler.registerTask(m.TEXT_TEXTURE_ATLAS,this),this.setDirty(),this._texture}dispose(){this._elements.clear(),this._elementsToRender.clear(),this._frameWorker=i(this._frameWorker),this._texture&&=(this._stage.removeTexture(this),r(this._texture)),this._canvas.width=0,this._canvas.height=0,this._canvas=null,this._ctx=null}_updateCanvasElementSize(e){let t=this._canvas;this._canvas=document.createElement(`canvas`),this._canvas.setAttribute(`id`,`textAtlasCanvas`),this._canvas.setAttribute(`style`,`display:none`),this._canvas.width=e.width,this._canvas.height=e.height,this._ctx=this._canvas.getContext(`2d`),t&&(this._ctx.drawImage(t,0,0),t.width=t.height=0)}_resizeAtlas(e,t){(this._atlas.width!==e||this._atlas.height!==t)&&(this._atlas.width=e,this._atlas.height=t,this._reset())}_reset(){this._needsCleanup||=this._elements.size>0||this._atlas.cursors.size>0,this._elementsToRender.clear(),this._atlas.reset(),this._needsRepack=!0,this.setDirty()}_addAtlasElement(e,t,n,r){let i=this._atlas;if(i.width<n||i.height<r)return!1;let a=i.cursors.get(r);if(!a){if(i.height<i.nextY+r)return!1;a=[new w(i.nextY)],i.cursors.set(r,a),i.nextY+=r}let o=a.find(e=>i.width>=e.x+n);if(o==null){if(i.height<i.nextY+r)return!1;o=new w(i.nextY),i.nextY+=r,a.push(o)}return e.setNewPosition(o),this._elements.set(t,e),this._elementsToRender.set(t,e),o.x+=n,!0}_ensureCallbacks(e){let t=this._uvCallbacks.get(e);if(t)return t;let n=new Set;return this._uvCallbacks.set(e,n),n}_addCallback(e,t){this._ensureCallbacks(e).add(t)}_removeCallback(e,t){let n=this._uvCallbacks.get(e);return n?.delete(t)&&n.size===0?(this._uvCallbacks.delete(e),!0):!1}_processAddition(e){let t=e.textRenderer.key;if(this._needsRepack){this._elements.set(t,e);return}let n=this._atlas,r=e.textRenderer.renderedWidth,i=e.textRenderer.renderedHeight,a=r+b,o=i+b+x;if(!this._addAtlasElement(e,t,a,o)){if(this._canRepack)this._reset();else if(n.width<a){let e=p(Math.max(a,n.width*1.5),v);this._resizeAtlas(e,n.height)}else{let e=n.nextY+o,t=p(Math.max(e,n.height*1.5),v);if(t>n.height)this._resizeAtlas(n.width,t);else if(n.width<v){let e=p(n.width*1.5,v);this._resizeAtlas(e,n.height)}}this._elements.set(t,e)}}_renderElement(e){let t=e.commitNewPosition(),n=e.textRenderer;this._ctx.clearRect(t[0]-b,t[1]-b,n.renderedWidth+2*b,n.renderedHeight+2*b),n.render(this._ctx,t[0],t[1]),this._uvCallbacks.get(n.key)?.forEach(t=>t(e.uv))}_clearUnusedPixels(){let e=new Path2D,t=!1;for(let n of this._elements.values()){let{xOffset:r,yOffset:i,textRenderer:a}=n;r!=null&&i!=null&&a.renderedWidth&&a.renderedHeight&&(e.rect(r,i,a.renderedWidth,a.renderedHeight),t=!0)}t?(this._ctx.save(),this._ctx.globalCompositeOperation=`destination-in`,this._ctx.fillStyle=`#000`,this._ctx.fill(e),this._ctx.restore()):this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this._needsCleanup=!1}get readyToRun(){return this.updating}runTask(e){if(this._texture==null)return h;for(;this._needsRepack&&(this._canRepack||this._atlas.height<v&&this._atlas.height<v);){this._canRepack=this._needsRepack=!1;let t=this._elements;this._elements=new Map,t.forEach(e=>this._processAddition(e)),e.madeProgress()}let t=this._canvas.height,n=0,{width:r,height:i}=this._atlas;(this._canvas.width!==r||this._canvas.height!==i)&&(this._updateCanvasElementSize(this._atlas),this._texture.clearMipmap(),this._texture.resize(r,i),t=0,n=i,this._elements.forEach(e=>this._uvCallbacks.get(e.textRenderer.key)?.forEach(t=>t(e.uv))));for(let[r,i]of this._elementsToRender){if(e.done)break;this._renderElement(i);let a=i.yOffset;t=Math.min(t,Math.max(0,a-b)),n=Math.max(n,Math.min(this._canvas.height,a+i.textRenderer.renderedHeight+b)),this._elementsToRender.delete(r),e.madeProgress()}this._needsCleanup&&this._elementsToRender.size===0&&(this._clearUnusedPixels(),t=0,n=this._canvas.height),t<n&&(this._texture.updateData(0,0,t,this._canvas.width,n-t,this._canvas,t),this._texture.generateMipmap()),this.updating=this._elementsToRender.size>0}addText(e,t){let n=e.key;this._addCallback(n,t);let r=this._elements.get(n);return r?c(r.uv,u)||t(r.uv):(r=new S(e),this._processAddition(r),this.setDirty()),{remove:()=>this._removeText(e,t)}}_removeText(e,t){let n=e.key;this._elements.get(n)&&this._removeCallback(n,t)&&(this._elements.delete(n),this._elementsToRender.delete(n),this._canRepack=!0)}setDirty(){this._texture&&(this.updating=!0)}get test(){}get usedMemory(){return(this._texture?.usedMemory??0)+(this._canvas?.width??0)*(this._canvas?.height??0)*4}};e([o({constructOnly:!0})],y.prototype,`view`,void 0),e([o({type:Boolean})],y.prototype,`updating`,void 0),y=e([s(`esri.views.3d.webgl-engine.lib.TextTextureAtlas`)],y);const b=2,x=2;class S{constructor(e){this.textRenderer=e,this._uv=d(),this._newPosition=[0,0]}get uv(){if(this._xOffset==null||this._yOffset==null)return u;let{renderedWidth:e,renderedHeight:t}=this.textRenderer;return l(this._uv,this._xOffset,this._yOffset+t,this._xOffset+e,this._yOffset)}setNewPosition(e){this._newPosition[0]=e.x,this._newPosition[1]=e.y}commitNewPosition(){return this._xOffset=this._newPosition[0],this._yOffset=this._newPosition[1],this._newPosition}get xOffset(){return this._xOffset}get yOffset(){return this._yOffset}}class C{constructor(e,t){this.width=e,this.height=t,this.cursors=new Map,this.nextY=0}reset(){this.cursors.clear(),this.nextY=T}}class w{constructor(e){this.y=e,this.x=T}}let T=0;export{y as TextTextureAtlas};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import{isSome as t}from"../../../../../core/arrayUtils.js";import n from"../../../../../core/Error.js";import{someMap as r,getOrCreateMapValue as i}from"../../../../../core/MapUtils.js";import{destroyMaybe as a}from"../../../../../core/maybe.js";import{isAborted as o,throwIfAborted as s}from"../../../../../core/promiseUtils.js";import{property as c,subclass as l}from"../../../../../core/accessorSupport/decorators.js";import{create as u}from"../../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{subtract as d,dot as f,transformMat4 as p}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as m}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as h,freeze as g}from"../../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{debugFlags as _}from"../../../support/debugFlags.js";import{glLayout as v}from"../../../support/buffer/glUtil.js";import y from"../../../webgl/RenderCamera.js";import{isColor as b}from"../../core/shaderLibrary/ShaderOutput.js";import{AsyncRenderPlugin as x}from"../../effects/RenderPlugin.js";import{getEmissions as S}from"../../effects/emissive/emissions.js";import{DepthRange as C}from"../DepthRange.js";import{assert as w}from"../Util.js";import{InstanceData as T}from"./InstanceData.js";import{InstanceOctree as E}from"./InstanceOctree.js";import{LevelSelector as D}from"./LevelSelector.js";import{LodLevel as O}from"./LodLevel.js";import{getRenderInstanceDataLayout as k,RenderInstanceData as A}from"./RenderInstanceData.js";import{colorMixModes as j}from"../../materials/internal/MaterialUtil.js";import{encodeDoubleVec3 as M}from"../../materials/renderers/utils.js";import{DefaultMaterialDrawParameters as N}from"../../shaders/DefaultMaterialTechnique.js";import{defaultHighlightName as P}from"../../../../support/HighlightDefaults.js";import{TaskPriority as F,noBudget as I}from"../../../../support/Scheduler.js";import{bindVertexBufferLayout as L}from"../../../../webgl/Util.js";import{fromLayout as R}from"../../../../webgl/VertexAttributeLocations.js";const z=e=>{let t=e.baseBoundingSphere.radius,n=e.levels.map(e=>e.minScreenSpaceRadius);return new D(t,n)};let B=class extends x{constructor(e,t){super(e),this.type=3,this.isGround=!1,this._levels=[],this._defaultRenderInstanceData=[],this._highlightRenderInstanceDatas=new Map,this._instanceIndex=0,this._cycleStartIndex=0,this._slicePlane=!1,this._camera=new y,this._updateCyclesWithStaticCamera=-1,this._needFullCycle=!1,this.produces=new Map([[2,e=>this._produces(e)],[4,e=>this._hasTransparentLevels()?this._produces(e):!1]]),this._instanceData=new T({shaderTransformation:e.shaderTransformation},e.symbol.materialParameters),this.addHandles(t.registerTask(F.LOD_RENDERER,this))}initialize(){this._instanceBufferLayout=k(this.symbol.materialParameters),this._glInstanceBufferLayout=v(this._instanceBufferLayout,1),this.addHandles([this._instanceData.events.on(`instances-changed`,()=>this._requestUpdateCycle()),this._instanceData.events.on(`instance-transform-changed`,({index:e})=>{this._requestUpdateCycle(),this.metadata.notifyGraphicGeometryChanged(e)}),this._instanceData.events.on(`instance-visibility-changed`,({index:e})=>{this._requestUpdateCycle(!0),this.metadata.notifyGraphicVisibilityChanged(e)}),this._instanceData.events.on(`instance-highlight-changed`,()=>this._requestUpdateCycle(!0))])}get _allRenderInstanceData(){return[this._defaultRenderInstanceData,...this._highlightRenderInstanceDatas.values()]}get _allRenderInstanceDataExceptHighlightShadow(){let e=[this._defaultRenderInstanceData];for(let t of this._highlightRenderInstanceDatas)t[0]!==P&&e.push(t[1]);return e}hasHighlight(e){return this._highlightRenderInstanceDatas.has(e)}get _enableLevelSelection(){return this.symbol.levels.length>1}get levels(){return this._levels}get baseBoundingBox(){return this._levels[this._levels.length-1].boundingBox}get baseBoundingSphere(){return this._levels[this._levels.length-1].boundingSphere}get baseMaterial(){return this._levels[this._levels.length-1].components[0].material}get slicePlaneEnabled(){return this._slicePlane}set slicePlaneEnabled(e){this._slicePlane=e}get layerViewUid(){return this.metadata.layerViewUid}get instanceData(){return this._instanceData}get emissions(){return S(this._levels)}get usedMemory(){return this._allRenderInstanceData.reduce((e,t)=>t.reduce((e,t)=>e+t.usedMemory,e),this._levels.reduce((e,t)=>e+t.components.reduce((e,t)=>e+t.usedMemory,0),0))}get renderStats(){let e=this._instanceData.size,t=[];return this._levels.forEach((e,n)=>{let r=this._allRenderInstanceData[0][n].size+this._allRenderInstanceData[1][n].size,i=e.triangleCount;t.push({renderedInstances:r,renderedTriangles:r*i,trianglesPerInstance:i})}),{totalInstances:e,renderedInstances:t.reduce((e,t)=>e+t.renderedInstances,0),renderedTriangles:t.reduce((e,t)=>e+t.renderedTriangles,0),levels:t}}_createRenderInstanceDataArray(){let{rctx:e}=this._context.renderContext;return this.symbol.levels.map(t=>new A(e,this._instanceBufferLayout))}async initializeRenderContext(e,n){this._context=e,this._defaultRenderInstanceData=this._createRenderInstanceDataArray();let r=await Promise.allSettled(this.symbol.levels.map(t=>O.create(e,t,n))),i=r.map(e=>e.status===`fulfilled`?e.value:null).filter(t);if(o(n)||i.length!==r.length){i.forEach(e=>e.destroy()),s(n);for(let e of r)if(e.status===`rejected`)throw e.reason}this._levels=i,this._levelSelector=z(this)}uninitializeRenderContext(){this._invalidateOctree(),this._levels.forEach(e=>e.destroy()),this._defaultRenderInstanceData.forEach(e=>e.destroy()),this._highlightRenderInstanceDatas.forEach(e=>e.forEach(e=>e.destroy()))}_hasTransparentLevels(){return this._levels.some(e=>e.components.some(e=>e.material.produces.get(4)?.(0)))}hasHighlights(){return r(this._highlightRenderInstanceDatas,e=>e.some(e=>e.size>0))}_produces(e){return(e!==10||this.hasHighlights())&&(e!==6||this.hasHighlight(P))}prepareRender(e){if(!_.LOD_INSTANCE_RENDERER_DISABLE_UPDATES){if(this._enableLevelSelection){let t=e.bind.contentCamera.equals(this._camera);this._camera.copyFrom(e.bind.contentCamera),t||this._requestUpdateCycle()}this._needFullCycle&&=(this.runTask(I),!1)}}acquireTechniques(e){if(!this.baseMaterial.visible||!this.baseMaterial.isVisibleForOutput(e.output))return null;let t=this._getInstanceDatas(e);if(!t)return null;let n=[],r=this.levels;return t.forEach(t=>r.forEach(({components:r},i)=>r.forEach(r=>n.push(this._beginComponent(e,t[i],r))))),n}render(e,t){let n=this._getInstanceDatas(e);if(!n||t==null)return;let r=0,i=this.levels;n.forEach(n=>i.forEach(({components:i},a)=>i.forEach(i=>this._renderComponent(e,t[r++],n[a],i,a)))),e.rctx.unbindBuffer(34962),e.rctx.bindVAO(null)}_getInstanceDatas(e){let{output:t,bind:n}=e,r=t===10,i=t===6,a=!r&&!i,o=t!==7;if(a)return o?this._allRenderInstanceData:this._allRenderInstanceDataExceptHighlightShadow;let{_highlightRenderInstanceDatas:s}=this;if(o){if(r){let e=n.highlight?.name;if(!e)return null;let t=s.get(e);return t?[t]:null}let e=s.get(P);return i?e?[e]:null:Array.from(s.values())}return null}intersectRay(e,t,n,r){if(!this.baseMaterial.visible||this._octree==null)return;let i=m();d(i,r,n);let a=i=>{let a=this._setupIntersectableInstance(e,i);a&&(p(K,n,e.transform.inverse),p(q,r,e.transform.inverse),a.intersect(e,t,K,q,i,this.metadata,this._levels.length))};this.baseMaterial.parameters.verticalOffset?this._octree.forEach(a):this._octree.forEachAlongRay(n,i,a)}*intersectScreenPolygon(e,t){if(!this.baseMaterial.visible||this._octree==null)return;let n=this.baseMaterial.parameters.verticalOffset?this._octree.values():this._octree.intersectingFrustumValues(t.broadPhaseFrustum,e=>!!(this._instanceData.getState(e)&4));for(let r of n)yield*this._intersectScreenPolygonInstance(e,t,r)}*_intersectScreenPolygonInstance(e,t,n){let r=this._setupIntersectableInstance(e,n);r&&(yield*r.intersectScreenPolygon(e,t,n,this.metadata,this._levels.length))}_setupIntersectableInstance(e,t){let n=this._instanceData.getState(t);if(!(n&4))return null;let r=this._instanceData.getLodLevel(t),i=this._levels.length;w(!!(n&18),`invalid instance state`),w(r>=0&&r<i,`invaid lod level`);let a=this._levels[r];return a==null?null:(this._instanceData.getCombinedModelTransform(t,G),e.transform.set(G),a)}notifyShaderTransformationChanged(){this._invalidateOctree(),this._requestUpdateCycle()}get _octree(){if(this._octreeCached==null){let e=this._instanceData,t=e.view?.state;if(!t)return null;this._octreeCached=new E(e,this.baseBoundingSphere);for(let n=0;n<e.capacity;++n)t.get(n)&18&&this._octreeCached.addInstance(n)}return this._octreeCached}_invalidateOctree(){this._octreeCached=a(this._octreeCached)}queryDepthRange(e){if(this._octree==null)return new C;let t=e.viewForward,n=this._octree.findClosest(t,1,e.frustum),r=this._octree.findClosest(t,-1,e.frustum);if(n==null||r==null)return new C;let i=e.eye,a=this._instanceData.view;a.boundingSphere.getVec(n,W),d(W,W,i);let o=f(W,t)-W[3];a.boundingSphere.getVec(r,W),d(W,W,i);let s=f(W,t)+W[3];return new C(o,s)}_requestUpdateCycle(e=!1){this._updateCyclesWithStaticCamera=-1,this._cycleStartIndex=this._instanceIndex,e&&(this._needFullCycle=!0,this._context.requestRender())}_startUpdateCycle(){this._updateCyclesWithStaticCamera++,this._allRenderInstanceData.forEach(e=>e.forEach(e=>e.startUpdateCycle()))}get readyToRun(){return this._instanceData.size>0&&this._updateCyclesWithStaticCamera<1}runTask(e){let{_enableLevelSelection:t,_camera:r,_levelSelector:a}=this;this._allRenderInstanceData.forEach(e=>e.forEach(e=>e.beginUpdate()));let o=this._instanceData,s=o.view,c=o.size,l=o.capacity,u=this._instanceIndex,d=Math.ceil(l/500),{_highlightRenderInstanceDatas:f}=this;for(let p=0;p<c&&!e.done;++p){u===this._cycleStartIndex&&this._startUpdateCycle();let p=s.state.get(u),m=0;if(!(p&1)){u=u+1===l?0:u+1,c++;continue}let h=s.lodLevel.get(u);if(p&2&&this._defaultRenderInstanceData[h].freeTail(),p&16){let e=o.geHighlightOptionsPrev(u);if(e){let t=f.get(e);if(t)t[h].freeTail(),t.every(e=>e.isEmpty)&&(t.forEach(e=>e.destroy()),f.delete(e));else throw new n(`internal:lod-renderer`,`Internal error in lodRenderer`)}}if(p&32)o.freeInstance(u);else if(p&4){let e=0;if(t&&(s.modelOrigin.getVec(u,U),e=a.selectLevel(U,o.getCombinedMedianScaleFactor(u),r)),m=p&-83,e>=0){if(p&8){let t=o.getHighlightName(u);if(t){let r=i(f,t,()=>{let e=this._createRenderInstanceDataArray();return e.forEach(e=>e.beginUpdate()),e});if(e>=r.length)throw new n(`internal:lod-renderer`,`LodRenderer internal error - missing lodLevel ${e}`);V(r[e],s,u)}m|=16}else V(this._defaultRenderInstanceData[e],s,u),m|=2}s.state.set(u,m),s.lodLevel.set(u,e)}else m=p&-83,s.state.set(u,m);let g=!!(p&18),_=!!(m&18);this._octreeCached!=null&&(!g&&_?this._octreeCached.addInstance(u):g&&!_?this._octreeCached.removeInstance(u):g&&_&&p&64&&(this._octreeCached.removeInstance(u),this._octreeCached.addInstance(u))),u=u+1===l?0:u+1,u%d===0&&e.madeProgress(),g!==_&&this.metadata.notifyGraphicVisibilityChanged(u),_&&p&64&&this.metadata.notifyGraphicGeometryChanged(u)}this._instanceIndex=u,this._allRenderInstanceData.forEach(e=>e.forEach(e=>e.endUpdate())),this._context.requestRender()}_beginComponent(e,t,n){return t.size===0?null:n.glMaterialLoader.load(e.rctx,e.bind.slot,e.output)?.beginSlot(e.bind)}_renderComponent(e,t,n,r,i){if(!t)return;let{bind:a,rctx:o}=e,s=o.bindTechnique(t,a,r.material.parameters,Y),c=this._glInstanceBufferLayout;s.assertCompatibleVertexAttributeLocations(r.vao,R(c)),o.bindVAO(r.vao),_.LOD_INSTANCE_RENDERER_COLORIZE_BY_LEVEL&&b(e.output)&&(s.setUniform4fv(`externalColor`,J[Math.min(i,J.length-1)]),s.setUniform1i(`symbolColorMixMode`,j.replace));let l=n.capacity,u=n.headIndex,d=n.tailIndex,f=n.firstIndex,p=(e,i)=>{L(o,s.locations,n.buffer,e),o.drawArraysInstanced(t.primitiveType,0,r.numVertices,i-e)};r.material.transparent&&f!=null?u>d?(w(f>=d&&f<=u,`invalid firstIndex`),p(f,u),p(d,f)):u<d&&(f<=u?(w(f>=0&&f<=u,`invalid firstIndex`),p(f,u),p(d,l),p(0,f)):(w(f>=d&&f<=l,`invalid firstIndex`),p(f,l),p(0,u),p(d,f))):u>d?p(d,u):u<d&&(p(0,u),p(d,l))}};e([c({constructOnly:!0})],B.prototype,`symbol`,void 0),e([c({constructOnly:!0})],B.prototype,`metadata`,void 0),e([c({constructOnly:!0})],B.prototype,`shaderTransformation`,void 0),e([c()],B.prototype,`_instanceData`,void 0),e([c()],B.prototype,`_cycleStartIndex`,void 0),e([c({readOnly:!0})],B.prototype,`_enableLevelSelection`,null),e([c()],B.prototype,`_updateCyclesWithStaticCamera`,void 0),e([c({readOnly:!0})],B.prototype,`readyToRun`,null),B=e([l(`esri.views.3d.webgl-engine.lib.lodRendering.LodRenderer`)],B);function V(e,t,n){let r=e.allocateHead();H(t,n,e.view,r)}function H(e,t,n,r){M(e.modelOrigin,t,n.modelOriginHi,n.modelOriginLo,r),n.model.copyFrom(r,e.model,t),n.modelNormal.copyFrom(r,e.modelNormal,t),e.color&&n.color&&n.color.copyFrom(r,e.color,t),e.olidColor&&n.olidColor&&n.olidColor.copyFrom(r,e.olidColor,t),e.featureAttribute&&n.featureAttribute&&n.featureAttribute.copyFrom(r,e.featureAttribute,t)}const U=m(),W=h(),G=u(),K=m(),q=m(),J=[g(1,0,1,1),g(0,0,1,1),g(0,1,0,1),g(1,1,0,1),g(1,0,0,1)],Y=new N;export{B as LodRenderer};
2
+ import{__decorate as e}from"tslib";import{isSome as t}from"../../../../../core/arrayUtils.js";import n from"../../../../../core/Error.js";import{someMap as r,getOrCreateMapValue as i}from"../../../../../core/MapUtils.js";import{destroyMaybe as a}from"../../../../../core/maybe.js";import{isAborted as o,throwIfAborted as s}from"../../../../../core/promiseUtils.js";import{property as c,subclass as l}from"../../../../../core/accessorSupport/decorators.js";import{create as u}from"../../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{subtract as d,dot as f,transformMat4 as p}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as m}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as h,freeze as g}from"../../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{debugFlags as _}from"../../../support/debugFlags.js";import{glLayout as v}from"../../../support/buffer/glUtil.js";import y from"../../../webgl/RenderCamera.js";import{isColor as b}from"../../core/shaderLibrary/ShaderOutput.js";import{AsyncRenderPlugin as x}from"../../effects/RenderPlugin.js";import{getEmissions as S}from"../../effects/emissive/emissions.js";import{DepthRange as C}from"../DepthRange.js";import{assert as w}from"../Util.js";import{InstanceData as T}from"./InstanceData.js";import{InstanceOctree as E}from"./InstanceOctree.js";import{LevelSelector as D}from"./LevelSelector.js";import{LodLevel as O}from"./LodLevel.js";import{getRenderInstanceDataLayout as k,RenderInstanceData as A}from"./RenderInstanceData.js";import{colorMixModes as j}from"../../materials/internal/MaterialUtil.js";import{encodeDoubleVec3 as M}from"../../materials/renderers/utils.js";import{DefaultMaterialDrawParameters as N}from"../../shaders/DefaultMaterialTechnique.js";import{defaultHighlightName as P}from"../../../../support/HighlightDefaults.js";import{TaskPriority as F,noBudget as I}from"../../../../support/Scheduler.js";import{bindVertexBufferLayout as L}from"../../../../webgl/Util.js";import{fromLayout as R}from"../../../../webgl/VertexAttributeLocations.js";const z=e=>{let t=e.baseBoundingSphere.radius,n=e.levels.map(e=>e.minScreenSpaceRadius);return new D(t,n)};let B=class extends x{constructor(e,t){super(e),this.type=3,this.isGround=!1,this._levels=[],this._defaultRenderInstanceData=[],this._highlightRenderInstanceDatas=new Map,this._instanceIndex=0,this._cycleStartIndex=0,this._slicePlane=!1,this._camera=new y,this._updateCyclesWithStaticCamera=-1,this._needFullCycle=!1,this.produces=new Map([[2,e=>this._produces(e)],[4,e=>this._hasTransparentLevels()?this._produces(e):!1]]),this._instanceData=new T({shaderTransformation:e.shaderTransformation},e.symbol.materialParameters),this.addHandles(t.registerTask(F.LOD_RENDERER,this))}initialize(){this._instanceBufferLayout=k(this.symbol.materialParameters),this._glInstanceBufferLayout=v(this._instanceBufferLayout,1),this.addHandles([this._instanceData.events.on(`instances-changed`,()=>this._requestUpdateCycle()),this._instanceData.events.on(`instance-transform-changed`,({index:e})=>{this._requestUpdateCycle(),this.metadata.notifyGraphicGeometryChanged(e)}),this._instanceData.events.on(`instance-visibility-changed`,({index:e})=>{this._requestUpdateCycle(!0),this.metadata.notifyGraphicVisibilityChanged(e)}),this._instanceData.events.on(`instance-highlight-changed`,()=>this._requestUpdateCycle(!0))])}get _allRenderInstanceData(){return[this._defaultRenderInstanceData,...this._highlightRenderInstanceDatas.values()]}get _allRenderInstanceDataExceptHighlightShadow(){let e=[this._defaultRenderInstanceData];for(let t of this._highlightRenderInstanceDatas)t[0]!==P&&e.push(t[1]);return e}hasHighlight(e){return this._highlightRenderInstanceDatas.has(e)}get _enableLevelSelection(){return this.symbol.levels.length>1}get levels(){return this._levels}get baseBoundingBox(){return this._levels[this._levels.length-1].boundingBox}get baseBoundingSphere(){return this._levels[this._levels.length-1].boundingSphere}get baseMaterial(){return this._levels[this._levels.length-1].components[0].material}get slicePlaneEnabled(){return this._slicePlane}set slicePlaneEnabled(e){this._slicePlane=e}get layerViewUid(){return this.metadata.layerViewUid}get instanceData(){return this._instanceData}get emissions(){return this._allRenderInstanceData.some(e=>e.some(({size:e})=>e>0))?S(this._levels):0}get usedMemory(){return this._allRenderInstanceData.reduce((e,t)=>t.reduce((e,t)=>e+t.usedMemory,e),this._levels.reduce((e,t)=>e+t.components.reduce((e,t)=>e+t.usedMemory,0),0))}get renderStats(){let e=this._instanceData.size,t=[];return this._levels.forEach((e,n)=>{let r=this._allRenderInstanceData[0][n].size+this._allRenderInstanceData[1][n].size,i=e.triangleCount;t.push({renderedInstances:r,renderedTriangles:r*i,trianglesPerInstance:i})}),{totalInstances:e,renderedInstances:t.reduce((e,t)=>e+t.renderedInstances,0),renderedTriangles:t.reduce((e,t)=>e+t.renderedTriangles,0),levels:t}}_createRenderInstanceDataArray(){let{rctx:e}=this._context.renderContext;return this.symbol.levels.map(t=>new A(e,this._instanceBufferLayout))}async initializeRenderContext(e,n){this._context=e,this._defaultRenderInstanceData=this._createRenderInstanceDataArray();let r=await Promise.allSettled(this.symbol.levels.map(t=>O.create(e,t,n))),i=r.map(e=>e.status===`fulfilled`?e.value:null).filter(t);if(o(n)||i.length!==r.length){i.forEach(e=>e.destroy()),s(n);for(let e of r)if(e.status===`rejected`)throw e.reason}this._levels=i,this._levelSelector=z(this)}uninitializeRenderContext(){this._invalidateOctree(),this._levels.forEach(e=>e.destroy()),this._defaultRenderInstanceData.forEach(e=>e.destroy()),this._highlightRenderInstanceDatas.forEach(e=>e.forEach(e=>e.destroy()))}_hasTransparentLevels(){return this._levels.some(e=>e.components.some(e=>e.material.produces.get(4)?.(0)))}hasHighlights(){return r(this._highlightRenderInstanceDatas,e=>e.some(e=>e.size>0))}_produces(e){return(e!==10||this.hasHighlights())&&(e!==6||this.hasHighlight(P))}prepareRender(e){if(!_.LOD_INSTANCE_RENDERER_DISABLE_UPDATES){if(this._enableLevelSelection){let t=e.bind.contentCamera.equals(this._camera);this._camera.copyFrom(e.bind.contentCamera),t||this._requestUpdateCycle()}this._needFullCycle&&=(this.runTask(I),!1)}}acquireTechniques(e){if(!this.baseMaterial.visible||!this.baseMaterial.isVisibleForOutput(e.output))return null;let t=this._getInstanceDatas(e);if(!t)return null;let n=[],r=this.levels;return t.forEach(t=>r.forEach(({components:r},i)=>r.forEach(r=>n.push(this._beginComponent(e,t[i],r))))),n}render(e,t){let n=this._getInstanceDatas(e);if(!n||t==null)return;let r=0,i=this.levels;n.forEach(n=>i.forEach(({components:i},a)=>i.forEach(i=>this._renderComponent(e,t[r++],n[a],i,a)))),e.rctx.unbindBuffer(34962),e.rctx.bindVAO(null)}_getInstanceDatas(e){let{output:t,bind:n}=e,r=t===10,i=t===6,a=!r&&!i,o=t!==7;if(a)return o?this._allRenderInstanceData:this._allRenderInstanceDataExceptHighlightShadow;let{_highlightRenderInstanceDatas:s}=this;if(o){if(r){let e=n.highlight?.name;if(!e)return null;let t=s.get(e);return t?[t]:null}let e=s.get(P);return i?e?[e]:null:Array.from(s.values())}return null}intersectRay(e,t,n,r){if(!this.baseMaterial.visible||this._octree==null)return;let i=m();d(i,r,n);let a=i=>{let a=this._setupIntersectableInstance(e,i);a&&(p(K,n,e.transform.inverse),p(q,r,e.transform.inverse),a.intersect(e,t,K,q,i,this.metadata,this._levels.length))};this.baseMaterial.parameters.verticalOffset?this._octree.forEach(a):this._octree.forEachAlongRay(n,i,a)}*intersectScreenPolygon(e,t){if(!this.baseMaterial.visible||this._octree==null)return;let n=this.baseMaterial.parameters.verticalOffset?this._octree.values():this._octree.intersectingFrustumValues(t.broadPhaseFrustum,e=>!!(this._instanceData.getState(e)&4));for(let r of n)yield*this._intersectScreenPolygonInstance(e,t,r)}*_intersectScreenPolygonInstance(e,t,n){let r=this._setupIntersectableInstance(e,n);r&&(yield*r.intersectScreenPolygon(e,t,n,this.metadata,this._levels.length))}_setupIntersectableInstance(e,t){let n=this._instanceData.getState(t);if(!(n&4))return null;let r=this._instanceData.getLodLevel(t),i=this._levels.length;w(!!(n&18),`invalid instance state`),w(r>=0&&r<i,`invaid lod level`);let a=this._levels[r];return a==null?null:(this._instanceData.getCombinedModelTransform(t,G),e.transform.set(G),a)}notifyShaderTransformationChanged(){this._invalidateOctree(),this._requestUpdateCycle()}get _octree(){if(this._octreeCached==null){let e=this._instanceData,t=e.view?.state;if(!t)return null;this._octreeCached=new E(e,this.baseBoundingSphere);for(let n=0;n<e.capacity;++n)t.get(n)&18&&this._octreeCached.addInstance(n)}return this._octreeCached}_invalidateOctree(){this._octreeCached=a(this._octreeCached)}queryDepthRange(e){if(this._octree==null)return new C;let t=e.viewForward,n=this._octree.findClosest(t,1,e.frustum),r=this._octree.findClosest(t,-1,e.frustum);if(n==null||r==null)return new C;let i=e.eye,a=this._instanceData.view;a.boundingSphere.getVec(n,W),d(W,W,i);let o=f(W,t)-W[3];a.boundingSphere.getVec(r,W),d(W,W,i);let s=f(W,t)+W[3];return new C(o,s)}_requestUpdateCycle(e=!1){this._updateCyclesWithStaticCamera=-1,this._cycleStartIndex=this._instanceIndex,e&&(this._needFullCycle=!0,this._context.requestRender())}_startUpdateCycle(){this._updateCyclesWithStaticCamera++,this._allRenderInstanceData.forEach(e=>e.forEach(e=>e.startUpdateCycle()))}get readyToRun(){return this._instanceData.size>0&&this._updateCyclesWithStaticCamera<1}runTask(e){let{_enableLevelSelection:t,_camera:r,_levelSelector:a}=this;this._allRenderInstanceData.forEach(e=>e.forEach(e=>e.beginUpdate()));let o=this._instanceData,s=o.view,c=o.size,l=o.capacity,u=this._instanceIndex,d=Math.ceil(l/500),{_highlightRenderInstanceDatas:f}=this;for(let p=0;p<c&&!e.done;++p){u===this._cycleStartIndex&&this._startUpdateCycle();let p=s.state.get(u),m=0;if(!(p&1)){u=u+1===l?0:u+1,c++;continue}let h=s.lodLevel.get(u);if(p&2&&this._defaultRenderInstanceData[h].freeTail(),p&16){let e=o.geHighlightOptionsPrev(u);if(e){let t=f.get(e);if(t)t[h].freeTail(),t.every(e=>e.isEmpty)&&(t.forEach(e=>e.destroy()),f.delete(e));else throw new n(`internal:lod-renderer`,`Internal error in lodRenderer`)}}if(p&32)o.freeInstance(u);else if(p&4){let e=0;if(t&&(s.modelOrigin.getVec(u,U),e=a.selectLevel(U,o.getCombinedMedianScaleFactor(u),r)),m=p&-83,e>=0){if(p&8){let t=o.getHighlightName(u);if(t){let r=i(f,t,()=>{let e=this._createRenderInstanceDataArray();return e.forEach(e=>e.beginUpdate()),e});if(e>=r.length)throw new n(`internal:lod-renderer`,`LodRenderer internal error - missing lodLevel ${e}`);V(r[e],s,u)}m|=16}else V(this._defaultRenderInstanceData[e],s,u),m|=2}s.state.set(u,m),s.lodLevel.set(u,e)}else m=p&-83,s.state.set(u,m);let g=!!(p&18),_=!!(m&18);this._octreeCached!=null&&(!g&&_?this._octreeCached.addInstance(u):g&&!_?this._octreeCached.removeInstance(u):g&&_&&p&64&&(this._octreeCached.removeInstance(u),this._octreeCached.addInstance(u))),u=u+1===l?0:u+1,u%d===0&&e.madeProgress(),g!==_&&this.metadata.notifyGraphicVisibilityChanged(u),_&&p&64&&this.metadata.notifyGraphicGeometryChanged(u)}this._instanceIndex=u,this._allRenderInstanceData.forEach(e=>e.forEach(e=>e.endUpdate())),this._context.requestRender()}_beginComponent(e,t,n){return t.size===0?null:n.glMaterialLoader.load(e.rctx,e.bind.slot,e.output)?.beginSlot(e.bind)}_renderComponent(e,t,n,r,i){if(!t)return;let{bind:a,rctx:o}=e,s=o.bindTechnique(t,a,r.material.parameters,Y),c=this._glInstanceBufferLayout;s.assertCompatibleVertexAttributeLocations(r.vao,R(c)),o.bindVAO(r.vao),_.LOD_INSTANCE_RENDERER_COLORIZE_BY_LEVEL&&b(e.output)&&(s.setUniform4fv(`externalColor`,J[Math.min(i,J.length-1)]),s.setUniform1i(`symbolColorMixMode`,j.replace));let l=n.capacity,u=n.headIndex,d=n.tailIndex,f=n.firstIndex,p=(e,i)=>{L(o,s.locations,n.buffer,e),o.drawArraysInstanced(t.primitiveType,0,r.numVertices,i-e)};r.material.transparent&&f!=null?u>d?(w(f>=d&&f<=u,`invalid firstIndex`),p(f,u),p(d,f)):u<d&&(f<=u?(w(f>=0&&f<=u,`invalid firstIndex`),p(f,u),p(d,l),p(0,f)):(w(f>=d&&f<=l,`invalid firstIndex`),p(f,l),p(0,u),p(d,f))):u>d?p(d,u):u<d&&(p(0,u),p(d,l))}};e([c({constructOnly:!0})],B.prototype,`symbol`,void 0),e([c({constructOnly:!0})],B.prototype,`metadata`,void 0),e([c({constructOnly:!0})],B.prototype,`shaderTransformation`,void 0),e([c()],B.prototype,`_instanceData`,void 0),e([c()],B.prototype,`_cycleStartIndex`,void 0),e([c({readOnly:!0})],B.prototype,`_enableLevelSelection`,null),e([c()],B.prototype,`_updateCyclesWithStaticCamera`,void 0),e([c({readOnly:!0})],B.prototype,`readyToRun`,null),B=e([l(`esri.views.3d.webgl-engine.lib.lodRendering.LodRenderer`)],B);function V(e,t,n){let r=e.allocateHead();H(t,n,e.view,r)}function H(e,t,n,r){M(e.modelOrigin,t,n.modelOriginHi,n.modelOriginLo,r),n.model.copyFrom(r,e.model,t),n.modelNormal.copyFrom(r,e.modelNormal,t),e.color&&n.color&&n.color.copyFrom(r,e.color,t),e.olidColor&&n.olidColor&&n.olidColor.copyFrom(r,e.olidColor,t),e.featureAttribute&&n.featureAttribute&&n.featureAttribute.copyFrom(r,e.featureAttribute,t)}const U=m(),W=h(),G=u(),K=m(),q=m(),J=[g(1,0,1,1),g(0,0,1,1),g(0,1,0,1),g(1,1,0,1),g(1,0,0,1)],Y=new N;export{B as LodRenderer};
@@ -222,4 +222,4 @@ export function fromRenderCamera(view: SceneView, camera: RenderCamera): Camera;
222
222
  * @param camera - The input render camera.
223
223
  * @returns The new camera using the spatial reference of the view.
224
224
  */
225
- export function toRenderCamera(view: SceneView, camera: Camera | null | undefined): RenderCamera;
225
+ export function toRenderCamera(view: SceneView, camera: Camera | null | undefined): RenderCamera | null | undefined;
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{removeUnordered as e,filterInPlace as t}from"../../core/arrayUtils.js";import n from"../../core/Handles.js";import"../../core/has.js";import r from"../../core/Logger.js";import{removeMaybe as i}from"../../core/maybe.js";import{recordPerformance as a}from"../../core/performance.js";import o from"../../core/PerformanceSampler.js";import{isAborted as s,createAbortError as c,when as l,isPromiseLike as u,ignoreAbortErrors as d}from"../../core/promiseUtils.js";import{watch as f,initial as p,when as m}from"../../core/reactiveUtils.js";import{signal as h}from"../../core/signal.js";import{Milliseconds as g}from"../../core/time.js";import _ from"./debugFlags.js";import{PromiseQueue as v}from"./PromiseQueue.js";import{Yield as y}from"./Yield.js";function b(){return new k}const x={RESOURCE_CONTROLLER_IMMEDIATE:`immediate`,RESOURCE_CONTROLLER:`schedule`,SLIDE:`slide`,STREAM_DATA_LOADER:`stream loader`,ELEVATION_QUERY:`elevation query`,TERRAIN_SURFACE:`terrain`,SURFACE_GEOMETRY_UPDATES:`surface geometry updates`,LOD_RENDERER:`LoD renderer`,GRAPHICS_CORE:`Graphics3D`,I3S:`I3S`,LYR3D:`Lyr3D`,TILES3D:`3DTiles`,POINT_CLOUD_LAYER:`point cloud`,FEATURE_TILE_FETCHER:`feature fetcher`,STREAM_CONTROLLER:`stream controller`,SCREEN_POLYGON_INTERSECTION:`screen polygon intersection`,OCCLUSION_QUERY:`occlusion query`,OVERLAY:`overlay`,OVERLAY_RENDERER:`overlay renderer`,STAGE:`stage`,GRAPHICS_DECONFLICTOR:`graphics deconflictor`,FILTER_VISIBILITY:`graphics filter visibility`,SCALE_VISIBILITY:`graphics scale visibility`,FRUSTUM_VISIBILITY:`graphics frustum visibility`,POINT_OF_INTEREST_FREQUENT:`POI frequent`,POINT_OF_INTEREST_INFREQUENT:`POI infrequent`,LABELER:`labeler`,FEATURE_QUERY_ENGINE:`feature query`,FEATURE_TILE_TREE:`feature tile tree`,FEATURE_TILE_TREE_ACTIVE:`fast feature tile tree`,ELEVATION_ALIGNMENT:`elevation alignment`,ELEVATION_ALIGNMENT_SCENE:`elevation alignment scene`,TEXT_TEXTURE_ATLAS:`text texture atlas`,TEXTURE_UNLOAD:`texture unload`,LINE_OF_SIGHT_TOOL:`line of sight tool`,LINE_OF_SIGHT_TOOL_INTERACTIVE:`interactive line of sight tool`,VOLUME_MEASUREMENT:`volume measurement`,ELEVATION_PROFILE:`elevation profile`,SNAPPING:`snapping`,SHADOW_ACCUMULATOR:`shadow accumulator`,CLOUDS_GENERATOR:`clouds generator`,FLOW_GENERATOR:`flow generator`,GAUSSIAN_SPLAT_SORTING:`gaussian splat sorting`,GAUSSIAN_SPLAT_TEXTURE_ATLAS:`gaussian splat texture atlas`,MAPVIEW_FETCH_QUEUE:`mapview fetch queue`,MAPVIEW_LAYERVIEW_UPDATE:`mapview layerview update`,MAPVIEW_VECTOR_TILE_PARSING_QUEUE:`mapview vector tile parsing queue`,NONE:0,TEST_PRIO:1},S=new Map([[x.RESOURCE_CONTROLLER_IMMEDIATE,0],[x.RESOURCE_CONTROLLER,4],[x.SLIDE,0],[x.STREAM_DATA_LOADER,0],[x.ELEVATION_QUERY,0],[x.TERRAIN_SURFACE,1],[x.SURFACE_GEOMETRY_UPDATES,1],[x.LOD_RENDERER,2],[x.GRAPHICS_CORE,2],[x.I3S,2],[x.LYR3D,2],[x.TILES3D,3],[x.POINT_CLOUD_LAYER,2],[x.FEATURE_TILE_FETCHER,2],[x.STREAM_CONTROLLER,2],[x.SCREEN_POLYGON_INTERSECTION,0],[x.CLOUDS_GENERATOR,2],[x.OCCLUSION_QUERY,2],[x.OVERLAY,4],[x.OVERLAY_RENDERER,4],[x.STAGE,4],[x.GRAPHICS_DECONFLICTOR,4],[x.FILTER_VISIBILITY,4],[x.SCALE_VISIBILITY,4],[x.FRUSTUM_VISIBILITY,4],[x.POINT_OF_INTEREST_FREQUENT,6],[x.POINT_OF_INTEREST_INFREQUENT,30],[x.LABELER,8],[x.FEATURE_QUERY_ENGINE,8],[x.FEATURE_TILE_TREE,16],[x.FEATURE_TILE_TREE_ACTIVE,0],[x.ELEVATION_ALIGNMENT,12],[x.ELEVATION_ALIGNMENT_SCENE,14],[x.TEXT_TEXTURE_ATLAS,12],[x.TEXTURE_UNLOAD,12],[x.LINE_OF_SIGHT_TOOL,16],[x.LINE_OF_SIGHT_TOOL_INTERACTIVE,0],[x.VOLUME_MEASUREMENT,4],[x.SNAPPING,0],[x.SHADOW_ACCUMULATOR,30],[x.FLOW_GENERATOR,12],[x.GAUSSIAN_SPLAT_SORTING,2],[x.GAUSSIAN_SPLAT_TEXTURE_ATLAS,12],[x.MAPVIEW_FETCH_QUEUE,0],[x.MAPVIEW_LAYERVIEW_UPDATE,2],[x.MAPVIEW_VECTOR_TILE_PARSING_QUEUE,0]]);function C(e){return S.has(e)?S.get(e):typeof e==`number`?e:1}const w=g(6.5),T=g(1),E=g(30),D=g(1e3/30),O=g(100);class k{get updating(){return this._updating.value}_updatingChanged(){this._updating.value=this._tasks.some(e=>e.needsUpdate)}constructor(){this._updating=h(!0),this._microTaskQueued=!1,this._frameNumber=0,this.performanceInfo={total:new o(`total`),tasks:new Map},this._frameTaskTimes=new Map,this._budget=new j,this.state=1,this._tasks=[],this._runQueue=[],this._load=0,this._forceTask=!1,this._debug=!1,this._debugHandle=f(()=>_.SCHEDULER_LOG_SLOW_TASKS,e=>this._debug=e,p);for(let e of Object.keys(x))this.performanceInfo.tasks.set(x[e],new o(String(x[e])))}destroy(){this._tasks.forEach(e=>e.remove()),this._tasks.length=0,this._runQueue.length=0,i(this._debugHandle),this._microTaskQueued=!1,this._updatingChanged()}taskRunningChanged(e){this._updatingChanged(),e&&this._budget.remaining>0&&!this._microTaskQueued&&(this._microTaskQueued=!0,queueMicrotask(()=>{this._microTaskQueued&&(this._microTaskQueued=!1,this._budget.remaining>0&&this._schedule()&&this._runFrame())}))}registerTask(e,t){let n=new A(this,e,t);return this._tasks.push(n),this._updatingChanged(),this.performanceInfo.tasks.has(e)||this.performanceInfo.tasks.set(e,new o(e)),n}get load(){return this._load}frame(e){if(this._startFrameTaskTimes(),this._updateBudget(e)){let e=this._budget.now();this._runFrame();let t=this._budget.now();this._recordFrameTaskTimes(t-e);let n=this.state===2?`Idle`:this.state===1?`Interacting`:`Animating`;return a(`${n} Frame Tasks`,e,t,`Maps SDK`,`Scheduling`),!0}return this._recordFrameTaskTimes(0),!1}_updateBudget(e){this._test&&(this._test.usedBudget=0),++this._frameNumber;let t=w,n=e.frameDuration,r=T;switch(this.state){case 2:t=g(0),n=g(Math.max(O,e.frameDuration)),r=E;break;case 1:n=g(Math.max(D,e.frameDuration))}return n=g(n-e.elapsedFrameTime-t),this.state!==2&&n<T&&!this._forceTask?(this._forceTask=!0,!1):(n=g(Math.max(n,r)),this._budget.reset(n),this._updateLoad(),this._schedule())}_runFrame(){this._forceTask=!1,this._microTaskQueued=!1,this._run(),this._test&&(this._test.usedBudget=this._budget.elapsed)}stopFrame(){this._budget.reset(g(0)),this._budget.madeProgress()}removeTask(t){e(this._tasks,t),e(this._runQueue,t),this._updatingChanged()}_updateTask(e){this._tasks.forEach(t=>{t.name===e&&t.setPriority(e)})}_getState(e){if(this._runQueue.some(t=>t.name===e))return`s`;let t=`i`;return this._tasks.forEach(n=>{n.name===e&&n.needsUpdate&&(n.schedulePriority<=1?t=`r`:t!==`r`&&(t=`w`))}),t}_getRuntime(e){let t=0;return this._tasks.forEach(n=>{n.name===e&&(t+=n.runtime)}),t}_resetRuntimes(){this._tasks.forEach(e=>e.runtime=0)}_getRunning(){let e=new Map;if(this._tasks.forEach(t=>{t.needsUpdate&&e.set(t.name,(e.get(t.name)||0)+1)}),e.size===0)return null;let t=``;return e.forEach((e,n)=>{t+=e>1?` ${e}x ${n}`:` ${n}`}),t}_updateLoad(){let e=this._tasks.reduce((e,t)=>t.needsUpdate?++e:e,0);this._load=this._load*.9+e*.09999999999999998}_schedule(){for(t(this._runQueue,e=>e.needsUpdate?!0:(e.schedulePriority=e.basePriority,!1)),this._tasks.forEach(e=>{e.basePriority===0&&e.needsUpdate&&!this._runQueue.includes(e)&&e.blockFrame!==this._frameNumber&&this._runQueue.unshift(e)});this._runQueue.length===0;){let e=!1,t=0;if(this._tasks.forEach(n=>{if(n.needsUpdate&&n.schedulePriority!==0&&n.basePriority!==0&&n.blockFrame!==this._frameNumber)switch(e=!0,t=Math.max(t,n.basePriority),n.schedulePriority){case 1:n.schedulePriority=0,this._runQueue.push(n);break;default:--n.schedulePriority}}),!e)return this._updatingChanged(),!1}return this._updatingChanged(),!0}_run(){do for(;this._runQueue.length>0;){let e=this._budget.now(),t=this._runQueue.pop();this._budget.resetProgress();try{t.task.runTask(this._budget)===y&&(t.blockFrame=this._frameNumber)}catch(e){r.getLogger(`esri.views.support.Scheduler`).error(`Exception in task "${t.name}"`,e),t.blockFrame=this._frameNumber}!this._budget.hasProgressed&&t.blockFrame!==this._frameNumber&&t.needsUpdate&&(t.name,x.I3S,t.blockFrame=this._frameNumber),t.schedulePriority=t.basePriority;let n=this._budget.now(),i=n-e;if(a(`${t.name}`,e,n,`Maps SDK`,`Scheduling`),t.runtime+=i,this._frameTaskTimes.set(t.priority,this._frameTaskTimes.get(t.priority)+i),this._budget.remaining<=0){this._updatingChanged();return}}while(this._schedule());this._updatingChanged()}_startFrameTaskTimes(){for(let e of Object.keys(x))this._frameTaskTimes.set(x[e],0)}_recordFrameTaskTimes(e){this._frameTaskTimes.forEach((e,t)=>this.performanceInfo.tasks.get(t).push(e)),this.performanceInfo.total.push(e)}get test(){return this._test}}class A{get task(){return this._task.value}get readyToRun(){return this._queue.readyToRun}get updating(){return this._queue.updating}constructor(e,t,r){this._scheduler=e,this.name=t,this.blockFrame=0,this.runtime=0,this._queue=new v,this._handles=new n,this._basePriority=C(t),this.schedulePriority=this._basePriority,this._task=h(r??this._queue),this._handles.add(m(()=>this.task.readyToRun,t=>e.taskRunningChanged(t)))}remove(){this._queue.drain(M),this._scheduler.removeTask(this),this.schedule=F.schedule,this.reschedule=F.reschedule,this.scheduleGenerator=F.scheduleGenerator,this._handles.destroy()}[Symbol.dispose](){this.remove()}get basePriority(){return this._basePriority}setPriority(e){if(this.name===e)return;this.name=e;let t=C(e);(this._basePriority===0||this.schedulePriority!==0)&&(this.schedulePriority=t),this._basePriority=t}get priority(){return this.name}set priority(e){this.setPriority(e)}get needsUpdate(){return this.readyToRun||!this.task.destroyed&&this.task.readyToRun}schedule(e,t,n){return this._queue.push(e,t,n)}reschedule(e,t,n){return this._queue.unshift(e,t,n)}scheduleGenerator(e,t,n){return this._queue.pushGenerator(e,t,n)}processQueue(e){return this._queue.runTask(e)}}class j{constructor(){this._begin=performance?.now()??0,this._budget=0,this._done=!1,this._progressed=!1,this._enabled=!0}run(e){return!this.done&&(e()===!0&&this.madeProgress(),!0)}get done(){return this._done}get budget(){return this._budget}madeProgress(){return this._progressed=!0,this._done=this.elapsed>=this._budget&&this._enabled,this._done}get enabled(){return this._enabled}set enabled(e){this._enabled=e}reset(e){this._begin=this.now(),this._budget=e,this.resetProgress()}get remaining(){return Math.max(this._budget-this.elapsed,0)}now(){return performance.now()}get elapsed(){return this.now()-this._begin}resetProgress(){this._progressed=!1,this._done=!1}get hasProgressed(){return this._progressed}}const M=new j;M.enabled=!1;function N(e){let t=new j;return t.reset(e),t}class P{remove(){}[Symbol.dispose](){this.remove()}processQueue(){}schedule(e,t,n){try{if(s(t)){let e=c();return n?Promise.resolve(n(e)):Promise.reject(e)}return l(e(M))}catch(e){return Promise.reject(e)}}reschedule(e,t,n){return this.schedule(e,t,n)}async scheduleGenerator(e,t,n){if(s(t)){let e=c();if(n)return n(e);throw e}let r=e(M);for(;;){let e=r.next(M),i=u(e)?await e:e;if(s(t)){let e=c();if(n){let t=n(e),i=r.return(null);return u(i)&&await d(i),t}let t=r.throw(e);throw u(t)&&await d(t),e}if(i.done)return i.value}}}const F=new P;export{F as ImmediateTask,x as TaskPriority,C as getTaskPriority,N as makeBudget,b as newScheduler,M as noBudget,S as taskPriorities};
2
+ import{removeUnordered as e,filterInPlace as t}from"../../core/arrayUtils.js";import n from"../../core/Handles.js";import"../../core/has.js";import r from"../../core/Logger.js";import{removeMaybe as i}from"../../core/maybe.js";import{recordPerformance as a}from"../../core/performance.js";import o from"../../core/PerformanceSampler.js";import{isAborted as s,createAbortError as c,when as l,isPromiseLike as u,ignoreAbortErrors as d}from"../../core/promiseUtils.js";import{watch as f,initial as p,when as m}from"../../core/reactiveUtils.js";import{signal as h}from"../../core/signal.js";import{Milliseconds as g}from"../../core/time.js";import _ from"./debugFlags.js";import{PromiseQueue as v}from"./PromiseQueue.js";import{Yield as y}from"./Yield.js";function b(){return new k}const x={RESOURCE_CONTROLLER_IMMEDIATE:`immediate`,RESOURCE_CONTROLLER:`schedule`,SLIDE:`slide`,STREAM_DATA_LOADER:`stream loader`,ELEVATION_QUERY:`elevation query`,TERRAIN_SURFACE:`terrain`,SURFACE_GEOMETRY_UPDATES:`surface geometry updates`,LOD_RENDERER:`LoD renderer`,GRAPHICS_CORE:`Graphics3D`,I3S:`I3S`,LYR3D:`Lyr3D`,TILES3D:`3DTiles`,POINT_CLOUD_LAYER:`point cloud`,FEATURE_TILE_FETCHER:`feature fetcher`,STREAM_CONTROLLER:`stream controller`,SCREEN_POLYGON_INTERSECTION:`screen polygon intersection`,OCCLUSION_QUERY:`occlusion query`,OVERLAY:`overlay`,OVERLAY_RENDERER:`overlay renderer`,STAGE:`stage`,GRAPHICS_DECONFLICTOR:`graphics deconflictor`,FILTER_VISIBILITY:`graphics filter visibility`,SCALE_VISIBILITY:`graphics scale visibility`,FRUSTUM_VISIBILITY:`graphics frustum visibility`,POINT_OF_INTEREST_FREQUENT:`POI frequent`,POINT_OF_INTEREST_INFREQUENT:`POI infrequent`,LABELER:`labeler`,FEATURE_QUERY_ENGINE:`feature query`,FEATURE_TILE_TREE:`feature tile tree`,FEATURE_TILE_TREE_ACTIVE:`fast feature tile tree`,ELEVATION_ALIGNMENT:`elevation alignment`,ELEVATION_ALIGNMENT_SCENE:`elevation alignment scene`,TEXT_TEXTURE_ATLAS:`text texture atlas`,TEXTURE_UNLOAD:`texture unload`,LINE_OF_SIGHT_TOOL:`line of sight tool`,LINE_OF_SIGHT_TOOL_INTERACTIVE:`interactive line of sight tool`,VOLUME_MEASUREMENT:`volume measurement`,ELEVATION_PROFILE:`elevation profile`,SNAPPING:`snapping`,SHADOW_ACCUMULATOR:`shadow accumulator`,CLOUDS_GENERATOR:`clouds generator`,FLOW_GENERATOR:`flow generator`,GAUSSIAN_SPLAT_SORTING:`gaussian splat sorting`,GAUSSIAN_SPLAT_TEXTURE_ATLAS:`gaussian splat texture atlas`,MAPVIEW_FETCH_QUEUE:`mapview fetch queue`,MAPVIEW_LAYERVIEW_UPDATE:`mapview layerview update`,MAPVIEW_VECTOR_TILE_PARSING_QUEUE:`mapview vector tile parsing queue`,NONE:0,TEST_PRIO:1},S=new Map([[x.RESOURCE_CONTROLLER_IMMEDIATE,0],[x.RESOURCE_CONTROLLER,4],[x.SLIDE,0],[x.STREAM_DATA_LOADER,0],[x.ELEVATION_QUERY,0],[x.TERRAIN_SURFACE,1],[x.SURFACE_GEOMETRY_UPDATES,1],[x.LOD_RENDERER,2],[x.GRAPHICS_CORE,2],[x.I3S,2],[x.LYR3D,2],[x.TILES3D,3],[x.POINT_CLOUD_LAYER,2],[x.FEATURE_TILE_FETCHER,2],[x.STREAM_CONTROLLER,2],[x.SCREEN_POLYGON_INTERSECTION,0],[x.CLOUDS_GENERATOR,2],[x.OCCLUSION_QUERY,2],[x.OVERLAY,4],[x.OVERLAY_RENDERER,4],[x.STAGE,4],[x.GRAPHICS_DECONFLICTOR,4],[x.FILTER_VISIBILITY,4],[x.SCALE_VISIBILITY,4],[x.FRUSTUM_VISIBILITY,4],[x.POINT_OF_INTEREST_FREQUENT,6],[x.POINT_OF_INTEREST_INFREQUENT,30],[x.LABELER,8],[x.FEATURE_QUERY_ENGINE,8],[x.FEATURE_TILE_TREE,16],[x.FEATURE_TILE_TREE_ACTIVE,0],[x.ELEVATION_ALIGNMENT,12],[x.ELEVATION_ALIGNMENT_SCENE,14],[x.TEXT_TEXTURE_ATLAS,12],[x.TEXTURE_UNLOAD,12],[x.LINE_OF_SIGHT_TOOL,16],[x.LINE_OF_SIGHT_TOOL_INTERACTIVE,0],[x.VOLUME_MEASUREMENT,4],[x.SNAPPING,0],[x.SHADOW_ACCUMULATOR,30],[x.FLOW_GENERATOR,12],[x.GAUSSIAN_SPLAT_SORTING,2],[x.GAUSSIAN_SPLAT_TEXTURE_ATLAS,12],[x.MAPVIEW_FETCH_QUEUE,0],[x.MAPVIEW_LAYERVIEW_UPDATE,2],[x.MAPVIEW_VECTOR_TILE_PARSING_QUEUE,0]]);function C(e){return S.has(e)?S.get(e):typeof e==`number`?e:1}const w=g(6.5),T=g(1),E=g(30),D=g(1e3/30),O=g(100);class k{get updating(){return this._updating.value}_updatingChanged(){this._updating.value=this._tasks.some(e=>e.needsUpdate)}constructor(){this._updating=h(!0),this._microTaskQueued=!1,this._frameNumber=0,this.performanceInfo={total:new o(`total`),tasks:new Map},this._frameTaskTimes=new Map,this._budget=new j,this.state=1,this._tasks=[],this._runQueue=[],this._load=0,this._forceTask=!1,this._debug=!1,this._debugHandle=f(()=>_.SCHEDULER_LOG_SLOW_TASKS,e=>this._debug=e,p);for(let e of Object.keys(x))this.performanceInfo.tasks.set(x[e],new o(String(x[e])))}destroy(){this._tasks.forEach(e=>e.remove()),this._tasks.length=0,this._runQueue.length=0,i(this._debugHandle),this._microTaskQueued=!1,this._updatingChanged()}taskRunningChanged(e){this._updatingChanged(),e&&this._budget.remaining>0&&!this._microTaskQueued&&(this._microTaskQueued=!0,queueMicrotask(()=>{this._microTaskQueued&&(this._microTaskQueued=!1,this._budget.remaining>0&&this._schedule()&&this._runFrame())}))}registerTask(e,t){let n=new A(this,e,t);return this._tasks.push(n),this._updatingChanged(),this.performanceInfo.tasks.has(e)||this.performanceInfo.tasks.set(e,new o(e)),n}get load(){return this._load}frame(e){if(this._startFrameTaskTimes(),this._updateBudget(e)){let e=this._budget.now();this._runFrame();let t=this._budget.now();this._recordFrameTaskTimes(t-e);let n=this.state===2?`Idle`:this.state===1?`Interacting`:`Animating`;return a(`${n} Frame Tasks`,e,t,`Maps SDK`,`Scheduling`),!0}return this._recordFrameTaskTimes(0),!1}_updateBudget(e){this._test&&(this._test.usedBudget=0),++this._frameNumber;let t=w,n=e.frameDuration,r=T;switch(this.state){case 2:t=g(0),n=g(Math.max(O,e.frameDuration)),r=E;break;case 1:n=g(Math.max(D,e.frameDuration))}return n=g(n-e.elapsedFrameTime-t),this.state!==2&&n<T&&!this._forceTask?(this._forceTask=!0,!1):(n=g(Math.max(n,r)),this._budget.reset(n),this._updateLoad(),this._schedule())}_runFrame(){this._forceTask=!1,this._microTaskQueued=!1,this._run(),this._test&&(this._test.usedBudget=this._budget.elapsed)}stopFrame(){this._budget.reset(g(0)),this._budget.madeProgress()}removeTask(t){e(this._tasks,t),e(this._runQueue,t),this._updatingChanged()}_updateTask(e){this._tasks.forEach(t=>{t.name===e&&t.setPriority(e)})}_getState(e){if(this._runQueue.some(t=>t.name===e))return`s`;let t=`i`;return this._tasks.forEach(n=>{n.name===e&&n.needsUpdate&&(n.schedulePriority<=1?t=`r`:t!==`r`&&(t=`w`))}),t}_getRuntime(e){let t=0;return this._tasks.forEach(n=>{n.name===e&&(t+=n.runtime)}),t}_resetRuntimes(){this._tasks.forEach(e=>e.runtime=0)}_getRunning(){let e=new Map;if(this._tasks.forEach(t=>{t.needsUpdate&&e.set(t.name,(e.get(t.name)||0)+1)}),e.size===0)return null;let t=``;return e.forEach((e,n)=>{t+=e>1?` ${e}x ${n}`:` ${n}`}),t}_updateLoad(){let e=this._tasks.reduce((e,t)=>t.needsUpdate?++e:e,0);this._load=this._load*.9+e*.09999999999999998}_schedule(){for(t(this._runQueue,e=>e.needsUpdate?!0:(e.schedulePriority=e.basePriority,!1)),this._tasks.forEach(e=>{e.basePriority===0&&e.needsUpdate&&!this._runQueue.includes(e)&&e.blockFrame!==this._frameNumber&&this._runQueue.unshift(e)});this._runQueue.length===0;){let e=!1,t=0;if(this._tasks.forEach(n=>{if(n.needsUpdate&&n.schedulePriority!==0&&n.basePriority!==0&&n.blockFrame!==this._frameNumber)switch(e=!0,t=Math.max(t,n.basePriority),n.schedulePriority){case 1:n.schedulePriority=0,this._runQueue.push(n);break;default:--n.schedulePriority}}),!e)return this._updatingChanged(),!1}return this._updatingChanged(),!0}_run(){do for(;this._runQueue.length>0;){let e=this._budget.now(),t=this._runQueue.pop();this._budget.resetProgress();try{t.task.runTask(this._budget)===y&&(t.blockFrame=this._frameNumber)}catch(e){r.getLogger(`esri.views.support.Scheduler`).error(`Exception in task "${t.name}"`,e),t.blockFrame=this._frameNumber}!this._budget.hasProgressed&&t.blockFrame!==this._frameNumber&&t.needsUpdate&&(t.name,x.I3S,t.blockFrame=this._frameNumber),t.schedulePriority=t.basePriority;let n=this._budget.now(),i=n-e;if(a(`${t.name}`,e,n,`Maps SDK`,`Scheduling`),t.runtime+=i,this._frameTaskTimes.set(t.priority,this._frameTaskTimes.get(t.priority)+i),this._budget.remaining<=0){this._updatingChanged();return}}while(this._schedule());this._updatingChanged()}_startFrameTaskTimes(){for(let e of Object.keys(x))this._frameTaskTimes.set(x[e],0)}_recordFrameTaskTimes(e){this._frameTaskTimes.forEach((e,t)=>this.performanceInfo.tasks.get(t).push(e)),this.performanceInfo.total.push(e)}get test(){return this._test}}class A{get task(){return this._task.value}get readyToRun(){return this._queue.readyToRun}get updating(){return this._queue.updating}constructor(e,t,r){this._scheduler=e,this.name=t,this.blockFrame=0,this.runtime=0,this._queue=new v,this._handles=new n,this._basePriority=C(t),this.schedulePriority=this._basePriority,this._task=h(r??this._queue),this._handles.add(m(()=>this.task.readyToRun,t=>e.taskRunningChanged(t)))}remove(){this._queue.drain(M),this._scheduler.removeTask(this),this.schedule=F.schedule,this.reschedule=F.reschedule,this.scheduleGenerator=F.scheduleGenerator,this._handles.destroy()}[Symbol.dispose](){this.remove()}get basePriority(){return this._basePriority}setPriority(e){if(this.name===e)return;this.name=e;let t=C(e);(this._basePriority===0||this.schedulePriority!==0)&&(this.schedulePriority=t),this._basePriority=t}get priority(){return this.name}set priority(e){this.setPriority(e)}get needsUpdate(){return this.readyToRun||!this.task.destroyed&&this.task.readyToRun}schedule(e,t,n){return this._queue.push(e,t,n)}reschedule(e,t,n){return this._queue.unshift(e,t,n)}scheduleGenerator(e,t,n){return this._queue.pushGenerator(e,t,n)}processQueue(e){return this._queue.runTask(e)}}class j{constructor(){this._begin=performance?.now()??0,this._budget=0,this._done=!1,this._progressed=!1,this._enabled=!0}run(e){return!this.done&&(e()===!0&&this.madeProgress(),!0)}get done(){return this._done}get budget(){return this._budget}madeProgress(){return this._progressed=!0,this._done=this._enabled&&this._budget!==1/0&&this.elapsed>=this._budget,this._done}get enabled(){return this._enabled}set enabled(e){this._enabled=e}reset(e){this._begin=this.now(),this._budget=e,this.resetProgress()}get remaining(){return Math.max(this._budget-this.elapsed,0)}now(){return performance.now()}get elapsed(){return this.now()-this._begin}resetProgress(){this._progressed=!1,this._done=!1}get hasProgressed(){return this._progressed}}const M=new j;M.enabled=!1;function N(e){let t=new j;return t.reset(e),t}class P{remove(){}[Symbol.dispose](){this.remove()}processQueue(){}schedule(e,t,n){try{if(s(t)){let e=c();return n?Promise.resolve(n(e)):Promise.reject(e)}return l(e(M))}catch(e){return Promise.reject(e)}}reschedule(e,t,n){return this.schedule(e,t,n)}async scheduleGenerator(e,t,n){if(s(t)){let e=c();if(n)return n(e);throw e}let r=e(M);for(;;){let e=r.next(M),i=u(e)?await e:e;if(s(t)){let e=c();if(n){let t=n(e),i=r.return(null);return u(i)&&await d(i),t}let t=r.throw(e);throw u(t)&&await d(t),e}if(i.done)return i.value}}}const F=new P;export{F as ImmediateTask,x as TaskPriority,C as getTaskPriority,N as makeBudget,b as newScheduler,M as noBudget,S as taskPriorities};
@@ -137,7 +137,7 @@ export interface DirectionsProperties extends WidgetProperties, Partial<Pick<Dir
137
137
  * @since 4.6
138
138
  * @see [DirectionsViewModel](https://developers.arcgis.com/javascript/latest/references/core/widgets/Directions/DirectionsViewModel/)
139
139
  * @see [RouteLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/RouteLayer/)
140
- * @see [Guide topic - Access secure resources](https://developers.arcgis.com/javascript/latest/secure-resources/)
140
+ * @see [Guide topic - Authentication and access tokens](https://developers.arcgis.com/javascript/latest/authentication/access-tokens/)
141
141
  * @see [Sample - Directions widget](https://developers.arcgis.com/javascript/latest/sample-code/widgets-directions/)
142
142
  * @example
143
143
  * // 1. Add empty RouteLayer to Directions widget
@@ -1 +0,0 @@
1
- "use strict";(self.webpackChunkRemoteClient=self.webpackChunkRemoteClient||[]).push([[1969],{83349(t,e,n){n.d(e,{e:()=>x});const r=new Set;let i=!1;function x(t,e,n=2){let i=e&&e.length,x=i?e[0]*n:t.length;r.size&&r.clear();let y=l(t,0,x,n,!0),o=[];if(!y||y.next===y.prev)return o;let h=0,a=0,u=0;if(i&&(y=c(t,e,y,n)),t.length>80*n){h=t[0],a=t[1];let e=h,r=a;for(let i=n;i<x;i+=n){let n=t[i],x=t[i+1];n<h&&(h=n),x<a&&(a=x),n>e&&(e=n),x>r&&(r=x)}u=Math.max(e-h,r-a),u=0===u?0:32767/u}return s(y,o,h,a,u),o}function l(t,e,n,r,i){let x=null;if(i===q(t,e,n,r)>0)for(let i=e;i<n;i+=r)x=j(i/r|0,t[i],t[i+1],x);else for(let i=n-r;i>=e;i-=r)x=j(i/r|0,t[i],t[i+1],x);return x&&L(x,x.next)&&(D(x),x=x.next),x}function y(t,e=t){let n,x=e===t,l=t;do{n=!1,l===l.next||0!==r.size&&r.has(l)||!L(l,l.next)&&0!==z(l.prev,l,l.next)?(x||l!==e)&&(l=l.next,n=!x):((x||l===e)&&(e=l.prev),i=!0,D(l),l=l.prev,n=!0)}while(n||l!==e);return e}function s(t,e,n,r,x){x&&function(t,e,n,r){let i=t,x=0;do{i.z=Z(i.x,i.y,e,n,r),T[x++]=i,i=i.next}while(i!==t);!function(t){if(t<=32)for(let e=1;e<t;e++){let t=T[e],n=t.z,r=e-1;for(;r>=0&&T[r].z>n;)T[r+1]=T[r],r--;T[r+1]=t}else{V.length<t&&(V=new Uint32Array(t),E=new Uint32Array(t),k=Array(t));for(let e=0;e<t;e++)V[e]=T[e].z;U(t,T,V,k,E,0),U(t,k,E,T,V,8),U(t,T,V,k,E,16),U(t,k,E,T,V,24)}}(x);let l=null;for(let t=0;t<x;t++){let e=T[t];e.prevZ=l,l&&(l.nextZ=e),l=e}l.nextZ=null,T.fill(null,0,x),k.fill(null,0,x)}(t,n,r,x);let l=t,s=!1;for(;t.prev!==t.next;){let f=t.prev,c=t.next;if(z(f,t,c)<0&&(x?h(t,n,r,x):o(t)))e.push(f.i,t.i,c.i),D(t),t=c,l=c;else if((t=c)===l){if(i=!1,t=y(t),i){l=t;continue}if(!s){l=t=a(t,e),s=!0;continue}u(t,e,n,r,x);break}}}function o(t){let e=t.prev,n=t,r=t.next,i=e.x,x=n.x,l=r.x,y=e.y,s=n.y,o=r.y,h=Math.min(i,x,l),a=Math.min(y,s,o),u=Math.max(i,x,l),f=Math.max(y,s,o),c=r.next;for(;c!==e;){if(c.x>=h&&c.x<=u&&c.y>=a&&c.y<=f&&(i!==c.x||y!==c.y)&&P(i,y,x,s,l,o,c.x,c.y)&&z(c.prev,c,c.next)>=0)return!1;c=c.next}return!0}function h(t,e,n,r){let i=t.prev,x=t,l=t.next,y=i.x,s=x.x,o=l.x,h=i.y,a=x.y,u=l.y,f=Math.min(y,s,o),c=Math.min(h,a,u),_=Math.max(y,s,o),d=Math.max(h,a,u),v=Z(f,c,e,n,r),w=Z(_,d,e,n,r),p=t.prevZ;for(;p&&p.z>=v;){if(p.x>=f&&p.x<=_&&p.y>=c&&p.y<=d&&p!==l&&(y!==p.x||h!==p.y)&&P(y,h,s,a,o,u,p.x,p.y)&&z(p.prev,p,p.next)>=0)return!1;p=p.prevZ}let g=t.nextZ;for(;g&&g.z<=w;){if(g.x>=f&&g.x<=_&&g.y>=c&&g.y<=d&&g!==l&&(y!==g.x||h!==g.y)&&P(y,h,s,a,o,u,g.x,g.y)&&z(g.prev,g,g.next)>=0)return!1;g=g.nextZ}return!0}function a(t,e){let n=t,r=!1;do{let i=n.prev,x=n.next.next;B(i,n,n.next,x,!1)&&R(i,x)&&R(x,i)&&(e.push(i.i,n.i,x.i),D(n),D(n.next),n=t=x,r=!0),n=n.next}while(n!==t);return r?y(n):n}function u(t,e,n,r,i){let x=t;do{let t=x.next.next;for(;t!==x.prev;){if(x.i!==t.i&&S(x,t)){let l=I(x,t);return x=y(x,x.next),l=y(l,l.next),s(x,e,n,r,i),void s(l,e,n,r,i)}t=t.next}x=x.next}while(x!==t)}let f=!1;function c(t,e,n,i){let x=[];for(let n=0,y=e.length;n<y;n++){let s=l(t,e[n]*i,n<y-1?e[n+1]*i:t.length,i,!1);s===s.next&&r.add(s),x.push(C(s))}x.sort(_),function(t,e){let n=Math.ceil((t+2*e)/16)+e+2;v.length<4*n&&(v=new Float64Array(4*n)),w=0}(t.length/i,e.length),b(n,n),f=!0;for(let t=0;t<x.length;t++)n=d(x[t],n);return f=!1,y(n)}function _(t,e){return t.x-e.x||t.y-e.y||(t.next.y-t.y)/(t.next.x-t.x)-(e.next.y-e.y)/(e.next.x-e.x)}function d(t,e){let n=function(t,e){let n,r=e,i=t.x,x=t.y,l=-1/0;if(L(t,r))return r;for(let e=0,y=0;e<w;e++,y+=4){if(x<v[y+1]||x>v[y+3]||v[y]>i||v[y+2]<=l)continue;let s=m(e);r=M(e);do{if(r.prev.next===r){if(L(t,r.next))return r.next;if(x<=r.y&&x>=r.next.y&&r.next.y!==r.y){let t=r.x+(x-r.y)*(r.next.x-r.x)/(r.next.y-r.y);if(t<=i&&t>l&&(l=t,n=r.x<r.next.x?r:r.next,t===i))return n}}r=r.next}while(r!==s)}if(!n)return null;let y=n.x,s=n.y,o=Math.min(x,s),h=Math.max(x,s),a=1/0;for(let e=0,u=0;e<w;e++,u+=4){if(v[u+2]<y||v[u]>i||v[u+3]<o||v[u+1]>h)continue;let f=m(e);r=M(e);do{if(r.prev.next===r&&i>=r.x&&r.x>=y&&i!==r.x&&P(x<s?i:l,x,y,s,x<s?l:i,x,r.x,r.y)){let e=Math.abs(x-r.y)/(i-r.x);(R(r,t)||r.y===x&&r.next.y===x&&r.next.x>i)&&(e<a||e===a&&(r.x>n.x||r.x===n.x&&A(n,r)))&&(n=r,a=e)}r=r.next}while(r!==f)}return n}(t,e);if(!n)return e;let r=I(n,t);return b(n,r.next.next),y(r,r.next),y(n,n.next)}let v=new Float64Array,w=0;const p=[],g=[];function b(t,e){let n=t;do{let t=w++;p[t]=n;let r=1/0,i=1/0,x=-1/0,l=-1/0,y=0;do{let e=n.next;n.z=t,n.x<r&&(r=n.x),n.x>x&&(x=n.x),n.y<i&&(i=n.y),n.y>l&&(l=n.y),e.x<r&&(r=e.x),e.x>x&&(x=e.x),e.y<i&&(i=e.y),e.y>l&&(l=e.y),n=e}while(++y<16&&n!==e);g[t]=n;let s=4*t;v[s]=r,v[s+1]=i,v[s+2]=x,v[s+3]=l}while(n!==e)}function m(t){let e=g[t];for(;e.prev.next!==e;)e=e.next;return g[t]=e,e}function M(t){let e=p[t];for(;e.prev.next!==e;)e=e.next;return p[t]=e,e}function A(t,e){return z(t.prev,t,e.prev)<0&&z(e.next,t,t.next)<0}const T=[];let k=[],V=new Uint32Array,E=new Uint32Array;const N=new Uint32Array(256);function U(t,e,n,r,i,x){N.fill(0);for(let e=0;e<t;e++)N[n[e]>>>x&255]++;let l=0;for(let t=0;t<256;t++){let e=N[t];N[t]=l,l+=e}for(let l=0;l<t;l++){let t=n[l],y=N[t>>>x&255]++;r[y]=e[l],i[y]=t}}function Z(t,e,n,r,i){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-n)*i|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-r)*i|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function C(t){let e=t,n=t;do{(e.x<n.x||e.x===n.x&&e.y<n.y)&&(n=e),e=e.next}while(e!==t);return n}function P(t,e,n,r,i,x,l,y){return(i-l)*(e-y)>=(t-l)*(x-y)&&(t-l)*(r-y)>=(n-l)*(e-y)&&(n-l)*(x-y)>=(i-l)*(r-y)}function S(t,e){let n=L(t,e)&&z(t.prev,t,t.next)>0&&z(e.prev,e,e.next)>0;return t.next.i!==e.i&&(n||R(t,e)&&R(e,t)&&(0!==z(t.prev,t,e.prev)||0!==z(t,e.prev,e)))&&!function(t,e){let n=Math.min(t.x,e.x),r=Math.max(t.x,e.x),i=Math.min(t.y,e.y),x=Math.max(t.y,e.y),l=t;do{let y=l.next;if(l.x>r&&y.x>r||l.x<n&&y.x<n||l.y>x&&y.y>x||l.y<i&&y.y<i)l=y;else{if(l.i!==t.i&&y.i!==t.i&&l.i!==e.i&&y.i!==e.i&&B(l,y,t,e))return!0;l=y}}while(l!==t);return!1}(t,e)&&(n||function(t,e){let n=t,r=!1,i=(t.x+e.x)/2,x=(t.y+e.y)/2;do{let t=n.next;n.y>x!=t.y>x&&i<(t.x-n.x)*(x-n.y)/(t.y-n.y)+n.x&&(r=!r),n=t}while(n!==t);return r}(t,e))}function z(t,e,n){return(e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y)}function L(t,e){return t.x===e.x&&t.y===e.y}function B(t,e,n,r,i=!0){let x=z(t,e,n),l=z(t,e,r),y=z(n,r,t),s=z(n,r,e);return(x>0&&l<0||x<0&&l>0)&&(y>0&&s<0||y<0&&s>0)||!!i&&!!(0===x&&F(t,n,e)||0===l&&F(t,r,e)||0===y&&F(n,t,r)||0===s&&F(n,e,r))}function F(t,e,n){return e.x<=Math.max(t.x,n.x)&&e.x>=Math.min(t.x,n.x)&&e.y<=Math.max(t.y,n.y)&&e.y>=Math.min(t.y,n.y)}function R(t,e){return z(t.prev,t,t.next)<0?z(t,e,t.next)>=0&&z(t,t.prev,e)>=0:z(t,e,t.prev)<0||z(t,t.next,e)<0}function I(t,e){let n=W(t.i,t.x,t.y),r=W(e.i,e.x,e.y),i=t.next,x=e.prev;return t.next=e,e.prev=t,n.next=i,i.prev=n,r.next=n,n.prev=r,x.next=r,r.prev=x,r}function j(t,e,n,r){let i=W(t,e,n);return r?(i.next=r.next,i.prev=r,r.next.prev=i,r.next=i):(i.prev=i,i.next=i),i}function D(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ),f&&function(t,e){let n=4*t.z;e.x<v[n]&&(v[n]=e.x),e.y<v[n+1]&&(v[n+1]=e.y),e.x>v[n+2]&&(v[n+2]=e.x),e.y>v[n+3]&&(v[n+3]=e.y)}(t.prev,t.next)}function W(t,e,n){return{i:t,x:e,y:n,prev:null,next:null,z:0,prevZ:null,nextZ:null}}function q(t,e,n,r){let i=0;for(let x=e,l=n-r;x<n;x+=r)i+=(t[l]-t[x])*(t[x+1]+t[l+1]),l=x;return i}let H,O,X,Y,$,Q=0,G=0;function J(t,e,n,r,i,x){return(n-t)*(x-e)-(r-e)*(i-t)}function K(t,e,n,r,i,x,l,y){let s=t-l,o=e-y,h=n-l,a=r-y,u=i-l,f=x-y,c=s*s+o*o,_=h*h+a*a,d=u*u+f*f,v=c+_+d;return s*(a*d-_*f)-o*(h*d-_*u)+c*(h*f-a*u)<=1e-13*v*v}function tt(t){return t-t%3+(t+1)%3}x.deviation=function(t,e,n,r){let i=e&&e.length,x=i?e[0]*n:t.length,l=Math.abs(q(t,0,x,n));if(i)for(let r=0,i=e.length;r<i;r++){let x=e[r]*n,y=r<i-1?e[r+1]*n:t.length;l-=Math.abs(q(t,x,y,n))}let y=0;for(let e=0;e<r.length;e+=3){let i=r[e]*n,x=r[e+1]*n,l=r[e+2]*n;y+=Math.abs((t[i]-t[l])*(t[x+1]-t[i+1])-(t[i]-t[x])*(t[l+1]-t[i+1]))}return 0===l&&0===y?0:Math.abs((y-l)/l)},x.flatten=function(t){let e=[],n=[],r=t[0][0].length,i=0,x=0;for(let l of t){for(let t of l)for(let n=0;n<r;n++)e.push(t[n]);x&&(i+=x,n.push(i)),x=l.length}return{vertices:e,holes:n,dimensions:r}},x.refine=function(t,e,n=2){let r=t,i=r.length;if(i<6)return;(function(t){(!H||H.length<t)&&(H=new Int32Array(t)),(!O||O.length<t)&&(O=new Int32Array(t)),(!$||$.length<t)&&($=new Uint8Array(t));let e=1;for(;e<4*t;)e<<=1;(!X||X.length<e)&&(X=new Int32Array(e),Y=new Uint32Array(e)),Q=e-1})(i),G++,O.fill(-1,0,i);let x=0;for(let t=0;t<i;t++){let e=r[t],n=r[tt(t)],i=e<n?e:n,l=e<n?n:e,y=(Math.imul(i,2654435761)^Math.imul(l,2246822507))&Q;for(;Y[y]===G;){let e=X[y];if(-1!==e){let n=r[e],s=r[tt(e)];if(n===i&&s===l||n===l&&s===i){O[t]=e,O[e]=t,X[y]=-1,$[e]=1,H[x++]=e;break}}y=y+1&Q}Y[y]!==G&&(X[y]=t,Y[y]=G)}for(;x>0;){let t=H[--x];$[t]=0;let i=O[t];if(-1===i)continue;let l=t-t%3,y=i-i%3,s=l+(t+2)%3,o=l+(t+1)%3,h=y+(i+2)%3,a=y+(i+1)%3,u=r[s],f=r[t],c=r[o],_=r[h],d=e[u*n],v=e[u*n+1],w=e[f*n],p=e[f*n+1],g=e[c*n],b=e[c*n+1],m=e[_*n],M=e[_*n+1];if(!K(d,v,w,p,g,b,m,M)&&J(d,v,w,p,m,M)>0&&J(d,v,m,M,g,b)>0){r[t]=_,r[i]=u;let e=O[h],n=O[s];O[t]=e,-1!==e&&(O[e]=t),O[i]=n,-1!==n&&(O[n]=i),O[s]=h,O[h]=s,-1!==e&&0===$[t]&&($[t]=1,H[x++]=t),-1!==n&&0===$[i]&&($[i]=1,H[x++]=i),-1!==O[o]&&0===$[o]&&($[o]=1,H[x++]=o),-1!==O[a]&&0===$[a]&&($[a]=1,H[x++]=a)}}}},15585(t,e,n){n.d(e,{If:()=>o,QT:()=>h});var r=n(32198),i=n(2741),x=n(49186),l=n(44208);n(34727);let y=null,s=null;async function o(){return y??=async function(){s=await(await n.e(2997).then(()=>n(42997))).default({locateFile:t=>(0,i.s)(`esri/core/libs/libtess/${t}`)})}(),y}function h(t,e,n=2){let i={stack:[],error:void 0,hasError:!1};try{let y=s;if(!y)throw new x.A("libtess:not-loaded","libtessF32 not loaded");let o=(0,r.mS)(i,f.from(y,t),!1),h=(0,r.mS)(i,c.from(y,e),!1),a=t.length/n*4,u=(0,r.mS)(i,new f(y,a*n),!1),_=y.triangulate(o.ptr,h.ptr,h.size,n,u.ptr,a);if((0,l.A)("esri-tessellation-debug")){let t=y.getError();0!==t&&console.warn("libtess:triangulation",function(t){switch(t){case 100903:return"Insufficient output buffer";case 100902:return"Out of memory";case 100151:return"Missing begin polygon";case 100152:return"Missing begin contour";case 100153:return"Missing end polygon";case 100154:return"Missing end countour";case 100155:return"Coordinates too large";case 100156:return"Missing combine callback";default:return`Unknown: ${t}`}}(t))}return{buffer:u.slice(0,_*n),vertexCount:_}}catch(t){i.error=t,i.hasError=!0}finally{(0,r.hk)(i)}}function a(t){return t.HEAPF32}function u(t){return t.HEAP32}new Float32Array,new Uint32Array,new Uint32Array,new Uint32Array,new Float64Array,new Uint32Array,new Uint32Array,new Uint32Array;class f{static from(t,e){let n=new f(t,e.length);return n.set(e),n}constructor(t,e){this._libtess=t,this.size=e,this.ptr=t.allocateCoordinateArray(e)}destroy(){this._libtess.destroyCoordinateArray(this.ptr)}[Symbol.dispose](){this.destroy()}get bytesPerCoordinate(){return Float32Array.BYTES_PER_ELEMENT}set(t){a(this._libtess).set(t,this.ptr/this.bytesPerCoordinate)}slice(t,e){let n=this.ptr/this.bytesPerCoordinate;return a(this._libtess).slice(n+t,n+e)}}Symbol.dispose;class c{static from(t,e){let n=new c(t,e.length);return n.set(e),n}constructor(t,e){this._libtess=t,this.size=e,this.ptr=t.allocateLengthsArray(e)}destroy(){this._libtess.destroyLengthsArray(this.ptr)}[Symbol.dispose](){this.destroy()}get bytesPerCoordinate(){return Int32Array.BYTES_PER_ELEMENT}set(t){u(this._libtess).set(t,this.ptr/this.bytesPerCoordinate)}slice(t,e){let n=this.ptr/this.bytesPerCoordinate;return function(t){let e=u(t);return new Uint32Array(e.buffer,e.byteOffset,e.length)}(this._libtess).slice(n+t,n+e)}}},83773(t,e,n){function r(t,e){return t.x===e.x&&t.y===e.y}function i(t){if(!t)return;let e=t.length;if(e<=1)return;let n=0;for(let i=1;i<e;i++)!r(t[i],t[n])&&++n!==i&&(t[n]=t[i]);t.length=n+1}function x(t,e){return t.x=e.y,t.y=-e.x,t}function l(t,e){return t.x=-e.y,t.y=e.x,t}function y(t,e){return t.x=e.x,t.y=e.y,t}function s(t,e){return t.x=-e.x,t.y=-e.y,t}function o(t){return Math.sqrt(t.x*t.x+t.y*t.y)}function h(t,e){return t.x*e.y-t.y*e.x}function a(t,e){return t.x*e.x+t.y*e.y}function u(t,e,n,r){return t.x=e.x*n+e.y*r,t.y=e.x*r-e.y*n,t}n.d(e,{i:()=>f});class f{constructor(t,e,n){this._writeVertex=t,this._writeTriangle=e,this._canUseThinTessellation=n,this._prevNormal={x:void 0,y:void 0},this._nextNormal={x:void 0,y:void 0},this._textureNormalLeft={x:0,y:1},this._textureNormalRight={x:0,y:-1},this._textureNormal={x:void 0,y:void 0},this._joinNormal={x:void 0,y:void 0},this._inner={x:void 0,y:void 0},this._outer={x:void 0,y:void 0},this._roundStart={x:void 0,y:void 0},this._roundEnd={x:void 0,y:void 0},this._startBreak={x:void 0,y:void 0},this._endBreak={x:void 0,y:void 0},this._innerPrev={x:void 0,y:void 0},this._innerNext={x:void 0,y:void 0},this._bevelStart={x:void 0,y:void 0},this._bevelEnd={x:void 0,y:void 0},this._bevelMiddle={x:void 0,y:void 0}}tessellate(t,e,n=this._canUseThinTessellation){i(t),n&&e.halfWidth<1.05&&!e.offset?this._tessellateThin(t,e):this._tessellate(t,e)}_tessellateThin(t,e){if(t.length<2)return;let n=e.wrapDistance||65535,r=e.initialDistance||0,i=!1,x=t[0].x,l=t[0].y,y=t.length;for(let e=1;e<y;++e){i&&(i=!1,r=0);let y=t[e].x,s=t[e].y,o=y-x,h=s-l,a=Math.sqrt(o*o+h*h);if(o/=a,h/=a,r+a>n){i=!0;let t=(n-r)/a;a=n-r,y=(1-t)*x+t*y,s=(1-t)*l+t*s,--e}let u=this._writeVertex(x,l,0,0,o,h,h,-o,0,-1,r),f=this._writeVertex(x,l,0,0,o,h,-h,o,0,1,r);r+=a;let c=this._writeVertex(y,s,0,0,o,h,h,-o,0,-1,r),_=this._writeVertex(y,s,0,0,o,h,-h,o,0,1,r);this._writeTriangle(u,f,c),this._writeTriangle(f,c,_),x=y,l=s}}_tessellate(t,e){let n=t[0],i=t[t.length-1],f=r(n,i),c=f?3:2;if(t.length<c)return;let _,d,v,w,p,g=e.pixelCoordRatio,b=null==e.capType?0:e.capType,m=null==e.joinType?2:e.joinType,M=null==e.miterLimit?2:Math.min(e.miterLimit,4),A=null==e.roundLimit?1.05:Math.min(e.roundLimit,1.05),T=null==e.halfWidth?2:e.halfWidth,k=!!e.textured,V=null,E=this._prevNormal,N=this._nextNormal,U=-1,Z=-1,C=this._joinNormal,P=this._textureNormalLeft,S=this._textureNormalRight,z=this._textureNormal,L=-1,B=-1,F=e.wrapDistance||65535,R=e.initialDistance||0,I=this._writeVertex,j=this._writeTriangle,D=(t,e,n,r,i,x)=>{let l=I(d,v,w,p,n,r,t,e,i,x,R);return L>=0&&B>=0&&l>=0&&j(L,B,l),L=B,B=l,l};f&&(_=t[t.length-2],N.x=i.x-_.x,N.y=i.y-_.y,Z=o(N),N.x/=Z,N.y/=Z);let W=!1;for(let e=0;e<t.length;++e){if(W&&(W=!1,R=0),_&&(E.x=-N.x,E.y=-N.y,U=Z,R+U>F&&(W=!0)),W){let n=(F-R)/U;U=F-R,_={x:(1-n)*_.x+n*t[e].x,y:(1-n)*_.y+n*t[e].y},--e}else _=t[e];d=_.x,v=_.y;let n=e<=0&&!W,r=e===t.length-1;if(n||(R+=U),V=r?f?t[1]:null:t[e+1],V?(N.x=V.x-d,N.y=V.y-v,Z=o(N),N.x/=Z,N.y/=Z):(N.x=void 0,N.y=void 0),!f){if(n){l(C,N),w=C.x,p=C.y,2===b&&(D(-N.y-N.x,N.x-N.y,N.x,N.y,0,-1),D(N.y-N.x,-N.x-N.y,N.x,N.y,0,1)),1===b&&(D(-N.y-N.x,N.x-N.y,N.x,N.y,-1,-1),D(N.y-N.x,-N.x-N.y,N.x,N.y,-1,1)),(1===b||0===b)&&(D(-N.y,N.x,N.x,N.y,0,-1),D(N.y,-N.x,N.x,N.y,0,1));continue}if(r){x(C,E),w=C.x,p=C.y,(1===b||0===b)&&(D(E.y,-E.x,-E.x,-E.y,0,-1),D(-E.y,E.x,-E.x,-E.y,0,1)),2===b&&(D(E.y-E.x,-E.x-E.y,-E.x,-E.y,0,-1),D(-E.y-E.x,E.x-E.y,-E.x,-E.y,0,1)),1===b&&(D(E.y-E.x,-E.x-E.y,-E.x,-E.y,1,-1),D(-E.y-E.x,E.x-E.y,-E.x,-E.y,1,1));continue}}let i,c,I=-h(E,N);if(Math.abs(I)<.01)a(E,N)>0?(C.x=E.x,C.y=E.y,I=1,i=Number.MAX_VALUE,c=!0):(l(C,N),I=1,i=1,c=!1);else{C.x=(E.x+N.x)/I,C.y=(E.y+N.y)/I,i=o(C);let t=(i-1)*T*g;c=i>4||t>U&&t>Z}w=C.x,p=C.y;let j=m;switch(m){case 0:i<1.05&&(j=2);break;case 1:i<A&&(j=2);break;case 2:i>M&&(j=0)}switch(j){case 2:if(D(C.x,C.y,-E.x,-E.y,0,-1),D(-C.x,-C.y,-E.x,-E.y,0,1),r)break;if(k){let t=W?0:R;L=this._writeVertex(d,v,w,p,N.x,N.y,C.x,C.y,0,-1,t),B=this._writeVertex(d,v,w,p,N.x,N.y,-C.x,-C.y,0,1,t)}break;case 0:{let t,e,n,i,o=I<0;if(o){let n=L;L=B,B=n,t=P,e=S}else t=S,e=P;if(c)n=o?l(this._innerPrev,E):x(this._innerPrev,E),i=o?x(this._innerNext,N):l(this._innerNext,N);else{let t=o?s(this._inner,C):y(this._inner,C);n=t,i=t}let h=o?x(this._bevelStart,E):l(this._bevelStart,E);D(n.x,n.y,-E.x,-E.y,t.x,t.y);let a=D(h.x,h.y,-E.x,-E.y,e.x,e.y);if(r)break;let f=o?l(this._bevelEnd,N):x(this._bevelEnd,N);if(c){let n=this._writeVertex(d,v,w,p,-E.x,-E.y,0,0,0,0,R);L=this._writeVertex(d,v,w,p,N.x,N.y,i.x,i.y,t.x,t.y,R),B=this._writeVertex(d,v,w,p,N.x,N.y,f.x,f.y,e.x,e.y,R),this._writeTriangle(a,n,B)}else{if(k){let e=this._bevelMiddle;e.x=(h.x+f.x)/2,e.y=(h.y+f.y)/2,u(z,e,-E.x,-E.y),D(e.x,e.y,-E.x,-E.y,z.x,z.y),u(z,e,N.x,N.y),L=this._writeVertex(d,v,w,p,N.x,N.y,e.x,e.y,z.x,z.y,R),B=this._writeVertex(d,v,w,p,N.x,N.y,i.x,i.y,t.x,t.y,R)}else{let t=L;L=B,B=t}D(f.x,f.y,N.x,N.y,e.x,e.y)}if(o){let t=L;L=B,B=t}break}case 1:{let t,e,n=I<0;if(n){let n=L;L=B,B=n,t=P,e=S}else t=S,e=P;let o,h,f=n?s(this._inner,C):y(this._inner,C);c?(o=n?l(this._innerPrev,E):x(this._innerPrev,E),h=n?x(this._innerNext,N):l(this._innerNext,N)):(o=f,h=f);let _=n?x(this._roundStart,E):l(this._roundStart,E),g=n?l(this._roundEnd,N):x(this._roundEnd,N),b=D(o.x,o.y,-E.x,-E.y,t.x,t.y),m=D(_.x,_.y,-E.x,-E.y,e.x,e.y);if(r)break;let M=this._writeVertex(d,v,w,p,-E.x,-E.y,0,0,0,0,R);c||this._writeTriangle(L,B,M);let A,T,V=s(this._outer,f),U=this._writeVertex(d,v,w,p,N.x,N.y,g.x,g.y,e.x,e.y,R),Z=i>2;if(Z){let t;i===Number.MAX_VALUE?t=-1:(V.x/=i,V.y/=i,t=a(E,V),t=(i*(t*t-1)+1)/t),A=n?x(this._startBreak,E):l(this._startBreak,E),A.x+=E.x*t,A.y+=E.y*t,T=n?l(this._endBreak,N):x(this._endBreak,N),T.x+=N.x*t,T.y+=N.y*t}u(z,V,-E.x,-E.y);let F=this._writeVertex(d,v,w,p,-E.x,-E.y,V.x,V.y,z.x,z.y,R);u(z,V,N.x,N.y);let j=k?this._writeVertex(d,v,w,p,N.x,N.y,V.x,V.y,z.x,z.y,R):F,W=M,q=k?this._writeVertex(d,v,w,p,N.x,N.y,0,0,0,0,R):M,H=-1,O=-1;if(Z&&(u(z,A,-E.x,-E.y),H=this._writeVertex(d,v,w,p,-E.x,-E.y,A.x,A.y,z.x,z.y,R),u(z,T,N.x,N.y),O=this._writeVertex(d,v,w,p,N.x,N.y,T.x,T.y,z.x,z.y,R)),k?Z?(this._writeTriangle(W,m,H),this._writeTriangle(W,H,F),this._writeTriangle(q,j,O),this._writeTriangle(q,O,U)):(this._writeTriangle(W,m,F),this._writeTriangle(q,j,U)):Z?(this._writeTriangle(M,m,H),this._writeTriangle(M,H,O),this._writeTriangle(M,O,U)):(this._writeTriangle(M,m,F),this._writeTriangle(M,j,U)),c?(L=this._writeVertex(d,v,w,p,N.x,N.y,h.x,h.y,t.x,t.y,R),B=U):(L=k?this._writeVertex(d,v,w,p,N.x,N.y,h.x,h.y,t.x,t.y,R):b,this._writeTriangle(L,q,U),B=U),n){let t=L;L=B,B=t}break}}}}}}}]);