Show callout - update UI interaction
@@ -59,32 +59,32 @@ public class ShowCalloutSample extends Application {
mapView = new MapView();
mapView.setMap(map);
+ // get the map view's callout
+ Callout callout = mapView.getCallout();
+
// click event to display the callout
mapView.setOnMouseClicked(e -> {
- // check that the primary mouse button was clicked and user is not
- // panning
- if (e.isStillSincePress() && e.getButton() == MouseButton.PRIMARY) {
+
+ // check that the primary mouse button was clicked and user is not panning
+ if (e.getButton() == MouseButton.PRIMARY && e.isStillSincePress()) {
+
// create a point from where the user clicked
Point2D point = new Point2D(e.getX(), e.getY());
// create a map point from a point
Point mapPoint = mapView.screenToLocation(point);
- // get the map view's callout
- Callout callout = mapView.getCallout();
-
- if (!callout.isVisible()) {
// set the callout's details
callout.setTitle("Location");
callout.setDetail(String.format("x: %.2f, y: %.2f", mapPoint.getX(), mapPoint.getY()));
// show the callout where the user clicked
callout.showCalloutAt(mapPoint, DURATION);
- } else {
- // hide the callout
+
+ // dismiss the callout on secondary click
+ } else if (e.getButton() == MouseButton.SECONDARY && e.isStillSincePress()) {
callout.dismiss();
}
- }
});
// add map view and control panel to stack pane
