feat: Add PDF export for turbine coordinate list
Deploy Standortplaner / deploy (push) Successful in 17s
Details
Deploy Standortplaner / deploy (push) Successful in 17s
Details
This commit is contained in:
parent
a844d8a872
commit
aebdf63095
69
app.js
69
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,6 +131,8 @@
|
|||
style="flex: 0.4; padding: 6px; margin-top: 0;">📐</button>
|
||||
<button class="btn-primary btn-mini" id="btnExportPDF" title="Karte als PDF exportieren"
|
||||
style="flex: 1; padding: 6px; margin-top: 4px; min-width: 100%;">📄 Karte PDF</button>
|
||||
<button class="btn-primary btn-mini" id="btnExportCoordsPDF" title="Koordinatenliste exportieren"
|
||||
style="flex: 1; padding: 6px; margin-top: 4px; min-width: 100%;">📄 Koordinatenliste PDF</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -285,6 +287,7 @@
|
|||
<script src="libs/turf.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.31/jspdf.plugin.autotable.min.js"></script>
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue