Display a scene

Learn how to create and display a scene with a basemap layer and elevation.

A scene contains layers of geographic data that are displayed in 3D. Scenes allow you to display real-world visualizations of landscapes, objects, buildings, and other 3D objects. You display a scene using a scene view to display a basemap layer and data layers, and also to control the center location, tilt, and angle of the view.

In this tutorial, you create and display a scene of the Santa Monica Mountains in California using the topographic basemap layer and the world elevation layer. The scene and code will be used as the starting point for other 3D tutorials.

Prerequisites

You need a free ArcGIS developer account to access your dashboard and API keys. The API key must be scoped to access the services used in this tutorial.

Steps

Create a new pen

  1. Go to CodePen to create a new pen for your mapping application.

Add HTML

Define an HTML page to create a scene that is the full width and height of the browser window.

  1. In CodePen > HTML, add HTML and CSS to create a page with a viewDiv element for the scene.

    The HTML will create a scene that is the full width and height of the page. The viewDiv is the element displays the scene and its CSS resets any browser settings so it can consume the full width and height of the browser.

    Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.
                                                         
    
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Display a scene</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
        }
      </style>
    
      <link rel="stylesheet" href="https://js.arcgis.com/4.18/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.18/"></script>
    
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/SceneView"
      ], function(esriConfig,Map, SceneView) {
    
        esriConfig.apiKey = "YOUR-API-KEY";
    
        const map = new Map({
          basemap: "arcgis-topographic", //Basemap layer service
          ground: "world-elevation", //Elevation service
        });
    
        const view = new SceneView({
          container: "viewDiv",
          map: map,
          camera: {
            position: {
              x: -118.808, //Longitude
              y: 33.961, //Latitude
              z: 2000 //Meters
            },
            tilt: 75
          }
          });
    
        });
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>

Reference the API

  1. In the <head> tag, add references to the CSS file and JS library.

    Add line.Add line.Add line.
                                                         
    
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Display a scene</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
        }
      </style>
    
      <link rel="stylesheet" href="https://js.arcgis.com/4.18/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.18/"></script>
    
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/SceneView"
      ], function(esriConfig,Map, SceneView) {
    
        esriConfig.apiKey = "YOUR-API-KEY";
    
        const map = new Map({
          basemap: "arcgis-topographic", //Basemap layer service
          ground: "world-elevation", //Elevation service
        });
    
        const view = new SceneView({
          container: "viewDiv",
          map: map,
          camera: {
            position: {
              x: -118.808, //Longitude
              y: 33.961, //Latitude
              z: 2000 //Meters
            },
            tilt: 75
          }
          });
    
        });
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>

Add modules

The ArcGIS JS API contains AMD modules. Reference the Map and SceneView modules in the require statement.

  1. Add a <script> tag and an AMD require statement to load the Map and SceneView modules.

    You can also add the JavaScript code to the CodePen > JS panel instead of the HTML panel. If you do so, remove the <script> tag.

    Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.
                                                         
    
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Display a scene</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
        }
      </style>
    
      <link rel="stylesheet" href="https://js.arcgis.com/4.18/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.18/"></script>
    
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/SceneView"
      ], function(esriConfig,Map, SceneView) {
    
        esriConfig.apiKey = "YOUR-API-KEY";
    
        const map = new Map({
          basemap: "arcgis-topographic", //Basemap layer service
          ground: "world-elevation", //Elevation service
        });
    
        const view = new SceneView({
          container: "viewDiv",
          map: map,
          camera: {
            position: {
              x: -118.808, //Longitude
              y: 33.961, //Latitude
              z: 2000 //Meters
            },
            tilt: 75
          }
          });
    
        });
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>

Get an API key

An API key is required to access ArcGIS services.

  1. Go to your developer dashboard to get an API key.
  2. Copy the key as it will be used in the next step.

Create a scene

Use a Map to define the basemap layer and elevation surface. Scenes use the information in the elevation layer to determine the ground (surface) height that will be rendered on the map.

  1. Go back to CodePen.

  2. At the beginning of the main function, set your API key.

    Add line.
                                                         
    
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Display a scene</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
        }
      </style>
    
      <link rel="stylesheet" href="https://js.arcgis.com/4.18/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.18/"></script>
    
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/SceneView"
      ], function(esriConfig,Map, SceneView) {
    
        esriConfig.apiKey = "YOUR-API-KEY";
    
        const map = new Map({
          basemap: "arcgis-topographic", //Basemap layer service
          ground: "world-elevation", //Elevation service
        });
    
        const view = new SceneView({
          container: "viewDiv",
          map: map,
          camera: {
            position: {
              x: -118.808, //Longitude
              y: 33.961, //Latitude
              z: 2000 //Meters
            },
            tilt: 75
          }
          });
    
        });
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>
  3. Create a Map and set the basemap property to arcgis-topographic and the ground property to world-elevation.

    Add line.Add line.Add line.Add line.
                                                         
    
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Display a scene</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
        }
      </style>
    
      <link rel="stylesheet" href="https://js.arcgis.com/4.18/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.18/"></script>
    
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/SceneView"
      ], function(esriConfig,Map, SceneView) {
    
        esriConfig.apiKey = "YOUR-API-KEY";
    
        const map = new Map({
          basemap: "arcgis-topographic", //Basemap layer service
          ground: "world-elevation", //Elevation service
        });
    
        const view = new SceneView({
          container: "viewDiv",
          map: map,
          camera: {
            position: {
              x: -118.808, //Longitude
              y: 33.961, //Latitude
              z: 2000 //Meters
            },
            tilt: 75
          }
          });
    
        });
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>

Create a scene view

Use a SceneView class to set the map and layers to draw, as well as to define the camera position. The camera is the point from which the visible extent of the SceneView is determined. The tilt property refers to the number of degrees from the surface that the camera is pointed.

  1. Create a SceneView. Set the container, map, and camera properties.

    Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.
                                                         
    
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS API for JavaScript Tutorials: Display a scene</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
        }
      </style>
    
      <link rel="stylesheet" href="https://js.arcgis.com/4.18/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.18/"></script>
    
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/SceneView"
      ], function(esriConfig,Map, SceneView) {
    
        esriConfig.apiKey = "YOUR-API-KEY";
    
        const map = new Map({
          basemap: "arcgis-topographic", //Basemap layer service
          ground: "world-elevation", //Elevation service
        });
    
        const view = new SceneView({
          container: "viewDiv",
          map: map,
          camera: {
            position: {
              x: -118.808, //Longitude
              y: 33.961, //Latitude
              z: 2000 //Meters
            },
            tilt: 75
          }
          });
    
        });
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>

Run the app

In CodePen, run your code to display the map.

The scene view should display the topographic basemap layer and elevation layer for an area of the Santa Monica Mountains in California.

What's next?

Learn how to use additional API features and ArcGIS services in these tutorials: