Click or drag to resize

KmlNode Class

A single node within a KML document.
Inheritance Hierarchy
SystemObject
  Esri.ArcGISRuntime.OgcKmlNode
    More...

Namespace:  Esri.ArcGISRuntime.Ogc
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.9.0.0
Syntax
C#
public abstract class KmlNode

The KmlNode type exposes the following members.

Properties
  NameDescription
Public propertyAddress
Gets or sets an address associated with this node.
Public propertyBalloonBackgroundColor
Gets the color that should be used for the background of the node's popup balloon.
Public propertyCode exampleBalloonContent
Gets the balloon popup content for this KML node as a string containing HTML.
Public propertyDescription
Gets or sets the description of this KML node.
Public propertyCode exampleExtent
Gets the bounding extent of this KML node.
Public propertyHighlightStyle
Gets or sets the style used to render this KML node when IsHighlighted is true.
Public propertyId
Gets or sets the ID of the KML node.
Public propertyIsHighlighted
Gets or sets a value indicating whether this KML node is highlighted. This controls whether the default Style or an alternate HighlightStyle (if present) is used for rendering the node.
Public propertyCode exampleIsVisible
Gets or sets a value indicating whether this KML node is visible.
Public propertyCode exampleName
Gets or sets the name of this KML node.
Public propertyParent
Gets the parent of this node.
Public propertyRefreshError
Gets the reason for refresh failure if the RefreshStatus is Failed.
Public propertyRefreshStatus
Gets the KML node's refresh status.
Public propertySnippet
Gets or sets the optional snippet for this KML node.
Public propertySnippetMaxLines
Gets or sets the maximum number of lines of snippet to be shown in the UI.
Public propertyCode exampleStyle
Gets or sets the style used to render this KML node.
Public propertyUxIcon
Gets the icon associated with this KML node for use in the user interface.
Public propertyUxIconColor
Gets the color used to tint the UX icon.
Public propertyUxIconId
Gets the UX icon id.
Public propertyCode exampleViewpoint
Gets the KmlViewpoint associated with this KML node or null if no Camera or LookAt is specified for the node.
Top
Methods
  NameDescription
Protected methodOnPropertyChanged
Called when a property changes.
Public methodSaveAsAsync
Saves this node and any referenced local files as a KMZ archive.
Public methodCode exampleWriteToAsync
Saves this node and any referenced local files into the given Stream as a KMZ archive.
Top
Events
  NameDescription
Public eventCode examplePropertyChanged
Occurs when a property value changes.
Top
Remarks

A KmlNode corresponds to the KML concept of a Feature. KmlNode is an abstract type that describes properties common to all KML Features, such as: Name, Description, IsVisible, Viewpoint, etc. The following table maps KML Features Types to ArcGIS Runtime types:

KML Feature TypeRuntime TypeNotes
ContainerKmlContainerAbstract type. Contains properties common to KmlDocument and KmlFolder.
DocumentKmlDocument
FolderKmlFolder
PlacemarkKmlPlacemarkProperties can be found on individual overlay subtypes instead.
OverlayN/A
GroundOverlayKmlGroundOverlay
ScreenOverlayKmlScreenOverlay
PhotoOverlayKmlPhotoOverlay
NetworkLinkKmlNetworkLink

Examining individual nodes may be useful for: viewing attributes of the KML data, seeing the organization/structure within the KmlDataset, toggling visibility of KML features, and navigating to specific KML features.

It should be noted that a typical KML document will have multiple levels of nested KML nodes. Therefore to accurately traverse through all of the KML node information in a KmlDataset, it is recommended to recursively test all KmlNodes to see if they contain additional child KmlNodes. When writing your recursive function pay particular attention to the properties: KmlDataset.RootNodes, KmlNetworkLink.ChildNodes, and KmlContainer.ChildNodes (inherited by KmlDocument and KmlFolder).

Examples

Android

Example Name: IdentifyKmlFeatures

Show a callout with formatted content for a KML feature.

Code example screen shot.

C#
// Copyright 2020 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.Webkit;
using ArcGISRuntime;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Ogc;
using Esri.ArcGISRuntime.UI.Controls;
using System;
using System.Linq;

namespace ArcGISRuntimeXamarin.Samples.IdentifyKmlFeatures
{
    [Activity(ConfigurationChanges = Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        name: "Identify KML features",
        category: "Layers",
        description: "Show a callout with formatted content for a KML feature.",
        instructions: "Tap a feature to identify it. Feature information will be displayed in a callout.",
        tags: new[] { "KML", "KMZ", "Keyhole", "NOAA", "NWS", "OGC", "weather" })]
    [ArcGISRuntime.Samples.Shared.Attributes.AndroidLayout("IdentifyKMLFeatures.axml")]
    public class IdentifyKmlFeatures : Activity
    {
        // Hold references to UI controls.
        private MapView _myMapView;
        private WebView _htmlView;

        // Hold a reference to the KML layer for use in identify operations.
        private KmlLayer _forecastLayer;

        // Initial view envelope.
        private readonly Envelope _usEnvelope = new Envelope(-144.619561355187, 18.0328662832097, -66.0903762761083, 67.6390975806745, SpatialReferences.Wgs84);

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

            Title = "Identify KML features";

            CreateLayout();
            Initialize();
        }

        private void Initialize()
        {
            // Set up the basemap.
            _myMapView.Map = new Map(Basemap.CreateDarkGrayCanvasVector());

            // Create the dataset.
            KmlDataset dataset = new KmlDataset(new Uri("https://www.wpc.ncep.noaa.gov/kml/noaa_chart/WPC_Day1_SigWx.kml"));

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

            // Add the layer to the map.
            _myMapView.Map.OperationalLayers.Add(_forecastLayer);

            // Zoom to the extent of the United States.
            _myMapView.SetViewpoint(new Viewpoint(_usEnvelope));

            // Listen for taps to identify features.
            _myMapView.GeoViewTapped += MyMapView_GeoViewTapped;
        }

        private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // Clear any existing popups.
            _myMapView.DismissCallout();

            try
            {
                // Perform identify on the KML layer and get the results.
                IdentifyLayerResult identifyResult = await _myMapView.IdentifyLayerAsync(_forecastLayer, e.Position, 2, false);

                // Return if there are no results that are KML placemarks.
                if (!identifyResult.GeoElements.OfType<KmlGeoElement>().Any())
                {
                    return;
                }

                // Get the first identified feature that is a KML placemark
                KmlNode firstIdentifiedPlacemark = identifyResult.GeoElements.OfType<KmlGeoElement>().First().KmlNode;

                // Display the string content as an HTML document.
                _htmlView.LoadDataWithBaseURL(string.Empty, firstIdentifiedPlacemark.BalloonContent, "text/html", "UTF-8", null);
            }
            catch (Exception ex)
            {
                new AlertDialog.Builder(this).SetMessage(ex.ToString()).SetTitle("Error").Show();
            }
        }

        private void CreateLayout()
        {
            // Load the layout from the axml resource.
            SetContentView(Resource.Layout.IdentifyKMLFeatures);

            _myMapView = FindViewById<MapView>(Resource.Id.mapView);
            _htmlView = FindViewById<WebView>(Resource.Id.webView);
        }
    }
}
Examples

Xamarin Forms Android

Example Name: IdentifyKmlFeatures

Show a callout with formatted content for a KML feature.

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 System.Linq;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Ogc;
using Xamarin.Forms;

namespace ArcGISRuntimeXamarin.Samples.IdentifyKmlFeatures
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        name: "Identify KML features",
        category: "Layers",
        description: "Show a callout with formatted content for a KML feature.",
        instructions: "Tap a feature to identify it. Feature information will be displayed in a callout.",
        tags: new[] { "KML", "KMZ", "Keyhole", "NOAA", "NWS", "OGC", "weather" })]
    public partial class IdentifyKmlFeatures : ContentPage
    {
        // Hold a reference to the KML layer for use in identify operations.
        private KmlLayer _forecastLayer;

        // Initial view envelope.
        private readonly Envelope _usEnvelope = new Envelope(-144.619561355187, 18.0328662832097, -66.0903762761083, 67.6390975806745, SpatialReferences.Wgs84);

        public IdentifyKmlFeatures()
        {
            InitializeComponent();
            Initialize();
        }

        private void Initialize()
        {
            // Set up the basemap.
            MyMapView.Map = new Map(Basemap.CreateDarkGrayCanvasVector());

            // Create the dataset.
            KmlDataset dataset = new KmlDataset(new Uri("https://www.wpc.ncep.noaa.gov/kml/noaa_chart/WPC_Day1_SigWx.kml"));

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

            // Add the layer to the map.
            MyMapView.Map.OperationalLayers.Add(_forecastLayer);

            // Zoom to the extent of the United States.
            MyMapView.SetViewpoint(new Viewpoint(_usEnvelope));

            // Listen for taps to identify features.
            MyMapView.GeoViewTapped += MyMapView_GeoViewTapped;
        }

        private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
        {
            // Clear any existing popups.
            MyMapView.DismissCallout();

            try
            {
                // Perform identify on the KML layer and get the results.
                IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_forecastLayer, e.Position, 2, false);

                // Return if there are no results that are KML placemarks.
                if (!identifyResult.GeoElements.OfType<KmlGeoElement>().Any())
                {
                    return;
                }

                // Get the first identified feature that is a KML placemark
                KmlNode firstIdentifiedPlacemark = identifyResult.GeoElements.OfType<KmlGeoElement>().First().KmlNode;

                // Show a page with the HTML content
                await Navigation.PushAsync(new KmlIdentifyResultDisplayPage(firstIdentifiedPlacemark.BalloonContent));
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.ToString(), "OK");
            }
        }
    }
}

public class KmlIdentifyResultDisplayPage : ContentPage
{
    public KmlIdentifyResultDisplayPage(string htmlContent)
    {
        Title = "KML identify result";

        // Create the web browser control
        WebView htmlView = new WebView
        {

            // Display the string content as an HTML document
            Source = new HtmlWebViewSource() { Html = htmlContent }
        };

        // Create and add a layout to the page
        Grid layout = new Grid();
        Content = layout;

        // Add the webview to the page
        layout.Children.Add(htmlView);
    }
}
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.IdentifyKmlFeatures.IdentifyKmlFeatures">
    <StackLayout Orientation="Vertical">
        <Label Text="Tap to identify features."
               VerticalOptions="Start"/>
        <esriUI:MapView x:Name="MyMapView"
                        VerticalOptions="FillAndExpand" />
    </StackLayout>
</ContentPage>
See Also
Inheritance Hierarchy
Additional Examples
Hyperlink to ExampleDescription
CreateAndSaveKmlFileConstruct a KML document and save it as a KMZ file.
EditKmlGroundOverlayEdit the values of a KML ground overlay.
IdentifyKmlFeaturesShow a callout with formatted content for a KML feature.
ListKmlContentsList the contents of a KML file.
PlayKmlToursPlay tours in KML files.