-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
38 lines (29 loc) · 1.11 KB
/
script.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
const mymap = L.map('mapid').setView([0, 0], 1);
const attribution =
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors';
const tileUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
const tiles = L.tileLayer(tileUrl, { attribution });
tiles.addTo(mymap);
const issIcon = L.icon({
iconUrl: 'iss200.png',
iconSize: [50, 32],
iconAnchor: [25, 16]
});
const marker = L.marker([0, 0], {icon: issIcon}).addTo(mymap);
const api_url = 'https://api.wheretheiss.at/v1/satellites/25544'
let firstTime = true;
async function getISS() {
const data = await fetch(api_url);
const response = await data.json();
const { latitude, longitude, visibility } = response;
marker.setLatLng([latitude, longitude]);
if (firstTime) {
mymap.setView([latitude, longitude], 2);
firstTime = false;
}
document.getElementById('lat').textContent = latitude.toFixed(2);
document.getElementById('lon').textContent = longitude.toFixed(2);
document.getElementById('vis').textContent = visibility;
}
getISS();
setInterval(getISS, 1000);