queryFeatures Client Vs. Server request

1113
2
Jump to solution
05-17-2012 11:15 AM
SeanHarkins
New Contributor III
In the documentation for FeatureLayer, the description for the queryFeatures method states that "Whenever possible the feature layer will perform the query on the client."  I'd assume that when the mode for the FeatureLayer is set to MODE_SNAPSHOT that all queryFeatures operations would occur on the client and no new request would be made to the server.  I've tried several different tests and all of them seem to generate a new request back to the server when a query is made.  Can someone shed some light on the details of what constitutes "Whenever possible".  I have a client with some network latency issues who is trying to reduce the overall number of asynchronous requests their application is generating and it would help to better understand the FeatureLayer behavior.  I've included a small sample page below which demonstrates new requests to the server being generated for each queryFeatures operation.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html>   <head>     <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>     <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />     <!--The viewport meta tag is used to improve the presentation and behavior of the samples        on iOS devices-->     <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>     <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.8/js/dojo/dijit/themes/claro/claro.css">          <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.8"></script>          <script type="text/javascript">       dojo.require("esri.map");       dojo.require("esri.tasks.query");       dojo.require("esri.layers.FeatureLayer");        var fireStations;       function init() {         var startExtent = new esri.geometry.Extent(-85.8132362723161,38.1612613907511,-85.6422584745839,38.2706997066712, new esri.SpatialReference({wkid:4326}) );         var map = new esri.Map("mapDiv", { extent: esri.geometry.geographicToWebMercator(startExtent) });         var streetMap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");         map.addLayer(streetMap);          fireStations = new esri.layers.FeatureLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_PublicSafety_Louisville/MapServer/1",           {mode: esri.layers.FeatureLayer.MODE_ONDEMAND,           outFields: ["*"]}         );         map.addLayer(fireStations);          dojo.connect(fireStations, "onDblClick", queryFeatureLayerAttribute);         dojo.connect(map, "onLoad", function () {             map.disableDoubleClickZoom();         });                }        function queryFeatureLayerAttribute(event) {           var query = new esri.tasks.Query();           query.where = "NAME = '" + event.graphic.attributes["NAME"] + "'";           fireStations.queryFeatures(query, function (featureSet) {               console.log(featureSet.features[0].attributes.NAME);           });       }       dojo.addOnLoad(init);      </script>   </head>    <body class="claro">     <div id="mapDiv" style="width: 800px; height:500px;"></div>   </body> </html>
0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Frequent Contributor
Sean
Queries with a where clause and non-extent based spatial queries will be performed on the server.  So if you performed a query like this in your app you won't see a request to the server:

          var query = new esri.tasks.Query();   query.objectIds = [event.graphic.attributes.OBJECTID];;           fireStations.queryFeatures(query, function (featureSet) {               console.log(featureSet.features[0].attributes.NAME);           });

View solution in original post

0 Kudos
2 Replies
KellyHutchins
Esri Frequent Contributor
Sean
Queries with a where clause and non-extent based spatial queries will be performed on the server.  So if you performed a query like this in your app you won't see a request to the server:

          var query = new esri.tasks.Query();   query.objectIds = [event.graphic.attributes.OBJECTID];;           fireStations.queryFeatures(query, function (featureSet) {               console.log(featureSet.features[0].attributes.NAME);           });
0 Kudos
SeanHarkins
New Contributor III
Thanks Kelly.  That's exactly the information I was looking for.
0 Kudos