db-vendo-client/parse/polyline.js
Kristjan ESPERANTO 53b385a865
Some checks are pending
test / lint (push) Waiting to run
test / unit-tests (18.x) (push) Waiting to run
test / unit-tests (20.x) (push) Waiting to run
test / unit-tests (22.x) (push) Waiting to run
test / integration-tests (18.x) (push) Waiting to run
test / integration-tests (20.x) (push) Waiting to run
test / integration-tests (22.x) (push) Waiting to run
test / e2e-tests (18.x) (push) Blocked by required conditions
Replace lodash by modern JavaScript functions (#20)
* Replace lodash by built-in functions

* .flatMap -> .flat
2025-03-01 17:30:58 +01:00

32 lines
689 B
JavaScript

const parsePolyline = (ctx, p) => { // p = raw polylineGroup
const desc = p.polylineDescriptions || p.polylineDesc;
if (desc.length < 1) {
return null;
}
const points = desc.reduce((max, d) => (d.coordinates.length > max.coordinates.length ? d : max),
).coordinates; // TODO: initial and final poly?
if (points.length === 0) {
return null;
}
const res = points.map(ll => ({
type: 'Feature',
properties: {},
geometry: {
type: 'Point',
coordinates: [ll.lng || ll.longitude, ll.lat || ll.latitude],
},
}));
// TODO initial and final descriptions?, match station info?
return {
type: 'FeatureCollection',
features: res,
};
};
export {
parsePolyline,
};