Skip to content

Commit

Permalink
Merge pull request #3922 from fstoe/bug_openseadragon_preserveViewport
Browse files Browse the repository at this point in the history
Bug fix: preservation of viewport doesnt work
  • Loading branch information
marlo-longley authored Oct 11, 2024
2 parents 018142a + f6b9ba7 commit 16aa69c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions __tests__/src/actions/canvas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const mockStore = configureMockStore(middlewares);

jest.mock('../../../src/state/selectors', () => ({
getCanvasGrouping: (state, { canvasId }) => [{ id: canvasId }],
getConfig: jest.fn((state) => {
const osdConfig = { osdConfig: { preserveViewport: true } };
return osdConfig;
}),
getNextCanvasGrouping: () => [{ id: 'canvasIndex-2' }],
getPreviousCanvasGrouping: () => [{ id: 'canvasIndex-0' }],
}));
Expand All @@ -24,6 +28,7 @@ describe('canvas actions', () => {
const id = 'abc123';
const expectedAction = {
canvasId: 'a',
preserveViewport: true,
type: ActionTypes.SET_CANVAS,
visibleCanvases: ['a'],
windowId: id,
Expand All @@ -42,6 +47,7 @@ describe('canvas actions', () => {
const id = 'abc123';
const expectedAction = {
canvasId: 'canvasIndex-0',
preserveViewport: true,
type: ActionTypes.SET_CANVAS,
visibleCanvases: ['canvasIndex-0'],
windowId: id,
Expand All @@ -60,6 +66,7 @@ describe('canvas actions', () => {
const id = 'abc123';
const expectedAction = {
canvasId: 'canvasIndex-2',
preserveViewport: true,
type: ActionTypes.SET_CANVAS,
visibleCanvases: ['canvasIndex-2'],
windowId: id,
Expand Down
8 changes: 7 additions & 1 deletion src/components/OpenSeadragonViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ export class OpenSeadragonViewer extends Component {
) {
viewer.close();
const canvasesChanged = !(isEqual(canvasWorld.canvasIds, prevProps.canvasWorld.canvasIds));
this.addAllImageSources((canvasesChanged || !viewerConfig));
if (canvasesChanged && viewer.preserveViewport) {
// Do not reset the zoom after add
this.addAllImageSources(false);
} else {
// Reset the zoom if the canvas has changed or if there is no viewerConfig
this.addAllImageSources((canvasesChanged || !viewerConfig));
}
} else if (!isEqual(canvasWorld.layers, prevProps.canvasWorld.layers)) {
this.refreshTileProperties();
} else if (viewerConfig && !this.osdUpdating) {
Expand Down
3 changes: 3 additions & 0 deletions src/state/actions/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
getNextCanvasGrouping,
getPreviousCanvasGrouping,
getCanvasGrouping,
getConfig,
} from '../selectors';

/**
Expand All @@ -15,6 +16,7 @@ import {
export function setCanvas(windowId, canvasId, newGroup = undefined, options = {}) {
return ((dispatch, getState) => {
const state = getState();
const { preserveViewport } = getConfig(state).osdConfig;
let visibleCanvases = newGroup;

if (!visibleCanvases) {
Expand All @@ -25,6 +27,7 @@ export function setCanvas(windowId, canvasId, newGroup = undefined, options = {}
dispatch({
...options,
canvasId,
preserveViewport,
type: ActionTypes.SET_CANVAS,
visibleCanvases,
windowId,
Expand Down

0 comments on commit 16aa69c

Please sign in to comment.