diff --git a/app.js b/app.js index 963811d..fbed516 100644 --- a/app.js +++ b/app.js @@ -2971,34 +2971,54 @@ async function resolveLayerConfig(isLocalFile, statusEl) { exportOverlay.style.fontFamily = 'Arial, sans-serif'; exportOverlay.style.boxShadow = '0 0 10px rgba(0,0,0,0.3)'; - const projName = document.getElementById('projectSelector')?.options[document.getElementById('projectSelector')?.selectedIndex]?.text || 'Unbekannt'; + const projName = document.getElementById('projectSelector')?.options[document.getElementById('projectSelector')?.selectedIndex]?.text || ''; + const projHtml = projName ? `
Projekt: ${projName}
` : `
`; + + const showAux = document.getElementById('checkShowAux')?.checked; + const showProx = document.getElementById('checkShowProximity')?.checked; exportOverlay.innerHTML = `
ENWELO Standortplanung
-
Projekt: ${projName}
+ ${projHtml}
Rotorüberstreichfläche
-
Gebietsumring
-
Abstandslinien
+ ${showAux ? `
Gebietsumring
` : ''} + ${showProx ? `
Abstandslinien
` : ''}
WEA Standort
`; mapContainer.appendChild(exportOverlay); + // Temporarily increase scale bar size + const scaleControl = document.querySelector('.leaflet-control-scale-line'); + let oldScaleStyle = ''; + if (scaleControl) { + oldScaleStyle = scaleControl.style.cssText; + scaleControl.style.transform = 'scale(1.5)'; + scaleControl.style.transformOrigin = 'bottom left'; + scaleControl.style.borderWidth = '2px'; + scaleControl.style.fontSize = '14px'; + } + // Wait a tiny bit for DOM to render overlay await new Promise(r => setTimeout(r, 100)); const canvas = await html2canvas(mapContainer, { useCORS: true, allowTaint: true, + scale: 2, // better resolution ignoreElements: (element) => { return element.classList.contains('leaflet-control-zoom'); } }); + // Restore scale bar + if (scaleControl) { + scaleControl.style.cssText = oldScaleStyle; + } mapContainer.removeChild(exportOverlay); - const imgData = canvas.toDataURL('image/png'); + const imgData = canvas.toDataURL('image/jpeg', 0.9); const pdf = new jspdf.jsPDF({ orientation: 'landscape', unit: 'mm', @@ -3007,23 +3027,28 @@ async function resolveLayerConfig(isLocalFile, statusEl) { const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); + + // Set margins (20mm on each side) + const margin = 20; + const maxRenderWidth = pdfWidth - (margin * 2); + const maxRenderHeight = pdfHeight - (margin * 2); const imgProps = pdf.getImageProperties(imgData); const ratio = imgProps.width / imgProps.height; - let renderWidth = pdfWidth; - let renderHeight = pdfWidth / ratio; + let renderWidth = maxRenderWidth; + let renderHeight = maxRenderWidth / ratio; - if (renderHeight > pdfHeight) { - renderHeight = pdfHeight; - renderWidth = pdfHeight * ratio; + if (renderHeight > maxRenderHeight) { + renderHeight = maxRenderHeight; + renderWidth = maxRenderHeight * ratio; } // Center image in PDF - const xOffset = (pdfWidth - renderWidth) / 2; - const yOffset = (pdfHeight - renderHeight) / 2; + const xOffset = margin + (maxRenderWidth - renderWidth) / 2; + const yOffset = margin + (maxRenderHeight - renderHeight) / 2; - pdf.addImage(imgData, 'PNG', xOffset, yOffset, renderWidth, renderHeight); + pdf.addImage(imgData, 'JPEG', xOffset, yOffset, renderWidth, renderHeight); pdf.save('Karte_Enwelo.pdf'); } catch (err) {