Changeset 334


Ignore:
Timestamp:
04/02/09 22:48:43 (9 years ago)
Author:
tschaub
Message:

Fixing the layer store add method (see #36).

Location:
sandbox/opengeo/geoexplorer
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sandbox/opengeo/geoexplorer/lib/GeoExt/data/LayerStore.js

    r320 r334  
    137137     */
    138138    onAddLayer: function(evt) {
    139         var layer = evt.layer;
    140         this._adding = true;
    141         this.add((this.reader.readRecords([layer])).records);
    142         delete this._adding;
     139        if(!this._adding) {
     140            var layer = evt.layer;
     141            this._adding = true;
     142            this.add((this.reader.readRecords([layer])).records);
     143            delete this._adding;
     144        }
    143145    },
    144146   
     
    151153     */
    152154    onRemoveLayer: function(evt){
    153         var layer = evt.layer;
    154         this._removing = true;
    155         this.remove(this.getById(layer.id));
    156         delete this._removing;
     155        if(!this._removing) {
     156            var layer = evt.layer;
     157            this._removing = true;
     158            this.remove(this.getById(layer.id));
     159            delete this._removing;
     160        }
    157161    },
    158162   
     
    168172    onAdd: function(store, records, index) {
    169173        if(!this._adding) {
     174            this._adding = true;
    170175            for(var i=0; i<records.length; ++i) {
    171176                this.map.addLayer(records[i].get("layer"));
    172177            }
     178            delete this._adding;
    173179        }
    174180    },
     
    185191    onRemove: function(store, record, index){
    186192        if(!this._removing) {
     193            this._removing = true;
    187194            this.map.removeLayer(record.get("layer"));
     195            delete this._removing;
    188196        }
    189197    }
  • sandbox/opengeo/geoexplorer/modifications.txt

    r328 r334  
    88 * Clone feature and layer in record.clone (see #34)
    99 * Set allOverlays in MapPanel (see #35)
     10 * Take care not to add records twice in LayerStore (see #36)
    1011 * Merge changes from trunk up to r319
    1112
  • sandbox/opengeo/geoexplorer/tests/lib/GeoExt/data/LayerStore.html

    r277 r334  
    22<html debug="true">
    33  <head>
    4     <script type="text/javascript" src="../../../../../../openlayers/lib/OpenLayers.js"></script>
    5     <script type="text/javascript" src="../../../../../../ext/2.2.1/adapter/ext/ext-base.js"></script>
    6     <script type="text/javascript" src="../../../../../../ext/2.2.1/ext-all-debug.js"></script>
     4    <script type="text/javascript" src="../../../../../openlayers/lib/OpenLayers.js"></script>
     5    <script type="text/javascript" src="../../../../../ext/adapter/ext/ext-base.js"></script>
     6    <script type="text/javascript" src="../../../../../ext/ext-all-debug.js"></script>
    77    <script type="text/javascript" src="../../../../lib/GeoExt.js"></script>
    88
     
    7474            t.eq(mapPanel.layers.getCount(),1,"Adding layers to MapPanel's LayerStore does not create duplicate layers");
    7575        }
     76       
     77        function test_add_remove(t) {
     78           
     79            t.plan(2);
     80           
     81            var map = new OpenLayers.Map("mappanel");
     82            var store = new GeoExt.data.LayerStore({
     83                map: map
     84            });
     85            var record = new GeoExt.data.LayerRecord({
     86                layer: new OpenLayers.Layer.Vector()
     87            });
     88
     89            store.add([record]);
     90            t.eq(store.getCount(), 1, "adding a single record to the store adds one record");
     91           
     92            store.remove(record);
     93            t.eq(store.getCount(), 0, "removing a single record from the store removes one record");
     94           
     95        }
     96       
    7697    </script>
    7798  <body>
Note: See TracChangeset for help on using the changeset viewer.