new google maps api v3
[plewww.git] / googlemap / googlemap3.js
1 /* the googlemap plugin using api v3 since v2 is bout to be taken down end of 2013 */
2
3 /* this function should solve the issue of calling a function
4  * upon page load, that badly depends on the browser
5  * see an example in http://svn.planet-lab.org/wiki/GooglemapSetup
6  */
7 function onContent(f){
8   var 
9     a=onContent,
10     b=navigator.userAgent,
11     d=document,
12     w=window,
13     c="onContent",
14     e="addEventListener",
15     o="opera",
16     r="readyState",
17     s="<scr".concat("ipt defer src='//:' on",r,"change='if(this.",r,"==\"complete\"){this.parentNode.removeChild(this);",c,".",c,"()}'></scr","ipt>");
18   a[c]=(function(o){return function(){a[c]=function(){};for(a=arguments.callee;!a.done;a.done=1)f(o?o():o)}})(a[c]);
19   if(d[e])d[e]("DOMContentLoaded",a[c],false);
20   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)})();
21   else if(/MSIE/i.test(b))d.write(s);
22 }
23
24 /* the PLE snippet for embedding a googlemap in front page */
25 /*
26 <p><?php
27 drupal_set_html_head('<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=<...>&sensor=false"></script>');
28 drupal_add_js('googlemap/googlemap3.js',TRUE);
29 drupal_set_html_head('<script type="text/javascript">
30 function my_googlemap () { ts = new Date().getTime(); googlemap("map_area","http://www.planet-lab.eu/sites/sites.kml?" + ts,52,15,4);} 
31 onContent(my_googlemap);
32 </script>');
33 <div id="map_area" style="width: 640px; height: 480px">  </div></p>
34 ?>
35 */
36
37 function googlemap (htmlid,kmlurl,centerLat, centerLon, zoom) {
38     //  alert ('in googlemap, kmlurl='+kmlurl+',id ='+htmlid);
39     /* GBrowserIsCompatible was deprecated in v3
40        if (GBrowserIsCompatible()) ...
41     */
42
43     var center = new google.maps.LatLng(centerLat, centerLon);
44     var options = {
45         zoom: zoom,
46         center: center,
47         mapTypeId: google.maps.MapTypeId.SATELLITEMAP, /* ROADMAP */
48         panControl: true,
49         zoomControl: true,
50         mapTypeControl: true,
51         scaleControl: true,
52         streetViewControl: true,
53         overviewMapControl: true,
54         scrollwheel: false
55     }
56
57     var map = new google.maps.Map(document.getElementById(htmlid), options);
58
59     var layer_options = {
60         map: map,
61         preserveViewport: true,
62         /*suppressInfoWindows*/
63     };
64     var layer = new google.maps.KmlLayer(kmlurl, layer_options);
65 }
66
67 /* GUnload was deprecated in v3
68 window.onunload=GUnload; 
69 */