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
Added plugin LayerGroupWithEvents. #4530
Conversation
A few commens about the plugin.
|
Thanks Ivan for the comment, I simply missed FeatureGroup. Whether plugin or patch, it would be a better place. Considering
instead, it might be more desirable to fire "loading" and "load" less often, ideally one time at the beginning and one time at the end:
This requires some logic, to check whether at least one layer is still loading. The proposed plugin implements that logic - at a suboptimal place, though. |
Yeah, I see the point. But your logic is flawed: if your layergroup has a layer which never fires a Besides, I just had a look at the code of (Also, by the Leaflet conventions on plugin naming, this should be something like |
Yes, in a general sense, I agree. Now, for a loading indicator, not receiving "loading" and "load" at all would still be adequate when none of the layer is doing any asynchronous loading. The use case I have only involves asynchrously loading layers like TileLayer. That is BTW one reason to prefer a plugin, which can be used for such use cases only - as opposed to patching the core code.
Ok I have to describe my use case in more details :) We have been providing tilelayer instances to our clients, as well as groups of tilelayers. In the group case, it would be bad API design to let our clients add and remove each layer of the group themselves, so we have been providing them LayerGroup instances. So far, fine. Now some clients use Leaflet.loading to display a loading indicator. They reported that this works fine in the single tilelayer case, but does not in the LayerGroup case. On the other hand, I looked at the place you mentionned in Control.Loading, as well as Map.eachLayer and LayerGroup.addLayer and I could not see anything contradicting your analysis. I'll look very soon deeper into this and comment here again. |
I narrowed down the issue: when using Control.Loading in conjunction with a Control instance, and a LayerGroup or FeatureGroup as one of the basemaps fed to the Control instance, then the loading indicator appears and never disappears. The use case looks like this:
To determine: Whether this problem is only due to Control.Loading, or something like a FeatureGroup.LoadEvents plugin is desirable. |
Here is the technical issue: as soon as one uses a
...but the One could argue that Unless someone objects, I am going to write a |
@glathoud Yeah, that looks like a bug in You could also modify
, as (if memory serves) only gridlayers (and tilelayers) fire these events. |
Good point. One could also be less restrictive and have a black list instead of a white list, excluding only instances of
In any case, then, the loading indicator does not appear right away, i.e. much later in case of a limited bandwidth, which basically revives that issue. From a design perspective, the fact that |
I opened an issue in In addition, I also wrote a
There is a corresponding pull request for |
Rationale:
Content: LayerGroupWithEvents extends LayerGroup to add event support ("loading" and "load").
For more details: https://github.com/Outdooractive/leaflet-layergroup-with-events_0.7
Remark: a direct modification of Leaflet's core's LayerGroup could be possible, but might be too much code for what it does.