Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • OpenLayers 2.10 Beginner's Guide
  • Toc
  • feedback
OpenLayers 2.10 Beginner's Guide

OpenLayers 2.10 Beginner's Guide

4.2 (9)
close
OpenLayers 2.10 Beginner's Guide

OpenLayers 2.10 Beginner's Guide

4.2 (9)

Overview of this book

Table of Contents (18 chapters)
close
OpenLayers 2.10
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 for a zoomend event type, which is an event that happens when the map has finished zooming. So, the key inside our eventListeners object will be the event type, which is 'zoomend'. The value will be the name of the function we wish to get called...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete