require(["esri/support/popupUtils"], (popupUtils) => { /* code goes here */ });
import * as popupUtils from "@arcgis/core/support/popupUtils.js";
esri/support/popupUtils
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
-
Creates an array of fieldInfo used for populating FieldsContent.
Starting with version 4.28,
date
fields are formatted using theshort-date-short-time
preset dateFormat rather thanlong-month-day-year
in field infos created with thecreateFieldInfos()
method. For example, previously a date that may have appeared as"December 30, 1997"
will now appear as"12/30/1997 6:00 PM"
.Parametersconfig FieldInfosConfigA configuration object containing properties for creating fieldInfo.
options CreatePopupTemplateOptionsoptionalOptions for creating the PopupTemplate.
ReturnsType 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
andShape__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
createFieldsContent(config, options){FieldsContent}
-
Creates fields content used for populating a PopupTemplate.
Starting with version 4.28,
date
fields are formatted using theshort-date-short-time
preset dateFormat rather thanlong-month-day-year
in FieldsContent created with thecreateFieldsContent()
method. For example, previously a date that may have appeared as"December 30, 1997"
will now appear as"12/30/1997 6:00 PM"
.Parametersconfig FieldInfosConfigA configuration object containing properties for creating FieldsContent.
options CreatePopupTemplateOptionsoptionalOptions for creating the PopupTemplate.
ReturnsType Description FieldsContent The fields
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
createPopupTemplate(config, options){PopupTemplate}
-
Creates a popup template given the specified config information.
Starting with version 4.28,
date
fields are formatted using theshort-date-short-time
preset dateFormat rather thanlong-month-day-year
in popup templates created with thecreatePopupTemplate()
method. For example, previously a date that may have appeared as"December 30, 1997"
will now appear as"12/30/1997 6:00 PM"
.Parametersconfig ConfigA configuration object containing properties for creating a PopupTemplate.
options CreatePopupTemplateOptionsoptionalOptions for creating the PopupTemplate.
ReturnsType 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
createPopupTemplateForFeatureReduction(params){PopupTemplate}
Since: ArcGIS Maps SDK for JavaScript 4.25popupUtils 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.
ParametersSpecificationparams ObjectParameters for creating a feature reduction popup template.
SpecificationfeatureReduction FeatureReductionBinning|FeatureReductionClusterThe FeatureReduction object for which to create a default popup template.
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 StringoptionalThe title to display in the popup template.
ReturnsType Description PopupTemplate The popup template, or null
if no AggregateFields are set on the feature reduction object.Exampleconst popupTemplate = popupUtils.createPopupTemplateForFeatureReduction(layer); layer.featureReduction.popupTemplate = popupTemplate;
Type Definitions
-
A configuration object containing properties for creating a PopupTemplate.
- Properties
-
displayField String
The display field.
title StringThe title for the PopupTemplate.
editFieldsInfo EditFieldsInfoThe fields that record who adds or edits data in the feature service and when the edit is made.
The fields displayed within the PopupTemplate.
objectIdField StringThe 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" };
-
Options for creating the PopupTemplate.
- Properties
-
optional An array of field types to ignore when creating the popup. System fields such as
Shape_Area
andShape_length
, in addition togeometry
,blob
,raster
,guid
andxml
field types are automatically ignored.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"]) };
-
A configuration object containing field properties for creating FieldsContent for a PopupTemplate.
- Properties
-
editFieldsInfo EditFieldsInfo
The fields that record who adds or edits data in the feature service and when the edit is made.
The fields displayed within the PopupTemplate.
objectIdField StringThe 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" }];