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 will 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

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.

    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS Maps SDK for JavaScript Tutorials: Display a scene</title>
      <style>
        html, body, #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
        }
      </style>
    
    </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.
    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS Maps SDK 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.30/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.30/"></script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>

Add modules

The ArcGIS Maps SDK for JavaScript is available as AMD modules and ES modules, but this tutorial is based on AMD. The AMD require function uses references to determine which modules will be loaded – for example, you can specify "esri/Map" for loading the Map module. After the modules are loaded, they are passed as parameters (e.g. Map) to the callback function where they can be used in your application. It is important to keep the module references and callback parameters in the same order. For more information on the different types of modules, visit the Overview Guide page.

  1. Add a <script> tag and a 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.
    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
      <title>ArcGIS Maps SDK 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.30/esri/themes/light/main.css">
      <script src="https://js.arcgis.com/4.30/"></script>
    
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/SceneView"
      ], function(esriConfig, Map, SceneView) {
    
        });
      </script>
    
    </head>
    <body>
      <div id="viewDiv"></div>
    </body>
    </html>

Get an access token

You need an access token with the correct privileges to access the location services used in this tutorial.

  1. Go to the Create an API key tutorial and create an API key with the following privilege:
    • Privileges
      • Location services > Basemaps
  2. Copy the API key as it will be used in the next step.

To learn about other ways to get an access token, go to Types of authentication.

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 the apiKey property to use your access token.

    Expand
    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
      <script>
        require([
          "esri/config",
          "esri/Map",
          "esri/views/SceneView"
      ], function(esriConfig, Map, SceneView) {
    
        esriConfig.apiKey = "YOUR_ACCESS_TOKEN";
    
    Expand
  3. Create a Map and set the basemap property to arcgis/topographic and the ground property to world-elevation.

    Expand
    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
        esriConfig.apiKey = "YOUR_ACCESS_TOKEN";
    
        const map = new Map({
          basemap: "arcgis/topographic", // basemap styles service
          ground: "world-elevation", //Elevation service
        });
    
    Expand

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.
    Expand
    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
        const map = new Map({
          basemap: "arcgis/topographic", // basemap styles 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
          }
          });
    
    Expand

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:

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.