| | |
| | | SpeedDial, |
| | | SpeedDialAction, |
| | | useTheme, |
| | | Snackbar, |
| | | } from '@mui/material'; |
| | | import { |
| | | MoreVert as MoreVertIcon, |
| | |
| | | Share as ShareIcon, |
| | | } from '@mui/icons-material'; |
| | | import Player from './player'; |
| | | import * as Tool from './tool'; |
| | | import { NotificationProvider, useNotification } from './Notification'; |
| | | |
| | | let player; |
| | | |
| | | const MapPage = () => { |
| | | const Map = () => { |
| | | const mapRef = useRef(); |
| | | const contentRef = React.useRef(); |
| | | const contentRef = useRef(); |
| | | const [app, setApp] = useState(null); |
| | | const [mapContainer, setMapContainer] = React.useState(null); |
| | | const [mapContainer, setMapContainer] = useState(null); |
| | | const notify = useNotification(); |
| | | |
| | | const [mode, setMode] = useState('monitoring'); |
| | | |
| | | const [windowSize, setWindowSize] = React.useState({ |
| | | width: window.innerWidth, |
| | | height: window.innerHeight, |
| | | }); |
| | | const [mode, setMode] = useState(MapMode.OBSERVER_MODE); |
| | | |
| | | const theme = useTheme(); |
| | | const themeMode = theme.palette.mode; |
| | | |
| | | useEffect(() => { |
| | | const parentElement = document.getElementById('main-content'); |
| | | if (parentElement && parentElement.classList.contains('RaLayout-content')) { |
| | | parentElement.style.paddingLeft = '0px'; |
| | | parentElement.style.paddingRight = '0px'; |
| | | } |
| | | |
| | | Tool.patchRaLayout('0px'); |
| | | const initialize = async () => { |
| | | player = new Player(mapRef.current, themeMode); |
| | | setApp(player.app); |
| | | setMapContainer(player.mapContainer); |
| | | Tool.setApp(player.app); |
| | | Tool.setMapContainer(player.mapContainer); |
| | | |
| | | } |
| | | initialize(); |
| | | |
| | | // windows resize |
| | | // resize |
| | | const handleResize = () => { |
| | | setWindowSize({ |
| | | width: window.innerWidth, |
| | | height: window.innerHeight, |
| | | }); |
| | | player.resize(); |
| | | const width = contentRef.current.offsetWidth; |
| | | const height = contentRef.current.offsetHeight; |
| | | |
| | | player.resize(width, height); |
| | | }; |
| | | handleResize(); |
| | | window.addEventListener('resize', handleResize); |
| | | |
| | | notify('Welcome to Rcs', 'info'); |
| | | |
| | | return () => { |
| | | player.destroy(); |
| | | window.removeEventListener('resize', handleResize); |
| | | |
| | | if (parentElement && parentElement.classList.contains('RaLayout-content')) { |
| | | parentElement.style.paddingLeft = ''; |
| | | parentElement.style.paddingRight = ''; |
| | | } |
| | | Tool.patchRaLayout(''); |
| | | }; |
| | | }, [themeMode]) |
| | | |
| | | const handleModeChange = (event) => { |
| | | setMode(event.target.value); |
| | | }; |
| | | const switchMode = (mode) => { |
| | | switch (mode) { |
| | | case MapMode.OBSERVER_MODE: |
| | | console.log('a'); |
| | | break |
| | | case MapMode.MOVABLE_MODE: |
| | | console.log('b'); |
| | | break |
| | | case MapMode.SETTINGS_MODE: |
| | | console.log('c'); |
| | | break |
| | | default: |
| | | break |
| | | } |
| | | } |
| | | |
| | | useEffect(() => { |
| | | if (!mapContainer) { |
| | | return |
| | | } |
| | | switchMode(mode); |
| | | }, [mode]); |
| | | |
| | | const actions = [ |
| | | { icon: <FileCopyIcon />, name: '复制' }, |
| | |
| | | <Box sx={{ flexGrow: 1 }} /> |
| | | <Select |
| | | value={mode} |
| | | onChange={handleModeChange} |
| | | onChange={(event) => { |
| | | setMode(event.target.value); |
| | | }} |
| | | variant="outlined" |
| | | size="small" |
| | | sx={{ |
| | |
| | | borderRadius: 1, |
| | | }} |
| | | > |
| | | <MenuItem value="monitoring">监控模式</MenuItem> |
| | | <MenuItem value="edit">编辑模式</MenuItem> |
| | | <MenuItem value="configuration">配置模式</MenuItem> |
| | | <MenuItem value={MapMode.OBSERVER_MODE}>监控模式</MenuItem> |
| | | <MenuItem value={MapMode.MOVABLE_MODE}>编辑模式</MenuItem> |
| | | <MenuItem value={MapMode.SETTINGS_MODE}>配置模式</MenuItem> |
| | | </Select> |
| | | <Button |
| | | variant="contained" |
| | |
| | | <Box |
| | | ref={contentRef} |
| | | sx={{ |
| | | position: 'relative', |
| | | width: '100%', |
| | | height: '100%', |
| | | backgroundColor: '#e0e0e0', |
| | | overflowY: 'hidden', |
| | | }} |
| | | > |
| | | <div ref={mapRef} style={{ |
| | | position: 'absolute', |
| | | top: 0, |
| | | left: 0, |
| | | width: '100%', |
| | | height: '100%', |
| | | }} /> |
| | |
| | | ); |
| | | } |
| | | |
| | | const MapPage = () => { |
| | | return ( |
| | | <NotificationProvider> |
| | | <Map /> |
| | | </NotificationProvider> |
| | | ) |
| | | } |
| | | |
| | | export const MapMode = Object.freeze({ |
| | | OBSERVER_MODE: "1", |
| | | MOVABLE_MODE: "2", |
| | | SETTINGS_MODE: "3", |
| | | }) |
| | | |
| | | export default MapPage; |