[Dive4elements-commits] [PATCH 1 of 2] Added a new control 'show legend' to the map's toolbar. This control opens a window that displays the legends of all activated layers

Wald Commits scm-commit at wald.intevation.org
Tue Oct 30 15:35:25 CET 2012


# HG changeset patch
# User Ingo Weinzierl <ingo.weinzierl at intevation.de>
# Date 1351595786 -3600
# Node ID c9dcce9448f24e8a5a6291071d1b5a9c367df2a5
# Parent  25157125f4a0bee1cc10c06161c6831966e478c1
Added a new control 'show legend' to the map's toolbar. This control opens a window that displays the legends of all activated layers.
Currently, the row in that window has a fixed size of 400x150. The size is fixed, because there are problems with SmartGWT to build
panels with auto height/width :-/

diff -r 25157125f4a0 -r c9dcce9448f2 flys-client/src/main/java/de/intevation/flys/client/client/ui/map/LegendWindow.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/LegendWindow.java	Tue Oct 30 12:16:26 2012 +0100
@@ -0,0 +1,100 @@
+package de.intevation.flys.client.client.ui.map;
+
+import java.util.List;
+
+import com.smartgwt.client.types.ImageStyle;
+import com.smartgwt.client.types.VerticalAlignment;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Img;
+import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.Window;
+import com.smartgwt.client.widgets.layout.HLayout;
+import com.smartgwt.client.widgets.layout.VLayout;
+
+import de.intevation.flys.client.shared.MapUtils;
+import de.intevation.flys.client.shared.model.AttributedTheme;
+import de.intevation.flys.client.shared.model.Theme;
+import de.intevation.flys.client.shared.model.ThemeList;
+
+
+public class LegendWindow extends Window {
+
+    private ThemeList themeList;
+
+    private VLayout legendContainer;
+
+    public LegendWindow(ThemeList themeList) {
+        this.themeList = themeList;
+        this.legendContainer = new VLayout();
+
+        init();
+    }
+
+    public void update(ThemeList themeList) {
+        this.themeList = themeList;
+
+        Canvas[] legends = legendContainer.getMembers();
+        legendContainer.removeMembers(legends);
+
+        addLegends();
+    }
+
+    private void addLegends() {
+        List<Theme> themes = themeList.getActiveThemes();
+
+        for (Theme theme : themes) {
+            if (theme.getActive() == 0) {
+                continue;
+            }
+
+            if (theme instanceof AttributedTheme) {
+                legendContainer
+                    .addMember(createLegendGraphicsRow((AttributedTheme) theme));
+            }
+        }
+    }
+
+    private Canvas createLegendGraphicsRow(AttributedTheme at) {
+        Label label = new Label(at.getDescription());
+        Img img = createLegendGraphics(at);
+
+        HLayout row = new HLayout();
+        row.addMember(label);
+        row.addMember(img);
+
+        row.setHeight(150);
+        row.setWidth(400);
+
+        return row;
+    }
+
+    private Img createLegendGraphics(AttributedTheme at) {
+        String imgUrl = MapUtils.getLegendGraphicUrl(at.getAttr("url"),
+            at.getAttr("layers"));
+
+        Img img = new Img(imgUrl);
+        img.setImageType(ImageStyle.CENTER);
+        img.setAutoFit(true);
+
+        return img;
+    }
+
+    private void init() {
+        legendContainer.setAutoHeight();
+        legendContainer.setLayoutAlign(VerticalAlignment.TOP);
+        legendContainer.setAlign(VerticalAlignment.CENTER);
+
+        setTitle("WMS Legend");
+        setAutoSize(true);
+        setCanDragResize(true);
+        setIsModal(false);
+        setShowModalMask(false);
+        setLayoutAlign(VerticalAlignment.TOP);
+        setAlign(VerticalAlignment.TOP);
+
+        addItem(legendContainer);
+        addLegends();
+
+        centerInPage();
+    }
+}
diff -r 25157125f4a0 -r c9dcce9448f2 flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java	Tue Oct 30 13:05:26 2012 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java	Tue Oct 30 12:16:26 2012 +0100
@@ -15,6 +15,8 @@
 
 import de.intevation.flys.client.client.Config;
 import de.intevation.flys.client.client.FLYSConstants;
+import de.intevation.flys.client.client.event.OutputParameterChangeEvent;
+import de.intevation.flys.client.client.event.OutputParameterChangeHandler;
 import de.intevation.flys.client.client.event.RedrawRequestEvent;
 import de.intevation.flys.client.client.event.RedrawRequestHandler;
 import de.intevation.flys.client.client.services.LoadArtifactService;
@@ -59,7 +61,7 @@
 
 public class MapOutputTab
 extends      OutputTab
-implements   RedrawRequestHandler, ExternalWMSWindow.LayerLoader, TabSelectedHandler {
+implements   RedrawRequestHandler, ExternalWMSWindow.LayerLoader, TabSelectedHandler, OutputParameterChangeHandler {
 
     public static final String DEFAULT_SRID = "4326";
 
@@ -457,7 +459,7 @@
             new MapThemePanel.ActivateCallback() {
                 @Override
                 public void activate(Theme theme, boolean active) {
-                    activateTheme(theme, active);
+                    fireActivateTheme(theme, active);
                 }
             },
             new MapThemePanel.ThemeMovedCallback() {
@@ -496,12 +498,18 @@
             }
         );
         themePanel.addRedrawRequestHandler(this);
+        themePanel.addOutputParameterChangeHandler(this);
         c.addChild(themePanel);
 
         return c;
     }
 
 
+    private void fireActivateTheme(Theme theme, boolean active) {
+        activateTheme(theme, active);
+    }
+
+
     protected void activateTheme(Theme theme, boolean active) {
         AttributedTheme at = (AttributedTheme) theme;
 
@@ -568,5 +576,12 @@
         this.themePanelCanvas.setSize(themePanelCanvas.getWidthAsString(),
                                        themePanelCanvas.getHeightAsString());
     }
+
+
+    @Override
+    public void onOutputParameterChanged(OutputParameterChangeEvent evt) {
+        GWT.log("OutputParameterChanged");
+        controlPanel.updateThemes(getThemePanel().getThemeList());
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 25157125f4a0 -r c9dcce9448f2 flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java	Tue Oct 30 13:05:26 2012 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java	Tue Oct 30 12:16:26 2012 +0100
@@ -1,7 +1,17 @@
 package de.intevation.flys.client.client.ui.map;
 
+import org.gwtopenmaps.openlayers.client.Bounds;
+import org.gwtopenmaps.openlayers.client.Map;
+import org.gwtopenmaps.openlayers.client.control.DragPan;
+import org.gwtopenmaps.openlayers.client.control.SelectFeature;
+import org.gwtopenmaps.openlayers.client.control.SelectFeatureOptions;
+import org.gwtopenmaps.openlayers.client.control.ZoomBox;
+import org.gwtopenmaps.openlayers.client.event.MapZoomListener;
+import org.gwtopenmaps.openlayers.client.feature.VectorFeature;
+import org.gwtopenmaps.openlayers.client.layer.Vector;
+import org.gwtopenmaps.openlayers.client.util.Attributes;
+
 import com.google.gwt.core.client.GWT;
-
 import com.smartgwt.client.types.Alignment;
 import com.smartgwt.client.types.SelectionType;
 import com.smartgwt.client.util.SC;
@@ -18,17 +28,7 @@
 import de.intevation.flys.client.client.ui.Toolbar;
 import de.intevation.flys.client.client.utils.EnableDisableCmd;
 import de.intevation.flys.client.shared.model.Collection;
-
-import org.gwtopenmaps.openlayers.client.Bounds;
-import org.gwtopenmaps.openlayers.client.Map;
-import org.gwtopenmaps.openlayers.client.control.DragPan;
-import org.gwtopenmaps.openlayers.client.control.SelectFeature;
-import org.gwtopenmaps.openlayers.client.control.SelectFeatureOptions;
-import org.gwtopenmaps.openlayers.client.control.ZoomBox;
-import org.gwtopenmaps.openlayers.client.event.MapZoomListener;
-import org.gwtopenmaps.openlayers.client.feature.VectorFeature;
-import org.gwtopenmaps.openlayers.client.layer.Vector;
-import org.gwtopenmaps.openlayers.client.util.Attributes;
+import de.intevation.flys.client.shared.model.ThemeList;
 
 
 /**
@@ -48,6 +48,7 @@
 
     protected Button manageThemesButton;
     protected Button datacageButton;
+    protected Button legendButton;
 
     protected ImgButton addWMSButton;
     protected ImgButton zoomToMaxButton;
@@ -65,6 +66,8 @@
     protected DrawControl    drawControl;
     protected MeasureControl measureControl;
 
+    protected LegendWindow legendWindow;
+
     protected Canvas position;
 
 
@@ -112,6 +115,9 @@
             datacageButton = createDatacageControl();
             addMember(datacageButton);
 
+            legendButton = createLegendControl();
+            addMember(legendButton);
+
             addWMSButton = createWMSControl();
             addMember(addWMSButton);
 
@@ -562,6 +568,29 @@
     }
 
 
+    protected Button createLegendControl() {
+        Button btn = new Button(MSG.legend());
+        btn.addClickHandler(new ClickHandler() {
+            @Override
+            public void onClick(ClickEvent event) {
+                openLegendWindow();
+            }
+        });
+
+        return btn;
+    }
+
+
+    protected void openLegendWindow() {
+        if (legendWindow == null) {
+            MapOutputTab tab = (MapOutputTab) getOutputTab();
+            legendWindow = new LegendWindow(tab.getThemePanel().getThemeList());
+        }
+
+        legendWindow.show();
+    }
+
+
     protected ImgButton createGetFeatureInfo() {
         MapOutputTab ot = (MapOutputTab) getOutputTab();
         if (ot == null) {
@@ -678,5 +707,12 @@
 
         return url;
     }
+
+
+    public void updateThemes(ThemeList themeList) {
+        if (legendWindow != null) {
+            legendWindow.update(themeList);
+        }
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :


More information about the Dive4elements-commits mailing list