ArcGIS Runtime SDK for WPF - Library Reference
Units Property
See Also  Example
ESRI.ArcGIS.Client Namespace > ArcGISTiledMapServiceLayer Class : Units Property

The map units the ArcGISTiledMapServiceLayer 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 ArcGISTiledMapServiceLayer for the 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 ArcGISTiledMapServiceLayer.

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 ArcGISTiledMapServiceLayer's.
  Each ArcGISTiledMapServiceLayer has unique Units and SpatialReference information. 
  -->
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="13,62,0,0" Name="Label1" 
       VerticalAlignment="Top" Width="26" Content="Url:"/>
  <ComboBox Height="28" HorizontalAlignment="Left" Margin="41,54,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 ArcGISTiledMapServiceLayer" Height="25" HorizontalAlignment="Left" 
          Margin="11,257,0,0" Name="Button1" VerticalAlignment="Top" Width="776" Click="Button1_Click"/>
  
  <!-- Display information about the ArcGISTiledMapServiceLayer.Units. -->
  <sdk:Label HorizontalAlignment="Left" Margin="12,90,0,0" Name="Label2" Width="32" Content="Units:"
       VerticalAlignment="Top" Height="25" />
  <TextBlock Height="28" HorizontalAlignment="Left" Margin="48,87,0,0" Name="TextBlock_Units" 
             VerticalAlignment="Top" Width="145" />
  
  <!-- Display information about the ArcGISTiledMapServiceLayer.SpatialReference. -->
  <sdk:Label Height="28" Margin="12,118,0,0" Name="Label3" HorizontalAlignment="Left"
       VerticalAlignment="Top" Content="SpatialReference:"/>
  <TextBlock Height="118" HorizontalAlignment="Left" Margin="12,133,0,0" Name="TextBlock_SpatialReference"  
             VerticalAlignment="Top" Width="775" TextWrapping="Wrap"/>
  
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="50" 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 ArcGISTiledMapServiceLayer for the 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 ArcGISTiledMapServiceLayer 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 initial 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 ArcGISTiledMapServiceLayer.
  string theUrl = ComboBox1.SelectionBoxItem.ToString();
  if (theUrl != null)
  {
    // Create a new ArcGISTiledMapServiceLayer using the Url and add it to the Map Control. 
    ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer theArcGISTiledMapServiceLayer = new ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer();
    theArcGISTiledMapServiceLayer.Url = theUrl;
    Map1.Layers.Add(theArcGISTiledMapServiceLayer);
    
    // Wire up the Initialized Event Handler. This will be used to display the ArcGISTiledMapServiceLayer Unit and
    // SpatialReference information.
    theArcGISTiledMapServiceLayer.Initialized += theArcGISTiledMapServiceLayer_Initialized;
  }
}
            
private void theArcGISTiledMapServiceLayer_Initialized(object sender, EventArgs e)
{
  // Get the ArcGISTiledMapServiceLayer. 
  ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer theArcGISTiledMapServiceLayer = null;
  theArcGISTiledMapServiceLayer = (ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer)sender;
  
  // Get and display the ArcGISTiledMapServiceLayer.Units information.
  string theUnits = theArcGISTiledMapServiceLayer.Units;
  TextBlock_Units.Text = theUnits;
  
  // Get and display the ArcGISTiledMapServiceLayer.SpatialReference information.
  ESRI.ArcGIS.Client.Geometry.SpatialReference theSpatialReference = theArcGISTiledMapServiceLayer.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 ArcGISTiledMapServiceLayer 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 initial 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 ArcGISTiledMapServiceLayer.
  Dim theUrl As String = ComboBox1.SelectionBoxItem.ToString
  If theUrl IsNot Nothing Then
    
    ' Create a new ArcGISTiledMapServiceLayer using the Url and add it to the Map Control. 
    Dim theArcGISTiledMapServiceLayer As New ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer
    theArcGISTiledMapServiceLayer.Url = theUrl
    Map1.Layers.Add(theArcGISTiledMapServiceLayer)
    
    ' Wire up the Initialized Event Handler. This will be used to display the ArcGISTiledMapServiceLayer Unit and
    ' SpatialReference information.
    AddHandler theArcGISTiledMapServiceLayer.Initialized, AddressOf theArcGISTiledMapServiceLayer_Initialized
    
  End If
  
End Sub
            
Private Sub theArcGISTiledMapServiceLayer_Initialized(sender As Object, e As EventArgs)
  
  ' Get the ArcGISTiledMapServiceLayer. 
  Dim theArcGISTiledMapServiceLayer As ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer
  theArcGISTiledMapServiceLayer = CType(sender, ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer)
  
  ' Get and display the ArcGISTiledMapServiceLayer.Units information.
  Dim theUnits As String = theArcGISTiledMapServiceLayer.Units
  TextBlock_Units.Text = theUnits
  
  ' Get and display the ArcGISTiledMapServiceLayer.SpatialReference information.
  Dim theSpatialReference As ESRI.ArcGIS.Client.Geometry.SpatialReference = theArcGISTiledMapServiceLayer.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, Windows 8

See Also

© ESRI, Inc. All Rights Reserved.