Skip to content

Commit 5908cbd

Browse files
committed
stacking changes
1 parent 446502b commit 5908cbd

2 files changed

Lines changed: 37 additions & 10 deletions

File tree

frontend/src/components/HUDleftPoints.jsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,18 @@ function LogoBlock() {
243243
const handleBeachClick = (item) => {
244244
// Also trigger map search if the function exists
245245
if (window.handleMapSearch) {
246-
// Use siteName for API points or coordinates for user points
246+
// Get the exact coordinates, ensuring we're using the right property names
247+
const lat = item.lat || item.Latitude;
248+
const lon = item.lng || item.lon || item.Longitude;
249+
250+
// Get a name for the search
247251
const searchIdentifier = item.siteName ||
248-
(item.isUserPoint ? `User Point (${item.lat},${item.lon})` : 'Unknown Point');
249-
window.handleMapSearch(searchIdentifier, item.lat, item.lon);
252+
(item.isUserPoint ? `User Point (${lat},${lon})` : 'Unknown Point');
253+
254+
// ALWAYS force popup to open with true parameter
255+
window.handleMapSearch(searchIdentifier, lat, lon, true);
256+
257+
console.log(`Clicked point: ${searchIdentifier} at ${lat},${lon}`);
250258
}
251259
};
252260

frontend/src/components/MapComponent.jsx

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ export default function MapComponent() {
758758
// }, []);
759759

760760
// Handle beach search by name or coordinates
761-
function handleSearch(selectedName, lat, lon) {
761+
function handleSearch(selectedName, lat, lon, forcePopup = false) {
762762
if (!mapInstanceRef.current) return;
763763

764764
// If direct coordinates are provided, use them
@@ -769,6 +769,16 @@ export default function MapComponent() {
769769
const offsetX = 0;
770770
const targetLatLng = [lat, lon];
771771

772+
// Find the marker that matches these coordinates before animation starts
773+
let targetMarker = null;
774+
markersRef.current.forEach(({marker, lat: markerLat, lon: markerLon}) => {
775+
// Use a larger tolerance for coordinate matching (0.005 is about 500m)
776+
if (Math.abs(markerLat - lat) < 0.005 && Math.abs(markerLon - lon) < 0.005) {
777+
console.log('Found matching marker at', markerLat, markerLon);
778+
targetMarker = marker;
779+
}
780+
});
781+
772782
// Calculate offset points for smooth animation
773783
const currentZoom = map.getZoom();
774784
const pointAtCurrentZoom = map.project(targetLatLng, currentZoom);
@@ -779,12 +789,21 @@ export default function MapComponent() {
779789
map.once('moveend', function() {
780790
// After panning completes, smoothly zoom in
781791
map.once('zoomend', function() {
782-
// Find and open any popup that might be at this location
783-
markersRef.current.forEach(({marker, lat: markerLat, lon: markerLon}) => {
784-
if (Math.abs(markerLat - lat) < 0.0001 && Math.abs(markerLon - lon) < 0.0001) {
785-
marker.openPopup();
786-
}
787-
});
792+
// After zooming completes, open the popup if we found the marker
793+
if (targetMarker && forcePopup) {
794+
setTimeout(() => {
795+
console.log('Opening popup for marker');
796+
targetMarker.openPopup();
797+
}, 400); // Increased delay to ensure map is settled
798+
} else if (forcePopup && !targetMarker) {
799+
console.log('No marker found to open popup for coordinates:', lat, lon);
800+
801+
// If we couldn't find a marker but still want to show something at this location
802+
const popup = L.popup()
803+
.setLatLng([lat, lon])
804+
.setContent(`<div><strong>${selectedName || 'Location'}</strong><br>Coordinates: ${lat.toFixed(5)}, ${lon.toFixed(5)}</div>`)
805+
.openOn(map);
806+
}
788807
});
789808

790809
// Animate zoom with a duration in ms

0 commit comments

Comments
 (0)