Time For Action – working with feature events
Let's take a quick look at a couple of the previous Vector class methods.
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.
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) };
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...