-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathhandlers.js
39 lines (35 loc) · 1.03 KB
/
handlers.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
39
/* located in js/handlers.js */
on_each_feature = function(f, l) {
l.bindPopup(function() {
return '<h5>' + dayjs.unix(f.properties.timestamp).format() + '</h5>';
});
}
source = function(responseHandler, errorHandler) {
var url = 'https://api.wheretheiss.at/v1/satellites/25544';
fetch(url)
.then((response) => {
return response.json().then((data) => {
var { id, timestamp, longitude, latitude } = data;
return {
'type': 'FeatureCollection',
'features': [{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [longitude, latitude]
},
'properties': {
'id': id,
'timestamp': timestamp
}
}]
};
})
})
.then(responseHandler)
.catch(errorHandler);
}
module.exports = {
source,
on_each_feature
}