Click or drag to resize

KmlDataset Class

Points to KML/KMZ content, either from a local file or the network. This object provides an entry point for traversing the tree of KmlNodes that make up the file.
Inheritance Hierarchy
SystemObject
  Esri.ArcGISRuntime.OgcKmlDataset

Namespace:  Esri.ArcGISRuntime.Ogc
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.7.0.0
Syntax
C#
public sealed class KmlDataset : ILoadable

The KmlDataset type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleKmlDataset(Uri)
Initializes a new instance of the KmlDataset class.
Public methodCode exampleKmlDataset(KmlNode)
Initializes a new instance of the KmlDataset class, with the given KmlNode as its root node.
Top
Properties
  NameDescription
Public propertyCredential
Gets or sets the security credential used to access remote files.
Public propertyLoadError
Gets the Exception associated with the last load error.
Public propertyLoadStatus
Gets the load status.
Public propertyCode exampleRootNodes
Gets this dataset's root KML nodes as a KmlNodeCollection.
Public propertySource
Gets the location of the KML data from which this dataset was created.
Top
Methods
  NameDescription
Public methodCancelLoad
Cancel loading metadata for the object.
Public methodCode exampleLoadAsync
Load the metadata for the object asynchronously.
Public methodRetryLoadAsync
Load or retry loading metadata for the object asynchronously.
Top
Events
  NameDescription
Public eventBalloonPopupEvent
Event that is raised when a KmlTour requests that a balloon popup should be shown or hidden for a particular KmlNode.
Public eventLoaded
Event that is raised when the object is done loading.
Public eventLoadStatusChanged
Event that is raised when the LoadStatus property changes.
Public eventCode exampleNetworkLinkControlMessage
Event that is raised when a network link control message is available for this dataset.
Top
Remarks

Use the RootNodes property to obtain a KmlNodeCollection to traverse the KmlNode objects for examining/using individual KML features. The RootNodes is populated after a KML dataset has finished loading successfully.

A typical KML document will have multiple levels of nodes. Consider using recursion to discover the full collection of nodes in a KML file. See the guide doc and samples for details.

If a KML file has KmlNetworkLinks, the content can change after loading due to automatic refresh. You can use the PropertyChanged event to detect changes and update your app's UI.

Examples

Android

Example Name: DisplayKmlNetworkLinks

Display a file with a KML network link.

Code example screen shot.

C#
// Copyright 2018 Esri.
// 
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an 
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific 
// language governing permissions and limitations under the License.

using Android.App;
using Android.OS;
using Android.Widget;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Ogc;
using Esri.ArcGISRuntime.UI.Controls;
using System;

namespace ArcGISRuntimeXamarin.Samples.DisplayKmlNetworkLinks
{
    [Activity (ConfigurationChanges=Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Display KML network links",
        "Layers",
        "Display a KML file that loads content from a network resource.",
        "")]
    public class DisplayKmlNetworkLinks : Activity
    {
        // Hold a reference to the scene view.
        private SceneView _mySceneView;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Title = "Display KML network links";

            CreateLayout();
            Initialize();
        }

        private void Initialize()
        {
            // Set up the basemap.
            _mySceneView.Scene = new Scene(Basemap.CreateImageryWithLabels());

            // Create the dataset.
            KmlDataset dataset = new KmlDataset(new Uri("https://www.arcgis.com/sharing/rest/content/items/600748d4464442288f6db8a4ba27dc95/data"));

            // Listen for network link control messages.
            // These should be shown to the user.
            dataset.NetworkLinkControlMessage += Dataset_NetworkLinkControlMessage;

            // Create the layer from the dataset.
            KmlLayer fileLayer = new KmlLayer(dataset);

            // Add the layer to the map.
            _mySceneView.Scene.OperationalLayers.Add(fileLayer);

            // Zoom in to center the map on Germany.
            _mySceneView.SetViewpoint(new Viewpoint(new MapPoint(8.150526, 50.472421, SpatialReferences.Wgs84), 20000000));
        }

        private void Dataset_NetworkLinkControlMessage(object sender, KmlNetworkLinkControlMessageEventArgs e)
        {
            // Due to the nature of the threading implementation,
            //     the dispatcher needs to be used to interact with the UI.
            // The dispatcher takes an Action, provided here as a lambda function.
            RunOnUiThread(() =>
            {
                // Display the message to the user.
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.SetMessage(e.Message).SetTitle("KML layer message").Show();
            });
        }

        private void CreateLayout()
        {
            // Create a new vertical layout for the app.
            var layout = new LinearLayout(this) {Orientation = Orientation.Vertical};

            // Add the scene view to the layout.
            _mySceneView = new SceneView(this);
            layout.AddView(_mySceneView);

            // Show the layout in the app.
            SetContentView(layout);
        }
    }
}
Examples

Xamarin Forms Android

Example Name: DisplayKmlNetworkLinks

Display a file with a KML network link.

Code example screen shot.

C#
// Copyright 2018 Esri.
// 
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an 
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific 
// language governing permissions and limitations under the License.

using System;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Ogc;
using Xamarin.Forms;

namespace ArcGISRuntimeXamarin.Samples.DisplayKmlNetworkLinks
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Display KML network links",
        "Layers",
        "Display a KML file that loads content from a network resource.",
        "")]
    public partial class DisplayKmlNetworkLinks : ContentPage
    {
        public DisplayKmlNetworkLinks()
        {
            InitializeComponent();
            Initialize();
        }

        private void Initialize()
        {
            // Set up the basemap.
            MySceneView.Scene = new Scene(Basemap.CreateImageryWithLabels());

            // Create the dataset.
            KmlDataset dataset = new KmlDataset(new Uri("https://www.arcgis.com/sharing/rest/content/items/600748d4464442288f6db8a4ba27dc95/data"));

            // Listen for network link control messages.
            // These should be shown to the user.
            dataset.NetworkLinkControlMessage += Dataset_NetworkLinkControlMessage;

            // Create the layer from the dataset.
            KmlLayer fileLayer = new KmlLayer(dataset);

            // Add the layer to the map.
            MySceneView.Scene.OperationalLayers.Add(fileLayer);

            // Zoom in to center the map on Germany.
            MySceneView.SetViewpoint(new Viewpoint(new MapPoint(8.150526, 50.472421, SpatialReferences.Wgs84), 20000000));
        }

        private void Dataset_NetworkLinkControlMessage(object sender, KmlNetworkLinkControlMessageEventArgs e)
        {
            // Due to the nature of the threading implementation,
            //     the dispatcher needs to be used to interact with the UI.
            // The dispatcher takes an Action, provided here as a lambda function.
            Device.BeginInvokeOnMainThread(async () =>
            {
                await Application.Current.MainPage.DisplayAlert("KML layer message", e.Message, "OK");
            });
        }
    }
}
XAML
<?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.DisplayKmlNetworkLinks.DisplayKmlNetworkLinks">
    <Grid>
        <esriUI:SceneView x:Name="MySceneView" />
    </Grid>
</ContentPage>
See Also
Additional Examples
Hyperlink to ExampleDescription
CreateAndSaveKmlFileConstruct a KML document and save it as a KMZ file.
DisplayKmlNetworkLinks Display a file with a KML network link.
EditKmlGroundOverlayEdit the values of a KML ground overlay.
IdentifyKmlFeaturesThis sample demonstrates how to identify features in a KML layer. Identified feature attributes are displayed in a callout to simulate a popup.
ListKmlContentsList the contents of a KML file. KML files can contain a hierarchy of features, including network links to other KML content.
PlayKmlToursPlay tours in KML files.