ArcGIS API for JavaScript "Search Multiple Sources"

3117
4
07-22-2015 07:41 AM
AdamBlough
New Contributor II

I am working on adding a search bar to my code and found this amazing source (Search multiple sources | ArcGIS API for JavaScript ) that allows one to search over multiple fields using the same search bar. The only issue is that the search in this code produces a single result (i.e there is only one congressional district that is 'district 6')

 

I want to use this tool for searching trees. So rather than "Congressional District" I want to search "Common Tree Name"

 

I am inquiring about how to change the one search result to be a result that shows all of the points that share that tree name.

 

Any help would be Awesome!

 

-Adam

0 Kudos
4 Replies
AnthonyGiles
Frequent Contributor

​Adam,

you need to configure the sources to match your data:

         sources.push({
            featureLayer
: new FeatureLayer("http://yourtreeserviceURL/FeatureServer/0"),
            searchFields
: ["CommonTreeName"],
            displayField
: "CommonTreeName",
            exactMatch
: true,
            name
: "tree",
            outFields
: ["*"],
            placeholder
: "Tree name",
            maxResults
: 6,
            maxSuggestions
: 6,

            //Create an InfoTemplate

            infoTemplate
: new InfoTemplate("Tree information", "Name: ${Name}"),
           
            enableSuggestions
: true,
            minCharacters
: 0
        
});

Regards

Anthony

0 Kudos
AdamBlough
New Contributor II

See I did that and it works fine. I can type in "Tulip Tree" and it identifies A tulip tree. It only shows one of the many tulip trees in the data. So as far as that is concerned the search bar works fine. I just want the search for 'tulip tree' to display ALL of the tulip trees (i.e. 50 point results rather than just 1 result)

0 Kudos
AnthonyGiles
Frequent Contributor

​Adam,

The search bar isn't really designed to do what you want to achieve, you really need to use a query task:

QueryTask | API Reference | ArcGIS API for JavaScript

Unfortunately I cannot see any samples that show you how to simply use this combined with a map.

Have a look at the configurable map viewer that might give you some pointers:

CMV - Configurable Map Viewer

Regards

Anthony

0 Kudos
AnthonyGiles
Frequent Contributor

​Adam,

you could could also try the find task:

Find features on a map | ArcGIS API for JavaScript

Regards

Anthony

0 Kudos