ZhangXianQiang
2024-04-18 e96c5023821c43c26993086de3a12eaf65a9d6d1
src/views/screen/components/screen-map-three/experience/utils/sizes.js
@@ -3,31 +3,33 @@
 */
import EventEmitter from './eventEmitter';
export default class Sizes extends EventEmitter {
    constructor() {
    constructor(canvas) {
        super();
        this.width = document.body.clientWidth;
        this.height = document.body.clientHeight;
        this.device = document.body.clientWidth <= 968 ? 'mobile' : 'pc';
        // 设备像素
        this.container = document.querySelector('.map-container');
        this.pixelRatio = Math.min(window.devicePixelRatio, 2);
        this.width = this.container.offsetWidth;
        this.height = this.container.offsetHeight;
        this.device = document.body.clientWidth <= 968 ? 'mobile' : 'pc';
        // this.resizeObserver = new ResizeObserver(entries => {
        //     let rect = canvas.getBoundingClientRect();
        //     this.scaleX = rect.width / this.width;
        //     this.scaleY = rect.height / this.height;
        //     console.log(this.scaleX, this.scaleY);
        // })
        // this.resizeObserver.observe(this.container);
        // 宽高变化
        window.addEventListener('resize', () => {
            // this.width = window.innerWidth;
            // this.height = window.innerHeight;
        // window.addEventListener('resize', () => {
        //     this.pixelRatio = Math.min(window.devicePixelRatio, 2);
        //     this.trigger('resize');
            this.width = document.body.clientWidth;
            this.height = document.body.clientHeight;
            this.pixelRatio = Math.min(window.devicePixelRatio, 2);
            this.trigger('resize');
            if(this.width < 968 && this.device !== 'mobile') {
                this.device = 'mobile';
                this.trigger('devicechange');
            } else if(this.width >= 968 && this.device !== 'pc') {
                this.device = 'pc';
                this.trigger('devicechange');
            }
        });
        //     if (this.width < 968 && this.device !== 'mobile') {
        //         this.device = 'mobile';
        //         this.trigger('devicechange');
        //     } else if (this.width >= 968 && this.device !== 'pc') {
        //         this.device = 'pc';
        //         this.trigger('devicechange');
        //     }
        // });
    }
}