UNPKG

@arcgis/map-components

Version:
2 lines 9.68 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */ import a from"./R3NYK6BO.js";import{a as A}from"./HZFVK34O.js";import"./AKBXFBDL.js";import"./LMBRORN7.js";import"./PBSJQPB2.js";import{O as C,U as x,a as I,b as w,p as c,r as m,x as T}from"./WUJCCZQC.js";import"./3TTFCHAA.js";export default $arcgis.t(([G,L,u,N,$,F,_,S,{c:k,f:P}])=>{var H=I`calcite-block{--calcite-block-content-space: 0;--calcite-block-border-color: transparent;margin:0}.add-location-button{--calcite-button-border-color: var(--calcite-color-border-1);--calcite-button-icon-color: var(--calcite-color-text-1);--calcite-button-text-color: var(--calcite-color-text-1)}.button-container{justify-content:center;display:grid}.clear-button{--calcite-button-border-color: transparent}`,v=class extends C{constructor(){super(...arguments),this.messages=A({blocking:!0}),this.isSelectWaiting=!1,this.traceLocationType="starting-point",this.spatialTolerance=.05,this.autoDestroyDisabled=!1,this.arcgisTraceLocationChange=T(),this.arcgisTraceLocationSelectEnd=T(),this.arcgisTraceLocationSelectStart=T()}static{this.properties={isSelectWaiting:16,beforeTraceLocationSelectStart:0,afterHitTest:0,view:0,traceLocationType:1,traceLocations:0,filterLayers:0,sketchViewModel:0,spatialTolerance:9,autoDestroyDisabled:5,utilityNetwork:0}}static{this.styles=H}async destroy(){this._resetCursor(),await this.manager.destroy()}async load(){u.isLoaded()||await u.load()}_calculatePercentAlong(t,e){let r=t.clone(),l=r.spatialReference,o=e.spatialReference;if(!l||!o)return c("warn",this,"Unable to calculate percent along because geometry is missing a spatial reference."),-1;let i=e;if(!l.equals(o)){let f=u.execute(e,l);if(!f)return c("warn",this,"Unable to project flag point to source geometry spatial reference."),-1;i=f}let s=N.getNearestCoordinate(r,i);if(s.isEmpty)return c("warn",this,"Unable to compute nearest coordinate for polyline flag."),-1;let a=s.coordinate,n=a.x-.5,p=a.y-.5,h=a.x+.5,g=a.y+.5,y=new $({hasZ:!1,hasM:!0,paths:[[[n,p],[h,g]]],spatialReference:r.spatialReference}),d=G.execute(r,y);if(d.length>0){let f=L.execute(r,{unit:"feet"}),b;return d[0].paths[0][0][0]===r.paths[0][0][0]?b=L.execute(d[0],{unit:"feet"}):d.length>1?b=L.execute(d[1],{unit:"feet"}):b=0,b/f}return c("warn",this,"Unable to cut the source geometry with the flag geometry."),-1}get _edgeSourceLayerIds(){let t=this.utilityNetwork?.dataElement?.domainNetworks;return t?t.flatMap(e=>e.edgeSources).map(e=>e.layerId).filter(Boolean):[]}async _handleAddButtonClick(){let{view:t,sketchViewModel:e}=this;if(!(t&&e)){c("error",this,"Cannot add trace location."),e||c("error",this,m("sketchViewModel")),t||c("error",this,m("view"));return}if(this.beforeTraceLocationSelectStart){this.isSelectWaiting=!0;try{await this.beforeTraceLocationSelectStart()}finally{this.isSelectWaiting=!1}}await this._startSketch(t,e)}async _startSketch(t,e){this.arcgisTraceLocationSelectStart.emit({cancelSelect:()=>e.cancel()}).defaultPrevented||(this._clickHandler?.remove(),this._clickHandler=e.on("create",r=>this._handleSketchComplete(r,t,e)),"acquireCursor"in t&&t.acquireCursor("crosshair"),e.snappingOptions.enabled=!0,e.create("point"))}_handleSketchComplete(t,e,r){if(t.state==="complete"&&t.graphic){r.layer.remove(t.graphic),this._performHitTest(t,e,r);return}t.state==="cancel"&&(this._resetCursor(),this.arcgisTraceLocationSelectEnd.emit())}async _performHitTest(t,e,r){let{utilityNetwork:l}=this,{graphic:o}=t;if(!l){c("error",this,m("utilityNetwork")),this._resetCursor(),this.arcgisTraceLocationSelectEnd.emit();return}if(o?.geometry?.type!=="point"){c("warn",this,"No screen point available for hit test."),this._startSketch(e,r);return}let i=o.geometry,s=e.toScreen(i);if(!s){c("warn",this,"No screen point available for hit test."),this._startSketch(e,r);return}let a=(await e.hitTest(s,{include:this.filterLayers})).results.filter(n=>n.type==="graphic"&&n?.layer&&n.graphic);if(!a.length){c("info",this,"No usable hit test results found."),this._startSketch(e,r);return}this._resetCursor(),await this._processHitTestResults(a,i,e)?this.arcgisTraceLocationSelectEnd.emit():this._startSketch(e,r)}_resetCursor(){let{view:t,sketchViewModel:e}=this;if(!t){c("error",this,m("view"));return}e&&(e.snappingOptions.enabled=!1),this._clickHandler?.remove(),this._clickHandler=void 0,"acquireCursor"in t&&t.acquireCursor("default")}async _processHitTestResults(t,e,r){if(!t.length)return c("error",this,"There are no hit test results to process."),!1;let l=t[0],o=t.map(a=>{let n=a,p=n.graphic;return p.origin=n.layer,p.sourceLayer=n.layer,p}),i=l.graphic;if(this.afterHitTest)try{i=await this.afterHitTest(o)}catch{i=null}if(!i)return c("error",this,"No graphic available from hit test results."),this.arcgisTraceLocationSelectEnd.emit(),!0;let s=await this._ensureNecessaryAttributes(i);return s?await this._generateTraceLocation(s,e,r):(c("error",this,"Unable to ensure necessary attributes on the selected graphic."),this.arcgisTraceLocationSelectEnd.emit(),!0)}async _ensureNecessaryAttributes(t){let e=(k(t.layer),t.layer),r=e.geometryType===null,l=e.fieldsIndex?.get("assetgroup")??!1,o=e.fieldsIndex?.get("assetgroup")?.name??"assetgroup",i=e.fieldsIndex?.get("assettype")??!1,s=e.fieldsIndex?.get("assettype")?.name??"assettype",a=t.getGlobalId(),n=t.getObjectId(),p=l?!!t.getAttribute(o):!0,h=i?!!t.getAttribute(s):!0,g=!!t.geometry;if(a&&n&&p&&h&&(g||r))return t;let y=e.createQuery();return y.objectIds=[n],(await e.queryFeatures(y))?.features[0]||null}async _generateTraceLocation(t,e,r){let{traceLocations:l}=this,o=t.getGlobalId()??"",i=t.geometry?.type,s=await this._generateFlagInfo(t,e);if(!s)return c("error",this,"Unable to generate flag info for trace location."),!1;let a=l?.filter(p=>p.spatialProperties.mapGraphic?.getGlobalId()===o)??[];if(a.length>0){if(i!=="polyline")return c("warn",this,"A flag with the same globalId already exists."),!1;if(a.some(p=>Math.abs(p.traceLocation.percentAlong-s.traceLocation.percentAlong)<=this.spatialTolerance))return c("warn",this,"A flag with the same globalId already exists within tolerance."),!1}let n=this._addFlagGraphic(t,e,r);return n?(s.spatialProperties.flagGraphic=n,l?.add(s),!0):(c("warn",this,"Unable to add flag graphic."),!1)}async _generateFlagInfo(t,e){let{traceLocationType:r,utilityNetwork:l}=this,o=t.getGlobalId()??"",i=t.geometry?.type,s=await this._generateItemTitle(t);if(i==="point"||i==="polygon"){let a=l?.getTerminalConfiguration(t),n=a?a.terminals[0].id:1;return{traceLocation:new _({type:r,isFilterBarrier:!1,globalId:o,terminalId:n}),flagProperties:{title:s,expanded:!1,terminalConfiguration:a??void 0,selectedTerminals:a?new Set([n]):void 0},spatialProperties:{mapPoint:e,mapGraphic:t}}}else if(i==="polyline"){let a=this._calculatePercentAlong(t.geometry,e);return a<0?(c("warn",this,"Unable to calculate percent along for polyline flag."),null):{traceLocation:new _({type:r,isFilterBarrier:!1,globalId:o,percentAlong:a}),flagProperties:{title:s,expanded:!1,terminalConfiguration:void 0,selectedTerminals:void 0},spatialProperties:{mapPoint:e,mapGraphic:t}}}else if(!i){let a=P(t.layer)?t.layer.parent:t.layer,n=a&&this._edgeSourceLayerIds.includes(a.layerId),p=l?.getTerminalConfiguration(t),h=p?p.terminals[0].id:n?-1:1,g=n?.5:-1;return{traceLocation:new _({type:r,isFilterBarrier:!1,globalId:o,terminalId:h,percentAlong:g}),flagProperties:{title:s,expanded:!1,terminalConfiguration:p??void 0,selectedTerminals:p?new Set([h]):void 0},spatialProperties:{mapPoint:e,mapGraphic:t}}}return null}async _generateItemTitle(t){let{messages:e}=this,r=(k(t.layer),t.layer);return("getFeatureTitle"in r?await r.getFeatureTitle(t):null)||t?.getObjectId()?.toString()||e.labels.unknown}_addFlagGraphic(t,e,r){let l=t.geometry?t.geometry.type==="point"?t.geometry:e:null,o=this._createFlagSymbol(),i=new F({geometry:l,symbol:o,attributes:t.attributes});return r.graphics.add(i),i}_createFlagSymbol(){let{traceLocationType:t}=this,e=[244,21,21,.6],r=[21,244,21,.6];return t==="stopping-point"?new S({color:e,style:"x",size:12,outline:{color:e,width:2}}):t==="barrier"?new S({color:e,style:"square",size:12,outline:{color:e,width:0}}):new S({color:r,style:"circle",size:12,outline:{color:r,width:0}})}_handleClearButtonClick(){let{view:t,traceLocations:e}=this;e?.forEach(r=>{r.spatialProperties.flagGraphic&&t&&t.graphics.remove(r.spatialProperties.flagGraphic)}),e?.removeAll()}renderAddLocationBlock(){let{traceLocationType:t,messages:e,traceLocations:r,view:l}=this,o=t==="starting-point"?e.types.startingPoint:t==="barrier"?e.types.barrier:e.types.stoppingPoint,i=o.heading,s=o.description,a=o.buttonText;return w`<calcite-block .heading=${i} .label=${i} expanded .description=${s}>${r?.length?w`<calcite-button class="clear-button" slot=actions-end appearance=transparent .label=${e.buttons.clear} @click=${()=>this._handleClearButtonClick()}>${e.buttons.clear}</calcite-button><arcgis-utility-network-trace-location-list .traceLocations=${r} .traceLocationType=${t} .view=${l}></arcgis-utility-network-trace-location-list>`:null}<div class="button-container"><calcite-button .loading=${this.isSelectWaiting} class="add-location-button" icon-start=select appearance=outline .label=${a} @click=${()=>this._handleAddButtonClick()}>${a}</calcite-button></div></calcite-block>`}render(){return w`<div class="root">${this.renderAddLocationBlock()}</div>`}};x("arcgis-utility-network-trace-location",v);return v},"geometry/operators/cutOperator","geometry/operators/lengthOperator","geometry/operators/projectOperator","geometry/operators/proximityOperator","geometry/Polyline","Graphic","rest/networks/support/TraceLocation","symbols/SimpleMarkerSymbol",a)