// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("exports ../../chunks/tslib.es6 ../../geometry ../../Graphic ../../intl ../../symbols ../../core/colorUtils ../../core/handleUtils ../../core/maybe ../../core/reactiveUtils ../../core/unitFormatUtils ../../core/unitUtils ../../core/accessorSupport/decorators/property ../../core/has ../../core/Logger ../../core/RandomLCG ../../core/accessorSupport/decorators/subclass ../../core/support/UpdatingHandles ../../geometry/geometryEngine ../../geometry/projection ../../geometry/support/geodesicUtils ../../layers/GraphicsLayer ../../views/ViewingMode ../../views/2d/interactive/SnappingVisualizer2D ../../views/draw/Draw ../../views/interactive/coordinateHelper ../../views/interactive/dragEventPipeline ../../views/interactive/GraphicManipulator ../../views/interactive/InteractiveToolBase ../../views/interactive/editGeometry/EditGeometry ../../views/interactive/editGeometry/EditGeometryOperations ../../views/interactive/snapping/SnappingContext ../../views/interactive/snapping/SnappingDragPipelineStep ../../views/interactive/snapping/SnappingManagerPool ../../views/interactive/snapping/snappingUtils ../../intl/messages ../../intl/locale ../../geometry/Point ../../symbols/CIMSymbol ../../symbols/TextSymbol ../../symbols/Font ../../symbols/SimpleMarkerSymbol ../../geometry/Polyline ../../geometry/SpatialReference".split(" "), function(e,h,la,y,ma,na,q,O,r,t,z,P,m,oa,pa,qa,Q,R,A,u,n,B,F,S,T,U,C,V,W,X,G,Y,Z,aa,ba,H,ca,D,da,ea,fa,I,ha,J){function ia(a,c,b){var d=q.multiplyOpacity(c.effectiveTheme.accentColor,.5);const f={type:"simple-line",width:0},k=new I({style:"circle",color:d,size:8,outline:f});d=new I({style:"circle",color:d,size:12,outline:f});a=new y({geometry:a,symbol:k});return new V.GraphicManipulator({view:c,layer:b,graphic:a,focusedSymbol:d})}function K(a,c,b){a=new ha({paths:[a],spatialReference:c});if(c.isGeographic)if(n.isSupported(c))b= n.geodesicLengths([a],"meters")[0],c=n.geodesicDensify(a,1E5);else{b=u.project(a,J.WGS84);var d=n.geodesicDensify(b,1E5);b=n.geodesicLengths([b],"meters")[0];c=u.project(d,c)}else c.isWebMercator?(b=A.geodesicLength(a,"meters"),c=A.geodesicDensify(a,1E5,"meters")):(d=A.planarLength(a,"meters"),null!=b&&d>=b?(b=u.project(a,J.WGS84),d=n.geodesicDensify(b,1E5),b=n.geodesicLengths([b],"meters")[0],c=u.project(d,c)):(b=d,c=a));return{measurement:{geometry:c,length:b},original:a,drawing:c}}function L(a, c,b){if(!c||!a)return"";switch(b){case "metric":return z.formatMetricLength(a,c.length,"meters");case "imperial":return z.formatImperialLength(a,c.length,"meters");default:return z.formatDecimal(a,P.convertUnit(c.length,"meters",b),b)}}e.DistanceMeasurement2DTool=class extends W.InteractiveToolBase{constructor(a){super(a);this._drawActive=!1;this._measurementLayer=new B({internal:!0,listMode:"hide",visible:!1});this._manipulatorLayer=new B({internal:!0,listMode:"hide",visible:!1});this._snappingLayer= new B({internal:!0,listMode:"hide",visible:!1});this._updatingHandles=new R.UpdatingHandles;this._vertices=[];this.measurementLabel=this.measurement=this.geodesicDistanceThreshold=null}initialize(){H.fetchMessageBundle("esri/core/t9n/Units").then(c=>{this.messages=c});const a=this.view;this._draw=new T({view:a});a.map.addMany([this._measurementLayer,this._manipulatorLayer,this._snappingLayer]);a.focus();this._snappingManagerResult=aa.acquire(a);this.addHandles([ca.onLocaleChange(async()=>{this.messages= await H.fetchMessageBundle("esri/core/t9n/Units")}),t.watch(()=>[this.unit,this.geodesicDistanceThreshold,this.messages],()=>{this._updatePolylines()},t.initial),t.watch(()=>[this.view.effectiveTheme.accentColor,this.view.effectiveTheme.textColor],()=>{if(this._vertices.length){var c=this._vertices.map(({coord:b})=>b);for(const {handle:b}of this._vertices)b.remove();this._vertices=[];this._measurementLayer.removeAll();this._manipulatorLayer.removeAll();this._snappingLayer.removeAll();this.manipulators.removeAll(); this._updateSketch(c)}}),t.watch(()=>this.snappingOptions.featureSources,c=>{for(const b of c)if(b.layer===this._measurementLayer||b.layer===this._manipulatorLayer)b.enabled=!1},t.initial),this._snappingManagerResult]);ba.setupSnappingToggleHandles(this)}destroy(){const {map:a}=this.view;this._draw.view=null;this._draw=r.destroyMaybe(this._draw);a.removeMany([this._measurementLayer,this._manipulatorLayer,this._snappingLayer]);this._measurementLayer.removeAll();this._manipulatorLayer.removeAll();this._snappingLayer.removeAll(); this._set("measurement",null);this._set("measurementLabel",null);this._measurementLayer=r.destroyMaybe(this._measurementLayer);this._manipulatorLayer=r.destroyMaybe(this._manipulatorLayer);this._snappingLayer=r.destroyMaybe(this._snappingLayer);this._updatingHandles=r.destroyMaybe(this._updatingHandles);this._resetVertices()}get _snappingManager(){return this._snappingManagerResult.snappingManager}get cursor(){return this._drawActive?"crosshair":null}set editable(a){this._set("editable",a);a||this._draw.reset()}get snappingOptions(){return this._snappingManager.options}get updating(){return this._updatingHandles.updating|| this._snappingManager.updating}onActivate(){this._drawActive||0!==this._vertices.length||this._startSketch()}onShow(){this._measurementLayer.visible=!0;this._manipulatorLayer.visible=!0;this._snappingLayer.visible=!0}onHide(){this._measurementLayer.visible=!1;this._manipulatorLayer.visible=!1;this._snappingLayer.visible=!1}_getSnappingContext(a){return new Y.SnappingContext({elevationInfo:{mode:"on-the-ground",offset:0},pointer:a,editGeometryOperations:new G.EditGeometryOperations(new X.EditGeometry("point", U.createCoordinateHelper(!1,!1,this.view.spatialReference)),F.ViewingMode.Local),visualizer:new S.SnappingVisualizer2D(this._snappingLayer)})}_resetVertices(){for(const {handle:a}of this._vertices)a.remove();this._vertices=[]}_startSketch(){this._drawActive=!0;const a=this._draw.create("polyline",{mode:"click",snappingManager:this._snappingManager});a.on("vertex-add vertex-update vertex-remove cursor-update undo redo".split(" "),c=>this._updateSketch(c.vertices));a.on("draw-complete",()=>{this._stopSketch()})}_stopSketch(){this.manipulators.forEach(({manipulator:a})=> {a.interactive=!0});this._drawActive=!1;this.finishToolCreation()}_updateSketch(a){const {spatialReference:c}=this.view;for(;this._vertices.length>a.length;){const {handle:l,manipulator:v}=this._vertices.pop();l.remove();this.manipulators.remove(v)}for(let l=this._vertices.length;l{if(p=p.vertices.at(0))this._vertices[l].coord=[p.pos[0],p.pos[1]],this._updatePolylines()}),C.createManipulatorDragEventPipeline(d,(p,ja,x,ka)=>{x=this._getSnappingContext(ka);({snappingStep:x}=Z.createSnapDragEventPipelineStep({snappingContext:x,snappingManager:this._snappingManager,updatingHandles:this._updatingHandles}));ja.next(C.screenToMap(this.view)).next(E=>{if("start"===E.action){const N=new D(E.mapStart);p.graphic.geometry=N;w.trySetGeometry(N)}return E}).next(...x).next(C.dragManipulatedObject({operations:w})).next(()=> {p.graphic.geometry=w.data.geometry})})];this._vertices.push({manipulator:d,coord:[v,M],handle:O.handlesGroup(b)})}d=this._vertices.length-1;b=this._vertices[d];const [f,k]=a[d];if(b.coord[0]!==f||b.coord[1]!==k)b.coord=[f,k],b.manipulator.graphic.geometry=new D({x:f,y:k,spatialReference:c});const g=this._drawActive?this._vertices[d].manipulator:null;this.manipulators.forEach(({manipulator:l})=>{l.interactive=null==g||l!==g});this._updatePolylines()}_updatePolylines(){if(2>this._vertices.length)this._measurementLayer.removeAll(); else{var a=this._vertices.map(({coord:l})=>l),{measurement:c,drawing:b,original:d}=K(a,this.view.spatialReference,this.geodesicDistanceThreshold);this._set("measurement",c);a=L(this.messages,c,this.unit);this._set("measurementLabel",a);var {graphics:f}=this._measurementLayer;var k=2===f.length;({effectiveTheme:g}=this.view);if(k){k=f.at(0);var g=f.at(1)}else k=new y({symbol:new da({data:{type:"CIMSymbolReference",symbol:{type:"CIMLineSymbol",symbolLayers:[{type:"CIMSolidStroke",effects:[{type:"CIMGeometricEffectDashes", dashTemplate:[14,12],lineDashEnding:"FullGap",controlPointEnding:"NoConstraint"}],enable:!0,capStyle:"Butt",joinStyle:"Round",width:3.5,color:q.getContrast(g.accentColor).toArray()},{type:"CIMSolidStroke",enable:!0,capStyle:"Butt",joinStyle:"Round",width:5,color:g.accentColor.toArray()}]}}})}),g=new y({symbol:new ea({color:g.textColor,haloColor:q.multiplyOpacity(q.getContrast(g.textColor,q.BrightnessThreshold.Low),.5),haloSize:2,font:new fa({size:14,family:"sans-serif"})})}),f.removeAll(),f.addMany([k, g]);k.geometry=b;g.geometry=d.extent?.center;g.symbol.text=a}}};h.__decorate([m.property()],e.DistanceMeasurement2DTool.prototype,"_drawActive",void 0);h.__decorate([m.property({readOnly:!0})],e.DistanceMeasurement2DTool.prototype,"cursor",null);h.__decorate([m.property({value:!0})],e.DistanceMeasurement2DTool.prototype,"editable",null);h.__decorate([m.property({type:Number})],e.DistanceMeasurement2DTool.prototype,"geodesicDistanceThreshold",void 0);h.__decorate([m.property({readOnly:!0})],e.DistanceMeasurement2DTool.prototype, "measurement",void 0);h.__decorate([m.property({readOnly:!0})],e.DistanceMeasurement2DTool.prototype,"measurementLabel",void 0);h.__decorate([m.property()],e.DistanceMeasurement2DTool.prototype,"messages",void 0);h.__decorate([m.property()],e.DistanceMeasurement2DTool.prototype,"unit",void 0);h.__decorate([m.property()],e.DistanceMeasurement2DTool.prototype,"updating",null);h.__decorate([m.property({constructOnly:!0})],e.DistanceMeasurement2DTool.prototype,"view",void 0);e.DistanceMeasurement2DTool= h.__decorate([Q.subclass("esri.widgets.DistanceMeasurement2D.DistanceMeasurement2DTool")],e.DistanceMeasurement2DTool);e.createDistanceMeasurementInfo2D=K;e.createDistanceMeasurementLabel=L;e.isProjectionEngineRequired=function(a){if(!a)return!1;const {isGeographic:c,isWebMercator:b,isWGS84:d}=a;return c&&!d&&!n.isSupported(a)||!c&&!b};e.isSupported=function(a){return null!=a};Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});