-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimator.js
125 lines (113 loc) · 2.91 KB
/
animator.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
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
114
115
116
117
118
119
120
121
122
123
124
125
//map animation over years
function animator() {
var last_layer;
var control = document.getElementById('layers');
// Add a play button div
var play_button = control.appendChild(document.createElement('a'))
play_button.className = "play";
//var pause = "▐▐";
//var play = "▶";
play_button.innerHTML = "";
play_button.id = "play_button";
play_button.onclick = function () {
if (nextInterval) {
nextInterval = clearInterval(nextInterval);
play_button.className = "play";
} else {
//highlightLayer(i++);
nextInterval = animate();
play_button.className = "pause";
}
}
var layers = [{
name: "'06",
id: "y2006"
}, {
name: "'07",
id: "y2007"
}, {
name: "'08",
id: "y2008"
}, {
name: "'09",
id: "y2009"
}, {
name: "'10",
id: "y2010"
}, {
name: "'11",
id: "y2011"
}, {
name: "'12",
id: "y2012"
}, {
name: "'13",
id: "y2013"
}, {
name: "'14",
id: "y2014"
}, {
name: "'15",
id: "y2015"
}, {
name: "'16",
id: "y2016"
}, {
name: "'17",
id: "y2017"
}, {
name: "'18",
id: "y2018"
}, {
name: "'19",
id: "y2019"
}, {
name: "'20",
id: "y2020"
}, {
name: "'21",
id: "y2021"
}, {
name: "'22",
id: "y2022"
}];
layers.forEach(function (layer, n) {
layer.button = control.appendChild(document.createElement('a'));
layer.button.innerHTML = layers[n].name;
layer.button.id = layers[n].id;
layer.button.onclick = function () {
highlightLayer(n);
i = n;
dispatch.yearChange(layer.button.id);
nextInterval = clearInterval(nextInterval);
play_button.className = "play";
};
});
// starting layer: most recent year
var i = layers.length - 1;
// show the first overlay as soon as the map loads
highlightLayer(i++);
var nextInterval;
function animate() {
// and then time the next() function to run every 1 seconds
return setInterval(function () {
if (++i > layers.length-1) {
i = 0;
//console.log("zerod");
}
highlightLayer(i);
//console.log(i);
}, 1000 * 1);
}
function highlightLayer(i) {
var active = control.getElementsByClassName('active');
for (var j = 0; j < active.length; j++) active[j].className = '';
if (layers[i] == undefined) {
console.log("yo");
layers[i] = layers[0];
}
layers[i].button.className = 'active';
dispatch.yearChange(layers[i].id);
}
}
animator();