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

Gets an array of sub-layer information, known as LayerInfo objects, in an ArcGISDynamicMapServiceLayer.

Syntax

Visual Basic (Declaration) 
Public ReadOnly Property Layers As LayerInfo()
C# 
public LayerInfo[] Layers {get;}

Remarks

Each LayerInfo in the array will provide the default visibility, unique ID, name, min/max scales, and a set of sub-layer IDs (if present).

Do not confuse the results of a Map.Layers Property (which returns a LayerCollection object) with the ArcGISDynamicMapServicelayer.Layers Property (which return a LayerInfo() object). A LayerCollection is an ObservableCollection of Layer objects used in displaying geographic information via symbols and text.

Example

How to use:

When the application loads the ArcGISDynaimcMapServiceLayer.Initialized Event will display information about the ArcGISDynamicMapServiceLayer.Layers Property in the TextBox.

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.

Interrogating the sub-layer information of the ArcGISDynamicMapServiceLayer.Layers Property.

XAMLCopy Code
<Grid x:Name="LayoutRoot">
    
  <!-- Add a Map Contol. Zoom to the Washington, DC area. -->
  <esri:Map Background="White" HorizontalAlignment="Left" Margin="12,131,0,0" Name="Map1" VerticalAlignment="Top" 
            WrapAround="True" Height="337" Width="384" Extent="-8580189,4701989,-8572263,4708946">
    <esri:Map.Layers>
      <esri:LayerCollection>
             
        <!-- Add an ArcGISDynamicMapServiceLayer; it has multiple sub-layers. Wire up an Initialized Event with code-behind. -->
        <esri:ArcGISDynamicMapServiceLayer ID="World_Topo_Map" Initialized="ArcGISDynamicMapServiceLayer_Initialized"
              Url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer" />
        
      </esri:LayerCollection>
    </esri:Map.Layers>
  </esri:Map>
  
  <!-- Add a TextBox to display ArcGISDynamicMapServiceLayers.Layers Property information. -->
  <TextBox Height="337" HorizontalAlignment="Left" Margin="402,131,0,0" Name="TextBox_Layers" Width="226"
           VerticalAlignment="Top" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Visible" />
  
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="52" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="756" TextWrapping="Wrap" 
             Text="When the application loads the ArcGISDynaimcMapServiceLayer.Initialized Event will display information about 
             the ArcGISDynamicMapServiceLayer.Layers Property in the TextBox." />
  
</Grid>
C#Copy Code
private void ArcGISDynamicMapServiceLayer_Initialized(object sender, System.EventArgs e)
{
  // Get the ArcGISDynamicMapServiceLayer from the Map Control. 
  ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = null;
  myArcGISDynamicMapServiceLayer = (ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer)(Map1.Layers["World_Topo_Map"]);
  
  // Get the ArcGISDynamicMapServiceLayer.Layers Property information (it will be an Array of LayerInfo objects).
  ESRI.ArcGIS.Client.LayerInfo[] myLayerInfo = myArcGISDynamicMapServiceLayer.Layers;
  
  // Create a StringBuilder to display the ArcGISDynamicMapServiceLayer.Layers Property information in a TextBox.
  System.Text.StringBuilder myStringBuilder = new System.Text.StringBuilder();
  
  // Add the count of LayerInfo objects to the StringBuilder.
  myStringBuilder.Append("Number of sub-layers: " + myLayerInfo.Length.ToString() + Environment.NewLine);
  myStringBuilder.Append("===================" + Environment.NewLine);
  
  // Loop through each LayerInfo object.
  foreach (ESRI.ArcGIS.Client.LayerInfo oneLayerInfo in myLayerInfo)
  {
    // Set each of the Properties in the LayerInfo object to corresponding variables. 
    bool myDefaultVisibility = oneLayerInfo.DefaultVisibility;
    int myID = oneLayerInfo.ID;
    double myMaxScale = oneLayerInfo.MaxScale;
    double myMinScale = oneLayerInfo.MinScale;
    string myName = oneLayerInfo.Name;
    int[] mySubLayerIds = oneLayerInfo.SubLayerIds;
    
    // Append the information in the LayerInfo variables to the StringBuilder.
    myStringBuilder.Append("Name: " + myName + Environment.NewLine);
    myStringBuilder.Append("ID: " + myID.ToString() + Environment.NewLine);
    myStringBuilder.Append("DefaultVisibility: " + myDefaultVisibility.ToString() + Environment.NewLine);
    myStringBuilder.Append("MaxScale: " + myMaxScale.ToString() + Environment.NewLine);
    myStringBuilder.Append("MinScale: " + myMinScale.ToString() + Environment.NewLine);
    
    // The LayerInfo.SubLayerIds could return either Nothing/null or an Array of Integer values for 
    // the sub-layer ID's. Add extra code logic to display the LayerInfo.SubLayerIds accordingly. 
    string mySubLayerIdsString = "";
    if (mySubLayerIds != null)
    {
      foreach (int oneSubLayerId in mySubLayerIds)
      {
        mySubLayerIdsString = mySubLayerIdsString + oneSubLayerId.ToString() + ", ";
      }
    }
    else
    {
      mySubLayerIdsString = "[NONE]";
    }
    myStringBuilder.Append("SubLayerIds: " + mySubLayerIdsString + Environment.NewLine + Environment.NewLine);
  }
  
  // Display all of the stuff in the StringBuilder in the TextBox.
  TextBox_Layers.Text = myStringBuilder.ToString();
}
VB.NETCopy Code
Private Sub ArcGISDynamicMapServiceLayer_Initialized(sender As System.Object, e As System.EventArgs)
  
  ' Get the ArcGISDynamicMapServiceLayer from the Map Control. 
  Dim myArcGISDynamicMapServiceLayer As ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer
  myArcGISDynamicMapServiceLayer = CType(Map1.Layers("World_Topo_Map"), ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer)
  
  ' Get the ArcGISDynamicMapServiceLayer.Layers Property information (it will be an Array of LayerInfo objects).
  Dim myLayerInfo() As ESRI.ArcGIS.Client.LayerInfo = myArcGISDynamicMapServiceLayer.Layers
  
  ' Create a StringBuilder to display the ArcGISDynamicMapServiceLayer.Layers Property information in a TextBox.
  Dim myStringBuilder As New System.Text.StringBuilder
  
  ' Add the count of LayerInfo objects to the StringBuilder.
  myStringBuilder.Append("Number of sub-layers: " + myLayerInfo.Length.ToString + vbCrLf)
  myStringBuilder.Append("===================" + vbCrLf)
  
  ' Loop through each LayerInfo object.
  For Each oneLayerInfo As ESRI.ArcGIS.Client.LayerInfo In myLayerInfo
    
    ' Set each of the Properties in the LayerInfo object to corresponding variables. 
    Dim myDefaultVisibility As Boolean = oneLayerInfo.DefaultVisibility
    Dim myID As Integer = oneLayerInfo.ID
    Dim myMaxScale As Double = oneLayerInfo.MaxScale
    Dim myMinScale As Double = oneLayerInfo.MinScale
    Dim myName As String = oneLayerInfo.Name
    Dim mySubLayerIds() As Integer = oneLayerInfo.SubLayerIds
    
    ' Append the information in the LayerInfo variables to the StringBuilder.
    myStringBuilder.Append("Name: " + myName + vbCrLf)
    myStringBuilder.Append("ID: " + myID.ToString + vbCrLf)
    myStringBuilder.Append("DefaultVisibility: " + myDefaultVisibility.ToString + vbCrLf)
    myStringBuilder.Append("MaxScale: " + myMaxScale.ToString + vbCrLf)
    myStringBuilder.Append("MinScale: " + myMinScale.ToString + vbCrLf)
    
    ' The LayerInfo.SubLayerIds could return either Nothing/null or an Array of Integer values for 
    ' the sub-layer ID's. Add extra code logic to display the LayerInfo.SubLayerIds accordingly. 
    Dim mySubLayerIdsString As String = ""
    If mySubLayerIds IsNot Nothing Then
      For Each oneSubLayerId As Integer In mySubLayerIds
        mySubLayerIdsString = mySubLayerIdsString + oneSubLayerId.ToString + ", "
      Next
    Else
      mySubLayerIdsString = "[NONE]"
    End If
    myStringBuilder.Append("SubLayerIds: " + mySubLayerIdsString + vbCrLf + vbCrLf)
    
  Next
  
  ' Display all of the stuff in the StringBuilder in the TextBox.
  TextBox_Layers.Text = myStringBuilder.ToString
  
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.