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 a single view iOS app and configure it to reference the API.
Open Xcode. In the menu bar, click File > New > Project > iOS > Single View App > Next.
- In the Choose options window, set the following properties:
- Product Name:
<your app name>
- Language: Swift
- User interface: Storyboard
- Organization Identifier:
<your organization>
- Product Name:
- Uncheck all other options.
- Click Next > Create.
- In the Choose options window, set the following properties:
Add a reference to the API by following the instructions in Get the API - Configure a project.
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. Use Xcode and the storyboard editor to add a scene view to the UI and connect it to the view controller source code. Set the scene view size to fill the entire device display.
In the Project Navigator, click ViewController.swift.
In the editor, add an
import
statement to reference the API and add an@IBOutlet
namedscene
and of typeView AGSScene
. This will provide a reference to the scene view that you will create in the storyboard.View ViewController.swiftUse dark colors for code blocks Add line. Add line. AGSScene
is a subclass ofView UIView
.In the Project Navigator, click Main.storyboard to open the storyboard editor.
In the menu, click View > Show Library to display the object library.
In the object library browser:
- Type
uiview
or scroll down to find View. - Drag and drop a new view on to the storyboard's main view.
- Type
At the bottom right of the storyboard editor, click Add New Constraints. In the panel:
- Type
0
for the top, right, bottom, and left constraints. - Click Add 4 Constraints.
The new view expands to fill the display.
- Type
In the menu, click View > Inspectors > Show Identity Inspector. In the Inspectors panel, set Custom Class > Class to
AGSScene
.View This sets the type of the new view to
AGSScene
.View In the storyboard editor, right-click on the yellow View Controller icon to display the Connections panel. Drag the sceneView outlet connector to the new
AGSScene
view on the storyboard.View This connects the
AGSScene
in the storyboard to theView scene
outlet created earlier in theView View
class.Controller
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 ViewController.swift.
In the editor, define a private method named
setup
. InScene() setup
create anScene() AGSScene
.ViewController.swiftUse dark colors for code blocks Add line. Add line. Add line. Add line. Add line. Create a new
AGSSurface
and add a newAGSArcGISTiled
to it to define the base surface for the scene. Set the newly created surface as the base surface of theElevation Source scene
.An elevation source can define a surface with 3D terrain in a scene. Without an elevation source, the default globe surface is used to display the scene.
ViewController.swiftUse dark colors for code blocks Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Set the initial viewpoint of the
scene
using anView AGSPoint
and anAGSCamera
.The position from which you view the scene is defined by an
AGSCamera
. The following properties of the camera are used to define an observation point in the scene:- 3D location: Latitude, longitude, and altitude
- Heading: Azimuth of the camera's direction
- Pitch: Up and down angle
- Roll: Side-to-side angle
ViewController.swiftUse dark colors for code blocks Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Set the
scene
property of thescene
outlet to the newView AGSScene
.ViewController.swiftUse dark colors for code blocks Add line. In the
View
'sController view
method, callD i d Load setup
once the view has loaded.Scene() ViewController.swiftUse dark colors for code blocks 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 AppDelegate.swift.
In the editor, add an
import
statement to reference the API and in theApp
'sDelegate application(_
method, set the: did Finish Launching With Options: ) api
property on theKey AGSArcGISRuntime
with your API Key.Environment AppDelegate.swiftUse dark colors for code blocks Add line. Add line. Press <Command+R> to run the app.
If you are using the Xcode simulator your system must meet these minimum requirements: macOS Big Sur 11.3, Xcode 13, iOS 13. If you are using a physical device, then refer to the system requirements.
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: