UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) • 10.1 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{_ as e}from"../chunks/tslib.es6.js";import t from"../request.js";import r from"../core/Collection.js";import i from"../core/Error.js";import{getOrCreateMapValue as o}from"../core/MapUtils.js";import{MultiOriginJSONMixin as s}from"../core/MultiOriginJSONSupport.js";import{throwIfAbortError as a}from"../core/promiseUtils.js";import{urlToObject as n,join as l,hasSamePortal as p}from"../core/urlUtils.js";import{property as d}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/Logger.js";import"../core/RandomLCG.js";import{subclass as y}from"../core/accessorSupport/decorators/subclass.js";import m from"./Layer.js";import u from"./catalog/CatalogDynamicGroupLayer.js";import c from"./catalog/CatalogFootprintLayer.js";import h from"./graphics/sources/FeatureLayerSource.js";import{APIKeyMixin as f}from"./mixins/APIKeyMixin.js";import{ArcGISService as g}from"./mixins/ArcGISService.js";import{BlendLayer as F}from"./mixins/BlendLayer.js";import{CustomParametersMixin as j}from"./mixins/CustomParametersMixin.js";import{DisplayFilteredLayer as w}from"./mixins/DisplayFilteredLayer.js";import{EditBusLayer as L}from"./mixins/EditBusLayer.js";import{FeatureLayerBase as v}from"./mixins/FeatureLayerBase.js";import{OperationalLayer as S}from"./mixins/OperationalLayer.js";import{OrderedLayer as x}from"./mixins/OrderedLayer.js";import{PortalLayer as I}from"./mixins/PortalLayer.js";import{RefreshableLayer as O}from"./mixins/RefreshableLayer.js";import{ScaleRangeLayer as b}from"./mixins/ScaleRangeLayer.js";import{TemporalLayer as E}from"./mixins/TemporalLayer.js";import{legendEnabled as T,id as _}from"./support/commonProperties.js";import{ensureLayerCredential as P,applyEdits as C,getFeatureType as G,hasDataChanged as U}from"./support/featureLayerUtils.js";import q from"./support/FeatureType.js";import{defineFieldProperties as A}from"./support/fieldProperties.js";import{serviceSupportsSpatialReference as D}from"./support/versionUtils.js";import Q from"../portal/Portal.js";import N from"../portal/PortalItem.js";import{normalizeArcGISOnlineOrgDomain as M}from"../portal/support/urlUtils.js";import R from"../rest/support/Query.js";const B=A();function V(e){return"object"==typeof e&&null!=e&&"itemId"in e&&"portalUrl"in e}function k(e){return"object"==typeof e&&null!=e&&"url"in e}function J(e){if(null==e)return!0;const t=Object.keys(e);return!t.length||1===t.length&&"id"===t[0]}function K(e,t,r,i){const o=e.write({},i);J(o)||(t[r]=o)}let H=class extends(w(v(L(F(x(E(b(O(g(S(I(s(j(f(m))))))))))))))){constructor(e){super(e),this.legendEnabled=!0,this._portals=new Map,this._layerToFootprint=new WeakMap,this.drawOrderField="cd_draworder",this.dynamicGroupLayer=new u({parent:this}),this.elevationInfo=null,this.fields=null,this.fieldsIndex=null,this.floorInfo=null,this.footprintLayer=new c({parent:this}),this.itemNameField="cd_itemname",this.itemSourceField="cd_itemsource",this.itemTypeField="cd_itemtype",this.layers=new r([this.dynamicGroupLayer,this.footprintLayer]),this.maxScaleField="cd_maxscale",this.minScaleField="cd_minscale",this.orderBy=null,this.outFields=null,this.supportedSourceTypes=new Set(["Catalog Layer"]),this.source=new h({layer:this,supportedSourceTypes:this.supportedSourceTypes}),this.type="catalog",this.typeIdField=null,this.types=null}load(e){const t=null!=e?e.signal:null,r=this.loadFromPortal({supportedTypes:["Feature Service"]},e).catch(a).then((async()=>{const{url:e,source:r,portalItem:o}=this;if(!e)throw new i("catalog-layer:missing-url","Catalog layer must be created with a url");if(null==this.layerId){const r=await this._fetchFirstValidLayerId(t);if(null==r)throw new i("catalog-layer:missing-layerId","There is no Catalog Layer in the service",{service:e});this.layerId=r}await r.load({signal:t});const{sourceJSON:s}=r;s&&(this.sourceJSON=s,this.read(s,{origin:"service",portalItem:o,portal:o?.portal,url:this.parsedUrl}))})).then((()=>{const e=[this.itemNameField,this.itemSourceField,this.itemTypeField,this.minScaleField,this.maxScaleField],t=e.filter((e=>!this.fieldsIndex.has(e)));if(t.length)throw new i("catalog-layer:missing-fields","There are missing fields to operate properly",{requiredFields:e,missingFields:t})})).then((()=>P(this,"load",e)));return this.addResolvingPromise(r),Promise.resolve(this)}destroy(){this.footprintLayer.destroy(),this.dynamicGroupLayer.destroy();for(const e of this._portals.values())e.destroy();this._portals.clear()}get createQueryVersion(){return this.commitProperty("definitionExpression"),this.commitProperty("timeExtent"),this.commitProperty("timeOffset"),this.commitProperty("geometryType"),this.commitProperty("capabilities"),(this._get("createQueryVersion")??0)+1}get editingEnabled(){return this.loaded&&null!=this.capabilities&&this.capabilities.operations.supportsEditing&&this.userHasEditingPrivileges}get effectiveEditingEnabled(){return!1}get parsedUrl(){const e=n(this.url);return null!=e&&null!=this.layerId&&(e.path=l(e.path,this.layerId.toString())),e}async applyEdits(e,t){return C(this,e,t)}on(e,t){return super.on(e,t)}async createLayerFromFootprint(e){const t=await this._createLayer(e);return this._configureLayer(t,e),this._layerToFootprint.set(t,e),t}createFootprintFromLayer(e){return this._layerToFootprint.get(e)?.clone()}createQuery(){const e=new R,t=this.capabilities?.query;e.returnGeometry=!0,t&&(e.compactGeometryEnabled=t.supportsCompactGeometry,e.defaultSpatialReferenceEnabled=t.supportsDefaultSpatialReference),e.outFields=["*"];const{timeOffset:r,timeExtent:i}=this;return e.timeExtent=null!=r&&null!=i?i.offset(-r.value,r.unit):i||null,e.where=this.definitionExpression||"1=1",e}getFeatureType(e){return G(this.types,this.typeIdField,e)}getFieldDomain(e,t){const r=t?.feature,i=this.getFeatureType(r);if(i){const t=i.domains&&i.domains[e];if(t&&"inherited"!==t.type)return t}return this.getField(e)?.domain}async hasDataChanged(){return U(this)}async queryFeatures(e,t){const r=await this.load(),i=await r.source.queryFeatures(R.from(e)??r.createQuery(),t);if(i?.features)for(const o of i.features)o.layer=o.sourceLayer=r.footprintLayer;return i}async queryObjectIds(e,t){return(await this.load()).source.queryObjectIds(R.from(e)??this.createQuery(),t)}async queryFeatureCount(e,t){return(await this.load()).source.queryFeatureCount(R.from(e)??this.createQuery(),t)}async queryExtent(e,t){return(await this.load()).source.queryExtent(R.from(e)??this.createQuery(),t)}serviceSupportsSpatialReference(e){return this.loaded&&D(this,e)}read(e,t){if(super.read(e,t),e){const{footprintLayer:r,dynamicGroupLayer:i}=e;r&&this.footprintLayer.read(r,t),i&&this.dynamicGroupLayer.read(i,t)}}async _fetchFirstValidLayerId(e){const{data:r}=await t(this.url,{query:{f:"json",...this.customParameters,token:this.apiKey},responseType:"json",signal:e});if(Array.isArray(r?.layers))return r.layers.find((({type:e})=>this.supportedSourceTypes.has(e)))?.id}async _createLayer(e){const t=e.getAttribute(this.itemSourceField);if(!t)throw new i("catalog-layer:item-source-missing",`The footprint is missing the "${this.itemSourceField}" attribute`);const r=JSON.parse(t);if(V(r)){const{itemId:e,portalUrl:t}=r,i=M(t),s=this.portalItem?.portal,a=Q.getDefault();let n,l=!0;s&&p(t,s.url)?n=s:p(t,a.url)?n=a:(n=o(this._portals,i,(()=>new Q({url:i}))),l=!1);const d=await m.fromPortalItem(new N({id:e,portal:n}));return l||await W(d),d}if(k(r))return m.fromArcGISServerUrl({url:r.url});const{default:s}=await import("./UnsupportedLayer.js");return new s}_configureLayer(e,t){const r=t.getAttribute(this.itemNameField);r&&(e.title=r);const i=t.getAttribute(this.maxScaleField);null!=i&&"maxScale"in e&&(e.maxScale=i);const o=t.getAttribute(this.minScaleField);null!=o&&"minScale"in e&&(e.minScale=o)}};async function W(e){if("portalItem"in e&&e.portalItem){try{await e.load()}catch{}e.portalItem=null,"group"===e.type&&await Promise.allSettled([...e.layers.map((e=>W(e))),...e.tables.map((e=>W(e)))])}}e([d(T)],H.prototype,"legendEnabled",void 0),e([d({readOnly:!0})],H.prototype,"createQueryVersion",null),e([d({readOnly:!0})],H.prototype,"drawOrderField",void 0),e([d({type:u,readOnly:!0,json:{read:!1,write:{ignoreOrigin:!0,writer:K}}})],H.prototype,"dynamicGroupLayer",void 0),e([d({readOnly:!0})],H.prototype,"editingEnabled",null),e([d({readOnly:!0})],H.prototype,"effectiveEditingEnabled",null),e([d({json:{origins:{"web-scene":{name:"layerDefinition.elevationInfo",read:!1,write:!1}}}})],H.prototype,"elevationInfo",void 0),e([d({...B.fields,readOnly:!0,json:{origins:{service:{read:!0}},read:!1}})],H.prototype,"fields",void 0),e([d(B.fieldsIndex)],H.prototype,"fieldsIndex",void 0),e([d({json:{origins:{"web-scene":{name:"layerDefinition.floorInfo",read:!1,write:!1}}}})],H.prototype,"floorInfo",void 0),e([d({type:c,readOnly:!0,json:{read:!1,write:{ignoreOrigin:!0,writer:K}}})],H.prototype,"footprintLayer",void 0),e([d(_)],H.prototype,"id",void 0),e([d({readOnly:!0})],H.prototype,"itemNameField",void 0),e([d({readOnly:!0})],H.prototype,"itemSourceField",void 0),e([d({readOnly:!0})],H.prototype,"itemTypeField",void 0),e([d({readOnly:!0})],H.prototype,"layers",void 0),e([d({type:["show","hide","hide-children"]})],H.prototype,"listMode",void 0),e([d({readOnly:!0})],H.prototype,"maxScaleField",void 0),e([d({readOnly:!0})],H.prototype,"minScaleField",void 0),e([d({value:"CatalogLayer",type:["CatalogLayer"]})],H.prototype,"operationalLayerType",void 0),e([d({json:{origins:{"web-scene":{name:"layerDefinition.orderBy",write:!0,read:!0}}}})],H.prototype,"orderBy",void 0),e([d(B.outFields)],H.prototype,"outFields",void 0),e([d({readOnly:!0})],H.prototype,"parsedUrl",null),e([d({readOnly:!0})],H.prototype,"source",void 0),e([d({json:{read:!1}})],H.prototype,"type",void 0),e([d({type:String})],H.prototype,"typeIdField",void 0),e([d({type:[q]})],H.prototype,"types",void 0),H=e([y("esri.layers.CatalogLayer")],H);const $=H;export{$ as default};