(function (win) {
  var bodyStyle = document.createElement('style');
  bodyStyle.innerHTML = `body{width:1920px !important ; height:1080px !important ;}`;
  document.documentElement.firstElementChild.appendChild(bodyStyle);

  // 监听resize事件
  function resizeMap() {
    var dom = document.getElementById('mapDiv');

    if (dom) {
      var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
      var height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
      dom.style.width = width + 'px';
      dom.style.height = height + 'px';
      if (window.map) window.map.viewer.resize();
    }
  }

  function refreshScale() {
    let docWidth = document.documentElement.clientWidth;
    let docHeight = document.documentElement.clientHeight;
    var designWidth = 1920,
      designHeight = 1080,
      widthRatio = docWidth / designWidth,
      heightRatio = docHeight / designHeight; // 缩放比例
    // console.log(widthRatio,'widthRatio');
    // console.log(heightRatio,'heightRatio');
    document.body.style = `transform:scale(${widthRatio},${heightRatio});transform-origin:left top;`;

    setTimeout(function () {
      var lateWidth = document.documentElement.clientWidth,
        lateHeight = document.documentElement.clientHeight;
      if (lateWidth === docWidth) return;

      widthRatio = lateWidth / designWidth;
      heightRatio = lateHeight / designHeight;
      // console.log(widthRatio, 'widthRatioTime');
      // console.log(heightRatio, 'heightRatioTime');
      document.body.style = 'transform:scale(' + widthRatio + ',' + heightRatio + ');transform-origin:left top; ';
      // resizeMap();
    }, 0);
    var zoomLevel = window.devicePixelRatio;
    // console.log(zoomLevel, 'zoomLevel');
  }

  refreshScale();

  win.addEventListener(
    'pageshow',
    function (e) {
      if (e.persisted) {
        // 浏览器后退的时候重新计算
        refreshScale();
      }
    },
    false
  );

  // win.addEventListener('resize', refreshScale, false);
})(window);

// (function(win){
//   var bodyStyle = document.createElement('style')
//   bodyStyle.innerHTML=`body{width:1920px !important ; height:1080px !important ;}`
//   document.documentElement.firstElementChild.appendChild(bodyStyle)

//   function refreshScale(){
//     let docWidth = document.documentElement.clientWidth;
//     let docHeight = document.documentElement.clientHeight;
//     var designWidth = 1920,
//         designHeight = 1080;
//     var widthRatio = Math.min(docWidth / designWidth, 1);
//     var heightRatio = Math.min(docHeight / designHeight, 1); // 缩放比例
//     console.log(widthRatio,'widthRatio');
//     console.log(heightRatio,'heightRatio');
//     if (widthRatio=1) {
//       console.log('靠中间');
//       document.body.style = `transform:scale(${widthRatio},${heightRatio});transform-origin:center top;`;
//     }
//     else{
//       console.log('靠左');
//       document.body.style = `transform:scale(${widthRatio},${heightRatio});transform-origin:left top;`;
//     }

//     setTimeout(function(){
//       var lateWidth= document.documentElement.clientWidth,
//         lateHeight = document.documentElement.clientHeight;
//       if(lateWidth===docWidth) return;

//       widthRatio = Math.min(lateWidth / designWidth, 1);
//       heightRatio = Math.min(lateHeight / designHeight, 1);
//       console.log(widthRatio,'widthRatioTime');
//       console.log(heightRatio,'heightRatioTime');
//       if (widthRatio=1) {
//         console.log('靠中间');
//         document.body.style = `transform:scale(${widthRatio},${heightRatio});transform-origin:center top;`;
//       }else{
//         console.log('靠左');
//         document.body.style = `transform:scale(${widthRatio},${heightRatio});transform-origin:left top;`;
//       }

//     },0);
//     var zoomLevel = window.devicePixelRatio;
//     console.log(zoomLevel,'zoomLevel');
//   }

//   refreshScale()

//   win.addEventListener("pageshow", function (e) {
//     if (e.persisted) { // 浏览器后退的时候重新计算
//       refreshScale()
//     }
//   }, false);

//   win.addEventListener("resize", refreshScale, false);
// })(window)
