From c8223d9b7df57199434b33444a52aab854af42b6 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 17 Nov 2024 11:31:07 +0100 Subject: [PATCH] remove line after change --- covas_mobile/lib/pages/MapboxPages.dart | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/covas_mobile/lib/pages/MapboxPages.dart b/covas_mobile/lib/pages/MapboxPages.dart index 1c5e2bc..0cda564 100644 --- a/covas_mobile/lib/pages/MapboxPages.dart +++ b/covas_mobile/lib/pages/MapboxPages.dart @@ -52,6 +52,7 @@ class _MapboxPagesState extends State with ShowErrorDialog { bool isLoading = true; late LatLng userPosition; bool isUserPositionInitialized = false; + Line? currentRouteLine; @override void initState() { @@ -223,6 +224,11 @@ class _MapboxPagesState extends State with ShowErrorDialog { } Future _drawRouteAndMarkers() async { + // Remove previous route line if it exists + if (currentRouteLine != null) { + await mapController.removeLine(currentRouteLine!); + currentRouteLine = null; + } if (!isUserPositionInitialized) { showErrorDialog( context, "User position is not yet initialized. Try again."); @@ -249,10 +255,10 @@ class _MapboxPagesState extends State with ShowErrorDialog { )); // Fetch and draw route - await _fetchRoute(userPosition!, destination, selectedMode); + await _fetchRoute(userPosition, destination, selectedMode); if (routeCoordinates.isNotEmpty) { - await mapController.addLine( + currentRouteLine = await mapController.addLine( LineOptions( geometry: routeCoordinates, lineColor: '#3b9ddd', @@ -260,6 +266,7 @@ class _MapboxPagesState extends State with ShowErrorDialog { lineOpacity: 0.8, ), ); + _zoomToFitRoute(routeCoordinates); } } else {