UNPKG

medsurf-draw

Version:

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

672 lines 29.4 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 { BaseContainer, BaseContainerImageModel } from "../../bases/elements/BaseContainer"; import { Design } from "../../config/design"; import { debounce } from 'debounce'; export var SelectGroupType; (function (SelectGroupType) { SelectGroupType[SelectGroupType["GROUPING"] = 0] = "GROUPING"; SelectGroupType[SelectGroupType["LAYERGROUP"] = 1] = "LAYERGROUP"; })(SelectGroupType || (SelectGroupType = {})); var SelectGroupModel = (function (_super) { __extends(SelectGroupModel, _super); function SelectGroupModel() { return _super !== null && _super.apply(this, arguments) || this; } return SelectGroupModel; }(BaseContainerImageModel)); export { SelectGroupModel }; var SelectGroupElement = (function (_super) { __extends(SelectGroupElement, _super); function SelectGroupElement(model) { var _this = _super.call(this, model) || this; _this._menuShown = false; _this.displayObjects = []; _this.imageObjectMenu = []; _this.groupingMenu = []; _this.zIndex = Design.selectElement.zIndex; _this.contextInteraction = new MedsurfDraw.ContextInteraction(_this); _this.contextInteraction.on("endRight", _this.endRight, _this); _this.moveInteraction = new MedsurfDraw.MoveInteraction(_this); _this.moveInteraction.on("startMove", _this.startMove, _this); _this.moveInteraction.on("onMove", _this.onMove, _this); _this.moveInteraction.on("endMove", _this.endMove, _this); _this._debounceControlSelectDefaultModeMethod = debounce(_this.controlSetDefaultMode.bind(_this), 50).bind(_this); _this.on("added", function () { _this.on("debounceControlSelectDefaultMode", _this._debounceControlSelectDefaultModeMethod); _this.image.modeInteraction.on("default", _this._modeDefault, _this); _this.image.modeInteraction.on("remove-default", _this._removeModeDefault, _this); _this.image.modeInteraction.on("author", _this._modeAuthor, _this); _this.image.modeInteraction.on("remove-author", _this._removeModeAuthor, _this); _this.image.modeInteraction.on("setDefaultMode", _this._debounceControlSelectDefaultModeMethod); _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.on("removed", function () { _this.off("debounceControlSelectDefaultMode", _this._debounceControlSelectDefaultModeMethod); _this.image.modeInteraction.off("default", _this._modeDefault, _this); _this.image.modeInteraction.off("remove-default", _this._removeModeDefault, _this); _this.image.modeInteraction.off("author", _this._modeAuthor, _this); _this.image.modeInteraction.off("remove-author", _this._removeModeAuthor, _this); _this.image.modeInteraction.off("setDefaultMode", _this._debounceControlSelectDefaultModeMethod); _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); }); return _this; } SelectGroupElement.prototype.init = function () { this.hideItem(); this.position.set(0, 0); this._selectElement = new MedsurfDraw.Rectangle({ rectangle: new PIXI.Rectangle(0, 0, 0, 0), options: { hasLine: true, lineColor: Design.selectElement.lineColor, lineAlpha: Design.selectElement.lineAlpha, hasFill: true, fillColor: Design.selectElement.fillColor, fillAlpha: Design.selectElement.fillAlpha }, lineWidth: Design.selectElement.lineWidth }); this._selectElement.zIndex = Design.selectElement.zIndex + 1; this.addChild(this._selectElement); this._imageObjectMenuElement = new MedsurfDraw.MenuElement({ image: this.image, menuElements: undefined }); this.image.parent.addChild(this._imageObjectMenuElement); this._groupingMenuElement = new MedsurfDraw.MenuElement({ image: this.image, menuElements: undefined }); this.image.parent.addChild(this._groupingMenuElement); this._editButtonElement = new MedsurfDraw.RoundButtonElement({ image: this.image, text: '\uf3f0', description: 'Bearbeiten', descriptionFontSize: Design.subMenu.descriptionFontSize, circle: new PIXI.Circle(0, 0, Design.subMenu.buttonRadius), fontSize: Design.subMenu.fontSize, fontColor: Design.subMenu.fontColor }); this._editButtonElement.on("onHover", this.collapseAllMenus, this); this._editButtonElement.on("button", this.onButtonEdit, this); this.imageObjectMenu.push({ element: this._editButtonElement, order: 0, }); this._moveToBackButtonElement = new MedsurfDraw.RoundButtonElement({ image: this.image, text: '\uf87f', description: 'Nach Hinten\nverschieben', descriptionFontSize: Design.subMenu.descriptionFontSize, circle: new PIXI.Circle(0, 0, Design.subMenu.buttonRadius), fontSize: Design.subMenu.fontSize, fontColor: Design.subMenu.fontColor }); this._moveToBackButtonElement.on("button", this.onButtonMoveToBack, this); this._moveToFrontButtonElement = new MedsurfDraw.RoundSubMenuElement({ image: this.image, text: '\uf856', description: 'Nach Vorne\nverschieben', descriptionFontSize: Design.subMenu.descriptionFontSize, menuElements: [ { element: this._moveToBackButtonElement, order: 0, } ], circle: new PIXI.Circle(0, 0, Design.subMenu.buttonRadius) }); this._moveToFrontButtonElement.on("onHover", this._moveToFrontButtonElement.showMenu, this._moveToFrontButtonElement); this._moveToFrontButtonElement.on("button", this.onButtonMoveToFront, this); this.imageObjectMenu.push({ element: this._moveToFrontButtonElement, order: 7, }); this._deleteButtonElement = new MedsurfDraw.RoundButtonElement({ image: this.image, text: '\uf1f8', description: 'Löschen', descriptionFontSize: Design.subMenu.descriptionFontSize, circle: new PIXI.Circle(0, 0, Design.subMenu.buttonRadius), fontSize: Design.subMenu.fontSize, fontColor: Design.subMenu.fontColor }); this._deleteButtonElement.on("onHover", this.collapseAllMenus, this); this._deleteButtonElement.on("button", this.onButtonDelete, this); this.imageObjectMenu.push({ element: this._deleteButtonElement, order: 6, }); this._degroupButtonElement = new MedsurfDraw.RoundButtonElement({ image: this.image, text: '\uf248', description: 'Gruppe\nauflösen', descriptionFontSize: Design.subMenu.descriptionFontSize, circle: new PIXI.Circle(0, 0, Design.subMenu.buttonRadius), fontSize: Design.subMenu.fontSize, fontColor: Design.subMenu.fontColor }); this._degroupButtonElement.on("onHover", this.collapseAllMenus, this); this._degroupButtonElement.on("button", this.onButtonDegroup, this); this.imageObjectMenu.push({ element: this._degroupButtonElement, order: 4, }); this._duplicateButtonElement = new MedsurfDraw.RoundButtonElement({ image: this.image, text: '\uf24d', description: 'Duplizieren', descriptionFontSize: Design.subMenu.descriptionFontSize, circle: new PIXI.Circle(0, 0, Design.subMenu.buttonRadius), fontSize: Design.subMenu.fontSize, fontColor: Design.subMenu.fontColor }); this._duplicateButtonElement.on("onHover", this.collapseAllMenus, this); this._duplicateButtonElement.on("button", this.onButtonDuplicate, this); this.imageObjectMenu.push({ element: this._duplicateButtonElement, order: 2, }); this._clipboardButtonElement = new MedsurfDraw.RoundButtonElement({ image: this.image, text: '\uf0c5', description: 'Kopieren', descriptionFontSize: Design.subMenu.descriptionFontSize, circle: new PIXI.Circle(0, 0, Design.subMenu.buttonRadius), fontSize: Design.subMenu.fontSize, fontColor: Design.subMenu.fontColor }); this._clipboardButtonElement.on("onHover", this.collapseAllMenus, this); this._clipboardButtonElement.on("button", this.onButtonClipboard, this); this.imageObjectMenu.push({ element: this._clipboardButtonElement, order: 1, }); this._imageObjectMenuElement.menuElements = this.imageObjectMenu; this._imageObjectMenuElement.hideItem(); this._interactiveGroupingButtonElement = new MedsurfDraw.RoundButtonElement({ image: this.image, text: '\uf277', description: 'Interaktive\nFläche\n(Gruppe)', descriptionFontSize: Design.subMenu.descriptionFontSize, circle: new PIXI.Circle(0, 0, Design.subMenu.buttonRadius), fontSize: Design.subMenu.fontSize, fontColor: Design.subMenu.fontColor }); this._interactiveGroupingButtonElement.on("onHover", this.collapseAllMenus, this); this._interactiveGroupingButtonElement.on("button", this.onButtonInteractiveGrouping, this); this.groupingMenu.push({ element: this._interactiveGroupingButtonElement, order: 0, }); this._poiGroupingButtonElement = new MedsurfDraw.RoundButtonElement({ image: this.image, text: '\uf649', description: 'POI\n(Gruppe)', descriptionFontSize: Design.subMenu.descriptionFontSize, circle: new PIXI.Circle(0, 0, Design.subMenu.buttonRadius), fontSize: Design.subMenu.fontSize, fontColor: Design.subMenu.fontColor }); this._poiGroupingButtonElement.on("onHover", this.collapseAllMenus, this); this._poiGroupingButtonElement.on("button", this.onButtonPoiGrouping, this); this.groupingMenu.push({ element: this._poiGroupingButtonElement, order: 5, }); this._textGroupingButtonElement = new MedsurfDraw.RoundButtonElement({ image: this.image, text: '\uf53f', description: 'Farbgruppe', descriptionFontSize: Design.subMenu.descriptionFontSize, circle: new PIXI.Circle(0, 0, Design.subMenu.buttonRadius), fontSize: Design.subMenu.fontSize, fontColor: Design.subMenu.fontColor }); this._textGroupingButtonElement.on("onHover", this.collapseAllMenus, this); this._textGroupingButtonElement.on("button", this.onButtonTextGrouping, this); this.groupingMenu.push({ element: this._textGroupingButtonElement, order: 6, }); this._legendGroupingButtonElement = new MedsurfDraw.RoundButtonElement({ image: this.image, text: '\uf0cb', description: 'Legende\n(Gruppe)', descriptionFontSize: Design.subMenu.descriptionFontSize, circle: new PIXI.Circle(0, 0, Design.subMenu.buttonRadius), fontSize: Design.subMenu.fontSize, fontColor: Design.subMenu.fontColor }); this._legendGroupingButtonElement.on("onHover", this.collapseAllMenus, this); this._legendGroupingButtonElement.on("button", this.onButtonLegendGrouping, this); this.groupingMenu.push({ element: this._legendGroupingButtonElement, order: 7, }); this._groupingMenuElement.menuElements = this.groupingMenu; this._groupingMenuElement.hideItem(); this.sortChildren(); this._setElements(); }; SelectGroupElement.prototype.draw = function () { this._selectElement.draw(); this._imageObjectMenuElement.draw(); this._groupingMenuElement.draw(); }; SelectGroupElement.prototype.destroy = function (options) { if (this.contextInteraction) { this.contextInteraction.removeAllListeners(); } if (this.moveInteraction) { this.moveInteraction.removeAllListeners(); } if (this._selectElement) { this._selectElement.destroy(options); } if (this._imageObjectMenuElement) { this._imageObjectMenuElement.destroy(options); } if (this._groupingMenuElement) { this._groupingMenuElement.destroy(options); } if (this._editButtonElement) { this._editButtonElement.destroy(options); } if (this._moveToBackButtonElement) { this._moveToBackButtonElement.destroy(options); } if (this._moveToFrontButtonElement) { this._moveToFrontButtonElement.destroy(options); } if (this._deleteButtonElement) { this._deleteButtonElement.destroy(options); } if (this._degroupButtonElement) { this._degroupButtonElement.destroy(options); } if (this._duplicateButtonElement) { this._duplicateButtonElement.destroy(options); } if (this._clipboardButtonElement) { this._clipboardButtonElement.destroy(options); } _super.prototype.destroy.call(this, options); }; SelectGroupElement.prototype.setGrouping = function (model) { var imageObjects = this.image.getDisplayObjectsByGrouping(model); if (imageObjects) { this.image.getImageObjects() .filter(function (imageObject) { return imageObjects.indexOf(imageObject) === -1; }) .forEach(function (imageObject) { imageObject.modeInteraction.setMode('blocked_item'); }); imageObjects.forEach(function (imageObject) { imageObject.modeInteraction.setMode('select_grouping'); }); this._type = SelectGroupType.GROUPING; this._grouping = model; return true; } return false; }; SelectGroupElement.prototype.setLayerGroup = function (model) { var imageObjects = this.image.getLayerGroupDisplayObjectsByLayerGroup(model); if (imageObjects) { this.image.getImageObjects() .filter(function (imageObject) { return imageObjects.indexOf(imageObject) === -1; }) .forEach(function (imageObject) { imageObject.modeInteraction.setMode('blocked_item'); }); imageObjects.forEach(function (imageObject) { imageObject.modeInteraction.setMode('select_layer_group'); }); this._type = SelectGroupType.LAYERGROUP; this._layerGroup = model; return true; } return false; }; SelectGroupElement.prototype._setElements = function () { this.hideItem(); if (!this.parent) { return; } var displayObjects = this._getSelectedDisplayObjects(); var rectangle = this._getSelectedItemsRectangle(displayObjects); if (rectangle) { rectangle.pad(Design.selectElement.groupPad, Design.selectElement.groupPad); this._selectElement.rectangle = rectangle; this.showItem(); this.interactive = true; this.image.sortChildren(); this.displayObjects = displayObjects; } else { if (this.interactive) { if (this._type === SelectGroupType.GROUPING) { this.image.emit("debouncedUnselectGrouping"); } else { this.image.emit("debouncedUnselectLayerGroup"); } } this.interactive = false; this.displayObjects = []; } this.emit("debounceDraw"); }; SelectGroupElement.prototype._getSelectedDisplayObjects = function () { return this.image.getImageObjects() .filter(function (displayObject) { return displayObject.modeInteraction && (displayObject.modeInteraction.lastMode === 'select_layer_group' || displayObject.modeInteraction.lastMode === 'select_grouping'); }); }; SelectGroupElement.prototype._getSelectedItemsRectangle = function (displayObjects) { if (displayObjects.length > 0) { var topLeft_1; var topRight_1; var bottomLeft_1; displayObjects.forEach(function (displayObject) { var position = displayObject.position; var rect = displayObject.getRectangle(); if (!topLeft_1) { topLeft_1 = new PIXI.Point(rect.x, rect.y); } else { if (rect.x < topLeft_1.x) { topLeft_1.x = rect.x; } if (rect.y < topLeft_1.y) { topLeft_1.y = rect.y; } } if (!topRight_1) { topRight_1 = new PIXI.Point(rect.x + rect.width); } else { if (rect.x + rect.width > topRight_1.x) { topRight_1.x = rect.x + rect.width; } } if (!bottomLeft_1) { bottomLeft_1 = new PIXI.Point(undefined, rect.y + rect.height); } else { if (rect.y + rect.height > bottomLeft_1.y) { bottomLeft_1.y = rect.y + rect.height; } } }); return new PIXI.Rectangle(topLeft_1.x, topLeft_1.y, topRight_1.x - topLeft_1.x, bottomLeft_1.y - topLeft_1.y); } else { return undefined; } }; SelectGroupElement.prototype._setEventsForDisplayObjects = function (displayObjects) { var _this = this; displayObjects.forEach(function (displayObject) { if (displayObject.moveInteraction) { displayObject.moveInteraction.on("endMove", _this.controlSetDefaultMode, _this); _this._displayObjects.push(displayObject); } }); }; SelectGroupElement.prototype._unsetEventsForDisplayObjects = function (displayObjects) { var _this = this; displayObjects.forEach(function (displayObject) { if (displayObject.moveInteraction) { displayObject.moveInteraction.off("endMove", _this.controlSetDefaultMode, _this); } }); }; SelectGroupElement.prototype._modeDefault = function () { this.hideItem(); }; SelectGroupElement.prototype._removeModeDefault = function () { this.hideItem(); }; SelectGroupElement.prototype._modeAuthor = function () { this.hideItem(); this.image.parent.on("rightup", this.contextInteraction.endRight, this.contextInteraction); }; SelectGroupElement.prototype._removeModeAuthor = function () { this.hideItem(); this.image.off("rightup", this.contextInteraction.endRight, this.contextInteraction); }; SelectGroupElement.prototype.displayMenu = function () { var _this = this; if (!this.visible) { return; } var point = this.image.getMousePosition(); this._menuShown = true; if (MedsurfDraw.Keyboard.isKeyDown("KeyG")) { this._groupingMenuElement.setMousePosition(point); this._groupingMenuElement.showItem(); } else { this._imageObjectMenuElement.setMousePosition(point); this._imageObjectMenuElement.showItem(); } this.image.moveInteraction.once("startMove", function () { _this._imageObjectMenuElement.hideItem(); _this._groupingMenuElement.hideItem(); }); this.image.moveInteraction.once("endMove", function () { _this._menuShown = false; }); }; SelectGroupElement.prototype.collapseAllMenus = function (event) { this._moveToFrontButtonElement.toggleMenu(event, false); }; SelectGroupElement.prototype.onButtonEdit = function () { this.collapseAllMenus(new PIXI.InteractionEvent()); this.image.controlHideMenu(); this.image.editImageObjectGrouping(); }; SelectGroupElement.prototype.onButtonMoveToFront = function () { this.displayObjects.forEach(function (io) { io.onButtonMoveToFront(); }); }; SelectGroupElement.prototype.onButtonMoveToBack = function () { this.displayObjects.forEach(function (io) { io.onButtonMoveToBack(); }); }; SelectGroupElement.prototype.onButtonDelete = function (event) { this.collapseAllMenus(new PIXI.InteractionEvent()); this.image.controlHideMenu(); this.displayObjects.forEach(function (io) { io.modeInteraction.setMode("delete_multiple"); }); this.image.controlSetDefaultMode(new PIXI.InteractionEvent()); if (this._type === SelectGroupType.GROUPING) { this.image.unselectGrouping(); } else { this.image.unselectLayerGroup(); } }; SelectGroupElement.prototype.onButtonDegroup = function () { this.collapseAllMenus(new PIXI.InteractionEvent()); this.image.controlHideMenu(); if (this._type === SelectGroupType.GROUPING) { this.image.degroupGroupImageLayerGroups(); } else { this.displayObjects.forEach(function (io) { io.onButtonDegroup(false); }); this.image.unselectLayerGroup(); } }; SelectGroupElement.prototype.onButtonDuplicate = function () { this.collapseAllMenus(new PIXI.InteractionEvent()); this.image.controlHideMenu(); switch (this._type) { case SelectGroupType.LAYERGROUP: this.image.copyLayerGroup(this._layerGroup); break; default: throw new Error("Not implemented"); } }; SelectGroupElement.prototype.onButtonClipboard = function () { this.collapseAllMenus(new PIXI.InteractionEvent()); switch (this._type) { case SelectGroupType.LAYERGROUP: this.image.clipboardLayerGroup(this._layerGroup); break; default: throw new Error("Not implemented"); } }; SelectGroupElement.prototype.onButtonInteractiveGrouping = function () { this._groupingMenuElement.hideItem(); this.image.createInteractiveGrouping(this.layerGroup); }; SelectGroupElement.prototype.onButtonPoiGrouping = function () { this._groupingMenuElement.hideItem(); this.image.createPoiGrouping(this.layerGroup); }; SelectGroupElement.prototype.onButtonTextGrouping = function () { this._groupingMenuElement.hideItem(); this.image.createTextGrouping(this.layerGroup); }; SelectGroupElement.prototype.onButtonLegendGrouping = function () { this._imageObjectMenuElement.hideItem(); this._groupingMenuElement.hideItem(); this.image.createLegendGrouping(this.layerGroup); }; SelectGroupElement.prototype.controlHideMenu = function () { this._imageObjectMenuElement.hideItem(); this._groupingMenuElement.hideItem(); }; SelectGroupElement.prototype.controlSetDefaultMode = function () { this._setElements(); }; SelectGroupElement.prototype.endRight = function (event) { event.stopPropagation(); this.displayMenu(); }; SelectGroupElement.prototype.startMove = function (event) { this.displayObjects.forEach(function (displayObject) { if (displayObject instanceof MedsurfDraw.PositionPoint || displayObject instanceof MedsurfDraw.LegendCollection) { displayObject.moveInteraction.startMove(event); } }); }; SelectGroupElement.prototype.onMove = function (event, dX, dY) { this.position.x += dX; this.position.y += dY; this.displayObjects.forEach(function (displayObject) { if (displayObject instanceof MedsurfDraw.PositionPoint || displayObject instanceof MedsurfDraw.LegendCollection) { displayObject.moveInteraction.onMove(event); } }); }; SelectGroupElement.prototype.endMove = function (event) { this.position.x = 0; this.position.y = 0; this.displayObjects.forEach(function (displayObject) { if (displayObject instanceof MedsurfDraw.PositionPoint || displayObject instanceof MedsurfDraw.LegendCollection) { displayObject.moveInteraction.endMove(event); } }); }; SelectGroupElement.prototype.onRelease = function () { this.modeInteraction.setMode(this.modeInteraction.defaultMode); }; Object.defineProperty(SelectGroupElement.prototype, "grouping", { get: function () { return this._grouping; }, enumerable: false, configurable: true }); Object.defineProperty(SelectGroupElement.prototype, "layerGroup", { get: function () { return this._layerGroup; }, enumerable: false, configurable: true }); Object.defineProperty(SelectGroupElement.prototype, "displayObjects", { get: function () { return this._displayObjects; }, set: function (value) { this._unsetEventsForDisplayObjects(this.displayObjects || []); this._displayObjects = value; this._setEventsForDisplayObjects(this.displayObjects); }, enumerable: false, configurable: true }); Object.defineProperty(SelectGroupElement.prototype, "imageObjectMenu", { get: function () { return this._imageObjectMenu; }, set: function (value) { this._imageObjectMenu = value; }, enumerable: false, configurable: true }); Object.defineProperty(SelectGroupElement.prototype, "groupingMenu", { get: function () { return this._groupingMenu; }, set: function (value) { this._groupingMenu = value; }, enumerable: false, configurable: true }); Object.defineProperty(SelectGroupElement.prototype, "contextInteraction", { get: function () { return this._contextInteraction; }, set: function (value) { this._contextInteraction = value; }, enumerable: false, configurable: true }); Object.defineProperty(SelectGroupElement.prototype, "moveInteraction", { get: function () { return this._moveInteraction; }, set: function (value) { this._moveInteraction = value; }, enumerable: false, configurable: true }); Object.defineProperty(SelectGroupElement.prototype, "menuShown", { get: function () { return this._menuShown; }, enumerable: false, configurable: true }); return SelectGroupElement; }(BaseContainer)); export { SelectGroupElement }; //# sourceMappingURL=SelectGroupElement.js.map