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);
});
1
  • maybe try featureLayer.refresh(); if not, a simplified repro case pointing at public services would make it a lot easier to help debug. Feb 7 '15 at 4:50
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);

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.