diff --git a/src/app/drawController.js b/src/app/drawController.js index 38735f6b92..cc74e20b22 100644 --- a/src/app/drawController.js +++ b/src/app/drawController.js @@ -1,5 +1,8 @@ import {AnnotationGroup} from '../image/annotation'; -import {RemoveAnnotationCommand} from '../tools/drawCommands'; +import { + RemoveAnnotationCommand, + UpdateAnnotationCommand +} from '../tools/drawCommands'; import {logger} from '../utils/logger'; // doc imports @@ -87,6 +90,32 @@ export class DrawController { command.execute(); } + /** + * Update an annotation via an update command (triggers draw actions). + * + * @param {string} id The annotation id. + * @param {object} originalProps The original annotation properties + * that will be updated. + * @param {object} newProps The new annotation properties + * that will replace the original ones. + * @param {Function} exeCallback The undo stack callback. + */ + updateAnnotationWithCommand(id, originalProps, newProps, exeCallback) { + const annotation = this.getAnnotation(id); + if (typeof annotation === 'undefined') { + logger.warn( + 'Cannot create update command for undefined annotation: ' + id); + return; + } + // create remove annotation command + const command = new UpdateAnnotationCommand( + annotation, originalProps, newProps, this); + // add command to undo stack + exeCallback(command); + // execute command: triggers draw remove + command.execute(); + } + /** * Remove all annotations via remove commands (triggers draw actions). *