-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
464 lines (397 loc) · 20.7 KB
/
index.html
File metadata and controls
464 lines (397 loc) · 20.7 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ISS Tracker</title>
<link rel="manifest" href="manifest.json" />
<link rel="stylesheet" href="w3.css">
<link rel="stylesheet" href="space.css" type="text/css">
<link rel="stylesheet" href="jquery.vidbacking.css" type="text/css">
<style>
html,
body {
margin: 0;
width: 100%;
height: 100%;
}
#earth_div {
top: 0;
right: 0;
bottom: 0;
left: 0;
position: absolute !important;
z-index: 1;
/* Lower z-index for the globe */
}
.ip {
font-family: 'Orbitron', sans-serif;
font-size: large;
color: azure;
outline: 2px ridge rgba(161, 134, 238, 0.6);
border-radius: 0.3rem;
margin: 2px;
width: fit-content;
}
.ippass {
font-family: 'Orbitron', sans-serif;
font-size: small;
color: rgb(128, 100, 232);
outline: 1px ridge rgba(238, 134, 207, 0.6);
border-radius: 0.3rem;
margin: 1px;
width: fit-content;
}
.iss-popup {
background-color: rgba(0, 0, 0, 0.7);
/* Black background with 70% opacity */
color: white;
/* Text color for visibility */
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.5);
/* Optional shadow for better readability */
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 10px;
padding: 10px;
font-family: 'Orbitron', sans-serif;
}
/* Adjust the padding and text color */
.iss-popup h5 {
margin-top: 0;
}
.iss-popup p {
font-size: 14px;
}
.w3-button {
font-family: 'Orbitron', sans-serif;
font-size: 14px;
background: rgba(255, 255, 255, 0);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 10px;
padding: 10px;
margin: 0px;
width: fit-content;
position: relative;
z-index: 100;
/* Ensure it's in front of the WebGL globe */
}
.w3-hide {
display: none;
}
.w3-show {
display: block;
position: absolute;
z-index: 100;
/* Ensure it's in front of the WebGL globe */
}
#pop-under {
z-index: 1;
position: relative;
}
</style>
<!-- <script>
function initialize() {
if (window.location.href.substr(0, 5) === 'file:') {
alert("This file must be accessed via http:// or https:// to run properly.");
}
earth = new WE.map('earth_div');
earth.setView([46.8011, 8.2266], 2);
WE.tileLayer('{z}/{x}/{y}.jpg', {
tileSize: 256,
bounds: [[-85, -180], [85, 180]],
minZoom: 0,
maxZoom: 16,
attribution: 'WebGLEarth example',
tms: true
}).addTo(earth);
}
</script> -->
<!-- Include satellite.js for tracking ISS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/satellite.js/4.0.0/satellite.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="jquery.vidbacking.js"></script>
</head>
<body onload="initialize()">
<div id="w3-menu-container" class="w3-bar w3-center">
<a href="index.html" class="w3-button"><img src="iss4.png" height="50px" width="40px" alt="ISS"></a>
<a href="space-astro.html" class="w3-button"><img src="cosmo.png" height="50px" width="40px"
alt="Space"></a>
<a href="lancements.html" class="w3-button"><img src="fusée.png" height="50px" width="40px"
alt="Launches"></a>
<a href="exo-arecibo.html" class="w3-button"><img src="saturne.png" height="50px" width="40px"
alt="Exoplanets"></a>
<a href="apod.html" class="w3-button"><img src="telescope.png" height="50px" width="40px" alt="APOD"></a>
</div>
<div id="main" class="w3-mobile">
<!-- video background -->
<video poster="starryNight2.jpeg" autoplay muted loop class="vidbacking">
</video>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="jquery.vidbacking.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('body').vidbacking({
'masked': false
});
});
</script>
<div id="earth_div" class="w3-container w3-block"></div>
</div>
<script src="api.js"></script>
<script>
let earth, userLatitude, userLongitude, issMarker;
// Initialize the WebGL globe
function initialize() {
earth = new WE.map('earth_div');
WE.tileLayer('https://data.geopf.fr/wmts?'+
'&REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0&TILEMATRIXSET=PM'+
'&LAYER={ignLayer}&STYLE={style}&FORMAT={format}'+
'&TILECOL={x}&TILEROW={y}&TILEMATRIX={z}',
{
ignLayer: 'GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2',
style: 'normal',
format: 'image/png',
service: 'WMTS',
opacity: 0,
attribution: 'Carte © IGN/Geoplateforme'
}).addTo(earth);
rotateEarth();
fetchUserLocation(); // Fetch user location after initializing the earth
}
// Function to rotate the earth
function rotateEarth() {
let before = null;
requestAnimationFrame(function animate(now) {
let c = earth.getPosition();
let elapsed = before ? now - before : 0;
before = now;
earth.setCenter([c[0], c[1] + 0.3 * (elapsed / 20)]);
requestAnimationFrame(animate);
});
}
// Fetch user's geolocation and update the marker
function fetchUserLocation() {
return new Promise((resolve, reject) => {
$.getJSON('https://geolocation-db.com/json/')
.done(function (location) {
// Fetch geolocation data and update the page elements
document.getElementById('country').textContent = location.country_name;
document.getElementById('state').textContent = location.state;
document.getElementById('city').textContent = location.city;
// document.getElementById('ip').textContent = location.IPv4;
// Parse and store the user latitude and longitude
userLatitude = parseFloat(location.latitude);
userLongitude = parseFloat(location.longitude);
// Ensure valid coordinates before adding the visitor marker
if (!isNaN(userLatitude) && !isNaN(userLongitude)) {
addVisitorMarker(); // Add the visitor's marker on the globe
resolve({ latitude: userLatitude, longitude: userLongitude });
} else {
console.error('Invalid user location data');
reject('Invalid user location data');
}
})
.fail(function () {
console.error('Error fetching location data');
reject('Error fetching location data');
});
});
}
// Add visitor marker
function addVisitorMarker() {
if (!earth) {
console.error('Earth object is not initialized yet.');
return;
}
const popupContent = `
<div class="w3-card-4 w3-padding iss-popup">
<a class="w3-animate-fading"><u>YOU ARE HERE</u></a><br>
<i>Lat:</i> <div class="w3-text-green w3-tag w3-round">${userLatitude.toFixed(4)}</div><br>
<i>Long:</i> <div class="w3-text-green w3-tag w3-round">${userLongitude.toFixed(4)}</div>
</div>`;
const visitorMarker = WE.marker([userLatitude, userLongitude]).addTo(earth);
visitorMarker.bindPopup(popupContent, { maxWidth: 140, closeButton: true }).openPopup();
}
// Fetch ISS data and update the marker
function fetchISSData() {
fetch('https://api.wheretheiss.at/v1/satellites/25544')
.then(response => response.json())
.then(data => {
const issLatitude = parseFloat(data.latitude);
const issLongitude = parseFloat(data.longitude);
const issAltitude = parseFloat(data.altitude);
const issVelocity = parseFloat(data.velocity);
// Ensure valid ISS coordinates
if (!isNaN(issLatitude) && !isNaN(issLongitude)) {
// Update HTML for ISS data
document.getElementById('latitude').textContent = issLatitude.toFixed(4);
document.getElementById('longitude').textContent = issLongitude.toFixed(4);
document.getElementById('altitude').textContent = issAltitude.toFixed(2) + ' km';
document.getElementById('velocity').textContent = issVelocity.toFixed(2) + ' km/h';
// Calculate real-time distance between the visitor and the ISS
if (userLatitude && userLongitude) {
const distance = haversineDistance(userLatitude, userLongitude, issLatitude, issLongitude);
if (!isNaN(distance)) {
document.getElementById('distance').textContent = distance.toFixed(2) + ' km';
} else {
console.error('Invalid distance calculation');
document.getElementById('distance').textContent = 'N/A';
}
}
updateISSMarker(data); // Update ISS marker on the globe
} else {
console.error('Invalid ISS data');
}
})
.catch(error => {
console.error('Error fetching ISS data:', error);
});
}
// Update ISS marker on the globe
function updateISSMarker(data) {
const popupContent = `
<div class="w3-animate-fading w3-card-4 w3-padding iss-popup pop-under">
<button onclick="toggleInfo()" class="w3-button w3-indigo w3-block">ISS >>></button>
<div id="issDetails" class="w3-hide w3-animate-zoom">
<p><b>Latitude:</b> <span class="w3-text-green w3-tag w3-round">${data.latitude.toFixed(4)}</span></p>
<p><b>Longitude:</b> <span class="w3-text-green w3-tag w3-round">${data.longitude.toFixed(4)}</span></p>
<p><b>Altitude: </b><span class="w3-text-green w3-tag w3-round">${data.altitude.toFixed(2)} km</span></p>
<p><b>Velocity: </b><span class="w3-text-green w3-tag w3-round">${data.velocity.toFixed(2)} km/h</span></p>
</div>
</div>`;
// Remove previous ISS marker if i
if (issMarker) {
earth.removeMarker(issMarker);
}
// Add a new marker for the ISS
issMarker = WE.marker([data.latitude, data.longitude],'iss3.png',80,55).addTo(earth);
issMarker.bindPopup(popupContent, { maxWidth: 145, closeButton: true }).openPopup();
}
// Haversine distance function
function haversineDistance(lat1, lon1, lat2, lon2) {
const R = 6371; // Radius of the Earth in km
const dLat = (lat2 - lat1) * (Math.PI / 180);
const dLon = (lon2 - lon1) * (Math.PI / 180);
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(lat1 * (Math.PI / 180)) * Math.cos(lat2 * (Math.PI / 180)) *
Math.sin(dLon / 2) * Math.sin(dLon / 2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return R * c; // Distance in km
}
// Fetch ISS TLE Data (Two-Line Element Set)
async function fetchISSTLE() {
const response = await fetch('https://celestrak.com/NORAD/elements/stations.txt');
const tleData = await response.text();
return tleData.split('\n').slice(1, 3); // Get the two TLE lines
}
// Predict ISS pass over a given location using satellite.js
function predictISSPasses(tleLine1, tleLine2, userLat, userLon) {
const passes = [];
const iss = satellite.twoline2satrec(tleLine1, tleLine2);
const startTime = new Date(); // current time
// Loop to calculate for the next 10 orbits (~15 minutes per orbit)
for (let i = 0; i < 30; i++) {
const time = new Date(startTime.getTime() + i * 90 * 60 * 1000); // 90 min intervals
const positionAndVelocity = satellite.propagate(iss, time);
const positionEci = positionAndVelocity.position;
const gmst = satellite.gstime(time);
const positionGd = satellite.eciToGeodetic(positionEci, gmst);
const latitude = satellite.degreesLat(positionGd.latitude);
const longitude = satellite.degreesLong(positionGd.longitude);
const distance = haversineDistance(userLat, userLon, latitude, longitude);
// ISS pass if it's within 2000 km (visible range)
if (distance <= 2000) {
passes.push({ time, latitude, longitude, distance });
}
}
return passes;
}
async function calculateISSPasses() {
const issPassesDiv = document.getElementById('iss-passes');
try {
// Fetch the TLE lines for the ISS
const tleLines = await fetchISSTLE();
// Fetch the user's location
const userLocation = await fetchUserLocation();
// Predict ISS passes over the user's location
const passes = predictISSPasses(
tleLines[0], tleLines[1],
userLocation.latitude, userLocation.longitude
);
// Display pass times
if (passes.length > 0) {
issPassesDiv.innerHTML = '<p>';
passes.forEach(pass => {
const passTime = pass.time.toLocaleString();
issPassesDiv.innerHTML += `<a class="w3-tag w3-round w3-transparent"><u>Pass:</u><a class="w3-tag w3-round w3-black w3-text-light-blue"> ${passTime} </a></a>
<a class="w3-tag w3-round w3-transparent"><u> Distance:</u><a class="w3-tag w3-round w3-black w3-text-light-blue"> ${pass.distance.toFixed(2)} km</a></a><br>`;
});
issPassesDiv.innerHTML += '</p>';
} else {
issPassesDiv.textContent = 'No upcoming passes within visible range.';
}
} catch (error) {
issPassesDiv.textContent = 'Error calculating ISS passes: ' + error;
}
}
// Accordion function to toggle visibility
function toggleAccordion() {
const accordionContent = document.getElementById("issAccordion");
// Toggle visibility with W3CSS animation
if (accordionContent.classList.contains("w3-hide")) {
accordionContent.classList.remove("w3-hide");
} else {
accordionContent.classList.add("w3-hide");
}
}
// Function to toggle the visibility of the detailed information
function toggleInfo() {
const infoDiv = document.getElementById("issDetails");
if (infoDiv.classList.contains("w3-hide")) {
infoDiv.classList.remove("w3-hide");
} else {
infoDiv.classList.add("w3-hide");
}
}
// Initialize everything when the window is loaded
window.onload = function () {
initialize();
calculateISSPasses();
};
// Update ISS data every 8 seconds
setInterval(fetchISSData, 8000);
</script>
<div class="w3-container">
<button onclick="toggleAccordion()"
class="w3-button w3-indigo w3-block w3-left-align w3-xlarge">Dist.</button>
<div id="issAccordion" class="w3-hide w3-animate-opacity w3-light-gray ">
<div class="w3-auto w3-row w3-padding w3-show ">
<div class="w3-container w3-animate-left">
<div class="ip w3-tag"><strong>Country:</strong> <span id="country"
class="w3-text-green"></span></div>
<div class="ip w3-tag"><strong>State:</strong> <span id="state" class="w3-text-green"></span>
</div>
<div class="ip w3-tag"><strong>City:</strong> <span id="city" class="w3-text-green"></span>
</div>
<!-- <div class="ip w3-tag"><strong>IP:</strong> <span id="ip" class="w3-text-green"></span></div> -->
</div><br>
<div id="distance-container" class="ip w3-tag w3-pale-blue w3-center">Distance ISS: <span
id="distance" class="w3-text-green w3-xlarge"></span></div><br><br>
<div class="w3-container w3-animate-bottom2">
<div class="ip w3-tag"><strong>Altitude:</strong> <span id="altitude"
class="w3-text-green"></span></div>
<div class="ip w3-tag"><strong>Velocity:</strong><span id="velocity"
class="w3-text-green"></span></div>
<div class="ip w3-tag"><strong>ISS Latitude:</strong> <span id="latitude"
class="w3-text-green"></span></div>
<div class="ip w3-tag"><strong>ISS Longitude:</strong> <span id="longitude"
class="w3-text-green"></span></div>
</div><br>
<div class="ippass w3-left w3-animate-bottom"><span
id="iss-passes"" class="w3-left w3-text-white w3-large w3-animate-opacity">Calculating ...</span></div><br>
</div>
</div>
</div>
</body>
</html>