123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- import { SGraphItem, SGraphView } from "@saga-web/graph/lib";
- import { SMouseButton, SMouseEvent, SNetUtil } from "@saga-web/base/lib";
- import { SPoint } from "@saga-web/draw/lib";
- /**
- * 楼层场景
- *
- * @author 郝建龙
- */
- export class FloorView extends SGraphView {
- /** 鼠标左键键按下时位置 */
- private _leftKeyPos = new SPoint();
- /** 空格是否被按下 */
- private spaceKey: boolean = false;
- /**
- * 保存底图json
- *
- * @param name 文件名
- */
- saveFloorJson(name: string): void {
- // @ts-ignore
- if (!this.scene || !this.scene.json) return;
- // @ts-ignore
- let url = URL.createObjectURL(new Blob([this.scene.json]));
- SNetUtil.downLoad(name, url);
- } // Function saveSceneSvg()
- /**
- * 按键按下事件
- *
- * @param event 事件参数
- */
- protected onKeyDown(event: KeyboardEvent): void {
- let keyCode = event.keyCode;
- this.spaceKey = false;
- switch (keyCode) {
- case 32:
- this.spaceKey = true;
- break;
- case 87:
- this.origin.y -= 10;
- break;
- case 83:
- this.origin.y += 10;
- break;
- case 68:
- this.origin.x += 10;
- break;
- case 65:
- this.origin.x -= 10;
- break;
- default:
- super.onKeyDown(event);
- break;
- }
- this.update();
- } // Function onKeyDown()
- /**
- * 按键松开事件
- *
- * @param event 事件参数
- */
- protected onKeyUp(event: KeyboardEvent): void {
- this.spaceKey = false;
- super.onKeyUp(event);
- } // Function onKeyUp()
- /**
- * 鼠标按下事件
- *
- * @param event 事件参数
- */
- protected onMouseDown(event: MouseEvent): void {
- ``
- let se = new SMouseEvent(event);
- if (se.buttons & SMouseButton.LeftButton) {
- this._leftKeyPos.x = se.x;
- this._leftKeyPos.y = se.y;
- }
- super.onMouseDown(event);
- } // Function onMouseDown()
- /**
- * 鼠标移动事件
- *
- * @param event 事件参数
- */
- protected onMouseMove(event: MouseEvent): void {
- // 按左键移动
- let se = new SMouseEvent(event);
- if (se.buttons & SMouseButton.LeftButton) {
- if (this.spaceKey) {
- this.origin.x += se.x - this._leftKeyPos.x;
- this.origin.y += se.y - this._leftKeyPos.y;
- }
- this._leftKeyPos.x = se.x;
- this._leftKeyPos.y = se.y;
- this.update();
- }
- super.onMouseMove(event);
- } // Function onMouseMove()
- // 模拟双击事件
- tryDbclick() {
- const event = {
- altKey: false,
- buttons: 0,
- clientX: 574,
- clientY: 309,
- ctrlKey: false,
- screenX: 574,
- screenY: 412,
- type: "dblclick",
- x: 545767.790241906,
- y: 210014.18692875182,
- }
- this.onDoubleClick(event)
- }
- } // Class FloorScene
|