Select to view content in your preferred language

4.28 New Features Widget not obeying view.popupEnabled

525
4
12-13-2023 12:01 AM
average_geo_97
New Contributor II

I'm using the new Features widget to create a custom selection experience. This involves a custom onClick handler to handle selection and setting view.popupEnabled to false. 

My custom view.on("click") handler performs a hit test, then adds only the first item in the hitTestResult to a list of features that we manage.

However, I noticed that when clicking on a location with multiple features, the Features Widget still shows multiple results. This suggests to me that the original onclick behavior is still happening, meaning that the Features Widget is not obeying view.popupEnabled = false.

Is there a way I could work around this?

Tags (1)
0 Kudos
4 Replies
LaurenBoyd
Esri Contributor

Hi @average_geo_97 -

The view.popupEnabled property only controls the popup on the view and doesn't control the behavior of the Features widget. If this is set to false, the popup will not show on view click.

If you would like to populate the Features widget with specific features and not all features in the view that are located at the click location, you can use the features property in the open method on the Features widget to add specific features. You could also populate the features property on the widget and then set the visible property to true.

Here's a codepen example showing how to use the features property with the open method: https://codepen.io/laurenb14/pen/mdvYGrJ?editors=1000

Hope this helps!

Lauren
0 Kudos
average_geo_97
New Contributor II

Hi Lauren, 

Thanks so much for the reply! I notice that in your codepen, you can display the popupTemplate of the feature by calling featuresWidget.open with location and features parameters. Somehow in my application, when I call featuresWidget.open with only these 2 arguments, the features widget is unable to display the popup correctly. Instead, I get a console message:

[esri.widgets.Feature.support.featureUtils]
The specified layer cannot be queried. The following fields will not be available.

 To perform a query to fetch the required fields from the layer, I need to set the fetchFeatures parameter to true as well. However, when fetchFeatures is true, it automatically retrieves all features at the click location, which is not what I want.

0 Kudos
LaurenBoyd
Esri Contributor

How do you have your data loaded into the map? Are you adding your data from a web map (like in my CodePen above) or are you adding your data using the FeatureLayer class? Seems that the fields might not be loaded based on the console message you are seeing.

If you're loading your data using feature layers, can you make sure the outFields property on the layer includes the fields participating in the popup template or set it to all fields using ['*']?

If the above doesn't work, would you be able to send an example CodePen reproducing the issue?

Lauren
0 Kudos
average_geo_97
New Contributor II

Is setting outFields to ['*'] required if we manually set the features on the Features/Popup widget? It is not required if using the default popup and view.popupEnabled = true, I'm assuming because the popup performs a query on the layer.

We initially had set outFields to ['*'] on all our layers, but removed it as it slows the loading of some layers quite significantly.

Edit: Is there any way to replicate the fetchFeatures behavior on a SceneLayer (without associated featurelayer)? I notice that with fetchFeatures set to true, the popup/features widget is able to query my SceneLayer to retrieve attributes on a feature. However, using the API I am unable to do the same as SceneLayers without associated feature layers do not support querying.

0 Kudos