Skip To ContentArcGIS for DevelopersSign In Dashboard
require(["esri/support/popupUtils"], function(popupUtils) { /* code goes here */ });
Object: esri/support/popupUtils
Since: ArcGIS API for JavaScript 4.16

Various utils for working with Popup widget functionality.

Method Overview

NameReturn TypeSummaryObject
FieldInfo[]

Creates an array of fieldInfo used for populating FieldsContent.

more details
more detailspopupUtils
FieldsContent

Creates fields content used for populating a PopupTemplate.

more details
more detailspopupUtils
PopupTemplate

Creates a popup template given the specified config information.

more details
more detailspopupUtils

Method Details

createFieldInfos(config, options){FieldInfo[]}

Creates an array of fieldInfo used for populating FieldsContent.

Parameters:

A configuration object containing properties for creating fieldInfo.

optional

Options for creating the PopupTemplate.

Returns:
TypeDescription
FieldInfo[]An array of FieldInfo content used to popuplate the FieldsContent, which in turn is used to popuplate 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(config, options){FieldsContent}

Creates fields content used for populating a PopupTemplate.

Parameters:

A configuration object containing properties for creating FieldsContent.

optional

Options for creating the PopupTemplate.

Returns:
TypeDescription
FieldsContentThefields content used to popuplate 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(config, options){PopupTemplate}

Creates a popup template given the specified config information.

Parameters:
config Config

A configuration object containing properties for creating a PopupTemplate.

optional

Options for creating the PopupTemplate.

Returns:
TypeDescription
PopupTemplateThe 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;

Type Definitions

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

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

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"
}];

API Reference search results

NameTypeModule
Loading...