Open layers multiple mouseover events for multiple markers

Posted by Bren G. on Stack Overflow See other posts from Stack Overflow or by Bren G.
Published on 2010-04-14T07:17:50Z Indexed on 2010/04/14 7:23 UTC
Read the original article Hit count: 714

Filed under:
|

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]);


    }

© Stack Overflow or respective owner

Related posts about openlayers

Related posts about JavaScript