Layers should inherit pane from containing L.LayerGroup
See original GitHub issueI’ve been reading #4277 and started to check some of the code and think.
When a layer is added to a LayerGroup
(or a child class like FeatureGroup
or a GeoJSON
), the layer does not inherit the pane
option of the LayerGroup
which contains it.
So, for example, this code from the “map panes” tutorial adds a layer to the labels
pane:
var positronLabels = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_only_labels/{z}/{x}/{y}.png', {
attribution: cartodbAttribution,
pane: 'labels'
}).addTo(map);
But this won’t:
var positronLabels = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_only_labels/{z}/{x}/{y}.png', {
attribution: cartodbAttribution,
});
var group = L.layerGroup();
group.options.pane = 'labels';
group.addLayer(positronLabels).addTo(map);
So I wonder if LayerGroup
s should force their pane
option on layers contained in them, and if it would be possible to override this behaviour, or add an option like forceGroupPaneOnLayers
or something like that. Or maybe it’s better to handle the practical cases like #4277 and forget about a generic solution.
I would prefer a generic solution, but I’m afraid it might not behave correctly with vector renderers in custom panes somehow.
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (2 by maintainers)
Top GitHub Comments
Looks like this issue is still around. I have a bunch of markers in a FeatureGroup. Since the Leaflet docs say FeatureGroup inherits layer options, I assumed I could make a new pane, set zIndex on the pane and pass that pane to my FeatureGroup as an option. But after reading #4277 and #4279 I realize that is not going to result in my markers have the desired zIndex. So I will do as cneumann suggested and set the desired zIndex on each marker as it is made.
I just discovered the same problem today: if I have a LayerGroup with pane:‘tooltipPane’ and then add a bunch of markers to it, those markers are in the overlay pane, whereas I expected them to inherit their group’s pane.
So I’d love to see one of these two possibilities: