| | |
| | | const MapPage = () => { |
| | | const mapRef = useRef(); |
| | | const contentRef = useRef(); |
| | | |
| | | const [app, setApp] = useState(null); |
| | | const [mapContainer, setMapContainer] = React.useState(null); |
| | | |
| | | const [windowSize, setWindowSize] = useState({ |
| | | width: window.innerWidth, |
| | | height: window.innerHeight, |
| | | }); |
| | | |
| | | const [mode, setMode] = useState('monitoring'); |
| | | |
| | | useEffect(() => { |
| | |
| | | }); |
| | | }; |
| | | window.addEventListener('resize', handleResize); |
| | | |
| | | } |
| | | |
| | | initialize(); |
| | | return () => { |
| | | player.app.destroy(true, { children: true }); |
| | | window.removeEventListener('resize', () => { }); |
| | | }; |
| | | }, []) |
| | | |
| | | // resize |
| | | React.useEffect(() => { |
| | | if (!app) { |
| | | return; |
| | | useEffect(() => { |
| | | if (app && contentRef.current) { |
| | | const width = contentRef.current.offsetWidth; |
| | | const height = contentRef.current.offsetHeight; |
| | | app.renderer.resize(width, height); // 动态调整 PIXI 大小 |
| | | } |
| | | console.log(1); |
| | | |
| | | const width = contentRef.current.offsetWidth; |
| | | const height = contentRef.current.offsetHeight; |
| | | app.renderer.resize(width, height); |
| | | }, [app, mapContainer, windowSize]) |
| | | }, [app, mapContainer]); |
| | | |
| | | const handleModeChange = (event) => { |
| | | setMode(event.target.value); |