@arcgis/core 4.24.0-next.20220331 → 4.24.0-next.20220401

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 (124) hide show
  1. package/WebScene.js +1 -1
  2. package/analysis/LineOfSightAnalysisObserver.js +1 -1
  3. package/analysis/LineOfSightAnalysisTarget.js +1 -1
  4. package/assets/esri/core/workers/RemoteClient.js +1 -1
  5. package/assets/esri/core/workers/chunks/0eb9c9477d36cd212f8b.js +1 -0
  6. package/assets/esri/core/workers/chunks/10779a256841c37f2429.js +1 -0
  7. package/assets/esri/core/workers/chunks/125b14c2ccd96d7c20c2.js +1 -0
  8. package/assets/esri/core/workers/chunks/{19cb7315d403a4cd4f59.js → 2530e8ccf6e12787ce76.js} +1 -1
  9. package/assets/esri/core/workers/chunks/{302c68c5b91d1ab4fd47.js → 560234694f3e53802aff.js} +1 -1
  10. package/assets/esri/core/workers/chunks/5633710daeb3bbb79bcf.js +1 -0
  11. package/assets/esri/core/workers/chunks/6f7917da7166e8c6854b.js +1 -0
  12. package/assets/esri/core/workers/chunks/7388824eac8da01ea03d.js +1 -0
  13. package/assets/esri/core/workers/chunks/794b47764ebb0257ed41.js +1 -0
  14. package/assets/esri/core/workers/chunks/81e9d860a044acec74ce.js +1 -0
  15. package/assets/esri/core/workers/chunks/{9a32f129f0d67547e44c.js → 831dc0187f71e658550c.js} +1 -1
  16. package/assets/esri/core/workers/chunks/{d162d1b7b97a58e97d8c.js → 8958cd555f4887526e8b.js} +1 -1
  17. package/assets/esri/core/workers/chunks/{e57b71ba70f088a3a052.js → 90dcd86cdef90099abfa.js} +1 -1
  18. package/assets/esri/core/workers/chunks/{a5b54e134ae59629d6d1.js → 93067e27eea5844edc6c.js} +1 -1
  19. package/assets/esri/core/workers/chunks/{0b63c9d5d9c004923a97.js → b26bd8fde2fc65bb67fb.js} +1 -1
  20. package/assets/esri/core/workers/chunks/{b81e1df3a47b61421295.js → b34ba22c7a5adce8a7a2.js} +1 -1
  21. package/assets/esri/core/workers/chunks/c28f7ae4756ad1ba94bd.js +1 -0
  22. package/assets/esri/core/workers/chunks/{e1408ff1b8343674e6ef.js → c59b0b58e24e6a60cf3e.js} +1 -1
  23. package/assets/esri/core/workers/chunks/{f4e79769297ad9c1d508.js → c7cee13a962396b23a5e.js} +1 -1
  24. package/assets/esri/core/workers/chunks/{cb38754110b7a0e901f6.js → cd3679fa86129ebabfdf.js} +1 -1
  25. package/assets/esri/core/workers/chunks/{224c0e64160bdc170051.js → d076627bb7dadea89e89.js} +1 -1
  26. package/assets/esri/core/workers/chunks/e06ad3a3d71154fed654.js +1 -0
  27. package/assets/esri/core/workers/chunks/{7a77d4cd27c30f1a5cae.js → ee3387a43dfbb3df23e1.js} +1 -1
  28. package/assets/esri/core/workers/chunks/{fbb7a121a45f8ca7d89c.js → f4fc165420d449e442b8.js} +1 -1
  29. package/assets/esri/themes/base/widgets/_Widget.scss +2 -2
  30. package/assets/esri/themes/dark/main.css +1 -1
  31. package/assets/esri/themes/dark-blue/main.css +1 -1
  32. package/assets/esri/themes/dark-green/main.css +1 -1
  33. package/assets/esri/themes/dark-purple/main.css +1 -1
  34. package/assets/esri/themes/dark-red/main.css +1 -1
  35. package/assets/esri/themes/light/main.css +1 -1
  36. package/assets/esri/themes/light/view.css +1 -1
  37. package/assets/esri/themes/light-blue/main.css +1 -1
  38. package/assets/esri/themes/light-green/main.css +1 -1
  39. package/assets/esri/themes/light-purple/main.css +1 -1
  40. package/assets/esri/themes/light-red/main.css +1 -1
  41. package/core/AsyncUpdate.js +1 -1
  42. package/exports/csv.js +1 -1
  43. package/geometry/support/meshUtils/exporters/gltf/geometry.js +1 -1
  44. package/geometry/support/normalizeUtils.js +1 -1
  45. package/interfaces.d.ts +120 -0
  46. package/layers/MapImageLayer.js +1 -1
  47. package/layers/RouteLayer.js +1 -1
  48. package/layers/VectorTileLayer.js +1 -1
  49. package/layers/graphics/editingSupport.js +1 -1
  50. package/layers/mixins/ArcGISImageService.js +1 -1
  51. package/layers/support/RasterJobHandler.js +1 -1
  52. package/layers/support/SpriteSource.js +1 -1
  53. package/layers/support/Sublayer.js +1 -1
  54. package/layers/support/TilemapCache.js +1 -1
  55. package/layers/support/vectorTileLayerLoader.js +1 -1
  56. package/libs/i3s/I3SModule.js +1 -1
  57. package/libs/vxl/VxlModule.js +1 -1
  58. package/package.json +1 -1
  59. package/portal/support/layersLoader.js +1 -1
  60. package/portal/support/portalLayers.js +1 -1
  61. package/renderers/support/DictionaryLoader.js +1 -1
  62. package/rest/query/operations/query.js +1 -1
  63. package/rest/query/operations/queryTopFeatures.js +1 -1
  64. package/rest/support/DirectionLine.js +1 -1
  65. package/rest/support/DirectionPoint.js +1 -1
  66. package/rest/support/PointBarrier.js +1 -1
  67. package/rest/support/PolygonBarrier.js +1 -1
  68. package/rest/support/PolylineBarrier.js +1 -1
  69. package/rest/support/RouteInfo.js +1 -1
  70. package/rest/support/Stop.js +1 -1
  71. package/smartMapping/labels/clusters.js +1 -1
  72. package/smartMapping/renderers/color.js +1 -1
  73. package/smartMapping/support/adapters/SceneLayerAdapter.js +1 -1
  74. package/support/elevationInfoUtils.js +1 -1
  75. package/support/revision.js +1 -1
  76. package/symbols/support/previewSymbol3D.js +1 -1
  77. package/symbols/support/symbolLayerUtils.js +1 -1
  78. package/views/2d/engine/vectorTiles/TileParser.js +1 -1
  79. package/views/2d/engine/webgl/util/Lock.js +1 -1
  80. package/views/2d/layers/RouteLayerView2D.js +1 -1
  81. package/views/2d/layers/features/support/AttributeStore.js +1 -1
  82. package/views/2d/layers/features/support/FeatureSetReaderPBF.js +1 -1
  83. package/views/2d/layers/support/webStyleUtils.js +1 -1
  84. package/views/3d/analysis/LineOfSight/LineOfSightController.js +1 -1
  85. package/views/3d/analysis/LineOfSight/LineOfSightIntersectionResult.js +1 -1
  86. package/views/3d/analysis/LineOfSight/LineOfSightRayIntersector.js +1 -1
  87. package/views/3d/interactive/analysisTools/lineOfSight/LineOfSightTool.js +1 -1
  88. package/views/3d/layers/BuildingComponentSublayerView3D.js +1 -1
  89. package/views/3d/layers/FeatureLikeLayerView3D.js +1 -1
  90. package/views/3d/layers/ImageryLayerView3D.js +1 -1
  91. package/views/3d/layers/RouteLayerView3D.js +1 -1
  92. package/views/3d/layers/SceneLayerGraphicsView3D.js +1 -1
  93. package/views/3d/layers/i3s/I3SNodeLoader.js +1 -1
  94. package/views/3d/layers/support/PopupSceneLayerView.js +1 -1
  95. package/views/3d/support/debugFlags.js +1 -1
  96. package/views/3d/terrain/TerrainSurface.js +1 -1
  97. package/views/3d/webgl-engine/lib/Renderer.js +1 -1
  98. package/views/SceneView.js +1 -1
  99. package/views/layers/ImageryTileLayerView.js +1 -1
  100. package/views/layers/MapImageLayerView.js +1 -1
  101. package/views/layers/TileLayerView.js +1 -1
  102. package/views/support/DefaultsFromMap.js +1 -1
  103. package/widgets/Bookmarks/BookmarksViewModel.js +1 -1
  104. package/widgets/CoordinateConversion/CoordinateConversionViewModel.js +1 -1
  105. package/widgets/Directions/DirectionsViewModel.js +1 -1
  106. package/widgets/Directions.js +1 -1
  107. package/widgets/Editor.js +1 -1
  108. package/widgets/Feature/support/featureUtils.js +1 -1
  109. package/widgets/FeatureForm/InputField.js +1 -1
  110. package/widgets/FeatureTable/support/FeatureStore.js +1 -1
  111. package/widgets/FloorFilter/FloorFilterViewModel.js +1 -1
  112. package/widgets/Legend/support/ActiveLayerInfo.js +1 -1
  113. package/widgets/Popup/actionUtils.js +1 -1
  114. package/widgets/Search/SearchViewModel.js +1 -1
  115. package/assets/esri/core/workers/chunks/113362697da1b69deaed.js +0 -1
  116. package/assets/esri/core/workers/chunks/1e590d63187ada4f5ff7.js +0 -1
  117. package/assets/esri/core/workers/chunks/391a330182c616cfffaf.js +0 -1
  118. package/assets/esri/core/workers/chunks/3a85312fd7d0cda9ce93.js +0 -1
  119. package/assets/esri/core/workers/chunks/3c00e38d3b16f4a53a4f.js +0 -1
  120. package/assets/esri/core/workers/chunks/4a82a6a473b3d540d0be.js +0 -1
  121. package/assets/esri/core/workers/chunks/5b4d9786c010d265346c.js +0 -1
  122. package/assets/esri/core/workers/chunks/bbfc98e33d4630eb9e5c.js +0 -1
  123. package/assets/esri/core/workers/chunks/bd725783b85f308e2c89.js +0 -1
  124. package/assets/esri/core/workers/chunks/d343f05a3366f95e0494.js +0 -1
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.24/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../chunks/tslib.es6.js";import"../../intl.js";import t from"../../core/Accessor.js";import{HandleOwnerMixin as i}from"../../core/HandleOwner.js";import{isSome as l,isNone as r,get as n}from"../../core/maybe.js";import{watch as o}from"../../core/reactiveUtils.js";import{generateUID as s}from"../../core/uid.js";import{property as a}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{subclass as u}from"../../core/accessorSupport/decorators/subclass.js";import d from"../../layers/support/CodedValueDomain.js";import"../../layers/support/Domain.js";import"../../layers/support/InheritedDomain.js";import"../../layers/support/RangeDomain.js";import{validateDomainValue as p,DomainValidationError as c,getDomainRange as m}from"../../layers/support/domainUtils.js";import{isNumericField as h,isStringField as y,isDateField as v,TypeValidationError as f,validateFieldValue as g,getFeatureEditFields as E,getFeatureGeometryFields as b,NumericRangeValidationError as _,getFieldRange as x}from"../../layers/support/fieldUtils.js";import{substitute as F}from"../../intl/substitute.js";var V,O;!function(e){e.Text="text",e.Number="number",e.Date="date",e.Unsupported="unsupported"}(V||(V={})),function(e){e.TOO_SHORT="length-validation-error::too-short"}(O||(O={}));const U={type:"number"},T={type:"number",intlOptions:{notation:"scientific"}},j={type:"date",intlOptions:{day:"2-digit",month:"2-digit",year:"numeric",hour:"numeric",minute:"numeric",second:"numeric"}};function A(e){return e>=1e7||e<=-1e7}let D=class extends(i(t)){constructor(e){super(e),this._storedValue=null,this.arcade=null,this.editableFunction=null,this.id=s().toString(),this.requiredFunction=null,this.valueFunction=null,this.visibilityFunction=null,this.feature=null,this.field=null,this.fieldElement=null,this.layer=null,this.description=null,this.inputType=null,this.error=null,this.group=null,this.hint=null,this.messages=null,this.name=null}initialize(){this.handles.add(o((()=>this.value),((e,t)=>{if(e!==t){const{feature:e,name:t,value:i}=this;e.setAttribute(t,i)}})))}get _configAllowsEdits(){var e,t,i;const{fieldElement:r,layer:n,name:o}=this;if(l(r))return!1!==r.editable;const s="subtype-group"!==(null==n?void 0:n.type)?null==n||null==(e=n.popupTemplate)||null==(t=e.fieldInfos)?void 0:t.find((({fieldName:e})=>e===o)):null;return null==(i=null==s?void 0:s.isEditable)||i}get _layerFieldAllowsEdits(){const{field:e,layer:t}=this;return(null==t?void 0:t.capabilities.operations.supportsEditing)&&(null==e?void 0:e.editable)}get isUsingValueExpression(){return this._shouldUseValueExpression()}get evaluatedEditableExpression(){const{editableFunction:e}=this;if(r(e))return null;const{arcade:t}=this;return t.arcadeUtils.executeFunction(e,t.arcadeUtils.createExecContext(this.feature))}get evaluatedRequiredExpression(){const{requiredFunction:e}=this;if(r(e))return null;const{arcade:t}=this;return t.arcadeUtils.executeFunction(e,t.arcadeUtils.createExecContext(this.feature))}get evaluatedVisibilityExpression(){const{visibilityFunction:e}=this;if(r(e))return null;const{arcade:t}=this;return t.arcadeUtils.executeFunction(e,t.arcadeUtils.createExecContext(this.feature))}get evaluatedValueExpression(){const{valueFunction:e}=this;if(r(e))return null;const{arcade:t}=this;return t.arcadeUtils.executeFunction(e,t.arcadeUtils.createExecContext(this.feature))}set initialFeature(e){this._set("initialFeature",e),this.notifyChange("valid")}get domain(){var e;const{typeIdField:t}=this.layer,i=t===this.name,r=null==(e=this.field)?void 0:e.domain;if(i&&!r){const{layer:e}=this,t="subtype-group"===e.type?e.sublayers.map((({subtypeCode:e,title:t})=>({id:e,name:t}))):e.types.map((({id:e,name:t})=>({code:e,name:t})));return new d({name:"__internal-type-based-coded-value-domain__",codedValues:t})}const{feature:o}=this,s=t&&this.layer.getFieldDomain(this.name,{feature:o})||r,a=n(this.fieldElement,"domain");return l(a)&&this._isDomainCompatible(a)?a:s}get editable(){var e;return!!this._layerFieldAllowsEdits&&(null!=(e=this.evaluatedEditableExpression)?e:this._configAllowsEdits)}get errorMessage(){return this._toErrorMessage()}get includeTime(){var e;const{fieldElement:t}=this,i=l(t)&&"datetime-picker"===(null==(e=t.input)?void 0:e.type)?t.input.includeTime:void 0;return void 0===i||i}get label(){return l(this.fieldElement)&&this.fieldElement.label||this.field.alias||this.field.name}get maxLength(){const e=-1;if(this.type===V.Date)return e;const{field:t,fieldElement:i}=this,r=null==t?void 0:t.length,n=l(i)&&N(i.input)?i.input.maxLength:NaN;return!isNaN(n)&&n>=e&&(r===e||n<=r)?n:r}get minLength(){const e=-1;if(this.type===V.Date)return e;const{field:t,fieldElement:i}=this,r=null==t?void 0:t.length,n=l(i)&&N(i.input)?i.input.minLength:NaN;return!isNaN(n)&&n>=e&&(r===e||n<=r)?n:e}get required(){var e,t;return!!this.editable&&(!1===(null==(e=this.field)?void 0:e.nullable)||null!=(t=this.evaluatedRequiredExpression)&&t)}get submittable(){return!!this.valid||this.initialFeature.getAttribute(this.field.name)===this.value}get type(){const{field:e}=this;return h(e)?V.Number:y(e)?V.Text:v(e)?V.Date:V.Unsupported}get valid(){const e=this._validate();return this._set("error",e),null===e}get value(){return this._shouldUseValueExpression()?this.evaluatedValueExpression:this.get("_storedValue")}set value(e){this.notifyChange("evaluatedVisibilityExpression"),this.set("_storedValue",e)}get visible(){return!this._isEditorField()&&(l(this.fieldElement)?null==(e=this.evaluatedVisibilityExpression)||e:this._isVisibleByDefault());var e}_isDomainCompatible(e){const{field:t}=this;if("coded-value"===(null==e?void 0:e.type)){const i=typeof e.codedValues[0].code;if("string"===i&&y(t)||"number"===i&&h(t))return!0}return!!("range"===(null==e?void 0:e.type)&&h(t)||v(t))}_validate(){const{domain:e,field:t,initialFeature:i,minLength:l,required:r,type:n,valid:o,value:s}=this,a=r&&null===s,u=void 0!==o;return!a&&i.getAttribute(t.name)===s&&u?null:"text"===n&&l>-1&&"string"==typeof s&&s.length<l?O.TOO_SHORT:e?null!==s||r?p(e,s):null:a?f.INVALID_TYPE:g(t,s)}_isVisibleByDefault(){var e;const t=null==(e=this.field)?void 0:e.type;return"oid"!==t&&"global-id"!==t&&!this._isGeometryField()}_isEditorField(){return E(this.layer).includes(this.name)}_isGeometryField(){return b(this.layer).includes(this.name)}_shouldUseValueExpression(){return this._layerFieldAllowsEdits&&!this._configAllowsEdits&&l(this.valueFunction)}_toErrorMessage(){const{domain:e,field:t,messages:i,minLength:l,value:r,required:n,type:o}=this,s=this.error;if(n&&null===r)return i.validationErrors.cannotBeNull;if(s===c.VALUE_OUT_OF_RANGE||s===_.OUT_OF_RANGE){const l=m(e)||x(t);return F(i.validationErrors.outsideRange,l,{format:{max:"date"===o?j:A(l.max)?T:U,min:"date"===o?j:A(l.min)?T:U}})}return s===c.INVALID_CODED_VALUE?i.validationErrors.invalidCodedValue:s===f.INVALID_TYPE?i.validationErrors.invalidType:s===O.TOO_SHORT?F(i.validationErrors.tooShort,{min:l}):null}};function N(e){return!!e&&"maxLength"in e}e([a()],D.prototype,"_storedValue",void 0),e([a()],D.prototype,"_configAllowsEdits",null),e([a()],D.prototype,"_layerFieldAllowsEdits",null),e([a()],D.prototype,"arcade",void 0),e([a()],D.prototype,"editableFunction",void 0),e([a()],D.prototype,"requiredFunction",void 0),e([a()],D.prototype,"valueFunction",void 0),e([a()],D.prototype,"isUsingValueExpression",null),e([a()],D.prototype,"visibilityFunction",void 0),e([a()],D.prototype,"evaluatedEditableExpression",null),e([a()],D.prototype,"evaluatedRequiredExpression",null),e([a()],D.prototype,"evaluatedVisibilityExpression",null),e([a()],D.prototype,"evaluatedValueExpression",null),e([a()],D.prototype,"feature",void 0),e([a()],D.prototype,"field",void 0),e([a()],D.prototype,"fieldElement",void 0),e([a()],D.prototype,"initialFeature",null),e([a()],D.prototype,"layer",void 0),e([a({aliasOf:"fieldElement.description"})],D.prototype,"description",void 0),e([a()],D.prototype,"domain",null),e([a()],D.prototype,"editable",null),e([a({aliasOf:"fieldElement.input.type"})],D.prototype,"inputType",void 0),e([a({readOnly:!0})],D.prototype,"error",void 0),e([a({dependsOn:["error","messages","value"]})],D.prototype,"errorMessage",null),e([a()],D.prototype,"group",void 0),e([a({aliasOf:"fieldElement.hint"})],D.prototype,"hint",void 0),e([a()],D.prototype,"includeTime",null),e([a()],D.prototype,"label",null),e([a()],D.prototype,"maxLength",null),e([a()],D.prototype,"minLength",null),e([a()],D.prototype,"messages",void 0),e([a({aliasOf:"field.name"})],D.prototype,"name",void 0),e([a()],D.prototype,"required",null),e([a()],D.prototype,"submittable",null),e([a()],D.prototype,"type",null),e([a()],D.prototype,"valid",null),e([a({value:null})],D.prototype,"value",null),e([a()],D.prototype,"visible",null),D=e([u("esri.widgets.FeatureForm.InputField")],D);const L=D;export{L as default};
5
+ import{_ as e}from"../../chunks/tslib.es6.js";import"../../intl.js";import t from"../../core/Accessor.js";import{HandleOwnerMixin as i}from"../../core/HandleOwner.js";import{isSome as l,isNone as r,get as n}from"../../core/maybe.js";import{watch as o}from"../../core/reactiveUtils.js";import{generateUID as s}from"../../core/uid.js";import{property as a}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{subclass as u}from"../../core/accessorSupport/decorators/subclass.js";import d from"../../layers/support/CodedValueDomain.js";import"../../layers/support/Domain.js";import"../../layers/support/InheritedDomain.js";import"../../layers/support/RangeDomain.js";import{validateDomainValue as p,DomainValidationError as c,getDomainRange as h}from"../../layers/support/domainUtils.js";import{isNumericField as m,isStringField as y,isDateField as v,TypeValidationError as f,validateFieldValue as g,getFeatureEditFields as E,getFeatureGeometryFields as b,NumericRangeValidationError as _,getFieldRange as x}from"../../layers/support/fieldUtils.js";import{substitute as F}from"../../intl/substitute.js";var V,O;!function(e){e.Text="text",e.Number="number",e.Date="date",e.Unsupported="unsupported"}(V||(V={})),function(e){e.TOO_SHORT="length-validation-error::too-short"}(O||(O={}));const U={type:"number"},T={type:"number",intlOptions:{notation:"scientific"}},j={type:"date",intlOptions:{day:"2-digit",month:"2-digit",year:"numeric",hour:"numeric",minute:"numeric",second:"numeric"}};function A(e){return e>=1e7||e<=-1e7}let D=class extends(i(t)){constructor(e){super(e),this._storedValue=null,this.arcade=null,this.editableFunction=null,this.id=s().toString(),this.requiredFunction=null,this.valueFunction=null,this.visibilityFunction=null,this.feature=null,this.field=null,this.fieldElement=null,this.layer=null,this.description=null,this.inputType=null,this.error=null,this.group=null,this.hint=null,this.messages=null,this.name=null}initialize(){this.handles.add(o((()=>this.value),((e,t)=>{if(e!==t){const{feature:e,name:t,value:i}=this;e.setAttribute(t,i)}})))}get _configAllowsEdits(){var e,t,i;const{fieldElement:r,layer:n,name:o}=this;if(l(r))return!1!==r.editable;const s="subtype-group"!==(null==n?void 0:n.type)?null==n||null==(e=n.popupTemplate)||null==(t=e.fieldInfos)?void 0:t.find((({fieldName:e})=>e===o)):null;return null==(i=null==s?void 0:s.isEditable)||i}get _layerFieldAllowsEdits(){const{field:e,layer:t}=this;return(null==t?void 0:t.capabilities.operations.supportsEditing)&&(null==e?void 0:e.editable)}get isUsingValueExpression(){return this._shouldUseValueExpression()}get evaluatedEditableExpression(){const{editableFunction:e}=this;if(r(e))return null;const{arcade:t}=this;return t.arcadeUtils.executeFunction(e,t.arcadeUtils.createExecContext(this.feature))}get evaluatedRequiredExpression(){const{requiredFunction:e}=this;if(r(e))return null;const{arcade:t}=this;return t.arcadeUtils.executeFunction(e,t.arcadeUtils.createExecContext(this.feature))}get evaluatedVisibilityExpression(){const{visibilityFunction:e}=this;if(r(e))return null;const{arcade:t}=this;return t.arcadeUtils.executeFunction(e,t.arcadeUtils.createExecContext(this.feature))}get evaluatedValueExpression(){const{valueFunction:e}=this;if(r(e))return null;const{arcade:t}=this;return t.arcadeUtils.executeFunction(e,t.arcadeUtils.createExecContext(this.feature))}set initialFeature(e){this._set("initialFeature",e),this.notifyChange("valid")}get domain(){var e;const{typeIdField:t}=this.layer,i=t===this.name,r=null==(e=this.field)?void 0:e.domain;if(i&&!r){const{layer:e}=this,t="subtype-group"===e.type?e.sublayers.map((({subtypeCode:e,title:t})=>({id:e,name:t}))):e.types.map((({id:e,name:t})=>({code:e,name:t})));return new d({name:"__internal-type-based-coded-value-domain__",codedValues:t})}const{feature:o}=this,s=t&&this.layer.getFieldDomain(this.name,{feature:o})||r,a=n(this.fieldElement,"domain");return l(a)&&this._isDomainCompatible(a)?a:s}get editable(){var e;return!!this._layerFieldAllowsEdits&&(null!=(e=this.evaluatedEditableExpression)?e:this._configAllowsEdits)}get errorMessage(){return this._toErrorMessage()}get includeTime(){var e;const{fieldElement:t}=this,i=l(t)&&"datetime-picker"===(null==(e=t.input)?void 0:e.type)?t.input.includeTime:void 0;return void 0===i||i}get label(){return l(this.fieldElement)&&this.fieldElement.label||this.field.alias||this.field.name}get maxLength(){const e=-1;if(this.type===V.Date)return e;const{field:t,fieldElement:i}=this,r=null==t?void 0:t.length,n=l(i)&&N(i.input)?i.input.maxLength:NaN;return!isNaN(n)&&n>=e&&(r===e||n<=r)?n:r}get minLength(){const e=-1;if(this.type===V.Date)return e;const{field:t,fieldElement:i}=this,r=null==t?void 0:t.length,n=l(i)&&N(i.input)?i.input.minLength:NaN;return!isNaN(n)&&n>=e&&(r===e||n<=r)?n:e}get required(){var e,t;return!!this.editable&&(!1===(null==(e=this.field)?void 0:e.nullable)||null!=(t=this.evaluatedRequiredExpression)&&t)}get submittable(){return!!this.valid||this.initialFeature.getAttribute(this.field.name)===this.value}get type(){const{field:e}=this;return m(e)?V.Number:y(e)?V.Text:v(e)?V.Date:V.Unsupported}get valid(){const e=this.editable?this._validate():null;return this._set("error",e),null===e}get value(){return this._shouldUseValueExpression()?this.evaluatedValueExpression:this.get("_storedValue")}set value(e){this.notifyChange("evaluatedVisibilityExpression"),this.set("_storedValue",e)}get visible(){return!this._isEditorField()&&(l(this.fieldElement)?null==(e=this.evaluatedVisibilityExpression)||e:this._isVisibleByDefault());var e}_isDomainCompatible(e){const{field:t}=this;if("coded-value"===(null==e?void 0:e.type)){const i=typeof e.codedValues[0].code;if("string"===i&&y(t)||"number"===i&&m(t))return!0}return!!("range"===(null==e?void 0:e.type)&&m(t)||v(t))}_validate(){const{domain:e,field:t,initialFeature:i,minLength:l,required:r,type:n,valid:o,value:s}=this,a=r&&null===s,u=void 0!==o;return!a&&i.getAttribute(t.name)===s&&u?null:"text"===n&&l>-1&&"string"==typeof s&&s.length<l?O.TOO_SHORT:e?null!==s||r?p(e,s):null:a?f.INVALID_TYPE:g(t,s)}_isVisibleByDefault(){var e;const t=null==(e=this.field)?void 0:e.type;return"oid"!==t&&"global-id"!==t&&!this._isGeometryField()}_isEditorField(){return E(this.layer).includes(this.name)}_isGeometryField(){return b(this.layer).includes(this.name)}_shouldUseValueExpression(){return this._layerFieldAllowsEdits&&!this._configAllowsEdits&&l(this.valueFunction)}_toErrorMessage(){const{domain:e,field:t,messages:i,minLength:l,value:r,required:n,type:o}=this,s=this.error;if(n&&null===r)return i.validationErrors.cannotBeNull;if(s===c.VALUE_OUT_OF_RANGE||s===_.OUT_OF_RANGE){const l=h(e)||x(t);return F(i.validationErrors.outsideRange,l,{format:{max:"date"===o?j:A(l.max)?T:U,min:"date"===o?j:A(l.min)?T:U}})}return s===c.INVALID_CODED_VALUE?i.validationErrors.invalidCodedValue:s===f.INVALID_TYPE?i.validationErrors.invalidType:s===O.TOO_SHORT?F(i.validationErrors.tooShort,{min:l}):null}};function N(e){return!!e&&"maxLength"in e}e([a()],D.prototype,"_storedValue",void 0),e([a()],D.prototype,"_configAllowsEdits",null),e([a()],D.prototype,"_layerFieldAllowsEdits",null),e([a()],D.prototype,"arcade",void 0),e([a()],D.prototype,"editableFunction",void 0),e([a()],D.prototype,"requiredFunction",void 0),e([a()],D.prototype,"valueFunction",void 0),e([a()],D.prototype,"isUsingValueExpression",null),e([a()],D.prototype,"visibilityFunction",void 0),e([a()],D.prototype,"evaluatedEditableExpression",null),e([a()],D.prototype,"evaluatedRequiredExpression",null),e([a()],D.prototype,"evaluatedVisibilityExpression",null),e([a()],D.prototype,"evaluatedValueExpression",null),e([a()],D.prototype,"feature",void 0),e([a()],D.prototype,"field",void 0),e([a()],D.prototype,"fieldElement",void 0),e([a()],D.prototype,"initialFeature",null),e([a()],D.prototype,"layer",void 0),e([a({aliasOf:"fieldElement.description"})],D.prototype,"description",void 0),e([a()],D.prototype,"domain",null),e([a()],D.prototype,"editable",null),e([a({aliasOf:"fieldElement.input.type"})],D.prototype,"inputType",void 0),e([a({readOnly:!0})],D.prototype,"error",void 0),e([a({dependsOn:["error","messages","value"]})],D.prototype,"errorMessage",null),e([a()],D.prototype,"group",void 0),e([a({aliasOf:"fieldElement.hint"})],D.prototype,"hint",void 0),e([a()],D.prototype,"includeTime",null),e([a()],D.prototype,"label",null),e([a()],D.prototype,"maxLength",null),e([a()],D.prototype,"minLength",null),e([a()],D.prototype,"messages",void 0),e([a({aliasOf:"field.name"})],D.prototype,"name",void 0),e([a()],D.prototype,"required",null),e([a()],D.prototype,"submittable",null),e([a()],D.prototype,"type",null),e([a()],D.prototype,"valid",null),e([a({value:null})],D.prototype,"value",null),e([a()],D.prototype,"visible",null),D=e([u("esri.widgets.FeatureForm.InputField")],D);const L=D;export{L as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.24/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Graphic.js";import r from"../../../core/Accessor.js";import{equals as s,remove as i}from"../../../core/arrayUtils.js";import a from"../../../core/Collection.js";import o from"../../../core/Error.js";import{clone as n}from"../../../core/lang.js";import u from"../../../core/Logger.js";import{property as h}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as y}from"../../../core/accessorSupport/decorators/subclass.js";import c from"../../../rest/support/AttachmentQuery.js";const l="esri.widgets.FeatureTable.support.FeatureStore",d=u.getLogger(l);function p(e,t,r){d.error(new o(e,t,r))}let m=class extends r{constructor(e){super(e),this._loaded=!1,this._loadError=!1,this._loading=!1,this._editOperationQueue=[],this._queryOperationQueue=[],this._objectIdCache=new a,this._hasStaleCache=!1,this.count=0,this.failures=new a,this.itemCache=new a,this.relatedRecordsEnabled=!1}destroy(){this.layer=null,this.itemCache&&this.itemCache.destroy(),this.failures&&this.failures.destroy(),this._set("itemCache",null)}set attachmentsEnabled(e){this._reset(),this._set("attachmentsEnabled",e),this.notifyChange("state")}set filterGeometry(e){this._reset(),this._set("filterGeometry",e),this.notifyChange("state")}set layer(e){this._reset(),this._set("layer",e),this.notifyChange("state")}set objectIds(e){this._reset(),this._set("objectIds",e||null),this.notifyChange("state")}get orderByFields(){return this._get("orderByFields")||[]}set orderByFields(e){const t=this.orderByFields;s(e,t)||(this.itemCache.removeAll(),this._hasStaleCache=!0,this._set("orderByFields",e))}get querying(){return this._queryOperationQueue.length>0}set returnGeometry(e){this._reset(),this._set("returnGeometry",e),this.notifyChange("state")}get state(){const{layer:e,_loaded:t,_loadError:r,_loading:s}=this;return r?"error":!e||this.get("layer.loadError")?"disabled":s?"loading":"loaded"===this.get("layer.loadStatus")&&t?"loaded":"ready"}get syncing(){return this._editOperationQueue.length>0}get where(){return this._get("where")||null}set where(e){this._reset(),this._set("where",e),this.notifyChange("state")}async load(){this._reset();const{layer:e}=this;if(!e)return Promise.resolve();this._loading=!0,this.notifyChange("state");try{await e.when(),await this._syncLayerInfo(),this._loading=!1,this._loaded=!0,this.notifyChange("state")}catch(t){throw this._reset(),this._loadError=!0,this.notifyChange("state"),p("store:load-error","An error ocurred.",{error:t}),t}}async refreshLayerInfo(){return this._syncLayerInfo()}async addItems(e){}async fetchItems(e){const{page:t,pageSize:r}=e,s=t*r,i=s+r,{layer:a,state:o}=this;if(!a||"loaded"!==o)return Promise.resolve([]);this.notifyChange("querying");const n=await this._query({start:s,num:i,page:t,pageSize:r});return this.notifyChange("state"),n}async verifyFeaturesByObjectId(e){const{layer:t,state:r}=this;if(!t||"loaded"!==r)return Promise.resolve([]);const{features:s}=await this._verifyFeaturesByObjectId(e);return e.map((e=>!!s.find((t=>(null==t?void 0:t.getObjectId())===e))))}async query(e){const{layer:t,state:r}=this;if(!t||"loaded"!==r)return[];this.notifyChange("querying");const s=await this._query(e);return this.notifyChange("state"),s}async removeItemAt(e){}async reset(){this._reset()}async updateItem(e){return this._update(e)}getItemByObjectId(e){const{itemCache:t,layer:{objectIdField:r}}=this;return t.find((t=>t.feature.attributes[r]===e))}getLocalItemAt(e){return this.itemCache.getItemAt(e)}getItemAt(e){return Promise.resolve(this.itemCache.getItemAt(e))}getObjectIdIndex(e){const{itemCache:t,layer:{objectIdField:r}}=this;return t.findIndex((t=>t.feature.attributes[r]===e))}_reset(){this.itemCache.removeAll(),this.failures.removeAll(),this._editOperationQueue=[],this._queryOperationQueue=[],this._hasStaleCache=!1,this._loading=!1,this._loaded=!1,this._loadError=!1,this._set("count",0),this._objectIdCache.removeAll(),this.notifyChange("querying"),this.notifyChange("syncing"),this.notifyChange("state")}_getIdsFromFeatures(e){return e.map((e=>e.attributes[this.layer.objectIdField]))}_toFeatureData(e,t){const{layer:{objectIdField:r}}=this;return e.map((e=>{const{attributes:s}=e,i=s[r];return{objectId:i,feature:e,attachments:t?t[i]:null,relatedRecords:null}}))}async _update(e){const{layer:r}=this,{operations:s}=r.capabilities;if(!s.supportsUpdate||!("applyEdits"in r))throw new o("store:update-error","Update is not supported.");const{index:i,name:a,value:u}=e,h=await this.getItemAt(i);if(!h||!h.feature)throw new o("store:update-error","Feature with provided 'objectId' not found.");const{feature:y}=h,c=n(y.attributes);c[a]=u;const l=new t({attributes:c}),d=r.applyEdits({updateFeatures:[l]}).then((e=>{const{updateFeatureResults:t}=e,r=t.find((e=>!!e.error));if(r)throw r.error;return t.length&&(y.attributes=c),e}));return this._queueEditOperation((()=>d))}async _query(e){const{refresh:t}=e;return!0===t?(this.itemCache.removeAll(),this._syncLayerInfo().then((()=>this._queryFeatureData(e)))):(this._hasStaleCache&&(await this._updateIds(),this._hasStaleCache=!1),this._queryFeatureData(e))}async _queryFeatureData(e){return this._queueQueryOperation((async()=>{const{features:t}=await this._queryFeatures(e),r=this._getIdsFromFeatures(t),s=await this._queryAttachments(r);return this._toFeatureData(t,s)||[]}))}async _syncLayerInfo(){await this._updateCount(),await this._updateIds()}async _updateCount(){await this._queryCount().then((e=>this._set("count",e)))}async _updateIds(){var e,t,r;null!=(e=this.layer)&&null!=(t=e.capabilities)&&null!=(r=t.query)&&r.supportsPagination||(this._objectIdCache.removeAll(),await this._queryForObjectIds().then((e=>this._objectIdCache.addMany(e))))}_queryCount(){const{filterGeometry:e,layer:t}=this,{capabilities:{query:{supportsCacheHint:r}}}=t,s=t.createQuery();return s.geometry=e,s.returnGeometry=!1,s.where=this._getWhere(),s.objectIds=this.objectIds,r&&(s.cacheHint=!0),t.queryFeatureCount(s)}_queryForObjectIds(){const{filterGeometry:e,layer:t,orderByFields:r}=this,{capabilities:{query:{supportsCacheHint:s,supportsOrderBy:i}}}=t,a=t.createQuery();return a.geometry=e,a.outFields=[t.objectIdField],a.returnGeometry=!1,a.where=this._getWhere(),a.objectIds=this.objectIds,i&&(a.orderByFields=r),s&&(a.cacheHint=!0),t.queryObjectIds(a)}async _queryFeatures(e){const{layer:t}=this;if(!t.capabilities.operations.supportsQuery)return Promise.reject(new o("store:query-error","Layer does not support query operation."));const{filterGeometry:r,layer:{capabilities:{query:{supportsCacheHint:s,supportsOrderBy:i,supportsPagination:a}}},orderByFields:n,returnGeometry:u}=this,{start:h,pageSize:y}=e,c=t.createQuery();return c.returnGeometry=u,a?(c.start=h,c.num=y,c.where=this._getWhere(),c.objectIds=this.objectIds):c.objectIds=this.objectIds||this._getObjectIdsForPage(h,y),i&&(c.orderByFields=n),r&&(c.geometry=r),s&&(c.cacheHint=!0),t.queryFeatures(c)}async _verifyFeaturesByObjectId(e){const{layer:t}=this;if(!t.capabilities.operations.supportsQuery)return Promise.reject(new o("store:query-error","Layer does not support query operation."));const{filterGeometry:r,layer:{capabilities:{query:{supportsCacheHint:s,supportsOrderBy:i}}},orderByFields:a}=this,n=t.createQuery();return n.where=this._getWhere(),n.returnGeometry=!1,n.objectIds=e,n.outFields=[t.objectIdField],i&&(n.orderByFields=a),r&&(n.geometry=r),s&&(n.cacheHint=!0),t.queryFeatures(n)}_getObjectIdsForPage(e,t){const r=this._objectIdCache.toArray();return r.length>=e+t?r.slice(e,e+t):r.slice(e)}_queryAttachments(e){const{attachmentsEnabled:t,layer:r}=this,{capabilities:{data:{supportsAttachment:s},operations:{supportsQueryAttachments:i}}}=r;return t&&s&&i&&"queryAttachments"in r?r.queryAttachments(new c({objectIds:e,where:this._getWhere()})):Promise.resolve(null)}_queueQueryOperation(e){return this._queryOperationQueue.push(e),this.notifyChange("querying"),e().then((t=>this._queryOperationQueue.includes(e)?(this.itemCache.addMany(t),t):[])).catch((t=>{p("store:query-error","An error ocurred.",{error:t});const r={error:t,retry:()=>{this.failures.remove(r),this._queueQueryOperation(e)},cancel:()=>this.failures.remove(r)};return this.failures.add(r),[]})).then((t=>(i(this._queryOperationQueue,e),this.notifyChange("querying"),t)))}_queueEditOperation(e){return this._editOperationQueue.push(e),this.notifyChange("syncing"),e().then((()=>{i(this._editOperationQueue,e),this.notifyChange("syncing")})).catch((t=>{p("store:edit-error","An error ocurred.",{error:t});const r={error:t,retry:()=>{this.failures.remove(r),this._queueEditOperation(e)},cancel:()=>this.failures.remove(r)};throw this.failures.add(r),i(this._editOperationQueue,e),this.notifyChange("syncing"),t}))}_getWhere(){return this.where||this.layer.definitionExpression||"1=1"}};e([h()],m.prototype,"attachmentsEnabled",null),e([h({readOnly:!0})],m.prototype,"count",void 0),e([h({readOnly:!0})],m.prototype,"failures",void 0),e([h()],m.prototype,"filterGeometry",null),e([h({readOnly:!0})],m.prototype,"itemCache",void 0),e([h({value:null})],m.prototype,"layer",null),e([h({value:null})],m.prototype,"objectIds",null),e([h()],m.prototype,"orderByFields",null),e([h({readOnly:!0})],m.prototype,"querying",null),e([h()],m.prototype,"relatedRecordsEnabled",void 0),e([h({value:!1})],m.prototype,"returnGeometry",null),e([h({readOnly:!0})],m.prototype,"state",null),e([h({readOnly:!0})],m.prototype,"syncing",null),e([h()],m.prototype,"where",null),m=e([y(l)],m);const _=m;export{_ as default};
5
+ import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Graphic.js";import r from"../../../core/Accessor.js";import{equals as s,remove as i}from"../../../core/arrayUtils.js";import a from"../../../core/Collection.js";import o from"../../../core/Error.js";import{clone as n}from"../../../core/lang.js";import u from"../../../core/Logger.js";import{property as h}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as y}from"../../../core/accessorSupport/decorators/subclass.js";import c from"../../../rest/support/AttachmentQuery.js";const l="esri.widgets.FeatureTable.support.FeatureStore",d=u.getLogger(l);function p(e,t,r){d.error(new o(e,t,r))}let _=class extends r{constructor(e){super(e),this._loaded=!1,this._loadError=!1,this._loading=!1,this._editOperationQueue=[],this._queryOperationQueue=[],this._objectIdCache=new a,this._hasStaleCache=!1,this.count=0,this.failures=new a,this.itemCache=new a,this.relatedRecordsEnabled=!1}destroy(){this.layer=null,this.itemCache&&this.itemCache.destroy(),this.failures&&this.failures.destroy(),this._set("itemCache",null)}set attachmentsEnabled(e){this._reset(),this._set("attachmentsEnabled",e),this.notifyChange("state")}set filterGeometry(e){this._reset(),this._set("filterGeometry",e),this.notifyChange("state")}set layer(e){this._reset(),this._set("layer",e),this.notifyChange("state")}set objectIds(e){this._reset(),this._set("objectIds",e||null),this.notifyChange("state")}get orderByFields(){return this._get("orderByFields")||[]}set orderByFields(e){const t=this.orderByFields;s(e,t)||(this.itemCache.removeAll(),this._hasStaleCache=!0,this._set("orderByFields",e))}get querying(){return this._queryOperationQueue.length>0}set returnGeometry(e){this._reset(),this._set("returnGeometry",e),this.notifyChange("state")}get state(){const{layer:e,_loaded:t,_loadError:r,_loading:s}=this;return r?"error":!e||this.get("layer.loadError")?"disabled":s?"loading":"loaded"===this.get("layer.loadStatus")&&t?"loaded":"ready"}get syncing(){return this._editOperationQueue.length>0}get where(){return this._get("where")||null}set where(e){this._reset(),this._set("where",e),this.notifyChange("state")}async load(){this._reset();const{layer:e}=this;if(e){this._loading=!0,this.notifyChange("state");try{await e.when(),await this._syncLayerInfo(),this._loading=!1,this._loaded=!0,this.notifyChange("state")}catch(t){throw this._reset(),this._loadError=!0,this.notifyChange("state"),p("store:load-error","An error ocurred.",{error:t}),t}}}async refreshLayerInfo(){return this._syncLayerInfo()}async addItems(e){}async fetchItems(e){const{page:t,pageSize:r}=e,s=t*r,i=s+r,{layer:a,state:o}=this;if(!a||"loaded"!==o)return[];this.notifyChange("querying");const n=await this._query({start:s,num:i,page:t,pageSize:r});return this.notifyChange("state"),n}async verifyFeaturesByObjectId(e){const{layer:t,state:r}=this;if(!t||"loaded"!==r)return[];const{features:s}=await this._verifyFeaturesByObjectId(e);return e.map((e=>!!s.find((t=>(null==t?void 0:t.getObjectId())===e))))}async query(e){const{layer:t,state:r}=this;if(!t||"loaded"!==r)return[];this.notifyChange("querying");const s=await this._query(e);return this.notifyChange("state"),s}async removeItemAt(e){}async reset(){this._reset()}async updateItem(e){return this._update(e)}getItemByObjectId(e){const{itemCache:t,layer:{objectIdField:r}}=this;return t.find((t=>t.feature.attributes[r]===e))}getLocalItemAt(e){return this.itemCache.getItemAt(e)}getItemAt(e){return Promise.resolve(this.itemCache.getItemAt(e))}getObjectIdIndex(e){const{itemCache:t,layer:{objectIdField:r}}=this;return t.findIndex((t=>t.feature.attributes[r]===e))}_reset(){this.itemCache.removeAll(),this.failures.removeAll(),this._editOperationQueue=[],this._queryOperationQueue=[],this._hasStaleCache=!1,this._loading=!1,this._loaded=!1,this._loadError=!1,this._set("count",0),this._objectIdCache.removeAll(),this.notifyChange("querying"),this.notifyChange("syncing"),this.notifyChange("state")}_getIdsFromFeatures(e){return e.map((e=>e.attributes[this.layer.objectIdField]))}_toFeatureData(e,t){const{layer:{objectIdField:r}}=this;return e.map((e=>{const{attributes:s}=e,i=s[r];return{objectId:i,feature:e,attachments:t?t[i]:null,relatedRecords:null}}))}async _update(e){const{layer:r}=this,{operations:s}=r.capabilities;if(!s.supportsUpdate||!("applyEdits"in r))throw new o("store:update-error","Update is not supported.");const{index:i,name:a,value:u}=e,h=await this.getItemAt(i);if(!h||!h.feature)throw new o("store:update-error","Feature with provided 'objectId' not found.");const{feature:y}=h,c=n(y.attributes);c[a]=u;const l=new t({attributes:c}),d=r.applyEdits({updateFeatures:[l]}).then((e=>{const{updateFeatureResults:t}=e,r=t.find((e=>!!e.error));if(r)throw r.error;return t.length&&(y.attributes=c),e}));return this._queueEditOperation((()=>d))}async _query(e){const{refresh:t}=e;return!0===t?(this.itemCache.removeAll(),this._syncLayerInfo().then((()=>this._queryFeatureData(e)))):(this._hasStaleCache&&(await this._updateIds(),this._hasStaleCache=!1),this._queryFeatureData(e))}async _queryFeatureData(e){return this._queueQueryOperation((async()=>{const{features:t}=await this._queryFeatures(e),r=this._getIdsFromFeatures(t),s=await this._queryAttachments(r);return this._toFeatureData(t,s)||[]}))}async _syncLayerInfo(){await this._updateCount(),await this._updateIds()}async _updateCount(){await this._queryCount().then((e=>this._set("count",e)))}async _updateIds(){var e,t,r;null!=(e=this.layer)&&null!=(t=e.capabilities)&&null!=(r=t.query)&&r.supportsPagination||(this._objectIdCache.removeAll(),await this._queryForObjectIds().then((e=>this._objectIdCache.addMany(e))))}_queryCount(){const{filterGeometry:e,layer:t}=this,{capabilities:{query:{supportsCacheHint:r}}}=t,s=t.createQuery();return s.geometry=e,s.returnGeometry=!1,s.where=this._getWhere(),s.objectIds=this.objectIds,r&&(s.cacheHint=!0),t.queryFeatureCount(s)}_queryForObjectIds(){const{filterGeometry:e,layer:t,orderByFields:r}=this,{capabilities:{query:{supportsCacheHint:s,supportsOrderBy:i}}}=t,a=t.createQuery();return a.geometry=e,a.outFields=[t.objectIdField],a.returnGeometry=!1,a.where=this._getWhere(),a.objectIds=this.objectIds,i&&(a.orderByFields=r),s&&(a.cacheHint=!0),t.queryObjectIds(a)}async _queryFeatures(e){const{layer:t}=this;if(!t.capabilities.operations.supportsQuery)throw new o("store:query-error","Layer does not support query operation.");const{filterGeometry:r,layer:{capabilities:{query:{supportsCacheHint:s,supportsOrderBy:i,supportsPagination:a}}},orderByFields:n,returnGeometry:u}=this,{start:h,pageSize:y}=e,c=t.createQuery();return c.returnGeometry=u,a?(c.start=h,c.num=y,c.where=this._getWhere(),c.objectIds=this.objectIds):c.objectIds=this.objectIds||this._getObjectIdsForPage(h,y),i&&(c.orderByFields=n),r&&(c.geometry=r),s&&(c.cacheHint=!0),t.queryFeatures(c)}async _verifyFeaturesByObjectId(e){const{layer:t}=this;if(!t.capabilities.operations.supportsQuery)throw new o("store:query-error","Layer does not support query operation.");const{filterGeometry:r,layer:{capabilities:{query:{supportsCacheHint:s,supportsOrderBy:i}}},orderByFields:a}=this,n=t.createQuery();return n.where=this._getWhere(),n.returnGeometry=!1,n.objectIds=e,n.outFields=[t.objectIdField],i&&(n.orderByFields=a),r&&(n.geometry=r),s&&(n.cacheHint=!0),t.queryFeatures(n)}_getObjectIdsForPage(e,t){const r=this._objectIdCache.toArray();return r.length>=e+t?r.slice(e,e+t):r.slice(e)}_queryAttachments(e){const{attachmentsEnabled:t,layer:r}=this,{capabilities:{data:{supportsAttachment:s},operations:{supportsQueryAttachments:i}}}=r;return t&&s&&i&&"queryAttachments"in r?r.queryAttachments(new c({objectIds:e,where:this._getWhere()})):Promise.resolve(null)}_queueQueryOperation(e){return this._queryOperationQueue.push(e),this.notifyChange("querying"),e().then((t=>this._queryOperationQueue.includes(e)?(this.itemCache.addMany(t),t):[])).catch((t=>{p("store:query-error","An error ocurred.",{error:t});const r={error:t,retry:()=>{this.failures.remove(r),this._queueQueryOperation(e)},cancel:()=>this.failures.remove(r)};return this.failures.add(r),[]})).then((t=>(i(this._queryOperationQueue,e),this.notifyChange("querying"),t)))}_queueEditOperation(e){return this._editOperationQueue.push(e),this.notifyChange("syncing"),e().then((()=>{i(this._editOperationQueue,e),this.notifyChange("syncing")})).catch((t=>{p("store:edit-error","An error ocurred.",{error:t});const r={error:t,retry:()=>{this.failures.remove(r),this._queueEditOperation(e)},cancel:()=>this.failures.remove(r)};throw this.failures.add(r),i(this._editOperationQueue,e),this.notifyChange("syncing"),t}))}_getWhere(){return this.where||this.layer.definitionExpression||"1=1"}};e([h()],_.prototype,"attachmentsEnabled",null),e([h({readOnly:!0})],_.prototype,"count",void 0),e([h({readOnly:!0})],_.prototype,"failures",void 0),e([h()],_.prototype,"filterGeometry",null),e([h({readOnly:!0})],_.prototype,"itemCache",void 0),e([h({value:null})],_.prototype,"layer",null),e([h({value:null})],_.prototype,"objectIds",null),e([h()],_.prototype,"orderByFields",null),e([h({readOnly:!0})],_.prototype,"querying",null),e([h()],_.prototype,"relatedRecordsEnabled",void 0),e([h({value:!1})],_.prototype,"returnGeometry",null),e([h({readOnly:!0})],_.prototype,"state",null),e([h({readOnly:!0})],_.prototype,"syncing",null),e([h()],_.prototype,"where",null),_=e([y(l)],_);const m=_;export{m as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.24/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../chunks/tslib.es6.js";import i from"../../core/Collection.js";import t from"../../core/Error.js";import{HandleOwner as l}from"../../core/HandleOwner.js";import{isSome as s}from"../../core/maybe.js";import{createTask as r}from"../../core/promiseUtils.js";import{Milliseconds as o}from"../../core/time.js";import{init as n,watch as a}from"../../core/watchUtils.js";import{property as u}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{subclass as d}from"../../core/accessorSupport/decorators/subclass.js";import h from"../../webdoc/Widgets.js";import c from"../../webdoc/widgets/FloorFilter.js";import{GoToMixin as f}from"../support/GoTo.js";function v(e){return"esri.WebMap"===e.declaredClass}function p(e){return"esri.WebScene"===e.declaredClass}let y=class extends(f(l)){constructor(e){super(e),this.filterMenuOpen=!1,this.filterMenuType="site",this.filterMode="base-floors",this.levelsExpanded=!0,this.searchTerm=null,this.view=null,this._updateFloorFilterTask=null}initialize(){this.handles.add([n(this,"view.map",(e=>{s(this._updateFloorFilterTask)&&(this._updateFloorFilterTask.abort(),this._updateFloorFilterTask=null),this._updateFloorFilterTask=r((()=>this._updateFloorFilterFromMap(e).then((()=>{this._setInitialViewState()}))))})),n(this,"view",((e,i)=>{this._unregisterWidget(i),this._registerWidget(e),this._watchSearchResults(e)}),!0),a(this,"view.widthBreakpoint",(e=>{this._viewWidthBreakpoint=e})),a(this,"view.heightBreakpoint",(e=>{this._viewHeightBreakpoint=e}))])}destroy(){this._unregisterWidget(this.view),this.view=null,s(this._updateFloorFilterTask)&&(this._updateFloorFilterTask.abort(),this._updateFloorFilterTask=null)}set enabled(e){this._callOverride("enabled",e)}set facility(e){if(e&&this._isOverridden("facility")){const i=this.getFacility(e);this.hasMultipleSites&&(this.site=(null==i?void 0:i.siteId)||void 0)}this._callOverride("facility",e)}set filterFeatures(e){this._callOverride("filterFeatures",e)}set filterLayers(e){this._callOverride("filterLayers",e)}get hasFacilities(){var e,i,t,l;return(null==(e=this.filterLayers)?void 0:e.facilityLayer)&&(null==(i=this.filterFeatures)||null==(t=i.facilities)||null==(l=t.facilitiesInfo)?void 0:l.length)>0}get hasLevels(){var e,i,t,l;return(null==(e=this.filterLayers)?void 0:e.levelLayer)&&(null==(i=this.filterFeatures)||null==(t=i.levels)||null==(l=t.levelsInfo)?void 0:l.length)>0}get hasMultipleSites(){var e,i,t,l;return(null==(e=this.filterLayers)?void 0:e.siteLayer)&&(null==(i=this.filterFeatures)||null==(t=i.sites)||null==(l=t.sitesInfo)?void 0:l.length)>1}get isNormalMode(){let e=!0;const i=this._viewWidthBreakpoint,t=this._viewHeightBreakpoint;return"small"!==i&&"xsmall"!==i&&"xsmall"!==t||(e=!1),e}set level(e){if(!e)return this._callOverride("level",e),this.facility=void 0,this.site=void 0,void this.setFloors(null);let i=null,t=null;const l=null==e?void 0:e.split("--");var s;(null==l?void 0:l.length)>1&&"all"===l[0]?(t=l[1],i={id:e,facilityId:t,shortName:null,longName:null,levelNumber:null,verticalOrder:null}):(i=this.getLevel(e),t=null==(s=i)?void 0:s.facilityId);if(this.level!==e||this.isNormalMode||this.levelsExpanded){if(i&&this.hasFacilities&&this.hasLevels){var r;if(this.facility=t,this.hasMultipleSites)this.site=null==(r=this.getFacility(t))?void 0:r.siteId;this.setFloors(i)}else this._isOverridden("level")&&(this.facility=void 0,this.site=void 0,this.hasMultipleSites&&(this.filterMenuType="site"),this.setFloors(null));this._callOverride("level",e)}else{const e=this.getFacilityLevels(t);(null==e?void 0:e.length)>1&&(this.levelsExpanded=!0)}}set longNames(e){this._callOverride("longNames",e)}set minimized(e){this._callOverride("minimized",e)}set pinnedLevels(e){this._callOverride("pinnedLevels",e)}set site(e){this._callOverride("site",e)}get state(){return this.view&&this.filterFeatures&&this.hasFacilities&&this.hasLevels?"ready":this.view&&!this.filterFeatures?"loading":"disabled"}filterFacilities(e){let i=e;this.searchTerm&&(i=e.filter((e=>{const{name:i}=e;return i.toLowerCase().includes(this.searchTerm.toLowerCase())}))),this.site&&(i=i.filter((e=>e.siteId===this.site)));return i.sort(((e,i)=>{const t=e.name,l=i.name;return t>l?1:t===l?0:-1}))}filterSites(e){let i=e;this.searchTerm&&(i=e.filter((e=>{const{name:i}=e;return i.toLowerCase().includes(this.searchTerm.toLowerCase())})));return i.sort(((e,i)=>{const t=e.name,l=i.name;return t>l?1:t===l?0:-1}))}getBaseLevel(e){var i,t;const l=null==(i=this.filterFeatures)||null==(t=i.levels)?void 0:t.levelsInfo;let s=null;if(e){const{id:i}=e;l&&l.length>0&&l.forEach((e=>{0===e.verticalOrder&&e.facilityId===i&&(s=e)}))}return s}getFacility(e){var i,t,l,s;return null!=(i=null==(t=this.filterFeatures)||null==(l=t.facilities)||null==(s=l.facilitiesInfo)?void 0:s.find((i=>i.id===e)))?i:null}getFacilityLevels(e){var i,t;if(!e||null==(i=this.filterFeatures)||null==(t=i.levels)||!t.levelsInfo)return[];return this.filterFeatures.levels.levelsInfo.filter((i=>i.facilityId===e)).sort(((e,i)=>{const t=e.verticalOrder,l=i.verticalOrder;return t>l?-1:t===l?0:1}))}getLevel(e){var i,t,l,s;return null!=(i=null==(t=this.filterFeatures)||null==(l=t.levels)||null==(s=l.levelsInfo)?void 0:s.find((i=>i.id===e)))?i:null}getSite(e){var i,t,l,s;return null!=(i=null==(t=this.filterFeatures)||null==(l=t.sites)||null==(s=l.sitesInfo)?void 0:s.find((i=>i.id===e)))?i:null}goTo(e){const{view:i}=this;if(!i||!e)return;const{geometry:t}=e;if(t&&t.extent){const e={duration:o(1e3),easing:"out-back"},i={target:t.extent,options:e};this.callGoTo(i)}}setFloors(e){var t,l,s;null==(t=this.view)||null==(l=t.map)||null==(s=l.allLayers)||s.forEach((e=>{"feature"===e.type&&this._computeViewAllModeFloors(e)})),this.view.floors=new i(this._computeFloors(e))}updateWebDocument(e){if(v(e)){var i,t,l;const s=new c({enabled:this.enabled,longNames:this.longNames,minimized:this.minimized,pinnedLevels:this.pinnedLevels,site:null!=(i=this.site)?i:null,facility:null!=(t=this.facility)?t:null,level:null!=(l=this.level)?l:null});e.widgets?e.widgets.floorFilter=s:e.widgets=new h({floorFilter:s})}}_computeFloors(e){if("single-floor"===this.filterMode)this._computeSingleFloor(e);else if("base-floors"===this.filterMode)return"3d"===this.view.type?this._computeBaseFloors3D(e):this._computeBaseFloors(e);return this._computeEmptyFloors()}_computeSingleFloor(e){if(!e)return this._computeEmptyFloors();const i=[];if("all"===(null==e?void 0:e.id)){this.getFacilityLevels(e.facilityId).forEach((e=>{e.id&&i.push(e.id)}))}else e&&i.push(e.id);return i}_computeBaseFloors(e){var i,t;const l=null==(i=this.filterFeatures)||null==(t=i.levels)?void 0:t.levelsInfo;if(!l||!l.length)return this._computeEmptyFloors();const s=[];if("all"===(null==e?void 0:e.id)){this.getFacilityLevels(e.facilityId).forEach((e=>{e.id&&s.push(e.id)}))}else e&&s.push(e.id);const r=null==e?void 0:e.facilityId;return l.forEach((e=>{const{id:i,facilityId:t,verticalOrder:l}=e;(r||0!==l||s.includes(i))&&(t===r||0!==l||s.includes(i))||s.push(i)})),s}_computeBaseFloors3D(e){var i,t;const l=null==(i=this.filterFeatures)||null==(t=i.levels)?void 0:t.levelsInfo;if(!l||!l.length)return this._computeEmptyFloors();const s=[],r=null==e?void 0:e.id.split("--");if((null==r?void 0:r.length)>1&&"all"===r[0]){this.getFacilityLevels(e.facilityId).forEach((e=>{e.id&&s.push(e.id)}))}else e&&s.push(e.id);const o=null==e?void 0:e.facilityId;return l.forEach((e=>{const{id:i,facilityId:t}=e;(o||s.includes(i))&&(t===o||s.includes(i))||s.push(i)})),s}_computeEmptyFloors(){return[]}async _setFilterLayers(){const{view:e}=this;if(!this._isOverridden("filterLayers")){if(!v(e.map)&&!p(e.map))throw new t("Map must be a webmap or webscene");{var i;const t=e.map,v=null==t?void 0:t.allLayers;if((null==v||null==(i=v.items)?void 0:i.length)>0){var l,s,r,o,n,a,u,d,h,c,f,y;const e={siteLayer:null,facilityLayer:null,levelLayer:null},i=null==(l=t.floorInfo)||null==(s=l.siteLayer)?void 0:s.layerId,p=null==(r=t.floorInfo)||null==(o=r.facilityLayer)?void 0:o.layerId,I=null==(n=t.floorInfo)||null==(a=n.levelLayer)?void 0:a.layerId,b=(null==(u=t.floorInfo)||null==(d=u.siteLayer)?void 0:d.sublayerId)||(null==(h=t.floorInfo)||null==(c=h.facilityLayer)?void 0:c.sublayerId)||(null==(f=t.floorInfo)||null==(y=f.levelLayer)?void 0:y.sublayerId);if(!p||!I)return;const O=v.items.filter((e=>"feature"===e.type||"scene"===e.type)),M=v.items.filter((e=>"map-image"===e.type));if((null==M?void 0:M.length)>0&&b){var m,F,g,L,_,w;await Promise.all(M.map((e=>e.load())));const l=null==(m=t.floorInfo)||null==(F=m.siteLayer)?void 0:F.sublayerId,s=null==(g=t.floorInfo)||null==(L=g.facilityLayer)?void 0:L.sublayerId,r=null==(_=t.floorInfo)||null==(w=_.levelLayer)?void 0:w.sublayerId;M.forEach((t=>{const o=t.id,n=null==t?void 0:t.allSublayers,a=null==n?void 0:n.items;(o===i||o===p||o===I)&&(null==a?void 0:a.length)>0&&n.items.forEach((t=>{const n=t.id;o===i&&n===l?e.siteLayer=t:n===s?e.facilityLayer=t:n===r&&(e.levelLayer=t)}))}))}(null==O?void 0:O.length)>0&&O.forEach((t=>{const l=t.id;l===i?e.siteLayer=t:l===p?e.facilityLayer=t:l===I&&(e.levelLayer=t)})),this.filterLayers=e}}}}async _getFilterFeatures(){if(this._isOverridden("filterFeatures"))return Promise.resolve(this.filterFeatures);const e={sites:null,facilities:null,levels:null},i=await this._getSites();e.sites=i;const t=await this._getFacilities();e.facilities=t;const l=await this._getLevels();return e.levels=l,e}async _getSites(){var e,i;const{filterLayers:t,view:l}=this,s=l.map,{siteLayer:r}=t,o={sitesInfo:[]};if(!r||null==s||null==(e=s.floorInfo)||!e.siteLayer)return o;const n=r.createQuery();n.returnGeometry=!0,n.outFields=["*"],n.returnZ=!0,"type"in r&&"scene"===r.type&&(n.multipatchOption="xyFootprint");const{siteIdField:a,nameField:u}=s.floorInfo.siteLayer,d=await r.queryFeatures(n);if((null==d||null==(i=d.features)?void 0:i.length)>0){d.features.forEach((e=>{const i=e.attributes,t=e.geometry,l=i[a],s=i[u];l&&s&&o.sitesInfo.push({id:l,name:s,geometry:t})}))}return o}async _getFacilities(){var e,i;const{filterLayers:t,view:l}=this,s=l.map,{facilityLayer:r}=t,o={facilitiesInfo:[]};if(!r||null==s||null==(e=s.floorInfo)||!e.facilityLayer)return o;const n=r.createQuery();n.returnGeometry=!0,n.outFields=["*"],n.returnZ=!0,"type"in r&&"scene"===r.type&&(n.multipatchOption="xyFootprint");const{facilityIdField:a,siteIdField:u,nameField:d}=s.floorInfo.facilityLayer,h=await r.queryFeatures(n);if((null==h||null==(i=h.features)?void 0:i.length)>0){h.features.forEach((e=>{const i=e.attributes,t=e.geometry,l=i[a],s=i[u],r=i[d];l&&r&&o.facilitiesInfo.push({id:l,siteId:s,name:r,geometry:t})}))}return o}async _getLevels(){var e,i;const{filterLayers:t,view:l}=this,s=l.map,{levelLayer:r}=t,o={levelsInfo:[]};if(!r||null==s||null==(e=s.floorInfo)||!e.levelLayer)return o;const n=r.createQuery();n.returnGeometry=!0,n.outFields=["*"],n.returnZ=!0;const{levelIdField:a,facilityIdField:u,longNameField:d,shortNameField:h,levelNumberField:c,verticalOrderField:f}=s.floorInfo.levelLayer,v=await r.queryFeatures(n);if((null==v||null==(i=v.features)?void 0:i.length)>0){v.features.forEach((e=>{const i=e.attributes,t=i[a],l=i[u],s=i[d],r=i[h],n=i[c],v=i[f];t&&l&&s&&r&&"number"==typeof n&&"number"==typeof v&&o.levelsInfo.push({id:t,facilityId:l,longName:s,shortName:r,levelNumber:n,verticalOrder:v})}))}return o}_registerWidget(e){(null==e?void 0:e.persistableViewModels.includes(this))||null==e||e.persistableViewModels.add(this)}_unregisterWidget(e){null==e||e.persistableViewModels.remove(this)}_watchSearchResults(e){null==e||e.on("select-result-floor",(e=>{const i=this.getLevel(e);i&&this.level!==e&&(this.level=e,this.setFloors(i))}))}async _setInitialViewState(){if(this.view)try{await this.view.when(),await this._setFilterLayers();const e=await this._getFilterFeatures();if(!e)return;if(this.filterFeatures=e,!this.hasFacilities||!this.hasLevels)return void console.error("Facilities and Levels are required for the Floor Filter widget");if(this.hasMultipleSites||(this.filterMenuType="facility"),this.facility&&this.level){this.filterMenuType="facility";const e=this.getFacility(this.facility),i=this.getLevel(this.level);this.site||(this.site=e.siteId||void 0),this.setFloors(i),this.goTo(e)}else if(this.facility&&!this.level){this.filterMenuType="facility";const e=this.getFacility(this.facility),i=this.getBaseLevel(e);this.site||(this.site=e.siteId||void 0),this.level=(null==i?void 0:i.id)||void 0,this.setFloors(i),this.goTo(e)}else if(!this.facility&&this.level){this.filterMenuType="facility";const e=this.getLevel(this.level),i=this.getFacility(null==e?void 0:e.facilityId);this.facility=(null==i?void 0:i.id)||void 0,this.site||(this.site=(null==i?void 0:i.siteId)||void 0),this.setFloors(e),this.goTo(i)}else if(!this.site||this.facility||this.level)this.setFloors(null);else{this.filterMenuType="site";const e=this.getSite(this.site);this.setFloors(null),this.goTo(e)}}catch(e){console.error("Couldn't retrieve sites, facilities, and levels",e)}}_callOverride(e,i){this._override(e,i)}async _updateFloorFilterFromMap(e){var i;if(!e||!v(e))return;const t=null==e||null==(i=e.widgets)?void 0:i.floorFilter;t&&(this._isOverridden("enabled")||(this.enabled=t.enabled),this._isOverridden("longNames")||(this.longNames=t.longNames),this._isOverridden("minimized")||(this.minimized=t.minimized),this._isOverridden("pinnedLevels")||(this.pinnedLevels=t.pinnedLevels),this._isOverridden("site")||(this.site=t.site),this._isOverridden("facility")||(this.facility=t.facility),this._isOverridden("level")||(this.level=t.level))}_computeViewAllModeFloors(e){var t;const{filterFeatures:l}=this;if(null!=(t=e.floorInfo)&&t.viewAllMode&&this.hasLevels&&this.hasFacilities&&"base-floors"===this.filterMode){const{level:t,facility:s}=this,r=[];l.levels.levelsInfo.forEach((e=>{const{id:i,facilityId:l}=e;s&&l===s?t&&i===t&&r.push(i):r.push(i)})),e.floorInfo.viewAllLevelIds=new i(r)}}};e([u({value:!1})],y.prototype,"enabled",null),e([u({value:void 0})],y.prototype,"facility",null),e([u({value:null})],y.prototype,"filterFeatures",null),e([u({value:null})],y.prototype,"filterLayers",null),e([u()],y.prototype,"filterMenuOpen",void 0),e([u()],y.prototype,"filterMenuType",void 0),e([u()],y.prototype,"filterMode",void 0),e([u()],y.prototype,"hasFacilities",null),e([u()],y.prototype,"hasLevels",null),e([u()],y.prototype,"hasMultipleSites",null),e([u({readOnly:!0})],y.prototype,"isNormalMode",null),e([u({value:void 0})],y.prototype,"level",null),e([u({value:!1})],y.prototype,"longNames",null),e([u()],y.prototype,"levelsExpanded",void 0),e([u({value:!1})],y.prototype,"minimized",null),e([u({value:!1})],y.prototype,"pinnedLevels",null),e([u()],y.prototype,"searchTerm",void 0),e([u({value:void 0})],y.prototype,"site",null),e([u({readOnly:!0})],y.prototype,"state",null),e([u()],y.prototype,"view",void 0),e([u()],y.prototype,"_viewHeightBreakpoint",void 0),e([u()],y.prototype,"_viewWidthBreakpoint",void 0),e([u()],y.prototype,"updateWebDocument",null),y=e([d("esri/widgets/FloorFilter/FloorFilterViewModel")],y);const m=y;export{m as default};
5
+ import{_ as e}from"../../chunks/tslib.es6.js";import i from"../../core/Collection.js";import t from"../../core/Error.js";import{HandleOwner as l}from"../../core/HandleOwner.js";import{isSome as s}from"../../core/maybe.js";import{createTask as r}from"../../core/promiseUtils.js";import{Milliseconds as o}from"../../core/time.js";import{init as n,watch as a}from"../../core/watchUtils.js";import{property as u}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{subclass as d}from"../../core/accessorSupport/decorators/subclass.js";import h from"../../webdoc/Widgets.js";import c from"../../webdoc/widgets/FloorFilter.js";import{GoToMixin as f}from"../support/GoTo.js";function v(e){return"esri.WebMap"===e.declaredClass}function p(e){return"esri.WebScene"===e.declaredClass}let y=class extends(f(l)){constructor(e){super(e),this.filterMenuOpen=!1,this.filterMenuType="site",this.filterMode="base-floors",this.levelsExpanded=!0,this.searchTerm=null,this.view=null,this._updateFloorFilterTask=null}initialize(){this.handles.add([n(this,"view.map",(e=>{s(this._updateFloorFilterTask)&&(this._updateFloorFilterTask.abort(),this._updateFloorFilterTask=null),this._updateFloorFilterTask=r((()=>this._updateFloorFilterFromMap(e).then((()=>{this._setInitialViewState()}))))})),n(this,"view",((e,i)=>{this._unregisterWidget(i),this._registerWidget(e),this._watchSearchResults(e)}),!0),a(this,"view.widthBreakpoint",(e=>{this._viewWidthBreakpoint=e})),a(this,"view.heightBreakpoint",(e=>{this._viewHeightBreakpoint=e}))])}destroy(){this._unregisterWidget(this.view),this.view=null,s(this._updateFloorFilterTask)&&(this._updateFloorFilterTask.abort(),this._updateFloorFilterTask=null)}set enabled(e){this._callOverride("enabled",e)}set facility(e){if(e&&this._isOverridden("facility")){const i=this.getFacility(e);this.hasMultipleSites&&(this.site=(null==i?void 0:i.siteId)||void 0)}this._callOverride("facility",e)}set filterFeatures(e){this._callOverride("filterFeatures",e)}set filterLayers(e){this._callOverride("filterLayers",e)}get hasFacilities(){var e,i,t,l;return(null==(e=this.filterLayers)?void 0:e.facilityLayer)&&(null==(i=this.filterFeatures)||null==(t=i.facilities)||null==(l=t.facilitiesInfo)?void 0:l.length)>0}get hasLevels(){var e,i,t,l;return(null==(e=this.filterLayers)?void 0:e.levelLayer)&&(null==(i=this.filterFeatures)||null==(t=i.levels)||null==(l=t.levelsInfo)?void 0:l.length)>0}get hasMultipleSites(){var e,i,t,l;return(null==(e=this.filterLayers)?void 0:e.siteLayer)&&(null==(i=this.filterFeatures)||null==(t=i.sites)||null==(l=t.sitesInfo)?void 0:l.length)>1}get isNormalMode(){let e=!0;const i=this._viewWidthBreakpoint,t=this._viewHeightBreakpoint;return"small"!==i&&"xsmall"!==i&&"xsmall"!==t||(e=!1),e}set level(e){if(!e)return this._callOverride("level",e),this.facility=void 0,this.site=void 0,void this.setFloors(null);let i=null,t=null;const l=null==e?void 0:e.split("--");var s;(null==l?void 0:l.length)>1&&"all"===l[0]?(t=l[1],i={id:e,facilityId:t,shortName:null,longName:null,levelNumber:null,verticalOrder:null}):(i=this.getLevel(e),t=null==(s=i)?void 0:s.facilityId);if(this.level!==e||this.isNormalMode||this.levelsExpanded){if(i&&this.hasFacilities&&this.hasLevels){var r;if(this.facility=t,this.hasMultipleSites)this.site=null==(r=this.getFacility(t))?void 0:r.siteId;this.setFloors(i)}else this._isOverridden("level")&&(this.facility=void 0,this.site=void 0,this.hasMultipleSites&&(this.filterMenuType="site"),this.setFloors(null));this._callOverride("level",e)}else{const e=this.getFacilityLevels(t);(null==e?void 0:e.length)>1&&(this.levelsExpanded=!0)}}set longNames(e){this._callOverride("longNames",e)}set minimized(e){this._callOverride("minimized",e)}set pinnedLevels(e){this._callOverride("pinnedLevels",e)}set site(e){this._callOverride("site",e)}get state(){return this.view&&this.filterFeatures&&this.hasFacilities&&this.hasLevels?"ready":this.view&&!this.filterFeatures?"loading":"disabled"}filterFacilities(e){let i=e;this.searchTerm&&(i=e.filter((e=>{const{name:i}=e;return i.toLowerCase().includes(this.searchTerm.toLowerCase())}))),this.site&&(i=i.filter((e=>e.siteId===this.site)));return i.sort(((e,i)=>{const t=e.name,l=i.name;return t>l?1:t===l?0:-1}))}filterSites(e){let i=e;this.searchTerm&&(i=e.filter((e=>{const{name:i}=e;return i.toLowerCase().includes(this.searchTerm.toLowerCase())})));return i.sort(((e,i)=>{const t=e.name,l=i.name;return t>l?1:t===l?0:-1}))}getBaseLevel(e){var i,t;const l=null==(i=this.filterFeatures)||null==(t=i.levels)?void 0:t.levelsInfo;let s=null;if(e){const{id:i}=e;l&&l.length>0&&l.forEach((e=>{0===e.verticalOrder&&e.facilityId===i&&(s=e)}))}return s}getFacility(e){var i,t,l,s;return null!=(i=null==(t=this.filterFeatures)||null==(l=t.facilities)||null==(s=l.facilitiesInfo)?void 0:s.find((i=>i.id===e)))?i:null}getFacilityLevels(e){var i,t;if(!e||null==(i=this.filterFeatures)||null==(t=i.levels)||!t.levelsInfo)return[];return this.filterFeatures.levels.levelsInfo.filter((i=>i.facilityId===e)).sort(((e,i)=>{const t=e.verticalOrder,l=i.verticalOrder;return t>l?-1:t===l?0:1}))}getLevel(e){var i,t,l,s;return null!=(i=null==(t=this.filterFeatures)||null==(l=t.levels)||null==(s=l.levelsInfo)?void 0:s.find((i=>i.id===e)))?i:null}getSite(e){var i,t,l,s;return null!=(i=null==(t=this.filterFeatures)||null==(l=t.sites)||null==(s=l.sitesInfo)?void 0:s.find((i=>i.id===e)))?i:null}goTo(e){const{view:i}=this;if(!i||!e)return;const{geometry:t}=e;if(t&&t.extent){const e={duration:o(1e3),easing:"out-back"},i={target:t.extent,options:e};this.callGoTo(i)}}setFloors(e){var t,l,s;null==(t=this.view)||null==(l=t.map)||null==(s=l.allLayers)||s.forEach((e=>{"feature"===e.type&&this._computeViewAllModeFloors(e)})),this.view.floors=new i(this._computeFloors(e))}updateWebDocument(e){if(v(e)){var i,t,l;const s=new c({enabled:this.enabled,longNames:this.longNames,minimized:this.minimized,pinnedLevels:this.pinnedLevels,site:null!=(i=this.site)?i:null,facility:null!=(t=this.facility)?t:null,level:null!=(l=this.level)?l:null});e.widgets?e.widgets.floorFilter=s:e.widgets=new h({floorFilter:s})}}_computeFloors(e){if("single-floor"===this.filterMode)this._computeSingleFloor(e);else if("base-floors"===this.filterMode)return"3d"===this.view.type?this._computeBaseFloors3D(e):this._computeBaseFloors(e);return this._computeEmptyFloors()}_computeSingleFloor(e){if(!e)return this._computeEmptyFloors();const i=[];if("all"===(null==e?void 0:e.id)){this.getFacilityLevels(e.facilityId).forEach((e=>{e.id&&i.push(e.id)}))}else e&&i.push(e.id);return i}_computeBaseFloors(e){var i,t;const l=null==(i=this.filterFeatures)||null==(t=i.levels)?void 0:t.levelsInfo;if(!l||!l.length)return this._computeEmptyFloors();const s=[];if("all"===(null==e?void 0:e.id)){this.getFacilityLevels(e.facilityId).forEach((e=>{e.id&&s.push(e.id)}))}else e&&s.push(e.id);const r=null==e?void 0:e.facilityId;return l.forEach((e=>{const{id:i,facilityId:t,verticalOrder:l}=e;(r||0!==l||s.includes(i))&&(t===r||0!==l||s.includes(i))||s.push(i)})),s}_computeBaseFloors3D(e){var i,t;const l=null==(i=this.filterFeatures)||null==(t=i.levels)?void 0:t.levelsInfo;if(!l||!l.length)return this._computeEmptyFloors();const s=[],r=null==e?void 0:e.id.split("--");if((null==r?void 0:r.length)>1&&"all"===r[0]){this.getFacilityLevels(e.facilityId).forEach((e=>{e.id&&s.push(e.id)}))}else e&&s.push(e.id);const o=null==e?void 0:e.facilityId;return l.forEach((e=>{const{id:i,facilityId:t}=e;(o||s.includes(i))&&(t===o||s.includes(i))||s.push(i)})),s}_computeEmptyFloors(){return[]}async _setFilterLayers(){const{view:e}=this;if(!this._isOverridden("filterLayers")){if(!v(e.map)&&!p(e.map))throw new t("Map must be a webmap or webscene");{var i;const t=e.map,v=null==t?void 0:t.allLayers;if((null==v||null==(i=v.items)?void 0:i.length)>0){var l,s,r,o,n,a,u,d,h,c,f,y;const e={siteLayer:null,facilityLayer:null,levelLayer:null},i=null==(l=t.floorInfo)||null==(s=l.siteLayer)?void 0:s.layerId,p=null==(r=t.floorInfo)||null==(o=r.facilityLayer)?void 0:o.layerId,I=null==(n=t.floorInfo)||null==(a=n.levelLayer)?void 0:a.layerId,b=(null==(u=t.floorInfo)||null==(d=u.siteLayer)?void 0:d.sublayerId)||(null==(h=t.floorInfo)||null==(c=h.facilityLayer)?void 0:c.sublayerId)||(null==(f=t.floorInfo)||null==(y=f.levelLayer)?void 0:y.sublayerId);if(!p||!I)return;const O=v.items.filter((e=>"feature"===e.type||"scene"===e.type)),M=v.items.filter((e=>"map-image"===e.type));if((null==M?void 0:M.length)>0&&b){var m,F,g,L,_,w;await Promise.all(M.map((e=>e.load())));const l=null==(m=t.floorInfo)||null==(F=m.siteLayer)?void 0:F.sublayerId,s=null==(g=t.floorInfo)||null==(L=g.facilityLayer)?void 0:L.sublayerId,r=null==(_=t.floorInfo)||null==(w=_.levelLayer)?void 0:w.sublayerId;M.forEach((t=>{const o=t.id,n=null==t?void 0:t.allSublayers,a=null==n?void 0:n.items;(o===i||o===p||o===I)&&(null==a?void 0:a.length)>0&&n.items.forEach((t=>{const n=t.id;o===i&&n===l?e.siteLayer=t:n===s?e.facilityLayer=t:n===r&&(e.levelLayer=t)}))}))}(null==O?void 0:O.length)>0&&O.forEach((t=>{const l=t.id;l===i?e.siteLayer=t:l===p?e.facilityLayer=t:l===I&&(e.levelLayer=t)})),this.filterLayers=e}}}}async _getFilterFeatures(){if(this._isOverridden("filterFeatures"))return this.filterFeatures;const e={sites:null,facilities:null,levels:null},i=await this._getSites();e.sites=i;const t=await this._getFacilities();e.facilities=t;const l=await this._getLevels();return e.levels=l,e}async _getSites(){var e,i;const{filterLayers:t,view:l}=this,s=l.map,{siteLayer:r}=t,o={sitesInfo:[]};if(!r||null==s||null==(e=s.floorInfo)||!e.siteLayer)return o;const n=r.createQuery();n.returnGeometry=!0,n.outFields=["*"],n.returnZ=!0,"type"in r&&"scene"===r.type&&(n.multipatchOption="xyFootprint");const{siteIdField:a,nameField:u}=s.floorInfo.siteLayer,d=await r.queryFeatures(n);if((null==d||null==(i=d.features)?void 0:i.length)>0){d.features.forEach((e=>{const i=e.attributes,t=e.geometry,l=i[a],s=i[u];l&&s&&o.sitesInfo.push({id:l,name:s,geometry:t})}))}return o}async _getFacilities(){var e,i;const{filterLayers:t,view:l}=this,s=l.map,{facilityLayer:r}=t,o={facilitiesInfo:[]};if(!r||null==s||null==(e=s.floorInfo)||!e.facilityLayer)return o;const n=r.createQuery();n.returnGeometry=!0,n.outFields=["*"],n.returnZ=!0,"type"in r&&"scene"===r.type&&(n.multipatchOption="xyFootprint");const{facilityIdField:a,siteIdField:u,nameField:d}=s.floorInfo.facilityLayer,h=await r.queryFeatures(n);if((null==h||null==(i=h.features)?void 0:i.length)>0){h.features.forEach((e=>{const i=e.attributes,t=e.geometry,l=i[a],s=i[u],r=i[d];l&&r&&o.facilitiesInfo.push({id:l,siteId:s,name:r,geometry:t})}))}return o}async _getLevels(){var e,i;const{filterLayers:t,view:l}=this,s=l.map,{levelLayer:r}=t,o={levelsInfo:[]};if(!r||null==s||null==(e=s.floorInfo)||!e.levelLayer)return o;const n=r.createQuery();n.returnGeometry=!0,n.outFields=["*"],n.returnZ=!0;const{levelIdField:a,facilityIdField:u,longNameField:d,shortNameField:h,levelNumberField:c,verticalOrderField:f}=s.floorInfo.levelLayer,v=await r.queryFeatures(n);if((null==v||null==(i=v.features)?void 0:i.length)>0){v.features.forEach((e=>{const i=e.attributes,t=i[a],l=i[u],s=i[d],r=i[h],n=i[c],v=i[f];t&&l&&s&&r&&"number"==typeof n&&"number"==typeof v&&o.levelsInfo.push({id:t,facilityId:l,longName:s,shortName:r,levelNumber:n,verticalOrder:v})}))}return o}_registerWidget(e){(null==e?void 0:e.persistableViewModels.includes(this))||null==e||e.persistableViewModels.add(this)}_unregisterWidget(e){null==e||e.persistableViewModels.remove(this)}_watchSearchResults(e){null==e||e.on("select-result-floor",(e=>{const i=this.getLevel(e);i&&this.level!==e&&(this.level=e,this.setFloors(i))}))}async _setInitialViewState(){if(this.view)try{await this.view.when(),await this._setFilterLayers();const e=await this._getFilterFeatures();if(!e)return;if(this.filterFeatures=e,!this.hasFacilities||!this.hasLevels)return void console.error("Facilities and Levels are required for the Floor Filter widget");if(this.hasMultipleSites||(this.filterMenuType="facility"),this.facility&&this.level){this.filterMenuType="facility";const e=this.getFacility(this.facility),i=this.getLevel(this.level);this.site||(this.site=e.siteId||void 0),this.setFloors(i),this.goTo(e)}else if(this.facility&&!this.level){this.filterMenuType="facility";const e=this.getFacility(this.facility),i=this.getBaseLevel(e);this.site||(this.site=e.siteId||void 0),this.level=(null==i?void 0:i.id)||void 0,this.setFloors(i),this.goTo(e)}else if(!this.facility&&this.level){this.filterMenuType="facility";const e=this.getLevel(this.level),i=this.getFacility(null==e?void 0:e.facilityId);this.facility=(null==i?void 0:i.id)||void 0,this.site||(this.site=(null==i?void 0:i.siteId)||void 0),this.setFloors(e),this.goTo(i)}else if(!this.site||this.facility||this.level)this.setFloors(null);else{this.filterMenuType="site";const e=this.getSite(this.site);this.setFloors(null),this.goTo(e)}}catch(e){console.error("Couldn't retrieve sites, facilities, and levels",e)}}_callOverride(e,i){this._override(e,i)}async _updateFloorFilterFromMap(e){var i;if(!e||!v(e))return;const t=null==e||null==(i=e.widgets)?void 0:i.floorFilter;t&&(this._isOverridden("enabled")||(this.enabled=t.enabled),this._isOverridden("longNames")||(this.longNames=t.longNames),this._isOverridden("minimized")||(this.minimized=t.minimized),this._isOverridden("pinnedLevels")||(this.pinnedLevels=t.pinnedLevels),this._isOverridden("site")||(this.site=t.site),this._isOverridden("facility")||(this.facility=t.facility),this._isOverridden("level")||(this.level=t.level))}_computeViewAllModeFloors(e){var t;const{filterFeatures:l}=this;if(null!=(t=e.floorInfo)&&t.viewAllMode&&this.hasLevels&&this.hasFacilities&&"base-floors"===this.filterMode){const{level:t,facility:s}=this,r=[];l.levels.levelsInfo.forEach((e=>{const{id:i,facilityId:l}=e;s&&l===s?t&&i===t&&r.push(i):r.push(i)})),e.floorInfo.viewAllLevelIds=new i(r)}}};e([u({value:!1})],y.prototype,"enabled",null),e([u({value:void 0})],y.prototype,"facility",null),e([u({value:null})],y.prototype,"filterFeatures",null),e([u({value:null})],y.prototype,"filterLayers",null),e([u()],y.prototype,"filterMenuOpen",void 0),e([u()],y.prototype,"filterMenuType",void 0),e([u()],y.prototype,"filterMode",void 0),e([u()],y.prototype,"hasFacilities",null),e([u()],y.prototype,"hasLevels",null),e([u()],y.prototype,"hasMultipleSites",null),e([u({readOnly:!0})],y.prototype,"isNormalMode",null),e([u({value:void 0})],y.prototype,"level",null),e([u({value:!1})],y.prototype,"longNames",null),e([u()],y.prototype,"levelsExpanded",void 0),e([u({value:!1})],y.prototype,"minimized",null),e([u({value:!1})],y.prototype,"pinnedLevels",null),e([u()],y.prototype,"searchTerm",void 0),e([u({value:void 0})],y.prototype,"site",null),e([u({readOnly:!0})],y.prototype,"state",null),e([u()],y.prototype,"view",void 0),e([u()],y.prototype,"_viewHeightBreakpoint",void 0),e([u()],y.prototype,"_viewWidthBreakpoint",void 0),e([u()],y.prototype,"updateWebDocument",null),y=e([d("esri/widgets/FloorFilter/FloorFilterViewModel")],y);const m=y;export{m as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.24/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Color.js";import{addTokenParameter as l}from"../../../kernel.js";import s from"../../../request.js";import"../../../symbols.js";import r from"../../../core/Accessor.js";import n from"../../../core/Collection.js";import i from"../../../core/Handles.js";import{JSONMap as a}from"../../../core/jsonMap.js";import o from"../../../core/Logger.js";import{unwrap as u,isSome as c}from"../../../core/maybe.js";import{eachAlways as d,debounce as y}from"../../../core/promiseUtils.js";import{px2pt as h}from"../../../core/screenUtils.js";import{addQueryParameters as m}from"../../../core/urlUtils.js";import{on as p,init as f,whenFalseOnce as g,watch as b}from"../../../core/watchUtils.js";import{property as S}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/arrayUtils.js";import"../../../core/has.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as _}from"../../../core/accessorSupport/decorators/subclass.js";import{OriginId as v}from"../../../core/accessorSupport/PropertyOrigin.js";import{EffectView as w}from"../../../layers/effects/EffectView.js";import{effectFunctionsFromJSON as L}from"../../../layers/effects/jsonUtils.js";import{ExportImageParameters as E}from"../../../layers/support/ExportImageParameters.js";import{isDateField as I}from"../../../layers/support/fieldUtils.js";import{fromJSON as C}from"../../../renderers/support/jsonUtils.js";import{isSupportedRenderer3D as R}from"../../../renderers/support/rendererConversion.js";import F from"../../../renderers/visualVariables/support/SizeVariableLegendOptions.js";import{applyCIMSymbolColor as V}from"../../../symbols/support/cimSymbolUtils.js";import{SymbolSizeDefaults as T}from"../../../symbols/support/previewUtils.js";import{renderSymbol as z}from"../../../symbols/support/renderUtils.js";import{renderColorRampPreviewHTML as x,renderDotDensityPreviewHTML as j,renderPreviewHTML as D}from"../../../symbols/support/symbolUtils.js";import{isVolumetricSymbol as O}from"../../../symbols/support/utils.js";import{getClusterSizeVariable as M}from"./clusterUtils.js";import{getColorFromPointCloudStops as P,getRampStopsForPointCloud as A,getStrectchRampStops as U,getRampStops as B}from"./colorRampUtils.js";import{getHeatmapRampStops as k}from"./heatmapRampUtils.js";import{getRotationAngleForFocus as N,getRelationshipRampElement as q}from"./relationshipRampUtils.js";import{getRampStops as W,REAL_WORLD_MAX_SIZE as $,REAL_WORLD_MIN_SIZE as G}from"./sizeRampUtils.js";import{SPECIAL_CHARS_LESS_THAN as J,SPECIAL_CHARS_GREATER_THAN as Q,getSymbolForFlowRenderer as H,getMedianColor as X,RGB_IMG_SOURCE as K}from"./utils.js";import{formatNumberLabel as Y}from"../../smartMapping/support/utils.js";import Z from"../../../symbols/SimpleMarkerSymbol.js";import ee from"../../../symbols/SimpleFillSymbol.js";const te=o.getLogger("esri.widgets.Legend.support.ActiveLayerInfo"),le="https://utility.arcgis.com/sharing/tools/legend",se="esri.layers.ImageryLayer",re="esri.layers.ImageryTileLayer",ne="esri.layers.WCSLayer",ie=/^\s*(return\s+)?\$view\.scale\s*(;)?\s*$/i,ae=new a({esriGeometryPoint:"point",esriGeometryMultipoint:"multipoint",esriGeometryPolyline:"polyline",esriGeometryPolygon:"polygon",esriGeometryMultiPatch:"multipatch"}),oe={u1:[0,1],u2:[0,3],u4:[0,15],u8:[0,255],s8:[-128,127],u16:[0,65535],s16:[-32768,32767],u32:[0,4294967295],s32:[-2147483648,2147483647],f32:[-34e38,34e38],f64:[-Number.MAX_VALUE,Number.MAX_VALUE]},ue=new Z({size:6,outline:{color:[128,128,128,.5],width:.5}}),ce=new ee({style:"solid"});function de(e){return"flow"===e.type}function ye(e){return"vector-field"===e.type}function he(e){return"raster-colormap"===e.type}function me(e){return"raster-stretch"===e.type}function pe(e){return"raster-shaded-relief"===e.type}function fe(e){return"esri.renderers.SimpleRenderer"===e.declaredClass}function ge(e){return"esri.renderers.ClassBreaksRenderer"===e.declaredClass}function be(e){return"esri.renderers.UniqueValueRenderer"===e.declaredClass}function Se(e){return"esri.renderers.HeatmapRenderer"===e.declaredClass}function _e(e){return we(e)||Le(e)||Ee(e)||ve(e)}function ve(e){return"esri.renderers.PointCloudRGBRenderer"===e.declaredClass}function we(e){return"esri.renderers.PointCloudClassBreaksRenderer"===e.declaredClass}function Le(e){return"esri.renderers.PointCloudStretchRenderer"===e.declaredClass}function Ee(e){return"esri.renderers.PointCloudUniqueValueRenderer"===e.declaredClass}function Ie(e){return"esri.renderers.DotDensityRenderer"===e.declaredClass}function Ce(e,t){return fe(e)||ge(e)||be(e)||Se(e)||Ie(e)?"2d"===t.type||R(e):me(e)||he(e)||pe(e)||we(e)||Le(e)||Ee(e)||ye(e)||de(e)}function Re(e){return"esri.layers.BuildingSceneLayer"===e.declaredClass}function Fe(e){return"esri.layers.VoxelLayer"===e.declaredClass}function Ve(e){return"esri.layers.WMSLayer"===e.declaredClass}function Te(e){return"esri.layers.WMTSLayer"===e.declaredClass}function ze(e){return"esri.layers.MapImageLayer"===e.declaredClass}function xe(e){return"esri.layers.TileLayer"===e.declaredClass}function je(e){return"esri.layers.FeatureLayer"===e.declaredClass}function De(e){return e.declaredClass===se}function Oe(e){return e.declaredClass===re}function Me(e){return e.declaredClass===ne}function Pe(e){return"stretch-ramp"===e.type}function Ae(e){const t="authoringInfo"in e&&(null==e?void 0:e.authoringInfo);return"univariate-color-size"===(null==t?void 0:t.type)}function Ue(e){const t="authoringInfo"in e&&(null==e?void 0:e.authoringInfo);return"univariate-color-size"===(null==t?void 0:t.type)&&"above-and-below"===(null==t?void 0:t.univariateTheme)}const Be=new Z({style:"path",path:"M10,5 L5,0 0,5 M5,0 L5,15",size:15,outline:{width:1,color:[85,85,85,1]}});let ke={},Ne=class extends r{constructor(e){super(e),this._handles=new i,this._hasColorRamp=!1,this._hasOpacityRamp=!1,this._hasSizeRamp=!1,this._webStyleSymbolCache=new Map,this._dotDensityUrlCache=new Map,this._scaleDrivenSizeVariable=null,this._hasClusterSizeVariable=!1,this.children=new n,this.layerView=null,this.layer=null,this.legendElements=[],this.parent=null,this.hideLayersNotInCurrentView=!1,this.keepCacheOnDestroy=!1,this.respectLayerVisibility=!0,this.sublayerIds=[],this.title=null,this.view=null}initialize(){const e=()=>this.notifyChange("ready");this._handles.add([p(this,"children","change",(t=>{const{added:l,removed:s}=t,r=this._handles;l.forEach((t=>{const l=`activeLayerInfo-ready-watcher-${t.layer.uid}`;r.add(f(t,"ready",e),l)})),s.forEach((e=>r.remove(e.layer.uid))),e()}))]),this.keepCacheOnDestroy||(ke={})}destroy(){this._handles.destroy(),this._handles=null,this._webStyleSymbolCache=null,this._dotDensityUrlCache=null,this._scaleDrivenSizeVariable=null,this.keepCacheOnDestroy||(ke=null)}get effectList(){const e=this.layer;let t=null;return"effect"in e&&e.effect&&(t=new w,t.effect=e.effect,t.end(),t.scale=this.scale),t}get opacity(){var e;const t=this.layer.opacity,l=null==(e=this.parent)?void 0:e.opacity,s=this.layer.parent,r=s&&"uid"in s?this._getParentLayerOpacity(s):null;return null!=l?l*t:null!=r?r*t:t}get ready(){return null===this.layer||(this.children.length>0?this._isGroupActive():this.legendElements.length>0)}get scale(){return this.view&&this.view.scale}get isScaleDriven(){const e=this.layer;if(null===e)return!1;if("effect"in e&&e.effect&&Array.isArray(e.effect))return!0;if("featureReduction"in e&&e.featureReduction&&"cluster"===e.featureReduction.type)return!0;if("renderer"in e&&e.renderer){if("dot-density"===e.renderer.type)return!0;const t=e.get("renderer.valueExpression");if(ie.test(t))return!0;const l=e.get("renderer.visualVariables");if(l)return l.some((e=>this._isScaleDrivenSizeVariable(e)))}return this._isLayerScaleDriven(this.layer)}get version(){return this._get("version")+1}async buildLegendElementsForFeatureCollections(e){if(!(!this.hideLayersNotInCurrentView||await this._isLayerInCurrentView()))return this.legendElements=[],void this.notifyChange("ready");const t=Array.from(e,(e=>{if(je(e))return this._getRendererLegendElements(e.renderer,{title:e.title});if(e.featureSet&&e.featureSet.features.length){const t=e.layerDefinition,l=t&&t.drawingInfo,s=l&&C(l.renderer),r=ae.read(t.geometryType);return s?this._getRendererLegendElements(s,{title:e.name,geometryType:r}):(te.warn("drawingInfo not available!"),null)}return null}));try{const e=[];await d(t).then((t=>{t.forEach((({value:t})=>t&&e.push(...t)))})),this.legendElements=e,this.notifyChange("ready")}catch(l){te.warn("error while building legend for layer!",l)}}async buildLegendElementsForRenderer(e){try{const t=!this.hideLayersNotInCurrentView||await this._isLayerInCurrentView();this.legendElements=t?await this._getRendererLegendElements(e):[],this.notifyChange("ready")}catch(t){te.warn("error while building legend for layer!",t)}}async buildLegendElementsForTools(){const e=this.layer;if(Fe(e))this._constructLegendElementsForVoxellayer();else if(Te(e))this._constructLegendElementsForWMTSlayer();else if(Ve(e))await this._constructLegendElementsForWMSSublayers();else if(Re(e))await this._constructLegendElementsForBuildingSceneLayer();else if(ze(e)||xe(e)||Re(e))await this._constructLegendElementsForSublayers();else{this._handles.remove("imageryLayers-watcher");let s="default";if(De(e)){var t,l;const r=e;s=((null==r||null==(t=r.renderingRule)?void 0:t.functionName)||"default")+"_"+(null!=(l=e.bandIds)&&l.length?e.bandIds.join(""):"###")}await this._getLegendLayers(`${e.uid}-${s}`).then((async t=>{this.legendElements=[],this.notifyChange("ready");const l=t.map((async t=>{if(De(e)||Oe(e)){const t=e.watch(["renderingRule","bandIds"],(()=>y((async()=>{ke.default=null,e.renderer?await this.buildLegendElementsForRenderer(e.renderer):await this.buildLegendElementsForTools()}))()));this._handles.add(t,"imageryLayers-watcher")}const l=this._generateSymbolTableElementForLegendLayer(t);l&&l.infos.length&&(De(e)&&(l.title=e.title),this.legendElements.push(l)),this.notifyChange("ready")}));await d(l)})).catch((e=>{te.warn("Request to server for legend has failed!",e)}))}}async _isLayerInCurrentView(){const e=this.layer,t=this.layerView,l=t&&"createQuery"in t&&"queryFeatureCount"in t;if(!l&&!(t&&"createQuery"in e&&"queryFeatureCount"in e))return!0;await g(t,"updating");const s=l?"createQuery"in t&&t.createQuery():"createQuery"in e&&e.createQuery();s.geometry=this.view.extent;return 0!==(l?"queryFeatureCount"in t&&await t.queryFeatureCount(s):"queryFeatureCount"in e&&await e.queryFeatureCount(s))}_getParentLayerOpacity(e){let t=1;const l=e.parent;return l&&"uid"in l&&(t=this._getParentLayerOpacity(l)),e.opacity*t}_isGroupActive(){const e=this.children;return!!e.length&&e.some((e=>e.ready))}_isScaleDrivenSizeVariable(e){if(e&&"size"!==e.type)return!1;const t=e,l=t.minSize,s=t.maxSize;return"object"==typeof l&&l?this._isScaleDrivenSizeVariable(l):"object"==typeof s&&s?this._isScaleDrivenSizeVariable(s):!!t.expression||ie.test(t.valueExpression)}_isLayerScaleDriven(e){if("minScale"in e&&e.minScale>0||"maxScale"in e&&e.maxScale>0)return!0;if("sublayers"in e&&e.sublayers)return e.sublayers.some((e=>this._isLayerScaleDriven(e)));const t=e.parent;if(!1===e.loaded&&t&&ze(t)&&"source"in e&&e.source&&"map-layer"===e.source.type)for(const l of t.sourceJSON.layers)if(l.id===e.source.mapLayerId&&(l.minScale>0||l.maxScale>0))return!0;return!1}async _constructLegendElementsForVoxellayer(){this.legendElements=[],this._handles.remove("voxel-style-watcher");const e=this.layer;this._handles.add(b(e,"style",(()=>this._constructLegendElementsForVoxellayer())),"voxel-style-watcher");const t=u(e.getVariableStyle(null)),l=[];var s;if(t)if(null!=(s=t.uniqueValues)&&s.length){const e=[];t.uniqueValues.forEach((t=>{t.enabled&&e.push({label:t.label||`${t.value}`,value:t.value,symbol:new ee({color:t.color,outline:null})})})),e.length&&l.push({type:"symbol-table",title:t.label,infos:e})}else if(t.transferFunction){const{colorStops:e,stretchRange:s}=t.transferFunction,r=e.toArray().reverse(),n=s.map(((e,t)=>`${0===t?J:Q} ${Y(e)}`)).reverse(),i=r.map((e=>({color:e.color,value:null,label:null})));i[0].label=n[0],i[i.length-1].label=n[1],l.push({type:"color-ramp",title:t.label,infos:i,preview:x(r.map((e=>e.color)))})}const r=e.opacity,n=l.reduce(((e,t)=>e.concat(this._getAllInfos(t))),[]).filter((e=>!(null==e||!e.symbol))).map((e=>this._getSymbolPreview(e,r)));await d(n),this.legendElements=l,this.notifyChange("ready")}_constructLegendElementsForWMTSlayer(){this.legendElements=[],this._handles.remove("wmts-activeLayer-watcher");const e=this.layer.activeLayer;if(this._handles.add(b(this.layer,"activeLayer",(()=>this._constructLegendElementsForWMTSlayer())),"wmts-activeLayer-watcher"),e.styleId&&e.styles){let t=null;e.styles.some((l=>e.styleId===l.id&&(t=l.legendUrl,!0))),t&&(this.legendElements=[{type:"symbol-table",title:e.title,infos:[{src:t,opacity:this.opacity}]}])}this.notifyChange("ready")}async _constructLegendElementsForWMSSublayers(){this.legendElements=[],this._handles.remove("wms-sublayers-watcher");const e=this.layer;let t=null;(e.customParameters||e.customLayerParameters)&&(t={...e.customParameters,...e.customLayerParameters}),this._handles.add(b(this.layer,"sublayers",(()=>this._constructLegendElementsForWMSSublayers())),"wms-sublayers-watcher"),this.legendElements=await this._generateLegendElementsForWMSSublayers(e.sublayers,t),this.notifyChange("ready")}async _generateLegendElementsForWMSSublayers(e,t){const l=[];this._handles.add(e.on("change",(()=>this._constructLegendElementsForWMSSublayers())),"wms-sublayers-watcher");const s=e.toArray();for(const r of s){const e=r.watch(["title","visible","legendEnabled"],(()=>this._constructLegendElementsForWMSSublayers()));if(this._handles.add(e,"wms-sublayers-watcher"),!this.respectLayerVisibility||r.visible&&r.legendEnabled){const e=await this._generateSymbolTableElementForWMSSublayer(r,t);e&&e.infos.length&&l.unshift(e)}}return l}async _generateSymbolTableElementForWMSSublayer(e,t){if(!e.legendUrl&&e.sublayers){const l=(await this._generateLegendElementsForWMSSublayers(e.sublayers,t)).filter((e=>e));return{type:"symbol-table",title:e.title,infos:l}}return this._generateSymbolTableElementForLegendUrl(e,t)}async _generateSymbolTableElementForLegendUrl(e,t){var l;let r=e.legendUrl;if(!r)return;const n={type:"symbol-table",title:e.title||e.name||e.id&&e.id+"",infos:[]};t&&(r=m(r,t));let i=null;const a=null==(l=e.layer)?void 0:l.opacity;try{i=(await s(r,{responseType:"image"})).data,i&&(i.style.opacity=a)}catch{}return n.infos.push({src:r,preview:i,opacity:a}),n}_getLegendLayers(e,t){const l=ke&&ke[e];return l?Promise.resolve(l):this._legendRequest(t).then((t=>{const l=t.layers;return ke[e]=l,l}))}_legendRequest(e){const t=this.layer;let l={f:"json",dynamicLayers:e};if(De(t)){const e=t.exportImageServiceParameters.renderingRule;if(e&&(l.renderingRule=JSON.stringify(e.rasterFunctionDefinition||e.toJSON())),t.bandIds&&(l.bandIds=t.bandIds.join()),t.raster||t.viewId||t.customParameters){const{raster:e,viewId:s,customParameters:r}=t;l={raster:e,viewId:s,...l,...r}}}let r=t.url.replace(/(\/)+$/,"");if("version"in t&&t.version>=10.01){const e=r.indexOf("?");e>-1?r=r.substring(0,e)+"/legend"+r.substring(e):r+="/legend"}else{const e=r.toLowerCase().indexOf("/rest/"),t=r.substring(0,e)+r.substring(e+5,r.length);r=le+"?soapUrl="+encodeURI(t)+"&returnbytes=true"}return s(r,{query:l}).then((e=>e.data))}async _constructLegendElementsForBuildingSceneLayer(){this.legendElements=[],this._handles.remove("sublayers-watcher");const e=this.layer;this._handles.add(b(e,"sublayers",(()=>this._constructLegendElementsForBuildingSceneLayer())),"sublayers-watcher");try{this.legendElements=await this._generateLegendElementsForBuildingSublayers(e.sublayers,this.opacity),this.notifyChange("ready")}catch(t){te.warn("Request to server for legend has failed!",t)}}async _generateLegendElementsForBuildingSublayers(e,t){let l=[];this._handles.add(e.on("change",(()=>this._constructLegendElementsForBuildingSceneLayer())),"sublayers-watcher");const s=e.toArray();for(const r of s){const e=r.watch(["renderer","opacity","title","visible"],(()=>this._constructLegendElementsForBuildingSceneLayer()));if(this._handles.add(e,"sublayers-watcher"),!this.respectLayerVisibility||r.visible){const e=r&&null!=r.opacity?r.opacity:null,s=null!=e?e*t:t;if("building-group"===r.type){const e={type:"symbol-table",title:r.title,infos:[]},t=await this._generateLegendElementsForBuildingSublayers(r.sublayers,s);e.infos.push(...t),l=[e,...l]}else if(r.renderer){l=[...await this._getRendererLegendElements(r.renderer,{title:r.title,opacity:s,sublayer:r}),...l]}}}return l.filter((e=>!!e&&(!("infos"in e)||e.infos.length>0)))}async _constructLegendElementsForSublayers(){this.legendElements=[],this._handles.remove("sublayers-watcher");const e=this.layer;this._handles.add(b(e,"sublayers",(()=>this._constructLegendElementsForSublayers)),"sublayers-watcher");try{this.legendElements=await this._generateLegendElementsForSublayers(e.sublayers,this.opacity),this.notifyChange("ready")}catch(t){te.warn("Request to server for legend has failed!",t)}}async _generateLegendElementsForSublayers(e,t,l){const s=this.layer;let r=[];this._handles.add(e.on("change",(()=>this._constructLegendElementsForSublayers())),"sublayers-watcher");let n=e.toArray();!l&&this.sublayerIds&&this.sublayerIds.length&&(n=this.sublayerIds.map((e=>s.findSublayerById(e))).filter(Boolean));for(const i of n){const e=i.watch("renderer, opacity, title, visible, legendEnabled",(()=>this._constructLegendElementsForSublayers()));if(this._handles.add(e,"sublayers-watcher"),!this.respectLayerVisibility||i.visible&&i.legendEnabled&&this._isSublayerInScale(i)){const e=i&&null!=i.opacity?i.opacity:null,s=null!=e?e*t:t;if(i.renderer&&!i.sublayers&&i.originIdOf("renderer")>v.SERVICE){await i.load();r=[...await this._getRendererLegendElements(i.renderer,{title:i.title,opacity:s,sublayer:i}),...r]}else{const e=await this._generateSymbolTableElementForSublayer(i,s,l);e&&r.unshift(e)}}}return r.filter((e=>!!e&&(!("infos"in e)||e.infos.length>0)))}async _generateSymbolTableElementForSublayer(e,t,l){if(!l){l=new Map;const t=this.layer,s=e.source;let r=null;if(!(!s||"map-layer"===s.type&&s.mapLayerId===e.id&&(!s.gdbVersion||s.gdbVersion===("gdbVersion"in t&&t.gdbVersion)))||e.originIdOf("renderer")>v.SERVICE||e.originIdOf("labelingInfo")>v.SERVICE||e.originIdOf("labelsVisible")>v.SERVICE){const e=new E({layer:this.layer});r=e.hasDynamicLayers?e.dynamicLayers:null,e.destroy()}const n=r||`${t.uid}-default`;(await this._getLegendLayers(n,r)).forEach((e=>l.set(e.layerId,e)))}const s=l.get(e.id);if((!s||null!=s&&s.subLayerIds&&s.defaultVisibility)&&e.sublayers){const s=await this._generateLegendElementsForSublayers(e.sublayers,t,l);return{type:"symbol-table",title:e.title,infos:s}}return this._generateSymbolTableElementForLegendLayer(s,e,t)}_generateSymbolTableElementForLegendLayer(e,t,l){var s;if(!e||!e.legend||this.respectLayerVisibility&&!this._isLegendLayerInScale(e,t))return null;const r=null==t?void 0:t.renderer;let n=(null==t?void 0:t.title)||e.layerName;if(r&&(!t||(null==t?void 0:t.originIdOf("renderer"))>v.SERVICE)){const e=(null==t?void 0:t.title)||this._getRendererTitle(r,t);e&&(n&&"string"!=typeof e&&"title"in e&&(e.title=n),n=e)}const i={type:"symbol-table",title:n,legendType:e.legendType?e.legendType:null,infos:[]},a=t?this._sanitizeLegendForSublayer(e.legend.slice(),t):e.legend;return(null==(s=e.legendGroups)?void 0:s.length)>0?e.legendGroups.forEach((t=>{var s;const r={type:"symbol-table",title:t.heading,legendType:e.legendType?e.legendType:null,infos:this._generateSymbolTableElementInfosForLegendLayer(a.filter((e=>e.groupId===t.id)),e.layerId,l)};(null==(s=r.infos)?void 0:s.length)>0&&i.infos.push(r)})):i.infos=this._generateSymbolTableElementInfosForLegendLayer(a,e.layerId,l),i.infos.length>0?i:null}_generateSymbolTableElementInfosForLegendLayer(e,t,s){return e.map((e=>{let r=e.url;if(e.imageData&&e.imageData.length>0)r=`data:image/png;base64,${e.imageData}`;else{if(0===r.indexOf("http"))return null;r=l(`${this.layer.url}/${t}/images/${r}`)}return{label:e.label,src:r,opacity:null==s?this.opacity:s,width:e.width,height:e.height}})).filter((e=>!!e))}_isSublayerInScale(e){const t=e.minScale||0,l=e.maxScale||0;return!(t>0&&t<this.scale||l>this.scale)}_isLegendLayerInScale(e,t){const l=t||this.layer;let s=null,r=null,n=!0;return!l.minScale&&0!==l.minScale||!l.maxScale&&0!==l.maxScale?(0===e.minScale&&l.tileInfo&&(s=l.tileInfo.lods[0].scale),0===e.maxScale&&l.tileInfo&&(r=l.tileInfo.lods[l.tileInfo.lods.length-1].scale)):(s=Math.min(l.minScale,e.minScale)||l.minScale||e.minScale,r=Math.max(l.maxScale,e.maxScale)),(s>0&&s<this.scale||r>this.scale)&&(n=!1),n}_sanitizeLegendForSublayer(e,t){if("version"in this.layer&&this.layer.version<10.1||0===e.length)return e;const l=t.renderer,s=e.some((e=>e.values));let r=null,n=null;return s&&e.some(((e,t)=>(e.values||(r=t,n=e,n.label||(n.label="others")),null!=n))),l?"unique-value"===l.type?n&&(e.splice(r,1),e.push(n)):"class-breaks"===l.type&&(n&&e.splice(r,1),e.reverse(),n&&e.push(n)):n&&(e.splice(r,1),e.push(n)),e}async _getRendererLegendElements(e,t={}){return Ce(e,this.view)?_e(e)?this._constructPointCloudRendererLegendElements(e,t):Ie(e)?this._constructDotDensityRendererLegendElements(e):this._constructRendererLegendElements(e,t):(te.warn(`Renderer of type '${e.type}' not supported!`),[])}_getPointCloudRendererTitle(e){return e.legendOptions&&e.legendOptions.title||e.field}_constructPointCloudRendererLegendElements(e,t={}){const l=t.title,s=[];let r=null,n=null;if(we(e))r={type:"symbol-table",title:l||this._getPointCloudRendererTitle(e),infos:[]},e.colorClassBreakInfos.forEach((e=>{r.infos.unshift({label:e.label||e.minValue+" - "+e.maxValue,value:[e.minValue,e.maxValue],symbol:this._getAppliedCloneSymbol(ue,e.color)})}));else if(Le(e)){const t=e.stops;let s=null;if(t.length&&(1===t.length&&(s=t[0].color),!s)){const e=t[0].value,l=t[t.length-1].value;if(null!=e&&null!=l){s=P(e+(l-e)/2,t)}}r={type:"symbol-table",title:null,infos:[{label:null,value:null,symbol:this._getAppliedCloneSymbol(ue,s||ue.color)}]};const i=A(e.stops);n={type:"color-ramp",title:l||this._getPointCloudRendererTitle(e),infos:i,preview:x(i.map((e=>e.color)))}}else Ee(e)&&(r={type:"symbol-table",title:l||this._getPointCloudRendererTitle(e),infos:[]},e.colorUniqueValueInfos.forEach((e=>{r.infos.push({label:e.label||e.values.join(", "),value:e.values.join(", "),symbol:this._getAppliedCloneSymbol(ue,e.color)})})));r&&r.infos.length&&s.push(r),n&&n.infos.length&&s.push(n);const i=s.reduce(((e,t)=>e.concat(t.infos)),[]).filter((e=>!!e.symbol)).map((t=>this._getSymbolPreview(t,this.opacity,{symbolConfig:{applyColorModulation:!!e.colorModulation}})));return d(i).then((()=>s))}_getElementInfoForDotDensity(e,t){const{backgroundColor:l,outline:s,dotSize:r}=e,n=this.effectList,i=null==n?void 0:n.effects.map((e=>e.toJSON())),a=L(i),o=r+"-"+t+"-"+l+"-"+(s&&JSON.stringify(s.toJSON()))+"-"+a,u=this._dotDensityUrlCache,c=u.has(o)?u.get(o):j(e,t);u.set(o,c);const d={shape:{type:"image",x:0,y:0,width:c.width,height:c.height,src:c.src},fill:null,stroke:null,offset:[0,0]},y=z([[d]],[c.width,c.height],{effectView:this.effectList});return{opacity:1,src:c.src,preview:y,width:c.width,height:c.height}}_constructDotDensityRendererLegendElements(e){const t=e.calculateDotValue(this.view.scale),l=e.legendOptions&&e.legendOptions.unit,s={type:"symbol-table",title:{value:t&&Math.round(t),unit:l||""},infos:[]};return e.attributes.forEach((t=>{const l=this._getElementInfoForDotDensity(e,t.color);l.label=t.label||t.valueExpressionTitle||t.field,s.infos.push(l)})),Promise.resolve([s])}async _constructRendererLegendElements(e,t={}){const{title:l,sublayer:s}=t,r=s||this.layer;let n=await this._loadRenderer(e);this._hasColorRamp=!1,this._hasOpacityRamp=!1,this._hasSizeRamp=!1,this._scaleDrivenSizeVariable=null;const i=await this._getVisualVariableLegendElements(n,r)||[],a={type:"symbol-table",title:l||this._getRendererTitle(n,r),infos:[]};let o=null,c=!1;const y=new Set;if(de(n)&&!this._hasSizeRamp){const e=await H(n);a.infos.push({label:null,symbol:e})}else if(Ae(n)){let e=l;const t=Ue(n)?"univariate-above-and-below-ramp":"univariate-color-size-ramp",s=i.findIndex((e=>"color-ramp"===e.type)),r=-1!==s?i.splice(s,1)[0]:null,a=i.findIndex((e=>"size-ramp"===e.type)),o=-1!==a?i.splice(a,1)[0]:null,u=[];r&&(e=r.title,u.push(r)),o&&(e=o.title,u.push(o)),u.length>0&&i.push({type:t,title:e,infos:u})}else if(Se(n)){const e=k(n);i.push({type:"heatmap-ramp",title:l,infos:e,preview:x(e.map((e=>e.color)),{effectList:this.effectList})})}else if(be(n)){const e=n&&n.authoringInfo;if(e&&"relationship"===e.type){const{focus:t,numClasses:l,field1:s,field2:o}=e;if(l&&s&&o){const e=[s,o];let u=N(t)||0;for(const t of e){const{field:e,normalizationField:l,label:s}=t,n=s||{field:this._getFieldAlias(e,r),normField:l&&this._getFieldAlias(l,r)},i=Be.clone();i.angle=u,a.infos.push({label:n,symbol:i}),y.add(i),u+=90}const c=q({focus:t,numClasses:l,infos:n.uniqueValueInfos});i.unshift(c)}}else{const e=n.field;n.uniqueValueInfos.forEach((t=>{t.symbol&&a.infos.push({label:t.label||this._getDomainName(e,t.value,r)||t.value,value:t.value,symbol:t.symbol})}))}n.defaultSymbol&&(a.infos.push({label:n.defaultLabel||"others",symbol:n.defaultSymbol}),c=!0)}else if(ge(n)){o=this._isUnclassedRenderer(n);(!o||!this._hasSizeRamp)&&(n.classBreakInfos.forEach((e=>{e.symbol&&a.infos.unshift({label:e.label||(o?null:e.minValue+" - "+e.maxValue),value:[e.minValue,e.maxValue],symbol:e.symbol})})),o&&(a.title=null),this._updateInfosforClassedSizeRenderer(n,a.infos)),n.defaultSymbol&&!o&&(a.infos.push({label:n.defaultLabel||"others",symbol:n.defaultSymbol}),c=!0)}else if(me(n))if(Oe(this.layer)||Me(this.layer)){const e=this._constructTileImageryStretchRendererElements(n);Pe(e)?i.push(e):a.infos=e}else{const e=this.layer;let t,l;n.statistics&&n.statistics.length&&(t=null!=n.statistics[0].min?n.statistics[0].min:n.statistics[0][0],l=null!=n.statistics[0].max?n.statistics[0].max:n.statistics[0][1]);let s=[];const r=u(e.renderingRule?await e.generateRasterInfo(e.renderingRule):e.serviceRasterInfo),o=r.keyProperties.BandProperties,c=oe[e.rasterInfo.pixelType.toLowerCase()];1===r.bandCount||e.bandIds&&1===e.bandIds.length?(t=null!=t?t:r.statistics?r.statistics[e.bandIds[0]].min:c[0],l=null!=l?l:r.statistics?r.statistics[e.bandIds[0]].max:c[1],t||l?i.push(this._getStretchLegendElements(n,{min:t,max:l})):this._getServerSideLegend()):r.bandCount>=3?o&&o.length>=r.bandCount?e.bandIds&&3===e.bandIds.length?(s=e.bandIds.map((e=>o[e].BandName)),a.infos=this._createSymbolTableElementMultiBand(s)):"lerc"===e.format?(s=[0,1,2].map((e=>o[e].BandName)),a.infos=this._createSymbolTableElementMultiBand(s)):this._getServerSideLegend():"lerc"===e.format?(s=["band1","band2","band3"],a.infos=this._createSymbolTableElementMultiBand(s)):this._getServerSideLegend():this._getServerSideLegend()}else if(he(n))n.colormapInfos.forEach((e=>{a.infos.push({label:e.label,value:e.value,symbol:this._getAppliedCloneSymbol(ce,e.color)})}));else if(fe(n)){let e=n.symbol;switch(t.geometryType){case"point":e="pointSymbol"in r&&r.pointSymbol;break;case"polyline":e="lineSymbol"in r&&r.lineSymbol;break;case"polygon":e="polygonSymbol"in r&&r.polygonSymbol}n.symbol&&!this._hasSizeRamp&&a.infos.push({label:n.label,symbol:e})}else if(ye(n)){n.outputUnit&&(this.title="("+n.toJSON().outputUnit+")"),a.title=n.attributeField;const e=n.getClassBreakInfos();null!=e&&e.length?e.forEach((e=>{a.infos.push({label:e.minValue+" - "+e.maxValue,symbol:e.symbol})})):a.infos.push({label:n.attributeField,symbol:n.getDefaultSymbol()})}else pe(n)&&i.push(this._getStretchLegendElements(n,{min:0,max:255}));const h=n.defaultSymbol;!h||c||fe(n)||o&&!this._hasColorRamp&&!this._hasSizeRamp&&!this._hasOpacityRamp||i.push({type:"symbol-table",infos:[{label:n.defaultLabel||"others",symbol:h}]}),a.infos.length&&i.unshift(a);const m=null==t.opacity?this.opacity:t.opacity,p=this._isTallSymbol("visualVariables"in n&&n.visualVariables),f=De(this.layer)||Oe(this.layer),g=i.reduce(((e,t)=>e.concat(this._getAllInfos(t))),[]).filter((e=>!(null==e||!e.symbol))).map((e=>this._getSymbolPreview(e,m,{isDefault:e.symbol===h,applyScaleDrivenSize:!y.has(e.symbol),symbolConfig:{isTall:p,isSquareFill:f},effectList:y.has(e.symbol)?null:this.effectList})));return n=null,await d(g),i}_getServerSideLegend(){setTimeout((()=>this.buildLegendElementsForTools()),0)}_getAllInfos(e){const t=null==e?void 0:e.infos;return t?t.reduce(((e,t)=>e.concat(this._getAllInfos(t))),[]):[e]}_constructTileImageryStretchRendererElements(e){var t,l;const s=this.layer,r=s.rasterInfo,n=r.bandCount||e.statistics.length;let i,a,o=[];const u=r.keyProperties&&r.keyProperties.BandProperties,c=null!=e&&null!=(t=e.statistics)&&t.length?e.statistics:null==r?void 0:r.statistics;if(c)i=void 0!==c[0].min?c[0].min:c[0][0],a=c[0].max||c[0][1];else{const e=oe[s.rasterInfo.pixelType.toLowerCase()];i=e[0],a=e[1]}if(s.hasStandardTime()&&(i=s.getStandardTimeValue(i),a=s.getStandardTimeValue(a)),1===r.bandCount||1===(null==(l=s.bandIds)?void 0:l.length))return this._getStretchLegendElements(e,{min:i,max:a});function d(e){var t;const l=(null!=s&&null!=(t=s.bandIds)&&t.length?s.bandIds:Array.from(Array(Math.min(r.bandCount,3)).keys())).map((t=>e&&e[t]&&e[t].BandName||"band"+(t+1)));return l.length<3?l.push(l[1]):l.length>3&&l.splice(3),l}return o=u&&u.length>=n?d(u):d(),this._createSymbolTableElementMultiBand(o)}_getStretchLegendElements(e,t){const l=e.colorRamp,s=U(l,t);return{type:"stretch-ramp",title:"",infos:s,preview:x(s.map((e=>e.color)))}}async _getSizeLegendElement(e,t,l,s){return{type:"size-ramp",title:this._hasClusterSizeVariable?this._getClusterTitle(t):e,infos:await W(l,t,await X(l),this.scale,this.view.type,s)}}_createSymbolTableElementMultiBand(e){const t=[],l=["red","green","blue"];return e.forEach(((e,s)=>{t.push({label:{colorName:l[s],bandName:e},src:K[s],opacity:1})})),t}_updateInfosforClassedSizeRenderer(e,t){const l=e.authoringInfo&&"class-breaks-size"===e.authoringInfo.type,s=e.classBreakInfos.some((e=>O(e.symbol)));if(l&&s){const l=$,s=G,r=e.classBreakInfos.length,n=(l-s)/(r>1?r-1:r);t.forEach(((e,t)=>{e.size=l-n*t}))}}_isTallSymbol(e){let t=!1,l=!1;if(e)for(let s=0;s<e.length&&(!t||!l);s++){const r=e[s];"size"===r.type&&("height"===r.axis&&(t=!0),"width-and-depth"===r.axis&&(l=!0))}return t&&l}async _getSymbolPreview(e,t,l){let s=null!=l&&l.isDefault||null!=e.size||!this._hasSizeRamp?e.size:h(T.size);if(this._scaleDrivenSizeVariable&&null!=l&&l.applyScaleDrivenSize){const{getSize:t}=await import("../../../renderers/visualVariables/support/visualVariableUtils.js");s=t(this._scaleDrivenSizeVariable,null,{view:this.view.type,scale:this.scale,shape:"simple-marker"===e.symbol.type?e.symbol.style:null})}return D(e.symbol,{size:s,opacity:t,scale:!1,symbolConfig:null==l?void 0:l.symbolConfig,effectView:null==l?void 0:l.effectList}).then((t=>(e.preview=t,e))).catch((()=>(e.preview=null,e)))}async _loadRenderer(e){var t,l;const s=[],r=this.layer;e=e.clone(),this._hasClusterSizeVariable=!1;const n="visualVariables"in e&&(null==(t=e.visualVariables)?void 0:t.some((e=>"size"===e.type&&"outline"!==e.target&&!ie.test(e.valueExpression))));if(e&&"visualVariables"in e&&!n&&"featureReduction"in r&&"cluster"===(null==(l=r.featureReduction)?void 0:l.type)){const t=this.layerView._effectiveRenderer,l=u(M(t,this.view));if(l){const t=r.featureReduction;if("clusterMinSize"in t&&"clusterMaxSize"in t){const{clusterMinSize:e,clusterMaxSize:s}=t;l.legendOptions=new F({showLegend:e!==s})}const s=e.visualVariables||[];e.visualVariables=s.concat([l]),this._hasClusterSizeVariable=!0}}const i=await X(e);if(ge(e)||be(e)){const t=(e.classBreakInfos||e.uniqueValueInfos).map((e=>this._fetchSymbol(e.symbol,i).then((t=>{e.symbol=t})).catch((()=>{e.symbol=null}))));Array.prototype.push.apply(s,t)}return s.push(this._fetchSymbol(e.symbol||e.defaultSymbol,e.defaultSymbol?null:i).then((t=>{this._applySymbolToRenderer(e,t,fe(e))})).catch((()=>{this._applySymbolToRenderer(e,null,fe(e))}))),d(s).then((()=>e))}_applySymbolToRenderer(e,t,l){l?e.symbol=t:e.defaultSymbol=t}_fetchSymbol(e,t){if(!e)return Promise.reject();if("web-style"===e.type){const l=e.portal,s=l&&l.url,r=l&&l.user&&l.user.username,n=e.name+"-"+e.styleName+"-"+e.styleUrl+"-"+s+"-"+r,i=this._webStyleSymbolCache;return i.has(n)||("2d"===this.view.type?i.set(n,e.fetchCIMSymbol()):i.set(n,e.fetchSymbol())),i.get(n).then((e=>this._getAppliedCloneSymbol(e,t))).catch((()=>(te.warn("Fetching web-style failed!"),Promise.reject())))}return Promise.resolve(this._getAppliedCloneSymbol(e,t))}_getAppliedCloneSymbol(e,l){if(!e||!l)return e;const s=e.clone(),r=l&&l.toRgba();return s.type.includes("3d")?this._applyColorTo3dSymbol(s,r):"cim"===s.type?V(s,l):s.color&&(s.color=new t(r||s.color)),s}_applyColorTo3dSymbol(e,l){l&&e.symbolLayers.forEach((e=>{e&&(e.material||(e.material={}),e.material.color=new t(l))}))}async _getVisualVariableLegendElements(e,t){if(!("visualVariables"in e)||!e.visualVariables||"vector-field"===e.type)return null;const l=e.visualVariables,s=[],r=[],n=[];for(const c of l)"color"===c.type?s.push(c):"size"===c.type?r.push(c):"opacity"===c.type&&n.push(c);const i=[...s,...r,...n];let a,o;if(0===s.length&&ge(e)&&e.classBreakInfos&&1===e.classBreakInfos.length){const t=e.classBreakInfos[0];a=t&&t.symbol}if(0===s.length&&fe(e)&&(a=e.symbol),a)if(a.type.includes("3d")){const e=a.symbolLayers.getItemAt(0);"water"===e.type?c(e.color)&&(o=e.color):c(e.material)&&c(e.material.color)&&(o=e.material.color)}else a.url||(o=a.color);const u=this.effectList;return(await Promise.all(i.map((async l=>{if(!l.legendOptions||!1!==l.legendOptions.showLegend){const s=de(e)?l.field:this._getRampTitle(l,t);let r=null;const n="getField"in t&&t.getField&&t.getField(l.field),i=n&&I(n);if("color"===l.type){const e=await B(l,null,i);r={type:"color-ramp",title:s,infos:e,preview:x(e.map((e=>e.color)),{effectList:u})},this._hasColorRamp||(this._hasColorRamp=!(null==r.infos||!r.infos.length))}else if("size"===l.type&&"outline"!==l.target)ie.test(l.valueExpression)?this._hasClusterSizeVariable||(this._scaleDrivenSizeVariable=l):(r=await this._getSizeLegendElement(s,l,e,i),this._hasSizeRamp||(this._hasSizeRamp=!(null==r.infos||!r.infos.length)));else if("opacity"===l.type){const e=await B(l,o,i);r={type:"opacity-ramp",title:s,infos:e,preview:x(e.map((e=>e.color)),{effectList:u})},this._hasOpacityRamp||(this._hasOpacityRamp=!(null==r.infos||!r.infos.length))}return r&&r.infos?r:null}})))).filter((e=>!!e))}_getDomainName(e,t,l){if(e&&"function"!=typeof e){const s="getField"in l&&l.getField&&l.getField(e),r=s&&"getFieldDomain"in l&&l.getFieldDomain?l.getFieldDomain(s.name):null;return r&&"coded-value"===r.type?r.getName(t):null}return null}_getClusterTitle(e){const t=this.layer,l=e.field;if("featureReduction"in t&&t.featureReduction&&"cluster"===t.featureReduction.type){const e=t.featureReduction,s="popupTemplate"in e&&e.popupTemplate,r=s&&s.fieldInfos;if(r)for(const t of r)if(t.fieldName===l)return"cluster_count"===l?t.label||{showCount:!0}:t.label}return{showCount:!0}}_getRampTitle(e,t){let l=e.field,s=e.normalizationField,r=!1,n=!1,i=!1,a=null;l="function"==typeof l?null:l,s="function"==typeof s?null:s;const o=e.legendOptions&&e.legendOptions.title;if(null!=o)a=o;else if(e.valueExpressionTitle)a=e.valueExpressionTitle;else{if("renderer"in t&&t.renderer&&"authoringInfo"in t.renderer&&t.renderer.authoringInfo&&t.renderer.authoringInfo.visualVariables){const e=t.renderer.authoringInfo.visualVariables;for(let t=0;t<e.length;t++){const l=e[t];if("color"===l.type){if("ratio"===l.style){r=!0;break}if("percent"===l.style){n=!0;break}if("percent-of-total"===l.style){i=!0;break}}}}a={field:l&&this._getFieldAlias(l,t),normField:s&&this._getFieldAlias(s,t),ratio:r,ratioPercent:n,ratioPercentTotal:i}}return a}_getRendererTitle(e,t){const l=e;if(l.legendOptions&&l.legendOptions.title)return l.legendOptions.title;if(l.valueExpressionTitle)return l.valueExpressionTitle;let s=l.field,r=null,n=null;ge(l)&&(r=l.normalizationField,n="percent-of-total"===l.normalizationType),s="function"==typeof s?null:s,r="function"==typeof r?null:r;let i=null;return(s||r)&&(i={field:s&&this._getFieldAlias(s,t),normField:r&&this._getFieldAlias(r,t),normByPct:n}),i}_getFieldAlias(e,t){const l="popupTemplate"in t&&t.popupTemplate,s=l&&l.fieldInfos;let r=null;s&&s.some((t=>e===t.fieldName&&(r=t,!0)));let n=null;"getField"in t&&t.getField?n=t.getField(e):"fieldsIndex"in t&&t.fieldsIndex&&(n=t.fieldsIndex.get(e));const i=r||n;let a=null;return i&&(a=r&&r.label||n&&n.alias||"name"in i&&i.name||"fieldName"in i&&i.fieldName),a}_isUnclassedRenderer(e){const t=e.visualVariables;let l=!1;return ge(e)&&e.classBreakInfos&&1===e.classBreakInfos.length&&t&&(l=e.field?t.some((t=>!(!t||e.field!==t.field||(e.normalizationField||t.normalizationField)&&e.normalizationField!==t.normalizationField))):!!t.length),l}};e([S()],Ne.prototype,"children",void 0),e([S({readOnly:!0})],Ne.prototype,"effectList",null),e([S()],Ne.prototype,"layerView",void 0),e([S()],Ne.prototype,"layer",void 0),e([S()],Ne.prototype,"legendElements",void 0),e([S({readOnly:!0})],Ne.prototype,"opacity",null),e([S()],Ne.prototype,"parent",void 0),e([S({readOnly:!0,dependsOn:[]})],Ne.prototype,"ready",null),e([S()],Ne.prototype,"hideLayersNotInCurrentView",void 0),e([S()],Ne.prototype,"keepCacheOnDestroy",void 0),e([S()],Ne.prototype,"respectLayerVisibility",void 0),e([S({readOnly:!0})],Ne.prototype,"scale",null),e([S()],Ne.prototype,"sublayerIds",void 0),e([S({readOnly:!0})],Ne.prototype,"isScaleDriven",null),e([S()],Ne.prototype,"title",void 0),e([S({readOnly:!0,dependsOn:["ready"],value:0})],Ne.prototype,"version",null),e([S()],Ne.prototype,"view",void 0),Ne=e([_("esri.widgets.Legend.support.ActiveLayerInfo")],Ne);const qe=Ne;export{qe as default};
5
+ import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Color.js";import{addTokenParameter as l}from"../../../kernel.js";import s from"../../../request.js";import"../../../symbols.js";import r from"../../../core/Accessor.js";import n from"../../../core/Collection.js";import i from"../../../core/Handles.js";import{JSONMap as a}from"../../../core/jsonMap.js";import o from"../../../core/Logger.js";import{unwrap as u,isSome as c}from"../../../core/maybe.js";import{eachAlways as d,debounce as y}from"../../../core/promiseUtils.js";import{px2pt as h}from"../../../core/screenUtils.js";import{addQueryParameters as m}from"../../../core/urlUtils.js";import{on as p,init as f,whenFalseOnce as g,watch as b}from"../../../core/watchUtils.js";import{property as S}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/arrayUtils.js";import"../../../core/has.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as _}from"../../../core/accessorSupport/decorators/subclass.js";import{OriginId as v}from"../../../core/accessorSupport/PropertyOrigin.js";import{EffectView as w}from"../../../layers/effects/EffectView.js";import{effectFunctionsFromJSON as L}from"../../../layers/effects/jsonUtils.js";import{ExportImageParameters as E}from"../../../layers/support/ExportImageParameters.js";import{isDateField as I}from"../../../layers/support/fieldUtils.js";import{fromJSON as C}from"../../../renderers/support/jsonUtils.js";import{isSupportedRenderer3D as R}from"../../../renderers/support/rendererConversion.js";import F from"../../../renderers/visualVariables/support/SizeVariableLegendOptions.js";import{applyCIMSymbolColor as V}from"../../../symbols/support/cimSymbolUtils.js";import{SymbolSizeDefaults as T}from"../../../symbols/support/previewUtils.js";import{renderSymbol as z}from"../../../symbols/support/renderUtils.js";import{renderColorRampPreviewHTML as x,renderDotDensityPreviewHTML as j,renderPreviewHTML as D}from"../../../symbols/support/symbolUtils.js";import{isVolumetricSymbol as O}from"../../../symbols/support/utils.js";import{getClusterSizeVariable as M}from"./clusterUtils.js";import{getColorFromPointCloudStops as P,getRampStopsForPointCloud as A,getStrectchRampStops as U,getRampStops as B}from"./colorRampUtils.js";import{getHeatmapRampStops as k}from"./heatmapRampUtils.js";import{getRotationAngleForFocus as N,getRelationshipRampElement as q}from"./relationshipRampUtils.js";import{getRampStops as W,REAL_WORLD_MAX_SIZE as $,REAL_WORLD_MIN_SIZE as G}from"./sizeRampUtils.js";import{SPECIAL_CHARS_LESS_THAN as J,SPECIAL_CHARS_GREATER_THAN as Q,getSymbolForFlowRenderer as H,getMedianColor as X,RGB_IMG_SOURCE as K}from"./utils.js";import{formatNumberLabel as Y}from"../../smartMapping/support/utils.js";import Z from"../../../symbols/SimpleMarkerSymbol.js";import ee from"../../../symbols/SimpleFillSymbol.js";const te=o.getLogger("esri.widgets.Legend.support.ActiveLayerInfo"),le="https://utility.arcgis.com/sharing/tools/legend",se="esri.layers.ImageryLayer",re="esri.layers.ImageryTileLayer",ne="esri.layers.WCSLayer",ie=/^\s*(return\s+)?\$view\.scale\s*(;)?\s*$/i,ae=new a({esriGeometryPoint:"point",esriGeometryMultipoint:"multipoint",esriGeometryPolyline:"polyline",esriGeometryPolygon:"polygon",esriGeometryMultiPatch:"multipatch"}),oe={u1:[0,1],u2:[0,3],u4:[0,15],u8:[0,255],s8:[-128,127],u16:[0,65535],s16:[-32768,32767],u32:[0,4294967295],s32:[-2147483648,2147483647],f32:[-34e38,34e38],f64:[-Number.MAX_VALUE,Number.MAX_VALUE]},ue=new Z({size:6,outline:{color:[128,128,128,.5],width:.5}}),ce=new ee({style:"solid"});function de(e){return"flow"===e.type}function ye(e){return"vector-field"===e.type}function he(e){return"raster-colormap"===e.type}function me(e){return"raster-stretch"===e.type}function pe(e){return"raster-shaded-relief"===e.type}function fe(e){return"esri.renderers.SimpleRenderer"===e.declaredClass}function ge(e){return"esri.renderers.ClassBreaksRenderer"===e.declaredClass}function be(e){return"esri.renderers.UniqueValueRenderer"===e.declaredClass}function Se(e){return"esri.renderers.HeatmapRenderer"===e.declaredClass}function _e(e){return we(e)||Le(e)||Ee(e)||ve(e)}function ve(e){return"esri.renderers.PointCloudRGBRenderer"===e.declaredClass}function we(e){return"esri.renderers.PointCloudClassBreaksRenderer"===e.declaredClass}function Le(e){return"esri.renderers.PointCloudStretchRenderer"===e.declaredClass}function Ee(e){return"esri.renderers.PointCloudUniqueValueRenderer"===e.declaredClass}function Ie(e){return"esri.renderers.DotDensityRenderer"===e.declaredClass}function Ce(e,t){return fe(e)||ge(e)||be(e)||Se(e)||Ie(e)?"2d"===t.type||R(e):me(e)||he(e)||pe(e)||we(e)||Le(e)||Ee(e)||ye(e)||de(e)}function Re(e){return"esri.layers.BuildingSceneLayer"===e.declaredClass}function Fe(e){return"esri.layers.VoxelLayer"===e.declaredClass}function Ve(e){return"esri.layers.WMSLayer"===e.declaredClass}function Te(e){return"esri.layers.WMTSLayer"===e.declaredClass}function ze(e){return"esri.layers.MapImageLayer"===e.declaredClass}function xe(e){return"esri.layers.TileLayer"===e.declaredClass}function je(e){return"esri.layers.FeatureLayer"===e.declaredClass}function De(e){return e.declaredClass===se}function Oe(e){return e.declaredClass===re}function Me(e){return e.declaredClass===ne}function Pe(e){return"stretch-ramp"===e.type}function Ae(e){const t="authoringInfo"in e&&(null==e?void 0:e.authoringInfo);return"univariate-color-size"===(null==t?void 0:t.type)}function Ue(e){const t="authoringInfo"in e&&(null==e?void 0:e.authoringInfo);return"univariate-color-size"===(null==t?void 0:t.type)&&"above-and-below"===(null==t?void 0:t.univariateTheme)}const Be=new Z({style:"path",path:"M10,5 L5,0 0,5 M5,0 L5,15",size:15,outline:{width:1,color:[85,85,85,1]}});let ke={},Ne=class extends r{constructor(e){super(e),this._handles=new i,this._hasColorRamp=!1,this._hasOpacityRamp=!1,this._hasSizeRamp=!1,this._webStyleSymbolCache=new Map,this._dotDensityUrlCache=new Map,this._scaleDrivenSizeVariable=null,this._hasClusterSizeVariable=!1,this.children=new n,this.layerView=null,this.layer=null,this.legendElements=[],this.parent=null,this.hideLayersNotInCurrentView=!1,this.keepCacheOnDestroy=!1,this.respectLayerVisibility=!0,this.sublayerIds=[],this.title=null,this.view=null}initialize(){const e=()=>this.notifyChange("ready");this._handles.add([p(this,"children","change",(t=>{const{added:l,removed:s}=t,r=this._handles;l.forEach((t=>{const l=`activeLayerInfo-ready-watcher-${t.layer.uid}`;r.add(f(t,"ready",e),l)})),s.forEach((e=>r.remove(e.layer.uid))),e()}))]),this.keepCacheOnDestroy||(ke={})}destroy(){this._handles.destroy(),this._handles=null,this._webStyleSymbolCache=null,this._dotDensityUrlCache=null,this._scaleDrivenSizeVariable=null,this.keepCacheOnDestroy||(ke=null)}get effectList(){const e=this.layer;let t=null;return"effect"in e&&e.effect&&(t=new w,t.effect=e.effect,t.end(),t.scale=this.scale),t}get opacity(){var e;const t=this.layer.opacity,l=null==(e=this.parent)?void 0:e.opacity,s=this.layer.parent,r=s&&"uid"in s?this._getParentLayerOpacity(s):null;return null!=l?l*t:null!=r?r*t:t}get ready(){return null===this.layer||(this.children.length>0?this._isGroupActive():this.legendElements.length>0)}get scale(){return this.view&&this.view.scale}get isScaleDriven(){const e=this.layer;if(null===e)return!1;if("effect"in e&&e.effect&&Array.isArray(e.effect))return!0;if("featureReduction"in e&&e.featureReduction&&"cluster"===e.featureReduction.type)return!0;if("renderer"in e&&e.renderer){if("dot-density"===e.renderer.type)return!0;const t=e.get("renderer.valueExpression");if(ie.test(t))return!0;const l=e.get("renderer.visualVariables");if(l)return l.some((e=>this._isScaleDrivenSizeVariable(e)))}return this._isLayerScaleDriven(this.layer)}get version(){return this._get("version")+1}async buildLegendElementsForFeatureCollections(e){if(!(!this.hideLayersNotInCurrentView||await this._isLayerInCurrentView()))return this.legendElements=[],void this.notifyChange("ready");const t=Array.from(e,(e=>{if(je(e))return this._getRendererLegendElements(e.renderer,{title:e.title});if(e.featureSet&&e.featureSet.features.length){const t=e.layerDefinition,l=t&&t.drawingInfo,s=l&&C(l.renderer),r=ae.read(t.geometryType);return s?this._getRendererLegendElements(s,{title:e.name,geometryType:r}):(te.warn("drawingInfo not available!"),null)}return null}));try{const e=[];await d(t).then((t=>{t.forEach((({value:t})=>t&&e.push(...t)))})),this.legendElements=e,this.notifyChange("ready")}catch(l){te.warn("error while building legend for layer!",l)}}async buildLegendElementsForRenderer(e){try{const t=!this.hideLayersNotInCurrentView||await this._isLayerInCurrentView();this.legendElements=t?await this._getRendererLegendElements(e):[],this.notifyChange("ready")}catch(t){te.warn("error while building legend for layer!",t)}}async buildLegendElementsForTools(){const e=this.layer;if(Fe(e))this._constructLegendElementsForVoxellayer();else if(Te(e))this._constructLegendElementsForWMTSlayer();else if(Ve(e))await this._constructLegendElementsForWMSSublayers();else if(Re(e))await this._constructLegendElementsForBuildingSceneLayer();else if(ze(e)||xe(e)||Re(e))await this._constructLegendElementsForSublayers();else{this._handles.remove("imageryLayers-watcher");let s="default";if(De(e)){var t,l;const r=e;s=((null==r||null==(t=r.renderingRule)?void 0:t.functionName)||"default")+"_"+(null!=(l=e.bandIds)&&l.length?e.bandIds.join(""):"###")}await this._getLegendLayers(`${e.uid}-${s}`).then((async t=>{this.legendElements=[],this.notifyChange("ready");const l=t.map((async t=>{if(De(e)||Oe(e)){const t=e.watch(["renderingRule","bandIds"],(()=>y((async()=>{ke.default=null,e.renderer?await this.buildLegendElementsForRenderer(e.renderer):await this.buildLegendElementsForTools()}))()));this._handles.add(t,"imageryLayers-watcher")}const l=this._generateSymbolTableElementForLegendLayer(t);l&&l.infos.length&&(De(e)&&(l.title=e.title),this.legendElements.push(l)),this.notifyChange("ready")}));await d(l)})).catch((e=>{te.warn("Request to server for legend has failed!",e)}))}}async _isLayerInCurrentView(){const e=this.layer,t=this.layerView,l=t&&"createQuery"in t&&"queryFeatureCount"in t;if(!l&&!(t&&"createQuery"in e&&"queryFeatureCount"in e))return!0;await g(t,"updating");const s=l?"createQuery"in t&&t.createQuery():"createQuery"in e&&e.createQuery();s.geometry=this.view.extent;return 0!==(l?"queryFeatureCount"in t&&await t.queryFeatureCount(s):"queryFeatureCount"in e&&await e.queryFeatureCount(s))}_getParentLayerOpacity(e){let t=1;const l=e.parent;return l&&"uid"in l&&(t=this._getParentLayerOpacity(l)),e.opacity*t}_isGroupActive(){const e=this.children;return!!e.length&&e.some((e=>e.ready))}_isScaleDrivenSizeVariable(e){if(e&&"size"!==e.type)return!1;const t=e,l=t.minSize,s=t.maxSize;return"object"==typeof l&&l?this._isScaleDrivenSizeVariable(l):"object"==typeof s&&s?this._isScaleDrivenSizeVariable(s):!!t.expression||ie.test(t.valueExpression)}_isLayerScaleDriven(e){if("minScale"in e&&e.minScale>0||"maxScale"in e&&e.maxScale>0)return!0;if("sublayers"in e&&e.sublayers)return e.sublayers.some((e=>this._isLayerScaleDriven(e)));const t=e.parent;if(!1===e.loaded&&t&&ze(t)&&"source"in e&&e.source&&"map-layer"===e.source.type)for(const l of t.sourceJSON.layers)if(l.id===e.source.mapLayerId&&(l.minScale>0||l.maxScale>0))return!0;return!1}async _constructLegendElementsForVoxellayer(){this.legendElements=[],this._handles.remove("voxel-style-watcher");const e=this.layer;this._handles.add(b(e,"style",(()=>this._constructLegendElementsForVoxellayer())),"voxel-style-watcher");const t=u(e.getVariableStyle(null)),l=[];var s;if(t)if(null!=(s=t.uniqueValues)&&s.length){const e=[];t.uniqueValues.forEach((t=>{t.enabled&&e.push({label:t.label||`${t.value}`,value:t.value,symbol:new ee({color:t.color,outline:null})})})),e.length&&l.push({type:"symbol-table",title:t.label,infos:e})}else if(t.transferFunction){const{colorStops:e,stretchRange:s}=t.transferFunction,r=e.toArray().reverse(),n=s.map(((e,t)=>`${0===t?J:Q} ${Y(e)}`)).reverse(),i=r.map((e=>({color:e.color,value:null,label:null})));i[0].label=n[0],i[i.length-1].label=n[1],l.push({type:"color-ramp",title:t.label,infos:i,preview:x(r.map((e=>e.color)))})}const r=e.opacity,n=l.reduce(((e,t)=>e.concat(this._getAllInfos(t))),[]).filter((e=>!(null==e||!e.symbol))).map((e=>this._getSymbolPreview(e,r)));await d(n),this.legendElements=l,this.notifyChange("ready")}_constructLegendElementsForWMTSlayer(){this.legendElements=[],this._handles.remove("wmts-activeLayer-watcher");const e=this.layer.activeLayer;if(this._handles.add(b(this.layer,"activeLayer",(()=>this._constructLegendElementsForWMTSlayer())),"wmts-activeLayer-watcher"),e.styleId&&e.styles){let t=null;e.styles.some((l=>e.styleId===l.id&&(t=l.legendUrl,!0))),t&&(this.legendElements=[{type:"symbol-table",title:e.title,infos:[{src:t,opacity:this.opacity}]}])}this.notifyChange("ready")}async _constructLegendElementsForWMSSublayers(){this.legendElements=[],this._handles.remove("wms-sublayers-watcher");const e=this.layer;let t=null;(e.customParameters||e.customLayerParameters)&&(t={...e.customParameters,...e.customLayerParameters}),this._handles.add(b(this.layer,"sublayers",(()=>this._constructLegendElementsForWMSSublayers())),"wms-sublayers-watcher"),this.legendElements=await this._generateLegendElementsForWMSSublayers(e.sublayers,t),this.notifyChange("ready")}async _generateLegendElementsForWMSSublayers(e,t){const l=[];this._handles.add(e.on("change",(()=>this._constructLegendElementsForWMSSublayers())),"wms-sublayers-watcher");const s=e.toArray();for(const r of s){const e=r.watch(["title","visible","legendEnabled"],(()=>this._constructLegendElementsForWMSSublayers()));if(this._handles.add(e,"wms-sublayers-watcher"),!this.respectLayerVisibility||r.visible&&r.legendEnabled){const e=await this._generateSymbolTableElementForWMSSublayer(r,t);e&&e.infos.length&&l.unshift(e)}}return l}async _generateSymbolTableElementForWMSSublayer(e,t){if(!e.legendUrl&&e.sublayers){const l=(await this._generateLegendElementsForWMSSublayers(e.sublayers,t)).filter((e=>e));return{type:"symbol-table",title:e.title,infos:l}}return this._generateSymbolTableElementForLegendUrl(e,t)}async _generateSymbolTableElementForLegendUrl(e,t){var l;let r=e.legendUrl;if(!r)return;const n={type:"symbol-table",title:e.title||e.name||e.id&&e.id+"",infos:[]};t&&(r=m(r,t));let i=null;const a=null==(l=e.layer)?void 0:l.opacity;try{i=(await s(r,{responseType:"image"})).data,i&&(i.style.opacity=a)}catch{}return n.infos.push({src:r,preview:i,opacity:a}),n}_getLegendLayers(e,t){const l=ke&&ke[e];return l?Promise.resolve(l):this._legendRequest(t).then((t=>{const l=t.layers;return ke[e]=l,l}))}_legendRequest(e){const t=this.layer;let l={f:"json",dynamicLayers:e};if(De(t)){const e=t.exportImageServiceParameters.renderingRule;if(e&&(l.renderingRule=JSON.stringify(e.rasterFunctionDefinition||e.toJSON())),t.bandIds&&(l.bandIds=t.bandIds.join()),t.raster||t.viewId||t.customParameters){const{raster:e,viewId:s,customParameters:r}=t;l={raster:e,viewId:s,...l,...r}}}let r=t.url.replace(/(\/)+$/,"");if("version"in t&&t.version>=10.01){const e=r.indexOf("?");e>-1?r=r.substring(0,e)+"/legend"+r.substring(e):r+="/legend"}else{const e=r.toLowerCase().indexOf("/rest/"),t=r.substring(0,e)+r.substring(e+5,r.length);r=le+"?soapUrl="+encodeURI(t)+"&returnbytes=true"}return s(r,{query:l}).then((e=>e.data))}async _constructLegendElementsForBuildingSceneLayer(){this.legendElements=[],this._handles.remove("sublayers-watcher");const e=this.layer;this._handles.add(b(e,"sublayers",(()=>this._constructLegendElementsForBuildingSceneLayer())),"sublayers-watcher");try{this.legendElements=await this._generateLegendElementsForBuildingSublayers(e.sublayers,this.opacity),this.notifyChange("ready")}catch(t){te.warn("Request to server for legend has failed!",t)}}async _generateLegendElementsForBuildingSublayers(e,t){let l=[];this._handles.add(e.on("change",(()=>this._constructLegendElementsForBuildingSceneLayer())),"sublayers-watcher");const s=e.toArray();for(const r of s){const e=r.watch(["renderer","opacity","title","visible"],(()=>this._constructLegendElementsForBuildingSceneLayer()));if(this._handles.add(e,"sublayers-watcher"),!this.respectLayerVisibility||r.visible){const e=r&&null!=r.opacity?r.opacity:null,s=null!=e?e*t:t;if("building-group"===r.type){const e={type:"symbol-table",title:r.title,infos:[]},t=await this._generateLegendElementsForBuildingSublayers(r.sublayers,s);e.infos.push(...t),l=[e,...l]}else if(r.renderer){l=[...await this._getRendererLegendElements(r.renderer,{title:r.title,opacity:s,sublayer:r}),...l]}}}return l.filter((e=>!!e&&(!("infos"in e)||e.infos.length>0)))}async _constructLegendElementsForSublayers(){this.legendElements=[],this._handles.remove("sublayers-watcher");const e=this.layer;this._handles.add(b(e,"sublayers",(()=>this._constructLegendElementsForSublayers)),"sublayers-watcher");try{this.legendElements=await this._generateLegendElementsForSublayers(e.sublayers,this.opacity),this.notifyChange("ready")}catch(t){te.warn("Request to server for legend has failed!",t)}}async _generateLegendElementsForSublayers(e,t,l){const s=this.layer;let r=[];this._handles.add(e.on("change",(()=>this._constructLegendElementsForSublayers())),"sublayers-watcher");let n=e.toArray();!l&&this.sublayerIds&&this.sublayerIds.length&&(n=this.sublayerIds.map((e=>s.findSublayerById(e))).filter(Boolean));for(const i of n){const e=i.watch("renderer, opacity, title, visible, legendEnabled",(()=>this._constructLegendElementsForSublayers()));if(this._handles.add(e,"sublayers-watcher"),!this.respectLayerVisibility||i.visible&&i.legendEnabled&&this._isSublayerInScale(i)){const e=i&&null!=i.opacity?i.opacity:null,s=null!=e?e*t:t;if(i.renderer&&!i.sublayers&&i.originIdOf("renderer")>v.SERVICE){await i.load();r=[...await this._getRendererLegendElements(i.renderer,{title:i.title,opacity:s,sublayer:i}),...r]}else{const e=await this._generateSymbolTableElementForSublayer(i,s,l);e&&r.unshift(e)}}}return r.filter((e=>!!e&&(!("infos"in e)||e.infos.length>0)))}async _generateSymbolTableElementForSublayer(e,t,l){if(!l){l=new Map;const t=this.layer,s=e.source;let r=null;if(!(!s||"map-layer"===s.type&&s.mapLayerId===e.id&&(!s.gdbVersion||s.gdbVersion===("gdbVersion"in t&&t.gdbVersion)))||e.originIdOf("renderer")>v.SERVICE||e.originIdOf("labelingInfo")>v.SERVICE||e.originIdOf("labelsVisible")>v.SERVICE){const e=new E({layer:this.layer});r=e.hasDynamicLayers?e.dynamicLayers:null,e.destroy()}const n=r||`${t.uid}-default`;(await this._getLegendLayers(n,r)).forEach((e=>l.set(e.layerId,e)))}const s=l.get(e.id);if((!s||null!=s&&s.subLayerIds&&s.defaultVisibility)&&e.sublayers){const s=await this._generateLegendElementsForSublayers(e.sublayers,t,l);return{type:"symbol-table",title:e.title,infos:s}}return this._generateSymbolTableElementForLegendLayer(s,e,t)}_generateSymbolTableElementForLegendLayer(e,t,l){var s;if(!e||!e.legend||this.respectLayerVisibility&&!this._isLegendLayerInScale(e,t))return null;const r=null==t?void 0:t.renderer;let n=(null==t?void 0:t.title)||e.layerName;if(r&&(!t||(null==t?void 0:t.originIdOf("renderer"))>v.SERVICE)){const e=(null==t?void 0:t.title)||this._getRendererTitle(r,t);e&&(n&&"string"!=typeof e&&"title"in e&&(e.title=n),n=e)}const i={type:"symbol-table",title:n,legendType:e.legendType?e.legendType:null,infos:[]},a=t?this._sanitizeLegendForSublayer(e.legend.slice(),t):e.legend;return(null==(s=e.legendGroups)?void 0:s.length)>0?e.legendGroups.forEach((t=>{var s;const r={type:"symbol-table",title:t.heading,legendType:e.legendType?e.legendType:null,infos:this._generateSymbolTableElementInfosForLegendLayer(a.filter((e=>e.groupId===t.id)),e.layerId,l)};(null==(s=r.infos)?void 0:s.length)>0&&i.infos.push(r)})):i.infos=this._generateSymbolTableElementInfosForLegendLayer(a,e.layerId,l),i.infos.length>0?i:null}_generateSymbolTableElementInfosForLegendLayer(e,t,s){return e.map((e=>{let r=e.url;if(e.imageData&&e.imageData.length>0)r=`data:image/png;base64,${e.imageData}`;else{if(0===r.indexOf("http"))return null;r=l(`${this.layer.url}/${t}/images/${r}`)}return{label:e.label,src:r,opacity:null==s?this.opacity:s,width:e.width,height:e.height}})).filter((e=>!!e))}_isSublayerInScale(e){const t=e.minScale||0,l=e.maxScale||0;return!(t>0&&t<this.scale||l>this.scale)}_isLegendLayerInScale(e,t){const l=t||this.layer;let s=null,r=null,n=!0;return!l.minScale&&0!==l.minScale||!l.maxScale&&0!==l.maxScale?(0===e.minScale&&l.tileInfo&&(s=l.tileInfo.lods[0].scale),0===e.maxScale&&l.tileInfo&&(r=l.tileInfo.lods[l.tileInfo.lods.length-1].scale)):(s=Math.min(l.minScale,e.minScale)||l.minScale||e.minScale,r=Math.max(l.maxScale,e.maxScale)),(s>0&&s<this.scale||r>this.scale)&&(n=!1),n}_sanitizeLegendForSublayer(e,t){if("version"in this.layer&&this.layer.version<10.1||0===e.length)return e;const l=t.renderer,s=e.some((e=>e.values));let r=null,n=null;return s&&e.some(((e,t)=>(e.values||(r=t,n=e,n.label||(n.label="others")),null!=n))),l?"unique-value"===l.type?n&&(e.splice(r,1),e.push(n)):"class-breaks"===l.type&&(n&&e.splice(r,1),e.reverse(),n&&e.push(n)):n&&(e.splice(r,1),e.push(n)),e}async _getRendererLegendElements(e,t={}){return Ce(e,this.view)?_e(e)?this._constructPointCloudRendererLegendElements(e,t):Ie(e)?this._constructDotDensityRendererLegendElements(e):this._constructRendererLegendElements(e,t):(te.warn(`Renderer of type '${e.type}' not supported!`),[])}_getPointCloudRendererTitle(e){return e.legendOptions&&e.legendOptions.title||e.field}_constructPointCloudRendererLegendElements(e,t={}){const l=t.title,s=[];let r=null,n=null;if(we(e))r={type:"symbol-table",title:l||this._getPointCloudRendererTitle(e),infos:[]},e.colorClassBreakInfos.forEach((e=>{r.infos.unshift({label:e.label||e.minValue+" - "+e.maxValue,value:[e.minValue,e.maxValue],symbol:this._getAppliedCloneSymbol(ue,e.color)})}));else if(Le(e)){const t=e.stops;let s=null;if(t.length&&(1===t.length&&(s=t[0].color),!s)){const e=t[0].value,l=t[t.length-1].value;if(null!=e&&null!=l){s=P(e+(l-e)/2,t)}}r={type:"symbol-table",title:null,infos:[{label:null,value:null,symbol:this._getAppliedCloneSymbol(ue,s||ue.color)}]};const i=A(e.stops);n={type:"color-ramp",title:l||this._getPointCloudRendererTitle(e),infos:i,preview:x(i.map((e=>e.color)))}}else Ee(e)&&(r={type:"symbol-table",title:l||this._getPointCloudRendererTitle(e),infos:[]},e.colorUniqueValueInfos.forEach((e=>{r.infos.push({label:e.label||e.values.join(", "),value:e.values.join(", "),symbol:this._getAppliedCloneSymbol(ue,e.color)})})));r&&r.infos.length&&s.push(r),n&&n.infos.length&&s.push(n);const i=s.reduce(((e,t)=>e.concat(t.infos)),[]).filter((e=>!!e.symbol)).map((t=>this._getSymbolPreview(t,this.opacity,{symbolConfig:{applyColorModulation:!!e.colorModulation}})));return d(i).then((()=>s))}_getElementInfoForDotDensity(e,t){const{backgroundColor:l,outline:s,dotSize:r}=e,n=this.effectList,i=null==n?void 0:n.effects.map((e=>e.toJSON())),a=L(i),o=r+"-"+t+"-"+l+"-"+(s&&JSON.stringify(s.toJSON()))+"-"+a,u=this._dotDensityUrlCache,c=u.has(o)?u.get(o):j(e,t);u.set(o,c);const d={shape:{type:"image",x:0,y:0,width:c.width,height:c.height,src:c.src},fill:null,stroke:null,offset:[0,0]},y=z([[d]],[c.width,c.height],{effectView:this.effectList});return{opacity:1,src:c.src,preview:y,width:c.width,height:c.height}}_constructDotDensityRendererLegendElements(e){const t=e.calculateDotValue(this.view.scale),l=e.legendOptions&&e.legendOptions.unit,s={type:"symbol-table",title:{value:t&&Math.round(t),unit:l||""},infos:[]};return e.attributes.forEach((t=>{const l=this._getElementInfoForDotDensity(e,t.color);l.label=t.label||t.valueExpressionTitle||t.field,s.infos.push(l)})),Promise.resolve([s])}async _constructRendererLegendElements(e,t={}){const{title:l,sublayer:s}=t,r=s||this.layer;let n=await this._loadRenderer(e);this._hasColorRamp=!1,this._hasOpacityRamp=!1,this._hasSizeRamp=!1,this._scaleDrivenSizeVariable=null;const i=await this._getVisualVariableLegendElements(n,r)||[],a={type:"symbol-table",title:l||this._getRendererTitle(n,r),infos:[]};let o=null,c=!1;const y=new Set;if(de(n)&&!this._hasSizeRamp){const e=await H(n);a.infos.push({label:null,symbol:e})}else if(Ae(n)){let e=l;const t=Ue(n)?"univariate-above-and-below-ramp":"univariate-color-size-ramp",s=i.findIndex((e=>"color-ramp"===e.type)),r=-1!==s?i.splice(s,1)[0]:null,a=i.findIndex((e=>"size-ramp"===e.type)),o=-1!==a?i.splice(a,1)[0]:null,u=[];r&&(e=r.title,u.push(r)),o&&(e=o.title,u.push(o)),u.length>0&&i.push({type:t,title:e,infos:u})}else if(Se(n)){const e=k(n);i.push({type:"heatmap-ramp",title:l,infos:e,preview:x(e.map((e=>e.color)),{effectList:this.effectList})})}else if(be(n)){const e=n&&n.authoringInfo;if(e&&"relationship"===e.type){const{focus:t,numClasses:l,field1:s,field2:o}=e;if(l&&s&&o){const e=[s,o];let u=N(t)||0;for(const t of e){const{field:e,normalizationField:l,label:s}=t,n=s||{field:this._getFieldAlias(e,r),normField:l&&this._getFieldAlias(l,r)},i=Be.clone();i.angle=u,a.infos.push({label:n,symbol:i}),y.add(i),u+=90}const c=q({focus:t,numClasses:l,infos:n.uniqueValueInfos});i.unshift(c)}}else{const e=n.field;n.uniqueValueInfos.forEach((t=>{t.symbol&&a.infos.push({label:t.label||this._getDomainName(e,t.value,r)||t.value,value:t.value,symbol:t.symbol})}))}n.defaultSymbol&&(a.infos.push({label:n.defaultLabel||"others",symbol:n.defaultSymbol}),c=!0)}else if(ge(n)){o=this._isUnclassedRenderer(n);(!o||!this._hasSizeRamp)&&(n.classBreakInfos.forEach((e=>{e.symbol&&a.infos.unshift({label:e.label||(o?null:e.minValue+" - "+e.maxValue),value:[e.minValue,e.maxValue],symbol:e.symbol})})),o&&(a.title=null),this._updateInfosforClassedSizeRenderer(n,a.infos)),n.defaultSymbol&&!o&&(a.infos.push({label:n.defaultLabel||"others",symbol:n.defaultSymbol}),c=!0)}else if(me(n))if(Oe(this.layer)||Me(this.layer)){const e=this._constructTileImageryStretchRendererElements(n);Pe(e)?i.push(e):a.infos=e}else{const e=this.layer;let t,l;n.statistics&&n.statistics.length&&(t=null!=n.statistics[0].min?n.statistics[0].min:n.statistics[0][0],l=null!=n.statistics[0].max?n.statistics[0].max:n.statistics[0][1]);let s=[];const r=u(e.renderingRule?await e.generateRasterInfo(e.renderingRule):e.serviceRasterInfo),o=r.keyProperties.BandProperties,c=oe[e.rasterInfo.pixelType.toLowerCase()];1===r.bandCount||e.bandIds&&1===e.bandIds.length?(t=null!=t?t:r.statistics?r.statistics[e.bandIds[0]].min:c[0],l=null!=l?l:r.statistics?r.statistics[e.bandIds[0]].max:c[1],t||l?i.push(this._getStretchLegendElements(n,{min:t,max:l})):this._getServerSideLegend()):r.bandCount>=3?o&&o.length>=r.bandCount?e.bandIds&&3===e.bandIds.length?(s=e.bandIds.map((e=>o[e].BandName)),a.infos=this._createSymbolTableElementMultiBand(s)):"lerc"===e.format?(s=[0,1,2].map((e=>o[e].BandName)),a.infos=this._createSymbolTableElementMultiBand(s)):this._getServerSideLegend():"lerc"===e.format?(s=["band1","band2","band3"],a.infos=this._createSymbolTableElementMultiBand(s)):this._getServerSideLegend():this._getServerSideLegend()}else if(he(n))n.colormapInfos.forEach((e=>{a.infos.push({label:e.label,value:e.value,symbol:this._getAppliedCloneSymbol(ce,e.color)})}));else if(fe(n)){let e=n.symbol;switch(t.geometryType){case"point":e="pointSymbol"in r&&r.pointSymbol;break;case"polyline":e="lineSymbol"in r&&r.lineSymbol;break;case"polygon":e="polygonSymbol"in r&&r.polygonSymbol}n.symbol&&!this._hasSizeRamp&&a.infos.push({label:n.label,symbol:e})}else if(ye(n)){n.outputUnit&&(this.title="("+n.toJSON().outputUnit+")"),a.title=n.attributeField;const e=n.getClassBreakInfos();null!=e&&e.length?e.forEach((e=>{a.infos.push({label:e.minValue+" - "+e.maxValue,symbol:e.symbol})})):a.infos.push({label:n.attributeField,symbol:n.getDefaultSymbol()})}else pe(n)&&i.push(this._getStretchLegendElements(n,{min:0,max:255}));const h=n.defaultSymbol;!h||c||fe(n)||o&&!this._hasColorRamp&&!this._hasSizeRamp&&!this._hasOpacityRamp||i.push({type:"symbol-table",infos:[{label:n.defaultLabel||"others",symbol:h}]}),a.infos.length&&i.unshift(a);const m=null==t.opacity?this.opacity:t.opacity,p=this._isTallSymbol("visualVariables"in n&&n.visualVariables),f=De(this.layer)||Oe(this.layer),g=i.reduce(((e,t)=>e.concat(this._getAllInfos(t))),[]).filter((e=>!(null==e||!e.symbol))).map((e=>this._getSymbolPreview(e,m,{isDefault:e.symbol===h,applyScaleDrivenSize:!y.has(e.symbol),symbolConfig:{isTall:p,isSquareFill:f},effectList:y.has(e.symbol)?null:this.effectList})));return n=null,await d(g),i}_getServerSideLegend(){setTimeout((()=>this.buildLegendElementsForTools()),0)}_getAllInfos(e){const t=null==e?void 0:e.infos;return t?t.reduce(((e,t)=>e.concat(this._getAllInfos(t))),[]):[e]}_constructTileImageryStretchRendererElements(e){var t,l;const s=this.layer,r=s.rasterInfo,n=r.bandCount||e.statistics.length;let i,a,o=[];const u=r.keyProperties&&r.keyProperties.BandProperties,c=null!=e&&null!=(t=e.statistics)&&t.length?e.statistics:null==r?void 0:r.statistics;if(c)i=void 0!==c[0].min?c[0].min:c[0][0],a=c[0].max||c[0][1];else{const e=oe[s.rasterInfo.pixelType.toLowerCase()];i=e[0],a=e[1]}if(s.hasStandardTime()&&(i=s.getStandardTimeValue(i),a=s.getStandardTimeValue(a)),1===r.bandCount||1===(null==(l=s.bandIds)?void 0:l.length))return this._getStretchLegendElements(e,{min:i,max:a});function d(e){var t;const l=(null!=s&&null!=(t=s.bandIds)&&t.length?s.bandIds:Array.from(Array(Math.min(r.bandCount,3)).keys())).map((t=>e&&e[t]&&e[t].BandName||"band"+(t+1)));return l.length<3?l.push(l[1]):l.length>3&&l.splice(3),l}return o=u&&u.length>=n?d(u):d(),this._createSymbolTableElementMultiBand(o)}_getStretchLegendElements(e,t){const l=e.colorRamp,s=U(l,t);return{type:"stretch-ramp",title:"",infos:s,preview:x(s.map((e=>e.color)))}}async _getSizeLegendElement(e,t,l,s){return{type:"size-ramp",title:this._hasClusterSizeVariable?this._getClusterTitle(t):e,infos:await W(l,t,await X(l),this.scale,this.view.type,s)}}_createSymbolTableElementMultiBand(e){const t=[],l=["red","green","blue"];return e.forEach(((e,s)=>{t.push({label:{colorName:l[s],bandName:e},src:K[s],opacity:1})})),t}_updateInfosforClassedSizeRenderer(e,t){const l=e.authoringInfo&&"class-breaks-size"===e.authoringInfo.type,s=e.classBreakInfos.some((e=>O(e.symbol)));if(l&&s){const l=$,s=G,r=e.classBreakInfos.length,n=(l-s)/(r>1?r-1:r);t.forEach(((e,t)=>{e.size=l-n*t}))}}_isTallSymbol(e){let t=!1,l=!1;if(e)for(let s=0;s<e.length&&(!t||!l);s++){const r=e[s];"size"===r.type&&("height"===r.axis&&(t=!0),"width-and-depth"===r.axis&&(l=!0))}return t&&l}async _getSymbolPreview(e,t,l){let s=null!=l&&l.isDefault||null!=e.size||!this._hasSizeRamp?e.size:h(T.size);if(this._scaleDrivenSizeVariable&&null!=l&&l.applyScaleDrivenSize){const{getSize:t}=await import("../../../renderers/visualVariables/support/visualVariableUtils.js");s=t(this._scaleDrivenSizeVariable,null,{view:this.view.type,scale:this.scale,shape:"simple-marker"===e.symbol.type?e.symbol.style:null})}return D(e.symbol,{size:s,opacity:t,scale:!1,symbolConfig:null==l?void 0:l.symbolConfig,effectView:null==l?void 0:l.effectList}).then((t=>(e.preview=t,e))).catch((()=>(e.preview=null,e)))}async _loadRenderer(e){var t,l;const s=[],r=this.layer;e=e.clone(),this._hasClusterSizeVariable=!1;const n="visualVariables"in e&&(null==(t=e.visualVariables)?void 0:t.some((e=>"size"===e.type&&"outline"!==e.target&&!ie.test(e.valueExpression))));if(e&&"visualVariables"in e&&!n&&"featureReduction"in r&&"cluster"===(null==(l=r.featureReduction)?void 0:l.type)){const t=this.layerView._effectiveRenderer,l=u(M(t,this.view));if(l){const t=r.featureReduction;if("clusterMinSize"in t&&"clusterMaxSize"in t){const{clusterMinSize:e,clusterMaxSize:s}=t;l.legendOptions=new F({showLegend:e!==s})}const s=e.visualVariables||[];e.visualVariables=s.concat([l]),this._hasClusterSizeVariable=!0}}const i=await X(e);if(ge(e)||be(e)){const t=(e.classBreakInfos||e.uniqueValueInfos).map((e=>this._fetchSymbol(e.symbol,i).then((t=>{e.symbol=t})).catch((()=>{e.symbol=null}))));Array.prototype.push.apply(s,t)}return s.push(this._fetchSymbol(e.symbol||e.defaultSymbol,e.defaultSymbol?null:i).then((t=>{this._applySymbolToRenderer(e,t,fe(e))})).catch((()=>{this._applySymbolToRenderer(e,null,fe(e))}))),d(s).then((()=>e))}_applySymbolToRenderer(e,t,l){l?e.symbol=t:e.defaultSymbol=t}_fetchSymbol(e,t){if(!e)return Promise.reject();if("web-style"===e.type){const l=e.portal,s=l&&l.url,r=l&&l.user&&l.user.username,n=e.name+"-"+e.styleName+"-"+e.styleUrl+"-"+s+"-"+r,i=this._webStyleSymbolCache;return i.has(n)||("2d"===this.view.type?i.set(n,e.fetchCIMSymbol()):i.set(n,e.fetchSymbol())),i.get(n).then((e=>this._getAppliedCloneSymbol(e,t))).catch((()=>{throw te.warn("Fetching web-style failed!"),new Error}))}return Promise.resolve(this._getAppliedCloneSymbol(e,t))}_getAppliedCloneSymbol(e,l){if(!e||!l)return e;const s=e.clone(),r=l&&l.toRgba();return s.type.includes("3d")?this._applyColorTo3dSymbol(s,r):"cim"===s.type?V(s,l):s.color&&(s.color=new t(r||s.color)),s}_applyColorTo3dSymbol(e,l){l&&e.symbolLayers.forEach((e=>{e&&(e.material||(e.material={}),e.material.color=new t(l))}))}async _getVisualVariableLegendElements(e,t){if(!("visualVariables"in e)||!e.visualVariables||"vector-field"===e.type)return null;const l=e.visualVariables,s=[],r=[],n=[];for(const c of l)"color"===c.type?s.push(c):"size"===c.type?r.push(c):"opacity"===c.type&&n.push(c);const i=[...s,...r,...n];let a,o;if(0===s.length&&ge(e)&&e.classBreakInfos&&1===e.classBreakInfos.length){const t=e.classBreakInfos[0];a=t&&t.symbol}if(0===s.length&&fe(e)&&(a=e.symbol),a)if(a.type.includes("3d")){const e=a.symbolLayers.getItemAt(0);"water"===e.type?c(e.color)&&(o=e.color):c(e.material)&&c(e.material.color)&&(o=e.material.color)}else a.url||(o=a.color);const u=this.effectList;return(await Promise.all(i.map((async l=>{if(!l.legendOptions||!1!==l.legendOptions.showLegend){const s=de(e)?l.field:this._getRampTitle(l,t);let r=null;const n="getField"in t&&t.getField&&t.getField(l.field),i=n&&I(n);if("color"===l.type){const e=await B(l,null,i);r={type:"color-ramp",title:s,infos:e,preview:x(e.map((e=>e.color)),{effectList:u})},this._hasColorRamp||(this._hasColorRamp=!(null==r.infos||!r.infos.length))}else if("size"===l.type&&"outline"!==l.target)ie.test(l.valueExpression)?this._hasClusterSizeVariable||(this._scaleDrivenSizeVariable=l):(r=await this._getSizeLegendElement(s,l,e,i),this._hasSizeRamp||(this._hasSizeRamp=!(null==r.infos||!r.infos.length)));else if("opacity"===l.type){const e=await B(l,o,i);r={type:"opacity-ramp",title:s,infos:e,preview:x(e.map((e=>e.color)),{effectList:u})},this._hasOpacityRamp||(this._hasOpacityRamp=!(null==r.infos||!r.infos.length))}return r&&r.infos?r:null}})))).filter((e=>!!e))}_getDomainName(e,t,l){if(e&&"function"!=typeof e){const s="getField"in l&&l.getField&&l.getField(e),r=s&&"getFieldDomain"in l&&l.getFieldDomain?l.getFieldDomain(s.name):null;return r&&"coded-value"===r.type?r.getName(t):null}return null}_getClusterTitle(e){const t=this.layer,l=e.field;if("featureReduction"in t&&t.featureReduction&&"cluster"===t.featureReduction.type){const e=t.featureReduction,s="popupTemplate"in e&&e.popupTemplate,r=s&&s.fieldInfos;if(r)for(const t of r)if(t.fieldName===l)return"cluster_count"===l?t.label||{showCount:!0}:t.label}return{showCount:!0}}_getRampTitle(e,t){let l=e.field,s=e.normalizationField,r=!1,n=!1,i=!1,a=null;l="function"==typeof l?null:l,s="function"==typeof s?null:s;const o=e.legendOptions&&e.legendOptions.title;if(null!=o)a=o;else if(e.valueExpressionTitle)a=e.valueExpressionTitle;else{if("renderer"in t&&t.renderer&&"authoringInfo"in t.renderer&&t.renderer.authoringInfo&&t.renderer.authoringInfo.visualVariables){const e=t.renderer.authoringInfo.visualVariables;for(let t=0;t<e.length;t++){const l=e[t];if("color"===l.type){if("ratio"===l.style){r=!0;break}if("percent"===l.style){n=!0;break}if("percent-of-total"===l.style){i=!0;break}}}}a={field:l&&this._getFieldAlias(l,t),normField:s&&this._getFieldAlias(s,t),ratio:r,ratioPercent:n,ratioPercentTotal:i}}return a}_getRendererTitle(e,t){const l=e;if(l.legendOptions&&l.legendOptions.title)return l.legendOptions.title;if(l.valueExpressionTitle)return l.valueExpressionTitle;let s=l.field,r=null,n=null;ge(l)&&(r=l.normalizationField,n="percent-of-total"===l.normalizationType),s="function"==typeof s?null:s,r="function"==typeof r?null:r;let i=null;return(s||r)&&(i={field:s&&this._getFieldAlias(s,t),normField:r&&this._getFieldAlias(r,t),normByPct:n}),i}_getFieldAlias(e,t){const l="popupTemplate"in t&&t.popupTemplate,s=l&&l.fieldInfos;let r=null;s&&s.some((t=>e===t.fieldName&&(r=t,!0)));let n=null;"getField"in t&&t.getField?n=t.getField(e):"fieldsIndex"in t&&t.fieldsIndex&&(n=t.fieldsIndex.get(e));const i=r||n;let a=null;return i&&(a=r&&r.label||n&&n.alias||"name"in i&&i.name||"fieldName"in i&&i.fieldName),a}_isUnclassedRenderer(e){const t=e.visualVariables;let l=!1;return ge(e)&&e.classBreakInfos&&1===e.classBreakInfos.length&&t&&(l=e.field?t.some((t=>!(!t||e.field!==t.field||(e.normalizationField||t.normalizationField)&&e.normalizationField!==t.normalizationField))):!!t.length),l}};e([S()],Ne.prototype,"children",void 0),e([S({readOnly:!0})],Ne.prototype,"effectList",null),e([S()],Ne.prototype,"layerView",void 0),e([S()],Ne.prototype,"layer",void 0),e([S()],Ne.prototype,"legendElements",void 0),e([S({readOnly:!0})],Ne.prototype,"opacity",null),e([S()],Ne.prototype,"parent",void 0),e([S({readOnly:!0,dependsOn:[]})],Ne.prototype,"ready",null),e([S()],Ne.prototype,"hideLayersNotInCurrentView",void 0),e([S()],Ne.prototype,"keepCacheOnDestroy",void 0),e([S()],Ne.prototype,"respectLayerVisibility",void 0),e([S({readOnly:!0})],Ne.prototype,"scale",null),e([S()],Ne.prototype,"sublayerIds",void 0),e([S({readOnly:!0})],Ne.prototype,"isScaleDriven",null),e([S()],Ne.prototype,"title",void 0),e([S({readOnly:!0,dependsOn:["ready"],value:0})],Ne.prototype,"version",null),e([S()],Ne.prototype,"view",void 0),Ne=e([_("esri.widgets.Legend.support.ActiveLayerInfo")],Ne);const qe=Ne;export{qe as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.24/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../core/Error.js";import t from"../../core/Logger.js";import{throwIfNotAbortError as r}from"../../core/promiseUtils.js";import{zoomToFeature as i,zoomToClusteredFeatures as o,browseClusteredFeatures as n,removeSelectedFeature as a}from"./actions.js";const s="esri.widgets.Popup.PopupViewModel",c=t.getLogger(s),u=function(t){const{event:s,view:c}=t,{action:u}=s,d=c&&c.popup;if(!u)return Promise.reject(new e("trigger-action:missing-arguments","Event has no action"));if(!d)return Promise.reject(new e("trigger-action:missing-arguments","view.popup is missing"));const{disabled:l,id:v}=u;if(!v)return Promise.reject(new e("trigger-action:invalid-action","action.id is missing"));if(l)return Promise.reject(new e("trigger-action:invalid-action","Action is disabled"));if(v===i.id)return g(d.viewModel).catch(r);if(v===o.id)return w(d.viewModel);if(v===n.id)return d.featureMenuOpen=!d.featureMenuOpen,d.viewModel.browseClusterEnabled=!d.viewModel.browseClusterEnabled,Promise.resolve();if(d.viewModel.browseClusterEnabled=!1,v===a.id){d.close();const{selectedFeature:t}=d;if(!t)return Promise.reject(new e(`trigger-action:${a.id}`,"selectedFeature is required",{selectedFeature:t}));const{sourceLayer:r}=t;return r?r.remove(t):c.graphics.remove(t),Promise.resolve()}return Promise.resolve()};function d(e){const{selectedFeature:t,location:r,view:i}=e;if(!i)return null;if("3d"===i.type)return t||r;return e.get("selectedFeature.geometry")||r}function l(t,r){if("3d"!==(null==r?void 0:r.type)||!t||"esri.Graphic"!==t.declaredClass)return!0;const i=r.getViewForGraphic(t);if(i&&"whenGraphicBounds"in i){let r=!1;return i.whenGraphicBounds(t,{useViewElevation:!0}).then((e=>{r=!e||!e.boundingBox||e.boundingBox[0]===e.boundingBox[3]&&e.boundingBox[1]===e.boundingBox[4]&&e.boundingBox[2]===e.boundingBox[5]})).catch((()=>{const r=new e("zoom-to:invalid-graphic","Could not zoom to the location of the graphic.",{graphic:t});c.error(r)})),r}return!0}async function g(t){const{location:r,selectedFeature:o,view:n,zoomFactor:a}=t,s=d(t);if(!s){const t=new e("zoom-to:invalid-target-or-view","Cannot zoom to location without a target and view.",{target:s,view:n});return c.error(t),Promise.reject(t)}const u=n.scale/a,g=t.get("selectedFeature.geometry")||r,w=g&&"point"===g.type&&l(o,n);i.active=!0,i.disabled=!0;try{await t.view.goTo({target:s,scale:w?u:void 0})}finally{i.active=!1,i.disabled=!1,t.zoomToLocation=null,w&&(t.location=g)}}async function w(t){const{selectedFeature:r,view:i}=t;if("2d"!==(null==i?void 0:i.type)){const t=new e("zoomToCluster:invalid-view","View must be 2d MapView.",{view:i});throw c.error(t),t}if(!r.isAggregate){const t=new e("zoomToCluster:invalid-selectedFeature","Selected feature must represent an aggregate/cluster graphic.",{selectedFeature:r});throw c.error(t),t}const n=r.sourceLayer,a=await i.whenLayerView(n),s=a.createQuery();s.aggregateIds=[r.getObjectId()],o.active=!0,o.disabled=!0;const{extent:u}=await a.queryExtent(s);await i.goTo({target:u}),o.active=!1,o.disabled=!1}async function v(t){const{selectedFeature:r,view:i}=t;if("2d"!==(null==i?void 0:i.type)){const t=new e("displayClusterExtent:invalid-view","View must be 2d MapView.",{view:i});throw c.error(t),t}if(!r.isAggregate){const t=new e("zoomToCluster:invalid-selectedFeature","Selected feature must represent an aggregate/cluster graphic.",{selectedFeature:r});throw c.error(t),t}const o=r.sourceLayer,n=await i.whenLayerView(o),a=n.createQuery();a.aggregateIds=[r.getObjectId()];const{extent:s}=await n.queryExtent(a);t.selectedClusterBoundaryFeature.geometry=s,i.graphics.add(t.selectedClusterBoundaryFeature)}async function p(t){const{selectedFeature:r,view:i}=t;if("2d"!==(null==i?void 0:i.type)){const t=new e("browseAggregateFeatures:invalid-view","View must be 2d MapView.",{view:i});throw c.error(t),t}if(!r.isAggregate){const t=new e("browseAggregateFeatures:invalid-selectedFeature","Selected feature must represent an aggregate/cluster graphic.",{selectedFeature:r});throw c.error(t),t}const o=r.sourceLayer,a=await i.whenLayerView(o),s=a.createQuery();s.aggregateIds=[r.getObjectId()],n.active=!0,n.disabled=!0;const{features:u}=await a.queryFeatures(s);n.active=!1,n.disabled=!1,i.popup.open({features:[r].concat(u),featureMenuOpen:!0})}function f(e){var t;null!=(t=e.selectedFeature)&&t.isAggregate&&(e.features=e.features.filter((e=>e.isAggregate)))}export{p as browseAggregateFeatures,v as displayClusterExtent,d as getSelectedTarget,l as isZoomScreenSize,f as removeClusteredFeaturesForBrowsing,u as triggerAction,w as zoomToClusterExtent,g as zoomToLocation};
5
+ import e from"../../core/Error.js";import t from"../../core/Logger.js";import{throwIfNotAbortError as r}from"../../core/promiseUtils.js";import{zoomToFeature as i,zoomToClusteredFeatures as o,browseClusteredFeatures as n,removeSelectedFeature as a}from"./actions.js";const s="esri.widgets.Popup.PopupViewModel",c=t.getLogger(s),u=function(t){const{event:s,view:c}=t,{action:u}=s,d=c&&c.popup;if(!u)return Promise.reject(new e("trigger-action:missing-arguments","Event has no action"));if(!d)return Promise.reject(new e("trigger-action:missing-arguments","view.popup is missing"));const{disabled:l,id:v}=u;if(!v)return Promise.reject(new e("trigger-action:invalid-action","action.id is missing"));if(l)return Promise.reject(new e("trigger-action:invalid-action","Action is disabled"));if(v===i.id)return g(d.viewModel).catch(r);if(v===o.id)return w(d.viewModel);if(v===n.id)return d.featureMenuOpen=!d.featureMenuOpen,d.viewModel.browseClusterEnabled=!d.viewModel.browseClusterEnabled,Promise.resolve();if(d.viewModel.browseClusterEnabled=!1,v===a.id){d.close();const{selectedFeature:t}=d;if(!t)return Promise.reject(new e(`trigger-action:${a.id}`,"selectedFeature is required",{selectedFeature:t}));const{sourceLayer:r}=t;return r?r.remove(t):c.graphics.remove(t),Promise.resolve()}return Promise.resolve()};function d(e){const{selectedFeature:t,location:r,view:i}=e;if(!i)return null;if("3d"===i.type)return t||r;return e.get("selectedFeature.geometry")||r}function l(t,r){if("3d"!==(null==r?void 0:r.type)||!t||"esri.Graphic"!==t.declaredClass)return!0;const i=r.getViewForGraphic(t);if(i&&"whenGraphicBounds"in i){let r=!1;return i.whenGraphicBounds(t,{useViewElevation:!0}).then((e=>{r=!e||!e.boundingBox||e.boundingBox[0]===e.boundingBox[3]&&e.boundingBox[1]===e.boundingBox[4]&&e.boundingBox[2]===e.boundingBox[5]})).catch((()=>{const r=new e("zoom-to:invalid-graphic","Could not zoom to the location of the graphic.",{graphic:t});c.error(r)})),r}return!0}async function g(t){const{location:r,selectedFeature:o,view:n,zoomFactor:a}=t,s=d(t);if(!s){const t=new e("zoom-to:invalid-target-or-view","Cannot zoom to location without a target and view.",{target:s,view:n});throw c.error(t),t}const u=n.scale/a,g=t.get("selectedFeature.geometry")||r,w=g&&"point"===g.type&&l(o,n);i.active=!0,i.disabled=!0;try{await t.view.goTo({target:s,scale:w?u:void 0})}finally{i.active=!1,i.disabled=!1,t.zoomToLocation=null,w&&(t.location=g)}}async function w(t){const{selectedFeature:r,view:i}=t;if("2d"!==(null==i?void 0:i.type)){const t=new e("zoomToCluster:invalid-view","View must be 2d MapView.",{view:i});throw c.error(t),t}if(!r.isAggregate){const t=new e("zoomToCluster:invalid-selectedFeature","Selected feature must represent an aggregate/cluster graphic.",{selectedFeature:r});throw c.error(t),t}const n=r.sourceLayer,a=await i.whenLayerView(n),s=a.createQuery();s.aggregateIds=[r.getObjectId()],o.active=!0,o.disabled=!0;const{extent:u}=await a.queryExtent(s);await i.goTo({target:u}),o.active=!1,o.disabled=!1}async function v(t){const{selectedFeature:r,view:i}=t;if("2d"!==(null==i?void 0:i.type)){const t=new e("displayClusterExtent:invalid-view","View must be 2d MapView.",{view:i});throw c.error(t),t}if(!r.isAggregate){const t=new e("zoomToCluster:invalid-selectedFeature","Selected feature must represent an aggregate/cluster graphic.",{selectedFeature:r});throw c.error(t),t}const o=r.sourceLayer,n=await i.whenLayerView(o),a=n.createQuery();a.aggregateIds=[r.getObjectId()];const{extent:s}=await n.queryExtent(a);t.selectedClusterBoundaryFeature.geometry=s,i.graphics.add(t.selectedClusterBoundaryFeature)}async function p(t){const{selectedFeature:r,view:i}=t;if("2d"!==(null==i?void 0:i.type)){const t=new e("browseAggregateFeatures:invalid-view","View must be 2d MapView.",{view:i});throw c.error(t),t}if(!r.isAggregate){const t=new e("browseAggregateFeatures:invalid-selectedFeature","Selected feature must represent an aggregate/cluster graphic.",{selectedFeature:r});throw c.error(t),t}const o=r.sourceLayer,a=await i.whenLayerView(o),s=a.createQuery();s.aggregateIds=[r.getObjectId()],n.active=!0,n.disabled=!0;const{features:u}=await a.queryFeatures(s);n.active=!1,n.disabled=!1,i.popup.open({features:[r].concat(u),featureMenuOpen:!0})}function f(e){var t;null!=(t=e.selectedFeature)&&t.isAggregate&&(e.features=e.features.filter((e=>e.isAggregate)))}export{p as browseAggregateFeatures,v as displayClusterExtent,d as getSelectedTarget,l as isZoomScreenSize,f as removeClusteredFeaturesForBrowsing,u as triggerAction,w as zoomToClusterExtent,g as zoomToLocation};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.24/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../chunks/tslib.es6.js";import{getAssetUrl as t}from"../../assets.js";import r from"../../config.js";import s from"../../Graphic.js";import o from"../../PopupTemplate.js";import"../../symbols.js";import l from"../../core/Accessor.js";import i from"../../core/Collection.js";import{deprecatedProperty as a}from"../../core/deprecate.js";import n from"../../core/Error.js";import u from"../../core/Evented.js";import c from"../../core/Handles.js";import h from"../../core/has.js";import p from"../../core/Logger.js";import{unwrap as d,isSome as g,isNone as m}from"../../core/maybe.js";import{eachAlways as y,after as f}from"../../core/promiseUtils.js";import{whenOnce as S}from"../../core/reactiveUtils.js";import{init as v}from"../../core/watchUtils.js";import{property as _}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as b}from"../../core/accessorSupport/decorators/subclass.js";import w from"../../geometry/Point.js";import x from"../../geometry/SpatialReference.js";import{onLocaleChange as I}from"../../intl/locale.js";import{fetchMessageBundle as j}from"../../intl/messages.js";import P from"../../portal/Portal.js";import{highlightsSupported as T}from"../../views/support/layerViewUtils.js";import R from"./LayerSearchSource.js";import L from"./LocatorSearchSource.js";import E from"./SearchSource.js";import{getPointFromGeometry as F,getPointWithElevation as A}from"./support/geometryUtils.js";import{isArcGISWorldGeocoder as C,meteredArcGISLocatorUrl as G,isProxiedArcGISWorldGeocoder as O,isMeteredArcGISWorldGeocoder as N}from"./support/locatorUtils.js";import{supported as D,getCurrentPosition as M,positionToPoint as V}from"../support/geolocationUtils.js";import{GoToMixin as k}from"../support/GoTo.js";import B from"../../symbols/PictureMarkerSymbol.js";import J from"../../symbols/SimpleLineSymbol.js";import U from"../../symbols/SimpleFillSymbol.js";import H from"../../symbols/TextSymbol.js";function Q(e,t){return e.hasOwnProperty(t)&&null!=e[t]&&""!==e[t]}const Z=()=>j("esri/widgets/Search/t9n/Search"),q="esri.widgets.Search.SearchViewModel",z=p.getLogger(q),K="highlight",W=i.ofType({key:e=>e.layer?"layer":"locator",base:E,typeMap:{layer:R,locator:L}}),X=x.WGS84,Y="esri/images/search/search-symbol-32.svg",$="esri/images/search/search-symbol-32.png",ee=/<(?:.|\s)*?>/g,te=-1;let re=class extends(k(u.EventedMixin(l))){constructor(e){super(e),this._handles=new c,this._gotoController=null,this._searching=null,this.autoNavigate=!0,this.autoSelect=!0,this.defaultPopupTemplate=null,this.defaultSources=new W,this.defaultSymbols={point:new B({url:t(h("trident")?$:Y),size:24,width:24,height:24}),polyline:new J({color:[130,130,130,1],width:2}),polygon:new U({color:[235,235,235,.4],outline:{color:[130,130,130,1],width:2}})},this.includeDefaultSources=!0,this.maxInputLength=128,this.maxResults=6,this.maxSuggestions=6,this.messages=null,this.minSuggestCharacters=3,this.popupEnabled=!0,this.popupTemplate=null,this.portal=P.getDefault(),this.resultCount=null,this.resultGraphicEnabled=!0,this.resultGraphic=null,this.results=null,this.selectedSuggestion=null,this.searchAllEnabled=!0,this.selectedResult=null,this.sources=new W,this.suggestionDelay=350,this.suggestionCount=null,this.suggestions=null,this.suggestionsEnabled=!0,this.view=null}initialize(){const e=async()=>{const e=await Z();this.messages=e,this.defaultPopupTemplate=new o({title:e.searchResult,content:"{Match_addr}"})};e(),this._handles.add([v(this,["includeDefaultSources","view","portal"],(()=>this._update())),I(e)])}destroy(){this._abortGoTo(),this.clearGraphics(),this._handles.destroy(),this._handles=null}get activeSource(){return this.allSources.getItemAt(this.activeSourceIndex)||null}get activeSourceIndex(){return 1===this.allSources.length||!this.searchAllEnabled?0:te}set activeSourceIndex(e){void 0!==e?this._override("activeSourceIndex",e):this._clearOverride("activeSourceIndex")}get allPlaceholder(){var e;return null==(e=this.messages)?void 0:e.allPlaceholder}set allPlaceholder(e){e?this._override("allPlaceholder",e):this._clearOverride("allPlaceholder")}get allSources(){const{sources:e,defaultSources:t,includeDefaultSources:r}=this,s="function"==typeof r?r.call(null,{sources:e,defaultSources:t}):r?t.concat(e):e,o=this._get("allSources")||new W;return o.removeAll(),o.addMany(s.filter(Boolean)),o}get defaultSymbol(){return a(z,"defaultSymbol",{replacement:"defaultSymbols",version:"4.22"}),this._get("defaultSymbol")}set defaultSymbol(e){a(z,"defaultSymbol",{replacement:"defaultSymbols",version:"4.22"}),this._set("defaultSymbol",e)}get locationEnabled(){return this._get("locationEnabled")||D()}set locationEnabled(e){if(void 0===e)return void this._clearOverride("locationEnabled");const t=D();if(e&&!t){const e=new n("locationEnabled:geolocation-unsupported","Geolocation API is unsupported.",{geolocation:navigator.geolocation});z.error(e)}this._override("locationEnabled",e&&t)}get placeholder(){const{allSources:e,activeSourceIndex:t,allPlaceholder:r}=this;if(t===te)return r;const s=e.getItemAt(t);return s?s.placeholder:""}set searchTerm(e){this._set("searchTerm",e||""),this.clearGraphics(),this.selectedSuggestion&&this.selectedSuggestion.text!==e&&this._set("selectedSuggestion",null),""===e&&this._clear()}get searchTerm(){return this._get("searchTerm")||""}get state(){return this._searching?"searching":this.updating?"loading":0===this.allSources.length?"disabled":"ready"}get updating(){return null!=this._updatingPromise}clear(){this.searchTerm=""}clearGraphics(){this._removeHighlight(),this._closePopup(),this.view&&this.view.graphics.remove(this.resultGraphic),this._set("resultGraphic",null)}search(e,t){this.emit("search-start"),this.clearGraphics();const r=this._createSuggestionForSearch(e),s=this.when().then((()=>this._getResultsFromSources(r,t).then((e=>{var s;if(null!=(s=d(null==t?void 0:t.signal))&&s.aborted)return null;const o={activeSourceIndex:this.activeSourceIndex,searchTerm:r.text,numResults:0,numErrors:0,errors:[],results:[]};this._formatResponse(o,e,r);const l=this._getFirstResult(o.results),i=(r.location&&l?l.name:r.text).replace(ee,"");return this._set("searchTerm",i),(r.key&&"number"==typeof r.sourceIndex||r.location)&&this._set("selectedSuggestion",r),this._set("results",o.results),this._set("resultCount",o.results.reduce(((e,t)=>e+t.results.length),0)),this.emit("search-complete",o),this._selectFirstResult(l).then((()=>o))})))).then((e=>(this._clearSearching(),e)),(e=>{throw this._clearSearching(),e}));return this._searching=s,s}searchNearby(e){if(!this.locationEnabled){const e=new n("searchNearby:geolocation-unsupported","Geolocation API is unsupported.",{geolocation:navigator.geolocation});return z.error(e),Promise.reject(e)}const t=M().then((t=>V({position:t,view:this.view},e))).then((t=>this.search(t,e)));return this._searching=t,t.catch((()=>{})).then((()=>this._clearSearching())),t}select(e){if(this.clearGraphics(),!e){const t=new n("select:missing-parameter","Cannot select without a searchResult.",{searchResult:e});return z.error(t),Promise.reject(t)}const{view:t}=this,r=Q(e,"sourceIndex")?e.sourceIndex:this._getSourceIndexOfResult(e),o=this.allSources.getItemAt(r);if(!o){const e=new n("select:missing-source","Cannot select without a source.",{source:o});return z.error(e),Promise.reject(e)}const l=o instanceof R?this._getLayerSourcePopupTemplate(o):o.popupTemplate,i=o.resultSymbol||this._getDefaultSymbol(e),a=Q(o,"resultGraphicEnabled")?o.resultGraphicEnabled:this.resultGraphicEnabled,u=Q(o,"autoNavigate")?o.autoNavigate:this.autoNavigate,c=Q(o,"popupEnabled")?o.popupEnabled:this.popupEnabled,h=c?l||this.popupTemplate||this.defaultPopupTemplate:null,{feature:p}=e;if(!p){const e=new n("select:missing-feature","Cannot select without a feature.",{feature:p});return z.error(e),Promise.reject(e)}const{attributes:d,geometry:m,layer:f,sourceLayer:S}=p,v=F(m),_={layerViewQuery:this._getLayerView(p),elevationQuery:t&&g(v)?A(v,t).catch((()=>v)):Promise.resolve(v)};return y(_).then((l=>{const n=l.layerViewQuery.value,y=l.elevationQuery.value;i instanceof H&&(i.text=e.name);const v=t&&u?e.target||e.extent:null;return(g(v)?this._goToSearchResult(v):Promise.resolve()).then((()=>{var l;const u=n?p:new s({geometry:m,symbol:i,attributes:d,layer:f,sourceLayer:S,popupTemplate:h}),g=c&&(null==(l=this.view)?void 0:l.popup),v=g&&u.getEffectivePopupTemplate(g.defaultPopupTemplateEnabled);return v&&t.popup.open({features:[u],location:y}),n&&T(n)&&!v&&this._highlightFeature({graphic:u,layerView:n}),!n&&a&&t&&t.graphics.push(u),this._setResultFloor(e),this._set("selectedResult",e),this._set("resultGraphic",u),this.emit("select-result",{result:e,source:o,sourceIndex:r}),e}))}))}suggest(e,t,r){const s=e||this.searchTerm;return this.emit("suggest-start",{searchTerm:s}),this._suggestTimer(t,r).then((()=>this._suggestImmediate(s,r).then((e=>(this._set("suggestions",e.results),this._set("suggestionCount",e.results.reduce(((e,t)=>e+t.results.length),0)),this.emit("suggest-complete",e),e)))))}async when(){await S((()=>!this.updating))}async _update(){const{portal:e,view:t}=this;if(this.includeDefaultSources){const r=this._updatingPromise=y([null==e?void 0:e.load(),null==t?void 0:t.when()]);if(this.destroyed)return;if(await r,r!==this._updatingPromise)return}await S((()=>this.messages)),this.destroyed||this._updateDefaultSources(),this._updatingPromise=null}_clearSearching(){this._searching=null}_convertHelperServices(){var e,t;const s=null==(e=this.portal)||null==(t=e.helperServices)?void 0:t.geocode;if(!s)return[];return s.map((e=>{if(!1===e.placefinding)return;const t=r.apiKey&&C(e.url)?{url:G}:null,s=L.fromJSON({...e,...t}),o=s.url;if(C(o)||O(o)||N(o)){const e=s.outFields||["Addr_type","Match_addr","StAddr","City"],t=s.placeholder||this.messages.placeholder,r="number"==typeof s.defaultZoomScale?s.defaultZoomScale:2500;s.set({singleLineFieldName:"SingleLine",outFields:e,placeholder:t,defaultZoomScale:r})}return s.singleLineFieldName?s:void 0})).filter(Boolean)}_getLayerSources(e,t){var r;const s=null==(r=this.view)?void 0:r.map;return e.map((e=>{const r=s.findLayerById(e.id);if(!r)return;const o=this._getLayerJSON(e),l=R.fromJSON(o);return l.placeholder=t,this._getLayer(r,o).then((e=>{l.layer=e})),l})).filter(Boolean).toArray()}_getTableSources(e,t){var r;const s=null==(r=this.view)?void 0:r.map;return e.map((e=>{const r=s.findTableById(e.id);if(!r)return;const o=this._getLayerJSON(e),l=R.fromJSON(o);return l.placeholder=t,this._getLayer(r,o).then((e=>{l.layer=e})),l})).filter(Boolean).toArray()}_convertApplicationProperties(){var e,t,r;const s=null==(e=this.view)?void 0:e.map,o=null==s||null==(t=s.applicationProperties)||null==(r=t.viewing)?void 0:r.search;if(!o)return[];const{enabled:l,hintText:i,layers:a,tables:n}=o;if(!l)return[];return[...this._getLayerSources(a,i),...this._getTableSources(n,i)]}_getSubLayer(e,t){return e.load().then((()=>{if(!e.allSublayers)return Promise.reject();const r=e.allSublayers.find((e=>e.id===t.subLayer));return r?r.createFeatureLayer():Promise.reject()}))}async _getBuildingSubLayer(e,t){await e.load();const r=e.allSublayers.find((e=>e.id===t.subLayer));return"building-component"!==(null==r?void 0:r.type)?Promise.reject():(await r.load(),null==r.associatedLayer?Promise.reject():(await r.associatedLayer.load(),r))}_getLayer(e,t){return"feature"===e.type||"scene"===e.type||"csv"===e.type||"geojson"===e.type||"ogc-feature"===e.type?Promise.resolve(e):"map-image"===e.type?this._getSubLayer(e,t).catch((()=>{const t=new n("search:create-featurelayer","Could not create a FeatureLayer from the MapImageLayer",{layer:e});return z.error(t),null})):"building-scene"===e.type?this._getBuildingSubLayer(e,t):Promise.resolve(null)}_getLayerJSON(e){return"function"==typeof e.toJSON?e.toJSON():e}_updateDefaultSources(){const{defaultSources:e,includeDefaultSources:t}=this;e.removeAll(),t&&e.addMany([...this._convertApplicationProperties(),...this._convertHelperServices()])}_abortGoTo(){this._gotoController&&this._gotoController.abort(),this._gotoController=null}_clear(){this._abortGoTo(),this._set("resultCount",null),this._set("results",null),this._set("suggestions",null),this._set("suggestionCount",null),this._set("selectedResult",null),this._set("selectedSuggestion",null),this.emit("search-clear")}_closePopup(){var e;const t=null==(e=this.view)?void 0:e.popup,{resultGraphic:r}=this;if(!t||!r)return;const{selectedFeature:s}=t;s&&s===r&&t.close()}_suggestTimer(e,t){const r=null!=e?e:this.suggestionDelay;return f(r,null,t&&t.signal)}_createLocationForSearch(e){return e instanceof s?F(e.geometry):e instanceof w?e:Array.isArray(e)&&2===e.length?new w({longitude:e[0],latitude:e[1]}):null}_createSuggestionForSearch(e){if(e&&Q(e,"key")&&Q(e,"text")&&Q(e,"sourceIndex"))return e;const t=this._createLocationForSearch(e),r="string"==typeof e?e:this.searchTerm,{selectedSuggestion:s,selectedResult:o}=this,l=!e&&s&&o,i=l&&s.key===o.key&&s.sourceIndex===o.sourceIndex,a=l&&s.location;return i||a?s:{location:d(t),text:t?"":r,sourceIndex:null,key:null}}_getFirstResult(e){let t=null;return e&&e.some((e=>{const{results:r}=e,s=r[0],o=!!s;return o&&(t=s),o})),t}_selectFirstResult(e){return this.autoSelect&&e?this.select(e):Promise.resolve(null)}_suggestImmediate(e,t){return this.when().then((()=>this._getSuggestionsFromSources(e,t))).then((r=>{var s;if(null!=(s=d(null==t?void 0:t.signal))&&s.aborted)return null;const o={activeSourceIndex:this.activeSourceIndex,searchTerm:e,numResults:0,numErrors:0,errors:[],results:[]};return this._formatResponse(o,r),o}))}_formatSourceResponse(e,t,r){const s=t&&t.value||[],o=t&&t.error,l=this.allSources.getItemAt(r);if(o){const t={sourceIndex:r,source:l,error:o};e.errors.push(t),z.error(o),e.numErrors++}else{const t={sourceIndex:r,source:l,results:s};e.results.push(t),e.numResults+=s.length}}_formatResponse(e,t,r){if(t)if(e.activeSourceIndex===te){const s=r&&Q(r,"sourceIndex")&&-1!==r.sourceIndex?r.sourceIndex:void 0;t.forEach(((t,r)=>{const o=void 0!==s?s:r;this._formatSourceResponse(e,t,o)}))}else this._formatSourceResponse(e,t[0],e.activeSourceIndex)}_getResultsFromSources(e,t){const{allSources:r}=this,s=!e.location&&Q(e,"sourceIndex")?e.sourceIndex:this.activeSourceIndex,o=[];if(!r.length){const e=new n("search:no-sources-defined","At least one source is required.",{allSources:r});return z.error(e),Promise.reject(e)}return s===te?r.forEach(((r,s)=>{o.push(this._getResultsFromSource(e,s,t))})):o.push(this._getResultsFromSource(e,s,t)),y(o)}_getSuggestionsFromSources(e,t){const{allSources:r,activeSourceIndex:s}=this,o=[];if(!r.length){const e=new n("suggest:no-sources-defined","At least one source is required.",{allSources:r});return z.error(e),Promise.reject(e)}return s===te?r.forEach(((r,s)=>{o.push(this._getSuggestionsFromSource(e,s,t))})):o.push(this._getSuggestionsFromSource(e,s,t)),y(o)}_getResultsFromSource(e,t,r){var s;const o=this.allSources.getItemAt(t),{location:l=null}=e,i=(null==(s=this.view)?void 0:s.spatialReference)||X,a=Q(o,"maxResults")?o.maxResults:this.maxResults,n=!!(o instanceof R&&Q(o,"exactMatch"))&&o.exactMatch,{view:u}=this;return o.getResults({view:u,sourceIndex:t,location:l,suggestResult:e,spatialReference:i,exactMatch:n,maxResults:a},r)}_getSuggestionsFromSource(e,t,r){const s=this.allSources.getItemAt(t),o=Q(s,"suggestionsEnabled")?s.suggestionsEnabled:this.suggestionsEnabled,l=e.length,i=Q(s,"minSuggestCharacters")?s.minSuggestCharacters:this.minSuggestCharacters;if(o&&e.trim()&&l>=i){var a;const o=(null==(a=this.view)?void 0:a.spatialReference)||X,l=Q(s,"maxSuggestions")?s.maxSuggestions:this.maxSuggestions,{view:i}=this,n=!!(s instanceof R&&Q(s,"exactMatch"))&&s.exactMatch;return s.getSuggestions({view:i,sourceIndex:t,suggestTerm:e,spatialReference:o,maxSuggestions:l,exactMatch:n},r)}return Promise.resolve(null)}_getLayerSourcePopupTemplate(e){const{layer:t}=e;if(t)return Q(e,"popupTemplate")?e.popupTemplate:t.popupTemplate}_getSourceIndexOfResult(e){const t=this.results;let r=null;return t.some((t=>t.results.some((s=>s===e&&(r=t.sourceIndex,!0))))),r}async _goToSearchResult(e){const t=!!e;this._abortGoTo();const r=new AbortController;this._gotoController=r;const s={target:{target:e},options:{animate:t,signal:r.signal}};await this.callGoTo(s),this._gotoController=null}_getDefaultSymbol(e){var t;const{defaultSymbols:r}=this,s=null==(t=e.feature)?void 0:t.geometry;if(m(s))return null;const o=this._get("defaultSymbol");if(o&&("point"===s.type||"multipoint"===s.type))return o;switch(s.type){case"point":case"multipoint":return r.point;case"polyline":return r.polyline;case"extent":case"polygon":return r.polygon;default:return null}}_removeHighlight(){this._handles.remove(K)}async _getLayerView(e){const{view:t}=this;if(!e||!t||"building-component"===e.layer.type||"subtype-sublayer"===e.layer.type)return Promise.resolve(null);const{layer:r}=e;return await t.when(),t.whenLayerView(r)}_highlightFeature(e){const{graphic:t,layerView:r}=e,{attributes:s,layer:o}=t,{objectIdField:l}=o,i=s&&s[l],a=r.highlight(i||t);this._handles.add(a,K)}_setResultFloor(e){var t,r,s;const{view:o}=this,l=null==(t=e.feature)?void 0:t.attributes,i=null==(r=e.feature)?void 0:r.sourceLayer;if(i&&"floorInfo"in i&&null!=i&&null!=(s=i.floorInfo)&&s.floorField&&l){const e=l[i.floorInfo.floorField];o.emit("select-result-floor",e)}}};re.ALL_INDEX=te,e([_()],re.prototype,"_searching",void 0),e([_()],re.prototype,"_updatingPromise",void 0),e([_({readOnly:!0,value:null})],re.prototype,"activeSource",null),e([_()],re.prototype,"activeSourceIndex",null),e([_()],re.prototype,"allPlaceholder",null),e([_({readOnly:!0})],re.prototype,"allSources",null),e([_()],re.prototype,"autoNavigate",void 0),e([_()],re.prototype,"autoSelect",void 0),e([_()],re.prototype,"defaultPopupTemplate",void 0),e([_({readOnly:!0})],re.prototype,"defaultSources",void 0),e([_()],re.prototype,"defaultSymbol",null),e([_()],re.prototype,"defaultSymbols",void 0),e([_()],re.prototype,"includeDefaultSources",void 0),e([_()],re.prototype,"locationEnabled",null),e([_()],re.prototype,"maxInputLength",void 0),e([_()],re.prototype,"maxResults",void 0),e([_()],re.prototype,"maxSuggestions",void 0),e([_()],re.prototype,"messages",void 0),e([_()],re.prototype,"minSuggestCharacters",void 0),e([_({readOnly:!0})],re.prototype,"placeholder",null),e([_()],re.prototype,"popupEnabled",void 0),e([_({type:o})],re.prototype,"popupTemplate",void 0),e([_({type:P})],re.prototype,"portal",void 0),e([_()],re.prototype,"resultCount",void 0),e([_()],re.prototype,"resultGraphicEnabled",void 0),e([_({readOnly:!0})],re.prototype,"resultGraphic",void 0),e([_({readOnly:!0})],re.prototype,"results",void 0),e([_({readOnly:!0})],re.prototype,"selectedSuggestion",void 0),e([_()],re.prototype,"searchAllEnabled",void 0),e([_({readOnly:!0})],re.prototype,"selectedResult",void 0),e([_()],re.prototype,"searchTerm",null),e([_({type:W})],re.prototype,"sources",void 0),e([_({readOnly:!0})],re.prototype,"state",null),e([_()],re.prototype,"suggestionDelay",void 0),e([_()],re.prototype,"suggestionCount",void 0),e([_({readOnly:!0})],re.prototype,"suggestions",void 0),e([_()],re.prototype,"suggestionsEnabled",void 0),e([_({readOnly:!0})],re.prototype,"updating",null),e([_()],re.prototype,"view",void 0),e([_()],re.prototype,"clear",null),re=e([b(q)],re);const se=re;export{se as default};
5
+ import{_ as e}from"../../chunks/tslib.es6.js";import{getAssetUrl as t}from"../../assets.js";import r from"../../config.js";import s from"../../Graphic.js";import o from"../../PopupTemplate.js";import"../../symbols.js";import l from"../../core/Accessor.js";import i from"../../core/Collection.js";import{deprecatedProperty as a}from"../../core/deprecate.js";import n from"../../core/Error.js";import u from"../../core/Evented.js";import c from"../../core/Handles.js";import h from"../../core/has.js";import p from"../../core/Logger.js";import{unwrap as d,isSome as g,isNone as m}from"../../core/maybe.js";import{eachAlways as y,after as f}from"../../core/promiseUtils.js";import{whenOnce as S}from"../../core/reactiveUtils.js";import{init as v}from"../../core/watchUtils.js";import{property as _}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as b}from"../../core/accessorSupport/decorators/subclass.js";import w from"../../geometry/Point.js";import x from"../../geometry/SpatialReference.js";import{onLocaleChange as I}from"../../intl/locale.js";import{fetchMessageBundle as j}from"../../intl/messages.js";import T from"../../portal/Portal.js";import{highlightsSupported as R}from"../../views/support/layerViewUtils.js";import P from"./LayerSearchSource.js";import E from"./LocatorSearchSource.js";import L from"./SearchSource.js";import{getPointFromGeometry as F,getPointWithElevation as A}from"./support/geometryUtils.js";import{isArcGISWorldGeocoder as C,meteredArcGISLocatorUrl as G,isProxiedArcGISWorldGeocoder as O,isMeteredArcGISWorldGeocoder as N}from"./support/locatorUtils.js";import{supported as D,getCurrentPosition as M,positionToPoint as V}from"../support/geolocationUtils.js";import{GoToMixin as k}from"../support/GoTo.js";import B from"../../symbols/PictureMarkerSymbol.js";import J from"../../symbols/SimpleLineSymbol.js";import U from"../../symbols/SimpleFillSymbol.js";import H from"../../symbols/TextSymbol.js";function Q(e,t){return e.hasOwnProperty(t)&&null!=e[t]&&""!==e[t]}const Z=()=>j("esri/widgets/Search/t9n/Search"),q="esri.widgets.Search.SearchViewModel",z=p.getLogger(q),K="highlight",W=i.ofType({key:e=>e.layer?"layer":"locator",base:L,typeMap:{layer:P,locator:E}}),X=x.WGS84,Y="esri/images/search/search-symbol-32.svg",$="esri/images/search/search-symbol-32.png",ee=/<(?:.|\s)*?>/g,te=-1;let re=class extends(k(u.EventedMixin(l))){constructor(e){super(e),this._handles=new c,this._gotoController=null,this._searching=null,this.autoNavigate=!0,this.autoSelect=!0,this.defaultPopupTemplate=null,this.defaultSources=new W,this.defaultSymbols={point:new B({url:t(h("trident")?$:Y),size:24,width:24,height:24}),polyline:new J({color:[130,130,130,1],width:2}),polygon:new U({color:[235,235,235,.4],outline:{color:[130,130,130,1],width:2}})},this.includeDefaultSources=!0,this.maxInputLength=128,this.maxResults=6,this.maxSuggestions=6,this.messages=null,this.minSuggestCharacters=3,this.popupEnabled=!0,this.popupTemplate=null,this.portal=T.getDefault(),this.resultCount=null,this.resultGraphicEnabled=!0,this.resultGraphic=null,this.results=null,this.selectedSuggestion=null,this.searchAllEnabled=!0,this.selectedResult=null,this.sources=new W,this.suggestionDelay=350,this.suggestionCount=null,this.suggestions=null,this.suggestionsEnabled=!0,this.view=null}initialize(){const e=async()=>{const e=await Z();this.messages=e,this.defaultPopupTemplate=new o({title:e.searchResult,content:"{Match_addr}"})};e(),this._handles.add([v(this,["includeDefaultSources","view","portal"],(()=>this._update())),I(e)])}destroy(){this._abortGoTo(),this.clearGraphics(),this._handles.destroy(),this._handles=null}get activeSource(){return this.allSources.getItemAt(this.activeSourceIndex)||null}get activeSourceIndex(){return 1===this.allSources.length||!this.searchAllEnabled?0:te}set activeSourceIndex(e){void 0!==e?this._override("activeSourceIndex",e):this._clearOverride("activeSourceIndex")}get allPlaceholder(){var e;return null==(e=this.messages)?void 0:e.allPlaceholder}set allPlaceholder(e){e?this._override("allPlaceholder",e):this._clearOverride("allPlaceholder")}get allSources(){const{sources:e,defaultSources:t,includeDefaultSources:r}=this,s="function"==typeof r?r.call(null,{sources:e,defaultSources:t}):r?t.concat(e):e,o=this._get("allSources")||new W;return o.removeAll(),o.addMany(s.filter(Boolean)),o}get defaultSymbol(){return a(z,"defaultSymbol",{replacement:"defaultSymbols",version:"4.22"}),this._get("defaultSymbol")}set defaultSymbol(e){a(z,"defaultSymbol",{replacement:"defaultSymbols",version:"4.22"}),this._set("defaultSymbol",e)}get locationEnabled(){return this._get("locationEnabled")||D()}set locationEnabled(e){if(void 0===e)return void this._clearOverride("locationEnabled");const t=D();if(e&&!t){const e=new n("locationEnabled:geolocation-unsupported","Geolocation API is unsupported.",{geolocation:navigator.geolocation});z.error(e)}this._override("locationEnabled",e&&t)}get placeholder(){const{allSources:e,activeSourceIndex:t,allPlaceholder:r}=this;if(t===te)return r;const s=e.getItemAt(t);return s?s.placeholder:""}set searchTerm(e){this._set("searchTerm",e||""),this.clearGraphics(),this.selectedSuggestion&&this.selectedSuggestion.text!==e&&this._set("selectedSuggestion",null),""===e&&this._clear()}get searchTerm(){return this._get("searchTerm")||""}get state(){return this._searching?"searching":this.updating?"loading":0===this.allSources.length?"disabled":"ready"}get updating(){return null!=this._updatingPromise}clear(){this.searchTerm=""}clearGraphics(){this._removeHighlight(),this._closePopup(),this.view&&this.view.graphics.remove(this.resultGraphic),this._set("resultGraphic",null)}search(e,t){this.emit("search-start"),this.clearGraphics();const r=this._createSuggestionForSearch(e),s=this.when().then((()=>this._getResultsFromSources(r,t).then((e=>{var s;if(null!=(s=d(null==t?void 0:t.signal))&&s.aborted)return null;const o={activeSourceIndex:this.activeSourceIndex,searchTerm:r.text,numResults:0,numErrors:0,errors:[],results:[]};this._formatResponse(o,e,r);const l=this._getFirstResult(o.results),i=(r.location&&l?l.name:r.text).replace(ee,"");return this._set("searchTerm",i),(r.key&&"number"==typeof r.sourceIndex||r.location)&&this._set("selectedSuggestion",r),this._set("results",o.results),this._set("resultCount",o.results.reduce(((e,t)=>e+t.results.length),0)),this.emit("search-complete",o),this._selectFirstResult(l).then((()=>o))})))).then((e=>(this._clearSearching(),e)),(e=>{throw this._clearSearching(),e}));return this._searching=s,s}searchNearby(e){if(!this.locationEnabled){const e=new n("searchNearby:geolocation-unsupported","Geolocation API is unsupported.",{geolocation:navigator.geolocation});return z.error(e),Promise.reject(e)}const t=M().then((t=>V({position:t,view:this.view},e))).then((t=>this.search(t,e)));return this._searching=t,t.catch((()=>{})).then((()=>this._clearSearching())),t}select(e){if(this.clearGraphics(),!e){const t=new n("select:missing-parameter","Cannot select without a searchResult.",{searchResult:e});return z.error(t),Promise.reject(t)}const{view:t}=this,r=Q(e,"sourceIndex")?e.sourceIndex:this._getSourceIndexOfResult(e),o=this.allSources.getItemAt(r);if(!o){const e=new n("select:missing-source","Cannot select without a source.",{source:o});return z.error(e),Promise.reject(e)}const l=o instanceof P?this._getLayerSourcePopupTemplate(o):o.popupTemplate,i=o.resultSymbol||this._getDefaultSymbol(e),a=Q(o,"resultGraphicEnabled")?o.resultGraphicEnabled:this.resultGraphicEnabled,u=Q(o,"autoNavigate")?o.autoNavigate:this.autoNavigate,c=Q(o,"popupEnabled")?o.popupEnabled:this.popupEnabled,h=c?l||this.popupTemplate||this.defaultPopupTemplate:null,{feature:p}=e;if(!p){const e=new n("select:missing-feature","Cannot select without a feature.",{feature:p});return z.error(e),Promise.reject(e)}const{attributes:d,geometry:m,layer:f,sourceLayer:S}=p,v=F(m),_={layerViewQuery:this._getLayerView(p),elevationQuery:t&&g(v)?A(v,t).catch((()=>v)):Promise.resolve(v)};return y(_).then((l=>{const n=l.layerViewQuery.value,y=l.elevationQuery.value;i instanceof H&&(i.text=e.name);const v=t&&u?e.target||e.extent:null;return(g(v)?this._goToSearchResult(v):Promise.resolve()).then((()=>{var l;const u=n?p:new s({geometry:m,symbol:i,attributes:d,layer:f,sourceLayer:S,popupTemplate:h}),g=c&&(null==(l=this.view)?void 0:l.popup),v=g&&u.getEffectivePopupTemplate(g.defaultPopupTemplateEnabled);return v&&t.popup.open({features:[u],location:y}),n&&R(n)&&!v&&this._highlightFeature({graphic:u,layerView:n}),!n&&a&&t&&t.graphics.push(u),this._setResultFloor(e),this._set("selectedResult",e),this._set("resultGraphic",u),this.emit("select-result",{result:e,source:o,sourceIndex:r}),e}))}))}suggest(e,t,r){const s=e||this.searchTerm;return this.emit("suggest-start",{searchTerm:s}),this._suggestTimer(t,r).then((()=>this._suggestImmediate(s,r).then((e=>(this._set("suggestions",e.results),this._set("suggestionCount",e.results.reduce(((e,t)=>e+t.results.length),0)),this.emit("suggest-complete",e),e)))))}async when(){await S((()=>!this.updating))}async _update(){const{portal:e,view:t}=this;if(this.includeDefaultSources){const r=this._updatingPromise=y([null==e?void 0:e.load(),null==t?void 0:t.when()]);if(this.destroyed)return;if(await r,r!==this._updatingPromise)return}await S((()=>this.messages)),this.destroyed||this._updateDefaultSources(),this._updatingPromise=null}_clearSearching(){this._searching=null}_convertHelperServices(){var e,t;const s=null==(e=this.portal)||null==(t=e.helperServices)?void 0:t.geocode;if(!s)return[];return s.map((e=>{if(!1===e.placefinding)return;const t=r.apiKey&&C(e.url)?{url:G}:null,s=E.fromJSON({...e,...t}),o=s.url;if(C(o)||O(o)||N(o)){const e=s.outFields||["Addr_type","Match_addr","StAddr","City"],t=s.placeholder||this.messages.placeholder,r="number"==typeof s.defaultZoomScale?s.defaultZoomScale:2500;s.set({singleLineFieldName:"SingleLine",outFields:e,placeholder:t,defaultZoomScale:r})}return s.singleLineFieldName?s:void 0})).filter(Boolean)}_getLayerSources(e,t){var r;const s=null==(r=this.view)?void 0:r.map;return e.map((e=>{const r=s.findLayerById(e.id);if(!r)return;const o=this._getLayerJSON(e),l=P.fromJSON(o);return l.placeholder=t,this._getLayer(r,o).then((e=>{l.layer=e})),l})).filter(Boolean).toArray()}_getTableSources(e,t){var r;const s=null==(r=this.view)?void 0:r.map;return e.map((e=>{const r=s.findTableById(e.id);if(!r)return;const o=this._getLayerJSON(e),l=P.fromJSON(o);return l.placeholder=t,this._getLayer(r,o).then((e=>{l.layer=e})),l})).filter(Boolean).toArray()}_convertApplicationProperties(){var e,t,r;const s=null==(e=this.view)?void 0:e.map,o=null==s||null==(t=s.applicationProperties)||null==(r=t.viewing)?void 0:r.search;if(!o)return[];const{enabled:l,hintText:i,layers:a,tables:n}=o;if(!l)return[];return[...this._getLayerSources(a,i),...this._getTableSources(n,i)]}_getSubLayer(e,t){return e.load().then((()=>{if(!e.allSublayers)throw new Error;const r=e.allSublayers.find((e=>e.id===t.subLayer));if(!r)throw new Error;return r.createFeatureLayer()}))}async _getBuildingSubLayer(e,t){await e.load();const r=e.allSublayers.find((e=>e.id===t.subLayer));if("building-component"!==(null==r?void 0:r.type))throw new Error;if(await r.load(),null==r.associatedLayer)throw new Error;return await r.associatedLayer.load(),r}_getLayer(e,t){return"feature"===e.type||"scene"===e.type||"csv"===e.type||"geojson"===e.type||"ogc-feature"===e.type?Promise.resolve(e):"map-image"===e.type?this._getSubLayer(e,t).catch((()=>{const t=new n("search:create-featurelayer","Could not create a FeatureLayer from the MapImageLayer",{layer:e});return z.error(t),null})):"building-scene"===e.type?this._getBuildingSubLayer(e,t):Promise.resolve(null)}_getLayerJSON(e){return"function"==typeof e.toJSON?e.toJSON():e}_updateDefaultSources(){const{defaultSources:e,includeDefaultSources:t}=this;e.removeAll(),t&&e.addMany([...this._convertApplicationProperties(),...this._convertHelperServices()])}_abortGoTo(){this._gotoController&&this._gotoController.abort(),this._gotoController=null}_clear(){this._abortGoTo(),this._set("resultCount",null),this._set("results",null),this._set("suggestions",null),this._set("suggestionCount",null),this._set("selectedResult",null),this._set("selectedSuggestion",null),this.emit("search-clear")}_closePopup(){var e;const t=null==(e=this.view)?void 0:e.popup,{resultGraphic:r}=this;if(!t||!r)return;const{selectedFeature:s}=t;s&&s===r&&t.close()}_suggestTimer(e,t){const r=null!=e?e:this.suggestionDelay;return f(r,null,t&&t.signal)}_createLocationForSearch(e){return e instanceof s?F(e.geometry):e instanceof w?e:Array.isArray(e)&&2===e.length?new w({longitude:e[0],latitude:e[1]}):null}_createSuggestionForSearch(e){if(e&&Q(e,"key")&&Q(e,"text")&&Q(e,"sourceIndex"))return e;const t=this._createLocationForSearch(e),r="string"==typeof e?e:this.searchTerm,{selectedSuggestion:s,selectedResult:o}=this,l=!e&&s&&o,i=l&&s.key===o.key&&s.sourceIndex===o.sourceIndex,a=l&&s.location;return i||a?s:{location:d(t),text:t?"":r,sourceIndex:null,key:null}}_getFirstResult(e){let t=null;return e&&e.some((e=>{const{results:r}=e,s=r[0],o=!!s;return o&&(t=s),o})),t}_selectFirstResult(e){return this.autoSelect&&e?this.select(e):Promise.resolve(null)}_suggestImmediate(e,t){return this.when().then((()=>this._getSuggestionsFromSources(e,t))).then((r=>{var s;if(null!=(s=d(null==t?void 0:t.signal))&&s.aborted)return null;const o={activeSourceIndex:this.activeSourceIndex,searchTerm:e,numResults:0,numErrors:0,errors:[],results:[]};return this._formatResponse(o,r),o}))}_formatSourceResponse(e,t,r){const s=t&&t.value||[],o=t&&t.error,l=this.allSources.getItemAt(r);if(o){const t={sourceIndex:r,source:l,error:o};e.errors.push(t),z.error(o),e.numErrors++}else{const t={sourceIndex:r,source:l,results:s};e.results.push(t),e.numResults+=s.length}}_formatResponse(e,t,r){if(t)if(e.activeSourceIndex===te){const s=r&&Q(r,"sourceIndex")&&-1!==r.sourceIndex?r.sourceIndex:void 0;t.forEach(((t,r)=>{const o=void 0!==s?s:r;this._formatSourceResponse(e,t,o)}))}else this._formatSourceResponse(e,t[0],e.activeSourceIndex)}_getResultsFromSources(e,t){const{allSources:r}=this,s=!e.location&&Q(e,"sourceIndex")?e.sourceIndex:this.activeSourceIndex,o=[];if(!r.length){const e=new n("search:no-sources-defined","At least one source is required.",{allSources:r});return z.error(e),Promise.reject(e)}return s===te?r.forEach(((r,s)=>{o.push(this._getResultsFromSource(e,s,t))})):o.push(this._getResultsFromSource(e,s,t)),y(o)}_getSuggestionsFromSources(e,t){const{allSources:r,activeSourceIndex:s}=this,o=[];if(!r.length){const e=new n("suggest:no-sources-defined","At least one source is required.",{allSources:r});return z.error(e),Promise.reject(e)}return s===te?r.forEach(((r,s)=>{o.push(this._getSuggestionsFromSource(e,s,t))})):o.push(this._getSuggestionsFromSource(e,s,t)),y(o)}_getResultsFromSource(e,t,r){var s;const o=this.allSources.getItemAt(t),{location:l=null}=e,i=(null==(s=this.view)?void 0:s.spatialReference)||X,a=Q(o,"maxResults")?o.maxResults:this.maxResults,n=!!(o instanceof P&&Q(o,"exactMatch"))&&o.exactMatch,{view:u}=this;return o.getResults({view:u,sourceIndex:t,location:l,suggestResult:e,spatialReference:i,exactMatch:n,maxResults:a},r)}_getSuggestionsFromSource(e,t,r){const s=this.allSources.getItemAt(t),o=Q(s,"suggestionsEnabled")?s.suggestionsEnabled:this.suggestionsEnabled,l=e.length,i=Q(s,"minSuggestCharacters")?s.minSuggestCharacters:this.minSuggestCharacters;if(o&&e.trim()&&l>=i){var a;const o=(null==(a=this.view)?void 0:a.spatialReference)||X,l=Q(s,"maxSuggestions")?s.maxSuggestions:this.maxSuggestions,{view:i}=this,n=!!(s instanceof P&&Q(s,"exactMatch"))&&s.exactMatch;return s.getSuggestions({view:i,sourceIndex:t,suggestTerm:e,spatialReference:o,maxSuggestions:l,exactMatch:n},r)}return Promise.resolve(null)}_getLayerSourcePopupTemplate(e){const{layer:t}=e;if(t)return Q(e,"popupTemplate")?e.popupTemplate:t.popupTemplate}_getSourceIndexOfResult(e){const t=this.results;let r=null;return t.some((t=>t.results.some((s=>s===e&&(r=t.sourceIndex,!0))))),r}async _goToSearchResult(e){const t=!!e;this._abortGoTo();const r=new AbortController;this._gotoController=r;const s={target:{target:e},options:{animate:t,signal:r.signal}};await this.callGoTo(s),this._gotoController=null}_getDefaultSymbol(e){var t;const{defaultSymbols:r}=this,s=null==(t=e.feature)?void 0:t.geometry;if(m(s))return null;const o=this._get("defaultSymbol");if(o&&("point"===s.type||"multipoint"===s.type))return o;switch(s.type){case"point":case"multipoint":return r.point;case"polyline":return r.polyline;case"extent":case"polygon":return r.polygon;default:return null}}_removeHighlight(){this._handles.remove(K)}async _getLayerView(e){const{view:t}=this;if(!e||!t||"building-component"===e.layer.type||"subtype-sublayer"===e.layer.type)return null;const{layer:r}=e;return await t.when(),t.whenLayerView(r)}_highlightFeature(e){const{graphic:t,layerView:r}=e,{attributes:s,layer:o}=t,{objectIdField:l}=o,i=s&&s[l],a=r.highlight(i||t);this._handles.add(a,K)}_setResultFloor(e){var t,r,s;const{view:o}=this,l=null==(t=e.feature)?void 0:t.attributes,i=null==(r=e.feature)?void 0:r.sourceLayer;if(i&&"floorInfo"in i&&null!=i&&null!=(s=i.floorInfo)&&s.floorField&&l){const e=l[i.floorInfo.floorField];o.emit("select-result-floor",e)}}};re.ALL_INDEX=te,e([_()],re.prototype,"_searching",void 0),e([_()],re.prototype,"_updatingPromise",void 0),e([_({readOnly:!0,value:null})],re.prototype,"activeSource",null),e([_()],re.prototype,"activeSourceIndex",null),e([_()],re.prototype,"allPlaceholder",null),e([_({readOnly:!0})],re.prototype,"allSources",null),e([_()],re.prototype,"autoNavigate",void 0),e([_()],re.prototype,"autoSelect",void 0),e([_()],re.prototype,"defaultPopupTemplate",void 0),e([_({readOnly:!0})],re.prototype,"defaultSources",void 0),e([_()],re.prototype,"defaultSymbol",null),e([_()],re.prototype,"defaultSymbols",void 0),e([_()],re.prototype,"includeDefaultSources",void 0),e([_()],re.prototype,"locationEnabled",null),e([_()],re.prototype,"maxInputLength",void 0),e([_()],re.prototype,"maxResults",void 0),e([_()],re.prototype,"maxSuggestions",void 0),e([_()],re.prototype,"messages",void 0),e([_()],re.prototype,"minSuggestCharacters",void 0),e([_({readOnly:!0})],re.prototype,"placeholder",null),e([_()],re.prototype,"popupEnabled",void 0),e([_({type:o})],re.prototype,"popupTemplate",void 0),e([_({type:T})],re.prototype,"portal",void 0),e([_()],re.prototype,"resultCount",void 0),e([_()],re.prototype,"resultGraphicEnabled",void 0),e([_({readOnly:!0})],re.prototype,"resultGraphic",void 0),e([_({readOnly:!0})],re.prototype,"results",void 0),e([_({readOnly:!0})],re.prototype,"selectedSuggestion",void 0),e([_()],re.prototype,"searchAllEnabled",void 0),e([_({readOnly:!0})],re.prototype,"selectedResult",void 0),e([_()],re.prototype,"searchTerm",null),e([_({type:W})],re.prototype,"sources",void 0),e([_({readOnly:!0})],re.prototype,"state",null),e([_()],re.prototype,"suggestionDelay",void 0),e([_()],re.prototype,"suggestionCount",void 0),e([_({readOnly:!0})],re.prototype,"suggestions",void 0),e([_()],re.prototype,"suggestionsEnabled",void 0),e([_({readOnly:!0})],re.prototype,"updating",null),e([_()],re.prototype,"view",void 0),e([_()],re.prototype,"clear",null),re=e([b(q)],re);const se=re;export{se as default};
@@ -1 +0,0 @@
1
- "use strict";(self.webpackChunkRemoteClient=self.webpackChunkRemoteClient||[]).push([[4720],{14720:(e,t,a)=>{a.r(t),a.d(t,{applyEdits:()=>u});var r=a(38171),s=a(80539),i=a(20102),d=a(22974),n=a(70586),l=a(17452),o=a(82526);async function u(e,t,a,r={}){let s,i;const n={edits:a,result:new Promise(((e,t)=>{s=e,i=t}))};e.emit("apply-edits",n);try{var l;const{results:i,edits:n}=await p(e,t,a,r),o=e=>e.filter((e=>!e.error)).map(d.d9),u={edits:n,addedFeatures:o(i.addFeatureResults),updatedFeatures:o(i.updateFeatureResults),deletedFeatures:o(i.deleteFeatureResults),addedAttachments:o(i.addAttachmentResults),updatedAttachments:o(i.updateAttachmentResults),deletedAttachments:o(i.deleteAttachmentResults)};return null!=(l=i.editedFeatureResults)&&l.length&&(u.editedFeatures=i.editedFeatureResults),(u.addedFeatures.length||u.updatedFeatures.length||u.deletedFeatures.length||u.addedAttachments.length||u.updatedAttachments.length||u.deletedAttachments.length)&&e.emit("edits",u),s(u),i}catch(e){throw i(e),e}}async function p(e,t,a,r){if(await e.load(),!function(e){return e&&null!=e.applyEdits}(t))return Promise.reject(new i.Z(`${e.type}-layer:no-editing-support`,"Layer source does not support applyEdits capability",{layer:e}));if(!e.editingEnabled)throw new i.Z(`${e.type}-layer:editing-disabled`,"Editing is disabled for layer",{layer:e});const{edits:d,options:l}=await async function(e,t,a){const r=t&&(t.addFeatures||t.updateFeatures||t.deleteFeatures),d=t&&(t.addAttachments||t.updateAttachments||t.deleteAttachments);if(!t||!r&&!d)throw new i.Z(`${e.type}-layer:missing-parameters`,"'addFeatures', 'updateFeatures', 'deleteFeatures', 'addAttachments', 'updateAttachments' or 'deleteAttachments' parameter is required");if(!e.capabilities.data.isVersioned&&a&&a.gdbVersion)throw new i.Z(`${e.type}-layer:invalid-parameter`,"'gdbVersion' is applicable only if the layer supports versioned data. See: 'capabilities.data.isVersioned'");if(!e.capabilities.editing.supportsRollbackOnFailure&&a&&a.rollbackOnFailureEnabled)throw new i.Z(`${e.type}-layer:invalid-parameter`,"This layer does not support 'rollbackOnFailureEnabled' parameter. See: 'capabilities.editing.supportsRollbackOnFailure'");if(!e.capabilities.editing.supportsGlobalId&&a&&a.globalIdUsed)throw new i.Z(`${e.type}-layer:invalid-parameter`,"This layer does not support 'globalIdUsed' parameter. See: 'capabilities.editing.supportsGlobalId'");if(!e.capabilities.editing.supportsGlobalId&&d)throw new i.Z(`${e.type}-layer:invalid-parameter`,"'addAttachments', 'updateAttachments' and 'deleteAttachments' are applicable only if the layer supports global ids. See: 'capabilities.editing.supportsGlobalId'");if((!a||!a.globalIdUsed)&&d)throw new i.Z(`${e.type}-layer:invalid-parameter`,"When 'addAttachments', 'updateAttachments' or 'deleteAttachments' is specified, globalIdUsed should be set to true");const l={...a};if(null!=l.rollbackOnFailureEnabled||e.capabilities.editing.supportsRollbackOnFailure||(l.rollbackOnFailureEnabled=!0),!1===l.rollbackOnFailureEnabled&&"original-and-current-features"===l.returnServiceEditsOption)throw new i.Z(`${e.type}-layer:invalid-parameter`,"'original-and-current-features' is valid for 'returnServiceEditsOption' only when 'rollBackOnFailure' is true.");if(!e.capabilities.editing.supportsReturnServiceEditsInSourceSpatialReference&&l.returnServiceEditsInSourceSR)throw new i.Z(`${e.type}-layer:invalid-parameter`,"This layer does not support 'returnServiceEditsInSourceSR' parameter. See: 'capabilities.editing.supportsReturnServiceEditsInSourceSpatialReference'");if(l.returnServiceEditsInSourceSR&&"original-and-current-features"!==l.returnServiceEditsOption)throw new i.Z(`${e.type}-layer:invalid-parameter`,"'returnServiceEditsOption' is valid only when 'returnServiceEditsOption' is set to 'original-and-current-features'");const o={...t};if(o.addFeatures=t&&s.Z.isCollection(t.addFeatures)?t.addFeatures.toArray():o.addFeatures||[],o.updateFeatures=t&&s.Z.isCollection(t.updateFeatures)?t.updateFeatures.toArray():o.updateFeatures||[],o.deleteFeatures=t&&s.Z.isCollection(t.deleteFeatures)?t.deleteFeatures.toArray():o.deleteFeatures||[],o.addFeatures.length&&!e.capabilities.operations.supportsAdd)throw new i.Z(`${e.type}-layer:unsupported-operation`,"Layer does not support adding features.");if(o.updateFeatures.length&&!e.capabilities.operations.supportsUpdate)throw new i.Z(`${e.type}-layer:unsupported-operation`,"Layer does not support updating features.");if(o.deleteFeatures.length&&!e.capabilities.operations.supportsDelete)throw new i.Z(`${e.type}-layer:unsupported-operation`,"Layer does not support deleting features.");o.addAttachments=o.addAttachments||[],o.updateAttachments=o.updateAttachments||[],o.deleteAttachments=o.deleteAttachments||[],o.addFeatures=o.addFeatures.map(m),o.updateFeatures=o.updateFeatures.map(m);const u=a&&a.globalIdUsed;return o.addFeatures.forEach((t=>function(e,t,a){c(e,t,a)}(t,e,u))),o.updateFeatures.forEach((t=>function(e,t,a){if(c(e,t,a),"geometry"in e&&(0,n.pC)(e.geometry)&&!t.capabilities.editing.supportsGeometryUpdate)throw new i.Z(`${t.type}-layer:unsupported-operation`,"Layer does not support geometry updates.")}(t,e,u))),o.deleteFeatures.forEach((t=>function(e,t,a){c(e,t,a)}(t,e,u))),o.addAttachments.forEach((t=>h(t,e))),o.updateAttachments.forEach((t=>h(t,e))),{edits:await y(o),options:l}}(e,a,r);return d.addFeatures.length||d.updateFeatures.length||d.deleteFeatures.length||d.addAttachments.length||d.updateAttachments.length||d.deleteAttachments.length?{edits:d,results:await t.applyEdits(d,l)}:{edits:d,results:{addFeatureResults:[],updateFeatureResults:[],deleteFeatureResults:[],addAttachmentResults:[],updateAttachmentResults:[],deleteAttachmentResults:[]}}}function c(e,t,a){if(a){if("attributes"in e&&!e.attributes[t.globalIdField])throw new i.Z(`${t.type}-layer:invalid-parameter`,"Feature should have 'globalId' when 'globalIdUsed' is true");if(!("attributes"in e)&&!e.globalId)throw new i.Z(`${t.type}-layer:invalid-parameter`,"'globalId' of the feature should be passed when 'globalIdUsed' is true")}if("geometry"in e&&(0,n.pC)(e.geometry)){if(e.geometry.hasZ&&!1===t.capabilities.data.supportsZ)throw new i.Z(`${t.type}-layer:z-unsupported`,"Layer does not support z values while feature has z values.");if(e.geometry.hasM&&!1===t.capabilities.data.supportsM)throw new i.Z(`${t.type}-layer:m-unsupported`,"Layer does not support m values while feature has m values.")}}function h(e,t){const{feature:a,attachment:r}=e;if(!a||"attributes"in a&&!a.attributes[t.globalIdField])throw new i.Z(`${t.type}-layer:invalid-parameter`,"Attachment should have reference to a feature with 'globalId'");if(!("attributes"in a)&&!a.globalId)throw new i.Z(`${t.type}-layer:invalid-parameter`,"Attachment should have reference to 'globalId' of the parent feature");if(!r.globalId)throw new i.Z(`${t.type}-layer:invalid-parameter`,"Attachment should have 'globalId'");if(!r.data&&!r.uploadId)throw new i.Z(`${t.type}-layer:invalid-parameter`,"Attachment should have 'data' or 'uploadId'");if(!(r.data instanceof File&&r.data.name||r.name))throw new i.Z(`${t.type}-layer:invalid-parameter`,"'name' is required when attachment is specified as Base64 encoded string using 'data'");if(!t.capabilities.editing.supportsUploadWithItemId&&r.uploadId)throw new i.Z(`${t.type}-layer:invalid-parameter`,"This layer does not support 'uploadId' parameter. See: 'capabilities.editing.supportsUploadWithItemId'");if("string"==typeof r.data){const e=(0,l.sJ)(r.data);if(e&&!e.isBase64)throw new i.Z(`${t.type}-layer:invalid-parameter`,"Attachment 'data' should be a Blob, File or Base64 encoded string")}}async function y(e){const t=e.addFeatures,a=e.updateFeatures,r=t.concat(a).map((e=>e.geometry)),s=await(0,o.aX)(r),i=t.length,d=a.length;return s.slice(0,i).forEach(((t,a)=>e.addFeatures[a].geometry=t)),s.slice(i,i+d).forEach(((t,a)=>e.updateFeatures[a].geometry=t)),e}function m(e){const t=new r.Z;return e.attributes||(e.attributes={}),t.geometry=e.geometry,t.attributes=e.attributes,t}}}]);