On the Matterhorn, a political boundary and a mountain ridge run close together. Put them on separate layers and you have a useful alignment check for a web map. The viewer below uses a 12 km square of elevation measurements and a generalized international border. Toggle the line and switch to the overhead camera to inspect their relationship.

1. Give the raster and the boundary one coordinate frame
The elevation source is a Mapzen Terrarium tile. Decode its RGB channels to metres with 256 × R + G + B / 256 − 32768 before resampling. Terrain Tiles use a Web Mercator tile grid. In QGIS, assign the tile its correct georeferenced bounds, then use Warp (reproject) to project the decoded raster to WGS 84 / UTM zone 32N (EPSG:32632). The boundary source is the Natural Earth 1:10m land boundary dataset. Its continental mapping scale accounts for the small number of line vertices at this zoom. Terrain Tiles · Terrarium encoding · Natural Earth boundaries
For the source tile linked below, save the PNG as tile.png. The following commands apply the tile’s outer bounds in EPSG:3857 and decode its three bands into one floating-point elevation band.
gdal_translate -q -a_srs EPSG:3857 \
-a_ullr 782715.16964 5792092.25534 860986.68660 5713820.73837 \
tile.png rgb-3857.tif
gdal_calc -A rgb-3857.tif --A_band=1 -B rgb-3857.tif --B_band=2 \
-C rgb-3857.tif --C_band=3 --type=Float32 \
--calc="A.astype(float)*256+B+C/256.0-32768" --outfile=elevation-3857.tifUse a north-up grid of 97 × 97 samples, spaced 125 m apart. The northwest sample centre is at easting 387,000 and northing 5,098,000. The southeast centre is at 399,000 and 5,086,000. GDAL takes the outer pixel edges for the output extent. Add 62.5 m around the sample centres and use bilinear resampling. Failing to add that half-pixel pad shifts the terrain under its overlay.
gdalwarp -t_srs EPSG:32632 -r bilinear -ot Int16 \
-te 386937.5 5085937.5 399062.5 5098062.5 -ts 97 97 \
elevation-3857.tif alpine.tifFor the vector layer, save a copy in the same UTM projection and clip it to the sample-centre rectangle. Export the clipped geometry to GeoJSON with WGS 84 longitude and latitude. Simplify that line with Mapshaper using a 20 m tolerance. Here the result has seven vertices. Work from an appropriate higher-resolution boundary dataset if you need local detail. Mapshaper · QGIS raster projection tools
mapshaper alpine-borders.geojson -simplify dp interval=20m \
-filter-fields -o format=geojson precision=0.000001 border.geojsonFor this page, the raster warp and vector clip ran with GDAL 3.12.1 and the simplification ran with Mapshaper 0.8.5. The QGIS instructions describe the desktop equivalent. We projected the simplified line back to UTM for display. Download the prepared GeoTIFF and GeoJSON to inspect their alignment in QGIS.
2. Give the coding agent coordinates it can test
We loaded the geometry and shader guides from Three.js Skills while implementing the viewer. The geometry guide informed the indexed plane and recalculated normals. The shader guide informed the elevation uniforms and the WebGL vertex and fragment stages. The critical input to the agent was the coordinate contract, including sample order and vertical units. Geometry skill used · Shader skill used
Build a north-up Three.js terrain from 9,409 signed little-endian heights in metres. Read rows from north to south. Map east to +X, elevation to +Y, and south to +Z. Use the same UTM origin and spacing for the border. Shade by elevation and draw contour intervals of 250 m. Check all four corners before adding a camera transition.
The render buffer is 18,818 bytes. Reading the four corners in NW, NE, SW, SE order yields 2,524, 3,187, 2,303, and 3,018 metres. With a terrain width of two scene units, the horizontal mapping is x = (east − 387000) / 6000 − 1 and z = (5098000 − north) / 6000 − 1. The height transform is y = (height − 1962) × 1.6 / 6000. Moving the camera should leave the same line pinned to the same slopes. Height buffer · Grid metadata and projected boundary
The plane has 96 × 96 cells and 18,432 triangles. After changing vertex heights, recompute its normals for slope shading. For the red line, insert samples along the long boundary segments and interpolate the elevation on the actual triangle below each one. A small display offset keeps the line visible on the surface. The fragment shader spaces contours in elevation metres, so toggling the contours changes the map style while preserving its geography.
The same mapping drives the mesh and the overlay. In the fragment shader a derivative-scaled edge softens the contour at its current screen size. Here vY is the interpolated scene height. The two uniforms convert the elevation datum and 250 m interval into scene units.
float band = (vY + uDatum) / uInterval;
float dist = abs(fract(band + 0.5) - 0.5);
float ink = 1.0 - smoothstep(0.005, max(fwidth(band), 0.012), dist);
if (uContours) color *= 1.0 - 0.32 * ink;3. Connect React controls to the scene
The HUD is a small React root mounted beside the canvas. Its three buttons call the scene directly. Boundary switches a Three.js group’s visibility. Contour lines changes a shader uniform. Overhead view eases the camera between two spherical poses looking at the same target. A second click mid-flight starts from the current pose, and a reduced-motion preference switches poses immediately.
Try hiding the boundary, switching to the overhead view, then restoring the line. The controls preserve independent state. The canvas redraws on a change or resize and runs an animation loop only during a camera transition. You can replace the buttons with your own motion components and keep that same layer and camera API.
Derived elevation from Terrarium tile 9/266/182, resampled for this preview. Europe terrain data produced using Copernicus data and information funded by the European Union, EU-DEM layers. SRTM and GMTED2010 data courtesy of the U.S. Geological Survey. Boundary from Natural Earth. Terrain source credits · Natural Earth terms

