O'Reilly logo

OpenLayers 2.10 by Erik Hazzard

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for Action – creating a custom TYPE_TOGGLE control

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.

  1. Open up the previous example. We'll be using that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required