fix: move btnExportCoordsPDF logic inside DOMContentLoaded to access state
Deploy Standortplaner / deploy (push) Successful in 17s
Details
Deploy Standortplaner / deploy (push) Successful in 17s
Details
This commit is contained in:
parent
aebdf63095
commit
4816876ff3
137
app.js
137
app.js
|
|
@ -2694,6 +2694,75 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||
|
||||
updateLegend();
|
||||
console.log("WindPlaner initialisiert.");
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
document.getElementById('statusInfo').innerText = "System bereit. Karte geladen.";
|
||||
});
|
||||
|
||||
|
|
@ -3162,71 +3231,3 @@ 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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue