I have patched my OL 2.4 code to include a "layerswitched" event, and I think it makes sense and would be useful to have this in the OL trunk. This event is associated with a Layer object and is triggered by the LayerSwitcher control any time a layer (base or overlay) is clicked.
Here's my purpose - I've got multiple pairs of layers, a marker layer and a vector layer. One appears in the LayerSwitcher, the other does not. When the user selects or deselects the marker layer (causing its visibility to change), I need the "layerswitched" event to trigger on the layer that was clicked. The event handler for the clicked layer responds by changing the visibility of the other layer in the pair to match the one that was clicked.
I think this implementation makes a bit more logical sense than watching for the "changelayer" event at the Map level. There are many sources of the "changelayer" event, and dealing with them all at the map level would make the event handler more complex than necessary for this type of operation.
The change is to add "layerswitched" to the list of events in the OpenLayers.Layer class, then to add the following line to the end of the OpenLayers.Control.LayerSwitcher.onInputClick() method:
this.layer.events.triggerEvent("layerswitched");
(After line 242 in OL 2.4)
Submitted by Eric.Peterson@motorola.com