792534357cafd6405a33b0733f940ba17dff5106
[plewww.git] / googlemap / googlemap.js
1 /* this function should solve the issue of calling a function
2  * upon page load, that badly depends on the browser
3  * see an example in http://svn.planet-lab.org/wiki/GooglemapSetup
4  */
5 function onContent(f){
6   var 
7     a=onContent,
8     b=navigator.userAgent,
9     d=document,
10     w=window,
11     c="onContent",
12     e="addEventListener",
13     o="opera",
14     r="readyState",
15     s="<scr".concat("ipt defer src='//:' on",r,"change='if(this.",r,"==\"complete\"){this.parentNode.removeChild(this);",c,".",c,"()}'></scr","ipt>");
16   a[c]=(function(o){return function(){a[c]=function(){};for(a=arguments.callee;!a.done;a.done=1)f(o?o():o)}})(a[c]);
17   if(d[e])d[e]("DOMContentLoaded",a[c],false);
18   if(/WebKit|Khtml/i.test(b)||(w[o]&&parseInt(w[o].version())<9))(function(){/loaded|complete/.test(d[r])?a[c]():setTimeout(arguments.callee,1)})();
19   else if(/MSIE/i.test(b))d.write(s);
20 }
21
22 function googlemap (htmlid,kmlurl,centerLat, centerLon, zoom) {
23   //  alert ('in googlemap, kmlurl='+kmlurl+',id ='+htmlid);
24   if (GBrowserIsCompatible()) {
25     var map = new GMap2(document.getElementById(htmlid));
26     map.setCenter(new GLatLng(centerLat, centerLon), zoom);
27     map.addControl(new GLargeMapControl());
28     map.addControl(new GMapTypeControl());
29     map.addControl(new GOverviewMapControl());
30     /*var geocoder = new GClientGeocoder();*/
31     map.setMapType(G_SATELLITE_MAP);
32     
33     geoXml = new GGeoXml(kmlurl);
34     map.addOverlay(geoXml);
35   }
36 }
37
38 window.onunload=GUnload;