11import WebGLMap from 'ol/WebGLMap' ;
2+ import Map from 'ol/Map' ;
23import View from 'ol/View' ;
34import TileLayer from 'ol/layer/Tile' ;
45import XYZ from 'ol/source/XYZ' ;
@@ -214,6 +215,20 @@ class DICOMMicroscopyViewer {
214215 '1.2.840.10008.1.2.4.80' : 'x-jls' ,
215216 '1.2.840.10008.1.2.4.90' : 'jp2'
216217 }
218+
219+ function base64Encode ( data ) {
220+ const uint8Array = new Uint8Array ( data ) ;
221+ const chunkSize = 0x8000 ;
222+ const strArray = [ ] ;
223+ for ( let i = 0 ; i < uint8Array . length ; i += chunkSize ) {
224+ let str = String . fromCharCode . apply (
225+ null , uint8Array . subarray ( i , i + chunkSize )
226+ ) ;
227+ strArray . push ( str ) ;
228+ }
229+ return btoa ( strArray . join ( '' ) ) ;
230+ }
231+
217232 function tileLoadFunction ( tile , src ) {
218233 if ( src !== null ) {
219234 let studyInstanceUID = DICOMwebClient . utils . getStudyInstanceUIDFromUri ( src ) ;
@@ -232,9 +247,8 @@ class DICOMMicroscopyViewer {
232247 imageSubtype
233248 } ;
234249 client . retrieveInstanceFrames ( retrieveOptions ) . then ( ( frames ) => {
235- let pixels = frames [ 0 ] ;
236250 // Encode pixel data as base64 string
237- const encodedPixels = btoa ( String . fromCharCode ( ... new Uint8Array ( pixels ) ) ) ;
251+ const encodedPixels = base64Encode ( frames [ 0 ] ) ;
238252 // Add pixel data to image
239253 tile . getImage ( ) . src = "data:image/" + imageSubtype + ";base64," + encodedPixels ;
240254
@@ -398,7 +412,7 @@ class DICOMMicroscopyViewer {
398412 loadTilesWhileInteracting : true ,
399413 logo : false
400414 } ) ;
401- this . map . getView ( ) . fit ( extent ) ;
415+ this . map . getView ( ) . fit ( extent , this . map . getSize ( ) ) ;
402416 return ( this . map ) ;
403417 } ) ;
404418 return ( mapPromise ) ;
0 commit comments