/** * 计算大小 */ 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'); // } // }); } }