View on GitHub Sample viewer app

Show a callout with formatted content for a KML feature.

Image of identify KML features

Use case

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

How to use the sample

Click on 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 NOAA and the NWS. You can’t identify the screen overlay.

How it works

  1. Listen to clicks on the MapView using setOnMouseClicked().
  2. When the map view is clicked:
  • Dismiss the Callout, if one is showing.
  • Call identifyLayerAsync(...) 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 “balloon content”. 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

  • IdentifyLayerResult
  • KmlLayer
  • KmlPlacemark
  • MapView

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.

Additional information

KML features can have rich HTML content, including images.

Tags

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

Sample Code

module-info.java module-info.java IdentifyKMLFeaturesSample.java
/*
* Copyright 2022 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.
*/
module com.esri.samples.identify_kml_features {
// require ArcGIS Maps SDK for Java module
requires com.esri.arcgisruntime;
// handle SLF4J http://www.slf4j.org/codes.html#StaticLoggerBinder
requires org.slf4j.nop;
// require JavaFX modules that the application uses
requires javafx.graphics;
requires javafx.controls;
requires javafx.web;
exports com.esri.samples.identify_kml_features;
}