/*
 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.virtualearth.VETiledLayer"],["require","esri.utils"],["require","esri.layers.tiled"],["require","esri.geometry"],["require","dojo.string"]],defineResource:function(_4,_5,_6){if(!_4._hasResource["esri.virtualearth.VETiledLayer"]){_4._hasResource["esri.virtualearth.VETiledLayer"]=true;_4.provide("esri.virtualearth.VETiledLayer");_4.require("esri.utils");_4.require("esri.layers.tiled");_4.require("esri.geometry");_4.require("dojo.string");_4.declare("esri.virtualearth.VETiledLayer",esri.layers.TiledMapServiceLayer,{constructor:function(_7){try{_7=_4.mixin({bingMapsKey:null,culture:"en-US"},_7||{});var _8=window.location.protocol;if(_8==="file:"){_8="http:";}this.url=_8+"//serverapi.arcgisonline.com/veadaptor/production/services/imagery/getmetadata";this._url=esri.urlToObject(this.url);this.spatialReference=new esri.SpatialReference({wkid:102100});this.tileInfo=new esri.layers.TileInfo({rows:256,cols:256,dpi:96,origin:{x:-20037508.342787,y:20037508.342787},spatialReference:{wkid:102100},lods:[{level:1,resolution:78271.5169639999,scale:295828763.795777},{level:2,resolution:39135.7584820001,scale:147914381.897889},{level:3,resolution:19567.8792409999,scale:73957190.948944},{level:4,resolution:9783.93962049996,scale:36978595.474472},{level:5,resolution:4891.96981024998,scale:18489297.737236},{level:6,resolution:2445.98490512499,scale:9244648.868618},{level:7,resolution:1222.99245256249,scale:4622324.434309},{level:8,resolution:611.49622628138,scale:2311162.217155},{level:9,resolution:305.748113140558,scale:1155581.108577},{level:10,resolution:152.874056570411,scale:577790.554289},{level:11,resolution:76.4370282850732,scale:288895.277144},{level:12,resolution:38.2185141425366,scale:144447.638572},{level:13,resolution:19.1092570712683,scale:72223.819286},{level:14,resolution:9.55462853563415,scale:36111.909643},{level:15,resolution:4.77731426794937,scale:18055.954822},{level:16,resolution:2.38865713397468,scale:9027.977411},{level:17,resolution:1.19432856685505,scale:4513.988705},{level:18,resolution:0.597164283559817,scale:2256.994353},{level:19,resolution:0.298582141647617,scale:1128.497176}]});this.initialExtent=(this.fullExtent=new esri.geometry.Extent(-20037508.342787,-20037508.34278,20037508.34278,20037508.342787,new esri.SpatialReference({wkid:102100})));_4.mixin(this,_7);this._initLayer=_4.hitch(this,this._initLayer);this._errorHandler=_4.hitch(this,this._errorHandler);this._getTileInfo=_4.hitch(this,this._getTileInfo);if(this.bingMapsKey){this._getTileInfo();}else{throw new Error(esri.bundle.virtualearth.vetiledlayer.bingMapsKeyNotSpecified);}}catch(e){this.onError(e);throw e;}},_unsetMap:function(_9,_a){this.inherited("_unsetMap",arguments);},_getTileInfo:function(){if(this.bingMapsKey){var _b=this.resourceInfo;if(!this.loaded&&_b){this._initLayer(_b);}else{esri.request({url:this._url.path,content:_4.mixin({},this._url.query,{token:this.bingMapsKey,style:this.mapStyle,culture:this.culture}),callbackParamName:"callback",load:this._initLayer,error:this._errorHandler});}}},_initLayer:function(_c,io){try{this.resourceInfo=_4.toJson(_c);var _d=_c.imageUri.replace("{","${");this.tileServers=_4.map(_c.subDomains,function(_e){var _f=window.location.protocol;if(_f==="file:"){_f="http:";}return _4.string.substitute(_d,{subdomain:_e}).replace("http:",_f);});this._tsLength=this.tileServers.length;if(!this.loaded){this.loaded=true;this.onLoad(this);var _10=this.loadCallback;if(_10){delete this.loadCallback;_10(this);}}else{this.refresh();}}catch(e){this.onError(e);}},getTileUrl:function(_11,row,col){var _12=this.tileServers[row%this._tsLength],_13=_12.replace(/\{/g,"${");return _4.string.substitute(_13,{quadkey:this._getQuadKey(_11,row,col),culture:this.culture,token:this.bingMapsKey});},_getQuadKey:function(_14,row,col){var _15="",_16,_17,i;for(i=_14;i>0;i--){_16="0";_17=1<<(i-1);if((col&_17)!=0){_16++;}if((row&_17)!=0){_16++;_16++;}_15=_15+_16;}return _15;},setMapStyle:function(_18){this.mapStyle=_18;this._getTileInfo();},setCulture:function(_19){this.culture=_19;this._getTileInfo();},setBingMapsKey:function(_1a){this.bingMapsKey=_1a;}});_4.mixin(esri.virtualearth.VETiledLayer,{MAP_STYLE_AERIAL:"aerial",MAP_STYLE_AERIAL_WITH_LABELS:"aerialWithLabels",MAP_STYLE_ROAD:"road"});}}};});