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.

SourceFeatureDoubleClickEvent

An event is fired when user makes double click on a feature.

SourceFeatureSelectEvent

An event is triggered when features are selected or deselected. Keep in mind that the event only includes the features that were just selected or deselected. For example, if one feature is already selected out of a total of two, and the second feature is then selected, the event will only contain the newly selected feature.

@Autowired
private Notifications notifications;

@Subscribe("map.featureLayer.featureSource")
public void onMapFeatureLayerFeatureSourceSourceFeatureSelect(final HasFeatureSelect.SourceFeatureSelectEvent event) {
    notifications.create("SourceFeatureSelectEvent",
                    String.format("Selected: %s\nDeselected: %s",
                            event.getSelected().size(), event.getDeselected()))
            .show();
}

SourceFeatureDragStartEvent

An event is fired when the user starts dragging a feature.

@Autowired
private Notifications notifications;

@Subscribe("map.featureLayer.featureSource")
public void onSourceFeatureDragStart(final HasFeatureDrag.SourceFeatureDragStartEvent event) {
    notifications.create("SourceFeatureDragStartEvent", "Features: "
                    + event.getFeatures().size())
            .show();
}

SourceFeatureDragEndEvent

An event is fired when the user finishes dragging a feature.

@Autowired
private Notifications notifications;

@Subscribe("map.featureLayer.featureSource")
public void onSourceFeatureDragEnd(final HasFeatureDrag.SourceFeatureDragEndEvent event) {
    notifications.create("SourceFeatureDragEndEvent", "Features: "
                    + event.getFeatures().size())
            .show();
}

SourceFeatureModifyStartEvent

An event is fired when a feature modification is initiated.

@Autowired
private Notifications notifications;

@Subscribe("map.featureLayer.featureSource")
public void onSourceFeatureModifyStart(final HasFeatureModify.SourceFeatureModifyStartEvent event) {
    notifications.create("SourceFeatureModifyStartEvent", "Features: "
                    + event.getFeatures().size())
            .show();
}

SourceFeatureModifyEndEvent

An event is fired when a feature modification is completed.

@Autowired
private Notifications notifications;

@Subscribe("map.featureLayer.featureSource")
public void onSourceFeatureModifyEnd(final HasFeatureModify.SourceFeatureModifyEndEvent event) {
    notifications.create("SourceFeatureModifyEndEvent", "Features: "
                    + event.getFeatures().size())
            .show();
}

SourceFeatureDeleteEvent

An event is fired when a feature is deleted from a source.

@Autowired
private Notifications notifications;

@Subscribe("map.featureLayer.featureSource")
public void onSourceFeatureDelete(final HasFeatureModify.SourceFeatureDeleteEvent event) {
    notifications.create("SourceFeatureDeleteEvent", "Features: "
                    + event.getFeatures().size())
            .show();
}

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());
}

GeoObjectSingleClickEvent

A geo-object single click event is fired after 250 ms to ensure that it is not a double click.

GeoObjectDoubleClickEvent

An event is fired when user makes double click on a geo-object.

GeoObjectSelectEvent

A selection event is triggered when geo-objects are selected or deselected. Keep in mind that the event only includes the newly selected or deselected geo-objects. For example, if one geo-object is already selected out of a total of two, and you then select the second geo-object, the event will only contain information about the second geo-object you just selected.

@Autowired
private Notifications notifications;

@Subscribe("map.layer.source")
public void onMapLayerSourceGeoObjectSelect(final HasGeoObjectSelect.GeoObjectSelectEvent<Region> event) {
    notifications.create("GeoObjectSelectEvent",
                    String.format("Selected: %s\nDeselected: %s",
                            event.getSelected().size(), event.getDeselected()))
            .show();
}

GeoObjectDragStartEvent

An event is fired when the user starts dragging a geo-object.

@Autowired
private Notifications notifications;

@Subscribe("map.layer.source")
public void onSourceGeoObjectDragStart(final HasGeoObjectDrag.GeoObjectDragStartEvent<Region> event) {
    notifications.create("GeoObjectDragStartEvent", "Items: "
                    + event.getItems().size())
            .show();
}

GeoObjectDragEndEvent

An event is fired when the user finishes dragging a geo-object.

@Autowired
private Notifications notifications;

@Subscribe("map.layer.source")
public void onSourceGeoObjectDragEnd(final HasGeoObjectDrag.GeoObjectDragEndEvent<Region> event) {
    notifications.create("GeoObjectDragEndEvent", "Items: "
                    + event.getItems().size())
            .show();
}

GeoObjectModifyStartEvent

An event is fired when a geo-object modification is initiated.

@Autowired
private Notifications notifications;

@Subscribe("map.layer.source")
public void onSourceGeoObjectModifyStart(final HasGeoObjectModify.GeoObjectModifyStartEvent<Region> event) {
    notifications.create("GeoObjectModifyStartEvent", "Items: "
                    + event.getItems().size())
            .show();
}

GeoObjectModifyEndEvent

An event is fired when a geo-object modification is completed.

@Autowired
private Notifications notifications;

@Subscribe("map.layer.source")
public void onSourceGeoObjectModifyEnd(final HasGeoObjectModify.GeoObjectModifyEndEvent<Region> event) {
    notifications.create("GeoObjectModifyEndEvent", "Items: "
                    + event.getItems().size())
            .show();
}

Feature Events

FeatureClickEvent

An event that is fired when feature is clicked. Note, if the user makes double click, event will be fired twice.

FeatureSingleClickEvent

An event is fired after 250 ms to ensure that it is not a double click.

FeatureDoubleClickEvent

An event is fired when user makes double click on a feature.