Note: This API is now obsolete. Please use the ScaleLine control in the ESRI.ArcGIS.Client.Toolkit namespace.
The ScaleBar Control generates a bar representing a certain distance on the map.
Visual Basic (Declaration) | |
---|---|
Public Class ScaleBar Inherits System.Windows.Controls.Control |
C# | |
---|---|
public class ScaleBar : System.Windows.Controls.Control |
XAML | Copy Code |
---|---|
<esri:ScaleBar Name="ScaleBar1" Map="{Binding ElementName=Map1}" HorizontalAlignment="Left" VerticalAlignment="Top" MapUnit="DecimalDegrees" DisplayUnit="Miles" BarHeight="30" TargetWidth="400" TextColor="Black" FontFamily="Courier New" FontSize="18" FillColor1="Magenta" FillColor2="Yellow" /> |
C# | Copy Code |
---|---|
//Create a new ScaleBar Control and add it to the LayoutRoot (a Grid in the XAML) ESRI.ArcGIS.Client.ScaleBar ScaleBar1 = new ESRI.ArcGIS.Client.ScaleBar(); LayoutRoot.Children.Add(ScaleBar1); //Associate the ScaleBar with Map Control (analagous to a OneTime Binding). Most common coding pattern. ScaleBar1.Map = Map1; //Alternative Binding Method. Useful if the ScaleBar's Properties will dynamically impact other objects. //System.Windows.Data.Binding myBinding = new System.Windows.Data.Binding(); //myBinding.ElementName = "Map1"; //ScaleBar1.SetBinding(ESRI.ArcGIS.Client.ScaleBar.MapProperty, myBinding); //Set the alignment properties relative the hosting Grid Control ScaleBar1.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; ScaleBar1.VerticalAlignment = System.Windows.VerticalAlignment.Top; //Set the Map and Display units for the ScaleBar ScaleBar1.MapUnit = ESRI.ArcGIS.Client.ScaleBarUnit.DecimalDegrees; ScaleBar1.DisplayUnit = ESRI.ArcGIS.Client.ScaleBarUnit.Miles; //Set the height and width for the ScaleBar ScaleBar1.BarHeight = 30; ScaleBar1.TargetWidth = 400; //Set TextColor and related Font information System.Windows.Media.Color myTextColor = Color.FromArgb(255, 0, 0, 0); ScaleBar1.TextColor = new System.Windows.Media.SolidColorBrush(myTextColor); ScaleBar1.FontFamily = new FontFamily("Courier New"); ScaleBar1.FontSize = 18; //Set the color of the alternating bars on the ScaleBar System.Windows.Media.Color myFillColor1 = Color.FromArgb(255, 255, 0, 255); ScaleBar1.FillColor1 = new System.Windows.Media.SolidColorBrush(myFillColor1); System.Windows.Media.Color myFillColor2 = Color.FromArgb(255, 255, 255, 0); ScaleBar1.FillColor2 = new System.Windows.Media.SolidColorBrush(myFillColor2); |
VB.NET | Copy Code |
---|---|
'Create a new ScaleBar Control and add it to the LayoutRoot (a Grid in the XAML) Dim ScaleBar1 As New ESRI.ArcGIS.Client.ScaleBar LayoutRoot.Children.Add(ScaleBar1) 'Associate the ScaleBar with Map Control (analagous to a OneTime Binding). Most common coding pattern. ScaleBar1.Map = Map1 'Alternative Binding Method. Useful if the ScaleBar's Properties will dynamically impact other objects. 'Dim myBinding As System.Windows.Data.Binding = New System.Windows.Data.Binding() 'myBinding.ElementName = "Map1" 'ScaleBar1.SetBinding(ESRI.ArcGIS.Client.ScaleBar.MapProperty, myBinding) 'Set the alignment properties relative the hosting Grid Control ScaleBar1.HorizontalAlignment = Windows.HorizontalAlignment.Left ScaleBar1.VerticalAlignment = Windows.VerticalAlignment.Top 'Set the Map and Display units for the ScaleBar ScaleBar1.MapUnit = ESRI.ArcGIS.Client.ScaleBarUnit.DecimalDegrees ScaleBar1.DisplayUnit = ESRI.ArcGIS.Client.ScaleBarUnit.Miles 'Set the height and width for the ScaleBar ScaleBar1.BarHeight = 30 ScaleBar1.TargetWidth = 400 'Set TextColor and related Font information Dim myTextColor As System.Windows.Media.Color = Color.FromArgb(255, 0, 0, 0) ScaleBar1.TextColor = New System.Windows.Media.SolidColorBrush(myTextColor) ScaleBar1.FontFamily = New FontFamily("Courier New") ScaleBar1.FontSize = 18 'Set the color of the alternating bars on the ScaleBar Dim myFillColor1 As System.Windows.Media.Color = Color.FromArgb(255, 255, 0, 255) ScaleBar1.FillColor1 = New System.Windows.Media.SolidColorBrush(myFillColor1) Dim myFillColor2 As System.Windows.Media.Color = Color.FromArgb(255, 255, 255, 0) ScaleBar1.FillColor2 = New System.Windows.Media.SolidColorBrush(myFillColor2) |
The following image depicts a ScaleBar that matches the code Examples in this document.
Setting the MapUnit Property:
For the ScaleBar to function correctly, it is important that the MapUnit is set 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), the approximate scale will be calculated at the center of the map using the EarthRadius as the radius for sphere used as an approximated scale. If any other units are used, a direct conversion between MapUnit's and DisplayUnits is used and scale distortion is not taken into account.
Controling the text on the ScaleBar:
It is not possibly to directly control the values of the text on the ScaleBar as a Property that can be set. The text as part of the ScaleBar that displays is automatically adjusted as the scale of the map changes when the ScaleBar 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 ScaleBar Control.
System.Object
System.Windows.Threading.DispatcherObject
System.Windows.DependencyObject
System.Windows.Media.Visual
System.Windows.UIElement
System.Windows.FrameworkElement
System.Windows.Controls.Control
ESRI.ArcGIS.Client.ScaleBar
Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family