@@ -46,18 +46,16 @@ function CollectionMap({ collection }: CollectionMapProps) {
4646
4747 // Fit the map view around the current collection extent
4848 useEffect ( ( ) => {
49- map ?. once ( "load" , ( ) => {
50- if ( collection ) {
51- let [ x1 , y1 , x2 , y2 ] = collection . extent . spatial . bbox [ 0 ] ;
52- const bounds = new LngLatBounds ( [ x1 , y1 , x2 , y2 ] ) ;
53- for ( let i = 1 , len = collection . extent . spatial . bbox . length ; i < len ; i ++ ) {
54- [ x1 , y1 , x2 , y2 ] = collection . extent . spatial . bbox [ i ] ;
55- bounds . extend ( [ x1 , y1 , x2 , y2 ] ) ;
56- }
57- [ x1 , y1 , x2 , y2 ] = bounds . toArray ( ) . flat ( ) ;
58- map . fitBounds ( [ x1 , y1 , x2 , y2 ] , { padding : 30 , duration : 10 } ) ;
49+ if ( collection && map ) {
50+ let [ x1 , y1 , x2 , y2 ] = collection . extent . spatial . bbox [ 0 ] ;
51+ const bounds = new LngLatBounds ( [ x1 , y1 , x2 , y2 ] ) ;
52+ for ( let i = 1 , len = collection . extent . spatial . bbox . length ; i < len ; i ++ ) {
53+ [ x1 , y1 , x2 , y2 ] = collection . extent . spatial . bbox [ i ] ;
54+ bounds . extend ( [ x1 , y1 , x2 , y2 ] ) ;
5955 }
60- } ) ;
56+ [ x1 , y1 , x2 , y2 ] = bounds . toArray ( ) . flat ( ) ;
57+ map . fitBounds ( [ x1 , y1 , x2 , y2 ] , { padding : 30 , duration : 10 } ) ;
58+ }
6159 } , [ collection , map ] ) ;
6260
6361 return (
0 commit comments