-
Notifications
You must be signed in to change notification settings - Fork 5
/
load.js
55 lines (46 loc) · 1.68 KB
/
load.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var network = get_parameter_from_url('network');
var ref = get_parameter_from_url('ref');
var qa = get_parameter_from_url('qa');
main()
async function main(){
await load_translation_strings();
if (network && ref){
var overpass_url = `
https://overpass-api.de/api/interpreter?data=[out:json];relation[type=route_master]
[~"network|operator"~"${network}",i]
["ref"="${ref}"];out ids;`
fetch(overpass_url)
.then(function(data) {
return data.json()
})
.then(function(data) {
if (data['elements'].length > 0){
var route_id = data['elements'][0]['id'];
if (qa){
window.location.href = `route.html?line=${route_id}&qa=${qa}`;
} else {
window.location.href = `route.html?line=${route_id}`;
}
} else {
status = i18n_messages["No route has been found :("];
document.getElementById("message").innerHTML = display_error(status);
}
})
.catch(function(error) {
console.error(error.message);
status = i18n_messages["Oops, something went wrong!"]
document.getElementById("message").innerHTML = display_error(status);
});
} else {
status = i18n_messages["Search some route on the home page."]
document.getElementById("message").innerHTML = display_error(status);
}
}
function display_error(error_message){
var template = `
<div class="w3-panel w3-pale-red w3-leftbar w3-border-red">
${error_message}
</div>
`
return template
}