perf(viewer): polylines USV <3s — Phase 1 usv_track endpoint + immediate applyTrailAndCursor

This commit is contained in:
Poulpe
2026-04-28 15:03:53 +00:00
parent f5788a01f4
commit dd6f0cf435
2 changed files with 112 additions and 3 deletions

View File

@@ -1280,8 +1280,42 @@ function setupSyncedZoom(chartIds) {
async function loadSortieData(sortieId) {
const prog = document.getElementById('sync-progress');
try {
prog.textContent = 'Chargement USV…';
const usvResp = await fetch(`${API2}/sorties/${encodeURIComponent(sortieId)}/usv`);
// Reset state for sortie mode (independent from datebar)
clearMapLayers();
allPoints = [];
usblPoints = [];
// Phase 1: USV GPS track → polylines on map immediately (<3s target)
prog.textContent = 'Chargement track USV…';
const trackResp = await fetch(`${API2}/sorties/${encodeURIComponent(sortieId)}/usv_track`,
{ signal: AbortSignal.timeout(15000) });
if (trackResp.ok) {
const trackPts = await trackResp.json();
allPoints.push(...trackPts);
allPoints.sort((a, b) => a.t_ms - b.t_ms);
if (allPoints.length > 0) {
const times = allPoints.map(p => p.t_ms);
tMin = Math.min(...times);
tMax = Math.max(...times);
tNow = tMax;
// Fit map bounds
const lats = allPoints.map(p => p.lat).filter(Boolean);
const lons = allPoints.map(p => p.lon).filter(Boolean);
if (lats.length) {
map.fitBounds([
[Math.min(...lats), Math.min(...lons)],
[Math.max(...lats), Math.max(...lons)],
], { padding: [40, 40] });
}
showNoDataOverlay(false);
applyTrailAndCursor(); // PERF FIX: polylines visible NOW, before charts
prog.textContent = `Track USV ${allPoints.length} pts — chargement charts…`;
}
}
// Phase 2: series + AUV (charts populate progressively)
const usvResp = await fetch(`${API2}/sorties/${encodeURIComponent(sortieId)}/usv`,
{ signal: AbortSignal.timeout(20000) });
if (usvResp.ok) {
const usvData = await usvResp.json();
switchTab('usv'); // BUG1d FIX: switch BEFORE renderUSV so Plotly renders on visible divs
@@ -1291,7 +1325,7 @@ async function loadSortieData(sortieId) {
prog.textContent = 'Chargement AUV…';
await loadAuvTabs(sortieId);
prog.textContent = `${sortieId} chargé`;
// POLYLINE FIX: ensure map trail is drawn if allPoints already loaded from datebar
// Re-apply after AUV usbl_track loaded (adds AUV trail if available)
if (allPoints.length > 0) applyTrailAndCursor();
} catch(e) {
prog.textContent = `Erreur: ${e.message}`;