166 Part III — Google Map Hacks
Listing 9-13 (continued)
request.open(‘GET’,’/examples/ch09-11.cgi’, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlsource = request.responseXML;
var markerlist = ;
xmlsource.documentElement.getElementsByTagName(“marker”);
var infowindow = ;
xmlsource.documentElement.getElementsByTagName(“infowindow”);
for (var i=0;i < markerlist.length;i++) {
addmarker(parseFloat(markerlist[i].getAttribute(“lng”)),
parseFloat(markerlist[i].getAttribute(“lat”)),
markerlist[i].getAttribute(“title”),
infowindow[i]);
}
}
}
request.send(null);
}
}
function addmarker(x,y,title,info) {
var point = new GPoint(parseFloat(x),parseFloat(y));
points.push(point);
var marker = new GMarker(point);
GEvent.addListener(marker,
‘click’,
function() {
marker.openInfoWindowXslt(info,”/examples/ch09-12.xsl”);
}
);
map.addOverlay(marker);
infopanel.innerHTML = infopanel.innerHTML +
‘<a href=”#” onClick=”movemap(‘ + index + ‘);”>’ +
title +
‘</a><br/>’;
index++;
}
When parsing the XML, the onLoad()function extracts the data contained within the XML
tag infowindowand places each occurrence into an array, in exactly the same way as the orig-
inal marker tags were extracted.
A further argument is then added to the addmarker()function that incorporates the XML con-
tained within the infowindowtag, which in turn is used with the openInfoWindowXslt()
method on each marker. This method takes the XML (or an object containing the XML) and
URL of the XSL stylesheet (see Listing 9-12). The remainder of the code is identical to the other
examples.