Search in sources :

Example 1 with Control

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

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

Example 3 with Control

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

the class BasicTest 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 = new LPolyline(new Point(60.45, 22.295), new Point(60.4555, 22.301), new Point(60.45, 22.307));
    leafletPolyline.setColor("#FF00FF");
    leafletPolyline.setFill(true);
    leafletPolyline.setFillColor("#00FF00");
    leafletPolyline.setClickable(false);
    leafletPolyline.setWeight(8);
    leafletPolyline.setOpacity(0.5);
    leafletPolyline.setDashArray("15, 10, 5, 10, 15");
    leafletPolyline.addClickListener(listener);
    leafletMap.addComponent(leafletPolyline);
    LPolygon leafletPolygon = new LPolygon(new Point(60.455, 22.300), new Point(60.456, 22.302), new Point(60.50, 22.308));
    leafletPolygon.setColor("#FF00FF");
    leafletPolygon.setFill(true);
    leafletPolygon.setFillColor("#00FF00");
    leafletPolygon.addClickListener(listener);
    leafletMap.addComponent(leafletPolygon);
    Bounds bounds = new Bounds(new Point(60.45, 22.295), new Point(60.4509, 22.300));
    LRectangle rect = new LRectangle(bounds);
    rect.addClickListener(listener);
    rect.setFillColor("yellow");
    leafletMap.addLayer(rect);
    LCircle leafletCircle = new LCircle(60.4525, 22.301, 300);
    leafletCircle.setColor("#00FFFF");
    // leafletCircle.addClickListener(listener);
    leafletMap.addComponent(leafletCircle);
    leafletCircle.addClickListener(listener);
    LCircleMarker leafletCircleMarker = new LCircleMarker(60.4525, 22.301, 5);
    leafletCircleMarker.setColor("#FFFF00");
    leafletMap.addComponent(leafletCircleMarker);
    leafletCircleMarker.addClickListener(listener);
    leafletMarker = new LMarker(60.4525, 22.301);
    leafletMarker.addClickListener(listener);
    leafletMarker.setTitle("this is marker two!");
    // leafletMarker
    // .setDivIcon("this is a <h1>fabulous</h1> <span style=\"color:red\">icon</span>");
    leafletMarker.setPopup("Hello <b>world</b>");
    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);
    leafletMarker.setTitle("this is marker one!");
    leafletMarker.setPopup("Hello <b>Vaadin World</b>!");
    leafletMarker.setPopupAnchor(new Point(-28, -26));
    leafletMap.addComponent(leafletMarker);
    leafletMap.setAttributionPrefix("Powered by Leaflet with v-leaflet");
    LPolyline roadOverlay = new LPolyline(new Point(61.42, 21.245), new Point(60.4655, 22.321), new Point(60.45, 22.307));
    leafletMap.addOverlay(roadOverlay, "Road overlay");
    LMarker point1 = new LMarker(61.441, 21.2442);
    LMarker point2 = new LMarker(61.445, 21.2441);
    LMarker point3 = new LMarker(61.447, 21.2445);
    LLayerGroup layerGroup = new LLayerGroup(point1, point2, point3);
    leafletMap.addOverlay(layerGroup, "Points overlay");
    leafletMap.addBaseLayer(new LOpenStreetMapLayer(), "CloudMade");
    // This will make everything sharper on "retina devices", but also text
    // quite small
    // baselayer.setDetectRetina(true);
    LTileLayer pk = new LTileLayer();
    pk.setUrl("https://{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.addBaseLayerChangeListener(new LeafletBaseLayerChangeListener() {

        @Override
        public void onBaseLayerChange(LeafletBaseLayerChangeEvent event) {
            Notification.show(event.getName() + " base layer was activated!");
        }
    });
    leafletMap.addOverlayAddListener(new LeafletOverlayAddListener() {

        @Override
        public void onOverlayAdd(LeafletOverlayAddEvent event) {
            Notification.show(event.getName() + " overlay was added!");
        }
    });
    leafletMap.addOverlayRemoveListener(new LeafletOverlayRemoveListener() {

        @Override
        public void onOverlayRemove(LeafletOverlayRemoveEvent event) {
            Notification.show(event.getName() + " overlay was removed!");
        }
    });
    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) Bounds(org.vaadin.addon.leaflet.shared.Bounds) Point(org.vaadin.addon.leaflet.shared.Point) Control(org.vaadin.addon.leaflet.shared.Control)

Aggregations

Bounds (org.vaadin.addon.leaflet.shared.Bounds)3 Control (org.vaadin.addon.leaflet.shared.Control)3 Point (org.vaadin.addon.leaflet.shared.Point)3 ClassResource (com.vaadin.server.ClassResource)2 LMap (org.vaadin.addon.leaflet.LMap)2 LMarker (org.vaadin.addon.leaflet.LMarker)2 LOpenStreetMapLayer (org.vaadin.addon.leaflet.LOpenStreetMapLayer)2 VerticalLayout (com.vaadin.ui.VerticalLayout)1 LCircle (org.vaadin.addon.leaflet.LCircle)1 LLayerGroup (org.vaadin.addon.leaflet.LLayerGroup)1 LPolyline (org.vaadin.addon.leaflet.LPolyline)1 LeafletMoveEndEvent (org.vaadin.addon.leaflet.LeafletMoveEndEvent)1 LeafletMoveEndListener (org.vaadin.addon.leaflet.LeafletMoveEndListener)1