esri.dijit.Scalebar : Issues

1473
5
11-04-2010 03:04 AM
__Rich_
Occasional Contributor III
I've just plugged in the scalebar dijit and it doesn't really work...at least not at all extents.

Sometimes it displays NaNmi sometimes it shows that the world is only about 120mi around the equator!

Try the sample to see what I mean.

Move the slider all the way to the bottom i.e. zoom right out and you should see the NaN issue, try zooming in a little from that position and you will find it is indeed, a 'small world'.

The problem I have is that at my initial extent (-180,-90,180,90) I get the NaN error when I instantiate the dijit which is throwing an exception in IE such that the dijit doesn't work at all.  FF is more forgiving in that despite the initial error (and subsequent display of NaNmi) the dijit does work at 'compatible' extents should the user zoom to them.
0 Kudos
5 Replies
MichaelJenkins
Occasional Contributor III
Here's what worked for me.  Initialize the scalebar after your map has loaded, then after the scalebar is initialized, call map.refresh().  Without this, my scalebar was incorrect until I did a zoom.

       //add the scalebar 
          var scalebar = new esri.dijit.Scalebar({
            map: map,
            scalebarUnit:'english'
          });
      //add the overview map 
          var overviewMapDijit = new esri.dijit.OverviewMap({
            map: map,
            color:"#D84E13",
            opacity:.40,
            visible:false,
            id:"overviewMap"
          });
          overviewMapDijit.startup();          
    map.reposition();
    map.resize();
GISP
0 Kudos
__Rich_
Occasional Contributor III
Thanks for the response.

The Map class doesn't have a refresh method but I'll have a play around with sticking a few resize/reposition calls in and see what happens.

There are two issues here:

1.  Under certain conditions the initialisation of the scalebar widget fails, so far I have determined that it always fails if the initial map extent is -180,-90,180,90 (wkid:4326) which is pretty poor.  Incidentally it seems happy with -179.999,-89.999,179.999,89.999!!!!

2.  At some extents the values shown are nonsense.  (see attachment - screenshot taken after panning/zooming!)

I will continue to look into it, but I have to say I'm disappointed...
0 Kudos
JianHuang
Occasional Contributor III
Thanks for the feedback.
When zooming out to the extent covering the whole world under web mercator projection or GCS, there is no meaningful scale value. I attach a screenshot of google maps, which behaves similarly.
The reason behind the scenes is those projections distort the map, hence the scale value varies in different area. So there is not a single scale value which can represent the whole map. The implementation of the scalebar picks the scale value at the location of itself to represent the map. In a relatively small area, this is not a problem. But in a map which covers the whole world, the scale values in different area differ drastically. The reason the scalebar shows very small values in the map is because it's under the south pole. So it uses the scale value in south pole area to create the scalebar.
But for sure, we can improve the behavior. Issue 1 will be fixed at the next release. Issue 2 will be fixed as well. It will find a more appropriate scale value when the map covers the whole world.
Thanks again.
0 Kudos
__Rich_
Occasional Contributor III
Thanks for the feedback.
When zooming out to the extent covering the whole world under web mercator projection or GCS, there is no meaningful scale value. I attach a screenshot of google maps, which behaves similarly.
The reason behind the scenes is those projections distort the map, hence the scale value varies in different area. So there is not a single scale value which can represent the whole map. The implementation of the scalebar picks the scale value at the location of itself to represent the map. In a relatively small area, this is not a problem. But in a map which covers the whole world, the scale values in different area differ drastically. The reason the scalebar shows very small values in the map is because it's under the south pole. So it uses the scale value in south pole area to create the scalebar.
But for sure, we can improve the behavior. Issue 1 will be fixed at the next release. Issue 2 will be fixed as well. It will find a more appropriate scale value when the map covers the whole world.
Thanks again.


Thanks for the response.

I understand the problems in making an accurate scalebar and that the accuracy is inversely proportional to the size of the extent.

Interesting info, I would have thought the middle latitude would have been a better choice, since most users will have the area of interest in the middle of their current extent.  By choosing the extreme southerly latitude it makes the scalebar (even more) inaccurate for the probable area of interest.

Presumably the most southerly latitude is still used when using the scalebar in an external container, like in this sample.
0 Kudos
KellyHutchins
Esri Frequent Contributor
You are correct, in the sample you like the southerly postion is used. The Scalebar widget help topic provides a few details about the location used to calculate the scale when placed externally.

http://help.arcgis.com/EN/webapi/javascript/arcgis/help/jsapi_start.htm#jsapi/scalebar.htm


Presumably the most southerly latitude is still used when using the scalebar in an external container, like in this sample.
0 Kudos