Select to view content in your preferred language

scalebarUnit - Changing the units

1433
4
02-10-2011 02:35 PM
CarlaYarrow
Emerging Contributor
I'm wondering if anyone knows how to alter the units in Javascript API from 'english' (which gives miles) to kilometers?

var scalebar = new esri.dijit.Scalebar({
            map: map,
            scalebarUnit:'english'
          });

I have tried using 'metric'. No luck! Any help on this one?
0 Kudos
4 Replies
JianHuang
Deactivated User
Please refer to the doc at:
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm#jsapi/scalebar.htm
It documents as:
<String> scalebarUnit  Specify the scalebar units. Valid values are "english" or "metric". The default value is "english".
Thanks.
0 Kudos
AdrianMarsden
Honored Contributor
I tried this myself, however it fails



It has both Yards and meters on it - zooming out, just "english" and zooming in further the two units overwrtite each other.  Snippet where I call it below.

        dojo.connect(map, 'onLoad', function(theMap) {
           
   var scalebar = new esri.dijit.Scalebar({
            map: map,
            scalebarUnit:'metric'
          });        
           
           
          //resize the map when the browser resizes
          dojo.connect(dijit.byId('map'), 'resize', map,map.resize);
         
         //add the overview map
          overviewMapDijit = new esri.dijit.OverviewMap({
             
            map: map,
   expandFactor:4
          }, dojo.byId('overviewMapDiv'));
          overviewMapDijit.startup();
   
        });
0 Kudos
AdrianMarsden
Honored Contributor
😮 Doh! Note to self - when re-using code from Esri examples and other places, make sure you don't call stuff twice.

I'd re-used some older code wit a scale bar, but had stripped out the initial definition, so it didn't work, then added the whole lot back in - result 2 bars, one metric the other "american" - Note to Esri, here in England we are trying very hard to use metric 😄
0 Kudos
JeffPace
MVP Alum
😮 Doh! Note to self - when re-using code from Esri examples and other places, make sure you don't call stuff twice.

I'd re-used some older code wit a scale bar, but had stripped out the initial definition, so it didn't work, then added the whole lot back in - result 2 bars, one metric the other "american" - Note to Esri, here in England we are trying very hard to use metric 😄


We did that in America back in the 80s. It didn't take.
0 Kudos