/*
 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.dijit.Scalebar"],["require","esri.geometry"],["require","esri.map"],["require","esri.WKIDUnitConversion"]],defineResource:function(_4,_5,_6){if(!_4._hasResource["esri.dijit.Scalebar"]){_4._hasResource["esri.dijit.Scalebar"]=true;_4.provide("esri.dijit.Scalebar");_4.require("esri.geometry");_4.require("esri.map");_4.require("esri.WKIDUnitConversion");(function(){var _7=[_4.moduleUrl("esri.dijit","css/Scalebar.css")];var _8=document.getElementsByTagName("head").item(0),_9;for(var i=0,il=_7.length;i<il;i++){_9=document.createElement("link");_9.type="text/css";_9.rel="stylesheet";_9.href=_7[i].toString();_8.appendChild(_9);}}());_4.declare("esri.dijit.Scalebar",null,{map:null,mapUnit:null,scalebarUnit:null,unitsDictionary:[],domNode:null,screenPt1:null,screenPt2:null,constructor:function(_a,_b){this.domNode=_4.create("div",{innerHTML:"<div class='esriScalebarRuler'><div class='esriScalebarRulerBlock upper_firstpiece'></div><div class='esriScalebarRulerBlock upper_secondpiece'></div><div class='esriScalebarRulerBlock lower_firstpiece'></div><div class='esriScalebarRulerBlock lower_secondpiece'></div></div><div class='scaleLabelDiv'><div class='esriScalebarLabel' style='left: -3%'>0</div><div class='esriScalebarLabel esriScalebarFirstNumber'></div><div class='esriScalebarLabel esriScalebarSecondNumber'></div></div>"});_a=_a||{};if(!_a.map){console.error("scalebar: unable to find the 'map' property in parameters");return;}if(!_a.scalebarUnit){this.scalebarUnit="mi";}else{if(_a.scalebarUnit!=="english"&&_a.scalebarUnit!=="metric"){console.error("scalebar unit only accepts english or metric");return;}else{this.scalebarUnit=(_a.scalebarUnit==="english")?"mi":"km";}}this.map=_a.map;if(_b){_b.appendChild(this.domNode);}else{this.map.container.appendChild(this.domNode);if(_a.attachTo){_4.addClass(this.domNode,"scalebar_"+_a.attachTo);}else{_4.addClass(this.domNode,"scalebar_bottom-left");}}_4.addClass(this.domNode,"esriScalebar");this._getDistance(this.map.extent);this._checkBingMaps();this._mapOnPan=_4.connect(this.map,"onPan",this,this._getDistance);this._mapOnExtentChange=_4.connect(this.map,"onExtentChange",this,this._getDistance);_4.forEach(this.map.layerIds,function(_c,_d){if(this.map.getLayer(_c).declaredClass==="esri.virtualearth.VETiledLayer"){_4.connect(this.map.getLayer(_c),"onVisibilityChange",_4.hitch(this,function(_e){this._checkBingMaps();}));}},this);this._mapOnLayerAdd=_4.connect(this.map,"onLayerAdd",_4.hitch(this,function(_f){if(_f.declaredClass==="esri.virtualearth.VETiledLayer"){_4.connect(_f,"onVisibilityChange",_4.hitch(this,function(_10){this._checkBingMaps();}));}this._checkBingMaps();}));this._mapOnLayerRemove=_4.connect(this.map,"onLayerRemove",_4.hitch(this,this._checkBingMaps));},hide:function(){this._hidden=true;esri.hide(this.domNode);},show:function(){this._hidden=false;esri.show(this.domNode);},destroy:function(){_4.disconnect(this._mapOnPan);_4.disconnect(this._mapOnExtentChange);_4.disconnect(this._mapOnLayerAdd);_4.disconnect(this._mapOnLayerRemove);this.hide();this.map=null;_4.destroy(this.domNode);},_checkBingMaps:function(){if(_4.hasClass(this.domNode,"scalebar_bottom-left")){_4.style(this.domNode,"left","25px");_4.forEach(this.map.layerIds,function(_11,idx){if(this.map.getLayer(_11).declaredClass==="esri.virtualearth.VETiledLayer"&&this.map.getLayer(_11).visible){var _12="95px";if(this.map._mapParams.nav){_12="115px";}_4.style(this.domNode,"left",_12);}},this);}},_getDistance:function(_13){var _14=_4.position(this.domNode,true);var _15=_14.y-this.map.position.y;_15=(_15>this.map.height)?this.map.height:_15;_15=(_15<0)?0:_15;var _16=new esri.geometry.Point(0,_15,this.map.spatialReference);var _17=new esri.geometry.Point(this.map.width,_15,this.map.spatialReference);var _18,_19;this.mapUnit="esriDecimalDegrees";var pt1=esri.geometry.toMapPoint(_13,this.map.width,this.map.height,_16);var pt2=esri.geometry.toMapPoint(_13,this.map.width,this.map.height,_17);var _1a=new esri.geometry.Point(_13.xmin,(_13.ymin+_13.ymax)/2,this.map.spatialReference);var _1b=new esri.geometry.Point(_13.xmax,(_13.ymin+_13.ymax)/2,this.map.spatialReference);if(this.map.spatialReference.wkid===3857||this.map.spatialReference.wkid===102100||this.map.spatialReference.wkid===102113||(this.map.spatialReference.wkt&&this.map.spatialReference.wkt.indexOf("WGS_1984_Web_Mercator")!=-1)){pt1=esri.geometry.webMercatorToGeographic(pt1,true);pt2=esri.geometry.webMercatorToGeographic(pt2,true);_1a=esri.geometry.webMercatorToGeographic(_1a,true);_1b=esri.geometry.webMercatorToGeographic(_1b,true);}else{if(esri._isDefined(esri.WKIDUnitConversion[this.map.spatialReference.wkid])||(this.map.spatialReference.wkt&&this.map.spatialReference.wkt.indexOf("PROJCS")===0)){this.mapUnit="linearUnit";_18=Math.abs(_13.xmax-_13.xmin);var _1c;if(esri._isDefined(esri.WKIDUnitConversion[this.map.spatialReference.wkid])){_1c=esri.WKIDUnitConversion.values[esri.WKIDUnitConversion[this.map.spatialReference.wkid]];}else{var wkt=this.map.spatialReference.wkt;var _1d=wkt.lastIndexOf(",")+1;var end=wkt.lastIndexOf("]]");_1c=parseFloat(wkt.substring(_1d,end));}_18*=_1c;if(this.scalebarUnit==="mi"){_18/=1609;}else{_18/=1000;}}}if(this.mapUnit==="esriDecimalDegrees"){var _1e=new esri.geometry.Polyline(new esri.SpatialReference({wkid:4326}));_1e.addPath([pt1,pt2]);var _1f=esri.geometry._straightLineDensify(_1e,10);_18=esri.geometry.geodesicLengths([_1f],esri.Units.KILOMETERS)[0];var _20=new esri.geometry.Polyline(new esri.SpatialReference({wkid:4326}));_20.addPath([_1a,_1b]);var _21=esri.geometry._straightLineDensify(_20,10);_19=esri.geometry.geodesicLengths([_21],esri.Units.KILOMETERS)[0];if(this.scalebarUnit==="mi"){_18/=1.609;_19/=1.609;}}this._getScaleBarLength(_18);if(_19){if(_18/_19>0.1){if(!this._hidden){esri.show(this.domNode);}}else{esri.hide(this.domNode);}}},_getScaleBarLength:function(_22){var _23=50;var _24=_23*_22/this.map.width;var _25=_24;var i=0;var _26=this.scalebarUnit;if(_25<0.1){if(this.scalebarUnit==="mi"){_25*=5280;_26="ft";}else{if(this.scalebarUnit==="km"){_25*=1000;_26="m";}}}while(_25>=1){_25/=10;i++;}var _27,_28;if(_25>0.5){_27=1;_28=0.5;}else{if(_25>0.3){_27=0.5;_28=0.3;}else{if(_25>0.2){_27=0.3;_28=0.2;}else{if(_25>0.15){_27=0.2;_28=0.15;}else{if(_25>0.1){_27=0.15;_28=0.1;}}}}}var _29=((_27/_25)>=(_25/_28))?_28:_27;var _2a=_29/_25;var _2b=_23*_2a;var _2c=Math.pow(10,i)*_29;this._drawScaleBar(_2b,_2c,_26);},_drawScaleBar:function(_2d,_2e,_2f){var _30=2*Math.round(_2d)+"px";this.domNode.style.width=_30;_4.forEach(_4.query(".esriScalebarFirstNumber",this.domNode),function(_31,idx){_31.innerHTML=_2e;},this);_4.forEach(_4.query(".esriScalebarSecondNumber",this.domNode),function(_32,idx){if(this.mapUnit!=="esriUnknown"){_32.innerHTML=2*_2e+_2f;}else{_32.innerHTML=2*_2e+"Unknown Unit";}},this);}});}}};});