@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 5.83 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{neverAbortedSignal as e}from"../../arcadeEnvironment.js";import{throwIfCancelled as t,FeatureSetError as r}from"../support/errorsupport.js";import{RootFeatureSet as i,emptyFeaturesResult as a}from"../support/FeatureSet.js";import{defaultMaxRecords as s}from"../support/shared.js";import l from"../../../rest/support/RelationshipQuery.js";class d extends i{constructor(e){super(),this.declaredClass="esri.arcade.featureset.sources.FeatureLayerRelated",this._removeGeometry=!1,this._overrideFields=null,this._maxProcessing=1e3,this._layer=e.layer,e.spatialReference&&(this.spatialReference=e.spatialReference),this._findObjectId=e.objectId,this.relationship=e.relationship,this._relatedLayer=e.relatedLayer,void 0!==e.outFields&&(this._overrideFields=e.outFields),void 0!==e.includeGeometry&&(this._removeGeometry=!1===e.includeGeometry)}_maxQueryRate(){return s}async loadImpl(){return await Promise.all([this._layer.load(),this._relatedLayer.load()]),this._initialiseFeatureSet(),this}nativeCapabilities(){return this._relatedLayer.nativeCapabilities()}_initialiseFeatureSet(){if(null==this.spatialReference&&(this.spatialReference=this._layer.spatialReference),this.geometryType=this._relatedLayer.geometryType,this.fields=this._relatedLayer.fields.slice(),this.hasZ=this._relatedLayer.hasZ,this.hasM=this._relatedLayer.hasM,null!==this._overrideFields)if(1===this._overrideFields.length&&"*"===this._overrideFields[0])this._overrideFields=null;else{const e=new Set(this._overrideFields.map(e=>e.toLowerCase()));this.fields=this.fields.filter(({type:t,name:r})=>"oid"===t||e.has(r.toLowerCase())),this._overrideFields=this.fields.map(({name:e})=>e)}const e=this._layer.nativeCapabilities();e&&(this._databaseType=e.databaseType),this.objectIdField=this._relatedLayer.objectIdField,this.globalIdField=this._relatedLayer.globalIdField,this.hasM=this._relatedLayer.supportsM,this.hasZ=this._relatedLayer.supportsZ,this.typeIdField=this._relatedLayer.typeIdField,this.types=this._relatedLayer.types,this.subtypeField=this._relatedLayer.subtypeField,this.subtypes=this._relatedLayer.subtypes}async databaseType(){return this._databaseType=await this._relatedLayer.databaseType(),this._databaseType}isTable(){return this._relatedLayer.isTable()}async _queryAll(){return(await this.query({abortSignal:e})).features}async query(e){if(await this._ensureLoaded(),await this.databaseType(),this.isTable()&&null!=e.spatialFilter)return a;const r=this._layer.nativeCapabilities();if(!1===r.canQueryRelated)return a;if(r.capabilities?.queryRelated.supportsPagination)return this._queryUsingPaging(r.source,e);let i="",s=!1;null!=e.orderBy&&!0===r.capabilities?.queryRelated.supportsOrderBy&&(i=e.orderBy.constructClause(),s=!0);const d=new l;return d.objectIds=[this._findObjectId],d.outFields=null!==this._overrideFields?this._overrideFields:this._fieldsIncludingObjectId(this._relatedLayer.fields?this._relatedLayer.fields.map(e=>e.name):["*"]),d.relationshipId=this.relationship.id,d.where="1=1",d.returnGeometry=!0!==this._removeGeometry,d.outSpatialReference=this.spatialReference,d.orderByFields=""!==i?i.split(","):null,{filterApplied:null==e.where,spatialFilterApplied:null==e.spatialFilter,ordered:s,features:async function*(){const i=await r.source.queryRelatedFeatures(d);t(e.abortSignal),yield i[this._findObjectId]?i[this._findObjectId].features:[]}.apply(this)}}async _queryUsingPaging(e,t){let r="",i=!1;const a=this._layer.nativeCapabilities();null!=t.orderBy&&!0===a.capabilities?.queryRelated.supportsOrderBy&&(r=t.orderBy.constructClause(),i=!0),await this.databaseType();let s=this._maxQueryRate();const d=a.capabilities?.query.maxRecordCount;null!=d&&d<s&&(s=d);const n=new l;return n.relationshipId=this.relationship.id,n.objectIds=[this._findObjectId],n.outFields=null!==this._overrideFields?this._overrideFields:this._fieldsIncludingObjectId(this._relatedLayer.fields?this._relatedLayer.fields.map(e=>e.name):["*"]),n.where="1=1",n.orderByFields=""!==r?r.split(","):null,n.returnGeometry=!0!==this._removeGeometry,n.outSpatialReference=this.spatialReference,{filterApplied:null==t.where,spatialFilterApplied:null==t.spatialFilter,ordered:i,features:this._queryPaginated(e,n,s,t.abortSignal)}}async*_queryPaginated(e,r,i,a){let s;r.num=i,r.start=0;do{t(a);s=(await e.queryRelatedFeatures(r))[this._findObjectId]??{exceededTransferLimit:!1,features:[]},yield s.features,r.start+=i}while(!0===s.exceededTransferLimit)}async queryStat(e){return{calculated:!1}}async canQueryAggregate(e){return!1}async queryAggregate(e){throw new r("NeverReach")}_fieldsIncludingObjectId(e){if(null===e)return[this.objectIdField];const t=e.slice();if(t.includes("*"))return t;let r=!1;for(const i of t)if(i.toUpperCase()===this.objectIdField.toUpperCase()){r=!0;break}return r||t.push(this.objectIdField),t}get gdbVersion(){return this._relatedLayer.gdbVersion}relationshipMetadata(){return this._relatedLayer.relationshipMetadata()}serviceUrl(){return this._relatedLayer.serviceUrl()}queryAttachments(e,t,r,i,a){return this._relatedLayer.queryAttachments(e,t,r,i,a)}getFeatureByObjectId(e,t){return this._relatedLayer.getFeatureByObjectId(e,t)}getOwningSystemUrl(){return this._relatedLayer.getOwningSystemUrl()}getIdentityUser(){return this._relatedLayer.getIdentityUser()}getDataSourceFeatureSet(){return this._relatedLayer}get preferredTimeZone(){return this._relatedLayer.preferredTimeZone??null}get dateFieldsTimeZone(){return this._relatedLayer.dateFieldsTimeZone??null}get datesInUnknownTimezone(){return this._relatedLayer.datesInUnknownTimezone}get editFieldsInfo(){return this._relatedLayer.editFieldsInfo??null}get timeInfo(){return this._relatedLayer.timeInfo??null}getFeatureSetInfo(){return this._relatedLayer.getFeatureSetInfo()}}export{d as default};