Set map coordinates of session as center

This commit is contained in:
Maarten 2024-08-08 13:38:42 +02:00
parent 4536442b3c
commit e3a2251898
3 changed files with 23 additions and 9 deletions

View file

@ -10,14 +10,32 @@ import { Colors } from '@/constants/Colors';
import { useColorScheme } from '@/hooks/useColorScheme';
import List from '@/components/List';
import { Request } from '@/services/request';
import { useToken } from '@/context/AppProvider';
import { useIsFocused } from '@react-navigation/core';
export default function MapScreen() {
const colorScheme = useColorScheme() ?? 'light';
const { token, isLoading } = useToken();
const isFocused = useIsFocused();
const [ types, setTypes ] = useState<any>( [] );
const [ coordinates, setCoordinates ] = useState<any>( [] );
const [ markers, setMarkers ] = useState<any>( [] );
// Load session
useEffect( () => {
if (token) {
Request.post( 'sessions/get', { token: token } ).then( (response) => {
console.log('session', response);
if (response.success) {
const { session } = response;
setCoordinates([session.coordinates.longitude, session.coordinates.latitude]);
}
} )
}
}, [isFocused]);
// Load markers and types
useEffect( () => {
Mapbox.setTelemetryEnabled( false );
@ -91,7 +109,7 @@ export default function MapScreen() {
attributionEnabled={false}
>
<Camera
centerCoordinate={[ 5.630960, 52.043420 ]}
centerCoordinate={coordinates.length == 2 ? coordinates : undefined}
zoomLevel={13}
animationMode={'none'}
/>