ArcGIS API for Windows Phone - Library Reference
ScaleLine Class
Members  Example  See Also  Send comments on this topic
ESRI.ArcGIS.Client.Toolkit Namespace : ScaleLine Class

The ScaleLine Control generates a line representing a certain distance on the map in both Metric and US units.

Object Model

ScaleLine ClassMap Class

Syntax

Visual Basic (Declaration) 
Public Class ScaleLine 
   Inherits System.Windows.Controls.Control
C# 
public class ScaleLine : System.Windows.Controls.Control 

Remarks

Setting the MapUnit Property:

For the ScaleLine to function correctly, it is possible to set the MapUnit to whatever unit the Map's SpatialReference is using. For example: if the Map's SpatialReference is based on a Geographic coordinate system use DecimalDegrees (aka. Longitude/Latitude) units; if it is a UTM or WebMercator (SRID=102100) projection use Meters.

When the Map is using Geographic units (ie. DecimalDegrees) or WebMercator projection, the approximate scale will be calculated at the center of the map. If any other units are used, a direct conversion between MapUnit's and Metric/US units is used and scale distortion is not taken into account.

Default MapUnit:

If the MapUnit is not set manually, the scale line control will use a default map unit which is calculated from the spatial reference of the map or from the ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer.Units of the layers inside the map. If the spatial reference is Geographic WGS84 (SRID=4326) or WebMercator (SRID=102100), the default MapUnit will be DecimalDegrees and Meters respectively. For others spatial references, the scale line will look at the Units property of the layers having the same spatial reference than the map. If no layers are found, the default DecimalDegrees will be used.

Controling the text on the ScaleLine:

It is not possibly to directly control the values of the text on the ScaleLine as a Property that can be set. The text as part of the ScaleLine that displays is automatically adjusted as the scale of the map changes when the ScaleLine is bound to a Map Control. This also means that it is not possible to control the scale (ie. zoom level) of the Map Control via a Property of the ScaleLine Control.

ScaleBar style

The ScaleLine control replaces the ScaleBar control, which is deprecated. You can apply a template to the ScaleLine control to render with the same look and feel as the ScaleBar control. Below is a sample of a ScaleLine style allowing to get a scale bar with metric units.

Example

XAMLCopy Code
<esri:ScaleLine Name="ScaleLine1" Map="{Binding ElementName=Map1}"
     HorizontalAlignment="Left" VerticalAlignment="Top"  
     TargetWidth="400" 
     Foreground="Black" FontFamily="Courier New" FontSize="18" />
C#Copy Code
//Create a new ScaleLine Control and add it to the LayoutRoot (a Grid in the XAML)
ESRI.ArcGIS.Client.Toolkit.ScaleLine ScaleLine1 = new ESRI.ArcGIS.Client.Toolkit.ScaleLine();
LayoutRoot.Children.Add(ScaleLine1);
             
//Associate the ScaleLine with Map Control (analagous to a OneTime Binding). Most common coding pattern.
ScaleLine1.Map = Map1;
             
//Alternative Binding Method. Useful if the ScaleLine's Properties will dynamically impact other objects.
//System.Windows.Data.Binding myBinding = new System.Windows.Data.Binding();
//myBinding.ElementName = "Map1";
//ScaleLine1.SetBinding(ESRI.ArcGIS.Client.Toolkit.ScaleLine.MapProperty, myBinding);
            
//Set the alignment properties relative the hosting Grid Control
ScaleLine1.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
ScaleLine1.VerticalAlignment = System.Windows.VerticalAlignment.Top;
             
//Set the Map units for the ScaleLine
ScaleLine1.MapUnit = ESRI.ArcGIS.Client.Toolkit.ScaleLine.ScaleLineUnit.DecimalDegrees;
             
//Set the target width for the ScaleLine
ScaleLine1.TargetWidth = 400;
             
//Set ScaleLine color and related Font information
System.Windows.Media.Color myScaleLineColor = Color.FromArgb(255, 0, 0, 0);
ScaleLine1.Foreground = new System.Windows.Media.SolidColorBrush(myScaleLineColor);
ScaleLine1.FontFamily = new FontFamily("Courier New");
ScaleLine1.FontSize = 18;
VB.NETCopy Code
'Create a new ScaleLine Control and add it to the LayoutRoot (a Grid in the XAML)
   Dim ScaleLine1 As New ESRI.ArcGIS.Client.Toolkit.ScaleLine
   LayoutRoot.Children.Add(ScaleLine1)
             
   'Associate the ScaleLine with Map Control (analagous to a OneTime Binding). Most common coding pattern.
   ScaleLine1.Map = Map1
             
   'Alternative Binding Method. Useful if the ScaleLine's Properties will dynamically impact other objects.
   'Dim myBinding As System.Windows.Data.Binding = New System.Windows.Data.Binding()
   'myBinding.ElementName = "Map1"
   'ScaleLine1.SetBinding(ESRI.ArcGIS.Client.Toolkit.ScaleLine.MapProperty, myBinding)
            
   'Set the alignment properties relative the hosting Grid Control
   ScaleLine1.HorizontalAlignment = Windows.HorizontalAlignment.Left
   ScaleLine1.VerticalAlignment = Windows.VerticalAlignment.Top
             
   'Set the Map units for the ScaleLine
   ScaleLine1.MapUnit = ESRI.ArcGIS.Client.Toolkit.ScaleLine.ScaleLineUnit.DecimalDegrees
             
   'Set the target width for the ScaleLine
   ScaleLine1.TargetWidth = 400
             
   'Set ScaleLine color and related Font information
   Dim myScaleLineColor As System.Windows.Media.Color = Color.FromArgb(255, 0, 0, 0)
   ScaleLine1.Foreground = New System.Windows.Media.SolidColorBrush(myScaleLineColor)
   ScaleLine1.FontFamily = New FontFamily("Courier New")
   ScaleLine1.FontSize = 18
XAMLCopy Code
<Style x:Key="ScaleBarStyle" TargetType="esri:ScaleLine">
    <Setter Property="Background" Value="White" />
    <Setter Property="TargetWidth" Value="150.0" />
    <Setter Property="FontSize" Value="10.0" />
    <Setter Property="Foreground" Value="Black" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="esri:ScaleLine">
                <StackPanel Name="LayoutRoot" Orientation="Horizontal">
                    <Grid VerticalAlignment="Center" Height="10" Width="{Binding MetricSize, RelativeSource={RelativeSource TemplatedParent}}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="1*" />
                            <ColumnDefinition Width="1*" />
                            <ColumnDefinition Width="1*" />
                            <ColumnDefinition Width="2*" />
                            <ColumnDefinition Width="5*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="1*" />
                            <RowDefinition Height="1*" />
                        </Grid.RowDefinitions>
                        <Rectangle Fill="{TemplateBinding Foreground}" Grid.Row="0" Grid.Column="0" />
                        <Rectangle Fill="{TemplateBinding Background}" Grid.Row="0" Grid.Column="1" />
                        <Rectangle Fill="{TemplateBinding Foreground}" Grid.Row="0" Grid.Column="2" />
                        <Rectangle Fill="{TemplateBinding Background}" Grid.Row="0" Grid.Column="3" />
                        <Rectangle Fill="{TemplateBinding Foreground}" Grid.Row="0" Grid.Column="4" />
                        <Rectangle Fill="{TemplateBinding Background}" Grid.Row="1" Grid.Column="0" />
                        <Rectangle Fill="{TemplateBinding Foreground}" Grid.Row="1" Grid.Column="1" />
                        <Rectangle Fill="{TemplateBinding Background}" Grid.Row="1" Grid.Column="2" />
                        <Rectangle Fill="{TemplateBinding Foreground}" Grid.Row="1" Grid.Column="3" />
                        <Rectangle Fill="{TemplateBinding Background}" Grid.Row="1" Grid.Column="4" />
                    </Grid>
                    <TextBlock Text="{Binding MetricValue, RelativeSource={RelativeSource TemplatedParent}}" VerticalAlignment="Center" Margin="2,0"/>
                    <TextBlock Text="{Binding MetricUnit, RelativeSource={RelativeSource TemplatedParent}}" VerticalAlignment="Center" />
                </StackPanel>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Inheritance Hierarchy

System.Object
   System.Windows.DependencyObject
      System.Windows.UIElement
         System.Windows.FrameworkElement
            System.Windows.Controls.Control
               ESRI.ArcGIS.Client.Toolkit.ScaleLine

Requirements

Target Platforms: Windows Vista, Windows 7

See Also

© ESRI, Inc. All Rights Reserved.