cshenfu
2022-10-24 7ad83b62babe01fa8356d2ed6d5eeefc5bd172cb
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
"use script"; //开发环境建议开启严格模式
(function (window, mars3d) {
  //创建widget类,需要继承BaseWidget
  class MyWidget extends mars3d.widget.BaseWidget {
    //弹窗配置
    get view() {
      return {
        type: "window",
        url: "view.html",
        style: "dark",
        windowOptions: {
          skin: "layer-mars-dialog animation-scale-up",
          width: 250,
          position: {
            top: 10,
            right: 5,
            bottom: 30,
          },
        },
      };
    }
 
    //初始化[仅执行1次]
    create() {
      let that = this;
      $.getJSON(this.path + "config/attr.json", function (data) {
        that.attrConfig = data;
        that.setDefaultVal();
 
        that.attrConfig["curve"] = that.attrConfig["polyline"];
        that.startEditing();
      });
    }
    //获取所有可配置属性的默认值
    setDefaultVal() {
      let data = this.attrConfig;
 
      //标号默认样式
      let attrDefConfig = {};
      for (let i in data) {
        let defstyle = {};
        for (let idx = 0; idx < data[i].style.length; idx++) {
          let item = data[i].style[idx];
          defstyle[item.name] = item.defval;
        }
        attrDefConfig[i] = defstyle;
      }
      this.attrDefConfig = attrDefConfig;
 
      // let logInfo = JSON.stringify(attrDefConfig)
      // logInfo = logInfo.replaceAll('"diffHeight":0,', '').replaceAll('"hasShadows":false,', '')
      // console.log('标号默认样式', logInfo)
    }
 
    //每个窗口创建完成后调用
    winCreateOK(opt, result) {
      this.viewWindow = result;
    }
    //激活插件
    activate() {}
    //释放插件
    disable() {}
    getDefStyle(type) {
      let defStyle = this.attrDefConfig[type] || {};
      return mars3d.Util.clone(defStyle);
    }
    getMinPointNum() {
      let graphic = this.config.graphic;
      if (graphic && graphic._minPointNum) {
        return graphic._minPointNum;
      }
      return 3;
    }
    getMaxPointNum() {
      let graphic = this.config.graphic;
      if (graphic && graphic._maxPointNum) {
        return graphic._maxPointNum;
      }
      return 999;
    }
    get defaultAttrList() {
      return [
        { name: "id", label: "主键", type: "label", defval: "" },
        { name: "name", label: "名称", type: "text", defval: "" },
        { name: "remark", label: "备注", type: "textarea", defval: "" },
      ];
    }
    getAttrList() {
      return this.config.attrList || this.defaultAttrList;
    }
    getLayerName() {
      let graphic = this.config.graphic;
      return graphic?._layer?.name || "";
    }
 
    startEditing(graphic, lonlats) {
      if (graphic) {
        this.config.graphic = graphic;
      }
      if (lonlats) {
        this.config.lonlats = lonlats;
      }
 
      if (this.viewWindow == null) {
        return;
      }
 
      graphic = this.config.graphic;
      lonlats = this.config.lonlats;
      this.viewWindow.plotEdit.startEditing(graphic.options, lonlats);
    }
    //更新图上的属性
    updateAttr2map(attr) {
      console.log("更新属性", attr);
 
      var graphic = this.config.graphic; //当前编辑的graphic
      graphic.setOptions(attr);
    }
    //更新坐标
    updatePoints2map(points) {
      console.log("更新坐标", points);
 
      var graphic = this.config.graphic;
      graphic.positions = points;
    }
    centerCurrentEntity() {
      let graphic = this.config.graphic;
      graphic.flyTo();
    }
    deleteEntity() {
      let graphic = this.config.graphic;
      graphic.remove();
 
      this.disableBase();
    }
 
    //文件处理
    getGeoJson() {
      let graphic = this.config.graphic;
      return graphic.toGeoJSON();
    }
  }
 
  //注册到widget管理器中。
  mars3d.widget.bindClass(MyWidget);
 
  //每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。
})(window, mars3d);