Ticket #57: 57.4.patch

File 57.4.patch, 3.1 kB (added by tschaub, 1 year ago)

remove layer on record replace

  • tests/lib/GeoExt/data/LayerStore.html

    old new  
    169169 
    170170        function test_add_remove(t) { 
    171171             
    172             t.plan(2); 
     172            t.plan(6); 
    173173             
    174174            var map = new OpenLayers.Map("mappanel"); 
    175175            var store = new GeoExt.data.LayerStore({ 
     
    184184             
    185185            store.remove(record); 
    186186            t.eq(store.getCount(), 0, "removing a single record from the store removes one record"); 
     187 
     188            // add back the original and prepare to add copy 
     189            store.add([record]);             
     190            t.eq(store.getCount(), 1, "store has a single record before adding copy"); 
     191            t.eq(map.layers.length, 1, "map has a single layer before adding copy"); 
    187192             
     193            // create a copy of the record with the same layer 
     194            var copy = record.copy(); // record with same id will replace original 
     195            copy.set("layer", record.get("layer")); // force records to have same layer             
     196            store.add(copy); 
     197            t.eq(store.getCount(), 1, "store has a single record after adding copy"); 
     198            t.eq(map.layers.length, 1, "map has a single layer after adding copy"); 
     199             
    188200        } 
    189201         
    190202        function test_reorder(t) { 
  • lib/GeoExt/data/LayerStore.js

    old new  
    151151            "remove": this.onRemove, 
    152152            scope: this 
    153153        }); 
     154        this.data.on({ 
     155            "replace" : this.onReplace, 
     156            scope: this 
     157        }); 
    154158    }, 
    155159 
    156160    /** 
     
    170174            this.un("add", this.onAdd, this); 
    171175            this.un("remove", this.onRemove, this); 
    172176 
     177            this.data.un("replace", this.onReplace, this); 
     178 
    173179            this.map = null; 
    174180        } 
    175181    }, 
     
    324330            var layer = record.get("layer"); 
    325331            if (this.map.getLayer(layer.id) != null) { 
    326332                this._removing = true; 
    327                 this.map.removeLayer(record.get("layer")); 
     333                this.removeMapLayer(record); 
    328334                delete this._removing; 
    329335            } 
    330336        } 
     337    }, 
     338 
     339    /** 
     340     * Method: removeMapLayers 
     341     * Removes a record's layer from the bound map. 
     342     *  
     343     * Parameters: 
     344     * record - {<Ext.data.Record>} 
     345     */ 
     346    removeMapLayer: function(record){ 
     347        this.map.removeLayer(record.get("layer")); 
     348    }, 
     349 
     350    /** 
     351     * Method: onReplace 
     352     * Handler for a store's data collections' replace event 
     353     *  
     354     * Parameters: 
     355     * key - {String} 
     356     * oldRecord - {Object} In this case, a record that has been replaced. 
     357     * newRecord - {Object} In this case, a record that is replacing oldRecord. 
     358     */ 
     359    onReplace: function(key, oldRecord, newRecord){ 
     360        this.removeMapLayer(oldRecord); 
    331361    } 
    332362}; 
    333363