Atlaslog
Atlaslog / Leaflet / API reference / DomEvent
Leaflet · API reference

DomEvent

Quick answer

L.DomEvent wraps native browser events for Leaflet controls and overlays, adding helpers for propagation control and coordinate reading. Use it instead of addEventListener when a control must stop clicks and wheel events from reaching the map beneath it. It also normalizes browser wheel deltas across engines.

Last verified 2026-11-03 · Leaflet 1.9.4 · Cite this page
L.DomEvent.on( el , types , fn , context ?) → this
Key points
Example
var ZoomBox = L.Control.extend({
  onAdd: function () {
    var box = L.DomUtil.create('div', 'zoom-box');
    box.innerHTML =
      '<button data-step="1">放大</button>' +
      '<button data-step="-1">缩小</button>';

    L.DomEvent.disableClickPropagation(box);
    L.DomEvent.disableScrollPropagation(box);

    L.DomEvent.on(box, 'click', function (e) {
      var step = Number(e.target.getAttribute('data-step'));
      if (!step) { return; }
      map.setZoom(map.getZoom() + step);
    });

    return box;
  }
});

map.addControl(new ZoomBox({ position: 'topright' }));
L.DomEvent.on(map.getContainer(), 'mousemove', function (e) {
  var p = L.DomEvent.getMousePosition(e, map.getContainer());
  hoverLabel.textContent = Math.round(p.x) + ', ' + Math.round(p.y);
});
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). DomEvent. https://www.jingweizhi.com/en/leaflet/api/dom-event.html (accessed 2026-11-03).