You can select features to visually distinguish them with a selection color or highlighting. This can be useful to demonstrate the physical extent or associated attributes of a feature, or to initiate another action such as centering that feature in the scene view.
How to use the sample
Click a building in the scene layer to select it. Deselect buildings by clicking away from the buildings.
How it works
Create an ArcGISSceneLayer passing in the URL to a scene layer service.
Use sceneView.setOnMouseClicked to get the screen click location Point2D.
Call sceneView.identifyLayersAsync(sceneLayer, point2D, tolerance, false, 1) to identify features in the scene.
From the resulting IdentifyLayerResult, get the list of identified GeoElements with result.getElements().
Get the first element in the list, checking that it is a feature, and call sceneLayer.selectFeature(feature) to select it.
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Copyright 2018 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.esri.samples.scene_layer_selection;
import java.util.List;
import java.util.concurrent.ExecutionException;
import javafx.application.Application;
import javafx.geometry.Point2D;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
import com.esri.arcgisruntime.concurrent.ListenableFuture;
import com.esri.arcgisruntime.data.Feature;
import com.esri.arcgisruntime.layers.ArcGISSceneLayer;
import com.esri.arcgisruntime.loadable.LoadStatus;
import com.esri.arcgisruntime.mapping.ArcGISScene;
import com.esri.arcgisruntime.mapping.ArcGISTiledElevationSource;
import com.esri.arcgisruntime.mapping.BasemapStyle;
import com.esri.arcgisruntime.mapping.GeoElement;
import com.esri.arcgisruntime.mapping.Surface;
import com.esri.arcgisruntime.mapping.view.Camera;
import com.esri.arcgisruntime.mapping.view.IdentifyLayerResult;
import com.esri.arcgisruntime.mapping.view.SceneView;
publicclassSceneLayerSelectionSampleextendsApplication{
private SceneView sceneView;
@Overridepublicvoidstart(Stage stage){
try {
// create stack pane and JavaFX app scene StackPane stackPane = new StackPane();
Scene fxScene = new Scene(stackPane);
// set title, size, and add JavaFX scene to stage stage.setTitle("Scene Layer Selection Sample");
stage.setWidth(800);
stage.setHeight(700);
stage.setScene(fxScene);
stage.show();
// authentication with an API key or named user is required to access basemaps and other location services String yourAPIKey = System.getProperty("apiKey");
ArcGISRuntimeEnvironment.setApiKey(yourAPIKey);
// create a scene with a basemap style ArcGISScene scene = new ArcGISScene(BasemapStyle.ARCGIS_TOPOGRAPHIC);
// set the scene to the scene view sceneView = new SceneView();
sceneView.setArcGISScene(scene);
// set the initial viewpoint Camera camera = new Camera(48.378, -4.494, 200, 345, 65, 0);
sceneView.setViewpointCamera(camera);
// add the scene view to the stack pane stackPane.getChildren().add(sceneView);
// add base surface with elevation data Surface surface = new Surface();
final String elevationService = "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer";
surface.getElevationSources().add(new ArcGISTiledElevationSource(elevationService));
scene.setBaseSurface(surface);
// add a scene layer of buildings in Brest, Francefinal String buildings = "http://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/Buildings_Brest/SceneServer/layers/0";
ArcGISSceneLayer sceneLayer = new ArcGISSceneLayer(buildings);
scene.getOperationalLayers().add(sceneLayer);
// zoom to the layer's extent when loaded sceneLayer.addDoneLoadingListener(() -> {
if (sceneLayer.getLoadStatus() == LoadStatus.LOADED) {
// when the scene is clicked, identify the clicked feature and select it sceneView.setOnMouseClicked(e -> {
if (e.isStillSincePress() && e.getButton() == MouseButton.PRIMARY) {
// clear any previous selection sceneLayer.clearSelection();
// identify clicked feature Point2D point2D = new Point2D(e.getX(), e.getY());
ListenableFuture<IdentifyLayerResult> identify = sceneView.identifyLayerAsync(sceneLayer, point2D, 10, false, 1);
identify.addDoneListener(() -> {
try {
// get the identified result and check that it is a feature IdentifyLayerResult result = identify.get();
List<GeoElement> geoElements = result.getElements();
if (geoElements.size() > 0) {
GeoElement geoElement = geoElements.get(0);
if (geoElement instanceof Feature) {
// select the feature sceneLayer.selectFeature((Feature) geoElement);
}
}
} catch (InterruptedException | ExecutionException ex) {
new Alert(Alert.AlertType.ERROR, "Error identifying features").show();
}
});
}
});
} else {
new Alert(Alert.AlertType.ERROR, "Error loading scene layer").show();
}
});
} catch (Exception e) {
// on any error, display the stack trace. e.printStackTrace();
}
}
/**
* Stops and releases all resources used in application.
*/@Overridepublicvoidstop(){
if (sceneView != null) {
sceneView.dispose();
}
}
/**
* Opens and runs application.
*
* @param args arguments passed to this application
*/publicstaticvoidmain(String[] args){
Application.launch(args);
}
}