Attribution for multiple WMSTile layers not showing correctly on first load
Opened this issue · 2 comments
Description
When drawing map with multiple WMSTile layers on initial load all three attributions (for each separate WMS layer) are printed as attribution. After first change everything is as should be and attributions are correctly displayed.
Live Demo
https://codesandbox.io/s/eager-feather-vf691
Steps to Reproduce
Create two or more separate WMS layers with different attribution and on initial load all three attributions will be showed.
Expected Results
On initial load only attribution of selected WMS base layer should be displayed as attribution.
Actual Results
On initial load all three attributions are showed and only after first change the attribution is correctly displayed.
Browsers Affected
- Chrome
- Firefox
- Edge
- Safari 9
- Safari 8
- IE 11
Versions
- Leaflet: v1.6.0
- Vue: v2.6.10
- Vue2Leaflet: v2.5.2
As far as I can tell, this is the behaviour in vanilla Leaflet as well, if all of the base layers are added to the map as well as the layers control: https://codesandbox.io/s/leaflet-three-visible-baselayers-gnvte
A simple resolution in the Vue2Leaflet case is to set visible: false
on all of the base layers except one, which will then be the only one whose attribution is initially displayed: https://codesandbox.io/s/objective-darkness-g6n0l?file=/App.vue
@DonNicoJs do you think there might still be an issue around how the LControlLayers
component works in this situation, or shall we close this? The Leaflet docs do say that "when using multiple base layers, only one of them should be added to the map at instantiation, but all of them should be present in the base layers object when creating the layers control".
So perhaps there's an argument that the logic in LMap.addLayer
should attempt to automatically add only the first (visible) base layer to the map, and add all subsequent base layers to only the layers control, then let it take care of handling which layer is added to the map at any given time. But since setting visible
on each layer gives the user a straightforward way to determine the initial configuration explicitly, I don't know whether that would be useful behaviour.