| | |
| | | }; |
| | | } |
| | | function addPointToViewer(point, index) { |
| | | // 确保 currentTime 有合理值 |
| | | const displayTime = currentTime.value || "未设置时间"; |
| | | |
| | | // 添加标签(确保实体创建时包含label属性) |
| | | const entity = viewer.entities.add({ |
| | | const labelEntity = viewer.entities.add({ |
| | | position: point.cartesian, |
| | | label: { |
| | | text: `测量点 ${index + 1}\n经度: ${point.longitude.toFixed(6)}\n纬度: ${point.latitude.toFixed(6)}\n时间: ${displayTime}`, |
| | |
| | | backgroundPadding: new Cesium.Cartesian2(10, 10), |
| | | showBackground: true, |
| | | scale: 1, |
| | | distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 5000), // 距地面5000米内显示 |
| | | pixelOffsetScaleByDistance: new Cesium.NearFarScalar( |
| | | 100, // Near 距离 (相机离地100米) |
| | | 1.0, // 在近处,放大倍数为1.0(正常) |
| | | 5000, // Far 距离 (相机离地5000米) |
| | | 0.3 // 在远处,缩小到0.3倍 |
| | | ) |
| | | distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 5000), |
| | | pixelOffsetScaleByDistance: new Cesium.NearFarScalar(100, 1.0, 5000, 0.3) |
| | | } |
| | | }); |
| | | |
| | | // 添加垂直线 |
| | | viewer.entities.add({ |
| | | const lineEntity = viewer.entities.add({ |
| | | polyline: { |
| | | positions: [point.cartesian, Cesium.Cartesian3.fromRadians(point.longitude * Math.PI / 180, point.latitude * Math.PI / 180, 0)], |
| | | width: 2, |
| | | material: new Cesium.PolylineOutlineMaterialProperty({ |
| | | outlineWidth: 4, |
| | | outlineColor: Cesium.Color.WHITE |
| | | color: Cesium.Color.RED.withAlpha(0.8), |
| | | outlineColor: Cesium.Color.WHITE, |
| | | outlineWidth: 4 |
| | | }), |
| | | distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 5000), // 距地面5000米内显示 |
| | | pixelOffsetScaleByDistance: new Cesium.NearFarScalar( |
| | | 100, // Near 距离 (相机离地100米) |
| | | 1.0, // 在近处,放大倍数为1.0(正常) |
| | | 5000, // Far 距离 (相机离地5000米) |
| | | 0.3 // 在远处,缩小到0.3倍 |
| | | ) |
| | | |
| | | |
| | | distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 5000), |
| | | pixelOffsetScaleByDistance: new Cesium.NearFarScalar(100, 1.0, 5000, 0.3) |
| | | } |
| | | }); |
| | | |
| | | // 存储点的信息(包含完整的entity引用) |
| | | // 保存 labelEntity 和 lineEntity |
| | | pickedPoints.value.push({ |
| | | entity: entity, |
| | | labelEntity, |
| | | lineEntity, |
| | | longitude: point.longitude, |
| | | latitude: point.latitude, |
| | | latitude: point.latitude |
| | | }); |
| | | } |
| | | |
| | |
| | | |
| | | function updateAllLabels() { |
| | | pickedPoints.value.forEach((pointInfo, index) => { |
| | | if (pointInfo.entity && pointInfo.entity.label) { |
| | | pointInfo.entity.label.text = |
| | | if (pointInfo.labelEntity && pointInfo.labelEntity.label) { |
| | | pointInfo.labelEntity.label.text = |
| | | `测量点 ${index + 1}\n经度: ${pointInfo.longitude.toFixed(6)}\n纬度: ${pointInfo.latitude.toFixed(6)}\n时间: ${currentTime.value}`; |
| | | } |
| | | }); |
| | |
| | | } |
| | | |
| | | function endCalculation() { |
| | | // ElMessage.success('清除所有测量点!'); |
| | | // console.log('由本功能创建的所有 label 和 polyline entities:'); |
| | | // pickedPoints.value.forEach((pointInfo, index) => { |
| | | // console.log(`测量点 ${index + 1}:`); |
| | | // console.log('Label Entity:', pointInfo.labelEntity); |
| | | // console.log('Polyline Entity:', pointInfo.lineEntity); |
| | | // }); |
| | | // console.log('当前 Cesium 中所有实体列表:'); |
| | | // viewer.entities.values.forEach((entity, idx) => { |
| | | // console.log(`实体 #${idx}:`, entity); |
| | | // }); |
| | | pickedPoints.value.forEach(pointInfo => { |
| | | if (pointInfo.labelEntity) viewer.entities.remove(pointInfo.labelEntity); |
| | | if (pointInfo.lineEntity) viewer.entities.remove(pointInfo.lineEntity); |
| | | }); |
| | | pickedPoints.value = []; |
| | | viewer.entities.removeAll(); |
| | | // currentTime.value = 0; |
| | | } |
| | | defineExpose({ |
| | | endCalculation |