Learn how to create and display a scene from a web scene stored in ArcGIS.
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:
-
You need an ArcGIS Location Platform or ArcGIS Online account.
-
Your system meets the system requirements.
Steps
Open the Xcode project
-
To start the tutorial, complete the Display a scene tutorial or download and unzip the solution.
-
Open the
.xcodeproj
file in Xcode. -
If you downloaded the solution, get an access token and set the API key.
An API Key gives your app access to secure resources used in this tutorial.
-
Go to the Create an API key tutorial to obtain a new API key access token. 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.
-
In Xcode, in the Project Navigator, click MainApp.swift.
-
In the Editor, set the
ArcGISEnvironment.apiKey
property on theArcGIS
with your access token.Environment MainApp.swiftUse dark colors for code blocks init() { ArcGISEnvironment.apiKey = APIKey("<#YOUR-ACCESS-TOKEN#>") }
-
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.
- 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.
- 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
-
In Xcode, in the Project Navigator, click ContentView.swift.
-
In the Editor, modify the
scene
closure to create aScene
for the web scene. To do this, create aPortal
providing the web scene's item ID and aItem Portal
referencing ArcGIS Online.ContentView.swiftUse dark colors for code blocks 22 23 27 28Change line Change line Change line @State private var scene: ArcGIS.Scene = { let portalID = PortalItem.ID("579f97b2f3b94d4a8e48a5f140a6639b")! let portalItem = PortalItem(portal: .arcGISOnline(connection: .anonymous), id: portalID) return Scene(item: portalItem) }()
-
Press Command + R to run the app.
If you are using the Xcode simulator your system must meet these minimum requirements: macOS Monterey 12.5, Xcode 15, iOS 17. If you are using a physical device, then refer to the system requirements.
Your app should display the scene that you viewed earlier in the Scene Viewer. You should see a map of trails, trailheads and parks in the Santa Monica Mountains. Drag, pinch, and rotate on the scene view to explore the scene.
What's Next?
Learn how to use additional API features, ArcGIS location services, and ArcGIS tools in these tutorials: