Search in sources :

Example 1 with LeafletClickListener

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

the class ChoroplethExample method configureFeature.

protected void configureFeature(LeafletLayer l, final Double density, final String name) {
    AbstractLeafletVector lPolygon = (AbstractLeafletVector) l;
    lPolygon.setFillColor(getColor(density));
    lPolygon.setColor("white");
    lPolygon.setDashArray("3");
    lPolygon.setWeight(2);
    lPolygon.setFillOpacity(0.7);
    lPolygon.addClickListener(new LeafletClickListener() {

        @Override
        public void onClick(LeafletClickEvent event) {
            // Any server side data access is easy to do here, could for
            // example do a DB query and show more detailed data for the
            // selected feature
            Notification.show("In " + name + ", the population is " + density + "people/mileĀ²");
        }
    });
    lPolygon.setLineCap("");
}
Also used : LeafletClickEvent(org.vaadin.addon.leaflet.LeafletClickEvent) LeafletClickListener(org.vaadin.addon.leaflet.LeafletClickListener) AbstractLeafletVector(org.vaadin.addon.leaflet.AbstractLeafletVector)

Example 2 with LeafletClickListener

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

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

the class SimpleMarkerTest method getTestComponent.

@Override
public Component getTestComponent() {
    leafletMap = new LMap();
    LTileLayer pk = new LTileLayer();
    pk.setUrl("http://{s}.kartat.kapsi.fi/peruskartta/{z}/{x}/{y}.png");
    pk.setAttributionString("Maanmittauslaitos, hosted by kartat.kapsi.fi");
    pk.setMaxZoom(18);
    pk.setSubDomains("tile2");
    pk.setDetectRetina(true);
    leafletMap.addBaseLayer(pk, "Peruskartta");
    leafletMap.setCenter(60.4525, 22.301);
    leafletMap.setZoomLevel(15);
    lMarker = new LMarker(60.4525, 22.301);
    lMarker.addStyleName("specialstyle");
    lMarker.setIcon(new ExternalResource("http://leafletjs.com/examples/custom-icons/leaf-red.png"));
    lMarker.setIconAnchor(new Point(22, 94));
    lMarker.setPopup("Popupstring");
    leafletMap.addComponent(lMarker);
    lMarker.openPopup();
    LMarker another = new LMarker(60.4525, 22.303);
    another.addClickListener(new LeafletClickListener() {

        @Override
        public void onClick(LeafletClickEvent event) {
            Notification.show("Another marker was clicke.");
        }
    });
    leafletMap.addComponent(another);
    return leafletMap;
}
Also used : LeafletClickEvent(org.vaadin.addon.leaflet.LeafletClickEvent) LMap(org.vaadin.addon.leaflet.LMap) LTileLayer(org.vaadin.addon.leaflet.LTileLayer) LeafletClickListener(org.vaadin.addon.leaflet.LeafletClickListener) Point(org.vaadin.addon.leaflet.shared.Point) LMarker(org.vaadin.addon.leaflet.LMarker) ExternalResource(com.vaadin.server.ExternalResource)

Example 4 with LeafletClickListener

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

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

the class FontawesomeMarkerAndSVGInMarker method getTestComponent.

@Override
public Component getTestComponent() {
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSizeFull();
    // Getting my map.
    LMap map = new LMap();
    map.addComponent(new LOpenStreetMapLayer());
    LMarker lMarker = new LMarker(61, 22);
    lMarker.setIcon(FontAwesome.BEER);
    lMarker.setPopup("FontAwesome marker popup with anchor beer");
    lMarker.setPopupAnchor(new Point(0, -45));
    lMarker.addStyleName("beer");
    map.addComponent(lMarker);
    LCircleMarker lCircleMarker = new LCircleMarker(61, 22, 2);
    map.addComponent(lCircleMarker);
    getPage().getStyles().add(".v-leaflet-custom-svg circle {stroke: blue;}");
    LMarker lMarker2 = new LMarker(62, 23);
    String svgCode = "<svg width=\"100\" height=\"100\">\n" + "  <circle cx=\"50\" cy=\"50\" r=\"40\" stroke-width=\"4\" fill=\"yellow\" />\n" + "</svg>";
    lMarker2.setIconSize(new Point(100, 100));
    lMarker2.setIconAnchor(new Point(50, 50));
    lMarker2.setPopup("Custom svg popup with anchor");
    lMarker2.setPopupAnchor(new Point(0, -40));
    lMarker2.addStyleName("v-leaflet-custom-svg");
    lMarker2.setDivIcon(svgCode);
    lMarker2.addClickListener(new LeafletClickListener() {

        @Override
        public void onClick(LeafletClickEvent event) {
            Notification.show("Clicked " + event.getPoint().toString());
        }
    });
    map.addComponent(lMarker2);
    LCircleMarker lCircleMarker2 = new LCircleMarker(62, 23, 2);
    map.addComponent(lCircleMarker2);
    LMarker lMarker3 = new LMarker(60.1698560, 24.9383790);
    lMarker3.setIcon(FontAwesome.GOOGLE);
    lMarker3.setIconTextFill("#F00");
    lMarker3.setIconPathFill("#666");
    lMarker3.setIconPathStroke("#000");
    lMarker3.setPopup("Configurable FontAwesome marker popup with anchor");
    lMarker3.setPopupAnchor(new Point(0, -45));
    map.addComponent(lMarker3);
    LMarker svgDataUrlMarker = new LMarker(62, 24);
    // Note that styling is not easy this way as css don't hook into images
    svgDataUrlMarker.addStyleName("red");
    svgDataUrlMarker.setIcon(new ExternalResource("data:image/svg+xml;utf8," + svgMarker.replace("FILLCOLOR", "red")));
    svgDataUrlMarker.setIconSize(new Point(50, 50));
    svgDataUrlMarker.setIconAnchor(new Point(25, 50));
    map.addComponent(svgDataUrlMarker);
    map.zoomToContent();
    layout.addComponent(map);
    return layout;
}
Also used : LeafletClickEvent(org.vaadin.addon.leaflet.LeafletClickEvent) LMap(org.vaadin.addon.leaflet.LMap) LCircleMarker(org.vaadin.addon.leaflet.LCircleMarker) LOpenStreetMapLayer(org.vaadin.addon.leaflet.LOpenStreetMapLayer) VerticalLayout(com.vaadin.ui.VerticalLayout) LeafletClickListener(org.vaadin.addon.leaflet.LeafletClickListener) Point(org.vaadin.addon.leaflet.shared.Point) LMarker(org.vaadin.addon.leaflet.LMarker) ExternalResource(com.vaadin.server.ExternalResource)

Aggregations

LeafletClickEvent (org.vaadin.addon.leaflet.LeafletClickEvent)6 LeafletClickListener (org.vaadin.addon.leaflet.LeafletClickListener)6 LMap (org.vaadin.addon.leaflet.LMap)5 LMarker (org.vaadin.addon.leaflet.LMarker)4 Point (org.vaadin.addon.leaflet.shared.Point)4 ExternalResource (com.vaadin.server.ExternalResource)2 LOpenStreetMapLayer (org.vaadin.addon.leaflet.LOpenStreetMapLayer)2 LPolygon (org.vaadin.addon.leaflet.LPolygon)2 VerticalLayout (com.vaadin.ui.VerticalLayout)1 Geometry (com.vividsolutions.jts.geom.Geometry)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 AbstractLeafletVector (org.vaadin.addon.leaflet.AbstractLeafletVector)1 LCircleMarker (org.vaadin.addon.leaflet.LCircleMarker)1 LPolyline (org.vaadin.addon.leaflet.LPolyline)1