OpenLayers OpenLayers

Ticket #577: layerswitcherMem.patch

File layerswitcherMem.patch, 2.7 kB (added by euzuro, 2 years ago)

dont add circular refs to inputElem. bind them into a context.

  • lib/OpenLayers/Control/LayerSwitcher.js

    old new  
    128128                inputElem.value = layer.name; 
    129129                inputElem.checked = checked; 
    130130                inputElem.defaultChecked = checked; 
    131                 inputElem.layer = layer; 
    132                 inputElem.control = this; 
    133131 
    134132                if (!baseLayer && !layer.inRange) { 
    135133                    inputElem.disabled = true; 
    136134                } 
     135                var context = { 
     136                    'inputElem': inputElem, 
     137                    'layer': layer, 
     138                    'layerSwitcher': this 
     139                } 
    137140                OpenLayers.Event.observe(inputElem, "mouseup",  
    138                               this.onInputClick.bindAsEventListener(inputElem)); 
     141                              this.onInputClick.bindAsEventListener(context)); 
    139142                 
    140143                // create span 
    141144                var labelSpan = document.createElement("span"); 
     
    143146                    labelSpan.style.color = "gray"; 
    144147                } 
    145148                labelSpan.innerHTML = layer.name; 
    146                 labelSpan.style.verticalAlign = (baseLayer) ? "bottom" : "baseline"; 
     149                labelSpan.style.verticalAlign = (baseLayer) ? "bottom"  
     150                                                            : "baseline"; 
    147151                OpenLayers.Event.observe(labelSpan, "click",  
    148                               this.onInputClick.bindAsEventListener(inputElem)); 
     152                              this.onInputClick.bindAsEventListener(context)); 
    149153                // create line break 
    150154                var br = document.createElement("br"); 
    151155     
     
    173177     *  
    174178     * @private 
    175179     *  
     180     * @context  
     181     *      {DOMElement} inputElem 
     182     *      {OpenLayers.Control.LayerSwitcher} layerSwitcher 
     183     *      {OpenLayers.Layer} layer 
     184     *  
    176185     * @param {Event} e 
    177186     */ 
    178187 
    179188    onInputClick: function(e) { 
    180         if (!this.disabled) { 
    181             if (this.type == "radio") { 
    182                 this.checked = true; 
     189 
     190        if (!this.inputElem.disabled) { 
     191            if (this.inputElem.type == "radio") { 
     192                this.inputElem.checked = true; 
    183193                this.layer.map.setBaseLayer(this.layer, true); 
    184194                this.layer.map.events.triggerEvent("changebaselayer"); 
    185195            } else { 
    186                 this.checked = !this.checked; 
    187                 this.control.updateMap(); 
     196                this.inputElem.checked = !this.checked; 
     197                this.layerSwitcher.updateMap(); 
    188198            } 
    189199        } 
    190200        OpenLayers.Event.stop(e);