123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548 |
- import { mathUtil } from "../Util/MathUtil";
- import { circleService } from "../Service/CircleService";
- import { listenLayer } from "../ListenLayer";
- import { roadPointService } from "../Service/RoadPointService";
- import { roadService } from "../Service/RoadService";
- import { edgeService } from "../Service/EdgeService";
- import { dataService } from "../Service/DataService";
- import { uiService } from "../Service/UIService";
- import UIEvents from "../enum/UIEvents.js";
- import Constant from "../Constant.js";
- import Settings from "../Settings.js";
- import RoadTemplate from "../enum/RoadTemplate";
- import { curveRoadPointService } from "../Service/CurveRoadPointService";
- import { curveRoadService } from "../Service/CurveRoadService";
- import { curveEdgeService } from "../Service/CurveEdgeService";
- import CurveRoad from "../Geometry/CurveRoad.js";
- export default class AddCrossRoad {
- constructor() {}
- build(position) {
- const roadTemplate = uiService.getSelectRoadTemplate();
- // 丁字路口
- if (roadTemplate == RoadTemplate.TJunction) {
- this.buildThree(position);
- }
- // 十字路口
- else if (roadTemplate == RoadTemplate.Crossroads) {
- this.buildFour(position);
- }
- // 五岔路口
- else if (roadTemplate == RoadTemplate.FiveForks) {
- this.buildFive(position);
- }
- // 六岔路口
- else if (roadTemplate == RoadTemplate.SixForkIntersection) {
- this.buildSix(position);
- }
- // s型弯路
- else if (roadTemplate == RoadTemplate.SBend) {
- this.buildCurveRoad(position);
- }
- // 出口匝道
- else if (roadTemplate == RoadTemplate.ExitRamp) {
- this.buildExitRamp(position);
- }
- // 国道(路肩)
- else if (roadTemplate == RoadTemplate.NationalHighwayShoulder) {
- this.buildNationalHighwayShoulder(position);
- }
- // 室内路段
- else if (roadTemplate == RoadTemplate.IndoorSection) {
- this.buildIndoorSection(position);
- }
- // 弯道
- else if (roadTemplate == RoadTemplate.Bend) {
- this.buildBend(position);
- }
- // 急转弯道
- else if (roadTemplate == RoadTemplate.SharpCurve) {
- this.buildSharpCurve(position);
- }
- // 直角弯道
- else if (roadTemplate == RoadTemplate.Corner) {
- this.buildCorner(position);
- }
- // 进口砸到
- else if (roadTemplate == RoadTemplate.ImportSmashedRoad) {
- this.buildImportSmashedRoad(position);
- }
- // 高速收费站
- else if (roadTemplate == RoadTemplate.HighSpeedTollBooth) {
- this.buildHighSpeedTollBooth(position);
- }
- // 高速港湾
- else if (roadTemplate == RoadTemplate.HighSpeedHarbor) {
- this.buildHighSpeedHarbor(position);
- }
- // 高速路段
- else if (roadTemplate == RoadTemplate.HighwaySection) {
- this.buildHighwaySection(position);
- }
- // 宽变窄路段
- else if (roadTemplate == RoadTemplate.WideNarrowRoad) {
- this.buildWideNarrowRoad(position);
- }
- }
- //s型弯路
- buildCurveRoad(position) {
- const roadLen = 500;
- const offsetDis = 100;
- let startPoint = {
- x: position.x,
- y: position.y + roadLen / 2,
- };
- let endPoint = {
- x: position.x,
- y: position.y - roadLen / 2,
- };
- startPoint = curveRoadPointService.create(startPoint);
- endPoint = curveRoadPointService.create(endPoint);
- let curveRoad = new CurveRoad(startPoint.vectorId, endPoint.vectorId);
- dataService.addCurveRoad(curveRoad);
- startPoint.setPointParent(curveRoad.vectorId);
- startPoint.setIndex(0);
- endPoint.setPointParent(curveRoad.vectorId);
- endPoint.setIndex(2);
- let edgePoints = mathUtil.RectangleVertex(
- startPoint,
- endPoint,
- curveRoad.leftWidth +
- curveRoad.rightWidth +
- curveRoad.midDivide.midDivideWidth
- );
- let leftEdge = curveEdgeService.create(
- edgePoints.leftEdgeStart,
- edgePoints.leftEdgeEnd,
- null,
- curveRoad.vectorId
- );
- let rightEdge = curveEdgeService.create(
- edgePoints.rightEdgeStart,
- edgePoints.rightEdgeEnd,
- null,
- curveRoad.vectorId
- );
- curveRoad.setLeftEdge(leftEdge.vectorId);
- curveRoad.setRightEdge(rightEdge.vectorId);
- curveRoad.points.push(startPoint);
- curveRoad.points.push(endPoint);
- leftEdge.points.push(edgePoints.leftEdgeStart);
- leftEdge.points.push(edgePoints.leftEdgeEnd);
- rightEdge.points.push(edgePoints.rightEdgeStart);
- rightEdge.points.push(edgePoints.rightEdgeEnd);
- //得有点曲率
- const midPoint = {
- x: (startPoint.x + endPoint.x) / 2,
- y: (startPoint.y + endPoint.y) / 2,
- };
- let mid1 = {
- x: (startPoint.x + midPoint.x) / 2,
- y: (startPoint.y + midPoint.y) / 2,
- };
- let mid2 = {
- x: (endPoint.x + midPoint.x) / 2,
- y: (endPoint.y + midPoint.y) / 2,
- };
- curveRoadService.addCPoint(curveRoad, mid1, 0);
- curveRoadService.addCPoint(curveRoad, mid2, 1);
- mid1.x -= offsetDis;
- mid2.x += offsetDis;
- curveRoadService.updateForMovePoint(curveRoad.points[1].vectorId, mid1);
- curveRoadService.updateForMovePoint(curveRoad.points[2].vectorId, mid2);
- }
- //三岔口
- buildThree(position) {
- const len = 300;
- let end = roadPointService.create(position);
- let start1 = roadPointService.create({
- x: end.x,
- y: end.y + len,
- });
- let start2 = roadPointService.create({
- x: end.x + len,
- y: end.y,
- });
- let start3 = roadPointService.create({
- x: end.x,
- y: end.y - len,
- });
- //需要设置公路的车道数,是否双向等等
- uiService.isBelongRoad(UIEvents.TwoEdgeOneLanRoad);
- roadService.create(start1.vectorId, end.vectorId);
- roadService.create(start2.vectorId, end.vectorId);
- roadService.create(start3.vectorId, end.vectorId);
- edgeService.updateEdgeForMulRoad(end.vectorId);
- }
- //四岔口
- buildFour(position) {
- const len = 300;
- let end = roadPointService.create(position);
- let start1 = roadPointService.create({
- x: end.x,
- y: end.y + len,
- });
- let start2 = roadPointService.create({
- x: end.x,
- y: end.y - len,
- });
- let start3 = roadPointService.create({
- x: end.x + len,
- y: end.y,
- });
- let start4 = roadPointService.create({
- x: end.x - len,
- y: end.y,
- });
- //需要设置公路的车道数,是否双向等等
- uiService.isBelongRoad(UIEvents.TwoEdgeOneLanRoad);
- roadService.create(start1.vectorId, end.vectorId);
- roadService.create(start2.vectorId, end.vectorId);
- roadService.create(start3.vectorId, end.vectorId);
- roadService.create(start4.vectorId, end.vectorId);
- edgeService.updateEdgeForMulRoad(end.vectorId);
- }
- //五岔口
- buildFive(position) {
- const len = 300;
- const points = mathUtil.createFivePointedStar(position, len);
- let end = roadPointService.create(position);
- let start1 = roadPointService.create(points[0]);
- let start2 = roadPointService.create(points[1]);
- let start3 = roadPointService.create(points[2]);
- let start4 = roadPointService.create(points[3]);
- let start5 = roadPointService.create(points[4]);
- roadService.create(start1.vectorId, end.vectorId);
- roadService.create(start2.vectorId, end.vectorId);
- roadService.create(start3.vectorId, end.vectorId);
- roadService.create(start4.vectorId, end.vectorId);
- roadService.create(start5.vectorId, end.vectorId);
- edgeService.updateEdgeForMulRoad(end.vectorId);
- }
- //六岔口
- buildSix(position) {
- const len = 300;
- const points = mathUtil.createSixPoint(position, len);
- let end = roadPointService.create(position);
- let start1 = roadPointService.create(points[0]);
- let start2 = roadPointService.create(points[1]);
- let start3 = roadPointService.create(points[2]);
- let start4 = roadPointService.create(points[3]);
- let start5 = roadPointService.create(points[4]);
- let start6 = roadPointService.create(points[5]);
- roadService.create(start1.vectorId, end.vectorId);
- roadService.create(start2.vectorId, end.vectorId);
- roadService.create(start3.vectorId, end.vectorId);
- roadService.create(start4.vectorId, end.vectorId);
- roadService.create(start5.vectorId, end.vectorId);
- roadService.create(start6.vectorId, end.vectorId);
- edgeService.updateEdgeForMulRoad(end.vectorId);
- }
- buildExitRamp(position) {
- const roadLen = 600;
- let startPoint = {
- x: position.x,
- y: position.y + (roadLen * 3) / 5,
- };
- let endPoint = {
- x: position.x,
- y: position.y - (roadLen * 2) / 5,
- };
- startPoint = roadPointService.create(startPoint);
- endPoint = roadPointService.create(endPoint);
- let crossPoint = roadPointService.create(position);
- uiService.isBelongRoad(UIEvents.OneEdgeThreeLanRoad);
- roadService.create(startPoint.vectorId, crossPoint.vectorId);
- roadService.create(crossPoint.vectorId, endPoint.vectorId);
- let startPoint2 = {
- x: startPoint.x + roadLen / 4,
- y: startPoint.y,
- };
- startPoint2 = roadPointService.create(startPoint2);
- uiService.isBelongRoad(UIEvents.OneEdgeOneLanRoad);
- roadService.create(startPoint2.vectorId, crossPoint.vectorId);
- edgeService.updateEdgeForMulRoad(crossPoint.vectorId);
- }
- buildNationalHighwayShoulder(position) {
- const roadLen = 600;
- let startPoint = {
- x: position.x,
- y: position.y + roadLen / 2,
- };
- let endPoint = {
- x: position.x,
- y: position.y - roadLen / 2,
- };
- startPoint = roadPointService.create(startPoint);
- endPoint = roadPointService.create(endPoint);
- uiService.isBelongRoad(UIEvents.TwoEdgeTwoLanRoad);
- roadService.create(startPoint.vectorId, endPoint.vectorId);
- }
- buildIndoorSection(position) {
- const roadLen = 600;
- let startPoint = {
- x: position.x,
- y: position.y + roadLen / 2,
- };
- let endPoint = {
- x: position.x,
- y: position.y - roadLen / 2,
- };
- startPoint = roadPointService.create(startPoint);
- endPoint = roadPointService.create(endPoint);
- uiService.isBelongRoad(UIEvents.TwoEdgeThreeLanRoad);
- roadService.create(startPoint.vectorId, endPoint.vectorId);
- }
- buildBend(position) {
- const roadLen = 500;
- const offsetDis = 150;
- let startPoint = {
- x: position.x,
- y: position.y + roadLen / 2,
- };
- let endPoint = {
- x: position.x,
- y: position.y - roadLen / 2,
- };
- startPoint = curveRoadPointService.create(startPoint);
- endPoint = curveRoadPointService.create(endPoint);
- uiService.setCurveRoadLeftDrivewayCount(2);
- uiService.setCurveRoadRightDrivewayCount(2);
- uiService.setLeftCurveRoadWidth(100);
- uiService.setRightCurveRoadWidth(100);
- const curveRoad = curveRoadService.create(
- startPoint.vectorId,
- endPoint.vectorId
- );
- const midPoint = {
- x: (startPoint.x + endPoint.x) / 2 - offsetDis,
- y: (startPoint.y + endPoint.y) / 2,
- };
- curveRoadService.updateForMovePoint(curveRoad.points[1].vectorId, midPoint);
- uiService.setCurveRoadLeftDrivewayCount(1);
- uiService.setCurveRoadRightDrivewayCount(1);
- uiService.setLeftCurveRoadWidth(50);
- uiService.setRightCurveRoadWidth(50);
- }
- buildSharpCurve(position) {
- const roadLen = 650;
- const height = 450;
- let startPoint = {
- x: position.x + roadLen,
- y: position.y + height / 2,
- };
- let endPoint = {
- x: position.x + roadLen,
- y: position.y - height / 2,
- };
- startPoint = curveRoadPointService.create(startPoint);
- endPoint = curveRoadPointService.create(endPoint);
- uiService.setCurveRoadLeftDrivewayCount(2);
- uiService.setCurveRoadRightDrivewayCount(2);
- uiService.setLeftCurveRoadWidth(100);
- uiService.setRightCurveRoadWidth(100);
- let curveRoad = new CurveRoad(startPoint.vectorId, endPoint.vectorId);
- dataService.addCurveRoad(curveRoad);
- startPoint.setPointParent(curveRoad.vectorId);
- startPoint.setIndex(0);
- endPoint.setPointParent(curveRoad.vectorId);
- endPoint.setIndex(2);
- let edgePoints = mathUtil.RectangleVertex(
- startPoint,
- endPoint,
- curveRoad.leftWidth +
- curveRoad.rightWidth +
- curveRoad.midDivide.midDivideWidth
- );
- let leftEdge = curveEdgeService.create(
- edgePoints.leftEdgeStart,
- edgePoints.leftEdgeEnd,
- null,
- curveRoad.vectorId
- );
- let rightEdge = curveEdgeService.create(
- edgePoints.rightEdgeStart,
- edgePoints.rightEdgeEnd,
- null,
- curveRoad.vectorId
- );
- curveRoad.setLeftEdge(leftEdge.vectorId);
- curveRoad.setRightEdge(rightEdge.vectorId);
- curveRoad.points.push(startPoint);
- curveRoad.points.push(endPoint);
- leftEdge.points.push(edgePoints.leftEdgeStart);
- leftEdge.points.push(edgePoints.leftEdgeEnd);
- rightEdge.points.push(edgePoints.rightEdgeStart);
- rightEdge.points.push(edgePoints.rightEdgeEnd);
- let point1 = {
- x: position.x + 200,
- y: position.y + height / 2,
- };
- let point2 = {
- x: position.x + 50,
- y: position.y + height / 2 - 50,
- };
- let point3 = {
- x: position.x + 50,
- y: position.y - height / 2 + 50,
- };
- let point4 = {
- x: position.x + 200,
- y: position.y - height / 2,
- };
- curveRoadService.addCPoint(curveRoad, point1, 0);
- curveRoadService.addCPoint(curveRoad, point2, 1);
- curveRoadService.addCPoint(curveRoad, position, 2);
- curveRoadService.addCPoint(curveRoad, point3, 3);
- curveRoadService.addCPoint(curveRoad, point4, 4);
- curveRoadService.updateForMovePoint(curveRoad.points[1].vectorId, point1);
- curveRoadService.updateForMovePoint(curveRoad.points[2].vectorId, point2);
- curveRoadService.updateForMovePoint(curveRoad.points[3].vectorId, position);
- curveRoadService.updateForMovePoint(curveRoad.points[4].vectorId, point3);
- curveRoadService.updateForMovePoint(curveRoad.points[5].vectorId, point4);
- uiService.setCurveRoadLeftDrivewayCount(1);
- uiService.setCurveRoadRightDrivewayCount(1);
- uiService.setLeftCurveRoadWidth(50);
- uiService.setRightCurveRoadWidth(50);
- }
- buildCorner(position) {
- const len = 300;
- let end = roadPointService.create(position);
- let start1 = roadPointService.create({
- x: end.x + len,
- y: end.y,
- });
- let start2 = roadPointService.create({
- x: end.x,
- y: end.y - len,
- });
- //需要设置公路的车道数,是否双向等等
- uiService.isBelongRoad(UIEvents.TwoEdgeTwoLanRoad);
- roadService.create(start1.vectorId, end.vectorId);
- roadService.create(start2.vectorId, end.vectorId);
- edgeService.updateEdgeForMulRoad(end.vectorId);
- }
- buildImportSmashedRoad(position) {
- const roadLen = 600;
- let startPoint = {
- x: position.x,
- y: position.y - (roadLen * 3) / 5,
- };
- let endPoint = {
- x: position.x,
- y: position.y + (roadLen * 2) / 5,
- };
- startPoint = roadPointService.create(startPoint);
- endPoint = roadPointService.create(endPoint);
- let crossPoint = roadPointService.create(position);
- uiService.isBelongRoad(UIEvents.OneEdgeThreeLanRoad);
- roadService.create(startPoint.vectorId, crossPoint.vectorId);
- roadService.create(crossPoint.vectorId, endPoint.vectorId);
- let startPoint2 = {
- x: startPoint.x + roadLen / 4,
- y: startPoint.y,
- };
- startPoint2 = roadPointService.create(startPoint2);
- uiService.isBelongRoad(UIEvents.OneEdgeOneLanRoad);
- roadService.create(startPoint2.vectorId, crossPoint.vectorId);
- edgeService.updateEdgeForMulRoad(crossPoint.vectorId);
- }
- buildHighSpeedTollBooth(position) {
- const roadLen = 600;
- let startPoint = {
- x: position.x,
- y: position.y + roadLen / 2,
- };
- let endPoint = {
- x: position.x,
- y: position.y - roadLen / 2,
- };
- startPoint = roadPointService.create(startPoint);
- endPoint = roadPointService.create(endPoint);
- uiService.setWayType(Constant.oneWay);
- uiService.setSingleRoadDrivewayCount(6);
- uiService.setSingleRoadWidth(Settings.singleLaneWidth * 6);
- roadService.create(startPoint.vectorId, endPoint.vectorId);
- }
- buildHighwaySection(position) {
- const roadLen = 600;
- let startPoint = {
- x: position.x,
- y: position.y + roadLen / 2,
- };
- let endPoint = {
- x: position.x,
- y: position.y - roadLen / 2,
- };
- startPoint = roadPointService.create(startPoint);
- endPoint = roadPointService.create(endPoint);
- uiService.isBelongRoad(UIEvents.TwoEdgeTwoLanRoad);
- roadService.create(startPoint.vectorId, endPoint.vectorId);
- }
- //这个还没解决
- buildHighSpeedHarbor(position) {}
- //这个还没解决
- buildWideNarrowRoad(position) {}
- }
- const addCrossRoad = new AddCrossRoad();
- export { addCrossRoad };
|