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

commits at geoext.org commits at geoext.org
Fri May 1 21:20:37 CEST 2009


Author: sbenthall
Date: 2009-05-01 21:20:37 +0200 (Fri, 01 May 2009)
New Revision: 583

Modified:
   sandbox/opengeo/geoexplorer/lib/GeoExt/data/LayerStore.js
   sandbox/opengeo/geoexplorer/modifications.txt
   sandbox/opengeo/geoexplorer/tests/lib/GeoExt/data/LayerStore.html
Log:
patch to keep LayerStore in sync with Map when a record is replaced


Modified: sandbox/opengeo/geoexplorer/lib/GeoExt/data/LayerStore.js
===================================================================
--- sandbox/opengeo/geoexplorer/lib/GeoExt/data/LayerStore.js	2009-05-01 19:15:39 UTC (rev 582)
+++ sandbox/opengeo/geoexplorer/lib/GeoExt/data/LayerStore.js	2009-05-01 19:20:37 UTC (rev 583)
@@ -110,6 +110,10 @@
                 "remove": this.onRemove,
                 scope: this
             });
+            this.data.on({
+                "replace" : this.onReplace,
+                scope: this
+            });
         }
     },
 
@@ -130,6 +134,10 @@
                 "remove": this.onRemove,
                 scope: this
             });
+            this.data.un({
+                "replace" : this.onReplace,
+                scope: this
+            });
             this.map = null;
         }
     },
@@ -236,6 +244,19 @@
             this.map.removeLayer(record.get("layer"));
             delete this._removing;
         }
+    },
+
+    /**
+     * 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.remove(oldRecord);
     }
 };
 

Modified: sandbox/opengeo/geoexplorer/modifications.txt
===================================================================
--- sandbox/opengeo/geoexplorer/modifications.txt	2009-05-01 19:15:39 UTC (rev 582)
+++ sandbox/opengeo/geoexplorer/modifications.txt	2009-05-01 19:20:37 UTC (rev 583)
@@ -15,3 +15,4 @@
  * Let components do special processing before being added to or removed from a MapPanel (#45)
  * Add ScaleSlider and tips (#16)
  * 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)

Modified: sandbox/opengeo/geoexplorer/tests/lib/GeoExt/data/LayerStore.html
===================================================================
--- sandbox/opengeo/geoexplorer/tests/lib/GeoExt/data/LayerStore.html	2009-05-01 19:15:39 UTC (rev 582)
+++ sandbox/opengeo/geoexplorer/tests/lib/GeoExt/data/LayerStore.html	2009-05-01 19:20:37 UTC (rev 583)
@@ -76,7 +76,7 @@
         
         function test_add_remove(t) {
             
-            t.plan(2);
+            t.plan(3);
             
             var map = new OpenLayers.Map("mappanel");
             var store = new GeoExt.data.LayerStore({
@@ -91,7 +91,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