aboutsummaryrefslogtreecommitdiff
path: root/modern/src/map/SelectedDeviceMap.js
diff options
context:
space:
mode:
Diffstat (limited to 'modern/src/map/SelectedDeviceMap.js')
-rw-r--r--modern/src/map/SelectedDeviceMap.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/modern/src/map/SelectedDeviceMap.js b/modern/src/map/SelectedDeviceMap.js
new file mode 100644
index 00000000..655fca98
--- /dev/null
+++ b/modern/src/map/SelectedDeviceMap.js
@@ -0,0 +1,24 @@
+import { useEffect } from 'react';
+import { useSelector } from 'react-redux';
+
+import { map } from './Map';
+
+const SelectedDeviceMap = () => {
+ const mapCenter = useSelector(state => {
+ if (state.devices.selectedId) {
+ const position = state.positions.items[state.devices.selectedId] || null;
+ if (position) {
+ return [position.longitude, position.latitude];
+ }
+ }
+ return null;
+ });
+
+ useEffect(() => {
+ map.easeTo({ center: mapCenter });
+ }, [mapCenter]);
+
+ return null;
+}
+
+export default SelectedDeviceMap;