Control.Layers zoom jumps when using LayerGroup as basemap
Expected behavior I expected that using a LayerGroup (e.g. of two tile layers with different zoom levels) as a basemap in Control.Layers works.
Current behavior Basically it works, however there is an undesired side effect: The Control.Layers does not always keep the current zoom level when switching between base layers but jumps.
Environment
- Leaflet version: 1.4
- Browser (with version): Firefox 65
- OS/Platform (with version): Ubuntu Linux
Minimal example reproducing the issue
Try to switch between the base layers several times:
https://plnkr.co/edit/MU4eekv2ZdLyIeBtSnuo?p=preview
https://gist.github.com/evod/c8540fe88147056975113a668fb678e5
Looks like the min/max zoom level calculation is happening just after adding the first tilelayer from the layergroup, not after all tilelayers of the layergroup have been added to the map.
:thinking:
I think only the the min/max zoom of the first layer in the layergroup is respected. My dirty workaround for this bug is to add an empty GridLayer with the combined zoom range as first layer of the layer group.
var minMaxZoomLayer = L.gridLayer({
minZoom: 0,
maxZoom: 19
});
var cartodbPositronLowZoom = L.tileLayer('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors © <a href="https://carto.com/attributions">CARTO</a>',
subdomains: 'abcd',
minZoom: 0,
maxZoom: 15
});
var osmHiZoom = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
minZoom: 16,
maxZoom: 19,
attribution: 'map data & imagery © <a href="https://openstreetmap.org" target="_blank">OpenStreetMap</a> contributors'
});
var mixed = L.layerGroup([minMaxZoomLayer, cartodbPositronLowZoom, osmHiZoom]);