1/* 2 * Javascript associated with googlemap plugin 3 * 4 * @author Borodin Oleg <onborodin@gmail.com> 5 */ 6 7/* 8 http://code.google.com/intl/ru/apis/maps/documentation/javascript/tutorial.html 9 http://code.google.com/intl/ru/apis/maps/documentation/javascript/controls.html 10 */ 11 12function dec2deg (dec) { 13 var dec_abs = Math.abs(dec); 14 var deg = Math.floor(dec_abs); 15 var min = Math.floor((dec_abs - deg)*60); 16 var sec = (((dec_abs - deg)*60 - min)*60).toFixed(4); 17 if (dec < 0) deg=-deg; 18 19 return (deg + '°' + min + '’' + sec + '”'); 20} 21 22function allMarkersVisible(map){ 23 var countOfMarkers = map.markerArray.length; 24 for (var m = 0; m < countOfMarkers; m++) { 25// map.markerArray[m].infoWindow.close(); 26 map.markerArray[m].setVisible(true); 27 } 28} 29 30 31function allInfoWindowClose(map){ 32 var countOfMarkers = map.markerArray.length; 33 for (var m = 0; m < countOfMarkers; m++) { 34 map.markerArray[m].infoWindow.close(); 35// map.markerArray[m].setVisible(true); 36 } 37} 38 39 40function attachDesc(marker) { 41 google.maps.event.addListener(marker, 'click', function() { 42 var map = marker.getMap(); 43 var countOfMarkers = marker.getMap().markerArray.length; 44 for (var m = 0; m < countOfMarkers; m++) { 45 map.markerArray[m].infoWindow.close(); 46 map.markerArray[m].setVisible(true); 47 } 48 49 map.tmpLat = map.getCenter().lat(); 50 map.tmpLng = map.getCenter().lng(); 51 map.markerHelper.setVisible(false); 52 map.markerHelper.infoWindow.close(); 53// marker.setVisible(false); 54 marker.infoWindow.setPosition(marker.getPosition()); 55 marker.infoWindow.open(marker.getMap()); // ...(marker.getMap()), marker) - corner to top marker 56 57 var currentInfoWindow = marker.infoWindow; 58 google.maps.event.addListener(currentInfoWindow, 'closeclick', 59 function(){ 60 var map = currentInfoWindow.map; 61 allMarkersVisible(map); 62 var tmpLatLng = new google.maps.LatLng(map.tmpLat, map.tmpLng); 63 map.panTo(tmpLatLng); 64 } 65 ) 66 }); 67} 68 69 70function attachHelper(map) { 71 google.maps.event.addListener(map, 'click', 72 function(event) { 73 var lat = event.latLng.lat(); 74 var lng = event.latLng.lng(); 75 var centerLatLng = map.getCenter(); 76 var clat = centerLatLng.lat(); 77 var clng = centerLatLng.lng(); 78 var zoom = map.getZoom(); 79 80 allInfoWindowClose(map); 81 82 var message = '<strong>Point latitude, longitude:</strong> <br />' + 83 lat.toFixed(7)+ ', ' + lng.toFixed(7) + '<br />' + 84 dec2deg(lat) + ', ' + dec2deg(lng) + '<br />' + 85 '<strong>Center latitude, longitude:</strong><br />' + 86 clat.toFixed(7)+ ', ' + clng.toFixed(7) + '<br />' + 87 '<strong>Zoom:</strong> ' + zoom; 88 89 map.markerHelper.setVisible(false); 90 map.markerHelper.setPosition(event.latLng); 91 map.markerHelper.infoWindow.close(); 92 map.markerHelper.infoWindow.setContent(message); 93 map.markerHelper.infoWindow.open(map, map.markerHelper); 94 } 95 ); 96} 97 98 99function attachPanTo(map) { 100 google.maps.event.addListener(map, 'click', 101 function(event) { 102 allInfoWindowClose(map); 103 map.panTo(event.latLng); 104 105 } 106 ); 107} 108 109function init_googlemap3() { 110 111 if (googleMapArray.length == 0) return; 112 113 var maptypes = { map : google.maps.MapTypeId.ROADMAP, 114 normal : google.maps.MapTypeId.ROADMAP, 115 hybrid : google.maps.MapTypeId.HYBRID, 116 satellite : google.maps.MapTypeId.SATELLITE, 117 terrain : google.maps.MapTypeId.TERRAIN 118 }; 119 120 // retrieve all google map containers 121 var nodes = document.body.getElementsByTagName('div'); 122 var i=0; 123 for (var j=0; j < nodes.length; j++) { 124 if (nodes[j].className.match(/\bgooglemap3\b/)) { 125 googleMapArray[i++].node = nodes[j]; 126 } 127 } 128 129 for (i=0; i < googleMapArray.length; i++) { 130 var navcont = (googleMapArray[i].controls == 'off') ? false : true; 131 var mapOptions = { 132 zoom: googleMapArray[i].zoom, 133 center: new google.maps.LatLng(googleMapArray[i].lat, googleMapArray[i].lng), 134 mapTypeId: maptypes[googleMapArray[i].type], 135 navigationControl: navcont, 136 draggableCursor: "crosshair", 137 draggingCursor: "move", 138 disableDoubleClickZoom: false, 139 keyboardShortcuts: false, 140 mapTypeContro: true, 141 mapTypeControlOptions: { 142 style: google.maps.MapTypeControlStyle.DROPDOWN_MENU 143// style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR 144 }, 145 zoomControl: navcont, 146 zoomControlOptions: { 147// style: google.maps.ZoomControlStyle.SMALL, 148 style: google.maps.ZoomControlStyle.LARGE, 149 position: google.maps.ControlPosition.LEFT_CENTER 150 }, 151 panControl: navcont, 152 panControlOptions: { 153 position: google.maps.ControlPosition.RIGHT_TOP 154 }, 155 streetViewControl: false, 156 streetViewControlOptions: { 157 position: google.maps.ControlPosition.TOP_LEFT 158 }, 159 scaleControl: navcont, 160 scaleControlOptions: { 161 position: google.maps.ControlPosition.BOTTOM_LEFT 162 }, 163 scrollwheel: false 164 }; 165 166 // extend google.maps.Map 167 googleMapArray[i].map = new google.maps.Map(googleMapArray[i].node, mapOptions); 168 googleMapArray[i].map.homeLatLng = new google.maps.LatLng(googleMapArray[i].lat, 169 googleMapArray[i].lng) 170 googleMapArray[i].map.tmpLat = 0; 171 googleMapArray[i].map.tmpLng = 0; 172// googleMapArray[i].map.parent = googleMapArray; 173// googleMapArray[i].map.number = i; 174 googleMapArray[i].map.markerArray = new Array(); 175 if (googleMapArray[i].overlay && googleMapArray[i].overlay.length > 0) { 176 for (j=0; j < googleMapArray[i].overlay.length; j++) { 177 googleMapArray[i].map.markerArray[j] = new google.maps.Marker({ 178 position: new google.maps.LatLng(googleMapArray[i].overlay[j].lat, 179 googleMapArray[i].overlay[j].lng), 180 clickable: true, 181 visible: true, 182 title: googleMapArray[i].overlay[j].msg, 183 }); 184 185 googleMapArray[i].map.markerArray[j].setMap(googleMapArray[i].map); 186 187 googleMapArray[i].map.markerArray[j].infoWindow = new google.maps.InfoWindow({ 188 content: googleMapArray[i].overlay[j].txt, 189 maxWidth: 600, 190 disableAutoPan: false, 191 size : new google.maps.Size(450, 350), 192// position: googleMapArray[i].map.markerArray[j].getPosition() 193 }); 194 195// googleMapArray[i].map.markerArray[j].setVisible(true); 196 197 // pointer to parents 198 googleMapArray[i].map.markerArray[j].infoWindow.map = googleMapArray[i].map; 199 googleMapArray[i].map.markerArray[j].infoWindow.marker = googleMapArray[i].map.markerArray[j]; 200 attachDesc(googleMapArray[i].map.markerArray[j]); 201 } 202 } 203 googleMapArray[i].map.markerHelper = new google.maps.Marker({ 204 clickable: true, 205 visible: false, 206 position: new google.maps.LatLng(0, 0) 207 }); 208 googleMapArray[i].map.markerHelper.setMap(googleMapArray[i].map); 209 googleMapArray[i].map.markerHelper.infoWindow = new google.maps.InfoWindow({ 210 maxWidth: 600, 211 disableAutoPan: false 212// size : new google.maps.Size(392, 120) 213 }); 214 215 if (googleMapArray[i].helper != 'off') { 216 attachHelper(googleMapArray[i].map); 217 } else { 218 attachPanTo(googleMapArray[i].map) 219 }; 220 221 if (googleMapArray[i].kml != 'off') { 222 var ctaLayer = new google.maps.KmlLayer(kml); 223 ctaLayer.setMap(googleMapArray[i].map); 224 } 225 } 226} /* init_googleMapArray */ 227 228var googleMapArray = new Array(); 229 230/* EOF googlemap3.js */ 231 232