Identify KML features

View inQMLC++
View on GitHub
Sample viewer app

Show a callout with formatted content for a KML feature.

screenshot

Use case

A user may wish to select a KML feature to view relevant information about it.

How to use the sample

Click a feature to identify it. Feature information will be displayed in a callout.

Note: the KML layer used in this sample contains a screen overlay. The screen overlay contains a legend and the logos for the National Oceanic and Atmospheric Administration (NOAA) and the National Weather Service (NWS). You can't identify the screen overlay.

How it works

  1. Connect to the MouseClicked event on the MapView.
  2. On click:
  3. Call identifyLayer(...) passing in the KmlLayer, screen point and tolerance.
  4. Await the result of the identify and then get the KmlPlacemark from the result.
  5. Create a callout at the calculated map point and populate the callout content with text from the placemark's BalloonContent. NOTE: KML supports defining HTML for balloon content and may need to be converted from HTML to text.
  6. Show the callout.

Note: There are several types of KML features. This sample only identifies features of type KmlPlacemark.

Relevant API

  • GeoView::identifyLayer(...)
  • IdentifyLayerResult
  • KmlLayer
  • KmlPlacemark
  • KmlPlacemark::balloonContent()

About the data

This sample shows a forecast for significant weather within the U.S. Regions of severe thunderstorms, flooding, snowfall, and freezing rain are shown. Tap the features to see details.

Additional information

KML features can have rich HTML content, including images.

Tags

Keyhole, KML, KMZ, NOAA, NWS, OGC, weather

Sample Code

IdentifyKmlFeatures.qmlIdentifyKmlFeatures.cppIdentifyKmlFeatures.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
// [WriteFile Name=IdentifyKmlFeatures, 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 Esri.Samples 1.0
import Esri.ArcGISRuntime.Toolkit 100.12

Item {

    // add a mapView component
    MapView {
        id: view
        anchors.fill: parent

        Callout {
            id: callout
            calloutData: view.calloutData
            autoAdjustWidth: false
            calloutWidth: 300
            accessoryButtonHidden: true
            leaderPosition: leaderPositionEnum.Top
            calloutContent: customComponent
        }

        Component {
            id: customComponent

            Text {
                text: model.calloutText

                Binding {
                    target: callout
                    value: contentHeight + callout.calloutFramePadding
                    property: "calloutHeight"
                }

                wrapMode: Text.WordWrap
                textFormat: Text.RichText
            }
        }
    }

    // Declare the C++ instance which creates the scene etc. and supply the view
    IdentifyKmlFeaturesSample {
        id: model
        mapView: view
    }
}

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