-
Notifications
You must be signed in to change notification settings - Fork 2
/
react-openseadragon-viewer.js
123 lines (108 loc) · 3.21 KB
/
react-openseadragon-viewer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import React from 'react';
import PropTypes from 'prop-types';
import OpenSeadragon from 'openseadragon';
import OpenSeadragonControls from './react-openseadragon-controls';
var OPENSEADRAGONVIEWER = undefined;
export default class OpenSeadragonViewer extends React.Component {
static defaultConfig() {
return {
sequenceMode: true,
showReferenceStrip: false,
showNavigator: true,
id: 'osd-viewer',
visibilityRatio: 1.0,
constrainDuringPan: false,
defaultZoomLevel: 1,
minZoomLevel: 1,
maxZoomLevel: 10,
zoomInButton: 'zoom-in',
zoomOutButton: 'zoom-out',
homeButton: 'reset',
fullPageButton: 'full-page',
previousButton: 'sidebar-previous',
nextButton: 'sidebar-next',
};
}
constructor(props) {
super(props);
this._config = this._config.bind(this);
this._id = this._id.bind(this);
this._currentPageIndex = this._currentPageIndex.bind(this);
this._osdViewer = this._osdViewer.bind(this);
this.setStrings = this.setStrings.bind(this);
this.setStringsItems = this.setStringsItems.bind(this);
this.state = {
pages: props.pages,
showSearchText: props.showSearchText,
osdDisplay: {},
textDisplay: { display: 'none' },
};
}
componentDidMount() {
this.setStrings();
if (typeof window.OpenSeadragon !== 'undefined') {
OPENSEADRAGONVIEWER = window.OpenSeadragon(this._config());
} else {
OPENSEADRAGONVIEWER = OpenSeadragon(this._config());
}
// Start at the image specified in the URL
OPENSEADRAGONVIEWER.goToPage(this.props.currentPageId);
}
setStringsItems() {
return (typeof this.props.osdConfig.setStrings !== 'undefined') ? this.props.osdConfig.setStrings : [];
}
// Allow users to overright UI strings in OpenSeadragon
// See: http://openseadragon.github.io/examples/ui-customize-tooltips/
setStrings() {
this.setStringsItems().map(
item => OpenSeadragon.setString(item.name, `${item.value}`));
}
_currentPageIndex() {
let urlParts = window.location.href.split('/');
return parseInt(urlParts.map(
(part, i) => {
if (part === 'image') {
return urlParts[i + 1];
}
return '';
}).join('').trim(), [0], 10);
};
_currentPage() {
return this.state.pages[this._currentPageIndex()];
}
_config() {
return Object.assign(OpenSeadragonViewer.defaultConfig(), this.props.osdConfig);
}
_id(){
return parseInt(this.props.match.params.id, 10);
}
_osdViewer() {
return (
<div className="openseadragon" id="osd-viewer">
<OpenSeadragonControls />
</div>
);
}
render() {
if (typeof OPENSEADRAGONVIEWER !== 'undefined') {
OPENSEADRAGONVIEWER.goToPage(this.props.currentPageId);
}
return (<div>{this._osdViewer()}</div>);
}
}
OpenSeadragonViewer.defaultProps = {
viewSearchText: '',
osdConfig: {
defaultZoomLevel: 0,
tileSources: [],
setStrings: [],
},
};
OpenSeadragonViewer.propTypes = {
osdConfig: PropTypes.shape({
defaultZoomLevel: PropTypes.number,
tileSources: PropTypes.arrayOf(PropTypes.string),
setStrings: PropTypes.arrayOf(PropTypes.object),
}),
viewSearchText: PropTypes.string,
};