Skip to content

Commit

Permalink
Add updateAnnotationWithCommand method
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Jul 24, 2024
1 parent fd1f14a commit 364a14b
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/app/drawController.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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).
*
Expand Down

0 comments on commit 364a14b

Please sign in to comment.