From dd154afa9d331738f5cdf1200f7eed980f49dd28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Fri, 17 Jul 2020 12:17:56 +0200 Subject: [PATCH] Update front for new back network format --- front/index.js | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/front/index.js b/front/index.js index 414eea1..4334e1b 100644 --- a/front/index.js +++ b/front/index.js @@ -42,31 +42,25 @@ fetch(SERVER + '/network').then(res => res.json()).then(network => { const stopPoints = Object.entries(network.stops) .map(([stopId, stop]) => - { - const feature = new Feature({ + new Feature({ type: 'stop', color: network.lines[stop.lines[0]].color, geometry: new Point(proj.fromLonLat([stop.lon, stop.lat])), - }); + }) + ); - feature.setId(stopId); - return feature; - }); - - const segmentLines = Object.entries(network.segments) - .map(([segmentId, segment]) => - { - const feature = new Feature({ - type: 'segment', - color: network.lines[segment.lines[0]].color, - geometry: new LineString(segment.nodes.map( - ({lat, lon}) => proj.fromLonLat([lon, lat]) - )), - }); - - feature.setId(segmentId); - return feature; - }); + const segmentLines = Object.values(network.lines) + .flatMap(({color, routes}) => + routes.map(({segments}) => + new Feature({ + type: 'segment', + color, + geometry: new LineString(segments.flat().map( + ({lat, lon}) => proj.fromLonLat([lon, lat]) + )), + }) + ) + ); dataSource.addFeatures( stopPoints.concat(segmentLines)