Select to view content in your preferred language

Unselecting a graphic - how?

232
4
Jump to solution
08-13-2024 03:01 PM
SteveCole
Honored Contributor

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();
			  }
		  });	

 

 

 

0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Honored Contributor

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

 

View solution in original post

0 Kudos
4 Replies
ReneRubalcava
Honored Contributor

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

 

0 Kudos
SteveCole
Honored Contributor

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:

  1. Use the Sketch tool to add a point.
  2. Click anywhere in the map to deselect the graphic.
  3. Now click on the added point graphic to display the popup.
  4. Close the popup. The graphic remains selected.
0 Kudos
ReneRubalcava
Honored Contributor

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

 

0 Kudos
SteveCole
Honored Contributor

Thanks. That appears to be what I wanted. That works in my application. Until it does something else unintended. 😂

0 Kudos