Select to view content in your preferred language

search widget from multiple sources

1168
2
Jump to solution
08-06-2017 01:07 PM
Henryobaseki
Regular Contributor

Hi All,

my search widget uses both geocoding service and two feature sources. However, I m having trouble having , it highlights the ESRI geocoder as the first source of search instead of ALL.

How do I make the ALL the default search so it searches all sources. Thanks in advance

// Add the layer to the map
  var trailsLayer = new FeatureLayer({
  });
 
  map.add(trailsLayer); // Optionally add layer to map

   // Add the layer to the map
  var trailsLayerr = new FeatureLayer({
  });
 
  map.add(trailsLayerr); // Optionally add layer to map
 
  var view = new MapView({
    container: "viewDiv"
    map: map,
   zoom: 17,
center: [0.46564130, 51.736810] // longitude, latitude
  });
 
  // Search
 
  var search = new Search({
    view: view
  });
  search.defaultSource.withinViewEnabled = true; // Limit search to visible map area only
  view.ui.add(search, "top-right"); // Add to the map

  // Add the trailheads as a search source

 
   

  search.sources.push({
    featureLayer: trailsLayer,
     searchFields: ["Postcode", "UPRN", "ADDRESS" ],
  displayField: "ADDRESS",
  exactMatch: false,
  outFields: ["*"],
   resultGraphicEnabled: true,
    name: "ADDRESS",
  placeholder: "example:  CM2 0HU",
    popupTemplate: { // autocasts as new popupTemplate()
        title: "Post Code: {Postcode}</br>UPRN: {UPRN}</br>ADDRESS: {ADDRESS}",
        overwriteActions: true
     
      }
  });

  search.sources.push({
    featureLayer: trailsLayerr,
     searchFields: ["Postcode", "UPRN", "ADDRESS" ],
  displayField: "ADDRESS",
  exactMatch: false,
  outFields: ["*"],
   resultGraphicEnabled: true,
    name: "Postcode",
  placeholder: "example:  CM2 0HU",
    popupTemplate: { // autocasts as new popupTemplate()
        title: "Post Code: {Postcode}</br>UPRN: {UPRN}</br>ADDRESS: {ADDRESS}",
        overwriteActions: true
     
      }
  });
 
 
 
   

 
 
 
 
 
 
 
 
 

});</script>
</head>
<body>
  <div id="viewDiv"></div>
</body>
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Henry,

   The help docs say that you set the activeIndex to -1 to search all layers:

https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search.html#activeSource 

The selected source's index. This value is -1 when all sources are selected.

View solution in original post

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus

Henry,

   The help docs say that you set the activeIndex to -1 to search all layers:

https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search.html#activeSource 

The selected source's index. This value is -1 when all sources are selected.

0 Kudos
Rocky_
by
Frequent Contributor

Hi Robert,

    Can you please tell me how to use below array of sources

var searchWidget = new Search(); var sources = [{ ... }, { ... }, { ... }]; //array of sources

searchWidget.sources = sources;

when we want to search multiple layers which having same name search-fields in it.

So in widget we can search it using search fields not with selecting feature layer.

right now am using it like below

const searchWidget = new Search({
view: view,
locationEnabled: true,
withinViewEnabled: true,
sources: [{
featureLayer: {
Placeholder: "OBJID",
url: "------------------------------------------",
popupTemplate: PopupTemp1
},
searchFields: ["OBJID", "TRACKNUM"],
suggestionTemplate: "{OBJID}, {TRACKNUM}",
exactMatch: true,
outFields: ["*"],
placeholder: "eg: SD0051S Or 2336767 or ",
zoomScale: 5000,
resultSymbol: {
type: "simple-line",
color: "black",
width: 8,
cap: "round",
style: "short-dashdotdot"
}
},
{
featureLayer: {
url: "-------------------------------------------",
popupTemplate: PopupTemp2
},
searchFields: ["OBJID", "TRACKNUM"],
suggestionTemplate: "{OBJID}, {TRACKNUM}",
exactMatch: true,
outFields: ["*"],
placeholder: "eg:SD0051S Or 2336767",
zoomScale: 5000,
resultSymbol: {
type: "simple-line",
color: "black",
width: 8,
cap: "round",
style: "short-dashdotdot"
}
}]
}, "SearchDivOpen", "top-right");

0 Kudos