AddLine.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { dataService } from "../Service/DataService";
  2. import { lineService } from "../Service/LineService";
  3. import { listenLayer } from "../ListenLayer";
  4. import VectorCategory from "../enum/VectorCategory";
  5. export default class AddLine {
  6. constructor() {
  7. this.startInfo = {};
  8. this.endInfo = {};
  9. this.category = VectorCategory.Line.NormalLine;
  10. }
  11. setPointInfo(dir, pointInfo) {
  12. if (dir == "start") {
  13. this.startInfo = {
  14. position: {
  15. x: pointInfo.x,
  16. y: pointInfo.y,
  17. },
  18. linkedPointId: pointInfo.linkedPointId,
  19. lineId: pointInfo.lineId,
  20. };
  21. } else if (dir == "end") {
  22. this.endInfo = {
  23. position: {
  24. x: pointInfo.x,
  25. y: pointInfo.y,
  26. },
  27. linkedPointId: pointInfo.linkedPointId,
  28. lineId: pointInfo.lineId,
  29. };
  30. }
  31. }
  32. setNewLinePoint(dir, position) {
  33. if (dir == "start") {
  34. if (listenLayer.modifyPoint) {
  35. this.setPointInfo(dir, listenLayer.modifyPoint);
  36. } else {
  37. this.setPointInfo(dir, position);
  38. }
  39. return true;
  40. } else if (dir == "end") {
  41. if (listenLayer.modifyPoint) {
  42. this.setPointInfo(dir, listenLayer.modifyPoint);
  43. } else {
  44. this.setPointInfo(dir, position);
  45. }
  46. return true;
  47. }
  48. return false;
  49. }
  50. buildLine() {
  51. lineService.create(
  52. this.startInfo.position,
  53. this.endInfo.position,
  54. this.category
  55. );
  56. listenLayer.clear();
  57. this.clear();
  58. }
  59. clear() {
  60. this.startInfo = {};
  61. this.endInfo = {};
  62. }
  63. }
  64. const addLine = new AddLine();
  65. export { addLine };