fix: resolve most tile pruning/state issues #2007
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes #1837
there are still some instances I can get the tiles to not prune when zooming, but i am not sure the exact conditions. it might be related to multi-level zooms, or prune timers? though it seems like they all appropriately callback.
As part of this PR i also looked to add optimistic tile pruning of the parent when all 4 children are loaded, however quickly ran into state consistency issues. This is a simple quick fix to resolve most of the problem, but the tile layer really needs a rewrite as some of the state is held inside of a
Manager
which cannot call setState when making changes to the tiles, leading to visual bugs, like this one. I tried to add a setState callback, but ran into flutter issues (as it is generally bad practice) to do this.So as a mostly-fix, I am adding a setState callback, which adds a few more calls to setState, but the performance impact is minimal (meaning only causing a few more widget draws, which isn't a big deal at all, however we should be able to just call setState under the manager and only update when we update the tiles), and not making the widget drawing slower. I did not notice a meaningful difference in the numbe of rendered frames after moving the map/zooming/animating when profiling.
This setState call also conveniently fixes another bug where changing the tileUrl didn't always update the drawing when it finishes loading.