Browse Source

继续添加公路

xushiting 2 years ago
parent
commit
43e3d3cd5c

+ 2 - 0
src/graphic/Constant.js

@@ -34,5 +34,7 @@ const Constant = {
   maxRoadSideWidth: 800,
   oneWay: "oneWay", //one表示单向,two表示双向
   twoWay: "twoWay", //one表示单向,two表示双向
+  defaultSingleLaneWidth: 30, //单个车道的宽度
+  defaultMidDivideWidth: 5, //隔离带的宽度
 };
 export default Constant;

+ 8 - 8
src/graphic/Controls/AddCrossRoad.js

@@ -30,10 +30,10 @@ export default class AddCrossRoad {
     });
 
     //需要设置公路的车道数,是否双向等等
-    // this.leftDrivewayCount = Setting.roadLeftDrivewayCount;
-    // this.rightDrivewayCount = Setting.roadRightDrivewayCount;
-    // this.singleRoadDrivewayCount = Setting.singleRoadDrivewayCount;
-    // this.way = Setting.wayType;
+    // this.leftDrivewayCount = Settings.roadLeftDrivewayCount;
+    // this.rightDrivewayCount = Settings.roadRightDrivewayCount;
+    // this.singleRoadDrivewayCount = Settings.singleRoadDrivewayCount;
+    // this.way = Settings.wayType;
 
     roadService.create(start1.vectorId, end.vectorId);
     roadService.create(start2.vectorId, end.vectorId);
@@ -66,10 +66,10 @@ export default class AddCrossRoad {
     });
 
     //需要设置公路的车道数,是否双向等等
-    // this.leftDrivewayCount = Setting.roadLeftDrivewayCount;
-    // this.rightDrivewayCount = Setting.roadRightDrivewayCount;
-    // this.singleRoadDrivewayCount = Setting.singleRoadDrivewayCount;
-    // this.way = Setting.wayType;
+    // this.leftDrivewayCount = Settings.roadLeftDrivewayCount;
+    // this.rightDrivewayCount = Settings.roadRightDrivewayCount;
+    // this.singleRoadDrivewayCount = Settings.singleRoadDrivewayCount;
+    // this.way = Settings.wayType;
 
     roadService.create(start1.vectorId, end.vectorId);
     roadService.create(start2.vectorId, end.vectorId);

+ 8 - 8
src/graphic/Geometry/CurveRoad.js

@@ -1,6 +1,6 @@
 import VectorType from "../enum/VectorType.js";
 import Road from "./Road.js";
-import Setting from "../Setting";
+import Settings from "../Settings";
 
 export default class CurveRoad extends Road {
   constructor(startId, endId, vectorId) {
@@ -9,20 +9,20 @@ export default class CurveRoad extends Road {
     this.leftLanesCurves = []; //左车道曲线
     this.rightLanesCurves = []; //左车道曲线
     this.singleLanesCurves = []; //单向车道
-    this.leftDrivewayCount = Setting.curveRoadLeftDrivewayCount; //左边的车道个数
-    this.rightDrivewayCount = Setting.curveRoadRightDrivewayCount; //右边的车道个数
-    this.leftWidth = Setting.leftCurveRoadWidth;
-    this.rightWidth = Setting.rightCurveRoadWidth;
+    this.leftDrivewayCount = Settings.curveRoadLeftDrivewayCount; //左边的车道个数
+    this.rightDrivewayCount = Settings.curveRoadRightDrivewayCount; //右边的车道个数
+    this.leftWidth = Settings.leftCurveRoadWidth;
+    this.rightWidth = Settings.rightCurveRoadWidth;
     this.midDivide = {
       leftMidDivide: [],
       leftMidDivideCurves: [],
       rightMidDivide: [],
       rightMidDivideCurves: [],
-      midDivideWidth: Setting.curveRoadMidDivideWidth,
+      midDivideWidth: Settings.curveRoadMidDivideWidth,
     };
     this.curves = [];
-    this.singleCurveRoadWidth = Setting.singleCurveRoadWidth;
-    this.singleCurveRoadDrivewayCount = Setting.singleCurveRoadDrivewayCount;
+    this.singleCurveRoadWidth = Settings.singleCurveRoadWidth;
+    this.singleCurveRoadDrivewayCount = Settings.singleCurveRoadDrivewayCount;
     this.geoType = VectorType.CurveRoad;
     this.setId(vectorId);
   }

+ 13 - 9
src/graphic/Geometry/Road.js

@@ -1,6 +1,6 @@
 import VectorType from "../enum/VectorType.js";
 import Geometry from "./Geometry.js";
-import Setting from "../Setting";
+import Settings from "../Settings";
 import Constant from "../Constant";
 
 export default class Road extends Geometry {
@@ -18,17 +18,17 @@ export default class Road extends Geometry {
     this.midDivide = {
       leftMidDivide: {},
       rightMidDivide: {},
-      midDivideWidth: Setting.roadMidDivideWidth,
+      midDivideWidth: Settings.roadMidDivideWidth,
     };
 
-    this.leftDrivewayCount = Setting.roadLeftDrivewayCount; //左边的车道个数
-    this.rightDrivewayCount = Setting.roadRightDrivewayCount; //右边的车道个数
+    this.leftDrivewayCount = Settings.roadLeftDrivewayCount; //左边的车道个数
+    this.rightDrivewayCount = Settings.roadRightDrivewayCount; //右边的车道个数
     this.geoType = VectorType.Road;
-    this.leftWidth = Setting.leftRoadWidth;
-    this.rightWidth = Setting.rightRoadWidth;
-    this.singleRoadWidth = Setting.singleRoadWidth;
-    this.singleRoadDrivewayCount = Setting.singleRoadDrivewayCount;
-    this.way = Setting.wayType;
+    this.leftWidth = Settings.leftRoadWidth;
+    this.rightWidth = Settings.rightRoadWidth;
+    this.singleRoadWidth = Settings.singleRoadWidth;
+    this.singleRoadDrivewayCount = Settings.singleRoadDrivewayCount;
+    this.way = Settings.wayType;
     this.setId(vectorId);
   }
 
@@ -83,4 +83,8 @@ export default class Road extends Geometry {
       this.rightDrivewayCount = 0;
     }
   }
+
+  setWay(value) {
+    this.way = value;
+  }
 }

+ 8 - 2
src/graphic/Service/ElementService.js

@@ -7,6 +7,7 @@ import ElementEvents from "../enum/ElementEvents.js";
 import VectorCategory from "../enum/VectorCategory.js";
 import { listenLayer } from "../ListenLayer";
 import Constant from "../Constant";
+import Settings from "../Settings";
 import { dataService } from "./DataService.js";
 import { mathUtil } from "../Util/MathUtil";
 import { coordinate } from "../Coordinate.js";
@@ -172,16 +173,21 @@ export class ElementService {
   setNewRoad(point1, point2) {
     this.newRoad.start.setPosition(point1);
     this.newRoad.end.setPosition(point2);
+    this.newRoad.setWay(Settings.wayType);
+
     //需要更新Edge坐标
     if (!mathUtil.equalPoint(point1, point2)) {
       let edgePoints = null;
       if (this.newRoad.way == Constant.oneWay) {
-        edgePoints = mathUtil.RectangleVertex(
+        this.newRoad.singleRoadWidth = Settings.singleRoadWidth;
+        this.newRoad.rightWidth = edgePoints = mathUtil.RectangleVertex(
           point1,
           point2,
-          this.newRoad.leftWidth + this.newRoad.rightWidth
+          this.newRoad.rightWidth
         );
       } else if (this.newRoad.way == Constant.twoWay) {
+        this.newRoad.leftWidth = Settings.leftRoadWidth;
+        this.newRoad.rightWidth = Settings.rightRoadWidth;
         edgePoints = mathUtil.RectangleVertex(
           point1,
           point2,

+ 52 - 18
src/graphic/Service/UIService.js

@@ -1,36 +1,50 @@
 import Text from "../Geometry/Text.js";
 import { dataService } from "./DataService.js";
 import { mathUtil } from "../Util/MathUtil.js";
-import Setting from "../Setting";
+import Settings from "../Settings";
 import { coordinate } from "../Coordinate.js";
+import UIEvents from "../enum/UIEvents.js";
+import Constant from "../Constant.js";
 
 export default class UIService {
   constructor() {}
 
   isBelongRoad(ui) {
-    if (ui == "OneEdgeOneLanRoad") {
-      this.setRoadLeftDrivewayCount(0);
-      this.setRoadRightDrivewayCount(0);
+    if (ui == UIEvents.OneEdgeOneLanRoad) {
+      this.setWayType(Constant.oneWay);
+      this.setSingleRoadDrivewayCount(1);
+      this.setSingleRoadWidth(Settings.singleLaneWidth);
       return true;
-    } else if (ui == "OneEdgeTwoLanRoad") {
-      this.setRoadLeftDrivewayCount(0);
-      this.setRoadRightDrivewayCount(0);
+    } else if (ui == UIEvents.OneEdgeTwoLanRoad) {
+      this.setWayType(Constant.oneWay);
+      this.setSingleRoadDrivewayCount(2);
+      this.setSingleRoadWidth(Settings.singleLaneWidth * 2);
       return true;
-    } else if (ui == "OneEdgeThreeLanRoad") {
-      this.setRoadLeftDrivewayCount(0);
-      this.setRoadRightDrivewayCount(0);
+    } else if (ui == UIEvents.OneEdgeThreeLanRoad) {
+      this.setWayType(Constant.oneWay);
+      this.setSingleRoadDrivewayCount(3);
+      this.setSingleRoadWidth(Settings.singleLaneWidth * 3);
       return true;
-    } else if (ui == "TwoEdgeOneLanRoad") {
+    } else if (ui == UIEvents.TwoEdgeOneLanRoad) {
+      this.setWayType(Constant.twoWay);
       this.setRoadLeftDrivewayCount(1);
       this.setRoadRightDrivewayCount(1);
+      this.setLeftRoadWidth(Settings.singleLaneWidth);
+      this.setRightRoadWidth(Settings.singleLaneWidth);
       return true;
-    } else if (ui == "TwoEdgeTwoLanRoad") {
+    } else if (ui == UIEvents.TwoEdgeTwoLanRoad) {
+      this.setWayType(Constant.twoWay);
       this.setRoadLeftDrivewayCount(2);
       this.setRoadRightDrivewayCount(2);
+      this.setLeftRoadWidth(Settings.singleLaneWidth * 2);
+      this.setRightRoadWidth(Settings.singleLaneWidth * 2);
       return true;
-    } else if (ui == "TwoEdgeThreeLanRoad") {
+    } else if (ui == UIEvents.TwoEdgeThreeLanRoad) {
+      this.setWayType(Constant.twoWay);
       this.setRoadLeftDrivewayCount(3);
       this.setRoadRightDrivewayCount(3);
+      this.setLeftRoadWidth(Settings.singleLaneWidth * 3);
+      this.setRightRoadWidth(Settings.singleLaneWidth * 3);
       return true;
     }
     return false;
@@ -41,27 +55,47 @@ export default class UIService {
       this.setRoadLeftDrivewayCount(0);
       this.setRoadRightDrivewayCount(0);
       return true;
-    } else if (ui == "OneEdgeOneLanRoad") {
+    } else if (ui == UIEvents.OneEdgeOneLanRoad) {
       this.setRoadLeftDrivewayCount(0);
       this.setRoadRightDrivewayCount(0);
       return true;
     }
   }
 
+  setWayType(value) {
+    Settings.wayType = value;
+  }
+
+  setSingleRoadDrivewayCount(value) {
+    Settings.singleRoadDrivewayCount = value;
+  }
+
   setRoadLeftDrivewayCount(value) {
-    Setting.roadLeftDrivewayCount = value;
+    Settings.roadLeftDrivewayCount = value;
   }
 
   setRoadRightDrivewayCount(value) {
-    Setting.roadRightDrivewayCount = value;
+    Settings.roadRightDrivewayCount = value;
   }
 
   setCurveRoadLeftDrivewayCount(value) {
-    Setting.curveRoadLeftDrivewayCount = value;
+    Settings.curveRoadLeftDrivewayCount = value;
   }
 
   setCurveRoadRightDrivewayCount(value) {
-    Setting.curveRoadRightDrivewayCount = value;
+    Settings.curveRoadRightDrivewayCount = value;
+  }
+
+  setSingleRoadWidth(value) {
+    Settings.singleRoadWidth = value;
+  }
+
+  setLeftRoadWidth(value) {
+    Settings.leftRoadWidth = value;
+  }
+
+  setRightRoadWidth(value) {
+    Settings.rightRoadWidth = value;
   }
 
   //如果position在屏幕左上角,返回的就朝向右下角,如果是右下角,则返回的是左上角。其他情况以此类推

+ 5 - 4
src/graphic/Setting.js

@@ -1,5 +1,5 @@
 import Constant from "./Constant";
-const Setting = {
+const Settings = {
   roadLeftDrivewayCount: 1,
   roadRightDrivewayCount: 1,
   curveRoadLeftDrivewayCount: 1,
@@ -12,8 +12,9 @@ const Setting = {
   rightRoadWidth: 50,
   leftCurveRoadWidth: 50,
   rightCurveRoadWidth: 50,
-  roadMidDivideWidth: 40,
-  curveRoadMidDivideWidth: 40,
+  singleLaneWidth: Constant.defaultSingleLaneWidth,
+  roadMidDivideWidth: Constant.defaultMidDivideWidth,
+  curveRoadMidDivideWidth: Constant.defaultMidDivideWidth,
   wayType: Constant.twoWay, //one表示单向,two表示双向
 };
-export default Setting;
+export default Settings;