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 | |
parent | e9f0913d2b1b66764931b6c1235877a44e72890b (diff) | |
download | trackermap-web-5b8419500610e9a62a264819d7ed7857ac35ac69.tar.gz trackermap-web-5b8419500610e9a62a264819d7ed7857ac35ac69.tar.bz2 trackermap-web-5b8419500610e9a62a264819d7ed7857ac35ac69.zip |
Selected device map plugin
-rw-r--r-- | modern/src/MainPage.js | 2 | ||||
-rw-r--r-- | modern/src/map/SelectedDeviceMap.js | 24 |
2 files changed, 26 insertions, 0 deletions
diff --git a/modern/src/MainPage.js b/modern/src/MainPage.js index 9f9f744b..ada6c01b 100644 --- a/modern/src/MainPage.js +++ b/modern/src/MainPage.js @@ -8,6 +8,7 @@ import DevicesList from './DevicesList'; import MainToolbar from './MainToolbar'; import Map from './map/Map'; import PositionsMap from './map/PositionsMap'; +import SelectedDeviceMap from './map/SelectedDeviceMap'; const useStyles = makeStyles(theme => ({ root: { @@ -55,6 +56,7 @@ const MainPage = ({ width }) => { <div className={classes.mapContainer}> <ContainerDimensions> <Map> + <SelectedDeviceMap /> <PositionsMap /> </Map> </ContainerDimensions> 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; |