Select to view content in your preferred language

Waiting for relation to complete

601
2
02-04-2011 12:04 PM
CliftonAbbott
Emerging Contributor
I have a polygon provided by the user specifying up to six gps coordinates. I'm using relation to verify that the polygon is valid since it will eventually end up is SDE.  I have a process that goes through the entire user's input checking values and completeness and calls a function to check the polygon. This process needs to get back a boolean so that it can continue or stop processing. I have not been able to a result back to the calling function. I hope the answer is a "I'm just missing something obvious" moment instead of a "that is not possible" moment. Here is an example of my code:

function processing()
{
   if(!checkPolygon())
      ...stop processing...
   else
      ...continue processing...
}

function checkPolygon(l)
{
   ...prepare to call relation...

   geometryService.relation(relationParams, checkPolygonResults);
  
   ...needs to return boolean...
}

function checkPolygonResults(relations)
{
   ...check polygon...
   ...send result back somehow...
}


I've tried checkPolygonResults setting a global var and checkPolygon somehow waiting on the answer. However, I have not been able to get checkPolygon to wait without (apparently) preventing checkPolygonResults from running.

I've also tried getting something through the deferred value that relation returns, either getting the result directly or waiting on the result. I have not gotten that to work either, admitting that I'm not an expert with dojo.

Am I just missing something? Is there a better way to validate the polygon? I'm currently checking for a crossing relation for each of the lines in the polygon. I'm using javscript api 2.1.

Thanks
0 Kudos
2 Replies
CliftonAbbott
Emerging Contributor
Well, apparently what I wanted to do is not possible as the synchronous processing is not going to wait for the asynchronous relation to complete. What I did was to do some of the validation, then called relation. The relation callback checks the polygon and if good, then calls the rest of the validation.

There has to be a better way to check for a valid polygon.

Thanks anyway.
0 Kudos
HemingZhu
Frequent Contributor
Well, apparently what I wanted to do is not possible as the synchronous processing is not going to wait for the asynchronous relation to complete. What I did was to do some of the validation, then called relation. The relation callback checks the polygon and if good, then calls the rest of the validation.

There has to be a better way to check for a valid polygon.

Thanks anyway.


Here are a couple of thoughts that might help: Enforce the validation of an input polygon using GeometryService's simplify method. It will make polygon topologically legal with regard to their geometry type (con is that it might slightly alter the shape of the original polygon).
Or create GP serivce contains system tool -CheckGeometry_management, accepting input polygon as one of the input parameter and set output table as an output. If the output table contains no record, that means there is no problem associated with the input.
0 Kudos