@@ -15,6 +15,10 @@ import areStringArraysEqual from './../helpers/areStringArraysEqual.js';
15
15
16
16
import './CornerstoneViewport.css' ;
17
17
18
+ const addToBeginning = true ;
19
+ const priority = - 5 ;
20
+ const requestType = 'interaction' ;
21
+
18
22
const scrollToIndex = cornerstoneTools . importInternal ( 'util/scrollToIndex' ) ;
19
23
const { loadHandlerManager } = cornerstoneTools ;
20
24
@@ -186,11 +190,27 @@ class CornerstoneViewport extends Component {
186
190
} ) ;
187
191
188
192
// Load first image in stack
189
- const image = await cornerstone . loadAndCacheImage ( imageId ) ;
190
-
191
- // Display
192
-
193
- cornerstone . displayImage ( this . element , image , initialViewport ) ;
193
+ const options = {
194
+ addToBeginning,
195
+ priority,
196
+ } ;
197
+
198
+ const requestFn = ( imageId , options ) => {
199
+ return cornerstone . loadAndCacheImage ( imageId , options ) . then ( ( image ) => {
200
+ cornerstone . displayImage ( this . element , image , initialViewport ) ;
201
+ } ) ;
202
+ } ;
203
+
204
+ // 1. Load the image using the ImageLoadingPool
205
+ cornerstone . imageLoadPoolManager . addRequest (
206
+ requestFn . bind ( this , imageId , options ) ,
207
+ requestType ,
208
+ {
209
+ imageId,
210
+ } ,
211
+ priority ,
212
+ addToBeginning
213
+ ) ;
194
214
195
215
if ( isStackPrefetchEnabled ) {
196
216
cornerstoneTools . stackPrefetch . enable ( this . element ) ;
@@ -243,10 +263,24 @@ class CornerstoneViewport extends Component {
243
263
// load + display image
244
264
const imageId = stack [ imageIndex || 0 ] ;
245
265
cornerstoneTools . stopClip ( this . element ) ;
246
- const image = await cornerstone . loadAndCacheImage ( imageId ) ;
247
-
248
- cornerstone . displayImage ( this . element , image , initialViewport ) ;
249
- cornerstone . reset ( this . element ) ;
266
+ const requestFn = ( imageId , options ) => {
267
+ return cornerstone
268
+ . loadAndCacheImage ( imageId , options )
269
+ . then ( ( image ) => {
270
+ cornerstone . displayImage ( this . element , image , initialViewport ) ;
271
+ cornerstone . reset ( this . element ) ;
272
+ } ) ;
273
+ } ;
274
+
275
+ cornerstone . imageLoadPoolManager . addRequest (
276
+ requestFn . bind ( this , imageId , { addToBeginning, priority } ) ,
277
+ requestType ,
278
+ {
279
+ imageId,
280
+ } ,
281
+ priority ,
282
+ addToBeginning
283
+ ) ;
250
284
} catch ( err ) {
251
285
// :wave:
252
286
// What if user kills component before `displayImage`?
@@ -350,13 +384,8 @@ class CornerstoneViewport extends Component {
350
384
*/
351
385
getOverlay ( ) {
352
386
const { viewportOverlayComponent : Component , imageIds } = this . props ;
353
- const {
354
- imageIdIndex,
355
- scale,
356
- windowWidth,
357
- windowCenter,
358
- isOverlayVisible,
359
- } = this . state ;
387
+ const { imageIdIndex, scale, windowWidth, windowCenter, isOverlayVisible } =
388
+ this . state ;
360
389
const imageId = imageIds [ imageIdIndex ] ;
361
390
return (
362
391
imageId &&
@@ -586,7 +615,7 @@ class CornerstoneViewport extends Component {
586
615
* @returns {undefined }
587
616
*/
588
617
_handleOnElementEnabledEvent = ( clear = false ) => {
589
- const handler = evt => {
618
+ const handler = ( evt ) => {
590
619
const elementThatWasEnabled = evt . detail . element ;
591
620
if ( elementThatWasEnabled === this . element ) {
592
621
// Pass Event
@@ -633,7 +662,7 @@ class CornerstoneViewport extends Component {
633
662
634
663
// We use this to "flip" `isLoading` to true, if our startLoading request
635
664
// takes longer than our "loadIndicatorDelay"
636
- const startLoadHandler = element => {
665
+ const startLoadHandler = ( element ) => {
637
666
clearTimeout ( this . loadHandlerTimeout ) ;
638
667
639
668
// Call user defined loadHandler
@@ -669,7 +698,7 @@ class CornerstoneViewport extends Component {
669
698
}
670
699
671
700
// TODO: May need to throttle?
672
- onImageRendered = event => {
701
+ onImageRendered = ( event ) => {
673
702
const viewport = event . detail . viewport ;
674
703
675
704
this . setState ( {
@@ -697,9 +726,9 @@ class CornerstoneViewport extends Component {
697
726
}
698
727
} ;
699
728
700
- onNewImage = event => this . onNewImageHandler ( event , this . props . onNewImage ) ;
729
+ onNewImage = ( event ) => this . onNewImageHandler ( event , this . props . onNewImage ) ;
701
730
702
- onNewImageDebounced = debounce ( event => {
731
+ onNewImageDebounced = debounce ( ( event ) => {
703
732
this . onNewImageHandler ( event , this . props . onNewImageDebounced ) ;
704
733
} , this . props . onNewImageDebounceTime ) ;
705
734
@@ -709,13 +738,13 @@ class CornerstoneViewport extends Component {
709
738
this . numImagesLoaded ++ ;
710
739
} ;
711
740
712
- onImageProgress = e => {
741
+ onImageProgress = ( e ) => {
713
742
this . setState ( {
714
743
imageProgress : e . detail . percentComplete ,
715
744
} ) ;
716
745
} ;
717
746
718
- imageSliderOnInputCallback = value => {
747
+ imageSliderOnInputCallback = ( value ) => {
719
748
this . setViewportActive ( ) ;
720
749
721
750
scrollToIndex ( this . element , value ) ;
@@ -757,9 +786,9 @@ class CornerstoneViewport extends Component {
757
786
) }
758
787
< div
759
788
className = "viewport-element"
760
- onContextMenu = { e => e . preventDefault ( ) }
761
- onMouseDown = { e => e . preventDefault ( ) }
762
- ref = { input => {
789
+ onContextMenu = { ( e ) => e . preventDefault ( ) }
790
+ onMouseDown = { ( e ) => e . preventDefault ( ) }
791
+ ref = { ( input ) => {
763
792
this . element = input ;
764
793
} }
765
794
>
@@ -796,9 +825,9 @@ function _trySetActiveTool(element, activeToolName) {
796
825
}
797
826
798
827
const validTools = cornerstoneTools . store . state . tools . filter (
799
- tool => tool . element === element
828
+ ( tool ) => tool . element === element
800
829
) ;
801
- const validToolNames = validTools . map ( tool => tool . name ) ;
830
+ const validToolNames = validTools . map ( ( tool ) => tool . name ) ;
802
831
803
832
if ( ! validToolNames . includes ( activeToolName ) ) {
804
833
console . warn (
0 commit comments