-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
533 lines (460 loc) · 17.5 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
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
<meta name="viewport" content="width=device-width, user-scalable=no">
<script src="https://d3js.org/d3.v3.js"></script>
<script src="https://d3js.org/topojson.v1.min.js"></script>
<script src='planetaryjs.js'></script>
<script src="satellite.js"></script>
<style>
#menu input {
float: right;
}
#menu input[type=search] {
float: none;
}
#menu input[type=search] {
width: 16em;
}
#angle {
-webkit-appearance: none;
width: calc(max(20em, 13%));
background: transparent;
}
#angle::-moz-range-track {
width: 100%;
background: linear-gradient(to right, orange 26%, green 28%, green 44%, orange 46%);
}
#angle::-webkit-slider-runnable-track {
width: 100%;
height: 0.1rem;
margin: 0.45rem;
background: linear-gradient(to right, orange 26%, green 28%, green 44%, orange 46%);
}
#angle::-webkit-slider-thumb {
margin-top: -0.45rem;
}
.circle {
height: 1em;
width: 1em;
border-radius: 50%;
display: inline-block;
background: #7ed9fd;
color: black;
}
</style>
<title>Starlink Coverage</title>
<body style="margin:0;background-color:#484820;text-align:center;--menu-open: none; --explanation: none; --help: inline-block;">
<div style="z-index: 2;position: fixed;text-align: left;margin: 1em;line-height:2em;">
<div id="menu_toggle" style="font-size: 2em;display: inline-block; color:whitesmoke;">⚙</div>
<div id="menu" style="display: var(--menu-open);color: whitesmoke;padding: 1em; width: 20em;">
<b>Time Controls</b>
<div>Real World Time<input id="realtime" type="checkbox" checked></div>
<div id="frametime"></div>
<div>Speed <span id="speed_out"></span><input id="speed" type="range" min="0" max="12" step="0.1" value="1"></div>
<hr>
<div id="addresses"></div>
<hr>
<b>Rotation</b>
<div>Auto Rotate <input id="autorotate" type="checkbox" value="true"> </div>
<div>Speed<input id="rot_speed" type="range" min="0" max="10" value="1.2" step="0.01"> </div>
<hr>
<b>Colors</b>
<div>Coverage Area<input id="circle_color" type="color" value="#14d400"></div>
<div>Coverage Highlight<input id="highlight_color" type="color" value="#F300FF"><input id="highlight_enabled" type="checkbox" checked></div>
<div>Satellite<input id="sat_color" type="color" value="#ffc0c0"><input id="sat_enabled" type="checkbox" checked></div>
<div>Background<input type="color" value="#484820" oninput="document.body.style.backgroundColor = this.value;"></div>
<div>Land<input id="land_color" type="color" value="#645817"></div>
<div>Ocean<input id="ocean_color" type="color" value="#203340"></div>
<div>Nations<input id="nation_color" type="color" value="#a043a0"><input id="nation_enabled" type="checkbox" checked></div>
<div>Ocean Edge<input id="edge_color" type="color" value="#8093a0"><input id="edge_enabled" type="checkbox" checked></div>
</div>
</div>
<div style="color:whitesmoke; z-index: 1; position: relative;">
<div>Degrees From Horizon For Connectivity
<span class="circle" style="display: var(--help)" onclick="display_help()">?</span>
<span class="circle" style="display: var(--explanation)" onclick="hide_help()">✖</span>
</div>
<input id="angle" type="range" min="0" max="89.9">
<div id="angle_text">25°</div>
<div style="display: var(--explanation); max-width: 75%; background-color: #00000066; padding: 1em; border-radius: 1em;">
<div>Degrees From Horizon is the amount you have to tilt your head to look at the satellite when standing in a flat field.</div>
<br />
<div>We believe the initial constellation will have connectivity if the satellite is above 25°, and that this requirement will later be eased to 40° to increase performance. Note: This number is how much of the whole sky (in all directions) will be required to be visible overhead to maintain constant connection to the constellation.</div>
</div>
</div>
<div style="bottom: 10px;position: fixed;width: 100%;color: #ffffff55;z-index: 1;">
MIT Licensed, Originally Created By <a href="http://droid.cafe/starlink/">Greg Morenz</a> (updated by <a href="http://twitter.com/blach/">Ben Lachman</a>)</div>
<canvas id='globe' style="position:fixed;top:0;display:block;"></canvas>
</body>
<script>
var a = 2 * Math.PI * (5 / 8);
var b = 2 * Math.PI * (7 / 8);
// Thank you https://stackoverflow.com/questions/25042350/draw-a-pin-on-canvas-using-html5
function drawPin(ctx, pin) {
ctx.save();
ctx.translate(pin.x, pin.y);
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.bezierCurveTo(2, -10, -20, -25, 0, -30);
ctx.bezierCurveTo(20, -25, -2, -10, 0, 0);
ctx.fillStyle = pin.color;
ctx.fill();
ctx.strokeStyle = "black";
ctx.lineWidth = 1.5;
ctx.stroke();
ctx.beginPath();
ctx.arc(0, -21, 3, 0, Math.PI * 2);
ctx.closePath();
ctx.fillStyle = "black";
ctx.fill();
ctx.restore();
}
let angle = document.getElementById("angle");
let angle_text = document.getElementById("angle_text");
angle.oninput = _ => angle_text.textContent = angle.value + "°";
angle.value = 25;
let autorotate_elem = document.getElementById("autorotate");
autorotate_elem.checked = true;
autorotate_elem.onclick = _ => planet.plugins.autorotate.set_paused(!autorotate_elem.checked);
let menu_active = false;
let menu_toggle = document.getElementById("menu_toggle");
menu_toggle.onclick = e => {
menu_active = !menu_active;
document.body.style.setProperty("--menu-open", menu_active ? "block" : "none");
}
let rot_speed = document.getElementById("rot_speed");
let circle_color = document.getElementById("circle_color");
let highlight_color = document.getElementById("highlight_color");
let highlight_enabled = document.getElementById("highlight_enabled");
let sat_color = document.getElementById("sat_color");
let sat_enabled = document.getElementById("sat_enabled");
let land_color = document.getElementById("land_color");
let ocean_color = document.getElementById("ocean_color");
let nation_color = document.getElementById("nation_color");
let nation_enabled = document.getElementById("nation_enabled");
let edge_color = document.getElementById("edge_color");
let edge_enabled = document.getElementById("edge_enabled");
let earth_settings = {
topojson: {
file: 'world-110m.json'
},
oceans: {
fill: '#203340'
},
land: {
fill: '#645817',
stroke: "#8093a0"
},
borders: {
stroke: '#a043a0'
}
}
land_color.oninput = _ => earth_settings.land.fill = land_color.value;
ocean_color.oninput = _ => earth_settings.oceans.fill = ocean_color.value;
let nation_update = _ => earth_settings.borders.stroke = nation_enabled.checked ? nation_color.value : land_color.value;
nation_color.oninput = nation_update;
nation_enabled.oninput = nation_update;
let edge_update = _ => earth_settings.land.stroke = edge_enabled.checked ? edge_color.value : false;
edge_color.oninput = edge_update;
edge_enabled.oninput = edge_update;
let addresses = document.getElementById("addresses");
var geocoder; // Initialized when gmaps loads
var pin_locations = [];
function new_address() {
let i = addresses.childElementCount;
let node = document.createElement("input");
node.type = "search";
node.onchange = _ => update_address(i, node.value);
node.style = "width:100%;display:block;";
node.placeholder = "Pin Address";
addresses.appendChild(node);
pin_locations.push(false);
}
// Initial address
new_address();
function update_address(i, address) {
if (address == "") {
planet.requiresRedraw = true;
pin_locations[i] = false;
for (let i = addresses.childElementCount - 1; i > 0; i--) {
if (addresses.children[i - 1].value != "") {
break;
}
pin_locations.pop();
addresses.lastChild.remove();
}
return;
}
if (i + 1 == addresses.childElementCount) {
// Add an blank address if this is the last address
new_address();
}
pin_address(i, address);
}
let frametime_el = document.getElementById("frametime");
let realtime = document.getElementById("realtime");
let speed_in = document.getElementById("speed");
let speed_out = document.getElementById("speed_out");
// Time at which we are simulating from
let base_time = new Date().getTime();
// Realtime that we last base_time
let reference_time = base_time;
// Controls framerate
let framedelay = 1 / 6;
// Playback speed
let speed = 1;
function update_timing(self) {
if (self.target !== realtime) {
realtime.checked = false;
}
let speed_parsed = Math.round(parseFloat(speed_in.value) ** 2)
speed_out.textContent = speed_parsed + "x";
if (realtime.checked) {
base_time = new Date().getTime();
reference_time = base_time;
framedelay = 1 / 6;
speed = 1;
} else {
let new_time = new Date().getTime();
base_time += (new_time - reference_time) * speed;
reference_time = new_time;
speed = speed_parsed;
framedelay = Math.max(1 / 60, speed / 6);
}
}
frametime_el.oninput = update_timing;
realtime.oninput = update_timing;
speed_in.oninput = update_timing;
update_timing({
target: realtime
});
satellite_positions = [];
function periodic_regen_positions() {
d3.timer(_ => periodic_regen_positions(), 1 / 6);
let render_time;
if (realtime.checked) {
render_time = new Date();
} else {
render_time = base_time + (new Date().getTime() - reference_time) * speed;
render_time = new Date(render_time);
}
frametime_el.textContent = render_time.toUTCString();
planet.requiresRedraw = true;
satellite_positions = generate_positions(render_time);
return true
}
function pin_address(i, address) {
geocoder.geocode({
'address': address
}, function(results, status) {
if (status === 'OK') {
planet.requiresRedraw = true;
let l = results[0].geometry.location;
pin_locations[i] = [l.lng(), l.lat()];
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
})
}
function display_help() {
document.body.style.setProperty("--explanation", "inline-block");
document.body.style.setProperty("--help", "none");
}
function hide_help() {
document.body.style.setProperty("--explanation", "none");
document.body.style.setProperty("--help", "inline-block");
}
Math.radians = function(degrees) {
return degrees / 180 * Math.PI;
};
Math.degrees = function(radians) {
return radians * 180 / Math.PI;
};
// Plugin to resize the canvas to fill the window and to
// automatically center the planet when the window size changes
function autocenter(options) {
options = options || {};
var needsCentering = false;
var globe = null;
var resize = function() {
var width = window.innerWidth + (options.extraWidth || 0);
var height = window.innerHeight + (options.extraHeight || 0);
globe.canvas.width = width;
globe.canvas.height = height;
globe.projection.translate([width / 2, height / 2]);
};
return function(planet) {
globe = planet;
planet.onInit(function() {
needsCentering = true;
d3.select(window).on('resize', function() {
needsCentering = true;
});
});
planet.onDraw(function() {
if (needsCentering) {
resize();
needsCentering = false;
}
});
};
};
// Plugin to automatically scale the planet's projection based
// on the window size when the planet is initialized
function autoscale(options) {
options = options || {};
return function(planet) {
planet.onInit(function() {
var width = window.innerWidth + (options.extraWidth || 0);
var height = window.innerHeight + (options.extraHeight || 0);
planet.projection.scale(Math.min(width, height) / 2);
});
};
};
// Plugin to automatically rotate the globe around its vertical
// axis a configured number of degrees every second.
function autorotate(degPerSecFunc) {
return function(planet) {
var lastTick = null;
var paused = false;
var manually_paused = false;
planet.plugins.autorotate = {
set_paused: function(v) {
manually_paused = v;
},
pause: function() {
paused = true;
},
resume: function() {
paused = false;
}
};
planet.onDraw(function() {
if (paused || manually_paused || !lastTick) {
lastTick = new Date();
} else {
planet.requiresDredraw = true;
var now = new Date();
var delta = now - lastTick;
var rotation = planet.projection.rotate();
rotation[0] += degPerSecFunc() * delta / 1000;
if (rotation[0] >= 180) rotation[0] -= 360;
planet.projection.rotate(rotation);
lastTick = now;
}
});
};
};
let canvas = document.getElementById("globe");
var planet = planetaryjs.planet();
planet.loadPlugin(autocenter({
extraHeight: 0
}));
planet.loadPlugin(autoscale({
extraHeight: -40
}));
planet.loadPlugin(planetaryjs.plugins.earth(earth_settings));
planet.loadPlugin(planetaryjs.plugins.pings());
planet.loadPlugin(planetaryjs.plugins.zoom({
scaleExtent: [50, 5000]
}));
planet.loadPlugin(planetaryjs.plugins.drag({
onDragStart: function() {
this.plugins.autorotate.pause();
},
onDragEnd: function() {
this.plugins.autorotate.resume();
},
afterDrag: function() {
planet.requiresRedraw = true;
}
}));
planet.loadPlugin(autorotate(_ => parseFloat(rot_speed.value) ** 2));
planet.projection.rotate([100, -10, 0]);
planet.draw(canvas);
planet.requiresRedraw = true;
// Defined out here so that you can play with it in the console
var satellites = [];
var satellite_positions;
function generate_positions(time) {
var gmst = satellite.gstime(time);
var positions = satellites.map(sat => {
let pos_and_vel = satellite.propagate(sat, time);
if(sat.error != 0) { return; }
let pos_gd = satellite.eciToGeodetic(pos_and_vel.position, gmst);
let lng = pos_gd.longitude * 180 / Math.PI;
let lat = pos_gd.latitude * 180 / Math.PI;
let orbit_radius = pos_gd.height + 6371;
let angle_horizon_station_satellite = parseFloat(angle.value);
let angle_earth_station_satellite = 90 + angle_horizon_station_satellite;
let angle_station_satellite_earth = Math.degrees(Math.asin(
Math.sin(Math.radians(angle_earth_station_satellite)) * 6371 / orbit_radius));
let angle_satellite_earth_observer = 180 - angle_earth_station_satellite - angle_station_satellite_earth;
return [lng, lat, pos_gd.height + 6371, angle_satellite_earth_observer];
});
return positions.filter( pos => { return pos !== undefined; });
}
fetch("starlink-data.txt")
.then(r => r.text(), _ => console.log("starlink data failed"))
.then(text => {
rows = text.split(/\r?\n/);
for (let i = 0; i + 2 < rows.length; i += 3) {
satellites.push(satellite.twoline2satrec(rows[i + 1], rows[i + 2]));
}
periodic_regen_positions();
planet.onDraw(_ => {
let rotation = planet.projection.rotate();
rotation[0] *= -1;
rotation[1] *= -1;
satellite_positions.forEach(pos => {
let lng = pos[0];
let lat = pos[1];
let height = pos[2];
let angular_size = pos[3];
// Only draw cirlces on the same side of the planet
if (d3.geo.distance(rotation, [lng, lat]) > Math.PI / 2) {
return;
}
// if( lng > 185 || lng < 175 ) { return }
let circle = d3.geo.circle().origin([lng, lat]).angle(angular_size)();
if (highlight_enabled.checked &&
pin_locations.some(loc => loc) &&
pin_locations.every(loc =>
loc == false || Math.degrees(d3.geo.distance(loc, [lng, lat])) < angular_size
)) {
planet.context.fillStyle = highlight_color.value;
} else {
planet.context.fillStyle = circle_color.value;
}
planet.context.globalAlpha = 0.2
planet.context.beginPath();
planet.path.context(planet.context)(circle);
planet.context.fill();
planet.context.globalAlpha = 1
if (sat_enabled.checked) {
planet.context.fillStyle = sat_color.value;
let scale = planet.projection.scale();
let new_scale = scale * (height / 6371);
planet.projection.scale(new_scale)
let xy = planet.projection([lng, lat]);
planet.context.beginPath();
planet.context.arc(xy[0], xy[1], 1, 0, 2 * Math.PI);
planet.context.fill();
planet.projection.scale(scale)
}
});
pin_locations.forEach(pin_location => {
if (pin_location != false && d3.geo.distance(rotation, pin_location) <= Math.PI / 2) {
let xy = planet.projection(pin_location)
drawPin(planet.context, {
x: xy[0],
y: xy[1],
color: "#aa6688",
});
}
});
})
}, _ => console.log("get starlink data text failed"))
function init_gmaps() {
geocoder = new google.maps.Geocoder();
}
</script>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCRdpMJ2ah1HCaFe5i2CiWN6ZfsZzhuSNc&callback=init_gmaps"></script>