70 lines
1.7 KiB
TypeScript
70 lines
1.7 KiB
TypeScript
// MapScreen.tsx
|
|
import { ThemedMapView } from '@/components/theme/themed-mapview';
|
|
import React, { useEffect, useState } from 'react';
|
|
import { StyleSheet, View, Dimensions, Image, Text } from 'react-native';
|
|
import MapView, { Marker, Callout, CalloutSubview, PROVIDER_DEFAULT } from 'react-native-maps';
|
|
import { db } from '../../firebase_config';
|
|
import { Chantier } from '@/class/class';
|
|
import { getChantiers } from '@/services/ressourcesService';
|
|
|
|
|
|
const MapScreen = () => {
|
|
|
|
const region = {
|
|
latitude: 48.8566,
|
|
longitude: 2.3522,
|
|
latitudeDelta: 0.05,
|
|
longitudeDelta: 0.05,
|
|
};
|
|
|
|
|
|
const [chantiers, setMarkers] = useState<Chantier[]>([]);
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
useEffect(() => {
|
|
async function loadData() {
|
|
try {
|
|
const data = await getChantiers();
|
|
setMarkers(data);
|
|
} catch (error) {
|
|
console.error("Erreur lors du chargement :", error);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
}
|
|
loadData();
|
|
}, []);
|
|
|
|
return (
|
|
<View style={styles.container}>
|
|
<ThemedMapView
|
|
provider={PROVIDER_DEFAULT} // OpenStreetMap
|
|
style={styles.map}
|
|
region={region}
|
|
>
|
|
{Array.isArray(chantiers) &&
|
|
chantiers.map(chantier => (
|
|
<Marker
|
|
key = {chantier.id}
|
|
coordinate={{ latitude: chantier.latitude, longitude: chantier.longitude }}
|
|
title={chantier.adresse}
|
|
description={chantier.etat}
|
|
/>
|
|
))}
|
|
</ThemedMapView>
|
|
</View>
|
|
);
|
|
};
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
flex: 1,
|
|
},
|
|
map: {
|
|
width: Dimensions.get('window').width,
|
|
height: Dimensions.get('window').height,
|
|
},
|
|
});
|
|
|
|
export default MapScreen;
|