Web applications
Mapbox provides many tools to build maps into your website or web-based application. Mapbox GL JS is a JavaScript library you can use to display your Mapbox maps, add interactivity, and customize the map experience in your application. We also provide many plugins for extending your web map's functionality with drawing tools and interfaces to Mapbox web services APIs like the Mapbox Geocoding API or Mapbox Directions API. Building webpages or web applications with our JavaScript libraries will require writing code, but this guide is designed to provide you with the resources to get started.
Use cases
How web apps work
A web mapping library allows you to add a map to a webpage and define the data it contains, its appearance, and a variety of functionality. Think of it like a toolbox filled with many different map-making tools that can be used together to build beautiful and interactive custom experiences.
Mapbox GL JS
Mapbox GL JS is a JavaScript library for building web applications with our modern mapping technology. This guide walks through some of Mapbox GL JS's essential functions and common patterns, highlighting some of the core concepts that distinguish Mapbox GL JS from other map libraries. For those with experience using Leaflet or OpenLayers, the next few sections will introduce some of the differences in Mapbox GL JS as well as features that should look familiar.
Client-side rendering
At the heart of Mapbox GL JS is client-side rendering. In web apps using Mapbox GL JS, maps are rendered dynamically by combining vector tiles with style rules using JavaScript and WebGL. Rendering maps in the browser rather than on a server makes it possible to change the map's style and the data it displays dynamically and in response to user interaction.
The camera
The camera is the map's field of view. While the viewpoint in maps made with traditional web mapping libraries is determined by the map's center point and zoom level, Mapbox GL JS also includes parameters like pitch and bearing for adjusting the map's perspective.
- Center: in longitude, latitude order.
- Zoom: any number within the zoom range, including decimals. For example, 1.5 or 6.2 are valid zoom levels.
- Bearing: a value between 0 and 360 degrees that determines the map's bearing, or rotation.
- Pitch: a value between 0 and 85 degrees that determines the map's tilt, or pitch.
Here's an example of combining bearing and zoom:
To experiment with camera pitch, bearing, tilt, and zoom and get values to use in your code, try our Location Helper tool.
Layers
Traditional JavaScript map libraries often have two distinct categories of what are called "layers": baselayers, or image tiles that provide the foundation of the map, and overlays, which are often vector data like GeoJSON that are displayed on top of baselayers, sometimes obscuring details like labels.
Mapbox GL JS has no distinction between baselayers and overlay layers. This means that map details like labels and icons and elements like streets and buildings can be modified with JavaScript, like overlays in earlier mapping libraries. Each layer provides rules about how the renderer should draw certain data in the browser, and the renderer uses these layers to draw the map on the screen.