Common Basic Layers

Draw points, lines, polygons, icons, and text over a Mapbox basemap with deck.gl.

🎯 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:

LayerSuitable dataCommon uses
ScatterplotLayerPoint coordinatesStations, devices, POIs
PathLayerCoordinate arraysRoads, flight routes, rivers
PolygonLayerClosed coordinate arraysAreas, building footprints
GeoJsonLayerGeoJSON Feature or FeatureCollectionStandard point, line, and polygon data
IconLayerPoint coordinates and icon informationDevice status, direction markers
TextLayerPoint coordinates and textNames, 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 GeoJsonLayer first to preserve the Feature structure.
  • For coordinate arrays, use ScatterplotLayer for points, PathLayer for lines, and PolygonLayer for polygons.
  • Use IconLayer for icons that change with data, and TextLayer for 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

  1. Add a path to PathLayer and observe its spatial relationship to Mapbox roads.
  2. Add a station name to TextLayer and adjust getPixelOffset.

🎉 You can now combine multiple deck.gl layers into a visualization with geographic context.