<?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 Iterating Geometry Server Distance calculations on a Result Set in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/iterating-geometry-server-distance-calculations-on/m-p/361470#M33459</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've searched through the forums and a bunch of dojo sites on Google, but haven't been able to find an answer for a problem that has stumped me for the past couple of days. So, I thought I'd just go ahead and ask straight out.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to write a function that calculates the distances between a point and each feature that falls within a buffer around that point. After performing the spatial query, the result set from the query is passed to the function that then returns an array of objects containing selected attributes from the features and the distance calculation. Here's a code snippet.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
var distanceParams = new esri.tasks.DistanceParameters();
distanceParams.distanceUnit = esri.tasks.GeometryService.UNIT_STATUTE_MILE;

distanceParams.geometry1 = myMap.geocodePoint; //the point being buffered 

var myAttributeArray = dojo.map(bufferQueryResultSet.features, function(res){
&amp;nbsp;&amp;nbsp; 
 var attr = {};
 attr.ID = res.attributes.ID;
 attr.NAME = res.attributes.NAME;
 distanceParams.geometry2 = res.geometry;
 myMap.geometryServer.distance(distanceParams, function(d){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; attr.DISTANCE = d;
 }).then(function(){return attr;});&amp;nbsp;&amp;nbsp; 
});
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The function as written above returns myAttributeArray as an array of undefined objects. If I rewrite the last few lines as:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
 myMap.geometryServer.distance(distanceParams, function(d){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; attr.DISTANCE = d;
 });
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return attr;
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...then myAttributeArray comprises objects with only ID and NAME defined. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I also tried:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
 attr.DISTANCE = myMap.geometryServer.distance(distanceParams, function(d){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return d;
 });
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return attr;
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...and that gave me an array of objects with ID and NAME defined and DISTANCE defined as a dojo.Deferred object.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know that there must be something with dojo.Deferred that I'm overlooking, but I'm not sure what. Any assistance would be greatly appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff Kapellas&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;California State Water Resources Control Board&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 02 Aug 2011 21:48:48 GMT</pubDate>
    <dc:creator>JeffKapellas</dc:creator>
    <dc:date>2011-08-02T21:48:48Z</dc:date>
    <item>
      <title>Iterating Geometry Server Distance calculations on a Result Set</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/iterating-geometry-server-distance-calculations-on/m-p/361470#M33459</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've searched through the forums and a bunch of dojo sites on Google, but haven't been able to find an answer for a problem that has stumped me for the past couple of days. So, I thought I'd just go ahead and ask straight out.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to write a function that calculates the distances between a point and each feature that falls within a buffer around that point. After performing the spatial query, the result set from the query is passed to the function that then returns an array of objects containing selected attributes from the features and the distance calculation. Here's a code snippet.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
var distanceParams = new esri.tasks.DistanceParameters();
distanceParams.distanceUnit = esri.tasks.GeometryService.UNIT_STATUTE_MILE;

distanceParams.geometry1 = myMap.geocodePoint; //the point being buffered 

var myAttributeArray = dojo.map(bufferQueryResultSet.features, function(res){
&amp;nbsp;&amp;nbsp; 
 var attr = {};
 attr.ID = res.attributes.ID;
 attr.NAME = res.attributes.NAME;
 distanceParams.geometry2 = res.geometry;
 myMap.geometryServer.distance(distanceParams, function(d){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; attr.DISTANCE = d;
 }).then(function(){return attr;});&amp;nbsp;&amp;nbsp; 
});
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The function as written above returns myAttributeArray as an array of undefined objects. If I rewrite the last few lines as:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
 myMap.geometryServer.distance(distanceParams, function(d){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; attr.DISTANCE = d;
 });
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return attr;
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...then myAttributeArray comprises objects with only ID and NAME defined. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I also tried:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
 attr.DISTANCE = myMap.geometryServer.distance(distanceParams, function(d){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return d;
 });
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return attr;
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...and that gave me an array of objects with ID and NAME defined and DISTANCE defined as a dojo.Deferred object.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know that there must be something with dojo.Deferred that I'm overlooking, but I'm not sure what. Any assistance would be greatly appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff Kapellas&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;California State Water Resources Control Board&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Aug 2011 21:48:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/iterating-geometry-server-distance-calculations-on/m-p/361470#M33459</guid>
      <dc:creator>JeffKapellas</dc:creator>
      <dc:date>2011-08-02T21:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating Geometry Server Distance calculations on a Result Set</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/iterating-geometry-server-distance-calculations-on/m-p/361471#M33460</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think there are two options:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Use a dojo.DeferredList to manage the deferreds returned from geometrySerivce.distance. That way, once all of your deferreds from the geometry service are resolved, you can access the results and go on building your array of objects. As is, if you access the myAttributeArray array immediately after dojo.map() runs, there could be resolved and unfulfilled promises. If you use a deferredList to manage everything, you are guaranteeing that your results will be there.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Do it all client side. The API includes client side functions to calculate distance between points. Check out &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/namespace_geometry.htm#getLength"&gt;esri.geometry.getLength()&lt;/A&gt;&lt;SPAN&gt; or, if you want geodesic distances, create a &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/polyline.htm"&gt;polyline&lt;/A&gt;&lt;SPAN&gt; out of your two points and pass it to &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/namespace_geometry.htm#geodesicLengths"&gt;esri.geometry.geodesicsLength()&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Aug 2011 21:55:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/iterating-geometry-server-distance-calculations-on/m-p/361471#M33460</guid>
      <dc:creator>derekswingley1</dc:creator>
      <dc:date>2011-08-03T21:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating Geometry Server Distance calculations on a Result Set</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/iterating-geometry-server-distance-calculations-on/m-p/361472#M33461</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Derek:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the reply. I'll take a look at the DeferredList option. The esri.geometry.getLength() option only seems to work for point-to-point, and I need to do point-to-line and point-to-poly calculations.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Aug 2011 16:47:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/iterating-geometry-server-distance-calculations-on/m-p/361472#M33461</guid>
      <dc:creator>JeffKapellas</dc:creator>
      <dc:date>2011-08-04T16:47:43Z</dc:date>
    </item>
  </channel>
</rss>

