3D relief map with live DOM pins and weather cards

I wanted to know if a procedural WebGL 2 relief map with real-time sun shading could hold live HTML weather cards in 3D space without breaking clicks or typing. Drag to orbit the island, pinch or scroll to zoom, sweep the sun azimuth to shift shadows across the ridges, or edit the field note and temperature units directly inside any card.

Ben Cairn Summit1,420 m
-3 °C48 km/h NW
Gale watchNo log yet
North Ridge Hut980 m
2 °C31 km/h W
Broken cloudNo log yet
West Harbour12 m
11 °C14 km/h SW
Clear bayNo log yet
South Cove Beacon45 m
9 °C22 km/h S
Coastal mistNo log yet
WebGL 2 relief

Drag to orbit, wheel or pinch to zoom. Tap any button, select or field note inside a station card.

Show the code procedural relief terrain, single-context ElementGL, 3D card projection and hit boxes
  1. Four station cards inside the canvas. Each weather card is a drawable child of <canvas content="drawable" layoutsubtree> with buttons, a unit <select> and an editable text <input>.
  2. Procedural alpine-and-coast heightfield. Deterministic five-octave noise with ridged peaks builds a 64 by 64 grid plus a plinth skirt with no network map tiles.
  3. Relief hillshading and card shaders. One shader colours elevation bands, anti-aliased contours, water glint and directional sun shading. The card fragment shader smooths tilted quad edges and adds depth haze.
  4. 3D quad projection and hit-test matrix. Both billboard and flat-on-map cards share one world-to-clip matrix for drawing and one element-to-canvas matrix for updateElementGeometry().
  5. One WebGL 2 context for terrain and DOM. The paint handler uploads changed cards through ElementGL, draws the relief mesh, terrain-conformed ground shadows and pin stems on stage.gl, then restores ElementGL's shader state to draw depth-sorted cards.
  6. Texture upload in element-gl.js. texElementSubImage2D() copies each card into a texture sized to getElementImageDefaultSize().

How it works

I took the idea from shader-driven relief maps like Mapbox GL and Tangram terrain hillshading, and from Three.js procedural topography experiments, then combined it with the 3D updateElementGeometry() hit-test pattern from /three-form/. Instead of loading external map tiles or a 3D engine, a deterministic noise function generates a 64 by 64 island heightfield with a central peak, an eastern granite ridge, a western harbour bay and a southern headland.

Everything renders on one WebGL 2 context created by new ElementGL(canvas, ...). On each paint event, the terrain mesh draws first with depth testing on. The vertex shader stores raw height and unscaled slope gradients once in the buffer, so dragging the elevation scale slider updates peaks and surface normals on the GPU without rebuilding geometry. Next, soft drop-shadow ellipses conformed to the local terrain height and screen-aligned pin stems draw over the slopes, shifting direction as you drag the sun azimuth slider.

After restoring ElementGL's shader program and vertex array object, the four station cards are sorted back-to-front by camera distance and drawn with stage.quad(). Each card's element-to-canvas projective matrix goes to canvas.updateElementGeometry(), scaled by geometryUnit() for high-DPI screens, and its data-hit-tick attribute toggles whenever the matrix changes to clear Chromium's hit-test cache. If WebGL 2 HTML-in-canvas isn't available, the page falls back to a 2D isometric relief projection with five-argument drawElementImage(), or to plain HTML cards below the 2D relief canvas when HTML-in-canvas is disabled.

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