Skip to content

Commit c613bd0

Browse files
committed
add code for 1.5
1 parent 2420e7a commit c613bd0

File tree

3 files changed

+77
-8
lines changed

3 files changed

+77
-8
lines changed

module1/03_mapping_iss/index.html

-8
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,17 @@ <h1>Where is the ISS?</h1>
5353

5454
const api_url = 'https://api.wheretheiss.at/v1/satellites/25544';
5555

56-
let firstTime = true;
57-
5856
async function getISS() {
5957
const response = await fetch(api_url);
6058
const data = await response.json();
6159
const { latitude, longitude } = data;
6260

6361
marker.setLatLng([latitude, longitude]);
64-
if (firstTime) {
65-
mymap.setView([latitude, longitude], 2);
66-
firstTime = false;
67-
}
6862
document.getElementById('lat').textContent = latitude.toFixed(2);
6963
document.getElementById('lon').textContent = longitude.toFixed(2);
7064
}
7165

7266
getISS();
73-
74-
setInterval(getISS, 1000);
7567
</script>
7668
</body>
7769
</html>
+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=\, initial-scale=1.0" />
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
7+
<link
8+
rel="stylesheet"
9+
href="https://unpkg.com/[email protected]/dist/leaflet.css"
10+
integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA=="
11+
crossorigin=""
12+
/>
13+
<script
14+
src="https://unpkg.com/[email protected]/dist/leaflet.js"
15+
integrity="sha512-QVftwZFqvtRNi0ZyCtsznlKSWOStnDORoefr1enyq5mVL4tmKB3S/EnC3rRJcxCPavG10IcrVGSmPh6Qw5lwrg=="
16+
crossorigin=""
17+
></script>
18+
<style>
19+
#issMap {
20+
height: 180px;
21+
}
22+
</style>
23+
24+
<title>Fetch JSON from API and map lat lon</title>
25+
</head>
26+
<body>
27+
<h1>Where is the ISS?</h1>
28+
29+
<p>
30+
latitude: <span id="lat"></span>°<br />
31+
longitude: <span id="lon"></span>°
32+
</p>
33+
34+
<div id="issMap"></div>
35+
36+
<script>
37+
// Making a map and tiles
38+
const mymap = L.map('issMap').setView([0, 0], 1);
39+
const attribution =
40+
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors';
41+
42+
const tileUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
43+
const tiles = L.tileLayer(tileUrl, { attribution });
44+
tiles.addTo(mymap);
45+
46+
// Making a marker with a custom icon
47+
const issIcon = L.icon({
48+
iconUrl: 'iss200.png',
49+
iconSize: [50, 32],
50+
iconAnchor: [25, 16]
51+
});
52+
const marker = L.marker([0, 0], { icon: issIcon }).addTo(mymap);
53+
54+
const api_url = 'https://api.wheretheiss.at/v1/satellites/25544';
55+
56+
let firstTime = true;
57+
58+
async function getISS() {
59+
const response = await fetch(api_url);
60+
const data = await response.json();
61+
const { latitude, longitude } = data;
62+
63+
marker.setLatLng([latitude, longitude]);
64+
if (firstTime) {
65+
mymap.setView([latitude, longitude], 2);
66+
firstTime = false;
67+
}
68+
document.getElementById('lat').textContent = latitude.toFixed(2);
69+
document.getElementById('lon').textContent = longitude.toFixed(2);
70+
}
71+
72+
getISS();
73+
74+
setInterval(getISS, 1000);
75+
</script>
76+
</body>
77+
</html>
11.9 KB
Loading

0 commit comments

Comments
 (0)