UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

377 lines (374 loc) • 27.9 kB
import type FieldInfoFormat from "./support/FieldInfoFormat.js"; import type { ClonableMixin } from "../core/Clonable.js"; import type { JSONSupport } from "../core/JSONSupport.js"; import type { FieldFormatUnion } from "../layers/support/types.js"; import type { NumberFieldFormatProperties } from "../layers/support/NumberFieldFormat.js"; import type { DateTimeFieldFormatProperties } from "../layers/support/DateTimeFieldFormat.js"; import type { FieldInfoFormatProperties } from "./support/FieldInfoFormat.js"; export interface FieldInfoProperties extends Partial<Pick<FieldInfo, "fieldName" | "isEditable" | "label" | "statisticType" | "stringFieldOption" | "tooltip" | "visible">> { /** * Provides formatting options for numerical or date fields, using the same format types as the [layer level field formatting](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#fieldConfigurations). * Setting this property automatically updates the [format](https://developers.arcgis.com/javascript/latest/references/core/popup/FieldInfo/#format) property. This property takes precedence over the [format](https://developers.arcgis.com/javascript/latest/references/core/popup/FieldInfo/#format) property when both are set and working with supported layer types. `FieldInfo.fieldFormat` should be used in the context of [fields content](https://developers.arcgis.com/javascript/latest/references/core/popup/content/FieldsContent/) used within [PopupTemplate.content](https://developers.arcgis.com/javascript/latest/references/core/PopupTemplate/), rather than directly on the [PopupTemplate.fieldInfos](https://developers.arcgis.com/javascript/latest/references/core/PopupTemplate/#fieldInfos) property. * * > [!WARNING] * > * > **Notes:** * > - This property is only supported for [FeatureLayers](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/) that reference services (not supported for feature collections) and when set on a [FieldsContent](https://developers.arcgis.com/javascript/latest/references/core/popup/content/FieldsContent/) element within a [PopupTemplate](https://developers.arcgis.com/javascript/latest/references/core/PopupTemplate/). * > - FieldInfos participating in [clustering](https://developers.arcgis.com/javascript/latest/references/core/layers/support/FeatureReductionCluster/#popupTemplate) or [binning](https://developers.arcgis.com/javascript/latest/references/core/layers/support/FeatureReductionBinning/#popupTemplate) are also supported when the parent layer is a service-based [FeatureLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/). * > - Use the [format](https://developers.arcgis.com/javascript/latest/references/core/popup/FieldInfo/#format) property instead if formatting: * > - [Layers](https://developers.arcgis.com/javascript/latest/references/core/layers/Layer/) other than [FeatureLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/) or feature collections. * > - [PopupTemplate.fieldInfos](https://developers.arcgis.com/javascript/latest/references/core/PopupTemplate/#fieldInfos) for layer types that don't support [layer level field formatting](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#fieldConfigurations). * > - FieldInfo that contains [field names](https://developers.arcgis.com/javascript/latest/references/core/popup/FieldInfo/#fieldName) referencing related fields or Arcade expressions. * * @since 4.34 * @see [FeatureLayer.fieldConfigurations](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#fieldConfigurations) * @see [FieldConfiguration](https://developers.arcgis.com/javascript/latest/references/core/layers/support/FieldConfiguration/) */ fieldFormat?: ((DateTimeFieldFormatProperties & { type: "date-time" }) | (NumberFieldFormatProperties & { type: "number" })) | null; /** * Class which provides formatting options for numerical or date fields and how they should display. * Setting this property will also automatically update the [fieldFormat](https://developers.arcgis.com/javascript/latest/references/core/popup/FieldInfo/#fieldFormat) property. * * > [!WARNING] * > * > **Notes:** * > - Use this property to format date and numerical fields in the following scenarios: * > - Formatting fields in [Layers](https://developers.arcgis.com/javascript/latest/references/core/layers/Layer/) other than [FeatureLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/) or feature collections. * > - Formatting fields in [PopupTemplate.fieldInfos](https://developers.arcgis.com/javascript/latest/references/core/PopupTemplate/#fieldInfos) for layer types that don't support [layer level field formatting](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#fieldConfigurations). * > - Formatting fields that contain [field names](https://developers.arcgis.com/javascript/latest/references/core/popup/FieldInfo/#fieldName) referencing related fields or Arcade expressions. * > - If formatting [FieldsContent](https://developers.arcgis.com/javascript/latest/references/core/popup/content/FieldsContent/) for a [FeatureLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/), use the [fieldFormat](https://developers.arcgis.com/javascript/latest/references/core/popup/FieldInfo/#fieldFormat) property to format dates and numbers instead. See the [fieldFormat](https://developers.arcgis.com/javascript/latest/references/core/popup/FieldInfo/#fieldFormat) property description for limitations. * > - If displaying a `timestamp-offset` or `date` [Field.type](https://developers.arcgis.com/javascript/latest/references/core/layers/support/Field/#type) field in a [Popup](https://developers.arcgis.com/javascript/latest/references/core/widgets/Popup/), [Features](https://developers.arcgis.com/javascript/latest/references/core/widgets/Features/), or [Feature](https://developers.arcgis.com/javascript/latest/references/core/widgets/Feature/) widget and the [MapView](https://developers.arcgis.com/javascript/latest/references/core/views/MapView/) has a [MapView.timeZone](https://developers.arcgis.com/javascript/latest/references/core/views/MapView/#timeZone) set other than `unknown`, * > the abbreviated time zone suffix will be omitted from the attribute value. For example, the attribute value will display as `9/28/2014, 7:58 PM`. To display an abbreviated time zone suffix, see the `Read more` section. * > <details> * > <summary>Read More</summary> * > * > * If the user wants `date` fields to show a time zone suffix (e.g. `9/28/2014, 7:58 PM PST`), then the [Arcade](https://developers.arcgis.com/javascript/latest/arcade/) [Text](https://developers.arcgis.com/arcade/function-reference/text_functions/#text) function can be used to format the field value. This can be done either with [ExpressionContent](https://developers.arcgis.com/javascript/latest/references/core/popup/content/ExpressionContent/) or [attribute expressions](https://developers.arcgis.com/javascript/latest/references/core/popup/ExpressionInfo/). * > ```js * > // Attribute expression using expressionInfos to append the time zone suffix to a date field. * > // Date field types will show in the MapView's current time zone. * > layer.popupTemplate = { * > title: "Display time zones", * > fieldInfos: [{ * > fieldName: "expression/date-with-time-zone-suffix", * > }], * > expressionInfos: [{ * > expression: `Text($feature.date_Field, "M/D/Y, h:mm A ZZZZ")`, * > name: "date-with-time-zone-suffix", * > }], * > content: [{ * > type: "fields" * > }] * > }; * > ``` * > ```js * > // ExpressionContent to append the time zone suffix to a date field. * > // Date field types will show in the MapView's current time zone by default. * > layer.popupTemplate = { * > title: "Display time zones", * > content: [{ * > type: "expression", * > expressionInfo: { * > expression: `return { * > type : 'text', * > text : Text($feature.date_Field, "M/D/Y, h:mm A ZZZZ") * > }` * > } * > }] * > }; * > ``` * > * If the user wants `timestamp-offset` fields to display in the time zone from the server with an abbreviated time zone suffix, then the [Arcade](https://developers.arcgis.com/javascript/latest/arcade/) [Text](https://developers.arcgis.com/arcade/function-reference/text_functions/#text) function can be used to format the field value. This can be done either with [ExpressionContent](https://developers.arcgis.com/javascript/latest/references/core/popup/content/ExpressionContent/) or [attribute expressions](https://developers.arcgis.com/javascript/latest/references/core/popup/ExpressionInfo/). * > ```js * > // Attribute expression using expressionInfos to append the time zone suffix to a timestamp-offset field. * > layer.popupTemplate = { * > title: "Display time zones", * > fieldInfos: [{ * > fieldName: "expression/TSO-from-server", * > }], * > expressionInfos: [{ * > expression: `Text($feature.TimestampOffset_Field, "M/D/Y, h:mm A ZZZZ")`, * > name: "TSO-from-server", * > }], * > content: [{ * > type: "fields" * > }] * > }; * > ``` * > ```js * > // ExpressionContent to append the time zone suffix to a timestamp-offset field. * > layer.popupTemplate = { * > title: "Display time zones", * > content: [{ * > type: "expression", * > expressionInfo: { * > expression: `return { * > type : 'text', * > text : Text($feature.TimestampOffset_Field, "M/D/Y, h:mm A ZZZZ") * > }` * > } * > }] * > }; * > ``` * > * If the user wants `timestamp-offset` fields to display in the MapView's time zone with an abbreviated time zone suffix, then the [`ChangeTimeZone`](https://developers.arcgis.com/javascript/latest/arcade/function-reference/date_functions/#changetimezone) [Arcade](https://developers.arcgis.com/javascript/latest/arcade/) function can be used to format the value. * > ```js * > // Attribute expression using expressionInfos to append the MapView's current time zone suffix to a timestamp-offset field * > layer.popupTemplate = { * > title: "Display time zones", * > fieldInfos: [{ * > fieldName: "expression/TSO-matching-view-tz", * > }], * > expressionInfos: [{ * > expression: `Text(ChangeTimeZone($feature.TimestampOffset_Field, GetEnvironment().timeZone), "M/D/Y, h:mm A ZZZZ")`, * > name: "TSO-matching-view-tz", * > }], * > content: [{ * > type: "fields" * > }] * > }; * > ``` * > ```js * > // ExpressionContent to append the MapView's current time zone suffix to a timestamp-offset field * > layer.popupTemplate = { * > title: "Display time zones", * > content: [{ * > type: "expression", * > expressionInfo: { * > expression: `return { * > type: "text", * > text: Text(ChangeTimeZone($feature.TimestampOffset_Field, GetEnvironment().timeZone), "M/D/Y, h:mm A ZZZZ") * > }` * > } * > }] * > }; * > ``` * > * > </details> * * @see [fieldFormat](https://developers.arcgis.com/javascript/latest/references/core/popup/FieldInfo/#fieldFormat) */ format?: FieldInfoFormatProperties | null; } export type StringFieldOption = "text-area" | "text-box" | "rich-text"; /** * The `FieldInfo` class defines how a [Field](https://developers.arcgis.com/javascript/latest/references/core/layers/support/Field/) participates, * or in some cases, does not participate, in a [PopupTemplate](https://developers.arcgis.com/javascript/latest/references/core/PopupTemplate/). * * @since 4.11 * @see [PopupTemplate](https://developers.arcgis.com/javascript/latest/references/core/PopupTemplate/) * @see [ExpressionInfo](https://developers.arcgis.com/javascript/latest/references/core/popup/ExpressionInfo/) * @see [Sample - Intro to PopupTemplate](https://developers.arcgis.com/javascript/latest/sample-code/intro-popuptemplate/) * @see [Sample - Custom popup actions per feature](https://developers.arcgis.com/javascript/latest/sample-code/popup-custom-action/) * @see [Sample - Multiple popup elements](https://developers.arcgis.com/javascript/latest/sample-code/popup-multipleelements/) * @see [Sample - PopupTemplate function](https://developers.arcgis.com/javascript/latest/sample-code/popuptemplate-function/) * @see [Sample - PopupTemplate with promise](https://developers.arcgis.com/javascript/latest/sample-code/popuptemplate-promise/) * @example * let fieldInfo = new FieldInfo({ * fieldName: 'PROMINENCE_ft', * label: 'Prominence (feet)', * //autocasts to FieldInfo.Format * format: { * places: 0, * digitSeparator: true * } * }); */ export default class FieldInfo extends FieldInfoSuperclass { constructor(properties?: FieldInfoProperties); /** * Provides formatting options for numerical or date fields, using the same format types as the [layer level field formatting](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#fieldConfigurations). * Setting this property automatically updates the [format](https://developers.arcgis.com/javascript/latest/references/core/popup/FieldInfo/#format) property. This property takes precedence over the [format](https://developers.arcgis.com/javascript/latest/references/core/popup/FieldInfo/#format) property when both are set and working with supported layer types. `FieldInfo.fieldFormat` should be used in the context of [fields content](https://developers.arcgis.com/javascript/latest/references/core/popup/content/FieldsContent/) used within [PopupTemplate.content](https://developers.arcgis.com/javascript/latest/references/core/PopupTemplate/), rather than directly on the [PopupTemplate.fieldInfos](https://developers.arcgis.com/javascript/latest/references/core/PopupTemplate/#fieldInfos) property. * * > [!WARNING] * > * > **Notes:** * > - This property is only supported for [FeatureLayers](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/) that reference services (not supported for feature collections) and when set on a [FieldsContent](https://developers.arcgis.com/javascript/latest/references/core/popup/content/FieldsContent/) element within a [PopupTemplate](https://developers.arcgis.com/javascript/latest/references/core/PopupTemplate/). * > - FieldInfos participating in [clustering](https://developers.arcgis.com/javascript/latest/references/core/layers/support/FeatureReductionCluster/#popupTemplate) or [binning](https://developers.arcgis.com/javascript/latest/references/core/layers/support/FeatureReductionBinning/#popupTemplate) are also supported when the parent layer is a service-based [FeatureLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/). * > - Use the [format](https://developers.arcgis.com/javascript/latest/references/core/popup/FieldInfo/#format) property instead if formatting: * > - [Layers](https://developers.arcgis.com/javascript/latest/references/core/layers/Layer/) other than [FeatureLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/) or feature collections. * > - [PopupTemplate.fieldInfos](https://developers.arcgis.com/javascript/latest/references/core/PopupTemplate/#fieldInfos) for layer types that don't support [layer level field formatting](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#fieldConfigurations). * > - FieldInfo that contains [field names](https://developers.arcgis.com/javascript/latest/references/core/popup/FieldInfo/#fieldName) referencing related fields or Arcade expressions. * * @since 4.34 * @see [FeatureLayer.fieldConfigurations](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#fieldConfigurations) * @see [FieldConfiguration](https://developers.arcgis.com/javascript/latest/references/core/layers/support/FieldConfiguration/) */ get fieldFormat(): FieldFormatUnion | null | undefined; set fieldFormat(value: ((DateTimeFieldFormatProperties & { type: "date-time" }) | (NumberFieldFormatProperties & { type: "number" })) | null | undefined); /** * The field name as defined by the service or the [ExpressionInfo.name](https://developers.arcgis.com/javascript/latest/references/core/popup/ExpressionInfo/#name) of * an [Arcade](https://developers.arcgis.com/javascript/latest/arcade/) * expression. Arcade expression names are defined in the [PopupTemplate.expressionInfos](https://developers.arcgis.com/javascript/latest/references/core/PopupTemplate/#expressionInfos) * property of the PopupTemplate. When referencing Arcade expressions, you must preface the name with `expression/`, such as * `expression/percent-total`. * * @see [ExpressionInfo.name](https://developers.arcgis.com/javascript/latest/references/core/popup/ExpressionInfo/#name) */ accessor fieldName: string | null | undefined; /** * Class which provides formatting options for numerical or date fields and how they should display. * Setting this property will also automatically update the [fieldFormat](https://developers.arcgis.com/javascript/latest/references/core/popup/FieldInfo/#fieldFormat) property. * * > [!WARNING] * > * > **Notes:** * > - Use this property to format date and numerical fields in the following scenarios: * > - Formatting fields in [Layers](https://developers.arcgis.com/javascript/latest/references/core/layers/Layer/) other than [FeatureLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/) or feature collections. * > - Formatting fields in [PopupTemplate.fieldInfos](https://developers.arcgis.com/javascript/latest/references/core/PopupTemplate/#fieldInfos) for layer types that don't support [layer level field formatting](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#fieldConfigurations). * > - Formatting fields that contain [field names](https://developers.arcgis.com/javascript/latest/references/core/popup/FieldInfo/#fieldName) referencing related fields or Arcade expressions. * > - If formatting [FieldsContent](https://developers.arcgis.com/javascript/latest/references/core/popup/content/FieldsContent/) for a [FeatureLayer](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/), use the [fieldFormat](https://developers.arcgis.com/javascript/latest/references/core/popup/FieldInfo/#fieldFormat) property to format dates and numbers instead. See the [fieldFormat](https://developers.arcgis.com/javascript/latest/references/core/popup/FieldInfo/#fieldFormat) property description for limitations. * > - If displaying a `timestamp-offset` or `date` [Field.type](https://developers.arcgis.com/javascript/latest/references/core/layers/support/Field/#type) field in a [Popup](https://developers.arcgis.com/javascript/latest/references/core/widgets/Popup/), [Features](https://developers.arcgis.com/javascript/latest/references/core/widgets/Features/), or [Feature](https://developers.arcgis.com/javascript/latest/references/core/widgets/Feature/) widget and the [MapView](https://developers.arcgis.com/javascript/latest/references/core/views/MapView/) has a [MapView.timeZone](https://developers.arcgis.com/javascript/latest/references/core/views/MapView/#timeZone) set other than `unknown`, * > the abbreviated time zone suffix will be omitted from the attribute value. For example, the attribute value will display as `9/28/2014, 7:58 PM`. To display an abbreviated time zone suffix, see the `Read more` section. * > <details> * > <summary>Read More</summary> * > * > * If the user wants `date` fields to show a time zone suffix (e.g. `9/28/2014, 7:58 PM PST`), then the [Arcade](https://developers.arcgis.com/javascript/latest/arcade/) [Text](https://developers.arcgis.com/arcade/function-reference/text_functions/#text) function can be used to format the field value. This can be done either with [ExpressionContent](https://developers.arcgis.com/javascript/latest/references/core/popup/content/ExpressionContent/) or [attribute expressions](https://developers.arcgis.com/javascript/latest/references/core/popup/ExpressionInfo/). * > ```js * > // Attribute expression using expressionInfos to append the time zone suffix to a date field. * > // Date field types will show in the MapView's current time zone. * > layer.popupTemplate = { * > title: "Display time zones", * > fieldInfos: [{ * > fieldName: "expression/date-with-time-zone-suffix", * > }], * > expressionInfos: [{ * > expression: `Text($feature.date_Field, "M/D/Y, h:mm A ZZZZ")`, * > name: "date-with-time-zone-suffix", * > }], * > content: [{ * > type: "fields" * > }] * > }; * > ``` * > ```js * > // ExpressionContent to append the time zone suffix to a date field. * > // Date field types will show in the MapView's current time zone by default. * > layer.popupTemplate = { * > title: "Display time zones", * > content: [{ * > type: "expression", * > expressionInfo: { * > expression: `return { * > type : 'text', * > text : Text($feature.date_Field, "M/D/Y, h:mm A ZZZZ") * > }` * > } * > }] * > }; * > ``` * > * If the user wants `timestamp-offset` fields to display in the time zone from the server with an abbreviated time zone suffix, then the [Arcade](https://developers.arcgis.com/javascript/latest/arcade/) [Text](https://developers.arcgis.com/arcade/function-reference/text_functions/#text) function can be used to format the field value. This can be done either with [ExpressionContent](https://developers.arcgis.com/javascript/latest/references/core/popup/content/ExpressionContent/) or [attribute expressions](https://developers.arcgis.com/javascript/latest/references/core/popup/ExpressionInfo/). * > ```js * > // Attribute expression using expressionInfos to append the time zone suffix to a timestamp-offset field. * > layer.popupTemplate = { * > title: "Display time zones", * > fieldInfos: [{ * > fieldName: "expression/TSO-from-server", * > }], * > expressionInfos: [{ * > expression: `Text($feature.TimestampOffset_Field, "M/D/Y, h:mm A ZZZZ")`, * > name: "TSO-from-server", * > }], * > content: [{ * > type: "fields" * > }] * > }; * > ``` * > ```js * > // ExpressionContent to append the time zone suffix to a timestamp-offset field. * > layer.popupTemplate = { * > title: "Display time zones", * > content: [{ * > type: "expression", * > expressionInfo: { * > expression: `return { * > type : 'text', * > text : Text($feature.TimestampOffset_Field, "M/D/Y, h:mm A ZZZZ") * > }` * > } * > }] * > }; * > ``` * > * If the user wants `timestamp-offset` fields to display in the MapView's time zone with an abbreviated time zone suffix, then the [`ChangeTimeZone`](https://developers.arcgis.com/javascript/latest/arcade/function-reference/date_functions/#changetimezone) [Arcade](https://developers.arcgis.com/javascript/latest/arcade/) function can be used to format the value. * > ```js * > // Attribute expression using expressionInfos to append the MapView's current time zone suffix to a timestamp-offset field * > layer.popupTemplate = { * > title: "Display time zones", * > fieldInfos: [{ * > fieldName: "expression/TSO-matching-view-tz", * > }], * > expressionInfos: [{ * > expression: `Text(ChangeTimeZone($feature.TimestampOffset_Field, GetEnvironment().timeZone), "M/D/Y, h:mm A ZZZZ")`, * > name: "TSO-matching-view-tz", * > }], * > content: [{ * > type: "fields" * > }] * > }; * > ``` * > ```js * > // ExpressionContent to append the MapView's current time zone suffix to a timestamp-offset field * > layer.popupTemplate = { * > title: "Display time zones", * > content: [{ * > type: "expression", * > expressionInfo: { * > expression: `return { * > type: "text", * > text: Text(ChangeTimeZone($feature.TimestampOffset_Field, GetEnvironment().timeZone), "M/D/Y, h:mm A ZZZZ") * > }` * > } * > }] * > }; * > ``` * > * > </details> * * @see [fieldFormat](https://developers.arcgis.com/javascript/latest/references/core/popup/FieldInfo/#fieldFormat) */ get format(): FieldInfoFormat | null | undefined; set format(value: FieldInfoFormatProperties | null | undefined); /** * A Boolean determining whether users can edit this field. * This is not applicable to Arcade expressions. * * @default true */ accessor isEditable: boolean; /** * A string containing the field alias. Not applicable to * Arcade expressions as the title is used instead. */ accessor label: string | null | undefined; /** * Used in a `one:many` or `many:many` relationship to compute the statistics * on the field to show in the popup. If the property is present, * must be one of the following values: */ accessor statisticType: "count" | "sum" | "min" | "max" | "avg" | "stddev" | "var" | null | undefined; /** * A string determining what type of input box editors see * when editing the field. Applies only to string fields. * This is not applicable to Arcade expressions. If this property * is present, it must be one of the following values: * * @default "text-box" */ stringFieldOption: StringFieldOption; /** * A string providing an editing hint for editors of the field. * This is not applicable to Arcade expressions. */ accessor tooltip: string | null | undefined; /** * Indicates whether the field is visible in the popup window. * * > [!WARNING] * > * > As of version 4.16, the default [Popup.defaultPopupTemplateEnabled](https://developers.arcgis.com/javascript/latest/references/core/widgets/Popup/#defaultPopupTemplateEnabled) * > has been improved to no longer display system fields that do not hold significant value, * > e.g. `Shape__Area` and `Shape__Length` are two fields that * > no longer display. * * @default true */ accessor visible: boolean; } declare const FieldInfoSuperclass: typeof JSONSupport & typeof ClonableMixin