Tilted OpenStreetMap with zero-drift HTML markers and PNG export

I wanted to know if a tilted 3D OpenStreetMap canvas could hold live HTML place cards with zero pan or zoom drift, real 3D building occlusion, keyboard Tab navigation and one-click PNG export. Drag the map to pan, right-drag (or use two fingers) to rotate, tilt the pitch slider, press Tab to step across pins, or export the whole scene into one PNG.

Waterloo StationTransit
51.5031, -0.1132Visit
Tate ModernCulture
51.5076, -0.0994Visit
Borough MarketFood
51.5055, -0.0910Visit
Westminster PierRiver
51.5015, -0.1235Visit
WebGL 2 map

Drag to pan, right-drag or two-finger twist to rotate, wheel or pinch to zoom, or press Tab to step across place cards.

Show the code OpenStreetMap tile atlas, 3D building extrusions, depth-occluded DOM cards and PNG export
  1. Four place cards inside the canvas. Each landmark card is a drawable child of <canvas content="drawable" layoutsubtree> with buttons, a tag <select> and an editable visit note <input>.
  2. OpenStreetMap tile cache and offline atlas. A plain offscreen 2D canvas draws a procedural street-and-river base and composites cached crossOrigin = 'anonymous' tiles from tile.openstreetmap.org before uploading one texture to WebGL 2.
  3. 3D extruded landmark buildings and shaders. Shaded prisms sit at real city coordinates and write to the depth buffer so tilting and rotating the map hides pins behind taller towers.
  4. One WebGL 2 pass with depth occlusion and hit boxes. Ground tiles, buildings, pin stems and ElementGL cards share one camera matrix, then updateElementGeometry() and geometryUnit() sync every card's hit box.
  5. Tap-triggered PNG export. On click, the page draws a fresh frame, copies the canvas into a plain 2D canvas with drawImage(), adds attribution, calls toDataURL('image/png') and retires the temporary canvas.
  6. Texture upload in element-gl.js. texElementSubImage2D() copies each card into a texture sized to getElementImageDefaultSize().

How it works

Web maps usually pick between two awkward marker models. Libraries like Leaflet (L.divIcon) and MapLibre GL (maplibregl.Marker) float HTML pins in a sibling DOM layer above the canvas, which keeps forms and keyboard Tab focus working, though pins can lag behind the GPU camera during fast pans or pitches, can't be occluded by 3D buildings, and disappear when you call canvas.toDataURL(). Moving markers into a WebGL symbol layer fixes drift and export, yet gives up real inputs, buttons and Tab order.

Here I put four live HTML place cards inside one <canvas content="drawable" layoutsubtree> and render everything through a single ElementGL WebGL 2 context, building on the shared-context pattern from /relief-map/ and the projective hit-test matrix from /three-form/. OpenStreetMap raster tiles (https://tile.openstreetmap.org/{z}/{x}/{y}.png, © OpenStreetMap contributors) load with img.crossOrigin = 'anonymous' into an in-memory cache and composite onto one plain 1,280 by 1,280 offscreen 2D canvas. While tiles arrive (or if you're offline), that atlas draws a procedural street grid, parks and river geometry for London, Tokyo and San Francisco so the ground plane is never blank.

On each paint event, the ground quad, the extruded 3D landmark buildings, the pin stems and the four uploaded DOM cards all project through the same view-projection matrix derived from Web Mercator coordinates. Because ElementGL transforms each card quad with that matrix, leaving DEPTH_TEST enabled makes the GPU depth buffer occlude cards pixel-by-pixel behind closer 3D towers; unchecking "3D building occlusion" disables depth testing before the card pass so cards float in front. After drawing each card, updateElementGeometry() receives the element-to-canvas projective matrix scaled by geometryUnit(), and toggles data-hit-tick whenever the matrix changes to clear Chromium's hit-test cache.

Pressing Tab steps natively through every button, select and note input inside the canvas; a focusin listener highlights that card's stem and smoothly pans the map so the focused pin moves into view. Clicking "Export PNG" draws a fresh frame, copies the canvas into a plain 2D canvas with drawImage(), stamps the OpenStreetMap credit, generates a PNG data URL and retires the copy canvas immediately.

Live checks

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

ResultCheckDetail

Findings