-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
113 lines (102 loc) · 3.47 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<html>
<head>
<title>#codesthlm map</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<style>
html, body, #map {
height: 100%;
margin: 0px;
padding: 0px
}
.overlay {
position: absolute;
left: 30%;
right: 30%;
bottom: 20px;
background: white;
padding: 10px 20px;
border-radius: 12px;
box-shadow: 0 3px 14px rgba(0,0,0,0.4);
font: 12px/1.5 "Helvetica Neue", Arial, Helvetica, sans-serif;
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script>
function parseTitle(text) {
var pattern = /(@|at) ([\s\w\u00C0-\u024F]+)/;
var result = pattern.exec(text);
if (result) {
return result[2].replace(/https?$/, '').trim();
} else {
return 'Unknown location';
}
}
function popupHtml(title, status) {
var statusUrl = 'http://twitter.com/statuses/' + status.id_str;
var title = '<h2>' + title + '</h2>';
var text = '<p>' + status.text + '</p>';
var link = '<p><a href="' + statusUrl + '">' + statusUrl + '</a>';
return title + text + link;
}
$(function() {
var map = new L.Map('map', {
center: new L.LatLng(59.3294, 18.0686),
zoom: 13
});
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
$.getJSON('/tweets.json')
.done(function(data) {
var fiveHoursAgo = new Date(Date.now() - 5*60*60*1000);
var latLngs = $.map(data.statuses, function(status) {
if (status.geo && Date.parse(status.created_at) > fiveHoursAgo) {
var title = parseTitle(status.text);
var marker = L.marker(status.geo.coordinates, {
title: title
}).addTo(map);
marker.bindPopup(popupHtml(title, status));
return marker.getLatLng();
}
});
if (latLngs.length > 0) {
var bounds = new L.LatLngBounds(latLngs);
map.fitBounds(bounds);
} else {
$('<p class="overlay"></p>').text(
'There are currently no #codesthlmers around. Tweet with the ' +
'#codesthlm hashtag, include your location data, and your tweet ' +
'will show up here.'
).appendTo('body');
}
})
.fail(function(jqxhr, status, error) {
console.log(status + ': ' + error);
});
});
</script>
</head>
<body>
<div id="map"></div>
<noscript>
<p>This page is nothing more than a dynamically-generated map of
<a href="https://twitter.com/search?f=realtime&q=%23codesthlm">all
tweets with the hashtag <code>#codesthlm</code></a>.</p>
<p>Sadly, we do not have a non-JavaScript version of this page. If
you're looking for the hottest place to hack code in Stockholm
<em>right now</em>, we suggest <a
href="https://twitter.com/search?q=%23codesthlm">the Twitter
feed</a>.</p>
<p>However, even that might require JavaScript, and so for your
entertainment we invite you to parse <a
href="tweets.json">the JSON that drives the
map</a>.</p>
<p><a href="https://github.com/codesthlm/maps">Patches
welcome</a>.</p>
</noscript>
</body>
</html>