@vertigis/arcgis-extensions 54.14.5 → 54.15.0

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 (41) hide show
  1. package/data/Feature.js +1 -1
  2. package/declarations/arcgis-js-api-extensions/index.d.ts +0 -29
  3. package/docs/html/assets/hierarchy.js +1 -1
  4. package/docs/html/assets/navigation.js +1 -1
  5. package/docs/html/assets/search.js +1 -1
  6. package/docs/html/classes/utilities_format_date.DateFormatter.html +1 -1
  7. package/docs/html/classes/utilities_format_number.NumberFormatter.html +1 -1
  8. package/docs/html/classes/utilities_format_time.TimeFormatter.html +1 -1
  9. package/docs/html/classes/utilities_log.ConsoleLogger.html +1 -1
  10. package/docs/html/classes/utilities_log.LoggerBase.html +1 -1
  11. package/docs/html/functions/utilities_arcade.constructProfile.html +43 -0
  12. package/docs/html/functions/utilities_arcade.createExecutorForExpression.html +53 -0
  13. package/docs/html/functions/utilities_arcade.isArcadeScriptAsync.html +7 -2
  14. package/docs/html/functions/utilities_arcade.isExpressionAsyncOnly.html +43 -0
  15. package/docs/html/functions/utilities_arcade.runArcadeExpression.html +9 -3
  16. package/docs/html/functions/utilities_arcade.runAsyncArcadeExpression.html +7 -2
  17. package/docs/html/functions/utilities_arcade.runAsyncExpression.html +47 -0
  18. package/docs/html/functions/utilities_arcade.runSyncExpression.html +52 -0
  19. package/docs/html/functions/utilities_arcade.toArcadeVariable.html +57 -0
  20. package/docs/html/hierarchy.html +19 -19
  21. package/docs/html/interfaces/utilities_arcade.RunArcadeExpressionParams.html +15 -6
  22. package/docs/html/interfaces/utilities_collection.AfterItemChangeEvent.html +1 -1
  23. package/docs/html/interfaces/utilities_format_FormatSettings.FormatSettings.html +1 -1
  24. package/docs/html/interfaces/utilities_format_date.DateFormatterProperties.html +1 -1
  25. package/docs/html/interfaces/utilities_format_date.DateSettings.html +1 -1
  26. package/docs/html/interfaces/utilities_format_number.NumberFormatterProperties.html +1 -1
  27. package/docs/html/interfaces/utilities_format_number.NumberSettings.html +1 -1
  28. package/docs/html/interfaces/utilities_format_string.FormatOptions.html +1 -1
  29. package/docs/html/interfaces/utilities_format_time.TimeFormatterProperties.html +1 -1
  30. package/docs/html/interfaces/utilities_format_time.TimeSettings.html +1 -1
  31. package/docs/html/interfaces/utilities_log.LogMessageOptions.html +1 -1
  32. package/docs/html/interfaces/utilities_log.LogMessageResourceOptions.html +1 -1
  33. package/docs/html/modules/utilities_arcade.html +6 -2
  34. package/docs/html/types/utilities_arcade.ArcadeVariable.html +39 -0
  35. package/docs/html/variables/version.version.html +1 -1
  36. package/mapping/MapExtension.js +1 -1
  37. package/package.json +1 -1
  38. package/utilities/arcade.d.ts +98 -4
  39. package/utilities/arcade.js +1 -1
  40. package/version.d.ts +1 -1
  41. package/version.js +1 -1
@@ -1 +1 @@
1
- var e;import{__decorate as t}from"tslib";import s,{}from"@arcgis/core/core/Collection";import{ArgumentError as i}from"../ArgumentError.js";import{EntityBase as a}from"../Entity.js";import{InvalidOperationError as n}from"../InvalidOperationError.js";import{isBasemapExtension as o,isBookmark as r,isGroundExtension as p,isLayerPreset as h,isMenu as m,isTableExtension as d,ItemType as l}from"../ItemType.js";import{TableExtension as _}from"../data/TableExtension.js";import{layerToParentJsonCache as b}from"../json/LayerJson.js";import{applyJsonToWebMap as c}from"../json/WebMapJson.js";import{applyJsonToWebScene as f}from"../json/WebSceneJson.js";import{LayerPreset as E}from"../layer-preset/LayerPreset.js";import{Menu as x}from"../menus/Menu.js";import{DefaultArcGISRequestHelper as u}from"../support/ArcGISRequestHelper.js";import{FormatSettings as y}from"../support/FormatSettings.js";import{InitializableCollectionProxy as w}from"../support/InitializableCollectionProxy.js";import{ReadOnlyInitializableCollection as M}from"../support/ReadOnlyInitializableCollection.js";import{serializable as g}from"../support/Serializable.js";import{WellKnownBasemap as v}from"../support/esri.js";import{createIHandle as I,notifyChange as A,onWatch as S,watch as O,watchEvent as z}from"../support/observableUtils.js";import{ReadOnlyCollection as T}from"../utilities/ReadOnlyCollection.js";import P from"../utilities/_ReferenceCountedHandle.js";import{groundsAreEquivalent as L}from"../utilities/_layers.js";import{basemapsAreEquivalent as V,createStandardBasemap as B,getStandardBasemapId as k,isStandardBasemap as C,isStandardBasemap2D as H}from"../utilities/basemaps.js";import{checkArg as j}from"../utilities/checkArg.js";import{compare as R}from"../utilities/collection.js";import{load as N}from"../utilities/esri.js";import{isGroupLayerExtension as W}from"../utilities/extensions.js";import{filter as J}from"../utilities/iterable.js";import{isWMTSLayer as F,layersAreEquivalent as G}from"../utilities/layers.js";import{getLogger as q}from"../utilities/log.js";import{getMapSpatialReference as K,isMap as D,isWebMap as U,isWebScene as $}from"../utilities/mapping.js";import{toPortalItem as X}from"../utilities/portal.js";import{parallelEach as Y}from"../utilities/promise.js";import{onCollectionPropertyChange as Q,onEach as Z}from"../utilities/watch.js";import{BasemapExtension as ee}from"./BasemapExtension.js";import{Bookmark as te}from"./Bookmark.js";import{GroundExtension as se}from"./GroundExtension.js";import{MapConstraints as ie}from"./MapConstraints.js";import{_assignLayerExtensions as ae}from"./_LayerExtension.js";import{LayerExtensionCollectionImpl as ne}from"./_LayerExtensionCollectionImpl.js";const oe=q("MapExtension");let re=class extends a{static{e=this}static _mapEventHandlesKey="map-extension-map-event-handles";static _sceneEventHandlesKey="map-extension-scene-event-handles";get webMap(){return this._webMap}get webScene(){return this._webScene}get map(){return this._currentMap}get viewMode(){return this.map?$(this.map)?"scene":"map":this.initialViewMode}get initialViewMode(){return this.webMap&&this.webScene?this._initialViewMode||"map":$(this.map)||this.webScene&&!this.webMap?"scene":"map"}set initialViewMode(e){this._initialViewMode=e}get requestHelper(){return this._requestHelper||(this._requestHelper=new u),this._requestHelper}set requestHelper(e){this._requestHelper=e}get basemapExtension(){return this._basemapExtension}set basemapExtension(e){const t=this._basemapExtension;if(t!==e)if(t&&t._setMapExtension(void 0),e){if(e._setMapExtension(this),this.isInitialized&&!e.basemap){if(e.isInitialized)throw e._setMapExtension(void 0),new n("Cannot set MapExtension.basemapExtension without a valid Esri Basemap object");e.initialize()}this._ensureIsBasemapOption(e),this.map&&e.basemap&&e.basemap!==this.map.basemap?this.map.basemap=e.basemap:this._basemapExtension=e}else this.map.basemap=void 0,this._basemapExtension=void 0}get groundExtension(){return this._groundExtension||(this.groundExtension=se.create({ground:this.map?.ground})),this._groundExtension}set groundExtension(e){if(!e)throw new n("Cannot set map.ground to undefined");const t=this._groundExtension;t!==e&&(t&&t._setMapExtension(void 0),e._setMapExtension(this),e._resolveGround(),e.ground?(this._groundExtensions.set(e.ground,e),this.map&&e.ground!==this.map.ground?this.map.ground=e.ground:this._groundExtension=e):this._groundExtension=e)}get basemapOptions(){return this._basemapOptions}get bookmarks(){return this._bookmarks}get initialBasemapExtension(){return this._initialBasemapExtension}get initialLayerPreset(){return this._initialLayerPreset}set initialLayerPreset(e){if(!e)return void(this._initialLayerPreset=void 0);const t=h(e)?e:new E(e);this._initialLayerPreset=t}get _spatialReference(){return K(this.map)}get webMapItemTitle(){if(this._webMapItem)return this._webMapItem.title}get webSceneItemTitle(){if(this._webSceneItem)return this._webSceneItem.title}get title(){return this._title?this._title:this._webMapItem&&"map"===this.viewMode?this.webMapItemTitle:this._webSceneItem&&"scene"===this.viewMode?this.webSceneItemTitle:void 0}set title(e){this._title=e}formatSettings;constraints;onClick;onHover;onHoverEnd;onInitialized;onViewpointChanged;get contextMenu(){return this._contextMenu}set contextMenu(e){this._contextMenu=e,e&&this.isInitialized&&!e.isInitialized&&(async()=>{try{await e.initialize()}catch(e){e instanceof Error&&oe.error({message:"An error occurred while initializing context menu.",error:e})}})()}_layerViews=new s;get _allLayerViews(){const e=t=>{const i=[t];return s.isCollection(t.sublayerViews)?i.push(...t.sublayerViews.toArray().flatMap(e)):s.isCollection(t.layerViews)&&i.push(...t.layerViews.toArray().flatMap(e)),i};return this._layerViews.toArray().flatMap(e)}get layerExtensions(){return this._layerExtensions}get isSwitchingMap(){return this._isSwitchingMap}tableExtensions;allLayerExtensions;_itemType=l.MAP_EXTENSION;_isSwitchingMap=!1;_map;_scene;_deserializedMapPromise;_deserializedViewMode;_deserializedViewModePromise;_deferredProperties;_currentMap;_requestHelper;_basemapExtension;_groundExtension;_basemapOptions;_groundExtensions;_bookmarks;_layerExtensions;_webMap;_webMapItem;_webScene;_webSceneItem;_title;_initialViewMode;_initialLayerPreset;_initialBasemapExtension;_skipBasemapOptions=!1;_createScenePromise;_createMapPromise;_contextMenu;constructor(t){super(t);let a={...t};this._basemapOptions=new pe(this),this._groundExtensions=new WeakMap,this._layerExtensions=this._createLayerExtensionCollection(),this.tableExtensions=this._createTableExtensionCollection(),this.formatSettings=this._createFormatSettings(),this._bookmarks=new s,this.constraints=new ie,this._handles.add([O(this,"_map",t=>{t?this._handles.add([Z(t.layers,"layerview-create",e=>{this._layerViews.add(e.layerView)}),Z(t.layers,"layerview-destroy",e=>{this._layerViews.remove(e.layerView)})],e._mapEventHandlesKey):this._handles.remove(e._mapEventHandlesKey)},{sync:!0}),O(this,"_scene",t=>{t?this._handles.add([Z(t.layers,"layerview-create",e=>{this._layerViews.add(e.layerView)}),Z(t.layers,"layerview-destroy",e=>{this._layerViews.remove(e.layerView)})],e._sceneEventHandlesKey):this._handles.remove(e._sceneEventHandlesKey)},{sync:!0})]);const{webMap:n,webScene:o,initialViewMode:r,map:p,basemapOptions:h}=a;if(this._webMap=n,this._webScene=o,this._webMapItem=de(n),this._webSceneItem=de(o),this.initialViewMode=r,$(p)&&o)throw new i("Cannot specify webScene property if map is initialized to a WebScene instance.");if(D(p)&&n)throw new i("Cannot specify webMap property if map is initialized to a 2D Map instance.");if($(p)||U(p)||D(p))this.assignProperties({basemapOptions:h}),this._skipBasemapOptions=!!h;else{const{layerExtensions:e,tableExtensions:t,groundExtension:s,basemapOptions:i,basemapExtension:n,...o}=a;this._deferredProperties={layerExtensions:e,tableExtensions:t,groundExtension:s,basemapOptions:i,basemapExtension:n},a=o,i&&(this._skipBasemapOptions=!0)}this._initMapFromProperties(a),this._handles.add([O(this,"map.basemap",()=>this._onBasemapChange(),{sync:!0}),O(this,"map.ground",()=>this._onGroundChange(),{sync:!0})]),this.allLayerExtensions=new me(this),this.map?.basemap&&this._onBasemapChange()}getLayerExtensionsForView(e=this.viewMode){return(("map"===e?this._map:this._scene)?.layers.toArray()??[]).map(e=>this._layerExtensions._forLayer(e)).filter(e=>!e.dynamicallyAddedLayer)}getAllFeatureSources(e=()=>!0){const t=[],s=a=>{a.hasFeatures&&t.push(a);for(const t of a.sublayerExtensions.initializedItems.filter(e).toArray())i(t);if(W(a))for(const t of a.layerExtensions.initializedItems.filter(e).toArray())s(t)},i=s=>{t.push(s);for(const t of s.sublayerExtensions.initializedItems.filter(e).toArray())i(t)};for(const t of this.layerExtensions.initializedItems.filter(e).toArray())s(t);for(const s of this.tableExtensions.initializedItems.filter(e).toArray())t.push(s);if(this.basemapExtension){for(const t of this.basemapExtension.baseLayerExtensions.initializedItems.filter(e).toArray())s(t);for(const t of this.basemapExtension.referenceLayerExtensions.initializedItems.filter(e).toArray())s(t)}return t}isSupportedViewMode(e){return e===this.viewMode||!(!this.webMap&&!this.webScene)&&("scene"===e?!!this.webScene:!!this.webMap)}async switchViewMode(e){if(j("viewMode",e).isNotMissing().satisfies(e=>this.isSupportedViewMode(e),"Unsupported view mode."),this.viewMode===e)return;let t;"scene"===e?(await this._createScene(),t=this._scene):(await this._createMap(),t=this._map),await this.switchMap(t),A(this,"viewMode"),A(this,"title")}async switchMap(t){if(j("newMap",t).isNotMissing(),t===this.map)return;if(!this.map)return void this._setMap(t);this._layerViews.removeAll(),"map"===this.viewMode?this._handles.remove(e._mapEventHandlesKey):this._handles.remove(e._sceneEventHandlesKey),this._isSwitchingMap=!0,this.isInitialized&&await be(t),this._preserveBasemapAndGround(t);const s=new Map(this.map.layers.map(e=>[e,this.layerExtensions.forLayer(e)])),i=new Map(this.map.tables.map(e=>[e,this.tableExtensions.forTable(e)])),{basemapExtension:a}=this;this._setMap(t),this._updateBookmarks();const n=[];for(const e of this.map.layers.toArray()){const t=[...J(s.entries(),([t])=>G(t,e))];if(1===t.length){const[s]=t;n.push((async()=>{const t=s[1];await t._switchLayer(e),this._layerExtensions._register(t)})())}else{const t=this._layerExtensions._forLayer(e);t&&t.layer!==e&&n.push(t._switchLayer(e))}}for(const e of this.map.tables.toArray()){const t=[...J(i.entries(),([t])=>G(t,e))];if(1===t.length){const[s]=t;n.push((async()=>{const t=s[1];await t._switchTable(e),this.tableExtensions.add(t)})())}else{const t=this.tableExtensions.forTable(e);t&&t.table!==e&&n.push(t._switchTable(e))}}this.map.basemap&&a&&V(this.map.basemap,a.basemap)&&n.push((async()=>{await a._switchBasemap(this.map.basemap),this.basemapExtension=a})()),await Promise.all(n),this.isInitialized&&(a&&a!==this.basemapExtension&&(this.basemapOptions.includes(a)||await a.destroy()),await this._initializeChildren()),this._isSwitchingMap=!1}async setWebMap(e){if(!e&&this.webMap&&!this.webScene)throw new n("Cannot unset both webMap and webScene.");const t=this._map?.basemap;this._webMap=e,this._map=void 0,this._createMapPromise=void 0,this._webMapItem=de(e),await N(this._webMapItem),"map"===this.viewMode&&(e?(this._basemapOptions.isExplicitlyModified||this._basemapOptions.removeAllInternal(),await this._createMap(),await this.switchMap(this._map),await this._createStandardBasemapOptions(),this._basemapOptions.reorderInternal(this.basemapExtension,0),this._initialBasemapExtension=this.basemapExtension):await this.switchViewMode("scene")),this._cleanPreviousBasemapOptions(t),A(this,"webMap"),A(this,"initialViewMode"),A(this,"title")}async setWebScene(e){if(!e&&this.webScene&&!this.webMap)throw new n("Cannot unset both webMap and webScene.");const t=this._scene?.basemap;this._webScene=e,this._scene=void 0,this._createScenePromise=void 0,this._webSceneItem=de(e),await N(this._webSceneItem),"scene"===this.viewMode&&(e?(this._basemapOptions.isExplicitlyModified||this._basemapOptions.removeAllInternal(),await this._createScene(),await this.switchMap(this._scene),await this._createStandardBasemapOptions(),this._basemapOptions.reorderInternal(this.basemapExtension,0),this._initialBasemapExtension=this.basemapExtension):await this.switchViewMode("map")),this._cleanPreviousBasemapOptions(t),A(this,"webScene"),A(this,"initialViewMode"),A(this,"title")}getDefaults(){const e=super.getDefaults();return e.initialViewMode="map",e}async _onDestroy(){await Promise.all([...Array.from(this._layerExtensions,e=>e.destroy()),...Array.from(this.tableExtensions,e=>e.destroy()),...Array.from(this._basemapOptions,e=>e.destroy()),...this._groundExtension?[this._groundExtension.destroy()]:[]]),this._layerExtensions.destroy(),this.tableExtensions.destroy(),this.allLayerExtensions.destroy(),this._basemapOptions.destroy(),this._bookmarks.destroy(),this._layerViews.destroy(),await super._onDestroy()}async _createScene(){if(!this._scene&&this.webScene)return this._createScenePromise=this._createScenePromise??(async()=>{const e=(await import("@arcgis/core/WebScene")).default;le(this.webScene)?(this._webSceneItem.type="Web Scene",this._scene=new e({portalItem:this._webSceneItem})):this._scene=e.fromJSON(this.webScene)})()}async _createMap(){if(!this._map&&this.webMap)return this._createMapPromise=this._createMapPromise??(async()=>{const e=(await import("@arcgis/core/WebMap")).default;le(this.webMap)?(this._webMapItem.type="Web Map",this._map=new e({portalItem:this._webMapItem})):this._map=e.fromJSON(this.webMap)})()}_getSerializableProperties(){return{...super._getSerializableProperties(),layerExtensions:{serializeModes:["initial","project"],deserialize:e=>{if(this.map&&e){const t="map"===this.viewMode,s=(t?this._scene:this._map)?.layers.toArray()??[],i=e.filter(e=>!s.includes(e.layer)&&!s.some(t=>e.layer&&G(t,e.layer)));ae(this.layerExtensions,i)}},serialize:e=>{if(this._deferredProperties?.layerExtensions)return this._deferredProperties.layerExtensions;{const t="map"===this.viewMode,s=(t?this._map:this._scene)?.layers.toArray();let i=(t?this._scene:this._map)?.layers.toArray()??[];return i=i.filter(e=>!s.find(t=>G(t,e))),this.layerExtensions.concat(i.map(e=>this._layerExtensions._forLayer(e))).filter(t=>"initial"!==e||!t.dynamicallyAddedLayer).toArray()}}},tableExtensions:{serializeModes:["initial","project"],deserialize:e=>{this.map?R(this.tableExtensions,e,{onNew:(e,t)=>{this.tableExtensions.add(d(e)?e:_.create(e),t)},onMatch:(e,t,s,i)=>{d(t)||e.assignProperties(t),s!==i&&this.tableExtensions.reorder(e,i)},equals:(e,t)=>d(t)?t===e:!!_._matchesRef(e,t.table)||e.id===t.id}):this._deferredProperties={...this._deferredProperties,tableExtensions:e}},serialize:()=>this._deferredProperties?.tableExtensions?this._deferredProperties?.tableExtensions:this.tableExtensions.toArray()},basemapExtension:{serializeModes:["project"],deserialize:e=>{if(this.map)if(e)if(o(e))this.basemapExtension=e;else{if(this.basemapExtension)return this.basemapExtension.assignPropertiesAsync(e);this.basemapExtension=ee.create(e)}else this.basemapExtension=void 0;else this._deferredProperties={...this._deferredProperties,basemapExtension:e}},serialize:()=>this._deferredProperties?.basemapExtension?this._deferredProperties?.basemapExtension:this.basemapExtension},basemapOptions:{serializeModes:["initial"],deserialize:e=>{this._skipBasemapOptions?this._skipBasemapOptions=!1:(R(this.basemapOptions,e,{onNew:(e,t)=>{this.basemapOptions.add(o(e)?e:ee.create(e),t)},onMatch:(e,t,s,i)=>{o(t)||e.assignProperties(t),s!==i&&this.basemapOptions.reorder(e,i)},onMissing:e=>{this.basemapOptions.remove(e)},equals:(e,t)=>{if(o(t))return t===e;if(e.id&&t.id)return e.id===t.id;{const s=e.toJSON();return V(s.basemap,t.basemap||t.baseMap)}}}),this.basemapExtension&&this._ensureIsBasemapOption(this.basemapExtension),this.isInitialized&&Y(this.basemapOptions.toArray(),e=>e._createBackingBasemap()))},serialize:()=>this._deferredProperties?.basemapOptions?this._deferredProperties?.basemapOptions:this.basemapOptions.toArray()},groundExtension:{serializeModes:["initial"],deserialize:e=>{if(this.map){if(!p(e))return this.groundExtension.assignPropertiesAsync(e);this.groundExtension=e}else this._deferredProperties={...this._deferredProperties,groundExtension:e}},serialize:()=>this._deferredProperties?.groundExtension?this._deferredProperties?.groundExtension:this.groundExtension},bookmarks:{serialize:()=>this.bookmarks.map(e=>e.toJSON()).toArray(),deserialize:e=>{this.bookmarks.addMany(e.map(e=>r(e)?e:new te(e)))}},webMap:{serializeModes:["initial"],deserialize:!1},webScene:{serializeModes:["initial"],deserialize:!1},initialLayerPreset:"initial",initialViewMode:{serializeModes:["initial","project"],serialize:e=>"project"===e?this.viewMode:"scene"!==this.initialViewMode||!this.webScene&&this.webMap?"map":"scene",deserialize:e=>{this.viewMode!==e&&(this._deserializedViewMode=e),this._initialViewMode=e},isDefault:(e,t)=>"project"!==t&&"map"===e},formatSettings:"initial",constraints:"initial",title:"initial",onClick:"initial",onHover:"initial",onHoverEnd:"initial",onInitialized:"initial",onViewpointChanged:"initial",contextMenu:{serializeModes:["initial"],deserialize:e=>{e?m(e)?this.contextMenu=e:this.contextMenu?this.contextMenu.assignProperties(e):this.contextMenu=x.create(e):this.contextMenu=void 0}},map:{serializeModes:["project"],serialize:()=>{b.lookup=new WeakMap;const e=this.layerExtensions.toArray().filter(e=>e.layer).map(e=>e._getProjectWebmapJSON()),t=this.tableExtensions.toArray().filter(e=>e.table).map(e=>({id:e.table.id,title:e.table.title}));return b.lookup=void 0,e.length>0||t.length>0?{operationalLayers:e,tables:t}:{}},deserialize:e=>{if(!this.map)throw new i("Cannot specify JSON object for the 'map' property. It must be an ArcGIS API Map instance. To specify JSON, use 'webMap' or 'webScene' instead.");if(D(e)||U(e)||$(e)){if(e!==this.map)throw new i("properties.map","Property 'map' is read-only.")}else this._deserializedMapPromise=(async()=>{this._deserializedViewMode&&this.webMap&&this.webScene&&(this._deserializedViewModePromise=this.switchViewMode(this._deserializedViewMode),await this._deserializedViewModePromise,this._deserializedViewMode=void 0,this._deserializedViewModePromise=void 0),await this._applyMapProperties(e,this.map),this._deserializedMapPromise=void 0})()}},requestHelper:{serialize:!1}}}async _applyMapProperties(e,t,s){await Y(this.basemapOptions.toArray(),e=>e._createBackingBasemap());let i=e;const a=this.basemapOptions.find(e=>V(e.basemap,i.baseMap));a&&(t.basemap=a.basemap,i={...i,baseMap:{...i.baseMap,title:t.basemap.title}}),$(t)?await f(i,t,s):await c(i,t,s)}_createFormatSettings(){return new y}_createLayerExtensionCollection(){return new ne(this)}_createTableExtensionCollection(){return new he(this)}async _onInitialize(){await super._onInitialize();const{basemapOptions:e,basemapExtension:t,webMap:s,webScene:i,...a}=this._deferredProperties??{};if(this.map||("scene"===this.initialViewMode?(await this._createScene(),this._setMap(this._scene)):(await this._createMap(),this._setMap(this._map))),this._webMapItem||this._webSceneItem?(await Promise.all([be(this.map),N(this._webMapItem),N(this._webSceneItem)]),_e(this._webMapItem,"webMap","Web Map"),_e(this._webSceneItem,"webScene","Web Scene")):await be(this.map),t&&(!o(t)&&t.basemap?this.basemapExtension=ee.create(t):await this.assignPropertiesAsync({basemapExtension:t}),await this.basemapExtension._createBackingBasemap()),e){const t=e.find(e=>o(e)&&V(this.map.basemap,e.toJSON().basemap));if(t){const e=t.toJSON().basemap?.id??t.basemap?.id,s=t.toJSON().basemap?.title;await t._switchBasemap(this.map.basemap),this.basemapExtension=t,e&&(this.map.basemap.id=e),s&&(this.map.basemap.title=s)}await this.assignPropertiesAsync({basemapOptions:e})}await this.assignPropertiesAsync(a),this._deferredProperties=void 0,this._initialBasemapExtension=this.basemapExtension,this._updateBookmarks();for(const e of this.layerExtensions.toArray())await e._createBackingLayer();await Promise.all(this.tableExtensions.map(e=>e._createBackingTable()).toArray())}async _postInitialize(){await super._postInitialize(),await this._createStandardBasemapOptions(),await Y(this.basemapOptions.toArray(),e=>e._createBackingBasemap()),this.initialLayerPreset&&await this.initialLayerPreset.applyTo(this)}*_initializableChildCollections(){yield*super._initializableChildCollections();const e=new s(this.layerExtensions.filter(e=>!!e.layer));e.remove=e=>this.layerExtensions.remove(e);const t=new s(this.tableExtensions.filter(e=>!!e.table));if(t.remove=e=>this.tableExtensions.remove(e),yield e,yield t,this.basemapExtension){const e=new s;e.add(this.basemapExtension),yield e}const i=new s;i.add(this.groundExtension),yield i}_preserveBasemapAndGround(e){(!e.basemap||H(e.basemap))&&this.map?.basemap&&H(this.map.basemap)&&(e.basemap=this.map.basemap),this.map?.ground&&e.ground&&L(this.map.ground,e.ground)&&(e.ground=this.map.ground)}_initMapFromProperties(e){const t=e.map;D(t)||U(t)||$(t)?this._setMap(t):"scene"===this.initialViewMode?e.webScene&&!le(e.webScene)&&(this._deferredProperties={webScene:e.webScene,...this._deferredProperties}):e.webMap&&!le(e.webMap)&&(this._deferredProperties={webMap:e.webMap,...this._deferredProperties})}_setMap(e){$(e)?this._scene=e:this._map=e,this._currentMap=e,this.basemapExtension?.basemap&&!e.basemap&&(e.basemap=this.basemapExtension.basemap),this.groundExtension?.ground&&!e.ground&&(e.ground=this.groundExtension.ground),A(this,"map")}_onBasemapChange(){if(this._basemapExtension){if(this.basemapExtension.basemap==this.map.basemap)return;this._basemapExtension._setMapExtension(void 0)}if(this.map.basemap){let e=this.basemapOptions.find(e=>this.map.basemap===e.basemap);if(!e){const t=this.basemapOptions.find(e=>V(e.basemap,this.map.basemap));t?(e=t,e._switchBasemap(this.map.basemap)):(e=ee.create({basemap:this.map.basemap}),this._basemapOptions.addInternal(e,0))}e.mapExtension!==this&&e._setMapExtension(this),this._basemapExtension=e}else this._basemapExtension=void 0;A(this,"basemapExtension")}_onGroundChange(){if(this._groundExtension){if(this.map.ground&&this.groundExtension.ground===this.map.ground)return void(this._groundExtensions.has(this.map.ground)||this._groundExtensions.set(this.map.ground,this.groundExtension));{const e=this.groundExtension,t=e.ground;e._setMapExtension(void 0),this.isSwitchingMap&&t&&t!==this._map?.ground&&t!==this._scene?.ground&&t!==this.map?.ground&&(this._groundExtensions.delete(t),e.destroy())}}this.map.ground&&!this._groundExtensions.has(this.map.ground)&&this._groundExtensions.set(this.map.ground,se.create({ground:this.map.ground}));const e=this._groundExtensions.get(this.map.ground);e&&e.mapExtension!==this&&e._setMapExtension(this),this._groundExtension=e,A(this,"groundExtension")}async _createStandardBasemapOptions(){const e=this._spatialReference;!this._basemapOptions.isExplicitlyModified&&e?.isWebMercator&&await Y([v.SATELLITE,v.HYBRID_VECTOR,v.STREETS_VECTOR,v.TOPO_VECTOR,v.STREETS_NAVIGATION_VECTOR,v.STREETS_NIGHT_VECTOR,v.TERRAIN_VECTOR,v.DARK_GRAY_VECTOR,v.GRAY_VECTOR,v.OCEANS_VECTOR,v.OPEN_STREET_MAP_VECTOR],async e=>{const t=await B(e);V(this.map.basemap,t)?this._basemapOptions.addInternal(this.basemapExtension):this._basemapOptions.addInternal(ee.create({basemap:t}),void 0,!1)})}_ensureIsBasemapOption(e){const t=this.basemapOptions.findIndex(t=>t.basemap===e.basemap);t>=0?this._basemapOptions.getItemAt(t)!==e&&(this._basemapOptions.removeAtInternal(t),this._basemapOptions.addInternal(e,t)):this._basemapOptions.addInternal(e,0)}_cleanPreviousBasemapOptions(e){if(e&&!C(e))for(let t=this._basemapOptions.length-1;t>=0;t--){const s=this._basemapOptions.getItemAt(t),i=V(s.basemap,e),a=V(s.basemap,this._map?.basemap)||V(s.basemap,this._scene?.basemap);i&&!a&&this._basemapOptions.removeAtInternal(t)}}_updateBookmarks(){this.bookmarks.removeMany(this.bookmarks.filter(e=>"map"===e.source)),U(this.map)&&this.map.bookmarks?.length>0?this.map.bookmarks.forEach(e=>{this.bookmarks.add(new te({source:"map",title:e.name,viewpoint:e.viewpoint}))}):$(this.map)&&this.map.presentation?.slides?.length>0&&this.map.presentation.slides.forEach(e=>{const t={source:"map",title:e.title.text,viewpoint:e.viewpoint},s=new te(t);this.bookmarks.add(s)})}};re=e=t([g],re);export{re as MapExtension};class pe extends w{isExplicitlyModified=!1;_mapExtension;constructor(e){super(new s),this._mapExtension=e}add(e,t){return super.add(e,t),this.isExplicitlyModified=!0,1===this.length&&this._mapExtension.map&&!this._mapExtension.basemapExtension&&(this._mapExtension.basemapExtension=e),this}addMany(e,t){return super.addMany(e,t),this.isExplicitlyModified=!0,this}addInternal(e,t,s=!0){const i=e=>{const t="-vector";return e?.endsWith(t)?e.substring(0,e.length-7):e};let a;if(e.basemap){const t=i(e.basemap.id);if(a=C(e.basemap)?this.findIndex(e=>i(e.basemap?.id)===t):this.findIndex(t=>V(t.basemap,e.basemap)),a>=0){if(!s)return;super.removeAt(a)}}super.add(e,t??(a>=0?a:void 0))}removeAt(e){const t=super.removeAt(e);return t&&(this.isExplicitlyModified=!0,t===this._mapExtension.basemapExtension&&(e<this.length?this._mapExtension.basemapExtension=this.getItemAt(e):this.length?this._mapExtension.basemapExtension=this.getItemAt(e-1):this._mapExtension.basemapExtension=void 0)),t}removeAll(){return this._mapExtension.basemapExtension=void 0,super.removeAll()}removeAtInternal(e){return super.removeAt(e)}removeAllInternal(){for(;this.length;)this.removeAtInternal(this.length-1)}reorder(e,t){return super.reorder(e,t),this.isExplicitlyModified=!0,e}reorderInternal(e,t){return super.reorder(e,t)}_itemIsInitialized(e){return super._itemIsInitialized(e)&&!!e.basemap}}class he extends w{get _collection(){return this._tables.map(e=>this._forTable(e)).concat(Array.from(this._uninitializedTableExtensions))}get _tables(){return this._mapExtension.map?.tables??new T(new s)}_mapExtension;_tableExtensionMap=new WeakMap;_uninitializedTableExtensions=new Set;_onChangeMapTablesHandle=new P(()=>Q(this._mapExtension,"map.tables",e=>{const t={added:(e.added||[]).map(e=>this._forTable(e)),moved:(e.moved||[]).map(e=>this._forTable(e)),removed:(e.removed||[]).map(e=>this._forTable(e)),target:this};this.emit("change",t)}));_onBeforeAddMapTablesHandle=new P(()=>z(this._mapExtension,"map.tables",["before-add",e=>this.emit("before-add",{...e,item:this._forTable(e.item)})]));_onBeforeRemoveMapTablesHandle=new P(()=>z(this._mapExtension,"map.tables",["before-remove",e=>this.emit("before-remove",{...e,item:this._forTable(e.item)})]));_onBeforeChangesMapTablesHandle=new P(()=>z(this._mapExtension,"map.tables",["before-changes",e=>this.emit("before-changes",{...e})]));_onAfterAddMapTablesHandle=new P(()=>z(this._mapExtension,"map.tables",["after-add",e=>this.emit("after-add",{...e,item:this._forTable(e.item)})],e=>{if(null!=e)for(const t of e)this.emit("after-add",{item:this._forTable(t)})}));_onAfterRemoveMapTablesHandle=new P(()=>z(this._mapExtension,"map.tables",["after-remove",e=>this.emit("after-remove",{...e,item:this._forTable(e.item)})],(e,t)=>{if(null!=t)for(const e of t)this.emit("after-remove",{item:this._forTable(e)})}));_onAfterChangesMapTablesHandle=new P(()=>z(this._mapExtension,"map.tables",["after-changes",e=>this.emit("after-changes",{...e,target:this})],()=>{this.emit("after-changes",{target:this})}));constructor(e){super(),this._mapExtension=e,S(this,"length",()=>O(this._mapExtension,"map.tables.length",()=>A(this,"length"),{sync:!0}))}on(e,t){const s=[];return"change"===e?s.push(this._onChangeMapTablesHandle.add()):"before-add"===e?s.push(this._onBeforeAddMapTablesHandle.add()):"before-remove"===e?s.push(this._onBeforeRemoveMapTablesHandle.add()):"before-changes"===e?s.push(this._onBeforeChangesMapTablesHandle.add()):"after-add"===e?s.push(this._onAfterAddMapTablesHandle.add()):"after-remove"===e?s.push(this._onAfterRemoveMapTablesHandle.add()):"after-changes"===e&&s.push(this._onAfterChangesMapTablesHandle.add()),s.push(super.on(e,t)),I(s)}destroy(){this._onChangeMapTablesHandle.destroy(),this._onBeforeAddMapTablesHandle.destroy(),this._onBeforeRemoveMapTablesHandle.destroy(),this._onBeforeChangesMapTablesHandle.destroy(),this._onAfterAddMapTablesHandle.destroy(),this._onAfterRemoveMapTablesHandle.destroy(),this._onAfterChangesMapTablesHandle.destroy();new Set(this).forEach(e=>this._onRemoved(e)),this._uninitializedTableExtensions.clear(),this._tableExtensionMap=new WeakMap,super.destroy()}toJSON(){const e=[];return this.forEach(t=>{e.push(`item://${encodeURIComponent(l.TABLE_EXTENSION)}/${encodeURIComponent(t.id)}`)}),e}clone(){const e=new he(this._mapExtension);return e._tableExtensionMap=this._tableExtensionMap,e}findById(e){return j("id",e).isNotMissing(),this.find(t=>t.id===e)}findByTableId(e){return j("id",e).isNotMissing(),this.find(t=>t._tableId===e)}forTable(e){if(j("table",e).isNotMissing(),this._tables.includes(e))return this._forTable(e)}add(e,t){if(j("tableX",e).isNotMissing(),e.mapExtension&&e.mapExtension.tableExtensions.remove(e),e._setMapExtension(this._mapExtension),e.table){const s=this._tableExtensionMap.get(e.table);if(this._tableExtensionMap.set(e.table,e),s&&s!==e&&this._onRemoved(s),this._tables.includes(e.table))if(void 0===t){const t={added:[e],moved:[],removed:s?[s]:[],target:this};s&&this.emit("after-remove",{item:s}),this.emit("after-add",{item:e}),this.emit("change",t)}else this._tables.reorder(e.table,t);else this._tables.add(e.table,t)}else{this._uninitializedTableExtensions.add(e);const t={added:[e],moved:[],removed:[],target:this};this.emit("after-add",{item:e}),this.emit("change",t)}return this._onAdded(e),this}removeAt(e){const t=this.getItemAt(e);if(void 0!==t){if(this._uninitializedTableExtensions.has(t)){this._uninitializedTableExtensions.delete(t);const e={added:[],moved:[],removed:[t],target:this};this.emit("after-remove",{item:t}),this.emit("change",e)}else this._tables.remove(t.table);return this._onRemoved(t),t}}reorder(e,t){if(e&&this._tables.includes(e.table))return this._tables.reorder(e.table,t),e}sort(e){return this._tables.sort((t,s)=>e(this._forTable(t),this._forTable(s))),this}_itemIsInitialized(e){return super._itemIsInitialized(e)&&!!e.table}_onAdded(e){}_onRemoved(e){e._setMapExtension(void 0)}_forTable(e){for(const e of this._uninitializedTableExtensions)e._resolveTable(),e.table&&(this._tableExtensionMap.set(e.table,e),this._uninitializedTableExtensions.delete(e));if(!this._tableExtensionMap.has(e)){const t=_.create({table:e});this._tableExtensionMap.set(e,t),t._setMapExtension(this._mapExtension),this._onAdded(t)}return this._tableExtensionMap.get(e)}}class me extends M{get _collection(){let e=this._mapExtension.layerExtensions.flatten(e=>W(e)?e.layerExtensions:[]);return this._mapExtension.basemapExtension&&(e=e.concat(this._mapExtension.basemapExtension.baseLayerExtensions.toArray()).concat(this._mapExtension.basemapExtension.referenceLayerExtensions.toArray())),e=e.concat(this._mapExtension.groundExtension.layerExtensions.toArray()),e}_mapExtension;_onChangeLayerExtensionsHandle=new P(()=>{const e=new WeakMap,t=new Set,i=a=>{const n=new s(a.added).flatten(e=>W(e)?e.layerExtensions:[]),o=new s(a.moved).flatten(e=>W(e)?e.layerExtensions:[]),r=new s(a.removed).flatten(e=>W(e)?e.layerExtensions:[]);for(const s of n)if(!e.has(s)&&W(s)){const a=s.layerExtensions.on("change",i);e.set(s,a),t.add(a)}for(const s of r){const i=e.get(s);i&&(i.remove(),e.delete(s),t.delete(i))}this.emit("change",{added:n.toArray(),moved:o.toArray(),removed:r.toArray()})};t.add(this._mapExtension.layerExtensions.on("change",i));const a=this._mapExtension.layerExtensions.flatten(e=>W(e)?e.layerExtensions:[]);for(const s of a)if(W(s)){const a=s.layerExtensions.on("change",i);e.set(s,a),t.add(a)}return t.add(Q(this._mapExtension,"basemapExtension.baseLayerExtensions",e=>{this.emit("change",{...e})})),t.add(Q(this._mapExtension,"basemapExtension.referenceLayerExtensions",e=>{this.emit("change",{...e})})),t.add(this._mapExtension.groundExtension.layerExtensions.on("change",e=>{this.emit("change",{...e})})),I(t)});_onAfterAddLayerExtensionsHandle=new P(()=>{const e=new WeakMap,t=new Set,s=s=>{const i=e.get(s);i&&(i.remove(),e.delete(s),t.delete(i))},i=e=>{const t=e.item;if(W(t)){const e=t.layerExtensions.flatten(e=>W(e)?e.layerExtensions:[]);for(const t of e)s(t)}s(t)},a=s=>{this.emit("after-add",{...s});const n=s.item;if(W(n)){const o=n.layerExtensions.flatten(e=>W(e)?e.layerExtensions:[]);for(const n of o)if(this.emit("after-add",{...s,item:n}),!e.has(n)&&W(n)){const s=n.layerExtensions.on("after-add",a),o=n.layerExtensions.on("after-remove",i),r=I([s,o]);e.set(n,r),t.add(r)}}};t.add(this._mapExtension.layerExtensions.on("after-add",a)),t.add(this._mapExtension.layerExtensions.on("after-remove",i));const n=this._mapExtension.layerExtensions.flatten(e=>W(e)?e.layerExtensions:[]);for(const s of n)if(W(s)){const n=s.layerExtensions.on("after-add",a),o=s.layerExtensions.on("after-remove",i),r=I([n,o]);e.set(s,r),t.add(r)}return t.add(z(this._mapExtension,"basemapExtension.baseLayerExtensions",["after-add",e=>this.emit("after-add",{...e})])),t.add(z(this._mapExtension,"basemapExtension.referenceLayerExtensions",["after-add",e=>this.emit("after-add",{...e})])),t.add(this._mapExtension.groundExtension.layerExtensions.on("after-add",e=>{this.emit("after-add",{...e})})),I(t)});_onAfterRemoveLayerExtensionsHandle=new P(()=>{const e=new WeakMap,t=new Set,s=s=>{const i=e.get(s);i&&(i.remove(),e.delete(s),t.delete(i))},i=e=>{this.emit("after-remove",{...e});const t=e.item;if(W(t)){const i=t.layerExtensions.flatten(e=>W(e)?e.layerExtensions:[]);for(const t of i)this.emit("after-remove",{...e,item:t}),s(t)}s(t)},a=s=>{const n=s.item;if(W(n)){const s=n.layerExtensions.on("after-add",a),o=n.layerExtensions.on("after-remove",i),r=I([s,o]);e.set(n,r),t.add(r)}};t.add(this._mapExtension.layerExtensions.on("after-remove",i)),t.add(this._mapExtension.layerExtensions.on("after-add",a));const n=this._mapExtension.layerExtensions.flatten(e=>W(e)?e.layerExtensions:[]);for(const s of n)if(W(s)){const n=s.layerExtensions.on("after-add",a),o=s.layerExtensions.on("after-remove",i),r=I([n,o]);e.set(s,r),t.add(r)}return t.add(z(this._mapExtension,"basemapExtension.baseLayerExtensions",["after-remove",e=>this.emit("after-remove",{...e})])),t.add(z(this._mapExtension,"basemapExtension.referenceLayerExtensions",["after-remove",e=>this.emit("after-remove",{...e})])),t.add(this._mapExtension.groundExtension.layerExtensions.on("after-remove",e=>{this.emit("after-remove",{...e})})),I(t)});constructor(e){super(),this._mapExtension=e}on(e,t){const s=[];return"change"===e?s.push(this._onChangeLayerExtensionsHandle.add()):"after-add"===e?s.push(this._onAfterAddLayerExtensionsHandle.add()):"after-remove"===e&&s.push(this._onAfterRemoveLayerExtensionsHandle.add()),s.push(super.on(e,t)),I(s)}destroy(){this._onChangeLayerExtensionsHandle.destroy(),this._onAfterAddLayerExtensionsHandle.destroy(),this._onAfterRemoveLayerExtensionsHandle.destroy(),super.destroy()}findById(e){return j("id",e).isNotMissing(),this.find(t=>t.id===e)}findByLayerId(e){return j("id",e).isNotMissing(),this.find(t=>t._layerId===e)}forLayer(e){return j("layer",e).isNotMissing(),this.findByLayerId(e.id)}_itemIsInitialized(e){return super._itemIsInitialized(e)&&!!e.layer}}function de(e){if(!(null==e||"object"==typeof e&&e?.baseMap))return X(e)}function le(e){return"object"!=typeof e||e&&!e.baseMap}function _e(e,t,s){if(e?.type&&e.type!==s)throw new Error(`Invalid portal item type "${e.type}" for property ${t}.`)}async function be(e){await N(e),e.basemap&&(await N(e.basemap),e.basemap.baseLayers.filter(e=>F(e)).map(e=>{const t=e;return t.activeLayer.imageFormat=t.activeLayer.imageFormat??(t.activeLayer.imageFormats?.length>0?t.activeLayer.imageFormats[0]:""),t.activeLayer.styleId=t.activeLayer.styleId??"",t}),e.basemap.id=k(e.basemap)??e.basemap.id)}
1
+ var e;import{__decorate as t}from"tslib";import s,{}from"@arcgis/core/core/Collection";import{ArgumentError as i}from"../ArgumentError.js";import{EntityBase as a}from"../Entity.js";import{InvalidOperationError as n}from"../InvalidOperationError.js";import{isBasemapExtension as o,isBookmark as r,isGroundExtension as p,isLayerPreset as h,isMenu as m,isTableExtension as d,ItemType as l}from"../ItemType.js";import{TableExtension as _}from"../data/TableExtension.js";import{layerToParentJsonCache as b}from"../json/LayerJson.js";import{applyJsonToWebMap as c}from"../json/WebMapJson.js";import{applyJsonToWebScene as f}from"../json/WebSceneJson.js";import{LayerPreset as E}from"../layer-preset/LayerPreset.js";import{Menu as x}from"../menus/Menu.js";import{DefaultArcGISRequestHelper as u}from"../support/ArcGISRequestHelper.js";import{FormatSettings as y}from"../support/FormatSettings.js";import{InitializableCollectionProxy as w}from"../support/InitializableCollectionProxy.js";import{ReadOnlyInitializableCollection as M}from"../support/ReadOnlyInitializableCollection.js";import{serializable as g}from"../support/Serializable.js";import{WellKnownBasemap as v}from"../support/esri.js";import{createIHandle as I,notifyChange as A,onWatch as S,watch as O,watchEvent as z}from"../support/observableUtils.js";import{ReadOnlyCollection as T}from"../utilities/ReadOnlyCollection.js";import P from"../utilities/_ReferenceCountedHandle.js";import{groundsAreEquivalent as L}from"../utilities/_layers.js";import{basemapsAreEquivalent as V,createStandardBasemap as B,getStandardBasemapId as k,isStandardBasemap as C,isStandardBasemap2D as H}from"../utilities/basemaps.js";import{checkArg as j}from"../utilities/checkArg.js";import{compare as R}from"../utilities/collection.js";import{load as N}from"../utilities/esri.js";import{isGroupLayerExtension as W}from"../utilities/extensions.js";import{filter as J}from"../utilities/iterable.js";import{isWMTSLayer as F,layersAreEquivalent as G}from"../utilities/layers.js";import{getLogger as q}from"../utilities/log.js";import{getMapSpatialReference as K,isMap as D,isWebMap as U,isWebScene as $}from"../utilities/mapping.js";import{toPortalItem as X}from"../utilities/portal.js";import{parallelEach as Y}from"../utilities/promise.js";import{onCollectionPropertyChange as Q,onEach as Z}from"../utilities/watch.js";import{BasemapExtension as ee}from"./BasemapExtension.js";import{Bookmark as te}from"./Bookmark.js";import{GroundExtension as se}from"./GroundExtension.js";import{MapConstraints as ie}from"./MapConstraints.js";import{_assignLayerExtensions as ae}from"./_LayerExtension.js";import{LayerExtensionCollectionImpl as ne}from"./_LayerExtensionCollectionImpl.js";const oe=q("MapExtension");let re=class extends a{static{e=this}static _mapEventHandlesKey="map-extension-map-event-handles";static _sceneEventHandlesKey="map-extension-scene-event-handles";get webMap(){return this._webMap}get webScene(){return this._webScene}get map(){return this._currentMap}get viewMode(){return this.map?$(this.map)?"scene":"map":this.initialViewMode}get initialViewMode(){return this.webMap&&this.webScene?this._initialViewMode||"map":$(this.map)||this.webScene&&!this.webMap?"scene":"map"}set initialViewMode(e){this._initialViewMode=e}get requestHelper(){return this._requestHelper||(this._requestHelper=new u),this._requestHelper}set requestHelper(e){this._requestHelper=e}get basemapExtension(){return this._basemapExtension}set basemapExtension(e){const t=this._basemapExtension;if(t!==e)if(t&&t._setMapExtension(void 0),e){if(e._setMapExtension(this),this.isInitialized&&!e.basemap){if(e.isInitialized)throw e._setMapExtension(void 0),new n("Cannot set MapExtension.basemapExtension without a valid Esri Basemap object");e.initialize()}this._ensureIsBasemapOption(e),this.map&&e.basemap&&e.basemap!==this.map.basemap?this.map.basemap=e.basemap:this._basemapExtension=e}else this.map.basemap=void 0,this._basemapExtension=void 0}get groundExtension(){return this._groundExtension||(this.groundExtension=se.create({ground:this.map?.ground})),this._groundExtension}set groundExtension(e){if(!e)throw new n("Cannot set map.ground to undefined");const t=this._groundExtension;t!==e&&(t&&t._setMapExtension(void 0),e._setMapExtension(this),e._resolveGround(),e.ground?(this._groundExtensions.set(e.ground,e),this.map&&e.ground!==this.map.ground?this.map.ground=e.ground:this._groundExtension=e):this._groundExtension=e)}get basemapOptions(){return this._basemapOptions}get bookmarks(){return this._bookmarks}get initialBasemapExtension(){return this._initialBasemapExtension}get initialLayerPreset(){return this._initialLayerPreset}set initialLayerPreset(e){if(!e)return void(this._initialLayerPreset=void 0);const t=h(e)?e:new E(e);this._initialLayerPreset=t}get _spatialReference(){return K(this.map)}get webMapItemTitle(){if(this._webMapItem)return this._webMapItem.title}get webSceneItemTitle(){if(this._webSceneItem)return this._webSceneItem.title}get title(){return this._title?this._title:this._webMapItem&&"map"===this.viewMode?this.webMapItemTitle:this._webSceneItem&&"scene"===this.viewMode?this.webSceneItemTitle:void 0}set title(e){this._title=e}formatSettings;constraints;onClick;onHover;onHoverEnd;onInitialized;onViewpointChanged;get contextMenu(){return this._contextMenu}set contextMenu(e){this._contextMenu=e,e&&this.isInitialized&&!e.isInitialized&&(async()=>{try{await e.initialize()}catch(e){e instanceof Error&&oe.error({message:"An error occurred while initializing context menu.",error:e})}})()}_layerViews=new s;get _allLayerViews(){const e=t=>{const i=[t];return s.isCollection(t.sublayerViews)?i.push(...t.sublayerViews.toArray().flatMap(e)):s.isCollection(t.layerViews)&&i.push(...t.layerViews.toArray().flatMap(e)),i};return this._layerViews.toArray().flatMap(e)}get layerExtensions(){return this._layerExtensions}get isSwitchingMap(){return this._isSwitchingMap}tableExtensions;allLayerExtensions;_itemType=l.MAP_EXTENSION;_isSwitchingMap=!1;_map;_scene;_deserializedMapPromise;_deserializedViewMode;_deserializedViewModePromise;_deferredProperties;_currentMap;_requestHelper;_basemapExtension;_groundExtension;_basemapOptions;_groundExtensions;_bookmarks;_layerExtensions;_webMap;_webMapItem;_webScene;_webSceneItem;_title;_initialViewMode;_initialLayerPreset;_initialBasemapExtension;_skipBasemapOptions=!1;_createScenePromise;_createMapPromise;_contextMenu;constructor(t){super(t);let a={...t};this._basemapOptions=new pe(this),this._groundExtensions=new WeakMap,this._layerExtensions=this._createLayerExtensionCollection(),this.tableExtensions=this._createTableExtensionCollection(),this.formatSettings=this._createFormatSettings(),this._bookmarks=new s,this.constraints=new ie,this._handles.add([O(this,"_map",t=>{t?this._handles.add([Z(t.layers,"layerview-create",e=>{this._layerViews.add(e.layerView)}),Z(t.layers,"layerview-destroy",e=>{this._layerViews.remove(e.layerView)})],e._mapEventHandlesKey):this._handles.remove(e._mapEventHandlesKey)},{sync:!0}),O(this,"_scene",t=>{t?this._handles.add([Z(t.layers,"layerview-create",e=>{this._layerViews.add(e.layerView)}),Z(t.layers,"layerview-destroy",e=>{this._layerViews.remove(e.layerView)})],e._sceneEventHandlesKey):this._handles.remove(e._sceneEventHandlesKey)},{sync:!0})]);const{webMap:n,webScene:o,initialViewMode:r,map:p,basemapOptions:h}=a;if(this._webMap=n,this._webScene=o,this._webMapItem=de(n),this._webSceneItem=de(o),this.initialViewMode=r,$(p)&&o)throw new i("Cannot specify webScene property if map is initialized to a WebScene instance.");if(D(p)&&n)throw new i("Cannot specify webMap property if map is initialized to a 2D Map instance.");if($(p)||U(p)||D(p))this.assignProperties({basemapOptions:h}),this._skipBasemapOptions=!!h;else{const{layerExtensions:e,tableExtensions:t,groundExtension:s,basemapOptions:i,basemapExtension:n,...o}=a;this._deferredProperties={layerExtensions:e,tableExtensions:t,groundExtension:s,basemapOptions:i,basemapExtension:n},a=o,i&&(this._skipBasemapOptions=!0)}this._initMapFromProperties(a),this._handles.add([O(this,"map.basemap",()=>this._onBasemapChange(),{sync:!0}),O(this,"map.ground",()=>this._onGroundChange(),{sync:!0})]),this.allLayerExtensions=new me(this),this.map?.basemap&&this._onBasemapChange()}getLayerExtensionsForView(e=this.viewMode){return(("map"===e?this._map:this._scene)?.layers.toArray()??[]).map(e=>this._layerExtensions._forLayer(e)).filter(e=>!e.dynamicallyAddedLayer)}getAllFeatureSources(e=()=>!0){const t=[],s=a=>{a.hasFeatures&&t.push(a);for(const t of a.sublayerExtensions.initializedItems.filter(e).toArray())i(t);if(W(a))for(const t of a.layerExtensions.initializedItems.filter(e).toArray())s(t)},i=s=>{t.push(s);for(const t of s.sublayerExtensions.initializedItems.filter(e).toArray())i(t)};for(const t of this.layerExtensions.initializedItems.filter(e).toArray())s(t);for(const s of this.tableExtensions.initializedItems.filter(e).toArray())t.push(s);if(this.basemapExtension){for(const t of this.basemapExtension.baseLayerExtensions.initializedItems.filter(e).toArray())s(t);for(const t of this.basemapExtension.referenceLayerExtensions.initializedItems.filter(e).toArray())s(t)}return t}isSupportedViewMode(e){return e===this.viewMode||!(!this.webMap&&!this.webScene)&&("scene"===e?!!this.webScene:!!this.webMap)}async switchViewMode(e){if(j("viewMode",e).isNotMissing().satisfies(e=>this.isSupportedViewMode(e),"Unsupported view mode."),this.viewMode===e)return;let t;"scene"===e?(await this._createScene(),t=this._scene):(await this._createMap(),t=this._map),await this.switchMap(t),A(this,"viewMode"),A(this,"title")}async switchMap(t){if(j("newMap",t).isNotMissing(),t===this.map)return;if(!this.map)return void this._setMap(t);this._layerViews.removeAll(),"map"===this.viewMode?this._handles.remove(e._mapEventHandlesKey):this._handles.remove(e._sceneEventHandlesKey),this._isSwitchingMap=!0,this.isInitialized&&await be(t),this._preserveBasemapAndGround(t);const s=new Map(this.map.layers.map(e=>[e,this.layerExtensions.forLayer(e)])),i=new Map(this.map.tables.map(e=>[e,this.tableExtensions.forTable(e)])),{basemapExtension:a}=this;this._setMap(t),this._updateBookmarks();const n=[];for(const e of this.map.layers.toArray()){const t=[...J(s.entries(),([t])=>G(t,e))];if(1===t.length){const[s]=t;n.push((async()=>{const t=s[1];await t._switchLayer(e),this._layerExtensions._register(t)})())}else{const t=this._layerExtensions._forLayer(e);t&&t.layer!==e&&n.push(t._switchLayer(e))}}for(const e of this.map.tables.toArray()){const t=[...J(i.entries(),([t])=>G(t,e))];if(1===t.length){const[s]=t;n.push((async()=>{const t=s[1];await t._switchTable(e),this.tableExtensions.add(t)})())}else{const t=this.tableExtensions.forTable(e);t&&t.table!==e&&n.push(t._switchTable(e))}}this.map.basemap&&a&&V(this.map.basemap,a.basemap)&&n.push((async()=>{await a._switchBasemap(this.map.basemap),this.basemapExtension=a})()),await Promise.all(n),this.isInitialized&&(a&&a!==this.basemapExtension&&(this.basemapOptions.includes(a)||await a.destroy()),await this._initializeChildren()),this._isSwitchingMap=!1}async setWebMap(e){if(!e&&this.webMap&&!this.webScene)throw new n("Cannot unset both webMap and webScene.");const t=this._map?.basemap;this._webMap=e,this._map=void 0,this._createMapPromise=void 0,this._webMapItem=de(e),await N(this._webMapItem),"map"===this.viewMode&&(e?(this._basemapOptions.isExplicitlyModified||this._basemapOptions.removeAllInternal(),await this._createMap(),await this.switchMap(this._map),await this._createStandardBasemapOptions(),this._basemapOptions.reorderInternal(this.basemapExtension,0),this._initialBasemapExtension=this.basemapExtension):await this.switchViewMode("scene")),this._cleanPreviousBasemapOptions(t),A(this,"webMap"),A(this,"initialViewMode"),A(this,"title")}async setWebScene(e){if(!e&&this.webScene&&!this.webMap)throw new n("Cannot unset both webMap and webScene.");const t=this._scene?.basemap;this._webScene=e,this._scene=void 0,this._createScenePromise=void 0,this._webSceneItem=de(e),await N(this._webSceneItem),"scene"===this.viewMode&&(e?(this._basemapOptions.isExplicitlyModified||this._basemapOptions.removeAllInternal(),await this._createScene(),await this.switchMap(this._scene),await this._createStandardBasemapOptions(),this._basemapOptions.reorderInternal(this.basemapExtension,0),this._initialBasemapExtension=this.basemapExtension):await this.switchViewMode("map")),this._cleanPreviousBasemapOptions(t),A(this,"webScene"),A(this,"initialViewMode"),A(this,"title")}getDefaults(){const e=super.getDefaults();return e.initialViewMode="map",e}async _onDestroy(){await Promise.all([...Array.from(this._layerExtensions,e=>e.destroy()),...Array.from(this.tableExtensions,e=>e.destroy()),...Array.from(this._basemapOptions,e=>e.destroy()),...this._groundExtension?[this._groundExtension.destroy()]:[]]),this._layerExtensions.destroy(),this.tableExtensions.destroy(),this.allLayerExtensions.destroy(),this._basemapOptions.destroy(),this._bookmarks.destroy(),this._layerViews.destroy(),await super._onDestroy()}async _createScene(){if(!this._scene&&this.webScene)return this._createScenePromise=this._createScenePromise??(async()=>{const e=(await import("@arcgis/core/WebScene")).default;le(this.webScene)?(this._webSceneItem.type="Web Scene",this._scene=new e({portalItem:this._webSceneItem})):this._scene=e.fromJSON(this.webScene)})()}async _createMap(){if(!this._map&&this.webMap)return this._createMapPromise=this._createMapPromise??(async()=>{const e=(await import("@arcgis/core/WebMap")).default;le(this.webMap)?(this._webMapItem.type="Web Map",this._map=new e({portalItem:this._webMapItem})):this._map=e.fromJSON(this.webMap)})()}_getSerializableProperties(){return{...super._getSerializableProperties(),layerExtensions:{serializeModes:["initial","project"],deserialize:e=>{if(this.map&&e){const t="map"===this.viewMode,s=(t?this._scene:this._map)?.layers.toArray()??[],i=e.filter(e=>!s.includes(e.layer)&&!s.some(t=>e.layer&&G(t,e.layer)));ae(this.layerExtensions,i)}},serialize:e=>{if(this._deferredProperties?.layerExtensions)return this._deferredProperties.layerExtensions;{const t="map"===this.viewMode,s=(t?this._map:this._scene)?.layers.toArray();let i=(t?this._scene:this._map)?.layers.toArray()??[];return i=i.filter(e=>!s.find(t=>G(t,e))),this.layerExtensions.concat(i.map(e=>this._layerExtensions._forLayer(e))).filter(t=>"initial"!==e||!t.dynamicallyAddedLayer).toArray()}}},tableExtensions:{serializeModes:["initial","project"],deserialize:e=>{this.map?R(this.tableExtensions,e,{onNew:(e,t)=>{this.tableExtensions.add(d(e)?e:_.create(e),t)},onMatch:(e,t,s,i)=>{d(t)||e.assignProperties(t),s!==i&&this.tableExtensions.reorder(e,i)},equals:(e,t)=>d(t)?t===e:!!_._matchesRef(e,t.table)||e.id===t.id}):this._deferredProperties={...this._deferredProperties,tableExtensions:e}},serialize:()=>this._deferredProperties?.tableExtensions?this._deferredProperties?.tableExtensions:this.tableExtensions.toArray()},basemapExtension:{serializeModes:["project"],deserialize:e=>{if(this.map)if(e)if(o(e))this.basemapExtension=e;else{if(this.basemapExtension)return this.basemapExtension.assignPropertiesAsync(e);this.basemapExtension=ee.create(e)}else this.basemapExtension=void 0;else this._deferredProperties={...this._deferredProperties,basemapExtension:e}},serialize:()=>this._deferredProperties?.basemapExtension?this._deferredProperties?.basemapExtension:this.basemapExtension},basemapOptions:{serializeModes:["initial"],deserialize:e=>{this._skipBasemapOptions?this._skipBasemapOptions=!1:(this.basemapOptions.length&&(this._basemapOptions.isExplicitlyModified=!0),R(this.basemapOptions,e,{onNew:(e,t)=>{this.basemapOptions.add(o(e)?e:ee.create(e),t)},onMatch:(e,t,s,i)=>{o(t)||e.assignProperties(t),s!==i&&this.basemapOptions.reorder(e,i)},onMissing:e=>{this.basemapOptions.remove(e)},equals:(e,t)=>{if(o(t))return t===e;if(e.id&&t.id)return e.id===t.id;{const s=e.toJSON();return V(s.basemap,t.basemap||t.baseMap)}}}),this.basemapExtension&&this._ensureIsBasemapOption(this.basemapExtension),this.isInitialized&&Y(this.basemapOptions.toArray(),e=>e._createBackingBasemap()))},serialize:()=>this._deferredProperties?.basemapOptions?this._deferredProperties?.basemapOptions:this.basemapOptions.toArray()},groundExtension:{serializeModes:["initial"],deserialize:e=>{if(this.map){if(!p(e))return this.groundExtension.assignPropertiesAsync(e);this.groundExtension=e}else this._deferredProperties={...this._deferredProperties,groundExtension:e}},serialize:()=>this._deferredProperties?.groundExtension?this._deferredProperties?.groundExtension:this.groundExtension},bookmarks:{serialize:()=>this.bookmarks.map(e=>e.toJSON()).toArray(),deserialize:e=>{this.bookmarks.addMany(e.map(e=>r(e)?e:new te(e)))}},webMap:{serializeModes:["initial"],deserialize:!1},webScene:{serializeModes:["initial"],deserialize:!1},initialLayerPreset:"initial",initialViewMode:{serializeModes:["initial","project"],serialize:e=>"project"===e?this.viewMode:"scene"!==this.initialViewMode||!this.webScene&&this.webMap?"map":"scene",deserialize:e=>{this.viewMode!==e&&(this._deserializedViewMode=e),this._initialViewMode=e},isDefault:(e,t)=>"project"!==t&&"map"===e},formatSettings:"initial",constraints:"initial",title:"initial",onClick:"initial",onHover:"initial",onHoverEnd:"initial",onInitialized:"initial",onViewpointChanged:"initial",contextMenu:{serializeModes:["initial"],deserialize:e=>{e?m(e)?this.contextMenu=e:this.contextMenu?this.contextMenu.assignProperties(e):this.contextMenu=x.create(e):this.contextMenu=void 0}},map:{serializeModes:["project"],serialize:()=>{b.lookup=new WeakMap;const e=this.layerExtensions.toArray().filter(e=>e.layer).map(e=>e._getProjectWebmapJSON()),t=this.tableExtensions.toArray().filter(e=>e.table).map(e=>({id:e.table.id,title:e.table.title}));return b.lookup=void 0,e.length>0||t.length>0?{operationalLayers:e,tables:t}:{}},deserialize:e=>{if(!this.map)throw new i("Cannot specify JSON object for the 'map' property. It must be an ArcGIS API Map instance. To specify JSON, use 'webMap' or 'webScene' instead.");if(D(e)||U(e)||$(e)){if(e!==this.map)throw new i("properties.map","Property 'map' is read-only.")}else this._deserializedMapPromise=(async()=>{this._deserializedViewMode&&this.webMap&&this.webScene&&(this._deserializedViewModePromise=this.switchViewMode(this._deserializedViewMode),await this._deserializedViewModePromise,this._deserializedViewMode=void 0,this._deserializedViewModePromise=void 0),await this._applyMapProperties(e,this.map),this._deserializedMapPromise=void 0})()}},requestHelper:{serialize:!1}}}async _applyMapProperties(e,t,s){await Y(this.basemapOptions.toArray(),e=>e._createBackingBasemap());let i=e;const a=this.basemapOptions.find(e=>V(e.basemap,i.baseMap));a&&(t.basemap=a.basemap,i={...i,baseMap:{...i.baseMap,title:t.basemap.title}}),$(t)?await f(i,t,s):await c(i,t,s)}_createFormatSettings(){return new y}_createLayerExtensionCollection(){return new ne(this)}_createTableExtensionCollection(){return new he(this)}async _onInitialize(){await super._onInitialize();const{basemapOptions:e,basemapExtension:t,webMap:s,webScene:i,...a}=this._deferredProperties??{};if(this.map||("scene"===this.initialViewMode?(await this._createScene(),this._setMap(this._scene)):(await this._createMap(),this._setMap(this._map))),this._webMapItem||this._webSceneItem?(await Promise.all([be(this.map),N(this._webMapItem),N(this._webSceneItem)]),_e(this._webMapItem,"webMap","Web Map"),_e(this._webSceneItem,"webScene","Web Scene")):await be(this.map),t&&(!o(t)&&t.basemap?this.basemapExtension=ee.create(t):await this.assignPropertiesAsync({basemapExtension:t}),await this.basemapExtension._createBackingBasemap()),e){const t=e.find(e=>o(e)&&V(this.map.basemap,e.toJSON().basemap));if(t){const e=t.toJSON().basemap?.id??t.basemap?.id,s=t.toJSON().basemap?.title;await t._switchBasemap(this.map.basemap),this.basemapExtension=t,e&&(this.map.basemap.id=e),s&&(this.map.basemap.title=s)}await this.assignPropertiesAsync({basemapOptions:e})}await this.assignPropertiesAsync(a),this._deferredProperties=void 0,this._initialBasemapExtension=this.basemapExtension,this._updateBookmarks();for(const e of this.layerExtensions.toArray())await e._createBackingLayer();await Promise.all(this.tableExtensions.map(e=>e._createBackingTable()).toArray())}async _postInitialize(){await super._postInitialize(),await this._createStandardBasemapOptions(),await Y(this.basemapOptions.toArray(),e=>e._createBackingBasemap()),this.initialLayerPreset&&await this.initialLayerPreset.applyTo(this)}*_initializableChildCollections(){yield*super._initializableChildCollections();const e=new s(this.layerExtensions.filter(e=>!!e.layer));e.remove=e=>this.layerExtensions.remove(e);const t=new s(this.tableExtensions.filter(e=>!!e.table));if(t.remove=e=>this.tableExtensions.remove(e),yield e,yield t,this.basemapExtension){const e=new s;e.add(this.basemapExtension),yield e}const i=new s;i.add(this.groundExtension),yield i}_preserveBasemapAndGround(e){(!e.basemap||H(e.basemap))&&this.map?.basemap&&H(this.map.basemap)&&(e.basemap=this.map.basemap),this.map?.ground&&e.ground&&L(this.map.ground,e.ground)&&(e.ground=this.map.ground)}_initMapFromProperties(e){const t=e.map;D(t)||U(t)||$(t)?this._setMap(t):"scene"===this.initialViewMode?e.webScene&&!le(e.webScene)&&(this._deferredProperties={webScene:e.webScene,...this._deferredProperties}):e.webMap&&!le(e.webMap)&&(this._deferredProperties={webMap:e.webMap,...this._deferredProperties})}_setMap(e){$(e)?this._scene=e:this._map=e,this._currentMap=e,this.basemapExtension?.basemap&&!e.basemap&&(e.basemap=this.basemapExtension.basemap),this.groundExtension?.ground&&!e.ground&&(e.ground=this.groundExtension.ground),A(this,"map")}_onBasemapChange(){if(this._basemapExtension){if(this.basemapExtension.basemap==this.map.basemap)return;this._basemapExtension._setMapExtension(void 0)}if(this.map.basemap){let e=this.basemapOptions.find(e=>this.map.basemap===e.basemap);if(!e){const t=this.basemapOptions.find(e=>V(e.basemap,this.map.basemap));t?(e=t,e._switchBasemap(this.map.basemap)):(e=ee.create({basemap:this.map.basemap}),this._basemapOptions.addInternal(e,0))}e.mapExtension!==this&&e._setMapExtension(this),this._basemapExtension=e}else this._basemapExtension=void 0;A(this,"basemapExtension")}_onGroundChange(){if(this._groundExtension){if(this.map.ground&&this.groundExtension.ground===this.map.ground)return void(this._groundExtensions.has(this.map.ground)||this._groundExtensions.set(this.map.ground,this.groundExtension));{const e=this.groundExtension,t=e.ground;e._setMapExtension(void 0),this.isSwitchingMap&&t&&t!==this._map?.ground&&t!==this._scene?.ground&&t!==this.map?.ground&&(this._groundExtensions.delete(t),e.destroy())}}this.map.ground&&!this._groundExtensions.has(this.map.ground)&&this._groundExtensions.set(this.map.ground,se.create({ground:this.map.ground}));const e=this._groundExtensions.get(this.map.ground);e&&e.mapExtension!==this&&e._setMapExtension(this),this._groundExtension=e,A(this,"groundExtension")}async _createStandardBasemapOptions(){const e=this._spatialReference;!this._basemapOptions.isExplicitlyModified&&e?.isWebMercator&&await Y([v.SATELLITE,v.HYBRID_VECTOR,v.STREETS_VECTOR,v.TOPO_VECTOR,v.STREETS_NAVIGATION_VECTOR,v.STREETS_NIGHT_VECTOR,v.TERRAIN_VECTOR,v.DARK_GRAY_VECTOR,v.GRAY_VECTOR,v.OCEANS_VECTOR,v.OPEN_STREET_MAP_VECTOR],async e=>{const t=await B(e);V(this.map.basemap,t)?this._basemapOptions.addInternal(this.basemapExtension):this._basemapOptions.addInternal(ee.create({basemap:t}),void 0,!1)})}_ensureIsBasemapOption(e){const t=this.basemapOptions.findIndex(t=>t.basemap===e.basemap);t>=0?this._basemapOptions.getItemAt(t)!==e&&(this._basemapOptions.removeAtInternal(t),this._basemapOptions.addInternal(e,t)):this._basemapOptions.addInternal(e,0)}_cleanPreviousBasemapOptions(e){if(e&&!C(e))for(let t=this._basemapOptions.length-1;t>=0;t--){const s=this._basemapOptions.getItemAt(t),i=V(s.basemap,e),a=V(s.basemap,this._map?.basemap)||V(s.basemap,this._scene?.basemap);i&&!a&&this._basemapOptions.removeAtInternal(t)}}_updateBookmarks(){this.bookmarks.removeMany(this.bookmarks.filter(e=>"map"===e.source)),U(this.map)&&this.map.bookmarks?.length>0?this.map.bookmarks.forEach(e=>{this.bookmarks.add(new te({source:"map",title:e.name,viewpoint:e.viewpoint}))}):$(this.map)&&this.map.presentation?.slides?.length>0&&this.map.presentation.slides.forEach(e=>{const t={source:"map",title:e.title.text,viewpoint:e.viewpoint},s=new te(t);this.bookmarks.add(s)})}};re=e=t([g],re);export{re as MapExtension};class pe extends w{isExplicitlyModified=!1;_mapExtension;constructor(e){super(new s),this._mapExtension=e}add(e,t){return super.add(e,t),this.isExplicitlyModified=!0,1===this.length&&this._mapExtension.map&&!this._mapExtension.basemapExtension&&(this._mapExtension.basemapExtension=e),this}addMany(e,t){return super.addMany(e,t),this.isExplicitlyModified=!0,this}addInternal(e,t,s=!0){const i=e=>{const t="-vector";return e?.endsWith(t)?e.substring(0,e.length-7):e};let a;if(e.basemap){const t=i(e.basemap.id);if(a=C(e.basemap)?this.findIndex(e=>i(e.basemap?.id)===t):this.findIndex(t=>V(t.basemap,e.basemap)),a>=0){if(!s)return;super.removeAt(a)}}super.add(e,t??(a>=0?a:void 0))}removeAt(e){const t=super.removeAt(e);return t&&(this.isExplicitlyModified=!0,t===this._mapExtension.basemapExtension&&(e<this.length?this._mapExtension.basemapExtension=this.getItemAt(e):this.length?this._mapExtension.basemapExtension=this.getItemAt(e-1):this._mapExtension.basemapExtension=void 0)),t}removeAll(){return this._mapExtension.basemapExtension=void 0,super.removeAll()}removeAtInternal(e){return super.removeAt(e)}removeAllInternal(){for(;this.length;)this.removeAtInternal(this.length-1)}reorder(e,t){return super.reorder(e,t),this.isExplicitlyModified=!0,e}reorderInternal(e,t){return super.reorder(e,t)}_itemIsInitialized(e){return super._itemIsInitialized(e)&&!!e.basemap}}class he extends w{get _collection(){return this._tables.map(e=>this._forTable(e)).concat(Array.from(this._uninitializedTableExtensions))}get _tables(){return this._mapExtension.map?.tables??new T(new s)}_mapExtension;_tableExtensionMap=new WeakMap;_uninitializedTableExtensions=new Set;_onChangeMapTablesHandle=new P(()=>Q(this._mapExtension,"map.tables",e=>{const t={added:(e.added||[]).map(e=>this._forTable(e)),moved:(e.moved||[]).map(e=>this._forTable(e)),removed:(e.removed||[]).map(e=>this._forTable(e)),target:this};this.emit("change",t)}));_onBeforeAddMapTablesHandle=new P(()=>z(this._mapExtension,"map.tables",["before-add",e=>this.emit("before-add",{...e,item:this._forTable(e.item)})]));_onBeforeRemoveMapTablesHandle=new P(()=>z(this._mapExtension,"map.tables",["before-remove",e=>this.emit("before-remove",{...e,item:this._forTable(e.item)})]));_onBeforeChangesMapTablesHandle=new P(()=>z(this._mapExtension,"map.tables",["before-changes",e=>this.emit("before-changes",{...e})]));_onAfterAddMapTablesHandle=new P(()=>z(this._mapExtension,"map.tables",["after-add",e=>this.emit("after-add",{...e,item:this._forTable(e.item)})],e=>{if(null!=e)for(const t of e)this.emit("after-add",{item:this._forTable(t)})}));_onAfterRemoveMapTablesHandle=new P(()=>z(this._mapExtension,"map.tables",["after-remove",e=>this.emit("after-remove",{...e,item:this._forTable(e.item)})],(e,t)=>{if(null!=t)for(const e of t)this.emit("after-remove",{item:this._forTable(e)})}));_onAfterChangesMapTablesHandle=new P(()=>z(this._mapExtension,"map.tables",["after-changes",e=>this.emit("after-changes",{...e,target:this})],()=>{this.emit("after-changes",{target:this})}));constructor(e){super(),this._mapExtension=e,S(this,"length",()=>O(this._mapExtension,"map.tables.length",()=>A(this,"length"),{sync:!0}))}on(e,t){const s=[];return"change"===e?s.push(this._onChangeMapTablesHandle.add()):"before-add"===e?s.push(this._onBeforeAddMapTablesHandle.add()):"before-remove"===e?s.push(this._onBeforeRemoveMapTablesHandle.add()):"before-changes"===e?s.push(this._onBeforeChangesMapTablesHandle.add()):"after-add"===e?s.push(this._onAfterAddMapTablesHandle.add()):"after-remove"===e?s.push(this._onAfterRemoveMapTablesHandle.add()):"after-changes"===e&&s.push(this._onAfterChangesMapTablesHandle.add()),s.push(super.on(e,t)),I(s)}destroy(){this._onChangeMapTablesHandle.destroy(),this._onBeforeAddMapTablesHandle.destroy(),this._onBeforeRemoveMapTablesHandle.destroy(),this._onBeforeChangesMapTablesHandle.destroy(),this._onAfterAddMapTablesHandle.destroy(),this._onAfterRemoveMapTablesHandle.destroy(),this._onAfterChangesMapTablesHandle.destroy();new Set(this).forEach(e=>this._onRemoved(e)),this._uninitializedTableExtensions.clear(),this._tableExtensionMap=new WeakMap,super.destroy()}toJSON(){const e=[];return this.forEach(t=>{e.push(`item://${encodeURIComponent(l.TABLE_EXTENSION)}/${encodeURIComponent(t.id)}`)}),e}clone(){const e=new he(this._mapExtension);return e._tableExtensionMap=this._tableExtensionMap,e}findById(e){return j("id",e).isNotMissing(),this.find(t=>t.id===e)}findByTableId(e){return j("id",e).isNotMissing(),this.find(t=>t._tableId===e)}forTable(e){if(j("table",e).isNotMissing(),this._tables.includes(e))return this._forTable(e)}add(e,t){if(j("tableX",e).isNotMissing(),e.mapExtension&&e.mapExtension.tableExtensions.remove(e),e._setMapExtension(this._mapExtension),e.table){const s=this._tableExtensionMap.get(e.table);if(this._tableExtensionMap.set(e.table,e),s&&s!==e&&this._onRemoved(s),this._tables.includes(e.table))if(void 0===t){const t={added:[e],moved:[],removed:s?[s]:[],target:this};s&&this.emit("after-remove",{item:s}),this.emit("after-add",{item:e}),this.emit("change",t)}else this._tables.reorder(e.table,t);else this._tables.add(e.table,t)}else{this._uninitializedTableExtensions.add(e);const t={added:[e],moved:[],removed:[],target:this};this.emit("after-add",{item:e}),this.emit("change",t)}return this._onAdded(e),this}removeAt(e){const t=this.getItemAt(e);if(void 0!==t){if(this._uninitializedTableExtensions.has(t)){this._uninitializedTableExtensions.delete(t);const e={added:[],moved:[],removed:[t],target:this};this.emit("after-remove",{item:t}),this.emit("change",e)}else this._tables.remove(t.table);return this._onRemoved(t),t}}reorder(e,t){if(e&&this._tables.includes(e.table))return this._tables.reorder(e.table,t),e}sort(e){return this._tables.sort((t,s)=>e(this._forTable(t),this._forTable(s))),this}_itemIsInitialized(e){return super._itemIsInitialized(e)&&!!e.table}_onAdded(e){}_onRemoved(e){e._setMapExtension(void 0)}_forTable(e){for(const e of this._uninitializedTableExtensions)e._resolveTable(),e.table&&(this._tableExtensionMap.set(e.table,e),this._uninitializedTableExtensions.delete(e));if(!this._tableExtensionMap.has(e)){const t=_.create({table:e});this._tableExtensionMap.set(e,t),t._setMapExtension(this._mapExtension),this._onAdded(t)}return this._tableExtensionMap.get(e)}}class me extends M{get _collection(){let e=this._mapExtension.layerExtensions.flatten(e=>W(e)?e.layerExtensions:[]);return this._mapExtension.basemapExtension&&(e=e.concat(this._mapExtension.basemapExtension.baseLayerExtensions.toArray()).concat(this._mapExtension.basemapExtension.referenceLayerExtensions.toArray())),e=e.concat(this._mapExtension.groundExtension.layerExtensions.toArray()),e}_mapExtension;_onChangeLayerExtensionsHandle=new P(()=>{const e=new WeakMap,t=new Set,i=a=>{const n=new s(a.added).flatten(e=>W(e)?e.layerExtensions:[]),o=new s(a.moved).flatten(e=>W(e)?e.layerExtensions:[]),r=new s(a.removed).flatten(e=>W(e)?e.layerExtensions:[]);for(const s of n)if(!e.has(s)&&W(s)){const a=s.layerExtensions.on("change",i);e.set(s,a),t.add(a)}for(const s of r){const i=e.get(s);i&&(i.remove(),e.delete(s),t.delete(i))}this.emit("change",{added:n.toArray(),moved:o.toArray(),removed:r.toArray()})};t.add(this._mapExtension.layerExtensions.on("change",i));const a=this._mapExtension.layerExtensions.flatten(e=>W(e)?e.layerExtensions:[]);for(const s of a)if(W(s)){const a=s.layerExtensions.on("change",i);e.set(s,a),t.add(a)}return t.add(Q(this._mapExtension,"basemapExtension.baseLayerExtensions",e=>{this.emit("change",{...e})})),t.add(Q(this._mapExtension,"basemapExtension.referenceLayerExtensions",e=>{this.emit("change",{...e})})),t.add(this._mapExtension.groundExtension.layerExtensions.on("change",e=>{this.emit("change",{...e})})),I(t)});_onAfterAddLayerExtensionsHandle=new P(()=>{const e=new WeakMap,t=new Set,s=s=>{const i=e.get(s);i&&(i.remove(),e.delete(s),t.delete(i))},i=e=>{const t=e.item;if(W(t)){const e=t.layerExtensions.flatten(e=>W(e)?e.layerExtensions:[]);for(const t of e)s(t)}s(t)},a=s=>{this.emit("after-add",{...s});const n=s.item;if(W(n)){const o=n.layerExtensions.flatten(e=>W(e)?e.layerExtensions:[]);for(const n of o)if(this.emit("after-add",{...s,item:n}),!e.has(n)&&W(n)){const s=n.layerExtensions.on("after-add",a),o=n.layerExtensions.on("after-remove",i),r=I([s,o]);e.set(n,r),t.add(r)}}};t.add(this._mapExtension.layerExtensions.on("after-add",a)),t.add(this._mapExtension.layerExtensions.on("after-remove",i));const n=this._mapExtension.layerExtensions.flatten(e=>W(e)?e.layerExtensions:[]);for(const s of n)if(W(s)){const n=s.layerExtensions.on("after-add",a),o=s.layerExtensions.on("after-remove",i),r=I([n,o]);e.set(s,r),t.add(r)}return t.add(z(this._mapExtension,"basemapExtension.baseLayerExtensions",["after-add",e=>this.emit("after-add",{...e})])),t.add(z(this._mapExtension,"basemapExtension.referenceLayerExtensions",["after-add",e=>this.emit("after-add",{...e})])),t.add(this._mapExtension.groundExtension.layerExtensions.on("after-add",e=>{this.emit("after-add",{...e})})),I(t)});_onAfterRemoveLayerExtensionsHandle=new P(()=>{const e=new WeakMap,t=new Set,s=s=>{const i=e.get(s);i&&(i.remove(),e.delete(s),t.delete(i))},i=e=>{this.emit("after-remove",{...e});const t=e.item;if(W(t)){const i=t.layerExtensions.flatten(e=>W(e)?e.layerExtensions:[]);for(const t of i)this.emit("after-remove",{...e,item:t}),s(t)}s(t)},a=s=>{const n=s.item;if(W(n)){const s=n.layerExtensions.on("after-add",a),o=n.layerExtensions.on("after-remove",i),r=I([s,o]);e.set(n,r),t.add(r)}};t.add(this._mapExtension.layerExtensions.on("after-remove",i)),t.add(this._mapExtension.layerExtensions.on("after-add",a));const n=this._mapExtension.layerExtensions.flatten(e=>W(e)?e.layerExtensions:[]);for(const s of n)if(W(s)){const n=s.layerExtensions.on("after-add",a),o=s.layerExtensions.on("after-remove",i),r=I([n,o]);e.set(s,r),t.add(r)}return t.add(z(this._mapExtension,"basemapExtension.baseLayerExtensions",["after-remove",e=>this.emit("after-remove",{...e})])),t.add(z(this._mapExtension,"basemapExtension.referenceLayerExtensions",["after-remove",e=>this.emit("after-remove",{...e})])),t.add(this._mapExtension.groundExtension.layerExtensions.on("after-remove",e=>{this.emit("after-remove",{...e})})),I(t)});constructor(e){super(),this._mapExtension=e}on(e,t){const s=[];return"change"===e?s.push(this._onChangeLayerExtensionsHandle.add()):"after-add"===e?s.push(this._onAfterAddLayerExtensionsHandle.add()):"after-remove"===e&&s.push(this._onAfterRemoveLayerExtensionsHandle.add()),s.push(super.on(e,t)),I(s)}destroy(){this._onChangeLayerExtensionsHandle.destroy(),this._onAfterAddLayerExtensionsHandle.destroy(),this._onAfterRemoveLayerExtensionsHandle.destroy(),super.destroy()}findById(e){return j("id",e).isNotMissing(),this.find(t=>t.id===e)}findByLayerId(e){return j("id",e).isNotMissing(),this.find(t=>t._layerId===e)}forLayer(e){return j("layer",e).isNotMissing(),this.findByLayerId(e.id)}_itemIsInitialized(e){return super._itemIsInitialized(e)&&!!e.layer}}function de(e){if(!(null==e||"object"==typeof e&&e?.baseMap))return X(e)}function le(e){return"object"!=typeof e||e&&!e.baseMap}function _e(e,t,s){if(e?.type&&e.type!==s)throw new Error(`Invalid portal item type "${e.type}" for property ${t}.`)}async function be(e){await N(e),e.basemap&&(await N(e.basemap),e.basemap.baseLayers.filter(e=>F(e)).map(e=>{const t=e;return t.activeLayer.imageFormat=t.activeLayer.imageFormat??(t.activeLayer.imageFormats?.length>0?t.activeLayer.imageFormats[0]:""),t.activeLayer.styleId=t.activeLayer.styleId??"",t}),e.basemap.id=k(e.basemap)??e.basemap.id)}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vertigis/arcgis-extensions",
3
3
  "license": "SEE LICENSE IN LICENSE",
4
- "version": "54.14.5",
4
+ "version": "54.15.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://dev.azure.com/vertigis/Studio/_git/arcgis-extensions-ts"
@@ -1,11 +1,25 @@
1
1
  import type EsriMap from "@arcgis/core/Map";
2
+ import * as Arcade from "@arcgis/core/arcade.js";
2
3
  import type SpatialReference from "@arcgis/core/geometry/SpatialReference";
3
4
  import type Layer from "@arcgis/core/layers/Layer";
4
5
  import type Sublayer from "@arcgis/core/layers/support/Sublayer";
5
6
  import type { Feature } from "../data/Feature.js";
6
7
  /**
7
- * Parameters for the {@link runArcadeExpression} and
8
- * {@link runAsyncArcadeExpression} functions.
8
+ * A custom Arcade variable value tagged with an explicit Arcade Variable type
9
+ * definition (excluding its `name`, which is inferred from its key in the
10
+ * `vars` object). Use this to attach values to the `vars` parameter of
11
+ * {@link runAsyncExpression} and {@link runSyncExpression} that are not plain
12
+ * JSON-compatible values (e.g. a FeatureSet, a Dictionary, or an Array of
13
+ * Features). Values in `vars` that are not created with this function are
14
+ * assumed to be plain JSON-compatible values and are declared using the "json"
15
+ * Arcade variable type.
16
+ */
17
+ export type ArcadeVariable = {
18
+ value: unknown;
19
+ } & (Omit<Arcade.SimpleVariable, "name"> | Omit<Arcade.DictionaryVariable, "name"> | Omit<Arcade.ArrayVariable, "name">);
20
+ /**
21
+ * Parameters for the {@link runArcadeExpression}, {@link runSyncExpression},
22
+ * {@link runAsyncExpression}, and {@link runAsyncArcadeExpression} functions.
9
23
  */
10
24
  export interface RunArcadeExpressionParams {
11
25
  /**
@@ -28,27 +42,59 @@ export interface RunArcadeExpressionParams {
28
42
  */
29
43
  layer?: Layer | Sublayer;
30
44
  /**
31
- * Additional Arcade arguments to attach to the script when run.
45
+ * Additional Arcade arguments to attach to the script when run. Values are
46
+ * assumed to be plain JSON-compatible values (declared using the "json"
47
+ * Arcade variable type) unless created with {@link toArcadeVariable} to
48
+ * specify an explicit Arcade variable type.
32
49
  */
33
50
  vars?: Record<string, unknown>;
34
51
  /**
35
52
  * Emit an error when the script is missing referenced variables. Defaults
36
53
  * to 'true'.
54
+ *
55
+ * @deprecated When using the {@link runAsyncExpression} or
56
+ * {@link runSyncExpression} function, this parameter is no longer used and
57
+ * the function will throw if any required parameters are missing.
37
58
  */
38
59
  emitErrorOnMissingVariables?: boolean;
39
60
  }
61
+ /**
62
+ * Creates and returns an ArcadeExecutor object for the given expression. This
63
+ * should primarily be used for executing Arcade expressions in a sync context
64
+ * with {@link runSyncExpression}. If you are executing an expression in an async
65
+ * context, you should use the {@link runAsyncExpression} function instead. Sync
66
+ * Arcade expressions cannot be run without first creating an executor
67
+ * asynchronously.
68
+ *
69
+ * @param expression The Arcade expression string.
70
+ * @param profile The profile definition used to execute the given expression.
71
+ * If not provided, a generic profile with all primary variable types will be
72
+ * used.
73
+ */
74
+ export declare function createExecutorForExpression(expression: string, profile?: Arcade.Profile): Promise<Arcade.ArcadeExecutor>;
75
+ /**
76
+ * Detect if the arcade expression requires an async evaluation.
77
+ *
78
+ * @param expression The Arcade expression string.
79
+ */
80
+ export declare function isExpressionAsyncOnly(expression: string): Promise<boolean>;
40
81
  /**
41
82
  * Detect if the arcade expression requires an async evaluation.
42
83
  *
84
+ * @deprecated Use {@link isExpressionAsyncOnly} instead. This function will be
85
+ * removed in a future release.
43
86
  * @param expression The Arcade expression string.
44
87
  * @param spatialReference Optionally the spatial reference for the expressions.
45
88
  */
46
89
  export declare function isArcadeScriptAsync(expression: string, spatialReference?: SpatialReference): boolean;
47
90
  /**
48
- * Execute an synchronous arcade expression string, and return the unformatted
91
+ * Execute a synchronous arcade expression string, and return the unformatted
49
92
  * result. You must call 'enableGeometrySupport' prior to evaluating any
50
93
  * expressions that might require the geometry engine.
51
94
  *
95
+ * @deprecated Create an executor using {@link createExecutorForExpression} and
96
+ * then call {@link runSyncExpression} instead. This function will be removed
97
+ * in a future release.
52
98
  * @param expression The arcade expression string.
53
99
  * @param params The parameters.
54
100
  */
@@ -57,7 +103,55 @@ export declare function runArcadeExpression(expression: string, params: RunArcad
57
103
  * Execute an asynchronous arcade expression string, and return the unformatted
58
104
  * result.
59
105
  *
106
+ * @deprecated Use runAsyncExpression instead. This function will be removed in
107
+ * a future release.
60
108
  * @param expression The arcade expression string.
61
109
  * @param params The parameters.
62
110
  */
63
111
  export declare function runAsyncArcadeExpression(expression: string, params: RunArcadeExpressionParams): Promise<unknown>;
112
+ /**
113
+ * Execute a synchronous arcade expression string, and return the unformatted
114
+ * result.
115
+ *
116
+ * @param expression The arcade expression string.
117
+ * @param params The parameters.
118
+ * @param executor The ArcadeExecutor to use for executing the expression. The
119
+ * executor should be created using the {@link createExecutorForExpression}
120
+ * function.
121
+ */
122
+ export declare function runSyncExpression(expression: string, params: RunArcadeExpressionParams, executor: Arcade.ArcadeExecutor): unknown;
123
+ /**
124
+ * Execute an asynchronous arcade expression string, and return the unformatted
125
+ * result.
126
+ *
127
+ * @param expression The arcade expression string.
128
+ * @param params The parameters.
129
+ */
130
+ export declare function runAsyncExpression(expression: string, params: RunArcadeExpressionParams): Promise<unknown>;
131
+ /**
132
+ * Constructs an Arcade profile based on the provided parameters.
133
+ *
134
+ * @param params The parameters.
135
+ */
136
+ export declare function constructProfile(params: RunArcadeExpressionParams): Arcade.Profile;
137
+ /**
138
+ * Tags a value with an explicit Arcade Variable type definition so it can be
139
+ * passed through the `vars` parameter of {@link runAsyncExpression} and
140
+ * {@link runSyncExpression} without being assumed to be a plain JSON-compatible
141
+ * value.
142
+ *
143
+ * @example
144
+ * ```
145
+ * await runAsyncExpression("Count($features)", {
146
+ * vars: {
147
+ * $features: toArcadeVariable(featureSet, { type: "featureSet" }),
148
+ * },
149
+ * });
150
+ * ```;
151
+ *
152
+ * @param value The value of the variable.
153
+ * @param definition The Arcade variable type definition (excluding `name`) to
154
+ * declare the value as (e.g. `{ type: "featureSet" }` for a FeatureSet
155
+ * object).
156
+ */
157
+ export declare function toArcadeVariable(value: unknown, definition: Omit<Arcade.SimpleVariable, "name"> | Omit<Arcade.DictionaryVariable, "name"> | Omit<Arcade.ArrayVariable, "name">): ArcadeVariable;
@@ -1 +1 @@
1
- import*as e from"@arcgis/core/arcade/arcade.js";import*as r from"@arcgis/core/support/arcadeUtils.js";import{checkArg as a}from"./checkArg.js";const t=new Map;export function isArcadeScriptAsync(a,t){const s=i(a,t);return["$datastore","$map","$layer"].some(e=>r.hasVariable(s,e))||e.scriptIsAsync({...s,isAsync:void 0,usesFeatureSet:void 0,usesGeometry:void 0},void 0)}export function arcadeScriptUsesGeometry(e,r){return!!i(e,r).usesGeometry}export async function enableGeometrySupportIfNeeded(r){const{spatialReference:a}=r.geometry??{},t=r.source?.layer?.elevationInfo?.featureExpressionInfo?.expression;t&&arcadeScriptUsesGeometry(t,a)&&await e.enableGeometrySupport()}export function runArcadeExpression(t,s){const{map:o,layer:n,vars:c,feature:p,spatialReference:u,emitErrorOnMissingVariables:f=!0}=s;a("$map and $layer parameters are not supported in synchronous arcade",s).satisfies(()=>!o&&!n);const l=r.getViewInfo({spatialReference:u}),m=r.createExecContext(p?.toGraphic(),l);if(c)for(const e of Object.keys(c))m.vars[e]=c[e];const y=i(t,u);if(r.hasVariable(y,"$feature"))if(f)a("params.feature",p).isNotMissing();else if(!p)return;return e.executeScript(y,m)}export async function runAsyncArcadeExpression(t,s){const{map:o,layer:n,vars:c,feature:p,spatialReference:u,emitErrorOnMissingVariables:f=!0}=s,l={...i(t,u)},m=["$datastore","$map","$layer"].filter(e=>r.hasVariable(l,e));await r.loadScriptDependencies(l,!0,m);const y=r.getViewInfo({spatialReference:u}),d=r.createExecContext(p?.toGraphic(),y);if(l.isAsync=!0,l.usesFeatureSet=!0,await Promise.all([e.enableAsyncSupport(),(async()=>{await import("@arcgis/core/arcade/functions/featuresetbase.js"),await e.enableFeatureSetSupport()})(),l.usesGeometry&&e.enableGeometrySupport()]),!r.hasVariable(l,"$feature")||(f&&a("params.feature",p).isNotMissing(),p)){if(m.includes("$map")){if(f&&a("params.map",o).isNotMissing(),!o)return;d.vars.$map=r.convertMapToFeatureSetCollection({map:o,spatialReference:u})}if(m.includes("$layer")){if(f&&a("params.layer",n).isNotMissing(),!n)return;d.vars.$layer=r.convertFeatureLayerToFeatureSet({layer:n,spatialReference:u})}if(m.includes("$datastore")){f&&a("params.layer",n).isNotMissing();const e=n?.url;if(!e)return;d.vars.$datastore=r.convertServiceUrlToWorkspace({url:e,spatialReference:u})}if(c)for(const e of Object.keys(c))d.vars[e]=c[e];return r.createFunction(l,d)(d)}}const s=["__proto__"];function i(r,a){const i=`${r}-${a?.wkid}`;if(t.has(i))return t.get(i);const o=s.filter(e=>r.includes(e));if(0!==o.length)throw new Error(`Invalid Arcade expression tokens: ${o.join()}`);const n=e.parseScript(r,a);return t.set(i,n),n}
1
+ import*as e from"@arcgis/core/arcade/arcade.js";import*as r from"@arcgis/core/arcade.js";import*as t from"@arcgis/core/support/arcadeUtils.js";import{checkArg as a}from"./checkArg.js";const n=new Map,s=r.createArcadeCache(),o=["__proto__"],i={variables:[{name:"$feature",type:"feature"},{name:"$map",type:"featureSetCollection"},{name:"$layer",type:"featureSet"},{name:"$datastore",type:"featureSetCollection"},{name:"$view",type:"featureSetCollection"}]};export async function createExecutorForExpression(e,t){return await r.createArcadeExecutor(e,t??i)}export async function isExpressionAsyncOnly(e){return(await createExecutorForExpression(e)).isAsync}export function isArcadeScriptAsync(r,a){const n=c(r,a);return["$datastore","$map","$layer"].some(e=>t.hasVariable(n,e))||e.scriptIsAsync({...n,isAsync:void 0,usesFeatureSet:void 0,usesGeometry:void 0},void 0)}export function runArcadeExpression(r,n){const{map:s,layer:o,vars:i,feature:p,spatialReference:u,emitErrorOnMissingVariables:f=!0}=n;a("$map and $layer parameters are not supported in synchronous arcade",n).satisfies(()=>!s&&!o);const l=t.getViewInfo({spatialReference:u}),y=t.createExecContext(p?.toGraphic(),l);if(i)for(const e of Object.keys(i))y.vars[e]=i[e];const m=c(r,u);if(t.hasVariable(m,"$feature"))if(f)a("params.feature",p).isNotMissing();else if(!p)return;return e.executeScript(m,y)}export async function runAsyncArcadeExpression(r,n){const{map:s,layer:o,vars:i,feature:p,spatialReference:u,emitErrorOnMissingVariables:f=!0}=n,l={...c(r,u)},y=["$datastore","$map","$layer"].filter(e=>t.hasVariable(l,e));await t.loadScriptDependencies(l,!0,y);const m=t.getViewInfo({spatialReference:u}),d=t.createExecContext(p?.toGraphic(),m);if(l.isAsync=!0,l.usesFeatureSet=!0,await Promise.all([e.enableAsyncSupport(),(async()=>{await import("@arcgis/core/arcade/functions/featuresetbase.js"),await e.enableFeatureSetSupport()})(),l.usesGeometry&&e.enableGeometrySupport()]),!t.hasVariable(l,"$feature")||(f&&a("params.feature",p).isNotMissing(),p)){if(y.includes("$map")){if(f&&a("params.map",s).isNotMissing(),!s)return;d.vars.$map=t.convertMapToFeatureSetCollection({map:s,spatialReference:u})}if(y.includes("$layer")){if(f&&a("params.layer",o).isNotMissing(),!o)return;d.vars.$layer=t.convertFeatureLayerToFeatureSet({layer:o,spatialReference:u})}if(y.includes("$datastore")){f&&a("params.layer",o).isNotMissing();const e=o?.url;if(!e)return;d.vars.$datastore=t.convertServiceUrlToWorkspace({url:e,spatialReference:u})}if(i)for(const e of Object.keys(i))d.vars[e]=i[e];return t.createFunction(l,d)(d)}}export function runSyncExpression(e,r,t){a("$map and $layer parameters are not supported in synchronous arcade",r).satisfies(()=>!r.map&&!r.layer);const n=p(e);if(n.length)throw new Error(`Invalid Arcade expression tokens: ${n.join()}`);const s=u(r),o=f(r);return t.execute(s,o)}export async function runAsyncExpression(e,r){const t=p(e);if(t.length)throw new Error(`Invalid Arcade expression tokens: ${t.join()}`);const a=constructProfile(r),n=u(r),s=f(r),o=await createExecutorForExpression(e,a);return await o.executeAsync(n,s)}export function constructProfile(e){const{feature:r,map:t,layer:a,vars:n}=e,s=[];if(n)for(const e of Object.keys(n)){const r=n[e];l(r)?s.push(y(e,r)):s.push({name:e,type:"json"})}return r&&s.push({name:"$feature",type:"feature"}),t&&s.push({name:"$map",type:"featureSetCollection"}),a&&(s.push({name:"$layer",type:"featureSet"}),s.push({name:"$datastore",type:"featureSetCollection"})),{variables:s}}export function toArcadeVariable(e,r){return{value:e,...r}}function c(r,t){const a=`${r}-${t?.wkid}`;if(n.has(a))return n.get(a);const s=p(r);if(s.length)throw new Error(`Invalid Arcade expression tokens: ${s.join()}`);const o=e.parseScript(r,t);return n.set(a,o),o}function p(e){return o.filter(r=>e.includes(r))}function u(e){const{feature:r,map:t,layer:a,vars:n}=e,s={};if(n)for(const e of Object.keys(n)){const r=n[e];s[e]=l(r)?r.value:r}return r&&(s.$feature=r.toGraphic()),t&&(s.$map=t),a&&(s.$layer=a,s.$datastore=a?.url),s}function f(e){const{spatialReference:r}=e;return{cache:s,spatialReference:r}}function l(e){return"object"==typeof e&&null!==e&&"value"in e&&"type"in e&&"string"==typeof e.type}function y(e,r){return"dictionary"===r.type?{name:e,type:"dictionary",properties:r.properties}:"array"===r.type?{name:e,type:"array",elementType:r.elementType}:{name:e,type:r.type}}
package/version.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * The current version of the Geocortex ArcGIS Extensions API.
3
3
  */
4
- export declare const version = "54.14.5";
4
+ export declare const version = "54.15.0";
package/version.js CHANGED
@@ -1 +1 @@
1
- export const version="54.14.5";
1
+ export const version="54.15.0";