diff flys-client/src/main/java/de/intevation/flys/client/client/ui/map/DrawControl.java @ 850:d02c3835df28

Set the 'typ' attribute of new features (digitized) in the map. flys-client/trunk@2634 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 01 Sep 2011 12:49:12 +0000
parents 95cc560ce7c4
children f5855350fc03
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/DrawControl.java	Wed Aug 31 10:28:28 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/DrawControl.java	Thu Sep 01 12:49:12 2011 +0000
@@ -18,16 +18,20 @@
 import org.gwtopenmaps.openlayers.client.Map;
 import org.gwtopenmaps.openlayers.client.control.Control;
 import org.gwtopenmaps.openlayers.client.control.DrawFeature;
+import org.gwtopenmaps.openlayers.client.event.VectorFeatureAddedListener;
+import org.gwtopenmaps.openlayers.client.event.VectorFeatureAddedListener.FeatureAddedEvent;
+import org.gwtopenmaps.openlayers.client.feature.VectorFeature;
 import org.gwtopenmaps.openlayers.client.handler.Handler;
 import org.gwtopenmaps.openlayers.client.handler.PathHandler;
 import org.gwtopenmaps.openlayers.client.handler.PolygonHandler;
 import org.gwtopenmaps.openlayers.client.layer.Vector;
+import org.gwtopenmaps.openlayers.client.util.Attributes;
 
 import de.intevation.flys.client.client.FLYSConstants;
 import de.intevation.flys.client.client.utils.EnableDisableCmd;
 
 
-public class DrawControl extends HLayout {
+public class DrawControl extends HLayout implements VectorFeatureAddedListener {
 
     public static final String BARRIER_PIPE1    = "pipe1";
     public static final String BARRIER_PIPE2    = "pipe2";
@@ -111,6 +115,8 @@
         addMember(button);
         addMember(form);
 
+        layer.addVectorFeatureAddedListener(this);
+
         activate(false);
     }
 
@@ -120,6 +126,22 @@
     }
 
 
+    public void onFeatureAdded(FeatureAddedEvent evt) {
+        setCurrentType(evt.getVectorFeature());
+    }
+
+
+    protected void setCurrentType(VectorFeature feature) {
+        Attributes attrs = feature.getAttributes();
+        String     type  = attrs.getAttributeAsString("typ");
+
+        if (type == null || type.length() == 0) {
+            type = getSelectedType();
+            attrs.setAttribute("typ", type);
+        }
+    }
+
+
     protected void removeControl() {
         if (control != null) {
             control.deactivate();

http://dive4elements.wald.intevation.org