-
Notifications
You must be signed in to change notification settings - Fork 0
/
theblitz.js
100 lines (86 loc) · 3.29 KB
/
theblitz.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
// London...
var thespot = {"lat": 51.49463582758311, "lon": -0.04628918457023179 }
// the first day of the blitz started after 16:44, the time
// German airplanes entered British airspace.
//
// The data entries should be shifted accordingly and the start of
// the animation should be minute 1004, the first drop at 16:57 will
// be 13 minutes later (data[84]) and continue into next day:
// datum.time=h:m
// hence minutes from start of raid: (h*60+m - 1004) % 1440
var minutes = function(d) {
// transform a time of day string [H]H:MM, i.e. "1:08"
// in minutes from midnight, i.e. 68.
reggie = /(\d):(\d{2})/g;
t = reggie.exec(d.time);
t = parseInt(t[1]) * 60 + parseInt(t[2]);
// shift so that 16:44 is the start of time
// (1440 = 24 * 60, the number of minutes in 1 day)
t = (((t - 1004 ) % 1440) + 600 + 1440) % 1440;
// console.log("" + d.value.order + " ("+ d.value.time + ") ->" + t);
return t;
};
// Create the Google Map
var map = new google.maps.Map(d3.select("#map").node(), {
zoom: 12,
center: new google.maps.LatLng(thespot.lat, thespot.lon),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
// Load the station data. When the data comes back, create an overlay.
d3.json("drops.json", function(data) {
var overlay = new google.maps.OverlayView();
// Add the container when the overlay is added to the map.
overlay.onAdd = function() {
var layer = d3.select(this.getPanes().overlayLayer).append("div")
.attr("class", "drops");
// Draw each marker as a separate SVG element.
// We could use a single SVG, but what size would it have?
overlay.draw = function() {
var projection = this.getProjection(),
padding = 10;
function key(d) {
return d.order;
}
function makegrey(d) {
d3.select(this)
.transition()
.delay(0)
.duration(1000)
.attr("r", 3)
.style("fill", "grey");
}
var marker = layer.selectAll("svg")
.data(data, key)
.each(transform) // update existing markers
.enter().append("svg:svg")
.each(transform)
.attr("class", "marker");
// Add a circle.
marker.append("svg:circle")
.attr("r", 0)
.attr("cx", padding)
.attr("cy", padding)
.transition()
.delay(function(d) {return 20 * minutes(d) + 30;})
.duration(2000)
.attr("r", 4.5)
.style("fill", "black")
.each("end", makegrey);
// Add a label.
// marker.append("svg:text")
// .attr("x", padding + 7)
// .attr("y", padding)
// .attr("dy", ".31em")
// .text(function(d) { return d.value.time; });
function transform(d) {
d = new google.maps.LatLng(d.location.lat, d.location.lon);
d = projection.fromLatLngToDivPixel(d);
return d3.select(this)
.style("left", (d.x - padding) + "px")
.style("top", (d.y - padding) + "px");
}
};
};
// Bind our overlay to the map
overlay.setMap(map);
});