20 lines
639 B
JavaScript

// Inicializamos el mapa en una posición central (Ej: Madrid)
var mapa = L.map("mapa").setView([40.4168, -3.7038], 3);
// Cargar OpenStreetMap como fondo del mapa
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution: "© OpenStreetMap contributors"
}).addTo(mapa);
// Pintar chincheta de los destinos que me devuelve mapa.php
fetch("/mapa.php")
.then(response => response.json())
.then(destinos => {
destinos.forEach(destino => {
L.marker([destino.lat, destino.lng])
.addTo(mapa)
.bindPopup(`<b>${destino.nombre}</b>`);
});
});