Commit 917b2495 authored by xinzhedeai's avatar xinzhedeai

add:better

parent 864c1424
......@@ -280,17 +280,8 @@ export default {
],
// 新增:车辆数据
vehicleList: [],
personModelInterval: null,
intervaler: null,
bgEntities: {}, // 所有的key都对应一个实体对象。而人员的实体对应的key不是数字。
// 轨迹追踪相关数据
selectedPerson: "", // 选中的人员
timePoints: [], // 时间点数组
currentTimeIndex: 0, // 当前时间索引
personTrajectories: {}, // 人员轨迹数据 { 人员名称: [{time, lng, lat, height}] }
trailEntities: {}, // 轨迹实体
isTracking: false, // 是否正在实时追踪
currentTimeDisplay: "", // 当前显示时间
};
},
mounted() {
......@@ -307,25 +298,35 @@ export default {
},
// 在beforeDestroy方法中添加清理代码
beforeDestroy() {
// 清理事件监听
window.removeEventListener("resize", this.handleResize);
// 清理地图资源
if (this.viewer) {
this.viewer.destroy();
this.viewer = null;
}
// 清理点击事件处理器
if (this.clickHandler) {
this.clickHandler.destroy();
this.clickHandler = null;
}
// 组件销毁前清理地图资源
if (this.viewer) {
this.viewer.destroy();
this.viewer = null;
}
if (this.personModelInterval) {
clearInterval(this.personModelInterval);
// 清理定时器
if (this.intervaler) {
clearInterval(this.intervaler);
}
if (this.trackingInterval) {
clearInterval(this.trackingInterval);
}
// 清空实体引用
this.bgEntities = {};
this.trailEntities = {};
},
methods: {
// 新增:实体类型选择变化处理
......@@ -426,61 +427,6 @@ export default {
}
},
addEntityClickHandler() {
// 创建鼠标事件处理器
this.clickHandler = new Cesium.ScreenSpaceEventHandler(
this.viewer.canvas
);
// 监听鼠标左键点击事件
this.clickHandler.setInputAction((click) => {
// 检测点击位置的实体
const pickedObject = this.viewer.scene.pick(click.position);
// 修复条件判断:检查是否是人员实体,通过判断是否有info属性或是否存在于bgEntities中
if (
Cesium.defined(pickedObject) &&
pickedObject.id &&
pickedObject.id.info // 直接检查实体是否有info属性
) {
// 获取点击的实体
const entity = pickedObject.id;
const personInfo = entity.info;
// 如果已有详细信息label,则移除它
if (entity.detailLabel) {
this.viewer.entities.remove(entity.detailLabel);
delete entity.detailLabel;
return;
}
console.log("点击实体了", personInfo);
// 创建详细信息label
const detailLabel = this.viewer.entities.add({
position: entity.position.getValue(),
label: {
text: `${personInfo.perName}\n状态: ${
personInfo.status === "online" ? "在线" : "离线"
}\n高度: ${personInfo.height.toFixed(2)}m`,
font: "14px 微软雅黑",
backgroundColor: Cesium.Color.fromCssColorString("#173349"),
showBackground: true,
fillColor: Cesium.Color.WHITE,
pixelOffset: new Cesium.Cartesian2(0, -60),
eyeOffset: new Cesium.Cartesian3(0, 0, -10),
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
verticalOrigin: Cesium.VerticalOrigin.TOP,
scaleByDistance: new Cesium.NearFarScalar(1000, 1, 500000, 0.5),
disableDepthTestDistance: Number.POSITIVE_INFINITY, // 确保始终显示在最前面
},
});
// 将详细信息label关联到实体,便于后续管理
entity.detailLabel = detailLabel;
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
},
/**
* 获取倾斜摄影模型的经纬度并将摄像机视角转向模型上方
*/
......@@ -556,9 +502,9 @@ export default {
// 修改createPersonModel方法
createPersonModel() {
// 先清除可能存在的定时器,避免重复执行
if (this.personModelInterval) {
clearInterval(this.personModelInterval);
this.personModelInterval = null;
if (this.intervaler) {
clearInterval(this.intervaler);
this.intervaler = null;
}
// 立即生成并显示人员实体,而不是等待定时器执行
......@@ -603,7 +549,7 @@ export default {
});
// 设置定时刷新,改为10秒(10000ms)
this.personModelInterval = setInterval(() => {
this.intervaler = setInterval(() => {
console.log("开始获取实时数据");
// 清除现有实体
this.clearEntities();
......@@ -690,9 +636,9 @@ export default {
// 新增:车辆模型创建方法
createVehicleModel() {
// 清除定时器,避免重复执行
if (this.personModelInterval) {
clearInterval(this.personModelInterval);
this.personModelInterval = null;
if (this.intervaler) {
clearInterval(this.intervaler);
this.intervaler = null;
}
// 清除现有实体
......@@ -734,7 +680,7 @@ export default {
}
// 设置定时刷新
this.personModelInterval = setInterval(() => {
this.intervaler = setInterval(() => {
console.log("开始获取实时车辆数据");
this.generateVehicleData();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment