2024-12-06 20:49:28 +00:00
|
|
|
import { StyleSheet } from 'react-native'
|
2024-12-02 19:11:31 +00:00
|
|
|
import MapLibreGL, { Camera, FillLayer, LineLayer, MapView, PointAnnotation, RasterLayer, RasterSource, ShapeSource, UserLocation } from '@maplibre/maplibre-react-native'
|
|
|
|
import { FontAwesome5 } from '@expo/vector-icons'
|
|
|
|
import { circle } from '@turf/circle'
|
2024-12-11 00:30:21 +00:00
|
|
|
import { useLastOwnLocation } from '@/hooks/useLocation'
|
2024-12-02 19:11:31 +00:00
|
|
|
|
2024-12-06 20:49:28 +00:00
|
|
|
export default function Map() {
|
2024-12-11 00:30:21 +00:00
|
|
|
const userLocation = useLastOwnLocation()
|
2024-12-02 19:11:31 +00:00
|
|
|
MapLibreGL.setAccessToken(null)
|
2024-12-06 20:49:28 +00:00
|
|
|
const accuracyCircle = circle([userLocation?.coords.longitude ?? 0, userLocation?.coords.latitude ?? 0], userLocation?.coords.accuracy ?? 0, {steps: 64, units: 'meters'})
|
2024-12-02 19:11:31 +00:00
|
|
|
return (
|
|
|
|
<MapView
|
2024-12-09 17:29:48 +00:00
|
|
|
logoEnabled={false}
|
2024-12-02 19:11:31 +00:00
|
|
|
style={styles.map}
|
|
|
|
styleURL="https://openmaptiles.geo.data.gouv.fr/styles/osm-bright/style.json">
|
|
|
|
{/* FIXME Il faudra pouvoir avoir un bouton de suivi pour activer le suivi de la caméro */}
|
2024-12-06 20:49:28 +00:00
|
|
|
{userLocation && <Camera
|
|
|
|
defaultSettings={{centerCoordinate: [userLocation?.coords.longitude, userLocation?.coords.latitude], zoomLevel: 15}} />}
|
2024-12-02 19:11:31 +00:00
|
|
|
<RasterSource id="railwaymap-source" tileUrlTemplates={["https://a.tiles.openrailwaymap.org/standard/{z}/{x}/{y}.png"]}></RasterSource>
|
|
|
|
<RasterLayer id="railwaymap-layer" sourceID="railwaymap-source" style={{rasterOpacity: 0.7}} />
|
|
|
|
|
|
|
|
{/* FIXME Il faudra avoir uniquement les positions des autres personnes, puisque sa propre position peut être obtenue nativement */}
|
|
|
|
<ShapeSource id="accuracy-radius" shape={accuracyCircle} />
|
|
|
|
<FillLayer id="accuracy-radius-fill" sourceID="accuracy-radius" style={{fillOpacity: 0.4, fillColor: 'lightblue'}} aboveLayerID="railwaymap-layer" />
|
|
|
|
<LineLayer id="accuracy-radius-border" sourceID="accuracy-radius" style={{lineOpacity: 0.4, lineColor: 'blue'}} aboveLayerID="accuracy-radius-fill" />
|
2024-12-06 20:49:28 +00:00
|
|
|
<PointAnnotation id="current-location" coordinate={[userLocation?.coords.longitude ?? 2.9, userLocation?.coords.latitude ?? 46.5]}>
|
2024-12-02 19:11:31 +00:00
|
|
|
<FontAwesome5 name="map-marker-alt" size={24} color="blue" />
|
|
|
|
</PointAnnotation>
|
|
|
|
{/* <UserLocation animated={true} renderMode="native" androidRenderMode="compass" showsUserHeadingIndicator={true} /> */}
|
|
|
|
</MapView>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
map: {
|
|
|
|
flex: 1,
|
|
|
|
alignSelf: 'stretch',
|
|
|
|
}
|
|
|
|
})
|