Add dual-map debug diagnostics

This commit is contained in:
Morten V. Christiansen 2026-04-07 15:11:38 +02:00
parent 5a0fce5374
commit 5a782b51ca
2 changed files with 42 additions and 1 deletions

View File

@ -13,6 +13,7 @@ const statusEl = document.getElementById("status");
const selectedVehicleInfoEl = document.getElementById("selectedVehicleInfo"); const selectedVehicleInfoEl = document.getElementById("selectedVehicleInfo");
const runtimeWarningEl = document.getElementById("runtimeWarning"); const runtimeWarningEl = document.getElementById("runtimeWarning");
const tileWarningEl = document.getElementById("tileWarning"); const tileWarningEl = document.getElementById("tileWarning");
const debugPanelEl = document.getElementById("debugPanel");
const alertsApproxEl = document.getElementById("presenceAlertsApprox"); const alertsApproxEl = document.getElementById("presenceAlertsApprox");
const alertsTrueEl = document.getElementById("presenceAlertsTrue"); const alertsTrueEl = document.getElementById("presenceAlertsTrue");
const playBtn = document.getElementById("playBtn"); const playBtn = document.getElementById("playBtn");
@ -154,17 +155,26 @@ function renderSelectedVehicleInfo(selection) {
function createView({ id, label, positionKey, alertsEl, indicatorsId }) { function createView({ id, label, positionKey, alertsEl, indicatorsId }) {
const map = L.map(id).setView([55.6761, 12.5683], 13); const map = L.map(id).setView([55.6761, 12.5683], 13);
let tileErrors = 0;
let tileLoads = 0;
const tileLayer = L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", { const tileLayer = L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution: "© OpenStreetMap contributors", attribution: "© OpenStreetMap contributors",
maxZoom: 19 maxZoom: 19
}).addTo(map); }).addTo(map);
tileLayer.on("tileerror", () => { tileLayer.on("tileerror", () => {
tileErrors += 1;
tileWarningEl.hidden = false; tileWarningEl.hidden = false;
}); });
tileLayer.on("tileload", () => {
tileLoads += 1;
});
tileLayer.on("load", () => { tileLayer.on("load", () => {
tileWarningEl.hidden = true; if (tileLoads > 0) {
tileWarningEl.hidden = true;
}
}); });
return { return {
@ -175,6 +185,7 @@ function createView({ id, label, positionKey, alertsEl, indicatorsId }) {
indicatorsEl: document.getElementById(indicatorsId), indicatorsEl: document.getElementById(indicatorsId),
map, map,
tileLayer, tileLayer,
getTileStats: () => ({ tileErrors, tileLoads }),
vehicles: {} vehicles: {}
}; };
} }
@ -398,10 +409,30 @@ function resetDemo() {
updateStatus(); updateStatus();
} }
function updateDebugPanel() {
const lines = views.map((view) => {
const el = document.getElementById(view.id);
const rect = el.getBoundingClientRect();
const center = view.map.getCenter();
const zoom = view.map.getZoom();
const stats = view.getTileStats();
return [
`${view.label}`,
` size: ${Math.round(rect.width)}x${Math.round(rect.height)}`,
` center: ${center.lat.toFixed(4)}, ${center.lng.toFixed(4)}`,
` zoom: ${zoom}`,
` tiles loaded/errors: ${stats.tileLoads}/${stats.tileErrors}`
].join("\n");
});
debugPanelEl.textContent = lines.join("\n\n");
}
function updateStatus() { function updateStatus() {
const total = VEHICLE_EVENTS.length; const total = VEHICLE_EVENTS.length;
const passed = VEHICLE_EVENTS.filter(e => e.ts <= simTime).length; const passed = VEHICLE_EVENTS.filter(e => e.ts <= simTime).length;
statusEl.textContent = `Simuleret tid: ${simTime.toFixed(1)} s\nEvents passeret: ${passed} / ${total}\nAfspilning: 2x`; statusEl.textContent = `Simuleret tid: ${simTime.toFixed(1)} s\nEvents passeret: ${passed} / ${total}\nAfspilning: 2x`;
updateDebugPanel();
} }
function tick(now) { function tick(now) {

View File

@ -181,6 +181,15 @@
display: none; display: none;
} }
.debug-panel {
border-color: #1d4ed8;
background: rgba(219, 234, 254, 0.98);
color: #1e3a8a;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 11px;
white-space: pre-wrap;
}
.tile-warning { .tile-warning {
border-color: #b91c1c; border-color: #b91c1c;
background: rgba(254, 226, 226, 0.98); background: rgba(254, 226, 226, 0.98);
@ -236,6 +245,7 @@
<div class="panel runtime-warning tile-warning" id="tileWarning" hidden> <div class="panel runtime-warning tile-warning" id="tileWarning" hidden>
Korttiles kunne ikke hentes. Demoen viser derfor grå flader. Tjek netværksadgang eller om browseren blokerer tile-requests. Korttiles kunne ikke hentes. Demoen viser derfor grå flader. Tjek netværksadgang eller om browseren blokerer tile-requests.
</div> </div>
<div class="panel debug-panel" id="debugPanel"></div>
<div class="panel"> <div class="panel">
<strong>Mulige off-map køretøjer, tilnærmet kort</strong> <strong>Mulige off-map køretøjer, tilnærmet kort</strong>
<div class="alerts" id="presenceAlertsApprox"></div> <div class="alerts" id="presenceAlertsApprox"></div>