Skip to content

Commit b28ff07

Browse files
committed
Updated posioning code to fix fullscreen mode and fix jiggly zooming
1 parent c81fba2 commit b28ff07

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

openseadragon-fabricjs-overlay.js

+11-16
Original file line numberDiff line numberDiff line change
@@ -92,31 +92,26 @@
9292
this._canvasdiv.setAttribute('height', this._containerHeight);
9393
this._canvas.setAttribute('height', this._containerHeight);
9494
}
95-
this._viewportOrigin = new OpenSeadragon.Point(0, 0);
96-
var boundsRect = this._viewer.viewport.getBounds(true);
97-
this._viewportOrigin.x = boundsRect.x;
98-
this._viewportOrigin.y = boundsRect.y * this.imgAspectRatio;
9995

100-
this._viewportWidth = boundsRect.width;
101-
this._viewportHeight = boundsRect.height * this.imgAspectRatio;
102-
this.imgWidth = this._viewer.viewport.contentSize.x;
103-
this.imgHeight = this._viewer.viewport.contentSize.y;
104-
this.imgAspectRatio = this.imgWidth / this.imgHeight;
105-
10696
},
10797
resizecanvas: function() {
108-
109-
98+
99+
var origin = new OpenSeadragon.Point(0, 0);
110100
var viewportZoom = this._viewer.viewport.getZoom(true);
111101
var image1 = this._viewer.world.getItemAt(0);
112102
var zoom = image1.viewportToImageZoom(viewportZoom);
113103

114-
var x=((this._viewportOrigin.x/this.imgWidth-this._viewportOrigin.x )/this._viewportWidth)*this._containerWidth;
115-
var y=((this._viewportOrigin.y/this.imgHeight-this._viewportOrigin.y )/this._viewportHeight)*this._containerHeight;
116104
this._fabricCanvas.setWidth(this._containerWidth);
117-
this._fabricCanvas.setHeight(this._containerHeight);
118-
this._fabricCanvas.absolutePan(new fabric.Point(-x,-y));
105+
this._fabricCanvas.setHeight(this._containerHeight);
119106
this._fabricCanvas.setZoom(zoom);
107+
108+
var image1WindowPoint = image1.imageToWindowCoordinates(origin);
109+
var x=Math.round(image1WindowPoint.x);
110+
var y=Math.round(image1WindowPoint.y);
111+
var canvasOffset=this._canvasdiv.getBoundingClientRect();
112+
113+
this._fabricCanvas.absolutePan(new fabric.Point(canvasOffset.left-x,canvasOffset.top-y));
114+
120115
}
121116

122117
};

0 commit comments

Comments
 (0)