Book Image

OpenLayers 2.10 Beginner's Guide

Book Image

OpenLayers 2.10 Beginner's Guide

Overview of this book

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

Time For Action – using Vector Layer events


Now that you know the possible event types, let's play around with some.

  1. Open up the first example from this chapter. We won't be editing the code, but instead we'll use Firebug again. We just need a vector layer and EditingToolbar control. As in the previous chapters, map.layers[1] is assumed to be the vector layer.

  2. Open up Firebug. We'll start off by registering a beforefeatureadded event to the map. First, like in Chapter 8, we need to create a listener function that will get called when the event fires. We know from the previous list of event types that the listener function will receive an object containing the feature, so let's create our function with a feature parameter that will reference the feature. In Firebug, create a function:

    function before_feature_added(feature){ console.log('before adding a feature!', feature); };
  3. All we have to do now is register the beforefeatureadded event on our vector layer:

    map.layers[1].events.register('beforefeatureadded...