Hi all, I'm fairly new to the world of the Javascript API, so I apologize if this is a very simple question.
I'm attempting to build out a simple form that filters data based on the users input. I've just been testing using samples of code I've found on the JS API site to see what is the best way to do this. The small sample I've made I'm attempting to just update the definitionexpression on the click event following (FeatureLayer | API Reference | ArcGIS API for JavaScript 4.8). However whenever I try to use this I keep getting the error "layer.setDefinitionExpression is not a function". Any advise about the error or a better way to do dynamic filtering based on a form. I've attached my sample code for anyone to assist with! Again, it's pretty dirty I'm just testing what I can do.
----------------------------------------------------------------------------------------------------------------------------------------------------------
const layer = new FeatureLayer({
url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0",
definitionExpression: "Sci_Name = 'Ulmus pumila'"
});
map.add(layer)
var filter = document.getElementById("button");
filter.addEventListener("click", function(event){
var newValue = "HEIGHT > 50";
layer.setDefinition
});
--------------------------------------------------------------------------------------------------------------------------------------------------------
Thanks!
Shawn.
Solved! Go to Solution.
You're mixing up syntax between 3.x and 4.x. In 4.x, it is
layer.definitionExpression = newValue;
You're mixing up syntax between 3.x and 4.x. In 4.x, it is
layer.definitionExpression = newValue;
Perfect thanks Ken! That was it.