diff flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPositionPanel.java @ 800:95cc560ce7c4

Added map controls for digitizing and removing barriers. flys-client/trunk@2321 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 12 Jul 2011 13:43:49 +0000
parents
children 9aa1a453eed5
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPositionPanel.java	Tue Jul 12 13:43:49 2011 +0000
@@ -0,0 +1,70 @@
+package de.intevation.flys.client.client.ui.map;
+
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.events.MouseMoveEvent;
+import com.smartgwt.client.widgets.events.MouseMoveHandler;
+import com.smartgwt.client.widgets.layout.HLayout;
+
+import org.gwtopenmaps.openlayers.client.LonLat;
+import org.gwtopenmaps.openlayers.client.Map;
+import org.gwtopenmaps.openlayers.client.MapWidget;
+import org.gwtopenmaps.openlayers.client.Pixel;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class MapPositionPanel extends HLayout {
+
+    protected MapWidget mapWidget;
+    protected Map       map;
+
+    protected Label  x;
+    protected Label  y;
+
+
+    public MapPositionPanel(MapWidget mapWidget, final Canvas c) {
+        this.mapWidget = mapWidget;
+        this.map       = mapWidget.getMap();
+
+        this.x  = new Label();
+        this.y  = new Label();
+        Label d = new Label("|");
+
+        setWidth(60);
+        setMembersMargin(2);
+
+        x.setWidth(25);
+        y.setWidth(25);
+        d.setWidth(5);
+
+        addMember(x);
+        addMember(d);
+        addMember(y);
+
+        // TODO We should use the MousePosition control provided by
+        // GwtOpenLayers here instead of calculating the mouse pos manually.
+        c.addMouseMoveHandler(new MouseMoveHandler() {
+            public void onMouseMove(MouseMoveEvent e) {
+                int x = e.getX() - c.getPageLeft();
+                int y = e.getY() - c.getPageTop();
+
+                LonLat point = map.getLonLatFromPixel(new Pixel(x, y));
+                setX(point.lon());
+                setY(point.lat());
+            }
+        });
+    }
+
+
+    protected void setX(double x) {
+        this.x.setContents(String.valueOf(x));
+    }
+
+
+    protected void setY(double y) {
+        this.y.setContents(String.valueOf(y));
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org