From 2947fea8c43cf944431ff641966e6886d7b78432 Mon Sep 17 00:00:00 2001 From: m0nac0 <58807793+m0nac0@users.noreply.github.com> Date: Mon, 20 Jul 2020 14:25:59 +0200 Subject: [PATCH] web: ignore myLocationTrackingMode if myLocationEnabled is false --- lib/src/mapbox_map.dart | 3 ++- mapbox_gl_web/lib/src/convert.dart | 1 + mapbox_gl_web/lib/src/mapbox_map_controller.dart | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/src/mapbox_map.dart b/lib/src/mapbox_map.dart index 1a765a848..fc2c8f9e7 100644 --- a/lib/src/mapbox_map.dart +++ b/lib/src/mapbox_map.dart @@ -114,7 +114,8 @@ class MapboxMap extends StatefulWidget { /// when the map tries to turn on the My Location layer. final bool myLocationEnabled; - /// The mode used to let the map's camera follow the device's physical location + /// The mode used to let the map's camera follow the device's physical location. + /// `myLocationEnabled` needs to be true for values other than `MyLocationTrackingMode.None` to work. final MyLocationTrackingMode myLocationTrackingMode; /// The mode to render the user location symbol diff --git a/mapbox_gl_web/lib/src/convert.dart b/mapbox_gl_web/lib/src/convert.dart index 376cdb1a0..838d850e7 100644 --- a/mapbox_gl_web/lib/src/convert.dart +++ b/mapbox_gl_web/lib/src/convert.dart @@ -45,6 +45,7 @@ class Convert { sink.setMyLocationEnabled(options['myLocationEnabled']); } if (options.containsKey('myLocationTrackingMode')) { + //Should not be invoked before sink.setMyLocationEnabled() sink.setMyLocationTrackingMode(options['myLocationTrackingMode']); } if (options.containsKey('myLocationRenderMode')) { diff --git a/mapbox_gl_web/lib/src/mapbox_map_controller.dart b/mapbox_gl_web/lib/src/mapbox_map_controller.dart index 7f970fcac..f1a090d30 100644 --- a/mapbox_gl_web/lib/src/mapbox_map_controller.dart +++ b/mapbox_gl_web/lib/src/mapbox_map_controller.dart @@ -542,6 +542,10 @@ class MapboxMapController extends MapboxGlPlatform @override void setMyLocationTrackingMode(int myLocationTrackingMode) { + if(_geolocateControl==null){ + //myLocationEnabled is false, ignore myLocationTrackingMode + return; + } if (myLocationTrackingMode == 0) { _addGeolocateControl(trackUserLocation: false); } else {