This sample is similar to the Feature widget sample with the exception that this sample demonstrates docking the widget into a side panel. This is useful in circumstances where you may not necessarily want or need the associated feature's information to display directly within the map. It displays information based on the PopupTemplate using the Feature widget. The content of the PopupTemplate is saved within the referenced layer and makes use of custom text elements with chart media.
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
// Provide graphic and DOM container to a new instance of a Feature widgetconst feature = new Feature({
container:"feature-node",
graphic: graphic,
map: view.map,
spatialReference: view.spatialReference
});
// Use the promiseUtils.debounce method to ensure the pointer-move event// is not simultaneously invoked more than once at a timeconst debouncedUpdate = promiseUtils.debounce((event) => {
// Perform a hitTest on the View view.hitTest(event).then((event) => {
// Make sure graphic has a popupTemplateconst results = event.results.filter((result) => {
return result.graphic.layer.popupTemplate;
});
const result = results[0];
const newObjectId = result && result.graphic.attributes[fLayer.objectIdField];
if (!newObjectId) {
highlight && highlight.remove();
objectId = feature.graphic = null;
} elseif (objectId !== newObjectId) {
highlight && highlight.remove();
objectId = newObjectId;
feature.graphic = result.graphic;
highlight = layerView.highlight(result.graphic);
}
});
});
// Listen for the pointer-move event on the View// and make sure that function is not invoked more// than one at a timeview.on("pointer-move", (event) => {
debouncedUpdate(event).catch((err) => {
if (!promiseUtils.isAbortError(err)) {
throw err;
}
});
});