db-vendo-client/parse/polyline.js

32 lines
627 B
JavaScript
Raw Normal View History

2024-12-07 22:46:04 +00:00
import maxBy from 'lodash/maxBy.js';
2024-12-07 16:16:31 +00:00
const parsePolyline = (ctx, p) => { // p = raw polylineGroup
2024-12-07 22:46:04 +00:00
if (p.polylineDescriptions.length < 1) {
2024-12-07 16:16:31 +00:00
return null;
}
2024-12-07 22:46:04 +00:00
const points = maxBy(p.polylineDescriptions, d => d.coordinates.length).coordinates; // TODO initial and final poly?
if (points.length === 0) {
return null;
}
2018-05-16 21:07:05 +02:00
2024-12-07 16:16:31 +00:00
const res = points.map(ll => ({
type: 'Feature',
properties: {},
geometry: {
type: 'Point',
2024-12-07 16:16:31 +00:00
coordinates: [ll.lng, ll.lat],
},
}));
2018-05-16 21:07:05 +02:00
2024-12-07 16:16:31 +00:00
// TODO initial and final descriptions?, match station info?
return {
type: 'FeatureCollection',
features: res,
};
};
2018-05-16 21:07:05 +02:00
2022-05-07 16:17:37 +02:00
export {
parsePolyline,
};