Multi-layer X-ray lens over OpenStreetMap

I wanted to know if a draggable circular shader lens over an OpenStreetMap street map could reveal a second map layer underneath alongside live HTML neighbourhood cards that only exist inside the lens. Drag the circular lens over the orange district markers to reveal each card, switch between night transit, thermal density and blueprint contour views, or pin the lens so tapping a checkbox, button or text input on a phone is easy.

Soho94 heat
Bakerloo / Elizabeth
Covent Garden88 heat
Piccadilly Line
South Bank81 heat
Waterloo / Jubilee
Bloomsbury69 heat
Russell Sq / Northern
WebGL 2 lens
© OpenStreetMap contributors, © CARTO
z14

Drag inside the brass ring to move the lens, drag outside to pan the map, or press Pin lens before tapping a card control.

Show the code OSM/CARTO tile textures, dual-layer bevel shader, circular card clipping and hit-box gating
  1. Four neighbourhood cards inside the canvas. Each card is a drawable child of <canvas content="drawable" layoutsubtree> with a transit filter checkbox, a save button and an editable district tag input.
  2. Web Mercator projection and two tile caches. Live daytime tiles from OpenStreetMap and dark tiles from CARTO DarkMatter paint into two plain offscreen canvases, with a deterministic procedural street grid filling any slot that is still loading or offline.
  3. Dual-layer X-ray lens and circular card aperture shaders. The map shader blends daytime tiles outside the brass bezel with night transit, thermal density or Sobel blueprint edges inside, adding curved glass bevel refraction near the rim. The card shader clips each DOM quad to the same circle.
  4. Hit boxes clipped to the lens with canvasClip and inert. Cards outside the circle are marked inert = true with a zero-size canvasClip; cards inside compute the overlapping visible rectangle in element coordinates, scale canvasTransform with geometryUnit() and toggle data-hit-tick.
  5. One WebGL 2 context for both map layers and live DOM cards. The paint handler uploads dirty cards via ElementGL, draws the fullscreen lens shader on stage.gl, then restores ElementGL's shader and VAO to draw the clipped cards.
  6. Texture upload in element-gl.js. texElementSubImage2D() copies each card into a texture sized to getElementImageDefaultSize().

How it works

The idea goes back to Bier et al.'s Magic Lenses paper at Xerox PARC (1993), combined with the live DOM lens experiments in /lens/ and /translate-lens/ on this site. Here the lens sits over live slippy-map tiles from OpenStreetMap (daytime base) and CARTO DarkMatter (night transit layer). Both tile layers composite into two plain offscreen 2D canvases (never drawable canvases) and upload to WebGL 2 textures only when a tile finishes loading or the map pans or zooms. While a tile is fetching or if you are offline, a deterministic street grid fills that tile slot so the shaders still have real lines to work on.

Everything on screen runs inside one WebGL 2 context from new ElementGL(canvas, ...). On each paint event, the map pass draws a fullscreen quad: outside the bevelled brass ring it samples the daytime OpenStreetMap texture and paints four district beacons; inside the ring it applies curved glass bevel refraction near the rim, optional optical zoom (1.0x to 1.8x) and the chosen lens mode. Night + Transit blends CARTO DarkMatter tiles (or a dark nocturnal fallback transform while tiles load) with glowing district transit rings controlled by each card's Transit checkbox. Thermal maps local street contrast and district activity plumes onto a five-stop false-colour ramp. Blueprint runs a 3 by 3 Sobel edge filter over the daytime tile luminance to pull out roads, parks and building edges on a drafting grid.

After restoring ElementGL's program and vertex array object, the four drawable neighbourhood cards draw on top. Each card's fragment shader checks the fragment's canvas CSS coordinates against the lens centre and radius, discarding anything outside the circular aperture so cards slide cleanly out from under the brass rim as you scan across a city. Hit testing follows the same aperture: cards outside the circle get inert = true and a zero-size canvasClip so hidden cards never intercept taps or keyboard focus, while cards inside pass their visible overlap rectangle to canvas.updateElementGeometry(card, { canvasTransform, canvasClip }) scaled by geometryUnit(). If WebGL 2 HTML-in-canvas isn't available, the page falls back to a 2D circular ctx.clip() path with five-argument drawElementImage(), or moves the cards into a plain HTML grid below the 2D map if HTML-in-canvas is disabled or the WebGL context is lost.

Live checks

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

ResultCheckDetail

Findings