mirror of
https://github.com/traccar/traccar-web.git
synced 2025-01-09 04:37:33 +08:00
Update the itemsCoordinates state every time the length of itemsRoutes changes.
This commit is contained in:
parent
759605342a
commit
9855a3473b
@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
import {
|
import {
|
||||||
Table, TableBody, TableCell, TableHead, TableRow,
|
Table, TableBody, TableCell, TableHead, TableRow,
|
||||||
@ -26,6 +26,13 @@ const CombinedReportPage = () => {
|
|||||||
|
|
||||||
const [items, setItems] = useState([]);
|
const [items, setItems] = useState([]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [itemsCoordinates, setItemsCoordinates] = useState([]);
|
||||||
|
|
||||||
|
const itemsRoutes = items.flatMap((item) => item.route);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setItemsCoordinates(itemsRoutes);
|
||||||
|
}, [itemsRoutes.length]);
|
||||||
|
|
||||||
const createMarkers = () => items.flatMap((item) => item.events
|
const createMarkers = () => items.flatMap((item) => item.events
|
||||||
.map((event) => item.positions.find((p) => event.positionId === p.id))
|
.map((event) => item.positions.find((p) => event.positionId === p.id))
|
||||||
@ -68,7 +75,7 @@ const CombinedReportPage = () => {
|
|||||||
))}
|
))}
|
||||||
<MapMarkers markers={createMarkers()} />
|
<MapMarkers markers={createMarkers()} />
|
||||||
</MapView>
|
</MapView>
|
||||||
<MapCamera coordinates={items.flatMap((item) => item.route)} />
|
<MapCamera coordinates={itemsCoordinates} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className={classes.containerMain}>
|
<div className={classes.containerMain}>
|
||||||
|
Loading…
Reference in New Issue
Block a user