This sample displays information based on the PopupTemplate using the Feature widget. You can use this widget to display information normally found in the Popup without having to use the Popup itself. You can also use this information in a custom widget or other parts of your application.
// Provide graphic to a new instance of a Feature widget
const feature = new Feature({
graphic: graphic,
map: view.map,
spatialReference: view.spatialReference
});
view.ui.add(feature, "bottom-left");
view.whenLayerView(fLayer).then((layerView) => {
let highlight;
let objectId;
const debouncedUpdate = promiseUtils.debounce(async (event) => {
// Perform a hitTest on the View
const hitTest = await view.hitTest(event, { include: fLayer });
// Make sure graphic has a popupTemplate
const results = hitTest.results.filter((result) => {
return result.graphic.layer.popupTemplate;
});
const result = results[0];
const newObjectId = result?.graphic.attributes[fLayer.objectIdField];
if (!newObjectId) {
highlight?.remove();
objectId = feature.graphic = null;
} else if (objectId !== newObjectId) {
highlight?.remove();
objectId = newObjectId;
feature.graphic = result.graphic;
highlight = layerView.highlight(result.graphic);
}
});
// Listen for the pointer-move event on the View
view.on("pointer-move", (event) => {
debouncedUpdate(event).catch((err) => {
if (!promiseUtils.isAbortError(err)) {
throw err;
}
});
});