Selaa lähdekoodia

feat: 完善多边形测量工具绘制逻辑

- 在绘制过程中只显示已完成的线段,不显示到鼠标位置的预览线段
- 在非绘制状态下显示完整的多边形包括闭合线段
- 优化了绘制过程中的视觉体验,避免闭合预览线的干扰

改动文件:
- src/components/measures/PolygonLengthMeasurementTool.ts
dengdx 2 viikkoa sitten
vanhempi
commit
279087ec7d
1 muutettua tiedostoa jossa 42 lisäystä ja 22 poistoa
  1. 42 22
      src/components/measures/PolygonLengthMeasurementTool.ts

+ 42 - 22
src/components/measures/PolygonLengthMeasurementTool.ts

@@ -1345,29 +1345,49 @@ export default class PolygonLengthMeasurementTool extends AnnotationTool {
       };
       // 绘制多边形线段(需要至少2个点)
       if (annotationUID && points.length >= 2) {
-        for (let j = 0; j < canvasPoints.length - 1; j++) {
-          const lineUID = `${annotationUID}-line-${j}`;
-          drawLineSvg(
-            svgDrawingHelper,
-            annotationUID,
-            lineUID,
-            canvasPoints[j],
-            canvasPoints[j + 1],
-            lineOptions
-          );
-        }
+        // 在绘制过程中:只绘制已完成的线段(不包括最后一段到鼠标位置的线段)
+        // 在非绘制过程中:绘制完整的多边形包括闭合线段
+        const isCurrentlyDrawing = this.isDrawing && this.currentAnnotation === annotation;
+
+        if (isCurrentlyDrawing) {
+          // 绘制过程中:只绘制 j 从 0 到 length-2 的线段(不显示闭合预览的实线)
+          for (let j = 0; j < canvasPoints.length - 1; j++) {
+            const lineUID = `${annotationUID}-line-${j}`;
+            drawLineSvg(
+              svgDrawingHelper,
+              annotationUID,
+              lineUID,
+              canvasPoints[j],
+              canvasPoints[j + 1],
+              lineOptions
+            );
+          }
+        } else {
+          // 非绘制过程中:绘制完整的多边形
+          for (let j = 0; j < canvasPoints.length - 1; j++) {
+            const lineUID = `${annotationUID}-line-${j}`;
+            drawLineSvg(
+              svgDrawingHelper,
+              annotationUID,
+              lineUID,
+              canvasPoints[j],
+              canvasPoints[j + 1],
+              lineOptions
+            );
+          }
 
-        // 绘制闭合线段(从最后一个点到第一个点)
-        if (points.length >= 3) {
-          const closingLineUID = `${annotationUID}-closing-line`;
-          drawLineSvg(
-            svgDrawingHelper,
-            annotationUID,
-            closingLineUID,
-            canvasPoints[canvasPoints.length - 1],
-            canvasPoints[0],
-            lineOptions
-          );
+          // 绘制闭合线段(从最后一个点到第一个点)
+          if (points.length >= 3) {
+            const closingLineUID = `${annotationUID}-closing-line`;
+            drawLineSvg(
+              svgDrawingHelper,
+              annotationUID,
+              closingLineUID,
+              canvasPoints[canvasPoints.length - 1],
+              canvasPoints[0],
+              lineOptions
+            );
+          }
         }
       }