Leaflet: Pre-Release v2.0.0-Alpha

5 days ago 1

⚡ Modernization of Leaflet

After two and a half years of hard work, we’re thrilled to announce the first alpha release of Leaflet 2.0!

This release marks a major modernization of the Leaflet codebase. We've dropped support for Internet Explorer, removed legacy methods and polyfills, adopted modern standards like Pointer Events, and now publish Leaflet as an ESM module. The global L is no longer part of the core package (though it’s still available in the bundled version leaflet-global.js for backward compatibility).

For more information checkout the blog post: https://leafletjs.com/2025/05/18/leaflet-2.0.0-alpha.html

What's New in Leaflet 2.0

  • Targeting only evergreen browsers
  • Switched from Mouse and Touch events to PointerEvents
  • ESM support and tree shaking
  • Rewritten using standardized ES6 classes

Migration

  1. Replace all factory methods with constructor calls: L.marker(latlng) ➜ new Marker(latlng)
  2. Change the <script> tag to module: <script type='module'>
  3. Replace usage of L with explicit imports from the Leaflet package: import { Marker } from 'leaflet'
  4. To have global access to variables of a module-script, assign them to the window object (Not recommended): window.map = map
  5. Consider Leaflet V1 Polyfill if you are using outdated plugins

Old implementation

<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script> <script> const map = L.map('map').setView([51.505, -0.09], 13); const tiles = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 19, attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>' }).addTo(map); </script>

New implementation

Module
<script type="importmap"> { "imports": { "leaflet": "https://unpkg.com/[email protected]/dist/leaflet.js" } } </script> <script type="module"> import L, {Map, TileLayer, Marker, Circle, Polygon, Popup} from 'leaflet'; const map = new Map('map').setView([51.505, -0.09], 13); const tiles = new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 19, attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>' }).addTo(map); </script>
Global Script
<script src="https://unpkg.com/[email protected]/dist/leaflet-global.js"></script> <script> const map = new L.Map('map').setView([51.505, -0.09], 13); const tiles = new L.TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 19, attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>' }).addTo(map); </script>

Need Legacy Support?

Check out this polyfill package to help ease the transition for legacy apps: Leaflet V1 Polyfill

Changes

❇️ New Features

✨ Refactorings (⚠️ Breaking Changes)

❌ Removed Features (⚠️ Breaking Changes)

🐞 Bugfixes

📝 Docs

📜 Formatting

  • Enforce quotes ESLint rule for the spec directory by @jonkoops in #8686
  • Provide file extensions when running ESLint by @jonkoops in #8831
  • Lint files in debug directory by @jonkoops in #8925
  • Upgrade to ESLint 9+ and flat config by @mourner in #9410
  • Enable prefer-exponentiation-operator linting rule and fix issues by @simon04 in #9660
  • Guard for-in loops and enable guard-for-in lint rule. by @alope107 in #8879
  • Split ESLint config and clean it up by @jonkoops in #8563
  • Upgrade ESLint config to latest version by @jonkoops in #8583
  • Enable arrow-spacing linting rule and fix issues by @jonkoops in #8584
  • Enable func-name-matching linting rule and fix issues by @jonkoops in #8585
  • Enable no-duplicate-imports linting rule and fix issues by @jonkoops in #8586
  • Enable prefer-template linting rule and fix issues by @jonkoops in #8587
  • Enable prefer-rest-params linting rule and fix issues by @jonkoops in #8593
  • Enable object-shorthand linting rule and fix issues by @jonkoops in #8592
  • Enable prefer-arrow-callback linting rule and fix issues by @jonkoops in #8594
  • Enable no-var linting rule and fix issues by @jonkoops in #8602
  • Remove unused test globals from ESLint config by @jonkoops in #9285

🔧 Workflow

🧪 Tests

Full Changelog: v1.9.4...v2.0.0-alpha

Read Entire Article