search multiple sources

1658
3
01-19-2017 07:49 AM
MelissaPrindiville
New Contributor III

I've added the search multiple sources code sample located https://developers.arcgis.com/javascript/3/jssamples/search_multiplesources.html.  however it doesn't appear to search the feature layer.  It does search the world geocode service but not the feature layer.  Any ideas on what I am missing.

I've added the District Feature Layer to the map and can see the Search box.

var sources = search.get("sources");

//Push the sources used to search, by default the ArcGIS Online World geocoder is included. In addition there is a feature layer of US congressional districts. The districts search is set up to find the "DISTRICTID". Also, a feature layer of senator information is set up to find based on the senator name.

sources.push({
featureLayer: new FeatureLayer("https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/CongressionalDistricts/FeatureServ..."),
searchFields: ["DISTRICTID"],
displayField: "DISTRICTID",
exactMatch: false,
outFields: ["DISTRICTID", "NAME", "PARTY"],
name: "Congressional Districts",
placeholder: "3708",
maxResults: 6,
maxSuggestions: 6,

//Create an InfoTemplate and include three fields
infoTemplate: new InfoTemplate("Congressional District", "District ID: ${DISTRICTID}</br>Name: ${NAME}</br>Party Affiliation: ${PARTY}"),
enableSuggestions: true,
minCharacters: 0
});

//Set the sources above to the search widget
search.set("sources", sources);

search.startup();
});

-melissa

0 Kudos
3 Replies
RupertEssinger
Frequent Contributor

Hi Melissa

Could you let us know which of the 8 Story Map apps you are customizing  ?

Rupert

0 Kudos
MelissaPrindiville
New Contributor III

Sorry the Shortlist storymap.

-Melissa

0 Kudos
MarkCooney
Occasional Contributor III

Hi Melissa,

I think your code looks good, and should work.  This snippet worked for me:

define(["dojo/topic", "esri/dijit/Search", "esri/layers/FeatureLayer", "esri/InfoTemplate"], function(topic, Search, FeatureLayer, InfoTemplate) {
     /*
     * Custom Javascript to be executed while the application is initializing goes here
     */

     // The application is ready
     topic.subscribe("tpl-ready", function(){
          /*
          * Custom Javascript to be executed when the application is ready goes here
          */
          var search = new Search({
               map: app.map
          }, "search");

          var sources = search.get("sources");
          sources.push({
               featureLayer: new FeatureLayer("https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/CongressionalDistricts/FeatureServ..."),
               searchFields: ["DISTRICTID"],
               displayField: "DISTRICTID",
               exactMatch: false,
               outFields: ["DISTRICTID", "NAME", "PARTY"],
               name: "Congressional Districts",
               placeholder: "3708",
               maxResults: 6,
               maxSuggestions: 6,
               //Create an InfoTemplate and include three fields
               infoTemplate: new InfoTemplate("Congressional District", "District ID: ${DISTRICTID}</br>Name: ${NAME}</br>Party Affiliation: ${PARTY}"),
               enableSuggestions: true,
               minCharacters: 0
          });
          //Set the sources above to the search widget
          search.set("sources", sources);
          search.startup();

     });
});