ebrelsford / Leaflet.loading

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

Loading indicator stays on for GeoJSON data #43

Open floggle opened 5 years ago

floggle commented 5 years ago

Neat plugin. Seems to be more complex to do this than you'd expect.

I have a basemap that's geojson data with many objects. There's also another (non-geojson) baselayer. The loading indicator is fine if the base-layer starts as the geojson, but when switching back to the geojson baselayer, the loading indicator appears and never disappears.

The problem seems to be that inside _handleBaseLayerChange the plugin runs addLoader for each child layer (as GeoJSON loads as a group). But they are then never triggered. Don't know why.

I worked around this by simply disabling it for LayerGroups:

                    if(!e.layer instanceof L.LayerGroup) {
                        e.layer.eachLayer(function (layer) {
                            that._handleBaseLayerChange({layer: layer});
                        });
                    }

but it's a weak solution

ebrelsford commented 5 years ago

If you wouldn't mind sharing a minimal example that shows this issue that would be helpful. I'm also open to pull requests that fix it.