wangzhibo
2021-09-06 2efb5d2a02ce47a9fd6f1cec138496aba72f0815
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"use script"; //开发环境建议开启严格模式
(function (window, mars3d) {
  //创建widget类,需要继承BaseWidget
  class MyWidget extends mars3d.widget.BaseWidget {
    //弹窗配置
    get view() {
      return {
        type: "window",
        url: "view.html",
        windowOptions: {
          width: 310,
          height: 530,
        },
      };
    }
 
    //初始化[仅执行1次]
    create() {
      this.measure = new mars3d.thing.Measure({
        name: this.config.name,
        pid: 99, //图层管理 中使用,父节点id
        //可设置文本样式
        label: {
          color: "#ffffff",
          font_family: "楷体",
          font_size: 20,
          background: false,
        },
      });
      this.measure.on(mars3d.EventType.start, (e) => {
        //开始分析前回调(异步)
        haoutil.loading.show();
      });
      this.measure.on(mars3d.EventType.end, (e) => {
        //分析完成后回调(异步)
        haoutil.loading.hide();
        if (e.graphic?.type === mars3d.graphic.SectionMeasure.type) {
          this.showSectionChars(e);
        }
        this.viewWindow.onMeasureEnd(e);
      });
      this.measure.on(mars3d.EventType.change, (e) => {
        this.viewWindow.onMeasureChange(e);
      });
      this.measure.on(mars3d.EventType.click, (e) => {
        let result = e.graphic?.measured;
        if (e.graphic?.type === mars3d.graphic.SectionMeasure.type && result) {
          this.showSectionChars(result);
        }
      });
    }
    //每个窗口创建完成后调用
    winCreateOK(opt, result) {
      this.viewWindow = result;
    }
    //激活插件
    activate() {
      this.map.addThing(this.measure);
    }
    //释放插件
    disable() {
      this.viewWindow = null;
      this.clearDraw();
      this.map.removeThing(this.measure);
    }
    clearDraw() {
      this.measure.clear();
      mars3d.widget.disable("widgets/measureChars/widget.js");
    }
    showSectionChars(data) {
      if (data == null || data.arrPoint == null) {
        return;
      }
 
      mars3d.widget.activate({
        uri: "widgets/measureChars/widget.js",
        data: data,
      });
    }
    changeOnlyPickModel(value) {
      //控制鼠标只取模型上的点,忽略地形上的点的拾取
      this.map.onlyPickModelPosition = value;
    }
  }
 
  //注册到widget管理器中。
  mars3d.widget.bindClass(MyWidget);
 
  //每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。
})(window, mars3d);