| 1 | <?php |
|---|
| 2 | require_once 'include/_universal.php'; |
|---|
| 3 | $x = new universal('map','',0); |
|---|
| 4 | global $lan, $dbc; |
|---|
| 5 | |
|---|
| 6 | if ($x->is_secure()) { |
|---|
| 7 | $x->display_top(); |
|---|
| 8 | |
|---|
| 9 | ?> |
|---|
| 10 | <div id="map_canvas" style="min-height: 500px; width: 100%; height: 100%;">Loading...</div> |
|---|
| 11 | <div id="zoom_to_fit" style="cursor: pointer;color: black; background: white; border: 1px solid black; z-index: 10000; position: absolute;" onclick="zoom_to_fit();">Zoom to fit</div> |
|---|
| 12 | <div style="text-align: right; color:white;">last click was lat: <span id="map_lat" style="font-weight: bold">?</span>, long: <span id="map_long" style="font-weight: bold">?</span></div> |
|---|
| 13 | |
|---|
| 14 | <script type="text/javascript"> |
|---|
| 15 | |
|---|
| 16 | var map; |
|---|
| 17 | var userlist = [ |
|---|
| 18 | <?php |
|---|
| 19 | $data = $dbc->database_query('SELECT username, longitude, latitude FROM users WHERE latitude IS NOT NULL AND latitude != 0 AND longitude IS NOT NULL AND longitude != 0 ORDER BY userid ASC'); |
|---|
| 20 | $count = $dbc->database_num_rows($data); |
|---|
| 21 | if ($count) { |
|---|
| 22 | $index = 0; |
|---|
| 23 | while($row = $dbc->database_fetch_assoc($data)) { |
|---|
| 24 | $index++; |
|---|
| 25 | printf(" ['%s', %f, %f ]%s\n", $row['username'], $row['latitude'], $row['longitude'],($index == $count) ? '' : ','); |
|---|
| 26 | } |
|---|
| 27 | } |
|---|
| 28 | ?> |
|---|
| 29 | ]; |
|---|
| 30 | |
|---|
| 31 | </script> |
|---|
| 32 | <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> |
|---|
| 33 | <script type="text/javascript"> |
|---|
| 34 | |
|---|
| 35 | var center; |
|---|
| 36 | |
|---|
| 37 | /* Basic loading of the google map */ |
|---|
| 38 | function initialize() { |
|---|
| 39 | var docelement = document.getElementById("map_canvas"); |
|---|
| 40 | var setLon = <?php echo $lan['longitude']; ?>; |
|---|
| 41 | var setLat = <?php echo $lan['latitude']; ?>; |
|---|
| 42 | center = new google.maps.LatLng(setLat,setLon); |
|---|
| 43 | var myOptions = { |
|---|
| 44 | zoom: 8, |
|---|
| 45 | center: center, |
|---|
| 46 | mapTypeId: google.maps.MapTypeId.ROADMAP |
|---|
| 47 | }; |
|---|
| 48 | map = new google.maps.Map(docelement, myOptions); |
|---|
| 49 | |
|---|
| 50 | var marker = new google.maps.Marker({ |
|---|
| 51 | position: center, |
|---|
| 52 | map: map, |
|---|
| 53 | title: "EuroNARP 2008", |
|---|
| 54 | zIndex: 100 |
|---|
| 55 | }); |
|---|
| 56 | setMarkers(map, userlist); |
|---|
| 57 | |
|---|
| 58 | google.maps.event.addListener(map, 'click', function(event) { |
|---|
| 59 | setLatLong(event.latLng); |
|---|
| 60 | }); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | document.body.onload = initialize(); |
|---|
| 64 | |
|---|
| 65 | /* Function to round coordinates to X decimals */ |
|---|
| 66 | function roundCoord(number, dec) { |
|---|
| 67 | return Math.round(number * Math.pow(10,dec)) / Math.pow(10,dec); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | function setLatLong(latLng) { |
|---|
| 72 | var lat = document.getElementById('map_lat'); |
|---|
| 73 | var long = document.getElementById('map_long'); |
|---|
| 74 | lat.innerHTML = '' + roundCoord(latLng.lat(), 6); |
|---|
| 75 | long.innerHTML = '' + roundCoord(latLng.lng(), 6); |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | function setMarkers(map, locations) { |
|---|
| 79 | // Add markers to the map |
|---|
| 80 | for (var i = 0; i < locations.length; i++) { |
|---|
| 81 | var user = locations[i]; |
|---|
| 82 | var myLatLng = new google.maps.LatLng(user[1], user[2]); |
|---|
| 83 | var image = 'img/userhead.png'; |
|---|
| 84 | var marker = new google.maps.Marker({ |
|---|
| 85 | position: myLatLng, |
|---|
| 86 | map: map, |
|---|
| 87 | title: user[0], |
|---|
| 88 | icon: image |
|---|
| 89 | }); |
|---|
| 90 | } |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | function zoom_to_fit() { |
|---|
| 94 | var area = new google.maps.LatLngBounds(); |
|---|
| 95 | area.extend(center); |
|---|
| 96 | for (var i = 0; i < userlist.length; i++) { |
|---|
| 97 | var user = userlist[i]; |
|---|
| 98 | area.extend(new google.maps.LatLng(user[1], user[2])); |
|---|
| 99 | } |
|---|
| 100 | map.fitBounds(area); |
|---|
| 101 | map.set_zoom(map.get_zoom() -1); |
|---|
| 102 | // map.setCenter( area.getCenter( ), map.getBoundsZoomLevel( area ) ); |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | </script> |
|---|
| 108 | <?php |
|---|
| 109 | } |
|---|
| 110 | $x->display_bottom(); |
|---|
| 111 | |
|---|
| 112 | ?> |
|---|