Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TileLayer loading event fired before layeradd event #2967

Closed
ventralnet opened this issue Oct 22, 2014 · 4 comments
Closed

TileLayer loading event fired before layeradd event #2967

ventralnet opened this issue Oct 22, 2014 · 4 comments

Comments

@ventralnet
Copy link

Fiddle of the issue http://jsfiddle.net/ventralnet/rnp2f769/

Notice that the 'loading' event is not logged to the console. This is because the loading event fires before the layeradd event is fired

I came across this issue when trying to incorporate a loading indicator to display when layers are loading. Do you think this is a valid issue?

@yohanboniface
Copy link
Member

layeradd event is fired after onAdd has been called. So everything that's run during onAdd can't be hooked on the layeradd event. I think this was already the case in 0.7.x.
@mourner should we have some beforeadd event that'd be fired before onAdd is run?

@jasonoverland
Copy link
Contributor

+1 to asking the question but not having a clear solution.

I'm using the plugin Leaflet.Loading which also suffers from this issue (ebrelsford/Leaflet.loading#28)

I also considered using Leaflet.Spin plugin which looks like it would have the same issue.

The hack fix is to peek at _loading when the listener receives the layeradd event. Could this kind of fix be put into _layerAdd?

Or would it be feasible to have layeradd fire before loading is called?

@perliedman
Copy link
Member

From what I gather, you want to add a load listener to every layer. How about adding an init hook to L.Layer, instead of trying to do it on layer add from the map class? From 1.0, all layers must extend L.Layer. Or am I missing something?

@Falke-Design
Copy link
Member

Like @perliedman described, the listener can be added in the initHook:

L.Layer.addInitHook(function() {
    this.on('loading',function(e){
    	console.log(e);
    });
});

http://jsfiddle.net/falkedesign/yaznmdeq/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants