use of org.vaadin.addon.leaflet.LPolygon 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;
}
use of org.vaadin.addon.leaflet.LPolygon 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;
}
use of org.vaadin.addon.leaflet.LPolygon in project v-leaflet by mstahv.
the class PolygonWithHolesTest method getTestComponent.
public Component getTestComponent() {
leafletMap = new LMap();
// Not creating a name -> not added to the
lfg = new LFeatureGroup();
// overlay controller
LPolygon polygon = new LPolygon();
polygon.setPoints(new Point[] { new Point(0, 0), new Point(30, 30), new Point(30, 0) });
polygon.setHoles(new Point[] { new Point(20, 20), new Point(25, 25), new Point(25, 20) });
// non complete hole
polygon.setHoles(new Point[] { new Point(5, 10), new Point(15, 15), new Point(15, 10) });
polygon.setColor("green");
lfg.addComponent(polygon);
Polygon poly = getPolygon();
Collection<LeafletLayer> lPoly = JTSUtil.toLayers(poly);
lfg.addComponent(lPoly);
leafletMap.setZoomLevel(5);
leafletMap.addComponent(lfg);
leafletMap.zoomToContent();
return leafletMap;
}
use of org.vaadin.addon.leaflet.LPolygon in project v-leaflet by mstahv.
the class VectorsWithNullPoints method getTestComponent.
public Component getTestComponent() {
leafletMap = new LMap();
LPolygon polygon = new LPolygon(new Point(0, 0), null, new Point(1, 1), new Point(2, 3), new Point(0, 0));
polygon.sanitizeGeometry();
LPolyline polyline = new LPolyline();
LPolyline polylineWithNullPoint = new LPolyline(new Point(0, 0), null, new Point(1, 1), new Point(2, 3));
polylineWithNullPoint.sanitizeGeometry();
LMarker m = new LMarker(0, 0);
leafletMap.setZoomLevel(0);
leafletMap.addComponents(polygon, polyline, polylineWithNullPoint, m);
leafletMap.zoomToContent();
return leafletMap;
}
Aggregations