mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
journeyLeg: polyline option
This commit is contained in:
parent
7c6e87afff
commit
37770654e1
3 changed files with 17 additions and 4 deletions
|
@ -25,7 +25,8 @@ With `opt`, you can override the default options, which look like this:
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
when: new Date(),
|
when: new Date(),
|
||||||
passedStations: true // return stations on the way?
|
passedStations: true, // return stations on the way?
|
||||||
|
polyline: false // return a shape for the leg?
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -116,3 +117,5 @@ The response looked like this:
|
||||||
passed: [ /* … */ ]
|
passed: [ /* … */ ]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you pass `polyline: true`, the leg will have a `polyline` field, containing an encoded shape. You can use e.g. [`@mapbox/polyline`](https://www.npmjs.com/package/@mapbox/polyline) to decode it.
|
||||||
|
|
12
index.js
12
index.js
|
@ -270,7 +270,8 @@ const createClient = (profile, request = _request) => {
|
||||||
throw new Error('lineName must be a non-empty string.')
|
throw new Error('lineName must be a non-empty string.')
|
||||||
}
|
}
|
||||||
opt = Object.assign({
|
opt = Object.assign({
|
||||||
passedStations: true // return stations on the way?
|
passedStations: true, // return stations on the way?
|
||||||
|
polyline: false
|
||||||
}, opt)
|
}, opt)
|
||||||
opt.when = opt.when || new Date()
|
opt.when = opt.when || new Date()
|
||||||
|
|
||||||
|
@ -280,11 +281,16 @@ const createClient = (profile, request = _request) => {
|
||||||
req: {
|
req: {
|
||||||
jid: ref,
|
jid: ref,
|
||||||
name: lineName,
|
name: lineName,
|
||||||
date: profile.formatDate(profile, opt.when)
|
date: profile.formatDate(profile, opt.when),
|
||||||
|
getPolyline: !!opt.polyline
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
const parse = profile.parseJourneyLeg(profile, d.locations, d.lines, d.remarks)
|
let polylines = []
|
||||||
|
if (opt.polyline && Array.isArray(d.common.polyL)) {
|
||||||
|
polylines = d.common.polyL.map(p => p.crdEncYX)
|
||||||
|
}
|
||||||
|
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
|
||||||
type: 'JNY',
|
type: 'JNY',
|
||||||
|
|
|
@ -13,6 +13,10 @@ client.journeys('900000003201', '900000024101', {results: 1, polylines: true})
|
||||||
// client.nearby(52.5137344, 13.4744798, {distance: 60})
|
// client.nearby(52.5137344, 13.4744798, {distance: 60})
|
||||||
// client.radar(52.52411, 13.41002, 52.51942, 13.41709, {results: 10})
|
// client.radar(52.52411, 13.41002, 52.51942, 13.41709, {results: 10})
|
||||||
|
|
||||||
|
// .then(([journey]) => {
|
||||||
|
// const leg = journey.legs[0]
|
||||||
|
// return client.journeyLeg(leg.id, leg.line.name, {polyline: true})
|
||||||
|
// })
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.log(require('util').inspect(data, {depth: null}))
|
console.log(require('util').inspect(data, {depth: null}))
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue