@@ -167,6 +167,37 @@ function _getRotation (metadata) {
167167 return angle + correction
168168}
169169
170+ /** Determine size of browser window.
171+ *
172+ * @return {number[] } Width and height of the window
173+ */
174+ function _getWindowSize ( ) {
175+ let width = 0
176+ let height = 0
177+ if ( typeof window . innerWidth === 'number' ) {
178+ // Non-IE
179+ width = window . innerWidth
180+ height = window . innerHeight
181+ } else if (
182+ document . documentElement && (
183+ document . documentElement . clientWidth || document . documentElement . clientHeight
184+ )
185+ ) {
186+ // IE 6+ in 'standards compliant mode'
187+ width = document . documentElement . clientWidth
188+ height = document . documentElement . clientHeight
189+ } else if (
190+ document . body && (
191+ document . body . clientWidth || document . body . clientHeight
192+ )
193+ ) {
194+ // IE 4 compatible
195+ width = document . body . clientWidth
196+ height = document . body . clientHeight
197+ }
198+ return [ width , height ]
199+ }
200+
170201/** Map style options to OpenLayers style.
171202 *
172203 * @param {object } styleOptions - Style options
@@ -1425,19 +1456,22 @@ class VolumeImageViewer {
14251456 )
14261457 overviewmapElement . style . border = '1px solid black'
14271458 // Try to fit the overview map into the target control overlay container
1428- const resizeFactor = 300
1429- let width = Math . abs ( this [ _referenceExtents ] [ 1 ] ) / resizeFactor
1430- let height = Math . abs ( this [ _referenceExtents ] [ 2 ] ) / resizeFactor
1431- if ( width > 400 || height > 400 ) {
1432- width /= 2
1433- height /= 2
1434- }
1435- if ( width < 150 || height < 150 ) {
1436- width *= 1.5
1437- height *= 1.5
1438- }
1439- overviewmapElement . style . width = `${ width } px`
1440- overviewmapElement . style . height = `${ height } px`
1459+ const height = Math . abs ( this [ _referenceExtents ] [ 1 ] )
1460+ const width = Math . abs ( this [ _referenceExtents ] [ 2 ] )
1461+ const rotation = this [ _rotation ] / Math . PI * 180
1462+ const windowSize = _getWindowSize ( )
1463+ const targetHeight = Math . ceil ( windowSize [ 1 ] * 0.2 )
1464+ let resizeFactor
1465+ let targetWidth
1466+ if ( rotation === 180 || rotation === 0 ) {
1467+ resizeFactor = targetHeight / height
1468+ targetWidth = width * resizeFactor
1469+ } else {
1470+ resizeFactor = targetHeight / width
1471+ targetWidth = height * resizeFactor
1472+ }
1473+ overviewmapElement . style . width = `${ targetWidth } px`
1474+ overviewmapElement . style . height = `${ targetHeight } px`
14411475
14421476 const container = this [ _map ] . getTargetElement ( )
14431477
0 commit comments