diff options
| author | 2009-07-24 03:58:17 -0400 | |
|---|---|---|
| committer | 2009-07-24 03:58:17 -0400 | |
| commit | e98a41988b5f67eedca02592005d3735e17a9e1f (patch) | |
| tree | 6ef5fc3889428c6c0bbc08f74b11c8d226064db6 | |
| parent | Add borked enron db (diff) | |
| download | geoemail-e98a41988b5f67eedca02592005d3735e17a9e1f.tar.xz geoemail-e98a41988b5f67eedca02592005d3735e17a9e1f.zip | |
Add flying feature.
| -rw-r--r-- | src/emailmap.py | 17 | ||||
| -rw-r--r-- | src/template/map.html | 63 |
2 files changed, 59 insertions, 21 deletions
diff --git a/src/emailmap.py b/src/emailmap.py index 13840a1a..5a5b11ae 100644 --- a/src/emailmap.py +++ b/src/emailmap.py @@ -2,6 +2,8 @@ # -*- coding: iso-8859-1 -*- import os +import time +import datetime class EmailMap: def __init__(self): @@ -10,7 +12,6 @@ class EmailMap: templateFile.close() self.__emails = [] self.__pointsIndex = self.__template.find("%%POINTS%%") - self.__centerIndex = self.__template.find("%%CENTER%%") def addEmail(self, email): self.__emails.append(email) def writeMap(self, outfile): @@ -18,18 +19,8 @@ class EmailMap: outfile.write(self.__template[:self.__pointsIndex]); points = [] for index, email in enumerate(self.__emails): - outfile.write(("\t\t\tnew Location(%s, %s, \"%s\", \"%s\", \"%s\")" % (email.location()[0][0], email.location()[0][1], email.ip, "%s, %s, %s" % email.location()[1], str(email.date))).encode("utf-8")) + outfile.write(("\t\t\tnew Location(%s, %s, \"%s\", \"%s\", %s)" % (email.location()[0][0], email.location()[0][1], email.ip, "%s, %s, %s" % email.location()[1], time.mktime(email.date.timetuple()) * 1000)).encode("utf-8")) points.append((float(email.location()[0][0]), float(email.location()[0][1]))) if index < len(self.__emails) - 1: outfile.write(",\n") - points = frozenset(points) - lat = 0 - lng = 0 - for point in points: - lat += point[0] - lng += point[1] - lat /= len(points) - lng /= len(points) - outfile.write(self.__template[self.__pointsIndex + 10: self.__centerIndex]) - outfile.write("%s, %s" % (lat, lng)) - outfile.write(self.__template[self.__centerIndex + 10:])
\ No newline at end of file + outfile.write(self.__template[self.__pointsIndex + 10:])
\ No newline at end of file diff --git a/src/template/map.html b/src/template/map.html index 4a6ebcbd..eefa0b76 100644 --- a/src/template/map.html +++ b/src/template/map.html @@ -3,6 +3,8 @@ <title>Geo Email</title> <script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=ABQIAAAACw81a-uHJcWwKUjMYuwnoxTwt3HnvzZv0TCu-YtHcwcsQml7YBQg-xE2KASNYwCexswehjh8ZNUOhw" type="text/javascript"></script> <script type="text/javascript"> +var lines = window.location.search.indexOf("nolines") == -1; +var fly = window.location.search.indexOf("fly") != -1; function Location(lat, lng, ip, region, date) { this.lat = lat; this.lng = lng; @@ -51,14 +53,18 @@ function initialize() { } } var marker = new GMarker(latlng); + latlng.marker = marker; var message = ""; var closeDiv = false; if (dateList.length + ipList.length + regionList.length > 15) { closeDiv = true; message += "<div style=\"height:250px;overflow:auto\">"; } - for (var i = 0; i < dateList.length; i++) - message += "<b>" + dateList[i] + "</b><br>"; + for (var i = 0; i < dateList.length; i++) { + var dateObj = new Date(); + dateObj.setTime(dateList[i]); + message += "<b>" + dateObj.toString() + "</b><br>"; + } for (var i = 0; i < ipList.length; i++) message += "<i>" + ipList[i] + "</i><br>"; for (var i = 0; i < regionList.length; i++) { @@ -68,28 +74,69 @@ function initialize() { } if (closeDiv) message += "</div>"; - GEvent.addListener(marker, "click", function() { + marker.clickEvent = function() { var myHtml = message; map.openInfoWindowHtml(latlng, myHtml); - }); + }; + GEvent.addListener(marker, "click", marker.clickEvent); map.addOverlay(marker); } var map = new GMap2(document.getElementById("map_canvas")); - map.setCenter(new GLatLng(%%CENTER%%), 3, G_NORMAL_MAP); - map.setUIToDefault(); var latLngs = new Array(); var prev = null; + var bounds = new GLatLngBounds(); for (var i = 0; i < points.length; i++) { var cur = new GLatLng(points[i].lat, points[i].lng); + bounds.extend(cur); makeMarker(cur); - if (window.location.search == "?nolines") + if (!lines) continue; if (prev == null || !latLngEqual(cur, prev)) latLngs.push(cur); prev = cur; } - if (window.location.search != "?nolines") + map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds), G_NORMAL_MAP); + map.setUIToDefault(); + if (lines) map.addOverlay(new GPolyline(latLngs, "#0000FF", 5, .5, {geodesic:true})); + if (fly) { + var totalTime = points[points.length - 1].date - points[0].date; + var totalFlyTime = 60000; //Hard coded! + function flyToNextPoint(point) { + var currentPoint = new GLatLng(points[point].lat, points[point].lng); + if (point > 0) { + var zoomSpace = new GLatLngBounds(); + zoomSpace.extend(currentPoint); + var previousPoint = point - 1; + while (previousPoint > 0 && points[point].lat == points[previousPoint].lat && points[point].lng == points[previousPoint].lng) + previousPoint--; + zoomSpace.extend(new GLatLng(points[previousPoint].lat, points[previousPoint].lng)); + var zoomLevel = map.getZoom() - map.getBoundsZoomLevel(zoomSpace); + while (zoomLevel != 0) { + if (zoomLevel > 0) { + map.zoomOut(currentPoint, true, true); + zoomLevel--; + } + else if (zoomLevel < 0) { + map.zoomIn(currentPoint, true, true); + zoomLevel++; + } + } + } + map.panTo(currentPoint); + if (point == 0 || points[point].lat != points[point - 1].lat || points[point].lng != points[point -1].lng) { + for (var i = 0; i < pointList.length; i++) { + if (currentPoint.equals(pointList[i])) { + pointList[i].marker.clickEvent(); + break; + } + } + } + if (point + 1 < points.length) + window.setTimeout(function() { flyToNextPoint(point + 1); }, (points[point + 1].date - points[point].date) / totalTime * totalFlyTime); + } + flyToNextPoint(0); + } } } </script> |
