/*
 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
 */
//>>built
define("esri/layers/DynamicMapServiceLayer",["dojo/_base/declare","dojo/_base/connect","dojo/_base/lang","dojo/dom-construct","dojo/dom-style","dojox/xml/parser","dojox/gfx/matrix","esri/kernel","esri/config","esri/sniff","esri/request","esri/domUtils","esri/layers/layer","esri/layers/MapImage"],function(_1,_2,_3,_4,_5,_6,_7,_8,_9,_a,_b,_c,_d,_e){var _f=_9.defaults.map.zoomDuration;var _10=_1(_d,{declaredClass:"esri.layers.DynamicMapServiceLayer",_eventMap:{"map-image-export":["mapImage"]},constructor:function(url,_11){this.useMapTime=(_11&&_11.hasOwnProperty("useMapTime"))?(!!_11.useMapTime):true;var _12=_3.hitch;this._exportMapImageHandler=_12(this,this._exportMapImageHandler);this._imgSrcFunc=_12(this,this._imgSrcFunc);this._divAlphaImageFunc=_12(this,this._divAlphaImageFunc);this._tileLoadHandler=_12(this,this._tileLoadHandler);this._tileErrorHandler=_12(this,this._tileErrorHandler);this.registerConnectEvents();},opacity:1,isPNG32:false,_setMap:function(map,_13,_14){this.inherited(arguments);this._map=map;var d=(this._div=_4.create("div",null,_13)),_15=_8._css.names,css={position:"absolute",width:map.width+"px",height:map.height+"px",overflow:"visible",opacity:this.opacity},_16=_a("ie"),_17=_2.connect,vd=map.__visibleDelta;if(_16&&_16>7){delete css.opacity;}if(map.navigationMode==="css-transforms"){css[_15.transform]=_8._css.translate(vd.x,vd.y);_5.set(d,css);this._left=vd.x;this._top=vd.y;}else{css.left="0px";css.top="0px";_5.set(d,css);this._left=this._top=0;}_5.set(d,css);this._onResizeHandler_connect=_17(map,"onResize",this,"_onResizeHandler");this._opacityChangeHandler_connect=_17(this,"onOpacityChange",this,"_opacityChangeHandler");this._img_loading=null;this._dragOrigin={x:0,y:0};this.evaluateSuspension();if(this.suspended&&!map.loaded){var _18=_2.connect(map,"onLoad",this,function(){_2.disconnect(_18);_18=null;this.evaluateSuspension();});}return d;},_unsetMap:function(map,_19){_4.destroy(this._div);this._map=this._div=null;var _1a=_2.disconnect;_1a(this._onResizeHandler_connect);_1a(this._opacityChangeHandler_connect);this._onResizeHandler_connect=this._opacityChangeHandler_connect=null;this._fireUpdateEnd();this._toggleTime();clearTimeout(this._wakeTimer);this._wakeTimer=null;this._disableDrawConnectors();this.inherited(arguments);},_onResizeHandler:function(_1b,_1c,_1d){_5.set(this._div,{width:_1c+"px",height:_1d+"px"});this._onExtentChangeHandler(_1b);},onSuspend:function(){this.inherited(arguments);this._fireUpdateEnd();this._toggleTime();_c.hide(this._div);clearTimeout(this._wakeTimer);this._wakeTimer=null;this._disableDrawConnectors();},onResume:function(){this.inherited(arguments);var map=this._map;this._toggleTime();if(map.navigationMode==="css-transforms"){var vd=map.__visibleDelta;this._left=vd.x;this._top=vd.y;_5.set(this._div,_8._css.names.transform,_8._css.translate(this._left,this._top));}this._enableDrawConnectors();this._wakeTimer=this._wakeTimer||setTimeout(_3.hitch(this,function(){if(!this.suspended){this._onExtentChangeHandler(this._map.extent);}}),0);},_enableDrawConnectors:function(){var _1e=_2.connect,map=this._map;if(map){this._onPanHandler_connect=_1e(map,"onPan",this,"_onPanHandler");this._onExtentChangeHandler_connect=_1e(map,"onExtentChange",this,"_onExtentChangeHandler");if(map.navigationMode==="css-transforms"){this._onScaleHandler_connect=_1e(map,"onScale",this,this._onScaleHandler);}else{this._onZoomHandler_connect=_1e(map,"onZoom",this,"_onZoomHandler");}}},_disableDrawConnectors:function(){var _1f=_2.disconnect;_1f(this._onPanHandler_connect);_1f(this._onExtentChangeHandler_connect);_1f(this._onZoomHandler_connect);_1f(this._onScaleHandler_connect);this._onPanHandler_connect=this._onExtentChangeHandler_connect=this._onZoomHandler_connect=this._onScaleHandler_connect=null;},_toggleTime:function(){var map=this._map;if(this.timeInfo&&this.useMapTime&&map&&!this.suspended){if(!this._timeConnect){this._timeConnect=_2.connect(map,"onTimeExtentChange",this,this._onTimeExtentChangeHandler);}this._setTime(map.timeExtent);}else{_2.disconnect(this._timeConnect);this._timeConnect=null;this._setTime(null);}},_setTime:function(_20){if(this._params){this._params.time=_20?_20.toJson().join(","):null;}},_onPanHandler:function(_21,_22){this._panDx=_22.x;this._panDy=_22.y;var _23=this._dragOrigin,vd=this._map.__visibleDelta,img=this._img;if(img){if(this._map.navigationMode==="css-transforms"){this._left=vd.x+_22.x;this._top=vd.y+_22.y;_5.set(this._div,_8._css.names.transform,_8._css.translate(this._left,this._top));}else{_5.set(img,{left:(_23.x+_22.x)+"px",top:(_23.y+_22.y)+"px"});}}},_onExtentChangeHandler:function(_24,_25,_26){if(this.suspended){return;}clearTimeout(this._wakeTimer);this._wakeTimer=null;var _27=this._map,_28=this._img,_29=_28&&_28.style,_2a=this._dragOrigin;if(_25&&!_26&&_28&&(_25.x!==this._panDx||_25.y!==this._panDy)){if(_27.navigationMode==="css-transforms"){var vd=_27.__visibleDelta;this._left=vd.x;this._top=vd.y;_5.set(this._div,_8._css.names.transform,_8._css.translate(this._left,this._top));}else{_5.set(_28,{left:(_2a.x+_25.x)+"px",top:(_2a.y+_25.y)+"px"});}}if(_28){_2a.x=parseInt(_29.left,10);_2a.y=parseInt(_29.top,10);}else{_2a.x=(_2a.y=0);}if(_27.navigationMode==="css-transforms"){if(_26&&_28){_5.set(_28,_8._css.names.transition,"none");_28._multiply=_28._multiply?_7.multiply(_28._matrix,_28._multiply):_28._matrix;}}this._fireUpdateStart();var _2b=this._img_loading;if(_2b){_2.disconnect(_2b._onload_connect);_2.disconnect(_2b._onerror_connect);_2.disconnect(_2b._onabort_connect);_4.destroy(_2b);this._img_loading=null;var _2c=this._jsonRequest;if(_2c){try{_2c.cancel();}catch(e){}this._jsonRequest=null;}}if(this.version>=10&&_27.wrapAround180){_24=_24._normalize(true);}if(this.isPNG32){var div=(this._img_loading=_4.create("div"));div.id=_27.id+"_"+this.id+"_"+new Date().getTime();_5.set(div,{position:"absolute",left:"0px",top:"0px",width:_27.width+"px",height:_27.height+"px"});var _2d=div.appendChild(_4.create("div"));_5.set(_2d,{opacity:0,width:_27.width+"px",height:_27.height+"px"});this.getImageUrl(_24,_27.width,_27.height,this._divAlphaImageFunc);div=null;}else{var img=(this._img_loading=_4.create("img")),_2e=_8._css.names,_2f=_a("ie"),css={position:"absolute",width:_27.width+"px",height:_27.height+"px"};if(_2f&&_2f>7){css.opacity=this.opacity;}if(_27.navigationMode==="css-transforms"){css[_2e.transform]=_8._css.translate(-this._left,-this._top);img._tdx=-this._left;img._tdy=-this._top;css[_2e.transition]=_2e.transformName+" "+_f+"ms ease";}else{css.left="0px";css.top="0px";}img.id=_27.id+"_"+this.id+"_"+new Date().getTime();_5.set(img,css);img._onload_connect=_2.connect(img,"onload",this,"_onLoadHandler");img._onerror_connect=_2.connect(img,"onerror",this,"_onErrorHandler");img._onabort_connect=_2.connect(img,"onabort",this,"_onErrorHandler");this._startRect={left:_2a.x,top:_2a.y,width:_28?parseInt(_29.width,10):_27.width,height:_28?parseInt(_29.height,10):_27.height,zoom:(_29&&_29.zoom)?parseFloat(_29.zoom):1};this.getImageUrl(_24,_27.width,_27.height,this._imgSrcFunc);img=null;}},_onTimeExtentChangeHandler:function(_30){if(this.suspended){return;}this._setTime(_30);this.refresh(true);},getImageUrl:function(_31,wd,ht,_32){},_imgSrcFunc:function(src){this._img_loading.src=src;},_divAlphaImageFunc:function(src){_5.set(this._img_loading,"filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='scale')");this._onLoadHandler({currentTarget:this._img_loading});},_onLoadHandler:function(evt){var img=evt.currentTarget,_33=_2.disconnect,_34=this._map;_33(img._onload_connect);_33(img._onerror_connect);_33(img._onabort_connect);if(!_34||_34.__panning||_34.__zooming){_4.destroy(img);this._fireUpdateEnd();return;}_6.removeChildren(this._div);this._img=img;this._startRect={left:0,top:0,width:_34.width,height:_34.height,zoom:1};this._div.appendChild(img);if(!this.suspended){_c.show(this._div);}img._onload_connect=img._onerror_connect=img._onabort_connect=this._img_loading=null;var _35=this._dragOrigin;_35.x=(_35.y=0);this.onUpdate();this._fireUpdateEnd();},_onErrorHandler:function(evt){var img=evt.currentTarget,_36=_2.disconnect;_5.set(img,"visibility","hidden");_36(img._onload_connect);_36(img._onerror_connect);_36(img._onabort_connect);img._onload_connect=img._onerror_connect=img._onabort_connect=null;var _37=new Error("Unable to load image: "+img.src);this.onError(_37);this._fireUpdateEnd(_37);},setUseMapTime:function(use,_38){this.useMapTime=use;this._toggleTime();if(!_38){this.refresh(true);}},refresh:function(){if(this._map){this._onExtentChangeHandler(this._map.extent);}},_onScaleHandler:function(mtx,_39){var css={},_3a=_8._css.names,img=this._img;if(!img){return;}_5.set(img,_3a.transition,_39?"none":(_3a.transformName+" "+_f+"ms ease"));img._matrix=mtx;mtx=img._multiply?_7.multiply(mtx,img._multiply):mtx;if(img._tdx||img._tdy){mtx=_7.multiply(mtx,{"xx":1,"xy":0,"yx":0,"yy":1,"dx":img._tdx,"dy":img._tdy});}css[_3a.transform]=_8._css.matrix(mtx);_5.set(img,css);},_onZoomHandler:function(_3b,_3c,_3d){var _3e=this._startRect,_3f=_3e.width*_3c,_40=_3e.height*_3c,img=this._img,_41=_a("ie");if(img){if(_41&&_41<8){_5.set(img,{left:(_3e.left-((_3f-_3e.width)*(_3d.x-_3e.left)/_3e.width))+"px",top:(_3e.top-((_40-_3e.height)*(_3d.y-_3e.top)/_3e.height))+"px",zoom:_3c*_3e.zoom});}else{_5.set(img,{left:(_3e.left-((_3f-_3e.width)*(_3d.x-_3e.left)/_3e.width))+"px",top:(_3e.top-((_40-_3e.height)*(_3d.y-_3e.top)/_3e.height))+"px",width:_3f+"px",height:_40+"px"});}}},_exportMapImage:function(url,_42,_43){var _44=this._exportMapImageHandler;_42.token=this._getToken();_b({url:url,content:_42,callbackParamName:"callback",load:function(){_44(arguments[0],arguments[1],_43);},error:_9.defaults.io.errorHandler});},_exportMapImageHandler:function(_45,io,_46){var _47=new _e(_45);this.onMapImageExport(_47);if(_46){_46(_47);}},onMapImageExport:function(){},setOpacity:function(o){if(this.opacity!=o){this.onOpacityChange(this.opacity=o);}},onOpacityChange:function(){},_opacityChangeHandler:function(_48){_5.set(this._div,"opacity",_48);}});if(_a("extend-esri")){_3.setObject("layers.DynamicMapServiceLayer",_10,_8);}return _10;});