fix: canvas fits image exactly, chained annotation loading, arrow move tracking
- Canvas now sizes to match the scaled image dimensions (zero empty space) instead of using a fixed aspect ratio, fixing coordinate mismatch between editor and viewer - Annotations load only after background image is ready via _pendingAnnotations pattern, preventing placement at wrong coordinates - Arrow endpoints (arrowX1/Y1/X2/Y2) update on object:modified using transform delta, so moved arrows serialize at correct position - Coordinate scaling on load: coordScale = currentImageScale / savedImageScale handles annotations saved at different screen widths Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -172,7 +172,13 @@ function annotationViewer() {
|
||||
|
||||
// Editor format (objects array from annotation-editor.js)
|
||||
if (this.annotations.objects) {
|
||||
var annoScale = this.canvas.width / (this.annotations.width || this.canvas.width);
|
||||
var previewScale = this.scale;
|
||||
var imgScale = this.annotations.imageScale;
|
||||
// v2+: use imageScale for correct canvas→image→preview mapping
|
||||
// v1 fallback: annoScale = previewWidth / editorWidth
|
||||
var annoScale = imgScale
|
||||
? (previewScale / imgScale)
|
||||
: (this.canvas.width / (this.annotations.width || this.canvas.width));
|
||||
_drawEditorAnnotations(this.ctx, this.annotations, annoScale);
|
||||
return;
|
||||
}
|
||||
@@ -397,7 +403,12 @@ function _drawPreview(canvas, ctx, source, srcW, srcH, annotations, maxHeight) {
|
||||
ctx.drawImage(source, 0, 0, canvas.width, canvas.height);
|
||||
|
||||
if (annotations && annotations.objects) {
|
||||
var annoScale = canvas.width / (annotations.width || srcW);
|
||||
var imgScale = annotations.imageScale;
|
||||
// v2+: use imageScale for correct canvas→image→preview mapping
|
||||
// v1 fallback: annoScale = previewWidth / editorWidth
|
||||
var annoScale = imgScale
|
||||
? (scale / imgScale)
|
||||
: (canvas.width / (annotations.width || srcW));
|
||||
_drawEditorAnnotations(ctx, annotations, annoScale);
|
||||
} else if (annotations && annotations.markers) {
|
||||
_drawLegacyAnnotations(ctx, annotations, scale);
|
||||
|
||||
Reference in New Issue
Block a user