mirror of
https://github.com/traccar/traccar-web.git
synced 2025-01-07 03:26:42 +08:00
Re-center device on click
This commit is contained in:
parent
e2f50c9e72
commit
731898d1ff
@ -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),
|
||||
|
@ -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;
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user