[Commits] r1860 - in sandbox/redlining/ux/FeatureEditing: examples ux/widgets ux/widgets/form ux/widgets/plugins

commits at geoext.org commits at geoext.org
Tue Feb 2 20:25:51 CET 2010


Author: adube
Date: 2010-02-02 20:25:51 +0100 (Tue, 02 Feb 2010)
New Revision: 1860

Modified:
   sandbox/redlining/ux/FeatureEditing/examples/ControlerOnlyExample.js
   sandbox/redlining/ux/FeatureEditing/examples/RedLiningPanelExample.js
   sandbox/redlining/ux/FeatureEditing/ux/widgets/FeatureEditingControler.js
   sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeatureEditingPanel.js
   sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeaturePanel.js
   sandbox/redlining/ux/FeatureEditing/ux/widgets/form/RedLiningPanel.js
   sandbox/redlining/ux/FeatureEditing/ux/widgets/plugins/CloseFeatureDialog.js
Log:
faded style now in controler, label support back

Modified: sandbox/redlining/ux/FeatureEditing/examples/ControlerOnlyExample.js
===================================================================
--- sandbox/redlining/ux/FeatureEditing/examples/ControlerOnlyExample.js	2010-02-01 21:07:26 UTC (rev 1859)
+++ sandbox/redlining/ux/FeatureEditing/examples/ControlerOnlyExample.js	2010-02-02 19:25:51 UTC (rev 1860)
@@ -13,13 +13,8 @@
         zoom: 5
     });
 
-    var style = OpenLayers.Util.applyDefaults(
-        {fillColor: "red"}, OpenLayers.Feature.Vector.style["default"]);
-
-    var layer = new OpenLayers.Layer.Vector("Cosmetic");
-
     controler = new GeoExt.ux.FeatureEditingControler({
-       'layers': [layer]
+        'cosmetic': true
     });
     
     new Ext.Panel({

Modified: sandbox/redlining/ux/FeatureEditing/examples/RedLiningPanelExample.js
===================================================================
--- sandbox/redlining/ux/FeatureEditing/examples/RedLiningPanelExample.js	2010-02-01 21:07:26 UTC (rev 1859)
+++ sandbox/redlining/ux/FeatureEditing/examples/RedLiningPanelExample.js	2010-02-02 19:25:51 UTC (rev 1860)
@@ -13,14 +13,11 @@
         zoom: 5
     });
 
-    var style = OpenLayers.Util.applyDefaults(
-        {fillColor: "red"}, OpenLayers.Feature.Vector.style["default"]);
-
     redLiningPanel = new GeoExt.ux.form.RedLiningPanel({
         title: OpenLayers.i18n("RedLining Panel"),
         region: "east",
         width: 300,
-        style: style,
+        map: mapPanel.map,
         //downloadService: 'http://localhost:5000/filemanager/download',
         plugins: [new GeoExt.ux.ImportFeatures(), 
                   new GeoExt.ux.ExportFeatures()]

Modified: sandbox/redlining/ux/FeatureEditing/ux/widgets/FeatureEditingControler.js
===================================================================
--- sandbox/redlining/ux/FeatureEditing/ux/widgets/FeatureEditingControler.js	2010-02-01 21:07:26 UTC (rev 1859)
+++ sandbox/redlining/ux/FeatureEditing/ux/widgets/FeatureEditingControler.js	2010-02-02 19:25:51 UTC (rev 1860)
@@ -131,6 +131,57 @@
      */
     autoSave: true,
 
+    /** private: property[style]
+     *  ``Object`` Feature style hash to use when creating a cosmetic layer.
+     *   If none is defined, OpenLayers.Feature.Vector.style['default'] is used
+     *   instead.
+     */
+    style: null,
+
+    /** private: property[defaultStyle]
+     *  ``Object`` Feature style hash to apply to the default 
+     *   OpenLayers.Feature.Vector.style['default'] if no style was specified.
+     */
+    defaultStyle: {
+        fillColor: "red",
+        strokeColor: "red"
+    },
+
+    /** api: config[layerOptions]
+     *  ``Object``
+     *  Options to be passed to the cosmetic OpenLayers.Layer.Vector
+     *  constructor.
+     */
+    layerOptions: {},
+
+    /** private: property[cosmetic]
+     *  ``Boolean``
+     *  If set to true, a blank OpenLayers.Layer.Vector object will be created
+     *  and added to this controler.
+     */
+    cosmetic: false,
+
+    /** api: config[fadeRatio]
+     *  ``Numeric``
+     *  The fade ratio to apply when features are not selected.
+     */
+    fadeRatio: '0.4',
+
+    /** api: config[opacityProperties]
+     *  ``Array(String)``
+     *  The style properties refering to opacity.
+     */
+    opacityProperties: [
+        "fillOpacity", "hoverFillOpacity",
+        "strokeOpacity", "hoverStrokeOpacity"
+    ],
+
+    /** api: config[defaultOpacity]
+     *  ``Numeric``
+     *  Default opacity maximum value
+     */
+    defaultOpacity: 1,
+
     /** private: method[constructor]
      *  Private constructor override.
      */
@@ -152,11 +203,26 @@
 
         this.initMap();
 
+        // Manage layers manually created
         if(config['layers'] != null) {
             this.addLayers(config['layers']);
             delete config['layers'];
         }
 
+        // if set, automatically creates a "cosmetic" layer
+        if(this.cosmetic === true) {
+            var style = this.style || OpenLayers.Util.applyDefaults(
+                this.defaultStyle, OpenLayers.Feature.Vector.style["default"]);
+            var styleMap = new OpenLayers.StyleMap(style); 
+            var layerOptions = OpenLayers.Util.applyDefaults(
+                this.layerOptions, {
+                  styleMap: styleMap,
+                  displayInLayerSwitcher: false
+            });
+            layer = new OpenLayers.Layer.Vector("Cosmetic", layerOptions);
+            this.addLayers([layer]);
+        }
+
         if(this.layers.length > 0) {
             this.setActiveLayer(this.layers[0]);
         }
@@ -185,18 +251,16 @@
         }
         this.layers.push(layer);
 
-        var events = {
+        layer.events.on({
+            "beforefeatureselected": this.onBeforeFeatureSelect,
+            "featureunselected": this.onFeatureUnselect,
+            "featureselected": this.onFeatureSelect,
             "beforefeaturemodified": this.onModificationStart,
             "featuremodified": this.onModification,
             "afterfeaturemodified": this.onModificationEnd,
+            "beforefeatureadded": this.onBeforeFeatureAdded,
             scope: this
-        }
-
-        if(this.useDefaultAttributes === true) {
-            events['beforefeatureadded'] = this.onBeforeFeatureAdded;
-        }
-
-        layer.events.on(events);
+        });
     },
 
     /** private: method[setActiveLayer]
@@ -582,28 +646,46 @@
 
     /** private: method[onBeforeFeatureAdded]
      *  :param event: ``event``
-     *  Called when a new feature is added to the layer.  Check if the feature
-     *  as any attributes.  If not, add those defined in this.attributes.
+     *  Called when a new feature is added to the layer.
      */
     onBeforeFeatureAdded: function(event) {
-        var feature, hasAttributes;
+        var feature = event.feature;
+        this.parseFeatureStyle(feature);
+        this.parseFeatureDefaultAttributes(feature);
+    },
 
-        feature = event.feature;
-        hasAttributes = false;
+    /** private: method[parseFeatureStyle]
+     */
+    parseFeatureStyle: function(feature) {
+        var symbolizer = this.activeLayer.styleMap.createSymbolizer(feature);
+        feature.style = symbolizer;
+    },
 
-        for (var key in feature.attributes) {
-            hasAttributes = true;
-            break;
-        }
+    /** private: method[parseFeatureDefaultAttributes]
+     *  :param event: ``OpenLayers.Feature.Vector``
+     *  Check if the feature has any attributes.  If not, add those defined in
+     *  this.defaultAttributes.
+     */
+    parseFeatureDefaultAttributes: function(feature) {
+        var hasAttributes;
 
-        if(!hasAttributes) {
-            for(var i=0; i<this.defaultAttributes.length; i++) {
-                feature.attributes[this.defaultAttributes[i]] = '';
+        if(this.useDefaultAttributes === true) {
+            hasAttributes = false;
+
+            for (var key in feature.attributes) {
+                hasAttributes = true;
+                break;
             }
+
+            if(!hasAttributes) {
+                for(var i=0; i<this.defaultAttributes.length; i++) {
+                    feature.attributes[this.defaultAttributes[i]] = '';
+                }
+            }
         }
     },
 
-    /** private: methodreactivateDrawControl[]
+    /** private: method[reactivateDrawControl]
      */
     reactivateDrawControl: function() {
         if (this.lastDrawControl && this.activeLayer.selectedFeatures.length === 0) {
@@ -621,5 +703,96 @@
         }
     },
 
+    /** private: method[onBeforeFeatureSelect]
+     *  :param event: ``event``
+     *  Called before a feature is selected
+     */
+    onBeforeFeatureSelect: function(event) {
+        var feature = (event.geometry) ? event : event.feature;
+
+        // if it's the first feature that is selected
+        if(feature.layer.selectedFeatures.length === 0) {
+            this.applyStyles('faded', {'redraw': true});
+        }
+    },
+
+    /** private: method[onFeatureUnselect]
+     *  :param event: ``event``
+     *  Called when a feature is unselected.
+     */
+    onFeatureUnselect: function(event) {
+        var feature = (event.geometry) ? event : event.feature;
+        this.applyStyle(feature, 'faded', {'redraw': true});
+
+        // if it's the last feature that is unselected
+        if(feature.layer.selectedFeatures.length === 0) {
+            this.applyStyles('normal', {'redraw': true});
+        }
+    },
+
+    /** private: method[onFeatureSelect]
+     *  :param event: ``event``
+     *  Called when a feature is selected
+     */
+    onFeatureSelect: function(event) {
+        var feature = (event.geometry) ? event : event.feature;
+        this.applyStyle(feature, 'normal', {'redraw': true});
+    },
+
+    /** private: method[applyStyles]
+     *  :param style: ``String`` Mandatory.  Can be "normal" or "faded".
+     *  :param options: ``Object`` Object of options.
+     *  Apply a specific style to all layers of this controler.  If 
+     *  'redraw': true was specified in the options, the layer is redrawn after.
+     */
+    applyStyles: function(style, options) {
+        style = style || "normal";
+        options = options || {};
+        for(var i=0; i<this.layers.length; i++) {
+            layer = this.layers[i];
+            for(var j=0; j<layer.features.length; j++) {
+                feature = layer.features[j];
+                if(feature.style) {
+                    this.applyStyle(feature, style);
+                }
+            }
+
+            if(options['redraw'] === true) {
+                layer.redraw();
+            }
+        }
+    },
+
+    /** private: method[applyStyle]
+     *  :param feature: ``OpenLayers.Feature.Vector``
+     *  :param style: ``String`` Mandatory.  Can be "normal" or "faded".
+     *  :param options: ``Object`` Object of options.
+     *  Apply a specific style to a specific feature.  If 'redraw': true was 
+     *  specified in the options, the layer is redrawn after.
+     */
+    applyStyle: function(feature, style, options) {
+        var fRatio;
+        options = options || {};
+
+        switch (style) {
+          case "faded":
+            fRatio = this.fadeRatio;
+            break;
+          default:
+            fRatio = 1 / this.fadeRatio;
+        }   
+
+        for(var i=0; i<this.opacityProperties.length; i++) {
+            property = this.opacityProperties[i];
+            if(feature.style[property]) {
+                feature.style[property] *= fRatio;
+            }
+        }
+
+        if(options['redraw'] === true) {
+            layer.redraw();
+        }
+    },
+
     CLASS_NAME: "GeoExt.ux.FeatureEditingControler"
 });

Modified: sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeatureEditingPanel.js
===================================================================
--- sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeatureEditingPanel.js	2010-02-01 21:07:26 UTC (rev 1859)
+++ sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeatureEditingPanel.js	2010-02-02 19:25:51 UTC (rev 1860)
@@ -11,8 +11,7 @@
  *  .. code-block:: javascript
  *     
  *      var featureEditingPanel = new GeoExt.ux.form.FeatureEditingPanel({
- *          title: "RedLining Panel"
- *          map: map,
+ *          title: "FeatureEditingPanel"
  *          controler: controler
  *      });
  */
@@ -65,11 +64,6 @@
      */
     defaultType: 'textfield',
 
-    /** api: property[map]
-     *  ``OpenLayers.Map``  A configured map object.
-     */
-    map: null,
-
     /** api: property[controler]
      *  ``GeoExt.ux.FeatureEditingControler``
      */
@@ -86,40 +80,14 @@
     /** private: method[initComponent]
      */
     initComponent: function() {
-        this.initMap();
-        this.initControler();
-        this.initToolbar();
-        this.initForm();
+        if(this.controler) {
+            this.initToolbar();
+            this.initForm();
+        }
 
         GeoExt.ux.form.FeatureEditingPanel.superclass.initComponent.call(this);
     },
-    
-    /** private: method[initMap]
-     *  Convenience method to make sure that the map object is correctly set.
-     */
-    initMap: function() {
-        if(this.map instanceof GeoExt.MapPanel) {
-            this.map = this.map.map;
-        }
 
-        if(!this.map) {
-            this.map = GeoExt.MapPanel.guess().map;
-        }
-    },
-
-    /** private: method[initControler]
-     *  Convenience method to make sure that a FeatureEditingControler has
-     *  been linked to this panel.
-     */
-    initControler: function() {
-        if(!this.controler){
-            this.controler = new GeoExt.ux.FeatureEditingControler({
-                map: this.map,
-                downloadService: this.downloadService
-            });
-        }
-    },
-
     /** private: method[initToolbar]
      *  
      */
@@ -147,7 +115,6 @@
      */
     beforeDestroy: function() {
         delete this.controler;
-        delete this.map;
     }
     
 });

Modified: sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeaturePanel.js
===================================================================
--- sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeaturePanel.js	2010-02-01 21:07:26 UTC (rev 1859)
+++ sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeaturePanel.js	2010-02-02 19:25:51 UTC (rev 1860)
@@ -268,9 +268,18 @@
         this.parseFormFieldsToFeatureAttributes(feature);
         if (feature.isLabel === true) {
             if (feature.attributes[this.labelAttribute] != "") {
+                feature.style.label = feature.attributes[this.labelAttribute];
+                feature.style.graphic = false;
+                feature.style.labelSelect = true;
+
                 feature.layer.drawFeature(feature);
             } else {
+                //this.controler.getSelectControl().unselect();
                 feature.layer.destroyFeatures([feature]);
+                if(this.controler.popup) {
+                    this.controler.popup.close();
+                    this.controler.popup = null;
+                }
             }
         }
     },

Modified: sandbox/redlining/ux/FeatureEditing/ux/widgets/form/RedLiningPanel.js
===================================================================
--- sandbox/redlining/ux/FeatureEditing/ux/widgets/form/RedLiningPanel.js	2010-02-01 21:07:26 UTC (rev 1859)
+++ sandbox/redlining/ux/FeatureEditing/ux/widgets/form/RedLiningPanel.js	2010-02-02 19:25:51 UTC (rev 1860)
@@ -37,185 +37,35 @@
  */
 GeoExt.ux.form.RedLiningPanel = Ext.extend(GeoExt.ux.form.FeatureEditingPanel, {
 
-    /** api: config[layer]
-     *  ``OpenLayers.Layer.Vector``
-     *  The cosmetic OpenLayers.Layer.Vector object to work with.
-     */
-    layer: null,
-
-    /** api: config[layerOptions]
-     *  ``Object``
-     *  Options to be passed to the cosmetic OpenLayers.Layer.Vector constructor.
-     */
-    layerOptions: {},
-
-    /** api: config[fadeRatio]
-     *  ``Numeric``
-     *  The fade ratio to apply when features are not selected.
-     */
-    fadeRatio: '0.4',
-
-    /** api: config[opacityProperties]
-     *  ``Array(String)``
-     *  The style properties refering to opacity.
-     */
-    opacityProperties: [
-        "fillOpacity", "hoverFillOpacity",
-        "strokeOpacity", "hoverStrokeOpacity"
-    ],
-
-    /** api: config[defaultOpacity]
-     *  ``Numeric``
-     *  Default opacity maximum value
-     */
-    defaultOpacity: 1,
-
-    /** private: property[style]
-     *  ``Object`` Feature style hash to use.  If none is defined,
-     *   OpenLayers.Feature.Vector.style['default'] is used instead.
-     */
-    style: null,
-
-    /** private: property[styleMap]
-     *  ``OpenLayers.StyleMap`` StyleMap object to use when automatically 
-     *  creating new OpenLayers.Layer.Vector objects.
-     */
-    styleMap: null,
-
     /** private: method[initComponent]
      */
     initComponent: function() {
-        this.initLayer(this.layer);
-        this.initControler(this.layer);
-
+        this.initMap();
+        this.initControler();
         GeoExt.ux.form.RedLiningPanel.superclass.initComponent.call(this);
     },
 
-    /** private: method[initLayer]
-     *  :param layer: ``OpenLayers.Layer.Vector``
-     *  Create a new layer object if none was provided.  Register some events.
+    /** private: method[initMap]
+     *  Convenience method to make sure that the map object is correctly set.
      */
-    initLayer: function(layer) {
-        if(!layer){
-            var labelStyle = {
-                label: "${name}",
-                labelSelect: true,
-                pointRadius: "${radius}"
-            };
-            var styleOptions = {
-              context: {
-                  'name': function(feature) {
-                      var szValue;
-                      if (feature.attributes.name && feature.isLabel === true) {
-                          szValue = feature.attributes.name;
-                      } else {
-                          szValue = "";
-                      }
-                      return szValue;
-                  },
-                  'radius': function(feature) {
-                      return (feature.isLabel === true) ? 0 : 6;
-                  }
-              }
-            };
-
-            // get the style hash to work with
-            var styleHash = this.style || OpenLayers.Feature.Vector.style["default"];
-
-            // normal style
-            var style = new OpenLayers.Style(
-                OpenLayers.Util.applyDefaults(
-                    labelStyle, styleHash),
-                styleOptions
-            );
-
-            // faded style auto-generation
-            var fadedHash = {};
-            for(var i=0; i<this.opacityProperties.length; i++) {
-                var prop = this.opacityProperties[i];
-                if(styleHash[prop]) {
-                    fadedHash[prop] = styleHash[prop] * this.fadeRatio;
-                } else {
-                    fadedHash[prop] = this.defaultOpacity * this.fadeRatio;
-                }
-            }
-
-            var fadedStyle = new OpenLayers.Style(
-                OpenLayers.Util.applyDefaults(fadedHash,
-                OpenLayers.Util.applyDefaults(
-                    labelStyle, styleHash)),
-                styleOptions
-            );
-
-            this.styleMap = new OpenLayers.StyleMap({
-                 "default": style,
-                 "select": style,
-                 "normal": style,
-                 "faded": fadedStyle
-            }); 
-
-            this.layerOptions = OpenLayers.Util.applyDefaults(this.layerOptions, {
-                styleMap: this.styleMap,
-                displayInLayerSwitcher: false
-            });
-            layer = new OpenLayers.Layer.Vector("Cosmetic", this.layerOptions);
+    initMap: function() {
+        if (this.map instanceof GeoExt.MapPanel) {
+            this.map = this.map.map;
         }
 
-        this.layer = layer;
-
-        layer.events.on({
-           "beforefeatureselected": this.onBeforeFeatureSelect,
-           "featureunselected": this.onFeatureUnselect,
-            scope: this
-        });
-    },
-
-    initControler: function() {
-        if(!this.controler){
-            this.controler = new GeoExt.ux.FeatureEditingControler({
-                layers: [this.layer]
-            });
+        if (!this.map) {
+            this.map = GeoExt.MapPanel.guess().map;
         }
     },
 
-   /** private: method[onFeatureSelect]
-     *  :param event: ``event``
-     *  Called when a feature is selected
+    /** private: method[initMap]
+     *  Automatically create a FeatureEditingControler.
      */
-    onBeforeFeatureSelect: function(event) {
-        var feature = (event.geometry) ? event : event.feature;
-
-        // if it's the first feature that is selected
-        if(feature.layer.selectedFeatures.length === 0) {
-            this.applyFadedStyle(feature.layer);
-        }
-    },
-
-    /** private: method[onFeatureUnselect]
-     *  :param event: ``event``
-     *  Called when a feature is unselected.
-     */
-    onFeatureUnselect: function(event) {
-        var feature = (event.geometry) ? event : event.feature;
-
-        // if it's the last feature that is unselected
-        if(feature.layer.selectedFeatures.length === 0) {
-            this.applyNormalStyle(feature.layer);
-        }
-    },
-
-    applyNormalStyle: function(layer) {
-        var styles = layer.styleMap.styles;
-        styles['default'] = styles.normal;
-
-        layer.redraw();
-    },
-
-    applyFadedStyle: function(layer) {
-        var styles = layer.styleMap.styles;
-        styles['default'] = styles.faded;
-
-        layer.redraw();
+    initControler: function() {
+        this.controler = new GeoExt.ux.FeatureEditingControler({
+            'cosmetic': true,
+            'map': this.map
+        });
     }
 });
 

Modified: sandbox/redlining/ux/FeatureEditing/ux/widgets/plugins/CloseFeatureDialog.js
===================================================================
--- sandbox/redlining/ux/FeatureEditing/ux/widgets/plugins/CloseFeatureDialog.js	2010-02-01 21:07:26 UTC (rev 1859)
+++ sandbox/redlining/ux/FeatureEditing/ux/widgets/plugins/CloseFeatureDialog.js	2010-02-02 19:25:51 UTC (rev 1860)
@@ -37,6 +37,9 @@
 
     closeFeatureDialog: function() {
         this.controler.triggerAutoSave();
-        this.controler.popup.close();
+        if(this.controler.popup) {
+            this.controler.popup.close();
+        }
+        this.controler.reactivateDrawControl();
     }
 });



More information about the Commits mailing list