-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathindex.html
84 lines (73 loc) · 1.97 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Maptime AMS #4: Geopolitics, Borders & D3.js!</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
svg {
position: absolute;
width: 100%;
height: 100%;
}
path {
stroke: #666;
fill: none;
fill-opacity: 0.6;
stroke-width: 1px;
stroke-linecap: round;
stroke-linejoin: round;
}
#boundary path {
stroke-dasharray: 3, 5;
}
</style>
</head>
<body>
<svg>
<g id="boundary"></g>
<g id="states"></g>
</svg>
<h1>United States in <span id="year">1790</span></h1>
<script>
var svgStates = d3.select("svg #states"),
svgBoundary = d3.select("svg #boundary"),
states = {},
startYear = 1790,
currentYear = startYear;
var width = window.innerWidth,
height = window.innerHeight;
var projection = d3.geo.albersUsa()
.translate([width / 2, height / 2]);
var path = d3.geo.path()
.projection(projection);
d3.json("../../data/usa.json", function(error, boundary) {
svgBoundary.selectAll("path")
.data(boundary.features)
.enter()
.append("path")
.attr("d", path)
});
d3.json("../../data/states.json", function(error, topologies) {
for (var i = 0; i < topologies.length; i++) {
states[startYear + i * 10] = topojson.feature(topologies[i], topologies[i].objects.stdin);
}
function update() {
svgStates.selectAll("path")
.data(states[currentYear].features)
.enter()
.append("path")
.attr("d", path);
}
update();
});
</script>
</body>
</html>