fix: skip redundant mapController.move() on gesture-driven pans
Every pan gesture updated mapProvider state, which triggered ref.listen to call _mapController.move() with the position the map was already at. This caused TileLayer to re-evaluate the viewport and cancel in-flight tile loads, producing a partially-rendered (diagonal) map. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3feefd128d
commit
578d2d24ed
1 changed files with 10 additions and 1 deletions
|
|
@ -42,10 +42,19 @@ class _MapScreenState extends ConsumerState<MapScreen> {
|
||||||
final styleAsync = ref.watch(mapStyleProvider(apiClient.baseUrl));
|
final styleAsync = ref.watch(mapStyleProvider(apiClient.baseUrl));
|
||||||
|
|
||||||
// Listen for zoom/center changes from the provider and move the map.
|
// Listen for zoom/center changes from the provider and move the map.
|
||||||
|
// Skip the move if the map controller is already at the target position
|
||||||
|
// (meaning the state change came from a user gesture via onPositionChanged).
|
||||||
|
// Without this guard, every gesture-driven pan calls _mapController.move()
|
||||||
|
// with the position the map is already at, which triggers a tile
|
||||||
|
// recalculation that cancels in-flight tile loads and produces a
|
||||||
|
// partially-rendered (diagonal) map.
|
||||||
ref.listen<MapState>(mapProvider, (previous, next) {
|
ref.listen<MapState>(mapProvider, (previous, next) {
|
||||||
if (previous?.center != next.center || previous?.zoom != next.zoom) {
|
if (previous?.center != next.center || previous?.zoom != next.zoom) {
|
||||||
|
final camera = _mapController.camera;
|
||||||
|
if (camera.center != next.center || camera.zoom != next.zoom) {
|
||||||
_mapController.move(next.center, next.zoom);
|
_mapController.move(next.center, next.zoom);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue