mapa-cobertura/static/js/index/99_functions.js

115 lines
3.3 KiB
JavaScript

let dic_edos = {
'01': 'Aguascalientes',
'02': 'Baja California',
'03': 'Baja California Sur',
'04': 'Campeche',
'05': 'Coahuila',
'06': 'Colima',
'07': 'Chiapas',
'08': 'Chihuahua',
'09': 'Ciudad de México',
'10': 'Durango',
'11': 'Guanajuato',
'12': 'Guerrero',
'13': 'Hidalgo',
'14': 'Jalisco',
'15': 'Estado de México',
'16': 'Michoacán',
'17': 'Morelos',
'18': 'Nayarit',
'19': 'Nuevo León',
'20': 'Oaxaca',
'21': 'Puebla',
'22': 'Querétaro',
'23': 'Quintana Roo',
'24': 'San Luis Potosí',
'25': 'Sinaloa',
'26': 'Sonora',
'27': 'Tabasco',
'28': 'Tamaulipas',
'29': 'Tlaxcala',
'30': 'Veracruz',
'31': 'Yucatán',
'32': 'Zacatecas',
}
function showNotification(message, type = 'info', duration = 5000) {
const notificationArea = document.getElementById('notification-area');
const notification = document.createElement('div');
notification.className = `notification ${type}`;
let icon = 'info-circle';
// por default el tipo es info
if (type === 'success') icon = 'check-circle';
if (type === 'error') icon = 'exclamation-circle';
notification.innerHTML = `
<i class="fas fa-${icon}"></i>
<span>${message}</span>
`;
notificationArea.appendChild(notification);
// Eliminar notificación después de la duración
setTimeout(() => {
notification.style.animation = 'slideInRight 0.3s ease reverse';
setTimeout(() => notification.remove(), 300);
}, duration);
}
// function crearPin({ lat, lng, label = "Sin etiqueta", popupHTML = null }) {
// const map = getMap();
// if (!map) return null;
// const popup = new maplibregl.Popup({ offset: 25 }).setHTML(
// popupHTML ||
// `<strong>${label}</strong><br>Lat: ${lat}<br>Lng: ${lng}`
// );
// const marker = new maplibregl.Marker({ color: "#d32f2f" })
// .setLngLat([lng, lat])
// .setPopup(popup)
// .addTo(map);
// allMarkers.push(marker);
// return marker;
// }
// function crearPin({ lat, lng, label = "Sin etiqueta", popupHTML = null }) {
// const map = getMap(); // Asegúrate de que esta función exista y devuelva el objeto map
// if (!map) return null;
// const popup = new maplibregl.Popup({ offset: 25 }).setHTML(
// popupHTML || `<strong>${label}</strong><br>Lat: ${lat}<br>Lng: ${lng}`
// );
// const marker = new maplibregl.Marker({ color: "#d32f2f" })
// .setLngLat([lng, lat])
// .setPopup(popup)
// .addTo(map);
// return marker; // Importante devolverlo para poder guardarlo en el array del otro archivo
// }
// En 99_functions.js (Sugerencia de limpieza)
function crearPin({ lat, lng, label = "Sin etiqueta", popupHTML = null }) {
const map = getMap();
if (!map) return null;
const popup = new maplibregl.Popup({ offset: 25 }).setHTML(
popupHTML || `<strong>${label}</strong><br>Lat: ${lat}<br>Lng: ${lng}`
);
const marker = new maplibregl.Marker({ color: "#d32f2f" })
.setLngLat([lng, lat])
.setPopup(popup)
.addTo(map);
return marker; // <-- Esto es lo que permite que tu allMarkers.push() funcione en el otro archivo
}
export { dic_edos, showNotification, crearPin };