Search in sources :

Example 1 with LeafletContextMenuListener

use of org.vaadin.addon.leaflet.LeafletContextMenuListener in project v-leaflet by mstahv.

the class ContextClickOnMap method getTestComponent.

@Override
public Component getTestComponent() {
    leafletMap = new LMap();
    final LOpenStreetMapLayer lOpenStreetMapLayer = new LOpenStreetMapLayer();
    leafletMap.addLayer(lOpenStreetMapLayer);
    leafletMap.setCenter(0, 0);
    leafletMap.setZoomLevel(2);
    LPolygon polygon = new LPolygon(new Point(0, 0), new Point(30, 30), new Point(0, 30));
    leafletMap.addLayer(polygon);
    polygon.addContextMenuListener(new LeafletContextMenuListener() {

        @Override
        public void onContextMenu(LeafletContextMenuEvent event) {
            Notification.show("CxtClick at polygon at " + event.toString());
        }
    });
    polygon.addClickListener(new LeafletClickListener() {

        @Override
        public void onClick(LeafletClickEvent event) {
            Notification.show("Std Click at polygon at " + event.toString());
        }
    });
    // prevent bubbling of events to DOM parents(like the map)
    polygon.setBubblingMouseEvents(false);
    leafletMap.addContextMenuListener(new LeafletContextMenuListener() {

        @Override
        public void onContextMenu(LeafletContextMenuEvent event) {
            Point point = event.getPoint();
            LMarker marker = new LMarker(point);
            marker.setPopup("Created by ContextClick on lOpenStreetMapLayer");
            leafletMap.addComponent(marker);
            marker.openPopup();
        }
    });
    leafletMap.addClickListener(new LeafletClickListener() {

        @Override
        public void onClick(LeafletClickEvent event) {
            if (event.getMouseEvent().getButton() == MouseEventDetails.MouseButton.LEFT) {
                Notification.show("Std Click on map at " + event.toString() + ". Use context click to add marker.");
            }
        }
    });
    return leafletMap;
}
Also used : LeafletClickEvent(org.vaadin.addon.leaflet.LeafletClickEvent) LMap(org.vaadin.addon.leaflet.LMap) LOpenStreetMapLayer(org.vaadin.addon.leaflet.LOpenStreetMapLayer) LeafletContextMenuListener(org.vaadin.addon.leaflet.LeafletContextMenuListener) LeafletClickListener(org.vaadin.addon.leaflet.LeafletClickListener) Point(org.vaadin.addon.leaflet.shared.Point) LeafletContextMenuEvent(org.vaadin.addon.leaflet.LeafletContextMenuEvent) LMarker(org.vaadin.addon.leaflet.LMarker) LPolygon(org.vaadin.addon.leaflet.LPolygon)

Aggregations

LMap (org.vaadin.addon.leaflet.LMap)1 LMarker (org.vaadin.addon.leaflet.LMarker)1 LOpenStreetMapLayer (org.vaadin.addon.leaflet.LOpenStreetMapLayer)1 LPolygon (org.vaadin.addon.leaflet.LPolygon)1 LeafletClickEvent (org.vaadin.addon.leaflet.LeafletClickEvent)1 LeafletClickListener (org.vaadin.addon.leaflet.LeafletClickListener)1 LeafletContextMenuEvent (org.vaadin.addon.leaflet.LeafletContextMenuEvent)1 LeafletContextMenuListener (org.vaadin.addon.leaflet.LeafletContextMenuListener)1 Point (org.vaadin.addon.leaflet.shared.Point)1