Layer order in `L.Control.Layers` is not preserved with GeoJson/FeatureGroup
See original GitHub issueWhen I do
L.control.layers({
'OSM': L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map)
}, {
'Circle': L.circle([53, 4], 111111),
'Polygon': L.polygon([[48, -3], [50, -4], [52, 4]]),
'GeoJSON': L.geoJson(geojson)
}, {
collapsed: false
}).addTo(map);
I expect the order of the overlays to be as I supplied them, however, GeoJSON and FeatureGroup layers are moved up top. This is because the FeatureGroup gets its _leaflet_id
while it’s created, while the other layers get it while they’re added to Control.Layers.
FeatureGroup is stamped because it’s passed as the context to layer.on
in FeatureGroup.js:19.
Not sure how to fix this:
- stamping each layer while initializing? Seems dirty.
- Different sorting mechanism in Control.Layers?
Issue Analytics
- State:
- Created 10 years ago
- Comments:25 (16 by maintainers)
Top Results From Across the Web
Changing layer order in Leaflet - GIS Stack Exchange
Basically you remove all layers and then re-add them in ascending z-index order. So loop through all your overlay layers, and call map....
Read more >Leaflet Layer Control: Ordering - Stack Overflow
In Leaflet 1.0.0-rc1, internal layer IDs are not used at all, and the layers control uses the order they were added to it....
Read more >L.Control.Layers
If true , the control will assign zIndexes in increasing order to all of its layers so that the order is preserved when...
Read more >How to make layer control visible at all times? Not a icon?
I would like to show as a opened layer control without the need for the user to mouse over it, so that it...
Read more >L.Control.Layers - WRLD3D
The layers control gives users the ability to switch between different base ... all of its layers so that the order is preserved...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If anyone here is using Leaflet 1.0.0 you should be able to use the new
pane
option to control this:You can see this inaction with lots of overlapping polygons here.
Huh, I already made a PR for this…