xushiting 2 лет назад
Родитель
Сommit
01a7cf4ea7

+ 12 - 0
src/graphic/Controls/AddCircle.js

@@ -1,4 +1,5 @@
 import { mathUtil } from "../Util/MathUtil";
+import { circleService } from "../Service/CircleService";
 
 export default class AddCircle {
   constructor() {
@@ -14,6 +15,17 @@ export default class AddCircle {
   setRadius(value) {
     this.radius = value;
   }
+
+  buildCircle() {
+    circleService.create(this.center, this.radius);
+    listenLayer.clear();
+    this.clear();
+  }
+
+  clear() {
+    this.center = null;
+    this.radius = null;
+  }
 }
 
 const addCircle = new AddCircle();

+ 8 - 1
src/graphic/Controls/AddLine.js

@@ -1,11 +1,13 @@
 import { dataService } from "../Service/DataService";
 import { lineService } from "../Service/LineService";
 import { listenLayer } from "../ListenLayer";
+import VectorCategory from "../enum/VectorCategory";
 
 export default class AddLine {
   constructor() {
     this.startInfo = {};
     this.endInfo = {};
+    this.simpleLineCategory = VectorCategory.Line.NormalLine;
   }
 
   setPointInfo(dir, pointInfo) {
@@ -50,8 +52,13 @@ export default class AddLine {
   }
 
   buildLine() {
-    lineService.create(this.startInfo.position, this.endInfo.position);
+    lineService.createSimpleLine(
+      this.startInfo.position,
+      this.endInfo.position,
+      this.simpleLineCategory
+    );
     listenLayer.clear();
+    this.clear();
   }
 
   clear() {

+ 5 - 1
src/graphic/Controls/AddRoad.js

@@ -40,7 +40,10 @@ export default class AddRoad {
   }
 
   buildRoad() {
-    console.log("添加路段!");
+    console.log("添加路!");
+    if (mathUtil.clonePoint(this.startInfo.position, this.endInfo.position)) {
+      return null;
+    }
     let joinInfos = this.getJoinsForRoads();
     let splitPointIds = this.splitAllJoins(joinInfos);
     this.creatNewRoads(splitPointIds);
@@ -62,6 +65,7 @@ export default class AddRoad {
       }
     }
     listenLayer.clear();
+    this.clear();
   }
 
   //开始新建公路,可能是多个

+ 1 - 1
src/graphic/Geometry/SimpleLine.js

@@ -13,7 +13,7 @@ export default class SimpleLine extends Geometry {
     this.setPositions(start, end);
   }
 
-  //GuideLine,MeasureLine,BaseLine
+  //NormalLine,GuideLine,MeasureLine,BaseLine
   setCategory(value) {
     this.category = value;
   }

+ 45 - 4
src/graphic/Layer.js

@@ -26,6 +26,7 @@ import { roadService } from "./Service/RoadService";
 import { edgeService } from "./Service/EdgeService";
 import { roadPointService } from "./Service/RoadPointService";
 import { curveRoadService } from "./Service/CurveRoadService";
+import VectorCategory from "./enum/VectorCategory";
 
 const minDragDis = 10;
 
@@ -215,12 +216,29 @@ export default class Layer {
           };
         }
 
-        elementService.execute(addLine.startInfo.position, position);
+        elementService.hideAll();
         elementService.setPoint(position);
-        elementService.setNewRoad(addLine.startInfo.position, position);
-        elementService.showNewRoad();
+        elementService.showPoint();
+        if (listenLayer.modifyPoint) {
+          elementService.execute(listenLayer.modifyPoint, position);
+        }
+        break;
+      case LayerEvents.AddCircle:
+        needAutoRedraw = true;
+        listenLayer.start(position);
+        if (listenLayer.modifyPoint) {
+          position = {
+            x: listenLayer.modifyPoint.x,
+            y: listenLayer.modifyPoint.y,
+          };
+        }
 
-        addLine.setNewLinePoint("end", position);
+        elementService.hideAll();
+        elementService.setPoint(position);
+        elementService.showPoint();
+        if (listenLayer.modifyPoint) {
+          elementService.execute(listenLayer.modifyPoint, position);
+        }
         break;
       case LayerEvents.AddingRoad:
         needAutoRedraw = true;
@@ -257,9 +275,23 @@ export default class Layer {
         elementService.execute(addLine.startInfo.position, position);
         elementService.setPoint(position);
         elementService.setNewLine(addLine.startInfo.position, position);
+        elementService.setNewLineCategory(VectorCategory.Line.NormalLine);
         elementService.showNewLine();
         addLine.setNewLinePoint("end", position);
         break;
+      case LayerEvents.AddingCircle:
+        needAutoRedraw = true;
+        listenLayer.start(position);
+        if (listenLayer.modifyPoint) {
+          position = {
+            x: listenLayer.modifyPoint.x,
+            y: listenLayer.modifyPoint.y,
+          };
+        }
+        elementService.execute(addCircle.center, position);
+        elementService.setPoint(position);
+        addCircle.setRadius(mathUtil.getDistance(addCircle.center, position));
+        break;
       case LayerEvents.MoveRoad:
         needAutoRedraw = true;
         //只允许拖拽一条公路
@@ -566,6 +598,13 @@ export default class Layer {
         this.history.save();
         elementService.hideAll();
         break;
+      case LayerEvents.AddingCircle:
+        needAutoRedraw = true;
+        addCircle.buildCircle();
+        addCircle.clear();
+        this.history.save();
+        elementService.hideAll();
+        break;
       // case LayerEvents.AddCurveRoad:
       //   addRoad.setNewRoadPoint("start", position);
       //   break;
@@ -838,6 +877,8 @@ export default class Layer {
           stateService.setEventName(LayerEvents.MoveLine);
         } else if (selectItem.type == VectorType.CurveLine) {
           stateService.setEventName(LayerEvents.MoveCurveLine);
+        } else if (selectItem.type == VectorType.Circle) {
+          stateService.setEventName(LayerEvents.MoveCircle);
         }
       }
     } else if (eventType == "mouseUp") {

+ 22 - 0
src/graphic/Service/CircleService.js

@@ -0,0 +1,22 @@
+import Point from "../Geometry/Point.js";
+import Circle from "../Geometry/Circle.js";
+import SimpleLine from "../Geometry/SimpleLine.js";
+import { dataService } from "./DataService.js";
+import VectorCategory from "../enum/VectorCategory.js";
+import { mathUtil } from "../Util/MathUtil.js";
+import Constant from "../Constant.js";
+export default class CircleService {
+  constructor() {}
+
+  create(center, radius, vectorId) {
+    if (!center || !radius || radius < Constant.minAdsorbPix / 2) {
+      return null;
+    }
+    let circle = new Circle(center, radius, vectorId);
+    dataService.addCircle(circle);
+    return circle;
+  }
+}
+
+const circleService = new CircleService();
+export { circleService };

+ 5 - 4
src/graphic/Service/ElementService.js

@@ -37,10 +37,7 @@ export class ElementService {
     this.newRoad.name = ElementEvents.NewRoad;
 
     this.newLine = new SimpleLine({ x: 0, y: 0 }, { x: 1, y: 1 });
-    this.newLine.setCategory(VectorCategory.Line.GuideLine);
-    this.newLine.name = ElementEvents.NewLine;
-
-    this.newLine = new SimpleLine({ x: 0, y: 0 }, { x: 1, y: 1 });
+    this.newLine.setCategory(VectorCategory.Line.NormalLine);
     this.newLine.name = ElementEvents.NewLine;
 
     this.checkLines.X = new SimpleLine({ x: 0, y: 0 }, { x: 1, y: 1 });
@@ -100,6 +97,10 @@ export class ElementService {
     return this.newRoad;
   }
 
+  setNewLineCategory(value) {
+    this.newLine.setCategory(value);
+  }
+
   showPoint() {
     this.point.display = true;
   }

+ 17 - 1
src/graphic/Service/LineService.js

@@ -1,10 +1,16 @@
 import Point from "../Geometry/Point.js";
 import Line from "../Geometry/Line.js";
+import SimpleLine from "../Geometry/SimpleLine.js";
 import { dataService } from "./DataService.js";
+import VectorCategory from "../enum/VectorCategory.js";
+import { mathUtil } from "../Util/MathUtil.js";
 export default class LineService {
   constructor() {}
 
-  create(startPoint, endPoint, vectorId) {
+  createLine(startPoint, endPoint) {
+    if (!startPoint || !endPoint || mathUtil.equalPoint(startPoint, endPoint)) {
+      return null;
+    }
     let start = new Point(startPoint);
     let end = new Point(endPoint);
     let line = new Line(start.vectorId, end.vectorId, vectorId);
@@ -15,6 +21,16 @@ export default class LineService {
     dataService.addLine(line);
     return line;
   }
+
+  createSimpleLine(startPoint, endPoint, category, vectorId) {
+    if (!startPoint || !endPoint || mathUtil.equalPoint(startPoint, endPoint)) {
+      return null;
+    }
+    let simpleLineline = new SimpleLine(startPoint, endPoint, vectorId);
+    simpleLineline.setCategory(category);
+    dataService.addLine(simpleLineline);
+    return simpleLineline;
+  }
 }
 
 const lineService = new LineService();

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

@@ -1,5 +1,6 @@
 const VectorCategory = {
   Line: {
+    NormalLine: "NormalLine",
     BaseLine: "BaseLine",
     MeasureLine: "MeasureLine",
     GuideLine: "GuideLine",