From ac01d925ca9ca20f83bbd6628cd9d336756db58b Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 6 Jul 2025 00:58:46 -0600 Subject: [PATCH] okay got to a much more stable state. Fixed race condtion at stat of files. Should be smooth salining for a bit now. --- map/README.md | 6 +++ map/app/public/css/style.css | 15 +++++++ map/app/public/js/map.js | 82 +++++++++++++++++++++++++++--------- 3 files changed, 84 insertions(+), 19 deletions(-) diff --git a/map/README.md b/map/README.md index 5808a4a..3696f6d 100644 --- a/map/README.md +++ b/map/README.md @@ -236,3 +236,9 @@ For issues or questions: 1. Check the troubleshooting section 2. Review NocoDB documentation 3. Open an issue on GitHub + +# Known Bugs + +- First load of page often fails, need to debug +- want ui for dots tohave a edit button that then brings up the form. +- \ No newline at end of file diff --git a/map/app/public/css/style.css b/map/app/public/css/style.css index 7261a2d..4ce8269 100644 --- a/map/app/public/css/style.css +++ b/map/app/public/css/style.css @@ -549,6 +549,21 @@ body { border-top: 1px solid #eee; } +/* Popup actions section */ +.popup-content .popup-actions { + margin-top: 15px; + padding-top: 15px; + border-top: 1px solid #eee; + display: flex; + gap: 10px; + justify-content: center; +} + +.popup-content .popup-actions .btn { + flex: 1; + max-width: 120px; +} + /* Distinctive start location marker styles */ .start-location-custom-marker { z-index: 2000 !important; diff --git a/map/app/public/js/map.js b/map/app/public/js/map.js index 60248b2..3d46a1e 100644 --- a/map/app/public/js/map.js +++ b/map/app/public/js/map.js @@ -20,14 +20,29 @@ let startLocationMarker = null; let isStartLocationVisible = true; // Initialize the application -document.addEventListener('DOMContentLoaded', () => { +document.addEventListener('DOMContentLoaded', async () => { console.log('DOM loaded, initializing application...'); - checkAuth(); - initializeMap(); - loadLocations(); - setupEventListeners(); - setupAutoRefresh(); - hideLoading(); + + try { + // First check authentication + await checkAuth(); + + // Then initialize the map + await initializeMap(); + + // Only load locations after map is ready + await loadLocations(); + + // Setup other features + setupEventListeners(); + setupAutoRefresh(); + + } catch (error) { + console.error('Initialization error:', error); + showStatus('Failed to initialize application', 'error'); + } finally { + hideLoading(); + } }); // Check authentication @@ -38,7 +53,8 @@ async function checkAuth() { if (!data.authenticated) { window.location.href = '/login.html'; - return; + // Throw error to stop further initialization + throw new Error('Not authenticated'); } currentUser = data.user; @@ -47,6 +63,8 @@ async function checkAuth() { } catch (error) { console.error('Auth check failed:', error); window.location.href = '/login.html'; + // Re-throw to stop initialization chain + throw error; } } @@ -184,14 +202,20 @@ async function loadLocations() { // Display locations on the map function displayLocations(locations) { // Clear existing markers - markers.forEach(marker => map.removeLayer(marker)); + markers.forEach(marker => { + if (marker && map) { + map.removeLayer(marker); + } + }); markers = []; // Add new markers locations.forEach(location => { if (location.latitude && location.longitude) { const marker = createLocationMarker(location); - markers.push(marker); + if (marker) { // Only add if marker was successfully created + markers.push(marker); + } } }); @@ -200,6 +224,12 @@ function displayLocations(locations) { // Create a location marker function createLocationMarker(location) { + // Safety check - ensure map exists + if (!map) { + console.warn('Map not initialized, skipping marker creation'); + return null; + } + const lat = parseFloat(location.latitude); const lng = parseFloat(location.longitude); @@ -228,16 +258,8 @@ function createLocationMarker(location) { const popupContent = createPopupContent(location); marker.bindPopup(popupContent); - // Add click handler for editing - Store location data on marker + // Store location data on marker for later use marker._locationData = location; - marker.on('click', () => { - if (currentUser) { - // Debug: Log the location object to see its structure - console.log('Location clicked:', location); - console.log('Available fields:', Object.keys(location)); - setTimeout(() => openEditForm(location), 100); - } - }); return marker; } @@ -263,6 +285,14 @@ function createPopupContent(location) { + ${currentUser ? ` + + ` : ''} `; } @@ -312,6 +342,20 @@ function setupEventListeners() { // Geo-location field sync setupGeoLocationSync(); + + // Add event delegation for popup edit buttons + document.addEventListener('click', (e) => { + if (e.target.classList.contains('edit-location-popup-btn')) { + e.preventDefault(); + try { + const locationData = JSON.parse(e.target.getAttribute('data-location')); + openEditForm(locationData); + } catch (error) { + console.error('Error parsing location data:', error); + showStatus('Error opening edit form', 'error'); + } + } + }); } // Setup geo-location field synchronization