how to customerize the scalebar?

715
4
10-26-2010 09:40 AM
DanDong
New Contributor
Hi all,

I want to have a scalebar like this, but right now, I can't find a way to change the style of scalebar in silverlight API.

Basically, I need the scalebar has many values displaying on the top of the scalebar and I want the scalebar to change the units as zoomin or zoomout, say on the state level, it display the unit of miles, when it becomes the county level, it displays the unit of feet.

Any suggestions, thanks very much!
0 Kudos
4 Replies
DominiqueBroux
Esri Frequent Contributor
You could change the scalebar displayunit when the map extent changes.

Something like (to adapt from your map units and the expected scalebar units):
       void Map_ExtentChanged(object sender, ExtentEventArgs e)
        {
            ScaleBarUnit scaleBarUnit;

            double width = e.NewExtent.Width;
            if (width < 10)
                scaleBarUnit = ScaleBarUnit.Centimeters;
            else if (width > 100000)
                scaleBarUnit = ScaleBarUnit.Kilometers;
            else
                scaleBarUnit = ScaleBarUnit.Meters;

            myScaleBar.DisplayUnit = scaleBarUnit;
        }
and XAML
       <esri:Map x:Name="Map" ExtentChanged="Map_ExtentChanged">
0 Kudos
DanDong
New Contributor
You could change the scalebar displayunit when the map extent changes.

Something like (to adapt from your map units and the expected scalebar units):
       void Map_ExtentChanged(object sender, ExtentEventArgs e)
        {
            ScaleBarUnit scaleBarUnit;

            double width = e.NewExtent.Width;
            if (width < 10)
                scaleBarUnit = ScaleBarUnit.Centimeters;
            else if (width > 100000)
                scaleBarUnit = ScaleBarUnit.Kilometers;
            else
                scaleBarUnit = ScaleBarUnit.Meters;

            myScaleBar.DisplayUnit = scaleBarUnit;
        }
and XAML
       <esri:Map x:Name="Map" ExtentChanged="Map_ExtentChanged">


Thanks dbroux. I will try this method. btw: how can I change the outlook of the scalebar, just like the image I attached, with different values on the top of the scalebar.
0 Kudos
JenniferNery
Esri Regular Contributor
Please look at this related thread: http://forums.arcgis.com/threads/15157-Access-ScaleBars-Current-Value Post #4, you can update this style.
0 Kudos
DanDong
New Contributor
Please look at this related thread: http://forums.arcgis.com/threads/15157-Access-ScaleBars-Current-Value Post #4, you can update this style.


Thank you Jennifer, that helps a lot. 🙂 Now I have a dynamic scalebar.
0 Kudos