Road.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import VectorType from "../enum/VectorType.js";
  2. import Geometry from "./Geometry.js";
  3. import Settings from "../Settings";
  4. import Constant from "../Constant";
  5. export default class Road extends Geometry {
  6. constructor(startId, endId, vectorId) {
  7. super();
  8. this.startId = startId;
  9. this.endId = endId;
  10. this.leftEdgeId = null;
  11. this.rightEdgeId = null;
  12. this.leftLanes = []; //二维数组。第一维表示第几个车道,第二维是一组点
  13. this.rightLanes = [];
  14. this.singleLanes = []; //单向车道
  15. //道路中间隔离栏 ,起点和终点与startId和endId方向一致。但是坐标有区别。因为隔离栏要比start-end短一些
  16. //单向车道没有中间栏
  17. this.midDivide = {
  18. leftMidDivide: {},
  19. rightMidDivide: {},
  20. midDivideWidth: Settings.roadMidDivideWidth,
  21. };
  22. this.leftDrivewayCount = Settings.roadLeftDrivewayCount; //左边的车道个数
  23. this.rightDrivewayCount = Settings.roadRightDrivewayCount; //右边的车道个数
  24. this.geoType = VectorType.Road;
  25. this.leftWidth = Settings.leftRoadWidth;
  26. this.rightWidth = Settings.rightRoadWidth;
  27. this.singleRoadWidth = Settings.singleRoadWidth;
  28. this.singleRoadDrivewayCount = Settings.singleRoadDrivewayCount;
  29. this.way = Settings.wayType;
  30. this.setId(vectorId);
  31. }
  32. setWidth(value, dir) {
  33. if (this.way == Constant.twoWay) {
  34. if (dir == "left") {
  35. this.leftWidth = value;
  36. } else if (dir == "right") {
  37. this.rightWidth = value;
  38. }
  39. } else if (this.way == Constant.oneWay) {
  40. this.singleRoadWidth = value;
  41. }
  42. }
  43. getOtherPointId(pointId) {
  44. if (this.startId == pointId) {
  45. return this.endId;
  46. } else if (this.endId == pointId) {
  47. return this.startId;
  48. } else {
  49. return null;
  50. }
  51. }
  52. getPointId(dir) {
  53. if (dir == "start") {
  54. return this.startId;
  55. } else {
  56. return this.endId;
  57. }
  58. }
  59. addLeftDrivewayCount() {
  60. ++this.leftDrivewayCount;
  61. }
  62. subtractLeftDrivewayCount() {
  63. --this.leftDrivewayCount;
  64. if (this.leftDrivewayCount < 0) {
  65. this.leftDrivewayCount = 0;
  66. }
  67. }
  68. addRightDrivewayCount() {
  69. ++this.rightDrivewayCount;
  70. }
  71. subtractRightDrivewayCount() {
  72. ++this.rightDrivewayCount;
  73. if (this.rightDrivewayCount < 0) {
  74. this.rightDrivewayCount = 0;
  75. }
  76. }
  77. setWay(value) {
  78. this.way = value;
  79. }
  80. getLanesCount(dir) {
  81. if (this.way == Constant.oneWay) {
  82. return this.singleRoadDrivewayCount;
  83. } else if (this.way == Constant.twoWay) {
  84. if (dir == "left") {
  85. return this.leftDrivewayCount;
  86. } else {
  87. return this.rightDrivewayCount;
  88. }
  89. }
  90. }
  91. }