Search in sources :

Example 1 with LMarker

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

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

the class MapInGridDetailsRow method getTestComponent.

@Override
public Component getTestComponent() {
    VerticalLayout vl = new VerticalLayout();
    vl.setSizeFull();
    final Grid<String> grid = new Grid<>();
    grid.setSizeFull();
    // Define some columns
    grid.addColumn(r -> r).setCaption("Name");
    grid.addColumn(r -> "").setCaption("Born");
    // Add some data rows
    grid.setItems("Nicolaus Copernicus", "Galileo Galilei", "Johannes Kepler");
    grid.setDetailsGenerator((DetailsGenerator<String>) s -> {
        final LMap leafletMap = new LMap();
        final LTileLayer baselayer = new LTileLayer();
        baselayer.setAttributionString("OpenStreetMap");
        baselayer.setUrl("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png");
        leafletMap.addLayer(baselayer);
        leafletMap.setWidth("100%");
        leafletMap.setHeight("100px");
        leafletMap.setZoomLevel(3);
        LMarker leafletMarker = new LMarker(-21.54, 30.76);
        leafletMap.addComponent(leafletMarker);
        leafletMap.zoomToContent();
        return leafletMap;
    });
    grid.addItemClickListener((ItemClickListener<String>) event -> grid.setDetailsVisible(event.getItem(), !grid.isDetailsVisible(event.getItem())));
    vl.addComponent(grid);
    return vl;
}
Also used : VerticalLayout(com.vaadin.ui.VerticalLayout) LMarker(org.vaadin.addon.leaflet.LMarker) LMap(org.vaadin.addon.leaflet.LMap) LTileLayer(org.vaadin.addon.leaflet.LTileLayer) AbstractTest(org.vaadin.addonhelpers.AbstractTest) DetailsGenerator(com.vaadin.ui.components.grid.DetailsGenerator) Component(com.vaadin.ui.Component) Grid(com.vaadin.ui.Grid) ItemClickListener(com.vaadin.ui.components.grid.ItemClickListener) LMap(org.vaadin.addon.leaflet.LMap) LTileLayer(org.vaadin.addon.leaflet.LTileLayer) Grid(com.vaadin.ui.Grid) VerticalLayout(com.vaadin.ui.VerticalLayout) LMarker(org.vaadin.addon.leaflet.LMarker)

Example 3 with LMarker

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

the class MarkerZIndexOffset method getTestComponent.

@Override
public Component getTestComponent() {
    LMap leafletMap = new LMap();
    leafletMap.setWidth("300px");
    leafletMap.setHeight("300px");
    leafletMap.setCenter(0, 0);
    leafletMap.setZoomLevel(2);
    final AtomicInteger currentBase = new AtomicInteger(1000);
    final LMarker m = new LMarker(5, 5);
    m.setId("5 5");
    final LMarker m2 = new LMarker(9, 9);
    m2.setZIndexOffset(currentBase.get());
    m2.setId("9 9");
    // m.setZIndexOffset(currentBase.getValue());
    final LMarker m3 = new LMarker(7, 7);
    leafletMap.addComponents(m, m2, m3);
    Button move = new Button("Move top right on top");
    move.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            m.setZIndexOffset(currentBase.get());
            currentBase.addAndGet(1000);
            m2.setZIndexOffset(currentBase.get());
        }
    });
    Button move2 = new Button("Move low left to top");
    move2.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            m2.setZIndexOffset(currentBase.get());
            currentBase.addAndGet(1000);
            m.setZIndexOffset(currentBase.get());
        }
    });
    return new VerticalLayout(leafletMap, move, move2);
}
Also used : LMap(org.vaadin.addon.leaflet.LMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Button(com.vaadin.ui.Button) VerticalLayout(com.vaadin.ui.VerticalLayout) LMarker(org.vaadin.addon.leaflet.LMarker)

Example 4 with LMarker

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

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

the class TextOnMap method getTestComponent.

@Override
public Component getTestComponent() {
    leafletMap = new LMap();
    leafletMap.addLayer(new LOpenStreetMapLayer());
    leafletMap.setCenter(0, 0);
    leafletMap.setZoomLevel(2);
    LMarker m = new LMarker(0, 0);
    // <- this becomes's to div icon's class names
    m.setStyleName("mycustomclassname");
    m.setDivIcon("Hello <strong>world</strong>!");
    // define the size for the html box
    m.setIconSize(new Point(80, 20));
    leafletMap.addLayer(m);
    return leafletMap;
}
Also used : LMap(org.vaadin.addon.leaflet.LMap) LOpenStreetMapLayer(org.vaadin.addon.leaflet.LOpenStreetMapLayer) Point(org.vaadin.addon.leaflet.shared.Point) LMarker(org.vaadin.addon.leaflet.LMarker)

Aggregations

LMarker (org.vaadin.addon.leaflet.LMarker)14 LMap (org.vaadin.addon.leaflet.LMap)12 Point (org.vaadin.addon.leaflet.shared.Point)8 VerticalLayout (com.vaadin.ui.VerticalLayout)6 LOpenStreetMapLayer (org.vaadin.addon.leaflet.LOpenStreetMapLayer)6 LeafletClickEvent (org.vaadin.addon.leaflet.LeafletClickEvent)4 LeafletClickListener (org.vaadin.addon.leaflet.LeafletClickListener)4 LPolyline (org.vaadin.addon.leaflet.LPolyline)3 ExternalResource (com.vaadin.server.ExternalResource)2 Button (com.vaadin.ui.Button)2 LPolygon (org.vaadin.addon.leaflet.LPolygon)2 LTileLayer (org.vaadin.addon.leaflet.LTileLayer)2 Bounds (org.vaadin.addon.leaflet.shared.Bounds)2 Control (org.vaadin.addon.leaflet.shared.Control)2 ClassResource (com.vaadin.server.ClassResource)1 Component (com.vaadin.ui.Component)1 Grid (com.vaadin.ui.Grid)1 DetailsGenerator (com.vaadin.ui.components.grid.DetailsGenerator)1 ItemClickListener (com.vaadin.ui.components.grid.ItemClickListener)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1