From aebdf6309549cf85bb48a30dfe85902ad32b2145 Mon Sep 17 00:00:00 2001 From: Johannes Baumeister Date: Sat, 4 Jul 2026 21:34:50 +0200 Subject: [PATCH] feat: Add PDF export for turbine coordinate list --- app.js | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 3 +++ 2 files changed, 72 insertions(+) diff --git a/app.js b/app.js index 3562772..cdccbe0 100644 --- a/app.js +++ b/app.js @@ -3161,3 +3161,72 @@ async function resolveLayerConfig(isLocalFile, statusEl) { } }); } + + const btnExportCoordsPDF = document.getElementById('btnExportCoordsPDF'); + if (btnExportCoordsPDF) { + btnExportCoordsPDF.addEventListener('click', async () => { + const originalText = btnExportCoordsPDF.innerText; + btnExportCoordsPDF.innerText = 'Exportiere...'; + btnExportCoordsPDF.disabled = true; + + try { + // Finde aktive Variante + const activeVariantNode = document.querySelector('.variant-tab.active'); + const activeVariant = activeVariantNode ? activeVariantNode.dataset.variant : 'variant1'; + + // Filtere Anlagen, die zur aktuellen Variante gehören + const activeTurbines = state.turbines.filter(t => t.variant === activeVariant); + + if (activeTurbines.length === 0) { + alert('Keine Anlagen in der aktuellen Variante gefunden.'); + return; + } + + // Initialisiere jsPDF + const { jsPDF } = window.jspdf; + const doc = new jsPDF(); + + // Titel und Projektname + const projName = document.getElementById('projectSelector')?.options[document.getElementById('projectSelector')?.selectedIndex]?.text || 'Projekt unbekannt'; + + doc.setFontSize(16); + doc.text(`Koordinatenliste - ${projName}`, 14, 20); + + // Untertitel (Variante) + doc.setFontSize(12); + let variantName = activeVariant === 'variant1' ? 'Variante 1' : activeVariant === 'variant2' ? 'Variante 2' : 'Variante 3'; + doc.text(`Variante: ${variantName}`, 14, 30); + + // Daten vorbereiten (Rechtswert/Hochwert aus UTM32) + const tableData = activeTurbines.map(t => { + const latlng = t.layers.marker.getLatLng(); + const utmCoords = proj4(wgs84, utm32, [latlng.lng, latlng.lat]); + return [ + t.nr, + t.hersteller || '-', + t.type || '-', + utmCoords[0].toFixed(2), + utmCoords[1].toFixed(2) + ]; + }); + + // Tabelle einfügen + doc.autoTable({ + startY: 40, + head: [['WEA Nr.', 'Hersteller', 'Anlagentyp', 'Rechtswert (E)', 'Hochwert (N)']], + body: tableData, + theme: 'striped', + headStyles: { fillColor: [0, 200, 255], textColor: [255, 255, 255] } + }); + + doc.save(`Koordinatenliste_${projName.replace(/\s+/g, '_')}_${activeVariant}.pdf`); + + } catch (err) { + console.error('Fehler beim Koordinaten-PDF Export:', err); + alert('Fehler beim PDF Export: ' + err.message); + } finally { + btnExportCoordsPDF.innerText = originalText; + btnExportCoordsPDF.disabled = false; + } + }); + } diff --git a/index.html b/index.html index 0a84af1..de4cb6b 100644 --- a/index.html +++ b/index.html @@ -131,6 +131,8 @@ style="flex: 0.4; padding: 6px; margin-top: 0;">📐 + @@ -285,6 +287,7 @@ +