Map
Quick answer
L.map creates the core map instance that owns the view, the layer stack, panes and all interaction handlers. Every layer, control and popup attaches to it, so its center, zoom and CRS options define the whole scene. Call invalidateSize whenever the container size changes.
L.map( id , options ) → Map
Key points
- setView jumps immediately, flyTo animates and fitBounds frames a rectangle.
- invalidateSize must follow container size changes or tiles misalign and render partially.
- addLayer, removeLayer and eachLayer manage the layer stack directly.
Example
map.on('click', function (e) {
console.log(e.latlng.lat, e.latlng.lng);
});
map.on('moveend', function () {
console.log(map.getCenter(), map.getZoom());
});
Notes
- A map initialized inside a hidden container reads height zero and renders broken tiles.
- move fires every frame, so attach expensive recalculation to moveend instead.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). Map. https://www.jingweizhi.com/en/leaflet/api/map.html (accessed 2026-11-03).