xushiting 2 년 전
부모
커밋
c9c49efaf5

+ 11 - 0
src/graphic/Controls/AddLine.js

@@ -2,11 +2,14 @@ import { dataService } from "../Service/DataService";
 import { lineService } from "../Service/LineService";
 import { listenLayer } from "../ListenLayer";
 import VectorCategory from "../enum/VectorCategory";
+import Point from "../Geometry/Point.js";
+import { mathUtil } from "../Util/MathUtil";
 
 export default class AddLine {
   constructor() {
     this.startInfo = {};
     this.endInfo = {};
+    this.baseLineId = null;
     this.category = VectorCategory.Line.NormalLine;
   }
 
@@ -61,6 +64,14 @@ export default class AddLine {
     this.clear();
   }
 
+  setBaseLineId(baseLineId) {
+    this.baseLineId = baseLineId;
+  }
+
+  getBaseLineId() {
+    return this.baseLineId;
+  }
+
   clear() {
     this.startInfo = {};
     this.endInfo = {};

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

@@ -0,0 +1,85 @@
+import { dataService } from "../Service/DataService";
+import { lineService } from "../Service/LineService";
+import { pointService } from "../Service/PointService";
+import VectorCategory from "../enum/VectorCategory";
+import Point from "../Geometry/Point.js";
+import { mathUtil } from "../Util/MathUtil";
+import addLine from "./AddLine";
+
+export default class AddPoint {
+  constructor() {}
+
+  //直角定位法
+  setLocationByAngle(testPointId, basePointId) {
+    if (testPointId == null || basePointId == null) {
+      return null;
+    }
+    let testPoint = dataService.getPoint(testPointId);
+    let basePoint = dataService.getPoint(basePointId);
+    let lineGeometry = dataService.getLine(addLine.baseLineId);
+    let startPoint = dataService.getPoint(lineGeometry.startId);
+    let endPoint = dataService.getPoint(lineGeometry.endId);
+    let line = mathUtil.createLine1(startPoint, endPoint);
+    let vLine1 = mathUtil.getVerticalLine(line, testPoint);
+    let join = mathUtil.getJoinLinePoint(basePoint, vLine1);
+    join = pointService.addPoint(join, VectorCategory.Point.TestBasePoint);
+
+    lineService.createByPointId(
+      testPointId,
+      join.vectorId,
+      VectorCategory.Line.PositionLine
+    );
+
+    lineService.createByPointId(
+      basePointId,
+      join.vectorId,
+      VectorCategory.Line.PositionLine
+    );
+  }
+
+  //综合定位法
+  setLocationByFull(testPointId1, testPointId2, basePointId) {
+    if (testPointId1 == null || basePointId == null) {
+      return null;
+    } else {
+      let testPoint1 = dataService.getPoint(testPointId1);
+      let lineGeometry = dataService.getLine(addLine.baseLineId);
+      let startPoint = dataService.getPoint(lineGeometry.startId);
+      let endPoint = dataService.getPoint(lineGeometry.endId);
+      let line = mathUtil.createLine1(startPoint, endPoint);
+      if (testPointId2 == null) {
+        let join = mathUtil.getJoinLinePoint(testPoint1, line);
+        join = pointService.addPoint(join, VectorCategory.Point.TestBasePoint);
+        lineService.createByPointId(
+          testPointId1,
+          join.vectorId,
+          VectorCategory.Line.PositionLine
+        );
+
+        lineService.createByPointId(
+          basePointId,
+          testPointId1,
+          VectorCategory.Line.PositionLine
+        );
+      } else {
+        let testPoint2 = dataService.getPoint(testPointId2);
+        let join = mathUtil.getJoinLinePoint(testPoint2, line);
+        join = pointService.addPoint(join, VectorCategory.Point.TestBasePoint);
+        lineService.createByPointId(
+          testPointId2,
+          join.vectorId,
+          VectorCategory.Line.PositionLine
+        );
+
+        lineService.createByPointId(
+          testPointId2,
+          testPointId1,
+          VectorCategory.Line.PositionLine
+        );
+      }
+    }
+  }
+}
+
+const addPoint = new AddPoint();
+export { addPoint };

+ 6 - 0
src/graphic/Geometry/Point.js

@@ -7,6 +7,7 @@ export default class Point extends Geometry {
     this.x = null;
     this.y = null;
     this.parent = {};
+    this.category = null;
     this.geoType = VectorType.Point;
     this.setId(vectorId);
 
@@ -17,4 +18,9 @@ export default class Point extends Geometry {
     this.x = position.x;
     this.y = position.y;
   }
+
+  //基准点:BasePoint
+  setCategory(value) {
+    this.category = value;
+  }
 }

+ 21 - 1
src/graphic/Service/DataService.js

@@ -485,7 +485,27 @@ export class DataService {
   }
 
   clear() {
-    this.vectorData = {};
+    //直路
+    this.vectorData.roadPoints = {};
+    this.vectorData.roads = {};
+    this.vectorData.roadEdges = {};
+    //弯路
+    this.vectorData.curveRoadPoints = {};
+    this.vectorData.curveRoads = {};
+    this.vectorData.curveRoadEdges = {};
+    //直路交叉的时候,产生的曲线控制点
+    this.vectorData.controlPoints = {};
+    //直线,起点和终点都是point的id
+    this.vectorData.lines = {};
+    //弯曲线条
+    this.vectorData.curvelines = {};
+    //线段(完全或者直线)上的端点
+    this.vectorData.points = {};
+    this.vectorData.circles = {};
+    //基准点
+    this.vectorData.basePointIds = [];
+    this.vectorData.texts = {};
+    this.vectorData.SVGs = {};
   }
 }
 

+ 14 - 0
src/graphic/Service/LineService.js

@@ -3,6 +3,7 @@ import Line from "../Geometry/Line.js";
 import { dataService } from "./DataService.js";
 import VectorCategory from "../enum/VectorCategory.js";
 import { mathUtil } from "../Util/MathUtil.js";
+
 export default class LineService {
   constructor() {}
 
@@ -23,6 +24,19 @@ export default class LineService {
     dataService.addLine(line);
     return line;
   }
+
+  createByPointId(startId, endId, category, vectorId) {
+    let line = new Line(startId, endId, vectorId);
+    if (category) {
+      line.setCategory(category);
+    }
+    let start = dataService.getPoint(startId);
+    let end = dataService.getPoint(endId);
+    start.setPointParent(line.vectorId, "start");
+    end.setPointParent(line.vectorId, "end");
+    dataService.addLine(line);
+    return line;
+  }
 }
 
 const lineService = new LineService();

+ 17 - 0
src/graphic/Service/PointService.js

@@ -0,0 +1,17 @@
+import Point from "../Geometry/Point.js";
+import Line from "../Geometry/Line.js";
+import { dataService } from "./DataService.js";
+import VectorCategory from "../enum/VectorCategory.js";
+import { mathUtil } from "../Util/MathUtil.js";
+export default class PointService {
+  constructor() {}
+
+  addPoint(position, categoryType) {
+    let point = new Point(position);
+    point.setCategory(categoryType);
+    dataService.addPoint(point);
+  }
+}
+
+const pointService = new PointService();
+export { pointService };

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

@@ -4,9 +4,13 @@ const VectorCategory = {
     BaseLine: "BaseLine",
     MeasureLine: "MeasureLine",
     GuideLine: "GuideLine",
+    PositionLine: "PositionLine", //定位线。与定位法相关的
   },
   Point: {
-    BasePoint: "BasePoint",
+    BasePoint: "BasePoint", //基准点
+    TestPoint: "TestPoint", //待测点
+    NormalPoint: "NormalPoint", //正常点
+    TestBasePoint: "TestBasePoint", //待测基准点
   },
 };
 export default VectorCategory;