@@ -19,21 +19,6 @@ const scrollToIndex = cornerstoneTools.importInternal('util/scrollToIndex');
1919const { loadHandlerManager } = cornerstoneTools ;
2020
2121class CornerstoneViewport extends Component {
22- static defaultProps = {
23- // Watch
24- imageIdIndex : 0 ,
25- isPlaying : false ,
26- cineFrameRate : 24 ,
27- viewportOverlayComponent : ViewportOverlay ,
28- imageIds : [ 'no-id://' ] ,
29- // Init
30- cornerstoneOptions : { } ,
31- isStackPrefetchEnabled : false ,
32- loadIndicatorDelay : 45 ,
33- resizeThrottleMs : 200 ,
34- tools : [ ] ,
35- } ;
36-
3722 static propTypes = {
3823 imageIds : PropTypes . arrayOf ( PropTypes . string ) . isRequired ,
3924 imageIdIndex : PropTypes . number ,
@@ -79,13 +64,33 @@ class CornerstoneViewport extends Component {
7964 startLoadHandler : PropTypes . func ,
8065 endLoadHandler : PropTypes . func ,
8166 loadIndicatorDelay : PropTypes . number ,
67+ loadingIndicatorComponent : PropTypes . oneOfType ( [
68+ PropTypes . element ,
69+ PropTypes . func ,
70+ ] ) ,
8271 resizeThrottleMs : PropTypes . number , // 0 to disable
8372 //
8473 style : PropTypes . object ,
8574 className : PropTypes . string ,
8675 isOverlayVisible : PropTypes . bool ,
8776 } ;
8877
78+ static defaultProps = {
79+ // Watch
80+ imageIdIndex : 0 ,
81+ isPlaying : false ,
82+ cineFrameRate : 24 ,
83+ viewportOverlayComponent : ViewportOverlay ,
84+ imageIds : [ 'no-id://' ] ,
85+ // Init
86+ cornerstoneOptions : { } ,
87+ isStackPrefetchEnabled : false ,
88+ loadIndicatorDelay : 45 ,
89+ loadingIndicatorComponent : LoadingIndicator ,
90+ resizeThrottleMs : 200 ,
91+ tools : [ ] ,
92+ } ;
93+
8994 constructor ( props ) {
9095 super ( props ) ;
9196
@@ -97,6 +102,7 @@ class CornerstoneViewport extends Component {
97102 // We can probs grab this once and hold on to? (updated on newImage)
98103 imageId,
99104 imageIdIndex, // Maybe
105+ imageProgress : 0 ,
100106 isLoading : true ,
101107 numImagesLoaded : 0 ,
102108 error : null ,
@@ -172,7 +178,6 @@ class CornerstoneViewport extends Component {
172178 _trySetActiveTool ( this . element , this . props . activeTool ) ;
173179 this . setState ( { isLoading : false } ) ;
174180 } catch ( error ) {
175- console . error ( error ) ;
176181 this . setState ( { error, isLoading : false } ) ;
177182 }
178183 }
@@ -299,6 +304,17 @@ class CornerstoneViewport extends Component {
299304 cornerstone . disable ( this . element ) ;
300305 }
301306
307+ /**
308+ * @returns Component
309+ * @memberof CornerstoneViewport
310+ */
311+ getLoadingIndicator ( ) {
312+ const { loadingIndicatorComponent : Component } = this . props ;
313+ const { error, imageProgress } = this . state ;
314+
315+ return < Component error = { error } percentComplete = { imageProgress } /> ;
316+ }
317+
302318 /**
303319 *
304320 *
@@ -388,9 +404,14 @@ class CornerstoneViewport extends Component {
388404 this . onNewImage
389405 ) ;
390406
391- // Update our "Images Loaded" count.
392- // Better than nothing?
393- this . element [ addOrRemoveEventListener ] (
407+ // Update image load progress
408+ cornerstone . events [ addOrRemoveEventListener ] (
409+ 'cornerstoneimageloadprogress' ,
410+ this . onImageProgress
411+ ) ;
412+
413+ // Update number of images loaded
414+ cornerstone . events [ addOrRemoveEventListener ] (
394415 cornerstone . EVENTS . IMAGE_LOADED ,
395416 this . onImageLoaded
396417 ) ;
@@ -581,6 +602,12 @@ class CornerstoneViewport extends Component {
581602 } ) ;
582603 } ;
583604
605+ onImageProgress = e => {
606+ this . setState ( {
607+ imageProgress : e . detail . percentComplete ,
608+ } ) ;
609+ } ;
610+
584611 imageSliderOnInputCallback = value => {
585612 this . setViewportActive ( ) ;
586613
@@ -624,9 +651,7 @@ class CornerstoneViewport extends Component {
624651 this . element = input ;
625652 } }
626653 >
627- { displayLoadingIndicator && (
628- < LoadingIndicator error = { this . state . error } />
629- ) }
654+ { displayLoadingIndicator && this . getLoadingIndicator ( ) }
630655 { /* This classname is important in that it tells `cornerstone` to not
631656 * create a new canvas element when we "enable" the `viewport-element`
632657 */ }
0 commit comments