How to get extent of feature layer after setDefinitionExpression?

2809
1
08-25-2015 02:33 PM
CharlesGage
New Contributor

I have a Feature Layer where I have successfully got the features using the "setDefinitionExpression()", but now I want to be able to Zoom to the extent of the features from this definition expression.   Any ideas on how I could do this?

Thanks

Tags (1)
0 Kudos
1 Reply
KellyHutchins
Esri Frequent Contributor

You can use esri/graphicsUtils graphicsExtent method to get the extent of the selected graphics. Here's a code snippet that shows this:

      var layer = new FeatureLayer("http://services5.arcgis.com/cuQhNeNcUrgLmYGD/arcgis/rest/services/JT/FeatureServer/0",{
        infoTemplate:template,
        outFields:["*"]
      });


      map.addLayer(layer);
      on.once(layer, "update-end", function(){
        var extent = graphicsUtils.graphicsExtent(layer.graphics);
        map.setExtent(extent);
      });
      layer.setDefinitionExpression("Tour_Name='NSYNC_in_Concert'")
0 Kudos