// Uses the next line to work // var map; function makeMap(dist_id) { if (GBrowserIsCompatible()) { var m = document.getElementById("map"); // create the map, and places the small controls as provided by Google on the map map = new GMap2(document.getElementById("map")); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); // Center the map in the center of Colorado in case it takes awhile to load the file map.setCenter(new GLatLng(39, -105), 8); // Call the KML Loader GetKML(dist_id) } else { // If anything fails... alert("your browser does not support Google Maps!"); } } function GetKML(districtid) { // Form the correct file names for each XMLfile // distid is defined so I don't have to write separate code for each map var theUrl = "http://www.comaps.org/kml/dist" + distid +".kml"; theUrl = theUrl.replace(/^\s+/, ""); theUrl = theUrl.replace(/\s+$/, ""); // Slightly complicated: // Will try to load theUrl provided, then activates the rest when it has // loaded correctly: // displays the KML and recenters the map on the loaded district var distKML = new GGeoXml(theUrl, function() { if (distKML.loadedCorrectly()) { distKML.gotoDefaultViewport(map); }}); map.addOverlay(distKML); map.setCenter(distKML.getDefaultCenter()); }