Newer
Older
Digital_Repository / Repositories / Maps / google_map.js
function load( startMillis, numEntries, showOnly, eprintIDs )
{
	if ( GBrowserIsCompatible() )
	{
		// Create new map.
		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 a label
		// containing the other remaining arguments.
		function createMarker( point, city, abstracts, downloads )
		{
			var marker = new GMarker( point );
			GEvent.addListener( marker, "click",
				function()
				{
					marker.openInfoWindowHtml( "<strong>" + city + "</strong> (" +
						abstracts + " abstracts, " +
						downloads + " downloads)" );
				} );
			return marker;
		}
	
		// Download the data and load it on the map.
		// The format we expect is:
		// <markers abs="200" ua="1" dl="100" ud="5" ips="27">
		//   <marker city="Timbuktu" lat="37.441" long="-122.141" abs="10" dl="0" />
		//   <marker city="West Bromwich" lat="37.322" long="-121.213" abs="22" dl="49" />
		// </markers>
		GDownloadUrl( "google_map_generate_data.pl?top=" + numEntries
			+ "&show=" + showOnly + "&eprint=" + eprintIDs,
			function( data, responseCode )
			{
				var xml = GXml.parse( data );
				var markerlist = xml.documentElement.getElementsByTagName( "marker" );
				for ( var i = 0; i < markerlist.length; i++ )
				{
					var point = new GLatLng( parseFloat( markerlist[i].getAttribute( "lat" ) ),
						parseFloat( markerlist[i].getAttribute( "long" ) ) );
					map.addOverlay( createMarker( point, markerlist[i].getAttribute( "city" ),
						markerlist[i].getAttribute( "abs" ), markerlist[i].getAttribute( "dl" ) ) );
				}
				var numA = xml.documentElement.getAttribute( "abs" );
				var numD = xml.documentElement.getAttribute( "dl" );
				var numUA = xml.documentElement.getAttribute( "ua" );
				var numUD = xml.documentElement.getAttribute( "ud" );
				// Grab finishing time. We have to do this here rather than in
				// the main part of the load() function because the map data
				// are loaded asynchronously.
				var endTime = new Date();
				document.getElementById( "timer" ).innerHTML =
					( ( numD > 0 )
					  ? ( '<span style="color:red;">' + numD + ' downloads'
					    + ( ( numUD > 0 ) ? ( ' (+' + numUD + ' unmappable)' ) : '' )
					    + '</span> '
					    + ( ( numA > 0 ) ? '& ' : '' ) )
					  : '' )
					+ ( ( numA > 0 )
					    ? ( '<span style="color:blue;">' + numA + ' abstracts'
					      + ( ( numUD > 0 ) ? ( ' (+' + numUA + ' unmappable)' ) : '' )
					      + '</span> ' )
					    : '' )
					+ 'from ' + markerlist.length + ' cities ('
					+ xml.documentElement.getAttribute( "ips" )
					+ ' IP addresses), page generated in '
					+ ( endTime - startMillis ) + ' ms.';
			} );
	}
}