How to reset focalPoint in GestureSettings to default behavior?
Hi team,
I have a question regarding the focalPoint property in GestureSettings.
I can successfully override the gesture center by setting a specific focalPoint via:
await mapboxMap.gestures.updateSettings(
GestureSettings(
focalPoint: ScreenCoordinate(x: ..., y: ...),
),
);
However, I would like to temporarily set the focal point, and then revert back to the default behavior, where the zoom/rotate center follows the user's gesture center.
What is the correct way to reset focalPoint to its default gesture-centered behavior?
Any clarification or workaround would be greatly appreciated!
Thanks 🙏
Hi, I have not try it, but I have two potential solution:
- You can store the initial state and reapply it
final initialSetting = await mapboxMap.gestures.getSettings();
await mapboxMap.gestures.updateSettings(initialSetting);
- You can try passing an empty instance of
GestureSettings()
await mapboxMap.gestures.updateSettings(GestureSettings());
Hope this helps!
@tchengck Hi, Thank you for your comment!
Calling GestureSettings() means the focalPoint field is null, and in updateSettings, null means "do not update". So the focalPoint remains unchanged.
await mapboxMap.gestures.updateSettings(
GestureSettings(
focalPoint: ScreenCoordinate(x: ..., y: ...),
),
);
await mapboxMap.gestures.updateSettings(GestureSettings());
final setting = await mapboxMap.gestures.getSettings();
print(setting.focalPoint.toString()); // x is ...,y is ...
Hi, unfortunately, that didn't work. My last idea is to retrieve the size of the MapView and set its center as the focal point. That should restore the default behavior, if I am not wrong.
await mapboxMap.gestures.updateSettings(
GesturesSettings(
focalPoint: ScreenCoordinate(x: mapView.width / 2.0, y: mapView.height / 2.0)
)
);