`;
const outputDiv = document.getElementById('airport-details-output');
outputDiv.innerHTML = detailsHTML;
outputDiv.style.display = 'block';
document.getElementById('airport-pdf-container').style.display = 'flex';
// Initialize or update map
if (map) {
map.remove(); // Remove previous map instance to avoid conflicts
}
map = L.map('airport-map').setView([data.latitude, data.longitude], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
L.marker([data.latitude, data.longitude]).addTo(map)
.bindPopup(`
${data.name}`).openPopup();
// This is crucial for maps in initially hidden divs
setTimeout(() => map.invalidateSize(), 10);
}
window.downloadAirportPDF = function() {
const dashboard = document.getElementById('airport-details-output');
html2canvas(dashboard, { scale: 2 }).then(canvas => {
const pdf = new jsPDF({ orientation: 'landscape', unit: 'pt', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const margin = 40;
const imgWidth = pdfWidth - (margin * 2);
const imgHeight = (canvas.height * imgWidth) / canvas.width;
pdf.addImage(canvas.toDataURL('image/png'), 'PNG', margin, margin, imgWidth, imgHeight);
pdf.save(`${document.getElementById('airport-search-input').value || 'CCU'}_Airport_Details.pdf`);
});
}
initialize();
});