Elevation profile control

The Elevation Profile control for MapTiler SDK is a super easy way to show the elevation profile of any GeoJSON or GPX (GPS) trace. By utilizing elevation data from MapTiler, this feature allows you to effortlessly showcase the elevation profile of your selected data source.

Following this step-by-step example, you can easily view the profile of various activities such as hiking routes, bicycle routes, trail runs, and more.

NPM module setup

  1. Install the npm package.

    
     npm install --save @maptiler/sdk
    
  2. Include the CSS file.

    If you have a bundler that can handle CSS, you can import the CSS

    
     import "@maptiler/sdk/dist/maptiler-sdk.css";
    

    or include it with a <link /> in the head of the document via the CDN

    
     <link href='https://cdn.maptiler.com/maptiler-sdk-js/v4.1.0/maptiler-sdk.css' rel='stylesheet' />
    
  3. Include the following code in your JavaScript file (Example: app.js).

    
     import * as maptilersdk from '@maptiler/sdk';
    
     maptilersdk.config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
     const map = new maptilersdk.Map({
       container: 'map', // container's id or the HTML element to render the map
       style: maptilersdk.MapStyle.OUTDOOR,
          
       center: [0.57705, 42.68311], // starting position [lng, lat]
       zoom: 12.22, // starting zoom
          
     });
    
  4. Replace YOUR_MAPTILER_API_KEY_HERE with your own API key. Make sure to secure the key before you publish it.

  5. The next is up to you. You can center your map wherever you desire (modifying the starting position) and set an appropriate zoom level (modifying the starting zoom) to match your users’ needs. Additionally, you can change the map’s look (by updating the source URL); choose from a range of visually appealing map styles from our extensive MapTiler standard maps, or create your own to truly differentiate your application.

  6. Install the elevation-profile-control npm package.

    
     npm install --save @maptiler/elevation-profile-control
    
  7. Import the MapTiler elevation profile control

    
     import * as maptilersdk from '@maptiler/sdk';
     import '@maptiler/sdk/dist/maptiler-sdk.css';
     import { ElevationProfileControl } from "@maptiler/elevation-profile-control";
    
  8. Instantiate the control and add it to a Map instance, most likely inside a map "ready" event callback

    
     map.on('ready', () => {
       maptilersdk.helpers.addPolyline(map, {
         data: 'YOUR_MAPTILER_DATASET_ID_HERE', 
         lineColor: '#66f', 
         lineWidth: 4, 
         outline: true, 
         outlineWidth: 2
       });
    
       // Create an instance
       const epc = new ElevationProfileControl({
         visible: true
       });
    
       // Add it to your map
       map.addControl(epc);
    
       // Add some data (from a URL or a MapTiler Data UUID)
       epc.setData('YOUR_MAPTILER_DATASET_ID_HERE');
    
     });
    

Learn more

You can also use elevation control via npm. See the How to display GPX track elevation profile example to use it as an npm module instead of from a CDN.

Show zoomed section in Elevation profile control

Zoomed section Elevation profile control

Examples

Display a zoomed-in section on the elevation profile.

Show the trace position with Elevation profile control

Show trace position Elevation profile control

Examples

Synchronize a moving map marker with elevation profile cursor.

Customize Elevation profile control

Customize Elevation profile control

Examples

Customize the MapTiler SDK elevation profile control interface.

Display a 3D terrain map

3D terrain map

Tutorials

Create and display 3D terrain maps on web pages.

Was this helpful?