radar: fix polylines option 🐛

Had to set the default value to `true` to stay backwards-compatible.
This commit is contained in:
Jannis R 2018-12-13 19:27:31 +01:00
parent 215fce004b
commit 5beff47dea
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
3 changed files with 14 additions and 12 deletions

View file

@ -11,7 +11,7 @@ With `opt`, you can override the default options, which look like this:
results: 256, // maximum number of vehicles results: 256, // maximum number of vehicles
duration: 30, // compute frames for the next n seconds duration: 30, // compute frames for the next n seconds
frames: 3, // nr of frames to compute frames: 3, // nr of frames to compute
polylines: false, // return a track shape for each vehicle? polylines: true, // return a track shape for each vehicle?
language: 'en' // language to get results in language: 'en' // language to get results in
} }
``` ```

View file

@ -426,7 +426,7 @@ const createClient = (profile, userAgent, request = _request) => {
// todo: what happens with `frames: 0`? // todo: what happens with `frames: 0`?
frames: 3, // nr of frames to compute 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? polylines: true // return a track shape for each vehicle?
}, opt || {}) }, opt || {})
opt.when = new Date(opt.when || Date.now()) opt.when = new Date(opt.when || Date.now())
if (Number.isNaN(+opt.when)) throw new Error('opt.when is invalid') if (Number.isNaN(+opt.when)) throw new Error('opt.when is invalid')
@ -458,7 +458,7 @@ const createClient = (profile, userAgent, request = _request) => {
lines: d.lines, lines: d.lines,
hints: d.hints, hints: d.hints,
warnings: d.warnings, warnings: d.warnings,
polylines: opt.polyline && d.common.polyL || [] polylines: opt.polylines && d.common.polyL || []
}) })
return d.jnyL.map(parse) return d.jnyL.map(parse)
}) })

View file

@ -37,15 +37,17 @@ const createParseMovement = (profile, opt, data) => {
} }
} }
if (m.ani.poly) { if (opt.polylines) {
const parse = profile.parsePolyline(profile, opt, data) if (m.ani.poly) {
res.polyline = parse(m.ani.poly) const parse = profile.parsePolyline(profile, opt, data)
} else if (m.ani.polyG) { res.polyline = parse(m.ani.poly)
let p = m.ani.polyG.polyXL } else if (m.ani.polyG) {
p = Array.isArray(p) && polylines[p[0]] let p = m.ani.polyG.polyXL
// todo: there can be >1 polyline p = Array.isArray(p) && polylines[p[0]]
const parse = profile.parsePolyline(profile, opt, data) // todo: there can be >1 polyline
res.polyline = p && parse(p) || null const parse = profile.parsePolyline(profile, opt, data)
res.polyline = p && parse(p) || null
}
} }
} }