@arcgis/core 5.0.0-next.32 → 5.0.0-next.34

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 (285) hide show
  1. package/assets/esri/core/workers/RemoteClient.js +1 -1
  2. package/assets/esri/core/workers/chunks/{9252854b512237b6a0ef.js → 0446562aee0639c61485.js} +1 -1
  3. package/assets/esri/core/workers/chunks/{b56c07c0b43cb1999070.js → 1fa55d4c4b092a98bdd7.js} +1 -1
  4. package/assets/esri/core/workers/chunks/22f745539ca54d8cd30d.js +1 -0
  5. package/assets/esri/core/workers/chunks/2613e482450b57f2d4f5.js +1 -0
  6. package/assets/esri/core/workers/chunks/{e7f4d135ef9665de1468.js → 33431e8131f6017de2f9.js} +1 -1
  7. package/assets/esri/core/workers/chunks/{1dfca37f95f2b968aa54.js → 39d2b540738431adec98.js} +1 -1
  8. package/assets/esri/core/workers/chunks/{096e5f94eaa226814569.js → 4356274cfa477eb6d749.js} +1 -1
  9. package/assets/esri/core/workers/chunks/44b6b7418cbf7f778bef.js +1 -0
  10. package/assets/esri/core/workers/chunks/4675ed3ca3e0104d00bf.js +1 -0
  11. package/assets/esri/core/workers/chunks/{25fd0884dd14973c89f5.js → 486e69261aa2caf9ec3c.js} +1 -1
  12. package/assets/esri/core/workers/chunks/{3c1e50c3505e5e7c946a.js → 4d5591c1b4ef37075921.js} +1 -1
  13. package/assets/esri/core/workers/chunks/4df7cc3477bc46fc39af.js +1 -0
  14. package/assets/esri/core/workers/chunks/52ecbaa2d32692d6d8df.js +1 -0
  15. package/assets/esri/core/workers/chunks/{3777b41b4fa2f1418402.js → 55818fe7a7aa1e5c8bbd.js} +1 -1
  16. package/assets/esri/core/workers/chunks/{d21ae4980741be98f948.js → 59889855d23baec1adf9.js} +1 -1
  17. package/assets/esri/core/workers/chunks/{7e6fae3660e7a6a0fa16.js → 5f781ef46ce7c4048c2f.js} +1 -1
  18. package/assets/esri/core/workers/chunks/5f9e64f00329cb646f0c.js +1 -0
  19. package/assets/esri/core/workers/chunks/61cb30e2e8edd18ebbf0.js +1 -0
  20. package/assets/esri/core/workers/chunks/63933cbcb5c12df09715.js +1 -0
  21. package/assets/esri/core/workers/chunks/706423d801fa9cbf2e90.js +1 -0
  22. package/assets/esri/core/workers/chunks/{e6df4327ac1d9b65b80d.js → 71dd80231ea656a6380c.js} +1 -1
  23. package/assets/esri/core/workers/chunks/725819839434c59102f3.js +1 -0
  24. package/assets/esri/core/workers/chunks/{d786b17cc9062b1450ac.js → 726a797f5df7eeee0b3d.js} +1 -1
  25. package/assets/esri/core/workers/chunks/72cebf18da5ec5eeb666.js +1 -0
  26. package/assets/esri/core/workers/chunks/{bd58c027408dc858f23c.js → 77b45957cfe42523c1c8.js} +1 -1
  27. package/assets/esri/core/workers/chunks/{a2cee5ac0d4df0108425.js → 82cc758bddd9f8397b9f.js} +1 -1
  28. package/assets/esri/core/workers/chunks/852de585a72d902344a6.js +1 -0
  29. package/assets/esri/core/workers/chunks/871dd5e1f016a04b8d98.js +1 -0
  30. package/assets/esri/core/workers/chunks/892c417f5130b003889d.js +1 -0
  31. package/assets/esri/core/workers/chunks/907083c427d7fb4354e9.js +1 -0
  32. package/assets/esri/core/workers/chunks/{433d249c35c56bf15806.js → 97650ee3d0eecb69ccbb.js} +3 -3
  33. package/assets/esri/core/workers/chunks/{add17e95f47e6904bf6d.js → a59dab47a58695c639da.js} +1 -1
  34. package/assets/esri/core/workers/chunks/{f441fc74451330384fb0.js → abb05a903440d97a6a74.js} +1 -1
  35. package/assets/esri/core/workers/chunks/{3bacd904cd93c8013f6a.js → ae793d814cf32db9fbde.js} +1 -1
  36. package/assets/esri/core/workers/chunks/{e0b70652da4a7f672cfc.js → b21cf62652ca772108c8.js} +1 -1
  37. package/assets/esri/core/workers/chunks/{5baef729beef0199c3d9.js → b536fdb655ad293d9024.js} +1 -1
  38. package/assets/esri/core/workers/chunks/{1d4ea8db272655c0608c.js → c7c721de93bc8688e13c.js} +1 -1
  39. package/assets/esri/core/workers/chunks/c82a974c8448407885e6.js +1 -0
  40. package/assets/esri/core/workers/chunks/c8d2cce4a426c72ab173.js +1 -0
  41. package/assets/esri/core/workers/chunks/c9c2e00fed979c21e2f0.js +1 -0
  42. package/assets/esri/core/workers/chunks/{94005916d321c879bea1.js → cb500d673ca7ec1ef945.js} +1 -1
  43. package/assets/esri/core/workers/chunks/{14feb12826e0c8ba7fb8.js → d14bd320f72d8e8a0ad8.js} +1 -1
  44. package/assets/esri/core/workers/chunks/d239a4ef60e348cfb05a.js +1 -0
  45. package/assets/esri/core/workers/chunks/{4b6a44c6265c8959abd8.js → d3db7244fac7398cc700.js} +1 -1
  46. package/assets/esri/core/workers/chunks/d6d03f22c91f528b97e5.js +1 -0
  47. package/assets/esri/core/workers/chunks/{4ab89c990a82c745c0fd.js → d764b6273974f4bca31b.js} +1 -1
  48. package/assets/esri/core/workers/chunks/d86e59da76eea888ba86.js +1 -0
  49. package/assets/esri/core/workers/chunks/dc3a4ad62bc041a4f899.js +1 -0
  50. package/assets/esri/core/workers/chunks/{7aa730e5ac7b268e3c98.js → dd34d56caafa38d4b8e4.js} +1 -1
  51. package/assets/esri/core/workers/chunks/df458ad51be27df3d79d.js +1 -0
  52. package/assets/esri/core/workers/chunks/{01b8e680befff83e7d3e.js → e093e745708f722bc1b9.js} +1 -1
  53. package/assets/esri/core/workers/chunks/e3a994587f9b2e88db85.js +1 -0
  54. package/assets/esri/core/workers/chunks/ea5bf896acfcc3106bf5.js +1 -0
  55. package/assets/esri/core/workers/chunks/{a74e6d505a55ed27f004.js → f11453f24c0b728669d2.js} +1 -1
  56. package/assets/esri/core/workers/chunks/f2ebd6471e1259a6eac0.js +1 -0
  57. package/assets/esri/core/workers/chunks/f3c232fc56a29d51196a.js +1 -0
  58. package/assets/esri/core/workers/chunks/{2a17991923abc64c84c6.js → f55328aabf84770c8e6a.js} +1 -1
  59. package/assets/esri/core/workers/chunks/fa01d1813fa78034526e.js +1 -0
  60. package/assets/esri/libs/lyr3d/lyr3DMain.wasm +0 -0
  61. package/chunks/ComponentShader.glsl.js +19 -21
  62. package/chunks/Envelope.js +1 -1
  63. package/chunks/GaussianSplat.glsl.js +2 -2
  64. package/chunks/Geometry.js +1 -1
  65. package/chunks/GlowComposition.glsl.js +5 -5
  66. package/chunks/Laserlines.glsl.js +1 -1
  67. package/chunks/MultiPathImpl.js +1 -1
  68. package/chunks/Point2D.js +1 -1
  69. package/chunks/Terrain.glsl.js +9 -11
  70. package/chunks/UnitFactory.js +1 -1
  71. package/chunks/boundedPlane.js +1 -1
  72. package/chunks/cameraUtilsSpherical.js +1 -1
  73. package/chunks/lyr3DMain.js +1 -1
  74. package/chunks/vec32.js +1 -1
  75. package/config.js +1 -1
  76. package/core/deprecate.js +1 -1
  77. package/core/has.js +1 -1
  78. package/core/libs/gl-matrix-2/math/quat.js +1 -1
  79. package/core/libs/gl-matrix-2/math/vec3.js +1 -1
  80. package/geometry/SpatialReference.js +1 -1
  81. package/geometry/operators/integrateOperator.js +1 -1
  82. package/geometry/operators/support/apiConverter.js +1 -1
  83. package/geometry/operators/support/jsonConverter.js +1 -1
  84. package/geometry/support/lineSegment.js +1 -1
  85. package/geometry/support/meshUtils/merge.js +1 -1
  86. package/geometry/support/spatialReferenceUtils.js +1 -1
  87. package/geometry/support/sphere.js +1 -1
  88. package/interfaces.d.ts +522 -5
  89. package/intl/locale.js +1 -1
  90. package/kernel.js +1 -1
  91. package/layers/Lyr3DWasmPerSceneView.js +1 -1
  92. package/layers/VoxelWasmPerSceneView.js +1 -1
  93. package/layers/catalog/CatalogDynamicGroupLayer.js +1 -1
  94. package/layers/graphics/data/AttributesBuilder.js +1 -1
  95. package/layers/graphics/data/QueryEngineResult.js +1 -1
  96. package/layers/mixins/ArcGISImageService.js +1 -1
  97. package/layers/orientedImagery/transformations/worldToImage.js +1 -1
  98. package/layers/support/layerOriginUtils.js +1 -1
  99. package/layers/voxel/VoxelVolume.js +1 -1
  100. package/package.json +3 -3
  101. package/portal/schemas/definitions.js +1 -1
  102. package/request/config.js +1 -1
  103. package/request/process.js +1 -1
  104. package/rest/query/operations/query.js +1 -1
  105. package/rest/support/LocateSetting.d.ts +4 -0
  106. package/rest/support/LocateSetting.js +5 -0
  107. package/rest/support/LocateSettingBase.d.ts +4 -0
  108. package/rest/support/LocateSettingBase.js +5 -0
  109. package/rest/support/LocateSettingSource.d.ts +4 -0
  110. package/rest/support/LocateSettingSource.js +5 -0
  111. package/rest/support/LocateSettings.d.ts +4 -0
  112. package/rest/support/LocateSettings.js +5 -0
  113. package/rest/support/LocateSettingsOverrides.d.ts +4 -0
  114. package/rest/support/LocateSettingsOverrides.js +5 -0
  115. package/rest/support/RouteParameters.js +1 -1
  116. package/statistics/utils.js +1 -1
  117. package/support/revision.js +1 -1
  118. package/views/3d/GroundView3D.js +1 -1
  119. package/views/3d/analysis/AreaMeasurement/support/MeasurementData.js +1 -1
  120. package/views/3d/analysis/Dimension/lengthDimensionConstraintUtils.js +1 -1
  121. package/views/3d/analysis/Dimension/lengthDimensionUtils.js +1 -1
  122. package/views/3d/analysis/LineOfSight/LineOfSightController.js +1 -1
  123. package/views/3d/analysis/LineOfSight/LineOfSightIntersectionResult.js +1 -1
  124. package/views/3d/analysis/LineOfSight/LineOfSightRayIntersector.js +1 -1
  125. package/views/3d/analysis/Slice/sliceToolUtils.js +1 -1
  126. package/views/3d/analysis/Viewshed/ViewshedScaleOrientManipulation.js +1 -1
  127. package/views/3d/analysis/Viewshed/ViewshedSubTool.js +1 -1
  128. package/views/3d/analysis/Viewshed/ViewshedSubVisualization.js +1 -1
  129. package/views/3d/analysis/Viewshed/ViewshedTool.js +1 -1
  130. package/views/3d/animation/pointToPoint/Camera.js +1 -1
  131. package/views/3d/camera/constraintUtils/distance.js +1 -1
  132. package/views/3d/camera/constraintUtils/tilt.js +1 -1
  133. package/views/3d/environment/ChapmanAtmosphere.js +1 -1
  134. package/views/3d/environment/CloudsParameters.js +1 -1
  135. package/views/3d/environment/EnvironmentManager.js +1 -1
  136. package/views/3d/environment/MarsAtmosphere.js +1 -1
  137. package/views/3d/interactive/editingTools/manipulations/MoveZManipulation.js +1 -1
  138. package/views/3d/interactive/editingTools/media/MediaElementManipulator3D.js +1 -1
  139. package/views/3d/interactive/editingTools/reshape/edgeOffsetUtils.js +1 -1
  140. package/views/3d/interactive/visualElements/MeasurementArrowVisualElement.js +1 -1
  141. package/views/3d/interactive/visualElements/RightAngleQuadVisualElement.js +1 -1
  142. package/views/3d/layers/GaussianSplatLayerView3D.js +1 -1
  143. package/views/3d/layers/I3SMeshView3D.js +1 -1
  144. package/views/3d/layers/IntegratedMesh3DTilesLayerView3D.js +1 -1
  145. package/views/3d/layers/graphics/Graphics3DFrustumVisibility.js +1 -1
  146. package/views/3d/layers/graphics/objectResourceUtils.js +1 -1
  147. package/views/3d/layers/i3s/I3SIndex.js +1 -1
  148. package/views/3d/layers/i3s/I3SViewportQueries.js +1 -1
  149. package/views/3d/layers/i3s/LayerElevationProvider.js +1 -1
  150. package/views/3d/layers/i3s/PointCloudRenderer.js +1 -1
  151. package/views/3d/layers/support/FeatureTileMeasurements3D.js +1 -1
  152. package/views/3d/layers/support/FeatureTileVisibility3D.js +1 -1
  153. package/views/3d/state/ConstraintsManager.js +1 -1
  154. package/views/3d/state/Frustum.js +1 -1
  155. package/views/3d/state/NearFarHeuristic.js +1 -1
  156. package/views/3d/state/controllers/FovController.js +1 -1
  157. package/views/3d/state/controllers/GamepadKeyboardController.js +1 -1
  158. package/views/3d/state/controllers/momentum/ZoomPlanarMomentumController.js +1 -1
  159. package/views/3d/state/helpers/SceneIntersectionHelper.js +1 -1
  160. package/views/3d/support/CombinedElevationProvider.js +1 -1
  161. package/views/3d/support/ElevationRange.js +1 -1
  162. package/views/3d/support/FrustumExtentIntersection.js +1 -1
  163. package/views/3d/support/cameraUtils.js +1 -1
  164. package/views/3d/support/gaussianSplatting/GaussianSplatDataStore.js +1 -1
  165. package/views/3d/support/gaussianSplatting/GaussianSplatFadeHelper.js +5 -0
  166. package/views/3d/support/gaussianSplatting/GaussianSplatFadeTexture.js +5 -0
  167. package/views/3d/support/gaussianSplatting/GaussianSplatOrderTexture.js +1 -1
  168. package/views/3d/support/gaussianSplatting/GaussianTile.js +1 -1
  169. package/views/3d/support/intersectionUtils.js +1 -1
  170. package/views/3d/support/pointsOfInterest/CameraOnSurface.js +1 -1
  171. package/views/3d/support/pointsOfInterest/CenterOnSurface.js +1 -1
  172. package/views/3d/support/pointsOfInterest/Focus.js +1 -1
  173. package/views/3d/support/viewpointUtils.js +1 -1
  174. package/views/3d/terrain/ElevationBounds.js +1 -1
  175. package/views/3d/terrain/ElevationData.js +1 -1
  176. package/views/3d/terrain/OverlayManager.js +1 -1
  177. package/views/3d/terrain/PatchRenderData.js +1 -1
  178. package/views/3d/terrain/SphericalPatch.js +1 -1
  179. package/views/3d/terrain/TerrainSurface.js +1 -1
  180. package/views/3d/terrain/Tile.js +1 -1
  181. package/views/3d/webgl/RenderCamera.js +1 -1
  182. package/views/3d/webgl-engine/collections/Component/ComponentObject.js +1 -1
  183. package/views/3d/webgl-engine/collections/Component/ComponentObjectCollection.js +1 -1
  184. package/views/3d/webgl-engine/collections/Component/Material/ComponentData.glsl.js +57 -0
  185. package/views/3d/webgl-engine/collections/Component/Material/ComponentDataConstants.js +5 -0
  186. package/views/3d/webgl-engine/collections/Component/Material/ComponentMaterial.js +1 -1
  187. package/views/3d/webgl-engine/collections/Component/Material/ComponentShader.glsl.js +5 -0
  188. package/views/3d/webgl-engine/collections/Component/Material/ComponentTechnique.js +1 -1
  189. package/views/3d/webgl-engine/collections/Component/Material/ComponentTechniqueConfiguration.js +1 -1
  190. package/views/3d/webgl-engine/collections/Component/Material/{shader/DecodeSymbolColor.glsl.js → DecodeSymbolColor.glsl.js} +1 -1
  191. package/views/3d/webgl-engine/core/shaderLibrary/Slice.glsl.js +1 -1
  192. package/views/3d/webgl-engine/core/shaderLibrary/TextureBackedBuffer.glsl.js +10 -13
  193. package/views/3d/webgl-engine/core/shaderLibrary/TextureBackedBufferFields.glsl.js +7 -1
  194. package/views/3d/webgl-engine/core/shaderLibrary/util/GaussianSplatUnpacking.glsl.js +1 -1
  195. package/views/3d/webgl-engine/effects/glow/GlowComposition.glsl.js +1 -1
  196. package/views/3d/webgl-engine/effects/glow/GlowCompositionTechnique.js +1 -1
  197. package/views/3d/webgl-engine/effects/glow/GlowPresets.glsl.js +1 -1
  198. package/views/3d/webgl-engine/effects/glow/GlowRenderNode.js +1 -1
  199. package/views/3d/webgl-engine/effects/haze/Haze.js +1 -1
  200. package/views/3d/webgl-engine/lib/GaussianSplatRenderNode.js +1 -1
  201. package/views/3d/webgl-engine/lib/Object3D.js +1 -1
  202. package/views/3d/webgl-engine/lib/ShadowAccumulator.js +1 -1
  203. package/views/3d/webgl-engine/lib/TextureBackedBuffer/BufferManager.js +1 -1
  204. package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBackedBuffer.js +1 -1
  205. package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBackedBufferFields.js +1 -1
  206. package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBackedBufferLayout.js +1 -1
  207. package/views/3d/webgl-engine/lib/Viewshed.js +1 -1
  208. package/views/3d/webgl-engine/lib/edgeRendering/EdgeView.js +1 -1
  209. package/views/3d/webgl-engine/lib/edgeRendering/bufferLayouts.js +1 -1
  210. package/views/3d/webgl-engine/lib/edgeRendering/edgePreprocessing.js +1 -1
  211. package/views/3d/webgl-engine/lib/geometryDataUtils.js +1 -1
  212. package/views/3d/webgl-engine/lib/triangleIntersectionUtils.js +1 -1
  213. package/views/3d/webgl-engine/materials/DefaultLayouts.js +1 -1
  214. package/views/3d/webgl-engine/materials/HUDMaterial.js +1 -1
  215. package/views/3d/webgl-engine/materials/LineMarkerMaterial.js +1 -1
  216. package/views/3d/webgl-engine/materials/MeasurementArrowMaterial.js +1 -1
  217. package/views/3d/webgl-engine/materials/NativeLineMaterial.js +1 -1
  218. package/views/3d/webgl-engine/materials/RibbonLineMaterial.js +1 -1
  219. package/views/3d/webgl-engine/parts/RenderView.js +1 -1
  220. package/views/3d/webgl-engine/shaders/GaussianSplatTechniqueConfiguration.js +1 -1
  221. package/views/3d/webgl-engine/shaders/SphereDepthInterpolate.glsl.js +1 -1
  222. package/views/3d/webgl-engine/shaders/sources/edgeRenderer/EdgeUtil.glsl.js +24 -31
  223. package/views/Attribution.js +1 -1
  224. package/views/DOMContainer.js +1 -1
  225. package/views/SelectionManager.js +1 -1
  226. package/views/View.js +1 -1
  227. package/views/interactive/GraphicManipulator.js +1 -1
  228. package/views/interactive/SegmentLabels.js +1 -1
  229. package/views/interactive/coordinateHelper.js +1 -1
  230. package/views/interactive/editGeometry/operations/OffsetEdgeVertex.js +1 -1
  231. package/views/interactive/sketch/constraints.js +1 -1
  232. package/views/interactive/snapping/featureSources/sceneLayerSource/SceneLayerSnappingSourceWorker.js +1 -1
  233. package/views/interactive/snapping/featureSources/sceneLayerSource/sceneLayerSnappingUtils.js +1 -1
  234. package/views/interactive/snapping/hints/LineSnappingHint.js +1 -1
  235. package/views/interactive/tooltip/tooltipCommonUtils.js +1 -1
  236. package/views/navigation/PanSphericalMomentumEstimator.js +1 -1
  237. package/views/support/GroundElevationSampler.js +1 -1
  238. package/views/support/euclideanAreaMeasurementUtils.js +1 -1
  239. package/views/support/euclideanLengthMeasurementUtils.js +1 -1
  240. package/views/support/geometry3dUtils.js +1 -1
  241. package/views/support/selectionUtils.js +1 -1
  242. package/widgets/Attachments/AttachmentsViewModel.js +1 -1
  243. package/widgets/BuildingExplorer/BuildingExplorerViewModel.js +1 -1
  244. package/widgets/BuildingExplorer/BuildingNumericFilterViewModel.js +1 -1
  245. package/widgets/BuildingExplorer.js +1 -1
  246. package/widgets/Editor/EditorViewModel.js +1 -1
  247. package/widgets/FeatureTable/FeatureTableViewModel.js +1 -1
  248. package/widgets/OrientedImageryViewer/OrientedImageryViewerViewModel.js +1 -1
  249. package/widgets/ShadowCast/DiscreteOptions.js +1 -1
  250. package/widgets/ShadowCast/DurationOptions.js +1 -1
  251. package/widgets/ShadowCast/ShadowCastViewModel.js +1 -1
  252. package/widgets/ShadowCast/ThresholdOptions.js +1 -1
  253. package/widgets/ShadowCast.js +1 -1
  254. package/widgets/support/SelectionList/SelectionListViewModel.js +1 -1
  255. package/assets/esri/core/workers/chunks/0a1df5a724fe253b3866.js +0 -1
  256. package/assets/esri/core/workers/chunks/155d74b9c0ef31dc2316.js +0 -1
  257. package/assets/esri/core/workers/chunks/2c8c48433b380da59831.js +0 -1
  258. package/assets/esri/core/workers/chunks/31b5747a254d13acc58e.js +0 -1
  259. package/assets/esri/core/workers/chunks/3ac84e324d212815e252.js +0 -1
  260. package/assets/esri/core/workers/chunks/41a00c77e6f7ce61e476.js +0 -1
  261. package/assets/esri/core/workers/chunks/45729d006db6a569715f.js +0 -1
  262. package/assets/esri/core/workers/chunks/50cf3cbcad2be1c1e210.js +0 -1
  263. package/assets/esri/core/workers/chunks/565358ea8d1bdc4d1ebc.js +0 -1
  264. package/assets/esri/core/workers/chunks/592afe1a41bed3b0cc31.js +0 -1
  265. package/assets/esri/core/workers/chunks/5aeda8a1f2ccabfdf40f.js +0 -1
  266. package/assets/esri/core/workers/chunks/657d9e5145da1306ace8.js +0 -1
  267. package/assets/esri/core/workers/chunks/7f7a81ed8893ab649af7.js +0 -1
  268. package/assets/esri/core/workers/chunks/7ffef8a19166f6b564d8.js +0 -1
  269. package/assets/esri/core/workers/chunks/819781a209608dcdd678.js +0 -1
  270. package/assets/esri/core/workers/chunks/8d57e3a0e5687ce15557.js +0 -1
  271. package/assets/esri/core/workers/chunks/8e9a5d38da40702def80.js +0 -1
  272. package/assets/esri/core/workers/chunks/aac313257a8b1ae75b75.js +0 -1
  273. package/assets/esri/core/workers/chunks/be06c8a58c217a17451b.js +0 -1
  274. package/assets/esri/core/workers/chunks/d56548a994753b08403c.js +0 -1
  275. package/assets/esri/core/workers/chunks/dd95e679618b7b21a7b1.js +0 -1
  276. package/assets/esri/core/workers/chunks/e08a1934d98e7324776d.js +0 -1
  277. package/assets/esri/core/workers/chunks/e5deb72df8b2505fd325.js +0 -1
  278. package/assets/esri/core/workers/chunks/e689a4849f5af3f2f641.js +0 -1
  279. package/assets/esri/core/workers/chunks/f259ad785ce3aa970792.js +0 -1
  280. package/assets/esri/core/workers/chunks/f3127bdf28a1d9b8db27.js +0 -1
  281. package/assets/esri/core/workers/chunks/f4919950a9a3703d9da3.js +0 -1
  282. package/assets/esri/core/workers/chunks/f6ce485c082d0d640b01.js +0 -1
  283. package/assets/esri/core/workers/chunks/fd9ef4b8c969962cf72b.js +0 -1
  284. package/views/3d/webgl-engine/collections/Component/Material/shader/ComponentData.glsl.js +0 -57
  285. package/views/3d/webgl-engine/collections/Component/Material/shader/ComponentShader.glsl.js +0 -5
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import t from"../request.js";import i from"../core/Accessor.js";import s from"../core/Logger.js";import{isAbortError as r}from"../core/promiseUtils.js";import{watch as a}from"../core/reactiveUtils.js";import{addFrameTask as n}from"../core/scheduling.js";import{property as o,subclass as l}from"../core/accessorSupport/decorators.js";import{isGeographic as d}from"../geometry/support/spatialReferenceUtils.js";import h from"../geometry/support/WKIDUnitConversion.js";import{wasmFailedToInit as _,invalidLayerView as u}from"./ILyr3DWasmPerSceneView.js";import{Lyr3DWorkerHandle as y}from"./Lyr3DWorkerHandle.js";import{loadLyr3DMainWASM as c}from"../libs/lyr3d/Lyr3DModule.js";import{getElevationOffsetInMeters as g}from"../support/elevationInfoUtils.js";import{makeScheduleFunction as m}from"../views/3d/layers/support/makeScheduleFunction.js";const w=3857,b=32662,p=4326,f=5773,L=115700;let M=class extends i{constructor(e){super(e),this._lyr3DMainPromise=null,this._lyr3DMain=null,this._layers=new Map,this._viewSR=null,this._lyr3DBusyCount=0,this._debugFlags=new Set,this._debugLevel=2,this._wasmNotLoaded="method requiring WASM was called when WASM isn't loaded",this._pulseTaskHandle=null,this._debugFlags.add(0),this._debugFlags.add(1),this._debugFlags.add(2)}_debugLog(e,t,i,r=!0){if(this._debugFlags.has(e)&&this._debugLevel>=t){const e=r?`[js] ${i}`:`${i}`;0===t||1===t?s.getLogger(this).error(e):2===t&&s.getLogger(this).warn(e),s.getLogger(this).info(e)}}initialize(){this._debugLevel>2&&(s.getLogger(this).level="info"),this._debugLog(0,3,"Lyr3DWasmPerSceneView.initialize()"),this.addHandles([a(()=>this.view.state?.contentCamera,()=>this._updateWasmCamera())]),this._pulseTaskHandle=n({preRender:()=>this._pulseTask()})}destroy(){this._debugLog(0,3,"Lyr3DWasmPerSceneView.destroy()"),this._lyr3DMain&&(this._layers.forEach(e=>{e.abortController.abort()}),this._lyr3DMain.uninitialize_lyr3d_wasm(),this._lyr3DMain=null);const e=this._workerHandle;e&&e.destroyWasm().then(()=>{this._workerHandle?.destroy(),this._workerHandle=null}),this._pulseTaskHandle?.remove(),this._pulseTaskHandle=null}addLayerView(e){return this._lyr3DMain?this._addLayerView(e):(this._debugLog(0,1,"Lyr3DWasmPerSceneView.add3DTilesLayerView() called when WASM wasn't initialized"),{wasmLayerId:_})}removeLayerView(e){if(!this._lyr3DMain)return this._debugLog(0,1,this._wasmNotLoaded),0;this._doRemoveLayerView(e);const t=this._layers.size;return 0===t&&(this._debugLog(0,3,"Lyr3DWasmPerSceneView.remove3DTilesLayerView() no Lyr3D layers left after removing a layer, destroying"),this.destroy()),t}getValidLayerViewCount(){if(!this._lyr3DMain)return this._debugLog(0,1,this._wasmNotLoaded),0;let e=0;return this._layers.forEach(t=>{t.layerView.wasmLayerId>=0&&++e}),e}setEnabled(e,t){if(!this._lyr3DMain)return void this._debugLog(0,1,this._wasmNotLoaded);const i=this._layers.get(e.wasmLayerId);if(i){this._lyr3DMain.set_enabled(e.wasmLayerId,t),i.needMemoryUsageUpdate=!0;const s=this._isUpdating(i);i.needFrame=!0,s||i.layerView.updatingFlagChanged()}}setLayerOffset(e,t){if(!this._lyr3DMain)return void this._debugLog(0,1,this._wasmNotLoaded);this._layers.get(e.wasmLayerId)&&this._lyr3DMain.set_carto_offset_z(e.wasmLayerId,t)}getAttributionText(){if(!this._lyr3DMain)return this._debugLog(0,1,this._wasmNotLoaded),[];return this._lyr3DMain.get_current_attribution_text().split("|")}onRenderableEvicted(e,t,i){if(!this._lyr3DMain)return void this._debugLog(0,1,this._wasmNotLoaded);this._layers.get(e.wasmLayerId)&&this._lyr3DMain.on_renderable_evicted(e.wasmLayerId,t,i)}setMeshModifications(e,t,i){if(!this._lyr3DMain)return void this._debugLog(0,1,this._wasmNotLoaded);const s=this._layers.get(e.wasmLayerId);if(s){const r=this._lyr3DMain._malloc(8*t.length),a=new Float64Array(this._lyr3DMain.HEAPF64.buffer,r,t.length);for(let e=0;e<t.length;++e)a[e]=t[e];this._lyr3DMain.set_mesh_modification_polygons(e.wasmLayerId,r,t.length,i),this._lyr3DMain._free(r);const n=this._isUpdating(s);s.needFrame=!0,n||s.layerView.updatingFlagChanged()}}isUpdating(e){if(!this._lyr3DMain&&this._lyr3DMainPromise)return!0;const t=this._layers.get(e);return!!t&&(t.outstandingJobCount>0||t.outstandingRenderableCount>0||t.needFrame||this._lyr3DBusyCount>0)}initializeWasm(e,t){return this._lyr3DMain?Promise.resolve():this.view.renderSpatialReference?(this._debugLog(0,3,"Lyr3DWasmPerSceneView.initializeWasm()"),this._lyr3DMainPromise||(this._lyr3DMainPromise=c().then(i=>{this._lyr3DMain=i,this._lyr3DMainPromise=null;const s=this._lyr3DMain.addFunction(this._onNewJob.bind(this),"v"),r=this._lyr3DMain.addFunction(this._onNewRenderable.bind(this),"v"),a=this._lyr3DMain.addFunction(this._freeRenderables.bind(this),"viii"),n=this._lyr3DMain.addFunction(this._setRenderableVisibility.bind(this),"viiii"),o=this._lyr3DMain.addFunction(this._onWasmError.bind(this),"viiii");if(!this.view.renderSpatialReference)return void(this._lyr3DMain=null);this._viewSR=this.view.renderSpatialReference?.toJSON();const l="global"===this.view.viewingMode?5:3;if(5===l)this._viewSR.wkid=this._viewSR.latestWkid=p,this._viewSR.vcsWkid=this._viewSR.latestVcsWkid=f;else if(this.view.renderSpatialReference?.isWebMercator)this._viewSR.wkid=this._viewSR.latestWkid=w,this._viewSR.vcsWkid=this._viewSR.latestVcsWkid=f;else if(this.view.renderSpatialReference?.wkid===b)this._viewSR.wkid=this._viewSR.latestWkid=p,this._viewSR.vcsWkid=this._viewSR.latestVcsWkid=f;else if(!this._viewSR.latestVcsWkid&&!this._viewSR.vcsWkid){const e=this.view.heightModelInfo?.heightModel,t=!e||"gravity-related-height"===e;this._viewSR.vcsWkid=this._viewSR.latestVcsWkid=t?f:L}return this._lyr3DMain.initialize_lyr3d_wasm(o,s,r,a,n,e,t,l,this._cleanUpSR(this._makeSRWasmSerializable(this._viewSR)),Math.max(this._debugLevel,0))?(this._workerHandle=new y(m(this.view.resourceController)),this._workerHandle.promise?this._workerHandle.promise:void 0):(this._lyr3DMain=null,void this._debugLog(0,0,"Lyr3d Main WASM failed to initialize",!1))}).catch(e=>{this._debugLog(0,0,`Lyr3d WASM failed to download error = ${e}`,!1)})),this._lyr3DMainPromise):Promise.reject()}setLodPixelThreshold(e,t){this._lyr3DMain?.set_lod_pixel_threshold(t);const i=this._layers.get(e.wasmLayerId);i&&(i.needFrame=!0)}_pulseTask(){if(this._lyr3DMain){let e=0,t=0;this._layers.forEach(i=>{e+=i.layerView.usedMemory,t+=i.layerView.cachedMemory}),e/=1048576,t/=1048576;const i=this.view.resourceController.memoryController,s=i.usedMemory*i.maxMemory-e;this._lyr3DBusyCount=this._lyr3DMain.frame_pulse(i.memoryFactor,e,t,s,i.maxMemory),this._layers.forEach(e=>{e.needFrame=!1,e.layerView.updatingFlagChanged()})}}_isUpdating(e){return e.outstandingJobCount>0||e.outstandingRenderableCount>0||e.needFrame||this._lyr3DBusyCount>0}_incrementJobCount(e){const t=this._isUpdating(e);e.outstandingJobCount+=1,t||e.layerView.updatingFlagChanged()}_decrementJobCount(e){const t=this._isUpdating(e);e.outstandingJobCount-=1;t!==this._isUpdating(e)&&e.layerView.updatingFlagChanged()}_incrementRenderableCount(e){const t=this._isUpdating(e);e.outstandingRenderableCount+=1,t||e.layerView.updatingFlagChanged()}_decrementRenderableCount(e){const t=this._isUpdating(e);e.outstandingRenderableCount-=1;t!==this._isUpdating(e)&&e.layerView.updatingFlagChanged()}_onJobFailed(e,t,i){t.error.length&&this._debugLog(1,1,t.error,!1),this._lyr3DMain&&this._lyr3DMain.on_job_failed(i.jobId,i.desc),this._decrementJobCount(e)}_onJobSucceeded(e,t,i){if(this._lyr3DMain){const e=t.data.byteLength,s=this._lyr3DMain._malloc(e);new Uint8Array(this._lyr3DMain.HEAPU8.buffer,s,e).set(t.data),this._lyr3DMain.on_job_completed(i.jobId,t.jobDescJson,s,e),this._lyr3DMain._free(s)}this._decrementJobCount(e)}_getRequestPromises(e,i,s,r){const a=[];for(const n of e){const e=new URL(n);if("integrated-mesh-3dtiles"===r.type){if(e.origin===s.origin&&e.pathname===s.pathname){if(r.rootTileset){a.push(Promise.resolve(r.rootTileset.slice()));continue}}else r.session&&e.searchParams.append("session",r.session)}a.push(t(e.toString(),i).then(e=>e.data))}return a}_getInitialPromise(e,t,i,s,a,n,o){const l=this._getRequestPromises(e.urls,t,i,s);return Promise.all(l).then(e=>(a.inputs=e,this._workerHandle.invoke(a,n))).then(e=>e).catch(t=>{let i=1;return r(t)?this._debugLog(1,2,`job ${e.jobId} was cancelled.`):o&&400===t.details?.httpStatus?(i=3,this._debugLog(1,2,"Session expired, trying to create new Session.")):this._debugLog(1,1,`job ${e.jobId} failed with error ${t}.`),{status:i,error:"",jobDescJson:"",data:new Uint8Array(0),missingInputUrls:[],inputs:[]}})}async _onNewJob(){const e=this._lyr3DMain.get_next_job(),t=this._layers.get(e.layerId);if(!t)return;this._incrementJobCount(t);const i=t.abortController.signal,s=t.layerView.layer,a="integrated-mesh-3dtiles"===s.type?s.key:null,n="integrated-mesh-3dtiles"===s.type?s.session:null,o={responseType:"array-buffer",signal:i,query:{...t.customParameters,token:t.apiKey,key:a}},l={id:e.jobId,inputs:[],jobDescJson:e.desc.slice(),isMissingResourceCase:!1},d=new URL(s.url),h=a=>{if(1===a.status)this._onJobFailed(t,a,e);else if(0===a.status)this._onJobSucceeded(t,a,e);else if(2===a.status){const n=this._getRequestPromises(a.missingInputUrls,o,d,s);Promise.all(n).then(e=>{l.jobDescJson=a.jobDescJson,a.originalInputs?l.inputs=a.originalInputs:l.inputs=[],l.isMissingResourceCase=!0;for(const t of e)l.inputs.push(t);return this._workerHandle.invoke(l,i)}).then(i=>{1===i.status?this._onJobFailed(t,i,e):0===i.status&&this._onJobSucceeded(t,i,e)}).catch(i=>{this._decrementJobCount(t),r(i)?this._debugLog(1,2,`job ${e.jobId} was cancelled.`):this._debugLog(1,1,`job ${e.jobId} failed with error2 ${i}.`),this._lyr3DMain&&this._lyr3DMain.on_job_failed(e.jobId,e.desc)})}};try{const t=await this._getInitialPromise(e,o,d,s,l,i,n);if(3===t.status&&"integrated-mesh-3dtiles"===s.type){n===s.session&&null!==s.session&&await s.requestRootAndSession(i);h(await this._getInitialPromise(e,o,d,s,l,i,s.session))}else h(t)}catch(_){_&&this._debugLog(1,1,_.toString(),!1),this._lyr3DMain&&this._lyr3DMain.on_job_failed(e.jobId,e.desc),this._decrementJobCount(t)}}_onNewRenderable(){const e=this._lyr3DMain.get_next_renderable(),{meshData:t}=e;if(t.data&&t.data.byteLength>0){const e=t.data.slice();t.data=e}const i=this._layers.get(e.layerId);i&&(this._incrementRenderableCount(i),i.layerView.createRenderable(e).then(t=>{this._lyr3DMain?.on_renderable_created(!0,e.layerId,e.handle,t.memUsageBytes),this._decrementRenderableCount(i)}).catch(t=>{r(t)||this._debugLog(2,1,`createRenderable failed with error ${t}.`),this._lyr3DMain?.on_renderable_created(!1,e.layerId,e.handle,0),this._decrementRenderableCount(i)}))}_freeRenderables(e,t,i){if(i<1)return;const s=this._layers.get(e);if(!s)return;const r=s.layerView,a=[],n=new Uint32Array(this._lyr3DMain.HEAPU32.buffer,t,i);for(let o=0;o<i;++o)a.push(n[o]);for(let o=0;o<i;++o)r.freeRenderable(a[o])}_setRenderableVisibility(e,t,i,s){if(s<1)return;const r=this._layers.get(e);if(!r)return;const a=r.layerView,n=[],o=[],l=new Uint32Array(this._lyr3DMain.HEAPU32.buffer,t,s),d=new Uint8Array(this._lyr3DMain.HEAPU8.buffer,i,s);for(let h=0;h<s;++h)n.push(l[h]),o.push(1===d[h]);a.setRenderableVisibility(n,o,s)}_onWasmError(e,t,i,s){this._lyr3DMain&&this._debugLog(i,s,this._lyr3DMain.UTF8ToString(e,t),!1)}_doRemoveLayerView(e){const t=this._layers.get(e.wasmLayerId);return!!t&&(t.abortController.abort(),this._lyr3DMain.remove_layer(e.wasmLayerId),this._layers.delete(e.wasmLayerId),!0)}_isGaussianSplatLayerView(e){return"gaussian-splat"===e.layer.type}_isGaussianSplatLayer(e){return"gaussian-splat"===e.type}_toWasmQuality(e){switch(e){case"low":return 1;case"medium":return 2;case"high":return 3}}_addLayerView(e){const t=e.layer;if(!t.url||!t.rootTilesetJSON)return{wasmLayerId:u};const i="integrated-mesh-3dtiles"===t.type?0:2,r=this._lyr3DMain.validate_root_tileset(JSON.stringify(t.rootTilesetJSON),i);if(0!==r.errorCode)return{wasmLayerId:u,check:r};const a=this._lyr3DMain.get_next_layer_id(),n=new AbortController;this._layers.set(a,{layerView:e,abortController:n,needMemoryUsageUpdate:!1,outstandingJobCount:0,outstandingRenderableCount:0,customParameters:t.customParameters,apiKey:t.apiKey,needFrame:!0});const o=g(t.elevationInfo),l=this._toWasmQuality(this.view?.qualityProfile),_=e=>s.getLogger(this).error("add-spatial-reference-error","Error when adding SR:",e);let y=!1;if(this._isGaussianSplatLayerView(e)&&this._isGaussianSplatLayer(t)){let i=t.spatialReference;if(e.useEsriCrs&&t.esriCrsSpatialReference){i=t.esriCrsSpatialReference;const s=d(i);let r=1,a=1;!s&&i.wkid&&-1!==i.wkid&&(r=h.values[h[i.wkid]],a=e.metersPerVCSUnit),this._workerHandle.addSpatialReferenceInfo(this._cleanUpSR(this._makeSRWasmSerializable(i)),s,r,a).catch(_)}y=this._lyr3DMain.add_gaussian_splat_layer(l,t.url,a,o)}else y=this._lyr3DMain.add_3dtiles_layer(l,t.url,a,o);return y?(this._updateWasmCamera(),e.updatingFlagChanged(),{wasmLayerId:a}):(this._layers.delete(a),{wasmLayerId:u})}_updateWasmCamera(){const e=this.view.state?.contentCamera;if(!e||!this._lyr3DMain)return;const{eye:t,center:i,up:s,near:r,far:a,fovY:n}=e,o=[e.viewport[2],e.viewport[3]],l=e.width/e.height;this._lyr3DMain.set_camera_parameters({eye:t,center:i,up:s,near:r,far:a,fov:n,aspectRatio:l,viewport:o}),this._layers.forEach(e=>{const t=this._isUpdating(e);e.needFrame=!0,t||e.layerView.updatingFlagChanged()})}_makeSRWasmSerializable(e){return{wkid:e?.wkid??-1,latestWkid:e?.latestWkid??-1,vcsWkid:e?.vcsWkid??-1,latestVcsWkid:e?.latestVcsWkid??-1,wkt:e?.wkt??""}}_cleanUpSR(e){return-1===e?.wkid&&e.latestWkid&&-1!==e.latestWkid?e.wkid=e.latestWkid:-1===e?.latestWkid&&e.wkid&&-1!==e.wkid&&(e.latestWkid=e.wkid),-1===e?.vcsWkid&&e.latestVcsWkid&&-1!==e.latestVcsWkid?e.vcsWkid=e.latestVcsWkid:-1===e?.latestVcsWkid&&e.vcsWkid&&-1!==e.vcsWkid&&(e.latestVcsWkid=e.vcsWkid),e}};e([o({constructOnly:!0})],M.prototype,"view",void 0),M=e([l("esri.layers.Lyr3DWasmPerSceneView")],M);const D=M;export{D as default};
5
+ import{__decorate as e}from"tslib";import t from"../request.js";import i from"../core/Accessor.js";import s from"../core/Logger.js";import{isAbortError as r}from"../core/promiseUtils.js";import{watch as a}from"../core/reactiveUtils.js";import{addFrameTask as n}from"../core/scheduling.js";import{property as o,subclass as l}from"../core/accessorSupport/decorators.js";import{clone as d}from"../core/libs/gl-matrix-2/factories/vec3f64.js";import{B as h}from"../chunks/vec32.js";import{canProjectWithoutEngine as _}from"../geometry/projectionUtils.js";import{projectBuffer as u}from"../geometry/projection/projectBuffer.js";import{containsXY as y}from"../geometry/support/aaBoundingRect.js";import{earth as c}from"../geometry/support/Ellipsoid.js";import{isGeographic as g}from"../geometry/support/spatialReferenceUtils.js";import m from"../geometry/support/WKIDUnitConversion.js";import{wasmFailedToInit as w,invalidLayerView as p}from"./ILyr3DWasmPerSceneView.js";import{Lyr3DWorkerHandle as f}from"./Lyr3DWorkerHandle.js";import{loadLyr3DMainWASM as b}from"../libs/lyr3d/Lyr3DModule.js";import{getElevationOffsetInMeters as v}from"../support/elevationInfoUtils.js";import{makeScheduleFunction as M}from"../views/3d/layers/support/makeScheduleFunction.js";const D=3857,L=32662,k=4326,R=5773,S=115700;let C=class extends i{constructor(e){super(e),this._lyr3DMainPromise=null,this._lyr3DMain=null,this._layers=new Map,this._viewSR=null,this._lyr3DBusyCount=0,this._updateCameraElevation=0,this._debugFlags=new Set,this._debugLevel=2,this._wasmNotLoaded="method requiring WASM was called when WASM isn't loaded",this._pulseTaskHandle=null,this._debugFlags.add(0),this._debugFlags.add(1),this._debugFlags.add(2)}_debugLog(e,t,i,r=!0){if(this._debugFlags.has(e)&&this._debugLevel>=t){const e=r?`[js] ${i}`:`${i}`;0===t||1===t?s.getLogger(this).error(e):2===t&&s.getLogger(this).warn(e),s.getLogger(this).info(e)}}initialize(){this._debugLevel>2&&(s.getLogger(this).level="info"),this._debugLog(0,3,"Lyr3DWasmPerSceneView.initialize()"),this.addHandles([this._createElevationUpdateHandle(),a(()=>this.view.state?.contentCamera,()=>this._updateWasmCamera())]),this._pulseTaskHandle=n({preRender:()=>this._pulseTask()})}destroy(){this._debugLog(0,3,"Lyr3DWasmPerSceneView.destroy()"),this._lyr3DMain&&(this._layers.forEach(e=>{e.abortController.abort()}),this._lyr3DMain.uninitialize_lyr3d_wasm(),this._lyr3DMain=null);const e=this._workerHandle;e&&e.destroyWasm().then(()=>{this._workerHandle?.destroy(),this._workerHandle=null}),this._pulseTaskHandle?.remove(),this._pulseTaskHandle=null}addLayerView(e){return this._lyr3DMain?this._addLayerView(e):(this._debugLog(0,1,"Lyr3DWasmPerSceneView.add3DTilesLayerView() called when WASM wasn't initialized"),{wasmLayerId:w})}removeLayerView(e){if(!this._lyr3DMain)return this._debugLog(0,1,this._wasmNotLoaded),0;this._doRemoveLayerView(e);const t=this._layers.size;return 0===t&&(this._debugLog(0,3,"Lyr3DWasmPerSceneView.remove3DTilesLayerView() no Lyr3D layers left after removing a layer, destroying"),this.destroy()),t}getValidLayerViewCount(){if(!this._lyr3DMain)return this._debugLog(0,1,this._wasmNotLoaded),0;let e=0;return this._layers.forEach(t=>{t.layerView.wasmLayerId>=0&&++e}),e}setEnabled(e,t){if(!this._lyr3DMain)return void this._debugLog(0,1,this._wasmNotLoaded);const i=this._layers.get(e.wasmLayerId);if(i){this._lyr3DMain.set_enabled(e.wasmLayerId,t),i.needMemoryUsageUpdate=!0;const s=this._isUpdating(i);i.needFrame=!0,s||i.layerView.updatingFlagChanged()}}setLayerOffset(e,t){if(!this._lyr3DMain)return void this._debugLog(0,1,this._wasmNotLoaded);this._layers.get(e.wasmLayerId)&&this._lyr3DMain.set_carto_offset_z(e.wasmLayerId,t)}getAttributionText(){if(!this._lyr3DMain)return this._debugLog(0,1,this._wasmNotLoaded),[];return this._lyr3DMain.get_current_attribution_text().split("|")}onRenderableEvicted(e,t,i){if(!this._lyr3DMain)return void this._debugLog(0,1,this._wasmNotLoaded);this._layers.get(e.wasmLayerId)&&this._lyr3DMain.on_renderable_evicted(e.wasmLayerId,t,i)}setMeshModifications(e,t,i){if(!this._lyr3DMain)return void this._debugLog(0,1,this._wasmNotLoaded);const s=this._layers.get(e.wasmLayerId);if(s){const r=this._lyr3DMain._malloc(8*t.length),a=new Float64Array(this._lyr3DMain.HEAPF64.buffer,r,t.length);for(let e=0;e<t.length;++e)a[e]=t[e];this._lyr3DMain.set_mesh_modification_polygons(e.wasmLayerId,r,t.length,i),this._lyr3DMain._free(r);const n=this._isUpdating(s);s.needFrame=!0,n||s.layerView.updatingFlagChanged()}}isUpdating(e){if(!this._lyr3DMain&&this._lyr3DMainPromise)return!0;const t=this._layers.get(e);return!!t&&(t.outstandingJobCount>0||t.outstandingRenderableCount>0||t.needFrame||this._lyr3DBusyCount>0)}initializeWasm(e,t){return this._lyr3DMain?Promise.resolve():this.view.renderSpatialReference?(this._debugLog(0,3,"Lyr3DWasmPerSceneView.initializeWasm()"),this._lyr3DMainPromise||(this._lyr3DMainPromise=b().then(i=>{this._lyr3DMain=i,this._lyr3DMainPromise=null;const s=this._lyr3DMain.addFunction(this._onNewJob.bind(this),"v"),r=this._lyr3DMain.addFunction(this._onNewRenderable.bind(this),"v"),a=this._lyr3DMain.addFunction(this._freeRenderables.bind(this),"viii"),n=this._lyr3DMain.addFunction(this._setRenderableVisibility.bind(this),"viiii"),o=this._lyr3DMain.addFunction(this._onWasmError.bind(this),"viiii");if(!this.view.renderSpatialReference)return void(this._lyr3DMain=null);this._viewSR=this.view.renderSpatialReference?.toJSON();const l="global"===this.view.viewingMode?5:3;if(5===l)this._viewSR.wkid=this._viewSR.latestWkid=k,this._viewSR.vcsWkid=this._viewSR.latestVcsWkid=R;else if(this.view.renderSpatialReference?.isWebMercator)this._viewSR.wkid=this._viewSR.latestWkid=D,this._viewSR.vcsWkid=this._viewSR.latestVcsWkid=R;else if(this.view.renderSpatialReference?.wkid===L)this._viewSR.wkid=this._viewSR.latestWkid=k,this._viewSR.vcsWkid=this._viewSR.latestVcsWkid=R;else if(!this._viewSR.latestVcsWkid&&!this._viewSR.vcsWkid){const e=this.view.heightModelInfo?.heightModel,t=!e||"gravity-related-height"===e;this._viewSR.vcsWkid=this._viewSR.latestVcsWkid=t?R:S}return this._lyr3DMain.initialize_lyr3d_wasm(o,s,r,a,n,e,t,l,this._cleanUpSR(this._makeSRWasmSerializable(this._viewSR)),Math.max(this._debugLevel,0))?(this._workerHandle=new f(M(this.view.resourceController)),this._workerHandle.promise?this._workerHandle.promise:void 0):(this._lyr3DMain=null,void this._debugLog(0,0,"Lyr3d Main WASM failed to initialize",!1))}).catch(e=>{this._debugLog(0,0,`Lyr3d WASM failed to download error = ${e}`,!1)})),this._lyr3DMainPromise):Promise.reject()}setLodPixelThreshold(e,t){this._lyr3DMain?.set_lod_pixel_threshold(t);const i=this._layers.get(e.wasmLayerId);i&&(i.needFrame=!0)}_pulseTask(){if(this._lyr3DMain){if(this._updateCameraElevation>0){let e=null;const t=this.view.state?.contentCamera;if(t&&this.view.renderSpatialReference){const{eye:i}=t,s=this.view.groundView.getElevation(i[0],i[1],i[2],this.view.renderSpatialReference);if(s){const t=h(i);e="global"===this.view.viewingMode?t-(c.radius+s):i[2]-s}}e?(this._lyr3DMain.set_camera_altitude(e),this._updateCameraElevation=0):(this._updateCameraElevation-=1,this._updateCameraElevation<=0&&(this._lyr3DMain.set_camera_altitude(0),this._updateCameraElevation=0))}let e=0,t=0;this._layers.forEach(i=>{e+=i.layerView.usedMemory,t+=i.layerView.cachedMemory}),e/=1048576,t/=1048576;const i=this.view.resourceController.memoryController,s=i.usedMemory*i.maxMemory-e;this._lyr3DBusyCount=this._lyr3DMain.frame_pulse(i.memoryFactor,e,t,s,i.maxMemory),this._layers.forEach(e=>{0===this._updateCameraElevation&&(e.needFrame=!1),e.layerView.updatingFlagChanged()})}}_isUpdating(e){return e.outstandingJobCount>0||e.outstandingRenderableCount>0||e.needFrame||this._lyr3DBusyCount>0}_incrementJobCount(e){const t=this._isUpdating(e);e.outstandingJobCount+=1,t||e.layerView.updatingFlagChanged()}_decrementJobCount(e){const t=this._isUpdating(e);e.outstandingJobCount-=1;t!==this._isUpdating(e)&&e.layerView.updatingFlagChanged()}_incrementRenderableCount(e){const t=this._isUpdating(e);e.outstandingRenderableCount+=1,t||e.layerView.updatingFlagChanged()}_decrementRenderableCount(e){const t=this._isUpdating(e);e.outstandingRenderableCount-=1;t!==this._isUpdating(e)&&e.layerView.updatingFlagChanged()}_onJobFailed(e,t,i){t.error.length&&this._debugLog(1,1,t.error,!1),this._lyr3DMain&&this._lyr3DMain.on_job_failed(i.jobId,i.desc),this._decrementJobCount(e)}_onJobSucceeded(e,t,i){if(this._lyr3DMain){if(e.layerView.destroyed)return void this._lyr3DMain.on_job_failed(i.jobId,i.desc);const s=t.data.byteLength,r=this._lyr3DMain._malloc(s);new Uint8Array(this._lyr3DMain.HEAPU8.buffer,r,s).set(t.data),this._lyr3DMain.on_job_completed(i.jobId,t.jobDescJson,r,s),this._lyr3DMain._free(r)}this._decrementJobCount(e)}_getRequestPromises(e,i,s,r){const a=[];for(const n of e){const e=new URL(n);if("integrated-mesh-3dtiles"===r.type){if(e.origin===s.origin&&e.pathname===s.pathname){if(r.rootTileset){a.push(Promise.resolve(r.rootTileset.slice()));continue}}else r.session&&e.searchParams.append("session",r.session)}a.push(t(e.toString(),i).then(e=>e.data))}return a}_getInitialPromise(e,t,i,s,a,n,o){const l=this._getRequestPromises(e.urls,t,i,s);return Promise.all(l).then(e=>(a.inputs=e,this._workerHandle.invoke(a,n))).then(e=>e).catch(t=>{let i=1;return r(t)?this._debugLog(1,2,`job ${e.jobId} was cancelled.`):o&&400===t.details?.httpStatus?(i=3,this._debugLog(1,2,"Session expired, trying to create new Session.")):this._debugLog(1,1,`job ${e.jobId} failed with error ${t}.`),{status:i,error:"",jobDescJson:"",data:new Uint8Array(0),missingInputUrls:[],inputs:[]}})}async _onNewJob(){const e=this._lyr3DMain.get_next_job(),t=this._layers.get(e.layerId);if(!t)return;this._incrementJobCount(t);const i=t.abortController.signal,s=t.layerView.layer,a="integrated-mesh-3dtiles"===s.type?s.key:null,n="integrated-mesh-3dtiles"===s.type?s.session:null,o={responseType:"array-buffer",signal:i,query:{...t.customParameters,token:t.apiKey,key:a}},l={id:e.jobId,inputs:[],jobDescJson:e.desc.slice(),isMissingResourceCase:!1},d=new URL(s.url),h=a=>{if(1===a.status)this._onJobFailed(t,a,e);else if(0===a.status)this._onJobSucceeded(t,a,e);else if(2===a.status){const n=this._getRequestPromises(a.missingInputUrls,o,d,s);Promise.all(n).then(e=>{l.jobDescJson=a.jobDescJson,a.originalInputs?l.inputs=a.originalInputs:l.inputs=[],l.isMissingResourceCase=!0;for(const t of e)l.inputs.push(t);return this._workerHandle.invoke(l,i)}).then(i=>{1===i.status?this._onJobFailed(t,i,e):0===i.status&&this._onJobSucceeded(t,i,e)}).catch(i=>{this._decrementJobCount(t),r(i)?this._debugLog(1,2,`job ${e.jobId} was cancelled.`):this._debugLog(1,1,`job ${e.jobId} failed with error2 ${i}.`),this._lyr3DMain&&this._lyr3DMain.on_job_failed(e.jobId,e.desc)})}};try{const t=await this._getInitialPromise(e,o,d,s,l,i,n);if(3===t.status&&"integrated-mesh-3dtiles"===s.type){n===s.session&&null!==s.session&&await s.requestRootAndSession(i);h(await this._getInitialPromise(e,o,d,s,l,i,s.session))}else h(t)}catch(_){_&&this._debugLog(1,1,_.toString(),!1),this._lyr3DMain&&this._lyr3DMain.on_job_failed(e.jobId,e.desc),this._decrementJobCount(t)}}_onNewRenderable(){const e=this._lyr3DMain.get_next_renderable(),{meshData:t}=e;if(t.data&&t.data.byteLength>0){const e=t.data.slice();t.data=e}const i=this._layers.get(e.layerId);i&&(this._incrementRenderableCount(i),i.layerView.createRenderable(e).then(t=>{this._lyr3DMain?.on_renderable_created(!0,e.layerId,e.handle,t.memUsageBytes),this._decrementRenderableCount(i)}).catch(t=>{r(t)||this._debugLog(2,1,`createRenderable failed with error ${t}.`),this._lyr3DMain?.on_renderable_created(!1,e.layerId,e.handle,0),this._decrementRenderableCount(i)}))}_freeRenderables(e,t,i){if(i<1)return;const s=this._layers.get(e);if(!s)return;const r=s.layerView,a=[],n=new Uint32Array(this._lyr3DMain.HEAPU32.buffer,t,i);for(let o=0;o<i;++o)a.push(n[o]);for(let o=0;o<i;++o)r.freeRenderable(a[o])}_setRenderableVisibility(e,t,i,s){if(s<1)return;const r=this._layers.get(e);if(!r)return;const a=r.layerView,n=[],o=[],l=new Uint32Array(this._lyr3DMain.HEAPU32.buffer,t,s),d=new Uint8Array(this._lyr3DMain.HEAPU8.buffer,i,s);for(let h=0;h<s;++h)n.push(l[h]),o.push(1===d[h]);a.setRenderableVisibility(n,o,s)}_onWasmError(e,t,i,s){this._lyr3DMain&&this._debugLog(i,s,this._lyr3DMain.UTF8ToString(e,t),!1)}_doRemoveLayerView(e){const t=this._layers.get(e.wasmLayerId);return!!t&&(t.abortController.abort(),this._lyr3DMain.remove_layer(e.wasmLayerId),this._layers.delete(e.wasmLayerId),!0)}_isGaussianSplatLayerView(e){return"gaussian-splat"===e.layer.type}_isGaussianSplatLayer(e){return"gaussian-splat"===e.type}_toWasmQuality(e){switch(e){case"low":return 1;case"medium":return 2;case"high":return 3}}_addLayerView(e){const t=e.layer;if(!t.url||!t.rootTilesetJSON)return{wasmLayerId:p};const i="integrated-mesh-3dtiles"===t.type?0:2,r=this._lyr3DMain.validate_root_tileset(JSON.stringify(t.rootTilesetJSON),i);if(0!==r.errorCode)return{wasmLayerId:p,check:r};const a=this._lyr3DMain.get_next_layer_id(),n=new AbortController;this._layers.set(a,{layerView:e,abortController:n,needMemoryUsageUpdate:!1,outstandingJobCount:0,outstandingRenderableCount:0,customParameters:t.customParameters,apiKey:t.apiKey,needFrame:!0});const o=v(t.elevationInfo),l=this._toWasmQuality(this.view?.qualityProfile),d=e=>s.getLogger(this).error("add-spatial-reference-error","Error when adding SR:",e);let h=!1;if(this._isGaussianSplatLayerView(e)&&this._isGaussianSplatLayer(t)){let i=t.spatialReference;if(e.useEsriCrs&&t.esriCrsSpatialReference){i=t.esriCrsSpatialReference;const s=g(i);let r=1,a=1;!s&&i.wkid&&-1!==i.wkid&&(r=m.values[m[i.wkid]],a=e.metersPerVCSUnit),this._workerHandle.addSpatialReferenceInfo(this._cleanUpSR(this._makeSRWasmSerializable(i)),s,r,a).catch(d)}h=this._lyr3DMain.add_gaussian_splat_layer(l,t.url,a,o)}else h=this._lyr3DMain.add_3dtiles_layer(l,t.url,a,o);return h?(this._updateWasmCamera(),e.updatingFlagChanged(),{wasmLayerId:a}):(this._layers.delete(a),{wasmLayerId:p})}_createElevationUpdateHandle(){const e=(e,t)=>{const i=this.view.state?.contentCamera;if(!i||!this._lyr3DMain)return;const s=d(i.eye);if(!_(this.view.renderSpatialReference,t))return;u(s,this.view.renderSpatialReference,0,s,t,0,1);y(e,s[0],s[1])&&(this._updateCameraElevation=5,this._layers.forEach(e=>{const t=this._isUpdating(e);e.needFrame=!0,t||e.layerView.updatingFlagChanged()}))};return this.view.groundView.on("elevation-change",({extent:t,spatialReference:i})=>e(t,i))}_updateWasmCamera(){const e=this.view.state?.contentCamera;if(!e||!this._lyr3DMain)return;const{eye:t,center:i,up:s,near:r,far:a,fovY:n}=e,o=[e.viewport[2],e.viewport[3]],l=e.width/e.height;this._lyr3DMain.set_camera_parameters({eye:t,center:i,up:s,near:r,far:a,fov:n,aspectRatio:l,viewport:o}),this._layers.forEach(e=>{const t=this._isUpdating(e);e.needFrame=!0,t||e.layerView.updatingFlagChanged()})}_makeSRWasmSerializable(e){return{wkid:e?.wkid??-1,latestWkid:e?.latestWkid??-1,vcsWkid:e?.vcsWkid??-1,latestVcsWkid:e?.latestVcsWkid??-1,wkt:e?.wkt??""}}_cleanUpSR(e){return-1===e?.wkid&&e.latestWkid&&-1!==e.latestWkid?e.wkid=e.latestWkid:-1===e?.latestWkid&&e.wkid&&-1!==e.wkid&&(e.latestWkid=e.wkid),-1===e?.vcsWkid&&e.latestVcsWkid&&-1!==e.latestVcsWkid?e.vcsWkid=e.latestVcsWkid:-1===e?.latestVcsWkid&&e.vcsWkid&&-1!==e.vcsWkid&&(e.latestVcsWkid=e.vcsWkid),e}};e([o({constructOnly:!0})],C.prototype,"view",void 0),C=e([l("esri.layers.Lyr3DWasmPerSceneView")],C);const W=C;export{W as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import t from"../request.js";import has from"../core/has.js";import s from"../core/Logger.js";import{isAbortError as i}from"../core/promiseUtils.js";import{watch as r,initial as a}from"../core/reactiveUtils.js";import{convertTime as n}from"../core/timeUtils.js";import{property as l,subclass as o}from"../core/accessorSupport/decorators.js";import{C as h}from"../chunks/vec32.js";import{create as d}from"../core/libs/gl-matrix-2/factories/vec3f64.js";import{renderSRFromViewSR as u}from"../geometry/support/coordinateSystem.js";import{loadVoxelWASM as _}from"../libs/vxl/VxlModule.js";import{VoxelGraphic as c}from"../views/3d/layers/VoxelGraphic.js";import{VoxelTarget as m}from"../views/3d/layers/i3s/Intersector.js";import{Frustum as g}from"../views/3d/state/Frustum.js";import{RenderCoordsHelper as f}from"../views/3d/support/RenderCoordsHelper.js";import{SyncRenderPlugin as p}from"../views/3d/webgl-engine/effects/RenderPlugin.js";import{IntersectorResult as y}from"../views/3d/webgl-engine/lib/IntersectorResult.js";let x=class extends p{constructor(e){super(e),this._halfIntTexturesAvailable=!1,this._textureFloatLinearAvailable=!1,this._havePreparedWithAllLayers=!1,this._renderPluginContext=null,this._vxlPromise=null,this._vxl=null,this._pluginIsActive=!1,this._moreToLoad=!1,this._viewportWidth=-1,this._viewportHeight=-1,this._newLayers=[],this._layers=new Map,this._rctx=null,this._renderTargetToRestore=null,this._lastFrameWasStationary=!1,this._wasmMemBlockSizes=[512,1024,2048,4096,8192,16384,32768,65536],this._wasmMemBlocks=new Map,this._dbgFlags=new Set,this._captureFrustum=!1,this._frustum=null,this._frustumRenderableId=-1,this._renderCoordsHelper=null,this.produces=new Map([[20,()=>!!this._vxl&&"local"===this.view.viewingMode]]),this.type=9,this.slicePlaneEnabled=!0,this.isGround=!1,this.layerViewUid=[]}_dbg(e,t){this._dbgFlags.has(e)&&(4===e?s.getLogger(this).error(t):s.getLogger(this).warn(t))}_removeRenderPlugin(){this._pluginIsActive&&this.view.stage&&(this._dbg(1,"--removeRenderPlugin--"),this.view.stage.removeRenderPlugin(this)),this._pluginIsActive=!1}initialize(){this._dbg(1,"--initialize--");for(const e of this._wasmMemBlockSizes)this._wasmMemBlocks.set(e,0);this.addHandles([r(()=>this.view.ready,e=>{e&&"local"===this.view.viewingMode?(this._dbg(1,"view ready status changed to ready on a local view, calling addRenderPlugin"),this.view.stage.addRenderPlugin(this),this._pluginIsActive=!0):(this._dbg(1,"view ready status changed, not ready or not a local view!"),this._removeRenderPlugin())},a),r(()=>this.view?.qualityProfile,e=>{this._dbg(3,"qualityProfile changed to "+e),this._vxl&&this._vxl.set_quality(this._toWasmQuality(e))},a),r(()=>this.view?.timeExtent,()=>{if(this._vxl){const e=this._getTimeArgs(this.view?.timeExtent);this._dbg(3,"sceneView timeExtent changed to useTime="+e.hasTime+" st="+e.startTime+" et="+e.endTime),this._vxl.set_scene_time_extent(e.startTime,e.endTime,e.hasTime),this._renderPluginContext.requestRender()}},a),r(()=>this.view?.stationary,e=>{this._vxl&&e&&!this._lastFrameWasStationary&&this._renderPluginContext.requestRender()})])}initializeRenderContext(e){this._dbg(1,"--initializeRenderContext--");const t=e.renderContext.rctx;this._renderPluginContext=e,this._rctx=e.renderContext.rctx,this._halfIntTexturesAvailable=!!this._rctx.capabilities.textureNorm16,this._textureFloatLinearAvailable=this._rctx.capabilities.textureFloatLinear,this._initializeWasm(t.gl)}uninitializeRenderContext(){this._renderPluginContext=null,this._rctx=null,this._dbg(1,"--uninitializeRenderContext--")}_restoreFramebuffer(){if(!this._renderTargetToRestore)return;const e=this._renderTargetToRestore.fbo;if(!!!this._rctx)return void this._dbg(4,"no context in restoreFramebuffer!");this._rctx.bindFramebuffer(e,!0);const t=this._renderTargetToRestore.viewport;this._rctx.setViewport(t.x,t.y,t.width,t.height)}_bindPreviousDepthToSlot(e,t){const s=!!this._rctx,i=!!this._renderTargetToRestore;if(!s||!i)return 0;const r=this._renderTargetToRestore.fbo.depthStencilTexture;return r?(0===t?this._rctx.bindTexture(null,e,!0):this._rctx.bindTexture(r,e,!0),1):(this._dbg(4,"no depth/stencil texture exists!"),0)}_modifyResourceCount(e,t,s){if(!this._rctx)return void this._dbg(4,"modifyAllocation callback has no rendering context!");const i=e;1===s?this._rctx.instanceCounter.increment(i,t):this._rctx.instanceCounter.decrement(i,t)}_setBlendState(e,t,s,i){this._rctx?(this._rctx.setBlendingEnabled(1===e),this._rctx.setBlendFunction(t,s),this._rctx.setBlendEquation(i)):this._dbg(4,"setBlendState callback has no rendering context!")}_setFrontFace(e){this._rctx?this._rctx.setFrontFace(e):this._dbg(4,"setFrontFace callback has no rendering context!")}_setDepthStencilStateFunction(e,t,s){this._rctx?(this._rctx.setDepthFunction(s),this._rctx.setDepthTestEnabled(1===e),this._rctx.setDepthWriteEnabled(1===t),this._rctx.setStencilTestEnabled(!1),this._rctx.setStencilFunction(519,0,255),this._rctx.setStencilOpSeparate(1028,7680,7682,7680),this._rctx.setStencilOpSeparate(1029,7680,7683,7680)):this._dbg(4,"setDepthStencilStateFunction callback has no rendering context!")}_setRasterizerState(e){if(this._rctx)switch(e){case 1:this._rctx.setFaceCullingEnabled(!1);break;case 3:this._rctx.setCullFace(1029),this._rctx.setFaceCullingEnabled(!0);break;case 2:this._rctx.setCullFace(1028),this._rctx.setFaceCullingEnabled(!0)}else this._dbg(4,"setRasterizerState callback has no rendering context!")}_setViewport(e,t,s,i){this._rctx?this._rctx.setViewport(e,t,s,i):this._dbg(4,"setViewport callback has no rendering context!")}_updateMemoryUsage(){this._layers.forEach((e,t)=>{if(e.needMemoryUsageUpdate){const s=this._vxl.estimate_memory_usage(t);s>=0&&(e.needMemoryUsageUpdate=!1,e.layerView.setUsedMemory(s))}})}_syncRequestsResponses(){this._layers.forEach((e,s)=>{const r=[];e.responses.forEach((t,i)=>{r.push(i),this._dbg(2,"responding for requestID:"+i+" size:"+t.size),this._vxl.respond(s,i,t),0!==t.requestType&&4!==t.requestType||(e.needMemoryUsageUpdate=!0)});const a=e.responses;for(const t of r)a.delete(t);const n=this._vxl.get_new_requests(s),l=e.abortController.signal;for(const o in n){e.outstandingRequestCount+=1,1===e.outstandingRequestCount&&e.layerView.updatingFlagChanged();const s=n[o],r={responseType:"array-buffer",signal:l,query:{...e.layerView.layer.customParameters,token:e.layerView.layer.apiKey}};this._dbg(2,"making requestID:"+o+" url:"+s.url),t(s.url,r).then(t=>{e.outstandingRequestCount-=1,0===e.outstandingRequestCount&&e.layerView.updatingFlagChanged(),this._dbg(2,"have response for requestID:"+o);let i=0;if(t.data.byteLength>0){i=this._vxl._malloc(t.data.byteLength);const e=new Uint8Array(this._vxl.HEAPU8.buffer,i,t.data.byteLength),s=new Uint8Array(t.data);for(let i=0;i<t.data.byteLength;++i)e[i]=s[i]}a.set(+o,{responseType:s.responseType,ptr:i,size:t.data.byteLength,success:!0,requestType:s.requestType})}).catch(t=>{e.outstandingRequestCount-=1,0===e.outstandingRequestCount&&e.layerView.updatingFlagChanged(),i(t)||(this._dbg(4,`requestID:${o} failed, error=${t.toString()}`),a.set(+o,{responseType:s.responseType,ptr:0,size:0,success:!1,requestType:s.requestType}))})}})}updateWasmCamera(e){this._vxl.set_projection_matrix.apply(this._vxl,e.projectionMatrix),this._vxl.set_view_matrix.apply(this._vxl,e.viewMatrix),this._vxl.set_near_far(e.near,e.far)}isUpdating(e){if(!this._vxl&&this._vxlPromise)return!0;const t=this._layers.get(e);return!!t&&t.outstandingRequestCount>0}getLayerTimes(e){const t=[];return this._layers.forEach((s,i)=>{if(s.layerView.wasmLayerId===e.wasmLayerId){const s=this._vxl.get_layer_epoch_times(i,e.layer.currentVariableId);for(let e=0;e<s.length;++e)t.push(s[e])}}),t}getCurrentLayerTimeIndex(e){let t=0;return this._layers.forEach((s,i)=>{s.layerView.wasmLayerId===e.wasmLayerId&&(t=this._vxl.get_layer_current_time_id(i))}),t}setEnabled(e,t){this._layers.forEach((s,i)=>{s.layerView.wasmLayerId===e.wasmLayerId&&(this._vxl.set_enabled(i,t),s.needMemoryUsageUpdate=!0,this._renderPluginContext.requestRender())})}setIsInScaleRange(e,t){const s=this._layers.get(e.wasmLayerId);s&&t!==s.isInScaleRange&&(s.isInScaleRange=t,this._vxl.set_is_in_scale_range(e.wasmLayerId,t),s.needMemoryUsageUpdate=!t,this._renderPluginContext.requestRender())}setStaticSections(e,t){const s={mask:1,staticSections:t};return this._doMaskedUIUpdate(e,s,!0)}setCurrentVariable(e,t){const s={mask:1024,currentVariable:t};return this._doMaskedUIUpdate(e,s,!0)}setRenderMode(e,t){const s={mask:8192,renderMode:t};return this._doMaskedUIUpdate(e,s,!0)}setVerticalExaggerationAndOffset(e,t,s,i){const r={mask:256,volStyleDesc:{volumeId:t,verticalExaggeration:s,verticalOffset:i}};return this._doMaskedUIUpdate(e,r,!0)}setVariableStyles(e,t){const s={mask:32768,variableStyles:t};return this._doMaskedUIUpdate(e,s,!0)}setVolumeStyles(e,t){const s={mask:65536,volumeStyles:t};return this._doMaskedUIUpdate(e,s,!0)}setEnableDynamicSections(e,t){const s={mask:4096,containerIsVisible:t,container:1};return this._doMaskedUIUpdate(e,s,!0)}setEnableIsosurfaces(e,t){const s={mask:4096,containerIsVisible:t,container:0};return this._doMaskedUIUpdate(e,s,!0)}setEnableSections(e,t){const s={mask:4096,containerIsVisible:t,container:2};return this._doMaskedUIUpdate(e,s,!0)}setAnalysisSlice(e,t,s,i){const r={mask:131072,analysisSlice:{point:s,normal:i,enabled:t}};return this._doMaskedUIUpdate(e,r,!0)}updateLayerTimeProperties(e){if(!this._vxl)return;const t=this._layers.get(e.wasmLayerId);if(t){const s=t.layerView.layer;let i=0;s.timeOffset&&(i=n(s.timeOffset.value,s.timeOffset.unit,"seconds"));const r=this._getTimeArgs(s.timeExtent);this._vxl.set_layer_time_properties(e.wasmLayerId,r.startTime,r.endTime,r.hasTime,s.useViewTime,i),this._renderPluginContext.requestRender()}}_doMaskedUIUpdate(e,t,s){if(!this._vxl)return!1;let i=!1;return this._layers.forEach((s,r)=>{if(s.layerView.wasmLayerId===e.wasmLayerId){const e={str:JSON.stringify(t),byteCount:0,ptr:0,isReusable:!1};this._allocateBlock(e)&&(i=1===this._vxl.handle_masked_ui_update(r,e.ptr,e.byteCount),e.isReusable||this._vxl._free(e.ptr))}}),i&&s&&this._renderPluginContext.requestRender(),i}_addTriangleToWasmBuffer(e,t,s,i,r){return e[3*t]=s[0],e[3*t+1]=s[1],e[3*t+2]=s[2],e[3*(t+=1)]=i[0],e[3*t+1]=i[1],e[3*t+2]=i[2],e[3*(t+=1)]=r[0],e[3*t+1]=r[1],e[3*t+2]=r[2],t+=1}_addNormalToWasmBuffer(e,t,s){return e[3*t]=s[0],e[3*t+1]=s[1],e[3*t+2]=s[2],t+=1}_doCaptureFrustum(){if(!this._vxl)return;const e=36,t=e/3,s=this._vxl._malloc(3*e*Float32Array.BYTES_PER_ELEMENT),i=new Float32Array(this._vxl.HEAPF32.buffer,s,3*e),r=this._vxl._malloc(3*t*Float32Array.BYTES_PER_ELEMENT),a=new Float32Array(this._vxl.HEAPF32.buffer,r,e),n=this._frustum.points[0],l=this._frustum.points[1],o=this._frustum.points[2],h=this._frustum.points[3],d=this._frustum.points[4],u=this._frustum.points[5],_=this._frustum.points[6],c=this._frustum.points[7];let m=0,g=0;const f=this._frustum.planes[4];m=this._addTriangleToWasmBuffer(i,m,o,l,n),g=this._addNormalToWasmBuffer(a,g,f),m=this._addTriangleToWasmBuffer(i,m,n,h,o),g=this._addNormalToWasmBuffer(a,g,f);const p=this._frustum.planes[5];m=this._addTriangleToWasmBuffer(i,m,d,u,_),g=this._addNormalToWasmBuffer(a,g,p),m=this._addTriangleToWasmBuffer(i,m,_,c,d),g=this._addNormalToWasmBuffer(a,g,p);const y=this._frustum.planes[3];m=this._addTriangleToWasmBuffer(i,m,_,o,h),g=this._addNormalToWasmBuffer(a,g,y),m=this._addTriangleToWasmBuffer(i,m,h,c,_),g=this._addNormalToWasmBuffer(a,g,y);const x=this._frustum.planes[2];m=this._addTriangleToWasmBuffer(i,m,n,l,u),g=this._addNormalToWasmBuffer(a,g,x),m=this._addTriangleToWasmBuffer(i,m,u,d,n),g=this._addNormalToWasmBuffer(a,g,x);const v=this._frustum.planes[0];m=this._addTriangleToWasmBuffer(i,m,h,n,d),g=this._addNormalToWasmBuffer(a,g,v),m=this._addTriangleToWasmBuffer(i,m,d,c,h),g=this._addNormalToWasmBuffer(a,g,v);const b=this._frustum.planes[1];m=this._addTriangleToWasmBuffer(i,m,o,_,u),g=this._addNormalToWasmBuffer(a,g,b),m=this._addTriangleToWasmBuffer(i,m,u,l,o),g=this._addNormalToWasmBuffer(a,g,b),-1!==this._frustumRenderableId&&this._vxl.remove_generic_mesh(this._frustumRenderableId),this._frustumRenderableId=this._vxl.add_generic_mesh(s,3*e,r,e,255,0,0,64),this._vxl._free(s),this._vxl._free(r),this._captureFrustum=!1,this._renderPluginContext.requestRender()}captureFrustum(){null===this._renderCoordsHelper&&(this._renderCoordsHelper=f.create(2,u(!1,this.view.spatialReference))),null===this._frustum&&(this._frustum=new g(this._renderCoordsHelper)),this._captureFrustum=!0,null!==this._renderPluginContext&&this._renderPluginContext.requestRender()}toggleFullVolumeExtentDraw(e){this._vxl&&this._layers.forEach((t,s)=>{t.layerView.wasmLayerId===e.wasmLayerId&&(this._vxl.toggle_full_volume_extent_draw(s),this._renderPluginContext.requestRender())})}dropQueryRenderTarget(){this._vxl&&this._vxl.drop_query_rt()}addVoxelLayer(e){if(!this._vxl){const t={layerView:e,resolveCallback:null,rejectCallback:null},s=new Promise((e,s)=>{t.resolveCallback=e,t.rejectCallback=s});return this._newLayers.push(t),s}const t=this._addVoxelLayer(e);return t<0?Promise.reject(-1):Promise.resolve(t)}removeVoxelLayer(e){if(!this._vxl){const t=this._newLayers.findIndex(t=>e.uid===t.layerView.uid);t>=0&&(this._newLayers[t].resolveCallback(-1),this._newLayers.splice(t,1));const s=this._newLayers.length;return 0===s&&(this._dbg(1," no voxel layers left after removing a layer, removing RenderPlugin and destroying"),this.destroy()),s}let t=-1;this._layers.forEach((s,i)=>{if(s.layerView.wasmLayerId===e.wasmLayerId){t=i,s.abortController.abort(),this._vxl.remove_layer(t);const r=this.layerViewUid.indexOf(e.uid);-1!==r&&this.layerViewUid.splice(r,1)}}),t>=0&&this._layers.delete(t);const s=this._layers.size;return 0===s&&(this._dbg(1," no voxel layers left after removing a layer, removing RenderPlugin and destroying"),this.destroy()),s}_getBlockSize(e){for(const t of this._wasmMemBlockSizes)if(e<t)return t;return-1}_allocateBlock(e){e.byteCount=this._vxl.lengthBytesUTF8(e.str)+1;const t=this._getBlockSize(e.byteCount);return t<0?(e.isReusable=!1,e.ptr=this._vxl._malloc(e.byteCount)):(e.isReusable=!0,e.ptr=this._wasmMemBlocks.get(t),0===e.ptr&&(e.ptr=this._vxl._malloc(t),this._wasmMemBlocks.set(t,e.ptr))),0!==e.ptr&&(this._vxl.stringToUTF8(e.str,e.ptr,e.byteCount),!0)}_getTimeArgs(e){let t=-Number.MAX_VALUE,s=Number.MAX_VALUE,i=!1;return null!=e&&(e.isAllTime?i=!0:(null!=e.start&&(i=!0,t=e.start.getTime()/1e3),null!=e.end&&(i=!0,s=e.end.getTime()/1e3))),{startTime:t,endTime:s,hasTime:i}}_addVoxelLayer(e){const t=e.layer;let i=-1;const r=t.getConfiguration();if(r.length<1)return-1;const a={str:r,byteCount:0,ptr:0,isReusable:!1};if(!this._allocateBlock(a))return-1;const l=this._getTimeArgs(t.timeExtent),o=this.view.spatialReference.isWGS84&&t.spatialReference.isWGS84?111319.49079327357:1;let h=0;if(t.timeOffset&&(h=n(t.timeOffset.value,t.timeOffset.unit,"seconds")),i=this._vxl.add_layer(t.serviceRoot,a.ptr,a.byteCount,o,o,l.startTime,l.endTime,l.hasTime,t.useViewTime,h,this._toWasmQuality(this.view.qualityProfile)),a.isReusable||this._vxl._free(a.ptr),i>=0){t.test?.constantUpscaling&&(this._setUpscalingLimits(0,.25,.25),this._setUpscalingLimits(1,.5,.5),this._setUpscalingLimits(2,.75,.75));const r=new AbortController;if(this._layers.set(i,{layerView:e,responses:new Map,outstandingRequestCount:0,abortController:r,needMemoryUsageUpdate:!1,isInScaleRange:!0}),this.layerViewUid.push(e.uid),!this._halfIntTexturesAvailable||has("mac")){const t=[];let i="";for(const s of e.layer.variables)"Int16"!==s.renderingFormat.type&&"UInt16"!==s.renderingFormat.type||(t.push(s.name),s.id===e.layer.currentVariableId&&(i=s.name));""!==i&&s.getLogger(this).error("#addVoxelLayer_error()",e.layer,`The voxel layer '${e.layer.title}' cannot render the current variable '${i}' in this browser`),t.length>0&&s.getLogger(this).warn("#addVoxelLayer_warning()",e.layer,`The voxel layer '${e.layer.title}' cannot render the variables '${t.toString()}' in this browser`)}if(!this._textureFloatLinearAvailable){const t=[];let i="";for(const s of e.layer.variables)"Float32"===s.renderingFormat.type&&(t.push(s.name),s.id===e.layer.currentVariableId&&(i=s.name));""!==i&&s.getLogger(this).error("#addVoxelLayer_error()",e.layer,`The voxel layer '${e.layer.title}' cannot render the current variable '${i}' in this browser`),t.length>0&&s.getLogger(this).warn("#addVoxelLayer_warning()",e.layer,`The voxel layer '${e.layer.title}' cannot render the variables '${t.toString()}' in this browser`)}return has("esri-mobile")&&s.getLogger(this).warnOnce("Mobile support differs across devices. Voxel layer might not display as expected."),i}return-1}prepareRender(e){if(!this._vxl)return;const t=e.bind.camera.viewForward,s=e.bind.camera.eye;this._vxl.update_camera_pos_and_direction(s[0],s[1],s[2],t[0],t[1],t[2]);const i=this._vxl.cull();this._dbg(2,"missingResourceCount="+i),this._moreToLoad=i>0,this._havePreparedWithAllLayers=0===this._newLayers.length,this._updateMemoryUsage()}acquireTechniques(){return[]}render(e){if(!this._vxl)return;for(const s of this._newLayers){const e=this._addVoxelLayer(s.layerView);-1===e?s.rejectCallback(-1):s.resolveCallback(e)}if(this._newLayers=[],0===this._layers.size)return void this._dbg(4,"No voxel layers but RenderPlugin instance is being asked to render!");this._lastFrameWasStationary=this.view.stationary,this._syncRequestsResponses(),this._beforeDraw(),this._vxl.begin_color_frame(!this.view.stage.renderer.isFeatureEnabled(2),e.bind.lighting.mainLight.direction[0],e.bind.lighting.mainLight.direction[1],e.bind.lighting.mainLight.direction[2]);const t=this._renderTargetToRestore.viewport;t.width===this._viewportWidth&&t.height===this._viewportHeight||(this._viewportWidth=t.width,this._viewportHeight=t.height,this._vxl.set_viewport(t.width,t.height),this._layers.forEach(e=>{e.needMemoryUsageUpdate=!0})),0===t.x&&0===t.y||this._dbg(4,"Unsupported viewport parameters detected!"),this.updateWasmCamera(e.bind.camera),this._captureFrustum&&(this._frustum.update(e.bind.camera),this._doCaptureFrustum()),this._vxl.draw(),this._afterDraw(),(this._moreToLoad||!this._havePreparedWithAllLayers&&this._layers.size>0)&&this._renderPluginContext.requestRender()}destroy(){this._dbg(1,"--destroy--"),this._vxl&&(this._layers.forEach(e=>{e.abortController.abort()}),this._wasmMemBlocks.forEach(e=>{0!==e&&this._vxl._free(e)}),this._vxl.uninitialize_voxel_wasm(),this._removeRenderPlugin(),this._vxl=null)}_initializeWasm(e){return this._vxl?Promise.resolve():(this._vxlPromise||(this._vxlPromise=_(e).then(t=>{if(t.specialHTMLTargets.jsAPI3DRenderingContext=e,this._vxl=t,this._vxlPromise=null,this._newLayers.length<=0)return this._dbg(1," no voxel layers left after WASM downloaded, removing RenderPlugin and destroying"),void this.destroy();const s=this._getTimeArgs(this.view?.timeExtent),i=this._vxl.addFunction(this._restoreFramebuffer.bind(this),"v"),r=this._vxl.addFunction(this._setBlendState.bind(this),"viiii"),a=this._vxl.addFunction(this._setFrontFace.bind(this),"vi"),n=this._vxl.addFunction(this._setRasterizerState.bind(this),"vi"),l=this._vxl.addFunction(this._setDepthStencilStateFunction.bind(this),"viii"),o=this._vxl.addFunction(this._setViewport.bind(this),"viiii"),h=this._vxl.addFunction(this._bindPreviousDepthToSlot.bind(this),"iii"),d=this._vxl.addFunction(this._modifyResourceCount.bind(this),"viii"),u=this._halfIntTexturesAvailable&&!has("mac"),_=this._textureFloatLinearAvailable;this._vxl.initialize_voxel_wasm(i,r,a,n,l,o,h,d,s.startTime,s.endTime,s.hasTime,u,_),this._renderPluginContext&&this._renderPluginContext.requestRender()}).catch(()=>{for(const e of this._newLayers)e.rejectCallback(-2);this._dbg(4," WASM failed to download, removing RenderPlugin and destroying"),this.destroy()})),this._vxlPromise)}pickDepth(e,t,s){if(!this._vxl||!this._rctx||0===this._layers.size)return null;const i=s.viewport[3]-t;if(e<0||e>s.viewport[2]||t<0||t>s.viewport[3])return this._dbg(4,`[js] pickDepth: outOfRange, screenXY=[${e.toFixed(0)}, ${i.toFixed(0)}]]`),null;this._beforeDraw();const r=s.viewForward,a=s.eye;this._vxl.update_camera_pos_and_direction(a[0],a[1],a[2],r[0],r[1],r[2]),this.updateWasmCamera(s),this._vxl.begin_frame();const n=this._vxl.pick_depth(e,i);if(this._afterDraw(),n.success){return n.distanceToCamera}return null}pickObject(e,t,s,i){if(!this._vxl||!this._rctx||0===this._layers.size)return null;const r=Math.round(e),a=Math.round(t);if(r<0||r>s.viewport[2]||a<0||a>s.viewport[3])return this._dbg(4,`[js] pickObject: outOfRange, screenXY=[${r}, ${a}], vp=[${s.viewport.toString()}]`),null;this._beforeDraw();const n=s.viewForward,l=s.eye;this._vxl.update_camera_pos_and_direction(l[0],l[1],l[2],n[0],n[1],n[2]),this.updateWasmCamera(s),this._vxl.begin_frame();let o=null;if(0===i.length)o=this._vxl.pick_object(r,a,0,0);else{const e={str:JSON.stringify({layerIds:i}),byteCount:0,ptr:0,isReusable:!1};this._allocateBlock(e)&&(o=this._vxl.pick_object(r,a,e.ptr,e.byteCount),e.isReusable||this._vxl._free(e.ptr))}return this._afterDraw(),o}async getOtherFieldPopupValues(e,s){for(const i of e){const e=i.gpuResult;if(!e)continue;const r=this._layers.get(e.layerId);if(!r||!r.layerView.layer.url)continue;const a=r.layerView.layer,n={responseType:"array-buffer",signal:r.abortController.signal,query:{...r.layerView.layer.customParameters,token:r.layerView.layer.apiKey}},l=e.voxelSpacePosition,o=[Math.floor(l[0]/32),Math.floor(l[1]/32),Math.floor(l[2]/32)],h=[-4&o[0],-4&o[1],-4&o[2]];let d=0;if(e.epochTime){const t=this._vxl.get_layer_epoch_times(r.layerView.wasmLayerId,a.currentVariableId);for(let s=0;s<t.length;++s)if(t[s]===e.epochTime/1e3){d=s;break}}const u=[],_={varIds:[],ptrs:[],sizes:[]};for(const i of s){const e=a.variables.findIndex(e=>e.name===i);if(-1===e)continue;const s=a.variables.getItemAt(e)?.id;if(null==s)continue;const r=`${a.url}/variables/${s}/${d}/bundles/0/${h[0]}-${h[1]}-${h[2]}`;u.push(t(r,n).then(e=>e.data)),_.varIds.push(s)}const c=await Promise.allSettled(u),m=c.length;for(let t=0;t<m;++t){const e=c[t];if("fulfilled"===e.status){const t=e.value,s=this._vxl._malloc(t.byteLength);new Uint8Array(this._vxl.HEAPU8.buffer,s,t.byteLength).set(new Uint8Array(t)),_.ptrs.push(s),_.sizes.push(t.byteLength)}else _.varIds.splice(t,1)}const g=this._vxl.get_other_field_popup_values(e,_);for(let t=0;t<_.ptrs.length;++t)this._vxl._free(_.ptrs[t]);if(g.continuousValues)for(const t in g.continuousValues)i.attributes[t]=g.continuousValues[t];if(g.uniqueValues)for(const t in g.uniqueValues)i.attributes[t]=g.uniqueValues[t]}return e}_beforeDraw(){this._renderTargetToRestore={fbo:this._rctx.getBoundFramebufferObject(),viewport:this._rctx.getViewport()},this._rctx.setPolygonOffsetFillEnabled(!1),this._rctx.setScissorTestEnabled(!1),this._rctx.setColorMask(!0,!0,!0,!0)}_afterDraw(){this._renderTargetToRestore.fbo=null,this._rctx.externalTextureUnitUpdate(this._vxl.get_texture_units_bound_in_frame(),this._vxl.get_active_texture_unit()),this._rctx.externalVertexArrayObjectUpdate(),this._rctx.externalVertexBufferUpdate(),this._rctx.externalProgramUpdate()}intersect(e,t,s,i,r){if(!this._vxl||!this._rctx||0===this._layers.size||!e.options.selectionMode||e.options.isFiltered||!e.camera)return;if(null==r||r[0]<0||r[0]>e.camera.viewport[2]||r[1]<0||r[1]>e.camera.viewport[3])return this._dbg(4,r?`[js] VoxelWasmPerScene.intersect: outOfRange, screenXY=[${r[0].toFixed(0)}, ${r[1].toFixed(0)}]`:"[js] VoxelWasmPerScene.intersect: outOfRange, screenXY=null"),null;const a=[];this._layers.forEach(t=>{e.options.filteredLayerViewUids.includes(t.layerView.uid)&&a.push(t.layerView.wasmLayerId)});const n=this.pickObject(r[0],r[1],e.camera,a);if(null==n||-1===n.layerId)return;const l=this._layers.get(n.layerId);if(l){const t=l.layerView.layer.uid,r=n.distanceToCamera/h(s,i),a=d();a[0]=n.worldX,a[1]=n.worldY,a[2]=n.worldZ;const o={},u=l.layerView.layer,_=u.variables.findIndex(e=>e.id===u.currentVariableId);if(_>=0){const e=u.variables.getItemAt(_);null!=e&&(null!=n.continuousValue?o[e.name]=n.continuousValue:null!=n.uniqueValueLabel&&null!=n.uniqueValue?o[e.name]=`${n.uniqueValueLabel} (${n.uniqueValue})`:null!=n.uniqueValue&&(o[e.name]=`${n.uniqueValue}`),e.description.length>0?o["Voxel.CurrentVariable"]=e.description:e.name?.length>0&&(o["Voxel.CurrentVariable"]=e.name))}if(o["Voxel.Position"]=`[${n.voxelSpacePosition.toString()}]`,null!=n.epochTime&&null!=n.nativeTime&&null!=n.nativeTimeUnits){const e=new Date(n.epochTime);o["Voxel.LocalTime"]=e,o["Voxel.SourceTime"]=`${n.nativeTime.toLocaleString()} ${n.nativeTimeUnits}`}null!=n.depth&&(o["Voxel.Depth"]=n.depth);const c=n.faceNormal;o["Voxel.WorldPosition"]=`[${a[0]}, ${a[1]}, ${a[2]}]`;const g=e=>{const s=new m(a,t,()=>this._createVoxelGraphic(l.layerView.layer,o,n));e.set(this.type,s,r,c)},f=e.results,p=2===e.options.store;if((null==f.min.distance||r<f.min.distance)&&g(f.min),(null==f.max.distance||r>f.max.distance)&&g(f.max),p){const t=new y(e.ray);g(t),e.results.all.push(t)}}}_createVoxelGraphic(e,t,s){return new c({layer:e,sourceLayer:e,origin:e.graphicOrigin,attributes:t,gpuResult:s})}_toWasmQuality(e){switch(e){case"low":return 0;case"medium":return 1;case"high":return 2}}_setUpscalingLimits(e,t,s){this._vxl&&this._vxl.set_upscaling_limits(e,t,s)}hasHighlight(){return!1}};e([l({constructOnly:!0})],x.prototype,"view",void 0),x=e([o("esri.layers.VoxelWasmPerSceneView")],x);const v=x;export{v as default};
5
+ import{__decorate as e}from"tslib";import t from"../request.js";import has from"../core/has.js";import s from"../core/Logger.js";import{isAbortError as i}from"../core/promiseUtils.js";import{watch as r,initial as a}from"../core/reactiveUtils.js";import{convertTime as n}from"../core/timeUtils.js";import{property as l,subclass as o}from"../core/accessorSupport/decorators.js";import{D as h}from"../chunks/vec32.js";import{create as d}from"../core/libs/gl-matrix-2/factories/vec3f64.js";import{renderSRFromViewSR as u}from"../geometry/support/coordinateSystem.js";import{loadVoxelWASM as _}from"../libs/vxl/VxlModule.js";import{VoxelGraphic as c}from"../views/3d/layers/VoxelGraphic.js";import{VoxelTarget as m}from"../views/3d/layers/i3s/Intersector.js";import{Frustum as g}from"../views/3d/state/Frustum.js";import{RenderCoordsHelper as f}from"../views/3d/support/RenderCoordsHelper.js";import{SyncRenderPlugin as p}from"../views/3d/webgl-engine/effects/RenderPlugin.js";import{IntersectorResult as y}from"../views/3d/webgl-engine/lib/IntersectorResult.js";let x=class extends p{constructor(e){super(e),this._halfIntTexturesAvailable=!1,this._textureFloatLinearAvailable=!1,this._havePreparedWithAllLayers=!1,this._renderPluginContext=null,this._vxlPromise=null,this._vxl=null,this._pluginIsActive=!1,this._moreToLoad=!1,this._viewportWidth=-1,this._viewportHeight=-1,this._newLayers=[],this._layers=new Map,this._rctx=null,this._renderTargetToRestore=null,this._lastFrameWasStationary=!1,this._wasmMemBlockSizes=[512,1024,2048,4096,8192,16384,32768,65536],this._wasmMemBlocks=new Map,this._dbgFlags=new Set,this._captureFrustum=!1,this._frustum=null,this._frustumRenderableId=-1,this._renderCoordsHelper=null,this.produces=new Map([[20,()=>!!this._vxl&&"local"===this.view.viewingMode]]),this.type=9,this.slicePlaneEnabled=!0,this.isGround=!1,this.layerViewUid=[]}_dbg(e,t){this._dbgFlags.has(e)&&(4===e?s.getLogger(this).error(t):s.getLogger(this).warn(t))}_removeRenderPlugin(){this._pluginIsActive&&this.view.stage&&(this._dbg(1,"--removeRenderPlugin--"),this.view.stage.removeRenderPlugin(this)),this._pluginIsActive=!1}initialize(){this._dbg(1,"--initialize--");for(const e of this._wasmMemBlockSizes)this._wasmMemBlocks.set(e,0);this.addHandles([r(()=>this.view.ready,e=>{e&&"local"===this.view.viewingMode?(this._dbg(1,"view ready status changed to ready on a local view, calling addRenderPlugin"),this.view.stage.addRenderPlugin(this),this._pluginIsActive=!0):(this._dbg(1,"view ready status changed, not ready or not a local view!"),this._removeRenderPlugin())},a),r(()=>this.view?.qualityProfile,e=>{this._dbg(3,"qualityProfile changed to "+e),this._vxl&&this._vxl.set_quality(this._toWasmQuality(e))},a),r(()=>this.view?.timeExtent,()=>{if(this._vxl){const e=this._getTimeArgs(this.view?.timeExtent);this._dbg(3,"sceneView timeExtent changed to useTime="+e.hasTime+" st="+e.startTime+" et="+e.endTime),this._vxl.set_scene_time_extent(e.startTime,e.endTime,e.hasTime),this._renderPluginContext.requestRender()}},a),r(()=>this.view?.stationary,e=>{this._vxl&&e&&!this._lastFrameWasStationary&&this._renderPluginContext.requestRender()})])}initializeRenderContext(e){this._dbg(1,"--initializeRenderContext--");const t=e.renderContext.rctx;this._renderPluginContext=e,this._rctx=e.renderContext.rctx,this._halfIntTexturesAvailable=!!this._rctx.capabilities.textureNorm16,this._textureFloatLinearAvailable=this._rctx.capabilities.textureFloatLinear,this._initializeWasm(t.gl)}uninitializeRenderContext(){this._renderPluginContext=null,this._rctx=null,this._dbg(1,"--uninitializeRenderContext--")}_restoreFramebuffer(){if(!this._renderTargetToRestore)return;const e=this._renderTargetToRestore.fbo;if(!!!this._rctx)return void this._dbg(4,"no context in restoreFramebuffer!");this._rctx.bindFramebuffer(e,!0);const t=this._renderTargetToRestore.viewport;this._rctx.setViewport(t.x,t.y,t.width,t.height)}_bindPreviousDepthToSlot(e,t){const s=!!this._rctx,i=!!this._renderTargetToRestore;if(!s||!i)return 0;const r=this._renderTargetToRestore.fbo.depthStencilTexture;return r?(0===t?this._rctx.bindTexture(null,e,!0):this._rctx.bindTexture(r,e,!0),1):(this._dbg(4,"no depth/stencil texture exists!"),0)}_modifyResourceCount(e,t,s){if(!this._rctx)return void this._dbg(4,"modifyAllocation callback has no rendering context!");const i=e;1===s?this._rctx.instanceCounter.increment(i,t):this._rctx.instanceCounter.decrement(i,t)}_setBlendState(e,t,s,i){this._rctx?(this._rctx.setBlendingEnabled(1===e),this._rctx.setBlendFunction(t,s),this._rctx.setBlendEquation(i)):this._dbg(4,"setBlendState callback has no rendering context!")}_setFrontFace(e){this._rctx?this._rctx.setFrontFace(e):this._dbg(4,"setFrontFace callback has no rendering context!")}_setDepthStencilStateFunction(e,t,s){this._rctx?(this._rctx.setDepthFunction(s),this._rctx.setDepthTestEnabled(1===e),this._rctx.setDepthWriteEnabled(1===t),this._rctx.setStencilTestEnabled(!1),this._rctx.setStencilFunction(519,0,255),this._rctx.setStencilOpSeparate(1028,7680,7682,7680),this._rctx.setStencilOpSeparate(1029,7680,7683,7680)):this._dbg(4,"setDepthStencilStateFunction callback has no rendering context!")}_setRasterizerState(e){if(this._rctx)switch(e){case 1:this._rctx.setFaceCullingEnabled(!1);break;case 3:this._rctx.setCullFace(1029),this._rctx.setFaceCullingEnabled(!0);break;case 2:this._rctx.setCullFace(1028),this._rctx.setFaceCullingEnabled(!0)}else this._dbg(4,"setRasterizerState callback has no rendering context!")}_setViewport(e,t,s,i){this._rctx?this._rctx.setViewport(e,t,s,i):this._dbg(4,"setViewport callback has no rendering context!")}_updateMemoryUsage(){this._layers.forEach((e,t)=>{if(e.needMemoryUsageUpdate){const s=this._vxl.estimate_memory_usage(t);s>=0&&(e.needMemoryUsageUpdate=!1,e.layerView.setUsedMemory(s))}})}_syncRequestsResponses(){this._layers.forEach((e,s)=>{const r=[];e.responses.forEach((t,i)=>{r.push(i),this._dbg(2,"responding for requestID:"+i+" size:"+t.size),this._vxl.respond(s,i,t),0!==t.requestType&&4!==t.requestType||(e.needMemoryUsageUpdate=!0)});const a=e.responses;for(const t of r)a.delete(t);const n=this._vxl.get_new_requests(s),l=e.abortController.signal;for(const o in n){e.outstandingRequestCount+=1,1===e.outstandingRequestCount&&e.layerView.updatingFlagChanged();const s=n[o],r={responseType:"array-buffer",signal:l,query:{...e.layerView.layer.customParameters,token:e.layerView.layer.apiKey}};this._dbg(2,"making requestID:"+o+" url:"+s.url),t(s.url,r).then(t=>{e.outstandingRequestCount-=1,0===e.outstandingRequestCount&&e.layerView.updatingFlagChanged(),this._dbg(2,"have response for requestID:"+o);let i=0;if(t.data.byteLength>0){i=this._vxl._malloc(t.data.byteLength);const e=new Uint8Array(this._vxl.HEAPU8.buffer,i,t.data.byteLength),s=new Uint8Array(t.data);for(let i=0;i<t.data.byteLength;++i)e[i]=s[i]}a.set(+o,{responseType:s.responseType,ptr:i,size:t.data.byteLength,success:!0,requestType:s.requestType})}).catch(t=>{e.outstandingRequestCount-=1,0===e.outstandingRequestCount&&e.layerView.updatingFlagChanged(),i(t)||(this._dbg(4,`requestID:${o} failed, error=${t.toString()}`),a.set(+o,{responseType:s.responseType,ptr:0,size:0,success:!1,requestType:s.requestType}))})}})}updateWasmCamera(e){this._vxl.set_projection_matrix.apply(this._vxl,e.projectionMatrix),this._vxl.set_view_matrix.apply(this._vxl,e.viewMatrix),this._vxl.set_near_far(e.near,e.far)}isUpdating(e){if(!this._vxl&&this._vxlPromise)return!0;const t=this._layers.get(e);return!!t&&t.outstandingRequestCount>0}getLayerTimes(e){const t=[];return this._layers.forEach((s,i)=>{if(s.layerView.wasmLayerId===e.wasmLayerId){const s=this._vxl.get_layer_epoch_times(i,e.layer.currentVariableId);for(let e=0;e<s.length;++e)t.push(s[e])}}),t}getCurrentLayerTimeIndex(e){let t=0;return this._layers.forEach((s,i)=>{s.layerView.wasmLayerId===e.wasmLayerId&&(t=this._vxl.get_layer_current_time_id(i))}),t}setEnabled(e,t){this._layers.forEach((s,i)=>{s.layerView.wasmLayerId===e.wasmLayerId&&(this._vxl.set_enabled(i,t),s.needMemoryUsageUpdate=!0,this._renderPluginContext.requestRender())})}setIsInScaleRange(e,t){const s=this._layers.get(e.wasmLayerId);s&&t!==s.isInScaleRange&&(s.isInScaleRange=t,this._vxl.set_is_in_scale_range(e.wasmLayerId,t),s.needMemoryUsageUpdate=!t,this._renderPluginContext.requestRender())}setStaticSections(e,t){const s={mask:1,staticSections:t};return this._doMaskedUIUpdate(e,s,!0)}setCurrentVariable(e,t){const s={mask:1024,currentVariable:t};return this._doMaskedUIUpdate(e,s,!0)}setRenderMode(e,t){const s={mask:8192,renderMode:t};return this._doMaskedUIUpdate(e,s,!0)}setVerticalExaggerationAndOffset(e,t,s,i){const r={mask:256,volStyleDesc:{volumeId:t,verticalExaggeration:s,verticalOffset:i}};return this._doMaskedUIUpdate(e,r,!0)}setVariableStyles(e,t){const s={mask:32768,variableStyles:t};return this._doMaskedUIUpdate(e,s,!0)}setVolumeStyles(e,t){const s={mask:65536,volumeStyles:t};return this._doMaskedUIUpdate(e,s,!0)}setEnableDynamicSections(e,t){const s={mask:4096,containerIsVisible:t,container:1};return this._doMaskedUIUpdate(e,s,!0)}setEnableIsosurfaces(e,t){const s={mask:4096,containerIsVisible:t,container:0};return this._doMaskedUIUpdate(e,s,!0)}setEnableSections(e,t){const s={mask:4096,containerIsVisible:t,container:2};return this._doMaskedUIUpdate(e,s,!0)}setAnalysisSlice(e,t,s,i){const r={mask:131072,analysisSlice:{point:s,normal:i,enabled:t}};return this._doMaskedUIUpdate(e,r,!0)}updateLayerTimeProperties(e){if(!this._vxl)return;const t=this._layers.get(e.wasmLayerId);if(t){const s=t.layerView.layer;let i=0;s.timeOffset&&(i=n(s.timeOffset.value,s.timeOffset.unit,"seconds"));const r=this._getTimeArgs(s.timeExtent);this._vxl.set_layer_time_properties(e.wasmLayerId,r.startTime,r.endTime,r.hasTime,s.useViewTime,i),this._renderPluginContext.requestRender()}}_doMaskedUIUpdate(e,t,s){if(!this._vxl)return!1;let i=!1;return this._layers.forEach((s,r)=>{if(s.layerView.wasmLayerId===e.wasmLayerId){const e={str:JSON.stringify(t),byteCount:0,ptr:0,isReusable:!1};this._allocateBlock(e)&&(i=1===this._vxl.handle_masked_ui_update(r,e.ptr,e.byteCount),e.isReusable||this._vxl._free(e.ptr))}}),i&&s&&this._renderPluginContext.requestRender(),i}_addTriangleToWasmBuffer(e,t,s,i,r){return e[3*t]=s[0],e[3*t+1]=s[1],e[3*t+2]=s[2],e[3*(t+=1)]=i[0],e[3*t+1]=i[1],e[3*t+2]=i[2],e[3*(t+=1)]=r[0],e[3*t+1]=r[1],e[3*t+2]=r[2],t+=1}_addNormalToWasmBuffer(e,t,s){return e[3*t]=s[0],e[3*t+1]=s[1],e[3*t+2]=s[2],t+=1}_doCaptureFrustum(){if(!this._vxl)return;const e=36,t=e/3,s=this._vxl._malloc(3*e*Float32Array.BYTES_PER_ELEMENT),i=new Float32Array(this._vxl.HEAPF32.buffer,s,3*e),r=this._vxl._malloc(3*t*Float32Array.BYTES_PER_ELEMENT),a=new Float32Array(this._vxl.HEAPF32.buffer,r,e),n=this._frustum.points[0],l=this._frustum.points[1],o=this._frustum.points[2],h=this._frustum.points[3],d=this._frustum.points[4],u=this._frustum.points[5],_=this._frustum.points[6],c=this._frustum.points[7];let m=0,g=0;const f=this._frustum.planes[4];m=this._addTriangleToWasmBuffer(i,m,o,l,n),g=this._addNormalToWasmBuffer(a,g,f),m=this._addTriangleToWasmBuffer(i,m,n,h,o),g=this._addNormalToWasmBuffer(a,g,f);const p=this._frustum.planes[5];m=this._addTriangleToWasmBuffer(i,m,d,u,_),g=this._addNormalToWasmBuffer(a,g,p),m=this._addTriangleToWasmBuffer(i,m,_,c,d),g=this._addNormalToWasmBuffer(a,g,p);const y=this._frustum.planes[3];m=this._addTriangleToWasmBuffer(i,m,_,o,h),g=this._addNormalToWasmBuffer(a,g,y),m=this._addTriangleToWasmBuffer(i,m,h,c,_),g=this._addNormalToWasmBuffer(a,g,y);const x=this._frustum.planes[2];m=this._addTriangleToWasmBuffer(i,m,n,l,u),g=this._addNormalToWasmBuffer(a,g,x),m=this._addTriangleToWasmBuffer(i,m,u,d,n),g=this._addNormalToWasmBuffer(a,g,x);const v=this._frustum.planes[0];m=this._addTriangleToWasmBuffer(i,m,h,n,d),g=this._addNormalToWasmBuffer(a,g,v),m=this._addTriangleToWasmBuffer(i,m,d,c,h),g=this._addNormalToWasmBuffer(a,g,v);const b=this._frustum.planes[1];m=this._addTriangleToWasmBuffer(i,m,o,_,u),g=this._addNormalToWasmBuffer(a,g,b),m=this._addTriangleToWasmBuffer(i,m,u,l,o),g=this._addNormalToWasmBuffer(a,g,b),-1!==this._frustumRenderableId&&this._vxl.remove_generic_mesh(this._frustumRenderableId),this._frustumRenderableId=this._vxl.add_generic_mesh(s,3*e,r,e,255,0,0,64),this._vxl._free(s),this._vxl._free(r),this._captureFrustum=!1,this._renderPluginContext.requestRender()}captureFrustum(){null===this._renderCoordsHelper&&(this._renderCoordsHelper=f.create(2,u(!1,this.view.spatialReference))),null===this._frustum&&(this._frustum=new g(this._renderCoordsHelper)),this._captureFrustum=!0,null!==this._renderPluginContext&&this._renderPluginContext.requestRender()}toggleFullVolumeExtentDraw(e){this._vxl&&this._layers.forEach((t,s)=>{t.layerView.wasmLayerId===e.wasmLayerId&&(this._vxl.toggle_full_volume_extent_draw(s),this._renderPluginContext.requestRender())})}dropQueryRenderTarget(){this._vxl&&this._vxl.drop_query_rt()}addVoxelLayer(e){if(!this._vxl){const t={layerView:e,resolveCallback:null,rejectCallback:null},s=new Promise((e,s)=>{t.resolveCallback=e,t.rejectCallback=s});return this._newLayers.push(t),s}const t=this._addVoxelLayer(e);return t<0?Promise.reject(-1):Promise.resolve(t)}removeVoxelLayer(e){if(!this._vxl){const t=this._newLayers.findIndex(t=>e.uid===t.layerView.uid);t>=0&&(this._newLayers[t].resolveCallback(-1),this._newLayers.splice(t,1));const s=this._newLayers.length;return 0===s&&(this._dbg(1," no voxel layers left after removing a layer, removing RenderPlugin and destroying"),this.destroy()),s}let t=-1;this._layers.forEach((s,i)=>{if(s.layerView.wasmLayerId===e.wasmLayerId){t=i,s.abortController.abort(),this._vxl.remove_layer(t);const r=this.layerViewUid.indexOf(e.uid);-1!==r&&this.layerViewUid.splice(r,1)}}),t>=0&&this._layers.delete(t);const s=this._layers.size;return 0===s&&(this._dbg(1," no voxel layers left after removing a layer, removing RenderPlugin and destroying"),this.destroy()),s}_getBlockSize(e){for(const t of this._wasmMemBlockSizes)if(e<t)return t;return-1}_allocateBlock(e){e.byteCount=this._vxl.lengthBytesUTF8(e.str)+1;const t=this._getBlockSize(e.byteCount);return t<0?(e.isReusable=!1,e.ptr=this._vxl._malloc(e.byteCount)):(e.isReusable=!0,e.ptr=this._wasmMemBlocks.get(t),0===e.ptr&&(e.ptr=this._vxl._malloc(t),this._wasmMemBlocks.set(t,e.ptr))),0!==e.ptr&&(this._vxl.stringToUTF8(e.str,e.ptr,e.byteCount),!0)}_getTimeArgs(e){let t=-Number.MAX_VALUE,s=Number.MAX_VALUE,i=!1;return null!=e&&(e.isAllTime?i=!0:(null!=e.start&&(i=!0,t=e.start.getTime()/1e3),null!=e.end&&(i=!0,s=e.end.getTime()/1e3))),{startTime:t,endTime:s,hasTime:i}}_addVoxelLayer(e){const t=e.layer;let i=-1;const r=t.getConfiguration();if(r.length<1)return-1;const a={str:r,byteCount:0,ptr:0,isReusable:!1};if(!this._allocateBlock(a))return-1;const l=this._getTimeArgs(t.timeExtent),o=this.view.spatialReference.isWGS84&&t.spatialReference.isWGS84?111319.49079327357:1;let h=0;if(t.timeOffset&&(h=n(t.timeOffset.value,t.timeOffset.unit,"seconds")),i=this._vxl.add_layer(t.serviceRoot,a.ptr,a.byteCount,o,o,l.startTime,l.endTime,l.hasTime,t.useViewTime,h,this._toWasmQuality(this.view.qualityProfile)),a.isReusable||this._vxl._free(a.ptr),i>=0){t.test?.constantUpscaling&&(this._setUpscalingLimits(0,.25,.25),this._setUpscalingLimits(1,.5,.5),this._setUpscalingLimits(2,.75,.75));const r=new AbortController;if(this._layers.set(i,{layerView:e,responses:new Map,outstandingRequestCount:0,abortController:r,needMemoryUsageUpdate:!1,isInScaleRange:!0}),this.layerViewUid.push(e.uid),!this._halfIntTexturesAvailable||has("mac")){const t=[];let i="";for(const s of e.layer.variables)"Int16"!==s.renderingFormat.type&&"UInt16"!==s.renderingFormat.type||(t.push(s.name),s.id===e.layer.currentVariableId&&(i=s.name));""!==i&&s.getLogger(this).error("#addVoxelLayer_error()",e.layer,`The voxel layer '${e.layer.title}' cannot render the current variable '${i}' in this browser`),t.length>0&&s.getLogger(this).warn("#addVoxelLayer_warning()",e.layer,`The voxel layer '${e.layer.title}' cannot render the variables '${t.toString()}' in this browser`)}if(!this._textureFloatLinearAvailable){const t=[];let i="";for(const s of e.layer.variables)"Float32"===s.renderingFormat.type&&(t.push(s.name),s.id===e.layer.currentVariableId&&(i=s.name));""!==i&&s.getLogger(this).error("#addVoxelLayer_error()",e.layer,`The voxel layer '${e.layer.title}' cannot render the current variable '${i}' in this browser`),t.length>0&&s.getLogger(this).warn("#addVoxelLayer_warning()",e.layer,`The voxel layer '${e.layer.title}' cannot render the variables '${t.toString()}' in this browser`)}return has("esri-mobile")&&s.getLogger(this).warnOnce("Mobile support differs across devices. Voxel layer might not display as expected."),i}return-1}prepareRender(e){if(!this._vxl)return;const t=e.bind.camera.viewForward,s=e.bind.camera.eye;this._vxl.update_camera_pos_and_direction(s[0],s[1],s[2],t[0],t[1],t[2]);const i=this._vxl.cull();this._dbg(2,"missingResourceCount="+i),this._moreToLoad=i>0,this._havePreparedWithAllLayers=0===this._newLayers.length,this._updateMemoryUsage()}acquireTechniques(){return[]}render(e){if(!this._vxl)return;for(const s of this._newLayers){const e=this._addVoxelLayer(s.layerView);-1===e?s.rejectCallback(-1):s.resolveCallback(e)}if(this._newLayers=[],0===this._layers.size)return void this._dbg(4,"No voxel layers but RenderPlugin instance is being asked to render!");this._lastFrameWasStationary=this.view.stationary,this._syncRequestsResponses(),this._beforeDraw(),this._vxl.begin_color_frame(!this.view.stage.renderer.isFeatureEnabled(2),e.bind.lighting.mainLight.direction[0],e.bind.lighting.mainLight.direction[1],e.bind.lighting.mainLight.direction[2]);const t=this._renderTargetToRestore.viewport;t.width===this._viewportWidth&&t.height===this._viewportHeight||(this._viewportWidth=t.width,this._viewportHeight=t.height,this._vxl.set_viewport(t.width,t.height),this._layers.forEach(e=>{e.needMemoryUsageUpdate=!0})),0===t.x&&0===t.y||this._dbg(4,"Unsupported viewport parameters detected!"),this.updateWasmCamera(e.bind.camera),this._captureFrustum&&(this._frustum.update(e.bind.camera),this._doCaptureFrustum()),this._vxl.draw(),this._afterDraw(),(this._moreToLoad||!this._havePreparedWithAllLayers&&this._layers.size>0)&&this._renderPluginContext.requestRender()}destroy(){this._dbg(1,"--destroy--"),this._vxl&&(this._layers.forEach(e=>{e.abortController.abort()}),this._wasmMemBlocks.forEach(e=>{0!==e&&this._vxl._free(e)}),this._vxl.uninitialize_voxel_wasm(),this._removeRenderPlugin(),this._vxl=null)}_initializeWasm(e){return this._vxl?Promise.resolve():(this._vxlPromise||(this._vxlPromise=_(e).then(t=>{if(t.specialHTMLTargets.jsAPI3DRenderingContext=e,this._vxl=t,this._vxlPromise=null,this._newLayers.length<=0)return this._dbg(1," no voxel layers left after WASM downloaded, removing RenderPlugin and destroying"),void this.destroy();const s=this._getTimeArgs(this.view?.timeExtent),i=this._vxl.addFunction(this._restoreFramebuffer.bind(this),"v"),r=this._vxl.addFunction(this._setBlendState.bind(this),"viiii"),a=this._vxl.addFunction(this._setFrontFace.bind(this),"vi"),n=this._vxl.addFunction(this._setRasterizerState.bind(this),"vi"),l=this._vxl.addFunction(this._setDepthStencilStateFunction.bind(this),"viii"),o=this._vxl.addFunction(this._setViewport.bind(this),"viiii"),h=this._vxl.addFunction(this._bindPreviousDepthToSlot.bind(this),"iii"),d=this._vxl.addFunction(this._modifyResourceCount.bind(this),"viii"),u=this._halfIntTexturesAvailable&&!has("mac"),_=this._textureFloatLinearAvailable;this._vxl.initialize_voxel_wasm(i,r,a,n,l,o,h,d,s.startTime,s.endTime,s.hasTime,u,_),this._renderPluginContext&&this._renderPluginContext.requestRender()}).catch(()=>{for(const e of this._newLayers)e.rejectCallback(-2);this._dbg(4," WASM failed to download, removing RenderPlugin and destroying"),this.destroy()})),this._vxlPromise)}pickDepth(e,t,s){if(!this._vxl||!this._rctx||0===this._layers.size)return null;const i=s.viewport[3]-t;if(e<0||e>s.viewport[2]||t<0||t>s.viewport[3])return this._dbg(4,`[js] pickDepth: outOfRange, screenXY=[${e.toFixed(0)}, ${i.toFixed(0)}]]`),null;this._beforeDraw();const r=s.viewForward,a=s.eye;this._vxl.update_camera_pos_and_direction(a[0],a[1],a[2],r[0],r[1],r[2]),this.updateWasmCamera(s),this._vxl.begin_frame();const n=this._vxl.pick_depth(e,i);if(this._afterDraw(),n.success){return n.distanceToCamera}return null}pickObject(e,t,s,i){if(!this._vxl||!this._rctx||0===this._layers.size)return null;const r=Math.round(e),a=Math.round(t);if(r<0||r>s.viewport[2]||a<0||a>s.viewport[3])return this._dbg(4,`[js] pickObject: outOfRange, screenXY=[${r}, ${a}], vp=[${s.viewport.toString()}]`),null;this._beforeDraw();const n=s.viewForward,l=s.eye;this._vxl.update_camera_pos_and_direction(l[0],l[1],l[2],n[0],n[1],n[2]),this.updateWasmCamera(s),this._vxl.begin_frame();let o=null;if(0===i.length)o=this._vxl.pick_object(r,a,0,0);else{const e={str:JSON.stringify({layerIds:i}),byteCount:0,ptr:0,isReusable:!1};this._allocateBlock(e)&&(o=this._vxl.pick_object(r,a,e.ptr,e.byteCount),e.isReusable||this._vxl._free(e.ptr))}return this._afterDraw(),o}async getOtherFieldPopupValues(e,s){for(const i of e){const e=i.gpuResult;if(!e)continue;const r=this._layers.get(e.layerId);if(!r||!r.layerView.layer.url)continue;const a=r.layerView.layer,n={responseType:"array-buffer",signal:r.abortController.signal,query:{...r.layerView.layer.customParameters,token:r.layerView.layer.apiKey}},l=e.voxelSpacePosition,o=[Math.floor(l[0]/32),Math.floor(l[1]/32),Math.floor(l[2]/32)],h=[-4&o[0],-4&o[1],-4&o[2]];let d=0;if(e.epochTime){const t=this._vxl.get_layer_epoch_times(r.layerView.wasmLayerId,a.currentVariableId);for(let s=0;s<t.length;++s)if(t[s]===e.epochTime/1e3){d=s;break}}const u=[],_={varIds:[],ptrs:[],sizes:[]};for(const i of s){const e=a.variables.findIndex(e=>e.name===i);if(-1===e)continue;const s=a.variables.getItemAt(e)?.id;if(null==s)continue;const r=`${a.url}/variables/${s}/${d}/bundles/0/${h[0]}-${h[1]}-${h[2]}`;u.push(t(r,n).then(e=>e.data)),_.varIds.push(s)}const c=await Promise.allSettled(u),m=c.length;for(let t=0;t<m;++t){const e=c[t];if("fulfilled"===e.status){const t=e.value,s=this._vxl._malloc(t.byteLength);new Uint8Array(this._vxl.HEAPU8.buffer,s,t.byteLength).set(new Uint8Array(t)),_.ptrs.push(s),_.sizes.push(t.byteLength)}else _.varIds.splice(t,1)}const g=this._vxl.get_other_field_popup_values(e,_);for(let t=0;t<_.ptrs.length;++t)this._vxl._free(_.ptrs[t]);if(g.continuousValues)for(const t in g.continuousValues)i.attributes[t]=g.continuousValues[t];if(g.uniqueValues)for(const t in g.uniqueValues)i.attributes[t]=g.uniqueValues[t]}return e}_beforeDraw(){this._renderTargetToRestore={fbo:this._rctx.getBoundFramebufferObject(),viewport:this._rctx.getViewport()},this._rctx.setPolygonOffsetFillEnabled(!1),this._rctx.setScissorTestEnabled(!1),this._rctx.setColorMask(!0,!0,!0,!0)}_afterDraw(){this._renderTargetToRestore.fbo=null,this._rctx.externalTextureUnitUpdate(this._vxl.get_texture_units_bound_in_frame(),this._vxl.get_active_texture_unit()),this._rctx.externalVertexArrayObjectUpdate(),this._rctx.externalVertexBufferUpdate(),this._rctx.externalProgramUpdate()}intersect(e,t,s,i,r){if(!this._vxl||!this._rctx||0===this._layers.size||!e.options.selectionMode||e.options.isFiltered||!e.camera)return;if(null==r||r[0]<0||r[0]>e.camera.viewport[2]||r[1]<0||r[1]>e.camera.viewport[3])return this._dbg(4,r?`[js] VoxelWasmPerScene.intersect: outOfRange, screenXY=[${r[0].toFixed(0)}, ${r[1].toFixed(0)}]`:"[js] VoxelWasmPerScene.intersect: outOfRange, screenXY=null"),null;const a=[];this._layers.forEach(t=>{e.options.filteredLayerViewUids.includes(t.layerView.uid)&&a.push(t.layerView.wasmLayerId)});const n=this.pickObject(r[0],r[1],e.camera,a);if(null==n||-1===n.layerId)return;const l=this._layers.get(n.layerId);if(l){const t=l.layerView.layer.uid,r=n.distanceToCamera/h(s,i),a=d();a[0]=n.worldX,a[1]=n.worldY,a[2]=n.worldZ;const o={},u=l.layerView.layer,_=u.variables.findIndex(e=>e.id===u.currentVariableId);if(_>=0){const e=u.variables.getItemAt(_);null!=e&&(null!=n.continuousValue?o[e.name]=n.continuousValue:null!=n.uniqueValueLabel&&null!=n.uniqueValue?o[e.name]=`${n.uniqueValueLabel} (${n.uniqueValue})`:null!=n.uniqueValue&&(o[e.name]=`${n.uniqueValue}`),e.description.length>0?o["Voxel.CurrentVariable"]=e.description:e.name?.length>0&&(o["Voxel.CurrentVariable"]=e.name))}if(o["Voxel.Position"]=`[${n.voxelSpacePosition.toString()}]`,null!=n.epochTime&&null!=n.nativeTime&&null!=n.nativeTimeUnits){const e=new Date(n.epochTime);o["Voxel.LocalTime"]=e,o["Voxel.SourceTime"]=`${n.nativeTime.toLocaleString()} ${n.nativeTimeUnits}`}null!=n.depth&&(o["Voxel.Depth"]=n.depth);const c=n.faceNormal;o["Voxel.WorldPosition"]=`[${a[0]}, ${a[1]}, ${a[2]}]`;const g=e=>{const s=new m(a,t,()=>this._createVoxelGraphic(l.layerView.layer,o,n));e.set(this.type,s,r,c)},f=e.results,p=2===e.options.store;if((null==f.min.distance||r<f.min.distance)&&g(f.min),(null==f.max.distance||r>f.max.distance)&&g(f.max),p){const t=new y(e.ray);g(t),e.results.all.push(t)}}}_createVoxelGraphic(e,t,s){return new c({layer:e,sourceLayer:e,origin:e.graphicOrigin,attributes:t,gpuResult:s})}_toWasmQuality(e){switch(e){case"low":return 0;case"medium":return 1;case"high":return 2}}_setUpscalingLimits(e,t,s){this._vxl&&this._vxl.set_upscaling_limits(e,t,s)}hasHighlight(){return!1}};e([l({constructOnly:!0})],x.prototype,"view",void 0),x=e([o("esri.layers.VoxelWasmPerSceneView")],x);const v=x;export{v as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import t from"../../core/Collection.js";import{makeHandle as r}from"../../core/handleUtils.js";import{LRUCache as o}from"../../core/LRUCache.js";import{someMap as i,getOrCreateMapValue as s}from"../../core/MapUtils.js";import{MultiOriginJSONMixin as a}from"../../core/MultiOriginJSONSupport.js";import n from"../../core/ReactiveMap.js";import{watch as l}from"../../core/reactiveUtils.js";import{signal as d}from"../../core/signal.js";import{property as p,subclass as y}from"../../core/accessorSupport/decorators.js";import{Integer as c}from"../../core/accessorSupport/ensureType.js";import h from"../Layer.js";import{BlendLayer as u}from"../mixins/BlendLayer.js";import{ScaleRangeLayer as m}from"../mixins/ScaleRangeLayer.js";import{legendEnabled as f,opacity as g}from"../support/commonProperties.js";import _ from"../support/OrderByInfo.js";import{getAttributeComparator as j}from"../../statistics/utils.js";let v=class extends(m(u(a(h)))){constructor(e){super(e),this._layerCache=new o(20,e=>e.destroy()),this._oidToReference=new n,this._layerToReference=new Map,this.legendEnabled=!0,this.layers=new t,this.maximumVisibleSublayers=10,this.opacity=1,this.parent=null,this.persistenceEnabled=!0,this.title="Layers in view",this.type="catalog-dynamic-group",this.visible=!0}initialize(){this.addHandles([this.layers.on("after-add",({item:e})=>{e.parent=this}),this.layers.on("after-remove",({item:e})=>{e.parent=null}),l(()=>this._orderBy,()=>{this._updateLayerSortValues(),this._sortAllLayers()})])}load(e){return this.addResolvingPromise(this.parent.load()),Promise.resolve(this)}destroy(){this._layerCache.destroy(),this._oidToReference.clear(),this._layerToReference.clear()}get _orderBy(){return this.parent?this.parent.orderBy?.find(e=>!e.valueExpression&&e.field)??new _({field:this.parent.objectIdField}):null}get _referenceComparator(){const e=this._orderBy;if(!this.parent||!e)return()=>0;const t=this.parent.fieldsIndex.get(e.field),r=j(t?.toJSON().type,"descending"===e.order),o=j("esriFieldTypeOID","descending"===e.order);return(e,t)=>r(t.sortValue,e.sortValue)||o(t.objectId,e.objectId)}get fullExtent(){return this.parent?.fullExtent??null}get updating(){return i(this._oidToReference,({pending:e})=>null!=e)}acquireLayer(e){if(this.destroyed)return r();const t=this._getLayerReference(e);return t.count++,r(()=>{t.count--,t.count||this._destroyLayerReference(t)})}_getLayerReference(e){const t=e.getObjectId();return s(this._oidToReference,t,()=>{const t=e.getObjectId(),r=`${t}`,o=e.getAttribute(this.parent.itemSourceField),i=new b(e,t,o),s=this._layerCache.pop(r);return s?(this._addLayer(i,s),i):(i.pending=this.parent.createLayerFromFootprint(e).then(e=>{i.count?this._addLayer(i,e):(this.destroyed||this._layerCache.get(r)||this._layerCache.put(r,e),i.layer=null)}).catch(()=>{}).finally(()=>{i.pending=null}),i)})}_destroyLayerReference(e){e.layer&&(this._layerToReference.delete(e.layer),this.layers.remove(e.layer),this.destroyed?e.layer.destroy():this._layerCache.put(`${e.objectId}`,e.layer),e.layer=null),this._oidToReference.delete(e.objectId)}_addLayer(e,t){e.layer=t,t.persistenceEnabled=!1,this._layerToReference.set(t,e),this._updateLayerSortValue(e),this.layers.add(t),this._sortAllLayers()}_updateLayerSortValues(){for(const e of this._layerToReference.values())this._updateLayerSortValue(e)}_updateLayerSortValue(e){this._orderBy&&(e.sortValue=e.footprint.getAttribute(this._orderBy.field))}_sortAllLayers(){this.layers.sort((e,t)=>this._referenceComparator(this._layerToReference.get(e),this._layerToReference.get(t)))}};e([p()],v.prototype,"_orderBy",null),e([p({readOnly:!0})],v.prototype,"_referenceComparator",null),e([p(f)],v.prototype,"legendEnabled",void 0),e([p({type:["show","hide","hide-children"],json:{write:!0}})],v.prototype,"listMode",void 0),e([p({readOnly:!0})],v.prototype,"fullExtent",null),e([p({type:String,json:{origins:{service:{read:!1},"portal-item":{read:!1}},write:{ignoreOrigin:!0,isRequired:!0}}})],v.prototype,"id",void 0),e([p({readOnly:!0})],v.prototype,"layers",void 0),e([p({type:c,range:{min:0,max:50},json:{write:!0,default:10}})],v.prototype,"maximumVisibleSublayers",void 0),e([p(g)],v.prototype,"opacity",void 0),e([p({clonable:!1})],v.prototype,"parent",void 0),e([p({type:String,nonNullable:!0,json:{write:{ignoreOrigin:!0,isRequired:!0}}})],v.prototype,"title",void 0),e([p({json:{read:!1}})],v.prototype,"type",void 0),e([p({readOnly:!0})],v.prototype,"updating",null),e([p({type:Boolean,json:{name:"visibility",write:!0}})],v.prototype,"visible",void 0),v=e([y("esri.layers.catalog.CatalogDynamicGroupLayer")],v);class b{constructor(e,t,r){this.footprint=e,this.objectId=t,this.itemSource=r,this.count=0,this.layer=null,this.sortValue=void 0,this._pending=d(null)}get pending(){return this._pending.value}set pending(e){this._pending.value=e}}export{v as default};
5
+ import{__decorate as e}from"tslib";import t from"../../core/Collection.js";import{makeHandle as r}from"../../core/handleUtils.js";import{LRUCache as o}from"../../core/LRUCache.js";import{someMap as i,getOrCreateMapValue as s}from"../../core/MapUtils.js";import{MultiOriginJSONMixin as a}from"../../core/MultiOriginJSONSupport.js";import n from"../../core/ReactiveMap.js";import{watch as l}from"../../core/reactiveUtils.js";import{signal as d}from"../../core/signal.js";import{property as p,subclass as y}from"../../core/accessorSupport/decorators.js";import{Integer as c}from"../../core/accessorSupport/ensureType.js";import h from"../Layer.js";import{BlendLayer as u}from"../mixins/BlendLayer.js";import{ScaleRangeLayer as m}from"../mixins/ScaleRangeLayer.js";import{legendEnabled as f,opacity as g}from"../support/commonProperties.js";import _ from"../support/OrderByInfo.js";import{getAttributeComparator as j}from"../../statistics/utils.js";let v=class extends(m(u(a(h)))){constructor(e){super(e),this._layerCache=new o(20,e=>e.destroy()),this._oidToReference=new n,this._layerToReference=new Map,this.legendEnabled=!0,this.layers=new t,this.maximumVisibleSublayers=10,this.opacity=1,this.parent=null,this.persistenceEnabled=!0,this.title="Layers in view",this.type="catalog-dynamic-group",this.visible=!0}initialize(){this.addHandles([this.layers.on("after-add",({item:e})=>{e.parent=this}),this.layers.on("after-remove",({item:e})=>{e.parent=null}),l(()=>this._orderBy,()=>{this._updateLayerSortValues(),this._sortAllLayers()})])}load(e){return this.addResolvingPromise(this.parent.load()),Promise.resolve(this)}destroy(){this._layerCache.destroy(),this._oidToReference.clear(),this._layerToReference.clear()}get _orderBy(){return this.parent?this.parent.orderBy?.find(e=>!e.valueExpression&&e.field)??new _({field:this.parent.objectIdField}):null}get _referenceComparator(){const e=this._orderBy;if(!this.parent||!e)return()=>0;const t=this.parent.fieldsIndex.get(e.field),r=j(t?.toJSON().type,"descending"===e.order,"case-sensitive"),o=j("esriFieldTypeOID","descending"===e.order);return(e,t)=>r(t.sortValue,e.sortValue)||o(t.objectId,e.objectId)}get fullExtent(){return this.parent?.fullExtent??null}get updating(){return i(this._oidToReference,({pending:e})=>null!=e)}acquireLayer(e){if(this.destroyed)return r();const t=this._getLayerReference(e);return t.count++,r(()=>{t.count--,t.count||this._destroyLayerReference(t)})}_getLayerReference(e){const t=e.getObjectId();return s(this._oidToReference,t,()=>{const t=e.getObjectId(),r=`${t}`,o=e.getAttribute(this.parent.itemSourceField),i=new b(e,t,o),s=this._layerCache.pop(r);return s?(this._addLayer(i,s),i):(i.pending=this.parent.createLayerFromFootprint(e).then(e=>{i.count?this._addLayer(i,e):(this.destroyed||this._layerCache.get(r)||this._layerCache.put(r,e),i.layer=null)}).catch(()=>{}).finally(()=>{i.pending=null}),i)})}_destroyLayerReference(e){e.layer&&(this._layerToReference.delete(e.layer),this.layers.remove(e.layer),this.destroyed?e.layer.destroy():this._layerCache.put(`${e.objectId}`,e.layer),e.layer=null),this._oidToReference.delete(e.objectId)}_addLayer(e,t){e.layer=t,t.persistenceEnabled=!1,this._layerToReference.set(t,e),this._updateLayerSortValue(e),this.layers.add(t),this._sortAllLayers()}_updateLayerSortValues(){for(const e of this._layerToReference.values())this._updateLayerSortValue(e)}_updateLayerSortValue(e){this._orderBy&&(e.sortValue=e.footprint.getAttribute(this._orderBy.field))}_sortAllLayers(){this.layers.sort((e,t)=>this._referenceComparator(this._layerToReference.get(e),this._layerToReference.get(t)))}};e([p()],v.prototype,"_orderBy",null),e([p({readOnly:!0})],v.prototype,"_referenceComparator",null),e([p(f)],v.prototype,"legendEnabled",void 0),e([p({type:["show","hide","hide-children"],json:{write:!0}})],v.prototype,"listMode",void 0),e([p({readOnly:!0})],v.prototype,"fullExtent",null),e([p({type:String,json:{origins:{service:{read:!1},"portal-item":{read:!1}},write:{ignoreOrigin:!0,isRequired:!0}}})],v.prototype,"id",void 0),e([p({readOnly:!0})],v.prototype,"layers",void 0),e([p({type:c,range:{min:0,max:50},json:{write:!0,default:10}})],v.prototype,"maximumVisibleSublayers",void 0),e([p(g)],v.prototype,"opacity",void 0),e([p({clonable:!1})],v.prototype,"parent",void 0),e([p({type:String,nonNullable:!0,json:{write:{ignoreOrigin:!0,isRequired:!0}}})],v.prototype,"title",void 0),e([p({json:{read:!1}})],v.prototype,"type",void 0),e([p({readOnly:!0})],v.prototype,"updating",null),e([p({type:Boolean,json:{name:"visibility",write:!0}})],v.prototype,"visible",void 0),v=e([y("esri.layers.catalog.CatalogDynamicGroupLayer")],v);class b{constructor(e,t,r){this.footprint=e,this.objectId=t,this.itemSource=r,this.count=0,this.layer=null,this.sortValue=void 0,this._pending=d(null)}get pending(){return this._pending.value}set pending(e){this._pending.value=e}}export{v as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{getExpressionFromFieldName as t,getWhereClause as e,getAliasFromFieldName as i}from"./attributeSupport.js";import{getGeometry as s}from"./geometryUtils.js";import{isDateOnlyField as a,isTimestampOffsetField as l,isTimeOnlyField as r}from"../../support/fieldUtils.js";import{timeOnlyToMilliseconds as n}from"../../../smartMapping/statistics/support/utils.js";import{processNullValue as u,getNormalizedValue as o}from"../../../statistics/utils.js";import{loadArcade as d}from"../../../support/loadArcade.js";class c{constructor(s,a,l){this._fieldDataCache=new Map,this._returnDistinctMap=new Map,this.returnDistinctValues=s.returnDistinctValues??!1,this.fieldsIndex=l,this.featureAdapter=a;const r=s.outFields;if(r&&!r.includes("*")){this.outFields=r;let s=0;for(const a of r){const r=t(a),n=this.fieldsIndex.get(r),u=n?null:e(r,l),o=n?n.name:i(a)||"FIELD_EXP_"+s++;this._fieldDataCache.set(a,{alias:o,clause:u})}}}countDistinctValues(t){return this.returnDistinctValues?(t.forEach(t=>this.getAttributes(t)),this._returnDistinctMap.size):t.length}getAttributes(t){const e=this._processAttributesForOutFields(t);return this._processAttributesForDistinctValues(e)}getFieldValue(t,i,s){const a=s?s.name:i;let l=null;return this._fieldDataCache.has(a)?l=this._fieldDataCache.get(a)?.clause:s||(l=e(i,this.fieldsIndex),this._fieldDataCache.set(a,{alias:a,clause:l})),s?this.featureAdapter.getAttribute(t,a):l?.calculateValue(t,this.featureAdapter)}getDataValues(t,e,i=!0){const s=e.normalizationType,d=e.normalizationTotal,c=this.fieldsIndex.get(e.field),f=a(c)||l(c),h=r(c);return t.map(t=>{let a=e.field&&this.getFieldValue(t,e.field,this.fieldsIndex.get(e.field));if(e.field2?(a=`${u(a)}${e.fieldDelimiter}${u(this.getFieldValue(t,e.field2,this.fieldsIndex.get(e.field2)))}`,e.field3&&(a=`${a}${e.fieldDelimiter}${u(this.getFieldValue(t,e.field3,this.fieldsIndex.get(e.field3)))}`)):"string"==typeof a&&i&&(f?a=a?new Date(a).getTime():null:h&&(a=a?n(a):null)),s&&Number.isFinite(a)){const i="field"===s&&e.normalizationField?this.getFieldValue(t,e.normalizationField,this.fieldsIndex.get(e.normalizationField)):null;a=o(a,s,i,d)}return a})}async getExpressionValues(t,e,i,a,l){const{arcadeUtils:r}=await d(),n=r.hasGeometryOperations(e);n&&await r.enableGeometryOperations();const u=r.createFunction(e),o=r.getViewInfo(i),c={fields:this.fieldsIndex.fields};return t.map(t=>{const e={attributes:this.featureAdapter.getAttributes(t),layer:c,geometry:n?{...s(a.geometryType,this.featureAdapter.getGeometry(t)),spatialReference:i?.spatialReference}:null},d=r.createExecContext(e,o,l);return r.executeFunction(u,d)})}validateItem(t,i){return this._fieldDataCache.has(i)||this._fieldDataCache.set(i,{alias:i,clause:e(i,this.fieldsIndex)}),this._fieldDataCache.get(i)?.clause?.testFeature(t,this.featureAdapter)??!1}validateItems(t,i){return this._fieldDataCache.has(i)||this._fieldDataCache.set(i,{alias:i,clause:e(i,this.fieldsIndex)}),this._fieldDataCache.get(i)?.clause?.testSet(t,this.featureAdapter)??!1}_processAttributesForOutFields(t){const e=this.outFields;if(!e?.length)return this.featureAdapter.getAttributes(t);const i={};for(const s of e){const{alias:e,clause:a}=this._fieldDataCache.get(s);i[e]=a?a.calculateValue(t,this.featureAdapter):this.featureAdapter.getAttribute(t,e)}return i}_processAttributesForDistinctValues(t){if(null==t||!this.returnDistinctValues)return t;const e=this.outFields,i=[];if(e)for(const l of e){const{alias:e}=this._fieldDataCache.get(l);i.push(t[e])}else for(const l in t)i.push(t[l]);const s=`${(e||["*"]).join(",")}=${i.join(",")}`;let a=this._returnDistinctMap.get(s)||0;return this._returnDistinctMap.set(s,++a),a>1?null:t}}export{c as default};
5
+ import{getExpressionFromFieldName as t,getWhereClause as e,getAliasFromFieldName as i}from"./attributeSupport.js";import{getGeometry as s}from"./geometryUtils.js";import{isDateOnlyField as a,isTimestampOffsetField as r,isTimeOnlyField as l}from"../../support/fieldUtils.js";import{timeOnlyToMilliseconds as n}from"../../../smartMapping/statistics/support/utils.js";import{processNullValue as u,getNormalizedValue as o}from"../../../statistics/utils.js";import{loadArcade as d}from"../../../support/loadArcade.js";class c{constructor(s,a,r){this._fieldDataCache=new Map,this._returnDistinctMap=new Map,this.returnDistinctValues=s.returnDistinctValues??!1,this.fieldsIndex=r,this.featureAdapter=a;const l=s.outFields;if(l&&!l.includes("*")){this.outFields=l;let s=0;for(const a of l){const l=t(a),n=this.fieldsIndex.get(l),u=n?null:e(l,r),o=n?n.name:i(a)||"FIELD_EXP_"+s++;this._fieldDataCache.set(a,{alias:o,clause:u})}}}countDistinctValues(t){return this.returnDistinctValues?(t.forEach(t=>this.getAttributes(t)),this._returnDistinctMap.size):t.length}getAttributes(t){const e=this._processAttributesForOutFields(t);return this._processAttributesForDistinctValues(e)}getFieldValue(t,i,s){if(s)return this.featureAdapter.getAttribute(t,s.name);const a=i;let r=null;return this._fieldDataCache.has(a)?r=this._fieldDataCache.get(a)?.clause:s||(r=e(i,this.fieldsIndex),this._fieldDataCache.set(a,{alias:a,clause:r})),r?.calculateValue(t,this.featureAdapter)}getDataValues(t,e,i=!0){const s=e.normalizationType,d=e.normalizationTotal,c=this.fieldsIndex.get(e.field),f=a(c)||r(c),h=l(c);return t.map(t=>{let a=e.field&&this.getFieldValue(t,e.field,this.fieldsIndex.get(e.field));if(e.field2?(a=`${u(a)}${e.fieldDelimiter}${u(this.getFieldValue(t,e.field2,this.fieldsIndex.get(e.field2)))}`,e.field3&&(a=`${a}${e.fieldDelimiter}${u(this.getFieldValue(t,e.field3,this.fieldsIndex.get(e.field3)))}`)):"string"==typeof a&&i&&(f?a=a?new Date(a).getTime():null:h&&(a=a?n(a):null)),s&&Number.isFinite(a)){const i="field"===s&&e.normalizationField?this.getFieldValue(t,e.normalizationField,this.fieldsIndex.get(e.normalizationField)):null;a=o(a,s,i,d)}return a})}async getExpressionValues(t,e,i,a,r){const{arcadeUtils:l}=await d(),n=l.hasGeometryOperations(e);n&&await l.enableGeometryOperations();const u=l.createFunction(e),o=l.getViewInfo(i),c={fields:this.fieldsIndex.fields};return t.map(t=>{const e={attributes:this.featureAdapter.getAttributes(t),layer:c,geometry:n?{...s(a.geometryType,this.featureAdapter.getGeometry(t)),spatialReference:i?.spatialReference}:null},d=l.createExecContext(e,o,r);return l.executeFunction(u,d)})}validateItem(t,i){return this._fieldDataCache.has(i)||this._fieldDataCache.set(i,{alias:i,clause:e(i,this.fieldsIndex)}),this._fieldDataCache.get(i)?.clause?.testFeature(t,this.featureAdapter)??!1}validateItems(t,i){return this._fieldDataCache.has(i)||this._fieldDataCache.set(i,{alias:i,clause:e(i,this.fieldsIndex)}),this._fieldDataCache.get(i)?.clause?.testSet(t,this.featureAdapter)??!1}_processAttributesForOutFields(t){const e=this.outFields;if(!e?.length)return this.featureAdapter.getAttributes(t);const i={};for(const s of e){const{alias:e,clause:a}=this._fieldDataCache.get(s);i[e]=a?a.calculateValue(t,this.featureAdapter):this.featureAdapter.getAttribute(t,e)}return i}_processAttributesForDistinctValues(t){if(null==t||!this.returnDistinctValues)return t;const e=this.outFields,i=[];if(e)for(const r of e){const{alias:e}=this._fieldDataCache.get(r);i.push(t[e])}else for(const r in t)i.push(t[r]);const s=`${(e||["*"]).join(",")}=${i.join(",")}`;let a=this._returnDistinctMap.get(s)||0;return this._returnDistinctMap.set(s,++a),a>1?null:t}}export{c as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{clone as e}from"../../../core/lang.js";import{polygonCentroid as t,extentCentroid as i}from"../../../geometry/support/centroid.js";import{getPolygonExtent as s,getGeometryExtent as a}from"../../../geometry/support/extentUtils.js";import{toQuantizationTransform as n}from"../../../geometry/support/quantizationUtils.js";import{isValid as r,equals as o}from"../../../geometry/support/spatialReferenceUtils.js";import l from"./AttributesBuilder.js";import{cleanFromGeometryEngine as u,getGeometry as c,transformCentroid as m}from"./geometryUtils.js";import{project as d}from"./projectionSupport.js";import{getDateInNumber as f}from"./queryUtils.js";import{SnappingCandidateEdge as p,SnappingCandidateVertex as h}from"./SnappingCandidate.js";import{isDateField as y,isDateOnlyField as g,isTimestampOffsetField as x,isStringField as T,isTimeOnlyField as F}from"../../support/fieldUtils.js";import I from"../../../rest/support/AutoIntervalBinParameters.js";import _ from"../../../rest/support/DateBinParameters.js";import{unitsDict as S}from"../../../rest/support/DateBinUtils.js";import V from"../../../rest/support/FixedBoundariesBinParameters.js";import b from"../../../rest/support/FixedIntervalBinParameters.js";import{calculateStringStatistics as v,calculateStatistics as R,processSummaryStatisticsResult as B,calculateUniqueValuesCount as z,createUVResult as M,calculateClassBreaks as A,resolveCBResult as N,calculateHistogram as w,getAttributeComparator as D,calculatePercentile as P,binIndex as q,getBinParams as j,isNullCountSupported as Z}from"../../../statistics/utils.js";import{utc as G}from"../../../time/constants.js";import{DateTime as C}from"luxon";const O="bin";class E{constructor(e,t,i){this.items=e,this.query=t,this.geometryType=i.geometryType,this.hasM=i.hasM,this.hasZ=i.hasZ,this.fieldsIndex=i.fieldsIndex,this.objectIdField=i.objectIdField,this.spatialReference=i.spatialReference,this.featureAdapter=i.featureAdapter}get size(){return this.items.length}createQueryResponseForCount(){const e=new l(this.query,this.featureAdapter,this.fieldsIndex);if(!this.query.outStatistics)return e.countDistinctValues(this.items);const{groupByFieldsForStatistics:t,having:i,outStatistics:s}=this.query,a=t?.length;if(!!!a)return 1;const n=new Map,r=new Map,o=new Set;for(const l of s){const{statisticType:s}=l,a="exceedslimit"!==s?l.onStatisticField:void 0;if(!r.has(a)){const i=[];for(const s of t){const t=this._getAttributeValues(e,s,this.items,n);i.push(t)}r.set(a,this._calculateUniqueValues(i,this.items,e.returnDistinctValues))}const u=r.get(a);for(const t in u){const{data:s,items:a}=u[t],n=s.join(",");i&&!e.validateItems(a,i)||o.add(n)}}return o.size}async createQueryResponse(){let e;if(this.query.outStatistics){e=this.query.outStatistics.some(e=>"exceedslimit"===e.statisticType)?this._createExceedsLimitQueryResponse():await this._createStatisticsQueryResponse(this.query,this.items)}else e=this._createFeatureQueryResponse(this.query);if(this.query.returnQueryGeometry){const t=this.query.geometry;r(this.query.outSR)&&!o(t.spatialReference,this.query.outSR)?e.queryGeometry=u({spatialReference:this.query.outSR,...d(t,t.spatialReference,this.query.outSR)}):e.queryGeometry=u({spatialReference:this.query.outSR,...t})}return e}createSnappingResponse(e,t,i){const s=this.featureAdapter,a=Q(this.hasZ,this.hasM),{point:n,mode:r}=e,o="number"==typeof e.distance?e.distance:e.distance.x,l="number"==typeof e.distance?e.distance:e.distance.y,u={candidates:[]},c="esriGeometryPolygon"===this.geometryType,m="esriGeometryPolyline"===this.geometryType||"esriGeometryPoint"===this.geometryType,d=this._getPointCreator(r,t,this.spatialReference,i),f=new U(null,0),y=new U(null,0),g={x:0,y:0,z:0};for(const x of this.items){const t=s.getGeometry(x);if(null==t)continue;const{coords:i}=t,r=t.isPoint?J:t.lengths;if(f.coords=i,y.coords=i,e.returnEdge){let e=0;for(let t=0;t<r.length;t++){const i=r[t],m=e;for(let t=0;t<i;t++,e+=a){if(!c&&t===i-1)continue;const r=f;r.coordsIndex=e;const h=y;h.coordsIndex=t===i-1?m:e+a;const T=g;if(!H(g,n,r,h))continue;const F=(n.x-T.x)/o,I=(n.y-T.y)/l,_=F*F+I*I;_<=1&&u.candidates.push(new p(s.getObjectId(x),d(T),Math.sqrt(_),d(r),d(h)))}}}if("all"===e.vertexMode){let e=0;for(let t=0;t<r.length;t++){const i=r[t],m=e,p=y;p.coordsIndex=m;for(let t=0;t<i;t++,e+=a){const a=f;if(a.coordsIndex=e,c&&t===i-1&&a.x===p.x&&a.y===p.y)continue;const r=(n.x-a.x)/o,m=(n.y-a.y)/l,y=r*r+m*m;y<=1&&u.candidates.push(new h(s.getObjectId(x),d(a),Math.sqrt(y)))}}}else if(m&&"ends"===e.vertexMode){let e=0;const t=[];for(let i=0;i<r.length;i++){t.push(e);const s=r[i];e+=s*a,!c&&s>1&&t.push(e-a)}for(const i of t){const e=f;e.coordsIndex=i;const t=(n.x-e.x)/o,a=(n.y-e.y)/l,r=t*t+a*a;r<=1&&u.candidates.push(new h(s.getObjectId(x),d(e),Math.sqrt(r)))}}}return u.candidates.sort((e,t)=>e.distance-t.distance),u}_getPointCreator(e,t,i,s){const a=null==s||o(i,s)?e=>e:e=>d(e,i,s),{hasZ:n}=this,r=0;return"3d"===e?n&&t?({x:e,y:t,z:i})=>a({x:e,y:t,z:i}):({x:e,y:t})=>a({x:e,y:t,z:r}):({x:e,y:t})=>a({x:e,y:t})}async createSummaryStatisticsResponse(e){const{field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:n,minValue:r,maxValue:o,scale:l,timeZone:u,outStatisticTypes:c}=e,m=this.fieldsIndex.get(t),d=y(m)||g(m)||x(m),f=await this._getDataValues({field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:n,scale:l,timeZone:u},this.items),p=Z({normalizationType:a,normalizationField:s,minValue:r,maxValue:o}),h={value:.5,fieldType:m?.type},F=T(m)?v({values:f,supportsNullCount:p,percentileParams:h,outStatisticTypes:c}):R({values:f,minValue:r,maxValue:o,useSampleStdDev:!a,supportsNullCount:p,percentileParams:h,outStatisticTypes:c});return B(F,c,d)}async createUniqueValuesResponse(e){const{field:t,valueExpression:i,domains:s,returnAllCodedValues:a,scale:n,timeZone:r}=e,o=await this._getDataValues({field:t,field2:e.field2,field3:e.field3,fieldDelimiter:e.fieldDelimiter,valueExpression:i,scale:n,timeZone:r},this.items,!1),l=z(o);return M(l,s,a,e.fieldDelimiter)}async createClassBreaksResponse(e){const{field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:n,classificationMethod:r,standardDeviationInterval:o,minValue:l,maxValue:u,numClasses:c,scale:m,timeZone:d}=e,f=await this._getDataValues({field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:n,scale:m,timeZone:d},this.items),p=A(f,{field:t,normalizationField:s,normalizationType:a,normalizationTotal:n,classificationMethod:r,standardDeviationInterval:o,minValue:l,maxValue:u,numClasses:c});return N(p,r)}async createHistogramResponse(e){const{field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:n,classificationMethod:r,standardDeviationInterval:o,minValue:l,maxValue:u,numBins:c,scale:m,timeZone:d}=e,f=await this._getDataValues({field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:n,scale:m,timeZone:d},this.items);return w(f,{field:t,normalizationField:s,normalizationType:a,normalizationTotal:n,classificationMethod:r,standardDeviationInterval:o,minValue:l,maxValue:u,numBins:c})}_sortFeatures(e,t,i){if(e.length>1&&t?.length)for(const s of t.slice().reverse()){const t=s.split(" "),a=t[0],n=this.fieldsIndex.get(a),r=!!t[1]&&"desc"===t[1].toLowerCase(),o=D(n?.type,r);e.sort((e,t)=>{const s=i(e,a,n),r=i(t,a,n);return o(s,r)})}}_createFeatureQueryResponse(e){const{items:t,geometryType:i,hasM:s,hasZ:a,objectIdField:r,spatialReference:o}=this,{outFields:l,outSR:c,quantizationParameters:m,resultRecordCount:d,resultOffset:f,returnZ:p,returnM:h}=e,y=null!=d&&t.length>(f||0)+d,g=l&&(l.includes("*")?[...this.fieldsIndex.fields]:l.map(e=>this.fieldsIndex.get(e)));return{exceededTransferLimit:y,features:this._createFeatures(e,t),fields:g,geometryType:i,hasM:s&&h,hasZ:a&&p,objectIdFieldName:r,spatialReference:u(c||o),transform:m&&n(m)||null}}_createFeatures(e,t){const i=new l(e,this.featureAdapter,this.fieldsIndex),{hasM:s,hasZ:a}=this,{orderByFields:r,quantizationParameters:o,returnGeometry:u,returnCentroid:d,maxAllowableOffset:f,resultOffset:p,resultRecordCount:h,returnZ:y=!1,returnM:g=!1}=e,x=a&&y,T=s&&g;let F=[],I=0;const _=[...t];if(this._sortFeatures(_,r,(e,t,s)=>i.getFieldValue(e,t,s)),this.geometryType&&(u||d)){const e=n(o)??void 0,t="esriGeometryPolygon"===this.geometryType||"esriGeometryPolyline"===this.geometryType;if(u&&!d)for(const s of _){const a=this.featureAdapter.getGeometry(s),n=this._addFeatureJSONMetadata(s,{attributes:i.getAttributes(s),geometry:c(this.geometryType,a,f,e,x,T)});t&&a&&!n.geometry&&(n.centroid=m(this,this.featureAdapter.getCentroid(s,this),e)),F[I++]=n}else if(!u&&d)for(const s of _)F[I++]=this._addFeatureJSONMetadata(s,{attributes:i.getAttributes(s),centroid:m(this,this.featureAdapter.getCentroid(s,this),e)});else for(const s of _)F[I++]=this._addFeatureJSONMetadata(s,{attributes:i.getAttributes(s),centroid:m(this,this.featureAdapter.getCentroid(s,this),e),geometry:c(this.geometryType,this.featureAdapter.getGeometry(s),f,e,x,T)})}else for(const n of _){const e=i.getAttributes(n);e&&(F[I++]=this._addFeatureJSONMetadata(n,{attributes:e}))}const S=p||0;if(null!=h){const e=S+h;F=F.slice(S,Math.min(F.length,e))}return F}_addFeatureJSONMetadata(e,t){const i=this.featureAdapter.getMetadata?.(e);return void 0!==i&&(t.metadata=i),t}_createExceedsLimitQueryResponse(){let e=!1,t=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,s=Number.POSITIVE_INFINITY;for(const a of this.query.outStatistics??[])if("exceedslimit"===a.statisticType){t=null!=a.maxPointCount?a.maxPointCount:Number.POSITIVE_INFINITY,i=null!=a.maxRecordCount?a.maxRecordCount:Number.POSITIVE_INFINITY,s=null!=a.maxVertexCount?a.maxVertexCount:Number.POSITIVE_INFINITY;break}if("esriGeometryPoint"===this.geometryType)e=this.items.length>t;else if(this.items.length>i)e=!0;else{const t=Q(this.hasZ,this.hasM),i=this.featureAdapter;e=this.items.reduce((e,t)=>{const s=i.getGeometry(t);return e+(null!=s&&s.coords.length||0)},0)/t>s}return{fields:[{name:"exceedslimit",type:"esriFieldTypeInteger",alias:"exceedslimit",sqlType:"sqlTypeInteger",domain:null,defaultValue:null}],features:[{attributes:{exceedslimit:Number(e)}}]}}async _createStatisticsQueryResponse(e,t,i={attributes:{}}){const s=[],a=new Map,n=new Map,r=new Map,o=new Map,u=new l(e,this.featureAdapter,this.fieldsIndex),c=e.outStatistics,{groupByFieldsForStatistics:m,having:d,orderByFields:f,resultRecordCount:p}=e,h=m?.length,y=!!h,g=y?m[0]:null,x=y&&!this.fieldsIndex.get(g);for(const l of c??[]){const{outStatisticFieldName:e,statisticType:c}=l,f=l,p="exceedslimit"!==c?l.onStatisticField:void 0,F="percentile_disc"===c||"percentile_cont"===c,I="EnvelopeAggregate"===c||"CentroidAggregate"===c||"ConvexHullAggregate"===c,_=y&&1===h&&(p===g||x)&&"count"===c;if(y){if(!r.has(p)){const e=[];for(const i of m){const s=this._getAttributeValues(u,i,t,a);e.push(s)}r.set(p,this._calculateUniqueValues(e,t,!I&&u.returnDistinctValues))}const i=r.get(p);if(!i)continue;const s=Object.keys(i);for(const n of s){const{count:s,data:r,items:l,itemPositions:c}=i[n],h=r.join(",");if(!d||u.validateItems(l,d)){const i=o.get(h)||{attributes:{}};if(I){i.aggregateGeometries||(i.aggregateGeometries={});const{aggregateGeometries:e,outStatisticFieldName:t}=await this._getAggregateGeometry(f,l);i.aggregateGeometries[t]=e}else{let n=null;if(_)n=s;else{const e=this._getAttributeValues(u,p,t,a),i=c.map(t=>e[t]);n=F&&"statisticParameters"in f?this._getPercentileValue(f,i):this._getStatisticValue(f,i,null,u.returnDistinctValues)}i.attributes[e]=n}let n=0;m.forEach((e,t)=>i.attributes[this.fieldsIndex.get(e)?e:"EXPR_"+ ++n]=r[t]),o.set(h,i)}}}else if(I){i.aggregateGeometries||(i.aggregateGeometries={});const{aggregateGeometries:e,outStatisticFieldName:s}=await this._getAggregateGeometry(f,t);i.aggregateGeometries[s]=e}else{const s=this._getAttributeValues(u,p,t,a);i.attributes[e]=F&&"statisticParameters"in f?this._getPercentileValue(f,s):this._getStatisticValue(f,s,n,u.returnDistinctValues)}const S="min"!==c&&"max"!==c||!T(this.fieldsIndex.get(p))&&!this._isAnyDateField(p)?null:this.fieldsIndex.get(p)?.type;s.push({name:e,alias:e,type:S||"esriFieldTypeDouble"})}const F=y?Array.from(o.values()):[i];return this._sortFeatures(F,f,(e,t)=>e.attributes[t]),p&&(F.length=Math.min(p,F.length)),{fields:s,features:F}}_isAnyDateField(e){const t=this.fieldsIndex.get(e);return y(t)||g(t)||x(t)||F(t)}async _getAggregateGeometry(e,n){const{convexHull:r,union:o}=await import("../../../geometry/geometryEngineJSON.js"),{statisticType:l,outStatisticFieldName:u}=e,{featureAdapter:m,spatialReference:d,geometryType:f}=this,p=n.map(e=>c(f,m.getGeometry(e))),h=r(d,p,!0)[0],y={aggregateGeometries:null,outStatisticFieldName:null};if("EnvelopeAggregate"===l){const e=h?s(h):a(o(d,p));y.aggregateGeometries={...e,spatialReference:d},y.outStatisticFieldName=u||"extent"}else if("CentroidAggregate"===l){const e=h?t(h):i(a(o(d,p)));y.aggregateGeometries={x:e[0],y:e[1],spatialReference:d},y.outStatisticFieldName=u||"centroid"}else"ConvexHullAggregate"===l&&(y.aggregateGeometries=h,y.outStatisticFieldName=u||"convexHull");return y}_getStatisticValue(e,t,i,s){const{onStatisticField:a,statisticType:n}=e;let r=null;r=i?.has(a)?i.get(a):T(this.fieldsIndex.get(a))||this._isAnyDateField(a)?v({values:t,returnDistinct:s}):R({values:s?[...new Set(t)]:t,minValue:null,maxValue:null,useSampleStdDev:!0}),i&&i.set(a,r);return r["var"===n?"variance":n]}_getPercentileValue(e,t){const{onStatisticField:i,statisticParameters:s,statisticType:a}=e,{value:n,orderBy:r}=s,o=this.fieldsIndex.get(i);return P(t,{value:n,orderBy:r,fieldType:o?.type,isDiscrete:"percentile_disc"===a})}_getAttributeValues(e,t,i,s){if(s.has(t))return s.get(t);const a=this.fieldsIndex.get(t),n=i.map(i=>e.getFieldValue(i,t,a));return s.set(t,n),n}_calculateUniqueValues(e,t,i){const s={},a=t.length;for(let n=0;n<a;n++){const a=t[n],r=[];for(const t of e)r.push(t[n]);const o=r.join(",");null==s[o]?s[o]={count:1,data:r,items:[a],itemPositions:[n]}:(i||s[o].count++,s[o].items.push(a),s[o].itemPositions.push(n))}return s}async _getDataValues(t,i,s=!0){const a=new l(this.query,this.featureAdapter,this.fieldsIndex),{valueExpression:n,scale:r,timeZone:o}=t;return n?a.getExpressionValues(i,n,{viewingMode:"map",scale:r,spatialReference:this.query.outSR||this.spatialReference},{geometryType:this.geometryType,hasZ:this.hasZ,hasM:this.hasM},o):a.getDataValues(i,e(t),s)}_calculateHistogramBins(e,t,i){if(null==t.min&&null==t.max)return[];const s=t.intervals,a=t.min??0,n=t.max??0,r=s.map(([e,t])=>({minValue:e,maxValue:t,count:0,items:[]}));for(let o=0;o<e.length;o++){const t=e[o],l=i[o];if(null!=t&&t>=a&&t<=n){const e=q(s,t);e>-1&&(r[e].count++,r[e].items.push(l))}}return r}async createQueryBinsResponse(e){const t=e.bin?.splitBy;if(!t)return this._createBinsResponse(e);const{value:i,outAlias:s,valueType:a}=t,n=[],r=[{name:s??i,alias:s??i,type:a??"esriFieldTypeString"},{name:O,alias:O,type:"esriFieldTypeInteger"}],o=new l(e,this.featureAdapter,this.fieldsIndex),u=new Map,c=[...this.items];this._sortFeatures(c,[i],(e,t,i)=>o.getFieldValue(e,t,i));const m=this._getAttributeValues(o,i,c,u),d=this._calculateUniqueValues([m],c,o.returnDistinctValues);for(const l in d){const{items:t}=d[l],a=await this._createBinsResponse(e,t);if(n.push(...a.features.map(e=>({...e,attributes:{...e.attributes,[s??i]:l}}))),a.fields)for(const e of a.fields)r.some(t=>t.name===e.name)||r.push(e)}return{fields:r,features:n}}async _createBinsResponse(e,t){const i=e.bin;switch(t=t??this.items,i.type){case"autoIntervalBin":return this._createAutoIntervalBinsResponse(I.fromJSON(i),e,t);case"dateBin":return this._createDateBinsResponse(_.fromJSON(i),e,t);case"fixedBoundariesBin":return this._createFixedBoundariesBinsResponse(V.fromJSON(i),e,t);case"fixedIntervalBin":return this._createFixedIntervalBinsResponse(b.fromJSON(i),e,t)}}async _createAutoIntervalBinsResponse(e,t,i){const{field:s,normalizationField:a,numBins:n,normalizationType:r,normalizationTotal:o,start:l,end:u}=e,c=await this._getDataValues({field:e.field,normalizationField:e.normalizationField,normalizationType:e.normalizationType,normalizationTotal:e.normalizationTotal,timeZone:t.outTimeReference?.ianaTimeZone},i),m=j(c,{field:s,normalizationField:a,normalizationType:r,normalizationTotal:o,numBins:n,minValue:f(l,!1),maxValue:f(u,!1)}),d=this._calculateHistogramBins(c,m,i);return this._createFeaturesFromHistogramBins(d,t)}async _createDateBinsResponse(e,t,i){const{field:s,interval:a,start:n,end:r,snapToData:o,returnFullIntervalBin:l}=e,u=a.unit,c=await this._getDataValues({field:e.field,timeZone:t.outTimeReference?.ianaTimeZone},i),m=F(this.fieldsIndex.get(s)),d=S.toJSON(u),p=c.filter(Boolean).sort((e,t)=>e-t),h=null!=n?f(n,m):p[0],y=null!=r?f(r,m):p[p.length-1],g=[];if(null!=h&&null!=y){const e={zone:t.outTimeReference?.ianaTimeZone??G},i=C.fromMillis(h,e),s=C.fromMillis(y,e);if("last"===o){let e=s;for(;e>i;){const t=e.minus({[d]:a.value});if(t<i){g.unshift([l?t.toMillis():i.toMillis(),e.toMillis()]);break}g.unshift([t.toMillis(),e.toMillis()]),e=t}}else{let e="first"===o?i:i.startOf(d);for(;e<=s;){const t=e.plus({[d]:a.value});if(t>s){g.push([e.toMillis(),l?t.toMillis():s.toMillis()]);break}g.push([e.toMillis(),t.toMillis()]),e=t}}}const x=this._calculateHistogramBins(c,{intervals:g,min:h,max:y},i);return this._createFeaturesFromHistogramBins(x,t)}async _createFixedBoundariesBinsResponse(e,t,i){const{field:s}=e,a=await this._getDataValues({field:s,timeZone:t.outTimeReference?.ianaTimeZone},i),n=F(this.fieldsIndex.get(s)),r=e.boundaries.map(e=>f(e,n)).sort((e,t)=>e-t),o=[];for(let c=0;c<r.length-1;c++)o.push([r[c],r[c+1]]);const l={intervals:o,min:r.at(0),max:r.at(-1)},u=this._calculateHistogramBins(a,l,i);return this._createFeaturesFromHistogramBins(u,t)}async _createFixedIntervalBinsResponse(e,t,i){const{field:s,interval:a,start:n,end:r}=e,o=await this._getDataValues({field:e.field,normalizationField:e.normalizationField,normalizationType:e.normalizationType,normalizationTotal:e.normalizationTotal,timeZone:t.outTimeReference?.ianaTimeZone},i),l=F(this.fieldsIndex.get(s)),u=j(o,{field:s,classificationMethod:"defined-interval",definedInterval:a,minValue:f(n,l),maxValue:f(r,l)},!0),c=this._calculateHistogramBins(o,u,i);return this._createFeaturesFromHistogramBins(c,t)}async _createFeaturesFromHistogramBins(e,t){const{upperBoundaryAlias:i,lowerBoundaryAlias:s}=t,a=s||"lowerBoundary",n=i||"upperBoundary",r=[],o=[{name:a,alias:a,type:"esriFieldTypeDouble"},{name:n,alias:n,type:"esriFieldTypeDouble"}],l=t.bin?.stackBy?.value,u=t.bin?.stackBy?.outAlias;l&&o.push({name:O,alias:O,type:"esriFieldTypeInteger"},{name:u??l,alias:u??l,type:"esriFieldTypeString"});let c=0;const m="dateBin"===t.bin.type,d=t.outTimeReference?.ianaTimeZone;for(const f of e){const{minValue:e,maxValue:i,items:s}=f,p={attributes:{}};let h;if(p.attributes[a]=m&&d&&null!=e?C.fromMillis(e,{zone:d}).toISO():e,p.attributes[n]=m&&d&&null!=i?C.fromMillis(i,{zone:d}).toISO():i,l?(h=await this._createStatisticsQueryResponse({...t,groupByFieldsForStatistics:[l],orderByFields:[l]},s),p.attributes[O]=++c,"flat"===t.bin.jsonStyle?r.push(...h.features.map(({attributes:{EXPR_1:e,...t},...i})=>({...i,attributes:u??e?{...t,[u??e]:e,...p.attributes}:{...t,...p.attributes}}))):(p.stackedAttributes=h.features.map(({attributes:{EXPR_1:e,...t}})=>u??e?{...t,[u??e]:e}:t),r.push(p))):(t.bin?.splitBy&&(p.attributes[O]=++c),h=await this._createStatisticsQueryResponse(t,s,p),r.push(p)),h.fields)for(const t of h.fields)o.some(e=>e.name===t.name)||o.push(t)}return"desc"===t.binOrder&&r.reverse(),{fields:o,features:r}}}function H(e,t,i,s){const a=s.x-i.x,n=s.y-i.y,r=t.x-i.x,o=t.y-i.y,l=a*a+n*n;if(0===l)return!1;const u=r*a+o*n,c=Math.min(1,Math.max(0,u/l));return e.x=i.x+a*c,e.y=i.y+n*c,!0}function Q(e,t){return e?t?4:3:t?3:2}class U{constructor(e,t){this.coords=e,this.coordsIndex=t}get x(){return this.coords[this.coordsIndex]}get y(){return this.coords[this.coordsIndex+1]}get z(){return this.coords[this.coordsIndex+2]}}const J=[1];export{E as QueryEngineResult};
5
+ import{clone as e}from"../../../core/lang.js";import{polygonCentroid as t,extentCentroid as i}from"../../../geometry/support/centroid.js";import{getPolygonExtent as s,getGeometryExtent as a}from"../../../geometry/support/extentUtils.js";import{toQuantizationTransform as n}from"../../../geometry/support/quantizationUtils.js";import{isValid as r,equals as o}from"../../../geometry/support/spatialReferenceUtils.js";import l from"./AttributesBuilder.js";import{cleanFromGeometryEngine as u,getGeometry as c,transformCentroid as m}from"./geometryUtils.js";import{project as d}from"./projectionSupport.js";import{getDateInNumber as f}from"./queryUtils.js";import{SnappingCandidateEdge as p,SnappingCandidateVertex as h}from"./SnappingCandidate.js";import{isDateField as y,isDateOnlyField as g,isTimestampOffsetField as x,isStringField as T,isTimeOnlyField as F}from"../../support/fieldUtils.js";import I from"../../../rest/support/AutoIntervalBinParameters.js";import _ from"../../../rest/support/DateBinParameters.js";import{unitsDict as S}from"../../../rest/support/DateBinUtils.js";import V from"../../../rest/support/FixedBoundariesBinParameters.js";import v from"../../../rest/support/FixedIntervalBinParameters.js";import{calculateStringStatistics as b,calculateStatistics as R,processSummaryStatisticsResult as B,calculateUniqueValuesCount as z,createUVResult as M,calculateClassBreaks as A,resolveCBResult as N,calculateHistogram as w,getAttributeComparator as D,calculatePercentile as P,binIndex as q,getBinParams as j,isNullCountSupported as Z}from"../../../statistics/utils.js";import{utc as G}from"../../../time/constants.js";import{DateTime as C}from"luxon";const O="bin";class E{constructor(e,t,i){this.items=e,this.query=t,this.geometryType=i.geometryType,this.hasM=i.hasM,this.hasZ=i.hasZ,this.fieldsIndex=i.fieldsIndex,this.objectIdField=i.objectIdField,this.spatialReference=i.spatialReference,this.featureAdapter=i.featureAdapter}get size(){return this.items.length}createQueryResponseForCount(){const e=new l(this.query,this.featureAdapter,this.fieldsIndex);if(!this.query.outStatistics)return e.countDistinctValues(this.items);const{groupByFieldsForStatistics:t,having:i,outStatistics:s}=this.query,a=t?.length;if(!!!a)return 1;const n=new Map,r=new Map,o=new Set;for(const l of s){const{statisticType:s}=l,a="exceedslimit"!==s?l.onStatisticField:void 0;if(!r.has(a)){const i=[];for(const s of t){const t=this._getAttributeValues(e,s,this.items,n);i.push(t)}r.set(a,this._calculateUniqueValues(i,this.items,e.returnDistinctValues))}const u=r.get(a);for(const t in u){const{data:s,items:a}=u[t],n=s.join(",");i&&!e.validateItems(a,i)||o.add(n)}}return o.size}async createQueryResponse(){let e;if(this.query.outStatistics){e=this.query.outStatistics.some(e=>"exceedslimit"===e.statisticType)?this._createExceedsLimitQueryResponse():await this._createStatisticsQueryResponse(this.query,this.items)}else e=this._createFeatureQueryResponse(this.query);if(this.query.returnQueryGeometry){const t=this.query.geometry;r(this.query.outSR)&&!o(t.spatialReference,this.query.outSR)?e.queryGeometry=u({spatialReference:this.query.outSR,...d(t,t.spatialReference,this.query.outSR)}):e.queryGeometry=u({spatialReference:this.query.outSR,...t})}return e}createSnappingResponse(e,t,i){const s=this.featureAdapter,a=Q(this.hasZ,this.hasM),{point:n,mode:r}=e,o="number"==typeof e.distance?e.distance:e.distance.x,l="number"==typeof e.distance?e.distance:e.distance.y,u={candidates:[]},c="esriGeometryPolygon"===this.geometryType,m="esriGeometryPolyline"===this.geometryType||"esriGeometryPoint"===this.geometryType,d=this._getPointCreator(r,t,this.spatialReference,i),f=new U(null,0),y=new U(null,0),g={x:0,y:0,z:0};for(const x of this.items){const t=s.getGeometry(x);if(null==t)continue;const{coords:i}=t,r=t.isPoint?J:t.lengths;if(f.coords=i,y.coords=i,e.returnEdge){let e=0;for(let t=0;t<r.length;t++){const i=r[t],m=e;for(let t=0;t<i;t++,e+=a){if(!c&&t===i-1)continue;const r=f;r.coordsIndex=e;const h=y;h.coordsIndex=t===i-1?m:e+a;const T=g;if(!H(g,n,r,h))continue;const F=(n.x-T.x)/o,I=(n.y-T.y)/l,_=F*F+I*I;_<=1&&u.candidates.push(new p(s.getObjectId(x),d(T),Math.sqrt(_),d(r),d(h)))}}}if("all"===e.vertexMode){let e=0;for(let t=0;t<r.length;t++){const i=r[t],m=e,p=y;p.coordsIndex=m;for(let t=0;t<i;t++,e+=a){const a=f;if(a.coordsIndex=e,c&&t===i-1&&a.x===p.x&&a.y===p.y)continue;const r=(n.x-a.x)/o,m=(n.y-a.y)/l,y=r*r+m*m;y<=1&&u.candidates.push(new h(s.getObjectId(x),d(a),Math.sqrt(y)))}}}else if(m&&"ends"===e.vertexMode){let e=0;const t=[];for(let i=0;i<r.length;i++){t.push(e);const s=r[i];e+=s*a,!c&&s>1&&t.push(e-a)}for(const i of t){const e=f;e.coordsIndex=i;const t=(n.x-e.x)/o,a=(n.y-e.y)/l,r=t*t+a*a;r<=1&&u.candidates.push(new h(s.getObjectId(x),d(e),Math.sqrt(r)))}}}return u.candidates.sort((e,t)=>e.distance-t.distance),u}_getPointCreator(e,t,i,s){const a=null==s||o(i,s)?e=>e:e=>d(e,i,s),{hasZ:n}=this,r=0;return"3d"===e?n&&t?({x:e,y:t,z:i})=>a({x:e,y:t,z:i}):({x:e,y:t})=>a({x:e,y:t,z:r}):({x:e,y:t})=>a({x:e,y:t})}async createSummaryStatisticsResponse(e){const{field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:n,minValue:r,maxValue:o,scale:l,timeZone:u,outStatisticTypes:c}=e,m=this.fieldsIndex.get(t),d=y(m)||g(m)||x(m),f=await this._getDataValues({field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:n,scale:l,timeZone:u},this.items),p=Z({normalizationType:a,normalizationField:s,minValue:r,maxValue:o}),h={value:.5,fieldType:m?.type},F=T(m)?b({values:f,supportsNullCount:p,percentileParams:h,outStatisticTypes:c}):R({values:f,minValue:r,maxValue:o,useSampleStdDev:!a,supportsNullCount:p,percentileParams:h,outStatisticTypes:c});return B(F,c,d)}async createUniqueValuesResponse(e){const{field:t,valueExpression:i,domains:s,returnAllCodedValues:a,scale:n,timeZone:r}=e,o=await this._getDataValues({field:t,field2:e.field2,field3:e.field3,fieldDelimiter:e.fieldDelimiter,valueExpression:i,scale:n,timeZone:r},this.items,!1),l=z(o);return M(l,s,a,e.fieldDelimiter)}async createClassBreaksResponse(e){const{field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:n,classificationMethod:r,standardDeviationInterval:o,minValue:l,maxValue:u,numClasses:c,scale:m,timeZone:d}=e,f=await this._getDataValues({field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:n,scale:m,timeZone:d},this.items),p=A(f,{field:t,normalizationField:s,normalizationType:a,normalizationTotal:n,classificationMethod:r,standardDeviationInterval:o,minValue:l,maxValue:u,numClasses:c});return N(p,r)}async createHistogramResponse(e){const{field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:n,classificationMethod:r,standardDeviationInterval:o,minValue:l,maxValue:u,numBins:c,scale:m,timeZone:d}=e,f=await this._getDataValues({field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:n,scale:m,timeZone:d},this.items);return w(f,{field:t,normalizationField:s,normalizationType:a,normalizationTotal:n,classificationMethod:r,standardDeviationInterval:o,minValue:l,maxValue:u,numBins:c})}_sortFeatures(e,t,i){if(e.length>1&&t?.length)for(const s of t.slice().reverse()){const t=s.split(" "),a=t[0],n=this.fieldsIndex.get(a),r=!!t[1]&&"desc"===t[1].toLowerCase(),o=D(n?.type,r,"case-sensitive");e.sort((e,t)=>{const s=i(e,a,n),r=i(t,a,n);return o(s,r)})}}_createFeatureQueryResponse(e){const{items:t,geometryType:i,hasM:s,hasZ:a,objectIdField:r,spatialReference:o}=this,{outFields:l,outSR:c,quantizationParameters:m,resultRecordCount:d,resultOffset:f,returnZ:p,returnM:h}=e,y=null!=d&&t.length>(f||0)+d,g=l&&(l.includes("*")?[...this.fieldsIndex.fields]:l.map(e=>this.fieldsIndex.get(e)));return{exceededTransferLimit:y,features:this._createFeatures(e,t),fields:g,geometryType:i,hasM:s&&h,hasZ:a&&p,objectIdFieldName:r,spatialReference:u(c||o),transform:m&&n(m)||null}}_createFeatures(e,t){const i=new l(e,this.featureAdapter,this.fieldsIndex),{hasM:s,hasZ:a}=this,{orderByFields:r,quantizationParameters:o,returnGeometry:u,returnCentroid:d,maxAllowableOffset:f,resultOffset:p,resultRecordCount:h,returnZ:y=!1,returnM:g=!1}=e,x=a&&y,T=s&&g;let F=[],I=0;const _=[...t];if(this._sortFeatures(_,r,(e,t,s)=>i.getFieldValue(e,t,s)),this.geometryType&&(u||d)){const e=n(o)??void 0,t="esriGeometryPolygon"===this.geometryType||"esriGeometryPolyline"===this.geometryType;if(u&&!d)for(const s of _){const a=this.featureAdapter.getGeometry(s),n=this._addFeatureJSONMetadata(s,{attributes:i.getAttributes(s),geometry:c(this.geometryType,a,f,e,x,T)});t&&a&&!n.geometry&&(n.centroid=m(this,this.featureAdapter.getCentroid(s,this),e)),F[I++]=n}else if(!u&&d)for(const s of _)F[I++]=this._addFeatureJSONMetadata(s,{attributes:i.getAttributes(s),centroid:m(this,this.featureAdapter.getCentroid(s,this),e)});else for(const s of _)F[I++]=this._addFeatureJSONMetadata(s,{attributes:i.getAttributes(s),centroid:m(this,this.featureAdapter.getCentroid(s,this),e),geometry:c(this.geometryType,this.featureAdapter.getGeometry(s),f,e,x,T)})}else for(const n of _){const e=i.getAttributes(n);e&&(F[I++]=this._addFeatureJSONMetadata(n,{attributes:e}))}const S=p||0;if(null!=h){const e=S+h;F=F.slice(S,Math.min(F.length,e))}return F}_addFeatureJSONMetadata(e,t){const i=this.featureAdapter.getMetadata?.(e);return void 0!==i&&(t.metadata=i),t}_createExceedsLimitQueryResponse(){let e=!1,t=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,s=Number.POSITIVE_INFINITY;for(const a of this.query.outStatistics??[])if("exceedslimit"===a.statisticType){t=null!=a.maxPointCount?a.maxPointCount:Number.POSITIVE_INFINITY,i=null!=a.maxRecordCount?a.maxRecordCount:Number.POSITIVE_INFINITY,s=null!=a.maxVertexCount?a.maxVertexCount:Number.POSITIVE_INFINITY;break}if("esriGeometryPoint"===this.geometryType)e=this.items.length>t;else if(this.items.length>i)e=!0;else{const t=Q(this.hasZ,this.hasM),i=this.featureAdapter;e=this.items.reduce((e,t)=>{const s=i.getGeometry(t);return e+(null!=s&&s.coords.length||0)},0)/t>s}return{fields:[{name:"exceedslimit",type:"esriFieldTypeInteger",alias:"exceedslimit",sqlType:"sqlTypeInteger",domain:null,defaultValue:null}],features:[{attributes:{exceedslimit:Number(e)}}]}}async _createStatisticsQueryResponse(e,t,i={attributes:{}}){const s=[],a=new Map,n=new Map,r=new Map,o=new Map,u=new l(e,this.featureAdapter,this.fieldsIndex),c=e.outStatistics,{groupByFieldsForStatistics:m,having:d,orderByFields:f,resultRecordCount:p}=e,h=m?.length,y=!!h,g=y?m[0]:null,x=y&&!this.fieldsIndex.get(g);for(const l of c??[]){const{outStatisticFieldName:e,statisticType:c}=l,f=l,p="exceedslimit"!==c?l.onStatisticField:void 0,F="percentile_disc"===c||"percentile_cont"===c,I="EnvelopeAggregate"===c||"CentroidAggregate"===c||"ConvexHullAggregate"===c,_=y&&1===h&&(p===g||x)&&"count"===c;if(y){if(!r.has(p)){const e=[];for(const i of m){const s=this._getAttributeValues(u,i,t,a);e.push(s)}r.set(p,this._calculateUniqueValues(e,t,!I&&u.returnDistinctValues))}const i=r.get(p);if(!i)continue;const s=Object.keys(i);for(const n of s){const{count:s,data:r,items:l,itemPositions:c}=i[n],h=r.join(",");if(!d||u.validateItems(l,d)){const i=o.get(h)||{attributes:{}};if(I){i.aggregateGeometries||(i.aggregateGeometries={});const{aggregateGeometries:e,outStatisticFieldName:t}=await this._getAggregateGeometry(f,l);i.aggregateGeometries[t]=e}else{let n=null;if(_)n=s;else{const e=this._getAttributeValues(u,p,t,a),i=c.map(t=>e[t]);n=F&&"statisticParameters"in f?this._getPercentileValue(f,i):this._getStatisticValue(f,i,null,u.returnDistinctValues)}i.attributes[e]=n}let n=0;m.forEach((e,t)=>i.attributes[this.fieldsIndex.get(e)?e:"EXPR_"+ ++n]=r[t]),o.set(h,i)}}}else if(I){i.aggregateGeometries||(i.aggregateGeometries={});const{aggregateGeometries:e,outStatisticFieldName:s}=await this._getAggregateGeometry(f,t);i.aggregateGeometries[s]=e}else{const s=this._getAttributeValues(u,p,t,a);i.attributes[e]=F&&"statisticParameters"in f?this._getPercentileValue(f,s):this._getStatisticValue(f,s,n,u.returnDistinctValues)}const S="min"!==c&&"max"!==c||!T(this.fieldsIndex.get(p))&&!this._isAnyDateField(p)?null:this.fieldsIndex.get(p)?.type;s.push({name:e,alias:e,type:S||"esriFieldTypeDouble"})}const F=y?Array.from(o.values()):[i];return this._sortFeatures(F,f,(e,t)=>e.attributes[t]),p&&(F.length=Math.min(p,F.length)),{fields:s,features:F}}_isAnyDateField(e){const t=this.fieldsIndex.get(e);return y(t)||g(t)||x(t)||F(t)}async _getAggregateGeometry(e,n){const{convexHull:r,union:o}=await import("../../../geometry/geometryEngineJSON.js"),{statisticType:l,outStatisticFieldName:u}=e,{featureAdapter:m,spatialReference:d,geometryType:f}=this,p=n.map(e=>c(f,m.getGeometry(e))),h=r(d,p,!0)[0],y={aggregateGeometries:null,outStatisticFieldName:null};if("EnvelopeAggregate"===l){const e=h?s(h):a(o(d,p));y.aggregateGeometries={...e,spatialReference:d},y.outStatisticFieldName=u||"extent"}else if("CentroidAggregate"===l){const e=h?t(h):i(a(o(d,p)));y.aggregateGeometries={x:e[0],y:e[1],spatialReference:d},y.outStatisticFieldName=u||"centroid"}else"ConvexHullAggregate"===l&&(y.aggregateGeometries=h,y.outStatisticFieldName=u||"convexHull");return y}_getStatisticValue(e,t,i,s){const{onStatisticField:a,statisticType:n}=e;let r=null;r=i?.has(a)?i.get(a):T(this.fieldsIndex.get(a))||this._isAnyDateField(a)?b({values:t,returnDistinct:s}):R({values:s?[...new Set(t)]:t,minValue:null,maxValue:null,useSampleStdDev:!0}),i&&i.set(a,r);return r["var"===n?"variance":n]}_getPercentileValue(e,t){const{onStatisticField:i,statisticParameters:s,statisticType:a}=e,{value:n,orderBy:r}=s,o=this.fieldsIndex.get(i);return P(t,{value:n,orderBy:r,fieldType:o?.type,isDiscrete:"percentile_disc"===a})}_getAttributeValues(e,t,i,s){if(s.has(t))return s.get(t);const a=this.fieldsIndex.get(t),n=i.map(i=>e.getFieldValue(i,t,a));return s.set(t,n),n}_calculateUniqueValues(e,t,i){const s={},a=t.length;for(let n=0;n<a;n++){const a=t[n],r=[];for(const t of e)r.push(t[n]);const o=r.join(",");null==s[o]?s[o]={count:1,data:r,items:[a],itemPositions:[n]}:(i||s[o].count++,s[o].items.push(a),s[o].itemPositions.push(n))}return s}async _getDataValues(t,i,s=!0){const a=new l(this.query,this.featureAdapter,this.fieldsIndex),{valueExpression:n,scale:r,timeZone:o}=t;return n?a.getExpressionValues(i,n,{viewingMode:"map",scale:r,spatialReference:this.query.outSR||this.spatialReference},{geometryType:this.geometryType,hasZ:this.hasZ,hasM:this.hasM},o):a.getDataValues(i,e(t),s)}_calculateHistogramBins(e,t,i){if(null==t.min&&null==t.max)return[];const s=t.intervals,a=t.min??0,n=t.max??0,r=s.map(([e,t])=>({minValue:e,maxValue:t,count:0,items:[]}));for(let o=0;o<e.length;o++){const t=e[o],l=i[o];if(null!=t&&t>=a&&t<=n){const e=q(s,t);e>-1&&(r[e].count++,r[e].items.push(l))}}return r}async createQueryBinsResponse(e){const t=e.bin?.splitBy;if(!t)return this._createBinsResponse(e);const{value:i,outAlias:s,valueType:a}=t,n=[],r=[{name:s??i,alias:s??i,type:a??"esriFieldTypeString"},{name:O,alias:O,type:"esriFieldTypeInteger"}],o=new l(e,this.featureAdapter,this.fieldsIndex),u=new Map,c=[...this.items];this._sortFeatures(c,[i],(e,t,i)=>o.getFieldValue(e,t,i));const m=this._getAttributeValues(o,i,c,u),d=this._calculateUniqueValues([m],c,o.returnDistinctValues);for(const l in d){const{items:t}=d[l],a=await this._createBinsResponse(e,t);if(n.push(...a.features.map(e=>({...e,attributes:{...e.attributes,[s??i]:l}}))),a.fields)for(const e of a.fields)r.some(t=>t.name===e.name)||r.push(e)}return{fields:r,features:n}}async _createBinsResponse(e,t){const i=e.bin;switch(t=t??this.items,i.type){case"autoIntervalBin":return this._createAutoIntervalBinsResponse(I.fromJSON(i),e,t);case"dateBin":return this._createDateBinsResponse(_.fromJSON(i),e,t);case"fixedBoundariesBin":return this._createFixedBoundariesBinsResponse(V.fromJSON(i),e,t);case"fixedIntervalBin":return this._createFixedIntervalBinsResponse(v.fromJSON(i),e,t)}}async _createAutoIntervalBinsResponse(e,t,i){const{field:s,normalizationField:a,numBins:n,normalizationType:r,normalizationTotal:o,start:l,end:u}=e,c=await this._getDataValues({field:e.field,normalizationField:e.normalizationField,normalizationType:e.normalizationType,normalizationTotal:e.normalizationTotal,timeZone:t.outTimeReference?.ianaTimeZone},i),m=j(c,{field:s,normalizationField:a,normalizationType:r,normalizationTotal:o,numBins:n,minValue:f(l,!1),maxValue:f(u,!1)}),d=this._calculateHistogramBins(c,m,i);return this._createFeaturesFromHistogramBins(d,t)}async _createDateBinsResponse(e,t,i){const{field:s,interval:a,start:n,end:r,snapToData:o,returnFullIntervalBin:l}=e,u=a.unit,c=await this._getDataValues({field:e.field,timeZone:t.outTimeReference?.ianaTimeZone},i),m=F(this.fieldsIndex.get(s)),d=S.toJSON(u),p=c.filter(Boolean).sort((e,t)=>e-t),h=null!=n?f(n,m):p[0],y=null!=r?f(r,m):p[p.length-1],g=[];if(null!=h&&null!=y){const e={zone:t.outTimeReference?.ianaTimeZone??G},i=C.fromMillis(h,e),s=C.fromMillis(y,e);if("last"===o){let e=s;for(;e>i;){const t=e.minus({[d]:a.value});if(t<i){g.unshift([l?t.toMillis():i.toMillis(),e.toMillis()]);break}g.unshift([t.toMillis(),e.toMillis()]),e=t}}else{let e="first"===o?i:i.startOf(d);for(;e<=s;){const t=e.plus({[d]:a.value});if(t>s){g.push([e.toMillis(),l?t.toMillis():s.toMillis()]);break}g.push([e.toMillis(),t.toMillis()]),e=t}}}const x=this._calculateHistogramBins(c,{intervals:g,min:h,max:y},i);return this._createFeaturesFromHistogramBins(x,t)}async _createFixedBoundariesBinsResponse(e,t,i){const{field:s}=e,a=await this._getDataValues({field:s,timeZone:t.outTimeReference?.ianaTimeZone},i),n=F(this.fieldsIndex.get(s)),r=e.boundaries.map(e=>f(e,n)).sort((e,t)=>e-t),o=[];for(let c=0;c<r.length-1;c++)o.push([r[c],r[c+1]]);const l={intervals:o,min:r.at(0),max:r.at(-1)},u=this._calculateHistogramBins(a,l,i);return this._createFeaturesFromHistogramBins(u,t)}async _createFixedIntervalBinsResponse(e,t,i){const{field:s,interval:a,start:n,end:r}=e,o=await this._getDataValues({field:e.field,normalizationField:e.normalizationField,normalizationType:e.normalizationType,normalizationTotal:e.normalizationTotal,timeZone:t.outTimeReference?.ianaTimeZone},i),l=F(this.fieldsIndex.get(s)),u=j(o,{field:s,classificationMethod:"defined-interval",definedInterval:a,minValue:f(n,l),maxValue:f(r,l)},!0),c=this._calculateHistogramBins(o,u,i);return this._createFeaturesFromHistogramBins(c,t)}async _createFeaturesFromHistogramBins(e,t){const{upperBoundaryAlias:i,lowerBoundaryAlias:s}=t,a=s||"lowerBoundary",n=i||"upperBoundary",r=[],o=[{name:a,alias:a,type:"esriFieldTypeDouble"},{name:n,alias:n,type:"esriFieldTypeDouble"}],l=t.bin?.stackBy?.value,u=t.bin?.stackBy?.outAlias;l&&o.push({name:O,alias:O,type:"esriFieldTypeInteger"},{name:u??l,alias:u??l,type:"esriFieldTypeString"});let c=0;const m="dateBin"===t.bin.type,d=t.outTimeReference?.ianaTimeZone;for(const f of e){const{minValue:e,maxValue:i,items:s}=f,p={attributes:{}};let h;if(p.attributes[a]=m&&d&&null!=e?C.fromMillis(e,{zone:d}).toISO():e,p.attributes[n]=m&&d&&null!=i?C.fromMillis(i,{zone:d}).toISO():i,l?(h=await this._createStatisticsQueryResponse({...t,groupByFieldsForStatistics:[l],orderByFields:[l]},s),p.attributes[O]=++c,"flat"===t.bin.jsonStyle?r.push(...h.features.map(({attributes:{EXPR_1:e,...t},...i})=>({...i,attributes:u??e?{...t,[u??e]:e,...p.attributes}:{...t,...p.attributes}}))):(p.stackedAttributes=h.features.map(({attributes:{EXPR_1:e,...t}})=>u??e?{...t,[u??e]:e}:t),r.push(p))):(t.bin?.splitBy&&(p.attributes[O]=++c),h=await this._createStatisticsQueryResponse(t,s,p),r.push(p)),h.fields)for(const t of h.fields)o.some(e=>e.name===t.name)||o.push(t)}return"desc"===t.binOrder&&r.reverse(),{fields:o,features:r}}}function H(e,t,i,s){const a=s.x-i.x,n=s.y-i.y,r=t.x-i.x,o=t.y-i.y,l=a*a+n*n;if(0===l)return!1;const u=r*a+o*n,c=Math.min(1,Math.max(0,u/l));return e.x=i.x+a*c,e.y=i.y+n*c,!0}function Q(e,t){return e?t?4:3:t?3:2}class U{constructor(e,t){this.coords=e,this.coordsIndex=t}get x(){return this.coords[this.coordsIndex]}get y(){return this.coords[this.coordsIndex+1]}get z(){return this.coords[this.coordsIndex+2]}}const J=[1];export{E as QueryEngineResult};