ArcGIS API for Silverlight - Library Reference
Units Property
See Also  Example Send comments on this topic
ESRI.ArcGIS.Client Namespace > ArcGISDynamicMapServiceLayer Class : Units Property

The map units the ArcGISDynamicMapServiceLayer uses for its default spatial reference.

Syntax

Visual Basic (Declaration) 
Public ReadOnly Property Units As String
C# 
public string Units {get;}

Remarks

The map unit strings that can be returned from the Units Property include:

  • esriCentimeters
  • esriDecimalDegrees
  • esriDecimeters
  • esriFeet
  • esriInches
  • esriKilometers
  • esriMeters
  • esriMiles
  • esriMillimeters
  • esriNauticalMiles
  • esriPoints
  • esriUnknownUnits
  • esriYards

Example

How to use:

Choose a Url from the ComboBox and then click the Button. A Map Control will be created on-the-fly via code-behind and then an ArcGISDynamicMapServiceLayer for then Url will be added to the Map. The Units and SpatialReference information will be displayed.

The XAML code in this example is used in conjunction with the code-behind (C# or VB.NET) to demonstrate the functionality.

The following screen shot corresponds to the code example in this page.

Discovering the Units of an ArcGISDynamicMapServiceLayer.

XAMLCopy Code
<Grid x:Name="LayoutRoot">
   
  <!-- Add a Stack Panel that will be used to hold the Map Control that is added via code-behind.  -->
  <StackPanel HorizontalAlignment="Left" Margin="12,288,0,0" Name="StackPanel1" 
              VerticalAlignment="Top" Width="775" Height="300">
  </StackPanel>
  
  <!-- 
  Add a ComboBox that allows the user to choose Url's for specifying different ArcGISDynamicMapServiceLayer's.
  Each ArcGISDynaicMapServiceLayer has unique Units and SpatialReference information. 
  -->
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="11,195,0,0" Name="Label1" 
             VerticalAlignment="Top" Width="26" Content="Url:"/>
  <ComboBox Height="28" HorizontalAlignment="Left" Margin="41,189,0,0" Name="ComboBox1" VerticalAlignment="Top" 
            Width="746" SelectedIndex="0">
    <ComboBoxItem>
      http://server.arcgisonline.com/ArcGIS/rest/services/Reference/ESRI_BoundariesPlaces_World_2D/MapServer
    </ComboBoxItem>
    <ComboBoxItem>
      http://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer
    </ComboBoxItem>
    <ComboBoxItem>
      http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/TaxParcel/IndustryFocusedPublicAccessMap/MapServer
    </ComboBoxItem>
  </ComboBox>
  
  <!-- Add a Button to perform the work. -->
  <Button Content="Load an ArcGISDynamicMapServiceLayer" Height="25" HorizontalAlignment="Left" 
          Margin="11,257,0,0" Name="Button1" VerticalAlignment="Top" Width="776" Click="Button1_Click"/>
  
  <!-- Display information about the ArcGISDynamicMapServiceLayer.Units. -->
  <sdk:Label HorizontalAlignment="Left" Margin="6,223,0,0" Name="Label2" Width="32" Content="Units:"
             VerticalAlignment="Top" Height="28" />
  <TextBlock Height="28" HorizontalAlignment="Left" Margin="42,223,0,0" Name="TextBlock_Units" 
             VerticalAlignment="Top" Width="145" />
  
  <!-- Display information about the ArcGISDynamicMapServiceLayer.SpatialReference. -->
  <sdk:Label Height="28" Margin="193,223,0,0" Name="Label3" HorizontalAlignment="Left"
             VerticalAlignment="Top" Content="SpatialReference:"/>
  <TextBlock Height="28" HorizontalAlignment="Left" Margin="298,223,0,0" Name="TextBlock_SpatialReference"  
             VerticalAlignment="Top" Width="490" />
  
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="183" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="787" 
             TextWrapping="Wrap" Text="Choose a Url from the ComboBox and then click the Button. A Map Control 
             will be created on-the-fly via code-behind and then an ArcGISDynamicMapServiceLayer for then Url 
             will be added to the Map. The Units and SpatialReference information will be displayed." />
  
</Grid>
C#Copy Code
// NOTE: From the ESRI.ArcGIS.Client.Map.SpatialReference API documentation:
// -------------------------------------------------------------------------
// The SpatialReference of the Map can be overridden (meaning that you can set the Map.SpatialReference) by 
// explicitly setting the Map.Extent Property with an Envelope that has an Envelope.SpatialReference defined. 
// Initializing a Map’s SpatialReference via the Map.Extent Property has to be done before any layers will be 
// added to the Map. Once the SpatialReference of a Map has been set and the layers have been loaded, the 
// SpatialReference can no longer be changed. If you need to change SpatialReference on the fly, you can 
// instead create a new Map instance, move the layers to this Map, and replace the previous Map instance. 
            
private void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
{
  // In this code example, each of the Url's options for the ArcGISDynamicMapServiceLayer in the ComboBox
  // will have a different SpatialReference. To make this sample work, we construct the Map Control on-the-fly
  // for each user choice of the ComboBox to accomodate the changing SpatialReference values.
  
  // Get the StackPanel that was defined in a XAML and remove all child controls.
  StackPanel theStackPanel = (StackPanel)(LayoutRoot.Children[0]);
  theStackPanel.Children.Clear();
  
  // Create a new Map Control, define the intial size properties and wrapwround mode, and then add it to the
  // StackPanel UI Control.
  ESRI.ArcGIS.Client.Map Map1 = new ESRI.ArcGIS.Client.Map();
  Map1.WrapAround = true;
  Map1.Height = 300;
  Map1.Width = 775;
  theStackPanel.Children.Add(Map1);
  
  // Get the user choice from the ComboBox that contains the Url for defining an ArcGISDynamicMapServiceLayer.
  string theUrl = ComboBox1.SelectionBoxItem.ToString();
  if (theUrl != null)
  {
    // Create a new ArcGISDynamicMapServiceLayer using the Url and add it to the Map Control. 
    ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer theArcGISDynamicMapServiceLayer = new ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer();
    theArcGISDynamicMapServiceLayer.Url = theUrl;
    Map1.Layers.Add(theArcGISDynamicMapServiceLayer);
    
    // Wire up the Intialized Event Handler. This will be used to display the ArcGISDynamicMapServiceLayer Unit and
    // SpatialReference information.
    theArcGISDynamicMapServiceLayer.Initialized += theArcGISDynamicMapServiceLayer_Initialized;
  }
}
            
private void theArcGISDynamicMapServiceLayer_Initialized(object sender, EventArgs e)
{
  // Get the ArcGISDynamicMapServiceLayer. 
  ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer theArcGISDynamicMapServiceLayer = null;
  theArcGISDynamicMapServiceLayer = (ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer)sender;
  
  // Get and display the ArcGISDynamicMapServiceLayer.Units information.
  string theUnits = theArcGISDynamicMapServiceLayer.Units;
  TextBlock_Units.Text = theUnits;
  
  // Get and display the ArcGISDynamicMapServiceLayer.SpatialReference information.
  ESRI.ArcGIS.Client.Geometry.SpatialReference theSpatialReference = theArcGISDynamicMapServiceLayer.SpatialReference;
  if (theSpatialReference != null)
  {
    int theWKID = theSpatialReference.WKID;
    string theWKT = theSpatialReference.WKT;
    if (theWKID != 0)
    {
      TextBlock_SpatialReference.Text = "WKID: " + theWKID.ToString();
    }
      else
    {
      TextBlock_SpatialReference.Text = "WKT: " + theWKT;
    }
  }
}
VB.NETCopy Code
' NOTE: From the ESRI.ArcGIS.Client.Map.SpatialReference API documentation:
' -------------------------------------------------------------------------
' The SpatialReference of the Map can be overridden (meaning that you can set the Map.SpatialReference) by 
' explicitly setting the Map.Extent Property with an Envelope that has an Envelope.SpatialReference defined. 
' Initializing a Map’s SpatialReference via the Map.Extent Property has to be done before any layers will be 
' added to the Map. Once the SpatialReference of a Map has been set and the layers have been loaded, the 
' SpatialReference can no longer be changed. If you need to change SpatialReference on the fly, you can 
' instead create a new Map instance, move the layers to this Map, and replace the previous Map instance. 
            
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
  
  ' In this code example, each of the Url's options for the ArcGISDynamicMapServiceLayer in the ComboBox
  ' will have a different SpatialReference. To make this sample work, we construct the Map Control on-the-fly
  ' for each user choice of the ComboBox to accomodate the changing SpatialReference values.
  
  ' Get the StackPanel that was defined in a XAML and remove all child controls.
  Dim theStackPanel As StackPanel = CType(LayoutRoot.Children(0), StackPanel)
  theStackPanel.Children.Clear()
  
  ' Create a new Map Control, define the intial size properties and wrapwround mode, and then add it to the
  ' StackPanel UI Control.
  Dim Map1 As ESRI.ArcGIS.Client.Map = New ESRI.ArcGIS.Client.Map
  Map1.WrapAround = True
  Map1.Height = 300
  Map1.Width = 775
  theStackPanel.Children.Add(Map1)
  
  ' Get the user choice from the ComboBox that contains the Url for defining an ArcGISDynamicMapServiceLayer.
  Dim theUrl As String = ComboBox1.SelectionBoxItem.ToString
  If theUrl IsNot Nothing Then
    
    ' Create a new ArcGISDynamicMapServiceLayer using the Url and add it to the Map Control. 
    Dim theArcGISDynamicMapServiceLayer As New ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer
    theArcGISDynamicMapServiceLayer.Url = theUrl
    Map1.Layers.Add(theArcGISDynamicMapServiceLayer)
    
    ' Wire up the Intialized Event Handler. This will be used to display the ArcGISDynamicMapServiceLayer Unit and
    ' SpatialReference information.
    AddHandler theArcGISDynamicMapServiceLayer.Initialized, AddressOf theArcGISDynamicMapServiceLayer_Initialized
    
  End If
  
End Sub
            
Private Sub theArcGISDynamicMapServiceLayer_Initialized(sender As Object, e As EventArgs)
  
  ' Get the ArcGISDynamicMapServiceLayer. 
  Dim theArcGISDynamicMapServiceLayer As ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer
  theArcGISDynamicMapServiceLayer = CType(sender, ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer)
  
  ' Get and display the ArcGISDynamicMapServiceLayer.Units information.
  Dim theUnits As String = theArcGISDynamicMapServiceLayer.Units
  TextBlock_Units.Text = theUnits
  
  ' Get and display the ArcGISDynamicMapServiceLayer.SpatialReference information.
  Dim theSpatialReference As ESRI.ArcGIS.Client.Geometry.SpatialReference = theArcGISDynamicMapServiceLayer.SpatialReference
  If theSpatialReference IsNot Nothing Then
    Dim theWKID As Integer = theSpatialReference.WKID
    Dim theWKT As String = theSpatialReference.WKT
    If theWKID <> Nothing Then
      TextBlock_SpatialReference.Text = "WKID: " + theWKID.ToString
    Else
      TextBlock_SpatialReference.Text = "WKT: " + theWKT
    End If
  End If
  
End Sub

Requirements

Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7

See Also

© ESRI, Inc. All Rights Reserved.