Can someone point me in the right direction of how to return the distances of each individual buffer when it is created using more than one distance in the params.distances parameter. I am currently generating multiple buffers at the same time from an input array specifying the distances. After these buffers are generated, I am having a hard time returning the individual distances of the buffers.
I have tried returning them from the params array for each graphic by the following:
1) alert(params.distances[0]);
2) for(var i=0; i<paramsBuffer.distances.length); i++){
alert(params.distances);
};
Neither of these will properly return the distance of the individual resulting buffer graphics. An example of what I am trying to do is return the distances of the two buffers generated in this example: ArcGIS API for JavaScript Sandbox . Any help is greatly appreciated.
Solved! Go to Solution.
You could add the buffer distances as attributes to the graphics, and then add the graphics to a GraphicsLayer. After the Graphics Layer is added, you can label the graphics using the attribute. I didn't get a chance to play with the placement, but below is an example you can build off of. One thing I noticed is that I was not able to get the labels to work using the 3.12 API. I had to revert to the 3.9.
Hi Wesley,
You can use the buffer-complete event to report the params.distances property. Ex:
gsvc.on("buffer-complete", function(results){ console.log(params.distances); })
Here is a working Fiddle.
Thanks for your response. This method returns the entire params.distance array. What I am trying to do is get the distance of each buffer generated from this array.
Try the following instead:
gsvc.on("buffer-complete", function(results){ for(var i=0; i<params.distances.length; i++){ console.log(params.distances) }; })
Updated Fiddle.
Thanks again. I have tried this and it will return the individual values in the array, however, I have not been able to associate them with the buffered graphics. For example, how would I label each buffer with these values once they are generated and added to the map?
You could add the buffer distances as attributes to the graphics, and then add the graphics to a GraphicsLayer. After the Graphics Layer is added, you can label the graphics using the attribute. I didn't get a chance to play with the placement, but below is an example you can build off of. One thing I noticed is that I was not able to get the labels to work using the 3.12 API. I had to revert to the 3.9.
The graphics layer is what I was missing. I figured it was something simple. Thanks for your help!