Ticket #90: geoext-90.patch

File geoext-90.patch, 7.5 kB (added by ahocevar, 1 year ago)

fix the problem at its root

  • tests/lib/GeoExt/widgets/tree/LayerContainer.html

    old new  
    5454            t.ok(node.firstChild.layer === layer, "child layer is correct"); 
    5555 
    5656            node.destroy(); 
    57             //map.destroy(); 
     57            map.destroy(); 
    5858             
    5959        } 
    6060         
     
    117117            t.eq(root.childNodes[3].layer.name, "c", "[c, a, b, d] first layer drawn at bottom of root"); 
    118118             
    119119            root.destroy(); 
    120             //map.destroy(); 
     120            map.destroy(); 
    121121             
    122122        } 
    123123         
  • lib/GeoExt/widgets/tree/LayerContainer.js

    old new  
    100100        } 
    101101    }, 
    102102 
    103     /** private: method[onDestroy] 
    104      */ 
    105     onDestroy: function() { 
    106         if(this.layerStore) { 
    107             this.layerStore.un("add", this.onStoreAdd, this); 
    108             this.layerStore.un("remove", this.onStoreRemove, this); 
    109         } 
    110         GeoExt.tree.LayerContainer.superclass.onDestroy.apply(this, arguments); 
    111     }, 
    112      
    113103    /** private: method[recordIndexToNodeIndex] 
    114104     *  :param index: ``Number`` The record index in the layer store. 
    115105     *  :return: ``Number`` The appropriate child node index for the record. 
     
    220210            this.layerStore.insert(newRecordIndex, [record]); 
    221211            delete this._reordering; 
    222212        } 
     213    }, 
     214 
     215    /** private: method[destroy] 
     216     */ 
     217    destroy: function() { 
     218        if(this.layerStore) { 
     219            this.layerStore.un("add", this.onStoreAdd, this); 
     220            this.layerStore.un("remove", this.onStoreRemove, this); 
     221        } 
     222        GeoExt.tree.LayerContainer.superclass.destroy.apply(this, arguments); 
    223223    } 
    224      
    225224}); 
    226225 
    227226/** 
  • lib/GeoExt/widgets/tree/LayerNode.js

    old new  
    6464        node.visibilityChanging = false; 
    6565    }, 
    6666     
    67     /** private: method[onDestroy] 
     67    /** private: method[destroy] 
    6868     */ 
    69     onDestroy: function() { 
     69    destroy: function() { 
    7070        delete this.radio; 
    71         GeoExt.tree.LayerNodeUI.superclass.onDestroy.call(this); 
     71        GeoExt.tree.LayerNodeUI.superclass.destroy.call(this); 
    7272    } 
    7373}); 
    7474 
     
    225225     *  state 
    226226     */ 
    227227    addVisibilityEventHandlers: function() { 
    228         this.layer.events.register("visibilitychanged", this, function() { 
    229             if(!this.visibilityChanging && 
    230                     this.attributes.checked != this.layer.getVisibility()) { 
    231                 this.getUI().toggleCheck(this.layer.getVisibility()); 
    232             } 
    233         }); 
     228        this.layer.events.on("visibilitychanged", this,  
     229                                            this.onLayerVisibilityChanged); 
    234230        this.on({ 
    235             "checkchange": function(node, checked) { 
    236                 if (checked && this.layer.isBaseLayer && this.layer.map) { 
    237                     this.layer.map.setBaseLayer(this.layer); 
    238                 } 
    239                 this.layer.setVisibility(checked); 
    240             }, 
     231            "checkchange": this.onCheckChange, 
    241232            scope: this 
    242233        }); 
    243234    }, 
    244235     
     236    /** private: method[onLayerVisiilityChanged 
     237     *  handler for visibilitychanged events on the layer 
     238     */ 
     239    onLayerVisibilityChanged: function() { 
     240        if(!this.visibilityChanging && 
     241                this.attributes.checked != this.layer.getVisibility()) { 
     242            this.getUI().toggleCheck(this.layer.getVisibility()); 
     243        } 
     244    }, 
     245     
     246    /** private: method[onCheckChange] 
     247     *  :param node: ``GeoExt.tree.LayerNode`` 
     248     *  :param checked: ``Boolean`` 
     249     *  handler for checkchange events  
     250     */ 
     251    onCheckChange: function(node, checked) { 
     252        if (checked && this.layer.isBaseLayer && this.layer.map) { 
     253            this.layer.map.setBaseLayer(this.layer); 
     254        } 
     255        this.layer.setVisibility(checked); 
     256    }, 
     257     
    245258    /** private: method[addStoreEventHandlers] 
    246259     *  Adds handlers that make sure the node disappeares when the layer is 
    247260     *  removed from the store, and appears when it is re-added. 
    248261     */ 
    249262    addStoreEventHandlers: function() { 
    250263        this.layerStore.on({ 
    251             "add": function(store, records, index) { 
    252                 var l; 
    253                 for(var i=0; i<records.length; ++i) { 
    254                     l = records[i].get("layer"); 
    255                     if(this.layer == l) { 
    256                         this.getUI().show(); 
    257                     } else if (this.layer == l.name) { 
    258                         // layer is a string, which means the node has not yet 
    259                         // been rendered because the layer was not found. But 
    260                         // now we have the layer and can render. 
    261                         this.render(bulkRender); 
    262                         return; 
    263                     } 
    264                 } 
    265             }, 
    266             "remove": function(store, record, index) { 
    267                 if(this.layer == record.get("layer")) { 
    268                     this.getUI().hide(); 
    269                 } 
    270             }, 
     264            "add": this.onStoreAdd, 
     265            "remove": this.onStoreRemove, 
    271266            scope: this 
    272267        }); 
    273268    }, 
    274269     
     270    /** private: method[onStoreAdd] 
     271     *  :param store: ``Ext.data.Store`` 
     272     *  :param records: ``Array(Ext.data.Record)`` 
     273     *  :param index: ``Nmber`` 
     274     *  handler for add events on the store  
     275     */ 
     276    onStoreAdd: function(store, records, index) { 
     277        var l; 
     278        for(var i=0; i<records.length; ++i) { 
     279            l = records[i].get("layer"); 
     280            if(this.layer == l) { 
     281                this.getUI().show(); 
     282            } else if (this.layer == l.name) { 
     283                // layer is a string, which means the node has not yet 
     284                // been rendered because the layer was not found. But 
     285                // now we have the layer and can render. 
     286                this.render(bulkRender); 
     287                return; 
     288            } 
     289        } 
     290    }, 
     291     
     292    /** private: method[onStoreRemove] 
     293     *  :param store: ``Ext.data.Store`` 
     294     *  :param record: ``Ext.data.Record`` 
     295     *  :param index: ``Nmber`` 
     296     *  handler for remove events on the store  
     297     */ 
     298    onStoreRemove: function(store, record, index) { 
     299        if(this.layer == record.get("layer")) { 
     300            this.getUI().hide(); 
     301        } 
     302    }, 
     303     
    275304    /** private: method[addChildNodes] 
    276305     *  Calls the add method of a node type configured as ``childNodeType`` 
    277306     *  to add children. 
     
    282311        } else if(typeof this.childNodeType.add === "function") { 
    283312            this.childNodeType.add(this); 
    284313        } 
     314    }, 
     315     
     316    /** private: method[destroy] 
     317     */ 
     318    destroy: function() { 
     319        this.layer.events.un("visibilitychanged", this,  
     320                                            this.onLayerVisibilityChanged); 
     321        delete this.layer; 
     322        this.layerStore.un("add", this.onStoreAdd, this); 
     323        this.layerStore.un("remove", this.onStoreRemove, this); 
     324        delete this.layerStore; 
     325        this.un("checkchange", this.onCheckChange, this); 
     326 
     327        GeoExt.tree.LayerNode.superclass.destroy.call(this); 
    285328    } 
    286329}); 
    287330