UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) • 9.99 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";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{MultiOriginJSONSupportMixin as s}from"../core/MultiOriginJSONSupport.js";import{throwIfAbortError as a}from"../core/promiseUtils.js";import{hasSamePortal as n}from"../core/urlUtils.js";import{property as l,subclass as p}from"../core/accessorSupport/decorators.js";import y from"./Layer.js";import d from"./catalog/CatalogDynamicGroupLayer.js";import u from"./catalog/CatalogFootprintLayer.js";import m from"./graphics/sources/FeatureLayerSource.js";import{APIKeyMixin as c}from"./mixins/APIKeyMixin.js";import{ArcGISService as f}from"./mixins/ArcGISService.js";import{BlendLayer as h}from"./mixins/BlendLayer.js";import{CustomParametersMixin as g}from"./mixins/CustomParametersMixin.js";import{DisplayFilteredLayer as F}from"./mixins/DisplayFilteredLayer.js";import{EditBusLayer as w}from"./mixins/EditBusLayer.js";import{FeatureLayerBase as j}from"./mixins/FeatureLayerBase.js";import{OperationalLayer as L}from"./mixins/OperationalLayer.js";import{OrderedLayer as v}from"./mixins/OrderedLayer.js";import{PortalLayer as S}from"./mixins/PortalLayer.js";import{RefreshableLayer as x}from"./mixins/RefreshableLayer.js";import{ScaleRangeLayer as b}from"./mixins/ScaleRangeLayer.js";import{TemporalLayer as I}from"./mixins/TemporalLayer.js";import{legendEnabled as O,id as E}from"./support/commonProperties.js";import{ensureLayerCredential as T,applyEdits as P,getFeatureType as _,hasDataChanged as C,validateBinsQuery as q}from"./support/featureLayerUtils.js";import A from"./support/FeatureType.js";import{defineFieldProperties as G}from"./support/fieldProperties.js";import{serviceSupportsSpatialReference as U}from"./support/versionUtils.js";import Q from"../portal/Portal.js";import B from"../portal/PortalItem.js";import{normalizeArcGISOnlineOrgDomain as D}from"../portal/support/urlUtils.js";import N from"../rest/support/Query.js";const M=G();function R(e){return"object"==typeof e&&null!=e&&"itemId"in e&&"portalUrl"in e}function V(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(F(j(w(h(v(I(b(x(f(L(S(s(g(c(y))))))))))))))){constructor(e){super(e),this.legendEnabled=!0,this._portals=new Map,this._layerToFootprint=new WeakMap,this.drawOrderField="cd_draworder",this.dynamicGroupLayer=new d({parent:this}),this.elevationInfo=null,this.fields=null,this.fieldsIndex=null,this.floorInfo=null,this.footprintLayer=new u({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 m({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(()=>T(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}async applyEdits(e,t){return P(this,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 N,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 _(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 C(this)}async queryFeatures(e,t){const r=await this.load(),i=await r.source.queryFeatures(N.from(e)??r.createQuery(),t),o=r.footprintLayer.graphicOrigin;if(i?.features)for(const s of i.features)s.layer=s.sourceLayer=r.footprintLayer,s.origin=o;return i}async queryObjectIds(e,t){return(await this.load()).source.queryObjectIds(N.from(e)??this.createQuery(),t)}async queryFeatureCount(e,t){return(await this.load()).source.queryFeatureCount(N.from(e)??this.createQuery(),t)}async queryExtent(e,t){return(await this.load()).source.queryExtent(N.from(e)??this.createQuery(),t)}serviceSupportsSpatialReference(e){return this.loaded&&U(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 queryAttributeBins(e,t){const{source:r,capabilities:i}=await this.load();q(e,i,"CatalogLayer");const o=await import("../rest/support/AttributeBinsQuery.js"),s=await r.queryAttributeBins(o.default.from(e),t);if(s.features)for(const a of s.features)a.layer=a.sourceLayer=this.footprintLayer;return s}async _fetchFirstValidLayerId(e){const{data:r}=await t(this.url,{query:{f:"json",...this.customParameters,token:this.apiKey},responseType:"json",signal:e});if(this.applyPreferredHost(r),Array.isArray(r?.layers))return r.layers.find(({type:e})=>!!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(R(r)){const{itemId:e,portalUrl:t}=r,i=D(t),s=this.portalItem?.portal,a=Q.getDefault();let l,p=!0;s&&n(t,s.url)?l=s:n(t,a.url)?l=a:(l=o(this._portals,i,()=>new Q({url:i})),p=!1);const d=await y.fromPortalItem(new B({id:e,portal:l}));return p||await K(d),d}if(V(r))return y.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 K(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=>K(e)),...e.tables.map(e=>K(e))])}}e([l(O)],H.prototype,"legendEnabled",void 0),e([l({readOnly:!0})],H.prototype,"createQueryVersion",null),e([l({readOnly:!0})],H.prototype,"drawOrderField",void 0),e([l({type:d,readOnly:!0,json:{read:!1,write:{ignoreOrigin:!0,writer:k}}})],H.prototype,"dynamicGroupLayer",void 0),e([l({readOnly:!0})],H.prototype,"editingEnabled",null),e([l({readOnly:!0})],H.prototype,"effectiveEditingEnabled",null),e([l({json:{origins:{"web-scene":{name:"layerDefinition.elevationInfo",read:!1,write:!1}}}})],H.prototype,"elevationInfo",void 0),e([l({...M.fields,readOnly:!0,json:{origins:{service:{read:!0}},read:!1}})],H.prototype,"fields",void 0),e([l(M.fieldsIndex)],H.prototype,"fieldsIndex",void 0),e([l({json:{origins:{"web-scene":{name:"layerDefinition.floorInfo",read:!1,write:!1}}}})],H.prototype,"floorInfo",void 0),e([l({type:u,readOnly:!0,json:{read:!1,write:{ignoreOrigin:!0,writer:k}}})],H.prototype,"footprintLayer",void 0),e([l(E)],H.prototype,"id",void 0),e([l({readOnly:!0})],H.prototype,"itemNameField",void 0),e([l({readOnly:!0})],H.prototype,"itemSourceField",void 0),e([l({readOnly:!0})],H.prototype,"itemTypeField",void 0),e([l({readOnly:!0})],H.prototype,"layers",void 0),e([l({type:["show","hide","hide-children"]})],H.prototype,"listMode",void 0),e([l({readOnly:!0})],H.prototype,"maxScaleField",void 0),e([l({readOnly:!0})],H.prototype,"minScaleField",void 0),e([l({value:"CatalogLayer",type:["CatalogLayer"]})],H.prototype,"operationalLayerType",void 0),e([l({json:{origins:{"web-scene":{name:"layerDefinition.orderBy",write:!0,read:!0}}}})],H.prototype,"orderBy",void 0),e([l(M.outFields)],H.prototype,"outFields",void 0),e([l({readOnly:!0})],H.prototype,"source",void 0),e([l({json:{read:!1}})],H.prototype,"type",void 0),e([l({type:String})],H.prototype,"typeIdField",void 0),e([l({type:[A]})],H.prototype,"types",void 0),H=e([p("esri.layers.CatalogLayer")],H);const W=H;export{W as default};