[Dive4elements-commits] [PATCH] Get rid of HorizontalLayout in MapOutputTab and use manual resizing

Wald Commits scm-commit at wald.intevation.org
Mon Nov 5 15:18:02 CET 2012


# HG changeset patch
# User Christian Lins <christian.lins at intevation.de>
# Date 1352125078 -3600
# Node ID c84630d544a1b4af5db7cbf8b8f97937b5260978
# Parent  6dad08f5436949504adc08ffa4e90ea1a89e918a
Get rid of HorizontalLayout in MapOutputTab and use manual resizing.

The OpenLayers Map widget is now resized and positioned manually by a
ResizeHandler method. The automatic HorizontalLayout was obviously
broken in combination with the OpenLayers widget.
This should fix various layout issues with the OpenLayers Map.

diff -r 6dad08f54369 -r c84630d544a1 flys-client/src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java	Mon Nov 05 14:39:48 2012 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java	Mon Nov 05 15:17:58 2012 +0100
@@ -34,10 +34,10 @@
     protected Bounds    maxExtent;
     protected ScaleLine scaleLine;
 
-    public FloodMap(String srid, Bounds maxExtent) {
+    public FloodMap(String srid, Bounds maxExtent, String width, String height) {
         this.srid      = srid;
         this.maxExtent = maxExtent;
-        recreateWidget("100%", "99px");
+        recreateWidget(width, height);
         getBarrierLayer();
     }
 
diff -r 6dad08f54369 -r c84630d544a1 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	Mon Nov 05 14:39:48 2012 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java	Mon Nov 05 15:17:58 2012 +0100
@@ -2,7 +2,7 @@
 
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.google.gwt.user.client.ui.Widget;
+import com.google.gwt.user.client.ui.AbsolutePanel;
 
 import com.smartgwt.client.util.SC;
 import com.smartgwt.client.widgets.Canvas;
@@ -48,6 +48,7 @@
 
 import org.gwtopenmaps.openlayers.client.Bounds;
 import org.gwtopenmaps.openlayers.client.Map;
+import org.gwtopenmaps.openlayers.client.MapWidget;
 import org.gwtopenmaps.openlayers.client.event.VectorFeatureAddedListener;
 import org.gwtopenmaps.openlayers.client.event.VectorFeatureRemovedListener;
 import org.gwtopenmaps.openlayers.client.feature.VectorFeature;
@@ -87,9 +88,10 @@
     protected MapToolbar controlPanel;
     protected ThemePanel themePanel;
     protected Canvas     themePanelCanvas;
-    protected Widget     mapPanel;
+    protected MapWidget     mapPanel;
     protected Canvas mapPanelCanvas;
-
+    protected VLayout rootLayout = new VLayout();
+    protected AbsolutePanel absPan = new AbsolutePanel();
     protected FloodMap floodMap;
 
 
@@ -121,7 +123,7 @@
                         initial = max;
                     }
 
-                    setFloodmap(new FloodMap(c.getSrid(), max));
+                    setFloodmap(new FloodMap(c.getSrid(), max, "100%", "100%"));
 
                     initLayout();
                     initBarriers();
@@ -136,40 +138,29 @@
 
 
     protected void initLayout() {
-        VLayout rootLayout = new VLayout();
         rootLayout.setHeight100();
         rootLayout.setWidth100();
         rootLayout.setMembersMargin(2);
 
         final HLayout hlayout = new HLayout();
-        hlayout.setMembersMargin(2);
+        hlayout.setMembersMargin(0);
 
         this.themePanelCanvas = createThemePanel();
 
         controlPanel = createControlPanel();
-        //mapPanel     = new Image();
-        //((Image)mapPanel).setUrl("http://www.hedweb.com/animimag/cool-pony.jpg");
         mapPanel = floodMap.getMapWidget();
-        hlayout.addMember(themePanelCanvas);
-        hlayout.addMember(mapPanel);
 
         rootLayout.addMember(controlPanel);
-        rootLayout.addMember(hlayout);
+        rootLayout.addMember(absPan);
+        absPan.setWidth("100%");
+        absPan.setHeight("100%");
+        absPan.add(themePanelCanvas);
+        absPan.add(mapPanel);
 
-        hlayout.addResizedHandler(new ResizedHandler() {
+        rootLayout.addResizedHandler(new ResizedHandler() {
             @Override
             public void onResized(ResizedEvent e) {
-                int height = hlayout.getHeight();
-                int width  = hlayout.getWidth() -
-                        (themePanelCanvas.isVisible() ? themePanelCanvas.getWidth() : 0);
-
-                height = height * 99 / 100;
-                width  = width  * 99 / 100;
-
-                String w = String.valueOf(width) + "px";
-                String h = String.valueOf(height) + "px";
-
-                mapPanel.setSize(w, h);
+                doLayout();
             }
         });
 
@@ -177,6 +168,39 @@
     }
 
 
+    protected void doLayout() {
+        if(!rootLayout.isVisible()) {
+            return;
+        }
+
+        // Manually set the height of the AbsolutePanel, somehow this is necessary
+        absPan.setHeight(String.valueOf(
+                rootLayout.getHeight() - controlPanel.getHeight() - 2) + "px");
+
+        // Calculate bounds of Map
+        int height = rootLayout.getHeight() -
+                controlPanel.getHeight() - 6;
+        int width  = controlPanel.getWidth() -
+                (themePanelCanvas.isVisible() ? themePanelCanvas.getWidth() + 4 : 0);
+
+        // Set size and position of Map
+        String w = String.valueOf(width) + "px";
+        String h = String.valueOf(height) + "px";
+        GWT.log("width=" + w);
+
+        mapPanel.setSize(w, h);
+        if(themePanelCanvas.isVisible()) {
+            absPan.setWidgetPosition(mapPanel, themePanelCanvas.getWidth() + 2, 0);
+        }
+        else {
+            absPan.setWidgetPosition(mapPanel, 0, 0);
+        }
+
+        // Set bounds of ThemePanelCanvas
+        themePanelCanvas.setSize(themePanelCanvas.getWidthAsString(), String.valueOf(height + 2) + "px");
+    }
+
+
     protected void initBarriers() {
         Vector vector = floodMap.getBarrierLayer();
         vector.addVectorFeatureAddedListener(
@@ -573,8 +597,9 @@
 
     public void toogleThemePanel() {
         this.themePanelCanvas.setVisible(!themePanelCanvas.isVisible());
-        this.themePanelCanvas.setSize(themePanelCanvas.getWidthAsString(),
-                                       themePanelCanvas.getHeightAsString());
+
+        // Trigger resize event handler
+        doLayout();
     }
 
 
diff -r 6dad08f54369 -r c84630d544a1 flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPanel.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPanel.java	Mon Nov 05 14:39:48 2012 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPanel.java	Mon Nov 05 15:17:58 2012 +0100
@@ -32,7 +32,8 @@
                 bbox.getLowerX(),
                 bbox.getLowerY(),
                 bbox.getUpperX(),
-                bbox.getUpperY()));
+                bbox.getUpperY()),
+                "100%", "100%");
 
         initLayout();
     }
@@ -51,6 +52,7 @@
         wrapper.setWidth100();
         wrapper.setHeight100();
         wrapper.addChild(mapArea);
+        wrapper.setRedrawOnResize(true);
 
         toolbar = new MapToolbar(floodMap, digitizeEnabled);
 


More information about the Dive4elements-commits mailing list