Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
wip - front
Browse files Browse the repository at this point in the history
  • Loading branch information
Seb-sti1 committed Nov 6, 2023
1 parent 95b0c54 commit 5c8c401
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 22 deletions.
23 changes: 2 additions & 21 deletions frontend/src/Components/Map/Road.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,11 @@ const Road: React.FC<Props> = ({ road, onClick }) => {
useEffect(() => {
if (road === undefined) return;
const lines: ReactElement[] = [];
const data: LatLngLiteral[][] = [];

let idx = 0;
// For each segment of the road create a array of the GPS points and a Polyline to show
road.way_ids.forEach((way_ids: string[]) => {
data[idx] = [];
way_ids.forEach((way_id, way_idx) => {
if (way_idx === 0) {
// add all the points for the first
data[idx].push(...road.geometries[way_id]);
} else if (way_idx === way_ids.length - 1) {
// add all the points except the first for the last ways
data[idx].push(...road.geometries[way_id].slice(1));
} else {
// add all the points except the first and last point for the middle ways
data[idx].push(...road.geometries[way_id].slice(1, -1));
}
});
idx++;
});
const data: LatLngLiteral[][] = Object.values(road.geometries);

lines.push(
<Polyline
key={road.way_ids.join('-')} // use by React JS to identify the element
key={road.branches.join('-')} // use by React JS to identify the element
pathOptions={{ weight: 5, opacity: opacity }}
positions={data}
eventHandlers={{
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/models/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export interface IRoad {
// /---<---\
// ----------- -----------
// \--->---/
way_ids: WayId[][];
branches: WayId[][];
// the geometry of each way
geometries: Record<WayId, LatLng[]>;
}
Expand Down

0 comments on commit 5c8c401

Please sign in to comment.