UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 9.48 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 t}from"../../chunks/tslib.es6.js";import i from"../../Graphic.js";import"../../intl.js";import s from"../../core/Accessor.js";import o from"../../core/Collection.js";import e from"../../core/Error.js";import r from"../../core/Logger.js";import{watch as n}from"../../core/reactiveUtils.js";import{property as a}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as c}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as l}from"../../core/support/UpdatingHandles.js";import h from"../../layers/GraphicsLayer.js";import y from"../../symbols/LineSymbolMarker.js";import m from"../../symbols/SimpleLineSymbol.js";import{addUniqueLayer as u}from"../../views/draw/support/layerUtils.js";import{onLocaleChange as p}from"../../intl/locale.js";import{fetchMessageBundle as A}from"../../intl/messages.js";const w={noAssociationTypeSpecified:-2147208504};let d=class extends s{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 l,this.autoRefreshAssociations=!1,this.connectivityAssociationsLineSymbol=new m({style:"short-dash",width:2,color:[190,159,159,1]}),this.executionError="",this.loadErrors=new o,this.maxAllowableAssociations=250,this.showAssociationsEnabled=!1,this.showArrowsConnectivity=!1,this.showArrowsStructuralAttachment=!1,this.structuralAttachmentAssociationsLineSymbol=new m({style:"short-dash",width:2,color:[159,190,159,1]})}initialize(){const t=async()=>{this.messages||(this.messages=await A("esri/widgets/UtilityNetworkAssociations/t9n/UtilityNetworkAssociations"))};t().then((()=>{this.view||(this.view=null),this.utilityNetwork||(this.utilityNetwork=null),this.addHandles([n((()=>[this.view,this.utilityNetwork]),(async()=>{const{loadErrors:t,messages:{info:{noUtilityNetwork:i,noView:s}}}=this;this._initialValidationsFinished=!1,t.removeAll();let o=!1,n=!1;this.removeAssociations(),"2d"===this.view?.type?(u(this.view,this._internalGraphicsLayerConnectivity),u(this.view,this._internalGraphicsLayerStructuralAttachment),o=!0):(this.loadErrors.push(s),r.getLogger(this).error(new e("utilityNetworkAssociations:missing-property",s))),"utility"===this.utilityNetwork?.type?n=!0:(this.loadErrors.push(i),r.getLogger(this).error(new e("utilityNetworkAssociations:missing-property",i))),o&&n&&this.showAssociationsEnabled&&await this.showAssociations(),this._internalGraphicsLayerConnectivity.visible=this.includeConnectivityAssociations,this._internalGraphicsLayerStructuralAttachment.visible=this.includeStructuralAttachmentAssociations,this._initialValidationsFinished=!0}),{initial:!0}),n((()=>[this.view?.stationary,this.showAssociationsEnabled,this.maxAllowableAssociations]),(async()=>{this.view?.stationary&&this.showAssociationsEnabled&&(this.includeConnectivityAssociations||this.includeStructuralAttachmentAssociations)&&await this.showAssociations()})),n((()=>[this.showArrowsConnectivity]),(()=>{const t=this.connectivityAssociationsLineSymbol.clone();t.marker=null,this.showArrowsConnectivity&&(t.marker=new y({color:this.connectivityAssociationsLineSymbol.color,placement:"end",style:"arrow"}));for(const i of this._internalGraphicsLayerConnectivity.graphics)i.symbol=t})),n((()=>[this.showArrowsStructuralAttachment]),(()=>{const t=this.structuralAttachmentAssociationsLineSymbol.clone();t.marker=null,this.showArrowsStructuralAttachment&&(t.marker=new y({color:this.structuralAttachmentAssociationsLineSymbol.color,placement:"end",style:"arrow"}));for(const i of this._internalGraphicsLayerStructuralAttachment.graphics)i.symbol=t})),n((()=>{const{cap:t,color:i,style:s,width:o,marker:e}=this.connectivityAssociationsLineSymbol;return[t,i,s,o,e]}),(()=>{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 y({color:this.connectivityAssociationsLineSymbol.color,placement:"end",style:"arrow"}))})),n((()=>{const{cap:t,color:i,style:s,width:o,marker:e}=this.structuralAttachmentAssociationsLineSymbol;return[t,i,s,o,e]}),(()=>{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 y({color:this.structuralAttachmentAssociationsLineSymbol.color,placement:"end",style:"arrow"}))})),p(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.utilityNetwork}set utilityNetwork(t){this._get("utilityNetwork")!==t&&this._set("utilityNetwork",t)}get view(){return this.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:o}},utilityNetwork:r}=this;this._set("executionError","");const n={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(r?.synthesizeAssociationGeometries(n).then((o=>{let e=[],r=[];return o?.maxGeometryCountExceeded?(this.removeAssociations(),void this._set("executionError",t)):0===o?.associations.length?(this.removeAssociations(),void this._set("executionError",s)):void(o&&(e=o?.associations.filter((({associationType:t})=>"connectivity"===t)).map((t=>(this.connectivityAssociationsLineSymbol.marker=null,this.showArrowsConnectivity&&(this.connectivityAssociationsLineSymbol.marker=new y({color:this.connectivityAssociationsLineSymbol.color,placement:"end",style:"arrow"})),new i({geometry:t.geometry.clone(),symbol:this.connectivityAssociationsLineSymbol})))),r=o.associations.filter((({associationType:t})=>"attachment"===t)).map((t=>(this.structuralAttachmentAssociationsLineSymbol.marker=null,this.showArrowsStructuralAttachment&&(this.structuralAttachmentAssociationsLineSymbol.marker=new y({color:this.structuralAttachmentAssociationsLineSymbol.color,placement:"end",style:"arrow"})),new i({geometry:t.geometry.clone(),symbol:this.structuralAttachmentAssociationsLineSymbol})))),this._internalGraphicsLayerConnectivity.removeAll(),e.length>0&&this._internalGraphicsLayerConnectivity.addMany(e),this._internalGraphicsLayerStructuralAttachment.removeAll(),r.length>0&&this._internalGraphicsLayerStructuralAttachment.addMany(r)))}),(t=>{let i="Error: "+t;if(t instanceof e&&t.details?.raw)if(t.details.raw.extendedCode===w.noAssociationTypeSpecified)i=o;else i=t.details.message;this._set("executionError",i)})))}_createInternalGraphicsLayer(t){return new h({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([a()],d.prototype,"_initialValidationsFinished",void 0),t([a()],d.prototype,"autoRefreshAssociations",void 0),t([a({type:m,nonNullable:!0})],d.prototype,"connectivityAssociationsLineSymbol",void 0),t([a({readOnly:!0})],d.prototype,"executionError",void 0),t([a({type:Boolean,value:!0})],d.prototype,"includeConnectivityAssociations",null),t([a({type:Boolean,value:!0})],d.prototype,"includeStructuralAttachmentAssociations",null),t([a()],d.prototype,"loadErrors",void 0),t([a()],d.prototype,"maxAllowableAssociations",void 0),t([a()],d.prototype,"messages",void 0),t([a()],d.prototype,"showAssociationsEnabled",void 0),t([a()],d.prototype,"showArrowsConnectivity",void 0),t([a()],d.prototype,"showArrowsStructuralAttachment",void 0),t([a({readOnly:!0})],d.prototype,"state",null),t([a({type:m,nonNullable:!0})],d.prototype,"structuralAttachmentAssociationsLineSymbol",void 0),t([a()],d.prototype,"utilityNetwork",null),t([a()],d.prototype,"view",null),d=t([c("esri.widgets.UtilityNetworkAssociations.UtilityNetworkAssociationsViewModel")],d);const v=d;export{v as default};