Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java @ 825:1b9b7e9ab219
Save and reload user defined geometries (barriers) in the map.
flys-client/trunk@2522 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 22 Aug 2011 13:29:55 +0000 |
parents | 407de0f4b66a |
children | c89a42950d11 |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java Mon Aug 22 10:46:49 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java Mon Aug 22 13:29:55 2011 +0000 @@ -1,6 +1,9 @@ package de.intevation.flys.client.client.ui.map; +import java.util.List; + import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.Widget; @@ -12,17 +15,34 @@ import org.gwtopenmaps.openlayers.client.Bounds; import org.gwtopenmaps.openlayers.client.Map; +import org.gwtopenmaps.openlayers.client.event.VectorFeatureAddedListener; +import org.gwtopenmaps.openlayers.client.event.VectorFeatureAddedListener.FeatureAddedEvent; +import org.gwtopenmaps.openlayers.client.event.VectorFeatureRemovedListener; +import org.gwtopenmaps.openlayers.client.event.VectorFeatureRemovedListener.FeatureRemovedEvent; +import org.gwtopenmaps.openlayers.client.feature.VectorFeature; +import org.gwtopenmaps.openlayers.client.format.GeoJSON; import org.gwtopenmaps.openlayers.client.layer.Layer; +import org.gwtopenmaps.openlayers.client.layer.Vector; import org.gwtopenmaps.openlayers.client.layer.WMS; import org.gwtopenmaps.openlayers.client.layer.WMSParams; import org.gwtopenmaps.openlayers.client.layer.WMSOptions; +import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.ArtifactDescription; import de.intevation.flys.client.shared.model.AttributedTheme; import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; import de.intevation.flys.client.shared.model.Theme; import de.intevation.flys.client.shared.model.ThemeList; import de.intevation.flys.client.shared.model.OutputMode; +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.services.StepForwardService; +import de.intevation.flys.client.client.services.StepForwardServiceAsync; import de.intevation.flys.client.client.ui.CollectionView; import de.intevation.flys.client.client.ui.OutputTab; import de.intevation.flys.client.client.ui.ThemePanel; @@ -32,10 +52,15 @@ public static final String DEFAULT_SRID = "4326"; + public static final String BARRIERS_PARAMETER_KEY = "uesk.barriers"; + + + protected StepForwardServiceAsync feedService = + GWT.create(StepForwardService.class); protected CollectionView parent; - protected Canvas controlPanel; + protected MapToolbar controlPanel; protected ThemePanel themePanel; protected Widget mapPanel; @@ -55,6 +80,7 @@ initLayout(); initLayers(); + initBarriers(); } @@ -152,6 +178,80 @@ } + protected void initBarriers() { + Vector vector = floodMap.getBarrierLayer(); + vector.addVectorFeatureAddedListener( + new VectorFeatureAddedListener() { + public void onFeatureAdded(FeatureAddedEvent e) { + saveBarriers(); + } + } + ); + + vector.addVectorFeatureRemovedListener( + new VectorFeatureRemovedListener() { + public void onFeatureRemoved(FeatureRemovedEvent e) { + saveBarriers(); + } + } + ); + + + Artifact artifact = getArtifact(); + + if (artifact == null) { + return; + } + + ArtifactDescription desc = artifact.getArtifactDescription(); + + String geojson = getGeoJSONFromStatic(desc); + geojson = geojson != null ? geojson : getGeoJSONFromDynamic(desc); + + if (geojson == null || geojson.length() == 0) { + GWT.log("No geojson string found -> no barriers existing."); + return; + } + + GeoJSON reader = new GeoJSON(); + VectorFeature[] features = reader.read(geojson); + + vector.addFeatures(features); + } + + + protected String getGeoJSONFromDynamic(ArtifactDescription desc) { + DataList list = desc.getCurrentData(); + + List<Data> datas = list.getAll(); + for (Data data: datas) { + String key = data.getLabel(); + + if (key != null && key.equals(BARRIERS_PARAMETER_KEY)) { + DataItem def = data.getDefault(); + + if (def != null) { + return def.getStringValue(); + } + } + } + + return null; + } + + + protected String getGeoJSONFromStatic(ArtifactDescription desc) { + // TODO Implement this method, if there are reachable states right after + // the floodmap state - which is currently not the case. + return null; + } + + + public Artifact getArtifact() { + return parent.getArtifact(); + } + + public ThemeList getThemeList() { return collection.getThemeList(mode.getName()); } @@ -264,7 +364,7 @@ } - protected Canvas createControlPanel(Canvas wrapper) { + protected MapToolbar createControlPanel(Canvas wrapper) { return new MapToolbar(floodMap, wrapper); } @@ -295,5 +395,37 @@ layer.setIsVisible(active); } } + + + protected void saveBarriers() { + Vector layer = floodMap.getBarrierLayer(); + + GeoJSON format = new GeoJSON(); + String features = format.write(layer.getFeatures()); + + DataItem item = new DefaultDataItem( + BARRIERS_PARAMETER_KEY, BARRIERS_PARAMETER_KEY, features); + + Data data = new DefaultData( + BARRIERS_PARAMETER_KEY, BARRIERS_PARAMETER_KEY, "String", + new DataItem[] {item} ); + + Config config = Config.getInstance(); + final String url = config.getServerUrl(); + final String locale = config.getLocale(); + + feedService.go(url, locale, getArtifact(), new Data[] { data }, + new AsyncCallback<Artifact>() { + public void onFailure(Throwable caught) { + GWT.log("Could not save barrier geometries: " + + caught.getMessage()); + } + + public void onSuccess(Artifact artifact) { + GWT.log("Successfully saved barrier geometries."); + } + } + ); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :