appn/map.html
2025-04-16 15:46:43 +02:00

48 lines
No EOL
1.6 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>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<style>
#map {
height: 100vh; /* Full height for the map */
width: 100%; /* Full width for the map */
}
</style>
</head>
<body>
<div id="map"></div>
<script src="https://unpkg.com/leaflet@1.9.4/dist/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>