Skip to content
import FieldsIndex from "@arcgis/core/layers/support/FieldsIndex.js";
Since
ArcGIS Maps SDK for JavaScript 4.12

This class provides convenient methods that can be used to make case-insensitive lookups for a field by its name. It also provides more information such as the list of date fields in a layer.

Constructors

Constructor

Constructor
Parameters
ParameterTypeDescriptionRequired
fields
T[] | null | undefined

Properties

PropertyTypeClass
dateFields
readonly
T[]

dateFields

readonly Property
Type
T[]

An array of date fields or field json objects.

Default value
[]

Methods

MethodSignatureClass
get
get(fieldName: string | null | undefined): T | null | undefined
getTimeZone(fieldOrFieldName: T | string | null | undefined): string | null | undefined
has
has(fieldName: string): boolean
isDateField(fieldName: string | null | undefined): boolean

get

Method
Signature
get (fieldName: string | null | undefined): T | null | undefined

Returns a field with the specified field name.

Parameters
ParameterTypeDescriptionRequired
fieldName

The name of the field. The name is case-insensitive.

Returns
T | null | undefined

Returns a field with a given name.

getTimeZone

Method
Signature
getTimeZone (fieldOrFieldName: T | string | null | undefined): string | null | undefined

Returns a time zone for a field. Use this method to ensure queries in the following places are issued in the time zone of the given date field:

The following table explains the value returned from this method:

Field typeReturned value
Date fieldReturns the time zone associated with the date field. Returns unknown if the layer's date fields are in unknown time zone.
Date-only, Time-only or Timestamp-offset fieldReturns unknown as services do not have time zone associated with date-only, time-only and timestamp-offset fields. Date-only and time-only fields are time zone agnostic. Timestamp-offset field values store its time offset.
All other fieldsReturns null.
See also
Parameters
ParameterTypeDescriptionRequired
fieldOrFieldName

The name of the field or the field instance.

Returns
string | null | undefined

Returns the time zone for the given date field name or date field instance.

Example
// Query for features that recorded on January 1, 2012 9:00:00 AM GMT
// DateTime_PST date field values are in PST. Must adjust the epoch values to PST
const queryDate = new Date(1325408400000); 01/01/2012 9:00:00 AM GMT
let queryFields = ["DateTime_PST"];
// get the timezone of the DateTime_PST date field
const fieldTimeZone = layer.fieldsIndex.getTimeZone("DateTime_PST") ;
// we need to adjust the date value to match the time zone of the field.
const where = `DateTime_PST < DATE '${getDateForTimeZone(queryDate, fieldTimeZone)}'`
layerView.filter = new FeatureFilter({
where
});
runQueries(where, queryFields);
// This function conveniently formats a date in terms of the parsed time zone.
function getDateForTimeZone(queryDate, timezone) {
// adjust the given date field to the timezone of the date field
const zonedDate = new Date(
queryDate.toLocaleString("en-US", {
timeZone: timezone
})
);
const pad = (value) => String(value).padStart(2, "0");
const month = pad(zonedDate.getMonth() + 1);
const day = pad(zonedDate.getDate())
const year = zonedDate.getFullYear();
const hour = pad(zonedDate.getHours());
const minutes = pad(zonedDate.getMinutes());
const seconds = pad(zonedDate.getSeconds());
return `${year}-${month}-${day} ${hour}:${minutes}:${seconds}`;
}

has

Method
Signature
has (fieldName: string): boolean

Checks if a field with the specified field name exists in the layer.

Parameters
ParameterTypeDescriptionRequired
fieldName

The name of the field. The name is case-insensitive.

Returns
boolean

Returns true if the field exists otherwise returns false.

isDateField

Method
Signature
isDateField (fieldName: string | null | undefined): boolean

Checks if a field with the specified field name is a date field.

Parameters
ParameterTypeDescriptionRequired
fieldName

The name of the field.

Returns
boolean

Returns true if the field type is date otherwise returns false.