From 0783d9e68a4b2fe63315e3abd92a44d6df2a0bfc Mon Sep 17 00:00:00 2001 From: Jannis R Date: Sun, 13 May 2018 22:42:02 +0200 Subject: [PATCH 1/7] fix Gitter badge --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index d5b042ef..70e885b1 100644 --- a/readme.md +++ b/readme.md @@ -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) From 9a0bfc39a45fa69c01dfa0365e34c746c5e43309 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Tue, 15 May 2018 19:39:28 +0200 Subject: [PATCH 2/7] radar: polylines option, return polylines --- docs/radar.md | 3 +++ index.js | 9 +++++++-- parse/movement.js | 27 ++++++++++++++++++--------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/docs/radar.md b/docs/radar.md index 281b2f77..8c4fa6a8 100644 --- a/docs/radar.md +++ b/docs/radar.md @@ -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? } ``` @@ -156,3 +157,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. diff --git a/index.js b/index.js index ac8f5a8e..b08a408b 100644 --- a/index.js +++ b/index.js @@ -313,7 +313,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() @@ -339,7 +340,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 && 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) }) } diff --git a/parse/movement.js b/parse/movement.js index 4a006026..5de96cd9 100644 --- a/parse/movement.js +++ b/parse/movement.js @@ -1,13 +1,12 @@ '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) @@ -24,13 +23,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].crdEncXY || null } } From 39aac10a178a9b6328a7af1a75722760867a1f9a Mon Sep 17 00:00:00 2001 From: Jannis R Date: Tue, 15 May 2018 23:04:13 +0200 Subject: [PATCH 3/7] parseMovement: empty default polylines arr :bug: --- parse/movement.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parse/movement.js b/parse/movement.js index 5de96cd9..5657f053 100644 --- a/parse/movement.js +++ b/parse/movement.js @@ -1,6 +1,6 @@ 'use strict' -const createParseMovement = (profile, locations, lines, remarks, polylines) => { +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? From 7b5f13524d7bc524428183d0c92da3110b2c1adb Mon Sep 17 00:00:00 2001 From: Jannis R Date: Tue, 15 May 2018 23:49:56 +0200 Subject: [PATCH 4/7] 2.7.0 --- docs/changelog.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 135c5d70..3bc5021a 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -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 diff --git a/package.json b/package.json index f1a314b0..bb03ae66 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "hafas-client", "description": "JavaScript client for HAFAS public transport APIs.", - "version": "2.6.0", + "version": "2.7.0", "main": "index.js", "files": [ "index.js", From aa480e01a2842df7b0686d48a98acf4c2cafba2b Mon Sep 17 00:00:00 2001 From: Jannis R Date: Wed, 16 May 2018 00:30:27 +0200 Subject: [PATCH 5/7] radar: fix polylines parsing :bug: --- index.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b08a408b..7ed498ee 100644 --- a/index.js +++ b/index.js @@ -341,7 +341,7 @@ const createClient = (profile, request = _request) => { if (!Array.isArray(d.jnyL)) return [] let polylines = [] - if (opt.polylines && Array.isArray(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) diff --git a/package.json b/package.json index bb03ae66..18ce6e92 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "hafas-client", "description": "JavaScript client for HAFAS public transport APIs.", - "version": "2.7.0", + "version": "2.7.1", "main": "index.js", "files": [ "index.js", From a97e0d31e7c5009b1f6c4d2695227c07a51a1a54 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Wed, 16 May 2018 00:42:45 +0200 Subject: [PATCH 6/7] radar: fix polylines parsing :bug:, 2.7.2 --- package.json | 2 +- parse/movement.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 18ce6e92..9df16958 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "hafas-client", "description": "JavaScript client for HAFAS public transport APIs.", - "version": "2.7.1", + "version": "2.7.2", "main": "index.js", "files": [ "index.js", diff --git a/parse/movement.js b/parse/movement.js index 5657f053..e2efdf5c 100644 --- a/parse/movement.js +++ b/parse/movement.js @@ -39,7 +39,7 @@ const createParseMovement = (profile, locations, lines, remarks, polylines = []) } 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].crdEncXY || null + res.polyline = polylines[p] && polylines[p].crdEncYX || null } } From 48f2cefb5b2b65a5f84f5c499835c3315ab67322 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Wed, 16 May 2018 19:30:09 +0200 Subject: [PATCH 7/7] parseMovement: expose journey (leg) id --- parse/movement.js | 1 + 1 file changed, 1 insertion(+) diff --git a/parse/movement.js b/parse/movement.js index e2efdf5c..7999eb52 100644 --- a/parse/movement.js +++ b/parse/movement.js @@ -12,6 +12,7 @@ const createParseMovement = (profile, locations, lines, remarks, polylines = []) 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 ? {