Request for `tileLayer.whenLoaded` function
See original GitHub issueIs your feature request related to a problem? Please describe. My use case:
- Start
flyTo
programmatically to another location in the map - Wait for the tiles in the new location to be loaded, then do X.
Currently I can only rely on tileLayer.on("load", function(){})
. However, when the new location is already loaded in the beginning (e.g., when the new location is nearby), there is nothing I can use to inform step 2 that X can now be done (“load” event won’t fire since the map is already loaded).
I cannot just rely on “moveend” or “zoomend”, since by the time we reach the new location, the new location might not finish loading yet.
Describe the solution you’d like
Just like map.whenReady
function, which fires immediately when the map is set, I would like to have tileLayer.whenLoaded
function, which fires immediately if the visible tile layer is already loaded.
Describe alternatives you’ve considered
- Putting X only on “moveend” or “zoomend” doesn’t guarantee that the visible tile is loaded.
- Putting X only on
tileLayer.on("load")
doesn’t guarantee that it will fire.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top GitHub Comments
There is no real advantage. As a rule we use private properties (
_loading
) in Leaflet’s own code, but in client code (or plugins) public method is preferable. Reason: private property can be changed in future version without notification, why public one is part of API, and thus more stable.Thanks for the response!
This seems similar to the solution we found here: https://stackoverflow.com/questions/66382098/does-there-exist-a-function-to-tell-if-the-current-tilelayer-is-already-load
Is there any advantage of doing this using lower level checks (
this._loading
) versus a higher-level one (isLoading()
)?