Skip to content

Commit b211ab0

Browse files
committed
updated positioning code
1 parent 471a61c commit b211ab0

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

demo.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
tileSources: [{
4848
tileSource: tileSource,
4949
width: 2,
50-
y: 0.5,
51-
x: 0.5
50+
y: 0,
51+
x: 0
5252
}]
5353
});
5454

openseadragon-fabricjs-overlay.js

+17-6
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,29 @@
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;
99+
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;
95105

96106
},
97107
resizecanvas: function() {
108+
98109
var viewportZoom = this._viewer.viewport.getZoom(true);
99110
var image1 = this._viewer.world.getItemAt(0);
100-
var zoom = image1.viewportToImageZoom(viewportZoom);
101-
var origin = new OpenSeadragon.Point(0, 0);
102-
var image1WindowPoint = image1.imageToWindowCoordinates(origin);
103-
var x=Math.round(image1WindowPoint.x);
104-
var y=Math.round(image1WindowPoint.y);
105-
this._fabricCanvas.setZoom(zoom);
111+
var zoom = image1.viewportToImageZoom(viewportZoom);
112+
113+
var x=((this._viewportOrigin.x/this.imgWidth-this._viewportOrigin.x )/this._viewportWidth)*this._containerWidth;
114+
var y=((this._viewportOrigin.y/this.imgHeight-this._viewportOrigin.y )/this._viewportHeight)*this._containerHeight;
115+
106116
this._fabricCanvas.absolutePan(new fabric.Point(-x,-y));
117+
this._fabricCanvas.setZoom(zoom);
107118
}
108119

109120
};

0 commit comments

Comments
 (0)