All skills
mapbox avatar

/mapbox-maplibre-migration

@9077a82 official
by mapboxmapbox/mapbox-agent-skills80 stars
17

Guide for migrating from MapLibre GL JS to Mapbox GL JS, covering API compatibility, token setup, style configuration, and the benefits of Mapbox's official support and ecosystem

Use this Skill: https://skilld.dev/gh/mapbox/mapbox-agent-skills/mapbox-maplibre-migration

This session only. Nothing lands on disk.

AGENTS.md

≈2.1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

MapLibre to Mapbox Migration Guide

Quick reference for migrating from MapLibre GL JS to Mapbox GL JS. APIs are ~95% identical - migration is straightforward.

Why Migrate to Mapbox?

Key advantages:

  • ✅ Official support and SLAs
  • ✅ Premium global tile coverage (streets, satellite, terrain)
  • ✅ Mapbox APIs (Geocoding, Directions, Isochrone, Matrix)
  • ✅ Mapbox Studio for custom styles (no coding required)
  • ✅ Advanced features (Globe view, 3D terrain, better satellite)
  • ✅ No infrastructure management (hosted tiles)
  • ✅ Predictable costs, free tier: 50,000 map loads/month
  • ✅ Enterprise features (compliance, analytics, support)

Migration Overview

Aspect MapLibre GL JS (Current) Mapbox GL JS (Target)
Package maplibre-gl mapbox-gl
Token Optional Required (pk.*)
Styles Custom URL / OSM mapbox://styles/...
Tiles OSM / Custom Mapbox premium tiles
Support Community Official + SLA
APIs Separate Integrated ecosystem
API Compatibility ~95% identical ~95% identical

Key insight: Most of your code stays the same. Only packaging and configuration changes.

Step-by-Step Migration

1. Get Mapbox Access Token

# Sign up at mapbox.com
# Get token from account dashboard
# Free tier: 50,000 map loads/month

2. Update Package

npm uninstall maplibre-gl
npm install mapbox-gl

3. Update Imports

// Before (MapLibre)
import maplibregl from 'maplibre-gl';
import 'maplibre-gl/dist/maplibre-gl.css';

// After (Mapbox)
import mapboxgl from 'mapbox-gl';
import 'mapbox-gl/dist/mapbox-gl.css';

4. Add Access Token

// Required for Mapbox
mapboxgl.accessToken = 'pk.your_mapbox_token';

// Best practice: Use environment variables
mapboxgl.accessToken = process.env.NEXT_PUBLIC_MAPBOX_TOKEN;

5. Update Map Initialization

// Before (MapLibre with OSM tiles)
const map = new maplibregl.Map({
  container: 'map',
  style: 'https://demotiles.maplibre.org/style.json',
  center: [-122.4194, 37.7749],
  zoom: 12
});

// After (Mapbox with premium tiles)
const map = new mapboxgl.Map({
  container: 'map',
  style: 'mapbox://styles/mapbox/streets-v12', // Or any Mapbox style
  center: [-122.4194, 37.7749],
  zoom: 12
});

6. Everything Else Stays the Same!

// All these work identically:
map.setCenter([lng, lat]);
map.setZoom(zoom);
map.fitBounds(bounds);
map.on('click', handler);
new mapboxgl.Marker().setLngLat([lng, lat]).addTo(map);
new mapboxgl.Popup().setHTML(html).addTo(map);
map.addSource(id, source);
map.addLayer(layer);

Mapbox Style Options

Pre-built styles:

'mapbox://styles/mapbox/standard'; // Mapbox Standard
'mapbox://styles/mapbox/standard-satellite'; // Mapbox Standard Satellite
'mapbox://styles/mapbox/streets-v12'; // Streets v12
'mapbox://styles/mapbox/outdoors-v12'; // Hiking/outdoor
'mapbox://styles/mapbox/light-v11'; // Minimal light
'mapbox://styles/mapbox/dark-v11'; // Minimal dark
'mapbox://styles/mapbox/satellite-v9'; // Satellite imagery
'mapbox://styles/mapbox/satellite-streets-v12'; // Satellite + labels
'mapbox://styles/mapbox/navigation-day-v1'; // Turn-by-turn navigation

Custom styles:

  • Create in Mapbox Studio (visual editor)
  • Reference as 'mapbox://styles/your-username/style-id'

Plugin Migration

MapLibre Plugin Mapbox Plugin
@maplibre/maplibre-gl-geocoder @mapbox/mapbox-gl-geocoder
@maplibre/maplibre-gl-draw @mapbox/mapbox-gl-draw
maplibre-gl-compare mapbox-gl-compare

Note: Most Mapbox plugins work directly, no alternatives needed.

Geocoder migration tip: if the original @maplibre/maplibre-gl-geocoder was configured with countries or language, carry those options over to @mapbox/mapbox-gl-geocoder. Both affect which results come back.

API Compatibility (95%+)

100% Compatible APIs:

  • Map methods (all setters/getters)
  • Event handling
  • Markers and Popups
  • Sources and Layers
  • Controls
  • GeoJSON handling
  • Camera animations
  • Feature state

Only differences:

  • Package name (maplibre-gl vs mapbox-gl)
  • Style URL format (custom vs mapbox://)
  • Token requirement (optional vs required)
  • Some plugins need Mapbox versions

Common Issues

Issue: Missing Token

// ❌ Forgot to set token
const map = new mapboxgl.Map({...});  // Error!

// ✅ Set token first
mapboxgl.accessToken = 'pk.your_token';
const map = new mapboxgl.Map({...});

Issue: Wrong Style Format

// ❌ Using OSM/custom URL
style: 'https://demotiles.maplibre.org/style.json'; // Won't load Mapbox tiles

// ✅ Use Mapbox style URL
style: 'mapbox://styles/mapbox/streets-v12';

Issue: Plugin Compatibility

// ❌ Using MapLibre plugin with Mapbox
import MaplibreGeocoder from '@maplibre/maplibre-gl-geocoder';

// ✅ Use Mapbox plugin
import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder';

Testing Checklist

✅ Map initializes without errors ✅ Tiles load correctly (Mapbox tiles, not OSM) ✅ Access token configured ✅ Markers/popups display properly ✅ Events fire as expected ✅ Custom layers render correctly ✅ Plugins work (if using Mapbox versions) ✅ No console errors ✅ Performance same or better

Token Security

Best practices:

// ✅ Use environment variables
mapboxgl.accessToken = process.env.NEXT_PUBLIC_MAPBOX_TOKEN;

// ✅ Add URL restrictions in Mapbox dashboard
// Only allow your domains

// ✅ Never commit tokens
// Add .env to .gitignore

// ✅ Use public tokens (pk.*) for client-side
// Never expose secret tokens (sk.*)

Mapbox Ecosystem Benefits

After migration, you gain access to:

Mapbox APIs:

  • Geocoding API (forward/reverse)
  • Directions API (routing, turn-by-turn)
  • Isochrone API (time/distance polygons)
  • Matrix API (distance matrices)
  • Tilequery API (feature lookup)

Mapbox Studio:

  • Visual style editor (no coding)
  • Dataset editor
  • Tileset management
  • Style publishing

Advanced Features:

  • Globe view (3D Earth)
  • 3D terrain with real elevations
  • Premium satellite imagery
  • Traffic-aware routing
  • Real-time updates

Performance Notes

Mapbox tiles are optimized for:

  • Fast loading (global CDN)
  • Smaller file sizes (vector tiles)
  • Better caching
  • Consistent quality worldwide

Expected performance:

  • Similar or better rendering speed
  • Potentially faster tile loading (Mapbox CDN)
  • Same memory usage
  • Identical frame rates

Migration Timeline

Typical migration: 1-2 hours

  1. Setup (15 min): Get token, update packages
  2. Code changes (30 min): Update imports, add token, change style URL
  3. Testing (30 min): Verify all features work
  4. Deployment (15 min): Deploy and monitor

For large apps: May take 1-2 days including QA

Support & Resources

After migration:

  • Official Mapbox support (for paid plans)
  • Extensive documentation
  • Code examples
  • Community forums
  • Enterprise SLAs (for enterprise plans)

Quick Decision: Should I Migrate?

Migrate to Mapbox if:

  • ✅ Want official support
  • ✅ Need Mapbox APIs (Geocoding, Directions)
  • ✅ Want better tile quality/coverage
  • ✅ Prefer no infrastructure management
  • ✅ Need enterprise features
  • ✅ Want Mapbox Studio for styling
  • ✅ Building production applications

Free tier (50K loads/month) is often sufficient for:

  • Small-medium websites
  • Internal tools
  • MVPs and prototypes
  • Many business applications

Migration is Low Risk

✅ ~95% API compatibility = minimal code changes ✅ Quick migration (1-2 hours typical) ✅ Free tier available for testing ✅ Easy to rollback if needed ✅ No data loss (just configuration changes)

Source: SKILL.md on GitHub

No alerts14d5 checks · Risk SAFE
  • Gen Agent Trust Hub14d

    The skill is a legitimate technical guide for migrating from MapLibre GL JS to Mapbox GL JS. It follows industry best practices, provides clear security guidance regarding API token management, and utilizes official Mapbox resources.

  • Socket14d

    No alerts

  • Snyk14d

    Risk: LOW · No issues

  • Runlayer6mo

    2/2 files flagged

  • ZeroLeaks5mo

    1 finding · Score: 82/100

Signed by skilld at 9077a82. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 9 hours ago.

Activeupdated 2 weeks ago
  • mapbox
  • maplibre
  • migration
  • gl-js
  • mapping
  • cartography
  • vector-tiles
  • web-mapping

README badge

README badge for mapbox/mapbox-agent-skills/mapbox-maplibre-migration

Guides migration from MapLibre GL JS to Mapbox GL JS, detailing the ~95% API compatibility, token setup, style configuration, and the transition path for plugins and dependencies. Covers account creation, package updates, environment variable management, and common migration pitfalls like token security and CDN URLs.

Generated from the current SKILL.md.

Does the API stay the same when migrating from MapLibre to Mapbox?
Yes, the APIs are approximately 95% identical because MapLibre forked from Mapbox GL JS v1.13.0. All map methods, events, layers, sources, markers, and controls work exactly the same — only imports, the token setup, and style URLs need to change.
What do I need to change in my code to migrate?
You must change the package name (maplibre-gl to mapbox-gl), update imports, set mapboxgl.accessToken before map initialization, switch style URLs to mapbox:// format, and replace any @maplibre/* plugins with their Mapbox equivalents. Everything else stays the same.
Do I need to pay to use Mapbox GL JS?
Mapbox offers a generous free tier with 50,000 map loads per month. You only pay for usage beyond that, making it suitable for many applications without cost.
How do I securely manage my Mapbox access token?
Store your token in a .env file and set it before map initialization using an environment variable (e.g., process.env.VITE_MAPBOX_TOKEN). Add .env to .gitignore to prevent committing tokens to git, and configure URL restrictions in the Mapbox dashboard for additional security.
What happens to my custom styles and layers when migrating?
Your custom styling, GeoJSON handling, layer definitions, and expressions work identically in both libraries. You can continue using custom styles from Mapbox Studio or switch to Mapbox's built-in professionally maintained styles.

Generated from the current SKILL.md. These answers refresh after source changes.