Select to view content in your preferred language

cancel query task in flex

3289
15
01-04-2011 11:08 PM
ReenaSingh
Emerging Contributor
How to cancel the querying task of query task in the middle of query process and stop all query process.
Tags (2)
0 Kudos
15 Replies
ShannonMartel
Emerging Contributor
Reena, 
queryTask.executeForIds(query,new AsyncResponder(onResult,onFault,token))
//you need to change it to
queryTask.addEventListener(QueryEvent.EXECUTE_FOR_IDS_COMPLETE, onResult);
queryTask.addEventListener(FaultEvent.FAULT, onFault);
queryTask.executeForIds(query);
//That way you can use remove listener
queryTask.removeEventListener(QueryEvent.EXECUTE_COMPLETE, onResult);


I work for a town that sits in two countys. Each county's parcels are in a seperate layer. I am using a point locater to find the address. Then I use that graphic to query the parcels. I am trying to tell it if you get a value in the FeatureSet for the parcels in County A FeatureSet then proceed to query function A. If it gets a null try County B parcel layer. I have tried to so many different ways, but it always runs both queries. This is what I have tried:

1 - Made seperate query functions for both parcel layers.
2 - Created two FeatureSets (one for each County).
3 - Wrote functions to do additional queries if the featureSet is greater than zero.

It still runs both counties... Does anyone know what I am missing? Do I need eventlisteners, and how would I do it.

thanks!
0 Kudos
ShannonMartel
Emerging Contributor
Please, does anyone have any ideas?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Shannon,

   This sounds pretty straight forward... So you take the locator result geometry (MapPoint) and do a spatial query against County A and in the results function if the FeatureSet.Length == 0 then fire off the query for County B.

Or you could executeForIds on both counties and the one that returns results then fires a true query to the layer.
0 Kudos
ShannonMartel
Emerging Contributor
Here is the query function for the two parcel layers.  For some reason, it gets stuck in a loop.... I don't know why.  I have this query function, and then two additional functions, one for each County.  It keeps looping through the two additional functions (each County's fire, school etc) and putting them in the datagrid.  I have Fiddler, and it does not show the repeating queries.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Shannon,

The first thing I would do is bracket your if statement here:

       if (featureSet.features.length == 0){
        meckParcels = new Array();
        meckParQuery.outSpatialReference = map.spatialReference;
        meckParQuery.geometry = lastAddressGraphic.geometry;
        meckParQueryTask.execute(meckParQuery, new AsyncResponder(onMeckParQResult, onMeckParQFault, tpoints));
        
        function onMeckParQResult(featureSet:FeatureSet, token:Object = null):void
        {
         meckParcels = featureSet.features;
         if (featureSet.features.length > 0){       
          meckSearch();
         }  
         
        }
        function onMeckParQFault(info:Object, token:Object = null):void 
        {
         trace(info.toString());
        }
                                                      }
0 Kudos
ShannonMartel
Emerging Contributor
Got it!  I found in my code were I told it to run the meckSearch() inside the meckSearch() function.  I think I have been staring at it too long...  not sure how I missed that.

Thank you so much for your help.
Shannon
0 Kudos