开发者

Open layers multiple mouseover events for multiple markers

开发者 https://www.devze.com 2022-12-27 07:48 出处:网络
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 final

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 final loop/iteration (228)?

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 final iteration of i (228)?????

            });

            countries.addMarker(window['popup'+i]);


    }


After MANY hours I managed to find the solution:

window['popup'+i].events.register('mouseover', window['z'+i], function(e){ // pass through popup object
                this.show(); // show popup

});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号