Sunday, September 30, 2012

Map Scale in ESRI Silverlight API


To display better scale information on the map, it's recommended to use the following technique.

1.       As always use the ESRI “ScaleLine” control for the Map.

2.       Utilize the property changed event of this control and then compute the scale to display.

Here is the sample code.
 

XAML code:

<StackPanel Orientation="Vertical">
<TextBlock x:Name="textBlockScaleVaue" Text="Scale" Margin="5,5,5,1" Foreground="White" FontSize="10"
FontStyle="Normal" FontWeight="Normal" Opacity="1.0"/>
<esri:ScaleLine Opacity="1.0" Map="{Binding ElementName=mapControl}" Margin="5,1,5,5" IsHitTestVisible="False" Foreground="White"
Name="scaleLine" MapUnit="Miles" PropertyChanged="scaleLine_PropertyChanged" >
</esri:ScaleLine>
</StackPanel>

.cs file code:

private void scaleLine_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
double currentMapscale = scaleLine.USValue;
ESRI.ArcGIS.Client.Toolkit.ScaleLine.ScaleLineUnit currentMapunit = scaleLine.USUnit;
double valueinInches = 0.0;
if (currentMapunit == ESRI.ArcGIS.Client.Toolkit.ScaleLine.ScaleLineUnit.Feet)
{
valueinInches = 12.0 * currentMapscale;
}
else if (currentMapunit == ESRI.ArcGIS.Client.Toolkit.ScaleLine.ScaleLineUnit.Miles)
{
valueinInches = 12.0 * 5280.0 * currentMapscale;
}
this.textBlockScaleVaue.Text = "Scale: 1:" + valueinInches.ToString("#,##0.##");
}

Hope this tip helps.

 Happy programming!

 

 

 

All Blogs so far ...