-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
64 lines (52 loc) · 1.38 KB
/
main.js
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
var data;
var index = 0;
var frame = d3.select('#map');
var quote = d3.select('#quote');
var source = d3.select('#source');
var address = d3.select('#location');
var hash = window.location.hash;
d3.csv('data.csv', function(_data) {
loadTour(_data, 'Queer New York');
$('body').on('click', function(e) {
nextPlace();
});
$(window).on('hashchange', function() {
go(window.location.hash.substring(1));
});
go(window.location.hash.substring(1));
});
function loadTour(_data, theme) {
data = _data.filter(function(d) {
return d['Theme'] == theme;
});
data = data.map(function(d) {
d.embed = d['Streetview Embed Code'].match(/src="(.*?)"/)[1];
d.lat = d['Streetview Embed Code'].match(/1d(.*?)!/)[1];
d.lng = d['Streetview Embed Code'].match(/2d(.*?)!/)[1];
d['Quote'] = d['Quote'].replace('\n', '<br>');
d['Source'] = d['Source'].replace('\n', '<br>');
return d;
});
}
function prevPlace() {
index --;
if (index < 0) {
index = data.length - 1;
}
window.location.hash = '#' + index;
}
function nextPlace() {
index ++;
if (index > data.length - 1) {
index = 0;
}
window.location.hash = '#' + index;
}
function go(i) {
if (typeof i != 'number') i = +i;
index = i;
frame.attr('src', data[index].embed);
quote.html(data[index]['Quote']);
source.html(data[index]['Source']);
address.text(data[index]['Location']);
}