<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: featureLayer.queryFeatures order by closest first? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-queryfeatures-order-by-closest-first/m-p/473141#M43874</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is an old sample of how this could be done using a much older API version:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/thread/107086"&gt;https://community.esri.com/thread/107086&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 09 Nov 2018 14:48:28 GMT</pubDate>
    <dc:creator>RobertScheitlin__GISP</dc:creator>
    <dc:date>2018-11-09T14:48:28Z</dc:date>
    <item>
      <title>featureLayer.queryFeatures order by closest first?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-queryfeatures-order-by-closest-first/m-p/473139#M43872</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a function that queries features that appear within a buffer around a given point on a feature layer.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;function queryLayer(layer, buffer, point){
&amp;nbsp; var query = layer.createQuery();
&amp;nbsp; query.geometry = buffer;
&amp;nbsp; query.spatialRelationship = "intersects";
&amp;nbsp; layer.queryFeatures(query).then(function(results){
&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log(results.features);
&amp;nbsp; });
}
‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I know that&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;SPAN style="color: #4c4c4c; background-color: #ffffff; font-weight: 300;"&gt;query.orderByFields = "..."&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;exists but I'm not sure how to go about using it.&amp;nbsp;Is there a good way&amp;nbsp;I can use the point variable to say "order by closest to this point"?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:55:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-queryfeatures-order-by-closest-first/m-p/473139#M43872</guid>
      <dc:creator>ShakilChoudhury</dc:creator>
      <dc:date>2021-12-11T20:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: featureLayer.queryFeatures order by closest first?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-queryfeatures-order-by-closest-first/m-p/473140#M43873</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Shakil,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;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.&lt;/P&gt;&lt;P&gt;&lt;A class="link-bare" href="https://developers.arcgis.com/javascript/3/jsapi/esri.geometry.geometryengine-amd.html#distance" title="https://developers.arcgis.com/javascript/3/jsapi/esri.geometry.geometryengine-amd.html#distance"&gt;https://developers.arcgis.com/javascript/3/jsapi/esri.geometry.geometryengine-amd.html#distance&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Nov 2018 14:35:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-queryfeatures-order-by-closest-first/m-p/473140#M43873</guid>
      <dc:creator>RobertScheitlin__GISP</dc:creator>
      <dc:date>2018-11-09T14:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: featureLayer.queryFeatures order by closest first?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-queryfeatures-order-by-closest-first/m-p/473141#M43874</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is an old sample of how this could be done using a much older API version:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/thread/107086"&gt;https://community.esri.com/thread/107086&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Nov 2018 14:48:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-queryfeatures-order-by-closest-first/m-p/473141#M43874</guid>
      <dc:creator>RobertScheitlin__GISP</dc:creator>
      <dc:date>2018-11-09T14:48:28Z</dc:date>
    </item>
  </channel>
</rss>

