Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying OpenLayers 2.10 Beginner's Guide
  • Table Of Contents Toc
  • Feedback & Rating feedback
OpenLayers 2.10 Beginner's Guide

OpenLayers 2.10 Beginner's Guide

4.2 (9)
close
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
close
OpenLayers 2.10
In Progress | 0 / 1 sections completed | 0%
Credits
In Progress | 0 / 1 sections completed | 0%
About the Author
In Progress | 0 / 1 sections completed | 0%
About the Reviewers
In Progress | 0 / 1 sections completed | 0%
www.PacktPub.com
In Progress | 0 / 1 sections completed | 0%
Preface
In Progress | 0 / 1 sections completed | 0%
Index
In Progress | 0 / 1 sections completed | 0%

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
      }
    });
  4. Be sure to add a WMS layer to the map, along with setting the extent like we've done before. Now, open up the map and start navigating around it. When you zoom in, you should receive an alert. When you finish panning, the layer's...

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

Create a Note

Modal Close icon
You need to login to use this feature.
notes
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

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY