View on GitHub Sample viewer app

Display custom labels in a 3D scene.

Show labels on layer in 3D

Use case

Labeling features is useful to visually display information or attributes on a scene. For example, city officials or maintenance crews may want to show installation dates of features of a gas network.

How to use the sample

Pan and zoom to explore the scene. Notice the labels showing installation dates of features in the 3D gas network.

How it works

  1. Create an ArcGISScene using a PortalItem.
  2. Add the scene to a SceneView and load it.
  3. After loading is complete, obtain the FeatureLayer from the scene’s operational layers.
  4. Set the feature layer’s setLabelsEnabled property to true.
  5. Create a TextSymbol to use for displaying the label text.
  6. Create a LabelDefinition using an ArcadeLabelExpression and the text symbol.
  7. Add the definition to the feature layer’s labelDefinitions list.

Relevant API

  • ArcadeLabelExpression
  • ArcGISScene
  • FeatureLayer
  • LabelDefinition
  • SceneView
  • TextSymbol

About the data

This sample shows a New York City infrastructure scene hosted on ArcGIS Online.

Tags

3D, arcade, attribute, buildings, label, model, scene, symbol, text, visualization

Sample Code

module-info.java module-info.java ShowLabelsOnLayerIn3dSample.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.show_labels_on_layer_in_3d {
// 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;
requires javafx.controls;
exports com.esri.samples.show_labels_on_layer_in_3d;
}