xushiting 2 лет назад
Родитель
Сommit
0f939bed68

+ 2 - 0
src/graphic/Constant.js

@@ -32,5 +32,7 @@ const Constant = {
   maxAngle: 170,
   minRoadSideWidth: 30,
   maxRoadSideWidth: 800,
+  oneWay: "oneWay", //one表示单向,two表示双向
+  twoWay: "twoWay", //one表示单向,two表示双向
 };
 export default Constant;

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

@@ -57,7 +57,6 @@ export default class AddRoad {
       for (let key in parent) {
         if (hasComputerRoadIds.indexOf(key) < 0) {
           roadService.setLanes(key);
-          roadService.setMidDivide(key, parent[key]);
           hasComputerRoadIds.push(key);
         }
       }

+ 0 - 1
src/graphic/Controls/MoveRoad.js

@@ -991,7 +991,6 @@ export default class MoveRoad {
       rightEdge.end.y += dy;
 
       roadService.setLanes(roadId);
-      roadService.setMidDivide(roadId);
     }
   }
 

+ 3 - 0
src/graphic/Geometry/CurveRoad.js

@@ -8,12 +8,15 @@ export default class CurveRoad extends Road {
     this.points = []; //中心线上一系列控制点。数组是从start到end。
     this.leftLanesCurves = []; //左车道曲线
     this.rightLanesCurves = []; //左车道曲线
+    this.singleLanesCurves = []; //单向车道
     this.leftDrivewayCount = Setting.curveRoadLeftDrivewayCount; //左边的车道个数
     this.rightDrivewayCount = Setting.curveRoadRightDrivewayCount; //右边的车道个数
     this.leftWidth = Setting.leftCurveRoadWidth;
     this.rightWidth = Setting.rightCurveRoadWidth;
     this.midDivideWidth = Setting.curveRoadMidDivideWidth;
     this.curves = [];
+    this.singleCurveRoadWidth = Setting.singleCurveRoadWidth;
+    this.singleCurveRoadDrivewayCount = Setting.singleCurveRoadDrivewayCount;
     this.geoType = VectorType.CurveRoad;
     this.setId(vectorId);
   }

+ 14 - 5
src/graphic/Geometry/Road.js

@@ -1,6 +1,7 @@
 import VectorType from "../enum/VectorType.js";
 import Geometry from "./Geometry.js";
 import Setting from "../Setting";
+import Constant from "../Constant";
 
 export default class Road extends Geometry {
   constructor(startId, endId, vectorId) {
@@ -11,21 +12,29 @@ export default class Road extends Geometry {
     this.rightEdgeId = null;
     this.leftLanes = []; //二维数组。第一维表示第几个车道,第二维是一组点
     this.rightLanes = [];
+    this.singleLanes = []; //单向车道
     this.midDivide = null; //道路中间隔离栏 ,起点和终点与startId和endId方向一致。但是坐标有区别。因为隔离栏要比start-end短一些
+    this.midDivideWidth = Setting.roadMidDivideWidth; //单向车道没有中间栏
     this.leftDrivewayCount = Setting.roadLeftDrivewayCount; //左边的车道个数
     this.rightDrivewayCount = Setting.roadRightDrivewayCount; //右边的车道个数
     this.geoType = VectorType.Road;
     this.leftWidth = Setting.leftRoadWidth;
     this.rightWidth = Setting.rightRoadWidth;
-    this.midDivideWidth = Setting.roadMidDivideWidth;
+    this.singleRoadWidth = Setting.singleRoadWidth;
+    this.singleRoadDrivewayCount = Setting.singleRoadDrivewayCount;
+    this.way = Setting.wayType;
     this.setId(vectorId);
   }
 
   setWidth(value, dir) {
-    if (dir == "left") {
-      this.leftWidth = value;
-    } else if (dir == "right") {
-      this.rightWidth = value;
+    if (this.way == Constant.twoWay) {
+      if (dir == "left") {
+        this.leftWidth = value;
+      } else if (dir == "right") {
+        this.rightWidth = value;
+      }
+    } else if (this.way == Constant.oneWay) {
+      this.singleRoadWidth = value;
     }
   }
 

+ 0 - 1
src/graphic/Layer.js

@@ -539,7 +539,6 @@ export default class Layer {
           let parent = point.getParent();
           for (let key in parent) {
             roadService.setLanes(key);
-            roadService.setMidDivide(key, parent[key]);
           }
           this.history.save();
         }

+ 418 - 157
src/graphic/Service/CurveRoadService.js

@@ -23,11 +23,21 @@ export default class CurveRoadService extends RoadService {
     endPoint.setPointParent(curveRoad.vectorId);
     endPoint.setIndex(2);
 
-    let edgePoints = mathUtil.RectangleVertex(
-      startPoint,
-      endPoint,
-      curveRoad.leftWidth + curveRoad.rightWidth + curveRoad.midDivideWidth
-    );
+    let edgePoints;
+    if (curveRoad.way == Constant.oneWay) {
+      edgePoints = mathUtil.RectangleVertex(
+        startPoint,
+        endPoint,
+        road.singleRoadWidth
+      );
+    } else {
+      edgePoints = mathUtil.RectangleVertex(
+        startPoint,
+        endPoint,
+        curveRoad.leftWidth + curveRoad.rightWidth + curveRoad.midDivideWidth
+      );
+    }
+
     let leftEdge = curveEdgeService.create(
       edgePoints.leftEdgeStart,
       edgePoints.leftEdgeEnd,
@@ -58,8 +68,6 @@ export default class CurveRoadService extends RoadService {
     rightEdge.points.push(edgePoints.rightEdgeStart);
     rightEdge.points.push(edgePoints.rightEdgeEnd);
 
-    this.setLanes(curveRoad);
-
     this.addCPoint(
       curveRoad,
       {
@@ -68,10 +76,12 @@ export default class CurveRoadService extends RoadService {
       },
       0
     );
+    this.setLanes(curveRoad.vectorId);
     return curveRoad;
   }
 
   //不能加首尾,只能加中间
+  //完全不处理车道,都放在setLanes上处理
   addCPoint(curveRoad, position, startIndex) {
     let point = curveRoadPointService.create(position);
     curveRoad.points.splice(startIndex + 1, 0, point);
@@ -150,73 +160,125 @@ export default class CurveRoadService extends RoadService {
       rightCurveEdge.points.splice(startIndex + 1, 0, rightJoin);
       curveEdgeService.setCurves(rightCurveEdge);
 
-      for (let i = 0; i < leftCount - 1; ++i) {
-        const leftLaneLine = mathUtil.createLine1(
-          curveRoad.leftLanes[i][startIndex],
-          curveRoad.leftLanes[i][startIndex + 1]
-        );
-        leftJoin = mathUtil.getJoinLinePoint(position, leftLaneLine);
-        leftJoin.x += dx;
-        leftJoin.y += dy;
-        curveRoad.leftLanes[i].splice(startIndex + 1, 0, leftJoin);
-        curveRoad.leftLanesCurves[i] = mathUtil.getCurvesByPoints(
-          curveRoad.leftLanes[i]
-        );
-      }
-
-      for (let i = 0; i < rightCount - 1; ++i) {
-        const rightLaneLine = mathUtil.createLine1(
-          curveRoad.rightLanes[i][startIndex],
-          curveRoad.rightLanes[i][startIndex + 1]
-        );
-        rightJoin = mathUtil.getJoinLinePoint(position, rightLaneLine);
-        rightJoin.x += dx;
-        rightJoin.y += dy;
-        curveRoad.rightLanes[i].splice(startIndex + 1, 0, rightJoin);
-        curveRoad.rightLanesCurves[i] = mathUtil.getCurvesByPoints(
-          curveRoad.rightLanes[i]
-        );
-      }
+      // for (let i = 0; i < leftCount - 1; ++i) {
+      //   const leftLaneLine = mathUtil.createLine1(
+      //     curveRoad.leftLanes[i][startIndex],
+      //     curveRoad.leftLanes[i][startIndex + 1]
+      //   );
+      //   leftJoin = mathUtil.getJoinLinePoint(position, leftLaneLine);
+      //   leftJoin.x += dx;
+      //   leftJoin.y += dy;
+      //   curveRoad.leftLanes[i].splice(startIndex + 1, 0, leftJoin);
+      //   curveRoad.leftLanesCurves[i] = mathUtil.getCurvesByPoints(
+      //     curveRoad.leftLanes[i]
+      //   );
+      // }
+
+      // const leftMidDivideLine = mathUtil.createLine1(
+      //   curveRoad.midDivide.leftMidDivide[startIndex],
+      //   curveRoad.midDivide.leftMidDivide[startIndex + 1]
+      // );
+      // leftJoin = mathUtil.getJoinLinePoint(position, leftMidDivideLine);
+      // leftJoin.x += dx;
+      // leftJoin.y += dy;
+      // curveRoad.midDivide.leftMidDivide.splice(startIndex + 1, 0, leftJoin);
+      // curveRoad.midDivide.leftMidDivideCurves = mathUtil.getCurvesByPoints(
+      //   curveRoad.midDivide.leftMidDivide
+      // );
+
+      // for (let i = 0; i < rightCount - 1; ++i) {
+      //   const rightLaneLine = mathUtil.createLine1(
+      //     curveRoad.rightLanes[i][startIndex],
+      //     curveRoad.rightLanes[i][startIndex + 1]
+      //   );
+      //   rightJoin = mathUtil.getJoinLinePoint(position, rightLaneLine);
+      //   rightJoin.x += dx;
+      //   rightJoin.y += dy;
+      //   curveRoad.rightLanes[i].splice(startIndex + 1, 0, rightJoin);
+      //   curveRoad.rightLanesCurves[i] = mathUtil.getCurvesByPoints(
+      //     curveRoad.rightLanes[i]
+      //   );
+      // }
+
+      // const rightMidDivideLine = mathUtil.createLine1(
+      //   curveRoad.midDivide.rightMidDivide[startIndex],
+      //   curveRoad.midDivide.rightMidDivide[startIndex + 1]
+      // );
+      // rightJoin = mathUtil.getJoinLinePoint(position, rightMidDivideLine);
+      // rightJoin.x += dx;
+      // rightJoin.y += dy;
+      // curveRoad.midDivide.rightMidDivide.splice(startIndex + 1, 0, rightJoin);
+      // curveRoad.midDivide.rightMidDivideCurves = mathUtil.getCurvesByPoints(
+      //   curveRoad.midDivide.rightMidDivide
+      // );
     } else {
       leftJoin = mathUtil.getIntersectionPoint(leftLine1, leftLine2);
       leftCurveEdge.points.splice(startIndex + 1, 0, leftJoin);
       curveEdgeService.setCurves(leftCurveEdge);
 
-      for (let i = 0; i < leftCount - 1; ++i) {
-        leftLine1 = mathUtil.createLine3(
-          line1,
-          curveRoad.leftLanes[i][startIndex]
-        );
-        leftLine2 = mathUtil.createLine3(
-          line2,
-          curveRoad.leftLanes[i][startIndex + 1]
-        );
-        leftJoin = mathUtil.getIntersectionPoint(leftLine1, leftLine2);
-        curveRoad.leftLanes[i].splice(startIndex + 1, 0, leftJoin);
-        curveRoad.leftLanesCurves[i] = mathUtil.getCurvesByPoints(
-          curveRoad.leftLanes[i]
-        );
-      }
+      // for (let i = 0; i < leftCount - 1; ++i) {
+      //   leftLine1 = mathUtil.createLine3(
+      //     line1,
+      //     curveRoad.leftLanes[i][startIndex]
+      //   );
+      //   leftLine2 = mathUtil.createLine3(
+      //     line2,
+      //     curveRoad.leftLanes[i][startIndex + 1]
+      //   );
+      //   leftJoin = mathUtil.getIntersectionPoint(leftLine1, leftLine2);
+      //   curveRoad.leftLanes[i].splice(startIndex + 1, 0, leftJoin);
+      //   curveRoad.leftLanesCurves[i] = mathUtil.getCurvesByPoints(
+      //     curveRoad.leftLanes[i]
+      //   );
+      // }
+
+      // leftLine1 = mathUtil.createLine3(
+      //   line1,
+      //   curveRoad.midDivide.leftMidDivide[startIndex]
+      // );
+      // leftLine2 = mathUtil.createLine3(
+      //   line2,
+      //   ccurveRoad.midDivide.leftMidDivide[startIndex + 1]
+      // );
+      // leftJoin = mathUtil.getIntersectionPoint(leftLine1, leftLine2);
+      // curveRoad.midDivide.leftMidDivide.splice(startIndex + 1, 0, leftJoin);
+      // curveRoad.midDivide.leftMidDivideCurves = mathUtil.getCurvesByPoints(
+      //   curveRoad.midDivide.leftMidDivide
+      // );
 
       rightJoin = mathUtil.getIntersectionPoint(rightLine1, rightLine2);
       rightCurveEdge.points.splice(startIndex + 1, 0, rightJoin);
       curveEdgeService.setCurves(rightCurveEdge);
 
-      for (let i = 0; i < rightCount - 1; ++i) {
-        rightLine1 = mathUtil.createLine3(
-          line1,
-          curveRoad.rightLanes[i][startIndex]
-        );
-        rightLine2 = mathUtil.createLine3(
-          line2,
-          curveRoad.rightLanes[i][startIndex + 1]
-        );
-        rightJoin = mathUtil.getIntersectionPoint(rightLine1, rightLine2);
-        curveRoad.rightLanes[i].splice(startIndex + 1, 0, rightJoin);
-        curveRoad.rightLanesCurves[i] = mathUtil.getCurvesByPoints(
-          curveRoad.rightLanes[i]
-        );
-      }
+      // for (let i = 0; i < rightCount - 1; ++i) {
+      //   rightLine1 = mathUtil.createLine3(
+      //     line1,
+      //     curveRoad.rightLanes[i][startIndex]
+      //   );
+      //   rightLine2 = mathUtil.createLine3(
+      //     line2,
+      //     curveRoad.rightLanes[i][startIndex + 1]
+      //   );
+      //   rightJoin = mathUtil.getIntersectionPoint(rightLine1, rightLine2);
+      //   curveRoad.rightLanes[i].splice(startIndex + 1, 0, rightJoin);
+      //   curveRoad.rightLanesCurves[i] = mathUtil.getCurvesByPoints(
+      //     curveRoad.rightLanes[i]
+      //   );
+      // }
+
+      // rightLine1 = mathUtil.createLine3(
+      //   line1,
+      //   curveRoad.midDivide.rightMidDivide[startIndex]
+      // );
+      // rightLine2 = mathUtil.createLine3(
+      //   line2,
+      //   ccurveRoad.midDivide.rightMidDivide[startIndex + 1]
+      // );
+      // rightJoin = mathUtil.getIntersectionPoint(rightLine1, rightLine2);
+      // curveRoad.midDivide.rightMidDivide.splice(startIndex + 1, 0, rightJoin);
+      // curveRoad.midDivide.rightMidDivideCurves = mathUtil.getCurvesByPoints(
+      //   curveRoad.midDivide.rightMidDivide
+      // );
     }
     this.setCurves(curveRoad);
   }
@@ -237,43 +299,67 @@ export default class CurveRoadService extends RoadService {
     rightCurveEdge.points.splice(index, 1);
     curveEdgeService.setCurves(rightCurveEdge);
 
-    this.removeCPointToLanes(curveRoad, index);
+    // curveRoad.midDivide.leftMidDivide.splice(index, 1);
+    // curveRoad.midDivide.leftMidDivideCurves =
+    //   mathUtil.getCurvesByPoints(leftMidDivide);
+    // curveRoad.midDivide.rightMidDivide.splice(index, 1);
+    // curveRoad.midDivide.rightMidDivideCurves =
+    //   mathUtil.getCurvesByPoints(rightMidDivide);
+    // this.removeCPointToLanes(curveRoad, index);
   }
 
-  removeCPointToLanes(curveRoad, index) {
-    for (let i = 0; i < curveRoad.leftLanes.length; ++i) {
-      curveRoad.leftLanes[i].splice(index, 1);
-      curveRoad.leftLanesCurves[i] = mathUtil.getCurvesByPoints(
-        curveRoad.leftLanes[i]
-      );
-    }
-    for (let i = 0; i < curveRoad.rightLanes.length; ++i) {
-      curveRoad.rightLanes[i].splice(index, 1);
-      curveRoad.rightLanesCurves[i] = mathUtil.getCurvesByPoints(
-        curveRoad.rightLanes[i]
-      );
-    }
-  }
+  // removeCPointToLanes(curveRoad, index) {
+  //   for (let i = 0; i < curveRoad.leftLanes.length; ++i) {
+  //     curveRoad.leftLanes[i].splice(index, 1);
+  //     curveRoad.leftLanesCurves[i] = mathUtil.getCurvesByPoints(
+  //       curveRoad.leftLanes[i]
+  //     );
+  //   }
+  //   for (let i = 0; i < curveRoad.rightLanes.length; ++i) {
+  //     curveRoad.rightLanes[i].splice(index, 1);
+  //     curveRoad.rightLanesCurves[i] = mathUtil.getCurvesByPoints(
+  //       curveRoad.rightLanes[i]
+  //     );
+  //   }
+  // }
+
+  //单向车道
+  setOneWayLanes(curveRoad) {
+    let points = curveRoad.points;
+    const leftEdge = dataService.getCurveRoadEdge(curveRoad.leftEdgeId);
+    const rightEdge = dataService.getCurveRoadEdge(curveRoad.rightEdgeId);
+    const leftEdgePoints = leftEdge.points;
+    const rightEdgePoints = rightEdge.points;
+    const singleRoadDrivewayCount = curveRoad.singleRoadDrivewayCount;
 
-  setLanesPoints(curveRoadId) {
-    let curveRoad = dataService.getCurveRoad(curveRoadId);
-    let startPoint = dataService.getRoadPoint(curveRoad.startId);
-    let endPoint = dataService.getRoadPoint(curveRoad.endId);
+    let singleLanes = [];
+    let singleLanesCurves = [];
 
-    let midPoint = curveRoadPointService.create({
-      x: (startPoint.x + endPoint.x) / 2,
-      y: (startPoint.y + endPoint.y) / 2,
-    });
+    for (let i = 0; i < singleRoadDrivewayCount - 1; ++i) {
+      for (let j = 0; j < points.length; ++j) {
+        if (!singleLanes[i]) {
+          singleLanes[i] = [];
+        }
 
-    curveRoad.points = [];
-    curveRoad.points.push(startPoint);
-    curveRoad.points.push(midPoint);
-    curveRoad.points.push(endPoint);
+        const dx =
+          (leftEdgePoints[j].x - rightEdgePoints[j].x) /
+          singleRoadDrivewayCount;
+        const dy =
+          (leftEdgePoints[j].y - rightEdgePoints[j].y) /
+          singleRoadDrivewayCount;
+
+        singleLanes[i][j] = {};
+        singleLanes[i][j].x = points[j].x + dx;
+        singleLanes[i][j].y = points[j].y + dy;
+      }
+      singleLanesCurves[i] = mathUtil.getCurvesByPoints(singleLanes[i]);
+    }
+    curveRoad.singleLanes = singleLanes;
+    curveRoad.singleLanesCurves = singleLanesCurves;
   }
 
-  //车道
-  //points的第一个元素是start,最后一个是end
-  setLanes(curveRoad, dir) {
+  //双向车道
+  setTwoWayLanes(curveRoad, dir) {
     let points = curveRoad.points;
     const leftEdge = dataService.getCurveRoadEdge(curveRoad.leftEdgeId);
     const rightEdge = dataService.getCurveRoadEdge(curveRoad.rightEdgeId);
@@ -282,6 +368,16 @@ export default class CurveRoadService extends RoadService {
     const leftCount = curveRoad.leftDrivewayCount;
     const rightCount = curveRoad.rightDrivewayCount;
 
+    if (!curveRoad.midDivide) {
+      curveRoad.midDivide = {
+        leftMidDivide: [],
+        leftMidDivideCurves: [],
+        rightMidDivide: [],
+        rightMidDivideCurves: [],
+      };
+    }
+    let leftMidDivide = [];
+    let rightMidDivide = [];
     let leftLanes = [];
     let leftLanesCurves = [];
     let rightLanes = [];
@@ -305,9 +401,31 @@ export default class CurveRoadService extends RoadService {
           leftLanes[i][j] = {};
           leftLanes[i][j].x = points[j].x + middx + leftdx * (i + 1);
           leftLanes[i][j].y = points[j].y + middy + leftdy * (i + 1);
+          if (!leftMidDivide[j]) {
+            leftMidDivide[j] = {};
+            leftMidDivide[j].x = points[j].x + middx;
+            leftMidDivide[j].y = points[j].y + middy;
+          }
         }
         leftLanesCurves[i] = mathUtil.getCurvesByPoints(leftLanes[i]);
       }
+
+      if (leftMidDivide.length == 0) {
+        for (let j = 0; j < points.length; ++j) {
+          const leftRatio =
+            curveRoad.leftWidth /
+            (curveRoad.leftWidth + curveRoad.midDivideWidth / 2);
+          const middx = (leftEdgePoints[j].x - points[j].x) * (1 - leftRatio);
+          const middy = (leftEdgePoints[j].y - points[j].y) * (1 - leftRatio);
+          leftMidDivide[j] = {};
+          leftMidDivide[j].x = points[j].x + middx;
+          leftMidDivide[j].y = points[j].y + middy;
+        }
+      }
+      curveRoad.midDivide.leftMidDivide = leftMidDivide;
+      curveRoad.midDivide.leftMidDivideCurves =
+        mathUtil.getCurvesByPoints(leftMidDivide);
+
       curveRoad.leftLanes = leftLanes;
       curveRoad.leftLanesCurves = leftLanesCurves;
     }
@@ -330,38 +448,73 @@ export default class CurveRoadService extends RoadService {
           rightLanes[i][j] = {};
           rightLanes[i][j].x = points[j].x + middx + rightdx * (i + 1);
           rightLanes[i][j].y = points[j].y + middy + rightdy * (i + 1);
+          if (!rightMidDivide[j]) {
+            rightMidDivide[j] = {};
+            rightMidDivide[j].x = points[j].x + middx;
+            rightMidDivide[j].y = points[j].y + middy;
+          }
         }
         rightLanesCurves[i] = mathUtil.getCurvesByPoints(rightLanes[i]);
       }
+      if (rightMidDivide.length == 0) {
+        for (let j = 0; j < points.length; ++j) {
+          const rightRatio =
+            curveRoad.rightWidth /
+            (curveRoad.rightWidth + curveRoad.midDivideWidth / 2);
+          const middx = (rightEdgePoints[j].x - points[j].x) * (1 - rightRatio);
+          const middy = (rightEdgePoints[j].y - points[j].y) * (1 - rightRatio);
+          rightMidDivide[j] = {};
+          rightMidDivide[j].x = points[j].x + middx;
+          rightMidDivide[j].y = points[j].y + middy;
+        }
+      }
+      curveRoad.midDivide.rightMidDivide = rightMidDivide;
+      curveRoad.midDivide.rightMidDivideCurves =
+        mathUtil.getCurvesByPoints(rightMidDivide);
       curveRoad.rightLanes = rightLanes;
       curveRoad.rightLanesCurves = rightLanesCurves;
     }
   }
 
+  //车道
+  //points的第一个元素是start,最后一个是end
+  setLanes(curveRoadId, dir) {
+    let curveRoad = dataService.getCurveRoad(curveRoadId);
+    if (curveRoad.way == Constant.oneWay) {
+      this.setOneWayLanes(curveRoad);
+    } else if (curveRoad.way == Constant.twoWay) {
+      this.setTwoWayLanes(curveRoad, dir);
+    }
+  }
+
   //删除或者减少车道
   updateForAddSubtractLanesCount(curveRoad, newCount, dir) {
     let curveEdge, oldCount, lanes;
-
+    const leftCurveEdge = dataService.getCurveRoadEdge(curveRoad.leftEdgeId);
+    const rightCurveEdge = dataService.getCurveRoadEdge(curveRoad.rightEdgeId);
     if (newCount < 0) {
       newCount = 0;
     }
+
     let ratio = null;
-    if (dir == "left") {
-      curveEdge = dataService.getCurveRoadEdge(curveRoad.leftEdgeId);
-      oldCount = curveRoad.leftDrivewayCount;
-      curveRoad.leftDrivewayCount = newCount;
-      lanes = curveRoad.leftLanes;
-      ratio =
-        curveRoad.leftWidth /
-        (curveRoad.leftWidth + curveRoad.midDivideWidth / 2);
-    } else if (dir == "right") {
-      curveEdge = dataService.getCurveRoadEdge(curveRoad.rightEdgeId);
-      oldCount = curveRoad.rightDrivewayCount;
-      curveRoad.rightDrivewayCount = newCount;
-      lanes = curveRoad.rightLanes;
-      ratio =
-        curveRoad.rightWidth /
-        (curveRoad.rightWidth + curveRoad.midDivideWidth / 2);
+    if (curveRoad.way == Constant.twoWay) {
+      if (dir == "left") {
+        curveEdge = dataService.getCurveRoadEdge(curveRoad.leftEdgeId);
+        oldCount = curveRoad.leftDrivewayCount;
+        curveRoad.leftDrivewayCount = newCount;
+        lanes = curveRoad.leftLanes;
+        ratio =
+          curveRoad.leftWidth /
+          (curveRoad.leftWidth + curveRoad.midDivideWidth / 2);
+      } else if (dir == "right") {
+        curveEdge = dataService.getCurveRoadEdge(curveRoad.rightEdgeId);
+        oldCount = curveRoad.rightDrivewayCount;
+        curveRoad.rightDrivewayCount = newCount;
+        lanes = curveRoad.rightLanes;
+        ratio =
+          curveRoad.rightWidth /
+          (curveRoad.rightWidth + curveRoad.midDivideWidth / 2);
+      }
     }
 
     if (newCount == oldCount) {
@@ -374,51 +527,91 @@ export default class CurveRoadService extends RoadService {
       return;
     }
 
-    for (let i = 0; i < curveRoad.points.length; ++i) {
-      const middx =
-        (curveEdge.points[i].x - curveRoad.points[i].x) * (1 - ratio);
-      const middy =
-        (curveEdge.points[i].y - curveRoad.points[i].y) * (1 - ratio);
-      const dx =
-        ((curveEdge.points[i].x - curveRoad.points[i].x) * ratio) / oldCount;
-      curveEdge.points[i].x = curveRoad.points[i].x + middx + dx * newCount;
-      const dy =
-        ((curveEdge.points[i].y - curveRoad.points[i].y) * ratio) / oldCount;
-      curveEdge.points[i].y = curveRoad.points[i].y + middy + dy * newCount;
-    }
+    if (curveRoad.way == Constant.twoWay) {
+      for (let i = 0; i < curveRoad.points.length; ++i) {
+        const middx =
+          (curveEdge.points[i].x - curveRoad.points[i].x) * (1 - ratio);
+        const middy =
+          (curveEdge.points[i].y - curveRoad.points[i].y) * (1 - ratio);
+        const dx =
+          ((curveEdge.points[i].x - curveRoad.points[i].x) * ratio) / oldCount;
+        curveEdge.points[i].x = curveRoad.points[i].x + middx + dx * newCount;
+        const dy =
+          ((curveEdge.points[i].y - curveRoad.points[i].y) * ratio) / oldCount;
+        curveEdge.points[i].y = curveRoad.points[i].y + middy + dy * newCount;
+      }
 
-    mathUtil.clonePoint(curveEdge.start, curveEdge.points[0]);
-    mathUtil.clonePoint(
-      curveEdge.end,
-      curveEdge.points[curveEdge.points.length - 1]
-    );
-    curveEdgeService.setCurves(curveEdge);
-    this.setLanes(curveRoad, dir);
+      mathUtil.clonePoint(curveEdge.start, curveEdge.points[0]);
+      mathUtil.clonePoint(
+        curveEdge.end,
+        curveEdge.points[curveEdge.points.length - 1]
+      );
+      curveEdgeService.setCurves(curveEdge);
+      const line = mathUtil.createLine1(
+        curveRoad.points[0],
+        curveRoad.points[1]
+      );
+      if (dir == "left") {
+        const leftWidth =
+          mathUtil.getDisForPoinLine(leftCurveEdge.start, line) -
+          curveRoad.midDivideWidth / 2;
+        curveRoad.setWidth(leftWidth, "left");
+      } else if (dir == "right") {
+        const rightWidth =
+          mathUtil.getDisForPoinLine(rightCurveEdge.start, line) -
+          curveRoad.midDivideWidth / 2;
+        curveRoad.setWidth(rightWidth, "right");
+      }
+    } else if (curveRoad.way == Constant.oneWay) {
+      oldCount = curveRoad.singleRoadDrivewayCount;
+      for (let i = 0; i < curveRoad.points.length; ++i) {
+        let dx =
+          (leftCurveEdge.points[i].x - rightCurveEdge.points[i].x) / oldCount;
+        let dy =
+          (leftCurveEdge.points[i].y - rightCurveEdge.points[i].y) / oldCount;
+
+        leftCurveEdge.points[i].x = curveRoad.points[i].x + (dx * newCount) / 2;
+        leftCurveEdge.points[i].y = curveRoad.points[i].y + (dy * newCount) / 2;
+        mathUtil.clonePoint(leftCurveEdge.start, leftCurveEdge.points[0]);
+        mathUtil.clonePoint(
+          leftCurveEdge.end,
+          leftCurveEdge.points[leftCurveEdge.points.length - 1]
+        );
+        curveEdgeService.setCurves(leftCurveEdge);
+
+        dx = -1 * dx;
+        dy = -1 * dy;
+        rightCurveEdge.points[i].x =
+          curveRoad.points[i].x + (dx * newCount) / 2;
+        rightCurveEdge.points[i].y =
+          curveRoad.points[i].y + (dy * newCount) / 2;
+        mathUtil.clonePoint(rightCurveEdge.start, rightCurveEdge.points[0]);
+        mathUtil.clonePoint(
+          rightCurveEdge.end,
+          rightCurveEdge.points[rightCurveEdge.points.length - 1]
+        );
+        curveEdgeService.setCurves(rightCurveEdge);
+      }
 
-    const line = mathUtil.createLine1(curveRoad.points[0], curveRoad.points[1]);
-    if (dir == "left") {
-      const leftCurveEdge = dataService.getCurveRoadEdge(curveRoad.leftEdgeId);
-      const leftWidth =
-        mathUtil.getDisForPoinLine(leftCurveEdge.start, line) -
-        curveRoad.midDivideWidth / 2;
-      curveRoad.setWidth(leftWidth, "left");
-    } else if (dir == "right") {
-      const rightCurveEdge = dataService.getCurveRoadEdge(
-        curveRoad.rightEdgeId
+      const line = mathUtil.createLine1(
+        curveRoad.leftCurveEdge.points[0],
+        curveRoad.leftCurveEdge.points[1]
+      );
+      const singleRoadWidth = mathUtil.getDisForPoinLine(
+        rightCurveEdge.start,
+        line
       );
-      const rightWidth =
-        mathUtil.getDisForPoinLine(rightCurveEdge.start, line) -
-        curveRoad.midDivideWidth / 2;
-      curveRoad.setWidth(rightWidth, "right");
+      curveRoad.setWidth(singleRoadWidth);
     }
+    this.setLanes(curveRoad.vectorId, dir);
   }
 
   //单车道转多车道,默认是转换成左右两边各一个
   //不改变路的宽度
   singleToMullane(curveRoad) {
-    curveRoad.leftDrivewayCount = 1;
-    curveRoad.rightDrivewayCount = 1;
-    this.setLanes(curveRoad);
+    // curveRoad.leftDrivewayCount = 1;
+    // curveRoad.rightDrivewayCount = 1;
+    // this.setLanes(curveRoad);
   }
 
   //多车道转单车道
@@ -441,6 +634,8 @@ export default class CurveRoadService extends RoadService {
     let curvePoint = dataService.getCurveRoadPoint(pointId);
     let curveRoadId = curvePoint.getParent();
     let curveRoad = dataService.getCurveRoad(curveRoadId);
+    const leftCurveEdge = dataService.getCurveRoadEdge(curveRoad.leftEdgeId);
+    const rightCurveEdge = dataService.getCurveRoadEdge(curveRoad.rightEdgeId);
     let startPoint = dataService.getCurveRoadPoint(curveRoad.startId);
     let endPoint = dataService.getCurveRoadPoint(curveRoad.endId);
     let index = curvePoint.getIndex();
@@ -450,17 +645,27 @@ export default class CurveRoadService extends RoadService {
     } else if (index == curveRoad.points.length - 1) {
       mathUtil.clonePoint(endPoint, position);
     }
-    const edgePoints = mathUtil.getOffset(
-      curveRoad.points,
-      curveRoad.leftWidth,
-      curveRoad.rightWidth
-    );
+    let edgePoints = null;
+    if (curveRoad.way == Constant.oneWay) {
+      edgePoints = mathUtil.getOffset(
+        curveRoad.points,
+        curveRoad.leftWidth + curveRoad.midDivideWidth / 2,
+        curveRoad.rightWidth + curveRoad.midDivideWidth / 2
+      );
+    } else if (curveRoad.way == Constant.twoWay) {
+      const line = mathUtil.createLine1(
+        curveRoad.points[0],
+        curveRoad.points[1]
+      );
+      const leftWidth = mathUtil.getDisForPoinLine(leftCurveEdge.start, line);
+      const rightWidth = mathUtil.getDisForPoinLine(rightCurveEdge.start, line);
+      edgePoints = mathUtil.getOffset(curveRoad.points, leftWidth, rightWidth);
+    }
 
-    const leftCurveEdge = dataService.getCurveRoadEdge(curveRoad.leftEdgeId);
     leftCurveEdge.points = edgePoints.leftEdgePoints;
     leftCurveEdge.start = leftCurveEdge.points[0];
     leftCurveEdge.end = leftCurveEdge.points[leftCurveEdge.points.length - 1];
-    const rightCurveEdge = dataService.getCurveRoadEdge(curveRoad.rightEdgeId);
+
     rightCurveEdge.points = edgePoints.rightEdgePoints;
     rightCurveEdge.start = rightCurveEdge.points[0];
     rightCurveEdge.end =
@@ -473,6 +678,7 @@ export default class CurveRoadService extends RoadService {
   }
 
   //变宽或者变窄(车道数据不变)
+  //单向的情况下,左右两边同时变宽或者变窄,即:dir无效
   updateForWidth(curveRoadId, newWidth, dir) {
     let curveRoad = dataService.getCurveRoad(curveRoadId);
     let leftCurveEdge = dataService.getCurveRoadEdge(curveRoad.leftEdgeId);
@@ -481,10 +687,19 @@ export default class CurveRoadService extends RoadService {
     let ratio = null;
     let dx = null;
     let dy = null;
+    //需要考虑中间带
     if (dir == "left") {
-      ratio = newWidth / curveRoad.leftWidth;
+      ratio =
+        (newWidth + curveRoad.midDivideWidth / 2) /
+        (curveRoad.leftWidth + curveRoad.midDivideWidth / 2);
     } else if (dir == "right") {
-      ratio = newWidth / curveRoad.rightWidth;
+      ratio =
+        (newWidth + curveRoad.midDivideWidth / 2) /
+        (curveRoad.rightWidth + curveRoad.midDivideWidth / 2);
+    } else {
+      if (curveRoad.way == Constant.oneWay) {
+        ratio = newWidth / curveRoad.singleRoadWidth;
+      }
     }
 
     for (let i = 0; i < curveRoad.points.length; ++i) {
@@ -498,16 +713,62 @@ export default class CurveRoadService extends RoadService {
         rightCurveEdge.points[i].x = curveRoad.points[i].x + dx;
         dy = (rightCurveEdge.points[i].y - curveRoad.points[i].y) * ratio;
         rightCurveEdge.points[i].y = curveRoad.points[i].y + dy;
+      } else {
+        if (curveRoad.way == Constant.oneWay) {
+          dx = (leftCurveEdge.points[i].x - curveRoad.points[i].x) * ratio;
+          leftCurveEdge.points[i].x = curveRoad.points[i].x + dx;
+          dy = (leftCurveEdge.points[i].y - curveRoad.points[i].y) * ratio;
+          leftCurveEdge.points[i].y = curveRoad.points[i].y + dy;
+          dx = (rightCurveEdge.points[i].x - curveRoad.points[i].x) * ratio;
+          rightCurveEdge.points[i].x = curveRoad.points[i].x + dx;
+          dy = (rightCurveEdge.points[i].y - curveRoad.points[i].y) * ratio;
+          rightCurveEdge.points[i].y = curveRoad.points[i].y + dy;
+        } else if (curveRoad.way == Constant.twoWay) {
+          ratio = newWidth / (curveRoad.leftWidth + curveRoad.rightWidth);
+          ratio =
+            (curveRoad.leftWidth * ratio + curveRoad.midDivideWidth / 2) /
+            (curveRoad.leftWidth + curveRoad.midDivideWidth / 2);
+          dx = (leftCurveEdge.points[i].x - curveRoad.points[i].x) * ratio;
+          leftCurveEdge.points[i].x = curveRoad.points[i].x + dx;
+          dy = (leftCurveEdge.points[i].y - curveRoad.points[i].y) * ratio;
+          leftCurveEdge.points[i].y = curveRoad.points[i].y + dy;
+          ratio = newWidth / (curveRoad.leftWidth + curveRoad.rightWidth);
+          ratio =
+            (curveRoad.rightWidth * ratio + curveRoad.midDivideWidth / 2) /
+            (curveRoad.rightWidth + curveRoad.midDivideWidth / 2);
+          dx = (rightCurveEdge.points[i].x - curveRoad.points[i].x) * ratio;
+          rightCurveEdge.points[i].x = curveRoad.points[i].x + dx;
+          dy = (rightCurveEdge.points[i].y - curveRoad.points[i].y) * ratio;
+          rightCurveEdge.points[i].y = curveRoad.points[i].y + dy;
+        }
       }
     }
 
     if (dir == "left") {
       curveEdgeService.setCurves(leftCurveEdge);
+      curveRoad.setWidth(newWidth, dir);
     } else if (dir == "right") {
       curveEdgeService.setCurves(rightCurveEdge);
+      curveRoad.setWidth(newWidth, dir);
+    } else {
+      curveEdgeService.setCurves(leftCurveEdge);
+      curveEdgeService.setCurves(rightCurveEdge);
+      if (curveRoad.way == Constant.oneWay) {
+        curveRoad.setWidth(newWidth);
+      } else if (curveRoad.way == Constant.twoWay) {
+        curveRoad.setWidth(
+          (newWidth * curveRoad.leftWidth) /
+            (curveRoad.leftWidth + curveRoad.rightWidth),
+          "left"
+        );
+        curveRoad.setWidth(
+          (newWidth * curveRoad.rightWidth) /
+            (curveRoad.leftWidth + curveRoad.rightWidth),
+          "right"
+        );
+      }
     }
     this.setLanes(curveRoad, dir);
-    curveRoad.setWidth(newWidth + curveRoad.midDivideWidth / 2, dir);
   }
 
   setCurves(curveRoad) {

+ 0 - 8
src/graphic/Service/EdgeService.js

@@ -772,13 +772,10 @@ export default class EdgeService {
       dir = roadService.getDirction(pointId, Object.keys(parent)[0]);
       this.updateDefaultEdge(Object.keys(parent)[0], dir);
       roadService.setLanes(Object.keys(parent)[0]);
-      roadService.setMidDivide(Object.keys(parent)[0], dir);
     } else if (Object.keys(parent).length == 2) {
       this.updateEdgeForTwoRoad(Object.keys(parent)[0], Object.keys(parent)[1]);
       roadService.setLanes(Object.keys(parent)[0]);
-      roadService.setMidDivide(Object.keys(parent)[0]);
       roadService.setLanes(Object.keys(parent)[1]);
-      roadService.setMidDivide(Object.keys(parent)[1]);
     } else if (Object.keys(parent).length > 2) {
       //起始墙:Object.keys(parent)[0]
       //开始
@@ -813,24 +810,19 @@ export default class EdgeService {
 
         dir = roadService.getDirction(pointId, startRoadId);
         roadService.setLanes(startRoadId, dir);
-        roadService.setMidDivide(startRoadId, dir);
         ++count;
       }
       this.updateSingleEdgeForTwoRoad(startRoadId, endRoadId);
       dir = roadService.getDirction(pointId, startRoadId);
       roadService.setLanes(startRoadId);
-      roadService.setMidDivide(startRoadId, dir);
       dir = roadService.getDirction(pointId, endRoadId);
       roadService.setLanes(endRoadId);
-      roadService.setMidDivide(endRoadId, dir);
 
       this.updateSingleEdgeForTwoRoad(endRoadId, _startRoadId);
       dir = roadService.getDirction(pointId, endRoadId);
       roadService.setLanes(endRoadId);
-      roadService.setMidDivide(endRoadId, dir);
       dir = roadService.getDirction(pointId, _startRoadId);
       roadService.setLanes(_startRoadId);
-      roadService.setMidDivide(_startRoadId, dir);
     } else {
       console.error(
         "updateEdgeForMulRoad***********************************************************************2"

+ 278 - 127
src/graphic/Service/RoadService.js

@@ -19,11 +19,20 @@ export default class RoadService {
     let endPoint = dataService.getRoadPoint(endId);
     endPoint.setPointParent(road.vectorId, "end");
 
-    let edgePoints = mathUtil.RectangleVertex(
-      startPoint,
-      endPoint,
-      road.leftWidth + road.rightWidth
-    );
+    let edgePoints;
+    if (road.way == Constant.oneWay) {
+      edgePoints = mathUtil.RectangleVertex(
+        startPoint,
+        endPoint,
+        road.singleRoadWidth
+      );
+    } else {
+      edgePoints = mathUtil.RectangleVertex(
+        startPoint,
+        endPoint,
+        road.leftWidth + road.rightWidth + road.midDivideWidth
+      );
+    }
     let leftEdge = edgeService.create(
       edgePoints.leftEdgeStart,
       edgePoints.leftEdgeEnd,
@@ -44,7 +53,6 @@ export default class RoadService {
       leftEdge.setEdgeParent(road.vectorId);
       rightEdge.setEdgeParent(road.vectorId);
     }
-    this.setMidDivide(road.vectorId);
     this.setLanes(road.vectorId);
     return road;
   }
@@ -522,7 +530,6 @@ export default class RoadService {
     // 第四步更新Edge
     edgeService.updateDefaultEdge(roadId, dir);
     this.setLanes(roadId, null, dir);
-    this.setMidDivide(roadId, dir);
   }
 
   setRoadPointId = function (roadId, pointId, dir) {
@@ -804,8 +811,6 @@ export default class RoadService {
   }
 
   /****************************************************************************************************************************************************************/
-  //中心线添加控制点
-  insert(roadId, cp) {}
 
   // updateDrivewayCount(roadId, dir, type) {
   //   let road = dataService.getRoad(roadId);
@@ -866,22 +871,33 @@ export default class RoadService {
         };
       }
 
-      //更新车道的起点和终点,因为车道的起点和终点的位置与中间隔离栏一致
-      for (let i = 0; i < road.leftLanes.length; ++i) {
-        const line = mathUtil.createLine1(
-          road.leftLanes[i].start,
-          road.leftLanes[i].end
-        );
-        const join = mathUtil.getJoinLinePoint(road.midDivide.start, line);
-        mathUtil.clonePoint(road.leftLanes[i].start, join);
-      }
-      for (let i = 0; i < road.rightLanes.length; ++i) {
-        const line = mathUtil.createLine1(
-          road.rightLanes[i].start,
-          road.rightLanes[i].end
-        );
-        const join = mathUtil.getJoinLinePoint(road.midDivide.start, line);
-        mathUtil.clonePoint(road.rightLanes[i].start, join);
+      if (road.way == Constant.twoWay) {
+        //更新车道的起点和终点,因为车道的起点和终点的位置与中间隔离栏一致
+        for (let i = 0; i < road.leftLanes.length; ++i) {
+          const line = mathUtil.createLine1(
+            road.leftLanes[i].start,
+            road.leftLanes[i].end
+          );
+          const join = mathUtil.getJoinLinePoint(road.midDivide.start, line);
+          mathUtil.clonePoint(road.leftLanes[i].start, join);
+        }
+        for (let i = 0; i < road.rightLanes.length; ++i) {
+          const line = mathUtil.createLine1(
+            road.rightLanes[i].start,
+            road.rightLanes[i].end
+          );
+          const join = mathUtil.getJoinLinePoint(road.midDivide.start, line);
+          mathUtil.clonePoint(road.rightLanes[i].start, join);
+        }
+      } else if (road.way == Constant.oneWay) {
+        for (let i = 0; i < road.singleLanes.length; ++i) {
+          const line = mathUtil.createLine1(
+            road.singleLanes[i].start,
+            road.singleLanes[i].end
+          );
+          const join = mathUtil.getJoinLinePoint(road.midDivide.start, line);
+          mathUtil.clonePoint(road.singleLanes[i].start, join);
+        }
       }
     }
 
@@ -902,47 +918,83 @@ export default class RoadService {
         };
       }
 
-      //更新车道的起点和终点,因为车道的起点和终点的位置与中间隔离栏一致
-      for (let i = 0; i < road.leftLanes.length; ++i) {
-        const line = mathUtil.createLine1(
-          road.leftLanes[i].start,
-          road.leftLanes[i].end
-        );
-        const join = mathUtil.getJoinLinePoint(road.midDivide.end, line);
-        mathUtil.clonePoint(road.leftLanes[i].end, join);
-      }
-      for (let i = 0; i < road.rightLanes.length; ++i) {
-        const line = mathUtil.createLine1(
-          road.rightLanes[i].start,
-          road.rightLanes[i].end
-        );
-        const join = mathUtil.getJoinLinePoint(road.midDivide.end, line);
-        mathUtil.clonePoint(road.rightLanes[i].end, join);
+      if (road.way == Constant.twoWay) {
+        //更新车道的起点和终点,因为车道的起点和终点的位置与中间隔离栏一致
+        for (let i = 0; i < road.leftLanes.length; ++i) {
+          const line = mathUtil.createLine1(
+            road.leftLanes[i].start,
+            road.leftLanes[i].end
+          );
+          const join = mathUtil.getJoinLinePoint(road.midDivide.end, line);
+          mathUtil.clonePoint(road.leftLanes[i].end, join);
+        }
+        for (let i = 0; i < road.rightLanes.length; ++i) {
+          const line = mathUtil.createLine1(
+            road.rightLanes[i].start,
+            road.rightLanes[i].end
+          );
+          const join = mathUtil.getJoinLinePoint(road.midDivide.end, line);
+          mathUtil.clonePoint(road.rightLanes[i].end, join);
+        }
+      } else if (road.way == Constant.oneWay) {
+        for (let i = 0; i < road.singleLanes.length; ++i) {
+          const line = mathUtil.createLine1(
+            road.singleLanes[i].start,
+            road.singleLanes[i].end
+          );
+          const join = mathUtil.getJoinLinePoint(road.midDivide.end, line);
+          mathUtil.clonePoint(road.singleLanes[i].end, join);
+        }
       }
     }
-    this.setMidDivideDisplay(roadId);
   }
 
-  setMidDivideForPointId(pointId) {
-    const point = dataService.getRoadPoint(pointId);
-    for (let key in point.parent) {
-      this.setMidDivide(key, point.parent[key]);
+  //设置车道
+  //dir1表示left或者right,dir2表示start或者end
+  //单车道不考虑dir1
+  setLanes(roadId, dir1, dir2) {
+    let road = dataService.getRoad(roadId);
+    if (road.way == Constant.oneWay) {
+      this.setOneWayLanes(road, dir1, dir2);
+    } else if (road.way == Constant.twoWay) {
+      this.setTwoWayLanes(road, dir1, dir2);
     }
   }
 
-  setMidDivideDisplay(roadId) {
-    const road = dataService.getRoad(roadId);
-    if (road.leftDrivewayCount == 0 || road.rightDrivewayCount == 0) {
-      road.midDivide.display = false;
-    } else {
-      road.midDivide.display = true;
+  //单向车道
+  setOneWayLanes(road, dir1, dir2) {
+    let leftEdge = dataService.getRoadEdge(road.leftEdgeId);
+    let rightEdge = dataService.getRoadEdge(road.rightEdgeId);
+    const drivewayCount = road.singleRoadDrivewayCount;
+
+    let dx1 = (leftEdge.start.x - rightEdge.start.x) / drivewayCount;
+    let dy1 = (leftEdge.start.y - rightEdge.start.y) / drivewayCount;
+
+    let dx2 = (leftEdge.end.x - rightEdge.end.x) / drivewayCount;
+    let dy2 = (leftEdge.end.y - rightEdge.end.y) / drivewayCount;
+
+    for (let i = 0; i < drivewayCount - 1; ++i) {
+      if (!road.singleLanes[i]) {
+        road.singleLanes[i] = {};
+      }
+
+      if (dir2 == "start" || !dir2) {
+        road.singleLanes[i].start = {};
+        road.singleLanes[i].start.x = rightEdge.start.x + dx1 * (i + 1);
+        road.singleLanes[i].start.y = rightEdge.start.y + dy1 * (i + 1);
+      }
+
+      if (dir2 == "end" || !dir2) {
+        road.singleLanes[i].end = {};
+        road.singleLanes[i].end.x = rightEdge.end.x + dx2 * (i + 1);
+        road.singleLanes[i].end.y = rightEdge.end.y + dy2 * (i + 1);
+      }
     }
+    this.setMidDivide(road.vectorId);
   }
 
-  //设置车道
-  //dir1表示left或者right,dir2表示start或者end
-  setLanes(roadId, dir1, dir2) {
-    let road = dataService.getRoad(roadId);
+  //双向车道
+  setTwoWayLanes(road, dir1, dir2) {
     let startPoint = dataService.getRoadPoint(road.startId);
     let endPoint = dataService.getRoadPoint(road.endId);
     let leftEdge = dataService.getRoadEdge(road.leftEdgeId);
@@ -1019,15 +1071,16 @@ export default class RoadService {
       }
       road.rightLanes.splice(rightCount - 1);
     }
-  }
-
-  singleToMullane(road) {
-    road.leftDrivewayCount = 1;
-    road.rightDrivewayCount = 1;
     this.setMidDivide(road.vectorId);
-    this.setLanes(road.vectorId);
   }
 
+  // singleToMullane(road) {
+  //   road.leftDrivewayCount = 1;
+  //   road.rightDrivewayCount = 1;
+  //   this.setMidDivide(road.vectorId);
+  //   this.setLanes(road.vectorId);
+  // }
+
   //多车道转单车道
   mulToSinglelane(road) {
     if (road.leftDrivewayCount > 0) {
@@ -1045,8 +1098,21 @@ export default class RoadService {
 
   //删除或者减少车道
   //需要考虑车道个数是0(左或者右)的情况
+  //单向车道不考虑dir,即:均匀的增加或者删除车道
   updateForAddSubtractLanesCount(roadId, newCount, dir) {
-    let dx1, dy1, dx2, dy2, oldCount, edgeStartPosition, edgeEndPosition;
+    let dx1,
+      dy1,
+      dx2,
+      dy2,
+      oldCount,
+      edgeStartPosition,
+      edgeEndPosition,
+      leftRatio,
+      rightRatio,
+      middx1,
+      middy1,
+      middx2,
+      middy2;
     let road = dataService.getRoad(roadId);
 
     if (newCount < 0) {
@@ -1058,44 +1124,42 @@ export default class RoadService {
     let leftEdge = dataService.getRoadEdge(road.leftEdgeId);
     let rightEdge = dataService.getRoadEdge(road.rightEdgeId);
 
-    const leftRatio =
-      road.leftWidth / (road.leftWidth + road.midDivideWidth / 2);
-    const rightRatio =
-      road.rightWidth / (road.rightWidth + road.midDivideWidth / 2);
-
-    let middx1, middy1, middx2, middy2;
-
-    if (dir == "left") {
-      oldCount = road.leftDrivewayCount;
-      if (oldCount != 0) {
-        dx1 = ((leftEdge.start.x - startPoint.x) * leftRatio) / oldCount;
-        dy1 = ((leftEdge.start.y - startPoint.y) * leftRatio) / oldCount;
+    if (road.way == Constant.twoWay) {
+      leftRatio = road.leftWidth / (road.leftWidth + road.midDivideWidth / 2);
+      rightRatio =
+        road.rightWidth / (road.rightWidth + road.midDivideWidth / 2);
+      if (dir == "left") {
+        oldCount = road.leftDrivewayCount;
+        if (oldCount != 0) {
+          dx1 = ((leftEdge.start.x - startPoint.x) * leftRatio) / oldCount;
+          dy1 = ((leftEdge.start.y - startPoint.y) * leftRatio) / oldCount;
+
+          dx2 = ((leftEdge.end.x - endPoint.x) * leftRatio) / oldCount;
+          dy2 = ((leftEdge.end.y - endPoint.y) * leftRatio) / oldCount;
+        }
 
-        dx2 = ((leftEdge.end.x - endPoint.x) * leftRatio) / oldCount;
-        dy2 = ((leftEdge.end.y - endPoint.y) * leftRatio) / oldCount;
-      }
+        middx1 = (leftEdge.start.x - startPoint.x) * (1 - leftRatio);
+        middy1 = (leftEdge.start.y - startPoint.y) * (1 - leftRatio);
+        middx2 = (leftEdge.end.x - endPoint.x) * (1 - leftRatio);
+        middy2 = (leftEdge.end.y - endPoint.y) * (1 - leftRatio);
 
-      middx1 = (leftEdge.start.x - startPoint.x) * (1 - leftRatio);
-      middy1 = (leftEdge.start.y - startPoint.y) * (1 - leftRatio);
-      middx2 = (leftEdge.end.x - endPoint.x) * (1 - leftRatio);
-      middy2 = (leftEdge.end.y - endPoint.y) * (1 - leftRatio);
+        road.leftDrivewayCount = newCount;
+      } else if (dir == "right") {
+        oldCount = road.rightDrivewayCount;
+        if (oldCount != 0) {
+          dx1 = ((rightEdge.start.x - startPoint.x) * rightRatio) / oldCount;
+          dy1 = ((rightEdge.start.y - startPoint.y) * rightRatio) / oldCount;
 
-      road.leftDrivewayCount = newCount;
-    } else if (dir == "right") {
-      oldCount = road.rightDrivewayCount;
-      if (oldCount != 0) {
-        dx1 = ((rightEdge.start.x - startPoint.x) * rightRatio) / oldCount;
-        dy1 = ((rightEdge.start.y - startPoint.y) * rightRatio) / oldCount;
+          dx2 = ((rightEdge.end.x - endPoint.x) * rightRatio) / oldCount;
+          dy2 = ((rightEdge.end.y - endPoint.y) * rightRatio) / oldCount;
+        }
+        middx1 = (rightEdge.start.x - startPoint.x) * (1 - rightRatio);
+        middy1 = (rightEdge.start.y - startPoint.y) * (1 - rightRatio);
+        middx2 = (rightEdge.end.x - endPoint.x) * (1 - rightRatio);
+        middy2 = (rightEdge.end.y - endPoint.y) * (1 - rightRatio);
 
-        dx2 = ((rightEdge.end.x - endPoint.x) * rightRatio) / oldCount;
-        dy2 = ((rightEdge.end.y - endPoint.y) * rightRatio) / oldCount;
+        road.rightDrivewayCount = newCount;
       }
-      middx1 = (rightEdge.start.x - startPoint.x) * (1 - rightRatio);
-      middy1 = (rightEdge.start.y - startPoint.y) * (1 - rightRatio);
-      middx2 = (rightEdge.end.x - endPoint.x) * (1 - rightRatio);
-      middy2 = (rightEdge.end.y - endPoint.y) * (1 - rightRatio);
-
-      road.rightDrivewayCount = newCount;
     }
 
     if (newCount == oldCount) {
@@ -1108,64 +1172,151 @@ export default class RoadService {
       return;
     }
 
-    edgeStartPosition = {
-      x: startPoint.x + middx1 + dx1 * newCount,
-      y: startPoint.y + middy1 + dy1 * newCount,
-    };
-    edgeEndPosition = {
-      x: endPoint.x + middx2 + dx2 * newCount,
-      y: endPoint.y + middy2 + dy2 * newCount,
-    };
+    if (road.way == Constant.twoWay) {
+      edgeStartPosition = {
+        x: startPoint.x + middx1 + dx1 * newCount,
+        y: startPoint.y + middy1 + dy1 * newCount,
+      };
+      edgeEndPosition = {
+        x: endPoint.x + middx2 + dx2 * newCount,
+        y: endPoint.y + middy2 + dy2 * newCount,
+      };
+
+      if (dir == "left") {
+        mathUtil.clonePoint(leftEdge.start, edgeStartPosition);
+        mathUtil.clonePoint(leftEdge.end, edgeEndPosition);
+      } else if (dir == "right") {
+        mathUtil.clonePoint(rightEdge.start, edgeStartPosition);
+        mathUtil.clonePoint(rightEdge.end, edgeEndPosition);
+      }
 
-    if (dir == "left") {
+      let line = roadService.getMidLine(road);
+      if (dir == "left") {
+        let join = mathUtil.getJoinLinePoint(leftEdge.start, line);
+        road.setWidth(
+          mathUtil.getDistance(leftEdge.start, join) - road.midDivideWidth / 2,
+          dir
+        );
+      } else if (dir == "right") {
+        let join = mathUtil.getJoinLinePoint(rightEdge.start, line);
+        road.setWidth(
+          mathUtil.getDistance(rightEdge.start, join) - road.midDivideWidth / 2,
+          dir
+        );
+      }
+    } else if (road.way == Constant.oneWay) {
+      oldCount = road.singleRoadDrivewayCount;
+      //不能从leftEdge直接到rightEdge,因为不一定是线性的
+      dx1 = ((leftEdge.start.x - startPoint.x) / oldCount) * newCount;
+      dy1 = ((leftEdge.start.y - startPoint.y) / oldCount) * newCount;
+      dx2 = ((leftEdge.end.x - endPoint.x) / oldCount) * newCount;
+      dy2 = ((leftEdge.end.y - endPoint.y) / oldCount) * newCount;
+
+      edgeStartPosition = {
+        x: startPoint.x + dx1,
+        y: startPoint.y + dy1,
+      };
+      edgeEndPosition = {
+        x: endPoint.x + dx2,
+        y: endPoint.y + dy2,
+      };
       mathUtil.clonePoint(leftEdge.start, edgeStartPosition);
       mathUtil.clonePoint(leftEdge.end, edgeEndPosition);
-    } else if (dir == "right") {
+
+      dx1 = ((rightEdge.start.x - startPoint.x) / oldCount) * newCount;
+      dy1 = ((rightEdge.start.y - startPoint.y) / oldCount) * newCount;
+      dx2 = ((rightEdge.end.x - endPoint.x) / oldCount) * newCount;
+      dy2 = ((rightEdge.end.y - endPoint.y) / oldCount) * newCount;
+
+      edgeStartPosition = {
+        x: startPoint.x + dx1,
+        y: startPoint.y + dy1,
+      };
+      edgeEndPosition = {
+        x: endPoint.x + dx2,
+        y: endPoint.y + dy2,
+      };
       mathUtil.clonePoint(rightEdge.start, edgeStartPosition);
       mathUtil.clonePoint(rightEdge.end, edgeEndPosition);
-    }
 
-    let line = roadService.getMidLine(road);
-    if (dir == "left") {
-      let join = mathUtil.getJoinLinePoint(leftEdge.start, line);
-      road.setWidth(
-        mathUtil.getDistance(leftEdge.start, join) - road.midDivideWidth / 2,
-        dir
-      );
-    } else if (dir == "right") {
-      let join = mathUtil.getJoinLinePoint(rightEdge.start, line);
-      road.setWidth(
-        mathUtil.getDistance(rightEdge.start, join) - road.midDivideWidth / 2,
-        dir
-      );
+      const line = mathUtil.createLine1(leftEdge.start, leftEdge.end);
+      const singleRoadWidth = mathUtil.getDisForPoinLine(rightEdge.start, line);
+      road.setWidth(singleRoadWidth);
     }
 
     edgeService.updateEdgeForMulRoad(road.startId);
     edgeService.updateEdgeForMulRoad(road.endId);
+    this.setLanes(road, dir);
   }
 
-  //变宽或者变窄(车道数据不变)
+  //变宽或者变窄(车道个数不变)
+  //单向的情况下,左右两边同时变宽或者变窄,即:dir无效
   updateForWidth(roadId, newWidth, dir) {
     let road = dataService.getRoad(roadId);
     let startPoint = dataService.getRoadPoint(road.startId);
     let endPoint = dataService.getRoadPoint(road.endId);
     let leftEdge = dataService.getRoadEdge(road.leftEdgeId);
     let rightEdge = dataService.getRoadEdge(road.rightEdgeId);
-    road.setWidth(newWidth + road.midDivideWidth / 2, dir);
-    let edgePoints = mathUtil.RectangleVertex(startPoint, endPoint, newWidth);
-    if (dir == "left") {
+    let edgePoints;
+    if (road.way == Constant.oneWay) {
+      edgePoints = mathUtil.RectangleVertex(startPoint, endPoint, newWidth);
       mathUtil.clonePoint(leftEdge.start, edgePoints.leftEdgeStart);
       mathUtil.clonePoint(leftEdge.end, edgePoints.leftEdgeEnd);
-    } else if (dir == "right") {
       mathUtil.clonePoint(rightEdge.start, edgePoints.rightEdgeStart);
       mathUtil.clonePoint(rightEdge.end, edgePoints.rightEdgeEnd);
+      road.setWidth(newWidth);
+    } else if (road.way == Constant.twoWay) {
+      if (dir == "left") {
+        edgePoints = mathUtil.RectangleVertex(
+          startPoint,
+          endPoint,
+          newWidth + road.midDivideWidth / 2
+        );
+        mathUtil.clonePoint(leftEdge.start, edgePoints.leftEdgeStart);
+        mathUtil.clonePoint(leftEdge.end, edgePoints.leftEdgeEnd);
+        road.setWidth(newWidth, dir);
+      } else if (dir == "right") {
+        edgePoints = mathUtil.RectangleVertex(
+          startPoint,
+          endPoint,
+          newWidth + road.midDivideWidth / 2
+        );
+        mathUtil.clonePoint(rightEdge.start, edgePoints.rightEdgeStart);
+        mathUtil.clonePoint(rightEdge.end, edgePoints.rightEdgeEnd);
+        road.setWidth(newWidth, dir);
+      }
+      //左右两边的edge同时变宽或者变窄
+      else {
+        edgePoints = mathUtil.RectangleVertex(
+          startPoint,
+          endPoint,
+          (newWidth * road.leftWidth) / (road.leftWidth + road.rightWidth) +
+            road.midDivideWidth / 2
+        );
+        mathUtil.clonePoint(leftEdge.start, edgePoints.leftEdgeStart);
+        mathUtil.clonePoint(leftEdge.end, edgePoints.leftEdgeEnd);
+        road.setWidth(
+          (newWidth * road.leftWidth) / (road.leftWidth + road.rightWidth),
+          "left"
+        );
+        edgePoints = mathUtil.RectangleVertex(
+          startPoint,
+          endPoint,
+          (newWidth * road.rightWidth) / (road.leftWidth + road.rightWidth) +
+            road.midDivideWidth / 2
+        );
+        mathUtil.clonePoint(rightEdge.start, edgePoints.rightEdgeStart);
+        mathUtil.clonePoint(rightEdge.end, edgePoints.rightEdgeEnd);
+        road.setWidth(
+          (newWidth * road.rightWidth) / (road.leftWidth + road.rightWidth),
+          "right"
+        );
+      }
     }
 
     edgeService.updateEdgeForMovePoint(road.startId);
     edgeService.updateEdgeForMovePoint(road.endId);
     roadService.setLanes(road.vectorId, dir);
-    roadService.setMidDivideForPointId(road.startId);
-    roadService.setMidDivideForPointId(road.endId);
   }
 
   unlock(roadId) {

+ 5 - 0
src/graphic/Setting.js

@@ -3,11 +3,16 @@ const Setting = {
   roadRightDrivewayCount: 1,
   curveRoadLeftDrivewayCount: 1,
   curveRoadRightDrivewayCount: 1,
+  singleRoadWidth: 50,
+  singleCurveRoadWidth: 50,
+  singleRoadDrivewayCount: 2,
+  singleCurveRoadDrivewayCount: 2,
   leftRoadWidth: 50,
   rightRoadWidth: 50,
   leftCurveRoadWidth: 50,
   rightCurveRoadWidth: 50,
   roadMidDivideWidth: 40,
   curveRoadMidDivideWidth: 40,
+  wayType: "oneWay", //one表示单向,two表示双向
 };
 export default Setting;