@@ -3,6 +3,7 @@ import Collection from 'ol/Collection';
33import Draw , { createRegularPolygon , createBox } from 'ol/interaction/Draw' ;
44import EVENT from "./events" ;
55import Feature from 'ol/Feature' ;
6+ import Fill from 'ol/style/Fill' ;
67import FullScreen from 'ol/control/FullScreen' ;
78import ImageLayer from 'ol/layer/Image' ;
89import Map from 'ol/Map' ;
@@ -13,6 +14,8 @@ import Projection from 'ol/proj/Projection';
1314import publish from "./eventPublisher" ;
1415import ScaleLine from 'ol/control/ScaleLine' ;
1516import Select from 'ol/interaction/Select' ;
17+ import Style from 'ol/style/Style' ;
18+ import Stroke from 'ol/style/Stroke' ;
1619import Static from 'ol/source/ImageStatic' ;
1720import Overlay from 'ol/Overlay' ;
1821import TileLayer from 'ol/layer/Tile' ;
@@ -215,10 +218,6 @@ function _geometry2Scoord3d(geometry, pyramid) {
215218 coordinates = coordinates . map ( c => {
216219 return _geometryCoordinates2scoord3dCoordinates ( c , pyramid ) ;
217220 } )
218-
219- // const metadata = pyramid[pyramid.length-1];
220- // const pixelSpacing = _getPixelSpacing(metadata);
221-
222221 return new Ellipse ( {
223222 coordinates,
224223 frameOfReferenceUID : frameOfReferenceUID
@@ -357,7 +356,11 @@ function _coordinateFormatScoord3d2Geometry(coordinates, pyramid) {
357356 Number ( origin . YOffsetInSlideCoordinateSystem ) ,
358357 ] ;
359358
359+ let outOfFrame = false
360360 coordinates = coordinates . map ( c => {
361+ if ( c [ 0 ] > 25 || c [ 1 ] > 76 ) {
362+ outOfFrame = true
363+ }
361364 const slideCoord = [ c [ 0 ] , c [ 1 ] ] ;
362365 const pixelCoord = mapSlideCoordToPixelCoord ( {
363366 offset,
@@ -370,6 +373,11 @@ function _coordinateFormatScoord3d2Geometry(coordinates, pyramid) {
370373 if ( transform ) {
371374 return coordinates [ 0 ] ;
372375 }
376+ if ( outOfFrame ) {
377+ console . warning (
378+ 'found coordinates outside slide coordinate system 25 x 76 mm'
379+ )
380+ }
373381 return coordinates ;
374382}
375383
@@ -382,18 +390,48 @@ function _coordinateFormatScoord3d2Geometry(coordinates, pyramid) {
382390 * @private
383391 */
384392function _getROIFromFeature ( feature , pyramid ) {
385- let roi = { }
386- if ( feature !== undefined ) {
393+ if ( feature !== undefined && feature !== null ) {
387394 const geometry = feature . getGeometry ( ) ;
388395 const scoord3d = _geometry2Scoord3d ( geometry , pyramid ) ;
389396 const properties = feature . getProperties ( ) ;
390397 // Remove geometry from properties mapping
391398 const geometryName = feature . getGeometryName ( ) ;
392399 delete properties [ geometryName ] ;
393400 const uid = feature . getId ( ) ;
394- roi = new ROI ( { scoord3d, properties, uid } ) ;
401+ return new ROI ( { scoord3d, properties, uid } ) ;
402+ }
403+ return
404+ }
405+
406+ /** Updates the style of a feature.
407+ *
408+ * @param {object } styleOptions - Style options
409+ * @param {object } styleOptions.stroke - Style options for the outline of the geometry
410+ * @param {number[] } styleOptions.stroke.color - RGBA color of the outline
411+ * @param {number } styleOptions.stroke.width - Width of the outline
412+ * @param {object } styleOptions.fill - Style options for body the geometry
413+ * @param {number[] } styleOptions.fill.color - RGBA color of the body
414+ */
415+ function _setFeatureStyle ( feature , styleOptions ) {
416+ if ( styleOptions !== undefined ) {
417+ const style = new Style ( ) ;
418+ if ( 'stroke' in styleOptions ) {
419+ const strokeOptions = {
420+ color : styleOptions . stroke . color ,
421+ width : styleOptions . stroke . width ,
422+ }
423+ const stroke = new Stroke ( strokeOptions ) ;
424+ style . setStroke ( stroke ) ;
425+ }
426+ if ( 'fill' in styleOptions ) {
427+ const fillOptions = {
428+ color : styleOptions . fill . color
429+ }
430+ const fill = new Fill ( fillOptions ) ;
431+ style . setFill ( fill ) ;
432+ }
433+ feature . setStyle ( style ) ;
395434 }
396- return roi ;
397435}
398436
399437const _client = Symbol ( 'client' ) ;
@@ -814,7 +852,8 @@ class VolumeImageViewer {
814852 this [ _controls ] . overview = new OverviewMap ( {
815853 view : overviewView ,
816854 layers : [ overviewImageLayer ] ,
817- collapsed : true ,
855+ collapsed : false ,
856+ collapsible : false ,
818857 } ) ;
819858 }
820859
@@ -923,6 +962,8 @@ class VolumeImageViewer {
923962 /** Activates the draw interaction for graphic annotation of regions of interest.
924963 * @param {object } options - Drawing options.
925964 * @param {string } options.geometryType - Name of the geometry type (point, circle, box, polygon, freehandPolygon, line, freehandLine)
965+ * @param {object } options.strokeStyle - Style of the geometry stroke (keys: "color", "width")
966+ * @param {object } options.fillStyle - Style of the geometry body (keys: "color")
926967 */
927968 activateDrawInteraction ( options ) {
928969 this . deactivateDrawInteraction ( ) ;
@@ -972,9 +1013,6 @@ class VolumeImageViewer {
9721013
9731014 const defaultDrawOptions = { source : this [ _drawingSource ] } ;
9741015 const customDrawOptions = customOptionsMapping [ options . geometryType ] ;
975- if ( 'style' in options ) {
976- customDrawOptions . style = options . style ;
977- }
9781016 const allDrawOptions = Object . assign ( defaultDrawOptions , customDrawOptions ) ;
9791017 this [ _interactions ] . draw = new Draw ( allDrawOptions ) ;
9801018
@@ -1162,17 +1200,45 @@ class VolumeImageViewer {
11621200
11631201 /** Adds a regions of interest.
11641202 *
1165- * @param {ROI } Regions of interest.
1203+ * @param {ROI } item - Regions of interest.
1204+ * @param {object } styleOptions - Style options
1205+ * @param {object } styleOptions.stroke - Style options for the outline of the geometry
1206+ * @param {number[] } styleOptions.stroke.color - RGBA color of the outline
1207+ * @param {number } styleOptions.stroke.width - Width of the outline
1208+ * @param {object } styleOptions.fill - Style options for body the geometry
1209+ * @param {number[] } styleOptions.fill.color - RGBA color of the body
1210+ *
11661211 */
1167- addROI ( item ) {
1212+ addROI ( item , styleOptions ) {
11681213 console . info ( `add ROI ${ item . uid } ` )
11691214 const geometry = _scoord3d2Geometry ( item . scoord3d , this [ _pyramidMetadata ] ) ;
11701215 const feature = new Feature ( geometry ) ;
11711216 feature . setProperties ( item . properties , true ) ;
11721217 feature . setId ( item . uid ) ;
1218+ _setFeatureStyle ( feature , styleOptions )
11731219 this [ _features ] . push ( feature ) ;
11741220 }
11751221
1222+ /** Sets the style of a region of interest.
1223+ *
1224+ * @param {string } uid - Unique identifier of the regions of interest.
1225+ * @param {object } styleOptions - Style options
1226+ * @param {object } styleOptions.stroke - Style options for the outline of the geometry
1227+ * @param {number[] } styleOptions.stroke.color - RGBA color of the outline
1228+ * @param {number } styleOptions.stroke.width - Width of the outline
1229+ * @param {object } styleOptions.fill - Style options for body the geometry
1230+ * @param {number[] } styleOptions.fill.color - RGBA color of the body
1231+ *
1232+ */
1233+ setROIStyle ( uid , styleOptions ) {
1234+ this [ _features ] . forEach ( feature => {
1235+ const id = feature . getId ( ) ;
1236+ if ( id === uid ) {
1237+ _setFeatureStyle ( feature , styleOptions )
1238+ }
1239+ } )
1240+ }
1241+
11761242 /** Adds a new viewport overlay.
11771243 *
11781244 * @param {object } options Overlay options
0 commit comments