Events
The map and features has the following events.
Map Events
MapClickEvent
An event that is fired when the map is clicked. Please note that if the user double-clicks, the event will be triggered twice.
Below is an example of handling a map click event. When a user clicks on the map, a notification is displayed with the event name and the coordinates of the map click location:
protected GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();
@Autowired
private Notifications notifications;
@Subscribe("geoMap")
public void onGeoMapMapClick(final MapClickEvent event) {
Point point = geometryFactory.createPoint(event.getCoordinate());
notifications.create("ClickEvent", point.getCoordinate().toString())
.withPosition(Notification.Position.BOTTOM_END)
.show();
}
MapSingleClickEvent
A map single event is fired after 250 ms to ensure that it is not a double click.
MapDoubleClickEvent
An event is fired when user makes double-click on a map.
Below is an example of handling a map double-click event.
@ViewComponent
private GeoMap geoMap;
@Subscribe("geoMap")
public void onGeoMapMapDoubleClick(final MapDoubleClickEvent event) {
GeoMapView view = new GeoMapView();
view.setCenter(event.getCoordinate());
view.setZoom(6);
geoMap.setMapView(view);
}
MapMoveEndEvent
An event is fired after the map is moved (for instance, after zooming, panning, or dragging the map).
Here’s an example of how to handle a map move event.
@Autowired
private Notifications notifications;
@Subscribe("geoMap")
public void onGeoMapMapMoveEnd(final MapMoveEndEvent event) {
notifications.create("MapMoveEndEvent",
String.format("""
Values:
Center: %s
Zoom: %s
Rotation: %s
""",
event.getCenter(),
event.getZoom(),
event.getRotation()))
.withPosition(Notification.Position.BOTTOM_END)
.show();
}
MapZoomChangedEvent
An event is triggered when the resolution of the map view is changed.
Here’s an example demonstrating how to handle a map zoom change event.
@Autowired
private Notifications notifications;
@Subscribe("geoMap")
public void onGeoMapMapZoomChanged(final MapZoomChangedEvent event) {
notifications.create("MapZoomChangedEvent", "Zoom: " + event.getZoom())
.withPosition(Notification.Position.BOTTOM_END)
.show();
}
Source Events
SourceFeatureClickEvent
An event that is fired when the feature is clicked. Note, if the user makes double click, event will be fired twice.
@ViewComponent("geoMap.vector.vectorSource")
private VectorSource vectorSource;
@Subscribe
public void onInit(final InitEvent event) {
vectorSource.addSourceFeatureClickListener(clickEvent -> {
Feature feature = clickEvent.getFeature();
notifications.create("SourceFeatureClickEvent",
feature.getGeometry().get().getClass().getSimpleName())
.withPosition(Notification.Position.BOTTOM_END)
.show();
});
}
SourceFeatureSingleClickEvent
A feature single click event is fired after 250 ms to ensure that it is not a double click.
GeoObjectClickEvent
An event that is fired when the geo-object is clicked. Note, if the user makes double click, event will be fired twice.
@Autowired
private Notifications notifications;
@ViewComponent("map.vectorLayer.dataVectorSource")
private DataVectorSource<Location> dataVectorSource;
@Subscribe
public void onInit(final InitEvent event) {
dataVectorSource.addGeoObjectClickListener(clickEvent ->
notifications.create("GeoObject click", clickEvent.getItem().getCity())
.withPosition(Notification.Position.BOTTOM_END)
.show());
}