diff --git a/www/app.js b/www/app.js index c3719ea..aeab63f 100644 --- a/www/app.js +++ b/www/app.js @@ -5,16 +5,16 @@ import * as THREE from './lib/three.module.js'; // ?v=lib2 : fichiers de lib/ modifiés (imports relatifs) ; changer lib2 si on les retouche, sinon le // navigateur peut garder l'ancienne version en cache (et LineSegments2.js doit importer les mêmes URL). import * as LocAR from './lib/locar.es.js?v=lib2'; -import { PYLON_TYPES } from './pylon.js?v=49'; -import { BuildingOccluders } from './buildings.js?v=49'; -import { LidarOccluders } from './lidar.js?v=49'; -import { Terrain, TerrainOccluders } from './terrain.js?v=49'; -import { registerServiceWorker, offlineSupported, offlineStatus, downloadAll, clearOffline, sourceSize } from './offline.js?v=49'; +import { PYLON_TYPES } from './pylon.js?v=50'; +import { BuildingOccluders } from './buildings.js?v=50'; +import { LidarOccluders } from './lidar.js?v=50'; +import { Terrain, TerrainOccluders } from './terrain.js?v=50'; +import { registerServiceWorker, offlineSupported, offlineStatus, downloadAll, clearOffline, sourceSize } from './offline.js?v=50'; import { LineSegments2 } from './lib/lines/LineSegments2.js?v=lib2'; import { LineSegmentsGeometry } from './lib/lines/LineSegmentsGeometry.js?v=lib2'; import { LineMaterial } from './lib/lines/LineMaterial.js?v=lib2'; -const APP_VERSION = 'v49'; // affichée à gauche de l'indication « Tourne à… » +const APP_VERSION = 'v50'; // affichée à gauche de l'indication « Tourne à… » window.__bdhLoaded = true; // vu par boot.js : l'app s'est bien chargée // --------------------------------------------------------------------------- @@ -212,7 +212,7 @@ const $ = (id) => document.getElementById(id); const ui = { intro: $('intro'), start: $('start'), error: $('error'), hud: $('hud'), gps: $('h-gps'), heading: $('h-heading'), trace: $('h-trace'), pylon: $('h-pylon'), prec: $('h-prec'), - hint: $('h-hint'), err: $('h-err'), sensors: $('h-sensors'), + hint: $('h-hint'), err: $('h-err'), sensors: $('h-sensors'), quality: $('h-quality'), qPill: $('btn-quality'), bar: $('bar'), toggle: $('btn-toggle'), fov: $('fov'), fovOut: $('fov-out'), color: $('btn-color'), shotBtn: $('btn-shot'), shot: $('shot'), shotImg: $('shot-img'), shotShare: $('shot-share'), @@ -650,6 +650,58 @@ function drawMiniMap() { c.fillText(miniMapRadius < 1000 ? `${miniMapRadius} m` : `${miniMapRadius / 1000} km`, r, size - 6 * dpr); } +// --------------------------------------------------------------------------- +// Fiabilité de la vue en ce moment (étape 8) : GPS, boussole, relief. +// Niveau = le pire des trois : ok (vert) / moyen (orange) / faible (rouge), toujours avec un mot. +// --------------------------------------------------------------------------- +const compassAbsolute = () => fakeMode || app?.deviceOrientationControls?.orientationChangeEventName === 'deviceorientationabsolute' + || /iPhone|iPad|iPod|Macintosh/.test(navigator.userAgent); +const Q_RANK = { ok: 0, moyen: 1, faible: 2 }; +const Q_WORD = { ok: 'Fiable', moyen: 'Approximatif', faible: 'Peu fiable' }; +const Q_ICON = { ok: '●', moyen: '◐', faible: '○' }; +function quality() { + const items = []; // [niveau, texte] + // GPS + const g = fakeMode ? (me && { ...me, t: Date.now() }) : raw; + if (fakeMode) items.push(['moyen', 'position simulée (mode test)']); + else if (!g) items.push(['faible', 'GPS : en attente de position']); + else { + const age = (Date.now() - g.t) / 1000, acc = Math.round(g.acc); + if (age > 15) items.push(['faible', `GPS : pas de mesure depuis ${Math.round(age)} s`]); + else if (acc <= 10) items.push(['ok', `GPS ± ${acc} m`]); + else if (acc <= 30) items.push(['moyen', `GPS ± ${acc} m (approximatif)`]); + else items.push(['faible', `GPS ± ${acc} m (imprécis)`]); + } + // Boussole + if (!fakeMode && (oriRate === 0 || nullRate >= oriRate) && Date.now() - lastOriValid > 2000) items.push(['faible', 'boussole : aucune donnée']); + else if (!compassAbsolute()) items.push(['faible', 'boussole non absolue : la direction peut être fausse']); + else if (calDone) items.push(['ok', `boussole calée${compassOffset ? ` (${fmtOffset(compassOffset)})` : ''}`]); + else items.push(['moyen', 'boussole non calée : décalage possible de 10 à 20° (Réglages › 🎯 Caler la vue)']); + // Relief / masquage + if (!occlOn) items.push(['moyen', 'masquage désactivé : la ligne est dessinée devant tout']); + else if (groundMe === null || !buildings?.count) items.push(['moyen', 'relief en cours de chargement']); + else items.push(['ok', `relief chargé (${occlSrc === 'osm' ? 'bâtiments OSM' : `LiDAR ${OCCL_SOURCES[occlSrc].short.toLowerCase()}`})`]); + const level = items.reduce((w, [l]) => (Q_RANK[l] > Q_RANK[w] ? l : w), 'ok'); + return { level, word: Q_WORD[level], items }; +} +function showQuality() { + const q = quality(); + ui.qPill.textContent = `${Q_ICON[q.level]} ${q.word}`; + ui.qPill.className = `q-pill q-${q.level}`; + ui.quality.innerHTML = q.items.map(([l, t]) => `${t}`).join(' · '); + if (!$('limits').hidden) fillLimitsNow(q); +} +function fillLimitsNow(q = quality()) { + $('limits-now').hidden = !app; + $('limits-quality').innerHTML = `${Q_ICON[q.level]} ${q.word}`; + $('limits-details').innerHTML = q.items.map(([l, t]) => `
  • ${t}
  • `).join(''); +} +function openLimits() { fillLimitsNow(); $('limits').hidden = false; } +$('limits-close').addEventListener('click', () => { $('limits').hidden = true; }); +$('btn-limits-intro').addEventListener('click', openLimits); +$('btn-limits-settings').addEventListener('click', openLimits); +ui.qPill.addEventListener('click', (e) => { e.stopPropagation(); openLimits(); }); + // Ligne « Précision » du bandeau : précision du masquage choisie, relief, zone sans obstacle function precisionText() { if (!occlOn) return 'masquage désactivé (la ligne est dessinée par-dessus tout) · relief 10 m'; @@ -665,8 +717,7 @@ function updateHud() { applyFov(); // la vidéo peut changer de dimensions (rotation, reprise) const h = cameraHeading(); - const abs = fakeMode || app.deviceOrientationControls?.orientationChangeEventName === 'deviceorientationabsolute' - || /iPhone|iPad|iPod|Macintosh/.test(navigator.userAgent); + const abs = compassAbsolute(); ui.heading.innerHTML = `${Math.round(h)}° ${cardinal(h)}` + (abs ? '' : ' (boussole non absolue ?)') + (compassOffset ? ` (correction ${fmtOffset(compassOffset)})` : ''); drawMiniMap(); @@ -721,6 +772,7 @@ function updateHud() { } ui.prec.textContent = precisionText(); + showQuality(); if (!me) { ui.trace.textContent = '–'; ui.pylon.textContent = '–'; setHint('Recherche du GPS…'); return; } // Ligne la plus proche + contrôle de vraisemblance de la position @@ -979,7 +1031,7 @@ async function capturePhoto() { // Mise en page : côte à côte en portrait, l'une sous l'autre en paysage const portrait = H >= W, gap = Math.round(Math.min(W, H) * 0.015); const fs = Math.round(Math.max(14, Math.min(W, H) * 0.035)); // taille de texte - const capH = Math.round(fs * 4.6); // bandeau de légende + const capH = Math.round(fs * 7.1); // bandeau de légende (5 lignes) const outW = portrait ? W * 2 + gap : W, outH = (portrait ? H : H * 2 + gap) + capH; const out = document.createElement('canvas'); out.width = outW; out.height = outH; @@ -1009,11 +1061,14 @@ async function capturePhoto() { const h = Math.round(cameraHeading()); const pos = me ? `${me.lat.toFixed(5)}, ${me.lon.toFixed(5)} (± ${Math.round(me.acc)} m)` : 'position inconnue'; const t = curType(); + const q = quality(); const lines = [ `Boucle du Hainaut (380 kV) – simulation en réalité augmentée ${APP_VERSION} · ${when}`, `Position ${pos} · regard vers ${h}° ${cardinal(h)} · pylônes ${t.label}, un tous les ${t.span} m`, + `Fiabilité : ${q.word.toUpperCase()} – ${q.items.map(([, s]) => s.replace(/ \(Réglages.*\)$/, '')).join(' · ')}`, 'Tracé : carte limonier.be/carte-bdh · emplacements estimés, pas officiels · relief : SPW 2021-2022' + (occlSrc === 'osm' ? ' · bâtiments OSM' : ' (LiDAR) + bâtiments OSM proches'), + 'Vérifie sur place avec ton téléphone : sillycone-village.be/bdh-ar', ]; const y0 = outH - capH; o.fillStyle = '#111'; o.fillRect(0, y0, outW, capH); @@ -1079,8 +1134,9 @@ function setCompassOffset(v) { // Mode « Caler la vue » : on fait glisser le paysage virtuel (bâtiments en bleu, pylônes) // à gauche ou à droite jusqu'à ce qu'il se superpose au réel → règle la correction de boussole. // --------------------------------------------------------------------------- -let calMode = false, calLast = null; +let calMode = false, calLast = null, calDone = false; // calDone : calage fait pendant cette session function setCalMode(on) { + if (calMode && !on) calDone = true; calMode = on; ui.cal.classList.toggle('on', on); ui.calInfo.hidden = !on; diff --git a/www/buildings.js b/www/buildings.js index e29ba00..8213ecf 100644 --- a/www/buildings.js +++ b/www/buildings.js @@ -9,7 +9,7 @@ // dans la même projection locale que l'app (équirectangulaire, LAT0 = 50,6°). import * as THREE from './lib/three.module.js'; -import { withClearZone } from './terrain.js?v=49'; +import { withClearZone } from './terrain.js?v=50'; const TILE = 1000; // m diff --git a/www/index.html b/www/index.html index 53f1323..5d59e74 100644 --- a/www/index.html +++ b/www/index.html @@ -11,7 +11,7 @@ Boucle du Hainaut : ouvrons les yeux - + @@ -44,7 +45,8 @@
    Tracé –
    Pylônes –
    Précision –
    -
    +
    Qualité –
    +
    @@ -98,6 +100,7 @@

    Plus l'angle est petit, plus le pylône paraît grand. Pour calibrer : vise un objet de taille connue à distance connue. Valeur habituelle : 60–70°.

    + @@ -122,6 +125,43 @@ + + + - - + + diff --git a/www/lidar.js b/www/lidar.js index 8a9fc16..b0edaf6 100644 --- a/www/lidar.js +++ b/www/lidar.js @@ -5,7 +5,7 @@ // Les hauteurs sont posées sur le relief du terrain (terrain.js) : y = altitude du sol + hauteur. import * as THREE from './lib/three.module.js'; -import { withClearZone } from './terrain.js?v=49'; +import { withClearZone } from './terrain.js?v=50'; const TILE = 1000; // m diff --git a/www/style.css b/www/style.css index a3d3bbf..51a7625 100644 --- a/www/style.css +++ b/www/style.css @@ -169,3 +169,21 @@ button:disabled { opacity: .5; } #intro .legal { margin-top: 16px; padding-top: 10px; border-top: 1px solid #2a333c; font-size: .7rem; line-height: 1.4; color: #7f8b96; } #intro #start { width: 100%; } + +/* Voyant de qualité (couleur + mot, lisible aussi pour les daltoniens) */ +.q-pill { flex: 0 0 auto; padding: 3px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; border: 1px solid transparent; } +.q-pill.q-ok { background: #1b5e20; color: #fff; } +.q-pill.q-moyen { background: #ffb300; color: #000; } +.q-pill.q-faible { background: #c62828; color: #fff; } +.q-ok-t { color: #8fd694; } .q-moyen-t { color: #ffcf5c; } .q-faible-t { color: #ff8a80; } +/* Sources et limites */ +.btn-limits { background: transparent; border: 1px solid #44505c; color: #b8c4cf; font-size: .85rem; padding: 8px 10px; margin-top: 10px; width: 100%; } +#limits { position: fixed; inset: 0; z-index: 3600; background: rgba(0,0,0,.85); overflow-y: auto; padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom)); } +#limits[hidden] { display: none; } +#limits .limits-box { max-width: 640px; margin: 0 auto; background: #10161c; border: 1px solid #44505c; border-radius: 12px; padding: 14px 16px; font-size: .9rem; line-height: 1.45; color: #dde4ea; } +#limits h2 { margin: 0 0 6px; font-size: 1.25rem; } +#limits h3 { margin: 14px 0 4px; font-size: 1rem; color: #fff; } +#limits ul { margin: 0; padding-left: 1.2em; } +#limits li { margin: 3px 0; } +#limits a { color: #7cc4ff; } +#limits-close { width: 100%; margin-top: 14px; padding: 10px; background: #44505c; } diff --git a/www/sw.js b/www/sw.js index 6e09b57..7038595 100644 --- a/www/sw.js +++ b/www/sw.js @@ -4,11 +4,11 @@ // Réglages › « Télécharger tout pour hors-ligne » (cache DATA, conservé entre les versions). // À chaque nouvelle version de l'app, changer VERSION (et les ?v= dans index.html). -const VERSION = 'v49'; +const VERSION = 'v50'; const SHELL = `bdh-shell-${VERSION}`; const DATA = 'bdh-data-v1'; const SHELL_FILES = [ - './', 'index.html', `app.js?v=49`, `boot.js?v=49`, `pylon.js?v=49`, `buildings.js?v=49`, `offline.js?v=49`, `lidar.js?v=49`, `terrain.js?v=49`, `style.css?v=49`, + './', 'index.html', `app.js?v=50`, `boot.js?v=50`, `pylon.js?v=50`, `buildings.js?v=50`, `offline.js?v=50`, `lidar.js?v=50`, `terrain.js?v=50`, `style.css?v=50`, 'lib/three.module.js', 'lib/three.core.js', 'lib/locar.es.js?v=lib2', 'lib/lines/LineSegments2.js?v=lib2', 'lib/lines/LineSegmentsGeometry.js?v=lib2', 'lib/lines/LineMaterial.js?v=lib2', 'data/trace.json', 'manifest.json', 'icon.svg', 'icon-192.png', 'icon-512.png',