db-vendo-client/parse/polyline.js

33 lines
678 B
JavaScript
Raw Permalink 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
2025-01-03 10:57:24 +00:00
const desc = p.polylineDescriptions || p.polylineDesc;
if (desc.length < 1) {
2024-12-07 16:16:31 +00:00
return null;
}
2025-01-03 10:57:24 +00:00
const points = maxBy(desc, 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',
2025-01-03 10:57:24 +00:00
coordinates: [ll.lng || ll.longitude, ll.lat || ll.latitude],
},
}));
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,
};