Coordinates, Units, and Map Alignment

Understand deck.gl coordinates, units, and local offsets to align data accurately with a Mapbox map.

🎯 Introduction

By the end of this article, you will be able to diagnose position offsets and choose longitude/latitude coordinates, meters, pixels, or local coordinates for your map extent.

🧱 Longitude and latitude

Geographic points are usually written as [longitude, latitude, altitude]: longitude first, latitude second, and optional altitude last. Standard WGS84 longitude/latitude data can be returned directly from getPosition:

getPosition: (station) => [station.longitude, station.latitude],

The Mapbox camera and deck.gl overlay use the same map space, so standard longitude/latitude layers align directly with the Mapbox basemap. A common mistake is using [latitude, longitude], which places graphics at the wrong location.

⚖️ Meters, pixels, and coordinate systems

Check the units of each layer property separately:

  • radiusUnits: 'meters': measures the radius as a geographic distance, so its apparent size changes as the map zooms.
  • radiusUnits: 'pixels': measures the radius in screen pixels, keeping points at a readable screen size.
  • coordinateSystem: tells deck.gl how to interpret position arrays.
new ScatterplotLayer({
    id: 'meter-offset',
    data: [{ position: [350, 180, 0] }],
    coordinateSystem: COORDINATE_SYSTEM.METER_OFFSETS,
    coordinateOrigin: [116.4, 39.9, 0],
    getPosition: (item) => item.position,
    getRadius: 20,
    radiusUnits: 'pixels',
});

Here, [350, 180, 0] is an offset in meters from coordinateOrigin, rather than longitude and latitude.

🧭 Local coordinates and data conversion

Local coordinates work well for many relative positions near a reference point, such as device offsets from a station. Data covering larger areas should still use actual longitude/latitude or appropriately converted projected coordinates.

If your data uses GCJ-02, BD-09, EPSG:3857, or another local projection, do not assume it is WGS84. Convert the coordinates before passing them to Mapbox and deck.gl.

This example places longitude/latitude points and points defined as meter offsets from a shared origin on a Mapbox map:

🪤 Diagnosing position offsets

When positions are misaligned, check these in order:

  1. Are arrays in [longitude, latitude] order?
  2. Is the data actually in WGS84?
  3. Have meters, pixels, and longitude/latitude been mixed up?
  4. When using METER_OFFSETS, does coordinateOrigin match the reference point?
  5. Does the Mapbox basemap use a different coordinate conversion or data source?

🧾 Summary

  • Geographic positions usually use [longitude, latitude, altitude].
  • Mapbox and the deck.gl overlay share map space and the camera.
  • Meters express geographic distances; pixels maintain visual size on screen.
  • Local coordinates require explicit coordinateSystem and coordinateOrigin settings.

❓ Questions and answers

Q1: Why can [lng, lat] align directly with Mapbox?

Mapbox and the deck.gl overlay share the same geographic map space, allowing both to transform WGS84 longitude/latitude correctly.

Q2: How do radius and radiusPixels differ?

They use different units: geographic distance and screen pixels, respectively. Refer to the layer API for the exact property names.

Q3: Should all data use METER_OFFSETS?

No. Use the default coordinate system for ordinary longitude/latitude data. Use local coordinates only when the data itself contains relative offsets.

🧪 Exercises

  1. Deliberately change a coordinate array to [latitude, longitude], observe the misplaced point, then restore the correct order.
  2. Move coordinateOrigin to another point and observe how the red point in local coordinates moves.

🎉 You now know how to align deck.gl data accurately with a Mapbox map.