Skip to content

Enable 3D Terrain

The community styles ship with a rgb-tiles terrain-DEM source. Call map.setTerrain() to raise the surface into 3D, and add a sky for the horizon. Tilt the map to see the alpine relief.

Note: Instead you can simply use the 3D version of our standard styles: For example use “summer-3d.json” (or any other of the default styles) to get the 3d version.

import { MaptoolkitLogoControl } from 'https://cdn.jsdelivr.net/npm/@maptoolkit/maplibre-gl-logo/+esm';
const map = new maplibregl.Map({ container: 'map', attributionControl: { customAttribution: '' }, style: 'https://styles.maptoolkit.org/summer.json', center: [12.694, 47.074], zoom: 12, pitch: 80, bearing: 0 }); // Grossglockner, Alps
map.on('load', function () {
  map.setTerrain({ source: 'rgb-tiles', exaggeration: 1.6 });
  map.setSky({ 'sky-color': '#a3ccff', 'sky-horizon-blend': 0.6, 'horizon-color': '#ffffff', 'horizon-fog-blend': 0.6, 'fog-color': '#ffffff', 'fog-ground-blend': 0.4 });
});
map.addControl(new MaptoolkitLogoControl());
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/maplibre-gl.js"></script>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/maplibre-gl.css" />
  <style>
    html, body { width: 100%; height: 100%; margin: 0; padding: 0; }
    #map { width: 100%; height: 100%; }
  </style>
</head>
<body>
  <div id="map"></div>
  <script type="module">
import { MaptoolkitLogoControl } from 'https://cdn.jsdelivr.net/npm/@maptoolkit/maplibre-gl-logo/+esm';
const map = new maplibregl.Map({ container: 'map', attributionControl: { customAttribution: '' }, style: 'https://styles.maptoolkit.org/summer.json', center: [12.694, 47.074], zoom: 12, pitch: 80, bearing: 0 }); // Grossglockner, Alps
map.on('load', function () {
  map.setTerrain({ source: 'rgb-tiles', exaggeration: 1.6 });
  map.setSky({ 'sky-color': '#a3ccff', 'sky-horizon-blend': 0.6, 'horizon-color': '#ffffff', 'horizon-fog-blend': 0.6, 'fog-color': '#ffffff', 'fog-ground-blend': 0.4 });
});
map.addControl(new MaptoolkitLogoControl());
  </script>
</body>
</html>