Road.js 3.5 KB

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