Feature layer definition expression error

2003
3
07-05-2018 04:33 PM
City_ofVernonia
New Contributor

If a feature layer is created with a definition expression and then gets set to null it throws an error and essentially snapshots the max number features the service supports in one request and that's all the features which are displayed with no more requests on extent change. Based on the error it looks like the creating the layer with a definition expression does a snapshot thing instead of on demand.

If created without a definition expression, the layer can be set to null or any other expression and works fine.

Not sure if this is a bug or if there is another way to clear the definition expression to avoid this error. I don't see any prop like 3.x mode.

// EXAMPLE ONE
// create layer with definitionExpression
const layer = new FeatureLayer({
  url: 'https://service/url',
  definitionExpression: 'ACTIVE = 1'
});

layer.definitionExpression = null;
// first n number of features shown and throws error
// [esri.layers.graphics.controllers.SnapshotController] Feature limit exceeded on layer " Permits ". Not all features are shown.

layer.definitionExpression = 'ACTIVE = 1';
// works as expected

layer.definitionExpression = 'ACTIVE = 0';
// works as expected

layer.definitionExpression = null;
// same error as above

//EXAMPLE TWO
// create layer without definitionExpression
const layer = new FeatureLayer({
  url: 'https://service/url'
});

layer.definitionExpression = null;
// works as expected

layer.definitionExpression = 'ACTIVE = 1';
// works as expected

layer.definitionExpression = null;
// works as expected

layer.definitionExpression = 'ACTIVE = 0';
// works as expected
0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus

City of Vernonia,

   This sample works fine for me. I set the definitionExpression in the constructor and then set it to null using a timeout and then again in a timeout to another definitionExpression.

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>Intro to FeatureLayer - 4.8</title>

  <link rel="stylesheet" href="https://js.arcgis.com/4.7/esri/css/main.css">
  <script src="https://js.arcgis.com/4.7/"></script>

  <style>
    html,
    body,
    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  </style>

  <script>
    require([
        "esri/Map",
        "esri/views/MapView",

        "esri/layers/FeatureLayer",

        "dojo/domReady!"
      ],
      function(
        Map, MapView,
        FeatureLayer
      ) {

        var map = new Map({
          basemap: "hybrid"
        });

        var view = new MapView({
          container: "viewDiv",
          map: map,

          extent: { // autocasts as new Extent()
            xmin: -9177811,
            ymin: 4247000,
            xmax: -9176791,
            ymax: 4247784,
            spatialReference: 102100
          }
        });

        /********************
         * Add feature layer
         ********************/

        // Carbon storage of trees in Warren Wilson College.
        var featureLayer = new FeatureLayer({
          url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0",
          definitionExpression: "Status = 'U'"
        });

        map.add(featureLayer);
        
        setTimeout(function(){
          featureLayer.definitionExpression = null;
          setTimeout(function(){
            featureLayer.definitionExpression = "Status = 'P'";
          }, 5000)
        }, 5000)

      });
  </script>
</head>

<body>
  <div id="viewDiv"></div>
</body>

</html>
City_ofVernonia
New Contributor

Good morning.

After a little more investigation I realized if the initial definition expression includes fewer features than the max feature count the layer is in snapshot mode, resulting the snapshot error when the api tries to load all features. A definition expression which has a greater number of features than the max feature count does not have this issue.

Seems like a bug to me. I'm sure it does so for performance, but the layer should be able to handle a scenario where the initial definition expression has very few features but the layer could include tens of thousands of features or more if the definition expression changed or was set to null.

Thanks.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Sounds like a bug that needs to be reported to esri tech support.

0 Kudos