UNPKG

medsurf-draw

Version:

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

162 lines 8.89 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 LegendGeneratorModel = (function (_super) { __extends(LegendGeneratorModel, _super); function LegendGeneratorModel() { return _super !== null && _super.apply(this, arguments) || this; } return LegendGeneratorModel; }(BaseGeneratorModel)); export { LegendGeneratorModel }; var LegendGenerator = (function (_super) { __extends(LegendGenerator, _super); function LegendGenerator(model) { var _this = _super.call(this, model) || this; _this._isImageMoving = false; _this.target.modeInteraction.setModeItem("drawing"); _this._legendElement = MedsurfDraw.LegendCollection.getInstance(_this.target, _this.target.dimensions.width); _this.legendElement.hideItem(); _this.target.addChild(_this.legendElement); _this.legendElement.controlDrawItem(true); _this._drawInteraction = new MedsurfDraw.DrawInteraction(_this.legendElement, MedsurfDraw.StickMode.NOELEMENTS); _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.legendElement.moveInteraction.startMove, _this.legendElement.moveInteraction); _this.drawInteraction.on("resetMove", _this.legendElement.moveInteraction.resetMove, _this.legendElement.moveInteraction); _this.drawInteraction.on("onMove", _this.legendElement.moveInteraction.onMove, _this.legendElement.moveInteraction); _this.drawInteraction.on("endMove", _this.legendElement.moveInteraction.endMove, _this.legendElement.moveInteraction); _this.drawInteraction.on("startDraw", _this.legendElement.startDraw, _this.legendElement); _this.drawInteraction.on("startDrawScale", _this.legendElement.startDrawScale, _this.legendElement); _this.drawInteraction.on("onDraw", _this.legendElement.onDraw, _this.legendElement); _this.drawInteraction.on("onScale", _this.onScale, _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; } LegendGenerator.prototype.start = function (event) { var pos = this.target.renderer.plugins.interaction.mouse.global; var rect = this.target.getRectangle(); this.legendElement.position.x += (pos.x - rect.x) / this.target.scale.x; this.legendElement.position.y += (pos.y - rect.y) / this.target.scale.y; this.drawInteraction.startDraw(event); this.legendElement.showItem(); _super.prototype.start.call(this, event); this.target.addImageObject(this.legendElement.model, this.data.layerGroup, this.data.image); }; LegendGenerator.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.off("startMove", this.legendElement.moveInteraction.startMove, this.legendElement.moveInteraction); this.drawInteraction.off("resetMove", this.legendElement.moveInteraction.resetMove, this.legendElement.moveInteraction); this.drawInteraction.off("onMove", this.legendElement.moveInteraction.onMove, this.legendElement.moveInteraction); this.drawInteraction.off("endMove", this.legendElement.moveInteraction.endMove, this.legendElement.moveInteraction); this.drawInteraction.off("startDraw", this.legendElement.startDraw, this.legendElement); this.drawInteraction.off("startDrawScale", this.legendElement.startDrawScale, this.legendElement); this.drawInteraction.off("onDraw", this.legendElement.onDraw, this.legendElement); this.drawInteraction.off("onScale", this.onScale, this); this.drawInteraction.off("endDraw", this.endDraw, this); this.drawInteraction.off("abortDraw", this.abortDraw, this); _super.prototype.end.call(this); }; LegendGenerator.prototype.destroy = function (options) { this.end(); if (this.legendElement && this.legendElement.modeInteraction.lastMode.endsWith('_new')) { this.legendElement.modeInteraction.setMode('delete_draw'); } }; LegendGenerator.prototype.endGenerator = function () { _super.prototype.endGenerator.call(this); this.target.sortChildren(); this.target.modeInteraction.setMode(this.target.modeInteraction.defaultMode); }; LegendGenerator.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); }; LegendGenerator.prototype.onScale = function (event) { event.stopPropagation(); this._isImageMoving = true; }; LegendGenerator.prototype.endDraw = function (event) { event.stopPropagation(); if (this._isImageMoving) { this._isImageMoving = false; this.drawInteraction.startDraw(event); return; } this.legendElement.modeInteraction.setModeItem("draw_select_new"); this.emit("endGenerator"); this.end(); }; LegendGenerator.prototype.abortDraw = function (event) { event.stopPropagation(); this.emit("abortGenerator"); this.destroy(); }; LegendGenerator.prototype.onZoom = function () { var pos = this.target.renderer.plugins.interaction.mouse.global; var rect = this.target.getRectangle(); this.legendElement.position.x = (pos.x - rect.x) / this.target.scale.x; this.legendElement.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(LegendGenerator.prototype, "drawInteraction", { get: function () { return this._drawInteraction; }, enumerable: false, configurable: true }); Object.defineProperty(LegendGenerator.prototype, "legendElement", { get: function () { return this._legendElement; }, enumerable: false, configurable: true }); return LegendGenerator; }(BaseGenerator)); export { LegendGenerator }; //# sourceMappingURL=LegendGenerator.js.map