Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for Qt

Identify KML features

Sample Viewer View Sample on GitHub

Show a callout with formatted content for a KML feature.

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:
  • Call identifyLayer(...) passing in the KmlLayer, screen point and tolerance.
  • Await the result of the identify and then get the KmlPlacemark from the result.
  • 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.
  • 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.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.


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

Sample Code

import QtQuick 2.6
import Esri.ArcGISRuntime 100.9
import Esri.ArcGISRuntime.Toolkit.Controls 100.9 // needed to use Callout in QML

Rectangle {
    id: rootRectangle
    clip: true
    width: 800
    height: 600

    property Point clickedPoint: null
    property string calloutText: ""
    readonly property url layerUrl: ""

    MapView {
        id: mapView
        anchors.fill: parent

        Callout {
            id: callout
            calloutData: parent.calloutData
            autoAdjustWidth: false
            calloutWidth: 400
            accessoryButtonHidden: true
            leaderPosition: leaderPositionEnum.Top
            calloutContent: customComponent

        Map {
            BasemapDarkGrayCanvasVector {}

            // start zoomed in over the US
            ViewpointExtent {
                Envelope {
                    xMin: -19195297.778679
                    yMin: 512343.939994
                    xMax: -3620418.579987
                    yMax: 8658913.035426
                    SpatialReference {
                        wkid: 3857

            KmlLayer {
                id: forecastLayer
                KmlDataset {
                    url: layerUrl

        onMouseClicked: {
            clickedPoint = screenToLocation(mouse.x, mouse.y);
            if (identifyLayerStatus !== Enums.TaskStatusInProgress) {
                identifyLayer(forecastLayer, mouse.x, mouse.y, 15, false, 1);

        onIdentifyLayerStatusChanged: {
            if (identifyLayerStatus === Enums.TaskStatusCompleted) {
                if (identifyLayerResult.geoElements.length < 1) {
                calloutText = identifyLayerResult.geoElements[0].balloonContent;
                callout.calloutData.location = clickedPoint;

        Component {
            id: customComponent

            Text {
                id: componentText
                text: calloutText
                Binding {
                    target: callout
                    value: contentHeight + callout.calloutFramePadding
                    property: "calloutHeight"

                wrapMode: Text.WordWrap
                textFormat: Text.RichText