Re-center device on click

This commit is contained in:
Anton Tananaev 2024-05-29 06:27:27 -07:00
parent e2f50c9e72
commit 731898d1ff
2 changed files with 8 additions and 7 deletions

View File

@ -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),

View File

@ -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;
},