changeset 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 3fe265b47675
children 2f65c742803f
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java
diffstat 4 files changed, 152 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Mon Aug 22 10:46:49 2011 +0000
+++ b/flys-client/ChangeLog	Mon Aug 22 13:29:55 2011 +0000
@@ -1,3 +1,18 @@
+2011-08-22  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/CollectionView.java:
+	  Set the Collection and its Master-Artifact at first when we create a
+	  CollectionView with an existing Collection instance.
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java:
+	  Enabled the SelectFeature control to select a feature using a box.
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java:
+	  The geometries added by the user are saved as GeoJSON parameters of the
+	  master artifact . The user does not need to save the geometries
+	  explicitly - this is an automatic process. While initializing the map,
+	  those geometries are reloaded and displayed again.
+
 2011-08-22  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/NoInputPanel.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java	Mon Aug 22 10:46:49 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java	Mon Aug 22 13:29:55 2011 +0000
@@ -144,6 +144,8 @@
 
     public CollectionView(FLYS flys, Collection collection, Artifact artifact) {
         this.flys          = flys;
+        this.artifact      = artifact;
+        this.collection    = collection;
         this.tabs          = new TabSet();
         this.outputTabs    = new HashMap<String, OutputTab>();
         this.handlers      = new ArrayList<CollectionChangeHandler>();
--- 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 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java	Mon Aug 22 10:46:49 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java	Mon Aug 22 13:29:55 2011 +0000
@@ -282,6 +282,7 @@
 
     protected ImgButton createSelectFeatureControl() {
         SelectFeatureOptions opts = new SelectFeatureOptions();
+        opts.setBox(true);
 
         // VectorFeatures selected by the SelectFeature control are manually
         // marked with the string "mark.delete". The control to remove selected

http://dive4elements.wald.intevation.org