I am using Bing Maps to implement putting multiple pins on a map. Whenever a pin is pressed I have an infobox popup and within the info box i have an edit button. When the edit button is pressed i want it to display the title associated for the pin (testing purposes). However, whenever I add a handler in my for loop for each pin only the last handler is used... For example if I add three pins with the titles: [hello, foo, bar], bar is displayed no matter what pin I click on... Here is what I am doing:
for ( var pos = 0; pos < locationsSize; pos++) {
var locationFromIndex = locations[pos];
var bingLocation = new Microsoft.Maps.Location(
locationFromIndex.latitude, locationFromIndex.longitude);
// Create/add the pin
var pin = new Microsoft.Maps.Pushpin(bingLocation, {
width : 25,
height : 39,
anchor : mAnchor
});
pins.push(pin);
// Create/add the pin info box
var pinInfobox = new Microsoft.Maps.Infobox(pin.getLocation(), {
title : locationFromIndex.type,
visible : false,
height : 75,
zIndex : i,
width : 150,
offset : mOffset,
})
pinInfobox.setOptions({
actions : [ {
label : "Edit",
eventHandler : function(mouseEvent) {
alert(pinInfobox.getTitle()); // Only the last eventHandler added is being used...
}
} ]
});
map.entities.push(pinInfobox);
}