-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolar-circumnav-x.html
218 lines (178 loc) · 4.52 KB
/
polar-circumnav-x.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<!DOCTYPE html>
<html>
<head>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://unpkg.com/topojson-client@3"></script>
</head>
<body>
<svg id="svg1" width="1080" height="600"></svg>
<svg id="svg2" width="1080" height="600"></svg>
</body>
</html>
<style>
.stroke {
fill: none;
stroke: #000;
stroke-width: 0;
}
.fill {
fill: #1795d1;
}
.graticule {
fill: none;
stroke: #ddd;
stroke-width: 2px;
stroke-opacity: 1;
}
.land {
fill: #fff ;
}
.boundary {
fill: none;
stroke: #fff;
stroke-width: 0;
}
.route {
fill: none;
stroke: #000;
stroke-width: 8px;
}
.point {
fill: black;
stroke: #000;
stroke-width: 15px;
}
</style>
<script>
function getLineString(i) {
return {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": i
}
}
]
};
}
function getMultiPoint(i) {
return {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "MultiPoint",
"coordinates": i
}
}
]
};
}
var centerlon1 = 5;
var centerlat1 = -90;
var centerlon2 = centerlon1 > 0 ? centerlon1 - 180 : centerlon1 + 180;
var centerlat2 = -centerlat1;
console.log([centerlon2, centerlat2]);
// svg1
var svg1 = d3.select("#svg1"),
width = +svg1.attr("width"),
height = +svg1.attr("height");
var projection1 = d3.geoOrthographic()
.rotate([centerlon1, centerlat1])
;
var path1 = d3.geoPath()
.projection(projection1);
svg1.append("defs").append("path")
.datum({type: "Sphere"})
.attr("id", "sphere")
.attr("d", path1);
svg1.append("use")
.attr("class", "stroke")
.attr("xlink:href", "#sphere");
svg1.append("use")
.attr("class", "fill")
.attr("xlink:href", "#sphere");
svg1.append("path")
.datum(function() {
return d3.geoGraticule()
.stepMinor([30,30])
.extentMinor([[-180,-90], [180,90]])
();
})
.attr("class", "graticule")
.attr("d", path1);
// svg2
var svg2 = d3.select("#svg2"),
width = +svg2.attr("width"),
height = +svg2.attr("height");
var projection2 = d3.geoOrthographic()
.rotate([centerlon2, centerlat2])
;
var path2 = d3.geoPath()
.projection(projection2);
svg2.append("defs").append("path")
.datum({type: "Sphere"})
.attr("id", "sphere")
.attr("d", path2);
svg2.append("use")
.attr("class", "stroke")
.attr("xlink:href", "#sphere");
svg2.append("use")
.attr("class", "fill")
.attr("xlink:href", "#sphere");
svg2.append("path")
.datum(function() {
return d3.geoGraticule()
.stepMinor([30,30])
.extentMinor([[-180,-90], [180,90]])
();
})
.attr("class", "graticule")
.attr("d", path2);
function addRoute(r) {
svg1.insert("path", ".route")
.datum(getLineString(r))
.attr("class", "route")
.attr("d", path1);
svg1.insert("path", ".point")
.datum(getMultiPoint(r))
.attr("class", "point")
.attr("d", path1);
svg2.insert("path", ".route")
.datum(getLineString(r))
.attr("class", "route")
.attr("d", path2);
svg2.insert("path", ".point")
.datum(getMultiPoint(r))
.attr("class", "point")
.attr("d", path2);
}
d3.json("common/50m.json", function(error, world) {
if (error) throw error;
svg1.insert("path", ".graticule")
.datum(topojson.feature(world, world.objects.land))
.attr("class", "land")
.attr("d", path1);
svg1.insert("path", ".graticule")
.datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))
.attr("class", "boundary")
.attr("d", path1);
svg2.insert("path", ".graticule")
.datum(topojson.feature(world, world.objects.land))
.attr("class", "land")
.attr("d", path2);
svg2.insert("path", ".graticule")
.datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))
.attr("class", "boundary")
.attr("d", path2);
});
d3.json("common/locations.json", function(error, l) {
if (error) throw error;
// addRoute([l.riodejaneiro, l.santiago, l.melbourne, l.perth]);
addRoute([l.riodejaneiro, l.saopaulo, l.johannesburg, l.perth]);
});
</script>