// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/toolbars/_GraphicMover","dojo/_base/declare dojo/_base/lang dojo/_base/connect dojo/_base/json dojo/dom-style dojox/gfx/Moveable dojox/gfx/Mover dojox/gfx/matrix ../kernel ../PointerEvents ../sniff ../geometry/webMercatorUtils ../geometry/ScreenPoint ../geometry/Point".split(" "),function(l,m,e,n,p,v,w,q,r,x,t,u,y,z){var g=l(null,{declaredClass:"esri.toolbars._GraphicMover",constructor:function(b,a,d,c){this.graphic=b;this.map=a;this.toolbar=d;this.tempPt=c;this._enableGraphicMover();
this._moved=!1},refresh:function(b){var a=this.graphic.getDojoShape();!a||!b&&a._hostGraphic||(this._disableGraphicMover(),this._enableGraphicMover())},destroy:function(){this._disableGraphicMover()},hasMoved:function(){return this._moved},_enableGraphicMover:function(){var b=this.graphic,a=b.getDojoShape();a&&(a._hostGraphic=b,this._moveable=new v(a,{mover:g.Mover}),this._moveStartHandle=e.connect(this._moveable,"onMoveStart",this,this._moveStartHandler),this._firstMoveHandle=e.connect(this._moveable,
"onFirstMove",this,this._firstMoveHandler),this._movingHandle=e.connect(this._moveable,"onMoving",this,this._movingHandler),this._moveStopHandle=e.connect(this._moveable,"onMoveStop",this,this._moveStopHandler),(b=a.getEventSource())&&p.set(b,"cursor",this.toolbar._cursors.move))},_disableGraphicMover:function(){var b=this._moveable;if(b){e.disconnect(this._moveStartHandle);e.disconnect(this._firstMoveHandle);e.disconnect(this._movingHandle);e.disconnect(this._moveStopHandle);var a=b.shape;a&&(a._hostGraphic=
null,(a=a.getEventSource())&&p.set(a,"cursor","inherit"));b.destroy()}this._moveable=null},_moveStartHandler:function(){var b=this.graphic,a=this.map;this._startTx=b.getDojoShape().getTransform();"point"===this.graphic.geometry.type&&a.snappingManager&&a.snappingManager._setUpSnapping();this.toolbar.onGraphicMoveStart(b)},_firstMoveHandler:function(){this.toolbar._beginOperation("MOVE");this.toolbar.onGraphicFirstMove(this.graphic)},_movingHandler:function(b,a,d){b=b.shape.getTransform();a=this.map;
var c;t("esri-pointer")?c=a.navigationManager.pointerEvents._processTouchEvent(d,d):d&&"pointermove"===d.type&&(c=x.prototype._processTouchEvent.call({map:a},d,d));c&&a.snappingManager&&a.snappingManager._onSnappingMouseMoveHandler(c);this.tempPt&&this.tempPt.getDojoShape().setTransform(b);this.toolbar.onGraphicMove(this.graphic,b)},_moveStopHandler:function(b){var a=this.graphic,d=this.toolbar,c=this.map,f=d._geo?u.geographicToWebMercator(a.geometry):a.geometry,k=f.type,e=a.getDojoShape(),h=e.getTransform();
if(n.toJson(h)!==n.toJson(this._startTx)){this._moved=!0;switch(k){case "point":var k=[h,q.invert(this._startTx)],g;c.snappingManager&&(g=c.snappingManager._snappingPoint);f=g||c.toMap(q.multiplyPoint(k,c.toScreen(f,!0)));c.snappingManager&&c.snappingManager._killOffSnapping();break;case "polyline":f=this._updatePolyGeometry(f,f.paths,h);break;case "polygon":f=this._updatePolyGeometry(f,f.rings,h)}e.setTransform(null);a.setGeometry(d._geo?u.webMercatorToGeographic(f,!0):f);this.tempPt&&this.tempPt.setGeometry(new z(a.geometry.toJson()))}else this._moved=
!1;d._endOperation("MOVE");d.onGraphicMoveStop(a,h);this._moved||(b=b.__e,c=this.map.position,b=new y(b.pageX-c.x,b.pageY-c.y),d.onGraphicClick(a,{screenPoint:b,mapPoint:this.map.toMap(b)}))},_updatePolyGeometry:function(b,a,d){var c=this.map,f=b.getPoint(0,0),c=c.toMap(c.toScreen(f).offset(d.dx,d.dy));d=c.x-f.x;for(var f=c.y-f.y,e,g,h,c=0;c<a.length;c++)for(g=a[c],e=0;e<g.length;e++)h=b.getPoint(c,e),b.setPoint(c,e,h.offset(d,f));return b}});g.Mover=l(w,{declaredClass:"esri.toolbars._Mover",constructor:function(b,
a,d){this.__e=a}});t("extend-esri")&&(m.setObject("toolbars._GraphicMover",g,r),m.setObject("toolbars._Mover",g.Mover,r));return g});