Chapter 11 — Building a Community Site 217
Loading a List of Types
The showentitylist()function loads the XML from the backend CGI script. It also
builds a list of types that the user can click to load the markers for a given entity. An identical
link is provided to hide existing markers:
function showentitylist() {
index = 0;
types = [];
message.innerHTML = ‘Select a business type’;
infopanel.innerHTML = ‘’;
var request = GXmlHttp.create();
request.open(‘GET’,’/examples/ch11-03.cgi?m=entitylist’, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlsource = request.responseXML;
var typelist = xmlsource.documentElement.getElementsByTagName(“type”);
for (var i=0;i < typelist.length;i++) {
types.push(typelist[i].getAttribute(“typename”));
infopanel.innerHTML = infopanel.innerHTML +
‘<a href=”#” onClick=”loadentity(‘ +
i +
‘);”>’ +
typelist[i].getAttribute(“typename”) +
‘ | ’ +
‘<a href=”#” onClick=”clearmarkers(‘ +
“‘“ + typelist[i].getAttribute(“typename”) + “‘“ +
‘);”>Hide ‘ +
typelist[i].getAttribute(“typename”) +
‘
’;
}
}
}
request.send(null);
}
The process is the by now familiar case of getting a list of individual matching XML tags and
extracting the attribute information to build the links.
Moving the Map
The movemap()function centers the map (using the latitude and longitude in the entity
objects) on a marker when its name is clicked from the loaded list of markers:
function movemap(index) {
map.recenterOrPanToLatLng(new GPoint(markers[index].lng,
markers[index].lat));
markers[index].marker.openInfoWindowXslt ;
(markers[index].info,”/examples/ch08-12.xsl”);
}