Learn how to create and display a sceneA scene is a collection of layers that are displayed in 3D. It is typically composed of a basemap layer, data layers, and 3D data. Learn more with a basemap layerA basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more and an elevation layerAn elevation layer is a layer that defines the ground height or the surface for a scene. Learn more . Set properties of the scene’s cameraA camera defines the rendering viewpoint of a 3D scene in a scene view. Learn more to control the 3D perspective.

Laptop displaying a 3D view of coastal terrain.

Like a mapA map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more , a sceneA scene is a collection of layers that are displayed in 3D. It is typically composed of a basemap layer, data layers, and 3D data. Learn more contains layersA layer is a reference to a collection of geographic data that is used to access and display data. The data for layers are typically provided by the basemap layer service and data services. Learn more of geographic data. It contains a basemap layerA basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more and, optionally, one or more data layersA data layer is a layer that references geographic data from a file or a service and is used to visualize the data in a map or scene. Learn more . To provide a realistic view of the terrain, you can also add elevation layersAn elevation layer is a layer that defines the ground height or the surface for a scene. Learn more to define the height of the surface across the scene. The 3D perspective of the scene is controlled by the scene’s cameraA camera defines the rendering viewpoint of a 3D scene in a scene view. Learn more , which defines the position of the scene observer in 3D space.

In this tutorial, you create and display a sceneA scene is a collection of layers that are displayed in 3D. It is typically composed of a basemap layer, data layers, and 3D data. Learn more using the imagery basemap layerA basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more . The surface of the scene is defined with an elevation layerAn elevation layer is a layer that defines the ground height or the surface for a scene. Learn more and the cameraA camera defines the rendering viewpoint of a 3D scene in a scene view. Learn more is positioned to display an area of the Santa Monica Mountains in the scene viewA scene view is a user interface that displays scene layers and graphics in 3D. It uses a camera to control the visible area of the scene and supports user interactions such as pan, zoom, tilt, and rotate. Learn more .

The scene and code will be used as the starting point for other 3D tutorials.

Prerequisites

Before starting this tutorial:

  1. You need an ArcGIS Location Platform or ArcGIS Online account.

  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.

  2. From the Welcome to IntelliJ IDEA screen, click the New Project button. (If you’re already inside a project, click File > New > Project in the menu bar.)

  3. In the New Project window, do the following:

    • Enter a name for your new project and choose a location to save it. Your app name can contain only Latin characters, digits, _ , - and :.

    • Deselect Create Git repository, if necessary

    • Select Java as your programming language, if necessary

    • Select Gradle as your build system

    • Select a supported JDK

    • Select Groovy as your Gradle build language (i.e. DSL), if necessary

    • Check the Add sample code box, if necessary

    • Click Advanced Settings to expand the drop-down. Set the Gradle distribution to Wrapper and check the Auto-select box for the Gradle version. Optionally, you can enable or disable the ability to use these settings for future projects. For GroupId enter com.example.app. You can leave the default for ArtifactId.

    • Click Create to build your new project.

  4. In the Project tool window, replace the contents of the build.gradle file with the following script to configure your app and reference the API. Make sure that you load the gradle changes after modifying build.gradle.

    build.gradle
    plugins {
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.1.0'
    id 'idea'
    }
    idea {
    module {
    downloadJavadoc = true
    }
    }
    ext {
    arcgisVersion = '200.6.0'
    }
    repositories {
    mavenCentral()
    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"
    implementation 'org.slf4j:slf4j-nop:2.0.16'
    }
    javafx {
    version = "21.0.5"
    modules = [ 'javafx.controls', 'javafx.graphics', 'javafx.fxml', 'javafx.web', 'javafx.media' ]
    }
    application {
    mainModule = "com.example.app"
    mainClass = "com.example.app.App"
    }
    task copyNatives(type: Copy) {
    description = "Copies the arcgis native libraries into the .arcgis directory for development."
    group = "build"
    configurations.natives.asFileTree.each {
    from(zipTree(it))
    }
    into "${System.properties.getProperty("user.home")}/.arcgis/$arcgisVersion"
    }
    run {
    dependsOn copyNatives
    }
    wrapper {
    gradleVersion = '8.10.2'
    }
    • 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.

    • In the Project tool window, under your package com.example.app, right-click Main and click Refactor > Rename….

    • Rename the Java class to App and click Refactor.

    Add import statements

    1. In App.java, add import statements to reference the ArcGIS and JavaFX classes.

      App.java
      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.BasemapStyle;
      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 {

      Add a UI for the scene view

      A scene viewA scene view is a user interface that displays scene layers and graphics in 3D. It uses a camera to control the visible area of the scene and supports user interactions such as pan, zoom, tilt, and rotate. Learn more is a UI component that displays a sceneA scene is a collection of layers that are displayed in 3D. It is typically composed of a basemap layer, data layers, and 3D data. Learn more . It also handles user interactions with the scene. Use JavaFX to add a scene view to the UI.

      1. In App.java, define a class named App that extends the JavaFX Application class.

        • Add a private member variable for a SceneView.

        • Inside the main() method, replace the print statement with a call to Application.launch(args).

        • Override the start() method, in which you configure the JavaFX Stage with a title and dimensions, and then show it.

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

        App.java
        30 collapsed lines
        // Copyright 2021 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.BasemapStyle;
        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);
        }
        }
        • Initialize your member variable, sceneView, and add it to the JavaFX UI.

          App.java
          47 collapsed lines
          // Copyright 2021 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.BasemapStyle;
          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);
          // create a scene view to display the scene and add it to the stack pane
          sceneView = new SceneView();
          stackPane.getChildren().add(sceneView);
          4 collapsed lines
          }
          }

          Add a scene

          Use the scene viewA scene view is a user interface that displays scene layers and graphics in 3D. It uses a camera to control the visible area of the scene and supports user interactions such as pan, zoom, tilt, and rotate. Learn more to display a sceneA scene is a collection of layers that are displayed in 3D. It is typically composed of a basemap layer, data layers, and 3D data. Learn more centered on the Santa Monica Mountains in California. The scene will contain an imagery basemap layerA basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more .

          1. Create a new ArcGISScene with an imagery basemap.

            App.java
            53 collapsed lines
            // Copyright 2021 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.BasemapStyle;
            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);
            // 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(BasemapStyle.ARCGIS_IMAGERY_STANDARD);
            3 collapsed lines
            }
            }
            • To display the scene in the scene view, call the sceneView’s setArcGISScene() method, passing the newly created ArcGISScene as a parameter.

              App.java
              57 collapsed lines
              // Copyright 2021 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.BasemapStyle;
              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);
              // 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(BasemapStyle.ARCGIS_IMAGERY_STANDARD);
              // set the scene on the scene view
              sceneView.setArcGISScene(scene);
              3 collapsed lines
              }
              }
              • Create a new Surface and add a new ArcGISTiledElevationSource to it to define the base surface for the scene. Next, set the setElevationExaggeration property on the surface to 2.5f to increase the 3D effect of the elevation. Finally, set the surface as the base surface of the scene.

                App.java
                59 collapsed lines
                // Copyright 2021 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.BasemapStyle;
                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);
                // 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(BasemapStyle.ARCGIS_IMAGERY_STANDARD);
                // 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);
                4 collapsed lines
                }
                }
                • Set the initial viewpoint of the sceneView using a Point and a Camera.

                  App.java
                  69 collapsed lines
                  // Copyright 2021 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.BasemapStyle;
                  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);
                  // 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(BasemapStyle.ARCGIS_IMAGERY_STANDARD);
                  // 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);
                  4 collapsed lines
                  }
                  }

                  Get an access token

                  You need an access tokenAn access token is an authorization string that provides access to secure ArcGIS content, data, and services. Its capabilities are determined by the privileges it supports. It is obtained by implementing API key authentication, User authentication, or App authentication. Learn more to use the location servicesArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Static Maps service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. Learn more used in this tutorial.

                  1. Go to the Create an API key tutorial to obtain an access tokenAn access token is an authorization string that provides access to secure ArcGIS content, data, and services. Its capabilities are determined by the privileges it supports. It is obtained by implementing API key authentication, User authentication, or App authentication. Learn more using your ArcGIS Location PlatformAn ArcGIS Location Platform account, formerly known as an ArcGIS Developer account, is an identity associated with an ArcGIS Location Platform subscription. Learn more or ArcGIS OnlineAn ArcGIS Online account, also known as an ArcGIS Organization account, is an identity associated with an ArcGIS Online subscription. It can be used to access ArcGIS tools and develop applications with ArcGIS location services for an organization. Learn more account.

                  2. Ensure that the following privilegePrivileges are a set of permissions assigned to ArcGIS accounts, developer credentials, and applications that grant access to secure resources and functionality in ArcGIS. Learn more is enabled: Location services > Basemaps > Basemap styles service.

                  3. Copy the access token as it will be used in the next step.

                  To learn more about other ways to get an access token, go to Types of authentication.

                  Set your API key

                  Set the API key property on the ArcGISRuntimeEnvironment. In the code below, replace YOUR_ACCESS_TOKEN with your copied access token. Be sure to surround your access token with double quotes as it is a string.

                  App.java
                  51 collapsed lines
                  // Copyright 2021 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.BasemapStyle;
                  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);
                  ArcGISRuntimeEnvironment.setApiKey("YOUR_ACCESS_TOKEN");
                  26 collapsed lines
                  // 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(BasemapStyle.ARCGIS_IMAGERY_STANDARD);
                  // 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);
                  }
                  }

                    Release API resources

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

                    App.java
                    79 collapsed lines
                    // Copyright 2021 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.BasemapStyle;
                    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);
                    ArcGISRuntimeEnvironment.setApiKey("YOUR_ACCESS_TOKEN");
                    // 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(BasemapStyle.ARCGIS_IMAGERY_STANDARD);
                    // 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 collapsed lines
                    }

                      Modularize the app

                      A Java module adds a higher level of aggregation above packages. A module must provide a module descriptor that specifies the dependencies, the packages the module makes available to other modules, and more.

                      You will create the module descriptor for this project in a file named module-info.java.

                      1. In the Project tool window, under src/main, right-click the java folder, and click New > module-info.java.

                      2. Inside module-info.java replace the module name (i.e. highlighted text) with com.example.app.

                      3. In the body of the module descriptor, define the three required packages this application depends on: com.esri.arcgisruntime, javafx.graphics, and org.slf4j.nop.

                      4. Export this project’s module package to make it accessible to code in all other modules.

                      module-info.java
                      13 collapsed lines
                      /*
                      COPYRIGHT 1995-2022 ESRI
                      TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
                      Unpublished material - all rights reserved under the
                      Copyright Laws of the United States.
                      For additional information, contact:
                      Environmental Systems Research Institute, Inc.
                      Attn: Contracts Dept
                      380 New York Street
                      Redlands, California, USA 92373
                      email: contracts@esri.com
                      */
                      module com.example.app {
                      // require ArcGIS Runtime module
                      requires com.esri.arcgisruntime;
                      // requires JavaFX modules that the application uses
                      requires javafx.graphics;
                      // requires SLF4j module
                      requires org.slf4j.nop;
                      exports com.example.app;
                      }

                        Run the app

                        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, double-click run.

                        You should see a sceneA scene is a collection of layers that are displayed in 3D. It is typically composed of a basemap layer, data layers, and 3D data. Learn more with the imagery basemap layerA basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more centered on the Santa Monica Mountains in California. Click, drag, and scroll the mouse wheel 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: