From 4e21755dc3fcf27c97574fea12d09e6f17698d25 Mon Sep 17 00:00:00 2001 From: Willian Wang Date: Sat, 27 May 2023 23:05:30 -0300 Subject: [PATCH] Fix accessory location focus --- lib/map/map.dart | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/map/map.dart b/lib/map/map.dart index adcf1e7..9d748c0 100644 --- a/lib/map/map.dart +++ b/lib/map/map.dart @@ -74,7 +74,6 @@ class _AccessoryMapState extends State { var accessories = accessoryRegistry.accessories; if (!accessoryInitialized && accessoryRegistry.initialLoadFinished) { fitToContent(accessories, locationModel.here); - accessoryInitialized = true; } @@ -86,8 +85,11 @@ class _AccessoryMapState extends State { } } - onStyleLoaded() { - _mapController!.addCircles( + updateMarkers(MapboxMapController controller) { + controller.removeCircles(controller.circles); + controller.removeSymbols(controller.symbols); + + controller.addCircles( accessories .where((accessory) => accessory.lastLocation != null) .map((accessory) => CircleOptions( @@ -99,7 +101,7 @@ class _AccessoryMapState extends State { )) .toList(), ); - _mapController!.addSymbols( + controller.addSymbols( accessories .where((accessory) => accessory.lastLocation != null) .map((accessory) => SymbolOptions( @@ -114,14 +116,17 @@ class _AccessoryMapState extends State { )) .toList(), ); - + } + + if (_mapController != null) { + updateMarkers(_mapController!); } return MapboxMap( myLocationEnabled: true, accessToken: const String.fromEnvironment("MAP_SDK_PUBLIC_KEY"), onMapCreated: onMapCreated, - onStyleLoadedCallback: onStyleLoaded, + onStyleLoadedCallback: () => updateMarkers(_mapController!), initialCameraPosition: CameraPosition( target: locationModel.here ?? const LatLng(-23.559389, -46.731839), zoom: 13.0,