-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (49 loc) · 1.6 KB
/
Copy pathindex.js
File metadata and controls
57 lines (49 loc) · 1.6 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
let map = L.map("map").setView([40.4167047, -3.7035825], 5);
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution: "Map data © OpenStreetMap contributors",
}).addTo(map);
var newGreenIcon = new L.Icon({
iconUrl: "./airport.png",
iconSize: [32, 37], // size of the icon
iconAnchor: [16, 37], // point of the icon which will correspond to marker's location
popupAnchor: [0, -25], // point from which the popup should open relative to the iconAnchor
});
const flightjson_url =
"https://airlabs.co/api/v9/flights?api_key=5d5b4894-fa52-4a7f-bd66-1819e9b02949";
fetch(flightjson_url)
.then((response) => response.json())
.then((data) => {
let flagFlights = data.response.filter((flight) => flight.flag === "ES");
let dataGeoJson = {
type: "FeatureCollection",
features: [],
};
flagFlights.forEach((flight, k) => {
dataGeoJson.features.push({
type: "Feature",
geometry: {
type: "Point",
coordinates: [flight.lng, flight.lat],
},
properties: {
...flight,
},
});
});
console.log(dataGeoJson);
L.geoJson(dataGeoJson
,{
onEachFeature: function (feature, layer) {
layer.bindPopup(`
<p>Status: ${feature.properties.status}</p>
<p>Departure: ${
feature.properties.dep_iata ? feature.properties.dep_iata : "No data"
}</p>
<p>Arribal: ${
feature.properties.arr_iata ? feature.properties.arr_iata : "No data"
}</p>
`);
layer.setIcon(newGreenIcon);
},
}).addTo(map);
});