RoadEdge.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //墙的边缘线
  2. import Geometry from "./Geometry.js";
  3. import VectorType from "../enum/VectorType.js";
  4. import VectorWight from "../enum/VectorWeight.js";
  5. import VectorStyle from "../enum/VectorStyle.js";
  6. import { mathUtil } from "../Util/MathUtil.js";
  7. import { dataService } from "../Service/DataService.js";
  8. import Constant from "../Constant";
  9. import { coordinate } from "../Coordinate";
  10. export default class RoadEdge extends Geometry {
  11. constructor(start, end, vectorId, parentId) {
  12. super();
  13. this.parent = parentId;
  14. this.start = {};
  15. this.end = {};
  16. this.vectorId = null;
  17. this.style = VectorStyle.SingleSolidLine;
  18. this.weight = VectorWight.Thinning;
  19. this.geoType = VectorType.RoadEdge;
  20. this.lineWidth = 4;
  21. this.roadSide = null;
  22. this.setId(vectorId);
  23. this.setPositions(start, end);
  24. }
  25. setPositions(point1, point2) {
  26. this.start.x = point1.x;
  27. this.start.y = point1.y;
  28. this.end.x = point2.x;
  29. this.end.y = point2.y;
  30. }
  31. setPosition(position, dir) {
  32. if (dir == "start") {
  33. mathUtil.clonePoint(this.start, position);
  34. } else if (dir == "end") {
  35. mathUtil.clonePoint(this.end, position);
  36. }
  37. }
  38. setLineWidth(value) {
  39. this.lineWidth = value;
  40. }
  41. getPosition(dir) {
  42. if (dir == "start") {
  43. return this.start;
  44. } else if (dir == "end") {
  45. return this.end;
  46. } else {
  47. return null;
  48. }
  49. }
  50. getLine() {
  51. let line = mathUtil.createLine1(this.start, this.end);
  52. return line;
  53. }
  54. initRoadSide() {
  55. // let line = this.getLine();
  56. let startPoint = this.start;
  57. let road = dataService.getRoad(this.parent);
  58. let endPoint = this.end;
  59. // let lines = mathUtil.getParallelLineForDistance(line, Constant.roadSideWidth);
  60. // let joinPoint = lines.line1;
  61. // for (let key in road) {
  62. // if (this.vectorId == road[key]) {
  63. // if (key == 'rightEdgeId') {
  64. // console.error('rightEdgeId')
  65. // joinPoint = lines.line2;
  66. // } else if (key == 'leftEdgeId') {
  67. // console.error('leftEdgeId')
  68. // joinPoint = lines.line1;
  69. // }
  70. // }
  71. // }
  72. // let point1 = mathUtil.getJoinLinePoint(startPoint, joinPoint);
  73. // let point2 = mathUtil.getJoinLinePoint(endPoint, joinPoint);
  74. if (!this.roadSide) {
  75. this.roadSide = {};
  76. this.roadSide["width"] = Constant.roadSideWidth;
  77. }
  78. let roadSidePoints = mathUtil.RectangleVertex(startPoint, endPoint, (this.roadSide.width * 2) / 5);
  79. for (let key in road) {
  80. if (this.vectorId == road[key]) {
  81. if (key == "rightEdgeId") {
  82. this.roadSide["start"] = roadSidePoints.rightEdgeStart;
  83. this.roadSide["end"] = roadSidePoints.rightEdgeEnd;
  84. } else if (key == "leftEdgeId") {
  85. this.roadSide["start"] = roadSidePoints.leftEdgeStart;
  86. this.roadSide["end"] = roadSidePoints.leftEdgeEnd;
  87. }
  88. }
  89. }
  90. // this.roadSide['start'] = point1;
  91. // this.roadSide['end'] = point2;
  92. }
  93. setRoadSideWidth(width) {
  94. this.roadSide.width = width;
  95. this.initRoadSide();
  96. }
  97. setRoadSide(roadSide) {
  98. this.roadSide = JSON.parse(JSON.stringify(roadSide));
  99. }
  100. removeRoadSide() {
  101. this.roadSide = null;
  102. }
  103. }