@arcgis/core 5.1.0-next.86 → 5.1.0-next.88

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 (206) hide show
  1. package/Graphic.js +1 -1
  2. package/analysis/LineOfSightAnalysisObserver.d.ts +2 -2
  3. package/analysis/LineOfSightAnalysisTarget.d.ts +2 -2
  4. package/applications/Components/arcadeUtils.d.ts +23 -0
  5. package/applications/Components/arcadeUtils.js +2 -0
  6. package/assets/esri/core/workers/RemoteClient.js +1 -1
  7. package/assets/esri/core/workers/chunks/00e9e25269d5776f8645.js +1 -0
  8. package/assets/esri/core/workers/chunks/015fc0a17b17d69cc3bb.js +1 -0
  9. package/assets/esri/core/workers/chunks/0a6df243b18acae471be.js +1 -0
  10. package/assets/esri/core/workers/chunks/0cc4b3100a7a453bd058.js +1 -0
  11. package/assets/esri/core/workers/chunks/10cf6a70bf79f04a7208.js +1 -0
  12. package/assets/esri/core/workers/chunks/{e9a42f0262fc44a79d4b.js → 164ee62f2211987ad850.js} +1 -1
  13. package/assets/esri/core/workers/chunks/169ca3724053fc046d1b.js +1 -0
  14. package/assets/esri/core/workers/chunks/206bdfd868a9ef88f3a8.js +1 -0
  15. package/assets/esri/core/workers/chunks/2343b1105bc4c1b4a086.js +1 -0
  16. package/assets/esri/core/workers/chunks/{1bad4331a43169f3cc34.js → 2549a07f403447482f4e.js} +1 -1
  17. package/assets/esri/core/workers/chunks/{f89b7b0ccfbd1e5f9a0f.js → 3092184350d66c79f610.js} +1 -1
  18. package/assets/esri/core/workers/chunks/3469df5c4846b0cee012.js +1 -0
  19. package/assets/esri/core/workers/chunks/{26f804c92077c11c626d.js → 394812e19b6915d560b0.js} +1 -1
  20. package/assets/esri/core/workers/chunks/{2f8b173d1dac73ba0d9e.js → 3cf77b7a61f78f9bcd62.js} +1 -1
  21. package/assets/esri/core/workers/chunks/{edbdee69440dbfc05644.js → 3e72bd6dbfc52d956c06.js} +1 -1
  22. package/assets/esri/core/workers/chunks/3feec3d08424b94e1bcf.js +1 -0
  23. package/assets/esri/core/workers/chunks/{ce4dfc3a470230ddc9e4.js → 43f58604ba4a94a9167c.js} +1 -1
  24. package/assets/esri/core/workers/chunks/{ff57a071156d8a7e47be.js → 456d269e3982c437010a.js} +1 -1
  25. package/assets/esri/core/workers/chunks/46b16501db6681dc467b.js +1 -0
  26. package/assets/esri/core/workers/chunks/48549d3d7bf0154c0afa.js +1 -0
  27. package/assets/esri/core/workers/chunks/{713ab619060bd5087479.js → 4baf66314f82cfa76beb.js} +182 -157
  28. package/assets/esri/core/workers/chunks/{1ab66600579fa4232d7b.js → 4dc91c2208201ba34c90.js} +1 -1
  29. package/assets/esri/core/workers/chunks/{b14c4c3f295970f731ab.js → 500be1fb7cc9efec875c.js} +1 -1
  30. package/assets/esri/core/workers/chunks/{fc6ca7ffb9f1b875059c.js → 51716e411fad624ac21c.js} +1 -1
  31. package/assets/esri/core/workers/chunks/54c035cdc171998d0776.js +1 -0
  32. package/assets/esri/core/workers/chunks/{b23e677c33db6f9bac8a.js → 566f6319ded0634769e0.js} +1 -1
  33. package/assets/esri/core/workers/chunks/{701b823763e941b71f4f.js → 7185486c6dc28fc367a1.js} +1 -1
  34. package/assets/esri/core/workers/chunks/752f4e0e2961fc315dca.js +1 -0
  35. package/assets/esri/core/workers/chunks/7ba67f1d7831a5576a5a.js +1 -0
  36. package/assets/esri/core/workers/chunks/{186bfde8c552e3b42302.js → 7ef51b0ebd560113ae7e.js} +1 -1
  37. package/assets/esri/core/workers/chunks/7f0f10946f05a09b5654.js +1 -0
  38. package/assets/esri/core/workers/chunks/{fce2306a1b31c6680f90.js → 7f34fa9f154f5101cb13.js} +1 -1
  39. package/assets/esri/core/workers/chunks/8178e9ba3c568d406a87.js +1 -0
  40. package/assets/esri/core/workers/chunks/83f1871d04c979fa23b7.js +1 -0
  41. package/assets/esri/core/workers/chunks/85da2987e17b6755a94e.js +1 -0
  42. package/assets/esri/core/workers/chunks/8a5a827ee557d9f9a66e.js +1 -0
  43. package/assets/esri/core/workers/chunks/9c09097e390985bbac58.js +1 -0
  44. package/assets/esri/core/workers/chunks/{618106f5fbdf88ef2278.js → a401d44a5b45c05072c2.js} +1 -1
  45. package/assets/esri/core/workers/chunks/{d0aee7c80c5c7e23d216.js → a429355534bf6cbd8304.js} +1 -1
  46. package/assets/esri/core/workers/chunks/a432219de6a873f88776.js +1 -0
  47. package/assets/esri/core/workers/chunks/{455d08294e0f5c5509ff.js → a6b75576d598ec161cc4.js} +1 -1
  48. package/assets/esri/core/workers/chunks/{99c6bd2125f4eb6796fe.js → aae40d70eb01249c1bab.js} +1 -1
  49. package/assets/esri/core/workers/chunks/b2662bfdbd1e3623ceb9.js +1 -0
  50. package/assets/esri/core/workers/chunks/b4bac22467e96be7a974.js +1 -0
  51. package/assets/esri/core/workers/chunks/{5166f204fd078dced5db.js → baea6f86b2dbe067940e.js} +1 -1
  52. package/assets/esri/core/workers/chunks/c3e89c7c7b677bd18557.js +1 -0
  53. package/assets/esri/core/workers/chunks/cb81d524f12edcadb9bb.js +1 -0
  54. package/assets/esri/core/workers/chunks/cc0f3b9b153a0c232afe.js +1 -0
  55. package/assets/esri/core/workers/chunks/cd0c232f4e3868d91a05.js +1 -0
  56. package/assets/esri/core/workers/chunks/{bae8f2a5dfe0cfbc0688.js → d00dddc3881fa29446e1.js} +1 -1
  57. package/assets/esri/core/workers/chunks/{9bd713d96502ddc2ce25.js → d8ccc713c5ad93e7a0c3.js} +1 -1
  58. package/assets/esri/core/workers/chunks/{e66b9d00d02fc08cbb2d.js → da008d6a3afb30d18392.js} +1 -1
  59. package/assets/esri/core/workers/chunks/dde94664110ff231a52d.js +1 -0
  60. package/assets/esri/core/workers/chunks/de3e5d82502ee15b7eae.js +1 -0
  61. package/assets/esri/core/workers/chunks/defac06f9e2b43090677.js +2 -0
  62. package/assets/esri/core/workers/chunks/e6fe8b5fbe95de01453b.js +1 -0
  63. package/assets/esri/core/workers/chunks/ee7e9bca57160694b3c4.js +1 -0
  64. package/assets/esri/core/workers/chunks/f36345ebb9851ab92453.js +1 -0
  65. package/assets/esri/core/workers/chunks/{add000f51c778114c028.js → f37e4ae0e9be80210db0.js} +1 -1
  66. package/assets/esri/core/workers/chunks/{c503c79ba5761f7abbeb.js → fa869bfe4366f7f49cca.js} +1 -1
  67. package/assets/esri/core/workers/chunks/{d8de7fe49dba9ed589df.js → fade7b878a9498382bb2.js} +1 -1
  68. package/assets/esri/core/workers/chunks/fe30e61652716fcccf16.js +2 -0
  69. package/assets/esri/libs/lyr3d/lyr3DMain.wasm +0 -0
  70. package/assets/esri/libs/lyr3d/lyr3DWorker.wasm +0 -0
  71. package/assets/esri/libs/text/pkg/bundle_bg.wasm +0 -0
  72. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_ar.json +1 -1
  73. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_bg.json +1 -1
  74. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_bs.json +1 -1
  75. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_ca.json +1 -1
  76. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_cs.json +1 -1
  77. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_da.json +1 -1
  78. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_de.json +1 -1
  79. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_el.json +1 -1
  80. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_es.json +1 -1
  81. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_et.json +1 -1
  82. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_fi.json +1 -1
  83. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_fr.json +1 -1
  84. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_he.json +1 -1
  85. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_hr.json +1 -1
  86. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_hu.json +1 -1
  87. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_id.json +1 -1
  88. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_it.json +1 -1
  89. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_ja.json +1 -1
  90. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_ko.json +1 -1
  91. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_lt.json +1 -1
  92. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_lv.json +1 -1
  93. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_nl.json +1 -1
  94. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_no.json +1 -1
  95. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_pl.json +1 -1
  96. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_pt-BR.json +1 -1
  97. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_pt-PT.json +1 -1
  98. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_ro.json +1 -1
  99. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_ru.json +1 -1
  100. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_sk.json +1 -1
  101. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_sl.json +1 -1
  102. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_sr.json +1 -1
  103. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_sv.json +1 -1
  104. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_th.json +1 -1
  105. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_tr.json +1 -1
  106. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_uk.json +1 -1
  107. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_vi.json +1 -1
  108. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_zh-CN.json +1 -1
  109. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_zh-HK.json +1 -1
  110. package/assets/esri/views/3d/analysis/ShadowCast/t9n/ShadowCastAnalysis_zh-TW.json +1 -1
  111. package/chunks/GlobalIllumination.glsl.js +25 -17
  112. package/chunks/GlowBlur.glsl.js +11 -8
  113. package/chunks/OITBlend.glsl.js +1 -1
  114. package/chunks/bundle2.js +1 -1
  115. package/config.js +1 -1
  116. package/core/has.js +1 -1
  117. package/interfaces.d.ts +0 -3
  118. package/kernel.js +1 -1
  119. package/layers/Lyr3DWasmPerSceneView.js +1 -1
  120. package/layers/graphics/data/QueryEngineCapabilities.js +1 -1
  121. package/layers/graphics/data/QueryEngineResult.js +1 -1
  122. package/layers/graphics/sources/OGCFeatureSource.js +1 -1
  123. package/layers/graphics/sources/support/ParquetSourceWorker.js +1 -1
  124. package/layers/mixins/ArcGISImageService.js +1 -1
  125. package/layers/support/SubtypeSublayer.js +1 -1
  126. package/layers/support/capabilities.js +1 -1
  127. package/layers/support/layerUtils.js +1 -1
  128. package/layers/support/serviceCapabilitiesUtils.js +1 -1
  129. package/networks/CircuitManager.d.ts +33 -25
  130. package/networks/CircuitManager.js +1 -1
  131. package/networks/support/typeUtils.d.ts +4 -1
  132. package/networks/support/typeUtils.js +1 -1
  133. package/package.json +3 -3
  134. package/renderers/ClassBreaksRenderer.js +1 -1
  135. package/renderers/UniqueValueRenderer.js +1 -1
  136. package/renderers/support/scaleDependentSymbolUtils.js +2 -0
  137. package/rest/networks/circuits/queryCircuits.js +1 -1
  138. package/rest/networks/circuits/support/QueryCircuitsParameters.d.ts +21 -15
  139. package/rest/networks/circuits/support/QueryCircuitsParameters.js +1 -1
  140. package/rest/query/operations/query.js +1 -1
  141. package/rest/support/Query.js +1 -1
  142. package/support/revision.js +1 -1
  143. package/third-party-notices.txt +19 -12
  144. package/views/2d/engine/webgl/GlyphSDFCreator.js +1 -1
  145. package/views/2d/engine/webgl/shaders/sources/shaderRepository.js +1 -1
  146. package/views/3d/analysis/LineOfSight/LineOfSightAuthoringStore.js +2 -0
  147. package/views/3d/analysis/LineOfSight/LineOfSightAuthoringUtils.js +2 -0
  148. package/views/3d/analysis/LineOfSight/LineOfSightController.js +1 -1
  149. package/views/3d/analysis/LineOfSight/LineOfSightDrawToolRenderer.js +2 -0
  150. package/views/3d/analysis/LineOfSight/LineOfSightObserverPlugin.js +2 -0
  151. package/views/3d/analysis/LineOfSight/LineOfSightPlacementTool.js +2 -0
  152. package/views/3d/analysis/LineOfSight/LineOfSightRootPlugin.js +2 -0
  153. package/views/3d/analysis/LineOfSight/LineOfSightTargetPlugin.js +2 -0
  154. package/views/3d/analysis/LineOfSight/LineOfSightTool2.js +1 -1
  155. package/views/3d/analysis/LineOfSightAnalysisView3D.js +1 -1
  156. package/views/3d/layers/FeatureLikeLayerViewBase3D.js +1 -1
  157. package/views/3d/webgl-engine/collections/Component/Material/ComponentTechniqueConfiguration.js +1 -1
  158. package/views/3d/webgl-engine/core/shaderLibrary/shading/ScreenSpaceRayMarching.glsl.js +149 -0
  159. package/views/3d/webgl-engine/core/shaderLibrary/shading/WaterColor.glsl.js +2 -2
  160. package/views/3d/webgl-engine/effects/globalIllumination/GlobalIllumination.glsl.js +1 -1
  161. package/views/3d/webgl-engine/effects/globalIllumination/GlobalIllumination.js +1 -1
  162. package/views/3d/webgl-engine/effects/globalIllumination/GlobalIlluminationTechniqueConfiguration.js +1 -1
  163. package/views/3d/webgl-engine/effects/glow/Glow.js +1 -1
  164. package/views/3d/webgl-engine/materials/WaterTechniqueConfiguration.js +1 -1
  165. package/views/3d/webgl-engine/parts/RenderView.js +1 -1
  166. package/views/3d/webgl-engine/shaders/TerrainTechniqueConfiguration.js +1 -1
  167. package/webmap/utils.js +1 -1
  168. package/widgets/Legend/support/ActiveLayerInfo.js +1 -1
  169. package/assets/esri/core/workers/chunks/0c074c46d106ca4d3bad.js +0 -1
  170. package/assets/esri/core/workers/chunks/1f16bc8c02d8c4b2f693.js +0 -1
  171. package/assets/esri/core/workers/chunks/29878b52aa12b3815230.js +0 -1
  172. package/assets/esri/core/workers/chunks/2c916b93d8a6e6b9c0d7.js +0 -1
  173. package/assets/esri/core/workers/chunks/3ea5a18b264628dc37f0.js +0 -1
  174. package/assets/esri/core/workers/chunks/41913575dd45c65d645e.js +0 -1
  175. package/assets/esri/core/workers/chunks/46e622857ba92a72a317.js +0 -1
  176. package/assets/esri/core/workers/chunks/49e8144effc299dfcd66.js +0 -1
  177. package/assets/esri/core/workers/chunks/4d0f793dee4ad919221b.js +0 -1
  178. package/assets/esri/core/workers/chunks/65ac73de5bb133c6bf89.js +0 -1
  179. package/assets/esri/core/workers/chunks/67ec1694d6e18b7c234c.js +0 -1
  180. package/assets/esri/core/workers/chunks/6e526c06825ecc6c99c0.js +0 -1
  181. package/assets/esri/core/workers/chunks/6f7aaba26773fe416ac2.js +0 -1
  182. package/assets/esri/core/workers/chunks/7acf82763aeba44049d0.js +0 -1
  183. package/assets/esri/core/workers/chunks/88eb1e4320c4ada01711.js +0 -1
  184. package/assets/esri/core/workers/chunks/8af9a78cf316581ea482.js +0 -1
  185. package/assets/esri/core/workers/chunks/96bba4d93a32ad34a1c8.js +0 -1
  186. package/assets/esri/core/workers/chunks/97719271a3e4c9f2b2c9.js +0 -1
  187. package/assets/esri/core/workers/chunks/9ea23cd4b2664c08b670.js +0 -1
  188. package/assets/esri/core/workers/chunks/a1a12552d34ea9eea130.js +0 -1
  189. package/assets/esri/core/workers/chunks/a844547bf33a8527ee9f.js +0 -2
  190. package/assets/esri/core/workers/chunks/ac5999c88c27b49cd760.js +0 -1
  191. package/assets/esri/core/workers/chunks/b575292013bceef9b015.js +0 -1
  192. package/assets/esri/core/workers/chunks/bbc27d9285162696d089.js +0 -1
  193. package/assets/esri/core/workers/chunks/bc8a74da48b08309875f.js +0 -1
  194. package/assets/esri/core/workers/chunks/cd7159600ce132e32d04.js +0 -1
  195. package/assets/esri/core/workers/chunks/ce66c551b7083913eee5.js +0 -1
  196. package/assets/esri/core/workers/chunks/cf7acf5acb6d322fd996.js +0 -1
  197. package/assets/esri/core/workers/chunks/d9c3f14eee4db7a7137b.js +0 -1
  198. package/assets/esri/core/workers/chunks/db3c484bfa607dec6050.js +0 -1
  199. package/assets/esri/core/workers/chunks/dcc719e15b2e0cce1f3b.js +0 -1
  200. package/assets/esri/core/workers/chunks/ded2f19a1685db2137f4.js +0 -2
  201. package/assets/esri/core/workers/chunks/f43d628d47eec7d530c7.js +0 -1
  202. package/assets/esri/core/workers/chunks/fae147d03ed723ab234d.js +0 -1
  203. package/assets/esri/core/workers/chunks/fcf51697c361e0075cc2.js +0 -1
  204. package/views/3d/webgl-engine/core/shaderLibrary/shading/ScreenSpaceReflections.glsl.js +0 -132
  205. /package/assets/esri/core/workers/chunks/{ded2f19a1685db2137f4.js.LICENSE.txt → defac06f9e2b43090677.js.LICENSE.txt} +0 -0
  206. /package/assets/esri/core/workers/chunks/{a844547bf33a8527ee9f.js.LICENSE.txt → fe30e61652716fcccf16.js.LICENSE.txt} +0 -0
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import{insertSortedStableTopN as e}from"../../../core/arrayUtils.js";import{clone as t}from"../../../core/lang.js";import i from"../../../geometry/SpatialReference.js";import{polygonCentroid as s,extentCentroid as a}from"../../../geometry/support/centroid.js";import{getPolygonExtent as r,getGeometryExtent as n}from"../../../geometry/support/extentUtils.js";import{toQuantizationTransform as o}from"../../../geometry/support/quantizationUtils.js";import{isValid as l,equals as u}from"../../../geometry/support/spatialReferenceUtils.js";import{closestPointOnCurve as c}from"../../../geometry/support/curves/closestPointOnCurve.js";import{getEndpoint as m,isCoordinate as d,cloneCurve as f}from"../../../geometry/support/curves/curveUtils.js";import p from"./AttributesBuilder.js";import{cleanFromGeometryEngine as h,getGeometry as y,transformCentroid as g}from"./geometryUtils.js";import{project as x}from"./projectionSupport.js";import{getDateInNumber as I}from"./queryUtils.js";import{SnappingCandidateEdge as T,SnappingCandidateVertex as F}from"./SnappingCandidate.js";import{isDateField as _,isDateOnlyField as v,isTimestampOffsetField as V,isStringField as S,isTimeOnlyField as b}from"../../support/fieldUtils.js";import R from"../../../rest/support/AutoIntervalBinParameters.js";import z from"../../../rest/support/DateBinParameters.js";import{unitsDict as B}from"../../../rest/support/DateBinUtils.js";import M from"../../../rest/support/FixedBoundariesBinParameters.js";import A from"../../../rest/support/FixedIntervalBinParameters.js";import{calculateStringStatistics as N,calculateStatistics as w,processSummaryStatisticsResult as D,calculateUniqueValuesCount as P,createUVResult as q,calculateClassBreaks as O,resolveCBResult as j,calculateHistogram as C,calculatePercentile as G,binIndex as Z,getBinParams as E,isNullCountSupported as H,getAttributeComparator as U}from"../../../statistics/utils.js";import{utc as k}from"../../../time/constants.js";import{DateTime as J}from"luxon";const Q="bin";class Y{constructor(e,t,i){this.items=e,this.query=t,this.geometryType=i.geometryType,this.hasZ=!!t.returnZ&&i.hasZ,this.hasM=!!t.returnM&&i.hasM,this.fieldsIndex=i.fieldsIndex,this.spatialReference=i.spatialReference,this.featureAdapter=i.featureAdapter,this.featureIdInfo=i.featureIdInfo}get size(){return this.items.length}createQueryResponseForCount(){const e=new p(this.query,this.featureAdapter,this.fieldsIndex);if(!this.query.outStatistics)return e.countDistinctValues(this.items);const{groupByFieldsForStatistics:t,having:i,outStatistics:s}=this.query,a=t?.length;if(!!!a)return 1;const r=new Map,n=new Map,o=new Set;for(const l of s){const{statisticType:s}=l,a="exceedslimit"!==s?l.onStatisticField:void 0;if(!n.has(a)){const i=[];for(const s of t){const t=this._getAttributeValues(e,s,this.items,r);i.push(t)}n.set(a,this._calculateUniqueValues(i,this.items,e.returnDistinctValues))}const u=n.get(a);for(const t in u){const{data:s,items:a}=u[t],r=s.join(",");i&&!e.validateItems(a,i)||o.add(r)}}return o.size}async createQueryResponse(){let e;if(this.query.outStatistics){e=this.query.outStatistics.some(e=>"exceedslimit"===e.statisticType)?this._createExceedsLimitQueryResponse():await this._createStatisticsQueryResponse(this.query,this.items)}else e=this._createFeatureQueryResponse(this.query);if(this.query.returnQueryGeometry){const t=this.query.geometry;l(this.query.outSR)&&!u(t.spatialReference,this.query.outSR)?e.queryGeometry=h({spatialReference:this.query.outSR,...x(t,t.spatialReference,this.query.outSR)}):e.queryGeometry=h({spatialReference:this.query.outSR,...t})}return e}createSnappingResponse(e,t,i){const s=this.featureAdapter,{point:a}=e,r="number"==typeof e.distance?e.distance:e.distance.x,n="number"==typeof e.distance?e.distance:e.distance.y;function o(e,t){const i=(e-a.x)/r,s=(t-a.y)/n;return i*i+s*s}const l={candidates:[]},u="esriGeometryPolygon"===this.geometryType,p="esriGeometryPolyline"===this.geometryType||"esriGeometryPoint"===this.geometryType,h=this._getPointCreator(t,this.spatialReference,i),y=new L(null,0),g=new L(null,0),x={x:0,y:0,z:0};for(const c of this.items){const e=s.getObjectId(c),t=s.getGeometryWithCurves?.(c);if(null!=t){_(t,e);continue}const i=s.getGeometry(c);null==i||I(i,e)}return l.candidates.sort((e,t)=>e.distance-t.distance),l;function I(t,i){const{coords:s,stride:r}=t,n=t.isPoint?W:t.lengths;if(y.coords=s,g.coords=s,e.returnEdge){let e=0;for(let t=0;t<n.length;t++){const s=n[t],c=e;for(let t=0;t<s;t++,e+=r){if(!u&&t===s-1)continue;if(y.coordsIndex=e,g.coordsIndex=t===s-1?c:e+r,!X(x,a,y,g))continue;const n=o(x.x,x.y);n<=1&&l.candidates.push(new T(i,h(x),Math.sqrt(n),h(y),h(g)))}}}if("all"===e.vertexMode){let e=0;for(let t=0;t<n.length;t++){const s=n[t],a=e,c=g;c.coordsIndex=a;for(let t=0;t<s;t++,e+=r){if(y.coordsIndex=e,u&&t===s-1&&y.x===c.x&&y.y===c.y)continue;const a=o(y.x,y.y);a<=1&&l.candidates.push(new F(i,h(y),Math.sqrt(a)))}}}else if(p&&"ends"===e.vertexMode){let e=0;const t=[];for(let i=0;i<n.length;i++){t.push(e);const s=n[i];e+=s*r,s>1&&t.push(e-r)}for(const s of t){y.coordsIndex=s;const e=o(y.x,y.y);e<=1&&l.candidates.push(new F(i,h(y),Math.sqrt(e)))}}}function _(t,i){const{candidates:s}=l,r={x:0,y:0,z:0};if(e.returnEdge){const e=[a.x,a.y],n=new L(e,0),l=new L(e,0);for(const{segments:a}of t.parts)for(const{start:t,curve:u}of a){const{curvePoint:a}=c(t,u,e),p=o(...a);if(p>1)continue;[r.x,r.y]=a,n.coords=t,l.coords=m(u);const y=d(u)?null:f(u);s.push(new T(i,h(r),Math.sqrt(p),h(n),h(l),!1,y))}}function n(e){r.x=t.vertexXY[2*e],r.y=t.vertexXY[2*e+1];const a=o(r.x,r.y);a>1||(r.z=t.vertexZ?.[e]??0,s.push(new F(i,h(r),Math.sqrt(a))))}if("all"===e.vertexMode){const{vertexCount:e}=t;for(let t=0;t<e;++t)n(t);return}if("ends"===e.vertexMode)switch(t.type){case"point":n(0);break;case"polyline":for(let e=0;e<t.partCount;++e){const i=t.partOffsets[e],s=t.partOffsets[e+1]-1;n(i),s!==i&&n(s)}}}}_getPointCreator(e,t,i){const s=null==i||u(t,i)?e=>e:e=>x(e,t,i),{hasZ:a}=this,r=0;return a&&e?({x:e,y:t,z:i})=>s({x:e,y:t,z:i}):({x:e,y:t})=>s({x:e,y:t,z:r})}async createSummaryStatisticsResponse(e){const{field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:r,minValue:n,maxValue:o,scale:l,timeZone:u,outStatisticTypes:c}=e,m=this.fieldsIndex.get(t),d=_(m)||v(m)||V(m),f=await this._getDataValues({field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:r,scale:l,timeZone:u},this.items),p=H({normalizationType:a,normalizationField:s,minValue:n,maxValue:o}),h={value:.5,fieldType:m?.type},y=S(m)?N({values:f,supportsNullCount:p,percentileParams:h,outStatisticTypes:c}):w({values:f,minValue:n,maxValue:o,useSampleStdDev:!a,supportsNullCount:p,percentileParams:h,outStatisticTypes:c});return D(y,c,d)}async createUniqueValuesResponse(e){const{field:t,valueExpression:i,domains:s,returnAllCodedValues:a,scale:r,timeZone:n}=e,o=await this._getDataValues({field:t,field2:e.field2,field3:e.field3,fieldDelimiter:e.fieldDelimiter,valueExpression:i,scale:r,timeZone:n},this.items,!1),l=P(o);return q(l,s,a,e.fieldDelimiter)}async createClassBreaksResponse(e){const{field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:r,classificationMethod:n,standardDeviationInterval:o,minValue:l,maxValue:u,numClasses:c,scale:m,timeZone:d}=e,f=await this._getDataValues({field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:r,scale:m,timeZone:d},this.items),p=O(f,{field:t,normalizationField:s,normalizationType:a,normalizationTotal:r,classificationMethod:n,standardDeviationInterval:o,minValue:l,maxValue:u,numClasses:c});return j(p,n)}async createHistogramResponse(e){const{field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:r,classificationMethod:n,standardDeviationInterval:o,minValue:l,maxValue:u,numBins:c,scale:m,timeZone:d}=e,f=await this._getDataValues({field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:r,scale:m,timeZone:d},this.items);return C(f,{field:t,normalizationField:s,normalizationType:a,normalizationTotal:r,classificationMethod:n,standardDeviationInterval:o,minValue:l,maxValue:u,numBins:c})}_sortFeatures(e,t,i){if(e.length>1&&t?.length)for(const s of t.slice().reverse()){const{compare:t,fieldOrExpression:a,fieldInfo:r}=K(s,this.fieldsIndex);e.sort((e,s)=>t(i(e,a,r),i(s,a,r)))}}_topNFeatures(t,i,s,a){if(t.length>1&&i?.length){const r=i.map(e=>{const{compare:t,fieldOrExpression:i,fieldInfo:s}=K(e,this.fieldsIndex);return(e,r)=>t(a(e,i,s),a(r,i,s))}).reduceRight((e,t)=>(i,s)=>{const a=t(i,s);return 0===a||Number.isNaN(a)?e(i,s):a}),n=[];for(const i of t)e(n,i,s,r);return n}return t.slice(0,s)}_createFeatureQueryResponse(e){const{items:t,geometryType:i,hasM:s,hasZ:a,featureIdInfo:r,spatialReference:n}=this,{outFields:l,outSR:u,quantizationParameters:c,resultRecordCount:m,resultOffset:d,returnZ:f,returnM:p}=e,y=null!=m&&t.length>(d||0)+m,g=l&&(l.includes("*")?[...this.fieldsIndex.fields]:l.map(e=>this.fieldsIndex.get(e)));return{exceededTransferLimit:y,features:this._createFeatures(e,t),fields:g,geometryType:i,hasM:s&&p,hasZ:a&&f,objectIdFieldName:"object-id"===r.type?r.fieldName:null,spatialReference:h(u||n),transform:c&&o(c)||null}}_createFeatures(e,t){const i=new p(e,this.featureAdapter,this.fieldsIndex),{hasM:s,hasZ:a}=this,{orderByFields:r,quantizationParameters:n,returnGeometry:l,returnCentroid:u,maxAllowableOffset:c,resultOffset:m,resultRecordCount:d,returnZ:f=!1,returnM:h=!1}=e,x=a&&f,I=s&&h;let T;const F=m||0,_=null!=d?F+d:null;null!=_&&_<=5e3&&_<t.length?T=this._topNFeatures(t,r,_,(e,t,s)=>i.getFieldValue(e,t,s)):(T=[...t],this._sortFeatures(T,r,(e,t,s)=>i.getFieldValue(e,t,s))),(F>0||null!=_)&&(T=T.slice(F,_??void 0));const v=[];let V=0;if(this.geometryType&&(l||u)){const e=o(n)??void 0,t="esriGeometryPolygon"===this.geometryType||"esriGeometryPolyline"===this.geometryType;if(l&&!u)for(const s of T){const a=this.featureAdapter.getGeometry(s),r=this._addFeatureJSONMetadata(s,{attributes:i.getAttributes(s),geometry:y(this.geometryType,a,c,e,x,I)});t&&a&&!r.geometry&&(r.centroid=g(this,this.featureAdapter.getCentroid(s,this),e)),v[V++]=r}else if(!l&&u)for(const s of T)v[V++]=this._addFeatureJSONMetadata(s,{attributes:i.getAttributes(s),centroid:g(this,this.featureAdapter.getCentroid(s,this),e)});else for(const s of T)v[V++]=this._addFeatureJSONMetadata(s,{attributes:i.getAttributes(s),centroid:g(this,this.featureAdapter.getCentroid(s,this),e),geometry:y(this.geometryType,this.featureAdapter.getGeometry(s),c,e,x,I)})}else for(const o of T){const e=i.getAttributes(o);e&&(v[V++]=this._addFeatureJSONMetadata(o,{attributes:e}))}return v}_addFeatureJSONMetadata(e,t){const i=this.featureAdapter.getMetadata?.(e);return void 0!==i&&(t.metadata=i),t}_createExceedsLimitQueryResponse(){let e=!1,t=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,s=Number.POSITIVE_INFINITY;for(const a of this.query.outStatistics??[])if("exceedslimit"===a.statisticType){t=null!=a.maxPointCount?a.maxPointCount:Number.POSITIVE_INFINITY,i=null!=a.maxRecordCount?a.maxRecordCount:Number.POSITIVE_INFINITY,s=null!=a.maxVertexCount?a.maxVertexCount:Number.POSITIVE_INFINITY;break}if("esriGeometryPoint"===this.geometryType)e=this.items.length>t;else if(this.items.length>i)e=!0;else{e=this.items.reduce((e,t)=>{const i=this.featureAdapter.getGeometry(t);return e+(i?.size??0)},0)>s}return{fields:[{name:"exceedslimit",type:"esriFieldTypeInteger",alias:"exceedslimit",sqlType:"sqlTypeInteger",domain:null,defaultValue:null}],features:[{attributes:{exceedslimit:Number(e)}}]}}async _createStatisticsQueryResponse(e,t,i={attributes:{}}){const s=[],a=new Map,r=new Map,n=new Map,o=new Map,l=new p(e,this.featureAdapter,this.fieldsIndex),u=e.outStatistics,{groupByFieldsForStatistics:c,having:m,orderByFields:d,resultRecordCount:f}=e,h=c?.length,y=!!h,g=y?c[0]:null,x=y&&!this.fieldsIndex.get(g);for(const p of u??[]){const{outStatisticFieldName:e,statisticType:u}=p,d=p,f="exceedslimit"!==u?p.onStatisticField:void 0,I="percentile_disc"===u||"percentile_cont"===u,T="EnvelopeAggregate"===u||"CentroidAggregate"===u||"ConvexHullAggregate"===u,F=y&&1===h&&(f===g||x)&&"count"===u;if(y){if(!n.has(f)){const e=[];for(const i of c){const s=this._getAttributeValues(l,i,t,a);e.push(s)}n.set(f,this._calculateUniqueValues(e,t,!T&&l.returnDistinctValues))}const i=n.get(f);if(!i)continue;const s=Object.keys(i);for(const r of s){const{count:s,data:n,items:u,itemPositions:p}=i[r],h=n.join(",");if(!m||l.validateItems(u,m)){const i=o.get(h)||{attributes:{}};if(T){i.aggregateGeometries||(i.aggregateGeometries={});const{aggregateGeometries:e,outStatisticFieldName:t}=await this._getAggregateGeometry(d,u);i.aggregateGeometries[t]=e}else{let r=null;if(F)r=s;else{const e=this._getAttributeValues(l,f,t,a),i=p.map(t=>e[t]);r=I&&"statisticParameters"in d?this._getPercentileValue(d,i):this._getStatisticValue(d,i,null,l.returnDistinctValues)}i.attributes[e]=r}let r=0;c.forEach((e,t)=>i.attributes[this.fieldsIndex.get(e)?e:"EXPR_"+ ++r]=n[t]),o.set(h,i)}}}else if(T){i.aggregateGeometries||(i.aggregateGeometries={});const{aggregateGeometries:e,outStatisticFieldName:s}=await this._getAggregateGeometry(d,t);i.aggregateGeometries[s]=e}else{const s=this._getAttributeValues(l,f,t,a);i.attributes[e]=I&&"statisticParameters"in d?this._getPercentileValue(d,s):this._getStatisticValue(d,s,r,l.returnDistinctValues)}const _="min"!==u&&"max"!==u||!S(this.fieldsIndex.get(f))&&!this._isAnyDateField(f)?null:this.fieldsIndex.get(f)?.type;s.push({name:e,alias:e,type:_||"esriFieldTypeDouble"})}const I=y?Array.from(o.values()):[i];return this._sortFeatures(I,d,(e,t)=>e.attributes[t]),f&&(I.length=Math.min(f,I.length)),{fields:s,features:I}}_isAnyDateField(e){const t=this.fieldsIndex.get(e);return _(t)||v(t)||V(t)||b(t)}async _getAggregateGeometry(e,t){const{convexHull:i,union:o}=await import("../../../geometry/geometryEngineJSON.js"),{statisticType:l,outStatisticFieldName:u}=e,{featureAdapter:c,spatialReference:m,geometryType:d}=this,f=t.map(e=>y(d,c.getGeometry(e))),p=i(m,f,!0)[0],h={aggregateGeometries:null,outStatisticFieldName:null};if("EnvelopeAggregate"===l){const e=p?r(p):n(o(m,f));h.aggregateGeometries={...e,spatialReference:m},h.outStatisticFieldName=u||"extent"}else if("CentroidAggregate"===l){const e=p?s(p):a(n(o(m,f)));h.aggregateGeometries={x:e[0],y:e[1],spatialReference:m},h.outStatisticFieldName=u||"centroid"}else"ConvexHullAggregate"===l&&(h.aggregateGeometries=p,h.outStatisticFieldName=u||"convexHull");return h}_getStatisticValue(e,t,i,s){const{onStatisticField:a,statisticType:r}=e;let n=null;n=i?.has(a)?i.get(a):S(this.fieldsIndex.get(a))||this._isAnyDateField(a)?N({values:t,returnDistinct:s}):w({values:s?[...new Set(t)]:t,minValue:null,maxValue:null,useSampleStdDev:!0}),i&&i.set(a,n);return n["var"===r?"variance":r]}_getPercentileValue(e,t){const{onStatisticField:i,statisticParameters:s,statisticType:a}=e,{value:r,orderBy:n}=s,o=this.fieldsIndex.get(i);return G(t,{value:r,orderBy:n,fieldType:o?.type,isDiscrete:"percentile_disc"===a})}_getAttributeValues(e,t,i,s){if(s.has(t))return s.get(t);const a=this.fieldsIndex.get(t),r=i.map(i=>e.getFieldValue(i,t,a));return s.set(t,r),r}_calculateUniqueValues(e,t,i){const s={},a=t.length;for(let r=0;r<a;r++){const a=t[r],n=[];for(const t of e)n.push(t[r]);const o=n.join(",");null==s[o]?s[o]={count:1,data:n,items:[a],itemPositions:[r]}:(i||s[o].count++,s[o].items.push(a),s[o].itemPositions.push(r))}return s}async _getDataValues(e,s,a=!0){const r=new p(this.query,this.featureAdapter,this.fieldsIndex),{valueExpression:n,scale:o,timeZone:l}=e,u=i.fromJSON(this.query.outSR||this.spatialReference);return n?r.getExpressionValues(s,n,{viewingMode:"map",scale:o,spatialReference:u},{geometryType:this.geometryType,hasZ:this.hasZ,hasM:this.hasM},l):r.getDataValues(s,t(e),a)}_calculateHistogramBins(e,t,i){if(null==t.min&&null==t.max)return[];const s=t.intervals,a=t.min??0,r=t.max??0,n=s.map(([e,t])=>({minValue:e,maxValue:t,count:0,items:[]}));for(let o=0;o<e.length;o++){const t=e[o],l=i[o];if(null!=t&&t>=a&&t<=r){const e=Z(s,t);e>-1&&(n[e].count++,n[e].items.push(l))}}return n}async createQueryBinsResponse(e){const t=e.bin?.splitBy;if(!t)return this._createBinsResponse(e);const{value:i,outAlias:s,valueType:a}=t,r=[],n=[{name:s??i,alias:s??i,type:a??"esriFieldTypeString"},{name:Q,alias:Q,type:"esriFieldTypeInteger"}],o=new p(e,this.featureAdapter,this.fieldsIndex),l=new Map,u=[...this.items];this._sortFeatures(u,[i],(e,t,i)=>o.getFieldValue(e,t,i));const c=this._getAttributeValues(o,i,u,l),m=this._calculateUniqueValues([c],u,o.returnDistinctValues);for(const d in m){const{items:t}=m[d],a=await this._createBinsResponse(e,t);if(r.push(...a.features.map(e=>({...e,attributes:{...e.attributes,[s??i]:d}}))),a.fields)for(const e of a.fields)n.some(t=>t.name===e.name)||n.push(e)}return{fields:n,features:r}}async _createBinsResponse(e,t){const i=e.bin;switch(t=t??this.items,i.type){case"autoIntervalBin":return this._createAutoIntervalBinsResponse(R.fromJSON(i),e,t);case"dateBin":return this._createDateBinsResponse(z.fromJSON(i),e,t);case"fixedBoundariesBin":return this._createFixedBoundariesBinsResponse(M.fromJSON(i),e,t);case"fixedIntervalBin":return this._createFixedIntervalBinsResponse(A.fromJSON(i),e,t)}}async _createAutoIntervalBinsResponse(e,t,i){const{field:s,normalizationField:a,numBins:r,normalizationType:n,normalizationTotal:o,start:l,end:u}=e,c=await this._getDataValues({field:e.field||e.expression,normalizationField:e.normalizationField,normalizationType:e.normalizationType,normalizationTotal:e.normalizationTotal,timeZone:t.outTimeReference?.ianaTimeZone},i),m=E(c,{field:s,normalizationField:a,normalizationType:n,normalizationTotal:o,numBins:r,minValue:I(n?e.normalizationMinValue:l,!1),maxValue:I(n?e.normalizationMaxValue:u,!1)}),d=this._calculateHistogramBins(c,m,i);return this._createFeaturesFromHistogramBins(d,t)}async _createDateBinsResponse(e,t,i){const{field:s,interval:a,start:r,end:n,snapToData:o,returnFullIntervalBin:l,offset:u,firstDayOfWeek:c}=e,m=a.unit,d=await this._getDataValues({field:s||e.expression,timeZone:t.outTimeReference?.ianaTimeZone},i),f=b(this.fieldsIndex.get(s)),p=B.toJSON(m),h=d.filter(Boolean).sort((e,t)=>e-t),y=null!=r?I(r,f):h[0],g=null!=n?I(n,f):h[h.length-1],x=[];if(null!=y&&null!=g){const e={zone:t.outTimeReference?.ianaTimeZone??k},i=u?.unit?B.toJSON(u.unit):"milliseconds",s={[i]:u?.value||0},r=J.fromMillis(y,e).minus(s),n=J.fromMillis(g,e).minus(s),m="number"==typeof c&&c>=1&&c<=7?c:7,d=(e,t)=>{const i=(e.weekday-t+7)%7;return e.minus({days:i}).startOf("day")};if("last"===o){let e="week"===p?((e,t)=>d(e,t).plus({days:7}))(n,m):n;for(;e>r;){const t=e.minus({[p]:a.value});if(t<r){x.unshift([l?t.plus(s).toMillis():r.plus(s).toMillis(),e.plus(s).toMillis()]);break}x.unshift([t.plus(s).toMillis(),e.plus(s).toMillis()]),e=t}}else{let e="first"===o?r:"week"===p?d(r,m):r.startOf(p);for(;e<=n;){const t=e.plus({[p]:a.value});if(t>n){x.push([e.plus(s).toMillis(),l?t.plus(s).toMillis():n.plus(s).toMillis()]);break}x.push([e.plus(s).toMillis(),t.plus(s).toMillis()]),e=t}}}const T=this._calculateHistogramBins(d,{intervals:x,min:y,max:g},i);return this._createFeaturesFromHistogramBins(T,t)}async _createFixedBoundariesBinsResponse(e,t,i){const{field:s}=e,a=await this._getDataValues({field:s||e.expression,timeZone:t.outTimeReference?.ianaTimeZone},i),r=b(this.fieldsIndex.get(s)),n=e.boundaries.map(e=>I(e,r)).sort((e,t)=>e-t),o=[];for(let c=0;c<n.length-1;c++)o.push([n[c],n[c+1]]);const l={intervals:o,min:n.at(0),max:n.at(-1)},u=this._calculateHistogramBins(a,l,i);return this._createFeaturesFromHistogramBins(u,t)}async _createFixedIntervalBinsResponse(e,t,i){const{field:s,interval:a,normalizationType:r,start:n,end:o}=e,l=await this._getDataValues({field:s||e.expression,normalizationField:e.normalizationField,normalizationType:r,normalizationTotal:e.normalizationTotal,timeZone:t.outTimeReference?.ianaTimeZone},i),u=b(this.fieldsIndex.get(s)),c=E(l,{field:s,classificationMethod:"defined-interval",definedInterval:a,minValue:I(r?e.normalizationMinValue:n,u),maxValue:I(r?e.normalizationMaxValue:o,u)},!0),m=this._calculateHistogramBins(l,c,i);return this._createFeaturesFromHistogramBins(m,t)}async _createFeaturesFromHistogramBins(e,t){const{upperBoundaryAlias:i,lowerBoundaryAlias:s}=t,a=s||"lowerBoundary",r=i||"upperBoundary",n=[],o=[{name:a,alias:a,type:"esriFieldTypeDouble"},{name:r,alias:r,type:"esriFieldTypeDouble"}],l=t.bin?.stackBy?.value,u=t.bin?.stackBy?.outAlias;l&&o.push({name:Q,alias:Q,type:"esriFieldTypeInteger"},{name:u??l,alias:u??l,type:"esriFieldTypeString"});let c=0;const m="dateBin"===t.bin.type,d=t.outTimeReference?.ianaTimeZone;for(const f of e){const{minValue:e,maxValue:i,items:s}=f,p={attributes:{}};let h;if(p.attributes[a]=m&&d&&null!=e?J.fromMillis(e,{zone:d}).toISO():e,t.bin.hideUpperBound||(p.attributes[r]=m&&d&&null!=i?J.fromMillis(i,{zone:d}).toISO():i),l?(h=await this._createStatisticsQueryResponse({...t,groupByFieldsForStatistics:[l],orderByFields:[l]},s),p.attributes[Q]=++c,"flat"===t.bin.jsonStyle?n.push(...h.features.map(({attributes:{EXPR_1:e,...t},...i})=>({...i,attributes:u??e?{...t,[u??e]:e,...p.attributes}:{...t,...p.attributes}}))):(p.stackedAttributes=h.features.map(({attributes:{EXPR_1:e,...t}})=>u??e?{...t,[u??e]:e}:t),n.push(p))):(t.bin?.splitBy&&(p.attributes[Q]=++c),h=await this._createStatisticsQueryResponse(t,s,p),n.push(p)),h.fields)for(const t of h.fields)o.some(e=>e.name===t.name)||o.push(t)}return"desc"===t.binOrder&&n.reverse(),{fields:o,features:n}}}function X(e,t,i,s){const a=s.x-i.x,r=s.y-i.y,n=t.x-i.x,o=t.y-i.y,l=a*a+r*r;if(0===l)return!1;const u=n*a+o*r,c=Math.min(1,Math.max(0,u/l));return e.x=i.x+a*c,e.y=i.y+r*c,!0}class L{constructor(e,t){this.coords=e,this.coordsIndex=t}get x(){return this.coords[this.coordsIndex]}get y(){return this.coords[this.coordsIndex+1]}get z(){return this.coords[this.coordsIndex+2]}}const W=[1];function K(e,t){const i=e.split(" "),s=i[0],a=t.get(s),r=!!i[1]&&"desc"===i[1].toLowerCase();return{compare:U(a?.type,r,"case-insensitive"),fieldOrExpression:s,fieldInfo:a}}export{Y as QueryEngineResult};
2
+ import{insertSortedStableTopN as e}from"../../../core/arrayUtils.js";import{clone as t}from"../../../core/lang.js";import i from"../../../geometry/SpatialReference.js";import{polygonCentroid as s,extentCentroid as a}from"../../../geometry/support/centroid.js";import{getPolygonExtent as r,getGeometryExtent as n}from"../../../geometry/support/extentUtils.js";import{toQuantizationTransform as o}from"../../../geometry/support/quantizationUtils.js";import{isValid as l,equals as u}from"../../../geometry/support/spatialReferenceUtils.js";import{closestPointOnCurve as c}from"../../../geometry/support/curves/closestPointOnCurve.js";import{getEndpoint as m,isCoordinate as d,cloneCurve as f}from"../../../geometry/support/curves/curveUtils.js";import p from"./AttributesBuilder.js";import{cleanFromGeometryEngine as h,getGeometry as y,transformCentroid as g}from"./geometryUtils.js";import{project as x}from"./projectionSupport.js";import{getDateInNumber as I}from"./queryUtils.js";import{SnappingCandidateEdge as T,SnappingCandidateVertex as F}from"./SnappingCandidate.js";import{isDateField as _,isDateOnlyField as v,isTimestampOffsetField as V,isStringField as S,isTimeOnlyField as b}from"../../support/fieldUtils.js";import R from"../../../rest/support/AutoIntervalBinParameters.js";import z from"../../../rest/support/DateBinParameters.js";import{unitsDict as B}from"../../../rest/support/DateBinUtils.js";import M from"../../../rest/support/FixedBoundariesBinParameters.js";import A from"../../../rest/support/FixedIntervalBinParameters.js";import{calculateStringStatistics as N,calculateStatistics as w,processSummaryStatisticsResult as D,calculateUniqueValuesCount as P,createUVResult as O,calculateClassBreaks as q,resolveCBResult as j,calculateHistogram as C,calculatePercentile as G,binIndex as Z,getBinParams as E,isNullCountSupported as H,getAttributeComparator as U}from"../../../statistics/utils.js";import{utc as k}from"../../../time/constants.js";import{DateTime as J}from"luxon";const Q="bin";class Y{constructor(e,t,i){this.items=e,this.query=t,this.geometryType=i.geometryType,this.hasZ=!!t.returnZ&&i.hasZ,this.hasM=!!t.returnM&&i.hasM,this.fieldsIndex=i.fieldsIndex,this.spatialReference=i.spatialReference,this.featureAdapter=i.featureAdapter,this.featureIdInfo=i.featureIdInfo}get size(){return this.items.length}createQueryResponseForCount(){const e=new p(this.query,this.featureAdapter,this.fieldsIndex);if(!this.query.outStatistics)return e.countDistinctValues(this.items);const{groupByFieldsForStatistics:t,having:i,outStatistics:s}=this.query,a=t?.length;if(!!!a)return 1;const r=new Map,n=new Map,o=new Set;for(const l of s){const{statisticType:s}=l,a="exceedslimit"!==s?l.onStatisticField:void 0;if(!n.has(a)){const i=[];for(const s of t){const t=this._getAttributeValues(e,s,this.items,r);i.push(t)}n.set(a,this._calculateUniqueValues(i,this.items,e.returnDistinctValues))}const u=n.get(a);for(const t in u){const{data:s,items:a}=u[t],r=s.join(",");i&&!e.validateItems(a,i)||o.add(r)}}return o.size}async createQueryResponse(){let e;if(this.query.outStatistics){e=this.query.outStatistics.some(e=>"exceedslimit"===e.statisticType)?this._createExceedsLimitQueryResponse():await this._createStatisticsQueryResponse(this.query,this.items)}else e=this._createFeatureQueryResponse(this.query);if(this.query.returnQueryGeometry){const t=this.query.geometry;l(this.query.outSR)&&!u(t.spatialReference,this.query.outSR)?e.queryGeometry=h({spatialReference:this.query.outSR,...x(t,t.spatialReference,this.query.outSR)}):e.queryGeometry=h({spatialReference:this.query.outSR,...t})}return e}createSnappingResponse(e,t,i){const s=this.featureAdapter,{point:a}=e,r="number"==typeof e.distance?e.distance:e.distance.x,n="number"==typeof e.distance?e.distance:e.distance.y;function o(e,t){const i=(e-a.x)/r,s=(t-a.y)/n;return i*i+s*s}const l={candidates:[]},u="esriGeometryPolygon"===this.geometryType,p="esriGeometryPolyline"===this.geometryType||"esriGeometryPoint"===this.geometryType,h=this._getPointCreator(t,this.spatialReference,i),y=new L(null,0),g=new L(null,0),x={x:0,y:0,z:0};for(const c of this.items){const e=s.getObjectId(c),t=s.getGeometryWithCurves?.(c);if(null!=t){_(t,e);continue}const i=s.getGeometry(c);null==i||I(i,e)}return l.candidates.sort((e,t)=>e.distance-t.distance),l;function I(t,i){const{coords:s,stride:r}=t,n=t.isPoint?W:t.lengths;if(y.coords=s,g.coords=s,e.returnEdge){let e=0;for(let t=0;t<n.length;t++){const s=n[t],c=e;for(let t=0;t<s;t++,e+=r){if(!u&&t===s-1)continue;if(y.coordsIndex=e,g.coordsIndex=t===s-1?c:e+r,!X(x,a,y,g))continue;const n=o(x.x,x.y);n<=1&&l.candidates.push(new T(i,h(x),Math.sqrt(n),h(y),h(g)))}}}if("all"===e.vertexMode){let e=0;for(let t=0;t<n.length;t++){const s=n[t],a=e,c=g;c.coordsIndex=a;for(let t=0;t<s;t++,e+=r){if(y.coordsIndex=e,u&&t===s-1&&y.x===c.x&&y.y===c.y)continue;const a=o(y.x,y.y);a<=1&&l.candidates.push(new F(i,h(y),Math.sqrt(a)))}}}else if(p&&"ends"===e.vertexMode){let e=0;const t=[];for(let i=0;i<n.length;i++){t.push(e);const s=n[i];e+=s*r,s>1&&t.push(e-r)}for(const s of t){y.coordsIndex=s;const e=o(y.x,y.y);e<=1&&l.candidates.push(new F(i,h(y),Math.sqrt(e)))}}}function _(t,i){const{candidates:s}=l,r={x:0,y:0,z:0};if(e.returnEdge){const e=[a.x,a.y],n=new L(e,0),l=new L(e,0);for(const{segments:a}of t.parts)for(const{start:t,curve:u}of a){const{curvePoint:a}=c(t,u,e),p=o(...a);if(p>1)continue;[r.x,r.y]=a,n.coords=t,l.coords=m(u);const y=d(u)?null:f(u);s.push(new T(i,h(r),Math.sqrt(p),h(n),h(l),!1,y))}}function n(e){r.x=t.vertexXY[2*e],r.y=t.vertexXY[2*e+1];const a=o(r.x,r.y);a>1||(r.z=t.vertexZ?.[e]??0,s.push(new F(i,h(r),Math.sqrt(a))))}if("all"===e.vertexMode){const{vertexCount:e}=t;for(let t=0;t<e;++t)n(t);return}if("ends"===e.vertexMode)switch(t.type){case"point":n(0);break;case"polyline":for(let e=0;e<t.partCount;++e){const i=t.partOffsets[e],s=t.partOffsets[e+1]-1;n(i),s!==i&&n(s)}}}}_getPointCreator(e,t,i){const s=null==i||u(t,i)?e=>e:e=>x(e,t,i),{hasZ:a}=this,r=0;return a&&e?({x:e,y:t,z:i})=>s({x:e,y:t,z:i}):({x:e,y:t})=>s({x:e,y:t,z:r})}async createSummaryStatisticsResponse(e){const{field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:r,minValue:n,maxValue:o,scale:l,timeZone:u,outStatisticTypes:c}=e,m=this.fieldsIndex.get(t),d=_(m)||v(m)||V(m),f=await this._getDataValues({field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:r,scale:l,timeZone:u},this.items),p=H({normalizationType:a,normalizationField:s,minValue:n,maxValue:o}),h={value:.5,fieldType:m?.type},y=S(m)?N({values:f,supportsNullCount:p,percentileParams:h,outStatisticTypes:c}):w({values:f,minValue:n,maxValue:o,useSampleStdDev:!a,supportsNullCount:p,percentileParams:h,outStatisticTypes:c});return D(y,c,d)}async createUniqueValuesResponse(e){const{field:t,valueExpression:i,domains:s,returnAllCodedValues:a,scale:r,timeZone:n}=e,o=await this._getDataValues({field:t,field2:e.field2,field3:e.field3,fieldDelimiter:e.fieldDelimiter,valueExpression:i,scale:r,timeZone:n},this.items,!1),l=P(o);return O(l,s,a,e.fieldDelimiter)}async createClassBreaksResponse(e){const{field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:r,classificationMethod:n,standardDeviationInterval:o,minValue:l,maxValue:u,numClasses:c,scale:m,timeZone:d}=e,f=await this._getDataValues({field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:r,scale:m,timeZone:d},this.items),p=q(f,{field:t,normalizationField:s,normalizationType:a,normalizationTotal:r,classificationMethod:n,standardDeviationInterval:o,minValue:l,maxValue:u,numClasses:c});return j(p,n)}async createHistogramResponse(e){const{field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:r,classificationMethod:n,standardDeviationInterval:o,minValue:l,maxValue:u,numBins:c,scale:m,timeZone:d}=e,f=await this._getDataValues({field:t,valueExpression:i,normalizationField:s,normalizationType:a,normalizationTotal:r,scale:m,timeZone:d},this.items);return C(f,{field:t,normalizationField:s,normalizationType:a,normalizationTotal:r,classificationMethod:n,standardDeviationInterval:o,minValue:l,maxValue:u,numBins:c})}_sortFeatures(e,t,i){if(e.length>1&&t?.length)for(const s of t.slice().reverse()){const{compare:t,fieldOrExpression:a,fieldInfo:r}=K(s,this.fieldsIndex);e.sort((e,s)=>t(i(e,a,r),i(s,a,r)))}}_topNFeatures(t,i,s,a){if(t.length>1&&i?.length){const r=i.map(e=>{const{compare:t,fieldOrExpression:i,fieldInfo:s}=K(e,this.fieldsIndex);return(e,r)=>t(a(e,i,s),a(r,i,s))}).reduceRight((e,t)=>(i,s)=>{const a=t(i,s);return 0===a||Number.isNaN(a)?e(i,s):a}),n=[];for(const i of t)e(n,i,s,r);return n}return t.slice(0,s)}_createFeatureQueryResponse(e){const{items:t,geometryType:i,hasM:s,hasZ:a,featureIdInfo:r,spatialReference:n}=this,{outFields:l,outSR:u,quantizationParameters:c,resultRecordCount:m,resultOffset:d,returnZ:f,returnM:p}=e,y=null!=m&&t.length>(d||0)+m,g=l&&(l.includes("*")?[...this.fieldsIndex.fields]:l.map(e=>this.fieldsIndex.get(e)));return{exceededTransferLimit:y,features:this._createFeatures(e,t),fields:g,geometryType:i,hasM:s&&p,hasZ:a&&f,objectIdFieldName:"object-id"===r.type?r.fieldName:null,spatialReference:h(u||n),transform:c&&o(c)||null}}_createFeatures(e,t){const i=new p(e,this.featureAdapter,this.fieldsIndex),{hasM:s,hasZ:a}=this,{orderByFields:r,quantizationParameters:n,returnGeometry:l,returnCentroid:u,maxAllowableOffset:c,resultOffset:m,resultRecordCount:d,returnZ:f=!1,returnM:h=!1}=e,x=a&&f,I=s&&h;let T;const F=m||0,_=null!=d?F+d:null;null!=_&&_<=5e3&&_<t.length?T=this._topNFeatures(t,r,_,(e,t,s)=>i.getFieldValue(e,t,s)):(T=[...t],this._sortFeatures(T,r,(e,t,s)=>i.getFieldValue(e,t,s))),(F>0||null!=_)&&(T=T.slice(F,_??void 0));const v=[];let V=0;if(this.geometryType&&(l||u)){const e=o(n)??void 0,t="esriGeometryPolygon"===this.geometryType||"esriGeometryPolyline"===this.geometryType;if(l&&!u)for(const s of T){const a=this.featureAdapter.getGeometry(s),r=this._addFeatureJSONMetadata(s,{attributes:i.getAttributes(s),geometry:y(this.geometryType,a,c,e,x,I)});t&&a&&!r.geometry&&(r.centroid=g(this,this.featureAdapter.getCentroid(s,this),e)),v[V++]=r}else if(!l&&u)for(const s of T)v[V++]=this._addFeatureJSONMetadata(s,{attributes:i.getAttributes(s),centroid:g(this,this.featureAdapter.getCentroid(s,this),e)});else for(const s of T)v[V++]=this._addFeatureJSONMetadata(s,{attributes:i.getAttributes(s),centroid:g(this,this.featureAdapter.getCentroid(s,this),e),geometry:y(this.geometryType,this.featureAdapter.getGeometry(s),c,e,x,I)})}else for(const o of T){const e=i.getAttributes(o);e&&(v[V++]=this._addFeatureJSONMetadata(o,{attributes:e}))}return v}_addFeatureJSONMetadata(e,t){const i=this.featureAdapter.getMetadata?.(e);return void 0!==i&&(t.metadata=i),t}_createExceedsLimitQueryResponse(){let e=!1,t=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,s=Number.POSITIVE_INFINITY;for(const a of this.query.outStatistics??[])if("exceedslimit"===a.statisticType){t=null!=a.maxPointCount?a.maxPointCount:Number.POSITIVE_INFINITY,i=null!=a.maxRecordCount?a.maxRecordCount:Number.POSITIVE_INFINITY,s=null!=a.maxVertexCount?a.maxVertexCount:Number.POSITIVE_INFINITY;break}if("esriGeometryPoint"===this.geometryType)e=this.items.length>t;else if(this.items.length>i)e=!0;else{e=this.items.reduce((e,t)=>{const i=this.featureAdapter.getGeometry(t);return e+(i?.size??0)},0)>s}return{fields:[{name:"exceedslimit",type:"esriFieldTypeInteger",alias:"exceedslimit",sqlType:"sqlTypeInteger",domain:null,defaultValue:null}],features:[{attributes:{exceedslimit:Number(e)}}]}}async _createStatisticsQueryResponse(e,t,i={attributes:{}}){const s=[],a=new Map,r=new Map,n=new Map,o=new Map,l=new p(e,this.featureAdapter,this.fieldsIndex),u=e.outStatistics,{groupByFieldsForStatistics:c,having:m,orderByFields:d,resultRecordCount:f}=e,h=c?.length,y=!!h,g=y?c[0]:null,x=y&&!this.fieldsIndex.get(g);for(const p of u??[]){const{outStatisticFieldName:u,statisticType:d}=p,f=p,I="exceedslimit"!==d?p.onStatisticField:void 0,T="percentile_disc"===d||"percentile_cont"===d,F="EnvelopeAggregate"===d||"CentroidAggregate"===d||"ConvexHullAggregate"===d,_=y&&1===h&&(I===g||x)&&"count"===d;if(y){if(!n.has(I)){const e=[];for(const i of c){const s=this._getAttributeValues(l,i,t,a);e.push(s)}n.set(I,this._calculateUniqueValues(e,t,!F&&l.returnDistinctValues))}const i=n.get(I);if(!i)continue;const s=Object.keys(i);for(const r of s){const{count:s,data:n,items:d,itemPositions:p}=i[r],h=n.join(",");if(!m||l.validateItems(d,m)){const i=o.get(h)||{attributes:{}};if(e.returnAggIds&&(i.aggregateIds=d.map(e=>this.featureAdapter.getObjectId(e)).filter(e=>null!=e)),F){i.aggregateGeometries||(i.aggregateGeometries={});const{aggregateGeometries:e,outStatisticFieldName:t}=await this._getAggregateGeometry(f,d);i.aggregateGeometries[t]=e}else{let e=null;if(_)e=s;else{const i=this._getAttributeValues(l,I,t,a),s=p.map(e=>i[e]);e=T&&"statisticParameters"in f?this._getPercentileValue(f,s):this._getStatisticValue(f,s,null,l.returnDistinctValues)}i.attributes[u]=e}let r=0;c.forEach((e,t)=>i.attributes[this.fieldsIndex.get(e)?e:"EXPR_"+ ++r]=n[t]),o.set(h,i)}}}else if(F){i.aggregateGeometries||(i.aggregateGeometries={});const{aggregateGeometries:e,outStatisticFieldName:s}=await this._getAggregateGeometry(f,t);i.aggregateGeometries[s]=e}else{const e=this._getAttributeValues(l,I,t,a);i.attributes[u]=T&&"statisticParameters"in f?this._getPercentileValue(f,e):this._getStatisticValue(f,e,r,l.returnDistinctValues)}const v="min"!==d&&"max"!==d||!S(this.fieldsIndex.get(I))&&!this._isAnyDateField(I)?null:this.fieldsIndex.get(I)?.type;s.push({name:u,alias:u,type:v||"esriFieldTypeDouble"})}const I=y?Array.from(o.values()):[i];return this._sortFeatures(I,d,(e,t)=>e.attributes[t]),f&&(I.length=Math.min(f,I.length)),{fields:s,features:I}}_isAnyDateField(e){const t=this.fieldsIndex.get(e);return _(t)||v(t)||V(t)||b(t)}async _getAggregateGeometry(e,t){const{convexHull:i,union:o}=await import("../../../geometry/geometryEngineJSON.js"),{statisticType:l,outStatisticFieldName:u}=e,{featureAdapter:c,spatialReference:m,geometryType:d}=this,f=t.map(e=>y(d,c.getGeometry(e))),p=i(m,f,!0)[0],h={aggregateGeometries:null,outStatisticFieldName:null};if("EnvelopeAggregate"===l){const e=p?r(p):n(o(m,f));h.aggregateGeometries={...e,spatialReference:m},h.outStatisticFieldName=u||"extent"}else if("CentroidAggregate"===l){const e=p?s(p):a(n(o(m,f)));h.aggregateGeometries={x:e[0],y:e[1],spatialReference:m},h.outStatisticFieldName=u||"centroid"}else"ConvexHullAggregate"===l&&(h.aggregateGeometries=p,h.outStatisticFieldName=u||"convexHull");return h}_getStatisticValue(e,t,i,s){const{onStatisticField:a,statisticType:r}=e;let n=null;n=i?.has(a)?i.get(a):S(this.fieldsIndex.get(a))||this._isAnyDateField(a)?N({values:t,returnDistinct:s}):w({values:s?[...new Set(t)]:t,minValue:null,maxValue:null,useSampleStdDev:!0}),i&&i.set(a,n);return n["var"===r?"variance":r]}_getPercentileValue(e,t){const{onStatisticField:i,statisticParameters:s,statisticType:a}=e,{value:r,orderBy:n}=s,o=this.fieldsIndex.get(i);return G(t,{value:r,orderBy:n,fieldType:o?.type,isDiscrete:"percentile_disc"===a})}_getAttributeValues(e,t,i,s){if(s.has(t))return s.get(t);const a=this.fieldsIndex.get(t),r=i.map(i=>e.getFieldValue(i,t,a));return s.set(t,r),r}_calculateUniqueValues(e,t,i){const s={},a=t.length;for(let r=0;r<a;r++){const a=t[r],n=[];for(const t of e)n.push(t[r]);const o=n.join(",");null==s[o]?s[o]={count:1,data:n,items:[a],itemPositions:[r]}:(i||s[o].count++,s[o].items.push(a),s[o].itemPositions.push(r))}return s}async _getDataValues(e,s,a=!0){const r=new p(this.query,this.featureAdapter,this.fieldsIndex),{valueExpression:n,scale:o,timeZone:l}=e,u=i.fromJSON(this.query.outSR||this.spatialReference);return n?r.getExpressionValues(s,n,{viewingMode:"map",scale:o,spatialReference:u},{geometryType:this.geometryType,hasZ:this.hasZ,hasM:this.hasM},l):r.getDataValues(s,t(e),a)}_calculateHistogramBins(e,t,i){if(null==t.min&&null==t.max)return[];const s=t.intervals,a=t.min??0,r=t.max??0,n=s.map(([e,t])=>({minValue:e,maxValue:t,count:0,items:[]}));for(let o=0;o<e.length;o++){const t=e[o],l=i[o];if(null!=t&&t>=a&&t<=r){const e=Z(s,t);e>-1&&(n[e].count++,n[e].items.push(l))}}return n}async createQueryBinsResponse(e){const t=e.bin?.splitBy;if(!t)return this._createBinsResponse(e);const{value:i,outAlias:s,valueType:a}=t,r=[],n=[{name:s??i,alias:s??i,type:a??"esriFieldTypeString"},{name:Q,alias:Q,type:"esriFieldTypeInteger"}],o=new p(e,this.featureAdapter,this.fieldsIndex),l=new Map,u=[...this.items];this._sortFeatures(u,[i],(e,t,i)=>o.getFieldValue(e,t,i));const c=this._getAttributeValues(o,i,u,l),m=this._calculateUniqueValues([c],u,o.returnDistinctValues);for(const d in m){const{items:t}=m[d],a=await this._createBinsResponse(e,t);if(r.push(...a.features.map(e=>({...e,attributes:{...e.attributes,[s??i]:d}}))),a.fields)for(const e of a.fields)n.some(t=>t.name===e.name)||n.push(e)}return{fields:n,features:r}}async _createBinsResponse(e,t){const i=e.bin;switch(t=t??this.items,i.type){case"autoIntervalBin":return this._createAutoIntervalBinsResponse(R.fromJSON(i),e,t);case"dateBin":return this._createDateBinsResponse(z.fromJSON(i),e,t);case"fixedBoundariesBin":return this._createFixedBoundariesBinsResponse(M.fromJSON(i),e,t);case"fixedIntervalBin":return this._createFixedIntervalBinsResponse(A.fromJSON(i),e,t)}}async _createAutoIntervalBinsResponse(e,t,i){const{field:s,normalizationField:a,numBins:r,normalizationType:n,normalizationTotal:o,start:l,end:u}=e,c=await this._getDataValues({field:e.field||e.expression,normalizationField:e.normalizationField,normalizationType:e.normalizationType,normalizationTotal:e.normalizationTotal,timeZone:t.outTimeReference?.ianaTimeZone},i),m=E(c,{field:s,normalizationField:a,normalizationType:n,normalizationTotal:o,numBins:r,minValue:I(n?e.normalizationMinValue:l,!1),maxValue:I(n?e.normalizationMaxValue:u,!1)}),d=this._calculateHistogramBins(c,m,i);return this._createFeaturesFromHistogramBins(d,t)}async _createDateBinsResponse(e,t,i){const{field:s,interval:a,start:r,end:n,snapToData:o,returnFullIntervalBin:l,offset:u,firstDayOfWeek:c}=e,m=a.unit,d=await this._getDataValues({field:s||e.expression,timeZone:t.outTimeReference?.ianaTimeZone},i),f=b(this.fieldsIndex.get(s)),p=B.toJSON(m),h=d.filter(Boolean).sort((e,t)=>e-t),y=null!=r?I(r,f):h[0],g=null!=n?I(n,f):h[h.length-1],x=[];if(null!=y&&null!=g){const e={zone:t.outTimeReference?.ianaTimeZone??k},i=u?.unit?B.toJSON(u.unit):"milliseconds",s={[i]:u?.value||0},r=J.fromMillis(y,e).minus(s),n=J.fromMillis(g,e).minus(s),m="number"==typeof c&&c>=1&&c<=7?c:7,d=(e,t)=>{const i=(e.weekday-t+7)%7;return e.minus({days:i}).startOf("day")};if("last"===o){let e="week"===p?((e,t)=>d(e,t).plus({days:7}))(n,m):n;for(;e>r;){const t=e.minus({[p]:a.value});if(t<r){x.unshift([l?t.plus(s).toMillis():r.plus(s).toMillis(),e.plus(s).toMillis()]);break}x.unshift([t.plus(s).toMillis(),e.plus(s).toMillis()]),e=t}}else{let e="first"===o?r:"week"===p?d(r,m):r.startOf(p);for(;e<=n;){const t=e.plus({[p]:a.value});if(t>n){x.push([e.plus(s).toMillis(),l?t.plus(s).toMillis():n.plus(s).toMillis()]);break}x.push([e.plus(s).toMillis(),t.plus(s).toMillis()]),e=t}}}const T=this._calculateHistogramBins(d,{intervals:x,min:y,max:g},i);return this._createFeaturesFromHistogramBins(T,t)}async _createFixedBoundariesBinsResponse(e,t,i){const{field:s}=e,a=await this._getDataValues({field:s||e.expression,timeZone:t.outTimeReference?.ianaTimeZone},i),r=b(this.fieldsIndex.get(s)),n=e.boundaries.map(e=>I(e,r)).sort((e,t)=>e-t),o=[];for(let c=0;c<n.length-1;c++)o.push([n[c],n[c+1]]);const l={intervals:o,min:n.at(0),max:n.at(-1)},u=this._calculateHistogramBins(a,l,i);return this._createFeaturesFromHistogramBins(u,t)}async _createFixedIntervalBinsResponse(e,t,i){const{field:s,interval:a,normalizationType:r,start:n,end:o}=e,l=await this._getDataValues({field:s||e.expression,normalizationField:e.normalizationField,normalizationType:r,normalizationTotal:e.normalizationTotal,timeZone:t.outTimeReference?.ianaTimeZone},i),u=b(this.fieldsIndex.get(s)),c=E(l,{field:s,classificationMethod:"defined-interval",definedInterval:a,minValue:I(r?e.normalizationMinValue:n,u),maxValue:I(r?e.normalizationMaxValue:o,u)},!0),m=this._calculateHistogramBins(l,c,i);return this._createFeaturesFromHistogramBins(m,t)}async _createFeaturesFromHistogramBins(e,t){const{upperBoundaryAlias:i,lowerBoundaryAlias:s}=t,a=s||"lowerBoundary",r=i||"upperBoundary",n=[],o=[{name:a,alias:a,type:"esriFieldTypeDouble"},{name:r,alias:r,type:"esriFieldTypeDouble"}],l=t.bin?.stackBy?.value,u=t.bin?.stackBy?.outAlias;l&&o.push({name:Q,alias:Q,type:"esriFieldTypeInteger"},{name:u??l,alias:u??l,type:"esriFieldTypeString"});let c=0;const m="dateBin"===t.bin.type,d=t.outTimeReference?.ianaTimeZone;for(const f of e){const{minValue:e,maxValue:i,items:s}=f,p={attributes:{}};let h;if(p.attributes[a]=m&&d&&null!=e?J.fromMillis(e,{zone:d}).toISO():e,t.bin.hideUpperBound||(p.attributes[r]=m&&d&&null!=i?J.fromMillis(i,{zone:d}).toISO():i),l?(h=await this._createStatisticsQueryResponse({...t,groupByFieldsForStatistics:[l],orderByFields:[l]},s),p.attributes[Q]=++c,"flat"===t.bin.jsonStyle?n.push(...h.features.map(({attributes:{EXPR_1:e,...t},...i})=>({...i,attributes:u??e?{...t,[u??e]:e,...p.attributes}:{...t,...p.attributes}}))):(p.stackedAttributes=h.features.map(({attributes:{EXPR_1:e,...t}})=>u??e?{...t,[u??e]:e}:t),n.push(p))):(t.bin?.splitBy&&(p.attributes[Q]=++c),h=await this._createStatisticsQueryResponse(t,s,p),n.push(p)),h.fields)for(const t of h.fields)o.some(e=>e.name===t.name)||o.push(t)}return"desc"===t.binOrder&&n.reverse(),{fields:o,features:n}}}function X(e,t,i,s){const a=s.x-i.x,r=s.y-i.y,n=t.x-i.x,o=t.y-i.y,l=a*a+r*r;if(0===l)return!1;const u=n*a+o*r,c=Math.min(1,Math.max(0,u/l));return e.x=i.x+a*c,e.y=i.y+r*c,!0}class L{constructor(e,t){this.coords=e,this.coordsIndex=t}get x(){return this.coords[this.coordsIndex]}get y(){return this.coords[this.coordsIndex+1]}get z(){return this.coords[this.coordsIndex+2]}}const W=[1];function K(e,t){const i=e.split(" "),s=i[0],a=t.get(s),r=!!i[1]&&"desc"===i[1].toLowerCase();return{compare:U(a?.type,r,"case-insensitive"),fieldOrExpression:s,fieldInfo:a}}export{Y as QueryEngineResult};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../../core/Error.js";import{Loadable as s}from"../../../core/Loadable.js";import{escapeRegExpString as r}from"../../../core/string.js";import{property as o,subclass as p}from"../../../core/accessorSupport/decorators.js";import i from"../../../geometry/SpatialReference.js";import{typeKebabDictionary as u}from"../../../geometry/support/typeUtils.js";import{queryFeatureSetJSON as a,crsDefault as n,getSpatialReferenceWkid as c,getServerLandingPage as l,getServerConformance as d,getServerCollectionsPage as m,getServerOpenApi as y,getCollectionDefinition as f,crsPrefix as g}from"../../ogc/ogcFeatureUtils.js";import{zeroQueryBins as h}from"../../support/capabilities.js";import S from"../../../rest/support/FeatureSet.js";let C=class extends s{constructor(){super(...arguments),this.featureDefinition=null,this.type="ogc-feature"}load(e){return this.addResolvingPromise(this._loadOGCServices(this.layer,e)),this.when()}getSource(){const{featureDefinition:{collection:e,layerDefinition:t,spatialReference:s,supportedCrs:r},layer:{apiKey:o,customParameters:p,effectiveMaxRecordCount:i}}=this;return{type:"ogc-source",collection:e,layerDefinition:t,maxRecordCount:i,queryParameters:{apiKey:o,customParameters:p},spatialReference:s,supportedCrs:r}}queryExtent(e,t={}){return null}queryFeatureCount(e,t={}){return null}queryFeatures(e,t={}){return this.queryFeaturesJSON(e,t).then(e=>S.fromJSON(e))}queryFeaturesJSON(e,t={}){const s=this.getSource();return this.load(t).then(()=>a(s,e,t))}queryObjectIds(e,t={}){return null}serviceSupportsSpatialReference(e){const{isWebMercator:t,isWGS84:s,latestWkid:r,wkid:o}=e,{supportedCrs:p}=this.featureDefinition;return s||t||!!o&&!!p[o]||!!r&&!!p[r]}_conformsToType(e,t){const s=new RegExp(`^${r(t)}$`,"i");return e.conformsTo.some(e=>s.test(e))??!1}_getCapabilities(e,t){return{analytics:{supportsCacheHint:!1},attachment:null,data:{isVersioned:!1,isBranchVersioned:!1,supportedCurveTypes:[],supportsAttachment:!1,supportsM:!1,supportsTrueCurve:!1,supportsZ:e},metadata:{supportsAdvancedFieldProperties:!1},operations:{supportsCalculate:!1,supportsTruncate:!1,supportsValidateSql:!1,supportsAdd:!1,supportsDelete:!1,supportsEditing:!1,supportsChangeTracking:!1,supportsQuery:!1,supportsQueryBins:!1,supportsQueryPivot:!1,supportsQueryAnalytics:!1,supportsQueryAttachments:!1,supportsQueryTopFeatures:!1,supportsResizeAttachments:!1,supportsSync:!1,supportsUpdate:!1,supportsExceedsLimitStatistics:!1,supportsAsyncConvert3D:!1},query:{maxRecordCount:t,maxRecordCountFactor:void 0,maxUniqueIDCount:void 0,relativeTimeBinWindow:void 0,standardMaxRecordCount:void 0,standardMaxRecordCountNoGeometry:void 0,supportsCacheHint:!1,supportsCentroid:!1,supportsCentroidOnDegeneratedQuantizedGeometry:!1,supportsCurrentUser:!1,supportsDegeneratedQuantizedGeometry:!1,supportsDisjointSpatialRelationship:!1,supportsDistance:!1,supportsDistinct:!1,supportsExtent:!1,supportsFormatPBF:!1,supportsFormatPBFWithCurves:!1,supportsGeometryProperties:!1,supportsHavingClause:!1,supportsHistoricMoment:!1,supportsMaxRecordCountFactor:!1,supportsOrderBy:!1,supportsPagination:!1,supportsPaginationOnAggregatedQueries:!1,supportsPercentileStatistics:!1,supportsQuantization:!1,supportsQuantizationEditMode:!1,supportsQueryByAnonymous:!1,supportsQueryByOthers:!1,supportsQueryGeometry:!1,supportsResultType:!1,supportsReturnMesh:!1,supportsStandardizedQueriesOnly:!1,supportsTopFeaturesQuery:!1,supportsStatistics:!1,supportsSpatialAggregationStatistics:!1,supportedSpatialAggregationStatistics:{envelope:!1,centroid:!1,convexHull:!1},supportsDefaultSpatialReference:!1,supportsFullTextSearch:!1,supportsCompactGeometry:!1,supportsSqlExpression:!1,supportsTrueCurve:!1,tileMaxRecordCount:void 0},queryRelated:{supportsCount:!1,supportsOrderBy:!1,supportsPagination:!1,supportsCacheHint:!1},queryTopFeatures:{supportsCacheHint:!1},queryAttributeBins:h,editing:{supportsDeleteByAnonymous:!1,supportsDeleteByOthers:!1,supportsGeometryUpdate:!1,supportsGlobalId:!1,supportsReturnServiceEditsInSourceSpatialReference:!1,supportsRollbackOnFailure:!1,supportsTrueCurveUpdate:!1,supportsTrueCurveUpdateByTrueCurveClientsOnly:!0,supportsUpdateByAnonymous:!1,supportsUpdateByOthers:!1,supportsUploadWithItemId:!1,supportsUpdateWithoutM:!1,supportsAsyncApplyEdits:!1,zDefault:void 0}}}_getMaxRecordCount(e){const t=e?.components?.parameters;return t?.limit?.schema?.maximum??t?.limitFeatures?.schema?.maximum}_getStorageSpatialReference(e){const t=e.storageCrs??n,s=c(t);return null==s?i.WGS84:new i({wkid:s})}_getSupportedSpatialReferences(e,t){const s="#/crs",r=e.crs??[n],o=r.includes(s)?r.filter(e=>e!==s).concat(t.crs??[]):r,p=/^http:\/\/www\.opengis.net\/def\/crs\/epsg\/.*\/3785$/i;return o.filter(e=>!p.test(e))}async _loadOGCServices(e,s){const o=null!=s?s.signal:null,{apiKey:p,collectionId:i,customParameters:a,fields:n,geometryType:h,hasZ:S,objectIdField:C,timeInfo:v,url:R}=e,w={fields:n?.map(e=>e.toJSON()),geometryType:u.toJSON(h),hasZ:S,objectIdField:C,timeInfo:v?.toJSON()},x={apiKey:p,customParameters:a,signal:o},T=await l(R,x),[F,O]=await Promise.all([d(T,x),m(T,x)]);if(!this._conformsToType(F,"http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/geojson"))throw new t("ogc-feature-layer:no-geojson-support","Server does not support geojson");const D=O.collections.find(({id:e})=>e===i);if(!D)throw new t("ogc-feature-layer:collection-not-found","Server does not contain the named collection");const j=this._conformsToType(F,"http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/oas30")?await y(T,x):null,A=await f(D,w,x),P=this._getMaxRecordCount(j),Q=this._getCapabilities(A.hasZ,P),B=this._getStorageSpatialReference(D).toJSON(),q=this._getSupportedSpatialReferences(D,O),b=new RegExp(`^${r(g)}`,"i"),G={};for(const t of q){const e=c(t);null!=e&&(G[e]||(G[e]=t.replace(b,"")))}this.featureDefinition={capabilities:Q,collection:D,layerDefinition:A,spatialReference:B,supportedCrs:G}}};e([o()],C.prototype,"featureDefinition",void 0),e([o({constructOnly:!0})],C.prototype,"layer",void 0),e([o()],C.prototype,"type",void 0),C=e([p("esri.layers.graphics.sources.OGCFeatureSource")],C);export{C as OGCFeatureSource};
2
+ import{__decorate as e}from"tslib";import t from"../../../core/Error.js";import{Loadable as s}from"../../../core/Loadable.js";import{escapeRegExpString as r}from"../../../core/string.js";import{property as o,subclass as p}from"../../../core/accessorSupport/decorators.js";import i from"../../../geometry/SpatialReference.js";import{typeKebabDictionary as u}from"../../../geometry/support/typeUtils.js";import{queryFeatureSetJSON as a,crsDefault as n,getSpatialReferenceWkid as c,getServerLandingPage as l,getServerConformance as d,getServerCollectionsPage as m,getServerOpenApi as y,getCollectionDefinition as f,crsPrefix as g}from"../../ogc/ogcFeatureUtils.js";import{zeroQueryBins as h}from"../../support/capabilities.js";import S from"../../../rest/support/FeatureSet.js";let C=class extends s{constructor(){super(...arguments),this.featureDefinition=null,this.type="ogc-feature"}load(e){return this.addResolvingPromise(this._loadOGCServices(this.layer,e)),this.when()}getSource(){const{featureDefinition:{collection:e,layerDefinition:t,spatialReference:s,supportedCrs:r},layer:{apiKey:o,customParameters:p,effectiveMaxRecordCount:i}}=this;return{type:"ogc-source",collection:e,layerDefinition:t,maxRecordCount:i,queryParameters:{apiKey:o,customParameters:p},spatialReference:s,supportedCrs:r}}queryExtent(e,t={}){return null}queryFeatureCount(e,t={}){return null}queryFeatures(e,t={}){return this.queryFeaturesJSON(e,t).then(e=>S.fromJSON(e))}queryFeaturesJSON(e,t={}){const s=this.getSource();return this.load(t).then(()=>a(s,e,t))}queryObjectIds(e,t={}){return null}serviceSupportsSpatialReference(e){const{isWebMercator:t,isWGS84:s,latestWkid:r,wkid:o}=e,{supportedCrs:p}=this.featureDefinition;return s||t||!!o&&!!p[o]||!!r&&!!p[r]}_conformsToType(e,t){const s=new RegExp(`^${r(t)}$`,"i");return e.conformsTo.some(e=>s.test(e))??!1}_getCapabilities(e,t){return{analytics:{supportsCacheHint:!1},attachment:null,data:{isVersioned:!1,isBranchVersioned:!1,supportedCurveTypes:[],supportsAttachment:!1,supportsM:!1,supportsTrueCurve:!1,supportsZ:e},metadata:{supportsAdvancedFieldProperties:!1},operations:{supportsCalculate:!1,supportsTruncate:!1,supportsValidateSql:!1,supportsAdd:!1,supportsDelete:!1,supportsEditing:!1,supportsChangeTracking:!1,supportsQuery:!1,supportsQueryBins:!1,supportsQueryPivot:!1,supportsQueryAnalytics:!1,supportsQueryAttachments:!1,supportsQueryTopFeatures:!1,supportsResizeAttachments:!1,supportsSync:!1,supportsUpdate:!1,supportsExceedsLimitStatistics:!1,supportsAsyncConvert3D:!1},query:{maxRecordCount:t,maxRecordCountFactor:void 0,maxUniqueIDCount:void 0,relativeTimeBinWindow:void 0,standardMaxRecordCount:void 0,standardMaxRecordCountNoGeometry:void 0,supportsAggregateIds:!1,supportsCacheHint:!1,supportsCentroid:!1,supportsCentroidOnDegeneratedQuantizedGeometry:!1,supportsCurrentUser:!1,supportsDegeneratedQuantizedGeometry:!1,supportsDisjointSpatialRelationship:!1,supportsDistance:!1,supportsDistinct:!1,supportsExtent:!1,supportsFormatPBF:!1,supportsFormatPBFWithCurves:!1,supportsGeometryProperties:!1,supportsHavingClause:!1,supportsHistoricMoment:!1,supportsMaxRecordCountFactor:!1,supportsOrderBy:!1,supportsPagination:!1,supportsPaginationOnAggregatedQueries:!1,supportsPercentileStatistics:!1,supportsQuantization:!1,supportsQuantizationEditMode:!1,supportsQueryByAnonymous:!1,supportsQueryByOthers:!1,supportsQueryGeometry:!1,supportsResultType:!1,supportsReturnMesh:!1,supportsStandardizedQueriesOnly:!1,supportsTopFeaturesQuery:!1,supportsStatistics:!1,supportsSpatialAggregationStatistics:!1,supportedSpatialAggregationStatistics:{envelope:!1,centroid:!1,convexHull:!1},supportsDefaultSpatialReference:!1,supportsFullTextSearch:!1,supportsCompactGeometry:!1,supportsSqlExpression:!1,supportsTrueCurve:!1,tileMaxRecordCount:void 0},queryRelated:{supportsCount:!1,supportsOrderBy:!1,supportsPagination:!1,supportsCacheHint:!1},queryTopFeatures:{supportsCacheHint:!1},queryAttributeBins:h,editing:{supportsDeleteByAnonymous:!1,supportsDeleteByOthers:!1,supportsGeometryUpdate:!1,supportsGlobalId:!1,supportsReturnServiceEditsInSourceSpatialReference:!1,supportsRollbackOnFailure:!1,supportsTrueCurveUpdate:!1,supportsTrueCurveUpdateByTrueCurveClientsOnly:!0,supportsUpdateByAnonymous:!1,supportsUpdateByOthers:!1,supportsUploadWithItemId:!1,supportsUpdateWithoutM:!1,supportsAsyncApplyEdits:!1,zDefault:void 0}}}_getMaxRecordCount(e){const t=e?.components?.parameters;return t?.limit?.schema?.maximum??t?.limitFeatures?.schema?.maximum}_getStorageSpatialReference(e){const t=e.storageCrs??n,s=c(t);return null==s?i.WGS84:new i({wkid:s})}_getSupportedSpatialReferences(e,t){const s="#/crs",r=e.crs??[n],o=r.includes(s)?r.filter(e=>e!==s).concat(t.crs??[]):r,p=/^http:\/\/www\.opengis.net\/def\/crs\/epsg\/.*\/3785$/i;return o.filter(e=>!p.test(e))}async _loadOGCServices(e,s){const o=null!=s?s.signal:null,{apiKey:p,collectionId:i,customParameters:a,fields:n,geometryType:h,hasZ:S,objectIdField:C,timeInfo:v,url:R}=e,w={fields:n?.map(e=>e.toJSON()),geometryType:u.toJSON(h),hasZ:S,objectIdField:C,timeInfo:v?.toJSON()},x={apiKey:p,customParameters:a,signal:o},T=await l(R,x),[F,O]=await Promise.all([d(T,x),m(T,x)]);if(!this._conformsToType(F,"http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/geojson"))throw new t("ogc-feature-layer:no-geojson-support","Server does not support geojson");const D=O.collections.find(({id:e})=>e===i);if(!D)throw new t("ogc-feature-layer:collection-not-found","Server does not contain the named collection");const A=this._conformsToType(F,"http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/oas30")?await y(T,x):null,j=await f(D,w,x),P=this._getMaxRecordCount(A),Q=this._getCapabilities(j.hasZ,P),B=this._getStorageSpatialReference(D).toJSON(),q=this._getSupportedSpatialReferences(D,O),b=new RegExp(`^${r(g)}`,"i"),G={};for(const t of q){const e=c(t);null!=e&&(G[e]||(G[e]=t.replace(b,"")))}this.featureDefinition={capabilities:Q,collection:D,layerDefinition:j,spatialReference:B,supportedCrs:G}}};e([o()],C.prototype,"featureDefinition",void 0),e([o({constructOnly:!0})],C.prototype,"layer",void 0),e([o()],C.prototype,"type",void 0),C=e([p("esri.layers.graphics.sources.OGCFeatureSource")],C);export{C as OGCFeatureSource};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import{__addDisposableResource as e,__disposeResources as t}from"tslib";import r from"../../../../core/Collection.js";import{toConst as s}from"../../../../core/compilerUtils.js";import i from"../../../../core/Error.js";import has from"../../../../core/has.js";import o from"../../../../core/Logger.js";import{onAbortOrThrow as a,throwIfAborted as n}from"../../../../core/promiseUtils.js";import{QueueProcessor as u}from"../../../../core/QueueProcessor.js";import{parseWhereClause as l}from"../../../../core/sql.js";import p from"../../../../geometry/SpatialReference.js";import{set as c,create as d,expandWithRect as f,expandWithAABB as m,negativeInfinity as y,fromRect as h}from"../../../../geometry/support/aaBoundingBox.js";import{getQueryResultExtent as g,QueryEngine as w}from"../../data/QueryEngine.js";import{QueryEngineResult as _}from"../../data/QueryEngineResult.js";import{normalizeQueryLike as I}from"../../data/queryUtils.js";import{createDrawingInfo as F}from"./clientSideDefaults.js";import{getParquetFileId as x,getParquetRowId as R}from"./parquetIdUtils.js";import S from"../../../support/Field.js";import q from"../../../support/FieldsIndex.js";import{fromParquetGeometryEncodingJSON as C}from"../../../support/parquetEncodingUtils.js";import{completeParquetLayerInfo as v,fromParquetJSONGeometryType as E,toParquetJSONGeometryType as b}from"../../../support/parquetUtils.js";import{loadParquetModule as O}from"../../../../libs/parquet/loadParquetModule.js";import{createParquetFile as Q,readGeoMetadata as T}from"../../../../libs/parquet/parquet.js";import{FeatureStoreQueryAdapter as j}from"../../../../views/2d/layers/features/FeatureStoreQueryAdapter.js";import{FeatureSnapshotSourceChunk as P}from"../../../../views/2d/layers/features/sources/strategies/chunks/FeatureSnapshotSourceChunk.js";import{FeatureSourceChunkStore as M}from"../../../../views/2d/layers/features/sources/strategies/chunks/SourceChunkStore.js";import{FeatureMetadata as A}from"../../../../views/2d/layers/features/support/FeatureMetadata.js";import{FeatureSetReaderParquet as G}from"../../../../views/2d/layers/features/support/FeatureSetReaderParquet.js";const B=new j,D=4,z="__OBJECTID",W=new TextDecoder;class U{constructor(){this._fileInfos=new Map,this._queue=new u({concurrency:D,process:(e,t)=>this._executeQuery(e,t)}),this._indexMap={}}async load(s){const a=s.spatialReference?p.fromJSON(s.spatialReference):void 0;if(a&&!a.isWGS84&&!a.isWebMercator)throw new i("parquet:unsupported-projection","Only WGS84 and Web Mercator are supported");const n=await v({urls:new r(s.urls),fields:s.fields?.map(e=>S.fromJSON(e)),geometryEncoding:s.geometryEncoding?C(s.geometryEncoding):null,geometryType:s.geometryType?E(s.geometryType):null,displayOptimization:s.displayOptimization,spatialReference:a},{customParameters:s.customParameters});if(!n.fields)throw new i("parquet:unsupported","Fields must be defined");let u;if(n.spatialReference&&n.geometryType){if(!n.spatialReference)throw new i("parquet:unsupported","SpatialReference must be defined");if(!n.spatialReference.isGeographic&&!n.spatialReference.isWebMercator)throw new i("parquet:unsupported-projection","Only WGS84 and Web Mercator are supported");n.spatialReference.isGeographic&&!n.spatialReference.isWGS84&&(o.getLogger("parquet:unsupported-projection").warn("Found a geographic projection that is not WGS84. Handling as WGS84.",{spatialReference:n.spatialReference}),n.spatialReference=p.WGS84),u={geometry:n.geometryEncoding?{geometryType:b(n.geometryType),spatialReference:n.spatialReference.toJSON(),encoding:n.geometryEncoding.toJSON()}:null,displayOptimization:n.displayOptimization}}this.setCustomParameters(s.customParameters),this._geometryInfo=u;const l=s.urls;for(const e of l)this._addFile(e);this._capabilities=H(await this.getFileStatistics());const m=this._fileInfos.values().next().value;if(!m)return{layerDefinition:{},capabilities:H(null)};const h=await m,{fields:g}=n;if(null==g)throw new i("parquet-layer:missing-metadata","Unable to create parquet source: cannot infer fields",g);g.push(new S({name:z,type:"oid",alias:z}));for(const e of g){const t=h.file.columnForFieldName(e.name);null!=t&&(this._indexMap[e.name]=t)}const w=new q(g.map(e=>e.toJSON()));this._fieldsIndex=w;const _=b(n.geometryType??"point");if(this._metadata=A.createFeature({fieldsIndex:w.toJSON(),geometryType:_,hasZ:!1,hasM:!1,featureIdInfo:{type:"object-id",fieldName:"rowId"},subtypes:null,subtypeField:null,types:null,typeIdField:null,globalIdField:null,spatialReference:n.spatialReference,outSpatialReference:null,timeInfo:null,timeReferenceUnknownClient:null,dateFieldsTimeZone:null}),this._queryEngineParams={fieldsIndex:this._metadata.fieldsIndex,geometryType:_,featureIdInfo:{type:"object-id",fieldName:"rowId"},hasM:!1,hasZ:!1,spatialReference:n.spatialReference?.toJSON()??{wkid:4326},aggregateAdapter:null,timeInfo:null,definitionExpression:null},n.spatialReference){const e=await this.getFileInfos();this._fullExtent=V(e,n.spatialReference.toJSON())}if(null==this._fullExtent&&"location"===n.geometryEncoding?.type){const{xField:r,yField:s}=n.geometryEncoding,i=c(d(),y);for(const o of await this.getFileInfos())for(const a of o.file.rowGroups()){const o={stack:[],error:void 0,hasError:!1};try{const t=e(o,a.columnDescriptorForAttribute(r),!1),n=e(o,a.columnDescriptorForAttribute(s),!1),u=[t.minValue(),n.minValue(),t.maxValue(),n.maxValue()];f(i,u),a.free()}catch(I){o.error=I,o.hasError=!0}finally{t(o)}}this._fullExtent={xmin:i[0],ymin:i[1],xmax:i[3],ymax:i[4],spatialReference:n.spatialReference?.toJSON()}}return{capabilities:this._capabilities,layerDefinition:{fields:n.fields?.map(e=>e.toJSON()),drawingInfo:F(_),extent:this._fullExtent??void 0,geometryType:_,geometryEncoding:n.geometryEncoding?.toJSON(),displayOptimization:n.displayOptimization}}}destroy(){for(const e of this._fileInfos.values())e.then(e=>e.file.free);this._fileInfos.clear(),this._queue.destroy()}setCustomParameters(e){this._customParameters=e}getIndexMap(){return this._indexMap}async getFileId(e){const t=this._fileInfos.get(e);if(!t)throw new Error(`InternalError: File ${e} does not exist`);return(await t).id}async getFileInfo(e){const t=this._fileInfos.get(e);if(!t)throw new Error(`InternalError: File ${e} does not exist`);return t}async getFileInfos(){return Promise.all(Array.from(this._fileInfos.values()))}async getFileStatistics(){if(!this._fileInfos.size)return null;const e=(await this.getFileInfos()).reduce((e,t)=>e+t.file.byteLength(),0);return{featureCount:await this._getFeatureCount(),byteLength:e}}async updateFiles(e){const t=new Set(e);for(const[r,s]of this._fileInfos.entries())t.has(r)?t.delete(r):(s.then(e=>e.file.free()),this._fileInfos.delete(r));await Promise.all(Array.from(t.values()).map(e=>this._addFile(e)))}async queryFeatures(e,t){this._validateQuery(e),Z(e)||(e.resultRecordCount=e.resultRecordCount?Math.min(e.resultRecordCount,8e3):8e3,e.resultOffset=e.resultOffset??0),(e.outStatistics||e.returnDistinctValues)&&(e.returnGeometry=void 0);return(await this._enqueueQuery(e,t)).createQueryResponse()}async queryFeatureCount(e,t){const r=await I(e,null,this._queryEngineParams.spatialReference);if(this._validateQuery(r),!N(r))return this._getFeatureCount();r.outFields=void 0,r.returnGeometry=void 0;return(await this._enqueueQuery(r,t)).createQueryResponseForCount()}async queryObjectIds(e,t){const r=await I(e,null,this._queryEngineParams.spatialReference);if(this._validateQuery(r),!N(r))return Array.from({length:await this._getFeatureCount()},(e,t)=>t);r.resultRecordCount=r.resultRecordCount?Math.min(r.resultRecordCount,8e3):8e3,r.resultOffset=r.resultOffset??0,r.returnGeometry=void 0,r.outFields=void 0;return(await this._enqueueQuery(r,t)).items.map(e=>e.getObjectId())}async queryExtent(e,t){const r=await I(e,null,this._queryEngineParams.spatialReference);if(this._validateQuery(r),this._fullExtent&&!N(r))return{count:await this._getFeatureCount(),extent:this._fullExtent};const i=s(this._metadata.spatialReference);r.returnGeometry=!0,r.outFields=void 0;const o=c(d(),y),a=d(),n=await this._enqueueQuery(r,t);let u=0;for(const s of n.items)s.getBounds(a)&&(m(o,a),u+=1);return{count:u,extent:g(o,i,r.outSR?s(r.outSR):i,i,!1)}}async queryStream(e,t,r){if(!r.signal)throw new Error("InternalError: AbortSignal must be passed");const s=await this.getFileInfo(e),i=(await O()).Query.new();"tile"===t.type&&(i.setExtent(t.extent),i.setQuantizationTransform(t.transform),i.setScale(t.scale)),i.setOutFields(t.outFields.filter(e=>null!=this._indexMap[e])),i.setOutSpatialReference(t.outSpatialReference.wkid),i.setReturnGeometry(!0),t.where&&await this._setWhereClause(i,s.file,t.where);const o=await s.file.executeQuery(i,r.signal),n=s.streamIdCounter++,u=a(r.signal,e=>{const t=s.streams.get(n);null!=t&&(t.handle.remove(),s.streams.delete(n))});return s.streams.set(n,{stream:o,handle:u}),n}async getStreamNext(e,t,r){if(!r.signal)throw new Error("InternalError: AbortSignal must be passed");const s=await this.getFileInfo(e),i=s.streams.get(t);if(!i)return null;const o=await i.stream.next(r.signal);return null==o&&(i.handle.remove(),s.streams.delete(t)),o?.serialize().buffer}async createPatch(e,t,r,s,i){if(!i.signal)throw new Error("InternalError: AbortSignal must be passed");const o=await this.getFileInfo(e);return(await o.file.createChunkPatch(t,r,s,i.signal)).serialize().buffer}async _getFile(e){for(const t of await this.getFileInfos())if(t.id===e)return t.file;throw new Error(`InternalError: File ${e} does not exist`)}_addFile(e){const t=this._fileInfos.size;this._fileInfos.set(e,this._createFileInfo(e,t))}async _createFileInfo(e,t){return{id:t,file:await Q(e,{geometryInfo:this._geometryInfo,getCustomParameters:()=>this._customParameters}),streamIdCounter:0,streams:new Map}}async _getFeatureCount(){return(await this.getFileInfos()).reduce((e,t)=>e+t.file.numRows(),0)}_validateQuery(e){if(!this._capabilities.query.supportsStatistics&&e.outStatistics)throw new i("parquet:unsupported","Statistics queries are not supported",{query:e});if(!this._capabilities.query.supportsOrderBy&&e.orderByFields?.length)throw new i("parquet:unsupported","Queries using orderBy are not supported",{query:e});if(!this._capabilities.query.supportsDistinct&&e.returnDistinctValues)throw new i("parquet:unsupported","Queries using returnDistinctValues are not supported",{query:e})}async _setWhereClause(e,t,r){const s=this._indexMap,o=this._fieldsIndex,a={getAttribute(e,r){const i=t.readAttribute(e.rowGroup,e.row,s[r]);if(null==i)return null;const a=o.get(r);return"esriFieldTypeString"===a.type||"esriFieldTypeDateOnly"===a.type||"esriFieldTypeTimeOnly"===a.type||"esriFieldTypeTimestampOffset"===a.type?W.decode(i):i}},n=await l(r,this._fieldsIndex);if(!n.isStandardized)throw new i("sql-parse-error","expression is not standardized");const u=(e,t)=>n.testFeatureCompiled({rowGroup:e,row:t},a,null);e.setWhere(r),e.setWhereEvaluator(u),e.setWhereFields(n.fieldNames)}async*_fetchChunks(e,t){const r=await O();for(const s of await this.getFileInfos()){const i=r.Query.new();i.setOutFields(e.fields),i.setReturnGeometry(e.returnGeometry),e.where&&await this._setWhereClause(i,s.file,e.where);const o=await s.file.executeQuery(i),a=[],u=o.next(t);for(let e=0;e<D;e++)a.push(o.next(t));let l=await u;for(;null!=l;){n(t);const e=new G(this._metadata,this._indexMap,l,s.id),r=k([new P(e,null,0,!1)],this._queryEngineParams),i=a.shift();a.push(o.next(t)),yield r,l=await i}}}_enqueueQuery(e,t){return this._queue.push(e,t)}async _executeQuery(e,t){const r=await this._getReadParams(e);if(e.where=void 0,e.objectIds?.length){const r=new Map;for(const t of e.objectIds){const e=x(t),s=R(t);let i=r.get(e);i||(i=[],r.set(e,i)),i.push(s)}const s=[];for(const[i,o]of r.entries()){const r=await this._executeFileIdQuery(e,i,o,t);for(const e of r)s.push(e)}return new _(s,e,{fieldsIndex:this._fieldsIndex,geometryType:this._metadata.geometryType,spatialReference:this._queryEngineParams.spatialReference,hasM:!1,hasZ:!1,featureAdapter:B,featureIdInfo:this._queryEngineParams.featureIdInfo})}let s=e.resultRecordCount??await this._getFeatureCount(),i=e.resultOffset??0;e.resultRecordCount=void 0,e.resultOffset=void 0;const o=[];for await(const a of this._fetchChunks(r,t)){const r=await a.executeQueryForOpaqueFeatures(e,t);if(r.length>i){const t=r.slice(i,Math.min(i+s,r.length));for(const e of t)o.push(e);if(i=0,s-=t.length,0===s)return new _(o,e,{fieldsIndex:this._fieldsIndex,geometryType:this._metadata.geometryType,spatialReference:this._queryEngineParams.spatialReference,hasM:!1,hasZ:!1,featureAdapter:B,featureIdInfo:this._queryEngineParams.featureIdInfo})}else i-=r.length}return new _(o,e,{fieldsIndex:this._fieldsIndex,geometryType:this._metadata.geometryType,spatialReference:this._queryEngineParams.spatialReference,hasM:!1,hasZ:!1,featureAdapter:B,featureIdInfo:this._queryEngineParams.featureIdInfo})}async _executeFileIdQuery(e,t,r,s){const i=await this._getReadParams(e),o=(await O()).Query.new();o.setOutFields(i.fields),o.setReturnGeometry(i.returnGeometry),o.setIds(new Uint32Array(r));const a=await this._getFile(t),n=await a.executeQuery(o,s);let u=await n.next(s),l=0;const p=[];for(;null!=u;){const e=new G(this._metadata,this._indexMap,u,t),r=new P(e,null,l++,!1);p.push(r),u=await n.next(s)}return k(p,this._queryEngineParams).executeQueryForOpaqueFeatures(e,s)}async _getReadParams(e){const t=new Set;if(e.outStatistics)for(const r of e.outStatistics)null!=r.onStatisticField&&t.add(r.onStatisticField);if(e.outFields)for(const r of e.outFields)t.add(r);return{fields:(t.has("*")?this._fieldsIndex.fields.map(e=>e.name):Array.from(t)).filter(e=>null!=this._indexMap[e]),returnGeometry:!!e.returnGeometry||!!e.geometry,where:e.where}}}function N(e){for(const t in e){const r=t;switch(r){case"resultOffset":case"resultRecordCount":case"aggregateIds":case"distance":case"gdbVersion":case"geometry":case"having":case"timeExtent":case"objectIds":case"historicMoment":case"where":return null!=e[r]}}return!1}function k(e,t){const r=new M;for(const s of e)r.insert(s);return new w({...t,featureStore:r})}function J(e){switch(e.length){case 4:return h(d(),e);case 6:return e;default:throw new i("parquet:protocol-violation","Invalid Geoparquet file. BoundingBox size must be 4 or 6.",{bbox:e})}}function V(e,t){const r=c(d(),y);for(const s of e){const e=T(s.file);if(!e)return null;const t=e.columns[e.primary_column];if(!t.bbox)return null;const i=J(t.bbox);m(r,i)}return{xmin:r[0],ymin:r[1],xmax:r[3],ymax:r[4],spatialReference:t}}function H(e){const t=e?.featureCount;let r=!1;return null!=t&&t<has("parquetlayer-full-query-feature-count")&&(r=!0),{analytics:{supportsCacheHint:!1},attachment:null,data:{isVersioned:!1,isBranchVersioned:!1,supportedCurveTypes:[],supportsAttachment:!1,supportsM:!1,supportsTrueCurve:!1,supportsZ:!1},metadata:{supportsAdvancedFieldProperties:!1},operations:{supportsCalculate:!1,supportsTruncate:!1,supportsValidateSql:!1,supportsAdd:!1,supportsDelete:!1,supportsEditing:!1,supportsChangeTracking:!1,supportsQuery:!0,supportsQueryBins:!1,supportsQueryPivot:!1,supportsQueryAnalytics:!1,supportsQueryAttachments:!1,supportsQueryTopFeatures:!1,supportsResizeAttachments:!1,supportsSync:!1,supportsUpdate:!1,supportsExceedsLimitStatistics:!1,supportsAsyncConvert3D:!1},query:{maxRecordCount:8e3,maxRecordCountFactor:void 0,maxUniqueIDCount:void 0,relativeTimeBinWindow:void 0,standardMaxRecordCount:void 0,standardMaxRecordCountNoGeometry:void 0,supportsCacheHint:!1,supportsCentroid:!0,supportsCentroidOnDegeneratedQuantizedGeometry:!1,supportsCurrentUser:!1,supportsDegeneratedQuantizedGeometry:!1,supportsDisjointSpatialRelationship:!1,supportsDistance:!1,supportsDistinct:r,supportsExtent:!1,supportsFormatPBF:!1,supportsFormatPBFWithCurves:!1,supportsGeometryProperties:!1,supportsHavingClause:!1,supportsHistoricMoment:!1,supportsMaxRecordCountFactor:!1,supportsOrderBy:r,supportsPagination:!0,supportsPaginationOnAggregatedQueries:!1,supportsPercentileStatistics:!1,supportsQuantization:!0,supportsQuantizationEditMode:!1,supportsQueryByAnonymous:!1,supportsQueryByOthers:!1,supportsQueryGeometry:!1,supportsResultType:!1,supportsReturnMesh:!1,supportsStandardizedQueriesOnly:!1,supportsTopFeaturesQuery:!1,supportsStatistics:r,supportsSpatialAggregationStatistics:!1,supportedSpatialAggregationStatistics:{envelope:!1,centroid:!1,convexHull:!1},supportsDefaultSpatialReference:!1,supportsFullTextSearch:!1,supportsCompactGeometry:!1,supportsSqlExpression:!1,supportsTrueCurve:!1,tileMaxRecordCount:void 0},queryAttributeBins:{supportsDate:!1,supportsFixedInterval:!1,supportsAutoInterval:!1,supportsFixedBoundaries:!1,supportsStackBy:!1,supportsSplitBy:!1,supportsSnapToData:!1,supportsReturnFullIntervalBin:!1,supportsFirstDayOfWeek:!1,supportsNormalization:!1},queryRelated:{supportsCount:!1,supportsOrderBy:!1,supportsPagination:!1,supportsCacheHint:!1},queryTopFeatures:{supportsCacheHint:!1},editing:{supportsDeleteByAnonymous:!1,supportsDeleteByOthers:!1,supportsGeometryUpdate:!1,supportsGlobalId:!1,supportsTrueCurveUpdate:!1,supportsTrueCurveUpdateByTrueCurveClientsOnly:!0,supportsReturnServiceEditsInSourceSpatialReference:!1,supportsRollbackOnFailure:!1,supportsUpdateByAnonymous:!1,supportsUpdateByOthers:!1,supportsUploadWithItemId:!1,supportsUpdateWithoutM:!1,supportsAsyncApplyEdits:!1,zDefault:void 0}}}function Z(e){return!!(e.objectIds?.length||e.outStatistics||e.orderByFields?.length||e.returnDistinctValues)}export{U as default};
2
+ import{__addDisposableResource as e,__disposeResources as t}from"tslib";import r from"../../../../core/Collection.js";import{toConst as s}from"../../../../core/compilerUtils.js";import i from"../../../../core/Error.js";import has from"../../../../core/has.js";import o from"../../../../core/Logger.js";import{onAbortOrThrow as a,throwIfAborted as n}from"../../../../core/promiseUtils.js";import{QueueProcessor as u}from"../../../../core/QueueProcessor.js";import{parseWhereClause as p}from"../../../../core/sql.js";import l from"../../../../geometry/SpatialReference.js";import{set as c,create as d,expandWithRect as f,expandWithAABB as m,negativeInfinity as y,fromRect as h}from"../../../../geometry/support/aaBoundingBox.js";import{getQueryResultExtent as g,QueryEngine as w}from"../../data/QueryEngine.js";import{QueryEngineResult as _}from"../../data/QueryEngineResult.js";import{normalizeQueryLike as I}from"../../data/queryUtils.js";import{createDrawingInfo as F}from"./clientSideDefaults.js";import{getParquetFileId as x,getParquetRowId as R}from"./parquetIdUtils.js";import S from"../../../support/Field.js";import q from"../../../support/FieldsIndex.js";import{fromParquetGeometryEncodingJSON as C}from"../../../support/parquetEncodingUtils.js";import{completeParquetLayerInfo as v,fromParquetJSONGeometryType as E,toParquetJSONGeometryType as b}from"../../../support/parquetUtils.js";import{loadParquetModule as O}from"../../../../libs/parquet/loadParquetModule.js";import{createParquetFile as Q,readGeoMetadata as T}from"../../../../libs/parquet/parquet.js";import{FeatureStoreQueryAdapter as j}from"../../../../views/2d/layers/features/FeatureStoreQueryAdapter.js";import{FeatureSnapshotSourceChunk as P}from"../../../../views/2d/layers/features/sources/strategies/chunks/FeatureSnapshotSourceChunk.js";import{FeatureSourceChunkStore as M}from"../../../../views/2d/layers/features/sources/strategies/chunks/SourceChunkStore.js";import{FeatureMetadata as A}from"../../../../views/2d/layers/features/support/FeatureMetadata.js";import{FeatureSetReaderParquet as G}from"../../../../views/2d/layers/features/support/FeatureSetReaderParquet.js";const B=new j,D=4,z="__OBJECTID",W=new TextDecoder;class U{constructor(){this._fileInfos=new Map,this._queue=new u({concurrency:D,process:(e,t)=>this._executeQuery(e,t)}),this._indexMap={}}async load(s){const a=s.spatialReference?l.fromJSON(s.spatialReference):void 0;if(a&&!a.isWGS84&&!a.isWebMercator)throw new i("parquet:unsupported-projection","Only WGS84 and Web Mercator are supported");const n=await v({urls:new r(s.urls),fields:s.fields?.map(e=>S.fromJSON(e)),geometryEncoding:s.geometryEncoding?C(s.geometryEncoding):null,geometryType:s.geometryType?E(s.geometryType):null,displayOptimization:s.displayOptimization,spatialReference:a},{customParameters:s.customParameters});if(!n.fields)throw new i("parquet:unsupported","Fields must be defined");let u;if(n.spatialReference&&n.geometryType){if(!n.spatialReference)throw new i("parquet:unsupported","SpatialReference must be defined");if(!n.spatialReference.isGeographic&&!n.spatialReference.isWebMercator)throw new i("parquet:unsupported-projection","Only WGS84 and Web Mercator are supported");n.spatialReference.isGeographic&&!n.spatialReference.isWGS84&&(o.getLogger("parquet:unsupported-projection").warn("Found a geographic projection that is not WGS84. Handling as WGS84.",{spatialReference:n.spatialReference}),n.spatialReference=l.WGS84),u={geometry:n.geometryEncoding?{geometryType:b(n.geometryType),spatialReference:n.spatialReference.toJSON(),encoding:n.geometryEncoding.toJSON()}:null,displayOptimization:n.displayOptimization}}this.setCustomParameters(s.customParameters),this._geometryInfo=u;const p=s.urls;for(const e of p)this._addFile(e);this._capabilities=H(await this.getFileStatistics());const m=this._fileInfos.values().next().value;if(!m)return{layerDefinition:{},capabilities:H(null)};const h=await m,{fields:g}=n;if(null==g)throw new i("parquet-layer:missing-metadata","Unable to create parquet source: cannot infer fields",g);g.push(new S({name:z,type:"oid",alias:z}));for(const e of g){const t=h.file.columnForFieldName(e.name);null!=t&&(this._indexMap[e.name]=t)}const w=new q(g.map(e=>e.toJSON()));this._fieldsIndex=w;const _=b(n.geometryType??"point");if(this._metadata=A.createFeature({fieldsIndex:w.toJSON(),geometryType:_,hasZ:!1,hasM:!1,featureIdInfo:{type:"object-id",fieldName:"rowId"},subtypes:null,subtypeField:null,types:null,typeIdField:null,globalIdField:null,spatialReference:n.spatialReference,outSpatialReference:null,timeInfo:null,timeReferenceUnknownClient:null,dateFieldsTimeZone:null}),this._queryEngineParams={fieldsIndex:this._metadata.fieldsIndex,geometryType:_,featureIdInfo:{type:"object-id",fieldName:"rowId"},hasM:!1,hasZ:!1,spatialReference:n.spatialReference?.toJSON()??{wkid:4326},aggregateAdapter:null,timeInfo:null,definitionExpression:null},n.spatialReference){const e=await this.getFileInfos();this._fullExtent=V(e,n.spatialReference.toJSON())}if(null==this._fullExtent&&"location"===n.geometryEncoding?.type){const{xField:r,yField:s}=n.geometryEncoding,i=c(d(),y);for(const o of await this.getFileInfos())for(const a of o.file.rowGroups()){const o={stack:[],error:void 0,hasError:!1};try{const t=e(o,a.columnDescriptorForAttribute(r),!1),n=e(o,a.columnDescriptorForAttribute(s),!1),u=[t.minValue(),n.minValue(),t.maxValue(),n.maxValue()];f(i,u),a.free()}catch(I){o.error=I,o.hasError=!0}finally{t(o)}}this._fullExtent={xmin:i[0],ymin:i[1],xmax:i[3],ymax:i[4],spatialReference:n.spatialReference?.toJSON()}}return{capabilities:this._capabilities,layerDefinition:{fields:n.fields?.map(e=>e.toJSON()),drawingInfo:F(_),extent:this._fullExtent??void 0,geometryType:_,geometryEncoding:n.geometryEncoding?.toJSON(),displayOptimization:n.displayOptimization}}}destroy(){for(const e of this._fileInfos.values())e.then(e=>e.file.free);this._fileInfos.clear(),this._queue.destroy()}setCustomParameters(e){this._customParameters=e}getIndexMap(){return this._indexMap}async getFileId(e){const t=this._fileInfos.get(e);if(!t)throw new Error(`InternalError: File ${e} does not exist`);return(await t).id}async getFileInfo(e){const t=this._fileInfos.get(e);if(!t)throw new Error(`InternalError: File ${e} does not exist`);return t}async getFileInfos(){return Promise.all(Array.from(this._fileInfos.values()))}async getFileStatistics(){if(!this._fileInfos.size)return null;const e=(await this.getFileInfos()).reduce((e,t)=>e+t.file.byteLength(),0);return{featureCount:await this._getFeatureCount(),byteLength:e}}async updateFiles(e){const t=new Set(e);for(const[r,s]of this._fileInfos.entries())t.has(r)?t.delete(r):(s.then(e=>e.file.free()),this._fileInfos.delete(r));await Promise.all(Array.from(t.values()).map(e=>this._addFile(e)))}async queryFeatures(e,t){this._validateQuery(e),Z(e)||(e.resultRecordCount=e.resultRecordCount?Math.min(e.resultRecordCount,8e3):8e3,e.resultOffset=e.resultOffset??0),(e.outStatistics||e.returnDistinctValues)&&(e.returnGeometry=void 0);return(await this._enqueueQuery(e,t)).createQueryResponse()}async queryFeatureCount(e,t){const r=await I(e,null,this._queryEngineParams.spatialReference);if(this._validateQuery(r),!N(r))return this._getFeatureCount();r.outFields=void 0,r.returnGeometry=void 0;return(await this._enqueueQuery(r,t)).createQueryResponseForCount()}async queryObjectIds(e,t){const r=await I(e,null,this._queryEngineParams.spatialReference);if(this._validateQuery(r),!N(r))return Array.from({length:await this._getFeatureCount()},(e,t)=>t);r.resultRecordCount=r.resultRecordCount?Math.min(r.resultRecordCount,8e3):8e3,r.resultOffset=r.resultOffset??0,r.returnGeometry=void 0,r.outFields=void 0;return(await this._enqueueQuery(r,t)).items.map(e=>e.getObjectId())}async queryExtent(e,t){const r=await I(e,null,this._queryEngineParams.spatialReference);if(this._validateQuery(r),this._fullExtent&&!N(r))return{count:await this._getFeatureCount(),extent:this._fullExtent};const i=s(this._metadata.spatialReference);r.returnGeometry=!0,r.outFields=void 0;const o=c(d(),y),a=d(),n=await this._enqueueQuery(r,t);let u=0;for(const s of n.items)s.getBounds(a)&&(m(o,a),u+=1);return{count:u,extent:g(o,i,r.outSR?s(r.outSR):i,i,!1)}}async queryStream(e,t,r){if(!r.signal)throw new Error("InternalError: AbortSignal must be passed");const s=await this.getFileInfo(e),i=(await O()).Query.new();"tile"===t.type&&(i.setExtent(t.extent),i.setQuantizationTransform(t.transform),i.setScale(t.scale)),i.setOutFields(t.outFields.filter(e=>null!=this._indexMap[e])),i.setOutSpatialReference(t.outSpatialReference.wkid),i.setReturnGeometry(!0),t.where&&await this._setWhereClause(i,s.file,t.where);const o=await s.file.executeQuery(i,r.signal),n=s.streamIdCounter++,u=a(r.signal,e=>{const t=s.streams.get(n);null!=t&&(t.handle.remove(),s.streams.delete(n))});return s.streams.set(n,{stream:o,handle:u}),n}async getStreamNext(e,t,r){if(!r.signal)throw new Error("InternalError: AbortSignal must be passed");const s=await this.getFileInfo(e),i=s.streams.get(t);if(!i)return null;const o=await i.stream.next(r.signal);return null==o&&(i.handle.remove(),s.streams.delete(t)),o?.serialize().buffer}async createPatch(e,t,r,s,i){if(!i.signal)throw new Error("InternalError: AbortSignal must be passed");const o=await this.getFileInfo(e);return(await o.file.createChunkPatch(t,r,s,i.signal)).serialize().buffer}async _getFile(e){for(const t of await this.getFileInfos())if(t.id===e)return t.file;throw new Error(`InternalError: File ${e} does not exist`)}_addFile(e){const t=this._fileInfos.size;this._fileInfos.set(e,this._createFileInfo(e,t))}async _createFileInfo(e,t){return{id:t,file:await Q(e,{geometryInfo:this._geometryInfo,getCustomParameters:()=>this._customParameters}),streamIdCounter:0,streams:new Map}}async _getFeatureCount(){return(await this.getFileInfos()).reduce((e,t)=>e+t.file.numRows(),0)}_validateQuery(e){if(!this._capabilities.query.supportsStatistics&&e.outStatistics)throw new i("parquet:unsupported","Statistics queries are not supported",{query:e});if(!this._capabilities.query.supportsOrderBy&&e.orderByFields?.length)throw new i("parquet:unsupported","Queries using orderBy are not supported",{query:e});if(!this._capabilities.query.supportsDistinct&&e.returnDistinctValues)throw new i("parquet:unsupported","Queries using returnDistinctValues are not supported",{query:e})}async _setWhereClause(e,t,r){const s=this._indexMap,o=this._fieldsIndex,a={getAttribute(e,r){const i=t.readAttribute(e.rowGroup,e.row,s[r]);if(null==i)return null;const a=o.get(r);return"esriFieldTypeString"===a.type||"esriFieldTypeDateOnly"===a.type||"esriFieldTypeTimeOnly"===a.type||"esriFieldTypeTimestampOffset"===a.type?W.decode(i):i}},n=await p(r,this._fieldsIndex);if(!n.isStandardized)throw new i("sql-parse-error","expression is not standardized");const u=(e,t)=>n.testFeatureCompiled({rowGroup:e,row:t},a,null);e.setWhere(r),e.setWhereEvaluator(u),e.setWhereFields(n.fieldNames)}async*_fetchChunks(e,t){const r=await O();for(const s of await this.getFileInfos()){const i=r.Query.new();i.setOutFields(e.fields),i.setReturnGeometry(e.returnGeometry),e.where&&await this._setWhereClause(i,s.file,e.where);const o=await s.file.executeQuery(i),a=[],u=o.next(t);for(let e=0;e<D;e++)a.push(o.next(t));let p=await u;for(;null!=p;){n(t);const e=new G(this._metadata,this._indexMap,p,s.id),r=k([new P(e,null,0,!1)],this._queryEngineParams),i=a.shift();a.push(o.next(t)),yield r,p=await i}}}_enqueueQuery(e,t){return this._queue.push(e,t)}async _executeQuery(e,t){const r=await this._getReadParams(e);if(e.where=void 0,e.objectIds?.length){const r=new Map;for(const t of e.objectIds){const e=x(t),s=R(t);let i=r.get(e);i||(i=[],r.set(e,i)),i.push(s)}const s=[];for(const[i,o]of r.entries()){const r=await this._executeFileIdQuery(e,i,o,t);for(const e of r)s.push(e)}return new _(s,e,{fieldsIndex:this._fieldsIndex,geometryType:this._metadata.geometryType,spatialReference:this._queryEngineParams.spatialReference,hasM:!1,hasZ:!1,featureAdapter:B,featureIdInfo:this._queryEngineParams.featureIdInfo})}let s=e.resultRecordCount??await this._getFeatureCount(),i=e.resultOffset??0;e.resultRecordCount=void 0,e.resultOffset=void 0;const o=[];for await(const a of this._fetchChunks(r,t)){const r=await a.executeQueryForOpaqueFeatures(e,t);if(r.length>i){const t=r.slice(i,Math.min(i+s,r.length));for(const e of t)o.push(e);if(i=0,s-=t.length,0===s)return new _(o,e,{fieldsIndex:this._fieldsIndex,geometryType:this._metadata.geometryType,spatialReference:this._queryEngineParams.spatialReference,hasM:!1,hasZ:!1,featureAdapter:B,featureIdInfo:this._queryEngineParams.featureIdInfo})}else i-=r.length}return new _(o,e,{fieldsIndex:this._fieldsIndex,geometryType:this._metadata.geometryType,spatialReference:this._queryEngineParams.spatialReference,hasM:!1,hasZ:!1,featureAdapter:B,featureIdInfo:this._queryEngineParams.featureIdInfo})}async _executeFileIdQuery(e,t,r,s){const i=await this._getReadParams(e),o=(await O()).Query.new();o.setOutFields(i.fields),o.setReturnGeometry(i.returnGeometry),o.setIds(new Uint32Array(r));const a=await this._getFile(t),n=await a.executeQuery(o,s);let u=await n.next(s),p=0;const l=[];for(;null!=u;){const e=new G(this._metadata,this._indexMap,u,t),r=new P(e,null,p++,!1);l.push(r),u=await n.next(s)}return k(l,this._queryEngineParams).executeQueryForOpaqueFeatures(e,s)}async _getReadParams(e){const t=new Set;if(e.outStatistics)for(const r of e.outStatistics)null!=r.onStatisticField&&t.add(r.onStatisticField);if(e.outFields)for(const r of e.outFields)t.add(r);return{fields:(t.has("*")?this._fieldsIndex.fields.map(e=>e.name):Array.from(t)).filter(e=>null!=this._indexMap[e]),returnGeometry:!!e.returnGeometry||!!e.geometry,where:e.where}}}function N(e){for(const t in e){const r=t;switch(r){case"resultOffset":case"resultRecordCount":case"aggregateIds":case"distance":case"gdbVersion":case"geometry":case"having":case"timeExtent":case"objectIds":case"historicMoment":case"where":return null!=e[r]}}return!1}function k(e,t){const r=new M;for(const s of e)r.insert(s);return new w({...t,featureStore:r})}function J(e){switch(e.length){case 4:return h(d(),e);case 6:return e;default:throw new i("parquet:protocol-violation","Invalid Geoparquet file. BoundingBox size must be 4 or 6.",{bbox:e})}}function V(e,t){const r=c(d(),y);for(const s of e){const e=T(s.file);if(!e)return null;const t=e.columns[e.primary_column];if(!t.bbox)return null;const i=J(t.bbox);m(r,i)}return{xmin:r[0],ymin:r[1],xmax:r[3],ymax:r[4],spatialReference:t}}function H(e){const t=e?.featureCount;let r=!1;return null!=t&&t<has("parquetlayer-full-query-feature-count")&&(r=!0),{analytics:{supportsCacheHint:!1},attachment:null,data:{isVersioned:!1,isBranchVersioned:!1,supportedCurveTypes:[],supportsAttachment:!1,supportsM:!1,supportsTrueCurve:!1,supportsZ:!1},metadata:{supportsAdvancedFieldProperties:!1},operations:{supportsCalculate:!1,supportsTruncate:!1,supportsValidateSql:!1,supportsAdd:!1,supportsDelete:!1,supportsEditing:!1,supportsChangeTracking:!1,supportsQuery:!0,supportsQueryBins:!1,supportsQueryPivot:!1,supportsQueryAnalytics:!1,supportsQueryAttachments:!1,supportsQueryTopFeatures:!1,supportsResizeAttachments:!1,supportsSync:!1,supportsUpdate:!1,supportsExceedsLimitStatistics:!1,supportsAsyncConvert3D:!1},query:{maxRecordCount:8e3,maxRecordCountFactor:void 0,maxUniqueIDCount:void 0,relativeTimeBinWindow:void 0,standardMaxRecordCount:void 0,standardMaxRecordCountNoGeometry:void 0,supportsAggregateIds:!1,supportsCacheHint:!1,supportsCentroid:!0,supportsCentroidOnDegeneratedQuantizedGeometry:!1,supportsCurrentUser:!1,supportsDegeneratedQuantizedGeometry:!1,supportsDisjointSpatialRelationship:!1,supportsDistance:!1,supportsDistinct:r,supportsExtent:!1,supportsFormatPBF:!1,supportsFormatPBFWithCurves:!1,supportsGeometryProperties:!1,supportsHavingClause:!1,supportsHistoricMoment:!1,supportsMaxRecordCountFactor:!1,supportsOrderBy:r,supportsPagination:!0,supportsPaginationOnAggregatedQueries:!1,supportsPercentileStatistics:!1,supportsQuantization:!0,supportsQuantizationEditMode:!1,supportsQueryByAnonymous:!1,supportsQueryByOthers:!1,supportsQueryGeometry:!1,supportsResultType:!1,supportsReturnMesh:!1,supportsStandardizedQueriesOnly:!1,supportsTopFeaturesQuery:!1,supportsStatistics:r,supportsSpatialAggregationStatistics:!1,supportedSpatialAggregationStatistics:{envelope:!1,centroid:!1,convexHull:!1},supportsDefaultSpatialReference:!1,supportsFullTextSearch:!1,supportsCompactGeometry:!1,supportsSqlExpression:!1,supportsTrueCurve:!1,tileMaxRecordCount:void 0},queryAttributeBins:{supportsDate:!1,supportsFixedInterval:!1,supportsAutoInterval:!1,supportsFixedBoundaries:!1,supportsStackBy:!1,supportsSplitBy:!1,supportsSnapToData:!1,supportsReturnFullIntervalBin:!1,supportsFirstDayOfWeek:!1,supportsNormalization:!1},queryRelated:{supportsCount:!1,supportsOrderBy:!1,supportsPagination:!1,supportsCacheHint:!1},queryTopFeatures:{supportsCacheHint:!1},editing:{supportsDeleteByAnonymous:!1,supportsDeleteByOthers:!1,supportsGeometryUpdate:!1,supportsGlobalId:!1,supportsTrueCurveUpdate:!1,supportsTrueCurveUpdateByTrueCurveClientsOnly:!0,supportsReturnServiceEditsInSourceSpatialReference:!1,supportsRollbackOnFailure:!1,supportsUpdateByAnonymous:!1,supportsUpdateByOthers:!1,supportsUploadWithItemId:!1,supportsUpdateWithoutM:!1,supportsAsyncApplyEdits:!1,zDefault:void 0}}}function Z(e){return!!(e.objectIds?.length||e.outStatistics||e.orderByFields?.length||e.returnDistinctValues)}export{U as default};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../Graphic.js";import i from"../../request.js";import r from"../../core/Error.js";import{clone as s}from"../../core/lang.js";import n from"../../core/Logger.js";import{watch as a}from"../../core/reactiveUtils.js";import{urlToObject as o}from"../../core/urlUtils.js";import{property as l,subclass as u}from"../../core/accessorSupport/decorators.js";import{Integer as p,ensureClass as m}from"../../core/accessorSupport/ensureType.js";import{runUntracked as c}from"../../core/accessorSupport/tracking.js";import h from"../../geometry/Extent.js";import d from"../../geometry/Polygon.js";import f from"../../geometry/SpatialReference.js";import{srToRESTValue as y}from"../../geometry/support/spatialReferenceUtils.js";import{intersectMultimensionalSubset as g,getEffectiveMultidimensionalDefinition as R,getSubsetVariablesFromMdInfo as I,getDefaultMultidimensionalDefinition as w}from"../raster/datasets/multidimensionalUtils.js";import{decode as v,getFormat as b}from"../raster/formats/RasterCodec.js";import{uvComponentToVector as x}from"../raster/functions/vectorFieldUtils.js";import{opacity as S,url as F}from"../support/commonProperties.js";import _ from"../support/DimensionalDefinition.js";import{ExportImageServiceParameters as D}from"../support/ExportImageServiceParameters.js";import O from"../support/Field.js";import T from"../support/FieldsIndex.js";import{createBitmap as C}from"../support/imageBitmapUtils.js";import{isSupportedRendererType as M}from"../support/imageryRendererUtils.js";import q from"../support/MosaicRule.js";import N from"../support/MultidimensionalSubset.js";import P from"../support/PixelBlock.js";import{interpolationKebab as j,noDataInterpretationKebab as E,pixelTypeKebabDict as A}from"../support/rasterEnums.js";import{getServicePixelValueField as Q,getItemPixelValueField as V,getRawServicePixelValueField as J,getProcessedServicePixelValueField as U,getMagnitudeField as B,getDirectionField as z,getMultidimensionalFields as L,getRasterAttributeTableFields as H,addMultidimensionalFieldValues as G,commonRasterFieldNames as k,rasterFieldPrefix as W}from"../support/rasterFieldUtils.js";import $ from"../support/RasterFunction.js";import X from"../support/RasterInfo.js";import{createDefaultRenderer as K,getDefaultBandCombination as Y,getSupportedRendererTypes as Z,matchPresetRenderer as ee,normalizeRendererJSON as te}from"../../renderers/support/rasterRendererHelper.js";import ie from"../../renderers/support/RasterSymbolizer.js";import{rasterRendererTypes as re,websceneRasterRendererTypes as se,read as ne}from"../../renderers/support/rasterTypeUtils.js";import{calculateVolume as ae,computeAngles as oe,computePixelSpaceLocations as le,computeHistograms as ue,computeStatisticsHistograms as pe,measureHeight as me,measureAreaAndPerimeter as ce,measureDistanceAndAngle as he,measurePointOrCentroid as de,measureLengthFromImage as fe,measureAreaFromImage as ye,getImageSpatialReferenceQueryParameter as ge,getSamples as Re,identify as Ie,imageToMap as we,imageToMapMultiray as ve,mapToImage as be,findImages as xe,getImageUrl as Se,queryBoundary as Fe,queryGPSInfo as _e}from"../../rest/imageService.js";import{fetchServiceRasterInfo as De,generateRasterInfo as Oe,patchServiceInfo as Te}from"../../rest/imageService/fetchRasterInfo.js";import{getCatalogItemRasterInfo as Ce}from"../../rest/imageService/getCatalogItemRasterInfo.js";import{executeForCount as Me}from"../../rest/query/executeForCount.js";import{executeForExtent as qe}from"../../rest/query/executeForExtent.js";import{executeForIds as Ne}from"../../rest/query/executeForIds.js";import{executeQueryJSON as Pe}from"../../rest/query/executeQueryJSON.js";import je from"../../rest/support/FeatureSet.js";import Ee from"../../rest/support/ImageIdentifyParameters.js";import Ae from"../../rest/support/Query.js";import{reader as Qe}from"../../core/accessorSupport/decorators/reader.js";import{writer as Ve}from"../../core/accessorSupport/decorators/writer.js";const Je=new Set(["png","png8","png24","png32","jpg","bmp","gif","jpgpng","lerc","tiff"]);function Ue(e){const t=JSON.stringify(e),i=t.includes('"rasterFunctionDefinition":{'),r=i?t.match(/"type":"(.*?FunctionArguments")/gi):t.match(/"rasterFunction":"(.*?")/gi),s=r?.map(e=>i?e.slice(8,-18):e.slice(18,-1));return s?s.join("/"):null}const Be=Be=>{const ze=Be;let Le=class extends ze{constructor(){super(...arguments),this._functionRasterInfos={},this._serviceSupportsMosaicRule=null,this.adjustAspectRatio=null,this.bandIds=void 0,this.capabilities=null,this.compressionQuality=void 0,this.compressionTolerance=.01,this.copyright=null,this.defaultMosaicRule=null,this.definitionExpression=null,this.exportImageServiceParameters=null,this.rasterInfo=null,this.fields=null,this.fullExtent=null,this.hasMultidimensions=!1,this.imageMaxHeight=4100,this.imageMaxWidth=4100,this.interpolation=void 0,this.minScale=0,this.maxScale=0,this.multidimensionalInfo=null,this.multidimensionalSubset=null,this.noData=null,this.noDataInterpretation=void 0,this.objectIdField=null,this.geometryType="polygon",this.typeIdField=null,this.types=[],this.pixelFilter=null,this.raster=void 0,this.sourceType=null,this.viewId=void 0,this.symbolizer=null,this.rasterFunctionInfos=null,this.serviceDataType=null,this.spatialReference=null,this.pixelType=null,this.serviceRasterInfo=null,this.sourceJSON=null,this.url=null,this.version=void 0}initialize(){this._set("exportImageServiceParameters",new D({layer:this}))}readServiceSupportsMosaicRule(e,t){return this._isMosaicRuleSupported(t)}get _rasterFunctionNamesIndex(){const e=new Map;return!this.rasterFunctionInfos||null!=this.rasterFunctionInfos&&this.rasterFunctionInfos.length<1||null!=this.rasterFunctionInfos&&this.rasterFunctionInfos.forEach(t=>{e.set(t.name.toLowerCase().replaceAll(/ /gi,"_"),t.name)}),e}readBandIds(e,t){if(Array.isArray(e)&&e.length>0&&e.every(e=>"number"==typeof e))return e}readCapabilities(e,t){return this._readCapabilities(t)}writeCompressionQuality(e,t,i){null!=e&&"lerc"!==this.format&&(t[i]=e)}writeCompressionTolerance(e,t,i){"lerc"===this.format&&null!=e&&(t[i]=e)}readDefaultMosaicRule(e,t){return this._serviceSupportsMosaicRule?c(()=>q.fromJSON(t)):null}get fieldsIndex(){return this.fields?new T(this.fields):null}set format(e){e&&Je.has(e.toLowerCase())&&this._set("format",e.toLowerCase())}readFormat(e,t){return"esriImageServiceDataTypeVector-UV"===t.serviceDataType||"esriImageServiceDataTypeVector-MagDir"===t.serviceDataType||null!=this.pixelFilter?"lerc":"jpgpng"}get isRenderedFormat(){return!this.format||this.format.includes("jpg")||this.format.includes("png")}readMinScale(e,t){return null!=t.minLOD&&null!=t.maxLOD?e:0}readMaxScale(e,t){return null!=t.minLOD&&null!=t.maxLOD?e:0}set mosaicRule(e){let t=e;t?.mosaicMethod&&(t=q.fromJSON({...t.toJSON(),mosaicMethod:t.mosaicMethod,mosaicOperation:t.mosaicOperation})),this._set("mosaicRule",t)}readMosaicRule(e,t){const i=e||t.mosaicRule;return i?q.fromJSON(i):this._isMosaicRuleSupported(t)?q.fromJSON(t):null}writeMosaicRule(e,t,i){const{mosaicRule:r}=this;this._isValidCustomizedMosaicRule(r)&&(t[i]=r.toJSON())}readObjectIdField(e,t){if(!e){const i=t.fields.find(e=>"esriFieldTypeOID"===e.type||"oid"===e.type);e=i?.name}return e}get parsedUrl(){return o(this.url)}readSourceType(e,t){return this._isMosaicDataset(t)?"mosaic-dataset":"raster-dataset"}get renderer(){const{activePresetRendererName:e,presetRenderers:t}=this;if(e){const i=t?.find(({name:t})=>t===e);return i?.renderer.clone()}return this.internalRenderer}set renderer(e){this.activePresetRendererName=null,this.internalRenderer=e}set internalRenderer(e){this.loaded&&(e=this._configRenderer(e)),this._set("internalRenderer",e)}readRenderer(e,t,i){const r=t?.layerDefinition?.drawingInfo?.renderer,s=ne(r,i);return null==s?null:("vector-field"===s.type&&t.symbolTileSize&&!r.symbolTileSize&&(s.symbolTileSize=t.symbolTileSize),M(s)||n.getLogger(this).warn("ArcGISImageService","Imagery layer doesn't support given renderer type."),s)}writeRenderer(e,t,i){t.layerDefinition=t.layerDefinition||{},t.layerDefinition.drawingInfo=t.layerDefinition.drawingInfo||{},t.layerDefinition.drawingInfo.renderer=e.toJSON()}get rasterFields(){const e=this.fields?.map(e=>e.clone())??[];e.push(Q()),"mosaic-dataset"===this.sourceType&&this.fields?.length&&e.push(V()),this.version>=10.4&&null!=this.rasterFunctionInfos&&this.rasterFunctionInfos.some(({name:e})=>"none"===e.toLowerCase())&&e.push(J()),null!=this.rasterFunctionInfos&&this.rasterFunctionInfos.filter(({name:e})=>"none"!==e.toLowerCase()).forEach(({name:t})=>e.push(U(t)));const{rasterInfo:t}=this;if(this._isVectorDataSet()){const i=t?.multidimensionalInfo?.variables[0].unit?.trim(),r=B(i),s=z();e.push(r,s)}if(t?.multidimensionalInfo&&"raster-dataset"===this.sourceType){const i=L(t.multidimensionalInfo);e.push(...i)}const i=t?.attributeTable;if(null!=i){const t=H(i);e.push(...t)}return e}set rasterFunction(e){let t=e;t?.rasterFunction&&(t=$.fromJSON({...t.toJSON(),rasterFunction:t.rasterFunction,rasterFunctionArguments:t.rasterFunctionArguments})),this._set("rasterFunction",t)}readRasterFunction(e,t){const i=t.rasterFunctionInfos;return t.renderingRule||i?.length&&"None"!==i[0].name?this._isRFTJson(t.renderingRule)?$.fromJSON({rasterFunctionDefinition:t.renderingRule}):$.fromJSON(t.renderingRule||{rasterFunctionInfos:t.rasterFunctionInfos}):null}readSpatialReference(e,t){const i=e||t.extent.spatialReference;return i?f.fromJSON(i):null}writePixelType(e,t,i){null!=this.serviceRasterInfo&&this.pixelType===this.serviceRasterInfo.pixelType||(t[i]=A.toJSON(e))}readVersion(e,t){let i=t.currentVersion;return i||(i=t.hasOwnProperty("fields")||t.hasOwnProperty("timeInfo")?10:9.3),i}applyFilter(e){let t=e;return this.pixelFilter&&(t=this._clonePixelData(e),this.pixelFilter(t)),t}async applyRenderer(e,t){let i=e,{renderer:r,symbolizer:s,pixelFilter:n}=this;const{isRawData:a}=e;if(a&&"lerc"!==this.format&&(r??=K(this.rasterInfo,{bandIds:this.bandIds,variableName:this.rasterFunction?null:this.mosaicRule?.multidimensionalDefinition?.[0].variableName}),s||(this.symbolizer=new ie({rendererJSON:r.toJSON(),rasterInfo:this.rasterInfo}),s=this.symbolizer)),(a||!this.isRenderedFormat)&&r&&s&&!n){await this._updateSymbolizer(s,r);const n=this.bandIds?.length?this.bandIds:Y(this.rasterInfo);i=await this._symbolize({pixelData:e,bandIds:n,symbolizer:s},t)}return i}destroy(){this._shutdownJobHandler()}async calculateVolume(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsCalculateVolume)throw new r("imagery-layer:compute-pixel-space-locations","this operation is not supported on the input image service");return e=s(e),this.mosaicRule&&null==e.mosaicRule&&(e.mosaicRule=this.mosaicRule),ae(this.url,e,this._getRequestOptions(t))}async computeAngles(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsComputeAngles)throw new r("imagery-layer:compute-angles","this operation is not supported on the input image service");return oe(this.url,e,this._getRequestOptions(t))}async computePixelSpaceLocations(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsComputePixelLocation)throw new r("imagery-layer:compute-pixel-space-locations","this operation is not supported on the input image service");return le(this.url,e,this._getRequestOptions(t))}async computeHistograms(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsComputeHistograms)throw new r("imagery-layer:compute-histograms","this operation is not supported on the input image service");return e=s(e),this._applyMosaicAndRenderingRules(e),ue(this.url,e,this._getRequestOptions(t))}async computeStatisticsHistograms(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsComputeStatisticsHistograms)throw new r("imagery-layer:compute-statistics-histograms","this operation is not supported on the input image service");return e=s(e),this._applyMosaicAndRenderingRules(e),pe(this.url,e,this._getRequestOptions(t))}async measureHeight(e,t){const i=await this._fetchCapabilities(t?.signal);if(!("base-and-top"===e.operationType?i.mensuration.supportsHeightFromBaseAndTop:"base-and-top-shadow"===e.operationType?i.mensuration.supportsHeightFromBaseAndTopShadow:i.mensuration.supportsHeightFromTopAndTopShadow))throw new r("imagery-layer:measure-height","this operation is not supported on the input image service");return e=s(e),this._applyMosaicRule(e),me(this.url,e,this._getRequestOptions(t))}async measureAreaAndPerimeter(e,t){const i=await this._fetchCapabilities(t?.signal);if(!(i.mensuration.supportsAreaAndPerimeter&&(!e.is3D||i.mensuration.supports3D)))throw new r("imagery-layer:measure-area-and-perimeter","this operation is not supported on the input image service");return e=s(e),this._applyMosaicRule(e),ce(this.url,e,this._getRequestOptions(t))}async measureDistanceAndAngle(e,t){const i=await this._fetchCapabilities(t?.signal);if(!(i.mensuration.supportsDistanceAndAngle&&(!e.is3D||i.mensuration.supports3D)))throw new r("imagery-layer:measure-distance-and-angle","this operation is not supported on the input image service");return e=s(e),this._applyMosaicRule(e),he(this.url,e,this._getRequestOptions(t))}async measurePointOrCentroid(e,t){const i=await this._fetchCapabilities(t?.signal);if(!(i.mensuration.supportsPointOrCentroid&&(!e.is3D||i.mensuration.supports3D)))throw new r("imagery-layer:measure-point-or-centroid","this operation is not supported on the input image service");return e=s(e),this._applyMosaicRule(e),de(this.url,e,this._getRequestOptions(t))}async measureLengthFromImage(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsMeasureFromImage)throw new r("imagery-layer:measure-length-from-image","this operation is not supported on the input image service");if("polyline"!==e.geometry.type)throw new r("imagery-layer:measure-length-from-image","this input geometry must be a polyline");return fe(this.url,e,this._getRequestOptions(t))}async measureAreaFromImage(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsMeasureFromImage)throw new r("imagery-layer:measure-area-from-image","this operation is not supported on the input image service");if("polygon"!==e.geometry.type)throw new r("imagery-layer:measure-area-from-image","this input geometry must be a polygon");return ye(this.url,e,this._getRequestOptions(t))}getField(e){const{fieldsIndex:t}=this;return null!=t?t.get(e):void 0}getFieldDomain(e,t){const i=this.getField(e);return i?i.domain:null}async internalFetchImage(e,t,i,r={}){await this._updateCurrentRasterInfo();const{exportImageServiceParameters:s}=this;let n=!1;r.requestRawData&&(await this._initJobHandler(),s.requestRawData||"lerc"===this.format||(n=!0,s.requestRawData=!0));const a=this.getExportImageServiceParameters(e,t,i,r.timeExtent);if(n&&(s.requestRawData=!1,a&&!this.bandIds?.length&&(null==a.bandIds||""===a.bandIds))){const e=Y(this.rasterInfo);a.bandIds=e?.join(",")}if(null==a){if(r.requestAsImageElement&&this._canRequestImageElement(this.format)){const e=document.createElement("canvas");if(e.width=t,e.height=i,r.returnImageBitmap){const{bitmap:t}=await C(e,`${He(this.parsedUrl)}/exportImage`,r);return{imageBitmap:t}}return{imageOrCanvasElement:e}}const{bandIds:s,rasterInfo:n}=this,a=(s?.length||n.bandCount)??0,o=t*i,l=n.pixelType,u=[];for(let e=0;e<a;e++)u.push(P.createEmptyBand(l,o));return{pixelData:{pixelBlock:new P({width:t,height:i,pixels:u,mask:new Uint8Array(o),pixelType:l}),extent:e}}}const o=!!r.requestAsImageElement&&!this.pixelFilter,l=o&&!!r.returnImageBitmap,u={imageServiceParameters:a,imageProps:{extent:e,width:t,height:i,format:this.format},requestAsImageElement:o,returnImageBitmap:l,signal:r.signal};return this._requestArrayBuffer(u)}async fetchPixels(e,t,i,r={}){await this._initJobHandler(),r.applyRendering&&this._updateCurrentRasterInfo();const s=r.applyRendering?void 0:new D({layer:this,requestRawData:!0,interpolation:r.interpolation??"nearest",bandIds:r.bandIds??[]}),n=this.getExportImageServiceParameters(e,t,i,r.timeExtent,s);if(null==n)return{extent:e,pixelBlock:null};delete n.pixelType,r.bandIds||delete n.bandIds,delete n.compressionQuality;const a={imageServiceParameters:n,imageProps:{extent:e,width:t,height:i,format:this.format},requestAsImageElement:!1,returnImageBitmap:!1,signal:r.signal},{pixelData:o}=await this._requestArrayBuffer(a);return o??{extent:e,pixelBlock:null}}fetchKeyProperties(e){return i(He(this.parsedUrl)+"/keyProperties",{query:this._getQueryParams({renderingRule:this.version>=10.3?e?.rasterFunction:null})}).then(e=>e.data)}fetchRasterAttributeTable(e){return this.version<10.1?Promise.reject(new r("#fetchRasterAttributeTable()","Failed to get rasterAttributeTable")):i(He(this.parsedUrl)+"/rasterAttributeTable",{query:this._getQueryParams({renderingRule:this.version>=10.3?e?.rasterFunction:null})}).then(e=>je.fromJSON(e.data))}getCatalogItemRasterInfo(e,t){const i={...t,query:this._getQueryParams()};return Ce(He(this.parsedUrl),e,i)}async getCatalogItemICSInfo(e,t){const{data:r}=await i(He(this.parsedUrl)+"/"+e+"/info/ics",{query:this._getQueryParams(),...t}),s=r?.ics;if(!s)return;let n=null;try{n=(await i(He(this.parsedUrl)+"/"+e+"/info",{query:this._getQueryParams(),...t})).data.extent}catch{}if(!n?.spatialReference)return{ics:s,icsToPixelTransform:null,icsExtent:null,northDirection:null};const a=this.version>=10.7?i(He(this.parsedUrl)+"/"+e+"/info/icstopixel",{query:this._getQueryParams(),...t}).then(e=>e.data).catch(()=>({})):{},o=n.spatialReference,l={geometries:JSON.stringify({geometryType:"esriGeometryEnvelope",geometries:[n]}),inSR:y(o),outSR:"0:"+e},u=i(He(this.parsedUrl)+"/project",{query:this._getQueryParams(l),...t}).then(e=>e.data).catch(()=>({})),p=5,m=(n.xmin+n.xmax)/2,c=(n.ymax-n.ymin)/(p+1),d=n.ymin+c,g=[];for(let i=0;i<p;i++)g.push({x:m,y:d+c*i});const R={geometries:JSON.stringify({geometryType:"esriGeometryPoint",geometries:g}),inSR:y(o),outSR:"0:"+e},I=i(He(this.parsedUrl)+"/project",{query:this._getQueryParams(R),...t}).then(e=>e.data).catch(()=>({})),w=await Promise.all([a,u,I]);let v=w[0].ipxf;if(null==v){const e=s.geodataXform?.xf_0;"topup"===e?.name?.toLowerCase()&&6===e?.coefficients?.length&&(v={affine:{name:"ics [sensor: Frame] to pixel (column, row) transformation",coefficients:e.coefficients,cellsizeRatio:0,type:"GeometricXform"}})}const b=h.fromJSON(w[1]?.geometries?.[0]);b&&(b.spatialReference=new f({wkid:0,imageCoordinateSystem:s}));const x=w[2].geometries?w[2].geometries.filter(e=>null!=e?.x&&null!=e.y&&"NaN"!==e.x&&"NaN"!==e.y):[],S=x.length;if(S<3)return{ics:s,icsToPixelTransform:v,icsExtent:b,northDirection:null};let F=0,_=0,D=0,O=0;for(let i=0;i<S;i++)F+=x[i].x,_+=x[i].y,D+=x[i].x*x[i].x,O+=x[i].x*x[i].y;const T=(S*O-F*_)/(S*D-F*F);let C=0;const M=x[p-1].x>x[0].x,q=x[p-1].y>x[0].y;return T===1/0?C=q?90:270:0===T?C=M?0:180:T>0?C=M?180*Math.atan(T)/Math.PI:180*Math.atan(T)/Math.PI+180:T<0&&(C=q?180+180*Math.atan(T)/Math.PI:360+180*Math.atan(T)/Math.PI),{ics:s,icsToPixelTransform:v,icsExtent:b,northDirection:C}}async generateRasterInfo(e,t){const i=m($,e),s={...t,query:this._getQueryParams()};if(!i||"none"===i.functionName?.toLowerCase()||this._isVectorFieldResampleFunction(i))return this.serviceRasterInfo??De(He(this.parsedUrl),this.sourceJSON,s);const n=Ue(i);if(!n)throw new r("imagery-layer:generate-raster-info","the rendering rule is not supported");if(this._functionRasterInfos[n])return this._functionRasterInfos[n];const a=Oe(He(this.parsedUrl),i,s);this._functionRasterInfos[n]=a;try{return await a}catch(o){throw this._functionRasterInfos[n]=null,o}}getExportImageServiceParameters(e,t,i,r,s){e=e.clone().shiftCentralMeridian();const n=ge(e.spatialReference,He(this.parsedUrl));s??=this.exportImageServiceParameters;const a=s.toJSON(),{bandIds:o,noData:l}=a;let{renderingRule:u}=a;const p=this.rasterFunction?.rasterFunctionDefinition,m=this.renderer?.type,c=!m||"raster-stretch"===m||"raster-colormap"===m||"unique-value"===m||"class-breaks"===m||"raster-shaded-relief"===m;if(o?.length&&this._hasRasterFunction(this.rasterFunction)&&!p&&c){const e={rasterFunction:"ExtractBand",rasterFunctionArguments:{BandIds:o}};if("Stretch"===u.rasterFunction)e.rasterFunctionArguments.Raster=u.rasterFunctionArguments.Raster,u.rasterFunctionArguments.Raster=e;else if("Colormap"===u.rasterFunction){const t=u.rasterFunctionArguments.Raster;"Stretch"===t?.rasterFunction?(e.rasterFunctionArguments.Raster=t.rasterFunctionArguments.Raster,t.rasterFunctionArguments.Raster=e):(e.rasterFunctionArguments.Raster=t,u.rasterFunctionArguments.Raster=e)}else e.rasterFunctionArguments.Raster=u,u=e;a.bandIds=void 0}else a.bandIds=o?.join(",");Array.isArray(l)&&l.length>0&&(a.noData=l.join(","));const h=this._processMultidimensionalIntersection(null,r,s.mosaicRule);if(h.isOutSide)return null;a.mosaicRule=null!=h.mosaicRule?JSON.stringify(h.mosaicRule):null,r=h.timeExtent,a.renderingRule=this._getRenderingRuleString($.fromJSON(u));const d={};if(null!=r){const{start:e,end:t}=r.toJSON();e&&t&&e===t?d.time=""+e:null==e&&null==t||(d.time=`${e??"null"},${t??"null"}`)}return{bbox:e.xmin+","+e.ymin+","+e.xmax+","+e.ymax,bboxSR:n,imageSR:n,size:t+","+i,...a,...d}}async getSamples(e,t){const i=await this._fetchCapabilities(t?.signal);if(!i?.operations.supportsGetSamples)throw new r("imagery-layer:get-samples","getSamples operation is not supported on the input image service");e=s(e);const{raster:n}=this;return n&&null==e.raster&&(e.raster=n),Re(this.url,e,this._getRequestOptions(t))}async identify(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsIdentify)throw new r("imagery-layer:identify","identify operation is not supported on the input image service");e=s(e),this.version<10.91&&"extent"===e.geometry?.type&&(e.geometry=d.fromExtent(e.geometry));const i=this._processMultidimensionalIntersection(e.geometry,e.timeExtent,e.mosaicRule||this.mosaicRule);if(i.isOutSide)throw new r("imagery-layer:identify","the request cannot be fulfilled when falling outside of the multidimensional subset");e.timeExtent=i.timeExtent,e.mosaicRule=i.mosaicRule;const{raster:n,rasterFunction:a}=this;return a&&null==e.rasterFunction&&(e.rasterFunction=a),n&&null==e.raster&&(e.raster=n),Ie(this.url,e,this._getRequestOptions(t))}async imageToMap(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsImageToMap)throw new r("imagery-layer:image-to-map","imageToMap operation is not supported on the input image service");return we(He(this.parsedUrl),e,this._getRequestOptions(t))}async imageToMapMultiray(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsImageToMapMultiray)throw new r("imagery-layer:image-to-map-multiray","imageToMapMultiray operation is not supported on the input image service");return ve(He(this.parsedUrl),e,this._getRequestOptions(t))}async mapToImage(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsMapToImage)throw new r("imagery-layer:map-to-image","mapToImage operation is not supported on the input image service");return be(He(this.parsedUrl),e,this._getRequestOptions(t))}async findImages(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsFindImages)throw new r("imagery-layer:find-images","findImages operation is not supported on the input image service");return xe(He(this.parsedUrl),e,this._getRequestOptions(t))}async getImageUrl(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsGetImageUrl)throw new r("imagery-layer:get-image-url","getImageUrl operation is not supported on the input image service");return Se(He(this.parsedUrl),e,this._getRequestOptions(t))}createQuery(){return new Ae({outFields:["*"],returnGeometry:!0,where:this.definitionExpression||"1=1"})}async queryBoundary(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsQueryBoundary)throw new r("imagery-layer:query-boundary","queryBoundary operation is not supported on the input image service");return e=e??{outSpatialReference:this.spatialReference},Fe(He(this.parsedUrl),e,this._getRequestOptions(t))}async queryExtent(e,t){({query:e,requestOptions:t}=await this._prepareForQuery(e,t));const{where:i,objectIds:r,geometry:s,timeExtent:n,start:a,num:o,pixelSize:l}=e,u=null!=i&&"1=1"!==i,p=null!=r&&r.length>0,m=null!=s&&("extent"!==s.type||!s.equals(this.fullExtent)),c=null!=l,h=null!=a||null!=o,{timeInfo:d}=this,f=null!=n&&null!=d&&!n.equals(d.fullTimeExtent);if(!(u||p||m||c||f||h)){const i=await Me(this.url,e,t),{outSpatialReference:r}=e;if(!r||r.equals(this.spatialReference))return{count:i,extent:this.fullExtent.clone()};const s=await import("../../geometry/operators/projectOperator.js");await s.load();return{count:i,extent:s.execute(this.fullExtent,r)}}return qe(this.url,e,t)}async queryRasters(e,t){({query:e,requestOptions:t}=await this._prepareForQuery(e,t));const i=await Pe(this.url,e,t),r=this.graphicOrigin;return i.features.forEach(e=>{e.layer=this,e.origin=r}),i}async queryObjectIds(e,t){return({query:e,requestOptions:t}=await this._prepareForQuery(e,t)),Ne(this.url,e,t)}async queryGPSInfo(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsQueryGPSInfo)throw new r("imagery-layer:query-gps-info","queryGPSInfo operation is not supported on the input image service");return e=e??{where:"1=1"},_e(He(this.parsedUrl),e,this._getRequestOptions(t))}async queryRasterCount(e,t){return({query:e,requestOptions:t}=await this._prepareForQuery(e,t)),Me(this.url,e,t)}async queryVisibleRasters(e,t){if(!e)throw new r("imagery-layer: query-visible-rasters","missing query parameter");await this.load();const{pixelSize:i,returnDomainValues:s,returnTopmostRaster:n,showNoDataRecords:a}=t||{pixelSize:null,returnDomainValues:!1,returnTopmostRaster:!1,showNoDataRecords:!1};let o=!1,l=null,u=null;const p=k.servicePixelValue.toLowerCase(),m=this._rasterFunctionNamesIndex;if(null!=e.outFields&&(o=e.outFields.some(e=>!e.toLowerCase().startsWith(p)),this.version>=10.4)){const t=e.outFields.filter(e=>e.toLowerCase().startsWith(p)&&e.length>p.length).map(e=>{const t=e.slice(p.length+1);return[this._updateRenderingRulesFunctionName(t,m),t]});l=t.map(e=>new $({functionName:e[0]})),u=t.map(e=>e[1]);const{rasterFunction:i}=this;0===l.length?i?.functionName?(l.push(i),u.push(i.functionName)):l=null:i?.functionName&&!l.some(e=>e.functionName===i.functionName)&&(l.push(i),u.push(i.functionName))}const c=null==e.outSpatialReference||e.outSpatialReference.equals(this.spatialReference),{multidimensionalSubset:h}=this;let f=e.timeExtent||this.timeExtent;if(h){const{isOutside:t,intersection:i}=g(h,{geometry:e.geometry,timeExtent:e.timeExtent,multidimensionalDefinition:this.exportImageServiceParameters.mosaicRule?.multidimensionalDefinition});if(t)throw new r("imagery-layer:query-visible-rasters","the request cannot be fulfilled when falling outside of the multidimensional subset");null!=i?.timeExtent&&(f=i.timeExtent)}const y=this._combineMosaicRuleWithTimeExtent(this.exportImageServiceParameters.mosaicRule,f);let I=e.geometry;this.version<10.91&&"extent"===I?.type&&(I=d.fromExtent(I));const w=this._getQueryParams({geometry:I,timeExtent:f,mosaicRule:y,rasterFunction:this.version<10.4?this.rasterFunction:null,rasterFunctions:l,pixelSize:i,returnCatalogItems:o,returnGeometry:c,raster:this.raster,maxItemCount:n?1:null});delete w.f;const v=new Ee(w);try{await this._generateRasterInfo(this.rasterFunction);const i=await Ie(this.url,v,{signal:t?.signal,query:{...this.customParameters}}),r=e.outFields,n=null!=i.value&&i.value.toLowerCase().includes("nodata"),l=o&&!c&&i?.catalogItems?.features.length&&(a||!n),p=this.multidimensionalInfo&&"raster-dataset"===this.sourceType?R({rasterInfo:this.rasterInfo,multidimensionalDefinition:y?.multidimensionalDefinition,timeExtent:f,multidimensionalSubset:this.multidimensionalSubset}):null;if(!l)return this._processVisibleRastersResponse(i,{returnDomainValues:s,templateRRFunctionNames:u,showNoDataRecords:a,templateFields:r,effectiveMultidimensionalDefinition:p});const m=this.objectIdField||"ObjectId",h=i.catalogItems?.features??[],d=h.map(e=>e.attributes?.[m]),g=new Ae({objectIds:d,returnGeometry:!0,outSpatialReference:e.outSpatialReference,outFields:[m]}),I=await this.queryRasters(g);return I?.features?.length&&I.features.forEach(t=>{h.forEach(i=>{i.attributes[m]===t.attributes[m]&&t.geometry&&(i.geometry=t.geometry.clone(),null!=e.outSpatialReference&&(i.geometry.spatialReference=e.outSpatialReference))})}),this._processVisibleRastersResponse(i,{returnDomainValues:s,templateRRFunctionNames:u,showNoDataRecords:a,templateFields:r,effectiveMultidimensionalDefinition:p})}catch{throw new r("imagery-layer:query-visible-rasters","encountered error when querying visible rasters")}}async fetchVariableStatisticsHistograms(e,t){const r=i(He(this.parsedUrl)+"/statistics",{query:this._getQueryParams({variable:e}),signal:t}).then(e=>e.data?.statistics),s=i(He(this.parsedUrl)+"/histograms",{query:this._getQueryParams({variable:e}),signal:t}).then(e=>e.data?.histograms),n=await Promise.all([r,s]);return n[0]&&n[0].forEach(e=>{e.avg=e.mean,e.stddev=e.standardDeviation}),{statistics:n[0]||null,histograms:n[1]||null}}getMultidimensionalSubsetVariables(e){const t=e??this.serviceRasterInfo.multidimensionalInfo;return I(this.multidimensionalSubset,t)}async _fetchService(e){await this._fetchServiceInfo(e),this.rasterInfo||(this.rasterInfo=this.serviceRasterInfo);const t=this.sourceJSON,i=null!=this.serviceRasterInfo?Promise.resolve(this.serviceRasterInfo):De(He(this.parsedUrl),t,{signal:e,query:this._getQueryParams()}).then(e=>(this._set("serviceRasterInfo",e),this._set("multidimensionalInfo",e.multidimensionalInfo),Te(e,t),e)),r=this._hasRasterFunction(this.rasterFunction)?this._generateRasterInfo(this.rasterFunction,{signal:e}):null,s=this._getRasterFunctionInfos();return Promise.all([i,r,s]).then(e=>{e[1]?this._set("rasterInfo",e[1]):this._set("rasterInfo",e[0]),e[2]&&this._set("rasterFunctionInfos",e[2]),this.internalRenderer&&!this._isSupportedRenderer(this.internalRenderer)&&(this._set("internalRenderer",null),n.getLogger(this).warn("ArcGISImageService","Switching to the default renderer. Renderer applied is not valid for this Imagery Layer")),this._set("internalRenderer",this._configRenderer(this.renderer)),this.addHandles([a(()=>this.rasterFunction,e=>{(this.renderer||this.symbolizer||this.popupEnabled&&this.popupTemplate)&&this._generateRasterInfo(e).then(e=>{e&&(this.rasterInfo=e)})})]);const{serviceRasterInfo:t}=this;null!=t.multidimensionalInfo&&this._updateMultidimensionalDefinition(t)})}_combineMosaicRuleWithTimeExtent(e,t){const i=this.timeInfo,{multidimensionalInfo:r}=this.serviceRasterInfo;if(null==e||null==r||null==t||null==i?.startField)return e;const{startField:s}=i,n=r.variables.some(e=>e.dimensions.some(e=>e.name===s))?s:"StdTime";if(e=e.clone(),"mosaic-dataset"===this.sourceType)return e.multidimensionalDefinition=e.multidimensionalDefinition?.filter(e=>e.dimensionName!==n),this._cleanupMultidimensionalDefinition(e);e.multidimensionalDefinition=e.multidimensionalDefinition||[];const a=e.multidimensionalDefinition.filter(e=>e.dimensionName===n),o=null!=t.start?t.start.getTime():null,l=null!=t.end?t.end.getTime():null,u=null==o||null==l||o===l,p=u?[o||l]:[[o,l]],m=this.version>=10.8;if(a.length)a.forEach(e=>{e.dimensionName===n&&(m?(e.dimensionName=null,e.isSlice=!1,e.values=[]):(e.isSlice=u,e.values=p))});else if(!m){const t=e.multidimensionalDefinition.filter(e=>null!=e.variableName&&null==e.dimensionName);t.length?t.forEach(e=>{e.dimensionName=n,e.isSlice=u,e.values=p}):e.multidimensionalDefinition.push(new _({variableName:"",dimensionName:n,isSlice:u,values:p}))}return this._cleanupMultidimensionalDefinition(e)}_cleanupMultidimensionalDefinition(e){return null==e?null:(e.multidimensionalDefinition&&(e.multidimensionalDefinition=e.multidimensionalDefinition.filter(e=>!(!e.variableName&&!e.dimensionName)),0===e.multidimensionalDefinition.length&&(e.multidimensionalDefinition=null)),"mosaic-dataset"!==this.sourceType&&null==e.multidimensionalDefinition?null:e)}async _prepareForQuery(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsQuery)throw new r("imagery-layer:query-rasters","query operation is not supported on the input image service");const i=null!=e?m(Ae,e):this.createQuery();return t=this._getRequestOptions(t),this.raster&&(t.query={...t.query,raster:this.raster}),{query:i,requestOptions:t}}_isSupportedRenderer(e){const{rasterInfo:t,rasterFunction:i}=this;return"unique-value"===e.type&&this._hasRasterFunction(i)&&1===t?.bandCount&&["u8","s8"].includes(t.pixelType)||null!=t&&null!=e&&Z(t).includes(e.type)}async _fetchCapabilities(e){return this.capabilities||await this._fetchServiceInfo(e),this.capabilities}async _fetchServiceInfo(e){let t=this.sourceJSON;if(!t){const{data:r,ssl:s}=await i(He(this.parsedUrl),{query:this._getQueryParams(),signal:e});t=r,this.sourceJSON=t,s&&(this.url=this.url.replace(/^http:/i,"https:"))}if(t.capabilities?.toLowerCase().split(",").map(e=>e.trim()).indexOf("tilesonly")>-1)throw new r("imagery-layer:fetch-service-info","use ImageryTileLayer to open tiles-only image services");this.read(t,{origin:"service",url:this.parsedUrl})}_isMosaicDataset(e){return e.serviceSourceType?"esriImageServiceSourceTypeMosaicDataset"===e.serviceSourceType:e.fields?.length>0}_isMosaicRuleSupported(e){if(!e)return!1;const t=this._isMosaicDataset(e),i=e.currentVersion>=10.71&&e.hasMultidimensions&&!(e.fields?.length>1);return t||i}_isVectorFieldResampleFunction(e){if(null==e)return!1;const{functionName:t,functionArguments:i}=e,r="resample"===t?.toLowerCase(),s=i?.ResampleType||i?.resampleType;return r&&(7===s||10===s)}_configRenderer(e){const{rasterInfo:t}=this;if(!this.isRenderedFormat&&!this.pixelFilter||this._isVectorDataSet()){const i=this.mosaicRule?.multidimensionalDefinition?.[0].variableName,r=ee({variableName:i,rasterFunctionName:this.rasterFunction?.functionName,presetRenderers:this.presetRenderers});if(!this.bandIds&&t.bandCount>=3){const e=r?.bandIds??Y(t);!e||3===t.bandCount&&0===e[0]&&1===e[1]&&2===e[2]||(this.bandIds=e)}e||(e=r?.renderer??K(t,{bandIds:this.bandIds,variableName:this.rasterFunction?null:i}));const s=te(e.toJSON());this.symbolizer?(this.symbolizer.rendererJSON=s,this.symbolizer.rasterInfo=t):this.symbolizer=new ie({rendererJSON:s,rasterInfo:t}),this.symbolizer.bind().success||(this.symbolizer=null)}return e}_clonePixelData(e){return null==e?e:{extent:e.extent&&e.extent.clone(),pixelBlock:null!=e.pixelBlock?e.pixelBlock.clone():null}}_getQueryParams(e){null!=e?.renderingRule&&"string"!=typeof e.renderingRule&&(e.renderingRule=this._getRenderingRuleString(e.renderingRule));const{raster:t,viewId:i}=this;return{raster:t,viewId:i,f:"json",...e,...this.customParameters}}_getRequestOptions(e){return{...e,query:{...e?.query,...this.customParameters}}}_decodePixelBlock(e,t,i){return this._rasterJobHandler?this._rasterJobHandler.decode({data:e,options:t}):v(e,t,i)}async _getRasterFunctionInfos(e){const t=this.sourceJSON.rasterFunctionInfos;if(this.loaded)return t;if(t&&this.version>=10.3){if(1===t.length&&"none"===t[0].name.toLowerCase())return t;const r=await i(He(this.parsedUrl)+"/rasterFunctionInfos",{query:this._getQueryParams(),signal:e});return r.data?.rasterFunctionInfos}return null}_canRequestImageElement(e){return!this.pixelFilter&&(!e||e.includes("png"))}async _requestArrayBuffer(e){const{imageProps:t,requestAsImageElement:s,returnImageBitmap:n,signal:a}=e;if(s&&this._canRequestImageElement(t.format)){const r=`${He(this.parsedUrl)}/exportImage`,{data:s}=await i(r,{responseType:n?"blob":"image",query:this._getQueryParams({f:"image",...this.refreshParameters,...e.imageServiceParameters}),signal:a});if(s instanceof Blob){const{bitmap:e}=await C(s,r,{signal:a});return{imageBitmap:e,params:t}}return{imageOrCanvasElement:s,params:t}}const o=this._initJobHandler(),l=i(He(this.parsedUrl)+"/exportImage",{responseType:"array-buffer",query:this._getQueryParams({f:"image",...e.imageServiceParameters}),signal:a}),u=(await Promise.all([l,o]))[0].data,p=t.format||"jpgpng";let m=p;if("bsq"!==m&&"bip"!==m&&(m=b(u)),!m)throw new r("imagery-layer:fetch-image","unsupported format signature "+String.fromCharCode.apply(null,new Uint8Array(u)));const c={signal:a},h=this._decodePixelBlock(u,{width:t.width,height:t.height,format:p,applyJpegMask:!0},c);return{pixelData:{pixelBlock:await h,extent:t.extent},params:t}}_generateRasterInfo(e,t){return this.generateRasterInfo(e,t).catch(()=>null)}_isValidCustomizedMosaicRule(e){return e&&JSON.stringify(e.toJSON())!==JSON.stringify(this.defaultMosaicRule?.toJSON())}_updateMultidimensionalDefinition(e){if(this._isValidCustomizedMosaicRule(this.mosaicRule))return;let t=w(e,{multidimensionalSubset:this.multidimensionalSubset});if(null!=t&&t.length>0){this.mosaicRule=this.mosaicRule||new q;const e=this.mosaicRule.multidimensionalDefinition;!this.sourceJSON.defaultVariableName&&this.rasterFunction&&"none"!==this.rasterFunction.functionName?.toLowerCase()&&t.forEach(e=>e.variableName=""),t=t.filter(({variableName:e,dimensionName:t})=>e&&"*"!==e||t),!e?.length&&t.length&&(this.mosaicRule.multidimensionalDefinition=t)}}_processVisibleRastersResponse(e,i){i=i||{};const r=e.value,{templateRRFunctionNames:s,showNoDataRecords:n,returnDomainValues:a,templateFields:o}=i,l=e.processedValues;let u=e.catalogItems?.features,p=e.properties?.Values?.map(e=>e.replaceAll(/ /gi,", "))||[];const m=this.objectIdField||"ObjectId",c="string"==typeof r&&r.toLowerCase().includes("nodata"),h=[];if(r&&!u&&(!c||n)){const e={};e[m]=0;p=[r],u=[new t({geometry:this.fullExtent,attributes:e})],this.multidimensionalInfo&&"raster-dataset"===this.sourceType&&G(this.rasterFields,e,i.effectiveMultidimensionalDefinition)}if(!u)return[];this._updateResponseFieldNames(u,o),c&&!n&&(u=[]);const{itemPixelValue:d,servicePixelValue:f}=k,y=this.rasterFields.some(e=>e.name===d),g=this.graphicOrigin;for(let t=0;t<u.length;t++){const e=u[t];if(null!=r){const i=p[t],a=this.rasterFunction&&l&&l.length>0&&s&&s.length>0&&s.includes(this.rasterFunction.functionName)?l[s.indexOf(this.rasterFunction.functionName)]:r;if("nodata"===i.toLowerCase()&&!n)continue;y&&(e.attributes[d]=i),e.attributes[f]=a,this._updateFeatureWithMagDirValues(e,i);const o=this.fields&&this.fields.length>0;let u=this.rasterFunction&&null!=this.serviceRasterInfo.attributeTable?o?i:r:a;this.rasterFunction||(u=o?i:r),this._updateFeatureWithRasterAttributeTableValues(e,u)}if(e.sourceLayer=e.layer=this,e.origin=g,a&&this._updateFeatureWithDomainValues(e),s&&l&&s.length===l.length)for(let t=0;t<s.length;t++){const i=`${k.servicePixelValue}.${s[t]}`;e.attributes[i]=l[t]}h.push(u[t])}return h}_processMultidimensionalIntersection(e,t,i){const{multidimensionalSubset:r}=this;if(!r)return{isOutSide:!1,timeExtent:t,mosaicRule:i=this._combineMosaicRuleWithTimeExtent(i,t)};if(r){const{isOutside:i,intersection:s}=g(r,{geometry:e,timeExtent:t});if(i)return{isOutSide:!0,timeExtent:null,mosaicRule:null};null!=s?.timeExtent&&(t=s.timeExtent)}if(i=this._combineMosaicRuleWithTimeExtent(i,t),i?.multidimensionalDefinition){const{isOutside:e}=g(r,{multidimensionalDefinition:i.multidimensionalDefinition});if(e)return{isOutSide:!0,timeExtent:null,mosaicRule:null}}return{isOutSide:!1,timeExtent:t,mosaicRule:i}}_updateFeatureWithRasterAttributeTableValues(e,t){const i=this.rasterInfo.attributeTable||this.serviceRasterInfo.attributeTable;if(null==i)return;const{features:r,fields:s}=i,n=s.map(e=>e.name).find(e=>"value"===e.toLowerCase());if(!n)return;const a=r.filter(e=>e.attributes[n]===(null!=t?parseInt(t,10):null));a&&a[0]&&s.forEach(t=>{const i=W+t.name;e.attributes[i]=a[0].attributes[t.name]})}_updateFeatureWithMagDirValues(e,t){if(!this._isVectorDataSet())return;const i=t.split(/,\s*/).map(e=>parseFloat(e)),r=i.map(e=>[e]),s=i.map(e=>({minValue:e,maxValue:e,noDataValue:null})),n=new P({height:1,width:1,pixelType:"f32",pixels:r,statistics:s});null!=this.pixelFilter&&this.pixelFilter({pixelBlock:n,extent:new h(0,0,0,0,this.spatialReference)});const a="esriImageServiceDataTypeVector-MagDir"===this.serviceDataType?[n.pixels[0][0],n.pixels[1][0]]:x([n.pixels[0][0],n.pixels[1][0]]);e.attributes[k.magnitude]=a[0],e.attributes[k.direction]=a[1]}_updateFeatureWithDomainValues(e){const t=this.fields&&this.fields.filter(e=>"coded-value"===e.domain?.type);null!=t&&t.forEach(t=>{const i=e.attributes[t.name];if(null!=i){const r=t.domain.codedValues.find(e=>e.code===i);r&&(e.attributes[t.name]=r.name)}})}_updateResponseFieldNames(e,t){if(!t||t.length<1)return;const i=this.fieldsIndex;null!=i&&e.forEach(e=>{if(e?.attributes)for(const r of t){const t=i.get(r)?.name;t&&t!==r&&(e.attributes[r]=e.attributes[t],delete e.attributes[t])}})}_getRenderingRuleString(e){if(e){let t=e.toJSON();return t=t.rasterFunctionDefinition??t,(t.thumbnail||t.thumbnailEx)&&(t.thumbnail=t.thumbnailEx=null),JSON.stringify(t)}return null}_hasRasterFunction(e){return null!=e?.functionName&&"none"!==e.functionName.toLowerCase()}_updateRenderingRulesFunctionName(e,t){if(!e||e.length<1)return;if("Raw"===e)return e.replace("Raw","None");const i=e.toLowerCase().replaceAll(/ /gi,"_");return t.has(i)?t.get(i):e}_isRFTJson(e){return e?.name&&e.arguments&&e.function&&e.hasOwnProperty("functionType")}_isVectorDataSet(){return"esriImageServiceDataTypeVector-UV"===this.serviceDataType||"esriImageServiceDataTypeVector-MagDir"===this.serviceDataType}_applyMosaicAndRenderingRules(e){const{raster:t,mosaicRule:i,rasterFunction:r}=this;r&&null==e.rasterFunction&&(e.rasterFunction=r),i&&null==e.mosaicRule&&(e.mosaicRule=i),t&&null==e.raster&&(e.raster=t)}async _updateCurrentRasterInfo(e){if(this.renderer||this.symbolizer){const t=await this._generateRasterInfo(this.rasterFunction,{signal:e});t&&(this.rasterInfo=t)}}_applyMosaicRule(e){const{raster:t,mosaicRule:i}=this;i&&null==e.mosaicRule&&(e.mosaicRule=i),t&&null==e.raster&&(e.raster=t)}_readCapabilities(e){const t=e.capabilities?e.capabilities.toLowerCase().split(",").map(e=>e.trim()):["image","catalog"],{currentVersion:i,maxRecordCount:r}=e,s=t.includes("image"),n="esriImageServiceDataTypeElevation"===e.serviceDataType,a=!(!e.spatialReference&&!e.extent?.spatialReference),o=t.includes("edit"),l=t.includes("mensuration")&&a,u=null==e.mensurationCapabilities?[]:e.mensurationCapabilities.toLowerCase().split(",").map(e=>e.trim()),p=l&&u.includes("basic"),m=this._isMosaicDataset(e)&&t.includes("catalog"),c=t.includes("download"),h=i>=10.7&&n||i>=11.4&&(n||l&&u.includes("3d")),d=m&&e.fields&&e.fields.length>0,f=d&&e.supportsAdvancedQueries?e.advancedQueryCapabilities:void 0;return{data:{supportsAttachment:!1},operations:{supportsComputeHistograms:s,supportsExportImage:s,supportsIdentify:s,supportsImageToMap:i>=11.2&&m,supportsImageToMapMultiray:i>=11.2&&m,supportsMapToImage:i>=11.2&&m,supportsFindImages:i>=11.2&&m,supportsGetImageUrl:i>=11.3&&c,supportsMeasure:l,supportsMeasureFromImage:i>=11.2,supportsDownload:c,supportsQuery:d,supportsGetSamples:i>=10.2&&s,supportsProject:i>=10.3&&s,supportsComputeStatisticsHistograms:i>=10.4&&s,supportsQueryBoundary:i>=10.6&&s,supportsCalculateVolume:h,supportsComputePixelLocation:i>=10.7&&m,supportsComputeAngles:i>=10.91,supportsQueryGPSInfo:i>=11.2&&m,supportsAdd:o,supportsDelete:o,supportsEditing:o,supportsUpdate:o,supportsCalculate:!1,supportsTruncate:!1,supportsValidateSql:!1,supportsChangeTracking:!1,supportsQueryAttachments:!1,supportsResizeAttachments:!1,supportsSync:!1,supportsExceedsLimitStatistics:!1,supportsQueryAnalytics:!1,supportsQueryBins:!1,supportsQueryPivot:!1,supportsQueryTopFeatures:!1,supportsAsyncConvert3D:!1},query:{maxRecordCount:r,maxRecordCountFactor:void 0,maxUniqueIDCount:void 0,relativeTimeBinWindow:void 0,supportsStatistics:!!f?.supportsStatistics,supportsOrderBy:!!f?.supportsOrderBy,supportsDistinct:!!f?.supportsDistinct,supportsPagination:!!f?.supportsPagination,supportsPaginationOnAggregatedQueries:!!f?.supportsPaginationOnAggregatedQueries,supportsStandardizedQueriesOnly:!!f?.useStandardizedQueries,supportsPercentileStatistics:!!f?.supportsPercentileStatistics,supportsCentroid:!!f?.supportsReturningGeometryCentroid,supportsCentroidOnDegeneratedQuantizedGeometry:!1,supportsCurrentUser:!1,supportsDegeneratedQuantizedGeometry:!1,supportsDistance:!!f?.supportsQueryWithDistance,supportsExtent:!!f?.supportsReturningQueryExtent,supportsGeometryProperties:!!f?.supportsReturningGeometryProperties,supportsHavingClause:!!f?.supportsHavingClause,supportsQuantization:!1,supportsQuantizationEditMode:!1,supportsQueryGeometry:!1,supportsResultType:!1,supportsReturnMesh:!1,supportsMaxRecordCountFactor:!1,supportsSqlExpression:f?.supportsSqlExpression??!!f,supportsTopFeaturesQuery:!1,supportsQueryByAnonymous:!1,supportsQueryByOthers:!1,supportsHistoricMoment:!1,supportsFormatPBF:!1,supportsFormatPBFWithCurves:!1,supportsDisjointSpatialRelationship:!1,supportsCacheHint:!1,supportsSpatialAggregationStatistics:!1,supportedSpatialAggregationStatistics:{envelope:!1,centroid:!1,convexHull:!1},supportsDefaultSpatialReference:!!f?.supportsDefaultSR,supportsFullTextSearch:!1,supportsCompactGeometry:!1,standardMaxRecordCount:void 0,standardMaxRecordCountNoGeometry:void 0,tileMaxRecordCount:void 0,supportsTrueCurve:!1},mensuration:{supportsDistanceAndAngle:p,supportsAreaAndPerimeter:p,supportsPointOrCentroid:p,supportsHeightFromBaseAndTop:l&&u.includes("base-top height"),supportsHeightFromBaseAndTopShadow:l&&u.includes("base-top shadow height"),supportsHeightFromTopAndTopShadow:l&&u.includes("top-top shadow height"),supports3D:l&&u.includes("3d")}}}};function He(e){return e?.path??""}return e([l({clonable:!1})],Le.prototype,"_functionRasterInfos",void 0),e([l({readOnly:!0})],Le.prototype,"_serviceSupportsMosaicRule",void 0),e([Qe("_serviceSupportsMosaicRule",["currentVersion","fields"])],Le.prototype,"readServiceSupportsMosaicRule",null),e([l({readOnly:!0})],Le.prototype,"_rasterFunctionNamesIndex",null),e([l()],Le.prototype,"adjustAspectRatio",void 0),e([l({type:[p],json:{write:!0}})],Le.prototype,"bandIds",void 0),e([Qe("bandIds")],Le.prototype,"readBandIds",null),e([l({readOnly:!0,json:{read:!1}})],Le.prototype,"capabilities",void 0),e([Qe("service","capabilities",["capabilities","currentVersion","serviceDataType"])],Le.prototype,"readCapabilities",null),e([l({type:Number})],Le.prototype,"compressionQuality",void 0),e([Ve("compressionQuality")],Le.prototype,"writeCompressionQuality",null),e([l({type:Number})],Le.prototype,"compressionTolerance",void 0),e([Ve("compressionTolerance")],Le.prototype,"writeCompressionTolerance",null),e([l({json:{read:{source:"copyrightText"}}})],Le.prototype,"copyright",void 0),e([l({readOnly:!0})],Le.prototype,"defaultMosaicRule",void 0),e([Qe("defaultMosaicRule",["defaultMosaicMethod"])],Le.prototype,"readDefaultMosaicRule",null),e([l({type:String,json:{name:"layerDefinition.definitionExpression",write:{enabled:!0,allowNull:!0}}})],Le.prototype,"definitionExpression",void 0),e([l({readOnly:!0,constructOnly:!0})],Le.prototype,"exportImageServiceParameters",void 0),e([l()],Le.prototype,"rasterInfo",void 0),e([l({readOnly:!0,type:[O]})],Le.prototype,"fields",void 0),e([l({readOnly:!0})],Le.prototype,"fieldsIndex",null),e([l({type:["png","png8","png24","png32","jpg","bmp","gif","jpgpng","lerc","tiff","bip","bsq"],json:{write:!0}})],Le.prototype,"format",null),e([Qe("service","format",["serviceDataType"])],Le.prototype,"readFormat",null),e([l({type:h})],Le.prototype,"fullExtent",void 0),e([l({readOnly:!0})],Le.prototype,"hasMultidimensions",void 0),e([l({json:{read:{source:"maxImageHeight"}}})],Le.prototype,"imageMaxHeight",void 0),e([l({json:{read:{source:"maxImageWidth"}}})],Le.prototype,"imageMaxWidth",void 0),e([l({type:String,json:{type:j.jsonValues,read:j.read,write:j.write}})],Le.prototype,"interpolation",void 0),e([l()],Le.prototype,"minScale",void 0),e([Qe("service","minScale")],Le.prototype,"readMinScale",null),e([l()],Le.prototype,"maxScale",void 0),e([Qe("service","maxScale")],Le.prototype,"readMaxScale",null),e([l({type:q})],Le.prototype,"mosaicRule",null),e([Qe("mosaicRule",["mosaicRule","defaultMosaicMethod"])],Le.prototype,"readMosaicRule",null),e([Ve("mosaicRule")],Le.prototype,"writeMosaicRule",null),e([l()],Le.prototype,"multidimensionalInfo",void 0),e([l({type:N,json:{write:!0}})],Le.prototype,"multidimensionalSubset",void 0),e([l({json:{type:[Number,[Number]],write:!0}})],Le.prototype,"noData",void 0),e([l({type:String,json:{type:E.jsonValues,read:E.read,write:E.write}})],Le.prototype,"noDataInterpretation",void 0),e([l({type:String,readOnly:!0,json:{read:{source:["fields"]}}})],Le.prototype,"objectIdField",void 0),e([Qe("objectIdField")],Le.prototype,"readObjectIdField",null),e([l({readOnly:!0})],Le.prototype,"geometryType",void 0),e([l({})],Le.prototype,"typeIdField",void 0),e([l({})],Le.prototype,"types",void 0),e([l({readOnly:!0})],Le.prototype,"parsedUrl",null),e([l({type:Function})],Le.prototype,"pixelFilter",void 0),e([l()],Le.prototype,"raster",void 0),e([l({readOnly:!0})],Le.prototype,"sourceType",void 0),e([Qe("sourceType",["serviceSourceType","fields"])],Le.prototype,"readSourceType",null),e([l()],Le.prototype,"viewId",void 0),e([l({types:re})],Le.prototype,"renderer",null),e([l({types:re,json:{name:"layerDefinition.drawingInfo.renderer",origins:{"web-scene":{types:se,name:"layerDefinition.drawingInfo.renderer",write:{overridePolicy:e=>({enabled:e&&"vector-field"!==e.type})}}}}})],Le.prototype,"internalRenderer",null),e([Qe("internalRenderer")],Le.prototype,"readRenderer",null),e([Ve("internalRenderer")],Le.prototype,"writeRenderer",null),e([l({clonable:!1})],Le.prototype,"symbolizer",void 0),e([l(S)],Le.prototype,"opacity",void 0),e([l({readOnly:!0})],Le.prototype,"rasterFields",null),e([l({constructOnly:!0})],Le.prototype,"rasterFunctionInfos",void 0),e([l({type:$,json:{name:"renderingRule"}})],Le.prototype,"rasterFunction",null),e([Qe("rasterFunction",["renderingRule","rasterFunctionInfos"])],Le.prototype,"readRasterFunction",null),e([l({readOnly:!0})],Le.prototype,"serviceDataType",void 0),e([l({readOnly:!0,type:f})],Le.prototype,"spatialReference",void 0),e([Qe("spatialReference",["spatialReference","extent"])],Le.prototype,"readSpatialReference",null),e([l({type:A.apiValues,json:{read:A.read,type:A.jsonValues}})],Le.prototype,"pixelType",void 0),e([Ve("pixelType")],Le.prototype,"writePixelType",null),e([l({constructOnly:!0,type:X})],Le.prototype,"serviceRasterInfo",void 0),e([l()],Le.prototype,"sourceJSON",void 0),e([l(F)],Le.prototype,"url",void 0),e([l({readOnly:!0})],Le.prototype,"version",void 0),e([Qe("version",["currentVersion","fields","timeInfo"])],Le.prototype,"readVersion",null),Le=e([u("esri.layers.mixins.ArcGISImageService")],Le),Le};export{Be as ArcGISImageService};
2
+ import{__decorate as e}from"tslib";import t from"../../Graphic.js";import i from"../../request.js";import r from"../../core/Error.js";import{clone as s}from"../../core/lang.js";import n from"../../core/Logger.js";import{watch as a}from"../../core/reactiveUtils.js";import{urlToObject as o}from"../../core/urlUtils.js";import{property as l,subclass as u}from"../../core/accessorSupport/decorators.js";import{Integer as p,ensureClass as m}from"../../core/accessorSupport/ensureType.js";import{runUntracked as c}from"../../core/accessorSupport/tracking.js";import d from"../../geometry/Extent.js";import h from"../../geometry/Polygon.js";import f from"../../geometry/SpatialReference.js";import{srToRESTValue as g}from"../../geometry/support/spatialReferenceUtils.js";import{intersectMultimensionalSubset as y,getEffectiveMultidimensionalDefinition as R,getSubsetVariablesFromMdInfo as I,getDefaultMultidimensionalDefinition as w}from"../raster/datasets/multidimensionalUtils.js";import{decode as v,getFormat as b}from"../raster/formats/RasterCodec.js";import{uvComponentToVector as x}from"../raster/functions/vectorFieldUtils.js";import{opacity as S,url as F}from"../support/commonProperties.js";import _ from"../support/DimensionalDefinition.js";import{ExportImageServiceParameters as D}from"../support/ExportImageServiceParameters.js";import O from"../support/Field.js";import T from"../support/FieldsIndex.js";import{createBitmap as C}from"../support/imageBitmapUtils.js";import{isSupportedRendererType as M}from"../support/imageryRendererUtils.js";import q from"../support/MosaicRule.js";import N from"../support/MultidimensionalSubset.js";import P from"../support/PixelBlock.js";import{interpolationKebab as j,noDataInterpretationKebab as E,pixelTypeKebabDict as A}from"../support/rasterEnums.js";import{getServicePixelValueField as Q,getItemPixelValueField as V,getRawServicePixelValueField as J,getProcessedServicePixelValueField as U,getMagnitudeField as B,getDirectionField as z,getMultidimensionalFields as L,getRasterAttributeTableFields as H,addMultidimensionalFieldValues as G,commonRasterFieldNames as k,rasterFieldPrefix as W}from"../support/rasterFieldUtils.js";import $ from"../support/RasterFunction.js";import X from"../support/RasterInfo.js";import{createDefaultRenderer as K,getDefaultBandCombination as Y,getSupportedRendererTypes as Z,matchPresetRenderer as ee,normalizeRendererJSON as te}from"../../renderers/support/rasterRendererHelper.js";import ie from"../../renderers/support/RasterSymbolizer.js";import{rasterRendererTypes as re,websceneRasterRendererTypes as se,read as ne}from"../../renderers/support/rasterTypeUtils.js";import{calculateVolume as ae,computeAngles as oe,computePixelSpaceLocations as le,computeHistograms as ue,computeStatisticsHistograms as pe,measureHeight as me,measureAreaAndPerimeter as ce,measureDistanceAndAngle as de,measurePointOrCentroid as he,measureLengthFromImage as fe,measureAreaFromImage as ge,getImageSpatialReferenceQueryParameter as ye,getSamples as Re,identify as Ie,imageToMap as we,imageToMapMultiray as ve,mapToImage as be,findImages as xe,getImageUrl as Se,queryBoundary as Fe,queryGPSInfo as _e}from"../../rest/imageService.js";import{fetchServiceRasterInfo as De,generateRasterInfo as Oe,patchServiceInfo as Te}from"../../rest/imageService/fetchRasterInfo.js";import{getCatalogItemRasterInfo as Ce}from"../../rest/imageService/getCatalogItemRasterInfo.js";import{executeForCount as Me}from"../../rest/query/executeForCount.js";import{executeForExtent as qe}from"../../rest/query/executeForExtent.js";import{executeForIds as Ne}from"../../rest/query/executeForIds.js";import{executeQueryJSON as Pe}from"../../rest/query/executeQueryJSON.js";import je from"../../rest/support/FeatureSet.js";import Ee from"../../rest/support/ImageIdentifyParameters.js";import Ae from"../../rest/support/Query.js";import{reader as Qe}from"../../core/accessorSupport/decorators/reader.js";import{writer as Ve}from"../../core/accessorSupport/decorators/writer.js";const Je=new Set(["png","png8","png24","png32","jpg","bmp","gif","jpgpng","lerc","tiff"]);function Ue(e){const t=JSON.stringify(e),i=t.includes('"rasterFunctionDefinition":{'),r=i?t.match(/"type":"(.*?FunctionArguments")/gi):t.match(/"rasterFunction":"(.*?")/gi),s=r?.map(e=>i?e.slice(8,-18):e.slice(18,-1));return s?s.join("/"):null}const Be=Be=>{const ze=Be;let Le=class extends ze{constructor(){super(...arguments),this._functionRasterInfos={},this._serviceSupportsMosaicRule=null,this.adjustAspectRatio=null,this.bandIds=void 0,this.capabilities=null,this.compressionQuality=void 0,this.compressionTolerance=.01,this.copyright=null,this.defaultMosaicRule=null,this.definitionExpression=null,this.exportImageServiceParameters=null,this.rasterInfo=null,this.fields=null,this.fullExtent=null,this.hasMultidimensions=!1,this.imageMaxHeight=4100,this.imageMaxWidth=4100,this.interpolation=void 0,this.minScale=0,this.maxScale=0,this.multidimensionalInfo=null,this.multidimensionalSubset=null,this.noData=null,this.noDataInterpretation=void 0,this.objectIdField=null,this.geometryType="polygon",this.typeIdField=null,this.types=[],this.pixelFilter=null,this.raster=void 0,this.sourceType=null,this.viewId=void 0,this.symbolizer=null,this.rasterFunctionInfos=null,this.serviceDataType=null,this.spatialReference=null,this.pixelType=null,this.serviceRasterInfo=null,this.sourceJSON=null,this.url=null,this.version=void 0}initialize(){this._set("exportImageServiceParameters",new D({layer:this}))}readServiceSupportsMosaicRule(e,t){return this._isMosaicRuleSupported(t)}get _rasterFunctionNamesIndex(){const e=new Map;return!this.rasterFunctionInfos||null!=this.rasterFunctionInfos&&this.rasterFunctionInfos.length<1||null!=this.rasterFunctionInfos&&this.rasterFunctionInfos.forEach(t=>{e.set(t.name.toLowerCase().replaceAll(/ /gi,"_"),t.name)}),e}readBandIds(e,t){if(Array.isArray(e)&&e.length>0&&e.every(e=>"number"==typeof e))return e}readCapabilities(e,t){return this._readCapabilities(t)}writeCompressionQuality(e,t,i){null!=e&&"lerc"!==this.format&&(t[i]=e)}writeCompressionTolerance(e,t,i){"lerc"===this.format&&null!=e&&(t[i]=e)}readDefaultMosaicRule(e,t){return this._serviceSupportsMosaicRule?c(()=>q.fromJSON(t)):null}get fieldsIndex(){return this.fields?new T(this.fields):null}set format(e){e&&Je.has(e.toLowerCase())&&this._set("format",e.toLowerCase())}readFormat(e,t){return"esriImageServiceDataTypeVector-UV"===t.serviceDataType||"esriImageServiceDataTypeVector-MagDir"===t.serviceDataType||null!=this.pixelFilter?"lerc":"jpgpng"}get isRenderedFormat(){return!this.format||this.format.includes("jpg")||this.format.includes("png")}readMinScale(e,t){return null!=t.minLOD&&null!=t.maxLOD?e:0}readMaxScale(e,t){return null!=t.minLOD&&null!=t.maxLOD?e:0}set mosaicRule(e){let t=e;t?.mosaicMethod&&(t=q.fromJSON({...t.toJSON(),mosaicMethod:t.mosaicMethod,mosaicOperation:t.mosaicOperation})),this._set("mosaicRule",t)}readMosaicRule(e,t){const i=e||t.mosaicRule;return i?q.fromJSON(i):this._isMosaicRuleSupported(t)?q.fromJSON(t):null}writeMosaicRule(e,t,i){const{mosaicRule:r}=this;this._isValidCustomizedMosaicRule(r)&&(t[i]=r.toJSON())}readObjectIdField(e,t){if(!e){const i=t.fields.find(e=>"esriFieldTypeOID"===e.type||"oid"===e.type);e=i?.name}return e}get parsedUrl(){return o(this.url)}readSourceType(e,t){return this._isMosaicDataset(t)?"mosaic-dataset":"raster-dataset"}get renderer(){const{activePresetRendererName:e,presetRenderers:t}=this;if(e){const i=t?.find(({name:t})=>t===e);return i?.renderer.clone()}return this.internalRenderer}set renderer(e){this.activePresetRendererName=null,this.internalRenderer=e}set internalRenderer(e){this.loaded&&(e=this._configRenderer(e)),this._set("internalRenderer",e)}readRenderer(e,t,i){const r=t?.layerDefinition?.drawingInfo?.renderer,s=ne(r,i);return null==s?null:("vector-field"===s.type&&t.symbolTileSize&&!r.symbolTileSize&&(s.symbolTileSize=t.symbolTileSize),M(s)||n.getLogger(this).warn("ArcGISImageService","Imagery layer doesn't support given renderer type."),s)}writeRenderer(e,t,i){t.layerDefinition=t.layerDefinition||{},t.layerDefinition.drawingInfo=t.layerDefinition.drawingInfo||{},t.layerDefinition.drawingInfo.renderer=e.toJSON()}get rasterFields(){const e=this.fields?.map(e=>e.clone())??[];e.push(Q()),"mosaic-dataset"===this.sourceType&&this.fields?.length&&e.push(V()),this.version>=10.4&&null!=this.rasterFunctionInfos&&this.rasterFunctionInfos.some(({name:e})=>"none"===e.toLowerCase())&&e.push(J()),null!=this.rasterFunctionInfos&&this.rasterFunctionInfos.filter(({name:e})=>"none"!==e.toLowerCase()).forEach(({name:t})=>e.push(U(t)));const{rasterInfo:t}=this;if(this._isVectorDataSet()){const i=t?.multidimensionalInfo?.variables[0].unit?.trim(),r=B(i),s=z();e.push(r,s)}if(t?.multidimensionalInfo&&"raster-dataset"===this.sourceType){const i=L(t.multidimensionalInfo);e.push(...i)}const i=t?.attributeTable;if(null!=i){const t=H(i);e.push(...t)}return e}set rasterFunction(e){let t=e;t?.rasterFunction&&(t=$.fromJSON({...t.toJSON(),rasterFunction:t.rasterFunction,rasterFunctionArguments:t.rasterFunctionArguments})),this._set("rasterFunction",t)}readRasterFunction(e,t){const i=t.rasterFunctionInfos;return t.renderingRule||i?.length&&"None"!==i[0].name?this._isRFTJson(t.renderingRule)?$.fromJSON({rasterFunctionDefinition:t.renderingRule}):$.fromJSON(t.renderingRule||{rasterFunctionInfos:t.rasterFunctionInfos}):null}readSpatialReference(e,t){const i=e||t.extent.spatialReference;return i?f.fromJSON(i):null}writePixelType(e,t,i){null!=this.serviceRasterInfo&&this.pixelType===this.serviceRasterInfo.pixelType||(t[i]=A.toJSON(e))}readVersion(e,t){let i=t.currentVersion;return i||(i=t.hasOwnProperty("fields")||t.hasOwnProperty("timeInfo")?10:9.3),i}applyFilter(e){let t=e;return this.pixelFilter&&(t=this._clonePixelData(e),this.pixelFilter(t)),t}async applyRenderer(e,t){let i=e,{renderer:r,symbolizer:s,pixelFilter:n}=this;const{isRawData:a}=e;if(a&&"lerc"!==this.format&&(r??=K(this.rasterInfo,{bandIds:this.bandIds,variableName:this.rasterFunction?null:this.mosaicRule?.multidimensionalDefinition?.[0].variableName}),s||(this.symbolizer=new ie({rendererJSON:r.toJSON(),rasterInfo:this.rasterInfo}),s=this.symbolizer)),(a||!this.isRenderedFormat)&&r&&s&&!n){await this._updateSymbolizer(s,r);const n=this.bandIds?.length?this.bandIds:Y(this.rasterInfo);i=await this._symbolize({pixelData:e,bandIds:n,symbolizer:s},t)}return i}destroy(){this._shutdownJobHandler()}async calculateVolume(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsCalculateVolume)throw new r("imagery-layer:compute-pixel-space-locations","this operation is not supported on the input image service");return e=s(e),this.mosaicRule&&null==e.mosaicRule&&(e.mosaicRule=this.mosaicRule),ae(this.url,e,this._getRequestOptions(t))}async computeAngles(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsComputeAngles)throw new r("imagery-layer:compute-angles","this operation is not supported on the input image service");return oe(this.url,e,this._getRequestOptions(t))}async computePixelSpaceLocations(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsComputePixelLocation)throw new r("imagery-layer:compute-pixel-space-locations","this operation is not supported on the input image service");return le(this.url,e,this._getRequestOptions(t))}async computeHistograms(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsComputeHistograms)throw new r("imagery-layer:compute-histograms","this operation is not supported on the input image service");return e=s(e),this._applyMosaicAndRenderingRules(e),ue(this.url,e,this._getRequestOptions(t))}async computeStatisticsHistograms(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsComputeStatisticsHistograms)throw new r("imagery-layer:compute-statistics-histograms","this operation is not supported on the input image service");return e=s(e),this._applyMosaicAndRenderingRules(e),pe(this.url,e,this._getRequestOptions(t))}async measureHeight(e,t){const i=await this._fetchCapabilities(t?.signal);if(!("base-and-top"===e.operationType?i.mensuration.supportsHeightFromBaseAndTop:"base-and-top-shadow"===e.operationType?i.mensuration.supportsHeightFromBaseAndTopShadow:i.mensuration.supportsHeightFromTopAndTopShadow))throw new r("imagery-layer:measure-height","this operation is not supported on the input image service");return e=s(e),this._applyMosaicRule(e),me(this.url,e,this._getRequestOptions(t))}async measureAreaAndPerimeter(e,t){const i=await this._fetchCapabilities(t?.signal);if(!(i.mensuration.supportsAreaAndPerimeter&&(!e.is3D||i.mensuration.supports3D)))throw new r("imagery-layer:measure-area-and-perimeter","this operation is not supported on the input image service");return e=s(e),this._applyMosaicRule(e),ce(this.url,e,this._getRequestOptions(t))}async measureDistanceAndAngle(e,t){const i=await this._fetchCapabilities(t?.signal);if(!(i.mensuration.supportsDistanceAndAngle&&(!e.is3D||i.mensuration.supports3D)))throw new r("imagery-layer:measure-distance-and-angle","this operation is not supported on the input image service");return e=s(e),this._applyMosaicRule(e),de(this.url,e,this._getRequestOptions(t))}async measurePointOrCentroid(e,t){const i=await this._fetchCapabilities(t?.signal);if(!(i.mensuration.supportsPointOrCentroid&&(!e.is3D||i.mensuration.supports3D)))throw new r("imagery-layer:measure-point-or-centroid","this operation is not supported on the input image service");return e=s(e),this._applyMosaicRule(e),he(this.url,e,this._getRequestOptions(t))}async measureLengthFromImage(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsMeasureFromImage)throw new r("imagery-layer:measure-length-from-image","this operation is not supported on the input image service");if("polyline"!==e.geometry.type)throw new r("imagery-layer:measure-length-from-image","this input geometry must be a polyline");return fe(this.url,e,this._getRequestOptions(t))}async measureAreaFromImage(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsMeasureFromImage)throw new r("imagery-layer:measure-area-from-image","this operation is not supported on the input image service");if("polygon"!==e.geometry.type)throw new r("imagery-layer:measure-area-from-image","this input geometry must be a polygon");return ge(this.url,e,this._getRequestOptions(t))}getField(e){const{fieldsIndex:t}=this;return null!=t?t.get(e):void 0}getFieldDomain(e,t){const i=this.getField(e);return i?i.domain:null}async internalFetchImage(e,t,i,r={}){await this._updateCurrentRasterInfo();const{exportImageServiceParameters:s}=this;let n=!1;r.requestRawData&&(await this._initJobHandler(),s.requestRawData||"lerc"===this.format||(n=!0,s.requestRawData=!0));const a=this.getExportImageServiceParameters(e,t,i,r.timeExtent);if(n&&(s.requestRawData=!1,a&&!this.bandIds?.length&&(null==a.bandIds||""===a.bandIds))){const e=Y(this.rasterInfo);a.bandIds=e?.join(",")}if(null==a){if(r.requestAsImageElement&&this._canRequestImageElement(this.format)){const e=document.createElement("canvas");if(e.width=t,e.height=i,r.returnImageBitmap){const{bitmap:t}=await C(e,`${He(this.parsedUrl)}/exportImage`,r);return{imageBitmap:t}}return{imageOrCanvasElement:e}}const{bandIds:s,rasterInfo:n}=this,a=(s?.length||n.bandCount)??0,o=t*i,l=n.pixelType,u=[];for(let e=0;e<a;e++)u.push(P.createEmptyBand(l,o));return{pixelData:{pixelBlock:new P({width:t,height:i,pixels:u,mask:new Uint8Array(o),pixelType:l}),extent:e}}}const o=!!r.requestAsImageElement&&!this.pixelFilter,l=o&&!!r.returnImageBitmap,u={imageServiceParameters:a,imageProps:{extent:e,width:t,height:i,format:this.format},requestAsImageElement:o,returnImageBitmap:l,signal:r.signal};return this._requestArrayBuffer(u)}async fetchPixels(e,t,i,r={}){await this._initJobHandler(),r.applyRendering&&this._updateCurrentRasterInfo();const s=r.applyRendering?void 0:new D({layer:this,requestRawData:!0,interpolation:r.interpolation??"nearest",bandIds:r.bandIds??[]}),n=this.getExportImageServiceParameters(e,t,i,r.timeExtent,s);if(null==n)return{extent:e,pixelBlock:null};delete n.pixelType,r.bandIds||delete n.bandIds,delete n.compressionQuality;const a={imageServiceParameters:n,imageProps:{extent:e,width:t,height:i,format:this.format},requestAsImageElement:!1,returnImageBitmap:!1,signal:r.signal},{pixelData:o}=await this._requestArrayBuffer(a);return o??{extent:e,pixelBlock:null}}fetchKeyProperties(e){return i(He(this.parsedUrl)+"/keyProperties",{query:this._getQueryParams({renderingRule:this.version>=10.3?e?.rasterFunction:null})}).then(e=>e.data)}fetchRasterAttributeTable(e){return this.version<10.1?Promise.reject(new r("#fetchRasterAttributeTable()","Failed to get rasterAttributeTable")):i(He(this.parsedUrl)+"/rasterAttributeTable",{query:this._getQueryParams({renderingRule:this.version>=10.3?e?.rasterFunction:null})}).then(e=>je.fromJSON(e.data))}getCatalogItemRasterInfo(e,t){const i={...t,query:this._getQueryParams()};return Ce(He(this.parsedUrl),e,i)}async getCatalogItemICSInfo(e,t){const{data:r}=await i(He(this.parsedUrl)+"/"+e+"/info/ics",{query:this._getQueryParams(),...t}),s=r?.ics;if(!s)return;let n=null;try{n=(await i(He(this.parsedUrl)+"/"+e+"/info",{query:this._getQueryParams(),...t})).data.extent}catch{}if(!n?.spatialReference)return{ics:s,icsToPixelTransform:null,icsExtent:null,northDirection:null};const a=this.version>=10.7?i(He(this.parsedUrl)+"/"+e+"/info/icstopixel",{query:this._getQueryParams(),...t}).then(e=>e.data).catch(()=>({})):{},o=n.spatialReference,l={geometries:JSON.stringify({geometryType:"esriGeometryEnvelope",geometries:[n]}),inSR:g(o),outSR:"0:"+e},u=i(He(this.parsedUrl)+"/project",{query:this._getQueryParams(l),...t}).then(e=>e.data).catch(()=>({})),p=5,m=(n.xmin+n.xmax)/2,c=(n.ymax-n.ymin)/(p+1),h=n.ymin+c,y=[];for(let i=0;i<p;i++)y.push({x:m,y:h+c*i});const R={geometries:JSON.stringify({geometryType:"esriGeometryPoint",geometries:y}),inSR:g(o),outSR:"0:"+e},I=i(He(this.parsedUrl)+"/project",{query:this._getQueryParams(R),...t}).then(e=>e.data).catch(()=>({})),w=await Promise.all([a,u,I]);let v=w[0].ipxf;if(null==v){const e=s.geodataXform?.xf_0;"topup"===e?.name?.toLowerCase()&&6===e?.coefficients?.length&&(v={affine:{name:"ics [sensor: Frame] to pixel (column, row) transformation",coefficients:e.coefficients,cellsizeRatio:0,type:"GeometricXform"}})}const b=d.fromJSON(w[1]?.geometries?.[0]);b&&(b.spatialReference=new f({wkid:0,imageCoordinateSystem:s}));const x=w[2].geometries?w[2].geometries.filter(e=>null!=e?.x&&null!=e.y&&"NaN"!==e.x&&"NaN"!==e.y):[],S=x.length;if(S<3)return{ics:s,icsToPixelTransform:v,icsExtent:b,northDirection:null};let F=0,_=0,D=0,O=0;for(let i=0;i<S;i++)F+=x[i].x,_+=x[i].y,D+=x[i].x*x[i].x,O+=x[i].x*x[i].y;const T=(S*O-F*_)/(S*D-F*F);let C=0;const M=x[p-1].x>x[0].x,q=x[p-1].y>x[0].y;return T===1/0?C=q?90:270:0===T?C=M?0:180:T>0?C=M?180*Math.atan(T)/Math.PI:180*Math.atan(T)/Math.PI+180:T<0&&(C=q?180+180*Math.atan(T)/Math.PI:360+180*Math.atan(T)/Math.PI),{ics:s,icsToPixelTransform:v,icsExtent:b,northDirection:C}}async generateRasterInfo(e,t){const i=m($,e),s={...t,query:this._getQueryParams()};if(!i||"none"===i.functionName?.toLowerCase()||this._isVectorFieldResampleFunction(i))return this.serviceRasterInfo??De(He(this.parsedUrl),this.sourceJSON,s);const n=Ue(i);if(!n)throw new r("imagery-layer:generate-raster-info","the rendering rule is not supported");if(this._functionRasterInfos[n])return this._functionRasterInfos[n];const a=Oe(He(this.parsedUrl),i,s);this._functionRasterInfos[n]=a;try{return await a}catch(o){throw this._functionRasterInfos[n]=null,o}}getExportImageServiceParameters(e,t,i,r,s){e=e.clone().shiftCentralMeridian();const n=ye(e.spatialReference,He(this.parsedUrl));s??=this.exportImageServiceParameters;const a=s.toJSON(),{bandIds:o,noData:l}=a;let{renderingRule:u}=a;const p=this.rasterFunction?.rasterFunctionDefinition,m=this.renderer?.type,c=!m||"raster-stretch"===m||"raster-colormap"===m||"unique-value"===m||"class-breaks"===m||"raster-shaded-relief"===m;if(o?.length&&this._hasRasterFunction(this.rasterFunction)&&!p&&c){const e={rasterFunction:"ExtractBand",rasterFunctionArguments:{BandIds:o}};if("Stretch"===u.rasterFunction)e.rasterFunctionArguments.Raster=u.rasterFunctionArguments.Raster,u.rasterFunctionArguments.Raster=e;else if("Colormap"===u.rasterFunction){const t=u.rasterFunctionArguments.Raster;"Stretch"===t?.rasterFunction?(e.rasterFunctionArguments.Raster=t.rasterFunctionArguments.Raster,t.rasterFunctionArguments.Raster=e):(e.rasterFunctionArguments.Raster=t,u.rasterFunctionArguments.Raster=e)}else e.rasterFunctionArguments.Raster=u,u=e;a.bandIds=void 0}else a.bandIds=o?.join(",");Array.isArray(l)&&l.length>0&&(a.noData=l.join(","));const d=this._processMultidimensionalIntersection(null,r,s.mosaicRule);if(d.isOutSide)return null;a.mosaicRule=null!=d.mosaicRule?JSON.stringify(d.mosaicRule):null,r=d.timeExtent,a.renderingRule=this._getRenderingRuleString($.fromJSON(u));const h={};if(null!=r){const{start:e,end:t}=r.toJSON();e&&t&&e===t?h.time=""+e:null==e&&null==t||(h.time=`${e??"null"},${t??"null"}`)}return{bbox:e.xmin+","+e.ymin+","+e.xmax+","+e.ymax,bboxSR:n,imageSR:n,size:t+","+i,...a,...h}}async getSamples(e,t){const i=await this._fetchCapabilities(t?.signal);if(!i?.operations.supportsGetSamples)throw new r("imagery-layer:get-samples","getSamples operation is not supported on the input image service");e=s(e);const{raster:n}=this;return n&&null==e.raster&&(e.raster=n),Re(this.url,e,this._getRequestOptions(t))}async identify(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsIdentify)throw new r("imagery-layer:identify","identify operation is not supported on the input image service");e=s(e),this.version<10.91&&"extent"===e.geometry?.type&&(e.geometry=h.fromExtent(e.geometry));const i=this._processMultidimensionalIntersection(e.geometry,e.timeExtent,e.mosaicRule||this.mosaicRule);if(i.isOutSide)throw new r("imagery-layer:identify","the request cannot be fulfilled when falling outside of the multidimensional subset");e.timeExtent=i.timeExtent,e.mosaicRule=i.mosaicRule;const{raster:n,rasterFunction:a}=this;return a&&null==e.rasterFunction&&(e.rasterFunction=a),n&&null==e.raster&&(e.raster=n),Ie(this.url,e,this._getRequestOptions(t))}async imageToMap(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsImageToMap)throw new r("imagery-layer:image-to-map","imageToMap operation is not supported on the input image service");return we(He(this.parsedUrl),e,this._getRequestOptions(t))}async imageToMapMultiray(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsImageToMapMultiray)throw new r("imagery-layer:image-to-map-multiray","imageToMapMultiray operation is not supported on the input image service");return ve(He(this.parsedUrl),e,this._getRequestOptions(t))}async mapToImage(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsMapToImage)throw new r("imagery-layer:map-to-image","mapToImage operation is not supported on the input image service");return be(He(this.parsedUrl),e,this._getRequestOptions(t))}async findImages(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsFindImages)throw new r("imagery-layer:find-images","findImages operation is not supported on the input image service");return xe(He(this.parsedUrl),e,this._getRequestOptions(t))}async getImageUrl(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsGetImageUrl)throw new r("imagery-layer:get-image-url","getImageUrl operation is not supported on the input image service");return Se(He(this.parsedUrl),e,this._getRequestOptions(t))}createQuery(){return new Ae({outFields:["*"],returnGeometry:!0,where:this.definitionExpression||"1=1"})}async queryBoundary(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsQueryBoundary)throw new r("imagery-layer:query-boundary","queryBoundary operation is not supported on the input image service");return e=e??{outSpatialReference:this.spatialReference},Fe(He(this.parsedUrl),e,this._getRequestOptions(t))}async queryExtent(e,t){({query:e,requestOptions:t}=await this._prepareForQuery(e,t));const{where:i,objectIds:r,geometry:s,timeExtent:n,start:a,num:o,pixelSize:l}=e,u=null!=i&&"1=1"!==i,p=null!=r&&r.length>0,m=null!=s&&("extent"!==s.type||!s.equals(this.fullExtent)),c=null!=l,d=null!=a||null!=o,{timeInfo:h}=this,f=null!=n&&null!=h&&!n.equals(h.fullTimeExtent);if(!(u||p||m||c||f||d)){const i=await Me(this.url,e,t),{outSpatialReference:r}=e;if(!r||r.equals(this.spatialReference))return{count:i,extent:this.fullExtent.clone()};const s=await import("../../geometry/operators/projectOperator.js");await s.load();return{count:i,extent:s.execute(this.fullExtent,r)}}return qe(this.url,e,t)}async queryRasters(e,t){({query:e,requestOptions:t}=await this._prepareForQuery(e,t));const i=await Pe(this.url,e,t),r=this.graphicOrigin;return i.features.forEach(e=>{e.layer=this,e.origin=r}),i}async queryObjectIds(e,t){return({query:e,requestOptions:t}=await this._prepareForQuery(e,t)),Ne(this.url,e,t)}async queryGPSInfo(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsQueryGPSInfo)throw new r("imagery-layer:query-gps-info","queryGPSInfo operation is not supported on the input image service");return e=e??{where:"1=1"},_e(He(this.parsedUrl),e,this._getRequestOptions(t))}async queryRasterCount(e,t){return({query:e,requestOptions:t}=await this._prepareForQuery(e,t)),Me(this.url,e,t)}async queryVisibleRasters(e,t){if(!e)throw new r("imagery-layer: query-visible-rasters","missing query parameter");await this.load();const{pixelSize:i,returnDomainValues:s,returnTopmostRaster:n,showNoDataRecords:a}=t||{pixelSize:null,returnDomainValues:!1,returnTopmostRaster:!1,showNoDataRecords:!1};let o=!1,l=null,u=null;const p=k.servicePixelValue.toLowerCase(),m=this._rasterFunctionNamesIndex;if(null!=e.outFields&&(o=e.outFields.some(e=>!e.toLowerCase().startsWith(p)),this.version>=10.4)){const t=e.outFields.filter(e=>e.toLowerCase().startsWith(p)&&e.length>p.length).map(e=>{const t=e.slice(p.length+1);return[this._updateRenderingRulesFunctionName(t,m),t]});l=t.map(e=>new $({functionName:e[0]})),u=t.map(e=>e[1]);const{rasterFunction:i}=this;0===l.length?i?.functionName?(l.push(i),u.push(i.functionName)):l=null:i?.functionName&&!l.some(e=>e.functionName===i.functionName)&&(l.push(i),u.push(i.functionName))}const c=null==e.outSpatialReference||e.outSpatialReference.equals(this.spatialReference),{multidimensionalSubset:d}=this;let f=e.timeExtent||this.timeExtent;if(d){const{isOutside:t,intersection:i}=y(d,{geometry:e.geometry,timeExtent:e.timeExtent,multidimensionalDefinition:this.exportImageServiceParameters.mosaicRule?.multidimensionalDefinition});if(t)throw new r("imagery-layer:query-visible-rasters","the request cannot be fulfilled when falling outside of the multidimensional subset");null!=i?.timeExtent&&(f=i.timeExtent)}const g=this._combineMosaicRuleWithTimeExtent(this.exportImageServiceParameters.mosaicRule,f);let I=e.geometry;this.version<10.91&&"extent"===I?.type&&(I=h.fromExtent(I));const w=this._getQueryParams({geometry:I,timeExtent:f,mosaicRule:g,rasterFunction:this.version<10.4?this.rasterFunction:null,rasterFunctions:l,pixelSize:i,returnCatalogItems:o,returnGeometry:c,raster:this.raster,maxItemCount:n?1:null});delete w.f;const v=new Ee(w);try{await this._generateRasterInfo(this.rasterFunction);const i=await Ie(this.url,v,{signal:t?.signal,query:{...this.customParameters}}),r=e.outFields,n=null!=i.value&&i.value.toLowerCase().includes("nodata"),l=o&&!c&&i?.catalogItems?.features.length&&(a||!n),p=this.multidimensionalInfo&&"raster-dataset"===this.sourceType?R({rasterInfo:this.rasterInfo,multidimensionalDefinition:g?.multidimensionalDefinition,timeExtent:f,multidimensionalSubset:this.multidimensionalSubset}):null;if(!l)return this._processVisibleRastersResponse(i,{returnDomainValues:s,templateRRFunctionNames:u,showNoDataRecords:a,templateFields:r,effectiveMultidimensionalDefinition:p});const m=this.objectIdField||"ObjectId",d=i.catalogItems?.features??[],h=d.map(e=>e.attributes?.[m]),y=new Ae({objectIds:h,returnGeometry:!0,outSpatialReference:e.outSpatialReference,outFields:[m]}),I=await this.queryRasters(y);return I?.features?.length&&I.features.forEach(t=>{d.forEach(i=>{i.attributes[m]===t.attributes[m]&&t.geometry&&(i.geometry=t.geometry.clone(),null!=e.outSpatialReference&&(i.geometry.spatialReference=e.outSpatialReference))})}),this._processVisibleRastersResponse(i,{returnDomainValues:s,templateRRFunctionNames:u,showNoDataRecords:a,templateFields:r,effectiveMultidimensionalDefinition:p})}catch{throw new r("imagery-layer:query-visible-rasters","encountered error when querying visible rasters")}}async fetchVariableStatisticsHistograms(e,t){const r=i(He(this.parsedUrl)+"/statistics",{query:this._getQueryParams({variable:e}),signal:t}).then(e=>e.data?.statistics),s=i(He(this.parsedUrl)+"/histograms",{query:this._getQueryParams({variable:e}),signal:t}).then(e=>e.data?.histograms),n=await Promise.all([r,s]);return n[0]&&n[0].forEach(e=>{e.avg=e.mean,e.stddev=e.standardDeviation}),{statistics:n[0]||null,histograms:n[1]||null}}getMultidimensionalSubsetVariables(e){const t=e??this.serviceRasterInfo.multidimensionalInfo;return I(this.multidimensionalSubset,t)}async _fetchService(e){await this._fetchServiceInfo(e),this.rasterInfo||(this.rasterInfo=this.serviceRasterInfo);const t=this.sourceJSON,i=null!=this.serviceRasterInfo?Promise.resolve(this.serviceRasterInfo):De(He(this.parsedUrl),t,{signal:e,query:this._getQueryParams()}).then(e=>(this._set("serviceRasterInfo",e),this._set("multidimensionalInfo",e.multidimensionalInfo),Te(e,t),e)),r=this._hasRasterFunction(this.rasterFunction)?this._generateRasterInfo(this.rasterFunction,{signal:e}):null,s=this._getRasterFunctionInfos();return Promise.all([i,r,s]).then(e=>{e[1]?this._set("rasterInfo",e[1]):this._set("rasterInfo",e[0]),e[2]&&this._set("rasterFunctionInfos",e[2]),this.internalRenderer&&!this._isSupportedRenderer(this.internalRenderer)&&(this._set("internalRenderer",null),n.getLogger(this).warn("ArcGISImageService","Switching to the default renderer. Renderer applied is not valid for this Imagery Layer")),this._set("internalRenderer",this._configRenderer(this.renderer)),this.addHandles([a(()=>this.rasterFunction,e=>{(this.renderer||this.symbolizer||this.popupEnabled&&this.popupTemplate)&&this._generateRasterInfo(e).then(e=>{e&&(this.rasterInfo=e)})})]);const{serviceRasterInfo:t}=this;null!=t.multidimensionalInfo&&this._updateMultidimensionalDefinition(t)})}_combineMosaicRuleWithTimeExtent(e,t){const i=this.timeInfo,{multidimensionalInfo:r}=this.serviceRasterInfo;if(null==e||null==r||null==t||null==i?.startField)return e;const{startField:s}=i,n=r.variables.some(e=>e.dimensions.some(e=>e.name===s))?s:"StdTime";if(e=e.clone(),"mosaic-dataset"===this.sourceType)return e.multidimensionalDefinition=e.multidimensionalDefinition?.filter(e=>e.dimensionName!==n),this._cleanupMultidimensionalDefinition(e);e.multidimensionalDefinition=e.multidimensionalDefinition||[];const a=e.multidimensionalDefinition.filter(e=>e.dimensionName===n),o=null!=t.start?t.start.getTime():null,l=null!=t.end?t.end.getTime():null,u=null==o||null==l||o===l,p=u?[o||l]:[[o,l]],m=this.version>=10.8;if(a.length)a.forEach(e=>{e.dimensionName===n&&(m?(e.dimensionName=null,e.isSlice=!1,e.values=[]):(e.isSlice=u,e.values=p))});else if(!m){const t=e.multidimensionalDefinition.filter(e=>null!=e.variableName&&null==e.dimensionName);t.length?t.forEach(e=>{e.dimensionName=n,e.isSlice=u,e.values=p}):e.multidimensionalDefinition.push(new _({variableName:"",dimensionName:n,isSlice:u,values:p}))}return this._cleanupMultidimensionalDefinition(e)}_cleanupMultidimensionalDefinition(e){return null==e?null:(e.multidimensionalDefinition&&(e.multidimensionalDefinition=e.multidimensionalDefinition.filter(e=>!(!e.variableName&&!e.dimensionName)),0===e.multidimensionalDefinition.length&&(e.multidimensionalDefinition=null)),"mosaic-dataset"!==this.sourceType&&null==e.multidimensionalDefinition?null:e)}async _prepareForQuery(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsQuery)throw new r("imagery-layer:query-rasters","query operation is not supported on the input image service");const i=null!=e?m(Ae,e):this.createQuery();return t=this._getRequestOptions(t),this.raster&&(t.query={...t.query,raster:this.raster}),{query:i,requestOptions:t}}_isSupportedRenderer(e){const{rasterInfo:t,rasterFunction:i}=this;return"unique-value"===e.type&&this._hasRasterFunction(i)&&1===t?.bandCount&&["u8","s8"].includes(t.pixelType)||null!=t&&null!=e&&Z(t).includes(e.type)}async _fetchCapabilities(e){return this.capabilities||await this._fetchServiceInfo(e),this.capabilities}async _fetchServiceInfo(e){let t=this.sourceJSON;if(!t){const{data:r,ssl:s}=await i(He(this.parsedUrl),{query:this._getQueryParams(),signal:e});t=r,this.sourceJSON=t,s&&(this.url=this.url.replace(/^http:/i,"https:"))}if(t.capabilities?.toLowerCase().split(",").map(e=>e.trim()).indexOf("tilesonly")>-1)throw new r("imagery-layer:fetch-service-info","use ImageryTileLayer to open tiles-only image services");this.read(t,{origin:"service",url:this.parsedUrl})}_isMosaicDataset(e){return e.serviceSourceType?"esriImageServiceSourceTypeMosaicDataset"===e.serviceSourceType:e.fields?.length>0}_isMosaicRuleSupported(e){if(!e)return!1;const t=this._isMosaicDataset(e),i=e.currentVersion>=10.71&&e.hasMultidimensions&&!(e.fields?.length>1);return t||i}_isVectorFieldResampleFunction(e){if(null==e)return!1;const{functionName:t,functionArguments:i}=e,r="resample"===t?.toLowerCase(),s=i?.ResampleType||i?.resampleType;return r&&(7===s||10===s)}_configRenderer(e){const{rasterInfo:t}=this;if(!this.isRenderedFormat&&!this.pixelFilter||this._isVectorDataSet()){const i=this.mosaicRule?.multidimensionalDefinition?.[0].variableName,r=ee({variableName:i,rasterFunctionName:this.rasterFunction?.functionName,presetRenderers:this.presetRenderers});if(!this.bandIds&&t.bandCount>=3){const e=r?.bandIds??Y(t);!e||3===t.bandCount&&0===e[0]&&1===e[1]&&2===e[2]||(this.bandIds=e)}e||(e=r?.renderer??K(t,{bandIds:this.bandIds,variableName:this.rasterFunction?null:i}));const s=te(e.toJSON());this.symbolizer?(this.symbolizer.rendererJSON=s,this.symbolizer.rasterInfo=t):this.symbolizer=new ie({rendererJSON:s,rasterInfo:t}),this.symbolizer.bind().success||(this.symbolizer=null)}return e}_clonePixelData(e){return null==e?e:{extent:e.extent&&e.extent.clone(),pixelBlock:null!=e.pixelBlock?e.pixelBlock.clone():null}}_getQueryParams(e){null!=e?.renderingRule&&"string"!=typeof e.renderingRule&&(e.renderingRule=this._getRenderingRuleString(e.renderingRule));const{raster:t,viewId:i}=this;return{raster:t,viewId:i,f:"json",...e,...this.customParameters}}_getRequestOptions(e){return{...e,query:{...e?.query,...this.customParameters}}}_decodePixelBlock(e,t,i){return this._rasterJobHandler?this._rasterJobHandler.decode({data:e,options:t}):v(e,t,i)}async _getRasterFunctionInfos(e){const t=this.sourceJSON.rasterFunctionInfos;if(this.loaded)return t;if(t&&this.version>=10.3){if(1===t.length&&"none"===t[0].name.toLowerCase())return t;const r=await i(He(this.parsedUrl)+"/rasterFunctionInfos",{query:this._getQueryParams(),signal:e});return r.data?.rasterFunctionInfos}return null}_canRequestImageElement(e){return!this.pixelFilter&&(!e||e.includes("png"))}async _requestArrayBuffer(e){const{imageProps:t,requestAsImageElement:s,returnImageBitmap:n,signal:a}=e;if(s&&this._canRequestImageElement(t.format)){const r=`${He(this.parsedUrl)}/exportImage`,{data:s}=await i(r,{responseType:n?"blob":"image",query:this._getQueryParams({f:"image",...this.refreshParameters,...e.imageServiceParameters}),signal:a});if(s instanceof Blob){const{bitmap:e}=await C(s,r,{signal:a});return{imageBitmap:e,params:t}}return{imageOrCanvasElement:s,params:t}}const o=this._initJobHandler(),l=i(He(this.parsedUrl)+"/exportImage",{responseType:"array-buffer",query:this._getQueryParams({f:"image",...e.imageServiceParameters}),signal:a}),u=(await Promise.all([l,o]))[0].data,p=t.format||"jpgpng";let m=p;if("bsq"!==m&&"bip"!==m&&(m=b(u)),!m)throw new r("imagery-layer:fetch-image","unsupported format signature "+String.fromCharCode.apply(null,new Uint8Array(u)));const c={signal:a},d=this._decodePixelBlock(u,{width:t.width,height:t.height,format:p,applyJpegMask:!0},c);return{pixelData:{pixelBlock:await d,extent:t.extent},params:t}}_generateRasterInfo(e,t){return this.generateRasterInfo(e,t).catch(()=>null)}_isValidCustomizedMosaicRule(e){return e&&JSON.stringify(e.toJSON())!==JSON.stringify(this.defaultMosaicRule?.toJSON())}_updateMultidimensionalDefinition(e){if(this._isValidCustomizedMosaicRule(this.mosaicRule))return;let t=w(e,{multidimensionalSubset:this.multidimensionalSubset});if(null!=t&&t.length>0){this.mosaicRule=this.mosaicRule||new q;const e=this.mosaicRule.multidimensionalDefinition;!this.sourceJSON.defaultVariableName&&this.rasterFunction&&"none"!==this.rasterFunction.functionName?.toLowerCase()&&t.forEach(e=>e.variableName=""),t=t.filter(({variableName:e,dimensionName:t})=>e&&"*"!==e||t),!e?.length&&t.length&&(this.mosaicRule.multidimensionalDefinition=t)}}_processVisibleRastersResponse(e,i){i=i||{};const r=e.value,{templateRRFunctionNames:s,showNoDataRecords:n,returnDomainValues:a,templateFields:o}=i,l=e.processedValues;let u=e.catalogItems?.features,p=e.properties?.Values?.map(e=>e.replaceAll(/ /gi,", "))||[];const m=this.objectIdField||"ObjectId",c="string"==typeof r&&r.toLowerCase().includes("nodata"),d=[];if(r&&!u&&(!c||n)){const e={};e[m]=0;p=[r],u=[new t({geometry:this.fullExtent,attributes:e})],this.multidimensionalInfo&&"raster-dataset"===this.sourceType&&G(this.rasterFields,e,i.effectiveMultidimensionalDefinition)}if(!u)return[];this._updateResponseFieldNames(u,o),c&&!n&&(u=[]);const{itemPixelValue:h,servicePixelValue:f}=k,g=this.rasterFields.some(e=>e.name===h),y=this.graphicOrigin;for(let t=0;t<u.length;t++){const e=u[t];if(null!=r){const i=p[t],a=this.rasterFunction&&l&&l.length>0&&s&&s.length>0&&s.includes(this.rasterFunction.functionName)?l[s.indexOf(this.rasterFunction.functionName)]:r;if("nodata"===i.toLowerCase()&&!n)continue;g&&(e.attributes[h]=i),e.attributes[f]=a,this._updateFeatureWithMagDirValues(e,i);const o=this.fields&&this.fields.length>0;let u=this.rasterFunction&&null!=this.serviceRasterInfo.attributeTable?o?i:r:a;this.rasterFunction||(u=o?i:r),this._updateFeatureWithRasterAttributeTableValues(e,u)}if(e.sourceLayer=e.layer=this,e.origin=y,a&&this._updateFeatureWithDomainValues(e),s&&l&&s.length===l.length)for(let t=0;t<s.length;t++){const i=`${k.servicePixelValue}.${s[t]}`;e.attributes[i]=l[t]}d.push(u[t])}return d}_processMultidimensionalIntersection(e,t,i){const{multidimensionalSubset:r}=this;if(!r)return{isOutSide:!1,timeExtent:t,mosaicRule:i=this._combineMosaicRuleWithTimeExtent(i,t)};if(r){const{isOutside:i,intersection:s}=y(r,{geometry:e,timeExtent:t});if(i)return{isOutSide:!0,timeExtent:null,mosaicRule:null};null!=s?.timeExtent&&(t=s.timeExtent)}if(i=this._combineMosaicRuleWithTimeExtent(i,t),i?.multidimensionalDefinition){const{isOutside:e}=y(r,{multidimensionalDefinition:i.multidimensionalDefinition});if(e)return{isOutSide:!0,timeExtent:null,mosaicRule:null}}return{isOutSide:!1,timeExtent:t,mosaicRule:i}}_updateFeatureWithRasterAttributeTableValues(e,t){const i=this.rasterInfo.attributeTable||this.serviceRasterInfo.attributeTable;if(null==i)return;const{features:r,fields:s}=i,n=s.map(e=>e.name).find(e=>"value"===e.toLowerCase());if(!n)return;const a=r.filter(e=>e.attributes[n]===(null!=t?parseInt(t,10):null));a&&a[0]&&s.forEach(t=>{const i=W+t.name;e.attributes[i]=a[0].attributes[t.name]})}_updateFeatureWithMagDirValues(e,t){if(!this._isVectorDataSet())return;const i=t.split(/,\s*/).map(e=>parseFloat(e)),r=i.map(e=>[e]),s=i.map(e=>({minValue:e,maxValue:e,noDataValue:null})),n=new P({height:1,width:1,pixelType:"f32",pixels:r,statistics:s});null!=this.pixelFilter&&this.pixelFilter({pixelBlock:n,extent:new d(0,0,0,0,this.spatialReference)});const a="esriImageServiceDataTypeVector-MagDir"===this.serviceDataType?[n.pixels[0][0],n.pixels[1][0]]:x([n.pixels[0][0],n.pixels[1][0]]);e.attributes[k.magnitude]=a[0],e.attributes[k.direction]=a[1]}_updateFeatureWithDomainValues(e){const t=this.fields&&this.fields.filter(e=>"coded-value"===e.domain?.type);null!=t&&t.forEach(t=>{const i=e.attributes[t.name];if(null!=i){const r=t.domain.codedValues.find(e=>e.code===i);r&&(e.attributes[t.name]=r.name)}})}_updateResponseFieldNames(e,t){if(!t||t.length<1)return;const i=this.fieldsIndex;null!=i&&e.forEach(e=>{if(e?.attributes)for(const r of t){const t=i.get(r)?.name;t&&t!==r&&(e.attributes[r]=e.attributes[t],delete e.attributes[t])}})}_getRenderingRuleString(e){if(e){let t=e.toJSON();return t=t.rasterFunctionDefinition??t,(t.thumbnail||t.thumbnailEx)&&(t.thumbnail=t.thumbnailEx=null),JSON.stringify(t)}return null}_hasRasterFunction(e){return null!=e?.functionName&&"none"!==e.functionName.toLowerCase()}_updateRenderingRulesFunctionName(e,t){if(!e||e.length<1)return;if("Raw"===e)return e.replace("Raw","None");const i=e.toLowerCase().replaceAll(/ /gi,"_");return t.has(i)?t.get(i):e}_isRFTJson(e){return e?.name&&e.arguments&&e.function&&e.hasOwnProperty("functionType")}_isVectorDataSet(){return"esriImageServiceDataTypeVector-UV"===this.serviceDataType||"esriImageServiceDataTypeVector-MagDir"===this.serviceDataType}_applyMosaicAndRenderingRules(e){const{raster:t,mosaicRule:i,rasterFunction:r}=this;r&&null==e.rasterFunction&&(e.rasterFunction=r),i&&null==e.mosaicRule&&(e.mosaicRule=i),t&&null==e.raster&&(e.raster=t)}async _updateCurrentRasterInfo(e){if(this.renderer||this.symbolizer){const t=await this._generateRasterInfo(this.rasterFunction,{signal:e});t&&(this.rasterInfo=t)}}_applyMosaicRule(e){const{raster:t,mosaicRule:i}=this;i&&null==e.mosaicRule&&(e.mosaicRule=i),t&&null==e.raster&&(e.raster=t)}_readCapabilities(e){const t=e.capabilities?e.capabilities.toLowerCase().split(",").map(e=>e.trim()):["image","catalog"],{currentVersion:i,maxRecordCount:r}=e,s=t.includes("image"),n="esriImageServiceDataTypeElevation"===e.serviceDataType,a=!(!e.spatialReference&&!e.extent?.spatialReference),o=t.includes("edit"),l=t.includes("mensuration")&&a,u=null==e.mensurationCapabilities?[]:e.mensurationCapabilities.toLowerCase().split(",").map(e=>e.trim()),p=l&&u.includes("basic"),m=this._isMosaicDataset(e)&&t.includes("catalog"),c=t.includes("download"),d=i>=10.7&&n||i>=11.4&&(n||l&&u.includes("3d")),h=m&&e.fields&&e.fields.length>0,f=h&&e.supportsAdvancedQueries?e.advancedQueryCapabilities:void 0;return{data:{supportsAttachment:!1},operations:{supportsComputeHistograms:s,supportsExportImage:s,supportsIdentify:s,supportsImageToMap:i>=11.2&&m,supportsImageToMapMultiray:i>=11.2&&m,supportsMapToImage:i>=11.2&&m,supportsFindImages:i>=11.2&&m,supportsGetImageUrl:i>=11.3&&c,supportsMeasure:l,supportsMeasureFromImage:i>=11.2,supportsDownload:c,supportsQuery:h,supportsGetSamples:i>=10.2&&s,supportsProject:i>=10.3&&s,supportsComputeStatisticsHistograms:i>=10.4&&s,supportsQueryBoundary:i>=10.6&&s,supportsCalculateVolume:d,supportsComputePixelLocation:i>=10.7&&m,supportsComputeAngles:i>=10.91,supportsQueryGPSInfo:i>=11.2&&m,supportsAdd:o,supportsDelete:o,supportsEditing:o,supportsUpdate:o,supportsCalculate:!1,supportsTruncate:!1,supportsValidateSql:!1,supportsChangeTracking:!1,supportsQueryAttachments:!1,supportsResizeAttachments:!1,supportsSync:!1,supportsExceedsLimitStatistics:!1,supportsQueryAnalytics:!1,supportsQueryBins:!1,supportsQueryPivot:!1,supportsQueryTopFeatures:!1,supportsAsyncConvert3D:!1},query:{maxRecordCount:r,maxRecordCountFactor:void 0,maxUniqueIDCount:void 0,relativeTimeBinWindow:void 0,supportsAggregateIds:!!f?.supportsAggregateIds,supportsStatistics:!!f?.supportsStatistics,supportsOrderBy:!!f?.supportsOrderBy,supportsDistinct:!!f?.supportsDistinct,supportsPagination:!!f?.supportsPagination,supportsPaginationOnAggregatedQueries:!!f?.supportsPaginationOnAggregatedQueries,supportsStandardizedQueriesOnly:!!f?.useStandardizedQueries,supportsPercentileStatistics:!!f?.supportsPercentileStatistics,supportsCentroid:!!f?.supportsReturningGeometryCentroid,supportsCentroidOnDegeneratedQuantizedGeometry:!1,supportsCurrentUser:!1,supportsDegeneratedQuantizedGeometry:!1,supportsDistance:!!f?.supportsQueryWithDistance,supportsExtent:!!f?.supportsReturningQueryExtent,supportsGeometryProperties:!!f?.supportsReturningGeometryProperties,supportsHavingClause:!!f?.supportsHavingClause,supportsQuantization:!1,supportsQuantizationEditMode:!1,supportsQueryGeometry:!1,supportsResultType:!1,supportsReturnMesh:!1,supportsMaxRecordCountFactor:!1,supportsSqlExpression:f?.supportsSqlExpression??!!f,supportsTopFeaturesQuery:!1,supportsQueryByAnonymous:!1,supportsQueryByOthers:!1,supportsHistoricMoment:!1,supportsFormatPBF:!1,supportsFormatPBFWithCurves:!1,supportsDisjointSpatialRelationship:!1,supportsCacheHint:!1,supportsSpatialAggregationStatistics:!1,supportedSpatialAggregationStatistics:{envelope:!1,centroid:!1,convexHull:!1},supportsDefaultSpatialReference:!!f?.supportsDefaultSR,supportsFullTextSearch:!1,supportsCompactGeometry:!1,standardMaxRecordCount:void 0,standardMaxRecordCountNoGeometry:void 0,tileMaxRecordCount:void 0,supportsTrueCurve:!1},mensuration:{supportsDistanceAndAngle:p,supportsAreaAndPerimeter:p,supportsPointOrCentroid:p,supportsHeightFromBaseAndTop:l&&u.includes("base-top height"),supportsHeightFromBaseAndTopShadow:l&&u.includes("base-top shadow height"),supportsHeightFromTopAndTopShadow:l&&u.includes("top-top shadow height"),supports3D:l&&u.includes("3d")}}}};function He(e){return e?.path??""}return e([l({clonable:!1})],Le.prototype,"_functionRasterInfos",void 0),e([l({readOnly:!0})],Le.prototype,"_serviceSupportsMosaicRule",void 0),e([Qe("_serviceSupportsMosaicRule",["currentVersion","fields"])],Le.prototype,"readServiceSupportsMosaicRule",null),e([l({readOnly:!0})],Le.prototype,"_rasterFunctionNamesIndex",null),e([l()],Le.prototype,"adjustAspectRatio",void 0),e([l({type:[p],json:{write:!0}})],Le.prototype,"bandIds",void 0),e([Qe("bandIds")],Le.prototype,"readBandIds",null),e([l({readOnly:!0,json:{read:!1}})],Le.prototype,"capabilities",void 0),e([Qe("service","capabilities",["capabilities","currentVersion","serviceDataType"])],Le.prototype,"readCapabilities",null),e([l({type:Number})],Le.prototype,"compressionQuality",void 0),e([Ve("compressionQuality")],Le.prototype,"writeCompressionQuality",null),e([l({type:Number})],Le.prototype,"compressionTolerance",void 0),e([Ve("compressionTolerance")],Le.prototype,"writeCompressionTolerance",null),e([l({json:{read:{source:"copyrightText"}}})],Le.prototype,"copyright",void 0),e([l({readOnly:!0})],Le.prototype,"defaultMosaicRule",void 0),e([Qe("defaultMosaicRule",["defaultMosaicMethod"])],Le.prototype,"readDefaultMosaicRule",null),e([l({type:String,json:{name:"layerDefinition.definitionExpression",write:{enabled:!0,allowNull:!0}}})],Le.prototype,"definitionExpression",void 0),e([l({readOnly:!0,constructOnly:!0})],Le.prototype,"exportImageServiceParameters",void 0),e([l()],Le.prototype,"rasterInfo",void 0),e([l({readOnly:!0,type:[O]})],Le.prototype,"fields",void 0),e([l({readOnly:!0})],Le.prototype,"fieldsIndex",null),e([l({type:["png","png8","png24","png32","jpg","bmp","gif","jpgpng","lerc","tiff","bip","bsq"],json:{write:!0}})],Le.prototype,"format",null),e([Qe("service","format",["serviceDataType"])],Le.prototype,"readFormat",null),e([l({type:d})],Le.prototype,"fullExtent",void 0),e([l({readOnly:!0})],Le.prototype,"hasMultidimensions",void 0),e([l({json:{read:{source:"maxImageHeight"}}})],Le.prototype,"imageMaxHeight",void 0),e([l({json:{read:{source:"maxImageWidth"}}})],Le.prototype,"imageMaxWidth",void 0),e([l({type:String,json:{type:j.jsonValues,read:j.read,write:j.write}})],Le.prototype,"interpolation",void 0),e([l()],Le.prototype,"minScale",void 0),e([Qe("service","minScale")],Le.prototype,"readMinScale",null),e([l()],Le.prototype,"maxScale",void 0),e([Qe("service","maxScale")],Le.prototype,"readMaxScale",null),e([l({type:q})],Le.prototype,"mosaicRule",null),e([Qe("mosaicRule",["mosaicRule","defaultMosaicMethod"])],Le.prototype,"readMosaicRule",null),e([Ve("mosaicRule")],Le.prototype,"writeMosaicRule",null),e([l()],Le.prototype,"multidimensionalInfo",void 0),e([l({type:N,json:{write:!0}})],Le.prototype,"multidimensionalSubset",void 0),e([l({json:{type:[Number,[Number]],write:!0}})],Le.prototype,"noData",void 0),e([l({type:String,json:{type:E.jsonValues,read:E.read,write:E.write}})],Le.prototype,"noDataInterpretation",void 0),e([l({type:String,readOnly:!0,json:{read:{source:["fields"]}}})],Le.prototype,"objectIdField",void 0),e([Qe("objectIdField")],Le.prototype,"readObjectIdField",null),e([l({readOnly:!0})],Le.prototype,"geometryType",void 0),e([l({})],Le.prototype,"typeIdField",void 0),e([l({})],Le.prototype,"types",void 0),e([l({readOnly:!0})],Le.prototype,"parsedUrl",null),e([l({type:Function})],Le.prototype,"pixelFilter",void 0),e([l()],Le.prototype,"raster",void 0),e([l({readOnly:!0})],Le.prototype,"sourceType",void 0),e([Qe("sourceType",["serviceSourceType","fields"])],Le.prototype,"readSourceType",null),e([l()],Le.prototype,"viewId",void 0),e([l({types:re})],Le.prototype,"renderer",null),e([l({types:re,json:{name:"layerDefinition.drawingInfo.renderer",origins:{"web-scene":{types:se,name:"layerDefinition.drawingInfo.renderer",write:{overridePolicy:e=>({enabled:e&&"vector-field"!==e.type})}}}}})],Le.prototype,"internalRenderer",null),e([Qe("internalRenderer")],Le.prototype,"readRenderer",null),e([Ve("internalRenderer")],Le.prototype,"writeRenderer",null),e([l({clonable:!1})],Le.prototype,"symbolizer",void 0),e([l(S)],Le.prototype,"opacity",void 0),e([l({readOnly:!0})],Le.prototype,"rasterFields",null),e([l({constructOnly:!0})],Le.prototype,"rasterFunctionInfos",void 0),e([l({type:$,json:{name:"renderingRule"}})],Le.prototype,"rasterFunction",null),e([Qe("rasterFunction",["renderingRule","rasterFunctionInfos"])],Le.prototype,"readRasterFunction",null),e([l({readOnly:!0})],Le.prototype,"serviceDataType",void 0),e([l({readOnly:!0,type:f})],Le.prototype,"spatialReference",void 0),e([Qe("spatialReference",["spatialReference","extent"])],Le.prototype,"readSpatialReference",null),e([l({type:A.apiValues,json:{read:A.read,type:A.jsonValues}})],Le.prototype,"pixelType",void 0),e([Ve("pixelType")],Le.prototype,"writePixelType",null),e([l({constructOnly:!0,type:X})],Le.prototype,"serviceRasterInfo",void 0),e([l()],Le.prototype,"sourceJSON",void 0),e([l(F)],Le.prototype,"url",void 0),e([l({readOnly:!0})],Le.prototype,"version",void 0),e([Qe("version",["currentVersion","fields","timeInfo"])],Le.prototype,"readVersion",null),Le=e([u("esri.layers.mixins.ArcGISImageService")],Le),Le};export{Be as ArcGISImageService};