事件
地图和地图要素具有下列事件。
地图事件
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();
}
源事件
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();
});
}
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());
}
本页是否有帮助?
感谢您的反馈