Spaces:
Running
Running
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.
- static/map.html +1 -1
- 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/
|
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 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
headerActions.insertBefore(userInfo, treeCounter);
|
103 |
-
}
|
104 |
}
|
105 |
}
|
106 |
|
107 |
addLogoutButton() {
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
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('
|
299 |
-
panel
|
|
|
|
|
300 |
}
|
301 |
|
302 |
hideInfoPanel() {
|
303 |
-
const panel = document.getElementById('
|
304 |
-
panel
|
|
|
|
|
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 |
|