UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) • 12 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import{ClonableMixin as t}from"../core/Clonable.js";import r from"../core/Collection.js";import s from"../core/Error.js";import{loadAll as i}from"../core/loadAll.js";import{getOrCreateMapValue as o}from"../core/MapUtils.js";import{MultiOriginJSONSupportMixin as a}from"../core/MultiOriginJSONSupport.js";import{debounce as n,throwIfAbortError as u,whenOrAbort as l}from"../core/promiseUtils.js";import{watch as p,sync as y}from"../core/reactiveUtils.js";import{sqlAnd as d}from"../core/sql.js";import{property as c,subclass as h}from"../core/accessorSupport/decorators.js";import m from"./Layer.js";import{APIKeyMixin as f}from"./mixins/APIKeyMixin.js";import{ArcGISService as b}from"./mixins/ArcGISService.js";import{BlendLayer as g}from"./mixins/BlendLayer.js";import{CustomParametersMixin as w}from"./mixins/CustomParametersMixin.js";import{DisplayFilteredLayer as S}from"./mixins/DisplayFilteredLayer.js";import{EditBusLayer as F}from"./mixins/EditBusLayer.js";import{FeatureLayerBase as j}from"./mixins/FeatureLayerBase.js";import{OperationalLayer as v}from"./mixins/OperationalLayer.js";import{PortalLayer as L}from"./mixins/PortalLayer.js";import{RefreshableLayer as T}from"./mixins/RefreshableLayer.js";import{ScaleRangeLayer as x}from"./mixins/ScaleRangeLayer.js";import{TemporalLayer as E}from"./mixins/TemporalLayer.js";import{titleFromUrlAndName as I}from"./support/arcgisLayerUrl.js";import{id as _}from"./support/commonProperties.js";import{ensureLayerCredential as O,computeEffectiveEditingEnabled as C,addAttachment as P,updateAttachment as G,applyEdits as U,createQuery as q,deleteAttachments as D,fetchRecomputedExtents as A,computeDomainFromSubtypes as M,getFeatureSubtype as k,queryAttachments as R,queryObjectIds as N,queryFeatureCount as Q,queryExtent as $,queryRelatedFeatures as H,queryRelatedFeaturesCount as J,hasDataChanged as V}from"./support/featureLayerUtils.js";import{defineFieldProperties as B}from"./support/fieldProperties.js";import{fixTimeInfoFields as z}from"./support/fieldUtils.js";import{getSymbolWithColorSupport as K,createSimpleRenderersWithUniqueColors as Z}from"./support/subtypeGroupLayerUtils.js";import W from"./support/SubtypeSublayer.js";import X from"./support/TimeInfo.js";import{serviceSupportsSpatialReference as Y}from"./support/versionUtils.js";import ee from"../rest/support/Query.js";import{isNumber as te}from"../support/guards.js";import{addLayerUnsupportedError as re}from"../webdoc/support/unsupportedErrors.js";import{reader as se}from"../core/accessorSupport/decorators/reader.js";const ie="SubtypeGroupLayer";function oe(e,t){const r=[];for(const s of e){const e=new W;e.read(s,t),r.push(e)}return r}const ae=B();function ne(){return{name:"layerType",read:{enabled:!0},write:{enabled:!0,ignoreOrigin:!0,isRequired:!0}}}let ue=class extends(j(S(F(g(E(x(T(b(v(L(a(w(f(t(m))))))))))))))){constructor(...e){super(...e),this._sublayerLookup=new Map,this.fields=null,this.fieldsIndex=null,this.outFields=null,this.sublayers=new(r.ofType(W)),this.useUniqueColorsForSublayers=!0,this.supportedSourceTypes=new Set(["Feature Layer","Table"]),this.timeInfo=null,this.title="Layer",this.type="subtype-group",this._debouncedSaveOperations=n(async(e,t,r)=>{const{save:s,saveAs:i}=await import("./save/featureLayerUtils.js");switch(e){case 0:return s(this,t);case 1:return i(this,r,t)}}),this.addHandles(p(()=>this.sublayers,(e,t)=>this._handleSublayersChange(e,t),y))}destroy(){this.source?.destroy()}normalizeCtorArgs(e,t){return"string"==typeof e?{url:e,...t}:e}load(e){const t=null!=e?e.signal:null,r=this.loadFromPortal({supportedTypes:["Feature Service"]},e).catch(u).then(async()=>{if(!this.url)throw new s("subtype-grouplayer:missing-url-or-source","SubtypeGroupLayer must be created with either a url or a portal item");if(null==this.layerId)throw new s("subtype-grouplayer:missing-layerid","layerId is required for a SubtypeGroupLayer created with url");this._initLayerProperties(await this.createGraphicsSource(t))}).then(()=>O(this,"load",e));return this.addResolvingPromise(r),Promise.resolve(this)}get createQueryVersion(){return this.commitProperty("definitionExpression"),this.commitProperty("timeExtent"),this.commitProperty("timeOffset"),this.commitProperty("geometryType"),this.commitProperty("gdbVersion"),this.commitProperty("historicMoment"),this.commitProperty("returnZ"),this.commitProperty("capabilities"),this.commitProperty("returnM"),(this._get("createQueryVersion")??0)+1}get editingEnabled(){return this.loaded&&null!=this.capabilities&&this.capabilities.operations.supportsEditing&&this.userHasEditingPrivileges}get effectiveEditingEnabled(){return C(this)}get operationalLayerType(){return this.isTable?"SubtypeGroupTable":"SubtypeGroupLayer"}set source(e){this._get("source")!==e&&this._set("source",e)}readTitleFromService(e,{name:t}){return this.url?I(this.url,t):t}async addAttachment(e,t){const r=await P(this,e,t,ie);return this.lastEditsEventDate=new Date,r}async updateAttachment(e,t,r){const s=await G(this,e,t,r,ie);return this.lastEditsEventDate=new Date,s}async applyEdits(e,t){return U(this,e,t)}async createGraphicsSource(e){const{default:t}=await l(import("./graphics/sources/FeatureLayerSource.js"),e);return new t({layer:this,supportedSourceTypes:this.supportedSourceTypes}).load({signal:e})}createQuery(){const e=q(this),t=this.sublayers.map(e=>e.subtypeCode);return e.where=d(`${this.subtypeField} IN (${t.join(",")})`,this.definitionExpression),e}async deleteAttachments(e,t){const r=await D(this,e,t,ie);return this.lastEditsEventDate=new Date,r}async fetchRecomputedExtents(e){return A(this,e,ie)}findSublayerForFeature(e){const t=this.fieldsIndex.get(this.subtypeField),r=e.attributes[t.name];return this.findSublayerForSubtypeCode(r)}findSublayerForSubtypeCode(e){return this._sublayerLookup.get(e)}getFieldDomain(e,t){if(!t?.excludeImpliedDomains){const t=M(this,e);if(t)return t}const r=k(this,t?.feature);if(r){const t=r.domains?.[e];return"inherited"===t?.type?this._getLayerDomain(e):t}return this._getLayerDomain(e)}loadAll(){return i(this,e=>{e(this.sublayers)})}async queryAttachments(e,t){return R(this,e,t,ie)}async queryFeatures(e,t){const r=await this.load(),s=ee.from(e)??r.createQuery(),i=s.outFields??[];i.includes(this.subtypeField)||(i.push(this.subtypeField),s.outFields=i);const o=await r.source.queryFeatures(s,t);if(o?.features)for(const a of o.features){const e=this.findSublayerForFeature(a);a.origin=e?.graphicOrigin,a.layer=a.sourceLayer=this.findSublayerForFeature(a)}return o}async queryObjectIds(e,t){return(await N(this,e,t,ie)).filter(te)}async queryFeatureCount(e,t){return Q(this,e,t,ie)}async queryExtent(e,t){return $(this,e,t,ie)}async queryRelatedFeatures(e,t){return H(this,e,t,ie)}async queryRelatedFeaturesCount(e,t){return J(this,e,t,ie)}async save(e){return this._debouncedSaveOperations(0,e)}async saveAs(e,t){return this._debouncedSaveOperations(1,t,e)}write(e,t){const{origin:r,layerContainerType:i,messages:o}=t;if(this.isTable){if("web-scene"===r||"web-map"===r&&"tables"!==i)return re(t,this,"a table source cannot be written to web scenes and web maps"),null}else if(this.loaded&&"web-map"===r&&"tables"===i)return re(t,this,"a non-table source cannot be written to tables in web maps"),null;return this.sublayers?.length?super.write(e,t):(o?.push(new s("web-document-write:invalid-property",`Layer (${this.title}, ${this.id}) of type '${this.declaredClass}' has invalid value for 'sublayers' property. 'sublayers' collection should contain at least one sublayer`,{layer:this})),null)}serviceSupportsSpatialReference(e){return!!this.loaded&&Y(this,e)}async getFeatureTitle(e,t){const r=this.findSublayerForFeature(e);return r?await r.getFeatureTitle(e,t):this._getFeatureTitleForUnknownSublayer(e)}async getFeatureTitles(e,t){const r=new Map,s=new Map,i=[s];e.forEach(e=>{const t=this.findSublayerForFeature(e);if(t)o(r,t,()=>[]).push(e);else{const t=e.getObjectId()??e.attributes[this.objectIdField];s.set(t,this._getFeatureTitleForUnknownSublayer(e))}});const a=await Promise.all(Array.from(r).map(([e,r])=>e.getFeatureTitles(r,t)));return a.forEach(e=>i.push(e)),new Map(i.flatMap(e=>[...e]))}get featureTitleFields(){const e=new Set;for(const t of this.sublayers){const r=t.featureTitleFields;for(const t of r)e.add(t)}return[...e]}_getLayerDomain(e){const t=this.fieldsIndex.get(e);return t?t.domain:null}_initLayerProperties(e){this._set("source",e);const{sourceJSON:t}=e;if(t&&(this.sourceJSON=t,this.read(t,{origin:"service",url:this.parsedUrl})),!this.subtypes?.length)throw new s("subtype-grouplayer:missing-subtypes","SubtypeGroupLayer must be created using a layer with subtypes");this._verifyFields(),z(this.timeInfo,this.fieldsIndex)}async hasDataChanged(){return V(this)}_verifyFields(){const e=this.parsedUrl?.path??"undefined";this.objectIdField||console.log("SubtypeGroupLayer: 'objectIdField' property is not defined (url: "+e+")"),this.isTable||-1!==e.search(/\/FeatureServer\//i)||this.fields?.some(e=>"geometry"===e.type)||console.log("SubtypeGroupLayer: unable to find field of type 'geometry' in the layer 'fields' list. If you are using a map service layer, features will not have geometry (url: "+e+")")}_handleSublayersChange(e,t){t&&(t.forEach(e=>{e.parent=null}),this.removeHandles("sublayers-owner"),this._sublayerLookup.clear()),e&&(e.forEach(e=>{e.parent=this,this._sublayerLookup.set(e.subtypeCode,e)}),this.addHandles([e.on("after-add",({item:e})=>{e.parent=this,this._sublayerLookup.set(e.subtypeCode,e)}),e.on("after-remove",({item:e})=>{e.parent=null,this._sublayerLookup.delete(e.subtypeCode)})],"sublayers-owner"))}_getFeatureTitleForUnknownSublayer(e){const{displayField:t,fieldsIndex:r,objectIdField:s}=this;if(t&&r.has(t))return e.attributes[r.get(t).name]??"";const i=e.getObjectId();return null!=i?i.toString():s&&r.has(s)?e.attributes[r.get(s).name]??"":""}};e([c({readOnly:!0})],ue.prototype,"createQueryVersion",null),e([c({readOnly:!0})],ue.prototype,"editingEnabled",null),e([c({readOnly:!0})],ue.prototype,"effectiveEditingEnabled",null),e([c({...ae.fields,readOnly:!0,json:{origins:{service:{read:!0}},read:!1}})],ue.prototype,"fields",void 0),e([c(ae.fieldsIndex)],ue.prototype,"fieldsIndex",void 0),e([c(_)],ue.prototype,"id",void 0),e([c({type:["show","hide","hide-children"],json:{origins:{"portal-item":{read:!1,write:!1}}}})],ue.prototype,"listMode",void 0),e([c({type:["SubtypeGroupLayer","SubtypeGroupTable"],json:{...ne(),origins:{"web-document":ne(),"portal-item":ne()}}})],ue.prototype,"operationalLayerType",null),e([c(ae.outFields)],ue.prototype,"outFields",void 0),e([c({clonable:!1})],ue.prototype,"source",null),e([c({type:r.ofType(W),json:{origins:{service:{read:{source:"subtypes",reader(e,t,s){let i=null;if(this.useUniqueColorsForSublayers){const r=K(t,s);i=r?Z(e.length,r):null}const o=e.map(({code:e},r)=>{const o=new W({subtypeCode:e});o.read(t,s);const a=i?.[r];return a&&o.read({drawingInfo:{renderer:a.toJSON()}},s),o});return new(r.ofType(W))(o)}}}},read:{source:["layers","tables"],reader(e,t,s){let i;return"SubtypeGroupLayer"===t.layerType&&t.layers?.length?i=oe(t.layers,s):"SubtypeGroupTable"===t.layerType&&t.tables?.length&&(i=oe(t.tables,s)),new(r.ofType(W))(i)}},write:{ignoreOrigin:!0,writer(e,t,r,s){const i=[];for(const o of e){const e=o.write({},s);i.push(e)}this.isTable?t.tables=i:t.layers=i}}}})],ue.prototype,"sublayers",void 0),e([c()],ue.prototype,"useUniqueColorsForSublayers",void 0),e([c({type:X})],ue.prototype,"timeInfo",void 0),e([c({json:{origins:{"portal-item":{write:{enabled:!0,ignoreOrigin:!0,writerEnsuresNonNull:!0}}}}})],ue.prototype,"title",void 0),e([se("service","title",["name"])],ue.prototype,"readTitleFromService",null),e([c({json:{read:!1}})],ue.prototype,"type",void 0),e([c({clonable:!1,readOnly:!0})],ue.prototype,"featureTitleFields",null),ue=e([h("esri.layers.SubtypeGroupLayer")],ue);const le=ue;export{le as default};