Skip to content

feat(deckgl): add a Vector Tiles (MVT) chart - #46649

Open
sohil-chhabra wants to merge 26 commits into
apache:masterfrom
sohil-chhabra:feat/deckgl-vector-tiles
Open

sohil-chhabra wants to merge 26 commits into
apache:masterfrom
sohil-chhabra:feat/deckgl-vector-tiles

Conversation

@sohil-chhabra

@sohil-chhabra sohil-chhabra commented Nov 27, 2026 •

Copy link
Copy Markdown

SUMMARY

Superset’s map charts can’t read the native geometry formats that spatial databases use (Ex: WKB). This prompts the user to make lat/lon or geojson columns.
The charts also send every row to the browser once which is a disadvantage for large geospatial layers.
Hence, this PR adds a deck.gl Vector tiles chart that draws vector tiles from any tile server.
Discussion: #43001 (comment)

A few decisions taken while implementing this feature:

  • A dataset is still required, but only for metadata: Superset only stores the settings and the query it sends to the dataset is a constant. This query is added to not break Superset's current structure/requirement of having a dataset for every chart.
  • Tooltip fields use their own key (tooltip_properties): The backend adds tooltip_contents to the SQL query, which would break for tile-only properties since the users are allowed to add TileJSON URL from which we retrieve the properties/fields. Without TileJSON URL, the dataset columns are listed
  • Styling reuses the existing deck.gl colour controls (fixed / categorical / breakpoints) which are turned into a Maplibre expression with@maplibre/maplibre-gl-style-spec. This dependency addition and conversion was intended because a very useful followup to this MVP is to let users add/paste their own Maplibre expressions.

Here's an AI assisted summary of the changes. However, I've reviewed it and agree with it. :

  • New chart deck_vector_tile (layers/VectorTile/), registered in the deck.gl
    preset. It renders a deck.gl MVTLayer, decoding tiles on the main thread because
    the default worker loads from a CDN that Superset's CSP blocks.
  • Settings (layerSettings.ts): normalises form data. The tile URL must contain
    {z}, {x} and {y}; zoom is clamped to 0-24 and swapped if reversed
  • Styling (styling.ts): each colour mode is compiled once into a MapLibre
    expression with @maplibre/maplibre-gl-style-spec (new dependency) and evaluated
    per feature.
    • Categorical colours come from Superset's CategoricalColorScale, cached for each
      chart and palette so colours stay stable as new tiles load. The cache is rebuilt
      when a dashboard changes its custom label colours. Like the other categorical
      deck.gl charts, these colours are fully opaque.
    • Breakpoints treat null, empty strings and booleans as missing before to-number,
      which would otherwise turn them into 0 or 1.
  • TileJSON (tileJson.ts, TilePropertyControl.tsx): fetches the document (only
    http/https URLs), caching one request per URL, and lists the properties of the source layer. The
    breakpoint picker lists only numeric properties. If the fetch fails, the control shows a warning and falls back to the dataset's columns.
  • Tooltip: lists all tile properties by default, or the chosen
    tooltip_properties. Properties are copied to the top level, so templates can use
    {{ name }}.
  • Legend (legend.ts): reads the colour property straight from the binary data of
    the tiles on screen. Points copied into a neighbouring tile's buffer are counted once. Hidden in fixed-colour mode.
  • Multiple Layers: the chart is registered in layers/index.ts, so it can be added as a layer.
  • Shared code: createTooltipContent's fallback may return null. That's a
    one-line type change.
  • Docs: a vector tiles section in map-tiles.mdx, and a CSP note in
    security.mdx.
  • Tests: unit tests for settings, styling, the legend, TileJSON parsing,
    buildQuery and the control panel, plus render tests for the layer.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

  1. The chart gallery
  • Before: New Chart, no before state
  • After:
image
  1. The basic chart
image
  1. Color modes
image
  • Fixed color: The screenshot above is in fixed color.
  • Categorical:
image - **Breakpoints**: Colored by rating with two ranges. The picker lists only numeric properties. image
  1. Tooltips
  • Default tooltip:
image
  • Chosen properties:
image
  • Template:
image
  1. Vector tile requests, tooltip hover, switching between colour mode preserves settings
Screen.Recording.2026-11-27.at.2.57.52.PM.mov

TESTING INSTRUCTIONS

1. Start a tile server with demo data (PostGIS + Martin, 50,000 points around Toronto).

docker-compose.yml:

services:
  db:
    image: imresamu/postgis:16-3.4
    environment:
      POSTGRES_PASSWORD: postgres
    ports: ["5433:5432"]
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 2s
      retries: 30
  martin:
    image: ghcr.io/maplibre/martin:latest
    environment:
      DATABASE_URL: postgres://postgres:postgres@db/postgres
    ports: ["3000:3000"]
    depends_on:
      db:
        condition: service_healthy

Seed data:

Details

seed.sql: 50,000 random places around Toronto
CREATE EXTENSION IF NOT EXISTS postgis;

DROP TABLE IF EXISTS public.places;

CREATE TABLE public.places (
    id       serial PRIMARY KEY,
    name     text NOT NULL,
    category text NOT NULL,
    rating   numeric(2, 1) NOT NULL,
    visitors integer NOT NULL,
    geom     geometry(Point, 4326) NOT NULL
);

INSERT INTO public.places (name, category, rating, visitors, geom)
SELECT
    'Place ' || g,
    (ARRAY['cafe', 'park', 'school', 'restaurant', 'shop'])[1 + floor(random() * 5)::int],
    round((1 + random() * 4)::numeric, 1),
    floor(random() * 10000)::int,
    -- Toronto is roughly lon -79.38, lat 43.70
    ST_SetSRID(ST_MakePoint(-79.38 + (random() - 0.5) * 0.6,
                            43.70 + (random() - 0.5) * 0.4), 4326)
FROM generate_series(1, 50000) AS g;

-- Spatial index so Martin can find the points inside each tile quickly
CREATE INDEX places_geom_idx ON public.places USING gist (geom);
ANALYZE public.places;
docker compose up -d
docker compose exec -T db psql -U postgres < seed.sql
docker compose restart martin

Check that http://localhost:3000/places returns TileJSON listing category, id,
name, rating and visitors.

2. Allow the tile server in the CSP. In superset_config.py, add
"http://localhost:3000" to connect-src in TALISMAN_DEV_CONFIG (and in
TALISMAN_CONFIG if not running in debug mode). Restart Superset.

3. Create the chart. Choose the dataset created earlier, then the
deck.gl Vector Tiles chart, and set:

  • Tile URL: http://localhost:3000/places/{z}/{x}/{y}
  • TileJSON URL: http://localhost:3000/places
  • Source layer: places
  • Viewport: longitude -79.38, latitude 43.70, zoom 10

Points should appear around Toronto.

4. Try each feature:

  • Tile URL validation: remove {y}. The control shows an error and no layer is drawn.
  • Fixed colour: changing the colour repaints the points. There's no legend.
  • Categorical palette -> Colour by category: five colours appear, and the legend
    lists the five categories. Pan and zoom: each category keeps its colour on newly
    loaded tiles. Changing the palette repaints the points and the legend.
  • Colour by name: the legend shows 10 rows plus "+ N more".
  • Colour breakpoints: the property picker lists only id, rating and
    visitors. Pick rating and add 0-2 for red and 2.5-5 for blue. Ratings between
    2 and 2.5 use the default colour. The legend shows both ranges, and Legend Format
    changes how they're displayed.
  • Switching modes keeps each mode's chosen property and the legend position.
  • Tooltip: hovering shows every property except the loader's layerName.
    Choosing tooltip properties limits the list. A template such as
    {{ name }} ({{ rating }}) also works.
  • TileJSON failure: set the TileJSON URL to http://localhost:3001/places. The
    pickers show a warning and list the dataset's columns instead.
  • deck.gl Multiple Layers: adding this chart as a layer still renders it.

5. Unit tests:

cd superset-frontend
npm run test -- plugins/preset-chart-deckgl/src/layers/VectorTile

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

Known limitations

  • Legend counts: the categorical legend counts features in the tiles on screen.
    Points near tile edges are counted once. Lines and polygons that span several tiles
    are counted once per tile, because the tile server cuts them at tile edges. This only
    changes the order of the legend rows and doesn't changes which categories appear.
  • MultiPoint features whose first point is in a neighbouring tile's buffer can be left out of the legend.
  • No legend in Multiple Layers. When this chart is added as a layer, it renders,
    but Multiple Layers doesn't show per-layer legends.

Follow-ups/Stretch goals/Future

  • Following this, I'd like to add a semantic layer so we still get the vector tiles from tile server but aggregated metrics from a Superset dataset and the tiles with aggregated metrics get joined in the browser. This avoids the bottleneck of querying the geometry since geometry is defined by vector tiles
  • As previously mentioned, Custom MapLibre expressions would also be a very helpful and doable followup since it will allow users to write their own MapLibre style expression for colour (initially).
  • Legend toggling: click a category in the legend to hide it on the map, like the
    other categorical deck.gl charts.
  • Opacity control for categorical mode.
  • Legend in Multiple Layers.

@github-actions github-actions Bot added doc Namespace | Anything related to documentation plugins dependencies:npm risk:chart-metadata labels Nov 27, 2026
@sohil-chhabra
sohil-chhabra marked this pull request as ready for review November 28, 2026 00:26
// SQL query. The shared tooltip code reads `tooltip_contents`, so they are
// handed over only here, in the browser.
const tooltipContent = createTooltipContent(
{ ...formData, tooltip_contents: tooltipProperties },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: When a selected tile field contains 0 or false, the shared tooltip extractor treats it as missing, so the field-based tooltip omits it.

Assessment: 🟠 Major · 🔁 Occurrence: Sometimes · 🏷️ Falsy zero check

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset-frontend/plugins/preset-chart-deckgl/src/layers/VectorTile/VectorTile.tsx
**Line:** 111:111
**Comment:**
	*Falsy Zero Check: When a selected tile field contains `0` or `false`, the shared tooltip extractor treats it as missing, so the field-based tooltip omits it.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@codeant-ai-for-open-source

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟡  Medium Risk

  • The PR needs attention before merging: selected tile properties valued 0 or false may be omitted by the shared tooltip renderer.

Assessed commit: d05d936494e3

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies:npm doc Namespace | Anything related to documentation plugins risk:chart-metadata size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant