Feature Layer vs Query Task

4105
1
02-11-2015 12:04 PM
PeterHunt3
New Contributor

I'm using ArcGIS Javascript API, and I need to query the GIS and show the results on the map.  Currently I have used a Query Task by specifying the layer,  the "where" statement,  graphic symbol, InfoTemplate etc. and it works well.  I'm wondering however whether I should be using a Feature Layer with a Definition Expression, rather than the Query Task.  Using a Feature Layer would enable the drawing information from the server to be used.  Also the symbol would show in the legend.  When is it better to use a Query Task rather then a Feature Layer?

0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Emeritus

Peter,

     Much of that is dependent on your full use case. Does the map already have that FeatureLayer added? If so then using FeatureLayer.queryFeatures may be a better route because:

Query features from the feature layer. Layer definition and time definition are honored. Whenever possible the feature layer will perform the query on the client.

Will you need to show the full feature layer in the map as well as distinguish the queried results differently form the rest of the features, or do you only want to see the queried features in the map?

You may want to look into adding the FeatureLayer to the map in selection mode "MODE_SELECTION" and the selectFeatures method, if you only want to see the results of the selection in the map.