Highlight features from map.allLayers

521
2
Jump to solution
01-27-2023 02:13 AM
Vakhtang_Zubiashvili
Occasional Contributor III

Hi folks,

I am selecting features from all layers on my map and now i want to highlight all selected features. I do it using this code:

 

let highlight;
map.allLayers.forEach(layer => {
            // Query all layers data
              if (layer.type === "feature" && layer.visible){
                        layer.queryFeatures(query)
                        .then((results) => {
                          const graphics = results.features;
                          // console.log(graphics);
                            // do something with query results
                            highlight = highlight(graphics);
                     })   
                }
            });

 

 

But i get error: Uncaught (in promise) TypeError: highlight is not a function;

How can i simply achive this?

 

Thanks

0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor

Highlight is a method on the LayerView, so you need a reference to the LayerView that your features come from.

https://developers.arcgis.com/javascript/latest/api-reference/esri-views-layers-FeatureLayerView.htm...

You get a reference to the LayerView for each layer using the view.whenLayerView method.

https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#whenLayerView

Then you can use the layerView to highlight the features you are interested in.

Here is one of a few samples that show how to use highlight

https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=widgets-feature-multiple...

View solution in original post

2 Replies
ReneRubalcava
Frequent Contributor

Highlight is a method on the LayerView, so you need a reference to the LayerView that your features come from.

https://developers.arcgis.com/javascript/latest/api-reference/esri-views-layers-FeatureLayerView.htm...

You get a reference to the LayerView for each layer using the view.whenLayerView method.

https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#whenLayerView

Then you can use the layerView to highlight the features you are interested in.

Here is one of a few samples that show how to use highlight

https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=widgets-feature-multiple...

Vakhtang_Zubiashvili
Occasional Contributor III

Thank you @ReneRubalcava , you helped me, awesome!

0 Kudos