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 – 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
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