Hi Chris,
You don't attach the onClick event to the feature layer. You attach
it to each feature individually. Then you will have access to the
feature clicked on through the e.target property.
I'm pretty new with Leaflet myself, so this might not be the best way
to go about it, but I generally add individual features to an
L.FeatureGroup, then add the FeatureGroup to the map with
map.addLayer(). For each feature, I attach a click handler.
I think you can probably attach the click handlers in the featureParse
event handler as well, but here's an example of what I do:
// Plotting points on the map as cirlces (should work with lines or
polygons as well)
// records is an array of locations, brought back from a jQuery ajax
call
var circles = [];
$.each(records, function(index, value) {
var circleLocation = new L.LatLng(value.Latitude,
value.Longitude);
var circleOptions = {radius: 5, fillColor: '#00FF00'};
var circle = new L.CircleMarker(circleLocation,
circleOptions); // circleOptions is optional
circle.featureInfo = value; // featureInfo is not part of
Leaflet. I attach it here as a new property (thanks, JavaScript) so I
can use it later, in the click handler.
circle.on('click', function(e) {
// This is your click handler.
// Your feature is available here as e.target, and the
featureInfo object we added is available as e.target.featureInfo
});
circles.push(circle);
});
var group = new L.FeatureGroup(circles);
map.addLayer(group);
Hope this helps.
Aaron