changeset 799:f4299b90c996

Added controls to navigate in the map. flys-client/trunk@2318 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 11 Jul 2011 13:29:57 +0000
parents 7061c2e66039
children 95cc560ce7c4
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/MapToolbar.java
diffstat 4 files changed, 215 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Mon Jul 11 10:21:16 2011 +0000
+++ b/flys-client/ChangeLog	Mon Jul 11 13:29:57 2011 +0000
@@ -1,3 +1,14 @@
+2011-07-11  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java:
+	  New. This toolbar provides controls that interact with the map.
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java:
+	  Removed the initialization of map controls.
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java:
+	  Added the MapToolbar at the top of the layout.
+
 2011-07-11  Ingo Weinzierl <ingo@intevation.de>
 
 	* 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/FloodMap.java	Mon Jul 11 10:21:16 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java	Mon Jul 11 13:29:57 2011 +0000
@@ -3,7 +3,6 @@
 import org.gwtopenmaps.openlayers.client.Map;
 import org.gwtopenmaps.openlayers.client.MapOptions;
 import org.gwtopenmaps.openlayers.client.MapWidget;
-import org.gwtopenmaps.openlayers.client.control.Navigation;
 import org.gwtopenmaps.openlayers.client.util.JObjectArray;
 import org.gwtopenmaps.openlayers.client.util.JSObject;
 
@@ -22,13 +21,6 @@
 
         mapWidget = new MapWidget("510px", "635px", opts);
         map       = mapWidget.getMap();
-
-        initControls();
-    }
-
-
-    protected void initControls() {
-        map.addControl(new Navigation());
     }
 
 
@@ -52,3 +44,4 @@
         mapWidget.setHeight(height);
     }
 }
+// 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/MapOutputTab.java	Mon Jul 11 10:21:16 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java	Mon Jul 11 13:29:57 2011 +0000
@@ -3,10 +3,7 @@
 import com.google.gwt.user.client.ui.HorizontalPanel;
 import com.google.gwt.user.client.ui.Widget;
 
-import com.smartgwt.client.widgets.Button;
 import com.smartgwt.client.widgets.Canvas;
-import com.smartgwt.client.widgets.events.ClickEvent;
-import com.smartgwt.client.widgets.events.ClickHandler;
 import com.smartgwt.client.widgets.events.ResizedEvent;
 import com.smartgwt.client.widgets.events.ResizedHandler;
 import com.smartgwt.client.widgets.layout.HLayout;
@@ -126,23 +123,7 @@
 
 
     protected Canvas createControlPanel() {
-        HLayout layout = new HLayout();
-        layout.setWidth100();
-        layout.setHeight(30);
-        layout.setMembersMargin(10);
-        layout.setPadding(5);
-        layout.setBorder("1px solid black");
-
-        Button zoomToMax = new Button("Max Extent");
-        zoomToMax.addClickHandler(new ClickHandler() {
-            public void onClick(ClickEvent event) {
-                floodMap.getMap().zoomToMaxExtent();
-            }
-        });
-
-        layout.addMember(zoomToMax);
-
-        return layout;
+        return new MapToolbar(floodMap);
     }
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java	Mon Jul 11 13:29:57 2011 +0000
@@ -0,0 +1,202 @@
+package de.intevation.flys.client.client.ui.map;
+
+import com.google.gwt.core.client.GWT;
+
+import com.smartgwt.client.types.SelectionType;
+import com.smartgwt.client.widgets.ImgButton;
+import com.smartgwt.client.widgets.events.ClickEvent;
+import com.smartgwt.client.widgets.events.ClickHandler;
+import com.smartgwt.client.widgets.layout.HLayout;
+
+import org.gwtopenmaps.openlayers.client.Map;
+import org.gwtopenmaps.openlayers.client.control.DragPan;
+import org.gwtopenmaps.openlayers.client.control.ZoomBox;
+
+import de.intevation.flys.client.client.FLYSConstants;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class MapToolbar extends HLayout {
+
+    /** The message class that provides i18n strings.*/
+    protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
+
+    protected FloodMap floodMap;
+    protected DragPan  pan;
+    protected ZoomBox  zoomBox;
+
+    protected ImgButton zoomToMaxButton;
+    protected ImgButton zoomBoxButton;
+    protected ImgButton zoomOutButton;
+    protected ImgButton panButton;
+
+
+    public MapToolbar(FloodMap floodMap) {
+        super();
+
+        setWidth100();
+        setHeight(30);
+        setMembersMargin(10);
+        setPadding(5);
+        setBorder("1px solid black");
+
+        this.floodMap = floodMap;
+
+        zoomToMaxButton = createMaxExtentControl();
+        zoomBoxButton   = createZoomBoxControl();
+        zoomOutButton   = createZoomOutControl();
+        panButton       = createPanControl();
+
+        addMember(zoomToMaxButton);
+        addMember(zoomBoxButton);
+        addMember(zoomOutButton);
+        addMember(panButton);
+    }
+
+
+    protected Map getMap() {
+        return floodMap.getMap();
+    }
+
+
+    protected void activatePan(boolean activate) {
+        if (activate) {
+            panButton.select();
+            pan.activate();
+        }
+        else {
+            panButton.deselect();
+            pan.deactivate();
+        }
+    }
+
+
+    protected void activateZoomBox(boolean activate) {
+        if (activate) {
+            zoomBoxButton.select();
+            zoomBox.activate();
+        }
+        else {
+            zoomBoxButton.deselect();
+            zoomBox.deactivate();
+        }
+    }
+
+
+    protected ImgButton createMaxExtentControl() {
+        ImgButton zoomToMax = new ImgButton();
+
+        String baseUrl = GWT.getHostPageBaseURL();
+        zoomToMax.setSrc(baseUrl + MSG.zoom_all());
+        zoomToMax.setWidth(20);
+        zoomToMax.setHeight(20);
+        zoomToMax.setShowDown(false);
+        zoomToMax.setShowRollOver(false);
+        zoomToMax.setShowDisabled(false);
+        zoomToMax.setShowDisabledIcon(true);
+        zoomToMax.setShowDownIcon(false);
+        zoomToMax.setShowFocusedIcon(false);
+
+        zoomToMax.addClickHandler(new ClickHandler() {
+            public void onClick(ClickEvent event) {
+                floodMap.getMap().zoomToMaxExtent();
+            }
+        });
+
+        return zoomToMax;
+    }
+
+
+    protected ImgButton createZoomBoxControl() {
+        zoomBox = new ZoomBox();
+
+        final ImgButton button = new ImgButton();
+
+        String baseUrl = GWT.getHostPageBaseURL();
+        button.setSrc(baseUrl + MSG.zoom_in());
+        button.setActionType(SelectionType.CHECKBOX);
+        button.setSize(20);
+        button.setShowRollOver(false);
+        button.setSelected(false);
+
+        button.addClickHandler(new ClickHandler() {
+            public void onClick(ClickEvent e) {
+                if (button.isSelected()) {
+                    activatePan(false);
+                    activateZoomBox(true);
+                }
+                else {
+                    activateZoomBox(false);
+                }
+            }
+        });
+
+        Map map = getMap();
+        map.addControl(zoomBox);
+
+        return button;
+    }
+
+
+    protected ImgButton createZoomOutControl() {
+        ImgButton zoomOut = new ImgButton();
+
+        String baseUrl = GWT.getHostPageBaseURL();
+        zoomOut.setSrc(baseUrl + MSG.zoom_out());
+        zoomOut.setWidth(20);
+        zoomOut.setHeight(20);
+        zoomOut.setShowDown(false);
+        zoomOut.setShowRollOver(false);
+        zoomOut.setShowDisabled(false);
+        zoomOut.setShowDisabledIcon(true);
+        zoomOut.setShowDownIcon(false);
+        zoomOut.setShowFocusedIcon(false);
+
+        zoomOut.addClickHandler(new ClickHandler() {
+            public void onClick(ClickEvent event) {
+                Map map   = floodMap.getMap();
+                int level = map.getZoom();
+
+                if (level > 1) {
+                    map.zoomTo(level-1);
+                }
+            }
+        });
+
+        return zoomOut;
+    }
+
+
+    protected ImgButton createPanControl() {
+        pan = new DragPan();
+
+        final ImgButton button = new ImgButton();
+
+        String baseUrl = GWT.getHostPageBaseURL();
+        button.setSrc(baseUrl + MSG.pan());
+        button.setActionType(SelectionType.CHECKBOX);
+        button.setSize(20);
+        button.setShowRollOver(false);
+        button.setSelected(false);
+
+        button.addClickHandler(new ClickHandler() {
+            public void onClick(ClickEvent e) {
+                if (button.isSelected()) {
+                    activateZoomBox(false);
+                    activatePan(true);
+                }
+                else {
+                    activatePan(false);
+                }
+            }
+        });
+
+        Map map = getMap();
+        map.addControl(pan);
+
+        return button;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org