How to set extent of the map as per feature definition

3744
4
Jump to solution
05-19-2016 04:10 AM
SatyanarayanaNarmala
New Contributor III

Hi,

I have a state layer in which counties exists. i have definied the layer by which the layer only showing the counties existing in a particular state as below. but how can make this defined state to be as a map extent.

var featureLayer1 = new FeatureLayer("XYZ",{

          mode: FeatureLayer.MODE_ONDEMAND,

          outFields: ["*"],

        //minScale : 800000,

        //maxScale : 0,

          infoTemplate: template

        });

       

        featureLayer1.setDefinitionExpression("sde.sde.TS_Const.dname = '" + distname + "'");

0 Kudos
1 Solution

Accepted Solutions
FC_Basson
MVP Regular Contributor

Once the featureLayer is loaded and the definition expression is defined, you can zoom to the graphics with:

map.setExtent(esri.graphicsExtent(featureLayer.graphics));

View solution in original post

4 Replies
FC_Basson
MVP Regular Contributor

Once the featureLayer is loaded and the definition expression is defined, you can zoom to the graphics with:

map.setExtent(esri.graphicsExtent(featureLayer.graphics));

FC_Basson
MVP Regular Contributor

But this approach requires the featureLayer graphics to be visible in the current map extent.

0 Kudos
FC_Basson
MVP Regular Contributor

The best option would be to get the extent of the definition expression features with the featureLayer queryExtent function after load:

featureLayer.on('load', function(){         
   var query = new esri.tasks.Query();
   query.where = "sde.sde.TS_Const.dname = '" + distname + "'";
   featureLayer.queryExtent(query,function(result){
      map.setExtent(result.extent);
   })
})
ChrisSmith7
Frequent Contributor

Please note, this does not work if your feature layer is hosted in ArcGIS Server, unless it is v10.3.1+:

Get the extent of features that satisfy the input query. The count of features that satisfy the input query is returned as well. This is valid only for hosted feature services on arcgis.com and for ArcGIS Server 10.3.1 and later. (Added at v3.9)

0 Kudos