Hello there,
I am using version 7.2.1
Is there any way to get the previous annotation(the unchanged annotation of which I have changed) in annotationChanged event
Thanks
Hello there,
I am using version 7.2.1
Is there any way to get the previous annotation(the unchanged annotation of which I have changed) in annotationChanged event
Thanks
Hello, I’m Ron, an automated tech support bot
While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:
Hey there,
There is no way to get this information from the annotation changed event.
What you could do is maintain a separate cache of annotations in your application, and grab that version of the annot in the annotationChanged event. Keep in mind that annotations are class references, so you will have to clone them in order to maintain the old state.
Something like this should get you started:
const annotCache = new Map();
const cacheAnnot = (annot) => {
const id = annot.Id;
const copy = instance.annotManager.getAnnotationCopy(annot);
annotCache.set(id, copy);
}
const getCachedAnnot = (id) => {
return annotCache.get(id);
}
// Clear the cache when a new doc is loaded
instance.docViewer.on('documentLoaded', () => {
annotCache.clear();
})
// create the cache when the annotations are loaded
instance.docViewer.on('annotationsLoaded', () => {
const annots = instance.annotManager.getAnnotationsList();
annots.forEach(annot => {
cacheAnnot(annot)
})
})
instance.annotManager.on('annotationChanged', (annots) => {
for (const annot of annots) {
const id = annot.Id;
const cachedAnnot = getCachedAnnot(id);
console.log('Old annotation', cachedAnnot);
console.log('New annotation', annot);
cacheAnnot(annot);
}
})
Thanks!
Logan