Select to view content in your preferred language

Changing definitionExpression doesn't work

4944
15
Jump to solution
06-07-2016 01:41 AM
MohamedHamoud
Deactivated User

definitionExpression attribute of FeatureLayer works fine when the application is loaded, but when I click a button that changes the definitionExpression attribute of the layer, the displayed features disappear from the map but I don't see the new features based on the new definitionExpression, although the attribute is changed.

The code I am using:

 
  var buildingsLyr = new FeatureLayer({
      url: "myURL",
      id: "BuildingsBM",
      renderer: renderer,
      popupTemplate: {
      title: "{ID}",
      content: "{*}"
    },
    outFields: ["ID", "Use", "Z"],
    definitionExpression: "Sector = 'S1'", // show only buildings within this sector
  });

  map = new Map({
    basemap: "streets",
    layers: [buildingsLyr]
  });

  view = new SceneView({
    container: "viewDiv",
    map: map
   ,
   camera: {
      position: [54, 24, 30000],
      heading: 0,
      tilt: 35
    }
  });

// on button click, change the         definitionExpression   

  on(document.getElementById("btnLocate"), "click", function (e) {
     
      buildingsLyr.definitionExpression = "Sector = 'S2'"
  });
0 Kudos
15 Replies
FC_Basson
MVP Regular Contributor

Here's an updated working fiddle :Edit fiddle - JSFiddle

0 Kudos
MohamedHamoud
Deactivated User

Thank you. But still not workingfor me.

It works only if I clicked the button while the buildings are being loaded. But if I click the button after all buildings are completed loding then all buildings disappears.

0 Kudos
FC_Basson
MVP Regular Contributor

Funny enough, if you set the layer definition expression through the browser console, then the button click works afterwards.

0 Kudos
FC_Basson
MVP Regular Contributor

Hi Mohamed.  Take a look at this fiddle: Edit fiddle - JSFiddle .  I've added buttons to increase and decrease the building elevation. I have to agree with you that the behaviour is "buggy".  I also suspect that it might have something to do with the maximum feature count provided by the REST endpoint (2000).

MohamedHamoud
Deactivated User

Dear FC Basson,

Thank you very much for your help.

I tried your nice last fiddle and found that on some clicks the result is as expected, and on others it is not.

I hope that esri's java script API team to look at this issue and fix it.

0 Kudos
FC_Basson
MVP Regular Contributor

No problem.  I think the 4.1 release will include some major improvements.

0 Kudos