add zoomfit

This commit is contained in:
2025-09-04 09:04:24 +02:00
parent 692d55858c
commit 35fc1cfa25

View File

@@ -168,6 +168,43 @@ class _MapboxPagesState extends State<MapboxPages> with ShowAlertDialog {
}
}
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 {
if (mapboxMap == null || !isUserPositionInitialized) return;