We're going to create a
TYPE_TOGGLE control button. We'll actually be using events in two ways. We'll use events to call a function when the control is activated/deactivated (i.e., toggled). This activated/deactivated concept is important, as we cannot use controls if they are not activated.
When the toggle control is activated, the
activate() function that gets called will add an event handler to the map. The map event handler will look for a click event and upon a click will call a function which updates the base layer's opacity. When the control is deactivated, the
deactivate() function that gets called will remove the map event handler.