1+ import 'dart:async' ;
12import 'dart:math' ;
23
34import 'package:arcgis_example/main.dart' ;
45import 'package:arcgis_map_sdk/arcgis_map_sdk.dart' ;
56import 'package:flutter/material.dart' ;
67import 'package:geolocator/geolocator.dart' ;
8+ import 'package:rxdart/rxdart.dart' ;
79
810class LocationIndicatorExamplePage extends StatefulWidget {
911 const LocationIndicatorExamplePage ({super .key});
1012
1113 @override
12- State <LocationIndicatorExamplePage > createState () =>
13- _LocationIndicatorExamplePageState ();
14+ State <LocationIndicatorExamplePage > createState () => _LocationIndicatorExamplePageState ();
1415}
1516
16- class _LocationIndicatorExamplePageState
17- extends State <LocationIndicatorExamplePage > {
17+ class _LocationIndicatorExamplePageState extends State <LocationIndicatorExamplePage > {
1818 final _mockLocations = [
1919 LatLng (48.1234963 , 11.5910182 ),
2020 LatLng (48.1239241 , 11.45897063 ),
@@ -34,6 +34,8 @@ class _LocationIndicatorExamplePageState
3434 var _activeAutoPanMode = AutoPanMode .off;
3535 var _wanderExtentFactor = 0.5 ;
3636
37+ StreamSubscription ? _panUpdateSubscription;
38+
3739 @override
3840 Widget build (BuildContext context) {
3941 return Scaffold (
@@ -48,8 +50,7 @@ class _LocationIndicatorExamplePageState
4850 : await _controller! .locationDisplay.startSource ();
4951 } catch (e, stack) {
5052 if (! mounted) return ;
51- ScaffoldMessenger .of (_snackBarKey.currentContext! )
52- .showSnackBar (SnackBar (content: Text ("$e " )));
53+ ScaffoldMessenger .of (_snackBarKey.currentContext! ).showSnackBar (SnackBar (content: Text ("$e " )));
5354 debugPrint ("$e " );
5455 debugPrintStack (stackTrace: stack);
5556 }
@@ -71,16 +72,21 @@ class _LocationIndicatorExamplePageState
7172 _controller = controller;
7273 _requestLocationPermission ();
7374 _configureLocationDisplay (Colors .blue);
75+
76+ _panUpdateSubscription? .cancel ();
77+ _panUpdateSubscription = controller
78+ .centerPosition ()
79+ .debounceTime (const Duration (milliseconds: 50 ))
80+ .listen ((_) => _refreshAutoPanMode ());
7481 },
7582 ),
7683 ),
7784 const SizedBox (height: 16 ),
85+ Text ("Current auto pan mode: ${_activeAutoPanMode .name }" ),
7886 ElevatedButton (
7987 onPressed: _switchLocationSource,
8088 child: Text (
81- _isManualLocationSource
82- ? "Use auto location source"
83- : "Use manual location source" ,
89+ _isManualLocationSource ? "Use auto location source" : "Use manual location source" ,
8490 ),
8591 ),
8692 if (_isManualLocationSource) ...[
@@ -101,15 +107,12 @@ class _LocationIndicatorExamplePageState
101107 ElevatedButton (
102108 onPressed: () {
103109 setState (
104- () =>
105- _useCourseSymbolForMovement = ! _useCourseSymbolForMovement,
110+ () => _useCourseSymbolForMovement = ! _useCourseSymbolForMovement,
106111 );
107112 _configureLocationDisplay (Colors .red);
108113 },
109114 child: Text (
110- _useCourseSymbolForMovement
111- ? "Disable course indicator"
112- : "Enable course indicator" ,
115+ _useCourseSymbolForMovement ? "Disable course indicator" : "Enable course indicator" ,
113116 ),
114117 ),
115118 ElevatedButton (
@@ -158,9 +161,7 @@ class _LocationIndicatorExamplePageState
158161 Future <void > _switchLocationSource () async {
159162 await _controller! .locationDisplay.stopSource ();
160163 await _controller! .setLocationDisplay (
161- _isManualLocationSource
162- ? ArcgisLocationDisplay ()
163- : ArcgisManualLocationDisplay (),
164+ _isManualLocationSource ? ArcgisLocationDisplay () : ArcgisManualLocationDisplay (),
164165 );
165166 setState (() => _isManualLocationSource = ! _isManualLocationSource);
166167
@@ -246,4 +247,16 @@ class _LocationIndicatorExamplePageState
246247 _controller? .locationDisplay.setWanderExtentFactor (_wanderExtentFactor);
247248 }
248249 }
250+
251+ @override
252+ void dispose () {
253+ _panUpdateSubscription? .cancel ();
254+ super .dispose ();
255+ }
256+
257+ Future <void > _refreshAutoPanMode () async {
258+ final panMode = await _controller! .locationDisplay.getAutoPanMode ();
259+ if (! mounted) return ;
260+ setState (() => _activeAutoPanMode = panMode);
261+ }
249262}
0 commit comments