2 * performs the equivalent of <body onload=create_map onunload=GUnload>
3 * needs the allSites global var that is suppoesd to have been defined
4 * in /var/www/html/sites/plc-sites.js by plc-map.py
7 window.onDomReady = DomReady;
10 function DomReady(fn) {
12 if(document.addEventListener) {
13 document.addEventListener("DOMContentLoaded", fn, false);
16 document.onreadystatechange = function(){readyState(fn)}
21 function readyState(fn) {
22 // Thierry: initial version from the internet read
23 // if(document.readyState == "interactive")
24 // I have noticed that
25 // (*) on first load, I was hitting this point only once with complete
26 // (*) on reload I get here twice with "interactive" and then "complete"
27 // so as a quick'n dirty way :
28 if(document.readyState == "complete") {
33 window.onDomReady(create_map);
38 /* initial zoom level */
41 function decode_utf8( s )
43 return decodeURIComponent( escape( s ) );
46 function create_marker (map, point, site) {
47 var marker=new GMarker(point);
48 var html='<a href="/db/sites/index.php?id=' + site.site_id + '">' + decode_utf8(site.name) + '</a>\n';
49 html += '<br><a href="/db/nodes/index.php?site_id=' + site.site_id +'">' + site.nb_nodes + ' Nodes</a>\n';
51 html += '<br> <a href="/db/peers/index.php?id=' + site.peer_id + '">' + decode_utf8(site.peername) + '</a>\n';
53 /* display site name with url on info window - triggers on click */
54 GEvent.addListener(marker, 'click', function() {marker.openInfoWindowHtml(html);});
55 /* double click - clear info window */
56 GEvent.addListener(marker, 'dblclick', function() {marker.closeInfoWindow();});
57 /* required before setImage can be called */
58 map.addOverlay(marker);
59 /* set different layouts for local/foreign */
60 /* google originals are in http://maps.google.com/mapfiles/ms/icons/blue-dot.png or blue.png or ... */
63 marker.setImage('/misc/google-ple.png');
65 marker.setImage('/misc/google-plc.png');
70 function create_map() {
71 if (GBrowserIsCompatible()) {
72 var map = new GMap2(document.getElementById("googlemap"));
73 map.setCenter(new GLatLng(centerLat, centerLon), initZoom);
74 map.addControl(new GLargeMapControl());
75 map.addControl(new GMapTypeControl());
76 map.addControl(new GOverviewMapControl());
77 /*var geocoder = new GClientGeocoder();*/
78 map.setMapType(G_SATELLITE_MAP);
81 for (i=0;i<allSites.length;i++) {
83 /* discard unspecified sites, and sites with no nodes */
84 if ( (site.nb_nodes != 0) && ( (site.lat!=0.0) || (site.lon!=0.0)) ) {
85 var point = new GLatLng(site.lat,site.lon);
86 create_marker(map,point,site);
92 window.onunload=GUnload;