View on GitHub Sample viewer app

Play tours in KML files.

Image of play KML tour

Use case

KML, the file format used by Google Earth, supports creating tours, which can control the viewpoint of the scene, hide and show content, and play audio. Tours allow you to easily share tours of geographic locations, which can be augmented with rich multimedia. ArcGIS Maps SDK for Java allows you to consume these tours using a simple API.

How to use the sample

The sample will load the KMZ file from ArcGIS Online. Click the play button to start the tour. The narration audio will start and then the viewpoint will animate. Press the button again to pause the tour. To restart the tour, hit the refresh button and then the play button.

How it works

  1. Create a KmlDataset with the path to a local KML file with a KML tour.
  2. Create and load a KmlLayer with the dataset.
  3. When the layer has loaded, search its KmlNodes by recursing through kmlLayer.getRootNodes() to find a KmlTour node.
  4. Create a KmlTourController and set the tour with kmlTourController.setTour(kmlTour).
  5. Use kmltourController.play(), kmltourController.pause(), and kmltourController.reset() to control the tour.

Relevant API

  • KmlTour
  • KmlTourController

About the data

This sample uses a custom tour created by the ArcGIS Maps SDKs for Native Apps samples team. When you play the tour, you’ll see a narrated journey through some of Esri’s offices.

Additional information

See Touring in KML in Keyhole Markup Language for more information.

Tags

animation, interactive, KML, narration, pause, play, story, tour

Sample Code

module-info.java module-info.java PlayAKMLTourSample.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.play_a_kml_tour {
// 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;
exports com.esri.samples.play_a_kml_tour;
}