Atlaslog
Atlaslog / Leaflet / Tutorial / Popups and tooltips
Leaflet · Tutorial

Popups and tooltips

Quick answer

This tutorial distinguishes Leaflet Popup from Tooltip by trigger, default style and how many can stay open, then binds both to markers, circles and raw coordinates. It covers autoClose, autoPan, maxWidth, offset and direction, permanent and sticky tooltips, and refreshing an open popup with setContent followed by update(). Readers can place readable callouts without breaking layout or leaking memory.

Last verified 2026-11-03 · Leaflet 1.9.4 · Cite this page
Key points
Example
var marker = L.marker([39.907359, 116.391263]).addTo(map);

marker.bindPopup(
  '<b>天安门</b><br>东经 116.391263,北纬 39.907359',
  { maxWidth: 260, autoPan: true }
);
L.popup()
  .setLatLng([39.916345, 116.397155])
  .setContent('<p>王府井</p>')
  .openOn(map);
var popup = L.popup()
  .setLatLng([39.907359, 116.391263])
  .setContent('加载中…')
  .openOn(map);

fetch('/api/station/42')
  .then(function (r) { return r.json(); })
  .then(function (data) {
    popup.setContent(
      '<h4>' + data.name + '</h4><p>客流:' + data.flow + '</p>'
    );
    popup.update();       // 重算尺寸与箭头位置
  });
Notes
Runnable examplesChinese originalAll Tutorials
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). Popups and tooltips. https://www.jingweizhi.com/en/leaflet/tutorials/popup-tooltip.html (accessed 2026-11-03).