Search in sources :

Example 1 with LPolygon

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

the class GeoJSONExample method getTestComponent.

@Override
public Component getTestComponent() {
    leafletMap = new LMap();
    leafletMap.setWidth("600px");
    leafletMap.setHeight("400px");
    /*
         * Note, this is just one option to read GeoJSON in java. Here, using 
         * helper from geotools library. In some simple cases approach to use
         * plain Json library like Jackson or GSON might be better.
         */
    FeatureJSON io = new FeatureJSON();
    try {
        long currentTimeMillis = System.currentTimeMillis();
        // Look ma, no proxy needed, how cool is that!
        FeatureCollection fc = io.readFeatureCollection(new URL("http://eric.clst.org/assets/wiki/uploads/Stuff/gz_2010_us_040_00_500k.json").openStream());
        Logger.getLogger(GeoJSONExample.class.getName()).severe("Download in " + (System.currentTimeMillis() - currentTimeMillis));
        currentTimeMillis = System.currentTimeMillis();
        FeatureIterator iterator = fc.features();
        try {
            while (iterator.hasNext()) {
                Feature feature = iterator.next();
                final String name = feature.getProperty("NAME").getValue().toString();
                System.out.println("State " + name + " read!");
                Geometry geometry = (Geometry) feature.getDefaultGeometryProperty().getValue();
                // The geojson provided in example is rather complex (several megabytes)
                // Use JTS to simplyfy. Note that it is rather easy to use
                // different settings on different zoom levels, as well as decide
                // to drop the feature form client altogether
                geometry = DouglasPeuckerSimplifier.simplify(geometry, 0.2);
                // In this example can be Polygon/Multipolygon
                Collection<LeafletLayer> toLayers = JTSUtil.toLayers(geometry);
                for (LeafletLayer l : toLayers) {
                    leafletMap.addComponent(l);
                    if (l instanceof LPolygon) {
                        LPolygon lPolygon = (LPolygon) l;
                        lPolygon.addClickListener(new LeafletClickListener() {

                            @Override
                            public void onClick(LeafletClickEvent event) {
                                Notification.show("That is " + name);
                            }
                        });
                    }
                }
            }
            Logger.getLogger(GeoJSONExample.class.getName()).severe("Reducing and creating layers " + (System.currentTimeMillis() - currentTimeMillis));
        } finally {
            iterator.close();
        }
    } catch (MalformedURLException ex) {
        Logger.getLogger(GeoJSONExample.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(GeoJSONExample.class.getName()).log(Level.SEVERE, null, ex);
    }
    leafletMap.zoomToContent();
    return leafletMap;
}
Also used : LeafletClickEvent(org.vaadin.addon.leaflet.LeafletClickEvent) MalformedURLException(java.net.MalformedURLException) LeafletLayer(org.vaadin.addon.leaflet.LeafletLayer) LeafletClickListener(org.vaadin.addon.leaflet.LeafletClickListener) IOException(java.io.IOException) Feature(org.opengis.feature.Feature) URL(java.net.URL) LPolygon(org.vaadin.addon.leaflet.LPolygon) FeatureIterator(org.geotools.feature.FeatureIterator) Geometry(com.vividsolutions.jts.geom.Geometry) FeatureJSON(org.geotools.geojson.feature.FeatureJSON) LMap(org.vaadin.addon.leaflet.LMap) FeatureCollection(org.geotools.feature.FeatureCollection)

Example 2 with LPolygon

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

Example 3 with LPolygon

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

the class PolygonWithHolesTest method getTestComponent.

public Component getTestComponent() {
    leafletMap = new LMap();
    // Not creating a name -> not added to the
    lfg = new LFeatureGroup();
    // overlay controller
    LPolygon polygon = new LPolygon();
    polygon.setPoints(new Point[] { new Point(0, 0), new Point(30, 30), new Point(30, 0) });
    polygon.setHoles(new Point[] { new Point(20, 20), new Point(25, 25), new Point(25, 20) });
    // non complete hole
    polygon.setHoles(new Point[] { new Point(5, 10), new Point(15, 15), new Point(15, 10) });
    polygon.setColor("green");
    lfg.addComponent(polygon);
    Polygon poly = getPolygon();
    Collection<LeafletLayer> lPoly = JTSUtil.toLayers(poly);
    lfg.addComponent(lPoly);
    leafletMap.setZoomLevel(5);
    leafletMap.addComponent(lfg);
    leafletMap.zoomToContent();
    return leafletMap;
}
Also used : LMap(org.vaadin.addon.leaflet.LMap) LFeatureGroup(org.vaadin.addon.leaflet.LFeatureGroup) LeafletLayer(org.vaadin.addon.leaflet.LeafletLayer) Point(org.vaadin.addon.leaflet.shared.Point) LPolygon(org.vaadin.addon.leaflet.LPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) LPolygon(org.vaadin.addon.leaflet.LPolygon)

Example 4 with LPolygon

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

the class VectorsWithNullPoints method getTestComponent.

public Component getTestComponent() {
    leafletMap = new LMap();
    LPolygon polygon = new LPolygon(new Point(0, 0), null, new Point(1, 1), new Point(2, 3), new Point(0, 0));
    polygon.sanitizeGeometry();
    LPolyline polyline = new LPolyline();
    LPolyline polylineWithNullPoint = new LPolyline(new Point(0, 0), null, new Point(1, 1), new Point(2, 3));
    polylineWithNullPoint.sanitizeGeometry();
    LMarker m = new LMarker(0, 0);
    leafletMap.setZoomLevel(0);
    leafletMap.addComponents(polygon, polyline, polylineWithNullPoint, m);
    leafletMap.zoomToContent();
    return leafletMap;
}
Also used : LMap(org.vaadin.addon.leaflet.LMap) LPolyline(org.vaadin.addon.leaflet.LPolyline) Point(org.vaadin.addon.leaflet.shared.Point) LMarker(org.vaadin.addon.leaflet.LMarker) LPolygon(org.vaadin.addon.leaflet.LPolygon)

Aggregations

LMap (org.vaadin.addon.leaflet.LMap)4 LPolygon (org.vaadin.addon.leaflet.LPolygon)4 Point (org.vaadin.addon.leaflet.shared.Point)3 LMarker (org.vaadin.addon.leaflet.LMarker)2 LeafletClickEvent (org.vaadin.addon.leaflet.LeafletClickEvent)2 LeafletClickListener (org.vaadin.addon.leaflet.LeafletClickListener)2 LeafletLayer (org.vaadin.addon.leaflet.LeafletLayer)2 Geometry (com.vividsolutions.jts.geom.Geometry)1 Polygon (com.vividsolutions.jts.geom.Polygon)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 FeatureCollection (org.geotools.feature.FeatureCollection)1 FeatureIterator (org.geotools.feature.FeatureIterator)1 FeatureJSON (org.geotools.geojson.feature.FeatureJSON)1 Feature (org.opengis.feature.Feature)1 LFeatureGroup (org.vaadin.addon.leaflet.LFeatureGroup)1 LOpenStreetMapLayer (org.vaadin.addon.leaflet.LOpenStreetMapLayer)1 LPolyline (org.vaadin.addon.leaflet.LPolyline)1 LeafletContextMenuEvent (org.vaadin.addon.leaflet.LeafletContextMenuEvent)1