Elevation by Point
This example demonstrates how to display elevation information on a map using the Elevation service. Click on any point of the map to retrieve elevation data.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdn.smartmaps.cloud/packages/smartmaps/elevation/umd/elevation.min.js"></script>
<script src="https://cdn.smartmaps.cloud/packages/smartmaps/smartmaps-gl/v2/umd/smartmaps-gl.min.js"></script>
<style>
body {
margin: 0;
padding: 0;
}
html,
body,
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
const apiKey = 'INSERT API-KEY';
const map = new smartmapsgl.Map({
apiKey: apiKey,
container: 'map',
center: { lat: 49.02164948779226, lng: 8.439330018049352 },
zoom: 10,
style: smartmapsgl.MapStyle.LIGHT,
terrain: {
activated: true
}
});
const elevation = new smartmaps.elevationService.Elevation(apiKey);
map.on('click', async (event) => {
const params = {
point: {
longitude: event.lngLat.lng,
latitude: event.lngLat.lat
}
};
const elevationData = await elevation.point(params);
const popupContent = `
<strong>Information:</strong><br>
Elevation: ${elevationData.features[0].properties.elevation} meters<br>
`;
new smartmapsgl.Popup().setLngLat(event.lngLat).setHTML(popupContent).addTo(map);
});
</script>
</body>
</html>