Display custom labels in a 3D scene.

Use case
Labeling features is useful to visually display a key piece of information or attribute of a feature on a map. For example, you may want to label rivers or streets with their names.
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
- Create an
ArcGISScenefrom aPortalItem. - Add the scene to an
SceneViewand load it. - After loading is complete, obtain the
FeatureLayerfrom one of theGroupLayersin the scene’s operationalLayers. - Set the feature layer’s
labelsEnabledproperty totrue. - Create an
TextSymbolto use for displaying the label text. - Create an
LabelDefinitionusing anArcadeLabelExpression. - Add the definition to the feature layer’s
labelDefinitionsarray.
Relevant API
- ArcadeLabelExpression
- FeatureLayer
- LabelDefinition
- Scene
- SceneView
- TextSymbol
About the data
This sample shows a New York City infrastructure scene hosted on ArcGIS Online.
Additional information
Help regarding the Arcade label expression script for defining a label definition can be found on the ArcGIS Developers site.
Tags
3D, arcade, attribute, buildings, label, model, scene, symbol, text, URL, visualization
Sample code
/* Copyright 2026 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.arcgismaps.sample.showlabelsonlayerin3d.components
import android.app.Applicationimport androidx.lifecycle.AndroidViewModelimport androidx.lifecycle.viewModelScopeimport com.arcgismaps.Colorimport com.arcgismaps.arcade.ArcadeExpressionimport com.arcgismaps.arcgisservices.LabelingPlacementimport com.arcgismaps.mapping.ArcGISSceneimport com.arcgismaps.mapping.PortalItemimport com.arcgismaps.mapping.labeling.ArcadeLabelExpressionimport com.arcgismaps.mapping.labeling.LabelDefinitionimport com.arcgismaps.mapping.layers.FeatureLayerimport com.arcgismaps.mapping.layers.GroupLayerimport com.arcgismaps.mapping.symbology.TextSymbolimport com.arcgismaps.portal.Portalimport com.esri.arcgismaps.sample.sampleslib.components.MessageDialogViewModelimport kotlinx.coroutines.launch
class ShowLabelsOnLayerIn3DViewModel(app: Application) : AndroidViewModel(app) {
val arcGISScene = ArcGISScene( item = PortalItem( portal = Portal.arcGISOnline(Portal.Connection.Anonymous), itemId = "850dfee7d30f4d9da0ebca34a533c169" ) )
// Create the text symbol for the label definition. private val textSymbol = TextSymbol().apply { color = Color.red haloColor = Color.white haloWidth = 2.0f size = 16.0f }
// Create the label definition to display the installation date of a feature. private val labelDefinition = LabelDefinition( labelExpression = ArcadeLabelExpression( arcadeExpression = ArcadeExpression( expression = $$"Text($feature.INSTALLATIONDATE, `DD MMM YY`)" ) ), textSymbol = textSymbol ).apply { placement = LabelingPlacement.LineAboveAlong useCodedValues = true }
init { viewModelScope.launch { // Load the scene arcGISScene.load().onFailure { messageDialogVM.showMessageDialog(it) } // Find the group layer and feature layer val groupLayer = arcGISScene.operationalLayers .filterIsInstance<GroupLayer>() .first { it.name == "Gas" } val featureLayer = groupLayer.layers .filterIsInstance<FeatureLayer>() .first { it.name == "Gas Main" }
// Enable labels and add the label definition to the feature layer featureLayer.apply { labelsEnabled = true labelDefinitions.clear() labelDefinitions.add(labelDefinition) } } }
// Create a message dialog view model for handling error messages val messageDialogVM = MessageDialogViewModel()}/* Copyright 2026 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.arcgismaps.sample.showlabelsonlayerin3d
import android.os.Bundleimport androidx.activity.ComponentActivityimport androidx.activity.compose.setContentimport androidx.activity.enableEdgeToEdgeimport androidx.compose.material3.MaterialThemeimport androidx.compose.material3.Surfaceimport com.esri.arcgismaps.sample.sampleslib.theme.SampleAppThemeimport com.esri.arcgismaps.sample.showlabelsonlayerin3d.screens.ShowLabelsOnLayerIn3DScreen
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() setContent { SampleAppTheme { Surface(color = MaterialTheme.colorScheme.background) { ShowLabelsOnLayerIn3DScreen() } } } }}/* Copyright 2026 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.arcgismaps.sample.showlabelsonlayerin3d.screens
import androidx.compose.foundation.layout.Columnimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.paddingimport androidx.compose.material3.Scaffoldimport androidx.compose.runtime.Composableimport androidx.compose.ui.Modifierimport androidx.compose.ui.res.stringResourceimport androidx.lifecycle.viewmodel.compose.viewModelimport com.arcgismaps.toolkit.geoviewcompose.SceneViewimport com.esri.arcgismaps.sample.showlabelsonlayerin3d.Rimport com.esri.arcgismaps.sample.showlabelsonlayerin3d.components.ShowLabelsOnLayerIn3DViewModelimport com.esri.arcgismaps.sample.sampleslib.components.MessageDialogimport com.esri.arcgismaps.sample.sampleslib.components.SampleTopAppBar
/** * Main screen layout for the sample app */@Composablefun ShowLabelsOnLayerIn3DScreen( mapViewModel: ShowLabelsOnLayerIn3DViewModel = viewModel()) { val mapViewModel: ShowLabelsOnLayerIn3DViewModel = viewModel() Scaffold( topBar = { SampleTopAppBar(title = stringResource(R.string.show_labels_on_layer_in_3d_app_name)) }, content = { Column( modifier = Modifier .fillMaxSize() .padding(it), ) { SceneView( modifier = Modifier .fillMaxSize() .weight(1f), arcGISScene = mapViewModel.arcGISScene ) }
mapViewModel.messageDialogVM.apply { if (dialogStatus) { MessageDialog( title = messageTitle, description = messageDescription, onDismissRequest = ::dismissDialog ) } } } )}