216 Part III — Google Map Hacks
var map;
var index = 0;
var markindex = 0;
var types = [];
var markers = [];
var infopanel;
var message;
There are really only two critical global variables, the array of marker objects and the array
of entity types. The other globals relate to the main Google Map, and the infopaneland
messageobjects relate to the HTML DOM in the body of the page.
Entity Object
The entitymarkerobject is used to hold information about an individual marker that will
be added to the map. For convenience, the object includes the latitude, longitude, title, type,
marker, and XML to be used in an info window:
function entitymarker(lat,lng,title,type,marker,info) {
this.lat = lat;
this.lng = lng;
this.title = title;
this.type = type;
this.marker = marker;
this.info = info;
}
All of the information is recorded as attributes to the original object. In Chapter 9 arrays and
indexes were used to store and recover the information; here, the information is instead written
into a suitable object. You see some examples of where the object is used later in this chapter.
Initial Function
When the application is first loaded, the map is initialized, the global objects are initialized,
and the map is zoomed to a map of the U.K.:
function onLoad() {
if (GBrowserIsCompatible()) {
infopanel = document.getElementById(“infopanel”);
message = document.getElementById(“message”);
map = new GMap(document.getElementById(“map”));
map.centerAndZoom(new GPoint(-2.944336,53.644638), 10);
map.addControl(new GSmallZoomControl());
showentitylist();
}
}
The final stage is to load the list of entity types by calling the showentitylist()function.