From 49afc8a75bc7338178c8021af1759d9e519277a7 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Mon, 30 Apr 2018 12:49:33 +0200 Subject: [PATCH] journeys: polylines option --- docs/journeys.md | 5 ++++- index.js | 3 ++- p/vbb/example.js | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/journeys.md b/docs/journeys.md index 152d408d..550a7c15 100644 --- a/docs/journeys.md +++ b/docs/journeys.md @@ -60,7 +60,8 @@ With `opt`, you can override the default options, which look like this: express: true, regional: true }, - tickets: false // return tickets? only available with some profiles + tickets: false, // return tickets? only available with some profiles + polylines: false // return a shape for each leg? } ``` @@ -277,3 +278,5 @@ client.journeys(hbf, heinrichHeineStr) departure of last journey 2017-12-17T19:07:00.000+01:00 departure of first (later) journey 2017-12-17T19:19:00.000+01:00 ``` + +If you pass `polylines: true`, each journey 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. diff --git a/index.js b/index.js index 374c1aa7..e2b178d5 100644 --- a/index.js +++ b/index.js @@ -85,6 +85,7 @@ const createClient = (profile, request = _request) => { accessibility: 'none', // 'none', 'partial' or 'complete' bike: false, // only bike-friendly journeys tickets: false, // return tickets? + polylines: false // return leg shapes? }, opt) if (opt.via) opt.via = profile.formatLocation(profile, opt.via) opt.when = opt.when || new Date() @@ -126,7 +127,7 @@ const createClient = (profile, request = _request) => { getPT: true, // todo: what is this? outFrwd: true, // todo: what is this? getIV: false, // todo: walk & bike as alternatives? - getPolyline: false // todo: shape for displaying on a map? + getPolyline: !!opt.polylines } if (profile.journeysNumF) query.numF = opt.results diff --git a/p/vbb/example.js b/p/vbb/example.js index 079f85c3..0f0831c7 100644 --- a/p/vbb/example.js +++ b/p/vbb/example.js @@ -6,7 +6,7 @@ const vbbProfile = require('.') const client = createClient(vbbProfile) // Hauptbahnhof to Charlottenburg -client.journeys('900000003201', '900000024101', {results: 1}) +client.journeys('900000003201', '900000024101', {results: 1, polylines: true}) // client.departures('900000013102', {duration: 1}) // client.locations('Alexanderplatz', {results: 2}) // client.location('900000042101') // Spichernstr