cheit_maps/templates/index.html
2025-04-21 18:33:12 +02:00

82 lines
2.3 KiB
HTML

<!-- backend/templates/index.html -->
<!DOCTYPE html>
<html>
<head>
<title>Orienteering Map Viewer</title>
<meta charset="utf-8" />
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
<style>
#map { height: 100vh; margin: 0; }
.popup-img { width: 250px; cursor: pointer; }
body, html {
font-family: 'Roboto', sans-serif;
margin: 0;
padding: 0;
height: 100%;
}
#map {
height: 100vh;
}
#title-overlay {
font-family: 'Poppins', sans-serif;
position: absolute;
top: 20px;
left: 50%;
transform: translateX(-50%);
background-color: rgba(255, 255, 255, 0.8);
padding: 10px 20px;
border-radius: 12px;
font-size: 24px;
font-weight: bold;
z-index: 1000;
box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
</style>
</head>
<body>
<div id="map"></div>
<div id="title-overlay">Super Cheit Orienteering Maps<img src="/static/face.jog" style="width: 50px;" />
</div>
<div id="map"></div>
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
<script>
const map = L.map('map'); // Initialize without setting center and zoom yet
const flag = L.icon({ iconUrl: '/static/O_Flag_.svg', iconSize: [64, 80] , iconAnchor: [32, 79]})
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; OpenStreetMap contributors'
}).addTo(map);
fetch("/api/maps")
.then(res => res.json())
.then(maps => {
const bounds = [];
maps.forEach(m => {
const latlng = [m.latitude, m.longitude];
bounds.push(latlng);
const marker = L.marker(latlng, {icon: flag}).addTo(map);
const popup = `
<strong>${m.name}</strong><br>
${m.description}<br>
<img class="popup-img" src="${m.thumbnail}" onclick="window.location='/map/${m.id}'" />
`;
marker.bindPopup(popup);
});
if (bounds.length > 0) {
map.fitBounds(bounds, { padding: [50, 50] });
} else {
// Fallback if no maps
map.setView([45, 9], 5); // Default view
}
});
</script>
</body>
</html>