changeset 802:d45ad7fd3027

Added map tools to measure lines and polygons. flys-client/trunk@2323 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 12 Jul 2011 15:04:50 +0000
parents f6693d8f0bc8
children 653ae84533e7
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MeasureControl.java flys-client/src/main/webapp/images/measureLine.png flys-client/src/main/webapp/images/measureLine_Selected.png flys-client/src/main/webapp/images/measurePolygon.png flys-client/src/main/webapp/images/measurePolygon_Selected.png
diffstat 11 files changed, 245 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue Jul 12 13:44:27 2011 +0000
+++ b/flys-client/ChangeLog	Tue Jul 12 15:04:50 2011 +0000
@@ -1,3 +1,24 @@
+2011-07-12  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/MeasureControl.java:
+	  New. This control consists of two OpenLayers controls to measure lines
+	  and polygons.
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java:
+	  Added the MeasureControl.
+
+	* src/main/webapp/images/measurePolygon.png,
+	  src/main/webapp/images/measurePolygon_Selected.png,
+	  src/main/webapp/images/measureLine.png,
+	  src/main/webapp/images/measureLine_Selected.png: New. Icons for the
+	  measure control.
+
+	* src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants.java: Added
+	  path locations for the measurement tools.
+
 2011-07-12  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/map/MapPositionPanel.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Tue Jul 12 13:44:27 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Tue Jul 12 15:04:50 2011 +0000
@@ -345,5 +345,9 @@
     String selectFeature();
 
     String removeFeature();
+
+    String measureLine();
+
+    String measurePolygon();
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Tue Jul 12 13:44:27 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Tue Jul 12 15:04:50 2011 +0000
@@ -176,3 +176,5 @@
 ring_dike = Ringdike
 selectFeature = images/selectFeature.png
 removeFeature = images/removeFeature.png
+measureLine = images/measureLine.png
+measurePolygon = images/measurePolygon.png
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Tue Jul 12 13:44:27 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Tue Jul 12 15:04:50 2011 +0000
@@ -176,3 +176,5 @@
 ring_dike = Ringdeich
 selectFeature = images/selectFeature.png
 removeFeature = images/removeFeature.png
+measureLine = images/measureLine.png
+measurePolygon = images/measurePolygon.png
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Tue Jul 12 13:44:27 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Tue Jul 12 15:04:50 2011 +0000
@@ -171,3 +171,5 @@
 ring_dike = Ringdike
 selectFeature = images/selectFeature.png
 removeFeature = images/removeFeature.png
+measureLine = images/measureLine.png
+measurePolygon = images/measurePolygon.png
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java	Tue Jul 12 13:44:27 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java	Tue Jul 12 15:04:50 2011 +0000
@@ -43,7 +43,8 @@
     protected ImgButton selectButton;
     protected ImgButton removeButton;
 
-    protected DrawControl drawControl;
+    protected DrawControl    drawControl;
+    protected MeasureControl measureControl;
 
     protected Canvas position;
 
@@ -70,6 +71,7 @@
         drawControl     = createDrawControl();
         selectButton    = createSelectFeatureControl();
         removeButton    = createRemoveFeatureControl();
+        measureControl  = createMeasureControl();
 
         addMember(zoomToMaxButton);
         addMember(zoomBoxButton);
@@ -78,6 +80,7 @@
         addMember(drawControl);
         addMember(selectButton);
         addMember(removeButton);
+        addMember(measureControl);
         addMember(spacer);
         addMember(position);
     }
@@ -129,6 +132,11 @@
     }
 
 
+    protected void activateMeasureControl(boolean activate) {
+        measureControl.activate(activate);
+    }
+
+
     protected ImgButton createButton(String img, ClickHandler handler) {
         ImgButton btn = new ImgButton();
 
@@ -198,6 +206,7 @@
                 activatePan(false);
                 activateDrawFeature(false);
                 activateSelectFeature(false);
+                activateMeasureControl(false);
             }
 
             public void disable() {
@@ -239,6 +248,7 @@
                 activatePan(true);
                 activateDrawFeature(false);
                 activateSelectFeature(false);
+                activateMeasureControl(false);
             }
 
             public void disable() {
@@ -259,6 +269,7 @@
                 activatePan(false);
                 activateDrawFeature(true);
                 activateSelectFeature(false);
+                activateMeasureControl(false);
             }
 
             public void disable() {
@@ -302,6 +313,7 @@
                 activatePan(false);
                 activateZoomBox(false);
                 activateSelectFeature(true);
+                activateMeasureControl(false);
             }
 
             public void disable() {
@@ -346,5 +358,23 @@
     protected Canvas createMousePosition(Canvas mapWrapper) {
         return new MapPositionPanel(floodMap.getMapWidget(), mapWrapper);
     }
+
+
+    protected MeasureControl createMeasureControl() {
+        EnableDisableCmd cmd = new EnableDisableCmd() {
+            public void enable() {
+                activateDrawFeature(false);
+                activatePan(false);
+                activateZoomBox(false);
+                activateSelectFeature(false);
+            }
+
+            public void disable() {
+                // do nothing
+            }
+        };
+
+        return new MeasureControl(floodMap, cmd);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MeasureControl.java	Tue Jul 12 15:04:50 2011 +0000
@@ -0,0 +1,183 @@
+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.Label;
+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.control.Measure;
+import org.gwtopenmaps.openlayers.client.event.MeasureEvent;
+import org.gwtopenmaps.openlayers.client.event.MeasureListener;
+import org.gwtopenmaps.openlayers.client.event.MeasurePartialListener;
+import org.gwtopenmaps.openlayers.client.handler.PathHandler;
+import org.gwtopenmaps.openlayers.client.handler.PolygonHandler;
+
+import de.intevation.flys.client.client.FLYSConstants;
+import de.intevation.flys.client.client.utils.EnableDisableCmd;
+
+
+public class MeasureControl extends HLayout {
+
+    protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
+
+    protected FloodMap floodMap;
+
+    protected Measure measureLine;
+    protected Measure measurePolygon;
+
+    protected ImgButton measureLineButton;
+    protected ImgButton measurePolyButton;
+    protected Label     label;
+
+
+    public MeasureControl(FloodMap floodMap, EnableDisableCmd cmd) {
+        this.floodMap = floodMap;
+
+        measureLineButton = createMeasureLineControl(cmd);
+        measurePolyButton = createMeasurePolyControl(cmd);
+
+        label = new Label();
+
+        initLayout();
+    }
+
+
+    protected void initLayout() {
+        setMembersMargin(2);
+        addMember(measureLineButton);
+        addMember(measurePolyButton);
+        addMember(label);
+    }
+
+
+    protected ImgButton createMeasureLineControl(final EnableDisableCmd cmd) {
+        measureLine = new Measure(new PathHandler());
+        measureLine.setPersist(true);
+        measureLine.addMeasureListener(new MeasureListener() {
+            public void onMeasure(MeasureEvent e) {
+                updateMeasure(e.getMeasure(), e.getUnits());
+            }
+        });
+        measureLine.addMeasurePartialListener(new MeasurePartialListener() {
+            public void onMeasurePartial(MeasureEvent e) {
+                updateMeasure(e.getMeasure(), e.getUnits());
+            }
+        });
+
+        floodMap.getMap().addControl(measureLine);
+
+        final ImgButton btn = new ImgButton();
+        String baseUrl = GWT.getHostPageBaseURL();
+        btn.setSrc(baseUrl + MSG.measureLine());
+        btn.setActionType(SelectionType.CHECKBOX);
+        btn.setSize(20);
+        btn.setShowRollOver(false);
+        btn.setSelected(false);
+        btn.addClickHandler(new ClickHandler() {
+            public void onClick(ClickEvent e) {
+                if (btn.isSelected()) {
+                    cmd.enable();
+                    activateMeasurePolygon(false);
+                    activateMeasureLine(true);
+                }
+                else {
+                    cmd.disable();
+                    activateMeasureLine(false);
+                }
+            }
+        });
+
+        return btn;
+    }
+
+
+    protected ImgButton createMeasurePolyControl(final EnableDisableCmd cmd) {
+        measurePolygon = new Measure(new PolygonHandler());
+        measurePolygon.setPersist(true);
+        measurePolygon.addMeasureListener(new MeasureListener() {
+            public void onMeasure(MeasureEvent e) {
+                updateMeasure(e.getMeasure(), e.getUnits());
+            }
+        });
+        measurePolygon.addMeasurePartialListener(new MeasurePartialListener() {
+            public void onMeasurePartial(MeasureEvent e) {
+                updateMeasure(e.getMeasure(), e.getUnits());
+            }
+        });
+
+        floodMap.getMap().addControl(measurePolygon);
+
+        final ImgButton btn = new ImgButton();
+        String baseUrl = GWT.getHostPageBaseURL();
+        btn.setSrc(baseUrl + MSG.measurePolygon());
+        btn.setActionType(SelectionType.CHECKBOX);
+        btn.setSize(20);
+        btn.setShowRollOver(false);
+        btn.setSelected(false);
+        btn.addClickHandler(new ClickHandler() {
+            public void onClick(ClickEvent e) {
+                if (btn.isSelected()) {
+                    cmd.enable();
+                    activateMeasureLine(false);
+                    activateMeasurePolygon(true);
+                }
+                else {
+                    cmd.disable();
+                    activateMeasurePolygon(false);
+                }
+            }
+        });
+
+        return btn;
+    }
+
+
+    protected void clearMeasure() {
+        label.setContents("");
+    }
+
+
+    protected void updateMeasure(float value, String unit) {
+        label.setContents(String.valueOf(value) + " " + unit);
+    }
+
+
+    public void activate(boolean activate) {
+        if (!activate) {
+            clearMeasure();
+            activateMeasureLine(activate);
+            activateMeasurePolygon(activate);
+        }
+    }
+
+
+    protected void activateMeasureLine(boolean activate) {
+        if (activate) {
+            clearMeasure();
+            measureLineButton.select();
+            measureLine.activate();
+        }
+        else {
+            measureLineButton.deselect();
+            measureLine.deactivate();
+        }
+    }
+
+
+    protected void activateMeasurePolygon(boolean activate) {
+        if (activate) {
+            clearMeasure();
+            measurePolyButton.select();
+            measurePolygon.activate();
+        }
+        else {
+            measurePolyButton.deselect();
+            measurePolygon.deactivate();
+        }
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
Binary file flys-client/src/main/webapp/images/measureLine.png has changed
Binary file flys-client/src/main/webapp/images/measureLine_Selected.png has changed
Binary file flys-client/src/main/webapp/images/measurePolygon.png has changed
Binary file flys-client/src/main/webapp/images/measurePolygon_Selected.png has changed

http://dive4elements.wald.intevation.org