Display a scene
Learn how to create and display a scene with a basemap layer and an elevation layer. Set properties of the scene's camera to control the 3D perspective.
Like a map, a scene contains layers of geographic data. It contains a basemap layer and, optionally, one or more data layers. To provide a realistic view of the terrain, you can also add elevation layers to define the height of the surface across the scene. The 3D perspective of the scene is controlled by the scene's camera, which defines the position of the scene observer in 3D space.
In this tutorial, you create and display a scene using the imagery basemap layer. The surface of the scene is defined with an elevation layer and the camera is positioned to display an area of the Santa Monica Mountains in the scene view.
The scene and code will be used as the starting point for other 3D tutorials.
Prerequisites
The following are required for this tutorial:
- An ArcGIS account to access your API keys. If you don't have an account, sign up for free.
- Your system meets the system requirements.
Steps
Create a new Xcode project
Use Xcode to create an iOS app and configure it to reference the API.
Open Xcode. In the menu bar, click File > New > Project.
- In the Choose a template for your new project window, select iOS then App.
- Click Next.
- In the Choose a template for your new project window, set the following properties:
- Product Name:
<your app name>
- Organization Identifier:
<your organization>
- Interface: SwiftUI
- Language: Swift
- Product Name:
- Click Next.
- Choose a location to store your project. Click Create.
In the Project Navigatorr, click on the swift file named <your_app_name>App. In the Editor, right click on the struct name, <your_app_name>App. Select Refactor > Rename... and type
Main
. Click the Rename button in the top right to confirm the new name of the file and struct. TheApp Main
file and struct will be used by all following tutorials.App Add a reference to the API using Swift Package Manager.
Add a scene
Use the scene view to display a scene centered on the Santa Monica Mountains in California. The scene will contain an imagery basemap layer.
In Xcode, in the Project Navigator, click ContentView.swift.
In the Editor, add a
@State
property wrapper namedObject scene
of typeScene
with a default value. Create aArcGIS.Scene
with aarc
basemap style and return it.GISImagery Standard ContentView.swiftUse dark colors for code blocks Add line. Add line. Add line. Add line. Create a new
Surface
and add a newArcGISTiled
to it to define the base surface for the scene. Set the newly createdElevation Source surface
as the base surface of thescene
.ContentView.swiftUse dark colors for code blocks Add line. Add line. Add line. Add line. Add line. Add line. Set the initial viewpoint of the
scene
using aPoint
and aCamera
.ContentView.swiftUse dark colors for code blocks Add line. Add line. Add line.
Add a scene view to the UI
A scene view is a UI component that displays a scene. It also handles user interactions with the scene, including navigating with touch gestures.
Add a
Scene
initialized with the previously created scene to theView Content
body.View ContentView.swiftUse dark colors for code blocks Add line. Add line. Add line.
Set your API key
An API key is required to enable access to services, web maps, and web scenes hosted in ArcGIS Online.If you haven't already, 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.
In the Project Navigator, click MainApp.swift.
In the Editor, add an
import
statement to reference the API.MainApp.swiftUse dark colors for code blocks Add line. Implement an initializer in the
Main
struct. Set theApp api
property on theKey ArcGISEnvironment
with your API Key.MainApp.swiftUse dark colors for code blocks Add line. Add line. Add line. Press <Command+R> to run the app.
You should see a scene with the imagery basemap layer centered on the Santa Monica Mountains in California. 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: