var thisWidget; //当前页面业务 function initWidgetView(_thisWidget) { thisWidget = _thisWidget; if (thisWidget.config && thisWidget.config.style) {//适应不同样式 $("body").addClass(thisWidget.config.style); } //清除所有标号 $("#btn_plot_delall").click(function () { thisWidget.deleteAll(); tab2plot() }); $("#btn_plot_end").click(function (e) { thisWidget.endDraw(); }); $("#btn_plot_socket").click(function (e) { thisWidget.socketConfig(); }); //是否可以编辑 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); }); plotFile.initEvent(); plotlist.bindSelList(); tableWork.initEvent(); } //文件处理 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.getGeoJson(); if (data == null || data == "") { toastr.warning("当前未标绘任何数据!"); } else { haoutil.file.downloadFile("标绘.json", JSON.stringify(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 = this.result; thisWidget.jsonToLayer(strjson, isClearForOpenFile, true); that.clearPlotFile(); }; } }); }, clearPlotFile: function () { if (!window.addEventListener) { document.getElementById('input_plot_file').outerHTML += ''; //IE } else { document.getElementById('input_plot_file').value = ""; //FF } } }; //标号列表相关 var plotlist = { //绑定标号列表切换下拉框 bindSelList: function () { var that = this; var $sel_plot_list = $("#sel_plot_list"); $.getJSON("config/plotlist.json", function (plotlist) { var inhtml = ''; var defval; var count = 0; for (var i in plotlist) { inhtml += ''; if (defval == null) defval = i; count++; } if (defval) { that.showPlotList(plotlist[defval]); $sel_plot_list.attr('data-value', defval); } if (count > 1) { $sel_plot_list.html(inhtml); $sel_plot_list.select(); $sel_plot_list.change(function () { var val = $(this).attr('data-value'); var list = plotlist[val]; that.showPlotList(list); }); } else { $sel_plot_list.hide(); $(".mp_mark").css({ 'margin-top': '10px' }); } }); }, _listData: null, showPlotList: function (list) { this._listData = list; var serverURL = thisWidget.getServerURL(); var serverURL_gltf = thisWidget.getGltfServerURL(); var inhtml = ''; for (var i = 0; i < list.length; i++) { var item = list[i]; if (item.hide) continue; //处理模型url if (item.style && item.style.modelUrl) { if (item.style.modelUrl.startsWith("$plot$")) { item.style.modelUrl = item.style.modelUrl.replace("$plot$/", thisWidget.path); //是模块内部本级图片 } else if (item.style.modelUrl.startsWith("$serverURL_gltf$")) { item.style.modelUrl = item.style.modelUrl.replace("$serverURL_gltf$", serverURL_gltf); } else if (item.style.modelUrl.startsWith("$serverURL$")) { item.style.modelUrl = item.style.modelUrl.replace("$serverURL$", serverURL); } } var defStyle = thisWidget.getDefStyle(item.edittype || item.type) //使用图片图标 var image; if (defStyle) { image = defStyle.image; } if (item.image) { image = item.image; } if (item.style && item.style.image) { image = item.style.image; } if (image) { if (image.startsWith("http")) { //不用特殊处理 } else if (image.startsWith("$plot$")) { image = image.replace("$plot$/", ""); //是模块内部本级图片 } else if (image.startsWith("$serverURL_gltf$")) { image = image.replace("$serverURL_gltf$", serverURL_gltf); } else if (image.startsWith("$serverURL$")) { image = image.replace("$serverURL$", serverURL); //是模块内部本级图片 } else { image = "../../" + image; //相对于父级index页面的图片 } inhtml += '