/*
 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
 */

if(!dojo._hasResource["esri.virtualearth.VETiledLayer"]){dojo._hasResource["esri.virtualearth.VETiledLayer"]=true;dojo.provide("esri.virtualearth.VETiledLayer");dojo.require("esri.utils");dojo.require("esri.layers.tiled");dojo.require("esri.geometry");dojo.require("dojo.string");dojo.declare("esri.virtualearth.VETiledLayer",esri.layers.TiledMapServiceLayer,{constructor:function(_1){try{_1=dojo.mixin({bingMapsKey:null,culture:"en-US"},_1||{});var _2=window.location.protocol;if(_2==="file:"){_2="http:";}this.url=_2+"//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})));dojo.mixin(this,_1);this._initLayer=dojo.hitch(this,this._initLayer);this._errorHandler=dojo.hitch(this,this._errorHandler);this._getTileInfo=dojo.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(_3,_4){this.inherited("_unsetMap",arguments);},_getTileInfo:function(){if(this.bingMapsKey){var _5=this.resourceInfo;if(!this.loaded&&_5){this._initLayer(_5);}else{esri.request({url:this._url.path,content:dojo.mixin({},this._url.query,{token:this.bingMapsKey,style:this.mapStyle,culture:this.culture}),callbackParamName:"callback",load:this._initLayer,error:this._errorHandler});}}},_initLayer:function(_6,io){try{this.resourceInfo=dojo.toJson(_6);var _7=_6.imageUri.replace("{","${");this.tileServers=dojo.map(_6.subDomains,function(_8){var _9=window.location.protocol;if(_9==="file:"){_9="http:";}return dojo.string.substitute(_7,{subdomain:_8}).replace("http:",_9);});this._tsLength=this.tileServers.length;if(!this.loaded){this.loaded=true;this.onLoad(this);var _a=this.loadCallback;if(_a){delete this.loadCallback;_a(this);}}else{this.refresh();}}catch(e){this.onError(e);}},getTileUrl:function(_b,_c,_d){var _e=this.tileServers[_c%this._tsLength],_f=_e.replace(/\{/g,"${");return dojo.string.substitute(_f,{quadkey:this._getQuadKey(_b,_c,_d),culture:this.culture,token:this.bingMapsKey});},_getQuadKey:function(_10,row,col){var _11="",_12,_13,i;for(i=_10;i>0;i--){_12="0";_13=1<<(i-1);if((col&_13)!=0){_12++;}if((row&_13)!=0){_12++;_12++;}_11=_11+_12;}return _11;},setMapStyle:function(_14){this.mapStyle=_14;this._getTileInfo();},setCulture:function(_15){this.culture=_15;this._getTileInfo();},setBingMapsKey:function(_16){this.bingMapsKey=_16;}});dojo.mixin(esri.virtualearth.VETiledLayer,{MAP_STYLE_AERIAL:"aerial",MAP_STYLE_AERIAL_WITH_LABELS:"aerialWithLabels",MAP_STYLE_ROAD:"road"});}