瀏覽代碼

修复bug

xushiting 2 年之前
父節點
當前提交
a08372b522

+ 2 - 0
src/graphic/Controls/AddPoint.js

@@ -12,6 +12,7 @@ import VectorType from "../enum/VectorType";
 import Constant from "../Constant";
 import { listenLayer } from "../ListenLayer";
 import { textService } from "../Service/TextService";
+import { uiService } from "../Service/UIService";
 
 export default class AddPoint {
   constructor() {
@@ -96,6 +97,7 @@ export default class AddPoint {
       newPoint.linkedTextId = textVector.vectorId;
       textVector.linkedPointId = newPoint.vectorId;
     }
+    uiService.setSelectPointCategory(VectorCategory.Point.NormalPoint);
     listenLayer.clear();
     return newPoint;
   }

+ 13 - 2
src/graphic/Controls/LocationModeControl.js

@@ -37,11 +37,19 @@ export default class LocationModeControl {
     let startPoint = dataService.getPoint(baseLine.startId);
     let endPoint = dataService.getPoint(baseLine.endId);
 
+    fixPoint.linkedBasePointId = basePoint.vectorId;
+
     let baseLineGeometry = mathUtil.createLine1(startPoint, endPoint);
     let vLine = mathUtil.getVerticalLine(baseLineGeometry, fixPoint);
-    let join = mathUtil.getJoinLinePoint(basePoint, vLine);
+    // let join = mathUtil.getJoinLinePoint(basePoint, vLine);
+    // join = pointService.create(join);
+    // join.setLocationMode(Constant.angleLocationMode);
+    let join = mathUtil.getIntersectionPoint(baseLineGeometry, vLine); //固定点到基准线的垂直线与基准线的交点
     join = pointService.create(join);
     join.setLocationMode(Constant.angleLocationMode);
+    join.setCategory(VectorCategory.Point.TestBasePoint);
+    //join.setCategory(VectorCategory.Line.LocationLineByFixPoint);
+    //fixPoint.linkedTestPointId = join.vectorId;
 
     let locationLineByFixPoint = lineService.createByPointId(
       fixPointId,
@@ -50,10 +58,13 @@ export default class LocationModeControl {
     );
     locationLineByFixPoint.setLocationMode(Constant.angleLocationMode);
 
-    let locationLineByBasePoint = mathUtil.getVerticalLine(vLine, basePoint);
+    let locationLineByBasePoint = mathUtil.getVerticalLine(vLine, basePoint); //基准点1条垂直线的垂直线
     join = mathUtil.getIntersectionPoint(locationLineByBasePoint, vLine);
     join = pointService.create(join);
     join.setLocationMode(Constant.angleLocationMode);
+    join.setCategory(VectorCategory.Point.TestBasePoint);
+    //join.linkedBasePointId = basePointId;
+
     locationLineByBasePoint = lineService.createByPointId(
       basePointId,
       join.vectorId,

+ 73 - 2
src/graphic/Controls/MoveLine.js

@@ -1,4 +1,6 @@
 import Constant from "../Constant";
+import Settings from "../Settings";
+
 import { dataService } from "../Service/DataService";
 import { lineService } from "../Service/LineService";
 import { pointService } from "../Service/PointService";
@@ -93,10 +95,14 @@ export default class MoveLine {
     let startPoint = dataService.getPoint(line.startId);
     let endPoint = dataService.getPoint(line.endId);
 
+    let baseLine = dataService.getLine(Settings.baseLineId);
+    let baseStartPoint = dataService.getPoint(baseLine.startId);
+    let baseEndPoint = dataService.getPoint(baseLine.endId);
+    baseLine = mathUtil.createLine1(baseStartPoint, baseEndPoint);
+
     //垂直移动,直角定位法只支持定位线的拖拽
     if (
-      (line.getCategory() == VectorCategory.Line.LocationLineByFixPoint ||
-        line.getCategory() == VectorCategory.Line.LocationLineByBasePoint) &&
+      line.getCategory() == VectorCategory.Line.LocationLineByBasePoint &&
       line.getLocationMode() == Constant.angleLocationMode
     ) {
       let point1 = {
@@ -157,6 +163,71 @@ export default class MoveLine {
       point2 = mathUtil.getJoinLinePoint(endPoint, lineGeometry);
       endPoint.x = point2.x;
       endPoint.y = point2.y;
+    } else if (
+      line.getCategory() == VectorCategory.Line.LocationLineByFixPoint &&
+      line.getLocationMode() == Constant.angleLocationMode
+    ) {
+      let point1 = {
+        x: startPoint.x + dx,
+        y: startPoint.y + dy,
+      };
+      let point2 = {
+        x: endPoint.x + dx,
+        y: endPoint.y + dy,
+      };
+      let lineGeometry = mathUtil.createLine1(point1, point2);
+      point1 = mathUtil.getJoinLinePoint(startPoint, lineGeometry);
+      if (startPoint.getCategory() == VectorCategory.Point.FixPoint) {
+        //达到一定距离才能移动
+        if (mathUtil.getDistance(startPoint, point1) < Constant.minAdsorbPix) {
+          return false;
+        }
+        let newStartPoint = pointService.create(point1);
+        let extendedPositionLine = lineService.createByPointId(
+          startPoint.vectorId,
+          newStartPoint.vectorId,
+          VectorCategory.Line.ExtendedPositionLine
+        );
+        extendedPositionLine.setLocationMode(Constant.angleLocationMode);
+        dataService.deletePointParent(startPoint.vectorId, lineId);
+        line.startId = newStartPoint.vectorId;
+        newStartPoint.setPointParent(line.vectorId, "start");
+        newStartPoint.setCategory(VectorCategory.Point.TestBasePoint);
+        let join = mathUtil.getIntersectionPoint(lineGeometry, baseLine);
+        mathUtil.clonePoint(endPoint, join);
+      } else {
+        let extendedPositionLine = mathUtil.createLine3(baseLine, startPoint);
+        let join = mathUtil.getIntersectionPoint(
+          lineGeometry,
+          extendedPositionLine
+        );
+        mathUtil.clonePoint(startPoint, join);
+        join = mathUtil.getIntersectionPoint(lineGeometry, baseLine);
+        mathUtil.clonePoint(endPoint, join);
+
+        let parent = startPoint.getParent();
+        for (let key in parent) {
+          if (key == lineId) {
+            continue;
+          } else {
+            extendedPositionLine = dataService.getLine(key);
+          }
+        }
+        startPoint = dataService.getPoint(extendedPositionLine.startId);
+        if (mathUtil.getDistance(point1, startPoint) < Constant.minAdsorbPix) {
+          let otherPointId = extendedPositionLine.getOtherPointId(
+            startPoint.vectorId
+          );
+          let otherPoint = dataService.getPoint(otherPointId);
+          if (startPoint.getCategory() == VectorCategory.Point.FixPoint) {
+            dataService.deleteLine(extendedPositionLine.vectorId);
+            dataService.deletePoint(otherPoint.vectorId);
+            line.startId = startPoint.vectorId;
+          }
+          join = mathUtil.getJoinLinePoint(startPoint, baseLine);
+          mathUtil.clonePoint(endPoint, join);
+        }
+      }
     } else {
       //综合定位和垂线定位,拖动基准线更新位置
       //缺

+ 108 - 29
src/graphic/Controls/MovePoint.js

@@ -10,30 +10,42 @@ import { mathUtil } from "../Util/MathUtil";
 export default class MovePoint {
   constructor() {}
 
+  // movePoint(position, pointId) {
+  //   let point = dataService.getPoint(pointId);
+  //   point.x = position.x;
+  //   point.y = position.y;
+  //   if (point.getCategory() == VectorCategory.Point.TestPoint) {
+  //     this.updatePositionByTestPoint(pointId);
+  //   } else if (point.getCategory() == VectorCategory.Point.BasePoint) {
+  //     this.updateBasePoint(pointId);
+  //   } else {
+  //     let parent = point.getParent();
+  //     for (let key in parent) {
+  //       let line = dataService.getLine(key);
+  //       line.setValue(null);
+  //       //拖拽的点是基准线
+  //       if (line.category == VectorCategory.Line.BaseLine) {
+  //         let points = dataService.getPoints();
+  //         for (let key in points) {
+  //           let testPoint = dataService.getPoint(key);
+  //           if (testPoint.category == VectorCategory.Point.TestPoint) {
+  //             this.updatePositionByTestPoint(key);
+  //           }
+  //         }
+  //       }
+  //     }
+  //   }
+  // }
+
   movePoint(position, pointId) {
     let point = dataService.getPoint(pointId);
-    point.x = position.x;
-    point.y = position.y;
-    if (point.getCategory() == VectorCategory.Point.TestPoint) {
-      this.updatePositionByTestPoint(pointId);
-    } else if (point.getCategory() == VectorCategory.Point.BasePoint) {
-      this.updateBasePoint(pointId);
+    if (point.getCategory() == VectorCategory.Point.BasePoint) {
+      this.updateBasePoint(position, pointId);
+    } else if (point.getCategory() == VectorCategory.Point.FixPoint) {
+      this.updateFixPoint(position, pointId);
     } else {
-      let parent = point.getParent();
-      for (let key in parent) {
-        let line = dataService.getLine(key);
-        line.setValue(null);
-        //拖拽的点是基准线
-        if (line.category == VectorCategory.Line.BaseLine) {
-          let points = dataService.getPoints();
-          for (let key in points) {
-            let testPoint = dataService.getPoint(key);
-            if (testPoint.category == VectorCategory.Point.TestPoint) {
-              this.updatePositionByTestPoint(key);
-            }
-          }
-        }
-      }
+      point.x = position.x;
+      point.y = position.y;
     }
   }
 
@@ -213,17 +225,84 @@ export default class MovePoint {
     mathUtil.clonePoint(testBasePoint, join);
   }
 
-  updateBasePoint(basePointId) {
-    let points = dataService.getPoints();
-    for (let key in points) {
-      let point = dataService.getPoint(key);
-      if (
-        point.getCategory() == VectorCategory.Point.TestPoint &&
-        point.getLinkedBasePointId() == basePointId
+  // updateBasePoint(basePointId) {
+  //   let points = dataService.getPoints();
+  //   for (let key in points) {
+  //     let point = dataService.getPoint(key);
+  //     if (
+  //       point.getCategory() == VectorCategory.Point.TestPoint &&
+  //       point.getLinkedBasePointId() == basePointId
+  //     ) {
+  //       this.updatePositionByTestPoint(key);
+  //     }
+  //   }
+  // }
+
+  updateBasePoint(position, basePointId) {
+    let lineGeometry = dataService.getLine(Settings.baseLineId);
+    let startPoint = dataService.getPoint(lineGeometry.startId);
+    let endPoint = dataService.getPoint(lineGeometry.endId);
+    lineGeometry = mathUtil.createLine1(startPoint, endPoint);
+    let basePoint = dataService.getPoint(basePointId);
+    let parent = basePoint.getParent();
+    for (let key in parent) {
+      let line = dataService.getLine(key);
+      if (line.getCategory() == VectorCategory.Line.LocationLineByBasePoint) {
+        let otherPointId = line.getOtherPointId(basePointId);
+        let otherPoint = dataService.getPoint(otherPointId);
+        let otherLine = mathUtil.getLineForPoint(lineGeometry, otherPoint);
+        line = mathUtil.createLine3(lineGeometry, position);
+        let join = mathUtil.getIntersectionPoint(line, otherLine);
+        mathUtil.clonePoint(otherPoint, join);
+        mathUtil.clonePoint(basePoint, position);
+      } else if (
+        line.getCategory() == VectorCategory.Line.ExtendedPositionLine
       ) {
-        this.updatePositionByTestPoint(key);
+        let otherPointId = line.getOtherPointId(basePointId);
+        let otherPoint = dataService.getPoint(otherPointId);
+        let otherLine = mathUtil.createLine3(lineGeometry, otherPoint);
+        let join = mathUtil.getJoinLinePoint(position, otherLine);
+        mathUtil.clonePoint(otherPoint, join);
+        mathUtil.clonePoint(basePoint, position);
+      }
+    }
+  }
+
+  updateFixPoint(position, fixPointId) {
+    let fixPoint = dataService.getPoint(fixPointId);
+    let basePoint = dataService.getPoint(fixPoint.linkedBasePointId);
+    let baseLine = dataService.getLine(Settings.baseLineId);
+    let startPoint = dataService.getPoint(baseLine.startId);
+    let endPoint = dataService.getPoint(baseLine.endId);
+
+    let baseLineGeometry = mathUtil.createLine1(startPoint, endPoint);
+    let vLine = mathUtil.getVerticalLine(baseLineGeometry, position);
+    let join = mathUtil.getIntersectionPoint(baseLineGeometry, vLine);
+
+    let parent = fixPoint.getParent();
+    for (let key in parent) {
+      let line = dataService.getLine(key);
+      if (line.getCategory() == VectorCategory.Line.LocationLineByFixPoint) {
+        let otherPointId = line.getOtherPointId(fixPointId);
+        let otherPoint = dataService.getPoint(otherPointId);
+        mathUtil.clonePoint(otherPoint, join);
+      } else if (line.getCategory() == VectorCategory.Line.GuideLocationLine) {
+        let otherPointId = line.getOtherPointId(fixPointId);
+        let otherPoint = dataService.getPoint(otherPointId);
+        let line2 = mathUtil.createLine3(baseLineGeometry, otherPoint);
+        join = mathUtil.getIntersectionPoint(line2, vLine);
+        mathUtil.clonePoint(otherPoint, join);
+      } else if (
+        line.getCategory() == VectorCategory.Line.ExtendedPositionLine
+      ) {
+        let otherPointId = line.getOtherPointId(fixPointId);
+        let otherPoint = dataService.getPoint(otherPointId);
+        let line2 = mathUtil.createLine3(baseLineGeometry, fixPoint);
+        join = mathUtil.getJoinLinePoint(otherPoint, line2);
+        mathUtil.clonePoint(otherPoint, join);
       }
     }
+    mathUtil.clonePoint(fixPoint, position);
   }
 
   /*****************************************************************************曲线上的点********************************************************************************/

+ 5 - 0
src/graphic/Controls/UIControl.js

@@ -30,6 +30,7 @@ import Message from "@/components/base/components/message/message.vue";
 import { pointService } from "../Service/PointService.js";
 import Settings from "../Settings.js";
 import { addPoint } from "./AddPoint.js";
+import { locationModeControl } from "./LocationModeControl.js";
 import { curveRoadPointService } from "../Service/CurveRoadPointService.js";
 import { roadService } from "../Service/RoadService.js";
 import { curveRoadService } from "../Service/CurveRoadService.js";
@@ -115,6 +116,10 @@ export default class UIControl {
           stateService.setEventName(LayerEvents.AddRoadTemplate);
         } else if (uiService.isBelongRoadStructure(selectUI)) {
           stateService.setEventName(LayerEvents.AddRoadStructure);
+        } else if (selectUI == Constant.angleLocationMode) {
+          locationModeControl.setAngle();
+          this.layer.history.save();
+          this.layer.renderer.autoRedraw();
         }
       }
     }

+ 10 - 0
src/graphic/Geometry/Line.js

@@ -37,4 +37,14 @@ export default class Line extends Geometry {
       return null;
     }
   }
+
+  getOtherPointId(pointId) {
+    if (this.startId == pointId) {
+      return this.endId;
+    } else if (this.endId == pointId) {
+      return this.startId;
+    } else {
+      return null;
+    }
+  }
 }

+ 1 - 1
src/graphic/Layer.js

@@ -835,7 +835,7 @@ export default class Layer {
           point = dataService.getPoint(draggingItem.vectorId);
           listenLayer.start(position, {
             exceptPointId: draggingItem.vectorId,
-            exceptLineId: point.parent,
+            exceptLineIds: point.parent,
           });
 
           // if (listenLayer.modifyPoint) {  //原本是这样的,不知用途,下面修改为了修复拖动点经过放大镜导致NaN或者错位

+ 21 - 3
src/graphic/ListenLayer.js

@@ -62,7 +62,8 @@ export default class ListenLayer {
     );
     selectInfo.pointInfo = this.isSelectPoint(
       position,
-      exceptVectorIds.exceptPointId
+      exceptVectorIds.exceptPointId,
+      exceptVectorIds.exceptLineIds
     );
     selectInfo.lineInfo = this.isSelectLine(
       position,
@@ -221,17 +222,32 @@ export default class ListenLayer {
     return curveLineInfo;
   }
 
-  isSelectPoint(position, exceptPointId) {
+  isSelectPoint(position, exceptPointId, exceptLineIds) {
     let pointInfo = {
       pointId: null,
       type: null,
       distance: null,
     };
 
+    let exceptPointIds = [];
+    if (exceptPointId) {
+      exceptPointIds.push(exceptPointId);
+    }
+    if (exceptLineIds) {
+      for (let key in exceptLineIds) {
+        let exceptLine = dataService.getLine(key);
+        exceptPointIds.push(exceptLine.startId);
+        exceptPointIds.push(exceptLine.endId);
+      }
+    }
+
     let seqInfo = {};
     const points = dataService.getPoints();
     for (const pointId in points) {
-      if (pointId == exceptPointId) {
+      // if (pointId == exceptPointId) {
+      //   continue;
+      // }
+      if (exceptPointIds.indexOf(pointId) > -1) {
         continue;
       }
       const point = dataService.getPoint(pointId);
@@ -323,6 +339,8 @@ export default class ListenLayer {
 
       const line = dataService.getLine(lineId);
       if (
+        line.getCategory() == VectorCategory.Line.ExtendedPositionLine ||
+        line.getCategory() == VectorCategory.Line.GuideLocationLine ||
         line.getCategory() == VectorCategory.Line.GuidePositionLine ||
         (line.getCategory() == VectorCategory.Line.PositionLine &&
           line.getLocationMode() != Constant.angleLocationMode)

+ 7 - 9
src/graphic/Service/DataService.js

@@ -138,15 +138,13 @@ export class DataService {
       return;
     }
     let start = this.getPoint(line.startId);
-    if (start && start.getCategory() != VectorCategory.Point.BasePoint) {
-      let startParent = start.getParent();
-      delete startParent[lineId];
-      if (
-        Object.keys(startParent).length == 0 &&
-        start.getCategory() != VectorCategory.Point.BasePoint
-      ) {
-        this.deletePoint(line.startId);
-      }
+    let startParent = start.getParent();
+    delete startParent[lineId];
+    if (
+      Object.keys(startParent).length == 0 &&
+      start.getCategory() != VectorCategory.Point.BasePoint
+    ) {
+      this.deletePoint(line.startId);
     }
 
     let end = this.getPoint(line.endId);

+ 21 - 13
src/graphic/Service/UIService.js

@@ -93,19 +93,27 @@ export default class UIService {
   }
 
   isBelongPoint(ui) {
-    if (ui == UIEvents.NormalLocationMode) {
-      this.setSelectPointCategory(VectorCategory.Point.TestPoint);
-      this.setSelectLocationMode(Constant.normalLocationMode);
-      return true;
-    } else if (ui == UIEvents.AngleLocationMode) {
-      this.setSelectPointCategory(VectorCategory.Point.TestPoint);
-      this.setSelectLocationMode(Constant.angleLocationMode);
-      return true;
-    } else if (ui == UIEvents.AllLocationMode) {
-      this.setSelectPointCategory(VectorCategory.Point.TestPoint);
-      this.setSelectLocationMode(Constant.allLocationMode);
-      return true;
-    } else if (ui == UIEvents.BasePoint) {
+    // if (ui == UIEvents.NormalLocationMode) {
+    //   this.setSelectPointCategory(VectorCategory.Point.TestPoint);
+    //   this.setSelectLocationMode(Constant.normalLocationMode);
+    //   return true;
+    // } else if (ui == UIEvents.AngleLocationMode) {
+    //   this.setSelectPointCategory(VectorCategory.Point.TestPoint);
+    //   this.setSelectLocationMode(Constant.angleLocationMode);
+    //   return true;
+    // } else if (ui == UIEvents.AllLocationMode) {
+    //   this.setSelectPointCategory(VectorCategory.Point.TestPoint);
+    //   this.setSelectLocationMode(Constant.allLocationMode);
+    //   return true;
+    // } else if (ui == UIEvents.BasePoint) {
+    //   this.setSelectPointCategory(VectorCategory.Point.BasePoint);
+    //   this.setSelectLocationMode(null);
+    //   return true;
+    // } else if (ui == UIEvents.FixPoint) {
+    //   this.setSelectPointCategory(VectorCategory.Point.FixPoint);
+    //   return true;
+    // }
+    if (ui == UIEvents.BasePoint) {
       this.setSelectPointCategory(VectorCategory.Point.BasePoint);
       this.setSelectLocationMode(null);
       return true;

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

@@ -384,11 +384,9 @@ export default class MathUtil {
     let parameter = {};
     if (line.a == 0 || typeof line.a == "undefined") {
       if (line.hasOwnProperty("x")) {
-        parameter.x = line.x;
         parameter.y = point.y;
       } else if (line.hasOwnProperty("y")) {
         parameter.x = point.x;
-        parameter.y = line.y;
       }
     } else {
       parameter.a = -1 / line.a;

+ 1 - 1
src/graphic/enum/VectorCategory.js

@@ -16,7 +16,7 @@ const VectorCategory = {
     //重做定位
     GuideLocationLine: "GuideLocationLine", //定位辅助线
     LocationLineByFixPoint: "LocationLineByFixPoint", //经过固定点的定位线
-    LocationLineByBasePoint: "LocationLineByFixPoint", //经过基础点的定位线
+    LocationLineByBasePoint: "LocationLineByBasePoint", //经过基础点的定位线
     LocationLineByFixPointToFixPoint: "LocationLineByFixPointToFixPoint", //经过固定点到固定点的定位线,综合定位法
     LocationLineByFixPointToBasePoint: "LocationLineByFixPointToBasePoint", //经过固定点到基础点的定位线,综合定位法
   },