Display a web scene

A web scene is a scene that is stored as an item in ArcGIS Online. A web scene item contains all of the configuration settings for the scene (in JSON format) such as extent, basemap, data layers, and styles. Applications can access and display the web scene using its item ID.

In this tutorial, you will access and display a pre-configured web scene stored in ArcGIS Online.

Prerequisites

Steps

Create a new pen

  1. To get started, either complete the Display a map tutorial or .

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(s):
    • Privileges
      • Location services > Basemaps
  2. In CodePen, set esriConfig.apiKey to your API key..
    Use dark colors for code blocks
    1
    2
    3
    4
    esriConfig.apiKey = "YOUR_ACCESS_TOKEN";
    const map = new Map({
      basemap: "arcgis/topographic" // basemap styles service
    });

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

Add modules

  1. In the require statement, delete the Map and MapView modules. Add the WebScene, SceneView, and Legend modules.

    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
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
          "esri/config",
    
          "esri/Map",
          "esri/MapView",
    
          "esri/WebScene",
          "esri/views/SceneView",
          "esri/widgets/Legend"
    
        ], function(esriConfig, WebScene, SceneView, Legend) {
    
    Expand

Load the web scene

You can use the portal item ID to create a WebScene. The web scene will be passed to the view.

  1. Delete the code that creates the Map and the MapView.

    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
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
         esriConfig.apiKey = "YOUR_ACCESS_TOKEN";
    
          const map = new Map ({
            basemap: "arcgis/topographic"
          });
    
          const view = new MapView({
              map: map,
              center: [-118.805, 34.027], // Longitude, latitude
              zoom: 13, // Zoom level
              container: "viewDiv" // Div element
            });
    
    
    Expand
  2. Create a WebScene. Load the web scene using its portal item ID.

    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
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
         esriConfig.apiKey = "YOUR_ACCESS_TOKEN";
    
          const webscene = new WebScene({
            portalItem: {
              id: "579f97b2f3b94d4a8e48a5f140a6639b"
            }
          });
    
    Expand

Create a scene view

  1. Create a SceneView and set the container and map 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
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
          const webscene = new WebScene({
            portalItem: {
              id: "579f97b2f3b94d4a8e48a5f140a6639b"
            }
          });
    
          const view = new SceneView({
            container: "viewDiv",
            map: webscene
          });
    
    Expand
  2. At the top-right, click Run to verify that the web map has been successfully loaded and displays.

Add widgets

Use the Legend widget to add more context to the application. The Legend widget displays labels and symbols for layers visible in the view.

  1. Create a Legend to display feature information. Add the legend to the top-right of the view.
    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
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
          const view = new SceneView({
            container: "viewDiv",
            map: webscene
          });
    
          const legend = new Legend ({
            view:view
          });
    
          view.ui.add(legend, "top-right");
    
    Expand

Run the app

In CodePen, run your code to display the map.

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.