UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 11.3 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{_ as e}from"../chunks/tslib.es6.js";import t from"../Graphic.js";import{getOrCreateMapValue as r}from"../core/MapUtils.js";import{property as s}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/Logger.js";import"../core/RandomLCG.js";import{subclass as i}from"../core/accessorSupport/decorators/subclass.js";import a from"../layers/FeatureLayer.js";import{queryAllJSON as o}from"../layers/support/featureQueryAll.js";import n from"./Network.js";import l from"./RulesTable.js";import u from"./support/NamedTraceConfiguration.js";import{getAssociationsTableFields as d}from"./support/networkFieldUtils.js";import m from"./support/NetworkSystemLayers.js";import c from"./support/TerminalConfiguration.js";import y from"./support/TraceJobInfo.js";import{AssociationTypeEnum as p,RuleType as f}from"./support/typeUtils.js";import{doesRuleAllowAssociation as h}from"./support/utils.js";import I from"../rest/support/Query.js";let g=class extends n{constructor(e){super(e),this.sharedNamedTraceConfigurations=[],this.type="utility",this._terminalById=new Map,this._circuitManagerMap=new Map,this._unitIdentifierManager=null}get serviceTerritoryFeatureLayerId(){return this.dataElement?.serviceTerritoryFeatureLayerId??null}get networkSystemLayers(){return new m({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,associationsTableId:this.sourceJSON?.systemLayers.associationsTableId,associationsTableUrl:this.sourceJSON?`${this.featureServiceUrl}/${this.sourceJSON?.systemLayers.associationsTableId}`:null})}get terminalConfigurations(){return this.dataElement?.terminalConfigurations.map((e=>c.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((({layerId:t,sourceId:r})=>{this._layerIdBySourceId.set(r,t),this._sourceIdByLayerId.set(t,r),e.add(t)})),t?.junctionSources?.map((({layerId:t,sourceId:r})=>{this._layerIdBySourceId.set(r,t),this._sourceIdByLayerId.set(t,r),e.add(t)}))})),e}get hasTelecomNetwork(){return this.dataElement?.domainNetworks.some((e=>e.isTelecomNetwork))??!1}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.sourceLayer;let i=null;if("feature"===s?.type){if(i=s.layerId,null===i)return null}else{if("subtype-sublayer"!==s?.type)return null;if(i=s?.parent?.layerId??null,null===i)return null}const a=e.attributes;if(null==a)return null;for(const l of Object.keys(a))"ASSETGROUP"===l.toUpperCase()&&(t=e.getAttribute(l)),"ASSETTYPE"===l.toUpperCase()&&(r=e.getAttribute(l));if(!this.dataElement)return null;let o=null;const n=this.dataElement.domainNetworks;for(const l of n){const e=l.junctionSources?.find((e=>e.layerId===i));if(e){const s=e.assetGroups?.find((e=>e.assetGroupCode===t));if(s){const e=s.assetTypes?.find((e=>e.assetTypeCode===r));if(e?.isTerminalConfigurationSupported){o=e.terminalConfigurationId;break}}}}if(null!=o){const e=this.dataElement.terminalConfigurations,t=e?.find((e=>e.terminalConfigurationId===o));return t?c.fromJSON(t):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._sharedRulesTable||(this._sharedRulesTable=this._createRulesTable()),await this._sharedRulesTable}async getCircuitManager(e){if(!this.hasTelecomNetwork)return null;const t=this.dataElement?.domainNetworks.find((t=>t.domainNetworkName===e&&t.isTelecomNetwork));if(!t)return null;const{default:s}=await import("./CircuitManager.js");return r(this._circuitManagerMap,e,(()=>new s({utilityNetwork:this,telecomDomainNetwork:t})))}async getUnitIdentifierManager(){if(!this.hasTelecomNetwork)return null;if(this._unitIdentifierManager)return this._unitIdentifierManager;const{default:e}=await import("./UnitIdentifierManager.js");return this._unitIdentifierManager=new e({utilityNetwork:this}),this._unitIdentifierManager}getTerminalById(e){if(!this.dataElement||null==e)return null;const t=this._terminalById.get(e);return null!=t?t:(this.terminalConfigurations.forEach((e=>{e.terminals.forEach((e=>{this._terminalById.set(e.id,e)}))})),this._terminalById.get(e))}isUtilityLayer(e){return"layerId"in e?this._utilityLayerList.has(e?.layerId)&&(e.url?.startsWith(this.featureServiceUrl)??!1):!("subtype-sublayer"!==e.type||!e.parent)&&(this._utilityLayerList.has(e.parent.layerId)&&(e.parent.url?.startsWith(this.featureServiceUrl)??!1))}async queryAssociations(e,t){const[{queryAssociations:r},{default:s}]=await Promise.all([import("../rest/networks/queryAssociations.js"),import("../rest/networks/support/QueryAssociationsParameters.js")]),i=s.from(e);i.gdbVersion=this.gdbVersion,i.moment=this.historicMoment;return(await r(this.networkServiceUrl,i,t)).associations}async synthesizeAssociationGeometries(e){const[{synthesizeAssociationGeometries:t},{default:r}]=await Promise.all([import("../rest/networks/synthesizeAssociationGeometries.js"),import("../rest/networks/support/SynthesizeAssociationGeometriesParameters.js")]),s=r.from(e);return s.gdbVersion=this.gdbVersion,s.moment=this.historicMoment,t(this.networkServiceUrl,s)}async trace(e){const[{trace:t},{default:r}]=await Promise.all([import("../rest/networks/trace.js"),import("../rest/networks/support/TraceParameters.js")]),s=r.from(e);return s.gdbVersion=this.gdbVersion,s.moment=this.historicMoment,t(this.networkServiceUrl,s)}async submitTraceJob(e){const[{submitTraceJob:t},{default:r}]=await Promise.all([import("../rest/networks/trace.js"),import("../rest/networks/support/TraceParameters.js")]),s=r.from(e);s.gdbVersion=this.gdbVersion,s.moment=this.historicMoment;const i=await t(this.networkServiceUrl,s);return new y({statusUrl:i})}async canAddAssociation(e){const t=await this.getRulesTable();if(!t)return!1;const{fromNetworkElement:r,toNetworkElement:s}=e;if(!r||!s)return!1;await t.load();let i=null;switch(e.associationType){case"containment":i=t.rulesCategorized.containment;break;case"attachment":i=t.rulesCategorized.attachment;break;default:i=t.rulesCategorized.connectivity}return i.some((e=>h(e,r,s)))}generateAddAssociations(e){const{associationsTable:r}=this.networkSystemLayers,{fromNetworkSourceId:s,fromGlobalId:i,fromTerminalId:a,toNetworkSourceId:o,toGlobalId:n,toTerminalId:l,associationType:u,isContentVisible:m,percentAlong:c,globalId:y}=d(r);return{addFeatures:e.map((e=>new t({attributes:{[s]:e.fromNetworkElement?.networkSourceId,[i]:e.fromNetworkElement?.globalId,[a]:e.fromNetworkElement?.terminalId,[o]:e.toNetworkElement?.networkSourceId,[n]:e.toNetworkElement?.globalId,[l]:e.toNetworkElement?.terminalId,[u]:p[e.associationType],[m]:null==e.isContentVisible?void 0:e.isContentVisible?1:0,[c]:e.percentAlong,[y]:e.globalId}}))),id:this.networkSystemLayers.associationsTableId,identifierFields:{globalIdField:r?.globalIdField??"globalid",objectIdField:r?.objectIdField??"objectid"}}}generateDeleteAssociations(e){const{associationsTable:t,associationsTableId:r}=this.networkSystemLayers;return{deleteFeatures:e.map((e=>({globalId:e.globalId}))),id:r,identifierFields:{globalIdField:t?.globalIdField??"globalid",objectIdField:t?.objectIdField??"objectid"}}}async loadAssociationsTable(){return this.networkSystemLayers.loadAssociationsTable()}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=this.networkSystemLayers.rulesTableUrl,t=new a({url:e});await t.load();const r=this.dataElement?.domainNetworks;if(!r)return null;const s=r.flatMap((e=>[...e.edgeSources||[],...e.junctionSources||[]])),i=(await b(t)).map((e=>this._hydrateRuleInfo(t,s,e)));return new l({rulesLayer:t,rules:i})}_hydrateRuleInfo(e,t,r){const s=e.fieldsIndex,i=s.get("RULETYPE"),a=s.get("CREATIONDATE"),o=s.get("FROMNETWORKSOURCEID"),n=s.get("FROMASSETGROUP"),l=s.get("FROMASSETTYPE"),u=s.get("FROMTERMINALID"),d=s.get("TONETWORKSOURCEID"),m=s.get("TOASSETGROUP"),c=s.get("TOASSETTYPE"),y=s.get("TOTERMINALID"),p=s.get("VIANETWORKSOURCEID"),h=s.get("VIAASSETGROUP"),I=s.get("VIAASSETTYPE"),g=s.get("VIATERMINALID"),b=r.attributes[i.name],w=new Date(r.attributes[a.name]),T=[{networkSourceId:r.attributes[o.name],assetGroupId:r.attributes[n.name],assetTypeId:r.attributes[l.name],terminalId:r.attributes[u.name]},{networkSourceId:r.attributes[d.name],assetGroupId:r.attributes[m.name],assetTypeId:r.attributes[c.name],terminalId:r.attributes[y.name]},{networkSourceId:r.attributes[p.name],assetGroupId:r.attributes[h.name],assetTypeId:r.attributes[I.name],terminalId:r.attributes[g.name]}];let k;!function(e){e[e.from=0]="from",e[e.to=1]="to",e[e.via=2]="via"}(k||(k={}));const N={ruleType:b,creationDate:w};for(const S of[k.from,k.to,k.via]){if(b!==f.RTEdgeJunctionEdgeConnectivity&&S===k.via)continue;const e=T[S],r=t.find((t=>t.sourceId===e.networkSourceId)),s=r?.assetGroups.find((t=>t.assetGroupCode===e.assetGroupId)),i=s?.assetTypes.find((t=>t.assetTypeCode===e.assetTypeId)),a=this._getTerminal(i,e);let o="";switch(S){case k.from:o="from";break;case k.to:o="to";break;case k.via:o="via"}N[`${o}NetworkSource`]=r,N[`${o}AssetGroup`]=s,N[`${o}AssetType`]=i,N[`${o}Terminal`]=a?.toJSON()}return N}_getTerminal(e,t){const r=e?.terminalConfigurationId,s=this.terminalConfigurations?.find((e=>e.id===r));return s?.terminals?.find((e=>e.id===t.terminalId))??null}};async function b(e){const t=new I({where:"1=1",outFields:["*"]});return(await o(e,t)).features}e([s({type:[u],json:{origins:{"web-map":{read:{source:"traceConfigurations"},write:{target:"traceConfigurations"}},service:{read:{source:"traceConfigurations"}}},read:!1}})],g.prototype,"sharedNamedTraceConfigurations",void 0),e([s({type:["utility"],readOnly:!0,json:{read:!1,write:!1}})],g.prototype,"type",void 0),e([s({readOnly:!0})],g.prototype,"serviceTerritoryFeatureLayerId",null),e([s({readOnly:!0})],g.prototype,"networkSystemLayers",null),e([s({readOnly:!0})],g.prototype,"terminalConfigurations",null),e([s({readOnly:!0})],g.prototype,"domainNetworkNames",null),e([s({readOnly:!0})],g.prototype,"hasTelecomNetwork",null),g=e([i("esri.networks.UtilityNetwork")],g);const w=g;export{w as default};