Learn how to create and display a scene with a basemap layer and an elevation layer. Set properties of the scene's camera to control the 3D perspective.
Like a map, a scene contains layers of geographic data. It contains a basemap layer and, optionally, one or more data layers. To provide a realistic view of the terrain, you can also add elevation layers to define the height of the surface across the scene. The 3D perspective of the scene is controlled by the scene's camera, which defines the position of the scene observer in 3D space.
In this tutorial, you create and display a scene using the imagery basemap layer. The surface of the scene is defined with an elevation layer and the camera is positioned to display an area of the Santa Monica Mountains in the scene view.
The scene and code will be used as the starting point for other 3D tutorials.
Prerequisites
The following are required for this tutorial:
An ArcGIS account to access your API keys. If you don't have an account, sign up for free.
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.)
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 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. In GroupId enter com.example.app. You can leave the default for ArtifactId.
Click Create to build your new project.
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.
To load the Gradle changes, in the Gradle window, click the Reload All Gradle Projects icon in the upper left corner.
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.
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
In App.java, add import statements to reference the ArcGIS and JavaFX classes.
The sceneView member variable allows you to easily reference your SceneView from other parts of the application.
Inside the main() method, replace the print statement with a call to Application.launch(args).
This code calls the static method launch() of the JavaFX class Application, which creates an instance of your App class on the JavaFX Application Thread and then calls the start() method. For a description of the JavaFX life-cycle, see Application.
Override the start() method, in which you configure the JavaFX Stage with a title and dimensions, and then show it.
Note that the start() method is abstract in the JavaFX Application class and must be overridden in your application code. The start() method takes a single parameter of the JavaFX type Stage.
Create a JavaFX StackPane, and use it to create a JavaFX Scene. Then set the scene on the stage.
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.
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.
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 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);
Expand
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:
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
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
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);
Expand
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:
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.
In the Project tool window, under src/main, right-click the java folder, and click New > module-info.java.
Inside module-info.java replace the module name (i.e. highlighted text) with com.example.app.
In the body of the module descriptor, define the two required packages this application depends on: com.esri.arcgisruntime and javafx.graphics.
Export this project's module package to make it accessible to code in all other modules.
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 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.