Scale bar wrong after zoom or pan

1184
5
12-19-2010 07:00 PM
mdonnelly
Esri Contributor
Hello,

Has anyone seen the problem where the scalebar becomes incorrect after a zoom or pan? When the map initially loads the scale looks about right. When I zoom in or pan, the scale bar refreshes with the wrong scale, eg it goes from measuring 0.3 km to 100km after zooming.

See the before and after shots attached.
Regards,
Mark
0 Kudos
5 Replies
by Anonymous User
Not applicable
Original User: mdonnelly

OK, I think I know the answer to this one.

The scalebar is first loaded after the map layer is loaded. Next I load a web service layer which is in in different units and a different projection. I then move that to be the first layer, ie 0.

So, the scale bar is set correctly on the base map and then subsequently it looks to the web service layer and gets a different scale as this is the bottom most layer.

I'll have sort out the difference between these two layers.
0 Kudos
mdonnelly
Esri Contributor
Nope, that doesn't seem to fix anything.

I have changed the web service layer to have exactly the same projection as the other layers but it still behaves as it did before.

It must have something to do with the web service map layer because if I don't load it, the problem goes away.
Regards,
Mark
0 Kudos
mdonnelly
Esri Contributor
After chasing numerous red herrings I have found the solution:

When I load the WMS layer the 'units' property is not defined by default. This causes the api scale bar calculations to get pretty confused and come up with the wrong numbers on the scale bar.

To get around this I had to manually define the WMS layer 'units' property as 'esriMeters':

wmsLayer.units = "esriMeters";
map.addLayer(wmsLayer,0);


I guess this could be caused by any layer that does not have it's 'units' property defined by default. I hope this helps other people who come across this problem.

Regards,

Mark
Regards,
Mark
0 Kudos
mdonnelly
Esri Contributor
Note that the scalebar units are taken from the layer with the zero index, so the fix only applies to that layer.

ie the map layer that is the first to be added to the map or if as in the previous example, the layer is added to index 0. The layer could also be moved to index 0 as well and that would affect calculations.

Regards,

Mark
Regards,
Mark
0 Kudos
by Anonymous User
Not applicable
Original User: Jian

Mark,

You are right. The scalebar read map unit from the first layer. The next version will read it from the map.spatialReference to determine if this is a projected coordinate system, then decide the unit. Another words, you don't have to specify the unit for your WMS layer. However, I would still encourage to set the correct unit for your layer for the reason of completeness.
Thanks.
0 Kudos