@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 11.3 kB
JavaScript
import e from"../request.js";import t from"./featureSetCollection.js";import a from"./featureset/actions/AttributeFilter.js";import r from"./featureset/actions/GroupBy.js";import n from"./featureset/actions/OrderBy.js";import i from"./featureset/actions/SpatialFilter.js";import s from"./featureset/actions/Top.js";import l from"./featureset/sources/FeatureLayerDynamic.js";import o from"./featureset/sources/FeatureLayerMemory.js";import u from"./featureset/sources/FeatureLayerRelated.js";import c from"./featureset/support/cache.js";import{FeatureSetError as d,FeatureSetErrorCodes as f}from"./featureset/support/errorsupport.js";import m from"./featureset/support/FeatureSet.js";import{extractServiceUrl as p}from"./featureset/support/shared.js";import{WhereClause as y}from"../core/sql/WhereClause.js";import h from"../layers/FeatureLayer.js";import _ from"../portal/PortalItem.js";function L(){null===c.applicationCache&&(c.applicationCache=new c)}async function w(e,t){if(c.applicationCache){const r=c.applicationCache.getLayerInfo(e);if(r){const a=await r;return new h({url:e,outFields:t,sourceJSON:a})}const n=new h({url:e,outFields:t}),i=(async()=>(await n.load(),n.sourceJSON))();if(c.applicationCache){c.applicationCache.setLayerInfo(e,i);try{return await i,n}catch(a){throw c.applicationCache.clearLayerInfo(e),a}}return await i,n}return new h({url:e,outFields:t})}async function I(e,t,a,r,n,i=null){return S(await w(e,["*"]),t,a,r,n,i)}function S(e,t=null,a=null,r=!0,n=null,i=null){const s={layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:i};return!0===e._hasMemorySource()?new o(s):new l(s)}async function N(t){if(null!==c.applicationCache){const e=c.applicationCache.getLayerInfo(t);if(null!==e)return e}const a=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});return a.data?a.data:null})();if(null!==c.applicationCache){c.applicationCache.setLayerInfo(t,a);try{return await a}catch(r){throw c.applicationCache.clearLayerInfo(t),r}}return a}async function F(t,a){const r="QUERYDATAELEMTS:"+a.toString()+":"+t;if(null!==c.applicationCache){const e=c.applicationCache.getLayerInfo(r);if(null!==e)return e}const n=(async()=>{const r=await e(t+"/queryDataElements",{method:"post",responseType:"json",query:{layers:JSON.stringify([a.toString()]),f:"json"}});if(r.data){const e=r.data;if(e.layerDataElements&&e.layerDataElements[0])return e.layerDataElements[0]}throw new d(f.DataElementsNotFound)})();if(null!==c.applicationCache){c.applicationCache.setLayerInfo(r,n);try{return await n}catch(i){throw c.applicationCache.clearLayerInfo(r),i}}return n}async function g(t){if(null!==c.applicationCache){const e=c.applicationCache.getLayerInfo(t);if(null!==e)return e}const a=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});if(a.data){const e=a.data;return e.layers||(e.layers=[]),e.tables||(e.tables=[]),e}return{layers:[],tables:[]}})();if(null!==c.applicationCache){c.applicationCache.setLayerInfo(t,a);try{return await a}catch(r){throw c.applicationCache.clearLayerInfo(t),r}}return a}async function A(e,t){const a={metadata:null,networkId:-1,unVersion:3,terminals:[],queryelem:null,layerNameLkp:{},lkp:null},r=await g(e);if(a.metadata=r,r.controllerDatasetLayers&&void 0!==r.controllerDatasetLayers.utilityNetworkLayerId&&null!==r.controllerDatasetLayers.utilityNetworkLayerId){if(r.layers)for(const e of r.layers)a.layerNameLkp[e.id]=e.name;if(r.tables)for(const e of r.tables)a.layerNameLkp[e.id]=e.name;const n=r.controllerDatasetLayers.utilityNetworkLayerId;a.networkId=n;const i=await F(e,n);if(i){a.queryelem=i,a.queryelem&&a.queryelem.dataElement&&void 0!==a.queryelem.dataElement.schemaGeneration&&(a.unVersion=a.queryelem.dataElement.schemaGeneration),a.lkp={},a.queryelem.dataElement.domainNetworks||(a.queryelem.dataElement.domainNetworks=[]);for(const e of a.queryelem.dataElement.domainNetworks){for(const t of e.edgeSources?e.edgeSources:[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:a.layerNameLkp[t.layerId]?a.layerNameLkp[t.layerId]:null};e.className&&(a.lkp[e.className]=e)}for(const t of e.junctionSources?e.junctionSources:[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:a.layerNameLkp[t.layerId]?a.layerNameLkp[t.layerId]:null};e.className&&(a.lkp[e.className]=e)}}if(a.queryelem.dataElement.terminalConfigurations)for(const e of a.queryelem.dataElement.terminalConfigurations)for(const t of e.terminals)a.terminals.push({terminalId:t.terminalId,terminalName:t.terminalName});const r=await N(e+"/"+n);if(r.systemLayers&&void 0!==r.systemLayers.associationsTableId&&null!==r.systemLayers.associationsTableId){const n=[];a.unVersion>=4&&(n.push("STATUS"),n.push("PERCENTALONG"));let i=await I(e+"/"+r.systemLayers.associationsTableId.toString(),t,["OBJECTID","FROMNETWORKSOURCEID","TONETWORKSOURCEID","FROMGLOBALID","TOGLOBALID","TOTERMINALID","FROMTERMINALID","ASSOCIATIONTYPE","ISCONTENTVISIBLE","GLOBALID",...n],!1,null,null);return await i.load(),a.unVersion>=4&&(i=i.filter(y.create("STATUS NOT IN (1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 57, 58, 59, 60, 61, 62,63)",i.getFieldsIndex())),await i.load()),{lkp:a.lkp,associations:i,unVersion:a.unVersion,terminals:a.terminals}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}async function C(e,t,a,r=null,n=null,i=!0,s=null,l=null){let o=e.serviceUrl();if(!o)return null;o="/"===o.charAt(o.length-1)?o+t.relatedTableId.toString():o+"/"+t.relatedTableId.toString();const c=await I(o,r,n,i,s,l);return new u({layer:e,relatedLayer:c,relationship:t,objectId:a,spatialReference:r,outFields:n,includeGeometry:i,lrucache:s,interceptor:l})}a.registerAction(),r.registerAction(),n.registerAction(),i.registerAction(),s.registerAction();class T extends t{constructor(e,t=null,a=null,r=null){super(),this._map=e,this._overridespref=t,this._lrucache=a,this._interceptor=r,this._instantLayers=[]}_makeAndAddFeatureSet(e,t=!0,a=null){const r=S(e,this._overridespref,null===a?["*"]:a,t,this._lrucache,this._interceptor);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async featureSetByName(e,t=!0,a=null){if(void 0!==this._map.loaded&&void 0!==this._map.load&&!1===this._map.loaded)return await this._map.load(),this.featureSetByName(e,t,a);null===a&&(a=["*"]),a=(a=a.slice(0)).sort();const r=JSON.stringify(a);for(let i=0;i<this._instantLayers.length;i++){const a=this._instantLayers[i];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[i].featureset}const n=this._map.allLayers.find((t=>t instanceof h&&t.title===e));if(n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.tables){const r=this._map.tables.find((t=>!!(t.title&&t.title===e||t.title&&t.title===e)));if(r){if(r instanceof h)return this._makeAndAddFeatureSet(r,t,a);if(r._materializedTable);else{const e=r.outFields?r:{...r,outFields:["*"]};r._materializedTable=new h(e)}return await r._materializedTable.load(),this._makeAndAddFeatureSet(r._materializedTable,t,a)}}return null}async featureSetById(e,t=!0,a=["*"]){if(void 0!==this._map.loaded&&void 0!==this._map.load&&!1===this._map.loaded)return await this._map.load(),this.featureSetById(e,t,a);null===a&&(a=["*"]),a=(a=a.slice(0)).sort();const r=JSON.stringify(a);for(let i=0;i<this._instantLayers.length;i++){const a=this._instantLayers[i];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[i].featureset}const n=this._map.allLayers.find((t=>t instanceof h&&t.id===e));if(n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.tables){const r=this._map.tables.find((t=>t.id===e));if(r){if(r instanceof h)return this._makeAndAddFeatureSet(r,t,a);if(r._materializedTable);else{const e={...r,outFields:["*"]};r._materializedTable=new h(e)}return await r._materializedTable.load(),this._makeAndAddFeatureSet(r._materializedTable,t,a)}}return null}}class k extends t{constructor(e,t=null,a=null,r=null){super(),this._url=e,this._overridespref=t,this._lrucache=a,this._interceptor=r,this.metadata=null,this._instantLayers=[]}get url(){return this._url}_makeAndAddFeatureSet(e,t=!0,a=null){const r=S(e,this._overridespref,null===a?["*"]:a,t,this._lrucache);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async _loadMetaData(){const e=await g(this._url);return this.metadata=e,e}load(){return this._loadMetaData()}clone(){return new k(this._url,this._overridespref,this._lrucache,this._interceptor)}async featureSetByName(e,t=!0,a=null){null===a&&(a=["*"]),a=(a=a.slice(0)).sort();const r=JSON.stringify(a);for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let i=null;for(const s of n.layers?n.layers:[])s.name===e&&(i=s);if(!i)for(const s of n.tables?n.tables:[])s.name===e&&(i=s);if(i){const e=await w(this._url+"/"+i.id,["*"]);return this._makeAndAddFeatureSet(e,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){null===a&&(a=["*"]),a=(a=a.slice(0)).sort();const r=JSON.stringify(a);e=null!=e?e.toString():"";for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let i=null;for(const s of n.layers?n.layers:[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(i=s);if(!i)for(const s of n.tables?n.tables:[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(i=s);if(i){const e=await w(this._url+"/"+i.id,["*"]);return this._makeAndAddFeatureSet(e,t,a)}return null}}function O(e,t,a=null,r=null){return new T(e,t,a,r)}function b(e,t,a=null,r=null){return new k(e,t,a,r)}function E(e,t,a,r,n){if(null===e)return null;if(e instanceof h){switch(t){case"datasource":return S(e,n,e.outFields,!0,a,r).getDataSourceFeatureSet();case"parent":case"root":return S(e,n,e.outFields,!0,a,r)}return null}if(e instanceof m)switch(t){case"datasource":return e.getDataSourceFeatureSet();case"parent":return e;case"root":return e.getRootFeatureSet()}return null}async function j(e,t,a,r,n,i,s,l=null){if(c.applicationCache){const o=c.applicationCache.getLayerInfo(e+":"+i.url);if(o){const e=await o;return S(new h({url:p(e.url)+"/"+t,outFields:["*"]}),a,r,n,s,l)}}const o=new _({id:e,portal:i}).load();c.applicationCache&&c.applicationCache.setLayerInfo(e+":"+i.url,o);try{const e=await o;return S(new h({url:p(e.url??"")+"/"+t,outFields:["*"]}),a,r,n,s,l)}catch(u){throw c.applicationCache&&c.applicationCache.clearLayerInfo(e+":"+i.url),u}}export{A as constructAssociationMetaDataFeatureSetFromUrl,S as constructFeatureSet,j as constructFeatureSetFromPortalItem,C as constructFeatureSetFromRelationship,I as constructFeatureSetFromUrl,E as convertToFeatureSet,O as createFeatureSetCollectionFromMap,b as createFeatureSetCollectionFromService,L as initialiseMetaDataCache};