Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
229 lines (200 sloc) 7.37 KB
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Roland's 2010 Commute</title>
</head>
<body>
<h2 id="heading">Roland's 2010 Commute</h2>
<div id="cm-example" style="width: 800px; height: 600px"></div>
<script type="text/javascript" src="http://tile.cloudmade.com/wml/latest/web-maps-lite.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">//<![CDATA[
(function($){
$.ajaxSetup({
cache: false // turn off AJAX caching
});
var cloudmade = new CM.Tiles.CloudMade.Web({key: 'ccfc587e00ca40458db437d57437f5cf',styleId: 22405});
var map = new CM.Map('cm-example', cloudmade);
// set centre to be Vancouver Centroid from Flickr:
// http://www.flickr.com/places/info/9807
map.setCenter(new CM.LatLng(49.2604, -123.1140), 13);
// disable all scrolling and dragging
map.disableDragging();
map.disableMouseZoom();
function mysqlTimeStampToDate(timestamp) {
// from http://snippets.dzone.com/posts/show/4132
//function parses mysql datetime string and returns javascript Date object
//input has to be in this format: 2007-06-05 15:26:02
var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
var parts=timestamp.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
return new Date(parts[0],parts[1]-1,parts[2],parts[3],parts[4],parts[5]);
};
function toggle_polygon(index,polygons,circles) {
var current_index = (++index);
switch (current_index) {
case (1):
case (2):
case (3):
case (4):
map.removeOverlay(circles[current_index - 1]);
map.addOverlay(circles[current_index]);
break;
case (5):
map.removeOverlay(circles[current_index - 1]);
map.addOverlay(polygons[0]);
break;
default:
map.removeOverlay(polygons[current_index % 2]);
//map.addOverlay(polygons[(current_index + 1) % 2]);
break;
}
if (current_index < 5) {
setTimeout(function () {toggle_polygon(current_index,polygons,circles);},250);
}
};
var num_pages = 200;
var num_commutePics = 0;
var total_pages = 1;
var latlon = new Array();
var latlon_index = 0;
var plot_index = 0;
var total_photos = 0;
function plotPoints() {
var polygons = [];
var lat = latlon[plot_index]["lat"];
var lon = latlon[plot_index]["lon"];
var datetaken = latlon[plot_index]["datetaken"];
$('title').text("Roland's 2010 Commute Geotagged Photo taken:"+datetaken);
$('#heading').text("Roland's 2010 Commute Geotagged Photo taken:"+datetaken);
polygons.push(new CM.Polygon([new CM.LatLng(lat,lon)], "red", 3, 0.5));
var circles = [];
var colour_of_new_commute_pic = "orange";
if (plot_index % 3 == 0) {
colour_of_new_commute_pic = "blue";
}
if (plot_index % 3 == 1) {
colour_of_new_commute_pic = "green";
}
circles.push(new CM.Circle(new CM.LatLng(lat,lon), 50, colour_of_new_commute_pic, 5, 0.1));
circles.push(new CM.Circle(new CM.LatLng(lat,lon), 22, colour_of_new_commute_pic, 5, 0.2));
circles.push(new CM.Circle(new CM.LatLng(lat,lon), 15, colour_of_new_commute_pic, 5, 0.3));
circles.push(new CM.Circle(new CM.LatLng(lat,lon), 10, colour_of_new_commute_pic, 5, 0.4));
circles.push(new CM.Circle(new CM.LatLng(lat,lon), 2, colour_of_new_commute_pic, 5, 0.5));
map.addOverlay(circles[0]);
setTimeout(function () {toggle_polygon(0,polygons,circles);},20);
plot_index++;
if (plot_index < latlon.length) {
setTimeout(plotPoints,200);
}
};
var apiKey = 'a3b9e1fec66dfb1797c7414dfbb81974';
var woeID = '9807';
var dates = new Array();
date_index = 0;
dates[0] = {};
dates[0]["min"] = new Date('January 1, 2010 0:00:00 am PST');
dates[0]["max"] = new Date('May 1, 2010 11:59:59 pm PST');
dates[1] = {};
dates[1]["min"] = new Date('May 2, 2010 0:00:00 am PST');
dates[1]["max"] = new Date('August 31, 2010 11:59:59 pm PST');
dates[2] = {};
dates[2]["min"] = new Date('September 1, 2010 0:00:00 am PST');
dates[2]["max"] = new Date('December 31, 2010 11:59:59 pm PST');
function getCommuterPhotoMetaData(date_index, page) {
var min_s = Math.round(dates[date_index]["min"].getTime() * 0.001);
var min_str = min_s + '';
var max_s = Math.round(dates[date_index]["max"].getTime() * 0.001);
var max_str = max_s + '';
$.getJSON("http://api.flickr.com/services/rest/?method=flickr.photos.search"+
"&user_id=35034347371@N01"+
"&api_key="+apiKey+
"&format=json&content_type=1&woe_id="+woeID+
"&per_page=250&min_taken_date="+min_str+
"&max_taken_date="+max_str+
"&tags=cameraphone"+
"&extras=date_taken,geo"+
"&page="+page+"&sort=date-taken-asc&jsoncallback=?",
function(flickrjs){
console.log('page:'+page)
if (page == 1) {
total_pages = parseInt(flickrjs.photos.pages);
total_photos = parseInt(flickrjs.photos.total);
}
$('title').text("Roland's 2010 Commute Date Index:"+date_index+" Retrieving Page:"+page+" of:"+total_pages);
$('#heading').text("Roland's 2010 Commute Date Index:"+date_index+" Retrieving Page:"+page+" of:"+total_pages);
if (total_photos == 0) {
console.log("No Roland's 2010 Commute photos:");
}
else {
$.each(flickrjs.photos.photo,function(i,photo) {
var id = photo.id;
var lat = photo.latitude;
var lon = photo.longitude;
var datetaken = mysqlTimeStampToDate(photo.datetaken);
console.log("Datetaken:"+datetaken);
var hourtaken = datetaken.getHours();
var dayofweek = datetaken.getDay();
var inCommuttingHours = false;
var mondayToFriday = false;
if (hourtaken >= 7 && hourtaken <= 10) {
inCommuttingHours = true;
}
if (hourtaken >= 14 && hourtaken <= 18) {
inCommuttingHours = true;
}
if (dayofweek >= 1 && dayofweek <= 5) {
mondayToFriday = true;
}
if (inCommuttingHours && mondayToFriday) {
console.log("photo:"+id+" not in cache; dayofweek:"+dayofweek+"; hourtaken:"+hourtaken);
var id = photo.id;
var lat = photo.latitude;
var lon = photo.longitude;
latlon[latlon_index] = {};
latlon[latlon_index]["lat"] = lat;
latlon[latlon_index]["lon"] = lon;
latlon[latlon_index]["datetaken"] = photo.datetaken;
latlon_index++;
}
});
if (page < total_pages) {
getCommuterPhotoMetaData(date_index, page + 1);
}
else {
date_index++;
if (date_index >= dates.length) {
top();
}
else {
getCommuterPhotoMetaData(date_index, 1);
}
}
}
});
};
var sort_by = function(field, reverse, primer){
reverse = (reverse) ? -1 : 1;
return function(a,b){
a = a[field];
b = b[field];
if (typeof(primer) != 'undefined'){
a = primer(a);
b = primer(b);
}
if (a<b) return reverse * -1;
if (a>b) return reverse * 1;
return 0;
}
};
function top() {
$('title').text("Roland's 2010 Commute: SORTING");
$('#heading').text("Roland's 2010 Commute: SORTING");
latlon.sort(sort_by('datetaken', false));
$('#heading').text("Roland's 2010 Commute: PLOTTING");
$('title').text("Roland's 2010 Commute: PLOTTING");
plotPoints();
};
setTimeout(function() { getCommuterPhotoMetaData(0, 1) }, 1000);
})(jQuery);
//]]></script>
</body>