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 – working with feature events


Let's take a quick look at a couple of the previous Vector class methods.

  1. Open up the first example from the chapter—we'll be using Firebug, and we'll just need a vector layer and EditingToolbar control. We won't be editing any code, so open up the first example and Firebug's JavaScript console.

  2. We're going to add a function using preFeatureInsert that will display an alert containing the feature's ID. This function will be triggered before the feature is inserted into the map. Type and run the following in Firebug to create the function as follows:

    map.layers[1].preFeatureInsert = function(feature){ 
      alert('preFeatureInsert – ID: ' + feature.id) 
    };
  3. Take a look at the map now and add a point using the EditingToolbar control (or calling map.layers[1].addFeatures()). You should see an alert that will be triggered before the feature is added to the map that displays the ID of the soon to be added feature. Take note of the ID that the alert contains...