代码优化

This commit is contained in:
BianLzhaoMin 2025-07-16 16:29:35 +08:00
parent 4457e9a2b6
commit f168f2a3e6
2 changed files with 49 additions and 24 deletions

View File

@ -460,7 +460,9 @@ function saveData(data) {
tbSpanTowerList = JSON.parse(pointsStr).map((item) => {
return {
id: item.id || null,
lon: item.lng.toString().slice(0, 10),
lon: item.lon
? item.lon.toString().slice(0, 10)
: item.lng.toString().slice(0, 10),
lat: item.lat.toString().slice(0, 10),
sort: item.sort,
};

View File

@ -7,6 +7,7 @@ let cablewayList = []; // 索道列表
let towerList = []; // 塔列表
let crossingList = []; // 跨越列表
let crossingListNew = []; // 跨越列表
let crossingLineListNew = []; // 跨越线列表
let highwayList = []; // 公路列表
let aThousandFieldsList = []; // 牵张场地
let intLng = 116.254; // 初始经度
@ -306,6 +307,7 @@ function getLocationInfo(id) {
crossingList = [];
crossingListNew = [];
crossingLineListNew = [];
cablewayList = [];
towerList = [];
@ -324,6 +326,7 @@ function getLocationInfo(id) {
} else {
crossingList = [];
crossingListNew = [];
crossingLineListNew = [];
}
if (data.highwayList.length > 0) {
@ -341,8 +344,10 @@ function getLocationInfo(id) {
// 处理一下交叉信息
if (crossingList && crossingList.length > 0) {
crossingList.forEach((item) => {
let lineList = [];
if (item.lonAndLat && item.lonAndLat.indexOf(",") > -1) {
const lonAndLatList = item.lonAndLat.split(",");
lonAndLatList.forEach((lonAndLat, index) => {
const lonAndLatItem = lonAndLat.split("@");
crossingListNew.push({
@ -350,8 +355,16 @@ function getLocationInfo(id) {
baiduLat: lonAndLatItem[1],
...item,
});
lineList.push({
baiduLon: lonAndLatItem[0],
baiduLat: lonAndLatItem[1],
...item,
});
});
}
crossingLineListNew.push({ lineList });
});
}
initMap();
@ -717,7 +730,7 @@ async function addAllMapPoints() {
});
graphicLayerList.push(billboard);
// graphicLayerList.push(graphic);
graphicLayerList.push(label2);
});
}
@ -931,35 +944,43 @@ async function addMapLine() {
},
});
graphicLayer.addGraphic(polyline);
graphicLayerList.push(polyline);
}
}
// 绘制交叉线路
if (crossingListNew.length > 0) {
for (let i = 0; i < crossingListNew.length - 1; i++) {
const startPoint = crossingListNew[i];
const endPoint = crossingListNew[i + 1];
if (crossingLineListNew.length > 0) {
for (let i = 0; i < crossingLineListNew.length; i++) {
for (
let j = 0;
j < crossingLineListNew[i].lineList.length - 1;
j++
) {
const startPoint = crossingLineListNew[i].lineList[j];
const endPoint = crossingLineListNew[i].lineList[j + 1];
// 创建线段点数组
const positions = [
[startPoint.baiduLon, startPoint.baiduLat],
[endPoint.baiduLon, endPoint.baiduLat],
];
// 创建线段点数组
const positions = [
[startPoint.baiduLon, startPoint.baiduLat],
[endPoint.baiduLon, endPoint.baiduLat],
];
// const positions2 = positions.map((item) => {
// return mars3d.PointTrans.bd2wgs(item);
// });
// const positions2 = positions.map((item) => {
// return mars3d.PointTrans.bd2wgs(item);
// });
const polyline = new mars3d.graphic.PolylineEntity({
positions: positions,
eventParent: false,
style: {
width: 2, // 线宽(像素)
color: "#800080", // 线颜色
clampToGround: true, // 是否贴地山区建议设为true
},
});
graphicLayer.addGraphic(polyline);
const polyline = new mars3d.graphic.PolylineEntity({
positions: positions,
eventParent: false,
style: {
width: 2, // 线宽(像素)
color: "#800080", // 线颜色
clampToGround: true, // 是否贴地山区建议设为true
},
});
graphicLayer.addGraphic(polyline);
graphicLayerList.push(polyline);
}
}
}
@ -998,6 +1019,7 @@ async function addMapLine() {
},
});
graphicLayer.addGraphic(polyline);
graphicLayerList.push(polyline);
}
}
});
@ -1037,6 +1059,7 @@ async function addMapLine() {
},
});
graphicLayer.addGraphic(polyline);
graphicLayerList.push(polyline);
}
}
}