@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 8.13 kB
JavaScript
import e from"../../../Graphic.js";import{FeatureSetError as t,FeatureSetErrorCodes as r}from"../support/errorsupport.js";import s from"../support/FeatureSet.js";import i from"../support/IdSet.js";import{defaultMaxRecords as a,FeatureServiceDatabaseType as l,IdState as n}from"../support/shared.js";import{toWhereClause as o}from"../support/sqlUtils.js";import u from"../../../geometry/Geometry.js";import h from"../../../layers/FeatureLayer.js";import c from"../../../layers/support/FeatureType.js";import y from"../../../layers/support/Field.js";import d from"../../../rest/support/Query.js";class f extends s{constructor(e){super(e),this.declaredClass="esri.arcade.featureset.sources.FeatureLayerMemory",this._removeGeometry=!1,this._overrideFields=null,this._forceIsTable=!1,e.spatialReference&&(this.spatialReference=e.spatialReference),this._transparent=!0,this._maxProcessing=1e3,this._layer=e.layer,this._wset=null,!0===e.isTable&&(this._forceIsTable=!0),void 0!==e.outFields&&(this._overrideFields=e.outFields),void 0!==e.includeGeometry&&(this._removeGeometry=!1===e.includeGeometry)}_maxQueryRate(){return a}end(){return this._layer}optimisePagingFeatureQueries(){}async loadImpl(){return!0===this._layer.loaded?(this._initialiseFeatureSet(),this):(await this._layer.load(),this._initialiseFeatureSet(),this)}get gdbVersion(){return""}_initialiseFeatureSet(){if(null==this.spatialReference&&(this.spatialReference=this._layer.spatialReference),this.geometryType=this._layer.geometryType,this.fields=this._layer.fields.slice(0),this._layer.outFields)if(1===this._layer.outFields.length&&"*"===this._layer.outFields[0]);else{const e=[];for(const t of this.fields)if("oid"===t.type)e.push(t);else for(const r of this._layer.outFields)if(r.toLowerCase()===t.name.toLowerCase()){e.push(t);break}this.fields=e}else;if(null!==this._overrideFields)if(1===this._overrideFields.length&&"*"===this._overrideFields[0])this._overrideFields=null;else{const e=[],t=[];for(const r of this.fields)if("oid"===r.type)e.push(r),t.push(r.name);else for(const s of this._overrideFields)if(s.toLowerCase()===r.name.toLowerCase()){e.push(r),t.push(r.name);break}this.fields=e,this._overrideFields=t}this.objectIdField=this._layer.objectIdField;for(const e of this.fields)"global-id"===e.type&&(this.globalIdField=e.name);this.hasM=this._layer.supportsM,this.hasZ=this._layer.supportsZ,this._databaseType=l.Standardised,this.typeIdField=this._layer.typeIdField,this.types=this._layer.types}isTable(){return this._forceIsTable||this._layer.isTable||"table"===this._layer.type||!this._layer.geometryType}_isInFeatureSet(){return n.InFeatureSet}_candidateIdTransform(e){return e}async _getSet(e){if(null===this._wset){await this._ensureLoaded();const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,t}return this._wset}_changeFeature(t){const r={};for(const e of this.fields)r[e.name]=t.attributes[e.name];return new e({geometry:!0===this._removeGeometry?null:t.geometry,attributes:r})}async _getFilteredSet(e,t,r,s,a){let n="",u=!1;if(null!==s&&(n=s.constructClause(),u=!0),this.isTable()&&t&&null!==e&&""!==e){return new i([],[],!0,null)}const h=new d;h.where=null===r?null===t?"1=1":"":o(r,l.Standardised),h.spatialRelationship=this._makeRelationshipEnum(e),h.outSpatialReference=this.spatialReference,h.orderByFields=""!==n?n.split(","):null,h.geometry=null===t?null:t,h.returnGeometry=!0,h.relationParameter=this._makeRelationshipParam(e);const c=await this._layer.queryFeatures(h);if(null===c)return new i([],[],u,null);this._checkCancelled(a);const y=[];c.features.forEach((e=>{const t=e.attributes[this._layer.objectIdField];y.push(t),this._featureCache[t]=this._changeFeature(e)}));return new i([],y,u,null)}_makeRelationshipEnum(e){if(e.includes("esriSpatialRelRelation"))return"relation";switch(e){case"esriSpatialRelRelation":return"relation";case"esriSpatialRelIntersects":return"intersects";case"esriSpatialRelContains":return"contains";case"esriSpatialRelOverlaps":return"overlaps";case"esriSpatialRelWithin":return"within";case"esriSpatialRelTouches":return"touches";case"esriSpatialRelCrosses":return"crosses";case"esriSpatialRelEnvelopeIntersects":return"envelope-intersects"}return e}_makeRelationshipParam(e){return e.includes("esriSpatialRelRelation")?e.split(":")[1]:""}async _queryAllFeatures(){if(this._wset)return this._wset;const e=new d;if(e.where="1=1",await this._ensureLoaded(),this._layer.source&&this._layer.source.items){const e=[];return this._layer.source.items.forEach((t=>{const r=t.attributes[this._layer.objectIdField];e.push(r),this._featureCache[r]=this._changeFeature(t)})),this._wset=new i([],e,!1,null),this._wset}const t=await this._layer.queryFeatures(e),r=[];return t.features.forEach((e=>{const t=e.attributes[this._layer.objectIdField];r.push(t),this._featureCache[t]=this._changeFeature(e)})),this._wset=new i([],r,!1,null),this._wset}async _getFeatures(e,s,i){const a=[];-1!==s&&void 0===this._featureCache[s]&&a.push(s);for(let t=e._lastFetchedIndex;t<e._known.length&&(e._lastFetchedIndex+=1,!(void 0===this._featureCache[e._known[t]]&&(e._known[t]!==s&&a.push(e._known[t]),a.length>i)));t++);if(0===a.length)return"success";throw new t(r.MissingFeatures)}async _refineSetBlock(e){return e}async _stat(){return{calculated:!1}}async _canDoAggregates(){return!1}relationshipMetaData(){return[]}static _cloneAttr(e){const t={};for(const r in e)t[r]=e[r];return t}nativeCapabilities(){return{title:this._layer.title??"",canQueryRelated:!1,source:this,capabilities:this._layer.capabilities,databaseType:this._databaseType,requestStandardised:!0}}static create(e,t){let r=e.layerDefinition.objectIdField;const s=e.layerDefinition.typeIdField?e.layerDefinition.typeIdField:"",i=[];if(e.layerDefinition.types)for(const u of e.layerDefinition.types)i.push(c.fromJSON(u));let a=e.layerDefinition.geometryType;void 0===a&&(a=e.featureSet.geometryType||"");let l=e.featureSet.features;const n=t.toJSON();if(""===r||void 0===r){let t=!1;for(const s of e.layerDefinition.fields)if("oid"===s.type||"esriFieldTypeOID"===s.type){r=s.name,t=!0;break}if(!1===t){let t="FID",s=!0,i=0;for(;s;){let r=!0;for(const s of e.layerDefinition.fields)if(s.name===t){r=!1;break}!0===r?s=!1:(i++,t="FID"+i.toString())}e.layerDefinition.fields.push({type:"esriFieldTypeOID",name:t,alias:t});const a=[];for(let r=0;r<l.length;r++)a.push({geometry:e.featureSet.features[r].geometry,attributes:e.featureSet.features[r].attributes?this._cloneAttr(e.featureSet.features[r].attributes):{}}),a[r].attributes[t]=r;l=a,r=t}}const o=[];for(const u of e.layerDefinition.fields)u instanceof y?o.push(u):o.push(y.fromJSON(u));let d=a;switch(d||(d=""),d){case"esriGeometryPoint":d="point";break;case"esriGeometryPolyline":d="polyline";break;case"esriGeometryPolygon":d="polygon";break;case"esriGeometryExtent":d="extent";break;case"esriGeometryMultipoint":d="multipoint";break;case"":case"esriGeometryNull":d="esriGeometryNull"}if("esriGeometryNull"!==d)for(const h of l)h.geometry&&h.geometry instanceof u==!1&&(h.geometry.type=d,void 0===h.geometry.spatialReference&&(h.geometry.spatialReference=n));else for(const u of l)u.geometry&&(u.geometry=null);const p={outFields:["*"],source:l,fields:o,types:i,typeIdField:s,objectIdField:r,spatialReference:t};""!==d&&"esriGeometryNull"!==d&&null!==d&&(p.geometryType=d);const m=new h(p);return new f({layer:m,spatialReference:t,isTable:null===d||""===d||"esriGeometryNull"===d})}async queryAttachments(){return[]}async getFeatureByObjectId(e){const t=new d;t.where=this.objectIdField+"="+e.toString();const r=await this._layer.queryFeatures(t);return 1===r.features.length?r.features[0]:null}async getOwningSystemUrl(){return""}async getIdentityUser(){return""}get preferredTimeReference(){return this._layer?.preferredTimeReference?.toJSON()??null}get dateFieldsTimeReference(){return this._layer?.dateFieldsTimeReference?.toJSON()??null}get datesInUnknownTimezone(){return this._layer?.datesInUnknownTimezone}get editFieldsInfo(){return this._layer?.editFieldsInfo?.toJSON()??null}get timeInfo(){return this._layer?.timeInfo?.toJSON()??null}}export{f as default};