|
@@ -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) {
|