Set map coordinates of session as center
This commit is contained in:
parent
4536442b3c
commit
e3a2251898
3 changed files with 23 additions and 9 deletions
|
@ -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'}
|
||||
/>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue