merge master into next

This commit is contained in:
Jannis R 2018-05-16 19:41:45 +02:00
commit c9e77f3050
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
6 changed files with 37 additions and 13 deletions

View file

@ -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

View file

@ -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.

View file

@ -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)
})
}

View file

@ -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",

View file

@ -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,7 +24,8 @@ const createParseMovement = (profile, locations, lines, remarks) => {
frames: []
}
if (m.ani && Array.isArray(m.ani.mSec)) {
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,
@ -34,6 +35,15 @@ const createParseMovement = (profile, locations, lines, remarks) => {
}
}
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
}
}
return res
}
return parseMovement

View file

@ -13,7 +13,7 @@ HAFAS endpoint | wrapper library | docs | example code | source code
[![npm version](https://img.shields.io/npm/v/hafas-client.svg)](https://www.npmjs.com/package/hafas-client)
[![build status](https://img.shields.io/travis/public-transport/hafas-client.svg)](https://travis-ci.org/public-transport/hafas-client)
![ISC-licensed](https://img.shields.io/github/license/public-transport/hafas-client.svg)
[![chat on gitter](https://badges.gitter.im/derhuerst.svg)](https://gitter.im/derhuerst)
[![chat on gitter](https://badges.gitter.im/public-transport/Lobby.svg)](https://gitter.im/public-transport/Lobby)
[![support me on Patreon](https://img.shields.io/badge/support%20me-on%20patreon-fa7664.svg)](https://patreon.com/derhuerst)