How to configure the find task to search for layers in multiple services...

735
3
09-12-2011 02:50 PM
ZlatkoGrebenar1
New Contributor II
I am using code from the samples (Zoom to found features). I got it to work on searching for fields in one service just like the example shows.

How can I add multiple find tasks in order to search multiple services?

Any code or help is very much appreciated.

Thanks,

Zlatko
Tags (2)
0 Kudos
3 Replies
YungKaiChin
Occasional Contributor
Declare multiple FindTasks and run them.

You can create them inside
<fx: Declarations>

</fx: Declarations>
0 Kudos
ZlatkoGrebenar1
New Contributor II
HI YungKai,


Script:


private function doFind1():void
   {
    findTask.execute(myFindParameters);
   }
  
   private function executeCompleteHandler1(event:FindEvent):void
   {
    myGraphicsLayer.clear();
   
    resultSummary.text = "Found " + event.findResults.length + " results.";
    myGraphicsLayer.symbol = sfsFind;
   
    var resultCount:int = event.findResults.length;
   
    if (resultCount == 0)
    {
     Alert.show("No parcels found. Please change your search.");
    }
    else
    {
     // add feature as graphic to graphics layer
     for (var i:int = 0; i < resultCount; i++)
     {
      var graphic:Graphic = FindResult(event.findResults).feature;
      graphic.toolTip = event.findResults.foundFieldName + ": " + event.findResults.value;
      myGraphicsLayer.add(graphic);
     }
    
     // zoom to extent of all features
     var graphicProvider:ArrayCollection = myGraphicsLayer.graphicProvider as ArrayCollection;
     var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(graphicProvider.toArray());
     map.extent = graphicsExtent.expand(1.4); // zoom out a little
    }
   }

Declarations:

<esri:FindTask id="findTask2"
        executeComplete="executeCompleteHandler1(event)"
        url="**************"/>
<esri:FindParameters id="myFindParameters"
        contains="true"
        layerIds="[3]"
        outSpatialReference="{map.spatialReference}"
        returnGeometry="true"
        searchFields="[SubName]"
        searchText="{fText.text}"/>

Am I on the right track here or am I missing something?

Thanks,

Zlatko
0 Kudos
YungKaiChin
Occasional Contributor
Yes, you are.

However, you may need to think a bit more when to execute two findTasks, and how to deal with the results.
0 Kudos