fuliqi
2024-04-19 fed41b2fd390ae729c05f63fcbc9f5e93cfd8f71
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
 * 计算大小
 */
import EventEmitter from './eventEmitter';
export default class Sizes extends EventEmitter {
    constructor(canvas) {
        super();
        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.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');
        //     }
        // });
    }
}