feat: implement turbine loading from DB and improved error reporting
Deploy Bürgerwind / deploy (push) Successful in 16s
Details
Deploy Bürgerwind / deploy (push) Successful in 16s
Details
This commit is contained in:
parent
90b9ad9ffa
commit
5fd8ea3763
43
app.js
43
app.js
|
|
@ -1440,11 +1440,11 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
body: JSON.stringify({ projekt_id, turbines: turbineData })
|
body: JSON.stringify({ projekt_id, turbines: turbineData })
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const result = await response.json();
|
|
||||||
statusEl.innerHTML = `<span style="color: #2ecc71;">${result.message}</span>`;
|
statusEl.innerHTML = `<span style="color: #2ecc71;">${result.message}</span>`;
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Fehler beim Speichern in DB");
|
throw new Error(result.error || "Fehler beim Speichern in DB");
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
@ -1453,6 +1453,45 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function loadTurbinesFromDB() {
|
||||||
|
const project_id = "BWSamern-Ohne";
|
||||||
|
const statusEl = document.getElementById('statusInfo');
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/api/wea/${project_id}`);
|
||||||
|
if (response.ok) {
|
||||||
|
const dbTurbines = await response.json();
|
||||||
|
if (dbTurbines.length > 0) {
|
||||||
|
console.log(`Geladen: ${dbTurbines.length} WEAs aus der Datenbank.`);
|
||||||
|
|
||||||
|
// Optional: Clear existing turbines if they were loaded from shapefile
|
||||||
|
// but usually DB should take precedence
|
||||||
|
state.turbines.forEach(t => {
|
||||||
|
Object.values(t.layers).forEach(l => variantLayers[t.variant].removeLayer(l));
|
||||||
|
});
|
||||||
|
state.turbines = [];
|
||||||
|
|
||||||
|
dbTurbines.forEach(t => {
|
||||||
|
const latlng = L.latLng(t.lat, t.lng);
|
||||||
|
createTurbine(latlng, null, {
|
||||||
|
nr: t.nr,
|
||||||
|
type: t.type,
|
||||||
|
rd: t.rd,
|
||||||
|
hh: t.hh
|
||||||
|
});
|
||||||
|
});
|
||||||
|
statusEl.innerText = `${dbTurbines.length} WEAs aus Datenbank geladen.`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Fehler beim Laden aus der DB:", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load from DB after layers are initialized
|
||||||
|
initDynamicLayers().then(() => {
|
||||||
|
loadTurbinesFromDB();
|
||||||
|
});
|
||||||
|
|
||||||
btnLoad.addEventListener('click', () => projectInput.click());
|
btnLoad.addEventListener('click', () => projectInput.click());
|
||||||
|
|
||||||
projectInput.addEventListener('change', (e) => {
|
projectInput.addEventListener('change', (e) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue