UNPKG

2.47 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var matrix_util_1 = require("@antv/matrix-util");
5var __1 = require("..");
6var util_1 = require("../util");
7var MIN_DISTANCE = 5;
8/**
9 * @ignore
10 * View 移动的 Action
11 */
12var Move = /** @class */ (function (_super) {
13 tslib_1.__extends(Move, _super);
14 function Move() {
15 var _this = _super !== null && _super.apply(this, arguments) || this;
16 _this.starting = false;
17 _this.isMoving = false;
18 // private cacheRange = null;
19 _this.startPoint = null;
20 _this.startMatrix = null;
21 return _this;
22 }
23 /**
24 * 开始移动
25 */
26 Move.prototype.start = function () {
27 this.starting = true;
28 this.startPoint = this.context.getCurrentPoint();
29 // 缓存开始时的矩阵,防止反复拖拽
30 this.startMatrix = this.context.view.middleGroup.getMatrix();
31 };
32 /**
33 * 移动
34 */
35 Move.prototype.move = function () {
36 if (!this.starting) {
37 return;
38 }
39 var startPoint = this.startPoint;
40 var currentPoint = this.context.getCurrentPoint();
41 var d = util_1.distance(startPoint, currentPoint);
42 if (d > MIN_DISTANCE && !this.isMoving) {
43 this.isMoving = true;
44 }
45 if (this.isMoving) {
46 var view = this.context.view;
47 var matrix = matrix_util_1.ext.transform(this.startMatrix, [
48 ['t', currentPoint.x - startPoint.x, currentPoint.y - startPoint.y],
49 ]);
50 view.backgroundGroup.setMatrix(matrix);
51 view.foregroundGroup.setMatrix(matrix);
52 view.middleGroup.setMatrix(matrix);
53 }
54 };
55 /**
56 * 结束移动
57 */
58 Move.prototype.end = function () {
59 if (this.isMoving) {
60 this.isMoving = false;
61 }
62 this.startMatrix = null;
63 this.starting = false;
64 this.startPoint = null;
65 };
66 /**
67 * 回滚
68 */
69 Move.prototype.reset = function () {
70 this.starting = false;
71 this.startPoint = null;
72 this.isMoving = false;
73 var view = this.context.view;
74 view.backgroundGroup.resetMatrix();
75 view.foregroundGroup.resetMatrix();
76 view.middleGroup.resetMatrix();
77 this.isMoving = false;
78 };
79 return Move;
80}(__1.Action));
81exports.default = Move;
82//# sourceMappingURL=move.js.map
\No newline at end of file