Search in sources :

Example 1 with LPolyline

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

the class LayerGroupTest method setup.

@Override
protected void setup() {
    super.setup();
    addMarkers = new CheckBox("Add markers");
    content.addComponentAsFirst(addMarkers);
    delete = new CheckBox("Delete on click");
    content.addComponentAsFirst(delete);
    showLayerGroupCB = new CheckBox("Show first layer (switch on/off from server side)");
    showLayerGroupCB.setValue(true);
    content.addComponentAsFirst(showLayerGroupCB);
    showLayerGroupCB.addValueChangeListener(new HasValue.ValueChangeListener<Boolean>() {

        @Override
        public void valueChange(ValueChangeEvent<Boolean> event) {
            if (event.getValue()) {
                if (!leafletMap.hasComponent(llg)) {
                    leafletMap.addComponent(llg);
                }
            } else {
                leafletMap.removeComponent(llg);
            }
        }
    });
    Button button = new Button("Delete first component from map (may also be a layer containing many components)");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            for (Component c : leafletMap) {
                if (!(c instanceof LTileLayer)) {
                    leafletMap.removeComponent(c);
                    break;
                }
            }
        }
    });
    content.addComponentAsFirst(button);
    button = new Button("Delete first component from first layer group (may also be a layer containing many components)");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            LLayerGroup group = null;
            for (Component c : leafletMap) {
                if (c instanceof LLayerGroup) {
                    group = (LLayerGroup) c;
                    break;
                }
            }
            if (group.getComponentCount() > 0) {
                Component next = group.iterator().next();
                group.removeComponent(next);
            } else {
                Notification.show("No component in first component group");
            }
        }
    });
    content.addComponentAsFirst(button);
    button = new Button("Add polyline to first group on map (creates if does not exist)");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            LLayerGroup group = null;
            for (Component c : leafletMap) {
                if (c instanceof LLayerGroup) {
                    group = (LLayerGroup) c;
                    break;
                }
            }
            if (group == null) {
                group = new LLayerGroup();
                leafletMap.addOverlay(group, "new group");
            }
            LPolyline lPolyline = new LPolyline(new Point(60.44, 22.30), new Point(60.456, 22.304));
            lPolyline.addClickListener(listener);
            group.addComponent(lPolyline);
        }
    });
    content.addComponentAsFirst(button);
}
Also used : LTileLayer(org.vaadin.addon.leaflet.LTileLayer) LPolyline(org.vaadin.addon.leaflet.LPolyline) ClickEvent(com.vaadin.ui.Button.ClickEvent) LeafletClickEvent(org.vaadin.addon.leaflet.LeafletClickEvent) Point(org.vaadin.addon.leaflet.shared.Point) HasValue(com.vaadin.data.HasValue) LLayerGroup(org.vaadin.addon.leaflet.LLayerGroup) Button(com.vaadin.ui.Button) CheckBox(com.vaadin.ui.CheckBox) Component(com.vaadin.ui.Component) ClickListener(com.vaadin.ui.Button.ClickListener) LeafletClickListener(org.vaadin.addon.leaflet.LeafletClickListener)

Example 2 with LPolyline

use of org.vaadin.addon.leaflet.LPolyline 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 LPolyline

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

the class PlainImage method getTestComponent.

@Override
public Component getTestComponent() {
    leafletMap.setCrs(Crs.Simple);
    ExternalResource url = new ExternalResource("https://www.dropbox.com/s/oajfgu8onqxfo0g/photo.jpg?dl=1");
    // The size of this image is 3264 * 2448, scale it here to suite better
    // for default zoomlevels
    final Bounds bounds = new Bounds(new Point(0, 0), new Point(244.8, 326.4));
    LImageOverlay imageOverlay = new LImageOverlay(url, bounds);
    leafletMap.addLayer(imageOverlay);
    // You can fit it directly or to another extend like here, you could also
    // use multiple images on the background
    leafletMap.setMaxBounds(new Bounds(new Point(0, 0), new Point(300, 500)));
    // draw line from corner to corner
    leafletMap.addLayer(new LPolyline(new Point(0, 0), new Point(244.8, 326.4)));
    leafletMap.setMaxZoom(5);
    return leafletMap;
}
Also used : LPolyline(org.vaadin.addon.leaflet.LPolyline) Bounds(org.vaadin.addon.leaflet.shared.Bounds) Point(org.vaadin.addon.leaflet.shared.Point) ExternalResource(com.vaadin.server.ExternalResource) LImageOverlay(org.vaadin.addon.leaflet.LImageOverlay)

Example 4 with LPolyline

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

the class RestritedExtent method getTestComponent.

@Override
public Component getTestComponent() {
    final LMap leafletMap = new LMap();
    leafletMap.setHeight("300px");
    leafletMap.setWidth("300px");
    leafletMap.setZoomLevel(15);
    // leafletMap.addBaseLayer(new LOpenStreetMapLayer(), "OSM");
    Point p = new Point(60, 22);
    Point p2 = new Point(61, 23);
    final Bounds b = new Bounds(p, p2);
    leafletMap.setMaxBounds(b);
    leafletMap.zoomToExtent(b);
    leafletMap.addComponent(new LPolyline(p, p2));
    Button button = new Button("Move restricted extent (aka max bounds)");
    button.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            b.setNorthEastLat(b.getNorthEastLat() + 0.5);
            b.setNorthEastLon(b.getNorthEastLon() + 0.5);
            b.setSouthWestLat(b.getSouthWestLat() + 0.5);
            b.setSouthWestLon(b.getSouthWestLon() + 0.5);
            leafletMap.setMaxBounds(b);
            leafletMap.addComponent(new LPolyline(new Point(b.getSouthWestLat(), b.getSouthWestLon()), new Point(b.getNorthEastLat(), b.getNorthEastLon())));
            leafletMap.zoomToExtent(b);
        }
    });
    return new VerticalLayout(leafletMap, button);
}
Also used : LMap(org.vaadin.addon.leaflet.LMap) LPolyline(org.vaadin.addon.leaflet.LPolyline) Button(com.vaadin.ui.Button) Bounds(org.vaadin.addon.leaflet.shared.Bounds) VerticalLayout(com.vaadin.ui.VerticalLayout) Point(org.vaadin.addon.leaflet.shared.Point)

Example 5 with LPolyline

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

the class TransparentMap method getTestComponent.

@Override
public Component getTestComponent() {
    Page.getCurrent().getStyles().add(".v-leaflet .leaflet-container {background: yellow;}");
    leafletMap = new LMap();
    leafletMap.setWidth("300px");
    leafletMap.setHeight("300px");
    leafletMap.setCenter(0, 0);
    leafletMap.setZoomLevel(2);
    LPolyline lPolyline = new LPolyline(new Point(-30, -30), new Point(0, 30), new Point(30, 0));
    lPolyline.setColor("red");
    lPolyline.setFill(true);
    lPolyline.getStyle().setFillOpacity(1.0);
    leafletMap.addLayer(lPolyline);
    LCircleMarker lCircleMarker = new LCircleMarker(30, 30, 40);
    lCircleMarker.getStyle().setFillOpacity(0.05);
    leafletMap.addLayer(lCircleMarker);
    return leafletMap;
}
Also used : LMap(org.vaadin.addon.leaflet.LMap) LCircleMarker(org.vaadin.addon.leaflet.LCircleMarker) LPolyline(org.vaadin.addon.leaflet.LPolyline) Point(org.vaadin.addon.leaflet.shared.Point)

Aggregations

LPolyline (org.vaadin.addon.leaflet.LPolyline)10 Point (org.vaadin.addon.leaflet.shared.Point)10 LMap (org.vaadin.addon.leaflet.LMap)8 Button (com.vaadin.ui.Button)3 LMarker (org.vaadin.addon.leaflet.LMarker)3 Bounds (org.vaadin.addon.leaflet.shared.Bounds)3 VerticalLayout (com.vaadin.ui.VerticalLayout)2 LLayerGroup (org.vaadin.addon.leaflet.LLayerGroup)2 LOpenStreetMapLayer (org.vaadin.addon.leaflet.LOpenStreetMapLayer)2 LeafletClickEvent (org.vaadin.addon.leaflet.LeafletClickEvent)2 LeafletClickListener (org.vaadin.addon.leaflet.LeafletClickListener)2 HasValue (com.vaadin.data.HasValue)1 ClassResource (com.vaadin.server.ClassResource)1 ExternalResource (com.vaadin.server.ExternalResource)1 ClickEvent (com.vaadin.ui.Button.ClickEvent)1 ClickListener (com.vaadin.ui.Button.ClickListener)1 CheckBox (com.vaadin.ui.CheckBox)1 Component (com.vaadin.ui.Component)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1