diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2021-08-07 07:42:21 -1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-07 07:42:21 -1000 |
commit | db406fcc787df2fa865e5c5fe333f152e533cda1 (patch) | |
tree | f8a0ca5cf0b897106c618a8b2cb83f31f155d86d /modern/src/map/SelectedDeviceMap.js | |
parent | 59c60f8fcfabe855231e3dfecf9b363b7488024f (diff) | |
parent | 1521abf0372dd1f91d690e2931cc87d71642acb6 (diff) | |
download | trackermap-web-db406fcc787df2fa865e5c5fe333f152e533cda1.tar.gz trackermap-web-db406fcc787df2fa865e5c5fe333f152e533cda1.tar.bz2 trackermap-web-db406fcc787df2fa865e5c5fe333f152e533cda1.zip |
Merge pull request #888 from mail2bishnoi/quick_device_menu
Quick device menu
Diffstat (limited to 'modern/src/map/SelectedDeviceMap.js')
-rw-r--r-- | modern/src/map/SelectedDeviceMap.js | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/modern/src/map/SelectedDeviceMap.js b/modern/src/map/SelectedDeviceMap.js index e6c5f58f..e55ee10c 100644 --- a/modern/src/map/SelectedDeviceMap.js +++ b/modern/src/map/SelectedDeviceMap.js @@ -1,21 +1,63 @@ -import { useEffect } from 'react'; -import { useSelector } from 'react-redux'; +import React, { useEffect } from 'react'; +import ReactDOM from 'react-dom'; +import { ThemeProvider } from '@material-ui/core/styles'; +import maplibregl from 'maplibre-gl'; +import { Provider, useSelector } from 'react-redux'; +import { useHistory } from 'react-router-dom'; import { map } from './Map'; +import store from '../store'; +import StatusView from './StatusView'; +import theme from '../theme'; + +let popup; const SelectedDeviceMap = () => { + const history = useHistory(); + 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 { deviceId: state.devices.selectedId, position: [position.longitude, position.latitude] }; } } return null; }); + const showStatus = (deviceId, coordinates) => { + const placeholder = document.createElement('div'); + ReactDOM.render( + <Provider store={store}> + <ThemeProvider theme={theme}> + <StatusView + deviceId={deviceId} + onShowDetails={(positionId) => history.push(`/position/${positionId}`)} + onShowHistory={() => history.push('/replay')} + onEditClick={(deviceId) => history.push(`/device/${deviceId}`)} + /> + </ThemeProvider> + </Provider>, + placeholder, + ); + + if (popup) { + popup.remove(); + } + popup = new maplibregl.Popup({ + offset: 25, + anchor: 'top', + closeOnClick: true, + }); + + popup.setDOMContent(placeholder).setLngLat(coordinates).addTo(map); + }; + useEffect(() => { - map.easeTo({ center: mapCenter }); + if (mapCenter) { + map.easeTo({ center: mapCenter.position }); + showStatus(mapCenter.deviceId, mapCenter.position); + } }, [mapCenter]); return null; |