@arcgis/core 4.29.0 → 4.29.2

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 (257) hide show
  1. package/arcade/treeAnalysis.js +1 -1
  2. package/assets/esri/core/workers/RemoteClient.js +1 -1
  3. package/assets/esri/core/workers/chunks/{b43fde3e25d0c3b020b5.js → 039a872509872ce67ba4.js} +1 -1
  4. package/assets/esri/core/workers/chunks/{5243f9ff21e768c620c2.js → 23a5d750d93a7829174f.js} +1 -1
  5. package/assets/esri/core/workers/chunks/{47e6119be4a4a5ed640d.js → 2447a4d5886aeb0ff72a.js} +1 -1
  6. package/assets/esri/core/workers/chunks/{7f45a9e9bdbcffc2d6e0.js → 348bcc57b99a975902a8.js} +1 -1
  7. package/assets/esri/core/workers/chunks/{8c9fb2601488998013ba.js → 3523789a2948a4ab8cc8.js} +1 -1
  8. package/assets/esri/core/workers/chunks/{24649b410b757599a549.js → 48db6e0bbb1a9c043193.js} +1 -1
  9. package/assets/esri/core/workers/chunks/{752082be991f1cc8558f.js → 4984e2b79d862114d6a6.js} +1 -1
  10. package/assets/esri/core/workers/chunks/{8d9736fd15cdb54d9855.js → 5227f9eea6988aadad7f.js} +1 -1
  11. package/assets/esri/core/workers/chunks/60ab18c6a04d4b2f1d4c.js +1 -0
  12. package/assets/esri/core/workers/chunks/647515801d94180b8402.js +1 -0
  13. package/assets/esri/core/workers/chunks/6c3ae96ec90e9ed7dd50.js +1 -0
  14. package/assets/esri/core/workers/chunks/7427d03e693f32a81377.js +1 -0
  15. package/assets/esri/core/workers/chunks/7a8bba91769ee18cc39f.js +1 -0
  16. package/assets/esri/core/workers/chunks/7a98d2e026f63a581b1e.js +1 -0
  17. package/assets/esri/core/workers/chunks/8a9387483b19a5ec5b86.js +1 -0
  18. package/assets/esri/core/workers/chunks/{1a25ba411b89e050fbb7.js → a61f337802ae963d7f65.js} +1 -1
  19. package/assets/esri/core/workers/chunks/{d0c5318d7ef2e923aad0.js → a8ac511280f873960d46.js} +1 -1
  20. package/assets/esri/core/workers/chunks/b125ab84b7761e761734.js +1 -0
  21. package/assets/esri/core/workers/chunks/{b34d6e58b125fe111f91.js → b42a83db83851cb57d44.js} +1 -1
  22. package/assets/esri/core/workers/chunks/{1497dd943df7eede0704.js → b9c55ff1f21db198ce03.js} +1 -1
  23. package/assets/esri/core/workers/chunks/bb3322ddb89c0bd444f0.js +1 -0
  24. package/assets/esri/core/workers/chunks/becfdaeeb07f089d8be7.js +1 -0
  25. package/assets/esri/core/workers/chunks/{b26e39a399963c176d33.js → c527692694688a5b3b07.js} +2 -2
  26. package/assets/esri/core/workers/chunks/{210a93e0b96c5bff44a3.js → c556644bb0cf88770939.js} +1 -1
  27. package/assets/esri/core/workers/chunks/{a5e7b4acae17f88e2208.js → ce93027b6b81428ce9b0.js} +1 -1
  28. package/assets/esri/core/workers/chunks/{b8ece275abac93f3dccf.js → d14f16bfa6c12909929c.js} +1 -1
  29. package/assets/esri/core/workers/chunks/{1594f06a2d7d9439c62e.js → e2147c99cc5839654be1.js} +1 -1
  30. package/assets/esri/core/workers/chunks/{d33ed3a2a0d4b640bd4a.js → e4c7d8c69e4957c9d27c.js} +1 -1
  31. package/assets/esri/core/workers/chunks/{7709248f59520aee6f51.js → eceaa46f622f6fa31128.js} +1 -1
  32. package/assets/esri/core/workers/chunks/{2286db4c83ff1b6fb088.js → ef3e6209e6ac6a56960b.js} +1 -1
  33. package/assets/esri/core/workers/chunks/f59b5ea05caca8a1a398.js +1 -0
  34. package/chunks/Laserlines.glsl.js +3 -3
  35. package/chunks/Precipitation.glsl.js +1 -1
  36. package/chunks/SSAOBlur.glsl.js +2 -2
  37. package/chunks/boundedPlane.js +1 -1
  38. package/chunks/cameraUtilsSpherical.js +1 -1
  39. package/chunks/sphere.js +1 -1
  40. package/chunks/terrainUtilsPlanar.js +1 -1
  41. package/chunks/vec32.js +1 -1
  42. package/core/libs/gl-matrix-2/math/quat.js +1 -1
  43. package/core/libs/gl-matrix-2/math/vec3.js +1 -1
  44. package/core/libs/gl-matrix-2/vec3.js +1 -1
  45. package/geohash/geohashUtils.js +1 -1
  46. package/geometry/support/axisAngleDegrees.js +1 -1
  47. package/geometry/support/coordinateSystem.js +1 -1
  48. package/geometry/support/lineSegment.js +1 -1
  49. package/geometry/support/meshUtils/exporters/gltf/gltf.js +1 -1
  50. package/geometry/support/meshUtils/georeference.js +1 -1
  51. package/geometry/support/meshUtils/merge.js +1 -1
  52. package/geometry/support/meshUtils/rotate.js +1 -1
  53. package/geometry/support/meshUtils/scale.js +1 -1
  54. package/geometry/support/meshUtils/vertexSpaceConversion.js +5 -0
  55. package/geometry/support/meshVertexSpaceUtils.js +1 -1
  56. package/geometry/support/plane.js +1 -1
  57. package/geometry/support/ray.js +1 -1
  58. package/geometry/support/triangle.js +1 -1
  59. package/geometry/support/vector.js +1 -1
  60. package/interfaces.d.ts +20 -14
  61. package/kernel.js +1 -1
  62. package/layers/IntegratedMesh3DTilesLayer.js +1 -1
  63. package/layers/LinkChartLayer.js +1 -1
  64. package/layers/VoxelWasmPerSceneView.js +1 -1
  65. package/layers/graphics/data/StreamFeatureManager.js +1 -1
  66. package/layers/knowledgeGraph/KnowledgeGraphLayerDataManager.js +1 -1
  67. package/layers/knowledgeGraph/KnowledgeGraphSublayer.js +1 -1
  68. package/layers/mixins/FeatureReductionLayer.js +1 -1
  69. package/layers/orientedImagery/core/coverageUtils.js +1 -1
  70. package/layers/orientedImagery/transformations/imageToGroundUtils.js +1 -1
  71. package/layers/orientedImagery/transformations/imageToWorld.js +1 -1
  72. package/layers/support/layerUtils.js +1 -1
  73. package/layers/video/VideoCameraSensorModel.js +1 -1
  74. package/layers/voxel/VoxelVolume.js +1 -1
  75. package/layers/voxel/voxelPlaneUtils.js +1 -1
  76. package/libs/linkchartlayout/LinkChartLayout.js +1 -1
  77. package/package.json +1 -1
  78. package/support/revision.js +1 -1
  79. package/symbols/cim/cimAnalyzer.js +1 -1
  80. package/views/2d/arcade/callExpressionWithCursor.js +1 -1
  81. package/views/2d/engine/webgl/collisions/CollisionEngine.js +1 -1
  82. package/views/2d/engine/webgl/shaderGraph/techniques/createTestMeshData.js +1 -1
  83. package/views/2d/engine/webgl/shaderGraph/techniques/mesh/MeshWriterInputEvaluator.js +1 -1
  84. package/views/2d/interactive/editingTools/TransformTool.js +1 -1
  85. package/views/2d/interactive/editingTools/manipulations/ScaleManipulation.js +1 -1
  86. package/views/2d/layers/FeatureLayerView2D.js +1 -1
  87. package/views/2d/layers/features/Processor.js +1 -1
  88. package/views/2d/layers/features/aggregation/GeohashSpatialIndex.js +1 -1
  89. package/views/2d/layers/features/aggregation/GridSpatialIndex.js +1 -1
  90. package/views/2d/layers/features/processor/BinningStrategy.js +1 -1
  91. package/views/2d/layers/features/processor/ClusterStrategy.js +1 -1
  92. package/views/2d/layers/features/processor/FeatureUpdateStrategy.js +1 -1
  93. package/views/2d/layers/features/schema/processor/SimpleProcessorSchema.js +1 -1
  94. package/views/2d/layers/features/schema/processor/SubtypeProcessorSchema.js +1 -1
  95. package/views/2d/layers/features/sources/strategies/StreamLoadStrategy.js +1 -1
  96. package/views/2d/layers/features/sources/strategies/chunks/DrillDownTileSourceChunk.js +1 -1
  97. package/views/2d/layers/features/sources/strategies/chunks/FeatureSnapshotSourceChunk.js +1 -1
  98. package/views/2d/layers/features/sources/strategies/chunks/OverrideChunk.js +1 -1
  99. package/views/2d/layers/features/sources/strategies/chunks/PagedTileSourceChunk.js +1 -1
  100. package/views/2d/layers/features/sources/strategies/chunks/StreamSourceChunk.js +1 -1
  101. package/views/2d/layers/features/support/AttributeStore.js +1 -1
  102. package/views/2d/layers/features/support/GraphicsReader.js +1 -1
  103. package/views/2d/layers/features/support/Tile.js +1 -1
  104. package/views/2d/layers/graphics/GraphicsView2D.js +1 -1
  105. package/views/2d/tiling/TileKey.js +1 -1
  106. package/views/3d/analysis/AreaMeasurement/support/MeasurementData.js +1 -1
  107. package/views/3d/analysis/Dimension/lengthDimensionConstraintUtils.js +1 -1
  108. package/views/3d/analysis/Dimension/lengthDimensionManipulatorUtils.js +1 -1
  109. package/views/3d/analysis/Dimension/lengthDimensionUtils.js +1 -1
  110. package/views/3d/analysis/DirectLineMeasurement/DirectLineMeasurementController.js +1 -1
  111. package/views/3d/analysis/LineOfSight/LineOfSightController.js +1 -1
  112. package/views/3d/analysis/LineOfSight/LineOfSightIntersectionResult.js +1 -1
  113. package/views/3d/analysis/Slice/SliceTool.js +1 -1
  114. package/views/3d/analysis/Slice/sliceToolUtils.js +1 -1
  115. package/views/3d/analysis/support/measurementUtils.js +1 -1
  116. package/views/3d/animation/pointToPoint/Camera.js +1 -1
  117. package/views/3d/camera/constraintUtils/common.js +1 -1
  118. package/views/3d/camera/constraintUtils/distance.js +1 -1
  119. package/views/3d/camera/constraintUtils/tilt.js +1 -1
  120. package/views/3d/camera/intersectionUtils.js +1 -1
  121. package/views/3d/environment/ChapmanAtmosphere.js +1 -1
  122. package/views/3d/environment/EnvironmentRenderer.js +1 -1
  123. package/views/3d/environment/Fog.js +1 -1
  124. package/views/3d/environment/MarsAtmosphere.js +1 -1
  125. package/views/3d/environment/SceneViewEnvironmentManager.js +1 -1
  126. package/views/3d/interactive/SnappingVisualizer3D.js +1 -1
  127. package/views/3d/interactive/editingTools/dragEventPipeline3D.js +1 -1
  128. package/views/3d/interactive/editingTools/manipulations/MoveZManipulation.js +1 -1
  129. package/views/3d/interactive/editingTools/reshapeGraphic/ReshapeOperation.js +1 -1
  130. package/views/3d/interactive/editingTools/reshapeGraphic/edgeOffsetUtils.js +1 -1
  131. package/views/3d/interactive/editingTools/transformGraphic/ExtentScale.js +1 -1
  132. package/views/3d/interactive/editingTools/transformGraphic/extentUtils.js +1 -1
  133. package/views/3d/interactive/visualElements/ExtendedLineVisualElement.js +1 -1
  134. package/views/3d/interactive/visualElements/ParallelLineVisualElement.js +1 -1
  135. package/views/3d/interactive/visualElements/RightAngleQuadVisualElement.js +1 -1
  136. package/views/3d/interactive/visualElements/support/Segment.js +1 -1
  137. package/views/3d/layers/I3SMeshView3D.js +1 -1
  138. package/views/3d/layers/PointCloudLayerView3D.js +1 -1
  139. package/views/3d/layers/PointCloudWorker.js +1 -1
  140. package/views/3d/layers/graphics/Graphics3DMeshFillSymbolLayer.js +1 -1
  141. package/views/3d/layers/graphics/Graphics3DObjectSymbolLayer.js +1 -1
  142. package/views/3d/layers/graphics/objectResourceUtils.js +1 -1
  143. package/views/3d/layers/i3s/I3SClientNodeLoader.js +1 -1
  144. package/views/3d/layers/i3s/I3SViewportQueries.js +1 -1
  145. package/views/3d/layers/i3s/LoDUtil.js +1 -1
  146. package/views/3d/layers/i3s/PointRenderer.js +1 -1
  147. package/views/3d/layers/support/FeatureTileMeasurements3D.js +1 -1
  148. package/views/3d/layers/support/FeatureTileVisibility3D.js +1 -1
  149. package/views/3d/layers/support/uvUtils.js +1 -1
  150. package/views/3d/state/Frustum.js +1 -1
  151. package/views/3d/state/NearFarHeuristic.js +1 -1
  152. package/views/3d/state/controllers/GamepadKeyboardController.js +1 -1
  153. package/views/3d/state/controllers/RotateController.js +1 -1
  154. package/views/3d/state/controllers/global/PinchAndPanController.js +1 -1
  155. package/views/3d/state/controllers/global/ZoomController.js +1 -1
  156. package/views/3d/state/controllers/global/ZoomStepController.js +1 -1
  157. package/views/3d/state/controllers/local/PinchAndPanController.js +1 -1
  158. package/views/3d/state/controllers/local/ZoomController.js +1 -1
  159. package/views/3d/state/controllers/local/ZoomStepController.js +1 -1
  160. package/views/3d/state/controllers/momentum/ZoomPlanarMomentumController.js +1 -1
  161. package/views/3d/state/helpers/SceneIntersectionHelper.js +1 -1
  162. package/views/3d/state/utils/navigationUtils.js +1 -1
  163. package/views/3d/state/utils/viewUtils.js +1 -1
  164. package/views/3d/support/FrustumExtentIntersection.js +1 -1
  165. package/views/3d/support/cameraUtils.js +1 -1
  166. package/views/3d/support/cameraUtilsInternal.js +1 -1
  167. package/views/3d/support/intersectionUtils.js +1 -1
  168. package/views/3d/support/mathUtils.js +1 -1
  169. package/views/3d/support/orientedBoundingBox.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/pointsOfInterest/PointsOfInterest.js +1 -1
  174. package/views/3d/support/sunUtils.js +1 -1
  175. package/views/3d/support/viewpointUtils.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/TerrainRenderer.js +1 -1
  180. package/views/3d/terrain/Tile.js +1 -1
  181. package/views/3d/webgl-engine/collections/Component/DepthRange.js +1 -1
  182. package/views/3d/webgl-engine/collections/Component/IntersectionGeometry.js +1 -1
  183. package/views/3d/webgl-engine/collections/Component/Material/ComponentMaterial.js +1 -1
  184. package/views/3d/webgl-engine/core/util/TwoVectorPosition.js +1 -1
  185. package/views/3d/webgl-engine/effects/RenderNodes.js +1 -1
  186. package/views/3d/webgl-engine/effects/highlight/ShadowHighlight.js +1 -1
  187. package/views/3d/webgl-engine/lib/BoundingInfo.js +1 -1
  188. package/views/3d/webgl-engine/lib/Camera.js +1 -1
  189. package/views/3d/webgl-engine/lib/GeometryUtil.js +1 -1
  190. package/views/3d/webgl-engine/lib/Object3D.js +1 -1
  191. package/views/3d/webgl-engine/lib/Octree.js +1 -1
  192. package/views/3d/webgl-engine/lib/PathVertex.js +1 -1
  193. package/views/3d/webgl-engine/lib/Renderer.js +1 -1
  194. package/views/3d/webgl-engine/lib/ShadowAccumulator.js +1 -1
  195. package/views/3d/webgl-engine/lib/ShadowMap.js +1 -1
  196. package/views/3d/webgl-engine/lib/edgeRendering/EdgeView.js +1 -1
  197. package/views/3d/webgl-engine/lib/edgeRendering/edgePreprocessing.js +1 -1
  198. package/views/3d/webgl-engine/lib/geometryDataUtils.js +1 -1
  199. package/views/3d/webgl-engine/lib/intersectorUtils.js +1 -1
  200. package/views/3d/webgl-engine/lib/lodRendering/LodRenderer.js +1 -1
  201. package/views/3d/webgl-engine/lib/verticalOffsetUtils.js +1 -1
  202. package/views/3d/webgl-engine/lighting/SceneLighting.js +1 -1
  203. package/views/3d/webgl-engine/lighting/SphericalHarmonics.js +1 -1
  204. package/views/3d/webgl-engine/materials/DefaultMaterial.js +1 -1
  205. package/views/3d/webgl-engine/materials/HUDMaterial.js +1 -1
  206. package/views/3d/webgl-engine/materials/LineMarkerMaterial.js +1 -1
  207. package/views/3d/webgl-engine/materials/MeasurementArrowMaterial.js +1 -1
  208. package/views/3d/webgl-engine/materials/NativeLineMaterial.js +1 -1
  209. package/views/3d/webgl-engine/materials/RibbonLineMaterial.js +1 -1
  210. package/views/3d/webgl-engine/materials/pbrUtils.js +1 -1
  211. package/views/SelectionManager.js +1 -1
  212. package/views/draw/support/createUtils.js +1 -1
  213. package/views/draw/support/surfaceCoordinateSystems.js +1 -1
  214. package/views/interactive/GraphicManipulator.js +1 -1
  215. package/views/interactive/SegmentLabels.js +1 -1
  216. package/views/interactive/coordinateHelper.js +1 -1
  217. package/views/interactive/editGeometry/operations/OffsetEdgeVertex.js +1 -1
  218. package/views/interactive/editGeometry/support/editPlaneUtils.js +1 -1
  219. package/views/interactive/sketch/constraints.js +1 -1
  220. package/views/interactive/snapping/RightAngleSnapper.js +1 -1
  221. package/views/interactive/snapping/candidates/ParallelLineSnappingCandidate.js +1 -1
  222. package/views/interactive/snapping/candidates/RightAngleTriangleSnappingCandidate.js +1 -1
  223. package/views/interactive/snapping/featureSources/sceneLayerSource/SceneLayerSnappingSourceWorker.js +1 -1
  224. package/views/interactive/snapping/featureSources/sceneLayerSource/sceneLayerSnappingUtils.js +1 -1
  225. package/views/interactive/snapping/hints/IntersectionSnappingHint.js +1 -1
  226. package/views/interactive/snapping/hints/LineSnappingHint.js +1 -1
  227. package/views/interactive/snapping/hints/ParallelSnappingHint.js +1 -1
  228. package/views/interactive/snapping/hints/PointSnappingHint.js +1 -1
  229. package/views/interactive/snapping/hints/RightAngleSnappingHint.js +1 -1
  230. package/views/layers/FeatureLayerView.js +1 -1
  231. package/views/navigation/PanSphericalMomentumEstimator.js +1 -1
  232. package/views/support/angularMeasurementUtils.js +1 -1
  233. package/views/support/euclideanAreaMeasurementUtils.js +1 -1
  234. package/views/support/euclideanLengthMeasurementUtils.js +1 -1
  235. package/views/support/geometry3dUtils.js +1 -1
  236. package/widgets/Editor/EditorViewModel.js +1 -1
  237. package/widgets/ElevationProfile/support/geometryUtils.js +1 -1
  238. package/widgets/FeatureTable/FeatureTableViewModel.js +1 -1
  239. package/widgets/FeatureTable/Grid/Grid.js +1 -1
  240. package/widgets/FeatureTable/support/ColumnTemplateBase.js +1 -1
  241. package/widgets/Features/FeaturesViewModel.js +1 -1
  242. package/widgets/PanoramicViewer/PanoramicViewerViewModel.js +1 -1
  243. package/widgets/PanoramicViewer/utils.js +1 -1
  244. package/widgets/UtilityNetworkTrace/UtilityNetworkTraceViewModel.js +1 -1
  245. package/widgets/support/Selector2D/SelectionOperation.js +1 -1
  246. package/widgets/support/Selector2D/selectorUtils.js +1 -1
  247. package/assets/esri/core/workers/chunks/0e83f3718a0b45652b5e.js +0 -1
  248. package/assets/esri/core/workers/chunks/1fa5c8af69a09a3730b3.js +0 -1
  249. package/assets/esri/core/workers/chunks/4736f79b5c94ce103d43.js +0 -1
  250. package/assets/esri/core/workers/chunks/65f7adaaf1f535310c11.js +0 -1
  251. package/assets/esri/core/workers/chunks/79c041b292648c5eaecc.js +0 -1
  252. package/assets/esri/core/workers/chunks/7c4c2c0beddabac672b6.js +0 -1
  253. package/assets/esri/core/workers/chunks/9307d485a9e5f9fa77d1.js +0 -1
  254. package/assets/esri/core/workers/chunks/9a758de08dfa57735879.js +0 -1
  255. package/assets/esri/core/workers/chunks/a4c3da057ec2a07bbbe8.js +0 -1
  256. package/assets/esri/core/workers/chunks/b252270b100351779f1f.js +0 -1
  257. package/assets/esri/core/workers/chunks/dc57aa9f2fc69e654559.js +0 -1
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.29/esri/copyright.txt for details.
4
4
  */
5
- import{_ as t}from"../../chunks/tslib.es6.js";import{createTask as e}from"../../core/asyncUtils.js";import a from"../../core/Collection.js";import{deprecatedProperty as r,deprecated as i}from"../../core/deprecate.js";import s from"../../core/Error.js";import o from"../../core/Evented.js";import{makeHandle as n}from"../../core/handleUtils.js";import l from"../../core/Logger.js";import{abortMaybe as p,removeMaybe as d,destroyMaybe as c}from"../../core/maybe.js";import{throwIfAborted as u,createResolver as h}from"../../core/promiseUtils.js";import{watch as w,on as f,when as m,whenOnce as y,syncAndInitial as k,initial as g,sync as v}from"../../core/reactiveUtils.js";import{property as _}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as W}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as b}from"../../core/support/UpdatingHandles.js";import I from"../../layers/GraphicsLayer.js";import{isEditableLayer as F}from"../../layers/support/editableLayers.js";import{isFeatureLayer as E,getOwningPortalUrl as M}from"../../layers/support/layerUtils.js";import{parseKnownArcGISOnlineDomain as C}from"../../portal/support/urlUtils.js";import V from"../../views/interactive/sketch/SketchOptions.js";import{SnappingManager as O}from"../../views/interactive/snapping/SnappingManager.js";import U from"../../views/interactive/snapping/SnappingOptions.js";import T from"../Attachments/AttachmentsViewModel.js";import L from"./CreateFeaturesWorkflow.js";import A from"./UpdateWorkflow.js";import{whenEditorLayerView as j}from"./workflowUtils.js";import S from"./support/EditorItem.js";import P from"../FeatureTemplates/FeatureTemplatesViewModel.js";import R from"../Sketch/SketchViewModel.js";import H from"../Spinner/SpinnerViewModel.js";const x="esri.widgets.Editor.EditorViewModel",D=()=>l.getLogger(x),G=["create-features","update"];function q(t,e,a){D().error(new s(t,e,a))}function B(t,e){return t?.find((t=>t.layer===e))}let Q=class extends o.EventedAccessor{constructor(t){super(t),this._sketchEventListenerHandle=null,this._sketchGraphicsLayer=new I({listMode:"hide",internal:!0}),this._snappingManager=null,this._updateItemsTask=null,this._updatingHandles=new b,this._featureTemplatesViewModelLocked=!1,this.activeWorkflow=null,this._activityQueue=new a,this.editorItems=new a,this.failures=[],this.hideTemplatesForInactiveLayers=!1,this.attachmentsViewModel=new T({capabilities:{editing:!0}}),this.featureTemplatesViewModel=new P({disabledItemFunction:({layer:t})=>this._itemIsSuspended(t)}),this.ownSketchViewModel=new R({layer:this._sketchGraphicsLayer}),this.sketchOptions=new V,this.snappingOptions=new U,this.spinnerViewModel=new H,this.pageStack=[],this.showDiscardEditsPrompt=()=>Promise.resolve(!0),this._candidateCommitted=!1,this.back=async()=>{this.canGoBack&&(this.activeWorkflow?.hasPreviousStep?await this.activeWorkflow.back(this.showDiscardEditsPrompt):await this._cancelWorkflow({force:!this.hasPendingEdits}))},this.saveWorkflow=async()=>{const{featureFormViewModel:t}=this;if(t){if(t.submit(),!t.submittable)return;const e=t.getValues();if(t.validateContingencyConstraints(e,{includeIncompleteViolations:!0}).length>0)return}await(this.activeWorkflow?.save())},this.selectFeature=(t,e=!1)=>{const a=this.activeWorkflow;this._candidateCommitted||"update"!==a?.type||(a.data.rootFeature=t,e&&(a.next(),this._candidateCommitted=!0))}}initialize(){this.addHandles([w((()=>{const t=this.view,e=t?.map?.editableLayers,a=t?.allLayerViews,r=a?.filter((t=>!!e?.includes(t.layer)));return[e,r,this.layerInfos,this.allowedWorkflows]}),(()=>this._updateEditorItems()),k),w((()=>this.hideTemplatesForInactiveLayers),(()=>this.syncFeatureTemplates())),f((()=>this.activeWorkflow),"cancel",(()=>this.emit("workflow-cancel"))),f((()=>this.activeWorkflow),"commit",(()=>this.emit("workflow-commit"))),f((()=>this.activeWorkflow),"complete",(()=>{this.emit("workflow-commit"),this._set("activeWorkflow",null)})),m((()=>this.view?.map),(t=>t.add(this._sketchGraphicsLayer)),g),f((()=>this.editorItems),"change",(()=>this._afterEditorItemsChange())),w((()=>[this.canCreate,this.canUpdateVisible]),(()=>this._afterEditorItemsChange())),w((()=>this.page),((t,e)=>{const a=[...this.pageStack];if(-1===a.indexOf(t))a.push(t);else for(;a.length&&a.at(-1)!==t;)a.pop();this.pageStack=a}),k),m((()=>"awaiting-update-feature-candidate"===this.state),(()=>this._candidateCommitted=!1)),f((()=>this.featureTemplatesViewModel),"select",(async({item:t,oldItem:e})=>{const{activeWorkflow:a}=this;if(a){if("update"===a.type&&"awaiting-feature-creation-info"===a.activeWorkflow?.stepId)return;try{await this.cancelWorkflow({force:!this.hasPendingEdits})}catch{return void this.featureTemplatesViewModel.select(e,{emit:!1})}}if(!t)return;const r={layer:t.layer,template:t.template};if(t.supportsUpload)return this.featureTemplatesViewModel.select(e,{emit:!1}),this.startCreateFeaturesWorkflow(r);this.startCreateFeaturesWorkflowAtFeatureCreation(r)})),f((()=>this.view),"key-down",(t=>{"Escape"===t.key&&this.activeWorkflow?.keyboardCancellationEnabled&&(t.stopPropagation(),this.back())})),f((()=>this.sketchViewModel),["create","delete","update"],(t=>{const{activeWorkflow:e}=this,a="update"===e?.type,r=a?e.activeWorkflow?.layer:e?.layer,i=a?e?.activeWorkflow?.parentLayer:void 0,s=`sketch-${t.type}`;this.emit(s,{type:s,detail:t,layer:r,parentLayer:i})}),v),w((()=>this.view),(t=>{if(this._snappingManager=c(this._snappingManager),!t)return;const e=this.snappingOptions;this._snappingManager=new O({view:t,options:e})}),k),w((()=>this.snappingOptions),(t=>{this._snappingManager&&(this._snappingManager.options=t)}),k)])}destroy(){this._cancelWorkflow({warnIfNoWorkflow:!1}).then((()=>{this.view?.map?.remove(this._sketchGraphicsLayer),this.view=null})),this._updateItemsTask=p(this._updateItemsTask),this._updatingHandles.destroy(),this._sketchEventListenerHandle=d(this._sketchEventListenerHandle)}get allowedWorkflows(){return this._get("allowedWorkflows")}set allowedWorkflows(t){r(l.getLogger(this),"allowedWorkflows",{replacement:"Editor.visibleElements",version:"4.29",warnOnce:!0}),t&&0!==t.length||(t=[...G]),this._set("allowedWorkflows",t)}get canCreate(){return this.editorItems.some((t=>t.supportsCreateFeaturesWorkflow))}get canCreateVisible(){return!!this.featureTemplatesLayers.length}get canUpdate(){return this.editorItems.some((t=>t.supportsUpdateWorkflow))}get canUpdateVisible(){return this.editorItems.some((t=>t.supportsUpdateWorkflow&&t.visible))}get featureTemplatesLayers(){const t=new a;for(const e of this.editorItems){const a=e.supportsCreateFeaturesWorkflow&&!e.isTable,r=this.hideTemplatesForInactiveLayers&&!e.visible;a&&!r&&t.push(e.layer)}return t}get editableItems(){return r(l.getLogger(this),"editableItems",{replacement:"editorItems",version:"4.29",warnOnce:!0}),this.editorItems.map((t=>{const{capabilities:e,disabled:a,hasInvalidFormTemplate:r,layer:i}=t,s=[],o=e.create,n=e.update,l=e.delete;return o.enabled&&s.push("create"),n.enabled&&s.push("update"),l.enabled&&s.push("delete"),{layer:i,supports:s,suspended:a,attributeUpdatesEnabled:n.attributes,geometryUpdatesEnabled:n.geometry,attachmentsOnCreateEnabled:o.attachments.enabled,attachmentsOnUpdateEnabled:n.attachments.enabled,hasInvalidFormTemplate:r,hasAttachments:e.attachments.enabled}}))}get featureFormViewModel(){const{activeWorkflow:t}=this;return"update"===t?.type?t.activeFeatureFormViewModel:"create-features"===t?.type?t.featureFormViewModel:null}get labelOptions(){return this.sketchOptions.labels}set labelOptions(t){this.sketchOptions.labels=t}set layerInfos(t){const e=t?.some((t=>"allowAttachments"in t));e&&i(D(),"Property: layerInfo.allowAttachments",{replacement:"layerInfo.attachmentsOnCreateEnabled or layerInfo.attachmentsOnUpdateEnabled",version:"4.26"}),this._set("layerInfos",t)}get sketchViewModel(){const{activeWorkflow:t}=this;return"update"===t?.type?t.activeSketchViewModel:"create-features"===t?.type?t.sketchViewModel:this.ownSketchViewModel}get state(){if(!this.view?.ready)return"disabled";const t=this.attachmentsViewModel.mode;if("add"===t)return"adding-attachment";if("edit"===t)return"editing-attachment";const{activeWorkflow:e}=this;return e?.stepId?"update"===e.type&&e.activeWorkflow?.stepId?e.activeWorkflow.stepId:e.stepId:"ready"}get syncing(){return this._activityQueue.length>0}get updating(){return this._updatingHandles.updating||!0===this.activeWorkflow?.updating}get tooltipOptions(){return this.sketchOptions.tooltips}set tooltipOptions(t){this.sketchOptions.tooltips=t}get valueOptions(){return this.sketchOptions.values}set valueOptions(t){this.sketchOptions.values=t}set view(t){this.ownSketchViewModel.view=t,this.spinnerViewModel.view=t,this._set("view",t)}get page(){const{activeWorkflow:t,state:e}=this;if("update"===t?.type&&"awaiting-feature-to-update"===t.stepId)return"ready";if("create-features"===t?.type&&0===t.numPendingFeatures){const e=t.data.upload;if(e)return"default"===e.state?"ready":"creating-features-upload-details"}return e??"disabled"}get featureFormDisabled(){const{activeWorkflow:t}=this;return"update"===t?.type&&!1===t.activeEditorItem?.capabilities.update.attributes}get canGoBack(){return null!=this.activeWorkflow&&!this.syncing}get shouldShowDeleteButton(){const{activeWorkflow:t}=this;return!!t&&"update"===t.type&&!!t.activeEditorItem?.capabilities.delete.enabled}get hasPendingEdits(){return this.activeWorkflow?.hasPendingEdits??!1}async startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.startCreateFeaturesWorkflow()}async startCreateFeaturesWorkflowAtFeatureCreation(t){return this.startCreateFeaturesWorkflow(t,"creating-features")}async startCreateFeaturesWorkflow(t,e="awaiting-feature-creation-info"){if(await y((()=>!this.updating)),!this.canCreate)throw new s("editing:unsupported-workflow","Creating features is unsupported or disabled.");const a=this._createUpdatingResolver();await this._cancelWorkflow();const r=this._createCreateFeaturesWorkflow(t,e);this._set("activeWorkflow",r),await r.start(),a.resolve()}async startCreateFeaturesWorkflowAtFeatureEdit(t){await y((()=>!this.updating));const e=this._createUpdatingResolver(),{initialFeature:a}=t,r=a.sourceLayer,i=r?this.findEditorItemForLayer(r):void 0;if(!i?.supportsCreateFeaturesWorkflow)throw new s("editing:unsupported-workflow","Creating features is unsupported or disabled for this layer.");await this._cancelWorkflow();const o=this._createCreateFeaturesWorkflow({initialFeature:a,layer:i.layer,maxFeatures:1},"creating-features");this._set("activeWorkflow",o),await o.start(),e.resolve()}async startUpdateWorkflowAtFeatureSelection(){if(await y((()=>!this.updating)),!this.canUpdate)return void q("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const t=this._createUpdatingResolver();await this._cancelWorkflow();const e=this._createUpdateWorkflow();this._set("activeWorkflow",e),await e.start(),t.resolve()}async startUpdateWorkflowAtMultipleFeatureSelection(t){if(await y((()=>!this.updating)),!this.canUpdate)return void q("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();await this._cancelWorkflow();const a=this._createUpdateWorkflow("awaiting-update-feature-candidate");a.data.candidates=t,this._set("activeWorkflow",a),await a.start(),e.resolve()}async startUpdateWorkflowAtFeatureEdit(t){if(await y((()=>!this.updating)),!this.canUpdate)return void q("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();await this._cancelWorkflow();const a=this._createUpdateWorkflow("editing-existing-feature");a.data.rootFeature=t,this._set("activeWorkflow",a),await a.start(),e.resolve()}async deleteFeatureFromWorkflow(){const{activeWorkflow:t}=this;t&&"update"===t.type?await t.deleteActiveFeature():q("editing:unsupported-workflow","Deleting requires an active update workflow.")}async cancelWorkflow(t){return this._cancelWorkflow({warnIfNoWorkflow:!0,...t})}findEditorItemForLayer(t){const e="subtype-sublayer"===t.type?t.parent:t;return this.editorItems.find((t=>t.layer===e))}itemHasInvalidFormTemplate(t){return null!=t&&!0===this.findEditorItemForLayer(t.layer)?.hasInvalidFormTemplate}syncFeatureTemplates(){this._featureTemplatesViewModelLocked||(this.featureTemplatesViewModel.layers=this.featureTemplatesLayers.toArray())}async toggleUpdateWorkflow(){this.canUpdate&&(this.hasPendingEdits&&!await this.showDiscardEditsPrompt()||(this.activeWorkflow&&"awaiting-feature-to-update"===this.state?await this.cancelWorkflow({force:!0}):await this.startUpdateWorkflowAtFeatureSelection()))}lockFeatureTemplatesViewModel(){return this._featureTemplatesViewModelLocked=!0,n((()=>{this._featureTemplatesViewModelLocked=!1,this.syncFeatureTemplates()}))}async _getEditorItemCandidates(t){const{view:e}=this;if(!e?.map)return[];const{map:a}=e,r=a.editableLayers.toArray()??[],i=a.allTables.toArray().filter(E)??[];return await Promise.allSettled([...r.map((t=>"subtype-group"===t.type?t.loadAll():Promise.resolve())),...i.map((t=>t.load()))]),u(t),[...r.reverse(),...i.reverse()].filter((t=>F(t)&&("mesh"!==t.geometryType||"3d"===e.type))).flatMap((t=>"subtype-group"===t.type?t.sublayers.toArray():t))}_drainEditorItems(){this.editorItems.drain((t=>t.destroy()))}async _updateEditorItems(){p(this._updateItemsTask);const{view:t}=this,a=e((async e=>{if(!t?.map||!t?.allLayerViews)return;const a=await this._getEditorItemCandidates(e);if(!a.length)return void this._drainEditorItems();const r=[],i=[],s=[],{layerInfos:o}=this;for(const l of a){const e=B(o,l),a=await j(t,l).catch((()=>null));(e?r:a?i:s).push(new S({layer:l,layerInfo:e,layerView:a}))}o?.length&&r.sort(((t,e)=>o.findIndex((({layer:e})=>e===t.layer))-o.findIndex((({layer:t})=>t===e.layer))));const n=[...r,...i,...s];e.aborted||(this._drainEditorItems(),this.editorItems.addMany(n))}));this._updatingHandles.addPromise(a.promise),this._updateItemsTask=a}_afterEditorItemsChange(){const{activeWorkflow:t}=this;if(this.syncFeatureTemplates(),!t)return;const{stepId:e}=t;"create-features"!==t.type?"update"===t.type&&("awaiting-feature-to-update"===e&&!this.canUpdateVisible||"awaiting-update-feature-candidate"===e&&!t.hasUpdatableCandidates)&&this._cancelWorkflow():"awaiting-feature-creation-info"!==e||this.canCreate||this._cancelWorkflow()}async _cancelWorkflow(t){const e=this.activeWorkflow;if(!e)return void(t?.warnIfNoWorkflow&&q("editing:no-active-workflow","There is no active workflow to cancel."));if(!t||!1!==t.force)return this.emit("workflow-cancel"),this._set("activeWorkflow",null),void await e.cancel(t);await e.cancel(t),this._set("activeWorkflow",null)}_createCreateFeaturesWorkflow(t,e){return L.create({viewModel:this,creationInfo:t,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:e,applyEditsCallback:(t,e,a)=>this._applyEdits(t,e,a),addAttachmentsCallback:(t,e)=>this._addAttachments(t,e)})}_createUpdateWorkflow(t){return A.create({viewModel:this,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:t,applyEditsCallback:(t,e,a)=>this._applyEdits(t,e,a),addAttachmentsCallback:(t,e)=>this._addAttachments(t,e)})}_addAttachments(t,e){const a=e.map((e=>this._addAttachment(t,e.feature,e.attachment)))??[];return Promise.all(a)}async _addAttachment(t,e,a){let r=null;if(!("addAttachment"in t)||null==t.capabilities?.attachment)throw new s("editor:attachments-not-supported","Adding attachments is not supported for this layer type");return await this._queueOperation((async()=>(r=await(t.addAttachment?.(e,a).catch((t=>{throw t?.error||t})))??null,r))),r}async _applyEdits(t,e,a){let r=null;const i=t.url?await M(t.url):null,s={returnServiceEditsOption:(!i||!C(i))&&!RegExp("/hosted/","i").test(t.url)?"original-and-current-features":void 0,...a};return await this._queueOperation((async()=>{const{view:a}=this;if(!a)return null;const i=await j(a,t).catch((()=>null));return r=await t.applyEdits(e,s),i&&await y((()=>!i.updating)),r})),r}_queueOperation(t){this._activityQueue.push(t);const e=(t,e)=>{const a=e.indexOf(t);a>-1&&e.splice(a,1)};return t().then((t=>{if(null!=t&&"error"in t&&null!=t.error)throw t.error;if(null!=t&&"addFeatureResults"in t){const{addFeatureResults:e,deleteFeatureResults:a,updateFeatureResults:r}=t,i=e.find((t=>!!t.error))||r.find((t=>!!t.error))||a.find((t=>!!t.error));if(i)throw i.error}return t})).catch((a=>{q("editing:operation-error","An error occurred.",{error:a});const r={error:a,retry:()=>(e(r,this.failures),this._queueOperation(t)),cancel:()=>{e(r,this.failures)}};this._set("failures",[...this.failures,r])})).then((()=>{e(t,this._activityQueue)}))}_createUpdatingResolver(){const t=h();return this._updatingHandles.addPromise(t.promise),t}_itemIsSuspended(t){const e=this.findEditorItemForLayer(t);return null!=e&&(!e.visible||e.disabled)}};t([_({readOnly:!0})],Q.prototype,"activeWorkflow",void 0),t([_({readOnly:!0})],Q.prototype,"_activityQueue",void 0),t([_({value:[...G]})],Q.prototype,"allowedWorkflows",null),t([_({readOnly:!0})],Q.prototype,"canCreate",null),t([_()],Q.prototype,"canCreateVisible",null),t([_({readOnly:!0})],Q.prototype,"canUpdate",null),t([_()],Q.prototype,"canUpdateVisible",null),t([_()],Q.prototype,"featureTemplatesLayers",null),t([_()],Q.prototype,"editableItems",null),t([_()],Q.prototype,"editorItems",void 0),t([_({readOnly:!0})],Q.prototype,"failures",void 0),t([_()],Q.prototype,"hideTemplatesForInactiveLayers",void 0),t([_()],Q.prototype,"attachmentsViewModel",void 0),t([_()],Q.prototype,"featureFormViewModel",null),t([_()],Q.prototype,"featureTemplatesViewModel",void 0),t([_()],Q.prototype,"labelOptions",null),t([_()],Q.prototype,"layerInfos",null),t([_()],Q.prototype,"ownSketchViewModel",void 0),t([_()],Q.prototype,"sketchOptions",void 0),t([_()],Q.prototype,"sketchViewModel",null),t([_({type:U,nonNullable:!0})],Q.prototype,"snappingOptions",void 0),t([_()],Q.prototype,"spinnerViewModel",void 0),t([_()],Q.prototype,"state",null),t([_({readOnly:!0})],Q.prototype,"syncing",null),t([_()],Q.prototype,"updating",null),t([_()],Q.prototype,"tooltipOptions",null),t([_()],Q.prototype,"valueOptions",null),t([_()],Q.prototype,"view",null),t([_()],Q.prototype,"pageStack",void 0),t([_()],Q.prototype,"showDiscardEditsPrompt",void 0),t([_()],Q.prototype,"_candidateCommitted",void 0),t([_()],Q.prototype,"page",null),t([_()],Q.prototype,"featureFormDisabled",null),t([_()],Q.prototype,"canGoBack",null),t([_()],Q.prototype,"shouldShowDeleteButton",null),t([_()],Q.prototype,"hasPendingEdits",null),Q=t([W(x)],Q);const N=Q;export{N as default};
5
+ import{_ as t}from"../../chunks/tslib.es6.js";import{createTask as e}from"../../core/asyncUtils.js";import a from"../../core/Collection.js";import{deprecatedProperty as r,deprecated as i}from"../../core/deprecate.js";import s from"../../core/Error.js";import o from"../../core/Evented.js";import{makeHandle as n}from"../../core/handleUtils.js";import l from"../../core/Logger.js";import{abortMaybe as p,removeMaybe as d,destroyMaybe as c}from"../../core/maybe.js";import{throwIfAborted as u,createResolver as h}from"../../core/promiseUtils.js";import{watch as w,on as f,when as m,whenOnce as y,syncAndInitial as k,initial as g,sync as v}from"../../core/reactiveUtils.js";import{property as _}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as W}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as b}from"../../core/support/UpdatingHandles.js";import I from"../../layers/GraphicsLayer.js";import{isEditableLayer as F}from"../../layers/support/editableLayers.js";import{isFeatureLayer as E,getOwningPortalUrl as M}from"../../layers/support/layerUtils.js";import{parseKnownArcGISOnlineDomain as C}from"../../portal/support/urlUtils.js";import V from"../../views/interactive/sketch/SketchOptions.js";import{SnappingManager as O}from"../../views/interactive/snapping/SnappingManager.js";import U from"../../views/interactive/snapping/SnappingOptions.js";import T from"../Attachments/AttachmentsViewModel.js";import L from"./CreateFeaturesWorkflow.js";import A from"./UpdateWorkflow.js";import{whenEditorLayerView as j}from"./workflowUtils.js";import S from"./support/EditorItem.js";import P from"../FeatureTemplates/FeatureTemplatesViewModel.js";import R from"../Sketch/SketchViewModel.js";import H from"../Spinner/SpinnerViewModel.js";const x="esri.widgets.Editor.EditorViewModel",D=()=>l.getLogger(x),G=["create-features","update"];function q(t,e,a){D().error(new s(t,e,a))}function B(t,e){return t?.find((t=>t.layer===e))}let Q=class extends o.EventedAccessor{constructor(t){super(t),this._sketchEventListenerHandle=null,this._sketchGraphicsLayer=new I({listMode:"hide",internal:!0}),this._snappingManager=null,this._updateItemsTask=null,this._updatingHandles=new b,this._featureTemplatesViewModelLocked=!1,this.activeWorkflow=null,this._activityQueue=new a,this.editorItems=new a,this.failures=[],this.hideTemplatesForInactiveLayers=!1,this.attachmentsViewModel=new T({capabilities:{editing:!0}}),this.featureTemplatesViewModel=new P({disabledItemFunction:({layer:t})=>this._itemIsSuspended(t)}),this.ownSketchViewModel=new R({layer:this._sketchGraphicsLayer}),this.sketchOptions=new V,this.snappingOptions=new U,this.spinnerViewModel=new H,this.pageStack=[],this.showDiscardEditsPrompt=()=>Promise.resolve(!0),this._candidateCommitted=!1,this.back=async()=>{this.canGoBack&&(this.activeWorkflow?.hasPreviousStep?await this.activeWorkflow.back(this.showDiscardEditsPrompt):await this._cancelWorkflow({force:!this.hasPendingEdits}))},this.saveWorkflow=async()=>{const{featureFormViewModel:t}=this;if(t){if(t.submit(),!t.submittable)return;const e=t.getValues();if(t.validateContingencyConstraints(e,{includeIncompleteViolations:!0}).length>0)return}await(this.activeWorkflow?.save())},this.selectFeature=(t,e=!1)=>{const a=this.activeWorkflow;this._candidateCommitted||"update"!==a?.type||(a.data.rootFeature=t,e&&(a.next(),this._candidateCommitted=!0))}}initialize(){this.addHandles([w((()=>{const t=this.view,e=t?.map?.editableLayers,a=t?.allLayerViews,r=a?.filter((t=>!!e?.includes(t.layer)));return[e,r,this.layerInfos,this.allowedWorkflows]}),(()=>this._updateEditorItems()),k),w((()=>this.hideTemplatesForInactiveLayers),(()=>this.syncFeatureTemplates())),f((()=>this.activeWorkflow),"cancel",(()=>this.emit("workflow-cancel"))),f((()=>this.activeWorkflow),"commit",(()=>this.emit("workflow-commit"))),f((()=>this.activeWorkflow),"complete",(()=>{this.emit("workflow-commit"),this._set("activeWorkflow",null)})),m((()=>this.view?.map),(t=>t.add(this._sketchGraphicsLayer)),g),f((()=>this.editorItems),"change",(()=>this._afterEditorItemsChange())),w((()=>[this.canCreate,this.canUpdateVisible]),(()=>this._afterEditorItemsChange())),w((()=>this.page),((t,e)=>{const a=[...this.pageStack];if(-1===a.indexOf(t))a.push(t);else for(;a.length&&a.at(-1)!==t;)a.pop();this.pageStack=a}),k),m((()=>"awaiting-update-feature-candidate"===this.state),(()=>this._candidateCommitted=!1)),f((()=>this.featureTemplatesViewModel),"select",(async({item:t,oldItem:e})=>{const{activeWorkflow:a}=this;if(a){if("update"===a.type&&"awaiting-feature-creation-info"===a.activeWorkflow?.stepId)return;try{await this.cancelWorkflow({force:!this.hasPendingEdits})}catch{return void this.featureTemplatesViewModel.select(e,{emit:!1})}}if(!t)return;const r={layer:t.layer,template:t.template};if(t.supportsUpload)return this.featureTemplatesViewModel.select(e,{emit:!1}),this.startCreateFeaturesWorkflow(r);this.startCreateFeaturesWorkflowAtFeatureCreation(r)})),f((()=>this.view),"key-down",(t=>{"Escape"===t.key&&this.activeWorkflow?.keyboardCancellationEnabled&&(t.stopPropagation(),this.back())})),f((()=>this.sketchViewModel),["create","delete","update"],(t=>{const{activeWorkflow:e}=this,a="update"===e?.type,r=a?e.activeWorkflow?.layer:e?.layer,i=a?e?.activeWorkflow?.parentLayer:void 0,s=`sketch-${t.type}`;this.emit(s,{type:s,detail:t,layer:r,parentLayer:i})}),v),w((()=>this.view),(t=>{if(this._snappingManager=c(this._snappingManager),!t)return;const e=this.snappingOptions;this._snappingManager=new O({view:t,options:e})}),k),w((()=>this.snappingOptions),(t=>{this._snappingManager&&(this._snappingManager.options=t)}),k)])}destroy(){this._cancelWorkflow({warnIfNoWorkflow:!1}).then((()=>{this.view?.map?.remove(this._sketchGraphicsLayer),this.view=null})),this._updateItemsTask=p(this._updateItemsTask),this._updatingHandles.destroy(),this._sketchEventListenerHandle=d(this._sketchEventListenerHandle)}get allowedWorkflows(){return this._get("allowedWorkflows")}set allowedWorkflows(t){r(l.getLogger(this),"allowedWorkflows",{replacement:"Editor.visibleElements",version:"4.29",warnOnce:!0}),t&&0!==t.length||(t=[...G]),this._set("allowedWorkflows",t)}get canCreate(){return this.editorItems.some((t=>t.supportsCreateFeaturesWorkflow))}get canCreateVisible(){return!!this.featureTemplatesLayers.length}get canUpdate(){return this.editorItems.some((t=>t.supportsUpdateWorkflow))}get canUpdateVisible(){return this.editorItems.some((t=>t.supportsUpdateWorkflow&&t.visible))}get featureTemplatesLayers(){const t=new a;for(const e of this.editorItems){const a=e.supportsCreateFeaturesWorkflow&&!e.isTable,r=this.hideTemplatesForInactiveLayers&&!e.visible;a&&!r&&t.push(e.layer)}return t}get editableItems(){return r(l.getLogger(this),"editableItems",{replacement:"editorItems",version:"4.29",warnOnce:!0}),this.editorItems.map((t=>{const{capabilities:e,disabled:a,hasInvalidFormTemplate:r,layer:i}=t,s=[],o=e.create,n=e.update,l=e.delete;return o.enabled&&s.push("create"),n.enabled&&s.push("update"),l.enabled&&s.push("delete"),{layer:i,supports:s,suspended:a,attributeUpdatesEnabled:n.attributes,geometryUpdatesEnabled:n.geometry,attachmentsOnCreateEnabled:o.attachments.enabled,attachmentsOnUpdateEnabled:n.attachments.enabled,hasInvalidFormTemplate:r,hasAttachments:e.attachments.enabled}}))}get featureFormViewModel(){const{activeWorkflow:t}=this;return"update"===t?.type?t.activeFeatureFormViewModel:"create-features"===t?.type?t.featureFormViewModel:null}get labelOptions(){return this.sketchOptions.labels}set labelOptions(t){this.sketchOptions.labels=t}set layerInfos(t){const e=t?.some((t=>"allowAttachments"in t));e&&i(D(),"Property: layerInfo.allowAttachments",{replacement:"layerInfo.attachmentsOnCreateEnabled or layerInfo.attachmentsOnUpdateEnabled",version:"4.26"}),this._set("layerInfos",t)}get sketchViewModel(){const{activeWorkflow:t}=this;return"update"===t?.type?t.activeSketchViewModel:"create-features"===t?.type?t.sketchViewModel:this.ownSketchViewModel}get state(){if(!this.view?.ready)return"disabled";const t=this.attachmentsViewModel.mode;if("add"===t)return"adding-attachment";if("edit"===t)return"editing-attachment";const{activeWorkflow:e}=this;return e?.stepId?"update"===e.type&&e.activeWorkflow?.stepId?e.activeWorkflow.stepId:e.stepId:"ready"}get syncing(){return this._activityQueue.length>0}get updating(){return this._updatingHandles.updating||!0===this.activeWorkflow?.updating}get tooltipOptions(){return this.sketchOptions.tooltips}set tooltipOptions(t){this.sketchOptions.tooltips=t}get valueOptions(){return this.sketchOptions.values}set valueOptions(t){this.sketchOptions.values=t}set view(t){this.ownSketchViewModel.view=t,this.spinnerViewModel.view=t,this._set("view",t)}get page(){const{activeWorkflow:t,state:e}=this;if("update"===t?.type&&"awaiting-feature-to-update"===t.stepId)return"ready";if("create-features"===t?.type&&0===t.numPendingFeatures){const e=t.data.upload;if(e)return"default"===e.state?"ready":"creating-features-upload-details"}return e??"disabled"}get featureFormDisabled(){const{activeWorkflow:t}=this;return"update"===t?.type&&!1===t.activeEditorItem?.capabilities.update.attributes}get canGoBack(){return null!=this.activeWorkflow&&!this.syncing}get shouldShowDeleteButton(){const{activeWorkflow:t}=this;return!!t&&"update"===t.type&&!!t.activeEditorItem?.capabilities.delete.enabled}get hasPendingEdits(){return this.activeWorkflow?.hasPendingEdits??!1}async startCreateFeaturesWorkflowAtFeatureTypeSelection(){return this.startCreateFeaturesWorkflow()}async startCreateFeaturesWorkflowAtFeatureCreation(t){return this.startCreateFeaturesWorkflow(t,"creating-features")}async startCreateFeaturesWorkflow(t,e="awaiting-feature-creation-info"){if(await y((()=>!this.updating)),!this.canCreate)throw new s("editing:unsupported-workflow","Creating features is unsupported or disabled.");const a=this._createUpdatingResolver();await this._cancelWorkflow();const r=this._createCreateFeaturesWorkflow(t,e);this._set("activeWorkflow",r),await r.start(),a.resolve()}async startCreateFeaturesWorkflowAtFeatureEdit(t){await y((()=>!this.updating));const e=this._createUpdatingResolver(),{initialFeature:a}=t,r=a.sourceLayer=a.layer,i=r?this.findEditorItemForLayer(r):void 0;if(!i?.supportsCreateFeaturesWorkflow)throw new s("editing:unsupported-workflow","Creating features is unsupported or disabled for this layer.");await this._cancelWorkflow();const o=this._createCreateFeaturesWorkflow({initialFeature:a,layer:i.layer,maxFeatures:1},"creating-features");this._set("activeWorkflow",o),await o.start(),e.resolve()}async startUpdateWorkflowAtFeatureSelection(){if(await y((()=>!this.updating)),!this.canUpdate)return void q("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const t=this._createUpdatingResolver();await this._cancelWorkflow();const e=this._createUpdateWorkflow();this._set("activeWorkflow",e),await e.start(),t.resolve()}async startUpdateWorkflowAtMultipleFeatureSelection(t){if(await y((()=>!this.updating)),!this.canUpdate)return void q("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();await this._cancelWorkflow();const a=this._createUpdateWorkflow("awaiting-update-feature-candidate");a.data.candidates=t,this._set("activeWorkflow",a),await a.start(),e.resolve()}async startUpdateWorkflowAtFeatureEdit(t){if(await y((()=>!this.updating)),!this.canUpdate)return void q("editing:unsupported-workflow","Update workflow is unsupported or disabled.");const e=this._createUpdatingResolver();await this._cancelWorkflow();const a=this._createUpdateWorkflow("editing-existing-feature");a.data.rootFeature=t,this._set("activeWorkflow",a),await a.start(),e.resolve()}async deleteFeatureFromWorkflow(){const{activeWorkflow:t}=this;t&&"update"===t.type?await t.deleteActiveFeature():q("editing:unsupported-workflow","Deleting requires an active update workflow.")}async cancelWorkflow(t){return this._cancelWorkflow({warnIfNoWorkflow:!0,...t})}findEditorItemForLayer(t){return this.editorItems.find((e=>e.layer===t))}itemHasInvalidFormTemplate(t){return null!=t&&!0===this.findEditorItemForLayer(t.layer)?.hasInvalidFormTemplate}syncFeatureTemplates(){this._featureTemplatesViewModelLocked||(this.featureTemplatesViewModel.layers=this.featureTemplatesLayers.toArray())}async toggleUpdateWorkflow(){this.canUpdate&&(this.hasPendingEdits&&!await this.showDiscardEditsPrompt()||(this.activeWorkflow&&"awaiting-feature-to-update"===this.state?await this.cancelWorkflow({force:!0}):await this.startUpdateWorkflowAtFeatureSelection()))}lockFeatureTemplatesViewModel(){return this._featureTemplatesViewModelLocked=!0,n((()=>{this._featureTemplatesViewModelLocked=!1,this.syncFeatureTemplates()}))}async _getEditorItemCandidates(t){const{view:e}=this;if(!e?.map)return[];const{map:a}=e,r=a.editableLayers.toArray()??[],i=a.allTables.toArray().filter(E)??[];return await Promise.allSettled([...r.map((t=>"subtype-group"===t.type?t.loadAll():Promise.resolve())),...i.map((t=>t.load()))]),u(t),[...r.reverse(),...i.reverse()].filter((t=>F(t)&&("mesh"!==t.geometryType||"3d"===e.type))).flatMap((t=>"subtype-group"===t.type?t.sublayers.toArray():t))}_drainEditorItems(){this.editorItems.drain((t=>t.destroy()))}async _updateEditorItems(){p(this._updateItemsTask);const{view:t}=this,a=e((async e=>{if(!t?.map||!t?.allLayerViews)return;const a=await this._getEditorItemCandidates(e);if(!a.length)return void this._drainEditorItems();const r=[],i=[],s=[],{layerInfos:o}=this;for(const l of a){const e=B(o,l),a=await j(t,l).catch((()=>null));(e?r:a?i:s).push(new S({layer:l,layerInfo:e,layerView:a}))}o?.length&&r.sort(((t,e)=>o.findIndex((({layer:e})=>e===t.layer))-o.findIndex((({layer:t})=>t===e.layer))));const n=[...r,...i,...s];e.aborted||(this._drainEditorItems(),this.editorItems.addMany(n))}));this._updatingHandles.addPromise(a.promise),this._updateItemsTask=a}_afterEditorItemsChange(){const{activeWorkflow:t}=this;if(this.syncFeatureTemplates(),!t)return;const{stepId:e}=t;"create-features"!==t.type?"update"===t.type&&("awaiting-feature-to-update"===e&&!this.canUpdateVisible||"awaiting-update-feature-candidate"===e&&!t.hasUpdatableCandidates)&&this._cancelWorkflow():"awaiting-feature-creation-info"!==e||this.canCreate||this._cancelWorkflow()}async _cancelWorkflow(t){const e=this.activeWorkflow;if(!e)return void(t?.warnIfNoWorkflow&&q("editing:no-active-workflow","There is no active workflow to cancel."));if(!t||!1!==t.force)return this.emit("workflow-cancel"),this._set("activeWorkflow",null),void await e.cancel(t);await e.cancel(t),this._set("activeWorkflow",null)}_createCreateFeaturesWorkflow(t,e){return L.create({viewModel:this,creationInfo:t,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:e,applyEditsCallback:(t,e,a)=>this._applyEdits(t,e,a),addAttachmentsCallback:(t,e)=>this._addAttachments(t,e)})}_createUpdateWorkflow(t){return A.create({viewModel:this,sketchOptions:this.sketchOptions,snappingManager:this._snappingManager,startAt:t,applyEditsCallback:(t,e,a)=>this._applyEdits(t,e,a),addAttachmentsCallback:(t,e)=>this._addAttachments(t,e)})}_addAttachments(t,e){const a=e.map((e=>this._addAttachment(t,e.feature,e.attachment)))??[];return Promise.all(a)}async _addAttachment(t,e,a){let r=null;if(!("addAttachment"in t)||null==t.capabilities?.attachment)throw new s("editor:attachments-not-supported","Adding attachments is not supported for this layer type");return await this._queueOperation((async()=>(r=await(t.addAttachment?.(e,a).catch((t=>{throw t?.error||t})))??null,r))),r}async _applyEdits(t,e,a){let r=null;const i=t.url?await M(t.url):null,s={returnServiceEditsOption:(!i||!C(i))&&!RegExp("/hosted/","i").test(t.url)?"original-and-current-features":void 0,...a};return await this._queueOperation((async()=>{const{view:a}=this;if(!a)return null;const i=await j(a,t).catch((()=>null));return r=await t.applyEdits(e,s),i&&await y((()=>!i.updating)),r})),r}_queueOperation(t){this._activityQueue.push(t);const e=(t,e)=>{const a=e.indexOf(t);a>-1&&e.splice(a,1)};return t().then((t=>{if(null!=t&&"error"in t&&null!=t.error)throw t.error;if(null!=t&&"addFeatureResults"in t){const{addFeatureResults:e,deleteFeatureResults:a,updateFeatureResults:r}=t,i=e.find((t=>!!t.error))||r.find((t=>!!t.error))||a.find((t=>!!t.error));if(i)throw i.error}return t})).catch((a=>{q("editing:operation-error","An error occurred.",{error:a});const r={error:a,retry:()=>(e(r,this.failures),this._queueOperation(t)),cancel:()=>{e(r,this.failures)}};this._set("failures",[...this.failures,r])})).then((()=>{e(t,this._activityQueue)}))}_createUpdatingResolver(){const t=h();return this._updatingHandles.addPromise(t.promise),t}_itemIsSuspended(t){const e=this.findEditorItemForLayer(t);return null!=e&&(!e.visible||e.disabled)}};t([_({readOnly:!0})],Q.prototype,"activeWorkflow",void 0),t([_({readOnly:!0})],Q.prototype,"_activityQueue",void 0),t([_({value:[...G]})],Q.prototype,"allowedWorkflows",null),t([_({readOnly:!0})],Q.prototype,"canCreate",null),t([_()],Q.prototype,"canCreateVisible",null),t([_({readOnly:!0})],Q.prototype,"canUpdate",null),t([_()],Q.prototype,"canUpdateVisible",null),t([_()],Q.prototype,"featureTemplatesLayers",null),t([_()],Q.prototype,"editableItems",null),t([_()],Q.prototype,"editorItems",void 0),t([_({readOnly:!0})],Q.prototype,"failures",void 0),t([_()],Q.prototype,"hideTemplatesForInactiveLayers",void 0),t([_()],Q.prototype,"attachmentsViewModel",void 0),t([_()],Q.prototype,"featureFormViewModel",null),t([_()],Q.prototype,"featureTemplatesViewModel",void 0),t([_()],Q.prototype,"labelOptions",null),t([_()],Q.prototype,"layerInfos",null),t([_()],Q.prototype,"ownSketchViewModel",void 0),t([_()],Q.prototype,"sketchOptions",void 0),t([_()],Q.prototype,"sketchViewModel",null),t([_({type:U,nonNullable:!0})],Q.prototype,"snappingOptions",void 0),t([_()],Q.prototype,"spinnerViewModel",void 0),t([_()],Q.prototype,"state",null),t([_({readOnly:!0})],Q.prototype,"syncing",null),t([_()],Q.prototype,"updating",null),t([_()],Q.prototype,"tooltipOptions",null),t([_()],Q.prototype,"valueOptions",null),t([_()],Q.prototype,"view",null),t([_()],Q.prototype,"pageStack",void 0),t([_()],Q.prototype,"showDiscardEditsPrompt",void 0),t([_()],Q.prototype,"_candidateCommitted",void 0),t([_()],Q.prototype,"page",null),t([_()],Q.prototype,"featureFormDisabled",null),t([_()],Q.prototype,"canGoBack",null),t([_()],Q.prototype,"shouldShowDeleteButton",null),t([_()],Q.prototype,"hasPendingEdits",null),Q=t([W(x)],Q);const N=Q;export{N as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.29/esri/copyright.txt for details.
4
4
  */
5
- import{lerp as e}from"../../../core/mathUtils.js";import{throwIfAborted as t}from"../../../core/promiseUtils.js";import{getMetersPerUnitForSR as n}from"../../../core/unitUtils.js";import{distance as r,lerp as s}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{k as o}from"../../../chunks/vec32.js";import a from"../../../geometry/Polyline.js";import{initializeProjection as i,project as c}from"../../../geometry/projection.js";import u from"../../../geometry/SpatialReference.js";import{geodesicLengths as l,isSupported as f,inverseGeodeticSolver as h,directGeodeticSolver as p}from"../../../geometry/support/geodesicUtils.js";import{getElevationOffset as m}from"../../../support/elevationInfoUtils.js";import{ProfileGenerationError as d,ProfileGenerationErrorCause as g}from"./ProfileGenerationError.js";async function w(e,r,s,o,a,f,h){let p,m,w;const j=e.spatialReference,v=j.isGeographic||j.isWebMercator;let P=0;if(!v){const{planarLength:n}=await import("../../../geometry/geometryEngineAsync.js");t(h),P=await n(e,"meters"),t(h)}const Z=1/n(o),x=a.geodesicDistanceThreshold??1/0;if(v||P>=x){await i([{source:j,dest:o},{source:j,dest:u.WGS84}],h);const t=W(e);p=l([t],"meters")[0];const n=y(p,a);if(D(e,p,n)>f)throw new d(g.TooComplex);const v=R(t,r,s);({densifiedPath:m,distances:w}=b(v,n,Z)),m=c(m,o)}else{await i([{source:j,dest:o}],h),p=P;const n=y(p,a);if(D(e,p,n)>f)throw new d(g.TooComplex);const u=R(e,r,s);({densifiedPath:m,distances:w}=S(u,n,Z)),t(h),m=c(m,o)}return{densifiedPath:m,pathLength:p*Z,distances:w}}function y(e,t){const n=e/t.densificationMaxSamples;return Math.max(t.samplingDistance,n)}function R(e,t,n){if(null==t)return P(e);const r=e.spatialReference,s=t.mode,o=m(t,r);let i=null;switch(n.type){case"2d":i=j(e,s,o);break;case"3d":i=v(e,s,o,n)}return null==i?P(e):new a({hasZ:!0,hasM:!1,spatialReference:r,paths:Z(e.paths,i)})}function j({hasZ:e},t,n){return"absolute-height"===t?e?([e,t,r])=>[e,t,r+n]:([e,t])=>[e,t,n]:null}function v({spatialReference:e,hasZ:t},n,r,{elevationProvider:s}){const o=(t,n,r,o)=>s?.getElevation(t,n,r,e,o)??0;switch(n){case"on-the-ground":return([e,t])=>[e,t,o(e,t,0,"ground")];case"absolute-height":return t?([e,t,n])=>[e,t,n+r]:([e,t])=>[e,t,r];case"relative-to-ground":return t?([e,t,n])=>[e,t,n+o(e,t,n,"ground")+r]:([e,t])=>[e,t,o(e,t,0,"ground")+r];case"relative-to-scene":return t?([e,t,n])=>[e,t,n+o(e,t,n,"scene")+r]:([e,t])=>[e,t,o(e,t,0,"scene")+r];default:return null}}function P(e){return e.hasZ?new a({hasZ:!1,hasM:!1,spatialReference:e.spatialReference,paths:Z(e.paths,(([e,t])=>[e,t]))}):e}function Z(e,t){const n=e.length,r=new Array(n);for(let s=0;s<n;++s){const n=e[s],o=n.length,a=new Array(n.length);r[s]=a;for(let e=0;e<o;++e)a[e]=t(n[e])}return r}function x(e){return M(e)&&e.paths.length>0&&e.paths.every((e=>e.length>=2))}function M(e){return null!=e&&"polyline"===e.type}function A(e,t,r,s,o){const{spatialReference:i,hasZ:c}=e,u={from:null,to:null,distance:0,azimuth:0,reverseAzimuth:0,spatialReference:i,metersPerSR:n(i)},l=[],f=[];let h=0;for(let n=0;n<e.paths.length;++n){const a=e.paths[n],i=new Array,c=new Array;let p=0;for(let e=1;e<a.length;++e){const n=a[e-1],l=a[e],f=s(u,n,l);let m;for(m=p;m<f.distance;m+=t)i.push(o(f,m)),c.push((h+m)*r);p=m-f.distance,h+=f.distance,i.push(l),c.push(h*r)}l[n]=i,f[n]=c}return{densifiedPath:new a({spatialReference:i,hasZ:c,paths:l}),distances:f}}function S(e,t,n){const{hasZ:r}=e;return A(e,t,n,z,r?T:E)}function b(e,t,n){const{hasZ:r}=e;return A(e,t,n,U,r?k:G)}function U(e,t,n){return e.distance=0,h(e,t,n,e.spatialReference),e.from=t,e.to=n,e}function z(e,t,n){return e.from=t,e.to=n,e.distance=r(n,t)*e.metersPerSR,e}function G({from:e,azimuth:t,spatialReference:n},r){return p([0,0],e,t,r,n)}function k({from:t,to:n,azimuth:r,distance:s,spatialReference:o},a){const i=a/s,c=[0,0,e(t[2],n[2],i)];return p(c,t,r,a,o),c}function E({from:e,to:t,distance:n},r){return s([0,0],e,t,r/n)}function T({from:e,to:t,distance:n},r){return o([0,0,0],e,t,r/n)}function W(e){return f(e.spatialReference)?e:c(e,u.WGS84)}function C(e){return e.paths.reduce(((e,t)=>e+t.length),0)}function D(e,t,n){return C(e)+Math.floor(t/n)+Math.max(0,e.paths.reduce((e=>1+e),0)-1)}export{C as countPoints,w as densifyPath,M as isPolyline,x as isValidInputPath,R as toAbsoluteHeightElevation};
5
+ import{lerp as e}from"../../../core/mathUtils.js";import{throwIfAborted as t}from"../../../core/promiseUtils.js";import{getMetersPerUnitForSR as n}from"../../../core/unitUtils.js";import{distance as r,lerp as s}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{m as o}from"../../../chunks/vec32.js";import a from"../../../geometry/Polyline.js";import{initializeProjection as i,project as c}from"../../../geometry/projection.js";import u from"../../../geometry/SpatialReference.js";import{geodesicLengths as l,isSupported as f,inverseGeodeticSolver as h,directGeodeticSolver as p}from"../../../geometry/support/geodesicUtils.js";import{getElevationOffset as m}from"../../../support/elevationInfoUtils.js";import{ProfileGenerationError as d,ProfileGenerationErrorCause as g}from"./ProfileGenerationError.js";async function w(e,r,s,o,a,f,h){let p,m,w;const j=e.spatialReference,v=j.isGeographic||j.isWebMercator;let P=0;if(!v){const{planarLength:n}=await import("../../../geometry/geometryEngineAsync.js");t(h),P=await n(e,"meters"),t(h)}const Z=1/n(o),x=a.geodesicDistanceThreshold??1/0;if(v||P>=x){await i([{source:j,dest:o},{source:j,dest:u.WGS84}],h);const t=k(e);p=l([t],"meters")[0];const n=y(p,a);if(D(e,p,n)>f)throw new d(g.TooComplex);const v=R(t,r,s);({densifiedPath:m,distances:w}=b(v,n,Z)),m=c(m,o)}else{await i([{source:j,dest:o}],h),p=P;const n=y(p,a);if(D(e,p,n)>f)throw new d(g.TooComplex);const u=R(e,r,s);({densifiedPath:m,distances:w}=S(u,n,Z)),t(h),m=c(m,o)}return{densifiedPath:m,pathLength:p*Z,distances:w}}function y(e,t){const n=e/t.densificationMaxSamples;return Math.max(t.samplingDistance,n)}function R(e,t,n){if(null==t)return P(e);const r=e.spatialReference,s=t.mode,o=m(t,r);let i=null;switch(n.type){case"2d":i=j(e,s,o);break;case"3d":i=v(e,s,o,n)}return null==i?P(e):new a({hasZ:!0,hasM:!1,spatialReference:r,paths:Z(e.paths,i)})}function j({hasZ:e},t,n){return"absolute-height"===t?e?([e,t,r])=>[e,t,r+n]:([e,t])=>[e,t,n]:null}function v({spatialReference:e,hasZ:t},n,r,{elevationProvider:s}){const o=(t,n,r,o)=>s?.getElevation(t,n,r,e,o)??0;switch(n){case"on-the-ground":return([e,t])=>[e,t,o(e,t,0,"ground")];case"absolute-height":return t?([e,t,n])=>[e,t,n+r]:([e,t])=>[e,t,r];case"relative-to-ground":return t?([e,t,n])=>[e,t,n+o(e,t,n,"ground")+r]:([e,t])=>[e,t,o(e,t,0,"ground")+r];case"relative-to-scene":return t?([e,t,n])=>[e,t,n+o(e,t,n,"scene")+r]:([e,t])=>[e,t,o(e,t,0,"scene")+r];default:return null}}function P(e){return e.hasZ?new a({hasZ:!1,hasM:!1,spatialReference:e.spatialReference,paths:Z(e.paths,(([e,t])=>[e,t]))}):e}function Z(e,t){const n=e.length,r=new Array(n);for(let s=0;s<n;++s){const n=e[s],o=n.length,a=new Array(n.length);r[s]=a;for(let e=0;e<o;++e)a[e]=t(n[e])}return r}function x(e){return M(e)&&e.paths.length>0&&e.paths.every((e=>e.length>=2))}function M(e){return null!=e&&"polyline"===e.type}function A(e,t,r,s,o){const{spatialReference:i,hasZ:c}=e,u={from:null,to:null,distance:0,azimuth:0,reverseAzimuth:0,spatialReference:i,metersPerSR:n(i)},l=[],f=[];let h=0;for(let n=0;n<e.paths.length;++n){const a=e.paths[n],i=new Array,c=new Array;let p=0;for(let e=1;e<a.length;++e){const n=a[e-1],l=a[e],f=s(u,n,l);let m;for(m=p;m<f.distance;m+=t)i.push(o(f,m)),c.push((h+m)*r);p=m-f.distance,h+=f.distance,i.push(l),c.push(h*r)}l[n]=i,f[n]=c}return{densifiedPath:new a({spatialReference:i,hasZ:c,paths:l}),distances:f}}function S(e,t,n){const{hasZ:r}=e;return A(e,t,n,z,r?W:T)}function b(e,t,n){const{hasZ:r}=e;return A(e,t,n,U,r?E:G)}function U(e,t,n){return e.distance=0,h(e,t,n,e.spatialReference),e.from=t,e.to=n,e}function z(e,t,n){return e.from=t,e.to=n,e.distance=r(n,t)*e.metersPerSR,e}function G({from:e,azimuth:t,spatialReference:n},r){return p([0,0],e,t,r,n)}function E({from:t,to:n,azimuth:r,distance:s,spatialReference:o},a){const i=a/s,c=[0,0,e(t[2],n[2],i)];return p(c,t,r,a,o),c}function T({from:e,to:t,distance:n},r){return s([0,0],e,t,r/n)}function W({from:e,to:t,distance:n},r){return o([0,0,0],e,t,r/n)}function k(e){return f(e.spatialReference)?e:c(e,u.WGS84)}function C(e){return e.paths.reduce(((e,t)=>e+t.length),0)}function D(e,t,n){return C(e)+Math.floor(t/n)+Math.max(0,e.paths.reduce((e=>1+e),0)-1)}export{C as countPoints,w as densifyPath,M as isPolyline,x as isValidInputPath,R as toAbsoluteHeightElevation};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.29/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import"../../intl.js";import i from"../../core/Collection.js";import s from"../../core/Handles.js";import{debounce as r,ignoreAbortErrors as o}from"../../core/promiseUtils.js";import{on as l,watch as n}from"../../core/reactiveUtils.js";import{property as a}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as h}from"../../core/accessorSupport/decorators/subclass.js";import{getLowerCaseDefaultHiddenFields as d}from"../../layers/support/fieldUtils.js";import{getTimeZoneFormattingOptions as m,system as g}from"../../time/timeZoneUtils.js";import{highlightsSupported as c}from"../../views/support/layerViewUtils.js";import p from"./AttachmentsColumn.js";import u from"./FieldColumn.js";import y from"./Grid/Column.js";import f from"./Grid/Grid.js";import b from"./Grid/GridViewModel.js";import _ from"./Grid/GroupColumn.js";import w from"./support/FeatureStore.js";import"../support/widgetUtils.js";import{messageBundle as v}from"../support/decorators/messageBundle.js";import{onLocaleChange as I}from"../../intl/locale.js";import{convertDateFormatToIntlOptions as F}from"../../intl/date.js";import{fetchMessageBundle as E}from"../../intl/messages.js";let C=class extends b{constructor(e){super(e),this._debounceRefresh=r((()=>this._refresh())),this._highlights=new s,this.activeFilters=new i,this.attachmentsEnabled=!1,this.autoRefreshEnabled=!0,this.cellClassNameGenerator=(e,t)=>e.path||"",this.columns=new i,this.dataProvider=async(e,t)=>{const{store:i}=this,s=this._sortOrdersToLayerOrderByFields(e.sortOrders);t&&(i?(i.set({orderByFields:s}),"loaded"!==i.state&&"loading"!==i.state&&await i.load(),t&&t(await i.fetchItems(e))):t&&t([]))},this.editingEnabled=!1,this.grid=null,this.highlightEnabled=!0,this.itemIdPath="objectId",this.layer=null,this.messagesCommon=null,this.messagesURIUtils=null,this.relatedRecordsEnabled=!1,this.returnGeometryEnabled=!1,this.store=null,this.tableTemplate=null,this.timeZone=null,this.view=null,this._onLayerRefresh=this._onLayerRefresh.bind(this),this._set("store",new w),this._set("grid",new f({itemIdPath:this.itemIdPath,viewModel:this}))}initialize(){const e=async()=>{this.messages=await E("esri/widgets/FeatureTable/t9n/FeatureTable"),this.messagesCommon=await E("esri/t9n/common"),this.messagesURIUtils=await E("esri/widgets/support/t9n/uriUtils")};e(),this.addHandles([I((()=>{e(),this._generateColumns()})),l((()=>this.highlightIds),"change",(e=>this._onHighlightIdsChange(e)),{onListenerAdd:()=>{this.highlightIds.forEach((e=>this._highlight(e)))},onListenerRemove:()=>{this.highlightIds.forEach((e=>this._removeHighlight(e)))}}),n((()=>this.attachmentsEnabled),(e=>{this.store.attachmentsEnabled=e,this.layer?.loaded&&this._generateColumns()})),n((()=>this.layerView),(e=>{this._highlights.removeAll(),e&&this.highlightEnabled&&this.highlightIds?.forEach((e=>this._highlight(e)))})),n((()=>this.highlightEnabled),(e=>{this._highlights.removeAll(),e&&this.highlightIds?.forEach((e=>this._highlight(e)))})),n((()=>this.relatedRecordsEnabled),(e=>this.store.relatedRecordsEnabled=e)),n((()=>this.returnGeometryEnabled),(e=>this.store.returnGeometry=e)),n((()=>this.layer),(async(e,t)=>{const i=this.grid;i&&(i.clearSort(),e&&t&&await i.reset()),this._drainColumns(),e&&(this.store.layer=e,e.loaded?this._onLayerLoad():e.load().catch((()=>{})))})),n((()=>this.layer?.loaded),(e=>e&&this._onLayerLoad())),n((()=>this.store.state),(e=>{"loaded"===e&&this.grid?.scrollToTop()})),n((()=>[this.messages,this.tableTemplate]),(()=>this.layer?.loaded&&this._generateColumns())),n((()=>[this.timeZone,this.view?.timeZone]),(()=>{this.columns.forEach((e=>{if("field"in e&&e.field){const{timeZone:t,timeZoneName:i}=this._getTimeZoneInfoForFieldColumn(e.field);e.set({timeZone:t,timeZoneName:i})}})),this.grid?.onColumnChange()})),n((()=>this.editingEnabled),(e=>{this.columns.forEach((t=>{"editingEnabled"in t&&(t.editingEnabled=e)})),this.grid?.onColumnChange()})),n((()=>this.layer?.definitionExpression),((e,t)=>(e||t)&&"loaded"===this.store.state&&this.reset())),n((()=>this.layer&&"timeExtent"in this.layer&&this.layer.timeExtent),((e,t)=>(e||t)&&!this.timeExtent&&"loaded"===this.store.state&&this.reset())),l((()=>this.layer),"refresh",(e=>this._onLayerRefresh(e)))])}destroy(){this._drainColumns(),this._highlights.removeAll(),this._highlights.destroy(),this.grid?.destroy(),this.columns.destroyed||this.columns.destroy(),this.layer=null,this.view=null}get _defaultHiddenFields(){return d(this.layer)}get activeSortOrders(){return this.grid?.sortOrders?this.grid.sortOrders.map((({path:e,direction:t})=>({fieldName:e,direction:t}))).filter((e=>e.fieldName&&e.direction)):[]}set filterGeometry(e){if(!this.filterGeometry&&!e)return;const t=this.activeFilters.find((e=>"geometry"===e.type));t&&this.activeFilters.remove(t),this._set("filterGeometry",e),this.store.filterGeometry=e,e&&this.activeFilters.add({type:"geometry",geometry:e})}get hiddenFields(){return this._get("hiddenFields")??new i}set hiddenFields(e){Array.isArray(e)?this._set("hiddenFields",new i(e)):this._set("hiddenFields",e)}get highlightOnRowSelectEnabled(){return this.highlightEnabled}set highlightOnRowSelectEnabled(e){this.highlightEnabled=e}get layerView(){return this.view?.allLayerViews.find((e=>e.layer===this.layer))||null}set messages(e){this.grid?.set("messages",e),this._set("messages",e)}get state(){const{store:e}=this;return e&&"disabled"!==e.state?"loading"===e.state?"loading":"loaded"===e.state?"loaded":"ready":"disabled"}set timeExtent(e){this._set("timeExtent",e),this.store.timeExtent=e}clearSelection(){this.grid?.clearSelection()}async deleteSelection(){const e=this.highlightIds.toArray();if(!e?.length)return;const{deleteFeatureResults:t}=await this.store.deleteRowsByObjectId(e),i=t.filter((e=>!e.error)).map((e=>e.objectId));i.length&&(this.deselectRows(i),await this.refresh())}deselectRows(e){const t=this._getStoreItemsFromSelectionParams(e);this.grid?.deselectRows(t)}filterBySelection(){const e=this.highlightIds.toArray();e.length&&(this.clearSelectionFilter(),this.store.objectIds=e,this.activeFilters.add({type:"selection",objectIds:e}))}getObjectIdIndex(e){return this.store?.getObjectIdIndex(e)}getValue(e,t){const i=this.store.getItemByObjectId(e);return i?.feature?.attributes[t]}get highlightIds(){return this._get("highlightIds")||new i}set highlightIds(e){Array.isArray(e)?this._set("highlightIds",new i(e)):this._set("highlightIds",e)}async refresh(){return o(this._debounceRefresh())}reset(){this.grid?.reset()}selectRows(e){const t=this._getStoreItemsFromSelectionParams(e);return this.grid?.selectRows(t)}scrollToIndex(e){this.grid?.scrollToIndex(e)}clearSelectionFilter(){this.store.objectIds=null;const e=this.activeFilters.find((e=>"selection"===e.type));e&&this.activeFilters.remove(e)}async zoomToSelection(){const{layer:e,view:t}=this,i=this.highlightIds.toArray();if(!e||!t||!i.length)return;const s=e.createQuery();s.objectIds=i,s.returnGeometry=!0;const r=await e.queryFeatures(s);try{await t.goTo(r.features)}catch(o){"AbortError"!==o.name&&console.error(o)}}async _refresh(){await this.store.refreshLayerInfo();const e=this.highlightIds.toArray();if(e.length){(await this.store.verifyFeaturesByObjectId(e)).forEach(((t,i)=>{t||this.deselectRows(e[i])}))}this.grid?.refreshPageCache()}_onLayerLoad(){const e=this.layer.capabilities?.query.maxRecordCount;e&&e<this.pageSize&&this.grid&&(this.grid.pageSize=e),this._generateColumns()}_onLayerRefresh(e){this.autoRefreshEnabled&&e.dataChanged&&this.refresh()}_generateColumns(){this._drainColumns();const e=[],t=this.tableTemplate?.columnTemplates?this._generateColumnsFromTemplates(this.tableTemplate.columnTemplates):this._generateDefaultFieldColumns();e.push(...t),e.length&&this.attachmentsEnabled&&e.push(this._generateAttachmentsColumn()),this.columns.addMany([...e])}_generateColumnsFromTemplates(e){const{editingEnabled:t,grid:i,layer:s,messages:r,messagesCommon:o,messagesURIUtils:l,store:n,tableTemplate:a}=this,h=s?.fields??[],d=e=>{const t="fieldName"in e&&e.fieldName?.toLowerCase();return h.find((e=>t===e.name?.toLowerCase()))};return e.map((e=>({template:e,field:d(e)}))).filter((({template:e,field:t})=>null!=t||"group"===e.type&&"columnTemplates"in e||"column"===e.type)).map((({template:e,field:h})=>{if("fieldName"in e){const d=!1===e.visible||!0!==e.visible&&this._isFieldHidden(h?.name),{direction:m,formatFunction:g,initialSortPriority:c,invalid:p,menuConfig:y,sortable:f,textAlign:b}=e,_=a?.expressionInfos||null,{timeZone:w,timeZoneName:v}=this._getTimeZoneInfoForFieldColumn(h);return new u({sortable:!1!==f,direction:m,editingEnabled:t,expressionInfos:_,field:h,formatFunction:g,grid:i,hidden:d,initialSortPriority:c,invalid:p,layer:s,messages:r,messagesCommon:o,messagesURIUtils:l,menuConfig:y,store:n,template:e,textAlign:b,timeZone:w,timeZoneName:v})}if("group"===e.type&&"columnTemplates"in e){const t=this._generateColumnsFromTemplates(e.columnTemplates),i=!1===e.visible||!0!==e.visible&&this._isFieldHidden(e.label),{label:s}=e;return new _({header:s,columns:t,hidden:i})}return new y({...e,timeZone:this.timeZone})}))}_generateDefaultFieldColumns(){const{editingEnabled:e,grid:t,layer:i,messages:s,messagesCommon:r,messagesURIUtils:o,store:l}=this;return(this.layer?.fields??[]).map((n=>{const{timeZone:a,timeZoneName:h}=this._getTimeZoneInfoForFieldColumn(n);return new u({editingEnabled:e,field:n,grid:t,hidden:this._isFieldHidden(n.name),layer:i,store:l,messages:s,messagesCommon:r,messagesURIUtils:o,timeZone:a,timeZoneName:h})}))}_getTimeZoneInfoForFieldColumn(e){const{timeZone:t,view:i}=this;return!e||"date"!==e?.type&&"timestamp-offset"!==e?.type?{timeZone:void 0,timeZoneName:void 0}:m("preferredTimeZone"in this.layer?this.layer.preferredTimeZone:null,"datesInUnknownTimezone"in this.layer&&this.layer.datesInUnknownTimezone,t??i?.timeZone??g,F("short-time"),e.type)}_generateAttachmentsColumn(){return new p({header:this.messages?.attachments??"Attachments"})}_sortOrdersToLayerOrderByFields(e){return e?.length?e.filter(((e,t,i)=>i.map((e=>e.path)).indexOf(e.path)===t)).filter((({direction:e})=>!!e)).map((({direction:e,path:t})=>t+" "+e?.toUpperCase())):[]}_isFieldHidden(e){const t=e?.toLowerCase();return(this.hiddenFields??this._defaultHiddenFields).some((e=>e.toLowerCase()===t))}_highlight(e){this.layerView&&c(this.layerView)&&this._highlights.add(this.layerView.highlight(e),e)}_removeHighlight(e){this._highlights.remove(e)}_getStoreItemsFromSelectionParams(e){const i=[];return this.layer?((e=e instanceof Array?e:[e]).forEach((e=>{let s=e instanceof t?e:null;const r=s?s.getObjectId():e;if("number"==typeof r||"string"==typeof r){if(!s){const e=this.store.getItemByObjectId(r);e&&(s=e.feature)}i.push({objectId:r,feature:s})}})),i):[]}_onHighlightIdsChange(e){const{highlightEnabled:t}=this,{added:i,removed:s}=e;t&&(i.forEach((e=>this._highlight(e))),s.forEach((e=>this._removeHighlight(e)))),this.emit("selection-change",{added:i,removed:s})}_drainColumns(){this.columns.drain((e=>!e.destroyed&&e.destroy()))}};e([a()],C.prototype,"_defaultHiddenFields",null),e([a({readOnly:!0})],C.prototype,"activeFilters",void 0),e([a({readOnly:!0})],C.prototype,"activeSortOrders",null),e([a()],C.prototype,"attachmentsEnabled",void 0),e([a()],C.prototype,"autoRefreshEnabled",void 0),e([a()],C.prototype,"cellClassNameGenerator",void 0),e([a({readOnly:!0})],C.prototype,"columns",void 0),e([a()],C.prototype,"dataProvider",void 0),e([a()],C.prototype,"editingEnabled",void 0),e([a()],C.prototype,"filterGeometry",null),e([a({readOnly:!0})],C.prototype,"grid",void 0),e([a()],C.prototype,"hiddenFields",null),e([a()],C.prototype,"highlightEnabled",void 0),e([a()],C.prototype,"highlightOnRowSelectEnabled",null),e([a({readOnly:!0})],C.prototype,"itemIdPath",void 0),e([a()],C.prototype,"layer",void 0),e([a()],C.prototype,"layerView",null),e([a()],C.prototype,"messages",null),e([a(),v("esri/t9n/common")],C.prototype,"messagesCommon",void 0),e([a(),v("esri/widgets/support/t9n/uriUtils")],C.prototype,"messagesURIUtils",void 0),e([a()],C.prototype,"relatedRecordsEnabled",void 0),e([a()],C.prototype,"returnGeometryEnabled",void 0),e([a({readOnly:!0})],C.prototype,"state",null),e([a({readOnly:!0,type:w})],C.prototype,"store",void 0),e([a()],C.prototype,"tableTemplate",void 0),e([a()],C.prototype,"timeExtent",null),e([a()],C.prototype,"timeZone",void 0),e([a()],C.prototype,"view",void 0),e([a()],C.prototype,"highlightIds",null),C=e([h("esri.widgets.FeatureTable.FeatureTableViewModel")],C);const j=C;export{j as default};
5
+ import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import"../../intl.js";import i from"../../core/Collection.js";import s from"../../core/Handles.js";import{debounce as r,ignoreAbortErrors as o}from"../../core/promiseUtils.js";import{on as l,watch as n}from"../../core/reactiveUtils.js";import{property as a}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as h}from"../../core/accessorSupport/decorators/subclass.js";import{getLowerCaseDefaultHiddenFields as d}from"../../layers/support/fieldUtils.js";import{getTimeZoneFormattingOptions as m,system as g}from"../../time/timeZoneUtils.js";import{highlightsSupported as c}from"../../views/support/layerViewUtils.js";import p from"./AttachmentsColumn.js";import u from"./FieldColumn.js";import y from"./Grid/Column.js";import f from"./Grid/Grid.js";import b from"./Grid/GridViewModel.js";import _ from"./Grid/GroupColumn.js";import w from"./support/FeatureStore.js";import"../support/widgetUtils.js";import{messageBundle as v}from"../support/decorators/messageBundle.js";import{onLocaleChange as I}from"../../intl/locale.js";import{convertDateFormatToIntlOptions as E}from"../../intl/date.js";import{fetchMessageBundle as F}from"../../intl/messages.js";let C=class extends b{constructor(e){super(e),this._debounceRefresh=r((()=>this._refresh())),this._highlights=new s,this.activeFilters=new i,this.attachmentsEnabled=!1,this.autoRefreshEnabled=!0,this.cellClassNameGenerator=(e,t)=>e.path||"",this.columns=new i,this.dataProvider=async(e,t)=>{const{store:i}=this,s=this._sortOrdersToLayerOrderByFields(e.sortOrders);t&&(i?(i.set({orderByFields:s}),"loaded"!==i.state&&"loading"!==i.state&&await i.load(),t&&t(await i.fetchItems(e))):t&&t([]))},this.editingEnabled=!1,this.grid=null,this.highlightEnabled=!0,this.itemIdPath="objectId",this.layer=null,this.messagesCommon=null,this.messagesURIUtils=null,this.relatedRecordsEnabled=!1,this.returnGeometryEnabled=!1,this.store=null,this.tableTemplate=null,this.timeZone=null,this.view=null,this._onLayerRefresh=this._onLayerRefresh.bind(this),this._set("store",new w),this._set("grid",new f({itemIdPath:this.itemIdPath,viewModel:this}))}initialize(){const e=async()=>{this.messages=await F("esri/widgets/FeatureTable/t9n/FeatureTable"),this.messagesCommon=await F("esri/t9n/common"),this.messagesURIUtils=await F("esri/widgets/support/t9n/uriUtils")};e(),this.addHandles([I((()=>{e(),this._generateColumns()})),l((()=>this.highlightIds),"change",(e=>this._onHighlightIdsChange(e)),{onListenerAdd:()=>{this.highlightIds.forEach((e=>this._highlight(e)))},onListenerRemove:()=>{this.highlightIds.forEach((e=>this._removeHighlight(e)))}}),n((()=>this.attachmentsEnabled),(e=>{this.store.attachmentsEnabled=e,this.layer?.loaded&&this._generateColumns()})),n((()=>this.layerView),(e=>{this._highlights.removeAll(),e&&this.highlightEnabled&&this.highlightIds?.forEach((e=>this._highlight(e)))})),n((()=>this.highlightEnabled),(e=>{this._highlights.removeAll(),e&&this.highlightIds?.forEach((e=>this._highlight(e)))})),n((()=>this.relatedRecordsEnabled),(e=>this.store.relatedRecordsEnabled=e)),n((()=>this.returnGeometryEnabled),(e=>this.store.returnGeometry=e)),n((()=>this.layer),(async(e,t)=>{const i=this.grid;i&&(i.clearSort(),e&&t&&await i.reset()),this._drainColumns(),e&&(this.store.layer=e,e.loaded?this._onLayerLoad():e.load().catch((()=>{})))})),n((()=>this.layer?.loaded),(e=>e&&this._onLayerLoad())),n((()=>this.store.state),(e=>{"loaded"===e&&this.grid?.scrollToTop()})),n((()=>[this.messages,this.tableTemplate]),(()=>this.layer?.loaded&&this._generateColumns())),n((()=>[this.timeZone,this.view?.timeZone]),(()=>{this.columns.forEach((e=>{if("field"in e&&e.field){const{timeZone:t,timeZoneName:i}=this._getTimeZoneInfoForFieldColumn(e.field);e.set({timeZone:t,timeZoneName:i})}})),this.grid?.onColumnChange()})),n((()=>this.editingEnabled),(e=>{this.columns.forEach((t=>{"editingEnabled"in t&&(t.editingEnabled=e)})),this.grid?.onColumnChange()})),n((()=>this.layer?.definitionExpression),((e,t)=>(e||t)&&"loaded"===this.store.state&&this.reset())),n((()=>this.layer&&"timeExtent"in this.layer&&this.layer.timeExtent),((e,t)=>(e||t)&&!this.timeExtent&&"loaded"===this.store.state&&this.reset())),l((()=>this.layer),"refresh",(e=>this._onLayerRefresh(e)))])}destroy(){this._drainColumns(),this._highlights.removeAll(),this._highlights.destroy(),this.grid?.destroy(),this.columns.destroyed||this.columns.destroy(),this.layer=null,this.view=null}get _defaultHiddenFields(){return d(this.layer)}get activeSortOrders(){return this.grid?.sortOrders?this.grid.sortOrders.map((({path:e,direction:t})=>({fieldName:e,direction:t}))).filter((e=>e.fieldName&&e.direction)):[]}set filterGeometry(e){if(!this.filterGeometry&&!e)return;const t=this.activeFilters.find((e=>"geometry"===e.type));t&&this.activeFilters.remove(t),this._set("filterGeometry",e),this.store.filterGeometry=e,e&&this.activeFilters.add({type:"geometry",geometry:e})}get hiddenFields(){return this._get("hiddenFields")??new i}set hiddenFields(e){Array.isArray(e)?this._set("hiddenFields",new i(e)):this._set("hiddenFields",e)}get highlightOnRowSelectEnabled(){return this.highlightEnabled}set highlightOnRowSelectEnabled(e){this.highlightEnabled=e}get layerView(){return this.view?.allLayerViews.find((e=>e.layer===this.layer))||null}set messages(e){this.grid?.set("messages",e),this._set("messages",e)}get state(){const{store:e}=this;return e&&"disabled"!==e.state?"loading"===e.state?"loading":"loaded"===e.state?"loaded":"ready":"disabled"}set timeExtent(e){this._set("timeExtent",e),this.store.timeExtent=e}clearSelection(){this.grid?.clearSelection()}async deleteSelection(){const e=this.highlightIds.toArray();if(!e?.length)return;const{deleteFeatureResults:t}=await this.store.deleteRowsByObjectId(e),i=t.filter((e=>!e.error)).map((e=>e.objectId));i.length&&(this.deselectRows(i),await this.refresh())}deselectRows(e){const t=this._getStoreItemsFromSelectionParams(e);this.grid?.deselectRows(t)}filterBySelection(){const e=this.highlightIds.toArray();e.length&&(this.clearSelectionFilter(),this.store.objectIds=e,this.activeFilters.add({type:"selection",objectIds:e}))}getObjectIdIndex(e){return this.store?.getObjectIdIndex(e)}getValue(e,t){const i=this.store.getItemByObjectId(e);return i?.feature?.attributes[t]}get highlightIds(){return this._get("highlightIds")||new i}set highlightIds(e){Array.isArray(e)?this._set("highlightIds",new i(e)):this._set("highlightIds",e)}async refresh(){return o(this._debounceRefresh())}reset(){this.grid?.reset()}selectRows(e){const t=this._getStoreItemsFromSelectionParams(e);return this.grid?.selectRows(t)}scrollToIndex(e){this.grid?.scrollToIndex(e)}clearSelectionFilter(){this.store.objectIds=null;const e=this.activeFilters.find((e=>"selection"===e.type));e&&this.activeFilters.remove(e)}async zoomToSelection(){const{layer:e,view:t}=this,i=this.highlightIds.toArray();if(!e||!t||!i.length)return;const s=e.createQuery();s.objectIds=i,s.returnGeometry=!0;const r=await e.queryFeatures(s);try{await t.goTo(r.features)}catch(o){"AbortError"!==o.name&&console.error(o)}}async _refresh(){await this.store.refreshLayerInfo();const e=this.highlightIds.toArray();if(e.length){(await this.store.verifyFeaturesByObjectId(e)).forEach(((t,i)=>{t||this.deselectRows(e[i])}))}this.grid?.refreshPageCache()}_onLayerLoad(){const e=this.layer.capabilities?.query.maxRecordCount;e&&e<this.pageSize&&this.grid&&(this.grid.pageSize=e),this._generateColumns()}_onLayerRefresh(e){this.autoRefreshEnabled&&e.dataChanged&&this.refresh()}_generateColumns(){this._drainColumns();const e=[],t=this.tableTemplate?.columnTemplates?this._generateColumnsFromTemplates(this.tableTemplate.columnTemplates):this._generateDefaultFieldColumns();e.push(...t),e.length&&this.attachmentsEnabled&&e.push(this._generateAttachmentsColumn()),this.columns.addMany([...e])}_generateColumnsFromTemplates(e){const{editingEnabled:t,grid:i,layer:s,messages:r,messagesCommon:o,messagesURIUtils:l,store:n,tableTemplate:a}=this,h=s?.fields??[],d=e=>{const t="fieldName"in e&&e.fieldName?.toLowerCase();return h.find((e=>t===e.name?.toLowerCase()))};return e.map((e=>({template:e,field:d(e)}))).filter((({template:e,field:t})=>null!=t||"group"===e.type&&"columnTemplates"in e||"column"===e.type)).map((({template:e,field:h})=>{if("fieldName"in e){const d=!1===e.visible||!0!==e.visible&&this._isFieldHidden(h?.name),{direction:m,formatFunction:g,frozen:c,frozenToEnd:p,initialSortPriority:y,invalid:f,menuConfig:b,sortable:_,textAlign:w}=e,v=a?.expressionInfos||null,{timeZone:I,timeZoneName:E}=this._getTimeZoneInfoForFieldColumn(h);return new u({sortable:!1!==_,direction:m,editingEnabled:t,expressionInfos:v,field:h,formatFunction:g,frozen:c,frozenToEnd:p,grid:i,hidden:d,initialSortPriority:y,invalid:f,layer:s,messages:r,messagesCommon:o,messagesURIUtils:l,menuConfig:b,store:n,template:e,textAlign:w,timeZone:I,timeZoneName:E})}if("group"===e.type&&"columnTemplates"in e){const t=this._generateColumnsFromTemplates(e.columnTemplates),i=!1===e.visible||!0!==e.visible&&this._isFieldHidden(e.label),{label:s}=e;return new _({header:s,columns:t,hidden:i})}return new y({...e,timeZone:this.timeZone})}))}_generateDefaultFieldColumns(){const{editingEnabled:e,grid:t,layer:i,messages:s,messagesCommon:r,messagesURIUtils:o,store:l}=this;return(this.layer?.fields??[]).map((n=>{const{timeZone:a,timeZoneName:h}=this._getTimeZoneInfoForFieldColumn(n);return new u({editingEnabled:e,field:n,grid:t,hidden:this._isFieldHidden(n.name),layer:i,store:l,messages:s,messagesCommon:r,messagesURIUtils:o,timeZone:a,timeZoneName:h})}))}_getTimeZoneInfoForFieldColumn(e){const{timeZone:t,view:i}=this;return!e||"date"!==e?.type&&"timestamp-offset"!==e?.type?{timeZone:void 0,timeZoneName:void 0}:m("preferredTimeZone"in this.layer?this.layer.preferredTimeZone:null,"datesInUnknownTimezone"in this.layer&&this.layer.datesInUnknownTimezone,t??i?.timeZone??g,E("short-time"),e.type)}_generateAttachmentsColumn(){return new p({header:this.messages?.attachments??"Attachments"})}_sortOrdersToLayerOrderByFields(e){return e?.length?e.filter(((e,t,i)=>i.map((e=>e.path)).indexOf(e.path)===t)).filter((({direction:e})=>!!e)).map((({direction:e,path:t})=>t+" "+e?.toUpperCase())):[]}_isFieldHidden(e){const t=e?.toLowerCase();return(this.hiddenFields??this._defaultHiddenFields).some((e=>e.toLowerCase()===t))}_highlight(e){this.layerView&&c(this.layerView)&&this._highlights.add(this.layerView.highlight(e),e)}_removeHighlight(e){this._highlights.remove(e)}_getStoreItemsFromSelectionParams(e){const i=[];return this.layer?((e=e instanceof Array?e:[e]).forEach((e=>{let s=e instanceof t?e:null;const r=s?s.getObjectId():e;if("number"==typeof r||"string"==typeof r){if(!s){const e=this.store.getItemByObjectId(r);e&&(s=e.feature)}i.push({objectId:r,feature:s})}})),i):[]}_onHighlightIdsChange(e){const{highlightEnabled:t}=this,{added:i,removed:s}=e;t&&(i.forEach((e=>this._highlight(e))),s.forEach((e=>this._removeHighlight(e)))),this.emit("selection-change",{added:i,removed:s})}_drainColumns(){this.columns.drain((e=>!e.destroyed&&e.destroy()))}};e([a()],C.prototype,"_defaultHiddenFields",null),e([a({readOnly:!0})],C.prototype,"activeFilters",void 0),e([a({readOnly:!0})],C.prototype,"activeSortOrders",null),e([a()],C.prototype,"attachmentsEnabled",void 0),e([a()],C.prototype,"autoRefreshEnabled",void 0),e([a()],C.prototype,"cellClassNameGenerator",void 0),e([a({readOnly:!0})],C.prototype,"columns",void 0),e([a()],C.prototype,"dataProvider",void 0),e([a()],C.prototype,"editingEnabled",void 0),e([a()],C.prototype,"filterGeometry",null),e([a({readOnly:!0})],C.prototype,"grid",void 0),e([a()],C.prototype,"hiddenFields",null),e([a()],C.prototype,"highlightEnabled",void 0),e([a()],C.prototype,"highlightOnRowSelectEnabled",null),e([a({readOnly:!0})],C.prototype,"itemIdPath",void 0),e([a()],C.prototype,"layer",void 0),e([a()],C.prototype,"layerView",null),e([a()],C.prototype,"messages",null),e([a(),v("esri/t9n/common")],C.prototype,"messagesCommon",void 0),e([a(),v("esri/widgets/support/t9n/uriUtils")],C.prototype,"messagesURIUtils",void 0),e([a()],C.prototype,"relatedRecordsEnabled",void 0),e([a()],C.prototype,"returnGeometryEnabled",void 0),e([a({readOnly:!0})],C.prototype,"state",null),e([a({readOnly:!0,type:w})],C.prototype,"store",void 0),e([a()],C.prototype,"tableTemplate",void 0),e([a()],C.prototype,"timeExtent",null),e([a()],C.prototype,"timeZone",void 0),e([a()],C.prototype,"view",void 0),e([a()],C.prototype,"highlightIds",null),C=e([h("esri.widgets.FeatureTable.FeatureTableViewModel")],C);const j=C;export{j as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.29/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../chunks/tslib.es6.js";import"@vaadin/grid/vaadin-grid.js";import"@vaadin/grid/vaadin-grid-column-group.js";import"@vaadin/grid/vaadin-grid-selection-column.js";import"@vaadin/grid/vaadin-grid-sorter.js";import{isSome as t}from"../../../core/arrayUtils.js";import{on as r}from"../../../core/events.js";import{assertIsSome as i}from"../../../core/maybe.js";import{watch as o,on as s}from"../../../core/reactiveUtils.js";import{property as n}from"../../../core/accessorSupport/decorators/property.js";import{cast as l}from"../../../core/accessorSupport/decorators/cast.js";import"../../../core/has.js";import{subclass as d}from"../../../core/accessorSupport/decorators/subclass.js";import a from"../../Widget.js";import h from"./GridViewModel.js";import{globalCss as c}from"../../support/globalCss.js";import"../../support/widgetUtils.js";import{messageBundle as m}from"../../support/decorators/messageBundle.js";import{tsx as u}from"../../support/jsxFactory.js";const g={selectionColumn:!0,columnMenus:!0},p="esri-grid",_="compact column-borders",v={base:p,content:`${p}__content`,grid:`${p}__grid`,noColumnMenu:`${p}--no-column-menu`};let f=class extends a{constructor(e,t){super(e,t),this._columnElements=[],this._grid=null,this.itemIdPath=null,this.messages=null,this.viewModel=new h,this.visibleElements={...g}}initialize(){this.addHandles([this.columns.on("before-changes",(()=>this.renderNow())),this.columns.on("change",(()=>this.onColumnChange())),o((()=>this.viewModel?.size),(()=>this._updateGridSize())),o((()=>this.store?.state),((e,t)=>{"ready"!==e||"loaded"!==t&&"error"!==t||this.refreshPageCache()})),s((()=>this._grid?.$?.table),"scroll",(()=>this.viewModel?.closeColumnMenus()))])}destroy(){this.resetColumns(),this.columns.destroyed||this.columns.destroy()}resetColumns(){this.columns.drain((e=>!e.destroyed&&e.destroy()))}get _activeEditInfos(){return this._editorColumns.map((e=>e.activeEditInfo)).filter(t)}get _editorColumns(){return this.columns.filter((e=>"activeEditInfo"in e)).toArray()}get cellClassNameGenerator(){return this.viewModel.cellClassNameGenerator}set cellClassNameGenerator(e){this.viewModel.cellClassNameGenerator=e}get cellPartNameGenerator(){return this.viewModel.cellPartNameGenerator}set cellPartNameGenerator(e){this.viewModel.cellPartNameGenerator=e}get columns(){return this.viewModel.columns}set columns(e){this.viewModel.columns=e}get columnPerformanceModeEnabled(){return this.viewModel.columnPerformanceModeEnabled}set columnPerformanceModeEnabled(e){this.viewModel.columnPerformanceModeEnabled=e}get columnReorderingEnabled(){return this.viewModel.columnReorderingEnabled}set columnReorderingEnabled(e){this.viewModel.columnReorderingEnabled=e}get dataProvider(){return this.viewModel.dataProvider}set dataProvider(e){this.viewModel.dataProvider=e}get highlightIds(){return this.viewModel.highlightIds}set highlightIds(e){this.viewModel.highlightIds=e}get isEditingActive(){return!!this._activeEditInfos.length}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get multiSortEnabled(){return this.viewModel.multiSortEnabled}set multiSortEnabled(e){this.viewModel.multiSortEnabled=e}get pageSize(){return this.viewModel.pageSize}set pageSize(e){this.viewModel.pageSize=e}get rowDetailsRenderer(){return this.viewModel.rowDetailsRenderer}set rowDetailsRenderer(e){this.viewModel.rowDetailsRenderer=e}get size(){return this.viewModel.size}get sortOrders(){return this._grid?._sorters?this._grid._sorters.filter((e=>!!e&&e.path)).map((({direction:e,path:t})=>({direction:e,path:t}))):[]}get store(){return this.viewModel.store}set store(e){this.viewModel.store=e}castVisibleElements(e){return{...g,...e}}getColumnProps(e,t){const{id:r}=this,{autoWidth:i,direction:o,flexGrow:s,frozen:n,frozenToEnd:l,header:d,hidden:a,invalid:h,path:c,resizable:m,textAlign:u,width:g}=e,p=`${r}_${d}_${t??c}`,{renderFunction:_,footerRenderFunction:v,headerRenderFunction:f}=e,C=v?(e,t)=>v({root:e,column:t}):void 0,w=f?(e,t)=>f({root:e,column:t}):void 0,y=_?(e,t,r)=>_({root:e,column:t,rowData:r}):void 0;return{footerRenderer:C,headerRenderer:w,renderer:y,autoWidth:i,direction:o,flexGrow:s,frozen:n,frozenToEnd:l,header:d,hidden:a,key:p,path:c,resizable:m,bind:this,headerPartName:h?"invalid":void 0,"text-align":u,width:"number"==typeof g?`${g}px`:g,afterCreate:this._afterColumnCreate,afterRemoved:this._afterColumnRemoved}}clearSelection(){this._clearSelection(),this.scheduleRender()}clearSort(){let e=!1;if(this._grid){if(this._grid._sorters?.length&&(this._grid._sorters.forEach((e=>{e._order=null,e.direction=null})),e=!0),this.columns.length){this.columns.some((e=>!!e.direction))&&(this.columns.forEach((e=>e.direction=null)),e=!0)}e&&(this.notifyChange("sortOrders"),this.scheduleRender())}}findColumn(e){this.viewModel.findColumn(e)}generateCellClassNames(){this._grid?.generateCellClassNames()}generateCellPartNames(){this._grid?.generateCellPartNames()}getRowContainingNode(e){return this._grid?._getRowContainingNode(e)}getSlotElementByName(e){return this._grid?.shadowRoot?.querySelector(`slot[name='${e}']`)??null}hideColumn(e){this.viewModel?.hideColumn(e)}recalculateColumnWidths(){this._grid?.recalculateColumnWidths()}async reset(){this._clearSelection(),await(this.store?.reset()),this.scrollToTop()}refreshPageCache(){this._grid?.clearCache()}selectRows(e){const t=e?.filter((e=>!this.highlightIds.includes(e.objectId))),r=t.map((e=>e.objectId));r.length&&this.highlightIds.addMany(r)}deselectRows(e){const t=e?.map((e=>e.objectId))||[];t.length&&this.highlightIds.removeMany(t)}showColumn(e){this.viewModel?.showColumn(e)}sort({path:e,direction:t}){this.viewModel?.sortColumn(e,t),this.notifyChange("sortOrders")}scrollToIndex(e){this._grid?.scrollToIndex(e)}scrollToTop(){this._grid?.scrollToIndex(0)}onColumnChange(){this._columnElements.forEach((e=>{this._applyRenderersToColumnElement(e)})),this._grid?.requestContentUpdate()}render(){const{columnMenus:e}=this.visibleElements;return u("div",{bind:this,class:this.classes(v.base,c.widget,{[v.noColumnMenu]:!e})},u("div",{bind:this,class:v.content},this._renderGrid()))}_renderGrid(){const e=this.highlightIds.map((e=>this.store?.getLocalItemByKey(e)||{objectId:e})).toArray(),t=this.columnPerformanceModeEnabled?"lazy":"eager";return u("vaadin-grid",{afterCreate:this._afterGridCreate,afterUpdate:this._afterGridUpdate,bind:this,cellClassNameGenerator:this.cellClassNameGenerator,cellPartNameGenerator:this.cellPartNameGenerator,class:v.grid,columnRendering:t,columnReorderingAllowed:this.columnReorderingEnabled,dataProvider:this.dataProvider,id:`${this.id}_grid`,itemIdPath:this.itemIdPath,multiSort:this.multiSortEnabled,pageSize:this.pageSize,ref:"grid",rowDetailsRenderer:this.rowDetailsRenderer,selectedItems:e,size:this.size},this._renderAllColumns())}_renderAllColumns(){return"disabled"!==this.viewModel.state&&this.columns.length?[this._renderSelectionColumn(),this._renderColumns()]:null}_renderSelectionColumn(){return u("vaadin-grid-selection-column",{_selectAllHidden:!0,bind:this,dragSelect:!0,frozen:!0,hidden:!this.visibleElements.selectionColumn,selectAll:!1,sortable:!1,textAlign:"center"})}_renderColumns(){return Array.from(this.columns,((e,t)=>"columns"in e?this._renderGroupColumn(e,t):u("vaadin-grid-column",{...this.getColumnProps(e,t)}))).filter(t)}_renderGroupColumn(e,t){const r=this.getColumnProps(e,t);if(r.hidden||!e.columns)return null;const i=e.columns.filter((({hidden:e})=>!e));return i.length?u("vaadin-grid-column-group",{...r},i.map((e=>u("vaadin-grid-column",{...this.getColumnProps(e,t)})))):null}_afterGridCreate(e){const t=this._grid=e;t.setAttribute("theme",_),customElements.whenDefined("vaadin-grid").then((()=>{this._appendStyles(),this._addGridEventListeners()})),t.__updateSorter=e=>{const r=t._sorters,i=!r.includes(e);if(e.direction||!i)if(e._order=null,t.multiSort)t._removeArrayItem(r,e),e.direction&&(null!=e._initialOrder?(i?r[e._initialOrder]=e:r.splice(e._initialOrder,0,e),e._initialOrder=null):r.unshift(e)),t.__updateSortOrders();else if(e.direction){const i=r.filter((t=>t!==e));t._sorters=[e],i.forEach((e=>{e._order=null,e.direction=null}))}}}_appendStyles(){const e=this._grid?.shadowRoot,t=document.createElement("style");e&&(t.textContent='\n #items [part~="row"][editing], \n #items [part~="row"][editing][selected] { \n z-index: 2; \n }\n\n #items [part~="editing"],\n #items [part~="editing"][selected] {\n z-index: 3;\n }\n ',e.appendChild(t))}_afterGridUpdate(e){this._grid||(this._grid=e)}_afterColumnCreate(e){this._columnElements.push(e)}_afterColumnRemoved(e){const t=this._columnElements.indexOf(e,0);t>-1&&this._columnElements.splice(t,1)}_updateGridSize(){this._grid&&(this._grid.size=this.size||0,this.scheduleRender())}_addGridEventListeners(){const e=this._grid;i(e),this.addHandles([r(e,"click",(e=>this._onRowClick(e))),r(e,"selected-items-changed",(e=>this._onSelectedItemsChange(e))),r(e,"sorter-changed",(()=>this.notifyChange("sortOrders")))])}_onRowClick(e){const t=this._grid;i(t);const r=t.getEventContext(e),{item:o,section:s}=r;o&&s&&"details"!==s&&"header"!==s&&this.emit("row-click",{context:r,native:e})}_clearSelection(){this.highlightIds.removeAll()}_onSelectedItemsChange(e){const{highlightIds:t}=this,r=e.detail.value.map((e=>e.objectId)),i=r.filter((e=>!t.includes(e))),o=t.filter((e=>!r.includes(e)));t.removeMany(o),t.addMany(i)}_applyRenderersToColumnElement(e){const t=e?.path,r=null!=t?this.viewModel.findColumn(t):void 0;if(r)try{const{renderFunction:t,footerRenderFunction:i,headerRenderFunction:o}=r;t&&"renderer"in e&&(e.renderer=(e,r,i)=>t({root:e,column:r,rowData:i})),i&&(e.footerRenderer=(e,t)=>i({root:e,column:t})),o&&(e.headerRenderer=(e,t)=>o({root:e,column:t}))}catch(i){}}};e([n()],f.prototype,"_activeEditInfos",null),e([n()],f.prototype,"_columnElements",void 0),e([n()],f.prototype,"_editorColumns",null),e([n()],f.prototype,"_grid",void 0),e([n()],f.prototype,"cellClassNameGenerator",null),e([n()],f.prototype,"cellPartNameGenerator",null),e([n()],f.prototype,"columns",null),e([n()],f.prototype,"columnPerformanceModeEnabled",null),e([n()],f.prototype,"columnReorderingEnabled",null),e([n()],f.prototype,"dataProvider",null),e([n()],f.prototype,"highlightIds",null),e([n()],f.prototype,"isEditingActive",null),e([n()],f.prototype,"itemIdPath",void 0),e([n()],f.prototype,"label",null),e([n(),m("esri/widgets/FeatureTable/t9n/FeatureTable")],f.prototype,"messages",void 0),e([n()],f.prototype,"multiSortEnabled",null),e([n()],f.prototype,"pageSize",null),e([n()],f.prototype,"rowDetailsRenderer",null),e([n()],f.prototype,"size",null),e([n({readOnly:!0})],f.prototype,"sortOrders",null),e([n()],f.prototype,"store",null),e([n()],f.prototype,"viewModel",void 0),e([n()],f.prototype,"visibleElements",void 0),e([l("visibleElements")],f.prototype,"castVisibleElements",null),f=e([d("esri.widgets.FeatureTable.Grid.Grid")],f);const C=f;export{C as default};
5
+ import{_ as e}from"../../../chunks/tslib.es6.js";import"@vaadin/grid/vaadin-grid.js";import"@vaadin/grid/vaadin-grid-column-group.js";import"@vaadin/grid/vaadin-grid-selection-column.js";import"@vaadin/grid/vaadin-grid-sorter.js";import{isSome as t}from"../../../core/arrayUtils.js";import{on as r}from"../../../core/events.js";import{assertIsSome as i}from"../../../core/maybe.js";import{watch as o,on as n}from"../../../core/reactiveUtils.js";import{property as s}from"../../../core/accessorSupport/decorators/property.js";import{cast as l}from"../../../core/accessorSupport/decorators/cast.js";import"../../../core/has.js";import{subclass as d}from"../../../core/accessorSupport/decorators/subclass.js";import a from"../../Widget.js";import h from"./GridViewModel.js";import{globalCss as c}from"../../support/globalCss.js";import"../../support/widgetUtils.js";import{messageBundle as m}from"../../support/decorators/messageBundle.js";import{tsx as u}from"../../support/jsxFactory.js";const g={selectionColumn:!0,columnMenus:!0},p="esri-grid",_="compact column-borders",v={base:p,content:`${p}__content`,grid:`${p}__grid`,noColumnMenu:`${p}--no-column-menu`};let f=class extends a{constructor(e,t){super(e,t),this._columnElements=[],this._grid=null,this.itemIdPath=null,this.messages=null,this.viewModel=new h,this.visibleElements={...g}}initialize(){this.addHandles([this.columns.on("before-changes",(()=>this.renderNow())),this.columns.on("change",(()=>this.onColumnChange())),o((()=>this.viewModel?.size),(()=>this._updateGridSize())),o((()=>this.store?.state),((e,t)=>{"ready"!==e||"loaded"!==t&&"error"!==t||this.refreshPageCache()})),n((()=>this._grid?.$?.table),"scroll",(()=>this.viewModel?.closeColumnMenus()))])}destroy(){this.resetColumns(),this.columns.destroyed||this.columns.destroy()}resetColumns(){this.columns.drain((e=>!e.destroyed&&e.destroy()))}get _activeEditInfos(){return this._editorColumns.map((e=>e.activeEditInfo)).filter(t)}get _editorColumns(){return this.columns.filter((e=>"activeEditInfo"in e)).toArray()}get cellClassNameGenerator(){return this.viewModel.cellClassNameGenerator}set cellClassNameGenerator(e){this.viewModel.cellClassNameGenerator=e}get cellPartNameGenerator(){return this.viewModel.cellPartNameGenerator}set cellPartNameGenerator(e){this.viewModel.cellPartNameGenerator=e}get columns(){return this.viewModel.columns}set columns(e){this.viewModel.columns=e}get columnPerformanceModeEnabled(){return this.viewModel.columnPerformanceModeEnabled}set columnPerformanceModeEnabled(e){this.viewModel.columnPerformanceModeEnabled=e}get columnReorderingEnabled(){return this.viewModel.columnReorderingEnabled}set columnReorderingEnabled(e){this.viewModel.columnReorderingEnabled=e}get dataProvider(){return this.viewModel.dataProvider}set dataProvider(e){this.viewModel.dataProvider=e}get highlightIds(){return this.viewModel.highlightIds}set highlightIds(e){this.viewModel.highlightIds=e}get isEditingActive(){return!!this._activeEditInfos.length}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get multiSortEnabled(){return this.viewModel.multiSortEnabled}set multiSortEnabled(e){this.viewModel.multiSortEnabled=e}get pageSize(){return this.viewModel.pageSize}set pageSize(e){this.viewModel.pageSize=e}get rowDetailsRenderer(){return this.viewModel.rowDetailsRenderer}set rowDetailsRenderer(e){this.viewModel.rowDetailsRenderer=e}get size(){return this.viewModel.size}get sortOrders(){return this._grid?._sorters?this._grid._sorters.filter((e=>!!e&&e.path)).map((({direction:e,path:t})=>({direction:e,path:t}))):[]}get store(){return this.viewModel.store}set store(e){this.viewModel.store=e}castVisibleElements(e){return{...g,...e}}getColumnProps(e,t){const{id:r}=this,{autoWidth:i,direction:o,flexGrow:n,frozen:s,frozenToEnd:l,header:d,hidden:a,invalid:h,path:c,resizable:m,textAlign:u,width:g}=e,p=`${r}_${d}_${t??c}`,{renderFunction:_,footerRenderFunction:v,headerRenderFunction:f}=e,C=v?(e,t)=>v({root:e,column:t}):void 0,w=f?(e,t)=>f({root:e,column:t}):void 0,y=_?(e,t,r)=>_({root:e,column:t,rowData:r}):void 0;return{footerRenderer:C,headerRenderer:w,renderer:y,autoWidth:i,direction:o,flexGrow:n,frozen:s,frozenToEnd:l,header:d,hidden:a,key:p,path:c,resizable:m,bind:this,headerPartName:h?"invalid":void 0,"text-align":u,width:"number"==typeof g?`${g}px`:g,afterCreate:this._afterColumnCreate,afterRemoved:this._afterColumnRemoved}}clearSelection(){this._clearSelection(),this.scheduleRender()}clearSort(){let e=!1;if(this._grid){if(this._grid._sorters?.length&&(this._grid._sorters.forEach((e=>{e._order=null,e.direction=null})),e=!0),this.columns.length){this.columns.some((e=>!!e.direction))&&(this.columns.forEach((e=>e.direction=null)),e=!0)}e&&(this.notifyChange("sortOrders"),this.scheduleRender())}}findColumn(e){this.viewModel.findColumn(e)}generateCellClassNames(){this._grid?.generateCellClassNames()}generateCellPartNames(){this._grid?.generateCellPartNames()}getRowContainingNode(e){return this._grid?._getRowContainingNode(e)}getSlotElementByName(e){return this._grid?.shadowRoot?.querySelector(`slot[name='${e}']`)??null}hideColumn(e){this.viewModel?.hideColumn(e)}recalculateColumnWidths(){this._grid?.recalculateColumnWidths()}async reset(){this._clearSelection(),await(this.store?.reset()),this.scrollToTop()}refreshPageCache(){this._grid?.clearCache()}selectRows(e){const t=e?.filter((e=>!this.highlightIds.includes(e.objectId))),r=t.map((e=>e.objectId));r.length&&this.highlightIds.addMany(r)}deselectRows(e){const t=e?.map((e=>e.objectId))||[];t.length&&this.highlightIds.removeMany(t)}showColumn(e){this.viewModel?.showColumn(e)}sort({path:e,direction:t}){this.viewModel?.sortColumn(e,t),this.notifyChange("sortOrders")}scrollToIndex(e){this._grid?.scrollToIndex(e)}scrollToTop(){this._grid?.scrollToIndex(0)}onColumnChange(){this._columnElements.forEach((e=>{this._applyRenderersToColumnElement(e)})),this._grid?.requestContentUpdate()}render(){const{columnMenus:e}=this.visibleElements;return u("div",{bind:this,class:this.classes(v.base,c.widget,{[v.noColumnMenu]:!e})},u("div",{bind:this,class:v.content},this._renderGrid()))}_renderGrid(){const e=this.highlightIds.map((e=>this.store?.getLocalItemByKey(e)||{objectId:e})).toArray(),t=this.columnPerformanceModeEnabled?"lazy":"eager";return u("vaadin-grid",{afterCreate:this._afterGridCreate,afterUpdate:this._afterGridUpdate,bind:this,cellClassNameGenerator:this.cellClassNameGenerator,cellPartNameGenerator:this.cellPartNameGenerator,class:v.grid,columnRendering:t,columnReorderingAllowed:this.columnReorderingEnabled,dataProvider:this.dataProvider,id:`${this.id}_grid`,itemIdPath:this.itemIdPath,multiSort:this.multiSortEnabled,pageSize:this.pageSize,ref:"grid",rowDetailsRenderer:this.rowDetailsRenderer,selectedItems:e,size:this.size},this._renderAllColumns())}_renderAllColumns(){return"disabled"!==this.viewModel.state&&this.columns.length?[this._renderSelectionColumn(),this._renderColumns()]:null}_renderSelectionColumn(){return u("vaadin-grid-selection-column",{_selectAllHidden:!0,bind:this,dragSelect:!0,frozen:!0,hidden:!this.visibleElements.selectionColumn,selectAll:!1,sortable:!1,textAlign:"center"})}_renderColumns(){return Array.from(this.columns,((e,t)=>"columns"in e?this._renderGroupColumn(e,t):u("vaadin-grid-column",{...this.getColumnProps(e,t)}))).filter(t)}_renderGroupColumn(e,t){const r=this.getColumnProps(e,t);if(r.hidden||!e.columns)return null;const i=e.columns.filter((({hidden:e})=>!e));return i.length?u("vaadin-grid-column-group",{...r},i.map((e=>u("vaadin-grid-column",{...this.getColumnProps(e,t)})))):null}_afterGridCreate(e){const t=this._grid=e;t.setAttribute("theme",_),customElements.whenDefined("vaadin-grid").then((()=>{this._appendStyles(),this._addGridEventListeners()})),t.__updateSorter=e=>{const r=t._sorters,i=!r.includes(e);if(e.direction||!i)if(e._order=null,t.multiSort)t._removeArrayItem(r,e),e.direction&&(null!=e._initialOrder?(i?r[e._initialOrder]=e:r.splice(e._initialOrder,0,e),e._initialOrder=null):r.unshift(e)),t.__updateSortOrders();else if(e.direction){const i=r.filter((t=>t!==e));t._sorters=[e],i.forEach((e=>{e._order=null,e.direction=null}))}}}_appendStyles(){const e=this._grid?.shadowRoot,t=document.createElement("style");e&&(t.textContent='\n #items [part~="row"][editing], \n #items [part~="row"][editing][selected] { \n z-index: 2; \n }\n\n #items [part~="editing"],\n #items [part~="editing"][selected] {\n z-index: 3;\n }\n\n [frozen], [frozen-to-end] {\n z-index: 4;\n }\n ',e.appendChild(t))}_afterGridUpdate(e){this._grid||(this._grid=e)}_afterColumnCreate(e){this._columnElements.push(e)}_afterColumnRemoved(e){const t=this._columnElements.indexOf(e,0);t>-1&&this._columnElements.splice(t,1)}_updateGridSize(){this._grid&&(this._grid.size=this.size||0,this.scheduleRender())}_addGridEventListeners(){const e=this._grid;i(e),this.addHandles([r(e,"click",(e=>this._onRowClick(e))),r(e,"selected-items-changed",(e=>this._onSelectedItemsChange(e))),r(e,"sorter-changed",(()=>this.notifyChange("sortOrders")))])}_onRowClick(e){const t=this._grid;i(t);const r=t.getEventContext(e),{item:o,section:n}=r;o&&n&&"details"!==n&&"header"!==n&&this.emit("row-click",{context:r,native:e})}_clearSelection(){this.highlightIds.removeAll()}_onSelectedItemsChange(e){const{highlightIds:t}=this,r=e.detail.value.map((e=>e.objectId)),i=r.filter((e=>!t.includes(e))),o=t.filter((e=>!r.includes(e)));t.removeMany(o),t.addMany(i)}_applyRenderersToColumnElement(e){const t=e?.path,r=null!=t?this.viewModel.findColumn(t):void 0;if(r)try{const{renderFunction:t,footerRenderFunction:i,headerRenderFunction:o}=r;t&&"renderer"in e&&(e.renderer=(e,r,i)=>t({root:e,column:r,rowData:i})),i&&(e.footerRenderer=(e,t)=>i({root:e,column:t})),o&&(e.headerRenderer=(e,t)=>o({root:e,column:t}))}catch(i){}}};e([s()],f.prototype,"_activeEditInfos",null),e([s()],f.prototype,"_columnElements",void 0),e([s()],f.prototype,"_editorColumns",null),e([s()],f.prototype,"_grid",void 0),e([s()],f.prototype,"cellClassNameGenerator",null),e([s()],f.prototype,"cellPartNameGenerator",null),e([s()],f.prototype,"columns",null),e([s()],f.prototype,"columnPerformanceModeEnabled",null),e([s()],f.prototype,"columnReorderingEnabled",null),e([s()],f.prototype,"dataProvider",null),e([s()],f.prototype,"highlightIds",null),e([s()],f.prototype,"isEditingActive",null),e([s()],f.prototype,"itemIdPath",void 0),e([s()],f.prototype,"label",null),e([s(),m("esri/widgets/FeatureTable/t9n/FeatureTable")],f.prototype,"messages",void 0),e([s()],f.prototype,"multiSortEnabled",null),e([s()],f.prototype,"pageSize",null),e([s()],f.prototype,"rowDetailsRenderer",null),e([s()],f.prototype,"size",null),e([s({readOnly:!0})],f.prototype,"sortOrders",null),e([s()],f.prototype,"store",null),e([s()],f.prototype,"viewModel",void 0),e([s()],f.prototype,"visibleElements",void 0),e([l("visibleElements")],f.prototype,"castVisibleElements",null),f=e([d("esri.widgets.FeatureTable.Grid.Grid")],f);const C=f;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/4.29/esri/copyright.txt for details.
4
4
  */
5
- import{_ as o}from"../../../chunks/tslib.es6.js";import{JSONSupport as t}from"../../../core/JSONSupport.js";import{property as i}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as r}from"../../../core/accessorSupport/decorators/subclass.js";let e=class extends t{constructor(o){super(o),this.description=null,this.direction=null,this.formatFunction=null,this.initialSortPriority=null,this.invalid=!1,this.label=null,this.menuConfig=null,this.sortable=!0,this.textAlign="start",this.type=null,this.visible=!0}};o([i()],e.prototype,"description",void 0),o([i()],e.prototype,"direction",void 0),o([i()],e.prototype,"formatFunction",void 0),o([i()],e.prototype,"initialSortPriority",void 0),o([i()],e.prototype,"invalid",void 0),o([i()],e.prototype,"label",void 0),o([i()],e.prototype,"menuConfig",void 0),o([i()],e.prototype,"sortable",void 0),o([i()],e.prototype,"textAlign",void 0),o([i({type:String,json:{read:!1,write:!0}})],e.prototype,"type",void 0),o([i()],e.prototype,"visible",void 0),e=o([r("esri.widgets.FeatureTable.support.ColumnTemplateBase")],e);const s=e;export{s as default};
5
+ import{_ as o}from"../../../chunks/tslib.es6.js";import{JSONSupport as t}from"../../../core/JSONSupport.js";import{property as r}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as i}from"../../../core/accessorSupport/decorators/subclass.js";let e=class extends t{constructor(o){super(o),this.description=null,this.direction=null,this.formatFunction=null,this.frozen=!1,this.frozenToEnd=!1,this.initialSortPriority=null,this.invalid=!1,this.label=null,this.menuConfig=null,this.sortable=!0,this.textAlign="start",this.type=null,this.visible=!0}};o([r()],e.prototype,"description",void 0),o([r()],e.prototype,"direction",void 0),o([r()],e.prototype,"formatFunction",void 0),o([r()],e.prototype,"frozen",void 0),o([r()],e.prototype,"frozenToEnd",void 0),o([r()],e.prototype,"initialSortPriority",void 0),o([r()],e.prototype,"invalid",void 0),o([r()],e.prototype,"label",void 0),o([r()],e.prototype,"menuConfig",void 0),o([r()],e.prototype,"sortable",void 0),o([r()],e.prototype,"textAlign",void 0),o([r({type:String,json:{read:!1,write:!0}})],e.prototype,"type",void 0),o([r()],e.prototype,"visible",void 0),e=o([i("esri.widgets.FeatureTable.support.ColumnTemplateBase")],e);const s=e;export{s as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.29/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../chunks/tslib.es6.js";import"../../geometry.js";import t from"../../Graphic.js";import"../../symbols.js";import{isSome as i}from"../../core/arrayUtils.js";import s from"../../core/Error.js";import r from"../../core/Logger.js";import{debounce as o,isAbortError as a}from"../../core/promiseUtils.js";import n from"../../core/ReactiveSet.js";import{watch as l,when as h,sync as u}from"../../core/reactiveUtils.js";import{property as c}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import{subclass as d}from"../../core/accessorSupport/decorators/subclass.js";import{initializeProjection as p,project as g}from"../../geometry/projection.js";import{getPointFromGeometry as f}from"../../geometry/support/geometryUtils.js";import{geographicToWebMercator as m}from"../../geometry/support/webMercatorUtils.js";import y from"../../layers/Layer.js";import{fallbackObjectIDAttribute as w}from"../../layers/LayerConstants.js";import{getDisplayedSymbol as F}from"../../symbols/support/symbolUtils.js";import{highlightsSupported as v}from"../../views/support/layerViewUtils.js";import _ from"../Feature/FeatureViewModel.js";import{ActionsCollection as b,zoomToFeature as C,zoomToClusteredFeatures as P,browseClusteredFeatures as E}from"../Popup/actions.js";import{triggerAction as j,isClusterFeature as M,removeClusteredFeaturesForBrowsing as A,displayClusterExtent as L,browseAggregateFeatures as V,getSelectedTarget as I}from"../Popup/actionUtils.js";import S from"../support/AnchorElementViewModel.js";import{GoToMixin as O}from"../support/GoTo.js";import x from"../../symbols/SimpleFillSymbol.js";import T from"../../geometry/Point.js";const H=()=>[C.clone()],B=()=>[P.clone(),E.clone()];let R=null;function U(e,t){return"building-scene"===e||"2d"===t&&("map-image"===e||"tile"===e||"imagery"===e||"imagery-tile"===e)}let G=class extends(O(S)){constructor(e){super(e),this._pendingPromises=new n,this._fetchFeaturesController=null,this._highlightSelectedFeaturePromise=null,this._highlightActiveFeaturePromise=null,this._selectedClusterFeature=null,this._locationScaleHandle=null,this.actions=new b,this.activeFeature=null,this.autoCloseEnabled=!1,this.autoOpenEnabled=!0,this.browseClusterEnabled=!1,this.content=null,this.defaultPopupTemplateEnabled=!1,this.featurePage=null,this.featuresPerPage=20,this.featureMenuOpen=!1,this.featureViewModelAbilities=null,this.featureViewModels=[],this.highlightEnabled=!0,this.includeDefaultActions=!0,this.selectedClusterBoundaryFeature=new t({symbol:new x({outline:{width:1.5,color:"cyan"},style:"none"})}),this.title=null,this.updateLocationEnabled=!1,this.view=null,this.visible=!1,this.zoomFactor=4,this.zoomToLocation=null,this._debouncedLocationUpdate=o((async e=>{const{view:t}=this,i=this.selectedFeature?.geometry?.type,s=this.location??e;if("mesh"!==i&&t&&s&&this.selectedFeature)if("point"!==i)try{const{pendingFeatures:e}=await this._fetchFeaturesWithController({mapPoint:s}),i=(await Promise.all(e)).flat().filter(Boolean);if(!i.length)return;if(i.length!==this.features.length){const e=this._getHighlightLayer(this.selectedFeature),t="imagery"===e?.type?void 0:e&&"objectIdField"in e?e.objectIdField||w:null;if(t){const s=this.selectedFeature.getObjectId(),r=i.findIndex((i=>{const r=this._getHighlightLayer(i);return r?.uid===e?.uid&&i.attributes[t]===s}));this.features=i,this.selectedFeatureIndex=r}}const r=i[this.selectedFeatureIndex]?.geometry,o=("mesh"!==r?.type?r:null)??this.selectedFeature.geometry,a=g(o,t.spatialReference);R||(R=await import("../../geometry/geometryEngineAsync.js")),a&&!await R.intersects(a,s)&&(this.location=(await R.nearestCoordinate(a,s)).coordinate??s)}catch(o){a(o)||r.getLogger(this).error(o)}else this.location=f(this.selectedFeature.geometry)??s}))}initialize(){this.addHandles([this.on("view-change",(()=>this._autoClose())),l((()=>[this.highlightEnabled,this.selectedFeature,this.visible,this.view]),(()=>this._highlightSelectedFeature())),l((()=>[this.highlightEnabled,this.activeFeature,this.visible,this.view]),(()=>this._highlightActiveFeature())),l((()=>this.view?.animation?.state),(e=>this._animationStateChange(e))),l((()=>this.location),(e=>this._locationChange(e))),l((()=>this.selectedFeature),(e=>this._selectedFeatureChange(e))),l((()=>[this.selectedFeatureIndex,this.featureCount,this.featuresPerPage]),(()=>this._selectedFeatureIndexChange())),l((()=>[this.featurePage,this.selectedFeatureIndex,this.featureCount,this.featuresPerPage,this.featureViewModels]),(()=>this._setGraphicOnFeatureViewModels())),l((()=>this.featureViewModels),(()=>this._featureViewModelsChange())),this.on("trigger-action",(e=>j({event:e,viewModel:this,view:this.view}))),h((()=>!this.waitingForResult),(()=>this._waitingForResultChange()),u),l((()=>[this.features,this.view?.map,this.view?.spatialReference,this.view?.timeZone]),(()=>this._updateFeatureVMs())),l((()=>this.view?.scale),(()=>this._viewScaleChange())),h((()=>!this.visible),(()=>this.browseClusterEnabled=!1)),l((()=>this.browseClusterEnabled),(e=>e?this.enableClusterBrowsing():this.disableClusterBrowsing()))])}destroy(){this._cancelFetchingFeatures(),this._pendingPromises.clear(),this.browseClusterEnabled=!1,this.view=null,this._locationScaleHandle?.remove(),this._locationScaleHandle=null}get active(){return!(!this.visible||this.waitingForResult)}get allActions(){const e=this._get("allActions")||new b;e.removeAll();const{actions:t,defaultActions:i,defaultPopupTemplateEnabled:s,includeDefaultActions:r,selectedFeature:o}=this,a=r?i.concat(t):t,n=o&&("function"==typeof o.getEffectivePopupTemplate&&o.getEffectivePopupTemplate(s)||o.popupTemplate),l=n?.actions,h=n?.overwriteActions?l:l?.concat(a)??a;return h?.filter(Boolean).forEach((t=>e.add(t))),e}get defaultActions(){const e=this._get("defaultActions")||new b;return e.removeAll(),e.addMany(M(this.selectedFeature)?B():H()),e}get featureCount(){return this.features.length}set features(e){const t=e||[];this._set("features",t);const{pendingPromisesCount:i,promiseCount:s,selectedFeatureIndex:r}=this,o=s&&t.length;o&&i&&-1===r?this.selectedFeatureIndex=0:o&&-1!==r||(this.selectedFeatureIndex=t.length?0:-1)}set location(e){let t=e;const i=this.view?.spatialReference?.isWebMercator,s=e?.spatialReference?.isWGS84;s&&i&&(t=m(e)),this._set("location",t)}get pendingPromisesCount(){return this._pendingPromises.size}get promiseCount(){return this.promises.length}get promises(){return this._get("promises")||[]}set promises(e){this._pendingPromises.clear(),this.features=[],Array.isArray(e)&&e.length?(this._set("promises",e),(e=e.slice(0)).forEach((e=>this._pendingPromises.add(e))),e.reduce(((e,t)=>e.finally((()=>t.then((e=>{this._pendingPromises.has(t)&&this._updateFeatures(e)})).finally((()=>this._pendingPromises.delete(t))).catch((()=>{}))))),Promise.resolve())):this._set("promises",[])}get selectedFeature(){const{features:e,selectedFeatureIndex:t}=this;if(-1===t)return null;return e[t]||null}get selectedFeatureIndex(){const e=this._get("selectedFeatureIndex");return"number"==typeof e?e:-1}set selectedFeatureIndex(e){const{featureCount:t}=this;e=isNaN(e)||e<-1||!t?-1:(e+t)%t,this.activeFeature=null,this._set("selectedFeatureIndex",e)}get selectedFeatureViewModel(){return this.featureViewModels[this.selectedFeatureIndex]||null}get state(){return this.view?.ready?"ready":"disabled"}get waitingForContents(){return this.featureViewModels.some((e=>e.waitingForContent))}get waitingForResult(){return!(!(!!this._fetchFeaturesController||this.pendingPromisesCount>0)||0!==this.featureCount)}centerAtLocation(){const{view:e}=this,t=I(this);return t&&e?this.callGoTo({target:{target:t,scale:e.scale}}):Promise.reject(new s("center-at-location:invalid-target-or-view","Cannot center at a location without a target and view.",{target:t,view:e}))}zoomTo(e){return this.callGoTo(e)}clear(){this.set({promises:[],features:[],content:null,title:null,location:null,activeFeature:null})}fetchFeatures(e,t){const{view:i}=this;if(!i||!e)throw new s("fetch-features:invalid-screenpoint-or-view","Cannot fetch features without a screenPoint and view.",{screenPoint:e,view:i});return i.fetchPopupFeatures(e,{pointerType:t?.event?.pointerType,defaultPopupTemplateEnabled:this.defaultPopupTemplateEnabled,signal:t?.signal})}open(e){const t={updateLocationEnabled:!1,promises:[],fetchFeatures:!1,...e,visible:!0},{fetchFeatures:i}=t;delete t.fetchFeatures,i&&this._setFetchFeaturesPromises(t.location);const s=["actionsMenuOpen","collapsed"];for(const r of s)delete t[r];this.set(t)}triggerAction(e){const t=this.allActions.at(e);t&&!t.disabled&&this.emit("trigger-action",{action:t})}next(){return this.selectedFeatureIndex++,this}previous(){return this.selectedFeatureIndex--,this}disableClusterBrowsing(){A(this),this._clearBrowsedClusterGraphics()}async enableClusterBrowsing(){const{view:e,selectedFeature:t}=this;"2d"===e?.type?M(t)?(await L(this),await V(this)):r.getLogger(this).warn("enableClusterBrowsing:invalid-selectedFeature: Selected feature must represent an aggregate/cluster graphic.",t):r.getLogger(this).warn("enableClusterBrowsing:invalid-view: View must be 2d MapView.",t)}handleViewClick(e){this.autoOpenEnabled&&this._fetchFeaturesAndOpen(e)}_animationStateChange(e){this.zoomToLocation||(C.disabled="waiting-for-target"===e)}_clearBrowsedClusterGraphics(){const e=[this.selectedClusterBoundaryFeature,this._selectedClusterFeature].filter(i);this.view?.graphics?.removeMany(e),this._selectedClusterFeature=null,this.selectedClusterBoundaryFeature.geometry=null}_viewScaleChange(){if(M(this.selectedFeature))return this.browseClusterEnabled=!1,this.visible=!1,void this.clear();this.browseClusterEnabled&&(this.features=this.selectedFeature?[this.selectedFeature]:[])}_locationChange(e){const{selectedFeature:t,updateLocationEnabled:i}=this;i&&e&&(!t||t.geometry)&&this.centerAtLocation()}_selectedFeatureIndexChange(){this.featurePage=this.featureCount>1?Math.floor(this.selectedFeatureIndex/this.featuresPerPage)+1:null}_featureViewModelsChange(){this.featurePage=this.featureCount>1?1:null}_setGraphicOnFeatureViewModels(){const{features:e,featureCount:t,featurePage:i,featuresPerPage:s,featureViewModels:r}=this;if(null===i)return;const o=((i-1)*s+t)%t,a=o+s;r.slice(o,a).forEach(((t,i)=>{t&&(t.graphic??=e[o+i])}))}async _selectedFeatureChange(e){const{location:t,updateLocationEnabled:i,view:s}=this;if(e&&s){if(this.browseClusterEnabled){if(this._selectedClusterFeature&&(s.graphics.remove(this._selectedClusterFeature),this._selectedClusterFeature=null),M(e))return;return e.symbol=await F(e),this._selectedClusterFeature=e,void s.graphics.add(this._selectedClusterFeature)}if(e.symbol=await F(e),!i&&t||!e.geometry){if(i&&!e.geometry){await this.centerAtLocation();const e=s.center?.clone();e&&(this.location=e)}}else this.location=f(e.geometry)}}_waitingForResultChange(){!this.featureCount&&this.promises&&(this.visible=!1)}async _setFetchFeaturesPromises(e){const{pendingFeatures:t}=await this._fetchFeaturesWithController({mapPoint:e});this.promises=t}_destroyFeatureVMs(){this.featureViewModels.forEach((e=>e&&!e.destroyed&&e.destroy())),this._set("featureViewModels",[])}_updateFeatureVMs(){const{selectedFeature:e,features:t,featureViewModels:i,view:s}=this;if(M(e)||(this.browseClusterEnabled=!1),this._destroyFeatureVMs(),!t?.length)return;const r=i.slice(0),o=[];t.forEach(((t,i)=>{if(!t)return;let a=null;if(r.some(((e,i)=>(e&&e.graphic===t&&(a=e,r.splice(i,1)),!!a))),a)o[i]=a;else{const r=new _({abilities:this.featureViewModelAbilities,defaultPopupTemplateEnabled:this.defaultPopupTemplateEnabled,spatialReference:s?.spatialReference,graphic:t===e?t:null,location:this.location,map:s?.map,view:s});o[i]=r}})),r.forEach((e=>e&&!e.destroyed&&e.destroy())),this._set("featureViewModels",o)}async _getScreenPoint(e,t){const{view:i}=this;await(i?.when());const s=e?.spatialReference,r=i?.spatialReference;return s&&r?(await p(s,r,null,t),i.toScreen(e)):null}_cancelFetchingFeatures(){const e=this._fetchFeaturesController;e&&e.abort(),this._fetchFeaturesController=null}async _projectScreenPointAndFetchFeatures({mapPoint:e,screenPoint:t,event:i,signal:s}){return this.fetchFeatures(t??await this._getScreenPoint(e??this.location,{signal:s}),{signal:s,event:i})}_fetchFeaturesWithController({mapPoint:e,screenPoint:t,event:i}){this._cancelFetchingFeatures();const s=new AbortController,{signal:r}=s;this._fetchFeaturesController=s;const o=this._projectScreenPointAndFetchFeatures({mapPoint:e,screenPoint:t,signal:r,event:i});return o.catch((()=>{})).then((()=>{this._fetchFeaturesController=null})),o}async _fetchFeaturesAndOpen(e){const{mapPoint:t,screenPoint:i}=e,{view:s}=this;this._locationScaleHandle?.remove(),this._locationScaleHandle=l((()=>this.view?.scale),(()=>this._debouncedLocationUpdate(t).catch((e=>{a(e)||r.getLogger(this).error(e)}))));const{pendingFeatures:o}=await this._fetchFeaturesWithController({mapPoint:t,screenPoint:i,event:e});s?.popup&&"open"in s.popup&&s.popup.open({location:t??void 0,promises:o})}_autoClose(){this.autoCloseEnabled&&(this.visible=!1)}async _getLayerView(e,t){return await e.when(),e.whenLayerView(t)}_getHighlightLayer(e){const{layer:t,sourceLayer:i}=e;return i&&"layer"in i&&i.layer?i.layer:"map-notes"===i?.type||"subtype-group"===i?.type?i:t}_getHighlightTarget(e,t,i){if(U(t.type,i))return e;const s=e.getObjectId();if(null!=s)return s;const r="imagery"===t.type?void 0:"objectIdField"in t?t.objectIdField||w:null,o=e.attributes;return o&&r&&o[r]||e}_mapIncludesLayer(e){return!!this.view?.map?.allLayers?.includes(e)}async _highlightActiveFeature(){const e="highlight-active-feature";this.removeHandles(e);const{highlightEnabled:t,view:i,activeFeature:s,visible:r}=this;if(!(s&&i&&t&&r))return;const o=this._getHighlightLayer(s);if(!(o&&o instanceof y&&this._mapIncludesLayer(o)))return;const a=this._getLayerView(i,o);this._highlightActiveFeaturePromise=a;const n=await a;if(!(n&&v(n)&&this._highlightActiveFeaturePromise===a&&this.activeFeature&&this.highlightEnabled))return;const l=n.highlight(this._getHighlightTarget(s,o,i.type));this.addHandles(l,e)}async _highlightSelectedFeature(){const e="highlight-selected-feature";this.removeHandles(e);const{selectedFeature:t,highlightEnabled:i,view:s,visible:r}=this;if(!(t&&s&&i&&r))return;const o=this._getHighlightLayer(t);if(!(o&&o instanceof y&&this._mapIncludesLayer(o)))return;const a=this._getLayerView(s,o);this._highlightSelectedFeaturePromise=a;const n=await a;if(!(n&&v(n)&&this._highlightSelectedFeaturePromise===a&&this.selectedFeature&&this.highlightEnabled&&this.visible))return;const l=n.highlight(this._getHighlightTarget(t,o,s.type));this.addHandles(l,e)}_updateFeatures(e){const{features:t}=this,i=e.filter((e=>!t.includes(e)));i?.length&&(this.features=t.concat(i))}};e([c()],G.prototype,"_fetchFeaturesController",void 0),e([c({type:b})],G.prototype,"actions",void 0),e([c({readOnly:!0})],G.prototype,"active",null),e([c()],G.prototype,"activeFeature",void 0),e([c({readOnly:!0})],G.prototype,"allActions",null),e([c()],G.prototype,"autoCloseEnabled",void 0),e([c()],G.prototype,"autoOpenEnabled",void 0),e([c()],G.prototype,"browseClusterEnabled",void 0),e([c()],G.prototype,"content",void 0),e([c({type:b,readOnly:!0})],G.prototype,"defaultActions",null),e([c({type:Boolean})],G.prototype,"defaultPopupTemplateEnabled",void 0),e([c({readOnly:!0})],G.prototype,"featureCount",null),e([c()],G.prototype,"featurePage",void 0),e([c({value:[]})],G.prototype,"features",null),e([c()],G.prototype,"featuresPerPage",void 0),e([c()],G.prototype,"featureMenuOpen",void 0),e([c()],G.prototype,"featureViewModelAbilities",void 0),e([c({readOnly:!0})],G.prototype,"featureViewModels",void 0),e([c()],G.prototype,"highlightEnabled",void 0),e([c()],G.prototype,"includeDefaultActions",void 0),e([c({type:T})],G.prototype,"location",null),e([c({readOnly:!0})],G.prototype,"pendingPromisesCount",null),e([c({readOnly:!0})],G.prototype,"promiseCount",null),e([c()],G.prototype,"promises",null),e([c({readOnly:!0})],G.prototype,"selectedClusterBoundaryFeature",void 0),e([c({value:null,readOnly:!0})],G.prototype,"selectedFeature",null),e([c({value:-1})],G.prototype,"selectedFeatureIndex",null),e([c({readOnly:!0})],G.prototype,"selectedFeatureViewModel",null),e([c({readOnly:!0})],G.prototype,"state",null),e([c()],G.prototype,"title",void 0),e([c()],G.prototype,"updateLocationEnabled",void 0),e([c()],G.prototype,"view",void 0),e([c()],G.prototype,"visible",void 0),e([c({readOnly:!0})],G.prototype,"waitingForContents",null),e([c({readOnly:!0})],G.prototype,"waitingForResult",null),e([c()],G.prototype,"zoomFactor",void 0),e([c()],G.prototype,"zoomToLocation",void 0),e([c()],G.prototype,"centerAtLocation",null),G=e([d("esri.widgets.Features.FeaturesViewModel")],G);const z=G;export{z as default};
5
+ import{_ as e}from"../../chunks/tslib.es6.js";import"../../geometry.js";import t from"../../Graphic.js";import"../../symbols.js";import{isSome as i}from"../../core/arrayUtils.js";import s from"../../core/Error.js";import r from"../../core/Logger.js";import{debounce as o,isAbortError as a}from"../../core/promiseUtils.js";import n from"../../core/ReactiveSet.js";import{watch as l,when as h,sync as u}from"../../core/reactiveUtils.js";import{property as c}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import{subclass as d}from"../../core/accessorSupport/decorators/subclass.js";import{initializeProjection as p,project as g}from"../../geometry/projection.js";import{getPointFromGeometry as f}from"../../geometry/support/geometryUtils.js";import{geographicToWebMercator as m}from"../../geometry/support/webMercatorUtils.js";import y from"../../layers/Layer.js";import{fallbackObjectIDAttribute as w}from"../../layers/LayerConstants.js";import{getDisplayedSymbol as F}from"../../symbols/support/symbolUtils.js";import{highlightsSupported as v}from"../../views/support/layerViewUtils.js";import _ from"../Feature/FeatureViewModel.js";import{ActionsCollection as b,zoomToFeature as C,zoomToClusteredFeatures as P,browseClusteredFeatures as E}from"../Popup/actions.js";import{triggerAction as j,isClusterFeature as M,removeClusteredFeaturesForBrowsing as A,displayClusterExtent as L,browseAggregateFeatures as V,getSelectedTarget as I}from"../Popup/actionUtils.js";import S from"../support/AnchorElementViewModel.js";import{GoToMixin as O}from"../support/GoTo.js";import x from"../../symbols/SimpleFillSymbol.js";import T from"../../geometry/Point.js";const H=()=>[C.clone()],B=()=>[P.clone(),E.clone()];let R=null;function U(e,t){return"building-scene"===e||"2d"===t&&("map-image"===e||"tile"===e||"imagery"===e||"imagery-tile"===e)}let G=class extends(O(S)){constructor(e){super(e),this._pendingPromises=new n,this._fetchFeaturesController=null,this._highlightSelectedFeaturePromise=null,this._highlightActiveFeaturePromise=null,this._selectedClusterFeature=null,this._locationScaleHandle=null,this.actions=new b,this.activeFeature=null,this.autoCloseEnabled=!1,this.autoOpenEnabled=!0,this.browseClusterEnabled=!1,this.content=null,this.defaultPopupTemplateEnabled=!1,this.featurePage=null,this.featuresPerPage=20,this.featureMenuOpen=!1,this.featureViewModelAbilities=null,this.featureViewModels=[],this.highlightEnabled=!0,this.includeDefaultActions=!0,this.selectedClusterBoundaryFeature=new t({symbol:new x({outline:{width:1.5,color:"cyan"},style:"none"})}),this.title=null,this.updateLocationEnabled=!1,this.view=null,this.visible=!1,this.zoomFactor=4,this.zoomToLocation=null,this._debouncedLocationUpdate=o((async e=>{const{view:t}=this,i=this.selectedFeature?.geometry?.type,s=this.location??e;if("mesh"!==i&&t&&s&&this.selectedFeature)if("point"!==i)try{const{pendingFeatures:e}=await this._fetchFeaturesWithController({mapPoint:s}),i=(await Promise.all(e)).flat().filter(Boolean);if(!i.length)return;if(i.length!==this.features.length){const e=this._getHighlightLayer(this.selectedFeature),t="imagery"===e?.type?void 0:e&&"objectIdField"in e?e.objectIdField||w:null;if(t){const s=this.selectedFeature.getObjectId(),r=i.findIndex((i=>{const r=this._getHighlightLayer(i);return r?.uid===e?.uid&&i.attributes[t]===s}));this.features=i,this.selectedFeatureIndex=r}}const r=i[this.selectedFeatureIndex]?.geometry,o=("mesh"!==r?.type?r:null)??this.selectedFeature.geometry,a=o?g(o,t.spatialReference):null;if(!a)return;R||(R=await import("../../geometry/geometryEngineAsync.js")),await R.intersects(a,s)||(this.location=(await R.nearestCoordinate(a,s)).coordinate??s)}catch(o){a(o)||r.getLogger(this).error(o)}else this.location=f(this.selectedFeature.geometry)??s}))}initialize(){this.addHandles([this.on("view-change",(()=>this._autoClose())),l((()=>[this.highlightEnabled,this.selectedFeature,this.visible,this.view]),(()=>this._highlightSelectedFeature())),l((()=>[this.highlightEnabled,this.activeFeature,this.visible,this.view]),(()=>this._highlightActiveFeature())),l((()=>this.view?.animation?.state),(e=>this._animationStateChange(e))),l((()=>this.location),(e=>this._locationChange(e))),l((()=>this.selectedFeature),(e=>this._selectedFeatureChange(e))),l((()=>[this.selectedFeatureIndex,this.featureCount,this.featuresPerPage]),(()=>this._selectedFeatureIndexChange())),l((()=>[this.featurePage,this.selectedFeatureIndex,this.featureCount,this.featuresPerPage,this.featureViewModels]),(()=>this._setGraphicOnFeatureViewModels())),l((()=>this.featureViewModels),(()=>this._featureViewModelsChange())),this.on("trigger-action",(e=>j({event:e,viewModel:this,view:this.view}))),h((()=>!this.waitingForResult),(()=>this._waitingForResultChange()),u),l((()=>[this.features,this.view?.map,this.view?.spatialReference,this.view?.timeZone]),(()=>this._updateFeatureVMs())),l((()=>this.view?.scale),(()=>this._viewScaleChange())),h((()=>!this.visible),(()=>this.browseClusterEnabled=!1)),l((()=>this.browseClusterEnabled),(e=>e?this.enableClusterBrowsing():this.disableClusterBrowsing()))])}destroy(){this._cancelFetchingFeatures(),this._pendingPromises.clear(),this.browseClusterEnabled=!1,this.view=null,this._locationScaleHandle?.remove(),this._locationScaleHandle=null}get active(){return!(!this.visible||this.waitingForResult)}get allActions(){const e=this._get("allActions")||new b;e.removeAll();const{actions:t,defaultActions:i,defaultPopupTemplateEnabled:s,includeDefaultActions:r,selectedFeature:o}=this,a=r?i.concat(t):t,n=o&&("function"==typeof o.getEffectivePopupTemplate&&o.getEffectivePopupTemplate(s)||o.popupTemplate),l=n?.actions,h=n?.overwriteActions?l:l?.concat(a)??a;return h?.filter(Boolean).forEach((t=>e.add(t))),e}get defaultActions(){const e=this._get("defaultActions")||new b;return e.removeAll(),e.addMany(M(this.selectedFeature)?B():H()),e}get featureCount(){return this.features.length}set features(e){const t=e||[];this._set("features",t);const{pendingPromisesCount:i,promiseCount:s,selectedFeatureIndex:r}=this,o=s&&t.length;o&&i&&-1===r?this.selectedFeatureIndex=0:o&&-1!==r||(this.selectedFeatureIndex=t.length?0:-1)}set location(e){let t=e;const i=this.view?.spatialReference?.isWebMercator,s=e?.spatialReference?.isWGS84;s&&i&&(t=m(e)),this._set("location",t)}get pendingPromisesCount(){return this._pendingPromises.size}get promiseCount(){return this.promises.length}get promises(){return this._get("promises")||[]}set promises(e){this._pendingPromises.clear(),this.features=[],Array.isArray(e)&&e.length?(this._set("promises",e),(e=e.slice(0)).forEach((e=>this._pendingPromises.add(e))),e.reduce(((e,t)=>e.finally((()=>t.then((e=>{this._pendingPromises.has(t)&&this._updateFeatures(e)})).finally((()=>this._pendingPromises.delete(t))).catch((()=>{}))))),Promise.resolve())):this._set("promises",[])}get selectedFeature(){const{features:e,selectedFeatureIndex:t}=this;if(-1===t)return null;return e[t]||null}get selectedFeatureIndex(){const e=this._get("selectedFeatureIndex");return"number"==typeof e?e:-1}set selectedFeatureIndex(e){const{featureCount:t}=this;e=isNaN(e)||e<-1||!t?-1:(e+t)%t,this.activeFeature=null,this._set("selectedFeatureIndex",e)}get selectedFeatureViewModel(){return this.featureViewModels[this.selectedFeatureIndex]||null}get state(){return this.view?.ready?"ready":"disabled"}get waitingForContents(){return this.featureViewModels.some((e=>e.waitingForContent))}get waitingForResult(){return!(!(!!this._fetchFeaturesController||this.pendingPromisesCount>0)||0!==this.featureCount)}centerAtLocation(){const{view:e}=this,t=I(this);return t&&e?this.callGoTo({target:{target:t,scale:e.scale}}):Promise.reject(new s("center-at-location:invalid-target-or-view","Cannot center at a location without a target and view.",{target:t,view:e}))}zoomTo(e){return this.callGoTo(e)}clear(){this.set({promises:[],features:[],content:null,title:null,location:null,activeFeature:null})}fetchFeatures(e,t){const{view:i}=this;if(!i||!e)throw new s("fetch-features:invalid-screenpoint-or-view","Cannot fetch features without a screenPoint and view.",{screenPoint:e,view:i});return i.fetchPopupFeatures(e,{pointerType:t?.event?.pointerType,defaultPopupTemplateEnabled:this.defaultPopupTemplateEnabled,signal:t?.signal})}open(e){const t={updateLocationEnabled:!1,promises:[],fetchFeatures:!1,...e,visible:!0},{fetchFeatures:i}=t;delete t.fetchFeatures,i&&this._setFetchFeaturesPromises(t.location);const s=["actionsMenuOpen","collapsed"];for(const r of s)delete t[r];this.set(t)}triggerAction(e){const t=this.allActions.at(e);t&&!t.disabled&&this.emit("trigger-action",{action:t})}next(){return this.selectedFeatureIndex++,this}previous(){return this.selectedFeatureIndex--,this}disableClusterBrowsing(){A(this),this._clearBrowsedClusterGraphics()}async enableClusterBrowsing(){const{view:e,selectedFeature:t}=this;"2d"===e?.type?M(t)?(await L(this),await V(this)):r.getLogger(this).warn("enableClusterBrowsing:invalid-selectedFeature: Selected feature must represent an aggregate/cluster graphic.",t):r.getLogger(this).warn("enableClusterBrowsing:invalid-view: View must be 2d MapView.",t)}handleViewClick(e){this.autoOpenEnabled&&this._fetchFeaturesAndOpen(e)}_animationStateChange(e){this.zoomToLocation||(C.disabled="waiting-for-target"===e)}_clearBrowsedClusterGraphics(){const e=[this.selectedClusterBoundaryFeature,this._selectedClusterFeature].filter(i);this.view?.graphics?.removeMany(e),this._selectedClusterFeature=null,this.selectedClusterBoundaryFeature.geometry=null}_viewScaleChange(){if(M(this.selectedFeature))return this.browseClusterEnabled=!1,this.visible=!1,void this.clear();this.browseClusterEnabled&&(this.features=this.selectedFeature?[this.selectedFeature]:[])}_locationChange(e){const{selectedFeature:t,updateLocationEnabled:i}=this;i&&e&&(!t||t.geometry)&&this.centerAtLocation()}_selectedFeatureIndexChange(){this.featurePage=this.featureCount>1?Math.floor(this.selectedFeatureIndex/this.featuresPerPage)+1:null}_featureViewModelsChange(){this.featurePage=this.featureCount>1?1:null}_setGraphicOnFeatureViewModels(){const{features:e,featureCount:t,featurePage:i,featuresPerPage:s,featureViewModels:r}=this;if(null===i)return;const o=((i-1)*s+t)%t,a=o+s;r.slice(o,a).forEach(((t,i)=>{t&&(t.graphic??=e[o+i])}))}async _selectedFeatureChange(e){const{location:t,updateLocationEnabled:i,view:s}=this;if(e&&s){if(this.browseClusterEnabled){if(this._selectedClusterFeature&&(s.graphics.remove(this._selectedClusterFeature),this._selectedClusterFeature=null),M(e))return;return e.symbol=await F(e),this._selectedClusterFeature=e,void s.graphics.add(this._selectedClusterFeature)}if(e.symbol=await F(e),!i&&t||!e.geometry){if(i&&!e.geometry){await this.centerAtLocation();const e=s.center?.clone();e&&(this.location=e)}}else this.location=f(e.geometry)}}_waitingForResultChange(){!this.featureCount&&this.promises&&(this.visible=!1)}async _setFetchFeaturesPromises(e){const{pendingFeatures:t}=await this._fetchFeaturesWithController({mapPoint:e});this.promises=t}_destroyFeatureVMs(){this.featureViewModels.forEach((e=>e&&!e.destroyed&&e.destroy())),this._set("featureViewModels",[])}_updateFeatureVMs(){const{selectedFeature:e,features:t,featureViewModels:i,view:s}=this;if(M(e)||(this.browseClusterEnabled=!1),this._destroyFeatureVMs(),!t?.length)return;const r=i.slice(0),o=[];t.forEach(((t,i)=>{if(!t)return;let a=null;if(r.some(((e,i)=>(e&&e.graphic===t&&(a=e,r.splice(i,1)),!!a))),a)o[i]=a;else{const r=new _({abilities:this.featureViewModelAbilities,defaultPopupTemplateEnabled:this.defaultPopupTemplateEnabled,spatialReference:s?.spatialReference,graphic:t===e?t:null,location:this.location,map:s?.map,view:s});o[i]=r}})),r.forEach((e=>e&&!e.destroyed&&e.destroy())),this._set("featureViewModels",o)}async _getScreenPoint(e,t){const{view:i}=this;await(i?.when());const s=e?.spatialReference,r=i?.spatialReference;return s&&r?(await p(s,r,null,t),i.toScreen(e)):null}_cancelFetchingFeatures(){const e=this._fetchFeaturesController;e&&e.abort(),this._fetchFeaturesController=null}async _projectScreenPointAndFetchFeatures({mapPoint:e,screenPoint:t,event:i,signal:s}){return this.fetchFeatures(t??await this._getScreenPoint(e??this.location,{signal:s}),{signal:s,event:i})}_fetchFeaturesWithController({mapPoint:e,screenPoint:t,event:i}){this._cancelFetchingFeatures();const s=new AbortController,{signal:r}=s;this._fetchFeaturesController=s;const o=this._projectScreenPointAndFetchFeatures({mapPoint:e,screenPoint:t,signal:r,event:i});return o.catch((()=>{})).then((()=>{this._fetchFeaturesController=null})),o}async _fetchFeaturesAndOpen(e){const{mapPoint:t,screenPoint:i}=e,{view:s}=this;this._locationScaleHandle?.remove(),this._locationScaleHandle=l((()=>this.view?.scale),(()=>this._debouncedLocationUpdate(t).catch((e=>{a(e)||r.getLogger(this).error(e)}))));const{pendingFeatures:o}=await this._fetchFeaturesWithController({mapPoint:t,screenPoint:i,event:e});s?.popup&&"open"in s.popup&&s.popup.open({location:t??void 0,promises:o})}_autoClose(){this.autoCloseEnabled&&(this.visible=!1)}async _getLayerView(e,t){return await e.when(),e.whenLayerView(t)}_getHighlightLayer(e){const{layer:t,sourceLayer:i}=e;return i&&"layer"in i&&i.layer?i.layer:"map-notes"===i?.type||"subtype-group"===i?.type?i:t}_getHighlightTarget(e,t,i){if(U(t.type,i))return e;const s=e.getObjectId();if(null!=s)return s;const r="imagery"===t.type?void 0:"objectIdField"in t?t.objectIdField||w:null,o=e.attributes;return o&&r&&o[r]||e}_mapIncludesLayer(e){return!!this.view?.map?.allLayers?.includes(e)}async _highlightActiveFeature(){const e="highlight-active-feature";this.removeHandles(e);const{highlightEnabled:t,view:i,activeFeature:s,visible:r}=this;if(!(s&&i&&t&&r))return;const o=this._getHighlightLayer(s);if(!(o&&o instanceof y&&this._mapIncludesLayer(o)))return;const a=this._getLayerView(i,o);this._highlightActiveFeaturePromise=a;const n=await a;if(!(n&&v(n)&&this._highlightActiveFeaturePromise===a&&this.activeFeature&&this.highlightEnabled))return;const l=n.highlight(this._getHighlightTarget(s,o,i.type));this.addHandles(l,e)}async _highlightSelectedFeature(){const e="highlight-selected-feature";this.removeHandles(e);const{selectedFeature:t,highlightEnabled:i,view:s,visible:r}=this;if(!(t&&s&&i&&r))return;const o=this._getHighlightLayer(t);if(!(o&&o instanceof y&&this._mapIncludesLayer(o)))return;const a=this._getLayerView(s,o);this._highlightSelectedFeaturePromise=a;const n=await a;if(!(n&&v(n)&&this._highlightSelectedFeaturePromise===a&&this.selectedFeature&&this.highlightEnabled&&this.visible))return;const l=n.highlight(this._getHighlightTarget(t,o,s.type));this.addHandles(l,e)}_updateFeatures(e){const{features:t}=this,i=e.filter((e=>!t.includes(e)));i?.length&&(this.features=t.concat(i))}};e([c()],G.prototype,"_fetchFeaturesController",void 0),e([c({type:b})],G.prototype,"actions",void 0),e([c({readOnly:!0})],G.prototype,"active",null),e([c()],G.prototype,"activeFeature",void 0),e([c({readOnly:!0})],G.prototype,"allActions",null),e([c()],G.prototype,"autoCloseEnabled",void 0),e([c()],G.prototype,"autoOpenEnabled",void 0),e([c()],G.prototype,"browseClusterEnabled",void 0),e([c()],G.prototype,"content",void 0),e([c({type:b,readOnly:!0})],G.prototype,"defaultActions",null),e([c({type:Boolean})],G.prototype,"defaultPopupTemplateEnabled",void 0),e([c({readOnly:!0})],G.prototype,"featureCount",null),e([c()],G.prototype,"featurePage",void 0),e([c({value:[]})],G.prototype,"features",null),e([c()],G.prototype,"featuresPerPage",void 0),e([c()],G.prototype,"featureMenuOpen",void 0),e([c()],G.prototype,"featureViewModelAbilities",void 0),e([c({readOnly:!0})],G.prototype,"featureViewModels",void 0),e([c()],G.prototype,"highlightEnabled",void 0),e([c()],G.prototype,"includeDefaultActions",void 0),e([c({type:T})],G.prototype,"location",null),e([c({readOnly:!0})],G.prototype,"pendingPromisesCount",null),e([c({readOnly:!0})],G.prototype,"promiseCount",null),e([c()],G.prototype,"promises",null),e([c({readOnly:!0})],G.prototype,"selectedClusterBoundaryFeature",void 0),e([c({value:null,readOnly:!0})],G.prototype,"selectedFeature",null),e([c({value:-1})],G.prototype,"selectedFeatureIndex",null),e([c({readOnly:!0})],G.prototype,"selectedFeatureViewModel",null),e([c({readOnly:!0})],G.prototype,"state",null),e([c()],G.prototype,"title",void 0),e([c()],G.prototype,"updateLocationEnabled",void 0),e([c()],G.prototype,"view",void 0),e([c()],G.prototype,"visible",void 0),e([c({readOnly:!0})],G.prototype,"waitingForContents",null),e([c({readOnly:!0})],G.prototype,"waitingForResult",null),e([c()],G.prototype,"zoomFactor",void 0),e([c()],G.prototype,"zoomToLocation",void 0),e([c()],G.prototype,"centerAtLocation",null),G=e([d("esri.widgets.Features.FeaturesViewModel")],G);const z=G;export{z as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.29/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../chunks/tslib.es6.js";import i from"../../Camera.js";import"../../geometry.js";import t from"../../Ground.js";import o from"../../Map.js";import a from"../../request.js";import r from"../../core/Collection.js";import s from"../../core/Error.js";import n from"../../core/Evented.js";import{JSONMap as h}from"../../core/jsonMap.js";import{destroyMaybe as m}from"../../core/maybe.js";import{isAbortError as l,waitTick as d}from"../../core/promiseUtils.js";import{watch as c,when as p,syncAndInitial as g}from"../../core/reactiveUtils.js";import{property as _}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{enumeration as u}from"../../core/accessorSupport/decorators/enumeration.js";import{subclass as y}from"../../core/accessorSupport/decorators/subclass.js";import v from"../../layers/GraphicsLayer.js";import{convertSphereVertexToPixelLocation as f}from"../../layers/orientedImagery/transformations/utils.js";import w from"../../views/SceneView.js";import V from"../Zoom.js";import{logAndThrow as C,getMissingPropertyErrorName as j,getMissingPropertyErrorMessage as P}from"../OrientedImageryViewer/utils.js";import{defaultImageSphereCenter as z}from"./constants.js";import R from"./PanoramicZoomConditions.js";import H from"./PanoramicZoomViewModel.js";import{meshToGraphic as b,createImageSphere as S}from"./utils.js";import M from"../../geometry/SpatialReference.js";const x={autoLoad:"auto-load",default:"default",navigation:"navigation",fovConstraint:"fov-constraint",clickAction:"image-click-action"};let O=class extends n.EventedAccessor{constructor(e){super(e),this._startPosition=null,this._targetPosition=null,this._graphics=new v({elevationInfo:{mode:"relative-to-ground"}}),this._imageGraphic=null,this._loadController=null,this._map=new o({ground:new t({opacity:0,navigationConstraint:null}),layers:new r([this._graphics])}),this._zoomViewModel=null,this.autoLoad=!0,this.clickAction="none",this.maxHFOV=120,this.minHFOV=50,this.imageSize=null,this.imageSource=null,this.pitch=90,this.state="ready",this.yaw=0,this._addNavigationHandles=()=>{this.imageRenderer.basemapTerrain.suspended=!0,this.imageRenderer.constraints.tilt.max=180,this.removeHandles(x.navigation),this.addHandles([this.imageRenderer.on("mouse-wheel",this._handleWheel),this.imageRenderer.on("double-click",this._handleDoubleClick),this.imageRenderer.on("drag",this._handleDrag),this.imageRenderer.on("key-down",(e=>{const i=["+","-","Shift","_","=","ArrowUp","ArrowDown","ArrowRight","ArrowLeft"],t=e.key;i.includes(t)&&e.stopPropagation()}))],x.navigation)},this._addHFOVHandles=()=>{this.removeHandles(x.fovConstraint),this.addHandles(c((()=>[this.maxHFOV,this.minHFOV]),(()=>{this._zoomViewModel&&(this._zoomViewModel.panoramicZoomConditions=new R({view:this.imageRenderer,maxFOV:this.maxHFOV,minFOV:this.minHFOV}))}),g),x.fovConstraint)},this._addZoomHandles=()=>{this._zoomViewModel=new H({view:this.imageRenderer,panoramicZoomConditions:new R({maxFOV:this.maxHFOV,minFOV:this.minHFOV})});const e=new V({viewModel:this._zoomViewModel});this.imageRenderer.ui.add(e,"top-left"),this._addHFOVHandles()},this._cancelLoadWithController=()=>{this._loadController?.abort(),this._loadController=null},this._handleDoubleClick=e=>{e.stopPropagation(),e.native.ctrlKey?this._zoomOut():this._zoomIn()},this._handleDrag=e=>{e.stopPropagation();const{action:i,x:t,y:o}=e;switch(i){case"start":this._startPosition=this._targetPosition={x:t,y:o};break;case"update":this._targetPosition={x:t,y:o},this._updateCameraHeadingAndTilt()}},this._handleImageClick=e=>{if("image-loaded"===this.state&&this.imageRenderer.ready)switch(this.clickAction){case"emit":e.stopPropagation(),this.emit("click",e);break;case"hittest":e.stopPropagation(),e.async((async()=>{const i=await this.imageRenderer.hitTest(e.screenPoint,{include:this._graphics});this.emit("hittest-response",i)}));break;case"pixel-location":{if(e.stopPropagation(),!this.imageSize||!e.mapPoint)return void this.emit("pixel-location",null);const i=f(e.mapPoint,this.imageSize[0],this.imageSize[1]);this.emit("pixel-location",{...i,spatialReference:M.WebMercator,meshVertex:e.mapPoint});break}}},this._handleWheel=e=>{const i=e.deltaX??e.native.deltaX;e.stopPropagation(),i>0||e.deltaY>0?this._zoomOut():this._zoomIn()},this._loadWithController=()=>{this._cancelLoadWithController(),this._loadController=new AbortController,this.loadImage(this._loadController)},this._zoomIn=()=>this._zoomViewModel?.zoomIn(),this._zoomOut=()=>this._zoomViewModel?.zoomOut(),this.addGraphic=(e,i)=>"image-loaded"===this.state&&!this._graphics.graphics.includes(e)&&(this._graphics.graphics.add(e,i),!0),this.addManyGraphics=e=>{if("image-loaded"!==this.state)return!1;const i=e.filter((e=>!this._graphics.graphics.includes(e)));return this._graphics.graphics.addMany(i),!0},this.clearGraphics=()=>{this._graphics.graphics.removeAll()},this.clearImage=()=>{this.imageSize=null,this._removeImageSphere()},this.removeGraphic=e=>!("image-loaded"!==this.state||!this._graphics.graphics.includes(e))&&(this._graphics.remove(e),!0),this.removeManyGraphics=e=>{if("image-loaded"!==this.state)return!1;const i=e.filter((e=>this._graphics.graphics.includes(e)));return this._graphics.removeMany(i),!0},this._imageRenderer=new w({map:this._map,viewingMode:"local",camera:{position:z},environment:{atmosphereEnabled:!1,starsEnabled:!1,lighting:{type:"virtual"}},popupEnabled:!1,spatialReference:M.WebMercator,ui:{components:["attribution"]}})}initialize(){this.addHandles([c((()=>this.imageSource),(()=>{this.state="initialized",this.imageSource&&this.autoLoad&&this._loadWithController()}),g),c((()=>this.fov),(()=>{this._reloadCamera()}),g),c((()=>this.yaw),(e=>{this.camera.heading=e,this._reloadCamera()}),g),c((()=>this.pitch),(e=>{this.camera.tilt=e,this._reloadCamera()}),g),p((()=>this.imageRenderer.ready),(()=>{this._addNavigationHandles(),this._addZoomHandles()}),g),c((()=>this.clickAction),(e=>{this.removeHandles(x.clickAction),"none"!==e&&this.addHandles(this.imageRenderer.on("click",this._handleImageClick))}),g)],x.default)}get camera(){return this.imageRenderer.camera}set camera(e){e&&(this.imageRenderer.camera=e.clone())}get fov(){return this.camera.fov}set fov(e){Number.isFinite(e)&&this._zoomViewModel?.zoomTo(e)}get imageRenderer(){return this._imageRenderer}async _loadImageInternal(e,i){let t;this._removeImageSphere(),this.state="image-loading";try{t=(await a(e,{responseType:"image",...i})).data}catch(o){throw l(o)?this.state="image-load-aborted":this.state="image-load-error",o}return this._updateImageSphere(t,i)}_reloadCamera(){this.camera=this.camera.clone()}_removeImageSphere(){this._imageGraphic&&(this._graphics.remove(this._imageGraphic),this._imageGraphic=m(this._imageGraphic)),this.state="ready"}_updateCameraHeadingAndTilt(){if(!this._startPosition||!this._targetPosition)return;const e=this.camera.heading+(this._startPosition.x-this._targetPosition.x)/this.imageRenderer.width*this.camera.fov;this.yaw=(e+360)%360;const i=this.camera.tilt-(this._startPosition.y-this._targetPosition.y)/this.imageRenderer.height*this.imageRenderer.camera.fov;this.pitch=Math.min(179.5,Math.max(.5,i)),this._startPosition=this._targetPosition}async _updateImageSphere(e,i){return await d(i),this._imageGraphic=b(S(e)),this.imageSize=[e.width,e.height],this._graphics.add(this._imageGraphic),this.state="image-loaded",this._imageGraphic.geometry}async loadImage(e){return this.imageSize=null,this.imageSource?this._loadImageInternal(this.imageSource,e):C(this.declaredClass,new s(j("panoramic-viewer"),P("PanoramicViewerViewModel","imageSource")))}};e([_()],O.prototype,"_graphics",void 0),e([_()],O.prototype,"_imageGraphic",void 0),e([_()],O.prototype,"_imageRenderer",void 0),e([_()],O.prototype,"_loadController",void 0),e([_()],O.prototype,"_map",void 0),e([_()],O.prototype,"_zoomViewModel",void 0),e([_({type:Boolean})],O.prototype,"autoLoad",void 0),e([_({type:i})],O.prototype,"camera",null),e([u(new h({emit:"emit",hittest:"hittest",none:"none","pixel-location":"pixel-location"}))],O.prototype,"clickAction",void 0),e([_({type:Number})],O.prototype,"fov",null),e([_({type:Number})],O.prototype,"maxHFOV",void 0),e([_({type:Number})],O.prototype,"minHFOV",void 0),e([_()],O.prototype,"imageSize",void 0),e([_()],O.prototype,"imageSource",void 0),e([_({type:Number})],O.prototype,"pitch",void 0),e([_({readOnly:!0})],O.prototype,"imageRenderer",null),e([_()],O.prototype,"state",void 0),e([_({type:Number})],O.prototype,"yaw",void 0),O=e([y("esri.widgets.PanoramicViewer.PanoramicViewerViewModel")],O);const k=O;export{k as default};
5
+ import{_ as e}from"../../chunks/tslib.es6.js";import i from"../../Camera.js";import"../../geometry.js";import t from"../../Ground.js";import o from"../../Map.js";import a from"../../request.js";import r from"../../core/Collection.js";import s from"../../core/Error.js";import n from"../../core/Evented.js";import{JSONMap as h}from"../../core/jsonMap.js";import{destroyMaybe as m}from"../../core/maybe.js";import{isAbortError as l,waitTick as d}from"../../core/promiseUtils.js";import{watch as c,when as p,syncAndInitial as g}from"../../core/reactiveUtils.js";import{property as _}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{enumeration as u}from"../../core/accessorSupport/decorators/enumeration.js";import{subclass as y}from"../../core/accessorSupport/decorators/subclass.js";import v from"../../layers/GraphicsLayer.js";import{convertSphereVertexToPixelLocation as f}from"../../layers/orientedImagery/transformations/utils.js";import w from"../../views/SceneView.js";import V from"../Zoom.js";import{logAndThrow as C,getMissingPropertyErrorName as j,getMissingPropertyErrorMessage as P}from"../OrientedImageryViewer/utils.js";import{defaultImageSphereCenter as z}from"./constants.js";import R from"./PanoramicZoomConditions.js";import H from"./PanoramicZoomViewModel.js";import{meshToGraphic as b,createImageSphere as S}from"./utils.js";import M from"../../geometry/SpatialReference.js";const x={autoLoad:"auto-load",default:"default",navigation:"navigation",fovConstraint:"fov-constraint",clickAction:"image-click-action"};let O=class extends n.EventedAccessor{constructor(e){super(e),this._startPosition=null,this._targetPosition=null,this._graphics=new v({elevationInfo:{mode:"relative-to-ground"}}),this._imageGraphic=null,this._loadController=null,this._map=new o({ground:new t({opacity:0,navigationConstraint:null}),layers:new r([this._graphics])}),this._zoomViewModel=null,this.autoLoad=!1,this.clickAction="none",this.maxHFOV=120,this.minHFOV=50,this.imageSize=null,this.imageSource=null,this.pitch=90,this.state="ready",this.yaw=0,this._addNavigationHandles=()=>{this.imageRenderer.basemapTerrain.suspended=!0,this.imageRenderer.constraints.tilt.max=180,this.removeHandles(x.navigation),this.addHandles([this.imageRenderer.on("mouse-wheel",this._handleWheel),this.imageRenderer.on("double-click",this._handleDoubleClick),this.imageRenderer.on("drag",this._handleDrag),this.imageRenderer.on("key-down",(e=>{const i=["+","-","Shift","_","=","ArrowUp","ArrowDown","ArrowRight","ArrowLeft"],t=e.key;i.includes(t)&&e.stopPropagation()}))],x.navigation)},this._addHFOVHandles=()=>{this.removeHandles(x.fovConstraint),this.addHandles(c((()=>[this.maxHFOV,this.minHFOV]),(()=>{this._zoomViewModel&&(this._zoomViewModel.panoramicZoomConditions=new R({view:this.imageRenderer,maxFOV:this.maxHFOV,minFOV:this.minHFOV}))}),g),x.fovConstraint)},this._addZoomHandles=()=>{this._zoomViewModel=new H({view:this.imageRenderer,panoramicZoomConditions:new R({maxFOV:this.maxHFOV,minFOV:this.minHFOV})});const e=new V({viewModel:this._zoomViewModel});this.imageRenderer.ui.add(e,"top-left"),this._addHFOVHandles()},this._cancelLoadWithController=()=>{this._loadController?.abort(),this._loadController=null},this._handleDoubleClick=e=>{e.stopPropagation(),e.native.ctrlKey?this._zoomOut():this._zoomIn()},this._handleDrag=e=>{e.stopPropagation();const{action:i,x:t,y:o}=e;switch(i){case"start":this._startPosition=this._targetPosition={x:t,y:o};break;case"update":this._targetPosition={x:t,y:o},this._updateCameraHeadingAndTilt()}},this._handleImageClick=e=>{if("image-loaded"===this.state&&this.imageRenderer.ready)switch(this.clickAction){case"emit":e.stopPropagation(),this.emit("click",e);break;case"hittest":e.stopPropagation(),e.async((async()=>{const i=await this.imageRenderer.hitTest(e.screenPoint,{include:this._graphics});this.emit("hittest-response",i)}));break;case"pixel-location":{if(e.stopPropagation(),!this.imageSize||!e.mapPoint)return void this.emit("pixel-location",null);const i=f(e.mapPoint,this.imageSize[0],this.imageSize[1]);this.emit("pixel-location",{...i,spatialReference:M.WebMercator,meshVertex:e.mapPoint});break}}},this._handleWheel=e=>{const i=e.deltaX??e.native.deltaX;e.stopPropagation(),i>0||e.deltaY>0?this._zoomOut():this._zoomIn()},this._loadWithController=()=>{this._cancelLoadWithController(),this._loadController=new AbortController,this.loadImage(this._loadController)},this._zoomIn=()=>this._zoomViewModel?.zoomIn(),this._zoomOut=()=>this._zoomViewModel?.zoomOut(),this.addGraphic=(e,i)=>"image-loaded"===this.state&&!this._graphics.graphics.includes(e)&&(this._graphics.graphics.add(e,i),!0),this.addManyGraphics=e=>{if("image-loaded"!==this.state)return!1;const i=e.filter((e=>!this._graphics.graphics.includes(e)));return this._graphics.graphics.addMany(i),!0},this.clearGraphics=()=>{this._graphics.graphics.removeAll()},this.clearImage=()=>{this.imageSize=null,this._removeImageSphere()},this.removeGraphic=e=>!("image-loaded"!==this.state||!this._graphics.graphics.includes(e))&&(this._graphics.remove(e),!0),this.removeManyGraphics=e=>{if("image-loaded"!==this.state)return!1;const i=e.filter((e=>this._graphics.graphics.includes(e)));return this._graphics.removeMany(i),!0},this._imageRenderer=new w({map:this._map,viewingMode:"local",camera:{position:z},environment:{atmosphereEnabled:!1,starsEnabled:!1,lighting:{type:"virtual"}},popupEnabled:!1,spatialReference:M.WebMercator,ui:{components:["attribution"]}})}initialize(){this.addHandles([c((()=>this.imageSource),(()=>{this.state="initialized",this.imageSource&&this.autoLoad&&this._loadWithController()}),g),c((()=>this.fov),(()=>{this._reloadCamera()}),g),c((()=>this.yaw),(e=>{this.camera.heading=e,this._reloadCamera()}),g),c((()=>this.pitch),(e=>{this.camera.tilt=e,this._reloadCamera()}),g),p((()=>this.imageRenderer.ready),(()=>{this._addNavigationHandles(),this._addZoomHandles()}),g),c((()=>this.clickAction),(e=>{this.removeHandles(x.clickAction),"none"!==e&&this.addHandles(this.imageRenderer.on("click",this._handleImageClick))}),g)],x.default)}get camera(){return this.imageRenderer.camera}set camera(e){e&&(this.imageRenderer.camera=e.clone())}get fov(){return this.camera.fov}set fov(e){Number.isFinite(e)&&this._zoomViewModel?.zoomTo(e)}get imageRenderer(){return this._imageRenderer}async _loadImageInternal(e,i){let t;this._removeImageSphere(),this.state="image-loading";try{t=(await a(e,{responseType:"image",...i})).data}catch(o){throw l(o)?this.state="image-load-aborted":this.state="image-load-error",o}return this._updateImageSphere(t,i)}_reloadCamera(){this.camera=this.camera.clone()}_removeImageSphere(){this._imageGraphic&&(this._graphics.remove(this._imageGraphic),this._imageGraphic=m(this._imageGraphic)),this.state="ready"}_updateCameraHeadingAndTilt(){if(!this._startPosition||!this._targetPosition)return;const e=this.camera.heading+(this._startPosition.x-this._targetPosition.x)/this.imageRenderer.width*this.camera.fov;this.yaw=(e+360)%360;const i=this.camera.tilt-(this._startPosition.y-this._targetPosition.y)/this.imageRenderer.height*this.imageRenderer.camera.fov;this.pitch=Math.min(179.5,Math.max(.5,i)),this._startPosition=this._targetPosition}async _updateImageSphere(e,i){return await d(i),this._imageGraphic=b(S(e)),this.imageSize=[e.width,e.height],this._graphics.add(this._imageGraphic),this.state="image-loaded",this._imageGraphic.geometry}async loadImage(e){return this.imageSize=null,this.imageSource?this._loadImageInternal(this.imageSource,e):C(this.declaredClass,new s(j("panoramic-viewer"),P("PanoramicViewerViewModel","imageSource")))}};e([_()],O.prototype,"_graphics",void 0),e([_()],O.prototype,"_imageGraphic",void 0),e([_()],O.prototype,"_imageRenderer",void 0),e([_()],O.prototype,"_loadController",void 0),e([_()],O.prototype,"_map",void 0),e([_()],O.prototype,"_zoomViewModel",void 0),e([_({type:Boolean})],O.prototype,"autoLoad",void 0),e([_({type:i})],O.prototype,"camera",null),e([u(new h({emit:"emit",hittest:"hittest",none:"none","pixel-location":"pixel-location"}))],O.prototype,"clickAction",void 0),e([_({type:Number})],O.prototype,"fov",null),e([_({type:Number})],O.prototype,"maxHFOV",void 0),e([_({type:Number})],O.prototype,"minHFOV",void 0),e([_()],O.prototype,"imageSize",void 0),e([_()],O.prototype,"imageSource",void 0),e([_({type:Number})],O.prototype,"pitch",void 0),e([_({readOnly:!0})],O.prototype,"imageRenderer",null),e([_()],O.prototype,"state",void 0),e([_({type:Number})],O.prototype,"yaw",void 0),O=e([y("esri.widgets.PanoramicViewer.PanoramicViewerViewModel")],O);const k=O;export{k as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.29/esri/copyright.txt for details.
4
4
  */
5
- import t from"../../Graphic.js";import e from"../../geometry/Mesh.js";import r from"../../geometry/support/MeshMaterial.js";import o from"../../geometry/support/MeshTexture.js";import{defaultImageSphereSize as s,defaultImageSphereCenter as i}from"./constants.js";function u(t,u=i,n=s){const m=u.clone();m.z=-s/2;const c=e.createSphere(m,{size:n,densificationFactor:2,vertexSpace:"local",material:new r({colorTexture:new o({data:t})})});if(c.components[0].trustSourceNormals=!0,c.vertexAttributes.uv){const t=c.vertexAttributes.uv.length??0;for(let e=0;e<t;e++)c.vertexAttributes.uv[2*e+0]=1-c.vertexAttributes.uv[2*e+0],c.vertexAttributes.uv[2*e+1]=c.vertexAttributes.uv[2*e+1]}return c.centerAt(m),c}function n(e){return new t({geometry:e,symbol:{type:"mesh-3d",symbolLayers:[{type:"fill"}]}})}export{u as createImageSphere,n as meshToGraphic};
5
+ import e from"../../Graphic.js";import t from"../../geometry/Mesh.js";import r from"../../geometry/support/MeshMaterial.js";import o from"../../geometry/support/MeshTexture.js";import{defaultImageSphereSize as s,defaultImageSphereCenter as i}from"./constants.js";function n(e,n=i,u=s){const m=n.clone();m.z=-s/2;const c=t.createSphere(m,{size:u,densificationFactor:2,vertexSpace:"georeferenced",material:new r({colorTexture:new o({data:e})})});if(c.components[0].trustSourceNormals=!0,c.vertexAttributes.uv){const e=c.vertexAttributes.uv.length??0;for(let t=0;t<e;t++)c.vertexAttributes.uv[2*t+0]=1-c.vertexAttributes.uv[2*t+0],c.vertexAttributes.uv[2*t+1]=c.vertexAttributes.uv[2*t+1]}return c.centerAt(m),c}function u(t){return new e({geometry:t,symbol:{type:"mesh-3d",symbolLayers:[{type:"fill"}]}})}export{n as createImageSphere,u as meshToGraphic};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.29/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../chunks/tslib.es6.js";import{id as t}from"../../kernel.js";import r from"../../core/Collection.js";import s from"../../core/Error.js";import i from"../../core/Evented.js";import a from"../../core/Logger.js";import{when as l}from"../../core/reactiveUtils.js";import{property as o}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as n}from"../../core/accessorSupport/decorators/subclass.js";import c from"../../geometry/Point.js";import{isPoint as h,isMultipoint as u}from"../../geometry/support/jsonUtils.js";import{fetchMessageBundle as p}from"../../intl/messages.js";import d from"../../layers/FeatureLayer.js";import g from"../../layers/GraphicsLayer.js";import y from"../../layers/support/CodedValueDomain.js";import{isFeatureLayer as m}from"../../layers/support/layerUtils.js";import f from"../../networks/UtilityNetwork.js";import{getObjectIdsFromElements as w,getFeaturesFromLayers as _}from"../../networks/support/utils.js";import A from"../../portal/Portal.js";import{hasUserTypeExtension as b}from"../../portal/support/utils.js";import{trace as v}from"../../rest/networks/trace.js";import R from"../../rest/networks/support/TraceLocation.js";import I from"../../rest/networks/support/TraceParameters.js";import{GeometryHandler as G}from"./support/GeometryHandler.js";import{GraphicHandler as k}from"./support/GraphicHandler.js";import{ResultAreaHandler as F}from"./support/ResultAreaHandler.js";import{UtilityHelper as T}from"./support/UtilityHelper.js";const S=()=>p("esri/widgets/UtilityNetworkTrace/t9n/UtilityNetworkTrace"),L=()=>p("esri/core/t9n/Units"),H=`utility-network-trace-flags-${Date.now()}`,P=`utility-network-trace-results-${Date.now()}`;function N(e){return e instanceof y}function U(e){return"feature"===e.layer.type||"subtype-group"===e.layer.type}function C(e){return"layer"in e}function E(e){return void 0!==e.layerViews}function B(e){return"graphics"===e.type}async function j(e){const t=new d({url:e.networkSystemLayers.dirtyAreasLayerUrl});await t.load();const r=t.version;if(Number(r)<=11.1){const t=new A({url:new URL(e.layerUrl).origin+"/portal"});await t.load();const r=t?.user?.username;return!!r&&b(t,r,"utilityNetwork")}return!0}let D=class extends i.EventedAccessor{constructor(e){super(e),this._activeProgress=!1,this._clickHandler=null,this._flags=[],this._flagId=0,this._geometryHandler=null,this._highlightHandler=[],this._resultAreaHandler=null,this._utilityHelper=new T,this._watchHandler=null,this._validUNLayers=[],this._traceTimeout=6e5,this.traces=[],this.graphicHandler=null,this.defaultGraphicColor={color:[255,255,0,.6],haloOpacity:.9,fillOpacity:.2,hex:"#FFFF00"},this.enableResultArea=!1,this.flags=[],this.gdbVersion="sde.DEFAULT",this.messages=null,this.messagesUnits=null,this.defaultResultAreaProperties={type:"convexhull",distance:10,unit:"meters",areaUnit:"square-meters",color:{color:[255,165,0,.5],haloOpacity:.9,fillOpacity:.2,hex:"#ffa500"},show:!1},this.selectedTraces=[],this.selectOnComplete=!0,this.showGraphicsOnComplete=!0,this.showSelectionAttributes=!0,this.traceResults=[],this.utilityNetwork=null}initialize(){this._geometryHandler=new G,this.graphicHandler=new k,this._resultAreaHandler=new F;(async()=>{const[e,t]=await Promise.all([S(),L()]);this.set({messages:e,messagesUnits:t})})()}destroy(){this.view=null}get resultAreaProperties(){return this.defaultResultAreaProperties}set resultAreaProperties(e){this._set("resultAreaProperties",{...this.defaultResultAreaProperties,...e}),this.graphicHandler.addCustomColor(this.resultAreaProperties.color),this.traceResults.forEach((t=>{t.resultArea={...this.defaultResultAreaProperties,...e};const r=t.resultArea.show;this.removeResultAreaFromMap(t),this.enableResultArea&&(t.resultAreaGraphic?this.addResultAreaToMap(t,t.resultAreaGraphic):this.createResultAreaGraphic(t).then((e=>{e&&(t.resultAreaGraphic=e,r&&this.addResultAreaToMap(t,e))})))}))}get state(){return this.view?.ready?"ready":"loading"}get view(){return this._get("view")}set view(e){e&&"2d"!==e.type&&a.getLogger(this).error(new s("view:invalid-view","SceneView is not supported",{view:e})),this._set("view",e),this.utilityNetwork&&this.reset(),this.utilityNetwork=null,this.loadUtilityNetwork().then((e=>{e&&this.selectTracesOnLoad()}))}addFlagByHit(e,t){const r=e=>{this.view?.popup&&(this.view.popupEnabled=e)};return new Promise(((s,i)=>{r(!1),this._clickHandler?.remove(),this.emit("add-flag",{type:e}),this._clickHandler=this.view?.on("click",(a=>{this.queryFlagByHitTest(a,e,t).then((i=>{r(!0),this._clickHandler?.remove(),this.emit("add-flag-complete",{type:e,symbol:t}),s(i)})).catch((s=>{r(!0),this._clickHandler?.remove(),this.emit("add-flag-error",{type:e,symbol:t}),i(s)}))}))}))}async addFlagsOnLoad(){return new Promise((e=>{const t=[];this._watchHandler=l((()=>null!=this.view&&!this.view.updating),(async()=>{if(this._flags.length>0)e(t);else{const r=this.flags.map((async e=>{if(e.mapPoint){const r=new c({x:e.mapPoint.x,y:e.mapPoint.y,spatialReference:e.mapPoint.spatialReference.wkid}),s={screenPoint:this.view.toScreen(r),mapPoint:r};await this.queryFlagByHitTest(s,e.type)||("barrier"===e.type?t.push("barrier"):t.push("starting-point"))}}));await Promise.all(r),e(t)}}),{initial:!0})}))}async addResultAreaToMap(e,t){if(this.view)if(e.resultArea.show=!0,t)this._resultAreaHandler?.addResultAreaToMap(t,this.view.map),this.emit("add-result-area",{graphic:t});else if(e.results){const t=await this.createResultAreaGraphic(e);t&&(this._resultAreaHandler?.addResultAreaToMap(t,this.view.map),this.emit("add-result-area",{graphic:t}))}}async addResultGraphicToView(e,t){const{view:r}=this,{results:s}=e;if(r&&s&&this.utilityNetwork)for(const i in s.aggregatedGeometry)if("line,multipoint,polygon".includes(i)){const a=i,l=s.aggregatedGeometry[a];if(null!=l){l.spatialReference=this.utilityNetwork.spatialReference,e.graphicEnabled=!0;const s=await this._geometryHandler.projectGeometry(l,r.spatialReference),i={globalid:e.trace.globalId};if(null!==s){const e=this.graphicHandler.makeGraphic(s,t.color,i,r.spatialReference);this._getGraphicLayer(P)?.add(e)}}}}addTerminal(e,t){const r=[...this._flags];r.forEach((r=>{r.globalId===t.globalId&&(t.selectedTerminals?.includes(parseInt(e,10))||r.selectedTerminals?.push(parseInt(e,10)))})),this._flags=r}async callTrace(){const e=this.traces.filter((e=>e.selected));return e.length>0&&(this.traceResults.length>0&&this.traceResults.forEach((e=>{this.removeResultGraphicFromView(e)})),this.traceResults=[],this.removeSelection(),await Promise.all(e.map((async(e,t)=>{const r=e,s=new I({gdbVersion:this.gdbVersion,moment:null,traceType:r.traceType,traceLocations:this._flags,namedTraceConfigurationGlobalId:r.globalId,traceConfiguration:null,outSpatialReference:null,resultTypes:null});await this.executeTrace(r,this.utilityNetwork?.networkServiceUrl,s).then((e=>{if(e.hasOwnProperty("results")){const r={...e};if(null!==r.results){r.resultArea={...this.resultAreaProperties};const e=[...r.results.elements];r.results.elements.length=0;const s=new Map;for(const t of e)s.has(t.globalId)||(s.set(t.globalId,!0),r.results.elements.push(t));const i=[...this.traceResults];i.splice(t,0,r),this.traceResults=i,null!==r.results&&(this.selectOnComplete&&this.mergeSelection(!0,r.trace),this.showGraphicsOnComplete&&this.addResultGraphicToView(r,r.graphicColor),this.enableResultArea&&this.createResultAreaGraphic(r).then((e=>{e&&(r.resultAreaGraphic=e,r.resultArea?.show&&this.addResultAreaToMap(r,r.resultAreaGraphic))})))}else{const r=[...this.traceResults];r.splice(t,0,e),this.traceResults=r}this._activeProgress=!1}else{this._activeProgress=!1;const r=[...this.traceResults];r.splice(t,0,e),this.traceResults=r}})).catch((e=>{throw this._activeProgress=!1,e}))}))),!0)}changeResultAreaColor(e,t){if(!e.resultArea)return;e.resultArea.color=t;const r=this._resultAreaHandler?.changeResultAreaColor(e.trace.globalId,t,this.view.map);e.resultAreaGraphic&&(e.resultAreaGraphic.symbol=r)}changeResultGraphicColor(e,t){const r=[...this.traceResults];r.length>0&&r.forEach((r=>{r.trace.globalId===t.trace.globalId&&(r.graphicColor=e,r.graphicEnabled=!0)})),this.traceResults=r,this.removeResultGraphicFromView(t),this.addResultGraphicToView(t,e)}changeFlagSymbol(e,t){this._flags.length>0&&this._flags.forEach((r=>{r.type===e&&t&&r.mapGraphic&&(r.mapGraphic.symbol=t)}))}checkCanTrace(){const e={status:!0,issues:[]};let t=!1;const r=this._flags.some((e=>"starting-point"===e.type)),s=this._flags.filter((e=>null!==e.allTerminals));s.length>0&&(t=s.some((e=>e.selectedTerminals.length<=0)));let i=[];return r?(i=this.traces.filter((e=>e.selected)),i.length<=0?(e.status=!1,e.issues=["noTrace"],t&&(e.status=!1,e.issues=["noTrace","noTerminalSelected"])):t&&(e.status=!1,e.issues=["noTerminalSelected"])):(i=this.traces.filter((e=>!0===e.selected)),i.length>0?(e.status=!1,e.issues=["noStart"],t&&(e.status=!1,e.issues=["noStart","noTerminalSelected"])):(e.status=!1,e.issues=["noStart","noTrace"],t&&(e.status=!1,e.issues=["noStart","noTrace","noTerminalSelected"]))),e}checkSelectionExist(){return this._highlightHandler.some((e=>e))}clearResult(e){if(!this.view)return;let t=this.traceResults;if(t.length>0){const r=t.filter((t=>t.trace.globalId===e.globalId));r.length>0&&(this.removeResultGraphicFromView(r[0]),this.removeResultAreaFromMap(r[0])),t=t.filter((t=>t.trace.globalId!==e.globalId))}this.traceResults=t,0===t.length?(this.removeAllResultAreaGraphics(),this.removeSelection(),this.emit("clear-selection",{resultSet:[]})):this.mergeSelection(!1,e)}createResultAreaGeometries(e,t,r){if(!this.view||!this.resultAreaProperties)return;let s;if("convexhull"===this.resultAreaProperties?.type?s=1===t.length&&(h(t[0])||u(t[0])&&1===t[0].points.length)?this._resultAreaHandler?.createBuffer(t,r,e.resultArea?.unit,!0):this._resultAreaHandler?.createConvexHull(t,e.resultArea?.distance,e.resultArea?.unit):t&&(s=this._resultAreaHandler?.createBuffer(t,r,e.resultArea?.unit,!0)),s&&Array.isArray(s)){if(s.length>0)for(const i of s){const t=this.getResultAreaAttributes(e,i),r=this._resultAreaHandler?.createResultAreaGraphic(i,t,e.resultArea?.areaUnit,this.messages,this.messagesUnits,e.resultArea?.color);if(r)return r}}else{const t=this.getResultAreaAttributes(e,s),r=this._resultAreaHandler?.createResultAreaGraphic(s,t,e.resultArea?.areaUnit,this.messages,this.messagesUnits,e.resultArea?.color);if(r)return r}}async createResultAreaGraphic(e){if(e.results){const t=await this._createResultAreaInputGeometry(e.results);if(t.length>0){const r=Array(t.length).fill(e.resultArea?.distance),s=this.createResultAreaGeometries(e,t,r);return this.emit("create-result-area",{graphic:s}),s}}}executeTrace(e,t,r){const s=this._processFlags(r.traceLocations);return r.traceLocations=s,v(t,r,{timeout:this._traceTimeout}).then((t=>({trace:e,results:t,selectionEnabled:!1,graphicEnabled:!1,graphicColor:this.defaultGraphicColor,status:"success",date:new Date}))).catch((t=>({trace:e,results:null,selectionEnabled:!1,graphicEnabled:!1,graphicColor:this.defaultGraphicColor,status:t.message,date:new Date})))}getResultAreaAttributes(e,r){const{messages:s}=this,i=[],a=[];this._flags.forEach((e=>{const t=e.displayValue?.field+":"+e.displayValue?.value+";"+s.attributeStrings.globalid+":"+e.globalId+";"+s.attributeStrings.terminalid+":"+e.terminalId+";"+s.attributeStrings.x+":"+e.mapPoint?.x+";"+s.attributeStrings.y+":"+e.mapPoint?.y;"starting-point"===e.type?i.push(t):a.push(t)}));return{traceId:e.trace.globalId,traceName:e.trace.title,traceDescription:e.trace.description??"",startingPoints:i.toString(),barriers:a.toString(),version:this.gdbVersion,username:t.credentials[0].userId,date:e.date,elementCount:e.results?.elements.length,functionResult:JSON.stringify(e.results?.globalFunctionResults),areaStatistic:r?this._geometryHandler.calculateArea(r,e.resultArea?.areaUnit):0}}getValidSources(){let e=[];const t=this.utilityNetwork?.dataElement?.domainNetworks??[];for(const r of t)e=e.concat(r.junctionSources),e=e.concat(r.edgeSources);return e}groupResultsByNetworkSource(e){return 0===e.length?[]:this._groupBy(e,"networkSourceId")}async loadUtilityNetwork(){const{view:e}=this;if(!e)return null;if(await e.when(),this.utilityNetwork){if(this.utilityNetwork.loaded||await this.utilityNetwork.load(),this.utilityNetwork instanceof f){try{const t=e.map;await t.loadAll(),this._loadUNSupportItems()}catch(i){this._loadUNSupportItems()}return this.utilityNetwork}return null}const t=e.map,r=t.utilityNetworks?.at(0);if(r){if(await r.load(),this.utilityNetwork=r,!await j(r))throw new s("utility-network:no-user-type-extension","User type extension not found");try{await t.loadAll(),this._loadUNSupportItems()}catch(i){}finally{this._loadUNSupportItems()}return r}return null}manageFilterBarrier(e,t){const r=[...this._flags];r.forEach((r=>{r.globalId===t.globalId&&"barrier"===t.type&&r.id===t.id&&(r.isFilterBarrier=e)})),this._flags=r}mergeSelection(e,t){let r=[];const s=[...this.traceResults],i=t.globalId;s.forEach((t=>{i===t.trace.globalId&&(t.selectionEnabled=e),t.selectionEnabled&&null!==t.results?.elements&&(r=[...r,...t.results?.elements??[]])})),this.selectResults([...new Set(r)])}async queryFeaturesById(e){const{view:t}=this;if(!t||!this.utilityNetwork)return null;const s=w(this.utilityNetwork,e),i={layerUrl:s[0].layerUrl,objectIds:s[0].objectIds,outFields:["*"]},a=t.map?.allTables.toArray().filter((e=>e?.parsedUrl?.path===s[0].layerUrl)).filter(m)??[];this._getUniqueMapLayerViews(t).filter((({layer:e})=>e?.parsedUrl?.path===s[0].layerUrl)).forEach((({layer:e})=>{"feature"!==e.type&&"subtype-group"!==e.type||a.push(e)}));const l=(await Promise.all(a.map((async e=>{const s={layers:new r([e]),layerInfos:[i],returnGeometry:!0,outSpatialReference:t.spatialReference},[a]=await _(s,!1);return a})))).filter((({featureSet:e})=>e.features.length>0));return l.length>0?l:null}queryFlagByHitTest(e,t,r){return this._lookupFlagByHit(e).then((e=>{const{view:s}=this;if(!s)return!1;if(e.length>0){const s=[...this._flags],i=r;return e.forEach((e=>{const r=e.graphic,a=r.attributes.hasOwnProperty("GLOBALID")?r.attributes.GLOBALID:r.attributes.globalid;if(s.filter((e=>e.globalId===a)).length<=0){const e=this.graphicHandler.getFlagGraphic(r.mapPoint,t,r,i);this._getGraphicLayer(H)?.add(e),s.push({...r,type:t,globalId:r.attributes.globalid||r.attributes.GLOBALID,details:r,mapGraphic:e,id:this._uniqueFlagId})}else if(null!==r.percentAlong){const e=this.graphicHandler.getFlagGraphic(r.mapPoint,t,r,i);this._getGraphicLayer(H)?.add(e),s.push({...r,type:t,globalId:r.attributes.globalid||r.attributes.GLOBALID,details:r,mapGraphic:e,id:this._uniqueFlagId})}})),this._flags=s,!0}return!1}))}removeResultGraphicFromView(e){const{view:t}=this;if(!t)return;const r=this._getGraphicLayer(P)?.graphics;e.graphicEnabled=!1;const s=r?.filter((t=>t.attributes[t.attributes.hasOwnProperty("GLOBALID")?"GLOBALID":"globalid"]===e.trace.globalId));s?.forEach((e=>{this._getGraphicLayer(P)?.remove(e)}))}removeFlag(e){const t=this._flags.filter((t=>{if(t.id!==e.id)return t}));this._removeGraphic(e),this._flags=t}removeAllResultAreaGraphics(){this._resultAreaHandler?.removeAllResultAreaGraphics(this.view.map)}removeResultAreaFromMap(e){if(e.resultArea){e.resultArea.show=!1;const t=this._resultAreaHandler?.removeResultArea(e.trace.globalId,this.view?.map);t&&this.emit("remove-result-area",{graphic:t})}}removeSelection(){this._highlightHandler.forEach((e=>{e&&e.remove()})),this._highlightHandler=[]}removeTerminal(e,t){const r=[...this._flags];r.forEach((r=>{if(r.globalId===t.globalId&&t.selectedTerminals?.includes(parseInt(e,10))){const s=t.selectedTerminals.indexOf(parseInt(e,10));r.selectedTerminals?.splice(s,1)}})),this._flags=r}removeFlagsOnLoadWatcher(){this._watchHandler&&null!==this._watchHandler&&this._watchHandler.remove()}reset(){this._flags=[],this.traceResults=[];const e=[...this.traces];e.forEach((e=>{e.selected=!1})),this.traces=e,this.view&&(this._getGraphicLayer(P)?.removeAll(),this._getGraphicLayer(H)?.removeAll(),this.removeAllResultAreaGraphics(),this.removeSelection(),this.emit("clear-selection",{resultSet:[]}))}selectFeaturesById(e){const{view:t}=this;if(!t||!this.utilityNetwork)return;const r=w(this.utilityNetwork,e);this._getUniqueMapLayerViews(t).forEach((e=>{C(e)&&e.layer?.parsedUrl?.path===r[0].layerUrl&&U(e)&&this._highlightHandler.push(e.highlight(r[0].objectIds))}))}selectResults(e){if(e.length>0){this.removeSelection();const t=this.groupResultsByNetworkSource(e),r=[];for(const e in t)this.selectFeaturesById(t[e]),r.push(this.queryFeaturesById(t[e]));Promise.all(r).then((e=>{this.emit("select-features",{resultSet:e})}))}else this.removeSelection(),this.emit("clear-selection",{resultSet:[]})}selectTraces(e,t){const r=[...this.traces];r.forEach((r=>{t===r.globalId&&(r.selected=e)})),this.traces=r}selectTracesOnLoad(){this.utilityNetwork?.hasOwnProperty("sharedNamedTraceConfigurations")&&(this.traces=[...this.utilityNetwork.sharedNamedTraceConfigurations],this.traces.forEach((e=>{e.selected=!1,this.selectedTraces.includes(e.globalId)&&(e.selected=!0)})))}zoomToAsset(e){this.view?.goTo(e).catch((e=>console.error(e)))}async _createResultAreaInputGeometry(e){if(null!=e.aggregatedGeometry)return this._geometryHandler.mergeAggregatedToGeometries(e.aggregatedGeometry);const t=this.groupResultsByNetworkSource(e.elements),r=[];for(const s in t)r.push(this.queryFeaturesById(t[s]));try{const e=await Promise.all(r),t=[];for(const r of e)if(r)for(const e of r)for(const r of e.featureSet.features)t.push(r.geometry);return t}catch{return[]}}_loadUNSupportItems(){if(!this.utilityNetwork)return;const{map:e}=this.view,{messages:t}=this;this._populateOutfields(),this._createGraphicLayer(H),this._createGraphicLayer(P),this._resultAreaHandler?.createGraphicLayer(e,t?.alertsStrings.genericResultHeader),this._validUNLayers=this._utilityHelper.getValidUtilityNetworkLayers(e,this.utilityNetwork)}_getUniqueMapLayerViews(e){const t=[];return e.layerViews.filter((({layer:{type:e}})=>"feature"===e||"group"===e||"subtype-group"===e)).toArray().forEach((e=>{switch(e.layer.type){case"group":if(E(e))for(const r of e.layerViews)t.push(r);break;case"subtype-group":t.push(e);break;default:t.some((t=>t.layer.id===e.layer.id))||t.push(e)}})),t}_processFlags(e){const t=[];return e.forEach((e=>{if(null!==e.selectedTerminals&&e.selectedTerminals.length>0)e.selectedTerminals.forEach((r=>{const s=new R({globalId:e.globalId,percentAlong:e.percentAlong,terminalId:r,type:e.type,isFilterBarrier:e.isFilterBarrier});t.push(s)}));else{const r=new R({globalId:e.globalId,percentAlong:e.percentAlong,terminalId:null,type:e.type,isFilterBarrier:e.isFilterBarrier});t.push(r)}})),t}_getDisplayField(e){return"subtype-sublayer"===e?.layer?.type?this._getDisplayFieldBySublayer(e):this._getDisplayFieldByFeatureLayer(e)}_getDisplayFieldBySublayer(e){let t="",r="";const s=e.layer;t=this._checkParentForData(s,"displayField");for(const i in e.attributes){const a=i.toLowerCase();a===t?.toLowerCase()?(r=e.attributes[i],"assetgroup"===a||"assettype"===a?r=this._checkSubtype(s,s.subtypeCode):(r=this._checkDomain(s.fields,i,r),"string"==typeof r&&(r=this._defaultDisplayField(r,s)))):(r=this._checkDomain(s.fields,i,r),"string"==typeof r&&(r=this._defaultDisplayField(r,s)))}return{field:t,value:r.toString()}}_getDisplayFieldByFeatureLayer(e){const t=e.layer;let r=t.displayField,s="";for(const i in e.attributes){const a=i.toLowerCase();if(a===r?.toLowerCase())if(s=e.attributes[i],"assetgroup"===a||"assettype"===a){let a=e.attributes[t.typeIdField.toUpperCase()];a||(a=e.attributes[t.typeIdField.toLowerCase()]),r=t.typeIdField,s=this._checkSubtype(t,a),""===r&&(t.templates&&t.templates.length>0?(r=t.templates[0]?.name,s=t.templates[0]?.name):(r=t.displayField,s=e.attributes[i]))}else s=this._checkDomain(t.fields,i,s),"string"==typeof s&&(s=this._defaultDisplayField(s,t));else s=this._checkDomain(t.fields,i,s),"string"==typeof s&&(s=this._defaultDisplayField(s,t))}return{field:r,value:s?s.toString():""}}_checkSubtype(e,t){let r=t;if("subtype-sublayer"===e.type){const s=this._checkParentForData(e,"subtypes");s?.length>0&&s.forEach((e=>{e.code===t&&(r=e.name)}))}else if(null!=e.types&&e.types.length>0){const s=e.types.filter((e=>e.id===t));s.length>0&&(r=s[0].name)}return r}_checkDomain(e,t,r){let s=r;const i=e.filter((e=>e.name.toLowerCase()===t.toLowerCase()));if(i.length>0&&N(i[0].domain)&&i[0].domain?.codedValues){const e=i[0].domain.codedValues.filter((({code:e})=>e===r));e.length>0&&(s=e[0].name)}return s}_checkParentForData(e,t){return e.parent?.[t]??null}_defaultDisplayField(e,t){return e.trim()?e:t.templates&&t.templates?.length>0?t.templates[0].name:t.title}get _uniqueFlagId(){return this._flagId++}_groupBy(e,t){return e.reduce(((e,r)=>((e[r[t]]=e[r[t]]||[]).push(r),e)),{})}async _lookupFlagByHit(e){if(null==e.mapPoint)return[];const t=await this.view.hitTest(e.screenPoint,{include:this._validUNLayers}),r=[];if(t.results.length>0){const s=t.results.find((e=>null!==e.layer));if(null!=s.graphic?.geometry)if("polyline"===s.graphic.geometry.type){const t=this._geometryHandler.getPercentageAlong(s.graphic.geometry,e.mapPoint,s.graphic.geometry.spatialReference),i=this._getDisplayField(s.graphic);s.graphic.terminalId=null,s.graphic.isFilterBarrier=!1,s.graphic.allTerminals=null,s.graphic.selectedTerminals=null,s.graphic.percentAlong=t,s.graphic.displayValue=i,s.graphic.mapPoint=s.mapPoint,r.push(s)}else if(("point"===s.graphic.geometry.type||"polygon"===s.graphic.geometry.type)&&null!==this.utilityNetwork){const e=this.utilityNetwork?.getTerminalConfiguration(s.graphic),t=this._getDisplayField(s.graphic);s.graphic.terminalId=e?e.terminals[0].id||null:1,s.graphic.isFilterBarrier=!1,s.graphic.allTerminals=e??null,s.graphic.selectedTerminals=[e?e.terminals[0].id||null:1],s.graphic.percentAlong=null,s.graphic.displayValue=t,s.graphic.mapPoint=s.mapPoint,r.push(s)}}return r}async _populateOutfields(){const e=this.view?.map,t=this.getValidSources();e?.layers.forEach((e=>{"group"===e.type?e.layers.forEach((e=>{t.some((t=>t.layerId===e.layerId))&&e.fields.some((e=>"assetgroup"===e.name.toLowerCase()))&&(e.outFields=["assetgroup","assettype","globalid","objectid"])})):t.some((t=>t.layerId===e.layerId))&&e.fields.some((e=>"assetgroup"===e.name.toLowerCase()))&&(e.outFields=["assetgroup","assettype","globalid","objectid"])}))}_removeGraphic(e){this._getGraphicLayer(H)?.remove(e.mapGraphic)}_createGraphicLayer(e){const{map:t}=this.view;if(!t.findLayerById(e)){const r=new g({title:e,listMode:"hide",id:e});t.add(r)}}_getGraphicLayer(e){const{map:t}=this.view;if(t){const r=t.findLayerById(e);if(r&&B(r))return r}return null}};e([o()],D.prototype,"_activeProgress",void 0),e([o()],D.prototype,"_flags",void 0),e([o()],D.prototype,"traces",void 0),e([o()],D.prototype,"defaultGraphicColor",void 0),e([o()],D.prototype,"enableResultArea",void 0),e([o()],D.prototype,"flags",void 0),e([o()],D.prototype,"gdbVersion",void 0),e([o()],D.prototype,"messages",void 0),e([o()],D.prototype,"messagesUnits",void 0),e([o()],D.prototype,"resultAreaProperties",null),e([o()],D.prototype,"selectedTraces",void 0),e([o()],D.prototype,"selectOnComplete",void 0),e([o()],D.prototype,"showGraphicsOnComplete",void 0),e([o()],D.prototype,"showSelectionAttributes",void 0),e([o({readOnly:!0})],D.prototype,"state",null),e([o()],D.prototype,"traceResults",void 0),e([o()],D.prototype,"utilityNetwork",void 0),e([o({value:null})],D.prototype,"view",null),D=e([n("esri.widgets.UtilityNetworkTrace.UtilityNetworkTraceViewModel")],D);const V=D;export{V as default};
5
+ import{_ as e}from"../../chunks/tslib.es6.js";import{id as t}from"../../kernel.js";import r from"../../core/Collection.js";import s from"../../core/Error.js";import i from"../../core/Evented.js";import a from"../../core/Logger.js";import{when as l}from"../../core/reactiveUtils.js";import{property as o}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as n}from"../../core/accessorSupport/decorators/subclass.js";import c from"../../geometry/Point.js";import{isPoint as h,isMultipoint as u}from"../../geometry/support/jsonUtils.js";import{fetchMessageBundle as p}from"../../intl/messages.js";import d from"../../layers/FeatureLayer.js";import g from"../../layers/GraphicsLayer.js";import y from"../../layers/support/CodedValueDomain.js";import{isFeatureLayer as m}from"../../layers/support/layerUtils.js";import f from"../../networks/UtilityNetwork.js";import{getObjectIdsFromElements as w,getFeaturesFromLayers as _}from"../../networks/support/utils.js";import A from"../../portal/Portal.js";import{hasUserTypeExtension as b}from"../../portal/support/utils.js";import{trace as v}from"../../rest/networks/trace.js";import R from"../../rest/networks/support/TraceLocation.js";import I from"../../rest/networks/support/TraceParameters.js";import{GeometryHandler as k}from"./support/GeometryHandler.js";import{GraphicHandler as G}from"./support/GraphicHandler.js";import{ResultAreaHandler as F}from"./support/ResultAreaHandler.js";import{UtilityHelper as T}from"./support/UtilityHelper.js";const S=()=>p("esri/widgets/UtilityNetworkTrace/t9n/UtilityNetworkTrace"),L=()=>p("esri/core/t9n/Units"),H=`utility-network-trace-flags-${Date.now()}`,P=`utility-network-trace-results-${Date.now()}`;function N(e){return e instanceof y}function U(e){return"feature"===e.layer.type||"subtype-group"===e.layer.type}function C(e){return"layer"in e}function E(e){return void 0!==e.layerViews}function B(e){return"graphics"===e.type}async function j(e){const t=new d({url:e.networkSystemLayers.dirtyAreasLayerUrl});await t.load();const r=t.version;if(Number(r)<=11.1){const t=new A({url:new URL(e.layerUrl).origin+"/portal"});await t.load();const r=t?.user?.username;return!!r&&b(t,r,"utilityNetwork")}return!0}let D=class extends i.EventedAccessor{constructor(e){super(e),this._activeProgress=!1,this._clickHandler=null,this._flags=[],this._flagId=0,this._geometryHandler=null,this._highlightHandler=[],this._resultAreaHandler=null,this._utilityHelper=new T,this._watchHandler=null,this._validUNLayers=[],this._traceTimeout=6e5,this.traces=[],this.graphicHandler=null,this.defaultGraphicColor={color:[255,255,0,.6],haloOpacity:.9,fillOpacity:.2,hex:"#FFFF00"},this.enableResultArea=!1,this.flags=[],this.gdbVersion="sde.DEFAULT",this.messages=null,this.messagesUnits=null,this.defaultResultAreaProperties={type:"convexhull",distance:10,unit:"meters",areaUnit:"square-meters",color:{color:[255,165,0,.5],haloOpacity:.9,fillOpacity:.2,hex:"#ffa500"},show:!1},this.selectedTraces=[],this.selectOnComplete=!0,this.showGraphicsOnComplete=!0,this.showSelectionAttributes=!0,this.traceResults=[],this.utilityNetwork=null}initialize(){this._geometryHandler=new k,this.graphicHandler=new G,this._resultAreaHandler=new F;(async()=>{const[e,t]=await Promise.all([S(),L()]);this.set({messages:e,messagesUnits:t})})()}destroy(){this.view=null}get resultAreaProperties(){return this.defaultResultAreaProperties}set resultAreaProperties(e){this._set("resultAreaProperties",{...this.defaultResultAreaProperties,...e}),this.graphicHandler.addCustomColor(this.resultAreaProperties.color),this.traceResults.forEach((t=>{const r=t.resultArea?.show;t.resultArea={...this.defaultResultAreaProperties,...e},this.removeResultAreaFromMap(t),this.enableResultArea&&this.createResultAreaGraphic(t).then((s=>{if(s){t.resultAreaGraphic=s;const i=e?.show??r;t.resultArea&&(t.resultArea.show=i),i&&this.addResultAreaToMap(t,s)}}))}))}get state(){return this.view?.ready?"ready":"loading"}get view(){return this._get("view")}set view(e){e&&"2d"!==e.type&&a.getLogger(this).error(new s("view:invalid-view","SceneView is not supported",{view:e})),this._set("view",e),this.utilityNetwork&&this.reset(),this.utilityNetwork=null,this.loadUtilityNetwork().then((e=>{e&&this.selectTracesOnLoad()}))}addFlagByHit(e,t){const r=e=>{this.view?.popup&&(this.view.popupEnabled=e)};return new Promise(((s,i)=>{r(!1),this._clickHandler?.remove(),this.emit("add-flag",{type:e}),this._clickHandler=this.view?.on("click",(a=>{this.queryFlagByHitTest(a,e,t).then((i=>{r(!0),this._clickHandler?.remove(),this.emit("add-flag-complete",{type:e,symbol:t}),s(i)})).catch((s=>{r(!0),this._clickHandler?.remove(),this.emit("add-flag-error",{type:e,symbol:t}),i(s)}))}))}))}async addFlagsOnLoad(){return new Promise((e=>{const t=[];this._watchHandler=l((()=>null!=this.view&&!this.view.updating),(async()=>{if(this._flags.length>0)e(t);else{const r=this.flags.map((async e=>{if(e.mapPoint){const r=new c({x:e.mapPoint.x,y:e.mapPoint.y,spatialReference:e.mapPoint.spatialReference.wkid}),s={screenPoint:this.view.toScreen(r),mapPoint:r};await this.queryFlagByHitTest(s,e.type)||("barrier"===e.type?t.push("barrier"):t.push("starting-point"))}}));await Promise.all(r),e(t)}}),{initial:!0})}))}async addResultAreaToMap(e,t){if(this.view)if(e.resultArea.show=!0,t)this._resultAreaHandler?.addResultAreaToMap(t,this.view.map),this.emit("add-result-area",{graphic:t});else if(e.results){const t=await this.createResultAreaGraphic(e);t&&(e.resultAreaGraphic=t,this._resultAreaHandler?.addResultAreaToMap(t,this.view.map),this.emit("add-result-area",{graphic:t}))}}async addResultGraphicToView(e,t){const{view:r}=this,{results:s}=e;if(r&&s&&this.utilityNetwork)for(const i in s.aggregatedGeometry)if("line,multipoint,polygon".includes(i)){const a=i,l=s.aggregatedGeometry[a];if(null!=l){l.spatialReference=this.utilityNetwork.spatialReference,e.graphicEnabled=!0;const s=await this._geometryHandler.projectGeometry(l,r.spatialReference),i={globalid:e.trace.globalId};if(null!==s){const e=this.graphicHandler.makeGraphic(s,t.color,i,r.spatialReference);this._getGraphicLayer(P)?.add(e)}}}}addTerminal(e,t){const r=[...this._flags];r.forEach((r=>{r.globalId===t.globalId&&(t.selectedTerminals?.includes(parseInt(e,10))||r.selectedTerminals?.push(parseInt(e,10)))})),this._flags=r}async callTrace(){const e=this.traces.filter((e=>e.selected));return e.length>0&&(this.traceResults.length>0&&this.traceResults.forEach((e=>{this.removeResultGraphicFromView(e)})),this.traceResults=[],this.removeSelection(),await Promise.all(e.map((async(e,t)=>{const r=e,s=new I({gdbVersion:this.gdbVersion,moment:null,traceType:r.traceType,traceLocations:this._flags,namedTraceConfigurationGlobalId:r.globalId,traceConfiguration:null,outSpatialReference:null,resultTypes:null});await this.executeTrace(r,this.utilityNetwork?.networkServiceUrl,s).then((e=>{if(e.hasOwnProperty("results")){const r={...e};if(null!==r.results){r.resultArea={...this.resultAreaProperties};const e=[...r.results.elements];r.results.elements.length=0;const s=new Map;for(const t of e)s.has(t.globalId)||(s.set(t.globalId,!0),r.results.elements.push(t));const i=[...this.traceResults];i.splice(t,0,r),this.traceResults=i,null!==r.results&&(this.selectOnComplete&&this.mergeSelection(!0,r.trace),this.showGraphicsOnComplete&&this.addResultGraphicToView(r,r.graphicColor),this.enableResultArea&&this.createResultAreaGraphic(r).then((e=>{e&&(r.resultAreaGraphic=e,r.resultArea?.show&&this.addResultAreaToMap(r,r.resultAreaGraphic))})))}else{const r=[...this.traceResults];r.splice(t,0,e),this.traceResults=r}this._activeProgress=!1}else{this._activeProgress=!1;const r=[...this.traceResults];r.splice(t,0,e),this.traceResults=r}})).catch((e=>{throw this._activeProgress=!1,e}))}))),!0)}changeResultAreaColor(e,t){if(!e.resultArea)return;e.resultArea.color=t;const r=this._resultAreaHandler?.changeResultAreaColor(e.trace.globalId,t,this.view.map);e.resultAreaGraphic&&(e.resultAreaGraphic.symbol=r)}changeResultGraphicColor(e,t){const r=[...this.traceResults];r.length>0&&r.forEach((r=>{r.trace.globalId===t.trace.globalId&&(r.graphicColor=e,r.graphicEnabled=!0)})),this.traceResults=r,this.removeResultGraphicFromView(t),this.addResultGraphicToView(t,e)}changeFlagSymbol(e,t){this._flags.length>0&&this._flags.forEach((r=>{r.type===e&&t&&r.mapGraphic&&(r.mapGraphic.symbol=t)}))}checkCanTrace(){const e={status:!0,issues:[]};let t=!1;const r=this._flags.some((e=>"starting-point"===e.type)),s=this._flags.filter((e=>null!==e.allTerminals));s.length>0&&(t=s.some((e=>e.selectedTerminals.length<=0)));let i=[];return r?(i=this.traces.filter((e=>e.selected)),i.length<=0?(e.status=!1,e.issues=["noTrace"],t&&(e.status=!1,e.issues=["noTrace","noTerminalSelected"])):t&&(e.status=!1,e.issues=["noTerminalSelected"])):(i=this.traces.filter((e=>!0===e.selected)),i.length>0?(e.status=!1,e.issues=["noStart"],t&&(e.status=!1,e.issues=["noStart","noTerminalSelected"])):(e.status=!1,e.issues=["noStart","noTrace"],t&&(e.status=!1,e.issues=["noStart","noTrace","noTerminalSelected"]))),e}checkSelectionExist(){return this._highlightHandler.some((e=>e))}clearResult(e){if(!this.view)return;let t=this.traceResults;if(t.length>0){const r=t.filter((t=>t.trace.globalId===e.globalId));r.length>0&&(this.removeResultGraphicFromView(r[0]),this.removeResultAreaFromMap(r[0])),t=t.filter((t=>t.trace.globalId!==e.globalId))}this.traceResults=t,0===t.length?(this.removeAllResultAreaGraphics(),this.removeSelection(),this.emit("clear-selection",{resultSet:[]})):this.mergeSelection(!1,e)}createResultAreaGeometries(e,t,r){if(!this.view||!this.resultAreaProperties)return;let s;if("convexhull"===this.resultAreaProperties?.type?s=1===t.length&&(h(t[0])||u(t[0])&&1===t[0].points.length)?this._resultAreaHandler?.createBuffer(t,r,e.resultArea?.unit,!0):this._resultAreaHandler?.createConvexHull(t,e.resultArea?.distance,e.resultArea?.unit):t&&(s=this._resultAreaHandler?.createBuffer(t,r,e.resultArea?.unit,!0)),s&&Array.isArray(s)){if(s.length>0)for(const i of s){const t=this.getResultAreaAttributes(e,i),r=this._resultAreaHandler?.createResultAreaGraphic(i,t,e.resultArea?.areaUnit,this.messages,this.messagesUnits,e.resultArea?.color);if(r)return r}}else{const t=this.getResultAreaAttributes(e,s),r=this._resultAreaHandler?.createResultAreaGraphic(s,t,e.resultArea?.areaUnit,this.messages,this.messagesUnits,e.resultArea?.color);if(r)return r}}async createResultAreaGraphic(e){if(e.results){const t=await this._createResultAreaInputGeometry(e.results);if(t.length>0){const r=Array(t.length).fill(e.resultArea?.distance),s=this.createResultAreaGeometries(e,t,r);return this.emit("create-result-area",{graphic:s}),s}}}executeTrace(e,t,r){const s=this._processFlags(r.traceLocations);return r.traceLocations=s,v(t,r,{timeout:this._traceTimeout}).then((t=>({trace:e,results:t,selectionEnabled:!1,graphicEnabled:!1,graphicColor:this.defaultGraphicColor,status:"success",date:new Date}))).catch((t=>({trace:e,results:null,selectionEnabled:!1,graphicEnabled:!1,graphicColor:this.defaultGraphicColor,status:t.message,date:new Date})))}getResultAreaAttributes(e,r){const{messages:s}=this,i=[],a=[];this._flags.forEach((e=>{const t=e.displayValue?.field+":"+e.displayValue?.value+";"+s.attributeStrings.globalid+":"+e.globalId+";"+s.attributeStrings.terminalid+":"+e.terminalId+";"+s.attributeStrings.x+":"+e.mapPoint?.x+";"+s.attributeStrings.y+":"+e.mapPoint?.y;"starting-point"===e.type?i.push(t):a.push(t)}));return{traceId:e.trace.globalId,traceName:e.trace.title,traceDescription:e.trace.description??"",startingPoints:i.toString(),barriers:a.toString(),version:this.gdbVersion,username:t.credentials[0].userId,date:e.date,elementCount:e.results?.elements.length,functionResult:JSON.stringify(e.results?.globalFunctionResults),areaStatistic:r?this._geometryHandler.calculateArea(r,e.resultArea?.areaUnit):0}}getValidSources(){let e=[];const t=this.utilityNetwork?.dataElement?.domainNetworks??[];for(const r of t)e=e.concat(r.junctionSources),e=e.concat(r.edgeSources);return e}groupResultsByNetworkSource(e){return 0===e.length?[]:this._groupBy(e,"networkSourceId")}async loadUtilityNetwork(){const{view:e}=this;if(!e)return null;if(await e.when(),this.utilityNetwork){if(this.utilityNetwork.loaded||await this.utilityNetwork.load(),this.utilityNetwork instanceof f){try{const t=e.map;await t.loadAll(),this._loadUNSupportItems()}catch(i){this._loadUNSupportItems()}return this.utilityNetwork}return null}const t=e.map,r=t.utilityNetworks?.at(0);if(r){if(await r.load(),this.utilityNetwork=r,!await j(r))throw new s("utility-network:no-user-type-extension","User type extension not found");try{await t.loadAll(),this._loadUNSupportItems()}catch(i){}finally{this._loadUNSupportItems()}return r}return null}manageFilterBarrier(e,t){const r=[...this._flags];r.forEach((r=>{r.globalId===t.globalId&&"barrier"===t.type&&r.id===t.id&&(r.isFilterBarrier=e)})),this._flags=r}mergeSelection(e,t){let r=[];const s=[...this.traceResults],i=t.globalId;s.forEach((t=>{i===t.trace.globalId&&(t.selectionEnabled=e),t.selectionEnabled&&null!==t.results?.elements&&(r=[...r,...t.results?.elements??[]])})),this.selectResults([...new Set(r)])}async queryFeaturesById(e){const{view:t}=this;if(!t||!this.utilityNetwork)return null;const s=w(this.utilityNetwork,e),i={layerUrl:s[0].layerUrl,objectIds:s[0].objectIds,outFields:["*"]},a=t.map?.allTables.toArray().filter((e=>e?.parsedUrl?.path===s[0].layerUrl)).filter(m)??[];this._getUniqueMapLayerViews(t).filter((({layer:e})=>e?.parsedUrl?.path===s[0].layerUrl)).forEach((({layer:e})=>{"feature"!==e.type&&"subtype-group"!==e.type||a.push(e)}));const l=(await Promise.all(a.map((async e=>{const s={layers:new r([e]),layerInfos:[i],returnGeometry:!0,outSpatialReference:t.spatialReference},[a]=await _(s,!1);return a})))).filter((({featureSet:e})=>e.features.length>0));return l.length>0?l:null}queryFlagByHitTest(e,t,r){return this._lookupFlagByHit(e).then((e=>{const{view:s}=this;if(!s)return!1;if(e.length>0){const s=[...this._flags],i=r;return e.forEach((e=>{const r=e.graphic,a=r.attributes.hasOwnProperty("GLOBALID")?r.attributes.GLOBALID:r.attributes.globalid;if(s.filter((e=>e.globalId===a)).length<=0){const e=this.graphicHandler.getFlagGraphic(r.mapPoint,t,r,i);this._getGraphicLayer(H)?.add(e),s.push({...r,type:t,globalId:r.attributes.globalid||r.attributes.GLOBALID,details:r,mapGraphic:e,id:this._uniqueFlagId})}else if(null!==r.percentAlong){const e=this.graphicHandler.getFlagGraphic(r.mapPoint,t,r,i);this._getGraphicLayer(H)?.add(e),s.push({...r,type:t,globalId:r.attributes.globalid||r.attributes.GLOBALID,details:r,mapGraphic:e,id:this._uniqueFlagId})}})),this._flags=s,!0}return!1}))}removeResultGraphicFromView(e){const{view:t}=this;if(!t)return;const r=this._getGraphicLayer(P)?.graphics;e.graphicEnabled=!1;const s=r?.filter((t=>t.attributes[t.attributes.hasOwnProperty("GLOBALID")?"GLOBALID":"globalid"]===e.trace.globalId));s?.forEach((e=>{this._getGraphicLayer(P)?.remove(e)}))}removeFlag(e){const t=this._flags.filter((t=>{if(t.id!==e.id)return t}));this._removeGraphic(e),this._flags=t}removeAllResultAreaGraphics(){this._resultAreaHandler?.removeAllResultAreaGraphics(this.view.map)}removeResultAreaFromMap(e){if(e.resultArea){e.resultArea.show=!1;const t=this._resultAreaHandler?.removeResultArea(e.trace.globalId,this.view?.map);t&&this.emit("remove-result-area",{graphic:t})}}removeSelection(){this._highlightHandler.forEach((e=>{e&&e.remove()})),this._highlightHandler=[]}removeTerminal(e,t){const r=[...this._flags];r.forEach((r=>{if(r.globalId===t.globalId&&t.selectedTerminals?.includes(parseInt(e,10))){const s=t.selectedTerminals.indexOf(parseInt(e,10));r.selectedTerminals?.splice(s,1)}})),this._flags=r}removeFlagsOnLoadWatcher(){this._watchHandler&&null!==this._watchHandler&&this._watchHandler.remove()}reset(){this._flags=[],this.traceResults=[];const e=[...this.traces];e.forEach((e=>{e.selected=!1})),this.traces=e,this.view&&(this._getGraphicLayer(P)?.removeAll(),this._getGraphicLayer(H)?.removeAll(),this.removeAllResultAreaGraphics(),this.removeSelection(),this.emit("clear-selection",{resultSet:[]}))}selectFeaturesById(e){const{view:t}=this;if(!t||!this.utilityNetwork)return;const r=w(this.utilityNetwork,e);this._getUniqueMapLayerViews(t).forEach((e=>{C(e)&&e.layer?.parsedUrl?.path===r[0].layerUrl&&U(e)&&this._highlightHandler.push(e.highlight(r[0].objectIds))}))}selectResults(e){if(e.length>0){this.removeSelection();const t=this.groupResultsByNetworkSource(e),r=[];for(const e in t)this.selectFeaturesById(t[e]),r.push(this.queryFeaturesById(t[e]));Promise.all(r).then((e=>{this.emit("select-features",{resultSet:e})}))}else this.removeSelection(),this.emit("clear-selection",{resultSet:[]})}selectTraces(e,t){const r=[...this.traces];r.forEach((r=>{t===r.globalId&&(r.selected=e)})),this.traces=r}selectTracesOnLoad(){this.utilityNetwork?.hasOwnProperty("sharedNamedTraceConfigurations")&&(this.traces=[...this.utilityNetwork.sharedNamedTraceConfigurations],this.traces.forEach((e=>{e.selected=!1,this.selectedTraces.includes(e.globalId)&&(e.selected=!0)})))}zoomToAsset(e){this.view?.goTo(e).catch((e=>console.error(e)))}async _createResultAreaInputGeometry(e){if(null!=e.aggregatedGeometry)return this._geometryHandler.mergeAggregatedToGeometries(e.aggregatedGeometry);const t=this.groupResultsByNetworkSource(e.elements),r=[];for(const s in t)r.push(this.queryFeaturesById(t[s]));try{const e=await Promise.all(r),t=[];for(const r of e)if(r)for(const e of r)for(const r of e.featureSet.features)t.push(r.geometry);return t}catch{return[]}}_loadUNSupportItems(){if(!this.utilityNetwork)return;const{map:e}=this.view,{messages:t}=this;this._populateOutfields(),this._createGraphicLayer(H),this._createGraphicLayer(P),this._resultAreaHandler?.createGraphicLayer(e,t?.alertsStrings.genericResultHeader),this._validUNLayers=this._utilityHelper.getValidUtilityNetworkLayers(e,this.utilityNetwork)}_getUniqueMapLayerViews(e){const t=[];return e.layerViews.filter((({layer:{type:e}})=>"feature"===e||"group"===e||"subtype-group"===e)).toArray().forEach((e=>{switch(e.layer.type){case"group":if(E(e))for(const r of e.layerViews)t.push(r);break;case"subtype-group":t.push(e);break;default:t.some((t=>t.layer.id===e.layer.id))||t.push(e)}})),t}_processFlags(e){const t=[];return e.forEach((e=>{if(null!==e.selectedTerminals&&e.selectedTerminals.length>0)e.selectedTerminals.forEach((r=>{const s=new R({globalId:e.globalId,percentAlong:e.percentAlong,terminalId:r,type:e.type,isFilterBarrier:e.isFilterBarrier});t.push(s)}));else{const r=new R({globalId:e.globalId,percentAlong:e.percentAlong,terminalId:null,type:e.type,isFilterBarrier:e.isFilterBarrier});t.push(r)}})),t}_getDisplayField(e){return"subtype-sublayer"===e?.layer?.type?this._getDisplayFieldBySublayer(e):this._getDisplayFieldByFeatureLayer(e)}_getDisplayFieldBySublayer(e){let t="",r="";const s=e.layer;t=this._checkParentForData(s,"displayField");for(const i in e.attributes){const a=i.toLowerCase();a===t?.toLowerCase()?(r=e.attributes[i],"assetgroup"===a||"assettype"===a?r=this._checkSubtype(s,s.subtypeCode):(r=this._checkDomain(s.fields,i,r),"string"==typeof r&&(r=this._defaultDisplayField(r,s)))):(r=this._checkDomain(s.fields,i,r),"string"==typeof r&&(r=this._defaultDisplayField(r,s)))}return{field:t,value:r.toString()}}_getDisplayFieldByFeatureLayer(e){const t=e.layer;let r=t.displayField,s="";for(const i in e.attributes){const a=i.toLowerCase();if(a===r?.toLowerCase())if(s=e.attributes[i],"assetgroup"===a||"assettype"===a){let a=e.attributes[t.typeIdField.toUpperCase()];a||(a=e.attributes[t.typeIdField.toLowerCase()]),r=t.typeIdField,s=this._checkSubtype(t,a),""===r&&(t.templates&&t.templates.length>0?(r=t.templates[0]?.name,s=t.templates[0]?.name):(r=t.displayField,s=e.attributes[i]))}else s=this._checkDomain(t.fields,i,s),"string"==typeof s&&(s=this._defaultDisplayField(s,t));else s=this._checkDomain(t.fields,i,s),"string"==typeof s&&(s=this._defaultDisplayField(s,t))}return{field:r,value:s?s.toString():""}}_checkSubtype(e,t){let r=t;if("subtype-sublayer"===e.type){const s=this._checkParentForData(e,"subtypes");s?.length>0&&s.forEach((e=>{e.code===t&&(r=e.name)}))}else if(null!=e.types&&e.types.length>0){const s=e.types.filter((e=>e.id===t));s.length>0&&(r=s[0].name)}return r}_checkDomain(e,t,r){let s=r;const i=e.filter((e=>e.name.toLowerCase()===t.toLowerCase()));if(i.length>0&&N(i[0].domain)&&i[0].domain?.codedValues){const e=i[0].domain.codedValues.filter((({code:e})=>e===r));e.length>0&&(s=e[0].name)}return s}_checkParentForData(e,t){return e.parent?.[t]??null}_defaultDisplayField(e,t){return e.trim()?e:t.templates&&t.templates?.length>0?t.templates[0].name:t.title}get _uniqueFlagId(){return this._flagId++}_groupBy(e,t){return e.reduce(((e,r)=>((e[r[t]]=e[r[t]]||[]).push(r),e)),{})}async _lookupFlagByHit(e){if(null==e.mapPoint)return[];const t=await this.view.hitTest(e.screenPoint,{include:this._validUNLayers}),r=[];if(t.results.length>0){const s=t.results.find((e=>null!==e.layer));if(null!=s.graphic?.geometry)if("polyline"===s.graphic.geometry.type){const t=this._geometryHandler.getPercentageAlong(s.graphic.geometry,e.mapPoint,s.graphic.geometry.spatialReference),i=this._getDisplayField(s.graphic);s.graphic.terminalId=null,s.graphic.isFilterBarrier=!1,s.graphic.allTerminals=null,s.graphic.selectedTerminals=null,s.graphic.percentAlong=t,s.graphic.displayValue=i,s.graphic.mapPoint=s.mapPoint,r.push(s)}else if(("point"===s.graphic.geometry.type||"polygon"===s.graphic.geometry.type)&&null!==this.utilityNetwork){const e=this.utilityNetwork?.getTerminalConfiguration(s.graphic),t=this._getDisplayField(s.graphic);s.graphic.terminalId=e?e.terminals[0].id||null:1,s.graphic.isFilterBarrier=!1,s.graphic.allTerminals=e??null,s.graphic.selectedTerminals=[e?e.terminals[0].id||null:1],s.graphic.percentAlong=null,s.graphic.displayValue=t,s.graphic.mapPoint=s.mapPoint,r.push(s)}}return r}async _populateOutfields(){const e=this.view?.map,t=this.getValidSources();e?.layers.forEach((e=>{"group"===e.type?e.layers.forEach((e=>{t.some((t=>t.layerId===e.layerId))&&e.fields.some((e=>"assetgroup"===e.name.toLowerCase()))&&(e.outFields=["assetgroup","assettype","globalid","objectid"])})):t.some((t=>t.layerId===e.layerId))&&e.fields.some((e=>"assetgroup"===e.name.toLowerCase()))&&(e.outFields=["assetgroup","assettype","globalid","objectid"])}))}_removeGraphic(e){this._getGraphicLayer(H)?.remove(e.mapGraphic)}_createGraphicLayer(e){const{map:t}=this.view;if(!t.findLayerById(e)){const r=new g({title:e,listMode:"hide",id:e});t.add(r)}}_getGraphicLayer(e){const{map:t}=this.view;if(t){const r=t.findLayerById(e);if(r&&B(r))return r}return null}};e([o()],D.prototype,"_activeProgress",void 0),e([o()],D.prototype,"_flags",void 0),e([o()],D.prototype,"traces",void 0),e([o()],D.prototype,"defaultGraphicColor",void 0),e([o()],D.prototype,"enableResultArea",void 0),e([o()],D.prototype,"flags",void 0),e([o()],D.prototype,"gdbVersion",void 0),e([o()],D.prototype,"messages",void 0),e([o()],D.prototype,"messagesUnits",void 0),e([o()],D.prototype,"resultAreaProperties",null),e([o()],D.prototype,"selectedTraces",void 0),e([o()],D.prototype,"selectOnComplete",void 0),e([o()],D.prototype,"showGraphicsOnComplete",void 0),e([o()],D.prototype,"showSelectionAttributes",void 0),e([o({readOnly:!0})],D.prototype,"state",null),e([o()],D.prototype,"traceResults",void 0),e([o()],D.prototype,"utilityNetwork",void 0),e([o({value:null})],D.prototype,"view",null),D=e([n("esri.widgets.UtilityNetworkTrace.UtilityNetworkTraceViewModel")],D);const V=D;export{V as default};