appn/map.html

53 lines
No EOL
1.9 KiB
HTML

<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Carte avec GeoJSON</title>
<script src="css/tailwind_3.4.16"></script>
<link rel="stylesheet" href="css/styles.css"> <!-- Import the external CSS file -->
<link rel="stylesheet" href="css/leaflet.css" />
</head>
<body class="bg-gray-100 flex flex-col items-center p-6 pt-24">
<nav class="bg-gray-800 text-white w-full p-6 shadow-lg fixed top-0 left-0 z-50">
<div class="container mx-auto flex space-x-8 text-lg font-bold">
<a href="index.html" class="hover:text-gray-300">Home</a>
<a href="map.html" class="hover:text-gray-300">Map</a>
</div>
</nav>
<div id="map" style="height: 100vh; width: 100%"></div>
<script src="css/leaflet.js"></script>
<script>
// Initialize the map
const map = L.map('map').setView([43.5683, 1.4705], 16); // Centered near the polygon
// Add a tile layer (OpenStreetMap)
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
// Fetch GeoJSON data from a file or URL
fetch('map.geojson') // Replace with your GeoJSON file path or URL
.then(response => response.json())
.then(geojsonData => {
// Add GeoJSON data to the map
const geoJsonLayer = L.geoJSON(geojsonData, {
onEachFeature: (feature, layer) => {
// Add a popup to each feature
if (feature.properties && feature.properties.name) {
layer.bindPopup(`<strong>${feature.properties.name}</strong>`);
}
}
}).addTo(map);
// Fit the map to the bounds of the GeoJSON layer
map.fitBounds(geoJsonLayer.getBounds());
})
.catch(error => console.error('Error loading GeoJSON:', error));
</script>
</body>
</html>