Skip to content

Draw geometry-file circle tiles with WebGL2 - #46

Merged
wf9a5m75 merged 1 commit into
developfrom
feat/webgl-circle-tiles
Nov 13, 2026
Merged

wf9a5m75 merged 1 commit into
developfrom
feat/webgl-circle-tiles

Conversation

@wf9a5m75

Copy link
Copy Markdown
Contributor

Summary

The tile service worker draws a nationwide circle set (the geometry file, used past 2,000 circles) with WebGL2 instead of the 2D canvas. This is the web counterpart of MapConductor/ios-sdk-core#41 and MapConductor/android-sdk-core#44.

What was slow

On a Pixel 5a, a zoomed-out tile of US Antenna Horizons (723,800 circles) took about 2.4 s. The service worker is single-threaded, so nine tiles took 13.6 s. Measured inside the worker, the time split about evenly into two parts:

  • picking the circle each pixel keeps;
  • drawing.

Both read every block of the geometry file (about 425 KB each from Cache Storage) through a cache of 8 blocks, which a nationwide tile overflows, so each block was read twice. They also built an object, a Path2D and a colour string per circle. The PNG encoding (20–40 ms) and the index query were small.

What changed (renderCircleFileTileGl)

  • One read per block. Each block is read once, and its records are read as numbers.
    • A dot that a later circle replaces in the same pixel is blanked in place, so the draw order is kept without a second pass.
  • Colours. The palette is converted to premultiplied RGBA once per file.
  • Drawing. Circles are drawn as WebGL2 instances, with the fill and outline computed from the distance to the centre, the same shader as iOS and Android.
  • One canvas. There is one OffscreenCanvas for the worker. Tiles take turns at it between their block reads, and convertToBlob makes the PNG.

The 2D canvas still draws:

  • a tile with a circle bent into its 128-gon;
  • polygon and polyline tiles;
  • everything in a worker without WebGL2.

Running useGl = false in the worker's console draws everything on the 2D canvas, to compare.

Measurements

Pixel 5a, Brave (Chromium 157), US Antenna Horizons on MapLibre. The first nine tiles (2x), time until each finished:

first tile all nine
deployed (2D) 2.4 s 13.6 s
this branch (WebGL2) 1.2 s 6.8 s

Desktop Chromium. Sixteen tiles at z9, z11 and z13 over New York, Chicago, Los Angeles and Houston, plus four z4 tiles: 776 ms on WebGL2 against 1,268 ms on 2D.

What is left is mostly reading the blocks from Cache Storage. Keeping a compact copy of the circles in the worker's memory (about 20 MB for 723,800 circles) would remove that, but the file exists to save that memory, so it is a separate decision.

Checks

  • npm test: all 426 pass. Node has no WebGL2, so the tests take the 2D path as before.
  • Desktop Chromium, the same 20 tiles drawn with useGl on and off and compared pixel by pixel:
    • pixels differing by more than 48 levels: at most 2.7% of a tile, all on the antialiased edges of dense circles;
    • zoomed-out tiles (dots only): identical.

The tile worker drew a nationwide circle set on the 2D canvas, reading every block of the geometry file twice through an 8-block cache and building an object, a Path2D and a colour string per circle: about 2.4 s a tile on a Pixel 5a. Each block is now read once and its records are read as numbers; a dot that a later circle replaces in the same pixel is blanked in place, which keeps the draw order. The circles are drawn as WebGL2 instances (fill and outline from the distance to the centre, as on iOS and Android) on one OffscreenCanvas the tiles take turns at.

A tile with a circle bent into its 128-gon, polygon and polyline tiles, and workers without WebGL2 keep the 2D canvas. useGl = false in the worker's console draws everything on the 2D canvas.
@wf9a5m75
wf9a5m75 merged commit fe3709b into develop Nov 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant