首页 / Leaflet / API 文档
Control.Attribution
先看结论
汇总各图层版权信息的控件,默认固定在右下角。
L.control.attribution(options) → Control.Attribution
参数
| 选项 | 默认值 | 说明 |
|---|---|---|
position | 'bottomright' | 控件所在角,可选四个方位 |
prefix | Leaflet 链接 | 固定显示在最前面的落款,默认是带 logo 的 Leaflet 官方链接 |
map.attributionControl | true | 地图选项,为 false 时不创建该控件 |
成员
| 成员 | 返回值 | 说明 |
|---|---|---|
addAttribution(text) | this | 追加一条署名,内部按引用计数合并,同一文字只显示一次 |
removeAttribution(text) | this | 减少一次引用,计数归零才真正移除 |
setPrefix(prefix) | this | 替换默认落款,传 false 可完全去掉 |
getPosition() | String | 读取所在角 |
setPosition(position) | this | 换角,内部先移除再添加 |
addTo(map) / remove() | this | 手动挂载与移除 |
/* 地图初始化时不创建,稍后手动放到左上角 */
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);
署名不是可选装饰。OpenStreetMap 的瓦片使用条款要求明确标注
“© OpenStreetMap contributors”,并链接到版权页。把
attribution 写进图层选项,移除图层时署名会随之消失,比手工
addAttribution 更不容易漏。
落款太长会占用地图底部空间,窄屏下可能盖住比例尺。只保留必要的版权方,
不要在 prefix 里再塞一段营销文字。用
setPrefix(false) 去掉默认 Leaflet 链接后,仍需保留数据来源。
经纬志(2026)。《Control.Attribution》。https://www.jingweizhi.com/leaflet/api/control-attribution.html(访问日期 2026-11-03)。