/*
 COPYRIGHT 2009 ESRI

 TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
 Unpublished material - all rights reserved under the
 Copyright Laws of the United States and applicable international
 laws, treaties, and conventions.

 For additional information, contact:
 Environmental Systems Research Institute, Inc.
 Attn: Contracts and Legal Services Department
 380 New York Street
 Redlands, California, 92373
 USA

 email: contracts@esri.com
 */

window[esri._dojoScopeName||"dojo"]._xdResourceLoaded(function(_1,_2,_3){return {depends:[["provide","esri.toolbars.navigation"],["require","esri.toolbars._toolbar"],["require","esri.geometry"],["require","esri.symbol"],["require","esri.utils"],["require","esri.undoManager"]],defineResource:function(_4,_5,_6){if(!_4._hasResource["esri.toolbars.navigation"]){_4._hasResource["esri.toolbars.navigation"]=true;_4.provide("esri.toolbars.navigation");_4.require("esri.toolbars._toolbar");_4.require("esri.geometry");_4.require("esri.symbol");_4.require("esri.utils");_4.require("esri.undoManager");_4.declare("esri.toolbars.MapExtent",esri.OperationBase,{label:"extent changes",constructor:function(_7){this.map=_7.map;this.preExtent=_7.preExtent;this.currentExtent=_7.currentExtent;},performRedo:function(){this.map.setExtent(this.currentExtent);},performUndo:function(){this.map.setExtent(this.preExtent);}});_4.declare("esri.toolbars.Navigation",esri.toolbars._Toolbar,{constructor:function(_8){this.zoomSymbol=new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,new _4.Color([255,0,0]),2),new _4.Color([0,0,0,0.25]));_4.connect(_8,"onUnload",this,"_cleanUp");this.map=_8;this._undoManager=new esri.UndoManager({maxOperations:-1});this._normalizeRect=_4.hitch(this,this._normalizeRect);this._onMouseDownHandler=_4.hitch(this,this._onMouseDownHandler);this._onMouseUpHandler=_4.hitch(this,this._onMouseUpHandler);this._onMouseDragHandler=_4.hitch(this,this._onMouseDragHandler);this._onExtentChangeHandler_connect=_4.connect(_8,"onExtentChange",this,"_extentChangeHandler");this._onMapLoad_connect=_4.connect(_8,"onLoad",this,"_mapOnLoandHandler");if(_8.loaded&&_8.extent){this._currentExtent=_8.extent;}},_mapOnLoandHandler:function(){this._currentExtent=this.map.extent;},_navType:null,_start:null,_graphic:null,_prevExtent:false,_currentExtent:null,_preExtent:null,_cleanUp:function(_9){_4.disconnect(this._onExtentChangeHandler_connect);_4.disconnect(this._onMapLoad_connect);},activate:function(_a){var _b=this.map;if(!this._graphic){this._deactivateMapTools(true,false,false,true);this._graphic=new esri.Graphic(null,this.zoomSymbol);}switch(_a){case esri.toolbars.Navigation.ZOOM_IN:case esri.toolbars.Navigation.ZOOM_OUT:this._deactivate();this._onMouseDownHandler_connect=_4.connect(_b,"onMouseDown",this,"_onMouseDownHandler");this._onMouseDragHandler_connect=_4.connect(_b,"onMouseDrag",this,"_onMouseDragHandler");this._onMouseUpHandler_connect=_4.connect(_b,"onMouseUp",this,"_onMouseUpHandler");this._navType=_a;break;case esri.toolbars.Navigation.PAN:this._deactivate();_b.enablePan();this._navType=_a;break;}},_extentChangeHandler:function(_c){if(this._prevExtent||this._nextExtent){this._currentExtent=_c;}else{this._preExtent=this._currentExtent;this._currentExtent=_c;if(this._preExtent&&this._currentExtent){var _d=esri.toolbars.MapExtent({map:this.map,preExtent:this._preExtent,currentExtent:this._currentExtent});this._undoManager.add(_d);}}this._prevExtent=this._nextExtent=false;this.onExtentHistoryChange();},_deactivate:function(){var _e=this._navType;if(_e===esri.toolbars.Navigation.PAN){this.map.disablePan();}else{if(_e===esri.toolbars.Navigation.ZOOM_IN||_e===esri.toolbars.Navigation.ZOOM_OUT){_4.disconnect(this._onMouseDownHandler_connect);_4.disconnect(this._onMouseDragHandler_connect);_4.disconnect(this._onMouseUpHandler_connect);}}},_normalizeRect:function(_f,end,_10){var sx=_f.x,sy=_f.y,ex=end.x,ey=end.y,_11=Math.abs(sx-ex),_12=Math.abs(sy-ey);return {x:Math.min(sx,ex),y:Math.max(sy,ey),width:_11,height:_12,spatialReference:_10};},_onMouseDownHandler:function(evt){this._start=evt.mapPoint;},_onMouseDragHandler:function(evt){var _13=this._graphic,_14=this.map.graphics;_14.remove(_13,true);_13.setGeometry(new esri.geometry.Rect(this._normalizeRect(this._start,evt.mapPoint,this.map.spatialReference)));_14.add(_13,true);},_onMouseUpHandler:function(evt){var map=this.map,_15=this._normalizeRect(this._start,evt.mapPoint,map.spatialReference);map.graphics.remove(this._graphic,true);if(_15.width===0&&_15.height===0){return;}if(this._navType===esri.toolbars.Navigation.ZOOM_IN){map.setExtent(esri.geometry._rectToExtent(new esri.geometry.Rect(_15)));}else{var tl=map.toScreen(_15),tr=map.toScreen({x:_15.x+_15.width,y:_15.y,spatialReference:map.spatialReference}),_16=map.extent.getWidth(),_17=(_16*map.width)/Math.abs(tr.x-tl.x),_18=(_17-_16)/2,ext=map.extent;map.setExtent(new esri.geometry.Extent(ext.xmin-_18,ext.ymin-_18,ext.xmax+_18,ext.ymax+_18,ext.spatialReference));}},deactivate:function(){this._deactivate();if(this._graphic){this.map.graphics.remove(this._graphic,true);}this._navType=this._start=this._graphic=null;this._activateMapTools(true,false,false,true);},setZoomSymbol:function(_19){this.zoomSymbol=_19;},isFirstExtent:function(){return !this._undoManager.canUndo;},isLastExtent:function(){return !this._undoManager.canRedo;},zoomToFullExtent:function(){var map=this.map;map.setExtent(map.getLayer(map.layerIds[0]).initialExtent);},zoomToPrevExtent:function(){if(!this._undoManager.canUndo){return;}this._prevExtent=true;this._undoManager.undo();},zoomToNextExtent:function(){if(!this._undoManager.canRedo){return;}this._nextExtent=true;this._undoManager.redo();},onExtentHistoryChange:function(){}});_4.mixin(esri.toolbars.Navigation,{ZOOM_IN:"zoomin",ZOOM_OUT:"zoomout",PAN:"pan"});}}};});