[Commits] r292 - core/trunk/geoext/lib/GeoExt/data

commits at geoext.org commits at geoext.org
Mon Mar 30 12:58:37 CEST 2009


Author: elemoine
Date: 2009-03-30 12:58:37 +0200 (Mon, 30 Mar 2009)
New Revision: 292

Modified:
   core/trunk/geoext/lib/GeoExt/data/LayerStore.js
Log:
LayerStore: use bind/unbind to enable/disable synchronization, r=tschaub (closes #30)


Modified: core/trunk/geoext/lib/GeoExt/data/LayerStore.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/data/LayerStore.js	2009-03-29 21:09:12 UTC (rev 291)
+++ core/trunk/geoext/lib/GeoExt/data/LayerStore.js	2009-03-30 10:58:37 UTC (rev 292)
@@ -65,9 +65,10 @@
         config = config || {};
         config.reader = config.reader ||
                         new GeoExt.data.LayerReader({}, config.recordType);
+        var map = config.map instanceof GeoExt.MapPanel ?
+                  config.map.map : config.map;
+        delete config.map;
         arguments.callee.superclass.constructor.call(this, config);
-        var map = config.map instanceof GeoExt.MapPanel ?
-            config.map.map : config.map;
         if(map) {
             // create a snapshop of the map's layers
             var layers = map.layers;
@@ -78,32 +79,56 @@
                 this.add((this.reader.readRecords([layer])).records);
             }
 
-            this.setMap(map);
+            this.bind(map);
             config.layers && map.addLayers(config.layers);
         }
     },
-    
+
     /**
-     * APIMethod: setMap
+     * APIMethod: bind
+     * Bind this store to a map instance, once bound the store
+     * is synchronized with the map and vice-versa.
      * 
      * Parameters:
-     * map - {OpenLayers.Map}
+     * map - {OpenLayers.Map} The map instance.
      */
-    setMap: function(map) {
-        this.map = map;
-        map.events.on({
-            "addlayer": this.onAddLayer,
-            "removelayer": this.onRemoveLayer,
-            scope: this
-        });
-        this.on({
-            "add": this.onAdd,
-            "remove": this.onRemove,
-            scope: this
-        });
+    bind: function(map) {
+        if(!this.map) {
+            this.map = map;
+            map.events.on({
+                "addlayer": this.onAddLayer,
+                "removelayer": this.onRemoveLayer,
+                scope: this
+            });
+            this.on({
+                "add": this.onAdd,
+                "remove": this.onRemove,
+                scope: this
+            });
+        }
     },
-    
+
     /**
+     * APIMethod: unbind
+     * Unbind this store from the map it is currently bound.
+     */
+    unbind: function() {
+        if(this.map) {
+            this.map.events.un({
+                "addlayer": this.onAddLayer,
+                "removelayer": this.onRemoveLayer,
+                scope: this
+            });
+            this.un({
+                "add": this.onAdd,
+                "remove": this.onRemove,
+                scope: this
+            });
+            this.map = null;
+        }
+    },
+   
+    /**
      * Method: onAddLayer
      * Handler for a map's addlayer event
      * 



More information about the Commits mailing list