Lin_Ye_Fang_Huo/public/widgets/roamLine/js/vew.work.js

822 lines
25 KiB
JavaScript
Raw Normal View History

2023-07-08 15:37:34 +08:00
/* 2017-12-7 12:41:21 | 修改 木遥(微信: http://marsgis.cn/weixin.html */
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;
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
$("#btn_plot_delall").click(function () {
thisWidget.deleteAll();
});
$("#btnDelete").click(function (e) {
thisWidget.deleteCurrentGraphic();
window.tab2plot(); //切换面板
});
$("#btn_plot_savefile").click(function () {
var data = thisWidget.arrFlyTable;
2023-07-08 15:37:34 +08:00
if (data == null || data.length == 0) {
2023-07-18 09:04:15 +08:00
toastr.warning("当前没有漫游路线数据!");
2023-07-08 15:37:34 +08:00
} else {
2023-07-18 09:04:15 +08:00
haoutil.file.downloadFile("漫游路线数据.json", JSON.stringify(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
$("#btn_plot_importfile").click(function () {
$("#input_plot_file").click();
});
2023-07-08 15:37:34 +08:00
function clearPlotFile() {
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
$("#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格式标注文件");
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 json = this.result;
clearPlotFile();
2023-07-08 15:37:34 +08:00
if (!json) {
2023-07-18 09:04:15 +08:00
haoutil.msg("数据为空,只能导入从“导出”按钮保存的数据。");
return;
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
var arrFlyTable = JSON.parse(json);
if (Array.isArray(arrFlyTable)) {
thisWidget.showData(arrFlyTable);
tableWork.loadData(arrFlyTable);
} else {
haoutil.msg("数据格式有误,只能导入从“导出”按钮保存的数据。");
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
});
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
$("#btnSaveGeoJson").click(function () {
var id = plotEdit._last_attr.id;
thisWidget.stopDraw();
2023-07-08 15:37:34 +08:00
for (var i = 0, len = thisWidget.arrFlyTable.length; i < len; i++) {
2023-07-18 09:04:15 +08:00
var item = thisWidget.arrFlyTable[i];
2023-07-08 15:37:34 +08:00
if (item.id == id) {
2023-07-18 09:04:15 +08:00
thisWidget.saveForGeoJson(item);
break;
2023-07-08 15:37:34 +08:00
}
}
2023-07-18 09:04:15 +08:00
});
$("#btnSaveCzml").click(function () {
var id = plotEdit._last_attr.id;
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
thisWidget.stopDraw();
2023-07-08 15:37:34 +08:00
for (var i = 0, len = thisWidget.arrFlyTable.length; i < len; i++) {
2023-07-18 09:04:15 +08:00
var item = thisWidget.arrFlyTable[i];
2023-07-08 15:37:34 +08:00
if (item.id == id) {
2023-07-18 09:04:15 +08:00
thisWidget.saveForCzml(item);
break;
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
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
plotEdit.initEvent();
plotEdit.loadConfig();
tableWork.initEvent();
2023-07-08 15:37:34 +08:00
}
//标号列表相关
var plotlist = {
//开始绘制
startPlot: function () {
2023-07-18 09:04:15 +08:00
var defval = haoutil.system.clone(plotEdit.defval["polyline"] || {});
defval.type = "polyline";
defval.name = "飞行漫游路线";
thisWidget.startDraw(defval);
2023-07-08 15:37:34 +08:00
},
//绘制结束
plotEnd: function () {
//取消选中状态
if (this._lastLi) {
2023-07-18 09:04:15 +08:00
this._lastLi.removeClass("markon");
2023-07-08 15:37:34 +08:00
}
},
2023-07-18 09:04:15 +08:00
};
2023-07-08 15:37:34 +08:00
//列表处理
var tableWork = {
$table: null,
getHeight: function () {
2023-07-18 09:04:15 +08:00
return $(window).height() - 80;
2023-07-08 15:37:34 +08:00
},
initEvent: function () {
2023-07-18 09:04:15 +08:00
var that = this;
$("#btn_Add_line").click(function () {
plotlist.startPlot();
});
$("#btnFlyStart").click(function (e) {
var id = plotEdit._last_attr.id;
thisWidget.graphicLayer.stopDraw();
2023-07-08 15:37:34 +08:00
for (var i = 0, len = thisWidget.arrFlyTable.length; i < len; i++) {
2023-07-18 09:04:15 +08:00
var item = thisWidget.arrFlyTable[i];
2023-07-08 15:37:34 +08:00
if (item.id == id) {
2023-07-18 09:04:15 +08:00
thisWidget.toRoamFly(item);
break;
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
var $table = $("#table");
2023-07-08 15:37:34 +08:00
$table.bootstrapTable({
height: this.getHeight(),
singleSelect: true, //单选
pagination: false,
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
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
formatter: function (value, row, index) {
2023-07-18 09:04:15 +08:00
return row?.attr?.name || "";
2023-07-08 15:37:34 +08:00
},
},
{
2023-07-18 09:04:15 +08:00
title: "操作",
align: "center",
2023-07-08 15:37:34 +08:00
width: 80,
events: {
2023-07-18 09:04:15 +08:00
"click .remove": function (e, value, row, index) {
thisWidget.deleteGraphic(row.id);
2023-07-08 15:37:34 +08:00
},
2023-07-18 09:04:15 +08:00
"click .fly": function (e, value, row, index) {
thisWidget.toRoamFly(row);
2023-07-08 15:37:34 +08:00
},
2023-07-18 09:04:15 +08:00
"click .edit": function (e, value, row, index) {
that.showTableItem(row);
2023-07-08 15:37:34 +08:00
},
},
formatter: function (value, row, index) {
return [
'<a class="fly" href="javascript:void(0)" title="飞行"><i class="fa fa-send-o"></i></a>&nbsp;&nbsp;',
'<a class="edit" href="javascript:void(0)" title="编辑"><i class="fa fa-edit"></i></a>&nbsp;&nbsp;',
'<a class="remove" href="javascript:void(0)" title="删除"><i class="fa fa-trash"></i></a>',
2023-07-18 09:04:15 +08:00
].join("");
2023-07-08 15:37:34 +08:00
},
},
],
onDblClickRow: function (rowData, $element, field) {
2023-07-18 09:04:15 +08:00
that.showTableItem(rowData);
2023-07-08 15:37:34 +08:00
},
2023-07-18 09:04:15 +08:00
});
this.$table = $table;
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
this.loadData(thisWidget.arrFlyTable);
2023-07-08 15:37:34 +08:00
},
loadData: function (arr) {
if (this.$table) {
2023-07-18 09:04:15 +08:00
this.$table.bootstrapTable("load", arr);
2023-07-08 15:37:34 +08:00
}
},
showTableItem: function (data) {
2023-07-18 09:04:15 +08:00
thisWidget.startEditingById(data.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
//属性编辑相关
var plotEdit = {
hasEditSylte: false,
config: {},
defval: {},
initEvent: function () {
2023-07-18 09:04:15 +08:00
var that = this;
2023-07-08 15:37:34 +08:00
if (!this.hasEditSylte) {
2023-07-18 09:04:15 +08:00
$("#attr_style_view").hide();
2023-07-08 15:37:34 +08:00
}
//改变高度 - 高程全部设置为
2023-07-18 09:04:15 +08:00
$("#plot_latlngs_allheight").bind("input propertychange", function () {
$("#plot_latlngs_addheight").val("");
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
var thisval = Number($(this).val()); //高度(米)
2023-07-08 15:37:34 +08:00
if (isNaN(thisval)) {
2023-07-18 09:04:15 +08:00
thisval = 1;
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
var latlngs = [];
$(".plot_latlngs").each(function () {
if ($(this).attr("data-type") == "height") {
$(this).val(thisval);
latlngs.push(thisval);
2023-07-08 15:37:34 +08:00
} else {
2023-07-18 09:04:15 +08:00
latlngs.push(Number($(this).val())); //经纬度值
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
thisWidget.updateGeo2map(latlngs, true);
});
2023-07-08 15:37:34 +08:00
//改变高度 - 在地表高程偏移
2023-07-18 09:04:15 +08:00
$("#plot_latlngs_addheight").bind("input propertychange", function () {
$("#plot_latlngs_allheight").val("");
var thisval = Number($(this).val()); //高度(米)
2023-07-08 15:37:34 +08:00
if (isNaN(thisval)) {
2023-07-18 09:04:15 +08:00
thisval = 1;
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
var latlngs = [];
$(".plot_latlngs").each(function () {
if ($(this).attr("data-type") == "height") {
var oldval = Number($(this).attr("oldvalue"));
$(this).val(oldval + thisval);
latlngs.push(oldval + thisval);
2023-07-08 15:37:34 +08:00
} else {
2023-07-18 09:04:15 +08:00
latlngs.push(Number($(this).val())); //经纬度值
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
thisWidget.updateGeo2map(latlngs, true);
});
2023-07-08 15:37:34 +08:00
//航速
2023-07-18 09:04:15 +08:00
$("#txtFlySpeedAll").bind("input propertychange", function () {
var thispeed = Number($(this).val());
2023-07-08 15:37:34 +08:00
if (thispeed > 0) {
2023-07-18 09:04:15 +08:00
var speeds = [];
$(".plot_speeds").each(function () {
$(this).val(thispeed);
speeds.push(thispeed);
});
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
that._last_attr.attr.speed = speeds;
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
});
2023-07-08 15:37:34 +08:00
},
loadConfig: function () {
2023-07-18 09:04:15 +08:00
var that = this;
$.getJSON("config/attr.json", function (data) {
that.config = data;
2023-07-08 15:37:34 +08:00
for (var i in data) {
2023-07-18 09:04:15 +08:00
var defstyle = {};
2023-07-08 15:37:34 +08:00
for (let idx = 0; idx < data[i].style.length; idx++) {
2023-07-18 09:04:15 +08:00
let item = data[i].style[idx];
defstyle[item.name] = item.defval;
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
var defattr = {};
2023-07-08 15:37:34 +08:00
for (let idx = 0; idx < data[i].attr.length; idx++) {
2023-07-18 09:04:15 +08:00
let item = data[i].attr[idx];
defattr[item.name] = item.defval;
2023-07-08 15:37:34 +08:00
}
that.defval[i] = {
2023-07-18 09:04:15 +08:00
type: "polyline",
2023-07-08 15:37:34 +08:00
name: data[i].name,
position: data[i].position,
style: defstyle,
attr: defattr,
2023-07-18 09:04:15 +08:00
};
2023-07-08 15:37:34 +08:00
}
//plotlist.bindSelList();
2023-07-18 09:04:15 +08:00
});
2023-07-08 15:37:34 +08:00
},
_last_attr: null,
//选中标号,激活属性面板
startEditing: function (attr, latlngs) {
2023-07-18 09:04:15 +08:00
this._last_attr = attr;
var config = this.config["polyline"] || {};
2023-07-08 15:37:34 +08:00
if (latlngs) {
2023-07-18 09:04:15 +08:00
this.updateLatlngsHtml(latlngs, config.position);
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
var arrFun = [];
2023-07-08 15:37:34 +08:00
//==============style==================
if (this.hasEditSylte) {
2023-07-18 09:04:15 +08:00
let parname = "plot_attr_style_";
let inHtml = '<tr><td class="nametd">类型:</td><td>' + (config.name || attr.name) + "</td></tr>";
2023-07-08 15:37:34 +08:00
for (let idx = 0; idx < config.style.length; idx++) {
2023-07-18 09:04:15 +08:00
let edit = config.style[idx];
if (edit.type == "hidden") {
continue;
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
let attrName = edit.name;
let attrVal = attr.style[attrName];
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
let input = this.getAttrInput(parname, attrName, attrVal, edit);
2023-07-08 15:37:34 +08:00
if (input.fun) {
arrFun.push({
parname: parname,
name: attrName,
value: attrVal,
edit: edit,
fun: input.fun,
2023-07-18 09:04:15 +08:00
});
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
inHtml += '<tr id="' + parname + "tr_" + attrName + '" > <td class="nametd">' + edit.label + "</td> <td>" + input.html + "</td> </tr>";
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
$("#talbe_style").html(inHtml);
2023-07-08 15:37:34 +08:00
}
//==============attr==================
2023-07-18 09:04:15 +08:00
let parname = "plot_attr_attr_";
let inHtml = "";
2023-07-08 15:37:34 +08:00
for (let idx = 0; idx < config.attr.length; idx++) {
2023-07-18 09:04:15 +08:00
let edit = config.attr[idx];
if (edit.type == "hidden") {
continue;
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
let attrName = edit.name;
let attrVal = attr.attr[attrName];
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
let input = this.getAttrInput(parname, attrName, attrVal, edit);
2023-07-08 15:37:34 +08:00
if (input.fun) {
arrFun.push({
parname: parname,
name: attrName,
value: attrVal,
edit: edit,
fun: input.fun,
2023-07-18 09:04:15 +08:00
});
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
inHtml += '<tr id="' + parname + "tr_" + attrName + '" > <td class="nametd">' + edit.label + "</td> <td>" + input.html + "</td> </tr>";
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
$("#talbe_attr").html(inHtml);
2023-07-08 15:37:34 +08:00
//执行各方法
for (let idx = 0; idx < arrFun.length; idx++) {
2023-07-18 09:04:15 +08:00
let item = arrFun[idx];
item.fun(item.parname, item.name, item.value, item.edit);
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
window.tab2attr(); //切换面板
2023-07-08 15:37:34 +08:00
},
lastCfg: null,
updateLatlngsHtml: function (latlngs, cfg) {
2023-07-18 09:04:15 +08:00
cfg = cfg || this.lastCfg || {};
this.lastCfg = cfg;
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
$("#plot_latlngs_addheight").val("");
$("#plot_latlngs_allheight").val("");
$("#view_updateheight").hide();
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
if (!cfg.hasOwnProperty("height")) {
cfg.height = true;
2023-07-08 15:37:34 +08:00
}
//显示坐标信息
2023-07-18 09:04:15 +08:00
var inHtml = "";
2023-07-08 15:37:34 +08:00
if (!latlngs || latlngs.length == 0) {
//
} else if (latlngs.length == 1) {
2023-07-18 09:04:15 +08:00
let latlng = latlngs[0];
let jd = latlng[0];
let wd = latlng[1];
let height = latlng.length == 3 ? latlng[2] : 0;
2023-07-08 15:37:34 +08:00
inHtml +=
' <div class="mp_attr" style=" margin-top: 10px;"><table>' +
' <tr> <td class="nametd">经度:</td> <td><input type="number" class="mp_input plot_latlngs" data-type="jd" value="' +
jd +
'"></td></tr>' +
'<tr> <td class="nametd">纬度:</td> <td><input type="number" class="mp_input plot_latlngs" data-type="wd" value="' +
wd +
2023-07-18 09:04:15 +08:00
'"></td></tr>';
2023-07-08 15:37:34 +08:00
if (cfg.height) {
inHtml +=
'<tr><td class="nametd">高程:</td> <td><input type="number" class="mp_input plot_latlngs" data-type="height" value="' +
height +
'" oldvalue="' +
height +
2023-07-18 09:04:15 +08:00
'"></td></tr>';
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
inHtml += " </table> </div>";
2023-07-08 15:37:34 +08:00
} else {
if (cfg.height) {
2023-07-18 09:04:15 +08:00
$("#view_updateheight").show();
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
var delhtml = "";
2023-07-08 15:37:34 +08:00
if (latlngs.length > (cfg.minCount || 3)) {
2023-07-18 09:04:15 +08:00
delhtml = '<i class="fa fa-trash-o latlng-del" title="删除点" ></i>';
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
var speeds = this._last_attr.attr.speed;
var isSpeedArray = !haoutil.isutil.isNumber(speeds);
var defSpeed = $("#txtFlySpeedAll").val() || 100;
2023-07-08 15:37:34 +08:00
for (var idx = 0; idx < latlngs.length; idx++) {
2023-07-18 09:04:15 +08:00
var latlng = latlngs[idx];
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
var jd = latlng[0];
var wd = latlng[1];
var height = latlng.length == 3 ? latlng[2] : 0;
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
var addthml = "";
2023-07-08 15:37:34 +08:00
if (cfg.maxCount == null || latlngs.length < cfg.maxCount) {
2023-07-18 09:04:15 +08:00
addthml = '<i class="fa fa-plus-square-o latlng-install" title="插入点" data-index="' + idx + '" ></i>&nbsp;&nbsp;';
2023-07-08 15:37:34 +08:00
}
//
inHtml +=
'<div><div class="open"><i class="tree_icon">-</i>第' +
(idx + 1) +
'点 <label style="width:100px;">&nbsp;</label> ' +
addthml +
delhtml +
' </div><div class="mp_attr"><table>' +
'<tr> <td class="nametd">经度:</td> <td><input type="number" class="mp_input plot_latlngs" data-type="jd" data-index="' +
idx +
'" value="' +
jd +
'"></td> </tr> ' +
'<tr> <td class="nametd">纬度:</td> <td><input type="number" class="mp_input plot_latlngs" data-type="wd" data-index="' +
idx +
'" value="' +
wd +
2023-07-18 09:04:15 +08:00
'"></td> </tr> ';
2023-07-08 15:37:34 +08:00
if (cfg.height) {
inHtml +=
'<tr> <td class="nametd">高程:</td> <td><input type="number" class="mp_input plot_latlngs" data-type="height" data-index="' +
idx +
'" value="' +
height +
'" oldvalue="' +
height +
2023-07-18 09:04:15 +08:00
'"></td> </tr> ';
2023-07-08 15:37:34 +08:00
}
if (idx != latlngs.length - 1) {
2023-07-18 09:04:15 +08:00
var _speed = isSpeedArray ? (speeds ? speeds[idx] : defSpeed) : speeds || defSpeed;
2023-07-08 15:37:34 +08:00
inHtml +=
'<tr> <td class="nametd">航速(km/h)</td> <td><input type="number" class="mp_input plot_speeds" title="第' +
(idx + 1) +
2023-07-18 09:04:15 +08:00
"点至第" +
2023-07-08 15:37:34 +08:00
(idx + 2) +
'点之间航速" data-type="speed" data-index="' +
idx +
'" value="' +
_speed +
2023-07-18 09:04:15 +08:00
'"></td> </tr> ';
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
inHtml += " </table> </div> </div>";
2023-07-08 15:37:34 +08:00
}
}
2023-07-18 09:04:15 +08:00
$("#view_latlngs").html(inHtml);
$("#view_latlngs .open").click(window.changeOpenShowHide);
var that = this;
$("#view_latlngs .latlng-del").click(function () {
$(this).parent().parent().remove();
var latlngs = [];
var withHeight = false;
$(".plot_latlngs").each(function () {
latlngs.push(Number($(this).val()));
if ($(this).attr("data-type") === "height") {
withHeight = true;
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
});
thisWidget.updateGeo2map(latlngs, withHeight);
2023-07-08 15:37:34 +08:00
//重新修改界面
2023-07-18 09:04:15 +08:00
var arr = [];
2023-07-08 15:37:34 +08:00
if (withHeight) {
for (let i = 0; i < latlngs.length; i += 3) {
2023-07-18 09:04:15 +08:00
arr.push([latlngs[i], latlngs[i + 1], latlngs[i + 2]]);
2023-07-08 15:37:34 +08:00
}
} else {
for (let i = 0; i < latlngs.length; i += 2) {
2023-07-18 09:04:15 +08:00
arr.push([latlngs[i], latlngs[i + 1]]);
2023-07-08 15:37:34 +08:00
}
}
2023-07-18 09:04:15 +08:00
that.updateLatlngsHtml(arr);
});
$("#view_latlngs .latlng-install").click(function () {
var idx = Number($(this).attr("data-index"));
2023-07-08 15:37:34 +08:00
//速度
2023-07-18 09:04:15 +08:00
var speeds = [];
$(".plot_speeds").each(function () {
speeds.push(Number($(this).val()));
});
speeds.splice(idx + 1, 0, speeds[idx]);
that._last_attr.attr.speed = speeds;
var latlngs = [];
var withHeight = false;
$(".plot_latlngs").each(function () {
latlngs.push(Number($(this).val()));
if ($(this).attr("data-type") === "height") {
withHeight = true;
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
var arr = [];
2023-07-08 15:37:34 +08:00
if (withHeight) {
for (let i = 0; i < latlngs.length; i += 3) {
2023-07-18 09:04:15 +08:00
arr.push([latlngs[i], latlngs[i + 1], latlngs[i + 2]]);
2023-07-08 15:37:34 +08:00
}
} else {
for (let i = 0; i < latlngs.length; i += 2) {
2023-07-18 09:04:15 +08:00
arr.push([latlngs[i], latlngs[i + 1]]);
2023-07-08 15:37:34 +08:00
}
}
2023-07-18 09:04:15 +08:00
var pt1 = arr[idx];
var pt2 = idx == arr.length - 1 ? arr[0] : arr[idx + 1];
var jd = Number(((pt1[0] + pt2[0]) / 2).toFixed(6));
var wd = Number(((pt1[1] + pt2[1]) / 2).toFixed(6));
2023-07-08 15:37:34 +08:00
if (withHeight) {
2023-07-18 09:04:15 +08:00
var gd = Number(((pt1[2] + pt2[2]) / 2).toFixed(1));
arr.splice(idx + 1, 0, [jd, wd, gd]);
latlngs.splice((idx + 1) * 3, 0, jd, wd, gd);
2023-07-08 15:37:34 +08:00
} else {
2023-07-18 09:04:15 +08:00
arr.splice(idx + 1, 0, [jd, wd]);
latlngs.splice((idx + 1) * 3, 0, jd, wd);
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
that.updateLatlngsHtml(arr);
thisWidget.updateGeo2map(latlngs, withHeight);
});
$(".plot_latlngs").bind("input propertychange", function () {
var latlngs = [];
var withHeight = false;
$(".plot_latlngs").each(function () {
latlngs.push(Number($(this).val()));
if ($(this).attr("data-type") === "height") {
withHeight = true;
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
});
thisWidget.updateGeo2map(latlngs, withHeight);
});
$(".plot_speeds").bind("input propertychange", function () {
var speeds = [];
$(".plot_speeds").each(function () {
speeds.push(Number($(this).val()));
});
that._last_attr.attr.speed = speeds;
});
2023-07-08 15:37:34 +08:00
},
//单击地图空白,释放属性面板
stopEditing: function () {
2023-07-18 09:04:15 +08:00
window.tab2plot(); //切换面板
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
$("#talbe_style").html("");
$("#talbe_attr").html("");
this._last_attr = null;
2023-07-08 15:37:34 +08:00
},
//获取各属性的编辑html和change方法
getAttrInput: function (parname, attrName, attrVal, edit) {
2023-07-18 09:04:15 +08:00
attrVal = attrVal || "";
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
var that = this;
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
var inHtml = "";
var fun = null;
2023-07-08 15:37:34 +08:00
switch (edit.type) {
default:
2023-07-18 09:04:15 +08:00
case "label":
inHtml = attrVal;
break;
case "text":
inHtml = '<input id="' + parname + attrName + '" type="text" value="' + attrVal + '" class="mp_input" />';
2023-07-08 15:37:34 +08:00
fun = function (parname, attrName, attrVal, edit) {
2023-07-18 09:04:15 +08:00
$("#" + parname + attrName).on("input propertychange", function (e) {
var attrVal = $(this).val();
that.updateAttr(parname, attrName, attrVal);
});
};
break;
case "textarea":
attrVal = attrVal.replace(new RegExp("<br />", "gm"), "\n");
inHtml = '<textarea id="' + parname + attrName + '" class="mp_input" style="height:50px;resize: none;" >' + attrVal + "</textarea>";
2023-07-08 15:37:34 +08:00
fun = function (parname, attrName, attrVal, edit) {
2023-07-18 09:04:15 +08:00
$("#" + parname + attrName).on("input propertychange", function (e) {
var attrVal = $(this).val();
2023-07-08 15:37:34 +08:00
if (attrVal.length == 0) {
2023-07-18 09:04:15 +08:00
attrVal = "";
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
attrVal = attrVal.replace(/\n/g, "<br />");
that.updateAttr(parname, attrName, attrVal);
});
};
break;
case "number":
inHtml = '<input id="' + parname + attrName + '" type="number" value="' + attrVal + '" class="mp_input"/>';
2023-07-08 15:37:34 +08:00
fun = function (parname, attrName, attrVal, edit) {
2023-07-18 09:04:15 +08:00
$("#" + parname + attrName).on("input propertychange", function (e) {
var attrVal = Number($(this).val());
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
that.updateAttr(parname, attrName, attrVal);
});
};
break;
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
case "combobox":
inHtml = '<select id="' + parname + attrName + '" class="mp_select" data-value="' + attrVal + '" >';
2023-07-08 15:37:34 +08:00
for (var jj = 0; jj < edit.data.length; jj++) {
2023-07-18 09:04:15 +08:00
var temp = edit.data[jj];
inHtml += '<option value="' + temp.value + '">' + temp.text + "</option>";
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
inHtml += "</select>";
2023-07-08 15:37:34 +08:00
fun = function (parname, attrName, attrVal, edit) {
2023-07-18 09:04:15 +08:00
$("#" + parname + attrName).select(); //绑定样式
$("#" + parname + attrName).change(function () {
var attrVal = $(this).attr("data-value");
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
that.updateAttr(parname, attrName, attrVal);
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
that.changeViewByAttrEx(parname, attrName, attrVal);
});
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
that.changeViewByAttrEx(parname, attrName, attrVal);
};
break;
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
case "radio":
var _name_key = parname + attrName;
2023-07-08 15:37:34 +08:00
inHtml =
' <div class="radio radio-info radio-inline"> <input type="radio" id="' +
_name_key +
'_1" value="1" name="' +
_name_key +
'" ' +
2023-07-18 09:04:15 +08:00
(attrVal ? 'checked="checked"' : "") +
2023-07-08 15:37:34 +08:00
'><label for="' +
_name_key +
'_1"> 是</label> </div> <div class="radio radio-info radio-inline"> <input type="radio" id="' +
_name_key +
'_2" value="2" name="' +
_name_key +
'" ' +
2023-07-18 09:04:15 +08:00
(attrVal ? "" : 'checked="checked"') +
2023-07-08 15:37:34 +08:00
' "><label for="' +
_name_key +
2023-07-18 09:04:15 +08:00
'_2"> 否 </label> </div>';
2023-07-08 15:37:34 +08:00
fun = function (parname, attrName, attrVal, edit) {
$('input:radio[name="' + parname + attrName + '"]').change(function () {
2023-07-18 09:04:15 +08:00
var attrVal = $(this).val() == "1";
that.updateAttr(parname, attrName, attrVal);
2023-07-08 15:37:34 +08:00
2023-07-18 09:04:15 +08:00
that.changeViewByAttr(parname, edit.impact, attrVal);
});
that.changeViewByAttr(parname, edit.impact, attrVal);
};
break;
case "color":
inHtml = '<input id="' + parname + attrName + '" class="mp_input" style="width: 100%;" value="' + attrVal + '" />';
2023-07-08 15:37:34 +08:00
fun = function (parname, attrName, attrVal, edit) {
2023-07-18 09:04:15 +08:00
$("#" + parname + attrName).minicolors({
position: "bottom right",
control: "saturation",
2023-07-08 15:37:34 +08:00
change: function (hex, opacity) {
2023-07-18 09:04:15 +08:00
that.updateAttr(parname, attrName, hex);
2023-07-08 15:37:34 +08:00
},
2023-07-18 09:04:15 +08:00
});
};
break;
case "slider":
inHtml = '<input id="' + parname + attrName + '" type="text" value="' + attrVal * 100 + '" />';
2023-07-08 15:37:34 +08:00
fun = function (parname, attrName, attrVal, edit) {
2023-07-18 09:04:15 +08:00
var _width = $(".mp_tab_card").width() * 0.7 - 30;
$("#" + parname + attrName).progress(_width); //绑定样式
$("#" + parname + attrName).change(function () {
var attrVal = Number($(this).val()) / 100;
that.updateAttr(parname, attrName, attrVal);
});
};
break;
case "window":
inHtml = '<input id="' + parname + attrName + '" type="text" value="' + attrVal + '" readonly class="mp_input" />';
2023-07-08 15:37:34 +08:00
fun = function (parname, attrName, attrVal, edit) {
2023-07-18 09:04:15 +08:00
$("#" + parname + attrName).on("click", function (e) {
2023-07-08 15:37:34 +08:00
thisWidget.showEditAttrWindow({
data: that._last_attr,
parname: parname,
attrName: attrName,
attrVal: attrVal,
2023-07-18 09:04:15 +08:00
});
});
$("#" + parname + attrName).on("input propertychange", function (e) {
var attrVal = $(this).val();
that.updateAttr(parname, attrName, attrVal);
});
};
break;
2023-07-08 15:37:34 +08:00
}
return {
html: inHtml,
fun: fun,
2023-07-18 09:04:15 +08:00
};
2023-07-08 15:37:34 +08:00
},
//联动属性控制
changeViewByAttr: function (parname, arrimpact, visible) {
if (arrimpact && arrimpact.length > 0) {
for (var jj = 0; jj < arrimpact.length; jj++) {
2023-07-18 09:04:15 +08:00
var attrName = arrimpact[jj];
2023-07-08 15:37:34 +08:00
if (visible) {
2023-07-18 09:04:15 +08:00
$("#" + parname + "tr_" + attrName).show();
2023-07-08 15:37:34 +08:00
} else {
2023-07-18 09:04:15 +08:00
$("#" + parname + "tr_" + attrName).hide();
2023-07-08 15:37:34 +08:00
}
}
}
},
changeViewByAttrEx: function (parname, attrName, attrVal) {
2023-07-18 09:04:15 +08:00
if (parname == "plot_attr_attr_" && attrName == "cameraType") {
2023-07-08 15:37:34 +08:00
switch (attrVal) {
default:
//无
2023-07-18 09:04:15 +08:00
$("#" + parname + "tr_followedX").hide();
$("#" + parname + "tr_followedZ").hide();
$("#" + parname + "tr_offsetZ").hide();
break;
case "gs": //跟随视角
$("#" + parname + "tr_followedX").hide();
$("#" + parname + "tr_followedZ").hide();
$("#" + parname + "tr_offsetZ").hide();
break;
case "dy": //锁定第一视角
$("#" + parname + "tr_followedX").show();
$("#" + parname + "tr_followedZ").show();
$("#" + parname + "tr_offsetZ").show();
break;
case "sd": //锁定上帝视角
$("#" + parname + "tr_followedX").hide();
$("#" + parname + "tr_followedZ").show();
$("#" + parname + "tr_offsetZ").hide();
break;
2023-07-08 15:37:34 +08:00
}
}
},
//属性面板值修改后触发此方法
updateAttr: function (parname, attrName, attrVal) {
switch (parname) {
default:
2023-07-18 09:04:15 +08:00
case "plot_attr_style_":
this._last_attr.style[attrName] = attrVal;
break;
case "plot_attr_attr_":
this._last_attr.attr[attrName] = attrVal;
2023-07-08 15:37:34 +08:00
//this.startEditing(this._last_attr);
2023-07-18 09:04:15 +08:00
break;
2023-07-08 15:37:34 +08:00
}
2023-07-18 09:04:15 +08:00
thisWidget.updateAttr2map(this._last_attr);
2023-07-08 15:37:34 +08:00
},
2023-07-18 09:04:15 +08:00
};