소스 검색

继续绘图

xushiting 2 년 전
부모
커밋
bb6f770f64
2개의 변경된 파일27개의 추가작업 그리고 8개의 파일을 삭제
  1. 19 6
      src/graphic/Layer.js
  2. 8 2
      src/graphic/Util/MathUtil.js

+ 19 - 6
src/graphic/Layer.js

@@ -699,17 +699,30 @@ export default class Layer {
       //弯路添加控制点
       else if (e.code == "KeyT") {
         const curveRoad = dataService.getCurveRoad(focusItem.vectorId);
-        const joinInfo = mathUtil.getHitInfoForCurves(
+        let index = mathUtil.getIndexForCurvesPoints(
           this.mousePosition,
-          curveRoad.curves,
-          curveRoad.width
-        );
-        const index = mathUtil.getIndexForCurvesPoints(
-          joinInfo.position,
           curveRoad.points
         );
         if (index != -1) {
           curveRoadService.addCPoint(curveRoad, this.mousePosition, index);
+        } else {
+          const dis1 = mathUtil.getDistance(
+            curveRoad.points[0],
+            this.mousePosition
+          );
+          const dis2 = mathUtil.getDistance(
+            curveRoad.points[curveRoad.points.length - 1],
+            this.mousePosition
+          );
+          if (dis1 > dis2) {
+            curveRoadService.addCPoint(
+              curveRoad,
+              this.mousePosition,
+              curveRoad.points.length - 2
+            );
+          } else {
+            curveRoadService.addCPoint(curveRoad, this.mousePosition, 1);
+          }
         }
         this.renderer.autoRedraw();
         this.history.save();

+ 8 - 2
src/graphic/Util/MathUtil.js

@@ -1341,14 +1341,20 @@ export default class MathUtil {
   }
 
   getIndexForCurvesPoints(position, points) {
+    let minDis = null;
+    let index = -1;
     for (let i = 0; i < points.length - 1; ++i) {
       const line = this.createLine1(points[i], points[i + 1]);
       const join = this.getJoinLinePoint(position, line);
+      const dis = mathUtil.getDistance(position, join);
       if (this.isContainForSegment(join, points[i], points[i + 1])) {
-        return i;
+        if (minDis == null || minDis > dis) {
+          minDis = dis;
+          index = i;
+        }
       }
     }
-    return -1;
+    return index;
   }
 }