-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.html
86 lines (76 loc) · 3.02 KB
/
map.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Us-Planes</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin=""/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<style>
.map {
height: 80vh;
}
</style>
</head>
<body>
<h1>Map starts from here</h1>
<div class="map" id="map"></div>
<script>
planes = {};
us_flight = 'https://opensky-network.org/api/states/all?lamin=30.038&lomin=-125.974&lamax=52.214&lomax=-68.748';
function plane_marker(plane) {
if (planes[plane[1]]) {
planes[plane[1]] = planes[plane[1]].setLatLng(new L.LatLng(plane[6], plane[5]));
} else {
planes[plane[1]] = L.marker([plane[6], plane[5]], {icon:greenIcon}).addTo(map);
}
}
map = L.map('map').setView([40.05264061210646, -102.4081931668813], 4);
L.tileLayer('https://api.maptiler.com/maps/openstreetmap/{z}/{x}/{y}.jpg?key=1oCmNBJXvSNb2J7xQsUM', {
maxZoom: 19,
attribution: '<a href="https://www.maptiler.com/copyright/" target="_blank">© MapTiler</a> <a href="https://www.openstreetmap.org/copyright" target="_blank">© OpenStreetMap contributors</a>'
}).addTo(map);
greenIcon = L.icon({
iconUrl: 'flight_FILL0_wght400_GRAD0_opsz24.png',
iconSize: [24, 24],
iconAnchor: [12, 12],
popupAnchor: [-3, -76]
});
var xml = new XMLHttpRequest();
xml.open('GET', us_flight, true);
xml.send();
xml.onload = () => {
console.log('api call loaded')
if (xml.status === 200) {
let response = JSON.parse(xml.response)['states'];
console.log('got the api')
for (i in response) {
plane_marker(response[i], i)
if (i==10){break}
}
} else {
response = "error";
console.log('error in api')
}
}
setInterval(function() {
xml.open('GET', us_flight, true);
xml.send();
xml.onload = () => {
console.log('api call loaded')
if (xml.status === 200) {
let response = JSON.parse(xml.response)['states'];
console.log('got the api')
for (i in response) {
plane_marker(response[i], i)
if (i==10){break}
}
} else {
response = "error";
console.log('error in api')
}
}
}, 12000)
</script>
</body>
</html>