UIService.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. import VectorStyle from "../enum/VectorStyle.js";
  10. import VectorWeight from "../enum/VectorWeight.js";
  11. import RoadTemplate from "../enum/RoadTemplate.js";
  12. import RoadStructure from "../enum/RoadStructure.js";
  13. import Message from "@/components/base/components/message/message.vue";
  14. export default class UIService {
  15. constructor() {}
  16. isBelongRoad(ui) {
  17. if (ui == UIEvents.OneEdgeOneLanRoad) {
  18. this.setWayType(Constant.oneWay);
  19. this.setSingleRoadDrivewayCount(1);
  20. this.setSingleRoadWidth(Settings.singleLaneWidth);
  21. return true;
  22. } else if (ui == UIEvents.OneEdgeTwoLanRoad) {
  23. this.setWayType(Constant.oneWay);
  24. this.setSingleRoadDrivewayCount(2);
  25. this.setSingleRoadWidth(Settings.singleLaneWidth * 2);
  26. return true;
  27. } else if (ui == UIEvents.OneEdgeThreeLanRoad) {
  28. this.setWayType(Constant.oneWay);
  29. this.setSingleRoadDrivewayCount(3);
  30. this.setSingleRoadWidth(Settings.singleLaneWidth * 3);
  31. return true;
  32. } else if (ui == UIEvents.TwoEdgeOneLanRoad) {
  33. this.setWayType(Constant.twoWay);
  34. this.setRoadLeftDrivewayCount(1);
  35. this.setRoadRightDrivewayCount(1);
  36. this.setLeftRoadWidth(Settings.singleLaneWidth);
  37. this.setRightRoadWidth(Settings.singleLaneWidth);
  38. return true;
  39. } else if (ui == UIEvents.TwoEdgeTwoLanRoad) {
  40. this.setWayType(Constant.twoWay);
  41. this.setRoadLeftDrivewayCount(2);
  42. this.setRoadRightDrivewayCount(2);
  43. this.setLeftRoadWidth(Settings.singleLaneWidth * 2);
  44. this.setRightRoadWidth(Settings.singleLaneWidth * 2);
  45. return true;
  46. } else if (ui == UIEvents.TwoEdgeThreeLanRoad) {
  47. this.setWayType(Constant.twoWay);
  48. this.setRoadLeftDrivewayCount(3);
  49. this.setRoadRightDrivewayCount(3);
  50. this.setLeftRoadWidth(Settings.singleLaneWidth * 3);
  51. this.setRightRoadWidth(Settings.singleLaneWidth * 3);
  52. return true;
  53. }
  54. return false;
  55. }
  56. isBelongCurveRoad(ui) {
  57. if (ui == "SBend") {
  58. this.setRoadLeftDrivewayCount(0);
  59. this.setRoadRightDrivewayCount(0);
  60. return true;
  61. } else if (ui == UIEvents.OneEdgeOneLanRoad) {
  62. this.setRoadLeftDrivewayCount(0);
  63. this.setRoadRightDrivewayCount(0);
  64. return true;
  65. }
  66. }
  67. isBelongLine(ui) {
  68. if (ui == UIEvents.SingleArrow) {
  69. this.setSelectLineCategory(VectorCategory.Line.SingleArrowLine);
  70. return true;
  71. } else if (ui == UIEvents.DoubleArrow) {
  72. this.setSelectLineCategory(VectorCategory.Line.DoubleArrowLine);
  73. return true;
  74. } else if (ui == UIEvents.MeasureLine) {
  75. this.setSelectLineCategory(VectorCategory.Line.MeasureLine);
  76. return true;
  77. } else if (ui == UIEvents.Line) {
  78. this.setSelectLineCategory(VectorCategory.Line.NormalLine);
  79. return true;
  80. } else if (ui == UIEvents.FreeMeasureLine) {
  81. this.setSelectLineCategory(VectorCategory.Line.FreeMeasureLine);
  82. return true;
  83. } else if (ui == UIEvents.BaseLine) {
  84. this.setSelectLineCategory(VectorCategory.Line.BaseLine);
  85. return true;
  86. }
  87. return false;
  88. }
  89. isBelongPoint(ui) {
  90. if (ui == UIEvents.BasePoint) {
  91. this.setSelectPointCategory(VectorCategory.Point.BasePoint);
  92. return true;
  93. } else if (ui == UIEvents.FixPoint) {
  94. this.setSelectPointCategory(VectorCategory.Point.FixPoint);
  95. return true;
  96. }
  97. return false;
  98. }
  99. isBelongRoadEdgeStyle(ui) {
  100. if (ui == VectorStyle.SingleSolidLine) {
  101. return true;
  102. } else if (ui == VectorStyle.SingleDashedLine) {
  103. return true;
  104. } else if (ui == VectorStyle.DoubleSolidLine) {
  105. return true;
  106. } else if (ui == VectorStyle.DoubleDashedLine) {
  107. return true;
  108. } else if (ui == VectorStyle.BrokenLine) {
  109. return true;
  110. } else if (ui == VectorStyle.PointDrawLine) {
  111. return true;
  112. } else if (ui == VectorStyle.Greenbelt) {
  113. return true;
  114. } else if (ui == VectorWeight.Bold) {
  115. return true;
  116. } else if (ui == VectorWeight.Thinning) {
  117. return true;
  118. } else {
  119. return false;
  120. }
  121. }
  122. isBelongRoadTemplate(ui) {
  123. if (RoadTemplate[ui]) {
  124. this.setSelectRoadTemplate(ui);
  125. return true;
  126. } else {
  127. return false;
  128. }
  129. }
  130. isBelongRoadStructure(ui) {
  131. if (RoadStructure[ui]) {
  132. this.setSelectRoadStructure(ui);
  133. return true;
  134. } else {
  135. return false;
  136. }
  137. }
  138. setWayType(value) {
  139. Settings.wayType = value;
  140. }
  141. setSelectBasePointId(value) {
  142. Settings.selectBasePointId = value;
  143. }
  144. setSingleRoadDrivewayCount(value) {
  145. Settings.singleRoadDrivewayCount = value;
  146. }
  147. setRoadLeftDrivewayCount(value) {
  148. Settings.roadLeftDrivewayCount = value;
  149. }
  150. setRoadRightDrivewayCount(value) {
  151. Settings.roadRightDrivewayCount = value;
  152. }
  153. setCurveRoadLeftDrivewayCount(value) {
  154. Settings.curveRoadLeftDrivewayCount = value;
  155. }
  156. setCurveRoadRightDrivewayCount(value) {
  157. Settings.curveRoadRightDrivewayCount = value;
  158. }
  159. setSingleRoadWidth(value) {
  160. Settings.singleRoadWidth = value;
  161. }
  162. setLeftRoadWidth(value) {
  163. Settings.leftRoadWidth = value;
  164. }
  165. setRightRoadWidth(value) {
  166. Settings.rightRoadWidth = value;
  167. }
  168. setCurveRoadLeftDrivewayCount(value) {
  169. Settings.curveRoadLeftDrivewayCount = value;
  170. }
  171. setCurveRoadRightDrivewayCount(value) {
  172. Settings.curveRoadRightDrivewayCount = value;
  173. }
  174. setLeftCurveRoadWidth(value) {
  175. Settings.leftCurveRoadWidth = value;
  176. }
  177. setRightCurveRoadWidth(value) {
  178. Settings.rightCurveRoadWidth = value;
  179. }
  180. setSelectLineCategory(value) {
  181. Settings.selectLineCategory = value;
  182. }
  183. setSelectPointCategory(value) {
  184. Settings.selectPointCategory = value;
  185. }
  186. //设置定位法
  187. setSelectLocationMode(value) {
  188. Settings.selectLocationMode = value;
  189. }
  190. getSelectLocationMode() {
  191. return Settings.selectLocationMode;
  192. }
  193. setSelectSVGType(value) {
  194. Settings.selectSVGType = value;
  195. }
  196. getSelectRoadTemplate() {
  197. return Settings.selectRoadTemplate;
  198. }
  199. setSelectRoadTemplate(value) {
  200. Settings.selectRoadTemplate = value;
  201. }
  202. setSelectRoadStructure(value) {
  203. Settings.selectRoadStructure = value;
  204. }
  205. getSelectRoadStructure() {
  206. return Settings.selectRoadStructure;
  207. }
  208. //Constant.defaultMidDivideWidth是真实宽度,现在赋值的时候要转换成像素
  209. setRoadMidDivideWidth(value) {
  210. Settings.roadMidDivideWidth = value;
  211. }
  212. //Constant.defaultMidDivideWidth是真实宽度,现在赋值的时候要转换成像素
  213. setCurveRoadMidDivideWidth(value) {
  214. Settings.curveRoadMidDivideWidth = value;
  215. }
  216. //Constant.defaultSingleLaneWidth是真实宽度,现在赋值的时候要转换成像素
  217. setSingleLaneWidth(value) {
  218. Settings.singleLaneWidth = value;
  219. }
  220. getSingleLaneWidth() {
  221. return Settings.singleLaneWidth;
  222. }
  223. getRoadMidDivideWidth() {
  224. return Settings.roadMidDivideWidth;
  225. }
  226. getLineWidth() {
  227. return Settings.lineWidth;
  228. }
  229. setLineWidth(value) {
  230. Settings.lineWidth = value;
  231. }
  232. //如果position在屏幕左上角,返回的就朝向右下角,如果是右下角,则返回的是左上角。其他情况以此类推
  233. getNewPositionForPop(position) {
  234. const offset = 50;
  235. const center = coordinate.getXYFromScreen({
  236. x: coordinate.width / 2,
  237. y: coordinate.height / 2,
  238. });
  239. let newPosition = {};
  240. mathUtil.clonePoint(newPosition, position);
  241. if (position.x > center.x) {
  242. newPosition.x -= offset;
  243. } else if (position.x < center.x) {
  244. newPosition.x += offset;
  245. }
  246. if (position.y > center.y) {
  247. newPosition.y -= offset;
  248. } else if (position.y < center.y) {
  249. newPosition.y += offset;
  250. }
  251. return newPosition;
  252. }
  253. currentShowMsgs = [];
  254. prompt(msg) {
  255. const config = typeof msg === "string" ? { msg, time: 1000 } : msg;
  256. if (this.currentShowMsgs.includes(config.msg)) {
  257. return;
  258. }
  259. this.currentShowMsgs.push(config.msg);
  260. setTimeout(() => {
  261. this.currentShowMsgs = this.currentShowMsgs.filter(
  262. (msg) => msg !== config.msg
  263. );
  264. }, config.time);
  265. Message.success(config);
  266. }
  267. }
  268. const uiService = new UIService();
  269. export { uiService };