Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix: preservation of viewport doesnt work #3922

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
marlo-longley marked this conversation as resolved.
Show resolved Hide resolved
}
} 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
Loading