[Commits] r1673 - sandbox/redlining/ux/RedLining/ux/widgets

commits at geoext.org commits at geoext.org
Fri Jan 8 15:58:04 CET 2010


Author: adube
Date: 2010-01-08 15:58:04 +0100 (Fri, 08 Jan 2010)
New Revision: 1673

Modified:
   sandbox/redlining/ux/RedLining/ux/widgets/MainControler.js
Log:
ModifyFeature control added with events, no popup yet

Modified: sandbox/redlining/ux/RedLining/ux/widgets/MainControler.js
===================================================================
--- sandbox/redlining/ux/RedLining/ux/widgets/MainControler.js	2010-01-08 14:15:58 UTC (rev 1672)
+++ sandbox/redlining/ux/RedLining/ux/widgets/MainControler.js	2010-01-08 14:58:04 UTC (rev 1673)
@@ -51,6 +51,23 @@
             this.map.addLayer(layer);
         }
         this.layers.push(layer);
+
+        layer.events.on({
+           "beforefeaturemodified": this.onModificationStart,
+            scope: this
+        });
+        layer.events.on({
+           "featuremodified": this.onModification,
+            scope: this
+        });
+        layer.events.on({
+           "afterfeaturemodified": this.onModificationEnd,
+            scope: this
+        });
+        layer.events.on({
+           "afterfeaturemodified": this.resumeDraw,
+            scope: this
+        });
     },
 
     setActiveLayer: function(layer) {
@@ -59,6 +76,33 @@
     },
 
     initFeatureControl: function() {
+        var layer, control, options;
+
+        layer = this.activeLayer;
+        options = {};
+
+        control = new OpenLayers.Control.ModifyFeature(
+            layer, options);
+
+        this.featureControl = control;
+        this.map.addControl(control);
+
+        action = new GeoExt.Action({
+            //iconCls: "todo",
+            text: "EditFeature",
+            control: control,
+            map: this.map,
+            // button options
+            toggleGroup: this.map.id,
+            allowDepress: false,
+            pressed: false,
+            tooltip: "todo",
+            // check item options
+            group: this.map.id,
+            checked: false
+        });
+
+        this.actions.push(action);
     },
 
     destroyFeatureControl: function() {
@@ -108,6 +152,11 @@
             this.drawControls.push(control);
             this.map.addControl(control);
 
+            control.events.on({
+               "featureadded": this.onFeatureAdded,
+                scope: this
+            });
+
             action = new GeoExt.Action({
                 //iconCls: "todo",
                 text: geometryType,
@@ -151,5 +200,87 @@
         }
     },
 
+    getSelectControl: function() {
+        var control = false;
+
+        switch(this.featureControl.CLASS_NAME) {
+          case "OpenLayers.Control.SelectFeature":
+            control = this.featureControl;
+            break;
+          case "OpenLayers.Control.ModifyFeature":
+          case "OpenLayers.Control.DeleteFeature":
+            control = this.featureControl.selectControl;
+            break;
+        }
+
+        return control;
+    },
+
+    getActiveDrawControl: function() {
+        var control = false;
+
+        for(var i=0; i<this.drawControls.length; i++) {
+            if(this.drawControls[i].active) {
+                control = this.drawControls[i];
+                break;
+            }
+        }
+
+        return control;
+    },
+
+    onFeatureAdded: function(event) {
+        var feature, drawControl;
+
+        feature = event.feature;
+        feature.state = OpenLayers.State.INSERT;
+
+        this.featureControl.activate();
+
+        drawControl = this.getActiveDrawControl();
+        if(drawControl) {
+            drawControl.deactivate();
+        }
+        
+        this.getSelectControl().select(feature);
+    },
+
+    onModificationStart: function(object) {
+        var feature = (object.geometry) ? object : object.feature;
+
+        // to keep the state before any modification, useful when hitting the
+        // 'cancel' button
+        /*
+        if(feature.state != OpenLayers.State.INSERT){
+            feature.myClone = feature.clone();
+            feature.myClone.fid = feature.fid;
+        }
+        */
+
+        // display the popup
+    },
+
+    onModification: function(object) {
+        //we could execute commits here
+    },
+
+    /**
+     * Method: onModificationEnd
+     * Called after feature modification.  
+     * If using a FeaturePanel :
+     *     Validate that it's currently commiting.  If not, depending of the
+     *     feature state, reset or destroy the feature.
+     * If not using a FeaturePanel :
+     *     Simply commit the modifications made to the feature.
+     *
+     * Parameters:
+     * object - {<OpenLayers.Event>} Used to get the modified feature
+     */
+    onModificationEnd: function(object) {
+        var feature = (object.geometry) ? object : object.feature;
+
+        // or we could execute commits here also
+    },
+
     CLASS_NAME: "GeoExt.ux.MainControler"
 });



More information about the Commits mailing list