Add auto-center on user location when first acquired
This commit is contained in:
parent
3e5437fb14
commit
45c4ebc602
|
|
@ -96,10 +96,22 @@ export default function RoomPage() {
|
||||||
// Auto-start location sharing when connected
|
// Auto-start location sharing when connected
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isConnected && currentUser && !isSharing) {
|
if (isConnected && currentUser && !isSharing) {
|
||||||
|
console.log('Auto-starting location sharing');
|
||||||
startSharing();
|
startSharing();
|
||||||
}
|
}
|
||||||
}, [isConnected, currentUser, isSharing, startSharing]);
|
}, [isConnected, currentUser, isSharing, startSharing]);
|
||||||
|
|
||||||
|
// Track if we've centered on user's location yet
|
||||||
|
const hasCenteredRef = useRef(false);
|
||||||
|
|
||||||
|
// Log when we get location updates
|
||||||
|
useEffect(() => {
|
||||||
|
if (currentLocation && !hasCenteredRef.current) {
|
||||||
|
console.log('First location acquired:', currentLocation.latitude, currentLocation.longitude);
|
||||||
|
hasCenteredRef.current = true;
|
||||||
|
}
|
||||||
|
}, [currentLocation]);
|
||||||
|
|
||||||
// Update status when app goes to background
|
// Update status when app goes to background
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleVisibility = () => {
|
const handleVisibility = () => {
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ interface MapViewProps {
|
||||||
initialViewport?: MapViewport;
|
initialViewport?: MapViewport;
|
||||||
onParticipantClick?: (participant: Participant) => void;
|
onParticipantClick?: (participant: Participant) => void;
|
||||||
onMapClick?: (lngLat: { lng: number; lat: number }) => void;
|
onMapClick?: (lngLat: { lng: number; lat: number }) => void;
|
||||||
|
/** Auto-center on current user's location when first available */
|
||||||
|
autoCenterOnUser?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default to Hamburg CCH area for CCC events
|
// Default to Hamburg CCH area for CCC events
|
||||||
|
|
@ -26,11 +28,13 @@ export default function MapView({
|
||||||
initialViewport = DEFAULT_VIEWPORT,
|
initialViewport = DEFAULT_VIEWPORT,
|
||||||
onParticipantClick,
|
onParticipantClick,
|
||||||
onMapClick,
|
onMapClick,
|
||||||
|
autoCenterOnUser = true,
|
||||||
}: MapViewProps) {
|
}: MapViewProps) {
|
||||||
const mapContainer = useRef<HTMLDivElement>(null);
|
const mapContainer = useRef<HTMLDivElement>(null);
|
||||||
const map = useRef<maplibregl.Map | null>(null);
|
const map = useRef<maplibregl.Map | null>(null);
|
||||||
const markersRef = useRef<Map<string, maplibregl.Marker>>(new Map());
|
const markersRef = useRef<Map<string, maplibregl.Marker>>(new Map());
|
||||||
const [mapLoaded, setMapLoaded] = useState(false);
|
const [mapLoaded, setMapLoaded] = useState(false);
|
||||||
|
const hasCenteredOnUserRef = useRef(false);
|
||||||
|
|
||||||
// Initialize map
|
// Initialize map
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -153,7 +157,20 @@ export default function MapView({
|
||||||
// Add accuracy circle if available
|
// Add accuracy circle if available
|
||||||
// TODO: Implement accuracy circles as a layer
|
// TODO: Implement accuracy circles as a layer
|
||||||
});
|
});
|
||||||
}, [participants, mapLoaded, currentUserId, onParticipantClick]);
|
|
||||||
|
// Auto-center on current user's first location
|
||||||
|
if (autoCenterOnUser && !hasCenteredOnUserRef.current && currentUserId) {
|
||||||
|
const currentUser = participants.find(p => p.id === currentUserId);
|
||||||
|
if (currentUser?.location && map.current) {
|
||||||
|
console.log('Auto-centering on user location:', currentUser.location.latitude, currentUser.location.longitude);
|
||||||
|
map.current.flyTo({
|
||||||
|
center: [currentUser.location.longitude, currentUser.location.latitude],
|
||||||
|
zoom: 16,
|
||||||
|
});
|
||||||
|
hasCenteredOnUserRef.current = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [participants, mapLoaded, currentUserId, onParticipantClick, autoCenterOnUser]);
|
||||||
|
|
||||||
// Fit bounds to show all participants
|
// Fit bounds to show all participants
|
||||||
const fitToParticipants = () => {
|
const fitToParticipants = () => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue