@vertigis/arcgis-extensions 44.1.4 → 44.2.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.
- package/AppConfig.schema.json +4 -4
- package/docs/html/assets/search.js +1 -1
- package/docs/html/classes/mapping_BuildingSceneLayerExtension.BuildingSceneLayerExtension.html +3 -2
- package/docs/html/classes/mapping_CSVLayerExtension.CSVLayerExtension.html +3 -2
- package/docs/html/classes/mapping_ElevationLayerExtension.ElevationLayerExtension.html +3 -2
- package/docs/html/classes/mapping_FeatureCollectionLayerExtension.FeatureCollectionLayerExtension.html +3 -2
- package/docs/html/classes/mapping_FeatureLayerExtension.FeatureLayerExtension.html +3 -2
- package/docs/html/classes/mapping_FeatureLayerExtensionBase.FeatureLayerExtensionBase.html +3 -2
- package/docs/html/classes/mapping_GeoJSONLayerExtension.GeoJSONLayerExtension.html +3 -2
- package/docs/html/classes/mapping_GeoRSSLayerExtension.GeoRSSLayerExtension.html +3 -2
- package/docs/html/classes/mapping_GraphicsLayerExtension.GraphicsLayerExtension.html +3 -2
- package/docs/html/classes/mapping_GroupLayerExtension.GroupLayerExtension.html +3 -2
- package/docs/html/classes/mapping_ImageryLayerExtension.ImageryLayerExtension.html +3 -2
- package/docs/html/classes/mapping_ImageryTileLayerExtension.ImageryTileLayerExtension.html +3 -2
- package/docs/html/classes/mapping_IntegratedMeshLayerExtension.IntegratedMeshLayerExtension.html +3 -2
- package/docs/html/classes/mapping_KMLLayerExtension.KMLLayerExtension.html +3 -2
- package/docs/html/classes/mapping_MapImageLayerExtension.MapImageLayerExtension.html +3 -2
- package/docs/html/classes/mapping_MapNotesLayerExtension.MapNotesLayerExtension.html +3 -2
- package/docs/html/classes/mapping_OpenStreetMapLayerExtension.OpenStreetMapLayerExtension.html +3 -2
- package/docs/html/classes/mapping_PointCloudLayerExtension.PointCloudLayerExtension.html +3 -2
- package/docs/html/classes/mapping_RouteLayerExtension.RouteLayerExtension.html +3 -2
- package/docs/html/classes/mapping_SceneLayerExtension.SceneLayerExtension.html +3 -2
- package/docs/html/classes/mapping_StreamLayerExtension.StreamLayerExtension.html +3 -2
- package/docs/html/classes/mapping_SubtypeGroupLayerExtension.SubtypeGroupLayerExtension.html +3 -2
- package/docs/html/classes/mapping_TileLayerExtension.TileLayerExtension.html +3 -2
- package/docs/html/classes/mapping_UnsupportedLayerExtension.UnsupportedLayerExtension.html +3 -2
- package/docs/html/classes/mapping_VectorTileLayerExtension.VectorTileLayerExtension.html +3 -2
- package/docs/html/classes/mapping_WFSLayerExtension.WFSLayerExtension.html +3 -2
- package/docs/html/classes/mapping_WMSLayerExtension.WMSLayerExtension.html +3 -2
- package/docs/html/classes/mapping_WMTSLayerExtension.WMTSLayerExtension.html +3 -2
- package/docs/html/classes/mapping_WebTileLayerExtension.WebTileLayerExtension.html +3 -2
- package/docs/html/classes/mapping__LayerExtension.LayerExtension.html +3 -2
- package/docs/html/variables/version.version.html +1 -1
- package/json/BasemapJson.js +1 -1
- package/json/LayerJson.js +1 -1
- package/mapping/BasemapExtension.js +1 -1
- package/mapping/MapExtension.js +1 -1
- package/mapping/_LayerExtension.d.ts +1 -0
- package/mapping/_LayerExtension.js +1 -1
- package/package.json +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/mapping/MapExtension.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__decorate as e}from"tslib";import t from"@arcgis/core/core/Collection";import{ArgumentError as i}from"../ArgumentError.js";import{EntityBase as s}from"../Entity.js";import{InvalidOperationError as a}from"../InvalidOperationError.js";import{isBasemapExtension as n,isBookmark as o,isGroundExtension as r,isLayerPreset as p,isMenu as h,isTableExtension as m,ItemType as l}from"../ItemType.js";import{TableExtension as d}from"../data/TableExtension.js";import{layerToParentJsonCache as c}from"../json/LayerJson.js";import{applyJsonToWebMap as b}from"../json/WebMapJson.js";import{applyJsonToWebScene as _}from"../json/WebSceneJson.js";import{LayerPreset as u}from"../layer-preset/LayerPreset.js";import{Menu as E}from"../menus/Menu.js";import{DefaultArcGISRequestHelper as w}from"../support/ArcGISRequestHelper.js";import{FormatSettings as x}from"../support/FormatSettings.js";import{InitializableCollectionProxy as f}from"../support/InitializableCollectionProxy.js";import{ReadOnlyInitializableCollection as y}from"../support/ReadOnlyInitializableCollection.js";import{serializable as M}from"../support/Serializable.js";import{WellKnownBasemap as g}from"../support/esri.js";import{ReadOnlyCollection as I}from"../utilities/ReadOnlyCollection.js";import{basemapsAreEquivalent as v,createStandardBasemap as S,getStandardBasemapId as z,isStandardBasemap as O}from"../utilities/basemaps.js";import{checkArg as A}from"../utilities/checkArg.js";import{compare as P}from"../utilities/collection.js";import{load as C}from"../utilities/esri.js";import{isGroupLayerExtension as T}from"../utilities/extensions.js";import{filter as V}from"../utilities/iterable.js";import{isWMTSLayer as k,layersAreEquivalent as j}from"../utilities/layers.js";import{getLogger as B}from"../utilities/log.js";import{getMapSpatialReference as L,isMap as N,isWebMap as R,isWebScene as W}from"../utilities/mapping.js";import{toPortalItem as H}from"../utilities/portal.js";import{parallelEach as J}from"../utilities/promise.js";import{onCollectionPropertyChange as q,onEach as F}from"../utilities/watch.js";import{BasemapExtension as G}from"./BasemapExtension.js";import{Bookmark as D}from"./Bookmark.js";import{GroundExtension as U}from"./GroundExtension.js";import{MapConstraints as $}from"./MapConstraints.js";import{UnsupportedLayerExtension as X}from"./UnsupportedLayerExtension.js";import{_assignLayerExtensions as Y}from"./_LayerExtension.js";import{LayerExtensionCollectionBase as K}from"./support/_LayerExtensionCollection.js";const Q=B("MapExtension");let Z=class extends s{get webMap(){return this._webMap}get webScene(){return this._webScene}get map(){return this._currentMap}get viewMode(){return this.map?W(this.map)?"scene":"map":this.initialViewMode}get initialViewMode(){return this.webMap&&this.webScene?this._initialViewMode||"map":W(this.map)||this.webScene&&!this.webMap?"scene":"map"}set initialViewMode(e){this._initialViewMode=e}get requestHelper(){return this._requestHelper||(this._requestHelper=new w),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 a("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=new U({ground:this.map?.ground})),this._groundExtension}set groundExtension(e){if(!e)throw new a("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=p(e)?e:new u(e);this._initialLayerPreset=t}get _spatialReference(){return L(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&&Q.error({message:"An error occurred while initializing context menu.",error:e})}})()}isSwitchingMap=!1;_layerViews=new t;get _allLayerViews(){const e=i=>{const s=[i];return t.isCollection(i.sublayerViews)?s.push(...i.sublayerViews.toArray().flatMap(e)):t.isCollection(i.layerViews)&&s.push(...i.layerViews.toArray().flatMap(e)),s};return this._layerViews.toArray().flatMap(e)}get layerExtensions(){return this._layerExtensions}tableExtensions;allLayerExtensions;_itemType=l.MAP_EXTENSION;_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(e){super(e);let s={...e};this._basemapOptions=new te(this),this._groundExtensions=new WeakMap,this._layerExtensions=this._createLayerExtensionCollection(),this.tableExtensions=this._createTableExtensionCollection(),this.formatSettings=this._createFormatSettings(),this._bookmarks=new t,this.constraints=new $,this.watch(["_map","_scene"],(e=>{e&&(F(e.layers,"layerview-create",(e=>{this._layerViews.add(e.layerView)})),F(e.layers,"layerview-destroy",(e=>{this._layerViews.remove(e.layerView)})))}));const{webMap:a,webScene:n,initialViewMode:o,map:r,basemapOptions:p}=s;if(this._webMap=a,this._webScene=n,this._webMapItem=ae(a),this._webSceneItem=ae(n),this.initialViewMode=o,W(r)&&n)throw new i("Cannot specify webScene property if map is initialized to a WebScene instance.");if(N(r)&&a)throw new i("Cannot specify webMap property if map is initialized to a 2D Map instance.");if(W(r)||R(r)||N(r))this.assignProperties({basemapOptions:p}),this._skipBasemapOptions=!!p;else{const{layerExtensions:e,tableExtensions:t,groundExtension:i,basemapOptions:a,basemapExtension:n,...o}=s;this._deferredProperties={layerExtensions:e,tableExtensions:t,groundExtension:i,basemapOptions:a,basemapExtension:n},s=o,a&&(this._skipBasemapOptions=!0)}this._initMapFromProperties(s),this.watch("map.basemap",(()=>this._onBasemapChange()),!0),this.watch("map.ground",(()=>this._onGroundChange()),!0),this.allLayerExtensions=new se(this),this.map?.basemap&&this._onBasemapChange()}getAllFeatureSources(e=(()=>!0)){const t=[],i=a=>{a.hasFeatures&&t.push(a);for(const t of a.sublayerExtensions.initializedItems.filter(e).toArray())s(t);if(T(a))for(const t of a.layerExtensions.initializedItems.filter(e).toArray())i(t)},s=i=>{t.push(i);for(const t of i.sublayerExtensions.initializedItems.filter(e).toArray())s(t)};for(const t of this.layerExtensions.initializedItems.filter(e).toArray())i(t);for(const i of this.tableExtensions.initializedItems.filter(e).toArray())t.push(i);if(this.basemapExtension){for(const t of this.basemapExtension.baseLayerExtensions.initializedItems.filter(e).toArray())i(t);for(const t of this.basemapExtension.referenceLayerExtensions.initializedItems.filter(e).toArray())i(t)}return t}isSupportedViewMode(e){return e===this.viewMode||!(!this.webMap&&!this.webScene)&&("scene"===e?!!this.webScene:!!this.webMap)}async switchViewMode(e){if(A("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),t.basemap=this.map.basemap,await this.switchMap(t),this.notifyChange("viewMode"),this.notifyChange("title")}async switchMap(e){if(A("newMap",e).isNotMissing(),e===this.map)return;if(!this.map)return void this._setMap(e);this.isSwitchingMap=!0,this.isInitialized&&await re(e);const t=new Map;this.map.layers.forEach((e=>t.set(e,this.layerExtensions.forLayer(e))));const{basemapExtension:i}=this;this._setMap(e),this._updateBookmarks();const s=[];for(const e of this.map.layers.toArray()){const i=[...V(t.entries(),(([t])=>j(t,e)))];if(1===i.length){const[t]=i;s.push((async()=>{const i=t[1];await i._switchLayer(e),this._layerExtensions._register(i)})())}else{const t=this._layerExtensions._forLayer(e);t?.layer!==e&&s.push(t._switchLayer(e))}}this.map.basemap&&i&&v(this.map.basemap,i.basemap)&&s.push((async()=>{await i._switchBasemap(this.map.basemap),this.basemapExtension=i})()),this.isInitialized&&s.push(this._initializeChildren()),await Promise.all(s),this.isSwitchingMap=!1}async setWebMap(e){if(!e&&this.webMap&&!this.webScene)throw new a("Cannot unset both webMap and webScene.");this._webMap=e,this._map=void 0,this._createMapPromise=void 0,this._webMapItem=ae(e),await C(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.notifyChange("webMap"),this.notifyChange("initialViewMode"),this.notifyChange("title")}async setWebScene(e){if(!e&&this.webScene&&!this.webMap)throw new a("Cannot unset both webMap and webScene.");this._webScene=e,this._scene=void 0,this._createScenePromise=void 0,this._webSceneItem=ae(e),await C(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.notifyChange("webScene"),this.notifyChange("initialViewMode"),this.notifyChange("title")}getDefaults(){const e=super.getDefaults();return e.initialViewMode="map",e}async _createScene(){if(!this._scene&&this.webScene)return this._createScenePromise=this._createScenePromise??(async()=>{const e=(await import("@arcgis/core/WebScene")).default;ne(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;ne(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,i=(t?this._scene:this._map)?.layers.toArray()??[],s=e.filter((e=>!i.includes(e.layer)&&!i.some((t=>e.layer&&j(t,e.layer)))));Y(this.layerExtensions,s)}},serialize:e=>{if(this._deferredProperties?.layerExtensions)return this._deferredProperties.layerExtensions;{const t="map"===this.viewMode,i=(t?this._map:this._scene)?.layers.toArray();let s=(t?this._scene:this._map)?.layers.toArray()??[];return s=s.filter((e=>!i.find((t=>j(t,e))))),this.layerExtensions.concat(s.map((e=>this._layerExtensions._forLayer(e)))).filter((t=>!(t instanceof X||"initial"===e)||!t.dynamicallyAddedLayer)).toArray()}}},tableExtensions:{serializeModes:["initial","project"],deserialize:e=>{this.map?P(this.tableExtensions,e,{onNew:(e,t)=>{this.tableExtensions.add(m(e)?e:d.create(e),t)},onMatch:(e,t,i,s)=>{m(t)||e.assignProperties(t),i!==s&&this.tableExtensions.reorder(e,s)},equals:(e,t)=>m(t)?t===e:!!d._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(n(e))this.basemapExtension=e;else{if(this.basemapExtension)return this.basemapExtension.assignPropertiesAsync(e);this.basemapExtension=G.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:(P(this.basemapOptions,e,{onNew:(e,t)=>{this.basemapOptions.add(n(e)?e:G.create(e),t)},onMatch:(e,t,i,s)=>{n(t)||e.assignProperties(t),i!==s&&this.basemapOptions.reorder(e,s)},onMissing:e=>{this.basemapOptions.remove(e)},equals:(e,t)=>{if(n(t))return t===e;if(e.id&&t.id)return e.id===t.id;{const i=e.toJSON();return v(i.basemap,t.basemap||t.baseMap)}}}),this.basemapExtension&&this._ensureIsBasemapOption(this.basemapExtension),this.isInitialized&&J(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(!r(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=>o(e)?e:new D(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?h(e)?this.contextMenu=e:this.contextMenu?this.contextMenu.assignProperties(e):this.contextMenu=E.create(e):this.contextMenu=void 0}},map:{serializeModes:["project"],serialize:()=>{c.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 c.lookup=void 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(N(e)||R(e)||W(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,i){await J(this.basemapOptions.toArray(),(e=>e._createBackingBasemap()));let s=e;const a=this.basemapOptions.find((e=>v(e.basemap,s.baseMap)));a&&(t.basemap=a.basemap,s={...s,baseMap:{...s.baseMap,title:t.basemap.title}}),W(t)?await _(s,t,i):await b(s,t,i)}_createFormatSettings(){return new x}_createLayerExtensionCollection(){return new ee(this)}_createTableExtensionCollection(){return new ie(this)}async _onInitialize(){await super._onInitialize();const{basemapOptions:e,basemapExtension:t,webMap:i,webScene:s,...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([re(this.map),C(this._webMapItem),C(this._webSceneItem)]),oe(this._webMapItem,"webMap","Web Map"),oe(this._webSceneItem,"webScene","Web Scene")):await re(this.map),t&&(!n(t)&&t.basemap?this.basemapExtension=G.create(t):await this.assignPropertiesAsync({basemapExtension:t}),await this.basemapExtension._createBackingBasemap()),e){const t=e.find((e=>n(e)&&v(this.map.basemap,e.toJSON().basemap)));if(t){const e=t.toJSON().basemap?.id??t.basemap?.id,i=t.toJSON().basemap?.title;await t._switchBasemap(this.map.basemap),this.basemapExtension=t,e&&(this.map.basemap.id=e),i&&(this.map.basemap.title=i)}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 J(this.basemapOptions.toArray(),(e=>e._createBackingBasemap())),this.initialLayerPreset&&await this.initialLayerPreset.applyTo(this)}*_initializableChildCollections(){yield*super._initializableChildCollections();const e=new t(this.layerExtensions.filter((e=>!!e.layer)));e.remove=e=>{this.layerExtensions.remove(e)};const i=new t(this.tableExtensions.filter((e=>!!e.table)));if(i.remove=e=>{this.tableExtensions.remove(e)},yield e,yield i,this.basemapExtension){const e=new t;e.add(this.basemapExtension),yield e}const s=new t;s.add(this.groundExtension),yield s}_initMapFromProperties(e){const t=e.map;N(t)||R(t)||W(t)?this._setMap(t):"scene"===this.initialViewMode?e.webScene&&!ne(e.webScene)&&(this._deferredProperties={webScene:e.webScene,...this._deferredProperties}):e.webMap&&!ne(e.webMap)&&(this._deferredProperties={webMap:e.webMap,...this._deferredProperties})}_setMap(e){W(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),this.notifyChange("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=G.create({basemap:this.map.basemap}),this._basemapOptions.addInternal(e,0))}e.mapExtension!==this&&e._setMapExtension(this),this._basemapExtension=e}else this._basemapExtension=void 0;this.notifyChange("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));this.groundExtension._setMapExtension(void 0)}let e;this.map.ground&&(this._groundExtensions.has(this.map.ground)||this._groundExtensions.set(this.map.ground,new U({ground:this.map.ground})),e=this._groundExtensions.get(this.map.ground),e.mapExtension!==this&&e._setMapExtension(this)),this._groundExtension=e,this.notifyChange("groundExtension")}async _createStandardBasemapOptions(){const e=this._spatialReference;!this._basemapOptions.isExplicitlyModified&&e&&e.isWebMercator&&await J([g.SATELLITE,g.HYBRID_VECTOR,g.STREETS_VECTOR,g.TOPO_VECTOR,g.STREETS_NAVIGATION_VECTOR,g.STREETS_NIGHT_VECTOR,g.TERRAIN_VECTOR,g.DARK_GRAY_VECTOR,g.GRAY_VECTOR,g.OCEANS_VECTOR,g.OPEN_STREET_MAP_VECTOR],(async e=>{const t=await S(e);v(this.map.basemap,t)?this._basemapOptions.addInternal(this.basemapExtension):this._basemapOptions.addInternal(G.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)}_updateBookmarks(){this.bookmarks.removeMany(this.bookmarks.filter((e=>"map"===e.source))),R(this.map)&&this.map.bookmarks?.length>0?this.map.bookmarks.forEach((e=>{this.bookmarks.add(new D({source:"map",title:e.name,viewpoint:e.viewpoint}))})):W(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},i=new D(t);this.bookmarks.add(i)}))}};Z=e([M],Z);export{Z as MapExtension};class ee extends K{get _mapExtension(){return this._parent}constructor(e){super(e,"map.layers")}toJSON(){const e=[];return this.forEach((t=>{e.push(`item://${encodeURIComponent(l.LAYER_EXTENSION)}/${encodeURIComponent(t.id)}`)})),e}}class te extends f{isExplicitlyModified=!1;_mapExtension;constructor(e){super(new t),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,i=!0){const s=e=>{const t="-vector";return e?.endsWith(t)?e.substring(0,e.length-7):e};let a;if(e.basemap){const t=s(e.basemap.id);if(a=this.findIndex((e=>s(e.basemap?.id)===t)),O(e.basemap)&&a>=0){if(!i)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(){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 ie extends f{get _collection(){return this._tables.map((e=>this._forTable(e))).concat(Array.from(this._uninitializedTableExtensions))}get _tables(){return this._mapExtension.map?.tables??new I(new t)}_mapExtension;_tableExtensionMap=new WeakMap;_uninitializedTableExtensions=new Set;constructor(e){super(),this._mapExtension=e,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)})),this._mapExtension.watch("map.tables.length",(()=>this.notifyChange("length")))}toJSON(){const e=[];return this.forEach((t=>{e.push(`item://${encodeURIComponent(l.TABLE_EXTENSION)}/${encodeURIComponent(t.id)}`)})),e}clone(){const e=new ie(this._mapExtension);return e._tableExtensionMap=this._tableExtensionMap,e}findById(e){return A("id",e).isNotMissing(),this.find((t=>t.id===e))}findByTableId(e){return A("id",e).isNotMissing(),this.find((t=>t._tableId===e))}forTable(e){if(A("table",e).isNotMissing(),this._tables.includes(e))return this._forTable(e)}add(e,t){if(A("tableX",e).isNotMissing(),e.mapExtension&&e.mapExtension.tableExtensions.remove(e),e._setMapExtension(this._mapExtension),e.table){const i=this._tableExtensionMap.get(e.table);if(this._tableExtensionMap.set(e.table,e),i&&i!==e&&this._onRemoved(i),this._tables.includes(e.table))if(void 0===t){const t={added:[e],moved:[],removed:i?[i]:[],target:this};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("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("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,i)=>e(this._forTable(t),this._forTable(i)))),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=d.create({table:e});this._tableExtensionMap.set(e,t),t._setMapExtension(this._mapExtension),this._onAdded(t)}return this._tableExtensionMap.get(e)}}class se extends y{get _collection(){let e=this._mapExtension.layerExtensions.flatten((e=>T(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;constructor(e){super(),this._mapExtension=e}findById(e){return A("id",e).isNotMissing(),this.find((t=>t.id===e))}findByLayerId(e){return A("id",e).isNotMissing(),this.find((t=>t._layerId===e))}forLayer(e){return A("layer",e).isNotMissing(),this.findByLayerId(e.id)}emit(e,i){if("change"===e){const s=new t;s.addMany(i.added);const a=s.flatten((e=>T(e)?e.layerExtensions:[])).toArray(),n=new t;n.addMany(i.removed);const o=n.flatten((e=>T(e)?e.layerExtensions:[])).toArray(),r=new t;r.addMany(i.moved);const p=r.flatten((e=>T(e)?e.layerExtensions:[])).toArray();super.emit(e,{added:a,removed:o,moved:p,target:this})}return super.emit(e,i)}_itemIsInitialized(e){return super._itemIsInitialized(e)&&!!e.layer}}function ae(e){if("object"!=typeof e||!e?.baseMap)return H(e)}function ne(e){return"object"!=typeof e||e&&!e.baseMap}function oe(e,t,i){if(e?.type&&e.type!==i)throw new Error(`Invalid portal item type "${e.type}" for property ${t}.`)}async function re(e){await C(e),e.basemap&&(await C(e.basemap),e.basemap.baseLayers.filter((e=>k(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=z(e.basemap)??e.basemap.id)}
|
|
1
|
+
import{__decorate as e}from"tslib";import t from"@arcgis/core/core/Collection";import{ArgumentError as i}from"../ArgumentError.js";import{EntityBase as s}from"../Entity.js";import{InvalidOperationError as a}from"../InvalidOperationError.js";import{isBasemapExtension as n,isBookmark as o,isGroundExtension as r,isLayerPreset as p,isMenu as h,isTableExtension as m,ItemType as l}from"../ItemType.js";import{TableExtension as d}from"../data/TableExtension.js";import{layerToParentJsonCache as c}from"../json/LayerJson.js";import{applyJsonToWebMap as b}from"../json/WebMapJson.js";import{applyJsonToWebScene as _}from"../json/WebSceneJson.js";import{LayerPreset as u}from"../layer-preset/LayerPreset.js";import{Menu as E}from"../menus/Menu.js";import{DefaultArcGISRequestHelper as w}from"../support/ArcGISRequestHelper.js";import{FormatSettings as x}from"../support/FormatSettings.js";import{InitializableCollectionProxy as f}from"../support/InitializableCollectionProxy.js";import{ReadOnlyInitializableCollection as y}from"../support/ReadOnlyInitializableCollection.js";import{serializable as M}from"../support/Serializable.js";import{WellKnownBasemap as g}from"../support/esri.js";import{ReadOnlyCollection as I}from"../utilities/ReadOnlyCollection.js";import{basemapsAreEquivalent as v,createStandardBasemap as S,getStandardBasemapId as z,isStandardBasemap as O}from"../utilities/basemaps.js";import{checkArg as A}from"../utilities/checkArg.js";import{compare as P}from"../utilities/collection.js";import{load as C}from"../utilities/esri.js";import{isGroupLayerExtension as T}from"../utilities/extensions.js";import{filter as V}from"../utilities/iterable.js";import{isWMTSLayer as k,layersAreEquivalent as j}from"../utilities/layers.js";import{getLogger as B}from"../utilities/log.js";import{getMapSpatialReference as L,isMap as N,isWebMap as R,isWebScene as W}from"../utilities/mapping.js";import{toPortalItem as H}from"../utilities/portal.js";import{parallelEach as J}from"../utilities/promise.js";import{onCollectionPropertyChange as q,onEach as F}from"../utilities/watch.js";import{BasemapExtension as G}from"./BasemapExtension.js";import{Bookmark as D}from"./Bookmark.js";import{GroundExtension as U}from"./GroundExtension.js";import{MapConstraints as $}from"./MapConstraints.js";import{UnsupportedLayerExtension as X}from"./UnsupportedLayerExtension.js";import{_assignLayerExtensions as Y}from"./_LayerExtension.js";import{LayerExtensionCollectionBase as K}from"./support/_LayerExtensionCollection.js";const Q=B("MapExtension");let Z=class extends s{get webMap(){return this._webMap}get webScene(){return this._webScene}get map(){return this._currentMap}get viewMode(){return this.map?W(this.map)?"scene":"map":this.initialViewMode}get initialViewMode(){return this.webMap&&this.webScene?this._initialViewMode||"map":W(this.map)||this.webScene&&!this.webMap?"scene":"map"}set initialViewMode(e){this._initialViewMode=e}get requestHelper(){return this._requestHelper||(this._requestHelper=new w),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 a("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=new U({ground:this.map?.ground})),this._groundExtension}set groundExtension(e){if(!e)throw new a("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=p(e)?e:new u(e);this._initialLayerPreset=t}get _spatialReference(){return L(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&&Q.error({message:"An error occurred while initializing context menu.",error:e})}})()}isSwitchingMap=!1;_layerViews=new t;get _allLayerViews(){const e=i=>{const s=[i];return t.isCollection(i.sublayerViews)?s.push(...i.sublayerViews.toArray().flatMap(e)):t.isCollection(i.layerViews)&&s.push(...i.layerViews.toArray().flatMap(e)),s};return this._layerViews.toArray().flatMap(e)}get layerExtensions(){return this._layerExtensions}tableExtensions;allLayerExtensions;_itemType=l.MAP_EXTENSION;_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(e){super(e);let s={...e};this._basemapOptions=new te(this),this._groundExtensions=new WeakMap,this._layerExtensions=this._createLayerExtensionCollection(),this.tableExtensions=this._createTableExtensionCollection(),this.formatSettings=this._createFormatSettings(),this._bookmarks=new t,this.constraints=new $,this.watch(["_map","_scene"],(e=>{e&&(F(e.layers,"layerview-create",(e=>{this._layerViews.add(e.layerView)})),F(e.layers,"layerview-destroy",(e=>{this._layerViews.remove(e.layerView)})))}));const{webMap:a,webScene:n,initialViewMode:o,map:r,basemapOptions:p}=s;if(this._webMap=a,this._webScene=n,this._webMapItem=ae(a),this._webSceneItem=ae(n),this.initialViewMode=o,W(r)&&n)throw new i("Cannot specify webScene property if map is initialized to a WebScene instance.");if(N(r)&&a)throw new i("Cannot specify webMap property if map is initialized to a 2D Map instance.");if(W(r)||R(r)||N(r))this.assignProperties({basemapOptions:p}),this._skipBasemapOptions=!!p;else{const{layerExtensions:e,tableExtensions:t,groundExtension:i,basemapOptions:a,basemapExtension:n,...o}=s;this._deferredProperties={layerExtensions:e,tableExtensions:t,groundExtension:i,basemapOptions:a,basemapExtension:n},s=o,a&&(this._skipBasemapOptions=!0)}this._initMapFromProperties(s),this.watch("map.basemap",(()=>this._onBasemapChange()),!0),this.watch("map.ground",(()=>this._onGroundChange()),!0),this.allLayerExtensions=new se(this),this.map?.basemap&&this._onBasemapChange()}getAllFeatureSources(e=(()=>!0)){const t=[],i=a=>{a.hasFeatures&&t.push(a);for(const t of a.sublayerExtensions.initializedItems.filter(e).toArray())s(t);if(T(a))for(const t of a.layerExtensions.initializedItems.filter(e).toArray())i(t)},s=i=>{t.push(i);for(const t of i.sublayerExtensions.initializedItems.filter(e).toArray())s(t)};for(const t of this.layerExtensions.initializedItems.filter(e).toArray())i(t);for(const i of this.tableExtensions.initializedItems.filter(e).toArray())t.push(i);if(this.basemapExtension){for(const t of this.basemapExtension.baseLayerExtensions.initializedItems.filter(e).toArray())i(t);for(const t of this.basemapExtension.referenceLayerExtensions.initializedItems.filter(e).toArray())i(t)}return t}isSupportedViewMode(e){return e===this.viewMode||!(!this.webMap&&!this.webScene)&&("scene"===e?!!this.webScene:!!this.webMap)}async switchViewMode(e){if(A("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),t.basemap=this.map.basemap,await this.switchMap(t),this.notifyChange("viewMode"),this.notifyChange("title")}async switchMap(e){if(A("newMap",e).isNotMissing(),e===this.map)return;if(!this.map)return void this._setMap(e);this.isSwitchingMap=!0,this.isInitialized&&await re(e);const t=new Map;this.map.layers.forEach((e=>t.set(e,this.layerExtensions.forLayer(e))));const{basemapExtension:i}=this;this._setMap(e),this._updateBookmarks();const s=[];for(const e of this.map.layers.toArray()){const i=[...V(t.entries(),(([t])=>j(t,e)))];if(1===i.length){const[t]=i;s.push((async()=>{const i=t[1];await i._switchLayer(e),this._layerExtensions._register(i)})())}else{const t=this._layerExtensions._forLayer(e);t?.layer!==e&&s.push(t._switchLayer(e))}}this.map.basemap&&i&&v(this.map.basemap,i.basemap)&&s.push((async()=>{await i._switchBasemap(this.map.basemap),this.basemapExtension=i})()),await Promise.all(s),this.isInitialized&&await this._initializeChildren(),this.isSwitchingMap=!1}async setWebMap(e){if(!e&&this.webMap&&!this.webScene)throw new a("Cannot unset both webMap and webScene.");this._webMap=e,this._map=void 0,this._createMapPromise=void 0,this._webMapItem=ae(e),await C(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.notifyChange("webMap"),this.notifyChange("initialViewMode"),this.notifyChange("title")}async setWebScene(e){if(!e&&this.webScene&&!this.webMap)throw new a("Cannot unset both webMap and webScene.");this._webScene=e,this._scene=void 0,this._createScenePromise=void 0,this._webSceneItem=ae(e),await C(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.notifyChange("webScene"),this.notifyChange("initialViewMode"),this.notifyChange("title")}getDefaults(){const e=super.getDefaults();return e.initialViewMode="map",e}async _createScene(){if(!this._scene&&this.webScene)return this._createScenePromise=this._createScenePromise??(async()=>{const e=(await import("@arcgis/core/WebScene")).default;ne(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;ne(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,i=(t?this._scene:this._map)?.layers.toArray()??[],s=e.filter((e=>!i.includes(e.layer)&&!i.some((t=>e.layer&&j(t,e.layer)))));Y(this.layerExtensions,s)}},serialize:e=>{if(this._deferredProperties?.layerExtensions)return this._deferredProperties.layerExtensions;{const t="map"===this.viewMode,i=(t?this._map:this._scene)?.layers.toArray();let s=(t?this._scene:this._map)?.layers.toArray()??[];return s=s.filter((e=>!i.find((t=>j(t,e))))),this.layerExtensions.concat(s.map((e=>this._layerExtensions._forLayer(e)))).filter((t=>!(t instanceof X||"initial"===e)||!t.dynamicallyAddedLayer)).toArray()}}},tableExtensions:{serializeModes:["initial","project"],deserialize:e=>{this.map?P(this.tableExtensions,e,{onNew:(e,t)=>{this.tableExtensions.add(m(e)?e:d.create(e),t)},onMatch:(e,t,i,s)=>{m(t)||e.assignProperties(t),i!==s&&this.tableExtensions.reorder(e,s)},equals:(e,t)=>m(t)?t===e:!!d._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(n(e))this.basemapExtension=e;else{if(this.basemapExtension)return this.basemapExtension.assignPropertiesAsync(e);this.basemapExtension=G.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:(P(this.basemapOptions,e,{onNew:(e,t)=>{this.basemapOptions.add(n(e)?e:G.create(e),t)},onMatch:(e,t,i,s)=>{n(t)||e.assignProperties(t),i!==s&&this.basemapOptions.reorder(e,s)},onMissing:e=>{this.basemapOptions.remove(e)},equals:(e,t)=>{if(n(t))return t===e;if(e.id&&t.id)return e.id===t.id;{const i=e.toJSON();return v(i.basemap,t.basemap||t.baseMap)}}}),this.basemapExtension&&this._ensureIsBasemapOption(this.basemapExtension),this.isInitialized&&J(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(!r(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=>o(e)?e:new D(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?h(e)?this.contextMenu=e:this.contextMenu?this.contextMenu.assignProperties(e):this.contextMenu=E.create(e):this.contextMenu=void 0}},map:{serializeModes:["project"],serialize:()=>{c.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 c.lookup=void 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(N(e)||R(e)||W(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,i){await J(this.basemapOptions.toArray(),(e=>e._createBackingBasemap()));let s=e;const a=this.basemapOptions.find((e=>v(e.basemap,s.baseMap)));a&&(t.basemap=a.basemap,s={...s,baseMap:{...s.baseMap,title:t.basemap.title}}),W(t)?await _(s,t,i):await b(s,t,i)}_createFormatSettings(){return new x}_createLayerExtensionCollection(){return new ee(this)}_createTableExtensionCollection(){return new ie(this)}async _onInitialize(){await super._onInitialize();const{basemapOptions:e,basemapExtension:t,webMap:i,webScene:s,...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([re(this.map),C(this._webMapItem),C(this._webSceneItem)]),oe(this._webMapItem,"webMap","Web Map"),oe(this._webSceneItem,"webScene","Web Scene")):await re(this.map),t&&(!n(t)&&t.basemap?this.basemapExtension=G.create(t):await this.assignPropertiesAsync({basemapExtension:t}),await this.basemapExtension._createBackingBasemap()),e){const t=e.find((e=>n(e)&&v(this.map.basemap,e.toJSON().basemap)));if(t){const e=t.toJSON().basemap?.id??t.basemap?.id,i=t.toJSON().basemap?.title;await t._switchBasemap(this.map.basemap),this.basemapExtension=t,e&&(this.map.basemap.id=e),i&&(this.map.basemap.title=i)}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 J(this.basemapOptions.toArray(),(e=>e._createBackingBasemap())),this.initialLayerPreset&&await this.initialLayerPreset.applyTo(this)}*_initializableChildCollections(){yield*super._initializableChildCollections();const e=new t(this.layerExtensions.filter((e=>!!e.layer)));e.remove=e=>{this.layerExtensions.remove(e)};const i=new t(this.tableExtensions.filter((e=>!!e.table)));if(i.remove=e=>{this.tableExtensions.remove(e)},yield e,yield i,this.basemapExtension){const e=new t;e.add(this.basemapExtension),yield e}const s=new t;s.add(this.groundExtension),yield s}_initMapFromProperties(e){const t=e.map;N(t)||R(t)||W(t)?this._setMap(t):"scene"===this.initialViewMode?e.webScene&&!ne(e.webScene)&&(this._deferredProperties={webScene:e.webScene,...this._deferredProperties}):e.webMap&&!ne(e.webMap)&&(this._deferredProperties={webMap:e.webMap,...this._deferredProperties})}_setMap(e){W(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),this.notifyChange("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=G.create({basemap:this.map.basemap}),this._basemapOptions.addInternal(e,0))}e.mapExtension!==this&&e._setMapExtension(this),this._basemapExtension=e}else this._basemapExtension=void 0;this.notifyChange("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));this.groundExtension._setMapExtension(void 0)}let e;this.map.ground&&(this._groundExtensions.has(this.map.ground)||this._groundExtensions.set(this.map.ground,new U({ground:this.map.ground})),e=this._groundExtensions.get(this.map.ground),e.mapExtension!==this&&e._setMapExtension(this)),this._groundExtension=e,this.notifyChange("groundExtension")}async _createStandardBasemapOptions(){const e=this._spatialReference;!this._basemapOptions.isExplicitlyModified&&e&&e.isWebMercator&&await J([g.SATELLITE,g.HYBRID_VECTOR,g.STREETS_VECTOR,g.TOPO_VECTOR,g.STREETS_NAVIGATION_VECTOR,g.STREETS_NIGHT_VECTOR,g.TERRAIN_VECTOR,g.DARK_GRAY_VECTOR,g.GRAY_VECTOR,g.OCEANS_VECTOR,g.OPEN_STREET_MAP_VECTOR],(async e=>{const t=await S(e);v(this.map.basemap,t)?this._basemapOptions.addInternal(this.basemapExtension):this._basemapOptions.addInternal(G.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)}_updateBookmarks(){this.bookmarks.removeMany(this.bookmarks.filter((e=>"map"===e.source))),R(this.map)&&this.map.bookmarks?.length>0?this.map.bookmarks.forEach((e=>{this.bookmarks.add(new D({source:"map",title:e.name,viewpoint:e.viewpoint}))})):W(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},i=new D(t);this.bookmarks.add(i)}))}};Z=e([M],Z);export{Z as MapExtension};class ee extends K{get _mapExtension(){return this._parent}constructor(e){super(e,"map.layers")}toJSON(){const e=[];return this.forEach((t=>{e.push(`item://${encodeURIComponent(l.LAYER_EXTENSION)}/${encodeURIComponent(t.id)}`)})),e}}class te extends f{isExplicitlyModified=!1;_mapExtension;constructor(e){super(new t),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,i=!0){const s=e=>{const t="-vector";return e?.endsWith(t)?e.substring(0,e.length-7):e};let a;if(e.basemap){const t=s(e.basemap.id);if(a=this.findIndex((e=>s(e.basemap?.id)===t)),O(e.basemap)&&a>=0){if(!i)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(){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 ie extends f{get _collection(){return this._tables.map((e=>this._forTable(e))).concat(Array.from(this._uninitializedTableExtensions))}get _tables(){return this._mapExtension.map?.tables??new I(new t)}_mapExtension;_tableExtensionMap=new WeakMap;_uninitializedTableExtensions=new Set;constructor(e){super(),this._mapExtension=e,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)})),this._mapExtension.watch("map.tables.length",(()=>this.notifyChange("length")))}toJSON(){const e=[];return this.forEach((t=>{e.push(`item://${encodeURIComponent(l.TABLE_EXTENSION)}/${encodeURIComponent(t.id)}`)})),e}clone(){const e=new ie(this._mapExtension);return e._tableExtensionMap=this._tableExtensionMap,e}findById(e){return A("id",e).isNotMissing(),this.find((t=>t.id===e))}findByTableId(e){return A("id",e).isNotMissing(),this.find((t=>t._tableId===e))}forTable(e){if(A("table",e).isNotMissing(),this._tables.includes(e))return this._forTable(e)}add(e,t){if(A("tableX",e).isNotMissing(),e.mapExtension&&e.mapExtension.tableExtensions.remove(e),e._setMapExtension(this._mapExtension),e.table){const i=this._tableExtensionMap.get(e.table);if(this._tableExtensionMap.set(e.table,e),i&&i!==e&&this._onRemoved(i),this._tables.includes(e.table))if(void 0===t){const t={added:[e],moved:[],removed:i?[i]:[],target:this};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("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("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,i)=>e(this._forTable(t),this._forTable(i)))),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=d.create({table:e});this._tableExtensionMap.set(e,t),t._setMapExtension(this._mapExtension),this._onAdded(t)}return this._tableExtensionMap.get(e)}}class se extends y{get _collection(){let e=this._mapExtension.layerExtensions.flatten((e=>T(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;constructor(e){super(),this._mapExtension=e}findById(e){return A("id",e).isNotMissing(),this.find((t=>t.id===e))}findByLayerId(e){return A("id",e).isNotMissing(),this.find((t=>t._layerId===e))}forLayer(e){return A("layer",e).isNotMissing(),this.findByLayerId(e.id)}emit(e,i){if("change"===e){const s=new t;s.addMany(i.added);const a=s.flatten((e=>T(e)?e.layerExtensions:[])).toArray(),n=new t;n.addMany(i.removed);const o=n.flatten((e=>T(e)?e.layerExtensions:[])).toArray(),r=new t;r.addMany(i.moved);const p=r.flatten((e=>T(e)?e.layerExtensions:[])).toArray();super.emit(e,{added:a,removed:o,moved:p,target:this})}return super.emit(e,i)}_itemIsInitialized(e){return super._itemIsInitialized(e)&&!!e.layer}}function ae(e){if("object"!=typeof e||!e?.baseMap)return H(e)}function ne(e){return"object"!=typeof e||e&&!e.baseMap}function oe(e,t,i){if(e?.type&&e.type!==i)throw new Error(`Invalid portal item type "${e.type}" for property ${t}.`)}async function re(e){await C(e),e.basemap&&(await C(e.basemap),e.basemap.baseLayers.filter((e=>k(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=z(e.basemap)??e.basemap.id)}
|
|
@@ -256,6 +256,7 @@ export declare abstract class LayerExtension<TProperties extends LayerExtensionP
|
|
|
256
256
|
* destroyed.
|
|
257
257
|
*/
|
|
258
258
|
protected readonly _watchHandles: IHandle[];
|
|
259
|
+
protected readonly _layerWatchHandles: IHandle[];
|
|
259
260
|
private _mapExtension;
|
|
260
261
|
private _basemapExtension;
|
|
261
262
|
private _groundExtension;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__decorate as e}from"tslib";import t from"@arcgis/core/core/Collection";import{ArgumentError as i}from"../ArgumentError.js";import{InvalidOperationError as s}from"../InvalidOperationError.js";import{ItemType as r}from"../ItemType.js";import{FeatureSourceBase as a}from"../data/FeatureSourceBase.js";import{FieldExtension as n}from"../data/FieldExtension.js";import{Schema as o}from"../data/Schema.js";import{layerToJson as l,getLayerJsonType as y,jsonToLayer as h,applyJsonToLayer as p}from"../json/LayerJson.js";import{DefaultArcGISRequestHelper as u}from"../support/ArcGISRequestHelper.js";import{ReadOnlyInitializableCollection as d}from"../support/ReadOnlyInitializableCollection.js";import{serializable as c}from"../support/Serializable.js";import{getEquivalencyTypeForLayers as f,getLayerUrl as _,isLayer as g}from"../utilities/_layers.js";import{checkArg as b}from"../utilities/checkArg.js";import{compare as m}from"../utilities/collection.js";import{load as S}from"../utilities/esri.js";import{isGroupLayerExtension as L}from"../utilities/extensions.js";import{hasMmapLayer as E}from"../utilities/layers.js";import{getLogger as x}from"../utilities/log.js";import{deepClone as w,objectKeys as v}from"../utilities/object.js";import{toPortalItem as M}from"../utilities/portal.js";import{onCollectionPropertyChange as P,watchEach as I}from"../utilities/watch.js";import{_assignSublayerExtensions as C}from"./_SublayerExtension.js";import{ExtensionBaseLayerListSettings as A,fromLayerListMode as z}from"./support/LayerListSettings.js";import{SublayerExtensionCollectionBase as j}from"./support/_SublayerExtensionCollection.js";const T="Invalid type of layer for this type of layer extension.",V="This type of layer does not have features.",F="This type of layer cannot have sublayers.",O=Object.freeze({supportsAdd:!1,supportsUpdate:!1,supportsDelete:!1,supportsEditing:!1,supportsQuery:!1,supportsAttachmentEditing:!1,supportsStandardizedQueries:!1});export class LayerExtension extends a{get layer(){return this._layer}get mapExtension(){return this._mapExtension}get basemapExtension(){return this._basemapExtension}get groundExtension(){return this._groundExtension}get parentLayerExtension(){return this._parentLayerExtension}get hasFeatures(){return!1}get capabilities(){return this._capabilities()}get renderer(){}get visibilityMode(){return this._visibilityMode}set visibilityMode(e){this._visibilityMode=e,"exclusive"===e&&this._ensureAtMostOneChildSublayerVisible()}get sublayerExtensions(){return this._sublayerExtensions}get requestHelper(){return this._requestHelper||(this._requestHelper=new u),this._requestHelper}set requestHelper(e){this._requestHelper=e}get title(){return this.layer?.title??this._deferredLayerProperties?.title??("string"==typeof this._deferredLayerProperties?.$ref?this._deferredLayerProperties?.$ref:this._deferredLayerProperties?.$ref?.title??this._deferredLayerProperties?.$ref?.id)??"Layer"}get supportsSublayers(){return!1}get effectiveMinScale(){return this.layer&&this.layer.minScale||0}get effectiveMaxScale(){return this.layer&&this.layer.maxScale||0}get isEffectivelyVisible(){const e=!!this.layer&&this.layer.visible;return this.parentLayerExtension?this.parentLayerExtension.isEffectivelyVisible&&e:e}get effectiveFullExtent(){return this.layer?this.layer.fullExtent:void 0}get canChangeScale(){return!0}get canChangeOpacity(){return!0}get canChangeLabels(){return!1}get canChangeRenderer(){return!1}get canChangeDefinitionExpression(){return!1}get initialVisibility(){return this._initialVisibility??this.layer?.visible??!1}get _layerId(){return this.layer?.id??this._deferredLayerProperties?.$ref?.id}get _layerSupportsHideChildren(){return this.supportsSublayers}get _sublayers(){if(this.supportsSublayers)return this.layer?this.layer.sublayers:void 0}static factory;get dynamicallyAddedLayer(){return this._dynamicallyAddedLayer}set dynamicallyAddedLayer(e){this._dynamicallyAddedLayer=e}tpkSource;layerListSettings;allSublayerExtensions;get sublayersAreReadOnly(){return!0}_itemType=r.LAYER_EXTENSION;_watchHandles=[];_mapExtension;_basemapExtension;_groundExtension;_parentLayerExtension;_sublayerExtensions;_layer;_dynamicallyAddedLayer=!1;_deferredLayerProperties;_requestHelper;_initialVisibility;_visibilityMode="independent";_portalItem;constructor(e){super(e);const t={...this.getDefaults(),...e};b("properties.layer",t.layer).isNotMissing();const{layer:i}=t;let s;if(i?.hasOwnProperty("listMode")&&(s=z(i.listMode)),this.layerListSettings=this._createLayerListSettings({...s,...t.layerListSettings}),g(i))b("properties.layer",i).satisfies((e=>this._isSupportedLayer(e)),T),this._setLayer(i);else if(i){if(i.$portalItem){const e=i.$portalItem;this._portalItem=M(e)}this._deferredLayerProperties=i}this._sublayerExtensions=this._createSublayerExtensionCollection(),this.allSublayerExtensions=new D(this),this.watch("parentLayerExtension.isEffectivelyVisible",(()=>this.notifyChange("isEffectivelyVisible"))),this.watch("layer.sublayers",(()=>this.notifyChange("_sublayers")))}static create(e){if(!LayerExtension.factory)throw new s("Cannot create layer extension: no layer extension factory has been registered.");return LayerExtension.factory.create(e)}static async fromPortalItem(e,t){b("portalItemLike",e).isNotMissing();const s=t??{};b("layerExtensionProperties.layer",s.layer).satisfies((e=>!g(e)));const r={...s.layer};b("layerExtensionProperties.layer.$ref",r.$ref).satisfies((e=>null==e));const a=new u,n=M(e);let o;await S(n);const l=n.typeKeywords??"";if("Map Service"===n.type)o=l.includes("Tiled")||l.includes("Hosted Service")?"ArcGISTiledMapServiceLayer":"ArcGISMapServiceLayer";else if("Feature Service"===n.type)o="ArcGISFeatureLayer";else if("Image Service"===n.type){const e=await LayerExtension._getLayerData(n.url,a);e.cacheType?"Map"===e.cacheType?o="ArcGISTiledImageServiceLayer":("Elevation"===e.cacheType||l.includes("Elevation 3D Layer"))&&(o="ArcGISTiledElevationServiceLayer"):o=e.singleFusedMapCache||e.tileInfo||l.includes("Hosted Service")?"ArcGISTiledImageServiceLayer":"ArcGISImageServiceLayer"}else if("CSV"===n.type)o="CSV";else if("KML"===n.type)o="KML";else if("Scene Service"===n.type)l.includes("3DObject")||l.includes("Point")?o="ArcGISSceneServiceLayer":l.includes("IntegratedMesh")?o="IntegratedMeshLayer":l.includes("PointCloud")?o="PointCloudLayer":l.includes("Building")&&(o="BuildingSceneLayer");else if("Stream Service"===n.type)o="ArcGISStreamLayer";else if("Vector Tile Service"===n.type)o="VectorTileLayer";else if("Feature Collection"===n.type){o="ArcGISFeatureLayer";const e=await n.fetchData();r.featureCollection=e}else if("WFS"===n.type){o="WFS";const e=await n.fetchData();Object.assign(r,e)}else if("WMTS"===n.type){o="WebTiledLayer";const e=await n.fetchData();Object.assign(r,e)}else if("WMS"===n.type){o="WMS";const e=await n.fetchData();Object.assign(r,e)}if(!o)throw new i("portalItem","Could not determine correct type of LayerExtension to create from portal item");if(r.layerType&&r.layerType!==o)throw new i("layerExtensionProperties.layer.layerType","Layer type defined in layer properties does not match layer type from portal item");return r.layerType=o,r.$portalItem=n,s.layer=r,LayerExtension.create(s)}static async _getLayerData(e,t){const i=await t.request(e,{query:{f:"json"}});if(!i?.data)throw new Error(`Response to request for url ${e} was invalid.`);return i.data}getFeatures(e,t){if(!this.hasFeatures)throw new s(V);return super.getFeatures(e,t)}getFullExtent(){return this.effectiveFullExtent}async addFeatures(e,t){if(b("features",e).isNotMissing(),!this.hasFeatures)throw new s(V);await super.addFeatures(e,t)}async updateFeatures(e,t){if(b("features",e).isNotMissing(),!this.hasFeatures)throw new s(V);await super.updateFeatures(e,t)}async deleteFeatures(e,t){if(b("features",e).isNotMissing(),!this.hasFeatures)throw new s(V);await super.deleteFeatures(e,t)}async _createBackingLayer(){this._portalItem||this.layer||this._deferredLayerProperties?.$ref?!this.layer&&this._portalItem&&this._setLayer(await this._createLayer(this.getDefaults().layer)):(this._setLayer(await this._createLayer(this._deferredLayerProperties)),b("properties.layer",this._layer).satisfies((e=>this._isSupportedLayer(e)),T),this._deferredLayerProperties=void 0)}_setMapExtension(e){const t=this.mapExtension;this._mapExtension=e,t&&this.featureSettings.formatSettings.parent===t.formatSettings&&(this.featureSettings.formatSettings.parent=void 0),e&&(this.featureSettings.formatSettings.parent||(this.featureSettings.formatSettings.parent=e.formatSettings)),this._resolveLayer(),this.notifyChange("mapExtension")}_setBasemapExtension(e){this._basemapExtension=e,this._resolveLayer(),e&&(this.taskSettings.parent=e.taskSettings),this.notifyChange("basemapExtension")}_setGroundExtension(e){this._groundExtension=e,this._resolveLayer(),e&&(this.taskSettings.parent=e.taskSettings),this.notifyChange("groundExtension")}_setParentLayerExtension(e){const t=this._parentLayerExtension;this._parentLayerExtension=e,t&&(this.featureSettings.formatSettings.parent===t.featureSettings.formatSettings&&(this.featureSettings.formatSettings.parent=this.mapExtension?this.mapExtension.formatSettings:void 0),this.taskSettings.parent===t.taskSettings&&(this.taskSettings.parent=void 0)),e&&((!this.featureSettings.formatSettings.parent||this.mapExtension&&this.featureSettings.formatSettings.parent===this.mapExtension.formatSettings)&&(this.featureSettings.formatSettings.parent=e.featureSettings.formatSettings),this.taskSettings.parent||(this.taskSettings.parent=e.taskSettings)),this._resolveLayer(),this.notifyChange("parentLayerExtension")}_resolveLayer(e){if(this.layer||!this._deferredLayerProperties)return;const t=e??this.basemapExtension?.basemap?.baseLayers??this.groundExtension?.ground?.layers??this.parentLayerExtension?.layer?.layers??this.mapExtension?.map.layers;if(!t)return;const i=[];let s;for(const e of t){const t=f(e,this._deferredLayerProperties);if("none"!==t){if("solid"===t){s=e;break}i.push(e)}}s||1!==i.length||(s=i[0]),s&&this._isSupportedLayer(s)&&(this._setLayer(s),this._deferredLayerProperties.$portalItem&&B().warn("LayerExtension defined with both $ref and $portalItem. Ignoring $portalItem."))}async _switchLayer(e){if(e===this.layer)return;b("newLayer",e).isNotMissing().satisfies((e=>this._isSupportedLayer(e)),T),this.isInitialized&&await S(e);const t=new Map;if(this._sublayers)for(const e of this._sublayers.toArray())t.set(e.id,this.sublayerExtensions.forSublayer(e));e.visible=this.layer.visible,e.opacity=this.layer.opacity,e.listMode=this.layer.listMode,e.hasOwnProperty("labelsVisible")&&this.layer.hasOwnProperty("labelsVisible")&&(e.labelsVisible=this.layer.labelsVisible);const i=this.schema.fieldExtensions.toArray();this._setLayer(e),i.forEach((e=>{const t=this.schema.fields.find((t=>n.matchesRef(e,{$ref:t.name})));t&&e._switchField(t)}));const s=[];if(this._sublayers){const e=this._sublayers.filter((e=>t.has(e.id))).toArray();s.push(...e.map((async e=>{const i=t.get(e.id);await i._switchSublayer(e),this._sublayerExtensions._register(i)})))}this.isInitialized&&s.push(this._initializeChildren()),await Promise.all(s)}_getProjectWebmapJSON(){if(!this.layer)return;let e=l(this.layer);if(!this.dynamicallyAddedLayer){const{id:t,title:i,layerType:s,visibility:r,opacity:a}=e;e={id:t,title:i,layerType:s,visibility:r,opacity:a}}return e}_onSublayerAddedPostInitialize=async e=>{try{await e.initialize()}catch(t){B().error({message:`Error occurred while initializing sublayer extension for sublayer '${e.title??e.sublayer.id??e.id}'.`,error:t})}};async _onDestroy(){this._watchHandles.forEach((e=>e?.remove())),await Promise.all(this.sublayerExtensions.toArray().map((e=>e.destroy()))),await super._onDestroy()}_getSerializableProperties(){return{...super._getSerializableProperties(),iconUrl:{serializeModes:["initial","project"],serialize:e=>"project"!==e||this.dynamicallyAddedLayer?this.iconUrl:this.getDefault("iconUrl")},visibilityMode:{serializeModes:["initial","project"],serialize:e=>"project"!==e||this.dynamicallyAddedLayer?this.visibilityMode:this.getDefault("visibilityMode"),default:"independent"},tpkSource:{serializeModes:["initial"]},layerListSettings:{serializeModes:["initial","project"],serialize:e=>"project"!==e||this.dynamicallyAddedLayer?this.layerListSettings:this.getDefault("layerListSettings")},sublayerExtensions:{serializeModes:["initial","project"],serialize:e=>this.sublayerExtensions.map((e=>e.toItemUri())).toArray(),deserialize:e=>{C(this.sublayerExtensions,e,(e=>this._createSublayerExtension(e)))}},layer:{serializeModes:["initial","project"],serialize:e=>{if(this.layer){if((this._mapExtension||this._parentLayerExtension||this._basemapExtension||this._groundExtension)&&(this._layer.id||this._layer.title)){const e=y(this._layer),t=this._getSerializableRefLayerProperties(),i=_(this._layer),s=i?{url:i}:{};return{$ref:{id:this._layer.id,title:this._layer.title,subtype:this._getSerializableLayerType(),...s},layerType:e,...t}}return l(this.layer)}return this._deferredLayerProperties?w(this._deferredLayerProperties):void 0},isDefault:()=>{throw new Error("Missing implementation for _getSerializableProperties() > layer > default. Subclasses of LayerExtension must implement this.")},deserialize:e=>{if(g(e)){if(e!==this.layer)throw new Error("Property 'layer' is read-only.")}else if(e){if(this._layer)return this._applyLayerProperties(e,this.layer);this._deferredLayerProperties&&(this._deferredLayerProperties={...this._deferredLayerProperties,...e})}}},dynamicallyAddedLayer:{serializeModes:["project"],default:!1},requestHelper:{serialize:!1}}}_getSerializableLayerType(){}_getSerializableRefLayerProperties(){return{}}_createSublayerExtension(e){if(!this.supportsSublayers)throw new s(F);throw new Error("Missing implementation for _createSublayerExtension(). Subclasses of LayerExtension that support sublayers must implement this.")}async _onInitialize(){if(await super._onInitialize(),await this._createBackingLayer(),this._portalItem&&(await S(this._portalItem),await this._applyPortalItemProperties(this._portalItem),this.layer.title=this._portalItem.title,this.layer.portalItem=this._portalItem,this.iconUrl||(this.iconUrl=this._portalItem.thumbnailUrl),await this._applyLayerProperties(this._deferredLayerProperties,this.layer),this._deferredLayerProperties=void 0),this._resolveLayer(),!this.layer){const e=this._deferredLayerProperties.$ref;throw this._mapExtension||this._parentLayerExtension||this._basemapExtension||this._groundExtension?new s(`No layer found matching reference "${"string"==typeof e?e:JSON.stringify(e)}".`):new s("Cannot resolve layer reference: missing parent.")}this._deferredLayerProperties&&(await this._applyLayerProperties(this._deferredLayerProperties,this.layer),this._deferredLayerProperties=void 0),await this._initializeLayer(),await S(this.layer),this.supportsSublayers&&!this.layer.sublayers&&this.layer._set("sublayers",new t),this._initialVisibility=this.layer.visible,this._sublayerExtensions.onParentInitialized()}async _postInitialize(){await super._postInitialize(),this.layerListSettings.onLayerExtensionInitialized(),this.supportsSublayers&&this._watchHandles.push(P(this,"layer.sublayers",(async e=>{const t=(e.added??[]).map((e=>this.sublayerExtensions.forSublayer(e)));await Promise.all(t.map(this._onSublayerAddedPostInitialize))})))}_applyPortalItemProperties(e){throw new s("Cannot use this type of layer extension with a PortalItem.")}async _initializeLayer(){}_createLayerListSettings(e){return new H(e,this)}_createSublayerExtensionCollection(){return new $(this)}_capabilities(){return O}*_initializableChildCollections(){yield*super._initializableChildCollections(),yield this.sublayerExtensions}async _createLayer(e){return h(e)}_applyLayerProperties(e,t){b("layerJson",e).isNotMissing();const i=e.layerType||e.type;return b("layerJson.layerType",i).satisfies((e=>!e||e===this.getDefault("layer")?.layerType)),b("layer",t).isNotMissing().satisfies((e=>this._isSupportedLayer(e))),p(e,t)}_setLayer(e){if(this._layer=e,e.watch("visible",this._onVisibleChanged),this.layer.watch("minScale",(()=>this.notifyChange("effectiveMinScale"))),this.layer.watch("maxScale",(()=>this.notifyChange("effectiveMaxScale"))),this.layer.watch("title",(()=>this.notifyChange("title"))),this.supportsSublayers)if(this._sublayers)this._setupSublayersHandles();else{const t=e.watch("sublayers",(()=>{this._setupSublayersHandles(),t.remove()}),!0)}this.notifyChange("layer"),this.notifyChange("title"),this.notifyChange("effectiveMinScale"),this.notifyChange("effectiveMaxScale"),this.notifyChange("isEffectivelyVisible")}_setupSublayersHandles(){this._sublayers.on("change",this._onSublayersChange),I(this._sublayers,"visible",this._onSublayersSublayerVisibleChanged)}_onVisibleChanged=e=>{if("inherited"===this.visibilityMode&&this.supportsSublayers&&this._sublayers)for(const t of this._sublayers.toArray())t.visible=e;this.notifyChange("isEffectivelyVisible")};_onSublayersSublayerVisibleChanged=(e,t,i,s)=>{e&&"exclusive"===this.visibilityMode&&this._ensureAChildSublayerVisible(s)};_onSublayersChange=e=>{e.added?.length&&"exclusive"===this.visibilityMode&&this._ensureAChildSublayerVisible(e.added[e.added.length-1])};_ensureAChildSublayerVisible(e){for(const t of this._sublayers.toArray())t!==e&&(t.visible=!1)}_ensureAtMostOneChildSublayerVisible(){this.layer&&this._sublayers&&this._ensureAChildSublayerVisible(this._sublayers.find((e=>e.visible)))}}class $ extends j{constructor(e){super(e,"_sublayers"),this._layerExtension=e}add(e,t){if(b("sublayerX",e).isNotMissing(),!this._layerExtension.supportsSublayers)throw new s(F);const i=e.sublayer?e.sublayer.layer:void 0;return i&&i!==this._layerExtension.layer&&i.sublayers.remove(e.sublayer),super.add(e,t)}}class D extends d{get _collection(){return this._layerExtension.sublayerExtensions.flatten((e=>e.sublayerExtensions))}_layerExtension;constructor(e){super(),this._layerExtension=e}findById(e){return b("id",e).isNotMissing(),this.find((t=>t.id===e))}findBySublayerId(e){return b("id",e).isNotMissing(),this.find((t=>t._sublayerId===e))}forSublayer(e){return b("sublayer",e).isNotMissing(),this.findBySublayerId(e.id)}emit(e,i){if("change"===e){const s=new t;s.addMany(i.added);const r=s.flatten((e=>e.sublayerExtensions)).toArray(),a=new t;a.addMany(i.removed);const n=a.flatten((e=>e.sublayerExtensions)).toArray(),o=new t;o.addMany(i.moved);const l=o.flatten((e=>e.sublayerExtensions)).toArray();return super.emit(e,{added:r,removed:n,moved:l,target:this})}return super.emit(e,i)}_itemIsInitialized(e){return super._itemIsInitialized(e)&&!!e.sublayer}}let H=class extends A{get _esriLayer(){return this._extension.layer}get _listModePath(){return"layer.listMode"}get _supportsChildren(){return this._extension.supportsSublayers}};H=e([c],H);export{H as LayerExtensionLayerListSettings};function N(e){return"object"==typeof e?e:{property:e}}let R=class extends o{_layerExtension;_layerBindings=new Map;constructor(e){if(super(),this._layerExtension=e,this._bindSettingsToLayerProperties(),e.layer)this._onLayerResolved(e.layer);else{const t=e.watch("layer",(()=>{this._onLayerResolved(e.layer),t.remove()}),!0)}}_getPropertyBindings(){return{}}_getSetting(e,t){if(this._layerBindings.has(e)){const t=N(this._layerBindings.get(e));if(t.hasOwnProperty("value"))return t.value;if(this._layerExtension.layer)return this._layerExtension.layer[t.property]}return super._getSetting(e,t)}_setSetting(e,t){if(this._layerBindings.has(e)){const i=N(this._layerBindings.get(e));if(i.readonly||i.hasOwnProperty("value"))throw new s(ERR_SCHEMA_READ_ONLY);if(this._layerExtension.layer)return void(this._layerExtension.layer[i.property]=t)}super._setSetting(e,t)}_bindSettingsToLayerProperties(){const e=this._getPropertyBindings();for(const t of v(e)){const i=N(e[t]);this._layerBindings.set(t,i),i.hasOwnProperty("value")||this._layerExtension.watch(`layer.${String(i.property)}`,(()=>this.notifyChange(t)),!i.hasOwnProperty("sync")||i.sync)}}_onLayerResolved(e){for(const t of this._layerBindings.keys())this.isModified(t)&&(e[t]=this[t],this.reset(t))}};R=e([c],R);export{R as LayerExtensionSchema};export function _assignLayerExtensions(e,t){return m(e,t,{onNew:(t,i)=>{e.add(t instanceof LayerExtension?t:LayerExtension.create(t),k(t)?void 0:i)},onMatch:(t,i,s,r)=>{i instanceof LayerExtension||t.assignProperties(i),s===r||k(i)||e.reorder(t,r)},onMissing:t=>{(E([t])||L(t)&&0===t.layerExtensions.toArray().length)&&e.remove(t)},equals:(e,t)=>t instanceof LayerExtension?t===e:"solid"===f(e.layer,t.layer)||e.id===t.id})}function B(){return x("geocortex.api.mapping.LayerExtension")}function k(e){return e instanceof LayerExtension?!!e._deferredLayerProperties?.$ref:!g(e.layer)&&!!e.layer?.$ref}let q=class extends R{_setSetting(e,t){if(this._layerBindings.has(e))throw new s(ERR_SCHEMA_READ_ONLY);super._setSetting(e,t)}};q=e([c],q);export{q as LayerExtensionReadOnlySchema};export const ERR_SCHEMA_READ_ONLY="This schema property is read-only.";
|
|
1
|
+
import{__decorate as e}from"tslib";import t from"@arcgis/core/core/Collection";import{ArgumentError as i}from"../ArgumentError.js";import{InvalidOperationError as s}from"../InvalidOperationError.js";import{ItemType as r}from"../ItemType.js";import{FeatureSourceBase as a}from"../data/FeatureSourceBase.js";import{FieldExtension as n}from"../data/FieldExtension.js";import{Schema as l}from"../data/Schema.js";import{layerToJson as o,getLayerJsonType as y,jsonToLayer as h,applyJsonToLayer as p}from"../json/LayerJson.js";import{DefaultArcGISRequestHelper as u}from"../support/ArcGISRequestHelper.js";import{ReadOnlyInitializableCollection as d}from"../support/ReadOnlyInitializableCollection.js";import{serializable as c}from"../support/Serializable.js";import{getEquivalencyTypeForLayers as f,getLayerUrl as _,isLayer as g}from"../utilities/_layers.js";import{checkArg as b}from"../utilities/checkArg.js";import{compare as m}from"../utilities/collection.js";import{load as S}from"../utilities/esri.js";import{isGroupLayerExtension as L}from"../utilities/extensions.js";import{hasMmapLayer as E}from"../utilities/layers.js";import{getLogger as x}from"../utilities/log.js";import{deepClone as w,objectKeys as v}from"../utilities/object.js";import{toPortalItem as M}from"../utilities/portal.js";import{onCollectionPropertyChange as P,watchEach as I}from"../utilities/watch.js";import{_assignSublayerExtensions as C}from"./_SublayerExtension.js";import{ExtensionBaseLayerListSettings as A,fromLayerListMode as z}from"./support/LayerListSettings.js";import{SublayerExtensionCollectionBase as j}from"./support/_SublayerExtensionCollection.js";const T="Invalid type of layer for this type of layer extension.",H="This type of layer does not have features.",V="This type of layer cannot have sublayers.",F=Object.freeze({supportsAdd:!1,supportsUpdate:!1,supportsDelete:!1,supportsEditing:!1,supportsQuery:!1,supportsAttachmentEditing:!1,supportsStandardizedQueries:!1});export class LayerExtension extends a{get layer(){return this._layer}get mapExtension(){return this._mapExtension}get basemapExtension(){return this._basemapExtension}get groundExtension(){return this._groundExtension}get parentLayerExtension(){return this._parentLayerExtension}get hasFeatures(){return!1}get capabilities(){return this._capabilities()}get renderer(){}get visibilityMode(){return this._visibilityMode}set visibilityMode(e){this._visibilityMode=e,"exclusive"===e&&this._ensureAtMostOneChildSublayerVisible()}get sublayerExtensions(){return this._sublayerExtensions}get requestHelper(){return this._requestHelper||(this._requestHelper=new u),this._requestHelper}set requestHelper(e){this._requestHelper=e}get title(){return this.layer?.title??this._deferredLayerProperties?.title??("string"==typeof this._deferredLayerProperties?.$ref?this._deferredLayerProperties?.$ref:this._deferredLayerProperties?.$ref?.title??this._deferredLayerProperties?.$ref?.id)??"Layer"}get supportsSublayers(){return!1}get effectiveMinScale(){return this.layer&&this.layer.minScale||0}get effectiveMaxScale(){return this.layer&&this.layer.maxScale||0}get isEffectivelyVisible(){const e=!!this.layer&&this.layer.visible;return this.parentLayerExtension?this.parentLayerExtension.isEffectivelyVisible&&e:e}get effectiveFullExtent(){return this.layer?this.layer.fullExtent:void 0}get canChangeScale(){return!0}get canChangeOpacity(){return!0}get canChangeLabels(){return!1}get canChangeRenderer(){return!1}get canChangeDefinitionExpression(){return!1}get initialVisibility(){return this._initialVisibility??this.layer?.visible??!1}get _layerId(){return this.layer?.id??this._deferredLayerProperties?.$ref?.id}get _layerSupportsHideChildren(){return this.supportsSublayers}get _sublayers(){if(this.supportsSublayers)return this.layer?this.layer.sublayers:void 0}static factory;get dynamicallyAddedLayer(){return this._dynamicallyAddedLayer}set dynamicallyAddedLayer(e){this._dynamicallyAddedLayer=e}tpkSource;layerListSettings;allSublayerExtensions;get sublayersAreReadOnly(){return!0}_itemType=r.LAYER_EXTENSION;_watchHandles=[];_layerWatchHandles=[];_mapExtension;_basemapExtension;_groundExtension;_parentLayerExtension;_sublayerExtensions;_layer;_dynamicallyAddedLayer=!1;_deferredLayerProperties;_requestHelper;_initialVisibility;_visibilityMode="independent";_portalItem;constructor(e){super(e);const t={...this.getDefaults(),...e};b("properties.layer",t.layer).isNotMissing();const{layer:i}=t;let s;if(i?.hasOwnProperty("listMode")&&(s=z(i.listMode)),this.layerListSettings=this._createLayerListSettings({...s,...t.layerListSettings}),g(i))b("properties.layer",i).satisfies((e=>this._isSupportedLayer(e)),T),this._setLayer(i);else if(i){if(i.$portalItem){const e=i.$portalItem;this._portalItem=M(e)}this._deferredLayerProperties=i}this._sublayerExtensions=this._createSublayerExtensionCollection(),this.allSublayerExtensions=new $(this),this.watch("parentLayerExtension.isEffectivelyVisible",(()=>this.notifyChange("isEffectivelyVisible"))),this.watch("layer.sublayers",(()=>this.notifyChange("_sublayers")))}static create(e){if(!LayerExtension.factory)throw new s("Cannot create layer extension: no layer extension factory has been registered.");return LayerExtension.factory.create(e)}static async fromPortalItem(e,t){b("portalItemLike",e).isNotMissing();const s=t??{};b("layerExtensionProperties.layer",s.layer).satisfies((e=>!g(e)));const r={...s.layer};b("layerExtensionProperties.layer.$ref",r.$ref).satisfies((e=>null==e));const a=new u,n=M(e);let l;await S(n);const o=n.typeKeywords??"";if("Map Service"===n.type)l=o.includes("Tiled")||o.includes("Hosted Service")?"ArcGISTiledMapServiceLayer":"ArcGISMapServiceLayer";else if("Feature Service"===n.type)l="ArcGISFeatureLayer";else if("Image Service"===n.type){const e=await LayerExtension._getLayerData(n.url,a);e.cacheType?"Map"===e.cacheType?l="ArcGISTiledImageServiceLayer":("Elevation"===e.cacheType||o.includes("Elevation 3D Layer"))&&(l="ArcGISTiledElevationServiceLayer"):l=e.singleFusedMapCache||e.tileInfo||o.includes("Hosted Service")?"ArcGISTiledImageServiceLayer":"ArcGISImageServiceLayer"}else if("CSV"===n.type)l="CSV";else if("KML"===n.type)l="KML";else if("Scene Service"===n.type)o.includes("3DObject")||o.includes("Point")?l="ArcGISSceneServiceLayer":o.includes("IntegratedMesh")?l="IntegratedMeshLayer":o.includes("PointCloud")?l="PointCloudLayer":o.includes("Building")&&(l="BuildingSceneLayer");else if("Stream Service"===n.type)l="ArcGISStreamLayer";else if("Vector Tile Service"===n.type)l="VectorTileLayer";else if("Feature Collection"===n.type){l="ArcGISFeatureLayer";const e=await n.fetchData();r.featureCollection=e}else if("WFS"===n.type){l="WFS";const e=await n.fetchData();Object.assign(r,e)}else if("WMTS"===n.type){l="WebTiledLayer";const e=await n.fetchData();Object.assign(r,e)}else if("WMS"===n.type){l="WMS";const e=await n.fetchData();Object.assign(r,e)}if(!l)throw new i("portalItem","Could not determine correct type of LayerExtension to create from portal item");if(r.layerType&&r.layerType!==l)throw new i("layerExtensionProperties.layer.layerType","Layer type defined in layer properties does not match layer type from portal item");return r.layerType=l,r.$portalItem=n,s.layer=r,LayerExtension.create(s)}static async _getLayerData(e,t){const i=await t.request(e,{query:{f:"json"}});if(!i?.data)throw new Error(`Response to request for url ${e} was invalid.`);return i.data}getFeatures(e,t){if(!this.hasFeatures)throw new s(H);return super.getFeatures(e,t)}getFullExtent(){return this.effectiveFullExtent}async addFeatures(e,t){if(b("features",e).isNotMissing(),!this.hasFeatures)throw new s(H);await super.addFeatures(e,t)}async updateFeatures(e,t){if(b("features",e).isNotMissing(),!this.hasFeatures)throw new s(H);await super.updateFeatures(e,t)}async deleteFeatures(e,t){if(b("features",e).isNotMissing(),!this.hasFeatures)throw new s(H);await super.deleteFeatures(e,t)}async _createBackingLayer(){this._portalItem||this.layer||this._deferredLayerProperties?.$ref?!this.layer&&this._portalItem&&this._setLayer(await this._createLayer(this.getDefaults().layer)):(this._setLayer(await this._createLayer(this._deferredLayerProperties)),b("properties.layer",this._layer).satisfies((e=>this._isSupportedLayer(e)),T),this._deferredLayerProperties=void 0)}_setMapExtension(e){const t=this.mapExtension;this._mapExtension=e,t&&this.featureSettings.formatSettings.parent===t.formatSettings&&(this.featureSettings.formatSettings.parent=void 0),e&&(this.featureSettings.formatSettings.parent||(this.featureSettings.formatSettings.parent=e.formatSettings)),this._resolveLayer(),this.notifyChange("mapExtension")}_setBasemapExtension(e){this._basemapExtension=e,this._resolveLayer(),e&&(this.taskSettings.parent=e.taskSettings),this.notifyChange("basemapExtension")}_setGroundExtension(e){this._groundExtension=e,this._resolveLayer(),e&&(this.taskSettings.parent=e.taskSettings),this.notifyChange("groundExtension")}_setParentLayerExtension(e){const t=this._parentLayerExtension;this._parentLayerExtension=e,t&&(this.featureSettings.formatSettings.parent===t.featureSettings.formatSettings&&(this.featureSettings.formatSettings.parent=this.mapExtension?this.mapExtension.formatSettings:void 0),this.taskSettings.parent===t.taskSettings&&(this.taskSettings.parent=void 0)),e&&((!this.featureSettings.formatSettings.parent||this.mapExtension&&this.featureSettings.formatSettings.parent===this.mapExtension.formatSettings)&&(this.featureSettings.formatSettings.parent=e.featureSettings.formatSettings),this.taskSettings.parent||(this.taskSettings.parent=e.taskSettings)),this._resolveLayer(),this.notifyChange("parentLayerExtension")}_resolveLayer(e){if(this.layer||!this._deferredLayerProperties)return;const t=e??this.basemapExtension?.basemap?.baseLayers??this.groundExtension?.ground?.layers??this.parentLayerExtension?.layer?.layers??this.mapExtension?.map.layers;if(!t)return;const i=[];let s;for(const e of t){const t=f(e,this._deferredLayerProperties);if("none"!==t){if("solid"===t){s=e;break}i.push(e)}}s||1!==i.length||(s=i[0]),s&&this._isSupportedLayer(s)&&(this._setLayer(s),this._deferredLayerProperties.$portalItem&&B().warn("LayerExtension defined with both $ref and $portalItem. Ignoring $portalItem."))}async _switchLayer(e){if(e===this.layer)return;b("newLayer",e).isNotMissing().satisfies((e=>this._isSupportedLayer(e)),T),this.isInitialized&&await S(e);const t=new Map;if(this._sublayers)for(const e of this._sublayers.toArray())t.set(e.id,this.sublayerExtensions.forSublayer(e));e.visible=this.layer.visible,e.opacity=this.layer.opacity,e.listMode=this.layer.listMode,e.hasOwnProperty("labelsVisible")&&this.layer.hasOwnProperty("labelsVisible")&&(e.labelsVisible=this.layer.labelsVisible);const i=this.schema.fieldExtensions.toArray();this._setLayer(e),i.forEach((e=>{const t=this.schema.fields.find((t=>n.matchesRef(e,{$ref:t.name})));t&&e._switchField(t)}));const s=[];if(this._sublayers){const e=this._sublayers.filter((e=>t.has(e.id))).toArray();s.push(...e.map((async e=>{const i=t.get(e.id);await i._switchSublayer(e),this._sublayerExtensions._register(i)})))}this.isInitialized&&s.push(this._initializeChildren()),await Promise.all(s)}_getProjectWebmapJSON(){if(!this.layer)return;let e=o(this.layer);if(!this.dynamicallyAddedLayer){const{id:t,title:i,layerType:s,visibility:r,opacity:a}=e;e={id:t,title:i,layerType:s,visibility:r,opacity:a}}return e}_onSublayerAddedPostInitialize=async e=>{try{await e.initialize()}catch(t){B().error({message:`Error occurred while initializing sublayer extension for sublayer '${e.title??e.sublayer.id??e.id}'.`,error:t})}};async _onDestroy(){this._watchHandles.forEach((e=>e?.remove())),this._layerWatchHandles.forEach((e=>e?.remove())),await Promise.all(this.sublayerExtensions.toArray().map((e=>e.destroy()))),await super._onDestroy()}_getSerializableProperties(){return{...super._getSerializableProperties(),iconUrl:{serializeModes:["initial","project"],serialize:e=>"project"!==e||this.dynamicallyAddedLayer?this.iconUrl:this.getDefault("iconUrl")},visibilityMode:{serializeModes:["initial","project"],serialize:e=>"project"!==e||this.dynamicallyAddedLayer?this.visibilityMode:this.getDefault("visibilityMode"),default:"independent"},tpkSource:{serializeModes:["initial"]},layerListSettings:{serializeModes:["initial","project"],serialize:e=>"project"!==e||this.dynamicallyAddedLayer?this.layerListSettings:this.getDefault("layerListSettings")},sublayerExtensions:{serializeModes:["initial","project"],serialize:e=>this.sublayerExtensions.map((e=>e.toItemUri())).toArray(),deserialize:e=>{C(this.sublayerExtensions,e,(e=>this._createSublayerExtension(e)))}},layer:{serializeModes:["initial","project"],serialize:e=>{if(this.layer){if((this._mapExtension||this._parentLayerExtension||this._basemapExtension||this._groundExtension)&&(this._layer.id||this._layer.title)){const e=y(this._layer),t=this._getSerializableRefLayerProperties(),i=_(this._layer),s=i?{url:i}:{};return{$ref:{id:this._layer.id,title:this._layer.title,subtype:this._getSerializableLayerType(),...s},layerType:e,...t}}return o(this.layer)}return this._deferredLayerProperties?w(this._deferredLayerProperties):void 0},isDefault:()=>{throw new Error("Missing implementation for _getSerializableProperties() > layer > default. Subclasses of LayerExtension must implement this.")},deserialize:e=>{if(g(e)){if(e!==this.layer)throw new Error("Property 'layer' is read-only.")}else if(e){if(this._layer)return this._applyLayerProperties(e,this.layer);this._deferredLayerProperties&&(this._deferredLayerProperties={...this._deferredLayerProperties,...e})}}},dynamicallyAddedLayer:{serializeModes:["project"],default:!1},requestHelper:{serialize:!1}}}_getSerializableLayerType(){}_getSerializableRefLayerProperties(){return{}}_createSublayerExtension(e){if(!this.supportsSublayers)throw new s(V);throw new Error("Missing implementation for _createSublayerExtension(). Subclasses of LayerExtension that support sublayers must implement this.")}async _onInitialize(){if(await super._onInitialize(),await this._createBackingLayer(),this._portalItem&&(await S(this._portalItem),await this._applyPortalItemProperties(this._portalItem),this.layer.title=this._portalItem.title,this.layer.portalItem=this._portalItem,this.iconUrl||(this.iconUrl=this._portalItem.thumbnailUrl),await this._applyLayerProperties(this._deferredLayerProperties,this.layer),this._deferredLayerProperties=void 0),this._resolveLayer(),!this.layer){const e=this._deferredLayerProperties.$ref;throw this._mapExtension||this._parentLayerExtension||this._basemapExtension||this._groundExtension?new s(`No layer found matching reference "${"string"==typeof e?e:JSON.stringify(e)}".`):new s("Cannot resolve layer reference: missing parent.")}this._deferredLayerProperties&&(await this._applyLayerProperties(this._deferredLayerProperties,this.layer),this._deferredLayerProperties=void 0),await this._initializeLayer(),await S(this.layer),this.supportsSublayers&&!this.layer.sublayers&&this.layer._set("sublayers",new t),this._initialVisibility=this.layer.visible,this._sublayerExtensions.onParentInitialized()}async _postInitialize(){await super._postInitialize(),this.layerListSettings.onLayerExtensionInitialized(),this.supportsSublayers&&this._watchHandles.push(P(this,"layer.sublayers",(async e=>{const t=(e.added??[]).map((e=>this.sublayerExtensions.forSublayer(e)));await Promise.all(t.map(this._onSublayerAddedPostInitialize))})))}_applyPortalItemProperties(e){throw new s("Cannot use this type of layer extension with a PortalItem.")}async _initializeLayer(){}_createLayerListSettings(e){return new D(e,this)}_createSublayerExtensionCollection(){return new O(this)}_capabilities(){return F}*_initializableChildCollections(){yield*super._initializableChildCollections(),yield this.sublayerExtensions}async _createLayer(e){return h(e)}_applyLayerProperties(e,t){b("layerJson",e).isNotMissing();const i=e.layerType||e.type;return b("layerJson.layerType",i).satisfies((e=>!e||e===this.getDefault("layer")?.layerType)),b("layer",t).isNotMissing().satisfies((e=>this._isSupportedLayer(e))),p(e,t)}_setLayer(e){if(this._layer=e,this._layerWatchHandles.forEach((e=>e.remove())),this._layerWatchHandles.length=0,this._layerWatchHandles.push(e.watch("visible",this._onVisibleChanged),this.layer.watch("minScale",(()=>this.notifyChange("effectiveMinScale"))),this.layer.watch("maxScale",(()=>this.notifyChange("effectiveMaxScale"))),this.layer.watch("title",(()=>this.notifyChange("title")))),this.supportsSublayers)if(this._sublayers)this._setupSublayersHandles();else{const t=e.watch("sublayers",(()=>{this._setupSublayersHandles(),t.remove()}),!0);this._layerWatchHandles.push(t)}this.notifyChange("layer"),this.notifyChange("title"),this.notifyChange("effectiveMinScale"),this.notifyChange("effectiveMaxScale"),this.notifyChange("isEffectivelyVisible")}_setupSublayersHandles(){this._layerWatchHandles.push(this._sublayers.on("change",this._onSublayersChange),I(this._sublayers,"visible",this._onSublayersSublayerVisibleChanged))}_onVisibleChanged=e=>{if("inherited"===this.visibilityMode&&this.supportsSublayers&&this._sublayers)for(const t of this._sublayers.toArray())t.visible=e;this.notifyChange("isEffectivelyVisible")};_onSublayersSublayerVisibleChanged=(e,t,i,s)=>{e&&"exclusive"===this.visibilityMode&&this._ensureAChildSublayerVisible(s)};_onSublayersChange=e=>{e.added?.length&&"exclusive"===this.visibilityMode&&this._ensureAChildSublayerVisible(e.added[e.added.length-1])};_ensureAChildSublayerVisible(e){for(const t of this._sublayers.toArray())t!==e&&(t.visible=!1)}_ensureAtMostOneChildSublayerVisible(){this.layer&&this._sublayers&&this._ensureAChildSublayerVisible(this._sublayers.find((e=>e.visible)))}}class O extends j{constructor(e){super(e,"_sublayers"),this._layerExtension=e}add(e,t){if(b("sublayerX",e).isNotMissing(),!this._layerExtension.supportsSublayers)throw new s(V);const i=e.sublayer?e.sublayer.layer:void 0;return i&&i!==this._layerExtension.layer&&i.sublayers.remove(e.sublayer),super.add(e,t)}}class $ extends d{get _collection(){return this._layerExtension.sublayerExtensions.flatten((e=>e.sublayerExtensions))}_layerExtension;constructor(e){super(),this._layerExtension=e}findById(e){return b("id",e).isNotMissing(),this.find((t=>t.id===e))}findBySublayerId(e){return b("id",e).isNotMissing(),this.find((t=>t._sublayerId===e))}forSublayer(e){return b("sublayer",e).isNotMissing(),this.findBySublayerId(e.id)}emit(e,i){if("change"===e){const s=new t;s.addMany(i.added);const r=s.flatten((e=>e.sublayerExtensions)).toArray(),a=new t;a.addMany(i.removed);const n=a.flatten((e=>e.sublayerExtensions)).toArray(),l=new t;l.addMany(i.moved);const o=l.flatten((e=>e.sublayerExtensions)).toArray();return super.emit(e,{added:r,removed:n,moved:o,target:this})}return super.emit(e,i)}_itemIsInitialized(e){return super._itemIsInitialized(e)&&!!e.sublayer}}let D=class extends A{get _esriLayer(){return this._extension.layer}get _listModePath(){return"layer.listMode"}get _supportsChildren(){return this._extension.supportsSublayers}};D=e([c],D);export{D as LayerExtensionLayerListSettings};function N(e){return"object"==typeof e?e:{property:e}}let R=class extends l{_layerExtension;_layerBindings=new Map;constructor(e){if(super(),this._layerExtension=e,this._bindSettingsToLayerProperties(),e.layer)this._onLayerResolved(e.layer);else{const t=e.watch("layer",(()=>{this._onLayerResolved(e.layer),t.remove()}),!0)}}_getPropertyBindings(){return{}}_getSetting(e,t){if(this._layerBindings.has(e)){const t=N(this._layerBindings.get(e));if(t.hasOwnProperty("value"))return t.value;if(this._layerExtension.layer)return this._layerExtension.layer[t.property]}return super._getSetting(e,t)}_setSetting(e,t){if(this._layerBindings.has(e)){const i=N(this._layerBindings.get(e));if(i.readonly||i.hasOwnProperty("value"))throw new s(ERR_SCHEMA_READ_ONLY);if(this._layerExtension.layer)return void(this._layerExtension.layer[i.property]=t)}super._setSetting(e,t)}_bindSettingsToLayerProperties(){const e=this._getPropertyBindings();for(const t of v(e)){const i=N(e[t]);this._layerBindings.set(t,i),i.hasOwnProperty("value")||this._layerExtension.watch(`layer.${String(i.property)}`,(()=>this.notifyChange(t)),!i.hasOwnProperty("sync")||i.sync)}}_onLayerResolved(e){for(const t of this._layerBindings.keys())this.isModified(t)&&(e[t]=this[t],this.reset(t))}};R=e([c],R);export{R as LayerExtensionSchema};export function _assignLayerExtensions(e,t){return m(e,t,{onNew:(t,i)=>{e.add(t instanceof LayerExtension?t:LayerExtension.create(t),k(t)?void 0:i)},onMatch:(t,i,s,r)=>{i instanceof LayerExtension||t.assignProperties(i),s===r||k(i)||e.reorder(t,r)},onMissing:t=>{(E([t])||L(t)&&0===t.layerExtensions.toArray().length)&&e.remove(t)},equals:(e,t)=>t instanceof LayerExtension?t===e:"solid"===f(e.layer,t.layer)||e.id===t.id})}function B(){return x("geocortex.api.mapping.LayerExtension")}function k(e){return e instanceof LayerExtension?!!e._deferredLayerProperties?.$ref:!g(e.layer)&&!!e.layer?.$ref}let W=class extends R{_setSetting(e,t){if(this._layerBindings.has(e))throw new s(ERR_SCHEMA_READ_ONLY);super._setSetting(e,t)}};W=e([c],W);export{W as LayerExtensionReadOnlySchema};export const ERR_SCHEMA_READ_ONLY="This schema property is read-only.";
|
package/package.json
CHANGED
package/version.d.ts
CHANGED
package/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version="44.
|
|
1
|
+
export const version="44.2.0";
|