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

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
private GeoMap geoMap;

@Subscribe
public void onInit(final InitEvent event) {
    VectorLayer vectorLayer = geoMap.getLayer("vector");
    VectorSource vectorSource = vectorLayer.getSource();
    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.

GeoObjectClickEvent

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

protected GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory(); (1)

@ViewComponent
private GeoMap map;

@Autowired
private Notifications notifications;

@Subscribe
public void onInit(final InitEvent event) {
    VectorLayer vectorLayer = map.getLayer("vectorLayer");
    DataVectorSource<Location> locationSource = vectorLayer.getSource();
    locationSource.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.

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.