question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Layers should inherit pane from containing L.LayerGroup

See original GitHub issue

I’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 LayerGroups 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:open
  • Created 8 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Jelfffcommented, Apr 21, 2020

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.

0reactions
gpsvisualizercommented, Nov 19, 2019

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:

  • A “force this group’s pane on its members” option when I create a layer group.
  • An “inherit parent group’s pane” option when I add a layer to a specific group.
Read more comments on GitHub >

github_iconTop Results From Across the Web

L.LayerGroup - WRLD3D
Overriding this option will cause the layer to be placed on another pane by default. Events. ▷ Events inherited from Layer. Event, Data ......
Read more >
Documentation - a JavaScript library for interactive maps
Iterates over the layers of the map, optionally specifying context of the iterator function. map.eachLayer(function(layer){ layer.bindPopup('Hello'); });.
Read more >
A Complete Guide to CSS Cascade Layers
Using the @layer at-rule and layered @import s, we can establish our own layers of the cascade — building from low-priority styles like...
Read more >
LayerGroup class - dartleaf library - Dart API - Pub.dev
If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement. inherited.
Read more >
Leaflet - a JavaScript library for interactive maps - GitHub Pages
Pane for popups. Marker. Used to put markers on the map. Extends Layer. L.marker([50.5, 30.5]).addTo(map); ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found