List KML contents

View inQMLC++
View on GitHub
Sample viewer app

List the contents of a KML file.

screenshot

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 list of buttons. Select a node to zoom to that node and see its child nodes, if it has any. 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 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 to it.

Relevant API

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

Offline data

Read more about how to set up the sample's offline data here.

Link Local Location
ESRI test data <userhome>/ArcGIS/Runtime/Data/kml/esritestdata.kmz

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.qmlListKmlContents.cppListKmlContents.h
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// [WriteFile Name=ListKmlContents, Category=Layers]
// [Legal]
// 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.
// [Legal]

import QtQuick 2.6
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.11
import Esri.Samples 1.0

Item {

    SceneView {
        id: view
        anchors.fill: parent

        // Create window for displaying the KML contents
        Control {
            width: 300
            background : Rectangle {
                color: "lightgrey"
            }
            contentItem: GridLayout {
                columns: 2
                Button {
                    id: backButton
                    Layout.margins: 3
                    text: "<"
                    enabled: !sampleModel.isTopLevel
                    flat: true
                    highlighted: pressed
                    onClicked: {
                        sampleModel.displayPreviousLevel();
                    }
                }
                Text {
                    Layout.fillWidth: true
                    id: textLabel
                    text: sampleModel.labelText
                    wrapMode: Text.Wrap
                }
                ListView {
                    id: myListView
                    Layout.columnSpan: 2
                    Layout.fillWidth: true
                    model: sampleModel.levelNodeNames
                    Layout.preferredHeight: contentHeight
                    delegate: Button {
                        text: modelData
                        anchors {
                            left: parent.left
                            right: parent.right
                        }
                        highlighted: pressed
                        onClicked: {
                            sampleModel.processSelectedNode(text);
                        }
                    }
                }
            }
        }
    }

    // Declare the C++ instance which creates the scene etc. and supply the view
    ListKmlContentsSample {
        id: sampleModel
        sceneView: view
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.