ArcGIS API for WPF - Library Reference
Name Property
See Also  Example Send comments on this topic
ESRI.ArcGIS.Client.Toolkit.DataSources Namespace > KmlLayer Class : Name Property

Gets the name of the KML document.

Syntax

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

Property Value

The name.

Example

How to use:

When the application starts, click the Button to load a KmlLayer in the Map. Then click on any child KmlLayer.Name in the ListBox (Note: there could be more than one depending on the KmlLayer loaded by the Button). This will cause the Map to zoom to the general area of the child KmlLayer and display detailed information (e.g. geometry type, symbology, and any attribute information).

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.

Digging deep into the KmlLayer sub-layers to get detailed information like: geometry, symbology, and attributes.

XAMLCopy Code
<Grid x:Name="LayoutRoot">
  
  <!-- Add a Map Control. -->
  <esri:Map Background="White" HorizontalAlignment="Left" Margin="356,144,0,0" Name="Map1" VerticalAlignment="Top" 
            WrapAround="True" Height="204" Width="350" >
    <esri:Map.Layers>
      <esri:LayerCollection>
      
        <!-- Add a background ArcGISTiledMapServiceLayer for visual reference. -->
        <esri:ArcGISTiledMapServiceLayer 
          Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
          
      </esri:LayerCollection>
    </esri:Map.Layers>
  </esri:Map>
  
  <!-- Add a Button that has the Click event wired up. The button will add a KmlLayer via the code-behind. -->
  <Button Content="Step 1 - Add a KmlLayer to the Map." Height="23" HorizontalAlignment="Left" 
          Margin="0,144,0,0" Name="Button1" VerticalAlignment="Top" Width="350" Click="Button1_Click"/>
  
  <!-- Add a TextBlock to give the user instructions to click on the KmlLayer.Name to see detailed information. -->
  <TextBlock Height="67" HorizontalAlignment="Left" Margin="0,173,0,0" Name="TextBlock2" VerticalAlignment="Top" 
             Width="350" TextWrapping="Wrap"
             Text="Step 2 - Click on a sub KmlLayer.Name in the ListBox (below) to zoom to the extent of that sub KmlLayer and display it's detailed information like: geometry, symbology, and attributes." />
  
  <!-- Add a ListBox. -->
  <ListBox Height="102" HorizontalAlignment="Left" Margin="0,246,0,0" Name="ListBox1" 
           VerticalAlignment="Top" Width="350" SelectionChanged="ListBox1_SelectionChanged"/>
  
  <!-- Add a Textbox to display the KmlLayer sub-layers. -->
  <TextBox Height="246" HorizontalAlignment="Left" Margin="0,354,0,0" Name="TextBox1" VerticalAlignment="Top" 
           Width="706" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" />
  
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="138" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="706" 
     TextWrapping="Wrap" Text="When the application starts, click the Button to load a KmlLayer in the Map.
     Then click on any child KmlLayer.Name in the ListBox (Note: there could be more than one depending on the 
     KmlLayer loaded by the Button). This will cause the Map to zoom to the general area of the child KmlLayer
     and display detailed information (e.g. geometry type, symbology, and any attribute information)." />
</Grid>
C#Copy Code
private void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
{
  // This function loads a KmlLayer.
  
  // Create a new KmlLayer object.
  ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer theKmlLayer = new ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer();
  
  // Set an initial ID.
  theKmlLayer.ID = "KML Sample Data";
  
  // Provide a Url for the KML/KMZ files to test.
  theKmlLayer.Url = new Uri("http://kml-samples.googlecode.com/svn/trunk/kml/ExtendedData/lincoln-park-gc-style.kml");
  
  // A few other public KML/KMZ layers to try too!
  //theKmlLayer.Url = new Uri("http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-age_src.kmz");
  //theKmlLayer.Url = new Uri("http://earthquake.usgs.gov/regional/nca/bayarea/kml/quads.kmz");
  
  // Need to use a ProxyUrl to access the data since it is not in our local network.
  theKmlLayer.ProxyUrl = "http://serverapps.esri.com/SilverlightDemos/ProxyPage/proxy.ashx";
  
  // Wire up an InitializationFailed Event Handler to catch any problems.
  theKmlLayer.InitializationFailed += kmlLayer1_InitializationFailed;
  
  // Wire up the Initialized Event Handler that will list all of the visible sub-layers.
  theKmlLayer.Initialized += kmlLayer1_Initialized;
  
  // Add the KmlLayer to the Map Control.
  Map1.Layers.Add(theKmlLayer);
}
  
private void kmlLayer1_InitializationFailed(object sender, EventArgs e)
{
  // Display a MessageBox with Error information if there is a problem loading the KmlLayer. 
  ESRI.ArcGIS.Client.Layer theLayer = (ESRI.ArcGIS.Client.Layer)sender;
  MessageBox.Show("Error initializing layer: " + theLayer.InitializationFailure.Message);
}
  
private void kmlLayer1_Initialized(object sender, EventArgs e)
{
  // Get the KmlLayer.
  ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer theKmlLayer = (ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer)sender;
  
  // Obtain the ChildLayers (i.e. GroupLayer) from the KmlLayer.
  ESRI.ArcGIS.Client.LayerCollection theLayerCollection = theKmlLayer.ChildLayers;
  
  // Loop through the ChildLayers and display the Layer.ID in the ListBox.
  foreach (ESRI.ArcGIS.Client.Layer theLayer in theLayerCollection)
  {
    string theLayerID = theLayer.ID;
    ListBox1.Items.Add(theLayerID);
    
    // TODO: You could add more logic here to recursively turn on the Visibility of the sub-Layers
    // so that they could be interrogated as well. Sometimes KML/KMZ authors intentionally turn off
    // the Visibility but they could have goody information that can be explored.
  }
}
  
private void ListBox1_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
  // This function runs when the user clicks on the name of one of the visible sub-layers of the KmlLayer in the ListBox.
  
  // Clear out any previous information in the TextBox.
  TextBox1.Text = "";
  
  // Get the name of the KmlLayer sub-layer.
  string listbox_LayerName = ListBox1.SelectedItem.ToString();
  
  // Create a new StringBuilder to display information about the KmlLayer back to the user.
  Text.StringBuilder sb = new Text.StringBuilder();
  
  // Set an initial level in the KmlLayer sub-layer hierarchy.
  int level = 0;
  
  // Get the KmlLayer in the in the Map.
  ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer theKmlLayer = (ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer)(Map1.Layers(1));
  
  // Add the top  level (Parent) information about the KmlLayer to the StringBuilder. 
  sb.Append("KmlLayer Name (Parent - Level " + level.ToString() + "): " + theKmlLayer.Name + Environment.NewLine);
  sb.Append("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" + Environment.NewLine);
  sb.Append(Environment.NewLine);
  
  // Get the child sub-layers (i.e. GroupLayer) of the KmlLayer.
  ESRI.ArcGIS.Client.LayerCollection theLayerCollection = theKmlLayer.ChildLayers;
  
  // Loop through all of the child sub-layers.
  foreach (ESRI.ArcGIS.Client.Layer theLayer in theLayerCollection)
  {
    // Get the Layer.ID
    string theLayerID = theLayer.ID;
    
    // If we have a match with the what was chosen in the ListBox.
    if (theLayerID == listbox_LayerName)
    {
      // Zoom to the FullExtent (and then expanded by 50%) of the Layer chosen in the Listbox .
      // User TODO: Watch out for single point layers. Their extent will return an Envelope 
      // that is a Point and not an area! More coding on your own.
      Map1.Extent = theLayer.FullExtent.Expand(1.5);
      
      // Go into a recursive function that gets details about the sub-layer.
      sb.Append(GoDeep(theLayer, 1)); // 1 is the intial level
    }
  }
  
  // Put the StringBuilder information into the TextBox. 
  TextBox1.Text = sb.ToString();
}
  
// A helper object to track which sub-layer object we are working on.
public class SuperObject
{
  public object theObjects;
  public int theLevel;
}
  
public string GoDeep(object theObject, int theLevel)
{
  // This is a recursive function that gets details about a specific sub-layer.
  
  // If we go more than one time in this recursive function, the SuperObject helps
  // delinate which sub-layer we are operating on.
  if (theObject is SuperObject)
  {
    SuperObject theSuperObject = (SuperObject)theObject;
    theObject = theSuperObject.theObjects;
    theLevel = theSuperObject.theLevel;
  }
  
  // Create a new StringBuilder object to hold the detailed information about the sub-layer.
  Text.StringBuilder sb = new Text.StringBuilder();
  
  // The sub-layer that is passed into this recursive function could be any number of
  // Layer types. Branch into the correct If statement depending on what type of
  // object we are dealing with.
  
  if (theObject is ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer)
  {
    // We have a KmlLayer type of object. Will need to recursively dig into more sub-layers 
    // in order to display details that we are interested in.
    
    // Get the KmlLayer.
    ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer theKmlLayer = (ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer)theObject;
    
    // Get the KmlLayer's child sub-layers.
    ESRI.ArcGIS.Client.LayerCollection theLayerCollection = theKmlLayer.ChildLayers;
    
    // Add some KmlLayer information into the StringBuilder.
    sb.Append("KmlLayer Name (Level " + theLevel.ToString() + "): " + theKmlLayer.ID + Environment.NewLine);
    sb.Append("##############################################" + Environment.NewLine);
    sb.Append(Environment.NewLine);
    
    // Loop through all of the sub-layers in the KmlLayer.
    foreach (object theObject2 in theLayerCollection)
    {
      // Create a SuperObject to perform the recursive analysis.
      SuperObject theRecursive_SuperObject = new SuperObject();
      theRecursive_SuperObject.theObjects = theObject2;
      theRecursive_SuperObject.theLevel = theLevel + 1;
      
      // Add detailed sub-layer information to the StringBuilder as a result of a recursive operation.
      sb.Append(GoDeep(theRecursive_SuperObject, theLevel));
    }
  }
  else if (theObject is ESRI.ArcGIS.Client.GraphicsLayer)
  {
    // We have a GraphicsLayer type of object. 
    
    // Display detailed information about each Graphic in the GraphicsLayer
    ESRI.ArcGIS.Client.GraphicsLayer theGraphicsLayer = (ESRI.ArcGIS.Client.GraphicsLayer)theObject;
    string theGraphicsLayerID = theGraphicsLayer.ID;
    
    // Display overall information on the number of Graphics in the GraphicsLayer.
    sb.Append("GraphicsLayer (Level " + theLevel.ToString() + "): " + theGraphicsLayerID + Environment.NewLine);
    sb.Append("================================================" + Environment.NewLine);
    sb.Append("Number of Graphics: " + theGraphicsLayer.Graphics.Count.ToString() + Environment.NewLine);
    sb.Append(Environment.NewLine);
    
    // A counter for the number of Graphics in the GraphicsLayer.
    int graphicsCount = 0;
    
    // Loop through each Graphic in the GraphicsLayer.
    foreach (ESRI.ArcGIS.Client.Graphic theGraphic in theGraphicsLayer)
    {
      // Append which Graphic we are operating on in the StringBuilder.
      sb.Append("Graphic #" + graphicsCount.ToString() + Environment.NewLine);
      
      // Incriment the Graphics counter.
      graphicsCount = graphicsCount + 1;
      
      // ---------------------------------------------------------------------------------------
      
      // Append the Geometry Type of the Graphic to the StringBuilder.
      sb.Append("Geometry Type: " + theGraphic.Geometry.GetType().ToString() + Environment.NewLine);
      
      // Interrogate the specific Geometry Type of the Graphic to display it's coordinate information.
      if (theGraphic.Geometry is ESRI.ArcGIS.Client.Geometry.MapPoint)
      {
        // We have a MapPoint. Display its coordinate information in the StringBuilder.
        ESRI.ArcGIS.Client.Geometry.MapPoint theMapPoint = (ESRI.ArcGIS.Client.Geometry.MapPoint)theGraphic.Geometry;
        sb.Append("Coordinates: " + theMapPoint.ToString() + Environment.NewLine);
      }
      else if (theGraphic.Geometry is ESRI.ArcGIS.Client.Geometry.Polyline)
      {
        // We have a Polyline. Display its coordinate information in the StringBuilder.
        ESRI.ArcGIS.Client.Geometry.Polyline thePolyline = (ESRI.ArcGIS.Client.Geometry.Polyline)theGraphic.Geometry;
        string polylineString = "";
        System.Collections.ObjectModel.ObservableCollection<ESRI.ArcGIS.Client.Geometry.PointCollection> theObservableCollection_PointCollection = thePolyline.Paths;
        foreach (ESRI.ArcGIS.Client.Geometry.PointCollection thePointCollection in theObservableCollection_PointCollection)
        {
          foreach (ESRI.ArcGIS.Client.Geometry.MapPoint theMapPoint in thePointCollection)
          {
            polylineString = polylineString + theMapPoint.ToString() + ", ";
          }
        }
        sb.Append("Coordinates: " + polylineString + Environment.NewLine);
      }
      else if (theGraphic.Geometry is ESRI.ArcGIS.Client.Geometry.Polygon)
      {
        // We have a Polygon. Display its coordinate information in the StringBuilder.
        ESRI.ArcGIS.Client.Geometry.Polygon thePolygon = (ESRI.ArcGIS.Client.Geometry.Polygon)theGraphic.Geometry;
        string polygonString = "";
        System.Collections.ObjectModel.ObservableCollection<ESRI.ArcGIS.Client.Geometry.PointCollection> theObservableCollection_PointCollection = thePolygon.Rings;
        foreach (ESRI.ArcGIS.Client.Geometry.PointCollection thePointCollection in theObservableCollection_PointCollection)
        {
          foreach (ESRI.ArcGIS.Client.Geometry.MapPoint theMapPoint in thePointCollection)
          {
            polygonString = polygonString + theMapPoint.ToString() + ", ";
          }
        }
        sb.Append("Coordinates: " + polygonString + Environment.NewLine);
      }
      
      // -------------------------------------------------------------------------------------
      
      // Append the symbology of the Graphic into the StringBuilder.
      ESRI.ArcGIS.Client.Symbols.Symbol theSymbol = theGraphic.Symbol;
      sb.Append("Symbol Type: " + theSymbol.GetType().ToString() + Environment.NewLine);
      
      // -------------------------------------------------------------------------------------
      
      // Interrogate the Attributes of the Graphic.
      
      // Get the Dictionary of Attributes.
      System.Collections.Generic.IDictionary<string, object> theAttributeDictionary = theGraphic.Attributes;
      
      // Get the Keys for the Dictionary.
      System.Collections.Generic.ICollection<string> theAttributeKeys = theAttributeDictionary.Keys;
      
      // Loop through each Key in the Dictionary of Attributes. 
      foreach (string theKey in theAttributeKeys)
      {
        // Get the Value of one Attribute. It could be any number of Types! 
        object theValue = theAttributeDictionary[theKey];
        
        // Get the Type of the Value of the Attribute (we could have a more complex object than a String).
        System.Type theType = theValue.GetType();
        
        // Interrogate the Value Type.
        if (theValue is System.Collections.Generic.List<ESRI.ArcGIS.Client.Toolkit.DataSources.Kml.KmlExtendedData>)
        {
          // We have a List<KmlExtendedData> objects (most likely a result of the <ExtendedData> tag in KML).
          
          // Get the List<KmlExtendedData> object.
          System.Collections.Generic.List<ESRI.ArcGIS.Client.Toolkit.DataSources.Kml.KmlExtendedData> theList = null;
          theList = (System.Collections.Generic.List<ESRI.ArcGIS.Client.Toolkit.DataSources.Kml.KmlExtendedData>)theValue;
          
          // Loop through each KmlExtendedData object in the List<KmlExtendedData>.
          foreach (ESRI.ArcGIS.Client.Toolkit.DataSources.Kml.KmlExtendedData oneKmlExtendedData in theList)
          {
            // Append the Attribute information of the KmlExtendedData into the StringBuilder.
            sb.Append("AttributeKey: " + "KmlExtendedData.DisplayName" + ", AttributeValue: " + oneKmlExtendedData.DisplayName + Environment.NewLine);
            sb.Append("AttributeKey: " + "KmlExtendedData.Name" + ", AttributeValue: " + oneKmlExtendedData.Name + Environment.NewLine);
            sb.Append("AttributeKey: " + "KmlExtendedData.Value" + ", AttributeValue: " + oneKmlExtendedData.Value + Environment.NewLine);
            sb.Append("----------------------------------------------------" + Environment.NewLine);
          }
        }
        else if (theValue is string)
        {
          // We have a String object.
          
          // This could come from a number of KML tags (ex: <atom:author> 'name' attribute; <atom:link> 'href' attribute;
          // <atom:name> 'href' attribute, <BalloonStyle><text> information, <description> information; and <name> information).
          sb.Append("AttributeKey: " + theKey + ", AttributeValue: " + theValue.ToString() + Environment.NewLine);
          sb.Append("----------------------------------------------------" + Environment.NewLine);
         }
         else
         {
          // We have some other Type of object. TODO: User to interrogate further!
         }
      }  
      sb.Append(Environment.NewLine);
    }
  }
  else if (theObject is ESRI.ArcGIS.Client.ElementLayer)
  {
    // We have an ElementLayer type of object. 
    
    // Display detailed information about each ElementLayer
    ESRI.ArcGIS.Client.ElementLayer theElementLayer = (ESRI.ArcGIS.Client.ElementLayer)theObject;
    
    // Append the overall information about the ElementLayer in the StringBuilder.
    string theElementLayerID = theElementLayer.ID;
    sb.Append("ElementLayer (Level " + theLevel.ToString() + "): " + theElementLayerID + Environment.NewLine);
    sb.Append("=============================================" + Environment.NewLine);
    sb.Append("Number of Elements: " + theElementLayer.Children.Count.ToString() + Environment.NewLine);
    
    // Append the Extent information about the ElementLayer int the Stirng Builder.
    ESRI.ArcGIS.Client.Geometry.Envelope elementLayerFullExtent = theElementLayer.FullExtent;
    sb.Append("FullExtent: " + elementLayerFullExtent.ToString() + Environment.NewLine);
    sb.Append(Environment.NewLine);
    
    // Loop through each UIElement in the ElementLayer.
    foreach (System.Windows.UIElement oneElement in theElementLayer.Children)
    {
      // Append information about each UIElement in the StringBulder.
      sb.Append("ElementType: " + oneElement.GetType().ToString() + Environment.NewLine);
      sb.Append("Opacity: " + oneElement.Opacity.ToString() + Environment.NewLine);
      sb.Append("Visibility: " + oneElement.Visibility.ToString() + Environment.NewLine);
      sb.Append("Envelope: " + ESRI.ArcGIS.Client.ElementLayer.GetEnvelope(oneElement).ToString() + Environment.NewLine);
      sb.Append(Environment.NewLine);
    }
  }
  // Return the StringBuilder information back to the caller.
  return sb.ToString();
}
VB.NETCopy Code
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
  
  ' This function loads a KmlLayer.
  
  ' Create a new KmlLayer object.
  Dim theKmlLayer As New ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer
  
  ' Set an initial ID.
  theKmlLayer.ID = "KML Sample Data"
  
  ' Provide a Url for the KML/KMZ files to test.
  theKmlLayer.Url = New Uri("http://kml-samples.googlecode.com/svn/trunk/kml/ExtendedData/lincoln-park-gc-style.kml")
  
  ' A few other public KML/KMZ layers to try too!
  'theKmlLayer.Url = New Uri("http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-age_src.kmz")
  'theKmlLayer.Url = New Uri("http://earthquake.usgs.gov/regional/nca/bayarea/kml/quads.kmz")
  
  ' Need to use a ProxyUrl to access the data since it is not in our local network.
  theKmlLayer.ProxyUrl = "http://serverapps.esri.com/SilverlightDemos/ProxyPage/proxy.ashx"
  
  ' Wire up an InitializationFailed Event Handler to catch any problems.
  AddHandler theKmlLayer.InitializationFailed, AddressOf kmlLayer1_InitializationFailed
  
  ' Wire up the Initialized Event Handler that will list all of the visible sub-layers.
  AddHandler theKmlLayer.Initialized, AddressOf kmlLayer1_Initialized
  
  ' Add the KmlLayer to the Map Control.
  Map1.Layers.Add(theKmlLayer)
  
End Sub
            
Private Sub kmlLayer1_InitializationFailed(sender As Object, e As EventArgs)
  
  ' Display a MessageBox with Error information if there is a problem loading the KmlLayer. 
  Dim theLayer As ESRI.ArcGIS.Client.Layer = CType(sender, ESRI.ArcGIS.Client.Layer)
  MessageBox.Show("Error initializing layer: " + theLayer.InitializationFailure.Message)
  
End Sub
  
Private Sub kmlLayer1_Initialized(sender As Object, e As EventArgs)
  
  ' Get the KmlLayer.
  Dim theKmlLayer As ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer = CType(sender, ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer)
  
  ' Obtain the ChildLayers (i.e. GroupLayer) from the KmlLayer.
  Dim theLayerCollection As ESRI.ArcGIS.Client.LayerCollection = theKmlLayer.ChildLayers
  
  ' Loop through the ChildLayers and display the Layer.ID in the ListBox.
  For Each theLayer As ESRI.ArcGIS.Client.Layer In theLayerCollection
    Dim theLayerID As String = theLayer.ID
    ListBox1.Items.Add(theLayerID)
    
    ' TODO: You could add more logic here to recursively turn on the Visibility of the sub-Layers
    ' so that they could be interrogated as well. Sometimes KML/KMZ authors intentionally turn off
    ' the Visibility but they could have goody information that can be explored.
  Next
  
End Sub
            
Private Sub ListBox1_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs)
  
  ' This function runs when the user clicks on the name of one of the visible sub-layers of the KmlLayer in the ListBox.
  
  ' Clear out any previous information in the TextBox.
  TextBox1.Text = ""
  
  ' Get the name of the KmlLayer sub-layer.
  Dim listbox_LayerName As String = ListBox1.SelectedItem.ToString
  
  ' Create a new StringBuilder to display information about the KmlLayer back to the user.
  Dim sb As New Text.StringBuilder
  
  ' Set an initial level in the KmlLayer sub-layer hierarchy.
  Dim level As Integer = 0
  
  ' Get the KmlLayer in the in the Map.
  Dim theKmlLayer As ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer = CType(Map1.Layers(1), ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer)
  
  ' Add the top  level (Parent) information about the KmlLayer to the StringBuilder. 
  sb.Append("KmlLayer Name (Parent - Level " + level.ToString + "): " + theKmlLayer.Name + vbCrLf)
  sb.Append("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" + vbCrLf)
  sb.Append(vbCrLf)
  
  ' Get the child sub-layers (i.e. GroupLayer) of the KmlLayer.
  Dim theLayerCollection As ESRI.ArcGIS.Client.LayerCollection = theKmlLayer.ChildLayers
  
  ' Loop through all of the child sub-layers.
  For Each theLayer As ESRI.ArcGIS.Client.Layer In theLayerCollection
    
    ' Get the Layer.ID
    Dim theLayerID As String = theLayer.ID
    
    ' If we have a match with the what was chosen in the ListBox.
    If theLayerID = listbox_LayerName Then
      
      ' Zoom to the FullExtent (and then expanded by 50%) of the Layer chosen in the Listbox .
      ' User TODO: Watch out for single point layers. Their extent will return an Envelope 
      ' that is a Point and not an area! More coding on your own.
      Map1.Extent = theLayer.FullExtent.Expand(1.5)
      
      ' Go into a recursive function that gets details about the sub-layer.
      sb.Append(GoDeep(theLayer, 1)) ' 1 is the intial level
      
    End If
  Next
  
  ' Put the StringBuilder information into the TextBox. 
  TextBox1.Text = sb.ToString
  
End Sub
  
' A helper object to track which sub-layer object we are working on.
Public Class SuperObject
  Public theObjects As Object
  Public theLevel As Integer
End Class
  
Public Function GoDeep(ByVal theObject As Object, ByVal theLevel As Integer) As String
  
  ' This is a recursive function that gets details about a specific sub-layer.
  
  ' If we go more than one time in this recursive function, the SuperObject helps
  ' delinate which sub-layer we are operating on.
  If TypeOf theObject Is SuperObject Then
    Dim theSuperObject As SuperObject = CType(theObject, SuperObject)
    theObject = theSuperObject.theObjects
    theLevel = theSuperObject.theLevel
  End If
  
  ' Create a new StringBuilder object to hold the detailed information about the sub-layer.
  Dim sb As New Text.StringBuilder
  
  ' The sub-layer that is passed into this recursive function could be any number of
  ' Layer types. Branch into the correct If statement depending on what type of
  ' object we are dealing with.
  
  If TypeOf theObject Is ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer Then
    
    ' We have a KmlLayer type of object. Will need to recursively dig into more sub-layers 
    ' in order to display details that we are interested in.
    
    ' Get the KmlLayer.
    Dim theKmlLayer As ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer = CType(theObject, ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer)
    
    ' Get the KmlLayer's child sub-layers.
    Dim theLayerCollection As ESRI.ArcGIS.Client.LayerCollection = theKmlLayer.ChildLayers
    
    ' Add some KmlLayer information into the StringBuilder.
    sb.Append("KmlLayer Name (Level " + theLevel.ToString + "): " + theKmlLayer.ID + vbCrLf)
    sb.Append("##############################################" + vbCrLf)
    sb.Append(vbCrLf)
    
    ' Loop through all of the sub-layers in the KmlLayer.
    For Each theObject2 As Object In theLayerCollection
      
      ' Create a SuperObject to perform the recursive analysis.
      Dim theRecursive_SuperObject As New SuperObject
      theRecursive_SuperObject.theObjects = theObject2
      theRecursive_SuperObject.theLevel = theLevel + 1
      
      ' Add detailed sub-layer information to the StringBuilder as a result of a recursive operation.
      sb.Append(GoDeep(theRecursive_SuperObject, theLevel))
      
    Next
    
  ElseIf TypeOf theObject Is ESRI.ArcGIS.Client.GraphicsLayer Then
    
    ' We have a GraphicsLayer type of object. 
      
    ' Display detailed information about each Graphic in the GraphicsLayer
    Dim theGraphicsLayer As ESRI.ArcGIS.Client.GraphicsLayer = CType(theObject, ESRI.ArcGIS.Client.GraphicsLayer)
    Dim theGraphicsLayerID As String = theGraphicsLayer.ID
    
    ' Display overall information on the number of Graphics in the GraphicsLayer.
    sb.Append("GraphicsLayer (Level " + theLevel.ToString + "): " + theGraphicsLayerID + vbCrLf)
    sb.Append("================================================" + vbCrLf)
    sb.Append("Number of Graphics: " + theGraphicsLayer.Graphics.Count.ToString + vbCrLf)
    sb.Append(vbCrLf)
    
    ' A counter for the number of Graphics in the GraphicsLayer.
    Dim graphicsCount As Integer = 0
    
    ' Loop through each Graphic in the GraphicsLayer.
    For Each theGraphic As ESRI.ArcGIS.Client.Graphic In theGraphicsLayer
      
      ' Append which Graphic we are operating on in the StringBuilder.
      sb.Append("Graphic #" + graphicsCount.ToString + vbCrLf)
      
      ' Incriment the Graphics counter.
      graphicsCount = graphicsCount + 1
      
      ' ---------------------------------------------------------------------------------------
      
      ' Append the Geometry Type of the Graphic to the StringBuilder.
      sb.Append("Geometry Type: " + theGraphic.Geometry.GetType.ToString + vbCrLf)
      
      ' Interrogate the specific Geometry Type of the Graphic to display it's coordinate information.
      If TypeOf theGraphic.Geometry Is ESRI.ArcGIS.Client.Geometry.MapPoint Then
        
        ' We have a MapPoint. Display its coordinate information in the StringBuilder.
        Dim theMapPoint As ESRI.ArcGIS.Client.Geometry.MapPoint = CType(theGraphic.Geometry, ESRI.ArcGIS.Client.Geometry.MapPoint)
        sb.Append("Coordinates: " + theMapPoint.ToString + vbCrLf)
        
      ElseIf TypeOf theGraphic.Geometry Is ESRI.ArcGIS.Client.Geometry.Polyline Then
        
        ' We have a Polyline. Display its coordinate information in the StringBuilder.
        Dim thePolyline As ESRI.ArcGIS.Client.Geometry.Polyline = CType(theGraphic.Geometry, ESRI.ArcGIS.Client.Geometry.Polyline)
        Dim polylineString As String = ""
        Dim theObservableCollection_PointCollection As System.Collections.ObjectModel.ObservableCollection(Of ESRI.ArcGIS.Client.Geometry.PointCollection) = thePolyline.Paths
        For Each thePointCollection As ESRI.ArcGIS.Client.Geometry.PointCollection In theObservableCollection_PointCollection
          For Each theMapPoint As ESRI.ArcGIS.Client.Geometry.MapPoint In thePointCollection
            polylineString = polylineString + theMapPoint.ToString + ", "
          Next
        Next
        sb.Append("Coordinates: " + polylineString + vbCrLf)
        
      ElseIf TypeOf theGraphic.Geometry Is ESRI.ArcGIS.Client.Geometry.Polygon Then
        
        ' We have a Polygon. Display its coordinate information in the StringBuilder.
        Dim thePolygon As ESRI.ArcGIS.Client.Geometry.Polygon = CType(theGraphic.Geometry, ESRI.ArcGIS.Client.Geometry.Polygon)
        Dim polygonString As String = ""
        Dim theObservableCollection_PointCollection As System.Collections.ObjectModel.ObservableCollection(Of ESRI.ArcGIS.Client.Geometry.PointCollection) = thePolygon.Rings
        For Each thePointCollection As ESRI.ArcGIS.Client.Geometry.PointCollection In theObservableCollection_PointCollection
          For Each theMapPoint As ESRI.ArcGIS.Client.Geometry.MapPoint In thePointCollection
            polygonString = polygonString + theMapPoint.ToString + ", "
          Next
        Next
        sb.Append("Coordinates: " + polygonString + vbCrLf)
        
      End If
      
      ' -------------------------------------------------------------------------------------
      
      ' Append the symbology of the Graphic into the StringBuilder.
      Dim theSymbol As ESRI.ArcGIS.Client.Symbols.Symbol = theGraphic.Symbol
      sb.Append("Symbol Type: " + theSymbol.GetType.ToString + vbCrLf)
      
      ' -------------------------------------------------------------------------------------
      
      ' Interrogate the Attributes of the Graphic.
      
      ' Get the Dictionary of Attributes.
      Dim theAttributeDictionary As System.Collections.Generic.IDictionary(Of String, Object) = theGraphic.Attributes
      
      ' Get the Keys for the Dictionary.
      Dim theAttributeKeys As System.Collections.Generic.ICollection(Of String) = theAttributeDictionary.Keys
      
      ' Loop through each Key in the Dictionary of Attributes. 
      For Each theKey As String In theAttributeKeys
        
        ' Get the Value of one Attribute. It could be any number of Types! 
        Dim theValue As Object = theAttributeDictionary.Item(theKey)
         ' Get the Type of the Value of the Attribute (we could have a more complex object than a String).
        Dim theType As System.Type = theValue.GetType
          
        ' Interrogate the Value Type.
        If TypeOf theValue Is System.Collections.Generic.List(Of ESRI.ArcGIS.Client.Toolkit.DataSources.Kml.KmlExtendedData) Then
          
          ' We have a List(Of KmlExtendedData) objects (most likely a result of the <ExtendedData> tag in KML).
          
          ' Get the List(Of KmlExtendedData) object.
          Dim theList As System.Collections.Generic.List(Of ESRI.ArcGIS.Client.Toolkit.DataSources.Kml.KmlExtendedData)
          theList = CType(theValue, System.Collections.Generic.List(Of ESRI.ArcGIS.Client.Toolkit.DataSources.Kml.KmlExtendedData))
          
          ' Loop through each KmlExtendedData object in the List(Of KmlExtendedData).
          For Each oneKmlExtendedData As ESRI.ArcGIS.Client.Toolkit.DataSources.Kml.KmlExtendedData In theList
          
            ' Append the Attribute information of the KmlExtendedData into the StringBuilder.
            sb.Append("AttributeKey: " + "KmlExtendedData.DisplayName" + ", AttributeValue: " + oneKmlExtendedData.DisplayName + vbCrLf)
            sb.Append("AttributeKey: " + "KmlExtendedData.Name" + ", AttributeValue: " + oneKmlExtendedData.Name + vbCrLf)
            sb.Append("AttributeKey: " + "KmlExtendedData.Value" + ", AttributeValue: " + oneKmlExtendedData.Value + vbCrLf)
            sb.Append("----------------------------------------------------" + vbCrLf)
            
          Next
          
        ElseIf TypeOf theValue Is String Then
          
          ' We have a String object.
          
          ' This could come from a number of KML tags (ex: <atom:author> 'name' attribute; <atom:link> 'href' attribute;
          ' <atom:name> 'href' attribute, <BalloonStyle><text> information, <description> information; and <name> information).
          sb.Append("AttributeKey: " + theKey + ", AttributeValue: " + theValue.ToString + vbCrLf)
          sb.Append("----------------------------------------------------" + vbCrLf)
          
        Else
          
          ' We have some other Type of object. TODO: User to interrogate further!
          
        End If
      Next
        
      sb.Append(vbCrLf)
      
    Next
    
  ElseIf TypeOf theObject Is ESRI.ArcGIS.Client.ElementLayer Then
    
    ' We have an ElementLayer type of object. 
    
    ' Display detailed information about each ElementLayer
    Dim theElementLayer As ESRI.ArcGIS.Client.ElementLayer = CType(theObject, ESRI.ArcGIS.Client.ElementLayer)
    
    ' Append the overall information about the ElementLayer in the StringBuilder.
    Dim theElementLayerID As String = theElementLayer.ID
    sb.Append("ElementLayer (Level " + theLevel.ToString + "): " + theElementLayerID + vbCrLf)
    sb.Append("=============================================" + vbCrLf)
    sb.Append("Number of Elements: " + theElementLayer.Children.Count.ToString + vbCrLf)
    
    ' Append the Extent information about the ElementLayer int the Stirng Builder.
    Dim elementLayerFullExtent As ESRI.ArcGIS.Client.Geometry.Envelope = theElementLayer.FullExtent
    sb.Append("FullExtent: " + elementLayerFullExtent.ToString + vbCrLf)
    sb.Append(vbCrLf)
    
    ' Loop through each UIElement in the ElementLayer.
    For Each oneElement As System.Windows.UIElement In theElementLayer.Children
      
      ' Append information about each UIElement in the StringBulder.
      sb.Append("ElementType: " + oneElement.GetType.ToString + vbCrLf)
      sb.Append("Opacity: " + oneElement.Opacity.ToString + vbCrLf)
      sb.Append("Visibility: " + oneElement.Visibility.ToString + vbCrLf)
      sb.Append("Envelope: " + ESRI.ArcGIS.Client.ElementLayer.GetEnvelope(oneElement).ToString + vbCrLf)
      sb.Append(vbCrLf)
      
    Next
            
  End If
            
  ' Return the StringBuilder information back to the caller.
  Return sb.ToString
            
End Function

Requirements

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

See Also

© ESRI, Inc. All Rights Reserved.