Control.Attribution
Quick answer
L.control.attribution collects copyright text from every layer and shows it as a compact strip in a map corner, bottom right by default. Layer attribution options feed it automatically, so providers such as OpenStreetMap are credited without manual addAttribution calls. Place it in any of the four corners through the position option.
L.control.attribution( options ) → Control.Attribution
Key points
- addAttribution is reference counted, so identical strings appear once and vanish at zero.
- setPrefix(false) removes the default Leaflet credit while keeping data source lines.
- Set the map option attributionControl to false to create the control manually later.
Example
/* 地图初始化时不创建,稍后手动放到左上角 */
var map = L.map('map', {
center: [39.907359, 116.391263],
zoom: 12,
attributionControl: false
});
L.control.attribution({
position: 'bottomright',
prefix: '<a href="/">经纬志</a>'
}).addTo(map);
var osm = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
Notes
- Removing a layer drops its attribution entry, so strings added by hand must be restored.
- Long prefix text crowds narrow screens and can overlap the scale control.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). Control.Attribution. https://www.jingweizhi.com/en/leaflet/api/control-attribution.html (accessed 2026-11-03).