I am trying to loop through a number of encoded polylines and assign a
GEvent.addlistener that catches a mouseover event and appends some
html to a div. Unfortunately every span I mouseover gives the result
of the last span that was in the loop. I have researched it enough to
understand it has something to do with closures, which is as far as my
knowledge takes me.
Here is my loop:
GDownloadUrl("network/gen_span_xml.php", function(data) {
var xml = GXml.parse(data);
var spans = xml.documentElement.getElementsByTagName("span");
for (var i = 0; i < spans.length; i++) {
var span_id = spans[i].getAttribute("id");
var encoded_span = spans[i].getAttribute("encoded");
var encoded_levels = spans[i].getAttribute("levels");
var encoded_zoom_factor =
spans[i].getAttribute("zoom_factor");
var encoded_num_levels =
spans[i].getAttribute("num_levels");
var encodedPolyline = new GPolyline.fromEncoded({
color: '#0055ff',
weight: 4,
opacity: .5,
points: encoded_span,
levels: encoded_levels,
zoomFactor: encoded_zoom_factor,
numLevels: encoded_num_levels
});
GEvent.addListener(encodedPolyline, 'mouseover',
function() {
$("#alertDiv").empty().append(span_id);
});
map.addOverlay(encodedPolyline);
}
});
Thanks in advance.
--
You received this message because you are subscribed to the Google Groups
"Google Maps API V2" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-api?hl=en.