Search in sources :

Example 1 with Bounds

use of org.vaadin.addon.leaflet.shared.Bounds 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 2 with Bounds

use of org.vaadin.addon.leaflet.shared.Bounds 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 3 with Bounds

use of org.vaadin.addon.leaflet.shared.Bounds 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 4 with Bounds

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

the class SplitpanelIssue170 method getTestComponent.

@Override
public Component getTestComponent() {
    LMap leafletMap = new LMap();
    leafletMap.setSizeFull();
    Bounds bounds = new Bounds();
    bounds.setSouthWestLon(15.3308);
    bounds.setSouthWestLat(41.1427);
    bounds.setNorthEastLat(39.8847);
    bounds.setNorthEastLon(16.887);
    leafletMap.zoomToExtent(bounds);
    leafletMap.addLayer(new LTileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"));
    HorizontalSplitPanel sp = new HorizontalSplitPanel();
    sp.setSizeFull();
    sp.setFirstComponent(leafletMap);
    sp.setSecondComponent(new Label("My Label"));
    return sp;
}
Also used : LMap(org.vaadin.addon.leaflet.LMap) LTileLayer(org.vaadin.addon.leaflet.LTileLayer) Bounds(org.vaadin.addon.leaflet.shared.Bounds) HorizontalSplitPanel(com.vaadin.ui.HorizontalSplitPanel) Label(com.vaadin.ui.Label)

Example 5 with Bounds

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

the class ZoomToExtendOnInitilaRender method getTestComponent.

@Override
public Component getTestComponent() {
    final double[] latitude = { 44.03664d, 43.961669d, 43.859999d };
    final double[] longitude = { 11.161893d, 11.129769d, 11.061234d };
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSizeFull();
    // Getting my map.
    LMap map = new LMap();
    map.setControls(new ArrayList<Control>(Arrays.asList(Control.values())));
    map.setSizeFull();
    // Setting backgroud layer.
    map.addBaseLayer(new LOpenStreetMapLayer(), "OSM");
    // I am here.
    LMarker myPositon = new LMarker(43.894367, 11.078185);
    myPositon.setVisible(true);
    map.addComponent(myPositon);
    // Get random other point.
    int idxOther = Math.min((int) (Math.random() * 3.d), 2);
    // Put other point on map.
    LMarker leafletMarker = new LMarker(latitude[idxOther], longitude[idxOther]);
    map.addComponent(leafletMarker);
    // Build map bounds.
    Point[] mapPoints = { new Point(43.894367, 11.078185), new Point(latitude[idxOther], longitude[idxOther]) };
    Bounds mapBounds = new Bounds(mapPoints);
    // I'm expecting to see my map with two points.
    map.setCenter(mapBounds);
    map.zoomToExtent(mapBounds);
    layout.addComponent(map);
    return layout;
}
Also used : Control(org.vaadin.addon.leaflet.shared.Control) LMap(org.vaadin.addon.leaflet.LMap) LOpenStreetMapLayer(org.vaadin.addon.leaflet.LOpenStreetMapLayer) Bounds(org.vaadin.addon.leaflet.shared.Bounds) VerticalLayout(com.vaadin.ui.VerticalLayout) Point(org.vaadin.addon.leaflet.shared.Point) LMarker(org.vaadin.addon.leaflet.LMarker) Point(org.vaadin.addon.leaflet.shared.Point)

Aggregations

Bounds (org.vaadin.addon.leaflet.shared.Bounds)15 Point (org.vaadin.addon.leaflet.shared.Point)9 LMap (org.vaadin.addon.leaflet.LMap)6 LOpenStreetMapLayer (org.vaadin.addon.leaflet.LOpenStreetMapLayer)5 ExternalResource (com.vaadin.server.ExternalResource)3 Button (com.vaadin.ui.Button)3 VerticalLayout (com.vaadin.ui.VerticalLayout)3 LImageOverlay (org.vaadin.addon.leaflet.LImageOverlay)3 LPolyline (org.vaadin.addon.leaflet.LPolyline)3 Control (org.vaadin.addon.leaflet.shared.Control)3 ServerConnector (com.vaadin.client.ServerConnector)2 ClassResource (com.vaadin.server.ClassResource)2 ClickEvent (com.vaadin.ui.Button.ClickEvent)2 LMarker (org.vaadin.addon.leaflet.LMarker)2 LTileLayer (org.vaadin.addon.leaflet.LTileLayer)2 LeafletMoveEndEvent (org.vaadin.addon.leaflet.LeafletMoveEndEvent)2 LeafletMoveEndListener (org.vaadin.addon.leaflet.LeafletMoveEndListener)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 Element (com.google.gwt.dom.client.Element)1 Timer (com.google.gwt.user.client.Timer)1