AnsweredAssumed Answered

geometryService.distance not returning what's expected

Question asked by craygo on Feb 19, 2016
Latest reply on Mar 2, 2016 by craygo

This is killing me. Been working on this for hours and can't seem to work this out.

Here is my function.

 

function selectInBuffer(results){
        //console.log(results);
        sResults = {displayFieldName: null, features:[]};
        var feat;
        var features = results.features;

        for (var i = 0; i < features.length; i++) {
          var feat = features[i];
          tfeat[i] = feat;
          var distParams = new DistanceParameters();
          distParams.distanceUnit = geometryService.UNIT_FOOT;
          distParams.geometry1 = pt;
          distParams.geometry2 = feat.geometry;
          distParams.geodesic = true;
          distp = geometryService.distance(distParams);
          console.dir(distp);
          tfeat[i].dist = distp;
          feat.setSymbol(symbol2);
          feat.setInfoTemplate(infoTemplate);
          map.graphics.add(feat);
          if (!sResults.displayFieldName){ sResults.displayFieldName = results.displayFieldName }
                sResults.features.push(feat);

        }
        console.log(tfeat);
        registry.byId("grid").set("content", formatResults(results));
        //console.log(sResults);
      }

According to all the samples I have seen, var distp should be just a number. I am getting back an object that I can't seem to do anything with it.

 

Here is what is return with firebug

 

gsd1.jpg

gsd2.jpg

What I am trying to do is create a buffer, which works fine. Then query a layer to return the features in that buffer, again works fine. What I am doing here is loop through those results to push a field into the object array with the distance. Then I want to sort the array based on the distance. Then show the results in a grid.

 

Thanks in advance for help.

 

Ray

Outcomes