/*
 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.layers.tiled"],["require","dojox.collections.ArrayList"],["require","esri.layers.layer"],["require","esri.geometry"],["require","dojox.gfx.matrix"]],defineResource:function(_4,_5,_6){if(!_4._hasResource["esri.layers.tiled"]){_4._hasResource["esri.layers.tiled"]=true;_4.provide("esri.layers.tiled");_4.require("dojox.collections.ArrayList");_4.require("esri.layers.layer");_4.require("esri.geometry");_4.require("dojox.gfx.matrix");_4.declare("esri.layers.TiledMapServiceLayer",esri.layers.Layer,{constructor:function(_7,_8){_4.connect(this,"onLoad",this,"_initTiledLayer");this._displayLevels=_8?_8.displayLevels:null;var dh=_4.hitch;this._addImage=dh(this,this._addImage);this._tileLoadHandler=dh(this,this._tileLoadHandler);this._tileErrorHandler=dh(this,this._tileErrorHandler);this._tilePopPop=dh(this,this._tilePopPop);this._cleanUpRemovedImages=dh(this,this._cleanUpRemovedImages);this._fireOnUpdateEvent=dh(this,this._fireOnUpdateEvent);this._transitionEnd=dh(this,this._transitionEnd);},opacity:1,isPNG32:false,_initTiledLayer:function(){var ti=this.tileInfo,_9=ti.lods;this._tileW=ti.width;this._tileH=ti.height;this._normalizedScales=[];var _a=(this.scales=[]),dl=this._displayLevels,fe=this.fullExtent,ul=new esri.geometry.Point(fe.xmin,fe.ymax),lr=new esri.geometry.Point(fe.xmax,fe.ymin),_b=esri.TileUtils.getContainingTileCoords,_c,_d,i,_e=_9.length;for(i=0;i<_e;i++){_d=_9[i];_c=_b(ti,ul,_d);_d.startTileRow=_c.row<0?0:_c.row;_d.startTileCol=_c.col<0?0:_c.col;_c=_b(ti,lr,_d);_d.endTileRow=_c.row;_d.endTileCol=_c.col;if(!dl||_4.indexOf(dl,_d.level)!==-1){_a[i]=_d.scale;this._normalizedScales[i]=_d.scale/ti.dpi;}}this._patchIE=_4.isIE>=6&&_4.isIE<7&&(this.isPNG32||ti.format==="Mixed");},_setMap:function(_f,_10,_11,lod){this._map=_f;var d=(this._div=_4.create("div",null,_10));this._layerIndex=_11;var _12=_f.__visibleDelta,dc=_4.connect,_13=esri._css.names,css={position:"absolute",width:_f.width+"px",height:_f.height+"px",overflow:"visible"};if(_f.navigationMode==="css-transforms"){css[_13.transform]=esri._css.translate(-_12.x,-_12.y);_4.style(d,css);delete css[_13.transform];css[_13.transition]=_13.transformName+" "+esri.config.defaults.map.zoomDuration+"ms ease";_4.style((this._active=_4.create("div",null,d)),css);this._active._remove=0;this._passives=[];this._onScaleHandler_connect=dc(_f,"onScale",this,this._onScaleHandler);if(esri.isTouchEnabled){this._standby=[];var _14=this,_15=function(){_14._noDom=1;};this._onPanStartHandler_connect=dc(_f,"onPanStart",_15);this._onZoomStartHandler_connect=dc(_f,"onZoomStart",_15);}}else{css.left=-_12.x+"px";css.top=-_12.y+"px";_4.style(d,css);this._onZoomHandler_connect=dc(_f,"onZoom",this,"_onZoomHandler");}this._onPanHandler_connect=dc(_f,"onPan",this,"_onPanHandler");this._onExtentChangeHandler_connect=dc(_f,"onExtentChange",this,"_onExtentChangeHandler");this._onResizeHandler_connect=dc(_f,"onResize",this,"_onResizeHandler");this._opacityChangeHandler_connect=dc(this,"onOpacityChange",this,"_opacityChangeHandler");this._visibilityChangeHandler_connect=dc(this,"onVisibilityChange",this,"_visibilityChangeHandler");this._tileIds=[];this._tiles=[];this._tileBounds=[];this._ct=null;this._removeList=new _6.collections.ArrayList();this._loadingList=new _6.collections.ArrayList();var _16=this.tileInfo,sr=_16.spatialReference,_17=sr._getInfo();this._wrap=_f.wrapAround180&&sr._isWrappable()&&Math.abs(_17.origin[0]-_16.origin.x)<=_17.dx;if(this._wrap){esri.TileUtils._addFrameInfo(_16,_17);}var _18=_f.extent;if(!this.visible){this._visibilityChangeHandler(this.visible);}if(_18&&_f.loaded){this._onExtentChangeHandler(_18,null,null,lod);}return d;},_unsetMap:function(map,_19){if(_19){this._div=_19.removeChild(this._div);}_4.destroy(this._div);this._map=this._layerIndex=this._div=this._standby=null;var dd=_4.disconnect;dd(this._onExtentChangeHandler_connect);dd(this._onPanHandler_connect);dd(this._onZoomHandler_connect);dd(this._onScaleHandler_connect);dd(this._onLayerReorderHandler_connect);dd(this._onResizeHandler_connect);dd(this._opacityChangeHandler_connect);dd(this._visibilityChangeHandler_connect);dd(this._onPanStartHandler_connect);dd(this._onZoomStartHandler_connect);},_visibilityChangeHandler:function(v){if(v){esri.show(this._div);var map=this._map;if(map.navigationMode==="css-transforms"){this._onScaleHandler_connect=_4.connect(map,"onScale",this,this._onScaleHandler);}else{this._onZoomHandler_connect=_4.connect(map,"onZoom",this,"_onZoomHandler");}this._onPanHandler_connect=_4.connect(map,"onPan",this,"_onPanHandler");this._onExtentChangeHandler(map.extent,null,true);}else{esri.hide(this._div);_4.disconnect(this._onPanHandler_connect);_4.disconnect(this._onZoomHandler_connect);_4.disconnect(this._onScaleHandler_connect);}},_onResizeHandler:function(_1a,_1b,_1c){var css={width:_1b+"px",height:_1c+"px"},ds=_4.style,i;ds(this._div,css);if(this._map.navigationMode==="css-transforms"){if(this._active){ds(this._active,css);}for(i=this._passives.length-1;i>=0;i--){ds(this._passives[i],css);}}},_onExtentChangeHandler:function(_1d,_1e,_1f,lod){var i,_20=this._standby,img,_21;if(this._map.navigationMode==="css-transforms"){if(_1f){for(i=this._passives.length-1;i>=0;i--){_21=this._passives[i];_4.style(_21,esri._css.names.transition,"none");if(_21._marked){this._passives.splice(i,1);if(_21.parentNode){_21.parentNode.removeChild(_21);}_4.destroy(_21);}else{if(_21.childNodes.length>0){_21._multiply=_21._multiply?_6.gfx.matrix.multiply(_21._matrix,_21._multiply):_21._matrix;}}}}this._noDom=0;if(_20&&_20.length){for(i=_20.length-1;i>=0;i--){img=_20[i];_4.style(img,"visibility","visible");this._tilePopPop(img);_20.splice(i,1);}}}var _22=true;this._refreshArgs={extent:_1d,lod:lod};if(!this.visible){_22=false;}var map=this._map,_23;if(lod){_23=_4.indexOf(this.scales,lod.scale)===-1;if(this.declaredClass==="esri.layers.WMTSLayer"){var _24=map._params.tileInfo.dpi;var _25=map.width>map.height?map.width:map.height;_23=true;var s1,s2=lod.scale/_24;for(i=0;i<this._normalizedScales.length;i++){s1=this._normalizedScales[i];if(Math.abs((s1-s2)/s1)<(1/_25)){_23=false;break;}}}}else{var _26=map.getLevel(),_27=(_26!==-1)?map._params.tileInfo.lods[_26].scale:-1;_23=(_4.indexOf(this.scales,_27)===-1);}if(_22){var dd=_4.disconnect;if(_23){_22=false;esri.hide(this._div);dd(this._onPanHandler_connect);dd(this._onZoomHandler_connect);dd(this._onScaleHandler_connect);}else{this._fireUpdateStart();esri.show(this._div);dd(this._onPanHandler_connect);dd(this._onZoomHandler_connect);dd(this._onScaleHandler_connect);if(map.navigationMode==="css-transforms"){this._onScaleHandler_connect=_4.connect(map,"onScale",this,this._onScaleHandler);}else{this._onZoomHandler_connect=_4.connect(map,"onZoom",this,"_onZoomHandler");}this._onPanHandler_connect=_4.connect(map,"onPan",this,"_onPanHandler");}}this._rrIndex=0;var ct=esri.TileUtils.getCandidateTileInfo(map,this.tileInfo,_1d),mv=map.__visibleDelta,id;if(!this._ct||ct.lod.level!==this._ct.lod.level||_1f){var _28=(ct&&this._ct&&ct.lod.level!==this._ct.lod.level);this._ct=ct;var _29=this._tiles,_2a=this._tileIds,_2b=this._tileBounds,_2c=this._removeList,_2d,il=_2a.length;this._cleanUpRemovedImages();for(i=0;i<il;i++){id=_2a[i];_2d=_29[id];_2b[id]=_2a[i]=null;if((map.navigationMode==="css-transforms")&&_28&&_2d.parentNode&&map.fadeOnZoom&&_22){_2d._fadeOut=_28;_2d.parentNode._remove++;}_2c.add(_2d);}if(_1f){this._tileIds=[];this._tiles=[];this._tileBounds=[];}}var mx=mv.x,my=mv.y;if(map.navigationMode==="css-transforms"){var css={};css[esri._css.names.transform]=esri._css.translate(mx,my);_4.style(this._div,css);}else{_4.style(this._div,{left:mx+"px",top:my+"px"});}if(_22&&!_23){this.__coords_dx=mx;this.__coords_dy=my;this._updateImages(new esri.geometry.Rect(0,0,mv.width,mv.height));if(this._loadingList.count===0){this.onUpdate();this._fireUpdateEnd();}else{this._fireOnUpdate=true;}}else{this._cleanUpRemovedImages();}var _2e,_2f,_30=this._tileW,_31=this._tileH;mv=new esri.geometry.Rect(-mv.x,-mv.y,mv.width,mv.height);for(i=this._tileIds.length-1;i>=0;i--){id=this._tileIds[i];if(id){img=this._tiles[id];_2e=_4.coords(img);_2f=new esri.geometry.Rect(_2e.l,_2e.t,_30,_31);if(map.navigationMode==="css-transforms"){_2f.x=img._left;_2f.y=img._top;}if(mv.intersects(_2f)){this._tileBounds[id]=_2f;}else{if(this._loadingList.contains(id)){this._tilePopPop(img);}_4.destroy(img);this._tileIds.splice(i,1);delete this._tileBounds[id];delete this._tiles[id];}}else{this._tileIds.splice(i,1);delete this._tileBounds[id];delete this._tiles[id];}}},_onPanHandler:function(_32,_33){var map=this._map,mv=map.__visibleDelta.offset(_33.x,_33.y);this.__coords_dx=this.__coords_dy=0;if(map.navigationMode==="css-transforms"){var css={};css[esri._css.names.transform]=esri._css.translate(mv.x,mv.y);_4.style(this._div,css);if(!esri.isTouchEnabled){this._updateImages({x:-mv.x,y:-mv.y,width:mv.width,height:mv.height});}}else{_4.style(this._div,{left:mv.x+"px",top:mv.y+"px"});this._updateImages({x:-mv.x,y:-mv.y,width:mv.width,height:mv.height});}if(this._loadingList.count>0){this._fireUpdateStart();this._fireOnUpdate=true;}},_onScaleHandler:function(mtx,_34){var i,css={},_35=esri._css.names,map=this._map;for(i=this._passives.length-1;i>=0;i--){var _36=this._passives[i];if(_36.childNodes.length===0){this._passives.splice(i,1);_4.destroy(_36);}else{if(_36.style[_35.transition]==="none"){_4.style(_36,_35.transition,_35.transformName+" "+esri.config.defaults.map.zoomDuration+"ms ease");}_4.style(_36,_35.transition,_34?"none":(_35.transformName+" "+esri.config.defaults.map.zoomDuration+"ms ease"));_36._matrix=mtx;css[_35.transform]=esri._css.matrix(_36._multiply?_6.gfx.matrix.multiply(mtx,_36._multiply):mtx);_4.style(_36,css);}}if(this._active&&this._active.childNodes.length===0){return;}_4.style(this._active,_35.transition,_34?"none":(_35.transformName+" "+esri.config.defaults.map.zoomDuration+"ms ease"));this._active._matrix=mtx;css[_35.transform]=esri._css.matrix(this._active._matrix);_4.style(this._active,css);this._passives.push(this._active);css={position:"absolute",width:map.width+"px",height:map.height+"px",overflow:"visible"};css[_35.transition]=_35.transformName+" "+esri.config.defaults.map.zoomDuration+"ms ease";_4.style((this._active=_4.create("div",null,this._div)),css);this._active._remove=0;if(map.fadeOnZoom){_4.place(this._active,this._div,"first");}},_onZoomHandler:function(_37,_38,_39){var _3a=_4.coords(this._div);_39=_39.offset(-_3a.l,-_3a.t);var _3b,_3c=this._tileW*_38,_3d=this._tileH*_38,_3e=this._tileBounds,_3f=this._tiles,es=_4.style;var _40=_4.isIE;if(_40&&_40<8){_4.forEach(this._tileIds,function(id){_3b=_3e[id];es(_3f[id],{left:(_3b.x-((_3c-_3b.width)*(_39.x-_3b.x)/_3b.width))+"px",top:(_3b.y-((_3d-_3b.height)*(_39.y-_3b.y)/_3b.height))+"px",zoom:_38});});}else{_4.forEach(this._tileIds,function(id){_3b=_3e[id];es(_3f[id],{left:(_3b.x-((_3c-_3b.width)*(_39.x-_3b.x)/_3b.width))+"px",top:(_3b.y-((_3d-_3b.height)*(_39.y-_3b.y)/_3b.height))+"px",width:_3c+"px",height:_3d+"px"});});}},_updateImages:function(_41){var id,_42=this._tileW,_43=this._tileH,_44=this._ct,lod=_44.lod,_45=_44.tile,off=_45.offsets,_46=_45.coords,cr=_46.row,cc=_46.col,_47=lod.level,_48=this.opacity,_49=this._tileIds,_4a=this._loadingList,_4b=this._addImage,mId=this._map.id,tId=this.id,rx=_41.x,ry=_41.y,str=lod.startTileRow,etr=lod.endTileRow,stc=lod.startTileCol,etc=lod.endTileCol,_4c=_4.indexOf,r,c,mvx=-_41.x,mvy=-_41.y,_4d=off.x-this.__coords_dx,_4e=off.y-this.__coords_dy,vx=((_42-_4d)+mvx),vy=((_43-_4e)+mvy),_4f=Math.ceil,_50=(vx>0)?(vx%_42):((_42-(Math.abs(vx)%_42))),_51=(vy>0)?(vy%_43):((_43-(Math.abs(vy)%_43))),_52=(rx>0)?Math.floor((rx+_4d)/_42):_4f((rx-(_42-_4d))/_42),_53=(ry>0)?Math.floor((ry+_4e)/_43):_4f((ry-(_43-_4e))/_43),_54=_52+_4f((_41.width-_50)/_42),_55=_53+_4f((_41.height-_51)/_43),_56,_57,_58,_59,col,row;if(this._wrap){_56=lod._frameInfo;_57=_56[0];_58=_56[1];_59=_56[2];}for(col=_52;col<=_54;col++){for(row=_53;row<=_55;row++){r=cr+row;c=cc+col;if(this._wrap){if(c<_58){c=c%_57;c=c<_58?c+_57:c;}else{if(c>_59){c=c%_57;}}}if(r>=str&&r<=etr&&c>=stc&&c<=etc){id=mId+"_"+tId+"_tile_"+_47+"_"+row+"_"+col;if(_4c(_49,id)===-1){_4a.add(id);_49.push(id);_4b(_47,row,r,col,c,id,_42,_43,_48,_45,off);}}}}},_cleanUpRemovedImages:function(){var _5a=this._removeList,dd=_4.destroy,i,_5b=esri._css.names;_5a.forEach(function(img){if(!img._fadeOut){img.style.filter="";img.style.zoom=1;dd(img);}});if(this._map.navigationMode==="css-transforms"){for(i=this._passives.length-1;i>=0;i--){var _5c=this._passives[i];if(_5c.childNodes.length===0){this._passives.splice(i,1);dd(_5c);}else{if(this._map.fadeOnZoom&&!_5c._marked&&(_5c._remove===_5c.childNodes.length)){_4.style(_5c,_5b.transition,"opacity 0.65s");_4.style(_5c,"opacity",0);_5c._marked=1;if(_4.isIE>=10){_5c.addEventListener(_5b.endEvent,this._transitionEnd,false);}else{_5c._endHandle=_4.connect(_5c,_5b.endEvent,this._transitionEnd);}}}}}_5a.clear();},_transitionEnd:function(evt){var _5d=evt.target,idx;if(evt.propertyName!=="opacity"){return;}if(_4.isIE>=10){_5d.removeEventListener(esri._css.names.endEvent,this._transitionEnd,false);}else{_4.disconnect(_5d._endHandle);_5d._endHandle=null;}idx=_4.indexOf(this._passives,_5d);if(idx>-1){this._passives.splice(idx,1);}if(_5d.parentNode){_5d.parentNode.removeChild(_5d);}_4.destroy(_5d);},_addImage:function(_5e,row,r,col,c,id,_5f,_60,_61,_62,_63){if(this._patchIE){var div=(this._tiles[id]=_4.create("div"));div.id=id;_4.addClass(div,"layerTile");_4.style(div,{left:((_5f*col)-_63.x)+"px",top:((_60*row)-_63.y)+"px",width:_5f+"px",height:_60+"px",filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.getTileUrl(_5e,r,c)+"', sizingMethod='scale')"});if(_61<1){_4.style(div,"opacity",_61);}var _64=div.appendChild(_4.create("div"));_4.style(_64,{opacity:0,width:_5f+"px",height:_60+"px"});this._div.appendChild(div);div=null;this._loadingList.remove(id);this._fireOnUpdateEvent();}else{var img=(this._tiles[id]=_4.create("img")),dc=_4.connect;img.id=id;_4.addClass(img,"layerTile");var _65=(_5f*col)-_63.x,top=(_60*row)-_63.y,map=this._map,_66=esri._css.names,css={width:_5f+"px",height:_60+"px",visibility:"hidden"};if(map.navigationMode==="css-transforms"){css[_66.transform]=esri._css.translate(_65,top);_4.style(img,css);img._left=_65;img._top=top;}else{css.left=_65+"px";css.top=top+"px";_4.style(img,css);}if(_61<1){_4.style(img,"opacity",_61);}img._onload_connect=dc(img,"onload",this,"_tileLoadHandler");img._onerror_connect=dc(img,"onerror",this,"_tileErrorHandler");img._onabort_connect=dc(img,"onabort",this,"_tileErrorHandler");var url=this.getTileUrl(_5e,r,c,img);if(url){img.src=url;}if(map.navigationMode==="css-transforms"){this._active.appendChild(img);}else{this._div.appendChild(img);}img=null;}},getTileUrl:function(_67,row,col){},refresh:function(){var ra=this._refreshArgs;this._onExtentChangeHandler(ra.extent,null,true,ra.lod);},_tilePopPop:function(img){var dd=_4.disconnect;dd(img._onload_connect);dd(img._onerror_connect);dd(img._onabort_connect);img._onload_connect=img._onerror_connect=img._onabort_connect=null;this._loadingList.remove(img.id);this._fireOnUpdateEvent();},_tileLoadHandler:function(evt){var img=evt.currentTarget;if(this._noDom){this._standby.push(img);return;}_4.style(img,"visibility","visible");this._tilePopPop(img);},_tileErrorHandler:function(evt){var img=evt.currentTarget;this.onError(new Error(esri.bundle.layers.tiled.tileError+": "+img.src));_4.style(img,"visibility","hidden");this._tilePopPop(img);},_fireOnUpdateEvent:function(){if(this._loadingList.count===0){this._cleanUpRemovedImages();if(this._fireOnUpdate){this._fireOnUpdate=false;this.onUpdate();this._fireUpdateEnd();}}},setOpacity:function(o){if(this.opacity!=o){this.onOpacityChange(this.opacity=o);}},onOpacityChange:function(){},_opacityChangeHandler:function(_68){var djs=_4.style,i,j,_69;if(this._map.navigationMode==="css-transforms"){if(this._active){_69=this._active.childNodes;for(i=_69.length-1;i>=0;i--){djs(_69[i],"opacity",_68);}}for(i=this._passives.length-1;i>=0;i--){_69=this._passives[i].childNodes;for(j=_69.length-1;j>=0;j--){djs(_69[j],"opacity",_68);}}return;}_69=this._div.childNodes;for(i=_69.length-1;i>=0;i--){djs(_69[i],"opacity",_68);}}});_4.declare("esri.layers.TileInfo",null,{constructor:function(_6a){this.width=_6a.cols||_6a.width;this.height=_6a.rows||_6a.height;this.dpi=_6a.dpi;this.format=_6a.format;var sr=_6a.spatialReference,ori=_6a.origin;if(sr){sr=(this.spatialReference=new esri.SpatialReference(sr.declaredClass?sr.toJson():sr));}if(ori){ori=(this.origin=new esri.geometry.Point(ori.declaredClass?ori.toJson():ori));if(!ori.spatialReference&&sr){ori.setSpatialReference(new esri.SpatialReference(sr.toJson()));}}var _6b=(this.lods=[]);_4.forEach(_6a.lods,function(lod,i){_6b[i]=new esri.layers.LOD(lod);});}});_4.declare("esri.layers.LOD",null,{constructor:function(_6c){_4.mixin(this,_6c);}});}}};});