diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-10-24 16:46:43 -0700 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2020-10-24 16:46:43 -0700 |
commit | 5b8419500610e9a62a264819d7ed7857ac35ac69 (patch) | |
tree | facce1f982796daa3f58419c02d669c59ee9eb9e /modern/src/map/SelectedDeviceMap.js | |
parent | e9f0913d2b1b66764931b6c1235877a44e72890b (diff) | |
download | trackermap-web-5b8419500610e9a62a264819d7ed7857ac35ac69.tar.gz trackermap-web-5b8419500610e9a62a264819d7ed7857ac35ac69.tar.bz2 trackermap-web-5b8419500610e9a62a264819d7ed7857ac35ac69.zip |
Selected device map plugin
Diffstat (limited to 'modern/src/map/SelectedDeviceMap.js')
-rw-r--r-- | modern/src/map/SelectedDeviceMap.js | 24 |
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; |