use of org.vaadin.addon.leaflet.LMap 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.LMap in project v-leaflet by mstahv.
the class CustomProjection method getTestComponent.
@Override
public Component getTestComponent() {
LMap leafletMap = new LMap();
LWmsLayer lWmsLayer = new LWmsLayer();
lWmsLayer.setUrl("http://osm.omniscale.net/proxy/service");
lWmsLayer.setLayers("osm");
lWmsLayer.setFormat("image/png");
// Toggle this line to see if WMS layer is requested with differen
// CRS
lWmsLayer.setCrs(Crs.EPSG4326);
leafletMap.addLayer(lWmsLayer);
leafletMap.setCenter(52.51739, 13.40209);
leafletMap.setZoomLevel(14);
return leafletMap;
}
use of org.vaadin.addon.leaflet.LMap 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.LMap 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.LMap 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;
}
Aggregations