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 – using control methods

Let's go through a quick example using some of the functions we just covered.

  1. Open up an existing map (any map is fine).
  2. In Firebug, input and run the following:
    var returned_controls = map.getControlsBy('active', true);
  3. Now, if that array is not empty, call the following. If the array is empty, it means that there are no active controls. Try to add some controls to your map until this function returns a non empty array:
    map.removeControl(returned_controls[0])

What Just Happened?

We just got an array of controls that were active and then removed the first item in the returned array from the map. If the returned_controls array is empty, calling removeControl will not do anything (you can't remove a null control). ...

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