Compare commits
8 Commits
89c5e1aa6c
...
main
Author | SHA1 | Date | |
---|---|---|---|
5ee053272e | |||
1bb2612de3 | |||
86f81ff009 | |||
9989aebc32 | |||
35fc1cfa25 | |||
692d55858c | |||
59b16e5131 | |||
70545052c2 |
@@ -380,8 +380,8 @@ class _EditEventState extends State<EditEvent>
|
|||||||
|
|
||||||
imgUrl = widget.events!.imgUrl ?? "";
|
imgUrl = widget.events!.imgUrl ?? "";
|
||||||
inputDesc.text = widget.events!.description ?? "";
|
inputDesc.text = widget.events!.description ?? "";
|
||||||
initialTags = List<String>.from(widget.events!.tags as List);
|
initialTags = List<String>.from((widget.events?.tags as List?) ?? []);
|
||||||
initialOrga = List<String>.from(widget.events!.organizers as List);
|
initialOrga = List<String>.from((widget.events?.organizers as List?) ?? []);
|
||||||
}
|
}
|
||||||
|
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
@@ -126,7 +126,7 @@ class _MapboxPagesState extends State<MapboxPages> with ShowAlertDialog {
|
|||||||
setState(() {
|
setState(() {
|
||||||
userPosition = mapbox.Point(
|
userPosition = mapbox.Point(
|
||||||
coordinates:
|
coordinates:
|
||||||
mapbox.Position(position.latitude, position.longitude));
|
mapbox.Position(position.longitude, position.latitude));
|
||||||
isUserPositionInitialized = true;
|
isUserPositionInitialized = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -139,21 +139,72 @@ class _MapboxPagesState extends State<MapboxPages> with ShowAlertDialog {
|
|||||||
Future<void> _fetchRoute(
|
Future<void> _fetchRoute(
|
||||||
mapbox.Point origin, mapbox.Point destination, String mode) async {
|
mapbox.Point origin, mapbox.Point destination, String mode) async {
|
||||||
final url = Uri.parse(
|
final url = Uri.parse(
|
||||||
'https://api.mapbox.com/directions/v5/mapbox/$mode/${origin.coordinates.lng},${origin.coordinates.lat};${destination.coordinates.lng},${destination.coordinates.lat}?geometries=geojson&access_token=${dotenv.env['MAPBOX_ACCESS_TOKEN']}',
|
'https://api.mapbox.com/directions/v5/mapbox/$mode/'
|
||||||
|
'${origin.coordinates.lng},${origin.coordinates.lat};'
|
||||||
|
'${destination.coordinates.lng},${destination.coordinates.lat}'
|
||||||
|
'?geometries=geojson&access_token=${dotenv.env['MAPBOX_ACCESS_TOKEN']}',
|
||||||
);
|
);
|
||||||
|
|
||||||
final response = await http.get(url);
|
final response = await http.get(url);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final data = jsonDecode(response.body);
|
final data = jsonDecode(response.body);
|
||||||
final geometry = data['routes'][0]['geometry']['coordinates'];
|
|
||||||
setState(() {
|
// Vérifie si 'routes' existe et contient au moins 1 élément
|
||||||
routeCoordinates = (geometry as List)
|
if (data['routes'] != null && (data['routes'] as List).isNotEmpty) {
|
||||||
.map<List<double>>((coord) => [coord[0], coord[1]])
|
final geometry = data['routes'][0]['geometry']['coordinates'];
|
||||||
.toList();
|
|
||||||
});
|
setState(() {
|
||||||
|
routeCoordinates = (geometry as List)
|
||||||
|
.map<List<double>>((coord) => [coord[0], coord[1]])
|
||||||
|
.toList();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
debugPrint("⚠️ Aucune route trouvée entre ${origin} et $destination.");
|
||||||
|
// Optionnel : afficher un snackbar/toast à l’utilisateur
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
debugPrint("❌ Erreur API Mapbox: ${response.statusCode}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _zoomToFitRoute(List<List<double>> coordinates) async {
|
||||||
|
if (mapboxMap == null || coordinates.isEmpty) return;
|
||||||
|
|
||||||
|
double minLat = coordinates.first[1];
|
||||||
|
double maxLat = coordinates.first[1];
|
||||||
|
double minLng = coordinates.first[0];
|
||||||
|
double maxLng = coordinates.first[0];
|
||||||
|
|
||||||
|
for (var coord in coordinates) {
|
||||||
|
if (coord[1] < minLat) minLat = coord[1];
|
||||||
|
if (coord[1] > maxLat) maxLat = coord[1];
|
||||||
|
if (coord[0] < minLng) minLng = coord[0];
|
||||||
|
if (coord[0] > maxLng) maxLng = coord[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
final bounds = mapbox.CoordinateBounds(
|
||||||
|
southwest: mapbox.Point(coordinates: mapbox.Position(minLng, minLat)),
|
||||||
|
northeast: mapbox.Point(coordinates: mapbox.Position(maxLng, maxLat)),
|
||||||
|
infiniteBounds: true);
|
||||||
|
|
||||||
|
// Calculer une CameraOptions automatiquement à partir des bounds
|
||||||
|
final cameraOptions = await mapboxMap!.cameraForCoordinateBounds(
|
||||||
|
bounds,
|
||||||
|
mapbox.MbxEdgeInsets(
|
||||||
|
top: 50, left: 50, right: 50, bottom: 50), // marges
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
null,
|
||||||
|
null);
|
||||||
|
|
||||||
|
// Appliquer la caméra avec animation
|
||||||
|
await mapboxMap!.flyTo(
|
||||||
|
cameraOptions,
|
||||||
|
mapbox.MapAnimationOptions(duration: 1000),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _drawRouteAndMarkers() async {
|
Future<void> _drawRouteAndMarkers() async {
|
||||||
if (mapboxMap == null || !isUserPositionInitialized) return;
|
if (mapboxMap == null || !isUserPositionInitialized) return;
|
||||||
|
|
||||||
@@ -180,14 +231,12 @@ class _MapboxPagesState extends State<MapboxPages> with ShowAlertDialog {
|
|||||||
iconSize: 0.4,
|
iconSize: 0.4,
|
||||||
));
|
));
|
||||||
|
|
||||||
// Add event marker
|
// Ajoute directement la flèche rouge à la position de l’événement
|
||||||
final eventIcon = await _loadMarkerImage('images/marker-red.png');
|
final eventIcon = await _loadMarkerImage('images/marker-red.png');
|
||||||
await pointAnnotationManager!.create(mapbox.PointAnnotationOptions(
|
await pointAnnotationManager!.create(mapbox.PointAnnotationOptions(
|
||||||
geometry: mapbox.Point(
|
geometry: mapbox.Point(coordinates: mapbox.Position(longitude, latitude)),
|
||||||
coordinates: mapbox.Position(
|
|
||||||
destination.coordinates.lng, destination.coordinates.lat)),
|
|
||||||
image: eventIcon,
|
image: eventIcon,
|
||||||
iconSize: 0.4,
|
iconSize: 0.2,
|
||||||
));
|
));
|
||||||
|
|
||||||
// Fetch and draw route
|
// Fetch and draw route
|
||||||
@@ -201,6 +250,7 @@ class _MapboxPagesState extends State<MapboxPages> with ShowAlertDialog {
|
|||||||
lineColor: Colors.blue.value,
|
lineColor: Colors.blue.value,
|
||||||
lineWidth: 4.0,
|
lineWidth: 4.0,
|
||||||
));
|
));
|
||||||
|
await _zoomToFitRoute(routeCoordinates);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,15 +266,60 @@ class _MapboxPagesState extends State<MapboxPages> with ShowAlertDialog {
|
|||||||
drawer: MyDrawer(),
|
drawer: MyDrawer(),
|
||||||
body: isLoading
|
body: isLoading
|
||||||
? const Center(child: CircularProgressIndicator())
|
? const Center(child: CircularProgressIndicator())
|
||||||
: mapbox.MapWidget(
|
: Column(
|
||||||
onMapCreated: (controller) {
|
children: [
|
||||||
mapboxMap = controller;
|
Row(
|
||||||
},
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
cameraOptions: mapbox.CameraOptions(
|
children: [
|
||||||
center: mapbox.Point(
|
const Text("Mode : "),
|
||||||
coordinates: mapbox.Position(longitude, latitude)),
|
DropdownButton<String>(
|
||||||
zoom: 14.0,
|
value: selectedMode,
|
||||||
),
|
items: const [
|
||||||
|
DropdownMenuItem(
|
||||||
|
value: 'driving', child: Text("🚗 Voiture")),
|
||||||
|
DropdownMenuItem(
|
||||||
|
value: 'walking', child: Text("🚶 Marche")),
|
||||||
|
DropdownMenuItem(
|
||||||
|
value: 'cycling', child: Text("🚴 Vélo")),
|
||||||
|
],
|
||||||
|
onChanged: (value) {
|
||||||
|
if (value != null) {
|
||||||
|
setState(() {
|
||||||
|
selectedMode = value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: mapbox.MapWidget(
|
||||||
|
onMapCreated: (controller) async {
|
||||||
|
mapboxMap = controller;
|
||||||
|
|
||||||
|
// Crée un manager si nécessaire
|
||||||
|
pointAnnotationManager ??= await mapboxMap!.annotations
|
||||||
|
.createPointAnnotationManager();
|
||||||
|
|
||||||
|
// Ajoute directement la flèche rouge à la position de l’événement
|
||||||
|
final eventIcon =
|
||||||
|
await _loadMarkerImage('images/marker-red.png');
|
||||||
|
await pointAnnotationManager!
|
||||||
|
.create(mapbox.PointAnnotationOptions(
|
||||||
|
geometry: mapbox.Point(
|
||||||
|
coordinates: mapbox.Position(longitude, latitude)),
|
||||||
|
image: eventIcon,
|
||||||
|
iconSize: 0.2,
|
||||||
|
));
|
||||||
|
},
|
||||||
|
cameraOptions: mapbox.CameraOptions(
|
||||||
|
center: mapbox.Point(
|
||||||
|
coordinates: mapbox.Position(longitude, latitude)),
|
||||||
|
zoom: 14.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
onPressed: _drawRouteAndMarkers,
|
onPressed: _drawRouteAndMarkers,
|
||||||
|
Reference in New Issue
Block a user