zhaoxing
2023-10-08 ff81554eb8a6c63cd4e7e1e319ef2343fc55e2f3
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"use script"; //开发环境建议开启严格模式
(function (window, mars3d) {
  //创建widget类,需要继承BaseWidget
  class MyWidget extends mars3d.widget.BaseWidget {
    //弹窗配置
    get view() {
      var index = this.getBasemaps().length;
 
      var width, height;
      if (index <= 4) {
        width = 190;
        height = Math.ceil(index / 2) * 100 + 70;
      } else if (index > 4 && index <= 6) {
        width = 270;
        height = Math.ceil(index / 3) * 100 + 70;
      } else {
        width = 360;
        height = Math.ceil(index / 4) * 105 + 70;
      }
 
      return {
        type: "window",
        url: "view.html",
        windowOptions: {
          width: width,
          height: height,
        },
      };
    }
    //初始化[仅执行1次]
    create() {}
    //每个窗口创建完成后调用
    winCreateOK(opt, result) {
      this.viewWindow = result;
    }
    //打开激活
    activate() {}
    //关闭释放
    disable() {
      this.viewWindow = null;
    }
    getBasemaps() {
      return this.map.getBasemaps(true);
    }
 
    updateBasemap(item) {
      this.map.basemap = item;
      this.disableBase();
    }
  }
 
  //注册到widget管理器中。
  mars3d.widget.bindClass(MyWidget);
 
  //每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。
})(window, mars3d);