UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 2.04 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import e from"../../../Graphic.js";import r from"../../../PopupTemplate.js";import t from"../../../layers/GraphicsLayer.js";import o from"../../../popup/FieldInfo.js";import a from"../../../symbols/SimpleFillSymbol.js";import{GeometryHandler as i}from"./GeometryHandler.js";const n=`utility-network-trace-result-area-${Date.now()}`;function l(e){return"graphics"===e.type}class s{constructor(){this.traceInformation={},this._geometryHandler=new i}addResultAreaToMap(e,r){const t=this.createGraphicLayer(r);t&&l(t)&&t.add(e)}changeResultAreaColor(e,r,t){const o=new a({color:r.color,style:"solid",outline:{color:r.color,width:1}}),i=this._findGraphicsByTraceId(e,t);return i&&i.forEach((e=>{e.symbol=o})),o}createBuffer(e,r,t,o){return this._geometryHandler.createBuffer(e,r,t,o)}createConvexHull(e,r,t){const o=this._geometryHandler.createConvexHull(e);return r>0&&o?this.createBuffer(o,[r],t,!1):o}createResultAreaGraphic(t,i,n,l,s,c){const u=new a({color:c.color,style:"solid",outline:{color:c.color,width:1}}),d=[];for(const e in i)d.push(new o({fieldName:e,label:"areaStatistic"===e?l.attributeStrings[e]+" ("+s.units[n]?.abbr+")":l.attributeStrings[e]}));return new e({geometry:t,symbol:u,attributes:i,popupTemplate:new r({title:i.traceName,content:[{type:"fields",fieldInfos:d}]})})}removeResultArea(e,r){const t=r.findLayerById(n);if(t&&l(t)){const o=this._findGraphicsByTraceId(e,r);return o&&t.removeMany(o),o}return null}removeAllResultAreaGraphics(e){if(e){const r=e.findLayerById(n);r&&l(r)&&r.removeAll()}}createGraphicLayer(e,r){const o=e.findLayerById(n);if(o&&l(o))return o;const a=new t({title:r??n,listMode:"hide",id:n});return e.add(a),a}_findGraphicsByTraceId(e,r){const t=r.findLayerById(n);if(t&&l(t)){const r=t.graphics.filter((r=>r.attributes.traceId===e));return r.length>0?r.toArray():null}return null}}export{s as ResultAreaHandler,n as resultAreaGraphicLayer};