mapbox-maps-flutter icon indicating copy to clipboard operation
mapbox-maps-flutter copied to clipboard

How to reset focalPoint in GestureSettings to default behavior?

Open Taharu opened this issue 6 months ago • 3 comments

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 🙏

Taharu avatar Jun 04 '25 01:06 Taharu

Hi, I have not try it, but I have two potential solution:

  1. You can store the initial state and reapply it
final initialSetting = await mapboxMap.gestures.getSettings();
await mapboxMap.gestures.updateSettings(initialSetting);
  1. You can try passing an empty instance of GestureSettings()

await mapboxMap.gestures.updateSettings(GestureSettings());

Hope this helps!

tchengck avatar Jun 05 '25 12:06 tchengck

@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 ...

Taharu avatar Jun 06 '25 08:06 Taharu

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)
    )
);

tchengck avatar Jun 06 '25 08:06 tchengck