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 features layers for the Santa Monica Mountains in California.

Prerequisites

The following are required for this tutorial:

  1. An ArcGIS account to access your API keys. If you don't have an account, sign up for free.
  2. Your system meets the system requirements.
  3. The ArcGIS Runtime API for iOS is installed.

Steps

Open an Xcode project

This tutorial uses the completed Display a scene tutorial as a starting point. You can complete that tutorial first or download the completed solution.

  1. To start the tutorial, complete the Display a scene tutorial or download and unzip the solution.
  2. Open the .xcodeproj file in Xcode.

Set the API Key

An API Key enables access to services, web maps, and web scenes hosted in ArcGIS Online.

  1. Go to your developer dashboard to get your API key. For these tutorials, use your default API key. It is scoped to include all of the services demonstrated in the tutorials.

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

  3. In the editor, set the apiKey property on the AGSArcGISRuntimeEnvironment with your API key.


    AppDelegate.swift
                                       
    Change 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
    // Copyright 2021 Esri
    //
    // Licensed under the Apache License, Version 2.0 (the "License");
    // you may not use this file except in compliance with the License.
    // You may obtain a copy of the License at
    //
    //   https://www.apache.org/licenses/LICENSE-2.0
    //
    // Unless required by applicable law or agreed to in writing, software
    // distributed under the License is distributed on an "AS IS" BASIS,
    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    // See the License for the specific language governing permissions and
    // limitations under the License.
    
    
    import UIKit
    
    import ArcGIS
    
    
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
        var window: UIWindow?
    
        func application(_ application: UIApplication,
                         didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
            // Note: it is not best practice to store API keys in source code.
            // The API key is referenced here for the convenience of this tutorial.
    
            AGSArcGISRuntimeEnvironment.apiKey = "YOUR_API_KEY"
    
            return true
        }
    
    }
    

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
    26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 27 28 29 30 31 32 33 34 35 36 36 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
    //// Copyright 2018 Esri
    //
    // Licensed under the Apache License, Version 2.0 (the "License");
    // you may not use this file except in compliance with the License.
    // You may obtain a copy of the License at
    //
    //   http://www.apache.org/licenses/LICENSE-2.0
    //
    // Unless required by applicable law or agreed to in writing, software
    // distributed under the License is distributed on an "AS IS" BASIS,
    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    // See the License for the specific language governing permissions and
    // limitations under the License.
    
    import UIKit
    import ArcGIS
    
    class ViewController: UIViewController {
    
        @IBOutlet weak var sceneView: AGSSceneView!
    
        override func viewDidLoad() {
            super.viewDidLoad()
            setupScene()
        }
    
        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 in the iOS Simulator. Note that the simulator does not provide the best performance for interacting with the 3D scene. For a better experience, run the app on a physical device.

    Other ways to run the project in Xcode:

    • In Xcode's app menu, select Product > Run.

    • Pressing the Run button at the top-left of the Xcode project window.

What's Next?

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

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