Geoprocessing (intersecting / reading attributes / routing) with Javascript API

2239
5
09-23-2015 10:51 AM
wcESRI
by
New Contributor

Hello,

I am attempting to work with the Javscript API do the following.

Enter an address (address 1), intersect a polygon, get an address (address 2) from that polygon and route a line between the resulting points.

I am trying to find the proper functionality in the API to support this processing.

I found the routing support in the sample on the directions app at Directions | ArcGIS API for JavaScript.

There is also an example for point in polygon search at Geoprocessing - Point in polygon search | ArcGIS API for JavaScript .  Is there an basic example of this functionality available?

Does anyone have any example of reading attributes from a selected feature?

Thanks for your time!

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus

Christopher,

   I would just use a simple QueryTask to get the intersection of Address 1 geocode point with your polygon layer. The returned results of the QueryTask will have the attributes that you can read.

QueryTask | API Reference | ArcGIS API for JavaScript

0 Kudos
wcESRI
by
New Contributor

Robert, thanks for your help.

I am having difficulty with determining what classes to use and getting the results from the event.

I am trying to  use a search object and get the data from the search results.  I would then perform an intersection on the polygon layer and get the address.

I am trying to use a each object with no luck.  Am I using the right classes and how do I get the results from the event?

            var mySearch = new Search(
            {
                map: myMap

            }, "searchDiv");
           
            mySearch.startup();
           
            //begin event handler
            mySearch.on("search-results", function(e)
            {
                alert(e.results[0].toString());
               
            });   //end call process results function);  //end event handler

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Christopher,

  Try using:

mySearch.on("select-result", function (evt){
  //Do something with the result feature 
  console.info(evt.result.feature);
});
0 Kudos
wcESRI
by
New Contributor

Robert,  thank you again.  However, your code issues an error in javascript.

My code is below.

//begin event handler
 mySearch.on("search-results", function(e)
 {
                
       console.info(e.result.feature);
                
 });   //end call process results function);  //end event handler 



TypeError: Unable to get property 'feature' of undefined or null reference TypeError: Unable to get property 'feature' of undefined or null reference

The following code will produce a result but not very useful.

console.info(e.results[0].toString());

[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

I can't seem to access the event object in the seach results to get the results.

https://developers.arcgis.com/javascript/jsapi/search-amd.html#searchresults


					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Christopher,

  You need to look care fully at the API documentation the returned parameters for "select-result" is different than "select-result" code that I provided.

Search | API Reference | ArcGIS API for JavaScript | event-search-results

Your code would have to be:

//begin event handler  
 mySearch.on("search-results", function(e)  
 {            
     console.info(e.results);
     // This should return an array of results that have a extent and feature property        
 });   //end call process results function);  //end event handler
0 Kudos