Select to view content in your preferred language

[JSAPI] Limit Feature Layer by Query

3108
3
Jump to solution
08-10-2015 06:31 AM
KevinScalf
Deactivated User

Is there a way in the definition of a featureLayer via URL, to add some query string parameter to limit the returned results a feature layer and still function On Demand?

More detail: I have a feature layer hosted on a rest service that contains data from multiple lines in our system. I currently do this:

            featureLayer = new FeatureLayer(url, {

                mode: FeatureLayer.MODE_ONDEMAND,

                outFields: ["*"],

                visible: isVisible

            });

That works just fine, but it pulls data from every line and I really only want to view the data pertaining to one line at a time.

I would like to be able to do this:

          featureLayer = new FeatureLayer(url + querystring, {

                mode: FeatureLayer.MODE_ONDEMAND,

                outFields: ["*"],

                visible: isVisible

            });

I would like to add the query ("LINE_ID == ?") and still have it behave as it would in the first block of code where we pull the data On Demand as we're viewing the map.

Is there a way to accomplish this either on the API or Server side?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
PrevinWong1
Esri Contributor

If I understand your issue correctly, what you can do is use queryIds, to get the objects ids in the map extent, then on the call back of the queryIds, you can query for the actual result set.

something like

var queryparams = new Query();

queryparams.geometry = UserSuppliedGeom;

flayer.queryIds(queryparams, lang.hitch(this, function(objectIds) {

     //do something with certain Line Ids or

      var query = new Query();

      query.returnGeometry = false;

      query.outFields = ['*'];

      query.objectIds = objectIds;

      flayer.queryFeatures(query, lang.hitch(this, function(featureSet) {

          //do somthing with result set.

     }

}

View solution in original post

3 Replies
PrevinWong1
Esri Contributor

If I understand your issue correctly, what you can do is use queryIds, to get the objects ids in the map extent, then on the call back of the queryIds, you can query for the actual result set.

something like

var queryparams = new Query();

queryparams.geometry = UserSuppliedGeom;

flayer.queryIds(queryparams, lang.hitch(this, function(objectIds) {

     //do something with certain Line Ids or

      var query = new Query();

      query.returnGeometry = false;

      query.outFields = ['*'];

      query.objectIds = objectIds;

      flayer.queryFeatures(query, lang.hitch(this, function(featureSet) {

          //do somthing with result set.

     }

}

KevinScalf
Deactivated User

This is as close as I'm gonna get I think.

I would basically have to write my own version of the on_demand pull and use the query you stated there and hang it on the extent change event.

Thats better than nothing.

0 Kudos
KevinScalf
Deactivated User

One solution I've worked up in the mean time is have some logic on the graphic layer graphic_draw event and for every graphic do a check and hide it if its bad.

That doesn't do anything to help performance problems with pulling multiple lines but it at least hides data we don't want to see.

0 Kudos