re-zoom ok
This commit is contained in:
parent
af65dc1cb0
commit
7f5d59857c
@ -260,12 +260,42 @@ class _MapboxPagesState extends State<MapboxPages> with ShowErrorDialog {
|
||||
lineOpacity: 0.8,
|
||||
),
|
||||
);
|
||||
_zoomToFitRoute(routeCoordinates);
|
||||
}
|
||||
} else {
|
||||
showErrorDialog(context, "Invalid coordinates or user position.");
|
||||
}
|
||||
}
|
||||
|
||||
void _zoomToFitRoute(List<LatLng> coordinates) {
|
||||
// Calculate the bounding box
|
||||
double minLat = coordinates.first.latitude;
|
||||
double maxLat = coordinates.first.latitude;
|
||||
double minLng = coordinates.first.longitude;
|
||||
double maxLng = coordinates.first.longitude;
|
||||
|
||||
for (LatLng coord in coordinates) {
|
||||
if (coord.latitude < minLat) minLat = coord.latitude;
|
||||
if (coord.latitude > maxLat) maxLat = coord.latitude;
|
||||
if (coord.longitude < minLng) minLng = coord.longitude;
|
||||
if (coord.longitude > maxLng) maxLng = coord.longitude;
|
||||
}
|
||||
|
||||
// Define the bounds
|
||||
LatLng southwest = LatLng(minLat, minLng);
|
||||
LatLng northeast = LatLng(maxLat, maxLng);
|
||||
|
||||
mapController.moveCamera(
|
||||
CameraUpdate.newLatLngBounds(
|
||||
LatLngBounds(southwest: southwest, northeast: northeast),
|
||||
left: 50, // Padding on the left
|
||||
top: 50, // Padding on the top
|
||||
right: 50, // Padding on the right
|
||||
bottom: 50, // Padding on the bottom
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Load image from assets
|
||||
Future<Uint8List> _loadMarkerImage(String assetPath) async {
|
||||
final ByteData data = await rootBundle.load(assetPath);
|
||||
|
Loading…
x
Reference in New Issue
Block a user