Open dcox1776 opened 1 year ago
I was able to deal with this issue by writing the following function:
function saveViewport() {
const el = document.getElementById('image-element');
viewport.current = cornerstone.getViewport(el);
translation.current = {
x: viewport.current.translation.x,
y: viewport.current.translation.y
}
}
In response to an event such as a button click or slider change, I call this function to preserve the viewport in a reference variable. When the view is redrawn my useEffect function is called and I restore the viewport.
Notice that I copy the translation object explicitly. This is because assignment of objects in JavaScript is by reference and not value. The value attributes of the viewport are preserved when I assign the viewport to my reference variable but not the object attributes. If I don't do this, then the translation values are reset to 0.
Prerequisites
Description
Steps to Reproduce the issue
Expected behavior: I expect the image to retain its size as a result of zooming.
Actual behavior: (What actually happened)
CodeSandbox With Reproduction of Issue: I'll have to work on this. Need to setup a React app to reproduce the issue.