CloudMade/Leaflet — Issue #369: On load, map displays attribution for all base layers, not just visible
Author: yourcelf
Created: 2011-11-11 03:32:33+00:00
State: open

I'm creating two layers with different attribution. I expect only the attribution for the visible layer to show. However, the attribution for all base layers shows initially in one long line. After changing the visible layers with the layers control, only the attribution for the visible layer is shown, as expected. Example code:

var oamLayer = new L.TileLayer('http://{s}.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.png', {
attribution: "Portions Courtesy NASA/JPL-Caltech and U.S. Depart. of Agriculture, Farm Service Agency. Tiles Courtesy of MapQuest ",
subdomains: ['oatile1', 'oatile2', 'oatile3', 'oatile4'],
minZoom: 6,
maxZoom: 18
});

var osmLayer = new L.TileLayer('http://{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png', {
attribution: "Map data © 2011 OpenStreetMap contributors. Tiles Courtesy of MapQuest ",
subdomains: ['otile1', 'otile2', 'otile3', 'otile4'],
minZoom: 6,
maxZoom: 18
});

var map = new L.Map('map', {
center: new L.LatLng(37.468319, -112.644196),
zoom: 11,
layers: [oamLayer, osmLayer]
});
map.attributionControl.setPrefix("");

var baseMaps = {
"Satellite": oamLayer,
"Streets": osmLayer
};
var layersControl = new L.Control.Layers(baseMaps, null, {collapsed: false});
map.addControl(layersControl);