Remove layer definitions expression after searchWidget.on("select-result") - API 4.7

585
1
06-05-2018 09:09 AM
MathewMullan1
New Contributor

Using API 4.7

When my web map is loaded, I'm handling the loading of the feature layers and filtering the graphics displayed with the following:

   webMapView.on("layerview-create", function(event) {

      if (layerTitle === "Toxic Release")

      {
         layer.definitionExpression = "State_code = '" + state + "'";
      }      
      else if (layerTitle === "Region 3 Boundary") {
         layer.definitionExpression = "STUSPS = '" + state + "'";
      }
      else {
         layer.definitionExpression = "STATE = '" + state + "'";
      }
      return function queryLayerData() {
      var layerQuery = layer.createQuery();
      return layer.queryFeatures(layerQuery).then(function (response) {
         layerGeometries = response.features.map(function (feature) {
         return feature.geometry;
      });
      return layerGeometries;
     });
}
}

When an item is searched using the Search Widget, I want the feature layer to show the feature but there are cases when the feature is not show because of the filtering above. 

How would I remove the filtering that takes place during the layerview-create process?

0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Emeritus

Mathew,

   You would have to loop through the layerViews collection and get the layer property from the LayerView and set the definitionExpression  to an empty string.

0 Kudos