Feature Component

This sample displays information based on the PopupTemplate using the Feature component. The Feature component can be used to display information normally found in the Popup without having to use the Popup itself.

How it works

A hitTest is performed on the map to get the features at the hovered location. The feature that is hovered over is highlighted and the Feature component is then used to display the information from the feature's popup template.

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
            // Perform a hitTest on the map component.
            const hitTest = await mapElement.hitTest(event, {
              include: featureLayer
            });
            // Confirm that the hitTest results contain a graphic with a popupTemplate.
            const results = hitTest.results.filter((result) => {
              return result.graphic.layer.popupTemplate;
            });
            // Get the first result from the hitTest and the objectId of the feature.
            const result = results[0];
            const newObjectId = result?.graphic.attributes[featureLayer.objectIdField];
            // If the objectId has changed, update the graphic and highlight.
            if (!newObjectId) {
              highlight?.remove();
              objectId = arcgisFeature.graphic = defaultGraphic;
            } else if (objectId !== newObjectId) {
              highlight?.remove();
              objectId = newObjectId;
              arcgisFeature.graphic = result.graphic;
              highlight = layerView.highlight(result.graphic);
            }

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