Skip to content
Snippets Groups Projects
Commit 608b09c0 authored by insert's avatar insert
Browse files

Can add actual stops now

parent ee54cf68
Branches
No related merge requests found
......@@ -104,18 +104,45 @@ const request = {
},
search: query => {
return new Promise((resolve, reject) => {
// avoid stopType = NaptanRailEntrance
// if [NaptanOnstreetBusCoachStopCluster, NaptanOnstreetBusCoachStopPair] get child and process
// add NaptanPublicBusCoachTram [check indicator] = "e.g. Stop Y"
fetch('https://api.tfl.gov.uk/StopPoint/Search/' + query)
.then(response => response.json())
.then(source => {
let data = [];
let search = [];
source.matches.forEach(res => {
data.push({
id: res.id,
modes: res.modes,
name: res.name,
});
search.push(res.id);
});
resolve(data);
fetch('https://api.tfl.gov.uk/StopPoint/' + search.join(','))
.then(response => response.json())
.then(source => {
let data = [];
let process = (x, name) => {
if (['NaptanOnstreetBusCoachStopCluster', 'NaptanOnstreetBusCoachStopPair'].indexOf(x.stopType) > -1) {
x.children.forEach(y => process(y));
} else if (x.stopType == 'NaptanPublicBusCoachTram') {
let name = x.commonName;
if (x.indicator) {
name += ` [${x.indicator}]`
}
data.push({
id: x.id,
name,
//modes: res.modes,
});
}
};
if (search.length > 1) {
source.forEach(res => {
process(res);
});
} else {
process(source);
}
resolve(data);
})
.catch(reject);
})
.catch(reject);
});
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment