aboutsummaryrefslogtreecommitdiff
path: root/modern
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-10-28 17:16:19 -0700
committerAnton Tananaev <anton@traccar.org>2022-10-28 17:16:19 -0700
commit080164d310c9f789b400e9909c12423bf31ef79c (patch)
tree8ee0f0fdf2d20055de137559fc9f2f42e9fb5656 /modern
parent6a4eba7b63c84c20188b8a6b16f6107698bfde91 (diff)
downloadtrackermap-web-080164d310c9f789b400e9909c12423bf31ef79c.tar.gz
trackermap-web-080164d310c9f789b400e9909c12423bf31ef79c.tar.bz2
trackermap-web-080164d310c9f789b400e9909c12423bf31ef79c.zip
Store live route history
Diffstat (limited to 'modern')
-rw-r--r--modern/src/store/session.js14
1 files changed, 13 insertions, 1 deletions
diff --git a/modern/src/store/session.js b/modern/src/store/session.js
index 74dc29a0..121b47f5 100644
--- a/modern/src/store/session.js
+++ b/modern/src/store/session.js
@@ -7,6 +7,7 @@ const { reducer, actions } = createSlice({
user: null,
socket: null,
positions: {},
+ history: {},
},
reducers: {
updateServer(state, action) {
@@ -19,7 +20,18 @@ const { reducer, actions } = createSlice({
state.socket = action.payload;
},
updatePositions(state, action) {
- action.payload.forEach((position) => state.positions[position.deviceId] = position);
+ const liveRoutes = state.user.attributes.mapLiveRoutes || state.server.attributes.mapLiveRoutes || 'none';
+ const liveRoutesLimit = state.user.attributes['web.liveRouteLength'] || state.user.attributes['web.liveRouteLength'] || 10;
+ action.payload.forEach((position) => {
+ state.positions[position.deviceId] = position;
+ if (liveRoutes !== 'none') {
+ const route = state.history[position.deviceId] || [];
+ const last = route.at(-1);
+ if (!last || (last[0] !== position.longitude && last[1] !== position.latitude)) {
+ state.history[position.deviceId] = [...route.slice(1 - liveRoutesLimit), [position.longitude, position.latitude]];
+ }
+ }
+ });
},
},
});