What is maplibre-gl?
MapLibre GL is a JavaScript library for interactive, customizable vector maps on the web. It is a community-driven fork of Mapbox GL JS, providing similar functionalities for rendering maps and handling user interactions.
What are maplibre-gl's main functionalities?
Display a Map
This code initializes a basic map using MapLibre GL. It sets the container, style, center, and zoom level for the map.
const map = new maplibregl.Map({
container: 'map', // container ID
style: 'https://demotiles.maplibre.org/style.json', // style URL
center: [0, 0], // starting position [lng, lat]
zoom: 2 // starting zoom
});
Add a Marker
This code adds a marker to the map at the specified longitude and latitude.
const marker = new maplibregl.Marker()
.setLngLat([0, 0])
.addTo(map);
Add a Popup
This code adds a popup to the map at the specified longitude and latitude with custom HTML content.
const popup = new maplibregl.Popup({ closeOnClick: false })
.setLngLat([0, 0])
.setHTML('<h1>Hello World!</h1>')
.addTo(map);
Draw a Line
This code draws a line on the map using GeoJSON data. It adds a source and a layer to the map to render the line.
map.on('load', function () {
map.addSource('line', {
'type': 'geojson',
'data': {
'type': 'Feature',
'geometry': {
'type': 'LineString',
'coordinates': [
[0, 0],
[10, 10]
]
}
}
});
map.addLayer({
'id': 'line',
'type': 'line',
'source': 'line',
'layout': {},
'paint': {
'line-color': '#888',
'line-width': 8
}
});
});
Other packages similar to maplibre-gl
leaflet
Leaflet is a widely used open-source JavaScript library for mobile-friendly interactive maps. It is lightweight and easy to use, but it primarily supports raster tiles and lacks some of the advanced vector tile functionalities provided by MapLibre GL.
openlayers
OpenLayers is a high-performance, feature-packed library for rendering maps in web applications. It supports both raster and vector tiles and offers extensive customization options. However, it has a steeper learning curve compared to MapLibre GL.
cesium
Cesium is a JavaScript library for creating 3D globes and maps. It is highly suitable for applications requiring 3D visualization and geospatial data. While it offers advanced 3D capabilities, it is more complex and resource-intensive than MapLibre GL.
MapLibre GL
MapLibre GL is a community led fork derived from mapbox-gl-js prior to their switch to a non-OSS license.
Migrating from mapbox-gl
If you depend on mapbox-gl directly, simply replace mapbox-gl
with maplibre-gl
in package.json
:
"dependencies": {
- "mapbox-gl": "^1.13.0"
+ "maplibre-gl": ">=1.13.0-rc.1"
}
Want an example? Try out MapLibre GL on CodePen
If you use mapbox-gl via bindings (react, vue, etc), you may need to wait a little longer as we develop an easy migration path for each binding. Contributions welcome!
Roadmap
This project's initial plans are outlined in the Roadmap project. The primary goal is consistency and backwards-compatability with previous releases and continued bug-fixes and maintenance going forward.
Getting Involved
Join the #maplibre slack channel at OSMUS: get an invite at https://osmus-slack.herokuapp.com/
Avoid Fragmentation
If you depend on a free software alternative to mapbox-gl-js
, please consider joining our effort! Anyone with a stake in a healthy community led fork is welcome to help us figure out our next steps. We welcome contributors and leaders! MapLibre GL already represents the combined efforts of a few early fork efforts, and we all benefit from "one project" rather than "our way". If you know of other forks, please reach out to them and direct them here.
Thank you Mapbox 🙏🏽
We'd like to acknowledge the amazing work Mapbox has contributed to open source. The open source community is sad to part ways with them, but we simultaneously feel grateful for everything they already contributed. mapbox-gl-js
1.x is an open source achievment which now lives on as maplibre-gl
. We're proud to develop on the shoulders of giants, thank you Mapbox 🙇🏽♀️
License
MapLibre GL is licensed under the 3-Clause BSD license.