//The query below runs much faster when using a where clause var selQuery = new esri.tasks.Query(); //selQuery.where = "OBJECTID = " + [addResults[0].objectId]; selQuery.objectIds = [addResults[0].objectId]; //The query below takes about 40 seconds to run when using only the objectIds. var selQuery = new esri.tasks.Query(); //selQuery.where = "OBJECTID = " + [addResults[0].objectId]; selQuery.objectIds = [addResults[0].objectId];
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10"> <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no"> <title></title> <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.4/js/esri/css/esri.css"> <style> html, body, #map { height: 100%; width: 100%; margin: 0; padding: 0; } #feedback { background: #fff; bottom: 30px; color: #444; position: absolute; font-family: arial; height: auto; left: 20px; margin: 5px; padding: 10px; bottom: 20px; width: 200px; z-index: 40; } </style> <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.4/"></script> <script> var map; require([ "dojo/dom", "dojo/on", "dojo/query", "esri/map", "esri/layers/FeatureLayer", "esri/tasks/query", "dojo/domReady!" ], function(dom, on, dojoQuery, Map, FeatureLayer, Query) { map = new Map("map", { basemap: "streets", center: [-93.011, 44.951], zoom: 11 }); var fl = new FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/1", { id: "BlockGroups" }); map.addLayer(fl); // generate 10 random numbers < 200,000 var randoms = []; for ( var i = 0; i < 10; i++ ) { randoms.push(parseInt(Math.random() * 200000)); } on(dom.byId("runQuery"), "click", function() { var queryMethod = dojoQuery("input[name=queryType]:checked")[0].value; var params = new Query(); params.returnGeometry = false; if ( queryMethod === "where" ) { // params.where = "OBJECTID IN (300, 301)"; params.where = "OBJECTID IN (" + randoms.join(",") + ")"; console.log("set params.where", params.where); } else { // params.objectIds = [ 300, 301 ]; params.objectIds = randoms console.log("set params.objectIds", params.objectIds); } fl.queryFeatures(params).then(querySuccess, queryError); }); function querySuccess(results) { console.log("query success: ", results); } function queryError(error) { console.log("query error: ", error); } } ); </script> </head> <body> <div id="map"></div> <div id="feedback"> Query using: <br> <input type="radio" name="queryType" id="whereClause" value="where" checked="checked"><label for="whereClause">Where</label> <input type="radio" name="queryType" id="objectIds" value="objectIds"><label for="objectIds">ObjectIds</label> <br> <button id="runQuery">Query</button> </div> </body> </html>
How is generating a where clause considerably more effort than generating an array of objectIds? Whether it's a where clause (a string) or an array of numbers, you're setting a property on a query object. Building a comma separated string is slightly more effort, but it's minimal.
It will require more code writing and "assumptions" to have to generate the where clause every single time.
So to recap, this appears to be an ESRI bug. Is it not better for ESRI to address this issue? In the meantime, I will have to "play around" with the code to account for this "feature" ... or there lack of.
Since you can see similar performance issues at the REST tier, that indicates that the performance problem is in something ArcGIS Server is doing or, more likely, that there's a performance issue on the database side, which is a whole other world of troubleshooting.I would go with what's fast: use query.where as opposed to query.objectIds. Any reason you can't do that?
http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3/query?where=OBJECTID+IN+%283%2C+4%29&text=&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=&returnGeometry=false&maxAllowableOffset=&geometryPrecision=&outSR=&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&returnDistinctValues=false&f=html
http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3/query?where=&text=&objectIds=3%2C+4&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=&returnGeometry=false&maxAllowableOffset=&geometryPrecision=&outSR=&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&returnDistinctValues=false&f=html
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.