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.

image

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:

  1. An ArcGIS account to access API keys. If you don't have an account, sign up for free.
  2. A development and deployment environment that meets the system requirements.
  3. An IDE for Android development in Kotlin.

Steps

Create a new Android Studio project

Use Android Studio to create an app and configure it to reference the API.

  1. Open Android Studio.

    • In the menu bar, click File > New > New Project....
    • In the Create New Project window, make sure Phone and Tablet tab is selected, and then select Empty Activity. Click Next.
    • In the Configure your project window, set the following configuration options:
      • Name: Display a scene.
      • Package name: Change to com.example.app. Or change to match your organization.
      • Save location: Set to a new folder.
      • Language: Kotlin
      • Minimum SDK: API 26: Android 8.0 (O)
  2. In the Project tool window, make sure that your current view is Android. These tutorial instructions refer to that view.

  3. From the Project tool window, open Gradle Scripts > build.gradle (Project: Display_a_scene). Replace the contents of the file with the following code:

    build.gradle (Project: Display_a_scene)
    Use dark colors for code blocks
    1 2 3 4 5 6 7 8 9 10 11
    Change lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange line
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    plugins {
        id 'com.android.application' version '8.1.1' apply false
        id 'com.android.library' version '8.1.1' apply false
        id 'org.jetbrains.kotlin.android' version '1.9.10' apply false
    }
    
    tasks.register('clean', Delete) {
        delete rootProject.buildDir
    }
  4. From the Project tool window, open Gradle Scripts > build.gradle (Module: Display_a_scene.app). Replace the contents of the file with the following code:

    build.gradle (Module: app)
    Use dark colors for code blocks
    1 2 3 4 5 6 7 8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
    Change lineChange lineChange lineChange lineChange 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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    apply plugin: 'com.android.application'
    apply plugin: 'org.jetbrains.kotlin.android'
    
    android {
        compileSdk 33
    
        defaultConfig {
            applicationId "com.example.app"
            minSdkVersion 26
    
    Expand
  5. From the Project tool window, open Gradle Scripts > settings.gradle. Replace the contents of the file with the following code:

    settings.gradle (Display a scene)
    Use dark colors for code blocks
    1 2 3 4 5 6 7 8 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10
    Change lineChange lineChange lineChange lineChange lineChange 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
    
    pluginManagement {
        repositories {
            gradlePluginPortal()
            google()
            mavenCentral()
        }
    }
    
    dependencyResolutionManagement {
    
    Expand
  6. Sync the Gradle changes. Click the Sync now prompt or click the refresh icon (Sync Project with Gradle Files) in the toolbar. This may take several minutes.

  7. From the Project tool window, open app > manifests > AndroidManifest.xml. Update the Android manifest to allow network access.

    AndroidManifest.xml
    Expand
    Use dark colors for code blocks
    2 2 3 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
    Add 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
    <manifest xmlns:android="http://schemas.android.com/apk/res/android">
    
        <uses-permission android:name="android.permission.INTERNET" />
    
    Expand

Add import statements

Open app > java > com.example.app MainActivity.kt, and add import statements to reference the API.

MainActivity.kt
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.example.app

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import com.arcgismaps.ApiKey
import com.arcgismaps.ArcGISEnvironment
import com.arcgismaps.geometry.Point
import com.arcgismaps.geometry.SpatialReference
import com.arcgismaps.mapping.ArcGISScene
import com.arcgismaps.mapping.ArcGISTiledElevationSource
import com.arcgismaps.mapping.BasemapStyle
import com.arcgismaps.mapping.Surface
import com.arcgismaps.mapping.Viewpoint
import com.arcgismaps.mapping.view.Camera
import com.arcgismaps.mapping.view.SceneView
import com.example.app.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {

Add a UI for the scene view

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 XML to add a scene view to the UI and make it available to the main activity source code.

  1. In app > res > layout > activity_main.xml, replace the entire TextView element with a SceneView element.

    activity_main.xml
    Use dark colors for code blocks
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
    Change lineChange lineChange lineChange line
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    <?xml version="1.0" encoding="utf-8"?>
    <layout xmlns:android="http://schemas.android.com/apk/res/android">
    
        <androidx.constraintlayout.widget.ConstraintLayout xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".MainActivity">
    
            <com.arcgismaps.mapping.view.SceneView
                android:id="@+id/sceneView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
    
        </androidx.constraintlayout.widget.ConstraintLayout>
    </layout>
  2. In MainActivity.kt, create a read-only lazy variable named activityMainBinding referencing the generated Android class ActivityMainBinding. This variable will be initialized with DataBindingUtil.setContentView(this, R.layout.activity_main) when called.

    MainActivity.kt
    Expand
    Use dark colors for code blocks
    34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 35 36 37 38 39 40 40 40 40 39 39 39 39 39 39 38 37 36 35 35 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -3
    Add line.Add line.Add 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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    class MainActivity : AppCompatActivity() {
    
        private val activityMainBinding: ActivityMainBinding by lazy {
            DataBindingUtil.setContentView(this, R.layout.activity_main)
        }
    
    
    Expand
  3. Create a read-only variable named sceneView and bind it to the sceneView created in activity_main.xml.

    MainActivity.kt
    Expand
    Use dark colors for code blocks
    34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 35 36 37 38 39 40 41 42 43 43 43 43 43 43 43 42 41 40 39 39 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 1
    Add line.Add line.Add 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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    class MainActivity : AppCompatActivity() {
    
        private val activityMainBinding: ActivityMainBinding by lazy {
            DataBindingUtil.setContentView(this, R.layout.activity_main)
        }
    
        private val sceneView: SceneView by lazy {
            activityMainBinding.sceneView
        }
    
    Expand

Add a scene

Use the scene view to display a scene centered on the Santa Monica Mountains in California. The scene will contain a imagery basemap layer.

  1. In MainActivity.kt, add a new setupScene() method in your MainActivity class and create an ArcGISScene with an imagery basemap.

    MainActivity.kt
    Expand
    Use dark colors for code blocks
    64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 63 62 61 60 60 60 59 58 57 56 55 54 53 52 51 52 53 54 55 56 56 56 56 56 56 56 56 56 55 54 54 54 54 54 54 54 54 55 56 56 56 56 57 57 57
    Add 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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
        // set up your scene here. You will call this method from onCreate()
        private fun setupScene() {
    
            val scene = ArcGISScene(BasemapStyle.ArcGISImagery).apply {
    
            }
    
        }
    
    Expand
  2. Create a new ArcGISTiledElevationSource and use it to create a new Surface. Then set the elevationExaggeration property on the surface to 2.5f to increase the 3D effect of the elevation.

    MainActivity.kt
    Expand
    Use dark colors for code blocks
    64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 63 62 61 60 60 60 59 58 57 56 55 54 53 52 51 52 53 54 55 56 57 58 59 60 61 62 63 64 63 62 62 62 62 62 62 62 62 63 64 64 64 64 65 65 65
    Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add 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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
        // set up your scene here. You will call this method from onCreate()
        private fun setupScene() {
    
            val scene = ArcGISScene(BasemapStyle.ArcGISImagery).apply {
    
                // add base surface for elevation data
                val elevationSource = ArcGISTiledElevationSource("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer")
                val surface = Surface().apply {
                    elevationSources.add(elevationSource)
                    // add an exaggeration factor to increase the 3D effect of the elevation.
                    elevationExaggeration = 2.5f
                }
    
            }
    
        }
    
    Expand
  3. Set the baseSurface property of the scene to the surface.

    MainActivity.kt
    Expand
    Use dark colors for code blocks
    64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 63 62 61 60 60 60 59 58 57 56 55 54 53 52 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 66 66 66 66 66 66 66 67 68 68 68 68 69 69 69
    Add 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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
        // set up your scene here. You will call this method from onCreate()
        private fun setupScene() {
    
            val scene = ArcGISScene(BasemapStyle.ArcGISImagery).apply {
    
                // add base surface for elevation data
                val elevationSource = ArcGISTiledElevationSource("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer")
                val surface = Surface().apply {
                    elevationSources.add(elevationSource)
                    // add an exaggeration factor to increase the 3D effect of the elevation.
                    elevationExaggeration = 2.5f
                }
    
                baseSurface = surface
    
            }
    
        }
    
    Expand
  4. Create a Point for the camera and assign it to cameraLocation. Then create a Camera, passing the cameraLocation and values for the camera's heading, pitch, and roll.

    MainActivity.kt
    Expand
    Use dark colors for code blocks
    64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 63 62 62 62 61 60 59 58 57 56 55 54 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 73 73 74 75 76 77 78 79 79 79
    Add line.Add line.Add line.Add line.Add 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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
        // set up your scene here. You will call this method from onCreate()
        private fun setupScene() {
    
            val scene = ArcGISScene(BasemapStyle.ArcGISImagery).apply {
    
                // add base surface for elevation data
                val elevationSource = ArcGISTiledElevationSource("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer")
                val surface = Surface().apply {
                    elevationSources.add(elevationSource)
                    // add an exaggeration factor to increase the 3D effect of the elevation.
                    elevationExaggeration = 2.5f
                }
    
                baseSurface = surface
    
                // Point(x, y, z, spatialReference)
                val cameraLocation = Point(-118.794, 33.909, 5330.0, SpatialReference.wgs84())
                // Camera(location, heading, pitch, roll)
                val camera = Camera(cameraLocation, 355.0, 72.0, 0.0)
    
            }
    
            // set the scene on the scene view
            sceneView.scene = scene
    
        }
    
    Expand
  5. Create a Viewpoint using the cameraLocation the camera and set it as the initial viewpoint for the scene.

    MainActivity.kt
    Expand
    Use dark colors for code blocks
    64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 63 62 61 60 60 60 59 58 57 56 55 54 53 52 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 75 75 75 76 76 76
    Add 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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
        // set up your scene here. You will call this method from onCreate()
        private fun setupScene() {
    
            val scene = ArcGISScene(BasemapStyle.ArcGISImagery).apply {
    
                // add base surface for elevation data
                val elevationSource = ArcGISTiledElevationSource("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer")
                val surface = Surface().apply {
                    elevationSources.add(elevationSource)
                    // add an exaggeration factor to increase the 3D effect of the elevation.
                    elevationExaggeration = 2.5f
                }
    
                baseSurface = surface
    
                // Point(x, y, z, spatialReference)
                val cameraLocation = Point(-118.794, 33.909, 5330.0, SpatialReference.wgs84())
                // Camera(location, heading, pitch, roll)
                val camera = Camera(cameraLocation, 355.0, 72.0, 0.0)
    
                initialViewpoint = Viewpoint(cameraLocation, camera)
    
            }
    
        }
    
    Expand
  6. Set the scene property of sceneView to the new ArcGISScene.

    MainActivity.kt
    Expand
    Use dark colors for code blocks
    64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 63 62 61 60 60 60 59 58 57 56 55 54 53 52 51 52 53 54 55 56 56 56 56 56 56 56 56 56 55 54 54 54 54 54 54 54 54 55 56 57 58 59 60 60 60
    Add line.Add 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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
        // set up your scene here. You will call this method from onCreate()
        private fun setupScene() {
    
            val scene = ArcGISScene(BasemapStyle.ArcGISImagery).apply {
    
            }
    
            // set the scene on the scene view
            sceneView.scene = scene
    
        }
    
    Expand
  7. In the onCreate() method, call lifecycle.addObserver(sceneView) to add the sceneView to the lifecycle scope. Then call setupScene(), which has been defined in the previous steps.

    MainActivity.kt
    Expand
    Use dark colors for code blocks
    44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 45 46 47 48 49 49 49 50 51 52 52 51 50 49 48 47 46 45 44 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43
    Change lineAdd 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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
    
            lifecycle.addObserver(sceneView)
    
            setupScene()
    
        }
    
    Expand

Set your 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. Create the setApiKey() method, where you will set the ArcGISEnvironment.apiKey​ property by calling ApiKey.create() and passing your API key as a string. Don't forget the quotes.

    MainActivity.kt
    Use dark colors for code blocks
    55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 56 57 58 59 60 61 62 63 64 65 66 67 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68 68
    Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add 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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
        private fun setApiKey(){
            // set your API key
            // 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.
    
            ArcGISEnvironment.apiKey = ApiKey.create("YOUR_API_KEY")
    
        }
    
        // set up your scene here. You will call this method from onCreate()
        private fun setupScene() {
    
            val scene = ArcGISScene(BasemapStyle.ArcGISImagery).apply {
    
  3. Call setApiKey() in the onCreate() lifecycle method, before the setupScene() call.

    MainActivity.kt
    Expand
    Use dark colors for code blocks
    44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 45 46 47 48 49 50 51 52 53 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54
    Add 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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
    
            lifecycle.addObserver(sceneView)
    
            setApiKey()
    
            setupScene()
    
        }
    
    Expand
  4. Click Run > Run > app to run the app.

You should see a scene with the imagery basemap layer centered on the Santa Monica Mountains in California. Pinch, drag, and double-tap 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:

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