diff --git a/frontend/src/components/Lightbox.jsx b/frontend/src/components/Lightbox.jsx index 709de0f..0d28354 100644 --- a/frontend/src/components/Lightbox.jsx +++ b/frontend/src/components/Lightbox.jsx @@ -1,12 +1,15 @@ // Copyright DB InfraGO AG and contributors // SPDX-License-Identifier: Apache-2.0 -import { useEffect } from 'react'; +import { useEffect, useState } from 'react'; import { TransformWrapper, TransformComponent } from 'react-zoom-pan-pinch'; import { Printer, XIcon } from 'lucide-react'; import { LightboxButton } from './LightboxButton'; export const Lightbox = ({ onClose, imageSource }) => { + const [adjustedWidth, setAdjustedWidth] = useState(0); + const [adjustedHeight, setAdjustedHeight] = useState(0); + useEffect(() => { const handleEscape = (event) => { if (event.key === 'Escape') { @@ -28,16 +31,43 @@ export const Lightbox = ({ onClose, imageSource }) => { }; }, [onClose]); + useEffect(() => { + if (imageSource) { + const controlBar = document.getElementById('control-bar'); + const heightMatch = imageSource.match(/height="(\d+)"/); + const widthMatch = imageSource.match(/width="(\d+)"/); + const imgHeight = heightMatch ? heightMatch[1] : 'defaultHeight'; + const imgWidth = widthMatch ? widthMatch[1] : 'defaultWidth'; + + if (imgHeight > window.innerHeight) { + let widthScale = window.innerWidth / imgWidth; + let heightScale = + (window.innerHeight - controlBar.clientHeight - 20) / imgHeight; + const scalingFactor = Math.min(heightScale, widthScale); + + let adjustedHeight = imgHeight * scalingFactor; + let adjustedWidth = imgWidth * scalingFactor; + setAdjustedHeight(adjustedHeight); + setAdjustedWidth(adjustedWidth); + } else { + setAdjustedHeight('100%'); + setAdjustedWidth('100%'); + } + } + }, [imageSource]); + return (