Explorar el Código

Merge branch 'master' of http://192.168.0.115:3000/bill/traffic-laser

bill hace 2 años
padre
commit
ae5ca25c67

+ 3 - 2
src/graphic/Constant.js

@@ -23,10 +23,11 @@ const Constant = {
   // // cadImg_Height: 3000,
   // miniMap_Width: 1200,
   // miniMap_Height: 1200,
+  minLen: 0.2, //挨着,比如:点是否在线段上
   minAdsorbPix: 20, //最小吸附像素
   minRealDis: 20,
-  defaultRoad: 20, //默认公路宽度
-  defaultRoadWidth: 20,
+  defaultRoad: 100, //默认公路宽度
+  defaultRoadWidth: 100,
   ratio: 1,
   minAngle: 10,
   maxAngle: 170,

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

@@ -7,6 +7,7 @@ import { elementService } from "../Service/ElementService";
 import { stateService } from "../Service/StateService";
 import VectorType from "../enum/VectorType";
 import { roadService } from "../Service/RoadService";
+import { edgeService } from "../Service/EdgeService";
 
 export default class AddRoad {
   constructor() {
@@ -58,6 +59,8 @@ export default class AddRoad {
       let roadId = roadService.getRoadId(pointId1, pointId2);
       if (!roadId) {
         let road = roadService.create(pointId1, pointId2);
+        edgeService.updateEdgeForMulRoad(pointId1);
+        edgeService.updateEdgeForMulRoad(pointId2);
       }
     }
   }
@@ -278,17 +281,17 @@ export default class AddRoad {
     elementService.setNewRoadStartPosition(this.startInfo.position);
   }
 
-  setNewRoadPoint(dir, position, modifyPoint) {
+  setNewRoadPoint(dir, position) {
     if (dir == "start") {
-      if (modifyPoint) {
-        this.setPointInfo(dir, modifyPoint);
+      if (listenLayer.modifyPoint) {
+        this.setPointInfo(dir, listenLayer.modifyPoint);
       } else {
         this.setPointInfo(dir, position);
       }
       return true;
     } else if (dir == "end") {
-      if (modifyPoint) {
-        this.setPointInfo(dir, modifyPoint);
+      if (listenLayer.modifyPoint) {
+        this.setPointInfo(dir, listenLayer.modifyPoint);
       } else {
         this.setPointInfo(dir, position);
       }

+ 58 - 55
src/graphic/Controls/MoveRoad.js

@@ -4,6 +4,7 @@ import Constant from "../Constant";
 import { mathUtil } from "../Util/MathUtil";
 import { elementService } from "../Service/ElementService";
 import { coordinate } from "../Coordinate";
+import { edgeService } from "../Service/EdgeService";
 
 export default class MoveRoad {
   constructor() {
@@ -46,66 +47,67 @@ export default class MoveRoad {
     );
 
     if (!flag) {
-      if (
-        this.splitRoadId == null &&
-        Object.keys(this.adsorbPointRoads).length > 0
-      ) {
-        //要吸附一下
-        const adsorbPointId = Object.keys(this.adsorbPointRoads)[0];
-        const road = dataService.getRoad(this.adsorbPointRoads[adsorbPointId]);
-
-        const otherPointId = road.getOtherPointId(pointId);
-        let otherPoint = dataService.getPoint(otherPointId);
-        let modifyPoint = dataService.getPoint(adsorbPointId);
-        let line = mathUtil.createLine1(otherPoint, modifyPoint);
-        position = mathUtil.getJoinLinePoint(position, line);
-        point.setPosition(position);
-      }
       return false;
     }
 
-    let newPosition = null;
-    if (modifyPoint == null) {
-      //90°或者180°纠正
-      //不考虑当前角度
+    if (
+      this.splitRoadId == null &&
+      Object.keys(this.adsorbPointRoads).length > 0
+    ) {
+      //要吸附一下
+      const adsorbPointId = Object.keys(this.adsorbPointRoads)[0];
+      const road = dataService.getRoad(this.adsorbPointRoads[adsorbPointId]);
 
-      //当前点的parent只有一个,考虑邻居点
-      let neighPoints = roadService.getNeighPoints(pointId);
-      if (neighPoints.length == 1) {
-        newPosition = elementService.checkAngle(
-          position,
-          neighPoints[0].vectorId,
-          pointId
-        );
-      }
-      //当前点的parent有两个
-      else if (neighPoints.length == 2) {
-        newPosition = elementService.checkAngle(
-          position,
-          neighPoints[0].vectorId,
-          pointId
-        );
-        if (!newPosition) {
-          newPosition = elementService.checkAngle(
-            position,
-            neighPoints[1].vectorId,
-            pointId
-          );
-        }
-      }
+      const otherPointId = road.getOtherPointId(pointId);
+      let otherPoint = dataService.getPoint(otherPointId);
+      let modifyPoint = dataService.getPoint(adsorbPointId);
+      let line = mathUtil.createLine1(otherPoint, modifyPoint);
+      position = mathUtil.getJoinLinePoint(position, line);
+      point.setPosition(position);
+    }
 
-      if (newPosition) {
-        flag = this.canMoveForPoint(
-          pointId,
-          newPosition,
-          linkedPointId,
-          linkedRoadId
-        );
-        if (!flag) {
-          return false;
-        }
-        mathUtil.clonePoint(position, newPosition);
-      }
+    // let newPosition = null;
+    if (modifyPoint == null) {
+      // //90°或者180°纠正
+      // //不考虑当前角度
+
+      // //当前点的parent只有一个,考虑邻居点
+      // let neighPoints = roadService.getNeighPoints(pointId);
+      // if (neighPoints.length == 1) {
+      //   newPosition = elementService.checkAngle(
+      //     position,
+      //     neighPoints[0].vectorId,
+      //     pointId
+      //   );
+      // }
+      // //当前点的parent有两个
+      // else if (neighPoints.length == 2) {
+      //   newPosition = elementService.checkAngle(
+      //     position,
+      //     neighPoints[0].vectorId,
+      //     pointId
+      //   );
+      //   if (!newPosition) {
+      //     newPosition = elementService.checkAngle(
+      //       position,
+      //       neighPoints[1].vectorId,
+      //       pointId
+      //     );
+      //   }
+      // }
+
+      // if (newPosition) {
+      //   flag = this.canMoveForPoint(
+      //     pointId,
+      //     newPosition,
+      //     linkedPointId,
+      //     linkedRoadId
+      //   );
+      //   if (!flag) {
+      //     return false;
+      //   }
+      //   mathUtil.clonePoint(position, newPosition);
+      // }
 
       point.setPosition(position);
     }
@@ -153,6 +155,7 @@ export default class MoveRoad {
       }
     }
 
+    edgeService.updateEdgeForMovePoint(pointId);
     return true;
   }
 

+ 12 - 2
src/graphic/Geometry/Edge.js

@@ -26,9 +26,19 @@ export default class Edge extends Geometry {
 
   setPosition(position, dir) {
     if (dir == "start") {
-      mathUtil.clonePoint(start, position);
+      mathUtil.clonePoint(this.start, position);
     } else if (dir == "end") {
-      mathUtil.clonePoint(end, position);
+      mathUtil.clonePoint(this.end, position);
+    }
+  }
+
+  getPosition(dir) {
+    if (dir == "start") {
+      return this.start;
+    } else if (dir == "end") {
+      return this.end;
+    } else {
+      return null;
     }
   }
 

+ 53 - 109
src/graphic/Layer.js

@@ -23,6 +23,8 @@ import History from "./History/History";
 import mitt from "mitt";
 import { roadService } from "./Service/RoadService";
 
+const minDragDis = 10;
+
 export default class Layer {
   constructor(canvas) {
     this.canvas = canvas;
@@ -32,9 +34,7 @@ export default class Layer {
     this.renderer = new Render(this);
     this.history = new History(this);
 
-    this.display = false;
-    this.mousePosition = null;
-
+    this.dragging = false; // 当前是否正在拖拽
     this.start();
 
     Object.setPrototypeOf(Object.getPrototypeOf(this), mitt());
@@ -63,13 +63,16 @@ export default class Layer {
     this.canvas.addEventListener("mouseup", this.onMouseUp.bind(this));
     this.canvas.addEventListener("mousewheel", this.onWheel.bind(this));
     this.canvas.addEventListener("DOMMouseScroll", this.onWheel.bind(this));
+    this.canvas.addEventListener("resize", this.reSize.bind(this));
   }
 
-  onMouseDown(e) {
-    if (coordinate.center == null) {
-      return;
-    }
+  reSize = function () {
+    console.log("resize");
+    coordinate.updateForCanvas();
+    this.renderer.autoRedraw();
+  };
 
+  onMouseDown(e) {
     this.startX = e.offsetX || e.layerX;
     this.startY = e.offsetY || e.layerY;
 
@@ -84,53 +87,10 @@ export default class Layer {
       return;
     }
 
-    const eventName = stateService.getEventName();
-    //点击第一次
-    if (eventName == LayerEvents.AddRoad) {
-      let flag = addRoad.setNewRoadPoint(
-        "start",
-        coordinate.getXYFromScreen({
-          x: this.startX,
-          y: this.startY,
-        }),
-        listenLayer.modifyPoint
-      );
-      if (!flag) {
-        return;
-      }
-    }
-    //点击第二次
-    else if (eventName == LayerEvents.AddingRoad) {
-      let flag = addRoad.setNewRoadPoint(
-        "end",
-        elementService.newRoad.end,
-        listenLayer.modifyPoint
-      );
-      if (!flag) {
-        return;
-      }
-      if (addRoad.canAdd) {
-        addRoad.buildRoad();
-        addRoad.clear();
-        this.renderer.autoRedraw();
-        this.history.save();
-        stateService.clearEventName();
-        elementService.hideAll();
-      } else {
-        return;
-      }
-    } else {
-      const selectItem = stateService.getSelectItem();
-      if (eventName == null && selectItem) {
-        stateService.setDraggingItem(selectItem);
-        stateService.setFocusItem(selectItem);
-        //this.uiControl.showAttributes(); //弹出
-        this.uiControl.currentUI = selectItem.type;
-      } else if (eventName == null) {
-        this.uiControl.currentUI = null;
-      }
-    }
     this.setEventName("mouseDown");
+    const selectItem = stateService.getSelectItem();
+    const eventName = stateService.getEventName();
+    stateService.setDraggingItem(selectItem);
     // 清除上一个状态
     // 设置当前事件名称
     e.preventDefault();
@@ -140,10 +100,7 @@ export default class Layer {
   onMouseMove(e) {
     const X = e.offsetX || e.layerX;
     const Y = e.offsetY || e.layerY;
-    this.mousePosition = {
-      x: X,
-      y: Y,
-    };
+
     let dx = X - this.lastX;
     let dy = Y - this.lastY;
 
@@ -152,12 +109,21 @@ export default class Layer {
       y: Y,
     });
 
+    if (
+      Math.abs(X - this.startX) > minDragDis ||
+      Math.abs(Y - this.startY) > minDragDis
+    ) {
+      // 是否拖拽了
+      this.dragging = true;
+    } else {
+      this.dragging = false;
+    }
     const eventName = stateService.getEventName();
 
     // 是否需要重绘
     let needAutoRedraw = false;
-
     const draggingItem = stateService.getDraggingItem();
+
     switch (eventName) {
       case null:
         //监控
@@ -174,8 +140,6 @@ export default class Layer {
         needAutoRedraw = true;
         break;
       case LayerEvents.AddRoad:
-        stateService.clearDraggingItem();
-        stateService.clearFocusItem();
         needAutoRedraw = true;
         listenLayer.start(position);
         if (listenLayer.modifyPoint) {
@@ -184,19 +148,15 @@ export default class Layer {
             y: listenLayer.modifyPoint.y,
           };
         }
-        elementService.execute(null, position);
-        elementService.setStartAddRoad(position);
+
+        elementService.setAddingRoadPoint(position);
         elementService.showStartAddRoad();
+
+        addRoad.setNewRoadPoint("start", position);
         break;
       case LayerEvents.AddingRoad:
-        stateService.clearDraggingItem();
-        stateService.clearFocusItem();
         needAutoRedraw = true;
         listenLayer.start(position);
-        let startPosition = {
-          x: addRoad.startInfo.position.x,
-          y: addRoad.startInfo.position.y,
-        };
         if (listenLayer.modifyPoint) {
           position = {
             x: listenLayer.modifyPoint.x,
@@ -204,27 +164,13 @@ export default class Layer {
           };
         }
 
-        elementService.execute(startPosition, position);
-        elementService.setStartAddRoad(position);
-        if (!elementService.newRoad.display) {
-          elementService.setNewRoad(startPosition, position);
-          elementService.showNewRoad();
-        } else {
-          if (!listenLayer.modifyPoint && addRoad.startInfo.linkedPointId) {
-            let newEndPosition = elementService.checkAngle(
-              position,
-              addRoad.startInfo.linkedPointId,
-              null
-            );
-            if (newEndPosition) {
-              mathUtil.clonePoint(position, newEndPosition);
-              elementService.execute(startPosition, position);
-            }
-          }
-          elementService.setNewRoadGeoType(VectorType.Road);
-          elementService.setNewRoadEndPosition(position); //改变end位置
-        }
+        elementService.execute(addRoad.startInfo.position, position);
+        elementService.setAddingRoadPoint(position);
+        elementService.setNewRoad(addRoad.startInfo.position, position);
+        elementService.showNewRoad();
+        elementService.setNewRoadGeoType(VectorType.Road);
 
+        addRoad.setNewRoadPoint("end", position);
         addRoad.canAdd = addRoad.canAddRoadForEnd(position);
         if (!addRoad.canAdd) {
           elementService.setNewRoadState("error");
@@ -233,6 +179,9 @@ export default class Layer {
         }
         break;
       case LayerEvents.MoveRoad:
+        if (!this.dragging) {
+          return;
+        }
         dx = (dx * coordinate.defaultZoom) / coordinate.zoom;
         dy = (dy * coordinate.defaultZoom) / coordinate.zoom;
         // 1表示可以继续移动,2表示不能移动(启动距离还不够),3表示roadId被删除了,4表示重新开始移动(需要达到一定距离才能启动),5表示不能移动(不合适)
@@ -268,6 +217,9 @@ export default class Layer {
         }
         break;
       case LayerEvents.MoveRoadPoint:
+        if (!this.dragging) {
+          return;
+        }
         let point = dataService.getPoint(draggingItem.vectorId);
         listenLayer.start(position, draggingItem.vectorId, point.parent);
         if (listenLayer.modifyPoint) {
@@ -350,15 +302,17 @@ export default class Layer {
 
     let eventName = stateService.getEventName();
     const draggingItem = stateService.getDraggingItem();
+    const selectItem = stateService.getSelectItem();
     let focusItem = null;
 
-    if (draggingItem && draggingItem.vectorId) {
+    if (!this.dragging && selectItem) {
       focusItem = {
-        vectorId: draggingItem.vectorId,
-        type: draggingItem.type,
+        vectorId: selectItem.vectorId,
+        type: selectItem.type,
         cursor: { x: this.lastX, y: this.lastY },
       };
       stateService.setFocusItem(focusItem);
+      stateService.clearDraggingItem();
     }
 
     let position = coordinate.getXYFromScreen({
@@ -423,18 +377,11 @@ export default class Layer {
         break;
       case LayerEvents.AddingRoad:
         needAutoRedraw = true;
-        if (addRoad.startInfo && addRoad.startInfo.linkedPointId) {
-          let addRoadStartPoint = dataService.getPoint(
-            addRoad.startInfo.linkedPointId
-          );
-          if (
-            addRoad.endInfo.position &&
-            Object.keys(addRoadStartPoint.parent).length > 1
-          ) {
-            stateService.clearEventName();
-            addRoad.clear();
-            elementService.hideAll();
-          }
+        if (addRoad.canAdd) {
+          addRoad.buildRoad();
+          addRoad.clear();
+          this.history.save();
+          elementService.hideAll();
         }
         break;
       case LayerEvents.MoveRoad:
@@ -506,17 +453,14 @@ export default class Layer {
         } else if (selectItem.type == VectorType.Tag) {
           stateService.setEventName(LayerEvents.MoveTag);
         }
-      } else if (eventName == LayerEvents.AddRoad) {
-        stateService.setEventName(LayerEvents.AddingRoad);
       }
     } else if (eventType == "mouseUp") {
       if (eventName == LayerEvents.AddTag) {
         //可连续添加
         //stateService.clearEventName()
-      } else if (
-        eventName != LayerEvents.AddRoad &&
-        eventName != LayerEvents.AddingRoad
-      ) {
+      } else if (eventName == LayerEvents.AddRoad) {
+        stateService.setEventName(LayerEvents.AddingRoad);
+      } else {
         stateService.clearEventName();
       }
     }

+ 95 - 35
src/graphic/Renderer/Draw.js

@@ -73,7 +73,7 @@ export default class Draw {
       this.context.globalAlpha = 0.3;
       point1 = coordinate.getScreenXY(vector.start);
       point2 = coordinate.getScreenXY(vector.end);
-      this.context.lineWidth = Constant.defaultRoadWidth;
+      //this.context.lineWidth = Constant.defaultRoadWidth;
     } else {
       let start = dataService.getPoint(vector.startId);
       let end = dataService.getPoint(vector.endId);
@@ -84,7 +84,7 @@ export default class Draw {
         { x: (start.x + end.x) / 2, y: (start.y + end.y) / 2 },
         vector.vectorId
       );
-      this.context.lineWidth = vector.width;
+      //this.context.lineWidth = vector.width;
     }
     this.context.beginPath();
     this.context.moveTo(point1.x, point1.y);
@@ -137,6 +137,22 @@ export default class Draw {
     this.context.stroke();
 
     this.context.restore();
+
+    this.drawText(
+      {
+        x: (leftEdge.start.x + leftEdge.end.x) / 2,
+        y: (leftEdge.start.y + leftEdge.end.y) / 2,
+      },
+      vector.leftEdgeId
+    );
+
+    this.drawText(
+      {
+        x: (rightEdge.start.x + rightEdge.end.x) / 2,
+        y: (rightEdge.start.y + rightEdge.end.y) / 2,
+      },
+      vector.rightEdgeId
+    );
   }
 
   drawPoint(vector) {
@@ -169,9 +185,10 @@ export default class Draw {
       this.context.strokeStyle = Style.Focus.Point.strokeStyle;
       this.context.fillStyle = Style.Focus.Point.fillStyle;
       radius = Style.Focus.Point.radius;
-    } else {
-      return;
     }
+    // else {
+    //   return;
+    // }
 
     this.context.beginPath();
     this.context.arc(
@@ -189,18 +206,54 @@ export default class Draw {
     this.drawText(vector, vector.vectorId);
   }
 
+  drawControlPoint(vector) {
+    const pt = coordinate.getScreenXY({ x: vector.x, y: vector.y });
+    const color = this.rgb();
+    this.context.strokeStyle = color;
+    this.context.fillStyle = color;
+
+    let radius = Style.Point.radius;
+    this.context.beginPath();
+    this.context.arc(
+      pt.x,
+      pt.y,
+      radius * coordinate.ratio,
+      0,
+      Math.PI * 2,
+      true
+    );
+    this.context.stroke();
+    this.context.fill();
+
+    let start = dataService
+      .getEdge(vector.edgeInfo1.id)
+      .getPosition(vector.edgeInfo1.dir);
+    start = coordinate.getScreenXY(start);
+
+    let end = dataService
+      .getEdge(vector.edgeInfo2.id)
+      .getPosition(vector.edgeInfo2.dir);
+    end = coordinate.getScreenXY(end);
+
+    this.context.beginPath();
+    this.context.moveTo(start.x, start.y);
+    this.context.quadraticCurveTo(pt.x, pt.y, end.x, end.y);
+    this.context.stroke();
+
+    this.context.restore();
+    this.drawText(vector, vector.vectorId);
+  }
+
   // 文字
   drawText(position, txt, angle) {
     this.context.save();
     this.setCanvasStyle(Style.Font);
     if (coordinate.ratio == Constant.ratio) {
-      this.context.font = "36px Microsoft YaHei";
+      this.context.font = "12px Microsoft YaHei";
     } else {
       this.context.font = "12px Microsoft YaHei";
     }
-
     let pt = coordinate.getScreenXY(position);
-
     if (angle) {
       this.context.translate(pt.x, pt.y);
       this.context.rotate(angle);
@@ -210,7 +263,6 @@ export default class Draw {
       //this.context.strokeText(txt, pt.x, pt.y)
       this.context.fillText(txt, pt.x, pt.y);
     }
-
     this.context.restore();
   }
 
@@ -473,33 +525,33 @@ export default class Draw {
   }
 
   drawCircle(element) {
-    // let radius = null;
-    // const twoPi = Math.PI * 2;
-    // const pt = coordinate.getScreenXY(element);
-    // this.context.save();
-    // if (element.name == ElementEvents.StartAddRoad) {
-    //   radius = Style.Element.StartAddRoad.radius * coordinate.ratio;
-    //   this.context.strokeStyle = Style.Element.StartAddRoad.strokeStyle;
-    //   this.context.fillStyle = Style.Element.StartAddRoad.fillStyle;
-    // } else if (element.name == ElementEvents.StartSymbolPoints) {
-    //   radius = Style.Element.StartSymbolPoints.radius * coordinate.ratio;
-    //   this.context.strokeStyle = Style.Element.StartSymbolPoints.strokeStyle;
-    //   this.context.fillStyle = Style.Element.StartSymbolPoints.fillStyle;
-    // } else if (element.name == ElementEvents.EndSymbolPoints) {
-    //   radius = Style.Element.EndSymbolPoints.radius * coordinate.ratio;
-    //   this.context.strokeStyle = Style.Element.EndSymbolPoints.strokeStyle;
-    //   this.context.fillStyle = Style.Element.EndSymbolPoints.fillStyle;
-    // } else if (element.name == "pano") {
-    //   radius = Style.Pano.radius * coordinate.ratio;
-    //   this.context.strokeStyle = Style.Pano.strokeStyle;
-    //   this.context.fillStyle = Style.Pano.fillStyle;
-    //   this.context.lineWidth = Style.Pano.lineWidth;
-    // }
-    // this.context.beginPath();
-    // this.context.arc(pt.x, pt.y, radius, 0, twoPi, true);
-    // this.context.stroke();
-    // this.context.fill();
-    // this.context.restore();
+    let radius = null;
+    const twoPi = Math.PI * 2;
+    const pt = coordinate.getScreenXY(element);
+    this.context.save();
+    if (element.name == ElementEvents.AddingRoadPoint) {
+      radius = Style.Element.AddingRoadPoint.radius * coordinate.ratio;
+      this.context.strokeStyle = Style.Element.AddingRoadPoint.strokeStyle;
+      this.context.fillStyle = Style.Element.AddingRoadPoint.fillStyle;
+    } else if (element.name == ElementEvents.StartSymbolPoints) {
+      radius = Style.Element.StartSymbolPoints.radius * coordinate.ratio;
+      this.context.strokeStyle = Style.Element.StartSymbolPoints.strokeStyle;
+      this.context.fillStyle = Style.Element.StartSymbolPoints.fillStyle;
+    } else if (element.name == ElementEvents.EndSymbolPoints) {
+      radius = Style.Element.EndSymbolPoints.radius * coordinate.ratio;
+      this.context.strokeStyle = Style.Element.EndSymbolPoints.strokeStyle;
+      this.context.fillStyle = Style.Element.EndSymbolPoints.fillStyle;
+    } else if (element.name == "pano") {
+      radius = Style.Pano.radius * coordinate.ratio;
+      this.context.strokeStyle = Style.Pano.strokeStyle;
+      this.context.fillStyle = Style.Pano.fillStyle;
+      this.context.lineWidth = Style.Pano.lineWidth;
+    }
+    this.context.beginPath();
+    this.context.arc(pt.x, pt.y, radius, 0, twoPi, true);
+    this.context.stroke();
+    this.context.fill();
+    this.context.restore();
   }
 
   drawLine(element) {
@@ -925,6 +977,14 @@ export default class Draw {
     }
   }
 
+  rgb() {
+    //rgb颜色随机
+    const r = Math.floor(Math.random() * 256);
+    const g = Math.floor(Math.random() * 256);
+    const b = Math.floor(Math.random() * 256);
+    return `rgb(${r},${g},${b})`;
+  }
+
   /*************************************************************************************家具**********************************************************************************************/
 
   /***************************************************************************************************************************************************************************************/

+ 14 - 2
src/graphic/Renderer/Render.js

@@ -23,11 +23,15 @@ export default class Render {
       case VectorType.Point:
         draw.drawPoint(vector);
         return;
+      case VectorType.ControlPoint:
+        draw.drawControlPoint(vector);
+        return;
       case VectorType.Tag:
         draw.drawTag(vector, styleType, flag);
         return;
       case VectorType.MeasureLine:
         draw.drawMeasures(vector, styleType);
+        return;
     }
   }
 
@@ -58,8 +62,11 @@ export default class Render {
       this.drawElement(elementService.vCheckLines.Y);
     }
 
-    if (elementService.startAddRoad && elementService.startAddRoad.display) {
-      this.drawElement(elementService.startAddRoad);
+    if (
+      elementService.addingRoadPoint &&
+      elementService.addingRoadPoint.display
+    ) {
+      this.drawElement(elementService.addingRoadPoint);
     }
 
     if (elementService.newRoad && elementService.newRoad.display) {
@@ -89,6 +96,11 @@ export default class Render {
       this.drawGeometry(points[key]);
     }
 
+    let controlPoints = dataService.getControlPoints();
+    for (let key in controlPoints) {
+      this.drawGeometry(controlPoints[key]);
+    }
+
     let tags = dataService.getTags();
     for (let key in tags) {
       this.drawGeometry(tags[key]);

+ 22 - 7
src/graphic/Service/ControlPointService.js

@@ -6,26 +6,41 @@ import { edgeService } from "./EdgeService.js";
 export default class ControlPointService {
   constructor() {}
 
+  //暂时没有添加到vectorData里
   create(position, vectorId) {
     let controlPoint = new ControlPoint(position, vectorId);
-    dataService.addControlPoint(controlPoint);
     return controlPoint;
   }
 
-  update(point, edgePosition, edge1, edge2, dir1, dir2) {
+  update(realRosition, point1, point2, edge1, edge2, dir1, dir2) {
     let controlPoint = dataService.getControlPoint(
       edge1.vectorId,
       edge2.vectorId
     );
     const line1 = edgeService.getLine(edge1);
     const line2 = edgeService.getLine(edge2);
-    const position = mathUtil.getPositionForExtendedLine(point, edgePosition);
+    let position = mathUtil.getPositionForExtendedLine(point1, point2);
     //更新edge的坐标
-    const position1 = mathUtil.getJoinLinePoint(position, line1);
-    const position2 = mathUtil.getJoinLinePoint(position, line2);
+    let position1 = mathUtil.getJoinLinePoint(position, line1);
+    let position2 = mathUtil.getJoinLinePoint(position, line2);
+    //可能position1或者position2不在对应的edge上,这时候需要调换顺序
+    if (
+      !mathUtil.isContainForSegment(position1, edge1.start, edge1.end) ||
+      !mathUtil.isContainForSegment(position2, edge2.start, edge2.end)
+    ) {
+      position = mathUtil.getPositionForExtendedLine(point2, point1);
+      position1 = mathUtil.getJoinLinePoint(position, line1);
+      position2 = mathUtil.getJoinLinePoint(position, line2);
+    }
+
+    // const realRosition = mathUtil.getPositionForExtendedLine(point2, point1);
+    // const realRosition = {
+    //   x: (point1.x + point2.x) / 2,
+    //   y: (point1.y + point2.y) / 2,
+    // };
     if (controlPoint == null) {
       //新建控制点
-      controlPoint = this.create(position);
+      controlPoint = this.create(realRosition);
       //设置控制点的信息
       controlPoint.setEdgeInfo(edge1.vectorId, dir1, edge2.vectorId, dir2);
       //添加到数据集里
@@ -33,7 +48,7 @@ export default class ControlPointService {
     }
     //更新控制点坐标
     else {
-      controlPoint.setPosition(position);
+      controlPoint.setPosition(realRosition);
     }
     edge1.setPosition(position1, dir1);
     edge2.setPosition(position2, dir2);

+ 11 - 2
src/graphic/Service/DataService.js

@@ -22,6 +22,7 @@ export class DataService {
 
   initVectorData() {
     this.vectorData.points = {};
+    this.vectorData.controlPoints = {};
     this.vectorData.roads = {};
     this.vectorData.edges = {};
     this.vectorData.tags = {};
@@ -128,6 +129,16 @@ export class DataService {
     ] = controlPoint;
   }
 
+  deleteControlPoint(edgeId1, edgeId2) {
+    let key = edgeId1 + "-" + edgeId2;
+    if (!this.vectorData.controlPoints[key]) {
+      key = edgeId2 + "-" + edgeId1;
+    }
+    if (this.vectorData.controlPoints[key]) {
+      delete this.vectorData.controlPoints[key];
+    }
+  }
+
   /**
    * 对公路边缘的操作
    */
@@ -151,8 +162,6 @@ export class DataService {
   }
 
   deleteTag(tagId) {
-    let tag = this.getTag(tagId);
-    tag = null;
     delete this.vectorData.tags[tagId];
   }
 

+ 382 - 29
src/graphic/Service/EdgeService.js

@@ -123,8 +123,8 @@ export default class EdgeService {
 
     let road2 = dataService.getRoad(roadId2);
     this.computerDefaultEdge(roadId2);
-    // let startPoint2 = dataService.getPoint(road2.startId);
-    // let endPoint2 = dataService.getPoint(road2.endId);
+    let startPoint2 = dataService.getPoint(road2.startId);
+    let endPoint2 = dataService.getPoint(road2.endId);
     let leftEdge2 = dataService.getEdge(road2.leftEdgeId);
     let rightEdge2 = dataService.getEdge(road2.rightEdgeId);
     let lineLeft2 = this.getLine(leftEdge2);
@@ -150,12 +150,26 @@ export default class EdgeService {
       } else {
         newEdgePoint1 = mathUtil.getIntersectionPoint(lineLeft1, lineRight2);
         newEdgePoint2 = mathUtil.getIntersectionPoint(lineLeft2, lineRight1);
+      }
+
+      mathUtil.clonePoint(leftEdge1.start, newEdgePoint1);
+      mathUtil.clonePoint(rightEdge1.start, newEdgePoint2);
+
+      mathUtil.clonePoint(rightEdge2.start, newEdgePoint1);
+      mathUtil.clonePoint(leftEdge2.start, newEdgePoint2);
+
+      if (angle > Constant.maxAngle) {
+        //要删除控制点
+        dataService.deleteControlPoint(leftEdge1.vectorId, rightEdge2.vectorId);
+        dataService.deleteControlPoint(rightEdge1.vectorId, leftEdge2.vectorId);
+      } else {
         points.push(startPoint1);
         points.push(endPoint1);
-        points.push(newEdgePoint1);
+        points.push(endPoint2);
         if (mathUtil.isClockwise(points)) {
           //需要考虑控制点ControlPointService
           controlPointService.update(
+            newEdgePoint1,
             startPoint1,
             newEdgePoint1,
             leftEdge1,
@@ -163,24 +177,38 @@ export default class EdgeService {
             "start",
             "start"
           );
+          controlPointService.update(
+            newEdgePoint2,
+            newEdgePoint2,
+            startPoint1,
+            rightEdge1,
+            leftEdge2,
+            "start",
+            "start"
+          );
         } else {
           //需要考虑控制点ControlPointService
           controlPointService.update(
+            newEdgePoint2,
             startPoint1,
-            newEdgePoint1,
+            newEdgePoint2,
             rightEdge1,
             leftEdge2,
             "start",
             "start"
           );
+          controlPointService.update(
+            newEdgePoint1,
+            newEdgePoint1,
+            startPoint1,
+            leftEdge1,
+            rightEdge2,
+            "start",
+            "start"
+          );
         }
       }
 
-      mathUtil.clonePoint(leftEdge1.start, newEdgePoint1);
-      mathUtil.clonePoint(rightEdge1.start, newEdgePoint2);
-
-      mathUtil.clonePoint(rightEdge2.start, newEdgePoint1);
-      mathUtil.clonePoint(leftEdge2.start, newEdgePoint2);
       return true;
     }
     //start-end
@@ -192,12 +220,29 @@ export default class EdgeService {
       } else {
         newEdgePoint1 = mathUtil.getIntersectionPoint(lineLeft1, lineLeft2);
         newEdgePoint2 = mathUtil.getIntersectionPoint(lineRight1, lineRight2);
+      }
+
+      mathUtil.clonePoint(leftEdge1.start, newEdgePoint1);
+      mathUtil.clonePoint(rightEdge1.start, newEdgePoint2);
+
+      mathUtil.clonePoint(leftEdge2.end, newEdgePoint1);
+      mathUtil.clonePoint(rightEdge2.end, newEdgePoint2);
+
+      if (angle > Constant.maxAngle) {
+        //要删除控制点
+        dataService.deleteControlPoint(leftEdge1.vectorId, leftEdge2.vectorId);
+        dataService.deleteControlPoint(
+          rightEdge1.vectorId,
+          rightEdge2.vectorId
+        );
+      } else {
         points.push(startPoint1);
         points.push(endPoint1);
-        points.push(newEdgePoint1);
+        points.push(startPoint2);
         if (mathUtil.isClockwise(points)) {
           //需要考虑控制点ControlPointService
           controlPointService.update(
+            newEdgePoint1,
             startPoint1,
             newEdgePoint1,
             leftEdge1,
@@ -205,24 +250,37 @@ export default class EdgeService {
             "start",
             "end"
           );
+          controlPointService.update(
+            newEdgePoint2,
+            newEdgePoint2,
+            startPoint1,
+            rightEdge1,
+            rightEdge2,
+            "start",
+            "end"
+          );
         } else {
           //需要考虑控制点ControlPointService
           controlPointService.update(
+            newEdgePoint2,
             startPoint1,
-            newEdgePoint1,
+            newEdgePoint2,
             rightEdge1,
             rightEdge2,
             "start",
             "end"
           );
+          controlPointService.update(
+            newEdgePoint1,
+            newEdgePoint1,
+            startPoint1,
+            leftEdge1,
+            leftEdge2,
+            "start",
+            "end"
+          );
         }
       }
-
-      mathUtil.clonePoint(leftEdge1.start, newEdgePoint1);
-      mathUtil.clonePoint(rightEdge1.start, newEdgePoint2);
-
-      mathUtil.clonePoint(leftEdge2.end, newEdgePoint1);
-      mathUtil.clonePoint(rightEdge2.end, newEdgePoint2);
       return true;
     }
     //end-start
@@ -235,12 +293,64 @@ export default class EdgeService {
         newEdgePoint1 = mathUtil.getIntersectionPoint(lineLeft1, lineLeft2);
         newEdgePoint2 = mathUtil.getIntersectionPoint(lineRight1, lineRight2);
       }
-
       mathUtil.clonePoint(leftEdge1.end, newEdgePoint1);
       mathUtil.clonePoint(rightEdge1.end, newEdgePoint2);
 
       mathUtil.clonePoint(leftEdge2.start, newEdgePoint1);
       mathUtil.clonePoint(rightEdge2.start, newEdgePoint2);
+      if (angle > Constant.maxAngle) {
+        //要删除控制点
+        dataService.deleteControlPoint(leftEdge1.vectorId, leftEdge2.vectorId);
+        dataService.deleteControlPoint(
+          rightEdge1.vectorId,
+          rightEdge2.vectorId
+        );
+      } else {
+        points.push(endPoint1);
+        points.push(startPoint1);
+        points.push(endPoint2);
+        if (!mathUtil.isClockwise(points)) {
+          //需要考虑控制点ControlPointService
+          controlPointService.update(
+            newEdgePoint1,
+            endPoint1,
+            newEdgePoint1,
+            leftEdge1,
+            leftEdge2,
+            "end",
+            "start"
+          );
+          controlPointService.update(
+            newEdgePoint2,
+            newEdgePoint2,
+            endPoint1,
+            rightEdge1,
+            rightEdge2,
+            "end",
+            "start"
+          );
+        } else {
+          //需要考虑控制点ControlPointService
+          controlPointService.update(
+            newEdgePoint2,
+            endPoint1,
+            newEdgePoint2,
+            rightEdge1,
+            rightEdge2,
+            "end",
+            "start"
+          );
+          controlPointService.update(
+            newEdgePoint1,
+            newEdgePoint1,
+            endPoint1,
+            leftEdge1,
+            leftEdge2,
+            "end",
+            "start"
+          );
+        }
+      }
       return true;
     }
     //end-end
@@ -253,12 +363,63 @@ export default class EdgeService {
         newEdgePoint1 = mathUtil.getIntersectionPoint(lineLeft1, lineRight2);
         newEdgePoint2 = mathUtil.getIntersectionPoint(lineLeft2, lineRight1);
       }
-
       mathUtil.clonePoint(leftEdge1.end, newEdgePoint1);
       mathUtil.clonePoint(rightEdge1.end, newEdgePoint2);
 
       mathUtil.clonePoint(rightEdge2.end, newEdgePoint1);
       mathUtil.clonePoint(leftEdge2.end, newEdgePoint2);
+
+      if (angle > Constant.maxAngle) {
+        //要删除控制点
+        dataService.deleteControlPoint(leftEdge1.vectorId, rightEdge2.vectorId);
+        dataService.deleteControlPoint(rightEdge1.vectorId, leftEdge2.vectorId);
+      } else {
+        points.push(endPoint1);
+        points.push(startPoint1);
+        points.push(startPoint2);
+        if (!mathUtil.isClockwise(points)) {
+          //需要考虑控制点ControlPointService
+          controlPointService.update(
+            newEdgePoint1,
+            endPoint1,
+            newEdgePoint1,
+            leftEdge1,
+            rightEdge2,
+            "end",
+            "end"
+          );
+          controlPointService.update(
+            newEdgePoint2,
+            newEdgePoint2,
+            endPoint1,
+            leftEdge2,
+            rightEdge1,
+            "end",
+            "end"
+          );
+        } else {
+          //需要考虑控制点ControlPointService
+          controlPointService.update(
+            newEdgePoint2,
+            endPoint1,
+            newEdgePoint2,
+            leftEdge2,
+            rightEdge1,
+            "end",
+            "end"
+          );
+          controlPointService.update(
+            newEdgePoint1,
+            newEdgePoint1,
+            endPoint1,
+            leftEdge1,
+            rightEdge2,
+            "end",
+            "end"
+          );
+        }
+      }
+
       return true;
     } else {
       console.error(
@@ -276,19 +437,21 @@ export default class EdgeService {
   updateSingleEdgeForTwoRoad(roadId1, roadId2) {
     //console.log('更新'+roadId1+'和'+roadId2+'一侧相交的edge交点');
     console.log("开始执行updateSingleEdgeForTwoRoad");
-    let road1 = dataService.getRoad(roadId1);
-    let startPoint1 = dataService.getPoint(road1.startId);
-    let endPoint1 = dataService.getPoint(road1.endId);
-    this.computerDefaultEdge(roadId1);
+    const road1 = dataService.getRoad(roadId1);
+    const startPoint1 = dataService.getPoint(road1.startId);
+    const endPoint1 = dataService.getPoint(road1.endId);
+    let line1 = mathUtil.createLine1(startPoint1, endPoint1);
+
     let leftEdge1 = dataService.getEdge(road1.leftEdgeId);
     let rightEdge1 = dataService.getEdge(road1.rightEdgeId);
     let lineLeft1 = this.getLine(leftEdge1);
     let lineRight1 = this.getLine(rightEdge1);
 
-    let road2 = dataService.getRoad(roadId2);
-    this.computerDefaultEdge(roadId2);
-    // let startPoint2 = dataService.getPoint(road2.startId);
-    // let endPoint2 = dataService.getPoint(road2.endId);
+    const road2 = dataService.getRoad(roadId2);
+    const startPoint2 = dataService.getPoint(road2.startId);
+    const endPoint2 = dataService.getPoint(road2.endId);
+    let line2 = mathUtil.createLine1(startPoint2, endPoint2);
+
     let leftEdge2 = dataService.getEdge(road2.leftEdgeId);
     let rightEdge2 = dataService.getEdge(road2.rightEdgeId);
     let lineLeft2 = this.getLine(leftEdge2);
@@ -310,7 +473,12 @@ export default class EdgeService {
     if (road1.startId == road2.startId) {
       points.push(startPoint1);
       points.push(endPoint1);
-      //如果墙的角度过大,不能计算edge对应的line的交点
+
+      lineLeft1 = mathUtil.createLine3(line1, leftEdge1.end);
+      lineRight1 = mathUtil.createLine3(line1, rightEdge1.end);
+      lineRight2 = mathUtil.createLine3(line2, rightEdge2.end);
+
+      // 如果墙的角度过大,不能计算edge对应的line的交点
       if (angle > Constant.maxAngle) {
         newEdgePoint1 = mathUtil.getJoinLinePoint(startPoint1, lineLeft1);
         newEdgePoint2 = mathUtil.getJoinLinePoint(startPoint1, lineRight1);
@@ -321,11 +489,49 @@ export default class EdgeService {
 
       points[2] = newEdgePoint1;
       if (mathUtil.isClockwise(points)) {
+        console.log("情况1");
         mathUtil.clonePoint(leftEdge1.start, newEdgePoint1);
         mathUtil.clonePoint(rightEdge2.start, newEdgePoint1);
+        if (angle > Constant.maxAngle) {
+          //要删除控制点
+          dataService.deleteControlPoint(
+            leftEdge1.vectorId,
+            rightEdge2.vectorId
+          );
+        } else {
+          //需要考虑控制点ControlPointService
+          controlPointService.update(
+            newEdgePoint1,
+            startPoint1,
+            newEdgePoint1,
+            leftEdge1,
+            rightEdge2,
+            "start",
+            "start"
+          );
+        }
       } else {
+        console.log("情况2");
         mathUtil.clonePoint(rightEdge1.start, newEdgePoint2);
         mathUtil.clonePoint(leftEdge2.start, newEdgePoint2);
+        if (angle > Constant.maxAngle) {
+          //要删除控制点
+          dataService.deleteControlPoint(
+            leftEdge2.vectorId,
+            rightEdge1.vectorId
+          );
+        } else {
+          //需要考虑控制点ControlPointService
+          controlPointService.update(
+            newEdgePoint2,
+            startPoint1,
+            newEdgePoint2,
+            leftEdge2,
+            rightEdge1,
+            "start",
+            "start"
+          );
+        }
       }
       return true;
     }
@@ -334,6 +540,12 @@ export default class EdgeService {
     else if (road1.startId == road2.endId) {
       points.push(startPoint1);
       points.push(endPoint1);
+
+      lineLeft1 = mathUtil.createLine3(line1, leftEdge1.end);
+      lineRight1 = mathUtil.createLine3(line1, rightEdge1.end);
+      lineLeft2 = mathUtil.createLine3(line2, leftEdge2.start);
+      lineRight2 = mathUtil.createLine3(line2, rightEdge2.start);
+
       if (angle > Constant.maxAngle) {
         newEdgePoint1 = mathUtil.getJoinLinePoint(startPoint1, lineLeft1);
         newEdgePoint2 = mathUtil.getJoinLinePoint(startPoint1, lineRight1);
@@ -343,11 +555,49 @@ export default class EdgeService {
       }
       points[2] = newEdgePoint1;
       if (mathUtil.isClockwise(points)) {
+        console.log("情况3");
         mathUtil.clonePoint(leftEdge1.start, newEdgePoint1);
         mathUtil.clonePoint(leftEdge2.end, newEdgePoint1);
+        if (angle > Constant.maxAngle) {
+          //要删除控制点
+          dataService.deleteControlPoint(
+            leftEdge1.vectorId,
+            leftEdge2.vectorId
+          );
+        } else {
+          //需要考虑控制点ControlPointService
+          controlPointService.update(
+            newEdgePoint1,
+            startPoint1,
+            newEdgePoint1,
+            leftEdge1,
+            leftEdge2,
+            "start",
+            "end"
+          );
+        }
       } else {
+        console.log("情况4");
         mathUtil.clonePoint(rightEdge1.start, newEdgePoint2);
         mathUtil.clonePoint(rightEdge2.end, newEdgePoint2);
+        if (angle > Constant.maxAngle) {
+          //要删除控制点
+          dataService.deleteControlPoint(
+            rightEdge1.vectorId,
+            rightEdge2.vectorId
+          );
+        } else {
+          //需要考虑控制点ControlPointService
+          controlPointService.update(
+            newEdgePoint2,
+            startPoint1,
+            newEdgePoint2,
+            rightEdge1,
+            rightEdge2,
+            "start",
+            "end"
+          );
+        }
       }
       return true;
     }
@@ -356,6 +606,12 @@ export default class EdgeService {
     else if (road1.endId == road2.startId) {
       points.push(endPoint1);
       points.push(startPoint1);
+
+      lineLeft1 = mathUtil.createLine3(line1, leftEdge1.start);
+      lineRight1 = mathUtil.createLine3(line1, rightEdge1.start);
+      lineLeft2 = mathUtil.createLine3(line2, leftEdge2.end);
+      lineRight2 = mathUtil.createLine3(line2, rightEdge2.end);
+
       if (angle > Constant.maxAngle) {
         newEdgePoint1 = mathUtil.getJoinLinePoint(endPoint1, lineLeft1);
         newEdgePoint2 = mathUtil.getJoinLinePoint(endPoint1, lineRight1);
@@ -365,19 +621,63 @@ export default class EdgeService {
       }
       points[2] = newEdgePoint1;
       if (mathUtil.isClockwise(points)) {
+        console.log("情况5");
         mathUtil.clonePoint(leftEdge1.end, newEdgePoint1);
         mathUtil.clonePoint(leftEdge2.start, newEdgePoint1);
+        if (angle > Constant.maxAngle) {
+          //要删除控制点
+          dataService.deleteControlPoint(
+            leftEdge1.vectorId,
+            leftEdge2.vectorId
+          );
+        } else {
+          //需要考虑控制点ControlPointService
+          controlPointService.update(
+            newEdgePoint1,
+            endPoint1,
+            newEdgePoint1,
+            leftEdge1,
+            leftEdge2,
+            "end",
+            "start"
+          );
+        }
       } else {
+        console.log("情况6");
         mathUtil.clonePoint(rightEdge1.end, newEdgePoint2);
         mathUtil.clonePoint(rightEdge2.start, newEdgePoint2);
+        if (angle > Constant.maxAngle) {
+          //要删除控制点
+          dataService.deleteControlPoint(
+            rightEdge1.vectorId,
+            rightEdge2.vectorId
+          );
+        } else {
+          //需要考虑控制点ControlPointService
+          controlPointService.update(
+            newEdgePoint2,
+            endPoint1,
+            newEdgePoint2,
+            rightEdge1,
+            rightEdge2,
+            "end",
+            "start"
+          );
+        }
       }
       return true;
     }
     //end-end
     //left-right,right-left
-    else if (road1.endID == road2.endId) {
+    else if (road1.endId == road2.endId) {
       points.push(endPoint1);
       points.push(startPoint1);
+
+      lineLeft1 = mathUtil.createLine3(line1, leftEdge1.start);
+      lineRight1 = mathUtil.createLine3(line1, rightEdge1.start);
+      lineLeft2 = mathUtil.createLine3(line2, leftEdge2.start);
+      lineRight2 = mathUtil.createLine3(line2, rightEdge2.start);
+
       if (angle > Constant.maxAngle) {
         newEdgePoint1 = mathUtil.getJoinLinePoint(endPoint1, lineLeft1);
         newEdgePoint2 = mathUtil.getJoinLinePoint(endPoint1, lineRight1);
@@ -387,11 +687,51 @@ export default class EdgeService {
       }
       points[2] = newEdgePoint1;
       if (mathUtil.isClockwise(points)) {
+        console.log("情况7");
         mathUtil.clonePoint(leftEdge1.end, newEdgePoint1);
         mathUtil.clonePoint(rightEdge2.end, newEdgePoint1);
+        if (angle > Constant.maxAngle) {
+          //要删除控制点
+          dataService.deleteControlPoint(
+            leftEdge1.vectorId,
+            rightEdge2.vectorId
+          );
+        } else {
+          //需要考虑控制点ControlPointService
+          controlPointService.update(
+            newEdgePoint1,
+            endPoint1,
+            newEdgePoint1,
+            leftEdge1,
+            leftEdge2,
+            "end",
+            "end"
+          );
+        }
       } else {
+        console.log("情况8");
         mathUtil.clonePoint(rightEdge1.end, newEdgePoint2);
         mathUtil.clonePoint(leftEdge2.end, newEdgePoint2);
+        //要删除控制点
+        dataService.deleteControlPoint(leftEdge1.vectorId, rightEdge2.vectorId);
+        if (angle > Constant.maxAngle) {
+          //要删除控制点
+          dataService.deleteControlPoint(
+            rightEdge1.vectorId,
+            leftEdge2.vectorId
+          );
+        } else {
+          //需要考虑控制点ControlPointService
+          controlPointService.update(
+            newEdgePoint2,
+            endPoint1,
+            newEdgePoint2,
+            rightEdge1,
+            leftEdge2,
+            "end",
+            "end"
+          );
+        }
       }
       return true;
     } else {
@@ -512,6 +852,19 @@ export default class EdgeService {
     }
     return;
   }
+
+  // pointId的坐标已经变了
+  updateEdgeForMovePoint(pointId) {
+    const point = dataService.getPoint(pointId);
+    const parent = point.getParent();
+    for (const key in parent) {
+      this.computerDefaultEdge(key);
+      const road = dataService.getRoad(key);
+      const otherPointId = road.getOtherPointId(pointId);
+      this.updateEdgeForMulRoad(otherPointId);
+    }
+    this.updateEdgeForMulRoad(pointId);
+  }
 }
 
 const edgeService = new EdgeService();

+ 7 - 7
src/graphic/Service/ElementService.js

@@ -10,7 +10,7 @@ import { roadService } from "./RoadService.js";
 
 export class ElementService {
   constructor() {
-    this.startAddRoad = null;
+    this.addingRoadPoint = null;
     this.newRoad = null;
 
     this.checkLines = {
@@ -26,8 +26,8 @@ export class ElementService {
   }
 
   init() {
-    this.startAddRoad = new Point(0, 0);
-    this.startAddRoad.name = ElementEvents.StartAddRoad;
+    this.addingRoadPoint = new Point(0, 0);
+    this.addingRoadPoint.name = ElementEvents.AddingRoadPoint;
 
     this.newRoad = new Line({ x: 0, y: 0 }, { x: 1, y: 1 });
     this.newRoad.name = ElementEvents.NewRoad;
@@ -48,15 +48,15 @@ export class ElementService {
   }
 
   showStartAddRoad() {
-    this.startAddRoad.display = true;
+    this.addingRoadPoint.display = true;
   }
 
   hideStartAddRoad() {
-    this.startAddRoad.display = false;
+    this.addingRoadPoint.display = false;
   }
 
-  setStartAddRoad(position) {
-    this.startAddRoad.setPosition(position);
+  setAddingRoadPoint(position) {
+    this.addingRoadPoint.setPosition(position);
   }
 
   showNewRoad() {

+ 1 - 0
src/graphic/Service/RoadService.js

@@ -80,6 +80,7 @@ export default class RoadService {
       //修改旧公路的start
       point.setPointParent(roadId, "start");
     }
+    edgeService.updateEdgeForTwoRoad(roadId, newRoad.vectorId);
     return newRoad.vectorId;
   }
 

+ 1 - 1
src/graphic/Style.js

@@ -50,7 +50,7 @@ const Style = {
     },
   },
   Element: {
-    StartAddRoad: {
+    AddingRoadPoint: {
       radius: 4,
       fillStyle: "yellow",
       strokeStyle: "green",

+ 3 - 3
src/graphic/Util/MathUtil.js

@@ -341,10 +341,10 @@ export default class MathUtil {
 
     if ((180 * fi) / Math.PI < 180) {
       //return 180 * fi / Math.PI;
-      return fi;
+      return (fi * 180) / Math.PI;
     } else {
       //return 360 - 180 * fi / Math.PI;
-      return 2 * Math.PI - fi;
+      return ((2 * Math.PI - fi) * 180) / Math.PI;
     }
   }
 
@@ -401,7 +401,7 @@ export default class MathUtil {
   //方法:point到startPoint和endPoint的距离之和与startPoint和endPoint之间的距离对比
   isContainForSegment(point, startPoint, endPoint, minDis) {
     if (!minDis) {
-      minDis = Constant.minAdsorbPix;
+      minDis = Constant.minLen;
     }
     let dis1 =
       this.getDistance(startPoint, point) + this.getDistance(endPoint, point);

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

@@ -1,5 +1,5 @@
 const ElementEvents = {
-  StartAddRoad: "StartAddRoad",
+  AddingRoadPoint: "AddingRoadPoint",
   NewRoad: "NewRoad",
   CheckLinesX: "CheckLinesX",
   CheckLinesY: "CheckLinesY",