Geometry Service within a Function that Returns a Value

599
2
Jump to solution
09-02-2013 09:45 AM
JamesFaron
Occasional Contributor
This may not be possible, but I thought I would ask: Can a geometry service be made to work synchronously within a function that returns a value? In other words, in a similar manner that WebMercatorUtil can work? Or can the code in the function be somehow adjusted so as to delay the return of the point until the geometry service has completed and returned the new value?

For example, in the following function, 'return newPoint' will complete before the geometry service will fire, because the geometry service call and response is asynchronous (no matter how I do it), whereas one can use WebMercatorUtil synchronously.

public function convertToPoint(x:Number, y:Number, bool:Boolean):Point   {       var _pointObject:MapPoint = new MapPoint();    _pointObject.spatialReference = new SpatialReference(4326);    _pointObject.x = x;    _pointObject.y = y;        if(bool)    {     _pointObject = WebMercatorUtil.geographicToWebMercator(_pointObject) as MapPoint;    }        if((bool) && (!isNaN(x)) && (!isNaN(y)))    {     const projParams:ProjectParameters = new ProjectParameters();     projParams.geometries = [_pointObject ];     var outSR:SpatialReference = new SpatialReference(2277);     projParams.outSpatialReference = outSR;     this.geomServ.project(projParams,       new AsyncResponder(       function pResult(item:Object, token:Object = null):void{        var pt:MapPoint = (item as Array)[0] as MapPoint;        _pointObject.x = pt.x;        _pointObject.y = pt.y;       },       function pFault(fault:Fault, token:Object = null):void{        Alert.show("Error: " + fault.faultString, "Error code: " + fault.faultCode);       }      )     );         }    else    {     _pointObject = WebMercatorUtil.webMercatorToGeographic(_pointObject) as MapPoint;    }           return new Point(_pointObject.x, _pointObject.y);   }


Thanks,

Jim Faron
Austin Independent School District
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
PaulHastings1
Occasional Contributor
WebMercatorUtil's code is client side, the projection bits are up on your arcGIS server & the twain can only meet once the server's done processing.

if its just projection you're after, why not client side? see http://bit.ly/17AVGcE

View solution in original post

0 Kudos
2 Replies
PaulHastings1
Occasional Contributor
WebMercatorUtil's code is client side, the projection bits are up on your arcGIS server & the twain can only meet once the server's done processing.

if its just projection you're after, why not client side? see http://bit.ly/17AVGcE
0 Kudos
JamesFaron
Occasional Contributor
Yes, that worked! Thanks so much for the reference. OpenScales is a great resource.

Jim Faron
Austin Independent School District
0 Kudos