Hey,
I’m trying to add a tooltip when hovering an annotation that has been programatically created after webviewer initialization.
this.model.links.forEach(async (link: any) => {
const newLink = new Annotations.Link({
Subject: `${ link.target_version_label }: ${ link.target_version_title }`
})
const importingAnnotation = await annotationManager.importAnnotations(link.xfdf)
// eslint-disable-next-line @typescript-eslint/naming-convention
const { PageNumber, X, Y, Height, Width } = importingAnnotation[0]
Object.assign(newLink, { PageNumber, X, Y, Height, Width })
newLink.StrokeColor = new Annotations.Color(0, 165, 228)
newLink.StrokeStyle = 'none'
newLink.backgroundColor = new Annotations.Color(0, 165, 228, 0.1)
newLink.StrokeThickness = 1
newLink.NoMove = true
// add padding to annotation box
newLink.setWidth(newLink.getWidth() + 4)
newLink.setHeight(newLink.getHeight() + 4)
const previousRect = newLink.getRect()
const generatedRect = new this.instance.Core.Math.Rect(
previousRect.x1 - 2,
previousRect.y1 - 2,
previousRect.x2 - 2,
previousRect.y2 - 2
)
newLink.setRect(generatedRect)
// generate and add a drawing sheet URL to annotation
const route = this.$router.resolve({
name: 'project-sheets-view',
params: {
id: this.$route.params.id,
pid: this.$route.params.pid,
version_id: link.target_version_id
}
})
const targetURI = new URL(route.href, window.location.origin).href
newLink.addAction('U', new Actions.URI({
uri: targetURI,
})
)
annotationManager.addAnnotation(newLink)
annotationManager.groupAnnotations(importingAnnotation[0], [newLink])
})
This is how I import and create annotations.
Then I add this on document load
addHoverInfo (): void {
this.instance.UI.setAnnotationContentOverlayHandler( (annotation: any) => {
const div = document.createElement('div')
div.appendChild(document.createTextNode(`${ annotation.Subject }`))
return div
})
}
But it only works for annotations that I created using pdftron tools (like a circle, square, text highlight etc.)
Is there a way to do this for my usage?
Or can I somehow add a class/data-element/id to annotation html element, then target that html element using javascript and add a tooltip there using CSS?