Select to view content in your preferred language

GeometryServiceEvent token not accessible

1197
6
Jump to solution
11-30-2012 09:37 AM
JorgeFiallega
Emerging Contributor
The GeometryService when calling the buffer() method it returns back an AsyncToken
Nevertheless I dont find a way to access the token from the GeomtryServiceEvent.

This is all doable with the HTTPService and the ResultEvent.
The problem is that the token property comes from the AbstractToken which ResultEvent inherits from but the GeometryServiceEvent does not.


So

1. what is the purpose of returning hte AysncToken if it is not accessible from the event later
2. How do I pass values to handler of GeometryServiceEvent.BUFFER_COMPLETE ?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Jorge,

   See if this helps:

            private function buffer(event:Event):void{                 geometryService = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");                 bufferParameters = new BufferParameters();                 bufferParameters.bufferSpatialReference = new SpatialReference(102100);                 bufferParameters.distances = [1];                 bufferParameters.unit = GeometryService[GeometryService.UNIT_SQUARE_MILES];                 var mp:MapPoint = new MapPoint(3269676, 9132652, new SpatialReference(102100));                 bufferParameters.geometries = [mp];                 var token:AsyncToken = geometryService.buffer(bufferParameters)                 token.addResponder(new AsyncResponder(myResultFunction1,myFaultFunction1,{greeting:'hello'}));             }                          public function myResultFunction1(result:Array, token:Object = null):void{                 //The result should be an array of polygon(s)                 Alert.show(token.greeting);                 var pPoly:Polygon = result[0];                 trace(pPoly.toString());             }             public function myFaultFunction1(error:Object, token:Object = null):void{                 Alert.show('myFaulttFunction1');             }


Don't forget to click the Mark as answer check on this post and to click the top arrow (promote).
Follow these steps as shown in the below graphic:

View solution in original post

0 Kudos
6 Replies
JorgeFiallega
Emerging Contributor
I did the following:

geometryService.addEventListener(GeometryServiceEvent.BUFFER_COMPLETE, getCircleBufferCompleteHandler);
var token:AsyncToken = geometryService.buffer(bufferParameters)
token.addResponder(new AsyncResponder(myResultFunction1,myFaultFunction1,{greeting:'hello'}));

public function myResultFunction1(result:Object, token:Object = null):void{
  Alert.show(token.greeting);
}
public function myFaultFunction1(error:Object, token:Object = null):void{
  Alert.show('myFaulttFunction1');
}
private function getCircleBufferCompleteHandler(event:GeometryServiceEvent):void{
  Alert.show('getCircleBufferCompleteHandler');
}


but I am not sure this is a very good solution because two handlers are called, in the case of success myResultFunction1, getCircleBufferCompleteHandler. So I basically have to create a dummy getCircleBufferCompleteHandler which will do nothing. That tells me that I am going the wrong way.
I tried
geometryService.addEventListener(GeometryServiceEvent.BUFFER_COMPLETE, null);

to avoid one of the handlers but I get an error that second param can not be null.

So, I am not very happy about my solution. If somebody can shine some light, it will be appreciate it.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Jorge,

   See if this helps:

            private function buffer(event:Event):void{                 geometryService = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");                 bufferParameters = new BufferParameters();                 bufferParameters.bufferSpatialReference = new SpatialReference(102100);                 bufferParameters.distances = [1];                 bufferParameters.unit = GeometryService[GeometryService.UNIT_SQUARE_MILES];                 var mp:MapPoint = new MapPoint(3269676, 9132652, new SpatialReference(102100));                 bufferParameters.geometries = [mp];                 var token:AsyncToken = geometryService.buffer(bufferParameters)                 token.addResponder(new AsyncResponder(myResultFunction1,myFaultFunction1,{greeting:'hello'}));             }                          public function myResultFunction1(result:Array, token:Object = null):void{                 //The result should be an array of polygon(s)                 Alert.show(token.greeting);                 var pPoly:Polygon = result[0];                 trace(pPoly.toString());             }             public function myFaultFunction1(error:Object, token:Object = null):void{                 Alert.show('myFaulttFunction1');             }


Don't forget to click the Mark as answer check on this post and to click the top arrow (promote).
Follow these steps as shown in the below graphic:

0 Kudos
JorgeFiallega
Emerging Contributor
Thanks a lot.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Jorge,

   Don't mis the more important step... Making the question as answered. Step 1 in the graphic on my last post.
0 Kudos
JorgeFiallega
Emerging Contributor
that is the first thing I did. Does not show up for you   ?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Jorge,

   No the only thing that I see that you have done is step 2 (promoting the post). Step 1 is clicking the check mark.
0 Kudos