Select to view content in your preferred language

Applying Filter to GroupLayers in the layerlist

1149
3
Jump to solution
10-11-2022 06:29 AM
TheGamer
Regular Contributor

I'm new to Javascript, so please bare with me.

I have created a similar layer list (https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=widgets-layerlist-action...) but instead of having 1 group layer, I have several group layers, each containing multiple layers. All the layers being used contain a common field called CSDNAME. I was wondering if there is a way to create a filter ( https://developers.arcgis.com/javascript/latest/sample-code/featurefilter-attributes/) that would filter out all the layers at once, and when toggling between different group layers and layers, the filter would be applied.

@RobertScheitlin__GISP @UndralBatsukh 

0 Kudos
1 Solution

Accepted Solutions
UndralBatsukh
Esri Regular Contributor

Hi there, 

The FeatureFilter sample you referenced can only be used for feature based layers like FeatureLayer, CSVLayer, GeoJSONLayer etc. I created a simple test app that filters FeatureLayersViews based on same field names. In the app, I am only checking if the layer type is feature and set the filter. You should probably add more checks to make sure you are getting the right FeaturelayerViews. 

 

https://codepen.io/U_B_U/pen/QWrzyeQ?editors=100

 

View solution in original post

3 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

The FeatureFilter sample you referenced can only be used for feature based layers like FeatureLayer, CSVLayer, GeoJSONLayer etc. I created a simple test app that filters FeatureLayersViews based on same field names. In the app, I am only checking if the layer type is feature and set the filter. You should probably add more checks to make sure you are getting the right FeaturelayerViews. 

 

https://codepen.io/U_B_U/pen/QWrzyeQ?editors=100

 

TheGamer
Regular Contributor

@UndralBatsukh thank you so much. I have a question about your code. Is it possible to apply 'zoom to extent' on the filter?

0 Kudos
UndralBatsukh
Esri Regular Contributor

Popups will show for visible features on the map and you can zoom to an extent based on the filter. You need add that logic after you apply the filter. 

  document.getElementById("statesFIPS").addEventListener("change", () => {
view.allLayerViews.forEach((lv) => {
  if (lv.layer.type === "feature") {
    lv.filter = {
      where: "STATE_FIPS = '" +
       document.getElementById("statesFIPS").value +"'"
     };
     // ZOOM HERE       
  }
});
        });