Enable/disable map terrain
This tutorial demonstrates how to enable/disable the 3D terrain map programmatically using SDK functions
The easiest and fastest way to create a map with 3D terrain is through the map options. Check out the tutorial Display a 3D terrain map
Click on the map to enable/disable the map terrain
Copy the following code, paste it into your favorite text editor, and save it as a
YOUR_MAPTILER_API_KEY_HEREwith your actual MapTiler API key.
The next it’s up to you. You can start the map in a different place by modifying the
starting zoom, and you can change the look of the map to any of our styles, or yours, by updating the
style. See what’s available here.
Install the npm package.
Include the CSS file.
If you have a bundler that can handle CSS, you can
importthe CSS or include it with a
<link>in the head of the document via the CDN
Capture when the user clicks on the map. Add event handler for map click event. You will add code to enable/diable the terrain in this handler.
Check whether or not the terrian is enabled.
Toggle the map terrain.
Exaggerate the terrain. The
enableTerrainfunction by default enables terrain with an exaggeration factor of 1 (actual values). This function also allows you to activate the terrain with a certain exaggeration factor. In this example we will apply a factor of 1.5 to accentuate the terrain volumen.
Add event handler for map terrain event. You will add code to tilt/untilt the map in this handler.
Tilt animation. To animate the transition when changing the map pitch, let’s create a function called changePitch.
Toggle the map pitch.
View complete source code on GitHub
Check out the tutorial Display a 3D terrain map
Consult the SDK JS Reference