I have a function that queries features that appear within a buffer around a given point on a feature layer.
function queryLayer(layer, buffer, point){
var query = layer.createQuery();
query.geometry = buffer;
query.spatialRelationship = "intersects";
layer.queryFeatures(query).then(function(results){
console.log(results.features);
});
}
I know that
query.orderByFields = "..."
exists but I'm not sure how to go about using it. Is there a good way I can use the point variable to say "order by closest to this point"?
Solved! Go to Solution.
Shakil,
There is no spatial orderBy capabilities in the API. So you will have to do it manually in the returned results. To do this you need your buffer point of origin (center point) and then to loop through the results and do a geometryEngine.distance evaluation keeping an array of the distance results that sort the array on.
https://developers.arcgis.com/javascript/3/jsapi/esri.geometry.geometryengine-amd.html#distance
Shakil,
There is no spatial orderBy capabilities in the API. So you will have to do it manually in the returned results. To do this you need your buffer point of origin (center point) and then to loop through the results and do a geometryEngine.distance evaluation keeping an array of the distance results that sort the array on.
https://developers.arcgis.com/javascript/3/jsapi/esri.geometry.geometryengine-amd.html#distance
Here is an old sample of how this could be done using a much older API version: