View on GitHub Sample viewer app

Identify features in a scene to select.

Image of scene layer selection

Use case

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

  1. Create an ArcGISSceneLayer passing in the URL to a scene layer service.
  2. Use sceneView.setOnMouseClicked to get the screen click location Point2D.
  3. Call sceneView.identifyLayersAsync(sceneLayer, point2D, tolerance, false, 1) to identify features in the scene.
  4. From the resulting IdentifyLayerResult, get the list of identified GeoElements with result.getElements().
  5. Get the first element in the list, checking that it is a feature, and call sceneLayer.selectFeature(feature) to select it.

About the data

The scene shows a buildings layer in Brest, France hosted on ArcGIS Online.

Relevant API

  • ArcGISSceneLayer
  • Scene
  • SceneView

Tags

3D, Berlin, buildings, identify, model, query, search, select

Sample Code

module-info.java module-info.java SceneLayerSelectionSample.java
/*
* Copyright 2022 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.
*/
module com.esri.samples.scene_layer_selection {
// require ArcGIS Maps SDK for Java module
requires com.esri.arcgisruntime;
// handle SLF4J http://www.slf4j.org/codes.html#StaticLoggerBinder
requires org.slf4j.nop;
// require JavaFX modules that the application uses
requires javafx.graphics;
exports com.esri.samples.scene_layer_selection;
}