Open layers multiple mouseover events for multiple markers
- by Bren G.
I have the following loop inside an function init(); which is executed "onload", I am having traouble attaching the mouseover event for each marker, the alert i always returns the value of the last loop/iteration?
for(i=0; i<document.getElementById('departureSelect').options.length; i++){
var coords = eval(document.getElementById('departureSelect').options[i].value);
if(i==0){
window['popup'+i] = new OpenLayers.Marker(new OpenLayers.LonLat(coords[0], coords[1]),icon);
}else{
window['popup'+i] = new OpenLayers.Marker(new OpenLayers.LonLat(coords[0], coords[1]),icon.clone());
}
window['z'+i] = new OpenLayers.Popup.Anchored(coords[2],
new OpenLayers.LonLat(coords[0], coords[1]),
new OpenLayers.Size(0,0),
'<span class="country-label">' + coords[2] + '</span>',
icon,
false
);
window['z'+i].autoSize = true;
window['z'+i].setBorder('1px solid #888');
map.addPopup(window['z'+i]);
window['z'+i].hide();
window['popup'+i].events.register('mouseover', window['popup'+i], function(e){
alert(i); // only returns loast iteration of i?????
});
countries.addMarker(window['popup'+i]);
}