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;
}
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);
}
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);
}
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;
}
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;
}
Aggregations