@arcgis/core 6.0.0-next.13 → 6.0.0-next.15

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 (220) hide show
  1. package/arcade/containerUtils.js +1 -1
  2. package/arcade/featureset/sources/FeatureLayerDynamic.js +1 -1
  3. package/arcade/functions/feature.js +1 -1
  4. package/arcade/functions/featuresetstring.js +1 -1
  5. package/arcade/functions/geomasync.js +1 -1
  6. package/arcade/functions/portal.js +1 -1
  7. package/arcade/functions/string.js +1 -1
  8. package/assets/esri/core/workers/RemoteClient.js +1 -1
  9. package/assets/esri/core/workers/chunks/{5566f14afb63065e438f.js → 0050916e462e3c9e0627.js} +1 -1
  10. package/assets/esri/core/workers/chunks/02c5d027bdaee67869cf.js +1 -0
  11. package/assets/esri/core/workers/chunks/08fe248e412bb170210d.js +1 -0
  12. package/assets/esri/core/workers/chunks/0da6abe3ceabfe78f7a0.js +1 -0
  13. package/assets/esri/core/workers/chunks/0f617980c7dd9ad0444f.js +1 -0
  14. package/assets/esri/core/workers/chunks/{fb444954be74c1962ced.js → 10d80e793019dfb45ca2.js} +1 -1
  15. package/assets/esri/core/workers/chunks/{10445313d0d57b34511b.js → 2145a512d269d64036b0.js} +1 -1
  16. package/assets/esri/core/workers/chunks/21ddb26526bcb2b122c3.js +1 -0
  17. package/assets/esri/core/workers/chunks/25f19fc929f25ddd628c.js +1 -0
  18. package/assets/esri/core/workers/chunks/28b74bc77f7c13080074.js +1 -0
  19. package/assets/esri/core/workers/chunks/{2ef5237e4c876d6a4ee0.js → 2bd4ee083ca4ad221f8b.js} +1 -1
  20. package/assets/esri/core/workers/chunks/{f4f9d08b2df856e3b694.js → 2eae542fe7f0f6576ac1.js} +1 -1
  21. package/assets/esri/core/workers/chunks/{2aeb5cc32284dd3e4d22.js → 33e4ff228a8c81b99022.js} +1 -1
  22. package/assets/esri/core/workers/chunks/{42323093827adffe56d3.js → 3418877328f4f0830300.js} +1 -1
  23. package/assets/esri/core/workers/chunks/{8dc1c3042267618fd710.js → 34cbaf844730ac2d92c2.js} +2 -2
  24. package/assets/esri/core/workers/chunks/{96c50a0dda0f1503ef92.js → 3c301a689c7853c9fa67.js} +2 -2
  25. package/assets/esri/core/workers/chunks/{02253bdffbd580af22d8.js → 3ff6d1ed3c0f1285f3e7.js} +1 -1
  26. package/assets/esri/core/workers/chunks/{67e4b5651fd7ff7d8cf0.js → 4ac1d3e49e242e373a92.js} +1 -1
  27. package/assets/esri/core/workers/chunks/4df6cb1bee5d0720a43e.js +1 -0
  28. package/assets/esri/core/workers/chunks/{a4cab24af69260438ff4.js → 4e6f40cbdb8c508e6df1.js} +1 -1
  29. package/assets/esri/core/workers/chunks/5736feefa261589b6273.js +1 -0
  30. package/assets/esri/core/workers/chunks/601e1d020b8115497944.js +1 -0
  31. package/assets/esri/core/workers/chunks/{2686fe5b62dd0be699c0.js → 634523cc7757da9020e4.js} +1 -1
  32. package/assets/esri/core/workers/chunks/{a518ae5683367eeda74c.js → 70d3055f15d8b0cf4074.js} +1 -1
  33. package/assets/esri/core/workers/chunks/{1b946714ca4a1a7359d4.js → 76ab353d80d786777161.js} +2 -2
  34. package/assets/esri/core/workers/chunks/7f8e327acad48c9e75ea.js +1 -0
  35. package/assets/esri/core/workers/chunks/8052da8be251c3ff2176.js +1 -0
  36. package/assets/esri/core/workers/chunks/8e19629899a5becf8e19.js +1 -0
  37. package/assets/esri/core/workers/chunks/{f6e62d2d279a328cbed7.js → 90bdf86f553e2742d67c.js} +1 -1
  38. package/assets/esri/core/workers/chunks/91ebb2ccab1889eb7e81.js +1 -0
  39. package/assets/esri/core/workers/chunks/94e427040edb469d58ad.js +1 -0
  40. package/assets/esri/core/workers/chunks/{3d9d7d3a40b51eb7ee3d.js → 953ba13299e7aa92c1a0.js} +1 -1
  41. package/assets/esri/core/workers/chunks/{f46d9a19f79d4a4bd354.js → 9e1a3b6a08c96dcefdde.js} +1 -1
  42. package/assets/esri/core/workers/chunks/9f0a973a0dd28953ce25.js +1 -0
  43. package/assets/esri/core/workers/chunks/a2ad3e620c98e2b2eb06.js +1 -0
  44. package/assets/esri/core/workers/chunks/a34b3d2e11a777e1ff3f.js +1 -0
  45. package/assets/esri/core/workers/chunks/{140f2eeb11e39ab15734.js → aa36c3a9bbaa086e3757.js} +1 -1
  46. package/assets/esri/core/workers/chunks/ae31fd416bbb41a81392.js +1 -0
  47. package/assets/esri/core/workers/chunks/b49df4ebd4be1181b0f9.js +2 -0
  48. package/assets/esri/core/workers/chunks/{68d8ae42ab71d01a70a5.js → b557824bc1fa163d72a3.js} +2 -2
  49. package/assets/esri/core/workers/chunks/bc915fb182d463d804e6.js +1 -0
  50. package/assets/esri/core/workers/chunks/{992f102992c2bed7b34e.js → d5d0fe8e198ff5a902ee.js} +1 -1
  51. package/assets/esri/core/workers/chunks/e2190361247f35b02b32.js +1 -0
  52. package/assets/esri/core/workers/chunks/e2f42aec02bff33b25dd.js +1 -0
  53. package/assets/esri/core/workers/chunks/ebc1a2ef3aed8aa29424.js +1 -0
  54. package/assets/esri/core/workers/chunks/ed6e9d7f71bfd2691717.js +1 -0
  55. package/assets/esri/core/workers/chunks/ed8786fed345718ed684.js +1 -0
  56. package/assets/esri/core/workers/chunks/ee6679ef9efa1504e7eb.js +1 -0
  57. package/assets/esri/libs/lyr3d/lyr3DMain.wasm +0 -0
  58. package/assets/esri/libs/lyr3d/lyr3DWorker.wasm +0 -0
  59. package/assets/esri/libs/pdfjs/wasm/openjpeg_nowasm_fallback.js +1 -0
  60. package/chunks/BlendWeights.glsl.js +10 -10
  61. package/chunks/Blur.glsl.js +2 -2
  62. package/chunks/EdgeDetect.glsl.js +24 -19
  63. package/chunks/HUDMaterial.glsl.js +11 -1
  64. package/chunks/HighlightApply.glsl.js +4 -5
  65. package/chunks/HighlightBlur.glsl.js +5 -5
  66. package/chunks/HighlightDownsample.glsl.js +2 -2
  67. package/chunks/HighlightSharpApply.glsl.js +61 -0
  68. package/chunks/lyr3DMain.js +1 -1
  69. package/chunks/lyr3DWorker.js +2 -2
  70. package/chunks/portal.js +1 -1
  71. package/config.js +1 -1
  72. package/core/ObjectPool.js +1 -1
  73. package/core/PooledArray.js +1 -1
  74. package/core/accessorSupport/tracking/SimpleTrackingTarget.js +1 -1
  75. package/geometry/support/buffer/BufferPool.js +1 -1
  76. package/geometry/support/coordsUtils.js +1 -1
  77. package/geometry/support/curves/ellipticArc7Utils.js +1 -1
  78. package/geometry/support/curves/mathUtils.js +1 -1
  79. package/geometry/support/meshUtils.d.ts +5 -6
  80. package/interfaces.d.ts +18 -9
  81. package/kernel.js +1 -1
  82. package/layers/GeospatialPDFLayer.d.ts +154 -4
  83. package/layers/Layer.d.ts +2 -0
  84. package/layers/geospatialPDF/GeospatialPDFLayerWorker.js +1 -1
  85. package/layers/geospatialPDF/ViewportMeasureFrame.js +1 -1
  86. package/layers/geospatialPDF/geospatialPDFParserUtils.js +1 -1
  87. package/layers/geospatialPDF/projectionToWKTUtils.js +2 -2
  88. package/layers/graphics/controllers/FeatureTileController3D.js +1 -1
  89. package/layers/graphics/sources/GeoJSONSource.js +1 -1
  90. package/layers/graphics/sources/geojson/GeoJSONSourceWorker.js +1 -1
  91. package/layers/graphics/sources/support/MemorySourceWorker.js +1 -1
  92. package/layers/graphics/sources/support/clientSideDefaults.js +1 -1
  93. package/layers/graphics/sources/support/sourceUtils.js +1 -1
  94. package/layers/raster/datasets/TIFFRaster.js +1 -1
  95. package/layers/raster/datasets/pixelReader.js +1 -1
  96. package/layers/raster/functions/clipUtils.js +1 -1
  97. package/layers/support/LabelClass.d.ts +3 -2
  98. package/layers/support/PortalItemData.d.ts +31 -8
  99. package/layers/support/fieldUtils.js +1 -1
  100. package/layers/support/types.d.ts +4 -1
  101. package/package.json +2 -2
  102. package/portal/schemas/definitions.js +1 -1
  103. package/rest/knowledgeGraph/ObjectValue.js +1 -1
  104. package/symbols/cim/cimAnalyzer.js +1 -1
  105. package/views/2d/engine/webgl/GlyphWorker.js +1 -1
  106. package/views/2d/layers/features/schema/processor/symbols/ComplexSymbolSchema.js +1 -1
  107. package/views/3d/analysis/DirectLineMeasurementAnalysisView3D.js +1 -1
  108. package/views/3d/analysis/LineOfSight/LineOfSightItemTool.js +1 -1
  109. package/views/3d/analysis/LineOfSight/LineOfSightObserverPlugin.js +1 -1
  110. package/views/3d/analysis/LineOfSight/LineOfSightPlacementController.js +1 -1
  111. package/views/3d/analysis/LineOfSight/{LineOfSightRootPlugin.js → LineOfSightPlacementRootPlugin.js} +1 -1
  112. package/views/3d/analysis/LineOfSight/LineOfSightTargetPlugin.js +1 -1
  113. package/views/3d/analysis/LineOfSight/LineOfSightTool.js +1 -1
  114. package/views/3d/analysis/Viewshed/ViewshedPlacementPointPlugin.js +1 -1
  115. package/views/3d/analysis/Viewshed/ViewshedSubTool.js +1 -1
  116. package/views/3d/analysis/Viewshed/ViewshedTool.js +1 -1
  117. package/views/3d/interactive/editingTools/ManipulatedObject3DGraphic.js +1 -1
  118. package/views/3d/support/MemoryController.js +1 -1
  119. package/views/3d/terrain/TerrainData.js +1 -1
  120. package/views/3d/terrain/terrainUtils.js +1 -1
  121. package/views/3d/webgl-engine/core/shaderLibrary/HighlightCellGridScreenSpacePass.glsl.js +20 -6
  122. package/views/3d/webgl-engine/effects/RenderPluginManager.js +1 -1
  123. package/views/3d/webgl-engine/effects/geometry/RenderOccluded.js +1 -1
  124. package/views/3d/webgl-engine/effects/highlight/Highlight.js +1 -1
  125. package/views/3d/webgl-engine/effects/highlight/HighlightApply.glsl.js +1 -1
  126. package/views/3d/webgl-engine/effects/highlight/HighlightCellGridScreenSpacePassParameters.js +2 -0
  127. package/views/3d/webgl-engine/effects/highlight/HighlightDownsample.glsl.js +1 -1
  128. package/views/3d/webgl-engine/effects/highlight/HighlightPassParameters.js +1 -1
  129. package/views/3d/webgl-engine/effects/highlight/HighlightSharpApply.glsl.js +2 -0
  130. package/views/3d/webgl-engine/effects/highlight/HighlightSharpApplyTechnique.js +2 -0
  131. package/views/3d/webgl-engine/effects/smaa/BlendWeights.glsl.js +1 -1
  132. package/views/3d/webgl-engine/effects/smaa/Blur.glsl.js +1 -1
  133. package/views/3d/webgl-engine/effects/smaa/EdgeDetect.glsl.js +1 -1
  134. package/views/3d/webgl-engine/effects/smaa/SMAA.js +1 -1
  135. package/views/3d/webgl-engine/effects/smaa/SMAABlendWeightsTechnique.js +1 -1
  136. package/views/3d/webgl-engine/effects/smaa/SMAABlurTechnique.js +1 -1
  137. package/views/3d/webgl-engine/effects/smaa/SMAAEdgeDetectTechnique.js +1 -1
  138. package/views/3d/webgl-engine/effects/smaa/SMAAPassParameters.js +1 -1
  139. package/views/3d/webgl-engine/effects/smaa/SMAATechniqueConfiguration.js +2 -0
  140. package/views/3d/webgl-engine/lib/Compositor.js +1 -1
  141. package/views/3d/webgl-engine/lib/PathBuilder.js +1 -1
  142. package/views/3d/webgl-engine/lib/PathCapBuilder.js +1 -1
  143. package/views/3d/webgl-engine/lib/PathEvaluator.js +1 -1
  144. package/views/3d/webgl-engine/lib/PathExtruder.js +1 -1
  145. package/views/3d/webgl-engine/lib/PathProfile.js +1 -1
  146. package/views/3d/webgl-engine/lib/RenderFeature.js +1 -1
  147. package/views/3d/webgl-engine/lib/pathGeometryUtils.js +1 -1
  148. package/views/3d/webgl-engine/parts/RenderView.js +1 -1
  149. package/views/draw/DrawTool.js +1 -1
  150. package/views/draw/plugins/MultipointPlugin.js +1 -1
  151. package/views/draw/support/PluginContext.js +1 -1
  152. package/views/draw/support/managers/TooltipManager.js +1 -1
  153. package/views/draw/support/types.d.ts +5 -2
  154. package/views/support/HighlightDefaults.js +1 -1
  155. package/webdoc/applicationProperties/SearchLayerField.d.ts +7 -1
  156. package/webdoc/applicationProperties/SearchLayerField.js +1 -1
  157. package/webdoc/applicationProperties/SearchTableField.d.ts +7 -1
  158. package/webdoc/applicationProperties/SearchTableField.js +1 -1
  159. package/webdoc/applicationProperties/searchMode.js +2 -0
  160. package/widgets/BatchAttributeForm/batchAttributeFormUtils.js +1 -1
  161. package/widgets/BatchAttributeForm/inputs/support/DynamicChoiceController.js +1 -1
  162. package/widgets/BatchAttributeForm/inputs/support/inputUtils.js +1 -1
  163. package/widgets/BatchAttributeForm.js +1 -1
  164. package/widgets/Editor/EditorViewModel.d.ts +10 -1
  165. package/widgets/Editor.d.ts +10 -1
  166. package/widgets/FeatureTable/FeatureTableViewModel.js +1 -1
  167. package/widgets/FeatureTable/support/FeatureStore.js +1 -1
  168. package/widgets/HistogramRangeSlider.d.ts +2 -2
  169. package/widgets/HistogramRangeSlider.js +1 -1
  170. package/widgets/Legend.d.ts +1 -0
  171. package/widgets/OrientedImageryViewer/services/DepthImageService.js +1 -1
  172. package/widgets/ScaleRangeSlider/ScaleRangeSliderViewModel.d.ts +5 -2
  173. package/widgets/ScaleRangeSlider/ScaleRangeSliderViewModel.js +1 -1
  174. package/widgets/ScaleRangeSlider.js +1 -1
  175. package/widgets/Search/LayerSearchSource.d.ts +23 -1
  176. package/widgets/Search/LayerSearchSource.js +1 -1
  177. package/widgets/Search/support/layerSearchUtils.js +1 -1
  178. package/widgets/Search/types.d.ts +7 -0
  179. package/widgets/ValuePicker/ValuePickerBaseComponent.d.ts +5 -1
  180. package/widgets/ValuePicker/ValuePickerCollection.d.ts +2 -0
  181. package/widgets/ValuePicker/ValuePickerCombobox.d.ts +7 -1
  182. package/widgets/ValuePicker/ValuePickerLabel.d.ts +7 -1
  183. package/widgets/ValuePicker/ValuePickerSlider.d.ts +2 -0
  184. package/widgets/ValuePicker/ValuePickerSliderVisibleElements.d.ts +5 -1
  185. package/widgets/ValuePicker/ValuePickerVisibleElements.d.ts +5 -1
  186. package/widgets/ValuePicker/types.d.ts +2 -0
  187. package/widgets/support/forms/formUtils.js +1 -1
  188. package/widgets/support/forms/types.d.ts +1 -1
  189. package/assets/esri/core/workers/chunks/037a8cc19debbaaa4e10.js +0 -1
  190. package/assets/esri/core/workers/chunks/0dc66b03ff55d0ea5a09.js +0 -1
  191. package/assets/esri/core/workers/chunks/175c268e64ccd01f8c25.js +0 -1
  192. package/assets/esri/core/workers/chunks/1c65ab9ed611c322ce27.js +0 -1
  193. package/assets/esri/core/workers/chunks/2a1ec30f9ad305763f81.js +0 -2
  194. package/assets/esri/core/workers/chunks/3df5500a85345577480a.js +0 -1
  195. package/assets/esri/core/workers/chunks/3f7d583b676b23b3fadb.js +0 -1
  196. package/assets/esri/core/workers/chunks/408e81c8f1eff8a7b379.js +0 -1
  197. package/assets/esri/core/workers/chunks/4503b20ca6a80fb63d72.js +0 -1
  198. package/assets/esri/core/workers/chunks/4a640548032355e57acd.js +0 -1
  199. package/assets/esri/core/workers/chunks/53be85d04cd2da4f391d.js +0 -1
  200. package/assets/esri/core/workers/chunks/566e129f3d3805d7370a.js +0 -1
  201. package/assets/esri/core/workers/chunks/567a65f4203f6e81f4b4.js +0 -1
  202. package/assets/esri/core/workers/chunks/5982c6a8459c1237b298.js +0 -1
  203. package/assets/esri/core/workers/chunks/5eae5c29149f2429fe96.js +0 -1
  204. package/assets/esri/core/workers/chunks/6dc86e7496157c5e4d2c.js +0 -1
  205. package/assets/esri/core/workers/chunks/74b5c00f93cfc0d59029.js +0 -1
  206. package/assets/esri/core/workers/chunks/7c2c8f786a30267a5f05.js +0 -1
  207. package/assets/esri/core/workers/chunks/88e54449261ef94e390d.js +0 -1
  208. package/assets/esri/core/workers/chunks/9e142551163acf752618.js +0 -1
  209. package/assets/esri/core/workers/chunks/af75747b06d79446a855.js +0 -1
  210. package/assets/esri/core/workers/chunks/dba280c370df13196711.js +0 -1
  211. package/assets/esri/core/workers/chunks/dc486a3595b6d57018bb.js +0 -1
  212. package/assets/esri/core/workers/chunks/e3c1c9e6c62ba5cbcdb8.js +0 -1
  213. package/assets/esri/core/workers/chunks/f1f90adae13b04898008.js +0 -1
  214. package/assets/esri/core/workers/chunks/f47c7065da3b5001245f.js +0 -1
  215. /package/assets/esri/core/workers/chunks/{1b946714ca4a1a7359d4.js.LICENSE.txt → 34cbaf844730ac2d92c2.js.LICENSE.txt} +0 -0
  216. /package/assets/esri/core/workers/chunks/{96c50a0dda0f1503ef92.js.LICENSE.txt → 3c301a689c7853c9fa67.js.LICENSE.txt} +0 -0
  217. /package/assets/esri/core/workers/chunks/{8dc1c3042267618fd710.js.LICENSE.txt → 76ab353d80d786777161.js.LICENSE.txt} +0 -0
  218. /package/assets/esri/core/workers/chunks/{2a1ec30f9ad305763f81.js.LICENSE.txt → b49df4ebd4be1181b0f9.js.LICENSE.txt} +0 -0
  219. /package/assets/esri/core/workers/chunks/{68d8ae42ab71d01a70a5.js.LICENSE.txt → b557824bc1fa163d72a3.js.LICENSE.txt} +0 -0
  220. /package/views/3d/analysis/LineOfSight/{lineOfSightPlacementUtils.js → placementUtils.js} +0 -0
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import e from"../../core/Error.js";import{fromValues as t}from"../../core/libs/gl-matrix-2/factories/vec2f64.js";import n from"../../geometry/Point.js";import r from"../../geometry/SpatialReference.js";import{projectExecute as i}from"../../geometry/operators/projectOperator.js";import{expandMediaBox as a,validateTransform as o,affineTransformationFromGeoreference as s,createGeoreferencer as c}from"./sharedUtils.js";class l{constructor(e){let{bbox:t,bounds:n,gpts:r,lpts:i,gcs:c,mediaBox:l}=this.inputValidation(e);this._bbox=t,this._bounds=n,this._gpts=r,this._lpts=i,this._gcs=c,this.outerExtentMediaBox=a(l),this.geoControlPoints=this._getProjectedGeoControlPoints().map(e=>[e[0],e[1]]);let u=this._getBoundsPolygonPage()??this._getPageControlPoints();this.pairedNeatline=u.map(e=>[e[0],e[1]]),this.neatLine=this.pairedNeatline.flat(),this._georeference=this._createControlPointsGeoreference();let d=o(this._georeference);this.ctm=s(d),this.outputValidation()}toSpatialReference(){return new r({wkt:this._gcs.WKT})}inputValidation(t){let{bbox:n,bounds:r,gpts:i,lpts:a,gcs:o,mediaBox:s}=t;if(!n||n.length!==4)throw new e(`geospatial-pdf-layer:invalid-frame`,`Viewport missing or invalid BBox.`);if(!s||s.length!==4)throw new e(`geospatial-pdf-layer:invalid-frame`,`Viewport missing or invalid MediaBox.`);if(!i||i.length<6||i.length%2!=0)throw new e(`geospatial-pdf-layer:invalid-frame`,`MeasureFrame missing or invalid GPTS.`);if(!a||a.length<6||a.length%2!=0)throw new e(`geospatial-pdf-layer:invalid-frame`,`MeasureFrame missing or invalid LPTS.`);if(a.length!==i.length)throw new e(`geospatial-pdf-layer: invalid-frame`,`MeasureFrame LPTS and GPTS must be same length`);if(!o?.WKT)throw new e(`geospatial-pdf-layer:invalid-frame`,`MeasureFrame missing or invalid WKT.`);return{bbox:n,bounds:r,gpts:i,lpts:a,gcs:{WKT:o.WKT},mediaBox:s}}outputValidation(){if(this.outerExtentMediaBox.length!==4)throw new e(`geospatial-pdf-layer:invalid-frame`,`Failed to generate outer extent from mediaBox.`);if(this.geoControlPoints.length<2)throw new e(`geospatial-pdf-layer:invalid-frame`,`Map Frame should have at least 2 geoControlPoints.`);if(this.pairedNeatline.length<4)throw new e(`geospatial-pdf-layer:invalid-frame`,`Map Frame should have at least 4 neatline points.`);if(!this.ctm||this.ctm.length!==6)throw new e(`geospatial-pdf-layer:invalid-frame`,`Missing or invalid Map Frame CTM`)}_createControlPointsGeoreference(){let e=this._getPageControlPoints(),t=this._getProjectedGeoControlPoints(),n=this._getViewportRect();return c(e,t,this.toSpatialReference(),n)}_getBoundsPolygonLocal(){if(!this._bounds||this._bounds.length<8||this._bounds.length%2!=0)return null;let e=[];for(let t=0;t<this._bounds.length;t+=2)e.push({u:this._bounds[t],v:this._bounds[t+1]});return e}_getBoundsPolygonPage(){return this._getBoundsPolygonLocal()?.map(e=>this._localToPage(e.u,e.v))??null}_getPageControlPoints(){let e=[];for(let t=0;t<this._lpts.length;t+=2){let n=this._lpts[t],r=this._lpts[t+1];e.push(this._localToPage(n,r))}return e}_getProjectedGeoControlPoints(){let e=this.toSpatialReference(),r=[];for(let a=0;a<this._gpts.length;a+=2){let o=this._gpts[a],s=this._gpts[a+1],c=new n({x:s,y:o}),l=i(c,e);r.push(t(l.x,l.y))}return r}_getViewportRect(){let[e,t,n,r]=this._bbox;return{xmin:Math.min(e,n),ymin:Math.min(t,r),xmax:Math.max(e,n),ymax:Math.max(t,r)}}_localToPage(e,n){let[r,i,a,o]=this._bbox;return t(r+e*(a-r),i+n*(o-i))}}export{l as ViewportMeasureFrame};
2
+ import e from"../../core/Error.js";import{fromValues as t}from"../../core/libs/gl-matrix-2/factories/vec2f64.js";import n from"../../geometry/Point.js";import r from"../../geometry/SpatialReference.js";import{projectExecute as i}from"../../geometry/operators/projectOperator.js";import{expandMediaBox as a,validateTransform as o,affineTransformationFromGeoreference as s,createGeoreferencer as c}from"./sharedUtils.js";class l{constructor(e){let{bbox:t,bounds:n,gpts:r,lpts:i,gcs:c,mediaBox:l}=this.inputValidation(e);this._bbox=t,this._bounds=n,this._gpts=r,this._lpts=i,this._gcs=c,this.outerExtentMediaBox=a(l),this.geoControlPoints=this._getProjectedGeoControlPoints().map(e=>[e[0],e[1]]);let u=this._getBoundsPolygonPage()??this._getPageControlPoints();this.pairedNeatline=u.map(e=>[e[0],e[1]]),this.neatLine=this.pairedNeatline.flat(),this._georeference=this._createControlPointsGeoreference();let d=o(this._georeference);this.ctm=s(d),this.outputValidation()}toSpatialReference(){let t=this._gcs;if(t?.WKT)return new r({wkt:t.WKT});if(t?.EPSG!=null)return new r({wkid:t.EPSG});throw new e(`geospatial-pdf-layer: invalid-frame`,`MeasureFrame missing WKT or EPSG.`)}inputValidation(t){let{bbox:n,bounds:r,gpts:i,lpts:a,gcs:o,mediaBox:s}=t;if(!n||n.length!==4)throw new e(`geospatial-pdf-layer:invalid-frame`,`Viewport missing or invalid BBox.`);if(!s||s.length!==4)throw new e(`geospatial-pdf-layer:invalid-frame`,`Viewport missing or invalid MediaBox.`);if(!i||i.length<6||i.length%2!=0)throw new e(`geospatial-pdf-layer:invalid-frame`,`MeasureFrame missing or invalid GPTS.`);if(!a||a.length<6||a.length%2!=0)throw new e(`geospatial-pdf-layer:invalid-frame`,`MeasureFrame missing or invalid LPTS.`);if(a.length!==i.length)throw new e(`geospatial-pdf-layer: invalid-frame`,`MeasureFrame LPTS and GPTS must be same length`);if(!o?.WKT&&!o?.EPSG)throw new e(`geospatial-pdf-layer:invalid-frame`,`MeasureFrame missing a WKT or EPSG code.`);return{bbox:n,bounds:r,gpts:i,lpts:a,gcs:o,mediaBox:s}}outputValidation(){if(this.outerExtentMediaBox.length!==4)throw new e(`geospatial-pdf-layer:invalid-frame`,`Failed to generate outer extent from mediaBox.`);if(this.geoControlPoints.length<2)throw new e(`geospatial-pdf-layer:invalid-frame`,`Map Frame should have at least 2 geoControlPoints.`);if(this.pairedNeatline.length<4)throw new e(`geospatial-pdf-layer:invalid-frame`,`Map Frame should have at least 4 neatline points.`);if(!this.ctm||this.ctm.length!==6)throw new e(`geospatial-pdf-layer:invalid-frame`,`Missing or invalid Map Frame CTM`)}_createControlPointsGeoreference(){let e=this._getPageControlPoints(),t=this._getProjectedGeoControlPoints(),n=this._getViewportRect();return c(e,t,this.toSpatialReference(),n)}_getBoundsPolygonLocal(){if(!this._bounds||this._bounds.length<8||this._bounds.length%2!=0)return null;let e=[];for(let t=0;t<this._bounds.length;t+=2)e.push({u:this._bounds[t],v:this._bounds[t+1]});return e}_getBoundsPolygonPage(){return this._getBoundsPolygonLocal()?.map(e=>this._localToPage(e.u,e.v))??null}_getPageControlPoints(){let e=[];for(let t=0;t<this._lpts.length;t+=2){let n=this._lpts[t],r=this._lpts[t+1];e.push(this._localToPage(n,r))}return e}_getProjectedGeoControlPoints(){let e=this.toSpatialReference(),r=[];for(let a=0;a<this._gpts.length;a+=2){let o=this._gpts[a],s=this._gpts[a+1],c=new n({x:s,y:o}),l=i(c,e);r.push(t(l.x,l.y))}return r}_getViewportRect(){let[e,t,n,r]=this._bbox;return{xmin:Math.min(e,n),ymin:Math.min(t,r),xmax:Math.max(e,n),ymax:Math.max(t,r)}}_localToPage(e,n){let[r,i,a,o]=this._bbox;return t(r+e*(a-r),i+n*(o-i))}}export{l as ViewportMeasureFrame};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import e from"../../core/Error.js";import"../../core/has.js";import{LGIDictMapFrame as t}from"./LGIDictMapFrame.js";import{projectionToSpatialReference as n}from"./projectionToWKTUtils.js";import{ViewportMeasureFrame as r}from"./ViewportMeasureFrame.js";function i(i,s=0){let c={mediaBox:_(i.MediaBox),rotate:x(i.Rotate),hasLGIDict:i.LGIDict!=null,hasVP:i.VP!=null},l=a(i.LGIDict,s);if(l){if(!l.Projection)throw new e(`geospatial-pdf-layer:parse`,`LGIDict map frame missing Projection.`);let r=n(l.Projection),a;try{a=l.Display?n(l.Display):void 0}catch{a=r}return{result:c,lgiDictFrame:new t({ctm:l.CTM,registration:l.Registration,projection:r,display:a,neatline:l.Neatline,mediaBox:_(i.MediaBox)})}}let u=o(i.VP,s);return u?{result:c,vpFrame:new r({bbox:u.BBox,bounds:u.Measure?.Bounds,gpts:u.Measure?.GPTS,lpts:u.Measure?.LPTS,gcs:u.Measure?.GCS,mediaBox:_(i.MediaBox)})}:{result:c}}function a(e,t){return s(e)[t]}function o(e,t){return c(e)[t]}function s(e){return e==null?[]:Array.isArray(e)?e.map(e=>l(e)):[l(e)]}function c(e){return e==null?[]:Array.isArray(e)?e.map(e=>u(e)):[u(e)]}function l(e){let t=C(e,`LGIDict map frame must be an object.`);return{CTM:_(t.CTM),Registration:v(t.Registration),Neatline:_(t.Neatline),Projection:p(t.Projection),Display:p(t.Display)}}function u(e){let t=C(e,`Viewport frame must be an object.`),n=d(t.Measure);return{BBox:_(t.BBox),Measure_Raw:t.Measure,Measure:n,Raw:t}}function d(e){if(S(e))return{Bounds:_(e.Bounds),GPTS:_(e.GPTS),LPTS:_(e.LPTS),GCS:f(e.GCS)}}function f(e){if(S(e))return{WKT:y(e.WKT)}}function p(e){if(S(e))return{Type:b(e.Type),Units:b(e.Units),Datum:m(e.Datum),Projection_Type:b(e.ProjectionType),Central_Meridian:x(e.CentralMeridian),False_Easting:x(e.FalseEasting),False_Northing:x(e.FalseNorthing),Height:x(e.Height),Hemisphere:b(e.Hemisphere),Latitude_One:x(e.LatitudeOne),Latitude_Two:x(e.LatitudeTwo),Latitude_Of_True_Scale:x(e.LatitudeOfTrueScale),Longitude_One:x(e.LongitudeOne),Longitude_Two:x(e.LongitudeTwo),Longitude_Down_From_Pole:x(e.LongitudeDownFromPole),Orientation:b(e.Orientation),Origin_Height:x(e.OriginHeight),Origin_Latitude:x(e.OriginLatitude),Origin_Longitude:x(e.OriginLongitude),Scale_Factor:x(e.ScaleFactor),Standard_Parallel:x(e.StandardParallel),Standard_Parallel_One:x(e.StandardParallelOne),Standard_Parallel_Two:x(e.StandardParallelTwo),Zone:x(e.Zone),Description:b(e.Description),raw:e}}function m(e){return e==null?null:typeof e==`string`?{kind:`name`,name:b(e),ellipsoid:null,to_WGS84:null,raw:e}:S(e)?{kind:`definition`,name:b(e.Description),ellipsoid:h(e.Ellipsoid),to_WGS84:g(e.ToWGS84),raw:e}:{kind:`unknown`,name:b(e),ellipsoid:null,to_WGS84:null,raw:e}}function h(e){if(S(e))return{semi_Major_Axis:x(e.SemiMajorAxis),inverse_Flattening:x(e.InvFlattening),semi_Minor_Axis:x(e.SemiMinorAxis),description:b(e.Description)}}function g(e){if(S(e))return{dx:x(e.dx)??0,dy:x(e.dy)??0,dz:x(e.dz)??0,rx:x(e.rx)??0,ry:x(e.ry)??0,rz:x(e.rz)??0,sf:x(e.sf)??0}}function _(e){if(!Array.isArray(e))return;let t=[];for(let n of e){let e=x(n);if(e===void 0)return;t.push(e)}return t}function v(e){if(Array.isArray(e))return e.filter(e=>Array.isArray(e)).map(e=>e.map(e=>x(e)).filter(e=>e!==void 0))}function y(e){if(e!=null)return typeof e==`string`?e:String(e)}function b(e){let t=y(e);if(t!==void 0)return t.trim()}function x(e){if(e==null)return;if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(typeof e!=`string`)return;let t=e.trim();if(t===``)return;let n=Number(t);return Number.isFinite(n)?n:void 0}function S(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function C(t,n){if(!S(t))throw new e(`geospatial-pdf-layer:parse`,n);return t}export{i as parse};
2
+ import e from"../../core/Error.js";import"../../core/has.js";import{LGIDictMapFrame as t}from"./LGIDictMapFrame.js";import{projectionToSpatialReference as n}from"./projectionToWKTUtils.js";import{ViewportMeasureFrame as r}from"./ViewportMeasureFrame.js";function i(i,s=0){let c={mediaBox:_(i.MediaBox),rotate:x(i.Rotate),hasLGIDict:i.LGIDict!=null,hasVP:i.VP!=null};if(c.hasVP){let t=o(i.VP,s);if(!t)throw new e(`geospatial-pdf-layer:invalid frame`,`Failed to parse VP frame at index ${s}`);return{result:c,vpFrame:new r({bbox:t.BBox,bounds:t.Measure?.Bounds,gpts:t.Measure?.GPTS,lpts:t.Measure?.LPTS,gcs:t.Measure?.GCS,mediaBox:_(i.MediaBox)})}}if(c.hasLGIDict){let r=a(i.LGIDict,s);if(!r)throw new e(`geospatial-pdf-layer:invalid frame`,`Failed to parse LGI Dict frame at index ${s}`);if(!r.Projection)throw new e(`geospatial-pdf-layer:parse`,`LGIDict map frame missing Projection.`);let o=n(r.Projection),l;try{l=r.Display?n(r.Display):void 0}catch{l=o}return{result:c,lgiDictFrame:new t({ctm:r.CTM,registration:r.Registration,projection:o,display:l,neatline:r.Neatline,mediaBox:_(i.MediaBox)})}}return{result:c}}function a(e,t){return s(e)[t]}function o(e,t){return c(e)[t]}function s(e){return e==null?[]:Array.isArray(e)?e.map(e=>l(e)):[l(e)]}function c(e){return e==null?[]:Array.isArray(e)?e.map(e=>u(e)):[u(e)]}function l(e){let t=C(e,`LGIDict map frame must be an object.`);return{CTM:_(t.CTM),Registration:v(t.Registration),Neatline:_(t.Neatline),Projection:p(t.Projection),Display:p(t.Display)}}function u(e){let t=C(e,`Viewport frame must be an object.`),n=d(t.Measure);return{BBox:_(t.BBox),Measure_Raw:t.Measure,Measure:n,Raw:t}}function d(e){if(S(e))return{Bounds:_(e.Bounds),GPTS:_(e.GPTS),LPTS:_(e.LPTS),GCS:f(e.GCS)}}function f(e){if(S(e))return{WKT:y(e.WKT),EPSG:x(e.EPSG)}}function p(e){if(S(e))return{Type:b(e.Type),Units:b(e.Units),Datum:m(e.Datum),Projection_Type:b(e.ProjectionType),Central_Meridian:x(e.CentralMeridian),False_Easting:x(e.FalseEasting),False_Northing:x(e.FalseNorthing),Height:x(e.Height),Hemisphere:b(e.Hemisphere),Latitude_One:x(e.LatitudeOne),Latitude_Two:x(e.LatitudeTwo),Latitude_Of_True_Scale:x(e.LatitudeOfTrueScale),Longitude_One:x(e.LongitudeOne),Longitude_Two:x(e.LongitudeTwo),Longitude_Down_From_Pole:x(e.LongitudeDownFromPole),Orientation:b(e.Orientation),Origin_Height:x(e.OriginHeight),Origin_Latitude:x(e.OriginLatitude),Origin_Longitude:x(e.OriginLongitude),Scale_Factor:x(e.ScaleFactor),Standard_Parallel:x(e.StandardParallel),Standard_Parallel_One:x(e.StandardParallelOne),Standard_Parallel_Two:x(e.StandardParallelTwo),Zone:x(e.Zone),Description:b(e.Description),raw:e}}function m(e){return e==null?null:typeof e==`string`?{kind:`name`,name:b(e),ellipsoid:null,to_WGS84:null,raw:e}:S(e)?{kind:`definition`,name:b(e.Description),ellipsoid:h(e.Ellipsoid),to_WGS84:g(e.ToWGS84),raw:e}:{kind:`unknown`,name:b(e),ellipsoid:null,to_WGS84:null,raw:e}}function h(e){if(S(e))return{semi_Major_Axis:x(e.SemiMajorAxis),inverse_Flattening:x(e.InvFlattening),semi_Minor_Axis:x(e.SemiMinorAxis),description:b(e.Description)}}function g(e){if(S(e))return{dx:x(e.dx)??0,dy:x(e.dy)??0,dz:x(e.dz)??0,rx:x(e.rx)??0,ry:x(e.ry)??0,rz:x(e.rz)??0,sf:x(e.sf)??0}}function _(e){if(!Array.isArray(e))return;let t=[];for(let n of e){let e=x(n);if(e===void 0)return;t.push(e)}return t}function v(e){if(Array.isArray(e))return e.filter(e=>Array.isArray(e)).map(e=>e.map(e=>x(e)).filter(e=>e!==void 0))}function y(e){if(e!=null)return typeof e==`string`?e:String(e)}function b(e){let t=y(e);if(t!==void 0)return t.trim()}function x(e){if(e==null)return;if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(typeof e!=`string`)return;let t=e.trim();if(t===``)return;let n=Number(t);return Number.isFinite(n)?n:void 0}function S(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function C(t,n){if(!S(t))throw new e(`geospatial-pdf-layer:parse`,n);return t}export{i as parse};
@@ -1,3 +1,3 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import e from"../../core/Error.js";import t from"../../geometry/SpatialReference.js";const n={OriginLatitude:`Origin_Latitude`,CentralMeridian:`Central_Meridian`,ScaleFactor:`Scale_Factor`,FalseEasting:`False_Easting`,FalseNorthing:`False_Northing`,Zone:`Zone`,Hemisphere:`Hemisphere`,StandardParallelOne:`Standard_Parallel_One`,StandardParallelTwo:`Standard_Parallel_Two`},r=/^(?:NAD83|NORTH AMERICAN 1983|NAR(?:-[A-Z])?)$/i,i=/^(?:NAD27|NORTH AMERICAN 1927|NAS(?:-[A-Z])?)$/i,a=/^(?:WGS84|WGS 84|WGE)$/i;function o(e){let n=s(e);if(n.kind===`projected`){let{projectionType:r,datum:i}=n;return r===`SPCS`?O(e,i):new t({wkt:p(e,r,i)})}}function s(e){return c(e)}function c(t){let n=l(t.Type),r=u(t.Projection_Type),i;if(r||(i=`Projection is missing or has unsupported ProjectionType`),n||(i=`Projection dictionary is missing or has invalid Type. Expected Projection or Display.`),t.Datum||(i=`Projection is missing a Datum`),i)throw new e(`geospatial-pdf-layer:invalid-projection`,i);return d(t,r),{kind:`projected`,dictionaryType:n,projectionType:r,datum:t.Datum}}function l(e){switch(e){case`Projection`:case`Display`:return e;default:return}}function u(e){switch(e){case`TC`:case`PH`:case`UT`:case`AC`:case`LE`:case`SPCS`:return e;default:return}}function d(t,r){let i=f(r);for(let a of i){let i=t[n[a]];if(i===void 0||i===``)throw new e(`geospatial-pdf-layer:invalid-projection`,`Projection ${r} missing required parameter ${a}.`)}}function f(e){switch(e){case`TC`:return[`OriginLatitude`,`CentralMeridian`,`ScaleFactor`,`FalseEasting`,`FalseNorthing`];case`PH`:return[`OriginLatitude`,`CentralMeridian`,`FalseEasting`,`FalseNorthing`];case`UT`:return[`Zone`,`Hemisphere`];case`AC`:case`LE`:return[`OriginLatitude`,`CentralMeridian`,`StandardParallelOne`,`StandardParallelTwo`,`FalseEasting`,`FalseNorthing`];case`SPCS`:return[`Zone`]}}function p(e,t,n){let r=h(e,t,n),i=m(t),a=_(n),o=v(e.Units??`M`),s=y(e,t);return`PROJCS["${r}",GEOGCS["${S(n)}",${a},PRIMEM["Greenwich",0],UNIT["Degree",0.0174532925199433]],PROJECTION["${i}"],${s.join(`,
3
- `)},${o}]`}function m(e){switch(e){case`TC`:case`UT`:return`Transverse_Mercator`;case`PH`:return`Polyconic`;case`AC`:return`Albers`;case`LE`:return`Lambert_Conformal_Conic`}}function h(e,t,n){let r=g(n);switch(t){case`TC`:return`${r}_GeospatialPDF_Transverse_Mercator`;case`PH`:return`${r}_GeospatialPDF_Polyconic`;case`UT`:return`${r}_GeospatialPDF_UTM_Zone_${e.Zone}_${e.Hemisphere}`;case`AC`:return`${r}_GeospatialPDF_Albers_Equal_Area`;case`LE`:return`${r}_GeospatialPDF_Lambert_Conformal_Conic`}}function g(e){let t=C(e);return t?T(t)?`NAD_1983`:E(t)?`NAD_1927`:D(t)?`WGS_1984`:`geospatialPDF`:`geospatialPDF`}function _(t){if(t.kind===`definition`){let n=t.ellipsoid;if(!n?.semi_Major_Axis)throw new e(`geospatial-pdf-layer:invalid-Datum`,`Datum definition requires semi-major axis`);let r=x(n),i=t.name??`GeospatialPDF_Datum`,a=`SPHEROID["${n.description??`GeospatialPDF_Spheroid`}",${n.semi_Major_Axis},${r}]`,o=t.to_WGS84;return`DATUM["${i}",${a}${o?`,TOWGS84[${o.dx??0},${o.dy??0},${o.dz??0},${o.rx??0},${o.ry??0},${o.rz??0},${o.sf??0}]`:``}]`}if(t.name){let e=t.name.toUpperCase();if(T(e))return`DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]]`;if(E(e))return`DATUM["D_North_American_1927",SPHEROID["Clarke_1866",6378206.4,294.9786982]]`;if(D(e))return`DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]]`}throw new e(`geospatial-pdf-layer:invalid-Datum`,`Unsupported datum `+t.name)}function v(e){let t=e.toLowerCase();return[`m`,`meter`,`meters`,`metre`,`metres`].includes(t)?`UNIT["Meter",1.0]`:[`ft`,`foot`,`feet`].includes(t)?`UNIT["Foot",0.3048]`:`UNIT["${e}",1.0]`}function y(e,t){switch(t){case`TC`:return[`PARAMETER["False_Easting",${e.False_Easting}]`,`PARAMETER["False_Northing",${e.False_Northing}]`,`PARAMETER["Central_Meridian",${e.Central_Meridian}]`,`PARAMETER["Latitude_Of_Origin",${e.Origin_Latitude}]`,`PARAMETER["Scale_Factor",${e.Scale_Factor}]`];case`PH`:return[`PARAMETER["False_Easting",${e.False_Easting}]`,`PARAMETER["False_Northing",${e.False_Northing}]`,`PARAMETER["Central_Meridian",${e.Central_Meridian}]`,`PARAMETER["Latitude_Of_Origin",${e.Origin_Latitude}]`];case`AC`:case`LE`:return[`PARAMETER["False_Easting",${e.False_Easting}]`,`PARAMETER["False_Northing",${e.False_Northing}]`,`PARAMETER["Central_Meridian",${e.Central_Meridian}]`,`PARAMETER["Latitude_Of_Origin",${e.Origin_Latitude}]`,`PARAMETER["Standard_Parallel_1",${e.Standard_Parallel_One}]`,`PARAMETER["Standard_Parallel_2",${e.Standard_Parallel_Two}]`];case`UT`:return b(e)}}function b(t){if(!t.Zone)throw new e(`geospatial-pdf-layer:invalid-projection`,`No zone found for projection code UT`);let n=t.Zone*6-183;return[`PARAMETER["False_Easting",500000]`,`PARAMETER["False_Northing",${/^s/i.test(t.Hemisphere??``)?1e7:0}]`,`PARAMETER["Central_Meridian",${n}]`,`PARAMETER["Latitude_Of_Origin",0]`,`PARAMETER["Scale_Factor",0.9996]`]}function x(t){if(t.inverse_Flattening!=null)return t.inverse_Flattening;let n=t.semi_Major_Axis,r=t.semi_Minor_Axis;if(n==null||r==null)throw new e(`geospatial-pdf-layer:invalid-Datum`,`Ellipsoid definition missing InvFlattening or SemiMinorAxis.`);return n===r?0:n/(n-r)}function S(e){let t=C(e);return t?T(t)?`GCS_North_American_1983`:E(t)?`GCS_North_American_1927`:D(t)?`GCS_WGS_1984`:`GCS_GeospatialPDF`:`GCS_GeospatialPDF`}function C(e){return e.name?w(e.name):null}function w(e){return e.trim().toUpperCase().replace(/_/g,` `).replace(/\s+/g,` `)}function T(e){return r.test(e)}function E(e){return i.test(e)}function D(e){return a.test(e)}function O(n,r){let i=C(r);if(n.Zone===2800&&i&&T(i))return new t({wkid:32110});throw new e(`geospatial-pdf-layer:invalid-projection`,`Unsupported State Plane projection: datum ${r.name}, zone ${n.Zone}`)}export{o as projectionToSpatialReference,s as validateProjection};
2
+ import e from"../../core/Error.js";import t from"../../geometry/SpatialReference.js";const n={OriginLatitude:`Origin_Latitude`,CentralMeridian:`Central_Meridian`,ScaleFactor:`Scale_Factor`,FalseEasting:`False_Easting`,FalseNorthing:`False_Northing`,Zone:`Zone`,Hemisphere:`Hemisphere`,StandardParallelOne:`Standard_Parallel_One`,StandardParallelTwo:`Standard_Parallel_Two`},r=/^(?:NAD83|NORTH AMERICAN 1983|NAR(?:-[A-Z])?)$/i,i=/^(?:NAD27|NORTH AMERICAN 1927|NAS(?:-[A-Z])?)$/i,a=/^(?:WGS84|WGS 84|WGE)$/i;function o(e){let n=s(e);if(n.kind===`projected`){let{projectionType:r,datum:i}=n;return r===`SPCS`?O(e,i):new t({wkt:p(e,r,i)})}}function s(e){return c(e)}function c(t){let n=l(t.Type);if(!n)throw new e(`geospatial-pdf-layer:invalid-projection`,`Projection dictionary is missing or has invalid Type`,`Expected Projection or Display`);let r=t.Projection_Type;if(!r)throw new e(`geospatial-pdf-layer:invalid-projection`,`Missing projection code`);let i=u(t.Projection_Type);if(!i)throw new e(`geospatial-pdf-layer:unsupported-projection`,`Unsupported projection code: ${r}`);let a=t.Datum;if(!a)throw new e(`geospatial-pdf-layer:invalid-datum`,`Missing datum definition or code in LGI Dict frame`);if(a.kind===`unknown`)throw new e(`geospatial-pdf-layer:invalid-datum`,`Invalid datum: ${a.name??`unknown`}`);return d(t,i),{kind:`projected`,dictionaryType:n,projectionType:i,datum:t.Datum}}function l(e){switch(e){case`Projection`:case`Display`:return e;default:return}}function u(e){switch(e){case`TC`:case`PH`:case`UT`:case`AC`:case`LE`:case`SPCS`:return e;default:return}}function d(t,r){let i=f(r);for(let a of i){let i=t[n[a]];if(i===void 0||i===``)throw new e(`geospatial-pdf-layer:invalid-projection`,`Projection ${r} missing required parameter ${a}`)}}function f(e){switch(e){case`TC`:return[`OriginLatitude`,`CentralMeridian`,`ScaleFactor`,`FalseEasting`,`FalseNorthing`];case`PH`:return[`OriginLatitude`,`CentralMeridian`,`FalseEasting`,`FalseNorthing`];case`UT`:return[`Zone`,`Hemisphere`];case`AC`:case`LE`:return[`OriginLatitude`,`CentralMeridian`,`StandardParallelOne`,`StandardParallelTwo`,`FalseEasting`,`FalseNorthing`];case`SPCS`:return[`Zone`]}}function p(e,t,n){let r=h(e,t,n),i=m(t),a=_(n),o=v(e.Units??`M`),s=y(e,t);return`PROJCS["${r}",GEOGCS["${S(n)}",${a},PRIMEM["Greenwich",0],UNIT["Degree",0.0174532925199433]],PROJECTION["${i}"],${s.join(`,
3
+ `)},${o}]`}function m(e){switch(e){case`TC`:case`UT`:return`Transverse_Mercator`;case`PH`:return`Polyconic`;case`AC`:return`Albers`;case`LE`:return`Lambert_Conformal_Conic`}}function h(e,t,n){let r=g(n);switch(t){case`TC`:return`${r}_GeospatialPDF_Transverse_Mercator`;case`PH`:return`${r}_GeospatialPDF_Polyconic`;case`UT`:return`${r}_GeospatialPDF_UTM_Zone_${e.Zone}_${e.Hemisphere}`;case`AC`:return`${r}_GeospatialPDF_Albers_Equal_Area`;case`LE`:return`${r}_GeospatialPDF_Lambert_Conformal_Conic`}}function g(e){let t=C(e);return t?T(t)?`NAD_1983`:E(t)?`NAD_1927`:D(t)?`WGS_1984`:`geospatialPDF`:`geospatialPDF`}function _(t){if(t.kind===`definition`){let n=t.raw.Ellipsoid;if(typeof n==`string`)throw new e(`geospatial-pdf-layer:unsupported-ellipsoid`,`Only ellipsoid definitions are supported but found predefined code`,{code:n});let r=t.raw.ToWGS84;if(typeof r==`string`)throw new e(`geospatial-pdf-layer:unsupported-datum-shift`,`Only shift definitions are supported but found predefined code`,{code:r});let i=t.ellipsoid;if(!i?.semi_Major_Axis)throw new e(`geospatial-pdf-layer:invalid-Datum`,`Datum definition requires semi-major axis`);let a=x(i),o=t.name??`GeospatialPDF_Datum`,s=`SPHEROID["${i.description??`GeospatialPDF_Spheroid`}",${i.semi_Major_Axis},${a}]`,c=t.to_WGS84;return`DATUM["${o}",${s}${c?`,TOWGS84[${c.dx??0},${c.dy??0},${c.dz??0},${c.rx??0},${c.ry??0},${c.rz??0},${c.sf??0}]`:``}]`}if(t.name){let e=t.name.toUpperCase();if(T(e))return`DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]]`;if(E(e))return`DATUM["D_North_American_1927",SPHEROID["Clarke_1866",6378206.4,294.9786982]]`;if(D(e))return`DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]]`}throw new e(`geospatial-pdf-layer:unsupported-datum`,`Unsupported datum code: ${t.name??`unknown`}`)}function v(e){let t=e.toLowerCase();return[`m`,`meter`,`meters`,`metre`,`metres`].includes(t)?`UNIT["Meter",1.0]`:[`ft`,`foot`,`feet`].includes(t)?`UNIT["Foot",0.3048]`:`UNIT["${e}",1.0]`}function y(e,t){switch(t){case`TC`:return[`PARAMETER["False_Easting",${e.False_Easting}]`,`PARAMETER["False_Northing",${e.False_Northing}]`,`PARAMETER["Central_Meridian",${e.Central_Meridian}]`,`PARAMETER["Latitude_Of_Origin",${e.Origin_Latitude}]`,`PARAMETER["Scale_Factor",${e.Scale_Factor}]`];case`PH`:return[`PARAMETER["False_Easting",${e.False_Easting}]`,`PARAMETER["False_Northing",${e.False_Northing}]`,`PARAMETER["Central_Meridian",${e.Central_Meridian}]`,`PARAMETER["Latitude_Of_Origin",${e.Origin_Latitude}]`];case`AC`:case`LE`:return[`PARAMETER["False_Easting",${e.False_Easting}]`,`PARAMETER["False_Northing",${e.False_Northing}]`,`PARAMETER["Central_Meridian",${e.Central_Meridian}]`,`PARAMETER["Latitude_Of_Origin",${e.Origin_Latitude}]`,`PARAMETER["Standard_Parallel_1",${e.Standard_Parallel_One}]`,`PARAMETER["Standard_Parallel_2",${e.Standard_Parallel_Two}]`];case`UT`:return b(e)}}function b(t){if(!t.Zone)throw new e(`geospatial-pdf-layer:invalid-projection`,`No zone found for projection code UT`);let n=t.Zone*6-183;return[`PARAMETER["False_Easting",500000]`,`PARAMETER["False_Northing",${/^s/i.test(t.Hemisphere??``)?1e7:0}]`,`PARAMETER["Central_Meridian",${n}]`,`PARAMETER["Latitude_Of_Origin",0]`,`PARAMETER["Scale_Factor",0.9996]`]}function x(t){if(t.inverse_Flattening!=null)return t.inverse_Flattening;let n=t.semi_Major_Axis,r=t.semi_Minor_Axis;if(n==null||r==null)throw new e(`geospatial-pdf-layer:invalid-Datum`,`Ellipsoid definition missing InvFlattening or SemiMinorAxis`);return n===r?0:n/(n-r)}function S(e){let t=C(e);return t?T(t)?`GCS_North_American_1983`:E(t)?`GCS_North_American_1927`:D(t)?`GCS_WGS_1984`:`GCS_GeospatialPDF`:`GCS_GeospatialPDF`}function C(e){return e.name?w(e.name):null}function w(e){return e.trim().toUpperCase().replace(/_/g,` `).replace(/\s+/g,` `)}function T(e){return r.test(e)}function E(e){return i.test(e)}function D(e){return a.test(e)}function O(n,r){let i=C(r);if(n.Zone===2800&&i&&T(i))return new t({wkid:32110});throw new e(`geospatial-pdf-layer:invalid-projection`,`Unsupported State Plane projection: datum ${r.name}, zone ${n.Zone}`)}export{o as projectionToSpatialReference};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import{result as n}from"../../../core/asyncUtils.js";import r from"../../../core/Collection.js";import i from"../../../core/Error.js";import has from"../../../core/has.js";import{clone as a}from"../../../core/lang.js";import o from"../../../core/Logger.js";import{destroyMaybe as s,removeMaybe as c,abortMaybe as l}from"../../../core/maybe.js";import{EsriPromiseMixin as u}from"../../../core/Promise.js";import{createAbortError as d,isAbortError as f}from"../../../core/promiseUtils.js";import{initial as p,watch as m,syncAndInitial as h,sync as g}from"../../../core/reactiveUtils.js";import{sqlAnd as _}from"../../../core/sql.js";import{property as v,subclass as y}from"../../../core/accessorSupport/decorators.js";import{UpdatingHandles as b}from"../../../core/support/UpdatingHandles.js";import{projectAsync as x}from"../../../geometry/projectionUtils.js";import{isHostedAgolService as S}from"../../support/arcgisLayerUrl.js";import{checkServiceCurrentUserSupport as C}from"../../support/featureLayerUtils.js";import{getEffectiveLayerCapabilities as w}from"../../support/layerUtils.js";import T from"../../../rest/support/StatisticDefinition.js";import{FeatureTileDescriptor as E,virtualSnapshotTileId as D,virtualDisplayFilterHighlightTileId as O}from"../../../views/3d/layers/support/FeatureTileDescriptor.js";import{FeatureTileFetcher3D as k}from"../../../views/3d/layers/support/FeatureTileFetcher3D.js";import{FeatureTileFetcher3DDebugger as A}from"../../../views/3d/layers/support/FeatureTileFetcher3DDebugger.js";import{debugFlags as j}from"../../../views/3d/support/debugFlags.js";let M=class extends u(t){get dataUpdating(){return this._tileFetcher?.dataUpdating??!1}set extent(e){if(e!=null&&!e.spatialReference.equals(this.layerView.view.spatialReference)){o.getLogger(this).error(`#extent=`,`extent needs to be in the same spatial reference as the view`);return}let t=this._get(`extent`);if(t===e||t!=null&&e&&t.equals(e))return;let n=e==null?null:e.clone();this._set(`extent`,n)}get updating(){return!!(this._tileFetcher?.updating||this._fetchDataInfoPromise!=null||this.mode===`tiles`&&this.layerView.view.featureTiles?.updating||this._updatingHandles?.updating)}get updatingTotal(){return this.updating&&this._tileFetcher!=null?this._tileFetcher.updatingTotal:0}get updatingRemaining(){return this.updating&&this._tileFetcher!=null?this._tileFetcher.updatingRemaining:0}get expectedFeatureDiff(){return this.updating&&this._tileFetcher!=null?this._tileFetcher.expectedFeatureDiff:0}get usedMemory(){return this._tileFetcher?.usedMemory??0}get usedMemoryPerFeature(){return this._tileFetcher?.usedMemoryPerFeature??0}get maximumNumberOfFeaturesExceeded(){return!!(this._tileFetcher!=null&&this._tileFetcher.maximumNumberOfFeaturesExceeded)}get snappingComplexityExceeded(){return this._tileFetcher?.snappingComplexityExceeded??!0}get maximumNumberOfFeatures(){return this.displayFeatureLimit?.maximumNumberOfFeatures??0}set maximumNumberOfFeatures(e){e!==this.maximumNumberOfFeatures&&this._overrideIfSome(`maximumNumberOfFeatures`,e)}get hasMaximumNumberOfFeaturesOverride(){return this._isOverridden(`maximumNumberOfFeatures`)}get hasAllFeatures(){return this.serviceDataCount===I.noServiceDataCount&&this.mode===`snapshot`&&this.hasAllFeaturesInView||this.serviceDataCount===this.graphics.length}get hasAllFeaturesInView(){let e=this.context.effectiveDisplayFilter?.where||null,t=e!=null&&e!==`1=1`;return this.mode===`tiles`&&t?!1:this._tileFetcher?.showsAllFeatures??!1}get hasFullGeometries(){return this._tileFetcher?.hasFullGeometries??!1}get mode(){let e=this.layerView.layer;if(e.type===`feature`&&e.infoFor3D!=null)return`snapshot`;if(e.type===`catalog-footprint`||this._forceTilesMode)return`tiles`;let t=this.layerView.view;if(t.qualitySettings?.graphics3D?.snapshotAvailable===!1||this.serviceDataCount===I.noServiceDataCount||this._snapshotLimitExceeded||this.maximumNumberOfFeaturesExceeded||t.quality<1)return`tiles`;let n=(t&&t.featureTiles)?.tilingScheme;if(e&&e.minScale&&this.serviceDataExtent&&n){let t=this._approximateExtentSizeAtScale(e.minScale,n);if((this.serviceDataExtent.width/t+this.serviceDataExtent.height/t)/2>I.maxSnapshotMinScaleFactor)return`tiles`}return!this.maximumNumberOfFeatures||this.serviceDataCount<=this.maximumNumberOfFeatures?`snapshot`:`tiles`}get maxTotalSnapshotVertices(){let e=this._get(`maxTotalSnapshotVertices`)||0,t=this.mode===`snapshot`&&this._tileFetcher?.totalVertices||0;return Math.max(e,t)}_approximateExtentSizeAtScale(e,t){let n=this.layerView.view,r=Math.ceil((n.width/t.pixelSize+n.height/t.pixelSize)/2),i=t.levels[0];return r*((i.tileSize[0]/(i.scale/e)+i.tileSize[1]/(i.scale/e))/2)}get tileDescriptors(){if(this.mode===`snapshot`){let e=new E(0,0,0,null,D);return new r([e])}let e=this.layerView.view.featureTiles;if(!e)return new r;let t=e.tiles;if(this.layerView.displayFilterEnabled&&this.layerView.effectiveDisplayFilterClause!=null&&this.layerView.effectiveDisplayFilterClause!==`1=1`&&this.layerView.highlightIds?.length>0){let e=new E(0,0,0,this.layerView.view.featureTiles?.tilingScheme,O);return new r([...t,e])}return t}get test(){}constructor(e){super(e),this.type=`feature-tile-3d`,this._updatingHandles=new b,this.serviceDataExtent=null,this.serviceDataCount=I.noServiceDataCount,this._snapshotLimitExceeded=!1,this.displayFeatureLimit=null,this._forceTilesMode=!1,this._suspended=!1,this._tileFetcher=null,this._fetchDataInfoPromise=null,this._fetchDataInfoAbortController=null,this._lifeCycleAbortController=new AbortController}initialize(){this._updatingHandles.add(()=>this.displayFeatureLimit,e=>this._updatingHandles.addPromise(this._updateSnapshotLimit(e,null,this._lifeCycleAbortController.signal))),this._updatingHandles.add(()=>this.mode,()=>this._modeChanged(),p),this._updatingHandles.add(()=>this.mode,(e,t)=>{e===`tiles`&&t===`snapshot`&&(this._forceTilesMode=!0)},p),this.addResolvingPromise(Promise.resolve().then(()=>this._verifyCapabilities()).then(()=>this._updatingHandles.addPromise(this._fetchServiceDataInfo())).then(()=>this._initializeTileFetcher()))}_verifyCapabilities(){let e=this.layerView.layer;if(e.type!==`ogc-feature`&&!w(e)?.operations.supportsQuery)throw new i(`graphicscontroller:query-capability-required`,`Service requires query capabilities to be used as a feature layer`,{layer:e})}destroy(){this._cancelFetchServiceDataInfo(),this._tileFetcher=s(this._tileFetcher),this._tilesHandle=c(this._tilesHandle),this._lifeCycleAbortController=l(this._lifeCycleAbortController),this._updatingHandles.destroy(),this._set(`_updatingHandles`,null)}suspend(){this._suspended||(this._suspended=!0,this._tileFetcher!=null&&this._tileFetcher.suspend())}resume(){this._suspended&&(this._suspended=!1,this._tileFetcher!=null&&this._tileFetcher.resume())}restart(){let e=()=>{this._tileFetcher!=null&&this._tileFetcher.restart()};this._updatingHandles.consumePromise(this._fetchServiceDataInfo().then(e,e))}refetch(){this._refetch({resetForceTilesMode:!1})}getMissingAttributesForFeature(e){return this._tileFetcher?.getMissingAttributesForFeature(e)}_refetch(e){let t=()=>{this._tileFetcher!=null&&(e.resetForceTilesMode&&(this._forceTilesMode=!1),this._tileFetcher.refetch())};this._updatingHandles.consumePromise(this._fetchServiceDataInfo().then(t,t))}_initializeTileFetcher(){let e=this.layerView.view;if(!e)return;let{layerView:t,tileDescriptors:n}=this,r=t.layer,i=new k({context:this.context,filterExtent:this.extent,tileDescriptors:n,features:this.graphics});this._tileFetcher=i,this._suspended?i.suspend():i.resume(),e&&this.addHandles(m(()=>e.quality,e=>i.memoryFactor=e,h));let a=this.context.geometryType===`polygon`?`polygonLodFactor`:this.context.geometryType===`polyline`?`polylineLodFactor`:null;a&&this.addHandles(m(()=>this.layerView.view?.qualitySettings?.graphics3D?.[a],e=>i.lodFactor=e||1,p)),r.type!==`ogc-feature`&&this._updatingHandles.add(()=>r.createQueryVersion,()=>this._dataFilterChanged()),this._updatingHandles.add(()=>this.layerView.effectiveDisplayFilter,()=>this._effectiveDisplayFilterChanged()),this._updatingHandles.add(()=>this.layerView.highlightIds,()=>this._displayFilterHighlightIdsChanged()),this._updatingHandles.add(()=>t.availableFields,(e,t)=>this._availableFieldsChanged(t,e)),this._updatingHandles.add(()=>t.requiredFields,(e,t)=>this._requiredFieldsChanged(t,e)),`customParameters`in r&&this._updatingHandles.add(()=>r.customParameters,()=>this.restart()),this.addHandles([r.on(`apply-edits`,e=>this._applyEdits(e)),m(()=>this.extent,e=>i.filterExtent=e,g),m(()=>this.tileDescriptors,e=>i.tileDescriptors=e,g),m(()=>this.maximumNumberOfFeatures,e=>{i.maximumNumberOfFeatures=e,i.useTileCount=this.serviceDataCount>e},h),m(()=>this.serviceDataCount,e=>{i.useTileCount=e>this.maximumNumberOfFeatures},h),m(()=>({featureTiles:e.featureTiles,show:j.FEATURE_TILE_FETCH_SHOW_TILES}),({show:t,featureTiles:n})=>{t&&i&&n?i.debugger??=new A(i,n.tilingScheme.toTileInfo(),e):i.debugger=s(i.debugger)},p)]),this._supportsExceedsLimitQuery||this._updatingHandles.add(()=>this.maxTotalSnapshotVertices,()=>this._updatingHandles.addPromise(this._updateSnapshotLimit(this.displayFeatureLimit,null,this._lifeCycleAbortController.signal)))}_modeChanged(){switch(this.mode){case`tiles`:this._tilesHandle||=this.layerView.view.enableFeatureTiles();break;default:o.getLogger(this).warn(`Unhandled feature layer mode `+this.mode);case`snapshot`:this._tilesHandle!=null&&(this._tilesHandle.remove(),this._tilesHandle=null)}}_dataFilterChanged(){this._set(`maxTotalSnapshotVertices`,0),this.notifyChange(`maxTotalSnapshotVertices`),this._refetch({resetForceTilesMode:!0})}_effectiveDisplayFilterChanged(){this.mode!==`snapshot`&&this._refetch({resetForceTilesMode:!1})}_displayFilterHighlightIdsChanged(){this.mode!==`snapshot`&&this._tileFetcher!=null&&this._tileFetcher.refetchDisplayFilterHighlightTile()}_applyEdits(e){let t=this.layerView.layer;this._tileFetcher!=null&&this._tileFetcher.applyEdits(e).then(e=>{if(e){if(!this._lifeCycleAbortController)throw d();e.exceededTransferLimit&&`refresh`in t?t.refresh():(e.deletedFeatures.length||e.updatedFeatures.length||e.addedFeatures.length)&&this._updatingHandles.consumePromise(this._updateServiceDataExtent(this._lifeCycleAbortController.signal))}}).catch(e=>{if(!f(e))throw e})}_availableFieldsChanged(e,t){this._tileFetcher!=null&&F(this._tileFetcher.availableFields,t)&&this._refetch({resetForceTilesMode:!1})}_requiredFieldsChanged(e,t){this._tileFetcher!=null&&F(this._tileFetcher.availableFields,t)&&this.restart()}_createVertexLimitExceededQuery(e){let t=this.layerView.layer,n=t.createQuery();return n.returnGeometry=!1,n.outStatistics=[new T({statisticType:`exceedslimit`,maxVertexCount:e,outStatisticFieldName:`exceedslimit`,maxPointCount:1e8,maxRecordCount:1e8})],t.capabilities?.query.supportsCacheHint&&(n.cacheHint=!0),n}_createDataInfoQuery(){let e=this.layerView.layer,t=this.layerView,n=e.createQuery();return n.returnGeometry=!1,n.outSpatialReference=this.layerView.view.spatialReference,e.capabilities?.query.supportsCacheHint&&(n.cacheHint=!0),t.effectiveDisplayFilter&&(n.where=_(n.where,t.effectiveDisplayFilter.where)),n}_fullExtentIsAccurate(){let e=this.layerView.layer;if(`definitionExpression`in e&&e.definitionExpression)return!1;switch(e.type){case`feature`:case`catalog-footprint`:case`oriented-imagery`:return S(e.url);case`csv`:case`geojson`:case`ogc-feature`:case`wfs`:return!0;default:return}}async _updateServiceDataExtent(e){try{await this._tryUpdateServiceDataExtent(e)}catch(e){f(e)||this._set(`serviceDataExtent`,a(this.layerView.fullExtentInLocalViewSpatialReference)??null)}}async _tryUpdateServiceDataExtent(e){let t=this.layerView,n=t.layer,r=n.capabilities?.query.supportsExtent??!1,i=a(t.fullExtentInLocalViewSpatialReference),o=n.fullExtent,s=this._fullExtentIsAccurate(),c=this.serviceDataCount;if(r&&c<=I.maxFeatureCountForExtent&&(!i||!s)&&`queryExtent`in n){let t=this._createDataInfoQuery(),r=await n.queryExtent(t,{timeout:I.queryExtentTimeout,signal:e});this._set(`serviceDataExtent`,r.extent)}else if(i)this._set(`serviceDataExtent`,i);else if(o!=null){let e=o.spatialReference?await x(o,t.view.spatialReference):null;this._set(`serviceDataExtent`,e??null)}else this._set(`serviceDataExtent`,null)}async _updateServiceDataCount(e){let t=this.layerView.layer;if(!(`queryFeatureCount`in t)||!has(`featurelayer-snapshot-enabled`)){this._set(`serviceDataCount`,I.noServiceDataCount);return}let r=await n(t.queryFeatureCount(this._createDataInfoQuery(),{timeout:I.queryStatisticsTimeout,signal:e}));if(r.ok===!0)this._set(`serviceDataCount`,r.value);else{if(f(r.error))throw r.error;this._set(`serviceDataCount`,I.noServiceDataCount)}}get _supportsExceedsLimitQuery(){let e=this.layerView.layer;return e.capabilities!=null&&e.capabilities.operations&&e.capabilities.operations.supportsExceedsLimitStatistics}get _minimumNumberOfVerticesForGeometry(){switch(this.layerView.layer.geometryType){case`point`:return 1;case`multipoint`:return 1;case`polygon`:return 4;case`polyline`:return 2;case`multipatch`:case`mesh`:return 3;case null:case void 0:return 0;default:return 0}}async _updateSnapshotLimit(e,t,r){if(e?.averageSymbolComplexity==null){this._snapshotLimitExceeded=!1;return}let{maximumTotalNumberOfVertices:i,averageSymbolComplexity:a}=e,{verticesPerFeature:o,verticesPerCoordinate:s}=a,c=o<=0,l=this._minimumNumberOfVerticesForGeometry>1;if(!c&&!l){this._snapshotLimitExceeded=!1;return}o!==0&&t!=null&&await t;let u=Math.min(i,N),d=this.serviceDataCount,p=d!==I.noServiceDataCount,m=Math.ceil(p?(u-d*o)/(s||1):u/(s||1));if(l&&(m=Math.min(m,P)),p&&this._minimumNumberOfVerticesForGeometry*d>m){this._snapshotLimitExceeded=!0;return}if(!this._supportsExceedsLimitQuery||!has(`featurelayer-snapshot-enabled`)){this._snapshotLimitExceeded=this.maxTotalSnapshotVertices>m;return}let h=await n(this.layerView.layer.queryFeatures(this._createVertexLimitExceededQuery(m),{timeout:I.queryStatisticsTimeout,signal:r}));if(h.ok===!1){if(f(h.error))throw h.error;this._snapshotLimitExceeded=!1;return}let g=h.value.features[0];this._snapshotLimitExceeded=g?.attributes?!!g.attributes.exceedslimit:!1}async _fetchServiceDataInfo(){this._cancelFetchServiceDataInfo(),await C(this.layerView.layer);let e=new AbortController,t=e.signal,n=this._updateServiceDataCount(t),r=Promise.allSettled([n,this._updateSnapshotLimit(this.displayFeatureLimit,n,t)]),i=r.then(()=>this._updateServiceDataExtent(t)).catch(e=>{f(e)||o.getLogger(this).error(`#fetchServiceDataInfo()`,e)}).then(()=>{i===this._fetchDataInfoPromise&&(this._fetchDataInfoPromise=null,this._fetchDataInfoAbortController=null),e=null});return e&&(this._fetchDataInfoPromise=i),this._fetchDataInfoAbortController=e,r.then(()=>{},()=>{})}_cancelFetchServiceDataInfo(){let e=this._fetchDataInfoAbortController;e&&(this._fetchDataInfoAbortController=null,this._fetchDataInfoPromise=null,e.abort())}get performanceInfo(){return{storedFeatures:this._tileFetcher?.storedFeatures??0,totalFeatures:this._tileFetcher?.totalFeatures??0,totalVertices:this._tileFetcher?.totalVertices??0,missingTiles:this._tileFetcher?.missingTiles??0}}};e([v({readOnly:!0})],M.prototype,`type`,void 0),e([v({constructOnly:!0})],M.prototype,`graphics`,void 0),e([v({constructOnly:!0})],M.prototype,`layerView`,void 0),e([v({constructOnly:!0})],M.prototype,`context`,void 0),e([v({readOnly:!0})],M.prototype,`dataUpdating`,null),e([v()],M.prototype,`extent`,null),e([v()],M.prototype,`updating`,null),e([v({readOnly:!0})],M.prototype,`_updatingHandles`,void 0),e([v()],M.prototype,`updatingTotal`,null),e([v()],M.prototype,`updatingRemaining`,null),e([v()],M.prototype,`expectedFeatureDiff`,null),e([v()],M.prototype,`usedMemory`,null),e([v()],M.prototype,`usedMemoryPerFeature`,null),e([v()],M.prototype,`maximumNumberOfFeaturesExceeded`,null),e([v()],M.prototype,`snappingComplexityExceeded`,null),e([v({readOnly:!0})],M.prototype,`serviceDataExtent`,void 0),e([v({readOnly:!0})],M.prototype,`serviceDataCount`,void 0),e([v()],M.prototype,`_snapshotLimitExceeded`,void 0),e([v()],M.prototype,`displayFeatureLimit`,void 0),e([v({type:Number})],M.prototype,`maximumNumberOfFeatures`,null),e([v({readOnly:!0})],M.prototype,`hasAllFeatures`,null),e([v({readOnly:!0})],M.prototype,`hasAllFeaturesInView`,null),e([v({readOnly:!0})],M.prototype,`hasFullGeometries`,null),e([v()],M.prototype,`_forceTilesMode`,void 0),e([v({readOnly:!0})],M.prototype,`mode`,null),e([v({readOnly:!0})],M.prototype,`maxTotalSnapshotVertices`,null),e([v({readOnly:!0})],M.prototype,`tileDescriptors`,null),e([v()],M.prototype,`_tileFetcher`,void 0),e([v()],M.prototype,`_fetchDataInfoPromise`,void 0),M=e([y(`esri.layers.graphics.controllers.FeatureTileController3D`)],M);const N=1e6,P=5e6;function F(e,t){if(!t)return!1;for(let n of t)if(!e.has(n))return!0;return!1}class I{static{this.noServiceDataCount=1/0}static{this.maxSnapshotMinScaleFactor=5}static reset(){I.maxFeatureCountForExtent=1e4,I.queryStatisticsTimeout=12e3,I.queryExtentTimeout=1e4}}I.reset();export{M as FeatureTileController3D,I as FeatureTileController3DConstants};
2
+ import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import{result as n}from"../../../core/asyncUtils.js";import r from"../../../core/Collection.js";import i from"../../../core/Error.js";import has from"../../../core/has.js";import{clone as a}from"../../../core/lang.js";import o from"../../../core/Logger.js";import{destroyMaybe as s,removeMaybe as c,abortMaybe as l}from"../../../core/maybe.js";import{EsriPromiseMixin as u}from"../../../core/Promise.js";import{createAbortError as d,isAbortError as f}from"../../../core/promiseUtils.js";import{initial as p,watch as m,syncAndInitial as h,sync as g}from"../../../core/reactiveUtils.js";import{sqlAnd as _}from"../../../core/sql.js";import{property as v,subclass as y}from"../../../core/accessorSupport/decorators.js";import{UpdatingHandles as b}from"../../../core/support/UpdatingHandles.js";import{projectAsync as x}from"../../../geometry/projectionUtils.js";import{isHostedAgolService as S}from"../../support/arcgisLayerUrl.js";import{checkServiceCurrentUserSupport as C}from"../../support/featureLayerUtils.js";import{getEffectiveLayerCapabilities as w}from"../../support/layerUtils.js";import T from"../../../rest/support/StatisticDefinition.js";import{FeatureTileDescriptor as E,virtualSnapshotTileId as D,virtualDisplayFilterHighlightTileId as O}from"../../../views/3d/layers/support/FeatureTileDescriptor.js";import{FeatureTileFetcher3D as k}from"../../../views/3d/layers/support/FeatureTileFetcher3D.js";import{FeatureTileFetcher3DDebugger as A}from"../../../views/3d/layers/support/FeatureTileFetcher3DDebugger.js";import{debugFlags as j}from"../../../views/3d/support/debugFlags.js";let M=class extends u(t){get dataUpdating(){return this._tileFetcher?.dataUpdating??!1}set extent(e){if(e!=null&&!e.spatialReference.equals(this.layerView.view.spatialReference)){o.getLogger(this).error(`#extent=`,`extent needs to be in the same spatial reference as the view`);return}let t=this._get(`extent`);if(t===e||t!=null&&e&&t.equals(e))return;let n=e==null?null:e.clone();this._set(`extent`,n)}get updating(){return!!(this._tileFetcher?.updating||this._fetchDataInfoPromise!=null||this.mode===`tiles`&&this.layerView.view.featureTiles?.updating||this._updatingHandles?.updating)}get updatingTotal(){return this.updating&&this._tileFetcher!=null?this._tileFetcher.updatingTotal:0}get updatingRemaining(){return this.updating&&this._tileFetcher!=null?this._tileFetcher.updatingRemaining:0}get expectedFeatureDiff(){return this.updating&&this._tileFetcher!=null?this._tileFetcher.expectedFeatureDiff:0}get usedMemory(){return this._tileFetcher?.usedMemory??0}get usedMemoryPerFeature(){return this._tileFetcher?.usedMemoryPerFeature??0}get maximumNumberOfFeaturesExceeded(){return!!(this._tileFetcher!=null&&this._tileFetcher.maximumNumberOfFeaturesExceeded)}get snappingComplexityExceeded(){return this._tileFetcher?.snappingComplexityExceeded??!0}get maximumNumberOfFeatures(){return this.displayFeatureLimit?.maximumNumberOfFeatures??0}set maximumNumberOfFeatures(e){e!==this.maximumNumberOfFeatures&&this._overrideIfSome(`maximumNumberOfFeatures`,e)}get hasMaximumNumberOfFeaturesOverride(){return this._isOverridden(`maximumNumberOfFeatures`)}get hasAllFeatures(){return this.serviceDataCount===I.noServiceDataCount&&this.mode===`snapshot`&&this.hasAllFeaturesInView||this.serviceDataCount===this.graphics.length}get hasAllFeaturesInView(){let e=this.context.effectiveDisplayFilter?.where||null,t=e!=null&&e!==`1=1`;return this.mode===`tiles`&&t?!1:this._tileFetcher?.showsAllFeatures??!1}get hasFullGeometries(){return this._tileFetcher?.hasFullGeometries??!1}get mode(){let e=this.layerView.layer;if(e.type===`feature`&&e.infoFor3D!=null)return`snapshot`;if(e.type===`catalog-footprint`||this._forceTilesMode)return`tiles`;let t=this.layerView.view;if(t.qualitySettings?.graphics3D?.snapshotAvailable===!1||this.serviceDataCount===I.noServiceDataCount||this._snapshotLimitExceeded||this.maximumNumberOfFeaturesExceeded||t.quality<1)return`tiles`;let n=(t&&t.featureTiles)?.tilingScheme;if(e&&e.minScale&&this.serviceDataExtent&&n){let t=this._approximateExtentSizeAtScale(e.minScale,n);if((this.serviceDataExtent.width/t+this.serviceDataExtent.height/t)/2>I.maxSnapshotMinScaleFactor)return`tiles`}return!this.maximumNumberOfFeatures||this.serviceDataCount<=this.maximumNumberOfFeatures?`snapshot`:`tiles`}get maxTotalSnapshotVertices(){let e=this._get(`maxTotalSnapshotVertices`)||0,t=this.mode===`snapshot`&&this._tileFetcher?.totalVertices||0;return Math.max(e,t)}_approximateExtentSizeAtScale(e,t){let n=this.layerView.view,r=Math.ceil((n.width/t.pixelSize+n.height/t.pixelSize)/2),i=t.levels[0];return r*((i.tileSize[0]/(i.scale/e)+i.tileSize[1]/(i.scale/e))/2)}get tileDescriptors(){if(this.mode===`snapshot`){let e=new E(0,0,0,null,D);return new r([e])}let e=this.layerView.view.featureTiles;if(!e)return new r;let t=e.tiles;if(this.layerView.displayFilterEnabled&&this.layerView.effectiveDisplayFilterClause!=null&&this.layerView.effectiveDisplayFilterClause!==`1=1`&&this.layerView.highlightIds?.length>0){let e=new E(0,0,0,this.layerView.view.featureTiles?.tilingScheme,O);return new r([...t,e])}return t}get test(){}constructor(e){super(e),this.type=`feature-tile-3d`,this._updatingHandles=new b,this.serviceDataExtent=null,this.serviceDataCount=I.noServiceDataCount,this._snapshotLimitExceeded=!1,this.displayFeatureLimit=null,this._forceTilesMode=!1,this._suspended=!1,this._tileFetcher=null,this._fetchDataInfoPromise=null,this._fetchDataInfoAbortController=null,this._lifeCycleAbortController=new AbortController}initialize(){this._updatingHandles.add(()=>this.displayFeatureLimit,e=>this._updatingHandles.addPromise(this._updateSnapshotLimit(e,null,this._lifeCycleAbortController.signal))),this._updatingHandles.add(()=>this.mode,()=>this._modeChanged(),p),this._updatingHandles.add(()=>this.mode,(e,t)=>{e===`tiles`&&t===`snapshot`&&(this._forceTilesMode=!0)},p),this.addResolvingPromise(Promise.resolve().then(()=>this._verifyCapabilities()).then(()=>this._updatingHandles.addPromise(this._fetchServiceDataInfo())).then(()=>this._initializeTileFetcher()))}_verifyCapabilities(){let e=this.layerView.layer;if(e.type!==`ogc-feature`&&!w(e)?.operations.supportsQuery)throw new i(`graphicscontroller:query-capability-required`,`Service requires query capabilities to be used as a feature layer`,{layer:e})}destroy(){this._cancelFetchServiceDataInfo(),this._tileFetcher=s(this._tileFetcher),this._tilesHandle=c(this._tilesHandle),this._lifeCycleAbortController=l(this._lifeCycleAbortController),this._updatingHandles.destroy(),this._set(`_updatingHandles`,null)}suspend(){this._suspended||(this._suspended=!0,this._tileFetcher!=null&&this._tileFetcher.suspend())}resume(){this._suspended&&(this._suspended=!1,this._tileFetcher!=null&&this._tileFetcher.resume())}restart(){let e=()=>{this._tileFetcher!=null&&this._tileFetcher.restart()};this._updatingHandles.consumePromise(this._fetchServiceDataInfo().then(e,e))}refetch(){this._refetch({resetForceTilesMode:!1})}getMissingAttributesForFeature(e){return this._tileFetcher?.getMissingAttributesForFeature(e)}_refetch(e){let t=()=>{this._tileFetcher!=null&&(e.resetForceTilesMode&&(this._forceTilesMode=!1),this._tileFetcher.refetch())};this._updatingHandles.consumePromise(this._fetchServiceDataInfo().then(t,t))}_initializeTileFetcher(){let e=this.layerView.view;if(!e)return;let{layerView:t,tileDescriptors:n}=this,r=t.layer,i=new k({context:this.context,filterExtent:this.extent,tileDescriptors:n,features:this.graphics});this._tileFetcher=i,this._suspended?i.suspend():i.resume(),e&&this.addHandles(m(()=>e.quality,e=>i.memoryFactor=e,h));let a=this.context.geometryType===`polygon`?`polygonLodFactor`:this.context.geometryType===`polyline`?`polylineLodFactor`:null;a&&this.addHandles(m(()=>this.layerView.view?.qualitySettings?.graphics3D?.[a],e=>i.lodFactor=e||1,p)),r.type!==`ogc-feature`&&this._updatingHandles.add(()=>r.createQueryVersion,()=>this._dataFilterChanged()),this._updatingHandles.add(()=>this.layerView.effectiveDisplayFilter,()=>this._effectiveDisplayFilterChanged()),this._updatingHandles.add(()=>this.layerView.highlightIds,()=>this._displayFilterHighlightIdsChanged()),this._updatingHandles.add(()=>t.availableFields,(e,t)=>this._availableFieldsChanged(t,e)),this._updatingHandles.add(()=>t.requiredFields,(e,t)=>this._requiredFieldsChanged(t,e)),`customParameters`in r&&this._updatingHandles.add(()=>r.customParameters,()=>this.restart()),this.addHandles([r.on(`apply-edits`,e=>this._applyEdits(e)),m(()=>this.extent,e=>i.filterExtent=e,g),m(()=>this.tileDescriptors,e=>i.tileDescriptors=e,g),m(()=>this.maximumNumberOfFeatures,e=>{i.maximumNumberOfFeatures=e,i.useTileCount=this.serviceDataCount>e},h),m(()=>this.serviceDataCount,e=>{i.useTileCount=e>this.maximumNumberOfFeatures},h),m(()=>({featureTiles:e.featureTiles,show:j.FEATURE_TILE_FETCH_SHOW_TILES}),({show:t,featureTiles:n})=>{t&&i&&n?i.debugger??=new A(i,n.tilingScheme.toTileInfo(),e):i.debugger=s(i.debugger)},p)]),this._supportsExceedsLimitQuery||this._updatingHandles.add(()=>this.maxTotalSnapshotVertices,()=>this._updatingHandles.addPromise(this._updateSnapshotLimit(this.displayFeatureLimit,null,this._lifeCycleAbortController.signal)))}_modeChanged(){switch(this.mode){case`tiles`:this._tilesHandle||=this.layerView.view.enableFeatureTiles();break;default:o.getLogger(this).warn(`Unhandled feature layer mode `+this.mode);case`snapshot`:this._tilesHandle!=null&&(this._tilesHandle.remove(),this._tilesHandle=null)}}_dataFilterChanged(){this._set(`maxTotalSnapshotVertices`,0),this.notifyChange(`maxTotalSnapshotVertices`),this._refetch({resetForceTilesMode:!0})}_effectiveDisplayFilterChanged(){this.mode!==`snapshot`&&this._refetch({resetForceTilesMode:!1})}_displayFilterHighlightIdsChanged(){this.mode!==`snapshot`&&this._tileFetcher!=null&&this._tileFetcher.refetchDisplayFilterHighlightTile()}_applyEdits(e){let t=this.layerView.layer;this._tileFetcher!=null&&this._tileFetcher.applyEdits(e).then(e=>{if(e){if(!this._lifeCycleAbortController)throw d();e.exceededTransferLimit&&`refresh`in t?t.refresh():(e.deletedFeatures.length||e.updatedFeatures.length||e.addedFeatures.length)&&this._updatingHandles.consumePromise(this._updateServiceDataExtent(this._lifeCycleAbortController.signal))}}).catch(e=>{if(!f(e))throw e})}_availableFieldsChanged(e,t){this._tileFetcher!=null&&F(this._tileFetcher.availableFields,t)&&this._refetch({resetForceTilesMode:!1})}_requiredFieldsChanged(e,t){this._tileFetcher!=null&&F(this._tileFetcher.availableFields,t)&&this.restart()}_createVertexLimitExceededQuery(e){let t=this.layerView.layer,n=t.createQuery();return n.returnGeometry=!1,n.outStatistics=[new T({statisticType:`exceedslimit`,maxVertexCount:e,outStatisticFieldName:`exceedslimit`,maxPointCount:1e8,maxRecordCount:1e8})],t.capabilities?.query.supportsCacheHint&&(n.cacheHint=!0),n}_createDataInfoQuery(){let e=this.layerView.layer,t=this.layerView,n=e.createQuery();return n.returnGeometry=!1,n.outSpatialReference=this.layerView.view.spatialReference,e.capabilities?.query.supportsCacheHint&&(n.cacheHint=!0),t.effectiveDisplayFilter&&(n.where=_(n.where,t.effectiveDisplayFilter.where)),n}_fullExtentIsAccurate(){let e=this.layerView.layer;if(`definitionExpression`in e&&e.definitionExpression)return!1;switch(e.type){case`feature`:case`catalog-footprint`:case`oriented-imagery`:return S(e.url);case`csv`:case`geojson`:case`ogc-feature`:case`wfs`:return!0;default:return}}async _updateServiceDataExtent(e){try{await this._tryUpdateServiceDataExtent(e)}catch(e){f(e)||this._set(`serviceDataExtent`,a(this.layerView.fullExtentInLocalViewSpatialReference)??null)}}async _tryUpdateServiceDataExtent(e){let t=this.layerView,n=t.layer,r=n.capabilities?.query.supportsExtent??!1,i=a(t.fullExtentInLocalViewSpatialReference),o=n.fullExtent,s=this._fullExtentIsAccurate(),c=this.serviceDataCount;if(r&&c<=I.maxFeatureCountForExtent&&(!i||!s)&&`queryExtent`in n){let t=this._createDataInfoQuery(),r=await n.queryExtent(t,{timeout:I.queryExtentTimeout,signal:e});this._set(`serviceDataExtent`,r.extent)}else if(i)this._set(`serviceDataExtent`,i);else if(o!=null){let e=o.spatialReference?await x(o,t.view.spatialReference):null;this._set(`serviceDataExtent`,e??null)}else this._set(`serviceDataExtent`,null)}async _updateServiceDataCount(e){let t=this.layerView.layer;if(!(`queryFeatureCount`in t)||!has(`featurelayer-snapshot-enabled`)){this._set(`serviceDataCount`,I.noServiceDataCount);return}let r=await n(t.queryFeatureCount(this._createDataInfoQuery(),{timeout:I.queryStatisticsTimeout,signal:e}));if(r.ok===!0)this._set(`serviceDataCount`,r.value);else{if(f(r.error))throw r.error;this._set(`serviceDataCount`,I.noServiceDataCount)}}get _supportsExceedsLimitQuery(){let e=this.layerView.layer;return e.capabilities!=null&&e.capabilities.operations&&e.capabilities.operations.supportsExceedsLimitStatistics}get _minimumNumberOfVerticesForGeometry(){switch(this.layerView.layer.geometryType){case`point`:return 1;case`multipoint`:return 1;case`polygon`:return 4;case`polyline`:return 2;case`multipatch`:case`mesh`:return 3;case null:case void 0:return 0;default:return 0}}async _updateSnapshotLimit(e,t,r){if(e?.averageSymbolComplexity==null){this._snapshotLimitExceeded=!1;return}let{maximumTotalNumberOfVertices:i,averageSymbolComplexity:a}=e,{verticesPerFeature:o,verticesPerCoordinate:s}=a,c=o<=0,l=this._minimumNumberOfVerticesForGeometry>1;if(!c&&!l){this._snapshotLimitExceeded=!1;return}o!==0&&t!=null&&await t;let u=Math.min(i,N),d=this.serviceDataCount,p=d!==I.noServiceDataCount,m=Math.ceil(p?(u-d*o)/(s||1):u/(s||1));if(l&&(m=Math.min(m,P)),p&&this._minimumNumberOfVerticesForGeometry*d>m){this._snapshotLimitExceeded=!0;return}if(!this._supportsExceedsLimitQuery||!has(`featurelayer-snapshot-enabled`)){this._snapshotLimitExceeded=this.maxTotalSnapshotVertices>m;return}let h=await n(this.layerView.layer.queryFeatures(this._createVertexLimitExceededQuery(m),{timeout:I.queryStatisticsTimeout,signal:r}));if(h.ok===!1){if(f(h.error))throw h.error;this._snapshotLimitExceeded=!1;return}let g=h.value.features[0];this._snapshotLimitExceeded=g?.attributes?!!g.attributes.exceedslimit:!1}async _fetchServiceDataInfo(){this._cancelFetchServiceDataInfo(),await C(this.layerView.layer);let e=new AbortController,t=e.signal,n=this._updateServiceDataCount(t),r=Promise.allSettled([n,this._updateSnapshotLimit(this.displayFeatureLimit,n,t)]),i=r.then(()=>this._updateServiceDataExtent(t)).catch(e=>{f(e)||o.getLogger(this).error(`#fetchServiceDataInfo()`,e)}).then(()=>{i===this._fetchDataInfoPromise&&(this._fetchDataInfoPromise=null,this._fetchDataInfoAbortController=null),e=null});return e&&(this._fetchDataInfoPromise=i),this._fetchDataInfoAbortController=e,r.then(()=>{},()=>{})}_cancelFetchServiceDataInfo(){let e=this._fetchDataInfoAbortController;e&&(this._fetchDataInfoAbortController=null,this._fetchDataInfoPromise=null,e.abort())}get performanceInfo(){return{storedFeatures:this._tileFetcher?.storedFeatures??0,totalFeatures:this._tileFetcher?.totalFeatures??0,totalVertices:this._tileFetcher?.totalVertices??0,missingTiles:this._tileFetcher?.missingTiles??0}}};e([v({readOnly:!0})],M.prototype,`type`,void 0),e([v({constructOnly:!0})],M.prototype,`graphics`,void 0),e([v({constructOnly:!0})],M.prototype,`layerView`,void 0),e([v({constructOnly:!0})],M.prototype,`context`,void 0),e([v({readOnly:!0})],M.prototype,`dataUpdating`,null),e([v()],M.prototype,`extent`,null),e([v()],M.prototype,`updating`,null),e([v({readOnly:!0})],M.prototype,`_updatingHandles`,void 0),e([v()],M.prototype,`updatingTotal`,null),e([v()],M.prototype,`updatingRemaining`,null),e([v()],M.prototype,`expectedFeatureDiff`,null),e([v()],M.prototype,`usedMemory`,null),e([v()],M.prototype,`usedMemoryPerFeature`,null),e([v()],M.prototype,`maximumNumberOfFeaturesExceeded`,null),e([v()],M.prototype,`snappingComplexityExceeded`,null),e([v({readOnly:!0})],M.prototype,`serviceDataExtent`,void 0),e([v({readOnly:!0})],M.prototype,`serviceDataCount`,void 0),e([v()],M.prototype,`_snapshotLimitExceeded`,void 0),e([v()],M.prototype,`displayFeatureLimit`,void 0),e([v({type:Number})],M.prototype,`maximumNumberOfFeatures`,null),e([v({readOnly:!0})],M.prototype,`hasAllFeatures`,null),e([v({readOnly:!0})],M.prototype,`hasAllFeaturesInView`,null),e([v({readOnly:!0})],M.prototype,`hasFullGeometries`,null),e([v()],M.prototype,`_forceTilesMode`,void 0),e([v({readOnly:!0})],M.prototype,`mode`,null),e([v({readOnly:!0})],M.prototype,`maxTotalSnapshotVertices`,null),e([v({readOnly:!0})],M.prototype,`tileDescriptors`,null),e([v()],M.prototype,`_tileFetcher`,void 0),e([v()],M.prototype,`_fetchDataInfoPromise`,void 0),M=e([y(`esri.layers.graphics.controllers.FeatureTileController3D`)],M);const N=has(`esri-tests-maximum-vertices-for-snapshot`)??1e6,P=5e6;function F(e,t){if(!t)return!1;for(let n of t)if(!e.has(n))return!0;return!1}class I{static{this.noServiceDataCount=1/0}static{this.maxSnapshotMinScaleFactor=5}static reset(){I.maxFeatureCountForExtent=1e4,I.queryStatisticsTimeout=12e3,I.queryExtentTimeout=1e4}}I.reset();export{M as FeatureTileController3D,I as FeatureTileController3DConstants};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../../core/Error.js";import has from"../../../core/has.js";import{Loadable as n}from"../../../core/Loadable.js";import r from"../../../core/Logger.js";import{debounce as i}from"../../../core/promiseUtils.js";import{open as a}from"../../../core/workers.js";import{property as o,subclass as s}from"../../../core/accessorSupport/decorators.js";import c from"../../../geometry/Extent.js";import l from"../../../geometry/Polygon.js";import{featureGeometryTypeKebabDictionary as u}from"../../../geometry/support/typeUtils.js";import{createCapabilities as d}from"./support/clientSideDefaults.js";import f from"../../../rest/support/FeatureSet.js";let p=class extends n{constructor(){super(...arguments),this.type=`geojson`,this.refresh=i(async e=>{await this.load();let{extent:t,timeExtent:n}=await this._connection.invoke(`refresh`,e);return this.sourceJSON.extent=t,n&&(this.sourceJSON.timeInfo.timeExtent=[n.start,n.end]),{dataChanged:!0,updates:{extent:this.sourceJSON.extent,timeInfo:this.sourceJSON.timeInfo}}})}load(e){let t=e==null?null:e.signal;return this.addResolvingPromise(this._startWorker(t)),Promise.resolve(this)}destroy(){this._connection?.close(),this._connection=null}applyEdits(e){return this.load().then(()=>this._applyEdits(e))}openPorts(){return this.load().then(()=>this._connection.openPorts())}queryFeatures(e,t={}){return this.load(t).then(()=>this._connection.invoke(`queryFeatures`,e?e.toJSON():null,t)).then(e=>f.fromJSON(e))}queryFeaturesJSON(e,t={}){return this.load(t).then(()=>this._connection.invoke(`queryFeatures`,e?e.toJSON():null,t))}queryFeatureCount(e,t={}){return this.load(t).then(()=>this._connection.invoke(`queryFeatureCount`,e?e.toJSON():null,t))}queryObjectIds(e,t={}){return this.load(t).then(()=>this._connection.invoke(`queryObjectIds`,e?e.toJSON():null,t))}queryExtent(e,t={}){return this.load(t).then(()=>this._connection.invoke(`queryExtent`,e?e.toJSON():null,t)).then(e=>({count:e.count,extent:c.fromJSON(e.extent)}))}querySnapping(e,t={}){return this.load(t).then(()=>this._connection.invoke(`querySnapping`,e,t))}async queryAttributeBins(e,t={}){return await this.load(),this._connection.invoke(`queryAttributeBins`,e?.toJSON(),t)}_applyEdits(e){if(!this._connection)throw new t(`geojson-layer-source:edit-failure`,`Memory source not loaded`);let n=this.layer.objectIdField,r=[],i=[],a=[];if(e.addFeatures)for(let t of e.addFeatures)r.push(this._serializeFeature(t));if(e.deleteFeatures)for(let t of e.deleteFeatures)`objectId`in t&&t.objectId!=null?i.push(t.objectId):`attributes`in t&&t.attributes[n]!=null&&i.push(t.attributes[n]);if(e.updateFeatures)for(let t of e.updateFeatures)a.push(this._serializeFeature(t));return this._connection.invoke(`applyEdits`,{adds:r,updates:a,deletes:i}).then(({extent:e,timeExtent:t,featureEditResults:n})=>(this.sourceJSON.extent=e,t&&(this.sourceJSON.timeInfo.timeExtent=[t.start,t.end]),this._createEditsResult(n)))}_createEditsResult(e){return{addFeatureResults:e.addResults?e.addResults.map(this._createFeatureEditResult,this):[],updateFeatureResults:e.updateResults?e.updateResults.map(this._createFeatureEditResult,this):[],deleteFeatureResults:e.deleteResults?e.deleteResults.map(this._createFeatureEditResult,this):[],addAttachmentResults:[],updateAttachmentResults:[],deleteAttachmentResults:[]}}_createFeatureEditResult(e){let n=e.success===!0?null:e.error||{code:void 0,description:``};return{objectId:e.objectId,globalId:e.globalId,error:n?new t(`geojson-layer-source:edit-failure`,n.description,{code:n.code}):null}}_serializeFeature(e){let{attributes:t}=e,n=this._geometryForSerialization(e);return n?{geometry:n.toJSON(),attributes:t}:{attributes:t}}_geometryForSerialization(e){let{geometry:t}=e;return t==null?null:t.type===`mesh`||t.type===`extent`?l.fromExtent(t.extent):t}async _startWorker(e){this._connection=await a(`GeoJSONSourceWorker`,{strategy:has(`feature-layers-workers`)?`dedicated`:`local`,signal:e,registryTarget:this});let{fields:t,spatialReference:n,hasZ:i,geometryType:o,objectIdField:s,url:c,timeInfo:l,customParameters:f}=this.layer,p=this.layer.originOf(`spatialReference`)===`defaults`,m={url:c,customParameters:f,fields:t&&t.map(e=>e.toJSON()),geometryType:u.toJSON(o),hasZ:i,objectIdField:s,timeInfo:l?l.toJSON():null,spatialReference:p?null:n&&n.toJSON()},h=await this._connection.invoke(`load`,m,{signal:e});for(let e of h.warnings)r.getLogger(this.layer).warn(`#load()`,`${e.message} (title: '${this.layer.title||`no title`}', id: '${this.layer.id??`no id`}')`,{warning:e});h.featureErrors.length&&r.getLogger(this.layer).warn(`#load()`,`Encountered ${h.featureErrors.length} validation errors while loading features. (title: '${this.layer.title||`no title`}', id: '${this.layer.id??`no id`}')`,{errors:h.featureErrors}),this.sourceJSON=h.layerDefinition,this.capabilities=d(this.sourceJSON.hasZ,!0)}};e([o()],p.prototype,`capabilities`,void 0),e([o()],p.prototype,`type`,void 0),e([o({constructOnly:!0})],p.prototype,`layer`,void 0),e([o()],p.prototype,`sourceJSON`,void 0),p=e([s(`esri.layers.graphics.sources.GeoJSONSource`)],p);export{p as GeoJSONSource};
2
+ import{__decorate as e}from"tslib";import t from"../../../core/Error.js";import has from"../../../core/has.js";import{Loadable as n}from"../../../core/Loadable.js";import r from"../../../core/Logger.js";import{debounce as i}from"../../../core/promiseUtils.js";import{open as a}from"../../../core/workers.js";import{property as o,subclass as s}from"../../../core/accessorSupport/decorators.js";import c from"../../../geometry/Extent.js";import l from"../../../geometry/Polygon.js";import{featureGeometryTypeKebabDictionary as u}from"../../../geometry/support/typeUtils.js";import{createCapabilities as d}from"./support/clientSideDefaults.js";import f from"../../../rest/support/FeatureSet.js";let p=class extends n{constructor(){super(...arguments),this.type=`geojson`,this.refresh=i(async e=>{await this.load();let{extent:t,timeExtent:n}=await this._connection.invoke(`refresh`,e);return this.sourceJSON.extent=t,n&&(this.sourceJSON.timeInfo.timeExtent=[n.start,n.end]),{dataChanged:!0,updates:{extent:this.sourceJSON.extent,timeInfo:this.sourceJSON.timeInfo}}})}load(e){let t=e==null?null:e.signal;return this.addResolvingPromise(this._startWorker(t)),Promise.resolve(this)}destroy(){this._connection?.close(),this._connection=null}applyEdits(e){return this.load().then(()=>this._applyEdits(e))}openPorts(){return this.load().then(()=>this._connection.openPorts())}queryFeatures(e,t={}){return this.load(t).then(()=>this._connection.invoke(`queryFeatures`,e?e.toJSON():null,t)).then(e=>f.fromJSON(e))}queryFeaturesJSON(e,t={}){return this.load(t).then(()=>this._connection.invoke(`queryFeatures`,e?e.toJSON():null,t))}queryFeatureCount(e,t={}){return this.load(t).then(()=>this._connection.invoke(`queryFeatureCount`,e?e.toJSON():null,t))}queryObjectIds(e,t={}){return this.load(t).then(()=>this._connection.invoke(`queryObjectIds`,e?e.toJSON():null,t))}queryExtent(e,t={}){return this.load(t).then(()=>this._connection.invoke(`queryExtent`,e?e.toJSON():null,t)).then(e=>({count:e.count,extent:c.fromJSON(e.extent)}))}querySnapping(e,t={}){return this.load(t).then(()=>this._connection.invoke(`querySnapping`,e,t))}async queryAttributeBins(e,t={}){return await this.load(),this._connection.invoke(`queryAttributeBins`,e?.toJSON(),t)}_applyEdits(e){if(!this._connection)throw new t(`geojson-layer-source:edit-failure`,`Memory source not loaded`);let n=this.layer.objectIdField,r=[],i=[],a=[];if(e.addFeatures)for(let t of e.addFeatures)r.push(this._serializeFeature(t));if(e.deleteFeatures)for(let t of e.deleteFeatures)`objectId`in t&&t.objectId!=null?i.push(t.objectId):`attributes`in t&&t.attributes[n]!=null&&i.push(t.attributes[n]);if(e.updateFeatures)for(let t of e.updateFeatures)a.push(this._serializeFeature(t));return this._connection.invoke(`applyEdits`,{adds:r,updates:a,deletes:i}).then(({extent:e,timeExtent:t,featureEditResults:n})=>(this.sourceJSON.extent=e,t&&(this.sourceJSON.timeInfo.timeExtent=[t.start,t.end]),this._createEditsResult(n)))}_createEditsResult(e){return{addFeatureResults:e.addResults?e.addResults.map(this._createFeatureEditResult,this):[],updateFeatureResults:e.updateResults?e.updateResults.map(this._createFeatureEditResult,this):[],deleteFeatureResults:e.deleteResults?e.deleteResults.map(this._createFeatureEditResult,this):[],addAttachmentResults:[],updateAttachmentResults:[],deleteAttachmentResults:[]}}_createFeatureEditResult(e){let n=e.success===!0?null:e.error||{code:void 0,description:``};return{objectId:e.objectId,globalId:e.globalId,error:n?new t(`geojson-layer-source:edit-failure`,n.description,{code:n.code}):null}}_serializeFeature(e){let{attributes:t}=e,n=this._geometryForSerialization(e);return n?{geometry:n.toJSON(),attributes:t}:{attributes:t}}_geometryForSerialization(e){let{geometry:t}=e;return t==null?null:t.type===`mesh`||t.type===`extent`?l.fromExtent(t.extent):t}async _startWorker(e){this._connection=await a(`GeoJSONSourceWorker`,{strategy:has(`feature-layers-workers`)?`dedicated`:`local`,signal:e,registryTarget:this});let{fields:t,spatialReference:n,hasZ:i,geometryType:o,objectIdField:s,url:c,timeInfo:l,customParameters:f}=this.layer,p=this.layer.originOf(`spatialReference`)===`defaults`,m={url:c,customParameters:f,fields:t&&t.map(e=>e.toJSON()),geometryType:u.toJSON(o),hasZ:i,objectIdField:s,timeInfo:l?l.toJSON():null,spatialReference:p?null:n&&n.toJSON()},h=await this._connection.invoke(`load`,m,{signal:e});for(let e of h.warnings)r.getLogger(this.layer).warn(`#load()`,`${e.message} (title: '${this.layer.title||`no title`}', id: '${this.layer.id??`no id`}')`,{warning:e});h.featureErrors.length&&r.getLogger(this.layer).warn(`#load()`,`Encountered ${h.featureErrors.length} validation errors while loading features. (title: '${this.layer.title||`no title`}', id: '${this.layer.id??`no id`}')`,{errors:h.featureErrors}),this.sourceJSON=h.layerDefinition,this.capabilities=d(this.sourceJSON.hasZ,!0,!this.sourceJSON.geometryType)}};e([o()],p.prototype,`capabilities`,void 0),e([o()],p.prototype,`type`,void 0),e([o({constructOnly:!0})],p.prototype,`layer`,void 0),e([o()],p.prototype,`sourceJSON`,void 0),p=e([s(`esri.layers.graphics.sources.GeoJSONSource`)],p);export{p as GeoJSONSource};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import e from"../../../../request.js";import{createTask as t}from"../../../../core/asyncUtils.js";import n from"../../../../core/Error.js";import r from"../../../../core/Logger.js";import{isAbortError as i}from"../../../../core/promiseUtils.js";import{getJsonType as a}from"../../../../geometry/support/jsonTypeUtils.js";import{wgs84 as o,equals as s}from"../../../../geometry/support/spatialReferenceUtils.js";import{convertFromGeometry as c,convertToGeometry as l,convertFromFeatures as u,convertToFeature as d,convertFromFeature as f}from"../../featureConversionUtils.js";import p from"../../data/FeatureStore.js";import{checkProjectionSupport as m,project as h}from"../../data/projectionSupport.js";import{QueryEngine as g}from"../../data/QueryEngine.js";import{inferLayerProperties as _,createOptimizedFeatures as v,validateGeoJSON as y}from"./geojson.js";import{createDefaultTemplate as b,createDefaultAttributesFunction as x,createDrawingInfo as S}from"../support/clientSideDefaults.js";import{queryBinsCapabilities as C,loadGeometryEngineForSimplify as w,mixAttributes as T,createFeatureEditSuccessResult as E,createFeatureEditErrorResult as D,simplify as O}from"../support/sourceUtils.js";import k from"../../../support/FieldsIndex.js";import{kebabDict as A}from"../../../support/fieldType.js";import{getFieldDefaultValue as j,getFieldDefaultLength as M}from"../../../support/fieldUtils.js";import{utc as N}from"../../../../time/constants.js";const P={hasAttachments:!1,capabilities:`query, editing, create, delete, update`,useStandardizedQueries:!0,supportsCoordinatesQuantization:!0,supportsReturningQueryGeometry:!0,advancedQueryCapabilities:{supportsQueryAttachments:!1,supportsQueryAttachmentsCountOnly:!1,supportsQueryAttachmentOrderByFields:!1,supportsQueryAttachmentWithTypeWildcard:!1,supportsQueryBins:!0,supportsQueryPivot:!1,supportsQueryWithCacheHint:!0,supportsQueryWithDistance:!0,supportsOutDistance:!1,supportsQueryWithResultType:!0,supportsSpatialAggregationStatistics:!0,supportedSpatialAggregationStatistics:[`EnvelopeAggregate`,`CentroidAggregate`,`ConvexHullAggregate`],supportsStatistics:!0,supportsPercentileStatistics:!0,supportsReturningGeometryCentroid:!0,supportsDistinct:!0,supportsReturningQueryExtent:!0,supportsReturningGeometryProperties:!1,supportsHavingClause:!0,supportsOrderBy:!0,supportsPagination:!0,supportsSqlExpression:!0,supportsDisjointSpatialRel:!0},queryBinsCapabilities:C};class F{constructor(){this._featureIdInfo=null,this._queryEngine=null,this._snapshotFeatures=async e=>{let t=await this._fetch(e);return this._createFeatures(t)}}destroy(){this._queryEngine?.destroy(),this._queryEngine=this._createDefaultAttributes=null}async load(e,t={}){this._loadOptions={url:e.url,customParameters:e.customParameters};let r=[],[i]=await Promise.all([e.url?this._fetch(t?.signal):null,this._checkProjection(e.spatialReference)]),a=_(i,{geometryType:e.geometryType}),s=e.fields||a.fields||[],c=e.hasZ==null?a.hasZ:e.hasZ,l=a.geometryType,u=e.objectIdField||a.objectIdFieldName||`__OBJECTID`,d=e.spatialReference||o,f=e.timeInfo;s===a.fields&&a.unknownFields.length>0&&r.push({name:`geojson-layer:unknown-field-types`,message:`Some fields types couldn't be inferred from the features and were dropped`,details:{unknownFields:a.unknownFields}});let m=new k(s),h=m.dateFields.length>0,v=m.get(u);v?(v.type!==`esriFieldTypeString`&&(v.type=`esriFieldTypeOID`),v.editable=!1,v.nullable=!1,u=v.name):(v={alias:u,name:u,type:a.objectIdFieldType===`string`?`esriFieldTypeString`:`esriFieldTypeOID`,editable:!1,nullable:!1},s.unshift(v));let y={};for(let e of s){if(e.name??=e.alias,e.alias??=e.name,!e.name)throw new n(`geojson-layer:invalid-field-name`,`field name is missing`,{field:e});if(!A.jsonValues.includes(e.type))throw new n(`geojson-layer:invalid-field-type`,`invalid type for field "${e.name}"`,{field:e});if(e.name!==v.name){let t=j(e);t!==void 0&&(y[e.name]=t)}e.length??=M(e)}if(f){if(f.startTimeField){let e=m.get(f.startTimeField);e?(f.startTimeField=e.name,e.type=`esriFieldTypeDate`,h=!0):f.startTimeField=null}if(f.endTimeField){let e=m.get(f.endTimeField);e?(f.endTimeField=e.name,e.type=`esriFieldTypeDate`,h=!0):f.endTimeField=null}if(f.trackIdField){let e=m.get(f.trackIdField);e?f.trackIdField=e.name:(f.trackIdField=null,r.push({name:`geojson-layer:invalid-timeInfo-trackIdField`,message:`trackIdField is missing`,details:{timeInfo:f}}))}!f.startTimeField&&!f.endTimeField&&(r.push({name:`geojson-layer:invalid-timeInfo`,message:`startTimeField and endTimeField are missing`,details:{timeInfo:f}}),f=null)}let C=l?S(l):void 0,w=h?{timeZoneIANA:N}:null,T={warnings:r,featureErrors:[],layerDefinition:{...P,drawingInfo:C??void 0,templates:b(y),extent:void 0,geometryType:l,objectIdField:u,fields:s,hasZ:!!c,timeInfo:f,dateFieldsTimeReference:w}};this._featureIdInfo={type:`object-id`,fieldName:u},this._queryEngine=new g({fieldsIndex:k.fromLayerJSON({fields:s,timeInfo:f,dateFieldsTimeReference:w}),geometryType:l,hasM:!1,hasZ:c,featureIdInfo:this._featureIdInfo,spatialReference:d,timeInfo:f,featureStore:new p({geometryType:l,hasM:!1,hasZ:c})});let E=this._queryEngine.fieldsIndex.requiredFields.indexOf(v);E>-1&&this._queryEngine.fieldsIndex.requiredFields.splice(E,1),this._createDefaultAttributes=x(y,u);let D=this._createFeatures(i);this._objectIdGenerator=this._createObjectIdGenerator(this._queryEngine,D);let O=this._normalizeFeatures(D,T.featureErrors);this._queryEngine.featureStore.addMany(O);let{fullExtent:F,timeExtent:I}=await this._queryEngine.fetchRecomputedExtents();if(T.layerDefinition.extent=F,I){let{start:e,end:t}=I;T.layerDefinition.timeInfo.timeExtent=[e,t]}return T}async applyEdits(e){let{spatialReference:t,geometryType:n}=this._queryEngine;return await Promise.all([w(t,n),m(e.adds,t),m(e.updates,t)]),await this._waitSnapshotComplete(),this._applyEdits(e)}async queryFeatures(e={},t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeQuery(e,t.signal)}async queryFeatureCount(e={},t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeQueryForCount(e,t.signal)}async queryObjectIds(e={},t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeQueryForIds(e,t.signal)}async queryExtent(e={},t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeQueryForExtent(e,t.signal)}async querySnapping(e,t={}){return await this._waitSnapshotComplete(),await this._queryEngine.executeQueryForSnapping(e,t.signal)}async queryAttributeBins(e,t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeAttributeBinsQuery(e,t.signal)}async refresh(e){this._loadOptions.customParameters=e,this._snapshotTask?.abort(),this._snapshotTask=t(this._snapshotFeatures),this._snapshotTask.promise.then(e=>{this._queryEngine.featureStore.clear(),this._objectIdGenerator=this._createObjectIdGenerator(this._queryEngine,e);let t=this._normalizeFeatures(e);t&&this._queryEngine.featureStore.addMany(t)},e=>{this._queryEngine.featureStore.clear(),i(e)||r.getLogger(`esri.layers.GeoJSONLayer`).error(new n(`geojson-layer:refresh`,`An error occurred during refresh`,{error:e}))}),await this._waitSnapshotComplete();let{fullExtent:a,timeExtent:o}=await this._queryEngine.fetchRecomputedExtents();return{extent:a,timeExtent:o}}_createFeatures(e){if(e==null)return[];let{geometryType:t,hasZ:n}=this._queryEngine,r=this._featureIdInfo.fieldName,i=v(e,{geometryType:t,hasZ:n,objectIdField:r});if(!s(this._queryEngine.spatialReference,o))for(let e of i)e.geometry!=null&&(e.geometry=c(h(l(e.geometry,this._queryEngine.geometryType,this._queryEngine.hasZ,!1),o,this._queryEngine.spatialReference)));return i}async _waitSnapshotComplete(){if(this._snapshotTask&&!this._snapshotTask.finished){try{await this._snapshotTask.promise}catch{}return this._waitSnapshotComplete()}}async _fetch(t){let{url:n,customParameters:r}=this._loadOptions,i=(await e(n??``,{responseType:`json`,query:{...r},signal:t})).data;return y(i),i}_normalizeFeatures(e,t){let{fieldsIndex:n}=this._queryEngine,r=[],i=this._featureIdInfo.fieldName;for(let a of e){let e=this._createDefaultAttributes(),o=T(n,e,a.attributes,!0);o?t?.push(o):(this._assignObjectId(e,a.attributes,!0),a.attributes=e,a.objectId=e[i],r.push(a))}return r}async _applyEdits(e){let{adds:t,updates:n,deletes:r}=e,i={addResults:[],deleteResults:[],updateResults:[],uidToObjectId:{}};if(t?.length&&this._applyAddEdits(i,t),n?.length&&this._applyUpdateEdits(i,n),r?.length){for(let e of r)i.deleteResults.push(E(e));this._queryEngine.featureStore.removeManyById(r)}let{fullExtent:a,timeExtent:o}=await this._queryEngine.fetchRecomputedExtents();return{extent:a,timeExtent:o,featureEditResults:i}}_applyAddEdits(e,t){let{addResults:n}=e,{geometryType:r,hasM:i,hasZ:o,spatialReference:s,featureStore:c,fieldsIndex:l}=this._queryEngine,d=this._featureIdInfo.fieldName,f=[];for(let i of t){if(i.geometry&&r!==a(i.geometry)){n.push(D(`Incorrect geometry type.`));continue}let t=this._createDefaultAttributes(),o=T(l,t,i.attributes);if(o)n.push(o);else{if(this._assignObjectId(t,i.attributes),i.attributes=t,i.uid!=null){let t=i.attributes[d];e.uidToObjectId[i.uid]=t}if(i.geometry!=null){let e=i.geometry.spatialReference??s;i.geometry=h(O(i.geometry,e),e,s)}f.push(i),n.push(E(i.attributes[d]))}}c.addMany(u([],f,r,o,i,this._featureIdInfo))}_applyUpdateEdits({updateResults:e},t){let{geometryType:n,hasM:r,hasZ:i,spatialReference:o,featureStore:s,fieldsIndex:c}=this._queryEngine,l=this._featureIdInfo.fieldName;for(let u of t){let{attributes:t,geometry:p}=u,m=t?.[l];if(m==null){e.push(D(`Identifier field ${l} missing`));continue}if(!s.has(m)){e.push(D(`Feature with object id ${m} missing`));continue}let g=d(s.getFeature(m),n,i,r);if(p!=null){if(n!==a(p)){e.push(D(`Incorrect geometry type.`));continue}let t=p.spatialReference??o;g.geometry=h(O(p,t),t,o)}if(t){let n=T(c,g.attributes,t);if(n){e.push(n);continue}}s.add(f(g,n,i,r,this._featureIdInfo)),e.push(E(m))}}_createObjectIdGenerator(e,t){let n=this._featureIdInfo.fieldName,r=e.fieldsIndex.get(n);if(r.type===`esriFieldTypeString`)return()=>r.name+`-`+Date.now().toString(16);let i=-1/0;for(let e of t)e.objectId&&(i=Math.max(i,e.objectId));return i=Math.max(0,i)+1,()=>i++}_assignObjectId(e,t,n=!1){let r=this._featureIdInfo.fieldName;e[r]=!n||!(r in t)?this._objectIdGenerator():t[r]}async _checkProjection(e){try{await m(o,e)}catch{throw new n(`geojson-layer`,`Projection not supported`)}}}export{F as default};
2
+ import e from"../../../../request.js";import{createTask as t}from"../../../../core/asyncUtils.js";import n from"../../../../core/Error.js";import r from"../../../../core/Logger.js";import{isAbortError as i}from"../../../../core/promiseUtils.js";import{getJsonType as a}from"../../../../geometry/support/jsonTypeUtils.js";import{wgs84 as o,equals as s}from"../../../../geometry/support/spatialReferenceUtils.js";import{convertFromGeometry as c,convertToGeometry as l,convertFromFeatures as u,convertToFeature as d,convertFromFeature as f}from"../../featureConversionUtils.js";import p from"../../data/FeatureStore.js";import{checkProjectionSupport as m,project as h}from"../../data/projectionSupport.js";import{QueryEngine as g}from"../../data/QueryEngine.js";import{inferLayerProperties as _,createOptimizedFeatures as v,validateGeoJSON as y}from"./geojson.js";import{createDefaultTemplate as b,createDefaultAttributesFunction as x,createDrawingInfo as S}from"../support/clientSideDefaults.js";import{tableCapabilities as C,layerCapabilities as w,loadGeometryEngineForSimplify as T,mixAttributes as E,createFeatureEditSuccessResult as D,createFeatureEditErrorResult as O,simplify as k}from"../support/sourceUtils.js";import A from"../../../support/FieldsIndex.js";import{kebabDict as j}from"../../../support/fieldType.js";import{getFieldDefaultValue as M,getFieldDefaultLength as N}from"../../../support/fieldUtils.js";import{utc as P}from"../../../../time/constants.js";class F{constructor(){this._featureIdInfo=null,this._queryEngine=null,this._snapshotFeatures=async e=>{let t=await this._fetch(e);return this._createFeatures(t)}}destroy(){this._queryEngine?.destroy(),this._queryEngine=this._createDefaultAttributes=null}async load(e,t={}){this._loadOptions={url:e.url,customParameters:e.customParameters};let r=[],[i]=await Promise.all([e.url?this._fetch(t?.signal):null,this._checkProjection(e.spatialReference)]),a=_(i,{geometryType:e.geometryType}),s=e.fields||a.fields||[],c=e.hasZ==null?a.hasZ:e.hasZ,l=a.geometryType,u=!l,d=e.objectIdField||a.objectIdFieldName||`__OBJECTID`,f=e.spatialReference||o,m=e.timeInfo;s===a.fields&&a.unknownFields.length>0&&r.push({name:`geojson-layer:unknown-field-types`,message:`Some fields types couldn't be inferred from the features and were dropped`,details:{unknownFields:a.unknownFields}});let h=new A(s),v=h.dateFields.length>0,y=h.get(d);y?(y.type!==`esriFieldTypeString`&&(y.type=`esriFieldTypeOID`),y.editable=!1,y.nullable=!1,d=y.name):(y={alias:d,name:d,type:a.objectIdFieldType===`string`?`esriFieldTypeString`:`esriFieldTypeOID`,editable:!1,nullable:!1},s.unshift(y));let T={};for(let e of s){if(e.name??=e.alias,e.alias??=e.name,!e.name)throw new n(`geojson-layer:invalid-field-name`,`field name is missing`,{field:e});if(!j.jsonValues.includes(e.type))throw new n(`geojson-layer:invalid-field-type`,`invalid type for field "${e.name}"`,{field:e});if(e.name!==y.name){let t=M(e);t!==void 0&&(T[e.name]=t)}e.length??=N(e)}if(m){if(m.startTimeField){let e=h.get(m.startTimeField);e?(m.startTimeField=e.name,e.type=`esriFieldTypeDate`,v=!0):m.startTimeField=null}if(m.endTimeField){let e=h.get(m.endTimeField);e?(m.endTimeField=e.name,e.type=`esriFieldTypeDate`,v=!0):m.endTimeField=null}if(m.trackIdField){let e=h.get(m.trackIdField);e?m.trackIdField=e.name:(m.trackIdField=null,r.push({name:`geojson-layer:invalid-timeInfo-trackIdField`,message:`trackIdField is missing`,details:{timeInfo:m}}))}!m.startTimeField&&!m.endTimeField&&(r.push({name:`geojson-layer:invalid-timeInfo`,message:`startTimeField and endTimeField are missing`,details:{timeInfo:m}}),m=null)}let E=l?S(l):void 0,D=v?{timeZoneIANA:P}:null,O={warnings:r,featureErrors:[],layerDefinition:{...u?C:w,drawingInfo:E??void 0,templates:b(T),extent:void 0,geometryType:l,objectIdField:d,fields:s,hasZ:!!c,timeInfo:m,dateFieldsTimeReference:D}};this._featureIdInfo={type:`object-id`,fieldName:d},this._queryEngine=new g({fieldsIndex:A.fromLayerJSON({fields:s,timeInfo:m,dateFieldsTimeReference:D}),geometryType:l,hasM:!1,hasZ:c,featureIdInfo:this._featureIdInfo,spatialReference:f,timeInfo:m,featureStore:new p({geometryType:l,hasM:!1,hasZ:c})});let k=this._queryEngine.fieldsIndex.requiredFields.indexOf(y);k>-1&&this._queryEngine.fieldsIndex.requiredFields.splice(k,1),this._createDefaultAttributes=x(T,d);let F=this._createFeatures(i);this._objectIdGenerator=this._createObjectIdGenerator(this._queryEngine,F);let I=this._normalizeFeatures(F,O.featureErrors);this._queryEngine.featureStore.addMany(I);let{fullExtent:L,timeExtent:R}=await this._queryEngine.fetchRecomputedExtents();if(O.layerDefinition.extent=L,R){let{start:e,end:t}=R;O.layerDefinition.timeInfo.timeExtent=[e,t]}return O}async applyEdits(e){let{spatialReference:t,geometryType:n}=this._queryEngine;return await Promise.all([T(t,n),m(e.adds,t),m(e.updates,t)]),await this._waitSnapshotComplete(),this._applyEdits(e)}async queryFeatures(e={},t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeQuery(e,t.signal)}async queryFeatureCount(e={},t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeQueryForCount(e,t.signal)}async queryObjectIds(e={},t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeQueryForIds(e,t.signal)}async queryExtent(e={},t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeQueryForExtent(e,t.signal)}async querySnapping(e,t={}){return await this._waitSnapshotComplete(),await this._queryEngine.executeQueryForSnapping(e,t.signal)}async queryAttributeBins(e,t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeAttributeBinsQuery(e,t.signal)}async refresh(e){this._loadOptions.customParameters=e,this._snapshotTask?.abort(),this._snapshotTask=t(this._snapshotFeatures),this._snapshotTask.promise.then(e=>{this._queryEngine.featureStore.clear(),this._objectIdGenerator=this._createObjectIdGenerator(this._queryEngine,e);let t=this._normalizeFeatures(e);t&&this._queryEngine.featureStore.addMany(t)},e=>{this._queryEngine.featureStore.clear(),i(e)||r.getLogger(`esri.layers.GeoJSONLayer`).error(new n(`geojson-layer:refresh`,`An error occurred during refresh`,{error:e}))}),await this._waitSnapshotComplete();let{fullExtent:a,timeExtent:o}=await this._queryEngine.fetchRecomputedExtents();return{extent:a,timeExtent:o}}_createFeatures(e){if(e==null)return[];let{geometryType:t,hasZ:n}=this._queryEngine,r=this._featureIdInfo.fieldName,i=v(e,{geometryType:t,hasZ:n,objectIdField:r});if(!s(this._queryEngine.spatialReference,o))for(let e of i)e.geometry!=null&&(e.geometry=c(h(l(e.geometry,this._queryEngine.geometryType,this._queryEngine.hasZ,!1),o,this._queryEngine.spatialReference)));return i}async _waitSnapshotComplete(){if(this._snapshotTask&&!this._snapshotTask.finished){try{await this._snapshotTask.promise}catch{}return this._waitSnapshotComplete()}}async _fetch(t){let{url:n,customParameters:r}=this._loadOptions,i=(await e(n??``,{responseType:`json`,query:{...r},signal:t})).data;return y(i),i}_normalizeFeatures(e,t){let{fieldsIndex:n}=this._queryEngine,r=[],i=this._featureIdInfo.fieldName;for(let a of e){let e=this._createDefaultAttributes(),o=E(n,e,a.attributes,!0);o?t?.push(o):(this._assignObjectId(e,a.attributes,!0),a.attributes=e,a.objectId=e[i],r.push(a))}return r}async _applyEdits(e){let{adds:t,updates:n,deletes:r}=e,i={addResults:[],deleteResults:[],updateResults:[],uidToObjectId:{}};if(t?.length&&this._applyAddEdits(i,t),n?.length&&this._applyUpdateEdits(i,n),r?.length){for(let e of r)i.deleteResults.push(D(e));this._queryEngine.featureStore.removeManyById(r)}let{fullExtent:a,timeExtent:o}=await this._queryEngine.fetchRecomputedExtents();return{extent:a,timeExtent:o,featureEditResults:i}}_applyAddEdits(e,t){let{addResults:n}=e,{geometryType:r,hasM:i,hasZ:o,spatialReference:s,featureStore:c,fieldsIndex:l}=this._queryEngine,d=this._featureIdInfo.fieldName,f=[];for(let i of t){if(i.geometry&&r!==a(i.geometry)){n.push(O(`Incorrect geometry type.`));continue}let t=this._createDefaultAttributes(),o=E(l,t,i.attributes);if(o)n.push(o);else{if(this._assignObjectId(t,i.attributes),i.attributes=t,i.uid!=null){let t=i.attributes[d];e.uidToObjectId[i.uid]=t}if(i.geometry!=null){let e=i.geometry.spatialReference??s;i.geometry=h(k(i.geometry,e),e,s)}f.push(i),n.push(D(i.attributes[d]))}}c.addMany(u([],f,r,o,i,this._featureIdInfo))}_applyUpdateEdits({updateResults:e},t){let{geometryType:n,hasM:r,hasZ:i,spatialReference:o,featureStore:s,fieldsIndex:c}=this._queryEngine,l=this._featureIdInfo.fieldName;for(let u of t){let{attributes:t,geometry:p}=u,m=t?.[l];if(m==null){e.push(O(`Identifier field ${l} missing`));continue}if(!s.has(m)){e.push(O(`Feature with object id ${m} missing`));continue}let g=d(s.getFeature(m),n,i,r);if(p!=null){if(n!==a(p)){e.push(O(`Incorrect geometry type.`));continue}let t=p.spatialReference??o;g.geometry=h(k(p,t),t,o)}if(t){let n=E(c,g.attributes,t);if(n){e.push(n);continue}}s.add(f(g,n,i,r,this._featureIdInfo)),e.push(D(m))}}_createObjectIdGenerator(e,t){let n=this._featureIdInfo.fieldName,r=e.fieldsIndex.get(n);if(r.type===`esriFieldTypeString`)return()=>r.name+`-`+Date.now().toString(16);let i=-1/0;for(let e of t)e.objectId&&(i=Math.max(i,e.objectId));return i=Math.max(0,i)+1,()=>i++}_assignObjectId(e,t,n=!1){let r=this._featureIdInfo.fieldName;e[r]=!n||!(r in t)?this._objectIdGenerator():t[r]}async _checkProjection(e){try{await m(o,e)}catch{throw new n(`geojson-layer`,`Projection not supported`)}}}export{F as default};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{remove as e}from"../../../../core/arrayUtils.js";import t from"../../../../core/Error.js";import{getJsonType as n,isPoint as r}from"../../../../geometry/support/jsonTypeUtils.js";import{wgs84 as i}from"../../../../geometry/support/spatialReferenceUtils.js";import{convertFromFeatures as a,convertToFeature as o,convertFromFeature as s}from"../../featureConversionUtils.js";import{initialObjectId as c,findLastObjectIdFromFeatures as l}from"../../objectIdUtils.js";import u from"../../data/FeatureStore.js";import{checkProjectionSupport as d,project as f}from"../../data/projectionSupport.js";import{QueryEngine as p}from"../../data/QueryEngine.js";import{createDefaultAttributesFunction as m,createDefaultTemplate as h,createDrawingInfo as g}from"./clientSideDefaults.js";import{queryBinsCapabilities as _,loadGeometryEngineForSimplify as v,createFeatureEditErrorResult as y,mixAttributes as b,createFeatureEditSuccessResult as x,simplify as S}from"./sourceUtils.js";import C from"../../../support/FieldsIndex.js";import{kebabDict as w}from"../../../support/fieldType.js";import{getFieldDefaultLength as T,getFieldDefaultValue as E}from"../../../support/fieldUtils.js";import{utc as D}from"../../../../time/constants.js";const O=i,k={xmin:-180,ymin:-90,xmax:180,ymax:90,spatialReference:i},A={hasAttachments:!1,capabilities:`query, editing, create, delete, update`,useStandardizedQueries:!0,supportsCoordinatesQuantization:!0,supportsReturningQueryGeometry:!0,advancedQueryCapabilities:{supportsQueryAttachments:!1,supportsQueryAttachmentsCountOnly:!1,supportsQueryAttachmentOrderByFields:!1,supportsQueryAttachmentWithTypeWildcard:!1,supportsQueryBins:!0,supportsQueryPivot:!1,supportsSpatialAggregationStatistics:!0,supportedSpatialAggregationStatistics:[`EnvelopeAggregate`,`CentroidAggregate`,`ConvexHullAggregate`],supportsStatistics:!0,supportsPercentileStatistics:!0,supportsReturningGeometryCentroid:!0,supportsQueryWithDistance:!0,supportsOutDistance:!1,supportsDistinct:!0,supportsReturningQueryExtent:!0,supportsReturningGeometryProperties:!1,supportsHavingClause:!0,supportsOrderBy:!0,supportsPagination:!0,supportsQueryWithResultType:!0,supportsSqlExpression:!0,supportsDisjointSpatialRel:!0,supportsQueryWithCacheHint:!0},queryBinsCapabilities:_};function j(e){return r(e)?e.z!=null:!!e.hasZ}function M(e){return r(e)?e.m!=null:!!e.hasM}function N(e,t){let n,r=[];if(t.type===`unique-id-composite`){let i=[];for(let n of t.fieldNames)e.attributes[n]?i.push(e.attributes[n]):r.push(n);n=r.length===0?JSON.stringify(i):null}else n=e.attributes[t.fieldName],n||r.push(t.fieldName);return{objectId:n,missingFields:r}}class P{constructor(){this._uniqueIdInfo=null,this._queryEngine=null,this._nextObjectId=null}destroy(){this._queryEngine?.destroy(),this._queryEngine=this._createDefaultAttributes=null}async load(e){let n=[],{features:r}=e,i=this._inferLayerProperties(r,e.fields),a=e.fields||[],o=e.hasM==null?!!i.hasM:e.hasM,s=e.hasZ==null?!!i.hasZ:e.hasZ,f=!e.spatialReference&&!i.spatialReference,_=f?O:e.spatialReference||i.spatialReference,v=f?k:null,y=e.geometryType||i.geometryType,b=!y,x=e.uniqueIdInfo,S=e.objectIdField??i.objectIdField,j=e.timeInfo,M=new C(a);if(!b&&(f&&n.push({name:`feature-layer:spatial-reference-not-found`,message:`Spatial reference not provided or found in features. Defaults to WGS84`}),!y))throw new t(`feature-layer:missing-property`,`geometryType not set and couldn't be inferred from the provided features`);if(x){let e=new Set(a.map(({name:e})=>e));if(!x.fields.every(t=>e.has(t))){let n=x.fields.filter(t=>!e.has(t));throw new t(`feature-layer:missing-property`,`UniqueIdFields not set and couldn't be found in the provided fields. Fields: `+n+` are mssing.`)}S=null}else if(!S)throw new t(`feature-layer:missing-property`,`objectIdField not set and uniqueIdInfo not provided.`);if(i.objectIdField&&S!==i.objectIdField&&(n.push({name:`feature-layer:duplicated-oid-field`,message:`Provided objectIdField "${S}" doesn't match the field name "${i.objectIdField}", found in the provided fields`}),S=i.objectIdField),S&&!i.objectIdField){let e=M.get(S);e?(S=e.name,e.type=`esriFieldTypeOID`,e.editable=!1,e.nullable=!1):a.unshift({alias:S,name:S,type:`esriFieldTypeOID`,editable:!1,nullable:!1})}for(let e of a){if(e.name??=e.alias,e.alias??=e.name,!e.name)throw new t(`feature-layer:invalid-field-name`,`field name is missing`,{field:e});if(e.name===S&&(e.type=`esriFieldTypeOID`),!w.jsonValues.includes(e.type))throw new t(`feature-layer:invalid-field-type`,`invalid type for field "${e.name}"`,{field:e});e.length??=T(e)}let N={};for(let e of a)if(e.type!==`esriFieldTypeOID`&&e.type!==`esriFieldTypeGlobalID`){let t=E(e);t!==void 0&&(N[e.name]=t)}if(j){if(j.startTimeField){let e=M.get(j.startTimeField);e?(j.startTimeField=e.name,e.type=`esriFieldTypeDate`):j.startTimeField=null}if(j.endTimeField){let e=M.get(j.endTimeField);e?(j.endTimeField=e.name,e.type=`esriFieldTypeDate`):j.endTimeField=null}if(j.trackIdField){let e=M.get(j.trackIdField);e?j.trackIdField=e.name:(j.trackIdField=null,n.push({name:`feature-layer:invalid-timeInfo-trackIdField`,message:`trackIdField is missing`,details:{timeInfo:j}}))}!j.startTimeField&&!j.endTimeField&&(n.push({name:`feature-layer:invalid-timeInfo`,message:`startTimeField and endTimeField are missing or invalid`,details:{timeInfo:j}}),j=null)}let P=M.dateFields.length?{timeZoneIANA:e.dateFieldsTimeZone??D}:null;this._createDefaultAttributes=m(N,S),this._uniqueIdInfo=e.uniqueIdInfo??void 0;let F={warnings:n,featureErrors:[],layerDefinition:{...A,drawingInfo:g(y),templates:h(N),extent:v,geometryType:y,objectIdField:S,fields:a,hasZ:s,hasM:o,timeInfo:j,dateFieldsTimeReference:P,uniqueIdInfo:this._uniqueIdInfo??void 0},assignedObjectIds:{}},I=this._uniqueIdInfo?.OIDFieldContainsHashValue?this._uniqueIdInfo.type===`simple`?{type:`unique-id-simple`,fieldName:this._uniqueIdInfo.fields[0]}:{type:`unique-id-composite`,fieldNames:this._uniqueIdInfo.fields}:{type:`object-id`,fieldName:S};if(this._queryEngine=new p({fieldsIndex:C.fromLayerJSON({fields:a,timeInfo:j,dateFieldsTimeReference:P}),geometryType:y,hasM:o,hasZ:s,featureIdInfo:I,spatialReference:_,featureStore:new u({geometryType:y,hasM:o,hasZ:s}),timeInfo:j}),!r?.length)return this._nextObjectId=c,F;if(S){let e=l(S,r);this._nextObjectId=e+1}return await d(r,_),this._loadInitialFeatures(F,r)}async applyEdits(e){let{spatialReference:t,geometryType:n}=this._queryEngine;return await Promise.all([v(t,n),d(e.adds,t),d(e.updates,t)]),this._applyEdits(e)}queryFeatures(e,t={}){return this._queryEngine.executeQuery(e,t.signal)}queryFeatureCount(e,t={}){return this._queryEngine.executeQueryForCount(e,t.signal)}queryObjectIds(e,t={}){return this._queryEngine.executeQueryForIds(e,t.signal)}queryExtent(e,t={}){return this._queryEngine.executeQueryForExtent(e,t.signal)}querySnapping(e,t={}){return this._queryEngine.executeQueryForSnapping(e,t.signal)}queryAttributeBins(e,t={}){return this._queryEngine.executeAttributeBinsQuery(e,t.signal)}_inferLayerProperties(e,t){let r,i,a=null,o=null,s=null;for(let t of e){let e=t.geometry;if(e!=null&&(a||=n(e),o||=e.spatialReference,r??=j(e),i??=M(e),a&&o&&r!=null&&i!=null))break}if(t&&t.length){let e=null;t.some(t=>{let n=t.type===`esriFieldTypeOID`,r=!t.type&&t.name&&t.name.toLowerCase()===`objectid`;return e=t,n||r})&&(s=e.name)}return{geometryType:a,spatialReference:o,objectIdField:s,hasM:i,hasZ:r}}async _loadInitialFeatures(e,t){let{geometryType:r,hasM:i,hasZ:o,spatialReference:s,featureStore:c,fieldsIndex:l,featureIdInfo:u}=this._queryEngine,d=[];for(let i of t){if(i.uid!=null&&(e.assignedObjectIds[i.uid]=-1),i.geometry&&r!==n(i.geometry)){e.featureErrors.push(y(`Incorrect geometry type.`));continue}let t=this._createDefaultAttributes(),a=b(l,t,i.attributes,!0);a?e.featureErrors.push(a):(this._assignObjectId(t,i.attributes,!0),i.attributes=t,i.uid&&(e.assignedObjectIds[i.uid]=N(i,u).objectId),i.geometry!=null&&(i.geometry=f(i.geometry,i.geometry.spatialReference,s)),d.push(i))}c.addMany(a([],d,r,o,i,u));let{fullExtent:p,timeExtent:m}=await this._queryEngine.fetchRecomputedExtents();if(e.layerDefinition.extent=p,m){let{start:t,end:n}=m;e.layerDefinition.timeInfo.timeExtent=[t,n]}return e}async _applyEdits(e){let{adds:t,updates:n,deletes:r}=e,i={addResults:[],deleteResults:[],updateResults:[],uidToObjectId:{}};if(t?.length&&this._applyAddEdits(i,t),n?.length&&this._applyUpdateEdits(i,n),r?.length){for(let e of r)i.deleteResults.push(x(e));this._queryEngine.featureStore.removeManyById(r)}let{fullExtent:a,timeExtent:o}=await this._queryEngine.fetchRecomputedExtents();return{extent:a,timeExtent:o,featureEditResults:i}}_applyAddEdits(t,r){let{addResults:i,updateResults:o}=t,{geometryType:s,hasM:c,hasZ:l,spatialReference:u,featureStore:d,featureIdInfo:p,fieldsIndex:m}=this._queryEngine,h=[],g=new Map;for(let a of r){if(a.geometry&&s!==n(a.geometry)){i.push(y(`Incorrect geometry type.`));continue}let r=this._createDefaultAttributes(),c=b(m,r,a.attributes);if(c){i.push(c);continue}this._assignObjectId(r,a.attributes),a.attributes=r;let{objectId:l,missingFields:_}=N(a,p);if(l){if(a.uid!=null&&(t.uidToObjectId[a.uid]=l),a.geometry!=null){let e=a.geometry.spatialReference??u;a.geometry=f(S(a.geometry,e),e,u)}h.push(a);let n=x(l);g.has(l)?e(h,g.get(l)):d.has(l)?o.push(n):i.push(n),g.set(l,a)}else{i.push(y(`Missing unique id field value for fields: ${_.join()}`));continue}}d.addMany(a([],h,s,l,c,p))}_applyUpdateEdits({updateResults:e},t){let{geometryType:r,hasM:i,hasZ:a,spatialReference:c,featureStore:l,fieldsIndex:u,featureIdInfo:d}=this._queryEngine;for(let p of t){let{attributes:t,geometry:m}=p,{objectId:h,missingFields:g}=N(p,d);if(h==null){let t=d.type===`unique-id-composite`?g:d.fieldName;e.push(y(`Identifier fields: ${t} missing`));continue}if(!l.has(h)){e.push(y(`Feature with object id ${h} missing`));continue}let _=o(l.getFeature(h),r,a,i);if(m!=null){if(r!==n(m)){e.push(y(`Incorrect geometry type.`));continue}let t=m.spatialReference??c;_.geometry=f(S(m,t),t,c)}if(t){let n=b(u,_.attributes,t);if(n){e.push(n);continue}}l.add(s(_,r,a,i,d)),e.push(x(h))}}_assignObjectId(e,t,n=!1){if(this._queryEngine.featureIdInfo.type===`object-id`){let r=this._queryEngine.featureIdInfo.fieldName;e[r]=n&&t&&isFinite(t[r])?t[r]:this._nextObjectId++}}}export{P as default};
2
+ import{remove as e}from"../../../../core/arrayUtils.js";import t from"../../../../core/Error.js";import{getJsonType as n,isPoint as r}from"../../../../geometry/support/jsonTypeUtils.js";import{wgs84 as i}from"../../../../geometry/support/spatialReferenceUtils.js";import{convertFromFeatures as a,convertToFeature as o,convertFromFeature as s}from"../../featureConversionUtils.js";import{initialObjectId as c,findLastObjectIdFromFeatures as l}from"../../objectIdUtils.js";import u from"../../data/FeatureStore.js";import{checkProjectionSupport as d,project as f}from"../../data/projectionSupport.js";import{QueryEngine as p}from"../../data/QueryEngine.js";import{createDefaultAttributesFunction as m,createDefaultTemplate as h,createDrawingInfo as g}from"./clientSideDefaults.js";import{tableCapabilities as _,layerCapabilities as v,loadGeometryEngineForSimplify as y,createFeatureEditErrorResult as b,mixAttributes as x,createFeatureEditSuccessResult as S,simplify as C}from"./sourceUtils.js";import w from"../../../support/FieldsIndex.js";import{kebabDict as T}from"../../../support/fieldType.js";import{getFieldDefaultLength as E,getFieldDefaultValue as D}from"../../../support/fieldUtils.js";import{utc as O}from"../../../../time/constants.js";const k=i,A={xmin:-180,ymin:-90,xmax:180,ymax:90,spatialReference:i};function j(e){return r(e)?e.z!=null:!!e.hasZ}function M(e){return r(e)?e.m!=null:!!e.hasM}function N(e,t){let n,r=[];if(t.type===`unique-id-composite`){let i=[];for(let n of t.fieldNames)e.attributes[n]?i.push(e.attributes[n]):r.push(n);n=r.length===0?JSON.stringify(i):null}else n=e.attributes[t.fieldName],n||r.push(t.fieldName);return{objectId:n,missingFields:r}}class P{constructor(){this._uniqueIdInfo=null,this._queryEngine=null,this._nextObjectId=null}destroy(){this._queryEngine?.destroy(),this._queryEngine=this._createDefaultAttributes=null}async load(e){let n=[],{features:r}=e,i=this._inferLayerProperties(r,e.fields),a=e.fields||[],o=e.hasM==null?!!i.hasM:e.hasM,s=e.hasZ==null?!!i.hasZ:e.hasZ,f=!e.spatialReference&&!i.spatialReference,y=f?k:e.spatialReference||i.spatialReference,b=f?A:null,x=e.geometryType||i.geometryType,S=!x,C=e.uniqueIdInfo,j=e.objectIdField??i.objectIdField,M=e.timeInfo,N=new w(a);if(!S&&(f&&n.push({name:`feature-layer:spatial-reference-not-found`,message:`Spatial reference not provided or found in features. Defaults to WGS84`}),!x))throw new t(`feature-layer:missing-property`,`geometryType not set and couldn't be inferred from the provided features`);if(C){let e=new Set(a.map(({name:e})=>e));if(!C.fields.every(t=>e.has(t))){let n=C.fields.filter(t=>!e.has(t));throw new t(`feature-layer:missing-property`,`UniqueIdFields not set and couldn't be found in the provided fields. Fields: `+n+` are mssing.`)}j=null}else if(!j)throw new t(`feature-layer:missing-property`,`objectIdField not set and uniqueIdInfo not provided.`);if(i.objectIdField&&j!==i.objectIdField&&(n.push({name:`feature-layer:duplicated-oid-field`,message:`Provided objectIdField "${j}" doesn't match the field name "${i.objectIdField}", found in the provided fields`}),j=i.objectIdField),j&&!i.objectIdField){let e=N.get(j);e?(j=e.name,e.type=`esriFieldTypeOID`,e.editable=!1,e.nullable=!1):a.unshift({alias:j,name:j,type:`esriFieldTypeOID`,editable:!1,nullable:!1})}for(let e of a){if(e.name??=e.alias,e.alias??=e.name,!e.name)throw new t(`feature-layer:invalid-field-name`,`field name is missing`,{field:e});if(e.name===j&&(e.type=`esriFieldTypeOID`),!T.jsonValues.includes(e.type))throw new t(`feature-layer:invalid-field-type`,`invalid type for field "${e.name}"`,{field:e});e.length??=E(e)}let P={};for(let e of a)if(e.type!==`esriFieldTypeOID`&&e.type!==`esriFieldTypeGlobalID`){let t=D(e);t!==void 0&&(P[e.name]=t)}if(M){if(M.startTimeField){let e=N.get(M.startTimeField);e?(M.startTimeField=e.name,e.type=`esriFieldTypeDate`):M.startTimeField=null}if(M.endTimeField){let e=N.get(M.endTimeField);e?(M.endTimeField=e.name,e.type=`esriFieldTypeDate`):M.endTimeField=null}if(M.trackIdField){let e=N.get(M.trackIdField);e?M.trackIdField=e.name:(M.trackIdField=null,n.push({name:`feature-layer:invalid-timeInfo-trackIdField`,message:`trackIdField is missing`,details:{timeInfo:M}}))}!M.startTimeField&&!M.endTimeField&&(n.push({name:`feature-layer:invalid-timeInfo`,message:`startTimeField and endTimeField are missing or invalid`,details:{timeInfo:M}}),M=null)}let F=N.dateFields.length?{timeZoneIANA:e.dateFieldsTimeZone??O}:null;this._createDefaultAttributes=m(P,j),this._uniqueIdInfo=e.uniqueIdInfo??void 0;let I={warnings:n,featureErrors:[],layerDefinition:{...S?_:v,drawingInfo:g(x),templates:h(P),extent:b,geometryType:x,objectIdField:j,fields:a,hasZ:s,hasM:o,timeInfo:M,dateFieldsTimeReference:F,uniqueIdInfo:this._uniqueIdInfo??void 0},assignedObjectIds:{}},L=this._uniqueIdInfo?.OIDFieldContainsHashValue?this._uniqueIdInfo.type===`simple`?{type:`unique-id-simple`,fieldName:this._uniqueIdInfo.fields[0]}:{type:`unique-id-composite`,fieldNames:this._uniqueIdInfo.fields}:{type:`object-id`,fieldName:j};if(this._queryEngine=new p({fieldsIndex:w.fromLayerJSON({fields:a,timeInfo:M,dateFieldsTimeReference:F}),geometryType:x,hasM:o,hasZ:s,featureIdInfo:L,spatialReference:y,featureStore:new u({geometryType:x,hasM:o,hasZ:s}),timeInfo:M}),!r?.length)return this._nextObjectId=c,I;if(j){let e=l(j,r);this._nextObjectId=e+1}return await d(r,y),this._loadInitialFeatures(I,r)}async applyEdits(e){let{spatialReference:t,geometryType:n}=this._queryEngine;return await Promise.all([y(t,n),d(e.adds,t),d(e.updates,t)]),this._applyEdits(e)}queryFeatures(e,t={}){return this._queryEngine.executeQuery(e,t.signal)}queryFeatureCount(e,t={}){return this._queryEngine.executeQueryForCount(e,t.signal)}queryObjectIds(e,t={}){return this._queryEngine.executeQueryForIds(e,t.signal)}queryExtent(e,t={}){return this._queryEngine.executeQueryForExtent(e,t.signal)}querySnapping(e,t={}){return this._queryEngine.executeQueryForSnapping(e,t.signal)}queryAttributeBins(e,t={}){return this._queryEngine.executeAttributeBinsQuery(e,t.signal)}_inferLayerProperties(e,t){let r,i,a=null,o=null,s=null;for(let t of e){let e=t.geometry;if(e!=null&&(a||=n(e),o||=e.spatialReference,r??=j(e),i??=M(e),a&&o&&r!=null&&i!=null))break}if(t&&t.length){let e=null;t.some(t=>{let n=t.type===`esriFieldTypeOID`,r=!t.type&&t.name&&t.name.toLowerCase()===`objectid`;return e=t,n||r})&&(s=e.name)}return{geometryType:a,spatialReference:o,objectIdField:s,hasM:i,hasZ:r}}async _loadInitialFeatures(e,t){let{geometryType:r,hasM:i,hasZ:o,spatialReference:s,featureStore:c,fieldsIndex:l,featureIdInfo:u}=this._queryEngine,d=[];for(let i of t){if(i.uid!=null&&(e.assignedObjectIds[i.uid]=-1),i.geometry&&r!==n(i.geometry)){e.featureErrors.push(b(`Incorrect geometry type.`));continue}let t=this._createDefaultAttributes(),a=x(l,t,i.attributes,!0);a?e.featureErrors.push(a):(this._assignObjectId(t,i.attributes,!0),i.attributes=t,i.uid&&(e.assignedObjectIds[i.uid]=N(i,u).objectId),i.geometry!=null&&(i.geometry=f(i.geometry,i.geometry.spatialReference,s)),d.push(i))}c.addMany(a([],d,r,o,i,u));let{fullExtent:p,timeExtent:m}=await this._queryEngine.fetchRecomputedExtents();if(e.layerDefinition.extent=p,m){let{start:t,end:n}=m;e.layerDefinition.timeInfo.timeExtent=[t,n]}return e}async _applyEdits(e){let{adds:t,updates:n,deletes:r}=e,i={addResults:[],deleteResults:[],updateResults:[],uidToObjectId:{}};if(t?.length&&this._applyAddEdits(i,t),n?.length&&this._applyUpdateEdits(i,n),r?.length){for(let e of r)i.deleteResults.push(S(e));this._queryEngine.featureStore.removeManyById(r)}let{fullExtent:a,timeExtent:o}=await this._queryEngine.fetchRecomputedExtents();return{extent:a,timeExtent:o,featureEditResults:i}}_applyAddEdits(t,r){let{addResults:i,updateResults:o}=t,{geometryType:s,hasM:c,hasZ:l,spatialReference:u,featureStore:d,featureIdInfo:p,fieldsIndex:m}=this._queryEngine,h=[],g=new Map;for(let a of r){if(a.geometry&&s!==n(a.geometry)){i.push(b(`Incorrect geometry type.`));continue}let r=this._createDefaultAttributes(),c=x(m,r,a.attributes);if(c){i.push(c);continue}this._assignObjectId(r,a.attributes),a.attributes=r;let{objectId:l,missingFields:_}=N(a,p);if(l){if(a.uid!=null&&(t.uidToObjectId[a.uid]=l),a.geometry!=null){let e=a.geometry.spatialReference??u;a.geometry=f(C(a.geometry,e),e,u)}h.push(a);let n=S(l);g.has(l)?e(h,g.get(l)):d.has(l)?o.push(n):i.push(n),g.set(l,a)}else{i.push(b(`Missing unique id field value for fields: ${_.join()}`));continue}}d.addMany(a([],h,s,l,c,p))}_applyUpdateEdits({updateResults:e},t){let{geometryType:r,hasM:i,hasZ:a,spatialReference:c,featureStore:l,fieldsIndex:u,featureIdInfo:d}=this._queryEngine;for(let p of t){let{attributes:t,geometry:m}=p,{objectId:h,missingFields:g}=N(p,d);if(h==null){let t=d.type===`unique-id-composite`?g:d.fieldName;e.push(b(`Identifier fields: ${t} missing`));continue}if(!l.has(h)){e.push(b(`Feature with object id ${h} missing`));continue}let _=o(l.getFeature(h),r,a,i);if(m!=null){if(r!==n(m)){e.push(b(`Incorrect geometry type.`));continue}let t=m.spatialReference??c;_.geometry=f(C(m,t),t,c)}if(t){let n=x(u,_.attributes,t);if(n){e.push(n);continue}}l.add(s(_,r,a,i,d)),e.push(S(h))}}_assignObjectId(e,t,n=!1){if(this._queryEngine.featureIdInfo.type===`object-id`){let r=this._queryEngine.featureIdInfo.fieldName;e[r]=n&&t&&isFinite(t[r])?t[r]:this._nextObjectId++}}}export{P as default};
@@ -5,4 +5,4 @@ import has from"../../../../core/has.js";import{clone as e}from"../../../../core
5
5
  ${n};
6
6
  }
7
7
  }
8
- `)();return()=>new r}catch{return()=>t?{[t]:null,...e}:{...e}}}function u(e){return s.test(e)?`.${e}`:`[${JSON.stringify(e)}]`}function d(t={}){return[{name:`New Feature`,description:``,prototype:{attributes:e(t)}}]}function f(e,r){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:r,supportsDelete:r,supportsEditing:r,supportsChangeTracking:!1,supportsQuery:!0,supportsQueryBins:!0,supportsQueryPivot:!1,supportsQueryAnalytics:!1,supportsQueryAttachments:!1,supportsQueryTopFeatures:!1,supportsResizeAttachments:!1,supportsSync:!1,supportsUpdate:r,supportsExceedsLimitStatistics:!0,supportsAsyncConvert3D:!1},query:n,queryRelated:{supportsCount:!0,supportsOrderBy:!0,supportsPagination:!0,supportsCacheHint:!1},queryTopFeatures:{supportsCacheHint:!1},queryAttributeBins:t,editing:{supportsGeometryUpdate:r,supportsGlobalId:!1,supportsReturnServiceEditsInSourceSpatialReference:!1,supportsRollbackOnFailure:!1,supportsTrueCurveUpdate:r,supportsTrueCurveUpdateByTrueCurveClientsOnly:!1,supportsUpdateWithoutM:!1,supportsUploadWithItemId:!1,supportsDeleteByAnonymous:!1,supportsDeleteByOthers:!1,supportsUpdateByAnonymous:!1,supportsUpdateByOthers:!1,supportsAsyncApplyEdits:!1,zDefault:void 0}}}export{f as createCapabilities,l as createDefaultAttributesFunction,d as createDefaultTemplate,o as createDrawingInfo};
8
+ `)();return()=>new r}catch{return()=>t?{[t]:null,...e}:{...e}}}function u(e){return s.test(e)?`.${e}`:`[${JSON.stringify(e)}]`}function d(t={}){return[{name:`New Feature`,description:``,prototype:{attributes:e(t)}}]}const f={...n,supportsSpatialAggregationStatistics:!1,supportedSpatialAggregationStatistics:{envelope:!1,centroid:!1,convexHull:!1},supportsCentroid:!1,supportsDistance:!1,supportsExtent:!1,supportsQuantization:!1,supportsQueryGeometry:!1,supportsDisjointSpatialRelationship:!1},p={...t,supportedStatistics:{...t.supportedStatistics,envelope:!1,centroid:!1,convexHull:!1}};function m(e,r,i=!1){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:r,supportsDelete:r,supportsEditing:r,supportsChangeTracking:!1,supportsQuery:!0,supportsQueryBins:!0,supportsQueryPivot:!1,supportsQueryAnalytics:!1,supportsQueryAttachments:!1,supportsQueryTopFeatures:!1,supportsResizeAttachments:!1,supportsSync:!1,supportsUpdate:r,supportsExceedsLimitStatistics:!0,supportsAsyncConvert3D:!1},query:i?f:n,queryRelated:{supportsCount:!0,supportsOrderBy:!0,supportsPagination:!0,supportsCacheHint:!1},queryTopFeatures:{supportsCacheHint:!1},queryAttributeBins:i?p:t,editing:{supportsGeometryUpdate:r,supportsGlobalId:!1,supportsReturnServiceEditsInSourceSpatialReference:!1,supportsRollbackOnFailure:!1,supportsTrueCurveUpdate:r,supportsTrueCurveUpdateByTrueCurveClientsOnly:!1,supportsUpdateWithoutM:!1,supportsUploadWithItemId:!1,supportsDeleteByAnonymous:!1,supportsDeleteByOthers:!1,supportsUpdateByAnonymous:!1,supportsUpdateByOthers:!1,supportsAsyncApplyEdits:!1,zDefault:void 0}}}export{m as createCapabilities,l as createDefaultAttributesFunction,d as createDefaultTemplate,o as createDrawingInfo};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{parseDate as e}from"../../../../core/date.js";import{importLazily as t}from"../../../../core/importUtils.js";import{isPolygon as n,isPolyline as r}from"../../../../geometry/support/jsonTypeUtils.js";import{isValid as i}from"../../../../geometry/support/spatialReferenceUtils.js";import{validateFieldValue as a,validationErrorToString as o,isNumericField as s,sanitizedParseFloat as c,isStringField as l,isDateField as u,sanitizeNullFieldValue as d}from"../../../support/fieldUtils.js";class f{constructor(e){this.description=e,this.code=null}}class p{constructor(e){this.globalId=null,this.objectId=null,this.success=!1,this.uniqueId=null,this.error=new f(e)}}function m(e){return new p(e)}class h{constructor(e){this.globalId=null,this.success=!0,this.objectId=this.uniqueId=e}}function g(e){return new h(e)}const _=new Set;function v(e,t,n,r=!1){_.clear();for(let i in n){let s=e.get(i);if(!s)continue;let c=n[i],l=y(s,c);if(_.add(s.name),s&&(r||s.editable)){let e=a(s,l);if(!e)t[s.name]=l;else return m(o(e,s,l))}}for(let t of e.requiredFields??[])if(!_.has(t.name))return m(`missing required field "${t.name}"`);return null}function y(t,n){let r=n;return s(t)&&typeof n==`string`?r=c(n):l(t)&&n!=null&&typeof n!=`string`?r=String(n):u(t)&&typeof n==`string`&&(r=e(n)),d(r)}const b=t(()=>import(`../../../../geometry/operators/json/simplifyOperator.js`));function x(e,t){if(!n(e)&&!r(e)||!i(t))return e;let a=b.module;if(a==null)throw TypeError(`simplify operator not loaded`);return a.simplifyExecute({...e,spatialReference:t})??e}async function S(e,t){i(e)&&(t===`esriGeometryPolygon`||t===`esriGeometryPolyline`)&&await b.getImportPromise()}const C={supportsAutoIntervalBin:!0,supportsFixedIntervalBin:!0,supportsFixedBoundariesBin:!0,supportsDateBin:!0,supportsStackBy:!0,supportsSplitBy:!0,supportsNormalization:!0,supportedStatisticTypes:[`COUNT`,`SUM`,`AVG`,`VAR`,`STDDEV`,`MIN`,`MAX`,`PERCENTILE_CONT`,`PERCENTILE_DISC`,`CentroidAggregate`,`EnvelopeAggregate`,`ConvexHullAggregate`],supportedNormalizationTypes:[`field`,`log`,`naturalLog`,`percentOfTotal`,`squareRoot`]};export{m as createFeatureEditErrorResult,g as createFeatureEditSuccessResult,S as loadGeometryEngineForSimplify,v as mixAttributes,C as queryBinsCapabilities,x as simplify};
2
+ import{parseDate as e}from"../../../../core/date.js";import{importLazily as t}from"../../../../core/importUtils.js";import{isPolygon as n,isPolyline as r}from"../../../../geometry/support/jsonTypeUtils.js";import{isValid as i}from"../../../../geometry/support/spatialReferenceUtils.js";import{validateFieldValue as a,validationErrorToString as o,isNumericField as s,sanitizedParseFloat as c,isStringField as l,isDateField as u,sanitizeNullFieldValue as d}from"../../../support/fieldUtils.js";class f{constructor(e){this.description=e,this.code=null}}class p{constructor(e){this.globalId=null,this.objectId=null,this.success=!1,this.uniqueId=null,this.error=new f(e)}}function m(e){return new p(e)}class h{constructor(e){this.globalId=null,this.success=!0,this.objectId=this.uniqueId=e}}function g(e){return new h(e)}const _=new Set;function v(e,t,n,r=!1){_.clear();for(let i in n){let s=e.get(i);if(!s)continue;let c=n[i],l=y(s,c);if(_.add(s.name),s&&(r||s.editable)){let e=a(s,l);if(!e)t[s.name]=l;else return m(o(e,s,l))}}for(let t of e.requiredFields??[])if(!_.has(t.name))return m(`missing required field "${t.name}"`);return null}function y(t,n){let r=n;return s(t)&&typeof n==`string`?r=c(n):l(t)&&n!=null&&typeof n!=`string`?r=String(n):u(t)&&typeof n==`string`&&(r=e(n)),d(r)}const b=t(()=>import(`../../../../geometry/operators/json/simplifyOperator.js`));function x(e,t){if(!n(e)&&!r(e)||!i(t))return e;let a=b.module;if(a==null)throw TypeError(`simplify operator not loaded`);return a.simplifyExecute({...e,spatialReference:t})??e}async function S(e,t){i(e)&&(t===`esriGeometryPolygon`||t===`esriGeometryPolyline`)&&await b.getImportPromise()}const C={supportsAutoIntervalBin:!0,supportsFixedIntervalBin:!0,supportsFixedBoundariesBin:!0,supportsDateBin:!0,supportsStackBy:!0,supportsSplitBy:!0,supportsNormalization:!0,supportedStatisticTypes:[`COUNT`,`SUM`,`AVG`,`VAR`,`STDDEV`,`MIN`,`MAX`,`PERCENTILE_CONT`,`PERCENTILE_DISC`,`CentroidAggregate`,`EnvelopeAggregate`,`ConvexHullAggregate`],supportedNormalizationTypes:[`field`,`log`,`naturalLog`,`percentOfTotal`,`squareRoot`]},w={hasAttachments:!1,capabilities:`query, editing, create, delete, update`,useStandardizedQueries:!0,supportsCoordinatesQuantization:!0,supportsReturningQueryGeometry:!0,advancedQueryCapabilities:{supportsQueryAttachments:!1,supportsQueryAttachmentsCountOnly:!1,supportsQueryAttachmentOrderByFields:!1,supportsQueryAttachmentWithTypeWildcard:!1,supportsQueryBins:!0,supportsQueryPivot:!1,supportsSpatialAggregationStatistics:!0,supportedSpatialAggregationStatistics:[`EnvelopeAggregate`,`CentroidAggregate`,`ConvexHullAggregate`],supportsStatistics:!0,supportsPercentileStatistics:!0,supportsReturningGeometryCentroid:!0,supportsQueryWithDistance:!0,supportsOutDistance:!1,supportsDistinct:!0,supportsReturningQueryExtent:!0,supportsReturningGeometryProperties:!1,supportsHavingClause:!0,supportsOrderBy:!0,supportsPagination:!0,supportsQueryWithResultType:!0,supportsSqlExpression:!0,supportsDisjointSpatialRel:!0,supportsQueryWithCacheHint:!0},queryBinsCapabilities:C},T={...w,supportsCoordinatesQuantization:!1,supportsReturningQueryGeometry:!1,advancedQueryCapabilities:{...w.advancedQueryCapabilities,supportsSpatialAggregationStatistics:!1,supportedSpatialAggregationStatistics:[],supportsReturningGeometryCentroid:!1,supportsQueryWithDistance:!1,supportsReturningQueryExtent:!1,supportsDisjointSpatialRel:!1},queryBinsCapabilities:{...C,supportedStatisticTypes:C.supportedStatisticTypes.filter(e=>e!==`EnvelopeAggregate`&&e!==`CentroidAggregate`&&e!==`ConvexHullAggregate`)}};export{m as createFeatureEditErrorResult,g as createFeatureEditSuccessResult,w as layerCapabilities,S as loadGeometryEngineForSimplify,v as mixAttributes,C as queryBinsCapabilities,x as simplify,T as tableCapabilities};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../../core/Error.js";import"../../../core/has.js";import n from"../../../core/Logger.js";import{property as r,subclass as i}from"../../../core/accessorSupport/decorators.js";import a from"../../../geometry/Extent.js";import o from"../../../geometry/Point.js";import s from"../../../geometry/SpatialReference.js";import c from"./BaseRaster.js";import{parse as l}from"./DBFParser.js";import{parsePAMInfo as u,parseSpatialReference as d}from"./pamParser.js";import{parseSignature as f,getPyramidIFDs as p,getMaskIFDs as m,parseIFD as h,parseGeoKeyDirectory as g,parseXMP as _,parseFieldValues as v,isBSQConfig as y,getTagNumericValues as b,getTagFirstNumericValue as x,getImageInfo as S}from"../formats/tiffParser.js";import{tiffTags as C,ifdTags as w}from"../formats/tiffTag.js";import{estimateStatisticsFromHistograms as T}from"../functions/stretchUtils.js";import E from"../transforms/PolynomialTransform.js";import D from"../../support/RasterInfo.js";import O from"../../support/RasterStorageInfo.js";import k from"../../../rest/support/FeatureSet.js";const A=`none-tiled tiff is not optimized for access, convert to COG and retry.`;let j=class extends c{constructor(){super(...arguments),this._files=null,this._headerInfo=null,this._bufferSize=1048576,this._chunkSize=10*1024**2,this._fileSize=-1,this._headerChunks=[],this.datasetFormat=`TIFF`}async fetchRawTile(e,t,n,r={}){if(!this._headerInfo?.isSupported||this.isBlockOutside(e,t,n))return null;let i=await this._fetchRawTiffTile(e,t,n,!1,r);if(i!=null&&this._headerInfo.hasMaskBand){let a=await this._fetchRawTiffTile(e,t,n,!0,r);a!=null&&a.pixels[0]instanceof Uint8Array&&(i.mask=a.pixels[0])}return i}async _open(e){this.datasetName=this.url.slice(this.url.lastIndexOf(`/`)+1,this.url.lastIndexOf(`.`)),await this._readHeader(e?.signal);let{rasterInfo:t}=this,{skipMapInfo:n,skipExtensions:r=[]}=this.ioConfig;if(!r.includes(`aux.xml`)&&!n){let n=await this._fetchAuxiliaryMetaData(e);n!=null&&N(n,t)}!r.includes(`vat.dbf`)&&t.bandCount===1&&t.pixelType===`u8`&&!n&&(t.attributeTable=await this._fetchAuxiliaryTable(e),t.attributeTable!=null&&(t.keyProperties.DataType=`thematic`)),n&&this.updateImageSpaceRasterInfo(t),this.updateTileInfo()}async _readHeader(e){try{let n=await this._fetchHeaderData(0,this._bufferSize,e);if(!n)throw new t(`tiffraster:open`,`failed to open url `+this.url);let{littleEndian:r,firstIFDPos:i,isBigTiff:a}=f(n),o=[],s={fileChunk:n,posIFD:i,fileOffset:0};await this._readIFDs(o,s,r,a?8:4,e);let{imageInfo:c,rasterInfo:l}=M(o),u=p(o),d=m(o);this._headerInfo={littleEndian:r,isBigTiff:a,ifds:o,pyramidIFDs:u,maskIFDs:d,...c},this._set(`rasterInfo`,l),this._validateHeader()}finally{this._headerChunks.length=0}}_validateHeader(){let e=this._headerInfo;if(!e.isSupported)throw new t(`tiffraster:open`,`this tiff is not supported: `+e.message);if(!e.tileWidth||!e.tileHeight)throw new t(`tiffraster:open`,A);this.rasterInfo.isPseudoSpatialReference&&n.getLogger(this).warn(`The spatial reference for this tiff is unsupported. Only EPSG spatial reference codes and Esri WKTs are supported.`);let r=e.ifds[0],i=r.get(`PREDICTOR`)?.values?.[0];if(r.get(`SAMPLEFORMAT`)?.values?.[0]===3&&i===2)throw new t(`tiffraster:open`,`unsupported horizontal difference encoding. Predictor=3 is supported for floating point data`)}async _fetchHeaderData(e,n,r){let i=this._getCachedHeaderData(e,n);if(i)return i;let a=Math.floor(e/this._bufferSize)*this._bufferSize,o=a+Math.max(1,Math.ceil((n-a)/this._bufferSize))*this._bufferSize,s=this._getMissingHeaderRanges(a,o).map(async e=>{let{from:t,to:n}=e,i=await this._fetchOffsets(t,n,r),a=this._fileSize;return{chunk:i,fileOffset:t,isEOF:a>0?t+i.byteLength>=a:i.byteLength<n-t+1}}),c=await Promise.all(s);this._headerChunks.push(...c),this._headerChunks.sort((e,t)=>e.fileOffset-t.fileOffset);let l=this._getCachedHeaderData(e,n);if(!l)throw new t(`tiffraster:open`,`failed to fetch byte range ${e}-${n} from ${this.url}`);return l}_getCachedHeaderData(e,t){let n=[],r=e;for(let{chunk:i,fileOffset:a,isEOF:o}of this._headerChunks){if(a+i.byteLength-1<r)continue;if(a>r)return null;let s=r-a,c=Math.min(t-a+1,i.byteLength);if(n.push({chunk:i,start:s,end:c}),r=a+c,r>t||o&&c===i.byteLength){let t=new Uint8Array(r-e),i=0;for(let e of n){let n=new Uint8Array(e.chunk,e.start,e.end-e.start);t.set(n,i),i+=n.byteLength}return t.buffer}}return null}_getMissingHeaderRanges(e,t){let n=[],r=(e,t)=>{let r=Math.floor(e/this._bufferSize)*this._bufferSize,i=Math.ceil(t/this._bufferSize)*this._bufferSize;n.push({from:r,to:i})},i=e;for(let{chunk:e,fileOffset:a,isEOF:o}of this._headerChunks){let s=a+e.byteLength-1;if(!(s<i)&&(a>i&&r(i,Math.min(a-1,t)),i=Math.max(i,s+1),i>t||o))return n}return i<=t&&r(i,t),n}async _validateOrFetchHeaderBuffer(e,n){let{fileChunk:r,fileOffset:i,posIFD:a}=e;if(a+8>=r.byteLength||a<0){if(i=a+i,i<0)throw new t(`tiffraster:open`,`invalid IFD position ${i}. failed to open url ${this.url}`);r=await this._fetchHeaderData(i,i+this._bufferSize/2,n),a=0}return{fileChunk:r,fileOffset:i,posIFD:a}}async _readIFDs(e,n,r,i=4,a){if(!n.posIFD)return null;n=await this._validateOrFetchHeaderBuffer(n,a);let o=await this._readIFD(n,r,C,i,a);if(!o?.ifd)throw new t(`tiffraster:open`,`cannot parse tiff header. failed to open url `+this.url);if(e.push(o.ifd),!o.nextIFD)return null;n.posIFD=o.nextIFD-n.fileOffset,await this._readIFDs(e,n,r,i,a)}async _readIFD(e,n,r=C,i=4,a){let{fileChunk:o,posIFD:s,fileOffset:c}=e;if(!e.fileChunk)return null;let l=h(o,n,s,c,r,i);if(l.success){let{ifd:e}=l;if(!e)throw new t(`tiffraster:open`,`cannot parse tiff header. failed to open url `+this.url);if(!this.ioConfig.loadFullMetadata&&r===C&&(!e.has(`TILEWIDTH`)||!e.has(`TILELENGTH`)))throw new t(`tiffraster:open`,A);let i=[];e.forEach(e=>{e.values||i.push(e)}),i.length>0&&await this._fillOffsets(i,n,l.nextIFD,a),g(e),_(e);for(let[t,r]of w){let i=e.get(t),l=i?.data!=null&&Array.from(i.data.values()).some(e=>e.values==null&&e.offlineOffsetSize!=null);if(i&&(!i.data||l)){s=i.valueOffset-c;let e=await this._validateOrFetchHeaderBuffer({fileChunk:o,posIFD:s,fileOffset:c},a);i.data=(await this._readIFD(e,n,r,4,a))?.ifd}}return l}return l.requiredBufferSize?(o=await this._fetchHeaderData(c,c+s+l.requiredBufferSize+8,a),o.byteLength<s+l.requiredBufferSize?null:(e.fileChunk=o,e.fileOffset=c,this._readIFD(e,n,r,i,a))):null}async _fillOffsets(e,t,n,r){let i=e.filter(e=>e.offlineOffsetSize!=null);if(i.length===0)return;let a=i.map(e=>e.offlineOffsetSize),o=Math.min.apply(null,a.map(e=>e[0])),s=Math.max.apply(null,a.map(e=>e[0]+e[1])),c=a.length===1||s-o<=this._bufferSize;if(!c&&a.length>1&&(a.sort((e,t)=>e[0]-t[0]),c=a.reduce((e,t)=>e===t[0]?t[0]+t[1]:0,a[0][0])===s),c){let e=Math.max(s,o+this._bufferSize/4),n=await this._fetchHeaderData(o,e,r);i.forEach(e=>v(n,t,e,o));return}let l=i.map(async e=>{let n=e.offlineOffsetSize,i=await this._fetchHeaderData(n[0],n[1]+n[0],r);v(i,t,e,n[0])});await Promise.all(l)}async _fetchOffsets(e,t,n){let r=[],i=this._chunkSize;this._fileSize>0&&(t=Math.min(t,this._fileSize-1));let a=Math.ceil((t-e+1)/i),o=e;for(let e=0;e<a;e++)r.push(this.request(this.url,{range:{from:o,to:e===a-1?t:o+i-1},responseType:`array-buffer`,signal:n})),o+=i;let s=await Promise.all(r);if(this._fileSize===-1&&s[0].httpStatus===206){let e=s[0].getHeader?.(`Content-Range`),t=Number(e?.split(`/`)[1]);Number.isFinite(t)&&(this._fileSize=t)}if(s.length===1)return s[0].data;let c=s.reduce((e,t)=>e+t.data.byteLength,0),l=new Uint8Array(c),u=0;for(let e of s)l.set(new Uint8Array(e.data),u),u+=e.data.byteLength;return l.buffer}async _fetchRawTiffTile(e,t,n,r,i={}){let a=this._getTileLocation(e,t,n,r);if(!a)return null;let{ranges:o,actualTileWidth:s,actualTileHeight:c,ifd:l}=a,u=o.map(e=>this.request(this.url,{range:e,responseType:`array-buffer`,signal:i.signal})),d=await Promise.all(u),f=d.map(e=>e.data.byteLength).reduce((e,t)=>e+t),p=d.length===1?d[0].data:new ArrayBuffer(f),m=[0],h=[0];if(d.length>1){let e=new Uint8Array(p);for(let t=0,n=0;t<d.length;t++){let r=d[t].data;e.set(new Uint8Array(r),n),m[t]=n,n+=r.byteLength,h[t]=r.byteLength}}let{blockWidth:g,blockHeight:_}=this.getBlockWidthHeight(e),v=await this.decodePixelBlock(p,{format:`tiff`,customOptions:{headerInfo:this._headerInfo,ifd:l,offsets:m,sizes:h},width:g,height:_,planes:null,pixelType:null});if(v==null)return null;if(s!==g||c!==_){let e=v.mask;if(e)for(let t=0;t<_;t++){let n=t*g;if(t<c)for(let t=s;t<g;t++)e[n+t]=0;else for(let t=0;t<g;t++)e[n+t]=0}else{e=new Uint8Array(g*_),v.mask=e;for(let t=0;t<c;t++){let n=t*g;for(let t=0;t<s;t++)e[n+t]=1}}}return v}_getTileLocation(e,t,n,r=!1){let{firstPyramidLevel:i,blockBoundary:a}=this.rasterInfo.storageInfo,o=e===0?0:e-(i-1),{_headerInfo:s}=this;if(!s)return null;let c=r?s.maskIFDs[o]:o===0?s.ifds[0]:s.pyramidIFDs[o-1];if(!c)return null;let l=y(c,s),u=b(c,`TILEOFFSETS`),d=b(c,`TILEBYTECOUNTS`);if(!u?.length||!d?.length)return null;let{minRow:f,minCol:p,maxRow:m,maxCol:h}=a[o];if(t>m||n>h||t<f||n<p)return null;let g=x(c,`IMAGEWIDTH`),_=x(c,`IMAGELENGTH`),v=x(c,`TILEWIDTH`),S=x(c,`TILELENGTH`),C=[];if(l){let{bandCount:e}=this.rasterInfo;for(let r=0;r<e;r++){let e=r*(m+1)*(h+1)+t*(h+1)+n;C[r]={from:u[e],to:u[e]+d[e]-1}}}else{let e=t*(h+1)+n;C.push({from:u[e],to:u[e]+d[e]-1})}for(let e=0;e<C.length;e++)if(C[e].from==null||!C[e].to||C[e].to<0)return null;return{ranges:C,ifd:c,actualTileWidth:n===h&&g%v||v,actualTileHeight:t===m&&_%S||S}}async _fetchAuxiliaryMetaData(e){try{let{data:t}=await this.request(this.url+`.aux.xml`,{responseType:`xml`,signal:e?.signal});return u(t)}catch{return null}}async _fetchAuxiliaryTable(e){try{let{data:t}=await this.request(this.url+`.vat.dbf`,{responseType:`array-buffer`,signal:e?.signal}),n=l(t);return n?.recordSet?k.fromJSON(n.recordSet):null}catch{return null}}};e([r()],j.prototype,`_files`,void 0),e([r()],j.prototype,`_headerInfo`,void 0),e([r()],j.prototype,`_bufferSize`,void 0),e([r()],j.prototype,`_chunkSize`,void 0),e([r()],j.prototype,`_fileSize`,void 0),e([r()],j.prototype,`_headerChunks`,void 0),e([r({type:String,json:{write:!0}})],j.prototype,`datasetFormat`,void 0),j=e([i(`esri.layers.raster.datasets.TIFFRaster`)],j);function M(e){let t=S(e),{width:n,height:r,tileWidth:i,tileHeight:c,planes:l,pixelType:u,compression:f,firstPyramidLevel:p,maximumPyramidLevel:m,pyramidBlockWidth:h,pyramidBlockHeight:g,pyramidResolutions:_,tileBoundary:v,affine:y,metadata:b,colormap:x}=t,C=t.extent.spatialReference?.wkt||t.extent.spatialReference?.wkid,w=d(C),T=!!t.isPseudoGeographic;w??=(T=!0,new s({wkid:3857}));let k=new a({...t.extent,spatialReference:w}),A=k?new o({x:k.xmin,y:k.ymax,spatialReference:w}):new o({x:0,y:0}),j=new O({blockWidth:i,blockHeight:c,pyramidBlockWidth:h,pyramidBlockHeight:g,compression:f,origin:A,firstPyramidLevel:p,maximumPyramidLevel:m,pyramidResolutions:_,blockBoundary:v}),M=new o({x:(k.xmax-k.xmin)/n,y:(k.ymax-k.ymin)/r,spatialReference:w}),N=b?{BandProperties:b.bandProperties,DataType:b.dataType}:{},P=new D({width:n,height:r,bandCount:l,pixelType:u,pixelSize:M,storageInfo:j,spatialReference:w,isPseudoSpatialReference:T,keyProperties:N,extent:k,colormap:x,statistics:b?b.statistics:null});if(y?.length&&(P.nativeExtent=new a({xmin:-.5,ymin:.5-r,xmax:n-.5,ymax:.5,spatialReference:w}),P.transform=new E({polynomialOrder:1,forwardCoefficients:[y[2]+y[0]/2,y[5]-y[3]/2,y[0],y[3],-y[1],-y[4]]}),P.extent=P.transform.forwardTransform(P.nativeExtent),P.pixelSize=new o({x:(k.xmax-k.xmin)/n,y:(k.ymax-k.ymin)/r,spatialReference:w}),j.origin.x=-.5,j.origin.y=.5),_){let{x:e,y:t}=P.pixelSize;_.forEach(n=>{n.x*=e,n.y*=t})}return{imageInfo:t,rasterInfo:P}}function N(e,t){if(t.statistics=e.statistics??t.statistics,t.histograms=e.histograms,e.histograms&&t.statistics==null&&(t.statistics=T(e.histograms)),e.transform&&t.transform==null){t.transform=e.transform,t.nativeExtent=t.extent;let n=t.transform.forwardTransform(t.nativeExtent);t.pixelSize=new o({x:(n.xmax-n.xmin)/t.width,y:(n.ymax-n.ymin)/t.height,spatialReference:t.spatialReference}),t.extent=n}t.isPseudoSpatialReference&&e.spatialReference&&(t.spatialReference=e.spatialReference,t.extent.spatialReference=t.nativeExtent.spatialReference=t.storageInfo.origin.spatialReference=t.spatialReference)}const P=j;export{P as default};
2
+ import{__decorate as e}from"tslib";import t from"../../../core/Error.js";import"../../../core/has.js";import n from"../../../core/Logger.js";import{property as r,subclass as i}from"../../../core/accessorSupport/decorators.js";import a from"../../../geometry/Extent.js";import o from"../../../geometry/Point.js";import s from"../../../geometry/SpatialReference.js";import c from"./BaseRaster.js";import{parse as l}from"./DBFParser.js";import{parsePAMInfo as u,parseSpatialReference as d}from"./pamParser.js";import{parseSignature as f,getPyramidIFDs as p,getMaskIFDs as m,parseIFD as h,parseGeoKeyDirectory as g,parseXMP as _,parseFieldValues as v,isBSQConfig as y,getTagNumericValues as b,getTagFirstNumericValue as x,getImageInfo as S}from"../formats/tiffParser.js";import{tiffTags as C,ifdTags as w}from"../formats/tiffTag.js";import{estimateStatisticsFromHistograms as T}from"../functions/stretchUtils.js";import E from"../transforms/PolynomialTransform.js";import D from"../../support/RasterInfo.js";import O from"../../support/RasterStorageInfo.js";import k from"../../../rest/support/FeatureSet.js";const A=`none-tiled tiff is not optimized for access, convert to COG and retry.`;let j=class extends c{constructor(){super(...arguments),this._bufferSize=1048576,this._chunkSize=10*1024**2,this._fileSize=-1,this._headerChunks=[],this.datasetFormat=`TIFF`,this.headerInfo=null}async fetchRawTile(e,t,n,r={}){if(!this.headerInfo?.isSupported||this.isBlockOutside(e,t,n))return null;let i=await this._fetchRawTiffTile(e,t,n,!1,r);if(i!=null&&this.headerInfo.hasMaskBand){let a=await this._fetchRawTiffTile(e,t,n,!0,r);a!=null&&a.pixels[0]instanceof Uint8Array&&(i.mask=a.pixels[0])}return i}async _open(e){this.datasetName=this.url.slice(this.url.lastIndexOf(`/`)+1,this.url.lastIndexOf(`.`)),await this._readHeader(e?.signal),await this._fetchAllAuxData(),this.ioConfig.skipMapInfo&&this.updateImageSpaceRasterInfo(this.rasterInfo),this.updateTileInfo()}async _readHeader(e){try{let n=await this._fetchHeaderData(0,this._bufferSize,e);if(!n)throw new t(`tiffraster:open`,`failed to open url `+this.url);let{littleEndian:r,firstIFDPos:i,isBigTiff:a}=f(n),o=[],s={fileChunk:n,posIFD:i,fileOffset:0};await this._readIFDs(o,s,r,a?8:4,e);let{imageInfo:c,rasterInfo:l}=M(o),u=p(o),d=m(o);this.headerInfo={littleEndian:r,isBigTiff:a,ifds:o,pyramidIFDs:u,maskIFDs:d,...c},this._set(`rasterInfo`,l),this._validateHeader()}finally{this._headerChunks.length=0}}_validateHeader(){let e=this.headerInfo;if(!e.isSupported)throw new t(`tiffraster:open`,`this tiff is not supported: `+e.message);if(!e.tileWidth||!e.tileHeight)throw new t(`tiffraster:open`,A);this.rasterInfo.isPseudoSpatialReference&&n.getLogger(this).warn(`The spatial reference for this tiff is unsupported. Only EPSG spatial reference codes and Esri WKTs are supported.`);let r=e.ifds[0],i=r.get(`PREDICTOR`)?.values?.[0];if(r.get(`SAMPLEFORMAT`)?.values?.[0]===3&&i===2)throw new t(`tiffraster:open`,`unsupported horizontal difference encoding. Predictor=3 is supported for floating point data`)}async _fetchHeaderData(e,n,r){let i=this._getCachedHeaderData(e,n);if(i)return i;let a=Math.floor(e/this._bufferSize)*this._bufferSize,o=a+Math.max(1,Math.ceil((n-a)/this._bufferSize))*this._bufferSize,s=this._getMissingHeaderRanges(a,o).map(async e=>{let{from:t,to:n}=e,i=await this._fetchOffsets(t,n,r),a=this._fileSize;return{chunk:i,fileOffset:t,isEOF:a>0?t+i.byteLength>=a:i.byteLength<n-t+1}}),c=await Promise.all(s);this._headerChunks.push(...c),this._headerChunks.sort((e,t)=>e.fileOffset-t.fileOffset);let l=this._getCachedHeaderData(e,n);if(!l)throw new t(`tiffraster:open`,`failed to fetch byte range ${e}-${n} from ${this.url}`);return l}_getCachedHeaderData(e,t){let n=[],r=e;for(let{chunk:i,fileOffset:a,isEOF:o}of this._headerChunks){if(a+i.byteLength-1<r)continue;if(a>r)return null;let s=r-a,c=Math.min(t-a+1,i.byteLength);if(n.push({chunk:i,start:s,end:c}),r=a+c,r>t||o&&c===i.byteLength){let t=new Uint8Array(r-e),i=0;for(let e of n){let n=new Uint8Array(e.chunk,e.start,e.end-e.start);t.set(n,i),i+=n.byteLength}return t.buffer}}return null}_getMissingHeaderRanges(e,t){let n=[],r=(e,t)=>{let r=Math.floor(e/this._bufferSize)*this._bufferSize,i=Math.ceil(t/this._bufferSize)*this._bufferSize;n.push({from:r,to:i})},i=e;for(let{chunk:e,fileOffset:a,isEOF:o}of this._headerChunks){let s=a+e.byteLength-1;if(!(s<i)&&(a>i&&r(i,Math.min(a-1,t)),i=Math.max(i,s+1),i>t||o))return n}return i<=t&&r(i,t),n}async _validateOrFetchHeaderBuffer(e,n){let{fileChunk:r,fileOffset:i,posIFD:a}=e;if(a+8>=r.byteLength||a<0){if(i=a+i,i<0)throw new t(`tiffraster:open`,`invalid IFD position ${i}. failed to open url ${this.url}`);r=await this._fetchHeaderData(i,i+this._bufferSize/2,n),a=0}return{fileChunk:r,fileOffset:i,posIFD:a}}async _readIFDs(e,n,r,i=4,a){if(!n.posIFD)return null;n=await this._validateOrFetchHeaderBuffer(n,a);let o=await this._readIFD(n,r,C,i,a);if(!o?.ifd)throw new t(`tiffraster:open`,`cannot parse tiff header. failed to open url `+this.url);if(e.push(o.ifd),!o.nextIFD)return null;n.posIFD=o.nextIFD-n.fileOffset,await this._readIFDs(e,n,r,i,a)}async _readIFD(e,n,r=C,i=4,a){let{fileChunk:o,posIFD:s,fileOffset:c}=e;if(!e.fileChunk)return null;let l=h(o,n,s,c,r,i);if(l.success){let{ifd:e}=l;if(!e)throw new t(`tiffraster:open`,`cannot parse tiff header. failed to open url `+this.url);if(!this.ioConfig.loadFullMetadata&&r===C&&(!e.has(`TILEWIDTH`)||!e.has(`TILELENGTH`)))throw new t(`tiffraster:open`,A);let i=[];e.forEach(e=>{e.values||i.push(e)}),i.length>0&&await this._fillOffsets(i,n,l.nextIFD,a),g(e),_(e);for(let[t,r]of w){let i=e.get(t),l=i?.data!=null&&Array.from(i.data.values()).some(e=>e.values==null&&e.offlineOffsetSize!=null);if(i&&(!i.data||l)){s=i.valueOffset-c;let e=await this._validateOrFetchHeaderBuffer({fileChunk:o,posIFD:s,fileOffset:c},a);i.data=(await this._readIFD(e,n,r,4,a))?.ifd}}return l}return l.requiredBufferSize?(o=await this._fetchHeaderData(c,c+s+l.requiredBufferSize+8,a),o.byteLength<s+l.requiredBufferSize?null:(e.fileChunk=o,e.fileOffset=c,this._readIFD(e,n,r,i,a))):null}async _fillOffsets(e,t,n,r){let i=e.filter(e=>e.offlineOffsetSize!=null);if(i.length===0)return;let a=i.map(e=>e.offlineOffsetSize),o=Math.min.apply(null,a.map(e=>e[0])),s=Math.max.apply(null,a.map(e=>e[0]+e[1])),c=a.length===1||s-o<=this._bufferSize;if(!c&&a.length>1&&(a.sort((e,t)=>e[0]-t[0]),c=a.reduce((e,t)=>e===t[0]?t[0]+t[1]:0,a[0][0])===s),c){let e=Math.max(s,o+this._bufferSize/4),n=await this._fetchHeaderData(o,e,r);i.forEach(e=>v(n,t,e,o));return}let l=i.map(async e=>{let n=e.offlineOffsetSize,i=await this._fetchHeaderData(n[0],n[1]+n[0],r);v(i,t,e,n[0])});await Promise.all(l)}async _fetchOffsets(e,t,n){let r=[],i=this._chunkSize;this._fileSize>0&&(t=Math.min(t,this._fileSize-1));let a=Math.ceil((t-e+1)/i),o=e;for(let e=0;e<a;e++)r.push(this.request(this.url,{range:{from:o,to:e===a-1?t:o+i-1},responseType:`array-buffer`,signal:n})),o+=i;let s=await Promise.all(r);if(this._fileSize===-1&&s[0].httpStatus===206){let e=s[0].getHeader?.(`Content-Range`),t=Number(e?.split(`/`)[1]);Number.isFinite(t)&&(this._fileSize=t)}if(s.length===1)return s[0].data;let c=s.reduce((e,t)=>e+t.data.byteLength,0),l=new Uint8Array(c),u=0;for(let e of s)l.set(new Uint8Array(e.data),u),u+=e.data.byteLength;return l.buffer}async _fetchRawTiffTile(e,t,n,r,i={}){let a=this._getTileLocation(e,t,n,r);if(!a)return null;let{ranges:o,actualTileWidth:s,actualTileHeight:c,ifd:l}=a,u=o.map(e=>this.request(this.url,{range:e,responseType:`array-buffer`,signal:i.signal})),d=await Promise.all(u),f=d.map(e=>e.data.byteLength).reduce((e,t)=>e+t),p=d.length===1?d[0].data:new ArrayBuffer(f),m=[0],h=[0];if(d.length>1){let e=new Uint8Array(p);for(let t=0,n=0;t<d.length;t++){let r=d[t].data;e.set(new Uint8Array(r),n),m[t]=n,n+=r.byteLength,h[t]=r.byteLength}}let{blockWidth:g,blockHeight:_}=this.getBlockWidthHeight(e),v=await this.decodePixelBlock(p,{format:`tiff`,customOptions:{headerInfo:this.headerInfo,ifd:l,offsets:m,sizes:h},width:g,height:_,planes:null,pixelType:null});if(v==null)return null;if(s!==g||c!==_){let e=v.mask;if(e)for(let t=0;t<_;t++){let n=t*g;if(t<c)for(let t=s;t<g;t++)e[n+t]=0;else for(let t=0;t<g;t++)e[n+t]=0}else{e=new Uint8Array(g*_),v.mask=e;for(let t=0;t<c;t++){let n=t*g;for(let t=0;t<s;t++)e[n+t]=1}}}return v}_getTileLocation(e,t,n,r=!1){let{firstPyramidLevel:i,blockBoundary:a}=this.rasterInfo.storageInfo,o=e===0?0:e-(i-1),{headerInfo:s}=this;if(!s)return null;let c=r?s.maskIFDs[o]:o===0?s.ifds[0]:s.pyramidIFDs[o-1];if(!c)return null;let l=y(c,s),u=b(c,`TILEOFFSETS`),d=b(c,`TILEBYTECOUNTS`);if(!u?.length||!d?.length)return null;let{minRow:f,minCol:p,maxRow:m,maxCol:h}=a[o];if(t>m||n>h||t<f||n<p)return null;let g=x(c,`IMAGEWIDTH`),_=x(c,`IMAGELENGTH`),v=x(c,`TILEWIDTH`),S=x(c,`TILELENGTH`),C=[];if(l){let{bandCount:e}=this.rasterInfo;for(let r=0;r<e;r++){let e=r*(m+1)*(h+1)+t*(h+1)+n;C[r]={from:u[e],to:u[e]+d[e]-1}}}else{let e=t*(h+1)+n;C.push({from:u[e],to:u[e]+d[e]-1})}for(let e=0;e<C.length;e++)if(C[e].from==null||!C[e].to||C[e].to<0)return null;return{ranges:C,ifd:c,actualTileWidth:n===h&&g%v||v,actualTileHeight:t===m&&_%S||S}}async _fetchAllAuxData(e){if(this.ioConfig.skipMapInfo)return;let{rasterInfo:t}=this,{skipExtensions:n=[]}=this.ioConfig,r=n.includes(`aux.xml`)?Promise.resolve(null):this._fetchAuxiliaryMetaData(e),i=!n.includes(`vat.dbf`)&&t.bandCount===1&&t.pixelType===`u8`?this._fetchAuxiliaryTable(e):Promise.resolve(null),[a,o]=await Promise.all([r,i]);a!=null&&N(a,t),o!=null&&(t.attributeTable=o,t.keyProperties.DataType=`thematic`)}async _fetchAuxiliaryMetaData(e){try{let{data:t}=await this.request(this.url+`.aux.xml`,{responseType:`xml`,signal:e?.signal});return u(t)}catch{return null}}async _fetchAuxiliaryTable(e){try{let{data:t}=await this.request(this.url+`.vat.dbf`,{responseType:`array-buffer`,signal:e?.signal}),n=l(t);return n?.recordSet?k.fromJSON(n.recordSet):null}catch{return null}}};e([r()],j.prototype,`_bufferSize`,void 0),e([r()],j.prototype,`_chunkSize`,void 0),e([r()],j.prototype,`_fileSize`,void 0),e([r()],j.prototype,`_headerChunks`,void 0),e([r({type:String,json:{write:!0}})],j.prototype,`datasetFormat`,void 0),e([r()],j.prototype,`headerInfo`,void 0),j=e([i(`esri.layers.raster.datasets.TIFFRaster`)],j);function M(e){let t=S(e),{width:n,height:r,tileWidth:i,tileHeight:c,planes:l,pixelType:u,compression:f,firstPyramidLevel:p,maximumPyramidLevel:m,pyramidBlockWidth:h,pyramidBlockHeight:g,pyramidResolutions:_,tileBoundary:v,affine:y,metadata:b,colormap:x}=t,C=t.extent.spatialReference?.wkt||t.extent.spatialReference?.wkid,w=d(C),T=!!t.isPseudoGeographic;w??=(T=!0,new s({wkid:3857}));let k=new a({...t.extent,spatialReference:w}),A=k?new o({x:k.xmin,y:k.ymax,spatialReference:w}):new o({x:0,y:0}),j=new O({blockWidth:i,blockHeight:c,pyramidBlockWidth:h,pyramidBlockHeight:g,compression:f,origin:A,firstPyramidLevel:p,maximumPyramidLevel:m,pyramidResolutions:_,blockBoundary:v}),M=new o({x:(k.xmax-k.xmin)/n,y:(k.ymax-k.ymin)/r,spatialReference:w}),N=b?{BandProperties:b.bandProperties,DataType:b.dataType}:{},P=new D({width:n,height:r,bandCount:l,pixelType:u,pixelSize:M,storageInfo:j,spatialReference:w,isPseudoSpatialReference:T,keyProperties:N,extent:k,colormap:x,statistics:b?b.statistics:null});if(y?.length&&(P.nativeExtent=new a({xmin:-.5,ymin:.5-r,xmax:n-.5,ymax:.5,spatialReference:w}),P.transform=new E({polynomialOrder:1,forwardCoefficients:[y[2]+y[0]/2,y[5]-y[3]/2,y[0],y[3],-y[1],-y[4]]}),P.extent=P.transform.forwardTransform(P.nativeExtent),P.pixelSize=new o({x:(k.xmax-k.xmin)/n,y:(k.ymax-k.ymin)/r,spatialReference:w}),j.origin.x=-.5,j.origin.y=.5),_){let{x:e,y:t}=P.pixelSize;_.forEach(n=>{n.x*=e,n.y*=t})}return{imageInfo:t,rasterInfo:P}}function N(e,t){if(t.statistics=e.statistics??t.statistics,t.histograms=e.histograms,e.histograms&&t.statistics==null&&(t.statistics=T(e.histograms)),e.transform&&t.transform==null){t.transform=e.transform,t.nativeExtent=t.extent;let n=t.transform.forwardTransform(t.nativeExtent);t.pixelSize=new o({x:(n.xmax-n.xmin)/t.width,y:(n.ymax-n.ymin)/t.height,spatialReference:t.spatialReference}),t.extent=n}t.isPseudoSpatialReference&&e.spatialReference&&(t.spatialReference=e.spatialReference,t.extent.spatialReference=t.nativeExtent.spatialReference=t.storageInfo.origin.spatialReference=t.spatialReference)}const P=j;export{P as default};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import e from"../../../core/Error.js";import{throwIfAborted as t}from"../../../core/promiseUtils.js";import n from"../../../geometry/Extent.js";import r from"../../../geometry/Point.js";import{getByteCount as i}from"../formats/pixelRangeUtils.js";import{convertPixelSize as a,snapToRaster as o,clip as s}from"../functions/clipUtils.js";import{transformPixels as c}from"../functions/pixelTransformUtils.js";import{mapPixelValueToAttribute as l,mosaic as u,pixelIdFieldName as d,convertPixelBlockToFeatures as f,getValidPixels as p,countCategoricalPixels as m}from"../functions/pixelUtils.js";import{load as h,projectPolygon as g}from"../functions/rasterProjectionHelper.js";import{computeBoxStatistics as _,computeStatisticsHistograms as v}from"../functions/stretchUtils.js";import y from"../../support/Field.js";import b from"../../support/PixelBlock.js";import{getBandNames as x}from"../../../renderers/support/rasterRendererHelper.js";import S from"../../../rest/support/ImageIdentifyParameters.js";const C=2**30,w=2048,T=2**20;async function E(e,t){return e.type===`imagery`?await e.generateRasterInfo(e.rasterFunction,t):e.raster.rasterInfo}function D(e){let{rasterInfo:t,geometry:n,pixelSize:i,downsampleOnly:s=!1,maxPixelCountForDownsample:c}=e;if(!i)return!0;if(!s)return!1;let l=a(i,t.spatialReference);if(l.x+l.y<=t.pixelSize.x+t.pixelSize.y)return!0;if(c==null)return!1;let u=n?.type===`polyline`?n.extent:n??t.extent,d=new r({x:t.pixelSize.x,y:t.pixelSize.y,spatialReference:t.spatialReference}),f=o(t,u,d);return f.width*f.height<=c}function O(e){let t=[new y({name:d,alias:`Pixel ID`,type:`oid`})],{pixelType:n}=e,r=n===`f32`?`single`:n===`f64`?`double`:`integer`;return x(e).forEach(e=>{t.push(new y({name:e,alias:e,type:r}))}),t.map(e=>e.toJSON())}async function k(t,n){if(t.spatialReference.equals(n))return t;if(t.type===`polyline`){let{projectExecute:r}=await import(`../../../geometry/operators/projectOperator.js`),i=r(t,n);if(i==null)throw new e(`read-pixels`,`failed to project the geometry into the layer's spatial reference`);return i}if(t.type===`extent`||t.rings[0].length<20){let[{lengthExecute:e},{densifyExecute:r}]=await Promise.all([import(`../../../geometry/operators/lengthOperator.js`),import(`../../../geometry/operators/densifyOperator.js`)]),i=e(t,{unit:`meters`})/100;t=r(t,i,{unit:`meters`}),await h(),t=g(t,n)}return t}async function A(e,t,n=!1){let{spatialReference:i}=e,a=t?.geometry,s=await k(a??e.extent,i),c=s.type===`extent`?s:s.extent,l=a!=null&&(a.type!==`extent`||!a.spatialReference.equals(i))?s:void 0,u=new r({x:e.pixelSize.x,y:e.pixelSize.y,spatialReference:i}),d=!!t?.autoResample,f=d?u:t?.pixelSize??u,{extent:p,width:m,height:h}=o(e,c,f);if(!d)return{extent:p,clipGeometry:l,width:m,height:h,pixelSize:f};let g=e.storageInfo?.pyramidScalingFactor??2,{x:_,y:v}=f,y=t?.maxPixelCount??T;for(;m*h>y&&(!n||Math.max(m,h)>1024);)_*=g,v*=g,m/=g,h/=g;return m=Math.round(m),h=Math.round(h),{extent:p,clipGeometry:l,width:m,height:h,pixelSize:new r({x:_,y:v,spatialReference:i})}}async function*j(e,r,i=!1,a){let{extent:o,clipGeometry:c,width:l,height:u}=r,d=o.width/l,f=o.height/u,p=Math.ceil(l/w),m=Math.ceil(u/w),h=d*w,g=f*w,{xmin:_,xmax:v,ymin:y,ymax:b}=o,x=m*p,S={bandIds:r.bandIds?.length?r.bandIds:void 0,interpolation:`nearest`,...a};for(let r=0;r<m;r++)for(let a=0;a<p;a++){t(S);let l=new n({xmin:_+a*h,xmax:i?Math.min(v,_+(a+1)*h):_+(a+1)*h,ymax:b-r*g,ymin:i?Math.max(y,b-(r+1)*g):b-(r+1)*g,spatialReference:o.spatialReference}),u={row:r,col:a},m=r*p+a+1;if(c&&!l.intersects(c)){yield{extent:l,pixelBlock:null,id:u,total:x,current:m};continue}let C=i?Math.round(l.width/d):w,T=i?Math.round(l.height/f):w,{pixelBlock:E}=await e.fetchPixels(l,C,T,S).catch(()=>({pixelBlock:void 0}));E&&c&&(E=await s(E,l,c)),yield{extent:l,pixelBlock:E,id:u,total:x,current:m}}}async function*M(e,n,r){let i=await E(e,r),a=O(i),o=j(e,await A(i,{...n,geometry:n?.geometry??i.extent}),!0,r),s=i.width;for await(let c of o){if(!c.pixelBlock){yield{...c};continue}let o=J(e),{pixelBlock:l}=c,{statistics:u,histograms:d}=await K({pixelBlock:l,rasterJobHandler:o},r),f=c;f.statistics=u,f.histograms=d;let p=c.id.row*i.width*w+c.id.col*w;t(r),f.featureSet=await q({pixelBlock:l,extent:c.extent,fields:a,skipFactor:n?.skipFactor??1,rasterJobHandler:o,pixelIdOffset:p,imageRowSize:s},r),t(r),yield f}}function N(t,n,r){let a=i(n),{width:o,height:s}=t;if(o*s*a>C)throw new e(`fetch-pixels`,`failed to fetch pixels as pixel byte count exceeds the 1GB limit`);if(r&&o*s>r)throw new e(`fetch-pixels`,`failed to fetch pixels as pixel count exceeds the ${r} limit`)}async function P(t,n,r){if(!n.geometry)throw new e(`fetch-pixels`,`geometry is required to fetch pixel feature set`);let i=await E(t),a=await A(i,n,!0);N(a,i.pixelType);let{extent:o,pixelSize:s}=a,c=Math.round(i.extent.width/s.x),l=O(i),u={fields:l,features:[]},d=u.features,{maxPixelCount:f}=n,p=!!n.autoResample&&f!=null&&a.width*a.height>f,m=p?1:n.skipFactor??1,h=a.width<=w||a.height<=w,g=j(t,a,m===1||h,r);for await(let e of g){if(!e.pixelBlock)continue;let n=J(t),a=Math.floor((i.extent.ymax-e.extent.ymax)/s.y)*c+Math.floor((e.extent.xmin-i.extent.xmin)/s.x),o=await q({pixelBlock:e.pixelBlock,extent:e.extent,fields:l,skipFactor:m,rasterJobHandler:n,pixelIdOffset:a,imageRowSize:c},r);if(o?.features?.length){let{features:e}=o,t=e.length;for(let n=0;n<t;n++){let t=e.pop();d.push(t)}}}if(p&&f){let e=f/(n.skipFactor??1)**2;if(d.length>e){let t=d.length/e,n=[...d],r=d.length-1;d.length=0;for(let i=0,a=0;i<e-1;i++){a+=t;let e=Math.round(a);e<r&&d.push(n[e])}}}return{extent:o,featureSet:u,pixelSize:s}}async function F(e,t,n){let{geometry:r}=t;if(r.type===`multipoint`)return I(e,r,n);if(r.type===`polyline`)return z(e,r,n);let i=await Y(e,{geometry:r},n);return i?_(i):null}async function I(e,t,n){let r=await E(e,n),i=t.points.map((e,n)=>t.getPoint(n)).map(t=>L(e,t,n)),a=(await Promise.all(i)).filter(e=>e!=null);if(a.length<=1)return R(a[0]);let o=a[0].map((e,t)=>a.map(e=>e[t]));return _(new b({pixels:o,pixelType:r.pixelType}))}async function L(e,t,n){if(e.type===`imagery`){let r=await e.identify(new S({geometry:t,returnCatalogItems:!1}),n).catch(()=>null);return r?.value==null||r.value.includes(`NoData`)?null:r.value.replaceAll(`, `,` `).split(` `).map(e=>Number(e))}return(await e.identify(t,n).catch(()=>null))?.value}function R(e){return e?.map(e=>({min:e,max:e,avg:e,median:e,quartile1:e,quartile3:e}))}async function z(e,t,n){let r=await W(e,{geometry:t},n),{bandCount:i,pixelType:a}=await E(e,n),o=Array(i).fill(0).map(()=>b.createEmptyBand(a,r.length)),s=0;for(let e=0;e<r.length;e++){let t=r[e];if(t.value!=null){s++;for(let n=0;n<i;n++)o[n][e]=t.value[n]}}return s!==r.length&&o.forEach((e,t)=>{o[t]=e.subarray(0,s)}),_(new b({pixels:o,pixelType:a}))}async function B(t,n,r){let i=await E(t,r);if(!i.attributeTable)return null;let a=i.attributeTable.clone(),o=a.fields.find(e=>e.name.toLowerCase()===`value`),s=a.fields.find(e=>e.name.toLowerCase()===`count`);if(!o)throw new e(`compute-attribute-table`,`Value field not found in attribute table`);s||(s=new y({name:`Count`,alias:`Count`,type:`double`}),a.fields.push(s),a.features.forEach(e=>{e.attributes[s.name]=0}));let{geometry:c,pixelSize:l,downsampleOnly:u,maxPixelCountForDownsample:d}=n,f=new Map;return await G(t,{geometry:c,pixelSize:D({rasterInfo:i,geometry:c,pixelSize:l,downsampleOnly:u,maxPixelCountForDownsample:d})?void 0:l},(e,t)=>m(e,f),r),a.features.forEach(e=>{let t=e.attributes[o.name];e.attributes[s.name]=f.get(t)??0}),a}async function V(e,t,n){let{geometry:r}=t;if(r.type===`point`)return L(e,r,n);if(r.type===`multipoint`){let t=r.points.map((e,t)=>r.getPoint(t)).map(t=>L(e,t,n)),i=(await Promise.all(t)).filter(e=>e!=null);return i.length===0?null:H(i).map(e=>e/i.length)}let i=(await G(e,{geometry:r},(e,t)=>U(e),n))?.filter(e=>e.count>0);if(!i?.length)return null;let a=H(i.map(e=>e.bandSum)),o=i.map(e=>e.count).reduce((e,t)=>e+t);return a.map(e=>e/o)}function H(e){return e.reduce((e,t)=>e.map((e,n)=>e+t[n]))}function U(e){let{width:t,height:n,pixels:r,mask:i}=e,a=Array(r.length).fill(0),o=0;for(let e=0;e<n;e++)for(let n=0;n<t;n++){let s=e*t+n;if(!i||i[s]){for(let e=0;e<r.length;e++)a[e]+=r[e][s];o++}}return{bandSum:a,count:o}}async function W(e,t,n){return(await G(e,{geometry:t.geometry},p,n))?.flat()??[]}async function G(n,r,i,a){let o=n.spatialReference,{geometry:c}=r;if(c.type===`polyline`&&!c.spatialReference.equals(o)){let{projectExecute:t}=await import(`../../../geometry/operators/projectOperator.js`),n=t(c,o);if(n==null)throw new e(`read-pixels`,`failed to fetch pixels`);c=n}let l=await k(c.type===`polyline`?c.extent:c,o),u=c.type===`polyline`?c:l,d=await A(await E(n,a),{geometry:l,autoResample:!1,pixelSize:r?.pixelSize}),f=[],p=j(n,d,!0,a);for await(let e of p){if(!e.pixelBlock)continue;let{extent:n}=e,r=i(await s(e.pixelBlock,n,u),n);f.push(r),t(a)}return f}async function K(e,t){let{rasterJobHandler:n}=e,{pixelBlock:r}=e,{statistics:i,histograms:a}=n?await n.computeStatisticsHistograms({pixelBlock:r},t):v(r);return{statistics:i,histograms:a}}async function q(e,t){let{extent:n,fields:r,skipFactor:i,rasterJobHandler:a,pixelIdOffset:o,imageRowSize:s}=e,{pixelBlock:c}=e,l=r.map(({name:e})=>e),u=a?await a.convertPixelBlockToFeatures({pixelBlock:c,extent:n,fieldNames:l,skipFactor:i,pixelIdOffset:o,imageRowSize:s},t):f({pixelBlock:c,extent:n,fieldNames:l,skipFactor:i,pixelIdOffset:o,imageRowSize:s});return u?{fields:r,features:u}:void 0}function J(e){return`_rasterJobHandler`in e?e._rasterJobHandler:null}async function Y(e,t,n){let r=await E(e);t={...t,maxPixelCount:t.maxPixelCount??2**28};let i=await A(r,t);i.bandIds=t.bandIds?.length?t.bandIds:void 0,N(i,r.pixelType,t.maxPixelCount);let{width:a,height:o}=i;if(a<=w&&o<=w){let t=i.bandIds?.length?i.bandIds:void 0,{pixelBlock:r}=await e.fetchPixels(i.extent,a,o,{bandIds:t,interpolation:`nearest`,...n});return r}let s=[],c=j(e,i,!1,n);for await(let e of c)s.push(e.pixelBlock);if(!s.some(e=>e!=null))return null;let l=Math.ceil(a/w),d=Math.ceil(o/w),f={width:l*w,height:d*w},p,m=J(e);return p=m?(await m.mosaicAndTransform({srcPixelBlocks:s,srcMosaicSize:f,destDimension:f},{...n,transferPixelsToWorker:!0}))?.pixelBlock:u(s,f),p}async function X(t,n,r){if(!n.geometry)throw new e(`compute-statistics-histograms`,`geometry is required to fetch pixel feature set`);let{pixelSize:i,downsampleOnly:a,maxPixelCountForDownsample:o}=n,s=await E(t,r),u=D({rasterInfo:s,geometry:n.geometry,pixelSize:i,downsampleOnly:a,maxPixelCountForDownsample:o})?void 0:i,d=await Y(t,{...n,pixelSize:u},r);if(!d)throw new e(`compute-statistics-histograms`,`failed to get intersecting pixels`);let{valueAttributeFieldName:f}=n;f&&f.toLowerCase()!==`value`&&(d=l(d,s,f));let p=J(t),{transformType:m}=n;if(m){let e={lambda:n.lambda,shift:n.shift};d=p?await p.transformPixels({pixelBlock:d,transformType:m,transformParameters:e},{...r,transferPixelsToWorker:!0}):c(d,m,e)}let h=n.histogramSize??void 0;return p?await p.computeStatisticsHistograms({pixelBlock:d,histogramSize:h,includeSkewnessKurtosis:!0},{...r,transferPixelsToWorker:!0}):v(d,{histogramSize:h,includeSkewnessKurtosis:!0})}export{F as computeBoxStatistics,B as computeRasterAttributeTable,X as computeStatisticsHistograms,M as createPixelFeatureSetCursor,P as fetchPixelFeatureSet,V as identifyAveragePixelValue,W as readIntersectingPixels};
2
+ import e from"../../../core/Error.js";import{throwIfAborted as t}from"../../../core/promiseUtils.js";import n from"../../../geometry/Extent.js";import r from"../../../geometry/Point.js";import{getByteCount as i}from"../formats/pixelRangeUtils.js";import{convertPixelSize as a,snapToRaster as o,clip as s}from"../functions/clipUtils.js";import{transformPixels as c}from"../functions/pixelTransformUtils.js";import{mapPixelValueToAttribute as l,mosaic as u,pixelIdFieldName as d,convertPixelBlockToFeatures as f,getValidPixels as p,countCategoricalPixels as m}from"../functions/pixelUtils.js";import{load as h,projectPolygon as g}from"../functions/rasterProjectionHelper.js";import{computeBoxStatistics as _,computeStatisticsHistograms as v}from"../functions/stretchUtils.js";import y from"../../support/Field.js";import b from"../../support/PixelBlock.js";import{getBandNames as x}from"../../../renderers/support/rasterRendererHelper.js";import S from"../../../rest/support/ImageIdentifyParameters.js";const C=2**30,w=2048,T=2**20;async function E(e,t){return e.type===`imagery`?await e.generateRasterInfo(e.rasterFunction,t):e.raster.rasterInfo}function D(e){let{rasterInfo:t,geometry:n,pixelSize:i,downsampleOnly:s=!1,maxPixelCountForDownsample:c}=e;if(!i)return!0;if(!s)return!1;let l=a(i,t.spatialReference);if(l.x+l.y<=t.pixelSize.x+t.pixelSize.y)return!0;if(c==null)return!1;let u=n?.type===`polyline`?n.extent:n??t.extent,d=new r({x:t.pixelSize.x,y:t.pixelSize.y,spatialReference:t.spatialReference}),f=o(t,u,d);return f.width*f.height<=c}function O(e){let t=[new y({name:d,alias:`Pixel ID`,type:`oid`})],{pixelType:n}=e,r=n===`f32`?`single`:n===`f64`?`double`:`integer`;return x(e).forEach(e=>{t.push(new y({name:e,alias:e,type:r}))}),t.map(e=>e.toJSON())}async function k(t,n){if(t.spatialReference.equals(n))return t;if(t.type===`polyline`){let{projectExecute:r}=await import(`../../../geometry/operators/projectOperator.js`),i=r(t,n);if(i==null)throw new e(`read-pixels`,`failed to project the geometry into the layer's spatial reference`);return i}if(t.type===`extent`||t.rings[0].length<20){let[{lengthExecute:e},{densifyExecute:r}]=await Promise.all([import(`../../../geometry/operators/lengthOperator.js`),import(`../../../geometry/operators/densifyOperator.js`)]),i=e(t,{unit:`meters`})/100;t=r(t,i,{unit:`meters`}),await h(),t=g(t,n)}return t}async function A(e,t,n=!1){let{spatialReference:i}=e,a=t?.geometry,s=await k(a??e.extent,i),c=s.type===`extent`?s:s.extent,l=a!=null&&(a.type!==`extent`||!a.spatialReference.equals(i))?s:void 0,u=new r({x:e.pixelSize.x,y:e.pixelSize.y,spatialReference:i}),d=!!t?.autoResample,f=d?u:t?.pixelSize??u,{extent:p,width:m,height:h}=o(e,c,f);if(!d)return{extent:p,clipGeometry:l,width:m,height:h,pixelSize:f};let g=e.storageInfo?.pyramidScalingFactor??2,{x:_,y:v}=f,y=t?.maxPixelCount??T;for(;m*h>y&&(!n||Math.max(m,h)>1024);)_*=g,v*=g,m/=g,h/=g;return m=Math.round(m),h=Math.round(h),{extent:p,clipGeometry:l,width:m,height:h,pixelSize:new r({x:_,y:v,spatialReference:i})}}async function*j(e,r,i=!1,a){let{extent:o,clipGeometry:c,width:l,height:u}=r,d=o.width/l,f=o.height/u,p=Math.ceil(l/w),m=Math.ceil(u/w),h=d*w,g=f*w,{xmin:_,xmax:v,ymin:y,ymax:b}=o,x=m*p,S={bandIds:r.bandIds?.length?r.bandIds:void 0,interpolation:`nearest`,...a};for(let a=0;a<m;a++)for(let l=0;l<p;l++){t(S);let u=new n({xmin:_+l*h,xmax:i?Math.min(v,_+(l+1)*h):_+(l+1)*h,ymax:b-a*g,ymin:i?Math.max(y,b-(a+1)*g):b-(a+1)*g,spatialReference:o.spatialReference}),m={row:a,col:l},C=a*p+l+1;if(c&&!u.intersects(c)){yield{extent:u,pixelBlock:null,id:m,total:x,current:C};continue}let T=i?Math.round(u.width/d):w,E=i?Math.round(u.height/f):w,{pixelBlock:D}=await e.fetchPixels(u,T,E,S).catch(()=>({pixelBlock:void 0}));D&&c&&(D=await s(D,u,c,{thinPolyline:r?.thinPolyline??!1})),yield{extent:u,pixelBlock:D,id:m,total:x,current:C}}}async function*M(e,n,r){let i=await E(e,r),a=O(i),o=j(e,await A(i,{...n,geometry:n?.geometry??i.extent}),!0,r),s=i.width;for await(let c of o){if(!c.pixelBlock){yield{...c};continue}let o=J(e),{pixelBlock:l}=c,{statistics:u,histograms:d}=await K({pixelBlock:l,rasterJobHandler:o},r),f=c;f.statistics=u,f.histograms=d;let p=c.id.row*i.width*w+c.id.col*w;t(r),f.featureSet=await q({pixelBlock:l,extent:c.extent,fields:a,skipFactor:n?.skipFactor??1,rasterJobHandler:o,pixelIdOffset:p,imageRowSize:s},r),t(r),yield f}}function N(t,n,r){let a=i(n),{width:o,height:s}=t;if(o*s*a>C)throw new e(`fetch-pixels`,`failed to fetch pixels as pixel byte count exceeds the 1GB limit`);if(r&&o*s>r)throw new e(`fetch-pixels`,`failed to fetch pixels as pixel count exceeds the ${r} limit`)}async function P(t,n,r){if(!n.geometry)throw new e(`fetch-pixels`,`geometry is required to fetch pixel feature set`);let i=await E(t),a=await A(i,n,!0);N(a,i.pixelType);let{extent:o,pixelSize:s}=a,c=Math.round(i.extent.width/s.x),l=O(i),u={fields:l,features:[]},d=u.features,{maxPixelCount:f}=n,p=!!n.autoResample&&f!=null&&a.width*a.height>f,m=p?1:n.skipFactor??1,h=a.width<=w||a.height<=w,g=j(t,a,m===1||h,r);for await(let e of g){if(!e.pixelBlock)continue;let n=J(t),a=Math.floor((i.extent.ymax-e.extent.ymax)/s.y)*c+Math.floor((e.extent.xmin-i.extent.xmin)/s.x),o=await q({pixelBlock:e.pixelBlock,extent:e.extent,fields:l,skipFactor:m,rasterJobHandler:n,pixelIdOffset:a,imageRowSize:c},r);if(o?.features?.length){let{features:e}=o,t=e.length;for(let n=0;n<t;n++){let t=e.pop();d.push(t)}}}if(p&&f){let e=f/(n.skipFactor??1)**2;if(d.length>e){let t=d.length/e,n=[...d],r=d.length-1;d.length=0;for(let i=0,a=0;i<e-1;i++){a+=t;let e=Math.round(a);e<r&&d.push(n[e])}}}return{extent:o,featureSet:u,pixelSize:s}}async function F(e,t,n){let{geometry:r}=t;if(r.type===`multipoint`)return I(e,r,n);if(r.type===`polyline`)return z(e,r,n);let i=await Y(e,{geometry:r},n);return i?_(i):null}async function I(e,t,n){let r=await E(e,n),i=t.points.map((e,n)=>t.getPoint(n)).map(t=>L(e,t,n)),a=(await Promise.all(i)).filter(e=>e!=null);if(a.length<=1)return R(a[0]);let o=a[0].map((e,t)=>a.map(e=>e[t]));return _(new b({pixels:o,pixelType:r.pixelType}))}async function L(e,t,n){if(e.type===`imagery`){let r=await e.identify(new S({geometry:t,returnCatalogItems:!1}),n).catch(()=>null);return r?.value==null||r.value.includes(`NoData`)?null:r.value.replaceAll(`, `,` `).split(` `).map(e=>Number(e))}return(await e.identify(t,n).catch(()=>null))?.value}function R(e){return e?.map(e=>({min:e,max:e,avg:e,median:e,quartile1:e,quartile3:e}))}async function z(e,t,n){let r=await W(e,{geometry:t},n),{bandCount:i,pixelType:a}=await E(e,n),o=Array(i).fill(0).map(()=>b.createEmptyBand(a,r.length)),s=0;for(let e=0;e<r.length;e++){let t=r[e];if(t.value!=null){s++;for(let n=0;n<i;n++)o[n][e]=t.value[n]}}return s!==r.length&&o.forEach((e,t)=>{o[t]=e.subarray(0,s)}),_(new b({pixels:o,pixelType:a}))}async function B(t,n,r){let i=await E(t,r);if(!i.attributeTable)return null;let a=i.attributeTable.clone(),o=a.fields.find(e=>e.name.toLowerCase()===`value`),s=a.fields.find(e=>e.name.toLowerCase()===`count`);if(!o)throw new e(`compute-attribute-table`,`Value field not found in attribute table`);s||(s=new y({name:`Count`,alias:`Count`,type:`double`}),a.fields.push(s),a.features.forEach(e=>{e.attributes[s.name]=0}));let{geometry:c,pixelSize:l,downsampleOnly:u,maxPixelCountForDownsample:d}=n,f=new Map;return await G(t,{geometry:c,pixelSize:D({rasterInfo:i,geometry:c,pixelSize:l,downsampleOnly:u,maxPixelCountForDownsample:d})?void 0:l},(e,t)=>m(e,f),r),a.features.forEach(e=>{let t=e.attributes[o.name];e.attributes[s.name]=f.get(t)??0}),a}async function V(e,t,n){let{geometry:r}=t;if(r.type===`point`)return L(e,r,n);if(r.type===`multipoint`){let t=r.points.map((e,t)=>r.getPoint(t)).map(t=>L(e,t,n)),i=(await Promise.all(t)).filter(e=>e!=null);return i.length===0?null:H(i).map(e=>e/i.length)}let i=(await G(e,{geometry:r},(e,t)=>U(e),n))?.filter(e=>e.count>0);if(!i?.length)return null;let a=H(i.map(e=>e.bandSum)),o=i.map(e=>e.count).reduce((e,t)=>e+t);return a.map(e=>e/o)}function H(e){return e.reduce((e,t)=>e.map((e,n)=>e+t[n]))}function U(e){let{width:t,height:n,pixels:r,mask:i}=e,a=Array(r.length).fill(0),o=0;for(let e=0;e<n;e++)for(let n=0;n<t;n++){let s=e*t+n;if(!i||i[s]){for(let e=0;e<r.length;e++)a[e]+=r[e][s];o++}}return{bandSum:a,count:o}}async function W(e,t,n){return(await G(e,{geometry:t.geometry},p,n))?.flat()??[]}async function G(n,r,i,a){let o=n.spatialReference,{geometry:c}=r;if(c.type===`polyline`&&!c.spatialReference.equals(o)){let{projectExecute:t}=await import(`../../../geometry/operators/projectOperator.js`),n=t(c,o);if(n==null)throw new e(`read-pixels`,`failed to fetch pixels`);c=n}let l=await k(c.type===`polyline`?c.extent:c,o),u=c.type===`polyline`?c:l,d=await A(await E(n,a),{geometry:l,autoResample:!1,pixelSize:r?.pixelSize}),f=[],p=j(n,d,!0,a);for await(let e of p){if(!e.pixelBlock)continue;let{extent:n}=e,r=i(await s(e.pixelBlock,n,u),n);f.push(r),t(a)}return f}async function K(e,t){let{rasterJobHandler:n}=e,{pixelBlock:r}=e,{statistics:i,histograms:a}=n?await n.computeStatisticsHistograms({pixelBlock:r},t):v(r);return{statistics:i,histograms:a}}async function q(e,t){let{extent:n,fields:r,skipFactor:i,rasterJobHandler:a,pixelIdOffset:o,imageRowSize:s}=e,{pixelBlock:c}=e,l=r.map(({name:e})=>e),u=a?await a.convertPixelBlockToFeatures({pixelBlock:c,extent:n,fieldNames:l,skipFactor:i,pixelIdOffset:o,imageRowSize:s},t):f({pixelBlock:c,extent:n,fieldNames:l,skipFactor:i,pixelIdOffset:o,imageRowSize:s});return u?{fields:r,features:u}:void 0}function J(e){return`_rasterJobHandler`in e?e._rasterJobHandler:null}async function Y(e,t,n){let r=await E(e);t={...t,maxPixelCount:t.maxPixelCount??2**28};let i=await A(r,t);i.bandIds=t.bandIds?.length?t.bandIds:void 0,N(i,r.pixelType,t.maxPixelCount);let{width:a,height:o}=i;if(a<=w&&o<=w){let t=i.bandIds?.length?i.bandIds:void 0,{pixelBlock:r}=await e.fetchPixels(i.extent,a,o,{bandIds:t,interpolation:`nearest`,...n});return r}let s=[],c=j(e,i,!1,n);for await(let e of c)s.push(e.pixelBlock);if(!s.some(e=>e!=null))return null;let l=Math.ceil(a/w),d=Math.ceil(o/w),f={width:l*w,height:d*w},p,m=J(e);return p=m?(await m.mosaicAndTransform({srcPixelBlocks:s,srcMosaicSize:f,destDimension:f},{...n,transferPixelsToWorker:!0}))?.pixelBlock:u(s,f),p}async function X(t,n,r){if(!n.geometry)throw new e(`compute-statistics-histograms`,`geometry is required to fetch pixel feature set`);let{pixelSize:i,downsampleOnly:a,maxPixelCountForDownsample:o}=n,s=await E(t,r),u=D({rasterInfo:s,geometry:n.geometry,pixelSize:i,downsampleOnly:a,maxPixelCountForDownsample:o})?void 0:i,d=await Y(t,{...n,pixelSize:u},r);if(!d)throw new e(`compute-statistics-histograms`,`failed to get intersecting pixels`);let{valueAttributeFieldName:f}=n;f&&f.toLowerCase()!==`value`&&(d=l(d,s,f));let p=J(t),{transformType:m}=n;if(m){let e={lambda:n.lambda,shift:n.shift};d=p?await p.transformPixels({pixelBlock:d,transformType:m,transformParameters:e},{...r,transferPixelsToWorker:!0}):c(d,m,e)}let h=n.histogramSize??void 0;return p?await p.computeStatisticsHistograms({pixelBlock:d,histogramSize:h,includeSkewnessKurtosis:!0},{...r,transferPixelsToWorker:!0}):v(d,{histogramSize:h,includeSkewnessKurtosis:!0})}export{F as computeBoxStatistics,B as computeRasterAttributeTable,X as computeStatisticsHistograms,M as createPixelFeatureSetCursor,P as fetchPixelFeatureSet,V as identifyAveragePixelValue,W as readIntersectingPixels};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{getMetersPerUnitForSR as e}from"../../../core/units.js";import t from"../../../geometry/Extent.js";import n from"../../../geometry/Point.js";import r from"../../support/PixelBlock.js";function i(t,n){if(t.spatialReference.equals(n))return t;let r=e(t.spatialReference),i=e(n);if(r===i)return t;let a=r/i;return{x:t.x*a,y:t.y*a}}async function a(e,t,n){if(n.type===`extent`)return l(e,t,n);let{width:i,height:a}=e,s=i*a,c=new Uint8Array(s),{intersectsExecute:d}=await import(`../../../geometry/operators/intersectsOperator.js`);if(!d(t,n))return new r({pixelType:e.pixelType,width:i,height:a,mask:c,maskIsAlpha:!1,pixels:[...e.pixels]});if(n.type===`polyline`)return u(e,t,n);let{containsExecute:f}=await import(`../../../geometry/operators/containsOperator.js`);return f(n,t)?e:o(e,t,n)}function o(e,t,n){if(!e)return e;let{width:i,height:a}=e,o=s({geometry:n,size:[i,a],srcExtent:t,srcMask:e.mask});return new r({pixelType:e.pixelType,width:i,height:a,mask:o,maskIsAlpha:!1,pixels:[...e.pixels]})}function s(e){let{geometry:t,size:n,srcExtent:r,srcMask:i}=e,[a,o]=n,s,l=r.width/a,u=r.height/o,{xmin:d,ymax:f}=r;if(t.type===`extent`){let e=(t.xmin-d)/l,n=(t.xmax-d)/l,r=(f-t.ymax)/u,i=(f-t.ymin)/u;s=[[[e,r],[e,i],[n,i],[n,r],[e,r]]]}else s=t.rings.map(e=>e.map(([e,t])=>[(e-d)/l,(f-t)/u]));return c(s,n,i)}function c(e,t,n){let[r,i]=t,a=new OffscreenCanvas(r,i).getContext(`2d`);a.fillStyle=`#f00`,a.beginPath(),e.forEach(e=>{a.moveTo(e[0][0],e[0][1]);for(let t=0;t<e.length;t++)a.lineTo(e[t][0],e[t][1]);a.closePath()}),a.fill();let o=a.getImageData(0,0,r,i).data,s=r*i,c=new Uint8Array(s),l=!1;for(let e=0;e<s;e++)(!n||n[e])&&(o[e*4+3]>127?c[e]=255:l=!0);return l||n?c:void 0}function l(e,t,n){let{width:i,height:a}=e,o=new Uint8Array(i*a),s=t.width/i,c=t.height/a;if(n.width/s<.5||n.height/c<.5)return new r({pixelType:e.pixelType,width:i,height:a,mask:o,pixels:[...e.pixels]});let{xmin:l,xmax:u,ymin:d,ymax:f}=t,{xmin:p,xmax:m,ymin:h,ymax:g}=n,_=Math.max(l,p),v=Math.min(u,m),y=Math.max(d,h),b=Math.min(f,g),x=s*.5,S=c*.5;if(v-_<x||b-y<S||v<l+x||_>u-x||y>f-S||b<d+S)return new r({pixelType:e.pixelType,width:i,height:a,mask:o,pixels:[...e.pixels]});let C=Math.max(0,(_-l)/s),w=Math.min(i,Math.max(0,(v-l)/s)),T=Math.max(0,(f-b)/c),E=Math.min(a,Math.max(0,(f-y)/c)),D=Math.round(C),O=Math.round(w)-1,k=Math.round(T),A=Math.round(E)-1,j=D===O&&C%1>.5&&w%1<.5,M=k===A&&T%1>.5&&E%1<.5;if(j||M)return new r({pixelType:e.pixelType,width:i,height:a,mask:o,pixels:[...e.pixels]});if(D===0&&k===0&&O===i&&A===a)return e;let N=e.mask;for(let e=k;e<=A;e++)for(let t=D;t<=O;t++){let n=e*i+t;o[n]=N?N[n]:255}return new r({pixelType:e.pixelType,width:i,height:a,mask:o,pixels:[...e.pixels]})}function u(e,t,n){let{width:i,height:a}=e,o=new Uint8Array(i*a),s=t.width/i,c=t.height/a,{xmin:l,ymax:u}=t,{paths:d}=n,f=e.mask;for(let e=0;e<d.length;e++){let t=d[e];for(let e=0;e<t.length-1;e++){let[n,r]=t[e],[d,p]=t[e+1],m=Math.min(r,p),h=Math.max(0,Math.floor((u-Math.max(r,p))/c)),g=Math.min(a-1,Math.floor((u-m)/c));if(!(g<h)){if(h===g){let e=Math.min(n,d),t=Math.max(n,d),r=Math.max(0,Math.floor((e-l)/s)),a=Math.min(i-1,Math.floor((t-l)/s));if(a<r)continue;let c=h*i;for(let e=c+r;e<=c+a;e++)o[e]=f?f[e]:255}else{let e=(d-n)/(p-r),t=(n-l)/s,a=e/s,m=c*a;for(let e=h;e<=g;e++){let n=a*(u-e*c-r)+t,s=Math.max(0,Math.floor(m>0?n-m:n)),l=Math.min(i-1,Math.floor(m>0?n:n-m));if(l<s)continue;let d=e*i;for(let e=d+s;e<=d+l;e++)o[e]=f?f[e]:255}}}}}return new r({pixelType:e.pixelType,width:i,height:a,mask:o,pixels:[...e.pixels]})}function d(e,t){let{extent:r}=f(e,t,new n({x:e.pixelSize.x,y:e.pixelSize.y,spatialReference:e.spatialReference})),{extent:i}=e.extent;if(r.xmax=Math.min(r.xmax,i.xmax),r.ymax=Math.min(r.ymax,i.ymax),r.xmin<r.xmax&&r.ymin<r.ymax){let{x:t,y:n}=e.pixelSize,i=Math.round(r.width/t),a=Math.round(r.height/n);e.extent=r,e.width=i,e.height=a}}function f(e,n,r,a=!0){let{spatialReference:o}=e,{x:s,y:c}=i(r,o),l,u,d,{xmin:f,xmax:p,ymax:m,ymin:h}=n.type===`extent`?n:n.extent,{xmin:g,ymax:_}=e.extent;return a?(f=g+(f>g?s*Math.round((f-g)/s):0),m=_-(m<_?c*Math.round((_-m)/c):0),p=g+(p>g?s*Math.round((p-g)/s):0),h=_-(h<_?c*Math.round((_-h)/c):0),l=new t({xmin:f,ymax:m,xmax:p,ymin:h,spatialReference:o}),u=Math.round(l.width/s),d=Math.round(l.height/c)):(u=Math.floor((p-f)/s+.8),d=Math.floor((m-h)/c+.8),f=g+(f>g?s*Math.floor((f-g)/s+.1):0),m=_-(m<_?c*Math.floor((_-m)/c+.1):0),p=f+u*s,h=m-d*c,l=new t({xmin:f,ymax:m,xmax:p,ymin:h,spatialReference:o})),{extent:l,width:u,height:d}}export{a as clip,d as clipRasterInfo,s as convertGeometryToMask,i as convertPixelSize,f as snapToRaster};
2
+ import{getMetersPerUnitForSR as e}from"../../../core/units.js";import t from"../../../geometry/Extent.js";import n from"../../../geometry/Point.js";import r from"../../support/PixelBlock.js";function i(t,n){if(t.spatialReference.equals(n))return t;let r=e(t.spatialReference),i=e(n);if(r===i)return t;let a=r/i;return{x:t.x*a,y:t.y*a}}async function a(e,t,n,i){if(n.type===`extent`)return l(e,t,n);let{width:a,height:s}=e,c=a*s,d=new Uint8Array(c),{intersectsExecute:p}=await import(`../../../geometry/operators/intersectsOperator.js`);if(!p(t,n))return new r({pixelType:e.pixelType,width:a,height:s,mask:d,maskIsAlpha:!1,pixels:[...e.pixels]});if(n.type===`polyline`)return i?.thinPolyline?f(e,t,n):u(e,t,n);let{containsExecute:m}=await import(`../../../geometry/operators/containsOperator.js`);return m(n,t)?e:o(e,t,n)}function o(e,t,n){if(!e)return e;let{width:i,height:a}=e,o=s({geometry:n,size:[i,a],srcExtent:t,srcMask:e.mask});return new r({pixelType:e.pixelType,width:i,height:a,mask:o,maskIsAlpha:!1,pixels:[...e.pixels]})}function s(e){let{geometry:t,size:n,srcExtent:r,srcMask:i}=e,[a,o]=n,s,l=r.width/a,u=r.height/o,{xmin:d,ymax:f}=r;if(t.type===`extent`){let e=(t.xmin-d)/l,n=(t.xmax-d)/l,r=(f-t.ymax)/u,i=(f-t.ymin)/u;s=[[[e,r],[e,i],[n,i],[n,r],[e,r]]]}else s=t.rings.map(e=>e.map(([e,t])=>[(e-d)/l,(f-t)/u]));return c(s,n,i)}function c(e,t,n){let[r,i]=t,a=new OffscreenCanvas(r,i).getContext(`2d`);a.fillStyle=`#f00`,a.beginPath(),e.forEach(e=>{a.moveTo(e[0][0],e[0][1]);for(let t=0;t<e.length;t++)a.lineTo(e[t][0],e[t][1]);a.closePath()}),a.fill();let o=a.getImageData(0,0,r,i).data,s=r*i,c=new Uint8Array(s),l=!1;for(let e=0;e<s;e++)(!n||n[e])&&(o[e*4+3]>127?c[e]=255:l=!0);return l||n?c:void 0}function l(e,t,n){let{width:i,height:a}=e,o=new Uint8Array(i*a),s=t.width/i,c=t.height/a;if(n.width/s<.5||n.height/c<.5)return new r({pixelType:e.pixelType,width:i,height:a,mask:o,pixels:[...e.pixels]});let{xmin:l,xmax:u,ymin:d,ymax:f}=t,{xmin:p,xmax:m,ymin:h,ymax:g}=n,_=Math.max(l,p),v=Math.min(u,m),y=Math.max(d,h),b=Math.min(f,g),x=s*.5,S=c*.5;if(v-_<x||b-y<S||v<l+x||_>u-x||y>f-S||b<d+S)return new r({pixelType:e.pixelType,width:i,height:a,mask:o,pixels:[...e.pixels]});let C=Math.max(0,(_-l)/s),w=Math.min(i,Math.max(0,(v-l)/s)),T=Math.max(0,(f-b)/c),E=Math.min(a,Math.max(0,(f-y)/c)),D=Math.round(C),O=Math.round(w)-1,k=Math.round(T),A=Math.round(E)-1,j=D===O&&C%1>.5&&w%1<.5,M=k===A&&T%1>.5&&E%1<.5;if(j||M)return new r({pixelType:e.pixelType,width:i,height:a,mask:o,pixels:[...e.pixels]});if(D===0&&k===0&&O===i&&A===a)return e;let N=e.mask;for(let e=k;e<=A;e++)for(let t=D;t<=O;t++){let n=e*i+t;o[n]=N?N[n]:255}return new r({pixelType:e.pixelType,width:i,height:a,mask:o,pixels:[...e.pixels]})}function u(e,t,n){let{width:i,height:a}=e,o=new Uint8Array(i*a),s=t.width/i,c=t.height/a,{xmin:l,ymax:u}=t,{paths:d}=n,f=e.mask;for(let e=0;e<d.length;e++){let t=d[e];for(let e=0;e<t.length-1;e++){let[n,r]=t[e],[d,p]=t[e+1],m=Math.min(r,p),h=Math.max(r,p),g=Math.max(0,Math.floor((u-h)/c)),_=Math.min(a-1,Math.floor((u-m)/c));if(!(_<g)){if(r===p){let e=Math.min(n,d),t=Math.max(n,d),r=Math.max(0,Math.floor((e-l)/s)),a=Math.min(i-1,Math.floor((t-l)/s));if(a<r)continue;let c=g*i;for(let e=c+r;e<=c+a;e++)o[e]=f?f[e]:255}else{let e=(d-n)/(p-r),t=(n-l)/s,a=e/s;for(let e=g;e<=_;e++){let n=Math.min(h,u-e*c),s=Math.max(m,u-(e+1)*c),l=a*(n-r)+t,d=a*(s-r)+t,p=Math.max(0,Math.floor(Math.min(l,d))),g=Math.min(i-1,Math.floor(Math.max(l,d)));if(g<p)continue;let _=e*i;for(let e=_+p;e<=_+g;e++)o[e]=f?f[e]:255}}}}}return new r({pixelType:e.pixelType,width:i,height:a,mask:o,maskIsAlpha:e.maskIsAlpha,pixels:[...e.pixels]})}function d(e){let{size:t,start:n,end:r,outMask:i,srcMask:a}=e,[o,s]=t,[c,l]=n,[u,d]=r;if(Math.max(c,u)<=0||Math.min(c,u)>=o||Math.max(l,d)<=0||Math.min(l,d)>=s)return;let f=Math.abs(u-c),p=Math.abs(d-l);if(f===0&&p===0){let e=Math.floor(c),t=Math.floor(l)*o+e;i[t]=a?a[t]:255;return}let m=p>f;m&&([c,l]=[l,c],[u,d]=[d,u],[f,p]=[p,f],[o,s]=[s,o]),c>u&&([c,u]=[u,c],[l,d]=[d,l]);let h=Math.max(0,Math.floor(c)),g=Math.min(o-1,Math.floor(u)),_=l<=d?1:-1,v=Math.floor(Math.min(l,d)),y=Math.floor(Math.max(l,d)),b=p/f,x=l+(h+.5-c)*_*b,S=_>0?Math.floor(x):Math.ceil(x)-1,C=_>0?x-S:S+1-x;for(let e=h;e<=g;e++){let t=Math.max(v,Math.min(y,S));if(t>=0&&t<s){let n=m?e*s+t:t*o+e;i[n]=a?a[n]:255}C+=b,C>=1&&(S+=_,--C)}}function f(e,t,n){let{width:i,height:a,mask:o}=e,s=new Uint8Array(i*a),c=t.width/i,l=t.height/a,{xmin:u,ymax:f}=t,p=[i,a];for(let e of n.paths)for(let t=0;t<e.length-1;t++){let[n,r]=e[t],[i,a]=e[t+1];d({size:p,start:[(n-u)/c,(f-r)/l],end:[(i-u)/c,(f-a)/l],srcMask:o,outMask:s})}return new r({pixelType:e.pixelType,width:i,height:a,mask:s,maskIsAlpha:e.maskIsAlpha,pixels:[...e.pixels]})}function p(e,t){let{extent:r}=m(e,t,new n({x:e.pixelSize.x,y:e.pixelSize.y,spatialReference:e.spatialReference})),{extent:i}=e.extent;if(r.xmax=Math.min(r.xmax,i.xmax),r.ymax=Math.min(r.ymax,i.ymax),r.xmin<r.xmax&&r.ymin<r.ymax){let{x:t,y:n}=e.pixelSize,i=Math.round(r.width/t),a=Math.round(r.height/n);e.extent=r,e.width=i,e.height=a}}function m(e,n,r,a=!0){let{spatialReference:o}=e,{x:s,y:c}=i(r,o),l,u,d,{xmin:f,xmax:p,ymax:m,ymin:h}=n.type===`extent`?n:n.extent,{xmin:g,ymax:_}=e.extent;return a?(f=g+(f>g?s*Math.round((f-g)/s):0),m=_-(m<_?c*Math.round((_-m)/c):0),p=g+(p>g?s*Math.round((p-g)/s):0),h=_-(h<_?c*Math.round((_-h)/c):0),l=new t({xmin:f,ymax:m,xmax:p,ymin:h,spatialReference:o}),u=Math.round(l.width/s),d=Math.round(l.height/c)):(u=Math.floor((p-f)/s+.8),d=Math.floor((m-h)/c+.8),f=g+(f>g?s*Math.floor((f-g)/s+.1):0),m=_-(m<_?c*Math.floor((_-m)/c+.1):0),p=f+u*s,h=m-d*c,l=new t({xmin:f,ymax:m,xmax:p,ymin:h,spatialReference:o})),{extent:l,width:u,height:d}}export{a as clip,p as clipRasterInfo,s as convertGeometryToMask,i as convertPixelSize,d as rasterizeLineBresenham,m as snapToRaster};
@@ -308,10 +308,11 @@ export default class LabelClass extends JSONSupport {
308
308
  */
309
309
  accessor name: string | null | undefined;
310
310
  /**
311
- * Label offset authored by feature services.
311
+ * The offset distance of the label from its default position.
312
+ * Will be applied to the label's position relative to the [label placement](https://developers.arcgis.com/javascript/latest/references/core/layers/support/LabelClass/#labelPlacement).
312
313
  *
313
314
  * @default 0
314
- * @internal
315
+ * @since 5.2
315
316
  */
316
317
  accessor offsetDistance: number;
317
318
  /**
@@ -3,39 +3,62 @@ import type { Clonable } from "../../core/Clonable.js";
3
3
  import type { JSONSupportMixin } from "../../core/JSONSupport.js";
4
4
  import type { PortalItemProperties } from "../../portal/PortalItem.js";
5
5
 
6
+ /** Properties used to construct a [PortalItemData](https://developers.arcgis.com/javascript/latest/references/core/layers/support/PortalItemData/). */
6
7
  export interface PortalItemDataProperties {
7
- /** The portal item containing the data. */
8
+ /**
9
+ * The portal item that provides the layer's data source. The item's content must be compatible
10
+ * with the consuming layer, such as Parquet data for [ParquetLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/ParquetLayer/) or a geospatial PDF
11
+ * for [GeospatialPDFLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/GeospatialPDFLayer/). Set this to a [PortalItem](https://developers.arcgis.com/javascript/latest/references/core/portal/PortalItem/) instance or its properties;
12
+ * a plain object such as `{ id: "item-id" }` is autocast to a PortalItem.
13
+ * Set the item's [portal](https://developers.arcgis.com/javascript/latest/references/core/portal/PortalItem/#portal) when referencing content outside the default portal.
14
+ */
8
15
  portalItem?: PortalItemProperties;
9
16
  }
10
17
 
11
18
  /**
12
- * Sets an ArcGIS Online [portalItem](https://developers.arcgis.com/javascript/latest/references/core/portal/PortalItem/) as the [data](https://developers.arcgis.com/javascript/latest/references/core/layers/ParquetLayer/#data)
13
- * source for a [ParquetLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/ParquetLayer/) or a [GeospatialPDFLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/GeospatialPDFLayer/).
19
+ * Provides an ArcGIS [portal item](https://developers.arcgis.com/javascript/latest/references/core/portal/PortalItem/) as the data source for a
20
+ * [ParquetLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/ParquetLayer/) or a [GeospatialPDFLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/GeospatialPDFLayer/).
14
21
  *
15
22
  * @since 5.2
16
23
  * @beta
17
24
  * @example
18
- * // Create a parquet layer from arcgis online portal item
25
+ * ```ts
26
+ * import ParquetLayer from "@arcgis/core/layers/ParquetLayer.js";
27
+ * import PortalItemData from "@arcgis/core/layers/support/PortalItemData.js";
28
+ *
29
+ * // Replace the placeholder ID with a portal item containing Parquet data.
19
30
  * const layer = new ParquetLayer({
20
31
  * data: new PortalItemData({
21
32
  * portalItem: {
22
- * id: "parquet-layer-item-id",
33
+ * id: "6ab6f959c1684eb5a54db91644a89747",
23
34
  * },
24
35
  * }),
25
36
  * });
37
+ * ```
26
38
  * @example
27
- * // Create a geospatial PDF layer from an ArcGIS portal item
39
+ * ```ts
40
+ * import GeospatialPDFLayer from "@arcgis/core/layers/GeospatialPDFLayer.js";
41
+ * import PortalItemData from "@arcgis/core/layers/support/PortalItemData.js";
42
+ *
43
+ * // Replace the placeholder ID with a portal item whose URL resolves to a geospatial PDF.
28
44
  * const layer = new GeospatialPDFLayer({
29
45
  * data: new PortalItemData({
30
46
  * portalItem: {
31
- * id: "geospatial-pdf-layer-item-id",
47
+ * id: "0d8613492b1e4598a5edb111f05be7fd",
32
48
  * },
33
49
  * }),
34
50
  * });
51
+ * ```
35
52
  */
36
53
  export default class PortalItemData extends PortalItemDataSuperclass {
37
54
  constructor(properties?: PortalItemDataProperties);
38
- /** The portal item containing the data. */
55
+ /**
56
+ * The portal item that provides the layer's data source. The item's content must be compatible
57
+ * with the consuming layer, such as Parquet data for [ParquetLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/ParquetLayer/) or a geospatial PDF
58
+ * for [GeospatialPDFLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/GeospatialPDFLayer/). Set this to a [PortalItem](https://developers.arcgis.com/javascript/latest/references/core/portal/PortalItem/) instance or its properties;
59
+ * a plain object such as `{ id: "item-id" }` is autocast to a PortalItem.
60
+ * Set the item's [portal](https://developers.arcgis.com/javascript/latest/references/core/portal/PortalItem/#portal) when referencing content outside the default portal.
61
+ */
39
62
  get portalItem(): PortalItem;
40
63
  set portalItem(value: PortalItemProperties);
41
64
  /** The type of data source. */