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 hit
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.
// 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);
}