I've spent far too much time today trying to figure this out. In the 4.X API, how do you unselect a selected graphic? My specific issue is with a popup on a graphicsLayer where the graphic is not unselected when the popup is closed. FWIW, this would be my relevant code:
// Search for graphics at the clicked location
theView.hitTest(screenPoint,{include:theGLayer}).then(function (response) {
if (response.results.length) {
var theContent = app.plmf.graphicsLayerContent(response.results[0].graphic);
var theTitle = "User Defined Project";
theView.openPopup({title:theTitle, content:theContent, location: event.mapPoint});
//}
}
});
});
//Unselect the interactive project when the popup is closed
reactiveUtils.watch(
// getValue function
() => theView.popup.visible,
// callback
(visible) => {
if (visible == true) {
//Do Nothing
} else {
console.log('The popup is closed');
theView.popup.clear();
}
});
Solved! Go to Solution.
Ok, that's a little different. That's not a popup selection, that is the sketch selection because you are interacting with the sketch graphics layer. You can call cancel() on sketch to clear it when you close the popup.
https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch.html#cancel
Looking at this sample here, if you call view.closePopup() the highlight is cleared.
https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=popup-editaction
Hey Rene, thanks for responding. That sample works great for FeatureLayers but I'm dealing with a GraphicsLayer. Here's a CodePen using the Sketch Widget sample as a base:
https://codepen.io/evtguy/pen/xxoPorp
I've tried my best to modify the sample to reflect the code in my actual application. Once you open the CodePen, here's what to do:
Ok, that's a little different. That's not a popup selection, that is the sketch selection because you are interacting with the sketch graphics layer. You can call cancel() on sketch to clear it when you close the popup.
https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch.html#cancel
Thanks. That appears to be what I wanted. That works in my application. Until it does something else unintended. 😂