-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathairports-all.html
96 lines (78 loc) · 2.16 KB
/
airports-all.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
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="d3/d3.js"></script>
<script type="text/javascript" src="d3/d3.csv.js"></script>
<script type="text/javascript" src="d3/d3.geo.js"></script>
<script type="text/javascript" src="d3/d3.geom.js"></script>
<link type="text/css" rel="stylesheet" href="style.css"/>
<style type="text/css">
#states path {
fill: #ccc;
stroke: #fff;
}
path.cell {
fill: none;
pointer-events: all;
stroke: brown;
}
circle {
fill: black;
}
</style>
</head>
<body>
<div id="body">
<div id="footer">
<span>U.S. Airports</span>
<div class="hint"></div>
</div>
</div>
<script type="text/javascript">
var w = 1280,
h = 800;
var projection = d3.geo.azimuthal()
.mode("equidistant")
.origin([-98, 38])
.scale(1400)
.translate([640, 360]);
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("#body").append("svg:svg")
.attr("width", w)
.attr("height", h);
var states = svg.append("svg:g")
.attr("id", "states");
var cells = svg.append("svg:g")
.attr("id", "cells");
d3.json("us-states.json", function(collection) {
states.selectAll("path")
.data(collection.features)
.enter().append("svg:path")
.attr("d", path);
});
d3.csv("airports.csv", function(airports) {
var positions = [];
airports.forEach(function(airport) {
positions.push(projection([+airport.longitude, +airport.latitude]));
});
// Compute the Voronoi diagram of airports' projected positions.
var polygons = d3.geom.voronoi(positions);
var g = cells.selectAll("g")
.data(airports)
.enter().append("svg:g");
g.append("svg:path")
.attr("class", "cell")
.attr("d", function(d, i) { return "M" + polygons[i].join("L") + "Z"; })
.on("mouseover", function(d, i) {
d3.select("#footer span").text(d.name);
d3.select("#footer .hint").text(d.city + ", " + d.state);
});
g.append("svg:circle")
.attr("cx", function(d, i) { return positions[i][0]; })
.attr("cy", function(d, i) { return positions[i][1]; })
.attr("r", 1.5);
});
</script>
</body>
</html>