Search in sources :

Example 1 with LeafletMoveEndEvent

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

the class InitialViewPortDetectionWithFixedSize method getTestComponent.

@Override
public Component getTestComponent() {
    LOpenStreetMapLayer layer = new LOpenStreetMapLayer();
    leafletMap.addBaseLayer(layer, "OSM");
    leafletMap.setCenter(42.3625, -71.112);
    leafletMap.setZoomLevel(15);
    leafletMap.addMoveEndListener(new LeafletMoveEndListener() {

        @Override
        public void onMoveEnd(LeafletMoveEndEvent event) {
            updateZoomLabel();
        }
    });
    return leafletMap;
}
Also used : LeafletMoveEndListener(org.vaadin.addon.leaflet.LeafletMoveEndListener) LOpenStreetMapLayer(org.vaadin.addon.leaflet.LOpenStreetMapLayer) LeafletMoveEndEvent(org.vaadin.addon.leaflet.LeafletMoveEndEvent)

Example 2 with LeafletMoveEndEvent

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

the class LayerGroupTest method getTestComponent.

@Override
public Component getTestComponent() {
    leafletMap = new LMap();
    leafletMap.setCenter(60.4525, 22.301);
    leafletMap.setZoomLevel(15);
    leafletMap.setControls(new ArrayList<Control>(Arrays.asList(Control.values())));
    LPolyline leafletPolyline = null;
    // Adding to layergroup
    // Not creating a name -> not added to the
    llg = new LLayerGroup();
    // overlay controller
    leafletPolyline = new LPolyline(new Point(60.45, 22.295), new Point(60.4555, 22.301), new Point(60.45, 22.307));
    leafletPolyline.setColor("#FF0000");
    leafletPolyline.setFill(true);
    leafletPolyline.setFillColor("#FFFFFF");
    leafletPolyline.addClickListener(listener);
    llg.addComponent(leafletPolyline);
    leafletPolyline = new LPolyline(new Point(60.45 + 0.005, 22.295 + 0.005), new Point(60.4555 + 0.005, 22.301 + 0.005), new Point(60.45 + 0.005, 22.307 + 0.005));
    leafletPolyline.setColor("#FFFFFF");
    leafletPolyline.setFill(true);
    leafletPolyline.setFillColor("#FF0000");
    leafletPolyline.addClickListener(listener);
    llg.addComponent(leafletPolyline);
    LCircle leafletCircle = new LCircle(60.4525 + 0.005, 22.301 + 0.005, 200);
    leafletCircle.setColor("#FF0000");
    llgNested = new LLayerGroup();
    llgNested.addComponent(leafletCircle);
    llg.addComponent(llgNested);
    llg2 = new LLayerGroup();
    leafletCircle = new LCircle(60.4525 - 0.005, 22.301 - 0.005, 20);
    leafletCircle.setColor("#00FF00");
    llg2.addComponent(leafletCircle);
    leafletCircle = new LCircle(60.4525 - 0.008, 22.301 - 0.008, 20);
    leafletCircle.setColor("#00FF00");
    llg2.addComponent(leafletCircle);
    leafletCircle = new LCircle(60.4525 - 0.011, 22.301 - 0.011, 20);
    leafletCircle.setColor("#00FF00");
    llg2.addComponent(leafletCircle);
    leafletCircle = new LCircle(60.4525 - 0.014, 22.301 - 0.014, 20);
    leafletCircle.setColor("#00FF00");
    llg2.addComponent(leafletCircle);
    leafletMap.addOverlay(llg, null);
    leafletMap.addOverlay(llg2, "Small circles group");
    leafletCircle = new LCircle(60.4525, 22.301, 300);
    leafletCircle.setColor("#00FFFF");
    // leafletCircle.addClickListener(listener);
    leafletMap.addComponent(leafletCircle);
    LMarker leafletMarker = new LMarker(60.4525, 22.301);
    leafletMarker.addClickListener(listener);
    leafletMap.addComponent(leafletMarker);
    leafletMarker = new LMarker(60.4525, 22.301);
    leafletMarker.setIcon(new ClassResource("testicon.png"));
    leafletMarker.setIconSize(new Point(57, 52));
    leafletMarker.setIconAnchor(new Point(57, 26));
    leafletMarker.addClickListener(listener);
    leafletMap.addComponent(leafletMarker);
    leafletMap.addBaseLayer(new LOpenStreetMapLayer(), "OSM");
    leafletMap.addClickListener(listener);
    leafletMap.addMoveEndListener(new LeafletMoveEndListener() {

        @Override
        public void onMoveEnd(LeafletMoveEndEvent event) {
            Bounds b = event.getBounds();
            Notification.show(String.format("New viewport (%.4f,%.4f ; %.4f,%.4f)", b.getSouthWestLat(), b.getSouthWestLon(), b.getNorthEastLat(), b.getNorthEastLon()), Type.TRAY_NOTIFICATION);
        }
    });
    return leafletMap;
}
Also used : ClassResource(com.vaadin.server.ClassResource) LPolyline(org.vaadin.addon.leaflet.LPolyline) LOpenStreetMapLayer(org.vaadin.addon.leaflet.LOpenStreetMapLayer) Bounds(org.vaadin.addon.leaflet.shared.Bounds) LeafletMoveEndEvent(org.vaadin.addon.leaflet.LeafletMoveEndEvent) Point(org.vaadin.addon.leaflet.shared.Point) LMarker(org.vaadin.addon.leaflet.LMarker) LLayerGroup(org.vaadin.addon.leaflet.LLayerGroup) Control(org.vaadin.addon.leaflet.shared.Control) LeafletMoveEndListener(org.vaadin.addon.leaflet.LeafletMoveEndListener) LMap(org.vaadin.addon.leaflet.LMap) LCircle(org.vaadin.addon.leaflet.LCircle)

Example 3 with LeafletMoveEndEvent

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

the class ZoomLimitTest method getTestComponent.

@Override
public Component getTestComponent() {
    LOpenStreetMapLayer layer = new LOpenStreetMapLayer();
    leafletMap.addBaseLayer(layer, "OSM");
    leafletMap.setCenter(42.3625, -71.112);
    leafletMap.setZoomLevel(15);
    leafletMap.setMinZoom(MIN_ZOOM_LEVEL);
    leafletMap.setMaxZoom(MAX_ZOOM_LEVEL);
    leafletMap.addMoveEndListener(new LeafletMoveEndListener() {

        @Override
        public void onMoveEnd(LeafletMoveEndEvent event) {
            updateZoomLabel();
        }
    });
    return leafletMap;
}
Also used : LeafletMoveEndListener(org.vaadin.addon.leaflet.LeafletMoveEndListener) LOpenStreetMapLayer(org.vaadin.addon.leaflet.LOpenStreetMapLayer) LeafletMoveEndEvent(org.vaadin.addon.leaflet.LeafletMoveEndEvent)

Example 4 with LeafletMoveEndEvent

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

the class DynamicChanges method setup.

@Override
protected void setup() {
    super.setup();
    HorizontalLayout tools = new HorizontalLayout();
    Button button = new Button("Random new point");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            ArrayList<Point> arrayList = new ArrayList<Point>(Arrays.asList(polyline.getPoints()));
            arrayList.add(new Point(60 + r.nextInt(10), 20 + r.nextInt(10)));
            polyline.setPoints(arrayList.toArray(new Point[0]));
        }
    });
    tools.addComponent(button);
    button = new Button("Zoom to polyline");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            leafletMap.zoomToExtent(new Bounds(polyline.getPoints()));
        }
    });
    tools.addComponent(button);
    button = new Button("Center to last point ");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            Point[] points = polyline.getPoints();
            leafletMap.setCenter(points[points.length - 1]);
        }
    });
    tools.addComponent(button);
    button = new Button("Zoom to last point");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            Point[] points = polyline.getPoints();
            leafletMap.zoomToExtent(new Bounds(points[points.length - 1]));
        }
    });
    tools.addComponent(button);
    button = new Button("Show current zoom");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            Double zoomLevel = leafletMap.getZoomLevel();
            Notification.show("Zoomlevel is " + zoomLevel);
        }
    });
    tools.addComponent(button);
    button = new Button("Show current center point");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            Notification.show("Center point is " + leafletMap.getCenter());
        }
    });
    tools.addComponent(button);
    final LeafletMoveEndListener moveEndListener = new LeafletMoveEndListener() {

        @Override
        public void onMoveEnd(LeafletMoveEndEvent event) {
            Notification.show("Moved or zoomed", Type.TRAY_NOTIFICATION);
        }
    };
    final CheckBox checkBox = new CheckBox("Toggle move listener");
    checkBox.addValueChangeListener(new HasValue.ValueChangeListener<Boolean>() {

        @Override
        public void valueChange(ValueChangeEvent<Boolean> event) {
            if (event.getValue()) {
                registration = leafletMap.addMoveEndListener(moveEndListener);
            } else if (registration != null) {
                registration.remove();
            }
        }
    });
    tools.addComponent(checkBox);
    content.addComponentAsFirst(tools);
}
Also used : ClickEvent(com.vaadin.ui.Button.ClickEvent) LeafletClickEvent(org.vaadin.addon.leaflet.LeafletClickEvent) Bounds(org.vaadin.addon.leaflet.shared.Bounds) ArrayList(java.util.ArrayList) LeafletMoveEndEvent(org.vaadin.addon.leaflet.LeafletMoveEndEvent) Point(org.vaadin.addon.leaflet.shared.Point) HorizontalLayout(com.vaadin.ui.HorizontalLayout) HasValue(com.vaadin.data.HasValue) LeafletMoveEndListener(org.vaadin.addon.leaflet.LeafletMoveEndListener) Button(com.vaadin.ui.Button) CheckBox(com.vaadin.ui.CheckBox) ClickListener(com.vaadin.ui.Button.ClickListener) LeafletClickListener(org.vaadin.addon.leaflet.LeafletClickListener)

Aggregations

LeafletMoveEndEvent (org.vaadin.addon.leaflet.LeafletMoveEndEvent)4 LeafletMoveEndListener (org.vaadin.addon.leaflet.LeafletMoveEndListener)4 LOpenStreetMapLayer (org.vaadin.addon.leaflet.LOpenStreetMapLayer)3 Bounds (org.vaadin.addon.leaflet.shared.Bounds)2 Point (org.vaadin.addon.leaflet.shared.Point)2 HasValue (com.vaadin.data.HasValue)1 ClassResource (com.vaadin.server.ClassResource)1 Button (com.vaadin.ui.Button)1 ClickEvent (com.vaadin.ui.Button.ClickEvent)1 ClickListener (com.vaadin.ui.Button.ClickListener)1 CheckBox (com.vaadin.ui.CheckBox)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 ArrayList (java.util.ArrayList)1 LCircle (org.vaadin.addon.leaflet.LCircle)1 LLayerGroup (org.vaadin.addon.leaflet.LLayerGroup)1 LMap (org.vaadin.addon.leaflet.LMap)1 LMarker (org.vaadin.addon.leaflet.LMarker)1 LPolyline (org.vaadin.addon.leaflet.LPolyline)1 LeafletClickEvent (org.vaadin.addon.leaflet.LeafletClickEvent)1 LeafletClickListener (org.vaadin.addon.leaflet.LeafletClickListener)1