| | |
| | | |
| | | const MapPage = () => { |
| | | const mapRef = useRef(); |
| | | const contentRef = useRef(); |
| | | |
| | | const [app, setApp] = useState(null); |
| | | const [mapContainer, setMapContainer] = React.useState(null); |
| | |
| | | const themeMode = theme.palette.mode; |
| | | |
| | | useEffect(() => { |
| | | const initialize = async () => { |
| | | player = new Player(mapRef.current, themeMode); |
| | | setApp(player.app); |
| | | setMapContainer(player.mapContainer); |
| | | const parentElement = document.getElementById('main-content'); |
| | | if (parentElement && parentElement.classList.contains('RaLayout-content')) { |
| | | parentElement.style.paddingLeft = '0px'; |
| | | parentElement.style.paddingRight = '0px'; |
| | | } |
| | | |
| | | initialize(); |
| | | |
| | | // const initialize = async () => { |
| | | // player = new Player(mapRef.current, themeMode); |
| | | // setApp(player.app); |
| | | // setMapContainer(player.mapContainer); |
| | | |
| | | |
| | | |
| | | // } |
| | | // initialize(); |
| | | |
| | | // // resize |
| | | // const handleResize = () => { |
| | | // player.resize(); |
| | | // }; |
| | | // window.addEventListener('resize', handleResize); |
| | | // handleResize(); |
| | | |
| | | |
| | | // return () => { |
| | | // player.destroy(); |
| | | // window.removeEventListener('resize', handleResize); |
| | | // }; |
| | | return () => { |
| | | player.app.destroy(true, { children: true }); |
| | | // 销毁 Pixi.js 应用 |
| | | // ... |
| | | |
| | | // 恢复父容器的内边距 |
| | | if (parentElement && parentElement.classList.contains('RaLayout-content')) { |
| | | parentElement.style.paddingLeft = ''; |
| | | parentElement.style.paddingRight = ''; |
| | | } |
| | | }; |
| | | }, []) |
| | | }, [themeMode]) |
| | | |
| | | const handleModeChange = (event) => { |
| | | setMode(event.target.value); |
| | |
| | | return ( |
| | | <Box |
| | | sx={{ |
| | | margin: '0 -8px', |
| | | height: '100%', |
| | | display: 'flex', |
| | | flexDirection: 'column', |
| | |
| | | flexGrow: 1, // fill remaining of map space |
| | | position: 'relative', |
| | | backgroundColor: '#fff', |
| | | |
| | | }} |
| | | > |
| | | <Box |
| | | ref={contentRef} |
| | | ref={mapRef} |
| | | sx={{ |
| | | width: '100%', |
| | | height: '100%', |
| | | backgroundColor: '#e0e0e0', |
| | | }} |
| | | > |
| | | <div ref={mapRef} /> |
| | | </Box> |
| | | |
| | | <SpeedDial |