import { showNotification } from './99_functions.js'; const csvFileInputEl = document.getElementById('csv-file'); const loadingIndicator = document.getElementById('loading-indicator'); document.getElementById('csv-file').addEventListener('change', function (e) { const file = e.target.files[0]; if (!file) return; // emular loading de carga de archivo csv if (this.files.length > 0) { loadingIndicator.style.display = 'block'; // Simular carga setTimeout(() => { loadingIndicator.style.display = 'none'; // showNotification('Archivo CSV cargado exitosamente', 'success'); }, 500); } // PapaParse convierte el texto del CSV a objetos JSON automáticamente Papa.parse(file, { header: true, // Importante: Usa tus encabezados (Etiqueta_pin, Latitud, etc.) skipEmptyLines: true, dynamicTyping: true, // Convierte lat/lng a números automáticamente complete: function (results) { const data = results.data; if (data.length === 0) { showNotification("El archivo CSV está vacío."); return; } procesarYPintarPines(data); }, error: function (err) { console.error("Error al procesar CSV:", err); showNotification("Hubo un error al leer el archivo.", "error"); } }); }); function procesarYPintarPines(puntos) { // Usaremos esto para centrar el mapa en todos los puntos cargados const bounds = new maplibregl.LngLatBounds(); let puntosValidos = 0; puntos.forEach(punto => { // Extraer datos usando tus encabezados exactos const lat = parseFloat(punto.Latitud); const lng = parseFloat(punto.Longitud); const nombre = punto.Etiqueta_pin || "Sin nombre"; if (!isNaN(lat) && !isNaN(lng)) { // Crear el HTML del Popup con toda tu información const contenido = `
Estado: ${punto.Estado || 'N/A'}
Municipio: ${punto.Municipio || 'N/A'}
Localidad: ${punto.Localidad || 'N/A'}
Nota: ${punto.Comentario || '...'}