UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 9.55 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as t}from"tslib";import i from"../../Graphic.js";import{onLocaleChange as s,fetchMessageBundle as e}from"../../intl.js";import o from"../../core/Accessor.js";import r from"../../core/Collection.js";import{deprecatedModule as n}from"../../core/deprecate.js";import a from"../../core/Error.js";import c from"../../core/Logger.js";import{watch as l}from"../../core/reactiveUtils.js";import{property as h,subclass as y}from"../../core/accessorSupport/decorators.js";import{UpdatingHandles as m}from"../../core/support/UpdatingHandles.js";import u from"../../layers/GraphicsLayer.js";import A from"../../symbols/LineSymbolMarker.js";import p from"../../symbols/SimpleLineSymbol.js";import{addUniqueLayer as w}from"../../views/draw/support/layerUtils.js";const d={noAssociationTypeSpecified:-2147208504};n(c.getLogger("esri.widgets.UtilityNetworkAssociations.UtilityNetworkAssociationViewModel"),"UtilityNetworkAssociationViewModel",{replacement:"UtilityNetwork.synthesizeAssociationGeometries",version:"5.0",see:"https://esriurl.com/UtilityNetworkClass#synthesizeAssociationGeometries",warnOnce:!0});let v=class extends o{constructor(t){super(t),this._internalGraphicsLayerConnectivity=this._createInternalGraphicsLayer("Connectivity Associations (Internal)"),this._internalGraphicsLayerStructuralAttachment=this._createInternalGraphicsLayer("Structural Attachment Associations (Internal)"),this._initialValidationsFinished=!1,this._updatingHandles=new m,this.autoRefreshAssociations=!1,this.connectivityAssociationsLineSymbol=new p({style:"short-dash",width:2,color:[190,159,159,1]}),this.executionError="",this.loadErrors=new r,this.maxAllowableAssociations=250,this.showAssociationsEnabled=!1,this.showArrowsConnectivity=!1,this.showArrowsStructuralAttachment=!1,this.structuralAttachmentAssociationsLineSymbol=new p({style:"short-dash",width:2,color:[159,190,159,1]})}initialize(){const t=async()=>{this.messages||(this.messages=await e("esri/widgets/UtilityNetworkAssociations/t9n/UtilityNetworkAssociations"))};t().then(()=>{this.view||(this.view=null),this.utilityNetwork||(this.utilityNetwork=null),this.addHandles([l(()=>[this.view,this.utilityNetwork],async()=>{const{loadErrors:t,messages:{info:{noUtilityNetwork:i,noView:s}}}=this;this._initialValidationsFinished=!1,t.removeAll();let e=!1,o=!1;this.removeAssociations(),"2d"===this.view?.type?(w(this.view,this._internalGraphicsLayerConnectivity),w(this.view,this._internalGraphicsLayerStructuralAttachment),e=!0):(this.loadErrors.push(s),c.getLogger(this).error(new a("utilityNetworkAssociations:missing-property",s))),"utility"===this.utilityNetwork?.type?o=!0:(this.loadErrors.push(i),c.getLogger(this).error(new a("utilityNetworkAssociations:missing-property",i))),e&&o&&this.showAssociationsEnabled&&await this.showAssociations(),this._internalGraphicsLayerConnectivity.visible=this.includeConnectivityAssociations,this._internalGraphicsLayerStructuralAttachment.visible=this.includeStructuralAttachmentAssociations,this._initialValidationsFinished=!0},{initial:!0}),l(()=>[this.view?.stationary,this.showAssociationsEnabled,this.maxAllowableAssociations],async()=>{this.view?.stationary&&this.showAssociationsEnabled&&(this.includeConnectivityAssociations||this.includeStructuralAttachmentAssociations)&&await this.showAssociations()}),l(()=>[this.showArrowsConnectivity],()=>{const t=this.connectivityAssociationsLineSymbol.clone();t.marker=null,this.showArrowsConnectivity&&(t.marker=new A({color:this.connectivityAssociationsLineSymbol.color,placement:"end",style:"arrow"}));for(const i of this._internalGraphicsLayerConnectivity.graphics)i.symbol=t}),l(()=>[this.showArrowsStructuralAttachment],()=>{const t=this.structuralAttachmentAssociationsLineSymbol.clone();t.marker=null,this.showArrowsStructuralAttachment&&(t.marker=new A({color:this.structuralAttachmentAssociationsLineSymbol.color,placement:"end",style:"arrow"}));for(const i of this._internalGraphicsLayerStructuralAttachment.graphics)i.symbol=t}),l(()=>{const{cap:t,color:i,style:s,width:e,marker:o}=this.connectivityAssociationsLineSymbol;return[t,i,s,e,o]},()=>{const t=this.connectivityAssociationsLineSymbol.clone();for(const i of this._internalGraphicsLayerConnectivity.graphics)i.symbol=t;this.showArrowsConnectivity=!1,t.marker=null,this.connectivityAssociationsLineSymbol.marker&&(this.showArrowsConnectivity=!0,t.marker=new A({color:this.connectivityAssociationsLineSymbol.color,placement:"end",style:"arrow"}))}),l(()=>{const{cap:t,color:i,style:s,width:e,marker:o}=this.structuralAttachmentAssociationsLineSymbol;return[t,i,s,e,o]},()=>{const t=this.structuralAttachmentAssociationsLineSymbol.clone();for(const i of this._internalGraphicsLayerStructuralAttachment.graphics)i.symbol=t;this.showArrowsStructuralAttachment=!1,t.marker=null,this.structuralAttachmentAssociationsLineSymbol.marker&&(this.showArrowsStructuralAttachment=!0,t.marker=new A({color:this.structuralAttachmentAssociationsLineSymbol.color,placement:"end",style:"arrow"}))}),s(t)])})}destroy(){this._updatingHandles.destroy(),this.view=null,this._removeInternalGraphicsLayers()}set includeConnectivityAssociations(t){this._set("includeConnectivityAssociations",t),this._internalGraphicsLayerConnectivity.visible=t}set includeStructuralAttachmentAssociations(t){this._set("includeStructuralAttachmentAssociations",t),this._internalGraphicsLayerStructuralAttachment.visible=t}get state(){return this.loadErrors.length?"disabled":this._updatingHandles.updating?"executing":""!==this.executionError?"warning":this._initialValidationsFinished?"ready":"loading"}get utilityNetwork(){return this._get("utilityNetwork")}set utilityNetwork(t){this._get("utilityNetwork")!==t&&this._set("utilityNetwork",t)}get view(){return this._get("view")}set view(t){this._get("view")!==t&&this._set("view",t)}removeAssociations(){this._internalGraphicsLayerConnectivity.removeAll(),this._internalGraphicsLayerStructuralAttachment.removeAll()}async showAssociations(){const{messages:{info:{maxAllowableAssociationsExceeded:t,noAssociationsFound:s,noAssociationTypeSpecified:e}},utilityNetwork:o}=this;this._set("executionError","");const r={extent:this.view?.extent,gdbVersion:this.utilityNetwork?.gdbVersion,maxGeometryCount:this.maxAllowableAssociations,moment:this.utilityNetwork?.historicMoment,outSpatialReference:this.view?.spatialReference.clone(),returnConnectivityAssociations:this.includeConnectivityAssociations,returnAttachmentAssociations:this.includeStructuralAttachmentAssociations};this._updatingHandles.addPromise(o?.synthesizeAssociationGeometries(r).then(e=>{let o=[],r=[];return e?.maxGeometryCountExceeded?(this.removeAssociations(),void this._set("executionError",t)):0===e?.associations.length?(this.removeAssociations(),void this._set("executionError",s)):void(e&&(o=e?.associations.filter(({associationType:t})=>t.toLowerCase().includes("connectivity")).map(t=>(this.connectivityAssociationsLineSymbol.marker=null,this.showArrowsConnectivity&&(this.connectivityAssociationsLineSymbol.marker=new A({color:this.connectivityAssociationsLineSymbol.color,placement:"end",style:"arrow"})),new i({geometry:t.geometry.clone(),symbol:this.connectivityAssociationsLineSymbol}))),r=e.associations.filter(({associationType:t})=>"attachment"===t).map(t=>(this.structuralAttachmentAssociationsLineSymbol.marker=null,this.showArrowsStructuralAttachment&&(this.structuralAttachmentAssociationsLineSymbol.marker=new A({color:this.structuralAttachmentAssociationsLineSymbol.color,placement:"end",style:"arrow"})),new i({geometry:t.geometry.clone(),symbol:this.structuralAttachmentAssociationsLineSymbol}))),this._internalGraphicsLayerConnectivity.removeAll(),o.length>0&&this._internalGraphicsLayerConnectivity.addMany(o),this._internalGraphicsLayerStructuralAttachment.removeAll(),r.length>0&&this._internalGraphicsLayerStructuralAttachment.addMany(r)))},t=>{let i="Error: "+t;if(t instanceof a&&t.details?.raw)if(t.details.raw.extendedCode===d.noAssociationTypeSpecified)i=e;else i=t.details.message;this._set("executionError",i)}))}_createInternalGraphicsLayer(t){return new u({listMode:"hide",internal:!0,title:t})}_removeInternalGraphicsLayers(){this._internalGraphicsLayerConnectivity&&this._internalGraphicsLayerStructuralAttachment&&this.view?.map&&(this.view.map.remove(this._internalGraphicsLayerConnectivity),this.view.map.remove(this._internalGraphicsLayerStructuralAttachment))}};t([h()],v.prototype,"_initialValidationsFinished",void 0),t([h()],v.prototype,"autoRefreshAssociations",void 0),t([h({type:p,nonNullable:!0})],v.prototype,"connectivityAssociationsLineSymbol",void 0),t([h({readOnly:!0})],v.prototype,"executionError",void 0),t([h({type:Boolean,value:!0})],v.prototype,"includeConnectivityAssociations",null),t([h({type:Boolean,value:!0})],v.prototype,"includeStructuralAttachmentAssociations",null),t([h()],v.prototype,"loadErrors",void 0),t([h()],v.prototype,"maxAllowableAssociations",void 0),t([h()],v.prototype,"messages",void 0),t([h()],v.prototype,"showAssociationsEnabled",void 0),t([h()],v.prototype,"showArrowsConnectivity",void 0),t([h()],v.prototype,"showArrowsStructuralAttachment",void 0),t([h({readOnly:!0})],v.prototype,"state",null),t([h({type:p,nonNullable:!0})],v.prototype,"structuralAttachmentAssociationsLineSymbol",void 0),t([h()],v.prototype,"utilityNetwork",null),t([h()],v.prototype,"view",null),v=t([y("esri.widgets.UtilityNetworkAssociations.UtilityNetworkAssociationsViewModel")],v);const L=v;export{L as default};