Skip to content

Commit 89d109d

Browse files
committed
Fix resolution of overview image
1 parent dae4f54 commit 89d109d

File tree

1 file changed

+57
-44
lines changed

1 file changed

+57
-44
lines changed

src/viewer.js

Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import WebGLHelper from 'ol/webgl/Helper'
3636
import TileDebug from 'ol/source/TileDebug'
3737
import { default as VectorEventType } from 'ol/source/VectorEventType'// eslint-disable-line
3838
import { ZoomSlider, Zoom } from 'ol/control'
39-
import { getCenter } from 'ol/extent'
39+
import { getCenter, getHeight, getWidth } from 'ol/extent'
4040
import { defaults as defaultInteractions } from 'ol/interaction'
4141
import dcmjs from 'dcmjs'
4242
import { quantileSeq } from 'mathjs'
@@ -1199,16 +1199,13 @@ class VolumeImageViewer {
11991199
}
12001200

12011201
if (Math.max(...this[_pyramid].gridSizes[0]) <= 10) {
1202-
const center = view.getCenter()
1202+
const center = getCenter(this[_projection].getExtent())
12031203
this[_overviewMap] = new OverviewMap({
12041204
view: new View({
12051205
projection: this[_projection],
12061206
rotation: this[_rotation],
12071207
constrainOnlyCenter: true,
1208-
resolutions: this[_tileGrid].getResolutions(),
1209-
minZoom: 0,
1210-
maxZoom: 0,
1211-
center: center,
1208+
resolutions: [this[_tileGrid].getResolution(0)],
12121209
extent: center.concat(center),
12131210
showFullExtent: true
12141211
}),
@@ -1218,51 +1215,66 @@ class VolumeImageViewer {
12181215
rotateWithView: true
12191216
})
12201217
this[_updateOverviewMapSize] = () => {
1221-
const overviewElement = this[_controls].overview.element
1222-
const overviewChildren = overviewElement.children
1223-
const overviewmapElement = Object.values(overviewChildren).find(
1224-
c => c.className === 'ol-overviewmap-map'
1225-
)
1226-
// Try to fit the overview map into the target control overlay container
1227-
const height = this[_pyramid].metadata[0].TotalPixelMatrixRows
1228-
const width = this[_pyramid].metadata[0].TotalPixelMatrixColumns
1229-
const rotation = this[_rotation] / Math.PI * 180
1218+
const degrees = this[_rotation] / Math.PI * 180
12301219
const isRotated = !(
1231-
Math.abs(rotation - 180) < 0.01 || Math.abs(rotation - 0) < 0.01
1220+
Math.abs(degrees - 180) < 0.01 || Math.abs(degrees - 0) < 0.01
12321221
)
12331222
const viewport = this[_map].getViewport()
12341223
const viewportHeight = viewport.clientHeight
12351224
const viewportWidth = viewport.clientWidth
1236-
const viewportHeightFraction = 0.3
1225+
const viewportHeightFraction = 0.45
12371226
const viewportWidthFraction = 0.25
1238-
const maxTargetHeight = viewportHeight * viewportHeightFraction
1239-
const maxTargetWidth = viewportWidth * viewportWidthFraction
1240-
let targetHeight
1241-
let targetWidth
1227+
const targetHeight = viewportHeight * viewportHeightFraction
1228+
const targetWidth = viewportWidth * viewportWidthFraction
1229+
1230+
const extent = this[_projection].getExtent()
1231+
let height
1232+
let width
1233+
let resolution
12421234
if (isRotated) {
1243-
targetHeight = width
1244-
targetWidth = height
1235+
if (targetWidth > targetHeight) {
1236+
height = targetHeight
1237+
width = (height * getHeight(extent)) / getWidth(extent)
1238+
resolution = getWidth(extent) / height
1239+
} else {
1240+
width = targetWidth
1241+
height = (width * getWidth(extent)) / getHeight(extent)
1242+
resolution = getHeight(extent) / width
1243+
}
12451244
} else {
1246-
targetHeight = height
1247-
targetWidth = width
1245+
if (targetHeight > targetWidth) {
1246+
width = targetWidth
1247+
height = (width * getHeight(extent)) / getWidth(extent)
1248+
resolution = getWidth(extent) / width
1249+
} else {
1250+
height = targetHeight
1251+
width = (height * getWidth(extent)) / getHeight(extent)
1252+
resolution = getHeight(extent) / height
1253+
}
12481254
}
1249-
let resizeFactor = 1
1250-
resizeFactor = (
1251-
maxTargetWidth / targetWidth +
1252-
maxTargetHeight / targetHeight
1253-
) / 2
1254-
targetHeight *= resizeFactor
1255-
targetWidth *= resizeFactor
1256-
overviewmapElement.style.width = `${targetWidth}px`
1257-
overviewmapElement.style.height = `${targetHeight}px`
1255+
const center = getCenter(extent)
1256+
const overviewView = new View({
1257+
projection: this[_projection],
1258+
rotation: this[_rotation],
1259+
constrainOnlyCenter: true,
1260+
minResolution: resolution,
1261+
maxResolution: resolution,
1262+
extent: center.concat(center),
1263+
showFullExtent: true
1264+
})
12581265
const map = this[_overviewMap].getOverviewMap()
1259-
map.updateSize()
1260-
const view = map.getView()
1261-
const center = view.getCenter()
1262-
view.fit(
1263-
center.concat(center),
1264-
{ size: map.getSize() }
1266+
1267+
const overviewElement = this[_overviewMap].element
1268+
const overviewChildren = overviewElement.children
1269+
const overviewmapElement = Object.values(overviewChildren).find(
1270+
c => c.className === 'ol-overviewmap-map'
12651271
)
1272+
overviewmapElement.style.width = `${width}px`
1273+
overviewmapElement.style.height = `${height}px`
1274+
map.updateSize()
1275+
map.setView(overviewView)
1276+
this[_map].removeControl(this[_overviewMap])
1277+
this[_map].addControl(this[_overviewMap])
12661278
}
12671279
} else {
12681280
this[_overviewMap] = null
@@ -1767,9 +1779,9 @@ class VolumeImageViewer {
17671779
}
17681780

17691781
/**
1770-
* Get the size of the viewport.
1782+
* Size of the viewport.
17711783
*
1772-
* @return {number[]}
1784+
* @type {number[]}
17731785
*/
17741786
get size () {
17751787
return this[_map].getSize()
@@ -1842,6 +1854,7 @@ class VolumeImageViewer {
18421854
const view = this[_map].getView()
18431855
const projection = view.getProjection()
18441856
view.fit(projection.getExtent(), { size: this[_map].getSize() })
1857+
this[_updateOverviewMapSize]()
18451858

18461859
this[_drawingSource].on(VectorEventType.ADDFEATURE, (e) => {
18471860
publish(
@@ -4430,7 +4443,7 @@ class _NonVolumeImageViewer {
44304443
/**
44314444
* DICOM metadata for the displayed VL Whole Slide Microscopy Image instances.
44324445
*
4433-
* @return {VLWholeSlideMicroscopyImage}
4446+
* @type {VLWholeSlideMicroscopyImage}
44344447
*/
44354448
get imageMetadata () {
44364449
return this[_metadata]
@@ -4449,7 +4462,7 @@ class _NonVolumeImageViewer {
44494462
}
44504463

44514464
/**
4452-
* Get the size of the viewport.
4465+
* Size of the viewport.
44534466
*
44544467
* @type number[]
44554468
*/

0 commit comments

Comments
 (0)