UNPKG

medsurf-draw

Version:

Draw annotations on jpg/zoomify images, based on PIXI.js

183 lines 9.55 kB
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 * as PIXI from "pixi.js-legacy"; import * as MedsurfDraw from "../../public-api"; import { BaseGenerator, BaseGeneratorModel } from "../../bases/generators/BaseGenerator"; var PositionPointGeneratorModel = (function (_super) { __extends(PositionPointGeneratorModel, _super); function PositionPointGeneratorModel() { return _super !== null && _super.apply(this, arguments) || this; } return PositionPointGeneratorModel; }(BaseGeneratorModel)); export { PositionPointGeneratorModel }; var PositionPointGenerator = (function (_super) { __extends(PositionPointGenerator, _super); function PositionPointGenerator(model) { var _this = _super.call(this, model) || this; _this._isImageMoving = false; _this.target.modeInteraction.setModeItem("drawing"); _this._positionPointElement = MedsurfDraw.PositionPoint.getInstance(_this.target); _this.positionPointElement.hideItem(); _this.target.addChild(_this.positionPointElement); _this.positionPointElement.controlDrawItem(true); _this._drawInteraction = new MedsurfDraw.DrawInteraction(_this.positionPointElement, _this.stickMode); _this.target.on('imageZoom', _this.onZoom, _this); _this.target.parent.on("mousedown", _this.drawInteraction.startDrawScale, _this.drawInteraction); _this.target.parent.on("rightup", _this.drawInteraction.abortDraw, _this.drawInteraction); _this.target.parent.on("pointermove", _this.drawInteraction.onDraw, _this.drawInteraction); _this.target.parent.on("mouseup", _this.drawInteraction.endDraw, _this.drawInteraction); _this.drawInteraction.on("startMove", _this.positionPointElement.moveInteraction.startMove, _this.positionPointElement.moveInteraction); _this.drawInteraction.on("resetMove", _this.positionPointElement.moveInteraction.resetMove, _this.positionPointElement.moveInteraction); _this.drawInteraction.on("onMove", _this.positionPointElement.moveInteraction.onMove, _this.positionPointElement.moveInteraction); _this.drawInteraction.on("endMove", _this.positionPointElement.moveInteraction.endMove, _this.positionPointElement.moveInteraction); _this.drawInteraction.on("startDraw", _this.positionPointElement.startDraw, _this.positionPointElement); _this.drawInteraction.on("startDrawScale", _this.positionPointElement.startDrawScale, _this.positionPointElement); _this.drawInteraction.on("onDraw", _this.positionPointElement.onDraw, _this.positionPointElement); _this.drawInteraction.on("onScale", _this.onScale, _this); _this.drawInteraction.on("updatePoint", _this.updatePoint, _this); _this.drawInteraction.on("updateFill", _this.updateFill, _this); _this.drawInteraction.on("endDraw", _this.endDraw, _this); _this.drawInteraction.on("abortDraw", _this.abortDraw, _this); var globalPoint = _this.target.renderer.plugins.interaction.mouse.global; var hitTest = _this.target.renderer.plugins.interaction.hitTest(globalPoint, _this.target.parent); if (!hitTest) { _this.target.parent.once("pointerover", _this.start, _this); } else { var event_1 = new PIXI.InteractionEvent(); event_1.data = new PIXI.InteractionData(); event_1.data.global = globalPoint; _this.emit("debounceStart", event_1); } return _this; } PositionPointGenerator.prototype.start = function (event) { var pos = this.target.renderer.plugins.interaction.mouse.global; var rect = this.target.getRectangle(); this.positionPointElement.position.x += (pos.x - rect.x) / this.target.scale.x; this.positionPointElement.position.y += (pos.y - rect.y) / this.target.scale.y; this.drawInteraction.startDraw(event); this.positionPointElement.showItem(); _super.prototype.start.call(this, event); this.target.addImageObject(this.positionPointElement.model, this.data.layerGroup, this.data.image); }; PositionPointGenerator.prototype.end = function () { this.target.off('imageZoom', this.onZoom, this); this.target.parent.off("mousedown", this.drawInteraction.startDrawScale, this.drawInteraction); this.target.parent.off("rightup", this.drawInteraction.abortDraw, this.drawInteraction); this.target.parent.off("pointermove", this.drawInteraction.onDraw, this.drawInteraction); this.target.parent.off("mouseup", this.drawInteraction.endDraw, this.drawInteraction); this.drawInteraction.removeAllListeners(); _super.prototype.end.call(this); }; PositionPointGenerator.prototype.destroy = function (options) { this.end(); if (this.positionPointElement && this.positionPointElement.modeInteraction.lastMode.endsWith('new')) { this.positionPointElement.modeInteraction.setMode('delete_draw'); } }; PositionPointGenerator.prototype.endGenerator = function () { _super.prototype.endGenerator.call(this); this.target.sortChildren(); this.target.modeInteraction.setMode(this.target.modeInteraction.defaultMode); }; PositionPointGenerator.prototype.abortGenerator = function () { _super.prototype.abortGenerator.call(this); this.target.getImageObjects() .filter(function (imageObject) { return imageObject.modeInteraction.lastMode.startsWith('draw_') && imageObject.modeInteraction.lastMode.endsWith('_new'); }) .forEach(function (imageObject) { imageObject.modeInteraction.setMode("delete_draw"); }); this.target.sortChildren(); this.target.modeInteraction.setMode(this.target.modeInteraction.defaultMode); }; PositionPointGenerator.prototype.onScale = function (event) { event.stopPropagation(); this._isImageMoving = true; }; PositionPointGenerator.prototype.updatePoint = function (event, positionPoint) { event.stopPropagation(); this.destroy(); this._positionPointElement = positionPoint; if (!this.positionPointElement.modeInteraction.lastMode.startsWith("draw_select")) { this.positionPointElement.modeInteraction.setModeItem('draw_select'); } this.emit("updatePoint"); }; PositionPointGenerator.prototype.updateFill = function (event, fillCollection) { event.stopPropagation(); this.destroy(); this._positionPointElement = fillCollection; if (!this.positionPointElement.modeInteraction.lastMode.startsWith("draw_select")) { this.positionPointElement.modeInteraction.setModeItem('draw_select'); } this.emit('updateFill'); }; PositionPointGenerator.prototype.endDraw = function (event) { event.stopPropagation(); if (this._isImageMoving) { this._isImageMoving = false; this.drawInteraction.startDraw(event); return; } this.positionPointElement.modeInteraction.setModeItem('draw_select_new'); this.emit("endGenerator"); this.end(); }; PositionPointGenerator.prototype.abortDraw = function (event) { event.stopPropagation(); this.emit("abortGenerator"); this.destroy(); }; PositionPointGenerator.prototype.onZoom = function () { var pos = this.target.renderer.plugins.interaction.mouse.global; var rect = this.target.getRectangle(); this.positionPointElement.position.x = (pos.x - rect.x) / this.target.scale.x; this.positionPointElement.position.y = (pos.y - rect.y) / this.target.scale.y; var event = new PIXI.InteractionEvent(); event.data = new PIXI.InteractionData(); event.data.global = pos; this.drawInteraction.resetDraw(event); }; Object.defineProperty(PositionPointGenerator.prototype, "drawInteraction", { get: function () { return this._drawInteraction; }, enumerable: false, configurable: true }); Object.defineProperty(PositionPointGenerator.prototype, "positionPointElement", { get: function () { return this._positionPointElement; }, enumerable: false, configurable: true }); Object.defineProperty(PositionPointGenerator.prototype, "stickMode", { get: function () { return this.data.stickMode; }, set: function (value) { this.data.stickMode = value; }, enumerable: false, configurable: true }); return PositionPointGenerator; }(BaseGenerator)); export { PositionPointGenerator }; //# sourceMappingURL=PositionPointGenerator.js.map