5

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);
});
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Feb 5, 2015 at 16:27
1
  • maybe try featureLayer.refresh(); if not, a simplified repro case pointing at public services would make it a lot easier to help debug. Commented Feb 7, 2015 at 4:50

2 Answers 2

1

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);
});
answered Feb 5, 2015 at 17:33
6
  • 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. Commented Feb 5, 2015 at 17:54
  • Is LEVEL_ a number or a string field? If string then it should be set as "LEVEL = '" + level + "'" Commented 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. Commented Feb 5, 2015 at 18:56
  • can to try "LEVEL_ = " + level.toString() Commented Feb 5, 2015 at 19:09
  • Still no change.. Commented Feb 5, 2015 at 19:14
1

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.

answered Jan 6, 2018 at 10:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.