// 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/topic esri/graphic esri/toolbars/draw esri/geometry/Circle esri/geometry/Polyline esri/geometry/geometryEngine jimu/utils ./Feedback dojo/has dojo/touch dojo/on".split(" "),function(l,c,f,m,g,n,h,p,q,r,t,u,v,w){return l([t],{constructor:function(a){l.safeMixin(this,a);this.syncEvents();this.initGeometryService();this.circlePoints=[];this.geoDesicCirclePoints=[]},syncEvents:function(){m.subscribe("manual-rangering-center-point-input",
c.hitch(this,this.onCenterPointManualInputHandler));m.subscribe("clear-points",c.hitch(this,this.clearPoints))},clearPoints:function(a){a&&(this._points=[],this.circlePoints=[],this.geoDesicCirclePoints=[],this.map.graphics.clear())},clearGraphics:function(){this.map.graphics.clear()},onCenterPointManualInputHandler:function(a){this._points=[];this.circlePoints=[];this.geoDesicCirclePoints=[];this._points.push(a.offset(0,0));this.set("startPoint",this._points[0]);this.map.centerAt(a)},_onClickHandler:function(a){if(this.map.snappingManager)var d=
this.map.snappingManager._snappingPoint;var b=d||a.mapPoint,k=this.map;this._points.push(b.offset(0,0));this._processAfterMapClick(b).then(c.hitch(this,function(e){1===this._points.length?(this.canProjectLocally||(this.geoDesicCirclePoints=[],this.circlePoints=[]),this.set("startPoint",this._points[0]),this.set("startPointDD",e)):this.set("endPointDD",e);this.circlePoints.push(b.offset(0,0));this.geoDesicCirclePoints.push(e.offset(0,0));switch(this._geometryType){case n.POINT:this._drawEnd(e.offset(0,
0));this._setTooltipMessage(0);break;case n.POLYLINE:e=new p({paths:[[[b.x,b.y],[b.x,b.y]]],spatialReference:k.spatialReference}),this.lgraphic=new g(e,this.lineSymbol),k.snappingManager&&k.snappingManager._setGraphic(this._graphic),1<this._points.length&&this._drawRangeCircle(),0<this._points.length&&(u("esri-touch")&&this.parentWidget.own(w(this.map.root,v.move,c.hitch(this,this._onMouseMoveHandler))),!this._onMouseMoveHandler_connect&&this.canProjectLocally&&(this._onMouseMoveHandler_connect=f.connect(this.map,
"onMouseMove",this._onMouseMoveHandler)),this._onDoubleClickHandler_connect||(this._onDoubleClickHandler_connect=f.connect(this.map,"onDblClick",c.hitch(this,this._onDoubleClickHandler))))}this._setTooltipMessage(this._points.length);1<this._points.length&&(e=this._tooltip)&&(e.innerHTML=r.sanitizeHTML(this.nls.doubleClickEllipseMesage))}))},_drawRangeCircle:function(){if(this.canProjectLocally)this.circleGraphic&&(a=new g(this.circleGraphic.geometry,this.fillSymbol),this.map.graphics.add(a));else{var a=
new p({paths:[[[this.startPointDD.x,this.startPointDD.y],[this.endPointDD.x,this.endPointDD.y]]],spatialReference:this.startPointDD.spatialReference});a=q.geodesicLength(a,9001);var d=new h(this.startPointDD,{radius:a,geodesic:!0,numberOfPoints:360});this.geodsicCircleGeometry=new h(this.startPointDD,{radius:a,geodesic:!0,numberOfPoints:360});this.getProjectedGeometry(d,this.map.spatialReference).then(c.hitch(this,c.hitch(this,function(b){d=c.mixin(b,{distanceDirectionType:"military-tools-range-rings"});
this.circleGraphic=new g(d,this.fillSymbol);this.map.graphics.add(this.circleGraphic)})))}},_onMouseMoveHandler:function(a){if(this.map.snappingManager)var d=this.map.snappingManager._snappingPoint;var b=this._points[0];a=d||a.mapPoint;d=this.lgraphic.geometry;d.setPoint(0,0,{x:b.x,y:b.y});d.setPoint(0,1,{x:a.x,y:a.y});a=q.geodesicLength(d,9001);b=new h(b,{radius:a,geodesic:!0,numberOfPoints:360});this.geodsicCircleGeometry=new h(this.startPointDD,{radius:a,geodesic:!0,numberOfPoints:360});this.circleGraphic&&
this.map.graphics.remove(this.circleGraphic);b=c.mixin(b,{distanceDirectionType:"military-tools-range-rings"});this.circleGraphic=new g(b,this.fillSymbol);this.map.graphics.add(this.circleGraphic)},_onDoubleClickHandler:function(){if(this.geoDesicCirclePoints&&!(2>this.geoDesicCirclePoints.length)){this.disconnectOnMouseMoveHandlers();var a=c.clone(this.geoDesicCirclePoints);this.cleanup();this._clear();this._setTooltipMessage(0);a=c.mixin(this.geodsicCircleGeometry,{circlePoints:a});this._drawEnd(a)}},
disconnectOnMouseMoveHandlers:function(){f.disconnect(this._onMouseMoveHandler_connect);f.disconnect(this._onDoubleClickHandler_connect);this._onDoubleClickHandler_connect=null},cleanup:function(){for(var a=this.map.graphics.graphics.length-1;0<=a;a--)this.map.graphics.graphics[a].geometry.hasOwnProperty("distanceDirectionType")&&this.map.graphics.remove(this.map.graphics.graphics[a]);this.circlePoints=[];this.geoDesicCirclePoints=[]}})});