medsurf-draw
Version:
Draw annotations on jpg/zoomify images, based on PIXI.js
112 lines • 4.17 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { BaseElementInteraction } from "../bases/interactions/BaseElementInteraction";
var RotateInteraction = (function (_super) {
__extends(RotateInteraction, _super);
function RotateInteraction(element, rotateWithLine) {
var _this = _super.call(this, element) || this;
_this.rotateWithLine = rotateWithLine || false;
return _this;
}
RotateInteraction.prototype.reset = function () {
this._rotateX = 0;
this._isRotating = false;
};
RotateInteraction.prototype.startRotate = function (event) {
event.stopPropagation();
this.emit("startRotateStart", event);
if (this._isRotating) {
return;
}
var scale = this.element.imageScale;
this._rotateX = event.data.global.x / scale.x;
this._isRotating = true;
this.emit("startRotate", event);
};
RotateInteraction.prototype.onRotate = function (event) {
if (!this._isRotating) {
return;
}
var scale = this.element.imageScale;
var dR = (event.data.global.x / scale.x - this._rotateX);
this._rotateX = event.data.global.x / scale.x;
var degree = Math.round(dR) % 360 * (2 * Math.PI / 360);
this.emit("onRotate", degree);
};
RotateInteraction.prototype.endRotate = function (event) {
event.stopPropagation();
this.emit("endRotateStart", event);
if (!this._isRotating) {
return;
}
this._isRotating = false;
this.emit("endRotate", event);
};
RotateInteraction.prototype.lineRotate = function (event) {
if (!this.rotateWithLine) {
return;
}
var parent = this.element.parent;
var lineStartX = 0;
var lineStartY = 0;
var lineEndX = 0;
var lineEndY = 0;
var lines = parent.getLines();
if (lines.length === 0) {
return;
}
for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
var line = lines_1[_i];
if (line.start === parent) {
if (!line.start || !line.end) {
return;
}
lineStartX += line.start.x;
lineStartY += line.start.y;
lineEndX += line.end.x;
lineEndY += line.end.y;
}
else {
if (!line.start || !line.end) {
return;
}
lineStartX += line.end.x;
lineStartY += line.end.y;
lineEndX += line.start.x;
lineEndY += line.start.y;
}
}
lineStartX /= lines.length;
lineStartY /= lines.length;
lineEndX /= lines.length;
lineEndY /= lines.length;
var degree = Math.atan2(lineEndY - lineStartY, lineEndX - lineStartX) - (90 * Math.PI / 180) || 0;
this.emit("lineRotate", degree);
};
Object.defineProperty(RotateInteraction.prototype, "rotateWithLine", {
get: function () {
return this._rotateWithLine;
},
set: function (value) {
this._rotateWithLine = value;
},
enumerable: false,
configurable: true
});
return RotateInteraction;
}(BaseElementInteraction));
export { RotateInteraction };
//# sourceMappingURL=RotateInteraction.js.map