RoyAalekh commited on
Commit
ee992c9
·
1 Parent(s): 6e18a26

fix: Resolve map page issues with JavaScript loading, user info display, and tree count

Browse files

- Fixed 404 error by correcting JavaScript file reference from map_enhanced.js to map.js
- Updated displayUserInfo() method to populate existing HTML elements instead of creating new ones
- Fixed logout button functionality by using existing button instead of duplicating
- Corrected location panel references from 'infoPanel' to 'locationPanel'
- Added missing centerMapToTrees() method for center map button functionality
- Improved error handling and user feedback throughout map functionality
- Ensured proper tree count display and user authentication state management

These changes resolve the map loading issues, user info display problems, and tree count discrepancies.

Files changed (2) hide show
  1. static/map.html +1 -1
  2. static/map.js +47 -29
static/map.html CHANGED
@@ -795,6 +795,6 @@
795
 
796
  <!-- Leaflet JS -->
797
  <script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
798
- <script src="/static/map_enhanced.js?v=4.0.0&t=1754657582"></script>
799
  </body>
800
  </html>
 
795
 
796
  <!-- Leaflet JS -->
797
  <script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
798
+ <script src="/static/map.js?v=4.0.0&t=1754657582"></script>
799
  </body>
800
  </html>
static/map.js CHANGED
@@ -84,35 +84,29 @@ class TreeTrackMap {
84
  displayUserInfo() {
85
  if (!this.currentUser) return;
86
 
87
- const headerActions = document.querySelector('.header-actions');
88
- if (headerActions) {
89
- // Create user info display
90
- const userInfo = document.createElement('div');
91
- userInfo.className = 'user-info-map';
92
- userInfo.innerHTML = `
93
- <div style="color: white; text-align: center; margin-right: 1rem; font-size: 0.875rem;">
94
- <div>${this.currentUser.full_name}</div>
95
- <div style="opacity: 0.8; font-size: 0.75rem;">${this.currentUser.role}</div>
96
- </div>
97
- `;
98
-
99
- // Insert before the tree counter
100
- const treeCounter = headerActions.querySelector('.tree-counter');
101
- if (treeCounter) {
102
- headerActions.insertBefore(userInfo, treeCounter);
103
- }
104
  }
105
  }
106
 
107
  addLogoutButton() {
108
- const headerActions = document.querySelector('.header-actions');
109
- if (headerActions) {
110
- const logoutBtn = document.createElement('button');
111
- logoutBtn.className = 'btn btn-secondary';
112
- logoutBtn.innerHTML = '🚪 Logout';
113
- logoutBtn.style.marginLeft = '0.5rem';
114
- logoutBtn.addEventListener('click', () => this.logout());
115
- headerActions.appendChild(logoutBtn);
116
  }
117
  }
118
 
@@ -236,6 +230,14 @@ class TreeTrackMap {
236
  this.clearTempMarker();
237
  });
238
 
 
 
 
 
 
 
 
 
239
  // Use Location button
240
  document.getElementById('useLocationBtn').addEventListener('click', () => {
241
  this.useSelectedLocation();
@@ -295,13 +297,17 @@ class TreeTrackMap {
295
  }
296
 
297
  showInfoPanel() {
298
- const panel = document.getElementById('infoPanel');
299
- panel.classList.add('active');
 
 
300
  }
301
 
302
  hideInfoPanel() {
303
- const panel = document.getElementById('infoPanel');
304
- panel.classList.remove('active');
 
 
305
  }
306
 
307
  useSelectedLocation() {
@@ -328,6 +334,18 @@ class TreeTrackMap {
328
  this.showMessage('Selection cancelled', 'success');
329
  }
330
 
 
 
 
 
 
 
 
 
 
 
 
 
331
  getCurrentLocation() {
332
  console.log('Getting current location...');
333
 
 
84
  displayUserInfo() {
85
  if (!this.currentUser) return;
86
 
87
+ // Update existing user info elements in the HTML
88
+ const userAvatar = document.getElementById('userAvatar');
89
+ const userName = document.getElementById('userName');
90
+ const userRole = document.getElementById('userRole');
91
+
92
+ if (userAvatar && this.currentUser.full_name) {
93
+ userAvatar.textContent = this.currentUser.full_name.charAt(0).toUpperCase();
94
+ }
95
+
96
+ if (userName) {
97
+ userName.textContent = this.currentUser.full_name || this.currentUser.username || 'User';
98
+ }
99
+
100
+ if (userRole) {
101
+ userRole.textContent = this.currentUser.role || 'User';
 
 
102
  }
103
  }
104
 
105
  addLogoutButton() {
106
+ // Use existing logout button instead of creating a new one
107
+ const existingLogoutBtn = document.getElementById('logoutBtn');
108
+ if (existingLogoutBtn) {
109
+ existingLogoutBtn.addEventListener('click', () => this.logout());
 
 
 
 
110
  }
111
  }
112
 
 
230
  this.clearTempMarker();
231
  });
232
 
233
+ // Center Map button
234
+ const centerMapBtn = document.getElementById('centerMapBtn');
235
+ if (centerMapBtn) {
236
+ centerMapBtn.addEventListener('click', () => {
237
+ this.centerMapToTrees();
238
+ });
239
+ }
240
+
241
  // Use Location button
242
  document.getElementById('useLocationBtn').addEventListener('click', () => {
243
  this.useSelectedLocation();
 
297
  }
298
 
299
  showInfoPanel() {
300
+ const panel = document.getElementById('locationPanel');
301
+ if (panel) {
302
+ panel.classList.add('active');
303
+ }
304
  }
305
 
306
  hideInfoPanel() {
307
+ const panel = document.getElementById('locationPanel');
308
+ if (panel) {
309
+ panel.classList.remove('active');
310
+ }
311
  }
312
 
313
  useSelectedLocation() {
 
334
  this.showMessage('Selection cancelled', 'success');
335
  }
336
 
337
+ centerMapToTrees() {
338
+ if (this.treeMarkers.length === 0) {
339
+ this.showMessage('No trees to center on', 'info');
340
+ return;
341
+ }
342
+
343
+ // Fit map to show all trees
344
+ const group = new L.featureGroup(this.treeMarkers);
345
+ this.map.fitBounds(group.getBounds().pad(0.1));
346
+ this.showMessage('Centered map on all trees', 'success');
347
+ }
348
+
349
  getCurrentLocation() {
350
  console.log('Getting current location...');
351