Skip to content

Commit

Permalink
Updated example to use a working data set
Browse files Browse the repository at this point in the history
  • Loading branch information
mstahv committed May 5, 2021
1 parent b87660a commit 4814c36
Showing 1 changed file with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.geotools.feature.FeatureCollection;
Expand All @@ -14,11 +15,9 @@
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.simplify.DouglasPeuckerSimplifier;
import org.opengis.feature.Feature;
import org.vaadin.addon.leaflet.LMap;
import org.vaadin.addon.leaflet.LPolygon;
import org.vaadin.addon.leaflet.LeafletClickEvent;
import org.vaadin.addon.leaflet.LeafletClickListener;
import org.vaadin.addon.leaflet.LeafletLayer;
import org.opengis.feature.GeometryAttribute;
import org.opengis.feature.type.GeometryType;
import org.vaadin.addon.leaflet.*;
import org.vaadin.addon.leaflet.util.JTSUtil;
import org.vaadin.addonhelpers.AbstractTest;

Expand Down Expand Up @@ -48,16 +47,14 @@ public Component getTestComponent() {
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());
FeatureCollection fc = io.readFeatureCollection(new URL("https://gist.githubusercontent.com/hrbrmstr/91ea5cc9474286c72838/raw/59421ff9b268ff0929b051ddafafbeb94a4c1910/continents.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)
Expand All @@ -70,15 +67,14 @@ public Component getTestComponent() {
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);
}
});
if (l instanceof LLayerGroup) {
LLayerGroup group = (LLayerGroup) l;
Iterator<Component> components = group.getComponentIterator();
while(components.hasNext()) {
LPolygon lPolygon = (LPolygon) components.next();
lPolygon.setStroke(false);
lPolygon.setFillColor("brown");
}
}
}
}
Expand Down

0 comments on commit 4814c36

Please sign in to comment.