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
Solved! Go to Solution.
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
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
@UndralBatsukh thank you so much. I have a question about your code. Is it possible to apply 'zoom to extent' on the filter?
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
}
});
});