List KML contents

View inWPFUWPFormsiOSAndroid
View on GitHub

List the contents of a KML file.

Image of list KML contents

Use case

KML files can contain a hierarchy of features, including network links to other KML content. A user may wish to traverse through the contents of KML nodes to know what data is contained within each node and, recursively, their children.

How to use the sample

The contents of the KML file are shown in a tree. Select a node to zoom to that node. Not all nodes can be zoomed to (e.g. screen overlays).

How it works

  1. Add the KML file to the scene as a layer.
  2. Explore the root nodes of the KmlDataset recursively explored to create a view model.
  3. Each node is enabled for display at this step. KML files may include nodes that are turned off by default.
  4. When a node is selected, use the node's Extent to determine a viewpoint and set the SceneView object's viewpoint do it.

Relevant API

  • KmlContainer
  • KmlDataset
  • KmlDocument
  • KmlFolder
  • KmlGroundOverlay
  • KmlLayer
  • KmlNetworkLink
  • KmlNode
  • KmlPlacemark
  • KmlScreenOverlay

About the data

This is an example KML file meant to demonstrate how Runtime supports several common features.

Tags

Keyhole, KML, KMZ, layers, OGC

Sample Code

ListKmlContents.xamlListKmlContents.xaml.cs
                      
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms"
             x:Class="ArcGISRuntimeXamarin.Samples.ListKmlContents.ListKmlContents">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="150" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Label Text="Tap to zoom to KML content." HorizontalTextAlignment="Center" Grid.Row="0" />
        <ListView x:Name="LayerTreeView" Grid.Row="1" ItemSelected="LayerTreeView_OnSelectionChanged">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <TextCell Text="{Binding Name}" />
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
        <esriUI:SceneView x:Name="MySceneView" Grid.Row="2" />
    </Grid>
</ContentPage>