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

commits at geoext.org commits at geoext.org
Thu Jan 28 20:46:52 CET 2010


Author: adube
Date: 2010-01-28 20:46:52 +0100 (Thu, 28 Jan 2010)
New Revision: 1836

Added:
   sandbox/redlining/ux/FeatureEditing/examples/ControlerOnlyExample.html
   sandbox/redlining/ux/FeatureEditing/examples/ControlerOnlyExample.js
Modified:
   sandbox/redlining/ux/FeatureEditing/ux/widgets/FeatureEditingControler.js
   sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeatureEditingPanel.js
   sandbox/redlining/ux/FeatureEditing/ux/widgets/form/RedLiningPanel.js
Log:
controler object more independant, new sample with controler only, junk cleaning

Added: sandbox/redlining/ux/FeatureEditing/examples/ControlerOnlyExample.html
===================================================================
--- sandbox/redlining/ux/FeatureEditing/examples/ControlerOnlyExample.html	                        (rev 0)
+++ sandbox/redlining/ux/FeatureEditing/examples/ControlerOnlyExample.html	2010-01-28 19:46:52 UTC (rev 1836)
@@ -0,0 +1,44 @@
+<html>
+    <head>
+        <title>ControlerOnly Example</title>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+        <script type="text/javascript" src="http://extjs.cachefly.net/ext-3.0.0/adapter/ext/ext-base.js"></script>
+        <script type="text/javascript" src="http://extjs.cachefly.net/ext-3.0.0/ext-all.js"></script>
+        <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-3.0.0/resources/css/ext-all.css" />
+        <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-3.0.0/examples/shared/examples.css" />
+        <script type="text/javascript" src="../../../trunk/openlayers/lib/OpenLayers.js"></script>
+        <script type="text/javascript" src="../../../trunk/openlayers/lib/OpenLayers/Lang/fr.js"></script>
+        <script type="text/javascript" src="../resources/lang/fr.js"></script>
+        <script type="text/javascript" src="../../../trunk/geoext/lib/GeoExt.js"></script>
+
+        <script type="text/javascript" src="http://dev.geoext.org/sandbox/cmoullet/ux/LayerManager/ux/downloadify/js/swfobject.js"></script>
+        <script type="text/javascript" src="http://dev.geoext.org/sandbox/cmoullet/ux/LayerManager/ux/downloadify/js/downloadify.min.js"></script>
+        <script type="text/javascript" src="http://dev.geoext.org/sandbox/cmoullet/ux/LayerManager/ux/utils/flash.js"></script>
+        <script type="text/javascript" src="http://dev.geoext.org/sandbox/cmoullet/ux/LayerManager/ux/data/FormatStore.js"></script>
+        <script type="text/javascript" src="http://dev.geoext.org/sandbox/cmoullet/ux/LayerManager/ux/data/Export.js"></script>
+        <script type="text/javascript" src="http://dev.geoext.org/sandbox/cmoullet/ux/LayerManager/ux/data/Import.js"></script>
+        <script type="text/javascript" src="http://dev.geoext.org/sandbox/cmoullet/ux/LayerManager/ux/widgets/LayerManagerExportPanel.js"></script>
+        <script type="text/javascript" src="http://dev.geoext.org/sandbox/cmoullet/ux/LayerManager/ux/widgets/LayerManagerImportPanel.js"></script>
+        <script type="text/javascript" src="http://dev.geoext.org/sandbox/cmoullet/ux/LayerManager/ux/widgets/LayerManagerWindow.js"></script>
+        <script type="text/javascript" src="http://dev.geoext.org/sandbox/cmoullet/ux/LayerManager/ux/widgets/LayerManagerExportWindow.js"></script>
+        
+        <link rel="stylesheet" type="text/css" href="../resources/css/feature-editing.css" />
+        <script type="text/javascript" src="../ux/FeatureEditing.js"></script>
+        
+        <script type="text/javascript" src="ControlerOnlyExample.js"></script>
+        
+    </head>
+    <body>
+        <h1>ControlerOnly example</h1>
+        
+        <p></p>
+        
+        <p></p>
+        
+        <p></p>
+        
+        <p>See <a href="ControlerOnlyExample.js">ControlerOnlyExample.js</a> for the source code.</p>
+        
+        <div id="content"></div>
+    </body>
+</html>


Property changes on: sandbox/redlining/ux/FeatureEditing/examples/ControlerOnlyExample.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:eol-style
   + native

Added: sandbox/redlining/ux/FeatureEditing/examples/ControlerOnlyExample.js
===================================================================
--- sandbox/redlining/ux/FeatureEditing/examples/ControlerOnlyExample.js	                        (rev 0)
+++ sandbox/redlining/ux/FeatureEditing/examples/ControlerOnlyExample.js	2010-01-28 19:46:52 UTC (rev 1836)
@@ -0,0 +1,33 @@
+var controler, mapPanel;
+
+Ext.onReady(function() {
+
+    Ext.QuickTips.init();
+
+    mapPanel = new GeoExt.MapPanel({
+        region: "center",
+        layers: [new OpenLayers.Layer.WMS("Global Imagery",
+            "http://labs.metacarta.com/wms/vmap0",
+            {layers: "basic"})] ,
+        center: [16,48],
+        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]
+    });
+    
+    new Ext.Panel({
+        renderTo: "content",
+        layout: "border",
+        width: 650,
+        height: 350,
+        tbar: new Ext.Toolbar(controler.actions),
+        items: [mapPanel]
+    });
+});


Property changes on: sandbox/redlining/ux/FeatureEditing/examples/ControlerOnlyExample.js
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Modified: sandbox/redlining/ux/FeatureEditing/ux/widgets/FeatureEditingControler.js
===================================================================
--- sandbox/redlining/ux/FeatureEditing/ux/widgets/FeatureEditingControler.js	2010-01-28 12:33:09 UTC (rev 1835)
+++ sandbox/redlining/ux/FeatureEditing/ux/widgets/FeatureEditingControler.js	2010-01-28 19:46:52 UTC (rev 1836)
@@ -99,13 +99,38 @@
     useIcons: true,
 
     /** api: config[downloadService]
-     *  ``String``  URL used in order to use a server download service. The attributes "format" and "content" are sent (POST) to this service.
+     *  ``String``  URL used in order to use a server download service. The
+     *              attributes "format" and "content" are sent (POST) to this
+     *              service.
      */
-    /** private: property[defaultFormat]
-     *  ``String``  URL used in order to use a server download service. The attributes "format" and "content" are sent (POST) to this service.
+    /** private: property[downloadService]
+     *  ``String``  URL used in order to use a server download service. The
+     *              attributes "format" and "content" are sent (POST) to this
+     *              service.
      */
     downloadService: null,
 
+    /** private: property[useDefaultAttributes]
+     *  ``Boolean``
+     *  If set to true, defaultAttributes are set to new features added with
+     *  no attributes.
+     */
+    useDefaultAttributes: true,
+
+    /** api: config[defaultAttributes]
+     *  ``Array(String)``
+     *  An array of attribute names to used when a blank feature is added
+     *  to the map if useDefaultAttributes is set to true.
+     */
+    defaultAttributes: ['name','description'],
+
+    /** private: property[autoSave]
+     *  ``Boolean``
+     *  If set to true, automatically saves modifications on specific kind of
+     *  events.
+     */
+    autoSave: true,
+
     /** private: method[constructor]
      *  Private constructor override.
      */
@@ -121,20 +146,22 @@
             "activelayerchanged"
         ]);
 
-
-        GeoExt.ux.FeatureEditingControler.superclass.constructor.apply(this, arguments);
-
-        this.layers = [];
         this.drawControls = [];
         this.actions = [];
+        this.layers = [];
 
-        if (this.map instanceof GeoExt.MapPanel) {
-            this.map = this.map.map;
+        this.initMap();
+
+        if(config['layers'] != null) {
+            this.addLayers(config['layers']);
+            delete config['layers'];
         }
 
-        if (!this.map) {
-            this.map = GeoExt.MapPanel.guess().map;
+        if(this.layers.length > 0) {
+            this.setActiveLayer(this.layers[0]);
         }
+
+        GeoExt.ux.FeatureEditingControler.superclass.constructor.apply(this, arguments);
     },
 
     /** private: method[addLayers]
@@ -158,13 +185,18 @@
         }
         this.layers.push(layer);
 
-        layer.events.on({
+        var events = {
             "beforefeaturemodified": this.onModificationStart,
             "featuremodified": this.onModification,
             "afterfeaturemodified": this.onModificationEnd,
-            //           "featureunselected": this.onFeatureUnselect,
             scope: this
-        });
+        }
+
+        if(this.useDefaultAttributes === true) {
+            events['beforefeatureadded'] = this.onBeforeFeatureAdded;
+        }
+
+        layer.events.on(events);
     },
 
     /** private: method[setActiveLayer]
@@ -174,17 +206,37 @@
     setActiveLayer: function(layer) {
         this.activeLayer = layer;
         this.fireEvent("activelayerchanged", this, layer);
+
+        // 1st, destroy the old controls/actions
+
+        // 2nd, create new ones from the current active layer
+        this.initDrawControls(layer);
+        this.initFeatureControl(layer);
+        this.initDeleteAllAction();
+
     },
 
+    /** 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[initFeatureControl]
-     *  Create a ModifyFeature control linked to the current activeLayer and
+     *  :param layer: ``OpenLayers.Layer.Vector``
+     *  Create a ModifyFeature control linked to the passed layer and
      *  add it to the map.  An GeoExt.Action is also created and pushed to the
      *  actions array.
      */
-    initFeatureControl: function() {
-        var layer, control, options, actionOptions;
-
-        layer = this.activeLayer;
+    initFeatureControl: function(layer) {
+        var control, options, actionOptions;
         options = {};
 
         control = new OpenLayers.Control.ModifyFeature(
@@ -224,17 +276,17 @@
     },
 
     /** private: method[initDrawControls]
-     *  Create DrawFeature controls linked to the current activeLayer and
+     *  :param layer: ``OpenLayers.Layer.Vector``
+     *  Create DrawFeature controls linked to the passed layer and
      *  depending on its geometryType property and add them to the map.
      *  GeoExt.Action are also created and pushed to the actions array.
      */
-    initDrawControls: function() {
-        var layer, control, handler, geometryTypes, geometryType,
+    initDrawControls: function(layer) {
+        var control, handler, geometryTypes, geometryType,
                 options, action, iconCls, actionOptions, tooltip;
 
         geometryTypes = [];
         options = {};
-        layer = this.activeLayer;
 
         if (OpenLayers.i18n(layer.geometryType)) {
             geometryTypes.push(OpenLayers.i18n(layer.geometryType));
@@ -528,6 +580,29 @@
         this.reactivateDrawControl();
     },
 
+    /** 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.
+     */
+    onBeforeFeatureAdded: function(event) {
+        var feature, hasAttributes;
+
+        feature = event.feature;
+        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[]
      */
     reactivateDrawControl: function() {

Modified: sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeatureEditingPanel.js
===================================================================
--- sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeatureEditingPanel.js	2010-01-28 12:33:09 UTC (rev 1835)
+++ sandbox/redlining/ux/FeatureEditing/ux/widgets/form/FeatureEditingPanel.js	2010-01-28 19:46:52 UTC (rev 1836)
@@ -12,8 +12,8 @@
  *     
  *      var featureEditingPanel = new GeoExt.ux.form.FeatureEditingPanel({
  *          title: "RedLining Panel"
- *          map: map
- *          layers: [new OpenLayers.Layer.Vector("Cosmetic")]
+ *          map: map,
+ *          controler: controler
  *      });
  */
 
@@ -75,35 +75,6 @@
      */
     controler: null,
 
-    /** api: property[layers]
-     *  ``Array(OpenLayers.Layer.Vector)``
-     */
-    layers: null,
-
-    /** private: property[autoSave]
-     *  ``Boolean`` Enable the auto-save of any changes made to any feature
-     */
-    autoSave: true,
-
-    /** 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: property[useIcons]
-     *  ``Boolean``
-     *  If set to true, enables the use of image icons.  Must be combined with
-     *  a .css (see in resources/css).
-     */
-    useIcons: true,
-
     /** api: config[downloadService]
      *  ``String``  URL used in order to use a server download service. The attributes "format" and "content" are sent (POST) to this service.
      */
@@ -117,8 +88,6 @@
     initComponent: function() {
         this.initMap();
         this.initControler();
-        this.initLayers(this.layers);
-        this.initActions();
         this.initToolbar();
         this.initForm();
 
@@ -139,44 +108,18 @@
     },
 
     /** private: method[initControler]
-     *  Convenience method to make sure that the FeatureEditingControler has
+     *  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,
-                autoSave: this.autoSave,
-                useIcons: this.useIcons,
                 downloadService: this.downloadService
             });
         }
     },
 
-    /** private: method[initLayers]
-     *  :param layers: ``Array(OpenLayers.Layer.Vector)``
-     *  Add the layers to the controler and the first one as active.
-     */
-    initLayers: function(layers) {
-        if(layers instanceof Array) {
-            this.layers = layers;
-        } else {
-            this.layers = [layers];
-        }
-
-        this.controler.addLayers(this.layers);
-        this.controler.setActiveLayer(this.layers[0]);
-    },
-
-    /** private: method[initActions]
-     *  Initialize the controls of the controler resulting in creating actions.
-     */
-    initActions: function() {
-        this.controler.initDrawControls();
-        this.controler.initFeatureControl();
-        this.controler.initDeleteAllAction();
-    },
-
     /** private: method[initToolbar]
      *  
      */
@@ -203,11 +146,6 @@
     /** private: method[beforeDestroy]
      */
     beforeDestroy: function() {
-        if(!this.initialConfig.layers) {
-            for(var i=0; i<layers.length; i++) {
-                this.layers[i].destroy();
-            }
-        }
         delete this.controler;
         delete this.map;
     }

Modified: sandbox/redlining/ux/FeatureEditing/ux/widgets/form/RedLiningPanel.js
===================================================================
--- sandbox/redlining/ux/FeatureEditing/ux/widgets/form/RedLiningPanel.js	2010-01-28 12:33:09 UTC (rev 1835)
+++ sandbox/redlining/ux/FeatureEditing/ux/widgets/form/RedLiningPanel.js	2010-01-28 19:46:52 UTC (rev 1836)
@@ -36,13 +36,6 @@
  *  with all required controls and features.
  */
 GeoExt.ux.form.RedLiningPanel = Ext.extend(GeoExt.ux.form.FeatureEditingPanel, {
-    
-    /** api: config[attributes]
-     *  ``Array(String)``
-     *  An array of attribute names to used when a blank feature is added
-     *  to the map.
-     */
-    attributes: ['name','description'],
 
     /** api: config[layer]
      *  ``OpenLayers.Layer.Vector``
@@ -77,10 +70,23 @@
      */
     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);
 
         GeoExt.ux.form.RedLiningPanel.superclass.initComponent.call(this);
     },
@@ -155,38 +161,21 @@
             layer = new OpenLayers.Layer.Vector("Cosmetic", this.layerOptions);
         }
 
-        this.layers = [layer];
         this.layer = layer;
 
         layer.events.on({
-           "beforefeatureadded": this.onBeforeFeatureAdded,
            "beforefeatureselected": this.onBeforeFeatureSelect,
            "featureunselected": this.onFeatureUnselect,
             scope: this
         });
     },
 
-    /** 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.
-     */
-    onBeforeFeatureAdded: function(event) {
-        var feature, hasAttributes;
-
-        feature = event.feature;
-        hasAttributes = false;
-
-        for (var key in feature.attributes) {
-            hasAttributes = true;
-            break;
+    initControler: function() {
+        if(!this.controler){
+            this.controler = new GeoExt.ux.FeatureEditingControler({
+                layers: [this.layer]
+            });
         }
-
-        if(!hasAttributes) {
-            for(var i=0; i<this.attributes.length; i++) {
-                feature.attributes[this.attributes[i]] = '';
-            }
-        }
     },
 
    /** private: method[onFeatureSelect]



More information about the Commits mailing list