事件

地图和地图要素具有下列事件。

地图事件

MapClickEvent

用户点击地图触发的事件。注意,如果用户双击地图,该事件会触发两次。

下面是处理地图点击事件的示例。用户点击时,显示一条消息,包含事件的名称和地图中点击的坐标:

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

地图单击事件会延迟 250ms 发送,以确保用户不是双击。

MapDoubleClickEvent

用户双击地图时发送的事件。

下面是处理地图双击事件的示例。

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

源事件

SourceFeatureClickEvent

用户点击 地图要素 时触发的事件。注意,如果用户双击,该事件会触发两次。

@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

地图要素单击事件会延迟 250ms 发送,以确保用户不是双击。

SourceFeatureDoubleClickEvent

用户双击地图要素时发送的事件。

GeoObjectClickEvent

用户点击地理对象时发送的事件。注意,如果用户双击,该事件会触发两次。

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

地理对象单击事件会延迟 250ms 发送,以确保用户不是双击。

GeoObjectDoubleClickEvent

用户双击地理对象时发送的事件。

要素事件

FeatureClickEvent

用户点击地图要素时触发的事件。注意,如果用户双击地图,该事件会触发两次。

FeatureSingleClickEvent

地图要素单击事件会延迟 250ms 发送,以确保用户不是双击。

FeatureDoubleClickEvent

用户双击地图要素时发送的事件。