UIService.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import Text from "../Geometry/Text.js";
  2. import { dataService } from "./DataService.js";
  3. import { mathUtil } from "../Util/MathUtil.js";
  4. import Settings from "../Settings";
  5. import { coordinate } from "../Coordinate.js";
  6. import UIEvents from "../enum/UIEvents.js";
  7. import VectorCategory from "../enum/VectorCategory.js";
  8. import Constant from "../Constant.js";
  9. export default class UIService {
  10. constructor() {}
  11. isBelongRoad(ui) {
  12. if (ui == UIEvents.OneEdgeOneLanRoad) {
  13. this.setWayType(Constant.oneWay);
  14. this.setSingleRoadDrivewayCount(1);
  15. this.setSingleRoadWidth(Settings.singleLaneWidth);
  16. return true;
  17. } else if (ui == UIEvents.OneEdgeTwoLanRoad) {
  18. this.setWayType(Constant.oneWay);
  19. this.setSingleRoadDrivewayCount(2);
  20. this.setSingleRoadWidth(Settings.singleLaneWidth * 2);
  21. return true;
  22. } else if (ui == UIEvents.OneEdgeThreeLanRoad) {
  23. this.setWayType(Constant.oneWay);
  24. this.setSingleRoadDrivewayCount(3);
  25. this.setSingleRoadWidth(Settings.singleLaneWidth * 3);
  26. return true;
  27. } else if (ui == UIEvents.TwoEdgeOneLanRoad) {
  28. this.setWayType(Constant.twoWay);
  29. this.setRoadLeftDrivewayCount(1);
  30. this.setRoadRightDrivewayCount(1);
  31. this.setLeftRoadWidth(Settings.singleLaneWidth);
  32. this.setRightRoadWidth(Settings.singleLaneWidth);
  33. return true;
  34. } else if (ui == UIEvents.TwoEdgeTwoLanRoad) {
  35. this.setWayType(Constant.twoWay);
  36. this.setRoadLeftDrivewayCount(2);
  37. this.setRoadRightDrivewayCount(2);
  38. this.setLeftRoadWidth(Settings.singleLaneWidth * 2);
  39. this.setRightRoadWidth(Settings.singleLaneWidth * 2);
  40. return true;
  41. } else if (ui == UIEvents.TwoEdgeThreeLanRoad) {
  42. this.setWayType(Constant.twoWay);
  43. this.setRoadLeftDrivewayCount(3);
  44. this.setRoadRightDrivewayCount(3);
  45. this.setLeftRoadWidth(Settings.singleLaneWidth * 3);
  46. this.setRightRoadWidth(Settings.singleLaneWidth * 3);
  47. return true;
  48. }
  49. return false;
  50. }
  51. isBelongCurveRoad(ui) {
  52. if (ui == "SBend") {
  53. this.setRoadLeftDrivewayCount(0);
  54. this.setRoadRightDrivewayCount(0);
  55. return true;
  56. } else if (ui == UIEvents.OneEdgeOneLanRoad) {
  57. this.setRoadLeftDrivewayCount(0);
  58. this.setRoadRightDrivewayCount(0);
  59. return true;
  60. }
  61. }
  62. isBelongLine(ui) {
  63. if (ui == UIEvents.Arrow) {
  64. this.setLineCategory(VectorCategory.Line.ArrowLine);
  65. return true;
  66. } else if (ui == UIEvents.MeasureLine) {
  67. this.setLineCategory(VectorCategory.Line.MeasureLine);
  68. return true;
  69. } else if (ui == UIEvents.Line) {
  70. this.setLineCategory(VectorCategory.Line.NormalLine);
  71. return true;
  72. } else if (ui == UIEvents.BaseLine) {
  73. this.setLineCategory(VectorCategory.Line.BaseLine);
  74. return true;
  75. }
  76. return false;
  77. }
  78. isBelongPoint(ui) {
  79. if (ui == UIEvents.NormalLocationMode) {
  80. this.setPointCategory(VectorCategory.Point.TestPoint);
  81. this.setLocationMode(Constant.normalLocationMode);
  82. return true;
  83. } else if (ui == UIEvents.AngleLocationMode) {
  84. this.setPointCategory(VectorCategory.Point.TestPoint);
  85. this.setLocationMode(Constant.angleLocationMode);
  86. return true;
  87. } else if (ui == UIEvents.AllLocationMode) {
  88. this.setPointCategory(VectorCategory.Point.TestPoint);
  89. this.setLocationMode(Constant.allLocationMode);
  90. return true;
  91. } else if (ui == UIEvents.BasePoint) {
  92. this.setPointCategory(VectorCategory.Point.BasePoint);
  93. this.setLocationMode(null);
  94. return true;
  95. }
  96. return false;
  97. }
  98. setWayType(value) {
  99. Settings.wayType = value;
  100. }
  101. setSingleRoadDrivewayCount(value) {
  102. Settings.singleRoadDrivewayCount = value;
  103. }
  104. setRoadLeftDrivewayCount(value) {
  105. Settings.roadLeftDrivewayCount = value;
  106. }
  107. setRoadRightDrivewayCount(value) {
  108. Settings.roadRightDrivewayCount = value;
  109. }
  110. setCurveRoadLeftDrivewayCount(value) {
  111. Settings.curveRoadLeftDrivewayCount = value;
  112. }
  113. setCurveRoadRightDrivewayCount(value) {
  114. Settings.curveRoadRightDrivewayCount = value;
  115. }
  116. setSingleRoadWidth(value) {
  117. Settings.singleRoadWidth = value;
  118. }
  119. setLeftRoadWidth(value) {
  120. Settings.leftRoadWidth = value;
  121. }
  122. setRightRoadWidth(value) {
  123. Settings.rightRoadWidth = value;
  124. }
  125. setLineCategory(value) {
  126. Settings.lineCategory = value;
  127. }
  128. setPointCategory(value) {
  129. Settings.pointCategory = value;
  130. }
  131. //设置定位法
  132. setLocationMode(value) {
  133. Settings.locationMode = value;
  134. }
  135. //如果position在屏幕左上角,返回的就朝向右下角,如果是右下角,则返回的是左上角。其他情况以此类推
  136. getNewPositionForPop(position) {
  137. const offset = 50;
  138. const center = coordinate.getXYFromScreen({
  139. x: coordinate.width / 2,
  140. y: coordinate.height / 2,
  141. });
  142. let newPosition = {};
  143. mathUtil.clonePoint(newPosition, position);
  144. if (position.x > center.x) {
  145. newPosition.x -= offset;
  146. } else if (position.x < center.x) {
  147. newPosition.x += offset;
  148. }
  149. if (position.y > center.y) {
  150. newPosition.y -= offset;
  151. } else if (position.y < center.y) {
  152. newPosition.y += offset;
  153. }
  154. return newPosition;
  155. }
  156. }
  157. const uiService = new UIService();
  158. export { uiService };