FindNearest api not working

657
3
05-16-2018 04:10 AM
SurajShrestha
New Contributor II

How to use the findNearest arcgis javascript api? Is there any sample how to use findnearest api??

I have used something like : 

$scope.findNearest = new www.FindNearest({
analysisLayer: analysisLayer,  //this is the graphics layer type: polygon
nearLayers: nearLayers, //this is a feature layer get from quering arcgis url like: https://something.com/MapServer/0?f=pjson
map: $scope.map,
portalUrl: "https://domain/arcgis/rest/services/Utilities/Geometry/GeometryServer"
}, "analysis-tool");

It does not work.. I hope someone could suggest me on this. 

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus

Suraj,

   Some of your code looks strange:

$scope.findNearest = new www.FindNearest({
  analysisLayer: analysisLayer,  //this is the graphics layer type: polygon
  nearLayers: nearLayers, //this is a feature layer get from quering arcgis url like: https://something.com/MapServer/0?f=pjson
  map: $scope.map,
  portalUrl: "https://domain/arcgis/rest/services/Utilities/Geometry/GeometryServer"
}, "analysis-tool");
  1. PortalUrl should be "https://www.arcgis.com" not a Geometry server url.
  2. analysisLayer should be a FeatureLayer object not a GraphicsLayer
  3. nearLayer should be a FeatureLayer object not a map server query result (unless you are constructing a FeatureLayer from the result graphics).
  4. Also new www.FindNearest looks strange to me it normally would be new FindNearest()

You can find the expected/required properties in the help doc:

FindNearest | API Reference | ArcGIS API for JavaScript 3.24 

SurajShrestha
New Contributor II

Hi Robert,

Thanks for your reply. I have copied code sample from my project directly, so it looks bit strange. From your suggestions, it seems incorrect to use graphics layer to search nearest feature layer using FindNearest esri api. 

Could you suggest us right esri api to use in order to find nearest feature layer by using polygon graphics? Currently, we only get result from FindNearest api if the drawn polygon graphics contains feature layer, but if the polygon lies outside the layer, we get no result.

Thanks.

0 Kudos
GaneshSubbiah
Esri Contributor

Hi Suraj

Analysis Widgets/Dijits work against ArcGIS Spatial Analysis Service, I recommend looking at the Working with Analysis Widgets | Guide | ArcGIS API for JavaScript 3.24  Guide to working with Analysis Widgets and Samples on the documentation pages. Hope this helps

Thanks and Regards

Ganesh Subbiah

0 Kudos