Atlaslog
Atlaslog / Leaflet / API reference / Evented
Leaflet · API reference

Evented

Quick answer

L.Evented is the event base class shared by maps, layers and controls, and you can instantiate it directly as a standalone event bus. It provides on, off, once and fire with optional bubbling through registered event parents. Maps, layers and popups all use it for their click and lifecycle notifications.

Last verified 2026-11-03 · Leaflet 1.9.4 · Cite this page
L.Evented. extend ( props ) → Evented 子类
Key points
Example
var Selection = L.Evented.extend({
  select: function (id) {
    this.selectedId = id;
    this.fire('select', { id: id });
  }
});

var selection = new Selection();

selection.on('select', function (e) {
  console.log('选中', e.id, '来自', e.target === selection);
});

selection.once('select', function () {
  console.log('只执行一次');
});

selection.select(12);
selection.select(13);
var layerBus = new L.Evented();

layerBus.addEventParent(map);

layerBus.fire('status', { ready: true }, true);

map.on('status', function (e) {
  console.log('收到子级事件', e.ready);
});
Notes
Runnable examplesChinese originalAll API references
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). Evented. https://www.jingweizhi.com/en/leaflet/api/evented.html (accessed 2026-11-03).