@@ -10,6 +10,7 @@ import Icon from 'ol/style/Icon'
1010import ImageLayer from 'ol/layer/Image'
1111import Map from 'ol/Map'
1212import Modify from 'ol/interaction/Modify'
13+ import MousePosition from 'ol/control/MousePosition'
1314import OverviewMap from 'ol/control/OverviewMap'
1415import Projection from 'ol/proj/Projection'
1516import ScaleLine from 'ol/control/ScaleLine'
@@ -75,6 +76,7 @@ import {
7576 _scoord3d2Geometry ,
7677 getPixelSpacing ,
7778 _geometry2Scoord3d ,
79+ _geometryCoordinates2scoord3dCoordinates ,
7880 _getFeatureLength ,
7981 _getFeatureArea
8082} from './scoord3dUtils'
@@ -1297,8 +1299,31 @@ class VolumeImageViewer {
12971299 this [ _controls ] . overview = this [ _overviewMap ]
12981300 }
12991301 }
1300- for ( const control in this [ _controls ] ) {
1301- this [ _map ] . addControl ( this [ _controls ] [ control ] )
1302+ if ( this [ _options ] . controls . has ( 'position' ) ) {
1303+ this [ _controls ] . position = new MousePosition ( {
1304+ projection : this [ _projection ] ,
1305+ coordinateFormat : ( imageCoordinates ) => {
1306+ const slideCoordinates = _geometryCoordinates2scoord3dCoordinates (
1307+ imageCoordinates ,
1308+ this [ _pyramid ] . metadata
1309+ )
1310+ /*
1311+ * This assumes that the image is aligned with the X and Y axes
1312+ * of the slide (frame of reference).
1313+ * If one would ever change the orientation (rotation), this may
1314+ * need to be changed accordingly. The values would not become wrong,
1315+ * but the X and Y axes of the slide would no longer align with the
1316+ * vertical and horizontal axes of the viewport, respectively.
1317+ */
1318+ const x = slideCoordinates [ 0 ] . toFixed ( 5 )
1319+ const y = slideCoordinates [ 1 ] . toFixed ( 5 )
1320+ return `(${ x } , ${ y } )`
1321+ }
1322+ } )
1323+ }
1324+ for ( const name in this [ _controls ] ) {
1325+ console . info ( `add control "${ name } "` )
1326+ this [ _map ] . addControl ( this [ _controls ] [ name ] )
13021327 }
13031328
13041329 this [ _annotationManager ] = new _AnnotationManager ( {
@@ -1878,7 +1903,7 @@ class VolumeImageViewer {
18781903 } )
18791904 } )
18801905
1881- // Style scale element (overriding default Openlayers CSS "ol-scale-line")
1906+ // Style scale element (overriding Openlayers CSS "ol-scale-line")
18821907 const scaleElement = this [ _controls ] . scale . element
18831908 scaleElement . style . position = 'absolute'
18841909 scaleElement . style . right = '.5em'
@@ -1901,6 +1926,24 @@ class VolumeImageViewer {
19011926 scaleInnerElement . style . borderBottomColor = 'black'
19021927 scaleInnerElement . style . margin = '1px'
19031928 scaleInnerElement . style . willChange = 'contents,width'
1929+
1930+ // Style position element (overriding Openlayers CSS "ol-mouse-position")
1931+ if ( this [ _controls ] . position != null ) {
1932+ const positionElement = this [ _controls ] . position . element
1933+ positionElement . style . position = 'absolute'
1934+ positionElement . style . right = '.5em'
1935+ positionElement . style . top = '.5em'
1936+ positionElement . style . left = 'auto'
1937+ positionElement . style . bottom = 'auto'
1938+ positionElement . style . padding = '2px'
1939+ positionElement . style . backgroundColor = 'rgba(255,255,255,.5)'
1940+ positionElement . style . borderRadius = '4px'
1941+ positionElement . style . margin = '1px'
1942+ positionElement . style . color = 'black'
1943+ positionElement . style . fontWeight = '600'
1944+ positionElement . style . fontSize = '10px'
1945+ positionElement . style . textAlign = 'center'
1946+ }
19041947 }
19051948
19061949 /**
0 commit comments