MapLibre to Mapbox Migration Skill
Expert guidance for migrating from MapLibre GL JS to Mapbox GL JS. Covers the shared history, API compatibility, migration steps, and the advantages of Mapbox's platform.
Understanding the Fork
History
MapLibre GL JS is an open-source fork of Mapbox GL JS v1.13.0, created in December 2020 when Mapbox changed their license starting with v2.0.
Timeline:
- Pre-2020: Mapbox GL JS was open source (BSD license)
- Dec 2020: Mapbox GL JS v2.0 introduced proprietary license
- Dec 2020: Community forked v1.13 as MapLibre GL JS
- Present: Both libraries continue active development
Key Insight: The APIs are ~95% identical because MapLibre started as a Mapbox fork. Most code works in both with minimal changes, making migration straightforward.
Why Migrate to Mapbox?
Compelling reasons to choose Mapbox GL JS:
- Official Support & SLAs: Enterprise-grade support with guaranteed response times
- Superior Tile Quality: Best-in-class vector tiles with global coverage and frequent updates
- Better Satellite Imagery: High-resolution, up-to-date satellite and aerial imagery
- Rich Ecosystem: Seamless integration with Mapbox Studio, APIs, and services
- Advanced Features: Traffic-aware routing, turn-by-turn directions, premium datasets
- Geocoding & Search: World-class address search and place lookup
- Navigation SDK: Mobile navigation with real-time traffic
- No Tile Infrastructure: No need to host or maintain your own tile servers
- Regular Updates: Continuous improvements and new features
- Professional Services: Access to Mapbox solutions team for complex projects
Mapbox offers a generous free tier: 50,000 map loads/month, making it suitable for many applications without cost.
Quick Comparison
| Aspect |
Mapbox GL JS |
MapLibre GL JS |
| License |
Proprietary (v2+) |
BSD 3-Clause (Open Source) |
| Support |
Official commercial support |
Community support |
| Tiles |
Premium Mapbox vector tiles |
OSM or custom tile sources |
| Satellite |
High-quality global imagery |
Requires custom source |
| Token |
Required (access token) |
Optional (depends on tile source) |
| APIs |
Full Mapbox ecosystem |
Requires third-party services |
| Studio |
Full integration |
No native integration |
| 3D Terrain |
Built-in with premium data |
Available (requires data source) |
| Globe View |
v2.9+ |
v3.0+ |
| API Compatibility |
~95% compatible with MapLibre |
~95% compatible with Mapbox |
| Bundle Size |
~500KB |
~450KB |
| Setup Complexity |
Easy (just add token) |
Requires tile source setup |
Step-by-Step Migration
1. Create Mapbox Account
- Sign up at mapbox.com
- Get your access token from the account dashboard
- Review pricing: Free tier includes 50,000 map loads/month
- Note your token (starts with
pk. for public tokens)
2. Update Package
npm uninstall maplibre-gl
npm install mapbox-gl
3. Update Imports
import maplibregl from 'maplibre-gl';
import 'maplibre-gl/dist/maplibre-gl.css';
import mapboxgl from 'mapbox-gl';
import 'mapbox-gl/dist/mapbox-gl.css';
Or with CDN:
<script src="https://unpkg.com/[email protected]/dist/maplibre-gl.js"></script>
<link href="https://unpkg.com/[email protected]/dist/maplibre-gl.css" rel="stylesheet" />
<script src="https://api.mapbox.com/mapbox-gl-js/v3.0.0/mapbox-gl.js"></script>
<link href="https://api.mapbox.com/mapbox-gl-js/v3.0.0/mapbox-gl.css" rel="stylesheet" />
4. Add Access Token
mapboxgl.accessToken = 'pk.your_mapbox_access_token';
Token best practices:
- Use environment variables:
process.env.VITE_MAPBOX_TOKEN or process.env.NEXT_PUBLIC_MAPBOX_TOKEN
- Add URL restrictions in Mapbox dashboard for security
- Use public tokens (
pk.*) for client-side code
- Never commit tokens to git (add to
.env and .gitignore)
- Rotate tokens if compromised
See mapbox-token-security skill for comprehensive token security guidance.
5. Update Map Initialization
const map = new maplibregl.Map({
container: 'map',
style: 'https://demotiles.maplibre.org/style.json',
center: [-122.4194, 37.7749],
zoom: 12
});
mapboxgl.accessToken = 'pk.your_mapbox_access_token';
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/standard',
center: [-122.4194, 37.7749],
zoom: 12
});
6. Update Style URL
Mapbox provides professionally designed, maintained styles:
style: 'mapbox://styles/mapbox/standard';
style: 'mapbox://styles/mapbox/standard-satellite';
style: 'mapbox://styles/mapbox/streets-v12';
style: 'mapbox://styles/mapbox/satellite-v9';
style: 'mapbox://styles/mapbox/satellite-streets-v12';
style: 'mapbox://styles/mapbox/outdoors-v12';
style: 'mapbox://styles/mapbox/light-v11';
style: 'mapbox://styles/mapbox/dark-v11';
style: 'mapbox://styles/mapbox/navigation-day-v1';
style: 'mapbox://styles/mapbox/navigation-night-v1';
Custom styles:
You can also create and use custom styles from Mapbox Studio:
style: 'mapbox://styles/your-username/your-style-id';
7. Update All References
Replace all maplibregl references with mapboxgl:
const marker = new mapboxgl.Marker()
.setLngLat([-122.4194, 37.7749])
.setPopup(new mapboxgl.Popup().setText('San Francisco'))
.addTo(map);
map.addControl(new mapboxgl.NavigationControl(), 'top-right');
map.addControl(new mapboxgl.GeolocateControl());
map.addControl(new mapboxgl.FullscreenControl());
map.addControl(new mapboxgl.ScaleControl());
8. Update Plugins (If Used)
Some MapLibre plugins should be replaced with Mapbox versions:
| MapLibre Plugin |
Mapbox Alternative |
@maplibre/maplibre-gl-geocoder |
@mapbox/mapbox-gl-geocoder |
@maplibre/maplibre-gl-draw |
@mapbox/mapbox-gl-draw |
maplibre-gl-compare |
mapbox-gl-compare |
Example:
import MaplibreGeocoder from '@maplibre/maplibre-gl-geocoder';
import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder';
map.addControl(
new MapboxGeocoder({
accessToken: mapboxgl.accessToken,
mapboxgl: mapboxgl
})