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