River Mountain Locator
River Locator
Units:
Search for a river to see details here.
Mountain Locator
Units:
Search for a mountain to see details here.
Mouth: ${river.mouth}
Notable Cities: ${river.notableCities.join(', ')}
`; resultsDiv.appendChild(itemDiv); }); } function rlm_searchMountains(searchTermOverride, clearPrevious = true) { const input = searchTermOverride !== undefined ? searchTermOverride : document.getElementById('mountainSearchInput').value.toLowerCase(); const resultsDiv = document.getElementById('mountainResults'); if (clearPrevious) resultsDiv.innerHTML = ''; const filteredMountains = rlm_mountainsData.filter(mountain => mountain.name.toLowerCase().includes(input)); if (filteredMountains.length === 0) { resultsDiv.innerHTML = 'No mountains found matching your search criteria.
'; return; } filteredMountains.forEach(mountain => { const elevation = rlm_currentMountainUnit === 'metric' ? `${mountain.elevation_m} m` : `${mountain.elevation_ft} ft`; const itemDiv = document.createElement('div'); itemDiv.className = 'rlm-result-item'; itemDiv.innerHTML = `${mountain.name}
Elevation: ${elevation}
Range: ${mountain.range}
Location: ${mountain.location.join(', ')}
Prominence: ${mountain.prominence}
First Ascent: ${mountain.firstAscent}
`; resultsDiv.appendChild(itemDiv); }); } // Call rlm_openTab on load to set initial state and rlm_currentTabIndex document.addEventListener('DOMContentLoaded', function() { // Ensure the first tab's button exists before trying to click it or simulate a click const firstTabButton = document.querySelector("#riverMountainLocatorApp .rlm-tab-button"); if (firstTabButton) { // Simulate a click event object for rlm_openTab const initialEvent = { currentTarget: firstTabButton }; rlm_openTab(initialEvent, 'riverLocatorTab'); } // Attach listeners to search inputs for 'Enter' key press document.getElementById('riverSearchInput').addEventListener('keypress', function(e) { if (e.key === 'Enter') { rlm_searchRivers(); } }); document.getElementById('mountainSearchInput').addEventListener('keypress', function(e) { if (e.key === 'Enter') { rlm_searchMountains(); } }); }); // PDF Download Logic function rlm_downloadPdf() { const { jsPDF } = window.jspdf; const doc = new jsPDF(); let activeTabContent, title, dataToExport = [], headers = [], body = []; let fileName = "locator_results.pdf"; // Define PDF styles based on the tool's theme const headerColor = '#2c3e50'; // Midnight Blue const textColor = '#333333'; const highlightColor = '#3498db'; // Peter River Blue doc.setFont('helvetica', 'bold'); doc.setTextColor(headerColor); if (document.getElementById('riverLocatorTab').style.display === 'block') { activeTabContent = document.getElementById('riverResults'); title = "River Search Results"; fileName = "river_locator_results.pdf"; doc.text(title, 14, 20); const riverItems = activeTabContent.querySelectorAll('.rlm-result-item'); if (riverItems.length === 0 || activeTabContent.querySelector('p').textContent.startsWith("Search for a river")) { doc.setFont('helvetica', 'normal'); doc.setTextColor(textColor); doc.text("No river results to download.", 14, 30); doc.save(fileName); return; } headers = [["Name", "Length", "Countries", "Source", "Mouth", "Notable Cities"]]; body = Array.from(riverItems).map(item => { const name = item.querySelector('h3').textContent; // Extract data carefully, handling potential nulls if structure varies const length = item.querySelector('p:nth-of-type(1)').textContent.replace('Length: ', ''); const countries = item.querySelector('p:nth-of-type(2)').textContent.replace('Countries: ', ''); const source = item.querySelector('p:nth-of-type(3)').textContent.replace('Source: ', ''); const mouth = item.querySelector('p:nth-of-type(4)').textContent.replace('Mouth: ', ''); const cities = item.querySelector('p:nth-of-type(5)').textContent.replace('Notable Cities: ', ''); return [name, length, countries, source, mouth, cities]; }); } else if (document.getElementById('mountainLocatorTab').style.display === 'block') { activeTabContent = document.getElementById('mountainResults'); title = "Mountain Search Results"; fileName = "mountain_locator_results.pdf"; doc.text(title, 14, 20); const mountainItems = activeTabContent.querySelectorAll('.rlm-result-item'); if (mountainItems.length === 0 || activeTabContent.querySelector('p').textContent.startsWith("Search for a mountain")) { doc.setFont('helvetica', 'normal'); doc.setTextColor(textColor); doc.text("No mountain results to download.", 14, 30); doc.save(fileName); return; } headers = [["Name", "Elevation", "Range", "Location", "Prominence", "First Ascent"]]; body = Array.from(mountainItems).map(item => { const name = item.querySelector('h3').textContent; const elevation = item.querySelector('p:nth-of-type(1)').textContent.replace('Elevation: ', ''); const range = item.querySelector('p:nth-of-type(2)').textContent.replace('Range: ', ''); const location = item.querySelector('p:nth-of-type(3)').textContent.replace('Location: ', ''); const prominence = item.querySelector('p:nth-of-type(4)').textContent.replace('Prominence: ', ''); const ascent = item.querySelector('p:nth-of-type(5)').textContent.replace('First Ascent: ', ''); return [name, elevation, range, location, prominence, ascent]; }); } else { alert("No active tab found or no results to export."); return; } if (body.length > 0) { doc.autoTable({ head: headers, body: body, startY: 25, theme: 'grid', // 'striped', 'grid', 'plain' headStyles: { fillColor: headerColor, // Midnight Blue textColor: '#ffffff' // White }, styles: { font: 'helvetica', fontSize: 9, cellPadding: 2.5, textColor: textColor, }, alternateRowStyles: { fillColor: '#f5f5f5' // Light grey for alternate rows }, didDrawPage: function (data) { // Footer for PDF (Optional: Page numbers) // doc.setFontSize(10); // doc.text('Page ' + doc.internal.getNumberOfPages(), data.settings.margin.left, doc.internal.pageSize.height - 10); } }); } else { // This case is now handled earlier for more specific messages doc.setFont('helvetica', 'normal'); doc.setTextColor(textColor); doc.text("No results to export from the active tab.", 14, 30); } doc.save(fileName); }