UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 7.38 kB
import{_ as e}from"../chunks/tslib.es6.js";import{deprecatedProperty as t}from"../core/deprecate.js";import r from"../core/Logger.js";import{property as s}from"../core/accessorSupport/decorators/property.js";import"../core/accessorSupport/ensureType.js";import"../core/arrayUtils.js";import{subclass as a}from"../core/accessorSupport/decorators/subclass.js";import o from"../layers/FeatureLayer.js";import{queryAllJSON as n}from"../layers/support/featureQueryAll.js";import i from"./Network.js";import l from"./RulesTable.js";import u from"./support/NamedTraceConfiguration.js";import d from"./support/NetworkSystemLayers.js";import m from"./support/TerminalConfiguration.js";import{RuleType as c}from"./support/typeUtils.js";import y from"../rest/support/Query.js";const p="esri.networks.UtilityNetwork",T=r.getLogger(p);let f=class extends i{constructor(e){super(e),this.sharedNamedTraceConfigurations=[],this.type="utility"}get serviceTerritoryFeatureLayerId(){return this.dataElement?.serviceTerritoryFeatureLayerId??null}get networkSystemLayers(){return new d({rulesTableId:this.sourceJSON?.systemLayers.rulesTableId,rulesTableUrl:this.sourceJSON?`${this.featureServiceUrl}/${this.sourceJSON?.systemLayers.rulesTableId}`:null,subnetworksTableId:this.sourceJSON?.systemLayers.subnetworksTableId,subnetworksTableUrl:this.sourceJSON?`${this.featureServiceUrl}/${this.sourceJSON?.systemLayers.subnetworksTableId}`:null,dirtyAreasLayerId:this.sourceJSON?.systemLayers.dirtyAreasLayerId,dirtyAreasLayerUrl:this.sourceJSON?`${this.featureServiceUrl}/${this.sourceJSON?.systemLayers.dirtyAreasLayerId}`:null})}get rulesTableId(){return t(T,"rulesTableId",{replacement:"networkSystemLayers.rulesTableId",version:"4.25"}),this.sourceJSON?.systemLayers.rulesTableId}get rulesTableUrl(){return t(T,"rulesTableUrl",{replacement:"networkSystemLayers.rulesTableUrl",version:"4.25"}),this.sourceJSON?`${this.featureServiceUrl}/${this.networkSystemLayers.rulesTableId}`:null}get subnetworksTableId(){return t(T,"subnetworksTableId",{replacement:"networkSystemLayers.subnetworksTableId",version:"4.25"}),this.sourceJSON?.systemLayers.subnetworksTableId}get subnetworksTableUrl(){return t(T,"subnetworksTableUrl",{replacement:"networkSystemLayers.subnetworksTableUrl",version:"4.25"}),this.sourceJSON?`${this.featureServiceUrl}/${this.networkSystemLayers.subnetworksTableId}`:null}get terminalConfigurations(){return this.dataElement?.terminalConfigurations.map((e=>m.fromJSON(e)))||[]}get domainNetworkNames(){return this.dataElement?.domainNetworks.map((e=>e.domainNetworkName))||[]}get _utilityLayerList(){const e=new Set;return this.dataElement?.domainNetworks?.map((t=>{t.edgeSources.map((t=>{e.add(t.layerId)})),t.junctionSources.map((t=>{e.add(t.layerId)}))})),e}async load(e){return this.addResolvingPromise(super.load(e)),this.addResolvingPromise(this._loadNamedTraceConfigurationsFromNetwork(e)),this}getTerminalConfiguration(e){let t=null,r=null;const s=e.layer;let a=null;if("feature"!==s?.type)return null;if(a=s.layerId,null===a)return null;const o=e.attributes;if(null==o)return null;for(const l of Object.keys(o))"ASSETGROUP"===l.toUpperCase()&&(t=e.getAttribute(l)),"ASSETTYPE"===l.toUpperCase()&&(r=e.getAttribute(l));if(!this.dataElement)return null;let n=null;const i=this.dataElement.domainNetworks;for(const l of i){const e=l.junctionSources?.find((e=>e.layerId===a));if(e){const s=e.assetGroups?.find((e=>e.assetGroupCode===t));if(s){const e=s.assetTypes?.find((e=>e.assetTypeCode===r));if(e){n=e.terminalConfigurationId;break}}}}if(null!=n){const e=this.dataElement.terminalConfigurations?.find((e=>e.terminalConfigurationId===n));return e?m.fromJSON(e):null}return null}getTierNames(e){const t=this.dataElement?.domainNetworks.find((t=>t.domainNetworkName===e));return t?.tiers.map((e=>e.name))||[]}async getRulesTable(){return this._createRulesTable()}isUtilityLayer(e){return this._utilityLayerList.has(e.layerId)}async _loadNamedTraceConfigurationsFromNetwork(e){if(0===this.sharedNamedTraceConfigurations?.length)return;const t=this.sharedNamedTraceConfigurations.map((e=>e.globalId)),r=await this.queryNamedTraceConfigurations({globalIds:t},e);for(const s of this.sharedNamedTraceConfigurations){const e=r?.find((e=>e.globalId===s.globalId));if(e){const t=e.write({},{origin:"service"});s.read(t,{origin:"service"})}}}async _createRulesTable(){const e=new o({url:this.rulesTableUrl});await e.load();const t=this.dataElement?.domainNetworks;if(!t)return null;const r=t.flatMap((e=>[...e.edgeSources,...e.junctionSources])),s=(await this._queryRulesTable(e)).map((t=>this._hydrateRuleInfo(e,r,t)));return new l({layer:e,rules:s})}async _queryRulesTable(e){const t=new y({where:"1=1",outFields:["*"]});return(await n(e,t)).features}_hydrateRuleInfo(e,t,r){const s=e.fieldsIndex,a=s.get("RULETYPE"),o=s.get("CREATIONDATE"),n=s.get("FROMNETWORKSOURCEID"),i=s.get("FROMASSETGROUP"),l=s.get("FROMASSETTYPE"),u=s.get("FROMTERMINALID"),d=s.get("TONETWORKSOURCEID"),m=s.get("TOASSETGROUP"),y=s.get("TOASSETTYPE"),p=s.get("TOTERMINALID"),T=s.get("VIANETWORKSOURCEID"),f=s.get("VIAASSETGROUP"),b=s.get("VIAASSETTYPE"),g=s.get("VIATERMINALID"),I=r.attributes[a.name],S=new Date(r.attributes[o.name]),h=[{networkSourceId:r.attributes[n.name],assetGroupId:r.attributes[i.name],assetTypeId:r.attributes[l.name],terminalId:r.attributes[u.name]},{networkSourceId:r.attributes[d.name],assetGroupId:r.attributes[m.name],assetTypeId:r.attributes[y.name],terminalId:r.attributes[p.name]},{networkSourceId:r.attributes[T.name],assetGroupId:r.attributes[f.name],assetTypeId:r.attributes[b.name],terminalId:r.attributes[g.name]}];let w;!function(e){e[e.from=0]="from",e[e.to=1]="to",e[e.via=2]="via"}(w||(w={}));const N={ruleType:I,creationDate:S};for(const k of[w.from,w.to,w.via]){if(I!==c.RTEdgeJunctionEdgeConnectivity&&k===w.via)continue;const e=h[k],r=t.find((t=>t.sourceId===e.networkSourceId)),s=r?.assetGroups.find((t=>t.assetGroupCode===e.assetGroupId)),a=s?.assetTypes.find((t=>t.assetTypeCode===e.assetTypeId));let o=this._getTerminal(I,a,e);I!==c.RTContainment&&I!==c.RTAttachment||(o=null);let n="";switch(k){case w.from:n="from";break;case w.to:n="to";break;case w.via:n="via"}N[`${n}NetworkSource`]=r,N[`${n}AssetGroup`]=s,N[`${n}AssetType`]=a,N[`${n}Terminal`]=o}return N}_getTerminal(e,t,r){if(e===c.RTAttachment||e===c.RTContainment)return null;const s=t?.terminalConfigurationId,a=this.terminalConfigurations?.find((e=>e.id===s));return a?.terminals?.find((e=>e.id===r.terminalId))??null}};e([s({type:[u],json:{origins:{"web-map":{read:{source:"traceConfigurations"},write:{target:"traceConfigurations"}},service:{read:{source:"traceConfigurations"}}},read:!1}})],f.prototype,"sharedNamedTraceConfigurations",void 0),e([s({type:["utility"],readOnly:!0,json:{read:!1,write:!1}})],f.prototype,"type",void 0),e([s({readOnly:!0})],f.prototype,"serviceTerritoryFeatureLayerId",null),e([s({readOnly:!0})],f.prototype,"networkSystemLayers",null),e([s({readOnly:!0})],f.prototype,"rulesTableId",null),e([s({readOnly:!0})],f.prototype,"rulesTableUrl",null),e([s({readOnly:!0})],f.prototype,"subnetworksTableId",null),e([s({readOnly:!0})],f.prototype,"subnetworksTableUrl",null),e([s({readOnly:!0})],f.prototype,"terminalConfigurations",null),e([s({readOnly:!0})],f.prototype,"domainNetworkNames",null),f=e([a("esri.networks.UtilityNetwork")],f);const b=f;export{b as default};