diff --git a/Repositories/Maps/google_map.js b/Repositories/Maps/google_map.js new file mode 100755 index 0000000..28d0462 --- /dev/null +++ b/Repositories/Maps/google_map.js @@ -0,0 +1,53 @@ +function load() +{ + var startTime = new Date(); + + var timer = document.getElementById( "timer" ); + timer.innerHTML = "Loading..."; + + var code = document.getElementById( "code" ); + + if ( GBrowserIsCompatible() ) + { + var map = new GMap2( document.getElementById( "map" ) ); + map.addControl( new GSmallMapControl() ); + map.addControl( new GMapTypeControl() ); + map.setCenter( new GLatLng(10, 0), 2 ); + + // Creates a marker at the given point with the given label + function createMarker( point, city, abstracts, downloads ) + { + var marker = new GMarker( point ); + GEvent.addListener( marker, "click", + function() + { + marker.openInfoWindowHtml( "" + city + " (" + + abstracts + " abstracts, " + + downloads + " downloads)" ); + } ); + return marker; + } + + // Download the data in google_map_data.xml and load it on the map. The format we + // expect is: + // + // + // + // + GDownloadUrl( "google_map_data.xml", + function( data, responseCode ) + { + var xml = GXml.parse( data ); + var markers = xml.documentElement.getElementsByTagName( "marker" ); + for ( var i = 0; i < markers.length; i++ ) + { + var point = new GLatLng( parseFloat( markers[i].getAttribute( "lat" ) ), + parseFloat( markers[i].getAttribute( "lng" ) ) ); + map.addOverlay( createMarker( point, markers[i].getAttribute( "city" ), + markers[i].getAttribute( "abs" ), markers[i].getAttribute( "dl" ) ) ); + } + var endTime = new Date(); + timer.innerHTML = markers.length + " cities plotted in " + ( endTime - startTime ) + " ms."; + } ); + } +}