maplibre-native
MapLibre Native - Interactive vector tile maps for iOS, Android and other platforms.
Top Related Projects
Interactive, thoroughly customizable maps in native Android, iOS, macOS, Node.js, and Qt applications, powered by vector tiles and OpenGL
Vector and raster maps with GL styles. Server side rendering by MapLibre GL Native. Map tile server for MapLibre GL JS, Android, iOS, Leaflet, OpenLayers, GIS via WMTS, etc.
OpenLayers
π JavaScript library for mobile-friendly interactive maps πΊπ¦
WebGL2 powered visualization framework
An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
Quick Overview
MapLibre Native is an open-source mapping library for mobile and desktop platforms. It provides a powerful SDK for rendering interactive maps, similar to Mapbox GL Native, but with a focus on being free and open-source. MapLibre Native supports various platforms including iOS, Android, macOS, and Linux.
Pros
- Free and open-source alternative to proprietary mapping solutions
- Cross-platform support (iOS, Android, macOS, Linux)
- High-performance vector tile rendering
- Active community and regular updates
Cons
- Less extensive documentation compared to some commercial alternatives
- Smaller ecosystem of plugins and extensions
- May require more technical expertise to implement and customize
- Limited official support options
Code Examples
- Initializing a map view (iOS):
import Mapbox
let mapView = MGLMapView(frame: view.bounds)
mapView.styleURL = URL(string: "https://demotiles.maplibre.org/style.json")
view.addSubview(mapView)
- Adding a marker to the map (Android):
val symbolManager = SymbolManager(mapView, mapboxMap, style)
symbolManager.iconAllowOverlap = true
val symbol = SymbolOptions()
.withLatLng(LatLng(40.7128, -74.0060))
.withIconImage("marker-icon")
.withIconSize(1.5f)
symbolManager.create(symbol)
- Changing map style (JavaScript):
map.setStyle('https://demotiles.maplibre.org/style.json');
Getting Started
To get started with MapLibre Native, follow these steps:
-
Add the MapLibre Native dependency to your project:
For iOS (CocoaPods):
pod 'Mapbox-iOS-SDK', :git => 'https://github.com/maplibre/maplibre-native-ios.git', :tag => 'ios-v5.12.0'
For Android (Gradle):
implementation 'org.maplibre.gl:android-sdk:9.5.2'
-
Initialize a map view in your app:
iOS:
import Mapbox let mapView = MGLMapView(frame: view.bounds) mapView.styleURL = URL(string: "https://demotiles.maplibre.org/style.json") view.addSubview(mapView)
Android:
import com.mapbox.mapboxsdk.Mapbox import com.mapbox.mapboxsdk.maps.MapView val mapView = findViewById<MapView>(R.id.mapView) mapView.getMapAsync { mapboxMap -> mapboxMap.setStyle("https://demotiles.maplibre.org/style.json") }
-
Customize the map and add features as needed using the MapLibre Native SDK.
Competitor Comparisons
Interactive, thoroughly customizable maps in native Android, iOS, macOS, Node.js, and Qt applications, powered by vector tiles and OpenGL
Pros of mapbox-gl-native
- More extensive documentation and examples
- Wider range of supported platforms and devices
- Larger community and ecosystem of tools/plugins
Cons of mapbox-gl-native
- Proprietary license with usage restrictions
- Potential vendor lock-in
- Less flexibility for customization and modification
Code Comparison
mapbox-gl-native:
#include <mbgl/map/map.hpp>
#include <mbgl/style/style.hpp>
mbgl::Map map(view);
map.getStyle().loadJSON(jsonStyle);
map.setCenter(mbgl::LatLng(latitude, longitude));
maplibre-native:
#include <mbgl/map/map.hpp>
#include <mbgl/style/style.hpp>
mbgl::Map map(view);
map.getStyle().loadJSON(jsonStyle);
map.setCenter(mbgl::LatLng(latitude, longitude));
The code structure and API are very similar between the two projects, as MapLibre was forked from Mapbox GL Native. The main differences lie in the project setup, dependencies, and available features rather than the core API usage.
MapLibre Native offers an open-source alternative to Mapbox GL Native, providing similar functionality with more freedom for customization and commercial use. However, it may lack some advanced features and has a smaller ecosystem compared to Mapbox's offering.
Vector and raster maps with GL styles. Server side rendering by MapLibre GL Native. Map tile server for MapLibre GL JS, Android, iOS, Leaflet, OpenLayers, GIS via WMTS, etc.
Pros of tileserver-gl
- Lightweight and easy to set up for serving vector tiles
- Supports multiple data sources and styles out of the box
- Includes a built-in viewer for previewing maps
Cons of tileserver-gl
- Limited to serving tiles and styles, not a full mapping SDK
- Less flexibility for custom rendering and interactions
- Smaller community and fewer extensions compared to maplibre-native
Code Comparison
maplibre-native:
#include <mbgl/map/map.hpp>
#include <mbgl/style/style.hpp>
mbgl::Map map(view);
map.getStyle().loadURL("mapbox://styles/mapbox/streets-v11");
tileserver-gl:
const tileserver = require('tileserver-gl');
const config = {
styles: ['styles/osm-bright/style.json'],
data: { 'osm': { mbtiles: 'data/osm.mbtiles' } }
};
tileserver(config);
While maplibre-native provides a full-featured mapping SDK for rendering and interacting with maps, tileserver-gl focuses on serving vector tiles and styles. maplibre-native offers more control over the map rendering process, while tileserver-gl simplifies the process of setting up a tile server with minimal configuration.
OpenLayers
Pros of OpenLayers
- More comprehensive and feature-rich for web-based mapping applications
- Supports a wider range of data formats and projections
- Larger community and more extensive documentation
Cons of OpenLayers
- Steeper learning curve due to its extensive API
- Larger file size, which may impact load times for web applications
- Less suitable for mobile or native applications compared to MapLibre Native
Code Comparison
OpenLayers:
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import OSM from 'ol/source/OSM';
const map = new Map({
target: 'map',
layers: [new TileLayer({ source: new OSM() })],
view: new View({ center: [0, 0], zoom: 2 })
});
MapLibre Native:
#include <mbgl/map/map.hpp>
#include <mbgl/style/style.hpp>
auto map = std::make_unique<mbgl::Map>(view, resourceOptions);
map->getStyle().loadJSON(jsonStyle);
map->setCenter(mbgl::LatLng{0, 0});
map->setZoom(2);
Both libraries offer powerful mapping capabilities, but they cater to different use cases. OpenLayers is more suited for web-based applications with complex mapping requirements, while MapLibre Native is better for native mobile and desktop applications that require high performance and offline capabilities.
π JavaScript library for mobile-friendly interactive maps πΊπ¦
Pros of Leaflet
- Lightweight and simple to use, with a gentle learning curve
- Extensive plugin ecosystem for added functionality
- Better suited for basic web mapping applications
Cons of Leaflet
- Limited 3D mapping capabilities
- Less performant with large datasets or complex visualizations
- Fewer built-in advanced features compared to MapLibre Native
Code Comparison
Leaflet:
var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'Β© OpenStreetMap contributors'
}).addTo(map);
MapLibre Native:
var map = new maplibregl.Map({
container: 'map',
style: 'https://demotiles.maplibre.org/style.json',
center: [-0.09, 51.505],
zoom: 13
});
Key Differences
- MapLibre Native offers more advanced features and better performance for complex maps
- Leaflet is easier to set up and use for simple web mapping projects
- MapLibre Native provides better support for vector tiles and 3D mapping
- Leaflet has a larger community and more third-party plugins available
WebGL2 powered visualization framework
Pros of deck.gl
- Highly customizable and extensible WebGL-powered visualization framework
- Supports a wide range of data visualization types, including 3D
- Integrates well with React and other modern web frameworks
Cons of deck.gl
- Steeper learning curve for developers new to WebGL or advanced data visualization
- May have higher performance overhead for simpler map visualizations
- Less focused on traditional mapping features compared to MapLibre Native
Code Comparison
deck.gl:
import {Deck} from '@deck.gl/core';
import {GeoJsonLayer} from '@deck.gl/layers';
new Deck({
layers: [new GeoJsonLayer({id: 'geojson', data: GEOJSON_DATA})]
});
MapLibre Native:
var map = new maplibregl.Map({
container: 'map',
style: 'https://demotiles.maplibre.org/style.json',
center: [-74.5, 40],
zoom: 9
});
Summary
deck.gl is a powerful data visualization library that excels in creating complex, interactive visualizations, particularly for large datasets. It offers more flexibility in terms of custom rendering and data processing. MapLibre Native, on the other hand, is more focused on traditional mapping capabilities and may be easier to set up for basic map applications. The choice between the two depends on the specific requirements of your project, such as the complexity of visualizations needed and the level of customization required.
An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
Pros of Cesium
- Specializes in 3D geospatial visualization, offering advanced terrain rendering and globe-based mapping
- Supports time-dynamic data and animations, ideal for temporal geospatial analysis
- Extensive documentation and active community support
Cons of Cesium
- Steeper learning curve due to its focus on 3D and complex geospatial features
- Larger file size and potentially higher resource consumption compared to 2D-focused libraries
Code Comparison
MapLibre Native (C++):
#include <mbgl/map/map.hpp>
#include <mbgl/style/style.hpp>
mbgl::Map map(view);
map.getStyle().loadJSON(jsonStyle);
map.setCenter(mbgl::LatLng(latitude, longitude));
map.setZoom(zoomLevel);
Cesium (JavaScript):
const viewer = new Cesium.Viewer('cesiumContainer');
viewer.scene.camera.setView({
destination: Cesium.Cartesian3.fromDegrees(longitude, latitude, height),
orientation: {
heading: Cesium.Math.toRadians(heading),
pitch: Cesium.Math.toRadians(pitch),
roll: 0.0
}
});
Both libraries offer powerful mapping capabilities, but Cesium focuses on 3D visualization while MapLibre Native provides a more lightweight 2D mapping solution. Cesium excels in complex geospatial scenarios, while MapLibre Native is better suited for simpler 2D map applications with lower resource requirements.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
MapLibre Native
MapLibre Native is a free and open-source library for publishing maps in your apps and desktop applications on various platforms. Fast displaying of maps is possible thanks to GPU-accelerated vector tile rendering.
This project originated as a fork of Mapbox GL Native, before their switch to a non-OSS license in December 2020. For more information, see: FORK.md
.
Getting Started
Android
Add the latest version of MapLibre Native Android as a dependency to your project.
dependencies {
...
implementation 'org.maplibre.gl:android-sdk:11.5.1'
...
}
Add a MapView
to your layout XML file:
<org.maplibre.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
[!TIP] There are external projects such as Ramani Maps and MapLibre Compose Playground available to intergrate MapLibre Native Android with Compose-based projects.
Next, initialize the map in an activity:
Show code
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.LayoutInflater
import org.maplibre.android.Maplibre
import org.maplibre.android.camera.CameraPosition
import org.maplibre.android.geometry.LatLng
import org.maplibre.android.maps.MapView
import org.maplibre.android.testapp.R
class MainActivity : AppCompatActivity() {
// Declare a variable for MapView
private lateinit var mapView: MapView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Init MapLibre
MapLibre.getInstance(this)
// Init layout view
val inflater = LayoutInflater.from(this)
val rootView = inflater.inflate(R.layout.activity_main, null)
setContentView(rootView)
// Init the MapView
mapView = rootView.findViewById(R.id.mapView)
mapView.getMapAsync { map ->
map.setStyle("https://demotiles.maplibre.org/style.json")
map.cameraPosition = CameraPosition.Builder().target(LatLng(0.0,0.0)).zoom(1.0).build()
}
}
override fun onStart() {
super.onStart()
mapView.onStart()
}
override fun onResume() {
super.onResume()
mapView.onResume()
}
override fun onPause() {
super.onPause()
mapView.onPause()
}
override fun onStop() {
super.onStop()
mapView.onStop()
}
override fun onLowMemory() {
super.onLowMemory()
mapView.onLowMemory()
}
override fun onDestroy() {
super.onDestroy()
mapView.onDestroy()
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
mapView.onSaveInstanceState(outState)
}
}
For more information, refer to the Android API Documentation, Android Examples Documentation or the MapLibre Native Android README.md
.
iOS
You can find MapLibre Native iOS on Cocoapods and on the Swift Package Index. You can also MapLibre Native iOS as a dependency to Xcode directly.
MapLibre Native iOS uses UIKit. To intergrate it with an UIKit project, you can use
class SimpleMap: UIViewController, MLNMapViewDelegate {
var mapView: MLNMapView!
override func viewDidLoad() {
super.viewDidLoad()
mapView = MLNMapView(frame: view.bounds)
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(mapView)
mapView.delegate = self
}
func mapView(_: MLNMapView, didFinishLoading _: MLNStyle) {
}
}
You need to create a wrapper when using SwiftUI.
import MapLibre
struct SimpleMap: UIViewRepresentable {
func makeUIView(context _: Context) -> MLNMapView {
let mapView = MLNMapView()
return mapView
}
func updateUIView(_: MLNMapView, context _: Context) {}
}
You can also use MapLibreSwiftUI, a wrapper around MapLibre Native iOS that offers a declarative API like SwiftUI.
The iOS Documentation contains many examples and the entire API of the library. You might also want to check out the MapLibre Native iOS README.md
.
Node.js
There is an npm package for using MapLibre Native in a Node.js project. The source code of this project can be found in this repository.
Qt
Please check out the maplibre/maplibre-native-qt
repository to learn how to intergrate MapLibre Native with a Qt project.
Other Platforms
MapLibre Native can also be built on Linux, Windows and macOS.
Contributing
[!NOTE]
This section is only relevant for people who want to contribute to MapLibre Native.
MapLibre Native has at its core a C++ library. This is where the bulk of development is currently happening.
To get started with the code base, you need to clone the the repository including all its submodules.
All contributors use pull requests from a private fork. Fork the project. Then run:
git clone --recurse-submodules git@github.com:<YOUR NAME>/maplibre-native.git
git remote add origin https://github.com/maplibre/maplibre-native.git
Check out issues labelled as a good first issue.
Core
CONTRIBUTING.md
- MapLibre Native Markdown Book: architectural notes
- GitHub Wiki: low-friction way to share information with the community
- Core C++ API Documentation (unstable)
Android
Open platform/android
with Android Studio.
More information: platform/android/DEVELOPING.md
.
iOS
You need to use Bazel to generate an Xcode project. Install bazelisk
(a wrapper that installs the required Bazel version). Next, use:
bazel run //platform/ios:xcodeproj --@rules_xcodeproj//xcodeproj:extra_common_flags="--//:renderer=metal"
xed platform/ios/MapLibre.xcodeproj
To generate and open the Xcode project.
More information: platform/android/CONTRIBUTING.md
.
Other Platforms
See /platform
and navigate to the platform you are interested in for more information.
Getting Involved
Join the #maplibre-native
Slack channel at OSMUS. Get an invite at https://slack.openstreetmap.us/
Bounties Γ°ΒΒΒ°
Thanks to our sponsors, we are able to award bounties to developers making contributions toward certain bounty directions. To get started doing bounties, refer to the step-by-step bounties guide.
We thank everyone who supported us financially in the past and special thanks to the people and organizations who support us with recurring donations!
Read more about the MapLibre Sponsorship Program at https://maplibre.org/sponsors/.
Gold:
Silver:
Backers and Supporters:
License
MapLibre Native is licensed under the BSD 2-Clause License.
Top Related Projects
Interactive, thoroughly customizable maps in native Android, iOS, macOS, Node.js, and Qt applications, powered by vector tiles and OpenGL
Vector and raster maps with GL styles. Server side rendering by MapLibre GL Native. Map tile server for MapLibre GL JS, Android, iOS, Leaflet, OpenLayers, GIS via WMTS, etc.
OpenLayers
π JavaScript library for mobile-friendly interactive maps πΊπ¦
WebGL2 powered visualization framework
An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot