diff flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java @ 1382:78542ff1f562

Update map and theme panel when new layers are added via datacage or removed by context menu. flys-client/trunk@3155 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 03 Nov 2011 14:51:16 +0000
parents b0fe35d4ce6b
children 9aa1a453eed5
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java	Tue Nov 01 16:07:39 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java	Thu Nov 03 14:51:16 2011 +0000
@@ -102,7 +102,6 @@
                     setFloodmap(new FloodMap(c.getSrid(), max));
 
                     initLayout();
-                    initLayers();
                     initBarriers();
 
                     GWT.log("MAX EXTENT: " + max);
@@ -165,25 +164,6 @@
     }
 
 
-    protected void initLayers() {
-        ThemeList themeList = themePanel.getThemeList();
-
-        int num = themeList.getThemeCount();
-        Map map = floodMap.getMap();
-
-        for (int i = num; i >= 0; i--) {
-            Theme theme = themeList.getThemeAt(i);
-            Layer layer = createWMSLayer(theme);
-
-            if (layer == null) {
-                continue;
-            }
-
-            map.addLayer(layer);
-        }
-    }
-
-
     protected void initBarriers() {
         Vector vector = floodMap.getBarrierLayer();
         vector.addVectorFeatureAddedListener(
@@ -226,10 +206,40 @@
     }
 
 
+    public void addLayer(Layer layer) {
+        Map map = getMap();
+
+        if (map != null) {
+            GWT.log("Add new layer '" + layer.getName() + "' to map.");
+            map.addLayer(layer);
+        }
+    }
+
+
+    public void removeLayer(String name) {
+        Map map = getMap();
+
+        Layer[] layers = map.getLayers();
+
+        for (Layer layer: layers) {
+            if (name.equals(layer.getName())) {
+                map.removeLayer(layer);
+            }
+        }
+    }
+
+
     @Override
     public void onRedrawRequest(RedrawRequestEvent event) {
-        // TODO FILL ME
-        GWT.log("TODO: Request redraw.");
+        mapService.doOut(collection, new AsyncCallback<MapConfig>() {
+            public void onFailure(Throwable caught) {
+                GWT.log("MAP ERROR: " + caught.getMessage());
+            }
+
+            public void onSuccess(MapConfig c) {
+                themePanel.updateCollection();
+            }
+        });
     }
 
 
@@ -243,6 +253,11 @@
     }
 
 
+    protected ThemePanel getThemePanel() {
+        return themePanel;
+    }
+
+
     protected String getGeoJSONFromDynamic(ArtifactDescription desc) {
         DataList list = desc.getCurrentData();
 
@@ -327,7 +342,7 @@
     }
 
 
-    protected Layer createWMSLayer(Theme theme) {
+    public Layer createWMSLayer(Theme theme) {
         if (theme == null) {
             return null;
         }
@@ -379,6 +394,7 @@
         themePanel = new MapThemePanel(
             collection,
             mode,
+            this,
             new MapThemePanel.ActivateCallback() {
                 public void activate(Theme theme, boolean active) {
                     activateTheme(theme, active);
@@ -425,6 +441,8 @@
         String name = theme.getDescription();
         Layer layer = floodMap.getMap().getLayerByName(name);
 
+        GWT.log("Set visibility of '" + name + "': " + active);
+
         if (layer != null) {
             layer.setIsVisible(active);
         }

http://dive4elements.wald.intevation.org