Skip to content

Commit 446502b

Browse files
committed
fixed the bug where user points are not zoomed in
1 parent a72fd9c commit 446502b

2 files changed

Lines changed: 54 additions & 5 deletions

File tree

frontend/src/components/HUDleftPoints.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,13 @@ function LogoBlock() {
240240
setFilteredList(filteredItems);
241241
};
242242

243-
const handleBeachClick = (name) => {
243+
const handleBeachClick = (item) => {
244244
// Also trigger map search if the function exists
245245
if (window.handleMapSearch) {
246-
window.handleMapSearch(name.siteName);
246+
// Use siteName for API points or coordinates for user points
247+
const searchIdentifier = item.siteName ||
248+
(item.isUserPoint ? `User Point (${item.lat},${item.lon})` : 'Unknown Point');
249+
window.handleMapSearch(searchIdentifier, item.lat, item.lon);
247250
}
248251
};
249252

frontend/src/components/MapComponent.jsx

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,14 +757,60 @@ export default function MapComponent() {
757757
// };
758758
// }, []);
759759

760-
// Handle beach search by name
761-
function handleSearch(selectedName) {
760+
// Handle beach search by name or coordinates
761+
function handleSearch(selectedName, lat, lon) {
762762
if (!mapInstanceRef.current) return;
763-
const term = (selectedName || searchTerm).trim().toLowerCase();
763+
764+
// If direct coordinates are provided, use them
765+
if (lat && lon) {
766+
const map = mapInstanceRef.current;
767+
const targetZoom = 15;
768+
const offsetY = 150;
769+
const offsetX = 0;
770+
const targetLatLng = [lat, lon];
771+
772+
// Calculate offset points for smooth animation
773+
const currentZoom = map.getZoom();
774+
const pointAtCurrentZoom = map.project(targetLatLng, currentZoom);
775+
const offsetPointAtCurrentZoom = pointAtCurrentZoom.subtract([offsetX, offsetY]);
776+
const offsetLatLngAtCurrentZoom = map.unproject(offsetPointAtCurrentZoom, currentZoom);
777+
778+
// First just pan to the location at the current zoom level
779+
map.once('moveend', function() {
780+
// After panning completes, smoothly zoom in
781+
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+
});
788+
});
789+
790+
// Animate zoom with a duration in ms
791+
map.flyTo(targetLatLng, targetZoom, {
792+
duration: 0.5, // seconds
793+
easeLinearity: 0.2
794+
});
795+
});
796+
797+
// Start the sequence by panning
798+
map.panTo(offsetLatLngAtCurrentZoom, {
799+
animate: true,
800+
duration: 0.75 // seconds
801+
});
802+
803+
return;
804+
}
805+
806+
// Otherwise continue with name-based search
807+
const term = selectedName ? selectedName.trim().toLowerCase() : '';
764808
if (!term) return;
809+
765810
const match = markersRef.current.find(item =>
766811
item.name.toLowerCase().includes(term)
767812
);
813+
768814
if (match) {
769815
const map = mapInstanceRef.current;
770816
const currentZoom = map.getZoom();

0 commit comments

Comments
 (0)