-
Notifications
You must be signed in to change notification settings - Fork 1
/
observablehq-azimuthal.js
232 lines (227 loc) · 5.43 KB
/
observablehq-azimuthal.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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
// URL: https://beta.observablehq.com/@forresto/d3-azimuthal-cities-straight-line-routes
// Title: Azimuthal Artifact
// Author: Forrest Oliphant (@forresto)
// Version: 280
// Runtime version: 1
const m0 = {
id: "e6547e85ad478b83@280",
variables: [
{
inputs: ["md"],
value: (function(md){return(
md`# Azimuthal Artifact
Todo:
- Make a new non-equidistant (logarithmic?) azimuthal projection, to give closer locations more room
- Place names around edge
- Experiment with design to make it suitable for laser engraving
Non-map version, designed as artifact to have spatial intuition of friends, family, memories...
![](https://c2.staticflickr.com/2/1940/43785173620_0b8b5cc6cb_b.jpg)
`
)})
},
{
name: "viewof center",
inputs: ["html","cities","option"],
value: (function(html,cities,option)
{
const form = html`
<form><select name=select>
${cities.map(option)}
<!--
<option value="[0, 0]">Standard aspect</option>
<option value="[0, 90]">North polar aspect</option>
<option value="[0, -90]">South polar aspect</option>
-->
</select></form>`;
form.oninput = () => (form.value = JSON.parse(form.select.value));
form.oninput();
return form;
}
)
},
{
name: "center",
inputs: ["Generators","viewof center"],
value: (G, _) => G.input(_)
},
{
name: "map",
inputs: ["DOM","width","height","d3","projection","graticule","land","sphere","lines"],
value: (function(DOM,width,height,d3,projection,graticule,land,sphere,lines)
{
const context = DOM.context2d(width, height);
const path = d3.geoPath(projection, context);
context.beginPath(),
path(graticule),
(context.strokeStyle = "#eee"),
context.stroke();
context.beginPath(),
path(land),
(context.strokeStyle = "#aaa"),
context.stroke();
context.beginPath(),
path(sphere),
(context.strokeStyle = "#000"),
context.stroke();
context.beginPath(),
path(lines),
(context.strokeStyle = "#000"),
context.stroke();
return context.canvas;
}
)
},
{
name: "viewof zoom",
inputs: ["html"],
value: (function(html){return(
html`<input type=range min=-500 max=500 value=1>`
)})
},
{
name: "zoom",
inputs: ["Generators","viewof zoom"],
value: (G, _) => G.input(_)
},
{
name: "viewof rotateOffset",
inputs: ["html"],
value: (function(html){return(
html`<input type=range min=-360 max=360 value=0></input>`
)})
},
{
name: "rotateOffset",
inputs: ["Generators","viewof rotateOffset"],
value: (G, _) => G.input(_)
},
{
name: "rotate",
inputs: ["center","rotateOffset"],
value: (function(center,rotateOffset)
{
const r = center.map(x => -x);
r[0] += rotateOffset;
return r;
}
)
},
{
name: "projection",
inputs: ["d3","rotate","width","height","zoom","sphere"],
value: (function(d3,rotate,width,height,zoom,sphere){return(
d3
.geoAzimuthalEquidistant()
.rotate(rotate)
.translate([width / 2, height / 2])
.fitExtent([[zoom, zoom], [width - zoom, height - zoom]], sphere)
.precision(0.1)
)})
},
{
name: "height",
inputs: ["width"],
value: (function(width){return(
Math.max(640, width)
)})
},
{
name: "cities",
value: (function(){return(
[
["Tokyo", 35.685, 139.7514],
["New York", 40.6943, -73.9249],
["Mexico City", 19.4424, -99.131],
["Mumbai", 19.017, 72.857],
["Sao Paulo", -23.5587, -46.625],
["Delhi", 28.67, 77.23],
["Shanghai", 31.2165, 121.4365],
["Kolkata", 22.495, 88.3247],
["Dhaka", 23.7231, 90.4086],
["Buenos Aires", -34.6025, -58.3975],
["Los Angeles", 34.114, -118.4068],
["Karachi", 24.87, 66.99],
["Cairo", 30.05, 31.25],
["Rio de Janeiro", -22.925, -43.225],
["Osaka", 34.75, 135.4601],
["Beijing", 39.9289, 116.3883],
["Manila", 14.6042, 120.9822],
["Moscow", 55.7522, 37.6155],
["Istanbul", 41.105, 29.01],
["Paris", 48.8667, 2.3333],
["Seoul", 37.5663, 126.9997],
["Lagos", 6.4433, 3.3915],
["Jakarta", -6.1744, 106.8294],
["Guangzhou", 23.145, 113.325],
["Chicago", 41.8373, -87.6861],
["London", 51.5, -0.1167]
].map(([name, lat, lon]) => [name, lon, lat])
)})
},
{
name: "lines",
inputs: ["cities","center"],
value: (function(cities,center){return(
{
type: "MultiLineString",
coordinates: cities.map(([_, lon, lat]) => [center, [lon, lat]])
}
)})
},
{
name: "option",
inputs: ["html"],
value: (function(html){return(
([name, lon, lat]) =>
html`<option value="[${lon}, ${lat}]">${name}</option>`
)})
},
{
name: "sphere",
value: (function(){return(
{type: "Sphere"}
)})
},
{
name: "graticule",
inputs: ["d3"],
value: (function(d3){return(
d3.geoGraticule10()
)})
},
{
name: "land",
inputs: ["topojson","world"],
value: (function(topojson,world){return(
topojson.feature(world, world.objects.land)
)})
},
{
name: "world",
value: (function(){return(
fetch("https://unpkg.com/world-atlas@1/world/110m.json").then(
response => response.json()
)
)})
},
{
name: "topojson",
inputs: ["require"],
value: (function(require){return(
require("topojson-client@3")
)})
},
{
name: "d3",
inputs: ["require"],
value: (function(require){return(
require("d3-geo@1")
)})
}
]
};
const notebook = {
id: "e6547e85ad478b83@280",
modules: [m0]
};
export default notebook;