xushiting 2 éve
szülő
commit
a1951a999c

+ 4 - 0
src/graphic/Geometry/Road.js

@@ -19,6 +19,10 @@ export default class Road extends Geometry {
     this.setId(vectorId);
   }
 
+  setWidth(value) {
+    this.width = value;
+  }
+
   getOtherPointId(pointId) {
     if (this.startId == pointId) {
       return this.endId;

+ 0 - 8
src/graphic/Layer.js

@@ -593,8 +593,6 @@ export default class Layer {
             road.leftDrivewayCount + 1,
             "left"
           );
-          roadService.setMidDivideForPointId(road.startId);
-          roadService.setMidDivideForPointId(road.endId);
         } else {
           road = dataService.getCurveRoad(focusItem.vectorId);
           curveRoadService.updateForAddSubtractLanesCount(
@@ -615,8 +613,6 @@ export default class Layer {
             road.leftDrivewayCount - 1,
             "left"
           );
-          roadService.setMidDivideForPointId(road.startId);
-          roadService.setMidDivideForPointId(road.endId);
         } else {
           road = dataService.getCurveRoad(focusItem.vectorId);
           curveRoadService.updateForAddSubtractLanesCount(
@@ -637,8 +633,6 @@ export default class Layer {
             road.rightDrivewayCount + 1,
             "right"
           );
-          roadService.setMidDivideForPointId(road.startId);
-          roadService.setMidDivideForPointId(road.endId);
         } else {
           road = dataService.getCurveRoad(focusItem.vectorId);
           curveRoadService.updateForAddSubtractLanesCount(
@@ -659,8 +653,6 @@ export default class Layer {
             road.rightDrivewayCount - 1,
             "right"
           );
-          roadService.setMidDivideForPointId(road.startId);
-          roadService.setMidDivideForPointId(road.endId);
         } else {
           road = dataService.getCurveRoad(focusItem.vectorId);
           curveRoadService.updateForAddSubtractLanesCount(

+ 140 - 303
src/graphic/Service/CurveRoadService.js

@@ -137,7 +137,7 @@ export default class CurveRoadService extends RoadService {
       rightCurveEdge.points.splice(startIndex + 1, 0, rightJoin);
       curveEdgeService.setCurves(rightCurveEdge);
 
-      for (let i = 0; i < leftCount; ++i) {
+      for (let i = 0; i < leftCount - 1; ++i) {
         const leftLaneLine = mathUtil.createLine1(
           curveRoad.leftLanes[i][startIndex],
           curveRoad.leftLanes[i][startIndex + 1]
@@ -149,7 +149,7 @@ export default class CurveRoadService extends RoadService {
         );
       }
 
-      for (let i = 0; i < rightCount; ++i) {
+      for (let i = 0; i < rightCount - 1; ++i) {
         const rightLaneLine = mathUtil.createLine1(
           curveRoad.rightLanes[i][startIndex],
           curveRoad.rightLanes[i][startIndex + 1]
@@ -270,66 +270,17 @@ export default class CurveRoadService extends RoadService {
     let rightLanes = [];
     let rightLanesCurves = [];
 
-    const len = points.length;
-    // let leftdx1 = leftEdgePoints[0].x - points[0].x;
-    // leftdx1 = leftdx1 / (leftCount + 1);
-
-    // let leftdy1 = leftEdgePoints[0].y - points[0].y;
-    // leftdy1 = leftdy1 / (leftCount + 1);
-
-    // let leftdx2 =
-    //   leftEdgePoints[leftEdgePoints.length - 1].x - points[len - 1].x;
-    // leftdx2 = leftdx2 / (leftCount + 1);
-
-    // let leftdy2 =
-    //   leftEdgePoints[leftEdgePoints.length - 1].y - points[len - 1].y;
-    // leftdy2 = leftdy2 / (leftCount + 1);
-
     if (dir == "left" || !dir) {
-      for (let i = 0; i < leftCount; ++i) {
+      for (let i = 0; i < leftCount - 1; ++i) {
         for (let j = 0; j < points.length; ++j) {
           if (!leftLanes[i]) {
             leftLanes[i] = [];
           }
-          const leftdx = (leftEdgePoints[j].x - points[j].x) / (leftCount + 1);
-          const leftdy = (leftEdgePoints[j].y - points[j].y) / (leftCount + 1);
+          const leftdx = (leftEdgePoints[j].x - points[j].x) / leftCount;
+          const leftdy = (leftEdgePoints[j].y - points[j].y) / leftCount;
           leftLanes[i][j] = {};
           leftLanes[i][j].x = points[j].x + leftdx * (i + 1);
           leftLanes[i][j].y = points[j].y + leftdy * (i + 1);
-          // if (j == 0) {
-          //   leftLanes[i][j].x = points[j].x + leftdx1 * (i + 1);
-          //   leftLanes[i][j].y = points[j].y + leftdy1 * (i + 1);
-          // } else if (j == points.length - 1) {
-          //   leftLanes[i][j].x = points[j].x + leftdx2 * (i + 1);
-          //   leftLanes[i][j].y = points[j].y + leftdy2 * (i + 1);
-          // } else {
-          //   let edgePoints1 = mathUtil.RectangleVertex(
-          //     points[j],
-          //     points[j - 1],
-          //     ((leftEdgePoints[j].x - points[j].x) / (leftCount + 1)) * (i + 1)
-          //   );
-          //   let line1 = mathUtil.createLine1(
-          //     edgePoints1.leftEdgeStart,
-          //     edgePoints1.leftEdgeEnd
-          //   );
-
-          //   let edgePoints2 = mathUtil.RectangleVertex(
-          //     points[j],
-          //     points[j + 1],
-          //     ((leftEdgePoints[j].x - points[j].x) / (leftCount + 1)) * (i + 1)
-          //   );
-          //   let line2 = mathUtil.createLine1(
-          //     edgePoints2.leftEdgeStart,
-          //     edgePoints2.leftEdgeEnd
-          //   );
-
-          //   let join = mathUtil.getIntersectionPoint(line1, line2);
-          //   if (join == null) {
-          //     join = mathUtil.getJoinLinePoint(points[j], line1);
-          //   }
-          //   leftLanes[i][j].x = join.x;
-          //   leftLanes[i][j].y = join.y;
-          // }
         }
         leftLanesCurves[i] = mathUtil.getCurvesByPoints(leftLanes[i]);
       }
@@ -337,69 +288,17 @@ export default class CurveRoadService extends RoadService {
       curveRoad.leftLanesCurves = leftLanesCurves;
     }
 
-    // let rightdx1 = rightEdgePoints[0].x - points[0].x;
-    // rightdx1 = rightdx1 / (rightCount + 1);
-
-    // let rightdy1 = rightEdgePoints[0].y - points[0].y;
-    // rightdy1 = rightdy1 / (rightCount + 1);
-
-    // let rightdx2 =
-    //   rightEdgePoints[rightEdgePoints.length - 1].x - points[len - 1].x;
-    // rightdx2 = rightdx2 / (rightCount + 1);
-
-    // let rightdy2 =
-    //   rightEdgePoints[rightEdgePoints.length - 1].y - points[len - 1].y;
-    // rightdy2 = rightdy2 / (rightCount + 1);
-
     if (dir == "right" || !dir) {
-      for (let i = 0; i < rightCount; ++i) {
+      for (let i = 0; i < rightCount - 1; ++i) {
         for (let j = 0; j < points.length; ++j) {
           if (!rightLanes[i]) {
             rightLanes[i] = [];
           }
-          const rightdx =
-            (rightEdgePoints[j].x - points[j].x) / (rightCount + 1);
-          const rightdy =
-            (rightEdgePoints[j].y - points[j].y) / (rightCount + 1);
+          const rightdx = (rightEdgePoints[j].x - points[j].x) / rightCount;
+          const rightdy = (rightEdgePoints[j].y - points[j].y) / rightCount;
           rightLanes[i][j] = {};
           rightLanes[i][j].x = points[j].x + rightdx * (i + 1);
           rightLanes[i][j].y = points[j].y + rightdy * (i + 1);
-          // if (j == 0) {
-          //   rightLanes[i][j].x = points[j].x + rightdx1 * (i + 1);
-          //   rightLanes[i][j].y = points[j].y + rightdy1 * (i + 1);
-          // } else if (j == points.length - 1) {
-          //   rightLanes[i][j].x = points[j].x + rightdx2 * (i + 1);
-          //   rightLanes[i][j].y = points[j].y + rightdy2 * (i + 1);
-          // } else {
-          //   let edgePoints1 = mathUtil.RectangleVertex(
-          //     points[j],
-          //     points[j - 1],
-          //     ((rightEdgePoints[j].x - points[j].x) / (rightCount + 1)) *
-          //       (i + 1)
-          //   );
-          //   let line1 = mathUtil.createLine1(
-          //     edgePoints1.rightEdgeStart,
-          //     edgePoints1.rightEdgeEnd
-          //   );
-
-          //   let edgePoints2 = mathUtil.RectangleVertex(
-          //     points[j],
-          //     points[j + 1],
-          //     ((rightEdgePoints[j].x - points[j].x) / (rightCount + 1)) *
-          //       (i + 1)
-          //   );
-          //   let line2 = mathUtil.createLine1(
-          //     edgePoints2.rightEdgeStart,
-          //     edgePoints2.rightEdgeEnd
-          //   );
-
-          //   let join = mathUtil.getIntersectionPoint(line1, line2);
-          //   if (join == null) {
-          //     join = mathUtil.getJoinLinePoint(points[j], line1);
-          //   }
-          //   rightLanes[i][j].x = join.x;
-          //   rightLanes[i][j].y = join.y;
-          // }
         }
         rightLanesCurves[i] = mathUtil.getCurvesByPoints(rightLanes[i]);
       }
@@ -411,6 +310,11 @@ export default class CurveRoadService extends RoadService {
   //删除或者减少车道
   updateForAddSubtractLanesCount(curveRoad, newCount, dir) {
     let curveEdge, oldCount, lanes;
+
+    if (newCount < 0) {
+      newCount = 0;
+    }
+
     if (dir == "left") {
       curveEdge = dataService.getCurveEdge(curveRoad.leftEdgeId);
       oldCount = curveRoad.leftDrivewayCount;
@@ -434,12 +338,10 @@ export default class CurveRoadService extends RoadService {
     }
 
     for (let i = 0; i < curveRoad.points.length; ++i) {
-      const dx =
-        (curveEdge.points[i].x - curveRoad.points[i].x) / (oldCount + 1);
-      curveEdge.points[i].x = curveRoad.points[i].x + dx * (newCount + 1);
-      const dy =
-        (curveEdge.points[i].y - curveRoad.points[i].y) / (oldCount + 1);
-      curveEdge.points[i].y = curveRoad.points[i].y + dy * (newCount + 1);
+      const dx = (curveEdge.points[i].x - curveRoad.points[i].x) / oldCount;
+      curveEdge.points[i].x = curveRoad.points[i].x + dx * newCount;
+      const dy = (curveEdge.points[i].y - curveRoad.points[i].y) / oldCount;
+      curveEdge.points[i].y = curveRoad.points[i].y + dy * newCount;
     }
 
     mathUtil.clonePoint(curveEdge.start, curveEdge.points[0]);
@@ -449,23 +351,31 @@ export default class CurveRoadService extends RoadService {
     );
     curveEdgeService.setCurves(curveEdge);
     this.setLanes(curveRoad, dir);
+
+    const line = mathUtil.createLine1(curveRoad.points[0], curveRoad.points[1]);
+    const leftCurveEdge = dataService.getCurveEdge(curveRoad.leftEdgeId);
+    const rightCurveEdge = dataService.getCurveEdge(curveRoad.leftEdgeId);
+    const leftWidth = mathUtil.getDisForPoinLine(leftCurveEdge.start, line);
+    const rightWidth = mathUtil.getDisForPoinLine(rightCurveEdge.start, line);
+    curveRoad.setWidth(leftWidth + rightWidth);
   }
 
   //单车道转多车道,默认是转换成左右两边各一个
   //不改变路的宽度
   singleToMullane(curveRoad) {
-    curveRoad.rightEdgeId = null;
     curveRoad.leftDrivewayCount = 1;
     curveRoad.rightDrivewayCount = 1;
-    let lanes = this.setLanes(curveRoad);
-    curveRoad.leftLanes = lanes.leftLanes;
-    curveRoad.rightLanes = lanes.rightLanes;
-    curveRoad.leftLanesCurves = lanes.leftLanesCurves;
-    curveRoad.rightLanesCurves = lanes.rightLanesCurves;
+    this.setLanes(curveRoad);
   }
 
   //多车道转单车道
   mulToSinglelane(curveRoad) {
+    if (curveRoad.leftDrivewayCount > 0) {
+      this.updateForAddSubtractLanesCount(curveRoad, 1, "left");
+    }
+    if (curveRoad.rightDrivewayCount > 0) {
+      this.updateForAddSubtractLanesCount(curveRoad, 1, "right");
+    }
     curveRoad.leftDrivewayCount = 0;
     curveRoad.rightDrivewayCount = 0;
     curveRoad.leftLanesCurves = [];
@@ -492,13 +402,65 @@ export default class CurveRoadService extends RoadService {
     const leftCurveEdge = dataService.getCurveEdge(curveRoad.leftEdgeId);
     leftCurveEdge.points[index].x += dx;
     leftCurveEdge.points[index].y += dy;
+
+    const rightCurveEdge = dataService.getCurveEdge(curveRoad.rightEdgeId);
+    rightCurveEdge.points[index].x += dx;
+    rightCurveEdge.points[index].y += dy;
+
+    if (index == 0 || index == 1) {
+      line = mathUtil.createLine1(curveRoad.points[0], curveRoad.points[1]);
+      if (
+        line != null &&
+        !line.hasOwnProperty("x") &&
+        !line.hasOwnProperty("y")
+      ) {
+        let line1 = mathUtil.createLine3(line, leftCurveEdge.points[index]);
+        join = mathUtil.getJoinLinePoint(curveRoad.points[0], line1);
+        leftCurveEdge.points[0].x = join.x;
+        leftCurveEdge.points[0].y = join.y;
+        leftCurveEdge.start.x = join.x;
+        leftCurveEdge.start.y = join.y;
+
+        let line2 = mathUtil.createLine3(line, rightCurveEdge.points[index]);
+        join = mathUtil.getJoinLinePoint(curveRoad.points[0], line2);
+        rightCurveEdge.points[0].x = join.x;
+        rightCurveEdge.points[0].y = join.y;
+        rightCurveEdge.start.x = join.x;
+        rightCurveEdge.start.y = join.y;
+      }
+    }
+
+    if (
+      index == curveRoad.points.length - 1 ||
+      index == curveRoad.points.length - 2
+    ) {
+      line = mathUtil.createLine1(
+        curveRoad.points[len - 2],
+        curveRoad.points[len - 1]
+      );
+      if (
+        line != null &&
+        !line.hasOwnProperty("x") &&
+        !line.hasOwnProperty("y")
+      ) {
+        let line1 = mathUtil.createLine3(line, leftCurveEdge.points[index]);
+        join = mathUtil.getJoinLinePoint(curveRoad.points[len - 1], line1);
+        leftCurveEdge.points[len - 1].x = join.x;
+        leftCurveEdge.points[len - 1].y = join.y;
+        leftCurveEdge.end.x = join.x;
+        leftCurveEdge.end.y = join.y;
+        let line2 = mathUtil.createLine3(line, rightCurveEdge.points[index]);
+        join = mathUtil.getJoinLinePoint(curveRoad.points[len - 1], line2);
+        rightCurveEdge.points[len - 1].x = join.x;
+        rightCurveEdge.points[len - 1].y = join.y;
+        rightCurveEdge.end.x = join.x;
+        rightCurveEdge.end.y = join.y;
+      }
+    }
+
     for (let i = 0; i < curveRoad.leftLanes.length; ++i) {
       curveRoad.leftLanes[i][index].x += dx;
       curveRoad.leftLanes[i][index].y += dy;
-      curveRoad.leftLanesCurves[i] = mathUtil.getCurvesByPoints(
-        curveRoad.leftLanes[i]
-      );
-
       //需要修改端点
       if (
         index == 0 ||
@@ -507,39 +469,47 @@ export default class CurveRoadService extends RoadService {
         index == curveRoad.points.length - 2
       ) {
         if (index == 0 || index == 1) {
-          line = mathUtil.createLine1(
-            curveRoad.leftLanes[i][0],
-            curveRoad.leftLanes[i][1]
-          );
-          join = mathUtil.getJoinLinePoint(curveRoad.points[0], line);
-          curveRoad.leftLanes[i][0].x = join.x;
-          curveRoad.leftLanes[i][0].y = join.y;
+          line = mathUtil.createLine1(curveRoad.points[0], curveRoad.points[1]);
+          if (
+            line != null &&
+            !line.hasOwnProperty("x") &&
+            !line.hasOwnProperty("y")
+          ) {
+            line = mathUtil.createLine3(line, curveRoad.leftLanes[i][index]);
+            join = mathUtil.getJoinLinePoint(curveRoad.points[0], line);
+            curveRoad.leftLanes[i][0].x = join.x;
+            curveRoad.leftLanes[i][0].y = join.y;
+          }
         }
+
         if (
           index == curveRoad.points.length - 1 ||
           index == curveRoad.points.length - 2
         ) {
           line = mathUtil.createLine1(
-            curveRoad.leftLanes[i][len - 2],
-            curveRoad.leftLanes[i][len - 1]
+            curveRoad.points[len - 2],
+            curveRoad.points[len - 1]
           );
-          join = mathUtil.getJoinLinePoint(curveRoad.points[len - 1], line);
-          curveRoad.leftLanes[i][len - 1].x = join.x;
-          curveRoad.leftLanes[i][len - 1].y = join.y;
+          if (
+            line != null &&
+            !line.hasOwnProperty("x") &&
+            !line.hasOwnProperty("y")
+          ) {
+            line = mathUtil.createLine3(line, curveRoad.leftLanes[i][index]);
+            join = mathUtil.getJoinLinePoint(curveRoad.points[len - 1], line);
+            curveRoad.leftLanes[i][len - 1].x = join.x;
+            curveRoad.leftLanes[i][len - 1].y = join.y;
+          }
         }
       }
-    }
 
-    const rightCurveEdge = dataService.getCurveEdge(curveRoad.rightEdgeId);
-    rightCurveEdge.points[index].x += dx;
-    rightCurveEdge.points[index].y += dy;
+      curveRoad.leftLanesCurves[i] = mathUtil.getCurvesByPoints(
+        curveRoad.leftLanes[i]
+      );
+    }
     for (let i = 0; i < curveRoad.rightLanes.length; ++i) {
       curveRoad.rightLanes[i][index].x += dx;
       curveRoad.rightLanes[i][index].y += dy;
-      curveRoad.rightLanesCurves[i] = mathUtil.getCurvesByPoints(
-        curveRoad.rightLanes[i]
-      );
-
       //需要修改端点
       if (
         index == 0 ||
@@ -548,66 +518,42 @@ export default class CurveRoadService extends RoadService {
         index == curveRoad.points.length - 2
       ) {
         if (index == 0 || index == 1) {
-          line = mathUtil.createLine1(
-            curveRoad.rightLanes[i][0],
-            curveRoad.rightLanes[i][1]
-          );
-          join = mathUtil.getJoinLinePoint(curveRoad.points[0], line);
-          curveRoad.rightLanes[i][0].x = join.x;
-          curveRoad.rightLanes[i][0].y = join.y;
+          line = mathUtil.createLine1(curveRoad.points[0], curveRoad.points[1]);
+          if (
+            line != null &&
+            !line.hasOwnProperty("x") &&
+            !line.hasOwnProperty("y")
+          ) {
+            line = mathUtil.createLine3(line, curveRoad.rightLanes[i][index]);
+            join = mathUtil.getJoinLinePoint(curveRoad.points[0], line);
+            curveRoad.rightLanes[i][0].x = join.x;
+            curveRoad.rightLanes[i][0].y = join.y;
+          }
         }
         if (
           index == curveRoad.points.length - 1 ||
           index == curveRoad.points.length - 2
         ) {
           line = mathUtil.createLine1(
-            curveRoad.rightLanes[i][len - 2],
-            curveRoad.rightLanes[i][len - 1]
+            curveRoad.points[len - 2],
+            curveRoad.points[len - 1]
           );
-          join = mathUtil.getJoinLinePoint(curveRoad.points[len - 1], line);
-          curveRoad.rightLanes[i][len - 1].x = join.x;
-          curveRoad.rightLanes[i][len - 1].y = join.y;
+          if (
+            line != null &&
+            !line.hasOwnProperty("x") &&
+            !line.hasOwnProperty("y")
+          ) {
+            line = mathUtil.createLine3(line, curveRoad.rightLanes[i][index]);
+            join = mathUtil.getJoinLinePoint(curveRoad.points[len - 1], line);
+            curveRoad.rightLanes[i][len - 1].x = join.x;
+            curveRoad.rightLanes[i][len - 1].y = join.y;
+          }
         }
       }
-    }
-
-    if (index == 0 || index == 1) {
-      line = mathUtil.createLine1(
-        leftCurveEdge.points[0],
-        leftCurveEdge.points[1]
-      );
-      join = mathUtil.getJoinLinePoint(curveRoad.points[0], line);
-      leftCurveEdge.points[0].x = join.x;
-      leftCurveEdge.points[0].y = join.y;
 
-      line = mathUtil.createLine1(
-        rightCurveEdge.points[0],
-        rightCurveEdge.points[1]
-      );
-      join = mathUtil.getJoinLinePoint(curveRoad.points[0], line);
-      rightCurveEdge.points[0].x = join.x;
-      rightCurveEdge.points[0].y = join.y;
-    }
-
-    if (
-      index == curveRoad.points.length - 1 ||
-      index == curveRoad.points.length - 2
-    ) {
-      line = mathUtil.createLine1(
-        leftCurveEdge.points[len - 2],
-        leftCurveEdge.points[len - 1]
-      );
-      join = mathUtil.getJoinLinePoint(curveRoad.points[len - 1], line);
-      leftCurveEdge.points[len - 1].x = join.x;
-      leftCurveEdge.points[len - 1].y = join.y;
-
-      line = mathUtil.createLine1(
-        rightCurveEdge.points[len - 2],
-        rightCurveEdge.points[len - 1]
+      curveRoad.rightLanesCurves[i] = mathUtil.getCurvesByPoints(
+        curveRoad.rightLanes[i]
       );
-      join = mathUtil.getJoinLinePoint(curveRoad.points[len - 1], line);
-      rightCurveEdge.points[len - 1].x = join.x;
-      rightCurveEdge.points[len - 1].y = join.y;
     }
 
     this.setCurves(curveRoad);
@@ -618,115 +564,6 @@ export default class CurveRoadService extends RoadService {
   setCurves(curveRoad) {
     curveRoad.curves = mathUtil.getCurvesByPoints(curveRoad.points);
   }
-
-  // updateForMovePoint(curveRoad, index) {
-  //   let points = curveRoad.points;
-  //   let leftEdge = dataService.getCurveEdge(curveRoad.leftEdgeId);
-  //   let rightEdge = dataService.getCurveEdge(curveRoad.rightEdgeId);
-  //   let leftEdgePoints = leftEdge.points;
-  //   let rightEdgePoints = rightEdge.points;
-  //   let leftCount = curveRoad.leftDrivewayCount;
-  //   let rightCount = curveRoad.rightDrivewayCount;
-
-  //   const len = points.length;
-  //   let leftdx1 = leftEdgePoints[0].x - points[0].x;
-  //   leftdx1 = leftdx1 / leftCount;
-
-  //   let leftdy1 = leftEdgePoints[0].y - points[0].y;
-  //   leftdy1 = leftdy1 / leftCount;
-
-  //   let leftdx2 = leftEdgePoints[len - 1].x - points[len - 1].x;
-  //   leftdx2 = leftdx2 / leftCount;
-
-  //   let leftdy2 = leftEdgePoints[len - 1].y - points[len - 1].y;
-  //   leftdy2 = leftdy2 / leftCount;
-
-  //   for (let i = 0; i < leftCount - 1; ++i) {
-  //     if (index == 0) {
-  //       curveRoad.leftLanes[i][index].x = points[index].x + leftdx1 * (i + 1);
-  //       curveRoad.leftLanes[i][index].y = points[index].y + leftdy1 * (i + 1);
-  //     } else if (index == points.length - 1) {
-  //       curveRoad.leftLanes[i][index].x = points[index].x + leftdx2 * (i + 1);
-  //       curveRoad.leftLanes[i][index].y = points[index].y + leftdy2 * (i + 1);
-  //     } else {
-  //       let edgePoints1 = mathUtil.RectangleVertex(
-  //         points[index],
-  //         points[index - 1],
-  //         leftdx1
-  //       );
-  //       let line1 = mathUtil.createLine1(
-  //         edgePoints1.leftEdgeStart,
-  //         edgePoints1.leftEdgeEnd
-  //       );
-
-  //       let edgePoints2 = mathUtil.RectangleVertex(
-  //         points[index],
-  //         points[index + 1],
-  //         leftdx1
-  //       );
-  //       let line2 = mathUtil.createLine1(
-  //         edgePoints2.leftEdgeStart,
-  //         edgePoints2.leftEdgeEnd
-  //       );
-
-  //       let join = mathUtil.getIntersectionPoint(line1, line2);
-  //       if (join == null) {
-  //         join = mathUtil.getLineForPoint(line1, points[index]);
-  //       }
-  //       curveRoad.leftLanes[i][index].x = join.x;
-  //       curveRoad.leftLanes[i][index].y = join.y;
-  //     }
-  //   }
-
-  //   let rightdx1 = rightEdgePoints[0].x - points[0].x;
-  //   rightdx1 = rightdx1 / rightCount;
-
-  //   let rightdy1 = rightEdgePoints[0].y - points[0].y;
-  //   rightdy1 = rightdy1 / rightCount;
-
-  //   let rightdx2 = rightEdgePoints[len - 1].x - points[len - 1].x;
-  //   rightdx2 = rightdx2 / rightCount;
-
-  //   let rightdy2 = rightEdgePoints[len - 1].y - points[len - 1].y;
-  //   rightdy2 = rightdy2 / rightCount;
-
-  //   for (let i = 0; i < rightCount - 1; ++i) {
-  //     if (index == 0) {
-  //       curveRoad.rightLanes[i][index].x = points[index].x + rightdx1 * (i + 1);
-  //       curveRoad.rightLanes[i][index].y = points[index].y + rightdy1 * (i + 1);
-  //     } else if (index == points.length - 1) {
-  //       curveRoad.rightLanes[i][index].x = points[index].x + rightdy2 * (i + 1);
-  //       curveRoad.rightLanes[i][index].y = points[index].y + rightdy2 * (i + 1);
-  //     } else {
-  //       let edgePoints1 = mathUtil.RectangleVertex(
-  //         points[index],
-  //         points[index - 1],
-  //         rightdx1
-  //       );
-  //       let line1 = mathUtil.createLine1(
-  //         edgePoints1.rightEdgeStart,
-  //         edgePoints1.rightEdgeEnd
-  //       );
-
-  //       let edgePoints2 = mathUtil.RectangleVertex(
-  //         points[index],
-  //         points[index + 1],
-  //         rightdx1
-  //       );
-  //       let line2 = mathUtil.createLine1(
-  //         edgePoints2.rightEdgeStart,
-  //         edgePoints2.rightEdgeEnd
-  //       );
-
-  //       let join = mathUtil.getIntersectionPoint(line1, line2);
-  //       if (join == null) {
-  //         join = mathUtil.getLineForPoint(line1, points[index]);
-  //       }
-  //       curveRoad.rightLanes[i][index].x = join.x;
-  //       curveRoad.rightLanes[i][index].y = join.y;
-  //     }
-  //   }
-  // }
 }
 
 const curveRoadService = new CurveRoadService();

+ 72 - 84
src/graphic/Service/RoadService.js

@@ -906,31 +906,8 @@ export default class RoadService {
     let endPoint = dataService.getPoint(road.endId);
     let leftEdge = dataService.getEdge(road.leftEdgeId);
     let rightEdge = dataService.getEdge(road.rightEdgeId);
-    const leftCount = road.leftDrivewayCount + 1;
-    const rightCount = road.rightDrivewayCount + 1;
-
-    // let midPoint = {
-    //   x: (startPoint.x + endPoint.x) / 2,
-    //   y: (startPoint.y + endPoint.y) / 2,
-    // };
-    // let line = this.getMidLine(road);
-    // let point1 = mathUtil.getJoinLinePoint(leftEdge.start, line);
-    // let _point1 = mathUtil.getJoinLinePoint(rightEdge.start, line);
-    // if (
-    //   mathUtil.getDistance(point1, midPoint) >
-    //   mathUtil.getDistance(_point1, midPoint)
-    // ) {
-    //   point1 = _point1;
-    // }
-
-    // let point2 = mathUtil.getJoinLinePoint(leftEdge.end, line);
-    // let _point2 = mathUtil.getJoinLinePoint(rightEdge.end, line);
-    // if (
-    //   mathUtil.getDistance(point2, midPoint) >
-    //   mathUtil.getDistance(_point2, midPoint)
-    // ) {
-    //   point2 = _point2;
-    // }
+    const leftCount = road.leftDrivewayCount;
+    const rightCount = road.rightDrivewayCount;
 
     let leftdx1 = leftEdge.start.x - startPoint.x;
     leftdx1 = leftdx1 / leftCount;
@@ -956,63 +933,74 @@ export default class RoadService {
     let rightdy2 = rightEdge.end.y - endPoint.y;
     rightdy2 = rightdy2 / rightCount;
 
-    if (road.leftDrivewayCount == 0) {
-      road.leftLanes = [];
-    } else {
-      for (let i = 1; i < leftCount; ++i) {
-        if (!dir) {
-          road.leftLanes[i - 1] = {};
-        }
-        if (dir == "start" || !dir) {
-          road.leftLanes[i - 1].start = {};
-          road.leftLanes[i - 1].start.x = startPoint.x + leftdx1 * i;
-          road.leftLanes[i - 1].start.y = startPoint.y + leftdy1 * i;
-        }
-        if (dir == "end" || !dir) {
-          road.leftLanes[i - 1].end = {};
-          road.leftLanes[i - 1].end.x = endPoint.x + leftdx2 * i;
-          road.leftLanes[i - 1].end.y = endPoint.y + leftdy2 * i;
-        }
+    if (dir == "left" || !dir) {
+      for (let i = 0; i < leftCount - 1; ++i) {
+        road.leftLanes[i] = {};
+
+        road.leftLanes[i].start = {};
+        road.leftLanes[i].start.x = startPoint.x + leftdx1 * (i + 1);
+        road.leftLanes[i].start.y = startPoint.y + leftdy1 * (i + 1);
+
+        road.leftLanes[i].end = {};
+        road.leftLanes[i].end.x = endPoint.x + leftdx2 * (i + 1);
+        road.leftLanes[i].end.y = endPoint.y + leftdy2 * (i + 1);
       }
     }
 
-    if (road.rightDrivewayCount == 0) {
-      road.rightLanes = [];
-    } else {
-      for (let i = 1; i < rightCount; ++i) {
-        if (!dir) {
-          road.rightLanes[i - 1] = {};
-        }
-        if (dir == "start" || !dir) {
-          road.rightLanes[i - 1].start = {};
-          road.rightLanes[i - 1].start.x = startPoint.x + rightdx1 * i;
-          road.rightLanes[i - 1].start.y = startPoint.y + rightdy1 * i;
-        }
-        if (dir == "end" || !dir) {
-          road.rightLanes[i - 1].end = {};
-          road.rightLanes[i - 1].end.x = endPoint.x + rightdx2 * i;
-          road.rightLanes[i - 1].end.y = endPoint.y + rightdy2 * i;
-        }
+    if (dir == "right" || !dir) {
+      for (let i = 0; i < rightCount - 1; ++i) {
+        road.rightLanes[i] = {};
+
+        road.rightLanes[i].start = {};
+        road.rightLanes[i].start.x = startPoint.x + rightdx1 * (i + 1);
+        road.rightLanes[i].start.y = startPoint.y + rightdy1 * (i + 1);
+
+        road.rightLanes[i].end = {};
+        road.rightLanes[i].end.x = endPoint.x + rightdx2 * (i + 1);
+        road.rightLanes[i].end.y = endPoint.y + rightdy2 * (i + 1);
       }
     }
   }
 
+  singleToMullane(road) {
+    road.leftDrivewayCount = 1;
+    road.rightDrivewayCount = 1;
+    this.setMidDivide(road.vectorId);
+    this.setLanes(road.vectorId);
+  }
+
+  //多车道转单车道
+  mulToSinglelane(road) {
+    if (road.leftDrivewayCount > 0) {
+      this.updateForAddSubtractLanesCount(road.vectorId, 1, "left");
+    }
+    if (road.rightDrivewayCount > 0) {
+      this.updateForAddSubtractLanesCount(road.vectorId, 1, "right");
+    }
+    road.leftDrivewayCount = 0;
+    road.rightDrivewayCount = 0;
+    road.leftLanes = [];
+    road.rightLanes = [];
+    this.setMidDivide(road.vectorId);
+  }
+
   //删除或者减少车道
   //需要考虑车道个数是0(左或者右)的情况
   updateForAddSubtractLanesCount(roadId, newCount, dir) {
-    let dx1, dy1, dx2, dy2, oldCount, lanes, edgeStartPosition, edgeEndPosition;
+    let dx1, dy1, dx2, dy2, oldCount, edgeStartPosition, edgeEndPosition;
     let road = dataService.getRoad(roadId);
-    if (newCount == 0) {
-      //需要添加隐藏隔离栏
-      return;
+
+    if (newCount < 0) {
+      newCount = 0;
     }
+
     let startPoint = dataService.getPoint(road.startId);
     let endPoint = dataService.getPoint(road.endId);
     let leftEdge = dataService.getEdge(road.leftEdgeId);
     let rightEdge = dataService.getEdge(road.rightEdgeId);
 
     if (dir == "left") {
-      oldCount = road.leftDrivewayCount + 1;
+      oldCount = road.leftDrivewayCount;
       if (oldCount != 0) {
         dx1 = leftEdge.start.x - startPoint.x;
         dx1 = dx1 / oldCount;
@@ -1023,10 +1011,10 @@ export default class RoadService {
         dx2 = dx2 / oldCount;
         dy2 = leftEdge.end.y - endPoint.y;
         dy2 = dy2 / oldCount;
-        //road.midDivide.display = true;
       }
+      road.leftDrivewayCount = newCount;
     } else if (dir == "right") {
-      oldCount = road.rightDrivewayCount + 1;
+      oldCount = road.rightDrivewayCount;
       if (oldCount != 0) {
         dx1 = rightEdge.start.x - startPoint.x;
         dx1 = dx1 / oldCount;
@@ -1037,46 +1025,46 @@ export default class RoadService {
         dx2 = dx2 / oldCount;
         dy2 = rightEdge.end.y - endPoint.y;
         dy2 = dy2 / oldCount;
-        //road.midDivide.display = true;
       }
+      road.rightDrivewayCount = newCount;
     }
 
-    lanes = [];
-    for (let i = 0; i < newCount; ++i) {
-      lanes[i] = {};
-      lanes[i].start = {};
-      lanes[i].start.x = startPoint.x + dx1 * (i + 1);
-      lanes[i].start.y = startPoint.y + dy1 * (i + 1);
-
-      lanes[i].end = {};
-      lanes[i].end.x = endPoint.x + dx2 * (i + 1);
-      lanes[i].end.y = endPoint.y + dy2 * (i + 1);
+    if (newCount == oldCount) {
+      return;
+    } else if (newCount == 0) {
+      this.mulToSinglelane(road);
+      return;
+    } else if (oldCount == 0) {
+      this.singleToMullane(road);
+      return;
     }
+
     edgeStartPosition = {
-      x: startPoint.x + dx1 * (newCount + 1),
-      y: startPoint.y + dy1 * (newCount + 1),
+      x: startPoint.x + dx1 * newCount,
+      y: startPoint.y + dy1 * newCount,
     };
     edgeEndPosition = {
-      x: endPoint.x + dx2 * (newCount + 1),
-      y: endPoint.y + dy2 * (newCount + 1),
+      x: endPoint.x + dx2 * newCount,
+      y: endPoint.y + dy2 * newCount,
     };
 
     if (dir == "left") {
-      road.leftLanes = lanes;
       mathUtil.clonePoint(leftEdge.start, edgeStartPosition);
       mathUtil.clonePoint(leftEdge.end, edgeEndPosition);
       road.leftDrivewayCount = newCount;
     } else if (dir == "right") {
-      road.rightLanes = lanes;
       mathUtil.clonePoint(rightEdge.start, edgeStartPosition);
       mathUtil.clonePoint(rightEdge.end, edgeEndPosition);
       road.rightDrivewayCount = newCount;
     }
+
     let join = mathUtil.getJoinLinePoint(
       leftEdge.start,
       mathUtil.createLine1(rightEdge.start, rightEdge.end)
     );
-    road.width = mathUtil.getDistance(leftEdge.start, join);
+    road.setWidth(mathUtil.getDistance(leftEdge.start, join));
+    edgeService.updateEdgeForMulRoad(road.startId);
+    edgeService.updateEdgeForMulRoad(road.endId);
   }
   /****************************************************************************************************************************************************************/
 }