Explorar el Código

准备修改正在绘制道路的逻辑。将缓存的道路去掉(ElementService里将没有newRoad),提前保存一下。

xushiting hace 2 años
padre
commit
34f331afef

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

@@ -77,6 +77,12 @@ export default class AddLine {
     return this.baseLineId;
   }
 
+  clearVectorData() {
+    this.newLine = null;
+    this.startInfo = {};
+    this.baseLineId = null;
+  }
+
   clear() {
     this.newLine = null;
     this.startInfo = {};

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

@@ -75,6 +75,9 @@ export default class UIControl {
           stateService.setEventName(LayerEvents.AddCurveRoad);
         } else if (selectUI == UIEvents.Arrow) {
           stateService.setEventName(LayerEvents.AddLine);
+          addLine.setCategory(VectorCategory.Line.ArrowLine);
+        } else if (selectUI == UIEvents.MeasureLine) {
+          stateService.setEventName(LayerEvents.AddLine);
           addLine.setCategory(VectorCategory.Line.MeasureLine);
         } else if (selectUI == UIEvents.Line) {
           stateService.setEventName(LayerEvents.AddLine);

+ 5 - 7
src/graphic/Layer.js

@@ -311,10 +311,6 @@ 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();
-
         if (addLine.newLine == null) {
           addLine.buildLine(position);
         } else {
@@ -684,7 +680,7 @@ export default class Layer {
       case LayerEvents.AddingLine:
         needAutoRedraw = true;
         addLine.finish(position);
-        addLine.clear();
+        addLine.clearVectorData();
         this.history.save();
         elementService.hideAll();
         break;
@@ -754,7 +750,9 @@ export default class Layer {
 
     this.setEventName("mouseUp");
     stateService.clearDraggingItem();
-    this.renderer.autoRedraw();
+    if (needAutoRedraw) {
+      this.renderer.autoRedraw();
+    }
   }
 
   onWheel(e) {
@@ -1026,7 +1024,7 @@ export default class Layer {
     } else if (eventName == LayerEvents.AddingLine) {
       stateService.setEventName(LayerEvents.AddLine);
     }
-
+    addLine.clear(); //之前会保留category
     this.uiControl.clearUI();
     elementService.hideAll();
   }

+ 1 - 73
src/graphic/Service/ElementService.js

@@ -13,11 +13,6 @@ import { coordinate } from "../Coordinate.js";
 export class ElementService {
   constructor() {
     this.point = null;
-
-    this.newLine = null;
-    this.newLineStart = null;
-    this.newLineEnd = null;
-
     this.newRoad = null;
 
     this.checkLinesXStart = null;
@@ -47,15 +42,6 @@ export class ElementService {
     this.newRoad = this.createTempRoad();
     this.newRoad.name = ElementEvents.NewRoad;
 
-    this.newLineStart = new Point({ x: 0, y: 0 });
-    this.newLineEnd = new Point({ x: 1, y: 1 });
-    this.newLine = new Line(
-      this.newLineStart.vectorId,
-      this.newLineEnd.vectorId
-    );
-    this.newLine.setCategory(VectorCategory.Line.NormalLine);
-    this.newLine.name = ElementEvents.NewLine;
-
     this.checkLinesXStart = new Point({ x: 0, y: 0 });
     this.checkLinesXEnd = new Point({ x: 1, y: 1 });
     this.checkLines.X = new Line(
@@ -96,11 +82,7 @@ export class ElementService {
   }
 
   getPoint(vectorId) {
-    if (this.newLineStart.vectorId == vectorId) {
-      return this.newLineStart;
-    } else if (this.newLineEnd.vectorId == vectorId) {
-      return this.newLineEnd;
-    } else if (this.checkLinesXStart.vectorId == vectorId) {
+    if (this.checkLinesXStart.vectorId == vectorId) {
       return this.checkLinesXStart;
     } else if (this.checkLinesXEnd.vectorId == vectorId) {
       return this.checkLinesXEnd;
@@ -166,10 +148,6 @@ export class ElementService {
     return this.newRoad;
   }
 
-  setNewLineCategory(value) {
-    this.newLine.setCategory(value);
-  }
-
   showPoint() {
     this.point.display = true;
   }
@@ -211,19 +189,6 @@ export class ElementService {
     }
   }
 
-  setNewLine(point1, point2) {
-    this.newLineStart.setPosition(point1);
-    this.newLineEnd.setPosition(point2);
-  }
-
-  showNewLine() {
-    this.newLine.display = true;
-  }
-
-  hideNewLine() {
-    this.newLine.display = false;
-  }
-
   setNewRoadState(state) {
     this.newRoad.state = state;
   }
@@ -285,7 +250,6 @@ export class ElementService {
     this.hideCheckLinesY();
     this.hidePoint();
     this.hideNewRoad();
-    this.hideNewLine();
     this.hideVCheckLinesX();
     this.hideVCheckLinesY();
   }
@@ -374,42 +338,6 @@ export class ElementService {
       }
     }
   }
-
-  // //pointId是角度的顶点
-  // //exceptPointId表示position对应的pointId(如果有的话)
-  // checkAngle(position, pointId, exceptPointId) {
-  //   //type:1表示90°,2表示180°
-  //   function ajust(position, point1, point2, type) {
-  //     let line = mathUtil.createLine1(point1, point2);
-  //     let join = null;
-  //     if (type == 1) {
-  //       let vLine = mathUtil.getVerticalLine(line, point1);
-  //       join = mathUtil.getJoinLinePoint(position, vLine);
-  //     } else if (type == 2) {
-  //       join = mathUtil.getJoinLinePoint(position, line);
-  //     }
-  //     return join;
-  //   }
-
-  //   let points = roadService.getNeighPoints(pointId, exceptPointId);
-  //   let point = dataService.getRoadPoint(pointId);
-  //   let newPosition = null;
-  //   for (let i = 0; i < points.length; ++i) {
-  //     let angle = mathUtil.Angle(point, position, points[i]);
-  //     if (Math.abs((angle - 90) < 5) {
-  //       newPosition = ajust(position, point, points[i], 1);
-  //     } else if (
-  //       Math.abs(angle < 5 ||
-  //       Math.abs(angle - 180) < 5
-  //     ) {
-  //       newPosition = ajust(position, point, points[i], 2);
-  //     }
-  //     if (newPosition != null) {
-  //       return newPosition;
-  //     }
-  //   }
-  //   return newPosition;
-  // }
 }
 
 const elementService = new ElementService();

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

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