| | |
| | | }; |
| | | } |
| | | 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}`, |
| | | font: '14pt monospace', // 减小字体大小 |
| | | font: '14pt monospace', |
| | | style: Cesium.LabelStyle.FILL_AND_OUTLINE, |
| | | fillColor: Cesium.Color.YELLOW, |
| | | outlineColor: Cesium.Color.BLACK, |
| | | outlineWidth: 2, // 减小轮廓宽度 |
| | | outlineWidth: 2, |
| | | verticalOrigin: Cesium.VerticalOrigin.CENTER, |
| | | horizontalOrigin: Cesium.HorizontalOrigin.CENTER, |
| | | backgroundColor: Cesium.Color.fromCssColorString('rgba(0,0,0,0.7)'), |
| | | backgroundPadding: new Cesium.Cartesian2(10, 10), // 减小背景填充 |
| | | backgroundPadding: new Cesium.Cartesian2(10, 10), |
| | | showBackground: true, |
| | | scale: 1, // 设置缩放比例 |
| | | maximumScale: 1.5, // 设置最大缩放比例 |
| | | scale: 1, |
| | | 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), |
| | | 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 |