Street-level HTML overlays painted onto a tilted OpenStreetMap grid

I wanted to know if live interactive HTML signs, departure boards and route badges can lie flat in 3D perspective on a tilted OpenStreetMap road surface and keep accurate hit testing while you drive, rotate and pitch the view. Drag across Central London to pan, adjust the heading and pitch sliders, press Next step on the painted turn card, change the bus line filter, toggle Avoid tolls or edit the checkpoint note directly on the street.

Turn-by-turnStep 1 of 4
In 120 m
Turn right onto Embankment
Right lane · A3211
Stop E · EmbankmentLive
11 · Liverpool St2 min
11 · Fulham Bdwy7 min
Whitehall · A3212C-Zone
20
Keep clear · Bus lane
Congestion charge active
14 min · £15
Checkpoint · TrafalgarPinned
51.5078, -0.1280 22 chars
WebGL 2 road grid

Drag to pan across Whitehall and Embankment. Tap Next step, pick a bus route, toggle Avoid tolls or edit the checkpoint note.

Show the code zoom-16 OpenStreetMap tile atlas, single-context ElementGL road shader, projective flat and upright matrices
  1. Four interactive street overlays inside the canvas. Turn-by-turn directions, a transit departure board, a speed and toll plate and an editable checkpoint note sit as drawable children inside <canvas content="drawable" layoutsubtree>.
  2. Zoom-16 OpenStreetMap tile atlas with offline street fallback. A plain 1024 by 1024 offscreen canvas draws a procedural Central London street layout first, then paints each CORS-enabled OpenStreetMap tile into its slot as it loads from memory or network.
  3. Road plane, glowing route polyline and asphalt-blended card shaders. The road shader renders the pitched tile grid with horizon fog, the route shader animates forward chevrons and card drop shadows, and the card fragment shader blends subtle tarmac grain onto flat painted cards.
  4. Singularity-free camera and projective hit-test matrices. An analytical heading-and-pitch basis avoids gimbal lock at 0 degrees top-down, builds clip and canvas matrices for both flat painted overlays and upright street signs, and updates updateElementGeometry() with geometryUnit().
  5. One ElementGL WebGL 2 context for map, route and DOM. The paint handler uploads dirty cards via stage.upload(), draws the tile road plane and route polyline on stage.gl, restores ElementGL's shader state and draws depth-sorted cards.
  6. Texture upload in element-gl.js. texElementSubImage2D() copies each live HTML overlay into a WebGL 2 texture sized to getElementImageDefaultSize().

How it works

I took the visual idea from in-car AR navigation and painted road markings in Apple Maps, Google Maps Live View and Mapbox Navigation, and built it over live OpenStreetMap zoom-16 tiles around Trafalgar Square, Northumberland Avenue, Victoria Embankment and Whitehall. The projective updateElementGeometry() hit-testing approach follows /three-form/ and /relief-map/ on this site.

A plain detached 1024 by 1024 canvas holds a 4 by 4 grid of zoom-16 OpenStreetMap tiles (x = 32743..32746, y = 21791..21794) fetched with crossOrigin = 'anonymous' and cached in memory. Before those tiles arrive, or if the device is offline, a procedural fallback paints the same Central London streets, River Thames curve and embankment parks into the atlas using the exact Web Mercator projection, so the road surface and route polyline align either way.

Everything on screen runs inside one WebGL 2 context from new ElementGL(canvas, ...). After stage.begin(), I save ElementGL's active program and vertex array object, upload any newly loaded OpenStreetMap tiles to the road texture with mipmaps, draw the pitched road plane, then draw the glowing route polyline and soft ground shadows on stage.gl. Restoring ElementGL's program and VAO lets stage.quad() draw the four depth-sorted HTML overlays straight onto the tarmac.

In Painted on road mode, each card lies horizontally just above the asphalt and aligns to its street bearing so perspective foreshortening narrows the far edge as you raise the camera pitch toward 68 degrees. Switching to Upright sign stands each card vertically on a post facing the camera's horizontal heading. In both modes, the exact 4 by 4 projective matrix mapping CSS pixels (0..w, 0..h) to canvas coordinates is scaled by geometryUnit() and passed to canvas.updateElementGeometry(), toggling dataset.hitTick whenever the transform shifts so Chromium's hit-test cache stays fresh. If WebGL 2 HTML-in-canvas isn't available, the page falls back to a 2D affine projection using five-argument drawElementImage(), or to plain HTML cards below a 2D road map if HTML-in-canvas is turned off or the context is lost.

Live checks

These checks run on isolated fixtures in a hidden corner stage and retire their canvases after each row, leaving the road map above untouched.

ResultCheckDetail

Findings