#
luxiaotao1123
2024-10-08 44846b0e5414034a1cdfed9651f9527a76b4e602
zy-acs-flow/src/map/MapPage.jsx
@@ -23,7 +23,7 @@
const MapPage = () => {
    const mapRef = useRef();
    const contentRef = React.useRef();
    const [app, setApp] = useState(null);
    const [mapContainer, setMapContainer] = React.useState(null);
@@ -39,40 +39,35 @@
            parentElement.style.paddingRight = '0px';
        }
        const initialize = async () => {
            player = new Player(mapRef.current, themeMode);
            setApp(player.app);
            setMapContainer(player.mapContainer);
        // const initialize = async () => {
        //     player = new Player(mapRef.current, themeMode);
        //     setApp(player.app);
        //     setMapContainer(player.mapContainer);
        }
        initialize();
        // resize
        const handleResize = () => {
            const width = contentRef.current.offsetWidth;
            const height = contentRef.current.offsetHeight;
            player.resize(width, height);
        };
        handleResize();
        window.addEventListener('resize', handleResize);
        // }
        // initialize();
        // // resize
        // const handleResize = () => {
        //     player.resize();
        // };
        // window.addEventListener('resize', handleResize);
        // handleResize();
        // return () => {
        //     player.destroy();
        //     window.removeEventListener('resize', handleResize);
        // };
        return () => {
            // 销毁 Pixi.js 应用
            // ...
            player.destroy();
            window.removeEventListener('resize', handleResize);
            // 恢复父容器的内边距
            if (parentElement && parentElement.classList.contains('RaLayout-content')) {
                parentElement.style.paddingLeft = '';
                parentElement.style.paddingRight = '';
            }
        };
    }, [themeMode])
    const handleModeChange = (event) => {
        setMode(event.target.value);
@@ -147,17 +142,24 @@
                    flexGrow: 1,    // fill remaining of map space 
                    position: 'relative',
                    backgroundColor: '#fff',
                }}
            >
                <Box
                    ref={mapRef}
                    ref={contentRef}
                    sx={{
                        position: 'relative',
                        width: '100%',
                        height: '100%',
                        backgroundColor: '#e0e0e0',
                    }}
                >
                    <div ref={mapRef} style={{
                        position: 'absolute',
                        top: 0,
                        left: 0,
                        width: '100%',
                        height: '100%',
                    }} />
                </Box>
                <SpeedDial