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 your API keys. If you don't have an account, sign up for free.
  2. Confirm that your system meets the minimum system requirements.
  3. An IDE for Java.

Steps

Create a new Java project with Gradle

  1. Open IntelliJ IDEA.

    • In the menu bar, click File > New > Project.

    • In the New Project window, select Gradle from the list on the left and click Next.

    • In the next window, enter a name for your new project and choose a location to save it.

  2. In the project, replace the contents of the build.gradle file with the following script to configure your app and reference the API. Make sure that you import the Gradle changes once you have replaced the contents.

    build.gradle
    Change lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange lineChange 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
    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
    plugins {
        id 'application'
        id 'org.openjfx.javafxplugin' version '0.0.8'
    }
    
    ext {
        arcgisVersion = '100.11.0'
    }
    
    javafx {
        version = "11.0.2"
        modules = [ 'javafx.controls', 'javafx.fxml', 'javafx.web', 'javafx.media' ]
    }
    
    compileJava.options.encoding = 'UTF-8'
    
    repositories {
        jcenter()
        maven {
            url 'https://esri.jfrog.io/artifactory/arcgis'
        }
    }
    
    configurations {
        natives
    }
    
    dependencies {
        implementation "com.esri.arcgisruntime:arcgis-java:$arcgisVersion"
        natives "com.esri.arcgisruntime:arcgis-java-jnilibs:$arcgisVersion"
        natives "com.esri.arcgisruntime:arcgis-java-resources:$arcgisVersion"
    }
    
    task copyNatives(type: Copy) {
        description = "Copies the arcgis native libraries into the " +
                "project build directory for development."
        group = "build"
        configurations.natives.asFileTree.each {
            from(zipTree(it))
        }
        // store native libraries in a common location shared with other samples
        into "${System.properties.getProperty("user.home")}/.arcgis/$arcgisVersion"
    }
    
    run {
        dependsOn copyNatives
        mainClassName = 'com.example.app.App'
    }
    
    wrapper {
        gradleVersion = '6.5.1'
    }
    
  3. Click View > Tool Windows > Gradle to open the Gradle view, then in Tasks > build, double-click copyNatives. This unpacks the native library dependencies to $USER_HOME/.arcgis.

    You can also run Gradle tasks via the command line. Consult Gradle's documentation to learn how this is done.

  4. In the Project tool window, under src/main, right-click the Java folder, and click New > Package.

  5. Name the package com.example.app.

  6. Right-click this package and click New > Java class.

  7. Name the class App.java.

Add import statements

In App.Java, add import statements to reference the ArcGIS Runtime API and JavaFX classes.

App.java
Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.
1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18
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

//   Copyright 2020 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.

package com.example.app;

import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.geometry.SpatialReferences;
import com.esri.arcgisruntime.mapping.ArcGISScene;
import com.esri.arcgisruntime.mapping.ArcGISTiledElevationSource;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.Surface;
import com.esri.arcgisruntime.mapping.view.Camera;
import com.esri.arcgisruntime.mapping.view.SceneView;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class App extends Application {

  private SceneView sceneView;

  public static void main(String[] args) {
    Application.launch(args);
  }

  @Override
  public void start(Stage stage) {

    // set the title and size of the stage and show it
    stage.setTitle("Display a scene tutorial");
    stage.setWidth(800);
    stage.setHeight(700);
    stage.show();

    // create a JavaFX scene with a stack pane as the root node, and add it to the scene
    StackPane stackPane = new StackPane();
    Scene fxScene = new Scene(stackPane);

    stage.setScene(fxScene);

    // 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.
    String yourApiKey = "YOUR_API_KEY";
    ArcGISRuntimeEnvironment.setApiKey(yourApiKey);

    // create a scene view to display the scene and add it to the stack pane
    sceneView = new SceneView();
    stackPane.getChildren().add(sceneView);

    ArcGISScene scene = new ArcGISScene(Basemap.createImagery());

    // set the scene on the scene view
    sceneView.setArcGISScene(scene);

    // add base surface for elevation data
    Surface surface = new Surface();
    String elevationServiceUrl = "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer";
    surface.getElevationSources().add(new ArcGISTiledElevationSource(elevationServiceUrl));
    // add an exaggeration factor to increase the 3D effect of the elevation.
    surface.setElevationExaggeration(2.5f);

    scene.setBaseSurface(surface);

    Point cameraLocation = new Point(-118.794, 33.909, 5330.0, SpatialReferences.getWgs84());
    Camera camera = new Camera(cameraLocation, 355.0, 72.0, 0.0);
    sceneView.setViewpointCamera(camera);

  }

  /**
   * Stops and releases all resources used in application.
   */
  @Override
  public void stop() {
    if (sceneView != null) {
      sceneView.dispose();
    }
  }

}

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. Use JavaFX to add a scene view to the UI.

  1. In App.Java, create a new public class named App that extends the JavaFX Application class.

    • Add a member variable for a SceneView and a main() method.

      The main() method constructs an instance of the Application on the JavaFX Application Thread.

      The sceneView member variable allows you to easily reference your SceneView from other parts of the application.

    • In the start() method, configure the JavaFX Stage with a title and dimensions, and then show it.

      Note that the start method is abstract and must be overridden. It takes a single parameter of the JavaFX type Stage.

    • Create a JavaFX StackPane, and use it to create a JavaFX Scene. Then set the JavaFX scene on the stage.

      App.java
      Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.
      31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 32 33 34 35 36 37 38 39 40 41 42 43 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 55 56 56 56 56 56 56 56 56 56 56 56 57
      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
      
      //   Copyright 2020 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.
      
      package com.example.app;
      
      import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
      import com.esri.arcgisruntime.geometry.Point;
      import com.esri.arcgisruntime.geometry.SpatialReferences;
      import com.esri.arcgisruntime.mapping.ArcGISScene;
      import com.esri.arcgisruntime.mapping.ArcGISTiledElevationSource;
      import com.esri.arcgisruntime.mapping.Basemap;
      import com.esri.arcgisruntime.mapping.Surface;
      import com.esri.arcgisruntime.mapping.view.Camera;
      import com.esri.arcgisruntime.mapping.view.SceneView;
      
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;
      
      public class App extends Application {
      
        private SceneView sceneView;
      
        public static void main(String[] args) {
          Application.launch(args);
        }
      
        @Override
        public void start(Stage stage) {
      
          // set the title and size of the stage and show it
          stage.setTitle("Display a scene tutorial");
          stage.setWidth(800);
          stage.setHeight(700);
          stage.show();
      
          // create a JavaFX scene with a stack pane as the root node, and add it to the scene
          StackPane stackPane = new StackPane();
          Scene fxScene = new Scene(stackPane);
      
          stage.setScene(fxScene);
      
          // 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.
          String yourApiKey = "YOUR_API_KEY";
          ArcGISRuntimeEnvironment.setApiKey(yourApiKey);
      
          // create a scene view to display the scene and add it to the stack pane
          sceneView = new SceneView();
          stackPane.getChildren().add(sceneView);
      
          ArcGISScene scene = new ArcGISScene(Basemap.createImagery());
      
          // set the scene on the scene view
          sceneView.setArcGISScene(scene);
      
          // add base surface for elevation data
          Surface surface = new Surface();
          String elevationServiceUrl = "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer";
          surface.getElevationSources().add(new ArcGISTiledElevationSource(elevationServiceUrl));
          // add an exaggeration factor to increase the 3D effect of the elevation.
          surface.setElevationExaggeration(2.5f);
      
          scene.setBaseSurface(surface);
      
          Point cameraLocation = new Point(-118.794, 33.909, 5330.0, SpatialReferences.getWgs84());
          Camera camera = new Camera(cameraLocation, 355.0, 72.0, 0.0);
          sceneView.setViewpointCamera(camera);
      
        }
      
        /**
         * Stops and releases all resources used in application.
         */
        @Override
        public void stop() {
          if (sceneView != null) {
            sceneView.dispose();
          }
        }
      
      }
      
  2. Add the sceneView to the UI.

    App.java
    Add line.Add line.Add line.
    48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 49 50 51 52 53 54 54 54 54 54 54 55 56 57 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 39 39 38 37 36 35 34 33 32 31 30 29 29
    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
    
    //   Copyright 2020 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.
    
    package com.example.app;
    
    import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
    import com.esri.arcgisruntime.geometry.Point;
    import com.esri.arcgisruntime.geometry.SpatialReferences;
    import com.esri.arcgisruntime.mapping.ArcGISScene;
    import com.esri.arcgisruntime.mapping.ArcGISTiledElevationSource;
    import com.esri.arcgisruntime.mapping.Basemap;
    import com.esri.arcgisruntime.mapping.Surface;
    import com.esri.arcgisruntime.mapping.view.Camera;
    import com.esri.arcgisruntime.mapping.view.SceneView;
    
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    
    public class App extends Application {
    
      private SceneView sceneView;
    
      public static void main(String[] args) {
        Application.launch(args);
      }
    
      @Override
      public void start(Stage stage) {
    
        // set the title and size of the stage and show it
        stage.setTitle("Display a scene tutorial");
        stage.setWidth(800);
        stage.setHeight(700);
        stage.show();
    
        // create a JavaFX scene with a stack pane as the root node, and add it to the scene
        StackPane stackPane = new StackPane();
        Scene fxScene = new Scene(stackPane);
    
        stage.setScene(fxScene);
    
        // 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.
        String yourApiKey = "YOUR_API_KEY";
        ArcGISRuntimeEnvironment.setApiKey(yourApiKey);
    
        // create a scene view to display the scene and add it to the stack pane
        sceneView = new SceneView();
        stackPane.getChildren().add(sceneView);
    
        ArcGISScene scene = new ArcGISScene(Basemap.createImagery());
    
        // set the scene on the scene view
        sceneView.setArcGISScene(scene);
    
        // add base surface for elevation data
        Surface surface = new Surface();
        String elevationServiceUrl = "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer";
        surface.getElevationSources().add(new ArcGISTiledElevationSource(elevationServiceUrl));
        // add an exaggeration factor to increase the 3D effect of the elevation.
        surface.setElevationExaggeration(2.5f);
    
        scene.setBaseSurface(surface);
    
        Point cameraLocation = new Point(-118.794, 33.909, 5330.0, SpatialReferences.getWgs84());
        Camera camera = new Camera(cameraLocation, 355.0, 72.0, 0.0);
        sceneView.setViewpointCamera(camera);
    
      }
    
      /**
       * Stops and releases all resources used in application.
       */
      @Override
      public void stop() {
        if (sceneView != null) {
          sceneView.dispose();
        }
      }
    
    }
    

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.

  1. Create a new ArcGISScene with an imagery basemap.

    App.java
    Add line.
    59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 58 57 56 55 54 55 56 57 58 59 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 59 59 59 58 57 56 55 54 53 52 51 50 49 49
    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
    
    //   Copyright 2020 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.
    
    package com.example.app;
    
    import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
    import com.esri.arcgisruntime.geometry.Point;
    import com.esri.arcgisruntime.geometry.SpatialReferences;
    import com.esri.arcgisruntime.mapping.ArcGISScene;
    import com.esri.arcgisruntime.mapping.ArcGISTiledElevationSource;
    import com.esri.arcgisruntime.mapping.Basemap;
    import com.esri.arcgisruntime.mapping.Surface;
    import com.esri.arcgisruntime.mapping.view.Camera;
    import com.esri.arcgisruntime.mapping.view.SceneView;
    
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    
    public class App extends Application {
    
      private SceneView sceneView;
    
      public static void main(String[] args) {
        Application.launch(args);
      }
    
      @Override
      public void start(Stage stage) {
    
        // set the title and size of the stage and show it
        stage.setTitle("Display a scene tutorial");
        stage.setWidth(800);
        stage.setHeight(700);
        stage.show();
    
        // create a JavaFX scene with a stack pane as the root node, and add it to the scene
        StackPane stackPane = new StackPane();
        Scene fxScene = new Scene(stackPane);
    
        stage.setScene(fxScene);
    
        // 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.
        String yourApiKey = "YOUR_API_KEY";
        ArcGISRuntimeEnvironment.setApiKey(yourApiKey);
    
        // create a scene view to display the scene and add it to the stack pane
        sceneView = new SceneView();
        stackPane.getChildren().add(sceneView);
    
        ArcGISScene scene = new ArcGISScene(Basemap.createImagery());
    
        // set the scene on the scene view
        sceneView.setArcGISScene(scene);
    
        // add base surface for elevation data
        Surface surface = new Surface();
        String elevationServiceUrl = "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer";
        surface.getElevationSources().add(new ArcGISTiledElevationSource(elevationServiceUrl));
        // add an exaggeration factor to increase the 3D effect of the elevation.
        surface.setElevationExaggeration(2.5f);
    
        scene.setBaseSurface(surface);
    
        Point cameraLocation = new Point(-118.794, 33.909, 5330.0, SpatialReferences.getWgs84());
        Camera camera = new Camera(cameraLocation, 355.0, 72.0, 0.0);
        sceneView.setViewpointCamera(camera);
    
      }
    
      /**
       * Stops and releases all resources used in application.
       */
      @Override
      public void stop() {
        if (sceneView != null) {
          sceneView.dispose();
        }
      }
    
    }
    
  2. To display the scene in the scene view, call the sceneView's setArcGISScene() method, passing the newly created ArcGISScene as a parameter.

    App.java
    Add line.Add line.
    63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 62 61 60 59 58 58 58 58 58 59 60 61 62 63 63 63 63 63 63 63 63 63 63 63 63 63 62 62 62 61 60 59 58 57 56 55 54 53 52 52
    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
    
    //   Copyright 2020 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.
    
    package com.example.app;
    
    import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
    import com.esri.arcgisruntime.geometry.Point;
    import com.esri.arcgisruntime.geometry.SpatialReferences;
    import com.esri.arcgisruntime.mapping.ArcGISScene;
    import com.esri.arcgisruntime.mapping.ArcGISTiledElevationSource;
    import com.esri.arcgisruntime.mapping.Basemap;
    import com.esri.arcgisruntime.mapping.Surface;
    import com.esri.arcgisruntime.mapping.view.Camera;
    import com.esri.arcgisruntime.mapping.view.SceneView;
    
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    
    public class App extends Application {
    
      private SceneView sceneView;
    
      public static void main(String[] args) {
        Application.launch(args);
      }
    
      @Override
      public void start(Stage stage) {
    
        // set the title and size of the stage and show it
        stage.setTitle("Display a scene tutorial");
        stage.setWidth(800);
        stage.setHeight(700);
        stage.show();
    
        // create a JavaFX scene with a stack pane as the root node, and add it to the scene
        StackPane stackPane = new StackPane();
        Scene fxScene = new Scene(stackPane);
    
        stage.setScene(fxScene);
    
        // 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.
        String yourApiKey = "YOUR_API_KEY";
        ArcGISRuntimeEnvironment.setApiKey(yourApiKey);
    
        // create a scene view to display the scene and add it to the stack pane
        sceneView = new SceneView();
        stackPane.getChildren().add(sceneView);
    
        ArcGISScene scene = new ArcGISScene(Basemap.createImagery());
    
        // set the scene on the scene view
        sceneView.setArcGISScene(scene);
    
        // add base surface for elevation data
        Surface surface = new Surface();
        String elevationServiceUrl = "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer";
        surface.getElevationSources().add(new ArcGISTiledElevationSource(elevationServiceUrl));
        // add an exaggeration factor to increase the 3D effect of the elevation.
        surface.setElevationExaggeration(2.5f);
    
        scene.setBaseSurface(surface);
    
        Point cameraLocation = new Point(-118.794, 33.909, 5330.0, SpatialReferences.getWgs84());
        Camera camera = new Camera(cameraLocation, 355.0, 72.0, 0.0);
        sceneView.setViewpointCamera(camera);
    
      }
    
      /**
       * Stops and releases all resources used in application.
       */
      @Override
      public void stop() {
        if (sceneView != null) {
          sceneView.dispose();
        }
      }
    
    }
    
  3. Create a new Surface and add a new ArcGISTiledElevationSource to it to define the base surface for the scene. Set the newly created surface as the base surface of the 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.

    App.java
    Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.
    65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 64 63 62 61 60 60 60 60 60 60 60 61 62 63 64 65 66 67 68 69 70 71 71 70 69 68 67 67 67 66 65 64 63 62 61 60 59 58 57 57
    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
    
    //   Copyright 2020 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.
    
    package com.example.app;
    
    import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
    import com.esri.arcgisruntime.geometry.Point;
    import com.esri.arcgisruntime.geometry.SpatialReferences;
    import com.esri.arcgisruntime.mapping.ArcGISScene;
    import com.esri.arcgisruntime.mapping.ArcGISTiledElevationSource;
    import com.esri.arcgisruntime.mapping.Basemap;
    import com.esri.arcgisruntime.mapping.Surface;
    import com.esri.arcgisruntime.mapping.view.Camera;
    import com.esri.arcgisruntime.mapping.view.SceneView;
    
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    
    public class App extends Application {
    
      private SceneView sceneView;
    
      public static void main(String[] args) {
        Application.launch(args);
      }
    
      @Override
      public void start(Stage stage) {
    
        // set the title and size of the stage and show it
        stage.setTitle("Display a scene tutorial");
        stage.setWidth(800);
        stage.setHeight(700);
        stage.show();
    
        // create a JavaFX scene with a stack pane as the root node, and add it to the scene
        StackPane stackPane = new StackPane();
        Scene fxScene = new Scene(stackPane);
    
        stage.setScene(fxScene);
    
        // 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.
        String yourApiKey = "YOUR_API_KEY";
        ArcGISRuntimeEnvironment.setApiKey(yourApiKey);
    
        // create a scene view to display the scene and add it to the stack pane
        sceneView = new SceneView();
        stackPane.getChildren().add(sceneView);
    
        ArcGISScene scene = new ArcGISScene(Basemap.createImagery());
    
        // set the scene on the scene view
        sceneView.setArcGISScene(scene);
    
        // add base surface for elevation data
        Surface surface = new Surface();
        String elevationServiceUrl = "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer";
        surface.getElevationSources().add(new ArcGISTiledElevationSource(elevationServiceUrl));
        // add an exaggeration factor to increase the 3D effect of the elevation.
        surface.setElevationExaggeration(2.5f);
    
        scene.setBaseSurface(surface);
    
        Point cameraLocation = new Point(-118.794, 33.909, 5330.0, SpatialReferences.getWgs84());
        Camera camera = new Camera(cameraLocation, 355.0, 72.0, 0.0);
        sceneView.setViewpointCamera(camera);
    
      }
    
      /**
       * Stops and releases all resources used in application.
       */
      @Override
      public void stop() {
        if (sceneView != null) {
          sceneView.dispose();
        }
      }
    
    }
    
  4. Set the initial viewpoint of the sceneView using a Point and a Camera.

    The position you view the scene from is defined by a Camera. 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
    App.java
    Add line.Add line.Add line.
    75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 74 73 72 71 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 71 72 73 74 75 75 75 75 74 73 72 71 70 69 68 67 66 65 65
    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
    
    //   Copyright 2020 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.
    
    package com.example.app;
    
    import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
    import com.esri.arcgisruntime.geometry.Point;
    import com.esri.arcgisruntime.geometry.SpatialReferences;
    import com.esri.arcgisruntime.mapping.ArcGISScene;
    import com.esri.arcgisruntime.mapping.ArcGISTiledElevationSource;
    import com.esri.arcgisruntime.mapping.Basemap;
    import com.esri.arcgisruntime.mapping.Surface;
    import com.esri.arcgisruntime.mapping.view.Camera;
    import com.esri.arcgisruntime.mapping.view.SceneView;
    
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    
    public class App extends Application {
    
      private SceneView sceneView;
    
      public static void main(String[] args) {
        Application.launch(args);
      }
    
      @Override
      public void start(Stage stage) {
    
        // set the title and size of the stage and show it
        stage.setTitle("Display a scene tutorial");
        stage.setWidth(800);
        stage.setHeight(700);
        stage.show();
    
        // create a JavaFX scene with a stack pane as the root node, and add it to the scene
        StackPane stackPane = new StackPane();
        Scene fxScene = new Scene(stackPane);
    
        stage.setScene(fxScene);
    
        // 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.
        String yourApiKey = "YOUR_API_KEY";
        ArcGISRuntimeEnvironment.setApiKey(yourApiKey);
    
        // create a scene view to display the scene and add it to the stack pane
        sceneView = new SceneView();
        stackPane.getChildren().add(sceneView);
    
        ArcGISScene scene = new ArcGISScene(Basemap.createImagery());
    
        // set the scene on the scene view
        sceneView.setArcGISScene(scene);
    
        // add base surface for elevation data
        Surface surface = new Surface();
        String elevationServiceUrl = "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer";
        surface.getElevationSources().add(new ArcGISTiledElevationSource(elevationServiceUrl));
        // add an exaggeration factor to increase the 3D effect of the elevation.
        surface.setElevationExaggeration(2.5f);
    
        scene.setBaseSurface(surface);
    
        Point cameraLocation = new Point(-118.794, 33.909, 5330.0, SpatialReferences.getWgs84());
        Camera camera = new Camera(cameraLocation, 355.0, 72.0, 0.0);
        sceneView.setViewpointCamera(camera);
    
      }
    
      /**
       * Stops and releases all resources used in application.
       */
      @Override
      public void stop() {
        if (sceneView != null) {
          sceneView.dispose();
        }
      }
    
    }
    

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.

  1. Before running the ArcGIS Java API code, set the API key property on the ArcGISRuntimeEnvironment with your API key.

    App.java
    Add line.Add line.Add line.Add line.
    52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 53 54 55 56 57 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58
    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
    
    //   Copyright 2020 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.
    
    package com.example.app;
    
    import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
    import com.esri.arcgisruntime.geometry.Point;
    import com.esri.arcgisruntime.geometry.SpatialReferences;
    import com.esri.arcgisruntime.mapping.ArcGISScene;
    import com.esri.arcgisruntime.mapping.ArcGISTiledElevationSource;
    import com.esri.arcgisruntime.mapping.Basemap;
    import com.esri.arcgisruntime.mapping.Surface;
    import com.esri.arcgisruntime.mapping.view.Camera;
    import com.esri.arcgisruntime.mapping.view.SceneView;
    
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    
    public class App extends Application {
    
      private SceneView sceneView;
    
      public static void main(String[] args) {
        Application.launch(args);
      }
    
      @Override
      public void start(Stage stage) {
    
        // set the title and size of the stage and show it
        stage.setTitle("Display a scene tutorial");
        stage.setWidth(800);
        stage.setHeight(700);
        stage.show();
    
        // create a JavaFX scene with a stack pane as the root node, and add it to the scene
        StackPane stackPane = new StackPane();
        Scene fxScene = new Scene(stackPane);
    
        stage.setScene(fxScene);
    
        // 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.
        String yourApiKey = "YOUR_API_KEY";
        ArcGISRuntimeEnvironment.setApiKey(yourApiKey);
    
        // create a scene view to display the scene and add it to the stack pane
        sceneView = new SceneView();
        stackPane.getChildren().add(sceneView);
    
        ArcGISScene scene = new ArcGISScene(Basemap.createImagery());
    
        // set the scene on the scene view
        sceneView.setArcGISScene(scene);
    
        // add base surface for elevation data
        Surface surface = new Surface();
        String elevationServiceUrl = "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer";
        surface.getElevationSources().add(new ArcGISTiledElevationSource(elevationServiceUrl));
        // add an exaggeration factor to increase the 3D effect of the elevation.
        surface.setElevationExaggeration(2.5f);
    
        scene.setBaseSurface(surface);
    
        Point cameraLocation = new Point(-118.794, 33.909, 5330.0, SpatialReferences.getWgs84());
        Camera camera = new Camera(cameraLocation, 355.0, 72.0, 0.0);
        sceneView.setViewpointCamera(camera);
    
      }
    
      /**
       * Stops and releases all resources used in application.
       */
      @Override
      public void stop() {
        if (sceneView != null) {
          sceneView.dispose();
        }
      }
    
    }
    
  2. Run the app.

    Ensure to run the app as a Gradle task and not as an application in your IDE. In the Gradle tool window, under Tasks > application, click run.

You should see a scene with the imagery basemap layer centered on the Santa Monica Mountains in California. Click, drag, and scroll the mouse wheel on the scene view to explore the scene.

Stop the app

To ensure that ArcGIS Runtime API resources used in the application are released when it is closed, override the JavaFX stop method and call dispose() on the sceneView:

App.java
Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.
83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 84 85 86 87 88 89 90 91 92 92 92
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

//   Copyright 2020 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.

package com.example.app;

import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.geometry.SpatialReferences;
import com.esri.arcgisruntime.mapping.ArcGISScene;
import com.esri.arcgisruntime.mapping.ArcGISTiledElevationSource;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.Surface;
import com.esri.arcgisruntime.mapping.view.Camera;
import com.esri.arcgisruntime.mapping.view.SceneView;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class App extends Application {

  private SceneView sceneView;

  public static void main(String[] args) {
    Application.launch(args);
  }

  @Override
  public void start(Stage stage) {

    // set the title and size of the stage and show it
    stage.setTitle("Display a scene tutorial");
    stage.setWidth(800);
    stage.setHeight(700);
    stage.show();

    // create a JavaFX scene with a stack pane as the root node, and add it to the scene
    StackPane stackPane = new StackPane();
    Scene fxScene = new Scene(stackPane);

    stage.setScene(fxScene);

    // 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.
    String yourApiKey = "YOUR_API_KEY";
    ArcGISRuntimeEnvironment.setApiKey(yourApiKey);

    // create a scene view to display the scene and add it to the stack pane
    sceneView = new SceneView();
    stackPane.getChildren().add(sceneView);

    ArcGISScene scene = new ArcGISScene(Basemap.createImagery());

    // set the scene on the scene view
    sceneView.setArcGISScene(scene);

    // add base surface for elevation data
    Surface surface = new Surface();
    String elevationServiceUrl = "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer";
    surface.getElevationSources().add(new ArcGISTiledElevationSource(elevationServiceUrl));
    // add an exaggeration factor to increase the 3D effect of the elevation.
    surface.setElevationExaggeration(2.5f);

    scene.setBaseSurface(surface);

    Point cameraLocation = new Point(-118.794, 33.909, 5330.0, SpatialReferences.getWgs84());
    Camera camera = new Camera(cameraLocation, 355.0, 72.0, 0.0);
    sceneView.setViewpointCamera(camera);

  }

  /**
   * Stops and releases all resources used in application.
   */
  @Override
  public void stop() {
    if (sceneView != null) {
      sceneView.dispose();
    }
  }

}

What's next?

Learn how to use additional API features, ArcGIS platform 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.