diff options
author | Anton Tananaev <anton@traccar.org> | 2024-05-29 06:27:27 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2024-05-29 06:27:27 -0700 |
commit | 731898d1ffd785ce524833204d1aeac476b35104 (patch) | |
tree | 2b3beaa42bcaacf9e12e0cca4c5f7aa348be4195 | |
parent | e2f50c9e72ce5c7854290ccdaae7ce717b5b9df0 (diff) | |
download | trackermap-web-731898d1ffd785ce524833204d1aeac476b35104.tar.gz trackermap-web-731898d1ffd785ce524833204d1aeac476b35104.tar.bz2 trackermap-web-731898d1ffd785ce524833204d1aeac476b35104.zip |
Re-center device on click
-rw-r--r-- | src/map/main/MapSelectedDevice.js | 10 | ||||
-rw-r--r-- | src/store/devices.js | 5 |
2 files changed, 8 insertions, 7 deletions
diff --git a/src/map/main/MapSelectedDevice.js b/src/map/main/MapSelectedDevice.js index caf40cf8..d17fb997 100644 --- a/src/map/main/MapSelectedDevice.js +++ b/src/map/main/MapSelectedDevice.js @@ -7,16 +7,18 @@ import { usePrevious } from '../../reactHelper'; import { useAttributePreference } from '../../common/util/preferences'; const MapSelectedDevice = () => { - const selectedDeviceId = useSelector((state) => state.devices.selectedId); - const previousDeviceId = usePrevious(selectedDeviceId); + const currentTime = useSelector((state) => state.devices.selectTime); + const currentId = useSelector((state) => state.devices.selectedId); + const previousTime = usePrevious(currentTime); + const previousId = usePrevious(currentId); const selectZoom = useAttributePreference('web.selectZoom', 10); const mapFollow = useAttributePreference('mapFollow', false); - const position = useSelector((state) => state.session.positions[selectedDeviceId]); + const position = useSelector((state) => state.session.positions[currentId]); useEffect(() => { - if ((selectedDeviceId !== previousDeviceId || mapFollow) && position) { + if ((currentId !== previousId || currentTime !== previousTime || mapFollow) && position) { map.easeTo({ center: [position.longitude, position.latitude], zoom: Math.max(map.getZoom(), selectZoom), diff --git a/src/store/devices.js b/src/store/devices.js index f2f6263b..130b11c8 100644 --- a/src/store/devices.js +++ b/src/store/devices.js @@ -15,14 +15,13 @@ const { reducer, actions } = createSlice({ update(state, action) { action.payload.forEach((item) => state.items[item.id] = item); }, - select(state, action) { - state.selectedId = action.payload; - }, selectId(state, action) { + state.selectTime = Date.now(); state.selectedId = action.payload; state.selectedIds = state.selectedId ? [state.selectedId] : []; }, selectIds(state, action) { + state.selectTime = Date.now(); state.selectedIds = action.payload; [state.selectedId] = state.selectedIds; }, |