How 3D Terrain Works
GLMap SDK 2.0 can raise the map into the shape of the ground. The same vector map, with its roads, labels, tracks and markers, lies on the terrain instead of on a flat plane. Here is Chamonix going from flat to 3D and back:
Terrain is one of the larger features of the GLMap 2.0 release. This post shows what an application changes to use it and how the renderer draws it.
Turning it on
Terrain is one property, altitudeScale. At 0 the map is flat and no terrain data is even loaded; at 1 the
heights are natural; values up to 3 exaggerate them. It can be animated, which is how the video above goes from
flat to 3D.
mapView.mapPitch = 45
mapView.drawHillshades = true
mapView.drawElevationLines = true
mapView.altitudeScale = 1
On Android the properties have the same names:
renderer.mapPitch = 45f
renderer.drawHillshades = true
renderer.drawElevationLines = true
renderer.altitudeScale = 1f
Nothing else in the application changes. Routes, tracks, markers and labels are added as before and appear at the height of the ground under them.
How the renderer draws it
The map is not rebuilt in 3D. The renderer first draws the ordinary flat map, exactly as without terrain, into an offscreen texture. Then it draws the terrain: for every elevation tile, a regular grid of 128 by 128 cells, coarser for distant tiles, whose vertices take their height from the tile's elevation in the vertex shader. The flat map is stretched over that surface like a printed sheet over a relief model. A skirt along the tile edges hides the gaps between neighbouring tiles.
Labels, markers and other objects that must stay upright are not part of the sheet. For each of them the engine looks up the ground height at its position from the same elevation data and draws it at that height, so a peak name stands on the peak and a marker on the trail.
Terrain fades in with the pitch: below 20° of tilt the heights are scaled down towards zero, and a map seen straight from above is flat. Below zoom 7, where mountains are a few pixels high, terrain is off.
Hillshades, slopes and contours
The elevation data drives three more views, and each can be switched on separately:
- Hillshades (
drawHillshades): the engine computes surface normals from the elevation grid of each tile, and the shader takes the brightness for that normal from a light texture. WithrotateHillshadesLight, which is on by default, the light turns with the map, so the relief keeps its look when the map is rotated. - Slopes (
drawSlopes): the same normals, coloured by steepness, for ski and mountaineering maps. - Elevation lines (
drawElevationLines): contours traced from the elevation grid and drawn as ordinary vector lines with height labels.
Offline
Elevation is an optional data set in the same download flow as maps and navigation data. An app downloads it for the regions it needs, and terrain, hillshades and contours then work without a network connection.
Platforms and examples
Terrain is available on iOS and Android from the same 2.0 release. GLMap uses Metal on Apple devices and Vulkan or OpenGL ES on Android, with the same controls on both.
The example applications show Chamonix with terrain:
Both download map and elevation data for the area, turn terrain on, and leave the rest of the screen ordinary application code.
If you are building an outdoor, off-road, navigation or GIS product and want to try terrain with your own data and style, write to [email protected].
