npm leaflet 2.0.0-alpha
v2.0.0-alpha

latest release: 2.0.0-alpha.1
3 months ago

⚡ 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/leaflet@1.9.4/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/leaflet@2.0.0-alpha1/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/leaflet@2.0.0-alpha1/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

  • Disable zoom animation for Line/PolyUtil tests by @mourner in #8478
  • Fix test on mac changes the option 'wheelPxPerZoomLevel' by @Falke-Design in #8481
  • Make test runner output cleaner by @mourner in #8480
  • Add slow test stats and make some tests faster by @mourner in #8486
  • Added tests for panInsideBounds by @mikelowe5919 in #8429
  • Added testing for mouseEventLatLng by @spatterss135 in #8403
  • Update tests index.html and add missing RectangleSpec by @Falke-Design in #8499
  • Add test for map stopLocate (#8371) by @raychanks in #8505
  • Added test cases for Map:addHandler method by @precious-void in #8503
  • Added test cases for Map:mouseEventToContainerPoint method. by @kreloaded in #8406
  • Cover Map Locate with Unit Tests by @stephenspol in #8424
  • Add getWheelPxFactor and fix test changes the option 'wheelPxPerZoomLevel' for mac by @Falke-Design in #8512
  • Speed up PathSpec's "Add layer inside move handler" test: 611ms to 5ms (122x faster) by @rjackson in #8518
  • Speed up tests Map.ScrollWheelZoomSpec and Map.DoubleClickZoomSpec by @rjackson in #8519
  • Add panBy test by @adrianaris in #8420
  • Speed up tests relating to focusing on Marker by @rjackson in #8545
  • Speed up TileLayer.setUrl test (251ms to 13ms) by @rjackson in #8546
  • Speed up tests relating to containerPoint / layerPoint methods by @rjackson in #8544
  • Adding tests for 'layerPointToLatLng' method #8375 by @ANaphade in #8435
  • Refactor Event handling and happen.js by @Falke-Design in #8760
  • Added two more test cases for the unproject map method by @snehalvibhute in #8637
  • Replace expect.js with Chai by @jonkoops in #8952
  • Import Leaflet in tests using JavaScript modules by @jonkoops in #8975
  • Update ui-event-simulator and import as JavaScript module by @jonkoops in #8977
  • Add tests for BoxZoom by @Falke-Design in #9032
  • Fix CI tests to not depend on big Chrome window size by @mourner in #9235
  • Use explicit imports chai and sinon in the test suite by @jonkoops in #9284
  • Set Chrome window size to fix failing test in ubuntu by @Falke-Design in #9604
  • add test for project method by @AshwinNema in #9303
  • Add demo for all GeoJSON types by @simon04 in #9679
  • Vector Drift Test Pinch Zoom Fix by @stephenspol in #8644
  • Convert control layers debug page to ESM by @jonkoops in #8832
  • Convert canvas debug page to ESM by @jonkoops in #8830
  • Convert geolocation debug page to ESM by @jonkoops in #8835
  • Convert controls debug page to ESM by @jonkoops in #8834
  • Convert map debug pages to ESM by @jonkoops in #8838
  • Convert test debug pages to ESM by @jonkoops in #8921
  • Convert vector debug pages to ESM by @jonkoops in #8924
  • Use import maps to load Leaflet in the debug directory by @jonkoops in #8926
  • flyToBounds tests added by @shreya024 in #9112
  • Add test for map stop (#8369) by @victorpatru in #8581

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

Don't miss a new leaflet release

NewReleases is sending notifications on new releases.