Learn how to find the elevation of a point in Kaneohe, Hawaii with the ArcGIS Elevation service.
The ArcGIS Elevation service is a location service that returns elevation values for a single location or multiple locations. Elevation coverage is provided for both topography (land elevations) and bathymetry (water depths) and takes location inputs as longitude and latitude coordinates.
In this tutorial, use ArcGIS REST JS to access the Elevation service and display the elevation of a single location on a map. You can toggle between viewing elevation values relative to mean sea level or above ground level.
Prerequisites
You need an ArcGIS Location Platform account.
ArcGIS Online and ArcGIS Enterprise accounts are not supported.
Steps
Get the starter app
Select a type of authentication and follow the steps to create a new app.
Choose API key authentication if you:
- Want the easiest way to get started.
- Want to build public applications that access ArcGIS Location Services and secure items.
- Have an ArcGIS Location Platform or ArcGIS Online account.
Choose user authentication if you:
- Want to build private applications.
- Require application users to sign in with their own ArcGIS account and access resources their behalf.
- Have an ArcGIS Online account.
To learn more about both types of authentication, go to Authentication.
Set up authentication
Set developer credentials
Use the API key or OAuth developer credentials so your application can access ArcGIS services.
Add script references
Reference the ArcGIS REST JS request and elevation packages to access the Elevation service. You also reference the Calcite Design System library to create the user interface.
-
Reference the
requestandelevationpackages from ArcGIS REST JS. sUse dark colors for code blocks <!-- Load Leaflet from CDN --> <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" crossorigin=""> <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" crossorigin=""></script> <!-- Load Esri Leaflet from CDN --> <script src="https://unpkg.com/esri-leaflet@3.0.19/dist/esri-leaflet.js"></script> <script src="https://unpkg.com/esri-leaflet-vector@4.3.2/dist/esri-leaflet-vector.js"></script> <!-- Load ArcGIS REST JS --> <script src="https://unpkg.com/@esri/arcgis-rest-request@4/dist/bundled/request.umd.js"></script> <script src="https://unpkg.com/@esri/arcgis-rest-elevation@1/dist/bundled/elevation.umd.js"></script> -
Reference the Calcite Design System library.
Use dark colors for code blocks <!-- Load Leaflet from CDN --> <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" crossorigin=""> <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" crossorigin=""></script> <!-- Load Esri Leaflet from CDN --> <script src="https://unpkg.com/esri-leaflet@3.0.19/dist/esri-leaflet.js"></script> <script src="https://unpkg.com/esri-leaflet-vector@4.3.2/dist/esri-leaflet-vector.js"></script> <!-- Load ArcGIS REST JS --> <script src="https://unpkg.com/@esri/arcgis-rest-request@4/dist/bundled/request.umd.js"></script> <script src="https://unpkg.com/@esri/arcgis-rest-elevation@1/dist/bundled/elevation.umd.js"></script> <!-- Calcite components --> <script type="module" src="https://js.arcgis.com/calcite-components/2.12.1/calcite.esm.js"></script> <link rel="stylesheet" href="https://js.arcgis.com/calcite-components/2.12.1/calcite.css">
Create a toggle switch
In this step, you use Calcite to add a toggle switch. The switch will allow users to toggle between elevation values relative to mean sea level and ground level.
-
Inside
<html, create a> divcontainer for the toggle control. Usecalcite-switchto create a toggle switch.Use dark colors for code blocks <div id="control"> <label> <span>Show elevation relative to mean sea level</span> <calcite-switch id="elevationControl" checked></calcite-switch> </label> </div> <div id="map"></div> -
Add CSS to position the toggle switch on top of the map.
Use dark colors for code blocks body { margin: 0; padding: 0; } #map { position: absolute; top: 0; bottom: 0; right: 0; left: 0; font-family: Arial, Helvetica, sans-serif; font-size: 14px; z-index: 1; cursor: default; } #control { position: absolute; top: 15px; right: 15px; display: flex; flex-direction: row; z-index: 2; padding: 10px; background: #fff; }
Update the map
In this step, you update the map by changing the basemap and setting the viewpoint to focus on Kaneohe, Hawaii.
-
Set the basemap to
arcgis/topographic.Use dark colors for code blocks const basemapEnum = "arcgis/topographic"; -
To focus on Kaneohe, Hawaii, update the map's viewpoint to
21.410, -157.750and set the zoom level to12.Use dark colors for code blocks const map = L.map("map", { minZoom: 2 }).setView([21.410, -157.750], 12);
Get elevation data
In this step, you use the Elevation service to return the elevation data at the clicked point on the map.
-
Create a variable called
elevationto store the default elevation reference (datum), which will beMeasure mean.Sea Level Use dark colors for code blocks /* Use for API key authentication */ const accessToken = "YOUR_ACCESS_TOKEN"; // or /* Use for user authentication */ // const session = await arcgisRest.ArcGISIdentityManager.beginOAuth2({ // clientId: "YOUR_CLIENT_ID", // Your client ID from OAuth credentials // redirectUri: "YOUR_REDIRECT_URL", // The redirect URL registered in your OAuth credentials // portal: "YOUR_PORTAL_URL" // Your portal URL // }) // const accessToken = session.token; const basemapEnum = "arcgis/topographic"; const map = L.map("map", { minZoom: 2 }).setView([21.410, -157.750], 12); L.esri.Vector.vectorBasemapLayer(basemapEnum, { token: accessToken }).addTo(map); let elevationMeasure = "meanSeaLevel"; // default -
Add an event listener to your toggle to update the
elevationaccordingly.Measure Use dark colors for code blocks /* Use for API key authentication */ const accessToken = "YOUR_ACCESS_TOKEN"; // or /* Use for user authentication */ // const session = await arcgisRest.ArcGISIdentityManager.beginOAuth2({ // clientId: "YOUR_CLIENT_ID", // Your client ID from OAuth credentials // redirectUri: "YOUR_REDIRECT_URL", // The redirect URL registered in your OAuth credentials // portal: "YOUR_PORTAL_URL" // Your portal URL // }) // const accessToken = session.token; const basemapEnum = "arcgis/topographic"; const map = L.map("map", { minZoom: 2 }).setView([21.410, -157.750], 12); L.esri.Vector.vectorBasemapLayer(basemapEnum, { token: accessToken }).addTo(map); let elevationMeasure = "meanSeaLevel"; // default document.getElementById("elevationControl").addEventListener("calciteSwitchChange", (event) => { elevationMeasure = event.target.checked ? "meanSeaLevel" : "ellipsoid"; }); -
Add a click event handler to create a marker on the clicked point and request elevation data for the point.
Use dark colors for code blocks let circleMarker = null; map.on("click", async (e) => { const { lat, lng } = e.latlng; if (circleMarker) { map.removeLayer(circleMarker); } circleMarker = L.circle([lat, lng], { color: "#00000", fillColor: "#FF0000", radius: 75, fillOpacity: 1 }).addTo(map); const response = await arcgisRest.findElevationAtPoint({ lon: lng, lat: lat, relativeTo: elevationMeasure, authentication: arcgisRest.ApiKeyManager.fromKey(accessToken) }); });
Display results
In this step, you extract the elevation data from the response and display it in a popup on the map.
-
Extract the
x,y, andzvalues from the elevation request response.Use dark colors for code blocks let circleMarker = null; map.on("click", async (e) => { const { lat, lng } = e.latlng; if (circleMarker) { map.removeLayer(circleMarker); } circleMarker = L.circle([lat, lng], { color: "#00000", fillColor: "#FF0000", radius: 75, fillOpacity: 1 }).addTo(map); const response = await arcgisRest.findElevationAtPoint({ lon: lng, lat: lat, relativeTo: elevationMeasure, authentication: arcgisRest.ApiKeyManager.fromKey(accessToken) }); const { x, y, z } = response.result.point; }); -
Use
L.popup()to show the elevation (zvalue) at the clicked location in a popup format.Use dark colors for code blocks let circleMarker = null; map.on("click", async (e) => { const { lat, lng } = e.latlng; if (circleMarker) { map.removeLayer(circleMarker); } circleMarker = L.circle([lat, lng], { color: "#00000", fillColor: "#FF0000", radius: 75, fillOpacity: 1 }).addTo(map); const response = await arcgisRest.findElevationAtPoint({ lon: lng, lat: lat, relativeTo: elevationMeasure, authentication: arcgisRest.ApiKeyManager.fromKey(accessToken) }); const { x, y, z } = response.result.point; L.popup() .setLatLng(e.latlng) .setContent( `<b>Elevation relative to ${elevationMeasure === "meanSeaLevel" ? "mean sea level" : "ground level"}</b><br> Latitude: ${y.toFixed(5)}<br> Longitude: ${x.toFixed(5)}<br> Elevation: ${z} m` ) .openOn(map); });
Run the app
Run the app.
You should now see a map centered over Kaneohe, Hawaii. Click on the map to access the Elevation service to return elevation information and view the results in a popup.What's next?
Learn how to use additional location services in these tutorials:


