Skip to content

Commit 51f777e

Browse files
authored
cs/Using gesture detector (#327)
* update logics using interaction gesture detector * review update
1 parent 5d99b66 commit 51f777e

File tree

2 files changed

+46
-35
lines changed

2 files changed

+46
-35
lines changed

lib/samples/match_viewpoint_of_geo_views/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Interact with the MapView or SceneView by zooming or panning. The other MapView
1414

1515
## How it works
1616

17-
1. Wire up the `onViewpointChanged` and `onNavigationChanged` event handlers for both geo views.
17+
1. Wire up the `onViewpointChanged` event handlers for both geo views.
1818
2. In each event handler, get the current viewpoint from the geo view that is being interacted with and then set the viewpoint of the other geo view to the same value.
1919
3. Note: The reason for setting the viewpoints in multiple event handlers is to account for different types of interactions that can occur (ie. single click pan -vs- continuous pan, single click zoom in -vs- mouse scroll wheel zoom, etc.).
2020

lib/samples/match_viewpoint_of_geo_views/match_viewpoint_of_geo_views.dart

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,19 @@ class _MatchViewpointOfGeoViewsState extends State<MatchViewpointOfGeoViews>
3333
final _mapViewController = ArcGISMapView.createController();
3434
// A controller for the scene view.
3535
final _sceneViewController = ArcGISSceneView.createController();
36-
// Viewpoint for the map view.
37-
Viewpoint? _mapViewViewpoint;
38-
// Viewpoint for the scene view.
39-
Viewpoint? _sceneViewViewpoint;
40-
// A flag to indicate if the map view is currently navigating.
41-
bool _isMapViewNavigation = false;
42-
// Stream subscriptions for viewpoint and navigation changes.
36+
// A flag to indicate if the map view is currently interacting.
37+
bool _isMapViewInteraction = false;
38+
// A flag to indicate if the scene view is currently interacting.
39+
bool _isSceneViewInteraction = false;
40+
// Stream subscriptions for viewpoint changes.
4341
late StreamSubscription _mapViewViewpointChangedSubscription;
44-
late StreamSubscription _mapViewNavigationChangedSubscription;
4542
late StreamSubscription _sceneViewViewpointChangedSubscription;
4643
// A flag for when the map view is ready and controls can be used.
4744
var _ready = false;
4845

4946
@override
5047
void dispose() {
5148
_mapViewViewpointChangedSubscription.cancel();
52-
_mapViewNavigationChangedSubscription.cancel();
5349
_sceneViewViewpointChangedSubscription.cancel();
5450
super.dispose();
5551
}
@@ -83,16 +79,39 @@ class _MatchViewpointOfGeoViewsState extends State<MatchViewpointOfGeoViews>
8379
return [
8480
// Add a map view to the widget tree and set a controller.
8581
Expanded(
86-
child: ArcGISMapView(
87-
controllerProvider: () => _mapViewController,
88-
onMapViewReady: onMapViewReady,
82+
child: GestureDetector(
83+
behavior: HitTestBehavior.translucent,
84+
onTapDown: (_) => setState(() {
85+
_isMapViewInteraction = true;
86+
_isSceneViewInteraction = false;
87+
}),
88+
onDoubleTapDown: (_) => setState(() {
89+
_isMapViewInteraction = true;
90+
_isSceneViewInteraction = false;
91+
}),
92+
child: ArcGISMapView(
93+
controllerProvider: () => _mapViewController,
94+
onMapViewReady: onMapViewReady,
95+
),
8996
),
9097
),
9198
// Add a scene view to the widget tree and set a controller.
9299
Expanded(
93-
child: ArcGISSceneView(
94-
controllerProvider: () => _sceneViewController,
95-
onSceneViewReady: onSceneViewReady,
100+
child: GestureDetector(
101+
behavior: HitTestBehavior.translucent,
102+
onDoubleTapDown: (_) => setState(() {
103+
_isMapViewInteraction = false;
104+
_isSceneViewInteraction = true;
105+
}),
106+
onTapDown: (_) => setState(() {
107+
_isMapViewInteraction = false;
108+
_isSceneViewInteraction = true;
109+
}),
110+
111+
child: ArcGISSceneView(
112+
controllerProvider: () => _sceneViewController,
113+
onSceneViewReady: onSceneViewReady,
114+
),
96115
),
97116
),
98117
];
@@ -104,21 +123,14 @@ class _MatchViewpointOfGeoViewsState extends State<MatchViewpointOfGeoViews>
104123
final map = ArcGISMap.withBasemapStyle(BasemapStyle.arcGISImagery);
105124
_mapViewController.arcGISMap = map;
106125

107-
// Listen for navigation changes in the map view.
108-
_mapViewNavigationChangedSubscription = _mapViewController
109-
.onNavigationChanged
110-
.listen((isNavigating) {
111-
_isMapViewNavigation = isNavigating;
112-
});
113-
114126
// Listen for viewpoint changes in the map view.
115127
_mapViewViewpointChangedSubscription = _mapViewController.onViewpointChanged
116128
.listen((_) {
117-
_mapViewViewpoint = _mapViewController.getCurrentViewpoint(
118-
ViewpointType.centerAndScale,
119-
);
120-
if (_isMapViewNavigation) {
121-
_sceneViewController.setViewpoint(_mapViewViewpoint!);
129+
if (_isMapViewInteraction) {
130+
final mapViewViewpoint = _mapViewController.getCurrentViewpoint(
131+
ViewpointType.centerAndScale,
132+
);
133+
_sceneViewController.setViewpoint(mapViewViewpoint!);
122134
}
123135
});
124136

@@ -137,15 +149,14 @@ class _MatchViewpointOfGeoViewsState extends State<MatchViewpointOfGeoViews>
137149
_sceneViewViewpointChangedSubscription = _sceneViewController
138150
.onViewpointChanged
139151
.listen((_) {
140-
_sceneViewViewpoint = _sceneViewController.getCurrentViewpoint(
141-
ViewpointType.centerAndScale,
142-
);
143-
144-
if (!_isMapViewNavigation) {
145-
_mapViewController.setViewpoint(_sceneViewViewpoint!);
152+
if (_isSceneViewInteraction) {
153+
final sceneViewViewpoint = _sceneViewController.getCurrentViewpoint(
154+
ViewpointType.centerAndScale,
155+
);
156+
_mapViewController.setViewpoint(sceneViewViewpoint!);
146157
}
147158
});
148-
159+
149160
// Set the ready state variable to true to enable the sample UI.
150161
setState(() => _ready = true);
151162
}

0 commit comments

Comments
 (0)