Spaces:
Runtime error
Runtime error
Download templates/map.html from DavidRambeau/happytrain: direct link, hf CLI and curl.
- Browser
- Download file 6.83 kB
-
https://huggingface.co/spaces/DavidRambeau/happytrain/resolve/main/templates/map.html
- Command line
-
hf download hf://spaces/DavidRambeau/happytrain/templates/map.html
-
curl -L -o map.html https://huggingface.co/spaces/DavidRambeau/happytrain/resolve/main/templates/map.html
6.83 kB
| {% extends "base.html" %} | |
| {% block title %}Carte{% endblock %} | |
| {% block extra_head %} | |
| <!-- Leaflet CSS --> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.min.css"> | |
| <style> | |
| #map-container { | |
| height: calc(100vh - 180px); | |
| min-height: 500px; | |
| border: 1px solid var(--border); | |
| border-radius: var(--radius); | |
| overflow: hidden; | |
| } | |
| .map-controls { | |
| display: flex; | |
| gap: 0.75rem; | |
| align-items: center; | |
| padding: 0.75rem 0; | |
| margin-bottom: 0.75rem; | |
| } | |
| .map-legend { | |
| display: flex; | |
| gap: 1rem; | |
| align-items: center; | |
| padding: 0.5rem 1rem; | |
| background: var(--bg2); | |
| border: 1px solid var(--border); | |
| border-radius: var(--radius); | |
| font-family: var(--mono); | |
| font-size: 0.68rem; | |
| color: var(--text-dim); | |
| letter-spacing: 0.1em; | |
| flex-wrap: wrap; | |
| } | |
| .legend-dot { | |
| display: inline-block; | |
| width: 10px; | |
| height: 10px; | |
| border-radius: 50%; | |
| margin-right: 0.3rem; | |
| } | |
| #map-status { | |
| font-family: var(--mono); | |
| font-size: 0.72rem; | |
| color: var(--text-dim); | |
| letter-spacing: 0.1em; | |
| min-width: 160px; | |
| } | |
| .popup-name { | |
| font-family: var(--sans); | |
| font-size: 1rem; | |
| font-weight: 700; | |
| color: #fff; | |
| margin-bottom: 0.3rem; | |
| } | |
| .popup-id { | |
| font-family: var(--mono); | |
| font-size: 0.65rem; | |
| color: var(--text-dim); | |
| margin-bottom: 0.5rem; | |
| word-break: break-all; | |
| } | |
| .popup-link { | |
| display: inline-block; | |
| padding: 0.3rem 0.7rem; | |
| background: var(--accent); | |
| color: #0a0c0f; | |
| text-decoration: none; | |
| border-radius: var(--radius); | |
| font-family: var(--sans); | |
| font-size: 0.75rem; | |
| font-weight: 700; | |
| letter-spacing: 0.08em; | |
| text-transform: uppercase; | |
| } | |
| </style> | |
| {% endblock %} | |
| {% block content %} | |
| <div class="container"> | |
| <div class="page-header"> | |
| <h1 class="page-title">Carte du <span>RΓ©seau</span></h1> | |
| <p class="page-subtitle">Gares et points d'arrΓͺt Β· Cliquez pour voir les dΓ©parts</p> | |
| </div> | |
| <div class="map-controls"> | |
| <div class="map-legend"> | |
| <span><span class="legend-dot" style="background:#e8b84b"></span>Gare principale</span> | |
| <span><span class="legend-dot" style="background:#4b9fe8"></span>ArrΓͺt TGV</span> | |
| <span><span class="legend-dot" style="background:#4be878"></span>ArrΓͺt TER</span> | |
| <span><span class="legend-dot" style="background:#e84b6a"></span>ArrΓͺt OUIGO</span> | |
| <span><span class="legend-dot" style="background:#888"></span>Autre</span> | |
| </div> | |
| <div id="map-status">Chargement de la carteβ¦</div> | |
| <div style="margin-left:auto; display:flex; gap:0.5rem;"> | |
| <button class="btn btn-ghost" id="btn-france" style="font-size:0.78rem;">πΊ France entiΓ¨re</button> | |
| <button class="btn btn-ghost" id="btn-locate" style="font-size:0.78rem;">π Ma position</button> | |
| </div> | |
| </div> | |
| <div id="map-container"></div> | |
| </div> | |
| {% endblock %} | |
| {% block extra_scripts %} | |
| <!-- Leaflet JS --> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.min.js"></script> | |
| <script> | |
| (function() { | |
| // ββ Init carte βββββββββββββββββββββββββββββββββββββββββββ | |
| const map = L.map('map-container', { | |
| center: [46.8, 2.4], | |
| zoom: 6, | |
| zoomControl: true, | |
| }); | |
| // Tuiles sombre (CartoDB Dark) | |
| L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png', { | |
| attribution: 'Β© OpenStreetMap Β© CARTO', | |
| subdomains: 'abcd', | |
| maxZoom: 19, | |
| }).addTo(map); | |
| const status = document.getElementById('map-status'); | |
| let markersLayer = L.layerGroup().addTo(map); | |
| let loadTimeout = null; | |
| // ββ Couleurs par type ββββββββββββββββββββββββββββββββββββ | |
| function stopColor(stopId, stopName) { | |
| const id = (stopId || '').toLowerCase(); | |
| if (id.includes('tgv') || id.includes('inoui') || id.includes('lyria') || id.includes('ice')) return '#4b9fe8'; | |
| if (id.includes('ouigo')) return '#e84b6a'; | |
| if (id.includes('ter') || id.includes('train')) return '#4be878'; | |
| if (id.includes('ic') || id.includes('intercit')) return '#d86af5'; | |
| return '#e8b84b'; | |
| } | |
| function makeIcon(color) { | |
| return L.divIcon({ | |
| html: `<div style=" | |
| width:10px; height:10px; | |
| background:${color}; | |
| border-radius:50%; | |
| border:2px solid rgba(0,0,0,0.4); | |
| box-shadow: 0 0 6px ${color}88; | |
| "></div>`, | |
| className: '', | |
| iconSize: [10, 10], | |
| iconAnchor: [5, 5], | |
| }); | |
| } | |
| // ββ Chargement des gares βββββββββββββββββββββββββββββββββ | |
| async function loadStops() { | |
| clearTimeout(loadTimeout); | |
| loadTimeout = setTimeout(async () => { | |
| const center = map.getCenter(); | |
| const zoom = map.getZoom(); | |
| const radius = zoom < 7 ? 300 : zoom < 9 ? 150 : zoom < 11 ? 80 : 40; | |
| status.textContent = 'Chargementβ¦'; | |
| try { | |
| const res = await fetch( | |
| `/api/map/stops?lat=${center.lat.toFixed(4)}&lon=${center.lng.toFixed(4)}&radius_km=${radius}` | |
| ); | |
| const stops = await res.json(); | |
| markersLayer.clearLayers(); | |
| stops.forEach(s => { | |
| if (!s.stop_lat || !s.stop_lon) return; | |
| const color = stopColor(s.stop_id, s.stop_name); | |
| const marker = L.marker([s.stop_lat, s.stop_lon], { icon: makeIcon(color) }); | |
| const depUrl = `/departures?stop_id=${encodeURIComponent(s.stop_id)}`; | |
| marker.bindPopup(` | |
| <div class="popup-name">${s.stop_name}</div> | |
| <div class="popup-id">${s.stop_id}</div> | |
| <a class="popup-link" href="${depUrl}">Voir les dΓ©parts β</a> | |
| `, { maxWidth: 260 }); | |
| markersLayer.addLayer(marker); | |
| }); | |
| status.textContent = `${stops.length} arrΓͺts affichΓ©s`; | |
| } catch(e) { | |
| status.textContent = 'Erreur de chargement'; | |
| console.error(e); | |
| } | |
| }, 400); | |
| } | |
| map.on('moveend', loadStops); | |
| map.on('zoomend', loadStops); | |
| loadStops(); | |
| // ββ Boutons ββββββββββββββββββββββββββββββββββββββββββββββ | |
| document.getElementById('btn-france').addEventListener('click', () => { | |
| map.setView([46.8, 2.4], 6); | |
| }); | |
| document.getElementById('btn-locate').addEventListener('click', () => { | |
| if (!navigator.geolocation) { alert('GΓ©olocalisation non disponible'); return; } | |
| navigator.geolocation.getCurrentPosition(pos => { | |
| map.setView([pos.coords.latitude, pos.coords.longitude], 11); | |
| }, () => alert('Position non disponible')); | |
| }); | |
| })(); | |
| </script> | |
| {% endblock %} | |