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 – working with Map events

  1. Before the map object is instantiated, let's create a function that will get called when the map's zoomend event is called. First, we'll create the function:
    function zoomend_event(event){
      alert('Done zooming');
    }
  2. Let's add another function after that which will update the first layer's opacity to a random value when the map is finished being moved. First, create the function:
    function update_opacity(event){
      map.layers[0].setOpacity(Math.random());
    }
  3. Now we're going to create the map object. Use the following code to instantiate the map object, passing in event listeners for zoomend and moveend:
    map = new OpenLayers.Map('map_element', { eventListeners: { 'zoomend': zoomend_event, 'moveend': update_opacity } ...

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