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.
<script>
dojo.require("esri.map");
dojo.require("esri.layers.FeatureLayer");
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("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer/1",{
mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
outFields: ["*"],
infoTemplate: infoTemplate
});
map.addLayer(featureLayer);
map.infoWindow.resize(155,75);
featureLayer.setDefinitionExpression(prodGas);
}
dojo.ready(init);
</script>
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?