FloorView.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { SGraphItem, SGraphView } from "@saga-web/graph/lib";
  2. import { SMouseButton, SMouseEvent, SNetUtil } from "@saga-web/base/lib";
  3. import { SPoint } from "@saga-web/draw/lib";
  4. /**
  5. * 楼层场景
  6. *
  7. * @author 郝建龙
  8. */
  9. export class FloorView extends SGraphView {
  10. /** 鼠标左键键按下时位置 */
  11. private _leftKeyPos = new SPoint();
  12. /** 空格是否被按下 */
  13. private spaceKey: boolean = false;
  14. /**
  15. * 保存底图json
  16. *
  17. * @param name 文件名
  18. */
  19. saveFloorJson(name: string): void {
  20. // @ts-ignore
  21. if (!this.scene || !this.scene.json) return;
  22. // @ts-ignore
  23. let url = URL.createObjectURL(new Blob([this.scene.json]));
  24. SNetUtil.downLoad(name, url);
  25. } // Function saveSceneSvg()
  26. /**
  27. * 按键按下事件
  28. *
  29. * @param event 事件参数
  30. */
  31. protected onKeyDown(event: KeyboardEvent): void {
  32. let keyCode = event.keyCode;
  33. this.spaceKey = false;
  34. switch (keyCode) {
  35. case 32:
  36. this.spaceKey = true;
  37. break;
  38. case 87:
  39. this.origin.y -= 10;
  40. break;
  41. case 83:
  42. this.origin.y += 10;
  43. break;
  44. case 68:
  45. this.origin.x += 10;
  46. break;
  47. case 65:
  48. this.origin.x -= 10;
  49. break;
  50. default:
  51. super.onKeyDown(event);
  52. break;
  53. }
  54. this.update();
  55. } // Function onKeyDown()
  56. /**
  57. * 按键松开事件
  58. *
  59. * @param event 事件参数
  60. */
  61. protected onKeyUp(event: KeyboardEvent): void {
  62. this.spaceKey = false;
  63. super.onKeyUp(event);
  64. } // Function onKeyUp()
  65. /**
  66. * 鼠标按下事件
  67. *
  68. * @param event 事件参数
  69. */
  70. protected onMouseDown(event: MouseEvent): void {
  71. ``
  72. let se = new SMouseEvent(event);
  73. if (se.buttons & SMouseButton.LeftButton) {
  74. this._leftKeyPos.x = se.x;
  75. this._leftKeyPos.y = se.y;
  76. }
  77. super.onMouseDown(event);
  78. } // Function onMouseDown()
  79. /**
  80. * 鼠标移动事件
  81. *
  82. * @param event 事件参数
  83. */
  84. protected onMouseMove(event: MouseEvent): void {
  85. // 按左键移动
  86. let se = new SMouseEvent(event);
  87. if (se.buttons & SMouseButton.LeftButton) {
  88. if (this.spaceKey) {
  89. this.origin.x += se.x - this._leftKeyPos.x;
  90. this.origin.y += se.y - this._leftKeyPos.y;
  91. }
  92. this._leftKeyPos.x = se.x;
  93. this._leftKeyPos.y = se.y;
  94. this.update();
  95. }
  96. super.onMouseMove(event);
  97. } // Function onMouseMove()
  98. // 模拟双击事件
  99. tryDbclick() {
  100. const event = {
  101. altKey: false,
  102. buttons: 0,
  103. clientX: 574,
  104. clientY: 309,
  105. ctrlKey: false,
  106. screenX: 574,
  107. screenY: 412,
  108. type: "dblclick",
  109. x: 545767.790241906,
  110. y: 210014.18692875182,
  111. }
  112. this.onDoubleClick(event)
  113. }
  114. } // Class FloorScene