text: // All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  // See http://js.arcgis.com/4.0beta2/esri/copyright.txt for details.
  //>>built
  define("../core/declare dojo/_base/lang dojo/_base/array dojo/_base/connect dojo/dom-style dojox/gfx/Moveable dojox/gfx/matrix ../core/lang ../geometry/Point ../geometry/Polyline ../geometry/support/webMercatorUtils ../geometry/support/jsonUtils ../Graphic".split(" "),function(s,m,h,n,t,u,l,v,p,w,q,x,r){return s(null,{declaredClass:"esri.toolbars._Box",constructor:function(d,a,b,c,e,f,g){this._graphic=d;this._map=a;this._toolbar=b;this._scale=c;this._rotate=e;this._defaultEventArgs={};this._scaleEvent=
  "Scale";this._rotateEvent="Rotate";this._uniformScaling=f;d=b._options;this._markerSymbol=d.boxHandleSymbol;this._lineSymbol=d.boxLineSymbol;this._moveStartHandler=m.hitch(this,this._moveStartHandler);this._firstMoveHandler=m.hitch(this,this._firstMoveHandler);this._moveStopHandler=m.hitch(this,this._moveStopHandler);this._moveHandler=m.hitch(this,this._moveHandler);this._isTextPoint=g;this._init()},destroy:function(){this._cleanUp();this._graphic=this._map=this._toolbar=this._markerSymbol=this._lineSymbol=
  null},refresh:function(){this._draw()},suspend:function(){h.forEach(this._getAllGraphics(),function(d){d.hide()})},resume:function(){h.forEach(this._getAllGraphics(),function(d){d.show()});this._draw()},_init:function(){this._draw()},_cleanUp:function(){this._connects&&h.forEach(this._connects,n.disconnect);var d=this._toolbar._scratchGL;this._anchors&&h.forEach(this._anchors,function(a){d.remove(a.graphic);(a=a.moveable)&&a.destroy()});this._box&&d.remove(this._box);this._box=this._anchors=this._connects=
  null},_draw:function(){if(this._graphic.getDojoShape()){var d=this._map,a=this._toolbar._scratchGL,b=this._getBoxCoords(),c=new w(d.spatialReference),e=m.clone(h.filter(b,function(b,a){return 8!==a&&0===a%2}));e[0]&&e.push([e[0][0],e[0][1]]);c.addPath(e);this._rotate&&c.addPath([b[1],b[8]]);this._box?this._box.setGeometry(c):(this._box=new r(c,this._lineSymbol),a.add(this._box));this._anchors?h.forEach(this._anchors,function(a,c){this._scale||(c=8);var e=new p(b[c],d.spatialReference);a.graphic.setGeometry(e);
  var e=a.moveable,h=a.graphic.getDojoShape();h&&(e?h!==e.shape&&(e.destroy(),a.moveable=this._getMoveable(a.graphic,c)):a.moveable=this._getMoveable(a.graphic,c))},this):(this._anchors=[],this._connects=[],h.forEach(b,function(b,c){if(this._scale||!(8>c)){b=new p(b,d.spatialReference);var e=new r(b,this._markerSymbol);this._isTextPoint&&1===c%2&&e.hide();a.add(e);this._anchors.push({graphic:e,moveable:this._getMoveable(e,c)})}},this))}else this._cleanUp()},_getBoxCoords:function(d){var a=this._map,
  b,c=[],e,f,g;if(this._isTextPoint){b=this._graphic.getNode().getBoundingClientRect();var k=a.__container.getBoundingClientRect();b=[{x:b.left-k.left,y:b.top-k.top},{x:b.right-k.left,y:b.top-k.top},{x:b.right-k.left,y:b.bottom-k.top},{x:b.left-k.left,y:b.bottom-k.top}]}else b=this._getTransformedBoundingBox(this._graphic);h.forEach(b,function(b,k,h){e=b;(f=h[k+1])||(f=h[0]);g={x:(e.x+f.x)/2,y:(e.y+f.y)/2};d||(e=a.toMap(e),g=a.toMap(g));c.push([e.x,e.y]);c.push([g.x,g.y])});this._rotate&&(b=m.clone(c[1]),
  b=d?{x:b[0],y:b[1]}:a.toScreen({x:b[0],y:b[1],spatialReference:a.spatialReference}),b.y-=this._toolbar._options.rotateHandleOffset,d||(b=a.toMap(b)),c.push([b.x,b.y]));return c},_getTransformedBoundingBox:function(d){var a=this._map,b=d.geometry.getExtent(),c=d.geometry.spatialReference;d=new p(b.xmin,b.ymax,c);b=new p(b.xmax,b.ymin,c);d=a.toScreen(d);b=a.toScreen(b);return[{x:d.x,y:d.y},{x:b.x,y:d.y},{x:b.x,y:b.y},{x:d.x,y:b.y}]},_getAllGraphics:function(){var d=[this._box];this._anchors&&h.forEach(this._anchors,
  function(a){d.push(a.graphic)});return d=h.filter(d,v.isDefined)},_getMoveable:function(d,a){var b=d.getDojoShape();if(b){var c=new u(b);c._index=a;this._connects.push(n.connect(c,"onMoveStart",this._moveStartHandler));this._connects.push(n.connect(c,"onFirstMove",this._firstMoveHandler));this._connects.push(n.connect(c,"onMoveStop",this._moveStopHandler));c.onMove=this._moveHandler;(b=b.getEventSource())&&t.set(b,"cursor",this._toolbar._cursors["box"+a]);return c}},_moveStartHandler:function(d){this._toolbar["on"+
  (8===d.host._index?this._rotateEvent:this._scaleEvent)+"Start"](this._graphic)},_firstMoveHandler:function(d){var a=d.host._index,b=this._wrapOffset=d.host.shape._wrapOffsets[0]||0,c=this._graphic.getLayer()._div.getTransform(),e;d=h.map(this._getBoxCoords(!0),function(a){return{x:a[0]+b,y:a[1]}});e=this._isTextPoint?this._map.toScreen(this._graphic.geometry):{x:d[1].x,y:d[3].y};this._centerCoord=l.multiplyPoint(l.invert(c),e);if(8===a)e=l.multiplyPoint(l.invert(c),d[1]),this._isTextPoint&&(this._centerCoord=
  this._deNormalizePoint(this._centerCoord,e)),this._startLine=[this._centerCoord,e],this._moveLine=m.clone(this._startLine);else if(e=l.multiplyPoint(l.invert(c),d[a]),c=l.multiplyPoint(l.invert(c),d[(a+4)%8]),this._isTextPoint&&(this._centerCoord=this._deNormalizePoint(this._centerCoord,e)),this._firstMoverToAnchor=Math.sqrt((e.x-this._centerCoord.x)*(e.x-this._centerCoord.x)+(e.y-this._centerCoord.y)*(e.y-this._centerCoord.y)),this._startBox=c,this._startBox.width=d[4].x-d[0].x,this._startBox.height=
  d[4].y-d[0].y,this._moveBox=m.clone(this._startBox),this._xfactor=e.x>c.x?1:-1,this._yfactor=e.y>c.y?1:-1,1===a||5===a)this._xfactor=0;else if(3===a||7===a)this._yfactor=0;this._toolbar._beginOperation("BOX");this._toolbar["on"+(8===a?this._rotateEvent:this._scaleEvent)+"FirstMove"](this._graphic)},_moveHandler:function(d,a){var b=d.host._index,c=this._defaultEventArgs,e,f,g,k;c.angle=0;c.scaleX=1;c.scaleY=1;if(8===b)e=this._startLine,f=this._moveLine,g=f[1],g.x+=a.dx,g.y+=a.dy,g=this._getAngle(e,
  f),this._isTextPoint&&(g+=this._graphic.symbol.angle),f=l.rotategAt(g,e[0]),this._graphic.getDojoShape().setTransform(f),c.transform=f,c.angle=g,c.around=e[0];else{e=this._startBox;f=this._moveBox;f.width+=a.dx*this._xfactor;f.height+=a.dy*this._yfactor;this._uniformScaling||this._isTextPoint?(e=f.x+this._xfactor*f.width,f=f.y+this._yfactor*f.height,e=Math.sqrt((e-this._centerCoord.x)*(e-this._centerCoord.x)+(f-this._centerCoord.y)*(f-this._centerCoord.y)),this._scaleRatio=g=k=e/this._firstMoverToAnchor,
  e=this._centerCoord):(g=f.width/e.width,k=f.height/e.height,e={x:e.x,y:e.y});if(isNaN(g)||Infinity===g||-Infinity===g)g=1;if(isNaN(k)||Infinity===k||-Infinity===k)k=1;f=l.scaleAt(g,k,e);if(this._isTextPoint){var h=l.rotategAt(this._graphic.symbol.angle,e);this._graphic.getDojoShape().setTransform([h,f])}else this._graphic.getDojoShape().setTransform(f);c.transform=f;c.scaleX=g;c.scaleY=k;c.around=e}this._toolbar["on"+(8===b?this._rotateEvent:this._scaleEvent)](this._graphic,c)},_moveStopHandler:function(d){var a=
  this._graphic,b=this._toolbar,c=b._geo?q.geographicToWebMercator(a.geometry):a.geometry,e=c.spatialReference,f=a.getDojoShape(),g=f.getTransform(),k=a.getLayer()._div.getTransform();this._isTextPoint?(a=this._graphic.symbol,8===d.host._index?a.angle+=this._getAngle(this._startLine,this._moveLine):a.font.setSize(Math.round(100*a.font.size*this._scaleRatio)/100),this._graphic.setSymbol(a)):(c=c.toJSON(),this._updateSegments(c.paths||c.rings,g,k,e),f.setTransform(null),c=x.fromJSON(c),a.setGeometry(b._geo?
  q.webMercatorToGeographic(c,!0):c));this._draw();this._startLine=this._moveLine=this._startBox=this._moveBox=this._xfactor=this._yfactor=null;b._endOperation("BOX");this._defaultEventArgs.transform=g;b["on"+(8===d.host._index?this._rotateEvent:this._scaleEvent)+"Stop"](this._graphic,this._defaultEventArgs)},_updateSegments:function(d,a,b,c){var e=this._map,f=this._wrapOffset||0;h.forEach(d,function(d){h.forEach(d,function(d){this._updatePoint(d,c,f,l,e,b,a)},this)},this)},_updatePoint:function(d,
  a,b,c,e,f,g){a=e.toScreen({x:d[0],y:d[1],spatialReference:a},!0);a.x+=b;a=c.multiplyPoint([f,g,c.invert(f)],a);a.x-=b;b=e.toMap(a);d[0]=b.x;d[1]=b.y},_getAngle:function(d,a){var b=180*Math.atan2(d[0].y-d[1].y,d[0].x-d[1].x)/Math.PI;return 180*Math.atan2(a[0].y-a[1].y,a[0].x-a[1].x)/Math.PI-b},_deNormalizePoint:function(d,a){var b=this._map._getFrameWidth();if(-1===b)return d;for(var c={x:d.x,y:d.y};Math.abs(c.x-a.x)>=b;)c.x=c.x<a.x?c.x+b:c.x-b;var e=Math.abs(c.x-a.x);Math.abs(c.x-a.x+b)<e?c.x+=b:
  Math.abs(c.x-a.x-b)<e&&(c.x-=b);return c}})});