
OpenLayers 2.10 Beginner's Guide

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.
Open up the previous example. We'll be using that as the basis for this example. We don't really need to change anything there, so let's go ahead and start creating our buttons!
First, we're going to create the function that will randomly change the map's base layer's opacity when the map is clicked...
Change the font size
Change margin width
Change background colour