This sample shows how to change the elevation information of a FeatureLayer for 3D visualization. Various options are available to customize the elevation of features in a 3D scene by modifying the elevationInfo property of a FeatureLayer.
Four properties allow you to customize each feature's elevation: mode
, offset
, feature
and unit
.
Elevation mode sets the type of elevation placement. These are the values that mode
can take:
-
on-the-ground
: Balloon graphics are draped on the terrain surface. In this modeoffset
,feature
, andExpression Info unit
have no effect and z-values are discarded. -
relative-to-ground
: Balloon graphics are placed at an elevation relative to the terrain surface. If graphics have z-values, they will be kept. If defined,feature
is used instead of z-values. In the screenshot below, the graphics have z-values, but we set theExpression Info expression
infeature
toExpression Info 0
. -
relative-to-scene
: Balloon graphics are placed at an elevation relative to buildings. If present, the geometry's z-value is added to the elevation. Iffeature
is defined, the result of the expression is used instead of the geometry’s z-value.Expression Info -
absolute-height
: Balloon graphics are placed at an absolute height relative to the datum. The absolute height is determined by each feature's z-value. This mode works likerelative-to-ground
with the difference that terrain elevation is discarded.
Graphic offset is added to the elevation of all graphics. An offset
of 100 moves the symbols 100 units (meters by default) above their existing elevation. Changing the unit
to kilometers places the graphics 100km above the ground as shown in the image below:
(z-values are here not considered because feature
is defined)
Custom elevation can be calculated using feature
, which is an Arcade expression that evaluates to a custom elevation value. Once this property is set, zvalues are not considered anymore.
For example, you can do the following to calculate a custom elevation based on a feature's z-value and an attribute:
elevationInfo: {
mode: "relative-to-ground",
featureExpressionInfo: {
expression: "Geometry($feature).z * 10 + $feature.HEIGHT100"
},
unit: "meters"
}
This is how the graphics would be elevated using this code:
outFields should be defined on the layer when using attributes in expression
.
Elevation unit defines the units for feature
and offset
. By default it is meters.
Compare this sample to 3D symbols for points to understand the different choices of visualizing 2D features in 3D.