@arcgis/core 6.0.0-next.30 → 6.0.0-next.32

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 (147) hide show
  1. package/assets/esri/core/workers/RemoteClient.js +1 -1
  2. package/assets/esri/core/workers/chunks/0694c7bcfe71692e2ccf.js +1 -0
  3. package/assets/esri/core/workers/chunks/{e2c6cd8dac01e129ccfe.js → 0e445ec3523de9f2dfa2.js} +1 -1
  4. package/assets/esri/core/workers/chunks/0f6c0d42100c21367e5c.js +1 -0
  5. package/assets/esri/core/workers/chunks/{242a77066ac5cdb5b7d7.js → 14d81280807a3d3c1b7e.js} +1 -1
  6. package/assets/esri/core/workers/chunks/16cda273927ab0a39544.js +1 -0
  7. package/assets/esri/core/workers/chunks/1a3f71c4d97c36050030.js +1 -0
  8. package/assets/esri/core/workers/chunks/{ba4520ddcb6a49988da6.js → 1a8d8274df292d65f82e.js} +1 -1
  9. package/assets/esri/core/workers/chunks/{0b4481b57a611b15f65c.js → 1eaf8bfdd3765a90ccc2.js} +1 -1
  10. package/assets/esri/core/workers/chunks/29cc6b1705418b1be5d7.js +1 -0
  11. package/assets/esri/core/workers/chunks/2de077c7b971f2c215a6.js +1 -0
  12. package/assets/esri/core/workers/chunks/{fefdd10bdd5a4c8d8ed0.js → 360c944c610efa2051fc.js} +3 -3
  13. package/assets/esri/core/workers/chunks/{8ca2bb3c0551bb1898b6.js → 3fdcc383bbd9cf0d274c.js} +1 -1
  14. package/assets/esri/core/workers/chunks/{cc97e4fd0dacad970a23.js → 46453ebfee17b5421d9d.js} +1 -1
  15. package/assets/esri/core/workers/chunks/{64b360625c68cb863a08.js → 487c46d5245cfb35c4bb.js} +1 -1
  16. package/assets/esri/core/workers/chunks/{ad21757d78e372fa2ed6.js → 4a979fce1c971b614a18.js} +1 -1
  17. package/assets/esri/core/workers/chunks/{b5eff28cf482d920b9ea.js → 4d18b48d4a282a0f341c.js} +1 -1
  18. package/assets/esri/core/workers/chunks/4d8833f48348cbbcc947.js +1 -0
  19. package/assets/esri/core/workers/chunks/52a0aa2d19a495e48ab1.js +1 -0
  20. package/assets/esri/core/workers/chunks/{865cebc5c982c040ab6f.js → 55a9eaeb152a3abada67.js} +1 -1
  21. package/assets/esri/core/workers/chunks/572aec57593a08b8045b.js +1 -0
  22. package/assets/esri/core/workers/chunks/{9d40786c5ceface786ba.js → 601e1d020b8115497944.js} +1 -1
  23. package/assets/esri/core/workers/chunks/6029773458ab98600f67.js +1 -0
  24. package/assets/esri/core/workers/chunks/6b5c073dddd89d06ed80.js +1 -0
  25. package/assets/esri/core/workers/chunks/{7030a4d0714a35995a58.js → 6bb191b19ce43a27f205.js} +1 -1
  26. package/assets/esri/core/workers/chunks/6f6d1873753a9c6994aa.js +1 -0
  27. package/assets/esri/core/workers/chunks/7084dd6e10c6c1393e92.js +1 -0
  28. package/assets/esri/core/workers/chunks/7cc9d7a88b64e25fce14.js +1 -0
  29. package/assets/esri/core/workers/chunks/7e211d8a8ad6c6a7cf3e.js +1 -0
  30. package/assets/esri/core/workers/chunks/853563c66ecf58d53d36.js +1 -0
  31. package/assets/esri/core/workers/chunks/{c90388932a7825d9d933.js → 85de980c5b296ec69323.js} +1 -1
  32. package/assets/esri/core/workers/chunks/89dc49e784f7ba3b93ea.js +1 -0
  33. package/assets/esri/core/workers/chunks/8da2a10318f49d0dc73a.js +1 -0
  34. package/assets/esri/core/workers/chunks/8e6276ddd8d094c61f08.js +1 -0
  35. package/assets/esri/core/workers/chunks/{71f792a20077aa739f87.js → a607541959169741a943.js} +1 -1
  36. package/assets/esri/core/workers/chunks/b2d6b1ac9fbb50c7c8ab.js +1 -0
  37. package/assets/esri/core/workers/chunks/b657363113f4a37e634b.js +1 -0
  38. package/assets/esri/core/workers/chunks/b9cb92858a576eb6aa06.js +1 -0
  39. package/assets/esri/core/workers/chunks/{12b84262dedc6b393136.js → d9a240a3c6bf85124474.js} +1 -1
  40. package/assets/esri/core/workers/chunks/{8f008eedb11685ee2048.js → e096c1d9d53af74d3207.js} +1 -1
  41. package/assets/esri/core/workers/chunks/e4e2edfdc85dd14e66d4.js +1 -0
  42. package/assets/esri/core/workers/chunks/f4d91d470ca5fea0bd26.js +1 -0
  43. package/assets/esri/core/workers/chunks/f717005e14a7e9141df7.js +1 -0
  44. package/assets/esri/core/workers/chunks/f75eec2cbc541eec9712.js +1 -0
  45. package/assets/esri/core/workers/chunks/fcc3902d6d9eda6f09f5.js +1 -0
  46. package/assets/esri/core/workers/chunks/{28a821de9dbf10324033.js → fd031150d3a7f896e6b3.js} +1 -1
  47. package/config.js +1 -1
  48. package/core/scheduling.js +1 -1
  49. package/geometry/Mesh.d.ts +2 -125
  50. package/geometry/Mesh.js +1 -1
  51. package/geometry/support/GlobalCoordinateSystem.js +2 -0
  52. package/geometry/support/LocalCoordinateSystem.js +2 -0
  53. package/geometry/support/boundedPlane.js +1 -1
  54. package/geometry/support/coordinateSystem.js +1 -1
  55. package/geometry/support/meshErrors.js +1 -1
  56. package/geometry/support/plane.js +1 -1
  57. package/geometry/support/polygonUtils.js +1 -1
  58. package/geometry/support/ray.js +1 -1
  59. package/geometry/support/sphere.js +1 -1
  60. package/interfaces.d.ts +0 -3
  61. package/kernel.js +1 -1
  62. package/layers/SceneLayer.js +1 -1
  63. package/layers/graphics/controllers/I3SOnDemandController.js +1 -1
  64. package/layers/knowledgeGraph/KnowledgeGraphLayerDataManager.js +1 -1
  65. package/layers/mixins/ArcGISImageService.js +1 -1
  66. package/layers/raster/functions/rasterProjectionHelper.js +1 -1
  67. package/layers/support/featureLayerUtils.js +1 -1
  68. package/package.json +2 -2
  69. package/support/arcadeUtils.js +1 -1
  70. package/views/2d/engine/webgl/SpriteMosaic.js +1 -1
  71. package/views/2d/interactive/editingTools/TransformTool.js +1 -1
  72. package/views/2d/interactive/editingTools/manipulations/ScaleManipulation.js +1 -1
  73. package/views/2d/layers/ImageryLayerView2D.js +1 -1
  74. package/views/3d/analysis/LineOfSight/LineOfSightConfiguration.js +1 -1
  75. package/views/3d/analysis/LineOfSight/LineOfSightEditTool.js +1 -1
  76. package/views/3d/analysis/LineOfSight/LineOfSightItemTool.js +1 -1
  77. package/views/3d/analysis/LineOfSight/LineOfSightManipulators.js +1 -1
  78. package/views/3d/analysis/ShadowCastAnalysisView3D.js +1 -1
  79. package/views/3d/analysis/Slice/SliceController.js +1 -1
  80. package/views/3d/analysis/Slice/SliceTool.js +1 -1
  81. package/views/3d/analysis/Slice/sliceToolUtils.js +1 -1
  82. package/views/3d/analysis/Viewshed/ViewshedFieldOfViewManipulation.js +1 -1
  83. package/views/3d/analysis/Viewshed/ViewshedScaleOrientManipulation.js +1 -1
  84. package/views/3d/environment/SunLighting.d.ts +10 -8
  85. package/views/3d/environment/VirtualLighting.d.ts +10 -8
  86. package/views/3d/interactive/editingTools/transform/extentTransform/ExtentRotate.js +1 -1
  87. package/views/3d/interactive/editingTools/transform/extentTransform/ExtentScale.js +1 -1
  88. package/views/3d/interactive/editingTools/transform/extentTransform/extentUtils.js +1 -1
  89. package/views/3d/layers/graphics/Deconflictor.js +1 -1
  90. package/views/3d/layers/graphics/Graphics3DPathSymbolLayer.js +1 -1
  91. package/views/3d/layers/graphics/GraphicsDeconflictor.js +1 -1
  92. package/views/3d/state/ScreenSizePerspective.js +1 -1
  93. package/views/3d/support/RenderCoordsHelper.js +1 -1
  94. package/views/3d/support/ViewSlice.js +1 -1
  95. package/views/3d/support/hitTest.js +1 -1
  96. package/views/3d/support/renderInfoUtils/polygon.js +1 -1
  97. package/views/3d/terrain/PatchGeometryFactory.js +1 -1
  98. package/views/3d/terrain/PlanarPatch.js +1 -1
  99. package/views/3d/terrain/SphericalPatch.js +1 -1
  100. package/views/3d/webgl-engine/lib/Path.js +1 -1
  101. package/views/3d/webgl-engine/lib/PathBuilder.js +1 -1
  102. package/views/3d/webgl-engine/lib/PathExtruder.js +1 -1
  103. package/views/3d/webgl-engine/lib/PathGeometry.js +1 -1
  104. package/views/3d/webgl-engine/lib/SliceHelper.js +1 -1
  105. package/views/3d/webgl-engine/lib/intersectorUtils.js +1 -1
  106. package/views/3d/webgl-engine/lib/pathGeometryUtils.js +1 -1
  107. package/views/interactive/editGeometry/support/editPlaneUtils.js +1 -1
  108. package/views/interactive/snapping/FeatureSnappingEngine.js +1 -1
  109. package/views/interactive/snapping/featureSources/featureServiceSource/tileUtils.js +1 -1
  110. package/views/support/TextureCompressionWorker.js +1 -1
  111. package/views/webgl/Texture.js +1 -1
  112. package/webscene/Environment.d.ts +1 -1
  113. package/widgets/BatchAttributeForm/BatchAttributeFormViewModel.js +1 -1
  114. package/widgets/BatchAttributeForm/expressions/ExpressionsManager.js +1 -1
  115. package/widgets/BatchAttributeForm/inputs/RelationshipElementInput.js +1 -1
  116. package/widgets/BatchAttributeForm/inputs/support/createBatchFormInputs.js +1 -1
  117. package/widgets/BatchAttributeForm.js +1 -1
  118. package/widgets/FeatureForm.js +1 -1
  119. package/widgets/ShadowCast/ShadowCastViewModel.js +1 -1
  120. package/assets/esri/core/workers/chunks/02335385b1476fe322eb.js +0 -1
  121. package/assets/esri/core/workers/chunks/07b726a46864501b90a0.js +0 -1
  122. package/assets/esri/core/workers/chunks/189321d88026bd7e6d3e.js +0 -1
  123. package/assets/esri/core/workers/chunks/18d47ab571b613fbe719.js +0 -1
  124. package/assets/esri/core/workers/chunks/1967b9c96045a5802d08.js +0 -1
  125. package/assets/esri/core/workers/chunks/199a7f97916679e0257c.js +0 -1
  126. package/assets/esri/core/workers/chunks/1d96fbad881a7d14a950.js +0 -1
  127. package/assets/esri/core/workers/chunks/1dc6f093028530a492e6.js +0 -1
  128. package/assets/esri/core/workers/chunks/2cd60fd062d954322c1f.js +0 -1
  129. package/assets/esri/core/workers/chunks/2d3e0e4442dbc6ec6def.js +0 -1
  130. package/assets/esri/core/workers/chunks/2f5d014d6a72108b0b3a.js +0 -1
  131. package/assets/esri/core/workers/chunks/3105336a05f38a95ebea.js +0 -1
  132. package/assets/esri/core/workers/chunks/4419732baf3459a80e6d.js +0 -1
  133. package/assets/esri/core/workers/chunks/4fb2fcc95f852bf8f86c.js +0 -1
  134. package/assets/esri/core/workers/chunks/59bc55880e6fd8ce20c0.js +0 -1
  135. package/assets/esri/core/workers/chunks/5f787809b74eed7b9a91.js +0 -1
  136. package/assets/esri/core/workers/chunks/6a7de221cea4426cb490.js +0 -1
  137. package/assets/esri/core/workers/chunks/7a0b4dc0cda190367a39.js +0 -1
  138. package/assets/esri/core/workers/chunks/7d3f7940815fa5dc244e.js +0 -1
  139. package/assets/esri/core/workers/chunks/999c23da883eb11cb29e.js +0 -1
  140. package/assets/esri/core/workers/chunks/9bc3afe7013ef4ae737b.js +0 -1
  141. package/assets/esri/core/workers/chunks/bab1d010970d98c25470.js +0 -1
  142. package/assets/esri/core/workers/chunks/c4f78a481f43cfae7b63.js +0 -1
  143. package/assets/esri/core/workers/chunks/dcf6024dc19428ff2b9d.js +0 -1
  144. package/assets/esri/core/workers/chunks/e04fb83ab2634bc15cc7.js +0 -1
  145. package/assets/esri/core/workers/chunks/ee0dc906cc7979080329.js +0 -1
  146. package/assets/esri/core/workers/chunks/f0d0ed155275c2e6d3da.js +0 -1
  147. package/chunks/boundedPlane.js +0 -2
@@ -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 has from"../../../core/has.js";import n from"../../../core/Logger.js";import{destroyMaybe as r}from"../../../core/maybe.js";import i from"../../../core/PooledArray.js";import{EsriPromiseMixin as a}from"../../../core/Promise.js";import{isAbortError as o}from"../../../core/promiseUtils.js";import{watch as s,sync as c,initial as l}from"../../../core/reactiveUtils.js";import{property as u,subclass as d}from"../../../core/accessorSupport/decorators.js";import{runUntracked as f}from"../../../core/accessorSupport/tracking.js";import{exactEquals as p}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{UpdatingHandles as m}from"../../../core/support/UpdatingHandles.js";import{create as h,fromValues as g}from"../../../geometry/support/aaBoundingRect.js";import{viewingModeFromString as _}from"../../../views/ViewingMode.js";import{I3SClientNodeLoader as v}from"../../../views/3d/layers/i3s/I3SClientNodeLoader.js";import{I3SDataRequester as y}from"../../../views/3d/layers/i3s/I3SDataRequester.js";import{addCallback as b}from"../../../views/3d/layers/i3s/I3SFrameTask.js";import{I3SIndex as x}from"../../../views/3d/layers/i3s/I3SIndex.js";import S from"../../../views/3d/layers/i3s/I3SLodHandling.js";import C from"../../../views/3d/layers/i3s/I3SNodeLoader.js";import{getVertexCrs as w,getIndexCrs as T,findIntersectingNodes as E}from"../../../views/3d/layers/i3s/I3SUtil.js";import D from"../../../views/3d/layers/i3s/I3SViewportQueries.js";import{projectElevationUpdateExtent as O}from"../../../views/3d/support/elevationUpdateExtentUtils.js";import{toBoundingRect as k}from"../../../views/3d/support/extentUtils.js";import{minQuality as A}from"../../../views/3d/support/MemoryController.js";import{PromiseQueue as j}from"../../../views/support/PromiseQueue.js";import{noBudget as M}from"../../../views/support/Scheduler.js";const N=1e4,P=1e-4;let F=class extends a(t){get isMeshPyramid(){return this.layer.profile===`mesh-pyramids`||this.layer.store?.lodType===`MeshPyramid`}get isGraphics3D(){return this.layer.profile===`points`}get useMaximumNumberOfFeatures(){return!this.isMeshPyramid&&(this.layer.priority==null||this.layer.priority===`High`)}get indexRequester(){return new y(this.layer.customParameters,this.layer.apiKey)}get dataRequester(){return new y(this.layer.customParameters,this.layer.apiKey)}get crsVertex(){return w(this.layer)}get crsIndex(){return T(this.layer)}get layer(){return this.layerView.layer}get updating(){return this.running||this._updatingHandles.updating}get rootNodeVisible(){return f(()=>{if(this._index){let e=this._index.rootNode;if(e)return this._updateViewData(),this._index.isNodeVisible(e.index)}return!0})}get index(){return this._index}get requiredAttributes(){return this._requiredAttributes}constructor(e){super(e),this.featureTarget=5e4,this.fixedFeatureTarget=!1,this._updatingHandles=new m,this.running=!0,this.updatingProgress=1,this.leavesReached=!1,this.worker=null,this._featureLOD=1,this._stableFeatureLOD=!1,this._isIdle=!1,this._cameraDirty=!0,this._invisibleDirty=!1,this._newLoadingNodes=new i({deallocator:null}),this._modificationsNodeFilteringArray=new i,this._downloadingCount=0,this._loadingNodes=new Map,this._updatingNodes=new Map,this._progressMaxNumNodes=1,this._requiredAttributes=[],this._requiredAttributesDirty=!0,this._updatesDisabled=!1,this.disableIDBCache=!1,this._disableMemCache=!1,this._restartNodeLoading=!1,this._fields=null,this._attributeStorageInfo=null,this._idleQueue=new j,this._elevationUpdateNodes=new i({deallocator:null}),this._errorCount=0}initialize(){let{layerView:e,layer:t}=this;this._disableMemCache=!e.loadCachedGPUData||!e.addCachedGPUData,this._lodHandling=new S(e),this._defaultGeometrySchema=t.store.defaultGeometrySchema,this.disableIDBCache=!!has(`disable-feature:idb-cache`),`fields`in t&&(this._fields=t.fields,this._attributeStorageInfo=t.attributeStorageInfo),this.addResolvingPromise(Promise.all([t.indexInfo,t.when(),e.when()]).then(([r])=>{if(this.destroyed||!e||e.destroyed||!r)return;let{view:i,clientGeometry:a}=e;if(this._setClippingArea(i.clippingArea),this.addHandles([this._updatingHandles.add(()=>i?.pointsOfInterest?.focus?.renderLocation,e=>this._pointOfInterestChanged(e),{initial:!0,equals:p}),s(()=>i.quality,()=>this._setCameraDirty(),c),this._updatingHandles.add(()=>i.state.mode===2,t=>{this._updateIdleState(t),t&&(this._index?.resetFailedNodes(),e.contentVisible||this._updateViewData())},l),this._updatingHandles.add(()=>e.contentVisible,e=>{e&&this._index?.invalidateAllElevationRanges(),this.restartNodeLoading()},l),b(e.view.resourceController.scheduler,this),this._updatingHandles.add(()=>[this.featureTarget,this.fixedFeatureTarget],()=>{this._setCameraDirty(),this._stableFeatureLOD=!1}),this._updatingHandles.add(()=>i.state?.contentCamera,()=>this._setCameraDirty()),this._updatingHandles.add(()=>t.elevationInfo,e=>this._elevationInfoChanged(e),c),this._updatingHandles.add(()=>e.lodFactor,()=>this._setCameraDirty()),this._updatingHandles.add(()=>e.availableFields,()=>this._requiredFieldsChange()),this._updatingHandles.add(()=>e.holeFilling,e=>this._index!=null&&(this._index.holeFilling=e))]),this._viewportQueries=new D(this.crsIndex,i.renderCoordsHelper,i.state.contentCamera,!i.state.fixedContentCamera||this.isGraphics3D,this._clippingArea,this.isMeshPyramid?i.groundView:i.elevationProvider,_(i.viewingMode),this.layer.elevationInfo,{progressiveLoadFactor:this._getProgressiveLoadFactor(),screenspaceErrorBias:this._lod,angleDependentLoD:this._lod<.5}),this._clientNodeLoader=new v(this.layer.uid,{indexSR:this.crsIndex,vertexSR:this.crsVertex,renderSR:i.renderCoordsHelper.spatialReference},i.resourceController.memoryController,this.worker),this._index=new x(_(i.viewingMode),t,r,this.indexRequester,this._clientNodeLoader,this._viewportQueries,n.getLogger(this),e.holeFilling,t=>e.isNodeLoaded(t),t=>e.isNodeReloading(t),e=>this._shouldLoadNode(e),e=>this._enableFromGPUCache(e,1),e=>this._needsUpdate(e),t=>e.computeVisibilityObb?.(t)??null,e?.computeNodeFiltering?t=>e.computeNodeFiltering(t):void 0),this._index.updateElevationInfo(this.layer.elevationInfo,this.isMeshPyramid||this.isGraphics3D),this._index.imModificationsChanged(!!e.hasModifications),this._index.layerFilterChanged(!!e.hasGeometryFilter),a!=null){for(let e of a)this._addMesh(e.mesh,e.oid);this.addHandles(a.on(`change`,e=>{for(let t of e.removed)this._removeMesh(t.oid);for(let t of e.added)this._addMesh(t.mesh,t.oid)}))}this._startNodeLoading()}))}updateNodeModificationStatus(e){let t=this._index,n=this.layerView;t!=null&&n?.updateNodeModificationStatus&&(this._modificationsNodeFilteringArray.clear(),e.forAll(e=>{let n=t.getNode(e);n!=null&&this._modificationsNodeFilteringArray.push(n)}),n.updateNodeModificationStatus(this._modificationsNodeFilteringArray),this._invisibleDirty=!0)}destroy(){this.cancelNodeLoading(),this._updatingHandles.destroy(),this._nodeLoader=null,I.prune(),this._newLoadingNodes.prune(),this._modificationsNodeFilteringArray.prune(),this._elevationUpdateNodes.prune(),L!=null&&(L.hide(),L=null),this._index=null,this._lodHandling=r(this._lodHandling),this._nodeLoader=null,this._clientNodeLoader=null,this._viewportQueries=null,this._set(`worker`,null)}get viewportQueries(){return this._viewportQueries}_getRequiredAttributes(){if(this._attributeStorageInfo==null||!this._fields||!this.layerView.availableFields)return[];let e=this._attributeStorageInfo,t=this._fields,n=this.layer.objectIdField;return this.layerView.availableFields.map(n=>{let r=z(e,n),i=z(t,n);return r>=0&&i>=0?{index:r,name:t[i].name,field:t[i],attributeStorageInfo:e[r]}:null}).filter(e=>e!=null&&e.name!==n)}_requiredFieldsChange(){let e=this._getRequiredAttributes();R(this._requiredAttributes,e)||(this._requiredAttributes=e,this._requiredAttributesDirty=!1,this.restartNodeLoading())}requestUpdate(){this._requiredAttributesDirty=!0,this.restartNodeLoading()}_setClippingArea(e){let t=h();this._clippingArea=k(e,t,this.layerView.view.renderSpatialReference)?t:null}_pointOfInterestChanged(e){this._viewportQueries!=null&&(this._viewportQueries.setPointOfInterest(e),this._index!=null&&this._index.requestUpdate())}updateClippingArea(e){this._setClippingArea(e),this._viewportQueries!=null&&this._index!=null&&(this._viewportQueries.updateClippingArea(this._clippingArea),this._index.invalidateVisibilityCache()),this._setCameraDirty()}_setCameraDirty(){this._cameraDirty=!0,this._lodHandling.setLodGlobalDirty(),this._evaluateRunning()}_addMesh(e,t){if(this._index==null)return;let n=this._clientNodeLoader.createMeshNodeInfo(e,t),r=this._index.addClientNodeToIndex(n.id,n.mbs);this._clientNodeLoader.addMeshNode(r,n),this._evaluateRunning(),this.notifyChange(`rootNodeVisible`)}_removeMesh(e){let t=this._clientNodeLoader.getMeshNodeIndex(e);if(t!=null){if(this._index!=null)this._index.removeClientNodeFromIndex(t,(e,t)=>{this.layerView.removeNode(t),this._clientNodeLoader.removeNode(e),this.layerView.deleteCachedNodeData&&e!=null&&this.layerView.deleteCachedNodeData(e),this.layerView.deleteCachedGPUData?.(this.layerView.loadCachedGPUData?.(t))},(e,t,n)=>{this._clientNodeLoader.updateNodeIndex(e,t,n),this.layerView.updateNodeIndex&&this.layerView.updateNodeIndex(t,n)}),this.notifyChange(`rootNodeVisible`);else throw Error(`delayed removal of client side i3s node geometry not supported yet.`)}}updateElevationChanged(e,t){let n=this._index,r=this._viewportQueries;if(n?.rootNode==null||t==null||r==null)return null;let i=r.elevationIntersectionSpatialReference;i.equals(t)||(O(e,t,B,i)||g(-1/0,-1/0,1/0,1/0,B),e=B);let a=this._elevationUpdateNodes;return a.clear(),E(e,n.rootNode,n,e=>a.push(e.index),r),a.length&&(a.forAll(e=>n.updateElevationChanged(e)),this._setCameraDirty()),a}removeAllGeometryObbs(){this._index!=null&&this._index.removeAllGeometryObbs()}getRenderMbs(e){return this._viewportQueries==null?null:this._viewportQueries.calculateServiceMbsInRenderSRElevationAdjusted(e)}_elevationInfoChanged(e){this._index!=null&&(this._index.updateElevationInfo(e,this.isMeshPyramid||this.isGraphics3D),this._setCameraDirty())}restartNodeLoading(){this._restartNodeLoading=!0,this.cancelNodeLoading(),this._evaluateRunning()}schedule(e,t){let n=this._idleQueue.push(e,t);return this._evaluateRunning(),n}reschedule(e,t){let n=this._idleQueue.unshift(e,t);return this._evaluateRunning(),n}get _isIntegratedMesh(){return this.layer.type===`integrated-mesh`}get unloadedMemoryEstimate(){return this._index==null||!this.layerView.contentVisible?0:this._index.unloadedMemoryEstimate*this._lodDropFactor}async _loadNodeData(e,t){return e.index<0?this._clientNodeLoader.loadNodeData(e.id,t):this._nodeLoader.loadNodeData(e,t)}async _loadAttributes(e,t,n){return(e.index<0?this._clientNodeLoader:this._nodeLoader).loadAttributes(e,t,n)}get indexDepth(){return this._index==null?0:this._index.maxLevel}set disableMemCache(e){this._disableMemCache=!this.layerView.loadCachedGPUData||!this.layerView.addCachedGPUData||e}runTask(e,t){return this.layerView.contentVisible?!this.layerView.visible||this._index==null?-1/0:(this._processWithErrorLogging(e,t),this._index.maxPriority):(this._updateViewData(),this._evaluateRunning(),-1/0)}_processWithErrorLogging(e,t){try{this._process(e,t)}catch(e){this._errorCount<50?n.getLogger(this).error(`Error during processing: ${e} at ${e.stack}`):this._errorCount===50&&n.getLogger(this).error(`Too many errors for this layer. Further errors will not be displayed.`),this._errorCount++}}_process(e,t){this._restartNodeLoading&&this._startNodeLoading(),this._nodeLoader!=null&&this._index!=null&&(this._updateViewData(),this._invisibleDirty&&this._removeInvisibleNodes(e)&&(this._invisibleDirty=!1),this._isIntegratedMesh&&(e.enabled=!1),e.run(()=>this._processIndex(e)),this._updateFeatureLOD(),e.run(()=>this._processCache(e)),this._isIntegratedMesh&&(e.enabled=!0),e.run(()=>this._processNodes(e,t)),this._idleQueue.runTask(e),e.run(()=>this._prefetchIndex()),t.numIndexLoading+=this._index.indexLoading,t.numNodesLoading+=this._downloadingCount,e.run(()=>this._lodHandling.lodGlobalHandling(e)),this._evaluateRunning())}_processIndex(e){if(this._index==null)return!1;if(this._index.dirty){this._newLoadingNodes.clear(),this._index.update(Array.from(this._loadingNodes.keys()),e,e=>this.updateNodeModificationStatus(e)),this._disableMemCache||(this._newLoadingNodes.pushArray(this._index.updates.add.data,this._index.updates.add.length),this._newLoadingNodes.pushAll(this._index.updates.missing));let t=this._index.featureEstimate.leavesReached;!this._index.isLoading&&t!==this._get(`leavesReached`)&&this._set(`leavesReached`,t)}return this._index.load()}_prefetchIndex(){return this._index==null||this._loadingNodes.size>0||this._index.updates.add.length>0?!1:this._index.prefetch()}_updateFeatureLOD(){if(!this.useMaximumNumberOfFeatures||this._index==null||this._viewportQueries==null)return;let e=!this._index.isLoading,t=this.featureTarget*this._baseLOD,n=this._index.featureEstimate;if(n.estimate=n.estimate||t/2,this._index.indexMissing>500){if(this._featureLOD<=P)return;this._featureLOD/=1.5,this._stableFeatureLOD=!1}else if(e&&n.estimate<t){if(n.leavesReached||this._featureLOD>=N||this._stableFeatureLOD)return;let e=Math.min(10,Math.max(t/n.estimate,1.001));this._featureLOD*=e;let r=this._lod,i=this._index.checkFeatureTarget(t,r);i!==r&&(this._featureLOD=i/this._baseLOD,this._stableFeatureLOD=!0)}else if(n.estimate>t*1.2||e&&n.estimate>t){if(this._featureLOD<=P)return;this._featureLOD/=1+(n.estimate/t-1)*.25,this._stableFeatureLOD=!1}else return;this._featureLOD=Math.min(N,Math.max(P,this._featureLOD)),this._viewportQueries.updateScreenSpaceErrorBias(this._lod),this._index.requestUpdate()}_processCache(e){let t=this._index;if(t==null)return!1;for(;this._newLoadingNodes.length>0&&!e.done;){let n=this._newLoadingNodes.pop();for(let r=t.getParent(n);r!=null&&!this.layerView.isNodeLoaded(r.index);r=t.getParent(r.index))if(this._enableFromGPUCache(r,0)){e.madeProgress();break}}return e.hasProgressed}_processNodes(e,t){if(this._index==null)return!1;let n=(this._isIdle?100:2)-this._loadingNodes.size,r=this._index.updates;for(r.cancel.forEach(this._cancelNode,this),r.cancel=[];r.remove.length>0&&!e.done;)this.layerView.removeNode(r.remove.pop()),e.madeProgress();for(;r.update.length>0&&!e.done;){let t=this._index.getNode(r.update.pop());t!=null&&(this._updateLoadedNode(t),e.madeProgress())}for(;r.add.length>0&&!e.done&&n>0;){--n;let i=this._index.getNode(r.add.back());if(i==null||i.cacheState!==2&&!this._hasNodeLoadToken(t))break;r.add.pop(),this._loadNode(i),e.madeProgress()}return e.hasProgressed}_cancelAllNodes(){this._loadingNodes.forEach(e=>e.abort()),this._loadingNodes.clear(),this._updatingNodes.forEach(e=>e.abort()),this._updatingNodes.clear()}_cancelNode(e){let t=this._loadingNodes.get(e);t&&(t.abort(),this._loadingNodes.delete(e))}_hasNodeLoadToken(e){return!this._isIdle&&e.numNodesLoading+this._loadingNodes.size>=2?!1:this.index==null||!this.dataRequester.isFull(this._index.urlPrefix)}_evaluateRunning(){let e=!1,t=0;if(this.layerView){if(!this.layerView.contentVisible)e=this._cameraDirty,t=+!e;else{let n=(this._index?.indexMissing??0)+(this._index?.updates.add.length??0)*3+this._loadingNodes.size*2;e=!!(n>0||this._updatingNodes.size>0||this._restartNodeLoading||this._cameraDirty||this._idleQueue.updating||this._lodHandling&&this._lodHandling.requiresLODGlobalHandling||this._index!=null&&this._index.isPrefetching),n===0&&(this._progressMaxNumNodes=1),this._progressMaxNumNodes=Math.max(n,this._progressMaxNumNodes),t=1-n/this._progressMaxNumNodes}this.running=e,this.updatingProgress=t}}_updateViewData(){if(!this._cameraDirty||this._index==null||this._viewportQueries==null)return;let e=this.layerView.view,{contentCamera:t,fixedContentCamera:n}=e.state;this._viewportQueries.updateCamera(t,!n||this.isGraphics3D),this._viewportQueries.setPointOfInterest(e.pointsOfInterest.focus.renderLocation),this._viewportQueries.updateScreenSpaceErrorBias(this._lod),this._index.invalidateVisibilityCache(),this._index.requestUpdate(),this._stableFeatureLOD=!1,this._invisibleDirty=!0,this._cameraDirty=!1,this.notifyChange(`rootNodeVisible`)}_getProgressiveLoadFactor(){return this.layerView.view.quality<1?1:this.layerView.progressiveLoadFactor}get _lod(){return this._featureLOD*this._baseLOD}get _baseLOD(){let e=this.layerView.lodFactor;return this.fixedFeatureTarget?1:(e>0?e:1)*this.layerView.view.quality}get _lodDropFactor(){return this.fixedFeatureTarget?1:(Math.min(this.layerView.view.quality,.5)-A)/(.5-A)}isGeometryVisible(e){return!!this._index?.isGeometryVisible(e.index)}updateVisibility(e){this._index?.invalidateNodeVisibilityCache(e)}invalidateGeometryVisibility(e){this._index?.invalidateGeometryVisibility(e)}invalidateVisibilityObbs(){this._index?.invalidateVisibilityObbs()}modificationsChanged(){this._index?.imModificationsChanged(!!this.layerView.hasModifications),this._invisibleDirty=!0}_shouldLoadNode(e){return!(!this._lodHandling.shouldLoadNode(e)||this._shouldDropNode(e)||this._index==null||!this._index.isGeometryVisible(e.index))}_shouldDropNode(e){if(this._viewportQueries==null)return!1;let t=this._lodDropFactor;return t>=1||!this._lodHandling.hasNoVisibleChildren(e)?!1:Math.abs(this._viewportQueries.calcCameraDistanceToCenterAndUpdateMinmax(e))-this._viewportQueries.minCenterDistance>(this._viewportQueries.maxCenterDistance-this._viewportQueries.minCenterDistance)*t}_startNodeLoading(){this._restartNodeLoading=!1;let e=this._index;if(this._updatesDisabled||e==null||this._viewportQueries==null)return;this._updateViewData(),this._requiredAttributesDirty&&=(this._requiredAttributes=this._getRequiredAttributes(),!1);let t={textureEncodings:this.layerView.supportedTextureEncodings,textureUsageMask:this.layerView.rendererTextureUsage,loadFeatureData:this.useMaximumNumberOfFeatures};this._nodeLoader=new C(this.layer,this.dataRequester,n.getLogger(this),this._defaultGeometrySchema,this._requiredAttributes,t),e.requestUpdate(),this._lodHandling.startNodeLoading((e,t)=>this._removeNodes(e,t,1),e,{maxLodLevel:this._viewportQueries.maxLodLevel}),this._evaluateRunning()}isNodeLoading(){return this._nodeLoader!=null&&this._index!=null}cancelNodeLoading(){this.isNodeLoading()&&(this.indexRequester.cancelAll(),this.dataRequester.cancelAll(),this._idleQueue.cancelAll(),this._cancelAllNodes(),this._nodeLoader=null,this._evaluateRunning())}_removeInvisibleNodes(e){let t=this._index;if(t==null||this._viewportQueries==null)return!1;I.clear(),this.layerView.getLoadedNodeIndices(I);let n=this._viewportQueries.maxCenterDistance===0,r=n?()=>!1:e=>this._shouldDropNode(e);return I.filterInPlace(e=>{let n=t.getNode(e);return n==null||!t.isGeometryVisible(e)||r(n)}),I.length>0&&this._lodHandling.setLodGlobalDirty(),this._removeNodes(I,e,0),n&&this._lodDropFactor<1?!1:I.length===0||(I.clear(),!1)}markNodeToRemove(e){I.push(e)}removeMarkedNodes(){this._removeNodes(I,M,0)}_removeNodes(e,t,n){if(!(e.length===0||t.done))for(this._index!=null&&this._index.requestUpdate();e.length>0&&!t.done;){let r=e.pop(),i=this._index;n===1&&this.layerView.nodeFadeoutEnabled&&i!=null&&i.isGeometryVisible(r)?this.layerView.fadeNode(r,1,!0):this.layerView.removeNode(r),t.madeProgress()}}_needsUpdate(e){if(e.resources.isEmpty||this._updatingNodes.has(e.index))return!1;let t=this.layerView.getLoadedAttributes(e.index);return t!=null&&t!==this._requiredAttributes}async _updateLoadedNode(e){let t=new AbortController;this._updatingNodes.set(e.index,t),this._evaluateRunning();try{let n=R(this.layerView.getLoadedAttributes(e.index),this._requiredAttributes)?this.layerView.getAttributeData(e.index):await this._loadAttributes(e,this._requiredAttributes,t.signal);await this.schedule(()=>this.layerView.updateAttributes(e.index,{loadedAttributes:this._requiredAttributes,attributeData:n},t.signal),t.signal)}catch(n){if(!o(n))return this.layerView.updateAttributes(e.index,{loadedAttributes:this._requiredAttributes,attributeData:{}},t.signal)}this._updatingNodes.delete(e.index),this._evaluateRunning()}_loadNode(e){if(this._loadingNodes.has(e.index)){n.getLogger(this).error(`already loading node `+e.index);return}let t=new AbortController;this._loadingNodes.set(e.index,t),this._evaluateRunning(),this._loadAndAddNode(e,t.signal).then(n=>{n&&this._index!=null&&this._loadingNodes.get(e.index)===t&&(this._loadingNodes.delete(e.index),this._index.requestUpdate())}).catch(()=>{}).finally(()=>{this._loadingNodes.get(e.index)===t&&this._loadingNodes.delete(e.index),this._evaluateRunning()})}_loadAndAddNode(e,t){return e.cacheState===1?this._loadUncached(e,t).then(()=>!1):this._loadCached(e,t).then(t=>!t&&(e.cacheState=1,!0)).catch(t=>!o(t)&&(e.cacheState=1,!0))}_enableFromGPUCache(e,t){if(this._disableMemCache||this._index==null)return!1;if(t===0&&!this._index.useNodeAsHole(e.index))return!0;let n=this._loadCachedGPUData(e);return n?(this.layerView.addCachedGPUData(e,n,t),this._nodeAdded(),!0):!1}_loadCachedGPUData(e){let t=this.layerView.loadCachedGPUData(e.index);return t?.attributeInfo!=null&&R(t.attributeInfo.loadedAttributes,this._requiredAttributes)?t:(this.layerView.deleteCachedGPUData(t),null)}_nodeAdded(){this._index!=null&&this._index.requestUpdate(),this._lodHandling.setLodGlobalDirty(),this._evaluateRunning()}updateLoadStatus(e,t){this._index?.updateChildrenLoaded(e,t?1:-1)}async _loadCached(e,t){if(this._enableFromGPUCache(e,1))return!0;let n=this.layerView;if(this.disableIDBCache||!n.loadCachedNodeData||!n.addCachedNodeData)return!1;let r=e.index>=0?(t,n)=>this._nodeLoader.loadTextures(e,t,n):t=>this._clientNodeLoader.loadTextures(e,t),i=await this.schedule(()=>n.loadCachedNodeData(e,t,r),t);if(i==null)return!1;let a=this._requiredAttributes,o=await this.reschedule(()=>this._loadAttributes(e,a,t),t);return await this.reschedule(()=>n.addCachedNodeData(e,i,{loadedAttributes:a,attributeData:o},t),t),this._nodeAdded(),!0}_loadUncached(e,t){return this._downloadingCount++,this._loadNodeData(e,t).then(n=>this.schedule(()=>this.layerView.addNode(e,n,t),t)).finally(()=>this._downloadingCount--).then(()=>{this._nodeAdded(),e.cacheState=2}).catch(t=>{if(!o(t))throw n.getLogger(this).error(`#loadNodeData()`,this.layer,`Failed to load node '${e.id}'`,t),e.failed=!0,this._index?.requestUpdate(),t})}_updateIdleState(e){e!==this._isIdle&&(this._isIdle=e,this._evaluateRunning())}get test(){}notifyLODUpdate(){this._lodHandling.setLodGlobalDirty(),this._evaluateRunning(),this._index!=null&&this._index.requestUpdate()}geometryFilterChanged(e){this._index?.layerFilterChanged(e),this._setCameraDirty()}};e([u({readOnly:!0})],F.prototype,`isMeshPyramid`,null),e([u({readOnly:!0})],F.prototype,`isGraphics3D`,null),e([u({readOnly:!0})],F.prototype,`useMaximumNumberOfFeatures`,null),e([u({readOnly:!0})],F.prototype,`indexRequester`,null),e([u({readOnly:!0})],F.prototype,`dataRequester`,null),e([u({readOnly:!0})],F.prototype,`crsVertex`,null),e([u({readOnly:!0})],F.prototype,`crsIndex`,null),e([u()],F.prototype,`featureTarget`,void 0),e([u()],F.prototype,`fixedFeatureTarget`,void 0),e([u()],F.prototype,`layerView`,void 0),e([u()],F.prototype,`layer`,null),e([u()],F.prototype,`_updatingHandles`,void 0),e([u()],F.prototype,`updating`,null),e([u()],F.prototype,`running`,void 0),e([u()],F.prototype,`updatingProgress`,void 0),e([u({readOnly:!0})],F.prototype,`leavesReached`,void 0),e([u({constructOnly:!0})],F.prototype,`worker`,void 0),e([u({readOnly:!0})],F.prototype,`rootNodeVisible`,null),F=e([d(`esri.layers.graphics.controllers.I3SOnDemandController`)],F);const I=new i({deallocator:null});let L;function R(e,t){return e!=null&&e.length===t.length&&e.every(e=>z(t,e.name)>=0)}function z(e,t){let n=t.toLowerCase();for(let t=0;t<e.length;t++)if(e[t].name.toLowerCase()===n)return t;return-1}const B=h(),V=F;export{V as default};
2
+ import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import has from"../../../core/has.js";import n from"../../../core/Logger.js";import{destroyMaybe as r}from"../../../core/maybe.js";import i from"../../../core/PooledArray.js";import{EsriPromiseMixin as a}from"../../../core/Promise.js";import{isAbortError as o}from"../../../core/promiseUtils.js";import{watch as s,sync as c,initial as l}from"../../../core/reactiveUtils.js";import{property as u,subclass as d}from"../../../core/accessorSupport/decorators.js";import{runUntracked as f}from"../../../core/accessorSupport/tracking.js";import{exactEquals as p}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{UpdatingHandles as m}from"../../../core/support/UpdatingHandles.js";import{create as h,fromValues as g}from"../../../geometry/support/aaBoundingRect.js";import{viewingModeFromString as _}from"../../../views/ViewingMode.js";import{I3SClientNodeLoader as v}from"../../../views/3d/layers/i3s/I3SClientNodeLoader.js";import{I3SDataRequester as y}from"../../../views/3d/layers/i3s/I3SDataRequester.js";import{addCallback as b}from"../../../views/3d/layers/i3s/I3SFrameTask.js";import{I3SIndex as x}from"../../../views/3d/layers/i3s/I3SIndex.js";import S from"../../../views/3d/layers/i3s/I3SLodHandling.js";import C from"../../../views/3d/layers/i3s/I3SNodeLoader.js";import{getVertexCrs as w,getIndexCrs as T,findIntersectingNodes as E}from"../../../views/3d/layers/i3s/I3SUtil.js";import D from"../../../views/3d/layers/i3s/I3SViewportQueries.js";import{projectElevationUpdateExtent as O}from"../../../views/3d/support/elevationUpdateExtentUtils.js";import{toBoundingRect as k}from"../../../views/3d/support/extentUtils.js";import{minQuality as A}from"../../../views/3d/support/MemoryController.js";import{PromiseQueue as j}from"../../../views/support/PromiseQueue.js";import{noBudget as M}from"../../../views/support/Scheduler.js";const N=1e4,P=1e-4;let F=class extends a(t){get isMeshPyramid(){return this.layer.profile===`mesh-pyramids`||this.layer.store?.lodType===`MeshPyramid`}get isGraphics3D(){return this.layer.profile===`points`}get useMaximumNumberOfFeatures(){return!this.isMeshPyramid&&(this.layer.priority==null||this.layer.priority===`High`)}get indexRequester(){return new y(this.layer.customParameters,this.layer.apiKey)}get dataRequester(){return new y(this.layer.customParameters,this.layer.apiKey)}get crsVertex(){return w(this.layer)}get crsIndex(){return T(this.layer)}get layer(){return this.layerView.layer}get updating(){return this.running||this._updatingHandles.updating}get rootNodeVisible(){return f(()=>{if(this._index){let e=this._index.rootNode;if(e)return this._updateViewData(),this._index.isNodeVisible(e.index)}return!0})}get index(){return this._index}get requiredAttributes(){return this._requiredAttributes}constructor(e){super(e),this.featureTarget=5e4,this.fixedFeatureTarget=!1,this._updatingHandles=new m,this.running=!0,this.updatingProgress=1,this.leavesReached=!1,this.worker=null,this._featureLOD=1,this._stableFeatureLOD=!1,this._isIdle=!1,this._cameraDirty=!0,this._invisibleDirty=!1,this._newLoadingNodes=new i({deallocator:null}),this._modificationsNodeFilteringArray=new i,this._downloadingCount=0,this._loadingNodes=new Map,this._updatingNodes=new Map,this._progressMaxNumNodes=1,this._requiredAttributes=[],this._requiredAttributesDirty=!0,this._updatesDisabled=!1,this.disableIDBCache=!1,this._disableMemCache=!1,this._restartNodeLoading=!1,this._fields=null,this._attributeStorageInfo=null,this._idleQueue=new j,this._elevationUpdateNodes=new i({deallocator:null}),this._errorCount=0}initialize(){let{layerView:e,layer:t}=this;this._disableMemCache=!e.loadCachedGPUData||!e.addCachedGPUData,this._lodHandling=new S(e),this._defaultGeometrySchema=t.store.defaultGeometrySchema,this.disableIDBCache=!!has(`disable-feature:idb-cache`),`fields`in t&&(this._fields=t.fields,this._attributeStorageInfo=t.attributeStorageInfo),this.addResolvingPromise(Promise.all([t.indexInfo,t.when(),e.when()]).then(([r])=>{if(this.destroyed||!e||e.destroyed||!r)return;let{view:i,clientGeometry:a}=e;if(this._setClippingArea(i.clippingArea),this.addHandles([this._updatingHandles.add(()=>i?.pointsOfInterest?.focus?.renderLocation,e=>this._pointOfInterestChanged(e),{initial:!0,equals:p}),s(()=>i.quality,()=>this._setCameraDirty(),c),this._updatingHandles.add(()=>i.state.mode===2,t=>{this._updateIdleState(t),t&&(this._index?.resetFailedNodes(),e.contentVisible||this._updateViewData())},l),this._updatingHandles.add(()=>e.contentVisible,e=>{e&&this._index?.invalidateAllElevationRanges(),this.restartNodeLoading()},l),b(e.view.resourceController.scheduler,this),this._updatingHandles.add(()=>[this.featureTarget,this.fixedFeatureTarget],()=>{this._setCameraDirty(),this._stableFeatureLOD=!1}),this._updatingHandles.add(()=>i.state?.contentCamera,()=>this._setCameraDirty()),this._updatingHandles.add(()=>t.elevationInfo,e=>this._elevationInfoChanged(e),c),this._updatingHandles.add(()=>e.lodFactor,()=>this._setCameraDirty()),this._updatingHandles.add(()=>e.availableFields,()=>this._requiredFieldsChange()),this._updatingHandles.add(()=>e.holeFilling,e=>this._index!=null&&(this._index.holeFilling=e))]),this._viewportQueries=new D(this.crsIndex,i.renderCoordsHelper,i.state.contentCamera,!i.state.fixedContentCamera||this.isGraphics3D,this._clippingArea,this.isMeshPyramid?i.groundView:i.elevationProvider,_(i.viewingMode),this.layer.elevationInfo,{progressiveLoadFactor:this._getProgressiveLoadFactor(),screenspaceErrorBias:this._lod,angleDependentLoD:this._lod<.5}),this._clientNodeLoader=new v(this.layer.uid,{indexSR:this.crsIndex,vertexSR:this.crsVertex,renderSR:i.renderCoordsHelper.spatialReference},i.resourceController.memoryController,this.worker),this._index=new x(_(i.viewingMode),t,r,this.indexRequester,this._clientNodeLoader,this._viewportQueries,n.getLogger(this),e.holeFilling,t=>e.isNodeLoaded(t),t=>e.isNodeReloading(t),e=>this._shouldLoadNode(e),e=>this._enableFromGPUCache(e,1),e=>this._needsUpdate(e),t=>e.computeVisibilityObb?.(t)??null,e?.computeNodeFiltering?t=>e.computeNodeFiltering(t):void 0),this._index.updateElevationInfo(this.layer.elevationInfo,this.isMeshPyramid||this.isGraphics3D),this._index.imModificationsChanged(!!e.hasModifications),this._index.layerFilterChanged(!!e.hasGeometryFilter),a!=null){for(let e of a)this._addMesh(e.mesh,e.oid);this.addHandles(a.on(`change`,e=>{for(let t of e.removed)this._removeMesh(t.oid);for(let t of e.added)this._addMesh(t.mesh,t.oid)}))}this._startNodeLoading()}))}updateNodeModificationStatus(e){let t=this._index,n=this.layerView;t!=null&&n?.updateNodeModificationStatus&&(this._modificationsNodeFilteringArray.clear(),e.forAll(e=>{let n=t.getNode(e);n!=null&&this._modificationsNodeFilteringArray.push(n)}),n.updateNodeModificationStatus(this._modificationsNodeFilteringArray),this._invisibleDirty=!0)}destroy(){this.cancelNodeLoading(),this._updatingHandles.destroy(),this._nodeLoader=null,I.prune(),this._newLoadingNodes.prune(),this._modificationsNodeFilteringArray.prune(),this._elevationUpdateNodes.prune(),L!=null&&(L.hide(),L=null),this._index=null,this._lodHandling=r(this._lodHandling),this._nodeLoader=null,this._clientNodeLoader=null,this._viewportQueries=null,this._set(`worker`,null)}get viewportQueries(){return this._viewportQueries}_getRequiredAttributes(){if(this._attributeStorageInfo==null||!this._fields||!this.layerView.availableFields)return[];let e=this._attributeStorageInfo,t=this._fields,n=this.layer.objectIdField;return this.layerView.availableFields.map(n=>{let r=z(e,n),i=z(t,n);return r>=0&&i>=0?{index:r,name:t[i].name,field:t[i],attributeStorageInfo:e[r]}:null}).filter(e=>e!=null&&e.name!==n)}_requiredFieldsChange(){let e=this._getRequiredAttributes();R(this._requiredAttributes,e)||(this._requiredAttributes=e,this._requiredAttributesDirty=!1,this.restartNodeLoading())}requestUpdate(){this._requiredAttributesDirty=!0,this.restartNodeLoading()}_setClippingArea(e){let t=h();this._clippingArea=k(e,t,this.layerView.view.renderSpatialReference)?t:null}_pointOfInterestChanged(e){this._viewportQueries!=null&&(this._viewportQueries.setPointOfInterest(e),this._index!=null&&this._index.requestUpdate())}updateClippingArea(e){this._setClippingArea(e),this._viewportQueries!=null&&this._index!=null&&(this._viewportQueries.updateClippingArea(this._clippingArea),this._index.invalidateVisibilityCache()),this._setCameraDirty()}_setCameraDirty(){this._cameraDirty=!0,this._lodHandling.setLodGlobalDirty(),this._evaluateRunning()}_addMesh(e,t){if(this._index==null)return;let n=this._clientNodeLoader.createMeshNodeInfo(e,t),r=this._index.addClientNodeToIndex(n.id,n.mbs);this._clientNodeLoader.addMeshNode(r,n),this._evaluateRunning(),this.notifyChange(`rootNodeVisible`)}_removeMesh(e){let t=this._clientNodeLoader.getMeshNodeIndex(e);if(t!=null){if(this._index!=null)this._index.removeClientNodeFromIndex(t,(e,t)=>{this.layerView.removeNode(t),this._clientNodeLoader.removeNode(e),this.layerView.deleteCachedNodeData&&e!=null&&this.layerView.deleteCachedNodeData(e),this.layerView.deleteCachedGPUData?.(this.layerView.loadCachedGPUData?.(t))},(e,t,n)=>{this._clientNodeLoader.updateNodeIndex(e,t,n),this.layerView.updateNodeIndex&&this.layerView.updateNodeIndex(t,n)}),this.notifyChange(`rootNodeVisible`);else throw Error(`delayed removal of client side i3s node geometry not supported yet.`)}}updateElevationChanged(e,t){let n=this._index,r=this._viewportQueries;if(n?.rootNode==null||t==null||r==null)return null;let i=r.elevationIntersectionSpatialReference;i.equals(t)||(O(e,t,B,i)||g(-1/0,-1/0,1/0,1/0,B),e=B);let a=this._elevationUpdateNodes;return a.clear(),E(e,n.rootNode,n,e=>a.push(e.index),r),a.length&&(a.forAll(e=>n.updateElevationChanged(e)),this._setCameraDirty()),a}removeAllGeometryObbs(){this._index!=null&&this._index.removeAllGeometryObbs()}getRenderMbs(e){return this._viewportQueries==null?null:this._viewportQueries.calculateServiceMbsInRenderSRElevationAdjusted(e)}_elevationInfoChanged(e){this._index!=null&&(this._index.updateElevationInfo(e,this.isMeshPyramid||this.isGraphics3D),this._setCameraDirty())}restartNodeLoading(){this._restartNodeLoading=!0,this.cancelNodeLoading(),this._evaluateRunning()}schedule(e,t){let n=this._idleQueue.push(e,t);return this._evaluateRunning(),n}reschedule(e,t){let n=this._idleQueue.unshift(e,t);return this._evaluateRunning(),n}get _isIntegratedMesh(){return this.layer.type===`integrated-mesh`}get unloadedMemoryEstimate(){return this._index==null||!this.layerView.contentVisible?0:this._index.unloadedMemoryEstimate*this._lodDropFactor}async _loadNodeData(e,t){return e.index<0?this._clientNodeLoader.loadNodeData(e.id,t):this._nodeLoader.loadNodeData(e,t)}async _loadAttributes(e,t,n){return(e.index<0?this._clientNodeLoader:this._nodeLoader).loadAttributes(e,t,n)}get indexDepth(){return this._index==null?0:this._index.maxLevel}set disableMemCache(e){this._disableMemCache=!this.layerView.loadCachedGPUData||!this.layerView.addCachedGPUData||e}runTask(e,t){return this.layerView.contentVisible?!this.layerView.visible||this._index==null?-1/0:(this._processWithErrorLogging(e,t),this._index.maxPriority):(this._updateViewData(),this._evaluateRunning(),-1/0)}_processWithErrorLogging(e,t){try{this._process(e,t)}catch(e){this._errorCount<50?n.getLogger(this).error(`Error during processing: ${e} at ${e.stack}`):this._errorCount===50&&n.getLogger(this).error(`Too many errors for this layer. Further errors will not be displayed.`),this._errorCount++}}_process(e,t){this._restartNodeLoading&&this._startNodeLoading(),this._nodeLoader!=null&&this._index!=null&&(this._updateViewData(),this._invisibleDirty&&this._removeInvisibleNodes(e)&&(this._invisibleDirty=!1),this._isIntegratedMesh&&(e.enabled=!1),e.run(()=>this._processIndex(e)),this._updateFeatureLOD(),e.run(()=>this._processCache(e)),this._isIntegratedMesh&&(e.enabled=!0),e.run(()=>this._processNodes(e,t)),this._idleQueue.runTask(e),e.run(()=>this._prefetchIndex()),t.numIndexLoading+=this._index.indexLoading,t.numNodesLoading+=this._downloadingCount,e.run(()=>this._lodHandling.lodGlobalHandling(e)),this._evaluateRunning())}_processIndex(e){if(this._index==null)return!1;if(this._index.dirty){this._newLoadingNodes.clear(),this._index.update(Array.from(this._loadingNodes.keys()),e,e=>this.updateNodeModificationStatus(e)),this._disableMemCache||(this._newLoadingNodes.pushArray(this._index.updates.add.data,this._index.updates.add.length),this._newLoadingNodes.pushAll(this._index.updates.missing));let t=this._index.featureEstimate.leavesReached;!this._index.isLoading&&t!==this._get(`leavesReached`)&&this._set(`leavesReached`,t)}return this._index.load()}_prefetchIndex(){return this._index==null||this._loadingNodes.size>0||this._index.updates.add.length>0?!1:this._index.prefetch()}_updateFeatureLOD(){if(!this.useMaximumNumberOfFeatures||this._index==null||this._viewportQueries==null)return;let e=!this._index.isLoading,t=this.featureTarget*this._baseLOD,n=this._index.featureEstimate;if(n.estimate=n.estimate||t/2,this._index.indexMissing>500){if(this._featureLOD<=P)return;this._featureLOD/=1.5,this._stableFeatureLOD=!1}else if(e&&n.estimate<t){if(n.leavesReached||this._featureLOD>=N||this._stableFeatureLOD)return;let e=Math.min(10,Math.max(t/n.estimate,1.001));this._featureLOD*=e;let r=this._lod,i=this._index.checkFeatureTarget(t,r);i!==r&&(this._featureLOD=i/this._baseLOD,this._stableFeatureLOD=!0)}else if(n.estimate>t*1.2||e&&n.estimate>t){if(this._featureLOD<=P)return;this._featureLOD/=1+(n.estimate/t-1)*.25,this._stableFeatureLOD=!1}else return;this._featureLOD=Math.min(N,Math.max(P,this._featureLOD)),this._viewportQueries.updateScreenSpaceErrorBias(this._lod),this._index.requestUpdate()}_processCache(e){let t=this._index;if(t==null)return!1;for(;this._newLoadingNodes.length>0&&!e.done;){let n=this._newLoadingNodes.pop();for(let r=t.getParent(n);r!=null&&!this.layerView.isNodeLoaded(r.index);r=t.getParent(r.index)){if(!this._disableMemCache&&!t.useNodeAsHole(r.index)){e.enabled&&e.madeProgress();break}if(this._enableFromGPUCache(r,0)){e.madeProgress();break}}}return e.hasProgressed}_processNodes(e,t){if(this._index==null)return!1;let n=(this._isIdle?100:2)-this._loadingNodes.size,r=this._index.updates;for(r.cancel.forEach(this._cancelNode,this),r.cancel=[];r.remove.length>0&&!e.done;)this.layerView.removeNode(r.remove.pop()),e.madeProgress();for(;r.update.length>0&&!e.done;){let t=this._index.getNode(r.update.pop());t!=null&&(this._updateLoadedNode(t),e.madeProgress())}for(;r.add.length>0&&!e.done&&n>0;){--n;let i=this._index.getNode(r.add.back());if(i==null||i.cacheState!==2&&!this._hasNodeLoadToken(t))break;r.add.pop(),this._loadNode(i),e.madeProgress()}return e.hasProgressed}_cancelAllNodes(){this._loadingNodes.forEach(e=>e.abort()),this._loadingNodes.clear(),this._updatingNodes.forEach(e=>e.abort()),this._updatingNodes.clear()}_cancelNode(e){let t=this._loadingNodes.get(e);t&&(t.abort(),this._loadingNodes.delete(e))}_hasNodeLoadToken(e){return!this._isIdle&&e.numNodesLoading+this._loadingNodes.size>=2?!1:this.index==null||!this.dataRequester.isFull(this._index.urlPrefix)}_evaluateRunning(){let e=!1,t=0;if(this.layerView){if(!this.layerView.contentVisible)e=this._cameraDirty,t=+!e;else{let n=(this._index?.indexMissing??0)+(this._index?.updates.add.length??0)*3+this._loadingNodes.size*2;e=!!(n>0||this._updatingNodes.size>0||this._restartNodeLoading||this._cameraDirty||this._idleQueue.updating||this._lodHandling&&this._lodHandling.requiresLODGlobalHandling||this._index!=null&&this._index.isPrefetching),n===0&&(this._progressMaxNumNodes=1),this._progressMaxNumNodes=Math.max(n,this._progressMaxNumNodes),t=1-n/this._progressMaxNumNodes}this.running=e,this.updatingProgress=t}}_updateViewData(){if(!this._cameraDirty||this._index==null||this._viewportQueries==null)return;let e=this.layerView.view,{contentCamera:t,fixedContentCamera:n}=e.state;this._viewportQueries.updateCamera(t,!n||this.isGraphics3D),this._viewportQueries.setPointOfInterest(e.pointsOfInterest.focus.renderLocation),this._viewportQueries.updateScreenSpaceErrorBias(this._lod),this._index.invalidateVisibilityCache(),this._index.requestUpdate(),this._stableFeatureLOD=!1,this._invisibleDirty=!0,this._cameraDirty=!1,this.notifyChange(`rootNodeVisible`)}_getProgressiveLoadFactor(){return this.layerView.view.quality<1?1:this.layerView.progressiveLoadFactor}get _lod(){return this._featureLOD*this._baseLOD}get _baseLOD(){let e=this.layerView.lodFactor;return this.fixedFeatureTarget?1:(e>0?e:1)*this.layerView.view.quality}get _lodDropFactor(){return this.fixedFeatureTarget?1:(Math.min(this.layerView.view.quality,.5)-A)/(.5-A)}isGeometryVisible(e){return!!this._index?.isGeometryVisible(e.index)}updateVisibility(e){this._index?.invalidateNodeVisibilityCache(e)}invalidateGeometryVisibility(e){this._index?.invalidateGeometryVisibility(e)}invalidateVisibilityObbs(){this._index?.invalidateVisibilityObbs()}modificationsChanged(){this._index?.imModificationsChanged(!!this.layerView.hasModifications),this._invisibleDirty=!0}_shouldLoadNode(e){return!(!this._lodHandling.shouldLoadNode(e)||this._shouldDropNode(e)||this._index==null||!this._index.isGeometryVisible(e.index))}_shouldDropNode(e){if(this._viewportQueries==null)return!1;let t=this._lodDropFactor;return t>=1||!this._lodHandling.hasNoVisibleChildren(e)?!1:Math.abs(this._viewportQueries.calcCameraDistanceToCenterAndUpdateMinmax(e))-this._viewportQueries.minCenterDistance>(this._viewportQueries.maxCenterDistance-this._viewportQueries.minCenterDistance)*t}_startNodeLoading(){this._restartNodeLoading=!1;let e=this._index;if(this._updatesDisabled||e==null||this._viewportQueries==null)return;this._updateViewData(),this._requiredAttributesDirty&&=(this._requiredAttributes=this._getRequiredAttributes(),!1);let t={textureEncodings:this.layerView.supportedTextureEncodings,textureUsageMask:this.layerView.rendererTextureUsage,loadFeatureData:this.useMaximumNumberOfFeatures};this._nodeLoader=new C(this.layer,this.dataRequester,n.getLogger(this),this._defaultGeometrySchema,this._requiredAttributes,t),e.requestUpdate(),this._lodHandling.startNodeLoading((e,t)=>this._removeNodes(e,t,1),e,{maxLodLevel:this._viewportQueries.maxLodLevel}),this._evaluateRunning()}isNodeLoading(){return this._nodeLoader!=null&&this._index!=null}cancelNodeLoading(){this.isNodeLoading()&&(this.indexRequester.cancelAll(),this.dataRequester.cancelAll(),this._idleQueue.cancelAll(),this._cancelAllNodes(),this._nodeLoader=null,this._evaluateRunning())}_removeInvisibleNodes(e){let t=this._index;if(t==null||this._viewportQueries==null)return!1;I.clear(),this.layerView.getLoadedNodeIndices(I);let n=this._viewportQueries.maxCenterDistance===0,r=n?()=>!1:e=>this._shouldDropNode(e);return I.filterInPlace(e=>{let n=t.getNode(e);return n==null||!t.isGeometryVisible(e)||r(n)}),I.length>0&&this._lodHandling.setLodGlobalDirty(),this._removeNodes(I,e,0),n&&this._lodDropFactor<1?!1:I.length===0||(I.clear(),!1)}markNodeToRemove(e){I.push(e)}removeMarkedNodes(){this._removeNodes(I,M,0)}_removeNodes(e,t,n){if(!(e.length===0||t.done))for(this._index!=null&&this._index.requestUpdate();e.length>0&&!t.done;){let r=e.pop(),i=this._index;n===1&&this.layerView.nodeFadeoutEnabled&&i!=null&&i.isGeometryVisible(r)?this.layerView.fadeNode(r,1,!0):this.layerView.removeNode(r),t.madeProgress()}}_needsUpdate(e){if(e.resources.isEmpty||this._updatingNodes.has(e.index))return!1;let t=this.layerView.getLoadedAttributes(e.index);return t!=null&&t!==this._requiredAttributes}async _updateLoadedNode(e){let t=new AbortController;this._updatingNodes.set(e.index,t),this._evaluateRunning();try{let n=R(this.layerView.getLoadedAttributes(e.index),this._requiredAttributes)?this.layerView.getAttributeData(e.index):await this._loadAttributes(e,this._requiredAttributes,t.signal);await this.schedule(()=>this.layerView.updateAttributes(e.index,{loadedAttributes:this._requiredAttributes,attributeData:n},t.signal),t.signal)}catch(n){if(!o(n))return this.layerView.updateAttributes(e.index,{loadedAttributes:this._requiredAttributes,attributeData:{}},t.signal)}this._updatingNodes.delete(e.index),this._evaluateRunning()}_loadNode(e){if(this._loadingNodes.has(e.index)){n.getLogger(this).error(`already loading node `+e.index);return}let t=new AbortController;this._loadingNodes.set(e.index,t),this._evaluateRunning(),this._loadAndAddNode(e,t.signal).then(n=>{n&&this._index!=null&&this._loadingNodes.get(e.index)===t&&(this._loadingNodes.delete(e.index),this._index.requestUpdate())}).catch(()=>{}).finally(()=>{this._loadingNodes.get(e.index)===t&&this._loadingNodes.delete(e.index),this._evaluateRunning()})}_loadAndAddNode(e,t){return e.cacheState===1?this._loadUncached(e,t).then(()=>!1):this._loadCached(e,t).then(t=>!t&&(e.cacheState=1,!0)).catch(t=>!o(t)&&(e.cacheState=1,!0))}_enableFromGPUCache(e,t){if(this._disableMemCache||this._index==null)return!1;let n=this._loadCachedGPUData(e);return n?(this.layerView.addCachedGPUData(e,n,t),this._nodeAdded(),!0):!1}_loadCachedGPUData(e){let t=this.layerView.loadCachedGPUData(e.index);return t?.attributeInfo!=null&&R(t.attributeInfo.loadedAttributes,this._requiredAttributes)?t:(this.layerView.deleteCachedGPUData(t),null)}_nodeAdded(){this._index!=null&&this._index.requestUpdate(),this._lodHandling.setLodGlobalDirty(),this._evaluateRunning()}updateLoadStatus(e,t){this._index?.updateChildrenLoaded(e,t?1:-1)}async _loadCached(e,t){if(this._enableFromGPUCache(e,1))return!0;let n=this.layerView;if(this.disableIDBCache||!n.loadCachedNodeData||!n.addCachedNodeData)return!1;let r=e.index>=0?(t,n)=>this._nodeLoader.loadTextures(e,t,n):t=>this._clientNodeLoader.loadTextures(e,t),i=await this.schedule(()=>n.loadCachedNodeData(e,t,r),t);if(i==null)return!1;let a=this._requiredAttributes,o=await this.reschedule(()=>this._loadAttributes(e,a,t),t);return await this.reschedule(()=>n.addCachedNodeData(e,i,{loadedAttributes:a,attributeData:o},t),t),this._nodeAdded(),!0}_loadUncached(e,t){return this._downloadingCount++,this._loadNodeData(e,t).then(n=>this.schedule(()=>this.layerView.addNode(e,n,t),t)).finally(()=>this._downloadingCount--).then(()=>{this._nodeAdded(),e.cacheState=2}).catch(t=>{if(!o(t))throw n.getLogger(this).error(`#loadNodeData()`,this.layer,`Failed to load node '${e.id}'`,t),e.failed=!0,this._index?.requestUpdate(),t})}_updateIdleState(e){e!==this._isIdle&&(this._isIdle=e,this._evaluateRunning())}get test(){}notifyLODUpdate(){this._lodHandling.setLodGlobalDirty(),this._evaluateRunning(),this._index!=null&&this._index.requestUpdate()}geometryFilterChanged(e){this._index?.layerFilterChanged(e),this._setCameraDirty()}};e([u({readOnly:!0})],F.prototype,`isMeshPyramid`,null),e([u({readOnly:!0})],F.prototype,`isGraphics3D`,null),e([u({readOnly:!0})],F.prototype,`useMaximumNumberOfFeatures`,null),e([u({readOnly:!0})],F.prototype,`indexRequester`,null),e([u({readOnly:!0})],F.prototype,`dataRequester`,null),e([u({readOnly:!0})],F.prototype,`crsVertex`,null),e([u({readOnly:!0})],F.prototype,`crsIndex`,null),e([u()],F.prototype,`featureTarget`,void 0),e([u()],F.prototype,`fixedFeatureTarget`,void 0),e([u()],F.prototype,`layerView`,void 0),e([u()],F.prototype,`layer`,null),e([u()],F.prototype,`_updatingHandles`,void 0),e([u()],F.prototype,`updating`,null),e([u()],F.prototype,`running`,void 0),e([u()],F.prototype,`updatingProgress`,void 0),e([u({readOnly:!0})],F.prototype,`leavesReached`,void 0),e([u({constructOnly:!0})],F.prototype,`worker`,void 0),e([u({readOnly:!0})],F.prototype,`rootNodeVisible`,null),F=e([d(`esri.layers.graphics.controllers.I3SOnDemandController`)],F);const I=new i({deallocator:null});let L;function R(e,t){return e!=null&&e.length===t.length&&e.every(e=>z(t,e.name)>=0)}function z(e,t){let n=t.toLowerCase();for(let t=0;t<e.length;t++)if(e[t].name.toLowerCase()===n)return t;return-1}const B=h(),V=F;export{V as default};
@@ -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 n from"../../core/Error.js";import r from"../../core/Logger.js";import{getOrCreateMapValue as i}from"../../core/MapUtils.js";import{createAbortError as a}from"../../core/promiseUtils.js";import{parseWhereClause as o}from"../../core/sql.js";import{property as s,subclass as c}from"../../core/accessorSupport/decorators.js";import l from"../../geometry/Extent.js";import u from"../../geometry/Polygon.js";import{initializeProjection as d,project as f}from"../../geometry/projectionUtils.js";import{wgs84 as p}from"../../geometry/support/spatialReferenceUtils.js";import{systemOidFieldName as m,systemOriginIdFieldName as h,systemDestinationIdFieldName as g,systemIsSpatialFieldName as _,systemLayoutGeometryFieldName as v}from"./constants.js";import{recursiveParseSqlToCypher as y,addAdditionalClausesToCypher as b}from"./cypherUtils.js";import x from"./SessionMemoryStorage.js";import{utilsExtentToInBoundsRings as S}from"./supportUtils.js";import{executeQueryStreaming as C}from"../../rest/knowledgeGraphService.js";import w from"../../rest/knowledgeGraph/GraphQueryStreaming.js";import T from"../../rest/support/Query.js";let E=class extends t{constructor(e){super(e),this._processingCacheUpdatesLookup=new Map,this.knowledgeGraph=null,this.inclusionModeDefinition={generateAllSublayers:!0,namedTypeDefinitions:new Map},this.entityTypeNames=new Set,this.relationshipTypeNames=new Set,this.geographicLookup=new Map,this.sublayerCaches=new Map,this.nodeConnectionsLookup=new Map,this.relationshipConnectionsLookup=new Map,this.memberIdTypeLookup=new Map;let t=new Map;e.knowledgeGraph.dataModel.entityTypes?.forEach(n=>{n.name&&(t.set(n.name,`entity`),this._processingCacheUpdatesLookup.set(n.name,[]),(!e.inclusionModeDefinition||e.inclusionModeDefinition?.generateAllSublayers)&&this.entityTypeNames.add(n.name),n.properties?.forEach(e=>{e.geometryType&&e.geometryType!==`esriGeometryNull`&&this.geographicLookup.set(n.name,{name:e.name??``,geometryType:e.geometryType})}))}),e.knowledgeGraph.dataModel.relationshipTypes?.forEach(n=>{n.name&&(t.set(n.name,`relationship`),this._processingCacheUpdatesLookup.set(n.name,[]),(!e.inclusionModeDefinition||e.inclusionModeDefinition?.generateAllSublayers)&&this.relationshipTypeNames.add(n.name),n.properties?.forEach(e=>{e.geometryType&&e.geometryType!==`esriGeometryNull`&&this.geographicLookup.set(n.name,{name:e.name??``,geometryType:e.geometryType})}))}),e.inclusionModeDefinition?.namedTypeDefinitions.forEach((n,a)=>{if(t.get(a)===`entity`)this.entityTypeNames.add(a);else if(t.get(a)===`relationship`)this.relationshipTypeNames.add(a);else{r.getLogger(this).warn(`A named type, ${a}, was in the inclusion list that wasn't in the data model and will be removed`),e.inclusionModeDefinition?.namedTypeDefinitions.delete(a);return}let o=new Map;n.members?.forEach(e=>{i(this.memberIdTypeLookup,e.id,()=>new Set).add(a)}),this.sublayerCaches.set(a,o)})}addToLayer(e){e.forEach(({typeName:e,id:t})=>{if(!this.inclusionModeDefinition)throw new n(`knowledge-graph:layer-data-manager`,`You cannot add to a layer's exclusion list if it was not created with an exclusion list originally`);if(!this.inclusionModeDefinition.namedTypeDefinitions.has(e)){let n=new Map;n.set(t,{id:t}),this.inclusionModeDefinition.namedTypeDefinitions.set(e,{useAllData:!1,members:n}),i(this.memberIdTypeLookup,t,()=>new Set).add(e)}else if(this.inclusionModeDefinition.namedTypeDefinitions.has(e)){let n=this.inclusionModeDefinition.namedTypeDefinitions.get(e);n.members||=new Map,n.members.set(t,{id:t}),i(this.memberIdTypeLookup,t,()=>new Set).add(e)}})}getById(e){return x.getInstance().readFromStoreById(e)}async getData(e,t,n,r){if(t.objectType.name&&this.inclusionModeDefinition?.namedTypeDefinitions&&this.inclusionModeDefinition.namedTypeDefinitions.size>0&&!this.inclusionModeDefinition.namedTypeDefinitions.has(t.objectType.name))return{features:[],cypherTranslationApplied:!1};let i;if(i=e||new T({where:`1=1`,outFields:[`*`]}),n.type===`link-chart`){let e=n,r=this._processingCacheUpdatesLookup.get(t.objectType.name??``),a=i.outFields;a&&a.length===1&&a[0]===m&&i.where===`1=1`||await Promise.all(r??[]);let o=this.sublayerCaches.has(t.objectType.name??``)?Array.from(this.sublayerCaches.get(t.objectType.name)?.values()):[],s=[];return o.forEach(n=>{if(this.relationshipTypeNames.has(t.objectType.name)){n.geometry=e.relationshipLinkChartDiagramLookup.get(n.attributes[t.objectIdField]);let r=this.memberIdTypeLookup.get(n.attributes[h]),i=this.memberIdTypeLookup.get(n.attributes[g]),a=this._isEndEntitySpatial(r,n,h),o=this._isEndEntitySpatial(i,n,g);n.attributes[_]=Number(a&&o)}else{n.geometry=e.entityLinkChartDiagramLookup.get(n.attributes[t.objectIdField]);let r=this.geographicLookup.get(t.objectType.name);r&&n.attributes[r.name]?n.attributes[_]=1:n.attributes[_]=0}n.attributes[v]=n.geometry,s.push(n)}),{features:s,cypherTranslationApplied:!1}}return this.retrieveDataFromService(i,t,n,r)}async getConnectedRecordIds(e,t,n){let r=[],i=``,a=this._getNamedTypeIdMapFromNodeIds(e);if(t&&t?.length!==0){for(let e of t)i=i+e+`|`;i=i.slice(0,-1)}let o={},s=[];for(let[e,n]of a){let r=`${e}_ids`;o[r]=n,t&&t?.length!==0?s.push(`MATCH (n:${e}) WHERE id(n) IN $${r} WITH n MATCH (n)-[r:${i}]-(m) RETURN id(r), type(r), id(m), labels(m)[0]`):s.push(`MATCH (n:${e}) WHERE id(n) IN $${r} WITH n MATCH (n)-[r]-(m) RETURN id(r), type(r), id(m), labels(m)[0]`)}if(!s.length)return r;let c=s.join(` UNION `),l=(await C(this.knowledgeGraph,new w({openCypherQuery:c,bindParameters:o}),{signal:n?.signal})).resultRowsStream.getReader();for(;;){let{done:e,value:t}=await l.read();if(e)break;for(let e=0;e<t.length;e++){let n=t[e];r.push({id:n[0],typeName:n[1]}),r.push({id:n[2],typeName:n[3]})}}return r}async getRelationshipsBetweenNodes(e,t,n){let r=this._getNamedTypeIdMapFromNodeIds(e);if(r.size===0)return[];let i={relationshipExclusionIds:t,possibleConnectionEntityIds:e},a=[];for(let[e,t]of r.entries()){let n=`${e}_ids`;i[n]=t,a.push(`MATCH (n:${e}) WHERE id(n) IN $${n} WITH n MATCH (n)-[r]->(m) WHERE id(m) IN $possibleConnectionEntityIds AND NOT id(r) IN $relationshipExclusionIds RETURN id(r), type(r)`)}let o=a.join(` UNION `),s=[],c=(await C(this.knowledgeGraph,new w({openCypherQuery:o,bindParameters:i}),{signal:n?.signal})).resultRowsStream.getReader();for(;;){let{done:e,value:t}=await c.read();if(e)break;for(let e=0;e<t.length;e++){let n=t[e];s.push({id:n[0],typeName:n[1]})}}return s}async getRelationshipsFromNodes(e,t,n,r){let i=this._getNamedTypeIdMapFromNodeIds(e);if(i.size===0||t.length===0)return[];let a={relationshipExclusionIds:n,possibleConnectionEntityIds:t},o=[];for(let[e,t]of i.entries()){let n=`${e}_ids`;a[n]=t,o.push(`MATCH (n:${e}) WHERE id(n) IN $${n} WITH n MATCH (n)-[r]-(m) WHERE id(m) IN $possibleConnectionEntityIds AND NOT id(r) IN $relationshipExclusionIds RETURN id(r), type(r)`)}let s=o.join(` UNION `),c=new Map,l=(await C(this.knowledgeGraph,new w({openCypherQuery:s,bindParameters:a}),{signal:r?.signal})).resultRowsStream.getReader();for(;;){let{done:e,value:t}=await l.read();if(e)break;for(let e=0;e<t.length;e++){let n=t[e],r=c.get(n[1]);r||(r=new Set,c.set(n[1],r)),r.add(n[0])}}let u=[];for(let[e,t]of c)for(let n of t)u.push({id:n,typeName:e});return u}async refreshCacheContent(e,t,r,o=!0,s){let c=x.getInstance(),l=[],u=new Map,d=new Map;this.knowledgeGraph.dataModel.entityTypes?.forEach(e=>{e.name&&d.set(e.name,e)}),this.knowledgeGraph.dataModel.relationshipTypes?.forEach(e=>{e.name&&d.set(e.name,e)}),!e&&!this.inclusionModeDefinition?(this.knowledgeGraph.dataModel.entityTypes?.forEach(e=>{e.name&&u.set(e.name,null)}),this.knowledgeGraph.dataModel.entityTypes?.forEach(e=>{e.name&&u.set(e.name,null)})):e?e.forEach(e=>{if(this.memberIdTypeLookup.has(e))for(let t of this.memberIdTypeLookup.get(e))u.has(t)?u.get(t)?.push(e):u.set(t,[e])}):this.inclusionModeDefinition?.namedTypeDefinitions?.forEach((e,t)=>{e.useAllData?u.set(t,null):e.members&&e.members.forEach(e=>{u.has(t)&&u.get(t)!==null?u.get(t)?.push(e.id):u.set(t,[e.id])})});for(let[e,a]of u){let u=new Set(a),f=new Promise((l,f)=>{(async()=>{let l=new Set,f=[],p=``,h=!1;if(t||d.get(e)?.properties?.forEach(e=>{e.name&&l.add(e.name)}),r&&this.geographicLookup.has(e)){let t=this.geographicLookup.get(e)?.name;t&&l.add(t)}if(this.entityTypeNames.has(e))p=`MATCH (n:${e}) ${a?`WHERE id(n) IN $ids `:``}return ID(n)`,l.forEach(e=>{p+=`, n.${e}`,f.push(e)});else if(this.relationshipTypeNames.has(e))h=!0,p=`MATCH ()-[n:${e}]->() ${a?`WHERE id(n) IN $ids `:``}return ID(n), id(startNode(n)), id(endNode(n))`,l.forEach(e=>{p+=`, n.${e}`,f.push(e)});else throw new n(`knowledge-graph:layer-data-manager`,`The graph type of ${e} could not be determined. Was this type set in the KG data model and inclusion definition?`);let g;g=a?new w({openCypherQuery:p,bindParameters:{ids:a}}):new w({openCypherQuery:p});let _=(await C(this.knowledgeGraph,g,{signal:s?.signal})).resultRowsStream.getReader();for(;;){let{done:t,value:n}=await _.read();if(t)break;let r=[];for(let e=0;e<n.length;e++){let t=n[e],a=0,o=0,s={properties:{}};for(s.id=t[a],a++,o++,h&&(s.originId=t[a],a++,o++,s.destinationId=t[a],a++,o++,i(this.nodeConnectionsLookup,s.originId,()=>new Set).add(s.id),i(this.nodeConnectionsLookup,s.destinationId,()=>new Set).add(s.id),i(this.relationshipConnectionsLookup,s.id,()=>[s.originId,s.destinationId]));a<t.length;a++)s.properties[f[a-o]]=t[a];u.delete(s.id),r.push(s)}let a=c.writeToStore(r,m,this.geographicLookup.get(e)?.name);this.sublayerCaches.has(e)||this.sublayerCaches.set(e,new Map),o&&!this.inclusionModeDefinition?.namedTypeDefinitions.has(e)&&this.inclusionModeDefinition?.namedTypeDefinitions.set(e,{useAllData:!1,members:new Map}),o&&!this.inclusionModeDefinition?.namedTypeDefinitions.get(e).members&&(this.inclusionModeDefinition.namedTypeDefinitions.get(e).members=new Map);let s=this.sublayerCaches.get(e);a.forEach(t=>{s?.set(t.attributes[m],t),o&&!this.inclusionModeDefinition?.namedTypeDefinitions.get(e).members.has(t.attributes[m])&&(this.inclusionModeDefinition?.namedTypeDefinitions.get(e).members.set(t.attributes[m],{id:t.attributes[m]}),i(this.memberIdTypeLookup,t.attributes[m],()=>new Set).add(e))})}let v=this.inclusionModeDefinition?.namedTypeDefinitions.get(e);if(v)for(let e of u)v.members?.delete(e)})().then(()=>{l(null)}).catch(e=>{e.name===`AbortError`?l(null):f(e)})});l.push(f),this._processingCacheUpdatesLookup.get(e)?.push(f)}if(await Promise.all(l),s?.signal?.aborted)throw a()}removeFromLayer(e){let t=new Set,n=new Set(e.map(e=>e.id));for(let n of e)t.add(n.typeName),this.memberIdTypeLookup.get(n.id)?.size===1?this.memberIdTypeLookup.delete(n.id):this.memberIdTypeLookup.get(n.id)?.delete(n.typeName),this.inclusionModeDefinition?.namedTypeDefinitions.forEach((e,t)=>{t===n.typeName&&e.members?.has(n.id)&&e.members.delete(n.id)});t.forEach(e=>{this.sublayerCaches.get(e)?.forEach((t,r)=>{n.has(r)&&this.sublayerCaches.get(e)?.delete(r)})})}async retrieveDataFromService(e,t,r,i){let a=x.getInstance(),s=new Set,c=[],h=``,g=[],_=!1,v,T=t.graphType===`relationship`,E=this.inclusionModeDefinition?.namedTypeDefinitions?.get(t.objectType.name)?.useAllData,D=r.sublayerIdsCache.get(t.objectType.name),O=!E&&D?Array.from(D).sort():null,k={systemOidFieldName:m,supportedSqlTypes:new Set([`column-reference`,`string`,`number`,`binary-expression`]),supportedSqlOperators:new Set([`=`,`<`,`<=`,`<>`,`>`,`>=`,`AND`,`OR`,`LIKE`]),unsupportedOperationFound:!1};if(this.inclusionModeDefinition?.namedTypeDefinitions?.get(t.objectType.name)?.useAllData)this.inclusionModeDefinition?.namedTypeDefinitions?.get(t.objectType.name)?.useAllData&&e.objectIds!=null&&(O=e.objectIds);else if(e.objectIds!=null&&O&&O.length>0){let t=e.objectIds;e.objectIds=O.filter(e=>t.includes(e))}else if(e.objectIds!=null)O=e.objectIds;else if(this.inclusionModeDefinition?.namedTypeDefinitions.has(t.objectType.name)&&(!this.inclusionModeDefinition.namedTypeDefinitions.get(t.objectType.name)?.members||this.inclusionModeDefinition.namedTypeDefinitions.get(t.objectType.name)?.members?.size<1))return e.objectIds=[],{features:[],cypherTranslationApplied:_};else e.objectIds=O;if(e.outFields!=null){let n=e.outFields;n.includes(`*`)?t.fields.forEach(e=>{s.add(e.name)}):n.forEach(e=>{e!==m&&e!==t.geometryFieldName&&s.add(e)})}if(e.geometry!=null){let i=e.geometry,a,m=r.dataManager.knowledgeGraph.serviceDefinition,g=m?.spatialReference,_=m?.serviceCapabilities?.geometryCapabilities,y=_?.geometryMaxBoundingRectangleSizeX,b=_?.geometryMaxBoundingRectangleSizeY;if(i.type===`point`){let e=i;e.spatialReference?.isWGS84||(await d(e.spatialReference,p),e=f(e,p)),a=new l({spatialReference:p,xmin:e.x-1e-4,ymin:e.y-1e-4,xmax:e.x+1e-4,ymax:e.y+1e-4})}else i?.extent?.spatialReference&&!i.spatialReference?.isWGS84?(await d(i.extent.spatialReference,p),a=f(i.extent,p)):a=i.extent;if(y&&b&&g){if(g.wkid!==4326){let e=new l({spatialReference:g,xmax:y,ymax:b}),t=f(e,p);y=t.xmax,b=t.ymax}if(a.xmax-a.xmin>y)throw new n(`knowledge-graph:layer-data-manager`,`Extent x bounds should be within ${y}° latitude, limit exceeded`);if(a.ymax-a.ymin>b)throw new n(`knowledge-graph:layer-data-manager`,`Extent y bounds should be within ${b}° longitude, limit exceeded`)}if(e.where!=null&&e.where!==`1=1`){let n=await o(e.where.toUpperCase(),t.fieldsIndex);t.fields.forEach(e=>{n.fieldNames.includes(e.name)&&s.add(e.name)})}h=T?`Match ()-[n:${t.objectType.name}]->() WHERE esri.graph.ST_Intersects($param_filter_geom, n.${t.geometryFieldName}) return ID(n), id(startNode(r)), id(endNode(r))`:`Match (n:${t.objectType.name}) WHERE esri.graph.ST_Intersects($param_filter_geom, n.${t.geometryFieldName}) return ID(n)`,t.geometryFieldName&&s.add(t.geometryFieldName),s.forEach(e=>{h+=`, n.${e}`,c.push(e)}),v=new w({openCypherQuery:h,bindParameters:{param_filter_geom:new u({rings:S(a)})}})}else{let n=``;if(e.where!=null&&e.where!==`1=1`){let r=await o(e.where,t.fieldsIndex);t.fields.forEach(e=>{r.fieldNames.includes(e.name)&&s.add(e.name)}),n=y(r.parseTree,k),k.unsupportedOperationFound&&(n=``)}let r=``;r=T?`Match ()-[n:${t.objectType.name}]->()`:`Match (n:${t.objectType.name})`;let i=!1;O&&(i=!0,r+=` WHERE ID(n) IN $ids`),n&&(r+=i?` AND`:` WHERE`,r+=` ${n}`),r+=` return ID(n)`,T&&(r+=`, id(startNode(n)), id(endNode(n))`),e.returnGeometry&&t.geometryFieldName&&s.add(t.geometryFieldName),s.forEach(e=>{r+=`, n.${e}`,c.push(e)}),k.unsupportedOperationFound||(r=b(r,e),_=!0),v=O?new w({openCypherQuery:r,bindParameters:{ids:O}}):new w({openCypherQuery:r})}let A=(await C(r.dataManager.knowledgeGraph,v,i)).resultRowsStream.getReader();for(;;){let{done:e,value:n}=await A.read();if(e)break;let i=[];for(let e=0;e<n.length;e++){let t=n[e],r=0,a=0,o={properties:{}};for(o.id=t[r],r++,a++,T&&(o.originId=t[r],r++,a++,o.destinationId=t[r],r++,a++);r<t.length;r++)o.properties[c[r-a]]=t[r];i.push(o)}g=g.concat(a.writeToStore(i,m,r.dataManager.geographicLookup.get(t.objectType.name)?.name))}return{features:g,cypherTranslationApplied:_}}_isEndEntitySpatial(e,t,n){for(let r of e??[])if(this.entityTypeNames.has(r)){let e=this.geographicLookup.get(r),i=e&&this.sublayerCaches.get(r)?.get(t.attributes[n]);if(e&&i?.attributes[e.name])return!0}return!1}_getNamedTypeIdMapFromNodeIds(e){let t=new Map;return e.forEach(e=>{if(this.memberIdTypeLookup.has(e))for(let n of this.memberIdTypeLookup.get(e)){if(!this.entityTypeNames.has(n))return;t.has(n)?t.get(n)?.push(e):t.set(n,[e])}}),t}};e([s()],E.prototype,`knowledgeGraph`,void 0),e([s()],E.prototype,`inclusionModeDefinition`,void 0),e([s()],E.prototype,`entityTypeNames`,void 0),e([s()],E.prototype,`relationshipTypeNames`,void 0),e([s()],E.prototype,`geographicLookup`,void 0),e([s()],E.prototype,`sublayerCaches`,void 0),e([s()],E.prototype,`nodeConnectionsLookup`,void 0),e([s()],E.prototype,`relationshipConnectionsLookup`,void 0),e([s()],E.prototype,`memberIdTypeLookup`,void 0),E=e([c(`esri.layers.knowledgeGraph.KnowledgeGraphLayerDataManager`)],E);export{E as KnowledgeGraphLayerDataManager};
2
+ import{__decorate as e}from"tslib";import t from"../../core/Accessor.js";import n from"../../core/Error.js";import r from"../../core/Logger.js";import{getOrCreateMapValue as i}from"../../core/MapUtils.js";import{createAbortError as a}from"../../core/promiseUtils.js";import{parseWhereClause as o}from"../../core/sql.js";import{property as s,subclass as c}from"../../core/accessorSupport/decorators.js";import l from"../../geometry/Extent.js";import u from"../../geometry/Polygon.js";import{initializeProjection as d,project as f}from"../../geometry/projectionUtils.js";import{wgs84 as p}from"../../geometry/support/spatialReferenceUtils.js";import{systemOidFieldName as m,systemOriginIdFieldName as h,systemDestinationIdFieldName as g,systemIsSpatialFieldName as _,systemLayoutGeometryFieldName as v}from"./constants.js";import{recursiveParseSqlToCypher as y,addAdditionalClausesToCypher as b}from"./cypherUtils.js";import x from"./SessionMemoryStorage.js";import{utilsExtentToInBoundsRings as S}from"./supportUtils.js";import{executeQueryStreaming as C}from"../../rest/knowledgeGraphService.js";import w from"../../rest/knowledgeGraph/GraphQueryStreaming.js";import T from"../../rest/support/Query.js";let E=class extends t{constructor(e){super(e),this._processingCacheUpdatesLookup=new Map,this.knowledgeGraph=null,this.inclusionModeDefinition={generateAllSublayers:!0,namedTypeDefinitions:new Map},this.entityTypeNames=new Set,this.relationshipTypeNames=new Set,this.geographicLookup=new Map,this.sublayerCaches=new Map,this.nodeConnectionsLookup=new Map,this.relationshipConnectionsLookup=new Map,this.memberIdTypeLookup=new Map;let t=new Map;e.knowledgeGraph.dataModel.entityTypes?.forEach(n=>{n.name&&(t.set(n.name,`entity`),this._processingCacheUpdatesLookup.set(n.name,[]),(!e.inclusionModeDefinition||e.inclusionModeDefinition?.generateAllSublayers)&&this.entityTypeNames.add(n.name),n.properties?.forEach(e=>{e.geometryType&&e.geometryType!==`esriGeometryNull`&&this.geographicLookup.set(n.name,{name:e.name??``,geometryType:e.geometryType})}))}),e.knowledgeGraph.dataModel.relationshipTypes?.forEach(n=>{n.name&&(t.set(n.name,`relationship`),this._processingCacheUpdatesLookup.set(n.name,[]),(!e.inclusionModeDefinition||e.inclusionModeDefinition?.generateAllSublayers)&&this.relationshipTypeNames.add(n.name),n.properties?.forEach(e=>{e.geometryType&&e.geometryType!==`esriGeometryNull`&&this.geographicLookup.set(n.name,{name:e.name??``,geometryType:e.geometryType})}))}),e.inclusionModeDefinition?.namedTypeDefinitions.forEach((n,a)=>{if(t.get(a)===`entity`)this.entityTypeNames.add(a);else if(t.get(a)===`relationship`)this.relationshipTypeNames.add(a);else{r.getLogger(this).warn(`A named type, ${a}, was in the inclusion list that wasn't in the data model and will be removed`),e.inclusionModeDefinition?.namedTypeDefinitions.delete(a);return}let o=new Map;n.members?.forEach(e=>{i(this.memberIdTypeLookup,e.id,()=>new Set).add(a)}),this.sublayerCaches.set(a,o)})}addToLayer(e){e.forEach(({typeName:e,id:t})=>{if(!this.inclusionModeDefinition)throw new n(`knowledge-graph:layer-data-manager`,`You cannot add to a layer's exclusion list if it was not created with an exclusion list originally`);if(!this.inclusionModeDefinition.namedTypeDefinitions.has(e)){let n=new Map;n.set(t,{id:t}),this.inclusionModeDefinition.namedTypeDefinitions.set(e,{useAllData:!1,members:n}),i(this.memberIdTypeLookup,t,()=>new Set).add(e)}else if(this.inclusionModeDefinition.namedTypeDefinitions.has(e)){let n=this.inclusionModeDefinition.namedTypeDefinitions.get(e);n.members||=new Map,n.members.set(t,{id:t}),i(this.memberIdTypeLookup,t,()=>new Set).add(e)}})}getById(e){return x.getInstance().readFromStoreById(e)}async getData(e,t,n,r){if(t.objectType.name&&this.inclusionModeDefinition?.namedTypeDefinitions&&this.inclusionModeDefinition.namedTypeDefinitions.size>0&&!this.inclusionModeDefinition.namedTypeDefinitions.has(t.objectType.name))return{features:[],cypherTranslationApplied:!1};let i;if(i=e||new T({where:`1=1`,outFields:[`*`]}),n.type===`link-chart`){let e=n,r=this._processingCacheUpdatesLookup.get(t.objectType.name??``),a=i.outFields;a&&a.length===1&&a[0]===m&&i.where===`1=1`||await Promise.all(r??[]);let o=this.sublayerCaches.has(t.objectType.name??``)?Array.from(this.sublayerCaches.get(t.objectType.name)?.values()):[],s=[];return o.forEach(n=>{if(this.relationshipTypeNames.has(t.objectType.name)){n.geometry=e.relationshipLinkChartDiagramLookup.get(n.attributes[t.objectIdField]);let r=this.memberIdTypeLookup.get(n.attributes[h]),i=this.memberIdTypeLookup.get(n.attributes[g]),a=this._isEndEntitySpatial(r,n,h),o=this._isEndEntitySpatial(i,n,g);n.attributes[_]=Number(a&&o)}else{n.geometry=e.entityLinkChartDiagramLookup.get(n.attributes[t.objectIdField]);let r=this.geographicLookup.get(t.objectType.name);r&&n.attributes[r.name]?n.attributes[_]=1:n.attributes[_]=0}n.attributes[v]=n.geometry,s.push(n)}),{features:s,cypherTranslationApplied:!1}}return this.retrieveDataFromService(i,t,n,r)}async getConnectedRecordIds(e,t,n){let r=[],i=``,a=this._getNamedTypeIdMapFromNodeIds(e);if(t&&t?.length!==0){for(let e of t)i=i+e+`|`;i=i.slice(0,-1)}let o={},s=[];for(let[e,n]of a){let r=`${e}_ids`;o[r]=n,t&&t?.length!==0?s.push(`MATCH (n:${e}) WHERE id(n) IN $${r} WITH n MATCH (n)-[r:${i}]-(m) RETURN id(r), type(r), id(m), labels(m)[0]`):s.push(`MATCH (n:${e}) WHERE id(n) IN $${r} WITH n MATCH (n)-[r]-(m) RETURN id(r), type(r), id(m), labels(m)[0]`)}if(!s.length)return r;let c=s.join(` UNION `),l=(await C(this.knowledgeGraph,new w({openCypherQuery:c,bindParameters:o}),{signal:n?.signal})).resultRowsStream.getReader();for(;;){let{done:e,value:t}=await l.read();if(e)break;for(let e=0;e<t.length;e++){let n=t[e];r.push({id:n[0],typeName:n[1]}),r.push({id:n[2],typeName:n[3]})}}return r}async getRelationshipsBetweenNodes(e,t,n){let r=this._getNamedTypeIdMapFromNodeIds(e);if(r.size===0)return[];let i={relationshipExclusionIds:t,possibleConnectionEntityIds:e},a=[];for(let[e,t]of r.entries()){let n=`${e}_ids`;i[n]=t,a.push(`MATCH (n:${e}) WHERE id(n) IN $${n} WITH n MATCH (n)-[r]->(m) WHERE id(m) IN $possibleConnectionEntityIds AND NOT id(r) IN $relationshipExclusionIds RETURN id(r), type(r)`)}let o=a.join(` UNION `),s=[],c=(await C(this.knowledgeGraph,new w({openCypherQuery:o,bindParameters:i}),{signal:n?.signal})).resultRowsStream.getReader();for(;;){let{done:e,value:t}=await c.read();if(e)break;for(let e=0;e<t.length;e++){let n=t[e];s.push({id:n[0],typeName:n[1]})}}return s}async getRelationshipsFromNodes(e,t,n,r){let i=this._getNamedTypeIdMapFromNodeIds(e);if(i.size===0||t.length===0)return[];let a={relationshipExclusionIds:n,possibleConnectionEntityIds:t},o=[];for(let[e,t]of i.entries()){let n=`${e}_ids`;a[n]=t,o.push(`MATCH (n:${e}) WHERE id(n) IN $${n} WITH n MATCH (n)-[r]-(m) WHERE id(m) IN $possibleConnectionEntityIds AND NOT id(r) IN $relationshipExclusionIds RETURN id(r), type(r)`)}let s=o.join(` UNION `),c=new Map,l=(await C(this.knowledgeGraph,new w({openCypherQuery:s,bindParameters:a}),{signal:r?.signal})).resultRowsStream.getReader();for(;;){let{done:e,value:t}=await l.read();if(e)break;for(let e=0;e<t.length;e++){let n=t[e],r=c.get(n[1]);r||(r=new Set,c.set(n[1],r)),r.add(n[0])}}let u=[];for(let[e,t]of c)for(let n of t)u.push({id:n,typeName:e});return u}async refreshCacheContent(e,t,r,o=!0,s){let c=x.getInstance(),l=[],u=new Map,d=new Map;this.knowledgeGraph.dataModel.entityTypes?.forEach(e=>{e.name&&d.set(e.name,e)}),this.knowledgeGraph.dataModel.relationshipTypes?.forEach(e=>{e.name&&d.set(e.name,e)}),!e&&!this.inclusionModeDefinition?(this.knowledgeGraph.dataModel.entityTypes?.forEach(e=>{e.name&&u.set(e.name,null)}),this.knowledgeGraph.dataModel.entityTypes?.forEach(e=>{e.name&&u.set(e.name,null)})):e?e.forEach(e=>{if(this.memberIdTypeLookup.has(e))for(let t of this.memberIdTypeLookup.get(e))u.has(t)?u.get(t)?.push(e):u.set(t,[e])}):this.inclusionModeDefinition?.namedTypeDefinitions?.forEach((e,t)=>{e.useAllData?u.set(t,null):e.members&&e.members.forEach(e=>{u.has(t)&&u.get(t)!==null?u.get(t)?.push(e.id):u.set(t,[e.id])})});for(let[e,a]of u){let u=new Set(a),f=new Promise((l,f)=>{(async()=>{let l=new Set,f=[],p=``,h=!1;if(t||d.get(e)?.properties?.forEach(e=>{e.name&&l.add(e.name)}),r&&this.geographicLookup.has(e)){let t=this.geographicLookup.get(e)?.name;t&&l.add(t)}if(this.entityTypeNames.has(e))p=`MATCH (n:${e}) ${a?`WHERE id(n) IN $ids `:``}return ID(n)`,l.forEach(e=>{p+=`, n.${e}`,f.push(e)});else if(this.relationshipTypeNames.has(e))h=!0,p=`MATCH ()-[n:${e}]->() ${a?`WHERE id(n) IN $ids `:``}return ID(n), id(startNode(n)), id(endNode(n))`,l.forEach(e=>{p+=`, n.${e}`,f.push(e)});else throw new n(`knowledge-graph:layer-data-manager`,`The graph type of ${e} could not be determined. Was this type set in the KG data model and inclusion definition?`);let g;g=a?new w({openCypherQuery:p,bindParameters:{ids:a}}):new w({openCypherQuery:p});let _=(await C(this.knowledgeGraph,g,{signal:s?.signal})).resultRowsStream.getReader();for(;;){let{done:t,value:n}=await _.read();if(t)break;let r=[];for(let e=0;e<n.length;e++){let t=n[e],a=0,o=0,s={properties:{}};for(s.id=t[a],a++,o++,h&&(s.originId=t[a],a++,o++,s.destinationId=t[a],a++,o++,i(this.nodeConnectionsLookup,s.originId,()=>new Set).add(s.id),i(this.nodeConnectionsLookup,s.destinationId,()=>new Set).add(s.id),i(this.relationshipConnectionsLookup,s.id,()=>[s.originId,s.destinationId]));a<t.length;a++)s.properties[f[a-o]]=t[a];u.delete(s.id),r.push(s)}let a=c.writeToStore(r,m,this.geographicLookup.get(e)?.name);this.sublayerCaches.has(e)||this.sublayerCaches.set(e,new Map),o&&!this.inclusionModeDefinition?.namedTypeDefinitions.has(e)&&this.inclusionModeDefinition?.namedTypeDefinitions.set(e,{useAllData:!1,members:new Map}),o&&!this.inclusionModeDefinition?.namedTypeDefinitions.get(e).members&&(this.inclusionModeDefinition.namedTypeDefinitions.get(e).members=new Map);let s=this.sublayerCaches.get(e);a.forEach(t=>{s?.set(t.attributes[m],t),o&&!this.inclusionModeDefinition?.namedTypeDefinitions.get(e).members.has(t.attributes[m])&&(this.inclusionModeDefinition?.namedTypeDefinitions.get(e).members.set(t.attributes[m],{id:t.attributes[m]}),i(this.memberIdTypeLookup,t.attributes[m],()=>new Set).add(e))})}let v=this.inclusionModeDefinition?.namedTypeDefinitions.get(e);if(v)for(let e of u)v.members?.delete(e)})().then(()=>{l(null)}).catch(e=>{e.name===`AbortError`?l(null):f(e)})});l.push(f),this._processingCacheUpdatesLookup.get(e)?.push(f)}if(await Promise.all(l),s?.signal?.aborted)throw a()}removeFromLayer(e){let t=new Set,n=new Set(e.map(e=>e.id));for(let n of e)t.add(n.typeName),this.memberIdTypeLookup.get(n.id)?.size===1?this.memberIdTypeLookup.delete(n.id):this.memberIdTypeLookup.get(n.id)?.delete(n.typeName),this.inclusionModeDefinition?.namedTypeDefinitions.forEach((e,t)=>{t===n.typeName&&e.members?.has(n.id)&&e.members.delete(n.id)});t.forEach(e=>{this.sublayerCaches.get(e)?.forEach((t,r)=>{n.has(r)&&this.sublayerCaches.get(e)?.delete(r)})})}async retrieveDataFromService(e,t,r,i){let a=x.getInstance(),s=new Set,c=[],h=``,g=[],_=!1,v,T=t.graphType===`relationship`,E=this.inclusionModeDefinition?.namedTypeDefinitions?.get(t.objectType.name)?.useAllData,D=r.sublayerIdsCache.get(t.objectType.name),O=!E&&D?Array.from(D).sort():null,k={systemOidFieldName:m,supportedSqlTypes:new Set([`column-reference`,`string`,`number`,`binary-expression`]),supportedSqlOperators:new Set([`=`,`<`,`<=`,`<>`,`>`,`>=`,`AND`,`OR`,`LIKE`]),unsupportedOperationFound:!1};if(this.inclusionModeDefinition?.namedTypeDefinitions?.get(t.objectType.name)?.useAllData)this.inclusionModeDefinition?.namedTypeDefinitions?.get(t.objectType.name)?.useAllData&&e.objectIds!=null&&(O=e.objectIds);else if(e.objectIds!=null&&O&&O.length>0){let t=e.objectIds,n=O.filter(e=>t.includes(e));if(t.length>0&&n.length===0)return{features:[],cypherTranslationApplied:_};e.objectIds=n}else if(e.objectIds!=null)O=e.objectIds;else if(this.inclusionModeDefinition?.namedTypeDefinitions.has(t.objectType.name)&&(!this.inclusionModeDefinition.namedTypeDefinitions.get(t.objectType.name)?.members||this.inclusionModeDefinition.namedTypeDefinitions.get(t.objectType.name)?.members?.size<1))return e.objectIds=[],{features:[],cypherTranslationApplied:_};else e.objectIds=O;if(e.outFields!=null){let n=e.outFields;n.includes(`*`)?t.fields.forEach(e=>{s.add(e.name)}):n.forEach(e=>{e!==m&&e!==t.geometryFieldName&&s.add(e)})}if(e.geometry!=null){let i=e.geometry,a,m=r.dataManager.knowledgeGraph.serviceDefinition,g=m?.spatialReference,_=m?.serviceCapabilities?.geometryCapabilities,y=_?.geometryMaxBoundingRectangleSizeX,b=_?.geometryMaxBoundingRectangleSizeY;if(i.type===`point`){let e=i;e.spatialReference?.isWGS84||(await d(e.spatialReference,p),e=f(e,p)),a=new l({spatialReference:p,xmin:e.x-1e-4,ymin:e.y-1e-4,xmax:e.x+1e-4,ymax:e.y+1e-4})}else i?.extent?.spatialReference&&!i.spatialReference?.isWGS84?(await d(i.extent.spatialReference,p),a=f(i.extent,p)):a=i.extent;if(y&&b&&g){if(g.wkid!==4326){let e=new l({spatialReference:g,xmax:y,ymax:b}),t=f(e,p);y=t.xmax,b=t.ymax}if(a.xmax-a.xmin>y)throw new n(`knowledge-graph:layer-data-manager`,`Extent x bounds should be within ${y}° latitude, limit exceeded`);if(a.ymax-a.ymin>b)throw new n(`knowledge-graph:layer-data-manager`,`Extent y bounds should be within ${b}° longitude, limit exceeded`)}if(e.where!=null&&e.where!==`1=1`){let n=await o(e.where.toUpperCase(),t.fieldsIndex);t.fields.forEach(e=>{n.fieldNames.includes(e.name)&&s.add(e.name)})}h=T?`Match ()-[n:${t.objectType.name}]->() WHERE esri.graph.ST_Intersects($param_filter_geom, n.${t.geometryFieldName}) return ID(n), id(startNode(r)), id(endNode(r))`:`Match (n:${t.objectType.name}) WHERE esri.graph.ST_Intersects($param_filter_geom, n.${t.geometryFieldName}) return ID(n)`,t.geometryFieldName&&s.add(t.geometryFieldName),s.forEach(e=>{h+=`, n.${e}`,c.push(e)}),v=new w({openCypherQuery:h,bindParameters:{param_filter_geom:new u({rings:S(a)})}})}else{let n=``;if(e.where!=null&&e.where!==`1=1`){let r=await o(e.where,t.fieldsIndex);t.fields.forEach(e=>{r.fieldNames.includes(e.name)&&s.add(e.name)}),n=y(r.parseTree,k),k.unsupportedOperationFound&&(n=``)}let r=``;r=T?`Match ()-[n:${t.objectType.name}]->()`:`Match (n:${t.objectType.name})`;let i=!1;O&&(i=!0,r+=` WHERE ID(n) IN $ids`),n&&(r+=i?` AND`:` WHERE`,r+=` ${n}`),r+=` return ID(n)`,T&&(r+=`, id(startNode(n)), id(endNode(n))`),e.returnGeometry&&t.geometryFieldName&&s.add(t.geometryFieldName),s.forEach(e=>{r+=`, n.${e}`,c.push(e)}),k.unsupportedOperationFound||(r=b(r,e),_=!0),v=O?new w({openCypherQuery:r,bindParameters:{ids:O}}):new w({openCypherQuery:r})}let A=(await C(r.dataManager.knowledgeGraph,v,i)).resultRowsStream.getReader();for(;;){let{done:e,value:n}=await A.read();if(e)break;let i=[];for(let e=0;e<n.length;e++){let t=n[e],r=0,a=0,o={properties:{}};for(o.id=t[r],r++,a++,T&&(o.originId=t[r],r++,a++,o.destinationId=t[r],r++,a++);r<t.length;r++)o.properties[c[r-a]]=t[r];i.push(o)}g=g.concat(a.writeToStore(i,m,r.dataManager.geographicLookup.get(t.objectType.name)?.name))}return{features:g,cypherTranslationApplied:_}}_isEndEntitySpatial(e,t,n){for(let r of e??[])if(this.entityTypeNames.has(r)){let e=this.geographicLookup.get(r),i=e&&this.sublayerCaches.get(r)?.get(t.attributes[n]);if(e&&i?.attributes[e.name])return!0}return!1}_getNamedTypeIdMapFromNodeIds(e){let t=new Map;return e.forEach(e=>{if(this.memberIdTypeLookup.has(e))for(let n of this.memberIdTypeLookup.get(e)){if(!this.entityTypeNames.has(n))return;t.has(n)?t.get(n)?.push(e):t.set(n,[e])}}),t}};e([s()],E.prototype,`knowledgeGraph`,void 0),e([s()],E.prototype,`inclusionModeDefinition`,void 0),e([s()],E.prototype,`entityTypeNames`,void 0),e([s()],E.prototype,`relationshipTypeNames`,void 0),e([s()],E.prototype,`geographicLookup`,void 0),e([s()],E.prototype,`sublayerCaches`,void 0),e([s()],E.prototype,`nodeConnectionsLookup`,void 0),e([s()],E.prototype,`relationshipConnectionsLookup`,void 0),e([s()],E.prototype,`memberIdTypeLookup`,void 0),E=e([c(`esri.layers.knowledgeGraph.KnowledgeGraphLayerDataManager`)],E);export{E as KnowledgeGraphLayerDataManager};
@@ -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"../../Graphic.js";import n from"../../request.js";import r from"../../core/Error.js";import{clone as i}from"../../core/lang.js";import a from"../../core/Logger.js";import{QueueProcessor as o}from"../../core/QueueProcessor.js";import{watch as s}from"../../core/reactiveUtils.js";import{urlToObject as c}from"../../core/urlUtils.js";import{property as l,subclass as u}from"../../core/accessorSupport/decorators.js";import{Integer as d,ensureClass as f}from"../../core/accessorSupport/ensureType.js";import{runUntracked as p}from"../../core/accessorSupport/tracking.js";import m from"../../geometry/Extent.js";import h from"../../geometry/Polygon.js";import g from"../../geometry/SpatialReference.js";import{srToRESTValue as _}from"../../geometry/support/spatialReferenceUtils.js";import{intersectMultimensionalSubset as v,getEffectiveMultidimensionalDefinition as y,getSubsetVariablesFromMdInfo as b,getDefaultMultidimensionalDefinition as x}from"../raster/datasets/multidimensionalUtils.js";import{decode as S,getFormat as C}from"../raster/formats/RasterCodec.js";import{mosaicPixelData as w}from"../raster/functions/pixelUtils.js";import{uvComponentToVector as T}from"../raster/functions/vectorFieldUtils.js";import{opacity as E,url as D}from"../support/commonProperties.js";import O from"../support/DimensionalDefinition.js";import{ExportImageServiceParameters as k}from"../support/ExportImageServiceParameters.js";import A from"../support/Field.js";import j from"../support/FieldsIndex.js";import{createBitmap as M}from"../support/imageBitmapUtils.js";import{isSupportedRendererType as ee}from"../support/imageryRendererUtils.js";import N from"../support/MosaicRule.js";import te from"../support/MultidimensionalSubset.js";import P from"../support/PixelBlock.js";import{interpolationKebab as F,noDataInterpretationKebab as I,pixelTypeKebabDict as L}from"../support/rasterEnums.js";import{getServicePixelValueField as ne,getItemPixelValueField as re,getRawServicePixelValueField as ie,getProcessedServicePixelValueField as ae,getMagnitudeField as oe,getDirectionField as se,getMultidimensionalFields as ce,getRasterAttributeTableFields as le,addMultidimensionalFieldValues as ue,commonRasterFieldNames as R,rasterFieldPrefix as de}from"../support/rasterFieldUtils.js";import z from"../support/RasterFunction.js";import fe from"../support/RasterInfo.js";import{createDefaultRenderer as B,getDefaultBandCombination as V,getSupportedRendererTypes as H,getField as U,matchPresetRenderer as pe,normalizeRendererJSON as me}from"../../renderers/support/rasterRendererHelper.js";import W from"../../renderers/support/RasterSymbolizer.js";import{rasterRendererTypes as G,websceneRasterRendererTypes as he,read as ge}from"../../renderers/support/rasterTypeUtils.js";import{calculateVolume as _e,computeAngles as ve,computePixelSpaceLocations as ye,computeHistograms as be,computeStatisticsHistograms as xe,measureHeight as Se,measureAreaAndPerimeter as Ce,measureDistanceAndAngle as we,measurePointOrCentroid as Te,measureLengthFromImage as Ee,measureAreaFromImage as De,getImageSpatialReferenceQueryParameter as Oe,getSamples as ke,identify as K,imageToMap as Ae,imageToMapMultiray as je,mapToImage as Me,findImages as Ne,getImageUrl as Pe,queryBoundary as Fe,queryGPSInfo as Ie}from"../../rest/imageService.js";import{fetchServiceRasterInfo as q,generateRasterInfo as Le,patchServiceInfo as Re}from"../../rest/imageService/fetchRasterInfo.js";import{getCatalogItemRasterInfo as ze}from"../../rest/imageService/getCatalogItemRasterInfo.js";import{executeForCount as Be}from"../../rest/query/executeForCount.js";import{executeForExtent as Ve}from"../../rest/query/executeForExtent.js";import{executeForIds as He}from"../../rest/query/executeForIds.js";import{executeQueryJSON as Ue}from"../../rest/query/executeQueryJSON.js";import We from"../../rest/support/FeatureSet.js";import Ge from"../../rest/support/ImageIdentifyParameters.js";import J from"../../rest/support/Query.js";import{reader as Y}from"../../core/accessorSupport/decorators/reader.js";import{writer as X}from"../../core/accessorSupport/decorators/writer.js";const Ke=4096,qe=new Set([`png`,`png8`,`png24`,`png32`,`jpg`,`bmp`,`gif`,`jpgpng`,`lerc`,`tiff`]);function Je(e){let t=JSON.stringify(e),n=t.includes(`"rasterFunctionDefinition":{`),r=(n?t.match(/"type":"(.*?FunctionArguments")/gi):t.match(/"rasterFunction":"(.*?")/gi))?.map(e=>n?e.slice(8,-18):e.slice(18,-1));return r?r.join(`/`):null}const Z=Z=>{let Ye=Z,Q=class extends Ye{constructor(){super(...arguments),this._functionRasterInfos={},this._serviceSupportsMosaicRule=null,this._exportTileQueue=new o({concurrency:4,process:(e,t)=>this._fetchPixels(e.extent,e.width,e.height,{...e.options,signal:t})}),this.adjustAspectRatio=null,this.bandIds=void 0,this.capabilities=null,this.compressionQuality=void 0,this.compressionTolerance=.01,this.copyright=null,this.defaultMosaicRule=null,this.definitionExpression=null,this.exportImageServiceParameters=null,this.rasterInfo=null,this.fields=null,this.fullExtent=null,this.hasMultidimensions=!1,this.imageMaxHeight=4100,this.imageMaxWidth=4100,this.interpolation=void 0,this.minScale=0,this.maxScale=0,this.multidimensionalInfo=null,this.multidimensionalSubset=null,this.noData=null,this.noDataInterpretation=void 0,this.objectIdField=null,this.geometryType=`polygon`,this.typeIdField=null,this.types=[],this.pixelFilter=null,this.raster=void 0,this.sourceType=null,this.viewId=void 0,this.symbolizer=null,this.rasterFunctionInfos=null,this.serviceDataType=null,this.spatialReference=null,this.pixelType=null,this.serviceRasterInfo=null,this.sourceJSON=null,this.url=null,this.version=void 0}initialize(){this._set(`exportImageServiceParameters`,new k({layer:this}))}readServiceSupportsMosaicRule(e,t){return this._isMosaicRuleSupported(t)}get _rasterFunctionNamesIndex(){let e=new Map;return!this.rasterFunctionInfos||this.rasterFunctionInfos!=null&&this.rasterFunctionInfos.length<1||this.rasterFunctionInfos!=null&&this.rasterFunctionInfos.forEach(t=>{e.set(t.name.toLowerCase().replaceAll(/ /gi,`_`),t.name)}),e}readBandIds(e,t){if(Array.isArray(e)&&e.length>0&&e.every(e=>typeof e==`number`))return e}readCapabilities(e,t){return this._readCapabilities(t)}writeCompressionQuality(e,t,n){e!=null&&this.format!==`lerc`&&(t[n]=e)}writeCompressionTolerance(e,t,n){this.format===`lerc`&&e!=null&&(t[n]=e)}readDefaultMosaicRule(e,t){return this._serviceSupportsMosaicRule?p(()=>N.fromJSON(t)):null}get fieldsIndex(){return this.fields?new j(this.fields):null}set format(e){e&&qe.has(e.toLowerCase())&&this._set(`format`,e.toLowerCase())}readFormat(e,t){return t.serviceDataType===`esriImageServiceDataTypeVector-UV`||t.serviceDataType===`esriImageServiceDataTypeVector-MagDir`||this.pixelFilter!=null||t.allowRasterFunction===!1?`lerc`:`jpgpng`}get isRenderedFormat(){return!this.format||this.format.includes(`jpg`)||this.format.includes(`png`)}readMinScale(e,t){return t.minLOD!=null&&t.maxLOD!=null?e:0}readMaxScale(e,t){return t.minLOD!=null&&t.maxLOD!=null?e:0}set mosaicRule(e){let t=e;t?.mosaicMethod&&(t=N.fromJSON({...t.toJSON(),mosaicMethod:t.mosaicMethod,mosaicOperation:t.mosaicOperation})),this._set(`mosaicRule`,t)}readMosaicRule(e,t){let n=e||t.mosaicRule;return n?N.fromJSON(n):this._isMosaicRuleSupported(t)?N.fromJSON(t):null}writeMosaicRule(e,t,n){let{mosaicRule:r}=this;this._isValidCustomizedMosaicRule(r)&&(t[n]=r.toJSON())}readObjectIdField(e,t){return e||=t.fields.find(e=>e.type===`esriFieldTypeOID`||e.type===`oid`)?.name,e}get parsedUrl(){return c(this.url)}readSourceType(e,t){return this._isMosaicDataset(t)?`mosaic-dataset`:`raster-dataset`}get renderer(){let{activePresetRendererName:e,presetRenderers:t}=this;return e?(t?.find(({name:t})=>t===e))?.renderer.clone():this.internalRenderer}set renderer(e){this.activePresetRendererName=null,this.internalRenderer=e}set internalRenderer(e){this.loaded&&(e=this._configRenderer(e)),this._set(`internalRenderer`,e)}readRenderer(e,t,n){let r=t?.layerDefinition?.drawingInfo?.renderer,i=ge(r,n);return i==null?null:(i.type===`vector-field`&&t.symbolTileSize&&!r.symbolTileSize&&(i.symbolTileSize=t.symbolTileSize),ee(i)||a.getLogger(this).warn(`ArcGISImageService`,`Imagery layer doesn't support given renderer type.`),i)}writeRenderer(e,t,n){t.layerDefinition=t.layerDefinition||{},t.layerDefinition.drawingInfo=t.layerDefinition.drawingInfo||{},t.layerDefinition.drawingInfo.renderer=e.toJSON()}get rasterFields(){let e=this.fields?.map(e=>e.clone())??[];e.push(ne()),this.sourceType===`mosaic-dataset`&&this.fields?.length&&e.push(re()),this.version>=10.4&&this.rasterFunctionInfos!=null&&this.rasterFunctionInfos.some(({name:e})=>e.toLowerCase()===`none`)&&e.push(ie()),this.rasterFunctionInfos!=null&&this.rasterFunctionInfos.filter(({name:e})=>e.toLowerCase()!==`none`).forEach(({name:t})=>e.push(ae(t)));let{rasterInfo:t}=this;if(this._isVectorDataSet()){let n=t?.multidimensionalInfo?.variables[0].unit?.trim(),r=oe(n),i=se();e.push(r,i)}if(t?.multidimensionalInfo&&this.sourceType===`raster-dataset`){let n=ce(t.multidimensionalInfo);e.push(...n)}let n=t?.attributeTable;if(n!=null){let t=le(n);e.push(...t)}return e}set rasterFunction(e){let t=e;t?.rasterFunction&&(t=z.fromJSON({...t.toJSON(),rasterFunction:t.rasterFunction,rasterFunctionArguments:t.rasterFunctionArguments})),this._set(`rasterFunction`,t)}readRasterFunction(e,t){let n=t.rasterFunctionInfos,r=t.renderingRule,i=r!=null&&Object.keys(r).length>0;return!i&&(!n?.length||n[0].name===`None`)?null:this._isRFTJson(r)?z.fromJSON({rasterFunctionDefinition:r}):z.fromJSON(i?r:{rasterFunctionInfos:n})}readSpatialReference(e,t){let n=e||t.extent.spatialReference;return n?g.fromJSON(n):null}writePixelType(e,t,n){(this.serviceRasterInfo==null||this.pixelType!==this.serviceRasterInfo.pixelType)&&(t[n]=L.toJSON(e))}readVersion(e,t){let n=t.currentVersion;return n||=t.hasOwnProperty(`fields`)||t.hasOwnProperty(`timeInfo`)?10:9.3,n}applyFilter(e){let t=e;return this.pixelFilter&&(t=this._clonePixelData(e),this.pixelFilter(t)),t}async applyRenderer(e,t){let n=e,{renderer:r,symbolizer:i,pixelFilter:a}=this,{isRawData:o}=e;if(o&&this.format!==`lerc`&&(r??=B(this.rasterInfo,{bandIds:this.bandIds,variableName:this.rasterFunction?null:this.mosaicRule?.multidimensionalDefinition?.[0].variableName}),i||=(this.symbolizer=new W({rendererJSON:r.toJSON(),rasterInfo:this.rasterInfo}),this.symbolizer)),(o||!this.isRenderedFormat)&&r&&i&&!a){await this._updateSymbolizer(i,r);let a=this.bandIds?.length?this.bandIds:V(this.rasterInfo);n=await this._symbolize({pixelData:e,bandIds:a,symbolizer:i},t)}return n}destroy(){this._shutdownJobHandler()}async calculateVolume(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsCalculateVolume)throw new r(`imagery-layer:compute-pixel-space-locations`,`this operation is not supported on the input image service`);return e=i(e),this.mosaicRule&&e.mosaicRule==null&&(e.mosaicRule=this.mosaicRule),_e(this.url,e,this._getRequestOptions(t))}async computeAngles(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsComputeAngles)throw new r(`imagery-layer:compute-angles`,`this operation is not supported on the input image service`);return ve(this.url,e,this._getRequestOptions(t))}async computePixelSpaceLocations(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsComputePixelLocation)throw new r(`imagery-layer:compute-pixel-space-locations`,`this operation is not supported on the input image service`);return ye(this.url,e,this._getRequestOptions(t))}async computeHistograms(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsComputeHistograms)throw new r(`imagery-layer:compute-histograms`,`this operation is not supported on the input image service`);return e=i(e),this._applyMosaicAndRenderingRules(e),be(this.url,e,this._getRequestOptions(t))}async computeStatisticsHistograms(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsComputeStatisticsHistograms)throw new r(`imagery-layer:compute-statistics-histograms`,`this operation is not supported on the input image service`);return e=i(e),this._applyMosaicAndRenderingRules(e),xe(this.url,e,this._getRequestOptions(t))}async measureHeight(e,t){let n=await this._fetchCapabilities(t?.signal);if(!(e.operationType===`base-and-top`?n.mensuration.supportsHeightFromBaseAndTop:e.operationType===`base-and-top-shadow`?n.mensuration.supportsHeightFromBaseAndTopShadow:n.mensuration.supportsHeightFromTopAndTopShadow))throw new r(`imagery-layer:measure-height`,`this operation is not supported on the input image service`);return e=i(e),this._applyMosaicRule(e),Se(this.url,e,this._getRequestOptions(t))}async measureAreaAndPerimeter(e,t){let n=await this._fetchCapabilities(t?.signal);if(!n.mensuration.supportsAreaAndPerimeter||e.is3D&&!n.mensuration.supports3D)throw new r(`imagery-layer:measure-area-and-perimeter`,`this operation is not supported on the input image service`);return e=i(e),this._applyMosaicRule(e),Ce(this.url,e,this._getRequestOptions(t))}async measureDistanceAndAngle(e,t){let n=await this._fetchCapabilities(t?.signal);if(!n.mensuration.supportsDistanceAndAngle||e.is3D&&!n.mensuration.supports3D)throw new r(`imagery-layer:measure-distance-and-angle`,`this operation is not supported on the input image service`);return e=i(e),this._applyMosaicRule(e),we(this.url,e,this._getRequestOptions(t))}async measurePointOrCentroid(e,t){let n=await this._fetchCapabilities(t?.signal);if(!n.mensuration.supportsPointOrCentroid||e.is3D&&!n.mensuration.supports3D)throw new r(`imagery-layer:measure-point-or-centroid`,`this operation is not supported on the input image service`);return e=i(e),this._applyMosaicRule(e),Te(this.url,e,this._getRequestOptions(t))}async measureLengthFromImage(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsMeasureFromImage)throw new r(`imagery-layer:measure-length-from-image`,`this operation is not supported on the input image service`);if(e.geometry.type!==`polyline`)throw new r(`imagery-layer:measure-length-from-image`,`this input geometry must be a polyline`);return Ee(this.url,e,this._getRequestOptions(t))}async measureAreaFromImage(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsMeasureFromImage)throw new r(`imagery-layer:measure-area-from-image`,`this operation is not supported on the input image service`);if(e.geometry.type!==`polygon`)throw new r(`imagery-layer:measure-area-from-image`,`this input geometry must be a polygon`);return De(this.url,e,this._getRequestOptions(t))}getField(e){let{fieldsIndex:t}=this;return t?.get(e)}getFieldDomain(e,t){let n=this.getField(e);return n?n.domain:null}async internalFetchImage(e,t,n,r={}){await this._updateCurrentRasterInfo();let{exportImageServiceParameters:i}=this,a=!1;if(r.requestRawData&&(await this._initJobHandler(),!i.requestRawData&&this.format!==`lerc`)){a=!0,i.requestRawData=!0;let e=this.bandIds;if(!e?.length){let t=V(this.rasterInfo);Array.from({length:this.rasterInfo.bandCount},(e,t)=>t)?.join(`,`)!==t?.join(`,`)&&(e=t)}i.rawDataRequestBandIds=e}let o=this.getExportImageServiceParameters(e,t,n,r.timeExtent);if(a&&(i.requestRawData=!1,i.rawDataRequestBandIds=null),o==null){if(r.requestAsImageElement&&this._canRequestImageElement(this.format)){let e=document.createElement(`canvas`);if(e.width=t,e.height=n,r.returnImageBitmap){let{bitmap:t}=await M(e,`${$(this.parsedUrl)}/exportImage`,r);return{imageBitmap:t}}return{imageOrCanvasElement:e}}let{bandIds:i,rasterInfo:a}=this,o=(i?.length||a.bandCount)??0,s=t*n,c=a.pixelType,l=[];for(let e=0;e<o;e++)l.push(P.createEmptyBand(c,s));return{pixelData:{pixelBlock:new P({width:t,height:n,pixels:l,mask:new Uint8Array(s),pixelType:c}),extent:e}}}let s=!!r.requestAsImageElement&&!this.pixelFilter,c=s&&!!r.returnImageBitmap,l={imageServiceParameters:o,imageProps:{extent:e,width:t,height:n,format:this.format},requestAsImageElement:s,returnImageBitmap:c,signal:r.signal};return this._requestArrayBuffer(l)}async fetchPixels(e,t,n,i={}){await this._initJobHandler(),i.applyRendering&&await this._updateCurrentRasterInfo();let{imageMaxWidth:a,imageMaxHeight:o}=this;if(t<=a&&n<=o)return this._exportTileQueue.push({extent:e,width:t,height:n,options:i},{signal:i.signal});if(t>Ke||n>Ke||a<512||o<512)throw new r(`imagery-layer:fetch-pixels`,`The image service has a maximum export size of ${a}x${o}. The requested size of ${t}x${n} exceeds this limit.`);let{xmin:s,ymax:c,spatialReference:l}=this._projectedFullExtent??this.fullExtent;if(!l?.equals(e.spatialReference)){let{projectLoad:t,projectExecute:n}=await import(`../../geometry/operators/projectOperator.js`);await t();let r=n(this.fullExtent,e.spatialReference);s=r.xmin,c=r.ymax,this._projectedFullExtent=r}let u=e.width/t,d=e.height/n,f=Math.floor((e.xmin-s)/u),p=Math.floor((c-e.ymax)/d),h=f+t,g=p+n,_=Math.floor(f/512),v=Math.floor(p/512),y=Math.ceil(h/512)-1,b=Math.ceil(g/512)-1,x=512*u,S=512*d,C=[];for(let t=v;t<=b;t++){let n=c-t*S,r=n-S;for(let t=_;t<=y;t++){let a=s+t*x,o=new m({xmin:a,ymin:r,xmax:a+x,ymax:n,spatialReference:e.spatialReference});C.push(this._exportTileQueue.push({extent:o,width:512,height:512,options:i},{signal:i.signal}))}}let T=await Promise.all(C);return T.some(e=>e.pixelBlock==null)?{extent:e,pixelBlock:null}:{extent:e,pixelBlock:this._rasterJobHandler?await this._rasterJobHandler.mosaicPixelData({pixelBlocks:T,destExtent:e},{signal:i.signal,transferPixelsToWorker:!0}):w(T,e)?.pixelBlock}}async _fetchPixels(e,t,n,r={}){let i=r.applyRendering?void 0:new k({layer:this,requestRawData:!0,interpolation:r.interpolation??`nearest`,bandIds:r.bandIds??[]}),a=this.getExportImageServiceParameters(e,t,n,r.timeExtent,i);if(a==null)return{extent:e,pixelBlock:null};delete a.pixelType,r.bandIds||delete a.bandIds,delete a.compressionQuality;let o={imageServiceParameters:a,imageProps:{extent:e,width:t,height:n,format:this.format},requestAsImageElement:!1,returnImageBitmap:!1,signal:r.signal},{pixelData:s}=await this._requestArrayBuffer(o);return s??{extent:e,pixelBlock:null}}fetchKeyProperties(e){return n($(this.parsedUrl)+`/keyProperties`,{query:this._getQueryParams({renderingRule:this.version>=10.3?e?.rasterFunction:null})}).then(e=>e.data)}fetchRasterAttributeTable(e){return this.version<10.1?Promise.reject(new r(`#fetchRasterAttributeTable()`,`Failed to get rasterAttributeTable`)):n($(this.parsedUrl)+`/rasterAttributeTable`,{query:this._getQueryParams({renderingRule:this.version>=10.3?e?.rasterFunction:null})}).then(e=>We.fromJSON(e.data))}getCatalogItemRasterInfo(e,t){let n=this._getQueryParams(),r={...t,query:n};return ze($(this.parsedUrl),e,r)}async getCatalogItemICSInfo(e,t){let{data:r}=await n($(this.parsedUrl)+`/`+e+`/info/ics`,{query:this._getQueryParams(),...t}),i=r?.ics;if(!i)return;let a=null;try{a=(await n($(this.parsedUrl)+`/`+e+`/info`,{query:this._getQueryParams(),...t})).data.extent}catch{}if(!a?.spatialReference)return{ics:i,icsToPixelTransform:null,icsExtent:null,northDirection:null};let o=this.version>=10.7?n($(this.parsedUrl)+`/`+e+`/info/icstopixel`,{query:this._getQueryParams(),...t}).then(e=>e.data).catch(()=>({})):{},s=a.spatialReference,c={geometries:JSON.stringify({geometryType:`esriGeometryEnvelope`,geometries:[a]}),inSR:_(s),outSR:`0:`+e},l=n($(this.parsedUrl)+`/project`,{query:this._getQueryParams(c),...t}).then(e=>e.data).catch(()=>({})),u=(a.xmin+a.xmax)/2,d=(a.ymax-a.ymin)/6,f=a.ymin+d,p=[];for(let e=0;e<5;e++)p.push({x:u,y:f+d*e});let h={geometries:JSON.stringify({geometryType:`esriGeometryPoint`,geometries:p}),inSR:_(s),outSR:`0:`+e},v=n($(this.parsedUrl)+`/project`,{query:this._getQueryParams(h),...t}).then(e=>e.data).catch(()=>({})),y=await Promise.all([o,l,v]),b=y[0].ipxf;if(b==null){let e=i.geodataXform?.xf_0;e?.name?.toLowerCase()===`topup`&&e?.coefficients?.length===6&&(b={affine:{name:`ics [sensor: Frame] to pixel (column, row) transformation`,coefficients:e.coefficients,cellsizeRatio:0,type:`GeometricXform`}})}let x=m.fromJSON(y[1]?.geometries?.[0]);x&&(x.spatialReference=new g({wkid:0,imageCoordinateSystem:i}));let S=y[2].geometries?y[2].geometries.filter(e=>e?.x!=null&&e.y!=null&&e.x!==`NaN`&&e.y!==`NaN`):[],C=S.length;if(C<3)return{ics:i,icsToPixelTransform:b,icsExtent:x,northDirection:null};let w=0,T=0,E=0,D=0;for(let e=0;e<C;e++)w+=S[e].x,T+=S[e].y,E+=S[e].x*S[e].x,D+=S[e].x*S[e].y;let O=(C*D-w*T)/(C*E-w*w),k=0,A=S[4].x>S[0].x,j=S[4].y>S[0].y;return O===1/0?k=j?90:270:O===0?k=A?0:180:O>0?k=A?Math.atan(O)*180/Math.PI:Math.atan(O)*180/Math.PI+180:O<0&&(k=j?180+Math.atan(O)*180/Math.PI:360+Math.atan(O)*180/Math.PI),{ics:i,icsToPixelTransform:b,icsExtent:x,northDirection:k}}async generateRasterInfo(e,t){let n=f(z,e),i={...t,query:this._getQueryParams()};if(!n||n.functionName?.toLowerCase()===`none`||this._isVectorFieldResampleFunction(n))return this.serviceRasterInfo??q($(this.parsedUrl),this.sourceJSON,i);let a=Je(n);if(!a)throw new r(`imagery-layer:generate-raster-info`,`the rendering rule is not supported`);if(this._functionRasterInfos[a])return this._functionRasterInfos[a];let o=Le($(this.parsedUrl),n,i);this._functionRasterInfos[a]=o;try{let t=await o,{rasterFunction:n}=this;return(n===e||JSON.stringify(n)===JSON.stringify(e))&&JSON.stringify(this.rasterInfo)!==JSON.stringify(t)&&(this.rasterInfo=t),t}catch(e){throw this._functionRasterInfos[a]=null,e}}getExportImageServiceParameters(e,t,n,r,i){e=e.clone().shiftCentralMeridian();let a=Oe(e.spatialReference,$(this.parsedUrl));i??=this.exportImageServiceParameters;let o=i.toJSON(),{bandIds:s,noData:c}=o,{renderingRule:l}=o,u=this.rasterFunction?.rasterFunctionDefinition,d=this.renderer?.type,f=!d||d===`raster-stretch`||d===`raster-colormap`||d===`unique-value`||d===`class-breaks`||d===`raster-shaded-relief`;if(s?.length&&this._hasRasterFunction(this.rasterFunction)&&!u&&f){let e={rasterFunction:`ExtractBand`,rasterFunctionArguments:{BandIds:s}};if(l.rasterFunction===`Stretch`)e.rasterFunctionArguments.Raster=l.rasterFunctionArguments.Raster,l.rasterFunctionArguments.Raster=e;else if(l.rasterFunction===`Colormap`){let t=l.rasterFunctionArguments.Raster;t?.rasterFunction===`Stretch`?(e.rasterFunctionArguments.Raster=t.rasterFunctionArguments.Raster,t.rasterFunctionArguments.Raster=e):(e.rasterFunctionArguments.Raster=t,l.rasterFunctionArguments.Raster=e)}else e.rasterFunctionArguments.Raster=l,l=e;o.bandIds=void 0}else o.bandIds=s?.join(`,`);Array.isArray(c)&&c.length>0&&(o.noData=c.join(`,`));let p=this._processMultidimensionalIntersection(null,r,i.mosaicRule);if(p.isOutSide)return null;o.mosaicRule=p.mosaicRule==null?null:JSON.stringify(p.mosaicRule),r=p.timeExtent,o.renderingRule=this._getRenderingRuleString(z.fromJSON(l));let m={};if(r!=null){let{start:e,end:t}=r.toJSON();e&&t&&e===t?m.time=``+e:(e!=null||t!=null)&&(m.time=`${e??`null`},${t??`null`}`)}return{bbox:e.xmin+`,`+e.ymin+`,`+e.xmax+`,`+e.ymax,bboxSR:a,imageSR:a,size:t+`,`+n,...o,...m}}async getSamples(e,t){if(!(await this._fetchCapabilities(t?.signal))?.operations.supportsGetSamples)throw new r(`imagery-layer:get-samples`,`getSamples operation is not supported on the input image service`);e=i(e);let{raster:n}=this;return n&&e.raster==null&&(e.raster=n),ke(this.url,e,this._getRequestOptions(t))}async identify(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsIdentify)throw new r(`imagery-layer:identify`,`identify operation is not supported on the input image service`);e=i(e),this.version<10.91&&e.geometry?.type===`extent`&&(e.geometry=h.fromExtent(e.geometry));let n=this._processMultidimensionalIntersection(e.geometry,e.timeExtent,e.mosaicRule||this.mosaicRule);if(n.isOutSide)throw new r(`imagery-layer:identify`,`the request cannot be fulfilled when falling outside of the multidimensional subset`);e.timeExtent=n.timeExtent,e.mosaicRule=n.mosaicRule;let{raster:a,rasterFunction:o}=this;return o&&e.rasterFunction==null&&(e.rasterFunction=o),a&&e.raster==null&&(e.raster=a),K(this.url,e,this._getRequestOptions(t))}async imageToMap(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsImageToMap)throw new r(`imagery-layer:image-to-map`,`imageToMap operation is not supported on the input image service`);return Ae($(this.parsedUrl),e,this._getRequestOptions(t))}async imageToMapMultiray(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsImageToMapMultiray)throw new r(`imagery-layer:image-to-map-multiray`,`imageToMapMultiray operation is not supported on the input image service`);return je($(this.parsedUrl),e,this._getRequestOptions(t))}async mapToImage(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsMapToImage)throw new r(`imagery-layer:map-to-image`,`mapToImage operation is not supported on the input image service`);return Me($(this.parsedUrl),e,this._getRequestOptions(t))}async findImages(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsFindImages)throw new r(`imagery-layer:find-images`,`findImages operation is not supported on the input image service`);return Ne($(this.parsedUrl),e,this._getRequestOptions(t))}async getImageUrl(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsGetImageUrl)throw new r(`imagery-layer:get-image-url`,`getImageUrl operation is not supported on the input image service`);return Pe($(this.parsedUrl),e,this._getRequestOptions(t))}createQuery(){return new J({outFields:[`*`],returnGeometry:!0,where:this.definitionExpression||`1=1`})}async queryBoundary(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsQueryBoundary)throw new r(`imagery-layer:query-boundary`,`queryBoundary operation is not supported on the input image service`);return e??={outSpatialReference:this.spatialReference},Fe($(this.parsedUrl),e,this._getRequestOptions(t))}async queryExtent(e,t){({query:e,requestOptions:t}=await this._prepareForQuery(e,t));let{where:n,objectIds:r,geometry:i,timeExtent:a,start:o,num:s,pixelSize:c}=e,l=n!=null&&n!==`1=1`,u=r!=null&&r.length>0,d=i!=null&&(i.type!==`extent`||!i.equals(this.fullExtent)),f=c!=null,p=o!=null||s!=null,{timeInfo:m}=this,h=a!=null&&m!=null&&!a.equals(m.fullTimeExtent);if(!(l||u||d||f||h||p)){let n=await Be(this.url,e,t),{outSpatialReference:r}=e;if(!r||r.equals(this.spatialReference))return{count:n,extent:this.fullExtent.clone()};let{projectLoad:i,projectExecute:a}=await import(`../../geometry/operators/projectOperator.js`);return await i(),{count:n,extent:a(this.fullExtent,r)}}return Ve(this.url,e,t)}async queryRasters(e,t){({query:e,requestOptions:t}=await this._prepareForQuery(e,t));let n=await Ue(this.url,e,t),r=this.graphicOrigin;return n.features.forEach(e=>{e.layer=this,e.origin=r}),n}async queryObjectIds(e,t){return{query:e,requestOptions:t}=await this._prepareForQuery(e,t),He(this.url,e,t)}async queryGPSInfo(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsQueryGPSInfo)throw new r(`imagery-layer:query-gps-info`,`queryGPSInfo operation is not supported on the input image service`);return e??={where:`1=1`},Ie($(this.parsedUrl),e,this._getRequestOptions(t))}async queryRasterCount(e,t){return{query:e,requestOptions:t}=await this._prepareForQuery(e,t),Be(this.url,e,t)}async queryVisibleRasters(e,t){if(!e)throw new r(`imagery-layer: query-visible-rasters`,`missing query parameter`);await this.load();let{pixelSize:n,returnDomainValues:i,returnTopmostRaster:a,showNoDataRecords:o}=t||{pixelSize:null,returnDomainValues:!1,returnTopmostRaster:!1,showNoDataRecords:!1},s=!1,c=null,l=null,u=R.servicePixelValue.toLowerCase(),d=this._rasterFunctionNamesIndex;if(e.outFields!=null&&(s=e.outFields.some(e=>!e.toLowerCase().startsWith(u)),this.version>=10.4)){let t=e.outFields.filter(e=>e.toLowerCase().startsWith(u)&&e.length>u.length).map(e=>{let t=e.slice(u.length+1);return[this._updateRenderingRulesFunctionName(t,d),t]});c=t.map(e=>new z({functionName:e[0]})),l=t.map(e=>e[1]);let{rasterFunction:n}=this;c.length===0?n?.functionName?(c.push(n),l.push(n.functionName)):c=null:n?.functionName&&!c.some(e=>e.functionName===n.functionName)&&(c.push(n),l.push(n.functionName))}let f=e.outSpatialReference==null||e.outSpatialReference.equals(this.spatialReference),{multidimensionalSubset:p}=this,m=e.timeExtent||this.timeExtent;if(p){let{isOutside:t,intersection:n}=v(p,{geometry:e.geometry,timeExtent:e.timeExtent,multidimensionalDefinition:this.exportImageServiceParameters.mosaicRule?.multidimensionalDefinition});if(t)throw new r(`imagery-layer:query-visible-rasters`,`the request cannot be fulfilled when falling outside of the multidimensional subset`);n?.timeExtent!=null&&(m=n.timeExtent)}let g=this._combineMosaicRuleWithTimeExtent(this.exportImageServiceParameters.mosaicRule,m),_=e.geometry;this.version<10.91&&_?.type===`extent`&&(_=h.fromExtent(_));let b=this._getQueryParams({geometry:_,timeExtent:m,mosaicRule:g,rasterFunction:this.version<10.4?this.rasterFunction:null,rasterFunctions:c,pixelSize:n,returnCatalogItems:s,returnGeometry:f,raster:this.raster,maxItemCount:a?1:null});delete b.f;let x=new Ge(b);try{await this._generateRasterInfo(this.rasterFunction);let n=await K(this.url,x,{signal:t?.signal,query:{...this.customParameters}}),r=e.outFields,a=n.value!=null&&n.value.toLowerCase().includes(`nodata`),c=s&&!f&&n?.catalogItems?.features.length&&(o||!a),u=this.multidimensionalInfo&&this.sourceType===`raster-dataset`?y({rasterInfo:this.rasterInfo,multidimensionalDefinition:g?.multidimensionalDefinition,timeExtent:m,multidimensionalSubset:this.multidimensionalSubset}):null;if(!c)return this._processVisibleRastersResponse(n,{returnDomainValues:i,templateRRFunctionNames:l,showNoDataRecords:o,templateFields:r,effectiveMultidimensionalDefinition:u});let d=this.objectIdField||`ObjectId`,p=n.catalogItems?.features??[],h=p.map(e=>e.attributes?.[d]),_=new J({objectIds:h,returnGeometry:!0,outSpatialReference:e.outSpatialReference,outFields:[d]}),v=await this.queryRasters(_);return v?.features?.length&&v.features.forEach(t=>{p.forEach(n=>{n.attributes[d]===t.attributes[d]&&t.geometry&&(n.geometry=t.geometry.clone(),e.outSpatialReference!=null&&(n.geometry.spatialReference=e.outSpatialReference))})}),this._processVisibleRastersResponse(n,{returnDomainValues:i,templateRRFunctionNames:l,showNoDataRecords:o,templateFields:r,effectiveMultidimensionalDefinition:u})}catch{throw new r(`imagery-layer:query-visible-rasters`,`encountered error when querying visible rasters`)}}async fetchVariableStatisticsHistograms(e,t){let r=n($(this.parsedUrl)+`/statistics`,{query:this._getQueryParams({variable:e}),signal:t}).then(e=>e.data?.statistics),i=n($(this.parsedUrl)+`/histograms`,{query:this._getQueryParams({variable:e}),signal:t}).then(e=>e.data?.histograms),a=await Promise.all([r,i]);return a[0]&&a[0].forEach(e=>{e.avg=e.mean,e.stddev=e.standardDeviation}),{statistics:a[0]||null,histograms:a[1]||null}}getMultidimensionalSubsetVariables(e){let t=e??this.serviceRasterInfo.multidimensionalInfo;return b(this.multidimensionalSubset,t)}async _fetchService(e){await this._fetchServiceInfo(e);let t=this.sourceJSON,n=this.serviceRasterInfo==null?q($(this.parsedUrl),t,{signal:e,query:this._getQueryParams()}).then(e=>(this._set(`serviceRasterInfo`,e),this._set(`multidimensionalInfo`,e.multidimensionalInfo),Re(e,t),e)):Promise.resolve(this.serviceRasterInfo),r=!this.rasterInfo&&this._hasRasterFunction(this.rasterFunction)?this._generateRasterInfo(this.rasterFunction,{signal:e}):Promise.resolve(this.rasterInfo),i=this.rasterFunctionInfos?.every(e=>e.functionType!=null)?null:this._getRasterFunctionInfos();return Promise.all([n,r,i]).then(e=>{e[1]?this._set(`rasterInfo`,e[1]):this._set(`rasterInfo`,e[0]),e[2]&&(t.rasterFunctionInfos=e[2],this.setAtOrigin(`rasterFunctionInfos`,e[2],`service`)),this.internalRenderer&&!this._isSupportedRenderer(this.internalRenderer)&&(this._set(`internalRenderer`,null),a.getLogger(this).warn(`ArcGISImageService`,`Switching to the default renderer. Renderer applied is not valid for this Imagery Layer`)),this._set(`internalRenderer`,this._configRenderer(this.renderer)),this.addHandles([s(()=>this.rasterFunction,e=>{(this.renderer||this.symbolizer||this.popupEnabled&&this.popupTemplate)&&this._generateRasterInfo(e).then(e=>{e&&(this.rasterInfo=e)})})]);let{serviceRasterInfo:n}=this;n.multidimensionalInfo!=null&&this._updateMultidimensionalDefinition(n)})}_combineMosaicRuleWithTimeExtent(e,t){let n=this.timeInfo,{multidimensionalInfo:r}=this.serviceRasterInfo;if(e==null||r==null||t==null||n?.startField==null)return e;let{startField:i}=n,a=r.variables.some(e=>e.dimensions.some(e=>e.name===i))?i:`StdTime`;if(e=e.clone(),this.sourceType===`mosaic-dataset`)return e.multidimensionalDefinition=e.multidimensionalDefinition?.filter(e=>e.dimensionName!==a),this._cleanupMultidimensionalDefinition(e);e.multidimensionalDefinition=e.multidimensionalDefinition||[];let o=e.multidimensionalDefinition.filter(e=>e.dimensionName===a),s=t.start==null?null:t.start.getTime(),c=t.end==null?null:t.end.getTime(),l=s==null||c==null||s===c,u=l?[s||c]:[[s,c]],d=this.version>=10.8;if(o.length)o.forEach(e=>{e.dimensionName===a&&(d?(e.dimensionName=null,e.isSlice=!1,e.values=[]):(e.isSlice=l,e.values=u))});else if(!d){let t=e.multidimensionalDefinition.filter(e=>e.variableName!=null&&e.dimensionName==null);t.length?t.forEach(e=>{e.dimensionName=a,e.isSlice=l,e.values=u}):e.multidimensionalDefinition.push(new O({variableName:``,dimensionName:a,isSlice:l,values:u}))}return this._cleanupMultidimensionalDefinition(e)}_cleanupMultidimensionalDefinition(e){return e==null?null:(e.multidimensionalDefinition&&(e.multidimensionalDefinition=e.multidimensionalDefinition.filter(e=>!!(e.variableName||e.dimensionName)),e.multidimensionalDefinition.length===0&&(e.multidimensionalDefinition=null)),this.sourceType!==`mosaic-dataset`&&e.multidimensionalDefinition==null?null:e)}async _prepareForQuery(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsQuery)throw new r(`imagery-layer:query-rasters`,`query operation is not supported on the input image service`);let n=e==null?this.createQuery():f(J,e);return t=this._getRequestOptions(t),this.raster&&(t.query={...t.query,raster:this.raster}),{query:n,requestOptions:t}}_isSupportedRenderer(e){let{rasterInfo:t,rasterFunction:n}=this;return e.type===`unique-value`&&this._hasRasterFunction(n)&&t?.bandCount===1&&[`u8`,`s8`].includes(t.pixelType)||t!=null&&e!=null&&H(t).includes(e.type)}async _fetchCapabilities(e){return this.capabilities||await this._fetchServiceInfo(e),this.capabilities}async _fetchServiceInfo(e){let t=this.sourceJSON;if(!t){let{data:r,ssl:i}=await n($(this.parsedUrl),{query:this._getQueryParams(),signal:e});t=r,this.sourceJSON=t,i&&(this.url=this.url.replace(/^http:/i,`https:`))}if(t.capabilities?.toLowerCase().split(`,`).map(e=>e.trim()).indexOf(`tilesonly`)>-1)throw new r(`imagery-layer:fetch-service-info`,`use ImageryTileLayer to open tiles-only image services`);this.read(t,{origin:`service`,url:this.parsedUrl})}_isMosaicDataset(e){return e.serviceSourceType?e.serviceSourceType===`esriImageServiceSourceTypeMosaicDataset`:e.fields?.length>0}_isMosaicRuleSupported(e){if(!e)return!1;let t=this._isMosaicDataset(e),n=e.currentVersion>=10.71&&e.hasMultidimensions&&!(e.fields?.length>1);return t||n}_isVectorFieldResampleFunction(e){if(e==null)return!1;let{functionName:t,functionArguments:n}=e,r=t?.toLowerCase()===`resample`,i=n?.ResampleType||n?.resampleType;return r&&(i===7||i===10)}_configRenderer(e){let{rasterInfo:t}=this,n=t.attributeTable,r=U(n,`red`)!=null&&U(n,`green`)!=null&&U(n,`blue`)!=null,i=!e&&t.colormap==null&&!r&&H(t).includes(`unique-value`);if(!(this.isRenderedFormat||this.pixelFilter)||this._isVectorDataSet()||i){let n=this.mosaicRule?.multidimensionalDefinition?.[0].variableName,r=pe({variableName:n,rasterFunctionName:this.rasterFunction?.functionName,presetRenderers:this.presetRenderers});if(!this.bandIds&&t.bandCount>=3){let e=r?.bandIds??V(t);e&&(t.bandCount!==3||e[0]!==0||e[1]!==1||e[2]!==2)&&(this.bandIds=e)}e||=r?.renderer??B(t,{bandIds:this.bandIds,variableName:this.rasterFunction?null:n});let i=me(e.toJSON());this.symbolizer?(this.symbolizer.rendererJSON=i,this.symbolizer.rasterInfo=t):this.symbolizer=new W({rendererJSON:i,rasterInfo:t}),this.symbolizer.bind().success||(this.symbolizer=null)}return e}_clonePixelData(e){return e==null?e:{extent:e.extent&&e.extent.clone(),pixelBlock:e.pixelBlock==null?null:e.pixelBlock.clone()}}_getQueryParams(e){e?.renderingRule!=null&&typeof e.renderingRule!=`string`&&(e.renderingRule=this._getRenderingRuleString(e.renderingRule));let{raster:t,viewId:n}=this;return{raster:t,viewId:n,f:`json`,...e,...this.customParameters}}_getRequestOptions(e){return{...e,query:{...e?.query,...this.customParameters}}}_decodePixelBlock(e,t,n){return this._rasterJobHandler?this._rasterJobHandler.decode({data:e,options:t}):S(e,t,n)}async _getRasterFunctionInfos(e){let t=this.sourceJSON.rasterFunctionInfos;return this.loaded||!t?.length?t:t&&this.version>=10.3?t.length===1&&t[0].name.toLowerCase()===`none`?[{thumbnail:``,functionType:0,...t[0]}]:(await n($(this.parsedUrl)+`/rasterFunctionInfos`,{query:this._getQueryParams(),signal:e})).data?.rasterFunctionInfos:null}_canRequestImageElement(e){return!this.pixelFilter&&(!e||e.includes(`png`))}async _requestArrayBuffer(e){let{imageProps:t,requestAsImageElement:i,returnImageBitmap:a,signal:o}=e;if(i&&this._canRequestImageElement(t.format)){let r=`${$(this.parsedUrl)}/exportImage`,{data:i}=await n(r,{responseType:a?`blob`:`image`,query:this._getQueryParams({f:`image`,...this.refreshParameters,...e.imageServiceParameters}),signal:o});if(i instanceof Blob){let{bitmap:e}=await M(i,r,{signal:o});return{imageBitmap:e,params:t}}return{imageOrCanvasElement:i,params:t}}let s=this._initJobHandler(),c=n($(this.parsedUrl)+`/exportImage`,{responseType:`array-buffer`,query:this._getQueryParams({f:`image`,...e.imageServiceParameters}),signal:o}),l=(await Promise.all([c,s]))[0].data,u=t.format||`jpgpng`,d=u;if(d!==`bsq`&&d!==`bip`&&(d=C(l)),!d)throw new r(`imagery-layer:fetch-image`,`unsupported format signature `+String.fromCharCode.apply(null,new Uint8Array(l)));let f={signal:o};return{pixelData:{pixelBlock:await this._decodePixelBlock(l,{width:t.width,height:t.height,format:u,applyJpegMask:!0},f),extent:t.extent},params:t}}_generateRasterInfo(e,t){return this.generateRasterInfo(e,t).catch(()=>null)}_isValidCustomizedMosaicRule(e){return e&&JSON.stringify(e.toJSON())!==JSON.stringify(this.defaultMosaicRule?.toJSON())}_updateMultidimensionalDefinition(e){if(this._isValidCustomizedMosaicRule(this.mosaicRule))return;let t=x(e,{multidimensionalSubset:this.multidimensionalSubset});if(t!=null&&t.length>0){this.mosaicRule=this.mosaicRule||new N;let e=this.mosaicRule.multidimensionalDefinition;!this.sourceJSON.defaultVariableName&&this.rasterFunction&&this.rasterFunction.functionName?.toLowerCase()!==`none`&&t.forEach(e=>e.variableName=``),t=t.filter(({variableName:e,dimensionName:t})=>e&&e!==`*`||t),!e?.length&&t.length&&(this.mosaicRule.multidimensionalDefinition=t)}}_processVisibleRastersResponse(e,n){n||={};let r=e.value,{templateRRFunctionNames:i,showNoDataRecords:a,returnDomainValues:o,templateFields:s}=n,c=e.processedValues,l=e.catalogItems?.features,u=e.properties?.Values?.map(e=>e.replaceAll(/ /gi,`, `))||[],d=this.objectIdField||`ObjectId`,f=typeof r==`string`&&r.toLowerCase().includes(`nodata`),p=[];if(r&&!l&&(!f||a)){let e={};e[d]=0;let i=new t({geometry:this.fullExtent,attributes:e});u=[r],l=[i],this.multidimensionalInfo&&this.sourceType===`raster-dataset`&&ue(this.rasterFields,e,n.effectiveMultidimensionalDefinition)}if(!l)return[];this._updateResponseFieldNames(l,s),f&&!a&&(l=[]);let{itemPixelValue:m,servicePixelValue:h}=R,g=this.rasterFields.some(e=>e.name===m),_=this.graphicOrigin;for(let e=0;e<l.length;e++){let t=l[e];if(r!=null){let n=u[e],o=this.rasterFunction&&c&&c.length>0&&i&&i.length>0&&i.includes(this.rasterFunction.functionName)?c[i.indexOf(this.rasterFunction.functionName)]:r;if(n.toLowerCase()===`nodata`&&!a)continue;g&&(t.attributes[m]=n),t.attributes[h]=o,this._updateFeatureWithMagDirValues(t,n);let s=this.fields&&this.fields.length>0,l=this.rasterFunction&&this.serviceRasterInfo.attributeTable!=null?s?n:r:o;this.rasterFunction||(l=s?n:r),this._updateFeatureWithRasterAttributeTableValues(t,l)}if(t.sourceLayer=t.layer=this,t.origin=_,o&&this._updateFeatureWithDomainValues(t),i&&c&&i.length===c.length)for(let e=0;e<i.length;e++){let n=`${R.servicePixelValue}.${i[e]}`;t.attributes[n]=c[e]}p.push(l[e])}return p}_processMultidimensionalIntersection(e,t,n){let{multidimensionalSubset:r}=this;if(!r)return n=this._combineMosaicRuleWithTimeExtent(n,t),{isOutSide:!1,timeExtent:t,mosaicRule:n};if(r){let{isOutside:n,intersection:i}=v(r,{geometry:e,timeExtent:t});if(n)return{isOutSide:!0,timeExtent:null,mosaicRule:null};i?.timeExtent!=null&&(t=i.timeExtent)}if(n=this._combineMosaicRuleWithTimeExtent(n,t),n?.multidimensionalDefinition){let{isOutside:e}=v(r,{multidimensionalDefinition:n.multidimensionalDefinition});if(e)return{isOutSide:!0,timeExtent:null,mosaicRule:null}}return{isOutSide:!1,timeExtent:t,mosaicRule:n}}_updateFeatureWithRasterAttributeTableValues(e,t){let n=this.rasterInfo.attributeTable||this.serviceRasterInfo.attributeTable;if(n==null)return;let{features:r,fields:i}=n,a=i.map(e=>e.name).find(e=>e.toLowerCase()===`value`);if(!a)return;let o=r.filter(e=>e.attributes[a]===(t==null?null:parseInt(t,10)));o&&o[0]&&i.forEach(t=>{let n=de+t.name;e.attributes[n]=o[0].attributes[t.name]})}_updateFeatureWithMagDirValues(e,t){if(!this._isVectorDataSet())return;let n=t.split(/,\s*/).map(e=>parseFloat(e)),r=n.map(e=>[e]),i=n.map(e=>({minValue:e,maxValue:e,noDataValue:null})),a=new P({height:1,width:1,pixelType:`f32`,pixels:r,statistics:i});this.pixelFilter!=null&&this.pixelFilter({pixelBlock:a,extent:new m(0,0,0,0,this.spatialReference)});let o=this.serviceDataType===`esriImageServiceDataTypeVector-MagDir`?[a.pixels[0][0],a.pixels[1][0]]:T([a.pixels[0][0],a.pixels[1][0]]);e.attributes[R.magnitude]=o[0],e.attributes[R.direction]=o[1]}_updateFeatureWithDomainValues(e){(this.fields&&this.fields.filter(e=>e.domain?.type===`coded-value`))?.forEach(t=>{let n=e.attributes[t.name];if(n!=null){let r=t.domain.codedValues.find(e=>e.code===n);r&&(e.attributes[t.name]=r.name)}})}_updateResponseFieldNames(e,t){if(!t||t.length<1)return;let n=this.fieldsIndex;n!=null&&e.forEach(e=>{if(e?.attributes)for(let r of t){let t=n.get(r)?.name;t&&t!==r&&(e.attributes[r]=e.attributes[t],delete e.attributes[t])}})}_getRenderingRuleString(e){if(e){let t=e.toJSON();return t=t.rasterFunctionDefinition??t,(t.thumbnail||t.thumbnailEx)&&(t.thumbnail=t.thumbnailEx=null),JSON.stringify(t)}return null}_hasRasterFunction(e){return e?.functionName!=null&&e.functionName.toLowerCase()!==`none`}_updateRenderingRulesFunctionName(e,t){if(!e||e.length<1)return;if(e===`Raw`)return e.replace(`Raw`,`None`);let n=e.toLowerCase().replaceAll(/ /gi,`_`);return t.has(n)?t.get(n):e}_isRFTJson(e){return e?.name&&e.arguments&&e.function&&e.hasOwnProperty(`functionType`)}_isVectorDataSet(){return this.serviceDataType===`esriImageServiceDataTypeVector-UV`||this.serviceDataType===`esriImageServiceDataTypeVector-MagDir`}_applyMosaicAndRenderingRules(e){let{raster:t,mosaicRule:n,rasterFunction:r}=this;r&&e.rasterFunction==null&&(e.rasterFunction=r),n&&e.mosaicRule==null&&(e.mosaicRule=n),t&&e.raster==null&&(e.raster=t)}async _updateCurrentRasterInfo(e){if(this.renderer||this.symbolizer){let t=await this._generateRasterInfo(this.rasterFunction,{signal:e});t&&(this.rasterInfo=t)}}_applyMosaicRule(e){let{raster:t,mosaicRule:n}=this;n&&e.mosaicRule==null&&(e.mosaicRule=n),t&&e.raster==null&&(e.raster=t)}_readCapabilities(e){let t=e.capabilities?e.capabilities.toLowerCase().split(`,`).map(e=>e.trim()):[`image`,`catalog`],{currentVersion:n,maxRecordCount:r}=e,i=t.includes(`image`),a=e.serviceDataType===`esriImageServiceDataTypeElevation`,o=!!(e.spatialReference||e.extent?.spatialReference),s=t.includes(`edit`),c=t.includes(`mensuration`)&&o,l=e.mensurationCapabilities==null?[]:e.mensurationCapabilities.toLowerCase().split(`,`).map(e=>e.trim()),u=c&&l.includes(`basic`),d=this._isMosaicDataset(e)&&t.includes(`catalog`),f=t.includes(`download`),p=n>=10.7&&a||n>=11.4&&(a||c&&l.includes(`3d`)),m=d&&e.fields&&e.fields.length>0,h=m&&e.supportsAdvancedQueries?e.advancedQueryCapabilities:void 0;return{data:{supportsAttachment:!1},operations:{supportsComputeHistograms:i,supportsExportImage:i,supportsIdentify:i,supportsImageToMap:n>=11.2&&d,supportsImageToMapMultiray:n>=11.2&&d,supportsMapToImage:n>=11.2&&d,supportsFindImages:n>=11.2&&d,supportsGetImageUrl:n>=11.3&&f,supportsMeasure:c,supportsMeasureFromImage:n>=11.2,supportsDownload:f,supportsQuery:m,supportsGetSamples:n>=10.2&&i,supportsProject:n>=10.3&&i,supportsComputeStatisticsHistograms:n>=10.4&&i,supportsQueryBoundary:n>=10.6&&i,supportsCalculateVolume:p,supportsComputePixelLocation:n>=10.7&&d,supportsComputeAngles:n>=10.91,supportsQueryGPSInfo:n>=11.2&&d,supportsAdd:s,supportsDelete:s,supportsEditing:s,supportsUpdate:s,supportsCalculate:!1,supportsTruncate:!1,supportsValidateSql:!1,supportsChangeTracking:!1,supportsQueryAttachments:!1,supportsResizeAttachments:!1,supportsSync:!1,supportsExceedsLimitStatistics:!1,supportsQueryAnalytics:!1,supportsQueryBins:!1,supportsQueryPivot:!1,supportsQueryTopFeatures:!1,supportsAsyncConvert3D:!1},query:{maxRecordCount:r,maxRecordCountFactor:void 0,maxUniqueIDCount:void 0,relativeTimeBinWindow:void 0,supportsStatisticsAggregatedIds:!!h?.supportsAggregateIds,supportsStatistics:!!h?.supportsStatistics,supportsOrderBy:!!h?.supportsOrderBy,supportsDistinct:!!h?.supportsDistinct,supportsPagination:!!h?.supportsPagination,supportsPaginationOnAggregatedQueries:!!h?.supportsPaginationOnAggregatedQueries,supportsStandardizedQueriesOnly:!!h?.useStandardizedQueries,supportsPercentileStatistics:!!h?.supportsPercentileStatistics,supportsCentroid:!!h?.supportsReturningGeometryCentroid,supportsCentroidOnDegeneratedQuantizedGeometry:!1,supportsCurrentUser:!1,supportsDegeneratedQuantizedGeometry:!1,supportsDistance:!!h?.supportsQueryWithDistance,supportsOutDistance:!!h?.supportsOutDistance,supportsExtent:!!h?.supportsReturningQueryExtent,supportsGeometryProperties:!!h?.supportsReturningGeometryProperties,supportsHavingClause:!!h?.supportsHavingClause,supportsQuantization:!1,supportsQuantizationEditMode:!1,supportsQueryGeometry:!1,supportsResultType:!1,supportsReturnMesh:!1,supportsReturnExceededLimitGeometries:!1,supportsMaxRecordCountFactor:!1,supportsSqlExpression:h?.supportsSqlExpression??!!h,supportsTopFeaturesQuery:!1,supportsQueryByAnonymous:!1,supportsQueryByOthers:!1,supportsHistoricMoment:!1,supportsFormatPBF:!1,supportsFormatPBFWithCurves:!1,supportsDisjointSpatialRelationship:!1,supportsCacheHint:!1,supportsSpatialAggregationStatistics:!1,supportedSpatialAggregationStatistics:{envelope:!1,centroid:!1,convexHull:!1},supportsDefaultSpatialReference:!!h?.supportsDefaultSR,supportsFullTextSearch:!1,supportsCompactGeometry:!1,standardMaxRecordCount:void 0,standardMaxRecordCountNoGeometry:void 0,tileMaxRecordCount:void 0,supportsTrueCurve:!1},mensuration:{supportsDistanceAndAngle:u,supportsAreaAndPerimeter:u,supportsPointOrCentroid:u,supportsHeightFromBaseAndTop:c&&l.includes(`base-top height`),supportsHeightFromBaseAndTopShadow:c&&l.includes(`base-top shadow height`),supportsHeightFromTopAndTopShadow:c&&l.includes(`top-top shadow height`),supports3D:c&&l.includes(`3d`)}}}};e([l({clonable:!1})],Q.prototype,`_functionRasterInfos`,void 0),e([l({readOnly:!0})],Q.prototype,`_serviceSupportsMosaicRule`,void 0),e([Y(`_serviceSupportsMosaicRule`,[`currentVersion`,`fields`])],Q.prototype,`readServiceSupportsMosaicRule`,null),e([l({readOnly:!0})],Q.prototype,`_rasterFunctionNamesIndex`,null),e([l()],Q.prototype,`_projectedFullExtent`,void 0),e([l({clonable:!1})],Q.prototype,`_exportTileQueue`,void 0),e([l()],Q.prototype,`adjustAspectRatio`,void 0),e([l({type:[d],json:{write:!0}})],Q.prototype,`bandIds`,void 0),e([Y(`bandIds`)],Q.prototype,`readBandIds`,null),e([l({readOnly:!0,json:{read:!1}})],Q.prototype,`capabilities`,void 0),e([Y(`service`,`capabilities`,[`capabilities`,`currentVersion`,`serviceDataType`])],Q.prototype,`readCapabilities`,null),e([l({type:Number})],Q.prototype,`compressionQuality`,void 0),e([X(`compressionQuality`)],Q.prototype,`writeCompressionQuality`,null),e([l({type:Number})],Q.prototype,`compressionTolerance`,void 0),e([X(`compressionTolerance`)],Q.prototype,`writeCompressionTolerance`,null),e([l({json:{read:{source:`copyrightText`}}})],Q.prototype,`copyright`,void 0),e([l({readOnly:!0})],Q.prototype,`defaultMosaicRule`,void 0),e([Y(`defaultMosaicRule`,[`defaultMosaicMethod`])],Q.prototype,`readDefaultMosaicRule`,null),e([l({type:String,json:{name:`layerDefinition.definitionExpression`,write:{enabled:!0,allowNull:!0}}})],Q.prototype,`definitionExpression`,void 0),e([l({readOnly:!0,constructOnly:!0})],Q.prototype,`exportImageServiceParameters`,void 0),e([l()],Q.prototype,`rasterInfo`,void 0),e([l({readOnly:!0,type:[A]})],Q.prototype,`fields`,void 0),e([l({readOnly:!0})],Q.prototype,`fieldsIndex`,null),e([l({type:[`png`,`png8`,`png24`,`png32`,`jpg`,`bmp`,`gif`,`jpgpng`,`lerc`,`tiff`,`bip`,`bsq`],json:{write:!0}})],Q.prototype,`format`,null),e([Y(`service`,`format`,[`serviceDataType`,`allowRasterFunction`])],Q.prototype,`readFormat`,null),e([l({type:m})],Q.prototype,`fullExtent`,void 0),e([l({readOnly:!0})],Q.prototype,`hasMultidimensions`,void 0),e([l({json:{read:{source:`maxImageHeight`}}})],Q.prototype,`imageMaxHeight`,void 0),e([l({json:{read:{source:`maxImageWidth`}}})],Q.prototype,`imageMaxWidth`,void 0),e([l({type:String,json:{type:F.jsonValues,read:F.read,write:F.write}})],Q.prototype,`interpolation`,void 0),e([l()],Q.prototype,`minScale`,void 0),e([Y(`service`,`minScale`)],Q.prototype,`readMinScale`,null),e([l()],Q.prototype,`maxScale`,void 0),e([Y(`service`,`maxScale`)],Q.prototype,`readMaxScale`,null),e([l({type:N})],Q.prototype,`mosaicRule`,null),e([Y(`mosaicRule`,[`mosaicRule`,`defaultMosaicMethod`])],Q.prototype,`readMosaicRule`,null),e([X(`mosaicRule`)],Q.prototype,`writeMosaicRule`,null),e([l()],Q.prototype,`multidimensionalInfo`,void 0),e([l({type:te,json:{write:!0}})],Q.prototype,`multidimensionalSubset`,void 0),e([l({json:{type:[Number,[Number]],write:!0}})],Q.prototype,`noData`,void 0),e([l({type:String,json:{type:I.jsonValues,read:I.read,write:I.write}})],Q.prototype,`noDataInterpretation`,void 0),e([l({type:String,readOnly:!0,json:{read:{source:[`fields`]}}})],Q.prototype,`objectIdField`,void 0),e([Y(`objectIdField`)],Q.prototype,`readObjectIdField`,null),e([l({readOnly:!0})],Q.prototype,`geometryType`,void 0),e([l({})],Q.prototype,`typeIdField`,void 0),e([l({})],Q.prototype,`types`,void 0),e([l({readOnly:!0})],Q.prototype,`parsedUrl`,null),e([l({type:Function})],Q.prototype,`pixelFilter`,void 0),e([l()],Q.prototype,`raster`,void 0),e([l({readOnly:!0})],Q.prototype,`sourceType`,void 0),e([Y(`sourceType`,[`serviceSourceType`,`fields`])],Q.prototype,`readSourceType`,null),e([l()],Q.prototype,`viewId`,void 0),e([l({types:G})],Q.prototype,`renderer`,null),e([l({types:G,json:{name:`layerDefinition.drawingInfo.renderer`,origins:{"web-scene":{types:he,name:`layerDefinition.drawingInfo.renderer`,write:{overridePolicy(e){return{enabled:e&&e.type!==`vector-field`}}}}}}})],Q.prototype,`internalRenderer`,null),e([Y(`internalRenderer`)],Q.prototype,`readRenderer`,null),e([X(`internalRenderer`)],Q.prototype,`writeRenderer`,null),e([l({clonable:!1})],Q.prototype,`symbolizer`,void 0),e([l(E)],Q.prototype,`opacity`,void 0),e([l({readOnly:!0})],Q.prototype,`rasterFields`,null),e([l({constructOnly:!0})],Q.prototype,`rasterFunctionInfos`,void 0),e([l({type:z,json:{name:`renderingRule`}})],Q.prototype,`rasterFunction`,null),e([Y(`rasterFunction`,[`renderingRule`,`rasterFunctionInfos`])],Q.prototype,`readRasterFunction`,null),e([l({readOnly:!0})],Q.prototype,`serviceDataType`,void 0),e([l({readOnly:!0,type:g})],Q.prototype,`spatialReference`,void 0),e([Y(`spatialReference`,[`spatialReference`,`extent`])],Q.prototype,`readSpatialReference`,null),e([l({type:L.apiValues,json:{read:L.read,type:L.jsonValues}})],Q.prototype,`pixelType`,void 0),e([X(`pixelType`)],Q.prototype,`writePixelType`,null),e([l({constructOnly:!0,type:fe})],Q.prototype,`serviceRasterInfo`,void 0),e([l()],Q.prototype,`sourceJSON`,void 0),e([l(D)],Q.prototype,`url`,void 0),e([l({readOnly:!0})],Q.prototype,`version`,void 0),e([Y(`version`,[`currentVersion`,`fields`,`timeInfo`])],Q.prototype,`readVersion`,null),Q=e([u(`esri.layers.mixins.ArcGISImageService`)],Q);function $(e){return e?.path??``}return Q};export{Z as ArcGISImageService};
2
+ import{__decorate as e}from"tslib";import t from"../../Graphic.js";import n from"../../request.js";import r from"../../core/Error.js";import{clone as i}from"../../core/lang.js";import a from"../../core/Logger.js";import{QueueProcessor as o}from"../../core/QueueProcessor.js";import{watch as s}from"../../core/reactiveUtils.js";import{urlToObject as c}from"../../core/urlUtils.js";import{property as l,subclass as u}from"../../core/accessorSupport/decorators.js";import{Integer as d,ensureClass as f}from"../../core/accessorSupport/ensureType.js";import{runUntracked as p}from"../../core/accessorSupport/tracking.js";import m from"../../geometry/Extent.js";import h from"../../geometry/Point.js";import g from"../../geometry/Polygon.js";import _ from"../../geometry/SpatialReference.js";import{srToRESTValue as v}from"../../geometry/support/spatialReferenceUtils.js";import{intersectMultimensionalSubset as y,getEffectiveMultidimensionalDefinition as b,getSubsetVariablesFromMdInfo as x,getDefaultMultidimensionalDefinition as S}from"../raster/datasets/multidimensionalUtils.js";import{decode as C,getFormat as w}from"../raster/formats/RasterCodec.js";import{convertPixelSize as T}from"../raster/functions/clipUtils.js";import{mosaicPixelData as E}from"../raster/functions/pixelUtils.js";import{uvComponentToVector as D}from"../raster/functions/vectorFieldUtils.js";import{opacity as O,url as k}from"../support/commonProperties.js";import A from"../support/DimensionalDefinition.js";import{ExportImageServiceParameters as j}from"../support/ExportImageServiceParameters.js";import ee from"../support/Field.js";import te from"../support/FieldsIndex.js";import{createBitmap as M}from"../support/imageBitmapUtils.js";import{isSupportedRendererType as ne}from"../support/imageryRendererUtils.js";import N from"../support/MosaicRule.js";import re from"../support/MultidimensionalSubset.js";import P from"../support/PixelBlock.js";import{interpolationKebab as F,noDataInterpretationKebab as I,pixelTypeKebabDict as L}from"../support/rasterEnums.js";import{getServicePixelValueField as ie,getItemPixelValueField as ae,getRawServicePixelValueField as oe,getProcessedServicePixelValueField as se,getMagnitudeField as ce,getDirectionField as le,getMultidimensionalFields as ue,getRasterAttributeTableFields as de,addMultidimensionalFieldValues as fe,commonRasterFieldNames as R,rasterFieldPrefix as pe}from"../support/rasterFieldUtils.js";import z from"../support/RasterFunction.js";import me from"../support/RasterInfo.js";import{createDefaultRenderer as B,getDefaultBandCombination as V,getSupportedRendererTypes as H,getField as U,matchPresetRenderer as he,normalizeRendererJSON as ge}from"../../renderers/support/rasterRendererHelper.js";import W from"../../renderers/support/RasterSymbolizer.js";import{rasterRendererTypes as G,websceneRasterRendererTypes as _e,read as ve}from"../../renderers/support/rasterTypeUtils.js";import{calculateVolume as ye,computeAngles as be,computePixelSpaceLocations as xe,computeHistograms as Se,computeStatisticsHistograms as Ce,measureHeight as we,measureAreaAndPerimeter as Te,measureDistanceAndAngle as Ee,measurePointOrCentroid as De,measureLengthFromImage as Oe,measureAreaFromImage as ke,getImageSpatialReferenceQueryParameter as Ae,getSamples as je,identify as K,imageToMap as Me,imageToMapMultiray as Ne,mapToImage as Pe,findImages as Fe,getImageUrl as Ie,queryBoundary as Le,queryGPSInfo as Re}from"../../rest/imageService.js";import{fetchServiceRasterInfo as q,generateRasterInfo as ze,patchServiceInfo as Be}from"../../rest/imageService/fetchRasterInfo.js";import{getCatalogItemRasterInfo as Ve}from"../../rest/imageService/getCatalogItemRasterInfo.js";import{executeForCount as J}from"../../rest/query/executeForCount.js";import{executeForExtent as He}from"../../rest/query/executeForExtent.js";import{executeForIds as Ue}from"../../rest/query/executeForIds.js";import{executeQueryJSON as We}from"../../rest/query/executeQueryJSON.js";import Ge from"../../rest/support/FeatureSet.js";import Ke from"../../rest/support/ImageIdentifyParameters.js";import Y from"../../rest/support/Query.js";import qe from"../../rest/support/StatisticDefinition.js";import{reader as X}from"../../core/accessorSupport/decorators/reader.js";import{writer as Z}from"../../core/accessorSupport/decorators/writer.js";const Je=4096,Ye=new Set([`png`,`png8`,`png24`,`png32`,`jpg`,`bmp`,`gif`,`jpgpng`,`lerc`,`tiff`]);function Xe(e){let t=JSON.stringify(e),n=t.includes(`"rasterFunctionDefinition":{`),r=(n?t.match(/"type":"(.*?FunctionArguments")/gi):t.match(/"rasterFunction":"(.*?")/gi))?.map(e=>n?e.slice(8,-18):e.slice(18,-1));return r?r.join(`/`):null}const Ze=Ze=>{let Qe=Ze,Q=class extends Qe{constructor(){super(...arguments),this._functionRasterInfos={},this._serviceSupportsMosaicRule=null,this._exportTileQueue=new o({concurrency:4,process:(e,t)=>this._fetchPixels(e.extent,e.width,e.height,{...e.options,signal:t})}),this.adjustAspectRatio=null,this.bandIds=void 0,this.capabilities=null,this.compressionQuality=void 0,this.compressionTolerance=.01,this.copyright=null,this.defaultMosaicRule=null,this.definitionExpression=null,this.exportImageServiceParameters=null,this.rasterInfo=null,this.fields=null,this.fullExtent=null,this.hasMultidimensions=!1,this.imageMaxHeight=4100,this.imageMaxWidth=4100,this.interpolation=void 0,this.minScale=0,this.maxScale=0,this.multidimensionalInfo=null,this.multidimensionalSubset=null,this.noData=null,this.noDataInterpretation=void 0,this.objectIdField=null,this.geometryType=`polygon`,this.typeIdField=null,this.types=[],this.pixelFilter=null,this.raster=void 0,this.sourceType=null,this.viewId=void 0,this.symbolizer=null,this.rasterFunctionInfos=null,this.serviceDataType=null,this.spatialReference=null,this.pixelType=null,this.serviceRasterInfo=null,this.sourceJSON=null,this.url=null,this.version=void 0}initialize(){this._set(`exportImageServiceParameters`,new j({layer:this}))}readServiceSupportsMosaicRule(e,t){return this._isMosaicRuleSupported(t)}get _rasterFunctionNamesIndex(){let e=new Map;return!this.rasterFunctionInfos||this.rasterFunctionInfos!=null&&this.rasterFunctionInfos.length<1||this.rasterFunctionInfos!=null&&this.rasterFunctionInfos.forEach(t=>{e.set(t.name.toLowerCase().replaceAll(/ /gi,`_`),t.name)}),e}readBandIds(e,t){if(Array.isArray(e)&&e.length>0&&e.every(e=>typeof e==`number`))return e}readCapabilities(e,t){return this._readCapabilities(t)}writeCompressionQuality(e,t,n){e!=null&&this.format!==`lerc`&&(t[n]=e)}writeCompressionTolerance(e,t,n){this.format===`lerc`&&e!=null&&(t[n]=e)}readDefaultMosaicRule(e,t){return this._serviceSupportsMosaicRule?p(()=>N.fromJSON(t)):null}get fieldsIndex(){return this.fields?new te(this.fields):null}set format(e){e&&Ye.has(e.toLowerCase())&&this._set(`format`,e.toLowerCase())}readFormat(e,t){return t.serviceDataType===`esriImageServiceDataTypeVector-UV`||t.serviceDataType===`esriImageServiceDataTypeVector-MagDir`||this.pixelFilter!=null||t.allowRasterFunction===!1?`lerc`:`jpgpng`}get isRenderedFormat(){return!this.format||this.format.includes(`jpg`)||this.format.includes(`png`)}readMinScale(e,t){return t.minLOD!=null&&t.maxLOD!=null?e:0}readMaxScale(e,t){return t.minLOD!=null&&t.maxLOD!=null?e:0}set mosaicRule(e){let t=e;t?.mosaicMethod&&(t=N.fromJSON({...t.toJSON(),mosaicMethod:t.mosaicMethod,mosaicOperation:t.mosaicOperation})),this._set(`mosaicRule`,t)}readMosaicRule(e,t){let n=e||t.mosaicRule;return n?N.fromJSON(n):this._isMosaicRuleSupported(t)?N.fromJSON(t):null}writeMosaicRule(e,t,n){let{mosaicRule:r}=this;this._isValidCustomizedMosaicRule(r)&&(t[n]=r.toJSON())}readObjectIdField(e,t){return e||=t.fields.find(e=>e.type===`esriFieldTypeOID`||e.type===`oid`)?.name,e}get parsedUrl(){return c(this.url)}readSourceType(e,t){return this._isMosaicDataset(t)?`mosaic-dataset`:`raster-dataset`}get renderer(){let{activePresetRendererName:e,presetRenderers:t}=this;return e?(t?.find(({name:t})=>t===e))?.renderer.clone():this.internalRenderer}set renderer(e){this.activePresetRendererName=null,this.internalRenderer=e}set internalRenderer(e){this.loaded&&(e=this._configRenderer(e)),this._set(`internalRenderer`,e)}readRenderer(e,t,n){let r=t?.layerDefinition?.drawingInfo?.renderer,i=ve(r,n);return i==null?null:(i.type===`vector-field`&&t.symbolTileSize&&!r.symbolTileSize&&(i.symbolTileSize=t.symbolTileSize),ne(i)||a.getLogger(this).warn(`ArcGISImageService`,`Imagery layer doesn't support given renderer type.`),i)}writeRenderer(e,t,n){t.layerDefinition=t.layerDefinition||{},t.layerDefinition.drawingInfo=t.layerDefinition.drawingInfo||{},t.layerDefinition.drawingInfo.renderer=e.toJSON()}get rasterFields(){let e=this.fields?.map(e=>e.clone())??[];e.push(ie()),this.sourceType===`mosaic-dataset`&&this.fields?.length&&e.push(ae()),this.version>=10.4&&this.rasterFunctionInfos!=null&&this.rasterFunctionInfos.some(({name:e})=>e.toLowerCase()===`none`)&&e.push(oe()),this.rasterFunctionInfos!=null&&this.rasterFunctionInfos.filter(({name:e})=>e.toLowerCase()!==`none`).forEach(({name:t})=>e.push(se(t)));let{rasterInfo:t}=this;if(this._isVectorDataSet()){let n=t?.multidimensionalInfo?.variables[0].unit?.trim(),r=ce(n),i=le();e.push(r,i)}if(t?.multidimensionalInfo&&this.sourceType===`raster-dataset`){let n=ue(t.multidimensionalInfo);e.push(...n)}let n=t?.attributeTable;if(n!=null){let t=de(n);e.push(...t)}return e}set rasterFunction(e){let t=e;t?.rasterFunction&&(t=z.fromJSON({...t.toJSON(),rasterFunction:t.rasterFunction,rasterFunctionArguments:t.rasterFunctionArguments})),this._set(`rasterFunction`,t)}readRasterFunction(e,t){let n=t.rasterFunctionInfos,r=t.renderingRule,i=r!=null&&Object.keys(r).length>0;return!i&&(!n?.length||n[0].name===`None`)?null:this._isRFTJson(r)?z.fromJSON({rasterFunctionDefinition:r}):z.fromJSON(i?r:{rasterFunctionInfos:n})}readSpatialReference(e,t){let n=e||t.extent.spatialReference;return n?_.fromJSON(n):null}writePixelType(e,t,n){(this.serviceRasterInfo==null||this.pixelType!==this.serviceRasterInfo.pixelType)&&(t[n]=L.toJSON(e))}readVersion(e,t){let n=t.currentVersion;return n||=t.hasOwnProperty(`fields`)||t.hasOwnProperty(`timeInfo`)?10:9.3,n}applyFilter(e){let t=e;return this.pixelFilter&&(t=this._clonePixelData(e),this.pixelFilter(t)),t}async applyRenderer(e,t){let n=e,{renderer:r,symbolizer:i,pixelFilter:a}=this,{isRawData:o}=e;if(o&&this.format!==`lerc`&&(r??=B(this.rasterInfo,{bandIds:this.bandIds,variableName:this.rasterFunction?null:this.mosaicRule?.multidimensionalDefinition?.[0].variableName}),i||=(this.symbolizer=new W({rendererJSON:r.toJSON(),rasterInfo:this.rasterInfo}),this.symbolizer)),(o||!this.isRenderedFormat)&&r&&i&&!a){await this._updateSymbolizer(i,r);let a=this.bandIds?.length?this.bandIds:V(this.rasterInfo);n=await this._symbolize({pixelData:e,bandIds:a,symbolizer:i},t)}return n}destroy(){this._shutdownJobHandler()}async calculateVolume(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsCalculateVolume)throw new r(`imagery-layer:compute-pixel-space-locations`,`this operation is not supported on the input image service`);return e=i(e),this.mosaicRule&&e.mosaicRule==null&&(e.mosaicRule=this.mosaicRule),ye(this.url,e,this._getRequestOptions(t))}async computeAngles(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsComputeAngles)throw new r(`imagery-layer:compute-angles`,`this operation is not supported on the input image service`);return be(this.url,e,this._getRequestOptions(t))}async computePixelSpaceLocations(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsComputePixelLocation)throw new r(`imagery-layer:compute-pixel-space-locations`,`this operation is not supported on the input image service`);return xe(this.url,e,this._getRequestOptions(t))}async computeHistograms(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsComputeHistograms)throw new r(`imagery-layer:compute-histograms`,`this operation is not supported on the input image service`);return e=i(e),this._applyMosaicAndRenderingRules(e),Se(this.url,e,this._getRequestOptions(t))}async computeStatisticsHistograms(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsComputeStatisticsHistograms)throw new r(`imagery-layer:compute-statistics-histograms`,`this operation is not supported on the input image service`);return e=i(e),this._applyMosaicAndRenderingRules(e),Ce(this.url,e,this._getRequestOptions(t))}async measureHeight(e,t){let n=await this._fetchCapabilities(t?.signal);if(!(e.operationType===`base-and-top`?n.mensuration.supportsHeightFromBaseAndTop:e.operationType===`base-and-top-shadow`?n.mensuration.supportsHeightFromBaseAndTopShadow:n.mensuration.supportsHeightFromTopAndTopShadow))throw new r(`imagery-layer:measure-height`,`this operation is not supported on the input image service`);return e=i(e),this._applyMosaicRule(e),we(this.url,e,this._getRequestOptions(t))}async measureAreaAndPerimeter(e,t){let n=await this._fetchCapabilities(t?.signal);if(!n.mensuration.supportsAreaAndPerimeter||e.is3D&&!n.mensuration.supports3D)throw new r(`imagery-layer:measure-area-and-perimeter`,`this operation is not supported on the input image service`);return e=i(e),this._applyMosaicRule(e),Te(this.url,e,this._getRequestOptions(t))}async measureDistanceAndAngle(e,t){let n=await this._fetchCapabilities(t?.signal);if(!n.mensuration.supportsDistanceAndAngle||e.is3D&&!n.mensuration.supports3D)throw new r(`imagery-layer:measure-distance-and-angle`,`this operation is not supported on the input image service`);return e=i(e),this._applyMosaicRule(e),Ee(this.url,e,this._getRequestOptions(t))}async measurePointOrCentroid(e,t){let n=await this._fetchCapabilities(t?.signal);if(!n.mensuration.supportsPointOrCentroid||e.is3D&&!n.mensuration.supports3D)throw new r(`imagery-layer:measure-point-or-centroid`,`this operation is not supported on the input image service`);return e=i(e),this._applyMosaicRule(e),De(this.url,e,this._getRequestOptions(t))}async measureLengthFromImage(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsMeasureFromImage)throw new r(`imagery-layer:measure-length-from-image`,`this operation is not supported on the input image service`);if(e.geometry.type!==`polyline`)throw new r(`imagery-layer:measure-length-from-image`,`this input geometry must be a polyline`);return Oe(this.url,e,this._getRequestOptions(t))}async measureAreaFromImage(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsMeasureFromImage)throw new r(`imagery-layer:measure-area-from-image`,`this operation is not supported on the input image service`);if(e.geometry.type!==`polygon`)throw new r(`imagery-layer:measure-area-from-image`,`this input geometry must be a polygon`);return ke(this.url,e,this._getRequestOptions(t))}getField(e){let{fieldsIndex:t}=this;return t?.get(e)}getFieldDomain(e,t){let n=this.getField(e);return n?n.domain:null}async internalFetchImage(e,t,n,r={}){await this._updateCurrentRasterInfo();let{exportImageServiceParameters:i}=this,a=!1;if(r.requestRawData&&(await this._initJobHandler(),!i.requestRawData&&this.format!==`lerc`)){a=!0,i.requestRawData=!0;let e=this.bandIds;if(!e?.length){let t=V(this.rasterInfo);Array.from({length:this.rasterInfo.bandCount},(e,t)=>t)?.join(`,`)!==t?.join(`,`)&&(e=t)}i.rawDataRequestBandIds=e}let o=this.getExportImageServiceParameters(e,t,n,r.timeExtent);if(a&&(i.requestRawData=!1,i.rawDataRequestBandIds=null),o==null){if(r.requestAsImageElement&&this._canRequestImageElement(this.format)){let e=document.createElement(`canvas`);if(e.width=t,e.height=n,r.returnImageBitmap){let{bitmap:t}=await M(e,`${$(this.parsedUrl)}/exportImage`,r);return{imageBitmap:t}}return{imageOrCanvasElement:e}}let{bandIds:i,rasterInfo:a}=this,o=(i?.length||a.bandCount)??0,s=t*n,c=a.pixelType,l=[];for(let e=0;e<o;e++)l.push(P.createEmptyBand(c,s));return{pixelData:{pixelBlock:new P({width:t,height:n,pixels:l,mask:new Uint8Array(s),pixelType:c}),extent:e}}}let s=!!r.requestAsImageElement&&!this.pixelFilter,c=s&&!!r.returnImageBitmap,l={imageServiceParameters:o,imageProps:{extent:e,width:t,height:n,format:this.format},requestAsImageElement:s,returnImageBitmap:c,signal:r.signal};return this._requestArrayBuffer(l)}async fetchPixels(e,t,n,i={}){await this._initJobHandler(),i.applyRendering&&await this._updateCurrentRasterInfo();let{imageMaxWidth:a,imageMaxHeight:o}=this;if(t<=a&&n<=o)return this._exportTileQueue.push({extent:e,width:t,height:n,options:i},{signal:i.signal});if(t>Je||n>Je||a<512||o<512)throw new r(`imagery-layer:fetch-pixels`,`The image service has a maximum export size of ${a}x${o}. The requested size of ${t}x${n} exceeds this limit.`);let{xmin:s,ymax:c,spatialReference:l}=this._projectedFullExtent??this.fullExtent;if(!l?.equals(e.spatialReference)){let{projectLoad:t,projectExecute:n}=await import(`../../geometry/operators/projectOperator.js`);await t();let r=n(this.fullExtent,e.spatialReference);s=r.xmin,c=r.ymax,this._projectedFullExtent=r}let u=e.width/t,d=e.height/n,f=Math.floor((e.xmin-s)/u),p=Math.floor((c-e.ymax)/d),h=f+t,g=p+n,_=Math.floor(f/512),v=Math.floor(p/512),y=Math.ceil(h/512)-1,b=Math.ceil(g/512)-1,x=512*u,S=512*d,C=[];for(let t=v;t<=b;t++){let n=c-t*S,r=n-S;for(let t=_;t<=y;t++){let a=s+t*x,o=new m({xmin:a,ymin:r,xmax:a+x,ymax:n,spatialReference:e.spatialReference});C.push(this._exportTileQueue.push({extent:o,width:512,height:512,options:i},{signal:i.signal}))}}let w=await Promise.all(C);return w.some(e=>e.pixelBlock==null)?{extent:e,pixelBlock:null}:{extent:e,pixelBlock:this._rasterJobHandler?await this._rasterJobHandler.mosaicPixelData({pixelBlocks:w,destExtent:e},{signal:i.signal,transferPixelsToWorker:!0}):E(w,e)?.pixelBlock}}async _fetchPixels(e,t,n,r={}){let i=r.applyRendering?void 0:new j({layer:this,requestRawData:!0,interpolation:r.interpolation??`nearest`,bandIds:r.bandIds??[]}),a=this.getExportImageServiceParameters(e,t,n,r.timeExtent,i);if(a==null)return{extent:e,pixelBlock:null};delete a.pixelType,r.bandIds||delete a.bandIds,delete a.compressionQuality;let o={imageServiceParameters:a,imageProps:{extent:e,width:t,height:n,format:this.format},requestAsImageElement:!1,returnImageBitmap:!1,signal:r.signal},{pixelData:s}=await this._requestArrayBuffer(o);return s??{extent:e,pixelBlock:null}}fetchKeyProperties(e){return n($(this.parsedUrl)+`/keyProperties`,{query:this._getQueryParams({renderingRule:this.version>=10.3?e?.rasterFunction:null})}).then(e=>e.data)}fetchRasterAttributeTable(e){return this.version<10.1?Promise.reject(new r(`#fetchRasterAttributeTable()`,`Failed to get rasterAttributeTable`)):n($(this.parsedUrl)+`/rasterAttributeTable`,{query:this._getQueryParams({renderingRule:this.version>=10.3?e?.rasterFunction:null})}).then(e=>Ge.fromJSON(e.data))}getCatalogItemRasterInfo(e,t){let n=this._getQueryParams(),r={...t,query:n};return Ve($(this.parsedUrl),e,r)}async getCatalogItemICSInfo(e,t){let{data:r}=await n($(this.parsedUrl)+`/`+e+`/info/ics`,{query:this._getQueryParams(),...t}),i=r?.ics;if(!i)return;let a=null;try{a=(await n($(this.parsedUrl)+`/`+e+`/info`,{query:this._getQueryParams(),...t})).data.extent}catch{}if(!a?.spatialReference)return{ics:i,icsToPixelTransform:null,icsExtent:null,northDirection:null};let o=this.version>=10.7?n($(this.parsedUrl)+`/`+e+`/info/icstopixel`,{query:this._getQueryParams(),...t}).then(e=>e.data).catch(()=>({})):{},s=a.spatialReference,c={geometries:JSON.stringify({geometryType:`esriGeometryEnvelope`,geometries:[a]}),inSR:v(s),outSR:`0:`+e},l=n($(this.parsedUrl)+`/project`,{query:this._getQueryParams(c),...t}).then(e=>e.data).catch(()=>({})),u=(a.xmin+a.xmax)/2,d=(a.ymax-a.ymin)/6,f=a.ymin+d,p=[];for(let e=0;e<5;e++)p.push({x:u,y:f+d*e});let h={geometries:JSON.stringify({geometryType:`esriGeometryPoint`,geometries:p}),inSR:v(s),outSR:`0:`+e},g=n($(this.parsedUrl)+`/project`,{query:this._getQueryParams(h),...t}).then(e=>e.data).catch(()=>({})),y=await Promise.all([o,l,g]),b=y[0].ipxf;if(b==null){let e=i.geodataXform?.xf_0;e?.name?.toLowerCase()===`topup`&&e?.coefficients?.length===6&&(b={affine:{name:`ics [sensor: Frame] to pixel (column, row) transformation`,coefficients:e.coefficients,cellsizeRatio:0,type:`GeometricXform`}})}let x=m.fromJSON(y[1]?.geometries?.[0]);x&&(x.spatialReference=new _({wkid:0,imageCoordinateSystem:i}));let S=y[2].geometries?y[2].geometries.filter(e=>e?.x!=null&&e.y!=null&&e.x!==`NaN`&&e.y!==`NaN`):[],C=S.length;if(C<3)return{ics:i,icsToPixelTransform:b,icsExtent:x,northDirection:null};let w=0,T=0,E=0,D=0;for(let e=0;e<C;e++)w+=S[e].x,T+=S[e].y,E+=S[e].x*S[e].x,D+=S[e].x*S[e].y;let O=(C*D-w*T)/(C*E-w*w),k=0,A=S[4].x>S[0].x,j=S[4].y>S[0].y;return O===1/0?k=j?90:270:O===0?k=A?0:180:O>0?k=A?Math.atan(O)*180/Math.PI:Math.atan(O)*180/Math.PI+180:O<0&&(k=j?180+Math.atan(O)*180/Math.PI:360+Math.atan(O)*180/Math.PI),{ics:i,icsToPixelTransform:b,icsExtent:x,northDirection:k}}async generateRasterInfo(e,t){let n=f(z,e),i={...t,query:this._getQueryParams()};if(!n||n.functionName?.toLowerCase()===`none`||this._isVectorFieldResampleFunction(n))return this.serviceRasterInfo??q($(this.parsedUrl),this.sourceJSON,i);let a=Xe(n);if(!a)throw new r(`imagery-layer:generate-raster-info`,`the rendering rule is not supported`);if(this._functionRasterInfos[a])return this._functionRasterInfos[a];let o=ze($(this.parsedUrl),n,i);this._functionRasterInfos[a]=o;try{let t=await o,{rasterFunction:n}=this;return(n===e||JSON.stringify(n)===JSON.stringify(e))&&JSON.stringify(this.rasterInfo)!==JSON.stringify(t)&&(this.rasterInfo=t),t}catch(e){throw this._functionRasterInfos[a]=null,e}}getExportImageServiceParameters(e,t,n,r,i){e=e.clone().shiftCentralMeridian();let a=Ae(e.spatialReference,$(this.parsedUrl));i??=this.exportImageServiceParameters;let o=i.toJSON(),{bandIds:s,noData:c}=o,{renderingRule:l}=o,u=this.rasterFunction?.rasterFunctionDefinition,d=this.renderer?.type,f=!d||d===`raster-stretch`||d===`raster-colormap`||d===`unique-value`||d===`class-breaks`||d===`raster-shaded-relief`;if(s?.length&&this._hasRasterFunction(this.rasterFunction)&&!u&&f){let e={rasterFunction:`ExtractBand`,rasterFunctionArguments:{BandIds:s}};if(l.rasterFunction===`Stretch`)e.rasterFunctionArguments.Raster=l.rasterFunctionArguments.Raster,l.rasterFunctionArguments.Raster=e;else if(l.rasterFunction===`Colormap`){let t=l.rasterFunctionArguments.Raster;t?.rasterFunction===`Stretch`?(e.rasterFunctionArguments.Raster=t.rasterFunctionArguments.Raster,t.rasterFunctionArguments.Raster=e):(e.rasterFunctionArguments.Raster=t,l.rasterFunctionArguments.Raster=e)}else e.rasterFunctionArguments.Raster=l,l=e;o.bandIds=void 0}else o.bandIds=s?.join(`,`);Array.isArray(c)&&c.length>0&&(o.noData=c.join(`,`));let p=this._processMultidimensionalIntersection(null,r,i.mosaicRule);if(p.isOutSide)return null;o.mosaicRule=p.mosaicRule==null?null:JSON.stringify(p.mosaicRule),r=p.timeExtent,o.renderingRule=this._getRenderingRuleString(z.fromJSON(l));let m={};if(r!=null){let{start:e,end:t}=r.toJSON();e&&t&&e===t?m.time=``+e:(e!=null||t!=null)&&(m.time=`${e??`null`},${t??`null`}`)}return{bbox:e.xmin+`,`+e.ymin+`,`+e.xmax+`,`+e.ymax,bboxSR:a,imageSR:a,size:t+`,`+n,...o,...m}}async getSamples(e,t){if(!(await this._fetchCapabilities(t?.signal))?.operations.supportsGetSamples)throw new r(`imagery-layer:get-samples`,`getSamples operation is not supported on the input image service`);e=i(e);let{raster:n}=this;return n&&e.raster==null&&(e.raster=n),je(this.url,e,this._getRequestOptions(t))}async identify(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsIdentify)throw new r(`imagery-layer:identify`,`identify operation is not supported on the input image service`);e=i(e),this.version<10.91&&e.geometry?.type===`extent`&&(e.geometry=g.fromExtent(e.geometry));let n=this._processMultidimensionalIntersection(e.geometry,e.timeExtent,e.mosaicRule||this.mosaicRule);if(n.isOutSide)throw new r(`imagery-layer:identify`,`the request cannot be fulfilled when falling outside of the multidimensional subset`);e.timeExtent=n.timeExtent,e.mosaicRule=n.mosaicRule;let{raster:a,rasterFunction:o}=this;return o&&e.rasterFunction==null&&(e.rasterFunction=o),a&&e.raster==null&&(e.raster=a),K(this.url,e,this._getRequestOptions(t))}async imageToMap(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsImageToMap)throw new r(`imagery-layer:image-to-map`,`imageToMap operation is not supported on the input image service`);return Me($(this.parsedUrl),e,this._getRequestOptions(t))}async imageToMapMultiray(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsImageToMapMultiray)throw new r(`imagery-layer:image-to-map-multiray`,`imageToMapMultiray operation is not supported on the input image service`);return Ne($(this.parsedUrl),e,this._getRequestOptions(t))}async mapToImage(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsMapToImage)throw new r(`imagery-layer:map-to-image`,`mapToImage operation is not supported on the input image service`);return Pe($(this.parsedUrl),e,this._getRequestOptions(t))}async findImages(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsFindImages)throw new r(`imagery-layer:find-images`,`findImages operation is not supported on the input image service`);return Fe($(this.parsedUrl),e,this._getRequestOptions(t))}async getImageUrl(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsGetImageUrl)throw new r(`imagery-layer:get-image-url`,`getImageUrl operation is not supported on the input image service`);return Ie($(this.parsedUrl),e,this._getRequestOptions(t))}createQuery(){return new Y({outFields:[`*`],returnGeometry:!0,where:this.definitionExpression||`1=1`})}async queryBoundary(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsQueryBoundary)throw new r(`imagery-layer:query-boundary`,`queryBoundary operation is not supported on the input image service`);return e??={outSpatialReference:this.spatialReference},Le($(this.parsedUrl),e,this._getRequestOptions(t))}async queryExtent(e,t){({query:e,requestOptions:t}=await this._prepareForQuery(e,t));let{where:n,objectIds:r,geometry:i,timeExtent:a,start:o,num:s,pixelSize:c}=e,l=n!=null&&n!==`1=1`,u=r!=null&&r.length>0,d=i!=null&&(i.type!==`extent`||!i.equals(this.fullExtent)),f=c!=null,p=o!=null||s!=null,{timeInfo:m}=this,h=a!=null&&m!=null&&!a.equals(m.fullTimeExtent);if(!(l||u||d||f||h||p)){let n=await J(this.url,e,t),{outSpatialReference:r}=e;if(!r||r.equals(this.spatialReference))return{count:n,extent:this.fullExtent.clone()};let{projectLoad:i,projectExecute:a}=await import(`../../geometry/operators/projectOperator.js`);return await i(),{count:n,extent:a(this.fullExtent,r)}}return He(this.url,e,t)}async queryRasters(e,t){({query:e,requestOptions:t}=await this._prepareForQuery(e,t));let n=await We(this.url,e,t),r=this.graphicOrigin;return n.features.forEach(e=>{e.layer=this,e.origin=r}),n}async fetchMaxPixelSize(e,t){let n=await this._fetchCapabilities(t?.signal),r=this.fields?.find(({name:e})=>e.toLowerCase()===`maxps`);if(!n.query.supportsStatistics||!r)return null;let i=`maxPixelSize`,a=(await this.queryRasters({where:`1=1`,outStatistics:[new qe({statisticType:`max`,onStatisticField:r.name,outStatisticFieldName:i})],returnGeometry:!1},t)).features[0]?.attributes?.[i];if(!a)return null;let o=new h({x:a,y:a,spatialReference:this.spatialReference});return T(o,e)}async queryObjectIds(e,t){return{query:e,requestOptions:t}=await this._prepareForQuery(e,t),Ue(this.url,e,t)}async queryGPSInfo(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsQueryGPSInfo)throw new r(`imagery-layer:query-gps-info`,`queryGPSInfo operation is not supported on the input image service`);return e??={where:`1=1`},Re($(this.parsedUrl),e,this._getRequestOptions(t))}async queryRasterCount(e,t){return{query:e,requestOptions:t}=await this._prepareForQuery(e,t),J(this.url,e,t)}async queryVisibleRasters(e,t){if(!e)throw new r(`imagery-layer: query-visible-rasters`,`missing query parameter`);await this.load();let{pixelSize:n,returnDomainValues:i,returnTopmostRaster:a,showNoDataRecords:o}=t||{pixelSize:null,returnDomainValues:!1,returnTopmostRaster:!1,showNoDataRecords:!1},s=!1,c=null,l=null,u=R.servicePixelValue.toLowerCase(),d=this._rasterFunctionNamesIndex;if(e.outFields!=null&&(s=e.outFields.some(e=>!e.toLowerCase().startsWith(u)),this.version>=10.4)){let t=e.outFields.filter(e=>e.toLowerCase().startsWith(u)&&e.length>u.length).map(e=>{let t=e.slice(u.length+1);return[this._updateRenderingRulesFunctionName(t,d),t]});c=t.map(e=>new z({functionName:e[0]})),l=t.map(e=>e[1]);let{rasterFunction:n}=this;c.length===0?n?.functionName?(c.push(n),l.push(n.functionName)):c=null:n?.functionName&&!c.some(e=>e.functionName===n.functionName)&&(c.push(n),l.push(n.functionName))}let f=e.outSpatialReference==null||e.outSpatialReference.equals(this.spatialReference),{multidimensionalSubset:p}=this,m=e.timeExtent||this.timeExtent;if(p){let{isOutside:t,intersection:n}=y(p,{geometry:e.geometry,timeExtent:e.timeExtent,multidimensionalDefinition:this.exportImageServiceParameters.mosaicRule?.multidimensionalDefinition});if(t)throw new r(`imagery-layer:query-visible-rasters`,`the request cannot be fulfilled when falling outside of the multidimensional subset`);n?.timeExtent!=null&&(m=n.timeExtent)}let h=this._combineMosaicRuleWithTimeExtent(this.exportImageServiceParameters.mosaicRule,m),_=e.geometry;this.version<10.91&&_?.type===`extent`&&(_=g.fromExtent(_));let v=this._getQueryParams({geometry:_,timeExtent:m,mosaicRule:h,rasterFunction:this.version<10.4?this.rasterFunction:null,rasterFunctions:c,pixelSize:n,returnCatalogItems:s,returnGeometry:f,raster:this.raster,maxItemCount:a?1:null});delete v.f;let x=new Ke(v);try{await this._generateRasterInfo(this.rasterFunction);let n=await K(this.url,x,{signal:t?.signal,query:{...this.customParameters}}),r=e.outFields,a=n.value!=null&&n.value.toLowerCase().includes(`nodata`),c=s&&!f&&n?.catalogItems?.features.length&&(o||!a),u=this.multidimensionalInfo&&this.sourceType===`raster-dataset`?b({rasterInfo:this.rasterInfo,multidimensionalDefinition:h?.multidimensionalDefinition,timeExtent:m,multidimensionalSubset:this.multidimensionalSubset}):null;if(!c)return this._processVisibleRastersResponse(n,{returnDomainValues:i,templateRRFunctionNames:l,showNoDataRecords:o,templateFields:r,effectiveMultidimensionalDefinition:u});let d=this.objectIdField||`ObjectId`,p=n.catalogItems?.features??[],g=p.map(e=>e.attributes?.[d]),_=new Y({objectIds:g,returnGeometry:!0,outSpatialReference:e.outSpatialReference,outFields:[d]}),v=await this.queryRasters(_);return v?.features?.length&&v.features.forEach(t=>{p.forEach(n=>{n.attributes[d]===t.attributes[d]&&t.geometry&&(n.geometry=t.geometry.clone(),e.outSpatialReference!=null&&(n.geometry.spatialReference=e.outSpatialReference))})}),this._processVisibleRastersResponse(n,{returnDomainValues:i,templateRRFunctionNames:l,showNoDataRecords:o,templateFields:r,effectiveMultidimensionalDefinition:u})}catch{throw new r(`imagery-layer:query-visible-rasters`,`encountered error when querying visible rasters`)}}async fetchVariableStatisticsHistograms(e,t){let r=n($(this.parsedUrl)+`/statistics`,{query:this._getQueryParams({variable:e}),signal:t}).then(e=>e.data?.statistics),i=n($(this.parsedUrl)+`/histograms`,{query:this._getQueryParams({variable:e}),signal:t}).then(e=>e.data?.histograms),a=await Promise.all([r,i]);return a[0]&&a[0].forEach(e=>{e.avg=e.mean,e.stddev=e.standardDeviation}),{statistics:a[0]||null,histograms:a[1]||null}}getMultidimensionalSubsetVariables(e){let t=e??this.serviceRasterInfo.multidimensionalInfo;return x(this.multidimensionalSubset,t)}async _fetchService(e){await this._fetchServiceInfo(e);let t=this.sourceJSON,n=this.serviceRasterInfo==null?q($(this.parsedUrl),t,{signal:e,query:this._getQueryParams()}).then(e=>(this._set(`serviceRasterInfo`,e),this._set(`multidimensionalInfo`,e.multidimensionalInfo),Be(e,t),e)):Promise.resolve(this.serviceRasterInfo),r=!this.rasterInfo&&this._hasRasterFunction(this.rasterFunction)?this._generateRasterInfo(this.rasterFunction,{signal:e}):Promise.resolve(this.rasterInfo),i=this.rasterFunctionInfos?.every(e=>e.functionType!=null)?null:this._getRasterFunctionInfos();return Promise.all([n,r,i]).then(e=>{e[1]?this._set(`rasterInfo`,e[1]):this._set(`rasterInfo`,e[0]),e[2]&&(t.rasterFunctionInfos=e[2],this.setAtOrigin(`rasterFunctionInfos`,e[2],`service`)),this.internalRenderer&&!this._isSupportedRenderer(this.internalRenderer)&&(this._set(`internalRenderer`,null),a.getLogger(this).warn(`ArcGISImageService`,`Switching to the default renderer. Renderer applied is not valid for this Imagery Layer`)),this._set(`internalRenderer`,this._configRenderer(this.renderer)),this.addHandles([s(()=>this.rasterFunction,e=>{(this.renderer||this.symbolizer||this.popupEnabled&&this.popupTemplate)&&this._generateRasterInfo(e).then(e=>{e&&(this.rasterInfo=e)})})]);let{serviceRasterInfo:n}=this;n.multidimensionalInfo!=null&&this._updateMultidimensionalDefinition(n)})}_combineMosaicRuleWithTimeExtent(e,t){let n=this.timeInfo,{multidimensionalInfo:r}=this.serviceRasterInfo;if(e==null||r==null||t==null||n?.startField==null)return e;let{startField:i}=n,a=r.variables.some(e=>e.dimensions.some(e=>e.name===i))?i:`StdTime`;if(e=e.clone(),this.sourceType===`mosaic-dataset`)return e.multidimensionalDefinition=e.multidimensionalDefinition?.filter(e=>e.dimensionName!==a),this._cleanupMultidimensionalDefinition(e);e.multidimensionalDefinition=e.multidimensionalDefinition||[];let o=e.multidimensionalDefinition.filter(e=>e.dimensionName===a),s=t.start==null?null:t.start.getTime(),c=t.end==null?null:t.end.getTime(),l=s==null||c==null||s===c,u=l?[s||c]:[[s,c]],d=this.version>=10.8;if(o.length)o.forEach(e=>{e.dimensionName===a&&(d?(e.dimensionName=null,e.isSlice=!1,e.values=[]):(e.isSlice=l,e.values=u))});else if(!d){let t=e.multidimensionalDefinition.filter(e=>e.variableName!=null&&e.dimensionName==null);t.length?t.forEach(e=>{e.dimensionName=a,e.isSlice=l,e.values=u}):e.multidimensionalDefinition.push(new A({variableName:``,dimensionName:a,isSlice:l,values:u}))}return this._cleanupMultidimensionalDefinition(e)}_cleanupMultidimensionalDefinition(e){return e==null?null:(e.multidimensionalDefinition&&(e.multidimensionalDefinition=e.multidimensionalDefinition.filter(e=>!!(e.variableName||e.dimensionName)),e.multidimensionalDefinition.length===0&&(e.multidimensionalDefinition=null)),this.sourceType!==`mosaic-dataset`&&e.multidimensionalDefinition==null?null:e)}async _prepareForQuery(e,t){if(!(await this._fetchCapabilities(t?.signal)).operations.supportsQuery)throw new r(`imagery-layer:query-rasters`,`query operation is not supported on the input image service`);let n=e==null?this.createQuery():f(Y,e);return t=this._getRequestOptions(t),this.raster&&(t.query={...t.query,raster:this.raster}),{query:n,requestOptions:t}}_isSupportedRenderer(e){let{rasterInfo:t,rasterFunction:n}=this;return e.type===`unique-value`&&this._hasRasterFunction(n)&&t?.bandCount===1&&[`u8`,`s8`].includes(t.pixelType)||t!=null&&e!=null&&H(t).includes(e.type)}async _fetchCapabilities(e){return this.capabilities||await this._fetchServiceInfo(e),this.capabilities}async _fetchServiceInfo(e){let t=this.sourceJSON;if(!t){let{data:r,ssl:i}=await n($(this.parsedUrl),{query:this._getQueryParams(),signal:e});t=r,this.sourceJSON=t,i&&(this.url=this.url.replace(/^http:/i,`https:`))}if(t.capabilities?.toLowerCase().split(`,`).map(e=>e.trim()).indexOf(`tilesonly`)>-1)throw new r(`imagery-layer:fetch-service-info`,`use ImageryTileLayer to open tiles-only image services`);this.read(t,{origin:`service`,url:this.parsedUrl})}_isMosaicDataset(e){return e.serviceSourceType?e.serviceSourceType===`esriImageServiceSourceTypeMosaicDataset`:e.fields?.length>0}_isMosaicRuleSupported(e){if(!e)return!1;let t=this._isMosaicDataset(e),n=e.currentVersion>=10.71&&e.hasMultidimensions&&!(e.fields?.length>1);return t||n}_isVectorFieldResampleFunction(e){if(e==null)return!1;let{functionName:t,functionArguments:n}=e,r=t?.toLowerCase()===`resample`,i=n?.ResampleType||n?.resampleType;return r&&(i===7||i===10)}_configRenderer(e){let{rasterInfo:t}=this,n=t.attributeTable,r=U(n,`red`)!=null&&U(n,`green`)!=null&&U(n,`blue`)!=null,i=!e&&t.colormap==null&&!r&&H(t).includes(`unique-value`);if(!(this.isRenderedFormat||this.pixelFilter)||this._isVectorDataSet()||i){let n=this.mosaicRule?.multidimensionalDefinition?.[0].variableName,r=he({variableName:n,rasterFunctionName:this.rasterFunction?.functionName,presetRenderers:this.presetRenderers});if(!this.bandIds&&t.bandCount>=3){let e=r?.bandIds??V(t);e&&(t.bandCount!==3||e[0]!==0||e[1]!==1||e[2]!==2)&&(this.bandIds=e)}e||=r?.renderer??B(t,{bandIds:this.bandIds,variableName:this.rasterFunction?null:n});let i=ge(e.toJSON());this.symbolizer?(this.symbolizer.rendererJSON=i,this.symbolizer.rasterInfo=t):this.symbolizer=new W({rendererJSON:i,rasterInfo:t}),this.symbolizer.bind().success||(this.symbolizer=null)}return e}_clonePixelData(e){return e==null?e:{extent:e.extent&&e.extent.clone(),pixelBlock:e.pixelBlock==null?null:e.pixelBlock.clone()}}_getQueryParams(e){e?.renderingRule!=null&&typeof e.renderingRule!=`string`&&(e.renderingRule=this._getRenderingRuleString(e.renderingRule));let{raster:t,viewId:n}=this;return{raster:t,viewId:n,f:`json`,...e,...this.customParameters}}_getRequestOptions(e){return{...e,query:{...e?.query,...this.customParameters}}}_decodePixelBlock(e,t,n){return this._rasterJobHandler?this._rasterJobHandler.decode({data:e,options:t}):C(e,t,n)}async _getRasterFunctionInfos(e){let t=this.sourceJSON.rasterFunctionInfos;return this.loaded||!t?.length?t:t&&this.version>=10.3?t.length===1&&t[0].name.toLowerCase()===`none`?[{thumbnail:``,functionType:0,...t[0]}]:(await n($(this.parsedUrl)+`/rasterFunctionInfos`,{query:this._getQueryParams(),signal:e})).data?.rasterFunctionInfos:null}_canRequestImageElement(e){return!this.pixelFilter&&(!e||e.includes(`png`))}async _requestArrayBuffer(e){let{imageProps:t,requestAsImageElement:i,returnImageBitmap:a,signal:o}=e;if(i&&this._canRequestImageElement(t.format)){let r=`${$(this.parsedUrl)}/exportImage`,{data:i}=await n(r,{responseType:a?`blob`:`image`,query:this._getQueryParams({f:`image`,...this.refreshParameters,...e.imageServiceParameters}),signal:o});if(i instanceof Blob){let{bitmap:e}=await M(i,r,{signal:o});return{imageBitmap:e,params:t}}return{imageOrCanvasElement:i,params:t}}let s=this._initJobHandler(),c=n($(this.parsedUrl)+`/exportImage`,{responseType:`array-buffer`,query:this._getQueryParams({f:`image`,...e.imageServiceParameters}),signal:o}),l=(await Promise.all([c,s]))[0].data,u=t.format||`jpgpng`,d=u;if(d!==`bsq`&&d!==`bip`&&(d=w(l)),!d)throw new r(`imagery-layer:fetch-image`,`unsupported format signature `+String.fromCharCode.apply(null,new Uint8Array(l)));let f={signal:o};return{pixelData:{pixelBlock:await this._decodePixelBlock(l,{width:t.width,height:t.height,format:u,applyJpegMask:!0},f),extent:t.extent},params:t}}_generateRasterInfo(e,t){return this.generateRasterInfo(e,t).catch(()=>null)}_isValidCustomizedMosaicRule(e){return e&&JSON.stringify(e.toJSON())!==JSON.stringify(this.defaultMosaicRule?.toJSON())}_updateMultidimensionalDefinition(e){if(this._isValidCustomizedMosaicRule(this.mosaicRule))return;let t=S(e,{multidimensionalSubset:this.multidimensionalSubset});if(t!=null&&t.length>0){this.mosaicRule=this.mosaicRule||new N;let e=this.mosaicRule.multidimensionalDefinition;!this.sourceJSON.defaultVariableName&&this.rasterFunction&&this.rasterFunction.functionName?.toLowerCase()!==`none`&&t.forEach(e=>e.variableName=``),t=t.filter(({variableName:e,dimensionName:t})=>e&&e!==`*`||t),!e?.length&&t.length&&(this.mosaicRule.multidimensionalDefinition=t)}}_processVisibleRastersResponse(e,n){n||={};let r=e.value,{templateRRFunctionNames:i,showNoDataRecords:a,returnDomainValues:o,templateFields:s}=n,c=e.processedValues,l=e.catalogItems?.features,u=e.properties?.Values?.map(e=>e.replaceAll(/ /gi,`, `))||[],d=this.objectIdField||`ObjectId`,f=typeof r==`string`&&r.toLowerCase().includes(`nodata`),p=[];if(r&&!l&&(!f||a)){let e={};e[d]=0;let i=new t({geometry:this.fullExtent,attributes:e});u=[r],l=[i],this.multidimensionalInfo&&this.sourceType===`raster-dataset`&&fe(this.rasterFields,e,n.effectiveMultidimensionalDefinition)}if(!l)return[];this._updateResponseFieldNames(l,s),f&&!a&&(l=[]);let{itemPixelValue:m,servicePixelValue:h}=R,g=this.rasterFields.some(e=>e.name===m),_=this.graphicOrigin;for(let e=0;e<l.length;e++){let t=l[e];if(r!=null){let n=u[e],o=this.rasterFunction&&c&&c.length>0&&i&&i.length>0&&i.includes(this.rasterFunction.functionName)?c[i.indexOf(this.rasterFunction.functionName)]:r;if(n.toLowerCase()===`nodata`&&!a)continue;g&&(t.attributes[m]=n),t.attributes[h]=o,this._updateFeatureWithMagDirValues(t,n);let s=this.fields&&this.fields.length>0,l=this.rasterFunction&&this.serviceRasterInfo.attributeTable!=null?s?n:r:o;this.rasterFunction||(l=s?n:r),this._updateFeatureWithRasterAttributeTableValues(t,l)}if(t.sourceLayer=t.layer=this,t.origin=_,o&&this._updateFeatureWithDomainValues(t),i&&c&&i.length===c.length)for(let e=0;e<i.length;e++){let n=`${R.servicePixelValue}.${i[e]}`;t.attributes[n]=c[e]}p.push(l[e])}return p}_processMultidimensionalIntersection(e,t,n){let{multidimensionalSubset:r}=this;if(!r)return n=this._combineMosaicRuleWithTimeExtent(n,t),{isOutSide:!1,timeExtent:t,mosaicRule:n};if(r){let{isOutside:n,intersection:i}=y(r,{geometry:e,timeExtent:t});if(n)return{isOutSide:!0,timeExtent:null,mosaicRule:null};i?.timeExtent!=null&&(t=i.timeExtent)}if(n=this._combineMosaicRuleWithTimeExtent(n,t),n?.multidimensionalDefinition){let{isOutside:e}=y(r,{multidimensionalDefinition:n.multidimensionalDefinition});if(e)return{isOutSide:!0,timeExtent:null,mosaicRule:null}}return{isOutSide:!1,timeExtent:t,mosaicRule:n}}_updateFeatureWithRasterAttributeTableValues(e,t){let n=this.rasterInfo.attributeTable||this.serviceRasterInfo.attributeTable;if(n==null)return;let{features:r,fields:i}=n,a=i.map(e=>e.name).find(e=>e.toLowerCase()===`value`);if(!a)return;let o=r.filter(e=>e.attributes[a]===(t==null?null:parseInt(t,10)));o&&o[0]&&i.forEach(t=>{let n=pe+t.name;e.attributes[n]=o[0].attributes[t.name]})}_updateFeatureWithMagDirValues(e,t){if(!this._isVectorDataSet())return;let n=t.split(/,\s*/).map(e=>parseFloat(e)),r=n.map(e=>[e]),i=n.map(e=>({minValue:e,maxValue:e,noDataValue:null})),a=new P({height:1,width:1,pixelType:`f32`,pixels:r,statistics:i});this.pixelFilter!=null&&this.pixelFilter({pixelBlock:a,extent:new m(0,0,0,0,this.spatialReference)});let o=this.serviceDataType===`esriImageServiceDataTypeVector-MagDir`?[a.pixels[0][0],a.pixels[1][0]]:D([a.pixels[0][0],a.pixels[1][0]]);e.attributes[R.magnitude]=o[0],e.attributes[R.direction]=o[1]}_updateFeatureWithDomainValues(e){(this.fields&&this.fields.filter(e=>e.domain?.type===`coded-value`))?.forEach(t=>{let n=e.attributes[t.name];if(n!=null){let r=t.domain.codedValues.find(e=>e.code===n);r&&(e.attributes[t.name]=r.name)}})}_updateResponseFieldNames(e,t){if(!t||t.length<1)return;let n=this.fieldsIndex;n!=null&&e.forEach(e=>{if(e?.attributes)for(let r of t){let t=n.get(r)?.name;t&&t!==r&&(e.attributes[r]=e.attributes[t],delete e.attributes[t])}})}_getRenderingRuleString(e){if(e){let t=e.toJSON();return t=t.rasterFunctionDefinition??t,(t.thumbnail||t.thumbnailEx)&&(t.thumbnail=t.thumbnailEx=null),JSON.stringify(t)}return null}_hasRasterFunction(e){return e?.functionName!=null&&e.functionName.toLowerCase()!==`none`}_updateRenderingRulesFunctionName(e,t){if(!e||e.length<1)return;if(e===`Raw`)return e.replace(`Raw`,`None`);let n=e.toLowerCase().replaceAll(/ /gi,`_`);return t.has(n)?t.get(n):e}_isRFTJson(e){return e?.name&&e.arguments&&e.function&&e.hasOwnProperty(`functionType`)}_isVectorDataSet(){return this.serviceDataType===`esriImageServiceDataTypeVector-UV`||this.serviceDataType===`esriImageServiceDataTypeVector-MagDir`}_applyMosaicAndRenderingRules(e){let{raster:t,mosaicRule:n,rasterFunction:r}=this;r&&e.rasterFunction==null&&(e.rasterFunction=r),n&&e.mosaicRule==null&&(e.mosaicRule=n),t&&e.raster==null&&(e.raster=t)}async _updateCurrentRasterInfo(e){if(this.renderer||this.symbolizer){let t=await this._generateRasterInfo(this.rasterFunction,{signal:e});t&&(this.rasterInfo=t)}}_applyMosaicRule(e){let{raster:t,mosaicRule:n}=this;n&&e.mosaicRule==null&&(e.mosaicRule=n),t&&e.raster==null&&(e.raster=t)}_readCapabilities(e){let t=e.capabilities?e.capabilities.toLowerCase().split(`,`).map(e=>e.trim()):[`image`,`catalog`],{currentVersion:n,maxRecordCount:r}=e,i=t.includes(`image`),a=e.serviceDataType===`esriImageServiceDataTypeElevation`,o=!!(e.spatialReference||e.extent?.spatialReference),s=t.includes(`edit`),c=t.includes(`mensuration`)&&o,l=e.mensurationCapabilities==null?[]:e.mensurationCapabilities.toLowerCase().split(`,`).map(e=>e.trim()),u=c&&l.includes(`basic`),d=this._isMosaicDataset(e)&&t.includes(`catalog`),f=t.includes(`download`),p=n>=10.7&&a||n>=11.4&&(a||c&&l.includes(`3d`)),m=d&&e.fields&&e.fields.length>0,h=m&&e.supportsAdvancedQueries?e.advancedQueryCapabilities:void 0;return{data:{supportsAttachment:!1},operations:{supportsComputeHistograms:i,supportsExportImage:i,supportsIdentify:i,supportsImageToMap:n>=11.2&&d,supportsImageToMapMultiray:n>=11.2&&d,supportsMapToImage:n>=11.2&&d,supportsFindImages:n>=11.2&&d,supportsGetImageUrl:n>=11.3&&f,supportsMeasure:c,supportsMeasureFromImage:n>=11.2,supportsDownload:f,supportsQuery:m,supportsGetSamples:n>=10.2&&i,supportsProject:n>=10.3&&i,supportsComputeStatisticsHistograms:n>=10.4&&i,supportsQueryBoundary:n>=10.6&&i,supportsCalculateVolume:p,supportsComputePixelLocation:n>=10.7&&d,supportsComputeAngles:n>=10.91,supportsQueryGPSInfo:n>=11.2&&d,supportsAdd:s,supportsDelete:s,supportsEditing:s,supportsUpdate:s,supportsCalculate:!1,supportsTruncate:!1,supportsValidateSql:!1,supportsChangeTracking:!1,supportsQueryAttachments:!1,supportsResizeAttachments:!1,supportsSync:!1,supportsExceedsLimitStatistics:!1,supportsQueryAnalytics:!1,supportsQueryBins:!1,supportsQueryPivot:!1,supportsQueryTopFeatures:!1,supportsAsyncConvert3D:!1},query:{maxRecordCount:r,maxRecordCountFactor:void 0,maxUniqueIDCount:void 0,relativeTimeBinWindow:void 0,supportsStatisticsAggregatedIds:!!h?.supportsAggregateIds,supportsStatistics:!!h?.supportsStatistics,supportsOrderBy:!!h?.supportsOrderBy,supportsDistinct:!!h?.supportsDistinct,supportsPagination:!!h?.supportsPagination,supportsPaginationOnAggregatedQueries:!!h?.supportsPaginationOnAggregatedQueries,supportsStandardizedQueriesOnly:!!h?.useStandardizedQueries,supportsPercentileStatistics:!!h?.supportsPercentileStatistics,supportsCentroid:!!h?.supportsReturningGeometryCentroid,supportsCentroidOnDegeneratedQuantizedGeometry:!1,supportsCurrentUser:!1,supportsDegeneratedQuantizedGeometry:!1,supportsDistance:!!h?.supportsQueryWithDistance,supportsOutDistance:!!h?.supportsOutDistance,supportsExtent:!!h?.supportsReturningQueryExtent,supportsGeometryProperties:!!h?.supportsReturningGeometryProperties,supportsHavingClause:!!h?.supportsHavingClause,supportsQuantization:!1,supportsQuantizationEditMode:!1,supportsQueryGeometry:!1,supportsResultType:!1,supportsReturnMesh:!1,supportsReturnExceededLimitGeometries:!1,supportsMaxRecordCountFactor:!1,supportsSqlExpression:h?.supportsSqlExpression??!!h,supportsTopFeaturesQuery:!1,supportsQueryByAnonymous:!1,supportsQueryByOthers:!1,supportsHistoricMoment:!1,supportsFormatPBF:!1,supportsFormatPBFWithCurves:!1,supportsDisjointSpatialRelationship:!1,supportsCacheHint:!1,supportsSpatialAggregationStatistics:!1,supportedSpatialAggregationStatistics:{envelope:!1,centroid:!1,convexHull:!1},supportsDefaultSpatialReference:!!h?.supportsDefaultSR,supportsFullTextSearch:!1,supportsCompactGeometry:!1,standardMaxRecordCount:void 0,standardMaxRecordCountNoGeometry:void 0,tileMaxRecordCount:void 0,supportsTrueCurve:!1},mensuration:{supportsDistanceAndAngle:u,supportsAreaAndPerimeter:u,supportsPointOrCentroid:u,supportsHeightFromBaseAndTop:c&&l.includes(`base-top height`),supportsHeightFromBaseAndTopShadow:c&&l.includes(`base-top shadow height`),supportsHeightFromTopAndTopShadow:c&&l.includes(`top-top shadow height`),supports3D:c&&l.includes(`3d`)}}}};e([l({clonable:!1})],Q.prototype,`_functionRasterInfos`,void 0),e([l({readOnly:!0})],Q.prototype,`_serviceSupportsMosaicRule`,void 0),e([X(`_serviceSupportsMosaicRule`,[`currentVersion`,`fields`])],Q.prototype,`readServiceSupportsMosaicRule`,null),e([l({readOnly:!0})],Q.prototype,`_rasterFunctionNamesIndex`,null),e([l()],Q.prototype,`_projectedFullExtent`,void 0),e([l({clonable:!1})],Q.prototype,`_exportTileQueue`,void 0),e([l()],Q.prototype,`adjustAspectRatio`,void 0),e([l({type:[d],json:{write:!0}})],Q.prototype,`bandIds`,void 0),e([X(`bandIds`)],Q.prototype,`readBandIds`,null),e([l({readOnly:!0,json:{read:!1}})],Q.prototype,`capabilities`,void 0),e([X(`service`,`capabilities`,[`capabilities`,`currentVersion`,`serviceDataType`])],Q.prototype,`readCapabilities`,null),e([l({type:Number})],Q.prototype,`compressionQuality`,void 0),e([Z(`compressionQuality`)],Q.prototype,`writeCompressionQuality`,null),e([l({type:Number})],Q.prototype,`compressionTolerance`,void 0),e([Z(`compressionTolerance`)],Q.prototype,`writeCompressionTolerance`,null),e([l({json:{read:{source:`copyrightText`}}})],Q.prototype,`copyright`,void 0),e([l({readOnly:!0})],Q.prototype,`defaultMosaicRule`,void 0),e([X(`defaultMosaicRule`,[`defaultMosaicMethod`])],Q.prototype,`readDefaultMosaicRule`,null),e([l({type:String,json:{name:`layerDefinition.definitionExpression`,write:{enabled:!0,allowNull:!0}}})],Q.prototype,`definitionExpression`,void 0),e([l({readOnly:!0,constructOnly:!0})],Q.prototype,`exportImageServiceParameters`,void 0),e([l()],Q.prototype,`rasterInfo`,void 0),e([l({readOnly:!0,type:[ee]})],Q.prototype,`fields`,void 0),e([l({readOnly:!0})],Q.prototype,`fieldsIndex`,null),e([l({type:[`png`,`png8`,`png24`,`png32`,`jpg`,`bmp`,`gif`,`jpgpng`,`lerc`,`tiff`,`bip`,`bsq`],json:{write:!0}})],Q.prototype,`format`,null),e([X(`service`,`format`,[`serviceDataType`,`allowRasterFunction`])],Q.prototype,`readFormat`,null),e([l({type:m})],Q.prototype,`fullExtent`,void 0),e([l({readOnly:!0})],Q.prototype,`hasMultidimensions`,void 0),e([l({json:{read:{source:`maxImageHeight`}}})],Q.prototype,`imageMaxHeight`,void 0),e([l({json:{read:{source:`maxImageWidth`}}})],Q.prototype,`imageMaxWidth`,void 0),e([l({type:String,json:{type:F.jsonValues,read:F.read,write:F.write}})],Q.prototype,`interpolation`,void 0),e([l()],Q.prototype,`minScale`,void 0),e([X(`service`,`minScale`)],Q.prototype,`readMinScale`,null),e([l()],Q.prototype,`maxScale`,void 0),e([X(`service`,`maxScale`)],Q.prototype,`readMaxScale`,null),e([l({type:N})],Q.prototype,`mosaicRule`,null),e([X(`mosaicRule`,[`mosaicRule`,`defaultMosaicMethod`])],Q.prototype,`readMosaicRule`,null),e([Z(`mosaicRule`)],Q.prototype,`writeMosaicRule`,null),e([l()],Q.prototype,`multidimensionalInfo`,void 0),e([l({type:re,json:{write:!0}})],Q.prototype,`multidimensionalSubset`,void 0),e([l({json:{type:[Number,[Number]],write:!0}})],Q.prototype,`noData`,void 0),e([l({type:String,json:{type:I.jsonValues,read:I.read,write:I.write}})],Q.prototype,`noDataInterpretation`,void 0),e([l({type:String,readOnly:!0,json:{read:{source:[`fields`]}}})],Q.prototype,`objectIdField`,void 0),e([X(`objectIdField`)],Q.prototype,`readObjectIdField`,null),e([l({readOnly:!0})],Q.prototype,`geometryType`,void 0),e([l({})],Q.prototype,`typeIdField`,void 0),e([l({})],Q.prototype,`types`,void 0),e([l({readOnly:!0})],Q.prototype,`parsedUrl`,null),e([l({type:Function})],Q.prototype,`pixelFilter`,void 0),e([l()],Q.prototype,`raster`,void 0),e([l({readOnly:!0})],Q.prototype,`sourceType`,void 0),e([X(`sourceType`,[`serviceSourceType`,`fields`])],Q.prototype,`readSourceType`,null),e([l()],Q.prototype,`viewId`,void 0),e([l({types:G})],Q.prototype,`renderer`,null),e([l({types:G,json:{name:`layerDefinition.drawingInfo.renderer`,origins:{"web-scene":{types:_e,name:`layerDefinition.drawingInfo.renderer`,write:{overridePolicy(e){return{enabled:e&&e.type!==`vector-field`}}}}}}})],Q.prototype,`internalRenderer`,null),e([X(`internalRenderer`)],Q.prototype,`readRenderer`,null),e([Z(`internalRenderer`)],Q.prototype,`writeRenderer`,null),e([l({clonable:!1})],Q.prototype,`symbolizer`,void 0),e([l(O)],Q.prototype,`opacity`,void 0),e([l({readOnly:!0})],Q.prototype,`rasterFields`,null),e([l({constructOnly:!0})],Q.prototype,`rasterFunctionInfos`,void 0),e([l({type:z,json:{name:`renderingRule`}})],Q.prototype,`rasterFunction`,null),e([X(`rasterFunction`,[`renderingRule`,`rasterFunctionInfos`])],Q.prototype,`readRasterFunction`,null),e([l({readOnly:!0})],Q.prototype,`serviceDataType`,void 0),e([l({readOnly:!0,type:_})],Q.prototype,`spatialReference`,void 0),e([X(`spatialReference`,[`spatialReference`,`extent`])],Q.prototype,`readSpatialReference`,null),e([l({type:L.apiValues,json:{read:L.read,type:L.jsonValues}})],Q.prototype,`pixelType`,void 0),e([Z(`pixelType`)],Q.prototype,`writePixelType`,null),e([l({constructOnly:!0,type:me})],Q.prototype,`serviceRasterInfo`,void 0),e([l()],Q.prototype,`sourceJSON`,void 0),e([l(k)],Q.prototype,`url`,void 0),e([l({readOnly:!0})],Q.prototype,`version`,void 0),e([X(`version`,[`currentVersion`,`fields`,`timeInfo`])],Q.prototype,`readVersion`,null),Q=e([u(`esri.layers.mixins.ArcGISImageService`)],Q);function $(e){return e?.path??``}return Q};export{Ze as ArcGISImageService};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{isSome as e}from"../../../core/arrayUtils.js";import t from"../../../core/Error.js";import{getMetersPerUnitForSR as n}from"../../../core/units.js";import r from"../../../geometry/Extent.js";import{P as i,a,b as o,c as s,d as c}from"../../../chunks/pe.js";import l from"../../../geometry/Point.js";import u from"../../../geometry/Polygon.js";import{projectWithoutEngine as d}from"../../../geometry/projectionUtils.js";import f from"../../../geometry/SpatialReference.js";import{getInfo as p}from"../../../geometry/support/spatialReferenceUtils.js";function m(){if(!S)throw new t(`rasterprojectionhelper-project`,`projection operator is not loaded`)}const h=(e,t,n,r=0)=>{if(n[0]===1)return[0,0];let i=1,a=-1,o=1,s=-1;for(let t=0;t<e.length;t+=2)isNaN(e[t])||(i=i>e[t]?e[t]:i,a=a>e[t]?a:e[t],o=o>e[t+1]?e[t+1]:o,s=s>e[t+1]?s:e[t+1]);let{cols:c,rows:l}=t,u=(a-i)/c/n[0],d=(s-o)/l/n[1],f=r*2,p=0,m=!1,h=[0,0];for(let t=0;t<c-3;t++){for(let n=0;n<l-3;n++){let r=t*l*2+n*2,i=(e[r]+e[r+4]+e[r+l*4]+e[r+l*4+4])/4,a=(e[r+1]+e[r+5]+e[r+l*4+1]+e[r+l*4+5])/4,o=Math.abs((i-e[r+l*2+2])/u),s=Math.abs((a-e[r+l*2+3])/d);if(o+s>p&&(p=o+s,h=[o,s]),f&&p>f){m=!0;break}}if(m)break}return h},g={3395:20037508.342789244,3410:17334193.943686873,3857:20037508.342788905,3975:17367530.445161372,4087:20037508.342789244,4088:20015108.787169147,6933:17367530.445161372,32662:20037508.342789244,53001:20015086.79602057,53002:10007543.39801029,53003:20015086.79602057,53004:20015086.79602057,53016:14152803.599503474,53017:17333573.624304302,53034:20015086.79602057,53079:20015114.352186374,53080:20015114.352186374,54001:20037508.342789244,54002:10018754.171394624,54003:20037508.342789244,54004:20037508.342789244,54016:14168658.027268292,54017:17367530.44516137,54034:20037508.342789244,54079:20037508.342789244,54080:20037508.342789244,54100:20037508.342789244,54101:20037508.342789244},_=32,v=4,y=4,b=new Map,x=new Map;let S=!1,C,w,T;async function E(){return C||(C=Promise.withResolvers(),w=await import(`../../../geometry/operators/projectOperator.js`),T=await import(`../../../geometry/operators/support/geographicTransformationUtils.js`),w.projectIsLoaded()||await w.projectLoad(),T.isLoaded()||await T.load(),S=!0,C.resolve()),C.promise}function D(e,t,n){if(m(),n){let n=w.projectExecute(e,t);return T.getTransformation(t,e.spatialReference,n)}return T.getTransformation(e.spatialReference,t,e)}function O(e,t,n,i){let a=e.spatialReference;if(!a||!t||a.equals(t))return e;m();let o=n.center,s=new r({xmin:o.x-e.x/2,xmax:o.x+e.x/2,ymin:o.y-e.y/2,ymax:o.y+e.y/2,spatialReference:a}),c=w.projectExecute(s,t,{geographicTransformation:i}),l=W(t);return c==null||l!=null&&c.width>=l?k(e,a,t):{x:c.width,y:c.height}}function k(e,t,r){let i=n(t)/n(r);return{x:e.x*i,y:e.y*i}}function A(e,r,i){let{spatialReference:a}=i;if(!a||!r||a.equals(r))return e;if(a.isGeographic&&r.isGeographic)return k(e,a,r);if(m(),!S)throw new t(`raster-projection-helper:project-dataset-resolution`,`geometry engine is not loaded`);let{x:o,y:s}=e,c=n(a),l=(o+s)/2*c,d=1;l>30&&(d=30/l,o*=d,s*=d);let f=o*256/2,p=s*256/2,{x:h,y:g}=i.center,_=[];for(let e=0;e<=256;e++)_.push([h-f,g-p+e*s]);for(let e=1;e<=256;e++)_.push([h-f+e*o,g+p]);for(let e=1;e<=256;e++)_.push([h+f,g+p-e*s]);for(let e=1;e<256;e++)_.push([h+f-e*o,g-p]);_.push(_[0]);let v=new u({rings:[_],spatialReference:a}),y=w.projectExecute(v,r);if(!y)return k(e,a,r);let b=y.extent,x=W(r);if(b==null||x!=null&&b.width>=x)return k(e,a,r);let C=$(y.rings),T=o*s*256*256,E=Math.sqrt(C/T)/d,D={x:b.width/d/256,y:b.height/d/256},O={x:o*E,y:s*E},A=D.x*D.y;return Math.abs(A-O.x*O.y)/A<.1?D:O}function j(e,t){return(typeof e==`number`?e:(e.x+e.y)/2)*n(t)*96*39.37}function M(e,t){let{pixelSize:n,extent:r}=e;return j(A(n,t,r),t)}function N(e,t=.01){return n(e)?t/n(e):0}function P(e,t,n,r=!0){let i=e.spatialReference;if(i.equals(t))return e;m();let a=w.projectExecute(e,t,{geographicTransformation:n});return!r||!a||F([e],[a],i,t),a}function F(e,t,n,r){let i=G(n,!0),a=G(r,!0),o=N(n,500),s=N(r,500);if(o&&i!=null&&a!=null)for(let n=0;n<e.length;n++){let r=t[n];if(!r)continue;let{x:c}=e[n],{x:l}=r;l>=a[1]-s&&Math.abs(c-i[0])<o?r.x-=a[1]-a[0]:l<=a[0]+s&&Math.abs(c-i[1])<o&&(r.x+=a[1]-a[0])}}function I(e){let{inSR:t,outSR:n,preferPE:r}=e;if(t.equals(n)){let{points:t}=B(e,null);return t}return t.isWebMercator&&n.isWGS84||t.isWGS84&&n.isWebMercator?te(e):r&&(t.isGeographic||R(t)!=null)?ee(e):L(e)}function L(e){let{points:t}=B(e,null),{inSR:n,outSR:r,datumTransformation:i}=e,a=t.map(e=>new l(e[0],e[1],n)),o=w.projectExecuteMany(a,r,{geographicTransformation:i});return i&&F(a,o,n,r),o.map(e=>e?[e.x,e.y]:[NaN,NaN])}function ee(e){let{inSR:t,outSR:n,datumTransformation:r}=e,{points:o,mask:l}=B(e,R(t));if(!t.isGeographic){let e=t.wkid?i.coordsys(t.wkid):i.fromString(t.isGeographic?a.PE_TYPE_GEOGCS:a.PE_TYPE_PROJCS,t.wkt2||t.wkt);s.projToGeog(e,o.length,o)}if(r!=null&&r.steps.length){let e,t=179.9955;if(n.isGeographic&&(e=o.map(([e])=>e>t?1:e<-179.9955?-1:0)),r.steps.forEach(e=>{let t=e.wkid?i.geogtran(e.wkid):i.fromString(a.PE_TYPE_GEOGTRAN,e.wkt);c.geogToGeog(t,o.length,o,null,e.isInverse?a.PE_TRANSFORM_2_TO_1:a.PE_TRANSFORM_1_TO_2)}),e)for(let n=0;n<o.length;n++){let r=e[n],i=o[n][0],a=i>t?1:i<-179.9955?-1:0;r&&a&&r!==a&&(o[n][0]=r>0?i+360:i-360)}}if(!n.isGeographic){let e=R(n,!0);ne(o,e!=null&&e.isEnvelope?[e.bbox[1],e.bbox[3]]:[-90,90]);let t=n.wkid?i.coordsys(n.wkid):i.fromString(n.isGeographic?a.PE_TYPE_GEOGCS:a.PE_TYPE_PROJCS,n.wkt2||n.wkt);s.geogToProj(t,o.length,o)}let u=o;if(l&&o.length!==l.length){u=[];for(let e=0,t=0;e<l.length;e++)l[e]?u.push(o[t++]):u.push([NaN,NaN])}return u}function te(e){let{cols:t,rows:n,xres:r,yres:i,usePixelCenter:a,inSR:o,outSR:s}=e,{xmin:c,ymax:u}=e;a&&(c+=r/2,u-=i/2);let f=[],p=[],m=Math.max(t,n);for(let e=0;e<m;e++){let a=c+r*Math.min(t,e),m=u-i*Math.min(n,e),h=d(new l({x:a,y:m,spatialReference:o}),o,s);e<=t&&f.push(h.x),e<=n&&p.push(h.y)}let h=[];for(let e=0;e<t;e++)for(let t=0;t<n;t++)h.push([f[e],p[t]]);return h}function R(e,t=!1){let n=e.wkid||e.wkt2||e.wkt;if(!n||e.isGeographic)return null;if(n=String(n),b.has(n)){let e=b.get(n);return t?e?.gcs:e?.pcs}let r=e.wkid?i.coordsys(e.wkid):i.fromString(e.isGeographic?a.PE_TYPE_GEOGCS:a.PE_TYPE_PROJCS,e.wkt2||e.wkt),o=z(r,N(e,1e-4)),s=z(r,0,!0);return b.set(n,{pcs:o,gcs:s}),t?s:o}function z(e,t=0,n=!1){let r=o.generate(e),i=n?e.horizonGcsGenerate():e.horizonPcsGenerate();if(!r||!i?.length)return null;let a=!1,s=i.find(e=>e.getInclusive()===1&&e.getKind()===1);if(!s){if(s=i.find(e=>e.getInclusive()===1&&e.getKind()===0),!s)return null;a=!0}let c=n?0:+(r.getNorthPoleLocation()===2)|(r.getSouthPoleLocation()===2?2:0),l=r.isPannableRectangle(),u=s.getCoord();if(a)return{isEnvelope:a,isPannable:l,vertices:u,coef:null,bbox:[u[0][0]-t,u[0][1]-t,u[1][0]+t,u[1][1]+t],poleLocation:c};let d=0,f=[],[p,m]=u[0],[h,g]=u[0];for(let e=0,t=u.length;e<t;e++){d++,d===t&&(d=0);let[n,r]=u[e],[i,a]=u[d];if(a===r)f.push([n,i,r,a,2]);else{let e=(i-n)/(a-r||1e-4),t=n-e*r;r<a?f.push([e,t,r,a,0]):f.push([e,t,a,r,1])}p=p<n?p:n,m=m<r?m:r,h=h>n?h:n,g=g>r?g:r}return{isEnvelope:!1,isPannable:l,vertices:u,coef:f,bbox:[p,m,h,g],poleLocation:c}}function B(e,t){let n=[],{cols:r,rows:i,xres:a,yres:o,usePixelCenter:s}=e,{xmin:c,ymax:l}=e;if(s&&(c+=a/2,l-=o/2),t==null){for(let e=0;e<r;e++)for(let t=0;t<i;t++)n.push([c+a*e,l-o*t]);return{points:n}}let u=new Uint8Array(r*i);if(t.isEnvelope){let{isPannable:e,bbox:[s,d,f,p]}=t;for(let t=0,m=0;t<r;t++){let r=c+a*t,h=e||r>=s&&r<=f;for(let e=0;e<i;e++,m++){let t=l-o*e;h&&t>=d&&t<=p&&(n.push([r,t]),u[m]=1)}}return{points:n,mask:u}}let d=t.coef,f=[];for(let e=0;e<i;e++){let t=l-o*e,n=[],r=[];for(let e=0;e<d.length;e++){let[i,a,o,s,c]=d[e];if(t===o&&o===s)n.push(i),n.push(a),r.push(2),r.push(2);else if(t>=o&&t<=s){let e=i*t+a;n.push(e),r.push(c)}}let i=n;if(n.length>2){let e=r[0]===2?0:r[0],t=n[0];i=[];for(let a=1;a<r.length;a++)(r[a]!==2||a===r.length-1)&&(r[a]!==e&&(i.push(e===0?Math.min(t,n[a-1]):Math.max(t,n[a-1])),e=r[a],t=n[a]),a===r.length-1&&i.push(r[a]===0?Math.min(t,n[a]):Math.max(t,n[a])));i.sort((e,t)=>e-t)}else n[0]>n[1]&&(i=[n[1],n[0]]);f.push(i)}for(let e=0,t=0;e<r;e++){let r=c+a*e;for(let e=0;e<i;e++,t++){let i=l-o*e,a=f[e];if(a.length===2)r>=a[0]&&r<=a[1]&&(n.push([r,i]),u[t]=1);else if(a.length>2){let e=!1;for(let t=0;t<a.length;t+=2)if(r>=a[t]&&r<=a[t+1]){e=!0;break}e&&(n.push([r,i]),u[t]=1)}}}return{points:n,mask:u}}function ne(e,t){let[n,r]=t;for(let t=0;t<e.length;t++){let i=e[t][1];(i<n||i>r)&&(e[t]=[NaN,NaN])}}function V(e,t){let n=W(e[0].spatialReference);if(e.length<2||n==null||(t??=N(e[0].spatialReference),e=e.filter(e=>e.width>t),e.length===1))return e[0];let{xmin:i,xmax:a,ymin:o,ymax:s}=e[0];for(let t=1;t<e.length;t++){let r=e[t];a=r.xmax+n*t,o=Math.min(o,r.ymin),s=Math.max(s,r.ymax)}return new r({xmin:i,xmax:a,ymin:o,ymax:s,spatialReference:e[0].spatialReference})}function H(t,n,i=null,a=!0){let o=t.spatialReference;if(o.equals(n)||!n)return t;let s=q(t),c=W(o,!0),l=W(n);if(s===0||c==null||l==null){let e=U(t,n,i,a);if(e&&c==null&&l!=null&&Math.abs(e.width-l)<N(n)&&w.projectIsLoaded()){let r=R(o);if(r!=null&&r.poleLocation===0&&t.width<(r.bbox[2]-r.bbox[0])/2)return ie(t,n)||e}return e}let u=t.clone().normalize();if(u.length===1&&t.xmax<c&&t.xmax-c/2>N(o)){let{xmin:e,xmax:n}=t;for(let i=0;i<=s;i++){let a=i===0?e:-c/2,l=i===s?n-c*i:c/2;u[i]=new r({xmin:a,xmax:l,ymin:t.ymin,ymax:t.ymax,spatialReference:o})}}let d=u.map(e=>U(e,n,i,a)).filter(e);return d.length===0?null:V(d)}function re(e,t,n){if(e.type===`extent`){let{xmin:t,ymin:n,xmax:r,ymax:i,spatialReference:a}=e;e=new u({rings:[[[t,i],[r,i],[r,n],[t,n],[t,i]]],spatialReference:a})}return e.spatialReference.equals(t)?e:(m(),w.projectExecute(e,t,{geographicTransformation:n}))}function ie(e,t){let n=W(t);if(n==null)return null;let{xmin:i,ymin:a,xmax:o,ymax:s}=e,c=e.spatialReference,l=new u({spatialReference:c,rings:[[[i,a],[o,a],[o,s],[i,s],[i,a]]]}),d=w.projectExecute(l,t);if(d.rings.length!==2||!d.rings[0].length||!d.rings[1].length)return null;let{rings:f}=d,p=N(c),m=new r({spatialReference:t});for(let e=0;e<2;e++){i=o=f[e][0][0],a=s=f[e][0][1];for(let t=0;t<f[e].length;t++)i=i>f[e][t][0]?f[e][t][0]:i,o=o<f[e][t][0]?f[e][t][0]:o,a=a>f[e][t][1]?f[e][t][1]:a,s=s<f[e][t][1]?f[e][t][1]:s;if(e===0)m.ymin=a,m.ymax=s,m.xmin=i,m.xmax=o;else if(m.ymin=Math.min(m.ymin,a),m.ymax=Math.max(m.ymax,s),Math.abs(o-n/2)<p)m.xmin=i,m.xmax+=n;else if(Math.abs(i+n/2)<p)m.xmax=o+n;else return null}return m}function U(e,t,n,r=!0,i=!0){let a=e.spatialReference;if(a.equals(t)||!t)return e;m();let o=w.projectExecute(e,t,{geographicTransformation:n});if(i&&t.isWebMercator&&o&&(o.ymax=Math.min(20037508.342787,o.ymax),o.ymin=Math.max(-20037508.342787,o.ymin),o.ymin>=o.ymax))return null;if(!r||!o)return o;let s=G(a,!0),c=G(t,!0);if(s==null||c==null)return o;let u=N(a,.001),d=N(a,500),f=N(t,.001);if(Math.abs(o.xmin-c[0])<f&&Math.abs(o.xmax-c[1])<f){let r=Math.abs(e.xmin-s[0]),i=Math.abs(s[1]-e.xmax);if(r<u&&i>d){o.xmin=c[0];let r=[];r.push(new l(e.xmax,e.ymin,a)),r.push(new l(e.xmax,(e.ymin+e.ymax)/2,a)),r.push(new l(e.xmax,e.ymax,a));let i=r.map(e=>P(e,t,n)).filter(e=>!isNaN(e?.x)).map(e=>e.x);o.xmax=Math.max.apply(null,i)}if(i<u&&r>d){o.xmax=c[1];let r=[];r.push(new l(e.xmin,e.ymin,a)),r.push(new l(e.xmin,(e.ymin+e.ymax)/2,a)),r.push(new l(e.xmin,e.ymax,a));let i=r.map(e=>P(e,t,n)).filter(e=>!isNaN(e?.x)).map(e=>e.x);o.xmin=Math.min.apply(null,i)}}else{let e=N(t,.001);Math.abs(o.xmin-c[0])<e&&(o.xmin=c[0]),Math.abs(o.xmax-c[1])<e&&(o.xmax=c[1])}return o}function W(e,t=!1){if(!e)return null;let n=t?20037508.342787:20037508.342788905;return e.isWebMercator?n*2:e.wkid&&e.isGeographic?360:g[e.wkid]*2||null}function G(e,t=!1){if(e.isGeographic)return[-180,180];let n=W(e,t);return n?[-n/2,n/2]:null}function K(e,t,n,r){let i=(e-t)/n;return i-Math.floor(i)===0?r&&--i:i=Math.floor(i),i}function q(e,t=!1){let n=W(e.spatialReference);if(n==null)return 0;let r=n/2,i=t?0:-r,a=N(e.spatialReference),o=!t&&Math.abs(e.xmax-n/2)<a?n/2:e.xmax,s=!t&&Math.abs(e.xmin+n/2)<a?-n/2:e.xmin;return K(o,i,n,!0)-K(s,i,n,!1)}function ae(e){let t=e.storageInfo.origin.x,n=W(e.spatialReference,!0);if(n==null)return{originX:t,halfWorldWidth:null,pyramidsInfo:null};let r=n/2,{nativePixelSize:i,storageInfo:a,extent:o}=e,{maximumPyramidLevel:s,blockWidth:c,pyramidScalingFactor:l}=a,u=i.x,d=[],f=e.transform!=null&&e.transform.type===`gcs-shift`,p=t+(f?0:r),m=f?n-t:r-t;for(let e=0;e<=s;e++){let e=(o.xmax-t)/u/c,n=e-Math.floor(e)===0?e:Math.ceil(e),r=m/u/c,i=r-Math.floor(r)===0?r:Math.ceil(r),a=Math.floor(p/u/c),s=Math.round(p/u)%c,f=(c-Math.round(m/u)%c)%c;d.push({resolutionX:u,blockWidth:c,datasetColumnCount:n,worldColumnCountFromOrigin:i,leftMargin:s,rightPadding:f,originColumnOffset:a}),u*=l}return{originX:t,halfWorldWidth:r,pyramidsInfo:d,hasGCSSShiftTransform:f}}function oe(e){if(!e||e.isGeographic)return e;let t=String(e.wkid||e.wkt2||e.wkt),n;return x.has(t)?n=x.get(t):(n=(e.wkid?i.coordsys(e.wkid):i.fromString(a.PE_TYPE_PROJCS,e.wkt2||e.wkt)).getGeogcs().getCode(),x.set(t,n)),new f({wkid:n})}function se(e){let t=e.isAdaptive&&e.spacing==null,n=e.spacing||[32,32],r=J(e),i={cols:r.size[0]+1,rows:r.size[1]+1},a=r.outofBoundPointCount>0&&r.outofBoundPointCount<r.offsets.length/2,o=r.outofBoundPointCount===r.offsets.length/2||t&&a?[0,0]:h(r.offsets,i,n,4),s=(o[0]+o[1])/2,c=e.projectedExtent.spatialReference,l=e.srcBufferExtent.spatialReference;if(t&&(a||s>4)&&(c.isGeographic||R(c),n=[4,4],r=J({...e,spacing:n}),i={cols:r.size[0]+1,rows:r.size[1]+1},o=h(r.offsets,i,n,4)),r.error=o,n[0]>1&&(r.coefficients=Y(r.offsets,i,a)),e.includeGCSGrid&&!c.isGeographic&&!c.isWebMercator){if(l.isGeographic)r.gcsGrid={offsets:r.offsets,coefficients:r.coefficients,spacing:n};else{let t=R(c);if(t!=null&&!t.isEnvelope){let t=oe(c),o=H(e.projectedExtent,t),{offsets:s}=J({...e,srcBufferExtent:o,spacing:n}),l=Y(s,i,a);r.gcsGrid={offsets:s,coefficients:l,spacing:n}}}}return r}function J(e){let{projectedExtent:t,srcBufferExtent:n,pixelSize:r,datumTransformation:i,rasterTransform:a}=e,o=t.spatialReference,s=n.spatialReference;m();let{xmin:c,ymin:u,xmax:d,ymax:f}=t,p=W(s),h=p!=null&&(e.hasWrapAround||a?.type===`gcs-shift`),g=e.spacing||[32,32],_=g[0]*r.x,v=g[1]*r.y,y=g[0]===1,b=Math.ceil((d-c)/_-.1/g[0])+ +!y,x=Math.ceil((f-u)/v-.1/g[1])+ +!y,S=I({cols:b,rows:x,xmin:c,ymax:f,xres:_,yres:v,inSR:o,outSR:s,datumTransformation:i,preferPE:g[0]<=4,usePixelCenter:y}),C=[],w,T=0,E=y?-1:NaN,{xmin:D,xmax:O,ymax:k,width:A,height:j}=n,M=N(s,500),P=p!=null&&D>0&&O>p/2,F=R(o),L=F!=null&&F.poleLocation>0;for(let e=0;e<b;e++){let t=[];for(let n=0;n<x;n++){let r=S[e*x+n];if(h&&r[0]>O&&r[0]>p/2-M?r[0]-=p:h&&e===0&&r[0]<0&&P&&!a&&(r[0]+=p),!r||isNaN(r[0])||isNaN(r[1]))C.push(E),C.push(E),t.push(null),T++;else{if(a){let e=a.inverseTransform(new l({x:r[0],y:r[1],spatialReference:s}));r=[e.x,e.y]}t.push(r),e>0&&h&&w[n]&&r[0]<w[n][0]&&(r[0]+=p,L&&r[0]>O&&r[0]>p&&(r[0]-=p)),C.push((r[0]-D)/A),C.push((k-r[1])/j)}}w=t}return{offsets:C,error:null,coefficients:null,outofBoundPointCount:T,spacing:g,size:y?[b,x]:[b-1,x-1]}}function Y(e,t,n){let{cols:r,rows:i}=t,a=new Float32Array((r-1)*(i-1)*2*6),o=new Float32Array([-0,-1,1,-1,1,-0,1,-0,-0]),s=new Float32Array([-1,1,0,0,-1,1,1,0,0]);for(let t=0;t<r-1;t++){for(let n=0;n<i-1;n++){let c=t*i*2+n*2,l=e[c],u=e[c+1],d=e[c+2],f=e[c+3];c+=i*2;let p=e[c],m=e[c+1],h=e[c+2],g=e[c+3],_=0,v=(n*(r-1)+t)*12;for(let e=0;e<3;e++)a[v++]=o[_++]*l+o[_++]*d+o[_++]*h;_=0;for(let e=0;e<3;e++)a[v++]=o[_++]*u+o[_++]*f+o[_++]*g;_=0;for(let e=0;e<3;e++)a[v++]=s[_++]*l+s[_++]*p+s[_++]*h;_=0;for(let e=0;e<3;e++)a[v++]=s[_++]*u+s[_++]*m+s[_++]*g}if(n)for(let e=0;e<a.length;e++)isNaN(a[e])&&(a[e]=-1)}return a}function X(e,t){let n=e.clone().normalize();return n.length===1?n[0]:V(n,t)}function ce(e){let{spatialReference:t}=e,n=p(t);if(!n)return e;let[i,a]=n.valid,o=a-i,s=0;if(e.xmin<i){let t=i-e.xmin;s=Math.ceil(t/o)}else if(e.xmin>a){let t=e.xmin-a;s=-Math.ceil(t/o)}return new r({spatialReference:e.spatialReference,xmin:e.xmin+s*o,ymin:e.ymin,xmax:e.xmax+s*o,ymax:e.ymax})}function le(e,t,r){let{storageInfo:i,pixelSize:a}=t,o=0,s=!1,{pyramidResolutions:c}=i,u=i.tileInfo.format?.toLowerCase()===`mixed`?Math.max(1,Math.min(3,i.tileInfo.dpi/96)):1,d=(e.x+e.y)/2/u;if(c!=null&&c.length){let e=c[c.length-1],i=(e.x+e.y)/2,u=(a.x+a.y)/2;if(d<=u)o=0;else if(d>=i)o=c.length,s=d/i>8;else{let e=u,t;for(let n=1;n<=c.length;n++){if(t=(c[n-1].x+c[n-1].y)/2,d<=t){d===t?o=n:r===`down`?(o=n-1,s=d/e>8):o=r===`up`||d-e>t-d||d/e>2?n:n-1;break}e=t}}let f=o===0?a:c[o-1];return s&&Math.min(f.x,f.y)*n(t.spatialReference)>19567&&(s=!1),{pyramidLevel:o,pyramidResolution:new l({x:f.x,y:f.y,spatialReference:t.spatialReference}),excessiveReading:s}}let f=Math.log(e.x/a.x)/Math.LN2,p=Math.log(e.y/a.y)/Math.LN2,m=t.storageInfo.maximumPyramidLevel||0;o=r===`down`?Math.floor(Math.min(f,p)):r===`up`?Math.ceil(Math.max(f,p)):Math.round((f+p)/2),o<0?o=0:o>m&&(s=o>m+3,o=m);let h=2**o,g=new l({x:h*t.nativePixelSize.x,y:h*t.nativePixelSize.y,spatialReference:t.spatialReference});return{pyramidLevel:o,pyramidResolution:g,excessiveReading:s}}function Z(e,t,n=!1){let{pixelSize:r,extent:i}=e,a=D(i,t,!1),o=H(X(i,(r.x+r.y)/16),t,a);return!o||n||q(o)===0?o:U(i,t,a)}function ue(e,t,n){let r=n?.tileSize??512,i=n?.alignGlobalDatasetWithAGOL??!0,a=!!n?.limitToSrcResolution,{extent:o,pixelSize:s}=e,c=A(s,t,o);if(c==null)return{projectedPixelSize:null,scales:null,srcResolutions:null,isCustomTilingScheme:!1};let l=(c.x+c.y)/2,u=j(l,t),d=256/r,f=t.isGeographic?295828763.7958547*d:591657527.591555*d,p=(t.isGeographic?.703125:156543.03392800014)*d,m=e.dataType===`vector-magdir`||e.dataType===`vector-uv`,h=Z(e,t,!0),g=Math.min(Math.ceil(Math.log(Math.min(e.width,e.height)/32)/Math.LN2),Math.ceil(Math.log(f/2/u)/Math.LN2));if(!m&&h&&i&&(t.isGeographic||t.isWebMercator)){let n=W(t);if(m=q(h)>0||n!=null&&h.width>n/4,!m&&n!=null){let t=-1;if(g<3)t=2**g*l*r;else if(e.storageInfo){let{maximumPyramidLevel:n=0,pyramidScalingFactor:i=2}=e.storageInfo;t=i**n*l*r}let i=Math.ceil(n/t);m=i===1||i===2&&n/2-h.xmax<t}}let _=u,v,y=1.001,b=Math.min(2,Math.max(1.414,e.storageInfo?.pyramidScalingFactor||2));if(m){_=f;let n=Q(e,t);v={x:n.x*p,y:n.y*p}}else{v={x:s.x,y:s.y};let e=0;for(;_<y/2*f&&e<g;)e++,_*=b,v.x*=b,v.y*=b;Math.max(_,f)/Math.min(_,f)<=y&&(_=f)}let x=[_],S=[{x:v.x,y:v.y}],C=Math.min(70.5310735,u)/y;for(;_>=C;)_/=b,v.x/=b,v.y/=b,x.push(_),S.push({x:v.x,y:v.y});if(a){let e=s.x*.001,t=S.findIndex(t=>t.x>=s.x-e&&t.x<=s.x+e);t>-1?(S.length=t+1,x.length=t+1):(t=S.findIndex(t=>t.x<=s.x+e),t>0&&(S.length=t,x.length=t))}return{projectedPixelSize:c,scales:x,srcResolutions:S,isCustomTilingScheme:!m}}function Q(e,t){if(t.isWGS84||t.isWebMercator){let n=t.isGeographic?1341104507446289e-21:.29858214164761665,r=t.isGeographic?4326:3857,i=Z(e,new f({wkid:r}),!0),a=A({x:n,y:n},e.spatialReference,i);return{x:a.x/n,y:a.y/n}}let n=A(e.pixelSize,t,e.extent),r=(n.x+n.y)/2;return{x:e.pixelSize.x/r,y:e.pixelSize.y/r}}function de(e,t){let{spatialReference:n,lods:r}=t,{x:i,y:a}=Q(e,n);return r.map(({resolution:e})=>({x:e*i,y:e*a}))}function $(e){let t=0;for(let n of e){let e=n.length,r=n[0][0]*(n[1][1]-n[e-2][1]);for(let t=1;t<e-1;t++)r+=n[t][0]*(n[t+1][1]-n[t-1][1]);t+=r/2}return Math.abs(t)}export{$ as calculateArea2D,ue as computeProjectedScales,Q as computeSrcResolutionRatio,de as computeSrcResolutions,_ as defaultGridSpacing,y as defaultProjectionToleranceInPixels,D as getDefaultDatumTransformationForDataset,I as getProjectedGridPoints,se as getProjectionOffsetGrid,ae as getRasterDatasetAlignmentInfo,M as getSourceScale,W as getWorldWidth,q as getWorldWrapCount,E as load,v as minimumGridSpacing,Z as projectDatasetExtent,A as projectDatasetResolution,H as projectExtent,P as projectPoint,re as projectPolygon,O as projectResolution,ce as shiftExtent,X as snapExtent,le as snapPyramid};
2
+ import{isSome as e}from"../../../core/arrayUtils.js";import t from"../../../core/Error.js";import{getMetersPerUnitForSR as n}from"../../../core/units.js";import r from"../../../geometry/Extent.js";import{P as i,a,b as o,c as s,d as c}from"../../../chunks/pe.js";import l from"../../../geometry/Point.js";import u from"../../../geometry/Polygon.js";import{projectWithoutEngine as d}from"../../../geometry/projectionUtils.js";import f from"../../../geometry/SpatialReference.js";import{getInfo as p}from"../../../geometry/support/spatialReferenceUtils.js";function m(){if(!S)throw new t(`rasterprojectionhelper-project`,`projection operator is not loaded`)}const h=(e,t,n,r=0)=>{if(n[0]===1)return[0,0];let i=1,a=-1,o=1,s=-1;for(let t=0;t<e.length;t+=2)isNaN(e[t])||(i=i>e[t]?e[t]:i,a=a>e[t]?a:e[t],o=o>e[t+1]?e[t+1]:o,s=s>e[t+1]?s:e[t+1]);let{cols:c,rows:l}=t,u=(a-i)/c/n[0],d=(s-o)/l/n[1],f=r*2,p=0,m=!1,h=[0,0];for(let t=0;t<c-3;t++){for(let n=0;n<l-3;n++){let r=t*l*2+n*2,i=(e[r]+e[r+4]+e[r+l*4]+e[r+l*4+4])/4,a=(e[r+1]+e[r+5]+e[r+l*4+1]+e[r+l*4+5])/4,o=Math.abs((i-e[r+l*2+2])/u),s=Math.abs((a-e[r+l*2+3])/d);if(o+s>p&&(p=o+s,h=[o,s]),f&&p>f){m=!0;break}}if(m)break}return h},g={3395:20037508.342789244,3410:17334193.943686873,3857:20037508.342788905,3975:17367530.445161372,4087:20037508.342789244,4088:20015108.787169147,6933:17367530.445161372,32662:20037508.342789244,53001:20015086.79602057,53002:10007543.39801029,53003:20015086.79602057,53004:20015086.79602057,53016:14152803.599503474,53017:17333573.624304302,53034:20015086.79602057,53079:20015114.352186374,53080:20015114.352186374,54001:20037508.342789244,54002:10018754.171394624,54003:20037508.342789244,54004:20037508.342789244,54016:14168658.027268292,54017:17367530.44516137,54034:20037508.342789244,54079:20037508.342789244,54080:20037508.342789244,54100:20037508.342789244,54101:20037508.342789244},_=32,v=4,y=4,b=new Map,x=new Map;let S=!1,C,w,T;async function E(){return C||(C=Promise.withResolvers(),w=await import(`../../../geometry/operators/projectOperator.js`),T=await import(`../../../geometry/operators/support/geographicTransformationUtils.js`),w.projectIsLoaded()||await w.projectLoad(),T.isLoaded()||await T.load(),S=!0,C.resolve()),C.promise}function D(e,t,n){if(m(),n){let n=w.projectExecute(e,t);return T.getTransformation(t,e.spatialReference,n)}return T.getTransformation(e.spatialReference,t,e)}function O(e,t,n,i){let a=e.spatialReference;if(!a||!t||a.equals(t))return e;m();let o=n.center,s=new r({xmin:o.x-e.x/2,xmax:o.x+e.x/2,ymin:o.y-e.y/2,ymax:o.y+e.y/2,spatialReference:a}),c=w.projectExecute(s,t,{geographicTransformation:i}),l=W(t);return c==null||l!=null&&c.width>=l?k(e,a,t):{x:c.width,y:c.height}}function k(e,t,r){let i=n(t)/n(r);return{x:e.x*i,y:e.y*i}}function A(e,r,i){let{spatialReference:a}=i;if(!a||!r||a.equals(r))return e;if(a.isGeographic&&r.isGeographic)return k(e,a,r);if(m(),!S)throw new t(`raster-projection-helper:project-dataset-resolution`,`geometry engine is not loaded`);let{x:o,y:s}=e,c=n(a),l=(o+s)/2*c,d=1;l>30&&(d=30/l,o*=d,s*=d);let f=o*256/2,p=s*256/2,{x:h,y:g}=i.center,_=[];for(let e=0;e<=256;e++)_.push([h-f,g-p+e*s]);for(let e=1;e<=256;e++)_.push([h-f+e*o,g+p]);for(let e=1;e<=256;e++)_.push([h+f,g+p-e*s]);for(let e=1;e<256;e++)_.push([h+f-e*o,g-p]);_.push(_[0]);let v=new u({rings:[_],spatialReference:a}),y=w.projectExecute(v,r);if(!y)return k(e,a,r);let b=y.extent,x=W(r);if(b==null||x!=null&&b.width>=x)return k(e,a,r);let C=$(y.rings),T=o*s*256*256,E=Math.sqrt(C/T)/d,D={x:b.width/d/256,y:b.height/d/256},O={x:o*E,y:s*E},A=D.x*D.y;return Math.abs(A-O.x*O.y)/A<.1?D:O}function j(e,t){return(typeof e==`number`?e:(e.x+e.y)/2)*n(t)*96*39.37}function M(e,t){let{pixelSize:n,extent:r}=e;return j(A(n,t,r),t)}function N(e,t=.01){return n(e)?t/n(e):0}function P(e,t,n,r=!0){let i=e.spatialReference;if(i.equals(t))return e;m();let a=w.projectExecute(e,t,{geographicTransformation:n});return!r||!a||F([e],[a],i,t),a}function F(e,t,n,r){let i=G(n,!0),a=G(r,!0),o=N(n,500),s=N(r,500);if(o&&i!=null&&a!=null)for(let n=0;n<e.length;n++){let r=t[n];if(!r)continue;let{x:c}=e[n],{x:l}=r;l>=a[1]-s&&Math.abs(c-i[0])<o?r.x-=a[1]-a[0]:l<=a[0]+s&&Math.abs(c-i[1])<o&&(r.x+=a[1]-a[0])}}function I(e){let{inSR:t,outSR:n,preferPE:r}=e;if(t.equals(n)){let{points:t}=B(e,null);return t}return t.isWebMercator&&n.isWGS84||t.isWGS84&&n.isWebMercator?te(e):r&&(t.isGeographic||R(t)!=null)?ee(e):L(e)}function L(e){let{points:t}=B(e,null),{inSR:n,outSR:r,datumTransformation:i}=e,a=t.map(e=>new l(e[0],e[1],n)),o=w.projectExecuteMany(a,r,{geographicTransformation:i});return i&&F(a,o,n,r),o.map(e=>e?[e.x,e.y]:[NaN,NaN])}function ee(e){let{inSR:t,outSR:n,datumTransformation:r}=e,{points:o,mask:l}=B(e,R(t));if(!t.isGeographic){let e=t.wkid?i.coordsys(t.wkid):i.fromString(t.isGeographic?a.PE_TYPE_GEOGCS:a.PE_TYPE_PROJCS,t.wkt2||t.wkt);s.projToGeog(e,o.length,o)}if(r!=null&&r.steps.length){let e,t=179.9955;if(n.isGeographic&&(e=o.map(([e])=>e>t?1:e<-179.9955?-1:0)),r.steps.forEach(e=>{let t=e.wkid?i.geogtran(e.wkid):i.fromString(a.PE_TYPE_GEOGTRAN,e.wkt);c.geogToGeog(t,o.length,o,null,e.isInverse?a.PE_TRANSFORM_2_TO_1:a.PE_TRANSFORM_1_TO_2)}),e)for(let n=0;n<o.length;n++){let r=e[n],i=o[n][0],a=i>t?1:i<-179.9955?-1:0;r&&a&&r!==a&&(o[n][0]=r>0?i+360:i-360)}}if(!n.isGeographic){let e=R(n,!0);ne(o,e!=null&&e.isEnvelope?[e.bbox[1],e.bbox[3]]:[-90,90]);let t=n.wkid?i.coordsys(n.wkid):i.fromString(n.isGeographic?a.PE_TYPE_GEOGCS:a.PE_TYPE_PROJCS,n.wkt2||n.wkt);s.geogToProj(t,o.length,o)}let u=o;if(l&&o.length!==l.length){u=[];for(let e=0,t=0;e<l.length;e++)l[e]?u.push(o[t++]):u.push([NaN,NaN])}return u}function te(e){let{cols:t,rows:n,xres:r,yres:i,usePixelCenter:a,inSR:o,outSR:s}=e,{xmin:c,ymax:u}=e;a&&(c+=r/2,u-=i/2);let f=[],p=[],m=Math.max(t,n);for(let e=0;e<m;e++){let a=c+r*Math.min(t,e),m=u-i*Math.min(n,e),h=d(new l({x:a,y:m,spatialReference:o}),o,s);e<=t&&f.push(h.x),e<=n&&p.push(h.y)}let h=[];for(let e=0;e<t;e++)for(let t=0;t<n;t++)h.push([f[e],p[t]]);return h}function R(e,t=!1){let n=e.wkid||e.wkt2||e.wkt;if(!n||e.isGeographic)return null;if(n=String(n),b.has(n)){let e=b.get(n);return t?e?.gcs:e?.pcs}let r=e.wkid?i.coordsys(e.wkid):i.fromString(e.isGeographic?a.PE_TYPE_GEOGCS:a.PE_TYPE_PROJCS,e.wkt2||e.wkt),o=z(r,N(e,1e-4)),s=z(r,0,!0);return b.set(n,{pcs:o,gcs:s}),t?s:o}function z(e,t=0,n=!1){let r=o.generate(e),i=n?e.horizonGcsGenerate():e.horizonPcsGenerate();if(!r||!i?.length)return null;let a=!1,s=i.find(e=>e.getInclusive()===1&&e.getKind()===1);if(!s){if(s=i.find(e=>e.getInclusive()===1&&e.getKind()===0),!s)return null;a=!0}let c=n?0:+(r.getNorthPoleLocation()===2)|(r.getSouthPoleLocation()===2?2:0),l=r.isPannableRectangle(),u=s.getCoord();if(a)return{isEnvelope:a,isPannable:l,vertices:u,coef:null,bbox:[u[0][0]-t,u[0][1]-t,u[1][0]+t,u[1][1]+t],poleLocation:c};let d=0,f=[],[p,m]=u[0],[h,g]=u[0];for(let e=0,t=u.length;e<t;e++){d++,d===t&&(d=0);let[n,r]=u[e],[i,a]=u[d];if(a===r)f.push([n,i,r,a,2]);else{let e=(i-n)/(a-r||1e-4),t=n-e*r;r<a?f.push([e,t,r,a,0]):f.push([e,t,a,r,1])}p=p<n?p:n,m=m<r?m:r,h=h>n?h:n,g=g>r?g:r}return{isEnvelope:!1,isPannable:l,vertices:u,coef:f,bbox:[p,m,h,g],poleLocation:c}}function B(e,t){let n=[],{cols:r,rows:i,xres:a,yres:o,usePixelCenter:s}=e,{xmin:c,ymax:l}=e;if(s&&(c+=a/2,l-=o/2),t==null){for(let e=0;e<r;e++)for(let t=0;t<i;t++)n.push([c+a*e,l-o*t]);return{points:n}}let u=new Uint8Array(r*i);if(t.isEnvelope){let{isPannable:e,bbox:[s,d,f,p]}=t;for(let t=0,m=0;t<r;t++){let r=c+a*t,h=e||r>=s&&r<=f;for(let e=0;e<i;e++,m++){let t=l-o*e;h&&t>=d&&t<=p&&(n.push([r,t]),u[m]=1)}}return{points:n,mask:u}}let d=t.coef,f=[];for(let e=0;e<i;e++){let t=l-o*e,n=[],r=[];for(let e=0;e<d.length;e++){let[i,a,o,s,c]=d[e];if(t===o&&o===s)n.push(i),n.push(a),r.push(2),r.push(2);else if(t>=o&&t<=s){let e=i*t+a;n.push(e),r.push(c)}}let i=n;if(n.length>2){let e=r[0]===2?0:r[0],t=n[0];i=[];for(let a=1;a<r.length;a++)(r[a]!==2||a===r.length-1)&&(r[a]!==e&&(i.push(e===0?Math.min(t,n[a-1]):Math.max(t,n[a-1])),e=r[a],t=n[a]),a===r.length-1&&i.push(r[a]===0?Math.min(t,n[a]):Math.max(t,n[a])));i.sort((e,t)=>e-t)}else n[0]>n[1]&&(i=[n[1],n[0]]);f.push(i)}for(let e=0,t=0;e<r;e++){let r=c+a*e;for(let e=0;e<i;e++,t++){let i=l-o*e,a=f[e];if(a.length===2)r>=a[0]&&r<=a[1]&&(n.push([r,i]),u[t]=1);else if(a.length>2){let e=!1;for(let t=0;t<a.length;t+=2)if(r>=a[t]&&r<=a[t+1]){e=!0;break}e&&(n.push([r,i]),u[t]=1)}}}return{points:n,mask:u}}function ne(e,t){let[n,r]=t;for(let t=0;t<e.length;t++){let i=e[t][1];(i<n||i>r)&&(e[t]=[NaN,NaN])}}function V(e,t){let n=W(e[0].spatialReference);if(e.length<2||n==null||(t??=N(e[0].spatialReference),e=e.filter(e=>e.width>t),e.length===1))return e[0];let{xmin:i,xmax:a,ymin:o,ymax:s}=e[0];for(let t=1;t<e.length;t++){let r=e[t];a=r.xmax+n*t,o=Math.min(o,r.ymin),s=Math.max(s,r.ymax)}return new r({xmin:i,xmax:a,ymin:o,ymax:s,spatialReference:e[0].spatialReference})}function H(t,n,i=null,a=!0){let o=t.spatialReference;if(o.equals(n)||!n)return t;let s=q(t),c=W(o,!0),l=W(n);if(s===0||c==null||l==null){let e=U(t,n,i,a);if(e&&c==null&&l!=null&&Math.abs(e.width-l)<N(n)&&w.projectIsLoaded()){let r=R(o);if(r!=null&&r.poleLocation===0&&t.width<(r.bbox[2]-r.bbox[0])/2)return ie(t,n)||e}return e}let u=t.clone().normalize();if(u.length===1&&t.xmax<c&&t.xmax-c/2>N(o)){let{xmin:e,xmax:n}=t;for(let i=0;i<=s;i++){let a=i===0?e:-c/2,l=i===s?n-c*i:c/2;u[i]=new r({xmin:a,xmax:l,ymin:t.ymin,ymax:t.ymax,spatialReference:o})}}let d=u.map(e=>U(e,n,i,a)).filter(e);return d.length===0?null:V(d)}function re(e,t,n){if(e.type===`extent`){let{xmin:t,ymin:n,xmax:r,ymax:i,spatialReference:a}=e;e=new u({rings:[[[t,i],[r,i],[r,n],[t,n],[t,i]]],spatialReference:a})}return e.spatialReference.equals(t)?e:(m(),w.projectExecute(e,t,{geographicTransformation:n}))}function ie(e,t){let n=W(t);if(n==null)return null;let{xmin:i,ymin:a,xmax:o,ymax:s}=e,c=e.spatialReference,l=new u({spatialReference:c,rings:[[[i,a],[o,a],[o,s],[i,s],[i,a]]]}),d=w.projectExecute(l,t);if(d.rings.length!==2||!d.rings[0].length||!d.rings[1].length)return null;let{rings:f}=d,p=N(c),m=new r({spatialReference:t});for(let e=0;e<2;e++){i=o=f[e][0][0],a=s=f[e][0][1];for(let t=0;t<f[e].length;t++)i=i>f[e][t][0]?f[e][t][0]:i,o=o<f[e][t][0]?f[e][t][0]:o,a=a>f[e][t][1]?f[e][t][1]:a,s=s<f[e][t][1]?f[e][t][1]:s;if(e===0)m.ymin=a,m.ymax=s,m.xmin=i,m.xmax=o;else if(m.ymin=Math.min(m.ymin,a),m.ymax=Math.max(m.ymax,s),Math.abs(o-n/2)<p)m.xmin=i,m.xmax+=n;else if(Math.abs(i+n/2)<p)m.xmax=o+n;else return null}return m}function U(e,t,n,r=!0,i=!0){let a=e.spatialReference;if(a.equals(t)||!t)return e;m();let o=w.projectExecute(e,t,{geographicTransformation:n});if(i&&t.isWebMercator&&o&&(o.ymax=Math.min(20037508.342787,o.ymax),o.ymin=Math.max(-20037508.342787,o.ymin),o.ymin>=o.ymax))return null;if(!r||!o)return o;let s=G(a,!0),c=G(t,!0);if(s==null||c==null)return o;let u=N(a,.001),d=N(a,500),f=N(t,.001);if(Math.abs(o.xmin-c[0])<f&&Math.abs(o.xmax-c[1])<f){let r=Math.abs(e.xmin-s[0]),i=Math.abs(s[1]-e.xmax);if(r<u&&i>d){o.xmin=c[0];let r=[];r.push(new l(e.xmax,e.ymin,a)),r.push(new l(e.xmax,(e.ymin+e.ymax)/2,a)),r.push(new l(e.xmax,e.ymax,a));let i=r.map(e=>P(e,t,n)).filter(e=>!isNaN(e?.x)).map(e=>e.x);o.xmax=Math.max.apply(null,i)}if(i<u&&r>d){o.xmax=c[1];let r=[];r.push(new l(e.xmin,e.ymin,a)),r.push(new l(e.xmin,(e.ymin+e.ymax)/2,a)),r.push(new l(e.xmin,e.ymax,a));let i=r.map(e=>P(e,t,n)).filter(e=>!isNaN(e?.x)).map(e=>e.x);o.xmin=Math.min.apply(null,i)}}else{let e=N(t,.001);Math.abs(o.xmin-c[0])<e&&(o.xmin=c[0]),Math.abs(o.xmax-c[1])<e&&(o.xmax=c[1])}return o}function W(e,t=!1){if(!e)return null;let n=t?20037508.342787:20037508.342788905;return e.isWebMercator?n*2:e.wkid&&e.isGeographic?360:g[e.wkid]*2||null}function G(e,t=!1){if(e.isGeographic)return[-180,180];let n=W(e,t);return n?[-n/2,n/2]:null}function K(e,t,n,r){let i=(e-t)/n;return i-Math.floor(i)===0?r&&--i:i=Math.floor(i),i}function q(e,t=!1){let n=W(e.spatialReference);if(n==null)return 0;let r=n/2,i=t?0:-r,a=N(e.spatialReference),o=!t&&Math.abs(e.xmax-n/2)<a?n/2:e.xmax,s=!t&&Math.abs(e.xmin+n/2)<a?-n/2:e.xmin;return K(o,i,n,!0)-K(s,i,n,!1)}function ae(e){let t=e.storageInfo.origin.x,n=W(e.spatialReference,!0);if(n==null)return{originX:t,halfWorldWidth:null,pyramidsInfo:null};let r=n/2,{nativePixelSize:i,storageInfo:a,extent:o}=e,{maximumPyramidLevel:s,blockWidth:c,pyramidScalingFactor:l}=a,u=i.x,d=[],f=e.transform!=null&&e.transform.type===`gcs-shift`,p=Math.max(0,t+(f?0:r));for(let e=0;e<=s;e++){let e=(o.xmax-t)/u/c,r=e-Math.floor(e)===0?e:Math.ceil(e),i=Math.round(p/u),a=Math.round(n/u)-i,s=Math.ceil(a/c),f=Math.floor(i/c),m=i%c,h=(c-a%c)%c;d.push({resolutionX:u,blockWidth:c,datasetColumnCount:r,worldColumnCountFromOrigin:s,leftMargin:m,rightPadding:h,originColumnOffset:f}),u*=l}return{originX:t,halfWorldWidth:r,pyramidsInfo:d,hasGCSSShiftTransform:f}}function oe(e){if(!e||e.isGeographic)return e;let t=String(e.wkid||e.wkt2||e.wkt),n;return x.has(t)?n=x.get(t):(n=(e.wkid?i.coordsys(e.wkid):i.fromString(a.PE_TYPE_PROJCS,e.wkt2||e.wkt)).getGeogcs().getCode(),x.set(t,n)),new f({wkid:n})}function se(e){let t=e.isAdaptive&&e.spacing==null,n=e.spacing||[32,32],r=J(e),i={cols:r.size[0]+1,rows:r.size[1]+1},a=r.outofBoundPointCount>0&&r.outofBoundPointCount<r.offsets.length/2,o=r.outofBoundPointCount===r.offsets.length/2||t&&a?[0,0]:h(r.offsets,i,n,4),s=(o[0]+o[1])/2,c=e.projectedExtent.spatialReference,l=e.srcBufferExtent.spatialReference;if(t&&(a||s>4)&&(c.isGeographic||R(c),n=[4,4],r=J({...e,spacing:n}),i={cols:r.size[0]+1,rows:r.size[1]+1},o=h(r.offsets,i,n,4)),r.error=o,n[0]>1&&(r.coefficients=Y(r.offsets,i,a)),e.includeGCSGrid&&!c.isGeographic&&!c.isWebMercator){if(l.isGeographic)r.gcsGrid={offsets:r.offsets,coefficients:r.coefficients,spacing:n};else{let t=R(c);if(t!=null&&!t.isEnvelope){let t=oe(c),o=H(e.projectedExtent,t),{offsets:s}=J({...e,srcBufferExtent:o,spacing:n}),l=Y(s,i,a);r.gcsGrid={offsets:s,coefficients:l,spacing:n}}}}return r}function J(e){let{projectedExtent:t,srcBufferExtent:n,pixelSize:r,datumTransformation:i,rasterTransform:a}=e,o=t.spatialReference,s=n.spatialReference;m();let{xmin:c,ymin:u,xmax:d,ymax:f}=t,p=W(s),h=p!=null&&(e.hasWrapAround||a?.type===`gcs-shift`),g=e.spacing||[32,32],_=g[0]*r.x,v=g[1]*r.y,y=g[0]===1,b=Math.ceil((d-c)/_-.1/g[0])+ +!y,x=Math.ceil((f-u)/v-.1/g[1])+ +!y,S=I({cols:b,rows:x,xmin:c,ymax:f,xres:_,yres:v,inSR:o,outSR:s,datumTransformation:i,preferPE:g[0]<=4,usePixelCenter:y}),C=[],w,T=0,E=y?-1:NaN,{xmin:D,xmax:O,ymax:k,width:A,height:j}=n,M=N(s,500),P=p!=null&&D>0&&O>p/2,F=R(o),L=F!=null&&F.poleLocation>0;for(let e=0;e<b;e++){let t=[];for(let n=0;n<x;n++){let r=S[e*x+n];if(h&&r[0]>O&&r[0]>p/2-M?r[0]-=p:h&&e===0&&r[0]<0&&P&&!a&&(r[0]+=p),!r||isNaN(r[0])||isNaN(r[1]))C.push(E),C.push(E),t.push(null),T++;else{if(a){let e=a.inverseTransform(new l({x:r[0],y:r[1],spatialReference:s}));r=[e.x,e.y]}t.push(r),e>0&&h&&w[n]&&r[0]<w[n][0]&&(r[0]+=p,L&&r[0]>O&&r[0]>p&&(r[0]-=p)),C.push((r[0]-D)/A),C.push((k-r[1])/j)}}w=t}return{offsets:C,error:null,coefficients:null,outofBoundPointCount:T,spacing:g,size:y?[b,x]:[b-1,x-1]}}function Y(e,t,n){let{cols:r,rows:i}=t,a=new Float32Array((r-1)*(i-1)*2*6),o=new Float32Array([-0,-1,1,-1,1,-0,1,-0,-0]),s=new Float32Array([-1,1,0,0,-1,1,1,0,0]);for(let t=0;t<r-1;t++){for(let n=0;n<i-1;n++){let c=t*i*2+n*2,l=e[c],u=e[c+1],d=e[c+2],f=e[c+3];c+=i*2;let p=e[c],m=e[c+1],h=e[c+2],g=e[c+3],_=0,v=(n*(r-1)+t)*12;for(let e=0;e<3;e++)a[v++]=o[_++]*l+o[_++]*d+o[_++]*h;_=0;for(let e=0;e<3;e++)a[v++]=o[_++]*u+o[_++]*f+o[_++]*g;_=0;for(let e=0;e<3;e++)a[v++]=s[_++]*l+s[_++]*p+s[_++]*h;_=0;for(let e=0;e<3;e++)a[v++]=s[_++]*u+s[_++]*m+s[_++]*g}if(n)for(let e=0;e<a.length;e++)isNaN(a[e])&&(a[e]=-1)}return a}function X(e,t){let n=e.clone().normalize();return n.length===1?n[0]:V(n,t)}function ce(e){let{spatialReference:t}=e,n=p(t);if(!n)return e;let[i,a]=n.valid,o=a-i,s=0;if(e.xmin<i){let t=i-e.xmin;s=Math.ceil(t/o)}else if(e.xmin>a){let t=e.xmin-a;s=-Math.ceil(t/o)}return new r({spatialReference:e.spatialReference,xmin:e.xmin+s*o,ymin:e.ymin,xmax:e.xmax+s*o,ymax:e.ymax})}function le(e,t,r){let{storageInfo:i,pixelSize:a}=t,o=0,s=!1,{pyramidResolutions:c}=i,u=i.tileInfo.format?.toLowerCase()===`mixed`?Math.max(1,Math.min(3,i.tileInfo.dpi/96)):1,d=(e.x+e.y)/2/u;if(c!=null&&c.length){let e=c[c.length-1],i=(e.x+e.y)/2,u=(a.x+a.y)/2;if(d<=u)o=0;else if(d>=i)o=c.length,s=d/i>8;else{let e=u,t;for(let n=1;n<=c.length;n++){if(t=(c[n-1].x+c[n-1].y)/2,d<=t){d===t?o=n:r===`down`?(o=n-1,s=d/e>8):o=r===`up`||d-e>t-d||d/e>2?n:n-1;break}e=t}}let f=o===0?a:c[o-1];return s&&Math.min(f.x,f.y)*n(t.spatialReference)>19567&&(s=!1),{pyramidLevel:o,pyramidResolution:new l({x:f.x,y:f.y,spatialReference:t.spatialReference}),excessiveReading:s}}let f=Math.log(e.x/a.x)/Math.LN2,p=Math.log(e.y/a.y)/Math.LN2,m=t.storageInfo.maximumPyramidLevel||0;o=r===`down`?Math.floor(Math.min(f,p)):r===`up`?Math.ceil(Math.max(f,p)):Math.round((f+p)/2),o<0?o=0:o>m&&(s=o>m+3,o=m);let h=2**o,g=new l({x:h*t.nativePixelSize.x,y:h*t.nativePixelSize.y,spatialReference:t.spatialReference});return{pyramidLevel:o,pyramidResolution:g,excessiveReading:s}}function Z(e,t,n=!1){let{pixelSize:r,extent:i}=e,a=D(i,t,!1),o=H(X(i,(r.x+r.y)/16),t,a);return!o||n||q(o)===0?o:U(i,t,a)}function ue(e,t,n){let r=n?.tileSize??512,i=n?.alignGlobalDatasetWithAGOL??!0,a=!!n?.limitToSrcResolution,{extent:o,pixelSize:s}=e,c=A(s,t,o);if(c==null)return{projectedPixelSize:null,scales:null,srcResolutions:null,isCustomTilingScheme:!1};let l=(c.x+c.y)/2,u=j(l,t),d=256/r,f=t.isGeographic?295828763.7958547*d:591657527.591555*d,p=(t.isGeographic?.703125:156543.03392800014)*d,m=e.dataType===`vector-magdir`||e.dataType===`vector-uv`,h=Z(e,t,!0),g=Math.min(Math.ceil(Math.log(Math.min(e.width,e.height)/32)/Math.LN2),Math.ceil(Math.log(f/2/u)/Math.LN2));if(!m&&h&&i&&(t.isGeographic||t.isWebMercator)){let n=W(t);if(m=q(h)>0||n!=null&&h.width>n/4,!m&&n!=null){let t=-1;if(g<3)t=2**g*l*r;else if(e.storageInfo){let{maximumPyramidLevel:n=0,pyramidScalingFactor:i=2}=e.storageInfo;t=i**n*l*r}let i=Math.ceil(n/t);m=i===1||i===2&&n/2-h.xmax<t}}let _=u,v,y=1.001,b=Math.min(2,Math.max(1.414,e.storageInfo?.pyramidScalingFactor||2));if(m){_=f;let n=Q(e,t);v={x:n.x*p,y:n.y*p}}else{v={x:s.x,y:s.y};let e=0;for(;_<y/2*f&&e<g;)e++,_*=b,v.x*=b,v.y*=b;Math.max(_,f)/Math.min(_,f)<=y&&(_=f)}let x=[_],S=[{x:v.x,y:v.y}],C=Math.min(70.5310735,u)/y;for(;_>=C;)_/=b,v.x/=b,v.y/=b,x.push(_),S.push({x:v.x,y:v.y});if(a){let e=s.x*.001,t=S.findIndex(t=>t.x>=s.x-e&&t.x<=s.x+e);t>-1?(S.length=t+1,x.length=t+1):(t=S.findIndex(t=>t.x<=s.x+e),t>0&&(S.length=t,x.length=t))}return{projectedPixelSize:c,scales:x,srcResolutions:S,isCustomTilingScheme:!m}}function Q(e,t){if(t.isWGS84||t.isWebMercator){let n=t.isGeographic?1341104507446289e-21:.29858214164761665,r=t.isGeographic?4326:3857,i=Z(e,new f({wkid:r}),!0),a=A({x:n,y:n},e.spatialReference,i);return{x:a.x/n,y:a.y/n}}let n=A(e.pixelSize,t,e.extent),r=(n.x+n.y)/2;return{x:e.pixelSize.x/r,y:e.pixelSize.y/r}}function de(e,t){let{spatialReference:n,lods:r}=t,{x:i,y:a}=Q(e,n);return r.map(({resolution:e})=>({x:e*i,y:e*a}))}function $(e){let t=0;for(let n of e){let e=n.length,r=n[0][0]*(n[1][1]-n[e-2][1]);for(let t=1;t<e-1;t++)r+=n[t][0]*(n[t+1][1]-n[t-1][1]);t+=r/2}return Math.abs(t)}export{$ as calculateArea2D,ue as computeProjectedScales,Q as computeSrcResolutionRatio,de as computeSrcResolutions,_ as defaultGridSpacing,y as defaultProjectionToleranceInPixels,D as getDefaultDatumTransformationForDataset,I as getProjectedGridPoints,se as getProjectionOffsetGrid,ae as getRasterDatasetAlignmentInfo,M as getSourceScale,W as getWorldWidth,q as getWorldWrapCount,E as load,v as minimumGridSpacing,Z as projectDatasetExtent,A as projectDatasetResolution,H as projectExtent,P as projectPoint,re as projectPolygon,O as projectResolution,ce as shiftExtent,X as snapExtent,le as snapPyramid};