forked from devsar/d3talk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazimuthal.html
127 lines (106 loc) · 2.75 KB
/
azimuthal.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
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
126
127
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<script type="text/javascript" src="d3/d3.js"></script>
<script type="text/javascript" src="d3/d3.geo.js"></script>
<link type="text/css" rel="stylesheet" href="style.css"/>
<link type="text/css" rel="stylesheet" href="colorbrewer/colorbrewer.css"/>
<style type="text/css">
svg {
width: 1280px;
height: 800px;
pointer-events: all;
}
circle {
fill: #dbe4f0;
}
path {
fill: #aaa;
stroke: #fff;
}
</style>
</head>
<body>
<div id="body">
<div id="footer">
d3.geo.azimuthal
<div class="hint">drag to rotate the origin</div>
<div><select>
<option value="equalarea">equalarea</option>
<option value="equidistant">equidistant</option>
<option value="gnomonic">gnomonic</option>
<option value="orthographic" selected>orthographic</option>
<option value="stereographic">stereographic</option>
</select></div>
</div>
</div>
<script type="text/javascript">
var feature;
var projection = d3.geo.azimuthal()
.scale(380)
.origin([-71.03,42.37])
.mode("orthographic")
.translate([640, 400]);
var circle = d3.geo.greatCircle()
.origin(projection.origin());
// TODO fix d3.geo.azimuthal to be consistent with scale
var scale = {
orthographic: 380,
stereographic: 380,
gnomonic: 380,
equidistant: 380 / Math.PI * 2,
equalarea: 380 / Math.SQRT2
};
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("#body").append("svg:svg")
.attr("width", 1280)
.attr("height", 800)
.on("mousedown", mousedown);
d3.json("world-countries.json", function(collection) {
feature = svg.selectAll("path")
.data(collection.features)
.enter().append("svg:path")
.attr("d", clip);
feature.append("svg:title")
.text(function(d) { return d.properties.name; });
});
d3.select(window)
.on("mousemove", mousemove)
.on("mouseup", mouseup);
d3.select("select").on("change", function() {
projection.mode(this.value).scale(scale[this.value]);
refresh(750);
});
var m0,
o0;
function mousedown() {
m0 = [d3.event.pageX, d3.event.pageY];
o0 = projection.origin();
d3.event.preventDefault();
}
function mousemove() {
if (m0) {
var m1 = [d3.event.pageX, d3.event.pageY],
o1 = [o0[0] + (m0[0] - m1[0]) / 8, o0[1] + (m1[1] - m0[1]) / 8];
projection.origin(o1);
circle.origin(o1)
refresh();
}
}
function mouseup() {
if (m0) {
mousemove();
m0 = null;
}
}
function refresh(duration) {
(duration ? feature.transition().duration(duration) : feature).attr("d", clip);
}
function clip(d) {
return path(circle.clip(d));
}
</script>
</body>
</html>