Apply zoom scale when calculating annotation positions

Fixes #4978
pull/4981/head
Nick O'Leary 2024-12-05 15:34:24 +00:00
parent 84a2fbed2e
commit 43a9a3c3b1
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
1 changed files with 7 additions and 5 deletions

View File

@ -11,7 +11,7 @@ RED.view.annotations = (function() {
}
let badgeRDX = 0;
let badgeLDX = 0;
const scale = RED.view.scale()
for (let i=0,l=evt.el.__annotations__.length;i<l;i++) {
const annotation = evt.el.__annotations__[i];
if (annotations.hasOwnProperty(annotation.id)) {
@ -42,15 +42,17 @@ RED.view.annotations = (function() {
}
if (isBadge) {
if (showAnnotation) {
const rect = annotation.element.getBoundingClientRect();
// getBoundingClientRect is in real-world scale so needs to be adjusted according to
// the current scale factor
const rectWidth = annotation.element.getBoundingClientRect().width / scale;
let annotationX
if (!opts.align || opts.align === 'right') {
annotationX = evt.node.w - 3 - badgeRDX - rect.width
badgeRDX += rect.width + 4;
annotationX = evt.node.w - 3 - badgeRDX - rectWidth
badgeRDX += rectWidth + 4;
} else if (opts.align === 'left') {
annotationX = 3 + badgeLDX
badgeLDX += rect.width + 4;
badgeLDX += rectWidth + 4;
}
annotation.element.setAttribute("transform", "translate("+annotationX+", -8)");
}