View on GitHub Sample viewer app

Show a callout with the latitude and longitude of user-clicked points.

Image of show callout

Use case

Callouts are used to display temporary detail content on a map. You can display text and arbitrary UI controls in callouts.

How to use the sample

Click anywhere on the map. A callout showing the WGS84 coordinates for the clicked point will appear.

How it works

  1. Use MapView.setOnMouseClicked() to create a click event handler.
  2. Capture the click event and use its x and y coordinates to create a new Point2D representing the screen point.
  3. Get the screen point’s location on the map using MapView.screenToLocation(Point2D).
  4. Get the MapView’s callout.
  5. Set the title and detail of the callout to display the map point’s coordinates.
  6. Display the callout at the map point callout.showCalloutAt(mapPoint).

Relevant API

  • Callout
  • MapView
  • Point

Tags

balloon, bubble, callout, click, flyout, flyover, info window, popup

Sample Code

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