Display 3D labels in scene

View inQMLC++
View on GitHub
Sample viewer app

This sample demonstrates how to display custom labels in a 3D scene.

screenshot

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 a Scene from a URL.
  2. Obtain the FeatureLayer from one of the GroupLayers in the scene's operationalLayers.
  3. Create a TextSymbol to use for displaying the label text.
  4. Create a LabelDefinition with an ArcadeLabelExpression.
  5. Add the definition to the feature layer's labelDefinitions array.
  6. Set the feature layer's labelsEnabled property to true.

Relevant API

  • ArcadeLabelExpression
  • FeatureLayer
  • LabelDefinition
  • Scene
  • SceneView
  • TextSymbol

About the data

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

Tags

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

Sample Code

Display3DLabelsInScene.qmlDisplay3DLabelsInScene.cppDisplay3DLabelsInScene.h
                                 
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
// [WriteFile Name=Display3DLabelsInScene, Category=Scenes]
// [Legal]
// Copyright 2021 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.
// [Legal]

import QtQuick 2.6
import QtQuick.Controls 2.2
import Esri.Samples 1.0

Item {

    SceneView {
        id: view
        anchors.fill: parent
    }

    // Declare the C++ instance which creates the scene etc. and supply the view
    Display3DLabelsInSceneSample {
        id: model
        sceneView: view
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.