From 8f48ade9bfe39f10239fda0cac85c96c543643d1 Mon Sep 17 00:00:00 2001 From: ctw <1051735452@qq.com> Date: Mon, 2 Feb 2026 11:25:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9C=9F=E6=96=B9=E4=BD=8D=EF=BC=8C=E7=A3=81?= =?UTF-8?q?=E6=96=B9=E4=BD=8D=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/views/cesiumMap/index.vue | 104 +++++++++++++++++++++++++++++++-- 1 file changed, 100 insertions(+), 4 deletions(-) diff --git a/ruoyi-ui/src/views/cesiumMap/index.vue b/ruoyi-ui/src/views/cesiumMap/index.vue index aa41e97..ab592a5 100644 --- a/ruoyi-ui/src/views/cesiumMap/index.vue +++ b/ruoyi-ui/src/views/cesiumMap/index.vue @@ -577,10 +577,15 @@ export default { // 如果是线实体,显示长度信息 if (entityData && entityData.type === 'line') { const length = this.calculateLineLength(entityData.positions) + // 根据当前方位角类型计算方位角 + const bearingType = entityData.bearingType || 'true'; + const bearing = bearingType === 'magnetic' + ? this.calculateMagneticBearing(entityData.positions) + : this.calculateTrueBearing(entityData.positions); // 显示小框提示 this.hoverTooltip = { visible: true, - content: `长度:${length.toFixed(2)} 米`, + content: `长度:${length.toFixed(2)} 米\n${bearingType === 'magnetic' ? '磁方位' : '真方位'}:${bearing.toFixed(2)}°`, position: { x: movement.endPosition.x + 10, y: movement.endPosition.y - 10 @@ -842,10 +847,12 @@ export default { // 计算从最后一个点到当前鼠标位置的线段长度 const tempPositions = [...this.drawingPoints, newPosition]; const length = this.calculateLineLength(tempPositions); - // 更新小框提示,显示实时长度 + // 默认为真方位,因为绘制过程中还没有bearingType属性 + const bearing = this.calculateTrueBearing(tempPositions); + // 更新小框提示,显示实时长度和真方位角 this.hoverTooltip = { visible: true, - content: `长度:${length.toFixed(2)} 米`, + content: `长度:${length.toFixed(2)} 米\n真方位:${bearing.toFixed(2)}°`, position: { x: movement.endPosition.x + 10, y: movement.endPosition.y - 10 @@ -1959,7 +1966,8 @@ export default { pointEntities: pointEntities, // 存储点实体 color: this.defaultStyles.line.color, width: this.defaultStyles.line.width, - label: `线 ${this.entityCounter}` + label: `线 ${this.entityCounter}`, + bearingType: 'true' // 默认真方位 } this.allEntities.push(entityData) entity.clickHandler = (e) => { @@ -2089,6 +2097,94 @@ export default { } return totalLength }, + calculateTrueBearing(positions) { + if (!positions || positions.length < 2) { + return 0; + } + // 获取最后一段线段的两个端点 + const startPos = positions[positions.length - 2]; + const endPos = positions[positions.length - 1]; + + // 将笛卡尔坐标转换为地理坐标 + const startCartographic = Cesium.Cartographic.fromCartesian(startPos); + const endCartographic = Cesium.Cartographic.fromCartesian(endPos); + + // 转换为弧度 + const startLat = startCartographic.latitude; + const startLng = startCartographic.longitude; + const endLat = endCartographic.latitude; + const endLng = endCartographic.longitude; + + // 计算真方位角 + const dLng = endLng - startLng; + const y = Math.sin(dLng) * Math.cos(endLat); + const x = Math.cos(startLat) * Math.sin(endLat) - Math.sin(startLat) * Math.cos(endLat) * Math.cos(dLng); + let bearing = Math.atan2(y, x); + + // 转换为角度并调整到0-360范围 + bearing = Cesium.Math.toDegrees(bearing); + return (bearing + 360) % 360; + }, + // 计算磁偏角(简化模型) + calculateMagneticDeclination(lat, lng) { + // 注意:这是一个简化的磁偏角计算模型 + // 实际应用中,应该使用更精确的模型,如 WMM (World Magnetic Model) + + // 转换为角度 + const latDeg = Cesium.Math.toDegrees(lat); + const lngDeg = Cesium.Math.toDegrees(lng); + + // 简化的磁偏角计算(仅适用于中国地区) + // 实际值会随时间变化,此处为近似值 + let declination; + + if (lngDeg >= 73 && lngDeg <= 135 && latDeg >= 18 && latDeg <= 53) { + // 中国地区简化磁偏角模型 + // 基于2020年数据,每年约变化0.1度 + const year = new Date().getFullYear(); + const yearOffset = (year - 2020) * 0.1; + + if (lngDeg < 100) { + // 西部地区 + declination = 2.0 - yearOffset; + } else if (lngDeg < 115) { + // 中部地区 + declination = 1.0 - yearOffset; + } else { + // 东部地区 + declination = 0.5 - yearOffset; + } + } else { + // 其他地区默认磁偏角为0 + declination = 0; + } + + return declination; + }, + // 计算磁方位角 + calculateMagneticBearing(positions) { + if (!positions || positions.length < 2) { + return 0; + } + + // 计算真方位角 + const trueBearing = this.calculateTrueBearing(positions); + + // 获取线段起点的地理坐标 + const startPos = positions[positions.length - 2]; + const startCartographic = Cesium.Cartographic.fromCartesian(startPos); + const startLat = startCartographic.latitude; + const startLng = startCartographic.longitude; + + // 计算磁偏角 + const declination = this.calculateMagneticDeclination(startLat, startLng); + + // 计算磁方位角(真方位角加上磁偏角) + let magneticBearing = trueBearing + declination; + + // 调整到0-360范围 + return (magneticBearing + 360) % 360; + }, calculatePolygonArea(positions) { if (positions.length < 3) return 0 let area = 0