aboutsummaryrefslogtreecommitdiff
path: root/modern/src/map/main/MapSelectedDevice.js
diff options
context:
space:
mode:
Diffstat (limited to 'modern/src/map/main/MapSelectedDevice.js')
-rw-r--r--modern/src/map/main/MapSelectedDevice.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/modern/src/map/main/MapSelectedDevice.js b/modern/src/map/main/MapSelectedDevice.js
new file mode 100644
index 00000000..ba3bc784
--- /dev/null
+++ b/modern/src/map/main/MapSelectedDevice.js
@@ -0,0 +1,30 @@
+import { useEffect } from 'react';
+
+import { useSelector } from 'react-redux';
+import dimensions from '../../common/theme/dimensions';
+import { map } from '../core/Map';
+import { usePrevious } from '../../reactHelper';
+import usePersistedState from '../../common/util/usePersistedState';
+
+const MapSelectedDevice = () => {
+ const selectedDeviceId = useSelector((state) => state.devices.selectedId);
+ const previousDeviceId = usePrevious(selectedDeviceId);
+
+ const position = useSelector((state) => state.positions.items[selectedDeviceId]);
+
+ const [mapFollow] = usePersistedState('mapFollow', false);
+
+ useEffect(() => {
+ if ((selectedDeviceId !== previousDeviceId || mapFollow) && position) {
+ map.easeTo({
+ center: [position.longitude, position.latitude],
+ zoom: Math.max(map.getZoom(), 10),
+ offset: [0, -dimensions.popupMapOffset / 2],
+ });
+ }
+ });
+
+ return null;
+};
+
+export default MapSelectedDevice;