changeset 806:e50da1f74e58

The layers created in the floodmap reflect to the facets this output mode has. flys-client/trunk@2374 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 20 Jul 2011 13:31:20 +0000
parents f43d06d6a4a2
children 6f65e70fa11d
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.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/MapThemePanel.java
diffstat 4 files changed, 155 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Jul 20 07:52:19 2011 +0000
+++ b/flys-client/ChangeLog	Wed Jul 20 13:31:20 2011 +0000
@@ -1,3 +1,21 @@
+2011-07-20  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java: The
+	  vector layer which is used to save features created by the user acts as
+	  OpenLayers base layer. I decided to do so, because this is the first
+	  and only layer that will always exist in our maps. Users aren't able to
+	  remove it!
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/MapThemePanel.java:
+	  Added a callback interface that allows the MapOutputTab to react on
+	  modifications in the ThemePanel. This special callback is used to
+	  activate/deactivate layers.
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java:
+	  Now, the layers in the map reflect the facets of the map output. Each
+	  layer's extent is analyzed and finally the map is zoomed to the minimal
+	  extent that contains all layers.
+
 2011-07-20  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/chart/ThemeNavigationPanel.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java	Wed Jul 20 07:52:19 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java	Wed Jul 20 13:31:20 2011 +0000
@@ -25,6 +25,8 @@
 
         mapWidget = new MapWidget("510px", "635px", opts);
         map       = mapWidget.getMap();
+
+        getBarrierLayer();
     }
 
 
@@ -46,6 +48,7 @@
     public Vector getBarrierLayer() {
         if (barrierLayer == null) {
             barrierLayer = new Vector(LAYER_BARRIERS);
+            barrierLayer.setIsBaseLayer(true);
             map.addLayer(barrierLayer);
         }
 
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java	Wed Jul 20 07:52:19 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java	Wed Jul 20 13:31:20 2011 +0000
@@ -1,5 +1,6 @@
 package de.intevation.flys.client.client.ui.map;
 
+import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.ui.HorizontalPanel;
 import com.google.gwt.user.client.ui.Widget;
 
@@ -11,25 +12,29 @@
 
 import org.gwtopenmaps.openlayers.client.Bounds;
 import org.gwtopenmaps.openlayers.client.LonLat;
+import org.gwtopenmaps.openlayers.client.Map;
+import org.gwtopenmaps.openlayers.client.layer.Layer;
 import org.gwtopenmaps.openlayers.client.layer.WMS;
 import org.gwtopenmaps.openlayers.client.layer.WMSParams;
 
-
+import de.intevation.flys.client.shared.model.AttributedTheme;
 import de.intevation.flys.client.shared.model.Collection;
+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.ui.CollectionView;
 import de.intevation.flys.client.client.ui.OutputTab;
-import de.intevation.flys.client.client.ui.chart.ChartThemePanel;
+import de.intevation.flys.client.client.ui.ThemePanel;
 
 
 public class MapOutputTab extends OutputTab {
 
     protected CollectionView parent;
 
-    protected Canvas controlPanel;
-    protected Canvas themePanel;
-    protected Widget mapPanel;
+    protected Canvas     controlPanel;
+    protected ThemePanel themePanel;
+    protected Widget     mapPanel;
 
     protected FloodMap floodMap;
 
@@ -61,8 +66,8 @@
         wrapper.setHeight100();
 
         controlPanel = createControlPanel(wrapper);
-        themePanel   = createThemePanel();
         mapPanel     = floodMap.getMapWidget();
+        Canvas themePanelWrapper = createThemePanel();
 
         final HorizontalPanel layout = new HorizontalPanel();
         layout.setWidth("99%");
@@ -76,7 +81,7 @@
         hlayout.setWidth100();
         hlayout.setMembersMargin(2);
 
-        hlayout.addMember(themePanel);
+        hlayout.addMember(themePanelWrapper);
         hlayout.addMember(wrapper);
 
         rootLayout.addMember(controlPanel);
@@ -102,23 +107,99 @@
 
 
     protected void initLayers() {
-        // TODO Initialize correct layers here
+        ThemeList themeList = themePanel.getThemeList();
 
-        String url    = "http://vmap0.tiles.osgeo.org/wms/vmap0";
-        String layers = "basic";
+        int num = themeList.getThemeCount();
+
+        Map    map    = floodMap.getMap();
+        Bounds extent = null;
+
+        for (int i = 1; i <= num; i++) {
+            Theme theme = themeList.getThemeAt(i);
+            Layer layer = createWMSLayer(theme);
+
+            if (layer == null) {
+                continue;
+            }
+
+            map.addLayer(layer);
+
+            AttributedTheme at = (AttributedTheme) theme;
+            String tmp         = at.getAttr("extent");
+
+            if (theme.getActive() == 1) {
+                if (extent == null) {
+                    extent = boundsFromString(tmp);
+                }
+                else {
+                    Bounds b = boundsFromString(tmp);
+
+                    if (b != null) {
+                        extent.extend(b);
+                    }
+                }
+            }
+        }
+
+        map.zoomToExtent(extent != null
+            ? extent
+            : new Bounds(-90, -180, 90, 180));
+    }
+
+
+    protected Bounds boundsFromString(String bounds) {
+        if (bounds == null || bounds.length() == 0) {
+            return null;
+        }
+
+        String[] values = bounds.split(" ");
+
+        if (values == null || values.length < 4) {
+            return null;
+        }
+
+        try {
+            return new Bounds(
+                Double.valueOf(values[0]),
+                Double.valueOf(values[3]),
+                Double.valueOf(values[2]),
+                Double.valueOf(values[1]));
+        }
+        catch (NumberFormatException nfe) {}
+
+        return null;
+    }
+
+
+    protected Layer createWMSLayer(Theme theme) {
+        if (theme == null) {
+            return null;
+        }
+
+        AttributedTheme at = (AttributedTheme) theme;
+
+        String type   = at.getAttr("name");
+        String desc   = at.getAttr("description");
+        String url    = at.getAttr("url");
+        String layers = at.getAttr("layers");
+
+        if (url == null || layers == null) {
+            return null;
+        }
+
+        //boolean baseLayer = type.equals("floodmap.wmsbackground");
 
         WMSParams params = new WMSParams();
         params.setLayers(layers);
         params.setFormat("image/png");
-        params.setIsTransparent(false);
+        params.setIsTransparent(true);
         params.setMaxExtent(new Bounds(90, 180, -90, -180));
 
-        WMS wms = new WMS("vmap0", url, params);
-        wms.setIsBaseLayer(true);
-        wms.setIsVisible(true);
+        WMS wms = new WMS(desc, url, params);
+        wms.setIsVisible(at.getActive() == 1);
+        wms.setIsBaseLayer(false);
 
-        floodMap.getMap().addLayer(wms);
-        floodMap.getMap().setCenter(new LonLat(0, 0));
+        return wms;
     }
 
 
@@ -133,10 +214,25 @@
         c.setHeight100();
         c.setBorder("1px solid black");
 
-        ChartThemePanel ctp = new ChartThemePanel(collection, mode);
-        c.addChild(ctp);
+        themePanel = new MapThemePanel(
+            collection, mode, new MapThemePanel.ActivateCallback() {
+                public void activate(Theme theme, boolean active) {
+                    activateTheme(theme, active);
+                }
+            });
+        c.addChild(themePanel);
 
         return c;
     }
+
+
+    protected void activateTheme(Theme theme, boolean active) {
+        String name = theme.getDescription();
+        Layer layer = floodMap.getMap().getLayerByName(name);
+
+        if (layer != null) {
+            layer.setIsVisible(active);
+        }
+    }
 }
 // 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/MapThemePanel.java	Wed Jul 20 07:52:19 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapThemePanel.java	Wed Jul 20 13:31:20 2011 +0000
@@ -19,9 +19,18 @@
  */
 public class MapThemePanel extends ThemePanel {
 
+    public interface ActivateCallback {
+        void activate(Theme theme, boolean activate);
+    }
+
+
+
     private FLYSConstants MSG = GWT.create(FLYSConstants.class);
 
 
+    protected ActivateCallback activateCallback;
+
+
     public static final String GRID_FIELD_ACTIVE = "active";
     public static final String GRID_FIELD_NAME   = "name";
 
@@ -29,9 +38,15 @@
     protected MapOutputTab mapOut;
 
 
-    public MapThemePanel(Collection collection, OutputMode mode) {
+    public MapThemePanel(
+        Collection       collection,
+        OutputMode       mode,
+        ActivateCallback activateCallback)
+    {
         super(collection, mode);
 
+        this.activateCallback = activateCallback;
+
         initGrid();
         initLayout();
 
@@ -79,6 +94,10 @@
 
     @Override
     public void activateTheme(Theme theme, boolean active) {
+        if (activateCallback != null) {
+            activateCallback.activate(theme, active);
+        }
+
         theme.setActive(active ? 1 : 0);
     }
 }

http://dive4elements.wald.intevation.org