[Commits] r610 - in sandbox/opengeo/geoexplorer: . lib/GeoExt/data tests/lib/GeoExt/data

commits at geoext.org commits at geoext.org
Wed May 6 21:26:54 CEST 2009


Author: sbenthall
Date: 2009-05-06 21:26:54 +0200 (Wed, 06 May 2009)
New Revision: 610

Modified:
   sandbox/opengeo/geoexplorer/lib/GeoExt/data/LayerStore.js
   sandbox/opengeo/geoexplorer/modifications.txt
   sandbox/opengeo/geoexplorer/tests/lib/GeoExt/data/LayerStore.html
Log:
applied latest patch for #57


Modified: sandbox/opengeo/geoexplorer/lib/GeoExt/data/LayerStore.js
===================================================================
--- sandbox/opengeo/geoexplorer/lib/GeoExt/data/LayerStore.js	2009-05-06 19:24:42 UTC (rev 609)
+++ sandbox/opengeo/geoexplorer/lib/GeoExt/data/LayerStore.js	2009-05-06 19:26:54 UTC (rev 610)
@@ -151,6 +151,10 @@
             "remove": this.onRemove,
             scope: this
         });
+        this.data.on({
+            "replace" : this.onReplace,
+            scope: this
+        });
     },
 
     /**
@@ -170,6 +174,8 @@
             this.un("add", this.onAdd, this);
             this.un("remove", this.onRemove, this);
 
+            this.data.un("replace", this.onReplace, this);
+
             this.map = null;
         }
     },
@@ -324,10 +330,34 @@
             var layer = record.get("layer");
             if (this.map.getLayer(layer.id) != null) {
                 this._removing = true;
-                this.map.removeLayer(record.get("layer"));
+                this.removeMapLayer(record);
                 delete this._removing;
             }
         }
+    },
+
+    /**
+     * Method: removeMapLayers
+     * Removes a record's layer from the bound map.
+     * 
+     * Parameters:
+     * record - {<Ext.data.Record>}
+     */
+    removeMapLayer: function(record){
+        this.map.removeLayer(record.get("layer"));
+    },
+
+    /**
+     * Method: onReplace
+     * Handler for a store's data collections' replace event
+     * 
+     * Parameters:
+     * key - {String}
+     * oldRecord - {Object} In this case, a record that has been replaced.
+     * newRecord - {Object} In this case, a record that is replacing oldRecord.
+     */
+    onReplace: function(key, oldRecord, newRecord){
+        this.removeMapLayer(oldRecord);
     }
 };
 

Modified: sandbox/opengeo/geoexplorer/modifications.txt
===================================================================
--- sandbox/opengeo/geoexplorer/modifications.txt	2009-05-06 19:24:42 UTC (rev 609)
+++ sandbox/opengeo/geoexplorer/modifications.txt	2009-05-06 19:26:54 UTC (rev 610)
@@ -15,4 +15,4 @@
  * Let components do special processing before being added to or removed from a MapPanel (#45)
  * Add ScaleSlider and tips (#16)
  * Patch submitted. gxtheme css for geoext styles compatible with ext's xtheme (#51).
- * Keeping LayerStore and bound Map in sync when a record is replaced by add() method (and regression test) (#57)
+ * Patch submitted. Keeping LayerStore and bound Map in sync when a record is replaced by add() method (and regression test) (#57)

Modified: sandbox/opengeo/geoexplorer/tests/lib/GeoExt/data/LayerStore.html
===================================================================
--- sandbox/opengeo/geoexplorer/tests/lib/GeoExt/data/LayerStore.html	2009-05-06 19:24:42 UTC (rev 609)
+++ sandbox/opengeo/geoexplorer/tests/lib/GeoExt/data/LayerStore.html	2009-05-06 19:26:54 UTC (rev 610)
@@ -169,7 +169,7 @@
 
         function test_add_remove(t) {
             
-            t.plan(2);
+            t.plan(3);
             
             var map = new OpenLayers.Map("mappanel");
             var store = new GeoExt.data.LayerStore({
@@ -184,7 +184,14 @@
             
             store.remove(record);
             t.eq(store.getCount(), 0, "removing a single record from the store removes one record");
+
+            //test adding a record with the same id
+            store.add([record]);
+            store.add(store.getAt(0).copy());
+            t.eq(map.layers.length,store.getCount(),"number of OpenLayers map layers equals number of records after adding record with same id");
             
+
+            
         }
         
         function test_reorder(t) {



More information about the Commits mailing list