Foldable paper OpenStreetMap pocket map

I wanted to see if real OpenStreetMap tiles and live interactive HTML place pins could fold together along vertical and horizontal paper-map creases on one 2D canvas. Drag the edges of the map or use the fold presets to crease it into a pocket map, then unfold it flat to click stops, filter the legend, and pan the streets.

1 Covent Garden

Market piazza and colonnade

Start
2 Waterloo Bridge

Thames crossing and South Bank

+0.7 km
3 Temple Gardens

Embankment lanes and courtyard

+0.8 km
4 Tate Modern

Bankside turbine hall

+0.9 km

Unfolded flat. Drag the map interior to pan, drag the edges to fold, or click a stop.

Map tiles: © OpenStreetMap contributors.

Show the code OSM tile atlas, 4x2 paper fold with 9-argument slices, hit boxes, and pointer input
  1. The markup. One <canvas content="drawable" layoutsubtree> holding four drawable place pins (#pin-0 to #pin-3) and one drawable legend card (#map-legend).
  2. OpenStreetMap tile atlas and fallback. Web Mercator projection into a plain offscreen 2D canvas, fetching tile.openstreetmap.org PNGs with crossOrigin = 'anonymous' and drawing procedural paper-map fallback tiles until each image arrives.
  3. Two-axis pocket fold. Four vertical accordion columns crossed by a horizontal midline hinge, slicing both the offscreen tile atlas and every overlapping HTML pin with nine-argument drawElementImage(), plus a back-cover pocket flap.
  4. Flat draws and hit boxes. When flat, each pin and the legend draw once with five-argument drawElementImage(). When lightly folded, empty-clip five-argument draws restore hit boxes; when covered by the back flap, park() moves hidden controls out of hit testing.
  5. Panning vs folding. Clicks on buttons, inputs, and checkboxes go straight to the live DOM. Dragging inside an unfolded map pans the tiles; dragging the canvas margins or any folded packet creases both axes.
  6. Card and legend layout. Fixed paper colours for the pins and legend so they read against both real OpenStreetMap tiles and dark-mode page chrome.

How it works

I built this around a single <canvas content="drawable" layoutsubtree> and a plain offscreen 2D canvas that holds the map sheet. The offscreen canvas composites live raster tiles from OpenStreetMap (https://tile.openstreetmap.org/{z}/{x}/{y}.png with crossOrigin = 'anonymous'), cached in memory by z/x/y. While tiles are loading or if the device is offline, each 256 by 256 tile slot draws a deterministic procedural street, river, park, and grid tile in the colour palette of Ordnance Survey pocket paper maps. The dashed walking route, neatline ticks, scale bar, and pin anchor dots draw onto that same offscreen sheet.

The four place pins (#pin-0 to #pin-3) and the pocket legend card (#map-legend) sit inside the canvas as sibling drawable HTML elements. When the map is flat (foldX <= 0.01 and foldY <= 0.01), I draw the offscreen sheet once and then draw each HTML element with a single unclipped five-argument drawElementImage(el, x, y, w, h). That leaves every button, search input, and checkbox with an exact native hit box while you pan the map underneath.

Once either fold slider moves off zero, the renderer switches to a 4 by 2 grid of hinged paper panels, extending the sheared-strip folding pattern from /accordion/ and /origami-ticket/ into two axes. Each of the four vertical columns applies cosine foreshortening and alternating vertical affine shear (ctx.transform(cosX, shearY, 0, scaleY, dx, dy)) so adjacent vertical creases meet without gaps. Inside every panel clip, I copy the matching strip of the offscreen tile atlas and slice every overlapping HTML pin or legend card with nine-argument drawElementImage(el, sx, sy, sw, sh, dx, dy, dw, dh) so tiles, routes, and live DOM bend together along the exact same creases.

The horizontal midline crease folds the top half down over the bottom half. Below 50% vertical fold, the top row foreshortens upward toward the midline. Past 50%, it flips downward over the bottom row and draws the cream paper back with an Ordnance-Survey-style pocket cover. Tight horizontal folding (past 72%) also swings a hinged back-cover pocket flap over the edge of the concertina stack. When elements are hidden under the folded cover, I call park() from /lib/stage-2d.js so covered buttons don't intercept taps; when motion settles back to flat, toggling a data-hit attribute clears Chromium's hit-test cache.

Live checks

These six checks run on isolated fixtures in the corner of the window and leave the map above untouched. Every pixel read copies the fixture canvas into a plain non-drawable 2D canvas with drawImage() before calling getImageData().

Findings