javascript - Dynamically adding listeners in Google Maps where iframe src is set differently for each marker -
hi i've read articles , excellent piece on scope , closures robert nyman. cannot work. i'm trying assign mouseover event various markers , set iframe src depending on marker moused over. infamous last entry every mouseover event. i've played better part of few days , not 'thinking fluid' helping :). guidance appreciated
for(var i=0; i
var latlngr = new google.maps.latlng(mylatd,mylongd); markerno = "marker_"+i; markerarray[i] = new google.maps.marker({ position: latlngr, map: map, title:myname }); google.maps.event.addlistener(markerarray[i], 'mouseover', function(markerno) {return function() { mysrc = 'http://adds.aviationweather.gov/metars/index.php?submit=1&station_ids='+myicao+'&chk_metars=on&chk_tafs=on&std_trans=translated'; alert (mysrc); $('#weather').attr({src: mysrc}); }(markerno) }); }
i think can solve problem wrapping block in self-executing wrapper function:
for(var = 0; < somelength; i++) (function(i){ // internal code here. bound it's value in correct context })(i);
Comments
Post a Comment