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
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
"use script"; //开发环境建议开启严格模式
 
//对应widget.js中MyWidget实例化后的对象
var thisWidget;
var $table;
 
function getHeight() {
  return $(window).height() - 40;
}
 
//当前页面业务
function initWidgetView(_thisWidget) {
  thisWidget = _thisWidget;
 
  plotFile.initEvent();
 
  $("#btn_marker_Add").bind("click", function () {
    thisWidget.drawPoint();
  });
 
  //清除所有标号
  $("#btn_plot_delall").click(function () {
    thisWidget.deleteAll();
    refMarkerList();
  });
 
  //是否可以编辑
  var isedit = true;
  $("#btn_plot_isedit").click(function () {
    isedit = !isedit;
 
    if (isedit) {
      $(this).removeClass("active");
      $(this).children().removeClass("fa-lock").addClass("fa-unlock");
    } else {
      $(this).addClass("active");
      $(this).children().removeClass("fa-unlock").addClass("fa-lock");
    }
    thisWidget.hasEdit(isedit);
  });
 
  $table = $("#table");
  $table.bootstrapTable({
    height: getHeight(),
    singleSelect: true, //单选
    pagination: false,
    pageSize: 6,
    iconsPrefix: "fa",
    columns: [
      {
        field: "name",
        title: "名称",
        sortable: true,
        editable: false,
        align: "left",
      },
      {
        field: "operate",
        title: "操作",
        align: "center",
        width: 50,
        events: {
          "click .remove": function (e, value, row, index) {
            thisWidget.deleteItemById(row.id);
          },
        },
        formatter: function (value, row, index) {
          return ['<a class="remove" href="javascript:void(0)" title="删除">', '<i class="fa fa-trash"></i>', "</a>"].join("");
        },
      },
    ],
    onClickRow: function (rowData, $element, field) {
      thisWidget.flyTo(rowData.id);
    },
  });
  $(window).resize(function () {
    $table.bootstrapTable("refreshOptions", {
      height: getHeight(),
    });
  });
  refMarkerList();
}
 
function refMarkerList() {
  var arr = thisWidget.getGraphicAttrList();
  $table.bootstrapTable("load", arr);
}
 
//文件处理
var plotFile = {
  initEvent: function () {
    var that = this;
 
    var isClearForOpenFile;
    $("#btn_plot_openfile").click(function () {
      isClearForOpenFile = true;
      $("#input_plot_file").click();
    });
 
    $("#btn_plot_openfile2").click(function () {
      isClearForOpenFile = false;
      $("#input_plot_file").click();
    });
    $("#btn_plot_savefile").click(function () {
      var data = thisWidget.getJsonData();
      if (data == null || data == "") {
        toastr.error("当前未标记任何数据!");
      } else {
        haoutil.file.downloadFile("我的标记点.json", data);
      }
    });
 
    $("#input_plot_file").change(function (e) {
      var file = this.files[0];
 
      var fileName = file.name;
      var fileType = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length).toLowerCase();
      if (fileType != "json") {
        toastr.error("文件类型不合法,请选择json格式标注文件!");
        that.clearPlotFile();
        return;
      }
 
      if (window.FileReader) {
        var reader = new FileReader();
        reader.readAsText(file, "UTF-8");
        reader.onloadend = function (e) {
          var strjson = JSON.parse(this.result);
          thisWidget.loadJson(strjson, isClearForOpenFile);
          that.clearPlotFile();
        };
      }
    });
  },
  clearPlotFile: function () {
    if (!window.addEventListener) {
      document.getElementById("input_plot_file").outerHTML += ""; //IE
    } else {
      document.getElementById("input_plot_file").value = ""; //FF
    }
  },
};