Display a web scene

Learn how to create and display a scene from a web scene stored in ArcGIS.

display a web scene

This tutorial shows you how to create and display a scene from a web scene. All web scenes are stored in ArcGIS with a unique item ID. You will access an existing web scene by item ID and display its layers. The web scene contains feature layers for the Santa Monica Mountains in California.

Prerequisites

Before starting this tutorial:

  1. You need an ArcGIS Location Platform or ArcGIS Online account.

  2. Your system meets the system requirements.

Steps

Open the Xcode project

  1. To start the tutorial, complete the Display a scene tutorial or download and unzip the solution.

  2. Open the .xcodeproj file in Xcode.

  3. If you downloaded the solution, get an access token and set the API key.

Set the API Key

An API Key gives your app access to secure resources used in this tutorial.

  1. Go to the Create an API key tutorial to obtain a new API key access token using your ArcGIS Location Platform or ArcGIS Online account. Ensure that the following privilege is enabled: Location services > Basemaps > Basemap styles service. Copy the access token as it will be used in the next step.

  2. In Xcode, in the Project Navigator, click AppDelegate.swift.

  3. In the editor, set the APIKey property on the AGSArcGISRuntimeEnvironment with your access token.

    AppDelegate.swift
    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
        func application(_ application: UIApplication,
                         didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
            AGSArcGISRuntimeEnvironment.apiKey = "YOUR_ACCESS_TOKEN"
    
            return true
        }
    
    Expand

Get the web map item ID

You can use ArcGIS tools to create and view web scenes. Use the Scene Viewer to identify the web scene item ID. This item ID will be used later in the tutorial.

  1. Go to the LA Trails and Parks web scene in the Scene Viewer in ArcGIS Online. This web scene displays trails, trailheads and parks in the Santa Monica Mountains.
  2. Make a note of the item ID at the end of the browser's URL. The item ID should be 579f97b2f3b94d4a8e48a5f140a6639b.

Display the web scene

  1. In Xcode, in the Project Navigator, click ViewController.swift.

  2. In the editor, modify the setupScene() method to create an AGSScene for the web scene. To do this, create a portal item providing the web scene's item ID and an AGSPortal referencing ArcGIS Online.

    ViewController.swift
    Use dark colors for code blocks
    27 28 29 30 31 32 33 34 35 36
    Change lineChange lineChange lineChange lineChange line
    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
        private func setupScene() {
    
            let scene: AGSScene = {
                let portal = AGSPortal.arcGISOnline(withLoginRequired: false)
                let item = AGSPortalItem(portal: portal, itemID: "579f97b2f3b94d4a8e48a5f140a6639b")
                return AGSScene(item: item)
            }()
    
            sceneView.scene = scene
        }
    
  3. Press Command + R to run the app.

Your app should display the scene that you viewed earlier in the Scene Viewer.

What's Next?

Learn how to use additional API features, ArcGIS location services, and ArcGIS tools 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.