-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
121 lines (107 loc) · 4.17 KB
/
main.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
// event listeners
window.addEventListener("load", eventWindowLoaded, false);
window.addEventListener("dblclick", focusISS);
// Create a WorldWindow for the canvas.
var wwd = new WorldWind.WorldWindow("canvas");
var modelLayer = new WorldWind.RenderableLayer();
var routeLayer = new WorldWind.RenderableLayer();
var starFieldLayer = new WorldWind.StarFieldLayer();
var atmosphereLayer = new WorldWind.AtmosphereLayer();
// Define the event listener to initialize Web WorldWind.
var text;
var defaultDate;
var gtextLayer;
function eventWindowLoaded() {
timeline_init();
var now = new Date();
starFieldLayer.time = now;
atmosphereLayer.time = now;
// info
var offset;
var textLayer = new WorldWind.RenderableLayer("information");
offset = new WorldWind.Offset(WorldWind.OFFSET_FRACTION, 0, WorldWind.OFFSET_FRACTION, 0.2);
text = new WorldWind.ScreenText(offset, "Loading...");
text.attributes.offset = new WorldWind.Offset(WorldWind.OFFSET_FRACTION, 0, WorldWind.OFFSET_FRACTION, 0);
textLayer.addRenderable(text);
gtextLayer = new WorldWind.RenderableLayer("Ground Stations");
axios.get("data/groundstations.json")
.then(function(res) {
var gtext;
var stations = res.data;
for (var i = 0; i < stations.length; i++) {
var station = stations[i];
var station_pos = new WorldWind.Position(station["LATITUDE"], station["LONGITUDE"], station["ALTITUDE"]);
gtext = new WorldWind.GeographicText(station_pos, station["NAME"]);
gtextLayer.addRenderable(gtext);
}
});
var layers = [
// Imagery layers.
{layer: new WorldWind.BMNGLayer(), enabled: true},
{layer: new WorldWind.BMNGLandsatLayer(), enabled: false},
{layer: new WorldWind.BingAerialLayer(null), enabled: true},
{layer: new WorldWind.BingAerialWithLabelsLayer(null), enabled: true},
{layer: new WorldWind.BingRoadsLayer(null), enabled: false},
{layer: new WorldWind.OpenStreetMapImageLayer(null), enabled: false},
{layer: starFieldLayer, enabled: true},
// Add atmosphere layer on top of all base layers.
{layer: atmosphereLayer, enabled: true},
// WorldWindow UI layers.
{layer: textLayer, enabled: true},
{layer: gtextLayer, enabled: true},
{layer: new WorldWind.CompassLayer(), enabled: true},
{layer: new WorldWind.CoordinatesDisplayLayer(wwd), enabled: true},
{layer: new WorldWind.ViewControlsLayer(wwd), enabled: true}
];
for (let i = 0; i < layers.length; i++) {
layers[i].layer.enabled = layers[i].enabled;
wwd.addLayer(layers[i].layer);
}
wwd.addLayer(modelLayer);
wwd.addLayer(routeLayer);
// set default date (today)
var now_date = new Date();
defaultDate = now_date.toISOString().split('T')[0];
document.getElementById("date-input").defaultValue = defaultDate;
// console.log(document.getElementById("date-input").value);
}
var satrec;
// fetch ISS data
axios.get("https://live.ariss.org/iss.txt")
.then((res) => {
//console.log(res.data);
lines = res.data.split(/\r?\n/);
var tleLine1 = lines[1],
tleLine2 = lines[2];
satrec = satellite.twoline2satrec(tleLine1, tleLine2);
})
.then(() => {
updateISS();
focusISS();
setInterval(updateISS, 1000);
setInterval(updateInfo, 1000);
});
function toDateTime(secs) {
return new Date(secs * 1000); // Epoch
}
function get_current_date() {
var input_date = document.getElementById("date-input");
console.log("input date", input_date.value);
if (!input_date.value) {
console.log("Empty input date!!");
return 0;
}
else {
var parsed = Date.parse(input_date.value);
var parsed_defaultDate = Date.parse(defaultDate);
// console.log(parsed, parsed_defaultDate, parsed - parsed_defaultDate);
return parsed - parsed_defaultDate;
}
}
function get_current_time() {
// console.log("current date dev", get_current_date());
return Math.round((get_current_date() + Date.now()) / 1000);
}
function get_render_time() {
return get_current_time() + get_user_time();
}