Introducing a new way to review your PRs.

Read the announcement

visgl / deck.gl

WebGL2 powered visualization framework

View on GitHub

23 documents · Updated Nov 20, 2026

docs / carto-integration

CARTO integration

The CARTO integration connects CARTO data services to deck.gl visualizations. It turns CARTO source descriptions and map definitions into data flows and deck.gl layers. pydeck-carto gives Python users the same source and style model for notebooks and Python applications. See the data and visualization extensions page for its place among the optional deck.gl packages.

System boundary

The package sits between a CARTO account or data service and the deck.gl layer system. CARTO supplies access details, query or table choices, tile metadata, and spatial data. deck.gl supplies the camera, layer life cycle, drawing, and interaction model.

Data source descriptions

The JavaScript package exposes source builders from @carto/api-client through modules/…/index.ts. These builders describe how to reach a table, SQL query, or tileset and identify the spatial form that a layer should display. A source description is not the visualization itself. It is the contract that lets a CARTO service return tile metadata and data for a deck.gl layer.

The source families match the main CARTO data paths:

  • Vector data from a table, query, or tileset.
  • H3 cell data from a table, query, or tileset.
  • Quadbin cell data from a table, query, or tileset.
  • Boundary and raster data where the CARTO API supports those forms.

Source descriptions carry the connection, API base URL, and access token needed for the request. Query sources can also carry SQL parameters. Spatial-index sources can describe the aggregation expression and resolution used to prepare cell data. The Python binding presents these same choices with Python names and serializes them to the JavaScript source functions.

References: modules/…/index.ts• L74-114 bindings/…/sources.py• L12-42 bindings/…/sources.py• L145-233 bindings/…/sources.py• L236-429

Tile-backed data flow

Tile-backed layers use CARTO tile metadata as the handoff between a source and the deck.gl tile system. The metadata gives the layer tile URLs, usable resolution, spatial scheme, and access data. The layer requests only the tiles needed for the current view and presents their contents through normal deck.gl rendering and picking.

The vector layer accepts CARTO native binary tiles and MVT tiles. Both paths produce binary feature data for deck.gl. When CARTO provides a separate properties stream, the layer joins it with the geometry before rendering. Spatial and raster loaders turn CARTO tile formats into cell or value data that their layer families can display. Tile parsing can run in dedicated workers, while the package also keeps a synchronous path for compatible hosts.

The main flow is:

flowchart LR
    A[Source description] --> B[CARTO service]
    B --> C[Tile metadata]
    C --> D[deck.gl CARTO layer]
    D --> E[Visible tile requests]
    E --> B
    D --> F[Rendered features cells or surfaces]

Vector tiles can include geometry and a separate properties stream. Spatial tiles use either H3 or quadbin cell indexes. For quadbin data, the integration converts each cell index into a geographic cell footprint so the rendered shape matches the indexed tile space. Raster tiles provide values that the integration displays as a cell surface. These data forms remain compatible with deck.gl tile behavior while the CARTO package supplies the spatial meaning of each tile.

References: modules/…/vector-tile-layer.ts• L74-132 modules/…/carto-properties-tile-loader.ts• L26-43 modules/…/carto-vector-tile-loader.ts• L32-107 modules/…/carto-spatial-tile-loader.ts• L29-55 modules/…/carto-raster-tile-loader.ts• L30-70 modules/…/fast-pbf.ts• L8-26 modules/…/cartoVectorTile.ts• L5-8 modules/…/quadbin-utils.ts• L10-29

Visualization layer families

The public CARTO layers are deck.gl layers with CARTO-aware data inputs. They preserve deck.gl props such as accessors, visibility, picking, and visual effects. Each layer family chooses the tile scheme and geometry model required by its source.

Vector visualization

VectorTileLayer presents CARTO vector data as map features that can use the usual deck.gl fill, line, point, text, and interaction properties. It can create labels for line and polygon features when an application enables automatic labels. For point features, PointLabelLayer can render a primary label and an optional secondary label while keeping collision behavior tied to the label footprint.

Automatic labels are derived from feature geometry. Lines use a representative point from the longest or selected feature path. Polygons use a point inside the feature when possible. This lets labels follow the source features without changing the main deck.gl layer contract.

References: modules/…/vector-tile-layer.ts• L41-61 modules/…/vector-tile-layer.ts• L136-235 modules/…/label-utils.ts• L43-100 modules/…/label-utils.ts• L102-243

Spatial index visualization

H3TileLayer and QuadbinTileLayer present indexed cells as deck.gl hexagons or quadbin cells. H3 uses H3 resolution levels. Quadbin uses a hierarchical square-cell index. Both layers use tile metadata to select data for the current view and then render cells with deck.gl accessors such as fill color, elevation, and picking.

ClusterTileLayer builds a higher-level view from visible H3 or quadbin cells. It groups cells by parent index and combines their weights and properties for the current view. HeatmapTileLayer uses the same spatial cell families as a density surface. It chooses the active cell scheme from tile metadata, scales weights by cell resolution, and adjusts the displayed maximum as visible tiles and zoom levels change. This keeps density changes between tile resolutions less abrupt. Clustering and heatmaps are visualization choices over indexed data rather than separate source types.

References: modules/…/cluster-tile-layer.ts• L53-76 modules/…/cluster-tile-layer.ts• L147-229 modules/…/cluster-tile-layer.ts• L283-319 modules/…/cluster-utils.ts• L12-20 modules/…/cluster-utils.ts• L32-119 modules/…/heatmap-tile-layer.ts• L54-70 modules/…/heatmap-tile-layer.ts• L248-324

Raster visualization

RasterTileLayer displays CARTO raster tiles as a grid of colored cells. The layer uses raster metadata to keep displayed values aligned with the tile cell layout. It is intended for continuous surfaces and other value fields that the CARTO service has already prepared.

References: modules/…/raster-tile-layer.ts• L59-92 modules/…/raster-layer.ts• L95-128 modules/…/carto-raster-tile-loader.ts• L45-70

Visual style helpers

The package provides colorContinuous, colorBins, and colorCategories as small style helpers. Each helper returns a deck.gl color accessor that maps a selected attribute to a color range. Continuous values are interpolated. Numeric values can be assigned to bins. Named categories receive fixed colors. Null and unmatched values use explicit fallback colors.

These helpers connect data meaning to deck.gl visual channels without forcing an application to create its own scale logic. The Python binding exposes the same helpers as serialized expressions. This keeps styles portable between JavaScript and Python-created decks.

References: modules/…/raster-tile-layer.ts• L25-44 modules/…/raster-layer.ts• L73-128 modules/…/color-continuous-style.ts• L12-51 modules/…/color-bins-style.ts• L12-51 modules/…/color-categories-style.ts• L11-59 bindings/…/styles.py• L6-109

Map definition integration

The integration can consume a CARTO map definition instead of requiring an application to assemble every layer by hand. fetchMap obtains a map result through @carto/api-client, then maps each CARTO layer descriptor to the matching deck.gl CARTO layer. LayerFactory exposes the same conversion as a separate step when an application needs more control.

Layer descriptor mapping

The map path supports CARTO descriptor types for vector, H3, quadbin, raster, heatmap, and clustered tile views. The descriptor selects the layer family. Its properties carry the source and visual settings. The result contains deck.gl Layer instances that an application can pass to Deck or another deck.gl host.

References: modules/…/fetch-map.ts• L17-71

Basemap choices

The package also supplies CARTO basemap style URLs and a small set of named basemap choices. A map definition can carry a MapLibre or Google basemap description with its initial view state and optional layer-group visibility. The basemap is separate from the data layers. It gives geographic context while CARTO layers provide the application data.

References: modules/…/basemap.ts• L8-38 modules/…/basemap.ts• L40-113 modules/…/types.ts• L142-192

Python binding boundary

pydeck-carto is a Python-facing adapter for the CARTO layer and source model. It does not replace pydeck’s deck construction API. Instead, it lets Python code describe CARTO data and styles, register the CARTO JavaScript layer bundle, and then create a normal pdk.Deck.

Python source and style expressions

Python source functions validate the main arguments and emit pydeck function expressions such as vectorQuerySource, h3TableSource, or quadbinTilesetSource. The browser later evaluates these expressions in the JavaScript CARTO package. This boundary lets SQL, table, tileset, authentication, and spatial-index choices be made in Python while the deck still runs in the browser.

Python style functions follow the same boundary for color scales. They emit colorBins, colorCategories, or colorContinuous expressions instead of calculating a color for each feature in Python. The resulting style stays part of the deck specification and can work with the CARTO layers after they load data in the browser.

References: bindings/…/sources.py• L69-142 bindings/…/sources.py• L166-233 bindings/…/sources.py• L257-329 bindings/…/sources.py• L354-429 bindings/…/styles.py• L6-109

Browser layer registration

Before a Python deck uses a CARTO layer, register_layers() adds the CARTO bundle to pydeck’s custom libraries and registers the layer names that Python code can request. It also supplies a default data-error callback for the main tile layer families. The normal Python flow is therefore: authenticate with CARTO, register the browser layer bundle, build a source expression, create a pydeck layer, and render the deck.

sequenceDiagram
    participant P as Python application
    participant D as pydeck
    participant B as Browser
    participant C as CARTO
    P->>D: Register CARTO layers
    P->>D: Build source and style expressions
    D->>B: Serialize deck and load CARTO bundle
    B->>C: Request metadata and visible tiles
    C-->>B: Return CARTO data
    B-->>P: Render deck.gl visualization

References: bindings/…/README.md• L24-57 bindings/…/layer.py• L6-27 bindings/…/layer.py• L39-60 bindings/…/__init__.py• L1-11

The CARTO package relies on deck.gl’s standard layer contracts rather than defining a separate rendering system. The JSON specification describes the broader serialized layer model. The layer extensions page explains reusable behavior that can augment these layers. The Python bindings page covers pydeck as a broader Python interface, while this page focuses on the CARTO-specific source, layer, and style boundary.

Contract ownership

The main ownership boundaries are:

  • CARTO services own source access, query execution, tile creation, and tile metadata.
  • @carto/api-client owns CARTO source and map request contracts.
  • @deck.gl/carto owns the mapping from CARTO data forms to deck.gl layer families and styles.
  • deck.gl core and geospatial layers own rendering, view selection, updates, and interaction behavior.
  • pydeck-carto owns Python validation and serialization into the browser-side CARTO contract.
  • The CARTO package publishes typed ESM and CommonJS entry points. Its build also produces the worker bundles used by its host environments.

References: modules/…/package.json• L26-47 modules/…/package.json• L48-77 modules/…/build-cjs.mjs• L5-25 modules/…/utils.ts• L42-46 modules/…/index.ts• L14-23 modules/…/fetch-map.ts• L25-54 bindings/…/README.md• L6-14

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the CARTO descriptor type map aligned with the public layer names in modules/…/fetch-map.ts and modules/…/index.ts.
  • Keep Python source function names and serialized camelCase fields aligned with the JavaScript source contract exposed by @carto/api-client.
  • Keep the H3 and quadbin scheme passed to spatial tile loading aligned with the tileset class and the source metadata.
  • Keep quadbin cell geometry conversion aligned with the index tile space, world bounds, and geographic footprint used by the layer.
  • Keep vector tile format detection aligned with binary coordinate handling, separate property streams, and the matching sublayer behavior.
  • Keep automatic label geometry aligned with the coordinate space of native CARTO tiles and MVT tiles.
  • Keep cluster property suffixes aligned with the aggregation rules expected by ClusterTileLayer.
  • Keep heatmap density normalization aligned with the active spatial scheme, visible tile resolution, and zoom-based density estimate.
  • Keep the Python CDN bundle version compatible with the pydeck layer names and the @deck.gl/carto package version.
  • Treat access-token propagation as a cross-boundary contract between source metadata, tile requests, and browser error handling.
  • Keep worker URLs, worker entry points, and package version replacement aligned when tile formats or worker parsing changes.
  • Keep the ESM and CommonJS package entry points aligned when the CARTO build or synchronous tile decoding path changes.
  • Keep label collision behavior aligned with point-label offsets when point label props or label shader behavior changes.

Important failure modes

TriggerConsequenceGuard
A source uses a missing or invalid access tokenCARTO metadata or tile requests fail and the layer has no usable dataSupply the token in the source and keep the layer request contract intact
A map descriptor has no matching layer typeMap creation throws instead of returning a deck.gl layerAdd the descriptor type to the factory map and the public layer surface together
An H3 or quadbin source is paired with the wrong spatial schemeCell data is decoded or positioned with the wrong index meaningKeep source metadata, tileset class, and loader scheme aligned
Quadbin cell geometry uses the wrong tile-space or world-coordinate conversionCells can have the wrong footprint or appear in the wrong geographic positionKeep index conversion, world bounds, and polygon output aligned
Vector tile metadata is read with the wrong format or coordinate ruleGeometry can be decoded or positioned incorrectlyKeep format detection aligned with the tile loader and coordinate system
A separate properties tile is missing or cannot be joined to its geometry tileFeatures render without their attributes or the tile request failsKeep the geometry and properties URL templates and feature identifiers compatible
Aggregation property names do not end with a supported ruleCluster styling uses an unintended any value instead of the requested numeric summaryUse the supported aggregation suffixes and inspect the resulting tile properties
Raster metadata is unavailable when a raster tile is parsedRaster data is not produced for the layerPass the tile metadata with the raster load request
register_layers() is skipped in a pydeck notebookThe browser does not know the CARTO layer constructorsRegister the CARTO custom library before creating the deck
A Python source or style emits a field name that differs from the JavaScript contractThe browser receives an expression that cannot construct the source or styleTreat serialized camelCase names as a shared API contract
A host loads a stale or incomplete package entry point or worker bundleThe CARTO integration cannot load in that host or its tile data path failsBuild and publish the module formats and versioned worker bundles together
Point-label offsets and collision bounds use different geometryLabels can overlap or be rejected at the wrong positionKeep visual offsets and collision background calculations in step

Key files

FileWhy to read it
modules/…/index.tsPublic JavaScript surface for CARTO layers, sources, styles, map loading, and basemaps.
modules/…/fetch-map.tsShows how CARTO map descriptors become deck.gl layer instances.
modules/…/types.tsDefines the shared map, visual-channel, and basemap data shapes used by the map boundary.
modules/…/vector-tile-layer.tsDefines the main feature-oriented CARTO layer and its vector data boundary.
modules/…/label-utils.tsShows how feature geometry becomes automatic label positions.
modules/…/carto-vector-tile-loader.tsShows the vector tile data boundary and binary feature output.
modules/…/carto-spatial-tile-loader.tsShows how H3 and quadbin tile data becomes indexed cell data.
modules/…/quadbin-utils.tsConverts quadbin cells into the geographic footprints used by the visualization.
modules/…/cluster-tile-layer.tsExplains the aggregated view over visible H3 or quadbin cells.
modules/…/cluster-utils.tsDefines the property aggregation rules used by clustered cells.
modules/…/heatmap-tile-layer.tsShows how indexed tile data becomes a resolution-aware density visualization.
modules/…/heatmap.tsDefines the heatmap visual transformation applied to tile values.
modules/…/carto-raster-tile-loader.tsShows the raster value data boundary and metadata requirement.
modules/…/color-continuous-style.tsDefines continuous attribute-to-color styling.
modules/…/basemap.tsDefines CARTO basemap style choices and style grouping.
modules/…/build-cjs.mjsShows how the CommonJS package entry point keeps synchronous tile decoding available to compatible hosts.
modules/…/utils.tsDefines versioned worker URLs used by the tile loaders.
bindings/…/sources.pyDefines Python source choices and their serialized CARTO expressions.
bindings/…/styles.pyDefines Python wrappers for CARTO color style expressions.
bindings/…/layer.pyRegisters the browser-side CARTO bundle for pydeck.
bindings/…/README.mdGives the shortest end-to-end Python usage example.
modules/…/package.jsonDefines the package’s typed ESM and CommonJS exports, deck.gl peer boundary, CARTO dependency, and worker build outputs.