1 2/* 3 * Javascript associated with googlemaps plugin 4 */ 5 6 7function in_array(needle, haystack) { 8 for (var i=0; i<haystack.length; i++) 9 if (haystack[i] == needle) return true; 10 11 return false; 12} 13 14// Creates a marker at the given point with the given number label 15// from http://www.google.com/apis/maps/documentation/#Display_Info_Windows_Above_Markers 16// with minor modifications 17function create_marker(point, text) { 18 var marker = new GMarker(point); 19 GEvent.addListener(marker, "click", function() { 20 marker.openInfoWindowHtml(text); 21 }); 22 return marker; 23} 24 25function init_googlemaps() { 26 27 // nothing to do? 28 if (googlemap.length == 0) return; 29 30 var maptypes = { map : G_NORMAL_MAP, 31 normal : G_NORMAL_MAP, 32 hybrid : G_HYBRID_MAP, 33 satellite : G_SATELLITE_MAP 34 }; 35 36 // retrieve all google map containers 37 var nodes = document.body.getElementsByTagName('div'); 38 39 var i=0; 40 for (var j=0; j<nodes.length; j++) { 41 if (nodes[j].className.match(/\bgooglemap\b/)) { 42 googlemap[i++].node = nodes[j]; 43 } 44 } 45 46 // iterate through all the map containers and set up each map 47 for (i=0; i<googlemap.length; i++) { 48 googlemap[i].map = new GMap2(googlemap[i].node); 49 50 with (googlemap[i]) { 51 if (controls == 'on') { 52 map.addControl(new GSmallMapControl()); 53 map.addControl(new GMapTypeControl()); 54 } 55 map.setCenter(new GLatLng(lat, lon), zoom); 56 57 var supported = map.getMapTypes(); 58 var requested = maptypes[type]; 59 60 map.setMapType(in_array(requested,supported) ? requested : supported[0]); 61 62 if (googlemap[i].overlay && overlay.length > 0) { 63 for (j=0; j<overlay.length; j++) { 64 map.addOverlay(create_marker(new GLatLng(overlay[j].lat,overlay[j].lon),overlay[j].txt)); 65 } 66 } 67 if (kml != 'off') { 68 var geoXml = new GGeoXml(kml); 69 map.addOverlay(geoXml); 70 } 71 72 } 73 } 74 75 76 addEvent(document.body, 'unload', GUnload); 77} 78 79 80var googlemap = new Array(); 81addInitEvent(init_googlemaps); 82