Search in sources :

Example 1 with LOpenStreetMapLayer

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

the class ChoroplethExample method getTestComponent.

@Override
public Component getTestComponent() {
    leafletMap = new LMap();
    leafletMap.addLayer(new LOpenStreetMapLayer());
    leafletMap.setView(37.8, -96.0, 4.0);
    /*
         * Reading from geojson here, but typically you'd just query
         * your DB directly for the data.
         */
    FeatureJSON io = new FeatureJSON();
    try {
        // 
        // 
        FeatureCollection fc = io.readFeatureCollection(getClass().getResourceAsStream("/us-states.json"));
        FeatureIterator iterator = fc.features();
        try {
            while (iterator.hasNext()) {
                Feature feature = iterator.next();
                final String name = feature.getProperty("name").getValue().toString();
                final Double density = (Double) feature.getProperty("density").getValue();
                System.out.println("State " + name + " read!");
                Geometry geometry = (Geometry) feature.getDefaultGeometryProperty().getValue();
                // Using a helper create v-leaflet components from geojson
                Collection<LeafletLayer> toLayers = JTSUtil.toLayers(geometry);
                for (LeafletLayer l : toLayers) {
                    leafletMap.addComponent(l);
                    if (l instanceof AbstractLeafletVector) {
                        configureFeature(l, density, name);
                    } else if (l instanceof LLayerGroup) {
                        LLayerGroup g = (LLayerGroup) l;
                        for (Component component : g) {
                            configureFeature((LeafletLayer) component, density, name);
                        }
                    }
                }
            }
        } finally {
            iterator.close();
        }
    } catch (MalformedURLException ex) {
        Logger.getLogger(ChoroplethExample.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ChoroplethExample.class.getName()).log(Level.SEVERE, null, ex);
    }
    /*
         * AbsoluteLayout is a handy layout you can use to place any Vaadin
         * components on top of map. Here we just use raw html label to create
         * a legend, but we could use dynamically generated html or e.g. Table
         * component on top of the map as well.
         */
    AbsoluteLayout absoluteLayout = new AbsoluteLayout();
    absoluteLayout.setWidth("800px");
    absoluteLayout.setHeight("500px");
    absoluteLayout.addComponent(leafletMap);
    Label label = new Label("<style>.legend { background:white; padding:10px; border-radius: 4px; text-align: left; line-height: 18px; color: #555; } .legend i { width: 18px; height: 18px; float: left; margin-right: 8px; opacity: 0.7; }</style><div class=\"info legend leaflet-control\"><i style=\"background:#FFEDA0\"></i> 0–10<br><i style=\"background:#FED976\"></i> 10–20<br><i style=\"background:#FEB24C\"></i> 20–50<br><i style=\"background:#FD8D3C\"></i> 50–100<br><i style=\"background:#FC4E2A\"></i> 100–200<br><i style=\"background:#E31A1C\"></i> 200–500<br><i style=\"background:#BD0026\"></i> 500–1000<br><i style=\"background:#800026\"></i> 1000+</div>", ContentMode.HTML);
    label.setWidth("100px");
    absoluteLayout.addComponent(label, "bottom: 30px; right: 20px;");
    return absoluteLayout;
}
Also used : MalformedURLException(java.net.MalformedURLException) LOpenStreetMapLayer(org.vaadin.addon.leaflet.LOpenStreetMapLayer) LeafletLayer(org.vaadin.addon.leaflet.LeafletLayer) Label(com.vaadin.ui.Label) IOException(java.io.IOException) Feature(org.opengis.feature.Feature) AbsoluteLayout(com.vaadin.ui.AbsoluteLayout) FeatureIterator(org.geotools.feature.FeatureIterator) Geometry(com.vividsolutions.jts.geom.Geometry) LLayerGroup(org.vaadin.addon.leaflet.LLayerGroup) FeatureJSON(org.geotools.geojson.feature.FeatureJSON) LMap(org.vaadin.addon.leaflet.LMap) FeatureCollection(org.geotools.feature.FeatureCollection) Component(com.vaadin.ui.Component) AbstractLeafletVector(org.vaadin.addon.leaflet.AbstractLeafletVector)

Example 2 with LOpenStreetMapLayer

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

the class FlyToTest method getTestComponent.

@Override
public Component getTestComponent() {
    leafletMap = new LMap();
    leafletMap.setWidth("600px");
    leafletMap.setHeight("300px");
    leafletMap.setCenter(0, 0);
    leafletMap.setZoomLevel(2);
    final LOpenStreetMapLayer osm = new LOpenStreetMapLayer();
    leafletMap.addLayer(osm);
    Button flyTo1 = new Button("Fly to Vaadin HQ");
    flyTo1.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            leafletMap.flyTo(new Point(60.452236, 22.299839), 14.0);
        }
    });
    Button flyTo2 = new Button("Fly to Golden Gate");
    flyTo2.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            leafletMap.flyTo(new Point(37.816304, -122.478543), 9.0);
        }
    });
    return new VerticalLayout(leafletMap, flyTo1, flyTo2);
}
Also used : LMap(org.vaadin.addon.leaflet.LMap) LOpenStreetMapLayer(org.vaadin.addon.leaflet.LOpenStreetMapLayer) Button(com.vaadin.ui.Button) VerticalLayout(com.vaadin.ui.VerticalLayout) Point(org.vaadin.addon.leaflet.shared.Point)

Example 3 with LOpenStreetMapLayer

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

the class FractionalZoom method getTestComponent.

@Override
public Component getTestComponent() {
    leafletMap = new LMap();
    leafletMap.setWidth("300px");
    leafletMap.setHeight("300px");
    leafletMap.setCenter(0, 0);
    leafletMap.setZoomLevel(2.5);
    leafletMap.addLayer(new LOpenStreetMapLayer());
    final Slider slider = new Slider("ZoomLevel");
    slider.setWidth("200px");
    slider.setMin(1);
    slider.setMax(16);
    slider.setResolution(1);
    slider.addValueChangeListener((HasValue.ValueChangeListener<Double>) event -> {
        leafletMap.setZoomLevel(event.getValue());
        Notification.show("Zoom level: " + event.getValue(), Notification.Type.TRAY_NOTIFICATION);
    });
    return new VerticalLayout(leafletMap, slider);
}
Also used : HasValue(com.vaadin.data.HasValue) Notification(com.vaadin.ui.Notification) Slider(com.vaadin.ui.Slider) VerticalLayout(com.vaadin.ui.VerticalLayout) LMap(org.vaadin.addon.leaflet.LMap) LOpenStreetMapLayer(org.vaadin.addon.leaflet.LOpenStreetMapLayer) AbstractTest(org.vaadin.addonhelpers.AbstractTest) Component(com.vaadin.ui.Component) LMap(org.vaadin.addon.leaflet.LMap) Slider(com.vaadin.ui.Slider) LOpenStreetMapLayer(org.vaadin.addon.leaflet.LOpenStreetMapLayer) VerticalLayout(com.vaadin.ui.VerticalLayout) HasValue(com.vaadin.data.HasValue)

Example 4 with LOpenStreetMapLayer

use of org.vaadin.addon.leaflet.LOpenStreetMapLayer 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 5 with LOpenStreetMapLayer

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

Aggregations

LOpenStreetMapLayer (org.vaadin.addon.leaflet.LOpenStreetMapLayer)18 LMap (org.vaadin.addon.leaflet.LMap)15 Point (org.vaadin.addon.leaflet.shared.Point)9 VerticalLayout (com.vaadin.ui.VerticalLayout)7 LMarker (org.vaadin.addon.leaflet.LMarker)6 Bounds (org.vaadin.addon.leaflet.shared.Bounds)5 ExternalResource (com.vaadin.server.ExternalResource)3 Button (com.vaadin.ui.Button)3 LeafletMoveEndEvent (org.vaadin.addon.leaflet.LeafletMoveEndEvent)3 LeafletMoveEndListener (org.vaadin.addon.leaflet.LeafletMoveEndListener)3 ClickEvent (com.vaadin.ui.Button.ClickEvent)2 Component (com.vaadin.ui.Component)2 Label (com.vaadin.ui.Label)2 LImageOverlay (org.vaadin.addon.leaflet.LImageOverlay)2 LLayerGroup (org.vaadin.addon.leaflet.LLayerGroup)2 LPolyline (org.vaadin.addon.leaflet.LPolyline)2 LeafletClickEvent (org.vaadin.addon.leaflet.LeafletClickEvent)2 LeafletClickListener (org.vaadin.addon.leaflet.LeafletClickListener)2 LZoom (org.vaadin.addon.leaflet.control.LZoom)2 Control (org.vaadin.addon.leaflet.shared.Control)2