popupUtils

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

Various utils for working with Popup widget functionality.

Method Overview

Name Return Type Summary Object

Creates an array of fieldInfo used for populating FieldsContent.

popupUtils

Creates fields content used for populating a PopupTemplate.

popupUtils

Creates a popup template given the specified config information.

popupUtils

Creates a default popup template to use for FeatureReductionBinning or FeatureReductionCluster visualizations.

popupUtils

Method Details

createFieldInfos

Method
createFieldInfos(config, options){FieldInfo[]}

Creates an array of fieldInfo used for populating FieldsContent.

Starting with version 4.28, date fields are formatted using the short-date-short-time preset dateFormat rather than long-month-day-year in field infos created with the createFieldInfos() method. For example, previously a date that may have appeared as "December 30, 1997" will now appear as "12/30/1997 6:00 PM".

Parameters

A configuration object containing properties for creating fieldInfo.

optional

Options for creating the PopupTemplate.

Returns
Type Description
FieldInfo[] An array of FieldInfo content used to populate the FieldsContent, which in turn is used to populate the PopupTemplate. By default, system fields, e.g. Shape__Area and Shape__Length, OID, etc, do not display.
Example
// Sets the configuration for the popup template.
// Each object in this array is autocast as an instance of esri/layers/support/Field
const fields = [{
  name: "NAME",
  alias: "Name",
  type: "string"
}, {
  name: "County",
  alias: "County",
  type: "string"
}, {
  name: "ALAND",
  alias: "Land",
  type: "double"
}];

// This sets the options to ignore all fields of "date" type and sets two visible fields
const templateOptions = {
  ignoreFieldTypes: ["date"],
  visibleFieldNames: new Set(["NAME", "ALAND"])
};

// Set the FieldInfo
const fieldsConfig = {fields: fields};

// Create the FieldInfos
const fieldInfos = popupUtils.createFieldInfos(fieldsConfig, templateOptions);

// Sets the FieldsContent
const fieldsContent = new FieldsContent({
  fieldInfos: fieldInfos
});

// Create the template and pass in the fields content
const template = {
  title: "County Land",
  outFields: ["*"],
  content: [fieldsContent]
  };

// Set the feature layer's popup template
featureLayer.popupTemplate = template;

createFieldsContent

Method
createFieldsContent(config, options){FieldsContent}

Creates fields content used for populating a PopupTemplate.

Starting with version 4.28, date fields are formatted using the short-date-short-time preset dateFormat rather than long-month-day-year in FieldsContent created with the createFieldsContent() method. For example, previously a date that may have appeared as "December 30, 1997" will now appear as "12/30/1997 6:00 PM".

Parameters

A configuration object containing properties for creating FieldsContent.

optional

Options for creating the PopupTemplate.

Returns
Type Description
FieldsContent Thefields content used to populate the PopupTemplate. This content contains an array of FieldInfo.
Example
// Sets the configuration for the popup template.
// Each object in this array is autocast as an instance of esri/layers/support/Field
const fields = [{
  name: "NAME",
  alias: "Name",
  type: "string"
}, {
  name: "County",
  alias: "County",
  type: "string"
}, {
  name: "ALAND",
  alias: "Land",
  type: "double"
}];

// This sets the options to ignore all fields of "date" type and sets two visible fields
const templateOptions = {
  ignoreFieldTypes: ["date"],
  visibleFieldNames: new Set(["NAME", "ALAND"])
};

// Set the FieldInfo
const fieldsConfig = {fields: fields};

// Create the Fields Content
const fieldsContent = popupUtils.createFieldsContent(fieldsConfig, templateOptions);

// Create the template and pass in the fields content
const template = {
  title: "County Land",
  outFields: ["*"],
  content: [fieldsContent]
  };

// Set the feature layer's popup template
featureLayer.popupTemplate = template;

createPopupTemplate

Method
createPopupTemplate(config, options){PopupTemplate}

Creates a popup template given the specified config information.

Starting with version 4.28, date fields are formatted using the short-date-short-time preset dateFormat rather than long-month-day-year in popup templates created with the createPopupTemplate() method. For example, previously a date that may have appeared as "December 30, 1997" will now appear as "12/30/1997 6:00 PM".

Parameters
config Config

A configuration object containing properties for creating a PopupTemplate.

optional

Options for creating the PopupTemplate.

Returns
Type Description
PopupTemplate The popup template, or null if no fields are set.
Example
// Sets the configuration for the popup template.
// Each object in this array is autocast as an instance of esri/layers/support/Field
const fields = [{
  name: "NAME",
  alias: "Name",
  type: "string"
}, {
  name: "County",
  alias: "County",
  type: "string"
}, {
  name: "ALAND",
  alias: "Land",
  type: "double"
}];

const config = {
  displayField: "County",
  fields: fields,
  title: "County land"
};

// This sets the options to ignore all fields of "date" type and sets two visible fields
const templateOptions = {
  ignoreFieldTypes: ["date"],
  visibleFieldNames: new Set(["NAME", "ALAND"])
};

const template = popupUtils.createPopupTemplate(config, templateOptions);
featureLayer.popupTemplate = template;

createPopupTemplateForFeatureReduction

Method
createPopupTemplateForFeatureReduction(params){PopupTemplate}
Since: ArcGIS Maps SDK for JavaScript 4.25 popupUtils since 4.16, createPopupTemplateForFeatureReduction added at 4.25.

Creates a default popup template to use for FeatureReductionBinning or FeatureReductionCluster visualizations. The template will consist of a list of all the aggregate fields defined in the featureReduction property of the layer.

Parameters
Specification
params Object

Parameters for creating a feature reduction popup template.

Specification

The FeatureReduction object for which to create a default popup template.

fields Field[]
optional

The fields of the layer aggregated during the feature reduction process. These should correspond to any fields used in the definition of the aggregate fields of the feature reduction instance provided to this function.

title String
optional

The title to display in the popup template.

Returns
Type Description
PopupTemplate The popup template, or null if no AggregateFields are set on the feature reduction object.
Example
const popupTemplate = popupUtils.createPopupTemplateForFeatureReduction(layer);
layer.featureReduction.popupTemplate = popupTemplate;

Type Definitions

Config

Type Definition
Config

A configuration object containing properties for creating a PopupTemplate.

Properties
displayField String
optional

The display field.

title String

The title for the PopupTemplate.

editFieldsInfo EditFieldsInfo
optional

The fields that record who adds or edits data in the feature service and when the edit is made.

fields Field[]

The fields displayed within the PopupTemplate.

objectIdField String
optional

The object id field.

Example
// Sets the configuration for the popup template.
// Each object in this array is autocast as an instance of esri/layers/support/Field
const fields = [{
  name: "NAME",
  alias: "Name",
  type: "string"
}, {
  name: "County",
  alias: "County",
  type: "string"
}, {
  name: "ALAND",
  alias: "Land",
  type: "double"
}];

const config = {
  displayField: "County",
  fields: fields,
  title: "County land"
};

CreatePopupTemplateOptions

Type Definition
CreatePopupTemplateOptions

Options for creating the PopupTemplate.

Properties
ignoreFieldTypes String[]
optional

An array of field types to ignore when creating the popup. System fields such as Shape_Area and Shape_length, in addition to geometry, blob, raster, guid and xml field types are automatically ignored.

visibleFieldNames Set<string>
optional

An array of field names set to be visible within the PopupTemplate.

Example
// This sets the options to ignore all fields of "date" type and sets two visible fields
const templateOptions = {
  ignoreFieldTypes: ["date"],
  visibleFieldNames: new Set(["NAME", "ALAND"])
};

FieldInfosConfig

Type Definition
FieldInfosConfig

A configuration object containing field properties for creating FieldsContent for a PopupTemplate.

Properties
editFieldsInfo EditFieldsInfo
optional

The fields that record who adds or edits data in the feature service and when the edit is made.

fields Field[]

The fields displayed within the PopupTemplate.

objectIdField String
optional

The object id field.

Example
// Sets the configuration for the popup template.
// Each object in this array is autocast as an instance of esri/layers/support/Field
const fieldsConfig = [{
  name: "NAME",
  alias: "Name",
  type: "string"
}, {
  name: "County",
  alias: "County",
  type: "string"
}, {
  name: "ALAND",
  alias: "Land",
  type: "double"
}];

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