From e742405735a862ba5f393581390bbdd7fa30c0ef Mon Sep 17 00:00:00 2001 From: yyy <2605810609@qq.com> Date: Thu, 20 Mar 2025 08:59:13 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../itemAreaManagementDialog.vue | 56 ++++++- .../lineLibraryManagementDialog.vue | 47 +++++- src/views/mapPage/realTimeMap/editMap.vue | 111 ++++++++------ src/views/mapPage/realTimeMap/test.vue | 145 ++++++++++++------ 4 files changed, 260 insertions(+), 99 deletions(-) diff --git a/src/views/mapPage/realTimeMap/components-tool/itemAreaManagementDialog.vue b/src/views/mapPage/realTimeMap/components-tool/itemAreaManagementDialog.vue index 229b8336..02bfc38c 100644 --- a/src/views/mapPage/realTimeMap/components-tool/itemAreaManagementDialog.vue +++ b/src/views/mapPage/realTimeMap/components-tool/itemAreaManagementDialog.vue @@ -1,8 +1,8 @@ @@ -12,11 +12,12 @@ :header-cell-style="{ backgroundColor: '#EBF1FF', color: '#0D162A', padding: '13px 0' }" v-loading="loading" > - - - - + + + + + 编辑 删除 @@ -34,6 +35,23 @@ /> + + + + + + + + + + + + + + diff --git a/src/views/mapPage/realTimeMap/components-tool/lineLibraryManagementDialog.vue b/src/views/mapPage/realTimeMap/components-tool/lineLibraryManagementDialog.vue index 390373b6..2ab40a0a 100644 --- a/src/views/mapPage/realTimeMap/components-tool/lineLibraryManagementDialog.vue +++ b/src/views/mapPage/realTimeMap/components-tool/lineLibraryManagementDialog.vue @@ -2,7 +2,7 @@ @@ -12,10 +12,11 @@ :header-cell-style="{ backgroundColor: '#EBF1FF', color: '#0D162A', padding: '13px 0' }" v-loading="loading" > - - + + + 编辑 删除 @@ -33,6 +34,20 @@ /> + + + + + + + + + + + diff --git a/src/views/mapPage/realTimeMap/editMap.vue b/src/views/mapPage/realTimeMap/editMap.vue index d44122ba..a268c131 100644 --- a/src/views/mapPage/realTimeMap/editMap.vue +++ b/src/views/mapPage/realTimeMap/editMap.vue @@ -605,35 +605,18 @@ + + + + + {{ state.measureDistancesNum.toFixed(2) }}米 + + - - 距离:{{ state.measureDistancesNum.toFixed(2) }}米 @@ -2318,28 +2301,68 @@ const editMapRouteDialogSubmit = (form) => { addEditHistory() //重新监听键盘事件 } //测距相关 -// 计算两点之间的距离 -const calculateDistance = (point1, point2) => { - const dx = point2.x - point1.x - const dy = point2.y - point1.y - return Math.sqrt(dx * dx + dy * dy) -} -// 计算连线的角度 -const computedLineAngle = computed(() => { +// 计算连线的样式 +const rangingLineStyle = computed(() => { if (state.measureDistancesPoints.length === 2) { - const dx = state.measureDistancesPoints[1].x - state.measureDistancesPoints[0].x - const dy = state.measureDistancesPoints[1].y - state.measureDistancesPoints[0].y - return Math.atan2(dy, dx) * (180 / Math.PI) + const [point1, point2] = state.measureDistancesPoints + const length = Math.sqrt(Math.pow(point2.x - point1.x, 2) + Math.pow(point2.y - point1.y, 2)) + const angle = (Math.atan2(point2.y - point1.y, point2.x - point1.x) * 180) / Math.PI + return { + position: 'absolute', + left: `${point1.x}px`, + top: `${point1.y}px`, + width: `${length}px`, + height: '2px', + backgroundColor: 'red', + transform: `rotate(${angle}deg)`, + transformOrigin: '0 0' + } } - return 0 + return {} }) -// 计算连线的长度 -const computedLineWidth = computed(() => { +// 计算距离信息的样式(显示在连线中间,并根据角度调整文字方向) +const rangingTextStyle = computed(() => { if (state.measureDistancesPoints.length === 2) { - return calculateDistance(state.measureDistancesPoints[0], state.measureDistancesPoints[1]) + const [point1, point2] = state.measureDistancesPoints + const midX = (point1.x + point2.x) / 2 + const midY = (point1.y + point2.y) / 2 + const angle = (Math.atan2(point2.y - point1.y, point2.x - point1.x) * 180) / Math.PI + + // 调整文字方向,使其始终易于阅读 + let textRotation = 0 + if (angle > 90 || angle < -90) { + textRotation = angle + 180 // 翻转文字方向 + } else { + textRotation = angle + } + + return { + position: 'absolute', + left: `${midX}px`, + top: `${midY}px`, + transform: `translate(-50%, -50%) rotate(${textRotation}deg)`, + backgroundColor: 'rgba(255, 255, 255, 0.8)', + padding: '2px', + borderRadius: '4px', + fontSize: '12px', + color: 'black', + whiteSpace: 'nowrap', // 防止文字换行 + pointerEvents: 'none' // 防止文字遮挡点击事件 + } } - return 0 + return {} +}) + +// 计算点的样式 +const getRangingPointStyle = (point) => ({ + position: 'absolute', + left: `${point.x - 4}px`, + top: `${point.y - 4}px`, + width: '8px', + height: '8px', + backgroundColor: 'blue', + borderRadius: '50%' }) //计算路线的距离 @@ -2411,9 +2434,9 @@ const measureDistancesClick = (event) => { state.measureDistancesPoints.push({ x: offsetX, y: offsetY }) if (state.measureDistancesPoints.length === 2) { // 计算两点之间的距离 - let distancesNum = calculateDistance( - state.measureDistancesPoints[0], - state.measureDistancesPoints[1] + const [point1, point2] = state.measureDistancesPoints + let distancesNum = Math.sqrt( + Math.pow(point2.x - point1.x, 2) + Math.pow(point2.y - point1.y, 2) ) state.measureDistancesNum = distancesNum * Number(imgBgObj.resolution) } diff --git a/src/views/mapPage/realTimeMap/test.vue b/src/views/mapPage/realTimeMap/test.vue index 95a8eaca..697e0388 100644 --- a/src/views/mapPage/realTimeMap/test.vue +++ b/src/views/mapPage/realTimeMap/test.vue @@ -1,60 +1,115 @@ - - 放大 - 缩小 - - + + + + + + + 距离: {{ state.measureDistancesNum.toFixed(2) }} 像素 + + + -