I'm trying to set a definition expression according to a user-selected value from a drop down menu, but I can't get the map to update the feature layers according to the expression. The user is able to click the drop down and select the values, but nothing happens when they click one.
HTML:
<select id="level" name="level">
<option value="" selected="selected">Select Building Level</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
JS:
//creates and adds feature layers to map
var generalIssuePoints = new FeatureLayer(".../FeatureServer/0", {
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"]
});
var firePullPoints = new FeatureLayer(".../FeatureServer/1",{
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"]
});
map.addLayers([generalIssuePoints, firePullPoints]);
//handles drop-down change event
on(dom.byId("level"), "change", function(e) {
var level = e.target.value;
var definitionExpression = "LEVEL_ = " + level;
//sets definition expression
generalIssuePoints.setDefinitionExpression(definitionExpression);
firePullPoints.setDefinitionExpression(definitionExpression);
});
-
maybe try featureLayer.refresh(); if not, a simplified repro case pointing at public services would make it a lot easier to help debug.john gravois– john gravois2015年02月07日 04:50:33 +00:00Commented Feb 7, 2015 at 4:50
2 Answers 2
The definition expression needs to be set in the change handler
//handles drop-down change event
on(dom.byId("level"), "change", function(e) {
var level = e.target.value;
var definitionExpression = "LEVEL_ = " + level;
//sets definition expression
generalIssuePoints.setDefinitionExpression(definitionExpression);
firePullPoints.setDefinitionExpression(definitionExpression);
});
-
Apologies, I did have that put inside the change handler, I just made a mistake copy/pasting it over to the post. I edited my question to fix this.jcusick– jcusick2015年02月05日 17:54:18 +00:00Commented Feb 5, 2015 at 17:54
-
Is LEVEL_ a number or a string field? If string then it should be set as "LEVEL = '" + level + "'"Aamir Suleman– Aamir Suleman2015年02月05日 18:20:56 +00:00Commented Feb 5, 2015 at 18:20
-
It's a long int. I've gotten the definition expression to work by hard coding ..."LEVEL_ = 1" outside of the change handler before the layers are added to the map, but can't seem to figure out what's going wrong inside of the change event.jcusick– jcusick2015年02月05日 18:56:26 +00:00Commented Feb 5, 2015 at 18:56
-
can to try "LEVEL_ = " + level.toString()Aamir Suleman– Aamir Suleman2015年02月05日 19:09:06 +00:00Commented Feb 5, 2015 at 19:09
-
I cannot see any problems, even i am using the same approach.
on(dom.byId("select_type"), "change", function(e){
var type = e.target.value;
myFeatureLayer.setDefinitionExpression("Type = '"+type+"'");
});
This works fine.