Feature Layer: Update Map with User Entered Definition Query

Discussion created by chaninlee on Mar 30, 2013
I am working with a feature layer and I understand how the featureLayer.setDefinitionExpression() can be used to filter and display the contents that match the definition query.  What I want to do is take the user input and set that as the definition query and update the map after the user presses a submit button.

Here's what I have so far.


      var map, featureLayer;
      function init() {
        map = new esri.Map("mapDiv", { 
          basemap: "streets",
          center: [-97.395, 37.537],
          zoom: 7
        dojo.connect(map, "onLoad", initOperationalLayer);
      function initOperationalLayer(map) {

        var infoTemplate = new esri.InfoTemplate("${state_name}", "Population (2000) ${pop2000}");
        var prodGas = "PROD_GAS='Yes' AND PROD_OIL='No'";
        "PROD_GAS='Yes' AND PROD_OIL='No'"
        featureLayer = new esri.layers.FeatureLayer("",{
          mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
          outFields: ["*"],
          infoTemplate: infoTemplate


I created the variable prodGas to set my definition query.  I thought if I wrote a function to update the prodGas variable that the map will update with the new definition query but that doesn't seem to be the case.  For now I just set the prodGas variable as "PROD_GAS='Yes' AND PROD_OIL='No'" because I couldn't get the definition query and map to update correctly.  Can somebody help me work through this problem?