fieldUtils

AMD: require(["esri/layers/support/fieldUtils"], (fieldUtils) => { /* code goes here */ });
ESM: import * as fieldUtils from "@arcgis/core/layers/support/fieldUtils.js";
Object: esri/layers/support/fieldUtils
Since: ArcGIS Maps SDK for JavaScript 4.11

Convenience methods for getting field names used for feature layer labeling, elevation, editor tracking and time span.

Method Overview

Name Return Type Summary Object

Gets the appropriate display field name to label a feature.

fieldUtils

Returns an array of field names used in the Arcade expression for calculating the z-values of features in the given feature layer's FeatureLayer.elevationInfo.

fieldUtils

Returns an array of field names referenced in one or more Arcade expressions to be set on the given layer in either the renderer, labels, or popup template.

fieldUtils

Returns an array of editor tracking field names for a given layer.

fieldUtils

Returns an array of geometry field names for a given layer.

fieldUtils

Returns an array of field names used in the Arcade expression for labeling features in the given feature layer's FeatureLayer.labelingInfo.

fieldUtils

Returns an array of field names used in the layer's Renderer.

fieldUtils

Returns an array of field names related to time.

fieldUtils

Method Details

getDisplayFieldName

Method
getDisplayFieldName(layer){String}
Since: ArcGIS Maps SDK for JavaScript 4.15 fieldUtils since 4.11, getDisplayFieldName added at 4.15.

Gets the appropriate display field name to label a feature.

Parameter

An array of fields to determine the display field from.

Returns
Type Description
String The name of the display field to use for labeling.

getElevationFields

Method
getElevationFields(layer){Promise<string[]>}

Returns an array of field names used in the Arcade expression for calculating the z-values of features in the given feature layer's FeatureLayer.elevationInfo.

Parameter
layer FeatureLayer

The featureLayer to extract fields required for calculating feature z-values.

Returns
Type Description
Promise<string[]> When resolved, returns an array of field names.

getExpressionFields

Method
getExpressionFields(layer, expressions){Promise<string[]>}
Since: ArcGIS Maps SDK for JavaScript 4.15 fieldUtils since 4.11, getExpressionFields added at 4.15.

Returns an array of field names referenced in one or more Arcade expressions to be set on the given layer in either the renderer, labels, or popup template. This is useful for when you want to request the data for these fields prior to updating a renderer for fast visual updates or when you want to execute a client-side query on that data prior to setting the Arcade expressions on the layer.

Parameters

The layer for which the Arcade expressions are authored. This layer must have a fields property.

expressions String[]

An array of Arcade expressions to be set on the given layer.

Returns
Type Description
Promise<string[]> Returns an array of field names declared either by the $feature.fieldName or $feature[fieldName] syntax.
Example
const windDirectionExpression = `
  $feature["WIND_DIRECT"];
  $feature["WIND_SPEED"];
  var DEG = $feature.WIND_DIRECT;
  var SPEED = $feature.WIND_SPEED;
  var DIR = When( SPEED == 0, "",
    (DEG < 22.5 && DEG >= 0) || DEG > 337.5, "N",
    DEG >= 22.5 && DEG < 67.5, "NE",
    DEG >= 67.5 && DEG < 112.5, "E",
    DEG >= 112.5 && DEG < 157.5, "SE",
    DEG >= 157.5 && DEG < 202.5, "S",
    DEG >= 202.5 && DEG < 247.5, "SW",
    DEG >= 247.5 && DEG < 292.5, "W",
    DEG >= 292.5 && DEG < 337.5, "NW", "" );
  return SPEED + " mph " + DIR;
`;

const labelExpressions = [
  "Round($feature.TEMP) + '° F';",
  "$feature.R_HUMIDITY + '% RH'",
  "$feature.STATION_NAME",
  windDirectionExpression
];

// Assume the layer has only requested the OBJECTID field
fieldUtils.getExpressionFields(layer, labelExpressions)
 .then(function(fieldNames){

  // fieldNames = ["R_HUMIDITY", "STATION_NAME", "TEMP", "WIND_DIRECT", "WIND_SPEED"]
  layer.outFields = fieldNames;

  // Do something else like a client-side query with those fields
 }).catch(function(error){
   console.error(error);
 });

getFeatureEditFields

Method
getFeatureEditFields(layer){String[]}

Returns an array of editor tracking field names for a given layer. It includes the fields from the FeatureLayer.editFieldsInfo.

Parameter

The layer from which to extract editor tracking fields.

Returns
Type Description
String[] An array of field names used for editor tracking.

getFeatureGeometryFields

Method
getFeatureGeometryFields(layer){String[]}
Since: ArcGIS Maps SDK for JavaScript 4.19 fieldUtils since 4.11, getFeatureGeometryFields added at 4.19.

Returns an array of geometry field names for a given layer. It includes the fields from the FeatureLayer.geometryProperties.

Parameter

The layer to extract geometry fields from.

Returns
Type Description
String[] An array of geometry field names.

getLabelingFields

Method
getLabelingFields(layer){Promise<string[]>}

Returns an array of field names used in the Arcade expression for labeling features in the given feature layer's FeatureLayer.labelingInfo.

Parameter
layer FeatureLayer

The Feature Layer from which to extract label fields.

Returns
Type Description
Promise<string[]> When resolved, returns an array of field names used for labeling.

getRendererFields

Method
getRendererFields(renderer, fieldsIndex){Promise<string[]>}
Since: ArcGIS Maps SDK for JavaScript 4.30 fieldUtils since 4.11, getRendererFields added at 4.30.

Returns an array of field names used in the layer's Renderer.

Parameters
renderer Renderer

Layer's renderer to collect field names used in that renderer.

fieldsIndex FieldsIndex

The field index of the layer. It can be used to make case-insensitive lookups for a field by name.

Returns
Type Description
Promise<string[]> When resolved, returns an array of field names required by the layer's renderer, sorted in ascending order.
Example
const rendererFields = fieldUtils.getRendererFields(layer.renderer, layer.fieldsIndex);

getTimeFields

Method
getTimeFields(layer){Promise<string[]>}

Returns an array of field names related to time. It includes the fields from the FeatureLayer.timeInfo, and the trackIdField.

Parameter
layer FeatureLayer

The Feature Layer from which to extract time fields.

Returns
Type Description
Promise<string[]> When resolved, returns an array of time field names.

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