// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://@sbaseurl@/jsapi/jsapi/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.

//>>built
define("dojo/_base/declare dojo/_base/lang dojo/_base/connect dojo/has dojo/topic esri/toolbars/draw esri/graphic esri/geometry/Polyline esri/geometry/geometryEngine jimu/utils ./Feedback".split(" "),function(q,k,r,u,f,m,t,g,n,v,h){h=q([h],{constructor:function(a){q.safeMixin(this,a);this.syncEvents();this.initGeometryService()},syncEvents:function(){f.subscribe("manual-startpoint-input",k.hitch(this,this.onLineStartManualInputHandler));f.subscribe("manual-line-end-point-input",k.hitch(this,this.onLineEndManualInputHandler));
f.subscribe("clear-points",k.hitch(this,this.clearPoints))},clearPoints:function(a){a&&(this._points=[],this.map.graphics.clear())},onLineStartManualInputHandler:function(a){this._points=[];this._points.push(a.offset(0,0));this.set("startPoint",this._points[0]);this.map.centerAt(a)},onLineEndManualInputHandler:function(a){this._points.push(a.offset(0,0));this.set("endPoint",this._points[1])},getAngle:function(a,c){var b=null;b=(180*Math.atan2(c.x-a.x,c.y-a.y)/Math.PI+360)%360;"mils"===this.angleUnit&&
(b*=17.777777778);return b.toFixed(2)},_onClickHandler:function(a){if(this.map.snappingManager)var c=this.map.snappingManager._snappingPoint;var b=c||a.mapPoint,d=this.map,p,l;this._processAfterMapClick(b).then(k.hitch(this,function(e){this._points.push(b);switch(this._geometryType){case m.POINT:this.set("startPointDD",e);this.set("startPoint",this._points[0]);this._drawEnd(b);this._setTooltipMessage(0);break;case m.POLYLINE:if(2===this._points.length){this.set("endPoint",this._points[1]);this.set("endPointDD",
e);this._onDblClickHandler();return}1===this._points.length?(this.set("startPoint",this._points[0]),this.set("startPointDD",e),e=new g(d.spatialReference),e.addPath(this._points),this._graphic=d.graphics.add(new t(e,this.lineSymbol),!0),d.snappingManager&&d.snappingManager._setGraphic(this._graphic),this.canProjectLocally&&(this._onMouseMoveHandler_connect=r.connect(d,"onMouseMove",this._onMouseMoveHandler)),this._tGraphic=d.graphics.add(new t(new g({paths:[[[b.x,b.y],[b.x,b.y]]],spatialReference:d.spatialReference}),
this.lineSymbol),!0)):(this.set("endPoint",this._points[1]),this.set("endPointDD",e),this._graphic.geometry._insertPoints([b],0),this._graphic.setGeometry(this._graphic.geometry).setSymbol(this.lineSymbol),p=this._tGraphic,l=p.geometry,l.setPoint(0,0,b),l.setPoint(0,1,b),p.setGeometry(l))}this._setTooltipMessage(this._points.length);1===this._points.length&&"polyline"===this._geometryType&&(e=this._tooltip)&&(e.innerHTML=v.sanitizeHTML(this.nls.clickToFinishLineMessage))}))},_onDblClickHandler:function(a){var c=
this._points;var b=this.map.spatialReference;u("esri-touch")&&a&&c.push(a.mapPoint);a=new g({paths:[[[c[0].x,c[0].y],[c[1].x,c[1].y]]],spatialReference:b});c=new g({paths:[[[this.startPointDD.x,this.startPointDD.y],[this.endPointDD.x,this.endPointDD.y]]],spatialReference:this.startPointDD.spatialReference});c.geodesicLength=n.geodesicLength(c,9001);this._onMouseMoveHandler_connect&&r.disconnect(this._onMouseMoveHandler_connect);b=this.coordTool.convertMetersToUnits(c.geodesicLength,this.lengthUnit);
var d=this.getAngle(this.startPoint,this.endPoint);f.publish("DD_LINE_LENGTH_DID_CHANGE",b);f.publish("DD_LINE_ANGLE_DID_CHANGE",d);this._clear();this._setTooltipMessage(0);c={geometry:a,geographicGeometry:c};a=new g(a.toJson());a.result=c;this._drawEnd(a)},_onMouseMoveHandler:function(a){if(this.map.snappingManager)var c=this.map.snappingManager._snappingPoint;var b=this._geometryType===m.POLYLINE?this._points[0]:this._points[this._points.length-1];a=c||a.mapPoint;var d=this._tGraphic.geometry;d.setPoint(0,
0,{x:b.x,y:b.y});d.setPoint(0,1,{x:a.x,y:a.y});c=n.geodesicDensify(d,10001);d=n.geodesicLength(d,9001);this._graphic.setGeometry(c);c=this.coordTool.convertMetersToUnits(d,this.lengthUnit);b=this.getAngle(b,a);f.publish("DD_LINE_LENGTH_DID_CHANGE",c);f.publish("DD_LINE_ANGLE_DID_CHANGE",b)}});h.drawnLineLengthDidChange="DD_LINE_LENGTH_DID_CHANGE";h.drawnLineAngleDidChange="DD_LINE_ANGLE_DID_CHANGE";return h});