mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
parseJourneyLeg, parseMovement: use parsePolyline 💥, refactor
This commit is contained in:
parent
deefeb1f64
commit
431574b756
3 changed files with 14 additions and 19 deletions
15
index.js
15
index.js
|
@ -149,10 +149,7 @@ const createClient = (profile, request = _request) => {
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
if (!Array.isArray(d.outConL)) return []
|
if (!Array.isArray(d.outConL)) return []
|
||||||
|
|
||||||
let polylines = []
|
const polylines = opt.polyline && d.common.polyL || []
|
||||||
if (opt.polylines && Array.isArray(d.common.polyL)) {
|
|
||||||
polylines = d.common.polyL
|
|
||||||
}
|
|
||||||
const parse = profile.parseJourney(profile, d.locations, d.lines, d.remarks, polylines)
|
const parse = profile.parseJourney(profile, d.locations, d.lines, d.remarks, polylines)
|
||||||
|
|
||||||
if (!journeys.earlierRef) journeys.earlierRef = d.outCtxScrB
|
if (!journeys.earlierRef) journeys.earlierRef = d.outCtxScrB
|
||||||
|
@ -298,10 +295,7 @@ const createClient = (profile, request = _request) => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
let polylines = []
|
const polylines = opt.polyline && d.common.polyL || []
|
||||||
if (opt.polyline && Array.isArray(d.common.polyL)) {
|
|
||||||
polylines = d.common.polyL
|
|
||||||
}
|
|
||||||
const parse = profile.parseJourneyLeg(profile, d.locations, d.lines, d.remarks, polylines)
|
const parse = profile.parseJourneyLeg(profile, d.locations, d.lines, d.remarks, polylines)
|
||||||
|
|
||||||
const leg = { // pretend the leg is contained in a journey
|
const leg = { // pretend the leg is contained in a journey
|
||||||
|
@ -354,10 +348,7 @@ const createClient = (profile, request = _request) => {
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
if (!Array.isArray(d.jnyL)) return []
|
if (!Array.isArray(d.jnyL)) return []
|
||||||
|
|
||||||
let polylines = []
|
const polylines = opt.polyline && d.common.polyL || []
|
||||||
if (opt.polylines && d.common && Array.isArray(d.common.polyL)) {
|
|
||||||
polylines = d.common.polyL
|
|
||||||
}
|
|
||||||
const parse = profile.parseMovement(profile, d.locations, d.lines, d.remarks, polylines)
|
const parse = profile.parseMovement(profile, d.locations, d.lines, d.remarks, polylines)
|
||||||
return d.jnyL.map(parse)
|
return d.jnyL.map(parse)
|
||||||
})
|
})
|
||||||
|
|
|
@ -36,9 +36,10 @@ const createParseJourneyLeg = (profile, stations, lines, remarks, polylines) =>
|
||||||
|
|
||||||
if (pt.jny && pt.jny.polyG) {
|
if (pt.jny && pt.jny.polyG) {
|
||||||
let p = pt.jny.polyG.polyXL
|
let p = pt.jny.polyG.polyXL
|
||||||
p = p && polylines[p[0]]
|
p = Array.isArray(p) && polylines[p[0]]
|
||||||
// todo: there can be >1 polyline
|
// todo: there can be >1 polyline
|
||||||
res.polyline = p && p.crdEncYX || null
|
const parse = profile.parsePolyline(stations)
|
||||||
|
res.polyline = p && parse(p) || null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pt.type === 'WALK') {
|
if (pt.type === 'WALK') {
|
||||||
|
|
|
@ -35,12 +35,15 @@ const createParseMovement = (profile, locations, lines, remarks, polylines = [])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m.ani.poly && m.ani.poly.crdEncYX) {
|
if (m.ani.poly) {
|
||||||
res.polyline = m.ani.poly.crdEncYX
|
const parse = profile.parsePolyline(locations)
|
||||||
} else if (m.ani.polyG && Array.isArray(m.ani.polyG.polyXL)) {
|
res.polyline = parse(m.ani.poly)
|
||||||
let p = m.ani.polyG.polyXL[0]
|
} else if (m.ani.polyG) {
|
||||||
|
let p = m.ani.polyG.polyXL
|
||||||
|
p = Array.isArray(p) && polylines[p[0]]
|
||||||
// todo: there can be >1 polyline
|
// todo: there can be >1 polyline
|
||||||
res.polyline = polylines[p] && polylines[p].crdEncYX || null
|
const parse = profile.parsePolyline(locations)
|
||||||
|
res.polyline = p && parse(p) || null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue