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.
Mapping and location services guideFor more background information about the topics in this tutorial, visit Scenes (3D) and Basemaps.
PrerequisitesBefore starting this tutorial:
You need an ArcGIS Location Platform or ArcGIS Online account.
Confirm that your system meets the minimum system requirements.
An IDE for Java.
This tutorial uses IntelliJ IDEA, but the code described will work within any supported Java IDE.
Steps Create a new Java project with GradleOpen IntelliJ IDEA.
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 Gradle as your build system
If you wish to use an alternative to Gradle, see Install and Set Up for options.
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.
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.
build.gradle
Use dark colors for code blocks Copy
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
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.
In App.java, add import statements to reference the ArcGIS and JavaFX classes.
App.java
Use dark colors for code blocks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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 {
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.
In App.java, define a class named App
that extends the JavaFX Application
class.
Add a private member variable for a SceneView
.
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
.
App.java
Expand
Use dark colors for code blocks31 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 55 56 56 56 56 56 56 56 56 56 56 56 57
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.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
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
Expand
Use dark colors for code blocks48 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 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
Add line. Add line. Add line.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// 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);
Use the scene view to display a scene centered on the Santa Monica Mountains in California. The scene will contain an imagery basemap layer.
Create a new ArcGISScene
with an imagery basemap.
App.java
Expand
Use dark colors for code blocks56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 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
Add line.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// 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);
To display the scene in the scene view, call the sceneView
's setArcGISScene()
method, passing the newly created ArcGISScene
as a parameter.
App.java
Expand
Use dark colors for code blocks60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 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
Add line. Add line.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
ArcGISScene scene = new ArcGISScene(BasemapStyle.ARCGIS_IMAGERY_STANDARD);
// set the scene on the scene view
sceneView.setArcGISScene(scene);
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.
App.java
Expand
Use dark colors for code blocks62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 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
Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// 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);
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:
App.java
Expand
Use dark colors for code blocks72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 72 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
Add line. Add line. Add line.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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);
You need an access token to use the location services used in this tutorial.
Go to the Create an API key tutorial to obtain an access token using your ArcGIS Location Platform or ArcGIS Online account.
Ensure that the following privilege is enabled: Location services > Basemaps > Basemap styles service.
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 keySet 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.
Be sure to set the API Key before the mapping code, since the map needs the key to access the basemap.
App.java
Expand
Use dark colors for code blocks52 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 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 54 53 52 51 50 49 48 47 46 45 45
Add line.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
stage.setScene(fxScene);
ArcGISRuntimeEnvironment.setApiKey("YOUR_ACCESS_TOKEN");
Warning
The access token is stored directly in the code as a convenience for this tutorial. Storing access tokens in the source code is not best practice.
Release API resourcesTo 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
Expand
Use dark colors for code blocks80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 81 82 83 84 85 86 87 88 89 89 89
Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* Stops and releases all resources used in application.
*/
@Override
public void stop() {
if (sceneView != null) {
sceneView.dispose();
}
}
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
.
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 three required packages this application depends on: com.esri.arcgisruntime
, javafx.graphics
, and org.slf4j.nop
.
Export this project's module package to make it accessible to code in all other modules.
module-info.java
Expand
Use dark colors for code blocks13 13 13 13 13 13 13 13 13 13 13 13 13 14 15 16 17 18 19 20 21 22 23 24 25
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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 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.
What's next?Learn how to use additional API features, ArcGIS location services, and ArcGIS tools in these tutorials:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4