@@ -275,20 +275,27 @@ function drawLegends(tools, _legend, layerUUID, display_name, opacity) {
275275 . attr ( 'class' , 'legend-image-container' )
276276 . style ( 'display' , 'flex' )
277277 . style ( 'justify-content' , 'center' )
278- . style ( 'margin' , '8px ' )
279- . style ( 'padding' , '8px ' )
280-
278+ . style ( 'margin' , '4px ' )
279+ . style ( 'padding' , '4px ' )
280+ . style ( 'overflow-x' , 'hidden' )
281281 imageContainer
282282 . append ( 'img' )
283283 . attr ( 'src' , _legend . startsWith ( 'http' ) ? _legend : L_ . missionPath + _legend )
284284 . attr ( 'alt' , `Legend for ${ display_name } ` )
285- . style ( 'max-width' , '100% ' )
285+ . style ( 'max-width' , '300px ' )
286286 . style ( 'max-height' , '220px' )
287287 . style ( 'height' , 'auto' )
288288 . style ( 'background-color' , 'white' )
289289 . style ( 'border' , '1px solid var(--color-i)' )
290290 . style ( 'border-radius' , '3px' )
291291 . style ( 'opacity' , opacity )
292+ . on ( 'load' , function ( ) {
293+ // Set container max-width to image width (capped at 300px)
294+ const maxImageWidth = Math . min ( this . naturalWidth , 300 )
295+ imageContainer
296+ . style ( 'max-width' , maxImageWidth + 'px' )
297+ . style ( 'width' , 'fit-content' )
298+ } )
292299 . on ( 'error' , function ( ) {
293300 // Handle image load error
294301 d3 . select ( this . parentNode )
0 commit comments