diff --git a/app.js b/app.js index 431eaea..ff9325d 100644 --- a/app.js +++ b/app.js @@ -124,7 +124,7 @@ document.addEventListener('DOMContentLoaded', async () => { // Calculation Functions function calculateGeometries(latlng, rotorDiameter, hubHeight, foundationRadius, ksfAngle = 0, ksfMirrored = false, hersteller = 'Enercon') { - // Ensure valid numbers for Turf + console.log(`Berechne Geometrien für ${hersteller}, RD=${rotorDiameter}, HH=${hubHeight}`); const rd = parseFloat(rotorDiameter) || 160; const hh = parseFloat(hubHeight) || 165; const fr = parseFloat(foundationRadius) || 15; @@ -229,11 +229,16 @@ document.addEventListener('DOMContentLoaded', async () => { ]; } - const blf = transform(blfCoords); - const ksf = transform(ksfCoords); - const mf = turf.featureCollection(mfParts.map(part => transform(part))); + try { + const blf = transform(blfCoords); + const ksf = transform(ksfCoords); + const mf = turf.featureCollection(mfParts.map(part => transform(part))); - return { sweptArea, techDist, techDistSmall, loadRadius, foundation, blf, ksf, mf, totalHeight, utmCoords }; + return { sweptArea, techDist, techDistSmall, loadRadius, foundation, blf, ksf, mf, totalHeight, utmCoords }; + } catch (err) { + console.error("Fehler in calculateGeometries:", err); + throw err; + } } function updateLabel(turbine, geoms) { @@ -1925,7 +1930,9 @@ document.addEventListener('DOMContentLoaded', async () => { if (dbTurbines.length > 0) { // Clear existing turbines state.turbines.forEach(t => { - Object.values(t.layers).forEach(l => variantLayers[t.variant].removeLayer(l)); + if (t.layers && t.variant && variantLayers[t.variant]) { + Object.values(t.layers).forEach(l => variantLayers[t.variant].removeLayer(l)); + } }); state.turbines = [];