此技能为直截了当的迁移指南,内部逻辑一致。使用前请注意:(1)安全存储 Mapbox 令牌;(2)审查 Mapbox 许可和定价;(3)验证 API 调用令牌。若指南后续请求无关凭据或执行可疑操作,请停止并重新评估。...
详细分析 ▾
✓用途与能力
The name and description (migrating from MapLibre GL JS to Mapbox GL JS) match the content: package swap, import changes, token usage, style URLs, plugin mappings, and API compatibility. Nothing requested (no env vars, no binaries, no config paths) is unrelated to this documented purpose.
✓指令范围
SKILL.md contains only migration instructions, code examples, and best practices for token handling. It references calling Mapbox APIs (api.mapbox.com) in examples — expected for a Mapbox migration guide — and does not instruct the agent to read unrelated files, harvest credentials, or send data to unexpected endpoints. It references another skill (mapbox-token-security) for deeper guidance; that is a cross-reference, not hidden behavior.
✓安装机制
This is an instruction-only skill with no install spec and no code files that would be executed. No downloads, archive extraction, or package installs are performed by the skill itself; npm install steps are guidance for the developer and are proportionate to the migration task.
✓凭证需求
The guide explains how to use Mapbox access tokens and recommends storing them in environment variables and restricting them appropriately. It does not request any environment variables or secrets from the platform and does not ask for unrelated credentials or elevated access.
✓持久化与权限
The skill does not request persistent presence (always: false) and does not modify agent/system configuration. Autonomous invocation is allowed by default but this is normal for skills; there are no additional privileges or persistent behaviors requested.
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
// All map methods work the same
map.setCenter([lng, lat]);
map.setZoom(12);
map.fitBounds(bounds);
map.flyTo({ center: [lng, lat], zoom: 14 });
What Changes: Summary
Must change:
Package name (maplibre-gl -> mapbox-gl)
Import statements
Add mapboxgl.accessToken configuration
Style URL (switch to mapbox:// styles)
Plugin packages (if used)
Stays exactly the same:
All map methods (setCenter, setZoom, fitBounds, flyTo, etc.)
All event handling (map.on('click'), map.on('load'), etc.)
Marker/Popup APIs (100% compatible)
Layer/source APIs (100% compatible)
GeoJSON handling
Custom styling and expressions
Controls (Navigation, Geolocate, Scale, etc.)
Common Migration Issues
Issue 1: Token Not Set
Problem:
// Error: "A valid Mapbox access token is required to use Mapbox GL"
const map = new mapboxgl.Map({...});
Solution:
// Set token BEFORE creating map
mapboxgl.accessToken = 'pk.your_token';
const map = new mapboxgl.Map({...});
Issue 2: Token in Git
Problem:
// Token hardcoded in source
mapboxgl.accessToken = 'pk.eyJ1Ijoi...';
Solution:
// Use environment variables
mapboxgl.accessToken = process.env.VITE_MAPBOX_TOKEN;
// Add to .env file (not committed to git)
VITE_MAPBOX_TOKEN=pk.your_token
// Add .env to .gitignore
echo ".env" >> .gitignore
Issue 3: Wrong Style URL Format
Problem:
// MapLibre-style URL won't work optimally
style: 'https://demotiles.maplibre.org/style.json';
Solution:
// Use Mapbox style URL for better performance and features
style: 'mapbox://styles/mapbox/streets-v12';
Issue 4: Plugin Compatibility
Problem:
// MapLibre plugin won't work
import MaplibreGeocoder from '@maplibre/maplibre-gl-geocoder';
Solution:
// Use Mapbox plugin
import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder';
Important: This applies to ALL MapLibre plugins, not just the geocoder. Any @maplibre/ or maplibre-gl-* plugin must be replaced with its Mapbox equivalent. Check the Mapbox ecosystem for Mapbox-specific versions of every plugin you use (see Step 8 above for the full mapping table).
[ ] Configure token security: Add URL restrictions in dashboard
[ ] Test all functionality: Verify map loads, interactions work
[ ] Set up billing alerts: Monitor usage in Mapbox dashboard
[ ] Update documentation: Document token setup for team
[ ] Add .env to .gitignore: Ensure tokens not committed
Quick Reference
Key Differences Summary
What
MapLibre
Mapbox
Package
maplibre-gl
mapbox-gl
Import
import maplibregl from 'maplibre-gl'
import mapboxgl from 'mapbox-gl'
Token
Optional (depends on tiles)
Required: mapboxgl.accessToken = 'pk.xxx'
Style
Custom URL or OSM tiles
mapbox://styles/mapbox/streets-v12
License
BSD (Open Source)
Proprietary (v2+)
Support
Community
Official commercial support
Tiles
Requires tile source
Premium Mapbox tiles included
APIs
Third-party
Full Mapbox API ecosystem
API
~95% compatible
~95% compatible
Bottom line: Migration is easy because APIs are nearly identical. Main changes are packaging, token setup, and style URLs. The result is access to Mapbox's premium tiles, ecosystem, and support.