- Renamed "coordinates" to "gd_map".
- Added JavaScript and HTML for GD map.
- Finished off Google map timing code.
- Updated layout of web pages.
1 parent 54f5a1f commit 3ec725f5e1bb70e9ead0de8aeeab135e897685d4
nstanger authored on 12 May 2006
Showing 6 changed files
View
80
Repositories/Maps/gd_map.js 0 → 100755
/******************************************************************************
* Code adapted from Rasmus' 30 second AJAX Tutorial at:
* http://rajshekhar.net/blog/archives/85-Rasmus-30-second-AJAX-Tutorial.html
******************************************************************************/
 
/******************************************************************************
* Create XMLHttpRequest object. This happens once when the page
* is loaded.
*/
function createRequestObject()
{
var ro;
var browser = navigator.appName;
// In typical fashion, Microsoft does things differently.
if (browser == "Microsoft Internet Explorer")
{
ro = new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
ro = new XMLHttpRequest();
}
return ro;
}
 
// Global XMLHttpRequest object.
var http = createRequestObject();
 
/******************************************************************************
* Send a request to the back end application (written in PHP here, but
* could be ASP, Java servlets, etc.). To use this, attach it to an (X)HTML
* element either as a direct link, e.g.:
*
* <a href="javascript:sendRequest('foo', 'on')">[foo]</a>
*
* or via an onclick event, e.g.:
*
* <img src="foo.jpg" onclick="javascript:sendRequest('foo', 'off')" />
*
* If you need different handlers for different things, just create them as
* separate PHP files on the back end, and dispatch appropriately from here.
* For example, if you want a separate handler for database operations, you
* could add another function called "sendDBRequest", or something similar.
*/
function load()
{
// Somewhere to write the timing information to.
var timer = document.getElementById( "timer" );
timer.innerHTML = "Loading...";
// Grab start time.
var startTime = new Date();
// Open the request.
http.open('GET', 'coordinates.pl?width=900&height=457', true);
// Set callback function.
http.onreadystatechange =
function()
{
if(http.readyState == 4)
{
if (http.status == 200) // Did it work?
{
// Grab the response content.
var response = http.responseText;
document.getElementById( "timer" ).innerHTML = '';
}
}
// 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();
timer.innerHTML = 'Generated in ' + ( endTime - startTime ) + ' ms.';
};
// Send the request.
http.send(null);
}
View
25
Repositories/Maps/gd_map.php 0 → 100755
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>Repository hit visualisation using GD</title>
<meta name="generator" content="BBEdit 8.2" />
<script type="text/javascript" src="gd_map.js"></script>
</head>
<body onload="load()">
 
<h1>Repository hit visualisation using GD</h1>
 
<p>Stats current as of early afternoon 8 May 2006. You can also view the <a href="coordinates.pl?width=3599&height=1826"><strong>REALLY BIG</strong> version</a>.</p>
 
<div id="timer"></div>
 
<div id="map" style="width:900px; height:457px"></div>
 
<!--
<p><img src="coordinates.pl?width=900&height=457" width="900" height="457" alt="Small version loading --- please wait..." /></p>
-->
 
</body>
</html>
View
9
Repositories/Maps/gd_map.pl
#!/usr/bin/env perl
use strict;
use Time::HiRes qw( gettimeofday );
use CGI;
use DBI;
use GD;
use Geo::IP;
use Geo::Proj4;
 
 
my ($start_time) = time();
my ($start_sec, $start_micro) = gettimeofday;
 
my ($page);
 
my ($dsn) = "DBI:mysql:database=eprintstats;host=localhost";
$mapimage->string( gdSmallFont, 3, 3, "$types{'download'} downloads", $red );
$mapimage->string( gdSmallFont, 3, 15, "$types{'abstract'} abstracts", $blue );
$mapimage->string( gdSmallFont, 3, 27, 'from ' . scalar( keys %cities ) . ' cities', $black );
$mapimage->string( gdSmallFont, 3, 39, "($num_rows IP addresses)", $black );
$mapimage->string( gdSmallFont, 3, $height - 15, 'Generated in ' . ( time() - $start_time ) . ' seconds', $black );
 
my ($finish_sec, $finish_micro) = gettimeofday();
$mapimage->string( gdSmallFont, 3, $height - 15, 'Generated in ' . round( ( $finish_micro - $start_micro ) / 1000 ) . ' ms', $black );
 
binmode(STDOUT);
 
print $mapimage->jpeg();
View
60
Repositories/Maps/google_map.js
function load()
{
var startTime = new Date();
// Somewhere to write the timing information to.
var timer = document.getElementById( "timer" );
timer.innerHTML = "Loading...";
var code = document.getElementById( "code" );
// Grab start time.
var startTime = new Date();
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 the given label
// 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",
} );
return marker;
}
// Download the data in google_map_data.xml and load it on the map. The format we
// expect is:
// <markers>
// <marker lat="37.441" lng="-122.141"/>
// <marker lat="37.322" lng="-121.213"/>
// Download the data in google_map_data.xml and load it on the map.
// The format we expect is:
// <markers abs="200" dl="100" 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_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 markerlist = xml.documentElement.getElementsByTagName( "marker" );
for ( var i = 0; i < markerlist.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 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" ) ) );
}
// 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();
timer.innerHTML = markers.length + " cities plotted in " + ( endTime - startTime ) + " ms.";
timer.innerHTML = '<span style="color:red;">' +
xml.documentElement.getAttribute( "dl" ) +
' downloads</span> & <span style="color:blue;">' +
xml.documentElement.getAttribute( "abs" ) +
' abstracts</span> from ' +
markerlist.length +
' cities (' +
xml.documentElement.getAttribute( "ips" ) +
' IP addresses), generated in ' +
( endTime - startTime ) +
' ms.';
} );
}
}
View
21
Repositories/Maps/google_map.php
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Google Maps JavaScript API Example</title>
<title>Repository hit visualisation using Google Maps</title>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAdiP-i78VGweF9QIs3Kzx5xStigeMdN8paxvpTosC1OeLHYoRqBSkQbm8tvhKdj_F_yKVUD2Qm6NWtA" type="text/javascript"></script>
<script type="text/javascript" src="google_map.js"></script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="map" style="width: 1030px; height: 640px"></div>
<div id="timer"></div>
 
<h1>Repository hit visualisation using Google Maps</h1>
 
<p>Stats current as of early afternoon 8 May 2006.</p>
 
<div id="timer"></div>
 
<div id="map" style="width:1030px; height:640px"></div>
 
</body>
</html>
View
7
Repositories/Maps/google_map_generate_data.pl
my ($gidb) = '/usr/local/share/GeoIP/GeoLiteCity.dat';
 
# Miscellaneous variable.
my (%cities);
my ($num_IPs) = -1;
my ($num_IPs) = 100;
my ($num_hits) = 0;
my ( $ip, $count, $location );
my ( $lat, $long, $city ) = ( 0, 0, '' );
 
$cities{$city}{'abstract'} = 0;
$cities{$city}{'download'} = 0;
}
$cities{$city}{$vtype} += $count;
$types{$vtype} += $count;
}
}
 
# Need to wait until we have all the counts before writing the data out.
print '<?xml version="1.0"?>' . "\n";
print "<markers>\n";
print '<markers abs="' . $types{'abstract'} . '" dl="' . $types{'download'} . '" ips="' . $num_IPs . '">' . "\n";
 
foreach $city ( keys %cities )
{
print '<marker city="' . $city
. '" lat="'
. $cities{$city}{'lat'}
. '" lng="'
. '" long="'
. $cities{$city}{'long'}
. '" abs="'
. $cities{$city}{'abstract'}
. '" dl="'