Lin_Ye_Fang_Huo/public/widgets/addmarker/view.js

143 lines
3.6 KiB
JavaScript
Raw Normal View History

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