radar: polylines option, return polylines

This commit is contained in:
Jannis R 2018-05-15 19:39:28 +02:00
parent 0783d9e68a
commit 9a0bfc39a4
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
3 changed files with 28 additions and 11 deletions

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?
}
```
@ -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.

View file

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

View file

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