mapbox-gl-native
Interactive, thoroughly customizable maps in native Android, iOS, macOS, Node.js, and Qt applications, powered by vector tiles and OpenGL
Top Related Projects
MapLibre Native - Interactive vector tile maps for iOS, Android and other platforms.
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
WebGL map rendering engine for creative cartography
Quick Overview
Mapbox GL Native is an open-source library for embedding interactive, customizable vector maps into native applications on multiple platforms. It provides a seamless way to integrate high-performance maps into mobile and desktop applications, supporting both iOS and Android platforms, as well as macOS, Linux, and Qt.
Pros
- High-performance vector rendering for smooth map interactions
- Cross-platform support for iOS, Android, macOS, Linux, and Qt
- Extensive customization options for map styles and features
- Offline map support for use without an internet connection
Cons
- Steeper learning curve compared to some other mapping solutions
- Requires Mapbox account and API key for full functionality
- Limited documentation for some advanced features
- Larger app size due to inclusion of the mapping engine
Code Examples
- Initializing a map view (iOS):
import Mapbox
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let mapView = MGLMapView(frame: view.bounds)
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(mapView)
}
}
- Adding a marker to the map (Android):
import com.mapbox.mapboxsdk.geometry.LatLng
import com.mapbox.mapboxsdk.plugins.annotation.SymbolManager
import com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions
val symbolManager = SymbolManager(mapView, mapboxMap, style)
symbolManager.create(
SymbolOptions()
.withLatLng(LatLng(40.7128, -74.0060))
.withIconImage("marker-icon")
.withIconSize(1.5f)
)
- Changing map style (iOS):
mapView.styleURL = MGLStyle.satelliteStreetsStyleURL
Getting Started
To get started with Mapbox GL Native:
- Sign up for a Mapbox account and obtain an API key.
- Install the SDK for your platform:
- iOS: Use CocoaPods or Carthage
- Android: Add the dependency to your
build.gradle
file
- Initialize the map in your application:
// iOS
import Mapbox
let mapView = MGLMapView(frame: view.bounds)
view.addSubview(mapView)
// Android
import com.mapbox.mapboxsdk.Mapbox
import com.mapbox.mapboxsdk.maps.MapView
Mapbox.getInstance(context, "YOUR_MAPBOX_ACCESS_TOKEN")
val mapView = findViewById<MapView>(R.id.mapView)
mapView.onCreate(savedInstanceState)
- Customize the map and add features as needed.
Competitor Comparisons
MapLibre Native - Interactive vector tile maps for iOS, Android and other platforms.
Pros of maplibre-native
- Open-source and community-driven, allowing for greater flexibility and customization
- Free to use without usage limits or API key requirements
- Actively maintained with regular updates and improvements
Cons of maplibre-native
- Smaller ecosystem and community compared to mapbox-gl-native
- May lack some advanced features and optimizations present in mapbox-gl-native
- Potentially less documentation and support resources available
Code Comparison
maplibre-native:
#include <mbgl/map/map.hpp>
#include <mbgl/style/style.hpp>
mbgl::Map map(view);
map.getStyle().loadJSON(jsonStyle);
mapbox-gl-native:
#include <mbgl/map/map.hpp>
#include <mbgl/style/style.hpp>
mbgl::Map map(view, apiKey);
map.getStyle().loadURL(styleURL);
The main difference in the code is that maplibre-native doesn't require an API key, while mapbox-gl-native does. Additionally, maplibre-native typically loads styles from JSON, whereas mapbox-gl-native often uses style URLs.
Both libraries share similar core functionality and API structure, making it relatively easy to switch between them. However, some features and optimizations may differ, and developers should consider their specific project requirements when choosing between the two.
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
- Open-source and self-hosted solution, offering more control over data and infrastructure
- Supports multiple vector tile formats, including MBTiles and GeoJSON
- Easier setup for local development and testing of map applications
Cons of tileserver-gl
- Limited native mobile support compared to mapbox-gl-native
- Smaller community and fewer resources for troubleshooting
- May require more manual configuration and maintenance
Code Comparison
mapbox-gl-native:
#include <mbgl/map/map.hpp>
#include <mbgl/style/style.hpp>
mbgl::Map map(view);
map.setStyleURL("mapbox://styles/mapbox/streets-v11");
map.setCenter({-122.4194, 37.7749});
map.setZoom(12);
tileserver-gl:
const express = require('express');
const tileserver = require('tileserver-gl');
const app = express();
tileserver.serve({
paths: {
root: __dirname,
styles: './styles',
mbtiles: './data'
}
}, app);
The code snippets demonstrate the different approaches: mapbox-gl-native focuses on client-side rendering and map manipulation, while tileserver-gl is centered around serving tile data and styles to clients. mapbox-gl-native provides a more integrated solution for mobile development, whereas tileserver-gl offers flexibility in serving custom map data and styles through a server-side approach.
OpenLayers
Pros of OpenLayers
- Open-source and free to use without restrictions
- Supports a wide range of data formats and projections
- Extensive documentation and active community support
Cons of OpenLayers
- Steeper learning curve for beginners
- Larger file size compared to Mapbox GL JS
- May require more custom code for advanced features
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({
layers: [new TileLayer({ source: new OSM() })],
target: 'map',
view: new View({ center: [0, 0], zoom: 2 })
});
Mapbox GL Native:
#include <mbgl/map/map.hpp>
#include <mbgl/platform/default/headless_backend.hpp>
#include <mbgl/platform/default/headless_display.hpp>
auto display = std::make_shared<mbgl::HeadlessDisplay>();
mbgl::HeadlessBackend backend { display };
mbgl::Map map { backend, { 256, 256 }, 2 };
Note: The Mapbox GL Native code is in C++, as it's primarily used for native mobile and desktop applications, while OpenLayers is JavaScript-based for web applications. This difference in language and target platforms makes a direct code comparison less straightforward.
π JavaScript library for mobile-friendly interactive maps πΊπ¦
Pros of Leaflet
- Lightweight and simple to use, with a smaller learning curve
- Extensive plugin ecosystem for added functionality
- Open-source with a large community and broad browser support
Cons of Leaflet
- Limited built-in features compared to Mapbox GL
- Less performant for large datasets and complex visualizations
- Lacks native 3D mapping capabilities
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);
Mapbox GL Native:
mapboxgl.accessToken = 'your-access-token';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v11',
center: [-0.09, 51.505],
zoom: 13
});
Both examples initialize a map centered on London, but Mapbox GL Native requires an access token and uses vector tiles by default, while Leaflet uses raster tiles from OpenStreetMap in this example.
WebGL2 powered visualization framework
Pros of deck.gl
- Highly customizable and extensible for advanced data visualization
- Supports a wide range of 2D and 3D layer types
- Optimized for rendering large datasets efficiently
Cons of deck.gl
- Steeper learning curve for beginners
- Less out-of-the-box styling options compared to Mapbox GL
- May require additional libraries for certain map functionalities
Code Comparison
deck.gl example:
import {Deck} from '@deck.gl/core';
import {GeoJsonLayer} from '@deck.gl/layers';
new Deck({
layers: [new GeoJsonLayer({id: 'geojson', data: GEOJSON_DATA})]
});
Mapbox GL Native example:
#include <mbgl/map/map.hpp>
#include <mbgl/style/style.hpp>
mbgl::Map map(view);
map.getStyle().loadJSON(STYLE_JSON);
Key Differences
- deck.gl focuses on data visualization layers, while Mapbox GL Native provides a more complete mapping solution
- deck.gl is primarily JavaScript-based, whereas Mapbox GL Native offers native implementations for various platforms
- Mapbox GL Native has more built-in map controls and interactions, while deck.gl requires additional setup for these features
Both libraries have their strengths, with deck.gl excelling in custom data visualizations and Mapbox GL Native offering a more comprehensive mapping toolkit across multiple platforms.
WebGL map rendering engine for creative cartography
Pros of Tangram
- Open-source and free to use, with a more permissive license
- Highly customizable styling using a scene file format
- Supports 3D rendering and extrusion of map features
Cons of Tangram
- Smaller community and less extensive documentation
- Limited cross-platform support compared to Mapbox GL Native
- Fewer pre-built UI components and interaction tools
Code Comparison
Tangram (JavaScript):
var map = L.map('map');
var layer = Tangram.leafletLayer({
scene: 'scene.yaml',
attribution: '...'
});
layer.addTo(map);
Mapbox GL Native (C++):
#include <mbgl/map/map.hpp>
#include <mbgl/style/style.hpp>
auto map = std::make_unique<mbgl::Map>(view, resourceOptions, mapOptions);
map->getStyle().loadJSON(jsonStyle);
Both libraries offer powerful mapping capabilities, but they cater to different use cases. Tangram focuses on customizable vector tile rendering with a flexible styling system, while Mapbox GL Native provides a more comprehensive, cross-platform solution with additional features and tooling. The choice between them depends on specific project requirements, desired customization level, and target platforms.
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
Mapbox GL Native
A C++ library that powers customizable vector maps in native applications on multiple platforms by taking stylesheets that conform to the Mapbox Style Specification, applying them to vector tiles that conform to the Mapbox Vector Tile Specification, and rendering them using OpenGL or Metal.
To embed interactive maps into a native application using a platform-specific language, install the Mapbox Maps SDK:
- Mapbox Maps SDK for Android (Java, Kotlin)
- Mapbox Maps SDK for iOS (Objective-C, Swift, Interface Builder)
- Mapbox Maps SDK for macOS (Objective-C, Swift, Interface Builder, AppleScript)
Mapbox GL JS is the WebGL-based counterpart to Mapbox GL Native that is designed for use on the Web.
Developing
We use CMake to build Mapbox GL Native for various platforms, including Linux, Android, iOS, macOS and Windows. The following command, executed from the root of this repository tree, will build Mapbox GL Native targeting your host architecture given that you have all the dependencies installed and run the example app.
$ git submodule update --init --recursive
$ cmake . -B build
$ cmake --build build
$ MAPBOX_ACCESS_TOKEN=my_access_token_here ./build/platform/glfw/mbgl-glfw
License
Mapbox GL Native is licensed under the 2-Clause BSD license. The licenses of its dependencies are tracked via FOSSA:
Top Related Projects
MapLibre Native - Interactive vector tile maps for iOS, Android and other platforms.
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
WebGL map rendering engine for creative cartography
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