mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
merge master into next
This commit is contained in:
commit
c9e77f3050
6 changed files with 37 additions and 13 deletions
|
@ -1,5 +1,11 @@
|
|||
# Changelog
|
||||
|
||||
## `2.7.0`
|
||||
|
||||
- `journeys()`: `polylines` option
|
||||
- `journeyLeg()`: `polyline` option
|
||||
- `radar()`: `polylines` option
|
||||
|
||||
## `2.6.0`
|
||||
|
||||
- 5d10d76 journey legs: parse cycle
|
||||
|
|
|
@ -11,6 +11,7 @@ With `opt`, you can override the default options, which look like this:
|
|||
results: 256, // maximum number of vehicles
|
||||
duration: 30, // compute frames for the next n seconds
|
||||
frames: 3, // nr of frames to compute
|
||||
polylines: false // return a track shape for each vehicle?
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -161,3 +162,5 @@ The response may look like this:
|
|||
} ]
|
||||
}, /* … */ ]
|
||||
```
|
||||
|
||||
If you pass `polylines: true`, each result 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.
|
||||
|
|
9
index.js
9
index.js
|
@ -321,7 +321,8 @@ const createClient = (profile, request = _request) => {
|
|||
results: 256, // maximum number of vehicles
|
||||
duration: 30, // compute frames for the next n seconds
|
||||
frames: 3, // nr of frames to compute
|
||||
products: null // optionally an object of booleans
|
||||
products: null, // optionally an object of booleans
|
||||
polylines: false // return a track shape for each vehicle?
|
||||
}, opt || {})
|
||||
opt.when = opt.when || new Date()
|
||||
|
||||
|
@ -347,7 +348,11 @@ const createClient = (profile, request = _request) => {
|
|||
.then((d) => {
|
||||
if (!Array.isArray(d.jnyL)) return []
|
||||
|
||||
const parse = profile.parseMovement(profile, d.locations, d.lines, d.remarks)
|
||||
let polylines = []
|
||||
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)
|
||||
return d.jnyL.map(parse)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "hafas-client",
|
||||
"description": "JavaScript client for HAFAS public transport APIs.",
|
||||
"version": "2.6.0",
|
||||
"version": "2.7.2",
|
||||
"main": "index.js",
|
||||
"files": [
|
||||
"index.js",
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
'use strict'
|
||||
|
||||
const createParseMovement = (profile, locations, lines, remarks) => {
|
||||
const createParseMovement = (profile, locations, lines, remarks, polylines = []) => {
|
||||
// todo: what is m.dirGeo? maybe the speed?
|
||||
// todo: what is m.stopL?
|
||||
// todo: what is m.proc? wut?
|
||||
// todo: what is m.pos?
|
||||
// todo: what is m.ani.dirGeo[n]? maybe the speed?
|
||||
// todo: what is m.ani.proc[n]? wut?
|
||||
// todo: how does m.ani.poly work?
|
||||
const parseMovement = (m) => {
|
||||
const pStopover = profile.parseStopover(profile, locations, lines, remarks, m.date)
|
||||
|
||||
const res = {
|
||||
direction: profile.parseStationName(m.dirTxt),
|
||||
journeyId: m.jid || null,
|
||||
trip: m.jid && +m.jid.split('|')[1] || null, // todo: this seems brittle
|
||||
line: lines[m.prodX] || null,
|
||||
location: m.pos ? {
|
||||
|
@ -24,13 +24,23 @@ const createParseMovement = (profile, locations, lines, remarks) => {
|
|||
frames: []
|
||||
}
|
||||
|
||||
if (m.ani && Array.isArray(m.ani.mSec)) {
|
||||
for (let i = 0; i < m.ani.mSec.length; i++) {
|
||||
res.frames.push({
|
||||
origin: locations[m.ani.fLocX[i]] || null,
|
||||
destination: locations[m.ani.tLocX[i]] || null,
|
||||
t: m.ani.mSec[i]
|
||||
})
|
||||
if (m.ani) {
|
||||
if (Array.isArray(m.ani.mSec)) {
|
||||
for (let i = 0; i < m.ani.mSec.length; i++) {
|
||||
res.frames.push({
|
||||
origin: locations[m.ani.fLocX[i]] || null,
|
||||
destination: locations[m.ani.tLocX[i]] || null,
|
||||
t: m.ani.mSec[i]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (m.ani.poly && m.ani.poly.crdEncYX) {
|
||||
res.polyline = m.ani.poly.crdEncYX
|
||||
} else if (m.ani.polyG && Array.isArray(m.ani.polyG.polyXL)) {
|
||||
let p = m.ani.polyG.polyXL[0]
|
||||
// todo: there can be >1 polyline
|
||||
res.polyline = polylines[p] && polylines[p].crdEncYX || null
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ HAFAS endpoint | wrapper library | docs | example code | source code
|
|||
[](https://www.npmjs.com/package/hafas-client)
|
||||
[](https://travis-ci.org/public-transport/hafas-client)
|
||||

|
||||
[](https://gitter.im/derhuerst)
|
||||
[](https://gitter.im/public-transport/Lobby)
|
||||
[](https://patreon.com/derhuerst)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue