Elevation nach Punkt
Dieses Beispiel demonstriert die Integration von SmartMaps GL mit der Elevation-Service-API. Es erstellt eine interaktive Karte, auf der Nutzer auf einen beliebigen Punkt klicken können, um sofort die Höhendaten für diesen Standort abzurufen.
<!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/smartmaps-gl/v2/umd/smartmaps-gl.min.js"></script>
<style>
body {
margin: 0;
padding: 0;
}
html,
body,
#map {
height: 100%;
}
#controls {
position: absolute;
top: 10px;
left: 10px;
background: white;
padding: 10px;
z-index: 1;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
const apiKey = '[INSERT API-KEY]';
const map = new smartmapsgl.Map({
apiKey,
container: "map",
center: { lat: 49.02164948779226, lng: 8.439330018049352 },
zoom: 3,
style: smartmapsgl.MapStyle.AUTO,
terrain: {
activated: true
}
});
map.on('load', () => {
map.on('click', (e) => {
const latitude = e.lngLat.lat;
const longitude = e.lngLat.lng;
const url = `https://elevation.smartmaps.cloud/api/v2/Elevation/point?latitude=${latitude}&longitude=${longitude}&apiKey=${smartmapsgl.encodeString(apiKey)}`;
fetch(url)
.then(response => response.json())
.then(data => {
const elevation = data.features[0].properties.elevation;
const popupContent = `
<strong>Information:</strong><br>
Elevation: ${elevation} meters<br>
`;
new smartmapsgl.Popup()
.setLngLat(e.lngLat)
.setHTML(popupContent)
.addTo(map);
})
});
});
</script>
</body>
</html>