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 eventListeners

Let's demonstrate how to use event listeners. We'll start off with a simple example that will send an alert anytime the map finishes zooming.

  1. The first thing we'll need to do is to create a function that will get called by the event listener when some event happens. We'll have to do this for both the eventListeners method and the map.events.register method which we'll talk about shortly. Let's create a simple function that will send an alert when the user zooms in. Place this as the first line in your init() function, before your OpenLayers map code:
    function alert_on_zoom(event){ alert('You finished zooming'); }
  2. Next, we'll need to create our map object and pass in an eventListeners object. We'll want to listen ...

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