UNPKG

medsurf-draw

Version:

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

143 lines 6.75 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 { Design } from "../../config/design"; import { BaseContainer, BaseContainerImageModel } from "../../bases/elements/BaseContainer"; var WedgePointModel = (function (_super) { __extends(WedgePointModel, _super); function WedgePointModel() { return _super !== null && _super.apply(this, arguments) || this; } return WedgePointModel; }(BaseContainerImageModel)); export { WedgePointModel }; var WedgePoint = (function (_super) { __extends(WedgePoint, _super); function WedgePoint(model) { var _this = _super.call(this, model) || this; _this.zIndex = Design.wedgePoint.zIndex; _this.modeInteraction.on("default", _this._modeDefault, _this); _this.modeInteraction.on("remove-default", _this._removeModeDefault, _this); _this.modeInteraction.on("marker", _this._modeDefault, _this); _this.modeInteraction.on("remove-marker", _this._removeModeDefault, _this); _this.modeInteraction.on("selftest", _this._modeDefault, _this); _this.modeInteraction.on("remove-selftest", _this._removeModeDefault, _this); _this.modeInteraction.on("author", _this._modeDefault, _this); _this.modeInteraction.on("remove-author", _this._removeModeDefault, _this); _this.modeInteraction.on('select_parent', _this._modeSelectParent, _this); _this.modeInteraction.on("remove-select_parent", _this._removeModeSelectParent, _this); _this.modeInteraction.on('select_legend', _this._modeSelectParent, _this); _this.modeInteraction.on("remove-select_legend", _this._removeModeSelectParent, _this); _this.moveInteraction = new MedsurfDraw.MoveInteraction(_this); return _this; } WedgePoint.prototype.init = function () { this.position.set(this.wedgePoint.x, this.wedgePoint.y); this._wedgePointElement = new MedsurfDraw.Circle({ circle: new PIXI.Circle(0, 0, Design.wedgePoint.radius), options: { hasLine: true, lineColor: Design.wedgePoint.lineColorNormal, lineAlpha: Design.wedgePoint.lineAlpha, hasFill: true, fillColor: Design.wedgePoint.fillColorNormal, fillAlpha: Design.wedgePoint.fillAlpha }, lineWidth: Design.wedgePoint.lineWidth }); this.addChild(this._wedgePointElement); this.sortChildren(); this.emit("debounceDraw"); }; WedgePoint.prototype.draw = function () { this.position.set(this.wedgePoint.x, this.wedgePoint.y); var scale = this.imageScale.x * Design.wedgePoint.scaleAspect; var radius = Design.wedgePoint.radius; radius = Math.floor(radius / scale); var lineWidth = Math.floor(Design.wedgePoint.lineWidth || 1 / scale); if (lineWidth < 1) { lineWidth = 1; } this._wedgePointElement.circle.radius = radius; this._wedgePointElement.lineWidth = lineWidth; this._wedgePointElement.draw(); }; WedgePoint.prototype.destroy = function (options) { if (this.moveInteraction) { this.moveInteraction.removeAllListeners(); } if (this._wedgePointElement) { this._wedgePointElement.destroy(options); } _super.prototype.destroy.call(this, options); }; WedgePoint.prototype._modeDefault = function () { this.hideItem(); }; WedgePoint.prototype._removeModeDefault = function () { }; WedgePoint.prototype._modeSelectParent = function () { this.interactive = true; this.on("pointerover", this.onHover, this); this.on("pointerout", this.onOut, this); this.on("pointerover", this.moveInteraction.onMoveHover, this.moveInteraction); this.on("mousedown", this.moveInteraction.startMove, this.moveInteraction); this.on("pointermove", this.moveInteraction.onMove, this.moveInteraction); this.on("mouseup", this.moveInteraction.endMove, this.moveInteraction); this.showItem(); this.emit("debounceDraw"); }; WedgePoint.prototype._removeModeSelectParent = function () { this.interactive = false; this.off("pointerover", this.onHover, this); this.off("pointerout", this.onOut, this); this.off("pointerover", this.moveInteraction.onMoveHover, this.moveInteraction); this.off("mousedown", this.moveInteraction.startMove, this.moveInteraction); this.off("pointermove", this.moveInteraction.onMove, this.moveInteraction); this.off("mouseup", this.moveInteraction.endMove, this.moveInteraction); this.hideItem(); }; WedgePoint.prototype.onHover = function () { this._wedgePointElement.options.lineColor = Design.wedgePoint.lineColorHover; this._wedgePointElement.options.fillColor = Design.wedgePoint.fillColorHover; this.emit("debounceDraw"); }; WedgePoint.prototype.onOut = function () { this._wedgePointElement.options.lineColor = Design.wedgePoint.lineColorNormal; this._wedgePointElement.options.fillColor = Design.wedgePoint.fillColorNormal; this.emit("debounceDraw"); }; WedgePoint.prototype.onImageZoom = function (scaleX, scaleY) { this.emit("debounceDraw"); }; Object.defineProperty(WedgePoint.prototype, "wedgePoint", { get: function () { return this.data.wedgePoint; }, set: function (value) { this.data.wedgePoint = value; }, enumerable: false, configurable: true }); Object.defineProperty(WedgePoint.prototype, "moveInteraction", { get: function () { return this._moveInteraction; }, set: function (value) { this._moveInteraction = value; }, enumerable: false, configurable: true }); return WedgePoint; }(BaseContainer)); export { WedgePoint }; //# sourceMappingURL=WedgePoint.js.map