Show elevation on click

How to get the elevation in meters from any location. MapTiler SDK elevation functions provide convenient access to get the elevation in meters from any location. It’s possible to look up and compute the elevation from: a single location, provide a batch of points, a GeoJSON LineString or a GeoJSON MultiLineString.

Click on the map to get the elevation at this location

NPM module setup


npm install --save @maptiler/sdk
import { Map, MapStyle, config } from '@maptiler/sdk';
import '@maptiler/sdk/dist/maptiler-sdk.css';

config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
const map = new Map({
    container: 'map',
    style: MapStyle.HYBRID,
    center: [-70.02454, -33.81356],
    zoom: 12
});

map.on('load', function () {
    map.on('click', async function (ev) {
      const {lng, lat} = ev.lngLat;
      //get the elevation at a given position
      const elevatedPosition = await maptilersdk.elevation.at([lng, lat]);
      const popup = new maptilersdk.Popup()
        .setLngLat([lng, lat])
        .setHTML(`<h2>Elevation</h2>
        <h3>${elevatedPosition[2].toFixed(0)} mts</h3>`)
        .addTo(map);
    });
});
Elevation profile control

Add elevation profile control

Examples

Show elevation profiles for GeoJSON traces using MapTiler.

Display a 3D terrain map

3D terrain map

Tutorials

Create and display 3D terrain maps on web pages.

Get POIs information on click

Get POIs information on click

Examples

Get POI information by clicking the map.

Display a popup on click

Display a popup on click

Examples

Display a popup when a user clicks a symbol.

Was this helpful?