Common Basic Layers
🎯 Introduction
By the end of this article, you will be able to choose ScatterplotLayer, GeoJsonLayer, PathLayer, PolygonLayer, IconLayer, or TextLayer based on your data's geometry and combine them on one Mapbox map.
🧱 Points, lines, polygons, and labels
Start with three common geometry types in WebGIS: points represent locations, lines represent paths, and polygons represent enclosed areas. deck.gl provides layers for each:
| Layer | Suitable data | Common uses |
|---|---|---|
ScatterplotLayer | Point coordinates | Stations, devices, POIs |
PathLayer | Coordinate arrays | Roads, flight routes, rivers |
PolygonLayer | Closed coordinate arrays | Areas, building footprints |
GeoJsonLayer | GeoJSON Feature or FeatureCollection | Standard point, line, and polygon data |
IconLayer | Point coordinates and icon information | Device status, direction markers |
TextLayer | Point coordinates and text | Names, IDs, labels |
⚖️ deck.gl layers and Mapbox layers
Mapbox can render conventional map features using a GeoJSON source and layers such as fill, line, and circle. deck.gl supports the same geometry types, but is better suited to larger datasets, styles calculated from data, and GPU aggregation or animation.
A useful starting point is:
Basemap styles, roads, and a few conventional application data layers → Mapbox layers
Dynamic data, complex accessors, large geometry datasets, and animation → deck.gl layers
These are guidelines rather than strict limits. Your choice also depends on data volume, interaction requirements, and the existing map style.
🛠 A minimal combination
All the following layers are added to the Mapbox map through the same MapboxOverlay:
const layers = [
new PolygonLayer({
id: 'area',
data: areas,
getPolygon: (item) => item.polygon,
getFillColor: [245, 158, 11, 70],
}),
new PathLayer({
id: 'route',
data: routes,
getPath: (item) => item.path,
getColor: [16, 185, 129, 230],
getWidth: 8,
}),
new ScatterplotLayer({
id: 'stations',
data: stations,
getPosition: (item) => item.position,
getRadius: 500,
getFillColor: [37, 99, 235, 230],
}),
];
overlay.setProps({ layers });
You can also add GeoJsonLayer, IconLayer, and TextLayer to the same map to draw boundaries, icons, and text labels, respectively:
If two filled polygons overlap at the same or nearly the same elevation, the depth buffer may not reliably determine which is in front, causing flickering as you zoom. This is called z-fighting. Avoid overlapping coplanar surfaces, or explicitly configure layer elevations and drawing order.
💡 Choosing a layer
- If the data is already GeoJSON, consider
GeoJsonLayerfirst to preserve the Feature structure. - For coordinate arrays, use
ScatterplotLayerfor points,PathLayerfor lines, andPolygonLayerfor polygons. - Use
IconLayerfor icons that change with data, andTextLayerfor names and IDs. - To keep your data on the same map as Mapbox roads and place names, let Mapbox provide the basemap and deck.gl provide the application data layers.
🧾 Summary
- ScatterplotLayer, PathLayer, and PolygonLayer represent points, lines, and polygons.
- GeoJsonLayer handles standard GeoJSON data.
- IconLayer and TextLayer draw icons and text labels.
- Mapbox layers and deck.gl layers belong to separate layer systems.
❓ Questions and answers
Q1: How does GeoJsonLayer differ from a Mapbox layer using GeoJSON?
The former is a deck.gl layer suited to data-driven GPU rendering; the latter is a Mapbox style layer that integrates with Mapbox's source, filter, and styling system.
Q2: Can one map contain both Mapbox and deck.gl layers?
Yes. MapboxOverlay lets deck.gl layers share the Mapbox map's camera.
Q3: Why can graphics obscure text?
Layer order and depth affect readability. Usually, draw polygons first, followed by lines, points, and text, and adjust the layer order or depth settings as needed.
🧪 Exercises
- Add a path to
PathLayerand observe its spatial relationship to Mapbox roads. - Add a station name to
TextLayerand adjustgetPixelOffset.
🎉 You can now combine multiple deck.gl layers into a visualization with geographic context.
