Leaflet is a lightweight, open-source JavaScript library designed for creating mobile-friendly interactive maps. It focuses on performance, usability, and extensibility, providing a core set of features like layers, markers, popups, and controls, while supporting a rich ecosystem of plugins for advanced functionality. The current stable major version is 1.x, with `1.9.4` being the latest bugfix release, which is now in maintenance mode, receiving only critical bugfixes. Development has shifted significantly towards the upcoming 2.0 release, currently in alpha, which modernizes the codebase by dropping Internet Explorer support, removing legacy methods, and fully embracing ES Modules. Its simple API and strong community support make it a popular choice for web mapping applications, particularly where performance and bundle size are critical.
npm install leafletVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize a basic Leaflet map, add an OpenStreetMap tile layer, and place a marker with a popup. It also addresses the common issue of missing marker icons when using bundlers.
Migrate imports to use named ES Module syntax (e.g., `import { Map, tileLayer } from 'leaflet';`). For users relying on the global `L`, consider using the bundled `leaflet-global.js` or adapting to named imports.Ensure your target browser environment meets modern standards. Review custom plugins and code for reliance on deprecated Leaflet 1.x APIs or IE-specific logic.
While 1.x remains stable, plan for eventual migration to Leaflet 2.x to benefit from ongoing development, modernizations, and new features.
If you need an ESM entrypoint in 1.x, explicitly import `leaflet/dist/leaflet-src.esm.js`. For most users with bundlers, `import 'leaflet'` or `require('leaflet')` might still resolve to the CJS or UMD bundle.Manually set `L.Icon.Default.mergeOptions` to point to absolute URLs for the icon images (e.g., from unpkg.com) or configure your bundler to copy and correctly resolve the images from `node_modules/leaflet/dist/images`.
For Leaflet 1.x, ensure `leaflet.js` is loaded via a `<script>` tag or `import 'leaflet'` is used in a bundler setup. For Leaflet 2.x, use named imports like `import { Map } from 'leaflet';` or ensure you are loading the `leaflet-global.js` bundle if you require the global `L`.Override Leaflet's default icon paths to point to absolute URLs (e.g., `L.Icon.Default.mergeOptions({ iconRetinaUrl: 'https://...', iconUrl: 'https://...', shadowUrl: 'https://...' });`) or configure your bundler to copy `node_modules/leaflet/dist/images` to your public asset folder.For Leaflet 1.x, rely on the global `L` object or `import * as L from 'leaflet';` in TypeScript. For Leaflet 2.x, ensure your build setup supports ES Modules and use named imports like `import { Map, tileLayer } from 'leaflet';`. If on Leaflet `v1.9.2` or later and explicitly want ESM, import `leaflet/dist/leaflet-src.esm.js`.No dependency data recorded yet.