You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Repositioning the map through MapController in onMapReady prevents initial tiles loading #1507
Hey @MatyasK,
Can you please strip down your code to create an MRE? At the moment, it's difficult for us to test, as there's lots of state management surrounding it.
I created a sample app, the app bevahes the same way, so the map only loads after you move the camera around. (I created a test api key so you can use that).
changed the title [-][BUG] Tiles doesn't load after migrating to V4[/-][+][BUG] Repositioning the map through `MapController` in `onMapReady` prevents tiles loading[/+]on May 9, 2023
changed the title [-][BUG] Repositioning the map through `MapController` in `onMapReady` prevents tiles loading[/-][+][BUG] Repositioning the map through `MapController` in `onMapReady` prevents initial tiles loading[/+]on May 9, 2023
This is likely related to #1475. @ibrierley@mootw@TesteurManiak Is this issue worth fixing? Users shouldn't setup their map in this way - except from when they need data from asynchronous sources first. But in that case, they can just delay the whole map from loading.
hmm I think it depends if this is part of a more subtle bug. I think its fine to leave this as is for this current issue (i.e there's a more correct fix).
But I'm also wondering if its related to something like some bits in rorystephenson@a13353f (it may also be completely unrelated, just maybe the first place I'd look by the description of the problem). eg
Remove unnecessary setState in FlutterMapState’s emitMapEvent. The
event emitting does not change the map's state and was causing double
calls to setState in some code paths.
Removed the workaround for the initial map size being zero in TileLayer
which caused tiles to not be loaded. The new MapEventNonRotatedSizeChange
event removes the need for this workaround as during startup either:
- The platform has already set flutter's resolution and thus all
tiles are successfully loaded.
- The platform has not set flutter's resolution but when it does it
will cause LayoutBuilder to rebuild with the new size which will
trigger a MapEventNonRotatedSizeChange event. This event will in
turn trigger a tile load in TileLayer.
For example, if there's a condition where previously we didn't have a size in the layout builder, and previously didn't send a map ready event until the size was resolved but now we do. We may find there are some other sneaky bugs that come in where people are doing things on a map ready when it isn't correctly sized or tiles loaded. I don't know this is the case at all, just kinda worth being aware that it could be part of a larger issue that pops up a few times. The whole layoutbuilder sizing thing has always been a bit of a pita :).
just kinda worth being aware that it could be part of a larger issue that pops up a few times. The whole layoutbuilder sizing thing has always been a bit of a pita :).
Absolutely, whatever anyone does, it never seems to properly fix it!
Maybe we should mention something about this in the documentation of either MapController or onMapReady.
I'll mention it in https://docs.fleaflet.dev/usage/controller#usage-in-initstate - on a related note, I've recently changed the guidance for MapController in initState again to use onMapReady, because some people were having issues with the SchedulerBinding methods, and it's more clear now.
I think its fine to leave this as is for this current issue (i.e there's a more correct fix).
Maybe this should be converted to a general tracking issue then, for issues with initial sizing?
Activity
JaffaKetchup commentedon May 8, 2023
Hey @MatyasK,
Can you please strip down your code to create an MRE? At the moment, it's difficult for us to test, as there's lots of state management surrounding it.
MatyasK commentedon May 9, 2023
I created a sample app, the app bevahes the same way, so the map only loads after you move the camera around. (I created a test api key so you can use that).
JaffaKetchup commentedon May 9, 2023
Reproducible. The issue seems to be with running the
fitBoundscall when the map loads. Can you useboundsinMapOptionsinstead?MatyasK commentedon May 9, 2023
@JaffaKetchup That solves the issue, thanks for your quick reply!
[-][BUG] Tiles doesn't load after migrating to V4[/-][+][BUG] Repositioning the map through `MapController` in `onMapReady` prevents tiles loading[/+][-][BUG] Repositioning the map through `MapController` in `onMapReady` prevents tiles loading[/-][+][BUG] Repositioning the map through `MapController` in `onMapReady` prevents initial tiles loading[/+]JaffaKetchup commentedon May 9, 2023
This is likely related to #1475.
@ibrierley @mootw @TesteurManiak Is this issue worth fixing? Users shouldn't setup their map in this way - except from when they need data from asynchronous sources first. But in that case, they can just delay the whole map from loading.
TesteurManiak commentedon May 9, 2023
I agree with you @JaffaKetchup. Maybe we should mention something about this in the documentation of either
MapControlleroronMapReady.ibrierley commentedon May 9, 2023
hmm I think it depends if this is part of a more subtle bug. I think its fine to leave this as is for this current issue (i.e there's a more correct fix).
But I'm also wondering if its related to something like some bits in rorystephenson@a13353f (it may also be completely unrelated, just maybe the first place I'd look by the description of the problem). eg
For example, if there's a condition where previously we didn't have a size in the layout builder, and previously didn't send a map ready event until the size was resolved but now we do. We may find there are some other sneaky bugs that come in where people are doing things on a map ready when it isn't correctly sized or tiles loaded. I don't know this is the case at all, just kinda worth being aware that it could be part of a larger issue that pops up a few times. The whole layoutbuilder sizing thing has always been a bit of a pita :).
JaffaKetchup commentedon May 9, 2023
Absolutely, whatever anyone does, it never seems to properly fix it!
I'll mention it in https://docs.fleaflet.dev/usage/controller#usage-in-initstate - on a related note, I've recently changed the guidance for
MapControllerininitStateagain to useonMapReady, because some people were having issues with theSchedulerBindingmethods, and it's more clear now.Maybe this should be converted to a general tracking issue then, for issues with initial sizing?
JaffaKetchup commentedon May 20, 2023
Closing for now. More specific issues can be opened as necessary.
Fixed (temporarily-ish?) through documentation update.
pamtbaau commentedon Apr 27, 2026
Same happens when running
mapController.move()during theisMapReadyevent:The first time the map is opened, all is well. When closing and opening the map again with new location, the tyles are no longer displayed.
Workaround for my use case:
initialCenterinstead_mapController.move()insideFuture.delayed()