Skip to content

It is possible to customize Popup and PopupTemplate actions per feature attribute.

This sample demonstrates how to format custom actions specifically per selected feature using a Popup and a PopupTemplate. Although actions can be added via the actions property on either the Popup or PopupTemplate, the actions in this sample are specifically set within the featurelayer's popupTemplate.

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
        actions: [
          {
            id: "find-brewery",
            icon: "web",
            title: "Brewery Info",
          },
        ],

Actions are styled by either using the icon or image property. If using icon, you must use a Calcite icon. If using image, you must provide a valid URL to an image that will be used as a background-image for the action. In this specific example, a Calcite icon called web is used.

How it works

First, watch for the Popup's selectedFeature property. Next, set the action's visible property to true if the feature's website_url attribute isn't null, otherwise set it to false.

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
      // Watch for when features are selected
      reactiveUtils.watch(
        () => popupComponent.selectedFeature,
        (graphic) => {
          if (graphic) {
            // Set the action's visible property to true if the 'website' field value is not null, otherwise set it to false
            const graphicTemplate = graphic.getEffectivePopupTemplate();
            graphicTemplate.actions.items[0].visible = graphic.attributes.website_url
              ? true
              : false;
          }
        },
      );

The Popup's arcgisTriggerAction is watched using reactiveUtils.on. If the user clicked on the custom action with the ID of find-brewery, the code grabs the selected feature's website_url attribute. If the value is not null, it opens up a new browser window with the URL stored in the website_url attribute.

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
      // Watch for the trigger-action event on the popup
      reactiveUtils.on(
        () => popupComponent,
        "arcgisTriggerAction",
        (event) => {
          if (event.detail.action.id === "find-brewery") {
            const attributes = popupComponent.selectedFeature.attributes;
            // Get the 'website' field attribute
            const info = attributes.website_url;
            // Make sure the 'website' field value is not null
            if (info) {
              // Open up a new browser using the URL value in the 'website' field
              window.open(info.trim());
            }
          }
        },
      );

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