Popup Element

Since version: 1.16

The popup element profile allows map authors to write expressions that return a dictionary representing either a rich text, fields table, or media (i.e. a chart or an image) popup element. The returned dictionary must follow the Web Map Specification for a popupElement. When the popup opens, the expression will execute using the feature's attributes as variables. The app executing the expression will render the popup element as defined by the expression.

Unlike the Popup profile, this profile allows popup authors to return multiple values within a single element.

Context

The following products implement this profile:

Spatial reference

The spatial reference of the map in which the expression executes determines the execution context's spatial reference.

Time zone

The time zone of the map in which the expression executes determines the execution context's default time zone.

Profile variables

Variable NameTypeDescriptionSince version
$featureFeatureProvides access to the attributes and geometry of the feature whose popup is to be displayed in the view.1.16
$layerFeatureSetA collection of features in the same layer as the $feature whose popup is displayed in the view.1.16
$mapFeatureSetCollectionA collection of layers in the same map as the $feature whose popup is displayed in the view. This value may be null in cases where a popup is not associated with a map.1.16
$datastoreFeatureSetCollectionA collection of layers in the same feature service or database as the $feature whose popup is displayed in the view.1.16
$userInputGeometryA geometry representing a user's input for a popup. Typically, this represents a location where the user clicked or tapped in a map to launch a popup. There may be cases where this value is a Point, an Extent, or null as popups are not always opened from map interaction. Therefore, it is advised to check the geometry type of this value before it is used.1.26
$graphKnowledgeGraphA knowledge graph associated with the feature. If no knowledge graph is available, the value will be null.1.26

Function bundles

Core | Geometry | Data Access | Portal Access | Knowledge Graph

Return types

Dictionary

See the Web Map Specification for popupElement for a list of properties required for constructing a valid popup element dictionary.

Example

Returns a table with the top three crimes in each block group.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var attributes = {};
var fieldInfos = [];

// Query the number of crimes that intersect a selected polygon
var crimes = Intersects($feature, FeatureSetByName($map,"San Diego crimes", ["desc_"]));

// Queries the count of crimes grouped by the "desc_" field
var stats = GroupBy(crimes, ["desc_"], [{ name: "total", expression: "1", statistic: "count" }]);

// Orders the results in descending order by the total count
// excludes crimes that don't have a classification
var topCrimes = Top(OrderBy(Filter(stats, "desc_ <> ''"), "total desc"), 3);

if(Count(topCrimes) == 0){
  return {
    type: "text",
    text: "No crimes committed in this area"
  };
}
for(var item in topCrimes){
  var num_crimes = item.total;
  var crimeType = item["desc_"];
  attributes[crimeType] = num_crimes;
  Push(fieldInfos, {
    fieldName: crimeType
  });
}

return {
  type: "fields",
  fieldInfos: fieldInfos,
  attributes: attributes
};

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