ebrelsford / Leaflet.loading

A simple loading control for Leaflet
MIT License
143 stars 49 forks source link

Listen map layeradd event #15

Closed kcwu closed 10 years ago

kcwu commented 10 years ago

This change fixed no loading indicator issue if layers are added later.

ebrelsford commented 10 years ago

First off, thanks for the PR.

I'm not entirely opposed to merging this, but do you have examples of where it doesn't work currently?

The plugin already listens for new layers then adds the appropriate listeners to that layer. Adding a new layer doesn't necessarily mean that tiles or other entities are being loaded, so it seems premature to call _handleLoading when a layer is added.

kcwu commented 10 years ago

Here is my example. http://kcwu.csie.org/~kcwu/tmp/osm/history-loading.html Use the slider on the top to change date --- different date is on different layer. I am new to leaflet and may use leaflet incorrectly. However, I found hook layeradd event fixed my problem.

ebrelsford commented 10 years ago

Thanks for the example (great work, by the way!). It looks like the layers start loading before the event listeners are registered, so I don't think it's any fault of yours. I'll merge this in now.

ebrelsford commented 10 years ago

Thanks for the minimal example, @yohanboniface, that helps. I created a bl.ocks-able gist based on it here for others to see.

This is clearly a regression, so I'll revert.

@kcwu is there any chance you could (when you have a moment) create a minimal example like the one above, but doing what you're trying to accomplish? That is, a smaller example that should show the loader when a layer is added but does not. I'll get to it eventually if you can't, but I'd appreciate it if you could.