Map Events
Quick answer
The Map event catalog covers view changes, mouse and touch input, layer additions, popups and geolocation, each delivering a typed event object. Listen with map.on, map.once or map.off, then read fields such as latlng, center, layer and originalEvent from the payload.
map.on( type , fn , context ?) · map.off(...) · map.once(...) · map.fire(type, data?)
Key points
- preclick fires before click, which is useful for closing existing popups first.
- zoomlevelschange signals minZoom or maxZoom adjustments rather than a zoom step.
- layeradd fires per layer addition and never confirms tile loading.
Example
['click', 'dblclick', 'moveend', 'zoomend', 'layeradd'].forEach(function (name) {
map.on(name, function (e) {
console.log(name, e.latlng ? e.latlng.toString() : '', e.layer ? L.Util.stamp(e.layer) : '');
});
});
/* 只触发一次,适合「地图首次就绪后再加载数据」 */
map.once('load', function () { loadPoints(); });
/* 临时监听,回调里自行摘掉 */
function onFirstMove() {
console.log('第一次移动结束');
map.off('moveend', onFirstMove);
}
map.on('moveend', onFirstMove);
/* 主动派发自定义事件 */
map.on('dataset:ready', function (e) { console.log(e.count); });
map.fire('dataset:ready', { count: 128 });
Notes
- mousemove and move fire continuously, so heavy work there visibly drops the frame rate.
- Clicks are delayed roughly 300 milliseconds on touch devices when double tap zoom is on.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). Map Events. https://www.jingweizhi.com/en/leaflet/api/map-events.html (accessed 2026-11-03).