diff --git a/frontend/Skyeye-sys-ui/src/views/home/components/twin-situation/index.js b/frontend/Skyeye-sys-ui/src/views/home/components/twin-situation/index.js index dad00ed..73bab2f 100644 --- a/frontend/Skyeye-sys-ui/src/views/home/components/twin-situation/index.js +++ b/frontend/Skyeye-sys-ui/src/views/home/components/twin-situation/index.js @@ -54,6 +54,7 @@ let sceneEntity = {} let taskListResource = [] let orthoManager = null let socketPositionIndex = 0 +let uavTracks = {} const lang = window.localStorage.getItem('locale') || 'zh_CN' export default { name: 'TwinSituation', @@ -481,6 +482,7 @@ export default { this.SET_SPLIT_VISIBLE(false) this.removePictureHandle() socketPositionIndex = 0 + uavTracks = {} if (orthoManager) { orthoManager.clearAll() orthoManager = null @@ -1099,6 +1101,7 @@ export default { let data = res.data.data let list = [] socketPositionIndex = 0 + uavTracks = {} data.forEach(item => { // item.check = item.status === 1 || item.status === 3 item.check = false @@ -1582,6 +1585,7 @@ export default { // } this.removeTaskTarget(info.id); socketPositionIndex = 0 + uavTracks = {} if (orthoManager) { orthoManager.clearAll() orthoManager = null @@ -1614,7 +1618,9 @@ export default { viewer.entities.remove(item) } }) + viewer.entities socketPositionIndex = 0 + uavTracks = {} if (orthoManager) { orthoManager.clearAll() orthoManager = null @@ -2786,51 +2792,78 @@ export default { this.updateSceneUav(data) }, updateSceneUav(data) { - console.log(data, 44444); + // 1. 坐标转换(建议添加异常处理,避免非法坐标) + if (!data.longitude || !data.latitude) { + console.warn('无人机坐标不完整', data); + return; + } + let position = DT.Cesium.Cartesian3.fromDegrees( + Number(data.longitude), + Number(data.latitude), + Number(data.altitude) || 0 // 高度默认0,避免undefined + ); + let uavId = 'uav-' + data.jobId; - let position = DT.Cesium.Cartesian3.fromDegrees(data.longitude, data.latitude, data.altitude) - let entity = viewer.entities.getById('uav-' + data.id) + // 2. 轨迹数组维护(过滤重复坐标,避免无长度轨迹) + if (uavTracks[uavId]) { + // 获取最后一个坐标,计算与新坐标的距离(小于1米则不添加) + const lastPos = uavTracks[uavId][uavTracks[uavId].length - 1]; + const distance = lastPos ? DT.Cesium.Cartesian3.distance(lastPos, position) : 0; + // 只有距离大于1米时才添加新坐标,避免高频重复 + if (distance > 1) { + uavTracks[uavId].push(position); + // 限制轨迹长度,避免数组过大(可选,比如最多保存1000个点) + if (uavTracks[uavId].length > 1000) { + uavTracks[uavId].shift(); + } + } + } else { + uavTracks[uavId] = [position]; + } + // 3. 获取/创建无人机实体 + let entity = viewer.entities.getById(uavId); if (entity) { - entity.position = position + entity.position = position; + // !关键:更新实体后主动触发Cesium重绘(部分版本需要) + viewer.scene.requestRender(); } else { entity = viewer.entities.add({ - id: 'uav-' + data.id, + id: uavId, position: position, label: { text: '无人机', font: '14px sans-serif', - fillColor: DT.Cesium.Color.WHITE, + fillColor: DT.Cesium.Color.RED, horizontalOrigin: DT.Cesium.HorizontalOrigin.LEFT, verticalOrigin: DT.Cesium.VerticalOrigin.CENTER, disableDepthTestDistance: 100000, - pixelOffset: new DT.Cesium.Cartesian2(10, 0), showBackground: true, scaleByDistance: new DT.Cesium.NearFarScalar(0, 1, 1, 0.8), - distanceDisplayCondition: new DT.Cesium.DistanceDisplayCondition(0, 20000), - backgroundColor: DT.Cesium.Color.fromCssColorString('rgba(0,0,0,0.7)'), - style: DT.Cesium.LabelStyle.FILL_AND_OUTLINE, + distanceDisplayCondition: new DT.Cesium.DistanceDisplayCondition(0, 10000), + backgroundColor: DT.Cesium.Color.fromCssColorString('rgba(255,255,255,0.6)'), + pixelOffset: new DT.Cesium.Cartesian2(10, -15), }, model: { uri: process.env.BASE_URL + 'model/uav.gltf', minimumPixelSize: 64, maximumScale: 128, }, - // point: { - // pixelSize: 40, - // color: DT.Cesium.Color.RED, - // disableDepthTestDistance: 10000 - // }, polyline: { - positions: new DT.Cesium.CallbackProperty(function () { - return this.positions + // 修复:绑定uavId到回调作用域,避免丢失 + positions: new DT.Cesium.CallbackProperty(() => { + return uavTracks[uavId] || []; }, false), - width: 8, - zIndex: 600, - material: DT.Cesium.Color.BLACK, - depthFailMaterial: DT.Cesium.Color.CYAN, - arcType: DT.Cesium.ArcType.NONE + width: 2, // 线宽加大,更容易观察 + zIndex: 600, // 提高层级,避免被其他元素覆盖 + material: DT.Cesium.Color.fromCssColorString('#1fe46b'), // 半透明,更易见 + depthFailMaterial: DT.Cesium.Color.CYAN.withAlpha(0.8), + arcType: DT.Cesium.ArcType.NONE, // 关键:添加直线轨迹配置 + disableDepthTestDistance: Number.POSITIVE_INFINITY, // 永不被遮挡 + distanceDisplayCondition: new DT.Cesium.DistanceDisplayCondition(0, 50000), // 扩大显示范围 + clampToGround: false, // 不贴地,跟随无人机高度 + show: true // 显式开启,避免默认隐藏 } - }) + }); } }, handleWebsocketWave(info) { @@ -3090,6 +3123,7 @@ export default { } }) socketPositionIndex = 0 + uavTracks = {} if (orthoManager) { orthoManager.clearAll() orthoManager = null